Module Name: src Committed By: dyoung Date: Wed Jun 2 23:41:14 UTC 2010
Modified Files: src/sys/net: if.c Log Message: Prevent if_detach() from crashing while it walks the routing table to find and unlink routes that reference the detached ifnet: make if_rt_walktree() return ERESTART whenever it has deleted a route. Whenever rt_walktree() returns ERESTART, if_detach() restarts it. I believe that this fix resembles one by Jonathan Kollasch or by someone else, which has languished in a PR for too long. Sorry! Tested by me and by Jeff Rizzo. XXX It's supposed to be safe for rn_walktree() to apply to the routing XXX table a routine that may delete routes. Why isn't it safe in XXX practice? To generate a diff of this commit: cvs rdiff -u -r1.242 -r1.243 src/sys/net/if.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/net/if.c diff -u src/sys/net/if.c:1.242 src/sys/net/if.c:1.243 --- src/sys/net/if.c:1.242 Thu Jan 28 14:12:11 2010 +++ src/sys/net/if.c Wed Jun 2 23:41:14 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: if.c,v 1.242 2010/01/28 14:12:11 mbalmer Exp $ */ +/* $NetBSD: if.c,v 1.243 2010/06/02 23:41:14 dyoung Exp $ */ /*- * Copyright (c) 1999, 2000, 2001, 2008 The NetBSD Foundation, Inc. @@ -90,7 +90,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.242 2010/01/28 14:12:11 mbalmer Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.243 2010/06/02 23:41:14 dyoung Exp $"); #include "opt_inet.h" @@ -792,8 +792,10 @@ if_free_sadl(ifp); /* Walk the routing table looking for stragglers. */ - for (i = 0; i <= AF_MAX; i++) - (void)rt_walktree(i, if_rt_walktree, ifp); + for (i = 0; i <= AF_MAX; i++) { + while (rt_walktree(i, if_rt_walktree, ifp) == ERESTART) + ; + } DOMAIN_FOREACH(dp) { if (dp->dom_ifdetach != NULL && ifp->if_afdata[dp->dom_family]) @@ -904,7 +906,7 @@ if (error != 0) printf("%s: warning: unable to delete rtentry @ %p, " "error = %d\n", ifp->if_xname, rt, error); - return 0; + return ERESTART; } /*