From b1f2af00689e17a50eb09b1560acfd0dc96b1a7a Mon Sep 17 00:00:00 2001 From: Florent Fourcot Date: Tue, 28 Jul 2020 17:16:20 +0200 Subject: [PATCH] linux: add support of ip neigh get This feature has been added in kernel recently (end of 2018), and is now in iproute2 as well --- pyroute2/iproute/linux.py | 10 ++++++++++ tests/general/test_ipr.py | 12 ++++++++++++ 2 files changed, 22 insertions(+) diff --git a/pyroute2/iproute/linux.py b/pyroute2/iproute/linux.py index e75d78523..b1699c77c 100644 --- a/pyroute2/iproute/linux.py +++ b/pyroute2/iproute/linux.py @@ -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 @@ -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) diff --git a/tests/general/test_ipr.py b/tests/general/test_ipr.py index 37a479226..1ead608b6 100644 --- a/tests/general/test_ipr.py +++ b/tests/general/test_ipr.py @@ -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.