From: David Greenman Date: Thu, 10 Feb 1994 11:04:48 +0000 (+0000) Subject: Patch from Michael Galassi (nerd@percy.rain.com): X-Git-Tag: FreeBSD-release/1.1~126 X-Git-Url: https://git.subgeniuskitty.com/unix-history/.git/commitdiff_plain/57742e6e1ce591248d8b22bd0cd070bd8a016791 Patch from Michael Galassi (nerd@percy.rain.com): The problem as I saw it was that a route was being added to the routing tables in the kernel even in the case where the interface pointer in the route structure was a null, this was fine until an atempt was made to remove this route at which point a zero derefernce was "commited" and the inevitable core was dumped. The easy solution turns out to be to check for a null interface pointer and not add the route. The only time I've observed the problem is when adding a route to the local end of a point to point connection (SLIP or PPP). --- diff --git a/sbin/routed/tables.c b/sbin/routed/tables.c index a05e023f3a..17a4fb7b96 100644 --- a/sbin/routed/tables.c +++ b/sbin/routed/tables.c @@ -183,8 +183,21 @@ rtadd(dst, gate, metric, state) rt->rt_flags = RTF_UP | flags; rt->rt_state = state | RTS_CHANGED; rt->rt_ifp = if_ifwithdstaddr(&rt->rt_dst); - if (rt->rt_ifp == 0) + if (rt->rt_ifp == 0) { rt->rt_ifp = if_ifwithnet(&rt->rt_router); + /* + * seems like we can't figure out the interface for the + * IP address of the local side of a point to point + * connection, we just don't add that entry in the + * table. (it seems to already be there anyway) + */ + if (rt->rt_ifp == 0) { + syslog(LOG_DEBUG, + "rtadd: can't get interface for %s", + (*afswitch[dst->sa_family].af_format)(dst)); + return; + } + } if ((state & RTS_INTERFACE) == 0) rt->rt_flags |= RTF_GATEWAY; rt->rt_metric = metric; @@ -257,8 +270,22 @@ rtchange(rt, gate, metric) if (add) { rt->rt_router = *gate; rt->rt_ifp = if_ifwithdstaddr(&rt->rt_router); - if (rt->rt_ifp == 0) + if (rt->rt_ifp == 0) { rt->rt_ifp = if_ifwithnet(&rt->rt_router); + /* + * seems like we can't figure out the interface for the + * IP address of the local side of a point to point + * connection, we just don't add that entry in the + * table. (it seems to already be there anyway) + */ + if (rt->rt_ifp == 0) { + struct sockaddr *dst = &(rt->rt_dst); + syslog(LOG_DEBUG, + "rtchange: can't get interface for %s", + (*afswitch[dst->sa_family].af_format)(dst)); + return; + } + } } rt->rt_metric = metric; rt->rt_state |= RTS_CHANGED; diff --git a/usr.sbin/routed/tables.c b/usr.sbin/routed/tables.c index a05e023f3a..17a4fb7b96 100644 --- a/usr.sbin/routed/tables.c +++ b/usr.sbin/routed/tables.c @@ -183,8 +183,21 @@ rtadd(dst, gate, metric, state) rt->rt_flags = RTF_UP | flags; rt->rt_state = state | RTS_CHANGED; rt->rt_ifp = if_ifwithdstaddr(&rt->rt_dst); - if (rt->rt_ifp == 0) + if (rt->rt_ifp == 0) { rt->rt_ifp = if_ifwithnet(&rt->rt_router); + /* + * seems like we can't figure out the interface for the + * IP address of the local side of a point to point + * connection, we just don't add that entry in the + * table. (it seems to already be there anyway) + */ + if (rt->rt_ifp == 0) { + syslog(LOG_DEBUG, + "rtadd: can't get interface for %s", + (*afswitch[dst->sa_family].af_format)(dst)); + return; + } + } if ((state & RTS_INTERFACE) == 0) rt->rt_flags |= RTF_GATEWAY; rt->rt_metric = metric; @@ -257,8 +270,22 @@ rtchange(rt, gate, metric) if (add) { rt->rt_router = *gate; rt->rt_ifp = if_ifwithdstaddr(&rt->rt_router); - if (rt->rt_ifp == 0) + if (rt->rt_ifp == 0) { rt->rt_ifp = if_ifwithnet(&rt->rt_router); + /* + * seems like we can't figure out the interface for the + * IP address of the local side of a point to point + * connection, we just don't add that entry in the + * table. (it seems to already be there anyway) + */ + if (rt->rt_ifp == 0) { + struct sockaddr *dst = &(rt->rt_dst); + syslog(LOG_DEBUG, + "rtchange: can't get interface for %s", + (*afswitch[dst->sa_family].af_format)(dst)); + return; + } + } } rt->rt_metric = metric; rt->rt_state |= RTS_CHANGED;