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