Linux user space L2 control protocols

試著忘記壹切 提交于 2019-12-24 12:44:33

问题


I have a network device where a port of an Ethernet switch chip is connected to a CPU's network controller. The switch chip forwards packets from other ports to the CPU port with special header added (before MAC header) containing such information as ingress port etc.

I can strip the header when receiving the packets in the network controller driver, so the Linux network stack can communicate with the switch in a normal way. My goal, however, is to pass some information in the special headers to a user space Layer 2 control protocol suite.

In my case, a Layer 2 control protocol would normally use a raw socket to receive its control frames. For example, the Spanning Tree Protocol must be able to tell from which switch port did the packet come from.

Also, services such as http, telnet server etc should be able to use the same network interface.

Are there any Linux built-in means for delivering such information from a driver to the user space network server / client? If not, any suggestions on implementing this?

I could implement a simple ioctl call to query the driver about the header information of the last packet that was read. However, there is no guarantee that the device was not used by other processes between recv() and ioctl().


回答1:


I think the best way to implement this would be to add a field in sk_buff to store your special L2 header. If I understand correctly, headers should be preserved when passing sk_buffs from one layer to another, albeit, you might need to add some code to skb_clone.

If you reach this point, sending this value to user-space is only limited by your imagination. For example, you could

  1. store the value in the socket structure sock and return it later using an ioctl;
  2. return the value in recvfrom's src_addr directly

Hope this help.



来源:https://stackoverflow.com/questions/10947433/linux-user-space-l2-control-protocols

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!