Invalidate cached forwarding route (ipforward_rt) whenever a new route

is added to the routing table, otherwise we may end up using the wrong
route when forwarding.

PR:		kern/10778
Reviewed by:	silence on -net
This commit is contained in:
Ruslan Ermilov 2001-03-19 09:16:16 +00:00
parent 6eec3af9fe
commit 1e3d5af041
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=74454
3 changed files with 14 additions and 1 deletions

View File

@ -54,6 +54,7 @@
#include <net/route.h>
#include <netinet/in.h>
#include <netinet/in_var.h>
#include <netinet/ip_var.h>
extern int in_inithead __P((void **head, int off));
@ -137,6 +138,17 @@ in_addroute(void *v_arg, void *n_arg, struct radix_node_head *head,
RTFREE(rt2);
}
}
/*
* If the new route created successfully, and we are forwarding,
* and there is a cached route, free it. Otherwise, we may end
* up using the wrong route.
*/
if (ret != NULL && ipforwarding && ipforward_rt.ro_rt) {
RTFREE(ipforward_rt.ro_rt);
ipforward_rt.ro_rt = 0;
}
return ret;
}

View File

@ -257,7 +257,7 @@ ip_init()
}
static struct sockaddr_in ipaddr = { sizeof(ipaddr), AF_INET };
static struct route ipforward_rt;
struct route ipforward_rt;
/*
* Ip input routine. Checksum and byte swap header. If fragmented

View File

@ -141,6 +141,7 @@ extern struct ipstat ipstat;
extern u_short ip_id; /* ip packet ctr, for ids */
extern int ip_defttl; /* default IP ttl */
extern int ipforwarding; /* ip forwarding */
extern struct route ipforward_rt; /* ip forwarding cached route */
extern u_char ip_protox[];
extern struct socket *ip_rsvpd; /* reservation protocol daemon */
extern struct socket *ip_mrouter; /* multicast routing daemon */