]> git.proxmox.com Git - mirror_frr.git/blobdiff - bgpd/bgp_zebra.c
Merge pull request #5172 from donaldsharp/sa_clean_and_clean
[mirror_frr.git] / bgpd / bgp_zebra.c
index 5d1d430e9d8b7efc9474f0c5fadf9475bc4d4451..7923f076c11906fa689192bf98bf424cd30e0c11 100644 (file)
@@ -202,75 +202,36 @@ static void bgp_nbr_connected_delete(struct bgp *bgp, struct nbr_connected *ifc,
        }
 }
 
-/* Inteface addition message from zebra. */
-static int bgp_interface_add(ZAPI_CALLBACK_ARGS)
+static int bgp_ifp_destroy(struct interface *ifp)
 {
-       struct interface *ifp;
        struct bgp *bgp;
 
-       ifp = zebra_interface_add_read(zclient->ibuf, vrf_id);
-       if (!ifp) // unexpected
-               return 0;
-
-       if (BGP_DEBUG(zebra, ZEBRA) && ifp)
-               zlog_debug("Rx Intf add VRF %u IF %s", vrf_id, ifp->name);
-
-       bgp = bgp_lookup_by_vrf_id(vrf_id);
-       if (!bgp)
-               return 0;
-
-       bgp_mac_add_mac_entry(ifp);
-
-       bgp_update_interface_nbrs(bgp, ifp, ifp);
-       return 0;
-}
-
-static int bgp_interface_delete(ZAPI_CALLBACK_ARGS)
-{
-       struct stream *s;
-       struct interface *ifp;
-       struct bgp *bgp;
-
-       bgp = bgp_lookup_by_vrf_id(vrf_id);
-
-       s = zclient->ibuf;
-       ifp = zebra_interface_state_read(s, vrf_id);
-       if (!ifp) /* This may happen if we've just unregistered for a VRF. */
-               return 0;
+       bgp = bgp_lookup_by_vrf_id(ifp->vrf_id);
 
        if (BGP_DEBUG(zebra, ZEBRA))
-               zlog_debug("Rx Intf del VRF %u IF %s", vrf_id, ifp->name);
+               zlog_debug("Rx Intf del VRF %u IF %s", ifp->vrf_id, ifp->name);
 
        if (bgp)
                bgp_update_interface_nbrs(bgp, ifp, NULL);
 
        bgp_mac_del_mac_entry(ifp);
 
-       if_set_index(ifp, IFINDEX_INTERNAL);
        return 0;
 }
 
-static int bgp_interface_up(ZAPI_CALLBACK_ARGS)
+static int bgp_ifp_up(struct interface *ifp)
 {
-       struct stream *s;
-       struct interface *ifp;
        struct connected *c;
        struct nbr_connected *nc;
        struct listnode *node, *nnode;
        struct bgp *bgp;
 
-       bgp = bgp_lookup_by_vrf_id(vrf_id);
-
-       s = zclient->ibuf;
-       ifp = zebra_interface_state_read(s, vrf_id);
-
-       if (!ifp)
-               return 0;
+       bgp = bgp_lookup_by_vrf_id(ifp->vrf_id);
 
        bgp_mac_add_mac_entry(ifp);
 
        if (BGP_DEBUG(zebra, ZEBRA))
-               zlog_debug("Rx Intf up VRF %u IF %s", vrf_id, ifp->name);
+               zlog_debug("Rx Intf up VRF %u IF %s", ifp->vrf_id, ifp->name);
 
        if (!bgp)
                return 0;
@@ -284,27 +245,20 @@ static int bgp_interface_up(ZAPI_CALLBACK_ARGS)
        return 0;
 }
 
-static int bgp_interface_down(ZAPI_CALLBACK_ARGS)
+static int bgp_ifp_down(struct interface *ifp)
 {
-       struct stream *s;
-       struct interface *ifp;
        struct connected *c;
        struct nbr_connected *nc;
        struct listnode *node, *nnode;
        struct bgp *bgp;
        struct peer *peer;
 
-       bgp = bgp_lookup_by_vrf_id(vrf_id);
-
-       s = zclient->ibuf;
-       ifp = zebra_interface_state_read(s, vrf_id);
-       if (!ifp)
-               return 0;
+       bgp = bgp_lookup_by_vrf_id(ifp->vrf_id);
 
        bgp_mac_del_mac_entry(ifp);
 
        if (BGP_DEBUG(zebra, ZEBRA))
-               zlog_debug("Rx Intf down VRF %u IF %s", vrf_id, ifp->name);
+               zlog_debug("Rx Intf down VRF %u IF %s", ifp->vrf_id, ifp->name);
 
        if (!bgp)
                return 0;
@@ -503,7 +457,7 @@ static int bgp_interface_vrf_update(ZAPI_CALLBACK_ARGS)
                }
        }
 
-       if_update_to_new_vrf(ifp, vrf_lookup_by_id(new_vrf_id));
+       if_update_to_new_vrf(ifp, new_vrf_id);
 
        bgp = bgp_lookup_by_vrf_id(new_vrf_id);
        if (!bgp)
@@ -787,7 +741,7 @@ bool bgp_zebra_nexthop_set(union sockunion *local, union sockunion *remote,
                nexthop->v4 = local->sin.sin_addr;
                if (peer->update_if)
                        ifp = if_lookup_by_name(peer->update_if,
-                                               vrf_lookup_by_id(peer->bgp->vrf_id));
+                                               peer->bgp->vrf_id);
                else
                        ifp = if_lookup_by_ipv4_exact(&local->sin.sin_addr,
                                                      peer->bgp->vrf_id);
