How would a router handle a packet addressed to it?

chrstrbrts

Senior member
Aug 12, 2014
522
3
81
Hi,

What if I created a packet with a terminal destination IP address that belongs to a router? That is, what would happen if I sent a packet to a router as my terminal destination? How would the router process it?
 

Ken g6

Programming Moderator, Elite Member
Moderator
Dec 11, 1999
16,643
4,581
75
The same thing that would happen if you sent a packet to any other (usually) Linux *NIX-based computer. If you send a packet with "GET /\n\n" to TCP port 80 you might get the router's login page.
 

mv2devnull

Golden Member
Apr 13, 2010
1,526
160
106
Just like every other packet.
A routing decision is made.
The result is to forward the packet to localhost.

Do you configure a router with browser or ssh? If yes, then you have already sent packets with the router as terminal destination and have had a connection to httpd (or sshd) that runs on the router.
 

Gryz

Golden Member
Aug 28, 2010
1,551
204
106
What if I created a packet with a terminal destination IP address that belongs to a router? That is, what would happen if I sent a packet to a router as my terminal destination? How would the router process it?
A router consists of 2 major components.

1) The "forwarding plane".
2) The "control plane".

The forwarding plane is software or hardware that does nothing but:
a) receive incoming packets
b) look at the destination ip-address
c) look-up the destination ip-address in the forwarding table (aka the "FIB")
d) find the outgoing interface and next-hop ip-address in that "FIB-entry"
e) forward the packet out that interface to the next-hop as specified in the FIB-entry

The "forwarding-plane" can be a process running in user-space on a Linux-box. It can be code inside the kernel on a Linux box. It can be an interrupt-routine in the kernel in a Linux-box. Or it can be c-code running on a cpu on a line-card in a bigger router. Or it can be firmware running on an ASIC or a FPGA. Or even firmware running on a NPU (special chip, like a CPU, but for packet-forwarding). The whole idea of a "forwarding-plane" is that it is simple. All state it has is inside the FIB (Forwarding Information Base). All it does is forward packets.

The control-plane does not forward packets. The control-plane is very much like a regular computer. It has a CPU and RAM. Maybe long-term memory too (flash, or an SSD, or whatever). It runs a full-blow OS. Based on Unix, Linux, or some real-time version of Unix. It might be an (old) type of OS, like vXworks. Or a home-grown OS (like Classic IOS). It has a scheduler, runs processes (or Tasks). Maybe does multi-threading. It runs processes that do routing-protocols. The routing-protocols build a routing-table (the RIB). The RIB is simplified and copied to the forwarding-plane, where it is called the FIB. The control-plane also runs CLI-processes (like Unix-shells), it runs an SNMP-demon, etc, etc.

When you send a packet to a router, destined for one of its own ip-addresses, this happens:
1) the router receives the packet
2) does a lookup for the destination ip-address in the FIB
3) find an entry in the FIB that indicates that the ip-address belongs to the router itself
4) the forwarding-plane *punts* the packet up, to the control-plane
(The word "punt" is used for that: a packet is not forwarded, but given to the control-plane)
5) the control-plane looks at the destination-ip-address, the tcp-portnumber, etc
6) the control-plane gives the packet to the TCP component
7) the TCP component gives the packet to one of the tasks running on the control-plane
e.g. the sshd demon, the BGP task, the HTTP demon, etc

I hope this de-mystifies what a router does.