Linux内核:skbuff结构-路由信息..
我有疑问,请澄清。假设我有一个像下面这样连接的系统,
A -> B-> C-> D
我需要将数据包从 A 发送到 D,因此当数据包移出 A 时,它应该更新数据包中或 skbuff 中某处的路由信息,以便数据包正确路由经过 B,从而到达目的地。
请让我知道数据包中的更新位置意味着 skbuff 中的哪个标头或哪个参数。
提前谢谢。
I have a doubt, pls clarify. Suppose I have a System connected like the below,
A -> B -> C -> D
I need to send a packet from A to D, so when a packet moves out of A, it should update the routing information somewhere in the packet or in the skbuff so that packet is routed correctly via B, so that it reaches the destination.
Pls let me know where it is updated in the packet means which header or which parameter in the skbuff..
Thnx in advance..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
从您看来,您只需要目标地址 D 和第一个网关(或路由器)B。您无需对数据包进行任何修改,这是在路由器中完成的。 C 或通往 D 的途中的任何其他路由器对您来说都是透明的。
From your view, you only need the target address D and the first gateway (or router) B. You don't make any modification in the packet, this is done in the router(s). C or any other routers on the way to D are transparent for you.
通常,这是通过更新数据包的源和目标 MAC 地址来实现的。这可以在数据包的以太网标头中找到(假设它通过以太网传输)。在正常的 UDP 或 TCP 路由中,您可以通过修改路由表完全在用户空间中完成此操作。
您正在实施自定义互联网协议吗?否则,自定义内核模块/补丁不太可能是正确的位置。
Normally this happens by updating the source and destination mac address of the packet. This would be found in the ethernet header of the packet (assuming it's travelling over ethernet). In normal UDP or TCP routing, you can do this completely in userspace by modifying the routing tables.
Are you implementing a custom internet protocol? Otherwise, it's unlikely that a custom kernel module / patch is the right place for this.
当数据包在该网络中从A发送到D时,A→D。 B-> C-> D,A 上的应用程序与 D 上的应用程序有一个套接字。A 处的 IP 需要通过路由找到下一跳,在本例中为 B。该信息也可以缓存在套接字中(在某些版本的Linux中,在socket->sock->dst_cache字段中)。 IP数据报的目标IP始终是D的IP。因此,B根据路由表将其转发到C,类似地C转发到D。
这是否回答了您的问题?
When the packet is being sent from A to D in this network, A -> B -> C -> D, application on A has a socket to application on D. The IP at A needs to find the next hop through routing, which would be B in this case. This information can be cached in socket as well(as in some versions of Linux, in the socket->sock->dst_cache field). The IP datagram always has destination IP as IP of D. So, B forwards it to C based on routing table and similarly C to D.
Does this answer your question?