]> git.proxmox.com Git - mirror_frr.git/blobdiff - ospfd/ospf_zebra.c
Merge pull request #5468 from qlyoung/bgpd-remove-bgp-attr-dup
[mirror_frr.git] / ospfd / ospf_zebra.c
index c178e367d390a032fcc37df14163950328d8ce69..68d9d3bf8319bd1553be65714d5a85f26706f1db 100644 (file)
@@ -55,9 +55,6 @@ DEFINE_MTYPE_STATIC(OSPFD, OSPF_EXTERNAL, "OSPF External route table")
 DEFINE_MTYPE_STATIC(OSPFD, OSPF_REDISTRIBUTE, "OSPF Redistriute")
 DEFINE_MTYPE_STATIC(OSPFD, OSPF_DIST_ARGS, "OSPF Distribute arguments")
 
-DEFINE_HOOK(ospf_if_update, (struct interface * ifp), (ifp))
-DEFINE_HOOK(ospf_if_delete, (struct interface * ifp), (ifp))
-
 /* Zebra structure to hold current status. */
 struct zclient *zclient = NULL;
 
@@ -97,167 +94,6 @@ static int ospf_router_id_update_zebra(ZAPI_CALLBACK_ARGS)
        return 0;
 }
 
-/* Inteface addition message from zebra. */
-static int ospf_interface_add(ZAPI_CALLBACK_ARGS)
-{
-       struct interface *ifp = NULL;
-       struct ospf *ospf = NULL;
-
-       ifp = zebra_interface_add_read(zclient->ibuf, vrf_id);
-       if (ifp == NULL)
-               return 0;
-
-       if (IS_DEBUG_OSPF(zebra, ZEBRA_INTERFACE))
-               zlog_debug(
-                       "Zebra: interface add %s vrf %s[%u] index %d flags %llx metric %d mtu %d speed %u",
-                       ifp->name, ospf_vrf_id_to_name(ifp->vrf_id),
-                       ifp->vrf_id, ifp->ifindex,
-                       (unsigned long long)ifp->flags, ifp->metric, ifp->mtu,
-                       ifp->speed);
-
-       assert(ifp->info);
-
-       if (IF_DEF_PARAMS(ifp)
-           && !OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp), type)) {
-               SET_IF_PARAM(IF_DEF_PARAMS(ifp), type);
-               IF_DEF_PARAMS(ifp)->type = ospf_default_iftype(ifp);
-       }
-
-       ospf = ospf_lookup_by_vrf_id(vrf_id);
-       if (!ospf)
-               return 0;
-
-       ospf_if_recalculate_output_cost(ifp);
-
-       ospf_if_update(ospf, ifp);
-
-       hook_call(ospf_if_update, ifp);
-
-       return 0;
-}
-
-static int ospf_interface_delete(ZAPI_CALLBACK_ARGS)
-{
-       struct interface *ifp;
-       struct stream *s;
-       struct route_node *rn;
-
-       s = zclient->ibuf;
-       /* zebra_interface_state_read() updates interface structure in iflist */
-       ifp = zebra_interface_state_read(s, vrf_id);
-
-       if (ifp == NULL)
-               return 0;
-
-       if (IS_DEBUG_OSPF(zebra, ZEBRA_INTERFACE))
-               zlog_debug(
-                       "Zebra: interface delete %s vrf %s[%u] index %d flags %llx metric %d mtu %d",
-                       ifp->name, ospf_vrf_id_to_name(ifp->vrf_id),
-                       ifp->vrf_id, ifp->ifindex,
-                       (unsigned long long)ifp->flags, ifp->metric, ifp->mtu);
-
-       hook_call(ospf_if_delete, ifp);
-
-       for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn))
-               if (rn->info)
-                       ospf_if_free((struct ospf_interface *)rn->info);
-
-       if_set_index(ifp, IFINDEX_INTERNAL);
-       return 0;
-}
-
-static struct interface *zebra_interface_if_lookup(struct stream *s,
-                                                  vrf_id_t vrf_id)
-{
-       char ifname_tmp[INTERFACE_NAMSIZ];
-
-       /* Read interface name. */
-       stream_get(ifname_tmp, s, INTERFACE_NAMSIZ);
-
-       /* And look it up. */
-       return if_lookup_by_name(ifname_tmp, vrf_id);
-}
-
-static int ospf_interface_state_up(ZAPI_CALLBACK_ARGS)
-{
-       struct interface *ifp;
-       struct ospf_interface *oi;
-       struct route_node *rn;
-
-       ifp = zebra_interface_if_lookup(zclient->ibuf, vrf_id);
-
-       if (ifp == NULL)
-               return 0;
-
-       /* Interface is already up. */
-       if (if_is_operative(ifp)) {
-               /* Temporarily keep ifp values. */
-               struct interface if_tmp;
-               memcpy(&if_tmp, ifp, sizeof(struct interface));
-
-               zebra_interface_if_set_value(zclient->ibuf, ifp);
-
-               if (IS_DEBUG_OSPF(zebra, ZEBRA_INTERFACE))
-                       zlog_debug(
-                               "Zebra: Interface[%s] state update speed %u -> %u, bw  %d -> %d",
-                               ifp->name, if_tmp.speed, ifp->speed,
-                               if_tmp.bandwidth, ifp->bandwidth);
-
-               ospf_if_recalculate_output_cost(ifp);
-
-               if (if_tmp.mtu != ifp->mtu) {
-                       if (IS_DEBUG_OSPF(zebra, ZEBRA_INTERFACE))
-                               zlog_debug(
-                                       "Zebra: Interface[%s] MTU change %u -> %u.",
-                                       ifp->name, if_tmp.mtu, ifp->mtu);
-
-                       /* Must reset the interface (simulate down/up) when MTU
-                        * changes. */
-                       ospf_if_reset(ifp);
-               }
-               return 0;
-       }
-
-       zebra_interface_if_set_value(zclient->ibuf, ifp);
-
-       if (IS_DEBUG_OSPF(zebra, ZEBRA_INTERFACE))
-               zlog_debug("Zebra: Interface[%s] state change to up.",
-                          ifp->name);
-
-       for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
-               if ((oi = rn->info) == NULL)
-                       continue;
-
-               ospf_if_up(oi);
-       }
-
-       return 0;
-}
-
-static int ospf_interface_state_down(ZAPI_CALLBACK_ARGS)
-{
-       struct interface *ifp;
-       struct ospf_interface *oi;
-       struct route_node *node;
-
-       ifp = zebra_interface_state_read(zclient->ibuf, vrf_id);
-
-       if (ifp == NULL)
-               return 0;
-
-       if (IS_DEBUG_OSPF(zebra, ZEBRA_INTERFACE))
-               zlog_debug("Zebra: Interface[%s] state change to down.",
-                          ifp->name);
-
-       for (node = route_top(IF_OIFS(ifp)); node; node = route_next(node)) {
-               if ((oi = node->info) == NULL)
-                       continue;
-               ospf_if_down(oi);
-       }
-
-       return 0;
-}
-
 static int ospf_interface_address_add(ZAPI_CALLBACK_ARGS)
 {
        struct connected *c;
@@ -283,7 +119,7 @@ static int ospf_interface_address_add(ZAPI_CALLBACK_ARGS)
 
        ospf_if_update(ospf, c->ifp);
 
-       hook_call(ospf_if_update, c->ifp);
+       ospf_if_interface(c->ifp);
 
        return 0;
 }
