summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bgpd/bgp_attr_evpn.c7
-rw-r--r--bgpd/bgp_clist.c19
-rw-r--r--bgpd/bgp_ecommunity.c24
-rw-r--r--bgpd/bgp_ecommunity.h10
-rw-r--r--bgpd/bgp_encap_tlv.c17
-rw-r--r--bgpd/bgp_evpn_vty.c25
-rw-r--r--bgpd/bgp_lcommunity.c19
-rw-r--r--bgpd/bgp_nexthop.c6
-rw-r--r--bgpd/bgp_rd.c12
-rw-r--r--bgpd/rfapi/rfapi_import.c6
-rw-r--r--doc/cli.md3
-rw-r--r--ldpd/lde.c8
-rw-r--r--ldpd/ldp_debug.c12
-rw-r--r--ldpd/ldp_debug.h9
-rw-r--r--ldpd/ldp_vty_cmds.c3
-rw-r--r--ldpd/ldpd.c2
-rw-r--r--lib/command_match.c2
-rw-r--r--lib/skiplist.c4
-rw-r--r--lib/stream.c4
-rw-r--r--lib/stream.h18
-rw-r--r--ospf6d/ospf6_area.c3
-rw-r--r--ospfd/ospf_opaque.h3
-rw-r--r--zebra/redistribute.c12
-rw-r--r--zebra/zebra_mpls.c11
-rw-r--r--zebra/zebra_rib.c52
-rw-r--r--zebra/zebra_snmp.c15
-rw-r--r--zebra/zebra_vrf.c5
-rw-r--r--zebra/zserv.c2
28 files changed, 165 insertions, 148 deletions
diff --git a/bgpd/bgp_attr_evpn.c b/bgpd/bgp_attr_evpn.c
index 6ead059261..300c9ddb50 100644
--- a/bgpd/bgp_attr_evpn.c
+++ b/bgpd/bgp_attr_evpn.c
@@ -144,11 +144,8 @@ u_int32_t bgp_attr_mac_mobility_seqnum(struct attr *attr, u_char *sticky)
*sticky = 0;
pnt++;
- seq_num = (*pnt++ << 24);
- seq_num |= (*pnt++ << 16);
- seq_num |= (*pnt++ << 8);
- seq_num |= (*pnt++);
-
+ pnt = ptr_get_be32(pnt, &seq_num);
+ (void)pnt; /* consume value */
return seq_num;
}
diff --git a/bgpd/bgp_clist.c b/bgpd/bgp_clist.c
index b62a0a540c..f3bae9535c 100644
--- a/bgpd/bgp_clist.c
+++ b/bgpd/bgp_clist.c
@@ -25,6 +25,7 @@
#include "memory.h"
#include "queue.h"
#include "filter.h"
+#include "stream.h"
#include "bgpd/bgpd.h"
#include "bgpd/bgp_community.h"
@@ -465,20 +466,10 @@ static char *lcommunity_str_get(struct lcommunity *lcom, int i)
str = pnt = XMALLOC(MTYPE_LCOMMUNITY_STR, 48);
ptr = (u_char *)lcomval.val;
- globaladmin = (*ptr++ << 24);
- globaladmin |= (*ptr++ << 16);
- globaladmin |= (*ptr++ << 8);
- globaladmin |= (*ptr++);
-
- localdata1 = (*ptr++ << 24);
- localdata1 |= (*ptr++ << 16);
- localdata1 |= (*ptr++ << 8);
- localdata1 |= (*ptr++);
-
- localdata2 = (*ptr++ << 24);
- localdata2 |= (*ptr++ << 16);
- localdata2 |= (*ptr++ << 8);
- localdata2 |= (*ptr++);
+ ptr = ptr_get_be32(ptr, &globaladmin);
+ ptr = ptr_get_be32(ptr, &localdata1);
+ ptr = ptr_get_be32(ptr, &localdata2);
+ (void)ptr; /* consume value */
sprintf(pnt, "%u:%u:%u", globaladmin, localdata1, localdata2);
pnt += strlen(pnt);
diff --git a/bgpd/bgp_ecommunity.c b/bgpd/bgp_ecommunity.c
index ec52422d4c..bdcc12705c 100644
--- a/bgpd/bgp_ecommunity.c
+++ b/bgpd/bgp_ecommunity.c
@@ -27,6 +27,7 @@
#include "queue.h"
#include "filter.h"
#include "jhash.h"
+#include "stream.h"
#include "bgpd/bgpd.h"
#include "bgpd/bgp_ecommunity.h"
@@ -554,15 +555,8 @@ static int ecommunity_rt_soo_str(char *buf, u_int8_t *pnt, int type,
const char *prefix;
/* For parse Extended Community attribute tupple. */
- struct ecommunity_as {
- as_t as;
- u_int32_t val;
- } eas;
-
- struct ecommunity_ip {
- struct in_addr ip;
- u_int16_t val;
- } eip;
+ struct ecommunity_as eas;
+ struct ecommunity_ip eip;
/* Determine prefix for string, if any. */
@@ -583,10 +577,7 @@ static int ecommunity_rt_soo_str(char *buf, u_int8_t *pnt, int type,
/* Put string into buffer. */
if (type == ECOMMUNITY_ENCODE_AS4) {
- eas.as = (*pnt++ << 24);
- eas.as |= (*pnt++ << 16);
- eas.as |= (*pnt++ << 8);
- eas.as |= (*pnt++);
+ pnt = ptr_get_be32(pnt, &eas.as);
eas.val = (*pnt++ << 8);
eas.val |= (*pnt++);
@@ -594,11 +585,7 @@ static int ecommunity_rt_soo_str(char *buf, u_int8_t *pnt, int type,
} else if (type == ECOMMUNITY_ENCODE_AS) {
eas.as = (*pnt++ << 8);
eas.as |= (*pnt++);
-
- eas.val = (*pnt++ << 24);
- eas.val |= (*pnt++ << 16);
- eas.val |= (*pnt++ << 8);
- eas.val |= (*pnt++);
+ pnt = ptr_get_be32(pnt, &eas.val);
len = sprintf(buf, "%s%u:%u", prefix, eas.as, eas.val);
} else if (type == ECOMMUNITY_ENCODE_IP) {
@@ -610,6 +597,7 @@ static int ecommunity_rt_soo_str(char *buf, u_int8_t *pnt, int type,
len = sprintf(buf, "%s%s:%u", prefix, inet_ntoa(eip.ip),
eip.val);
}
+ (void)pnt; /* consume value */
return len;
}
diff --git a/bgpd/bgp_ecommunity.h b/bgpd/bgp_ecommunity.h
index 927b1370cf..c967f8bd47 100644
--- a/bgpd/bgp_ecommunity.h
+++ b/bgpd/bgp_ecommunity.h
@@ -70,6 +70,16 @@ struct ecommunity {
char *str;
};
+struct ecommunity_as {
+ as_t as;
+ uint32_t val;
+};
+
+struct ecommunity_ip {
+ struct in_addr ip;
+ uint16_t val;
+};
+
/* Extended community value is eight octet. */
struct ecommunity_val {
char val[ECOMMUNITY_SIZE];
diff --git a/bgpd/bgp_encap_tlv.c b/bgpd/bgp_encap_tlv.c
index 5c0cc40f16..4457501613 100644
--- a/bgpd/bgp_encap_tlv.c
+++ b/bgpd/bgp_encap_tlv.c
@@ -22,6 +22,7 @@
#include "memory.h"
#include "prefix.h"
#include "filter.h"
+#include "stream.h"
#include "bgpd.h"
#include "bgp_attr.h"
@@ -470,8 +471,7 @@ static int subtlv_decode_encap_l2tpv3_over_ip(
return -1;
}
- st->sessionid = (subtlv->value[0] << 24) | (subtlv->value[1] << 16)
- | (subtlv->value[2] << 8) | subtlv->value[3];
+ ptr_get_be32(subtlv->value, &st->sessionid);
st->cookie_length = subtlv->length - 4;
if (st->cookie_length > sizeof(st->cookie)) {
zlog_debug("%s, subtlv length %d is greater than %d", __func__,
@@ -491,8 +491,7 @@ static int subtlv_decode_encap_gre(struct bgp_attr_encap_subtlv *subtlv,
subtlv->length);
return -1;
}
- st->gre_key = (subtlv->value[0] << 24) | (subtlv->value[1] << 16)
- | (subtlv->value[2] << 8) | subtlv->value[3];
+ ptr_get_be32(subtlv->value, &st->gre_key);
return 0;
}
@@ -545,8 +544,7 @@ static int subtlv_decode_color(struct bgp_attr_encap_subtlv *subtlv,
__func__);
return -1;
}
- st->color = (subtlv->value[4] << 24) | (subtlv->value[5] << 16)
- | (subtlv->value[6] << 8) | subtlv->value[7];
+ ptr_get_be32(subtlv->value + 4, &st->color);
return 0;
}
@@ -580,16 +578,13 @@ subtlv_decode_remote_endpoint(struct bgp_attr_encap_subtlv *subtlv,
}
if (subtlv->length == 8) {
st->family = AF_INET;
- st->ip_address.v4.s_addr =
- ((subtlv->value[0] << 24) | (subtlv->value[1] << 16)
- | (subtlv->value[2] << 8) | subtlv->value[3]);
+ memcpy(&st->ip_address.v4.s_addr, subtlv->value, 4);
} else {
st->family = AF_INET6;
memcpy(&(st->ip_address.v6.s6_addr), subtlv->value, 16);
}
i = subtlv->length - 4;
- st->as4 = ((subtlv->value[i] << 24) | (subtlv->value[i + 1] << 16)
- | (subtlv->value[i + 2] << 8) | subtlv->value[i + 3]);
+ ptr_get_be32(subtlv->value + i, &st->as4);
return 0;
}
diff --git a/bgpd/bgp_evpn_vty.c b/bgpd/bgp_evpn_vty.c
index 2410f30ddf..c05e313298 100644
--- a/bgpd/bgp_evpn_vty.c
+++ b/bgpd/bgp_evpn_vty.c
@@ -22,6 +22,7 @@
#include "command.h"
#include "prefix.h"
#include "lib/json.h"
+#include "stream.h"
#include "bgpd/bgpd.h"
#include "bgpd/bgp_table.h"
@@ -34,6 +35,7 @@
#include "bgpd/bgp_evpn_private.h"
#include "bgpd/bgp_zebra.h"
#include "bgpd/bgp_vty.h"
+#include "bgpd/bgp_ecommunity.h"
#define SHOW_DISPLAY_STANDARD 0
#define SHOW_DISPLAY_TAGS 1
@@ -56,14 +58,8 @@ static void display_import_rt(struct vty *vty, struct irt_node *irt,
{
u_char *pnt;
u_char type, sub_type;
- struct ecommunity_as {
- as_t as;
- u_int32_t val;
- } eas;
- struct ecommunity_ip {
- struct in_addr ip;
- u_int16_t val;
- } eip;
+ struct ecommunity_as eas;
+ struct ecommunity_ip eip;
struct listnode *node, *nnode;
struct bgpevpn *tmp_vpn;
json_object *json_rt = NULL;
@@ -83,15 +79,12 @@ static void display_import_rt(struct vty *vty, struct irt_node *irt,
if (sub_type != ECOMMUNITY_ROUTE_TARGET)
return;
+ memset(&eas, 0, sizeof(eas));
switch (type) {
case ECOMMUNITY_ENCODE_AS:
eas.as = (*pnt++ << 8);
eas.as |= (*pnt++);
-
- eas.val = (*pnt++ << 24);
- eas.val |= (*pnt++ << 16);
- eas.val |= (*pnt++ << 8);
- eas.val |= (*pnt++);
+ pnt = ptr_get_be32(pnt, &eas.val);
snprintf(rt_buf, RT_ADDRSTRLEN, "%u:%u", eas.as, eas.val);
@@ -119,11 +112,7 @@ static void display_import_rt(struct vty *vty, struct irt_node *irt,
break;
case ECOMMUNITY_ENCODE_AS4:
- eas.as = (*pnt++ << 24);
- eas.as |= (*pnt++ << 16);
- eas.as |= (*pnt++ << 8);
- eas.as |= (*pnt++);
-
+ pnt = ptr_get_be32(pnt, &eas.val);
eas.val = (*pnt++ << 8);
eas.val |= (*pnt++);
diff --git a/bgpd/bgp_lcommunity.c b/bgpd/bgp_lcommunity.c
index d75f33f58b..54e9fd8894 100644
--- a/bgpd/bgp_lcommunity.c
+++ b/bgpd/bgp_lcommunity.c
@@ -26,6 +26,7 @@
#include "command.h"
#include "filter.h"
#include "jhash.h"
+#include "stream.h"
#include "bgpd/bgpd.h"
#include "bgpd/bgp_lcommunity.h"
@@ -431,20 +432,10 @@ char *lcommunity_lcom2str(struct lcommunity *lcom, int format)
pnt = lcom->val + (i * LCOMMUNITY_SIZE);
- globaladmin = (*pnt++ << 24);
- globaladmin |= (*pnt++ << 16);
- globaladmin |= (*pnt++ << 8);
- globaladmin |= (*pnt++);
-
- localdata1 = (*pnt++ << 24);
- localdata1 |= (*pnt++ << 16);
- localdata1 |= (*pnt++ << 8);
- localdata1 |= (*pnt++);
-
- localdata2 = (*pnt++ << 24);
- localdata2 |= (*pnt++ << 16);
- localdata2 |= (*pnt++ << 8);
- localdata2 |= (*pnt++);
+ pnt = ptr_get_be32(pnt, &globaladmin);
+ pnt = ptr_get_be32(pnt, &localdata1);
+ pnt = ptr_get_be32(pnt, &localdata2);
+ (void)pnt; /* consume value */
len = sprintf(str_buf + str_pnt, "%u:%u:%u", globaladmin,
localdata1, localdata2);
diff --git a/bgpd/bgp_nexthop.c b/bgpd/bgp_nexthop.c
index 1200d74d6a..8c08fe4c8f 100644
--- a/bgpd/bgp_nexthop.c
+++ b/bgpd/bgp_nexthop.c
@@ -580,7 +580,11 @@ DEFUN (show_ip_bgp_nexthop,
"Show detailed information\n")
{
int idx = 0;
- char *vrf = argv_find(argv, argc, "WORD", &idx) ? argv[idx]->arg : NULL;
+ char *vrf = NULL;
+
+ if (argv_find(argv, argc, "view", &idx)
+ || argv_find(argv, argc, "vrf", &idx))
+ vrf = argv[++idx]->arg;
int detail = argv_find(argv, argc, "detail", &idx) ? 1 : 0;
return show_ip_bgp_nexthop_table(vty, vrf, detail);
}
diff --git a/bgpd/bgp_rd.c b/bgpd/bgp_rd.c
index a15828bd36..2b676e052b 100644
--- a/bgpd/bgp_rd.c
+++ b/bgpd/bgp_rd.c
@@ -63,21 +63,13 @@ void decode_rd_as(u_char *pnt, struct rd_as *rd_as)
{
rd_as->as = (u_int16_t)*pnt++ << 8;
rd_as->as |= (u_int16_t)*pnt++;
-
- rd_as->val = ((u_int32_t)*pnt++ << 24);
- rd_as->val |= ((u_int32_t)*pnt++ << 16);
- rd_as->val |= ((u_int32_t)*pnt++ << 8);
- rd_as->val |= (u_int32_t)*pnt;
+ ptr_get_be32(pnt, &rd_as->val);
}
/* type == RD_TYPE_AS4 */
void decode_rd_as4(u_char *pnt, struct rd_as *rd_as)
{
- rd_as->as = (u_int32_t)*pnt++ << 24;
- rd_as->as |= (u_int32_t)*pnt++ << 16;
- rd_as->as |= (u_int32_t)*pnt++ << 8;
- rd_as->as |= (u_int32_t)*pnt++;
-
+ pnt = ptr_get_be32(pnt, &rd_as->as);
rd_as->val = ((u_int16_t)*pnt++ << 8);
rd_as->val |= (u_int16_t)*pnt;
}
diff --git a/bgpd/rfapi/rfapi_import.c b/bgpd/rfapi/rfapi_import.c
index 3f427c3903..d963a759ac 100644
--- a/bgpd/rfapi/rfapi_import.c
+++ b/bgpd/rfapi/rfapi_import.c
@@ -33,6 +33,7 @@
#include "lib/log.h"
#include "lib/skiplist.h"
#include "lib/thread.h"
+#include "lib/stream.h"
#include "bgpd/bgpd.h"
#include "bgpd/bgp_ecommunity.h"
@@ -1079,10 +1080,7 @@ int rfapiEcommunityGetEthernetTag(struct ecommunity *ecom, uint16_t *tag_id)
if (*p++ == ECOMMUNITY_ROUTE_TARGET) {
if (encode == ECOMMUNITY_ENCODE_AS4) {
- as = (*p++ << 24);
- as |= (*p++ << 16);
- as |= (*p++ << 8);
- as |= (*p++);
+ p = ptr_get_be32(p, &as);
} else if (encode == ECOMMUNITY_ENCODE_AS) {
as = (*p++ << 8);
as |= (*p++);
diff --git a/doc/cli.md b/doc/cli.md
index ef867362c3..253617e9b5 100644
--- a/doc/cli.md
+++ b/doc/cli.md
@@ -75,6 +75,9 @@ Some general notes:
configuration items should be defined in separate commands. Clarity is
preferred over LOC (within reason).
+* The maximum number of space-separated tokens that can be entered is presently
+ limited to 256. Please keep this limit in mind when implementing new CLI.
+
Variable Names
--------------
The parser tries to fill the "varname" field on each token. This can happen
diff --git a/ldpd/lde.c b/ldpd/lde.c
index 4460b424d2..3482f3d722 100644
--- a/ldpd/lde.c
+++ b/ldpd/lde.c
@@ -1609,7 +1609,6 @@ static void
zclient_sync_init(u_short instance)
{
/* Initialize special zclient for synchronous message exchanges. */
- log_debug("Initializing synchronous zclient for label manager");
zclient_sync = zclient_new(master);
zclient_sync->sock = -1;
zclient_sync->redist_default = ZEBRA_ROUTE_LDP;
@@ -1640,7 +1639,7 @@ lde_get_label_chunk(void)
int ret;
uint32_t start, end;
- log_debug("Getting label chunk");
+ debug_labels("getting label chunk (size %u)", CHUNK_SIZE);
ret = lm_get_label_chunk(zclient_sync, 0, CHUNK_SIZE, &start, &end);
if (ret < 0) {
log_warnx("Error getting label chunk!");
@@ -1670,7 +1669,7 @@ on_get_label_chunk_response(uint32_t start, uint32_t end)
{
struct label_chunk *new_label_chunk;
- log_debug("Label Chunk assign: %u - %u", start, end);
+ debug_labels("label chunk assign: %u - %u", start, end);
new_label_chunk = calloc(1, sizeof(struct label_chunk));
if (!new_label_chunk) {
@@ -1693,7 +1692,8 @@ static uint32_t
lde_get_next_label(void)
{
struct label_chunk *label_chunk;
- uint32_t i, pos, size;
+ uint32_t i, size;
+ uint64_t pos;
uint32_t label = NO_LABEL;
while (current_label_chunk) {
diff --git a/ldpd/ldp_debug.c b/ldpd/ldp_debug.c
index d80ec8dfbc..ee4f0843b7 100644
--- a/ldpd/ldp_debug.c
+++ b/ldpd/ldp_debug.c
@@ -66,6 +66,11 @@ ldp_vty_debug(struct vty *vty, const char *negate, const char *type_str,
DEBUG_OFF(event, EVENT);
else
DEBUG_ON(event, EVENT);
+ } else if (strcmp(type_str, "labels") == 0) {
+ if (negate)
+ DEBUG_OFF(labels, LABELS);
+ else
+ DEBUG_ON(labels, LABELS);
} else if (strcmp(type_str, "messages") == 0) {
if (dir_str == NULL)
return (CMD_WARNING_CONFIG_FAILED);
@@ -115,6 +120,8 @@ ldp_vty_show_debugging(struct vty *vty)
vty_out (vty, " LDP errors debugging is on\n");
if (LDP_DEBUG(event, EVENT))
vty_out (vty, " LDP events debugging is on\n");
+ if (LDP_DEBUG(labels, LABELS))
+ vty_out (vty, " LDP labels debugging is on\n");
if (LDP_DEBUG(msg, MSG_RECV_ALL))
vty_out (vty,
" LDP detailed messages debugging is on (inbound)\n");
@@ -157,6 +164,11 @@ ldp_debug_config_write(struct vty *vty)
write = 1;
}
+ if (CONF_LDP_DEBUG(labels, LABELS)) {
+ vty_out (vty, "debug mpls ldp labels\n");
+ write = 1;
+ }
+
if (CONF_LDP_DEBUG(msg, MSG_RECV_ALL)) {
vty_out (vty, "debug mpls ldp messages recv all\n");
write = 1;
diff --git a/ldpd/ldp_debug.h b/ldpd/ldp_debug.h
index 4b91656851..a0972cea8e 100644
--- a/ldpd/ldp_debug.h
+++ b/ldpd/ldp_debug.h
@@ -31,6 +31,9 @@ struct ldp_debug {
int event;
#define LDP_DEBUG_EVENT 0x01
+ int labels;
+#define LDP_DEBUG_LABELS 0x01
+
int msg;
#define LDP_DEBUG_MSG_RECV 0x01
#define LDP_DEBUG_MSG_RECV_ALL 0x02
@@ -90,6 +93,12 @@ do { \
log_debug("event: " emsg, __VA_ARGS__); \
} while (0)
+#define debug_labels(emsg, ...) \
+do { \
+ if (LDP_DEBUG(labels, LABELS)) \
+ log_debug("labels: " emsg, __VA_ARGS__); \
+} while (0)
+
#define debug_msg_recv(emsg, ...) \
do { \
if (LDP_DEBUG(msg, MSG_RECV)) \
diff --git a/ldpd/ldp_vty_cmds.c b/ldpd/ldp_vty_cmds.c
index be473063cd..cd92958d4c 100644
--- a/ldpd/ldp_vty_cmds.c
+++ b/ldpd/ldp_vty_cmds.c
@@ -538,13 +538,14 @@ DEFPY (ldp_debug_mpls_ldp_discovery_hello,
DEFPY (ldp_debug_mpls_ldp_type,
ldp_debug_mpls_ldp_type_cmd,
- "[no] debug mpls ldp <errors|event|zebra>$type",
+ "[no] debug mpls ldp <errors|event|labels|zebra>$type",
NO_STR
"Debugging functions\n"
"MPLS information\n"
"Label Distribution Protocol\n"
"Errors\n"
"LDP event information\n"
+ "LDP label allocation information\n"
"LDP zebra information\n")
{
return (ldp_vty_debug(vty, no, type, NULL, NULL));
diff --git a/ldpd/ldpd.c b/ldpd/ldpd.c
index 0a586ec1c5..d31c575920 100644
--- a/ldpd/ldpd.c
+++ b/ldpd/ldpd.c
@@ -370,9 +370,9 @@ main(int argc, char *argv[])
if (main_imsg_send_ipc_sockets(&iev_ldpe->ibuf, &iev_lde->ibuf))
fatal("could not establish imsg links");
- main_imsg_compose_both(IMSG_INIT, &init, sizeof(init));
main_imsg_compose_both(IMSG_DEBUG_UPDATE, &ldp_debug,
sizeof(ldp_debug));
+ main_imsg_compose_both(IMSG_INIT, &init, sizeof(init));
main_imsg_send_config(ldpd_conf);
if (ldpd_conf->ipv4.flags & F_LDPD_AF_ENABLED)
diff --git a/lib/command_match.c b/lib/command_match.c
index ad3ec2492e..62e7c63068 100644
--- a/lib/command_match.c
+++ b/lib/command_match.c
@@ -28,7 +28,7 @@
DEFINE_MTYPE_STATIC(LIB, CMD_MATCHSTACK, "Command Match Stack")
-#define MAXDEPTH 64
+#define MAXDEPTH 256
#ifdef TRACE_MATCHER
#define TM 1
diff --git a/lib/skiplist.c b/lib/skiplist.c
index 7acc78f563..a546bb44c0 100644
--- a/lib/skiplist.c
+++ b/lib/skiplist.c
@@ -593,8 +593,8 @@ static void *scramble(int i)
{
uintptr_t result;
- result = (i & 0xff) << 24;
- result |= (i >> 8);
+ result = (unsigned)(i & 0xff) << 24;
+ result |= (unsigned)i >> 8;
return (void *)result;
}
diff --git a/lib/stream.c b/lib/stream.c
index 577fa257df..f88689f677 100644
--- a/lib/stream.c
+++ b/lib/stream.c
@@ -394,7 +394,7 @@ u_int32_t stream_getl_from(struct stream *s, size_t from)
return 0;
}
- l = s->data[from++] << 24;
+ l = (unsigned)(s->data[from++]) << 24;
l |= s->data[from++] << 16;
l |= s->data[from++] << 8;
l |= s->data[from];
@@ -426,7 +426,7 @@ u_int32_t stream_getl(struct stream *s)
return 0;
}
- l = s->data[s->getp++] << 24;
+ l = (unsigned)(s->data[s->getp++]) << 24;
l |= s->data[s->getp++] << 16;
l |= s->data[s->getp++] << 8;
l |= s->data[s->getp++];
diff --git a/lib/stream.h b/lib/stream.h
index 33dd64c4a3..7dcdca69f6 100644
--- a/lib/stream.h
+++ b/lib/stream.h
@@ -239,4 +239,22 @@ extern struct stream *stream_fifo_head(struct stream_fifo *fifo);
extern void stream_fifo_clean(struct stream_fifo *fifo);
extern void stream_fifo_free(struct stream_fifo *fifo);
+/* This is here because "<< 24" is particularly problematic in C.
+ * This is because the left operand of << is integer-promoted, which means
+ * an uint8_t gets converted into a *signed* int. Shifting into the sign
+ * bit of a signed int is theoretically undefined behaviour, so - the left
+ * operand needs to be cast to unsigned.
+ *
+ * This is not a problem for 16- or 8-bit values (they don't reach the sign
+ * bit), for 64-bit values (you need to cast them anyway), and neither for
+ * encoding (because it's downcasted.)
+ */
+static inline uint8_t *ptr_get_be32(uint8_t *ptr, uint32_t *out)
+{
+ uint32_t tmp;
+ memcpy(&tmp, ptr, sizeof(tmp));
+ *out = ntohl(tmp);
+ return ptr + 4;
+}
+
#endif /* _ZEBRA_STREAM_H */
diff --git a/ospf6d/ospf6_area.c b/ospf6d/ospf6_area.c
index 485937d882..b5584dc86d 100644
--- a/ospf6d/ospf6_area.c
+++ b/ospf6d/ospf6_area.c
@@ -642,6 +642,9 @@ void ospf6_area_plist_update(struct prefix_list *plist, int add)
struct listnode *n;
const char *name = prefix_list_name(plist);
+ if (!ospf6)
+ return;
+
for (ALL_LIST_ELEMENTS_RO(ospf6->area_list, n, oa)) {
if (PREFIX_NAME_IN(oa) && !strcmp(PREFIX_NAME_IN(oa), name))
PREFIX_LIST_IN(oa) = add ? plist : NULL;
diff --git a/ospfd/ospf_opaque.h b/ospfd/ospf_opaque.h
index 2470cd2e2b..9dc1f92f4d 100644
--- a/ospfd/ospf_opaque.h
+++ b/ospfd/ospf_opaque.h
@@ -46,7 +46,8 @@
#define GET_OPAQUE_ID(lsid) ((u_int32_t)(lsid)&LSID_OPAQUE_ID_MASK)
#define SET_OPAQUE_LSID(type, id) \
- ((((type) << 24) & LSID_OPAQUE_TYPE_MASK) | ((id)&LSID_OPAQUE_ID_MASK))
+ ((((unsigned)(type) << 24) & LSID_OPAQUE_TYPE_MASK) \
+ | ((id) & LSID_OPAQUE_ID_MASK))
/*
* Opaque LSA types will be assigned by IANA.
diff --git a/zebra/redistribute.c b/zebra/redistribute.c
index ce86b6c1e3..93bfc0c031 100644
--- a/zebra/redistribute.c
+++ b/zebra/redistribute.c
@@ -84,11 +84,13 @@ static void zebra_redistribute_default(struct zserv *client, vrf_id_t vrf_id)
if (!rn)
continue;
- RNODE_FOREACH_RE(rn, newre)
- if (CHECK_FLAG(newre->flags, ZEBRA_FLAG_SELECTED)
- && newre->distance != DISTANCE_INFINITY)
- zsend_redistribute_route(ZEBRA_REDISTRIBUTE_ROUTE_ADD,
- client, &rn->p, NULL, newre);
+ RNODE_FOREACH_RE(rn, newre) {
+ if (CHECK_FLAG(newre->flags, ZEBRA_FLAG_SELECTED)
+ && newre->distance != DISTANCE_INFINITY)
+ zsend_redistribute_route(
+ ZEBRA_REDISTRIBUTE_ROUTE_ADD,
+ client, &rn->p, NULL, newre);
+ }
route_unlock_node(rn);
}
diff --git a/zebra/zebra_mpls.c b/zebra/zebra_mpls.c
index 273945778a..e3ce414127 100644
--- a/zebra/zebra_mpls.c
+++ b/zebra/zebra_mpls.c
@@ -2392,15 +2392,20 @@ void mpls_ldp_ftn_uninstall_all(struct zebra_vrf *zvrf, int afi)
for (rn = route_top(table); rn; rn = route_next(rn)) {
update = 0;
- RNODE_FOREACH_RE(rn, re)
- for (nexthop = re->nexthop; nexthop; nexthop = nexthop->next)
- if (nexthop->nh_label_type == ZEBRA_LSP_LDP) {
+ RNODE_FOREACH_RE(rn, re) {
+ for (nexthop = re->nexthop;
+ nexthop;
+ nexthop = nexthop->next) {
+ if (nexthop->nh_label_type != ZEBRA_LSP_LDP)
+ continue;
+
nexthop_del_labels(nexthop);
SET_FLAG(re->status, ROUTE_ENTRY_CHANGED);
SET_FLAG(re->status,
ROUTE_ENTRY_LABELS_CHANGED);
update = 1;
}
+ }
if (update)
rib_queue_add(rn);
diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c
index f88e594a99..d04b64b19c 100644
--- a/zebra/zebra_rib.c
+++ b/zebra/zebra_rib.c
@@ -1134,7 +1134,6 @@ static int rib_can_delete_dest(rib_dest_t *dest)
int rib_gc_dest(struct route_node *rn)
{
rib_dest_t *dest;
- struct zebra_vrf *zvrf;
dest = rib_dest_from_rnode(rn);
if (!dest)
@@ -1143,9 +1142,12 @@ int rib_gc_dest(struct route_node *rn)
if (!rib_can_delete_dest(dest))
return 0;
- zvrf = rib_dest_vrf(dest);
- if (IS_ZEBRA_DEBUG_RIB)
+ if (IS_ZEBRA_DEBUG_RIB) {
+ struct zebra_vrf *zvrf;
+
+ zvrf = rib_dest_vrf(dest);
rnode_debug(rn, zvrf_id(zvrf), "removing dest from table");
+ }
dest->rnode = NULL;
XFREE(MTYPE_RIB_DEST, dest);
@@ -2567,27 +2569,29 @@ static void rib_update_table(struct route_table *table,
*/
RNODE_FOREACH_RE_SAFE(rn, re, next)
{
- if (re->type == ZEBRA_ROUTE_OSPF
- || re->type == ZEBRA_ROUTE_OSPF6
- || re->type == ZEBRA_ROUTE_BGP)
- continue; /* protocol will handle. */
- else if (re->type == ZEBRA_ROUTE_STATIC) {
- struct nexthop *nh;
- for (nh = re->nexthop; nh;
- nh = nh->next)
- if (!(nh->type
- == NEXTHOP_TYPE_IPV4
- || nh->type
- == NEXTHOP_TYPE_IPV6))
- break;
-
- /* If we only have nexthops to a
- * gateway, NHT will
- * take care.
- */
- if (nh)
- rib_queue_add(rn);
- } else
+ struct nexthop *nh;
+
+ if (re->type != ZEBRA_ROUTE_SYSTEM &&
+ re->type != ZEBRA_ROUTE_KERNEL &&
+ re->type != ZEBRA_ROUTE_CONNECT &&
+ re->type != ZEBRA_ROUTE_STATIC)
+ continue;
+
+ if (re->type != ZEBRA_ROUTE_STATIC) {
+ rib_queue_add(rn);
+ continue;
+ }
+
+ for (nh = re->nexthop; nh; nh = nh->next)
+ if (!(nh->type == NEXTHOP_TYPE_IPV4
+ || nh->type == NEXTHOP_TYPE_IPV6))
+ break;
+
+ /* If we only have nexthops to a
+ * gateway, NHT will
+ * take care.
+ */
+ if (nh)
rib_queue_add(rn);
}
break;
diff --git a/zebra/zebra_snmp.c b/zebra/zebra_snmp.c
index 4d6ba566ca..9ac24c53ed 100644
--- a/zebra/zebra_snmp.c
+++ b/zebra/zebra_snmp.c
@@ -155,8 +155,9 @@ static u_char *ipFwNumber(struct variable *v, oid objid[], size_t *objid_len,
/* Return number of routing entries. */
result = 0;
for (rn = route_top(table); rn; rn = route_next(rn))
- RNODE_FOREACH_RE(rn, re)
- result++;
+ RNODE_FOREACH_RE(rn, re) {
+ result++;
+ }
return (u_char *)&result;
}
@@ -182,8 +183,9 @@ static u_char *ipCidrNumber(struct variable *v, oid objid[], size_t *objid_len,
/* Return number of routing entries. */
result = 0;
for (rn = route_top(table); rn; rn = route_next(rn))
- RNODE_FOREACH_RE(rn, re)
- result++;
+ RNODE_FOREACH_RE(rn, re) {
+ result++;
+ }
return (u_char *)&result;
}
@@ -388,8 +390,9 @@ static void get_fwtable_route_node(struct variable *v, oid objid[],
/* Check destination first */
if (in_addr_cmp(&np2->p.u.prefix, (u_char *)&dest) > 0)
- RNODE_FOREACH_RE(np2, re2)
- check_replace(np2, re2, np, re);
+ RNODE_FOREACH_RE(np2, re2) {
+ check_replace(np2, re2, np, re);
+ }
if (in_addr_cmp(&np2->p.u.prefix, (u_char *)&dest)
== 0) { /* have to look at each re individually */
diff --git a/zebra/zebra_vrf.c b/zebra/zebra_vrf.c
index 0a26ac6ad7..62c7d020bc 100644
--- a/zebra/zebra_vrf.c
+++ b/zebra/zebra_vrf.c
@@ -290,8 +290,9 @@ static void zebra_rtable_node_cleanup(struct route_table *table,
{
struct route_entry *re, *next;
- RNODE_FOREACH_RE_SAFE(node, re, next)
- rib_unlink(node, re);
+ RNODE_FOREACH_RE_SAFE(node, re, next) {
+ rib_unlink(node, re);
+ }
if (node->info)
XFREE(MTYPE_RIB_DEST, node->info);
diff --git a/zebra/zserv.c b/zebra/zserv.c
index ef289f3960..61a75e156c 100644
--- a/zebra/zserv.c
+++ b/zebra/zserv.c
@@ -601,7 +601,7 @@ int zsend_redistribute_route(int cmd, struct zserv *client, struct prefix *p,
int count = 0;
memset(&api, 0, sizeof(api));
- api.vrf_id = VRF_DEFAULT;
+ api.vrf_id = re->vrf_id;
api.type = re->type;
api.instance = re->instance;
api.flags = re->flags;