diff options
author | fenner <fenner@FreeBSD.org> | 1996-07-10 01:34:36 +0000 |
---|---|---|
committer | fenner <fenner@FreeBSD.org> | 1996-07-10 01:34:36 +0000 |
commit | eed58203acaa9a77d075817f01ace989e38b3754 (patch) | |
tree | 9b9c0d7256a9bcecd941d6e0be1caa8d73d761aa /sys/net | |
parent | af327615af4f875c98b372a03590eacd7d2b1e42 (diff) | |
download | FreeBSD-src-eed58203acaa9a77d075817f01ace989e38b3754.zip FreeBSD-src-eed58203acaa9a77d075817f01ace989e38b3754.tar.gz |
Disallow host routes that point to themselves. These routes serve no
purpose, other than to get in the way of the ARP table and cause
"can't allocate llinfo" errors.
This change may cause gated or routed to start complaining when adding
such routes. If so, these programs will need to be fixed to not try
to add these routes.
Reviewed by: wollman
Diffstat (limited to 'sys/net')
-rw-r--r-- | sys/net/route.c | 35 | ||||
-rw-r--r-- | sys/net/rtsock.c | 6 |
2 files changed, 35 insertions, 6 deletions
diff --git a/sys/net/route.c b/sys/net/route.c index a873953..363a741 100644 --- a/sys/net/route.c +++ b/sys/net/route.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * @(#)route.c 8.2 (Berkeley) 11/15/93 - * $Id: route.c,v 1.32 1996/03/11 15:13:05 davidg Exp $ + * $Id: route.c,v 1.33 1996/03/29 08:02:30 fenner Exp $ */ #include "opt_mrouting.h" @@ -445,6 +445,17 @@ rtrequest(req, dst, gateway, netmask, flags, ret_nrt) if ((flags & RTF_GATEWAY) && !gateway) panic("rtrequest: GATEWAY but no gateway"); + /* + * A host route with the destination equal to the gateway + * will interfere with keeping LLINFO in the routing + * table, so disallow it. + */ + if (((flags & (RTF_HOST|RTF_GATEWAY|RTF_LLINFO)) == + (RTF_HOST|RTF_GATEWAY)) && + (dst->sa_len == gateway->sa_len) && + (bcmp(dst, gateway, dst->sa_len) == 0)) + senderr(EADDRNOTAVAIL); + if ((ifa = ifa_ifwithroute(flags, dst, gateway)) == 0) senderr(ENETUNREACH); @@ -655,11 +666,29 @@ rt_setgate(rt0, dst, gate) register struct rtentry *rt = rt0; struct radix_node_head *rnh = rt_tables[dst->sa_family]; + /* + * A host route with the destination equal to the gateway + * will interfere with keeping LLINFO in the routing + * table, so disallow it. + */ + if (((rt0->rt_flags & (RTF_HOST|RTF_GATEWAY|RTF_LLINFO)) == + (RTF_HOST|RTF_GATEWAY)) && + (dst->sa_len == gate->sa_len) && + (bcmp(dst, gate, dst->sa_len) == 0)) { + /* + * The route might already exist if this is an RTM_CHANGE + * or a routing redirect, so try to delete it. + */ + rtrequest(RTM_DELETE, (struct sockaddr *)rt_key(rt0), + rt0->rt_gateway, rt_mask(rt0), rt0->rt_flags, 0); + return EADDRNOTAVAIL; + } + if (rt->rt_gateway == 0 || glen > ROUNDUP(rt->rt_gateway->sa_len)) { old = (caddr_t)rt_key(rt); R_Malloc(new, caddr_t, dlen + glen); if (new == 0) - return 1; + return ENOBUFS; rt->rt_nodes->rn_key = new; } else { new = rt->rt_nodes->rn_key; @@ -689,7 +718,7 @@ rt_setgate(rt0, dst, gate) if (rt->rt_gwroute == rt) { RTFREE(rt->rt_gwroute); rt->rt_gwroute = 0; - return 1; /* failure */ + return EDQUOT; /* failure */ } } diff --git a/sys/net/rtsock.c b/sys/net/rtsock.c index b6b3e3b..c0491e5 100644 --- a/sys/net/rtsock.c +++ b/sys/net/rtsock.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * @(#)rtsock.c 8.5 (Berkeley) 11/2/94 - * $Id: rtsock.c,v 1.18 1996/03/11 15:13:07 davidg Exp $ + * $Id: rtsock.c,v 1.19 1996/05/08 04:28:54 gpalmer Exp $ */ #include <sys/param.h> @@ -261,8 +261,8 @@ route_output(m, so) break; case RTM_CHANGE: - if (gate && rt_setgate(rt, rt_key(rt), gate)) - senderr(EDQUOT); + if (gate && (error = rt_setgate(rt, rt_key(rt), gate))) + senderr(error); /* * If they tried to change things but didn't specify |