@@ -799,11 +753,10 @@ bool bgp_zebra_nexthop_set(union sockunion *local, union sockunion *remote,
                                ifp = if_lookup_by_name(peer->conf_if
                                                                ? peer->conf_if
                                                                : peer->ifname,
-                                                       vrf_lookup_by_id(
-                                                                peer->bgp->vrf_id));
+                                                       peer->bgp->vrf_id);
                } else if (peer->update_if)
                        ifp = if_lookup_by_name(peer->update_if,
-                                       vrf_lookup_by_id(peer->bgp->vrf_id));
+                                               peer->bgp->vrf_id);
                else
                        ifp = if_lookup_by_ipv6_exact(&local->sin6.sin6_addr,
                                                      local->sin6.sin6_scope_id,
@@ -1275,6 +1228,11 @@ void bgp_zebra_announce(struct bgp_node *rn, struct prefix *p,
 
                SET_FLAG(api.flags, ZEBRA_FLAG_ALLOW_RECURSION);
 
+       if (info->attr->rmap_table_id) {
+               SET_FLAG(api.message, ZAPI_MESSAGE_TABLEID);
+               api.tableid = info->attr->rmap_table_id;
+       }
+
        /* Metric is currently based on the best-path only */
        metric = info->attr->med;
        for (mpinfo = info; mpinfo; mpinfo = bgp_path_info_mpath_next(mpinfo)) {
@@ -1541,6 +1499,11 @@ void bgp_zebra_withdraw(struct prefix *p, struct bgp_path_info *info,
        api.safi = safi;
        api.prefix = *p;
 
+       if (info->attr->rmap_table_id) {
+               SET_FLAG(api.message, ZAPI_MESSAGE_TABLEID);
+               api.tableid = info->attr->rmap_table_id;
+       }
+
        /* If the route's source is EVPN, flag as such. */
        if (is_route_parent_evpn(info))
                SET_FLAG(api.flags, ZEBRA_FLAG_EVPN_ROUTE);
@@ -2437,6 +2400,7 @@ static void bgp_encode_pbr_iptable_match(struct stream *s,
        stream_putw(s, pbm->tcp_mask_flags);
        stream_putc(s, pbm->dscp_value);
        stream_putc(s, pbm->fragment);
+       stream_putc(s, pbm->protocol);
 }
 
 /* BGP has established connection with Zebra. */
@@ -2721,17 +2685,35 @@ stream_failure:         /* for STREAM_GETX */
 
 extern struct zebra_privs_t bgpd_privs;
 
+static int bgp_ifp_create(struct interface *ifp)
+{
+       struct bgp *bgp;
+
+       if (BGP_DEBUG(zebra, ZEBRA))
+               zlog_debug("Rx Intf add VRF %u IF %s", ifp->vrf_id, ifp->name);
+
+       bgp = bgp_lookup_by_vrf_id(ifp->vrf_id);
+       if (!bgp)
+               return 0;
+
+       bgp_mac_add_mac_entry(ifp);
+
+       bgp_update_interface_nbrs(bgp, ifp, ifp);
+       return 0;
+}
+
 void bgp_zebra_init(struct thread_master *master, unsigned short instance)
 {
        zclient_num_connects = 0;
 
+       if_zapi_callbacks(bgp_ifp_create, bgp_ifp_up,
+                         bgp_ifp_down, bgp_ifp_destroy);
+
        /* Set default values. */
        zclient = zclient_new(master, &zclient_options_default);
        zclient_init(zclient, ZEBRA_ROUTE_BGP, 0, &bgpd_privs);
        zclient->zebra_connected = bgp_zebra_connected;
        zclient->router_id_update = bgp_router_id_update;
-       zclient->interface_add = bgp_interface_add;
-       zclient->interface_delete = bgp_interface_delete;
        zclient->interface_address_add = bgp_interface_address_add;
        zclient->interface_address_delete = bgp_interface_address_delete;
        zclient->interface_nbr_address_add = bgp_interface_nbr_address_add;
@@ -2740,8 +2722,6 @@ void bgp_zebra_init(struct thread_master *master, unsigned short instance)
        zclient->interface_vrf_update = bgp_interface_vrf_update;
        zclient->redistribute_route_add = zebra_read_route;
        zclient->redistribute_route_del = zebra_read_route;
-       zclient->interface_up = bgp_interface_up;
-       zclient->interface_down = bgp_interface_down;
        zclient->nexthop_update = bgp_read_nexthop_update;
        zclient->import_check_update = bgp_read_import_check_update;
        zclient->fec_update = bgp_read_fec_update;
@@ -2884,8 +2864,7 @@ static void bgp_encode_pbr_interface_list(struct bgp *bgp, struct stream *s)
        head = &(bgp_pbr_cfg->ifaces_by_name_ipv4);
 
        RB_FOREACH (pbr_if, bgp_pbr_interface_head, head) {
-               ifp = if_lookup_by_name(pbr_if->name,
-                                       vrf_lookup_by_id(bgp->vrf_id));
+               ifp = if_lookup_by_name(pbr_if->name, bgp->vrf_id);
                if (ifp)
                        stream_putl(s, ifp->ifindex);
        }
@@ -2903,8 +2882,7 @@ static int bgp_pbr_get_ifnumber(struct bgp *bgp)
        head = &(bgp_pbr_cfg->ifaces_by_name_ipv4);
 
        RB_FOREACH (pbr_if, bgp_pbr_interface_head, head) {
-               if (if_lookup_by_name(pbr_if->name,
-                                     vrf_lookup_by_id(bgp->vrf_id)))
+               if (if_lookup_by_name(pbr_if->name, bgp->vrf_id))
                        cnt++;
        }
        return cnt;