xref: /netbsd-src/usr.sbin/altq/libaltq/qop_dummy.c (revision 69881cf6b8dc615ac34107b2f982835e042159e3)
1*69881cf6Sitojun /*	$NetBSD: qop_dummy.c,v 1.7 2002/03/05 04:11:53 itojun Exp $	*/
2*69881cf6Sitojun /*	$KAME: qop_dummy.c,v 1.5 2001/12/03 08:20:55 kjc Exp $	*/
395a65560Sthorpej /*
495a65560Sthorpej  * Copyright (C) 1999-2000
595a65560Sthorpej  *	Sony Computer Science Laboratories, Inc.  All rights reserved.
695a65560Sthorpej  *
795a65560Sthorpej  * Redistribution and use in source and binary forms, with or without
895a65560Sthorpej  * modification, are permitted provided that the following conditions
995a65560Sthorpej  * are met:
1095a65560Sthorpej  * 1. Redistributions of source code must retain the above copyright
1195a65560Sthorpej  *    notice, this list of conditions and the following disclaimer.
1295a65560Sthorpej  * 2. Redistributions in binary form must reproduce the above copyright
1395a65560Sthorpej  *    notice, this list of conditions and the following disclaimer in the
1495a65560Sthorpej  *    documentation and/or other materials provided with the distribution.
1595a65560Sthorpej  *
1695a65560Sthorpej  * THIS SOFTWARE IS PROVIDED BY SONY CSL AND CONTRIBUTORS ``AS IS'' AND
1795a65560Sthorpej  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1895a65560Sthorpej  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1995a65560Sthorpej  * ARE DISCLAIMED.  IN NO EVENT SHALL SONY CSL OR CONTRIBUTORS BE LIABLE
2095a65560Sthorpej  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2195a65560Sthorpej  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2295a65560Sthorpej  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2395a65560Sthorpej  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2495a65560Sthorpej  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2595a65560Sthorpej  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2695a65560Sthorpej  * SUCH DAMAGE.
2795a65560Sthorpej  */
2895a65560Sthorpej 
2995a65560Sthorpej #include <sys/param.h>
3095a65560Sthorpej #include <sys/socket.h>
3195a65560Sthorpej #include <net/if.h>
3295a65560Sthorpej #include <stdio.h>
3395a65560Sthorpej #include <errno.h>
3495a65560Sthorpej #include <syslog.h>
35d5b97258Sthorpej #include <string.h>
3695a65560Sthorpej 
3795a65560Sthorpej #include <altq/altq.h>
3895a65560Sthorpej #include "altq_qop.h"
3995a65560Sthorpej 
408b8734d2Sitojun int null_interface_parser(const char *, int, char **);
418b8734d2Sitojun int null_class_parser(const char *, const char *, const char *, int, char **);
428b8734d2Sitojun int qcmd_nop_add_if(const char *);
438b8734d2Sitojun static int nop_attach(struct ifinfo *);
448b8734d2Sitojun static int nop_detach(struct ifinfo *);
458b8734d2Sitojun static int nop_clear(struct ifinfo *);
468b8734d2Sitojun static int nop_enable(struct ifinfo *);
478b8734d2Sitojun static int nop_disable(struct ifinfo *);
488b8734d2Sitojun static int nop_add_class(struct classinfo *);
498b8734d2Sitojun static int nop_modify_class(struct classinfo *, void *);
508b8734d2Sitojun static int nop_delete_class(struct classinfo *);
518b8734d2Sitojun static int nop_add_filter(struct fltrinfo *);
528b8734d2Sitojun static int nop_delete_filter(struct fltrinfo *);
5395a65560Sthorpej 
5495a65560Sthorpej struct qdisc_ops nop_qdisc = {
5595a65560Sthorpej 	ALTQT_NONE,
5695a65560Sthorpej 	"nop",
5795a65560Sthorpej 	nop_attach,
5895a65560Sthorpej 	nop_detach,
5995a65560Sthorpej 	nop_clear,
6095a65560Sthorpej 	nop_enable,
6195a65560Sthorpej 	nop_disable,
6295a65560Sthorpej 	nop_add_class,
6395a65560Sthorpej 	nop_modify_class,
6495a65560Sthorpej 	nop_delete_class,
6595a65560Sthorpej 	nop_add_filter,
6695a65560Sthorpej 	nop_delete_filter,
6795a65560Sthorpej };
6895a65560Sthorpej 
6995a65560Sthorpej #define EQUAL(s1, s2)	(strcmp((s1), (s2)) == 0)
7095a65560Sthorpej 
7195a65560Sthorpej /*
7295a65560Sthorpej  * parser interface for null interface
7395a65560Sthorpej  */
7495a65560Sthorpej int
null_interface_parser(const char * ifname,int argc,char ** argv)7595a65560Sthorpej null_interface_parser(const char *ifname, int argc, char **argv)
7695a65560Sthorpej {
7795a65560Sthorpej 	u_int  	bandwidth = 0;
7895a65560Sthorpej 	u_int	tbrsize = 0;
7995a65560Sthorpej 
8095a65560Sthorpej 	/*
8195a65560Sthorpej 	 * process options
8295a65560Sthorpej 	 */
8395a65560Sthorpej 	while (argc > 0) {
8495a65560Sthorpej 		if (EQUAL(*argv, "bandwidth")) {
8595a65560Sthorpej 			argc--; argv++;
8695a65560Sthorpej 			if (argc > 0)
8795a65560Sthorpej 				bandwidth = atobps(*argv);
8895a65560Sthorpej 		} else if (EQUAL(*argv, "tbrsize")) {
8995a65560Sthorpej 			argc--; argv++;
9095a65560Sthorpej 			if (argc > 0)
9195a65560Sthorpej 				tbrsize = atobytes(*argv);
9295a65560Sthorpej 		} else {
93*69881cf6Sitojun 			LOG(LOG_ERR, 0, "Unknown keyword '%s'", *argv);
9495a65560Sthorpej 			return (0);
9595a65560Sthorpej 		}
9695a65560Sthorpej 		argc--; argv++;
9795a65560Sthorpej 	}
9895a65560Sthorpej 
9995a65560Sthorpej 	if (bandwidth != 0)
10095a65560Sthorpej 		if (qcmd_tbr_register(ifname, bandwidth, tbrsize) != 0)
10195a65560Sthorpej 			return (0);
10295a65560Sthorpej 
10395a65560Sthorpej 	/*
10495a65560Sthorpej 	 * add a dummy interface since traffic conditioner might need it.
10595a65560Sthorpej 	 */
10695a65560Sthorpej 	if (qcmd_nop_add_if(ifname) != 0)
10795a65560Sthorpej 		return (0);
10895a65560Sthorpej 	return (1);
10995a65560Sthorpej }
11095a65560Sthorpej 
11195a65560Sthorpej int
null_class_parser(const char * ifname,const char * class_name,const char * parent_name,int argc,char ** argv)11295a65560Sthorpej null_class_parser(const char *ifname, const char *class_name,
11395a65560Sthorpej 		  const char *parent_name, int argc, char **argv)
11495a65560Sthorpej {
11595a65560Sthorpej 	LOG(LOG_ERR, 0,
116d5e1f166Sitojun 	    "class cannot be defined without a queueing discipline in %s, line %d",
11795a65560Sthorpej 	    altqconfigfile, line_no);
11895a65560Sthorpej 	return (0);
11995a65560Sthorpej }
12095a65560Sthorpej 
12195a65560Sthorpej /*
12295a65560Sthorpej  * qcmd api
12395a65560Sthorpej  */
12495a65560Sthorpej int
qcmd_nop_add_if(const char * ifname)12595a65560Sthorpej qcmd_nop_add_if(const char *ifname)
12695a65560Sthorpej {
12795a65560Sthorpej 	int error;
12895a65560Sthorpej 
12995a65560Sthorpej 	error = qop_add_if(NULL, ifname, 0, &nop_qdisc, NULL);
13095a65560Sthorpej 	if (error != 0)
131d5e1f166Sitojun 		LOG(LOG_ERR, errno, "%s: can't add nop on interface '%s'",
13295a65560Sthorpej 		    qoperror(error), ifname);
13395a65560Sthorpej 	return (error);
13495a65560Sthorpej }
13595a65560Sthorpej 
13695a65560Sthorpej /*
13795a65560Sthorpej  * qop api
13895a65560Sthorpej  */
nop_attach(struct ifinfo * ifinfo)13995a65560Sthorpej static int nop_attach(struct ifinfo *ifinfo)
14095a65560Sthorpej {
14195a65560Sthorpej 	return (0);
14295a65560Sthorpej }
14395a65560Sthorpej 
nop_detach(struct ifinfo * ifinfo)14495a65560Sthorpej static int nop_detach(struct ifinfo *ifinfo)
14595a65560Sthorpej {
14695a65560Sthorpej 	return (0);
14795a65560Sthorpej }
14895a65560Sthorpej 
nop_clear(struct ifinfo * ifinfo)14995a65560Sthorpej static int nop_clear(struct ifinfo *ifinfo)
15095a65560Sthorpej {
15195a65560Sthorpej 	return (0);
15295a65560Sthorpej }
15395a65560Sthorpej 
nop_enable(struct ifinfo * ifinfo)15495a65560Sthorpej static int nop_enable(struct ifinfo *ifinfo)
15595a65560Sthorpej {
15695a65560Sthorpej 	return (0);
15795a65560Sthorpej }
15895a65560Sthorpej 
nop_disable(struct ifinfo * ifinfo)15995a65560Sthorpej static int nop_disable(struct ifinfo *ifinfo)
16095a65560Sthorpej {
16195a65560Sthorpej 	return (0);
16295a65560Sthorpej }
16395a65560Sthorpej 
nop_add_class(struct classinfo * clinfo)16495a65560Sthorpej static int nop_add_class(struct classinfo *clinfo)
16595a65560Sthorpej {
16695a65560Sthorpej 	return (0);
16795a65560Sthorpej }
16895a65560Sthorpej 
nop_modify_class(struct classinfo * clinfo,void * arg)16995a65560Sthorpej static int nop_modify_class(struct classinfo *clinfo, void *arg)
17095a65560Sthorpej {
17195a65560Sthorpej 	return (0);
17295a65560Sthorpej }
17395a65560Sthorpej 
nop_delete_class(struct classinfo * clinfo)17495a65560Sthorpej static int nop_delete_class(struct classinfo *clinfo)
17595a65560Sthorpej {
17695a65560Sthorpej 	return (0);
17795a65560Sthorpej }
17895a65560Sthorpej 
nop_add_filter(struct fltrinfo * fltrinfo)17995a65560Sthorpej static int nop_add_filter(struct fltrinfo *fltrinfo)
18095a65560Sthorpej {
18195a65560Sthorpej 	return (0);
18295a65560Sthorpej }
18395a65560Sthorpej 
nop_delete_filter(struct fltrinfo * fltrinfo)18495a65560Sthorpej static int nop_delete_filter(struct fltrinfo *fltrinfo)
18595a65560Sthorpej {
18695a65560Sthorpej 	return (0);
18795a65560Sthorpej }
188