How to use the pyroute2.netlink.nla.encode 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 / netlink / rtnl / ifinfmsg / __init__.py View on Github external
def encode(self):
                    self['mac'] = ([int(x, 16) for x
                                    in self['mac'].split(':')] +
                                   [0] * 26)
                    nla.encode(self)
github svinota / pyroute2 / pyroute2 / netlink / rtnl / tcmsg.py View on Github external
def encode(self):
            self.rtab = None
            self.ptab = None
            if self.get('rate', False):
                self.rtab = self.calc_rtab('rate')
            if self.get('peak', False):
                self.ptab = self.calc_rtab('peak')
            if self.get('ceil', False):
                self.ctab = self.calc_rtab('ceil')
            nla.encode(self)
github svinota / pyroute2 / pyroute2 / netlink / rtnl / tcmsg / cls_u32.py View on Github external
key['key_val'] = 0
                    bits = 24
                if key is not None and bits >= 0:
                    key['key_mask'] |= bmask << bits
                    key['key_val'] |= bvalue << bits
                    bits -= 8
                    if (bits < 0 or offset == 255):
                        keys.append(key)
                        key = None

            assert keys
            self['nkeys'] = len(keys)
            # FIXME: do not hardcode flags :)
            self['flags'] = 1

            nla.encode(self)
            offset = self.offset + 20  # 4 bytes header + 16 bytes fields
            for key in keys:
                key.offset = offset
                key.encode()
                offset += 16  # keys haven't header
            self.length = offset - self.offset
            struct.pack_into('H',
                             self.data,
                             self.offset,
                             offset - self.offset)
github svinota / pyroute2 / pyroute2 / netlink / rtnl / tcmsg / sched_cake.py View on Github external
def encode(self):
        # Set default Auto-Rate value
        if not self.get_attr('TCA_CAKE_AUTORATE'):
            self['attrs'].append(['TCA_CAKE_AUTORATE', 0])
        nla.encode(self)
github svinota / pyroute2 / pyroute2 / netlink / generic / wireguard.py View on Github external
def encode(self):
                    if self['addr'].find(":") > -1:
                        self['family'] = AF_INET6
                        self['addr4'] = 0  # Set to NULL
                        self['addr6'] = inet_pton(AF_INET6, self['addr'])
                    else:
                        self['family'] = AF_INET
                        self['addr4'] = unpack('>I',
                                               inet_aton(self['addr']))[0]
                        self['addr6'] = b'\x00\x00\x00\x00\x00\x00\x00\x00'
                    self['port'] = int(self['port'])
                    self['__padding'] = 0
                    nla.encode(self)
github svinota / pyroute2 / pyroute2 / netlink / rtnl / ifinfmsg / __init__.py View on Github external
def encode(self):
                    #
                    # for details see:
                    url = 'https://github.com/svinota/pyroute2/issues/531'

                    v = self.value
                    for flag in GRE_VALUES:
                        v &= ~flag
                    if v != 0:
                        log.warning('possibly incorrect GRE flags, '
                                    'see %s' % url)
                    nla.encode(self)
github svinota / pyroute2 / pyroute2 / netlink / nfnetlink / nfctsocket.py View on Github external
def encode(self):
            if not isinstance(self['value'], tuple):
                self['value'] = (self['value'] & 0xffffffffffffffff,
                                 self['value'] >> 64)
            nla.encode(self)
github svinota / pyroute2 / pyroute2 / netlink / rtnl / rtmsg.py View on Github external
def encode(self):
                # Convert to network byte order
                self['value'] = inet_pton(AF_INET, self['value'])
                # Finally encode as nla
                nla.encode(self)
github svinota / pyroute2 / pyroute2 / netlink / rtnl / ifinfmsg / __init__.py View on Github external
def encode(self):
            self['value'] = state_by_name[self.value]
            nla.encode(self)