Skip to content

Commit e4ae004

Browse files
edumazetdavem330
authored andcommitted
netem: add ECN capability
Add ECN (Explicit Congestion Notification) marking capability to netem tc qdisc add dev eth0 root netem drop 0.5 ecn Instead of dropping packets, try to ECN mark them. Signed-off-by: Eric Dumazet <edumazet@google.com> Cc: Neal Cardwell <ncardwell@google.com> Cc: Tom Herbert <therbert@google.com> Cc: Hagen Paul Pfeifer <hagen@jauu.net> Cc: Stephen Hemminger <shemminger@vyatta.com> Acked-by: Hagen Paul Pfeifer <hagen@jauu.net> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 18d0700 commit e4ae004

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

‎include/linux/pkt_sched.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,7 @@ enum {
509509
TCA_NETEM_CORRUPT,
510510
TCA_NETEM_LOSS,
511511
TCA_NETEM_RATE,
512+
TCA_NETEM_ECN,
512513
__TCA_NETEM_MAX,
513514
};
514515

‎net/sched/sch_netem.c‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#include <net/netlink.h>
2828
#include <net/pkt_sched.h>
29+
#include <net/inet_ecn.h>
2930

3031
#define VERSION "1.3"
3132

@@ -78,6 +79,7 @@ struct netem_sched_data {
7879
psched_tdiff_t jitter;
7980

8081
u32 loss;
82+
u32 ecn;
8183
u32 limit;
8284
u32 counter;
8385
u32 gap;
@@ -374,9 +376,12 @@ static int netem_enqueue(struct sk_buff *skb, struct Qdisc *sch)
374376
++count;
375377

376378
/* Drop packet? */
377-
if (loss_event(q))
378-
--count;
379-
379+
if (loss_event(q)) {
380+
if (q->ecn && INET_ECN_set_ce(skb))
381+
sch->qstats.drops++; /* mark packet */
382+
else
383+
--count;
384+
}
380385
if (count == 0) {
381386
sch->qstats.drops++;
382387
kfree_skb(skb);
@@ -706,6 +711,7 @@ static const struct nla_policy netem_policy[TCA_NETEM_MAX + 1] = {
706711
[TCA_NETEM_CORRUPT] = { .len = sizeof(struct tc_netem_corrupt) },
707712
[TCA_NETEM_RATE] = { .len = sizeof(struct tc_netem_rate) },
708713
[TCA_NETEM_LOSS] = { .type = NLA_NESTED },
714+
[TCA_NETEM_ECN] = { .type = NLA_U32 },
709715
};
710716

711717
static int parse_attr(struct nlattr *tb[], int maxtype, struct nlattr *nla,
@@ -776,6 +782,9 @@ static int netem_change(struct Qdisc *sch, struct nlattr *opt)
776782
if (tb[TCA_NETEM_RATE])
777783
get_rate(sch, tb[TCA_NETEM_RATE]);
778784

785+
if (tb[TCA_NETEM_ECN])
786+
q->ecn = nla_get_u32(tb[TCA_NETEM_ECN]);
787+
779788
q->loss_model = CLG_RANDOM;
780789
if (tb[TCA_NETEM_LOSS])
781790
ret = get_loss_clg(sch, tb[TCA_NETEM_LOSS]);
@@ -902,6 +911,9 @@ static int netem_dump(struct Qdisc *sch, struct sk_buff *skb)
902911
if (nla_put(skb, TCA_NETEM_RATE, sizeof(rate), &rate))
903912
goto nla_put_failure;
904913

914+
if (q->ecn && nla_put_u32(skb, TCA_NETEM_ECN, q->ecn))
915+
goto nla_put_failure;
916+
905917
if (dump_loss_model(q, skb) != 0)
906918
goto nla_put_failure;
907919

0 commit comments

Comments
 (0)