How to use the pyroute2.nftables.parser.parser.conv_map_tuple function in pyroute2

To help you get started, we’ve selected a few pyroute2 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github svinota / pyroute2 / pyroute2 / nftables / rule.py View on Github external
}
NFPROTO_2_NAME = {v: k for k, v in NAME_2_NFPROTO.items()}


class NFTRule(nfta_nla_parser):

    conv_maps = (
        conv_map_tuple('family', 'nfgen_family', 'family', 'nfproto'),
        conv_map_tuple('table', 'NFTA_RULE_TABLE', 'table', 'raw'),
        conv_map_tuple('chain', 'NFTA_RULE_CHAIN', 'chain', 'raw'),
        conv_map_tuple('handle', 'NFTA_RULE_HANDLE', 'handle', 'raw'),
        conv_map_tuple('expressions', 'NFTA_RULE_EXPRESSIONS', 'expr',
                       'expressions_list'),
        conv_map_tuple('compat', 'NFTA_RULE_COMPAT', 'compat', 'raw'),
        conv_map_tuple('position', 'NFTA_RULE_POSITION', 'position', 'raw'),
        conv_map_tuple('userdata', 'NFTA_RULE_USERDATA', 'userdata',
                       'user_data'),
        conv_map_tuple('rule_id', 'NFTA_RULE_ID', 'rule_id', 'raw'),
        conv_map_tuple('position_id', 'NFTA_RULE_POSITION_ID', 'position_id',
                       'raw'),
    )

    @classmethod
    def from_netlink(cls, ndmsg):
        obj = super(NFTRule, cls).from_netlink(ndmsg)
        obj.family = cls.cparser_nfproto.from_netlink(
            ndmsg['nfgen_family'])
        return obj

    class cparser_user_data(object):
        def __init__(self, udata_type, value):
            self.type = udata_type
github svinota / pyroute2 / pyroute2 / nftables / parser / expr.py View on Github external
return val

        @staticmethod
        def from_dict(val):
            return val

        @staticmethod
        def to_dict(val):
            return val


class ExprMeta(NFTRuleExpr):

    conv_maps = NFTRuleExpr.conv_maps + (
        conv_map_tuple('key', 'NFTA_META_KEY', 'key', 'meta_key'),
        conv_map_tuple('dreg', 'NFTA_META_DREG', 'dreg', 'reg'),
    )

    class cparser_meta_key(NFTRuleExpr.cparser_extract_str):
        STRVAL = 'NFT_META_{0}'


class ExprCmp(NFTRuleExpr):

    conv_maps = NFTRuleExpr.conv_maps + (
        conv_map_tuple('sreg', 'NFTA_CMP_SREG', 'sreg', 'reg'),
        conv_map_tuple('op', 'NFTA_CMP_OP', 'op', 'cmp_op'),
        conv_map_tuple('data', 'NFTA_CMP_DATA', 'data', 'data'),
    )

    class cparser_cmp_op(NFTRuleExpr.cparser_extract_str):
        STRVAL = 'NFT_CMP_{0}'
github svinota / pyroute2 / pyroute2 / nftables / parser / expr.py View on Github external
class ExprLookup(NFTRuleExpr):

    conv_maps = NFTRuleExpr.conv_maps + (
        conv_map_tuple('setid', 'NFTA_LOOKUP_SET', 'set', 'raw'),
        conv_map_tuple('sreg', 'NFTA_LOOKUP_SREG', 'sreg', 'reg'),
        conv_map_tuple('flags', 'NFTA_LOOKUP_FLAGS', 'flags', 'raw'),
    )


class ExprNat(NFTRuleExpr):

    conv_maps = NFTRuleExpr.conv_maps + (
        conv_map_tuple('nat_type', 'NFTA_NAT_TYPE', 'nat_type', 'nat_type'),
        conv_map_tuple('family', 'NFTA_NAT_FAMILY', 'family', 'inet_family'),
        conv_map_tuple('sreg_addr_min', 'NFTA_NAT_REG_ADDR_MIN',
                       'sreg_addr_min', 'reg'),
        conv_map_tuple('sreg_addr_max', 'NFTA_NAT_REG_ADDR_MAX',
                       'sreg_addr_max', 'reg'),
    )

    class cparser_nat_type(NFTRuleExpr.cparser_extract_str):
        STRVAL = 'NFT_NAT_{0}'


