]> git.proxmox.com Git - mirror_frr.git/commitdiff
bgpd, lib, pimd: Abstract commands for nexthop tracking
authorDonald Sharp <sharpd@cumulusnetworks.com>
Mon, 22 Jan 2018 23:36:03 +0000 (18:36 -0500)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Tue, 23 Jan 2018 00:45:31 +0000 (19:45 -0500)
Abstract the code that sends the zapi message into zebra
for the turn on/off of nexthop tracking for a prefix.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
bgpd/bgp_nht.c
lib/zclient.c
lib/zclient.h
pimd/pim_nht.c

index 247884d2948b15fe7457d7efe42161b35d9ba5ba..a963838f5f27941e82e23ec761a930202f1a6608 100644 (file)
@@ -572,12 +572,11 @@ static int make_prefix(int afi, struct bgp_info *ri, struct prefix *p)
  */
 static void sendmsg_zebra_rnh(struct bgp_nexthop_cache *bnc, int command)
 {
-       struct stream *s;
        struct prefix *p;
+       bool exact_match = false;
        int ret;
 
-       /* Check socket. */
-       if (!zclient || zclient->sock < 0)
+       if (!zclient)
                return;
 
        /* Don't try to register if Zebra doesn't know of this instance. */
@@ -585,32 +584,14 @@ static void sendmsg_zebra_rnh(struct bgp_nexthop_cache *bnc, int command)
                return;
 
        p = &(bnc->node->p);
-       s = zclient->obuf;
-       stream_reset(s);
-       zclient_create_header(s, command, bnc->bgp->vrf_id);
        if ((command == ZEBRA_NEXTHOP_REGISTER ||
             command == ZEBRA_IMPORT_ROUTE_REGISTER) &&
            (CHECK_FLAG(bnc->flags, BGP_NEXTHOP_CONNECTED)
             || CHECK_FLAG(bnc->flags, BGP_STATIC_ROUTE_EXACT_MATCH)))
-               stream_putc(s, 1);
-       else
-               stream_putc(s, 0);
-
-       stream_putw(s, PREFIX_FAMILY(p));
-       stream_putc(s, p->prefixlen);
-       switch (PREFIX_FAMILY(p)) {
-       case AF_INET:
-               stream_put_in_addr(s, &p->u.prefix4);
-               break;
-       case AF_INET6:
-               stream_put(s, &(p->u.prefix6), 16);
-               break;
-       default:
-               break;
-       }
-       stream_putw_at(s, 0, stream_get_endp(s));
+               exact_match = true;
 
-       ret = zclient_send_message(zclient);
+       ret = zclient_send_rnh(zclient, command, p,
+                              exact_match, bnc->bgp->vrf_id);
        /* TBD: handle the failure */
        if (ret < 0)
                zlog_warn("sendmsg_nexthop: zclient_send_message() failed");
index 9045b5b6ce827d8c5e3fd98cff5a1cdd45489474..9d863a3b26fdc2748564dc5d1fa411a82f5a1ebd 100644 (file)
@@ -614,6 +614,33 @@ static int zclient_connect(struct thread *t)
        return zclient_start(zclient);
 }
 
+int zclient_send_rnh(struct zclient *zclient, int command, struct prefix *p,
+                    bool exact_match, vrf_id_t vrf_id)
+{
+       struct stream *s;
+
+       s = zclient->obuf;
+       stream_reset(s);
+       zclient_create_header(s, command, vrf_id);
+       stream_putc(s, (exact_match) ? 1 : 0);
+
+       stream_putw(s, PREFIX_FAMILY(p));
+       stream_putc(s, p->prefixlen);
+       switch (PREFIX_FAMILY(p)) {
+       case AF_INET:
+               stream_put_in_addr(s, &p->u.prefix4);
+               break;
+       case AF_INET6:
+               stream_put(s, &(p->u.prefix6), 16);
+               break;
+       default:
+               break;
+       }
+       stream_putw_at(s, 0, stream_get_endp(s));
+
+       return zclient_send_message(zclient);
+}
+
 /*
  * "xdr_encode"-like interface that allows daemon (client) to send
  * a message to zebra server for a route that needs to be
index 00ad692718fb9f896828a8783e0b88823987cce3..847c2904d054c952c0ddcf9cd71daace67808015 100644 (file)
@@ -478,6 +478,9 @@ extern int zapi_ipv4_route_ipv6_nexthop(u_char, struct zclient *,
                                        struct zapi_ipv6 *)
        __attribute__((deprecated));
 extern int zclient_route_send(u_char, struct zclient *, struct zapi_route *);
+extern int zclient_send_rnh(struct zclient *zclient, int command,
+                           struct prefix *p, bool exact_match,
+                           vrf_id_t vrf_id);
 extern int zapi_route_encode(u_char, struct stream *, struct zapi_route *);
 extern int zapi_route_decode(struct stream *, struct zapi_route *);
 bool zapi_route_notify_decode(struct stream *s, struct prefix *p,
index 089639c77e725126e25c7cfa8df24627a37ba5c9..ccef796724a3a159088cc02cdb5926a1f327bf46 100644 (file)
 void pim_sendmsg_zebra_rnh(struct pim_instance *pim, struct zclient *zclient,
                           struct pim_nexthop_cache *pnc, int command)
 {
-       struct stream *s;
        struct prefix *p;
        int ret;
 
-       /* Check socket. */
-       if (!zclient || zclient->sock < 0)
-               return;
-
        p = &(pnc->rpf.rpf_addr);
-       s = zclient->obuf;
-       stream_reset(s);
-       zclient_create_header(s, command, pim->vrf_id);
-       /* get update for all routes for a prefix */
-       stream_putc(s, 0);
-
-       stream_putw(s, PREFIX_FAMILY(p));
-       stream_putc(s, p->prefixlen);
-       switch (PREFIX_FAMILY(p)) {
-       case AF_INET:
-               stream_put_in_addr(s, &p->u.prefix4);
-               break;
-       case AF_INET6:
-               stream_put(s, &(p->u.prefix6), 16);
-               break;
-       default:
-               break;
-       }
-       stream_putw_at(s, 0, stream_get_endp(s));
-
-       ret = zclient_send_message(zclient);
+       ret = zclient_send_rnh(zclient, command, p, false, pim->vrf_id);
        if (ret < 0)
                zlog_warn("sendmsg_nexthop: zclient_send_message() failed");
 
-
        if (PIM_DEBUG_PIM_NHT) {
                char buf[PREFIX2STR_BUFFER];
                prefix2str(p, buf, sizeof(buf));