1 /* $NetBSD: qdisc_conf.c,v 1.4 2006/10/12 19:59:13 peter Exp $ */
2 /* $KAME: qdisc_conf.c,v 1.5 2002/10/26 06:59:54 kjc Exp $ */
4 * Copyright (C) 1999-2000
5 * Sony Computer Science Laboratories, Inc. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY SONY CSL AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL SONY CSL OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include <sys/param.h>
30 #include <sys/socket.h>
31 #if defined(__NetBSD__) || defined(__OpenBSD__)
32 #include <sys/ioctl.h>
34 #include <sys/fcntl.h>
36 #include <netinet/in.h>
37 #include <altq/altq.h>
47 #define ALTQ_DEVICE "/dev/altq/altq"
49 struct qdisc_conf qdisc_table
[] = {
50 {"cbq", ALTQT_CBQ
, cbq_stat_loop
},
51 {"hfsc", ALTQT_HFSC
, hfsc_stat_loop
},
52 {"cdnr", ALTQT_CDNR
, cdnr_stat_loop
},
53 {"wfq", ALTQT_WFQ
, wfq_stat_loop
},
54 {"fifoq", ALTQT_FIFOQ
, fifoq_stat_loop
},
55 {"red", ALTQT_RED
, red_stat_loop
},
56 {"rio", ALTQT_RIO
, rio_stat_loop
},
57 {"blue", ALTQT_BLUE
, blue_stat_loop
},
58 {"priq", ALTQT_PRIQ
, priq_stat_loop
},
59 {"jobs", ALTQT_JOBS
, jobs_stat_loop
},
64 qdisc2stat_loop(const char *qdisc_name
)
66 struct qdisc_conf
*st
;
68 for (st
= qdisc_table
; st
->qdisc_name
!= NULL
; st
++)
69 if (strcmp(st
->qdisc_name
, qdisc_name
) == 0)
70 return (st
->stat_loop
);
75 ifname2qdisc(const char *ifname
, char *qname
)
77 struct altqreq qtypereq
;
80 if (ifname
[0] == '_') {
83 strlcpy(qname
, "cdnr", 64);
87 strlcpy(qtypereq
.ifname
, ifname
, sizeof(qtypereq
.ifname
));
88 if ((fd
= open(ALTQ_DEVICE
, O_RDONLY
)) < 0) {
89 warn("can't open %s", ALTQ_DEVICE
);
92 if (ioctl(fd
, ALTQGTYPE
, &qtypereq
) < 0) {
99 struct qdisc_conf
*st
;
101 qtype
= qtypereq
.arg
;
102 for (st
= qdisc_table
; st
->qdisc_name
!= NULL
; st
++)
103 if (st
->altqtype
== qtype
)
104 strlcpy(qname
, st
->qdisc_name
, 64);