svn commit: r273556 - projects/routing/sys/contrib/ipfilter/netinet

Alexander V. Chernikov melifaro at FreeBSD.org
Thu Oct 23 20:01:56 UTC 2014


Author: melifaro
Date: Thu Oct 23 20:01:55 2014
New Revision: 273556
URL: https://svnweb.freebsd.org/changeset/base/273556

Log:
  Convert ipfilter to use new routing API.
  Compile tested only.

Modified:
  projects/routing/sys/contrib/ipfilter/netinet/ip_fil_freebsd.c

Modified: projects/routing/sys/contrib/ipfilter/netinet/ip_fil_freebsd.c
==============================================================================
--- projects/routing/sys/contrib/ipfilter/netinet/ip_fil_freebsd.c	Thu Oct 23 19:06:08 2014	(r273555)
+++ projects/routing/sys/contrib/ipfilter/netinet/ip_fil_freebsd.c	Thu Oct 23 20:01:55 2014	(r273556)
@@ -62,6 +62,7 @@ static const char rcsid[] = "@(#)$Id$";
 #ifdef USE_INET6
 # include <netinet/icmp6.h>
 #endif
+#include <net/rt_nhops.h>
 #include "netinet/ip_fil.h"
 #include "netinet/ip_nat.h"
 #include "netinet/ip_frag.h"
@@ -706,16 +707,16 @@ ipf_fastroute(m0, mpp, fin, fdp)
 {
 	register struct ip *ip, *mhip;
 	register struct mbuf *m = *mpp;
-	register struct route *ro;
 	int len, off, error = 0, hlen, code;
+	u_int fibnum;
 	struct ifnet *ifp, *sifp;
-	struct sockaddr_in *dst;
-	struct route iproute;
+	struct in_addr dst;
+	struct nhop_data nhd, *pnhd;
 	u_short ip_off;
 	frdest_t node;
 	frentry_t *fr;
 
-	ro = NULL;
+	pnhd = NULL;
 
 #ifdef M_WRITABLE
 	/*
@@ -760,11 +761,10 @@ ipf_fastroute(m0, mpp, fin, fdp)
 	/*
 	 * Route packet.
 	 */
-	ro = &iproute;
-	bzero(ro, sizeof (*ro));
-	dst = (struct sockaddr_in *)&ro->ro_dst;
-	dst->sin_family = AF_INET;
-	dst->sin_addr = ip->ip_dst;
+	fibnum = M_GETFIB(m0);
+	dst = ip->ip_dst;
+	memset(&nhd, 0, sizeof(nhd));
+	pnhd = &nhd;
 
 	fr = fin->fin_fr;
 	if ((fr != NULL) && !(fr->fr_flags & FR_KEEPSTATE) && (fdp != NULL) &&
@@ -784,25 +784,21 @@ ipf_fastroute(m0, mpp, fin, fdp)
 	}
 
 	if ((fdp != NULL) && (fdp->fd_ip.s_addr != 0))
-		dst->sin_addr = fdp->fd_ip;
+		dst = fdp->fd_ip;
 
-	dst->sin_len = sizeof(*dst);
-	in_rtalloc(ro, M_GETFIB(m0));
 
-	if ((ifp == NULL) && (ro->ro_rt != NULL))
-		ifp = ro->ro_rt->rt_ifp;
+	error = fib4_lookup_prepend(fibnum, dst, m0, pnhd, NULL);
 
-	if ((ro->ro_rt == NULL) || (ifp == NULL)) {
+	if (error != 0) {
+		pnhd = NULL;
 		if (in_localaddr(ip->ip_dst))
 			error = EHOSTUNREACH;
 		else
 			error = ENETUNREACH;
 		goto bad;
 	}
-	if (ro->ro_rt->rt_flags & RTF_GATEWAY)
-		dst = (struct sockaddr_in *)ro->ro_rt->rt_gateway;
-	if (ro->ro_rt)
-		counter_u64_add(ro->ro_rt->rt_pksent, 1);
+
+	ifp = NH_LIFP(pnhd);
 
 	/*
 	 * For input packets which are being "fastrouted", they won't
@@ -846,9 +842,7 @@ ipf_fastroute(m0, mpp, fin, fdp)
 	if (ntohs(ip->ip_len) <= ifp->if_mtu) {
 		if (!ip->ip_sum)
 			ip->ip_sum = in_cksum(m, hlen);
-		error = (*ifp->if_output)(ifp, m, (struct sockaddr *)dst,
-			    ro
-			);
+		error = fib4_sendmbuf(ifp, m, pnhd, dst);
 		goto done;
 	}
 	/*
@@ -928,10 +922,7 @@ sendorfree:
 		m0 = m->m_act;
 		m->m_act = 0;
 		if (error == 0)
-			error = (*ifp->if_output)(ifp, m,
-			    (struct sockaddr *)dst,
-			    ro
-			    );
+			error = fib4_sendmbuf(ifp, m, pnhd, dst);
 		else
 			FREE_MB_T(m);
 	}
@@ -942,9 +933,8 @@ done:
 	else
 		ipfmain.ipf_frouteok[1]++;
 
-	if ((ro != NULL) && (ro->ro_rt != NULL)) {
-		RTFREE(ro->ro_rt);
-	}
+	if (pnhd != NULL)
+		fib4_free_nh(fibnum, pnhd);
 	return 0;
 bad:
 	if (error == EMSGSIZE) {
@@ -965,18 +955,13 @@ int
 ipf_verifysrc(fin)
 	fr_info_t *fin;
 {
-	struct sockaddr_in *dst;
-	struct route iproute;
+	struct nhop4_basic nh4;
 
-	bzero((char *)&iproute, sizeof(iproute));
-	dst = (struct sockaddr_in *)&iproute.ro_dst;
-	dst->sin_len = sizeof(*dst);
-	dst->sin_family = AF_INET;
-	dst->sin_addr = fin->fin_src;
-	in_rtalloc(&iproute, 0);
-	if (iproute.ro_rt == NULL)
-		return 0;
-	return (fin->fin_ifp == iproute.ro_rt->rt_ifp);
+	memset(&nh4, 0, sizeof(nh4));
+	if (fib4_lookup_nh_basic(RT_DEFAULT_FIB, fin->fin_src, 0, &nh4) != 0)
+		return (0);
+
+	return (fin->fin_ifp == nh4.nh_ifp);
 }
 
 


More information about the svn-src-projects mailing list