Skip to content

Commit 0d89d20

Browse files
hormsdavem330
authored andcommitted
MPLS: Add limited GSO support
In the case where a non-MPLS packet is received and an MPLS stack is added it may well be the case that the original skb is GSO but the NIC used for transmit does not support GSO of MPLS packets. The aim of this code is to provide GSO in software for MPLS packets whose skbs are GSO. SKB Usage: When an implementation adds an MPLS stack to a non-MPLS packet it should do the following to skb metadata: * Set skb->inner_protocol to the old non-MPLS ethertype of the packet. skb->inner_protocol is added by this patch. * Set skb->protocol to the new MPLS ethertype of the packet. * Set skb->network_header to correspond to the end of the L3 header, including the MPLS label stack. I have posted a patch, "[PATCH v3.29] datapath: Add basic MPLS support to kernel" which adds MPLS support to the kernel datapath of Open vSwtich. That patch sets the above requirements in datapath/actions.c:push_mpls() and was used to exercise this code. The datapath patch is against the Open vSwtich tree but it is intended that it be added to the Open vSwtich code present in the mainline Linux kernel at some point. Features: I believe that the approach that I have taken is at least partially consistent with the handling of other protocols. Jesse, I understand that you have some ideas here. I am more than happy to change my implementation. This patch adds dev->mpls_features which may be used by devices to advertise features supported for MPLS packets. A new NETIF_F_MPLS_GSO feature is added for devices which support hardware MPLS GSO offload. Currently no devices support this and MPLS GSO always falls back to software. Alternate Implementation: One possible alternate implementation is to teach netif_skb_features() and skb_network_protocol() about MPLS, in a similar way to their understanding of VLANs. I believe this would avoid the need for net/mpls/mpls_gso.c and in particular the calls to __skb_push() and __skb_push() in mpls_gso_segment(). I have decided on the implementation in this patch as it should not introduce any overhead in the case where mpls_gso is not compiled into the kernel or inserted as a module. MPLS GSO suggested by Jesse Gross. Based in part on "v4 GRE: Add TCP segmentation offload for GRE" by Pravin B Shelar. Cc: Jesse Gross <jesse@nicira.com> Cc: Pravin B Shelar <pshelar@nicira.com> Signed-off-by: Simon Horman <horms@verge.net.au> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 1a37e41 commit 0d89d20

15 files changed

Lines changed: 143 additions & 3 deletions

File tree

