Open ffourcot opened 4 years ago
#!/usr/bin/env python3
import pyroute2
class CustomIPRoute(pyroute2.IPRoute):
def get_neighbours(self, family=None, match=None, **kwargs):
if match is None:
match = {}
match.update(kwargs)
return self.neigh('dump', family=family, match=match)
def main():
ip = CustomIPRoute()
# Example: Get neighbors with a specific master
neighbors = ip.get_neighbours(master=2)
for neighbor in neighbors:
print(neighbor)
if __name__ == '__main__':
main()
Hello,
get_neighbours is defined by a very simple function:
So, kwarg are never given to neigh() method. This has a big side effect, since NLA list building is based only on kwarg, and not on match:
We can compare netlink message generated with both methods:
Out of performance, it does not have any impact. But on arp cache, it's easy to have some performance issue