How to receive UDP packet with 127.0.0.0/8 dst address in userspace
10
votes
2
answers
1260
views
I would like to know if it is possible in linux to receive an UDP packet in userspace that has a 127.0.0.0/8 dst address but coming from an external interface.
I tested it with nc and I can see although nc binds to all addresses it doesn't receive the packet.
On *Device 1* I manipulated the local routing table to route this packet to desired interface then I send a test packet.
**Device 1**:
I know that according to RFC 1812 this should never happen. On the other hand this is a valid use case according RFC4379 . The trick here that the packet I'm sending is actually not IP routed but MPLS switched and on the last hop the MPLS label is missing due to PHP (Penultimate Hop Popping) and the goal of using 127.0.0.0/8 address as dst is to make sure that when label stack runs out or no valid nexthop then the router will not forward based on IP address but process the packet. This is called MPLS OAM or LSP Ping.
frr:~# ip route show table local
...
127.1.1.1 nhid 17 encap mpls 16 via 10.10.10.5 dev eth5
...
frr:~# echo "foo" | nc -w1 -u -v -s 3.3.3.3 127.1.1.1 3503
**Device 2**:
frr:~# nc -l -u -p 3503
The following packet is generated and captured in wireshark on Device 2 interface:

Asked by zskr
(103 rep)
Mar 4, 2024, 07:02 AM
Last activity: Mar 4, 2024, 09:13 AM
Last activity: Mar 4, 2024, 09:13 AM