svn commit: r273597 - projects/routing/sys/netinet
Alexander V. Chernikov
melifaro at FreeBSD.org
Fri Oct 24 17:40:34 UTC 2014
Author: melifaro
Date: Fri Oct 24 17:40:32 2014
New Revision: 273597
URL: https://svnweb.freebsd.org/changeset/base/273597
Log:
Convert all ip_rtaddr() users to fib4_lookup_nh_extended().
Remove ip_rtaddr().
Modified:
projects/routing/sys/netinet/ip_icmp.c
projects/routing/sys/netinet/ip_input.c
projects/routing/sys/netinet/ip_options.c
projects/routing/sys/netinet/ip_var.h
Modified: projects/routing/sys/netinet/ip_icmp.c
==============================================================================
--- projects/routing/sys/netinet/ip_icmp.c Fri Oct 24 17:24:29 2014 (r273596)
+++ projects/routing/sys/netinet/ip_icmp.c Fri Oct 24 17:40:32 2014 (r273597)
@@ -64,6 +64,8 @@ __FBSDID("$FreeBSD$");
#include <netinet/tcpip.h>
#include <netinet/icmp_var.h>
+#include <net/rt_nhops.h>
+
#ifdef INET
#ifdef IPSEC
#include <netipsec/ipsec.h>
@@ -709,6 +711,7 @@ icmp_reflect(struct mbuf *m)
struct in_ifaddr *ia;
struct in_addr t;
struct mbuf *opts = 0;
+ struct nhop4_extended nh_ext;
int optlen = (ip->ip_hl << 2) - sizeof(struct ip);
if (IN_MULTICAST(ntohl(ip->ip_src.s_addr)) ||
@@ -801,14 +804,12 @@ icmp_reflect(struct mbuf *m)
* When we don't have a route back to the packet source, stop here
* and drop the packet.
*/
- ia = ip_rtaddr(ip->ip_dst, M_GETFIB(m));
- if (ia == NULL) {
+ if (fib4_lookup_nh_extended(M_GETFIB(m), ip->ip_dst, 0, &nh_ext) != 0) {
m_freem(m);
ICMPSTAT_INC(icps_noroute);
goto done;
}
- t = IA_SIN(ia)->sin_addr;
- ifa_free(&ia->ia_ifa);
+ t = nh_ext.nh_src;
match:
#ifdef MAC
mac_netinet_icmp_replyinplace(m);
Modified: projects/routing/sys/netinet/ip_input.c
==============================================================================
--- projects/routing/sys/netinet/ip_input.c Fri Oct 24 17:24:29 2014 (r273596)
+++ projects/routing/sys/netinet/ip_input.c Fri Oct 24 17:40:32 2014 (r273597)
@@ -1415,33 +1415,6 @@ ipproto_unregister(short ipproto)
return (0);
}
-/*
- * Given address of next destination (final or next hop), return (referenced)
- * internet address info of interface to be used to get there.
- */
-struct in_ifaddr *
-ip_rtaddr(struct in_addr dst, u_int fibnum)
-{
- struct route sro;
- struct sockaddr_in *sin;
- struct in_ifaddr *ia;
-
- bzero(&sro, sizeof(sro));
- sin = (struct sockaddr_in *)&sro.ro_dst;
- sin->sin_family = AF_INET;
- sin->sin_len = sizeof(*sin);
- sin->sin_addr = dst;
- in_rtalloc_ign(&sro, 0, fibnum);
-
- if (sro.ro_rt == NULL)
- return (NULL);
-
- ia = ifatoia(sro.ro_rt->rt_ifa);
- ifa_ref(&ia->ia_ifa);
- RTFREE(sro.ro_rt);
- return (ia);
-}
-
u_char inetctlerrmap[PRC_NCMDS] = {
0, 0, 0, 0,
0, EMSGSIZE, EHOSTDOWN, EHOSTUNREACH,
@@ -1469,9 +1442,9 @@ void
ip_forward(struct mbuf *m, int srcrt)
{
struct ip *ip = mtod(m, struct ip *);
- struct in_ifaddr *ia;
struct mbuf *mcopy;
struct in_addr dest;
+ struct nhop4_basic nh4, *pnh4;
struct route ro;
struct route_info ri;
int error, type = 0, code = 0, mtu = 0;
@@ -1493,14 +1466,16 @@ ip_forward(struct mbuf *m, int srcrt)
}
#endif
- ia = ip_rtaddr(ip->ip_dst, M_GETFIB(m));
+ pnh4 = &nh4;
+ if (fib4_lookup_nh_basic(M_GETFIB(m), ip->ip_dst, 0, &nh4) != 0)
+ pnh4 = NULL;
#ifndef IPSEC
/*
* 'ia' may be NULL if there is no route for this destination.
* In case of IPsec, Don't discard it just yet, but pass it to
* ip_output in case of outgoing IPsec policy.
*/
- if (!srcrt && ia == NULL) {
+ if (!srcrt && pnh4 == NULL) {
icmp_error(m, ICMP_UNREACH, ICMP_UNREACH_HOST, 0, 0);
return;
}
@@ -1557,7 +1532,7 @@ ip_forward(struct mbuf *m, int srcrt)
*/
dest.s_addr = 0;
if (!srcrt && V_ipsendredirects &&
- ia != NULL && ia->ia_ifp == m->m_pkthdr.rcvif) {
+ pnh4 != NULL && nh4.nh_ifp == m->m_pkthdr.rcvif) {
struct sockaddr_in *sin;
struct rtentry *rt;
@@ -1610,14 +1585,10 @@ ip_forward(struct mbuf *m, int srcrt)
else {
if (mcopy)
m_freem(mcopy);
- if (ia != NULL)
- ifa_free(&ia->ia_ifa);
return;
}
}
if (mcopy == NULL) {
- if (ia != NULL)
- ifa_free(&ia->ia_ifa);
return;
}
@@ -1645,24 +1616,8 @@ ip_forward(struct mbuf *m, int srcrt)
* If IPsec is configured for this path,
* override any possibly mtu value set by ip_output.
*/
- mtu = ip_ipsec_mtu(mcopy, mtu);
+ mtu = min(ri.ri_mtu, ip_ipsec_mtu(mcopy, mtu));
#endif /* IPSEC */
- /*
- * If the MTU was set before make sure we are below the
- * interface MTU.
- * If the MTU wasn't set before use the interface mtu or
- * fall back to the next smaller mtu step compared to the
- * current packet size.
- */
- if (mtu != 0) {
- if (ia != NULL)
- mtu = min(mtu, ia->ia_ifp->if_mtu);
- } else {
- if (ia != NULL)
- mtu = ia->ia_ifp->if_mtu;
- else
- mtu = ip_next_mtu(ntohs(ip->ip_len), 0);
- }
IPSTAT_INC(ips_cantfrag);
break;
@@ -1677,8 +1632,6 @@ ip_forward(struct mbuf *m, int srcrt)
*/
if (V_ip_sendsourcequench == 0) {
m_freem(mcopy);
- if (ia != NULL)
- ifa_free(&ia->ia_ifa);
return;
} else {
type = ICMP_SOURCEQUENCH;
@@ -1688,12 +1641,8 @@ ip_forward(struct mbuf *m, int srcrt)
case EACCES: /* ipfw denied packet */
m_freem(mcopy);
- if (ia != NULL)
- ifa_free(&ia->ia_ifa);
return;
}
- if (ia != NULL)
- ifa_free(&ia->ia_ifa);
icmp_error(mcopy, type, code, dest.s_addr, mtu);
}
Modified: projects/routing/sys/netinet/ip_options.c
==============================================================================
--- projects/routing/sys/netinet/ip_options.c Fri Oct 24 17:24:29 2014 (r273596)
+++ projects/routing/sys/netinet/ip_options.c Fri Oct 24 17:40:32 2014 (r273597)
@@ -63,6 +63,8 @@ __FBSDID("$FreeBSD$");
#include <netinet/ip_icmp.h>
#include <machine/in_cksum.h>
+#include <net/rt_nhops.h>
+
#include <sys/socketvar.h>
static VNET_DEFINE(int, ip_dosourceroute);
@@ -104,6 +106,7 @@ ip_dooptions(struct mbuf *m, int pass)
int opt, optlen, cnt, off, code, type = ICMP_PARAMPROB, forward = 0;
struct in_addr *sin, dst;
uint32_t ntime;
+ struct nhop4_extended nh_ext;
struct sockaddr_in ipaddr = { sizeof(ipaddr), AF_INET };
/* Ignore or reject packets with IP options. */
@@ -235,18 +238,28 @@ dropit:
if (ia == NULL)
ia = (INA)ifa_ifwithnet((SA)&ipaddr, 0,
RT_ALL_FIBS);
- } else
-/* XXX MRT 0 for routing */
- ia = ip_rtaddr(ipaddr.sin_addr, M_GETFIB(m));
- if (ia == NULL) {
- type = ICMP_UNREACH;
- code = ICMP_UNREACH_SRCFAIL;
- goto bad;
+ if (ia == NULL) {
+ type = ICMP_UNREACH;
+ code = ICMP_UNREACH_SRCFAIL;
+ goto bad;
+ }
+
+ memcpy(cp + off, &(IA_SIN(ia)->sin_addr),
+ sizeof(struct in_addr));
+ ifa_free(&ia->ia_ifa);
+ } else {
+ /* XXX MRT 0 for routing */
+ if (fib4_lookup_nh_extended(M_GETFIB(m),
+ ipaddr.sin_addr, 0, &nh_ext) != 0) {
+ type = ICMP_UNREACH;
+ code = ICMP_UNREACH_SRCFAIL;
+ goto bad;
+ }
+
+ memcpy(cp + off, &nh_ext.nh_src,
+ sizeof(struct in_addr));
}
ip->ip_dst = ipaddr.sin_addr;
- (void)memcpy(cp + off, &(IA_SIN(ia)->sin_addr),
- sizeof(struct in_addr));
- ifa_free(&ia->ia_ifa);
cp[IPOPT_OFFSET] += sizeof(struct in_addr);
/*
* Let ip_intr's mcast routing check handle mcast pkts
@@ -280,15 +293,19 @@ dropit:
* destination, use the incoming interface (should be
* same).
*/
- if ((ia = (INA)ifa_ifwithaddr((SA)&ipaddr)) == NULL &&
- (ia = ip_rtaddr(ipaddr.sin_addr, M_GETFIB(m))) == NULL) {
+ if ((ia = (INA)ifa_ifwithaddr((SA)&ipaddr)) != NULL) {
+ memcpy(cp + off, &(IA_SIN(ia)->sin_addr),
+ sizeof(struct in_addr));
+ ifa_free(&ia->ia_ifa);
+ } else if (fib4_lookup_nh_extended(M_GETFIB(m),
+ ipaddr.sin_addr, 0, &nh_ext) == 0) {
+ memcpy(cp + off, &nh_ext.nh_src,
+ sizeof(struct in_addr));
+ } else {
type = ICMP_UNREACH;
code = ICMP_UNREACH_HOST;
goto bad;
}
- (void)memcpy(cp + off, &(IA_SIN(ia)->sin_addr),
- sizeof(struct in_addr));
- ifa_free(&ia->ia_ifa);
cp[IPOPT_OFFSET] += sizeof(struct in_addr);
break;
Modified: projects/routing/sys/netinet/ip_var.h
==============================================================================
--- projects/routing/sys/netinet/ip_var.h Fri Oct 24 17:24:29 2014 (r273596)
+++ projects/routing/sys/netinet/ip_var.h Fri Oct 24 17:40:32 2014 (r273597)
@@ -224,8 +224,6 @@ int ipproto_register(short);
int ipproto_unregister(short);
struct mbuf *
ip_reass(struct mbuf *);
-struct in_ifaddr *
- ip_rtaddr(struct in_addr, u_int fibnum);
void ip_savecontrol(struct inpcb *, struct mbuf **, struct ip *,
struct mbuf *);
void ip_slowtimo(void);
More information about the svn-src-projects
mailing list