mpls: support for ip tunnels
Subsystems (2)
RFC PATCH v2 3/3 mpls: support for ip tunnels
From: Roopa Prabhu <[email protected]>
Support ip mpls tunnels using the new lwt infrastructure.
--- include/linux/mpls_iptunnel.h | 6 ++ include/net/mpls_iptunnel.h | 29 +++++ include/uapi/linux/mpls_iptunnel.h | 26 +++++ net/mpls/Kconfig | 5 + net/mpls/Makefile | 1 + net/mpls/af_mpls.c | 9 +- net/mpls/internal.h | 3 + net/mpls/mpls_iptunnel.c | 205 ++++++++++++++++++++++++++++++++++++ 8 files changed, 281 insertions(+), 3 deletions(-) create mode 100644 include/linux/mpls_iptunnel.h create mode 100644 include/net/mpls_iptunnel.h create mode 100644 include/uapi/linux/mpls_iptunnel.h create mode 100644 net/mpls/mpls_iptunnel.c
include/linux/mpls_iptunnel.h new file +6 -0
@@ -0,0 +1,6 @@ +#ifndef _LINUX_MPLS_IPTUNNEL_H +#define _LINUX_MPLS_IPTUNNEL_H + +#include <uapi/linux/mpls_iptunnel.h> + +#endif /* _LINUX_MPLS_IPTUNNEL_H */
include/net/mpls_iptunnel.h new file +29 -0
@@ -0,0 +1,29 @@ +/* +* Copyright (c) 2015 Cumulus Networks, Inc. +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of version 2 of the GNU General Public +* License as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +*/ + +#ifndef _NET_MPLS_IPTUNNEL_H +#define _NET_MPLS_IPTUNNEL_H 1 + +#define MAX_NEW_LABELS 2 + +struct mpls_iptunnel_encap { +u32 label[MAX_NEW_LABELS ]; +u8 labels; +}; + +static inline struct mpls_iptunnel_encap *mpls_lwt_hdr (struct lwtunnel_state *lwtstate) +{ +return (struct mpls_iptunnel_encap *)lwtstate->tunnel.data; +} + +#endif
include/uapi/linux/mpls_iptunnel.h new file +26 -0
@@ -0,0 +1,26 @@ +/* +* mpls tunnel api +* +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version +* 2 of the License, or (at your option) any later version. +*/ + +#ifndef _UAPI_LINUX_MPLS_IPTUNNEL_H +#define _UAPI_LINUX_MPLS_IPTUNNEL_H + +/* MPLS tunnel attributes +* [RTA_ENCAP] = { +* [MPLS_IPTUNNEL_DST] +* } +*/ +enum { +MPLS_IPTUNNEL_UNSPEC , +MPLS_IPTUNNEL_DST , + __MPLS_IPTUNNEL_MAX, +}; +#define MPLS_IPTUNNEL_MAX (__MPLS_IPTUNNEL_MAX - 1) + +#endif /* _UAPI_LINUX_MPLS_IPTUNNEL_H */
net/mpls/Kconfig +5 -0
@@ -27,4 +27,9 @@ config MPLS_ROUTING help Add support for forwarding of mpls packets. +config MPLS_IPTUNNEL + tristate "MPLS: IP over MPLS tunnel support" + help + Light weight tunnel handling for mpls tunnel packets + endif # MPLS
net/mpls/Makefile +1 -0
@@ -3,5 +3,6 @@ # obj-$(CONFIG_NET_MPLS_GSO) += mpls_gso.o obj-$(CONFIG_MPLS_ROUTING) += mpls_router.o +obj-$(CONFIG_MPLS_IPTUNNEL) += mpls_iptunnel.o mpls_router-y := af_mpls.o
net/mpls/af_mpls.c +6 -3
@@ -58,10 +58,11 @@ static inline struct mpls_dev *mpls_dev_get(const struct net_device *dev)return rcu_dereference_rtnl (dev->mpls_ptr); } -static bool mpls_output_possible (const struct net_device *dev) +bool mpls_output_possible (const struct net_device *dev) {return dev && (dev->flags &IFF_UP ) &&netif_carrier_ok (dev); } +EXPORT_SYMBOL (mpls_output_possible);static unsigned int mpls_rt_header_size (const struct mpls_route *rt) {
@@ -69,13 +70,14 @@ static unsigned int mpls_rt_header_size(const struct mpls_route *rt)return rt->rt_labels *sizeof (struct mpls_shim_hdr ); } -static unsigned int mpls_dev_mtu (const struct net_device *dev) +unsigned int mpls_dev_mtu (const struct net_device *dev) {/* The amount of data the layer 2 frame can hold */ return dev->mtu; } +EXPORT_SYMBOL (mpls_dev_mtu); -static bool mpls_pkt_too_big (const struct sk_buff *skb,unsigned int mtu) +bool mpls_pkt_too_big (const struct sk_buff *skb,unsigned int mtu) {if (skb->len <= mtu)return false;
@@ -85,6 +87,7 @@ static bool mpls_pkt_too_big(const struct sk_buff *skb, unsigned int mtu)return true; } +EXPORT_SYMBOL (mpls_pkt_too_big);static bool mpls_egress (struct mpls_route *rt,struct sk_buff *skb,struct mpls_entry_decoded dec)
net/mpls/internal.h +3 -0
@@ -52,5 +52,8 @@ static inline struct mpls_entry_decoded mpls_entry_decode(struct mpls_shim_hdr *int nla_put_labels (struct sk_buff *skb,int attrtype,u8 labels,const u32 label[]);int nla_get_labels (const struct nlattr *nla,u32 max_labels,u32 *labels,u32 label[]); +bool mpls_output_possible (const struct net_device *dev); +unsigned int mpls_dev_mtu (const struct net_device *dev); +bool mpls_pkt_too_big (const struct sk_buff *skb,unsigned int mtu);#endif /* MPLS_INTERNAL_H */
net/mpls/mpls_iptunnel.c new file +205 -0
205 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Quoted 5 lines · Roopa Prabhu
From: Roopa Prabhu <[email protected]>
Support ip mpls tunnels using the new lwt infrastructure.
Signed-off-by Roopa Prabhu <[email protected]>
...
Quoted 16 lines
net/mpls/mpls_iptunnel.c new file +16
-0+int mpls_output (struct sock *sk,struct sk_buff *skb) +{ +struct mpls_iptunnel_encap *tun_encap_info; +struct mpls_shim_hdr *hdr; +struct mpls_entry_decoded dec; +struct net_device *out_dev; +unsigned int hh_len; +unsigned int new_header_size; +unsigned int mtu; +struct lwtunnel_state *lwtstate; +struct rtable *rt =skb_rtable (skb); +int err; +bool bos; +int i; + +if (skb->pkt_type !=PACKET_HOST )
net/mpls/mpls_iptunnel.c line 61
Quoted 10 lines
net/mpls/mpls_iptunnel.c new file +10
-0+ goto drop; + +if ((skb =skb_share_check (skb,GFP_ATOMIC )) ==NULL ) + goto drop; + +if (!rt) + goto drop; + +/* Find the output device */ + out_dev =rcu_dereference (skb_dst (skb)->dev);
Since the entire label stack and the output device is encoded in the route, this means that you won't get prefix-independent convergence with this implementation for an IGP route change. I.e. if you've got 10 million VPN routes via an IGP route for the BGP nexthop, and the IGP route for the BGP nexthop changes (e.g. because a link has gone down somewhere in the network) then you'll have to update all 10 million IP routes to change the output device, gateway and IGP label.
That's going to represent a scaling obstacle for one of the primary MPLS use cases.
Quoted 29 lines
net/mpls/mpls_iptunnel.c new file +29
-0+if (!mpls_output_possible (out_dev)) + goto drop; + +if (skb_warn_if_lro (skb)) + goto drop; +skb_forward_csum (skb); + + lwtstate = rt->rt_lwtstate; +if (!lwtstate) + goto drop; + + tun_encap_info =mpls_lwt_hdr (lwtstate); + +/* Verify the destination can hold the packet */ + new_header_size =mpls_encap_size (tun_encap_info); + mtu =mpls_dev_mtu (out_dev); +if (mpls_pkt_too_big (skb, mtu - new_header_size)) + goto drop; + + hh_len =LL_RESERVED_SPACE (out_dev); +if (!out_dev->header_ops) + hh_len =0 ; + +/* Ensure there is enough space for the headers in the skb */ +if (skb_cow (skb, hh_len + new_header_size)) + goto drop; + + skb->dev = out_dev; + skb->protocol =htons (ETH_P_MPLS_UC );
net/mpls/mpls_iptunnel.c line 100
Quoted 10 lines
net/mpls/mpls_iptunnel.c new file +10
-0+ +skb_push (skb, new_header_size); +skb_reset_network_header (skb); + +/* Push the new labels */ + hdr =mpls_hdr (skb); + bos = true; +for (i = tun_encap_info->labels -1 ; i >=0 ; i--) { + hdr[i] =mpls_entry_encode (tun_encap_info->label[i], + dec.ttl,0 , bos);
dec is never initialised in this function, so this will encode a garbage ttl into the packet.
This should instead be deriving the ttl from the IP packet, as Eric did in his original patch.
Thanks,
Rob
Quoted 15 lines
net/mpls/mpls_iptunnel.c new file +15
-0+ bos = false; + } + + err =neigh_xmit (NEIGH_ARP_TABLE , out_dev, &rt->rt_gateway, + skb); +if (err) +net_dbg_ratelimited ("%s: packet transmission failed: " +"%d\n" , __func__, err); + +return 0 ; + +drop: +kfree_skb (skb); +return -EINVAL ; +}
Quoted 4 lines · Robert Shearman
Since the entire label stack and the output device is encoded in the route, this means that you won't get prefix-independent convergence with this implementation for an IGP route change. I.e. if you've got 10 million VPN routes via an IGP route for the BGP nexthop, and the IGP route for the BGP nexthop changes (e.g. because a link has gone down somewhere in the network) then you'll have to update all 10 million IP routes to change the output device, gateway and IGP label.
That's going to represent a scaling obstacle for one of the primary MPLS use cases.
I cant say I understand PIC very well, but, assuming PIC is not just an mpls thing, PIC does require an alternate nexthop infrastructure in the kernel (FIB). And if that were present, It would help the mpls case too. I am not sure how you would solve PIC just for the mpls case or if having a netdevice makes it any easier.
Thanks,
Roopa
Quoted 8 lines · Robert Shearman
net/mpls/mpls_iptunnel.c line 100
Quoted 7 lines
net/mpls/mpls_iptunnel.c new file +7
-0+ +/* Push the new labels */ + hdr =mpls_hdr (skb); + bos = true; +for (i = tun_encap_info->labels -1 ; i >=0 ; i--) { + hdr[i] =mpls_entry_encode (tun_encap_info->label[i], + dec.ttl,0 , bos);
Quoted 4 lines
dec is never initialised in this function, so this will encode a garbage ttl into the packet.
This should instead be deriving the ttl from the IP packet, as Eric did in his original patch.
Thanks for the pointer Robert. I will fix it.
net/mpls/Kconfig config MPLS_ROUTING · line 34
Quoted 13 lines · Roopa Prabhu
net/mpls/Kconfig +5
-0@@ -27,4 +27,9 @@ config MPLS_ROUTING help Add support for forwarding of mpls packets. +config MPLS_IPTUNNEL + tristate "MPLS: IP over MPLS tunnel support" + help + Light weight tunnel handling for mpls tunnel packets +
I assume this should select CONFIG_LWTUNNEL
Quoted 9 lines · Thomas Graf
Quoted 8 lines · Roopa Prabhu
net/mpls/Kconfig +0
-0@@ -27,4 +27,9 @@ config MPLS_ROUTING help Add support for forwarding of mpls packets.
Quoted 6 lines
net/mpls/Kconfig config MPLS_ROUTING · line 34
Quoted 5 lines
net/mpls/Kconfig +5
-0+config MPLS_IPTUNNEL + tristate "MPLS: IP over MPLS tunnel support" + help + Light weight tunnel handling for mpls tunnel packets +I assume this should select
CONFIG_LWTUNNEL
yeah, i will fix this and other few open ends in this area... before the next non-RFC round..., thx