Introduce MPLS over GRE
Subsystems (3)
v3 cover Introduce MPLS over GRE
This series introduces the MPLS over GRE encapsulation (RFC 4023).
Various applications of MPLS make use of label stacks with multiple entries. In some cases, it is possible to replace the top label of the stack with an IP-based encapsulation, thereby, it is possible for two LSRs that are adjacent on an LSP to be separated by an IP network, even if that IP network does not provide MPLS.
Changes in v3:
- remove mpls_forward() function exportation patch.
- wrap efficiently mpls iptunnel add/del functions and dependent function/structure.
- move mpls_gre_rcv to af_mpls.c file and export it.
- remove unnecessary functions.
Changes in v2:
- wrap ip tunnel functions under ifdef in mpls file.
- fix indentation.
- check return code.
An example of configuration:
node1 LER1 LER2 node2
+-----+ +------+ +------+ +-----+
| | | | | | | |
| | | |p3 GRE tunnel p4| | | |
| |p1 p2| +-------------------+ |p5 p6| |
| +-------------+ +-------------------+ +------------+| |
| |10.100.0.0/24| | | |10.200.0.0/24| |
| |fd00:100::/64| | 10.125.0.0/24 | |fd00:200::/64| |
| | | | fd00:125::/64 | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
+-----+ +------+ +------+ +-----+
### node1 ###ip link set p1 up
ip addr add 10.100.0.1/24 dev p1
### LER1 ###
ip link set p2 up
ip addr add 10.100.0.2/24 dev p2
ip link set p3 up
ip addr add 10.125.0.1/24 dev p3
modprobe mpls_router
sysctl -w net.mpls.conf.p2.input=1
sysctl -w net.mpls.conf.p3.input=1
sysctl -w net.mpls.platform_labels=1000
ip link add gre1 type gre ttl 64 local 10.125.0.1 remote 10.125.0.2 dev p3 ip link set dev gre1 up
ip -M route add 111 as 222 dev gre1
ip -M route add 555 as 666 via inet 10.100.0.1 dev p2
### LER2 ###
ip link set p5 up
ip addr add 10.200.0.2/24 dev p5
ip link set p4 up
ip addr add 10.125.0.2/24 dev p4
modprobe mpls_router
sysctl -w net.mpls.conf.p4.input=1
sysctl -w net.mpls.conf.p5.input=1
sysctl -w net.mpls.platform_labels=1000
ip link add gre1 type gre ttl 64 local 10.125.0.2 remote 10.125.0.1 dev p4 ip link set dev gre1 up
ip -M route add 444 as 555 dev gre1
ip -M route add 222 as 333 via inet 10.200.0.1 dev p5
### node2 ###
ip link set p6 up
ip addr add 10.200.0.1/24 dev p6
Now using this scapy to forge and send packets from the port p1 of node1:
p = Ether(src='de:ed:01:0c:41:09', dst='de:ed:01:2f:3b:ba') p /= MPLS(s=1, ttl=64, label=111)/Raw(load='\xde') sendp(p, iface="p1", count=20, inter=0.1)
Amine Kherbouche (1):
ip_tunnel: add mpls over gre encapsulation
include/linux/mpls.h | 2 ++ include/uapi/linux/if_tunnel.h | 1 + net/ipv4/ip_gre.c | 11 +++++++++ net/ipv6/ip6_gre.c | 11 +++++++++ net/mpls/af_mpls.c | 52 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 77 insertions(+)
Signature · 1 line
2.1.4
PATCH v3 1/1 ip_tunnel: add mpls over gre encapsulation
This commit introduces the MPLSoGRE support (RFC 4023), using ip tunnel API.
Encap:
- Add a new iptunnel type mpls.
- Share tx path: gre type mpls loaded from skb->protocol.
Decap:
- pull gre hdr and call mpls_forward().
--- include/linux/mpls.h | 2 ++ include/uapi/linux/if_tunnel.h | 1 + net/ipv4/ip_gre.c | 11 +++++++++ net/ipv6/ip6_gre.c | 11 +++++++++ net/mpls/af_mpls.c | 52 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 77 insertions(+)
include/linux/mpls.h +2 -0
@@ -8,4 +8,6 @@#define MPLS_TC_MASK (MPLS_LS_TC_MASK >> MPLS_LS_TC_SHIFT)#define MPLS_LABEL_MASK (MPLS_LS_LABEL_MASK >> MPLS_LS_LABEL_SHIFT) +int mpls_gre_rcv (struct sk_buff *skb,int gre_hdr_len); +#endif /* _LINUX_MPLS_H */
include/uapi/linux/if_tunnel.h +1 -0
@@ -84,6 +84,7 @@ enum tunnel_encap_types {TUNNEL_ENCAP_NONE ,TUNNEL_ENCAP_FOU ,TUNNEL_ENCAP_GUE , + TUNNEL_ENCAP_MPLS, };#define TUNNEL_ENCAP_FLAG_CSUM (1<<0)
net/ipv4/ip_gre.c +11 -0
@@ -32,6 +32,9 @@#include <linux/netfilter_ipv4.h> #include <linux/etherdevice.h> #include <linux/if_ether.h> +#if IS_ENABLED (CONFIG_MPLS ) +#include <linux/mpls.h> +#endif #include <net/sock.h> #include <net/ip.h>
@@ -412,6 +415,14 @@ static int gre_rcv(struct sk_buff *skb)return 0 ; } +if (unlikely (tpi.proto ==htons (ETH_P_MPLS_UC ))) { +#if IS_ENABLED (CONFIG_MPLS ) +return mpls_gre_rcv (skb, hdr_len); +#else + goto drop; +#endif + } +if (ipgre_rcv (skb, &tpi, hdr_len) ==PACKET_RCVD )return 0 ;
net/ipv6/ip6_gre.c +11 -0
@@ -34,6 +34,9 @@#include <linux/hash.h> #include <linux/if_tunnel.h> #include <linux/ip6_tunnel.h> +#if IS_ENABLED (CONFIG_MPLS ) +#include <linux/mpls.h> +#endif #include <net/sock.h> #include <net/ip.h>
@@ -476,6 +479,14 @@ static int gre_rcv(struct sk_buff *skb)if (hdr_len <0 ) goto drop; +if (unlikely (tpi.proto ==htons (ETH_P_MPLS_UC ))) { +#if IS_ENABLED (CONFIG_MPLS ) +return mpls_gre_rcv (skb, hdr_len); +#else + goto drop; +#endif + } +if (iptunnel_pull_header (skb, hdr_len, tpi.proto, false)) goto drop;
net/mpls/af_mpls.c +52 -0
82 lines not on this page · raw message
Signature · 1 line
2.1.4
Re: [PATCH v3 1/1] ip_tunnel: add mpls over gre encapsulation
Quoted 58 lines · Amine Kherbouche
This commit introduces the MPLSoGRE support (RFC 4023), using ip tunnel API.
Encap:
- Add a new iptunnel type mpls.
- Share tx path: gre type mpls loaded fromskb->protocol.Decap:
- pull gre hdr and callmpls_forward().Signed-off-by Amine Kherbouche <[email protected]>--- include/linux/mpls.h | 2 ++ include/uapi/linux/if_tunnel.h | 1 + net/ipv4/ip_gre.c | 11 +++++++++ net/ipv6/ip6_gre.c | 11 +++++++++ net/mpls/af_mpls.c | 52 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 77 insertions(+)include/linux/mpls.h +2
-0@@ -8,4 +8,6 @@#define MPLS_TC_MASK (MPLS_LS_TC_MASK >> MPLS_LS_TC_SHIFT)#define MPLS_LABEL_MASK (MPLS_LS_LABEL_MASK >> MPLS_LS_LABEL_SHIFT) +int mpls_gre_rcv (struct sk_buff *skb,int gre_hdr_len); +#endif /* _LINUX_MPLS_H */ include/uapi/linux/if_tunnel.h +1
-0@@ -84,6 +84,7 @@ enum tunnel_encap_types {TUNNEL_ENCAP_NONE ,TUNNEL_ENCAP_FOU ,TUNNEL_ENCAP_GUE , + TUNNEL_ENCAP_MPLS, };#define TUNNEL_ENCAP_FLAG_CSUM (1<<0)net/ipv4/ip_gre.c +3
-0@@ -32,6 +32,9 @@#include <linux/netfilter_ipv4.h> #include <linux/etherdevice.h> #include <linux/if_ether.h> +#if IS_ENABLED (CONFIG_MPLS ) +#include <linux/mpls.h> +#endif #include <net/sock.h> #include <net/ip.h> @@ -412,6 +415,14 @@ static int gre_rcv(struct sk_buff *skb)return 0 ;
net/ipv4/ip_gre.c static int gre_rcv(struct sk_buff *skb) · line 425
Quoted 10 lines
net/ipv4/ip_gre.c +8
-0} +if (unlikely (tpi.proto ==htons (ETH_P_MPLS_UC ))) { +#if IS_ENABLED (CONFIG_MPLS ) +return mpls_gre_rcv (skb, hdr_len); +#else + goto drop; +#endif + } +
Amine, one small nit here.., if you define mpls_gre_rcv in gre header (like you had initially), you could do the below...
#if IS_ENABLED(CONFIG_MPLS)mpls_gre_rcv()
{
/* real func */
}#elsempls_gre_rcv()
{
kfree_skb(skb)
return NET_RX_DROP
}
#endif
and the check in gre_rcv() reduces to
if (unlikely(tpi.proto == htons(ETH_P_MPLS_UC)))
return mpls_gre_rcv(skb, hdr_len);
Which looks much cleaner.
Other than that, looks great. pls add my Acked-by: Roopa Prabhu <[email protected]> to your next version.
thanks!
Re: [PATCH v3 1/1] ip_tunnel: add mpls over gre encapsulation
Quoted 16 lines · Roopa Prabhu
Amine, one small nit here.., if you define
mpls_gre_rcvin gre header (like you had initially), you could do the below...#if
IS_ENABLED(CONFIG_MPLS)mpls_gre_rcv(){ /* real func */ }#else
mpls_gre_rcv()
{
kfree_skb(skb)
returnNET_RX_DROP
}
#endif
Quoted 6 lines
and the check in
gre_rcv()reduces toif (
unlikely(tpi.proto == htons(ETH_P_MPLS_UC)))return mpls_gre_rcv(skb, hdr_len);Which looks much cleaner.
If I do that, do I have to add back the patch that export mpls_forward() or just merge it with this one ?
Re: [PATCH v3 1/1] ip_tunnel: add mpls over gre encapsulation
Quoted 22 lines · Amine Kherbouche
Quoted 19 lines · Roopa Prabhu
Amine, one small nit here.., if you define
mpls_gre_rcvin gre header (like you had initially), you could do the below...#if
IS_ENABLED(CONFIG_MPLS)mpls_gre_rcv(){ /* real func */ }#else
mpls_gre_rcv()
{
kfree_skb(skb)
returnNET_RX_DROP
}
#endifand the check in
gre_rcv()reduces to
Quoted 8 lines
Quoted 4 lines
if (
unlikely(tpi.proto == htons(ETH_P_MPLS_UC)))return mpls_gre_rcv(skb, hdr_len);Which looks much cleaner.
If I do that, do I have to add back the patch that export
mpls_forward()or just merge it with this one ?
I think its better to bring the patch back in.
Re: [PATCH v3 1/1] ip_tunnel: add mpls over gre encapsulation
Quoted 1 line · Roopa Prabhu
I think its better to bring the patch back in.
Sounds good, ok