通过 linux 用户空间 C 中的特定下一跳发送 ping

Send a ping through a specific next hop in linux userspace C

如何从我正在编写的 Linux C 用户 space 应用程序发送 icmp 请求并控制下一跳。

我有一个 NIC (192.168.1.10/24),它连接到同一子网中的 2 个路由器(192.168.1.1192.168.1.2)。

我想通过 192.168.1.1192.168.1.2 访问互联网 (8.8.8.8),并根据延迟结果决定我的默认路由。

有什么方法可以控制用户 space C 中的下一跃点?我正在使用原始套接字。

您可以使用 source-routing:

In computer networking, source routing, also called path addressing, allows a sender of a packet to partially or completely specify the route the packet takes through the network.[1] In contrast, in conventional routing, routers in the network determine the path incrementally based on the packet's destination.

但是请注意,源路由数据包被草率地和静默地丢弃是很常见的,因为接收方无法相信它们来自它们似乎来自的地方而没有改变。

Sonicwall has this to say about their firewall configuration:

Drop Source Routed IP Packets - (Enabled by default.) Clear this checkbox if you are testing traffic between two specific hosts and you are using source routing.

IP Source Routing is a standard option in IP that allows the sender of a packet to specify some or all of the routers that should be used to get the packet to its destination.

This IP option is typically blocked from use as it can be used by an eavesdropper to receive packets by inserting an option to send packets from A to B via router C. The routing table should control the path that a packet takes, so that it is not overridden by the sender or a downstream router.