summaryrefslogtreecommitdiffstats
path: root/lib/if.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/if.c')
-rw-r--r--lib/if.c33
1 files changed, 18 insertions, 15 deletions
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;
}