]> git.proxmox.com Git - mirror_frr.git/blobdiff - ospfd/ospf_zebra.c
Merge branch 'master' into docs-user
[mirror_frr.git] / ospfd / ospf_zebra.c
index 16f87735beccda75d8c8dbebd425724686929300..58e8a921d51f8f8d46862214b68de065024881d6 100644 (file)
@@ -63,7 +63,6 @@ struct zclient *zclient = NULL;
 
 /* For registering threads. */
 extern struct thread_master *master;
-struct in_addr router_id_zebra;
 
 /* Router-id update message from zebra. */
 static int ospf_router_id_update_zebra(int command, struct zclient *zclient,
@@ -80,13 +79,12 @@ static int ospf_router_id_update_zebra(int command, struct zclient *zclient,
                           buf, ospf_vrf_id_to_name(vrf_id), vrf_id);
        }
 
-       router_id_zebra = router_id.u.prefix4;
-
        ospf = ospf_lookup_by_vrf_id(vrf_id);
 
-       if (ospf != NULL)
+       if (ospf != NULL) {
+               ospf->router_id_zebra = router_id.u.prefix4;
                ospf_router_id_update(ospf);
-       else {
+       else {
                if (IS_DEBUG_OSPF_EVENT) {
                        char buf[PREFIX2STR_BUFFER];
 
@@ -166,7 +164,7 @@ static int ospf_interface_delete(int command, struct zclient *zclient,
                if (rn->info)
                        ospf_if_free((struct ospf_interface *)rn->info);
 
-       ifp->ifindex = IFINDEX_DELETED;
+       if_set_index(ifp, IFINDEX_INTERNAL);
        return 0;
 }
 
@@ -179,8 +177,7 @@ static struct interface *zebra_interface_if_lookup(struct stream *s,
        stream_get(ifname_tmp, s, INTERFACE_NAMSIZ);
 
        /* And look it up. */
-       return if_lookup_by_name_len(
-               ifname_tmp, strnlen(ifname_tmp, INTERFACE_NAMSIZ), vrf_id);
+       return if_lookup_by_name(ifname_tmp, vrf_id);
 }
 
 static int ospf_interface_state_up(int command, struct zclient *zclient,
@@ -392,6 +389,7 @@ void ospf_zebra_add(struct ospf *ospf, struct prefix_ipv4 *p,
 
        memset(&api, 0, sizeof(api));
        api.vrf_id = ospf->vrf_id;
+       api.nh_vrf_id = ospf->vrf_id;
        api.type = ZEBRA_ROUTE_OSPF;
        api.instance = ospf->instance;
        api.safi = SAFI_UNICAST;
@@ -469,6 +467,7 @@ void ospf_zebra_delete(struct ospf *ospf, struct prefix_ipv4 *p,
 
        memset(&api, 0, sizeof(api));
        api.vrf_id = ospf->vrf_id;
+       api.nh_vrf_id = ospf->vrf_id;
        api.type = ZEBRA_ROUTE_OSPF;
        api.instance = ospf->instance;
        api.safi = SAFI_UNICAST;
@@ -490,6 +489,7 @@ void ospf_zebra_add_discard(struct ospf *ospf, struct prefix_ipv4 *p)
 
        memset(&api, 0, sizeof(api));
        api.vrf_id = ospf->vrf_id;
+       api.nh_vrf_id = ospf->vrf_id;
        api.type = ZEBRA_ROUTE_OSPF;
        api.instance = ospf->instance;
        api.safi = SAFI_UNICAST;
@@ -509,6 +509,7 @@ void ospf_zebra_delete_discard(struct ospf *ospf, struct prefix_ipv4 *p)
 
        memset(&api, 0, sizeof(api));
        api.vrf_id = ospf->vrf_id;
+       api.nh_vrf_id = ospf->vrf_id;
        api.type = ZEBRA_ROUTE_OSPF;
        api.instance = ospf->instance;
        api.safi = SAFI_UNICAST;
@@ -522,13 +523,14 @@ void ospf_zebra_delete_discard(struct ospf *ospf, struct prefix_ipv4 *p)
                           inet_ntoa(p->prefix), p->prefixlen);
 }
 
-struct ospf_external *ospf_external_lookup(u_char type, u_short instance)
+struct ospf_external *ospf_external_lookup(struct ospf *ospf, u_char type,
+                                          u_short instance)
 {
        struct list *ext_list;
        struct listnode *node;
        struct ospf_external *ext;
 
-       ext_list = om->external[type];
+       ext_list = ospf->external[type];
        if (!ext_list)
                return (NULL);
 
@@ -539,19 +541,20 @@ struct ospf_external *ospf_external_lookup(u_char type, u_short instance)
        return NULL;
 }
 
-struct ospf_external *ospf_external_add(u_char type, u_short instance)
+struct ospf_external *ospf_external_add(struct ospf *ospf, u_char type,
+                                       u_short instance)
 {
        struct list *ext_list;
        struct ospf_external *ext;
 
-       ext = ospf_external_lookup(type, instance);
+       ext = ospf_external_lookup(ospf, type, instance);
        if (ext)
                return ext;
 
-       if (!om->external[type])
-               om->external[type] = list_new();
+       if (!ospf->external[type])
+               ospf->external[type] = list_new();
 
-       ext_list = om->external[type];
+       ext_list = ospf->external[type];
        ext = (struct ospf_external *)XCALLOC(MTYPE_OSPF_EXTERNAL,
                                              sizeof(struct ospf_external));
        ext->instance = instance;
@@ -562,20 +565,21 @@ struct ospf_external *ospf_external_add(u_char type, u_short instance)
        return ext;
 }
 
-void ospf_external_del(u_char type, u_short instance)
+void ospf_external_del(struct ospf *ospf, u_char type, u_short instance)
 {
        struct ospf_external *ext;
 
-       ext = ospf_external_lookup(type, instance);
+       ext = ospf_external_lookup(ospf, type, instance);
 
        if (ext) {
                if (EXTERNAL_INFO(ext))
                        route_table_finish(EXTERNAL_INFO(ext));
 
-               listnode_delete(om->external[type], ext);
-               if (!om->external[type]->count) {
-                       list_delete_and_null(&om->external[type]);
-               }
+               listnode_delete(ospf->external[type], ext);
+
+               if (!ospf->external[type]->count)
+                       list_delete_and_null(&ospf->external[type]);
+
                XFREE(MTYPE_OSPF_EXTERNAL, ext);
        }
 }
@@ -687,7 +691,7 @@ int ospf_redistribute_set(struct ospf *ospf, int type, u_short instance,
        red->dmetric.type = mtype;
        red->dmetric.value = mvalue;
 
-       ospf_external_add(type, instance);
+       ospf_external_add(ospf, type, instance);
 
        zclient_redistribute(ZEBRA_REDISTRIBUTE_ADD, zclient, AFI_IP, type,
                             instance, ospf->vrf_id);
@@ -723,7 +727,7 @@ int ospf_redistribute_unset(struct ospf *ospf, int type, u_short instance)
        /* Remove the routes from OSPF table. */
        ospf_redistribute_withdraw(ospf, type, instance);
 
-       ospf_external_del(type, instance);
+       ospf_external_del(ospf, type, instance);
 
        ospf_asbr_status_update(ospf, --ospf->redistribute);
 
@@ -741,7 +745,7 @@ int ospf_redistribute_default_set(struct ospf *ospf, int originate, int mtype,
        red->dmetric.type = mtype;
        red->dmetric.value = mvalue;
 
-       ospf_external_add(DEFAULT_ROUTE, 0);
+       ospf_external_add(ospf, DEFAULT_ROUTE, 0);
 
        if (ospf_is_type_redistributed(ospf, DEFAULT_ROUTE, 0)) {
                /* if ospf->default_originate changes value, is calling
@@ -966,10 +970,11 @@ static int ospf_zebra_read_route(int command, struct zclient *zclient,
                 */
                for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
                        if (i != api.type)
-                               ospf_external_info_delete(i, api.instance, p);
+                               ospf_external_info_delete(ospf, i,
+                                                         api.instance, p);
 
-               ei = ospf_external_info_add(api.type, api.instance, p, ifindex,
-                                           nexthop, api.tag);
+               ei = ospf_external_info_add(ospf, api.type, api.instance, p,
+                                           ifindex, nexthop, api.tag);
                if (ei == NULL) {
                        /* Nothing has changed, so nothing to do; return */
                        return 0;
@@ -1007,7 +1012,7 @@ static int ospf_zebra_read_route(int command, struct zclient *zclient,
                }
        } else /* if (command == ZEBRA_REDISTRIBUTE_ROUTE_DEL) */
        {
-               ospf_external_info_delete(api.type, api.instance, p);
+               ospf_external_info_delete(ospf, api.type, api.instance, p);
                if (is_prefix_default(&p))
                        ospf_external_lsa_refresh_default(ospf);
                else
@@ -1090,7 +1095,7 @@ static int ospf_distribute_list_update_timer(struct thread *thread)
                struct listnode *node;
                struct ospf_external *ext;
 
-               ext_list = om->external[type];
+               ext_list = ospf->external[type];
                if (!ext_list)
                        continue;
 
@@ -1133,7 +1138,7 @@ void ospf_distribute_list_update(struct ospf *ospf, int type,
        args[1] = (void *)((ptrdiff_t) type);
 
        /* External info does not exist. */
-       ext = ospf_external_lookup(type, instance);
+       ext = ospf_external_lookup(ospf, type, instance);
        if (!ext || !(rt = EXTERNAL_INFO(ext))) {
                XFREE(MTYPE_OSPF_DIST_ARGS, args);
                return;
@@ -1435,12 +1440,14 @@ void ospf_zebra_vrf_register(struct ospf *ospf)
        if (!zclient || zclient->sock < 0 || !ospf)
                return;
 
-       if (ospf->vrf_id != VRF_DEFAULT && ospf->vrf_id != VRF_UNKNOWN) {
+       if (ospf->vrf_id != VRF_UNKNOWN) {
                if (IS_DEBUG_OSPF_EVENT)
                        zlog_debug("%s: Register VRF %s id %u",
                                   __PRETTY_FUNCTION__,
                                   ospf_vrf_id_to_name(ospf->vrf_id),
                                   ospf->vrf_id);
+               /* Deregister for router-id, interfaces,
+                * redistributed routes. */
                zclient_send_reg_requests(zclient, ospf->vrf_id);
        }
 }
@@ -1452,7 +1459,7 @@ void ospf_zebra_vrf_deregister(struct ospf *ospf)
 
        if (ospf->vrf_id != VRF_DEFAULT && ospf->vrf_id != VRF_UNKNOWN) {
                if (IS_DEBUG_OSPF_EVENT)
-                       zlog_debug("%s: De-Register VRF %s id %u",
+                       zlog_debug("%s: De-Register VRF %s id %u to Zebra.",
                                   __PRETTY_FUNCTION__,
                                   ospf_vrf_id_to_name(ospf->vrf_id),
                                   ospf->vrf_id);
@@ -1472,8 +1479,8 @@ static void ospf_zebra_connected(struct zclient *zclient)
 void ospf_zebra_init(struct thread_master *master, u_short instance)
 {
        /* Allocate zebra structure. */
-       zclient = zclient_new(master);
-       zclient_init(zclient, ZEBRA_ROUTE_OSPF, instance);
+       zclient = zclient_new_notify(master, &zclient_options_default);
+       zclient_init(zclient, ZEBRA_ROUTE_OSPF, instance, &ospfd_privs);
        zclient->zebra_connected = ospf_zebra_connected;
        zclient->router_id_update = ospf_router_id_update_zebra;
        zclient->interface_add = ospf_interface_add;