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