]> 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 c0f2dfca176c709cb020e70e4957459719c7d679..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;
@@ -1274,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)) {
@@ -1540,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);
@@ -2436,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. */
@@ -2720,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;
@@ -2739,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;