PERFORCE change 106755 for review

Matt Jacob mjacob at FreeBSD.org
Tue Sep 26 20:41:26 PDT 2006


http://perforce.freebsd.org/chv.cgi?CH=106755

Change 106755 by mjacob at newisp on 2006/09/27 03:40:43

	IFC again.

Affected files ...

.. //depot/projects/newisp/conf/files#4 integrate
.. //depot/projects/newisp/i386/i386/busdma_machdep.c#5 integrate
.. //depot/projects/newisp/modules/libalias/Makefile#2 integrate
.. //depot/projects/newisp/modules/libalias/libalias/Makefile#1 branch
.. //depot/projects/newisp/modules/libalias/modules/Makefile#1 branch
.. //depot/projects/newisp/modules/libalias/modules/Makefile.inc#1 branch
.. //depot/projects/newisp/modules/libalias/modules/cuseeme/Makefile#1 branch
.. //depot/projects/newisp/modules/libalias/modules/dummy/Makefile#1 branch
.. //depot/projects/newisp/modules/libalias/modules/ftp/Makefile#1 branch
.. //depot/projects/newisp/modules/libalias/modules/irc/Makefile#1 branch
.. //depot/projects/newisp/modules/libalias/modules/modules.inc#1 branch
.. //depot/projects/newisp/modules/libalias/modules/nbt/Makefile#1 branch
.. //depot/projects/newisp/modules/libalias/modules/pptp/Makefile#1 branch
.. //depot/projects/newisp/modules/libalias/modules/skinny/Makefile#1 branch
.. //depot/projects/newisp/modules/libalias/modules/smedia/Makefile#1 branch
.. //depot/projects/newisp/netinet/libalias/alias.c#2 integrate
.. //depot/projects/newisp/netinet/libalias/alias.h#2 integrate
.. //depot/projects/newisp/netinet/libalias/alias_cuseeme.c#2 integrate
.. //depot/projects/newisp/netinet/libalias/alias_db.c#2 integrate
.. //depot/projects/newisp/netinet/libalias/alias_dummy.c#1 branch
.. //depot/projects/newisp/netinet/libalias/alias_ftp.c#2 integrate
.. //depot/projects/newisp/netinet/libalias/alias_irc.c#2 integrate
.. //depot/projects/newisp/netinet/libalias/alias_local.h#2 integrate
.. //depot/projects/newisp/netinet/libalias/alias_mod.c#1 branch
.. //depot/projects/newisp/netinet/libalias/alias_mod.h#1 branch
.. //depot/projects/newisp/netinet/libalias/alias_nbt.c#2 integrate
.. //depot/projects/newisp/netinet/libalias/alias_old.c#2 integrate
.. //depot/projects/newisp/netinet/libalias/alias_pptp.c#2 integrate
.. //depot/projects/newisp/netinet/libalias/alias_proxy.c#2 integrate
.. //depot/projects/newisp/netinet/libalias/alias_skinny.c#2 integrate
.. //depot/projects/newisp/netinet/libalias/alias_smedia.c#2 integrate
.. //depot/projects/newisp/netinet/libalias/alias_util.c#2 integrate
.. //depot/projects/newisp/netinet/libalias/libalias.3#2 integrate

Differences ...

==== //depot/projects/newisp/conf/files#4 (text+ko) ====

@@ -1,4 +1,4 @@
-# $FreeBSD: src/sys/conf/files,v 1.1143 2006/09/25 11:40:14 scottl Exp $
+# $FreeBSD: src/sys/conf/files,v 1.1144 2006/09/26 23:26:51 piso Exp $
 #
 # The long compile-with and dependency lines are required because of
 # limitations in config: backslash-newline doesn't work in strings, and
@@ -1744,16 +1744,11 @@
 netinet/tcp_usrreq.c		optional inet
 netinet/udp_usrreq.c		optional inet
 netinet/libalias/alias.c	optional libalias
-netinet/libalias/alias_cuseeme.c optional libalias
 netinet/libalias/alias_db.c	optional libalias
-netinet/libalias/alias_ftp.c	optional libalias
-netinet/libalias/alias_irc.c	optional libalias
-netinet/libalias/alias_nbt.c	optional libalias
-netinet/libalias/alias_pptp.c	optional libalias
 netinet/libalias/alias_proxy.c	optional libalias
-netinet/libalias/alias_skinny.c	optional libalias
-netinet/libalias/alias_smedia.c	optional libalias
 netinet/libalias/alias_util.c	optional libalias
+netinet/libalias/alias_old.c	optional libalias
+netinet/libalias/alias_mod.c	optional libalias
 netinet6/ah_aesxcbcmac.c	optional ipsec
 netinet6/ah_core.c		optional ipsec
 netinet6/ah_input.c		optional ipsec

