3

Classless Interdomain Routing (CIDR) takes, in addition to a 32-bit IPv4 IP address, a prefix to tell the cut-off of the network ID.

IP header has room only 32-bit address fields.

And, an IP address can match two classless addresses: Eg. the IP address 222.10.5.11 would match both 222.10.0.0/21 and 222.10.5.0/23.

My Q is:

When a router R1 receives a packet addressed to host 222.10.5.11 of network 222.10.0.0/21, how does R1 know that this is a classless address and the network prefix is 21? Where is this network prefix written in the IP header?

TIA

//-----------------------------------------

EDIT:

I understand the routing protocols, like OSPF can pass the subnet mask and thus this prefix. But, for forwarding, when an IPv4 packet addressed to 222.10.5.11 comes in, how does IP know that this packet is for the host in 222.10.5.0/23?

2
  • 1
    It doesn't. As I said, it will go to the most specific route that matches.
    – Ricky
    Commented Oct 4, 2015 at 7:32
  • Did any answer help you? if so, you should accept the answer so that the question doesn't keep popping up forever, looking for an answer. Alternatively, you could provide and accept your own answer.
    – Ron Maupin
    Commented Aug 12, 2017 at 19:06

2 Answers 2

1

Routers use their route table to know where to send stuff. Your IP packet cannot tell my router how to deal with it. (there are options for "source routing" but every sane admin disables it.)

Routing flows to the most specific (longest prefix) match. If I have a route for 222/8 and a route for 222.10/16. The latter would apply -- 16 is greater than 8. In your example, the /23 would be the one used because it's the more specific route.

2
  • so you're saying, for the eg. in the Q above, the routing table incorrectly matches this packet to the one in 222.10.5.0/23 rather than its intended destination in 222.10.0.0/21?
    – ashley
    Commented Oct 4, 2015 at 5:42
  • @ashley, the correct match is the longest match so 222.10.0.0 would not be the correct match. The longest match gets you closer to the final destination. In the real world, both matches probably go out the same interface, but, even if they don't, the longest match proves that it knows more about which way to send the packet.
    – Ron Maupin
    Commented Oct 4, 2015 at 13:28
0

Packets just contain a destination address. Networks all have none-overlapping prefixes so it's always clear which network an address belongs in. A router's routing table contains the routes to prefixes and aggregates of prefixes so it knows where to send a packet. The final router is directly connected to the network and knows the exact (unaggregated) prefix.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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