简体   繁体   中英

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.

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

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.

Is there a way I could control the immediate next hop in user space 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] 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 :

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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