class ExprBitwise(NFTRuleExpr):

    conv_maps = NFTRuleExpr.conv_maps + (
        conv_map_tuple('sreg', 'NFTA_BITWISE_SREG', 'sreg', 'reg'),
        conv_map_tuple('dreg', 'NFTA_BITWISE_DREG', 'dreg', 'reg'),
        conv_map_tuple('len', 'NFTA_BITWISE_LEN', 'len', 'raw'),
        conv_map_tuple('mask', 'NFTA_BITWISE_MASK', 'mask', 'data'),
github svinota / pyroute2 / pyroute2 / nftables / parser / expr.py View on Github external
class ExprBitwise(NFTRuleExpr):

    conv_maps = NFTRuleExpr.conv_maps + (
        conv_map_tuple('sreg', 'NFTA_BITWISE_SREG', 'sreg', 'reg'),
        conv_map_tuple('dreg', 'NFTA_BITWISE_DREG', 'dreg', 'reg'),
        conv_map_tuple('len', 'NFTA_BITWISE_LEN', 'len', 'raw'),
        conv_map_tuple('mask', 'NFTA_BITWISE_MASK', 'mask', 'data'),
        conv_map_tuple('xor', 'NFTA_BITWISE_XOR', 'xor', 'data'),
    )


class ExprCounter(NFTRuleExpr):

    conv_maps = NFTRuleExpr.conv_maps + (
        conv_map_tuple('bytes', 'NFTA_COUNTER_BYTES', 'bytes', 'raw'),
        conv_map_tuple('packets', 'NFTA_COUNTER_PACKETS', 'pkts', 'raw'),
    )


class ExprMatch(NFTRuleExpr):

    conv_maps = NFTRuleExpr.conv_maps + (
        conv_map_tuple('match_name', 'NFTA_MATCH_NAME', 'name', 'raw'),
    )


class ExprTarget(NFTRuleExpr):

    conv_maps = NFTRuleExpr.conv_maps + (
        conv_map_tuple('target_name', 'NFTA_TARGET_NAME', 'name', 'raw'),
    )
github svinota / pyroute2 / pyroute2 / nftables / parser / expr.py View on Github external
return AF_INET6
            return val

        @staticmethod
        def from_dict(val):
            return val

        @staticmethod
        def to_dict(val):
            return val


class ExprMeta(NFTRuleExpr):

    conv_maps = NFTRuleExpr.conv_maps + (
        conv_map_tuple('key', 'NFTA_META_KEY', 'key', 'meta_key'),
        conv_map_tuple('dreg', 'NFTA_META_DREG', 'dreg', 'reg'),
    )

    class cparser_meta_key(NFTRuleExpr.cparser_extract_str):
        STRVAL = 'NFT_META_{0}'


class ExprCmp(NFTRuleExpr):

    conv_maps = NFTRuleExpr.conv_maps + (
        conv_map_tuple('sreg', 'NFTA_CMP_SREG', 'sreg', 'reg'),
        conv_map_tuple('op', 'NFTA_CMP_OP', 'op', 'cmp_op'),
        conv_map_tuple('data', 'NFTA_CMP_DATA', 'data', 'data'),
    )

    class cparser_cmp_op(NFTRuleExpr.cparser_extract_str):
github svinota / pyroute2 / pyroute2 / nftables / rule.py View on Github external
"ipv4": 2,
    "arp": 3,
    "netdev": 5,
    "bridge": 7,
    "ipv6": 10,
    "decnet": 12,
}
NFPROTO_2_NAME = {v: k for k, v in NAME_2_NFPROTO.items()}


class NFTRule(nfta_nla_parser):

    conv_maps = (
        conv_map_tuple('family', 'nfgen_family', 'family', 'nfproto'),
        conv_map_tuple('table', 'NFTA_RULE_TABLE', 'table', 'raw'),
        conv_map_tuple('chain', 'NFTA_RULE_CHAIN', 'chain', 'raw'),
        conv_map_tuple('handle', 'NFTA_RULE_HANDLE', 'handle', 'raw'),
        conv_map_tuple('expressions', 'NFTA_RULE_EXPRESSIONS', 'expr',
                       'expressions_list'),
        conv_map_tuple('compat', 'NFTA_RULE_COMPAT', 'compat', 'raw'),
        conv_map_tuple('position', 'NFTA_RULE_POSITION', 'position', 'raw'),
        conv_map_tuple('userdata', 'NFTA_RULE_USERDATA', 'userdata',
                       'user_data'),
        conv_map_tuple('rule_id', 'NFTA_RULE_ID', 'rule_id', 'raw'),
        conv_map_tuple('position_id', 'NFTA_RULE_POSITION_ID', 'position_id',
                       'raw'),
    )

    @classmethod
    def from_netlink(cls, ndmsg):
        obj = super(NFTRule, cls).from_netlink(ndmsg)
        obj.family = cls.cparser_nfproto.from_netlink(
github svinota / pyroute2 / pyroute2 / nftables / parser / expr.py View on Github external
conv_map_tuple('family', 'NFTA_NAT_FAMILY', 'family', 'inet_family'),
        conv_map_tuple('sreg_addr_min', 'NFTA_NAT_REG_ADDR_MIN',
                       'sreg_addr_min', 'reg'),
        conv_map_tuple('sreg_addr_max', 'NFTA_NAT_REG_ADDR_MAX',
                       'sreg_addr_max', 'reg'),
    )

    class cparser_nat_type(NFTRuleExpr.cparser_extract_str):
        STRVAL = 'NFT_NAT_{0}'


class ExprBitwise(NFTRuleExpr):

    conv_maps = NFTRuleExpr.conv_maps + (
        conv_map_tuple('sreg', 'NFTA_BITWISE_SREG', 'sreg', 'reg'),
        conv_map_tuple('dreg', 'NFTA_BITWISE_DREG', 'dreg', 'reg'),
        conv_map_tuple('len', 'NFTA_BITWISE_LEN', 'len', 'raw'),
        conv_map_tuple('mask', 'NFTA_BITWISE_MASK', 'mask', 'data'),
        conv_map_tuple('xor', 'NFTA_BITWISE_XOR', 'xor', 'data'),
    )


class ExprCounter(NFTRuleExpr):

    conv_maps = NFTRuleExpr.conv_maps + (
        conv_map_tuple('bytes', 'NFTA_COUNTER_BYTES', 'bytes', 'raw'),
        conv_map_tuple('packets', 'NFTA_COUNTER_PACKETS', 'pkts', 'raw'),
    )


class ExprMatch(NFTRuleExpr):
github svinota / pyroute2 / pyroute2 / nftables / parser / expr.py View on Github external
conv_map_tuple('bytes', 'NFTA_COUNTER_BYTES', 'bytes', 'raw'),
        conv_map_tuple('packets', 'NFTA_COUNTER_PACKETS', 'pkts', 'raw'),
    )


class ExprMatch(NFTRuleExpr):

    conv_maps = NFTRuleExpr.conv_maps + (
        conv_map_tuple('match_name', 'NFTA_MATCH_NAME', 'name', 'raw'),
    )


class ExprTarget(NFTRuleExpr):

    conv_maps = NFTRuleExpr.conv_maps + (
        conv_map_tuple('target_name', 'NFTA_TARGET_NAME', 'name', 'raw'),
    )


NFTA_EXPR_NAME_MAP = {
    'meta': ExprMeta,
    'cmp': ExprCmp,
    'immediate': ExprImmediate,
    'payload': ExprPayload,
    'lookup': ExprLookup,
    'nat': ExprNat,
    'bitwise': ExprBitwise,
    'counter': ExprCounter,
    'match': ExprMatch,
    'target': ExprTarget,
}
github svinota / pyroute2 / pyroute2 / nftables / parser / expr.py View on Github external
conv_map_tuple('nat_type', 'NFTA_NAT_TYPE', 'nat_type', 'nat_type'),
        conv_map_tuple('family', 'NFTA_NAT_FAMILY', 'family', 'inet_family'),
        conv_map_tuple('sreg_addr_min', 'NFTA_NAT_REG_ADDR_MIN',
                       'sreg_addr_min', 'reg'),
        conv_map_tuple('sreg_addr_max', 'NFTA_NAT_REG_ADDR_MAX',
                       'sreg_addr_max', 'reg'),
    )

    class cparser_nat_type(NFTRuleExpr.cparser_extract_str):
        STRVAL = 'NFT_NAT_{0}'


class ExprBitwise(NFTRuleExpr):

    conv_maps = NFTRuleExpr.conv_maps + (
        conv_map_tuple('sreg', 'NFTA_BITWISE_SREG', 'sreg', 'reg'),
        conv_map_tuple('dreg', 'NFTA_BITWISE_DREG', 'dreg', 'reg'),
        conv_map_tuple('len', 'NFTA_BITWISE_LEN', 'len', 'raw'),
        conv_map_tuple('mask', 'NFTA_BITWISE_MASK', 'mask', 'data'),
        conv_map_tuple('xor', 'NFTA_BITWISE_XOR', 'xor', 'data'),
    )


class ExprCounter(NFTRuleExpr):

    conv_maps = NFTRuleExpr.conv_maps + (
        conv_map_tuple('bytes', 'NFTA_COUNTER_BYTES', 'bytes', 'raw'),
        conv_map_tuple('packets', 'NFTA_COUNTER_PACKETS', 'pkts', 'raw'),
    )


class ExprMatch(NFTRuleExpr):
github svinota / pyroute2 / pyroute2 / nftables / parser / expr.py View on Github external
class ExprImmediate(NFTRuleExpr):

    conv_maps = NFTRuleExpr.conv_maps + (
        conv_map_tuple('dreg', 'NFTA_IMMEDIATE_DREG', 'dreg', 'reg'),
        conv_map_tuple('data', 'NFTA_IMMEDIATE_DATA', 'data', 'data'),
    )


class ExprPayload(NFTRuleExpr):

    conv_maps = NFTRuleExpr.conv_maps + (
        conv_map_tuple('dreg', 'NFTA_PAYLOAD_DREG', 'dreg', 'reg'),
        conv_map_tuple('base', 'NFTA_PAYLOAD_BASE', 'base', 'payload_base'),
        conv_map_tuple('offset', 'NFTA_PAYLOAD_OFFSET', 'offset', 'raw'),
        conv_map_tuple('len', 'NFTA_PAYLOAD_LEN', 'len', 'raw'),
    )

    class cparser_payload_base(NFTRuleExpr.cparser_extract_str):
        STRVAL = 'NFT_PAYLOAD_{0}_HEADER'

        @classmethod
        def from_netlink(cls, ndmsg):
            val = super(
                ExprPayload.cparser_payload_base, cls).from_netlink(ndmsg)
            if val == 'll':
                return 'link'
            return val

        @classmethod
        def to_netlink(cls, val):