Commit 94bbbef4 authored by Peter V. Saveliev's avatar Peter V. Saveliev

rtnl: compat proxy_linkinfo fix

parent 0d5c57ac
......@@ -298,8 +298,8 @@ class NetlinkMixin(object):
self.callbacks = [] # [(predicate, callback, args), ...]
self.pthread = None
self.closed = False
self.capabilities = {'create_bridge': True,
'create_bond': True,
self.capabilities = {'create_bridge': config.kernel > [3, 2, 0],
'create_bond': config.kernel > [3, 2, 0],
'create_dummy': True,
'provide_master': config.kernel[0] > 2}
self.backlog_lock = threading.Lock()
......
......@@ -10,6 +10,7 @@ from pyroute2 import RawIPRoute
from pyroute2 import config
from pyroute2.common import map_enoent
from pyroute2.netlink.rtnl import RTM_VALUES
from pyroute2.netlink.rtnl.marshal import MarshalRtnl
from pyroute2.netlink.rtnl.ifinfmsg import ifinfmsg
from pyroute2.netlink.exceptions import NetlinkError
......@@ -75,10 +76,12 @@ def compat_fix_attrs(msg, nl):
if kind is None:
kind = get_interface_type(ifname)
li['attrs'].append(['IFLA_INFO_KIND', kind])
else:
elif 'attrs' in msg:
kind = get_interface_type(ifname)
msg['attrs'].append(['IFLA_LINKINFO',
{'attrs': [['IFLA_INFO_KIND', kind]]}])
else:
return
li = msg.get_attr('IFLA_LINKINFO')
# fetch specific interface data
......@@ -107,20 +110,14 @@ def compat_fix_attrs(msg, nl):
def proxy_linkinfo(data, nl):
if config.kernel > [3, 2, 0]:
return {'verdict': 'forward',
'data': data}
offset = 0
inbox = []
while offset < len(data):
msg = ifinfmsg(data[offset:])
msg.decode()
inbox.append(msg)
offset += msg['header']['length']
marshal = MarshalRtnl()
inbox = marshal.parse(data)
data = b''
for msg in inbox:
if msg['event'] == 'NLMSG_ERROR':
data += msg.data
continue
# Sysfs operations can require root permissions,
# but the script can be run under a normal user
# Bug-Url: https://github.com/svinota/pyroute2/issues/113
......@@ -134,7 +131,7 @@ def proxy_linkinfo(data, nl):
msg.reset()
msg.encode()
data += msg.buf.getvalue()
data += msg.data
return {'verdict': 'forward',
'data': data}
......
......@@ -4,17 +4,10 @@ from pyroute2.common import Namespace
from pyroute2.common import AddrPool
from pyroute2.proxy import NetlinkProxy
from pyroute2.netlink import NETLINK_ROUTE
from pyroute2.netlink.nlsocket import Marshal
from pyroute2.netlink.nlsocket import NetlinkSocket
from pyroute2.netlink.nlsocket import BatchSocket
from pyroute2.netlink import rtnl
from pyroute2.netlink.rtnl.tcmsg import tcmsg
from pyroute2.netlink.rtnl.rtmsg import rtmsg
from pyroute2.netlink.rtnl.ndmsg import ndmsg
from pyroute2.netlink.rtnl.ndtmsg import ndtmsg
from pyroute2.netlink.rtnl.fibmsg import fibmsg
from pyroute2.netlink.rtnl.ifinfmsg import ifinfmsg
from pyroute2.netlink.rtnl.ifaddrmsg import ifaddrmsg
from pyroute2.netlink.rtnl.marshal import MarshalRtnl
if config.kernel < [3, 3, 0]:
from pyroute2.netlink.rtnl.ifinfmsg.compat import proxy_newlink
......@@ -26,44 +19,6 @@ else:
from pyroute2.netlink.rtnl.ifinfmsg import proxy_setlink
class MarshalRtnl(Marshal):
msg_map = {rtnl.RTM_NEWLINK: ifinfmsg,
rtnl.RTM_DELLINK: ifinfmsg,
rtnl.RTM_GETLINK: ifinfmsg,
rtnl.RTM_SETLINK: ifinfmsg,
rtnl.RTM_NEWADDR: ifaddrmsg,
rtnl.RTM_DELADDR: ifaddrmsg,
rtnl.RTM_GETADDR: ifaddrmsg,
rtnl.RTM_NEWROUTE: rtmsg,
rtnl.RTM_DELROUTE: rtmsg,
rtnl.RTM_GETROUTE: rtmsg,
rtnl.RTM_NEWRULE: fibmsg,
rtnl.RTM_DELRULE: fibmsg,
rtnl.RTM_GETRULE: fibmsg,
rtnl.RTM_NEWNEIGH: ndmsg,
rtnl.RTM_DELNEIGH: ndmsg,
rtnl.RTM_GETNEIGH: ndmsg,
rtnl.RTM_NEWQDISC: tcmsg,
rtnl.RTM_DELQDISC: tcmsg,
rtnl.RTM_GETQDISC: tcmsg,
rtnl.RTM_NEWTCLASS: tcmsg,
rtnl.RTM_DELTCLASS: tcmsg,
rtnl.RTM_GETTCLASS: tcmsg,
rtnl.RTM_NEWTFILTER: tcmsg,
rtnl.RTM_DELTFILTER: tcmsg,
rtnl.RTM_GETTFILTER: tcmsg,
rtnl.RTM_NEWNEIGHTBL: ndtmsg,
rtnl.RTM_GETNEIGHTBL: ndtmsg,
rtnl.RTM_SETNEIGHTBL: ndtmsg}
def fix_message(self, msg):
# FIXME: pls do something with it
try:
msg['event'] = rtnl.RTM_VALUES[msg['header']['type']]
except:
pass
class IPRSocketMixin(object):
def __init__(self, fileno=None):
......@@ -76,12 +31,16 @@ class IPRSocketMixin(object):
self._sproxy.pmap = {rtnl.RTM_NEWLINK: proxy_newlink,
rtnl.RTM_SETLINK: proxy_setlink}
if config.kernel < [3, 3, 0]:
recv_ns = Namespace(self, {'addr_pool': AddrPool(0x20000, 0x2ffff),
self._recv_ns = Namespace(self,
{'addr_pool': AddrPool(0x20000, 0x2ffff),
'monitor': False})
self._sproxy.pmap[rtnl.RTM_DELLINK] = proxy_dellink
self._rproxy = NetlinkProxy(policy='forward', nl=recv_ns)
self._rproxy.pmap = {rtnl.RTM_NEWLINK: proxy_linkinfo}
self.recv = self._p_recv
# inject proxy hooks into recv() and...
self.__recv = self._recv
self._recv = self._p_recv
# ... recv_into()
self._recv_ft = self.recv_ft
self.recv_ft = self._p_recv_ft
def clone(self):
return type(self)()
......@@ -113,8 +72,19 @@ class IPRSocketMixin(object):
return self._sendto(msg.data, addr)
def _p_recv_ft(self, bufsize, flags=0):
data = self._recv_ft(bufsize, flags)
ret = proxy_linkinfo(data, self._recv_ns)
if ret is not None:
if ret['verdict'] in ('forward', 'error'):
return ret['data']
else:
ValueError('Incorrect verdict')
return data
def _p_recv(self, bufsize, flags=0):
data = self._recv(bufsize, flags)
data = self.__recv(bufsize, flags)
ret = self._rproxy.handle(data)
if ret is not None:
if ret['verdict'] in ('forward', 'error'):
......
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