qop_dummy.c revision 1.7 1 1.7 itojun /* $NetBSD: qop_dummy.c,v 1.7 2002/03/05 04:11:53 itojun Exp $ */
2 1.7 itojun /* $KAME: qop_dummy.c,v 1.5 2001/12/03 08:20:55 kjc Exp $ */
3 1.1 thorpej /*
4 1.1 thorpej * Copyright (C) 1999-2000
5 1.1 thorpej * Sony Computer Science Laboratories, Inc. All rights reserved.
6 1.1 thorpej *
7 1.1 thorpej * Redistribution and use in source and binary forms, with or without
8 1.1 thorpej * modification, are permitted provided that the following conditions
9 1.1 thorpej * are met:
10 1.1 thorpej * 1. Redistributions of source code must retain the above copyright
11 1.1 thorpej * notice, this list of conditions and the following disclaimer.
12 1.1 thorpej * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 thorpej * notice, this list of conditions and the following disclaimer in the
14 1.1 thorpej * documentation and/or other materials provided with the distribution.
15 1.1 thorpej *
16 1.1 thorpej * THIS SOFTWARE IS PROVIDED BY SONY CSL AND CONTRIBUTORS ``AS IS'' AND
17 1.1 thorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 1.1 thorpej * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 1.1 thorpej * ARE DISCLAIMED. IN NO EVENT SHALL SONY CSL OR CONTRIBUTORS BE LIABLE
20 1.1 thorpej * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 1.1 thorpej * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 1.1 thorpej * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 1.1 thorpej * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 1.1 thorpej * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 1.1 thorpej * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 1.1 thorpej * SUCH DAMAGE.
27 1.1 thorpej */
28 1.1 thorpej
29 1.1 thorpej #include <sys/param.h>
30 1.1 thorpej #include <sys/socket.h>
31 1.1 thorpej #include <net/if.h>
32 1.1 thorpej #include <stdio.h>
33 1.1 thorpej #include <errno.h>
34 1.1 thorpej #include <syslog.h>
35 1.6 thorpej #include <string.h>
36 1.1 thorpej
37 1.1 thorpej #include <altq/altq.h>
38 1.1 thorpej #include "altq_qop.h"
39 1.1 thorpej
40 1.3 itojun int null_interface_parser(const char *, int, char **);
41 1.3 itojun int null_class_parser(const char *, const char *, const char *, int, char **);
42 1.3 itojun int qcmd_nop_add_if(const char *);
43 1.3 itojun static int nop_attach(struct ifinfo *);
44 1.3 itojun static int nop_detach(struct ifinfo *);
45 1.3 itojun static int nop_clear(struct ifinfo *);
46 1.3 itojun static int nop_enable(struct ifinfo *);
47 1.3 itojun static int nop_disable(struct ifinfo *);
48 1.3 itojun static int nop_add_class(struct classinfo *);
49 1.3 itojun static int nop_modify_class(struct classinfo *, void *);
50 1.3 itojun static int nop_delete_class(struct classinfo *);
51 1.3 itojun static int nop_add_filter(struct fltrinfo *);
52 1.3 itojun static int nop_delete_filter(struct fltrinfo *);
53 1.1 thorpej
54 1.1 thorpej struct qdisc_ops nop_qdisc = {
55 1.1 thorpej ALTQT_NONE,
56 1.1 thorpej "nop",
57 1.1 thorpej nop_attach,
58 1.1 thorpej nop_detach,
59 1.1 thorpej nop_clear,
60 1.1 thorpej nop_enable,
61 1.1 thorpej nop_disable,
62 1.1 thorpej nop_add_class,
63 1.1 thorpej nop_modify_class,
64 1.1 thorpej nop_delete_class,
65 1.1 thorpej nop_add_filter,
66 1.1 thorpej nop_delete_filter,
67 1.1 thorpej };
68 1.1 thorpej
69 1.1 thorpej #define EQUAL(s1, s2) (strcmp((s1), (s2)) == 0)
70 1.1 thorpej
71 1.1 thorpej /*
72 1.1 thorpej * parser interface for null interface
73 1.1 thorpej */
74 1.1 thorpej int
75 1.1 thorpej null_interface_parser(const char *ifname, int argc, char **argv)
76 1.1 thorpej {
77 1.1 thorpej u_int bandwidth = 0;
78 1.1 thorpej u_int tbrsize = 0;
79 1.1 thorpej
80 1.1 thorpej /*
81 1.1 thorpej * process options
82 1.1 thorpej */
83 1.1 thorpej while (argc > 0) {
84 1.1 thorpej if (EQUAL(*argv, "bandwidth")) {
85 1.1 thorpej argc--; argv++;
86 1.1 thorpej if (argc > 0)
87 1.1 thorpej bandwidth = atobps(*argv);
88 1.1 thorpej } else if (EQUAL(*argv, "tbrsize")) {
89 1.1 thorpej argc--; argv++;
90 1.1 thorpej if (argc > 0)
91 1.1 thorpej tbrsize = atobytes(*argv);
92 1.1 thorpej } else {
93 1.7 itojun LOG(LOG_ERR, 0, "Unknown keyword '%s'", *argv);
94 1.1 thorpej return (0);
95 1.1 thorpej }
96 1.1 thorpej argc--; argv++;
97 1.1 thorpej }
98 1.1 thorpej
99 1.1 thorpej if (bandwidth != 0)
100 1.1 thorpej if (qcmd_tbr_register(ifname, bandwidth, tbrsize) != 0)
101 1.1 thorpej return (0);
102 1.1 thorpej
103 1.1 thorpej /*
104 1.1 thorpej * add a dummy interface since traffic conditioner might need it.
105 1.1 thorpej */
106 1.1 thorpej if (qcmd_nop_add_if(ifname) != 0)
107 1.1 thorpej return (0);
108 1.1 thorpej return (1);
109 1.1 thorpej }
110 1.1 thorpej
111 1.1 thorpej int
112 1.1 thorpej null_class_parser(const char *ifname, const char *class_name,
113 1.1 thorpej const char *parent_name, int argc, char **argv)
114 1.1 thorpej {
115 1.1 thorpej LOG(LOG_ERR, 0,
116 1.5 itojun "class cannot be defined without a queueing discipline in %s, line %d",
117 1.1 thorpej altqconfigfile, line_no);
118 1.1 thorpej return (0);
119 1.1 thorpej }
120 1.1 thorpej
121 1.1 thorpej /*
122 1.1 thorpej * qcmd api
123 1.1 thorpej */
124 1.1 thorpej int
125 1.1 thorpej qcmd_nop_add_if(const char *ifname)
126 1.1 thorpej {
127 1.1 thorpej int error;
128 1.1 thorpej
129 1.1 thorpej error = qop_add_if(NULL, ifname, 0, &nop_qdisc, NULL);
130 1.1 thorpej if (error != 0)
131 1.5 itojun LOG(LOG_ERR, errno, "%s: can't add nop on interface '%s'",
132 1.1 thorpej qoperror(error), ifname);
133 1.1 thorpej return (error);
134 1.1 thorpej }
135 1.1 thorpej
136 1.1 thorpej /*
137 1.1 thorpej * qop api
138 1.1 thorpej */
139 1.1 thorpej static int nop_attach(struct ifinfo *ifinfo)
140 1.1 thorpej {
141 1.1 thorpej return (0);
142 1.1 thorpej }
143 1.1 thorpej
144 1.1 thorpej static int nop_detach(struct ifinfo *ifinfo)
145 1.1 thorpej {
146 1.1 thorpej return (0);
147 1.1 thorpej }
148 1.1 thorpej
149 1.1 thorpej static int nop_clear(struct ifinfo *ifinfo)
150 1.1 thorpej {
151 1.1 thorpej return (0);
152 1.1 thorpej }
153 1.1 thorpej
154 1.1 thorpej static int nop_enable(struct ifinfo *ifinfo)
155 1.1 thorpej {
156 1.1 thorpej return (0);
157 1.1 thorpej }
158 1.1 thorpej
159 1.1 thorpej static int nop_disable(struct ifinfo *ifinfo)
160 1.1 thorpej {
161 1.1 thorpej return (0);
162 1.1 thorpej }
163 1.1 thorpej
164 1.1 thorpej static int nop_add_class(struct classinfo *clinfo)
165 1.1 thorpej {
166 1.1 thorpej return (0);
167 1.1 thorpej }
168 1.1 thorpej
169 1.1 thorpej static int nop_modify_class(struct classinfo *clinfo, void *arg)
170 1.1 thorpej {
171 1.1 thorpej return (0);
172 1.1 thorpej }
173 1.1 thorpej
174 1.1 thorpej static int nop_delete_class(struct classinfo *clinfo)
175 1.1 thorpej {
176 1.1 thorpej return (0);
177 1.1 thorpej }
178 1.1 thorpej
179 1.1 thorpej static int nop_add_filter(struct fltrinfo *fltrinfo)
180 1.1 thorpej {
181 1.1 thorpej return (0);
182 1.1 thorpej }
183 1.1 thorpej
184 1.1 thorpej static int nop_delete_filter(struct fltrinfo *fltrinfo)
185 1.1 thorpej {
186 1.1 thorpej return (0);
187 1.1 thorpej }
188