Commit Graph

67 Commits

Author SHA1 Message Date
Cy Schubert
8b1e4b7c63 Retire macros:
BSD_GE_YEAR
	BSD_GT_YEAR
	BSD_LT_YEAR

MFC after:	3 days
2020-03-02 23:25:02 +00:00
Cy Schubert
d8deeff04d Document ipf_nat_hashtab_add() return codes.
MFC after:	3 days
2019-08-28 04:55:17 +00:00
Cy Schubert
d49ffa7664 Destroy the mutex in case of error.
Obtained from:	NetBSD ip_nat.c r1.7
MFC after:	3 days
2019-08-28 04:55:03 +00:00
Cy Schubert
6d7534d8ea Fixup typo in comment.
Obtained from:	NetBSD ip_nat.c r1.7
MFC after:	3 days
2019-08-28 04:54:26 +00:00
Cy Schubert
0fcd8cab4e ipfilter #ifdef cleanup.
Remove #ifdefs for ancient and irrelevant operating systems from
ipfilter.

When ipfilter was written the UNIX and UNIX-like systems in use
were diverse and plentiful. IRIX, Tru64 (OSF/1) don't exist any
more. OpenBSD removed ipfilter shortly after the first time the
ipfilter license terms changed in the early 2000's. ipfilter on AIX,
HP/UX, and Linux never really caught on. Removal of code for operating
systems that ipfilter will never run on again will simplify the code
making it easier to fix bugs, complete partially implemented features,
and extend ipfilter.

Unsupported previous version FreeBSD code and some older NetBSD code
has also been removed.

What remains is supported FreeBSD, NetBSD, and illumos. FreeBSD and
NetBSD have collaborated exchanging patches, while illumos has expressed
willingness to have their ipfilter updated to 5.1.2, provided their
zone-specific updates to their ipfilter are merged (which are of interest
to FreeBSD to allow control of ipfilters in jails from the global zone).

Reviewed by:	glebius@
MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D19006
2019-02-03 05:25:49 +00:00
Cy Schubert
b403765e8c Do not obtain an already held read lock. This causes a witness panic when
ipfs is invoked. This is the second of two panics resolving PR 235110.

PR:		235110
Reported by:	David.Boyd49@twc.com
MFC after:	2 weeks
2019-01-30 20:23:16 +00:00
Cy Schubert
b63abbf63a When copying a NAT rule struct to userland for save by ipfs, use the
length of the struct in memmove() rather than an unintialized variable.
This fixes the first of two kernel page faults when ipfs is invoked.

PR:		235110
Reported by:	David.Boyd49@twc.com
MFC after:	2 weeks
2019-01-30 20:22:33 +00:00
Cy Schubert
683a58eeb9 The bucket index is subtracted by one at lines 2304 and 2314. When 0 it
becomes -1, except these are unsigned integers, so they become very large
numbers. Thus are always larger than the maximum bucket; the hash table
insertion fails causing NAT to fail.

This commit ensures that if the index is already zero it is not reduced
prior to insertion into the hash table.

PR:		208566
2018-08-19 13:45:03 +00:00
Cy Schubert
58a290b9f4 Add handy DTrace probes useful in diagnosing NAT issues. DTrace probes
are situated next to error counters and/or in one instance prior to the
-1 return from various functions. This was useful in diagnosis of
PR/208566 and will be handy in the future diagnosing NAT failures.

PR:		208566
MFC after:	3 days
2018-08-19 13:44:59 +00:00
Cy Schubert
1d6e9fe75c Expose np (nat_t - an entry in the nat table structure) in the DTrace
probe when nat fails (label badnat). This is useful in diagnosing
failed NAT issues and was used in PR/208566.

PR:		208566
MFC after:	3 days
2018-08-19 13:44:56 +00:00
Cy Schubert
79476a1c3e Correct a comment. Should have been detected by ipf_nat_in() not
ipf_nat_out().

MFC after:	1 week
X-MFC-with:	r337558
2018-08-10 00:30:15 +00:00
Cy Schubert
e6191e11f0 Identify the return value (rval) that led to the IPv4 NAT failure
in ipf_nat_checkout() and report it in the frb_natv4out and frb_natv4in
dtrace probes.

This is currently being used to diagnose NAT failures in PR/208566. It's
rather handy so this commit makes it available for future diagnosis and
debugging efforts.

