]> git.proxmox.com Git - mirror_frr.git/blobdiff - zebra/zebra_ptm.c
zebra: reorganize zserv, batch i/o
[mirror_frr.git] / zebra / zebra_ptm.c
index 464a8cf875f2f9844c13fcd223befe1573b00d71..67c7220b6fe7bd20e0041e7bb7e0173c9abbabf5 100644 (file)
@@ -432,7 +432,7 @@ static void if_bfd_session_update(struct interface *ifp, struct prefix *dp,
                } else {
                        zlog_debug(
                                "MESSAGE: ZEBRA_INTERFACE_BFD_DEST_UPDATE %s/%d "
-                               "with src %s/%d and vrf %d %s event",
+                               "with src %s/%d and vrf %u %s event",
                                inet_ntop(dp->family, &dp->u.prefix, buf[0],
                                          INET6_ADDRSTRLEN),
                                dp->prefixlen,
@@ -661,8 +661,7 @@ int zebra_ptm_sock_read(struct thread *thread)
 }
 
 /* BFD peer/dst register/update */
-int zebra_ptm_bfd_dst_register(struct zserv *client, u_short length,
-                              int command, struct zebra_vrf *zvrf)
+void zebra_ptm_bfd_dst_register(ZAPI_HANDLER_ARGS)
 {
        struct stream *s;
        struct prefix src_p;
@@ -680,20 +679,20 @@ int zebra_ptm_bfd_dst_register(struct zserv *client, u_short length,
        int data_len = ZEBRA_PTM_SEND_MAX_SOCKBUF;
        unsigned int pid;
 
-       if (command == ZEBRA_BFD_DEST_UPDATE)
+       if (hdr->command == ZEBRA_BFD_DEST_UPDATE)
                client->bfd_peer_upd8_cnt++;
        else
                client->bfd_peer_add_cnt++;
 
        if (IS_ZEBRA_DEBUG_EVENT)
                zlog_debug("bfd_dst_register msg from client %s: length=%d",
-                          zebra_route_string(client->proto), length);
+                          zebra_route_string(client->proto), hdr->length);
 
        if (ptm_cb.ptm_sock == -1) {
                ptm_cb.t_timer = NULL;
                thread_add_timer(zebrad.master, zebra_ptm_connect, NULL,
                                 ptm_cb.reconnect_time, &ptm_cb.t_timer);
-               return -1;
+               return;
        }
 
        ptm_lib_init_msg(ptm_hdl, 0, PTMLIB_MSG_TYPE_CMD, NULL, &out_ctxt);
@@ -703,21 +702,21 @@ int zebra_ptm_bfd_dst_register(struct zserv *client, u_short length,
        ptm_lib_append_msg(ptm_hdl, out_ctxt, ZEBRA_PTM_BFD_CLIENT_FIELD,
                           tmp_buf);
 
-       s = client->ibuf;
+       s = msg;
 
-       pid = stream_getl(s);
+       STREAM_GETL(s, pid);
        sprintf(tmp_buf, "%d", pid);
        ptm_lib_append_msg(ptm_hdl, out_ctxt, ZEBRA_PTM_BFD_SEQID_FIELD,
                           tmp_buf);
 
-       dst_p.family = stream_getw(s);
+       STREAM_GETW(s, dst_p.family);
 
        if (dst_p.family == AF_INET)
                dst_p.prefixlen = IPV4_MAX_BYTELEN;
        else
                dst_p.prefixlen = IPV6_MAX_BYTELEN;
 
-       stream_get(&dst_p.u.prefix, s, dst_p.prefixlen);
+       STREAM_GET(&dst_p.u.prefix, s, dst_p.prefixlen);
        if (dst_p.family == AF_INET) {
                inet_ntop(AF_INET, &dst_p.u.prefix4, buf, sizeof(buf));
                ptm_lib_append_msg(ptm_hdl, out_ctxt,
@@ -728,32 +727,32 @@ int zebra_ptm_bfd_dst_register(struct zserv *client, u_short length,
                                   ZEBRA_PTM_BFD_DST_IP_FIELD, buf);
        }
 
-       min_rx_timer = stream_getl(s);
+       STREAM_GETL(s, min_rx_timer);
        sprintf(tmp_buf, "%d", min_rx_timer);
        ptm_lib_append_msg(ptm_hdl, out_ctxt, ZEBRA_PTM_BFD_MIN_RX_FIELD,
                           tmp_buf);
-       min_tx_timer = stream_getl(s);
+       STREAM_GETL(s, min_tx_timer);
        sprintf(tmp_buf, "%d", min_tx_timer);
        ptm_lib_append_msg(ptm_hdl, out_ctxt, ZEBRA_PTM_BFD_MIN_TX_FIELD,
                           tmp_buf);
-       detect_mul = stream_getc(s);
+       STREAM_GETC(s, detect_mul);
        sprintf(tmp_buf, "%d", detect_mul);
        ptm_lib_append_msg(ptm_hdl, out_ctxt, ZEBRA_PTM_BFD_DETECT_MULT_FIELD,
                           tmp_buf);
 
-       multi_hop = stream_getc(s);
+       STREAM_GETC(s, multi_hop);
        if (multi_hop) {
                sprintf(tmp_buf, "%d", 1);
                ptm_lib_append_msg(ptm_hdl, out_ctxt,
                                   ZEBRA_PTM_BFD_MULTI_HOP_FIELD, tmp_buf);
-               src_p.family = stream_getw(s);
+               STREAM_GETW(s, src_p.family);
 
                if (src_p.family == AF_INET)
                        src_p.prefixlen = IPV4_MAX_BYTELEN;
                else
                        src_p.prefixlen = IPV6_MAX_BYTELEN;
 
-               stream_get(&src_p.u.prefix, s, src_p.prefixlen);
+               STREAM_GET(&src_p.u.prefix, s, src_p.prefixlen);
                if (src_p.family == AF_INET) {
                        inet_ntop(AF_INET, &src_p.u.prefix4, buf, sizeof(buf));
                        ptm_lib_append_msg(ptm_hdl, out_ctxt,
@@ -764,7 +763,7 @@ int zebra_ptm_bfd_dst_register(struct zserv *client, u_short length,
                                           ZEBRA_PTM_BFD_SRC_IP_FIELD, buf);
                }
 
-               multi_hop_cnt = stream_getc(s);
+               STREAM_GETC(s, multi_hop_cnt);
                sprintf(tmp_buf, "%d", multi_hop_cnt);
                ptm_lib_append_msg(ptm_hdl, out_ctxt,
                                   ZEBRA_PTM_BFD_MAX_HOP_CNT_FIELD, tmp_buf);
@@ -775,14 +774,14 @@ int zebra_ptm_bfd_dst_register(struct zserv *client, u_short length,
                                           zvrf_name(zvrf));
        } else {
                if (dst_p.family == AF_INET6) {
-                       src_p.family = stream_getw(s);
+                       STREAM_GETW(s, src_p.family);
 
                        if (src_p.family == AF_INET)
                                src_p.prefixlen = IPV4_MAX_BYTELEN;
                        else
                                src_p.prefixlen = IPV6_MAX_BYTELEN;
 
-                       stream_get(&src_p.u.prefix, s, src_p.prefixlen);
+                       STREAM_GET(&src_p.u.prefix, s, src_p.prefixlen);
                        if (src_p.family == AF_INET) {
                                inet_ntop(AF_INET, &src_p.u.prefix4, buf,
                                          sizeof(buf));
@@ -797,8 +796,8 @@ int zebra_ptm_bfd_dst_register(struct zserv *client, u_short length,
                                                   buf);
                        }
                }
-               len = stream_getc(s);
-               stream_get(if_name, s, len);
+               STREAM_GETC(s, len);
+               STREAM_GET(if_name, s, len);
                if_name[len] = '\0';
 
                ptm_lib_append_msg(ptm_hdl, out_ctxt,
@@ -815,12 +814,15 @@ int zebra_ptm_bfd_dst_register(struct zserv *client, u_short length,
                zlog_debug("%s: Sent message (%d) %s", __func__, data_len,
                           ptm_cb.out_data);
        zebra_ptm_send_message(ptm_cb.out_data, data_len);
-       return 0;
+
+       return;
+
+stream_failure:
+       ptm_lib_cleanup_msg(ptm_hdl, out_ctxt);
 }
 
 /* BFD peer/dst deregister */
-int zebra_ptm_bfd_dst_deregister(struct zserv *client, u_short length,
-                                struct zebra_vrf *zvrf)
+void zebra_ptm_bfd_dst_deregister(ZAPI_HANDLER_ARGS)
 {
        struct stream *s;
        struct prefix src_p;
@@ -838,13 +840,13 @@ int zebra_ptm_bfd_dst_deregister(struct zserv *client, u_short length,
 
        if (IS_ZEBRA_DEBUG_EVENT)
                zlog_debug("bfd_dst_deregister msg from client %s: length=%d",
-                          zebra_route_string(client->proto), length);
+                          zebra_route_string(client->proto), hdr->length);
 
        if (ptm_cb.ptm_sock == -1) {
                ptm_cb.t_timer = NULL;
                thread_add_timer(zebrad.master, zebra_ptm_connect, NULL,
                                 ptm_cb.reconnect_time, &ptm_cb.t_timer);
-               return -1;
+               return;
        }
 
        ptm_lib_init_msg(ptm_hdl, 0, PTMLIB_MSG_TYPE_CMD, NULL, &out_ctxt);
@@ -856,21 +858,21 @@ int zebra_ptm_bfd_dst_deregister(struct zserv *client, u_short length,
        ptm_lib_append_msg(ptm_hdl, out_ctxt, ZEBRA_PTM_BFD_CLIENT_FIELD,
                           tmp_buf);
 
-       s = client->ibuf;
+       s = msg;
 
-       pid = stream_getl(s);
+       STREAM_GETL(s, pid);
        sprintf(tmp_buf, "%d", pid);
        ptm_lib_append_msg(ptm_hdl, out_ctxt, ZEBRA_PTM_BFD_SEQID_FIELD,
                           tmp_buf);
 
-       dst_p.family = stream_getw(s);
+       STREAM_GETW(s, dst_p.family);
 
        if (dst_p.family == AF_INET)
                dst_p.prefixlen = IPV4_MAX_BYTELEN;
        else
                dst_p.prefixlen = IPV6_MAX_BYTELEN;
 
-       stream_get(&dst_p.u.prefix, s, dst_p.prefixlen);
+       STREAM_GET(&dst_p.u.prefix, s, dst_p.prefixlen);
        if (dst_p.family == AF_INET)
                inet_ntop(AF_INET, &dst_p.u.prefix4, buf, sizeof(buf));
        else
@@ -878,20 +880,20 @@ int zebra_ptm_bfd_dst_deregister(struct zserv *client, u_short length,
        ptm_lib_append_msg(ptm_hdl, out_ctxt, ZEBRA_PTM_BFD_DST_IP_FIELD, buf);
 
 
-       multi_hop = stream_getc(s);
+       STREAM_GETC(s, multi_hop);
        if (multi_hop) {
                sprintf(tmp_buf, "%d", 1);
                ptm_lib_append_msg(ptm_hdl, out_ctxt,
                                   ZEBRA_PTM_BFD_MULTI_HOP_FIELD, tmp_buf);
 
-               src_p.family = stream_getw(s);
+               STREAM_GETW(s, src_p.family);
 
                if (src_p.family == AF_INET)
                        src_p.prefixlen = IPV4_MAX_BYTELEN;
                else
                        src_p.prefixlen = IPV6_MAX_BYTELEN;
 
-               stream_get(&src_p.u.prefix, s, src_p.prefixlen);
+               STREAM_GET(&src_p.u.prefix, s, src_p.prefixlen);
                if (src_p.family == AF_INET)
                        inet_ntop(AF_INET, &src_p.u.prefix4, buf, sizeof(buf));
                else
@@ -905,14 +907,14 @@ int zebra_ptm_bfd_dst_deregister(struct zserv *client, u_short length,
                                           zvrf_name(zvrf));
        } else {
                if (dst_p.family == AF_INET6) {
-                       src_p.family = stream_getw(s);
+                       STREAM_GETW(s, src_p.family);
 
                        if (src_p.family == AF_INET)
                                src_p.prefixlen = IPV4_MAX_BYTELEN;
                        else
                                src_p.prefixlen = IPV6_MAX_BYTELEN;
 
-                       stream_get(&src_p.u.prefix, s, src_p.prefixlen);
+                       STREAM_GET(&src_p.u.prefix, s, src_p.prefixlen);
                        if (src_p.family == AF_INET) {
                                inet_ntop(AF_INET, &src_p.u.prefix4, buf,
                                          sizeof(buf));
@@ -928,8 +930,8 @@ int zebra_ptm_bfd_dst_deregister(struct zserv *client, u_short length,
                        }
                }
 
-               len = stream_getc(s);
-               stream_get(if_name, s, len);
+               STREAM_GETC(s, len);
+               STREAM_GET(if_name, s, len);
                if_name[len] = '\0';
 
                ptm_lib_append_msg(ptm_hdl, out_ctxt,
@@ -942,16 +944,19 @@ int zebra_ptm_bfd_dst_deregister(struct zserv *client, u_short length,
                           ptm_cb.out_data);
 
        zebra_ptm_send_message(ptm_cb.out_data, data_len);
-       return 0;
+
+       return;
+
+stream_failure:
+       ptm_lib_cleanup_msg(ptm_hdl, out_ctxt);
 }
 
 /* BFD client register */
-int zebra_ptm_bfd_client_register(struct zserv *client,
-                                 u_short length)
+void zebra_ptm_bfd_client_register(ZAPI_HANDLER_ARGS)
 {
        struct stream *s;
        unsigned int pid;
-       void *out_ctxt;
+       void *out_ctxt = NULL;
        char tmp_buf[64];
        int data_len = ZEBRA_PTM_SEND_MAX_SOCKBUF;
 
@@ -959,16 +964,16 @@ int zebra_ptm_bfd_client_register(struct zserv *client,
 
        if (IS_ZEBRA_DEBUG_EVENT)
                zlog_debug("bfd_client_register msg from client %s: length=%d",
-                          zebra_route_string(client->proto), length);
+                          zebra_route_string(client->proto), hdr->length);
 
-       s = client->ibuf;
-       pid = stream_getl(s);
+       s = msg;
+       STREAM_GETL(s, pid);
 
        if (ptm_cb.ptm_sock == -1) {
                ptm_cb.t_timer = NULL;
                thread_add_timer(zebrad.master, zebra_ptm_connect, NULL,
                                 ptm_cb.reconnect_time, &ptm_cb.t_timer);
-               return -1;
+               return;
        }
 
        ptm_lib_init_msg(ptm_hdl, 0, PTMLIB_MSG_TYPE_CMD, NULL, &out_ctxt);
@@ -993,7 +998,18 @@ int zebra_ptm_bfd_client_register(struct zserv *client,
 
        SET_FLAG(ptm_cb.client_flags[client->proto],
                 ZEBRA_PTM_BFD_CLIENT_FLAG_REG);
-       return 0;
+
+       return;
+
+stream_failure:
+       /*
+        * IF we ever add more STREAM_GETXXX functions after the out_ctxt
+        * is allocated then we need to add this code back in
+        *
+        * if (out_ctxt)
+        *      ptm_lib_cleanup_msg(ptm_hdl, out_ctxt);
+        */
+       return;
 }
 
 /* BFD client deregister */