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