Home | History | Annotate | Download | only in netinet
History log of /src/sys/netinet/ip_encap.c
RevisionDateAuthorComments
 1.78  26-Feb-2025  andvar Fix typos in comments, mainly s/calcurate/calculate/.
 1.77  07-Dec-2022  knakahara branches: 1.77.8;
Refactor ip_encap.[ch]

- remove encap_attach() which is no longer used
- remove USE_RADIX code in ip_encap.c, which is used for
encap_attach() only
- remove mask members in encaptab
 1.76  07-Dec-2022  knakahara Implement encap_attach_addr() which is used by IP-encaped tunnels.

The tunnels attached by encap_attach() can process receiving packets
fastly as the softc is searched by radix-tree. However, the tunnels
cannot use priority function which decides tunnel's softc by not only
source and destination but also other informations.
On the other hand, the tunnels attached by encap_attach_func() can
use priority function. However, the tunnels can be slow receiving
processing as the softc is searched by linear search (and uses each
priority function).

encap_attach_addr() can be used for tunnels which is fixed tunnel
source address and tunnel destination address. The tunnels attached
by encap_attach_addr() is searched by thmap(9), so the receiving processing
can be fast. Moreover, the tunnels can use priority function.
 1.75  07-Dec-2022  knakahara refactor: use typedef for ip_encap priority function
 1.74  22-Aug-2020  riastradh Mark KASSERT-only variable __diagused.
 1.73  20-Aug-2020  riastradh [ozaki-r] Changes to the kernel core for wireguard
 1.72  23-Jan-2020  knakahara Fix PR security/54881. Pointed out by ohishi@IIJ, thanks.
 1.71  15-May-2019  knakahara branches: 1.71.2; 1.71.4;
Fix build failure when INET6 is disabled and NET_MPSAFE is enabled. Pointed out by ozaki-r@n.o, thanks.
 1.70  14-Sep-2018  maxv Use non-variadic function pointer in protosw::pr_input.
 1.69  21-Jun-2018  knakahara branches: 1.69.2;
sbappendaddr() is required any lock. Currently, softnet_lock is appropriate.

When rip_input() is called as inetsw[].pr_input, rip_iput() is always called
with holding softnet_lock, that is, in case of !defined(NET_MPSAFE) it is
acquired in ipintr(), otherwise(defined(NET_MPSAFE)) it is acquire in
PR_WRAP_INPUT macro.
However, some function calls rip_input() directly without holding softnet_lock.
That causes assertion failure in sbappendaddr().
rip6_input() and icmp6_rip6_input() are also required softnet_lock for the same
reason.
 1.68  01-May-2018  maxv Remove now unused net_osdep.h includes, the other BSDs did the same.
 1.67  14-Jan-2018  maxv branches: 1.67.2;
Fix memory leak, found by Mootja.
 1.66  15-Nov-2017  knakahara Add argument to encapsw->pr_input() instead of m_tag.
 1.65  01-Jun-2017  chs branches: 1.65.2;
remove checks for failure after memory allocation calls that cannot fail:

kmem_alloc() with KM_SLEEP
kmem_zalloc() with KM_SLEEP
percpu_alloc()
pserialize_create()
psref_class_create()

all of these paths include an assertion that the allocation has not failed,
so callers should not assert that again.
 1.64  15-Apr-2017  riastradh No need for membar_datadep_consumer here.

PSLIST_READER_FOREACH takes care of it already.
PSLIST_WRITER_FOREACH is exclusive so doesn't need it.
 1.63  07-Apr-2017  ozaki-r Commit a forgotten change for "Prepare netipsec for rump-ification"

- Allow encapinit to be called twice (by ifinit and ipe4_attach)
- ifinit didn't call encapinit if IPSEC is enabled (ipe4_attach called
it instead), however, on a rump kernel ipe4_attach may not be called
even if IPSEC is enabled. So we need to allow ifinit to call it anyway
 1.62  22-Dec-2016  knakahara branches: 1.62.2;
pserialize_perform() is required *after* PSLIST_WRITER_REMOVE.
 1.61  04-Jul-2016  knakahara branches: 1.61.2;
make gif(4) and ip_encap MP-ify
 1.60  04-Jul-2016  knakahara refactor: merge encap_init_once() to encapinit()
 1.59  04-Jul-2016  knakahara make encap_lock_{enter,exit} interruptable.
 1.58  04-Jul-2016  knakahara remove extra pserialize_perform()
 1.57  04-Jul-2016  knakahara use pserialize(9) and psref(9) (2/2) : ip_encap radix tree care
 1.56  04-Jul-2016  knakahara use pserialize(9) and psref(9) (1/2) : without ip_encap radix tree care
 1.55  04-Jul-2016  knakahara restore ifdef USE_RADIX (revert ip_encap.c:r1.44)

