0

Presume I have a route table with such entries:

typedef struct route_table_entry {
    uint32_t prefix;
    uint32_t next_hop;
    uint32_t mask;
    int interface;
} route_table_entry;

I have a network with 4 hosts and a router, all host are only bound to the router. enter image description here

I try to ping from h0 to h1. The first request is an ARP request. So as the router I have to first: cache h0 IP and MAC into an ARP table like this:

typedef struct arp_table_entry {
    uint32_t ipaddr;                /* IP address */
    uint8_t mac[ETH_ALEN];          /* MAC address */
    int interface;                  /* Interface number */
    int ttl;                        /* Time to live. */
} arp_table_entry;

But how do I find the interface if the ARP request or ether header doesn't include the interface? Should I use the route table? If so, how? Nevertheless, I get the ARP Request and I send it to all my available interfaces, right?

for (size_t i = 0; i < ROUTER_NUM_INTERFACES; ++i)  {
                rc = send_packet(interfaces[i], &m);
                DIE (rc < 0, "send_message");
            }

Isn't that what broadcast means? then I wait for a response, again I get a response an ARP-Reply this time, but I don't know to whom to send it, because I don't how from which interface the request came from, how should I go around it?

  • "all host are only bound to the router." Hosts do not bind to a router, they are connected to a network, and they send frames to a router for packets destined to a different network than the one the host is on, otherwise they send it directly to the destination host on the same network, not involving the router. ARP is only used for hosts on the same network. – Ron Maupin Mar 26 at 12:47
  • @RonMaupin This is cleared in the comment section of the answer below. – C. Cristi Mar 26 at 12:52
  • Also, remember that not every data-link protocol uses ARP, nor does every network protocol use ARP. – Ron Maupin Mar 27 at 13:48
  • What kind of protocols are there that perform the same operation as ARP? @RonMaupin – C. Cristi Mar 27 at 13:50
  • 1
    Well, if you look at PPP, it does not need ARP because there are only two hosts, so every frame sent is destined to the only other host on the network. Frame relay uses DLCI as the address not MAC addressing, and it can use Inverse ARP. ATM uses VPI/VCI as the addressing, and it can use Inverse ARP. IPv6 does not have broadcast, so it cannot use ARP, but uses NDP. Remember that only the IEEE protocols use MAC addressing, some of which use 48-bit MAC addresses and some of which use 64-bit MAC addresses. There are a multitude of data-link protocols. – Ron Maupin Mar 27 at 13:55
1

I have a network with 4 hosts and a router, all host are only bound to the router. I try to ping from h0 to h1. The first request is an ARP request.

Hosts within the same subnet don't use a router but talk directly to each other, by using ARP for the destination IP and using the resulting MAC for encapsulation. No router is involved.

When hosts are located in different subnets, the local routing table tells a host to use a gateway. The host ARPs the gateway (if not in cache) and sends the IP packet to that MAC.

In turn, the router ARPs the destination IP (or another gateway, as determined by its routing table) and sends the packet to that MAC.

In detail, sending from H0 to H1 across the router looks like this:

  1. H0 checks its routing table for H1, finding it requires R-0 as gateway.
  2. H0 ARPs R-0's IP for its MAC address.
  3. H0 sends the packet to R-0's MAC address.
  4. The router checks its routing table for H1, finding it attached locally to R-1.
  5. The router ARPs H1's IP address for its MAC on R-1.
  6. The router sends the packet out of R-1 to H1's MAC.

But how do I find the interface if the ARP request or ether header doesn't include the interface?

The interface is the one the ARP request was sent from (by broadcast) and the ARP response was received on. The ARP request is sent from the interface that is attached to the destination IP's subnet. That interface is determined by the local routing table.

In case you're asking about the router's use of ARP from the perspective of a host: whether or not and how a router (or anyone else) uses ARP is of no consequence to a host in another subnet. It doesn't and can't know about it.

| improve this answer | |
  • All hosts are in different subnets... I was trying to emphasize that there are only 4. – C. Cristi Mar 26 at 11:09
  • I have added those details to the answer. – Zac67 Mar 26 at 11:13
  • And in the route table, I search for the source ip address from the ARP request, or I search for the IP i want to search for by ANDING it with the current mask and finding a prefix? and the if the prefix matches I send on that particular interface? – C. Cristi Mar 26 at 11:14
  • Also, If I am the router, how to I send the ARP_packet broadcast, is it okay how I did in the question? Or do I have to set the destination hw address of the arp packet some special value to denote that it is indeed a broadcast? – C. Cristi Mar 26 at 11:29
  • 1
    @C.Cristi "I as the router send this ARP req broadcast to every interface" No, that is not how ARP works. Every router interface is in a different network, but ARP is only for one network. You use ARP to resolve the layer-3 (network) address to the layer-2 address. For a particular destination, you only send an ARP request on the network where that host will be found. – Ron Maupin Mar 27 at 13:39
1

The answer to your question is, you need a packet descriptor which you populate upon receiving a packet, with information including which interface received it.

But how do I find the interface if the ARP request or ether header doesn't include the interface? Should I use the route table?

Don't use the route table to figure out where you received a packet from. If you are using a raw socket (e.g. in Linux) receiving packets from an interface, you know which interface delivered that packet to your program, because you know which socket it arrived on. Save that information for your further processing steps.

| improve this answer | |
  • Can you explain to me how the routing process works? – C. Cristi Mar 26 at 18:00
  • @C.Cristi, routing happens based on the destination address in the packet header. That is looked up in the routing table. Routing does not really care where a packet originated, only where it is going, and each packet is routed independently, regardless of what came before. Asymmetric routing is actually pretty common. – Ron Maupin Mar 26 at 19:11
  • @RonMaupin When I forward a packet to another interface shouldn't it come again to me? as the router? – C. Cristi Mar 27 at 9:42
  • Not necessarily. Once you have forwarded a packet, it is out of your hands, and it will be forwarded by the rules of the next router, which may be different than your rules. The same thing for replies. Each packet is forwarded independently, regardless of what came before. Routers do not maintain state. IP was designed as a stateless protocol on purpose, so that packets can automatically be rerouted in the event of a failure in the Internet. That was a big advantage over the circuit-switched telephone network, and the very reason IP was created. – Ron Maupin Mar 27 at 12:29
  • @RonMaupin I understand now, thanks! The question was based that in my network that I created there is only 1 router.. – C. Cristi Mar 27 at 13:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.