Skip to content

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;

0 commit comments

Comments
 (0)