Skip to content

Commit 3347c96

Browse files
edumazetdavem330
authored andcommitted
ipv4: gso: make inet_gso_segment() stackable
In order to support GSO on IPIP, we need to make inet_gso_segment() stackable. It should not assume network header starts right after mac header. Signed-off-by: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 2d26f0a commit 3347c96

3 files changed

Lines changed: 25 additions & 9 deletions

File tree

‎include/linux/skbuff.h‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2722,9 +2722,12 @@ static inline struct sec_path *skb_sec_path(struct sk_buff *skb)
27222722
/* Keeps track of mac header offset relative to skb->head.
27232723
* It is useful for TSO of Tunneling protocol. e.g. GRE.
27242724
* For non-tunnel skb it points to skb_mac_header() and for
2725-
* tunnel skb it points to outer mac header. */
2725+
* tunnel skb it points to outer mac header.
2726+
* Keeps track of level of encapsulation of network headers.
2727+
*/
27262728
struct skb_gso_cb {
2727-
int mac_offset;
2729+
int mac_offset;
2730+
int encap_level;
27282731
};
27292732
#define SKB_GSO_CB(skb) ((struct skb_gso_cb *)(skb)->cb)
27302733

‎net/core/dev.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2377,6 +2377,8 @@ struct sk_buff *__skb_gso_segment(struct sk_buff *skb,
23772377
}
23782378

23792379
SKB_GSO_CB(skb)->mac_offset = skb_headroom(skb);
2380+
SKB_GSO_CB(skb)->encap_level = 0;
2381+
23802382
skb_reset_mac_header(skb);
23812383
skb_reset_mac_len(skb);
23822384

‎net/ipv4/af_inet.c‎

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,16 +1273,17 @@ static int inet_gso_send_check(struct sk_buff *skb)
12731273
}
12741274

12751275
static struct sk_buff *inet_gso_segment(struct sk_buff *skb,
1276-
netdev_features_t features)
1276+
netdev_features_t features)
12771277
{
12781278
struct sk_buff *segs = ERR_PTR(-EINVAL);
12791279
const struct net_offload *ops;
1280+
unsigned int offset = 0;
12801281
struct iphdr *iph;
1282+
bool tunnel;
12811283
int proto;
1284+
int nhoff;
12821285
int ihl;
12831286
int id;
1284-
unsigned int offset = 0;
1285-
bool tunnel;
12861287

12871288
if (unlikely(skb_shinfo(skb)->gso_type &
12881289
~(SKB_GSO_TCPV4 |
@@ -1296,6 +1297,8 @@ static struct sk_buff *inet_gso_segment(struct sk_buff *skb,
12961297
0)))
12971298
goto out;
12981299

1300+
skb_reset_network_header(skb);
1301+
nhoff = skb_network_header(skb) - skb_mac_header(skb);
12991302
if (unlikely(!pskb_may_pull(skb, sizeof(*iph))))
13001303
goto out;
13011304

@@ -1312,7 +1315,10 @@ static struct sk_buff *inet_gso_segment(struct sk_buff *skb,
13121315
goto out;
13131316
__skb_pull(skb, ihl);
13141317

1315-
tunnel = !!skb->encapsulation;
1318+
tunnel = SKB_GSO_CB(skb)->encap_level > 0;
1319+
if (tunnel)
1320+
features = skb->dev->hw_enc_features & netif_skb_features(skb);
1321+
SKB_GSO_CB(skb)->encap_level += ihl;
13161322

13171323
skb_reset_transport_header(skb);
13181324

@@ -1327,18 +1333,23 @@ static struct sk_buff *inet_gso_segment(struct sk_buff *skb,
13271333

13281334
skb = segs;
13291335
do {
1330-
iph = ip_hdr(skb);
1336+
iph = (struct iphdr *)(skb_mac_header(skb) + nhoff);
13311337
if (!tunnel && proto == IPPROTO_UDP) {
13321338
iph->id = htons(id);
13331339
iph->frag_off = htons(offset >> 3);
13341340
if (skb->next != NULL)
13351341
iph->frag_off |= htons(IP_MF);
1336-
offset += (skb->len - skb->mac_len - iph->ihl * 4);
1342+
offset += skb->len - nhoff - ihl;
13371343
} else {
13381344
iph->id = htons(id++);
13391345
}
1340-
iph->tot_len = htons(skb->len - skb->mac_len);
1346+
iph->tot_len = htons(skb->len - nhoff);
13411347
ip_send_check(iph);
1348+
if (tunnel) {
1349+
skb_reset_inner_headers(skb);
1350+
skb->encapsulation = 1;
1351+
}
1352+
skb->network_header = (u8 *)iph - skb->head;
13421353
} while ((skb = skb->next));
13431354

13441355
out:

0 commit comments

Comments
 (0)