To help future ip_encap optimaization works.
 1.54  04-Jul-2016  knakahara let gif(4) promise softint(9) contract (2/2) : ip_encap side

The last commit does not care encaptab. This commit fixes encaptab race which
is used not only gif(4).
 1.53  26-Apr-2016  ozaki-r Sweep unnecessary route.h inclusions
 1.52  26-Feb-2016  knakahara To eliminate gif_softc_list linear search, add extra argument to encapsw.pr_ctlinput().
 1.51  26-Jan-2016  knakahara implement encapsw instead of protosw and uniform prototype.

suggested and advised by riastradh@n.o, thanks.

BTW, It seems in_stf_input() had bugs...
 1.50  22-Jan-2016  riastradh Back out previous change to introduce struct encapsw.

This change was intended, but Nakahara-san had already made a better
one locally! So I'll let him commit that one, and I'll try not to
step on anyone's toes again.
 1.49  22-Jan-2016  riastradh Don't abuse struct protosw for ip_encap -- introduce struct encapsw.

Mostly mechanical change to replace it, culling some now-needless
boilerplate around all the users.

This does not substantively change the ip_encap API or eliminate
abuse of sketchy pointer casts -- that will come later, and will be
easier now that it is not tangled up with struct protosw.
 1.48  20-Jan-2016  knakahara remove unused variable.
 1.47  09-Dec-2015  knakahara ip_encap uses kmem_alloc APIs instead of malloc.
 1.46  24-Aug-2015  pooka sprinkle _KERNEL_OPT
 1.45  20-Apr-2015  ozaki-r Remove non-USE_RADIX case and USE_RADIX switch

It seems that we have been using ip_encap only with USE_RADIX
for long years. Let's remove unused non-USE_RADIX case.

No objection on tech-kern and tech-net.

Double-checked by knakahara@
 1.44  16-Apr-2015  ozaki-r Remove garbage undef
 1.43  15-Apr-2015  riastradh KASSERT x then y, not x && y, to give more specific errors.
 1.42  15-Apr-2015  ozaki-r Use LIST_FOREACH_SAFE

We have to use LIST_FOREACH_SAFE because LIST_REMOVE is used
inside the loop through encap_remove.
 1.41  15-Apr-2015  ozaki-r Replace DIAGNOSTIC & panic with KASSERT/KASSERTMSG
 1.40  15-Apr-2015  ozaki-r Add $NetBSD$ at the top of the file
 1.39  17-Jul-2011  joerg branches: 1.39.12; 1.39.30;
Retire varargs.h support. Move machine/stdarg.h logic into MI
sys/stdarg.h and expect compiler to provide proper builtins, defaulting
to the GCC interface. lint still has a special fallback.
Reduce abuse of _BSD_VA_LIST_ by defining __va_list by default and
derive va_list as required by standards.
 1.38  27-May-2009  pooka Make it possible to register delayed radix tree head inits which
will be processed when the radix "subsystem" is initialized -- all
users must be attached before any inits to know the max keylength.
Use of link sets is no longer required, and only attached domains
need to be considered.
 1.37  18-Apr-2009  tsutsui Remove extra whitespace added by a stupid tool.
XXX: more in src/sys/arch
 1.36  18-Mar-2009  cegger bcopy -> memcpy
 1.35  18-Mar-2009  cegger bzero -> memset
 1.34  18-Mar-2009  cegger bcmp -> memcmp
 1.33  25-Nov-2008  pooka branches: 1.33.4;
Make dom_maxrtkey of inet/inet6domain the size of the ip_encap pack
structures. This is far from optimal, but gets rid of iffy
#ifdef INET in radix.c. The radix bonsai still needs lots of love
before loading domains dynamically is possible...
 1.32  24-Apr-2008  ad branches: 1.32.2; 1.32.8; 1.32.10;
Merge the socket locking patch:

- Socket layer becomes MP safe.
- Unix protocols become MP safe.
- Allows protocol processing interrupts to safely block on locks.
- Fixes a number of race conditions.

With much feedback from matt@ and plunky@.
 1.31  13-Jun-2007  dyoung branches: 1.31.28; 1.31.30;
Use LIST_FOREACH().
 1.30  04-Mar-2007  christos branches: 1.30.2; 1.30.4;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.29  17-Feb-2007  dyoung KNF: de-__P, bzero -> memset, bcmp -> memcmp. Remove extraneous
