qdisc_conf.c revision 1.1 1 /* $KAME: qdisc_conf.c,v 1.3 2000/10/18 09:15:16 kjc Exp $ */
2 /*
3 * Copyright (C) 1999-2000
4 * Sony Computer Science Laboratories, Inc. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY SONY CSL AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL SONY CSL OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 */
27
28 #include <sys/param.h>
29 #include <sys/socket.h>
30 #if defined(__NetBSD__) || defined(__OpenBSD__)
31 #include <sys/ioctl.h>
32 #endif
33 #include <sys/fcntl.h>
34 #include <net/if.h>
35 #include <netinet/in.h>
36 #include <altq/altq.h>
37
38 #include <stdio.h>
39 #include <stdlib.h>
40 #include <unistd.h>
41 #include <string.h>
42 #include <err.h>
43
44 #include "altqstat.h"
45
46 #define ALTQ_DEVICE "/dev/altq/altq"
47
48 struct qdisc_conf qdisc_table[] = {
49 {"cbq", ALTQT_CBQ, cbq_stat_loop},
50 {"hfsc", ALTQT_HFSC, hfsc_stat_loop},
51 {"cdnr", ALTQT_CDNR, cdnr_stat_loop},
52 {"wfq", ALTQT_WFQ, wfq_stat_loop},
53 {"fifoq", ALTQT_FIFOQ, fifoq_stat_loop},
54 {"red", ALTQT_RED, red_stat_loop},
55 {"rio", ALTQT_RIO, rio_stat_loop},
56 {"blue", ALTQT_BLUE, blue_stat_loop},
57 {"priq", ALTQT_PRIQ, priq_stat_loop},
58 {NULL, 0, NULL}
59 };
60
61 stat_loop_t *
62 qdisc2stat_loop(const char *qdisc_name)
63 {
64 struct qdisc_conf *stat;
65
66 for (stat = qdisc_table; stat->qdisc_name != NULL; stat++)
67 if (strcmp(stat->qdisc_name, qdisc_name) == 0)
68 return (stat->stat_loop);
69 return (NULL);
70 }
71
72 int
73 ifname2qdisc(const char *ifname, char *qname)
74 {
75 struct altqreq qtypereq;
76 int fd, qtype = 0;
77
78 if (ifname[0] == '_') {
79 /* input interface */
80 if (qname != NULL)
81 strcpy(qname, "cdnr");
82 return (ALTQT_CDNR);
83 }
84
85 strcpy(qtypereq.ifname, ifname);
86 if ((fd = open(ALTQ_DEVICE, O_RDONLY)) < 0) {
87 warn("can't open %s", ALTQ_DEVICE);
88 return (0);
89 }
90 if (ioctl(fd, ALTQGTYPE, &qtypereq) < 0) {
91 warn("ALTQGQTYPE");
92 return (0);
93 }
94 close(fd);
95
96 if (qname != NULL) {
97 struct qdisc_conf *stat;
98
99 qtype = qtypereq.arg;
100 for (stat = qdisc_table; stat->qdisc_name != NULL; stat++)
101 if (stat->altqtype == qtype)
102 strcpy(qname, stat->qdisc_name);
103 }
104
105 return (qtype);
106 }
107
108