1 /* 2 * q_fifo.c FIFO. 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: Alexey Kuznetsov, <kuznet (at) ms2.inr.ac.ru> 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 26 static void explain(void) 27 { 28 fprintf(stderr, "Usage: ... [p|b]fifo [ limit NUMBER ]\n"); 29 } 30 31 #define usage() return(-1) 32 33 static int fifo_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n) 34 { 35 int ok=0; 36 struct tc_fifo_qopt opt; 37 memset(&opt, 0, sizeof(opt)); 38 39 while (argc > 0) { 40 if (strcmp(*argv, "limit") == 0) { 41 NEXT_ARG(); 42 if (get_size(&opt.limit, *argv)) { 43 fprintf(stderr, "Illegal \"limit\"\n"); 44 return -1; 45 } 46 ok++; 47 } else if (strcmp(*argv, "help") == 0) { 48 explain(); 49 return -1; 50 } else { 51 fprintf(stderr, "What is \"%s\"?\n", *argv); 52 explain(); 53 return -1; 54 } 55 argc--; argv++; 56 } 57 58 if (ok) 59 addattr_l(n, 1024, TCA_OPTIONS, &opt, sizeof(opt)); 60 return 0; 61 } 62 63 static int fifo_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) 64 { 65 struct tc_fifo_qopt *qopt; 66 67 if (opt == NULL) 68 return 0; 69 70 if (RTA_PAYLOAD(opt) < sizeof(*qopt)) 71 return -1; 72 qopt = RTA_DATA(opt); 73 if (strcmp(qu->id, "bfifo") == 0) { 74 SPRINT_BUF(b1); 75 fprintf(f, "limit %s", sprint_size(qopt->limit, b1)); 76 } else 77 fprintf(f, "limit %up", qopt->limit); 78 return 0; 79 } 80 81 82 struct qdisc_util bfifo_qdisc_util = { 83 .id = "bfifo", 84 .parse_qopt = fifo_parse_opt, 85 .print_qopt = fifo_print_opt, 86 }; 87 88 struct qdisc_util pfifo_qdisc_util = { 89 .id = "pfifo", 90 .parse_qopt = fifo_parse_opt, 91 .print_qopt = fifo_print_opt, 92 }; 93 94 extern int prio_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt); 95 struct qdisc_util pfifo_fast_qdisc_util = { 96 .id = "pfifo_fast", 97 .print_qopt = prio_print_opt, 98 }; 99