Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 0abf77e

Browse files
jkivilindavem330
authored andcommitted
net_sched: Add accessor function for packet length for qdiscs
Signed-off-by: Jussi Kivilinna <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 5f86173 commit 0abf77e

22 files changed

+69
-67
lines changed

include/net/sch_generic.h

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,11 @@ static inline bool qdisc_tx_is_noop(const struct net_device *dev)
306306
return true;
307307
}
308308

309+
static inline unsigned int qdisc_pkt_len(struct sk_buff *skb)
310+
{
311+
return skb->len;
312+
}
313+
309314
static inline int qdisc_enqueue(struct sk_buff *skb, struct Qdisc *sch)
310315
{
311316
return sch->enqueue(skb, sch);
@@ -320,8 +325,8 @@ static inline int __qdisc_enqueue_tail(struct sk_buff *skb, struct Qdisc *sch,
320325
struct sk_buff_head *list)
321326
{
322327
__skb_queue_tail(list, skb);
323-
sch->qstats.backlog += skb->len;
324-
sch->bstats.bytes += skb->len;
328+
sch->qstats.backlog += qdisc_pkt_len(skb);
329+
sch->bstats.bytes += qdisc_pkt_len(skb);
325330
sch->bstats.packets++;
326331

327332
return NET_XMIT_SUCCESS;
@@ -338,7 +343,7 @@ static inline struct sk_buff *__qdisc_dequeue_head(struct Qdisc *sch,
338343
struct sk_buff *skb = __skb_dequeue(list);
339344

340345
if (likely(skb != NULL))
341-
sch->qstats.backlog -= skb->len;
346+
sch->qstats.backlog -= qdisc_pkt_len(skb);
342347

343348
return skb;
344349
}
@@ -354,7 +359,7 @@ static inline struct sk_buff *__qdisc_dequeue_tail(struct Qdisc *sch,
354359
struct sk_buff *skb = __skb_dequeue_tail(list);
355360

356361
if (likely(skb != NULL))
357-
sch->qstats.backlog -= skb->len;
362+
sch->qstats.backlog -= qdisc_pkt_len(skb);
358363

359364
return skb;
360365
}
@@ -368,7 +373,7 @@ static inline int __qdisc_requeue(struct sk_buff *skb, struct Qdisc *sch,
368373
struct sk_buff_head *list)
369374
{
370375
__skb_queue_head(list, skb);
371-
sch->qstats.backlog += skb->len;
376+
sch->qstats.backlog += qdisc_pkt_len(skb);
372377
sch->qstats.requeues++;
373378

374379
return NET_XMIT_SUCCESS;
@@ -401,7 +406,7 @@ static inline unsigned int __qdisc_queue_drop(struct Qdisc *sch,
401406
struct sk_buff *skb = __qdisc_dequeue_tail(sch, list);
402407

403408
if (likely(skb != NULL)) {
404-
unsigned int len = skb->len;
409+
unsigned int len = qdisc_pkt_len(skb);
405410
kfree_skb(skb);
406411
return len;
407412
}

net/sched/act_gact.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ static int tcf_gact(struct sk_buff *skb, struct tc_action *a, struct tcf_result
139139
#else
140140
action = gact->tcf_action;
141141
#endif
142-
gact->tcf_bstats.bytes += skb->len;
142+
gact->tcf_bstats.bytes += qdisc_pkt_len(skb);
143143
gact->tcf_bstats.packets++;
144144
if (action == TC_ACT_SHOT)
145145
gact->tcf_qstats.drops++;

net/sched/act_ipt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ static int tcf_ipt(struct sk_buff *skb, struct tc_action *a,
205205
spin_lock(&ipt->tcf_lock);
206206

207207
ipt->tcf_tm.lastuse = jiffies;
208-
ipt->tcf_bstats.bytes += skb->len;
208+
ipt->tcf_bstats.bytes += qdisc_pkt_len(skb);
209209
ipt->tcf_bstats.packets++;
210210

211211
/* yes, we have to worry about both in and out dev

net/sched/act_mirred.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ static int tcf_mirred(struct sk_buff *skb, struct tc_action *a,
164164
if (skb2 != NULL)
165165
kfree_skb(skb2);
166166
m->tcf_qstats.overlimits++;
167-
m->tcf_bstats.bytes += skb->len;
167+
m->tcf_bstats.bytes += qdisc_pkt_len(skb);
168168
m->tcf_bstats.packets++;
169169
spin_unlock(&m->tcf_lock);
170170
/* should we be asking for packet to be dropped?
@@ -184,7 +184,7 @@ static int tcf_mirred(struct sk_buff *skb, struct tc_action *a,
184184
goto bad_mirred;
185185
}
186186

187-
m->tcf_bstats.bytes += skb2->len;
187+
m->tcf_bstats.bytes += qdisc_pkt_len(skb2);
188188
m->tcf_bstats.packets++;
189189
if (!(at & AT_EGRESS))
190190
if (m->tcfm_ok_push)

net/sched/act_nat.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ static int tcf_nat(struct sk_buff *skb, struct tc_action *a,
124124
egress = p->flags & TCA_NAT_FLAG_EGRESS;
125125
action = p->tcf_action;
126126

127-
p->tcf_bstats.bytes += skb->len;
127+
p->tcf_bstats.bytes += qdisc_pkt_len(skb);
128128
p->tcf_bstats.packets++;
129129

130130
spin_unlock(&p->tcf_lock);

net/sched/act_pedit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ static int tcf_pedit(struct sk_buff *skb, struct tc_action *a,
182182
bad:
183183
p->tcf_qstats.overlimits++;
184184
done:
185-
p->tcf_bstats.bytes += skb->len;
185+
p->tcf_bstats.bytes += qdisc_pkt_len(skb);
186186
p->tcf_bstats.packets++;
187187
spin_unlock(&p->tcf_lock);
188188
return p->tcf_action;

net/sched/act_police.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ static int tcf_act_police(struct sk_buff *skb, struct tc_action *a,
272272

273273
spin_lock(&police->tcf_lock);
274274

275-
police->tcf_bstats.bytes += skb->len;
275+
police->tcf_bstats.bytes += qdisc_pkt_len(skb);
276276
police->tcf_bstats.packets++;
277277

278278
if (police->tcfp_ewma_rate &&
@@ -282,7 +282,7 @@ static int tcf_act_police(struct sk_buff *skb, struct tc_action *a,
282282
return police->tcf_action;
283283
}
284284

285-
if (skb->len <= police->tcfp_mtu) {
285+
if (qdisc_pkt_len(skb) <= police->tcfp_mtu) {
286286
if (police->tcfp_R_tab == NULL) {
287287
spin_unlock(&police->tcf_lock);
288288
return police->tcfp_result;
@@ -295,12 +295,12 @@ static int tcf_act_police(struct sk_buff *skb, struct tc_action *a,
295295
ptoks = toks + police->tcfp_ptoks;
296296
if (ptoks > (long)L2T_P(police, police->tcfp_mtu))
297297
ptoks = (long)L2T_P(police, police->tcfp_mtu);
298-
ptoks -= L2T_P(police, skb->len);
298+
ptoks -= L2T_P(police, qdisc_pkt_len(skb));
299299
}
300300
toks += police->tcfp_toks;
301301
if (toks > (long)police->tcfp_burst)
302302
toks = police->tcfp_burst;
303-
toks -= L2T(police, skb->len);
303+
toks -= L2T(police, qdisc_pkt_len(skb));
304304
if ((toks|ptoks) >= 0) {
305305
police->tcfp_t_c = now;
306306
police->tcfp_toks = toks;

net/sched/act_simple.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ static int tcf_simp(struct sk_buff *skb, struct tc_action *a, struct tcf_result
4141

4242
spin_lock(&d->tcf_lock);
4343
d->tcf_tm.lastuse = jiffies;
44-
d->tcf_bstats.bytes += skb->len;
44+
d->tcf_bstats.bytes += qdisc_pkt_len(skb);
4545
d->tcf_bstats.packets++;
4646

4747
/* print policy string followed by _ then packet count

net/sched/sch_atm.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,9 +437,9 @@ drop: __maybe_unused
437437
flow->qstats.drops++;
438438
return ret;
439439
}
440-
sch->bstats.bytes += skb->len;
440+
sch->bstats.bytes += qdisc_pkt_len(skb);
441441
sch->bstats.packets++;
442-
flow->bstats.bytes += skb->len;
442+
flow->bstats.bytes += qdisc_pkt_len(skb);
443443
flow->bstats.packets++;
444444
/*
445445
* Okay, this may seem weird. We pretend we've dropped the packet if

net/sched/sch_cbq.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,6 @@ static int
370370
cbq_enqueue(struct sk_buff *skb, struct Qdisc *sch)
371371
{
372372
struct cbq_sched_data *q = qdisc_priv(sch);
373-
int len = skb->len;
374373
int uninitialized_var(ret);
375374
struct cbq_class *cl = cbq_classify(skb, sch, &ret);
376375

@@ -391,7 +390,7 @@ cbq_enqueue(struct sk_buff *skb, struct Qdisc *sch)
391390
if (ret == NET_XMIT_SUCCESS) {
392391
sch->q.qlen++;
393392
sch->bstats.packets++;
394-
sch->bstats.bytes+=len;
393+
sch->bstats.bytes += qdisc_pkt_len(skb);
395394
cbq_mark_toplevel(q, cl);
396395
if (!cl->next_alive)
397396
cbq_activate_class(cl);
@@ -658,7 +657,6 @@ static enum hrtimer_restart cbq_undelay(struct hrtimer *timer)
658657
#ifdef CONFIG_NET_CLS_ACT
659658
static int cbq_reshape_fail(struct sk_buff *skb, struct Qdisc *child)
660659
{
661-
int len = skb->len;
662660
struct Qdisc *sch = child->__parent;
663661
struct cbq_sched_data *q = qdisc_priv(sch);
664662
struct cbq_class *cl = q->rx_class;
@@ -675,7 +673,7 @@ static int cbq_reshape_fail(struct sk_buff *skb, struct Qdisc *child)
675673
if (qdisc_enqueue(skb, cl->q) == 0) {
676674
sch->q.qlen++;
677675
sch->bstats.packets++;
678-
sch->bstats.bytes+=len;
676+
sch->bstats.bytes += qdisc_pkt_len(skb);
679677
if (!cl->next_alive)
680678
cbq_activate_class(cl);
681679
return 0;
@@ -881,19 +879,19 @@ cbq_dequeue_prio(struct Qdisc *sch, int prio)
881879
if (skb == NULL)
882880
goto skip_class;
883881

884-
cl->deficit -= skb->len;
882+
cl->deficit -= qdisc_pkt_len(skb);
885883
q->tx_class = cl;
886884
q->tx_borrowed = borrow;
887885
if (borrow != cl) {
888886
#ifndef CBQ_XSTATS_BORROWS_BYTES
889887
borrow->xstats.borrows++;
890888
cl->xstats.borrows++;
891889
#else
892-
borrow->xstats.borrows += skb->len;
893-
cl->xstats.borrows += skb->len;
890+
borrow->xstats.borrows += qdisc_pkt_len(skb);
891+
cl->xstats.borrows += qdisc_pkt_len(skb);
894892
#endif
895893
}
896-
q->tx_len = skb->len;
894+
q->tx_len = qdisc_pkt_len(skb);
897895

898896
if (cl->deficit <= 0) {
899897
q->active[prio] = cl;

net/sched/sch_dsmark.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ static int dsmark_enqueue(struct sk_buff *skb, struct Qdisc *sch)
258258
return err;
259259
}
260260

261-
sch->bstats.bytes += skb->len;
261+
sch->bstats.bytes += qdisc_pkt_len(skb);
262262
sch->bstats.packets++;
263263
sch->q.qlen++;
264264

net/sched/sch_fifo.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ static int bfifo_enqueue(struct sk_buff *skb, struct Qdisc* sch)
2727
{
2828
struct fifo_sched_data *q = qdisc_priv(sch);
2929

30-
if (likely(sch->qstats.backlog + skb->len <= q->limit))
30+
if (likely(sch->qstats.backlog + qdisc_pkt_len(skb) <= q->limit))
3131
return qdisc_enqueue_tail(skb, sch);
3232

3333
return qdisc_reshape_fail(skb, sch);

net/sched/sch_gred.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ static int gred_enqueue(struct sk_buff *skb, struct Qdisc* sch)
188188
}
189189

190190
q->packetsin++;
191-
q->bytesin += skb->len;
191+
q->bytesin += qdisc_pkt_len(skb);
192192

193193
if (gred_wred_mode(t))
194194
gred_load_wred_set(t, q);
@@ -226,8 +226,8 @@ static int gred_enqueue(struct sk_buff *skb, struct Qdisc* sch)
226226
break;
227227
}
228228

229-
if (q->backlog + skb->len <= q->limit) {
230-
q->backlog += skb->len;
229+
if (q->backlog + qdisc_pkt_len(skb) <= q->limit) {
230+
q->backlog += qdisc_pkt_len(skb);
231231
return qdisc_enqueue_tail(skb, sch);
232232
}
233233

@@ -254,7 +254,7 @@ static int gred_requeue(struct sk_buff *skb, struct Qdisc* sch)
254254
} else {
255255
if (red_is_idling(&q->parms))
256256
red_end_of_idle_period(&q->parms);
257-
q->backlog += skb->len;
257+
q->backlog += qdisc_pkt_len(skb);
258258
}
259259

260260
return qdisc_requeue(skb, sch);
@@ -277,7 +277,7 @@ static struct sk_buff *gred_dequeue(struct Qdisc* sch)
277277
"VQ 0x%x after dequeue, screwing up "
278278
"backlog.\n", tc_index_to_dp(skb));
279279
} else {
280-
q->backlog -= skb->len;
280+
q->backlog -= qdisc_pkt_len(skb);
281281

282282
if (!q->backlog && !gred_wred_mode(t))
283283
red_start_of_idle_period(&q->parms);
@@ -299,7 +299,7 @@ static unsigned int gred_drop(struct Qdisc* sch)
299299

300300
skb = qdisc_dequeue_tail(sch);
301301
if (skb) {
302-
unsigned int len = skb->len;
302+
unsigned int len = qdisc_pkt_len(skb);
303303
struct gred_sched_data *q;
304304
u16 dp = tc_index_to_dp(skb);
305305

net/sched/sch_hfsc.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,7 @@ qdisc_peek_len(struct Qdisc *sch)
895895
printk("qdisc_peek_len: non work-conserving qdisc ?\n");
896896
return 0;
897897
}
898-
len = skb->len;
898+
len = qdisc_pkt_len(skb);
899899
if (unlikely(sch->ops->requeue(skb, sch) != NET_XMIT_SUCCESS)) {
900900
if (net_ratelimit())
901901
printk("qdisc_peek_len: failed to requeue\n");
@@ -1574,7 +1574,6 @@ static int
15741574
hfsc_enqueue(struct sk_buff *skb, struct Qdisc *sch)
15751575
{
15761576
struct hfsc_class *cl;
1577-
unsigned int len;
15781577
int err;
15791578

15801579
cl = hfsc_classify(skb, sch, &err);
@@ -1585,7 +1584,6 @@ hfsc_enqueue(struct sk_buff *skb, struct Qdisc *sch)
15851584
return err;
15861585
}
15871586

1588-
len = skb->len;
15891587
err = qdisc_enqueue(skb, cl->qdisc);
15901588
if (unlikely(err != NET_XMIT_SUCCESS)) {
15911589
cl->qstats.drops++;
@@ -1594,12 +1592,12 @@ hfsc_enqueue(struct sk_buff *skb, struct Qdisc *sch)
15941592
}
15951593

15961594
if (cl->qdisc->q.qlen == 1)
1597-
set_active(cl, len);
1595+
set_active(cl, qdisc_pkt_len(skb));
15981596

15991597
cl->bstats.packets++;
1600-
cl->bstats.bytes += len;
1598+
cl->bstats.bytes += qdisc_pkt_len(skb);
16011599
sch->bstats.packets++;
1602-
sch->bstats.bytes += len;
1600+
sch->bstats.bytes += qdisc_pkt_len(skb);
16031601
sch->q.qlen++;
16041602

16051603
return NET_XMIT_SUCCESS;
@@ -1649,9 +1647,9 @@ hfsc_dequeue(struct Qdisc *sch)
16491647
return NULL;
16501648
}
16511649

1652-
update_vf(cl, skb->len, cur_time);
1650+
update_vf(cl, qdisc_pkt_len(skb), cur_time);
16531651
if (realtime)
1654-
cl->cl_cumul += skb->len;
1652+
cl->cl_cumul += qdisc_pkt_len(skb);
16551653

16561654
if (cl->qdisc->q.qlen != 0) {
16571655
if (cl->cl_flags & HFSC_RSC) {

net/sched/sch_htb.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -579,13 +579,13 @@ static int htb_enqueue(struct sk_buff *skb, struct Qdisc *sch)
579579
} else {
580580
cl->bstats.packets +=
581581
skb_is_gso(skb)?skb_shinfo(skb)->gso_segs:1;
582-
cl->bstats.bytes += skb->len;
582+
cl->bstats.bytes += qdisc_pkt_len(skb);
583583
htb_activate(q, cl);
584584
}
585585

586586
sch->q.qlen++;
587587
sch->bstats.packets += skb_is_gso(skb)?skb_shinfo(skb)->gso_segs:1;
588-
sch->bstats.bytes += skb->len;
588+
sch->bstats.bytes += qdisc_pkt_len(skb);
589589
return NET_XMIT_SUCCESS;
590590
}
591591

@@ -642,7 +642,7 @@ static int htb_requeue(struct sk_buff *skb, struct Qdisc *sch)
642642
static void htb_charge_class(struct htb_sched *q, struct htb_class *cl,
643643
int level, struct sk_buff *skb)
644644
{
645-
int bytes = skb->len;
645+
int bytes = qdisc_pkt_len(skb);
646646
long toks, diff;
647647
enum htb_cmode old_mode;
648648

@@ -855,7 +855,8 @@ static struct sk_buff *htb_dequeue_tree(struct htb_sched *q, int prio,
855855
} while (cl != start);
856856

857857
if (likely(skb != NULL)) {
858-
if ((cl->un.leaf.deficit[level] -= skb->len) < 0) {
858+
cl->un.leaf.deficit[level] -= qdisc_pkt_len(skb);
859+
if (cl->un.leaf.deficit[level] < 0) {
859860
cl->un.leaf.deficit[level] += cl->un.leaf.quantum;
860861
htb_next_rb_node((level ? cl->parent->un.inner.ptr : q->
861862
ptr[0]) + prio);

net/sched/sch_ingress.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ static int ingress_enqueue(struct sk_buff *skb, struct Qdisc *sch)
7777
result = tc_classify(skb, p->filter_list, &res);
7878

7979
sch->bstats.packets++;
80-
sch->bstats.bytes += skb->len;
80+
sch->bstats.bytes += qdisc_pkt_len(skb);
8181
switch (result) {
8282
case TC_ACT_SHOT:
8383
result = TC_ACT_SHOT;

0 commit comments

Comments
 (0)