Skip to content

Commit b1a78b9

Browse files
lxinkuba-moo
authored andcommitted
net: add support for ipv4 big tcp
Similar to Eric's IPv6 BIG TCP, this patch is to enable IPv4 BIG TCP. Firstly, allow sk->sk_gso_max_size to be set to a value greater than GSO_LEGACY_MAX_SIZE by not trimming gso_max_size in sk_trim_gso_size() for IPv4 TCP sockets. Then on TX path, set IP header tot_len to 0 when skb->len > IP_MAX_MTU in __ip_local_out() to allow to send BIG TCP packets, and this implies that skb->len is the length of a IPv4 packet; On RX path, use skb->len as the length of the IPv4 packet when the IP header tot_len is 0 and skb->len > IP_MAX_MTU in ip_rcv_core(). As the API iph_set_totlen() and skb_ip_totlen() are used in __ip_local_out() and ip_rcv_core(), we only need to update these APIs. Also in GRO receive, add the check for ETH_P_IP/IPPROTO_TCP, and allows the merged packet size >= GRO_LEGACY_MAX_SIZE in skb_gro_receive(). In GRO complete, set IP header tot_len to 0 when the merged packet size greater than IP_MAX_MTU in iph_set_totlen() so that it can be processed on RX path. Note that by checking skb_is_gso_tcp() in API iph_totlen(), it makes this implementation safe to use iph->len == 0 indicates IPv4 BIG TCP packets. Signed-off-by: Xin Long <lucien.xin@gmail.com> Reviewed-by: David Ahern <dsahern@kernel.org> Reviewed-by: Eric Dumazet <edumazet@google.com> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 9eefedd commit b1a78b9

File tree

5 files changed

+27
-22
lines changed

5 files changed

+27
-22
lines changed

net/core/gro.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,16 +162,18 @@ int skb_gro_receive(struct sk_buff *p, struct sk_buff *skb)
162162
struct sk_buff *lp;
163163
int segs;
164164

165-
/* pairs with WRITE_ONCE() in netif_set_gro_max_size() */
166-
gro_max_size = READ_ONCE(p->dev->gro_max_size);
165+
/* pairs with WRITE_ONCE() in netif_set_gro(_ipv4)_max_size() */
166+
gro_max_size = p->protocol == htons(ETH_P_IPV6) ?
167+
READ_ONCE(p->dev->gro_max_size) :
168+
READ_ONCE(p->dev->gro_ipv4_max_size);
167169

168170
if (unlikely(p->len + len >= gro_max_size || NAPI_GRO_CB(skb)->flush))
169171
return -E2BIG;
170172

171173
if (unlikely(p->len + len >= GRO_LEGACY_MAX_SIZE)) {
172-
if (p->protocol != htons(ETH_P_IPV6) ||
173-
skb_headroom(p) < sizeof(struct hop_jumbo_hdr) ||
174-
ipv6_hdr(p)->nexthdr != IPPROTO_TCP ||
174+
if (NAPI_GRO_CB(skb)->proto != IPPROTO_TCP ||
175+
(p->protocol == htons(ETH_P_IPV6) &&
176+
skb_headroom(p) < sizeof(struct hop_jumbo_hdr)) ||
175177
p->encapsulation)
176178
return -E2BIG;
177179
}

net/core/sock.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2373,17 +2373,22 @@ void sk_free_unlock_clone(struct sock *sk)
23732373
}
23742374
EXPORT_SYMBOL_GPL(sk_free_unlock_clone);
23752375

2376-
static void sk_trim_gso_size(struct sock *sk)
2376+
static u32 sk_dst_gso_max_size(struct sock *sk, struct dst_entry *dst)
23772377
{
2378-
if (sk->sk_gso_max_size <= GSO_LEGACY_MAX_SIZE)
2379-
return;
2378+
bool is_ipv6 = false;
2379+
u32 max_size;
2380+
23802381
#if IS_ENABLED(CONFIG_IPV6)
2381-
if (sk->sk_family == AF_INET6 &&
2382-
sk_is_tcp(sk) &&
2383-
!ipv6_addr_v4mapped(&sk->sk_v6_rcv_saddr))
2384-
return;
2382+
is_ipv6 = (sk->sk_family == AF_INET6 &&
2383+
!ipv6_addr_v4mapped(&sk->sk_v6_rcv_saddr));
23852384
#endif
2386-
sk->sk_gso_max_size = GSO_LEGACY_MAX_SIZE;
2385+
/* pairs with the WRITE_ONCE() in netif_set_gso(_ipv4)_max_size() */
2386+
max_size = is_ipv6 ? READ_ONCE(dst->dev->gso_max_size) :
2387+
READ_ONCE(dst->dev->gso_ipv4_max_size);
2388+
if (max_size > GSO_LEGACY_MAX_SIZE && !sk_is_tcp(sk))
2389+
max_size = GSO_LEGACY_MAX_SIZE;
2390+
2391+
return max_size - (MAX_TCP_HEADER + 1);
23872392
}
23882393

