debuggers.hg

changeset 21284:99a85cb72c9f

Remus: python netlink fixes

Fix deprecation warning in Qdisc class under python 2.6.
Fix rtattr length and padding (rta_len is unaligned).
Null-terminate qdisc name in rtnl messages.

Signed-off-by: Brendan Cully <brendan@cs.ubc.ca>
author Keir Fraser <keir.fraser@citrix.com>
date Tue May 04 09:30:53 2010 +0100 (2010-05-04)
parents a167ea374f26
children 8559e324941f
files tools/python/xen/remus/netlink.py tools/python/xen/remus/qdisc.py
line diff
     1.1 --- a/tools/python/xen/remus/netlink.py	Thu Apr 29 19:38:52 2010 +0100
     1.2 +++ b/tools/python/xen/remus/netlink.py	Tue May 04 09:30:53 2010 +0100
     1.3 @@ -1,5 +1,7 @@
     1.4  # netlink wrappers
     1.5  
     1.6 +# See include/linux/netlink.h and rtnetlink.h
     1.7 +
     1.8  import socket, struct
     1.9  import xen.lowlevel.netlink
    1.10  
    1.11 @@ -77,9 +79,9 @@ class rtattr(object):
    1.12          return align(self.rta_len)
    1.13  
    1.14      def pack(self):
    1.15 -        self.rta_len = self.fmtlen + align(len(self.body), 2)
    1.16 +        self.rta_len = self.fmtlen + len(self.body)
    1.17          s = struct.pack(self.fmt, self.rta_len, self.rta_type) + self.body
    1.18 -        pad = self.rta_len - len(s)
    1.19 +        pad = align(self.rta_len) - len(s)
    1.20          if pad:
    1.21              s += '\0' * pad
    1.22          return s
    1.23 @@ -127,14 +129,16 @@ class nlmsg(object):
    1.24          attr.rta_type = type
    1.25          attr.body = data
    1.26          self.rta += attr.pack()
    1.27 +        self.nlmsg_len = len(self)
    1.28  
    1.29      def settype(self, cmd):
    1.30          self.nlmsg_type = cmd
    1.31  
    1.32      def pack(self):
    1.33 -        return struct.pack(self.fmt, len(self), self.nlmsg_type,
    1.34 +        s = struct.pack(self.fmt, len(self), self.nlmsg_type,
    1.35                             self.nlmsg_flags, self.nlmsg_seq,
    1.36                             self.nlmsg_pid) + self.body + self.rta
    1.37 +        return s
    1.38  
    1.39      def unpack(self, msg):
    1.40          args = struct.unpack(self.fmt, msg[:self.fmtlen])
     2.1 --- a/tools/python/xen/remus/qdisc.py	Thu Apr 29 19:38:52 2010 +0100
     2.2 +++ b/tools/python/xen/remus/qdisc.py	Tue May 04 09:30:53 2010 +0100
     2.3 @@ -35,7 +35,7 @@ class addrequest(request):
     2.4          flags = netlink.NLM_F_EXCL|netlink.NLM_F_CREATE
     2.5          super(addrequest, self).__init__(netlink.RTM_NEWQDISC, flags=flags,
     2.6                                           dev=dev, handle=handle)
     2.7 -        self.n.addattr(netlink.TCA_KIND, qdisc.kind)
     2.8 +        self.n.addattr(netlink.TCA_KIND, qdisc.kind + '\0')
     2.9          opts = qdisc.pack()
    2.10          if opts:
    2.11              self.n.addattr(netlink.TCA_OPTIONS, opts)
    2.12 @@ -49,7 +49,7 @@ class changerequest(request):
    2.13      def __init__(self, dev, handle, qdisc):
    2.14          super(changerequest, self).__init__(netlink.RTM_NEWQDISC,
    2.15                                              dev=dev, handle=handle)
    2.16 -        self.n.addattr(netlink.TCA_KIND, qdisc.kind)
    2.17 +        self.n.addattr(netlink.TCA_KIND, qdisc.kind + '\0')
    2.18          opts = qdisc.pack()
    2.19          if opts:
    2.20              self.n.addattr(netlink.TCA_OPTIONS, opts)
    2.21 @@ -59,7 +59,7 @@ class Qdisc(object):
    2.22          if qdict:
    2.23              kind = qdict.get('kind')
    2.24              cls = qdisc_kinds.get(kind, cls)
    2.25 -        obj = super(Qdisc, cls).__new__(cls, qdict=qdict, *args, **opts)
    2.26 +        obj = super(Qdisc, cls).__new__(cls)
    2.27          return obj
    2.28  
    2.29      def __init__(self, qdict):