==== //depot/projects/newisp/i386/i386/busdma_machdep.c#5 (text+ko) ====

@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/i386/i386/busdma_machdep.c,v 1.83 2006/09/24 19:24:26 imp Exp $");
+__FBSDID("$FreeBSD: src/sys/i386/i386/busdma_machdep.c,v 1.84 2006/09/26 23:14:42 scottl Exp $");
 
 #include <sys/param.h>
 #include <sys/kdb.h>
@@ -53,7 +53,6 @@
 #include <machine/md_var.h>
 
 #define MAX_BPAGES 512
-#define BUS_DMA_USE_FILTER	BUS_DMA_BUS2
 #define BUS_DMA_COULD_BOUNCE	BUS_DMA_BUS3
 #define BUS_DMA_MIN_ALLOC_COMP	BUS_DMA_BUS4
 
@@ -269,8 +268,8 @@
 			newtag->boundary = MIN(parent->boundary,
 					       newtag->boundary);
 		if ((newtag->filter != NULL) ||
-		    ((parent->flags & BUS_DMA_USE_FILTER) != 0))
-			newtag->flags |= BUS_DMA_USE_FILTER;
+		    ((parent->flags & BUS_DMA_COULD_BOUNCE) != 0))
+			newtag->flags |= BUS_DMA_COULD_BOUNCE;
 		if (newtag->filter == NULL) {
 			/*
 			 * Short circuit looking at our parent directly
@@ -583,7 +582,7 @@
 
 		while (vaddr < vendaddr) {
 			paddr = pmap_kextract(vaddr);
-			if (((dmat->flags & BUS_DMA_USE_FILTER) != 0) &&
+			if (((dmat->flags & BUS_DMA_COULD_BOUNCE) != 0) &&
 			    run_filter(dmat, paddr) != 0) {
 				needbounce = 1;
 				map->pagesneeded++;
@@ -682,7 +681,7 @@
 				sgsize = (baddr - curaddr);
 		}
 
-		if (((dmat->flags & BUS_DMA_USE_FILTER) != 0) &&
+		if (((dmat->flags & BUS_DMA_COULD_BOUNCE) != 0) &&
 		    map->pagesneeded != 0 && run_filter(dmat, curaddr))
 			curaddr = add_bounce_page(dmat, map, vaddr, sgsize);
 

==== //depot/projects/newisp/modules/libalias/Makefile#2 (text+ko) ====

@@ -1,33 +1,5 @@
-# $FreeBSD: src/sys/modules/libalias/Makefile,v 1.2 2005/06/20 08:33:29 glebius Exp $
+# $FreeBSD: src/sys/modules/libalias/Makefile,v 1.3 2006/09/26 23:26:51 piso Exp $
 
-.PATH: ${.CURDIR}/../../netinet/libalias
+SUBDIR=        libalias modules
 
-KMOD=	libalias
-SRCS=	alias.c alias_cuseeme.c alias_db.c alias_ftp.c alias_irc.c \
-	alias_nbt.c alias_pptp.c alias_proxy.c alias_skinny.c alias_smedia.c \
-	alias_util.c
-INCS=	alias.h
-
-EXPORT_SYMS=	LibAliasInit \
-		LibAliasUninit \
-		LibAliasSetAddress \
-		LibAliasSetMode \
-		LibAliasSkinnyPort \
-		LibAliasIn \
-		LibAliasOut \
-		LibAliasRedirectPort \
-		LibAliasRedirectAddr \
-		LibAliasAddServer \
-		LibAliasRedirectDynamic \
-		LibAliasRedirectDelete \
-		LibAliasProxyRule \
-		LibAliasRedirectProto \
-		LibAliasSaveFragment \
-		LibAliasGetFragment \
-		LibAliasFragmentIn \
-		LibAliasSetTarget \
-		LibAliasCheckNewLink \
-		LibAliasInternetChecksum \
-		LibAliasUnaliasOut
-
-.include <bsd.kmod.mk>
+.include <bsd.subdir.mk>

==== //depot/projects/newisp/netinet/libalias/alias.c#2 (text+ko) ====

@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/netinet/libalias/alias.c,v 1.53 2005/06/27 22:21:42 phk Exp $");
+__FBSDID("$FreeBSD: src/sys/netinet/libalias/alias.c,v 1.54 2006/09/26 23:26:53 piso Exp $");
 
 /*
     Alias.c provides supervisory control for the functions of the
@@ -115,7 +115,11 @@
 #include <sys/param.h>
 #else
 #include <sys/types.h>
+#include <stdlib.h>
 #include <stdio.h>
+#include <dlfcn.h>
+#include <errno.h>
+#include <string.h>
 #endif
 
 #include <netinet/in_systm.h>
@@ -128,22 +132,14 @@
 #ifdef _KERNEL
 #include <netinet/libalias/alias.h>
 #include <netinet/libalias/alias_local.h>
+#include <netinet/libalias/alias_mod.h>
 #else
+#include <err.h>
 #include "alias.h"
 #include "alias_local.h"
+#include "alias_mod.h"
 #endif
 
-#define NETBIOS_NS_PORT_NUMBER 137
-#define NETBIOS_DGM_PORT_NUMBER 138
-#define FTP_CONTROL_PORT_NUMBER 21
-#define IRC_CONTROL_PORT_NUMBER_1 6667
-#define IRC_CONTROL_PORT_NUMBER_2 6668
-#define CUSEEME_PORT_NUMBER 7648
-#define RTSP_CONTROL_PORT_NUMBER_1 554
-#define RTSP_CONTROL_PORT_NUMBER_2 7070
-#define TFTP_PORT_NUMBER 69
-#define PPTP_CONTROL_PORT_NUMBER 1723
-
 static __inline int
 twowords(void *p)
 {
@@ -725,24 +721,24 @@
 		struct in_addr original_address;
 		u_short alias_port;
 		int accumulate;
-		int r = 0;
+		int r = 0, error;
+		struct alias_data ad = {
+			.lnk = lnk, 
+			.oaddr = &original_address, 
+			.aaddr = &alias_address,
+			.aport = &alias_port,
+			.sport = &ud->uh_sport,
+			.dport = &ud->uh_dport,
+			.maxpktsize = 0
+		};
 
 		alias_address = GetAliasAddress(lnk);
 		original_address = GetOriginalAddress(lnk);
 		alias_port = ud->uh_dport;
 		ud->uh_dport = GetOriginalPort(lnk);
 
-/* Special processing for IP encoding protocols */
-		if (ntohs(ud->uh_dport) == CUSEEME_PORT_NUMBER)
-			AliasHandleCUSeeMeIn(la, pip, original_address);
-/* If NETBIOS Datagram, It should be alias address in UDP Data, too */
-		else if (ntohs(ud->uh_dport) == NETBIOS_DGM_PORT_NUMBER
-		    || ntohs(ud->uh_sport) == NETBIOS_DGM_PORT_NUMBER)
-			r = AliasHandleUdpNbt(la, pip, lnk, &original_address, ud->uh_dport);
-		else if (ntohs(ud->uh_dport) == NETBIOS_NS_PORT_NUMBER
-		    || ntohs(ud->uh_sport) == NETBIOS_NS_PORT_NUMBER)
-			r = AliasHandleUdpNbtNS(la, pip, lnk, &alias_address, &alias_port,
-			    &original_address, &ud->uh_dport);
+		/* Walk out chain. */		
+		error = find_handler(IN, UDP, la, pip, &ad);
 
 /* If UDP checksum is not zero, then adjust since destination port */
 /* is being unaliased and destination address is being altered.    */
@@ -774,6 +770,7 @@
 {
 	struct udphdr *ud;
 	struct alias_link *lnk;
+	int error;
 
 /* Return if proxy-only mode is enabled */
 	if (la->packetAliasMode & PKT_ALIAS_PROXY_ONLY)
@@ -787,29 +784,21 @@
 	if (lnk != NULL) {
 		u_short alias_port;
 		struct in_addr alias_address;
+		struct alias_data ad = {
+			.lnk = lnk, 
+			.oaddr = NULL,
+			.aaddr = &alias_address,
+			.aport = &alias_port,
+			.sport = &ud->uh_sport,
+			.dport = &ud->uh_dport,
+			.maxpktsize = 0
+		};
 
 		alias_address = GetAliasAddress(lnk);
 		alias_port = GetAliasPort(lnk);
 
-/* Special processing for IP encoding protocols */
-		if (ntohs(ud->uh_dport) == CUSEEME_PORT_NUMBER)
-			AliasHandleCUSeeMeOut(la, pip, lnk);
-/* If NETBIOS Datagram, It should be alias address in UDP Data, too */
-		else if (ntohs(ud->uh_dport) == NETBIOS_DGM_PORT_NUMBER
-		    || ntohs(ud->uh_sport) == NETBIOS_DGM_PORT_NUMBER)
-			AliasHandleUdpNbt(la, pip, lnk, &alias_address, alias_port);
-		else if (ntohs(ud->uh_dport) == NETBIOS_NS_PORT_NUMBER
-		    || ntohs(ud->uh_sport) == NETBIOS_NS_PORT_NUMBER)
-			AliasHandleUdpNbtNS(la, pip, lnk, &pip->ip_src, &ud->uh_sport,
-			    &alias_address, &alias_port);
-/*
- * We don't know in advance what TID the TFTP server will choose,
- * so we create a wilcard link (destination port is unspecified)
- * that will match any TID from a given destination.
- */
-		else if (ntohs(ud->uh_dport) == TFTP_PORT_NUMBER)
-			FindRtspOut(la, pip->ip_src, pip->ip_dst,
-			    ud->uh_sport, alias_port, IPPROTO_UDP);
+		/* Walk out chain. */		
+		error = find_handler(OUT, UDP, la, pip, &ad);
 
 /* If UDP checksum is not zero, adjust since source port is */
 /* being aliased and source address is being altered        */
@@ -855,15 +844,26 @@
 		struct in_addr proxy_address;
 		u_short alias_port;
 		u_short proxy_port;
-		int accumulate;
+		int accumulate, error;
+
+		/* 
+		 * The init of MANY vars is a bit below, but aliashandlepptpin 
+		 * seems to need the destination port that came within the
+		 * packet and not the original one looks below [*].
+		 */
+
+		struct alias_data ad = {
+			.lnk = lnk, 
+			.oaddr = NULL,
+			.aaddr = NULL,
+			.aport = NULL,
+			.sport = &tc->th_sport,
+			.dport = &tc->th_dport,
+			.maxpktsize = 0
+		};
 
-/* Special processing for IP encoding protocols */
-		if (ntohs(tc->th_dport) == PPTP_CONTROL_PORT_NUMBER
-		    || ntohs(tc->th_sport) == PPTP_CONTROL_PORT_NUMBER)
-			AliasHandlePptpIn(la, pip, lnk);
-		else if (la->skinnyPort != 0 && (ntohs(tc->th_dport) == la->skinnyPort
-		    || ntohs(tc->th_sport) == la->skinnyPort))
-			AliasHandleSkinny(la, pip, lnk);
+		/* Walk out chain. */		
+		error = find_handler(IN, TCP, la, pip, &ad);
 
 		alias_address = GetAliasAddress(lnk);
 		original_address = GetOriginalAddress(lnk);
@@ -872,6 +872,28 @@
 		tc->th_dport = GetOriginalPort(lnk);
 		proxy_port = GetProxyPort(lnk);
 
+		/* 
+		 * Look above, if anyone is going to add find_handler AFTER 
+		 * this aliashandlepptpin/point, please redo alias_data too.
+		 * Uncommenting the piece here below should be enough.
+		 */
+#if 0
+				 struct alias_data ad = {
+					.lnk = lnk,
+					.oaddr = &original_address,
+					.aaddr = &alias_address,
+					.aport = &alias_port,
+					.sport = &ud->uh_sport,
+					.dport = &ud->uh_dport,
+					.maxpktsize = 0
+				};
+		
+				/* Walk out chain. */
+				error = find_handler(la, pip, &ad);
+				if (error == EHDNOF)
+					printf("Protocol handler not found\n");
+#endif
+
 /* Adjust TCP checksum since destination port is being unaliased */
 /* and destination port is being altered.                        */
 		accumulate = alias_port;
@@ -926,7 +948,7 @@
 static int
 TcpAliasOut(struct libalias *la, struct ip *pip, int maxpacketsize, int create)
 {
-	int proxy_type;
+	int proxy_type, error;
 	u_short dest_port;
 	u_short proxy_server_port;
 	struct in_addr dest_address;
@@ -973,6 +995,15 @@
 		u_short alias_port;
 		struct in_addr alias_address;
 		int accumulate;
+		struct alias_data ad = {
+			.lnk = lnk, 
+			.oaddr = NULL,
+			.aaddr = &alias_address,
+			.aport = &alias_port,
+			.sport = &tc->th_sport,
+			.dport = &tc->th_dport,
+			.maxpktsize = maxpacketsize
+		};
 
 /* Save original destination address, if this is a proxy packet.
    Also modify packet to include destination encoding.  This may
@@ -989,26 +1020,10 @@
 
 /* Monitor TCP connection state */
 		TcpMonitorOut(pip, lnk);
+		
+		/* Walk out chain. */		
+		error = find_handler(OUT, TCP, la, pip, &ad);
 
-/* Special processing for IP encoding protocols */
-		if (ntohs(tc->th_dport) == FTP_CONTROL_PORT_NUMBER
-		    || ntohs(tc->th_sport) == FTP_CONTROL_PORT_NUMBER)
-			AliasHandleFtpOut(la, pip, lnk, maxpacketsize);
-		else if (ntohs(tc->th_dport) == IRC_CONTROL_PORT_NUMBER_1
-		    || ntohs(tc->th_dport) == IRC_CONTROL_PORT_NUMBER_2)
-			AliasHandleIrcOut(la, pip, lnk, maxpacketsize);
-		else if (ntohs(tc->th_dport) == RTSP_CONTROL_PORT_NUMBER_1
-			    || ntohs(tc->th_sport) == RTSP_CONTROL_PORT_NUMBER_1
-			    || ntohs(tc->th_dport) == RTSP_CONTROL_PORT_NUMBER_2
-		    || ntohs(tc->th_sport) == RTSP_CONTROL_PORT_NUMBER_2)
-			AliasHandleRtspOut(la, pip, lnk, maxpacketsize);
-		else if (ntohs(tc->th_dport) == PPTP_CONTROL_PORT_NUMBER
-		    || ntohs(tc->th_sport) == PPTP_CONTROL_PORT_NUMBER)
-			AliasHandlePptpOut(la, pip, lnk);
-		else if (la->skinnyPort != 0 && (ntohs(tc->th_sport) == la->skinnyPort
-		    || ntohs(tc->th_dport) == la->skinnyPort))
-			AliasHandleSkinny(la, pip, lnk);
-
 /* Adjust TCP checksum since source port is being aliased */
 /* and source address is being altered                    */
 		accumulate = tc->th_sport;
@@ -1208,13 +1223,26 @@
 		case IPPROTO_TCP:
 			iresult = TcpAliasIn(la, pip);
 			break;
-		case IPPROTO_GRE:
-			if (la->packetAliasMode & PKT_ALIAS_PROXY_ONLY ||
-			    AliasHandlePptpGreIn(la, pip) == 0)
+ 		case IPPROTO_GRE: {
+			int error;
+			struct alias_data ad = {
+				.lnk = NULL, 
+				.oaddr = NULL, 
+				.aaddr = NULL,
+				.aport = NULL,
+				.sport = NULL,
+				.dport = NULL,
+				.maxpktsize = 0                  
+			};
+			
+			/* Walk out chain. */		
+			error = find_handler(IN, IP, la, pip, &ad);
+			if (error ==  0)
 				iresult = PKT_ALIAS_OK;
 			else
 				iresult = ProtoAliasIn(la, pip);
-			break;
+		}
+ 			break; 
 		default:
 			iresult = ProtoAliasIn(la, pip);
 			break;
@@ -1321,12 +1349,25 @@
 			case IPPROTO_TCP:
 			iresult = TcpAliasOut(la, pip, maxpacketsize, create);
 			break;
-		case IPPROTO_GRE:
-			if (AliasHandlePptpGreOut(la, pip) == 0)
-				iresult = PKT_ALIAS_OK;
-			else
-				iresult = ProtoAliasOut(la, pip, create);
-			break;
+ 		case IPPROTO_GRE: {
+			int error;
+			struct alias_data ad = {
+				.lnk = NULL, 
+				.oaddr = NULL, 
+				.aaddr = NULL,
+				.aport = NULL,
+				.sport = NULL,
+				.dport = NULL,
+				.maxpktsize = 0                  
+			};
+			/* Walk out chain. */		
+			error = find_handler(OUT, IP, la, pip, &ad);
+			if (error == 0)
+ 				iresult = PKT_ALIAS_OK;
+ 			else
+ 				iresult = ProtoAliasOut(la, pip, create);
+		}
+ 			break;
 		default:
 			iresult = ProtoAliasOut(la, pip, create);
 			break;
@@ -1443,3 +1484,93 @@
 	return (iresult);
 
 }
+
+#ifndef _KERNEL
+
+int
+LibAliasRefreshModules(void)
+{
+	char buf[256], conf[] = "/etc/libalias.conf";
+	FILE *fd;
+	int len;
+
+	fd = fopen(conf, "r");
+	if (fd == NULL)
+		err(1, "fopen(%s)", conf);
+
+	LibAliasUnLoadAllModule();
+
+	for (;;) {
+		fgets(buf, 256, fd);
+		if feof(fd) 
+		        break;
+		len = strlen(buf);
+		if (len > 1) {
+			buf[len - 1] = '\0';
+			printf("Loading %s\n", buf);
+			LibAliasLoadModule(buf);
+		}
+	}
+	return (0);
+}
+
+int
+LibAliasLoadModule(char *path)
+{
+	struct dll *t;
+	void *handle;
+	struct proto_handler *m;
+        const char *error;
+	moduledata_t *p;
+
+        handle = dlopen (path, RTLD_LAZY);
+        if (!handle) {
+            fputs (dlerror(), stderr);
+            return (EINVAL);
+        }
+
+	p = dlsym(handle, "alias_mod");
+        if ((error = dlerror()) != NULL)  {
+            fputs(error, stderr);
+	    return (EINVAL);
+        }
+	
+	t = malloc(sizeof(struct dll));
+	if (t == NULL)
+		return (ENOMEM);
+	strncpy(t->name, p->name, DLL_LEN);
+	t->handle = handle;
+	if (attach_dll(t) == EEXIST) {
+		free(t);
+		fputs("dll conflict", stderr);
+		return (EEXIST);
+	}
+
+        m = dlsym(t->handle, "handlers");
+        if ((error = dlerror()) != NULL)  {
+            fputs(error, stderr);
+	    return (EINVAL);
+        }       
+
+	LibAliasAttachHandlers(m);
+	return (0);
+}
+
+int
+LibAliasUnLoadAllModule(void)
+{
+	struct dll *t;
+	struct proto_handler *p;
+
+	/* Unload all modules then reload everything. */
+	while ((p = first_handler()) != NULL) {	
+		detach_handler(p);
+	}
+	while ((t = walk_dll_chain()) != NULL) {	
+		dlclose(t->handle);
+		free(t);
+	}
+	return (1);
+}
+
+#endif

==== //depot/projects/newisp/netinet/libalias/alias.h#2 (text+ko) ====

@@ -25,10 +25,10 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: src/sys/netinet/libalias/alias.h,v 1.32 2005/05/05 21:53:17 glebius Exp $
+ * $FreeBSD: src/sys/netinet/libalias/alias.h,v 1.33 2006/09/26 23:26:53 piso Exp $
  */
 
-/*-
+/*
  * Alias.h defines the outside world interfaces for the packet aliasing
  * software.
  *
@@ -39,12 +39,16 @@
 #ifndef _ALIAS_H_
 #define	_ALIAS_H_
 
+#include <netinet/in_systm.h>
+#include <netinet/in.h>
+#include <netinet/ip.h>
+
+#define LIBALIAS_BUF_SIZE 128
 #ifdef	_KERNEL
 /*
  * The kernel version of libalias does not support these features.
  */
 #define	NO_FW_PUNCH
-#define	NO_LOGGING
 #define	NO_USE_SOCKETS
 #endif
 
@@ -180,6 +184,10 @@
 /* Transparent proxying routines. */
 int		LibAliasProxyRule(struct libalias *, const char *_cmd);
 
+/* Module handling API */
+int             LibAliasLoadModule(char *);
+int             LibAliasUnLoadAllModule(void);
+int             LibAliasRefreshModules(void);
 
 /*
  * Mode flags and other constants.
@@ -192,9 +200,7 @@
  * If PKT_ALIAS_LOG is set, a message will be printed to /var/log/alias.log
  * every time a link is created or deleted.  This is useful for debugging.
  */
-#ifndef	NO_LOGGING
 #define	PKT_ALIAS_LOG			0x01
-#endif
 
 /*
  * If PKT_ALIAS_DENY_INCOMING is set, then incoming connections (e.g. to ftp,

==== //depot/projects/newisp/netinet/libalias/alias_cuseeme.c#2 (text+ko) ====

@@ -27,11 +27,14 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/netinet/libalias/alias_cuseeme.c,v 1.12 2005/05/05 21:55:17 glebius Exp $");
+__FBSDID("$FreeBSD: src/sys/netinet/libalias/alias_cuseeme.c,v 1.13 2006/09/26 23:26:53 piso Exp $");
 
 #ifdef _KERNEL
 #include <sys/param.h>
+#include <sys/kernel.h>
+#include <sys/module.h>
 #else
+#include <errno.h>
 #include <sys/types.h>
 #include <stdio.h>
 #endif
@@ -44,10 +47,102 @@
 #ifdef _KERNEL
 #include <netinet/libalias/alias.h>
 #include <netinet/libalias/alias_local.h>
+#include <netinet/libalias/alias_mod.h>
 #else
 #include "alias_local.h"
+#include "alias_mod.h"
 #endif
 
+#define CUSEEME_PORT_NUMBER 7648
+
+static void
+AliasHandleCUSeeMeOut(struct libalias *la, struct ip *pip, 
+		      struct alias_link *lnk);
+
+static void
+AliasHandleCUSeeMeIn(struct libalias *la, struct ip *pip, 
+		     struct in_addr original_addr);
+
+static int 
+fingerprint(struct libalias *la, struct ip *pip, struct alias_data *ah)
+{
+
+	if (ah->dport == NULL || ah->oaddr == NULL)
+		return (-1);
+	if (ntohs(*ah->dport) == CUSEEME_PORT_NUMBER)
+		return (0);
+	return (-1);
+}
+
+static int 
+protohandlerin(struct libalias *la, struct ip *pip, struct alias_data *ah)
+{
+	
+	AliasHandleCUSeeMeIn(la, pip, *ah->oaddr);
+	return (0);
+}
+
+static int 
+protohandlerout(struct libalias *la, struct ip *pip, struct alias_data *ah)
+{
+	
+	AliasHandleCUSeeMeOut(la, pip, ah->lnk);
+	return (0);
+}
+
+/* Kernel module definition. */
+struct proto_handler handlers[] = {
+	{ 
+	  .pri = 120, 
+	  .dir = OUT, 
+	  .proto = UDP, 
+	  .fingerprint = &fingerprint, 
+	  .protohandler = &protohandlerout
+	}, 
+	{
+	  .pri = 120, 
+	  .dir = IN, 
+	  .proto = UDP, 
+	  .fingerprint = &fingerprint, 
+	  .protohandler = &protohandlerin
+	}, 
+	{ EOH }
+};
+
+static int
+mod_handler(module_t mod, int type, void *data)
+{
+	int error;
+
+	switch (type) {
+	case MOD_LOAD:
+		error = 0;
+		LibAliasAttachHandlers(handlers);
+		break;
+	case MOD_UNLOAD:
+		error = 0;
+		LibAliasDetachHandlers(handlers);
+		break;
+	default:
+		error = EINVAL;
+	}
+	return (error);
+}
+
+#ifdef _KERNEL
+static 
+#endif
+moduledata_t 
+alias_mod = {
+       "alias_cuseeme", mod_handler, NULL
+};
+
+#ifdef	_KERNEL
+DECLARE_MODULE(alias_cuseeme, alias_mod, SI_SUB_DRIVERS, SI_ORDER_SECOND);
+MODULE_VERSION(alias_cuseeme, 1);
+MODULE_DEPEND(alias_cuseeme, libalias, 1, 1, 1);
+#endif
+
 /* CU-SeeMe Data Header */
 struct cu_header {
 	u_int16_t	dest_family;
@@ -77,7 +172,7 @@
 					 * counts etc */
 };
 
-void
+static void
 AliasHandleCUSeeMeOut(struct libalias *la, struct ip *pip, struct alias_link *lnk)
 {
 	struct udphdr *ud = ip_next(pip);
@@ -100,7 +195,7 @@
 	}
 }
 
-void
+static void
 AliasHandleCUSeeMeIn(struct libalias *la, struct ip *pip, struct in_addr original_addr)
 {
 	struct in_addr alias_addr;

==== //depot/projects/newisp/netinet/libalias/alias_db.c#2 (text+ko) ====

@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/netinet/libalias/alias_db.c,v 1.68 2005/09/19 22:31:45 andre Exp $");
+__FBSDID("$FreeBSD: src/sys/netinet/libalias/alias_db.c,v 1.69 2006/09/26 23:26:53 piso Exp $");
 
 /*
     Alias_db.c encapsulates all data structures used for storing
@@ -143,40 +143,32 @@
 */
 
 #ifdef _KERNEL
+#include <machine/stdarg.h>
 #include <sys/param.h>
-#else
-#include <sys/types.h>
-#endif
-
-#include <sys/errno.h>
-#include <sys/queue.h>
-#include <sys/socket.h>
-#include <sys/time.h>
-
-#ifdef _KERNEL
-#include <sys/systm.h>
 #include <sys/kernel.h>
-#include <sys/malloc.h>
 #include <sys/module.h>
-#else 
+#include <sys/syslog.h>
+#else
+#include <stdarg.h>
 #include <stdlib.h>
 #include <stdio.h>
+#include <sys/errno.h>
+#include <sys/time.h>
 #include <unistd.h> 
-#include <arpa/inet.h>
 #endif
 
-/* BSD network include files */
-#include <netinet/in_systm.h>
-#include <netinet/in.h>
-#include <netinet/ip.h>
+#include <sys/socket.h>
 #include <netinet/tcp.h>
 
 #ifdef _KERNEL  
 #include <netinet/libalias/alias.h>
 #include <netinet/libalias/alias_local.h>
+#include <netinet/libalias/alias_mod.h>
+#include <net/if.h>
 #else
 #include "alias.h"
 #include "alias_local.h"
+#include "alias_mod.h"
 #endif
 
 static		LIST_HEAD(, libalias) instancehead = LIST_HEAD_INITIALIZER(instancehead);
@@ -358,10 +350,12 @@
 	switch (type) {
 	case MOD_LOAD:
 		error = 0;
+		handler_chain_init();
 		break;
 	case MOD_QUIESCE:
 	case MOD_UNLOAD:
-		finishoff();
+	        handler_chain_destroy();
+	        finishoff();
 		error = 0;
 		break;
 	default:
@@ -409,12 +403,10 @@
 
 #endif
 
-#ifndef	NO_LOGGING
 /* Log file control */
 static void	ShowAliasStats(struct libalias *);
-static void	InitPacketAliasLog(struct libalias *);
+static int	InitPacketAliasLog(struct libalias *);
 static void	UninitPacketAliasLog(struct libalias *);
-#endif
 
 static		u_int
 StartPointIn(struct in_addr alias_addr,
@@ -462,37 +454,55 @@
 	return (ntohl(y) - ntohl(x));
 }
 
+#ifdef _KERNEL
+
+static void
+AliasLog(char *str, const char *format, ...)
+{		
+	va_list ap;
+	
+	va_start(ap, format);
+	vsnprintf(str, LIBALIAS_BUF_SIZE, format, ap);
+	log(LOG_SECURITY | LOG_INFO, "%s\n", str);
+	va_end(ap);
+}
+#else
+static void
+AliasLog(FILE *stream, const char *format, ...)
+{
+	va_list ap;
+	
+	va_start(ap, format);
+	vfprintf(stream, format, ap);
+	va_end(ap);
+	fflush(stream);
+}
+#endif
 
-#ifndef	NO_LOGGING
 static void
 ShowAliasStats(struct libalias *la)
 {
 /* Used for debugging */
-
-	if (la->monitorFile) {
-		fprintf(la->monitorFile,
-		    "icmp=%d, udp=%d, tcp=%d, pptp=%d, proto=%d, frag_id=%d frag_ptr=%d",
-		    la->icmpLinkCount,
-		    la->udpLinkCount,
-		    la->tcpLinkCount,
-		    la->pptpLinkCount,
-		    la->protoLinkCount,
-		    la->fragmentIdLinkCount,
-		    la->fragmentPtrLinkCount);
-
-		fprintf(la->monitorFile, " / tot=%d  (sock=%d)\n",
-		    la->icmpLinkCount + la->udpLinkCount
-		    + la->tcpLinkCount
-		    + la->pptpLinkCount
-		    + la->protoLinkCount
-		    + la->fragmentIdLinkCount
-		    + la->fragmentPtrLinkCount,
-		    la->sockCount);
-
-		fflush(la->monitorFile);
+	if (la->logDesc) {
+		int tot  = la->icmpLinkCount + la->udpLinkCount + 
+			la->tcpLinkCount + la->pptpLinkCount +
+			la->protoLinkCount + la->fragmentIdLinkCount +
+			la->fragmentPtrLinkCount;
+		
+		AliasLog(la->logDesc,
+			 "icmp=%u, udp=%u, tcp=%u, pptp=%u, proto=%u, frag_id=%u frag_ptr=%u / tot=%u",
+			 la->icmpLinkCount,
+			 la->udpLinkCount,
+			 la->tcpLinkCount,
+			 la->pptpLinkCount,
+			 la->protoLinkCount,
+			 la->fragmentIdLinkCount,
+			 la->fragmentPtrLinkCount, tot);
+#ifndef _KERNEL
+		AliasLog(la->logDesc, " (sock=%u)\n", la->sockCount); 
+#endif
 	}
 }
-#endif
 
 /* Internal routines for finding, deleting and adding links
 
@@ -929,12 +939,10 @@
 /* Free memory */
 	free(lnk);
 
-#ifndef	NO_LOGGING
 /* Write statistics, if logging enabled */
 	if (la->packetAliasMode & PKT_ALIAS_LOG) {
 		ShowAliasStats(la);
 	}
-#endif
 }
 
 
@@ -1072,11 +1080,9 @@
 		fprintf(stderr, "malloc() call failed.\n");
 #endif
 	}
-#ifndef	NO_LOGGING
 	if (la->packetAliasMode & PKT_ALIAS_LOG) {
 		ShowAliasStats(la);
 	}
-#endif
 	return (lnk);
 }
 
@@ -2203,30 +2209,40 @@
 	}
 }
 
