Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Eric Dumazet and committed by
David S. Miller
e4ae004b 18d07000

+16 -3
+1
include/linux/pkt_sched.h
··· 509 509 TCA_NETEM_CORRUPT, 510 510 TCA_NETEM_LOSS, 511 511 TCA_NETEM_RATE, 512 + TCA_NETEM_ECN, 512 513 __TCA_NETEM_MAX, 513 514 }; 514 515
+15 -3
net/sched/sch_netem.c
··· 26 26 27 27 #include <net/netlink.h> 28 28 #include <net/pkt_sched.h> 29 + #include <net/inet_ecn.h> 29 30 30 31 #define VERSION "1.3" 31 32 ··· 79 78 psched_tdiff_t jitter; 80 79 81 80 u32 loss; 81 + u32 ecn; 82 82 u32 limit; 83 83 u32 counter; 84 84 u32 gap; ··· 376 374 ++count; 377 375 378 376 /* Drop packet? */ 379 - if (loss_event(q)) 380 - --count; 381 - 377 + if (loss_event(q)) { 378 + if (q->ecn && INET_ECN_set_ce(skb)) 379 + sch->qstats.drops++; /* mark packet */ 380 + else 381 + --count; 382 + } 382 383 if (count == 0) { 383 384 sch->qstats.drops++; 384 385 kfree_skb(skb); ··· 711 706 [TCA_NETEM_CORRUPT] = { .len = sizeof(struct tc_netem_corrupt) }, 712 707 [TCA_NETEM_RATE] = { .len = sizeof(struct tc_netem_rate) }, 713 708 [TCA_NETEM_LOSS] = { .type = NLA_NESTED }, 709 + [TCA_NETEM_ECN] = { .type = NLA_U32 }, 714 710 }; 715 711 716 712 static int parse_attr(struct nlattr *tb[], int maxtype, struct nlattr *nla, ··· 781 775 782 776 if (tb[TCA_NETEM_RATE]) 783 777 get_rate(sch, tb[TCA_NETEM_RATE]); 778 + 779 + if (tb[TCA_NETEM_ECN]) 780 + q->ecn = nla_get_u32(tb[TCA_NETEM_ECN]); 784 781 785 782 q->loss_model = CLG_RANDOM; 786 783 if (tb[TCA_NETEM_LOSS]) ··· 909 900 rate.cell_size = q->cell_size; 910 901 rate.cell_overhead = q->cell_overhead; 911 902 if (nla_put(skb, TCA_NETEM_RATE, sizeof(rate), &rate)) 903 + goto nla_put_failure; 904 + 905 + if (q->ecn && nla_put_u32(skb, TCA_NETEM_ECN, q->ecn)) 912 906 goto nla_put_failure; 913 907 914 908 if (dump_loss_model(q, skb) != 0)