Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

linux: add support of ip neigh get #723

Merged
merged 1 commit into from
Sep 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions pyroute2/iproute/linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,15 @@ def neigh(self, command, **kwarg):
Dump all the records in the NDB::

ip.neigh('dump')

**get**

Get specific record (dst and ifindex are mandatory). Available
only on recent kernel::

ip.neigh('get',
dst='172.16.45.1',
ifindex=idx)
'''
if (command == 'dump') and ('match' not in kwarg):
match = kwarg
Expand All @@ -931,6 +940,7 @@ def neigh(self, command, **kwarg):
'remove': (RTM_DELNEIGH, flags_make),
'delete': (RTM_DELNEIGH, flags_make),
'dump': (RTM_GETNEIGH, flags_dump),
'get': (RTM_GETNEIGH, flags_base),
'append': (RTM_NEWNEIGH, flags_append)}

(command, flags) = commands.get(command, command)
Expand Down
12 changes: 12 additions & 0 deletions tests/general/test_ipr.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,18 @@ def test_neigh_filter(self):
assert len(self.ip.get_neighbours(match=lambda x: x['ifindex'] ==
self.ifaces[0])) == 2

def test_neigh_get(self):
require_user('root')
ifaddr1 = self.ifaddr(1)
self.ip.neigh('add',
dst=ifaddr1,
lladdr='00:11:22:33:44:55',
ifindex=self.ifaces[0])
res = self.ip.neigh('get',
dst=ifaddr1,
ifindex=self.ifaces[0])
assert res[0].get_attr("NDA_DST") == ifaddr1

def test_mass_ipv6(self):
#
# Achtung! This test is time consuming.
Expand Down