summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sbin/Makefile2
-rw-r--r--sbin/ip6fw/Makefile7
-rw-r--r--sbin/ip6fw/ip6fw.8582
-rw-r--r--sbin/ip6fw/ip6fw.c1453
-rw-r--r--sbin/ip6fw/sample.sh28
-rw-r--r--sys/conf/files1
-rw-r--r--sys/conf/options4
-rw-r--r--sys/modules/Makefile1
-rw-r--r--sys/modules/ip6fw/Makefile17
-rw-r--r--sys/net/net_osdep.h4
-rw-r--r--sys/netinet/ip_fw2.c1
-rw-r--r--sys/netinet6/ip6_forward.c17
-rw-r--r--sys/netinet6/ip6_fw.c1318
-rw-r--r--sys/netinet6/ip6_fw.h231
-rw-r--r--sys/netinet6/ip6_input.c23
-rw-r--r--sys/netinet6/ip6_output.c58
16 files changed, 2 insertions, 3745 deletions
diff --git a/sbin/Makefile b/sbin/Makefile
index a2daff4..d96d29a 100644
--- a/sbin/Makefile
+++ b/sbin/Makefile
@@ -38,7 +38,6 @@ SUBDIR= adjkerntz \
gvinum \
ifconfig \
init \
- ${_ip6fw} \
${_ipf} \
ipfw \
kldconfig \
@@ -112,7 +111,6 @@ _pflogd= pflogd
.endif
.if ${MK_INET6} != "no"
-_ip6fw= ip6fw
_ping6= ping6
.endif
diff --git a/sbin/ip6fw/Makefile b/sbin/ip6fw/Makefile
deleted file mode 100644
index 17f330d..0000000
--- a/sbin/ip6fw/Makefile
+++ /dev/null
@@ -1,7 +0,0 @@
-# $FreeBSD$
-
-PROG= ip6fw
-WARNS?= 2
-MAN= ip6fw.8
-
-.include <bsd.prog.mk>
diff --git a/sbin/ip6fw/ip6fw.8 b/sbin/ip6fw/ip6fw.8
deleted file mode 100644
index 9d296cf..0000000
--- a/sbin/ip6fw/ip6fw.8
+++ /dev/null
@@ -1,582 +0,0 @@
-.\"
-.\" $FreeBSD$
-.\"
-.\" $KAME$
-.\"
-.\" Copyright (C) 1998, 1999, 2000 and 2001 WIDE Project.
-.\" All rights reserved.
-.\"
-.\" 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
-.\" notice, this list of conditions and the following disclaimer in the
-.\" documentation and/or other materials provided with the distribution.
-.\" 3. Neither the name of the 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 PROJECT AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.Dd March 13, 2000
-.Dt IP6FW 8
-.Os
-.Sh NAME
-.Nm ip6fw
-.Nd controlling utility for IPv6 firewall
-.Sh SYNOPSIS
-.Nm
-.Op Fl nq
-.Oo
-.Fl p Ar preproc
-.Oo Fl D
-.Ar macro Ns Op = Ns Ar value
-.Oc
-.Op Fl U Ar macro
-.Oc
-.Ar pathname
-.Nm
-.Op Fl n
-.Op Fl f | Fl q
-flush
-.Nm
-.Op Fl nq
-zero
-.Op Ar number ...
-.Nm
-.Op Fl n
-delete
-.Ar number ...
-.Nm
-.Op Fl aftN
-list
-.Op Ar number ...
-.Nm
-.Op Fl ftN
-show
-.Op Ar number ...
-.Nm
-.Op Fl nq
-add
-.Op Ar number
-.Ar action
-.Op log
-.Ar proto
-from
-.Ar src
-to
-.Ar dst
-.Op via Ar name | ipv6no
-.Op Ar options
-.Sh DESCRIPTION
-To ease configuration, rules can be put into a file which is
-processed using
-.Nm
-as shown in the first synopsis line.
-An absolute
-.Ar pathname
-must be used.
-The file
-will be read line by line and applied as arguments to the
-.Nm
-utility.
-.Pp
-Optionally, a preprocessor can be specified using
-.Fl p Ar preproc
-where
-.Ar pathname
-is to be piped through.
-Useful preprocessors include
-.Xr cpp 1
-and
-.Xr m4 1 .
-If
-.Ar preproc
-does not start with a slash
-.Pq Ql /
-as its first character, the usual
-.Ev PATH
-name search is performed.
-Care should be taken with this in environments where not all
-file systems are mounted (yet) by the time
-.Nm
-is being run (e.g.\& when they are mounted over NFS).
-Once
-.Fl p
-has been specified, optional
-.Fl D
-and
-.Fl U
-specifications can follow and will be passed on to the preprocessor.
-This allows for flexible configuration files (like conditionalizing
-them on the local hostname) and the use of macros to centralize
-frequently required arguments like IP addresses.
-.Pp
-The
-.Nm
-code works by going through the rule-list for each packet,
-until a match is found.
-All rules have two associated counters, a packet count and
-a byte count.
-These counters are updated when a packet matches the rule.
-.Pp
-The rules are ordered by a
-.Dq line-number
-from 1 to 65534 that is used
-to order and delete rules.
-Rules are tried in increasing order, and the
-first rule that matches a packet applies.
-Multiple rules may share the same number and apply in
-the order in which they were added.
-.Pp
-If a rule is added without a number, it is numbered 100 higher
-than the previous rule.
-If the highest defined rule number is
-greater than 65434, new rules are appended to the last rule.
-.Pp
-The delete operation deletes the first rule with number
-.Ar number ,
-if any.
-.Pp
-The list command prints out the current rule set.
-.Pp
-The show command is equivalent to `ip6fw -a list'.
-.Pp
-The zero operation zeroes the counters associated with rule number
-.Ar number .
-.Pp
-The flush operation removes all rules.
-.Pp
-Any command beginning with a
-.Sq # ,
-or being all blank, is ignored.
-.Pp
-One rule is always present:
-.Bd -literal -offset center
-65535 deny all from any to any
-.Ed
-.Pp
-This rule is the default policy, i.e., do not allow anything at all.
-Your job in setting up rules is to modify this policy to match your
-needs.
-.Pp
-The following options are available:
-.Bl -tag -width flag
-.It Fl a
-While listing, show counter values.
-See also
-.Dq show
-command.
-.It Fl f
-Do not ask for confirmation for commands that can cause problems if misused
-(ie; flush).
-.Ar Note ,
-if there is no tty associated with the process, this is implied.
-.It Fl n
-Only check syntax of the command strings,
-without actually passing them into the kernel.
-.It Fl q
-While adding, zeroing or flushing, be quiet about actions (implies '-f').
-This is useful for adjusting rules by executing multiple ip6fw commands in a
-script (e.g.\& sh /etc/rc.firewall), or by processing a file of many ip6fw rules,
-across a remote login session.
-If a flush is performed in normal
-(verbose) mode, it prints a message.
-Because all rules are flushed, the
-message cannot be delivered to the login session, the login session is
-closed and the remainder of the ruleset is not processed.
-Access to the
-console is required to recover.
-.It Fl t
-While listing, show last match timestamp.
-.It Fl N
-Try to resolve addresses and service names in output.
-.El
-.Pp
-.Ar action :
-.Bl -hang -offset flag -width 16n
-.It Ar allow
-Allow packets that match rule.
-The search terminates.
-Aliases are
-.Ar pass ,
-.Ar permit ,
-and
-.Ar accept .
-.It Ar deny
-Discard packets that match this rule.
-The search terminates.
-.Ar Drop
-is an alias for
-.Ar deny .
-.It Ar reject
-(Deprecated.)
-Discard packets that match this rule, and try to send an ICMPv6
-host unreachable notice.
-The search terminates.
-.It Ar unreach code
-Discard packets that match this rule, and try to send an ICMPv6
-unreachable notice with code
-.Ar code ,
-where
-.Ar code
-is a number from zero to 255, or one of these aliases:
-.Ar noroute ,
-.Ar admin ,
-.Ar notneighbor ,
-.Ar addr ,
-or
-.Ar noport ,
-The search terminates.
-.It Ar reset
-TCP packets only.
-Discard packets that match this rule,
-and try to send a TCP reset (RST) notice.
-The search terminates
-.It Ar count
-Update counters for all packets that match rule.
-The search continues with the next rule.
-.It Ar skipto number
-Skip all subsequent rules numbered less than
-.Ar number .
-The search continues with the first rule numbered
-.Ar number
-or higher.
-.El
-.Pp
-If the kernel was compiled with
-.Dv IPV6FIREWALL_VERBOSE ,
-then when a packet matches a rule with the
-.Dq log
-keyword or a clear/resetlog is performed, a message will be logged to
-.Xr syslogd 8 ,
-or, if that fails, to the console.
-If the kernel was compiled with the
-.Dv IPV6FIREWALL_VERBOSE_LIMIT
-option, then logging will cease after the number of packets
-specified by the option are received for that particular
-chain entry.
-When this limit is reached, the limit and rule number will be logged.
-Logging may then be re-enabled by clearing
-the packet counter for that entry.
-.Pp
-The
-.Xr syslogd 8
-logging and the default log limit are adjustable dynamically through the
-.Xr sysctl 8
-interface.
-.Pp
-.Ar proto :
-.Bl -hang -offset flag -width 16n
-.It Ar ipv6
-All packets match.
-The alias
-.Ar all
-has the same effect.
-.It Ar tcp
-Only TCP packets match.
-.It Ar udp
-Only UDP packets match.
-.It Ar ipv6-icmp
-Only ICMPv6 packets match.
-.It Ar <number|name>
-Only packets for the specified protocol matches (see
-.Pa /etc/protocols
-for a complete list).
-.El
-.Pp
-.Ar src
-and
-.Ar dst :
-.Bl -hang -offset flag
-.It Ar <address/prefixlen>
-.Op Ar ports
-.El
-.Pp
-The
-.Em <address/prefixlen>
-may be specified as:
-.Bl -hang -offset flag -width 16n
-.It Ar ipv6no
-An ipv6number of the form
-.Li fec0::1:2:3:4 .
-.It Ar ipv6no/prefixlen
-An ipv6number with a prefix length of the form
-.Li fec0::1:2:3:4/112 .
-.El
-.Pp
-The sense of the match can be inverted by preceding an address with the
-.Dq not
-modifier, causing all other addresses to be matched instead.
-This
-does not affect the selection of port numbers.
-.Pp
-With the TCP and UDP protocols, optional
-.Em ports
-may be specified as:
-.Pp
-.Bl -hang -offset flag
-.It Ns {port|port-port} Ns Op ,port Ns Op ,...
-.El
-.Pp
-Service names (from
-.Pa /etc/services )
-may be used instead of numeric port values.
-A range may only be specified as the first value,
-and the length of the port list is limited to
-.Dv IPV6_FW_MAX_PORTS
-(as defined in
-.In netinet6/ip6_fw.h )
-ports.
-.Pp
-Fragmented packets which have a non-zero offset (i.e., not the first
-fragment) will never match a rule which has one or more port
-specifications.
-See the
-.Ar frag
-option for details on matching fragmented packets.
-.Pp
-Rules can apply to packets when they are incoming, or outgoing, or both.
-The
-.Ar in
-keyword indicates the rule should only match incoming packets.
-The
-.Ar out
-keyword indicates the rule should only match outgoing packets.
-.Pp
-To match packets going through a certain interface, specify
-the interface using
-.Ar via :
-.Bl -hang -offset flag -width 16n
-.It Ar via ifX
-Packet must be going through interface
-.Ar ifX .
-.It Ar via if*
-Packet must be going through interface
-.Ar ifX ,
-where X is any unit number.
-.It Ar via any
-Packet must be going through
-.Em some
-interface.
-.It Ar via ipv6no
-Packet must be going through the interface having IPv6 address
-.Ar ipv6no .
-.El
-.Pp
-The
-.Ar via
-keyword causes the interface to always be checked.
-If
-.Ar recv
-or
-.Ar xmit
-is used instead of
-.Ar via ,
-then the only receive or transmit interface (respectively) is checked.
-By specifying both, it is possible to match packets based on both receive
-and transmit interface, e.g.:
-.Pp
-.Dl "ip6fw add 100 deny ip from any to any out recv ed0 xmit ed1"
-.Pp
-The
-.Ar recv
-interface can be tested on either incoming or outgoing packets, while the
-.Ar xmit
-interface can only be tested on outgoing packets.
-So
-.Ar out
-is required (and
-.Ar in
-invalid) whenever
-.Ar xmit
-is used.
-Specifying
-.Ar via
-together with
-.Ar xmit
-or
-.Ar recv
-is invalid.
-.Pp
-A packet may not have a receive or transmit interface: packets originating
-from the local host have no receive interface, while packets destined for
-the local host have no transmit interface.
-.Pp
-Additional
-.Ar options :
-.Bl -hang -offset flag -width 16n
-.It frag
-Matches if the packet is a fragment and this is not the first fragment
-of the datagram.
-.Ar frag
-may not be used in conjunction with either
-.Ar tcpflags
-or TCP/UDP port specifications.
-.It in
-Matches if this packet was on the way in.
-.It out
-Matches if this packet was on the way out.
-.It ipv6options Ar spec
-Matches if the IPv6 header contains the comma separated list of
-options specified in
-.Ar spec .
-The supported IPv6 options are:
-.Ar hopopt
-(hop-by-hop options header),
-.Ar route
-(routing header),
-.Ar frag
-(fragment header),
-.Ar esp
-(encapsulating security payload),
-.Ar ah
-(authentication header),
-.Ar nonxt
-(no next header), and
-.Ar opts
-(destination options header).
-The absence of a particular option may be denoted
-with a
-.Dq \&!
-.Em ( "not working yet" ) .
-.It established
-Matches packets that have the RST or ACK bits set.
-TCP packets only.
-.It setup
-Matches packets that have the SYN bit set but no ACK bit.
-TCP packets only.
-.It tcpflags Ar spec
-Matches if the TCP header contains the comma separated list of
-flags specified in
-.Ar spec .
-The supported TCP flags are:
-.Ar fin ,
-.Ar syn ,
-.Ar rst ,
-.Ar psh ,
-.Ar ack ,
-and
-.Ar urg .
-The absence of a particular flag may be denoted
-with a
-.Dq \&! .
-A rule which contains a
-.Ar tcpflags
-specification can never match a fragmented packet which has
-a non-zero offset.
-See the
-.Ar frag
-option for details on matching fragmented packets.
-.It icmptypes Ar types
-Matches if the ICMPv6 type is in the list
-.Ar types .
-The list may be specified as any combination of ranges
-or individual types separated by commas.
-.El
-.Sh CHECKLIST
-Here are some important points to consider when designing your
-rules:
-.Bl -bullet -offset flag
-.It
-Remember that you filter both packets going in and out.
-Most connections need packets going in both directions.
-.It
-Remember to test very carefully.
-It is a good idea to be near the console when doing this.
-.It
-Do not forget the loopback interface.
-.El
-.Sh FINE POINTS
-There is one kind of packet that the firewall will always discard,
-that is an IPv6 fragment with a fragment offset of one.
-This is a valid packet, but it only has one use, to try to circumvent
-firewalls.
-.Pp
-If you are logged in over a network, loading the KLD version of
-.Nm
-is probably not as straightforward as you would think
-.Em ( "not supported" ) .
-I recommend this command line:
-.Bd -literal -offset center
-kldload ip6fw && \e
-ip6fw add 32000 allow all from any to any
-.Ed
-.Pp
-Along the same lines, doing an
-.Bd -literal -offset center
-ip6fw flush
-.Ed
-.Pp
-in similar surroundings is also a bad idea.
-.Sh PACKET DIVERSION
-not supported.
-.Sh EXAMPLES
-This command adds an entry which denies all tcp packets from
-.Em hacker.evil.org
-to the telnet port of
-.Em wolf.tambov.su
-from being forwarded by the host:
-.Pp
-.Dl ip6fw add deny tcp from hacker.evil.org to wolf.tambov.su 23
-.Pp
-This one disallows any connection from the entire hackers network to
-my host:
-.Pp
-.Dl ip6fw add deny all from fec0::123:45:67:0/112 to my.host.org
-.Pp
-Here is a good usage of the list command to see accounting records
-and timestamp information:
-.Pp
-.Dl ip6fw -at l
-.Pp
-or in short form without timestamps:
-.Pp
-.Dl ip6fw -a l
-.Sh SEE ALSO
-.Xr ip 4 ,
-.Xr ipfirewall 4 ,
-.Xr protocols 5 ,
-.Xr services 5 ,
-.Xr reboot 8 ,
-.Xr sysctl 8 ,
-.Xr syslogd 8
-.Sh HISTORY
-A
-.Nm
-utility first appeared in
-.Fx 4.0 .
-.Sh AUTHORS
-.An Ugen J. S. Antsilevich ,
-.An Poul-Henning Kamp ,
-.An Alex Nash ,
-.An Archie Cobbs .
-.Pp
-.An -nosplit
-API based upon code written by
-.An Daniel Boulet
-for BSDI.
-.Sh BUGS
-.Em WARNING!!WARNING!!WARNING!!WARNING!!WARNING!!WARNING!!WARNING!!
-.Pp
-This program can put your computer in rather unusable state.
-When
-using it for the first time, work on the console of the computer, and
-do
-.Em NOT
-do anything you do not understand.
-.Pp
-When manipulating/adding chain entries, service and protocol names are
-not accepted.
diff --git a/sbin/ip6fw/ip6fw.c b/sbin/ip6fw/ip6fw.c
deleted file mode 100644
index 9ceabbf..0000000
--- a/sbin/ip6fw/ip6fw.c
+++ /dev/null
@@ -1,1453 +0,0 @@
-/* $KAME: ip6fw.c,v 1.14 2003/10/02 19:36:25 itojun Exp $ */
-
-/*
- * Copyright (C) 1998, 1999, 2000 and 2001 WIDE Project.
- * All rights reserved.
- *
- * 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
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the 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 PROJECT AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/*
- * Copyright (c) 1996 Alex Nash, Paul Traina, Poul-Henning Kamp
- * Copyright (c) 1994 Ugen J.S.Antsilevich
- *
- * Idea and grammar partially left from:
- * Copyright (c) 1993 Daniel Boulet
- *
- * Redistribution and use in source forms, with and without modification,
- * are permitted provided that this entire comment appears intact.
- *
- * Redistribution in binary form may occur without any restrictions.
- * Obviously, it would be nice if you gave credit where credit is due
- * but requiring it would be too onerous.
- *
- * This software is provided ``AS IS'' without any warranties of any kind.
- *
- * NEW command line interface for IP firewall facility
- *
- * $Id: ip6fw.c,v 1.1.2.2.2.2 1999/05/14 05:13:50 shin Exp $
- * $FreeBSD$
- */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/socket.h>
-#include <sys/sockio.h>
-#include <sys/time.h>
-#include <sys/ioctl.h>
-#include <sys/wait.h>
-
-#include <ctype.h>
-#include <err.h>
-#include <limits.h>
-#include <netdb.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <string.h>
-#include <time.h>
-#include <timeconv.h>
-#include <unistd.h>
-#include <errno.h>
-#include <signal.h>
-#include <sysexits.h>
-
-#include <net/if.h>
-#include <netinet/in.h>
-#include <netinet/in_systm.h>
-#include <netinet/ip6.h>
-#include <netinet/icmp6.h>
-#include <netinet6/ip6_fw.h>
-#include <netinet/tcp.h>
-#include <arpa/inet.h>
-
-int lineno = -1;
-
-int s; /* main RAW socket */
-int do_resolv=0; /* Would try to resolv all */
-int do_acct=0; /* Show packet/byte count */
-int do_time=0; /* Show time stamps */
-int do_quiet=0; /* Be quiet in add and flush */
-int do_force=0; /* Don't ask for confirmation */
-int do_test=0; /* Don't load into Kernel */
-
-struct icmpcode {
- int code;
- char *str;
-};
-
-static struct icmpcode icmp6codes[] = {
- { ICMP6_DST_UNREACH_NOROUTE, "noroute" },
- { ICMP6_DST_UNREACH_ADMIN, "admin" },
- { ICMP6_DST_UNREACH_NOTNEIGHBOR, "notneighbor" },
- { ICMP6_DST_UNREACH_ADDR, "addr" },
- { ICMP6_DST_UNREACH_NOPORT, "noport" },
- { 0, NULL }
-};
-
-static char ntop_buf[INET6_ADDRSTRLEN];
-
-static void show_usage(const char *fmt, ...);
-
-static int
-mask_bits(u_char *m_ad, int m_len)
-{
- int h_num = 0,i;
-
- for (i = 0; i < m_len; i++, m_ad++) {
- if (*m_ad != 0xff)
- break;
- h_num += 8;
- }
- if (i < m_len) {
- switch (*m_ad) {
-#define MASKLEN(m, l) case m: h_num += l; break
- MASKLEN(0xfe, 7);
- MASKLEN(0xfc, 6);
- MASKLEN(0xf8, 5);
- MASKLEN(0xf0, 4);
- MASKLEN(0xe0, 3);
- MASKLEN(0xc0, 2);
- MASKLEN(0x80, 1);
-#undef MASKLEN
- }
- }
- return h_num;
-}
-
-static int pl2m[9] = { 0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff };
-
-struct in6_addr *plen2mask(int n)
-{
- static struct in6_addr ia;
- u_char *p;
- int i;
-
- memset(&ia, 0, sizeof(struct in6_addr));
- p = (u_char *)&ia;
- for (i = 0; i < 16; i++, p++, n -= 8) {
- if (n >= 8) {
- *p = 0xff;
- continue;
- }
- *p = pl2m[n];
- break;
- }
- return &ia;
-}
-
-void
-print_port(prot, port, comma)
- u_char prot;
- u_short port;
- const char *comma;
-{
- struct servent *se;
- struct protoent *pe;
- const char *protocol;
- int printed = 0;
-
- if (do_resolv) {
- pe = getprotobynumber(prot);
- if (pe)
- protocol = pe->p_name;
- else
- protocol = NULL;
-
- se = getservbyport(htons(port), protocol);
- if (se) {
- printf("%s%s", comma, se->s_name);
- printed = 1;
- }
- }
- if (!printed)
- printf("%s%d",comma,port);
-}
-
-static void
-print_iface(char *key, union ip6_fw_if *un, int byname)
-{
-
- if (byname) {
- printf(" %s %s", key, un->fu_via_if.name);
- } else if (!IN6_IS_ADDR_UNSPECIFIED(&un->fu_via_ip6)) {
- printf(" %s %s", key, inet_ntop(AF_INET6,&un->fu_via_ip6,ntop_buf,sizeof(ntop_buf)));
- } else
- printf(" %s any", key);
-}
-
-static void
-print_reject_code(int code)
-{
- struct icmpcode *ic;
-
- for (ic = icmp6codes; ic->str; ic++)
- if (ic->code == code) {
- printf("%s", ic->str);
- return;
- }
- printf("%u", code);
-}
-
-static void
-show_ip6fw(struct ip6_fw *chain)
-{
- char *comma;
- struct hostent *he;
- struct protoent *pe;
- int i, mb;
- int nsp = IPV6_FW_GETNSRCP(chain);
- int ndp = IPV6_FW_GETNDSTP(chain);
-
- if (do_resolv)
- setservent(1/*stayopen*/);
-
- printf("%05u ", chain->fw_number);
-
- if (do_acct)
- printf("%10lu %10lu ",chain->fw_pcnt,chain->fw_bcnt);
-
- if (do_time)
- {
- if (chain->timestamp)
- {
- char timestr[30];
- time_t t = _long_to_time(chain->timestamp);
-
- strcpy(timestr, ctime(&t));
- *strchr(timestr, '\n') = '\0';
- printf("%s ", timestr);
- }
- else
- printf(" ");
- }
-
- switch (chain->fw_flg & IPV6_FW_F_COMMAND)
- {
- case IPV6_FW_F_ACCEPT:
- printf("allow");
- break;
- case IPV6_FW_F_DENY:
- printf("deny");
- break;
- case IPV6_FW_F_COUNT:
- printf("count");
- break;
- case IPV6_FW_F_DIVERT:
- printf("divert %u", chain->fw_divert_port);
- break;
- case IPV6_FW_F_TEE:
- printf("tee %u", chain->fw_divert_port);
- break;
- case IPV6_FW_F_SKIPTO:
- printf("skipto %u", chain->fw_skipto_rule);
- break;
- case IPV6_FW_F_REJECT:
- if (chain->fw_reject_code == IPV6_FW_REJECT_RST)
- printf("reset");
- else {
- printf("unreach ");
- print_reject_code(chain->fw_reject_code);
- }
- break;
- default:
- errx(EX_OSERR, "impossible");
- }
-
- if (chain->fw_flg & IPV6_FW_F_PRN)
- printf(" log");
-
- pe = getprotobynumber(chain->fw_prot);
- if (pe)
- printf(" %s", pe->p_name);
- else
- printf(" %u", chain->fw_prot);
-
- printf(" from %s", chain->fw_flg & IPV6_FW_F_INVSRC ? "not " : "");
-
- mb=mask_bits((u_char *)&chain->fw_smsk,sizeof(chain->fw_smsk));
- if (mb==128 && do_resolv) {
- he=gethostbyaddr((char *)&(chain->fw_src),sizeof(chain->fw_src),AF_INET6);
- if (he==NULL) {
- printf(inet_ntop(AF_INET6,&chain->fw_src,ntop_buf,sizeof(ntop_buf)));
- } else
- printf("%s",he->h_name);
- } else {
- if (mb!=128) {
- if (mb == 0) {
- printf("any");
- } else {
- printf(inet_ntop(AF_INET6,&chain->fw_src,ntop_buf,sizeof(ntop_buf)));
- printf("/%d",mb);
- }
- } else
- printf(inet_ntop(AF_INET6,&chain->fw_src,ntop_buf,sizeof(ntop_buf)));
- }
-
- if (chain->fw_prot == IPPROTO_TCP || chain->fw_prot == IPPROTO_UDP) {
- comma = " ";
- for (i = 0; i < nsp; i++) {
- print_port(chain->fw_prot, chain->fw_pts[i], comma);
- if (i==0 && (chain->fw_flg & IPV6_FW_F_SRNG))
- comma = "-";
- else
- comma = ",";
- }
- }
-
- printf(" to %s", chain->fw_flg & IPV6_FW_F_INVDST ? "not " : "");
-
- mb=mask_bits((u_char *)&chain->fw_dmsk,sizeof(chain->fw_dmsk));
- if (mb==128 && do_resolv) {
- he=gethostbyaddr((char *)&(chain->fw_dst),sizeof(chain->fw_dst),AF_INET6);
- if (he==NULL) {
- printf(inet_ntop(AF_INET6,&chain->fw_dst,ntop_buf,sizeof(ntop_buf)));
- } else
- printf("%s",he->h_name);
- } else {
- if (mb!=128) {
- if (mb == 0) {
- printf("any");
- } else {
- printf(inet_ntop(AF_INET6,&chain->fw_dst,ntop_buf,sizeof(ntop_buf)));
- printf("/%d",mb);
- }
- } else
- printf(inet_ntop(AF_INET6,&chain->fw_dst,ntop_buf,sizeof(ntop_buf)));
- }
-
- if (chain->fw_prot == IPPROTO_TCP || chain->fw_prot == IPPROTO_UDP) {
- comma = " ";
- for (i = 0; i < ndp; i++) {
- print_port(chain->fw_prot, chain->fw_pts[nsp+i], comma);
- if (i==0 && (chain->fw_flg & IPV6_FW_F_DRNG))
- comma = "-";
- else
- comma = ",";
- }
- }
-
- /* Direction */
- if ((chain->fw_flg & IPV6_FW_F_IN) && !(chain->fw_flg & IPV6_FW_F_OUT))
- printf(" in");
- if (!(chain->fw_flg & IPV6_FW_F_IN) && (chain->fw_flg & IPV6_FW_F_OUT))
- printf(" out");
-
- /* Handle hack for "via" backwards compatibility */
- if ((chain->fw_flg & IF6_FW_F_VIAHACK) == IF6_FW_F_VIAHACK) {
- print_iface("via",
- &chain->fw_in_if, chain->fw_flg & IPV6_FW_F_IIFNAME);
- } else {
- /* Receive interface specified */
- if (chain->fw_flg & IPV6_FW_F_IIFACE)
- print_iface("recv", &chain->fw_in_if,
- chain->fw_flg & IPV6_FW_F_IIFNAME);
- /* Transmit interface specified */
- if (chain->fw_flg & IPV6_FW_F_OIFACE)
- print_iface("xmit", &chain->fw_out_if,
- chain->fw_flg & IPV6_FW_F_OIFNAME);
- }
-
- if (chain->fw_flg & IPV6_FW_F_FRAG)
- printf(" frag");
-
- if (chain->fw_ip6opt || chain->fw_ip6nopt) {
- int _opt_printed = 0;
-#define PRINTOPT(x) {if (_opt_printed) printf(",");\
- printf(x); _opt_printed = 1;}
-
- printf(" ip6opt ");
- if (chain->fw_ip6opt & IPV6_FW_IP6OPT_HOPOPT) PRINTOPT("hopopt");
- if (chain->fw_ip6nopt & IPV6_FW_IP6OPT_HOPOPT) PRINTOPT("!hopopt");
- if (chain->fw_ip6opt & IPV6_FW_IP6OPT_ROUTE) PRINTOPT("route");
- if (chain->fw_ip6nopt & IPV6_FW_IP6OPT_ROUTE) PRINTOPT("!route");
- if (chain->fw_ip6opt & IPV6_FW_IP6OPT_FRAG) PRINTOPT("frag");
- if (chain->fw_ip6nopt & IPV6_FW_IP6OPT_FRAG) PRINTOPT("!frag");
- if (chain->fw_ip6opt & IPV6_FW_IP6OPT_ESP) PRINTOPT("esp");
- if (chain->fw_ip6nopt & IPV6_FW_IP6OPT_ESP) PRINTOPT("!esp");
- if (chain->fw_ip6opt & IPV6_FW_IP6OPT_AH) PRINTOPT("ah");
- if (chain->fw_ip6nopt & IPV6_FW_IP6OPT_AH) PRINTOPT("!ah");
- if (chain->fw_ip6opt & IPV6_FW_IP6OPT_NONXT) PRINTOPT("nonxt");
- if (chain->fw_ip6nopt & IPV6_FW_IP6OPT_NONXT) PRINTOPT("!nonxt");
- if (chain->fw_ip6opt & IPV6_FW_IP6OPT_OPTS) PRINTOPT("opts");
- if (chain->fw_ip6nopt & IPV6_FW_IP6OPT_OPTS) PRINTOPT("!opts");
- }
-
- if (chain->fw_ipflg & IPV6_FW_IF_TCPEST)
- printf(" established");
- else if (chain->fw_tcpf == IPV6_FW_TCPF_SYN &&
- chain->fw_tcpnf == IPV6_FW_TCPF_ACK)
- printf(" setup");
- else if (chain->fw_tcpf || chain->fw_tcpnf) {
- int _flg_printed = 0;
-#define PRINTFLG(x) {if (_flg_printed) printf(",");\
- printf(x); _flg_printed = 1;}
-
- printf(" tcpflg ");
- if (chain->fw_tcpf & IPV6_FW_TCPF_FIN) PRINTFLG("fin");
- if (chain->fw_tcpnf & IPV6_FW_TCPF_FIN) PRINTFLG("!fin");
- if (chain->fw_tcpf & IPV6_FW_TCPF_SYN) PRINTFLG("syn");
- if (chain->fw_tcpnf & IPV6_FW_TCPF_SYN) PRINTFLG("!syn");
- if (chain->fw_tcpf & IPV6_FW_TCPF_RST) PRINTFLG("rst");
- if (chain->fw_tcpnf & IPV6_FW_TCPF_RST) PRINTFLG("!rst");
- if (chain->fw_tcpf & IPV6_FW_TCPF_PSH) PRINTFLG("psh");
- if (chain->fw_tcpnf & IPV6_FW_TCPF_PSH) PRINTFLG("!psh");
- if (chain->fw_tcpf & IPV6_FW_TCPF_ACK) PRINTFLG("ack");
- if (chain->fw_tcpnf & IPV6_FW_TCPF_ACK) PRINTFLG("!ack");
- if (chain->fw_tcpf & IPV6_FW_TCPF_URG) PRINTFLG("urg");
- if (chain->fw_tcpnf & IPV6_FW_TCPF_URG) PRINTFLG("!urg");
- }
- if (chain->fw_flg & IPV6_FW_F_ICMPBIT) {
- int type_index;
- int first = 1;
-
- printf(" icmptype");
-
- for (type_index = 0; type_index < IPV6_FW_ICMPTYPES_DIM * sizeof(unsigned) * 8; ++type_index)
- if (chain->fw_icmp6types[type_index / (sizeof(unsigned) * 8)] &
- (1U << (type_index % (sizeof(unsigned) * 8)))) {
- printf("%c%d", first == 1 ? ' ' : ',', type_index);
- first = 0;
- }
- }
- printf("\n");
- if (do_resolv)
- endservent();
-}
-
-void
-list(ac, av)
- int ac;
- char **av;
-{
- struct ip6_fw *r, *rules, *n;
- int l,i;
- unsigned long rulenum;
- int nalloc, bytes, maxbytes;
-
- /* extract rules from kernel, resizing array as necessary */
- rules = NULL;
- nalloc = sizeof *rules;
- bytes = nalloc;
- maxbytes = 65536 * sizeof *rules;
- while (bytes >= nalloc) {
- if ((n = realloc(rules, nalloc * 2 + 200)) == NULL)
- err(EX_OSERR, "realloc");
- bytes = nalloc = nalloc * 2 + 200;
- rules = n;
- i = getsockopt(s, IPPROTO_IPV6, IPV6_FW_GET, rules, &bytes);
- if ((i < 0 && errno != EINVAL) || nalloc > maxbytes)
- err(EX_OSERR, "getsockopt(IPV6_FW_GET)");
- }
- if (!ac) {
- /* display all rules */
- for (r = rules, l = bytes; l >= sizeof rules[0];
- r++, l-=sizeof rules[0])
- show_ip6fw(r);
- }
- else {
- /* display specific rules requested on command line */
- int exitval = 0;
-
- while (ac--) {
- char *endptr;
- int seen;
-
- /* convert command line rule # */
- rulenum = strtoul(*av++, &endptr, 10);
- if (*endptr) {
- exitval = 1;
- warn("invalid rule number: %s", av[-1]);
- continue;
- }
- seen = 0;
- for (r = rules, l = bytes;
- l >= sizeof rules[0] && r->fw_number <= rulenum;
- r++, l-=sizeof rules[0])
- if (rulenum == r->fw_number) {
- show_ip6fw(r);
- seen = 1;
- }
- if (!seen) {
- exitval = 1;
- warnx("rule %lu does not exist", rulenum);
- }
- }
- if (exitval != 0)
- exit(exitval);
- }
-}
-
-static void
-show_usage(const char *fmt, ...)
-{
- if (fmt) {
- char buf[100];
- va_list args;
-
- va_start(args, fmt);
- vsnprintf(buf, sizeof(buf), fmt, args);
- va_end(args);
- warnx("error: %s", buf);
- }
- fprintf(stderr, "usage: ip6fw [options]\n"
-" flush\n"
-" add [number] rule\n"
-" delete number ...\n"
-" list [number ...]\n"
-" show [number ...]\n"
-" zero [number ...]\n"
-" rule: action proto src dst extras...\n"
-" action:\n"
-" {allow|permit|accept|pass|deny|drop|reject|unreach code|\n"
-" reset|count|skipto num} [log]\n"
-" proto: {ipv6|tcp|udp|ipv6-icmp|<number>}\n"
-" src: from [not] {any|ipv6[/prefixlen]} [{port|port-port},[port],...]\n"
-" dst: to [not] {any|ipv6[/prefixlen]} [{port|port-port},[port],...]\n"
-" extras:\n"
-" fragment (may not be used with ports or tcpflags)\n"
-" in\n"
-" out\n"
-" {xmit|recv|via} {iface|ipv6|any}\n"
-" {established|setup}\n"
-" tcpflags [!]{syn|fin|rst|ack|psh|urg},...\n"
-" ipv6options [!]{hopopt|route|frag|esp|ah|nonxt|opts},...\n"
-" icmptypes {type[,type]}...\n");
-
- exit(1);
-}
-
-static int
-lookup_host (host, addr, family)
- char *host;
- u_char *addr;
- int family;
-{
- struct hostent *he;
-
- if (inet_pton(family, host, addr) != 1) {
- if ((he = gethostbyname2(host, family)) == NULL)
- return(-1);
- memcpy(addr, he->h_addr_list[0], he->h_length);
- }
- return(0);
-}
-
-void
-fill_ip6(ipno, mask, acp, avp)
- struct in6_addr *ipno, *mask;
- int *acp;
- char ***avp;
-{
- int ac = *acp;
- char **av = *avp;
- char *p = 0, md = 0;
- int i;
-
- if (ac && !strncmp(*av,"any",strlen(*av))) {
- *ipno = *mask = in6addr_any; av++; ac--;
- } else {
- p = strchr(*av, '/');
- if (p) {
- md = *p;
- *p++ = '\0';
- }
-
- if (lookup_host(*av, (u_char *)ipno, AF_INET6) != 0)
- show_usage("hostname ``%s'' unknown", *av);
- switch (md) {
- case '/':
- if (atoi(p) == 0) {
- *mask = in6addr_any;
- } else if (atoi(p) > 128) {
- show_usage("bad width ``%s''", p);
- } else {
- *mask = *(plen2mask(atoi(p)));
- }
- break;
- default:
- *mask = *(plen2mask(128));
- break;
- }
- for (i = 0; i < sizeof(*ipno); i++)
- ipno->s6_addr[i] &= mask->s6_addr[i];
- av++;
- ac--;
- }
- *acp = ac;
- *avp = av;
-}
-
-static void
-fill_reject_code6(u_short *codep, char *str)
-{
- struct icmpcode *ic;
- u_long val;
- char *s;
-
- val = strtoul(str, &s, 0);
- if (s != str && *s == '\0' && val < 0x100) {
- *codep = val;
- return;
- }
- for (ic = icmp6codes; ic->str; ic++)
- if (!strcasecmp(str, ic->str)) {
- *codep = ic->code;
- return;
- }
- show_usage("unknown ICMP6 unreachable code ``%s''", str);
-}
-
-static void
-add_port(cnt, ptr, off, port)
- u_short *cnt, *ptr, off, port;
-{
- if (off + *cnt >= IPV6_FW_MAX_PORTS)
- errx(1, "too many ports (max is %d)", IPV6_FW_MAX_PORTS);
- ptr[off+*cnt] = port;
- (*cnt)++;
-}
-
-static int
-lookup_port(const char *arg, int test, int nodash)
-{
- int val;
- char *earg, buf[32];
- struct servent *s;
-
- snprintf(buf, sizeof(buf), "%s", arg);
- buf[strcspn(arg, nodash ? "-," : ",")] = 0;
- val = (int) strtoul(buf, &earg, 0);
- if (!*buf || *earg) {
- setservent(1);
- if ((s = getservbyname(buf, NULL))) {
- val = htons(s->s_port);
- } else {
- if (!test) {
- errx(1, "unknown port ``%s''", arg);
- }
- val = -1;
- }
- } else {
- if (val < 0 || val > 0xffff) {
- if (!test) {
- errx(1, "port ``%s'' out of range", arg);
- }
- val = -1;
- }
- }
- return(val);
-}
-
-int
-fill_port(cnt, ptr, off, arg)
- u_short *cnt, *ptr, off;
- char *arg;
-{
- char *s;
- int initial_range = 0;
-
- s = arg + strcspn(arg, "-,"); /* first port name can't have a dash */
- if (*s == '-') {
- *s++ = '\0';
- if (strchr(arg, ','))
- errx(1, "port range must be first in list");
- add_port(cnt, ptr, off, *arg ? lookup_port(arg, 0, 0) : 0x0000);
- arg = s;
- s = strchr(arg,',');
- if (s)
- *s++ = '\0';
- add_port(cnt, ptr, off, *arg ? lookup_port(arg, 0, 0) : 0xffff);
- arg = s;
- initial_range = 1;
- }
- while (arg != NULL) {
- s = strchr(arg,',');
- if (s)
- *s++ = '\0';
- add_port(cnt, ptr, off, lookup_port(arg, 0, 0));
- arg = s;
- }
- return initial_range;
-}
-
-void
-fill_tcpflag(set, reset, vp)
- u_char *set, *reset;
- char **vp;
-{
- char *p = *vp,*q;
- u_char *d;
-
- while (p && *p) {
- struct tpcflags {
- char * name;
- u_char value;
- } flags[] = {
- { "syn", IPV6_FW_TCPF_SYN },
- { "fin", IPV6_FW_TCPF_FIN },
- { "ack", IPV6_FW_TCPF_ACK },
- { "psh", IPV6_FW_TCPF_PSH },
- { "rst", IPV6_FW_TCPF_RST },
- { "urg", IPV6_FW_TCPF_URG }
- };
- int i;
-
- if (*p == '!') {
- p++;
- d = reset;
- } else {
- d = set;
- }
- q = strchr(p, ',');
- if (q)
- *q++ = '\0';
- for (i = 0; i < sizeof(flags) / sizeof(flags[0]); ++i)
- if (!strncmp(p, flags[i].name, strlen(p))) {
- *d |= flags[i].value;
- break;
- }
- if (i == sizeof(flags) / sizeof(flags[0]))
- show_usage("invalid tcp flag ``%s''", p);
- p = q;
- }
-}
-
-static void
-fill_ip6opt(u_char *set, u_char *reset, char **vp)
-{
- char *p = *vp,*q;
- u_char *d;
-
- while (p && *p) {
- if (*p == '!') {
- p++;
- d = reset;
- } else {
- d = set;
- }
- q = strchr(p, ',');
- if (q)
- *q++ = '\0';
- if (!strncmp(p,"hopopt",strlen(p))) *d |= IPV6_FW_IP6OPT_HOPOPT;
- if (!strncmp(p,"route",strlen(p))) *d |= IPV6_FW_IP6OPT_ROUTE;
- if (!strncmp(p,"frag",strlen(p))) *d |= IPV6_FW_IP6OPT_FRAG;
- if (!strncmp(p,"esp",strlen(p))) *d |= IPV6_FW_IP6OPT_ESP;
- if (!strncmp(p,"ah",strlen(p))) *d |= IPV6_FW_IP6OPT_AH;
- if (!strncmp(p,"nonxt",strlen(p))) *d |= IPV6_FW_IP6OPT_NONXT;
- if (!strncmp(p,"opts",strlen(p))) *d |= IPV6_FW_IP6OPT_OPTS;
- p = q;
- }
-}
-
-void
-fill_icmptypes(types, vp, fw_flg)
- u_long *types;
- char **vp;
- u_short *fw_flg;
-{
- char *c = *vp;
-
- while (*c)
- {
- unsigned long icmptype;
-
- if ( *c == ',' )
- ++c;
-
- icmptype = strtoul(c, &c, 0);
-
- if ( *c != ',' && *c != '\0' )
- show_usage("invalid ICMP6 type");
-
- if (icmptype >= IPV6_FW_ICMPTYPES_DIM * sizeof(unsigned) * 8)
- show_usage("ICMP6 type out of range");
-
- types[icmptype / (sizeof(unsigned) * 8)] |=
- 1 << (icmptype % (sizeof(unsigned) * 8));
- *fw_flg |= IPV6_FW_F_ICMPBIT;
- }
-}
-
-void
-delete(ac,av)
- int ac;
- char **av;
-{
- struct ip6_fw rule;
- int i;
- int exitval = 0;
-
- memset(&rule, 0, sizeof rule);
-
- av++; ac--;
-
- /* Rule number */
- while (ac && isdigit(**av)) {
- rule.fw_number = atoi(*av); av++; ac--;
- if (!do_test) {
- i = setsockopt(s, IPPROTO_IPV6, IPV6_FW_DEL, &rule, sizeof rule);
- if (i) {
- exitval = 1;
- warn("rule %u: setsockopt(%s)", rule.fw_number, "IPV6_FW_DEL");
- }
- }
- }
- if (exitval != 0)
- exit(exitval);
-}
-
-static void
-verify_interface(union ip6_fw_if *ifu)
-{
- struct ifreq ifr;
-
- strlcpy(ifr.ifr_name, ifu->fu_via_if.name, sizeof(ifr.ifr_name));
-
- if (ioctl(s, SIOCGIFFLAGS, &ifr) < 0)
- warnx("warning: interface ``%s'' does not exist", ifr.ifr_name);
-}
-
-static void
-fill_iface(char *which, union ip6_fw_if *ifu, int *byname, int ac, char *arg)
-{
- if (!ac)
- show_usage("missing argument for ``%s''", which);
-
- /* Parse the interface or address */
- if (!strcmp(arg, "any")) {
- ifu->fu_via_ip6 = in6addr_any;
- *byname = 0;
- } else if (!isdigit(*arg)) {
- *byname = 1;
- strlcpy(ifu->fu_via_if.name, arg, sizeof(ifu->fu_via_if.name));
- /*
- * We assume that strings containing '*', '?', or '['
- * are ment to be shell pattern.
- */
- if (strpbrk(arg, "*?[") != NULL) {
- ifu->fu_via_if.glob = 1;
- } else {
- ifu->fu_via_if.glob = 0;
- verify_interface(ifu);
- }
- } else if (inet_pton(AF_INET6, arg, &ifu->fu_via_ip6) != 1) {
- show_usage("bad ip6 address ``%s''", arg);
- } else
- *byname = 0;
-}
-
-static void
-add(ac,av)
- int ac;
- char **av;
-{
- struct ip6_fw rule;
- int i;
- u_char proto;
- struct protoent *pe;
- int saw_xmrc = 0, saw_via = 0;
-
- memset(&rule, 0, sizeof rule);
-
- av++; ac--;
-
- /* Rule number */
- if (ac && isdigit(**av)) {
- rule.fw_number = atoi(*av); av++; ac--;
- }
-
- /* Action */
- if (ac == 0)
- show_usage("missing action");
- if (!strncmp(*av,"accept",strlen(*av))
- || !strncmp(*av,"pass",strlen(*av))
- || !strncmp(*av,"allow",strlen(*av))
- || !strncmp(*av,"permit",strlen(*av))) {
- rule.fw_flg |= IPV6_FW_F_ACCEPT; av++; ac--;
- } else if (!strncmp(*av,"count",strlen(*av))) {
- rule.fw_flg |= IPV6_FW_F_COUNT; av++; ac--;
- }
-#if 0
- else if (!strncmp(*av,"divert",strlen(*av))) {
- rule.fw_flg |= IPV6_FW_F_DIVERT; av++; ac--;
- if (!ac)
- show_usage("missing divert port");
- rule.fw_divert_port = strtoul(*av, NULL, 0); av++; ac--;
- if (rule.fw_divert_port == 0) {
- struct servent *s;
- setservent(1);
- s = getservbyname(av[-1], "divert");
- if (s != NULL)
- rule.fw_divert_port = ntohs(s->s_port);
- else
- show_usage("illegal divert port");
- }
- } else if (!strncmp(*av,"tee",strlen(*av))) {
- rule.fw_flg |= IPV6_FW_F_TEE; av++; ac--;
- if (!ac)
- show_usage("missing divert port");
- rule.fw_divert_port = strtoul(*av, NULL, 0); av++; ac--;
- if (rule.fw_divert_port == 0) {
- struct servent *s;
- setservent(1);
- s = getservbyname(av[-1], "divert");
- if (s != NULL)
- rule.fw_divert_port = ntohs(s->s_port);
- else
- show_usage("illegal divert port");
- }
- }
-#endif
- else if (!strncmp(*av,"skipto",strlen(*av))) {
- rule.fw_flg |= IPV6_FW_F_SKIPTO; av++; ac--;
- if (!ac)
- show_usage("missing skipto rule number");
- rule.fw_skipto_rule = strtoul(*av, NULL, 0); av++; ac--;
- } else if ((!strncmp(*av,"deny",strlen(*av))
- || !strncmp(*av,"drop",strlen(*av)))) {
- rule.fw_flg |= IPV6_FW_F_DENY; av++; ac--;
- } else if (!strncmp(*av,"reject",strlen(*av))) {
- rule.fw_flg |= IPV6_FW_F_REJECT; av++; ac--;
- rule.fw_reject_code = ICMP6_DST_UNREACH_NOROUTE;
- } else if (!strncmp(*av,"reset",strlen(*av))) {
- rule.fw_flg |= IPV6_FW_F_REJECT; av++; ac--;
- rule.fw_reject_code = IPV6_FW_REJECT_RST; /* check TCP later */
- } else if (!strncmp(*av,"unreach",strlen(*av))) {
- rule.fw_flg |= IPV6_FW_F_REJECT; av++; ac--;
- fill_reject_code6(&rule.fw_reject_code, *av); av++; ac--;
- } else {
- show_usage("invalid action ``%s''", *av);
- }
-
- /* [log] */
- if (ac && !strncmp(*av,"log",strlen(*av))) {
- rule.fw_flg |= IPV6_FW_F_PRN; av++; ac--;
- }
-
- /* protocol */
- if (ac == 0)
- show_usage("missing protocol");
- if ((proto = atoi(*av)) > 0) {
- rule.fw_prot = proto; av++; ac--;
- } else if (!strncmp(*av,"all",strlen(*av))) {
- rule.fw_prot = IPPROTO_IPV6; av++; ac--;
- } else if ((pe = getprotobyname(*av)) != NULL) {
- rule.fw_prot = pe->p_proto; av++; ac--;
- } else {
- show_usage("invalid protocol ``%s''", *av);
- }
-
- if (rule.fw_prot != IPPROTO_TCP
- && (rule.fw_flg & IPV6_FW_F_COMMAND) == IPV6_FW_F_REJECT
- && rule.fw_reject_code == IPV6_FW_REJECT_RST)
- show_usage("``reset'' is only valid for tcp packets");
-
- /* from */
- if (ac && !strncmp(*av,"from",strlen(*av))) { av++; ac--; }
- else
- show_usage("missing ``from''");
-
- if (ac && !strncmp(*av,"not",strlen(*av))) {
- rule.fw_flg |= IPV6_FW_F_INVSRC;
- av++; ac--;
- }
- if (!ac)
- show_usage("missing arguments");
-
- fill_ip6(&rule.fw_src, &rule.fw_smsk, &ac, &av);
-
- if (ac && (isdigit(**av) || lookup_port(*av, 1, 1) >= 0)) {
- u_short nports = 0;
-
- if (fill_port(&nports, rule.fw_pts, 0, *av))
- rule.fw_flg |= IPV6_FW_F_SRNG;
- IPV6_FW_SETNSRCP(&rule, nports);
- av++; ac--;
- }
-
- /* to */
- if (ac && !strncmp(*av,"to",strlen(*av))) { av++; ac--; }
- else
- show_usage("missing ``to''");
-
- if (ac && !strncmp(*av,"not",strlen(*av))) {
- rule.fw_flg |= IPV6_FW_F_INVDST;
- av++; ac--;
- }
- if (!ac)
- show_usage("missing arguments");
-
- fill_ip6(&rule.fw_dst, &rule.fw_dmsk, &ac, &av);
-
- if (ac && (isdigit(**av) || lookup_port(*av, 1, 1) >= 0)) {
- u_short nports = 0;
-
- if (fill_port(&nports,
- rule.fw_pts, IPV6_FW_GETNSRCP(&rule), *av))
- rule.fw_flg |= IPV6_FW_F_DRNG;
- IPV6_FW_SETNDSTP(&rule, nports);
- av++; ac--;
- }
-
- if ((rule.fw_prot != IPPROTO_TCP) && (rule.fw_prot != IPPROTO_UDP)
- && (IPV6_FW_GETNSRCP(&rule) || IPV6_FW_GETNDSTP(&rule))) {
- show_usage("only TCP and UDP protocols are valid"
- " with port specifications");
- }
-
- while (ac) {
- if (!strncmp(*av,"in",strlen(*av))) {
- rule.fw_flg |= IPV6_FW_F_IN;
- av++; ac--; continue;
- }
- if (!strncmp(*av,"out",strlen(*av))) {
- rule.fw_flg |= IPV6_FW_F_OUT;
- av++; ac--; continue;
- }
- if (ac && !strncmp(*av,"xmit",strlen(*av))) {
- union ip6_fw_if ifu;
- int byname;
-
- if (saw_via) {
-badviacombo:
- show_usage("``via'' is incompatible"
- " with ``xmit'' and ``recv''");
- }
- saw_xmrc = 1;
- av++; ac--;
- fill_iface("xmit", &ifu, &byname, ac, *av);
- rule.fw_out_if = ifu;
- rule.fw_flg |= IPV6_FW_F_OIFACE;
- if (byname)
- rule.fw_flg |= IPV6_FW_F_OIFNAME;
- av++; ac--; continue;
- }
- if (ac && !strncmp(*av,"recv",strlen(*av))) {
- union ip6_fw_if ifu;
- int byname;
-
- if (saw_via)
- goto badviacombo;
- saw_xmrc = 1;
- av++; ac--;
- fill_iface("recv", &ifu, &byname, ac, *av);
- rule.fw_in_if = ifu;
- rule.fw_flg |= IPV6_FW_F_IIFACE;
- if (byname)
- rule.fw_flg |= IPV6_FW_F_IIFNAME;
- av++; ac--; continue;
- }
- if (ac && !strncmp(*av,"via",strlen(*av))) {
- union ip6_fw_if ifu;
- int byname = 0;
-
- if (saw_xmrc)
- goto badviacombo;
- saw_via = 1;
- av++; ac--;
- fill_iface("via", &ifu, &byname, ac, *av);
- rule.fw_out_if = rule.fw_in_if = ifu;
- if (byname)
- rule.fw_flg |=
- (IPV6_FW_F_IIFNAME | IPV6_FW_F_OIFNAME);
- av++; ac--; continue;
- }
- if (!strncmp(*av,"fragment",strlen(*av))) {
- rule.fw_flg |= IPV6_FW_F_FRAG;
- av++; ac--; continue;
- }
- if (!strncmp(*av,"ipv6options",strlen(*av))) {
- av++; ac--;
- if (!ac)
- show_usage("missing argument"
- " for ``ipv6options''");
- fill_ip6opt(&rule.fw_ip6opt, &rule.fw_ip6nopt, av);
- av++; ac--; continue;
- }
- if (rule.fw_prot == IPPROTO_TCP) {
- if (!strncmp(*av,"established",strlen(*av))) {
- rule.fw_ipflg |= IPV6_FW_IF_TCPEST;
- av++; ac--; continue;
- }
- if (!strncmp(*av,"setup",strlen(*av))) {
- rule.fw_tcpf |= IPV6_FW_TCPF_SYN;
- rule.fw_tcpnf |= IPV6_FW_TCPF_ACK;
- av++; ac--; continue;
- }
- if (!strncmp(*av,"tcpflags",strlen(*av))) {
- av++; ac--;
- if (!ac)
- show_usage("missing argument"
- " for ``tcpflags''");
- fill_tcpflag(&rule.fw_tcpf, &rule.fw_tcpnf, av);
- av++; ac--; continue;
- }
- }
- if (rule.fw_prot == IPPROTO_ICMPV6) {
- if (!strncmp(*av,"icmptypes",strlen(*av))) {
- av++; ac--;
- if (!ac)
- show_usage("missing argument"
- " for ``icmptypes''");
- fill_icmptypes(rule.fw_icmp6types,
- av, &rule.fw_flg);
- av++; ac--; continue;
- }
- }
- show_usage("unknown argument ``%s''", *av);
- }
-
- /* No direction specified -> do both directions */
- if (!(rule.fw_flg & (IPV6_FW_F_OUT|IPV6_FW_F_IN)))
- rule.fw_flg |= (IPV6_FW_F_OUT|IPV6_FW_F_IN);
-
- /* Sanity check interface check, but handle "via" case separately */
- if (saw_via) {
- if (rule.fw_flg & IPV6_FW_F_IN)
- rule.fw_flg |= IPV6_FW_F_IIFACE;
- if (rule.fw_flg & IPV6_FW_F_OUT)
- rule.fw_flg |= IPV6_FW_F_OIFACE;
- } else if ((rule.fw_flg & IPV6_FW_F_OIFACE) && (rule.fw_flg & IPV6_FW_F_IN))
- show_usage("can't check xmit interface of incoming packets");
-
- /* frag may not be used in conjunction with ports or TCP flags */
- if (rule.fw_flg & IPV6_FW_F_FRAG) {
- if (rule.fw_tcpf || rule.fw_tcpnf)
- show_usage("can't mix 'frag' and tcpflags");
-
- if (rule.fw_nports)
- show_usage("can't mix 'frag' and port specifications");
- }
-
- if (!do_quiet)
- show_ip6fw(&rule);
- if (!do_test) {
- i = setsockopt(s, IPPROTO_IPV6, IPV6_FW_ADD, &rule, sizeof rule);
- if (i)
- err(EX_UNAVAILABLE, "setsockopt(%s)", "IPV6_FW_ADD");
- }
-}
-
-static void
-zero (ac, av)
- int ac;
- char **av;
-{
- av++; ac--;
-
- if (!ac) {
- /* clear all entries */
- if (!do_test) {
- if (setsockopt(s,IPPROTO_IPV6,IPV6_FW_ZERO,NULL,0)<0)
- err(EX_UNAVAILABLE, "setsockopt(%s)", "IPV6_FW_ZERO");
- if (!do_quiet)
- printf("Accounting cleared.\n");
- } else if (!do_quiet)
- printf("Accounting not cleared.\n");
- } else {
- struct ip6_fw rule;
- int failed = 0;
-
- memset(&rule, 0, sizeof rule);
- while (ac) {
- /* Rule number */
- if (isdigit(**av)) {
- rule.fw_number = atoi(*av); av++; ac--;
- if (!do_test) {
- if (setsockopt(s, IPPROTO_IPV6,
- IPV6_FW_ZERO, &rule, sizeof rule)) {
- warn("rule %u: setsockopt(%s)", rule.fw_number,"IPV6_FW_ZERO");
- failed = 1;
- }
- if (!do_quiet)
- printf("Entry %d cleared\n",
- rule.fw_number);
- }
- else if (!do_quiet)
- printf("Entry %d not cleared\n",
- rule.fw_number);
- } else
- show_usage("invalid rule number ``%s''", *av);
- }
- if (failed != 0)
- exit(failed);
- }
-}
-
-int
-ip6fw_main(ac,av)
- int ac;
- char **av;
-{
- int ch;
-
- /* init optind to 1 */
- optind = 1;
-
- if ( ac == 1 ) {
- show_usage(NULL);
- }
-
- /* Set the force flag for non-interactive processes */
- do_force = !isatty(STDIN_FILENO);
-
- while ((ch = getopt(ac, av ,"afnqtN")) != -1)
- switch(ch) {
- case 'a':
- do_acct=1;
- break;
- case 'f':
- do_force=1;
- break;
- case 'n':
- do_test=1;
- break;
- case 'q':
- do_quiet=1;
- break;
- case 't':
- do_time=1;
- break;
- case 'N':
- do_resolv=1;
- break;
- default:
- show_usage(NULL);
- }
-
- ac -= optind;
- if (*(av+=optind)==NULL) {
- show_usage("Bad arguments");
- }
-
- if (!strncmp(*av, "add", strlen(*av))) {
- add(ac,av);
- } else if (!strncmp(*av, "delete", strlen(*av))) {
- delete(ac,av);
- } else if (!strncmp(*av, "flush", strlen(*av))) {
- int do_flush = 0;
-
- if ( do_force || do_quiet )
- do_flush = 1;
- else {
- int c;
-
- /* Ask the user */
- printf("Are you sure? [yn] ");
- do {
- fflush(stdout);
- c = toupper(getc(stdin));
- while (c != '\n' && getc(stdin) != '\n')
- if (feof(stdin))
- return (0);
- } while (c != 'Y' && c != 'N');
- printf("\n");
- if (c == 'Y')
- do_flush = 1;
- }
- if ( do_flush ) {
- if (!do_test) {
- if (setsockopt(s,IPPROTO_IPV6,IPV6_FW_FLUSH,NULL,0) < 0)
- err(EX_UNAVAILABLE, "setsockopt(%s)", "IPV6_FW_FLUSH");
-
- if (!do_quiet)
- printf("Flushed all rules.\n");
- } else if (!do_quiet)
- printf("Rules not flushed.\n");
- }
- } else if (!strncmp(*av, "zero", strlen(*av))) {
- zero(ac,av);
- } else if (!strncmp(*av, "print", strlen(*av))) {
- list(--ac,++av);
- } else if (!strncmp(*av, "list", strlen(*av))) {
- list(--ac,++av);
- } else if (!strncmp(*av, "show", strlen(*av))) {
- do_acct++;
- list(--ac,++av);
- } else {
- show_usage("Bad arguments");
- }
- return 0;
-}
-
-int
-main(ac, av)
- int ac;
- char **av;
-{
-#define MAX_ARGS 32
-#define WHITESP " \t\f\v\n\r"
- char buf[BUFSIZ];
- char *a, *p, *args[MAX_ARGS], *cmd = NULL;
- char linename[10];
- int i, c, lineno, nflag, qflag, pflag, status;
- FILE *f = NULL;
- pid_t preproc = 0;
-
- s = socket( AF_INET6, SOCK_RAW, IPPROTO_RAW );
- if ( s < 0 )
- err(EX_UNAVAILABLE, "socket");
-
- setbuf(stdout,0);
-
- /*
- * Only interpret the last command line argument as a file to
- * be preprocessed if it is specified as an absolute pathname.
- */
-
- if (ac > 1 && av[ac - 1][0] == '/' && access(av[ac - 1], R_OK) == 0) {
- nflag = qflag = pflag = i = 0;
- lineno = 0;
-
- while ((c = getopt(ac, av, "D:U:np:q")) != -1)
- switch(c) {
- case 'D':
- if (!pflag)
- errx(EX_USAGE, "-D requires -p");
- if (i > MAX_ARGS - 2)
- errx(EX_USAGE,
- "too many -D or -U options");
- args[i++] = "-D";
- args[i++] = optarg;
- break;
-
- case 'U':
- if (!pflag)
- errx(EX_USAGE, "-U requires -p");
- if (i > MAX_ARGS - 2)
- errx(EX_USAGE,
- "too many -D or -U options");
- args[i++] = "-U";
- args[i++] = optarg;
- break;
-
- case 'n':
- nflag = 1;
- break;
-
- case 'p':
- pflag = 1;
- cmd = optarg;
- args[0] = cmd;
- i = 1;
- break;
-
- case 'q':
- qflag = 1;
- break;
-
- default:
- show_usage(NULL);
- }
-
- av += optind;
- ac -= optind;
- if (ac != 1)
- show_usage("extraneous filename arguments");
-
- if ((f = fopen(av[0], "r")) == NULL)
- err(EX_UNAVAILABLE, "fopen: %s", av[0]);
-
- if (pflag) {
- /* pipe through preprocessor (cpp or m4) */
- int pipedes[2];
-
- args[i] = 0;
-
- if (pipe(pipedes) == -1)
- err(EX_OSERR, "cannot create pipe");
-
- switch((preproc = fork())) {
- case -1:
- err(EX_OSERR, "cannot fork");
-
- case 0:
- /* child */
- if (dup2(fileno(f), 0) == -1 ||
- dup2(pipedes[1], 1) == -1)
- err(EX_OSERR, "dup2()");
- fclose(f);
- close(pipedes[1]);
- close(pipedes[0]);
- execvp(cmd, args);
- err(EX_OSERR, "execvp(%s) failed", cmd);
-
- default:
- /* parent */
- fclose(f);
- close(pipedes[1]);
- if ((f = fdopen(pipedes[0], "r")) == NULL) {
- int savederrno = errno;
-
- (void)kill(preproc, SIGTERM);
- errno = savederrno;
- err(EX_OSERR, "fdopen()");
- }
- }
- }
-
- while (fgets(buf, BUFSIZ, f)) {
- lineno++;
- sprintf(linename, "Line %d", lineno);
- args[0] = linename;
-
- if (*buf == '#')
- continue;
- if ((p = strchr(buf, '#')) != NULL)
- *p = '\0';
- i=1;
- if (qflag) args[i++]="-q";
- if (nflag) args[i++]="-n";
- for (a = strtok(buf, WHITESP);
- a && i < MAX_ARGS; a = strtok(NULL, WHITESP), i++)
- args[i] = a;
- if (i == (qflag? 2: 1))
- continue;
- if (i == MAX_ARGS)
- errx(EX_USAGE, "%s: too many arguments", linename);
- args[i] = NULL;
-
- ip6fw_main(i, args);
- }
- fclose(f);
- if (pflag) {
- if (waitpid(preproc, &status, 0) != -1) {
- if (WIFEXITED(status)) {
- if (WEXITSTATUS(status) != EX_OK)
- errx(EX_UNAVAILABLE,
- "preprocessor exited with status %d",
- WEXITSTATUS(status));
- } else if (WIFSIGNALED(status)) {
- errx(EX_UNAVAILABLE,
- "preprocessor exited with signal %d",
- WTERMSIG(status));
- }
- }
- }
- } else
- ip6fw_main(ac,av);
- return 0;
-}
diff --git a/sbin/ip6fw/sample.sh b/sbin/ip6fw/sample.sh
deleted file mode 100644
index 0064140..0000000
--- a/sbin/ip6fw/sample.sh
+++ /dev/null
@@ -1,28 +0,0 @@
-#!/bin/sh -
-# $FreeBSD$
-
-fwcmd=/sbin/ip6fw
-
-$fwcmd -f flush
-
-#
-# loopback
-#
-$fwcmd add 1000 pass all from any to any via lo0
-
-#
-# ND
-#
-# DAD
-$fwcmd add 2000 pass ipv6-icmp from ff02::/16 to ::
-$fwcmd add 2100 pass ipv6-icmp from :: to ff02::/16
-# RS, RA, NS, NA, redirect...
-$fwcmd add 2300 pass ipv6-icmp from fe80::/10 to fe80::/10
-$fwcmd add 2400 pass ipv6-icmp from fe80::/10 to ff02::/16
-
-$fwcmd add 5000 pass tcp from any to any established
-
-# RIPng
-$fwcmd add 6000 pass udp from fe80::/10 521 to ff02::9 521
-
-$fwcmd add 65000 pass log all from any to any
diff --git a/sys/conf/files b/sys/conf/files
index 3973696..818f7c6 100644
--- a/sys/conf/files
+++ b/sys/conf/files
@@ -1726,7 +1726,6 @@ netinet6/in6_proto.c optional inet6
netinet6/in6_rmx.c optional inet6
netinet6/in6_src.c optional inet6
netinet6/ip6_forward.c optional inet6
-netinet6/ip6_fw.c optional inet6 ipv6firewall
netinet6/ip6_id.c optional inet6
netinet6/ip6_input.c optional inet6
netinet6/ip6_mroute.c optional inet6
diff --git a/sys/conf/options b/sys/conf/options
index a30da2c..76e8d3a 100644
--- a/sys/conf/options
+++ b/sys/conf/options
@@ -366,10 +366,6 @@ IPFIREWALL_VERBOSE_LIMIT opt_ipfw.h
IPFIREWALL_DEFAULT_TO_ACCEPT opt_ipfw.h
IPFIREWALL_FORWARD opt_ipfw.h
IPFIREWALL_FORWARD_EXTENDED opt_ipfw.h
-IPV6FIREWALL opt_ip6fw.h
-IPV6FIREWALL_VERBOSE opt_ip6fw.h
-IPV6FIREWALL_VERBOSE_LIMIT opt_ip6fw.h
-IPV6FIREWALL_DEFAULT_TO_ACCEPT opt_ip6fw.h
IPSTEALTH
IPX
IPXIP opt_ipx.h
diff --git a/sys/modules/Makefile b/sys/modules/Makefile
index d039e01..c5fef74 100644
--- a/sys/modules/Makefile
+++ b/sys/modules/Makefile
@@ -113,7 +113,6 @@ SUBDIR= ${_3dfx} \
if_vlan \
${_iir} \
${_io} \
- ip6fw \
ipdivert \
${_ipfilter} \
ipfw \
diff --git a/sys/modules/ip6fw/Makefile b/sys/modules/ip6fw/Makefile
deleted file mode 100644
index 42ca025..0000000
--- a/sys/modules/ip6fw/Makefile
+++ /dev/null
@@ -1,17 +0,0 @@
-# $FreeBSD$
-
-.PATH: ${.CURDIR}/../../netinet6
-
-KMOD= ip6fw
-SRCS= ip6_fw.c
-
-CFLAGS+= -DIPV6FIREWALL
-
-#If you want it verbose
-#CFLAGS+= -DIPV6FIREWALL_VERBOSE
-#CFLAGS+= -DIPV6FIREWALL_VERBOSE_LIMIT=100
-#
-#If you want it to pass all packets by default
-#CFLAGS+= -DIPV6FIREWALL_DEFAULT_TO_ACCEPT
-
-.include <bsd.kmod.mk>
diff --git a/sys/net/net_osdep.h b/sys/net/net_osdep.h
index 874eeb7..e5eed34 100644
--- a/sys/net/net_osdep.h
+++ b/sys/net/net_osdep.h
@@ -246,8 +246,8 @@
* listen/accept (like tcp).
*
* - header files with defopt (opt_xx.h)
- * FreeBSD3: opt_{inet,ipsec,ip6fw,altq}.h
- * FreeBSD4: opt_{inet,inet6,ipsec,ip6fw,altq}.h
+ * FreeBSD3: opt_{inet,ipsec,altq}.h
+ * FreeBSD4: opt_{inet,inet6,ipsec,altq}.h
* NetBSD: opt_{inet,ipsec,altq}.h
* others: does not use defopt
*
diff --git a/sys/netinet/ip_fw2.c b/sys/netinet/ip_fw2.c
index dacaa57..980d52f 100644
--- a/sys/netinet/ip_fw2.c
+++ b/sys/netinet/ip_fw2.c
@@ -34,7 +34,6 @@
#if !defined(KLD_MODULE)
#include "opt_ipfw.h"
-#include "opt_ip6fw.h"
#include "opt_ipdn.h"
#include "opt_inet.h"
#ifndef INET
diff --git a/sys/netinet6/ip6_forward.c b/sys/netinet6/ip6_forward.c
index 18f0312..3c7d354 100644
--- a/sys/netinet6/ip6_forward.c
+++ b/sys/netinet6/ip6_forward.c
@@ -30,7 +30,6 @@
* SUCH DAMAGE.
*/
-#include "opt_ip6fw.h"
#include "opt_inet.h"
#include "opt_inet6.h"
#include "opt_ipsec.h"
@@ -81,8 +80,6 @@
#define IPSEC
#endif /* FAST_IPSEC */
-#include <netinet6/ip6_fw.h>
-
#include <net/net_osdep.h>
#include <netinet6/ip6protosw.h>
@@ -555,20 +552,6 @@ ip6_forward(m, srcrt)
}
/*
- * Check with the firewall...
- */
- if (ip6_fw_enable && ip6_fw_chk_ptr) {
- u_short port = 0;
- /* If ipfw says divert, we have to just drop packet */
- if ((*ip6_fw_chk_ptr)(&ip6, rt->rt_ifp, &port, &m)) {
- m_freem(m);
- goto freecopy;
- }
- if (!m)
- goto freecopy;
- }
-
- /*
* Fake scoped addresses. Note that even link-local source or
* destinaion can appear, if the originating node just sends the
* packet to us (without address resolution for the destination).
diff --git a/sys/netinet6/ip6_fw.c b/sys/netinet6/ip6_fw.c
deleted file mode 100644
index 6927b60..0000000
--- a/sys/netinet6/ip6_fw.c
+++ /dev/null
@@ -1,1318 +0,0 @@
-/* $FreeBSD$ */
-/* $KAME: ip6_fw.c,v 1.21 2001/01/24 01:25:32 itojun Exp $ */
-
-/*-
- * Copyright (C) 1998, 1999, 2000 and 2001 WIDE Project.
- * All rights reserved.
- *
- * 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
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the 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 PROJECT AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/*-
- * Copyright (c) 1993 Daniel Boulet
- * Copyright (c) 1994 Ugen J.S.Antsilevich
- * Copyright (c) 1996 Alex Nash
- *
- * Redistribution and use in source forms, with and without modification,
- * are permitted provided that this entire comment appears intact.
- *
- * Redistribution in binary form may occur without any restrictions.
- * Obviously, it would be nice if you gave credit where credit is due
- * but requiring it would be too onerous.
- *
- * This software is provided ``AS IS'' without any warranties of any kind.
- */
-
-/*
- * Implement IPv6 packet firewall
- */
-
-#if !defined(KLD_MODULE)
-#include "opt_ip6fw.h"
-#include "opt_inet.h"
-#include "opt_inet6.h"
-#endif
-
-#ifdef IP6DIVERT
-#error "NOT SUPPORTED IPV6 DIVERT"
-#endif
-#ifdef IP6FW_DIVERT_RESTART
-#error "NOT SUPPORTED IPV6 DIVERT"
-#endif
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/malloc.h>
-#include <sys/mbuf.h>
-#include <sys/queue.h>
-#include <sys/kernel.h>
-#include <sys/module.h>
-#include <sys/socket.h>
-#include <sys/socketvar.h>
-#include <sys/syslog.h>
-#include <sys/time.h>
-#include <net/if.h>
-#include <net/route.h>
-#include <netinet/in_systm.h>
-#include <netinet/in.h>
-#include <netinet/ip.h>
-
-#include <netinet/ip6.h>
-#include <netinet6/ip6_var.h>
-#include <netinet6/in6_var.h>
-#include <netinet/icmp6.h>
-
-#include <netinet/in_pcb.h>
-
-#include <netinet6/ip6_fw.h>
-#include <netinet/ip_var.h>
-#include <netinet/tcp.h>
-#include <netinet/tcp_seq.h>
-#include <netinet/tcp_timer.h>
-#include <netinet/tcp_var.h>
-#include <netinet/udp.h>
-
-#include <sys/sysctl.h>
-
-#include <net/net_osdep.h>
-
-MALLOC_DEFINE(M_IP6FW, "Ip6Fw/Ip6Acct", "Ip6Fw/Ip6Acct chain's");
-
-static int fw6_debug = 1;
-#ifdef IPV6FIREWALL_VERBOSE
-static int fw6_verbose = 1;
-#else
-static int fw6_verbose = 0;
-#endif
-#ifdef IPV6FIREWALL_VERBOSE_LIMIT
-static int fw6_verbose_limit = IPV6FIREWALL_VERBOSE_LIMIT;
-#else
-static int fw6_verbose_limit = 0;
-#endif
-
-static LIST_HEAD (ip6_fw_head, ip6_fw_chain) ip6_fw_chain;
-
-SYSCTL_DECL(_net_inet6_ip6);
-static struct sysctl_ctx_list ip6_fw_sysctl_ctx;
-static struct sysctl_oid *ip6_fw_sysctl_tree;
-
-#define dprintf(a) do { \
- if (fw6_debug) \
- printf a; \
- } while (/*CONSTCOND*/ 0)
-#define SNPARGS(buf, len) buf + len, sizeof(buf) > len ? sizeof(buf) - len : 0
-
-static int add_entry6 __P((struct ip6_fw_head *chainptr, struct ip6_fw *frwl));
-static int del_entry6 __P((struct ip6_fw_head *chainptr, u_short number));
-static int zero_entry6 __P((struct mbuf *m));
-static struct ip6_fw *check_ip6fw_struct __P((struct ip6_fw *m));
-static struct ip6_fw *check_ip6fw_mbuf __P((struct mbuf *fw));
-static int ip6opts_match __P((struct ip6_hdr **ip6, struct ip6_fw *f,
- struct mbuf **m,
- int *off, int *nxt, u_short *offset));
-static int port_match6 __P((u_short *portptr, int nports, u_short port,
- int range_flag));
-static int tcp6flg_match __P((struct tcphdr *tcp6, struct ip6_fw *f));
-static int icmp6type_match __P((struct icmp6_hdr * icmp, struct ip6_fw * f));
-static void ip6fw_report __P((struct ip6_fw *f, struct ip6_hdr *ip6,
- struct ifnet *rif, struct ifnet *oif, int off, int nxt));
-
-static int ip6_fw_chk __P((struct ip6_hdr **pip6,
- struct ifnet *oif, u_int16_t *cookie, struct mbuf **m));
-static int ip6_fw_ctl __P((int stage, struct mbuf **mm));
-
-static char err_prefix[] = "ip6_fw_ctl:";
-
-/*
- * Returns 1 if the port is matched by the vector, 0 otherwise
- */
-static
-__inline
-int
-port_match6(u_short *portptr, int nports, u_short port, int range_flag)
-{
- if (!nports)
- return 1;
- if (range_flag) {
- if (portptr[0] <= port && port <= portptr[1]) {
- return 1;
- }
- nports -= 2;
- portptr += 2;
- }
- while (nports-- > 0) {
- if (*portptr++ == port) {
- return 1;
- }
- }
- return 0;
-}
-
-static int
-tcp6flg_match(struct tcphdr *tcp6, struct ip6_fw *f)
-{
- u_char flg_set, flg_clr;
-
- /*
- * If an established connection is required, reject packets that
- * have only SYN of RST|ACK|SYN set. Otherwise, fall through to
- * other flag requirements.
- */
- if ((f->fw_ipflg & IPV6_FW_IF_TCPEST) &&
- ((tcp6->th_flags & (IPV6_FW_TCPF_RST | IPV6_FW_TCPF_ACK |
- IPV6_FW_TCPF_SYN)) == IPV6_FW_TCPF_SYN))
- return 0;
-
- flg_set = tcp6->th_flags & f->fw_tcpf;
- flg_clr = tcp6->th_flags & f->fw_tcpnf;
-
- if (flg_set != f->fw_tcpf)
- return 0;
- if (flg_clr)
- return 0;
-
- return 1;
-}
-
-static int
-icmp6type_match(struct icmp6_hdr *icmp6, struct ip6_fw *f)
-{
- int type;
-
- if (!(f->fw_flg & IPV6_FW_F_ICMPBIT))
- return (1);
-
- type = icmp6->icmp6_type;
-
- /* check for matching type in the bitmap */
- if (type < IPV6_FW_ICMPTYPES_DIM * sizeof(unsigned) * 8 &&
- (f->fw_icmp6types[type / (sizeof(unsigned) * 8)] &
- (1U << (type % (8 * sizeof(unsigned))))))
- return (1);
-
- return (0); /* no match */
-}
-
-static int
-is_icmp6_query(struct ip6_hdr *ip6, int off)
-{
- const struct icmp6_hdr *icmp6;
- int icmp6_type;
-
- icmp6 = (struct icmp6_hdr *)((caddr_t)ip6 + off);
- icmp6_type = icmp6->icmp6_type;
-
- if (icmp6_type == ICMP6_ECHO_REQUEST ||
- icmp6_type == ICMP6_MEMBERSHIP_QUERY ||
- icmp6_type == ICMP6_WRUREQUEST ||
- icmp6_type == ICMP6_FQDN_QUERY ||
- icmp6_type == ICMP6_NI_QUERY)
- return (1);
-
- return (0);
-}
-
-static int
-ip6opts_match(struct ip6_hdr **pip6, struct ip6_fw *f, struct mbuf **m,
- int *off, int *nxt, u_short *offset)
-{
- int len;
- struct ip6_hdr *ip6 = *pip6;
- struct ip6_ext *ip6e;
- u_char opts, nopts, nopts_sve;
-
- opts = f->fw_ip6opt;
- nopts = nopts_sve = f->fw_ip6nopt;
-
- *nxt = ip6->ip6_nxt;
- *off = sizeof(struct ip6_hdr);
- len = ntohs(ip6->ip6_plen) + sizeof(struct ip6_hdr);
- while (*off < len) {
- ip6e = (struct ip6_ext *)((caddr_t) ip6 + *off);
- if ((*m)->m_len < *off + sizeof(*ip6e))
- goto opts_check; /* XXX */
-
- switch (*nxt) {
- case IPPROTO_FRAGMENT:
- if ((*m)->m_len >= *off + sizeof(struct ip6_frag)) {
- struct ip6_frag *ip6f;
-
- ip6f = (struct ip6_frag *) ((caddr_t)ip6 + *off);
- *offset = ip6f->ip6f_offlg & IP6F_OFF_MASK;
- }
- opts &= ~IPV6_FW_IP6OPT_FRAG;
- nopts &= ~IPV6_FW_IP6OPT_FRAG;
- *off += sizeof(struct ip6_frag);
- break;
- case IPPROTO_AH:
- opts &= ~IPV6_FW_IP6OPT_AH;
- nopts &= ~IPV6_FW_IP6OPT_AH;
- *off += (ip6e->ip6e_len + 2) << 2;
- break;
- default:
- switch (*nxt) {
- case IPPROTO_HOPOPTS:
- opts &= ~IPV6_FW_IP6OPT_HOPOPT;
- nopts &= ~IPV6_FW_IP6OPT_HOPOPT;
- break;
- case IPPROTO_ROUTING:
- opts &= ~IPV6_FW_IP6OPT_ROUTE;
- nopts &= ~IPV6_FW_IP6OPT_ROUTE;
- break;
- case IPPROTO_ESP:
- opts &= ~IPV6_FW_IP6OPT_ESP;
- nopts &= ~IPV6_FW_IP6OPT_ESP;
- goto opts_check;
- case IPPROTO_NONE:
- opts &= ~IPV6_FW_IP6OPT_NONXT;
- nopts &= ~IPV6_FW_IP6OPT_NONXT;
- goto opts_check;
- case IPPROTO_DSTOPTS:
- opts &= ~IPV6_FW_IP6OPT_OPTS;
- nopts &= ~IPV6_FW_IP6OPT_OPTS;
- break;
- default:
- goto opts_check;
- }
- *off += (ip6e->ip6e_len + 1) << 3;
- break;
- }
- *nxt = ip6e->ip6e_nxt;
-
- }
- opts_check:
- if (f->fw_ip6opt == f->fw_ip6nopt) /* XXX */
- return 1;
-
- if (opts == 0 && nopts == nopts_sve)
- return 1;
- else
- return 0;
-}
-
-static
-__inline
-int
-iface_match(struct ifnet *ifp, union ip6_fw_if *ifu, int byname)
-{
- /* Check by name or by IP address */
- if (byname) {
- /* Check name */
- if (ifu->fu_via_if.glob) {
- if (fnmatch(ifu->fu_via_if.name, ifp->if_xname, 0)
- == FNM_NOMATCH)
- return(0);
- } else {
- if (strncmp(ifp->if_xname, ifu->fu_via_if.name,
- IP6FW_IFNLEN) != 0)
- return(0);
- }
- return(1);
- } else if (!IN6_IS_ADDR_UNSPECIFIED(&ifu->fu_via_ip6)) { /* Zero == wildcard */
- struct ifaddr *ia;
-
- for (ia = ifp->if_addrlist.tqh_first; ia; ia = ia->ifa_list.tqe_next) {
-
- if (ia->ifa_addr == NULL)
- continue;
- if (ia->ifa_addr->sa_family != AF_INET6)
- continue;
- if (!IN6_ARE_ADDR_EQUAL(&ifu->fu_via_ip6,
- &(((struct sockaddr_in6 *)
- (ia->ifa_addr))->sin6_addr)))
- continue;
- return (1);
- }
- return (0);
- }
- return (1);
-}
-
-static void
-ip6fw_report(struct ip6_fw *f, struct ip6_hdr *ip6,
- struct ifnet *rif, struct ifnet *oif, int off, int nxt)
-{
- static int counter;
- struct tcphdr *const tcp6 = (struct tcphdr *) ((caddr_t) ip6+ off);
- struct udphdr *const udp = (struct udphdr *) ((caddr_t) ip6+ off);
- struct icmp6_hdr *const icmp6 = (struct icmp6_hdr *) ((caddr_t) ip6+ off);
- int count;
- char *action;
- char action2[32], proto[102], name[18];
- int len;
-
- count = f ? f->fw_pcnt : ++counter;
- if (fw6_verbose_limit != 0 && count > fw6_verbose_limit)
- return;
-
- /* Print command name */
- snprintf(SNPARGS(name, 0), "ip6fw: %d", f ? f->fw_number : -1);
-
- action = action2;
- if (!f)
- action = "Refuse";
- else {
- switch (f->fw_flg & IPV6_FW_F_COMMAND) {
- case IPV6_FW_F_DENY:
- action = "Deny";
- break;
- case IPV6_FW_F_REJECT:
- if (f->fw_reject_code == IPV6_FW_REJECT_RST)
- action = "Reset";
- else
- action = "Unreach";
- break;
- case IPV6_FW_F_ACCEPT:
- action = "Accept";
- break;
- case IPV6_FW_F_COUNT:
- action = "Count";
- break;
- case IPV6_FW_F_DIVERT:
- snprintf(SNPARGS(action2, 0), "Divert %d",
- f->fw_divert_port);
- break;
- case IPV6_FW_F_TEE:
- snprintf(SNPARGS(action2, 0), "Tee %d",
- f->fw_divert_port);
- break;
- case IPV6_FW_F_SKIPTO:
- snprintf(SNPARGS(action2, 0), "SkipTo %d",
- f->fw_skipto_rule);
- break;
- default:
- action = "UNKNOWN";
- break;
- }
- }
-
- switch (nxt) {
- case IPPROTO_TCP:
- len = snprintf(SNPARGS(proto, 0), "TCP [%s]",
- ip6_sprintf(&ip6->ip6_src));
- if (off > 0)
- len += snprintf(SNPARGS(proto, len), ":%d ",
- ntohs(tcp6->th_sport));
- else
- len += snprintf(SNPARGS(proto, len), " ");
- len += snprintf(SNPARGS(proto, len), "[%s]",
- ip6_sprintf(&ip6->ip6_dst));
- if (off > 0)
- snprintf(SNPARGS(proto, len), ":%d",
- ntohs(tcp6->th_dport));
- break;
- case IPPROTO_UDP:
- len = snprintf(SNPARGS(proto, 0), "UDP [%s]",
- ip6_sprintf(&ip6->ip6_src));
- if (off > 0)
- len += snprintf(SNPARGS(proto, len), ":%d ",
- ntohs(udp->uh_sport));
- else
- len += snprintf(SNPARGS(proto, len), " ");
- len += snprintf(SNPARGS(proto, len), "[%s]",
- ip6_sprintf(&ip6->ip6_dst));
- if (off > 0)
- snprintf(SNPARGS(proto, len), ":%d",
- ntohs(udp->uh_dport));
- break;
- case IPPROTO_ICMPV6:
- if (off > 0)
- len = snprintf(SNPARGS(proto, 0), "IPV6-ICMP:%u.%u ",
- icmp6->icmp6_type, icmp6->icmp6_code);
- else
- len = snprintf(SNPARGS(proto, 0), "IPV6-ICMP ");
- len += snprintf(SNPARGS(proto, len), "[%s]",
- ip6_sprintf(&ip6->ip6_src));
- snprintf(SNPARGS(proto, len), " [%s]",
- ip6_sprintf(&ip6->ip6_dst));
- break;
- default:
- len = snprintf(SNPARGS(proto, 0), "P:%d [%s]", nxt,
- ip6_sprintf(&ip6->ip6_src));
- snprintf(SNPARGS(proto, len), " [%s]",
- ip6_sprintf(&ip6->ip6_dst));
- break;
- }
-
- if (oif)
- log(LOG_SECURITY | LOG_INFO, "%s %s %s out via %s\n",
- name, action, proto, if_name(oif));
- else if (rif)
- log(LOG_SECURITY | LOG_INFO, "%s %s %s in via %s\n",
- name, action, proto, if_name(rif));
- else
- log(LOG_SECURITY | LOG_INFO, "%s %s %s",
- name, action, proto);
- if (fw6_verbose_limit != 0 && count == fw6_verbose_limit)
- log(LOG_SECURITY | LOG_INFO, "ip6fw: limit reached on entry %d\n",
- f ? f->fw_number : -1);
-}
-
-/*
- * Parameters:
- *
- * ip Pointer to packet header (struct ip6_hdr *)
- * hlen Packet header length
- * oif Outgoing interface, or NULL if packet is incoming
- * #ifndef IP6FW_DIVERT_RESTART
- * *cookie Ignore all divert/tee rules to this port (if non-zero)
- * #else
- * *cookie Skip up to the first rule past this rule number;
- * #endif
- * *m The packet; we set to NULL when/if we nuke it.
- *
- * Return value:
- *
- * 0 The packet is to be accepted and routed normally OR
- * the packet was denied/rejected and has been dropped;
- * in the latter case, *m is equal to NULL upon return.
- * port Divert the packet to port.
- */
-
-static int
-ip6_fw_chk(struct ip6_hdr **pip6,
- struct ifnet *oif, u_int16_t *cookie, struct mbuf **m)
-{
- struct ip6_fw_chain *chain;
- struct ip6_fw *rule = NULL;
- struct ip6_hdr *ip6 = *pip6;
- struct ifnet *const rif = (*m)->m_pkthdr.rcvif;
- u_short offset = 0;
- int off = sizeof(struct ip6_hdr), nxt = ip6->ip6_nxt;
- u_short src_port, dst_port;
-#ifdef IP6FW_DIVERT_RESTART
- u_int16_t skipto = *cookie;
-#else
- u_int16_t ignport = ntohs(*cookie);
-#endif
-
- *cookie = 0;
- /*
- * Go down the chain, looking for enlightment
- * #ifdef IP6FW_DIVERT_RESTART
- * If we've been asked to start at a given rule immediatly, do so.
- * #endif
- */
- chain = LIST_FIRST(&ip6_fw_chain);
-#ifdef IP6FW_DIVERT_RESTART
- if (skipto) {
- if (skipto >= 65535)
- goto dropit;
- while (chain && (chain->rule->fw_number <= skipto)) {
- chain = LIST_NEXT(chain, chain);
- }
- if (! chain) goto dropit;
- }
-#endif /* IP6FW_DIVERT_RESTART */
- for (; chain; chain = LIST_NEXT(chain, chain)) {
- struct ip6_fw *const f = chain->rule;
-
- if (oif) {
- /* Check direction outbound */
- if (!(f->fw_flg & IPV6_FW_F_OUT))
- continue;
- } else {
- /* Check direction inbound */
- if (!(f->fw_flg & IPV6_FW_F_IN))
- continue;
- }
-
-#define IN6_ARE_ADDR_MASKEQUAL(x,y,z) (\
- (((x)->s6_addr32[0] & (y)->s6_addr32[0]) == (z)->s6_addr32[0]) && \
- (((x)->s6_addr32[1] & (y)->s6_addr32[1]) == (z)->s6_addr32[1]) && \
- (((x)->s6_addr32[2] & (y)->s6_addr32[2]) == (z)->s6_addr32[2]) && \
- (((x)->s6_addr32[3] & (y)->s6_addr32[3]) == (z)->s6_addr32[3]))
-
- /* If src-addr doesn't match, not this rule. */
- if (((f->fw_flg & IPV6_FW_F_INVSRC) != 0) ^
- (!IN6_ARE_ADDR_MASKEQUAL(&ip6->ip6_src,&f->fw_smsk,&f->fw_src)))
- continue;
-
- /* If dest-addr doesn't match, not this rule. */
- if (((f->fw_flg & IPV6_FW_F_INVDST) != 0) ^
- (!IN6_ARE_ADDR_MASKEQUAL(&ip6->ip6_dst,&f->fw_dmsk,&f->fw_dst)))
- continue;
-
-#undef IN6_ARE_ADDR_MASKEQUAL
- /* Interface check */
- if ((f->fw_flg & IF6_FW_F_VIAHACK) == IF6_FW_F_VIAHACK) {
- struct ifnet *const iface = oif ? oif : rif;
-
- /* Backwards compatibility hack for "via" */
- if (!iface || !iface_match(iface,
- &f->fw_in_if, f->fw_flg & IPV6_FW_F_OIFNAME))
- continue;
- } else {
- /* Check receive interface */
- if ((f->fw_flg & IPV6_FW_F_IIFACE)
- && (!rif || !iface_match(rif,
- &f->fw_in_if, f->fw_flg & IPV6_FW_F_IIFNAME)))
- continue;
- /* Check outgoing interface */
- if ((f->fw_flg & IPV6_FW_F_OIFACE)
- && (!oif || !iface_match(oif,
- &f->fw_out_if, f->fw_flg & IPV6_FW_F_OIFNAME)))
- continue;
- }
-
- /* Check IP options */
- if (!ip6opts_match(&ip6, f, m, &off, &nxt, &offset))
- continue;
-
- /* Fragments */
- if ((f->fw_flg & IPV6_FW_F_FRAG) && !offset)
- continue;
-
- /* Check protocol; if wildcard, match */
- if (f->fw_prot == IPPROTO_IPV6)
- goto got_match;
-
- /* If different, don't match */
- if (nxt != f->fw_prot)
- continue;
-
-#define PULLUP_TO(len) do { \
- if ((*m)->m_len < (len) \
- && (*m = m_pullup(*m, (len))) == 0) { \
- goto dropit; \
- } \
- *pip6 = ip6 = mtod(*m, struct ip6_hdr *); \
- } while (/*CONSTCOND*/ 0)
-
- /* Protocol specific checks */
- switch (nxt) {
- case IPPROTO_TCP:
- {
- struct tcphdr *tcp6;
-
- if (offset == 1) { /* cf. RFC 1858 */
- PULLUP_TO(off + 4); /* XXX ? */
- goto bogusfrag;
- }
- if (offset != 0) {
- /*
- * TCP flags and ports aren't available in this
- * packet -- if this rule specified either one,
- * we consider the rule a non-match.
- */
- if (f->fw_nports != 0 ||
- f->fw_tcpf != f->fw_tcpnf)
- continue;
-
- break;
- }
- PULLUP_TO(off + 14);
- tcp6 = (struct tcphdr *) ((caddr_t)ip6 + off);
- if (((f->fw_tcpf != f->fw_tcpnf) ||
- (f->fw_ipflg & IPV6_FW_IF_TCPEST)) &&
- !tcp6flg_match(tcp6, f))
- continue;
- src_port = ntohs(tcp6->th_sport);
- dst_port = ntohs(tcp6->th_dport);
- goto check_ports;
- }
-
- case IPPROTO_UDP:
- {
- struct udphdr *udp;
-
- if (offset != 0) {
- /*
- * Port specification is unavailable -- if this
- * rule specifies a port, we consider the rule
- * a non-match.
- */
- if (f->fw_nports != 0)
- continue;
-
- break;
- }
- PULLUP_TO(off + 4);
- udp = (struct udphdr *) ((caddr_t)ip6 + off);
- src_port = ntohs(udp->uh_sport);
- dst_port = ntohs(udp->uh_dport);
-check_ports:
- if (!port_match6(&f->fw_pts[0],
- IPV6_FW_GETNSRCP(f), src_port,
- f->fw_flg & IPV6_FW_F_SRNG))
- continue;
- if (!port_match6(&f->fw_pts[IPV6_FW_GETNSRCP(f)],
- IPV6_FW_GETNDSTP(f), dst_port,
- f->fw_flg & IPV6_FW_F_DRNG))
- continue;
- break;
- }
-
- case IPPROTO_ICMPV6:
- {
- struct icmp6_hdr *icmp;
-
- if (offset != 0) /* Type isn't valid */
- break;
- PULLUP_TO(off + 2);
- icmp = (struct icmp6_hdr *) ((caddr_t)ip6 + off);
- if (!icmp6type_match(icmp, f))
- continue;
- break;
- }
-#undef PULLUP_TO
-
-bogusfrag:
- if (fw6_verbose)
- ip6fw_report(NULL, ip6, rif, oif, off, nxt);
- goto dropit;
- }
-
-got_match:
-#ifndef IP6FW_DIVERT_RESTART
- /* Ignore divert/tee rule if socket port is "ignport" */
- switch (f->fw_flg & IPV6_FW_F_COMMAND) {
- case IPV6_FW_F_DIVERT:
- case IPV6_FW_F_TEE:
- if (f->fw_divert_port == ignport)
- continue; /* ignore this rule */
- break;
- }
-
-#endif /* IP6FW_DIVERT_RESTART */
- /* Update statistics */
- f->fw_pcnt += 1;
- f->fw_bcnt += ntohs(ip6->ip6_plen);
- f->timestamp = time_second;
-
- /* Log to console if desired */
- if ((f->fw_flg & IPV6_FW_F_PRN) && fw6_verbose)
- ip6fw_report(f, ip6, rif, oif, off, nxt);
-
- /* Take appropriate action */
- switch (f->fw_flg & IPV6_FW_F_COMMAND) {
- case IPV6_FW_F_ACCEPT:
- return (0);
- case IPV6_FW_F_COUNT:
- continue;
- case IPV6_FW_F_DIVERT:
-#ifdef IP6FW_DIVERT_RESTART
- *cookie = f->fw_number;
-#else
- *cookie = htons(f->fw_divert_port);
-#endif /* IP6FW_DIVERT_RESTART */
- return (f->fw_divert_port);
- case IPV6_FW_F_TEE:
- /*
- * XXX someday tee packet here, but beware that you
- * can't use m_copym() or m_copypacket() because
- * the divert input routine modifies the mbuf
- * (and these routines only increment reference
- * counts in the case of mbuf clusters), so need
- * to write custom routine.
- */
- continue;
- case IPV6_FW_F_SKIPTO:
-#ifdef DIAGNOSTIC
- while (chain->chain.le_next
- && chain->chain.le_next->rule->fw_number
- < f->fw_skipto_rule)
-#else
- while (chain->chain.le_next->rule->fw_number
- < f->fw_skipto_rule)
-#endif
- chain = chain->chain.le_next;
- continue;
- }
-
- /* Deny/reject this packet using this rule */
- rule = f;
- break;
- }
-
-#ifdef DIAGNOSTIC
- /* Rule 65535 should always be there and should always match */
- if (!chain)
- panic("ip6_fw: chain");
-#endif
-
- /*
- * At this point, we're going to drop the packet.
- * Send a reject notice if all of the following are true:
- *
- * - The packet matched a reject rule
- * - The packet is not an ICMP packet, or is an ICMP query packet
- * - The packet is not a multicast or broadcast packet
- */
- if (rule && (rule->fw_flg & IPV6_FW_F_COMMAND) == IPV6_FW_F_REJECT
- && (nxt != IPPROTO_ICMPV6 || is_icmp6_query(ip6, off))
- && !((*m)->m_flags & (M_BCAST|M_MCAST))
- && !IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst)) {
- switch (rule->fw_reject_code) {
- case IPV6_FW_REJECT_RST:
-#if 1 /* not tested */
- {
- struct tcphdr *const tcp =
- (struct tcphdr *) ((caddr_t)ip6 + off);
- struct {
- struct ip6_hdr ip6;
- struct tcphdr th;
- } ti;
- tcp_seq ack, seq;
- int flags;
-
- if (offset != 0 || (tcp->th_flags & TH_RST))
- break;
-
- ti.ip6 = *ip6;
- ti.th = *tcp;
- ti.th.th_seq = ntohl(ti.th.th_seq);
- ti.th.th_ack = ntohl(ti.th.th_ack);
- ti.ip6.ip6_nxt = IPPROTO_TCP;
- if (ti.th.th_flags & TH_ACK) {
- ack = 0;
- seq = ti.th.th_ack;
- flags = TH_RST;
- } else {
- ack = ti.th.th_seq;
- if (((*m)->m_flags & M_PKTHDR) != 0) {
- ack += (*m)->m_pkthdr.len - off
- - (ti.th.th_off << 2);
- } else if (ip6->ip6_plen) {
- ack += ntohs(ip6->ip6_plen) + sizeof(*ip6)
- - off - (ti.th.th_off << 2);
- } else {
- m_freem(*m);
- *m = 0;
- break;
- }
- if (tcp->th_flags & TH_SYN)
- ack++;
- seq = 0;
- flags = TH_RST|TH_ACK;
- }
- bcopy(&ti, ip6, sizeof(ti));
- tcp_respond(NULL, ip6, (struct tcphdr *)(ip6 + 1),
- *m, ack, seq, flags);
- *m = NULL;
- break;
- }
-#endif
- default: /* Send an ICMP unreachable using code */
- if (oif)
- (*m)->m_pkthdr.rcvif = oif;
- icmp6_error(*m, ICMP6_DST_UNREACH,
- rule->fw_reject_code, 0);
- *m = NULL;
- break;
- }
- }
-
-dropit:
- /*
- * Finally, drop the packet.
- */
- if (*m) {
- m_freem(*m);
- *m = NULL;
- }
- return (0);
-}
-
-static int
-add_entry6(struct ip6_fw_head *chainptr, struct ip6_fw *frwl)
-{
- struct ip6_fw *ftmp = 0;
- struct ip6_fw_chain *fwc = 0, *fcp, *fcpl = 0;
- u_short nbr = 0;
- int s;
-
- fwc = malloc(sizeof *fwc, M_IP6FW, M_NOWAIT);
- ftmp = malloc(sizeof *ftmp, M_IP6FW, M_NOWAIT);
- if (!fwc || !ftmp) {
- dprintf(("%s malloc said no\n", err_prefix));
- if (fwc) free(fwc, M_IP6FW);
- if (ftmp) free(ftmp, M_IP6FW);
- return (ENOSPC);
- }
-
- bcopy(frwl, ftmp, sizeof(struct ip6_fw));
- ftmp->fw_in_if.fu_via_if.name[IP6FW_IFNLEN - 1] = '\0';
- ftmp->fw_pcnt = 0L;
- ftmp->fw_bcnt = 0L;
- fwc->rule = ftmp;
-
- s = splnet();
-
- if (!chainptr->lh_first) {
- LIST_INSERT_HEAD(chainptr, fwc, chain);
- splx(s);
- return (0);
- } else if (ftmp->fw_number == (u_short)-1) {
- if (fwc) free(fwc, M_IP6FW);
- if (ftmp) free(ftmp, M_IP6FW);
- splx(s);
- dprintf(("%s bad rule number\n", err_prefix));
- return (EINVAL);
- }
-
- /* If entry number is 0, find highest numbered rule and add 100 */
- if (ftmp->fw_number == 0) {
- for (fcp = chainptr->lh_first; fcp; fcp = fcp->chain.le_next) {
- if (fcp->rule->fw_number != (u_short)-1)
- nbr = fcp->rule->fw_number;
- else
- break;
- }
- if (nbr < (u_short)-1 - 100)
- nbr += 100;
- ftmp->fw_number = nbr;
- }
-
- /* Got a valid number; now insert it, keeping the list ordered */
- for (fcp = chainptr->lh_first; fcp; fcp = fcp->chain.le_next) {
- if (fcp->rule->fw_number > ftmp->fw_number) {
- if (fcpl) {
- LIST_INSERT_AFTER(fcpl, fwc, chain);
- } else {
- LIST_INSERT_HEAD(chainptr, fwc, chain);
- }
- break;
- } else {
- fcpl = fcp;
- }
- }
-
- splx(s);
- return (0);
-}
-
-static int
-del_entry6(struct ip6_fw_head *chainptr, u_short number)
-{
- struct ip6_fw_chain *fcp;
- int s;
-
- s = splnet();
-
- fcp = chainptr->lh_first;
- if (number != (u_short)-1) {
- for (; fcp; fcp = fcp->chain.le_next) {
- if (fcp->rule->fw_number == number) {
- LIST_REMOVE(fcp, chain);
- splx(s);
- free(fcp->rule, M_IP6FW);
- free(fcp, M_IP6FW);
- return 0;
- }
- }
- }
-
- splx(s);
- return (EINVAL);
-}
-
-static int
-zero_entry6(struct mbuf *m)
-{
- struct ip6_fw *frwl;
- struct ip6_fw_chain *fcp;
- int s;
-
- if (m && m->m_len != 0) {
- if (m->m_len != sizeof(struct ip6_fw))
- return (EINVAL);
- frwl = mtod(m, struct ip6_fw *);
- }
- else
- frwl = NULL;
-
- /*
- * It's possible to insert multiple chain entries with the
- * same number, so we don't stop after finding the first
- * match if zeroing a specific entry.
- */
- s = splnet();
- for (fcp = ip6_fw_chain.lh_first; fcp; fcp = fcp->chain.le_next)
- if (!frwl || frwl->fw_number == fcp->rule->fw_number) {
- fcp->rule->fw_bcnt = fcp->rule->fw_pcnt = 0;
- fcp->rule->timestamp = 0;
- }
- splx(s);
-
- if (fw6_verbose) {
- if (frwl)
- log(LOG_SECURITY | LOG_NOTICE,
- "ip6fw: Entry %d cleared.\n", frwl->fw_number);
- else
- log(LOG_SECURITY | LOG_NOTICE,
- "ip6fw: Accounting cleared.\n");
- }
-
- return (0);
-}
-
-static struct ip6_fw *
-check_ip6fw_mbuf(struct mbuf *m)
-{
- /* Check length */
- if (m->m_len != sizeof(struct ip6_fw)) {
- dprintf(("%s len=%d, want %zu\n", err_prefix, m->m_len,
- sizeof(struct ip6_fw)));
- return (NULL);
- }
- return (check_ip6fw_struct(mtod(m, struct ip6_fw *)));
-}
-
-static struct ip6_fw *
-check_ip6fw_struct(struct ip6_fw *frwl)
-{
- /* Check for invalid flag bits */
- if ((frwl->fw_flg & ~IPV6_FW_F_MASK) != 0) {
- dprintf(("%s undefined flag bits set (flags=%x)\n",
- err_prefix, frwl->fw_flg));
- return (NULL);
- }
- /* Must apply to incoming or outgoing (or both) */
- if (!(frwl->fw_flg & (IPV6_FW_F_IN | IPV6_FW_F_OUT))) {
- dprintf(("%s neither in nor out\n", err_prefix));
- return (NULL);
- }
- /* Empty interface name is no good */
- if (((frwl->fw_flg & IPV6_FW_F_IIFNAME)
- && !*frwl->fw_in_if.fu_via_if.name)
- || ((frwl->fw_flg & IPV6_FW_F_OIFNAME)
- && !*frwl->fw_out_if.fu_via_if.name)) {
- dprintf(("%s empty interface name\n", err_prefix));
- return (NULL);
- }
- /* Sanity check interface matching */
- if ((frwl->fw_flg & IF6_FW_F_VIAHACK) == IF6_FW_F_VIAHACK) {
- ; /* allow "via" backwards compatibility */
- } else if ((frwl->fw_flg & IPV6_FW_F_IN)
- && (frwl->fw_flg & IPV6_FW_F_OIFACE)) {
- dprintf(("%s outgoing interface check on incoming\n",
- err_prefix));
- return (NULL);
- }
- /* Sanity check port ranges */
- if ((frwl->fw_flg & IPV6_FW_F_SRNG) && IPV6_FW_GETNSRCP(frwl) < 2) {
- dprintf(("%s src range set but n_src_p=%d\n",
- err_prefix, IPV6_FW_GETNSRCP(frwl)));
- return (NULL);
- }
- if ((frwl->fw_flg & IPV6_FW_F_DRNG) && IPV6_FW_GETNDSTP(frwl) < 2) {
- dprintf(("%s dst range set but n_dst_p=%d\n",
- err_prefix, IPV6_FW_GETNDSTP(frwl)));
- return (NULL);
- }
- if (IPV6_FW_GETNSRCP(frwl) + IPV6_FW_GETNDSTP(frwl) > IPV6_FW_MAX_PORTS) {
- dprintf(("%s too many ports (%d+%d)\n",
- err_prefix, IPV6_FW_GETNSRCP(frwl), IPV6_FW_GETNDSTP(frwl)));
- return (NULL);
- }
- /*
- * Protocols other than TCP/UDP don't use port range
- */
- if ((frwl->fw_prot != IPPROTO_TCP) &&
- (frwl->fw_prot != IPPROTO_UDP) &&
- (IPV6_FW_GETNSRCP(frwl) || IPV6_FW_GETNDSTP(frwl))) {
- dprintf(("%s port(s) specified for non TCP/UDP rule\n",
- err_prefix));
- return (NULL);
- }
-
- /*
- * Rather than modify the entry to make such entries work,
- * we reject this rule and require user level utilities
- * to enforce whatever policy they deem appropriate.
- */
- if ((frwl->fw_src.s6_addr32[0] & (~frwl->fw_smsk.s6_addr32[0])) ||
- (frwl->fw_src.s6_addr32[1] & (~frwl->fw_smsk.s6_addr32[1])) ||
- (frwl->fw_src.s6_addr32[2] & (~frwl->fw_smsk.s6_addr32[2])) ||
- (frwl->fw_src.s6_addr32[3] & (~frwl->fw_smsk.s6_addr32[3])) ||
- (frwl->fw_dst.s6_addr32[0] & (~frwl->fw_dmsk.s6_addr32[0])) ||
- (frwl->fw_dst.s6_addr32[1] & (~frwl->fw_dmsk.s6_addr32[1])) ||
- (frwl->fw_dst.s6_addr32[2] & (~frwl->fw_dmsk.s6_addr32[2])) ||
- (frwl->fw_dst.s6_addr32[3] & (~frwl->fw_dmsk.s6_addr32[3]))) {
- dprintf(("%s rule never matches\n", err_prefix));
- return (NULL);
- }
-
- if ((frwl->fw_flg & IPV6_FW_F_FRAG) &&
- (frwl->fw_prot == IPPROTO_UDP || frwl->fw_prot == IPPROTO_TCP)) {
- if (frwl->fw_nports) {
- dprintf(("%s cannot mix 'frag' and ports\n", err_prefix));
- return (NULL);
- }
- if (frwl->fw_prot == IPPROTO_TCP &&
- frwl->fw_tcpf != frwl->fw_tcpnf) {
- dprintf(("%s cannot mix 'frag' with TCP flags\n", err_prefix));
- return (NULL);
- }
- }
-
- /* Check command specific stuff */
- switch (frwl->fw_flg & IPV6_FW_F_COMMAND)
- {
- case IPV6_FW_F_REJECT:
- if (frwl->fw_reject_code >= 0x100
- && !(frwl->fw_prot == IPPROTO_TCP
- && frwl->fw_reject_code == IPV6_FW_REJECT_RST)) {
- dprintf(("%s unknown reject code\n", err_prefix));
- return (NULL);
- }
- break;
- case IPV6_FW_F_DIVERT: /* Diverting to port zero is invalid */
- case IPV6_FW_F_TEE:
- if (frwl->fw_divert_port == 0) {
- dprintf(("%s can't divert to port 0\n", err_prefix));
- return (NULL);
- }
- break;
- case IPV6_FW_F_DENY:
- case IPV6_FW_F_ACCEPT:
- case IPV6_FW_F_COUNT:
- case IPV6_FW_F_SKIPTO:
- break;
- default:
- dprintf(("%s invalid command\n", err_prefix));
- return (NULL);
- }
-
- return frwl;
-}
-
-static int
-ip6_fw_ctl(int stage, struct mbuf **mm)
-{
- int error;
- struct mbuf *m;
-
- if (stage == IPV6_FW_GET) {
- struct ip6_fw_chain *fcp = ip6_fw_chain.lh_first;
- *mm = m = m_get(M_TRYWAIT, MT_DATA); /* XXX */
- if (!m)
- return (ENOBUFS);
- if (sizeof *(fcp->rule) > MLEN) {
- MCLGET(m, M_TRYWAIT);
- if ((m->m_flags & M_EXT) == 0) {
- m_free(m);
- return (ENOBUFS);
- }
- }
- for (; fcp; fcp = fcp->chain.le_next) {
- bcopy(fcp->rule, m->m_data, sizeof *(fcp->rule));
- m->m_len = sizeof *(fcp->rule);
- m->m_next = m_get(M_TRYWAIT, MT_DATA); /* XXX */
- if (!m->m_next) {
- m_freem(*mm);
- return (ENOBUFS);
- }
- m = m->m_next;
- if (sizeof *(fcp->rule) > MLEN) {
- MCLGET(m, M_TRYWAIT);
- if ((m->m_flags & M_EXT) == 0) {
- m_freem(*mm);
- return (ENOBUFS);
- }
- }
- m->m_len = 0;
- }
- return (0);
- }
- m = *mm;
- /* only allow get calls if secure mode > 2 */
- if (securelevel > 2) {
- if (m) {
- (void)m_freem(m);
- *mm = 0;
- }
- return (EPERM);
- }
- if (stage == IPV6_FW_FLUSH) {
- while (ip6_fw_chain.lh_first != NULL &&
- ip6_fw_chain.lh_first->rule->fw_number != (u_short)-1) {
- struct ip6_fw_chain *fcp = ip6_fw_chain.lh_first;
- int s = splnet();
- LIST_REMOVE(ip6_fw_chain.lh_first, chain);
- splx(s);
- free(fcp->rule, M_IP6FW);
- free(fcp, M_IP6FW);
- }
- if (m) {
- (void)m_freem(m);
- *mm = 0;
- }
- return (0);
- }
- if (stage == IPV6_FW_ZERO) {
- error = zero_entry6(m);
- if (m) {
- (void)m_freem(m);
- *mm = 0;
- }
- return (error);
- }
- if (m == NULL) {
- printf("%s NULL mbuf ptr\n", err_prefix);
- return (EINVAL);
- }
-
- if (stage == IPV6_FW_ADD) {
- struct ip6_fw *frwl = check_ip6fw_mbuf(m);
-
- if (!frwl)
- error = EINVAL;
- else
- error = add_entry6(&ip6_fw_chain, frwl);
- if (m) {
- (void)m_freem(m);
- *mm = 0;
- }
- return error;
- }
- if (stage == IPV6_FW_DEL) {
- if (m->m_len != sizeof(struct ip6_fw)) {
- dprintf(("%s len=%d, want %zu\n", err_prefix, m->m_len,
- sizeof(struct ip6_fw)));
- error = EINVAL;
- } else if (mtod(m, struct ip6_fw *)->fw_number == (u_short)-1) {
- dprintf(("%s can't delete rule 65535\n", err_prefix));
- error = EINVAL;
- } else
- error = del_entry6(&ip6_fw_chain,
- mtod(m, struct ip6_fw *)->fw_number);
- if (m) {
- (void)m_freem(m);
- *mm = 0;
- }
- return error;
- }
-
- dprintf(("%s unknown request %d\n", err_prefix, stage));
- if (m) {
- (void)m_freem(m);
- *mm = 0;
- }
- return (EINVAL);
-}
-
-void
-ip6_fw_init(void)
-{
- struct ip6_fw default_rule;
-
- ip6_fw_chk_ptr = ip6_fw_chk;
- ip6_fw_ctl_ptr = ip6_fw_ctl;
- LIST_INIT(&ip6_fw_chain);
-
- bzero(&default_rule, sizeof default_rule);
- default_rule.fw_prot = IPPROTO_IPV6;
- default_rule.fw_number = (u_short)-1;
-#ifdef IPV6FIREWALL_DEFAULT_TO_ACCEPT
- default_rule.fw_flg |= IPV6_FW_F_ACCEPT;
-#else
- default_rule.fw_flg |= IPV6_FW_F_DENY;
-#endif
- default_rule.fw_flg |= IPV6_FW_F_IN | IPV6_FW_F_OUT;
- if (check_ip6fw_struct(&default_rule) == NULL ||
- add_entry6(&ip6_fw_chain, &default_rule))
- panic(__func__);
-
- /* Setup our sysctl tree */
- sysctl_ctx_init(&ip6_fw_sysctl_ctx);
- ip6_fw_sysctl_tree = SYSCTL_ADD_NODE(&ip6_fw_sysctl_ctx,
- SYSCTL_STATIC_CHILDREN(_net_inet6_ip6), OID_AUTO, "fw",
- CTLFLAG_RW | CTLFLAG_SECURE, 0, "Firewall");
- SYSCTL_ADD_INT(&ip6_fw_sysctl_ctx, SYSCTL_CHILDREN(ip6_fw_sysctl_tree),
- OID_AUTO, "enable", CTLFLAG_RW | CTLFLAG_SECURE, &ip6_fw_enable, 0,
- "Enable ip6fw");
- SYSCTL_ADD_INT(&ip6_fw_sysctl_ctx, SYSCTL_CHILDREN(ip6_fw_sysctl_tree),
- OID_AUTO, "debug", CTLFLAG_RW, &fw6_debug, 0, "");
- SYSCTL_ADD_INT(&ip6_fw_sysctl_ctx, SYSCTL_CHILDREN(ip6_fw_sysctl_tree),
- OID_AUTO, "verbose", CTLFLAG_RW | CTLFLAG_SECURE, &fw6_verbose, 0,
- "");
- SYSCTL_ADD_INT(&ip6_fw_sysctl_ctx, SYSCTL_CHILDREN(ip6_fw_sysctl_tree),
- OID_AUTO, "verbose_limit", CTLFLAG_RW, &fw6_verbose_limit, 0, "");
-
- printf("IPv6 packet filtering initialized, ");
-#ifdef IPV6FIREWALL_DEFAULT_TO_ACCEPT
- printf("default to accept, ");
-#endif
-#ifndef IPV6FIREWALL_VERBOSE
- printf("logging disabled\n");
-#else
- if (fw6_verbose_limit == 0)
- printf("unlimited logging\n");
- else
- printf("logging limited to %d packets/entry\n",
- fw6_verbose_limit);
-#endif
-}
-
-static ip6_fw_chk_t *old_chk_ptr;
-static ip6_fw_ctl_t *old_ctl_ptr;
-
-static int
-ip6fw_modevent(module_t mod, int type, void *unused)
-{
- int s;
-
- switch (type) {
- case MOD_LOAD:
- s = splnet();
-
- old_chk_ptr = ip6_fw_chk_ptr;
- old_ctl_ptr = ip6_fw_ctl_ptr;
-
- ip6_fw_init();
- splx(s);
- return 0;
- case MOD_UNLOAD:
- s = splnet();
- ip6_fw_chk_ptr = old_chk_ptr;
- ip6_fw_ctl_ptr = old_ctl_ptr;
- while (LIST_FIRST(&ip6_fw_chain) != NULL) {
- struct ip6_fw_chain *fcp = LIST_FIRST(&ip6_fw_chain);
- LIST_REMOVE(LIST_FIRST(&ip6_fw_chain), chain);
- free(fcp->rule, M_IP6FW);
- free(fcp, M_IP6FW);
- }
-
- /* Free sysctl tree */
- sysctl_ctx_free(&ip6_fw_sysctl_ctx);
-
- splx(s);
- printf("IPv6 firewall unloaded\n");
- return 0;
- default:
- return EOPNOTSUPP;
- break;
- }
- return 0;
-}
-
-static moduledata_t ip6fwmod = {
- "ip6fw",
- ip6fw_modevent,
- 0
-};
-DECLARE_MODULE(ip6fw, ip6fwmod, SI_SUB_PSEUDO, SI_ORDER_ANY);
diff --git a/sys/netinet6/ip6_fw.h b/sys/netinet6/ip6_fw.h
deleted file mode 100644
index 2b5aa9f..0000000
--- a/sys/netinet6/ip6_fw.h
+++ /dev/null
@@ -1,231 +0,0 @@
-/* $FreeBSD$ */
-/* $KAME: ip6_fw.h,v 1.9 2001/08/01 04:29:57 sumikawa Exp $ */
-
-/*-
- * Copyright (C) 1998, 1999, 2000 and 2001 WIDE Project.
- * All rights reserved.
- *
- * 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
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the 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 PROJECT AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/*-
- * Copyright (c) 1993 Daniel Boulet
- * Copyright (c) 1994 Ugen J.S.Antsilevich
- *
- * Redistribution and use in source forms, with and without modification,
- * are permitted provided that this entire comment appears intact.
- *
- * Redistribution in binary form may occur without any restrictions.
- * Obviously, it would be nice if you gave credit where credit is due
- * but requiring it would be too onerous.
- *
- * This software is provided ``AS IS'' without any warranties of any kind.
- *
- */
-
-#ifndef _IP6_FW_H
-#define _IP6_FW_H
-
-#include <net/if.h>
-
-/*
- * This union structure identifies an interface, either explicitly
- * by name or implicitly by IP address. The flags IP_FW_F_IIFNAME
- * and IP_FW_F_OIFNAME say how to interpret this structure. An
- * interface unit number of -1 matches any unit number, while an
- * IP address of 0.0.0.0 indicates matches any interface.
- *
- * The receive and transmit interfaces are only compared against the
- * the packet if the corresponding bit (IP_FW_F_IIFACE or IP_FW_F_OIFACE)
- * is set. Note some packets lack a receive or transmit interface
- * (in which case the missing "interface" never matches).
- */
-
-union ip6_fw_if {
- struct in6_addr fu_via_ip6; /* Specified by IPv6 address */
- struct { /* Specified by interface name */
-#define IP6FW_IFNLEN IFNAMSIZ
- char name[IP6FW_IFNLEN];
- short glob; /* Is name a pattern or a name? */
- } fu_via_if;
-};
-
-/*
- * Format of an IP firewall descriptor
- *
- * fw_src, fw_dst, fw_smsk, fw_dmsk are always stored in network byte order.
- * fw_flg and fw_n*p are stored in host byte order (of course).
- * Port numbers are stored in HOST byte order.
- * Warning: setsockopt() will fail if sizeof(struct ip_fw) > MLEN (108)
- */
-
-struct ip6_fw {
- u_long fw_pcnt,fw_bcnt; /* Packet and byte counters */
- struct in6_addr fw_src, fw_dst; /* Source and destination IPv6 addr */
- struct in6_addr fw_smsk, fw_dmsk; /* Mask for src and dest IPv6 addr */
- u_short fw_number; /* Rule number */
- u_short fw_flg; /* Flags word */
-#define IPV6_FW_MAX_PORTS 10 /* A reasonable maximum */
- u_int fw_ipflg; /* IP flags word */
- u_short fw_pts[IPV6_FW_MAX_PORTS]; /* Array of port numbers to match */
- u_char fw_ip6opt,fw_ip6nopt; /* IPv6 options set/unset */
- u_char fw_tcpf,fw_tcpnf; /* TCP flags set/unset */
-#define IPV6_FW_ICMPTYPES_DIM (256 / (sizeof(unsigned) * 8))
- unsigned fw_icmp6types[IPV6_FW_ICMPTYPES_DIM]; /* ICMP types bitmap */
- long timestamp; /* timestamp (tv_sec) of last match */
- union ip6_fw_if fw_in_if, fw_out_if;/* Incoming and outgoing interfaces */
- union {
- u_short fu_divert_port; /* Divert/tee port (options IP6DIVERT) */
- u_short fu_skipto_rule; /* SKIPTO command rule number */
- u_short fu_reject_code; /* REJECT response code */
- } fw_un;
- u_char fw_prot; /* IPv6 protocol */
- u_char fw_nports; /* N'of src ports and # of dst ports */
- /* in ports array (dst ports follow */
- /* src ports; max of 10 ports in all; */
- /* count of 0 means match all ports) */
-};
-
-#define IPV6_FW_GETNSRCP(rule) ((rule)->fw_nports & 0x0f)
-#define IPV6_FW_SETNSRCP(rule, n) do { \
- (rule)->fw_nports &= ~0x0f; \
- (rule)->fw_nports |= (n); \
- } while (/*CONSTCOND*/ 0)
-#define IPV6_FW_GETNDSTP(rule) ((rule)->fw_nports >> 4)
-#define IPV6_FW_SETNDSTP(rule, n) do { \
- (rule)->fw_nports &= ~0xf0; \
- (rule)->fw_nports |= (n) << 4;\
- } while (/*CONSTCOND*/ 0)
-
-#define fw_divert_port fw_un.fu_divert_port
-#define fw_skipto_rule fw_un.fu_skipto_rule
-#define fw_reject_code fw_un.fu_reject_code
-
-struct ip6_fw_chain {
- LIST_ENTRY(ip6_fw_chain) chain;
- struct ip6_fw *rule;
-};
-
-/*
- * Values for "flags" field .
- */
-#define IPV6_FW_F_IN 0x0001 /* Check inbound packets */
-#define IPV6_FW_F_OUT 0x0002 /* Check outbound packets */
-#define IPV6_FW_F_IIFACE 0x0004 /* Apply inbound interface test */
-#define IPV6_FW_F_OIFACE 0x0008 /* Apply outbound interface test */
-
-#define IPV6_FW_F_COMMAND 0x0070 /* Mask for type of chain entry: */
-#define IPV6_FW_F_DENY 0x0000 /* This is a deny rule */
-#define IPV6_FW_F_REJECT 0x0010 /* Deny and send a response packet */
-#define IPV6_FW_F_ACCEPT 0x0020 /* This is an accept rule */
-#define IPV6_FW_F_COUNT 0x0030 /* This is a count rule */
-#define IPV6_FW_F_DIVERT 0x0040 /* This is a divert rule */
-#define IPV6_FW_F_TEE 0x0050 /* This is a tee rule */
-#define IPV6_FW_F_SKIPTO 0x0060 /* This is a skipto rule */
-
-#define IPV6_FW_F_PRN 0x0080 /* Print if this rule matches */
-
-#define IPV6_FW_F_SRNG 0x0100 /* The first two src ports are a min *
- * and max range (stored in host byte *
- * order). */
-
-#define IPV6_FW_F_DRNG 0x0200 /* The first two dst ports are a min *
- * and max range (stored in host byte *
- * order). */
-
-#define IPV6_FW_F_IIFNAME 0x0400 /* In interface by name/unit (not IP) */
-#define IPV6_FW_F_OIFNAME 0x0800 /* Out interface by name/unit (not IP) */
-
-#define IPV6_FW_F_INVSRC 0x1000 /* Invert sense of src check */
-#define IPV6_FW_F_INVDST 0x2000 /* Invert sense of dst check */
-
-#define IPV6_FW_F_FRAG 0x4000 /* Fragment */
-
-#define IPV6_FW_F_ICMPBIT 0x8000 /* ICMP type bitmap is valid */
-
-#define IPV6_FW_F_MASK 0xFFFF /* All possible flag bits mask */
-
-/*
- * Flags for the 'fw_ipflg' field, for comparing values of ip and its protocols. */
-#define IPV6_FW_IF_TCPEST 0x00000020 /* established TCP connection */
-#define IPV6_FW_IF_TCPMSK 0x00000020 /* mask of all TCP values */
-
-/*
- * For backwards compatibility with rules specifying "via iface" but
- * not restricted to only "in" or "out" packets, we define this combination
- * of bits to represent this configuration.
- */
-
-#define IF6_FW_F_VIAHACK (IPV6_FW_F_IN|IPV6_FW_F_OUT|IPV6_FW_F_IIFACE|IPV6_FW_F_OIFACE)
-
-/*
- * Definitions for REJECT response codes.
- * Values less than 256 correspond to ICMP unreachable codes.
- */
-#define IPV6_FW_REJECT_RST 0x0100 /* TCP packets: send RST */
-
-/*
- * Definitions for IPv6 option names.
- */
-#define IPV6_FW_IP6OPT_HOPOPT 0x01
-#define IPV6_FW_IP6OPT_ROUTE 0x02
-#define IPV6_FW_IP6OPT_FRAG 0x04
-#define IPV6_FW_IP6OPT_ESP 0x08
-#define IPV6_FW_IP6OPT_AH 0x10
-#define IPV6_FW_IP6OPT_NONXT 0x20
-#define IPV6_FW_IP6OPT_OPTS 0x40
-
-/*
- * Definitions for TCP flags.
- */
-#define IPV6_FW_TCPF_FIN TH_FIN
-#define IPV6_FW_TCPF_SYN TH_SYN
-#define IPV6_FW_TCPF_RST TH_RST
-#define IPV6_FW_TCPF_PSH TH_PUSH
-#define IPV6_FW_TCPF_ACK TH_ACK
-#define IPV6_FW_TCPF_URG TH_URG
-
-/*
- * Main firewall chains definitions and global var's definitions.
- */
-#ifdef _KERNEL
-
-/*
- * Function definitions.
- */
-void ip6_fw_init(void);
-
-/* Firewall hooks */
-struct ip6_hdr;
-typedef int ip6_fw_chk_t __P((struct ip6_hdr**, struct ifnet*,
- u_short *, struct mbuf**));
-typedef int ip6_fw_ctl_t __P((int, struct mbuf**));
-extern ip6_fw_chk_t *ip6_fw_chk_ptr;
-extern ip6_fw_ctl_t *ip6_fw_ctl_ptr;
-extern int ip6_fw_enable;
-
-#endif /* _KERNEL */
-
-#endif /* _IP6_FW_H */
diff --git a/sys/netinet6/ip6_input.c b/sys/netinet6/ip6_input.c
index a7f5a7c..d0b881c9 100644
--- a/sys/netinet6/ip6_input.c
+++ b/sys/netinet6/ip6_input.c
@@ -61,7 +61,6 @@
* @(#)ip_input.c 8.2 (Berkeley) 1/4/94
*/
-#include "opt_ip6fw.h"
#include "opt_inet.h"
#include "opt_inet6.h"
#include "opt_ipsec.h"
@@ -115,8 +114,6 @@
#define IPSEC
#endif /* FAST_IPSEC */
-#include <netinet6/ip6_fw.h>
-
#include <netinet6/ip6protosw.h>
#include <net/net_osdep.h>
@@ -138,11 +135,6 @@ int ip6_ours_check_algorithm;
struct pfil_head inet6_pfil_hook;
-/* firewall hooks */
-ip6_fw_chk_t *ip6_fw_chk_ptr;
-ip6_fw_ctl_t *ip6_fw_ctl_ptr;
-int ip6_fw_enable = 1;
-
struct ip6stat ip6stat;
static void ip6_init2 __P((void *));
@@ -426,21 +418,6 @@ ip6_input(m)
passin:
/*
- * Check with the firewall...
- */
- if (ip6_fw_enable && ip6_fw_chk_ptr) {
- u_short port = 0;
- /* If ipfw says divert, we have to just drop packet */
- /* use port as a dummy argument */
- if ((*ip6_fw_chk_ptr)(&ip6, NULL, &port, &m)) {
- m_freem(m);
- m = NULL;
- }
- if (!m)
- return;
- }
-
- /*
* Disambiguate address scope zones (if there is ambiguity).
* We first make sure that the original source or destination address
* is not in our internal form for scoped addresses. Such addresses
diff --git a/sys/netinet6/ip6_output.c b/sys/netinet6/ip6_output.c
index 57999f8..98f777a 100644
--- a/sys/netinet6/ip6_output.c
+++ b/sys/netinet6/ip6_output.c
@@ -61,7 +61,6 @@
* @(#)ip_output.c 8.3 (Berkeley) 1/21/94
*/
-#include "opt_ip6fw.h"
#include "opt_inet.h"
#include "opt_inet6.h"
#include "opt_ipsec.h"
@@ -106,8 +105,6 @@
#include <netipsec/key.h>
#endif /* FAST_IPSEC */
-#include <netinet6/ip6_fw.h>
-
#include <net/net_osdep.h>
#include <netinet6/ip6protosw.h>
@@ -839,23 +836,6 @@ again:
in6_clearscope(&ip6->ip6_dst);
/*
- * Check with the firewall...
- */
- if (ip6_fw_enable && ip6_fw_chk_ptr) {
- u_short port = 0;
- m->m_pkthdr.rcvif = NULL; /* XXX */
- /* If ipfw says divert, we have to just drop packet */
- if ((*ip6_fw_chk_ptr)(&ip6, ifp, &port, &m)) {
- m_freem(m);
- goto done;
- }
- if (!m) {
- error = EACCES;
- goto done;
- }
- }
-
- /*
* If the outgoing packet contains a hop-by-hop options header,
* it must be examined and processed even by the source node.
* (RFC 2460, section 4.)
@@ -1891,27 +1871,6 @@ do { \
break;
#endif /* KAME IPSEC */
- case IPV6_FW_ADD:
- case IPV6_FW_DEL:
- case IPV6_FW_FLUSH:
- case IPV6_FW_ZERO:
- {
- struct mbuf *m;
- struct mbuf **mp = &m;
-
- if (ip6_fw_ctl_ptr == NULL)
- return EINVAL;
- /* XXX */
- if ((error = soopt_getm(sopt, &m)) != 0)
- break;
- /* XXX */
- if ((error = soopt_mcopyin(sopt, m)) != 0)
- break;
- error = (*ip6_fw_ctl_ptr)(optname, mp);
- m = *mp;
- }
- break;
-
default:
error = ENOPROTOOPT;
break;
@@ -2138,23 +2097,6 @@ do { \
}
#endif /* KAME IPSEC */
- case IPV6_FW_GET:
- {
- struct mbuf *m;
- struct mbuf **mp = &m;
-
- if (ip6_fw_ctl_ptr == NULL)
- {
- return EINVAL;
- }
- error = (*ip6_fw_ctl_ptr)(optname, mp);
- if (error == 0)
- error = soopt_mcopyout(sopt, m); /* XXX */
- if (error == 0 && m)
- m_freem(m);
- }
- break;
-
default:
error = ENOPROTOOPT;
break;
OpenPOWER on IntegriCloud