In Section 6 of RFC-4364, it is stated that, if MPLS is being used as the tunneling technology (in the scope of forwarding VPN-IPV4 traffic from one PE to an other) , this means that a router in the backbone MUST NOT accept a labeled packet from any adjacent non-backbone device unless the following two conditions hold :
2. the backbone router can determine that use of that label will cause the packet to leave the backbone before any labels lower in the stack will be inspected, and before the IP header will be inspected.
I'm trying to understand how is the first P router inside the backbone, able to determine that a given label sent from a PE router will cause the packet to leave the backbone.
This also made me wonder about MPLS, say in the following configuration where it has been enabled between P1-P3 routers, each (L< number>) represents their inner label (IGRP) :
ingressPE (L0) <--> P1 (L1) <---> P2 (L2)<--> P3 (L3) <--> egressPE (L4)
When P1 receives a packet from ingressPE with label L4 on the top of the stack, i suppose it knows that the corresponding egressPE is the way out of the backbone, but then this L4 label will be replaced with L2 then with L3.
So how does P3 knows that it needs to send the packet to L4, with all the labels being switched, does it look up the information based on the IP ?