‎include/linux/netdev_features.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ enum {
4343
NETIF_F_FSO_BIT, /* ... FCoE segmentation */
4444
NETIF_F_GSO_GRE_BIT, /* ... GRE with TSO */
4545
NETIF_F_GSO_UDP_TUNNEL_BIT, /* ... UDP TUNNEL with TSO */
46+
NETIF_F_GSO_MPLS_BIT, /* ... MPLS segmentation */
4647
/**/NETIF_F_GSO_LAST = /* last bit, see GSO_MASK */
47-
NETIF_F_GSO_UDP_TUNNEL_BIT,
48+
NETIF_F_GSO_MPLS_BIT,
4849

4950
NETIF_F_FCOE_CRC_BIT, /* FCoE CRC32 */
5051
NETIF_F_SCTP_CSUM_BIT, /* SCTP checksum offload */
@@ -107,6 +108,7 @@ enum {
107108
#define NETIF_F_RXALL __NETIF_F(RXALL)
108109
#define NETIF_F_GSO_GRE __NETIF_F(GSO_GRE)
109110
#define NETIF_F_GSO_UDP_TUNNEL __NETIF_F(GSO_UDP_TUNNEL)
111+
#define NETIF_F_GSO_MPLS __NETIF_F(GSO_MPLS)
110112
#define NETIF_F_HW_VLAN_STAG_FILTER __NETIF_F(HW_VLAN_STAG_FILTER)
111113
#define NETIF_F_HW_VLAN_STAG_RX __NETIF_F(HW_VLAN_STAG_RX)
112114
#define NETIF_F_HW_VLAN_STAG_TX __NETIF_F(HW_VLAN_STAG_TX)

‎include/linux/netdevice.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,6 +1088,8 @@ struct net_device {
10881088
* need to set them appropriately.
10891089
*/
10901090
netdev_features_t hw_enc_features;
1091+
/* mask of fetures inheritable by MPLS */
1092+
netdev_features_t mpls_features;
10911093

10921094
/* Interface index. Unique device identifier */
10931095
int ifindex;

‎include/linux/skbuff.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,8 @@ enum {
319319
SKB_GSO_GRE = 1 << 6,
320320

321321
SKB_GSO_UDP_TUNNEL = 1 << 7,
322+
323+
SKB_GSO_MPLS = 1 << 8,
322324
};
323325

324326
#if BITS_PER_LONG > 32
@@ -389,6 +391,7 @@ typedef unsigned char *sk_buff_data_t;
389391
* @dropcount: total number of sk_receive_queue overflows
390392
* @vlan_proto: vlan encapsulation protocol
391393
* @vlan_tci: vlan tag control information
394+
* @inner_protocol: Protocol (encapsulation)
392395
* @inner_transport_header: Inner transport layer header (encapsulation)
393396
* @inner_network_header: Network layer header (encapsulation)
394397
* @inner_mac_header: Link layer header (encapsulation)
@@ -509,6 +512,7 @@ struct sk_buff {
509512
__u32 reserved_tailroom;
510513
};
511514

515+
__be16 inner_protocol;
512516
__u16 inner_transport_header;
513517
__u16 inner_network_header;
514518
__u16 inner_mac_header;

‎net/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ source "net/batman-adv/Kconfig"
218218
source "net/openvswitch/Kconfig"
219219
source "net/vmw_vsock/Kconfig"
220220
source "net/netlink/Kconfig"
221+
source "net/mpls/Kconfig"
221222

222223
config RPS
223224
boolean

‎net/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,4 @@ obj-$(CONFIG_BATMAN_ADV) += batman-adv/
7070
obj-$(CONFIG_NFC) += nfc/
7171
obj-$(CONFIG_OPENVSWITCH) += openvswitch/
7272
obj-$(CONFIG_VSOCKETS) += vmw_vsock/
73+
obj-$(CONFIG_NET_MPLS_GSO) += mpls/

‎net/core/dev.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5277,6 +5277,10 @@ int register_netdevice(struct net_device *dev)
52775277
*/
52785278
dev->hw_enc_features |= NETIF_F_SG;
52795279

5280+
/* Make NETIF_F_SG inheritable to MPLS.
5281+
*/
5282+
dev->mpls_features |= NETIF_F_SG;
5283+
52805284
ret = call_netdevice_notifiers(NETDEV_POST_INIT, dev);
52815285
ret = notifier_to_errno(ret);
52825286
if (ret)

‎net/core/ethtool.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ static const char netdev_features_strings[NETDEV_FEATURE_COUNT][ETH_GSTRING_LEN]
8282
[NETIF_F_FSO_BIT] = "tx-fcoe-segmentation",
8383
[NETIF_F_GSO_GRE_BIT] = "tx-gre-segmentation",
8484
[NETIF_F_GSO_UDP_TUNNEL_BIT] = "tx-udp_tnl-segmentation",
85+
[NETIF_F_GSO_MPLS_BIT] = "tx-mpls-segmentation",
8586

8687
[NETIF_F_FCOE_CRC_BIT] = "tx-checksum-fcoe-crc",
8788
[NETIF_F_SCTP_CSUM_BIT] = "tx-checksum-sctp",

‎net/ipv4/af_inet.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,6 +1295,7 @@ static struct sk_buff *inet_gso_segment(struct sk_buff *skb,
12951295
SKB_GSO_GRE |
12961296
SKB_GSO_TCPV6 |
12971297
SKB_GSO_UDP_TUNNEL |
1298+
SKB_GSO_MPLS |
12981299
0)))
12991300
goto out;
13001301

‎net/ipv4/tcp.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2917,6 +2917,7 @@ struct sk_buff *tcp_tso_segment(struct sk_buff *skb,
29172917
SKB_GSO_TCP_ECN |
29182918
SKB_GSO_TCPV6 |
29192919
SKB_GSO_GRE |
2920+
SKB_GSO_MPLS |
29202921
SKB_GSO_UDP_TUNNEL |
29212922
0) ||
29222923
!(type & (SKB_GSO_TCPV4 | SKB_GSO_TCPV6))))

‎net/ipv4/udp.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2381,7 +2381,7 @@ struct sk_buff *udp4_ufo_fragment(struct sk_buff *skb,
23812381

23822382
if (unlikely(type & ~(SKB_GSO_UDP | SKB_GSO_DODGY |
23832383
SKB_GSO_UDP_TUNNEL |
2384-
SKB_GSO_GRE) ||
2384+
SKB_GSO_GRE | SKB_GSO_MPLS) ||
23852385
!(type & (SKB_GSO_UDP))))
23862386
goto out;
23872387

0 commit comments

Comments
 (0)