svn commit: r287058 - in projects/routing/sys: net netinet6
Alexander V. Chernikov
melifaro at FreeBSD.org
Sun Aug 23 18:22:43 UTC 2015
Author: melifaro
Date: Sun Aug 23 18:22:41 2015
New Revision: 287058
URL: https://svnweb.freebsd.org/changeset/base/287058
Log:
Convert several places inside netinet6/ to new api.
Modified:
projects/routing/sys/net/rt_nhops.c
projects/routing/sys/net/rt_nhops.h
projects/routing/sys/netinet6/icmp6.c
projects/routing/sys/netinet6/in6_src.c
Modified: projects/routing/sys/net/rt_nhops.c
==============================================================================
--- projects/routing/sys/net/rt_nhops.c Sun Aug 23 18:22:20 2015 (r287057)
+++ projects/routing/sys/net/rt_nhops.c Sun Aug 23 18:22:41 2015 (r287058)
@@ -384,6 +384,7 @@ fib_rte_to_nh_flags(int rt_flags)
res |= (rt_flags & RTF_BLACKHOLE) ? NHF_BLACKHOLE : 0;
res |= (rt_flags & (RTF_DYNAMIC|RTF_MODIFIED)) ? NHF_REDIRECT : 0;
res |= (rt_flags & RTF_BROADCAST) ? NHF_BROADCAST : 0;
+ res |= (rt_flags & RTF_GATEWAY) ? NHF_GATEWAY : 0;
return (res);
}
Modified: projects/routing/sys/net/rt_nhops.h
==============================================================================
--- projects/routing/sys/net/rt_nhops.h Sun Aug 23 18:22:20 2015 (r287057)
+++ projects/routing/sys/net/rt_nhops.h Sun Aug 23 18:22:41 2015 (r287058)
@@ -98,6 +98,7 @@ struct nhop_prepend {
#define NHF_REDIRECT 0x0040 /* RTF_DYNAMIC|RTF_MODIFIED */
#define NHF_DEFAULT 0x0080 /* Default route */
#define NHF_BROADCAST 0x0100 /* RTF_BROADCAST */
+#define NHF_GATEWAY 0x0200 /* RTF_GATEWAY */
#define NH_LIFP(nh) ifnet_byindex_locked((nh)->lifp_idx)
#define NH_TIFP(nh) ifnet_byindex_locked((nh)->i.ifp_idx)
Modified: projects/routing/sys/netinet6/icmp6.c
==============================================================================
--- projects/routing/sys/netinet6/icmp6.c Sun Aug 23 18:22:20 2015 (r287057)
+++ projects/routing/sys/netinet6/icmp6.c Sun Aug 23 18:22:41 2015 (r287058)
@@ -109,6 +109,8 @@ __FBSDID("$FreeBSD$");
#include <netinet6/nd6.h>
#include <netinet6/send.h>
+#include <net/rt_nhops.h>
+
extern struct domain inet6domain;
VNET_PCPUSTAT_DEFINE(struct icmp6stat, icmp6stat);
@@ -2289,7 +2291,6 @@ icmp6_redirect_input(struct mbuf *m, int
int icmp6len = ntohs(ip6->ip6_plen);
char *lladdr = NULL;
int lladdrlen = 0;
- struct rtentry *rt = NULL;
int is_router;
int is_onlink;
struct in6_addr src6 = ip6->ip6_src;
@@ -2344,18 +2345,11 @@ icmp6_redirect_input(struct mbuf *m, int
}
{
/* ip6->ip6_src must be equal to gw for icmp6->icmp6_reddst */
- struct sockaddr_in6 sin6;
- struct in6_addr *gw6;
+ struct nhop6_extended nh_ext;
- bzero(&sin6, sizeof(sin6));
- sin6.sin6_family = AF_INET6;
- sin6.sin6_len = sizeof(struct sockaddr_in6);
- bcopy(&reddst6, &sin6.sin6_addr, sizeof(reddst6));
- rt = in6_rtalloc1((struct sockaddr *)&sin6, 0, 0UL, RT_DEFAULT_FIB);
- if (rt) {
- if (rt->rt_gateway == NULL ||
- rt->rt_gateway->sa_family != AF_INET6) {
- RTFREE_LOCKED(rt);
+ if (fib6_lookup_nh_ext(RT_DEFAULT_FIB, reddst6, 0, 0, 0, &nh_ext) == 0){
+ /* XXX: Think about AF_LINK GW */
+ if ((nh_ext.nh_flags & NHF_GATEWAY) == 0) {
nd6log((LOG_ERR,
"ICMP6 redirect rejected; no route "
"with inet6 gateway found for redirect dst: %s\n",
@@ -2363,14 +2357,12 @@ icmp6_redirect_input(struct mbuf *m, int
goto bad;
}
- gw6 = &(((struct sockaddr_in6 *)rt->rt_gateway)->sin6_addr);
- if (bcmp(&src6, gw6, sizeof(struct in6_addr)) != 0) {
- RTFREE_LOCKED(rt);
+ if (bcmp(&src6, &nh_ext.nh_addr, sizeof(struct in6_addr)) != 0){
nd6log((LOG_ERR,
"ICMP6 redirect rejected; "
"not equal to gw-for-src=%s (must be same): "
"%s\n",
- ip6_sprintf(ip6buf, gw6),
+ ip6_sprintf(ip6buf, &nh_ext.nh_addr),
icmp6_redirect_diag(&src6, &reddst6, &redtgt6)));
goto bad;
}
@@ -2381,8 +2373,6 @@ icmp6_redirect_input(struct mbuf *m, int
icmp6_redirect_diag(&src6, &reddst6, &redtgt6)));
goto bad;
}
- RTFREE_LOCKED(rt);
- rt = NULL;
}
if (IN6_IS_ADDR_MULTICAST(&reddst6)) {
nd6log((LOG_ERR,
Modified: projects/routing/sys/netinet6/in6_src.c
==============================================================================
--- projects/routing/sys/netinet6/in6_src.c Sun Aug 23 18:22:20 2015 (r287057)
+++ projects/routing/sys/netinet6/in6_src.c Sun Aug 23 18:22:41 2015 (r287058)
@@ -110,6 +110,8 @@ __FBSDID("$FreeBSD$");
#include <netinet6/scope6_var.h>
#include <netinet6/nd6.h>
+#include <net/rt_nhops.h>
+
static struct mtx addrsel_lock;
#define ADDRSEL_LOCK_INIT() mtx_init(&addrsel_lock, "addrsel_lock", NULL, MTX_DEF)
#define ADDRSEL_LOCK() mtx_lock(&addrsel_lock)
@@ -904,19 +906,17 @@ in6_selecthlim(struct inpcb *in6p, struc
else if (ifp)
return (ND_IFINFO(ifp)->chlim);
else if (in6p && !IN6_IS_ADDR_UNSPECIFIED(&in6p->in6p_faddr)) {
- struct route_in6 ro6;
- struct ifnet *lifp;
-
- bzero(&ro6, sizeof(ro6));
- ro6.ro_dst.sin6_family = AF_INET6;
- ro6.ro_dst.sin6_len = sizeof(struct sockaddr_in6);
- ro6.ro_dst.sin6_addr = in6p->in6p_faddr;
- in6_rtalloc(&ro6, in6p->inp_inc.inc_fibnum);
- if (ro6.ro_rt) {
- lifp = ro6.ro_rt->rt_ifp;
- RTFREE(ro6.ro_rt);
- if (lifp)
- return (ND_IFINFO(lifp)->chlim);
+ struct nhop6_extended nh_ext;
+ uint32_t fibnum;
+ int hlim;
+
+ fibnum = in6p->inp_inc.inc_fibnum;
+
+ if (fib6_lookup_nh_ext(fibnum, in6p->in6p_faddr, 0, 0,
+ NHOP_LOOKUP_REF, &nh_ext) == 0) {
+ hlim = ND_IFINFO(nh_ext.nh_ifp)->chlim;
+ fib6_free_nh_ext(fibnum, &nh_ext);
+ return (hlim);
}
}
return (V_ip6_defhlim);
More information about the svn-src-projects
mailing list