mirror of
https://github.com/xen-project/xen.git
synced 2026-10-28 10:11:27 +01:00
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>
This commit is contained in:
1 parent
147e14cc8e
commit
c6a0974ed9
2 files changed
+10
-6
No files matched your search
@@ -1,5 +1,7 @@
|
||||
# netlink wrappers
|
||||
|
||||
# See include/linux/netlink.h and rtnetlink.h
|
||||
|
||||
import socket, struct
|
||||
import xen.lowlevel.netlink
|
||||
|
||||
@@ -77,9 +79,9 @@ class rtattr(object):
|
||||
return align(self.rta_len)
|
||||
|
||||
def pack(self):
|
||||
self.rta_len = self.fmtlen + align(len(self.body), 2)
|
||||
self.rta_len = self.fmtlen + len(self.body)
|
||||
s = struct.pack(self.fmt, self.rta_len, self.rta_type) + self.body
|
||||
pad = self.rta_len - len(s)
|
||||
pad = align(self.rta_len) - len(s)
|
||||
if pad:
|
||||
s += '\0' * pad
|
||||
return s
|
||||
@@ -127,14 +129,16 @@ class nlmsg(object):
|
||||
attr.rta_type = type
|
||||
attr.body = data
|
||||
self.rta += attr.pack()
|
||||
self.nlmsg_len = len(self)
|
||||
|
||||
def settype(self, cmd):
|
||||
self.nlmsg_type = cmd
|
||||
|
||||
def pack(self):
|
||||
return struct.pack(self.fmt, len(self), self.nlmsg_type,
|
||||
s = struct.pack(self.fmt, len(self), self.nlmsg_type,
|
||||
self.nlmsg_flags, self.nlmsg_seq,
|
||||
self.nlmsg_pid) + self.body + self.rta
|
||||
return s
|
||||
|
||||
def unpack(self, msg):
|
||||
args = struct.unpack(self.fmt, msg[:self.fmtlen])
|
||||
|
||||
@@ -35,7 +35,7 @@ class addrequest(request):
|
||||
flags = netlink.NLM_F_EXCL|netlink.NLM_F_CREATE
|
||||
super(addrequest, self).__init__(netlink.RTM_NEWQDISC, flags=flags,
|
||||
dev=dev, handle=handle)
|
||||
self.n.addattr(netlink.TCA_KIND, qdisc.kind)
|
||||
self.n.addattr(netlink.TCA_KIND, qdisc.kind + '\0')
|
||||
opts = qdisc.pack()
|
||||
if opts:
|
||||
self.n.addattr(netlink.TCA_OPTIONS, opts)
|
||||
@@ -49,7 +49,7 @@ class changerequest(request):
|
||||
def __init__(self, dev, handle, qdisc):
|
||||
super(changerequest, self).__init__(netlink.RTM_NEWQDISC,
|
||||
dev=dev, handle=handle)
|
||||
self.n.addattr(netlink.TCA_KIND, qdisc.kind)
|
||||
self.n.addattr(netlink.TCA_KIND, qdisc.kind + '\0')
|
||||
opts = qdisc.pack()
|
||||
if opts:
|
||||
self.n.addattr(netlink.TCA_OPTIONS, opts)
|
||||
@@ -59,7 +59,7 @@ class Qdisc(object):
|
||||
if qdict:
|
||||
kind = qdict.get('kind')
|
||||
cls = qdisc_kinds.get(kind, cls)
|
||||
obj = super(Qdisc, cls).__new__(cls, qdict=qdict, *args, **opts)
|
||||
obj = super(Qdisc, cls).__new__(cls)
|
||||
return obj
|
||||
|
||||
def __init__(self, qdict):
|
||||
|
||||