summaryrefslogtreecommitdiffstats
path: root/zebra/zebra_ptm.c
diff options
context:
space:
mode:
authorDonald Sharp <sharpd@cumulusnetworks.com>2017-11-10 14:51:34 +0100
committerDonald Sharp <sharpd@cumulusnetworks.com>2017-11-13 20:16:13 +0100
commitec93aa120e7f1e817cbbe0498a719d5392a049ba (patch)
tree5a032c21c3dd983adf92fc1dd6f38d1a115f29f9 /zebra/zebra_ptm.c
parentlib: Add STREAM_GETX functions (diff)
downloadfrr-ec93aa120e7f1e817cbbe0498a719d5392a049ba.tar.xz
frr-ec93aa120e7f1e817cbbe0498a719d5392a049ba.zip
lib, zebra: Modify zebra to use STREAM_GET for zapi
This code modifies zebra to use the STREAM_GET functionality. This will allow zebra to continue functioning in the case of bad input data from higher level protocols instead of crashing. Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
Diffstat (limited to 'zebra/zebra_ptm.c')
-rw-r--r--zebra/zebra_ptm.c55
1 files changed, 30 insertions, 25 deletions
diff --git a/zebra/zebra_ptm.c b/zebra/zebra_ptm.c
index 464a8cf87..dcd4fb023 100644
--- a/zebra/zebra_ptm.c
+++ b/zebra/zebra_ptm.c
@@ -705,19 +705,19 @@ int zebra_ptm_bfd_dst_register(struct zserv *client, u_short length,
s = client->ibuf;
- 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 +728,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 +764,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 +775,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 +797,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,6 +815,8 @@ 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);
+
+stream_failure:
return 0;
}
@@ -858,19 +860,19 @@ int zebra_ptm_bfd_dst_deregister(struct zserv *client, u_short length,
s = client->ibuf;
- 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,6 +944,8 @@ 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);
+
+stream_failure:
return 0;
}
@@ -962,7 +966,7 @@ int zebra_ptm_bfd_client_register(struct zserv *client,
zebra_route_string(client->proto), length);
s = client->ibuf;
- pid = stream_getl(s);
+ STREAM_GETL(s, pid);
if (ptm_cb.ptm_sock == -1) {
ptm_cb.t_timer = NULL;
@@ -993,6 +997,7 @@ int zebra_ptm_bfd_client_register(struct zserv *client,
SET_FLAG(ptm_cb.client_flags[client->proto],
ZEBRA_PTM_BFD_CLIENT_FLAG_REG);
+stream_failure:
return 0;
}