summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/getopt.h2
-rw-r--r--lib/if.c7
-rw-r--r--lib/mlag.c28
-rw-r--r--lib/mlag.h9
-rw-r--r--lib/routemap_northbound.c3
-rw-r--r--lib/seqlock.c4
-rw-r--r--lib/skiplist.c12
-rw-r--r--lib/stream.h2
-rw-r--r--lib/systemd.c4
9 files changed, 44 insertions, 27 deletions
diff --git a/lib/getopt.h b/lib/getopt.h
index 138870d199..63e12e947e 100644
--- a/lib/getopt.h
+++ b/lib/getopt.h
@@ -111,7 +111,7 @@ struct option {
#if defined(__STDC__) && __STDC__
-#if REALLY_NEED_PLAIN_GETOPT
+#ifdef REALLY_NEED_PLAIN_GETOPT
/*
* getopt is defined in POSIX.2. Assume that if the system defines
diff --git a/lib/if.c b/lib/if.c
index 5edb58a2de..dabf66799d 100644
--- a/lib/if.c
+++ b/lib/if.c
@@ -887,11 +887,8 @@ void connected_free(struct connected **connected)
{
struct connected *ptr = *connected;
- if (ptr->address)
- prefix_free(&ptr->address);
-
- if (ptr->destination)
- prefix_free(&ptr->destination);
+ prefix_free(&ptr->address);
+ prefix_free(&ptr->destination);
XFREE(MTYPE_CONNECTED_LABEL, ptr->label);
diff --git a/lib/mlag.c b/lib/mlag.c
index 1daf290725..733dd41ea8 100644
--- a/lib/mlag.c
+++ b/lib/mlag.c
@@ -81,22 +81,33 @@ char *mlag_lib_msgid_to_str(enum mlag_msg_type msg_type, char *buf, size_t size)
}
-int mlag_lib_decode_mlag_hdr(struct stream *s, struct mlag_msg *msg)
+int mlag_lib_decode_mlag_hdr(struct stream *s, struct mlag_msg *msg,
+ size_t *length)
{
- if (s == NULL || msg == NULL)
+#define LIB_MLAG_HDR_LENGTH 8
+ *length = stream_get_endp(s);
+
+ if (s == NULL || msg == NULL || *length < LIB_MLAG_HDR_LENGTH)
return -1;
+ *length -= LIB_MLAG_HDR_LENGTH;
+
STREAM_GETL(s, msg->msg_type);
STREAM_GETW(s, msg->data_len);
STREAM_GETW(s, msg->msg_cnt);
+
return 0;
stream_failure:
return -1;
}
-int mlag_lib_decode_mroute_add(struct stream *s, struct mlag_mroute_add *msg)
+#define MLAG_MROUTE_ADD_LENGTH \
+ (VRF_NAMSIZ + INTERFACE_NAMSIZ + 4 + 4 + 4 + 4 + 1 + 1 + 4)
+
+int mlag_lib_decode_mroute_add(struct stream *s, struct mlag_mroute_add *msg,
+ size_t *length)
{
- if (s == NULL || msg == NULL)
+ if (s == NULL || msg == NULL || *length < MLAG_MROUTE_ADD_LENGTH)
return -1;
STREAM_GET(msg->vrf_name, s, VRF_NAMSIZ);
@@ -108,14 +119,18 @@ int mlag_lib_decode_mroute_add(struct stream *s, struct mlag_mroute_add *msg)
STREAM_GETC(s, msg->am_i_dual_active);
STREAM_GETL(s, msg->vrf_id);
STREAM_GET(msg->intf_name, s, INTERFACE_NAMSIZ);
+
return 0;
stream_failure:
return -1;
}
-int mlag_lib_decode_mroute_del(struct stream *s, struct mlag_mroute_del *msg)
+#define MLAG_MROUTE_DEL_LENGTH (VRF_NAMSIZ + INTERFACE_NAMSIZ + 4 + 4 + 4 + 4)
+
+int mlag_lib_decode_mroute_del(struct stream *s, struct mlag_mroute_del *msg,
+ size_t *length)
{
- if (s == NULL || msg == NULL)
+ if (s == NULL || msg == NULL || *length < MLAG_MROUTE_DEL_LENGTH)
return -1;
STREAM_GET(msg->vrf_name, s, VRF_NAMSIZ);
@@ -124,6 +139,7 @@ int mlag_lib_decode_mroute_del(struct stream *s, struct mlag_mroute_del *msg)
STREAM_GETL(s, msg->owner_id);
STREAM_GETL(s, msg->vrf_id);
STREAM_GET(msg->intf_name, s, INTERFACE_NAMSIZ);
+
return 0;
stream_failure:
return -1;
diff --git a/lib/mlag.h b/lib/mlag.h
index c531fb5b68..37bb3aa6db 100644
--- a/lib/mlag.h
+++ b/lib/mlag.h
@@ -125,11 +125,14 @@ struct mlag_msg {
extern char *mlag_role2str(enum mlag_role role, char *buf, size_t size);
extern char *mlag_lib_msgid_to_str(enum mlag_msg_type msg_type, char *buf,
size_t size);
-extern int mlag_lib_decode_mlag_hdr(struct stream *s, struct mlag_msg *msg);
+extern int mlag_lib_decode_mlag_hdr(struct stream *s, struct mlag_msg *msg,
+ size_t *length);
extern int mlag_lib_decode_mroute_add(struct stream *s,
- struct mlag_mroute_add *msg);
+ struct mlag_mroute_add *msg,
+ size_t *length);
extern int mlag_lib_decode_mroute_del(struct stream *s,
- struct mlag_mroute_del *msg);
+ struct mlag_mroute_del *msg,
+ size_t *length);
extern int mlag_lib_decode_mlag_status(struct stream *s,
struct mlag_status *msg);
extern int mlag_lib_decode_vxlan_update(struct stream *s,
diff --git a/lib/routemap_northbound.c b/lib/routemap_northbound.c
index 2d04a3d65c..69cebbd2a1 100644
--- a/lib/routemap_northbound.c
+++ b/lib/routemap_northbound.c
@@ -221,8 +221,7 @@ static int lib_route_map_entry_description_modify(enum nb_event event,
break;
case NB_EV_APPLY:
rmi = nb_running_get_entry(dnode, NULL, true);
- if (rmi->description != NULL)
- XFREE(MTYPE_TMP, rmi->description);
+ XFREE(MTYPE_TMP, rmi->description);
rmi->description = resource->ptr;
break;
}
diff --git a/lib/seqlock.c b/lib/seqlock.c
index 588a1175bc..77673146ea 100644
--- a/lib/seqlock.c
+++ b/lib/seqlock.c
@@ -165,7 +165,7 @@ bool seqlock_timedwait(struct seqlock *sqlo, seqlock_val_t val,
/*
* ABS_REALTIME - used on NetBSD, Solaris and OSX
*/
-#if TIME_ABS_REALTIME
+#ifdef TIME_ABS_REALTIME
#define time_arg1 &abs_rt
#define time_arg2 NULL
#define time_prep
@@ -187,7 +187,7 @@ bool seqlock_timedwait(struct seqlock *sqlo, seqlock_val_t val,
/*
* RELATIVE - used on OpenBSD (might get a patch to get absolute monotime)
*/
-#elif TIME_RELATIVE
+#elif defined(TIME_RELATIVE)
struct timespec reltime;
#define time_arg1 abs_monotime_limit
diff --git a/lib/skiplist.c b/lib/skiplist.c
index 67cc1ab378..d955c6eb9e 100644
--- a/lib/skiplist.c
+++ b/lib/skiplist.c
@@ -211,12 +211,12 @@ int skiplist_insert(register struct skiplist *l, register void *key,
q = newNodeOfLevel(k);
q->key = key;
q->value = value;
-#if SKIPLIST_0TIMER_DEBUG
+#ifdef SKIPLIST_0TIMER_DEBUG
q->flags = SKIPLIST_NODE_FLAG_INSERTED; /* debug */
#endif
++(l->stats->forward[k]);
-#if SKIPLIST_DEBUG
+#ifdef SKIPLIST_DEBUG
zlog_debug("%s: incremented stats @%p:%d, now %ld", __func__, l, k,
l->stats->forward[k] - (struct skiplistnode *)NULL);
#endif
@@ -281,7 +281,7 @@ int skiplist_delete(register struct skiplist *l, register void *key,
/*
* found node to delete
*/
-#if SKIPLIST_0TIMER_DEBUG
+#ifdef SKIPLIST_0TIMER_DEBUG
q->flags &= ~SKIPLIST_NODE_FLAG_INSERTED;
#endif
/*
@@ -300,7 +300,7 @@ int skiplist_delete(register struct skiplist *l, register void *key,
p->forward[k] = q->forward[k];
}
--(l->stats->forward[k - 1]);
-#if SKIPLIST_DEBUG
+#ifdef SKIPLIST_DEBUG
zlog_debug("%s: decremented stats @%p:%d, now %ld",
__func__, l, k - 1,
l->stats->forward[k - 1]
@@ -549,7 +549,7 @@ int skiplist_delete_first(register struct skiplist *l)
}
}
-#if SKIPLIST_0TIMER_DEBUG
+#ifdef SKIPLIST_0TIMER_DEBUG
q->flags &= ~SKIPLIST_NODE_FLAG_INSERTED;
#endif
/*
@@ -561,7 +561,7 @@ int skiplist_delete_first(register struct skiplist *l)
}
--(l->stats->forward[nodelevel]);
-#if SKIPLIST_DEBUG
+#ifdef SKIPLIST_DEBUG
zlog_debug("%s: decremented stats @%p:%d, now %ld", __func__, l,
nodelevel,
l->stats->forward[nodelevel] - (struct skiplistnode *)NULL);
diff --git a/lib/stream.h b/lib/stream.h
index c0d25e0579..36c65afa3c 100644
--- a/lib/stream.h
+++ b/lib/stream.h
@@ -110,7 +110,7 @@ struct stream {
size_t getp; /* next get position */
size_t endp; /* last valid data position */
size_t size; /* size of data segment */
- unsigned char data[0]; /* data pointer */
+ unsigned char data[]; /* data pointer */
};
/* First in first out queue structure. */
diff --git a/lib/systemd.c b/lib/systemd.c
index 81b0400ab9..c5cc3aa447 100644
--- a/lib/systemd.c
+++ b/lib/systemd.c
@@ -114,8 +114,10 @@ void systemd_send_started(struct thread_master *m, int the_process)
systemd_master = m;
systemd_send_information("READY=1");
- if (wsecs != 0)
+ if (wsecs != 0) {
+ systemd_send_information("WATCHDOG=1");
thread_add_timer(m, systemd_send_watchdog, m, wsecs, NULL);
+ }
}
void systemd_send_status(const char *status)