diff options
Diffstat (limited to 'lib/if.c')
| -rw-r--r-- | lib/if.c | 65 |
1 files changed, 44 insertions, 21 deletions
@@ -141,25 +141,16 @@ static int if_cmp_index_func(const struct interface *ifp1, } /* Create new interface structure. */ -static struct interface *if_create_backend(const char *name, ifindex_t ifindex, - vrf_id_t vrf_id) +static struct interface *if_new(vrf_id_t vrf_id) { - struct vrf *vrf = vrf_get(vrf_id, NULL); struct interface *ifp; ifp = XCALLOC(MTYPE_IF, sizeof(struct interface)); - ifp->vrf_id = vrf_id; - if (name) { - strlcpy(ifp->name, name, sizeof(ifp->name)); - IFNAME_RB_INSERT(vrf, ifp); - } else - ifp->name[0] = '\0'; + ifp->ifindex = IFINDEX_INTERNAL; + ifp->name[0] = '\0'; - if (ifindex != IFINDEX_INTERNAL) - if_set_index(ifp, ifindex); - else - ifp->ifindex = ifindex; /* doesn't add it to the list */ + ifp->vrf_id = vrf_id; ifp->connected = list_new(); ifp->connected->del = (void (*)(void *))connected_free; @@ -171,7 +162,6 @@ static struct interface *if_create_backend(const char *name, ifindex_t ifindex, SET_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION); QOBJ_REG(ifp, interface); - hook_call(if_add, ifp); return ifp; } @@ -203,14 +193,28 @@ void if_down_via_zapi(struct interface *ifp) (*ifp_master.down_hook)(ifp); } -struct interface *if_create(const char *name, vrf_id_t vrf_id) +struct interface *if_create_name(const char *name, vrf_id_t vrf_id) { - return if_create_backend(name, IFINDEX_INTERNAL, vrf_id); + struct interface *ifp; + + ifp = if_new(vrf_id); + + if_set_name(ifp, name); + + hook_call(if_add, ifp); + return ifp; } struct interface *if_create_ifindex(ifindex_t ifindex, vrf_id_t vrf_id) { - return if_create_backend(NULL, ifindex, vrf_id); + struct interface *ifp; + + ifp = if_new(vrf_id); + + if_set_index(ifp, ifindex); + + hook_call(if_add, ifp); + return ifp; } /* Create new interface structure. */ @@ -516,7 +520,7 @@ struct interface *if_get_by_name(const char *name, vrf_id_t vrf_id) ifp = if_lookup_by_name(name, vrf_id); if (ifp) return ifp; - return if_create(name, vrf_id); + return if_create_name(name, vrf_id); case VRF_BACKEND_VRF_LITE: ifp = if_lookup_by_name_all_vrf(name); if (ifp) { @@ -528,7 +532,7 @@ struct interface *if_get_by_name(const char *name, vrf_id_t vrf_id) if_update_to_new_vrf(ifp, vrf_id); return ifp; } - return if_create(name, vrf_id); + return if_create_name(name, vrf_id); } return NULL; @@ -566,14 +570,14 @@ void if_set_index(struct interface *ifp, ifindex_t ifindex) { struct vrf *vrf; - vrf = vrf_lookup_by_id(ifp->vrf_id); + vrf = vrf_get(ifp->vrf_id, NULL); assert(vrf); if (ifp->ifindex == ifindex) return; if (ifp->ifindex != IFINDEX_INTERNAL) - IFINDEX_RB_REMOVE(vrf, ifp) + IFINDEX_RB_REMOVE(vrf, ifp); ifp->ifindex = ifindex; @@ -581,6 +585,25 @@ void if_set_index(struct interface *ifp, ifindex_t ifindex) IFINDEX_RB_INSERT(vrf, ifp) } +void if_set_name(struct interface *ifp, const char *name) +{ + struct vrf *vrf; + + vrf = vrf_get(ifp->vrf_id, NULL); + assert(vrf); + + if (if_cmp_name_func(ifp->name, name) == 0) + return; + + if (ifp->name[0] != '\0') + IFNAME_RB_REMOVE(vrf, ifp); + + strlcpy(ifp->name, name, sizeof(ifp->name)); + + if (ifp->name[0] != '\0') + IFNAME_RB_INSERT(vrf, ifp); +} + /* Does interface up ? */ int if_is_up(const struct interface *ifp) { |
