Date: Mon, 24 Aug 2015 10:28:53 +0300 From: Alexander V. Chernikov <melifaro@freebsd.org> To: Julian Elischer <julian@freebsd.org>, "src-committers@freebsd.org" <src-committers@freebsd.org>, "svn-src-projects@freebsd.org" <svn-src-projects@freebsd.org> Subject: Re: svn commit: r287047 - in projects/routing/sys: net netinet Message-ID: <385571440401333@web5h.yandex.ru> In-Reply-To: <55DAC6B8.7090004@freebsd.org> References: <201508231815.t7NIFJ1U042238@repo.freebsd.org> <55DAC6B8.7090004@freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
24.08.2015, 10:25, "Julian Elischer" <julian@freebsd.org>: > On 8/24/15 2:15 AM, Alexander V. Chernikov wrote: >> šAuthor: melifaro >> šDate: Sun Aug 23 18:15:18 2015 >> šNew Revision: 287047 >> šURL: https://svnweb.freebsd.org/changeset/base/287047 >> >> šLog: >> ššššRename ip_sendmbuf to fib4_sendmbuf() and move it to >> šššššrt_nhops api. Convert IPv4 SAS to use new routing api. >> >> šModified: >> ššššprojects/routing/sys/net/rt_nhops.c >> ššššprojects/routing/sys/net/rt_nhops.h >> ššššprojects/routing/sys/netinet/in_pcb.c >> ššššprojects/routing/sys/netinet/ip_output.c > > I object to some small aspects of this. you are moving > inet specific code out of the inet files into the > protocol independent files. please don't do this.. > and if they are in Proto-indep. files htey need to be guarded by > #ifdef INET > (or whatever it is.). better to leave them in the inet files I think.. Yes, you're right. The original idea besides rt_nhops.c was just to have new file not to interfere with anything existing. Now when I have some sort of established API I plan to move all those af-dependent functions to somewhere like netinet/in_fib.c / netinet6/in6_fib.c Does this look good for you? > >> šModified: projects/routing/sys/net/rt_nhops.c >> š============================================================================== >> š--- projects/routing/sys/net/rt_nhops.c Sun Aug 23 18:14:30 2015 (r287046) >> š+++ projects/routing/sys/net/rt_nhops.c Sun Aug 23 18:15:18 2015 (r287047) >> š@@ -315,7 +315,8 @@ fib4_lookup_prepend(uint32_t fibnum, str >> šššššššššššššššššššš* It should be already presented if we're >> šššššššššššššššššššš* sending data via known gateway. >> šššššššššššššššššššš*/ >> š- error = arpresolve_fast(lifp, gw, m->m_flags, eh->ether_dhost); >> š+ error = arpresolve_fast(lifp, gw, m ? m->m_flags : 0, >> š+ eh->ether_dhost); >> šššššššššššššššššššif (error == 0) { >> šššššššššššššššššššššššššššmemcpy(&eh->ether_shost, IF_LLADDR(lifp), ETHER_ADDR_LEN); >> šššššššššššššššššššššššššššeh->ether_type = htons(ETHERTYPE_IP); >> š@@ -332,6 +333,46 @@ fib4_lookup_prepend(uint32_t fibnum, str >> šššššššššššreturn (0); >> ššš} >> >> š+int >> š+fib4_sendmbuf(struct ifnet *ifp, struct mbuf *m, struct nhop_data *nh, >> š+ struct in_addr dst) >> š+{ >> š+ int error; >> š+ >> š+ if (nh != NULL && (nh->nh_flags & NH_FLAGS_L2_INCOMPLETE) == 0) { >> š+ >> š+ /* >> š+ * Fast path case. Most packets should >> š+ * be sent from here. >> š+ * TODO: Make special ifnet >> š+ * 'if_output_frame' handler for that. >> š+ */ >> š+ struct route_compat rc; >> š+ struct ether_header *eh; >> š+ rc.ro_flags = AF_INET << 8 | RT_NHOP; >> š+ rc.ro_nh = nh; >> š+ >> š+ M_PREPEND(m, nh->nh_count, M_NOWAIT); >> š+ if (m == NULL) >> š+ return (ENOBUFS); >> š+ eh = mtod(m, struct ether_header *); >> š+ memcpy(eh, nh->d.data, nh->nh_count); >> š+ error = (*ifp->if_output)(ifp, m, >> š+ NULL, (struct route *)&rc); >> š+ } else { >> š+ struct sockaddr_in gw_out; >> š+ memset(&gw_out, 0, sizeof(gw_out)); >> š+ gw_out.sin_len = sizeof(gw_out); >> š+ gw_out.sin_family = AF_INET; >> š+ gw_out.sin_addr = nh ? nh->d.gw4 : dst; >> š+ error = (*ifp->if_output)(ifp, m, >> š+ (const struct sockaddr *)&gw_out, NULL); >> š+ } >> š+ >> š+ return (error); >> š+} >> š+ >> š+ >> šššstatic void >> šššfib4_rte_to_nh_extended(struct rtentry *rte, struct in_addr dst, >> šššššššstruct nhop4_extended *pnh4) >> >> šModified: projects/routing/sys/net/rt_nhops.h >> š============================================================================== >> š--- projects/routing/sys/net/rt_nhops.h Sun Aug 23 18:14:30 2015 (r287046) >> š+++ projects/routing/sys/net/rt_nhops.h Sun Aug 23 18:15:18 2015 (r287047) >> š@@ -198,6 +198,9 @@ void fib4_choose_prepend(uint32_t fibnum >> šššint fib4_lookup_prepend(uint32_t fibnum, struct in_addr dst, struct mbuf *m, >> šššššššstruct nhop_data *nh, struct nhop4_extended *nh_ext); >> >> š+int fib4_sendmbuf(struct ifnet *ifp, struct mbuf *m, struct nhop_data *nh, >> š+ struct in_addr dst); >> š+ >> šššvoid fib6_free_nh(uint32_t fibnum, struct nhop_data *nh); >> šššvoid fib6_choose_prepend(uint32_t fibnum, struct nhop_data *nh_src, >> šššššššuint32_t flowid, struct nhop_data *nh, struct nhop6_extended *nh_ext); >> >> šModified: projects/routing/sys/netinet/in_pcb.c >> š============================================================================== >> š--- projects/routing/sys/netinet/in_pcb.c Sun Aug 23 18:14:30 2015 (r287046) >> š+++ projects/routing/sys/netinet/in_pcb.c Sun Aug 23 18:15:18 2015 (r287047) >> š@@ -93,6 +93,7 @@ __FBSDID("$FreeBSD$"); >> ššš#include <netinet6/in6_var.h> >> ššš#include <netinet6/ip6_var.h> >> ššš#endif /* INET6 */ >> š+#include <net/rt_nhops.h> >> >> ššš#ifdef IPSEC >> š@@ -756,8 +757,10 @@ in_pcbladdr(struct inpcb *inp, struct in >> ššš{ >> šššššššššššstruct ifaddr *ifa; >> šššššššššššstruct sockaddr *sa; >> š- struct sockaddr_in *sin; >> š- struct route sro; >> š+ struct sockaddr_in *sin, sin_storage; >> š+ struct nhop_data nhd, *pnhd; >> š+ struct nhop4_extended nh_ext; >> š+ u_int fibnum; >> šššššššššššint error; >> >> šššššššššššKASSERT(laddr != NULL, ("%s: laddr NULL", __func__)); >> š@@ -770,9 +773,8 @@ in_pcbladdr(struct inpcb *inp, struct in >> šššššššššššššššššššreturn (0); >> >> šššššššššššerror = 0; >> š- bzero(&sro, sizeof(sro)); >> >> š- sin = (struct sockaddr_in *)&sro.ro_dst; >> š+ sin = &sin_storage; >> šššššššššššsin->sin_family = AF_INET; >> šššššššššššsin->sin_len = sizeof(struct sockaddr_in); >> šššššššššššsin->sin_addr.s_addr = faddr->s_addr; >> š@@ -783,8 +785,17 @@ in_pcbladdr(struct inpcb *inp, struct in >> šššššššššššš* >> šššššššššššš* Find out route to destination. >> šššššššššššš*/ >> š+ fibnum = inp->inp_inc.inc_fibnum; >> š+ pnhd = &nhd; >> š+ memset(&nhd, 0, sizeof(nhd)); >> š+ memset(&nh_ext, 0, sizeof(nh_ext)); >> šššššššššššif ((inp->inp_socket->so_options & SO_DONTROUTE) == 0) >> š- in_rtalloc_ign(&sro, 0, inp->inp_inc.inc_fibnum); >> š+ error = fib4_lookup_prepend(fibnum, *faddr, >> š+ NULL, &nhd, &nh_ext); >> š+ if (error != 0) { >> š+ pnhd = NULL; >> š+ error = 0; >> š+ } >> >> ššššššššššš/* >> šššššššššššš* If we found a route, use the address corresponding to >> š@@ -794,7 +805,7 @@ in_pcbladdr(struct inpcb *inp, struct in >> šššššššššššš* network and try to find a corresponding interface to take >> šššššššššššš* the source address from. >> šššššššššššš*/ >> š- if (sro.ro_rt == NULL || sro.ro_rt->rt_ifp == NULL) { >> š+ if (pnhd == NULL) { >> šššššššššššššššššššstruct in_ifaddr *ia; >> šššššššššššššššššššstruct ifnet *ifp; >> >> š@@ -850,23 +861,22 @@ in_pcbladdr(struct inpcb *inp, struct in >> šššššššššššš* belonging to this jail. If so use it. >> šššššššššššš* 3. as a last resort return the 'default' jail address. >> šššššššššššš*/ >> š- if ((sro.ro_rt->rt_ifp->if_flags & IFF_LOOPBACK) == 0) { >> š+ if ((nh_ext.nh_ifp->if_flags & IFF_LOOPBACK) == 0) { >> šššššššššššššššššššstruct in_ifaddr *ia; >> šššššššššššššššššššstruct ifnet *ifp; >> š+ struct in_addr addr; >> >> ššššššššššššššššššš/* If not jailed, use the default returned. */ >> šššššššššššššššššššif (cred == NULL || !prison_flag(cred, PR_IP4)) { >> š- ia = (struct in_ifaddr *)sro.ro_rt->rt_ifa; >> š- laddr->s_addr = ia->ia_addr.sin_addr.s_addr; >> š+ laddr->s_addr = nh_ext.nh_src.s_addr; >> šššššššššššššššššššššššššššgoto done; >> ššššššššššššššššššš} >> >> ššššššššššššššššššš/* Jailed. */ >> ššššššššššššššššššš/* 1. Check if the iface address belongs to the jail. */ >> š- sin = (struct sockaddr_in *)sro.ro_rt->rt_ifa->ifa_addr; >> š- if (prison_check_ip4(cred, &sin->sin_addr) == 0) { >> š- ia = (struct in_ifaddr *)sro.ro_rt->rt_ifa; >> š- laddr->s_addr = ia->ia_addr.sin_addr.s_addr; >> š+ addr = nh_ext.nh_src; >> š+ if (prison_check_ip4(cred, &addr) == 0) { >> š+ laddr->s_addr = nh_ext.nh_src.s_addr; >> šššššššššššššššššššššššššššgoto done; >> ššššššššššššššššššš} >> >> š@@ -875,7 +885,7 @@ in_pcbladdr(struct inpcb *inp, struct in >> šššššššššššššššššššš* belonging to this jail. >> šššššššššššššššššššš*/ >> šššššššššššššššššššia = NULL; >> š- ifp = sro.ro_rt->rt_ifp; >> š+ ifp = nh_ext.nh_ifp; >> šššššššššššššššššššIF_ADDR_RLOCK(ifp); >> šššššššššššššššššššTAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) { >> šššššššššššššššššššššššššššsa = ifa->ifa_addr; >> š@@ -908,7 +918,7 @@ in_pcbladdr(struct inpcb *inp, struct in >> šššššššššššš* In case of jails, check that it is an address of the jail >> šššššššššššš* and if we cannot find, fall back to the 'default' jail address. >> šššššššššššš*/ >> š- if ((sro.ro_rt->rt_ifp->if_flags & IFF_LOOPBACK) != 0) { >> š+ if ((nh_ext.nh_ifp->if_flags & IFF_LOOPBACK) != 0) { >> šššššššššššššššššššstruct sockaddr_in sain; >> šššššššššššššššššššstruct in_ifaddr *ia; >> >> š@@ -969,8 +979,8 @@ in_pcbladdr(struct inpcb *inp, struct in >> ššššššššššš} >> >> šššdone: >> š- if (sro.ro_rt != NULL) >> š- RTFREE(sro.ro_rt); >> š+ if (pnhd != NULL) >> š+ fib4_free_nh(fibnum, pnhd); >> šššššššššššreturn (error); >> ššš} >> >> šModified: projects/routing/sys/netinet/ip_output.c >> š============================================================================== >> š--- projects/routing/sys/netinet/ip_output.c Sun Aug 23 18:14:30 2015 (r287046) >> š+++ projects/routing/sys/netinet/ip_output.c Sun Aug 23 18:15:18 2015 (r287047) >> š@@ -102,9 +102,6 @@ SYSCTL_INT(_net_inet_ip, OID_AUTO, mbuf_ >> ššš#endif >> >> šššstatic void ip_mloopback (struct ifnet *, struct mbuf *, int); >> š-static inline int ip_sendmbuf(struct ifnet *ifp, struct mbuf *m, >> š- struct nhop_data *nh, struct in_addr dst); >> š- >> >> šššextern int in_mcast_loop; >> šššextern struct protosw inetsw[]; >> š@@ -651,7 +648,7 @@ sendit: >> šššššššššššššššššššš*/ >> šššššššššššššššššššm_clrprotoflags(m); >> šššššššššššššššššššIP_PROBE(send, NULL, NULL, ip, ifp, ip, NULL); >> š- error = ip_sendmbuf(ifp, m, nh, dst); >> š+ error = fib4_sendmbuf(ifp, m, nh, dst); >> šššššššššššššššššššgoto done; >> ššššššššššš} >> >> š@@ -688,7 +685,7 @@ sendit: >> šššššššššššššššššššššššššššm_clrprotoflags(m); >> >> šššššššššššššššššššššššššššIP_PROBE(send, NULL, NULL, ip, ifp, ip, NULL); >> š- error = ip_sendmbuf(ifp, m, nh, dst); >> š+ error = fib4_sendmbuf(ifp, m, nh, dst); >> ššššššššššššššššššš} else >> šššššššššššššššššššššššššššm_freem(m); >> ššššššššššš} >> š@@ -706,45 +703,6 @@ bad: >> šššššššššššgoto done; >> ššš} >> >> š-static inline int >> š-ip_sendmbuf(struct ifnet *ifp, struct mbuf *m, struct nhop_data *nh, >> š- struct in_addr dst) >> š-{ >> š- int error; >> š- >> š- if (nh != NULL && (nh->nh_flags & NH_FLAGS_L2_INCOMPLETE) == 0) { >> š- >> š- /* >> š- * Fast path case. Most packets should >> š- * be sent from here. >> š- * TODO: Make special ifnet >> š- * 'if_output_frame' handler for that. >> š- */ >> š- struct route_compat rc; >> š- struct ether_header *eh; >> š- rc.ro_flags = AF_INET << 8 | RT_NHOP; >> š- rc.ro_nh = nh; >> š- >> š- M_PREPEND(m, nh->nh_count, M_NOWAIT); >> š- if (m == NULL) >> š- return (ENOBUFS); >> š- eh = mtod(m, struct ether_header *); >> š- memcpy(eh, nh->d.data, nh->nh_count); >> š- error = (*ifp->if_output)(ifp, m, >> š- NULL, (struct route *)&rc); >> š- } else { >> š- struct sockaddr_in gw_out; >> š- memset(&gw_out, 0, sizeof(gw_out)); >> š- gw_out.sin_len = sizeof(gw_out); >> š- gw_out.sin_family = AF_INET; >> š- gw_out.sin_addr = nh ? nh->d.gw4 : dst; >> š- error = (*ifp->if_output)(ifp, m, >> š- (const struct sockaddr *)&gw_out, NULL); >> š- } >> š- >> š- return (error); >> š-} >> š- >> ššš/* >> šššš* Create a chain of fragments which fit the given mtu. m_frag points to the >> šššš* mbuf to be fragmented; on return it points to the chain with the fragments.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?385571440401333>