File:  [DragonFly] / src / sys / contrib / ipfilter / netinet / mlfk_ipl.c
Revision 1.6: download - view: text, annotated - select for diffs
Thu May 13 23:49:14 2004 UTC (9 years, 11 months ago) by dillon
Branches: MAIN
CVS tags: HEAD
device switch 1/many: Remove d_autoq, add d_clone (where d_autoq was).

d_autoq was used to allow the device port dispatch to mix old-style synchronous
calls with new style messaging calls within a particular device.  It was never
used for that purpose.

d_clone will be more fully implemented as work continues.  We are going to
install d_port in the dev_t (struct specinfo) structure itself and d_clone
will be needed to allow devices to 'revector' the port on a minor-number
by minor-number basis, in particular allowing minor numbers to be directly
dispatched to distinct threads.  This is something we will be needing later
on.

    1: /*
    2:  * Copyright 1999 Guido van Rooij.  All rights reserved.
    3:  * 
    4:  *
    5:  * Redistribution and use in source and binary forms, with or without
    6:  * modification, are permitted provided that the following conditions are
    7:  * met:
    8:  *  1. Redistributions of source code must retain the above copyright
    9:  *     notice, this list of conditions and the following disclaimer.
   10:  *  2. Redistributions in binary form must reproduce the above copyright notice,
   11:  *     this list of conditions and the following disclaimer in the documentation
   12:  *     and/or other materials provided with the distribution.
   13:  *
   14:  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER ``AS IS'' AND ANY EXPRESS
   15:  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
   16:  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   17:  * DISCLAIMED.  IN NO EVENT SHALL THE HOLDER OR CONTRIBUTORS BE LIABLE FOR
   18:  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   19:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
   20:  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
   21:  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   22:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   23:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   24:  * SUCH DAMAGE.
   25:  *
   26:  * $FreeBSD: src/sys/contrib/ipfilter/netinet/mlfk_ipl.c,v 1.9.2.2 2002/04/27 17:37:12 darrenr Exp $
   27:  * $DragonFly: src/sys/contrib/ipfilter/netinet/mlfk_ipl.c,v 1.6 2004/05/13 23:49:14 dillon Exp $
   28:  */
   29: 
   30: 
   31: #include <sys/param.h>
   32: #include <sys/systm.h>
   33: #include <sys/kernel.h>
   34: #include <sys/module.h>
   35: #include <sys/conf.h>
   36: #include <sys/socket.h>
   37: #include <sys/sysctl.h>
   38: #include <net/if.h>
   39: #include <netinet/in_systm.h>
   40: #include <netinet/in.h>
   41: #include <netinet/ip.h>
   42: #if defined(__DragonFly__) || (__FreeBSD_version >= 199511)
   43: # include <net/route.h>
   44: # include <netinet/ip_var.h>
   45: # include <netinet/tcp.h>
   46: # include <netinet/tcpip.h>
   47: #endif
   48: 
   49: 
   50: #include "ipl.h"
   51: #include "ip_compat.h"
   52: #include "ip_fil.h"
   53: #include "ip_state.h"
   54: #include "ip_nat.h"
   55: #include "ip_auth.h"
   56: #include "ip_frag.h"
   57: #include "ip_proxy.h"
   58: 
   59: static dev_t ipf_devs[IPL_LOGMAX + 1];
   60: 
   61: SYSCTL_DECL(_net_inet);
   62: SYSCTL_NODE(_net_inet, OID_AUTO, ipf, CTLFLAG_RW, 0, "IPF");
   63: SYSCTL_INT(_net_inet_ipf, OID_AUTO, fr_flags, CTLFLAG_RW, &fr_flags, 0, "");
   64: SYSCTL_INT(_net_inet_ipf, OID_AUTO, fr_pass, CTLFLAG_RW, &fr_pass, 0, "");
   65: SYSCTL_INT(_net_inet_ipf, OID_AUTO, fr_active, CTLFLAG_RD, &fr_active, 0, "");
   66: SYSCTL_INT(_net_inet_ipf, OID_AUTO, fr_tcpidletimeout, CTLFLAG_RW,
   67: 	   &fr_tcpidletimeout, 0, "");
   68: SYSCTL_INT(_net_inet_ipf, OID_AUTO, fr_tcpclosewait, CTLFLAG_RW,
   69: 	   &fr_tcpclosewait, 0, "");
   70: SYSCTL_INT(_net_inet_ipf, OID_AUTO, fr_tcplastack, CTLFLAG_RW,
   71: 	   &fr_tcplastack, 0, "");
   72: SYSCTL_INT(_net_inet_ipf, OID_AUTO, fr_tcptimeout, CTLFLAG_RW,
   73: 	   &fr_tcptimeout, 0, "");
   74: SYSCTL_INT(_net_inet_ipf, OID_AUTO, fr_tcpclosed, CTLFLAG_RW,
   75: 	   &fr_tcpclosed, 0, "");
   76: SYSCTL_INT(_net_inet_ipf, OID_AUTO, fr_tcphalfclosed, CTLFLAG_RW,
   77: 	   &fr_tcphalfclosed, 0, "");
   78: SYSCTL_INT(_net_inet_ipf, OID_AUTO, fr_udptimeout, CTLFLAG_RW,
   79: 	   &fr_udptimeout, 0, "");
   80: SYSCTL_INT(_net_inet_ipf, OID_AUTO, fr_udpacktimeout, CTLFLAG_RW,
   81: 	   &fr_udpacktimeout, 0, "");
   82: SYSCTL_INT(_net_inet_ipf, OID_AUTO, fr_icmptimeout, CTLFLAG_RW,
   83: 	   &fr_icmptimeout, 0, "");
   84: SYSCTL_INT(_net_inet_ipf, OID_AUTO, fr_icmpacktimeout, CTLFLAG_RW,
   85: 	   &fr_icmpacktimeout, 0, "");
   86: SYSCTL_INT(_net_inet_ipf, OID_AUTO, fr_defnatage, CTLFLAG_RW,
   87: 	   &fr_defnatage, 0, "");
   88: SYSCTL_INT(_net_inet_ipf, OID_AUTO, fr_ipfrttl, CTLFLAG_RW,
   89: 	   &fr_ipfrttl, 0, "");
   90: SYSCTL_INT(_net_inet_ipf, OID_AUTO, ipl_unreach, CTLFLAG_RW,
   91: 	   &ipl_unreach, 0, "");
   92: SYSCTL_INT(_net_inet_ipf, OID_AUTO, fr_running, CTLFLAG_RD,
   93: 	   &fr_running, 0, "");
   94: SYSCTL_INT(_net_inet_ipf, OID_AUTO, fr_authsize, CTLFLAG_RD,
   95: 	   &fr_authsize, 0, "");
   96: SYSCTL_INT(_net_inet_ipf, OID_AUTO, fr_authused, CTLFLAG_RD,
   97: 	   &fr_authused, 0, "");
   98: SYSCTL_INT(_net_inet_ipf, OID_AUTO, fr_defaultauthage, CTLFLAG_RW,
   99: 	   &fr_defaultauthage, 0, "");
  100: SYSCTL_INT(_net_inet_ipf, OID_AUTO, fr_chksrc, CTLFLAG_RW, &fr_chksrc, 0, "");
  101: SYSCTL_INT(_net_inet_ipf, OID_AUTO, ippr_ftp_pasvonly, CTLFLAG_RW,
  102: 	   &ippr_ftp_pasvonly, 0, "");
  103: SYSCTL_INT(_net_inet_ipf, OID_AUTO, fr_minttl, CTLFLAG_RW, &fr_minttl, 0, "");
  104: SYSCTL_INT(_net_inet_ipf, OID_AUTO, fr_minttllog, CTLFLAG_RW,
  105: 	   &fr_minttllog, 0, "");
  106: 
  107: #define CDEV_MAJOR 79
  108: static struct cdevsw ipl_cdevsw = {
  109: 	/* name */	"ipl",
  110: 	/* maj */	CDEV_MAJOR,
  111: 	/* flags */	0,
  112: 	/* port */      NULL,
  113: 	/* clone */	NULL,
  114: 
  115: 	/* open */	iplopen,
  116: 	/* close */	iplclose,
  117: 	/* read */	iplread,
  118: 	/* write */	nowrite,
  119: 	/* ioctl */	iplioctl,
  120: 	/* poll */	nopoll,
  121: 	/* mmap */	nommap,
  122: 	/* strategy */	nostrategy,
  123: 	/* dump */	nodump,
  124: 	/* psize */	nopsize
  125: };
  126: 
  127: static int
  128: ipfilter_modevent(module_t mod, int type, void *unused)
  129: {
  130: 	char	*c;
  131: 	int	i, error = 0;
  132: 
  133: 	switch (type) {
  134: 	case MOD_LOAD :
  135: 
  136: 		error = iplattach();
  137: 		if (error)
  138: 			break;
  139: 
  140: 		c = NULL;
  141: 		for(i=strlen(IPL_NAME); i>0; i--)
  142: 			if (IPL_NAME[i] == '/') {
  143: 				c = &IPL_NAME[i+1];
  144: 				break;
  145: 			}
  146: 		if (!c)
  147: 			c = IPL_NAME;
  148: 		ipf_devs[IPL_LOGIPF] =
  149: 		    make_dev(&ipl_cdevsw, IPL_LOGIPF, 0, 0, 0600, c);
  150: 
  151: 		c = NULL;
  152: 		for(i=strlen(IPL_NAT); i>0; i--)
  153: 			if (IPL_NAT[i] == '/') {
  154: 				c = &IPL_NAT[i+1];
  155: 				break;
  156: 			}
  157: 		if (!c)
  158: 			c = IPL_NAT;
  159: 		ipf_devs[IPL_LOGNAT] =
  160: 		    make_dev(&ipl_cdevsw, IPL_LOGNAT, 0, 0, 0600, c);
  161: 
  162: 		c = NULL;
  163: 		for(i=strlen(IPL_STATE); i>0; i--)
  164: 			if (IPL_STATE[i] == '/') {
  165: 				c = &IPL_STATE[i+1];
  166: 				break;
  167: 			}
  168: 		if (!c)
  169: 			c = IPL_STATE;
  170: 		ipf_devs[IPL_LOGSTATE] =
  171: 		    make_dev(&ipl_cdevsw, IPL_LOGSTATE, 0, 0, 0600, c);
  172: 
  173: 		c = NULL;
  174: 		for(i=strlen(IPL_AUTH); i>0; i--)
  175: 			if (IPL_AUTH[i] == '/') {
  176: 				c = &IPL_AUTH[i+1];
  177: 				break;
  178: 			}
  179: 		if (!c)
  180: 			c = IPL_AUTH;
  181: 		ipf_devs[IPL_LOGAUTH] =
  182: 		    make_dev(&ipl_cdevsw, IPL_LOGAUTH, 0, 0, 0600, c);
  183: 
  184: 		break;
  185: 	case MOD_UNLOAD :
  186: 		destroy_dev(ipf_devs[IPL_LOGIPF]);
  187: 		destroy_dev(ipf_devs[IPL_LOGNAT]);
  188: 		destroy_dev(ipf_devs[IPL_LOGSTATE]);
  189: 		destroy_dev(ipf_devs[IPL_LOGAUTH]);
  190: 		error = ipldetach();
  191: 		break;
  192: 	default:
  193: 		error = EINVAL;
  194: 		break;
  195: 	}
  196: 	return error;
  197: }
  198: 
  199: static moduledata_t ipfiltermod = {
  200: 	IPL_VERSION,
  201: 	ipfilter_modevent,
  202:         0
  203: };
  204: DECLARE_MODULE(ipfilter, ipfiltermod, SI_SUB_PROTO_DOMAIN, SI_ORDER_ANY);