aboutsummaryrefslogtreecommitdiff
path: root/sys/netinet/ip_fastfwd.c
diff options
context:
space:
mode:
authorAlexander V. Chernikov <melifaro@FreeBSD.org>2020-04-14 23:06:25 +0000
committerAlexander V. Chernikov <melifaro@FreeBSD.org>2020-04-14 23:06:25 +0000
commit9ac7c6cfed7262ebe46ad5b43978cc96ae333b8e (patch)
tree81021167b34d0543f19ef855a7b3e7260f487178 /sys/netinet/ip_fastfwd.c
parentfb8ed4c5f8ca5b8b9c4106832538b0b90673dde1 (diff)
downloadsrc-9ac7c6cfed7262ebe46ad5b43978cc96ae333b8e.tar.gz
src-9ac7c6cfed7262ebe46ad5b43978cc96ae333b8e.zip
Convert IP/IPv6 forwarding, ICMP processing and IP PCB laddr selection to
the new routing KPI. Reviewed by: ae Differential Revision: https://reviews.freebsd.org/D24245
Notes
Notes: svn path=/head/; revision=359942
Diffstat (limited to 'sys/netinet/ip_fastfwd.c')
-rw-r--r--sys/netinet/ip_fastfwd.c41
1 files changed, 24 insertions, 17 deletions
diff --git a/sys/netinet/ip_fastfwd.c b/sys/netinet/ip_fastfwd.c
index 502bd15cb072..10746a3e180f 100644
--- a/sys/netinet/ip_fastfwd.c
+++ b/sys/netinet/ip_fastfwd.c
@@ -96,6 +96,7 @@ __FBSDID("$FreeBSD$");
#include <net/if_dl.h>
#include <net/pfil.h>
#include <net/route.h>
+#include <net/route/nhop.h>
#include <net/vnet.h>
#include <netinet/in.h>
@@ -111,11 +112,13 @@ __FBSDID("$FreeBSD$");
#include <machine/in_cksum.h>
static int
-ip_findroute(struct nhop4_basic *pnh, struct in_addr dest, struct mbuf *m)
+ip_findroute(struct nhop_object **pnh, struct in_addr dest, struct mbuf *m)
{
+ struct nhop_object *nh;
- bzero(pnh, sizeof(*pnh));
- if (fib4_lookup_nh_basic(M_GETFIB(m), dest, 0, 0, pnh) != 0) {
+ nh = fib4_lookup(M_GETFIB(m), dest, 0, NHR_NONE,
+ m->m_pkthdr.flowid);
+ if (nh == NULL) {
IPSTAT_INC(ips_noroute);
IPSTAT_INC(ips_cantforward);
icmp_error(m, ICMP_UNREACH, ICMP_UNREACH_HOST, 0, 0);
@@ -124,18 +127,20 @@ ip_findroute(struct nhop4_basic *pnh, struct in_addr dest, struct mbuf *m)
/*
* Drop blackholed traffic and directed broadcasts.
*/
- if ((pnh->nh_flags & (NHF_BLACKHOLE | NHF_BROADCAST)) != 0) {
+ if ((nh->nh_flags & (NHF_BLACKHOLE | NHF_BROADCAST)) != 0) {
IPSTAT_INC(ips_cantforward);
m_freem(m);
return (EHOSTUNREACH);
}
- if (pnh->nh_flags & NHF_REJECT) {
+ if (nh->nh_flags & NHF_REJECT) {
IPSTAT_INC(ips_cantforward);
icmp_error(m, ICMP_UNREACH, ICMP_UNREACH_HOST, 0, 0);
return (EHOSTUNREACH);
}
+ *pnh = nh;
+
return (0);
}
@@ -151,7 +156,7 @@ ip_tryforward(struct mbuf *m)
{
struct ip *ip;
struct mbuf *m0 = NULL;
- struct nhop4_basic nh;
+ struct nhop_object *nh;
struct sockaddr_in dst;
struct in_addr dest, odest, rtdest;
uint16_t ip_len, ip_off;
@@ -323,7 +328,7 @@ passin:
if (!PFIL_HOOKED_OUT(V_inet_pfil_head))
goto passout;
- if (pfil_run_hooks(V_inet_pfil_head, &m, nh.nh_ifp,
+ if (pfil_run_hooks(V_inet_pfil_head, &m, nh->nh_ifp,
PFIL_OUT | PFIL_FWD, NULL) != PFIL_PASS)
goto drop;
@@ -376,12 +381,15 @@ passout:
bzero(&dst, sizeof(dst));
dst.sin_family = AF_INET;
dst.sin_len = sizeof(dst);
- dst.sin_addr = nh.nh_addr;
+ if (nh->nh_flags & NHF_GATEWAY)
+ dst.sin_addr = nh->gw4_sa.sin_addr;
+ else
+ dst.sin_addr = dest;
/*
* Check if packet fits MTU or if hardware will fragment for us
*/
- if (ip_len <= nh.nh_mtu) {
+ if (ip_len <= nh->nh_mtu) {
/*
* Avoid confusing lower layers.
*/
@@ -389,8 +397,8 @@ passout:
/*
* Send off the packet via outgoing interface
*/
- IP_PROBE(send, NULL, NULL, ip, nh.nh_ifp, ip, NULL);
- error = (*nh.nh_ifp->if_output)(nh.nh_ifp, m,
+ IP_PROBE(send, NULL, NULL, ip, nh->nh_ifp, ip, NULL);
+ error = (*nh->nh_ifp->if_output)(nh->nh_ifp, m,
(struct sockaddr *)&dst, NULL);
} else {
/*
@@ -399,15 +407,15 @@ passout:
if (ip_off & IP_DF) {
IPSTAT_INC(ips_cantfrag);
icmp_error(m, ICMP_UNREACH, ICMP_UNREACH_NEEDFRAG,
- 0, nh.nh_mtu);
+ 0, nh->nh_mtu);
goto consumed;
} else {
/*
* We have to fragment the packet
*/
m->m_pkthdr.csum_flags |= CSUM_IP;
- if (ip_fragment(ip, &m, nh.nh_mtu,
- nh.nh_ifp->if_hwassist) != 0)
+ if (ip_fragment(ip, &m, nh->nh_mtu,
+ nh->nh_ifp->if_hwassist) != 0)
goto drop;
KASSERT(m != NULL, ("null mbuf and no error"));
/*
@@ -423,10 +431,9 @@ passout:
m_clrprotoflags(m);
IP_PROBE(send, NULL, NULL,
- mtod(m, struct ip *), nh.nh_ifp,
+ mtod(m, struct ip *), nh->nh_ifp,
mtod(m, struct ip *), NULL);
- /* XXX: we can use cached route here */
- error = (*nh.nh_ifp->if_output)(nh.nh_ifp, m,
+ error = (*nh->nh_ifp->if_output)(nh->nh_ifp, m,
(struct sockaddr *)&dst, NULL);
if (error)
break;