-#ifndef	NO_LOGGING
 /* Init the log file and enable logging */
-static void
+static int
 InitPacketAliasLog(struct libalias *la)
 {
-	if ((~la->packetAliasMode & PKT_ALIAS_LOG)
-	    && (la->monitorFile = fopen("/var/log/alias.log", "w"))) {
+	if (~la->packetAliasMode & PKT_ALIAS_LOG) {
+#ifdef _KERNEL
+		if ((la->logDesc = malloc(LIBALIAS_BUF_SIZE)))
+			;
+#else 		
+		if ((la->logDesc = fopen("/var/log/alias.log", "w")))
+			fprintf(la->logDesc, "PacketAlias/InitPacketAliasLog: Packet alias logging enabled.\n");	       
+#endif
+		else 
+			return (ENOMEM); /* log initialization failed */
 		la->packetAliasMode |= PKT_ALIAS_LOG;
-		fprintf(la->monitorFile,
-		    "PacketAlias/InitPacketAliasLog: Packet alias logging enabled.\n");
 	}
+
+	return (1);
 }
 
 /* Close the log-file and disable logging. */
 static void
 UninitPacketAliasLog(struct libalias *la)
 {
-	if (la->monitorFile) {
-		fclose(la->monitorFile);
-		la->monitorFile = NULL;
-	}
+		if (la->logDesc) {

>>> TRUNCATED FOR MAIL (1000 lines) <<<


More information about the p4-projects mailing list