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