diff options
Diffstat (limited to 'lib/if.c')
-rw-r--r-- | lib/if.c | 94 |
1 files changed, 23 insertions, 71 deletions
@@ -117,21 +117,25 @@ 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) + assert (namelen <= INTERFACE_NAMSIZ); /* Need space for '\0' at end. */ + strncpy (ifp->name, name, namelen); + ifp->name[namelen] = '\0'; + 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; - + if (if_master.if_new_hook) (*if_master.if_new_hook) (ifp); @@ -146,7 +150,11 @@ if_delete_retain (struct interface *ifp) (*if_master.if_delete_hook) (ifp); /* Free connected address list */ - list_delete (ifp->connected); + if (ifp->connected) + { + list_delete (ifp->connected); + ifp->connected = NULL; + } } /* Delete and free interface structure. */ @@ -320,60 +328,6 @@ if_get_by_name_len(const char *name, size_t namelen) if_create(name, namelen); } -/* Does interface up ? */ -int -if_is_up (struct interface *ifp) -{ - return ifp->flags & IFF_UP; -} - -/* Is interface running? */ -int -if_is_running (struct interface *ifp) -{ - return ifp->flags & IFF_RUNNING; -} - -/* Is the interface operative, eg. either UP & RUNNING - or UP & !ZEBRA_INTERFACE_LINK_DETECTION */ -int -if_is_operative (struct interface *ifp) -{ - return ((ifp->flags & IFF_UP) && - (ifp->flags & IFF_RUNNING || !CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION))); -} - -/* Is this loopback interface ? */ -int -if_is_loopback (struct interface *ifp) -{ - /* XXX: Do this better, eg what if IFF_WHATEVER means X on platform M - * but Y on platform N? - */ - return (ifp->flags & (IFF_LOOPBACK|IFF_NOXMIT|IFF_VIRTUAL)); -} - -/* Does this interface support broadcast ? */ -int -if_is_broadcast (struct interface *ifp) -{ - return ifp->flags & IFF_BROADCAST; -} - -/* Does this interface support broadcast ? */ -int -if_is_pointopoint (struct interface *ifp) -{ - return ifp->flags & IFF_POINTOPOINT; -} - -/* Does this interface support multicast ? */ -int -if_is_multicast (struct interface *ifp) -{ - return ifp->flags & IFF_MULTICAST; -} - /* Printout flag information into log */ const char * if_flag_dump (unsigned long flag) @@ -422,7 +376,7 @@ if_flag_dump (unsigned long flag) /* For debugging */ static void -if_dump (struct interface *ifp) +if_dump (const struct interface *ifp) { struct listnode *node; struct connected *c; @@ -444,7 +398,7 @@ if_dump (struct interface *ifp) /* Interface printing for all interface. */ void -if_dump_all () +if_dump_all (void) { struct listnode *node; void *p; @@ -620,9 +574,7 @@ DEFUN (show_address, struct connected * connected_new (void) { - struct connected *new = XMALLOC (MTYPE_CONNECTED, sizeof (struct connected)); - memset (new, 0, sizeof (struct connected)); - return new; + return XCALLOC (MTYPE_CONNECTED, sizeof (struct connected)); } /* Free connected structure. */ |