From 133be3055da09253fc544763dcb744957f1f6319 Mon Sep 17 00:00:00 2001 From: Sebastien Roy Date: Fri, 12 Dec 2008 12:42:26 -0500 Subject: [PATCH] 6774464 assertion failure in net_hook_register() when running zone tests 6784207 netstack reference leak in ipnet_if_init() --- usr/src/uts/common/inet/ipnet/ipnet.c | 58 ++++++++++++++++++++++++----------- 1 file changed, 40 insertions(+), 18 deletions(-) diff --git a/usr/src/uts/common/inet/ipnet/ipnet.c b/usr/src/uts/common/inet/ipnet/ipnet.c index 78806d3ddb..577205f25a 100644 --- a/usr/src/uts/common/inet/ipnet/ipnet.c +++ b/usr/src/uts/common/inet/ipnet/ipnet.c @@ -213,9 +213,10 @@ ipnet_if_init(void) netstack_next_init(&nh); while ((ns = netstack_next(&nh)) != NULL) { ips = ns->netstack_ipnet; - if ((ret = ipnet_populate_if(ips->ips_ndv4, ips, B_FALSE)) != 0) - break; - if ((ret = ipnet_populate_if(ips->ips_ndv6, ips, B_TRUE)) != 0) + if ((ret = ipnet_populate_if(ips->ips_ndv4, ips, B_FALSE)) == 0) + ret = ipnet_populate_if(ips->ips_ndv6, ips, B_TRUE); + netstack_rele(ns); + if (ret != 0) break; } netstack_next_fini(&nh); @@ -284,29 +285,38 @@ static void ipnet_register_netihook(ipnet_stack_t *ips) { int ret; - netstackid_t stackid = ips->ips_netstack->netstack_stackid; + zoneid_t zoneid; + netid_t netid; HOOK_INIT(ips->ips_nicevents, ipnet_nicevent_cb, "ipnet_nicevents", ips); /* - * The ipnet device depends on ip and is registered in the netstack - * framework after ip so the call to net_lookup_impl() cannot fail. + * It is possible for an exclusive stack to be in the process of + * shutting down here, and the netid and protocol lookups could fail + * in that case. */ - ips->ips_ndv4 = net_protocol_lookup(stackid, NHF_INET); - ips->ips_ndv6 = net_protocol_lookup(stackid, NHF_INET6); + zoneid = netstackid_to_zoneid(ips->ips_netstack->netstack_stackid); + if ((netid = net_zoneidtonetid(zoneid)) == -1) + return; - ret = net_hook_register(ips->ips_ndv4, NH_NIC_EVENTS, - ips->ips_nicevents); - if (ret != 0) { - cmn_err(CE_WARN, "ipnet_register_netihook: net_register_hook() " - "failed for v4 stack instance %d: %d", stackid, ret); + if ((ips->ips_ndv4 = net_protocol_lookup(netid, NHF_INET)) != NULL) { + if ((ret = net_hook_register(ips->ips_ndv4, NH_NIC_EVENTS, + ips->ips_nicevents)) != 0) { + VERIFY(net_protocol_release(ips->ips_ndv4) == 0); + ips->ips_ndv4 = NULL; + cmn_err(CE_WARN, "unable to register IPv4 netinfo hooks" + " in zone %d: %d", zoneid, ret); + } } - ret = net_hook_register(ips->ips_ndv6, NH_NIC_EVENTS, - ips->ips_nicevents); - if (ret != 0) { - cmn_err(CE_WARN, "ipnet_register_netihook: net_register_hook() " - "failed for v6 stack instance %d: %d", stackid, ret); + if ((ips->ips_ndv6 = net_protocol_lookup(netid, NHF_INET6)) != NULL) { + if ((ret = net_hook_register(ips->ips_ndv6, NH_NIC_EVENTS, + ips->ips_nicevents)) != 0) { + VERIFY(net_protocol_release(ips->ips_ndv6) == 0); + ips->ips_ndv6 = NULL; + cmn_err(CE_WARN, "unable to register IPv6 netinfo hooks" + " in zone %d: %d", zoneid, ret); + } } } @@ -328,6 +338,18 @@ ipnet_populate_if(net_handle_t nd, ipnet_stack_t *ips, boolean_t isv6) int ret = 0; /* + * If ipnet_register_netihook() was unable to initialize this + * stack's net_handle_t, then we cannot populate any interface + * information. This usually happens when we attempted to + * grab a net_handle_t as a stack was shutting down. We don't + * want to fail the entire _init() operation because of a + * stack shutdown (other stacks will continue to work just + * fine), so we silently return success here. + */ + if (nd == NULL) + return (0); + + /* * Make sure we're not processing NIC events during the * population of our interfaces and address lists. */ -- 2.11.4.GIT