From f860c634d16f94793f6aafc4868bc56844ce4385 Mon Sep 17 00:00:00 2001 From: Bill Yuan Date: Mon, 9 Mar 2015 01:49:34 +0800 Subject: [PATCH] New IPFW2 for DragonflyBSD which is: 1. source clean and following the Dfly coding style. 2. able to run parallelly together with the existing ipfw. 3. support in-kernel NAT. 4. some enhanced features. 5. designed in modular. --- lib/libipfw2/basic/Makefile | 2 +- lib/libipfw2/layer2/Makefile | 4 +-- lib/libipfw2/layer2/ipfw2_layer2.c | 1 - lib/libipfw2/layer4/Makefile | 6 ++-- lib/libipfw2/layer4/ipfw2_layer4.c | 1 - lib/libipfw2/nat/Makefile | 6 ++-- lib/libipfw2/nat/ipfw2_nat.c | 1 - sbin/ipfw2/ipfw.h | 8 ++--- sys/net/dummynet2/Makefile | 4 +-- sys/net/ipfw2/ip_fw3.h | 1 - sys/net/ipfw2_basic/Makefile | 4 +-- sys/net/ipfw2_basic/ip_fw2_basic.h | 8 ++--- sys/net/ipfw2_layer2/Makefile | 4 +-- sys/net/ipfw2_layer4/Makefile | 4 +-- sys/net/ipfw2_nat/Makefile | 4 +-- sys/net/libalias/HISTORY | 4 +-- sys/net/libalias/alias.c | 68 +++++++++++++++++++------------------- sys/net/libalias/alias_cuseeme.c | 4 +-- sys/net/libalias/alias_dummy.c | 1 - sys/net/libalias/alias_ftp.c | 24 +++++++------- sys/net/libalias/alias_irc.c | 22 ++++++------ sys/net/libalias/alias_mod.h | 36 ++++++++++---------- sys/net/libalias/alias_nbt.c | 62 +++++++++++++++++----------------- sys/net/libalias/alias_pptp.c | 64 +++++++++++++++++------------------ sys/net/libalias/alias_smedia.c | 24 +++++++------- 25 files changed, 181 insertions(+), 186 deletions(-) diff --git a/lib/libipfw2/basic/Makefile b/lib/libipfw2/basic/Makefile index 00826820cf..44e2af6d29 100644 --- a/lib/libipfw2/basic/Makefile +++ b/lib/libipfw2/basic/Makefile @@ -1,6 +1,6 @@ SRCDIR= ${.CURDIR}/ -LIB= ipfw2basic +LIB= ipfw2basic SRCS= ipfw2_basic.c INCS= ipfw2_basic.h diff --git a/lib/libipfw2/layer2/Makefile b/lib/libipfw2/layer2/Makefile index 8bdcade282..edaf8d4b49 100644 --- a/lib/libipfw2/layer2/Makefile +++ b/lib/libipfw2/layer2/Makefile @@ -1,9 +1,9 @@ SRCDIR= ${.CURDIR}/ LIB= ipfw2layer2 -SRCS= ipfw2_layer2.c +SRCS= ipfw2_layer2.c -INCS= ipfw2_layer2.h +INCS= ipfw2_layer2.h WARNS?= 2 diff --git a/lib/libipfw2/layer2/ipfw2_layer2.c b/lib/libipfw2/layer2/ipfw2_layer2.c index 707d63998f..550b9fd5e7 100644 --- a/lib/libipfw2/layer2/ipfw2_layer2.c +++ b/lib/libipfw2/layer2/ipfw2_layer2.c @@ -180,4 +180,3 @@ load_module(register_func function, register_keyword keyword) function(MODULE_LAYER2_ID, O_LAYER2_MAC, (parser_func)parse_mac,(shower_func)show_mac); } - diff --git a/lib/libipfw2/layer4/Makefile b/lib/libipfw2/layer4/Makefile index eb7337c74d..749349878d 100644 --- a/lib/libipfw2/layer4/Makefile +++ b/lib/libipfw2/layer4/Makefile @@ -1,9 +1,9 @@ SRCDIR= ${.CURDIR}/ -LIB= ipfw2layer4 -SRCS= ipfw2_layer4.c +LIB= ipfw2layer4 +SRCS= ipfw2_layer4.c -INCS= ipfw2_layer4.h +INCS= ipfw2_layer4.h WARNS?= 2 diff --git a/lib/libipfw2/layer4/ipfw2_layer4.c b/lib/libipfw2/layer4/ipfw2_layer4.c index 431b093b55..069f53cd08 100644 --- a/lib/libipfw2/layer4/ipfw2_layer4.c +++ b/lib/libipfw2/layer4/ipfw2_layer4.c @@ -149,4 +149,3 @@ load_module(register_func function, register_keyword keyword) function(MODULE_LAYER4_ID, O_LAYER4_GID, (parser_func)parse_gid, (shower_func)show_gid); } - diff --git a/lib/libipfw2/nat/Makefile b/lib/libipfw2/nat/Makefile index ad8a6bb46b..1dc3bd4af0 100644 --- a/lib/libipfw2/nat/Makefile +++ b/lib/libipfw2/nat/Makefile @@ -1,9 +1,9 @@ SRCDIR= ${.CURDIR}/ -LIB= ipfw2nat -SRCS= ipfw2_nat.c +LIB= ipfw2nat +SRCS= ipfw2_nat.c -INCS= ipfw2_nat.h +INCS= ipfw2_nat.h WARNS?= 2 diff --git a/lib/libipfw2/nat/ipfw2_nat.c b/lib/libipfw2/nat/ipfw2_nat.c index d38181d466..d957eca63f 100644 --- a/lib/libipfw2/nat/ipfw2_nat.c +++ b/lib/libipfw2/nat/ipfw2_nat.c @@ -70,4 +70,3 @@ load_module(register_func function, register_keyword keyword) function(MODULE_NAT_ID, O_NAT_NAT, (parser_func)parse_nat, (shower_func)show_nat); } - diff --git a/sbin/ipfw2/ipfw.h b/sbin/ipfw2/ipfw.h index ad27d65c9f..366bbb02a7 100644 --- a/sbin/ipfw2/ipfw.h +++ b/sbin/ipfw2/ipfw.h @@ -1,13 +1,13 @@ /* * Copyright (c) 2014 The DragonFly Project. All rights reserved. - * + * * This code is derived from software contributed to The DragonFly Project * by Bill Yuan - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: - * + * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright @@ -17,7 +17,7 @@ * 3. Neither the name of The DragonFly Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific, prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS diff --git a/sys/net/dummynet2/Makefile b/sys/net/dummynet2/Makefile index b2ca7446dc..501c0003fa 100644 --- a/sys/net/dummynet2/Makefile +++ b/sys/net/dummynet2/Makefile @@ -1,8 +1,8 @@ # $FreeBSD: src/sys/modules/dummynet/Makefile,v 1.1.2.2 2003/04/08 10:18:00 maxim Exp $ # $DragonFly: src/sys/net/dummynet/Makefile,v 1.7 2008/09/16 12:30:57 sephe Exp $ -KMOD= dummynet2 -SRCS= ip_dummynet2.c +KMOD= dummynet2 +SRCS= ip_dummynet2.c SRCS+= opt_ipdn.h .ifndef BUILDING_WITH_KERNEL diff --git a/sys/net/ipfw2/ip_fw3.h b/sys/net/ipfw2/ip_fw3.h index 48a475ea08..d197d4bfce 100644 --- a/sys/net/ipfw2/ip_fw3.h +++ b/sys/net/ipfw2/ip_fw3.h @@ -528,4 +528,3 @@ typedef void ipfw_basic_append_state_t(struct ipfw_ioc_state *); #endif #endif /* _IPFW2_H */ - diff --git a/sys/net/ipfw2_basic/Makefile b/sys/net/ipfw2_basic/Makefile index a9b2780571..ddbc1f38a9 100644 --- a/sys/net/ipfw2_basic/Makefile +++ b/sys/net/ipfw2_basic/Makefile @@ -1,4 +1,4 @@ -KMOD= ipfw2_basic -SRCS= ip_fw2_basic.c +KMOD= ipfw2_basic +SRCS= ip_fw2_basic.c .include diff --git a/sys/net/ipfw2_basic/ip_fw2_basic.h b/sys/net/ipfw2_basic/ip_fw2_basic.h index 9f3c213157..a994eae119 100644 --- a/sys/net/ipfw2_basic/ip_fw2_basic.h +++ b/sys/net/ipfw2_basic/ip_fw2_basic.h @@ -41,7 +41,7 @@ MALLOC_DEFINE(M_IPFW2_BASIC,"IPFW2_BASIC", "ip_fw2 basic module"); #endif -enum ipfw_basic_opcodes { +enum ipfw_basic_opcodes { O_BASIC_ACCEPT, /* accept */ O_BASIC_DENY, /* deny */ O_BASIC_COUNT, /* count */ @@ -55,7 +55,7 @@ enum ipfw_basic_opcodes { O_BASIC_RECV, /* recv */ O_BASIC_PROTO, /* arg1=protocol */ - O_BASIC_IP_SRC, + O_BASIC_IP_SRC, O_BASIC_IP_SRC_MASK, /* ip = IP/mask*/ O_BASIC_IP_SRC_ME, /* me */ O_BASIC_IP_SRC_SET, /* u32=base, arg1=len, bitmap */ @@ -79,8 +79,8 @@ enum ipfw_basic_opcodes { #define IS_EXPIRED(state) (state->lifetime > 0 && \ (state->timestamp + state->lifetime) < time_second) || \ - ((state->expiry != 0) && (state->expiry < time_second)) + ((state->expiry != 0) && (state->expiry < time_second)) #define IPFW_BASIC_LOADED (ip_fw_basic_loaded) -#endif +#endif diff --git a/sys/net/ipfw2_layer2/Makefile b/sys/net/ipfw2_layer2/Makefile index 4b65b13ed0..a43c3ebed2 100644 --- a/sys/net/ipfw2_layer2/Makefile +++ b/sys/net/ipfw2_layer2/Makefile @@ -1,4 +1,4 @@ -KMOD= ipfw2_layer2 -SRCS= ip_fw2_layer2.c +KMOD= ipfw2_layer2 +SRCS= ip_fw2_layer2.c .include diff --git a/sys/net/ipfw2_layer4/Makefile b/sys/net/ipfw2_layer4/Makefile index 31b03ec6ac..6bcb556a78 100644 --- a/sys/net/ipfw2_layer4/Makefile +++ b/sys/net/ipfw2_layer4/Makefile @@ -1,4 +1,4 @@ -KMOD= ipfw2_layer4 -SRCS= ip_fw2_layer4.c +KMOD= ipfw2_layer4 +SRCS= ip_fw2_layer4.c .include diff --git a/sys/net/ipfw2_nat/Makefile b/sys/net/ipfw2_nat/Makefile index 5a65cc1d28..b44a5872a4 100644 --- a/sys/net/ipfw2_nat/Makefile +++ b/sys/net/ipfw2_nat/Makefile @@ -1,4 +1,4 @@ -KMOD= ipfw2_nat -SRCS= ip_fw2_nat.c +KMOD= ipfw2_nat +SRCS= ip_fw2_nat.c .include diff --git a/sys/net/libalias/HISTORY b/sys/net/libalias/HISTORY index afa94975c7..85a9094774 100644 --- a/sys/net/libalias/HISTORY +++ b/sys/net/libalias/HISTORY @@ -114,7 +114,7 @@ Version 2.2: July, 1997 (cjm) Version 2.3: August 11, 1997 (cjm) - Problem associated with socket file descriptor accumulation in alias_db.c corrected. The sockets - had to be closed when a binding failed. Problem + had to be closed when a binding failed. Problem in code located by Gordon Burditt. Version 2.4: September 1, 1997 (cjm) @@ -140,6 +140,6 @@ Version 3.1: May, 2000 (Erik Salander, erik@whistle.com) FTP servers in passive mode. - Added support for PPTP aliasing. -Version 3.2: July, 2000 (Erik Salander, erik@whistle.com and +Version 3.2: July, 2000 (Erik Salander, erik@whistle.com and Junichi Satoh, junichi@junichi.org) - Added support for streaming media (RTSP and PNA) aliasing. diff --git a/sys/net/libalias/alias.c b/sys/net/libalias/alias.c index 71a8117e54..b1c8f0f430 100644 --- a/sys/net/libalias/alias.c +++ b/sys/net/libalias/alias.c @@ -720,8 +720,8 @@ UdpAliasIn(struct libalias *la, struct ip *pip) int accumulate; int r = 0, error; struct alias_data ad = { - .lnk = lnk, - .oaddr = &original_address, + .lnk = lnk, + .oaddr = &original_address, .aaddr = &alias_address, .aport = &alias_port, .sport = &ud->uh_sport, @@ -734,7 +734,7 @@ UdpAliasIn(struct libalias *la, struct ip *pip) alias_port = ud->uh_dport; ud->uh_dport = GetOriginalPort(lnk); - /* Walk out chain. */ + /* Walk out chain. */ error = find_handler(IN, UDP, la, pip, &ad); /* If UDP checksum is not zero, then adjust since destination port */ @@ -783,7 +783,7 @@ UdpAliasOut(struct libalias *la, struct ip *pip, int create) u_short alias_port; struct in_addr alias_address; struct alias_data ad = { - .lnk = lnk, + .lnk = lnk, .oaddr = NULL, .aaddr = &alias_address, .aport = &alias_port, @@ -795,7 +795,7 @@ UdpAliasOut(struct libalias *la, struct ip *pip, int create) alias_address = GetAliasAddress(lnk); alias_port = GetAliasPort(lnk); - /* Walk out chain. */ + /* Walk out chain. */ error = find_handler(OUT, UDP, la, pip, &ad); /* If UDP checksum is not zero, adjust since source port is */ @@ -845,14 +845,14 @@ TcpAliasIn(struct libalias *la, struct ip *pip) u_short proxy_port; int accumulate, error; - /* - * The init of MANY vars is a bit below, but aliashandlepptpin + /* + * 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, + .lnk = lnk, .oaddr = NULL, .aaddr = NULL, .aport = NULL, @@ -861,7 +861,7 @@ TcpAliasIn(struct libalias *la, struct ip *pip) .maxpktsize = 0 }; - /* Walk out chain. */ + /* Walk out chain. */ error = find_handler(IN, TCP, la, pip, &ad); alias_address = GetAliasAddress(lnk); @@ -871,8 +871,8 @@ TcpAliasIn(struct libalias *la, struct ip *pip) tc->th_dport = GetOriginalPort(lnk); proxy_port = GetProxyPort(lnk); - /* - * Look above, if anyone is going to add find_handler AFTER + /* + * 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. */ @@ -886,7 +886,7 @@ TcpAliasIn(struct libalias *la, struct ip *pip) .dport = &ud->uh_dport, .maxpktsize = 0 }; - + /* Walk out chain. */ error = find_handler(la, pip, &ad); if (error == EHDNOF) @@ -996,7 +996,7 @@ TcpAliasOut(struct libalias *la, struct ip *pip, int maxpacketsize, int create) struct in_addr alias_address; int accumulate; struct alias_data ad = { - .lnk = lnk, + .lnk = lnk, .oaddr = NULL, .aaddr = &alias_address, .aport = &alias_port, @@ -1020,8 +1020,8 @@ TcpAliasOut(struct libalias *la, struct ip *pip, int maxpacketsize, int create) /* Monitor TCP connection state */ TcpMonitorOut(pip, lnk); - - /* Walk out chain. */ + + /* Walk out chain. */ error = find_handler(OUT, TCP, la, pip, &ad); /* Adjust TCP checksum since source port is being aliased */ @@ -1164,7 +1164,7 @@ LibAliasGetFragment(struct libalias *la, char *ptr) GetFragmentPtr(lnk, &fptr); SetFragmentPtr(lnk, NULL); SetExpire(lnk, 0); /* Deletes link */ - } else + } else fptr = NULL; LIBALIAS_UNLOCK(la); @@ -1234,7 +1234,7 @@ LibAliasInLocked(struct libalias *la, char *ptr, int maxpacketsize) /* Defense against mangled packets */ if (ntohs(pip->ip_len) > maxpacketsize || (pip->ip_hl << 2) > maxpacketsize) { - iresult = PKT_ALIAS_IGNORED; + iresult = PKT_ALIAS_IGNORED; goto getout; } @@ -1253,23 +1253,23 @@ LibAliasInLocked(struct libalias *la, char *ptr, int maxpacketsize) case IPPROTO_GRE: { int error; struct alias_data ad = { - .lnk = NULL, - .oaddr = NULL, + .lnk = NULL, + .oaddr = NULL, .aaddr = NULL, .aport = NULL, .sport = NULL, .dport = NULL, - .maxpktsize = 0 + .maxpktsize = 0 }; - - /* Walk out chain. */ + + /* 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; @@ -1395,15 +1395,15 @@ LibAliasOutLocked(struct libalias *la, char *ptr, /* valid IP packet */ case IPPROTO_GRE: { int error; struct alias_data ad = { - .lnk = NULL, - .oaddr = NULL, + .lnk = NULL, + .oaddr = NULL, .aaddr = NULL, .aport = NULL, .sport = NULL, .dport = NULL, - .maxpktsize = 0 + .maxpktsize = 0 }; - /* Walk out chain. */ + /* Walk out chain. */ error = find_handler(OUT, IP, la, pip, &ad); if (error == 0) iresult = PKT_ALIAS_OK; @@ -1549,7 +1549,7 @@ LibAliasRefreshModules(void) for (;;) { fgets(buf, 256, fd); - if feof(fd) + if feof(fd) break; len = strlen(buf); if (len > 1) { @@ -1615,10 +1615,10 @@ LibAliasUnLoadAllModule(void) struct proto_handler *p; /* Unload all modules then reload everything. */ - while ((p = first_handler()) != NULL) { + while ((p = first_handler()) != NULL) { detach_handler(p); } - while ((t = walk_dll_chain()) != NULL) { + while ((t = walk_dll_chain()) != NULL) { dlclose(t->handle); kfree(t,M_ALIAS); } @@ -1643,17 +1643,17 @@ LibAliasUnLoadAllModule(void) struct mbuf * m_megapullup(struct mbuf *m, int len) { struct mbuf *mcl; - + if (len > m->m_pkthdr.len) goto bad; - + /* Do not reallocate packet if it is sequentional, * writable and has some extra space for expansion. * XXX: Constant 100bytes is completely empirical. */ #define RESERVE 100 if (m->m_next == NULL && M_WRITABLE(m) && M_TRAILINGSPACE(m) >= RESERVE) return (m); - /* + /* if (len <= MCLBYTES - RESERVE) { mcl = m_getcl(M_DONTWAIT, MT_DATA, M_PKTHDR); } else if (len < MJUM16BYTES) { @@ -1678,7 +1678,7 @@ m_megapullup(struct mbuf *m, int len) { m_copydata(m, 0, len, mtod(mcl, caddr_t)); mcl->m_len = mcl->m_pkthdr.len = len; m_freem(m); - + return (mcl); bad: m_freem(m); diff --git a/sys/net/libalias/alias_cuseeme.c b/sys/net/libalias/alias_cuseeme.c index b0e4a7d181..7dff00c2e3 100644 --- a/sys/net/libalias/alias_cuseeme.c +++ b/sys/net/libalias/alias_cuseeme.c @@ -1,7 +1,7 @@ /*- * Copyright (c) 1998 Brian Somers - * with the aid of code written by - * Junichi SATOH 1996, 1997. + * with the aid of code written by + * Junichi SATOH 1996, 1997. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/net/libalias/alias_dummy.c b/sys/net/libalias/alias_dummy.c index e68d116c2f..fe4a6aea7b 100644 --- a/sys/net/libalias/alias_dummy.c +++ b/sys/net/libalias/alias_dummy.c @@ -150,4 +150,3 @@ AliasHandleDummy(struct libalias *la, struct ip *ip, struct alias_data *ah) { ; /* Dummy. */ } - diff --git a/sys/net/libalias/alias_ftp.c b/sys/net/libalias/alias_ftp.c index fe153f53f9..0e5eb788cb 100644 --- a/sys/net/libalias/alias_ftp.c +++ b/sys/net/libalias/alias_ftp.c @@ -99,14 +99,14 @@ __FBSDID("$FreeBSD: src/sys/netinet/libalias/alias_ftp.c,v 1.29.2.1.2.1 2008/11/ #define FTP_CONTROL_PORT_NUMBER 21 static void -AliasHandleFtpOut(struct libalias *, struct ip *, struct alias_link *, +AliasHandleFtpOut(struct libalias *, struct ip *, struct alias_link *, int maxpacketsize); -static int +static int fingerprint(struct libalias *la, struct ip *pip, struct alias_data *ah) { - if (ah->dport == NULL || ah->sport == NULL || ah->lnk == NULL || + if (ah->dport == NULL || ah->sport == NULL || ah->lnk == NULL || ah->maxpktsize == 0) return (-1); if (ntohs(*ah->dport) == FTP_CONTROL_PORT_NUMBER @@ -115,22 +115,22 @@ fingerprint(struct libalias *la, struct ip *pip, struct alias_data *ah) return (-1); } -static int +static int protohandler(struct libalias *la, struct ip *pip, struct alias_data *ah) { - + AliasHandleFtpOut(la, pip, ah->lnk, ah->maxpktsize); return (0); } struct proto_handler handlers[] = { - { - .pri = 80, - .dir = OUT, - .proto = TCP, - .fingerprint = &fingerprint, + { + .pri = 80, + .dir = OUT, + .proto = TCP, + .fingerprint = &fingerprint, .protohandler = &protohandler - }, + }, { EOH } }; @@ -139,7 +139,7 @@ mod_handler(module_t mod, int type, void *data) { int error; - switch (type) { + switch (type) { case MOD_LOAD: error = 0; LibAliasAttachHandlers(handlers); diff --git a/sys/net/libalias/alias_irc.c b/sys/net/libalias/alias_irc.c index 98c5322879..668c8f0a5f 100644 --- a/sys/net/libalias/alias_irc.c +++ b/sys/net/libalias/alias_irc.c @@ -88,14 +88,14 @@ char *newpacket; #define DBprintf(a) static void -AliasHandleIrcOut(struct libalias *, struct ip *, struct alias_link *, +AliasHandleIrcOut(struct libalias *, struct ip *, struct alias_link *, int maxpacketsize); -static int +static int fingerprint(struct libalias *la, struct ip *pip, struct alias_data *ah) { - if (ah->dport == NULL || ah->dport == NULL || ah->lnk == NULL || + if (ah->dport == NULL || ah->dport == NULL || ah->lnk == NULL || ah->maxpktsize == 0) return (-1); if (ntohs(*ah->dport) == IRC_CONTROL_PORT_NUMBER_1 @@ -104,7 +104,7 @@ fingerprint(struct libalias *la, struct ip *pip, struct alias_data *ah) return (-1); } -static int +static int protohandler(struct libalias *la, struct ip *pip, struct alias_data *ah) { @@ -117,13 +117,13 @@ protohandler(struct libalias *la, struct ip *pip, struct alias_data *ah) } struct proto_handler handlers[] = { - { - .pri = 90, - .dir = OUT, - .proto = TCP, - .fingerprint = &fingerprint, + { + .pri = 90, + .dir = OUT, + .proto = TCP, + .fingerprint = &fingerprint, .protohandler = &protohandler - }, + }, { EOH } }; @@ -148,7 +148,7 @@ mod_handler(module_t mod, int type, void *data) } #ifdef _KERNEL -static +static #endif moduledata_t alias_mod = { "alias_irc", mod_handler, NULL diff --git a/sys/net/libalias/alias_mod.h b/sys/net/libalias/alias_mod.h index 0f500c1cda..54b70673bc 100644 --- a/sys/net/libalias/alias_mod.h +++ b/sys/net/libalias/alias_mod.h @@ -38,30 +38,30 @@ /* Protocol handlers struct & function. */ /* Packet flow direction. */ -#define IN 1 -#define OUT 2 +#define IN 1 +#define OUT 2 /* Working protocol. */ #define IP 1 #define TCP 2 #define UDP 4 -/* +/* * Data passed to protocol handler module, it must be filled * right before calling find_handler() to determine which * module is elegible to be called. */ -struct alias_data { - struct alias_link *lnk; +struct alias_data { + struct alias_link *lnk; struct in_addr *oaddr; /* Original address. */ - struct in_addr *aaddr; /* Alias address. */ + struct in_addr *aaddr; /* Alias address. */ uint16_t *aport; /* Alias port. */ uint16_t *sport, *dport; /* Source & destination port */ uint16_t maxpktsize; /* Max packet size. */ -}; +}; -/* +/* * This structure contains all the information necessary to make * a protocol handler correctly work. */ @@ -69,29 +69,29 @@ struct alias_data { struct proto_handler { u_int pri; /* Handler priority. */ int16_t dir; /* Flow direction. */ - uint8_t proto; /* Working protocol. */ + uint8_t proto; /* Working protocol. */ int (*fingerprint)(struct libalias *la, /* Fingerprint * function. */ struct ip *pip, struct alias_data *ah); int (*protohandler)(struct libalias *la, /* Aliasing * function. */ - struct ip *pip, struct alias_data *ah); + struct ip *pip, struct alias_data *ah); LIST_ENTRY(proto_handler) entries; }; -/* +/* * Used only in userland when libalias needs to keep track of all * module loaded. In kernel land (kld mode) we don't need to care * care about libalias modules cause it's kld to do it for us. */ #define DLL_LEN 32 -struct dll { +struct dll { char name[DLL_LEN]; /* Name of module. */ - void *handle; /* + void *handle; /* * Ptr to shared obj obtained through * dlopen() - use this ptr to get access - * to any symbols from a loaded module - * via dlsym(). + * to any symbols from a loaded module + * via dlsym(). */ SLIST_ENTRY(dll) next; }; @@ -103,7 +103,7 @@ void handler_chain_destroy(void); int LibAliasAttachHandlers(struct proto_handler *); int LibAliasDetachHandlers(struct proto_handler *); int detach_handler(struct proto_handler *); -int find_handler(int8_t, int8_t, struct libalias *, +int find_handler(int8_t, int8_t, struct libalias *, struct ip *, struct alias_data *); struct proto_handler *first_handler(void); @@ -118,7 +118,7 @@ struct dll *walk_dll_chain(void); /* End of handlers. */ #define EOH -1 -/* +/* * Some defines borrowed from sys/module.h used to compile a kld * in userland as a shared lib. */ @@ -132,7 +132,7 @@ typedef enum modeventtype { MOD_SHUTDOWN, MOD_QUIESCE } modeventtype_t; - + typedef struct module *module_t; typedef int (*modeventhand_t)(module_t, int /* modeventtype_t */, void *); diff --git a/sys/net/libalias/alias_nbt.c b/sys/net/libalias/alias_nbt.c index 7e289c566c..1170703230 100644 --- a/sys/net/libalias/alias_nbt.c +++ b/sys/net/libalias/alias_nbt.c @@ -69,38 +69,38 @@ __FBSDID("$FreeBSD: src/sys/netinet/libalias/alias_nbt.c,v 1.20.6.1 2008/11/25 0 #define NETBIOS_DGM_PORT_NUMBER 138 static int -AliasHandleUdpNbt(struct libalias *, struct ip *, struct alias_link *, +AliasHandleUdpNbt(struct libalias *, struct ip *, struct alias_link *, struct in_addr *, u_short); static int AliasHandleUdpNbtNS(struct libalias *, struct ip *, struct alias_link *, struct in_addr *, u_short *, struct in_addr *, u_short *); -static int +static int fingerprint1(struct libalias *la, struct ip *pip, struct alias_data *ah) { - if (ah->dport == NULL || ah->sport == NULL || ah->lnk == NULL || + if (ah->dport == NULL || ah->sport == NULL || ah->lnk == NULL || ah->aaddr == NULL || ah->aport == NULL) return (-1); if (ntohs(*ah->dport) == NETBIOS_DGM_PORT_NUMBER - || ntohs(*ah->sport) == NETBIOS_DGM_PORT_NUMBER) + || ntohs(*ah->sport) == NETBIOS_DGM_PORT_NUMBER) return (0); return (-1); } -static int +static int protohandler1(struct libalias *la, struct ip *pip, struct alias_data *ah) { - + AliasHandleUdpNbt(la, pip, ah->lnk, ah->aaddr, *ah->aport); return (0); } -static int +static int fingerprint2(struct libalias *la, struct ip *pip, struct alias_data *ah) { - if (ah->dport == NULL || ah->sport == NULL || ah->lnk == NULL || + if (ah->dport == NULL || ah->sport == NULL || ah->lnk == NULL || ah->aaddr == NULL || ah->aport == NULL) return (-1); if (ntohs(*ah->dport) == NETBIOS_NS_PORT_NUMBER @@ -109,19 +109,19 @@ fingerprint2(struct libalias *la, struct ip *pip, struct alias_data *ah) return (-1); } -static int +static int protohandler2in(struct libalias *la, struct ip *pip, struct alias_data *ah) { - + AliasHandleUdpNbtNS(la, pip, ah->lnk, ah->aaddr, ah->aport, ah->oaddr, ah->dport); return (0); } -static int +static int protohandler2out(struct libalias *la, struct ip *pip, struct alias_data *ah) { - + AliasHandleUdpNbtNS(la, pip, ah->lnk, &pip->ip_src, ah->sport, ah->aaddr, ah->aport); return (0); @@ -129,27 +129,27 @@ protohandler2out(struct libalias *la, struct ip *pip, struct alias_data *ah) /* Kernel module definition. */ struct proto_handler handlers[] = { - { - .pri = 130, - .dir = IN|OUT, - .proto = UDP, - .fingerprint = &fingerprint1, + { + .pri = 130, + .dir = IN|OUT, + .proto = UDP, + .fingerprint = &fingerprint1, .protohandler = &protohandler1 - }, - { - .pri = 140, - .dir = IN, - .proto = UDP, - .fingerprint = &fingerprint2, + }, + { + .pri = 140, + .dir = IN, + .proto = UDP, + .fingerprint = &fingerprint2, .protohandler = &protohandler2in - }, - { - .pri = 140, - .dir = OUT, - .proto = UDP, - .fingerprint = &fingerprint2, + }, + { + .pri = 140, + .dir = OUT, + .proto = UDP, + .fingerprint = &fingerprint2, .protohandler = &protohandler2out - }, + }, { EOH } }; @@ -174,7 +174,7 @@ mod_handler(module_t mod, int type, void *data) } #ifdef _KERNEL -static +static #endif moduledata_t alias_mod = { "alias_nbt", mod_handler, NULL diff --git a/sys/net/libalias/alias_pptp.c b/sys/net/libalias/alias_pptp.c index 85d75e433c..1284bb1ba5 100644 --- a/sys/net/libalias/alias_pptp.c +++ b/sys/net/libalias/alias_pptp.c @@ -78,7 +78,7 @@ AliasHandlePptpGreOut(struct libalias *, struct ip *); static int AliasHandlePptpGreIn(struct libalias *, struct ip *); -static int +static int fingerprint(struct libalias *la, struct ip *pip, struct alias_data *ah) { @@ -90,30 +90,30 @@ fingerprint(struct libalias *la, struct ip *pip, struct alias_data *ah) return (-1); } -static int +static int fingerprintgre(struct libalias *la, struct ip *pip, struct alias_data *ah) { return (0); } -static int +static int protohandlerin(struct libalias *la, struct ip *pip, struct alias_data *ah) { - + AliasHandlePptpIn(la, pip, ah->lnk); return (0); } -static int +static int protohandlerout(struct libalias *la, struct ip *pip, struct alias_data *ah) { - + AliasHandlePptpOut(la, pip, ah->lnk); return (0); } -static int +static int protohandlergrein(struct libalias *la, struct ip *pip, struct alias_data *ah) { @@ -123,7 +123,7 @@ protohandlergrein(struct libalias *la, struct ip *pip, struct alias_data *ah) return (-1); } -static int +static int protohandlergreout(struct libalias *la, struct ip *pip, struct alias_data *ah) { @@ -134,39 +134,39 @@ protohandlergreout(struct libalias *la, struct ip *pip, struct alias_data *ah) /* Kernel module definition. */ struct proto_handler handlers[] = { - { - .pri = 200, - .dir = IN, - .proto = TCP, - .fingerprint = &fingerprint, + { + .pri = 200, + .dir = IN, + .proto = TCP, + .fingerprint = &fingerprint, .protohandler = &protohandlerin }, - { - .pri = 210, - .dir = OUT, - .proto = TCP, - .fingerprint = &fingerprint, + { + .pri = 210, + .dir = OUT, + .proto = TCP, + .fingerprint = &fingerprint, .protohandler = &protohandlerout }, -/* - * WATCH OUT!!! these 2 handlers NEED a priority of INT_MAX (highest possible) +/* + * WATCH OUT!!! these 2 handlers NEED a priority of INT_MAX (highest possible) * cause they will ALWAYS process packets, so they must be the last one * in chain: look fingerprintgre() above. */ - { - .pri = INT_MAX, - .dir = IN, - .proto = IP, - .fingerprint = &fingerprintgre, + { + .pri = INT_MAX, + .dir = IN, + .proto = IP, + .fingerprint = &fingerprintgre, .protohandler = &protohandlergrein }, - { - .pri = INT_MAX, - .dir = OUT, - .proto = IP, - .fingerprint = &fingerprintgre, + { + .pri = INT_MAX, + .dir = OUT, + .proto = IP, + .fingerprint = &fingerprintgre, .protohandler = &protohandlergreout - }, + }, { EOH } }; static int @@ -190,7 +190,7 @@ mod_handler(module_t mod, int type, void *data) } #ifdef _KERNEL -static +static #endif moduledata_t alias_mod = { "alias_pptp", mod_handler, NULL diff --git a/sys/net/libalias/alias_smedia.c b/sys/net/libalias/alias_smedia.c index 136bb59230..c2e6ca7fef 100644 --- a/sys/net/libalias/alias_smedia.c +++ b/sys/net/libalias/alias_smedia.c @@ -129,16 +129,16 @@ __FBSDID("$FreeBSD: src/sys/netinet/libalias/alias_smedia.c,v 1.17.6.1 2008/11/2 #define TFTP_PORT_NUMBER 69 static void -AliasHandleRtspOut(struct libalias *, struct ip *, struct alias_link *, +AliasHandleRtspOut(struct libalias *, struct ip *, struct alias_link *, int maxpacketsize); -static int +static int fingerprint(struct libalias *la, struct ip *pip, struct alias_data *ah) { if (ah->dport != NULL && ah->aport != NULL && ah->sport != NULL && ntohs(*ah->dport) == TFTP_PORT_NUMBER) return (0); - if (ah->dport == NULL || ah->sport == NULL || ah->lnk == NULL || + if (ah->dport == NULL || ah->sport == NULL || ah->lnk == NULL || ah->maxpktsize == 0) return (-1); if (ntohs(*ah->dport) == RTSP_CONTROL_PORT_NUMBER_1 @@ -149,25 +149,25 @@ fingerprint(struct libalias *la, struct ip *pip, struct alias_data *ah) return (-1); } -static int +static int protohandler(struct libalias *la, struct ip *pip, struct alias_data *ah) { - + if (ntohs(*ah->dport) == TFTP_PORT_NUMBER) FindRtspOut(la, pip->ip_src, pip->ip_dst, *ah->sport, *ah->aport, IPPROTO_UDP); - else AliasHandleRtspOut(la, pip, ah->lnk, ah->maxpktsize); + else AliasHandleRtspOut(la, pip, ah->lnk, ah->maxpktsize); return (0); } struct proto_handler handlers[] = { - { - .pri = 100, - .dir = OUT, + { + .pri = 100, + .dir = OUT, .proto = TCP|UDP, - .fingerprint = &fingerprint, + .fingerprint = &fingerprint, .protohandler = &protohandler - }, + }, { EOH } }; @@ -192,7 +192,7 @@ mod_handler(module_t mod, int type, void *data) } #ifdef _KERNEL -static +static #endif moduledata_t alias_mod = { "alias_smedia", mod_handler, NULL -- 2.11.4.GIT