parentheses in return statements.

Cosmetic: don't open-code TAILQ_FOREACH().

Cosmetic: change types of variables to avoid oodles of casts: in
in6_src.c, avoid casts by changing several route_in6 pointers
to struct route pointers. Remove unnecessary casts to caddr_t
elsewhere.

Pave the way for eliminating address family-specific route caches:
soon, struct route will not embed a sockaddr, but it will hold
a reference to an external sockaddr, instead. We will set the
destination sockaddr using rtcache_setdst(). (I created a stub
for it, but it isn't used anywhere, yet.) rtcache_free() will
free the sockaddr. I have extracted from rtcache_free() a helper
subroutine, rtcache_clear(). rtcache_clear() will "forget" a
cached route, but it will not forget the destination by releasing
the sockaddr. I use rtcache_clear() instead of rtcache_free()
in rtcache_update(), because rtcache_update() is not supposed
to forget the destination.

Constify:

1 Introduce const accessor for route->ro_dst, rtcache_getdst().

2 Constify the 'dst' argument to ifnet->if_output(). This
led me to constify a lot of code called by output routines.

3 Constify the sockaddr argument to protosw->pr_ctlinput. This
led me to constify a lot of code called by ctlinput routines.

4 Introduce const macros for converting from a generic sockaddr
to family-specific sockaddrs, e.g., sockaddr_in: satocsin6,
satocsin, et cetera.
 1.28  28-May-2006  liamjfoy branches: 1.28.12;
remove some dead code

ok christos@
 1.27  11-Dec-2005  christos branches: 1.27.4; 1.27.6; 1.27.8; 1.27.14;
merge ktrace-lwp.
 1.26  06-Jun-2005  martin branches: 1.26.2;
Since we decided "const struct mbuf *" would not do the right thing (tm),
remove ~all const from mbuf pointers.
 1.25  03-Jun-2005  martin Sprinkle some const
 1.24  02-Jun-2005  tron Change the first argument of the encapsulation check function from
"const struct mbuf *" to "struct mbuf *". Without this change the
actual implementation cannot even use m_copydata() on the mbuf chain
which is broken.
 1.23  03-Feb-2005  perry ANSIfy function prototypes. (Still have about 3/5ths of the C files in
netinet to go...)
 1.22  02-Feb-2005  perry de-__P -- will ANSIfy .c files later.
 1.21  24-Jan-2005  enami branches: 1.21.2;
To fix bad pointer dereference on start up when gif is used,
- Allow rn_init() to be called multiple times, but do nothing except the
first call.
- Include opt_inet.h so that #ifdef INET works.
- Call rn_init() from encap_init() explicitly rather than depending on the
order of initialization.
 1.20  24-Jan-2005  itojun get zero-cleared field on malloc. kame-pr-856
 1.19  17-Aug-2004  itojun branches: 1.19.4;
initialize max_keylen for ip_encap.c earlier
 1.18  26-Apr-2004  matt Remove #else clause of __STDC__
 1.17  04-Mar-2004  wiz branches: 1.17.4;
No need to include netinet/ip_mroute.h twice.
Closes PR 24652 by Kailash Sethuraman.
 1.16  30-Oct-2003  simonb Remove some assigned-to but otherwise unused variables.
 1.15  28-Oct-2003  mycroft Do the previous differently.
 1.14  25-Oct-2003  christos Fix uninitialized variable warning
 1.13  21-Jan-2003  itojun branches: 1.13.2;
correct panic when ip-in-ip encapsulation is used. found by Masanori Kanaoka
 1.12  17-Jan-2003  itojun switch from kame-based m_aux mbuf auxiliary data, to openbsd m_tag
implementation. it will simplify porting across *bsd (such as kame/altq),
and make us more synchronized. from Joel Wilsson
 1.11  25-Nov-2002  thorpej Avoid strict-alias warnings.
 1.10  31-Jul-2002  itojun remove packed attribute as it will cause data be unaligned
 1.9  09-Jun-2002  itojun whitespace
 1.8  04-Mar-2002  sommerfeld branches: 1.8.6; 1.8.8;
The "gif*" tunnelling interface does everything ipip does.
Move usage example from ipip.4 to gif.4
Excise ipip and stitch up the scars.
 1.7  21-Dec-2001  itojun use radix table for inbound tunnel lookup (would increase performance
for machines with a lot of tunnels).
update route cache for IPvX-over-IPv6 tunnel on path MTU discovery.
snyc with kame
 1.6  13-Nov-2001  lukem add RCSIDs
 1.5  08-May-2001  itojun branches: 1.5.2;
pull encapsulated packet for vif* via ip_encap framework.
 1.4  02-Oct-2000  itojun branches: 1.4.2; 1.4.4;
fix compilation without INET. fix confusion between ipsecstat and ipsec6stat.
sync with kame.
 1.3  05-Jul-2000  thorpej Make that note that we really should be checking the viftable
in ip_mroute.c for duplicate tunnel entries, too. Well, what
really needs to happen is that the mrouting code needs to be
changed to work w/ `gif' tunnels... but...
 1.2  05-Jul-2000  thorpej Use LIST_HEAD_INITIALIZER(), for correctness sake.
 1.1  19-Apr-2000  itojun introduce sys/netinet/ip_encap.c, to dispatch inbound packets
to protocol handlers, based on src/dst (for ip proto #4/41).
see comment in ip_encap.c for details of the problem we have.
there are too many protocol specs for ip proto #4/41.
backward compatibility with MROUTING case is now provided in ip_encap.c.

fix ipip to work with gif (using ip_encap.c). sorry for breakage.

gif now uses ip_encap.c.

introduce stf pseudo interface (implements 6to4, another IPv6-over-IPv4 code
with ip proto #41).
 1.4.4.8  17-Jan-2003  thorpej Sync with HEAD.
 1.4.4.7  11-Dec-2002  thorpej Sync with HEAD.
 1.4.4.6  01-Aug-2002  nathanw Catch up to -current.
 1.4.4.5  20-Jun-2002  nathanw Catch up to -current.
 1.4.4.4  01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.4.4.3  08-Jan-2002  nathanw Catch up to -current.
 1.4.4.2  14-Nov-2001  nathanw Catch up to -current.
 1.4.4.1  21-Jun-2001  nathanw Catch up to -current.
 1.4.2.2  20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
 1.4.2.1  02-Oct-2000  bouyer file ip_encap.c was added on branch thorpej_scsipi on 2000-11-20 18:10:25 +0000
 1.5.2.4  06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.5.2.3  23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.5.2.2  16-Mar-2002  jdolecek Catch up with -current.
 1.5.2.1  10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.8.8.1  02-Aug-2002  lukem Pull up revision 1.10 (requested by itojun in ticket #593):
remove packed attribute as it will cause data be unaligned
 1.8.6.2  29-Aug-2002  gehenna catch up with -current.
 1.8.6.1  20-Jun-2002  gehenna catch up with -current.
 1.13.2.7  10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.13.2.6  04-Feb-2005  skrll Sync with HEAD.
 1.13.2.5  24-Jan-2005  skrll Sync with HEAD.
 1.13.2.4  21-Sep-2004  skrll Fix the sync with head I botched.
 1.13.2.3  18-Sep-2004  skrll Sync with HEAD.
 1.13.2.2  25-Aug-2004  skrll Sync with HEAD.
 1.13.2.1  03-Aug-2004  skrll Sync with HEAD
 1.17.4.1  06-May-2005  riz Pull up revision 1.20 (requested by bouyer in ticket #1188):
get zero-cleared field on malloc. kame-pr-856
 1.19.4.1  29-Apr-2005  kent sync with -current
 1.21.2.1  12-Feb-2005  yamt sync with head.
 1.26.2.3  03-Sep-2007  yamt sync with head.
 1.26.2.2  26-Feb-2007  yamt sync with head.
 1.26.2.1  21-Jun-2006  yamt sync with head.
 1.27.14.1  19-Jun-2006  chap Sync with head.
 1.27.8.1  26-Jun-2006  yamt sync with head.
 1.27.6.1  01-Jun-2006  kardel Sync with head.
 1.27.4.2  09-Sep-2006  rpaulo sync with head
 1.27.4.1  05-Feb-2006  rpaulo <netinet6/in6_pcb.h> went away. Bye!
 1.28.12.2  12-Mar-2007  rmind Sync with HEAD.
 1.28.12.1  27-Feb-2007  yamt - sync with head.
- move sched_changepri back to kern_synch.c as it doesn't know PPQ anymore.
 1.30.4.1  11-Jul-2007  mjf Sync with head.
 1.30.2.1  15-Jul-2007  ad Sync with head.
 1.31.30.1  18-May-2008  yamt sync with head.
 1.31.28.2  17-Jan-2009  mjf Sync with HEAD.
 1.31.28.1  02-Jun-2008  mjf Sync with HEAD.
 1.32.10.2  28-Apr-2009  skrll Sync with HEAD.
 1.32.10.1  19-Jan-2009  skrll Sync with HEAD.
 1.32.8.1  13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.32.2.2  20-Jun-2009  yamt sync with head
 1.32.2.1  04-May-2009  yamt sync with head.
 1.33.4.2  23-Jul-2009  jym Sync with HEAD.
 1.33.4.1  13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.39.30.8  28-Aug-2017  skrll Sync with HEAD
 1.39.30.7  05-Feb-2017  skrll Sync with HEAD
 1.39.30.6  09-Jul-2016  skrll Sync with HEAD
 1.39.30.5  29-May-2016  skrll Sync with HEAD
 1.39.30.4  19-Mar-2016  skrll Sync with HEAD
 1.39.30.3  27-Dec-2015  skrll Sync with HEAD (as of 26th Dec)
 1.39.30.2  22-Sep-2015  skrll Sync with HEAD
 1.39.30.1  06-Jun-2015  skrll Sync with HEAD
 1.39.12.1  03-Dec-2017  jdolecek update from HEAD
 1.61.2.2  26-Apr-2017  pgoyette Sync with HEAD
 1.61.2.1  07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.62.2.1  21-Apr-2017  bouyer Sync with HEAD
 1.65.2.5  23-Jan-2020  martin Pull up following revision(s) (requested by knakahara in ticket #1489):

sys/netinet/ip_encap.c: revision 1.72

Fix PR security/54881. Pointed out by ohishi@IIJ, thanks.
 1.65.2.4  29-May-2019  martin Pull up following revision(s) (requested by knakahara in ticket #1271):

sys/netinet/ip_encap.c: revision 1.71

Fix build failure when INET6 is disabled. Pointed out by ozaki-r@n.o, thanks.
 1.65.2.3  13-Jul-2018  martin Pull up following revision(s) via patch (requested by knakahara in ticket #905):

sys/netinet/ip_mroute.c: revision 1.160
sys/netinet6/in6_l2tp.c: revision 1.16
sys/net/if.h: revision 1.263
sys/netinet/in_l2tp.c: revision 1.15
sys/netinet/ip_icmp.c: revision 1.172
sys/netinet/igmp.c: revision 1.68
sys/netinet/ip_encap.c: revision 1.69
sys/netinet6/ip6_mroute.c: revision 1.129

sbappendaddr() is required any lock. Currently, softnet_lock is appropriate.

When rip_input() is called as inetsw[].pr_input, rip_iput() is always called
with holding softnet_lock, that is, in case of !defined(NET_MPSAFE) it is
acquired in ipintr(), otherwise(defined(NET_MPSAFE)) it is acquire in
PR_WRAP_INPUT macro.

However, some function calls rip_input() directly without holding softnet_lock.
That causes assertion failure in sbappendaddr().
rip6_input() and icmp6_rip6_input() are also required softnet_lock for the same
reason.
 1.65.2.2  30-Mar-2018  martin Pull up following revision(s) (requested by maxv in ticket #661):

sys/netinet/ip_encap.c: revision 1.67

Fix memory leak, found by Mootja.
 1.65.2.1  10-Dec-2017  snj Pull up following revision(s) (requested by knakahara in ticket #419):
sys/net/if_stf.c: revision 1.103
sys/net/if_stf.h: revision 1.8
sys/netinet/in_gif.c: revision 1.89
sys/netinet/in_gif.h: revision 1.17
sys/netinet/in_l2tp.c: revision 1.4
sys/netinet/ip_encap.c: revision 1.66
sys/netinet/ip_encap.h: revision 1.23
sys/netinet/ip_mroute.c: revision 1.148
sys/netinet6/in6_gif.c: revision 1.87
sys/netinet6/in6_gif.h: revision 1.16
sys/netinet6/in6_l2tp.c: revision 1.7
sys/netipsec/xform.h: revision 1.13
sys/netipsec/xform_ipip.c: revision 1.55
Add argument to encapsw->pr_input() instead of m_tag.
 1.67.2.3  30-Sep-2018  pgoyette Ssync with HEAD
 1.67.2.2  25-Jun-2018  pgoyette Sync with HEAD
 1.67.2.1  02-May-2018  pgoyette Synch with HEAD
 1.69.2.2  08-Apr-2020  martin Merge changes from current as of 20200406
 1.69.2.1  10-Jun-2019  christos Sync with HEAD
 1.71.4.1  25-Jan-2020  ad Sync with head.
 1.71.2.1  23-Jan-2020  martin Pull up following revision(s) (requested by knakahara in ticket #644):

sys/netinet/ip_encap.c: revision 1.72

Fix PR security/54881. Pointed out by ohishi@IIJ, thanks.
 1.77.8.1  02-Aug-2025  perseant Sync with HEAD

RSS XML Feed