@@ -314,7 +150,7 @@ static int ospf_interface_address_delete(ZAPI_CALLBACK_ARGS)
 
        rn = route_node_lookup(IF_OIFS(ifp), &p);
        if (!rn) {
-               connected_free(c);
+               connected_free(&c);
                return 0;
        }
 
@@ -325,9 +161,9 @@ static int ospf_interface_address_delete(ZAPI_CALLBACK_ARGS)
        /* Call interface hook functions to clean up */
        ospf_if_free(oi);
 
-       hook_call(ospf_if_update, c->ifp);
+       ospf_if_interface(c->ifp);
 
-       connected_free(c);
+       connected_free(&c);
 
        return 0;
 }
@@ -744,10 +580,10 @@ int ospf_redistribute_unset(struct ospf *ospf, int type,
 int ospf_redistribute_default_set(struct ospf *ospf, int originate, int mtype,
                                  int mvalue)
 {
-       struct ospf_external *ext;
        struct prefix_ipv4 p;
        struct in_addr nexthop;
        int cur_originate = ospf->default_originate;
+       const char *type_str = NULL;
 
        nexthop.s_addr = 0;
        p.family = AF_INET;
@@ -756,41 +592,7 @@ int ospf_redistribute_default_set(struct ospf *ospf, int originate, int mtype,
 
        ospf->default_originate = originate;
 
-       ospf_external_add(ospf, DEFAULT_ROUTE, 0);
-
-       if (cur_originate == DEFAULT_ORIGINATE_NONE) {
-               /* First time configuration */
-               if (IS_DEBUG_OSPF(zebra, ZEBRA_REDISTRIBUTE))
-                       zlog_debug("Redistribute[DEFAULT]: Start Type[%d], Metric[%d]",
-                       metric_type(ospf, DEFAULT_ROUTE, 0),
-                       metric_value(ospf, DEFAULT_ROUTE, 0));
-
-               if (ospf->router_id.s_addr == 0)
-                       ospf->external_origin |= (1 << DEFAULT_ROUTE);
-               if ((originate == DEFAULT_ORIGINATE_ALWAYS)
-                         && (ospf->router_id.s_addr)) {
-
-                       /* always , so originate lsa even it doesn't
-                        * exist in RIB.
-                        */
-                       ospf_external_info_add(ospf, DEFAULT_ROUTE, 0,
-                                                p, 0, nexthop, 0);
-                       ospf_external_lsa_refresh_default(ospf);
-
-               } else if (originate == DEFAULT_ORIGINATE_ZEBRA) {
-                       /* Send msg to Zebra to validate default route
-                        * existance.
-                        */
-                       zclient_redistribute_default(
-                               ZEBRA_REDISTRIBUTE_DEFAULT_ADD, zclient, AFI_IP,
-                               ospf->vrf_id);
-               }
-
-               ospf_asbr_status_update(ospf, ++ospf->redistribute);
-               return CMD_SUCCESS;
-
-
-       } else if (originate == cur_originate) {
+       if (cur_originate == originate) {
                /* Refresh the lsa since metric might different */
                if (IS_DEBUG_OSPF(zebra, ZEBRA_REDISTRIBUTE))
                        zlog_debug(
@@ -800,67 +602,51 @@ int ospf_redistribute_default_set(struct ospf *ospf, int originate, int mtype,
                                metric_value(ospf, DEFAULT_ROUTE, 0));
 
                ospf_external_lsa_refresh_default(ospf);
-
-       } else {
-               /* "default-info originate always" configured now,
-                * where "default-info originate" configured previoulsly.
-                */
-               if (originate == DEFAULT_ORIGINATE_ALWAYS) {
-
-                       zclient_redistribute_default(
-                                       ZEBRA_REDISTRIBUTE_DEFAULT_DELETE,
-                                       zclient, AFI_IP, ospf->vrf_id);
-                       /* here , ex-info should be added since ex-info might
-                        * have not updated earlier if def route is not exist.
-                        * If ex-iinfo ex-info already exist , it will return
-                        * smoothly.
-                        */
-                       ospf_external_info_add(ospf, DEFAULT_ROUTE, 0,
-                                                p, 0, nexthop, 0);
-                       ospf_external_lsa_refresh_default(ospf);
-
-               } else {
-                       /* "default-info originate" configured now,where
-                        * "default-info originate always" configured
-                        * previoulsy.
-                        */
-
-                       ospf_external_lsa_flush(ospf, DEFAULT_ROUTE, &p, 0);
-
-                       ext = ospf_external_lookup(ospf, DEFAULT_ROUTE, 0);
-                       if (ext && EXTERNAL_INFO(ext))
-                               ospf_external_info_delete(ospf,
-                                                DEFAULT_ROUTE, 0, p);
-
-                       zclient_redistribute_default(
-                                       ZEBRA_REDISTRIBUTE_DEFAULT_ADD,
-                                       zclient, AFI_IP, ospf->vrf_id);
-               }
+               return CMD_SUCCESS;
        }
 
-       return CMD_SUCCESS;
-}
-int ospf_redistribute_default_unset(struct ospf *ospf)
-{
-       if (ospf->default_originate == DEFAULT_ORIGINATE_ZEBRA) {
-               if (!ospf_is_type_redistributed(ospf, DEFAULT_ROUTE, 0))
-                       return CMD_SUCCESS;
+       switch (cur_originate) {
+       case DEFAULT_ORIGINATE_NONE:
+               break;
+       case DEFAULT_ORIGINATE_ZEBRA:
                zclient_redistribute_default(ZEBRA_REDISTRIBUTE_DEFAULT_DELETE,
                                 zclient, AFI_IP, ospf->vrf_id);
+               ospf->redistribute--;
+               break;
+       case DEFAULT_ORIGINATE_ALWAYS:
+               ospf_external_info_delete(ospf, DEFAULT_ROUTE, 0, p);
+               ospf_external_del(ospf, DEFAULT_ROUTE, 0);
+               ospf->redistribute--;
+               break;
        }
 
-       ospf->default_originate = DEFAULT_ORIGINATE_NONE;
+       switch (originate) {
+       case DEFAULT_ORIGINATE_NONE:
+               type_str = "none";
+               break;
+       case DEFAULT_ORIGINATE_ZEBRA:
+               type_str = "normal";
+               ospf->redistribute++;
+               zclient_redistribute_default(ZEBRA_REDISTRIBUTE_DEFAULT_ADD,
+                                            zclient, AFI_IP, ospf->vrf_id);
+               break;
+       case DEFAULT_ORIGINATE_ALWAYS:
+               type_str = "always";
+               ospf->redistribute++;
+               ospf_external_add(ospf, DEFAULT_ROUTE, 0);
+               ospf_external_info_add(ospf, DEFAULT_ROUTE, 0, p, 0, nexthop,
+                                      0);
+               break;
+       }
 
        if (IS_DEBUG_OSPF(zebra, ZEBRA_REDISTRIBUTE))
-               zlog_debug("Redistribute[DEFAULT]: Stop");
-
-       // Pending: how does the external_info cleanup work in this case?
-
-       ospf_asbr_status_update(ospf, --ospf->redistribute);
-
-       /* clean up maxage default originate external lsa */
-       ospf_default_originate_lsa_update(ospf);
+               zlog_debug("Redistribute[DEFAULT]: %s Type[%d], Metric[%d]",
+               type_str,
+               metric_type(ospf, DEFAULT_ROUTE, 0),
+               metric_value(ospf, DEFAULT_ROUTE, 0));
 
+       ospf_external_lsa_refresh_default(ospf);
+       ospf_asbr_status_update(ospf, ospf->redistribute);
        return CMD_SUCCESS;
 }
 
@@ -943,7 +729,7 @@ int ospf_redistribute_check(struct ospf *ospf, struct external_info *ei,
        /* apply route-map if needed */
        red = ospf_redist_lookup(ospf, type, instance);
        if (red && ROUTEMAP_NAME(red)) {
-               int ret;
+               route_map_result_t ret;
 
                ret = route_map_apply(ROUTEMAP(red), (struct prefix *)p,
                                      RMAP_OSPF, ei);
@@ -1033,7 +819,8 @@ static int ospf_zebra_read_route(ZAPI_CALLBACK_ARGS)
                char buf_prefix[PREFIX_STRLEN];
                prefix2str(&api.prefix, buf_prefix, sizeof(buf_prefix));
 
-               zlog_debug("%s: from client %s: vrf_id %d, p %s", __func__,
+               zlog_debug("%s: cmd %s from client %s: vrf_id %d, p %s",
+                          __func__, zserv_command_string(cmd),
                           zebra_route_string(api.type), vrf_id, buf_prefix);
        }
 
@@ -1067,11 +854,7 @@ static int ospf_zebra_read_route(ZAPI_CALLBACK_ARGS)
                        /* Nothing has changed, so nothing to do; return */
                        return 0;
                }
-               if (ospf->router_id.s_addr == 0)
-                       /* Set flags to generate AS-external-LSA originate event
-                          for each redistributed protocols later. */
-                       ospf->external_origin |= (1 << rt_type);
-               else {
+               if (ospf->router_id.s_addr != 0) {
                        if (ei) {
                                if (is_prefix_default(&p))
                                        ospf_external_lsa_refresh_default(ospf);
@@ -1577,10 +1360,6 @@ void ospf_zebra_init(struct thread_master *master, unsigned short instance)
        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;
-       zclient->interface_delete = ospf_interface_delete;
-       zclient->interface_up = ospf_interface_state_up;
-       zclient->interface_down = ospf_interface_state_down;
        zclient->interface_address_add = ospf_interface_address_add;
        zclient->interface_address_delete = ospf_interface_address_delete;
        zclient->interface_link_params = ospf_interface_link_params;