Commit f32baf46 authored by MXAmin's avatar MXAmin Committed by Peter V. Saveliev

tc: fix HTB QDisc generation with default arguments

When we call `tc` function for creating the HTB QDisc with NO kwargs,
the kernel will return error 22 (invalid argument)::

	 ip.tc("add", "htb", eth0, 0x10000)
	 pyroute2.netlink.exceptions.NetlinkError: (22, 'Invalid argument')

As you can see by calling the `tc` function without any additional
arguments (we only defined `command`, `kind`, `index` and `handle`
arguments) the module will raise `NetlinkError`; reason: according to
'net/sched/sch_htb.c' of linux kernel source code, to create a HTB
QDisc we also need to define `direct_pkts`, `rate2quantum` and
`defcls` which is not defined by default (the function `get_parameters`
is responsible for providing these default arguments which WON'T be
called unless we have at least ONE argument in kwargs.

Bug-Url: https://github.com/svinota/pyroute2/pull/308
parent 62de83cd
......@@ -1459,7 +1459,7 @@ class IPRouteMixin(object):
msg['parent'] = kwarg.get('parent', TC_H_ROOT)
if kind is not None:
msg['attrs'] = [['TCA_KIND', kind]]
msg['attrs'].append(['TCA_KIND', kind])
if opts is not None:
msg['attrs'].append(['TCA_OPTIONS', opts])
return self.nlm_request(msg, msg_type=command, msg_flags=flags)
......
......@@ -122,6 +122,12 @@ def get_parameters(kwarg):
'version': version}]]}
def fix_msg(msg, kwarg):
if not kwarg:
opts = get_parameters({})
msg['attrs'].append(['TCA_OPTIONS', opts])
class stats(nla):
fields = (('lends', 'I'),
('borrows', 'I'),
......
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