qop_dummy.c revision 1.3 1 /* $KAME: qop_dummy.c,v 1.2 2000/10/18 09:15:19 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 #include <net/if.h>
31 #include <stdio.h>
32 #include <errno.h>
33 #include <syslog.h>
34
35 #include <altq/altq.h>
36 #include "altq_qop.h"
37
38 int null_interface_parser(const char *, int, char **);
39 int null_class_parser(const char *, const char *, const char *, int, char **);
40 int qcmd_nop_add_if(const char *);
41 static int nop_attach(struct ifinfo *);
42 static int nop_detach(struct ifinfo *);
43 static int nop_clear(struct ifinfo *);
44 static int nop_enable(struct ifinfo *);
45 static int nop_disable(struct ifinfo *);
46 static int nop_add_class(struct classinfo *);
47 static int nop_modify_class(struct classinfo *, void *);
48 static int nop_delete_class(struct classinfo *);
49 static int nop_add_filter(struct fltrinfo *);
50 static int nop_delete_filter(struct fltrinfo *);
51
52 struct qdisc_ops nop_qdisc = {
53 ALTQT_NONE,
54 "nop",
55 nop_attach,
56 nop_detach,
57 nop_clear,
58 nop_enable,
59 nop_disable,
60 nop_add_class,
61 nop_modify_class,
62 nop_delete_class,
63 nop_add_filter,
64 nop_delete_filter,
65 };
66
67 #define EQUAL(s1, s2) (strcmp((s1), (s2)) == 0)
68
69 /*
70 * parser interface for null interface
71 */
72 int
73 null_interface_parser(const char *ifname, int argc, char **argv)
74 {
75 u_int bandwidth = 0;
76 u_int tbrsize = 0;
77
78 /*
79 * process options
80 */
81 while (argc > 0) {
82 if (EQUAL(*argv, "bandwidth")) {
83 argc--; argv++;
84 if (argc > 0)
85 bandwidth = atobps(*argv);
86 } else if (EQUAL(*argv, "tbrsize")) {
87 argc--; argv++;
88 if (argc > 0)
89 tbrsize = atobytes(*argv);
90 } else {
91 LOG(LOG_ERR, 0, "Unknown keyword '%s'\n", argv);
92 return (0);
93 }
94 argc--; argv++;
95 }
96
97 if (bandwidth != 0)
98 if (qcmd_tbr_register(ifname, bandwidth, tbrsize) != 0)
99 return (0);
100
101 /*
102 * add a dummy interface since traffic conditioner might need it.
103 */
104 if (qcmd_nop_add_if(ifname) != 0)
105 return (0);
106 return (1);
107 }
108
109 int
110 null_class_parser(const char *ifname, const char *class_name,
111 const char *parent_name, int argc, char **argv)
112 {
113 LOG(LOG_ERR, 0,
114 "class cannot be defined without a queueing discipline in %s, line %d\n",
115 altqconfigfile, line_no);
116 return (0);
117 }
118
119 /*
120 * qcmd api
121 */
122 int
123 qcmd_nop_add_if(const char *ifname)
124 {
125 int error;
126
127 error = qop_add_if(NULL, ifname, 0, &nop_qdisc, NULL);
128 if (error != 0)
129 LOG(LOG_ERR, errno, "%s: can't add nop on interface '%s'\n",
130 qoperror(error), ifname);
131 return (error);
132 }
133
134 /*
135 * qop api
136 */
137 static int nop_attach(struct ifinfo *ifinfo)
138 {
139 return (0);
140 }
141
142 static int nop_detach(struct ifinfo *ifinfo)
143 {
144 return (0);
145 }
146
147 static int nop_clear(struct ifinfo *ifinfo)
148 {
149 return (0);
150 }
151
152 static int nop_enable(struct ifinfo *ifinfo)
153 {
154 return (0);
155 }
156
157 static int nop_disable(struct ifinfo *ifinfo)
158 {
159 return (0);
160 }
161
162 static int nop_add_class(struct classinfo *clinfo)
163 {
164 return (0);
165 }
166
167 static int nop_modify_class(struct classinfo *clinfo, void *arg)
168 {
169 return (0);
170 }
171
172 static int nop_delete_class(struct classinfo *clinfo)
173 {
174 return (0);
175 }
176
177 static int nop_add_filter(struct fltrinfo *fltrinfo)
178 {
179 return (0);
180 }
181
182 static int nop_delete_filter(struct fltrinfo *fltrinfo)
183 {
184 return (0);
185 }
186