23892394
void sk_setup_caps(struct sock *sk, struct dst_entry *dst)
@@ -2403,10 +2408,7 @@ void sk_setup_caps(struct sock *sk, struct dst_entry *dst)
24032408
sk->sk_route_caps &= ~NETIF_F_GSO_MASK;
24042409
} else {
24052410
sk->sk_route_caps |= NETIF_F_SG | NETIF_F_HW_CSUM;
2406-
/* pairs with the WRITE_ONCE() in netif_set_gso_max_size() */
2407-
sk->sk_gso_max_size = READ_ONCE(dst->dev->gso_max_size);
2408-
sk_trim_gso_size(sk);
2409-
sk->sk_gso_max_size -= (MAX_TCP_HEADER + 1);
2411+
sk->sk_gso_max_size = sk_dst_gso_max_size(sk, dst);
24102412
/* pairs with the WRITE_ONCE() in netif_set_gso_max_segs() */
24112413
max_segs = max_t(u32, READ_ONCE(dst->dev->gso_max_segs), 1);
24122414
}

net/ipv4/af_inet.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,6 +1485,7 @@ struct sk_buff *inet_gro_receive(struct list_head *head, struct sk_buff *skb)
14851485
if (unlikely(ip_fast_csum((u8 *)iph, 5)))
14861486
goto out;
14871487

1488+
NAPI_GRO_CB(skb)->proto = proto;
14881489
id = ntohl(*(__be32 *)&iph->id);
14891490
flush = (u16)((ntohl(*(__be32 *)iph) ^ skb_gro_len(skb)) | (id & ~IP_DF));
14901491
id >>= 16;
@@ -1618,9 +1619,9 @@ int inet_recv_error(struct sock *sk, struct msghdr *msg, int len, int *addr_len)
16181619

16191620
int inet_gro_complete(struct sk_buff *skb, int nhoff)
16201621
{
1621-
__be16 newlen = htons(skb->len - nhoff);
16221622
struct iphdr *iph = (struct iphdr *)(skb->data + nhoff);
16231623
const struct net_offload *ops;
1624+
__be16 totlen = iph->tot_len;
16241625
int proto = iph->protocol;
16251626
int err = -ENOSYS;
16261627

@@ -1629,8 +1630,8 @@ int inet_gro_complete(struct sk_buff *skb, int nhoff)
16291630
skb_set_inner_network_header(skb, nhoff);
16301631
}
16311632

1632-
csum_replace2(&iph->check, iph->tot_len, newlen);
1633-
iph->tot_len = newlen;
1633+
iph_set_totlen(iph, skb->len - nhoff);
1634+
csum_replace2(&iph->check, totlen, iph->tot_len);
16341635

16351636
ops = rcu_dereference(inet_offloads[proto]);
16361637
if (WARN_ON(!ops || !ops->callbacks.gro_complete))

net/ipv4/ip_input.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ static struct sk_buff *ip_rcv_core(struct sk_buff *skb, struct net *net)
511511
if (unlikely(ip_fast_csum((u8 *)iph, iph->ihl)))
512512
goto csum_error;
513513

514-
len = ntohs(iph->tot_len);
514+
len = iph_totlen(skb, iph);
515515
if (skb->len < len) {
516516
drop_reason = SKB_DROP_REASON_PKT_TOO_SMALL;
517517
__IP_INC_STATS(net, IPSTATS_MIB_INTRUNCATEDPKTS);

net/ipv4/ip_output.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ int __ip_local_out(struct net *net, struct sock *sk, struct sk_buff *skb)
100100
{
101101
struct iphdr *iph = ip_hdr(skb);
102102

103-
iph->tot_len = htons(skb->len);
103+
iph_set_totlen(iph, skb->len);
104104
ip_send_check(iph);
105105

106106
/* if egress device is enslaved to an L3 master device pass the

0 commit comments

Comments
 (0)