Adding route with priority

61 views
Skip to first unread message

Ragan Gidde

unread,
Jul 24, 2017, 8:39:44 AM7/24/17
to pyroute2-dev
Hi,

Adding a route using IPRoute module. Route addition just works fine.

However, we are observing one specific behavior. Looks like route addition is not considering priority.

'raw' NLA notation:
ip.route("add", dst="10.0.0.0/24", gateway="192.168.58.1", metrics={'attrs': [('RTA_PRIORITY', 123)]})
[{'header': {'pid': 11458, 'length': 36, 'flags': 0, 'error': None, 'type': 2, 'sequence_number': 257}, 'event': 'NLMSG_ERROR'}]

or

Simplified way:
ip.route("add", dst="10.0.0.0/24", gateway="192.168.58.1", metrics={"priority": 123})
[{'header': {'pid': 11458, 'length': 36, 'flags': 0, 'error': None, 'type': 2, 'sequence_number': 257}, 'event': 'NLMSG_ERROR'}]

There is no error while adding the route. However we don't view the metric in the route dump.
>ip r
10.0.0.0/24 via 192.168.58.1 dev eth0  proto static

>>> ip.route('dump')[2]
{'family': 2, 'dst_len': 24, 'proto': 4, 'tos': 0, 'event': 'RTM_NEWROUTE', 'header': {'pid': 11458, 'length': 60, 'flags': 2, 'error': None, 'type': 24, 'sequence_number': 261}, 'flags': 0, 'attrs': [('RTA_TABLE', 254), ('RTA_DST', '10.0.0.0'), ('RTA_GATEWAY', '192.168.58.1'), ('RTA_OIF', 2)], 'table': 254, 'src_len': 0, 'type': 1, 'scope': 0}

Kindly let us know if we are missing anything here.

Thanks in advance.

Br,
Ragan






Peter Saveliev

unread,
Jul 24, 2017, 9:08:12 AM7/24/17
to Ragan Gidde, pyroute2-dev
I'm not sure that's exactly what you need, but I think now about RTA_PRIORITY that's not a part of RTA_METRICS (actually, there is no priority in metrics, afair), so try simply:

> ip.route("add", dst="10.0.0.0/24", gateway="192.168.58.1", priority=123)

Maybe that will help. Getting the routes with `ip route show` thereafter you will see `metric 123`.  That's a naming confusion, iproute uses `metric` for compatibility, pyroute2 uses `priority` since in the kernel code it's called `priority`, while `metrics` is used for a completely different thing.

--
You received this message because you are subscribed to the Google Groups "pyroute2-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyroute2-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ragan Gidde

unread,
Jul 25, 2017, 8:42:27 AM7/25/17
to pyroute2-dev, ragan...@gmail.com
Thanks so much. That's what i was looking for.
To unsubscribe from this group and stop receiving emails from it, send an email to pyroute2-dev...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages