iproute2/tc/q_skbprio.c
<<
>>
Prefs
   1/*
   2 * q_skbprio.c          SKB PRIORITY QUEUE.
   3 *
   4 *              This program is free software; you can redistribute it and/or
   5 *              modify it under the terms of the GNU General Public License
   6 *              as published by the Free Software Foundation; either version
   7 *              2 of the License, or (at your option) any later version.
   8 *
   9 * Authors:     Nishanth Devarajan, <ndev2021@gmail.com>
  10 *
  11 */
  12
  13#include <stdio.h>
  14#include <stdlib.h>
  15#include <unistd.h>
  16#include <syslog.h>
  17#include <fcntl.h>
  18#include <sys/socket.h>
  19#include <netinet/in.h>
  20#include <arpa/inet.h>
  21#include <string.h>
  22
  23#include "utils.h"
  24#include "tc_util.h"
  25
  26static void explain(void)
  27{
  28        fprintf(stderr, "Usage: ... <skbprio> [ limit NUMBER ]\n");
  29}
  30
  31static int skbprio_parse_opt(struct qdisc_util *qu, int argc, char **argv,
  32                             struct nlmsghdr *n, const char *dev)
  33{
  34        int ok = 0;
  35        struct tc_skbprio_qopt opt = {};
  36
  37        while (argc > 0) {
  38                if (strcmp(*argv, "limit") == 0) {
  39                        NEXT_ARG();
  40                        if (get_size(&opt.limit, *argv)) {
  41                                fprintf(stderr,
  42                                        "%s: Illegal \"limit\" value:\"%s\"\n",
  43                                         qu->id, *argv);
  44                                return -1;
  45                        }
  46                        ok++;
  47                }
  48                else if (strcmp(*argv, "help") == 0) {
  49                        explain();
  50                        return -1;
  51                } else {
  52                        fprintf(stderr,
  53                                "%s: unknown parameter \"%s\"\n",
  54                                qu->id, *argv);
  55                        explain();
  56                        return -1;
  57                }
  58                argc--; argv++;
  59        }
  60
  61        if (ok)
  62                addattr_l(n, 1024, TCA_OPTIONS, &opt, sizeof(opt));
  63        return 0;
  64}
  65
  66static int skbprio_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
  67{
  68        struct tc_skbprio_qopt *qopt;
  69
  70        if (opt == NULL)
  71                return 0;
  72
  73        if (RTA_PAYLOAD(opt)  < sizeof(*qopt))
  74                return -1;
  75        qopt = RTA_DATA(opt);
  76
  77        print_uint(PRINT_ANY, "limit", "limit %u ", qopt->limit);
  78        return 0;
  79}
  80
  81struct qdisc_util skbprio_qdisc_util = {
  82        .id = "skbprio",
  83        .parse_qopt = skbprio_parse_opt,
  84        .print_qopt = skbprio_print_opt,
  85};
  86