Linux用户空间L2控制协议 [英] Linux user space L2 control protocols

查看:138
本文介绍了Linux用户空间L2控制协议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网络设备,其中以太网交换芯片的端口连接到CPU的网络控制器.交换芯片将数据包从其他端口转发到CPU端口,并添加特殊报头(在MAC报头之前),其中包含诸如入口端口等信息.

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.

在网络控制器驱动程序中接收到数据包时,我可以剥离标题,因此Linux网络堆栈可以正常方式与交换机通信.但是,我的目标是将特殊标头中的某些信息传递给用户空间第2层控制协议套件.

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.

在我的情况下,第2层控制协议通常会使用原始套接字来接收其控制帧.例如,生成树协议必须能够分辨出数据包来自哪个交换机端口.

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.

此外,诸如http,telnet服务器等服务应能够使用相同的网络接口.

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

是否有Linux内置方法将这些信息从驱动程序传递到用户空间网络服务器/客户端? 如果没有,对实施此方法有什么建议吗?

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?

我可以实现一个简单的ioctl调用,以向驱动程序查询读取的最后一个数据包的标头信息.但是,不能保证recv()ioctl()之间的其他进程没有使用该设备.

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().

推荐答案

我认为实现此目的的最佳方法是在

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. 将值存储在套接字结构中 ,并稍后使用ioctl;
  2. 返回
  3. 返回recvfrom中的值src_addr 直接
  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

希望获得帮助.

这篇关于Linux用户空间L2控制协议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