Exemplo n.º 1
0
 def encode(self):
     # FIXME: add human-friendly API to specify IP addresses as str
     # (see also decode())
     if self['idiag_src'] == 0:
         self['idiag_src'] = (0, 0, 0, 0)
     if self['idiag_dst'] == 0:
         self['idiag_dst'] = (0, 0, 0, 0)
     nlmsg.encode(self)
Exemplo n.º 2
0
 def encode(self):
     # FIXME: add human-friendly API to specify IP addresses as str
     # (see also decode())
     if self['idiag_src'] == 0:
         self['idiag_src'] = (0, 0, 0, 0)
     if self['idiag_dst'] == 0:
         self['idiag_dst'] = (0, 0, 0, 0)
     nlmsg.encode(self)
Exemplo n.º 3
0
 def encode(self):
     if self.get('family') == AF_MPLS:
         # force fields
         self['dst_len'] = 20
         self['table'] = 254
         self['type'] = 1
         # assert NLA types
         for n in self.get('attrs', []):
             if n[0] not in ('RTA_OIF', 'RTA_DST', 'RTA_VIA', 'RTA_NEWDST'):
                 raise TypeError('Incorrect NLA type %s for AF_MPLS' % n[0])
     nlmsg.encode(self)
Exemplo n.º 4
0
 def encode(self):
     if self.get('family') == AF_MPLS:
         # force fields
         self['dst_len'] = 20
         self['table'] = 254
         self['type'] = 1
         # assert NLA types
         for n in self.get('attrs', []):
             if n[0] not in ('RTA_OIF', 'RTA_DST', 'RTA_VIA', 'RTA_NEWDST'):
                 raise TypeError('Incorrect NLA type %s for AF_MPLS' % n[0])
     nlmsg.encode(self)
Exemplo n.º 5
0
 def encode(self):
     init = self.buf.tell()
     nlmsg.encode(self)
     if 'payload' in self:
         self.buf.write(self['payload'])
         self.update_length(init)
Exemplo n.º 6
0
 def encode(self):
     # convert flags
     if isinstance(self['flags'], (set, tuple, list)):
         self['flags'], self['change'] = self.names2flags(self['flags'])
     return nlmsg.encode(self)
Exemplo n.º 7
0
 def encode(self):
     init = self.buf.tell()
     nlmsg.encode(self)
     if 'payload' in self:
         self.buf.write(self['payload'])
         self.update_length(init)