aboutsummaryrefslogtreecommitdiff
path: root/sys/netinet6
diff options
context:
space:
mode:
authorAlexander V. Chernikov <melifaro@FreeBSD.org>2020-07-02 21:04:08 +0000
committerAlexander V. Chernikov <melifaro@FreeBSD.org>2020-07-02 21:04:08 +0000
commit6ad7446c6f3ac5636428bc4064a48fb0b65905ae (patch)
treebca4738e23bdfd4958f3c6471b7f772535dc4d4c /sys/netinet6
parentf60b4812d88581ff7932e4d9d7a50ecccce0e727 (diff)
downloadsrc-6ad7446c6f3ac5636428bc4064a48fb0b65905ae.tar.gz
src-6ad7446c6f3ac5636428bc4064a48fb0b65905ae.zip
Notes
Diffstat (limited to 'sys/netinet6')
-rw-r--r--sys/netinet6/icmp6.c21
-rw-r--r--sys/netinet6/in6.c8
-rw-r--r--sys/netinet6/in6_fib.c178
-rw-r--r--sys/netinet6/in6_fib.h27
-rw-r--r--sys/netinet6/in6_mcast.c8
-rw-r--r--sys/netinet6/in6_src.c7
6 files changed, 23 insertions, 226 deletions
diff --git a/sys/netinet6/icmp6.c b/sys/netinet6/icmp6.c
index 597fb9d5de27..8f0169d5132c 100644
--- a/sys/netinet6/icmp6.c
+++ b/sys/netinet6/icmp6.c
@@ -2270,13 +2270,17 @@ icmp6_redirect_input(struct mbuf *m, int off)
}
{
/* ip6->ip6_src must be equal to gw for icmp6->icmp6_reddst */
- struct nhop6_basic nh6;
+ struct nhop_object *nh;
struct in6_addr kdst;
uint32_t scopeid;
in6_splitscope(&reddst6, &kdst, &scopeid);
- if (fib6_lookup_nh_basic(ifp->if_fib, &kdst, scopeid, 0, 0,&nh6)==0){
- if ((nh6.nh_flags & NHF_GATEWAY) == 0) {
+ NET_EPOCH_ASSERT();
+ nh = fib6_lookup(ifp->if_fib, &kdst, scopeid, 0, 0);
+ if (nh == NULL) {
+ struct in6_addr nh_addr;
+ nh_addr = ifatoia6(nh->nh_ifa)->ia_addr.sin6_addr;
+ if ((nh->nh_flags & NHF_GATEWAY) == 0) {
nd6log((LOG_ERR,
"ICMP6 redirect rejected; no route "
"with inet6 gateway found for redirect dst: %s\n",
@@ -2285,19 +2289,16 @@ icmp6_redirect_input(struct mbuf *m, int off)
}
/*
- * Embed scope zone id into next hop address, since
- * fib6_lookup_nh_basic() returns address without embedded
- * scope zone id.
+ * Embed scope zone id into next hop address.
*/
- if (in6_setscope(&nh6.nh_addr, m->m_pkthdr.rcvif, NULL))
- goto freeit;
+ nh_addr = nh->gw6_sa.sin6_addr;
- if (IN6_ARE_ADDR_EQUAL(&src6, &nh6.nh_addr) == 0) {
+ if (IN6_ARE_ADDR_EQUAL(&src6, &nh_addr) == 0) {
nd6log((LOG_ERR,
"ICMP6 redirect rejected; "
"not equal to gw-for-src=%s (must be same): "
"%s\n",
- ip6_sprintf(ip6buf, &nh6.nh_addr),
+ ip6_sprintf(ip6buf, &nh_addr),
icmp6_redirect_diag(&src6, &reddst6, &redtgt6)));
goto bad;
}
diff --git a/sys/netinet6/in6.c b/sys/netinet6/in6.c
index 3eac100aa9bb..fb53adb86e82 100644
--- a/sys/netinet6/in6.c
+++ b/sys/netinet6/in6.c
@@ -91,6 +91,7 @@ __FBSDID("$FreeBSD$");
#include <net/if_var.h>
#include <net/if_types.h>
#include <net/route.h>
+#include <net/route/nhop.h>
#include <net/if_dl.h>
#include <net/vnet.h>
@@ -2141,10 +2142,9 @@ in6_lltable_rtcheck(struct ifnet *ifp,
const struct sockaddr *l3addr)
{
const struct sockaddr_in6 *sin6;
- struct nhop6_basic nh6;
+ struct nhop_object *nh;
struct in6_addr dst;
uint32_t scopeid;
- int error;
char ip6buf[INET6_ADDRSTRLEN];
int fibnum;
@@ -2155,8 +2155,8 @@ in6_lltable_rtcheck(struct ifnet *ifp,
sin6 = (const struct sockaddr_in6 *)l3addr;
in6_splitscope(&sin6->sin6_addr, &dst, &scopeid);
fibnum = V_rt_add_addr_allfibs ? RT_DEFAULT_FIB : ifp->if_fib;
- error = fib6_lookup_nh_basic(fibnum, &dst, scopeid, 0, 0, &nh6);
- if (error != 0 || (nh6.nh_flags & NHF_GATEWAY) || nh6.nh_ifp != ifp) {
+ nh = fib6_lookup(fibnum, &dst, scopeid, NHR_NONE, 0);
+ if (nh && ((nh->nh_flags & NHF_GATEWAY) || nh->nh_ifp != ifp)) {
struct ifaddr *ifa;
/*
* Create an ND6 cache for an IPv6 neighbor
diff --git a/sys/netinet6/in6_fib.c b/sys/netinet6/in6_fib.c
index 15ed3cd2f178..d93df54aa3fc 100644
--- a/sys/netinet6/in6_fib.c
+++ b/sys/netinet6/in6_fib.c
@@ -70,187 +70,9 @@ __FBSDID("$FreeBSD$");
#include <net/if_types.h>
#ifdef INET6
-static void fib6_rte_to_nh_extended(const struct nhop_object *nh,
- const struct in6_addr *dst, uint32_t flags, struct nhop6_extended *pnh6);
-static void fib6_rte_to_nh_basic(const struct nhop_object *nh, const struct in6_addr *dst,
- uint32_t flags, struct nhop6_basic *pnh6);
-
-#define ifatoia6(ifa) ((struct in6_ifaddr *)(ifa))
CHK_STRUCT_ROUTE_COMPAT(struct route_in6, ro_dst);
-
-
-static void
-fib6_rte_to_nh_basic(const struct nhop_object *nh, const struct in6_addr *dst,
- uint32_t flags, struct nhop6_basic *pnh6)
-{
-
- /* Do explicit nexthop zero unless we're copying it */
- memset(pnh6, 0, sizeof(*pnh6));
-
- if ((flags & NHR_IFAIF) != 0)
- pnh6->nh_ifp = nh->nh_aifp;
- else
- pnh6->nh_ifp = nh->nh_ifp;
-
- pnh6->nh_mtu = nh->nh_mtu;
- if (nh->nh_flags & NHF_GATEWAY) {
- /* Return address with embedded scope. */
- pnh6->nh_addr = nh->gw6_sa.sin6_addr;
- } else
- pnh6->nh_addr = *dst;
- /* Set flags */
- pnh6->nh_flags = nh->nh_flags;
-}
-
-static void
-fib6_rte_to_nh_extended(const struct nhop_object *nh, const struct in6_addr *dst,
- uint32_t flags, struct nhop6_extended *pnh6)
-{
-
- /* Do explicit nexthop zero unless we're copying it */
- memset(pnh6, 0, sizeof(*pnh6));
-
- if ((flags & NHR_IFAIF) != 0)
- pnh6->nh_ifp = nh->nh_aifp;
- else
- pnh6->nh_ifp = nh->nh_ifp;
-
- pnh6->nh_mtu = nh->nh_mtu;
- if (nh->nh_flags & NHF_GATEWAY) {
- /* Return address with embedded scope. */
- pnh6->nh_addr = nh->gw6_sa.sin6_addr;
- } else
- pnh6->nh_addr = *dst;
- /* Set flags */
- pnh6->nh_flags = nh->nh_flags;
- pnh6->nh_ia = ifatoia6(nh->nh_ifa);
-}
-
-/*
- * Performs IPv6 route table lookup on @dst. Returns 0 on success.
- * Stores basic nexthop info into provided @pnh6 structure.
- * Note that
- * - nh_ifp represents logical transmit interface (rt_ifp) by default
- * - nh_ifp represents "address" interface if NHR_IFAIF flag is passed
- * - mtu from logical transmit interface will be returned.
- * - nh_ifp cannot be safely dereferenced
- * - nh_ifp represents rt_ifp (e.g. if looking up address on
- * interface "ix0" pointer to "ix0" interface will be returned instead
- * of "lo0")
- * - howewer mtu from "transmit" interface will be returned.
- * - scope will be embedded in nh_addr
- */
-int
-fib6_lookup_nh_basic(uint32_t fibnum, const struct in6_addr *dst, uint32_t scopeid,
- uint32_t flags, uint32_t flowid, struct nhop6_basic *pnh6)
-{
- RIB_RLOCK_TRACKER;
- struct rib_head *rh;
- struct radix_node *rn;
- struct sockaddr_in6 sin6;
- struct nhop_object *nh;
-
- KASSERT((fibnum < rt_numfibs), ("fib6_lookup_nh_basic: bad fibnum"));
- rh = rt_tables_get_rnh(fibnum, AF_INET6);
- if (rh == NULL)
- return (ENOENT);
-
- /* Prepare lookup key */
- memset(&sin6, 0, sizeof(sin6));
- sin6.sin6_addr = *dst;
- sin6.sin6_len = sizeof(struct sockaddr_in6);
- /* Assume scopeid is valid and embed it directly */
- if (IN6_IS_SCOPE_LINKLOCAL(dst))
- sin6.sin6_addr.s6_addr16[1] = htons(scopeid & 0xffff);
-
- RIB_RLOCK(rh);
- rn = rh->rnh_matchaddr((void *)&sin6, &rh->head);
- if (rn != NULL && ((rn->rn_flags & RNF_ROOT) == 0)) {
- nh = RNTORT(rn)->rt_nhop;
- /* Ensure route & ifp is UP */
- if (RT_LINK_IS_UP(nh->nh_ifp)) {
- fib6_rte_to_nh_basic(nh, &sin6.sin6_addr, flags, pnh6);
- RIB_RUNLOCK(rh);
- return (0);
- }
- }
- RIB_RUNLOCK(rh);
-
- return (ENOENT);
-}
-
-/*
- * Performs IPv6 route table lookup on @dst. Returns 0 on success.
- * Stores extended nexthop info into provided @pnh6 structure.
- * Note that
- * - nh_ifp cannot be safely dereferenced unless NHR_REF is specified.
- * - in that case you need to call fib6_free_nh_ext()
- * - nh_ifp represents logical transmit interface (rt_ifp) by default
- * - nh_ifp represents "address" interface if NHR_IFAIF flag is passed
- * - mtu from logical transmit interface will be returned.
- * - scope will be embedded in nh_addr
- */
-int
-fib6_lookup_nh_ext(uint32_t fibnum, const struct in6_addr *dst,uint32_t scopeid,
- uint32_t flags, uint32_t flowid, struct nhop6_extended *pnh6)
-{
- RIB_RLOCK_TRACKER;
- struct rib_head *rh;
- struct radix_node *rn;
- struct sockaddr_in6 sin6;
- struct rtentry *rte;
- struct nhop_object *nh;
-
- KASSERT((fibnum < rt_numfibs), ("fib6_lookup_nh_ext: bad fibnum"));
- rh = rt_tables_get_rnh(fibnum, AF_INET6);
- if (rh == NULL)
- return (ENOENT);
-
- /* Prepare lookup key */
- memset(&sin6, 0, sizeof(sin6));
- sin6.sin6_len = sizeof(struct sockaddr_in6);
- sin6.sin6_addr = *dst;
- /* Assume scopeid is valid and embed it directly */
- if (IN6_IS_SCOPE_LINKLOCAL(dst))
- sin6.sin6_addr.s6_addr16[1] = htons(scopeid & 0xffff);
-
- RIB_RLOCK(rh);
- rn = rh->rnh_matchaddr((void *)&sin6, &rh->head);
- if (rn != NULL && ((rn->rn_flags & RNF_ROOT) == 0)) {
- rte = RNTORT(rn);
-#ifdef RADIX_MPATH
- rte = rt_mpath_select(rte, flowid);
- if (rte == NULL) {
- RIB_RUNLOCK(rh);
- return (ENOENT);
- }
-#endif
- nh = rte->rt_nhop;
- /* Ensure route & ifp is UP */
- if (RT_LINK_IS_UP(nh->nh_ifp)) {
- fib6_rte_to_nh_extended(nh, &sin6.sin6_addr, flags,
- pnh6);
- if ((flags & NHR_REF) != 0) {
- /* TODO: Do lwref on egress ifp's */
- }
- RIB_RUNLOCK(rh);
-
- return (0);
- }
- }
- RIB_RUNLOCK(rh);
-
- return (ENOENT);
-}
-
-void
-fib6_free_nh_ext(uint32_t fibnum, struct nhop6_extended *pnh6)
-{
-
-}
-
/*
* Looks up path in fib @fibnum specified by @dst.
* Assumes scope is deembedded and provided in @scopeid.
diff --git a/sys/netinet6/in6_fib.h b/sys/netinet6/in6_fib.h
index 907d2d731949..f6195776f245 100644
--- a/sys/netinet6/in6_fib.h
+++ b/sys/netinet6/in6_fib.h
@@ -32,33 +32,6 @@
#ifndef _NETINET6_IN6_FIB_H_
#define _NETINET6_IN6_FIB_H_
-/* Basic nexthop info used for uRPF/mtu checks */
-struct nhop6_basic {
- struct ifnet *nh_ifp; /* Logical egress interface */
- uint16_t nh_mtu; /* nexthop mtu */
- uint16_t nh_flags; /* nhop flags */
- uint8_t spare[4];
- struct in6_addr nh_addr; /* GW/DST IPv4 address */
-};
-
-/* Extended nexthop info used for control protocols. */
-struct nhop6_extended {
- struct ifnet *nh_ifp; /* Logical egress interface */
- struct in6_ifaddr *nh_ia; /* Associated address. */
- uint16_t nh_mtu; /* nexthop mtu */
- uint16_t nh_flags; /* nhop flags */
- uint8_t spare[4];
- struct in6_addr nh_addr; /* GW/DST IPv6 address */
- uint64_t spare2[1];
-};
-
-int fib6_lookup_nh_basic(uint32_t fibnum, const struct in6_addr *dst,
- uint32_t scopeid, uint32_t flags, uint32_t flowid,struct nhop6_basic *pnh6);
-int fib6_lookup_nh_ext(uint32_t fibnum, const struct in6_addr *dst,
- uint32_t scopeid, uint32_t flags, uint32_t flowid,
- struct nhop6_extended *pnh6);
-void fib6_free_nh_ext(uint32_t fibnum, struct nhop6_extended *pnh6);
-
struct nhop_object *fib6_lookup(uint32_t fibnum,
const struct in6_addr *dst6, uint32_t scopeid, uint32_t flags,
uint32_t flowid);
diff --git a/sys/netinet6/in6_mcast.c b/sys/netinet6/in6_mcast.c
index 28a7fdfe638d..9da4fcb775e8 100644
--- a/sys/netinet6/in6_mcast.c
+++ b/sys/netinet6/in6_mcast.c
@@ -57,6 +57,7 @@ __FBSDID("$FreeBSD$");
#include <net/if_var.h>
#include <net/if_dl.h>
#include <net/route.h>
+#include <net/route/nhop.h>
#include <net/vnet.h>
#include <netinet/in.h>
@@ -1829,7 +1830,7 @@ static struct ifnet *
in6p_lookup_mcast_ifp(const struct inpcb *inp,
const struct sockaddr_in6 *gsin6)
{
- struct nhop6_basic nh6;
+ struct nhop_object *nh;
struct in6_addr dst;
uint32_t scopeid;
uint32_t fibnum;
@@ -1841,10 +1842,9 @@ in6p_lookup_mcast_ifp(const struct inpcb *inp,
in6_splitscope(&gsin6->sin6_addr, &dst, &scopeid);
fibnum = inp ? inp->inp_inc.inc_fibnum : RT_DEFAULT_FIB;
- if (fib6_lookup_nh_basic(fibnum, &dst, scopeid, 0, 0, &nh6) != 0)
- return (NULL);
+ nh = fib6_lookup(fibnum, &dst, scopeid, 0, 0);
- return (nh6.nh_ifp);
+ return (nh ? nh->nh_ifp : NULL);
}
/*
diff --git a/sys/netinet6/in6_src.c b/sys/netinet6/in6_src.c
index 74a4c283388a..8c0f3b334b54 100644
--- a/sys/netinet6/in6_src.c
+++ b/sys/netinet6/in6_src.c
@@ -916,15 +916,16 @@ in6_selecthlim(struct inpcb *inp, struct ifnet *ifp)
else if (ifp)
return (ND_IFINFO(ifp)->chlim);
else if (inp && !IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_faddr)) {
- struct nhop6_basic nh6;
+ struct nhop_object *nh;
struct in6_addr dst;
uint32_t fibnum, scopeid;
int hlim;
fibnum = inp->inp_inc.inc_fibnum;
in6_splitscope(&inp->in6p_faddr, &dst, &scopeid);
- if (fib6_lookup_nh_basic(fibnum, &dst, scopeid, 0, 0, &nh6)==0){
- hlim = ND_IFINFO(nh6.nh_ifp)->chlim;
+ nh = fib6_lookup(fibnum, &dst, scopeid, 0, 0);
+ if (nh != NULL) {
+ hlim = ND_IFINFO(nh->nh_ifp)->chlim;
return (hlim);
}
}