diff --git a/nlmanager/nlpacket.py b/nlmanager/nlpacket.py index 8b1a951..83e8c12 100644 --- a/nlmanager/nlpacket.py +++ b/nlmanager/nlpacket.py @@ -205,6 +205,10 @@ class Attribute(object): return raw def encode(self): + + if not self.LEN: + raise Exception('Please define an encode() method in your child attribute class, or do not use AttributeGeneric') + length = self.HEADER_LEN + self.LEN attr_type_with_flags = self.atype @@ -447,6 +451,14 @@ class AttributeGeneric(Attribute): raise +class AttributeOneByteValue(AttributeGeneric): + + def __init__(self, atype, string, logger): + Attribute.__init__(self, atype, string, logger) + self.PACK = '=B' + self.LEN = calcsize(self.PACK) + + class AttributeIFLA_AF_SPEC(Attribute): """ value will be a dictionary such as: @@ -1638,7 +1650,7 @@ class Link(NetlinkPacket): IFLA_PHYS_SWITCH_ID : ('IFLA_PHYS_SWITCH_ID', AttributeGeneric), IFLA_LINK_NETNSID : ('IFLA_LINK_NETNSID', AttributeGeneric), IFLA_PHYS_PORT_NAME : ('IFLA_PHYS_PORT_NAME', AttributeGeneric), - IFLA_PROTO_DOWN : ('IFLA_PROTO_DOWN', AttributeGeneric), + IFLA_PROTO_DOWN : ('IFLA_PROTO_DOWN', AttributeOneByteValue), IFLA_LINKPROTODOWN : ('IFLA_LINKPROTODOWN', AttributeGeneric) }