Date: Sun, 23 Aug 2015 18:17:39 +0000 (UTC) From: "Alexander V. Chernikov" <melifaro@FreeBSD.org> To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r287050 - projects/routing/sys/netinet Message-ID: <201508231817.t7NIHdFN042464@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: melifaro Date: Sun Aug 23 18:17:38 2015 New Revision: 287050 URL: https://svnweb.freebsd.org/changeset/base/287050 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 Sun Aug 23 18:16:41 2015 (r287049) +++ projects/routing/sys/netinet/ip_icmp.c Sun Aug 23 18:17:38 2015 (r287050) @@ -65,6 +65,8 @@ __FBSDID("$FreeBSD$"); #include <netinet/tcpip.h> #include <netinet/icmp_var.h> +#include <net/rt_nhops.h> + #ifdef INET #include <machine/in_cksum.h> @@ -656,6 +658,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)) || @@ -748,14 +751,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 Sun Aug 23 18:16:41 2015 (r287049) +++ projects/routing/sys/netinet/ip_input.c Sun Aug 23 18:17:38 2015 (r287050) @@ -844,33 +844,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, @@ -898,10 +871,9 @@ void ip_forward(struct mbuf *m, int srcrt) { struct ip *ip = mtod(m, struct ip *); - struct in_ifaddr *ia; struct mbuf *mcopy; - struct sockaddr_in *sin; struct in_addr dest; + struct nhop4_basic nh4, *pnh4; struct route ro; struct route_info ri; int error, type = 0, code = 0, mtu = 0; @@ -930,30 +902,16 @@ ip_forward(struct mbuf *m, int srcrt) } #endif - bzero(&ro, sizeof(ro)); - sin = (struct sockaddr_in *)&ro.ro_dst; - sin->sin_family = AF_INET; - sin->sin_len = sizeof(*sin); - sin->sin_addr = ip->ip_dst; -#ifdef RADIX_MPATH - rtalloc_mpath_fib(&ro, - ntohl(ip->ip_src.s_addr ^ ip->ip_dst.s_addr), - M_GETFIB(m)); -#else - in_rtalloc_ign(&ro, 0, M_GETFIB(m)); -#endif - if (ro.ro_rt != NULL) { - ia = ifatoia(ro.ro_rt->rt_ifa); - ifa_ref(&ia->ia_ifa); - } else - ia = NULL; + 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); RO_RTFREE(&ro); return; @@ -1011,7 +969,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 rtentry *rt; rt = ro.ro_rt; @@ -1050,14 +1008,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; } @@ -1085,36 +1039,16 @@ 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; case ENOBUFS: 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 Sun Aug 23 18:16:41 2015 (r287049) +++ projects/routing/sys/netinet/ip_options.c Sun Aug 23 18:17:38 2015 (r287050) @@ -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 Sun Aug 23 18:16:41 2015 (r287049) +++ projects/routing/sys/netinet/ip_var.h Sun Aug 23 18:17:38 2015 (r287050) @@ -223,8 +223,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);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201508231817.t7NIHdFN042464>