1/*
2 * q_sfq.c		SFQ.
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@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
26static void explain(void)
27{
28	fprintf(stderr, "Usage: ... sfq [ perturb SECS ] [ quantum BYTES ]\n");
29}
30
31#define usage() return(-1)
32
33static int sfq_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
34{
35	int ok=0;
36	struct tc_sfq_qopt opt;
37
38	memset(&opt, 0, sizeof(opt));
39
40	while (argc > 0) {
41		if (strcmp(*argv, "quantum") == 0) {
42			NEXT_ARG();
43			if (get_size(&opt.quantum, *argv)) {
44				fprintf(stderr, "Illegal \"limit\"\n");
45				return -1;
46			}
47			ok++;
48		} else if (strcmp(*argv, "perturb") == 0) {
49			NEXT_ARG();
50			if (get_integer(&opt.perturb_period, *argv, 0)) {
51				fprintf(stderr, "Illegal \"perturb\"\n");
52				return -1;
53			}
54			ok++;
55		} else if (strcmp(*argv, "help") == 0) {
56			explain();
57			return -1;
58		} else {
59			fprintf(stderr, "What is \"%s\"?\n", *argv);
60			explain();
61			return -1;
62		}
63		argc--; argv++;
64	}
65
66	if (ok)
67		addattr_l(n, 1024, TCA_OPTIONS, &opt, sizeof(opt));
68	return 0;
69}
70
71static int sfq_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
72{
73	struct tc_sfq_qopt *qopt;
74	SPRINT_BUF(b1);
75
76	if (opt == NULL)
77		return 0;
78
79	if (RTA_PAYLOAD(opt)  < sizeof(*qopt))
80		return -1;
81	qopt = RTA_DATA(opt);
82	fprintf(f, "quantum %s ", sprint_size(qopt->quantum, b1));
83	if (show_details) {
84		fprintf(f, "limit %up flows %u/%u ",
85			qopt->limit, qopt->flows, qopt->divisor);
86	}
87	if (qopt->perturb_period)
88		fprintf(f, "perturb %dsec ", qopt->perturb_period);
89	return 0;
90}
91
92static int sfq_print_xstats(struct qdisc_util *qu, FILE *f, struct rtattr *xstats)
93{
94	return 0;
95}
96
97
98struct qdisc_util sfq_util = {
99	NULL,
100	"sfq",
101	sfq_parse_opt,
102	sfq_print_opt,
103	sfq_print_xstats,
104};
105