简体   繁体   English

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

[英]Send a ping through a specific next hop in linux userspace C

How can I send icmp requests and control the next hop from a Linux C user space application I'm writing.如何从我正在编写的 Linux C 用户空间应用程序发送icmp请求并控制下一跳。

I have a single NIC ( 192.168.1.10/24 ) which is connected to 2 routers on the same subnet ( 192.168.1.1 and 192.168.1.2 ).我有一个网卡( 192.168.1.10/24 ),它连接到同一子网( 192.168.1.1192.168.1.2 )上的 2 个路由器。

I would like to reach the internet ( 8.8.8.8 ) through 192.168.1.1 and 192.168.1.2 and decide what is my default route according to the latency results.我想通过192.168.1.1192.168.1.2访问互联网( 8.8.8.8 ),并根据延迟结果决定我的默认路由是什么。

Is there a way I could control the immediate next hop in user space C ?有没有办法可以控制用户空间 C 中的下一跳? I'm using raw sockets.我正在使用原始套接字。

You can use 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]在计算机网络中,源路由,也称为路径寻址,允许数据包的发送者部分或完全指定数据包通过网络所采用的路由。 [1] In contrast, in conventional routing, routers in the network determine the path incrementally based on the packet's destination.相比之下,在传统路由中,网络中的路由器根据数据包的目的地逐步确定路径。

Note, though, it's quite common for source-routed packets to be summarily and silently dropped as there's no way for the receiver to trust that they came from where they seem to have come from without alteration.但是请注意,源路由数据包被突然和静默丢弃是很常见的,因为接收器无法相信它们来自它们似乎来自的地方而没有改变。

Sonicwall has this to say about their firewall configuration : Sonicwall 关于他们的防火墙配置是这样说的

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 数据包-(默认启用。)如果您正在测试两个特定主机之间的流量并且您正在使用源路由,请清除此复选框。

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. IP 源路由是 IP 中的一个标准选项,它允许数据包的发送者指定应该用于将数据包送到其目的地的部分或全部路由器。

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.这个 IP 选项通常被阻止使用,因为它可以被窃听者用来接收数据包,方法是插入一个选项,通过路由器 C 将数据包从 A 发送到 B。路由表应该控制数据包采用的路径,以便它不会被发送者或下游路由器覆盖。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM