---- a/include/linux/pkt_sched.h
-+++ b/include/linux/pkt_sched.h
-@@ -850,4 +850,57 @@ struct tc_pie_xstats {
+--- a/include/uapi/linux/pkt_sched.h
++++ b/include/uapi/linux/pkt_sched.h
+@@ -872,4 +872,63 @@ struct tc_pie_xstats {
__u32 maxq; /* maximum queue size */
__u32 ecn_mark; /* packets marked with ecn*/
};
+ TCA_CAKE_AUTORATE,
+ TCA_CAKE_MEMORY,
+ TCA_CAKE_NAT,
++ TCA_CAKE_ETHERNET,
++ TCA_CAKE_WASH,
++ TCA_CAKE_MPU,
++ TCA_CAKE_INGRESS,
++ TCA_CAKE_ACK_FILTER,
+ __TCA_CAKE_MAX
+};
+#define TCA_CAKE_MAX (__TCA_CAKE_MAX - 1)
+
+#define TC_CAKE_MAX_TINS (8)
+struct tc_cake_xstats {
-+ __u16 version; /* == 4, increments when struct extended */
++ __u16 version; /* == 5, increments when struct extended */
+ __u8 max_tins; /* == TC_CAKE_MAX_TINS */
+ __u8 tin_cnt; /* <= TC_CAKE_MAX_TINS */
+
-+ __u32 threshold_rate [TC_CAKE_MAX_TINS];
-+ __u32 target_us [TC_CAKE_MAX_TINS];
-+ struct tc_cake_traffic_stats sent [TC_CAKE_MAX_TINS];
-+ struct tc_cake_traffic_stats dropped [TC_CAKE_MAX_TINS];
++ __u32 threshold_rate[TC_CAKE_MAX_TINS];
++ __u32 target_us[TC_CAKE_MAX_TINS];
++ struct tc_cake_traffic_stats sent[TC_CAKE_MAX_TINS];
++ struct tc_cake_traffic_stats dropped[TC_CAKE_MAX_TINS];
+ struct tc_cake_traffic_stats ecn_marked[TC_CAKE_MAX_TINS];
-+ struct tc_cake_traffic_stats backlog [TC_CAKE_MAX_TINS];
-+ __u32 interval_us [TC_CAKE_MAX_TINS];
++ struct tc_cake_traffic_stats backlog[TC_CAKE_MAX_TINS];
++ __u32 interval_us[TC_CAKE_MAX_TINS];
+ __u32 way_indirect_hits[TC_CAKE_MAX_TINS];
-+ __u32 way_misses [TC_CAKE_MAX_TINS];
-+ __u32 way_collisions [TC_CAKE_MAX_TINS];
-+ __u32 peak_delay_us [TC_CAKE_MAX_TINS]; /* ~= delay to bulk flows */
-+ __u32 avge_delay_us [TC_CAKE_MAX_TINS];
-+ __u32 base_delay_us [TC_CAKE_MAX_TINS]; /* ~= delay to sparse flows */
-+ __u16 sparse_flows [TC_CAKE_MAX_TINS];
-+ __u16 bulk_flows [TC_CAKE_MAX_TINS];
-+ __u16 unresponse_flows [TC_CAKE_MAX_TINS]; /* v4 - was u32 last_len */
-+ __u16 spare [TC_CAKE_MAX_TINS]; /* v4 - split last_len */
-+ __u32 max_skblen [TC_CAKE_MAX_TINS];
++ __u32 way_misses[TC_CAKE_MAX_TINS];
++ __u32 way_collisions[TC_CAKE_MAX_TINS];
++ __u32 peak_delay_us[TC_CAKE_MAX_TINS]; /* ~= bulk flow delay */
++ __u32 avge_delay_us[TC_CAKE_MAX_TINS];
++ __u32 base_delay_us[TC_CAKE_MAX_TINS]; /* ~= sparse flows delay */
++ __u16 sparse_flows[TC_CAKE_MAX_TINS];
++ __u16 bulk_flows[TC_CAKE_MAX_TINS];
++ __u16 unresponse_flows[TC_CAKE_MAX_TINS]; /* v4 - was u32 last_len */
++ __u16 spare[TC_CAKE_MAX_TINS]; /* v4 - split last_len */
++ __u32 max_skblen[TC_CAKE_MAX_TINS];
+ __u32 capacity_estimate; /* version 2 */
+ __u32 memory_limit; /* version 3 */
+ __u32 memory_used; /* version 3 */
++ struct tc_cake_traffic_stats ack_drops[TC_CAKE_MAX_TINS]; /* v5 */
+};
+
#endif
--- a/tc/Makefile
+++ b/tc/Makefile
-@@ -63,6 +63,7 @@ TCMODULES += q_codel.o
+@@ -65,6 +65,7 @@ TCMODULES += q_codel.o
TCMODULES += q_fq_codel.o
TCMODULES += q_fq.o
TCMODULES += q_pie.o
+TCMODULES += q_cake.o
TCMODULES += q_hhf.o
+ TCMODULES += q_clsact.o
TCMODULES += e_bpf.o
-
--- /dev/null
+++ b/tc/q_cake.c
-@@ -0,0 +1,643 @@
+@@ -0,0 +1,692 @@
+/*
+ * Common Applications Kept Enhanced -- CAKE
+ *
+
+static void explain(void)
+{
-+ fprintf(stderr, "Usage: ... cake [ bandwidth RATE | unlimited* | autorate_ingress ]\n"
-+ " [ rtt TIME | datacentre | lan | metro | regional | internet* | oceanic | satellite | interplanetary ]\n"
-+ " [ besteffort | precedence | diffserv8 | diffserv4* ]\n"
-+ " [ flowblind | srchost | dsthost | hosts | flows* | dual-srchost | dual-dsthost | triple-isolate ] [ nat | nonat* ]\n"
-+ " [ ptm | atm | noatm* ] [ overhead N | conservative | raw* ]\n"
-+ " [ memlimit LIMIT ]\n"
-+ " (* marks defaults)\n");
++ fprintf(stderr,
++"Usage: ... cake [ bandwidth RATE | unlimited* | autorate_ingress ]\n"
++" [ rtt TIME | datacentre | lan | metro | regional |\n"
++" internet* | oceanic | satellite | interplanetary ]\n"
++" [ besteffort | diffserv8 | diffserv4 | diffserv-llt |\n"
++" diffserv3* ]\n"
++" [ flowblind | srchost | dsthost | hosts | flows |\n"
++" dual-srchost | dual-dsthost | triple-isolate* ]\n"
++" [ nat | nonat* ]\n"
++" [ wash | nowash * ]\n"
++" [ memlimit LIMIT ]\n"
++" [ ptm | atm | noatm* ] [ overhead N | conservative | raw* ]\n"
++" [ mpu N ]\n"
++" (* marks defaults)\n");
+}
+
+static int cake_parse_opt(struct qdisc_util *qu, int argc, char **argv,
+ unsigned memlimit = 0;
+ int overhead = 0;
+ bool overhead_set = false;
++ bool overhead_override = false;
++ int wash = -1;
++ int mpu = 0;
+ int flowmode = -1;
+ int nat = -1;
+ int atm = -1;
+ diffserv = 4;
+ } else if (strcmp(*argv, "diffserv-llt") == 0) {
+ diffserv = 5;
++ } else if (strcmp(*argv, "diffserv3") == 0) {
++ diffserv = 6;
++
++ } else if (strcmp(*argv, "nowash") == 0) {
++ wash = 0;
++ } else if (strcmp(*argv, "wash") == 0) {
++ wash = 1;
+
+ } else if (strcmp(*argv, "flowblind") == 0) {
+ flowmode = 0;
+ atm = 0;
+ overhead = 0;
+ overhead_set = true;
++ overhead_override = true;
+ } else if (strcmp(*argv, "conservative") == 0) {
+ /*
+ * Deliberately over-estimate overhead:
+ overhead = 48;
+ overhead_set = true;
+
-+ /*
-+ * DOCSIS overhead figures courtesy of Greg White @ CableLabs.
-+ * The "-ip" versions include the Ethernet frame header, in case
-+ * you are shaping an IP interface instead of an Ethernet one.
-+ */
-+ } else if (strcmp(*argv, "docsis-downstream-ip") == 0) {
-+ atm = 0;
-+ overhead += 35;
-+ overhead_set = true;
-+ } else if (strcmp(*argv, "docsis-downstream") == 0) {
-+ atm = 0;
-+ overhead += 35 - 14;
-+ overhead_set = true;
-+ } else if (strcmp(*argv, "docsis-upstream-ip") == 0) {
-+ atm = 0;
-+ overhead += 28;
-+ overhead_set = true;
-+ } else if (strcmp(*argv, "docsis-upstream") == 0) {
-+ atm = 0;
-+ overhead += 28 - 14;
-+ overhead_set = true;
-+
+ /* Various ADSL framing schemes, all over ATM cells */
+ } else if (strcmp(*argv, "ipoa-vcmux") == 0) {
+ atm = 1;
+
+ } else if (strcmp(*argv, "via-ethernet") == 0) {
+ /*
-+ * The above overheads are relative to an IP packet,
-+ * but Linux includes Ethernet framing overhead already
-+ * if we are shaping an Ethernet interface rather than
-+ * an IP interface.
++ * We used to use this flag to manually compensate for
++ * Linux including the Ethernet header on Ethernet-type
++ * interfaces, but not on IP-type interfaces.
++ *
++ * It is no longer needed, because Cake now adjusts for
++ * that automatically, and is thus ignored.
++ *
++ * It would be deleted entirely, but it appears in the
++ * stats output when the automatic compensation is active.
+ */
-+ overhead -= 14;
-+ overhead_set = true;
+
-+ /* Additional Ethernet-related overheads used by some ISPs */
-+ } else if (strcmp(*argv, "ether-phy") == 0) {
-+ /* ethernet pre-amble & interframe gap 20 bytes
-+ * Linux will have already accounted for MACs & frame type 14 bytes
-+ * you probably want to add an FCS as well*/
-+ overhead += 20;
-+ overhead_set = true;
-+ } else if (strcmp(*argv, "ether-all") == 0) {
++ } else if (strcmp(*argv, "ethernet") == 0) {
+ /* ethernet pre-amble & interframe gap & FCS
-+ * Linux will have already accounted for MACs & frame type 14 bytes
-+ * you may need to add vlan tag*/
-+ overhead += 24;
++ * you may need to add vlan tag */
++ overhead += 38;
+ overhead_set = true;
++ mpu = 84;
+
-+ } else if (strcmp(*argv, "ether-fcs") == 0) {
-+ /* Frame Check Sequence */
-+ /* we ignore the minimum frame size, because IP packets usually meet it */
-+ overhead += 4;
-+ overhead_set = true;
++ /* Additional Ethernet-related overhead used by some ISPs */
+ } else if (strcmp(*argv, "ether-vlan") == 0) {
+ /* 802.1q VLAN tag - may be repeated */
+ overhead += 4;
+ overhead_set = true;
+
++ /*
++ * DOCSIS cable shapers account for Ethernet frame with FCS,
++ * but not interframe gap nor preamble.
++ */
++ } else if (strcmp(*argv, "docsis") == 0) {
++ atm = 0;
++ overhead += 18;
++ overhead_set = true;
++ mpu = 64;
++
+ } else if (strcmp(*argv, "overhead") == 0) {
+ char* p = NULL;
+ NEXT_ARG();
+ }
+ overhead_set = true;
+
++ } else if (strcmp(*argv, "mpu") == 0) {
++ char* p = NULL;
++ NEXT_ARG();
++ mpu = strtol(*argv, &p, 10);
++ if(!p || *p || !*argv || mpu < 0 || mpu > 256) {
++ fprintf(stderr, "Illegal \"mpu\", valid range is 0 to 256\\n");
++ return -1;
++ }
++
+ } else if (strcmp(*argv, "memlimit") == 0) {
+ NEXT_ARG();
+ if(get_size(&memlimit, *argv)) {
+ addattr_l(n, 1024, TCA_CAKE_FLOW_MODE, &flowmode, sizeof(flowmode));
+ if (overhead_set)
+ addattr_l(n, 1024, TCA_CAKE_OVERHEAD, &overhead, sizeof(overhead));
++ if (overhead_override) {
++ unsigned zero = 0;
++ addattr_l(n, 1024, TCA_CAKE_ETHERNET, &zero, sizeof(zero));
++ }
++ if (mpu > 0)
++ addattr_l(n, 1024, TCA_CAKE_MPU, &mpu, sizeof(mpu));
+ if (interval)
+ addattr_l(n, 1024, TCA_CAKE_RTT, &interval, sizeof(interval));
+ if (target)
+ addattr_l(n, 1024, TCA_CAKE_MEMORY, &memlimit, sizeof(memlimit));
+ if (nat != -1)
+ addattr_l(n, 1024, TCA_CAKE_NAT, &nat, sizeof(nat));
++ if (wash != -1)
++ addattr_l(n, 1024, TCA_CAKE_WASH, &wash, sizeof(wash));
+
+ tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
+ return 0;
+ unsigned interval = 0;
+ unsigned memlimit = 0;
+ int overhead = 0;
++ int ethernet = 0;
++ int mpu = 0;
+ int atm = 0;
+ int nat = 0;
+ int autorate = 0;
++ int wash = 0;
+ SPRINT_BUF(b1);
+ SPRINT_BUF(b2);
+
+ case 5:
+ fprintf(f, "diffserv-llt ");
+ break;
++ case 6:
++ fprintf(f, "diffserv3 ");
++ break;
+ default:
+ fprintf(f, "(?diffserv?) ");
+ break;
+ if(nat)
+ fprintf(f, "nat ");
+ }
++ if (tb[TCA_CAKE_WASH] &&
++ RTA_PAYLOAD(tb[TCA_CAKE_WASH]) >= sizeof(__u32)) {
++ wash = rta_getattr_u32(tb[TCA_CAKE_WASH]);
++ }
+ if (tb[TCA_CAKE_ATM] &&
+ RTA_PAYLOAD(tb[TCA_CAKE_ATM]) >= sizeof(__u32)) {
+ atm = rta_getattr_u32(tb[TCA_CAKE_ATM]);
+ RTA_PAYLOAD(tb[TCA_CAKE_OVERHEAD]) >= sizeof(__u32)) {
+ overhead = rta_getattr_u32(tb[TCA_CAKE_OVERHEAD]);
+ }
++ if (tb[TCA_CAKE_MPU] &&
++ RTA_PAYLOAD(tb[TCA_CAKE_MPU]) >= sizeof(__u32)) {
++ mpu = rta_getattr_u32(tb[TCA_CAKE_MPU]);
++ }
++ if (tb[TCA_CAKE_ETHERNET] &&
++ RTA_PAYLOAD(tb[TCA_CAKE_ETHERNET]) >= sizeof(__u32)) {
++ ethernet = rta_getattr_u32(tb[TCA_CAKE_ETHERNET]);
++ }
+ if (tb[TCA_CAKE_RTT] &&
+ RTA_PAYLOAD(tb[TCA_CAKE_RTT]) >= sizeof(__u32)) {
+ interval = rta_getattr_u32(tb[TCA_CAKE_RTT]);
+ }
+
++ if (wash)
++ fprintf(f,"wash ");
++
+ if (interval)
+ fprintf(f, "rtt %s ", sprint_time(interval, b2));
+
-+ if (atm == 1)
-+ fprintf(f, "atm ");
-+ else if (atm == 2)
-+ fprintf(f, "ptm ");
-+ else if (overhead)
-+ fprintf(f, "noatm ");
++ if (!atm && overhead == ethernet) {
++ fprintf(f, "raw ");
++ } else {
++ if (atm == 1)
++ fprintf(f, "atm ");
++ else if (atm == 2)
++ fprintf(f, "ptm ");
++ else
++ fprintf(f, "noatm ");
+
-+ if (overhead || atm)
+ fprintf(f, "overhead %d ", overhead);
+
-+ if (!atm && !overhead)
-+ fprintf(f, "raw ");
++ // This is actually the *amount* of automatic compensation, but we only report
++ // its presence as a boolean for now.
++ if (ethernet)
++ fprintf(f, "via-ethernet ");
++ }
++
++ if (mpu) {
++ fprintf(f, "mpu %d ", mpu);
++ }
+
+ if (memlimit)
+ fprintf(f, "memlimit %s", sprint_size(memlimit, b1));
+ fprintf(f, " capacity estimate: %s\n", sprint_rate(stnc->capacity_estimate, b1));
+
+ switch(stnc->tin_cnt) {
++ case 3:
++ fprintf(f, " Bulk Best Effort Voice\n");
++ break;
++
+ case 4:
+ fprintf(f, " Bulk Best Effort Video Voice\n");
+ break;