Make fast-ipsec and ipflow (Fast Forwarding) interoperate.

The idea is that we only clear M_CANFASTFWD if an SPD exists
for the packet. Otherwise, it's safe to add a fast-forward
cache entry for the route.

To make this work properly, we invalidate the entire ipflow
cache if a fast-ipsec key is added or changed.
This commit is contained in:
scw 2003-12-12 21:17:59 +00:00
parent 4b9d54ff56
commit 6aec1d6812
4 changed files with 58 additions and 8 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: ip_flow.c,v 1.26 2002/11/02 07:28:12 perry Exp $ */
/* $NetBSD: ip_flow.c,v 1.27 2003/12/12 21:17:59 scw Exp $ */
/*-
* Copyright (c) 1998 The NetBSD Foundation, Inc.
@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ip_flow.c,v 1.26 2002/11/02 07:28:12 perry Exp $");
__KERNEL_RCSID(0, "$NetBSD: ip_flow.c,v 1.27 2003/12/12 21:17:59 scw Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -433,3 +433,19 @@ ipflow_create(
IPFLOW_INSERT(&ipflowtable[hash], ipf);
splx(s);
}
void
ipflow_invalidate_all(
void)
{
struct ipflow *ipf, *next_ipf;
int s;
s = splnet();
ipf = LIST_FIRST(&ipflowlist);
for (ipf = LIST_FIRST(&ipflowlist); ipf != NULL; ipf = next_ipf) {
next_ipf = LIST_NEXT(ipf, ipf_list);
ipflow_free(ipf);
}
splx(s);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: ip_input.c,v 1.192 2003/12/08 02:23:27 jonathan Exp $ */
/* $NetBSD: ip_input.c,v 1.193 2003/12/12 21:17:59 scw Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@ -98,7 +98,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ip_input.c,v 1.192 2003/12/08 02:23:27 jonathan Exp $");
__KERNEL_RCSID(0, "$NetBSD: ip_input.c,v 1.193 2003/12/12 21:17:59 scw Exp $");
#include "opt_inet.h"
#include "opt_gateway.h"
@ -572,7 +572,7 @@ ip_input(struct mbuf *m)
m_adj(m, len - m->m_pkthdr.len);
}
#if defined(IPSEC) || defined(FAST_IPSEC)
#if defined(IPSEC)
/* ipflow (IP fast forwarding) is not compatible with IPsec. */
m->m_flags &= ~M_CANFASTFWD;
#else
@ -806,6 +806,26 @@ ip_input(struct mbuf *m)
ipstat.ips_cantforward++;
goto bad;
}
/*
* Peek at the outbound SP for this packet to determine if
* it's a Fast Forward candidate.
*/
mtag = m_tag_find(m, PACKET_TAG_IPSEC_PENDING_TDB, NULL);
if (mtag != NULL)
m->m_flags &= ~M_CANFASTFWD;
else {
s = splsoftnet();
sp = ipsec4_checkpolicy(m, IPSEC_DIR_OUTBOUND,
(IP_FORWARDING |
(ip_directedbcast ? IP_ALLOWBROADCAST : 0)),
&error, NULL);
if (sp != NULL) {
m->m_flags &= ~M_CANFASTFWD;
KEY_FREESP(&sp);
}
splx(s);
}
#endif /* FAST_IPSEC */
ip_forward(m, srcrt);

View File

@ -1,4 +1,4 @@
/* $NetBSD: ip_var.h,v 1.64 2003/12/08 02:23:27 jonathan Exp $ */
/* $NetBSD: ip_var.h,v 1.65 2003/12/12 21:17:59 scw Exp $ */
/*
* Copyright (c) 1982, 1986, 1993
@ -251,6 +251,7 @@ void ipflow_init __P((void));
struct ipflow *ipflow_reap __P((int));
void ipflow_create __P((const struct route *, struct mbuf *));
void ipflow_slowtimo __P((void));
void ipflow_invalidate_all __P((void));
extern uint16_t ip_id;
static __inline uint16_t ip_newid __P((void));

View File

@ -1,4 +1,4 @@
/* $NetBSD: key.c,v 1.5 2003/12/12 21:04:03 scw Exp $ */
/* $NetBSD: key.c,v 1.6 2003/12/12 21:17:59 scw Exp $ */
/* $FreeBSD: /usr/local/www/cvsroot/FreeBSD/src/sys/netipsec/key.c,v 1.3.2.2 2003/07/01 01:38:13 sam Exp $ */
/* $KAME: key.c,v 1.191 2001/06/27 10:46:49 sakane Exp $ */
@ -32,7 +32,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: key.c,v 1.5 2003/12/12 21:04:03 scw Exp $");
__KERNEL_RCSID(0, "$NetBSD: key.c,v 1.6 2003/12/12 21:17:59 scw Exp $");
/*
* This code is referd to RFC 2367
@ -43,6 +43,9 @@ __KERNEL_RCSID(0, "$NetBSD: key.c,v 1.5 2003/12/12 21:04:03 scw Exp $");
#include "opt_inet6.h"
#endif
#include "opt_ipsec.h"
#ifdef __NetBSD__
#include "opt_gateway.h"
#endif
#include <sys/types.h>
#include <sys/param.h>
@ -69,6 +72,9 @@ __KERNEL_RCSID(0, "$NetBSD: key.c,v 1.5 2003/12/12 21:04:03 scw Exp $");
#include <netinet/in_systm.h>
#include <netinet/ip.h>
#include <netinet/in_var.h>
#ifdef INET
#include <netinet/ip_var.h>
#endif
#ifdef INET6
#include <netinet/ip6.h>
@ -1794,6 +1800,13 @@ key_spdadd(so, m, mhp)
}
}
#if defined(__NetBSD__) && defined(GATEWAY)
/*
* Nail the ipflow cache, since we're adding/changing an SPD
*/
ipflow_invalidate_all();
#endif
/* allocation new SP entry */
if ((newsp = key_msg2sp(xpl0, PFKEY_EXTLEN(xpl0), &error)) == NULL) {
return key_senderror(so, m, error);