Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'nsh-headers-GSO'

Jiri Benc says:

====================
nsh: headers, GSO

This adds header structs and helpers for NSH together with GSO support.

Note there is no code in this patchset that actually manipulates the NSH
headers. That was sent to netdev by Yi Yang ("[PATCH net-next v6 0/3]
openvswitch: add NSH support"). The aim of this series is to lay the
groundwork and ease the implementation for him.

In addition to openvswitch, the NSH support should be added to tc (flower to
match, act_nsh to push/pop NSH headers). That will come later. There's
currently no plan to support NSH by other means than those two.

The patch 3 in this patchset was written by Yi Yang, I took it from the
aforementioned series and slightly modified it - see the note in the patch.
====================

Signed-off-by: David S. Miller <davem@davemloft.net>

+467 -31
+7 -25
drivers/net/vxlan.c
··· 26 26 #include <net/inet_ecn.h> 27 27 #include <net/net_namespace.h> 28 28 #include <net/netns/generic.h> 29 + #include <net/tun_proto.h> 29 30 #include <net/vxlan.h> 30 31 31 32 #if IS_ENABLED(CONFIG_IPV6) ··· 1262 1261 if (gpe->oam_flag) 1263 1262 return false; 1264 1263 1265 - switch (gpe->next_protocol) { 1266 - case VXLAN_GPE_NP_IPV4: 1267 - *protocol = htons(ETH_P_IP); 1268 - break; 1269 - case VXLAN_GPE_NP_IPV6: 1270 - *protocol = htons(ETH_P_IPV6); 1271 - break; 1272 - case VXLAN_GPE_NP_ETHERNET: 1273 - *protocol = htons(ETH_P_TEB); 1274 - break; 1275 - default: 1264 + *protocol = tun_p_to_eth_p(gpe->next_protocol); 1265 + if (!*protocol) 1276 1266 return false; 1277 - } 1278 1267 1279 1268 unparsed->vx_flags &= ~VXLAN_GPE_USED_BITS; 1280 1269 return true; ··· 1790 1799 struct vxlanhdr_gpe *gpe = (struct vxlanhdr_gpe *)vxh; 1791 1800 1792 1801 gpe->np_applied = 1; 1793 - 1794 - switch (protocol) { 1795 - case htons(ETH_P_IP): 1796 - gpe->next_protocol = VXLAN_GPE_NP_IPV4; 1797 - return 0; 1798 - case htons(ETH_P_IPV6): 1799 - gpe->next_protocol = VXLAN_GPE_NP_IPV6; 1800 - return 0; 1801 - case htons(ETH_P_TEB): 1802 - gpe->next_protocol = VXLAN_GPE_NP_ETHERNET; 1803 - return 0; 1804 - } 1805 - return -EPFNOSUPPORT; 1802 + gpe->next_protocol = tun_p_from_eth_p(protocol); 1803 + if (!gpe->next_protocol) 1804 + return -EPFNOSUPPORT; 1805 + return 0; 1806 1806 } 1807 1807 1808 1808 static int vxlan_build_skb(struct sk_buff *skb, struct dst_entry *dst,
+307
include/net/nsh.h
··· 1 + #ifndef __NET_NSH_H 2 + #define __NET_NSH_H 1 3 + 4 + #include <linux/skbuff.h> 5 + 6 + /* 7 + * Network Service Header: 8 + * 0 1 2 3 9 + * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 10 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 11 + * |Ver|O|U| TTL | Length |U|U|U|U|MD Type| Next Protocol | 12 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 13 + * | Service Path Identifier (SPI) | Service Index | 14 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 15 + * | | 16 + * ~ Mandatory/Optional Context Headers ~ 17 + * | | 18 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 19 + * 20 + * Version: The version field is used to ensure backward compatibility 21 + * going forward with future NSH specification updates. It MUST be set 22 + * to 0x0 by the sender, in this first revision of NSH. Given the 23 + * widespread implementation of existing hardware that uses the first 24 + * nibble after an MPLS label stack for ECMP decision processing, this 25 + * document reserves version 01b and this value MUST NOT be used in 26 + * future versions of the protocol. Please see [RFC7325] for further 27 + * discussion of MPLS-related forwarding requirements. 28 + * 29 + * O bit: Setting this bit indicates an Operations, Administration, and 30 + * Maintenance (OAM) packet. The actual format and processing of SFC 31 + * OAM packets is outside the scope of this specification (see for 32 + * example [I-D.ietf-sfc-oam-framework] for one approach). 33 + * 34 + * The O bit MUST be set for OAM packets and MUST NOT be set for non-OAM 35 + * packets. The O bit MUST NOT be modified along the SFP. 36 + * 37 + * SF/SFF/SFC Proxy/Classifier implementations that do not support SFC 38 + * OAM procedures SHOULD discard packets with O bit set, but MAY support 39 + * a configurable parameter to enable forwarding received SFC OAM 40 + * packets unmodified to the next element in the chain. Forwarding OAM 41 + * packets unmodified by SFC elements that do not support SFC OAM 42 + * procedures may be acceptable for a subset of OAM functions, but can 43 + * result in unexpected outcomes for others, thus it is recommended to 44 + * analyze the impact of forwarding an OAM packet for all OAM functions 45 + * prior to enabling this behavior. The configurable parameter MUST be 46 + * disabled by default. 47 + * 48 + * TTL: Indicates the maximum SFF hops for an SFP. This field is used 49 + * for service plane loop detection. The initial TTL value SHOULD be 50 + * configurable via the control plane; the configured initial value can 51 + * be specific to one or more SFPs. If no initial value is explicitly 52 + * provided, the default initial TTL value of 63 MUST be used. Each SFF 53 + * involved in forwarding an NSH packet MUST decrement the TTL value by 54 + * 1 prior to NSH forwarding lookup. Decrementing by 1 from an incoming 55 + * value of 0 shall result in a TTL value of 63. The packet MUST NOT be 56 + * forwarded if TTL is, after decrement, 0. 57 + * 58 + * All other flag fields, marked U, are unassigned and available for 59 + * future use, see Section 11.2.1. Unassigned bits MUST be set to zero 60 + * upon origination, and MUST be ignored and preserved unmodified by 61 + * other NSH supporting elements. Elements which do not understand the 62 + * meaning of any of these bits MUST NOT modify their actions based on 63 + * those unknown bits. 64 + * 65 + * Length: The total length, in 4-byte words, of NSH including the Base 66 + * Header, the Service Path Header, the Fixed Length Context Header or 67 + * Variable Length Context Header(s). The length MUST be 0x6 for MD 68 + * Type equal to 0x1, and MUST be 0x2 or greater for MD Type equal to 69 + * 0x2. The length of the NSH header MUST be an integer multiple of 4 70 + * bytes, thus variable length metadata is always padded out to a 71 + * multiple of 4 bytes. 72 + * 73 + * MD Type: Indicates the format of NSH beyond the mandatory Base Header 74 + * and the Service Path Header. MD Type defines the format of the 75 + * metadata being carried. 76 + * 77 + * 0x0 - This is a reserved value. Implementations SHOULD silently 78 + * discard packets with MD Type 0x0. 79 + * 80 + * 0x1 - This indicates that the format of the header includes a fixed 81 + * length Context Header (see Figure 4 below). 82 + * 83 + * 0x2 - This does not mandate any headers beyond the Base Header and 84 + * Service Path Header, but may contain optional variable length Context 85 + * Header(s). The semantics of the variable length Context Header(s) 86 + * are not defined in this document. The format of the optional 87 + * variable length Context Headers is provided in Section 2.5.1. 88 + * 89 + * 0xF - This value is reserved for experimentation and testing, as per 90 + * [RFC3692]. Implementations not explicitly configured to be part of 91 + * an experiment SHOULD silently discard packets with MD Type 0xF. 92 + * 93 + * Next Protocol: indicates the protocol type of the encapsulated data. 94 + * NSH does not alter the inner payload, and the semantics on the inner 95 + * protocol remain unchanged due to NSH service function chaining. 96 + * Please see the IANA Considerations section below, Section 11.2.5. 97 + * 98 + * This document defines the following Next Protocol values: 99 + * 100 + * 0x1: IPv4 101 + * 0x2: IPv6 102 + * 0x3: Ethernet 103 + * 0x4: NSH 104 + * 0x5: MPLS 105 + * 0xFE: Experiment 1 106 + * 0xFF: Experiment 2 107 + * 108 + * Packets with Next Protocol values not supported SHOULD be silently 109 + * dropped by default, although an implementation MAY provide a 110 + * configuration parameter to forward them. Additionally, an 111 + * implementation not explicitly configured for a specific experiment 112 + * [RFC3692] SHOULD silently drop packets with Next Protocol values 0xFE 113 + * and 0xFF. 114 + * 115 + * Service Path Identifier (SPI): Identifies a service path. 116 + * Participating nodes MUST use this identifier for Service Function 117 + * Path selection. The initial classifier MUST set the appropriate SPI 118 + * for a given classification result. 119 + * 120 + * Service Index (SI): Provides location within the SFP. The initial 121 + * classifier for a given SFP SHOULD set the SI to 255, however the 122 + * control plane MAY configure the initial value of SI as appropriate 123 + * (i.e., taking into account the length of the service function path). 124 + * The Service Index MUST be decremented by a value of 1 by Service 125 + * Functions or by SFC Proxy nodes after performing required services 126 + * and the new decremented SI value MUST be used in the egress packet's 127 + * NSH. The initial Classifier MUST send the packet to the first SFF in 128 + * the identified SFP for forwarding along an SFP. If re-classification 129 + * occurs, and that re-classification results in a new SPI, the 130 + * (re)classifier is, in effect, the initial classifier for the 131 + * resultant SPI. 132 + * 133 + * The SI is used in conjunction the with Service Path Identifier for 134 + * Service Function Path Selection and for determining the next SFF/SF 135 + * in the path. The SI is also valuable when troubleshooting or 136 + * reporting service paths. Additionally, while the TTL field is the 137 + * main mechanism for service plane loop detection, the SI can also be 138 + * used for detecting service plane loops. 139 + * 140 + * When the Base Header specifies MD Type = 0x1, a Fixed Length Context 141 + * Header (16-bytes) MUST be present immediately following the Service 142 + * Path Header. The value of a Fixed Length Context 143 + * Header that carries no metadata MUST be set to zero. 144 + * 145 + * When the base header specifies MD Type = 0x2, zero or more Variable 146 + * Length Context Headers MAY be added, immediately following the 147 + * Service Path Header (see Figure 5). Therefore, Length = 0x2, 148 + * indicates that only the Base Header followed by the Service Path 149 + * Header are present. The optional Variable Length Context Headers 150 + * MUST be of an integer number of 4-bytes. The base header Length 151 + * field MUST be used to determine the offset to locate the original 152 + * packet or frame for SFC nodes that require access to that 153 + * information. 154 + * 155 + * The format of the optional variable length Context Headers 156 + * 157 + * 0 1 2 3 158 + * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 159 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 160 + * | Metadata Class | Type |U| Length | 161 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 162 + * | Variable Metadata | 163 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 164 + * 165 + * Metadata Class (MD Class): Defines the scope of the 'Type' field to 166 + * provide a hierarchical namespace. The IANA Considerations 167 + * Section 11.2.4 defines how the MD Class values can be allocated to 168 + * standards bodies, vendors, and others. 169 + * 170 + * Type: Indicates the explicit type of metadata being carried. The 171 + * definition of the Type is the responsibility of the MD Class owner. 172 + * 173 + * Unassigned bit: One unassigned bit is available for future use. This 174 + * bit MUST NOT be set, and MUST be ignored on receipt. 175 + * 176 + * Length: Indicates the length of the variable metadata, in bytes. In 177 + * case the metadata length is not an integer number of 4-byte words, 178 + * the sender MUST add pad bytes immediately following the last metadata 179 + * byte to extend the metadata to an integer number of 4-byte words. 180 + * The receiver MUST round up the length field to the nearest 4-byte 181 + * word boundary, to locate and process the next field in the packet. 182 + * The receiver MUST access only those bytes in the metadata indicated 183 + * by the length field (i.e., actual number of bytes) and MUST ignore 184 + * the remaining bytes up to the nearest 4-byte word boundary. The 185 + * Length may be 0 or greater. 186 + * 187 + * A value of 0 denotes a Context Header without a Variable Metadata 188 + * field. 189 + * 190 + * [0] https://datatracker.ietf.org/doc/draft-ietf-sfc-nsh/ 191 + */ 192 + 193 + /** 194 + * struct nsh_md1_ctx - Keeps track of NSH context data 195 + * @nshc<1-4>: NSH Contexts. 196 + */ 197 + struct nsh_md1_ctx { 198 + __be32 context[4]; 199 + }; 200 + 201 + struct nsh_md2_tlv { 202 + __be16 md_class; 203 + u8 type; 204 + u8 length; 205 + u8 md_value[]; 206 + }; 207 + 208 + struct nshhdr { 209 + __be16 ver_flags_ttl_len; 210 + u8 mdtype; 211 + u8 np; 212 + __be32 path_hdr; 213 + union { 214 + struct nsh_md1_ctx md1; 215 + struct nsh_md2_tlv md2; 216 + }; 217 + }; 218 + 219 + /* Masking NSH header fields. */ 220 + #define NSH_VER_MASK 0xc000 221 + #define NSH_VER_SHIFT 14 222 + #define NSH_FLAGS_MASK 0x3000 223 + #define NSH_FLAGS_SHIFT 12 224 + #define NSH_TTL_MASK 0x0fc0 225 + #define NSH_TTL_SHIFT 6 226 + #define NSH_LEN_MASK 0x003f 227 + #define NSH_LEN_SHIFT 0 228 + 229 + #define NSH_MDTYPE_MASK 0x0f 230 + #define NSH_MDTYPE_SHIFT 0 231 + 232 + #define NSH_SPI_MASK 0xffffff00 233 + #define NSH_SPI_SHIFT 8 234 + #define NSH_SI_MASK 0x000000ff 235 + #define NSH_SI_SHIFT 0 236 + 237 + /* MD Type Registry. */ 238 + #define NSH_M_TYPE1 0x01 239 + #define NSH_M_TYPE2 0x02 240 + #define NSH_M_EXP1 0xFE 241 + #define NSH_M_EXP2 0xFF 242 + 243 + /* NSH Base Header Length */ 244 + #define NSH_BASE_HDR_LEN 8 245 + 246 + /* NSH MD Type 1 header Length. */ 247 + #define NSH_M_TYPE1_LEN 24 248 + 249 + /* NSH header maximum Length. */ 250 + #define NSH_HDR_MAX_LEN 256 251 + 252 + /* NSH context headers maximum Length. */ 253 + #define NSH_CTX_HDRS_MAX_LEN 248 254 + 255 + static inline struct nshhdr *nsh_hdr(struct sk_buff *skb) 256 + { 257 + return (struct nshhdr *)skb_network_header(skb); 258 + } 259 + 260 + static inline u16 nsh_hdr_len(const struct nshhdr *nsh) 261 + { 262 + return ((ntohs(nsh->ver_flags_ttl_len) & NSH_LEN_MASK) 263 + >> NSH_LEN_SHIFT) << 2; 264 + } 265 + 266 + static inline u8 nsh_get_ver(const struct nshhdr *nsh) 267 + { 268 + return (ntohs(nsh->ver_flags_ttl_len) & NSH_VER_MASK) 269 + >> NSH_VER_SHIFT; 270 + } 271 + 272 + static inline u8 nsh_get_flags(const struct nshhdr *nsh) 273 + { 274 + return (ntohs(nsh->ver_flags_ttl_len) & NSH_FLAGS_MASK) 275 + >> NSH_FLAGS_SHIFT; 276 + } 277 + 278 + static inline u8 nsh_get_ttl(const struct nshhdr *nsh) 279 + { 280 + return (ntohs(nsh->ver_flags_ttl_len) & NSH_TTL_MASK) 281 + >> NSH_TTL_SHIFT; 282 + } 283 + 284 + static inline void __nsh_set_xflag(struct nshhdr *nsh, u16 xflag, u16 xmask) 285 + { 286 + nsh->ver_flags_ttl_len 287 + = (nsh->ver_flags_ttl_len & ~htons(xmask)) | htons(xflag); 288 + } 289 + 290 + static inline void nsh_set_flags_and_ttl(struct nshhdr *nsh, u8 flags, u8 ttl) 291 + { 292 + __nsh_set_xflag(nsh, ((flags << NSH_FLAGS_SHIFT) & NSH_FLAGS_MASK) | 293 + ((ttl << NSH_TTL_SHIFT) & NSH_TTL_MASK), 294 + NSH_FLAGS_MASK | NSH_TTL_MASK); 295 + } 296 + 297 + static inline void nsh_set_flags_ttl_len(struct nshhdr *nsh, u8 flags, 298 + u8 ttl, u8 len) 299 + { 300 + len = len >> 2; 301 + __nsh_set_xflag(nsh, ((flags << NSH_FLAGS_SHIFT) & NSH_FLAGS_MASK) | 302 + ((ttl << NSH_TTL_SHIFT) & NSH_TTL_MASK) | 303 + ((len << NSH_LEN_SHIFT) & NSH_LEN_MASK), 304 + NSH_FLAGS_MASK | NSH_TTL_MASK | NSH_LEN_MASK); 305 + } 306 + 307 + #endif /* __NET_NSH_H */
+49
include/net/tun_proto.h
··· 1 + #ifndef __NET_TUN_PROTO_H 2 + #define __NET_TUN_PROTO_H 3 + 4 + #include <linux/kernel.h> 5 + 6 + /* One byte protocol values as defined by VXLAN-GPE and NSH. These will 7 + * hopefully get a shared IANA registry. 8 + */ 9 + #define TUN_P_IPV4 0x01 10 + #define TUN_P_IPV6 0x02 11 + #define TUN_P_ETHERNET 0x03 12 + #define TUN_P_NSH 0x04 13 + #define TUN_P_MPLS_UC 0x05 14 + 15 + static inline __be16 tun_p_to_eth_p(u8 proto) 16 + { 17 + switch (proto) { 18 + case TUN_P_IPV4: 19 + return htons(ETH_P_IP); 20 + case TUN_P_IPV6: 21 + return htons(ETH_P_IPV6); 22 + case TUN_P_ETHERNET: 23 + return htons(ETH_P_TEB); 24 + case TUN_P_NSH: 25 + return htons(ETH_P_NSH); 26 + case TUN_P_MPLS_UC: 27 + return htons(ETH_P_MPLS_UC); 28 + } 29 + return 0; 30 + } 31 + 32 + static inline u8 tun_p_from_eth_p(__be16 proto) 33 + { 34 + switch (proto) { 35 + case htons(ETH_P_IP): 36 + return TUN_P_IPV4; 37 + case htons(ETH_P_IPV6): 38 + return TUN_P_IPV6; 39 + case htons(ETH_P_TEB): 40 + return TUN_P_ETHERNET; 41 + case htons(ETH_P_NSH): 42 + return TUN_P_NSH; 43 + case htons(ETH_P_MPLS_UC): 44 + return TUN_P_MPLS_UC; 45 + } 46 + return 0; 47 + } 48 + 49 + #endif
-6
include/net/vxlan.h
··· 168 168 #define VXLAN_GPE_USED_BITS (VXLAN_HF_VER | VXLAN_HF_NP | VXLAN_HF_OAM | \ 169 169 cpu_to_be32(0xff)) 170 170 171 - /* VXLAN-GPE header Next Protocol. */ 172 - #define VXLAN_GPE_NP_IPV4 0x01 173 - #define VXLAN_GPE_NP_IPV6 0x02 174 - #define VXLAN_GPE_NP_ETHERNET 0x03 175 - #define VXLAN_GPE_NP_NSH 0x04 176 - 177 171 struct vxlan_metadata { 178 172 u32 gbp; 179 173 };
+1
include/uapi/linux/if_ether.h
··· 99 99 #define ETH_P_FIP 0x8914 /* FCoE Initialization Protocol */ 100 100 #define ETH_P_80221 0x8917 /* IEEE 802.21 Media Independent Handover Protocol */ 101 101 #define ETH_P_HSR 0x892F /* IEC 62439-3 HSRv1 */ 102 + #define ETH_P_NSH 0x894F /* Network Service Header */ 102 103 #define ETH_P_LOOPBACK 0x9000 /* Ethernet loopback packet, per IEEE 802.3 */ 103 104 #define ETH_P_QINQ1 0x9100 /* deprecated QinQ VLAN [ NOT AN OFFICIALLY REGISTERED ID ] */ 104 105 #define ETH_P_QINQ2 0x9200 /* deprecated QinQ VLAN [ NOT AN OFFICIALLY REGISTERED ID ] */
+1
net/Kconfig
··· 235 235 source "net/vmw_vsock/Kconfig" 236 236 source "net/netlink/Kconfig" 237 237 source "net/mpls/Kconfig" 238 + source "net/nsh/Kconfig" 238 239 source "net/hsr/Kconfig" 239 240 source "net/switchdev/Kconfig" 240 241 source "net/l3mdev/Kconfig"
+1
net/Makefile
··· 75 75 obj-$(CONFIG_OPENVSWITCH) += openvswitch/ 76 76 obj-$(CONFIG_VSOCKETS) += vmw_vsock/ 77 77 obj-$(CONFIG_MPLS) += mpls/ 78 + obj-$(CONFIG_NET_NSH) += nsh/ 78 79 obj-$(CONFIG_HSR) += hsr/ 79 80 ifneq ($(CONFIG_NET_SWITCHDEV),) 80 81 obj-y += switchdev/
+9
net/nsh/Kconfig
··· 1 + menuconfig NET_NSH 2 + tristate "Network Service Header (NSH) protocol" 3 + default n 4 + ---help--- 5 + Network Service Header is an implementation of Service Function 6 + Chaining (RFC 7665). The current implementation in Linux supports 7 + only MD type 1 and only with the openvswitch module. 8 + 9 + If unsure, say N.
+1
net/nsh/Makefile
··· 1 + obj-$(CONFIG_NET_NSH) += nsh.o
+91
net/nsh/nsh.c
··· 1 + /* 2 + * Network Service Header 3 + * 4 + * Copyright (c) 2017 Red Hat, Inc. -- Jiri Benc <jbenc@redhat.com> 5 + * 6 + * This program is free software; you can redistribute it and/or modify 7 + * it under the terms of the GNU General Public License version 2 as 8 + * published by the Free Software Foundation. 9 + */ 10 + 11 + #include <linux/module.h> 12 + #include <linux/netdevice.h> 13 + #include <linux/skbuff.h> 14 + #include <net/nsh.h> 15 + #include <net/tun_proto.h> 16 + 17 + static struct sk_buff *nsh_gso_segment(struct sk_buff *skb, 18 + netdev_features_t features) 19 + { 20 + struct sk_buff *segs = ERR_PTR(-EINVAL); 21 + unsigned int nsh_len, mac_len; 22 + __be16 proto; 23 + int nhoff; 24 + 25 + skb_reset_network_header(skb); 26 + 27 + nhoff = skb->network_header - skb->mac_header; 28 + mac_len = skb->mac_len; 29 + 30 + if (unlikely(!pskb_may_pull(skb, NSH_BASE_HDR_LEN))) 31 + goto out; 32 + nsh_len = nsh_hdr_len(nsh_hdr(skb)); 33 + if (unlikely(!pskb_may_pull(skb, nsh_len))) 34 + goto out; 35 + 36 + proto = tun_p_to_eth_p(nsh_hdr(skb)->np); 37 + if (!proto) 38 + goto out; 39 + 40 + __skb_pull(skb, nsh_len); 41 + 42 + skb_reset_mac_header(skb); 43 + skb_reset_mac_len(skb); 44 + skb->protocol = proto; 45 + 46 + features &= NETIF_F_SG; 47 + segs = skb_mac_gso_segment(skb, features); 48 + if (IS_ERR_OR_NULL(segs)) { 49 + skb_gso_error_unwind(skb, htons(ETH_P_NSH), nsh_len, 50 + skb->network_header - nhoff, 51 + mac_len); 52 + goto out; 53 + } 54 + 55 + for (skb = segs; skb; skb = skb->next) { 56 + skb->protocol = htons(ETH_P_NSH); 57 + __skb_push(skb, nsh_len); 58 + skb_set_mac_header(skb, -nhoff); 59 + skb->network_header = skb->mac_header + mac_len; 60 + skb->mac_len = mac_len; 61 + } 62 + 63 + out: 64 + return segs; 65 + } 66 + 67 + static struct packet_offload nsh_packet_offload __read_mostly = { 68 + .type = htons(ETH_P_NSH), 69 + .priority = 15, 70 + .callbacks = { 71 + .gso_segment = nsh_gso_segment, 72 + }, 73 + }; 74 + 75 + static int __init nsh_init_module(void) 76 + { 77 + dev_add_offload(&nsh_packet_offload); 78 + return 0; 79 + } 80 + 81 + static void __exit nsh_cleanup_module(void) 82 + { 83 + dev_remove_offload(&nsh_packet_offload); 84 + } 85 + 86 + module_init(nsh_init_module); 87 + module_exit(nsh_cleanup_module); 88 + 89 + MODULE_AUTHOR("Jiri Benc <jbenc@redhat.com>"); 90 + MODULE_DESCRIPTION("NSH protocol"); 91 + MODULE_LICENSE("GPL v2");