Commit a468db8d authored by Florent Fourcot's avatar Florent Fourcot

netlink: add flags in __repr__ of nla_slot

On ipset module, flags are one important value for debugging. Without
BYTEORDER set, ipset modules raises often a netlink error.

It's hard to debug with debuger.py since it prints exactly the same
structure with or without flags set. With this patch, the issue will be
easy to spot.
parent fba4528b
......@@ -1376,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()
......@@ -1401,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