【问题标题】:How to use netlink to monitor the kernel arp table in userspace deamon?如何使用netlink监控用户空间守护进程中的内核arp表?
【发布时间】:2012-10-22 17:53:01
【问题描述】:

我知道我们可以使用带有 RTM_F_NOTIFY 标志的 'NETLINK_ROUTE' 套接字来通知用户是否根据 RFC3549 更改路由。但是我找不到一种在 arp 表更改时通知用户的方法。

PS:我用的是linux kernel 3.0.6

【问题讨论】:

    标签: linux sockets netlink


    【解决方案1】:

    应该使用NETLINK_ROUTE 套接字和bind() 到组RTNLGRP_NEIGH

    之后可以通过recv() 获得ndmsg 通知。请注意,必须使用所有通知,否则套接字将在溢出后引发ENOBUF 异常和下一个recv()

    或使用外部ip(8) 实用程序:

    $ ip monitor all    # get all the notifications
    $ ip monitor neigh  # get only arp notifications
    

    或者使用 Python library:

    from pyroute2 import IPRoute
    from pprint import pprint
    
    ip = IPRoute()
    ip.bind()  # subscribe to all the events
    while True:
        pprint(ip.get())
    

    【讨论】:

      【解决方案2】:

      如果我理解你的话 - 我建议你分析“ip”程序的来源。当您运行“ip monitor”并添加或删除任何 ARP 条目时,“ip monitor”将向您显示相应的消息。

      【讨论】:

        【解决方案3】:

        我不知道纯 arp 通知,但您可以使用在用户空间中运行的 arpd,它适用于 arp 表非常大的情况。如果您使用 arpd 并对其进行修改,则可以使其向您发送有关 arp 表更改的通知。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2011-03-02
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-01-16
          • 1970-01-01
          相关资源
          最近更新 更多