1c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet/* 2c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet * Fair Queue Codel 3c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet * 4df1c7d9138eafd5b96e81040b0c1475b6d73d158Eric Dumazet * Copyright (C) 2012,2015 Eric Dumazet <edumazet@google.com> 5c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet * 6c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet * Redistribution and use in source and binary forms, with or without 7c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet * modification, are permitted provided that the following conditions 8c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet * are met: 9c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet * 1. Redistributions of source code must retain the above copyright 10c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet * notice, this list of conditions, and the following disclaimer, 11c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet * without modification. 12c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet * 2. Redistributions in binary form must reproduce the above copyright 13c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet * notice, this list of conditions and the following disclaimer in the 14c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet * documentation and/or other materials provided with the distribution. 15c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet * 3. The names of the authors may not be used to endorse or promote products 16c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet * derived from this software without specific prior written permission. 17c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet * 18c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet * Alternatively, provided that this notice is retained in full, this 19c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet * software may be distributed under the terms of the GNU General 20c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet * Public License ("GPL") version 2, in which case the provisions of the 21c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet * GPL apply INSTEAD OF those given above. 22c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet * 23c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 27c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 29c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 30c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 31c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 34c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet * DAMAGE. 35c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet * 36c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet */ 37c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet 38c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet#include <stdio.h> 39c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet#include <stdlib.h> 40c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet#include <unistd.h> 41c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet#include <syslog.h> 42c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet#include <fcntl.h> 43c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet#include <sys/socket.h> 44c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet#include <netinet/in.h> 45c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet#include <arpa/inet.h> 46c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet#include <string.h> 47c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet 48c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet#include "utils.h" 49c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet#include "tc_util.h" 50c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet 51c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazetstatic void explain(void) 52c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet{ 53c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet fprintf(stderr, "Usage: ... fq_codel [ limit PACKETS ] [ flows NUMBER ]\n"); 54c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet fprintf(stderr, " [ target TIME] [ interval TIME ]\n"); 55c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet fprintf(stderr, " [ quantum BYTES ] [ [no]ecn ]\n"); 56df1c7d9138eafd5b96e81040b0c1475b6d73d158Eric Dumazet fprintf(stderr, " [ ce_threshold TIME ]\n"); 57c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet} 58c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet 59c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazetstatic int fq_codel_parse_opt(struct qdisc_util *qu, int argc, char **argv, 60c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet struct nlmsghdr *n) 61c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet{ 62c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet unsigned limit = 0; 63c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet unsigned flows = 0; 64c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet unsigned target = 0; 65c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet unsigned interval = 0; 66c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet unsigned quantum = 0; 67df1c7d9138eafd5b96e81040b0c1475b6d73d158Eric Dumazet unsigned ce_threshold = ~0U; 68c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet int ecn = -1; 69c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet struct rtattr *tail; 70c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet 71c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet while (argc > 0) { 72c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet if (strcmp(*argv, "limit") == 0) { 73c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet NEXT_ARG(); 74c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet if (get_unsigned(&limit, *argv, 0)) { 75c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet fprintf(stderr, "Illegal \"limit\"\n"); 76c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet return -1; 77c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet } 78c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet } else if (strcmp(*argv, "flows") == 0) { 79c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet NEXT_ARG(); 80c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet if (get_unsigned(&flows, *argv, 0)) { 81c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet fprintf(stderr, "Illegal \"flows\"\n"); 82c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet return -1; 83c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet } 84c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet } else if (strcmp(*argv, "quantum") == 0) { 85c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet NEXT_ARG(); 86c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet if (get_unsigned(&quantum, *argv, 0)) { 87c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet fprintf(stderr, "Illegal \"quantum\"\n"); 88c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet return -1; 89c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet } 90c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet } else if (strcmp(*argv, "target") == 0) { 91c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet NEXT_ARG(); 92c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet if (get_time(&target, *argv)) { 93c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet fprintf(stderr, "Illegal \"target\"\n"); 94c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet return -1; 95c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet } 96df1c7d9138eafd5b96e81040b0c1475b6d73d158Eric Dumazet } else if (strcmp(*argv, "ce_threshold") == 0) { 97df1c7d9138eafd5b96e81040b0c1475b6d73d158Eric Dumazet NEXT_ARG(); 98df1c7d9138eafd5b96e81040b0c1475b6d73d158Eric Dumazet if (get_time(&ce_threshold, *argv)) { 99df1c7d9138eafd5b96e81040b0c1475b6d73d158Eric Dumazet fprintf(stderr, "Illegal \"ce_threshold\"\n"); 100df1c7d9138eafd5b96e81040b0c1475b6d73d158Eric Dumazet return -1; 101df1c7d9138eafd5b96e81040b0c1475b6d73d158Eric Dumazet } 102c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet } else if (strcmp(*argv, "interval") == 0) { 103c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet NEXT_ARG(); 104c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet if (get_time(&interval, *argv)) { 105c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet fprintf(stderr, "Illegal \"interval\"\n"); 106c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet return -1; 107c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet } 108c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet } else if (strcmp(*argv, "ecn") == 0) { 109c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet ecn = 1; 110c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet } else if (strcmp(*argv, "noecn") == 0) { 111c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet ecn = 0; 112c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet } else if (strcmp(*argv, "help") == 0) { 113c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet explain(); 114c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet return -1; 115c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet } else { 116c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet fprintf(stderr, "What is \"%s\"?\n", *argv); 117c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet explain(); 118c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet return -1; 119c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet } 120c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet argc--; argv++; 121c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet } 122c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet 123c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet tail = NLMSG_TAIL(n); 124c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet addattr_l(n, 1024, TCA_OPTIONS, NULL, 0); 125c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet if (limit) 126c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet addattr_l(n, 1024, TCA_FQ_CODEL_LIMIT, &limit, sizeof(limit)); 127c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet if (flows) 128c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet addattr_l(n, 1024, TCA_FQ_CODEL_FLOWS, &flows, sizeof(flows)); 129c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet if (quantum) 130c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet addattr_l(n, 1024, TCA_FQ_CODEL_QUANTUM, &quantum, sizeof(quantum)); 131c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet if (interval) 132c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet addattr_l(n, 1024, TCA_FQ_CODEL_INTERVAL, &interval, sizeof(interval)); 133c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet if (target) 134c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet addattr_l(n, 1024, TCA_FQ_CODEL_TARGET, &target, sizeof(target)); 135c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet if (ecn != -1) 136c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet addattr_l(n, 1024, TCA_FQ_CODEL_ECN, &ecn, sizeof(ecn)); 137df1c7d9138eafd5b96e81040b0c1475b6d73d158Eric Dumazet if (ce_threshold != ~0U) 138df1c7d9138eafd5b96e81040b0c1475b6d73d158Eric Dumazet addattr_l(n, 1024, TCA_FQ_CODEL_CE_THRESHOLD, 139df1c7d9138eafd5b96e81040b0c1475b6d73d158Eric Dumazet &ce_threshold, sizeof(ce_threshold)); 140c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail; 141c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet return 0; 142c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet} 143c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet 144c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazetstatic int fq_codel_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) 145c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet{ 146c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet struct rtattr *tb[TCA_FQ_CODEL_MAX + 1]; 147c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet unsigned limit; 148c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet unsigned flows; 149c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet unsigned interval; 150c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet unsigned target; 151c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet unsigned ecn; 152c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet unsigned quantum; 153df1c7d9138eafd5b96e81040b0c1475b6d73d158Eric Dumazet unsigned ce_threshold; 154c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet SPRINT_BUF(b1); 155c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet 156c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet if (opt == NULL) 157c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet return 0; 158c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet 159c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet parse_rtattr_nested(tb, TCA_FQ_CODEL_MAX, opt); 160c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet 161c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet if (tb[TCA_FQ_CODEL_LIMIT] && 162c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet RTA_PAYLOAD(tb[TCA_FQ_CODEL_LIMIT]) >= sizeof(__u32)) { 163c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet limit = rta_getattr_u32(tb[TCA_FQ_CODEL_LIMIT]); 164c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet fprintf(f, "limit %up ", limit); 165c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet } 166c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet if (tb[TCA_FQ_CODEL_FLOWS] && 167c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet RTA_PAYLOAD(tb[TCA_FQ_CODEL_FLOWS]) >= sizeof(__u32)) { 168c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet flows = rta_getattr_u32(tb[TCA_FQ_CODEL_FLOWS]); 169c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet fprintf(f, "flows %u ", flows); 170c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet } 171c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet if (tb[TCA_FQ_CODEL_QUANTUM] && 172c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet RTA_PAYLOAD(tb[TCA_FQ_CODEL_QUANTUM]) >= sizeof(__u32)) { 173c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet quantum = rta_getattr_u32(tb[TCA_FQ_CODEL_QUANTUM]); 174c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet fprintf(f, "quantum %u ", quantum); 175c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet } 176c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet if (tb[TCA_FQ_CODEL_TARGET] && 177c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet RTA_PAYLOAD(tb[TCA_FQ_CODEL_TARGET]) >= sizeof(__u32)) { 178c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet target = rta_getattr_u32(tb[TCA_FQ_CODEL_TARGET]); 179c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet fprintf(f, "target %s ", sprint_time(target, b1)); 180c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet } 181df1c7d9138eafd5b96e81040b0c1475b6d73d158Eric Dumazet if (tb[TCA_FQ_CODEL_CE_THRESHOLD] && 182df1c7d9138eafd5b96e81040b0c1475b6d73d158Eric Dumazet RTA_PAYLOAD(tb[TCA_FQ_CODEL_CE_THRESHOLD]) >= sizeof(__u32)) { 183df1c7d9138eafd5b96e81040b0c1475b6d73d158Eric Dumazet ce_threshold = rta_getattr_u32(tb[TCA_FQ_CODEL_CE_THRESHOLD]); 184df1c7d9138eafd5b96e81040b0c1475b6d73d158Eric Dumazet fprintf(f, "ce_threshold %s ", sprint_time(ce_threshold, b1)); 185df1c7d9138eafd5b96e81040b0c1475b6d73d158Eric Dumazet } 186c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet if (tb[TCA_FQ_CODEL_INTERVAL] && 187c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet RTA_PAYLOAD(tb[TCA_FQ_CODEL_INTERVAL]) >= sizeof(__u32)) { 188c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet interval = rta_getattr_u32(tb[TCA_FQ_CODEL_INTERVAL]); 189c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet fprintf(f, "interval %s ", sprint_time(interval, b1)); 190c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet } 191c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet if (tb[TCA_FQ_CODEL_ECN] && 192c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet RTA_PAYLOAD(tb[TCA_FQ_CODEL_ECN]) >= sizeof(__u32)) { 193c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet ecn = rta_getattr_u32(tb[TCA_FQ_CODEL_ECN]); 194c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet if (ecn) 195c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet fprintf(f, "ecn "); 196c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet } 197c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet 198c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet return 0; 199c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet} 200c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet 201c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazetstatic int fq_codel_print_xstats(struct qdisc_util *qu, FILE *f, 202c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet struct rtattr *xstats) 203c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet{ 204df1c7d9138eafd5b96e81040b0c1475b6d73d158Eric Dumazet struct tc_fq_codel_xstats _st, *st; 205c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet SPRINT_BUF(b1); 206c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet 207c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet if (xstats == NULL) 208c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet return 0; 209c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet 210c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet st = RTA_DATA(xstats); 211df1c7d9138eafd5b96e81040b0c1475b6d73d158Eric Dumazet if (RTA_PAYLOAD(xstats) < sizeof(*st)) { 212df1c7d9138eafd5b96e81040b0c1475b6d73d158Eric Dumazet memset(&_st, 0, sizeof(_st)); 213df1c7d9138eafd5b96e81040b0c1475b6d73d158Eric Dumazet memcpy(&_st, st, RTA_PAYLOAD(xstats)); 214df1c7d9138eafd5b96e81040b0c1475b6d73d158Eric Dumazet st = &_st; 215df1c7d9138eafd5b96e81040b0c1475b6d73d158Eric Dumazet } 216c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet if (st->type == TCA_FQ_CODEL_XSTATS_QDISC) { 217c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet fprintf(f, " maxpacket %u drop_overlimit %u new_flow_count %u ecn_mark %u", 218c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet st->qdisc_stats.maxpacket, 219c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet st->qdisc_stats.drop_overlimit, 220c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet st->qdisc_stats.new_flow_count, 221c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet st->qdisc_stats.ecn_mark); 222df1c7d9138eafd5b96e81040b0c1475b6d73d158Eric Dumazet if (st->qdisc_stats.ce_mark) 223df1c7d9138eafd5b96e81040b0c1475b6d73d158Eric Dumazet fprintf(f, " ce_mark %u", st->qdisc_stats.ce_mark); 224c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet fprintf(f, "\n new_flows_len %u old_flows_len %u", 225c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet st->qdisc_stats.new_flows_len, 226c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet st->qdisc_stats.old_flows_len); 227c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet } 228c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet if (st->type == TCA_FQ_CODEL_XSTATS_CLASS) { 229c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet fprintf(f, " deficit %d count %u lastcount %u ldelay %s", 230c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet st->class_stats.deficit, 231c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet st->class_stats.count, 232c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet st->class_stats.lastcount, 233c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet sprint_time(st->class_stats.ldelay, b1)); 234c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet if (st->class_stats.dropping) { 235c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet fprintf(f, " dropping"); 236c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet if (st->class_stats.drop_next < 0) 237c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet fprintf(f, " drop_next -%s", 238c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet sprint_time(-st->class_stats.drop_next, b1)); 239c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet else 240c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet fprintf(f, " drop_next %s", 241c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet sprint_time(st->class_stats.drop_next, b1)); 242c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet } 243c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet } 244c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet return 0; 245c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet 246c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet} 247c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet 248c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazetstruct qdisc_util fq_codel_qdisc_util = { 249c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet .id = "fq_codel", 250c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet .parse_qopt = fq_codel_parse_opt, 251c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet .print_qopt = fq_codel_print_opt, 252c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet .print_xstats = fq_codel_print_xstats, 253c3524efc14e3112329a18bc699dd99437fae9a5cEric Dumazet}; 254