summaryrefslogtreecommitdiffstats
path: root/sys/net/route.c
diff options
context:
space:
mode:
authorfenner <fenner@FreeBSD.org>1996-07-10 01:34:36 +0000
committerfenner <fenner@FreeBSD.org>1996-07-10 01:34:36 +0000
commiteed58203acaa9a77d075817f01ace989e38b3754 (patch)
tree9b9c0d7256a9bcecd941d6e0be1caa8d73d761aa /sys/net/route.c
parentaf327615af4f875c98b372a03590eacd7d2b1e42 (diff)
downloadFreeBSD-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/route.c')
-rw-r--r--sys/net/route.c35
1 files changed, 32 insertions, 3 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 */
}
}
OpenPOWER on IntegriCloud