PR:		208566
MFC after:	1 week
2018-08-10 00:04:32 +00:00
Cy Schubert
27cb792d48 Fix typo from r323945.
Reported by:	Gary Jennejohn <gljennjohn@gmail.com>
Point hat to:	cy (me)
2017-09-24 03:33:26 +00:00
Cy Schubert
37c50e570d Correct two misspellings. Also align */. 2017-09-23 06:00:17 +00:00
Cy Schubert
a3329e0129 Fix matchcing of NATed ICMP queries (resolving NATed MTU discovery).
MFC after:	1 month
2017-08-05 00:28:42 +00:00
Cy Schubert
808c7f058c Revert r318789. It causes hanging NAT tcp sessions. 2017-05-29 07:15:28 +00:00
Cy Schubert
d84a2fbab5 Ifdef out a redundant if statement when LARGE_NAT is disabled.
MFC after:	1 week
2017-05-24 14:36:51 +00:00
Cy Schubert
59c8837dfa Remove redundant variable declaration.
MFC after:	3 days
2017-05-23 14:38:59 +00:00
Cy Schubert
0d20533e69 Fix lookup of original destination address when using a redirect rule.
Transparent proxying, e.g. to squid, is an example of this.

Obtained from:	NetBSD ip_nat.c r1.17, ip_nat6.c r1.10
MFC after:	6 weeks
2017-01-27 14:12:34 +00:00
Bjoern A. Zeeb
e88e125d77 Remove unused global variables as well as unused memory
allocations from ipfilter in preparation for VNET support.

Suggested by:		cy (see D7000)
Sponsored by:		The FreeBSD Foundation
MFC after:		2 weeks
Approved by:		re (gjb)
2016-06-30 01:32:12 +00:00
Cy Schubert
7d6528d739 Correct __FreeBSD__ check.
MFC after:	3 days
2015-12-28 00:42:15 +00:00
Cy Schubert
ec992425dc Don't assume checksums will be calculated later when fastfoward is
enabled (by default in r290383).

PR:		72210
MFC after:	1 week
2015-12-20 18:02:13 +00:00
Bjoern A. Zeeb
5ddb05c2fe Compare the newly allocated array elements to NULL in order to see
if the malloc succeeded.

Spotted by:	reading kernel compile time log
MFC after:	2 weeks
2015-09-25 23:07:17 +00:00
Gleb Smirnoff
6d947416cc o Use new function ip_fillid() in all places throughout the kernel,
where we want to create a new IP datagram.
o Add support for RFC6864, which allows to set IP ID for atomic IP
  datagrams to any value, to improve performance. The behaviour is
  controlled by net.inet.ip.rfc6864 sysctl knob, which is enabled by
  default.
o In case if we generate IP ID, use counter(9) to improve performance.
o Gather all code related to IP ID into ip_id.c.

Differential Revision:		https://reviews.freebsd.org/D2177
Reviewed by:			adrian, cy, rpaulo
Tested by:			Emeric POUPON <emeric.poupon stormshield.eu>
Sponsored by:			Netflix
Sponsored by:			Nginx, Inc.
Relnotes:			yes
2015-04-01 22:26:39 +00:00
Cy Schubert
2777bfabc0 ipfilter bug #537 NAT rules with sticky have incorrect hostmap IP address.
This fixes when an IP address mapping is put in the hostmap table for
sticky NAT rules, it ends up having the wrong byte order.

Obtained from:	ipfilter CVS repo (r1.102), NetBSD CVS repo (r1.12)
2014-10-05 03:58:30 +00:00
Cy Schubert
bfc88dcbf7 Update ipfilter 4.1.28 --> 5.1.2.
Approved by:		glebius (mentor)
BSD Licensed by:	Darren Reed <darrenr@reed.wattle.id.au> (author)
2013-09-06 23:11:19 +00:00
Cy Schubert
850b82f47b As per the developers handbook (5.3.1 step 1), prepare the vendor trees for
import of new ipfilter vendor sources by flattening them.

To keep the tags consistent with dist, the tags are also flattened.

Approved by:	glebius (Mentor)
2013-07-19 05:41:57 +00:00
Jamie Gritton
0304c73163 Add hierarchical jails. A jail may further virtualize its environment
by creating a child jail, which is visible to that jail and to any
parent jails.  Child jails may be restricted more than their parents,
but never less.  Jail names reflect this hierarchy, being MIB-style
dot-separated strings.

Every thread now points to a jail, the default being prison0, which
contains information about the physical system.  Prison0's root
directory is the same as rootvnode; its hostname is the same as the
global hostname, and its securelevel replaces the global securelevel.
Note that the variable "securelevel" has actually gone away, which
should not cause any problems for code that properly uses
securelevel_gt() and securelevel_ge().

Some jail-related permissions that were kept in global variables and
set via sysctls are now per-jail settings.  The sysctls still exist for
backward compatibility, used only by the now-deprecated jail(2) system
call.

Approved by:	bz (mentor)
2009-05-27 14:11:23 +00:00
Darren Reed
14fbef0c79 2020447 IPFilter's NAT can undo name server random port selection
(fix output port range, was a random number in [0,max-min]
	 (byteswapped on litle endian), instead of [min,max])

Submitted by:	darrenr
2008-07-26 19:46:00 +00:00
Darren Reed
52c7653383 2020447 IPFilter's NAT can undo name server random port selection
Approved by:	darrenr
MFC after:	1 week
Security:	CERT VU#521769
2008-07-24 12:35:05 +00:00
Darren Reed
782218e851 Apply a few changes from ipfilter-current:
* Do not hold any locks over calls to copyin/copyout.
* Clean up some #ifdefs
* fix a possible mbuf leak when NAT fails on policy routed packets

PR:		117216
2007-10-30 15:23:27 +00:00
Darren Reed
e86e344222 Pullup IPFilter 4.1.28 from the vendor branch into HEAD.
MFC after:	7 days
2007-10-18 21:52:14 +00:00
Darren Reed
e8e48c1c7b Import IPFilter 4.1.28 2007-10-18 21:42:51 +00:00
Darren Reed
d7eeb25225 Merge IPFilter 4.1.23 back to HEAD
See src/contrib/ipfilter/HISTORY for details of changes since 4.1.13
2007-06-04 02:54:36 +00:00
Darren Reed
103b406762 Import IPFilter 4.1.23 to vendor branch.
See src/contrib/ipfilter/HISTORY for details of changes since 4.1.13
2007-06-04 02:50:28 +00:00
Guido van Rooij
4160f4c64e Resolve conflicts
MFC after:	2 weeks
2006-08-16 12:06:35 +00:00
Guido van Rooij
0be1832174 Import IP Filter 4.1.13 2006-08-16 11:51:32 +00:00
Guido van Rooij
9088f4e67b Resolve conflicts 2005-12-30 11:32:23 +00:00
Guido van Rooij
fc79eaf127 Import IP Filter version 4.1.10 2005-12-30 11:22:11 +00:00
Darren Reed
b1660bb30d - Comment out duplicate rcsid strings in *.c files
- Move SIOCPROXY from ip_nat.h to ip_proxy.h and fix ip_proxy.h so that it
  can be easily compiled into kdump, et al.
2005-04-27 03:48:10 +00:00
Darren Reed
6eab6ed50f Merge the changes from 3.4.35 to 4.1.8 into the kernel source tree 2005-04-25 18:43:14 +00:00
Darren Reed
8158c4468d import ipfilter 4.1.8 into the kernel source tree 2005-04-25 18:15:41 +00:00
Max Laier
905c6b87b7 Make ip_nat compile again. Should read #if->n<-def LARGE_NAT as in ipf 4.x 2004-12-18 03:47:54 +00:00
Darren Reed
f42b5dbebb Move two variables that are unused if LARGE_NAT is defined inside an #ifdef
to keep them out of harms way when compiling.

PR:	72783
2004-12-17 15:59:16 +00:00
Darren Reed
8a377db272 Allow ipnat redirect rules to work for non-TCP/UDP packets.
PR:             70038
Submitted by:   fming@borderware.com
Reviewed by:    darrenr
Obtained from:  fming@borderware.com
2004-12-17 02:29:34 +00:00
Darren Reed
7b807523f4 Update ipfilter from 3.4.31 -> 3.4.35. Some important changes:
* block packets that fail to create state table entries
* only allow non-fragmented packets to influence whether or not a logged
  packet is the same as the one logged before.
* correct the ICMP packet checksum fixing up when processing ICMP errors for NAT
* implement a maximum for the number of entries in the NAT table (NAT_TABLE_MAX
  and ipf_nattable_max)
* frsynclist() wasn't paying attention to all the places where interface
  names are, like it should.
* fix comparing ICMP packets with established TCP state where only 8 bytes
  of header are returned in the ICMP error.

MFC after:	1 week
2004-06-21 22:46:36 +00:00
Darren Reed
866bef8856 Import ipfilter 3.4.35 (destinated for RELENG_4) to vendor branch 2004-06-21 22:26:10 +00:00
Darren Reed
aeb497128e Commit import changed from vendor branch of ipfilter to -current head 2003-02-15 06:25:25 +00:00
Darren Reed
46e22717ef Import IPFilter 3.4.31 into -current 2003-02-15 06:18:25 +00:00
Darren Reed
ecae20848a Finally merge in the changes from ipfilter 3.4.29 to freebsd-current.
Main changes here are related to the ftp proxy and making that work better.
2002-08-28 13:41:36 +00:00