Skip to content

Commit de960aa

Browse files
Florian Westphaldavem330
authored andcommitted
net: add and use skb_gso_transport_seglen()
This moves part of Eric Dumazets skb_gso_seglen helper from tbf sched to skbuff core so it may be reused by upcoming ip forwarding path patch. Signed-off-by: Florian Westphal <fw@strlen.de> Acked-by: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 77d143d commit de960aa

3 files changed

Lines changed: 29 additions & 10 deletions

File tree

‎include/linux/skbuff.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2456,6 +2456,7 @@ void skb_zerocopy(struct sk_buff *to, const struct sk_buff *from,
24562456
void skb_split(struct sk_buff *skb, struct sk_buff *skb1, const u32 len);
24572457
int skb_shift(struct sk_buff *tgt, struct sk_buff *skb, int shiftlen);
24582458
void skb_scrub_packet(struct sk_buff *skb, bool xnet);
2459+
unsigned int skb_gso_transport_seglen(const struct sk_buff *skb);
24592460
struct sk_buff *skb_segment(struct sk_buff *skb, netdev_features_t features);
24602461

24612462
struct skb_checksum_ops {

‎net/core/skbuff.c‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
#include <linux/in.h>
4848
#include <linux/inet.h>
4949
#include <linux/slab.h>
50+
#include <linux/tcp.h>
51+
#include <linux/udp.h>
5052
#include <linux/netdevice.h>
5153
#ifdef CONFIG_NET_CLS_ACT
5254
#include <net/pkt_sched.h>
@@ -3916,3 +3918,26 @@ void skb_scrub_packet(struct sk_buff *skb, bool xnet)
39163918
nf_reset_trace(skb);
39173919
}
39183920
EXPORT_SYMBOL_GPL(skb_scrub_packet);
3921+
3922+
/**
3923+
* skb_gso_transport_seglen - Return length of individual segments of a gso packet
3924+
*
3925+
* @skb: GSO skb
3926+
*
3927+
* skb_gso_transport_seglen is used to determine the real size of the
3928+
* individual segments, including Layer4 headers (TCP/UDP).
3929+
*
3930+
* The MAC/L2 or network (IP, IPv6) headers are not accounted for.
3931+
*/
3932+
unsigned int skb_gso_transport_seglen(const struct sk_buff *skb)
3933+
{
3934+
const struct skb_shared_info *shinfo = skb_shinfo(skb);
3935+
unsigned int hdr_len;
3936+
3937+
if (likely(shinfo->gso_type & (SKB_GSO_TCPV4 | SKB_GSO_TCPV6)))
3938+
hdr_len = tcp_hdrlen(skb);
3939+
else
3940+
hdr_len = sizeof(struct udphdr);
3941+
return hdr_len + shinfo->gso_size;
3942+
}
3943+
EXPORT_SYMBOL_GPL(skb_gso_transport_seglen);

‎net/sched/sch_tbf.c‎

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include <net/netlink.h>
2222
#include <net/sch_generic.h>
2323
#include <net/pkt_sched.h>
24-
#include <net/tcp.h>
2524

2625

2726
/* Simple Token Bucket Filter.
@@ -148,16 +147,10 @@ static u64 psched_ns_t2l(const struct psched_ratecfg *r,
148147
* Return length of individual segments of a gso packet,
149148
* including all headers (MAC, IP, TCP/UDP)
150149
*/
151-
static unsigned int skb_gso_seglen(const struct sk_buff *skb)
150+
static unsigned int skb_gso_mac_seglen(const struct sk_buff *skb)
152151
{
153152
unsigned int hdr_len = skb_transport_header(skb) - skb_mac_header(skb);
154-
const struct skb_shared_info *shinfo = skb_shinfo(skb);
155-
156-
if (likely(shinfo->gso_type & (SKB_GSO_TCPV4 | SKB_GSO_TCPV6)))
157-
hdr_len += tcp_hdrlen(skb);
158-
else
159-
hdr_len += sizeof(struct udphdr);
160-
return hdr_len + shinfo->gso_size;
153+
return hdr_len + skb_gso_transport_seglen(skb);
161154
}
162155

163156
/* GSO packet is too big, segment it so that tbf can transmit
@@ -202,7 +195,7 @@ static int tbf_enqueue(struct sk_buff *skb, struct Qdisc *sch)
202195
int ret;
203196

204197
if (qdisc_pkt_len(skb) > q->max_size) {
205-
if (skb_is_gso(skb) && skb_gso_seglen(skb) <= q->max_size)
198+
if (skb_is_gso(skb) && skb_gso_mac_seglen(skb) <= q->max_size)
206199
return tbf_segment(skb, sch);
207200
return qdisc_reshape_fail(skb, sch);
208201
}

0 commit comments

Comments
 (0)