def decode(self): # Decode the data nla.decode(self) # Extract the encap mode self['mode'] = (self.r_encapmodes .get(self['encapmode'], "encap")) # Calculate offset of the segs offset = self.offset + 16 # Point the addresses addresses = self.data[offset:] # Extract the number of segs n_segs = self['segments_left'] + 1 # Init segs segs = [] # Move 128 bit in each step for i in range(n_segs): # Save the segment segs.append(inet_ntop(AF_INET6, addresses[i * 16:i * 16 + 16])) # Save segs self['segs'] = segs # Init tlvs self['tlvs'] = '' # If hmac is used if self.has_hmac(): # Point to the start of hmac hmac = addresses[n_segs * 16:n_segs * 16 + 40] # Save tlvs section self['tlvs'] = hexdump(hmac) # Show also the hmac key self['hmac'] = hexdump(hmac[4:8])
def decode(self): nla.decode(self) # old latency/jitter are in tick units self['delay'] = tick2time(self['delay']) self['jitter'] = tick2time(self['jitter']) self['loss'] = round(u32_percent(self['loss']), 2) self['duplicate'] = round(u32_percent(self['duplicate']), 2)
def decode(self): # Decode the data nla.decode(self) # Calculate offset of the segs offset = self.offset + 16 # Point the addresses addresses = self.data[offset:] # Extract the number of segs n_segs = self['segments_left'] + 1 # Init segs segs = [] # Move 128 bit in each step for i in range(n_segs): # Save the segment segs.append(inet_ntop(AF_INET6, addresses[i * 16:i * 16 + 16])) # Save segs self['segs'] = segs # Init tlvs self['tlvs'] = '' # If hmac is used if self.has_hmac(): # Point to the start of hmac hmac = addresses[n_segs * 16:n_segs * 16 + 40] # Save tlvs section self['tlvs'] = hexdump(hmac) # Show also the hmac key self['hmac'] = hexdump(hmac[4:8])
def decode(self): nla.decode(self) r_prio = self['value'][:2] r_addr = self['value'][2:] self.value = {'prio': struct.unpack('H', r_prio)[0], 'addr': ':'.join('%02x' % (i) for i in struct.unpack('BBBBBB', r_addr))}
def decode(self): nla.decode(self) if self['family'] == AF_INET: self['addr'] = inet_ntoa(pack('>I', self['addr4'])) else: self['addr'] = inet_ntoa(AF_INET6, self['addr6']) del self['addr4'] del self['addr6']
def decode(self): nla.decode(self) keys = '' for key, value in tc_flow_keys.items(): if value & self['flow_keys']: keys = '{0},{1}'.format(keys, key) self['flow_keys'] = keys.strip(',')
def decode(self): nla.decode(self) self['keys'] = [] nkeys = self['nkeys'] while nkeys: key = self.u32_key(self.buf) key.decode() self['keys'].append(key) nkeys -= 1
def decode(self): nla.decode(self) parms = self.parent.get_attr('TCA_TBF_PARMS') or \ self.parent.get_attr('TCA_HTB_PARMS') or \ self.parent.get_attr('TCA_POLICE_TBF') if parms is not None: rtab = struct.unpack('I' * (len(self['value']) / 4), self['value']) self.value = rtab setattr(parms, self.__class__.__name__, rtab)
def decode(self): nla.decode(self) if self.get_attr('WGALLOWEDIP_A_FAMILY') == AF_INET: pre = (self.get_attr('WGALLOWEDIP_A_IPADDR').replace( ':', '')) self['addr'] = inet_ntoa(a2b_hex(pre)) else: self['addr'] = (self.get_attr('WGALLOWEDIP_A_IPADDR')) wgaddr = self.get_attr('WGALLOWEDIP_A_CIDR_MASK') self['addr'] = '{0}/{1}'.format(self['addr'], wgaddr)
def decode(self): nla.decode(self) family = struct.unpack('H', self['value'][:2])[0] addr = self['value'][2:] if len(addr): if (family == AF_INET and len(addr) == 4) or \ (family == AF_INET6 and len(addr) == 16): addr = inet_ntop(family, addr) else: addr = hexdump(addr) self.value = {'family': family, 'addr': addr}
def decode(self): nla.decode(self) # read the type kind = struct.unpack('I', self.buf.read(4))[0] if kind == self.TCA_FQ_CODEL_XSTATS_QDISC: self.fields = self.qdisc_fields elif kind == self.TCA_FQ_CODEL_XSTATS_CLASS: self.fields = self.class_fields else: raise TypeError("Unknown xstats type") self.decode_fields()
def decode(self): nla.decode(self) offset = self.offset + 16 self['keys'] = [] nkeys = self['nkeys'] while nkeys: key = self.u32_key(data=self.data, offset=offset) key.decode() offset += 16 self['keys'].append(key) nkeys -= 1
def decode(self): # Fix tcpi_rcv_scale amd delivery_rate bit fields. # In the C: # # __u8 tcpi_snd_wscale : 4, tcpi_rcv_wscale : 4; # __u8 tcpi_delivery_rate_app_limited:1; # nla.decode(self) self['tcpi_rcv_wscale'] = self['tcpi_snd_wscale'] & 0xf self['tcpi_snd_wscale'] = self['tcpi_snd_wscale'] & 0xf0 >> 4 self['tcpi_delivery_rate_app_limited'] = \ self['tcpi_delivery_rate_app_limited'] & 0x80 >> 7
def decode(self): nla.decode(self) size = 0 for field in self.fields + self.header: if 'opt' in field: # Ignore this field as it a hack used to brain encoder continue size += struct.calcsize(field[1]) start = self.offset + size end = self.offset + self.length data = self.data[start:end] self['opt'] = self.parse_ematch_options(self, data)
def decode(self): self.header = None self.length = 24 nla.decode(self) # Patch to have a better view in nldecap attrs = dict(self['attrs']) rvalue = attrs.get('TCA_EM_META_RVALUE') meta_hdr = attrs.get('TCA_EM_META_HDR') meta_id = meta_hdr['id'] rvalue = bytearray.fromhex(rvalue.replace(':', '')) if meta_id == 'TCF_META_TYPE_VAR': rvalue.decode('utf-8') if meta_id == 'TCF_META_TYPE_INT': rvalue = unpack('<I', rvalue)[0] self['attrs'][2] = ('TCA_EM_META_RVALUE', rvalue)
def decode(self): self.header = None self.length = 24 nla.decode(self) self['align'] = self['align_flags'] & 0x0F self['flags'] = (self['align_flags'] & 0xF0) >> 4 self['layer'] = self['layer_opnd'] & 0x0F self['opnd'] = (self['layer_opnd'] & 0xF0) >> 4 del self['layer_opnd'] del self['align_flags'] # Perform translation for readability with nldecap self['layer'] = 'TCF_LAYER_{}'.format(LAYERS_DICT[self['layer']][0])\ .upper() self['align'] = 'TCF_EM_ALIGN_{}'.format(ALIGNS_DICT[self['align']])\ .upper() self['opnd'] = 'TCF_EM_OPND_{}'.format(OPERANDS_DICT[self['opnd']][0])\ .upper()
def decode(self): nla.decode(self) self['id'] = (self['kind'] & TCF_META_TYPE_MASK) >> 12 if self['id'] == TCF_META_TYPE_VAR: self['id'] = 'TCF_META_TYPE_VAR' elif self['id'] == TCF_META_TYPE_INT: self['id'] = 'TCF_META_TYPE_INT' else: pass self['kind'] &= TCF_META_ID_MASK for k, v in META_ID.items(): if self['kind'] == v: self['kind'] = 'TCF_META_ID_{}'.format(k.upper()) fmt = 'TCF_EM_OPND_{}'.format(OPERANDS_DICT[self['opnd']][0] .upper()) self['opnd'] = fmt del self['pad']
def decode(self): # Decode the data nla.decode(self) # Convert the packed IP address to its string representation self['value'] = inet_ntop(AF_INET6, self['value'])
def decode(self): nla.decode(self) self['delay_corr'] = round(u32_percent(self['delay_corr']), 2) self['loss_corr'] = round(u32_percent(self['loss_corr']), 2) self['dup_corr'] = round(u32_percent(self['dup_corr']), 2)
def decode(self): nla.decode(self) self.value = self.ops.get(self['value'])
def decode(self): nla.decode(self) self.value = state_by_code[self['value']]
def decode(self): nla.decode(self) self.value = frozenset(o for i, o in enumerate(self.ops) if self['value'] & 1 << i)
def decode(self): nla.decode(self) self['ac_comm'] = self['ac_comm'][:self['ac_comm'].find('\0')]
def decode(self): nla.decode(self) if isinstance(self['value'], tuple): self['value'] = (self['value'][0] & 0xffffffffffffffff) | \ (self['value'][1] << 64)
def decode(self): nla.decode(self) self['prob_corrupt'] = round(u32_percent(self['prob_corrupt']), 2) self['corr_corrupt'] = round(u32_percent(self['corr_corrupt']), 2)
def decode(self): nla.decode(self) for key, value in tc_flow_modes.items(): if self['flow_mode'] == value: self['flow_mode'] = key break
def decode(self): nla.decode(self) self['prob_reorder'] = round(u32_percent(self['prob_reorder']), 2) self['corr_reorder'] = round(u32_percent(self['corr_reorder']), 2)
def decode(self): nla.decode(self) # convert to usec units self['jitter'] = float(self['jitter']) / 1000
def decode(self): nla.decode(self) # convert to usec units self['delay'] = float(self['delay']) / 1000
def decode(self): nla.decode(self) self['mac'] = ':'.join(['%02x' % x for x in self['mac'][:6]])
def decode(self): nla.decode(self) self.value = state_by_code[self["value"]]
def decode(self): nla.decode(self) self['mac'] = ':'.join( ['%02x' % x for x in self['mac'][:6]])
def decode(self): nla.decode(self) self.value = '%s:%s' % (self['start'], self['end'])
def decode(self): nla.decode(self) self['ib_port_guid'] = ':'.join( ['%02x' % x for x in self['ib_port_guid'][4:12][::-1]])
def decode(self): nla.decode(self) self['value'] = b64encode(self['value'])
def decode(self): nla.decode(self) self['latest handshake'] = ctime(self['tv_sec'])