1
votes

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

1 Answers

1
votes

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.