From 219940a5f510270113c7eca0c7b25f6938b7565a Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Fri, 12 Dec 2008 06:45:00 -0800 Subject: Handle interfaces coming back from dead Need to handle the case where interface comes back after being deleted. After deletion state is retained but ifindex is set to IFINDEX_INTERNAL. When new interface arrives with same name, then update index --- lib/if.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) (limited to 'lib/if.c') diff --git a/lib/if.c b/lib/if.c index d270c21f..7c4fb1a4 100644 --- a/lib/if.c +++ b/lib/if.c @@ -117,23 +117,26 @@ if_create (const char *name, int namelen) { struct interface *ifp; - ifp = XCALLOC (MTYPE_IF, sizeof (struct interface)); - ifp->ifindex = IFINDEX_INTERNAL; + ifp = if_lookup_by_name(name); + if (ifp) { + if (ifp->ifindex != IFINDEX_INTERNAL) + zlog_err("if_create(%s): corruption detected -- interface with this " + "name exists already!", ifp->name); + } else { + ifp = XCALLOC (MTYPE_IF, sizeof (struct interface)); + ifp->ifindex = IFINDEX_INTERNAL; - assert (name); - assert (namelen <= INTERFACE_NAMSIZ); /* Need space for '\0' at end. */ - strncpy (ifp->name, name, namelen); - ifp->name[namelen] = '\0'; - if (if_lookup_by_name(ifp->name) == NULL) - listnode_add_sort (iflist, ifp); - else - zlog_err("if_create(%s): corruption detected -- interface with this " - "name exists already!", ifp->name); - ifp->connected = list_new (); - ifp->connected->del = (void (*) (void *)) connected_free; + assert (namelen <= INTERFACE_NAMSIZ); /* Need space for '\0' at end. */ + strncpy (ifp->name, name, namelen); + ifp->name[namelen] = '\0'; - if (if_master.if_new_hook) - (*if_master.if_new_hook) (ifp); + listnode_add_sort (iflist, ifp); + ifp->connected = list_new (); + ifp->connected->del = (void (*) (void *)) connected_free; + + if (if_master.if_new_hook) + (*if_master.if_new_hook) (ifp); + } return ifp; } -- cgit v1.2.3