Commit f352dd46 authored by Peter V. Saveliev's avatar Peter V. Saveliev Committed by GitHub

netlink: merge pull request #327 from ffourcot/nla_flags

Nla flags support
parents 8fa05bcd a468db8d
......@@ -1333,9 +1333,10 @@ class nlmsg_base(dict):
while offset - self.offset <= self.length - 4:
nla = None
# pick the length and the type
(length, msg_type) = struct.unpack_from('HH', self.data, offset)
(length, base_msg_type) = struct.unpack_from('HH', self.data,
offset)
# first two bits of msg_type are flags:
msg_type = msg_type & ~(NLA_F_NESTED | NLA_F_NET_BYTEORDER)
msg_type = base_msg_type & ~(NLA_F_NESTED | NLA_F_NET_BYTEORDER)
# rewind to the beginning
length = min(max(length, 4), (self.length - offset + self.offset))
# we have a mapping for this NLA
......@@ -1357,8 +1358,8 @@ class nlmsg_base(dict):
length=length,
init=prime['init'])
nla.nla_array = prime['nla_array']
nla.nla_flags = msg_type & (NLA_F_NESTED |
NLA_F_NET_BYTEORDER)
nla.nla_flags = base_msg_type & (NLA_F_NESTED |
NLA_F_NET_BYTEORDER)
name = prime['name']
else:
name = 'UNKNOWN'
......@@ -1375,17 +1376,29 @@ class nla_slot(object):
def __init__(self, name, value):
self.cell = (name, value)
def get_value(self):
def try_to_decode(self):
try:
cell = self.cell[1]
if not cell.decoded:
cell.decode()
return cell.getvalue()
return True
except Exception:
log.warning("decoding %s" % (self.cell[0]))
log.warning(traceback.format_exc())
return False
def get_value(self):
cell = self.cell[1]
if self.try_to_decode():
return cell.getvalue()
else:
return cell.data[cell.offset:cell.offset+cell.length]
def get_flags(self):
if self.try_to_decode():
return self.cell[1].nla_flags
return None
def __getitem__(self, key):
if key == 1:
return self.get_value()
......@@ -1400,6 +1413,8 @@ class nla_slot(object):
raise IndexError(key)
def __repr__(self):
if self.get_flags():
return repr((self.cell[0], self.get_value(), self.get_flags()))
return repr((self.cell[0], self.get_value()))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment