Bug 192350 - [ipf] ipnat doesn't work with INET6 kernel option
Summary: [ipf] ipnat doesn't work with INET6 kernel option
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 10.0-STABLE
Hardware: Any Any
: --- Affects Some People
Assignee: Cy Schubert
URL:
Keywords: patch-ready
Depends on:
Blocks:
 
Reported: 2014-08-03 01:57 UTC by Daniil Chubiy
Modified: 2015-03-10 01:49 UTC (History)
2 users (show)

See Also:


Attachments
ipv6 fix to ip_compat.h to work with ipf/ipnat (736 bytes, text/plain)
2014-08-03 01:57 UTC, Daniil Chubiy
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Daniil Chubiy 2014-08-03 01:57:02 UTC
Created attachment 145286 [details]
ipv6 fix to ip_compat.h to work with ipf/ipnat

Just boot into this livecd ftp://ftp.freebsd.org/pub/FreeBSD/snapshots/amd64/amd64/ISO-IMAGES/10.0/FreeBSD-10.0-STABLE-amd64-20140725-r269083-disc1.iso
or i386 one
Then type kldload ipfilter && ipnat -l
you'll get this:
70:ioctl(SIOCGNATS) object size mismatch for copying out ipfobj

To fix this in installed system:
cd /usr/src
patch -p0 < /root/ipnat-ip6fix-ip_compat.diff
cd sys/modules/ipfilter/ && make clean
cd ../../../sbin/ipf && make all install clean
Then:
ipnat -l
List of active MAP/Redirect filters:

List of active sessions:


Looks like Cy Schubert broke it with this fix https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=190964

Here is what was changed in his fix that breaks ipnat when INET6 is enabled:
root@amd64older:/usr/src/sys/contrib/ipfilter # diff -r /usr/src/sys/contrib/ipfilter /root/src/sys/contrib/ipfilter
diff -r /usr/src/sys/contrib/ipfilter/netinet/ip_compat.h /root/src/sys/contrib/ipfilter/netinet/ip_compat.h
7c7
<  * $FreeBSD: stable/10/sys/contrib/ipfilter/netinet/ip_compat.h 255754 2013-09-21 03:57:56Z cy $
---
>  * $FreeBSD: stable/10/sys/contrib/ipfilter/netinet/ip_compat.h 268937 2014-07-21 06:45:19Z cy $
36,39d35
< #if defined(__FreeBSD_version) && (__FreeBSD_version >= 400000) && \
<     !defined(_KERNEL) && !defined(USE_INET6) && !defined(NOINET6)
< # define      USE_INET6
< #endif

Sure this def utilizes an old way to pass kernel build options so NOINET6 does not work.
But deleting this ifdef completely forces to compile userland ipf without -DUSE_INET6. So we should use MK_INET_SUPPORT in some way and it was made in this same file (ip_compat.h):
# define HAS_SYS_MD5_H  1
# if defined(_KERNEL)
#   include "opt_bpf.h"
#   include "opt_inet6.h"
#  if defined(INET6) && !defined(USE_INET6)
#   define USE_INET6
#  endif
# endif

As you can see for some reason it was made not to work with userland.
Is there a strong reason for this? Is it safe to enable it here or this must be done in some other way?
Comment 1 Cy Schubert freebsd_committer freebsd_triage 2014-08-07 13:44:48 UTC
Just committed a fix to -CURRENT two days ago. Will MFC shortly.
Comment 2 Mark Linimon freebsd_committer freebsd_triage 2015-03-10 01:49:04 UTC
Committed by cy 2014-08-05.