#Some quick info about MPLS: You need to compile your kernel with options MPLS and psuedo-device ifmpls For pure LSR - that only switch labels without encap/decap from other protocols (e.g. INET) - you need to work on routing table, ONLY. For example:
# route add -mpls 41 -tag 25 -inet 193.28.151.97
add host 41: gateway 193.28.151.97
# route add -mpls 42 -tag 30 -inet 193.28.151.97
add host 42: gateway 193.28.151.97
# route add -mpls 51 -tag 25 -inet 193.28.151.97
add host 51: gateway 193.28.151.97
Translation of first line: if it receives an MPLS frame with label 41 forward it to INET next-hop 193.28.151.97, but switch (change) label 41 with label 25 You also need to tweak sysctl to accept and forward MPLS:
# sysctl -w net.mpls.accept=1
net.mpls.accept: 0 -> 1
# sysctl -w net.mpls.forwarding=1
net.mpls.forwarding: 0 -> 1
Verify routes with route get or better with netstat -nrT:
...
MPLS:
Destination        Gateway            Flags    Refs      Use    Mtu     Tag Interface
41                 193.28.151.97      UGHS        0    37241      -      25 sk0
42                 193.28.151.97      UGHS        0        0      -      30 sk0
51                 193.28.151.97      UGHS        0        0      -      25 sk0
#Interacting with other protocols If you want to also decapsulate/encapsulate from MPLS to some other protocol (like INET or INET6), then you have to create an mpls interface and put in up state.
# ifconfig mpls0 create up
After that, create routes using ifa flag in order to specify the source interface (used for source IP Address of host generated packets), but route them through mpls0 interface.
# route add 204.152.190.0/24 -ifa 193.28.151.105 -ifp mpls0 -tag 25 -inet 193.28.151.97
add net 204.152.190.0: gateway 193.28.151.97
Verify the route:
# route -n get 204.152.190.0/24
   route to: 204.152.190.0
destination: 204.152.190.0
       mask: 255.255.255.0
    gateway: 193.28.151.97
        Tag: 25
 local addr: 193.28.151.105
  interface: mpls0
      flags: 
 recvpipe  sendpipe  ssthresh  rtt,msec    rttvar  hopcount      mtu     expire
       0         0         0       813       344         0         0         0 
sockaddrs: 
or with netstat -rT:
...
204.152.190/24     193.28.151.97      UGS         0    95362      -      25 mpls0
...
Test if it's working using traceroute -M. Notice first hop is reporting label 25.
# traceroute -M 204.152.190.12
traceroute to 204.152.190.12 (204.152.190.12), 64 hops max, 40 byte packets
 1  shaitan.girsa.ro (193.28.151.97)  2.892 ms  1.957 ms  1.992 ms [MPLS: Label 25 Exp 0]
 2  b4-vlan811.girsa.ro (193.28.151.82)  1.988 ms  1.961 ms  1.989 ms [MPLS: Label 27 Exp 0]
 3  80.97.219.81 (80.97.219.81)  1.990 ms  1.974 ms  2.009 ms
 4  vlan103.cr3-sw.buch.artelecom.net (80.97.199.1)  2.651 ms  2.280 ms  3.663 ms
 5  10.0.241.189 (10.0.241.189)  33.944 ms  34.011 ms  33.869 ms [MPLS: Label 21669 Exp 0]
 6  10.0.240.22 (10.0.240.22)  33.946 ms  33.689 ms  33.929 ms
 7  20gigabitethernet4-3.core1.fra1.he.net (80.81.192.172)  35.930 ms  35.926 ms  35.917 ms
 8  10gigabitethernet1-2.core1.par1.he.net (72.52.92.89)  43.940 ms  45.900 ms  47.916 ms
 9  10gigabitethernet1-3.core1.lon1.he.net (72.52.92.33)  59.901 ms  51.888 ms  51.913 ms
10  10gigabitethernet4-4.core1.nyc4.he.net (72.52.92.241)  119.808 ms  119.780 ms  119.800 ms
11  10gigabitethernet1-2.core1.chi1.he.net (72.52.92.102)  141.755 ms  143.748 ms  149.756 ms
12  he.ord1.isc.org (209.51.161.18)  143.756 ms  143.757 ms  141.755 ms
13  iana.r1.ord1.isc.org (199.6.0.1)  145.831 ms  141.747 ms  143.762 ms
14  int-0-0-1-8.r1.pao1.isc.org (149.20.65.157)  201.653 ms  205.650 ms  201.650 ms [MPLS: Label 16005 Exp 0]
15  int-0-0-1-0.r2.sql1.isc.org (149.20.65.10)  201.663 ms  201.645 ms  201.664 ms
16  www.netbsd.org (204.152.190.12)  199.676 ms  201.652 ms  201.673 ms
See also [[LDP]] wiki page.