]> git.puffer.fish Git - mirror/frr.git/commitdiff
lib, zebra: Add ability to notify to Routing Protocols Success/Failure
authorDonald Sharp <sharpd@cumulusnetworks.com>
Thu, 9 Nov 2017 18:55:46 +0000 (13:55 -0500)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Mon, 27 Nov 2017 14:09:32 +0000 (09:09 -0500)
Provide ZAPI code that can pass to an upper level protocol
what happened to it's route on install.

There are these notifications:
1) ZAPI_ROUTE_FAIL_INSTALL - The route attempted to be
   installed did not work.
2) ZAPI_ROUTE_BETTER_ADMIN_WON - A route that was installed
   has become un-installed due to another routing protocol
   installing a better admin distance
3) ZAPI_ROUTE_INSTALLED - The route specified has been installed

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
lib/log.c
lib/zclient.c
lib/zclient.h
zebra/zserv.c
zebra/zserv.h

index 02af55d46516d568f832f7c2f9ed4637e18a9802..89d7052d1eadb8e0d216abb7dfb667e241216b9f 100644 (file)
--- a/lib/log.c
+++ b/lib/log.c
@@ -897,6 +897,7 @@ static const struct zebra_desc_table command_types[] = {
        DESC_ENTRY(ZEBRA_INTERFACE_SET_MASTER),
        DESC_ENTRY(ZEBRA_ROUTE_ADD),
        DESC_ENTRY(ZEBRA_ROUTE_DELETE),
+       DESC_ENTRY(ZEBRA_ROUTE_NOTIFY_OWNER),
        DESC_ENTRY(ZEBRA_IPV4_ROUTE_ADD),
        DESC_ENTRY(ZEBRA_IPV4_ROUTE_DELETE),
        DESC_ENTRY(ZEBRA_IPV6_ROUTE_ADD),
index 6d6d44fb12afe255c00d62b8c5eed839a6df0e98..e769906012972cbb05a432483a33ecba6d53d79a 100644 (file)
@@ -1144,6 +1144,22 @@ stream_failure:
        return 0;
 }
 
+bool zapi_route_notify_decode(struct stream *s, struct prefix *p,
+                             enum zapi_route_notify_owner *note)
+{
+       STREAM_GET(note, s, sizeof(*note));
+
+       STREAM_GETC(s, p->family);
+       STREAM_GETC(s, p->prefixlen);
+       STREAM_GET(&p->u.prefix, s,
+                  PSIZE(p->prefixlen));
+
+       return true;
+
+stream_failure:
+       return false;
+}
+
 /*
  * send a ZEBRA_REDISTRIBUTE_ADD or ZEBRA_REDISTRIBUTE_DELETE
  * for the route type (ZEBRA_ROUTE_KERNEL etc.). The zebra server will
@@ -2194,6 +2210,11 @@ static int zclient_read(struct thread *thread)
                        (*zclient->pw_status_update)(command, zclient, length,
                                                     vrf_id);
                break;
+       case ZEBRA_ROUTE_NOTIFY_OWNER:
+               if (zclient->notify_owner)
+                       (*zclient->notify_owner)(command, zclient,
+                                                length, vrf_id);
+               break;
        default:
                break;
        }
index e9b2cb89560d5b5a618fdc70f0f4da58b89af6ba..025a3ac230d88dd88b4aefaed2c0bd26abb406ae 100644 (file)
@@ -61,6 +61,7 @@ typedef enum {
        ZEBRA_INTERFACE_SET_MASTER,
        ZEBRA_ROUTE_ADD,
        ZEBRA_ROUTE_DELETE,
+       ZEBRA_ROUTE_NOTIFY_OWNER,
        ZEBRA_IPV4_ROUTE_ADD,
        ZEBRA_IPV4_ROUTE_DELETE,
        ZEBRA_IPV6_ROUTE_ADD,
@@ -199,6 +200,8 @@ struct zclient {
        int (*local_macip_add)(int, struct zclient *, uint16_t, vrf_id_t);
        int (*local_macip_del)(int, struct zclient *, uint16_t, vrf_id_t);
        int (*pw_status_update)(int, struct zclient *, uint16_t, vrf_id_t);
+       int (*notify_owner)(int command, struct zclient *zclient,
+                           uint16_t length, vrf_id_t vrf_id);
 };
 
 /* Zebra API message flag. */
@@ -323,6 +326,12 @@ struct zapi_pw_status {
        uint32_t status;
 };
 
+enum zapi_route_notify_owner {
+       ZAPI_ROUTE_FAIL_INSTALL,
+       ZAPI_ROUTE_BETTER_ADMIN_WON,
+       ZAPI_ROUTE_INSTALLED,
+};
+
 /* Zebra MAC types */
 #define ZEBRA_MAC_TYPE_STICKY                0x01 /* Sticky MAC*/
 #define ZEBRA_MAC_TYPE_GW                    0x02 /* gateway (SVI) mac*/
@@ -445,6 +454,8 @@ extern int zapi_ipv4_route_ipv6_nexthop(u_char, struct zclient *,
 extern int zclient_route_send(u_char, struct zclient *, struct zapi_route *);
 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,
+                             enum zapi_route_notify_owner *note);
 
 static inline void zapi_route_set_blackhole(struct zapi_route *api,
                                            enum blackhole_type bh_type)
index 2389944e84aa9777b45334e31ac0508ef42ca5c7..f76490861dabc3da6f12e2d792fbd94e1d20deff 100644 (file)
@@ -988,6 +988,40 @@ static int zsend_ipv4_nexthop_lookup_mrib(struct zserv *client,
        return zebra_server_send_message(client);
 }
 
+int zsend_route_notify_owner(u_char proto, vrf_id_t vrf_id,
+                            struct prefix *p,
+                            enum zapi_route_notify_owner note)
+{
+       struct zserv *client;
+       struct stream *s;
+       uint8_t blen;
+
+       client = zebra_find_client(proto);
+       if (!client) {
+               if (IS_ZEBRA_DEBUG_PACKET)
+                       zlog_debug("Attempting to notify a client for proto: %u but did not find one",
+                                  proto);
+               return -1;
+       }
+
+       s = client->obuf;
+       stream_reset(s);
+
+       zserv_create_header(s, ZEBRA_ROUTE_NOTIFY_OWNER, vrf_id);
+
+       stream_put(s, &note, sizeof(note));
+
+       stream_putc(s, p->family);
+
+       blen = prefix_blen(p);
+       stream_putc(s, p->prefixlen);
+       stream_put(s, &p->u.prefix, blen);
+
+       stream_putw_at(s, 0, stream_get_endp(s));
+
+       return zebra_server_send_message(client);
+}
+
 /* Router-id is updated. Send ZEBRA_ROUTER_ID_ADD to client. */
 int zsend_router_id_update(struct zserv *client, struct prefix *p,
                           vrf_id_t vrf_id)
index 60e055088ae7a5105012030b16db92c3c5c42563..9978c6d896b6a6f48a16903efe12f0f1c8942532 100644 (file)
@@ -183,6 +183,10 @@ extern int zsend_interface_vrf_update(struct zserv *, struct interface *,
 extern int zsend_interface_link_params(struct zserv *, struct interface *);
 extern int zsend_pw_update(struct zserv *, struct zebra_pw *);
 
+extern int zsend_route_notify_owner(u_char proto, vrf_id_t vrf_id,
+                                   struct prefix *p,
+                                   enum zapi_route_notify_owner note);
+
 extern pid_t pid;
 
 extern void zserv_create_header(struct stream *s, uint16_t cmd,