2005-01-07 02:30:35 +00:00
|
|
|
/*-
|
2017-11-20 19:43:44 +00:00
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
*
|
1999-12-07 17:39:16 +00:00
|
|
|
* Copyright (C) 1995, 1996, 1997, and 1998 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.
|
2007-12-10 16:03:40 +00:00
|
|
|
*
|
|
|
|
* $KAME: in6_gif.c,v 1.49 2001/05/14 14:02:17 itojun Exp $
|
1999-12-07 17:39:16 +00:00
|
|
|
*/
|
|
|
|
|
2007-12-10 16:03:40 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1999-12-07 17:39:16 +00:00
|
|
|
#include "opt_inet.h"
|
2000-07-04 16:35:15 +00:00
|
|
|
#include "opt_inet6.h"
|
1999-12-07 17:39:16 +00:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
2014-10-14 13:31:47 +00:00
|
|
|
#include <sys/lock.h>
|
|
|
|
#include <sys/rmlock.h>
|
1999-12-07 17:39:16 +00:00
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/sockio.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/errno.h>
|
2010-04-29 11:52:42 +00:00
|
|
|
#include <sys/kernel.h>
|
2001-06-11 12:39:29 +00:00
|
|
|
#include <sys/queue.h>
|
|
|
|
#include <sys/syslog.h>
|
2010-04-29 11:52:42 +00:00
|
|
|
#include <sys/sysctl.h>
|
2001-06-11 12:39:29 +00:00
|
|
|
#include <sys/malloc.h>
|
1999-12-07 17:39:16 +00:00
|
|
|
|
|
|
|
#include <net/if.h>
|
2013-10-26 17:58:36 +00:00
|
|
|
#include <net/if_var.h>
|
1999-12-07 17:39:16 +00:00
|
|
|
#include <net/route.h>
|
2013-10-26 17:58:36 +00:00
|
|
|
#include <net/vnet.h>
|
1999-12-07 17:39:16 +00:00
|
|
|
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/in_systm.h>
|
|
|
|
#ifdef INET
|
|
|
|
#include <netinet/ip.h>
|
|
|
|
#endif
|
2000-07-04 16:35:15 +00:00
|
|
|
#include <netinet/ip_encap.h>
|
|
|
|
#ifdef INET6
|
|
|
|
#include <netinet/ip6.h>
|
1999-12-07 17:39:16 +00:00
|
|
|
#include <netinet6/ip6_var.h>
|
2000-07-04 16:35:15 +00:00
|
|
|
#include <netinet6/in6_var.h>
|
|
|
|
#endif
|
1999-12-22 19:13:38 +00:00
|
|
|
#include <netinet/ip_ecn.h>
|
2000-07-04 16:35:15 +00:00
|
|
|
#ifdef INET6
|
1999-12-22 19:13:38 +00:00
|
|
|
#include <netinet6/ip6_ecn.h>
|
Merge helper fib* functions used for basic lookups.
Vast majority of rtalloc(9) users require only basic info from
route table (e.g. "does the rtentry interface match with the interface
I have?". "what is the MTU?", "Give me the IPv4 source address to use",
etc..).
Instead of hand-rolling lookups, checking if rtentry is up, valid,
dealing with IPv6 mtu, finding "address" ifp (almost never done right),
provide easy-to-use API hiding all the complexity and returning the
needed info into small on-stack structure.
This change also helps hiding route subsystem internals (locking, direct
rtentry accesses).
Additionaly, using this API improves lookup performance since rtentry is not
locked.
(This is safe, since all the rtentry changes happens under both radix WLOCK
and rtentry WLOCK).
Sponsored by: Yandex LLC
2015-12-08 10:50:03 +00:00
|
|
|
#include <netinet6/in6_fib.h>
|
2000-07-04 16:35:15 +00:00
|
|
|
#endif
|
1999-12-07 17:39:16 +00:00
|
|
|
|
|
|
|
#include <net/if_gif.h>
|
|
|
|
|
2014-12-23 16:17:37 +00:00
|
|
|
#define GIF_HLIM 30
|
|
|
|
static VNET_DEFINE(int, ip6_gif_hlim) = GIF_HLIM;
|
2010-04-29 11:52:42 +00:00
|
|
|
#define V_ip6_gif_hlim VNET(ip6_gif_hlim)
|
|
|
|
|
|
|
|
SYSCTL_DECL(_net_inet6_ip6);
|
Rework IP encapsulation handling code.
Currently it has several disadvantages:
- it uses single mutex to protect internal structures. It is used by
data- and control- path, thus there are no parallelism at all.
- it uses single list to keep encap handlers for both INET and INET6
families.
- struct encaptab keeps unneeded information (src, dst, masks, protosw),
that isn't used by code in the source tree.
- matches are prioritized and when many tunneling interfaces are
registered, encapcheck handler of each interface is invoked for each
packet. The search takes O(n) for n interfaces. All this work is done
with exclusive lock held.
What this patch includes:
- the datapath is converted to be lockless using epoch(9) KPI.
- struct encaptab now linked using CK_LIST.
- all unused fields removed from struct encaptab. Several new fields
addedr: min_length is the minimum packet length, that encapsulation
handler expects to see; exact_match is maximum number of bits, that
can return an encapsulation handler, when it wants to consume a packet.
- IPv6 and IPv4 handlers are stored in separate lists;
- added new "encap_lookup_t" method, that will be used later. It is
targeted to speedup lookup of needed interface, when gif(4)/gre(4) have
many interfaces.
- the need to use protosw structure is eliminated. The only pr_input
method was used from this structure, so I don't see the need to keep
using it.
- encap_input_t method changed to avoid using mbuf tags to store softc
pointer. Now it is passed directly trough encap_input_t method.
encap_getarg() funtions is removed.
- all sockaddr structures and code that uses them removed. We don't have
any code in the tree that uses them. All consumers use encap_attach_func()
method, that relies on invoking of encapcheck() to determine the needed
handler.
- introduced struct encap_config, it contains parameters of encap handler
that is going to be registered by encap_attach() function.
- encap handlers are stored in lists ordered by exact_match value, thus
handlers that need more bits to match will be checked first, and if
encapcheck method returns exact_match value, the search will be stopped.
- all current consumers changed to use new KPI.
Reviewed by: mmacy
Sponsored by: Yandex LLC
Differential Revision: https://reviews.freebsd.org/D15617
2018-06-05 20:51:01 +00:00
|
|
|
SYSCTL_INT(_net_inet6_ip6, IPV6CTL_GIF_HLIM, gifhlim,
|
|
|
|
CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(ip6_gif_hlim), 0,
|
|
|
|
"Default hop limit for encapsulated packets");
|
2002-10-16 19:49:37 +00:00
|
|
|
|
1999-12-07 17:39:16 +00:00
|
|
|
int
|
2014-10-14 13:31:47 +00:00
|
|
|
in6_gif_output(struct ifnet *ifp, struct mbuf *m, int proto, uint8_t ecn)
|
1999-12-07 17:39:16 +00:00
|
|
|
{
|
2014-10-14 13:31:47 +00:00
|
|
|
GIF_RLOCK_TRACKER;
|
2005-06-10 16:49:24 +00:00
|
|
|
struct gif_softc *sc = ifp->if_softc;
|
1999-12-07 17:39:16 +00:00
|
|
|
struct ip6_hdr *ip6;
|
2014-10-14 13:31:47 +00:00
|
|
|
int len;
|
2003-10-08 18:26:08 +00:00
|
|
|
|
1999-12-07 17:39:16 +00:00
|
|
|
/* prepend new IP header */
|
2009-03-07 19:08:58 +00:00
|
|
|
len = sizeof(struct ip6_hdr);
|
|
|
|
#ifndef __NO_STRICT_ALIGNMENT
|
2014-10-14 13:31:47 +00:00
|
|
|
if (proto == IPPROTO_ETHERIP)
|
2009-03-07 19:08:58 +00:00
|
|
|
len += ETHERIP_ALIGN;
|
|
|
|
#endif
|
2012-12-05 08:04:20 +00:00
|
|
|
M_PREPEND(m, len, M_NOWAIT);
|
2014-10-14 13:31:47 +00:00
|
|
|
if (m == NULL)
|
|
|
|
return (ENOBUFS);
|
2009-03-07 19:08:58 +00:00
|
|
|
#ifndef __NO_STRICT_ALIGNMENT
|
2014-10-14 13:31:47 +00:00
|
|
|
if (proto == IPPROTO_ETHERIP) {
|
2009-03-07 19:08:58 +00:00
|
|
|
len = mtod(m, vm_offset_t) & 3;
|
|
|
|
KASSERT(len == 0 || len == ETHERIP_ALIGN,
|
|
|
|
("in6_gif_output: unexpected misalignment"));
|
|
|
|
m->m_data += len;
|
|
|
|
m->m_len -= ETHERIP_ALIGN;
|
|
|
|
}
|
|
|
|
#endif
|
1999-12-07 17:39:16 +00:00
|
|
|
|
|
|
|
ip6 = mtod(m, struct ip6_hdr *);
|
2014-10-14 13:31:47 +00:00
|
|
|
GIF_RLOCK(sc);
|
|
|
|
if (sc->gif_family != AF_INET6) {
|
2001-06-11 12:39:29 +00:00
|
|
|
m_freem(m);
|
2014-10-14 13:31:47 +00:00
|
|
|
GIF_RUNLOCK(sc);
|
|
|
|
return (ENETDOWN);
|
1999-12-07 17:39:16 +00:00
|
|
|
}
|
2014-10-14 13:31:47 +00:00
|
|
|
bcopy(sc->gif_ip6hdr, ip6, sizeof(struct ip6_hdr));
|
|
|
|
GIF_RUNLOCK(sc);
|
1999-12-07 17:39:16 +00:00
|
|
|
|
2014-10-14 13:31:47 +00:00
|
|
|
ip6->ip6_flow |= htonl((uint32_t)ecn << 20);
|
|
|
|
ip6->ip6_nxt = proto;
|
|
|
|
ip6->ip6_hlim = V_ip6_gif_hlim;
|
2000-07-04 16:35:15 +00:00
|
|
|
/*
|
|
|
|
* force fragmentation to minimum MTU, to avoid path MTU discovery.
|
|
|
|
* it is too painful to ask for resend of inner packet, to achieve
|
|
|
|
* path MTU discovery for encapsulated packets.
|
|
|
|
*/
|
2014-10-14 13:31:47 +00:00
|
|
|
return (ip6_output(m, 0, NULL, IPV6_MINMTU, 0, NULL, NULL));
|
1999-12-07 17:39:16 +00:00
|
|
|
}
|
|
|
|
|
2014-12-23 16:17:37 +00:00
|
|
|
static int
|
Rework IP encapsulation handling code.
Currently it has several disadvantages:
- it uses single mutex to protect internal structures. It is used by
data- and control- path, thus there are no parallelism at all.
- it uses single list to keep encap handlers for both INET and INET6
families.
- struct encaptab keeps unneeded information (src, dst, masks, protosw),
that isn't used by code in the source tree.
- matches are prioritized and when many tunneling interfaces are
registered, encapcheck handler of each interface is invoked for each
packet. The search takes O(n) for n interfaces. All this work is done
with exclusive lock held.
What this patch includes:
- the datapath is converted to be lockless using epoch(9) KPI.
- struct encaptab now linked using CK_LIST.
- all unused fields removed from struct encaptab. Several new fields
addedr: min_length is the minimum packet length, that encapsulation
handler expects to see; exact_match is maximum number of bits, that
can return an encapsulation handler, when it wants to consume a packet.
- IPv6 and IPv4 handlers are stored in separate lists;
- added new "encap_lookup_t" method, that will be used later. It is
targeted to speedup lookup of needed interface, when gif(4)/gre(4) have
many interfaces.
- the need to use protosw structure is eliminated. The only pr_input
method was used from this structure, so I don't see the need to keep
using it.
- encap_input_t method changed to avoid using mbuf tags to store softc
pointer. Now it is passed directly trough encap_input_t method.
encap_getarg() funtions is removed.
- all sockaddr structures and code that uses them removed. We don't have
any code in the tree that uses them. All consumers use encap_attach_func()
method, that relies on invoking of encapcheck() to determine the needed
handler.
- introduced struct encap_config, it contains parameters of encap handler
that is going to be registered by encap_attach() function.
- encap handlers are stored in lists ordered by exact_match value, thus
handlers that need more bits to match will be checked first, and if
encapcheck method returns exact_match value, the search will be stopped.
- all current consumers changed to use new KPI.
Reviewed by: mmacy
Sponsored by: Yandex LLC
Differential Revision: https://reviews.freebsd.org/D15617
2018-06-05 20:51:01 +00:00
|
|
|
in6_gif_input(struct mbuf *m, int off, int proto, void *arg)
|
1999-12-07 17:39:16 +00:00
|
|
|
{
|
Rework IP encapsulation handling code.
Currently it has several disadvantages:
- it uses single mutex to protect internal structures. It is used by
data- and control- path, thus there are no parallelism at all.
- it uses single list to keep encap handlers for both INET and INET6
families.
- struct encaptab keeps unneeded information (src, dst, masks, protosw),
that isn't used by code in the source tree.
- matches are prioritized and when many tunneling interfaces are
registered, encapcheck handler of each interface is invoked for each
packet. The search takes O(n) for n interfaces. All this work is done
with exclusive lock held.
What this patch includes:
- the datapath is converted to be lockless using epoch(9) KPI.
- struct encaptab now linked using CK_LIST.
- all unused fields removed from struct encaptab. Several new fields
addedr: min_length is the minimum packet length, that encapsulation
handler expects to see; exact_match is maximum number of bits, that
can return an encapsulation handler, when it wants to consume a packet.
- IPv6 and IPv4 handlers are stored in separate lists;
- added new "encap_lookup_t" method, that will be used later. It is
targeted to speedup lookup of needed interface, when gif(4)/gre(4) have
many interfaces.
- the need to use protosw structure is eliminated. The only pr_input
method was used from this structure, so I don't see the need to keep
using it.
- encap_input_t method changed to avoid using mbuf tags to store softc
pointer. Now it is passed directly trough encap_input_t method.
encap_getarg() funtions is removed.
- all sockaddr structures and code that uses them removed. We don't have
any code in the tree that uses them. All consumers use encap_attach_func()
method, that relies on invoking of encapcheck() to determine the needed
handler.
- introduced struct encap_config, it contains parameters of encap handler
that is going to be registered by encap_attach() function.
- encap handlers are stored in lists ordered by exact_match value, thus
handlers that need more bits to match will be checked first, and if
encapcheck method returns exact_match value, the search will be stopped.
- all current consumers changed to use new KPI.
Reviewed by: mmacy
Sponsored by: Yandex LLC
Differential Revision: https://reviews.freebsd.org/D15617
2018-06-05 20:51:01 +00:00
|
|
|
struct gif_softc *sc = arg;
|
2014-10-14 13:31:47 +00:00
|
|
|
struct ifnet *gifp;
|
1999-12-07 17:39:16 +00:00
|
|
|
struct ip6_hdr *ip6;
|
2014-10-14 13:31:47 +00:00
|
|
|
uint8_t ecn;
|
1999-12-07 17:39:16 +00:00
|
|
|
|
2005-06-20 20:17:00 +00:00
|
|
|
if (sc == NULL) {
|
|
|
|
m_freem(m);
|
2013-04-09 07:11:22 +00:00
|
|
|
IP6STAT_INC(ip6s_nogif);
|
2014-10-14 13:31:47 +00:00
|
|
|
return (IPPROTO_DONE);
|
2005-06-20 20:17:00 +00:00
|
|
|
}
|
|
|
|
gifp = GIF2IFP(sc);
|
2014-10-14 13:31:47 +00:00
|
|
|
if ((gifp->if_flags & IFF_UP) != 0) {
|
1999-12-07 17:39:16 +00:00
|
|
|
ip6 = mtod(m, struct ip6_hdr *);
|
2014-10-14 13:31:47 +00:00
|
|
|
ecn = (ntohl(ip6->ip6_flow) >> 20) & 0xff;
|
Rework IP encapsulation handling code.
Currently it has several disadvantages:
- it uses single mutex to protect internal structures. It is used by
data- and control- path, thus there are no parallelism at all.
- it uses single list to keep encap handlers for both INET and INET6
families.
- struct encaptab keeps unneeded information (src, dst, masks, protosw),
that isn't used by code in the source tree.
- matches are prioritized and when many tunneling interfaces are
registered, encapcheck handler of each interface is invoked for each
packet. The search takes O(n) for n interfaces. All this work is done
with exclusive lock held.
What this patch includes:
- the datapath is converted to be lockless using epoch(9) KPI.
- struct encaptab now linked using CK_LIST.
- all unused fields removed from struct encaptab. Several new fields
addedr: min_length is the minimum packet length, that encapsulation
handler expects to see; exact_match is maximum number of bits, that
can return an encapsulation handler, when it wants to consume a packet.
- IPv6 and IPv4 handlers are stored in separate lists;
- added new "encap_lookup_t" method, that will be used later. It is
targeted to speedup lookup of needed interface, when gif(4)/gre(4) have
many interfaces.
- the need to use protosw structure is eliminated. The only pr_input
method was used from this structure, so I don't see the need to keep
using it.
- encap_input_t method changed to avoid using mbuf tags to store softc
pointer. Now it is passed directly trough encap_input_t method.
encap_getarg() funtions is removed.
- all sockaddr structures and code that uses them removed. We don't have
any code in the tree that uses them. All consumers use encap_attach_func()
method, that relies on invoking of encapcheck() to determine the needed
handler.
- introduced struct encap_config, it contains parameters of encap handler
that is going to be registered by encap_attach() function.
- encap handlers are stored in lists ordered by exact_match value, thus
handlers that need more bits to match will be checked first, and if
encapcheck method returns exact_match value, the search will be stopped.
- all current consumers changed to use new KPI.
Reviewed by: mmacy
Sponsored by: Yandex LLC
Differential Revision: https://reviews.freebsd.org/D15617
2018-06-05 20:51:01 +00:00
|
|
|
m_adj(m, off);
|
2014-10-14 13:31:47 +00:00
|
|
|
gif_input(m, gifp, proto, ecn);
|
|
|
|
} else {
|
1999-12-07 17:39:16 +00:00
|
|
|
m_freem(m);
|
2014-10-14 13:31:47 +00:00
|
|
|
IP6STAT_INC(ip6s_nogif);
|
1999-12-07 17:39:16 +00:00
|
|
|
}
|
2014-10-14 13:31:47 +00:00
|
|
|
return (IPPROTO_DONE);
|
1999-12-07 17:39:16 +00:00
|
|
|
}
|
2000-07-04 16:35:15 +00:00
|
|
|
|
|
|
|
/*
|
2015-07-29 14:07:43 +00:00
|
|
|
* we know that we are in IFF_UP, outer address available, and outer family
|
|
|
|
* matched the physical addr family. see gif_encapcheck().
|
2000-07-04 16:35:15 +00:00
|
|
|
*/
|
2015-07-29 14:07:43 +00:00
|
|
|
int
|
|
|
|
in6_gif_encapcheck(const struct mbuf *m, int off, int proto, void *arg)
|
2002-10-16 19:49:37 +00:00
|
|
|
{
|
2015-07-29 14:07:43 +00:00
|
|
|
const struct ip6_hdr *ip6;
|
|
|
|
struct gif_softc *sc;
|
2015-05-15 12:19:45 +00:00
|
|
|
int ret;
|
2000-07-04 16:35:15 +00:00
|
|
|
|
2015-07-29 14:07:43 +00:00
|
|
|
/* sanity check done in caller */
|
|
|
|
sc = (struct gif_softc *)arg;
|
2014-10-14 13:31:47 +00:00
|
|
|
GIF_RLOCK_ASSERT(sc);
|
2015-07-29 14:07:43 +00:00
|
|
|
|
2002-10-16 19:49:37 +00:00
|
|
|
/*
|
|
|
|
* Check for address match. Note that the check is for an incoming
|
|
|
|
* packet. We should compare the *source* address in our configuration
|
|
|
|
* and the *destination* address of the packet, and vice versa.
|
|
|
|
*/
|
2015-07-29 14:07:43 +00:00
|
|
|
ip6 = mtod(m, const struct ip6_hdr *);
|
2015-05-15 12:19:45 +00:00
|
|
|
if (!IN6_ARE_ADDR_EQUAL(&sc->gif_ip6hdr->ip6_src, &ip6->ip6_dst))
|
2014-10-14 13:31:47 +00:00
|
|
|
return (0);
|
2015-05-15 12:19:45 +00:00
|
|
|
ret = 128;
|
|
|
|
if (!IN6_ARE_ADDR_EQUAL(&sc->gif_ip6hdr->ip6_dst, &ip6->ip6_src)) {
|
|
|
|
if ((sc->gif_options & GIF_IGNORE_SOURCE) == 0)
|
|
|
|
return (0);
|
|
|
|
} else
|
|
|
|
ret += 128;
|
2000-07-04 16:35:15 +00:00
|
|
|
|
|
|
|
/* ingress filters on outer source */
|
2015-07-29 14:07:43 +00:00
|
|
|
if ((GIF2IFP(sc)->if_flags & IFF_LINK2) == 0) {
|
Merge helper fib* functions used for basic lookups.
Vast majority of rtalloc(9) users require only basic info from
route table (e.g. "does the rtentry interface match with the interface
I have?". "what is the MTU?", "Give me the IPv4 source address to use",
etc..).
Instead of hand-rolling lookups, checking if rtentry is up, valid,
dealing with IPv6 mtu, finding "address" ifp (almost never done right),
provide easy-to-use API hiding all the complexity and returning the
needed info into small on-stack structure.
This change also helps hiding route subsystem internals (locking, direct
rtentry accesses).
Additionaly, using this API improves lookup performance since rtentry is not
locked.
(This is safe, since all the rtentry changes happens under both radix WLOCK
and rtentry WLOCK).
Sponsored by: Yandex LLC
2015-12-08 10:50:03 +00:00
|
|
|
struct nhop6_basic nh6;
|
|
|
|
|
|
|
|
/* XXX empty scope id */
|
2015-12-09 22:09:33 +00:00
|
|
|
if (fib6_lookup_nh_basic(sc->gif_fibnum, &ip6->ip6_src, 0, 0, 0,
|
|
|
|
&nh6) != 0)
|
Merge helper fib* functions used for basic lookups.
Vast majority of rtalloc(9) users require only basic info from
route table (e.g. "does the rtentry interface match with the interface
I have?". "what is the MTU?", "Give me the IPv4 source address to use",
etc..).
Instead of hand-rolling lookups, checking if rtentry is up, valid,
dealing with IPv6 mtu, finding "address" ifp (almost never done right),
provide easy-to-use API hiding all the complexity and returning the
needed info into small on-stack structure.
This change also helps hiding route subsystem internals (locking, direct
rtentry accesses).
Additionaly, using this API improves lookup performance since rtentry is not
locked.
(This is safe, since all the rtentry changes happens under both radix WLOCK
and rtentry WLOCK).
Sponsored by: Yandex LLC
2015-12-08 10:50:03 +00:00
|
|
|
return (0);
|
|
|
|
|
|
|
|
if (nh6.nh_ifp != m->m_pkthdr.rcvif)
|
2014-10-14 13:31:47 +00:00
|
|
|
return (0);
|
2000-07-04 16:35:15 +00:00
|
|
|
}
|
2015-05-15 12:19:45 +00:00
|
|
|
return (ret);
|
2000-07-04 16:35:15 +00:00
|
|
|
}
|
2002-10-16 19:49:37 +00:00
|
|
|
|
Rework IP encapsulation handling code.
Currently it has several disadvantages:
- it uses single mutex to protect internal structures. It is used by
data- and control- path, thus there are no parallelism at all.
- it uses single list to keep encap handlers for both INET and INET6
families.
- struct encaptab keeps unneeded information (src, dst, masks, protosw),
that isn't used by code in the source tree.
- matches are prioritized and when many tunneling interfaces are
registered, encapcheck handler of each interface is invoked for each
packet. The search takes O(n) for n interfaces. All this work is done
with exclusive lock held.
What this patch includes:
- the datapath is converted to be lockless using epoch(9) KPI.
- struct encaptab now linked using CK_LIST.
- all unused fields removed from struct encaptab. Several new fields
addedr: min_length is the minimum packet length, that encapsulation
handler expects to see; exact_match is maximum number of bits, that
can return an encapsulation handler, when it wants to consume a packet.
- IPv6 and IPv4 handlers are stored in separate lists;
- added new "encap_lookup_t" method, that will be used later. It is
targeted to speedup lookup of needed interface, when gif(4)/gre(4) have
many interfaces.
- the need to use protosw structure is eliminated. The only pr_input
method was used from this structure, so I don't see the need to keep
using it.
- encap_input_t method changed to avoid using mbuf tags to store softc
pointer. Now it is passed directly trough encap_input_t method.
encap_getarg() funtions is removed.
- all sockaddr structures and code that uses them removed. We don't have
any code in the tree that uses them. All consumers use encap_attach_func()
method, that relies on invoking of encapcheck() to determine the needed
handler.
- introduced struct encap_config, it contains parameters of encap handler
that is going to be registered by encap_attach() function.
- encap handlers are stored in lists ordered by exact_match value, thus
handlers that need more bits to match will be checked first, and if
encapcheck method returns exact_match value, the search will be stopped.
- all current consumers changed to use new KPI.
Reviewed by: mmacy
Sponsored by: Yandex LLC
Differential Revision: https://reviews.freebsd.org/D15617
2018-06-05 20:51:01 +00:00
|
|
|
static const struct encap_config ipv6_encap_cfg = {
|
|
|
|
.proto = -1,
|
|
|
|
.min_length = sizeof(struct ip6_hdr),
|
|
|
|
.exact_match = (sizeof(struct in6_addr) << 4) + 8,
|
|
|
|
.check = gif_encapcheck,
|
|
|
|
.input = in6_gif_input
|
|
|
|
};
|
|
|
|
|
2002-10-16 19:49:37 +00:00
|
|
|
int
|
2007-07-05 16:23:49 +00:00
|
|
|
in6_gif_attach(struct gif_softc *sc)
|
2002-10-16 19:49:37 +00:00
|
|
|
{
|
|
|
|
|
2014-10-14 13:31:47 +00:00
|
|
|
KASSERT(sc->gif_ecookie == NULL, ("gif_ecookie isn't NULL"));
|
Rework IP encapsulation handling code.
Currently it has several disadvantages:
- it uses single mutex to protect internal structures. It is used by
data- and control- path, thus there are no parallelism at all.
- it uses single list to keep encap handlers for both INET and INET6
families.
- struct encaptab keeps unneeded information (src, dst, masks, protosw),
that isn't used by code in the source tree.
- matches are prioritized and when many tunneling interfaces are
registered, encapcheck handler of each interface is invoked for each
packet. The search takes O(n) for n interfaces. All this work is done
with exclusive lock held.
What this patch includes:
- the datapath is converted to be lockless using epoch(9) KPI.
- struct encaptab now linked using CK_LIST.
- all unused fields removed from struct encaptab. Several new fields
addedr: min_length is the minimum packet length, that encapsulation
handler expects to see; exact_match is maximum number of bits, that
can return an encapsulation handler, when it wants to consume a packet.
- IPv6 and IPv4 handlers are stored in separate lists;
- added new "encap_lookup_t" method, that will be used later. It is
targeted to speedup lookup of needed interface, when gif(4)/gre(4) have
many interfaces.
- the need to use protosw structure is eliminated. The only pr_input
method was used from this structure, so I don't see the need to keep
using it.
- encap_input_t method changed to avoid using mbuf tags to store softc
pointer. Now it is passed directly trough encap_input_t method.
encap_getarg() funtions is removed.
- all sockaddr structures and code that uses them removed. We don't have
any code in the tree that uses them. All consumers use encap_attach_func()
method, that relies on invoking of encapcheck() to determine the needed
handler.
- introduced struct encap_config, it contains parameters of encap handler
that is going to be registered by encap_attach() function.
- encap handlers are stored in lists ordered by exact_match value, thus
handlers that need more bits to match will be checked first, and if
encapcheck method returns exact_match value, the search will be stopped.
- all current consumers changed to use new KPI.
Reviewed by: mmacy
Sponsored by: Yandex LLC
Differential Revision: https://reviews.freebsd.org/D15617
2018-06-05 20:51:01 +00:00
|
|
|
sc->gif_ecookie = ip6_encap_attach(&ipv6_encap_cfg, sc, M_WAITOK);
|
2014-10-14 13:31:47 +00:00
|
|
|
return (0);
|
2002-10-16 19:49:37 +00:00
|
|
|
}
|