summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/command.c6
-rw-r--r--lib/command_match.c4
-rw-r--r--lib/compiler.h23
-rw-r--r--lib/filter.c10
-rw-r--r--lib/frrlua.c100
-rw-r--r--lib/frrlua.h21
-rw-r--r--lib/frrscript.c18
-rw-r--r--lib/frrscript.h76
-rw-r--r--lib/prefix.c17
-rw-r--r--lib/prefix.h10
-rw-r--r--lib/sockunion.c3
-rw-r--r--lib/sockunion.h1
-rw-r--r--lib/table.c4
-rw-r--r--lib/zclient.c24
-rw-r--r--lib/zclient.h3
15 files changed, 240 insertions, 80 deletions
diff --git a/lib/command.c b/lib/command.c
index 560d4a09f8..9dac60599c 100644
--- a/lib/command.c
+++ b/lib/command.c
@@ -2428,14 +2428,16 @@ DEFUN(script,
struct prefix p;
(void)str2prefix("1.2.3.4/24", &p);
-
struct frrscript *fs = frrscript_load(argv[1]->arg, NULL);
if (fs == NULL) {
vty_out(vty, "Script '/etc/frr/scripts/%s.lua' not found\n",
argv[1]->arg);
} else {
- int ret = frrscript_call(fs, NULL);
+ int ret = frrscript_call(fs, ("p", &p));
+ char buf[40];
+ prefix2str(&p, buf, sizeof(buf));
+ vty_out(vty, "p: %s\n", buf);
vty_out(vty, "Script result: %d\n", ret);
}
diff --git a/lib/command_match.c b/lib/command_match.c
index e9e8466ffd..5703510148 100644
--- a/lib/command_match.c
+++ b/lib/command_match.c
@@ -813,7 +813,7 @@ static enum match_type match_ipv4_prefix(const char *str)
str++;
}
- if (atoi(sp) > 32)
+ if (atoi(sp) > IPV4_MAX_BITLEN)
return no_match;
return exact_match;
@@ -948,7 +948,7 @@ static enum match_type match_ipv6_prefix(const char *str, bool prefix)
if (*endptr != '\0')
return no_match;
- if (mask < 0 || mask > 128)
+ if (mask < 0 || mask > IPV6_MAX_BITLEN)
return no_match;
return exact_match;
diff --git a/lib/compiler.h b/lib/compiler.h
index 970ed297fc..bf443906eb 100644
--- a/lib/compiler.h
+++ b/lib/compiler.h
@@ -173,6 +173,29 @@ extern "C" {
#define MACRO_REPEAT(NAME, ...) \
MACRO_VARIANT(_MACRO_REPEAT, ##__VA_ARGS__)(NAME, ##__VA_ARGS__)
+/* per-arglist repeat macro, use like this:
+ * #define foo(...) MAP_LISTS(F, ##__VA_ARGS__)
+ * where F is a n-ary function where n is the number of args in each arglist.
+ * e.g.: MAP_LISTS(f, (a, b), (c, d))
+ * expands to: f(a, b); f(c, d)
+ */
+
+#define ESC(...) __VA_ARGS__
+#define MAP_LISTS(M, ...) \
+ _CONCAT(_MAP_LISTS_, PP_NARG(__VA_ARGS__))(M, ##__VA_ARGS__)
+#define _MAP_LISTS_0(M)
+#define _MAP_LISTS_1(M, _1) ESC(M _1)
+#define _MAP_LISTS_2(M, _1, _2) ESC(M _1; M _2)
+#define _MAP_LISTS_3(M, _1, _2, _3) ESC(M _1; M _2; M _3)
+#define _MAP_LISTS_4(M, _1, _2, _3, _4) ESC(M _1; M _2; M _3; M _4)
+#define _MAP_LISTS_5(M, _1, _2, _3, _4, _5) ESC(M _1; M _2; M _3; M _4; M _5)
+#define _MAP_LISTS_6(M, _1, _2, _3, _4, _5, _6) \
+ ESC(M _1; M _2; M _3; M _4; M _5; M _6)
+#define _MAP_LISTS_7(M, _1, _2, _3, _4, _5, _6, _7) \
+ ESC(M _1; M _2; M _3; M _4; M _5; M _6; M _7)
+#define _MAP_LISTS_8(M, _1, _2, _3, _4, _5, _6, _7, _8) \
+ ESC(M _1; M _2; M _3; M _4; M _5; M _6; M _7; M _8)
+
/*
* for warnings on macros, put in the macro content like this:
* #define MACRO BLA CPP_WARN("MACRO has been deprecated")
diff --git a/lib/filter.c b/lib/filter.c
index b7a935d076..72a66d85ad 100644
--- a/lib/filter.c
+++ b/lib/filter.c
@@ -108,10 +108,14 @@ static int filter_match_cisco(struct filter *mfilter, const struct prefix *p)
masklen2ip(p->prefixlen, &mask);
check_mask = mask.s_addr & ~filter->mask_mask.s_addr;
- if (memcmp(&check_addr, &filter->addr.s_addr, 4) == 0
- && memcmp(&check_mask, &filter->mask.s_addr, 4) == 0)
+ if (memcmp(&check_addr, &filter->addr.s_addr, IPV4_MAX_BYTELEN)
+ == 0
+ && memcmp(&check_mask, &filter->mask.s_addr,
+ IPV4_MAX_BYTELEN)
+ == 0)
return 1;
- } else if (memcmp(&check_addr, &filter->addr.s_addr, 4) == 0)
+ } else if (memcmp(&check_addr, &filter->addr.s_addr, IPV4_MAX_BYTELEN)
+ == 0)
return 1;
return 0;
diff --git a/lib/frrlua.c b/lib/frrlua.c
index d8aaa3aa3c..e97e48121c 100644
--- a/lib/frrlua.c
+++ b/lib/frrlua.c
@@ -52,10 +52,9 @@ int frrlua_table_get_integer(lua_State *L, const char *key)
}
/*
- * Encoders.
- *
* This section has functions that convert internal FRR datatypes into Lua
- * datatypes.
+ * datatypes: one encoder function and two decoder functions for each type.
+ *
*/
void lua_pushprefix(lua_State *L, const struct prefix *prefix)
@@ -71,14 +70,19 @@ void lua_pushprefix(lua_State *L, const struct prefix *prefix)
lua_setfield(L, -2, "family");
}
-void *lua_toprefix(lua_State *L, int idx)
+void lua_decode_prefix(lua_State *L, int idx, struct prefix *prefix)
{
- struct prefix *p = XCALLOC(MTYPE_TMP, sizeof(struct prefix));
-
lua_getfield(L, idx, "network");
- (void)str2prefix(lua_tostring(L, -1), p);
+ (void)str2prefix(lua_tostring(L, -1), prefix);
lua_pop(L, 1);
+ /* pop the table */
+ lua_pop(L, 1);
+}
+void *lua_toprefix(lua_State *L, int idx)
+{
+ struct prefix *p = XCALLOC(MTYPE_TMP, sizeof(struct prefix));
+ lua_decode_prefix(L, idx, p);
return p;
}
@@ -109,10 +113,8 @@ void lua_pushinterface(lua_State *L, const struct interface *ifp)
lua_setfield(L, -2, "linklayer_type");
}
-void *lua_tointerface(lua_State *L, int idx)
+void lua_decode_interface(lua_State *L, int idx, struct interface *ifp)
{
- struct interface *ifp = XCALLOC(MTYPE_TMP, sizeof(struct interface));
-
lua_getfield(L, idx, "name");
strlcpy(ifp->name, lua_tostring(L, -1), sizeof(ifp->name));
lua_pop(L, 1);
@@ -146,13 +148,21 @@ void *lua_tointerface(lua_State *L, int idx)
lua_getfield(L, idx, "linklayer_type");
ifp->ll_type = lua_tointeger(L, -1);
lua_pop(L, 1);
+ /* pop the table */
+ lua_pop(L, 1);
+}
+void *lua_tointerface(lua_State *L, int idx)
+{
+ struct interface *ifp = XCALLOC(MTYPE_TMP, sizeof(struct interface));
+ lua_decode_interface(L, idx, ifp);
return ifp;
}
void lua_pushinaddr(lua_State *L, const struct in_addr *addr)
{
char buf[INET_ADDRSTRLEN];
+
inet_ntop(AF_INET, addr, buf, sizeof(buf));
lua_newtable(L);
@@ -162,14 +172,19 @@ void lua_pushinaddr(lua_State *L, const struct in_addr *addr)
lua_setfield(L, -2, "string");
}
-void *lua_toinaddr(lua_State *L, int idx)
+void lua_decode_inaddr(lua_State *L, int idx, struct in_addr *inaddr)
{
- struct in_addr *inaddr = XCALLOC(MTYPE_TMP, sizeof(struct in_addr));
-
lua_getfield(L, idx, "value");
inaddr->s_addr = lua_tointeger(L, -1);
lua_pop(L, 1);
+ /* pop the table */
+ lua_pop(L, 1);
+}
+void *lua_toinaddr(lua_State *L, int idx)
+{
+ struct in_addr *inaddr = XCALLOC(MTYPE_TMP, sizeof(struct in_addr));
+ lua_decode_inaddr(L, idx, inaddr);
return inaddr;
}
@@ -177,6 +192,7 @@ void *lua_toinaddr(lua_State *L, int idx)
void lua_pushin6addr(lua_State *L, const struct in6_addr *addr)
{
char buf[INET6_ADDRSTRLEN];
+
inet_ntop(AF_INET6, addr, buf, sizeof(buf));
lua_newtable(L);
@@ -186,20 +202,26 @@ void lua_pushin6addr(lua_State *L, const struct in6_addr *addr)
lua_setfield(L, -2, "string");
}
-void *lua_toin6addr(lua_State *L, int idx)
+void lua_decode_in6addr(lua_State *L, int idx, struct in6_addr *in6addr)
{
- struct in6_addr *in6addr = XCALLOC(MTYPE_TMP, sizeof(struct in6_addr));
-
lua_getfield(L, idx, "string");
inet_pton(AF_INET6, lua_tostring(L, -1), in6addr);
lua_pop(L, 1);
+ /* pop the table */
+ lua_pop(L, 1);
+}
+void *lua_toin6addr(lua_State *L, int idx)
+{
+ struct in6_addr *in6addr = XCALLOC(MTYPE_TMP, sizeof(struct in6_addr));
+ lua_decode_in6addr(L, idx, in6addr);
return in6addr;
}
void lua_pushsockunion(lua_State *L, const union sockunion *su)
{
char buf[SU_ADDRSTRLEN];
+
sockunion2str(su, buf, sizeof(buf));
lua_newtable(L);
@@ -210,13 +232,20 @@ void lua_pushsockunion(lua_State *L, const union sockunion *su)
lua_setfield(L, -2, "string");
}
-void *lua_tosockunion(lua_State *L, int idx)
+void lua_decode_sockunion(lua_State *L, int idx, union sockunion *su)
{
- union sockunion *su = XCALLOC(MTYPE_TMP, sizeof(union sockunion));
-
lua_getfield(L, idx, "string");
str2sockunion(lua_tostring(L, -1), su);
+ lua_pop(L, 1);
+ /* pop the table */
+ lua_pop(L, 1);
+}
+
+void *lua_tosockunion(lua_State *L, int idx)
+{
+ union sockunion *su = XCALLOC(MTYPE_TMP, sizeof(union sockunion));
+ lua_decode_sockunion(L, idx, su);
return su;
}
@@ -225,12 +254,17 @@ void lua_pushtimet(lua_State *L, const time_t *time)
lua_pushinteger(L, *time);
}
+void lua_decode_timet(lua_State *L, int idx, time_t *t)
+{
+ *t = lua_tointeger(L, idx);
+ lua_pop(L, 1);
+}
+
void *lua_totimet(lua_State *L, int idx)
{
time_t *t = XCALLOC(MTYPE_TMP, sizeof(time_t));
- *t = lua_tointeger(L, idx);
-
+ lua_decode_timet(L, idx, t);
return t;
}
@@ -239,17 +273,28 @@ void lua_pushintegerp(lua_State *L, const long long *num)
lua_pushinteger(L, *num);
}
-void *lua_tointegerp(lua_State *L, int idx)
+void lua_decode_integerp(lua_State *L, int idx, long long *num)
{
int isnum;
- long long *num = XCALLOC(MTYPE_TMP, sizeof(long long));
-
*num = lua_tonumberx(L, idx, &isnum);
+ lua_pop(L, 1);
assert(isnum);
+}
+
+void *lua_tointegerp(lua_State *L, int idx)
+{
+ long long *num = XCALLOC(MTYPE_TMP, sizeof(long long));
+ lua_decode_integerp(L, idx, num);
return num;
}
+void lua_decode_stringp(lua_State *L, int idx, char *str)
+{
+ strlcpy(str, lua_tostring(L, idx), strlen(str) + 1);
+ lua_pop(L, 1);
+}
+
void *lua_tostringp(lua_State *L, int idx)
{
char *string = XSTRDUP(MTYPE_TMP, lua_tostring(L, idx));
@@ -258,6 +303,13 @@ void *lua_tostringp(lua_State *L, int idx)
}
/*
+ * Decoder for const values, since we cannot modify them.
+ */
+void lua_decode_noop(lua_State *L, int idx, const void *ptr)
+{
+}
+
+/*
* Logging.
*
* Lua-compatible wrappers for FRR logging functions.
diff --git a/lib/frrlua.h b/lib/frrlua.h
index 6fb30938b0..c4de82740c 100644
--- a/lib/frrlua.h
+++ b/lib/frrlua.h
@@ -50,6 +50,8 @@ static inline void lua_pushstring_wrapper(lua_State *L, const char *str)
*/
void lua_pushprefix(lua_State *L, const struct prefix *prefix);
+void lua_decode_prefix(lua_State *L, int idx, struct prefix *prefix);
+
/*
* Converts the Lua value at idx to a prefix.
*
@@ -63,6 +65,8 @@ void *lua_toprefix(lua_State *L, int idx);
*/
void lua_pushinterface(lua_State *L, const struct interface *ifp);
+void lua_decode_interface(lua_State *L, int idx, struct interface *ifp);
+
/*
* Converts the Lua value at idx to an interface.
*
@@ -77,6 +81,8 @@ void *lua_tointerface(lua_State *L, int idx);
*/
void lua_pushinaddr(lua_State *L, const struct in_addr *addr);
+void lua_decode_inaddr(lua_State *L, int idx, struct in_addr *addr);
+
/*
* Converts the Lua value at idx to an in_addr.
*
@@ -90,6 +96,8 @@ void *lua_toinaddr(lua_State *L, int idx);
*/
void lua_pushin6addr(lua_State *L, const struct in6_addr *addr);
+void lua_decode_in6addr(lua_State *L, int idx, struct in6_addr *addr);
+
/*
* Converts the Lua value at idx to an in6_addr.
*
@@ -103,6 +111,8 @@ void *lua_toin6addr(lua_State *L, int idx);
*/
void lua_pushtimet(lua_State *L, const time_t *time);
+void lua_decode_timet(lua_State *L, int idx, time_t *time);
+
/*
* Converts the Lua value at idx to a time_t.
*
@@ -116,6 +126,8 @@ void *lua_totimet(lua_State *L, int idx);
*/
void lua_pushsockunion(lua_State *L, const union sockunion *su);
+void lua_decode_sockunion(lua_State *L, int idx, union sockunion *su);
+
/*
* Converts the Lua value at idx to a sockunion.
*
@@ -129,6 +141,8 @@ void *lua_tosockunion(lua_State *L, int idx);
*/
void lua_pushintegerp(lua_State *L, const long long *num);
+void lua_decode_integerp(lua_State *L, int idx, long long *num);
+
/*
* Converts the Lua value at idx to an int.
*
@@ -137,6 +151,8 @@ void lua_pushintegerp(lua_State *L, const long long *num);
*/
void *lua_tointegerp(lua_State *L, int idx);
+void lua_decode_stringp(lua_State *L, int idx, char *str);
+
/*
* Pop string.
*
@@ -146,6 +162,11 @@ void *lua_tointegerp(lua_State *L, int idx);
void *lua_tostringp(lua_State *L, int idx);
/*
+ * No-op decocder
+ */
+void lua_decode_noop(lua_State *L, int idx, const void *ptr);
+
+/*
* Retrieve an integer from table on the top of the stack.
*
* key
diff --git a/lib/frrscript.c b/lib/frrscript.c
index 10d400886d..1a9f3639dd 100644
--- a/lib/frrscript.c
+++ b/lib/frrscript.c
@@ -104,24 +104,8 @@ static void codec_free(struct codec *c)
/* Generic script APIs */
-int frrscript_call(struct frrscript *fs, struct frrscript_env *env)
+int _frrscript_call(struct frrscript *fs)
{
- struct frrscript_codec c = {};
- const void *arg;
- const char *bindname;
-
- /* Encode script arguments */
- for (int i = 0; env && env[i].val != NULL; i++) {
- bindname = env[i].name;
- c.typename = env[i].typename;
- arg = env[i].val;
-
- struct frrscript_codec *codec = hash_lookup(codec_hash, &c);
- assert(codec && "No encoder for type");
- codec->encoder(fs->L, arg);
-
- lua_setglobal(fs->L, bindname);
- }
int ret = lua_pcall(fs->L, 0, 0, 0);
diff --git a/lib/frrscript.h b/lib/frrscript.h
index f4057f531b..8612c602f3 100644
--- a/lib/frrscript.h
+++ b/lib/frrscript.h
@@ -25,6 +25,7 @@
#include <lua.h>
#include "frrlua.h"
+#include "../bgpd/bgp_script.h"
#ifdef __cplusplus
extern "C" {
@@ -96,6 +97,56 @@ void frrscript_register_type_codecs(struct frrscript_codec *codecs);
*/
void frrscript_init(const char *scriptdir);
+#define ENCODE_ARGS(name, value) \
+ do { \
+ ENCODE_ARGS_WITH_STATE(L, value); \
+ lua_setglobal(L, name); \
+ } while (0)
+
+#define DECODE_ARGS(name, value) \
+ do { \
+ lua_getglobal(L, name); \
+ DECODE_ARGS_WITH_STATE(L, value); \
+ } while (0)
+
+/*
+ * Maps the type of value to its encoder/decoder.
+ * Add new mappings here.
+ *
+ * L
+ * Lua state
+ * scriptdir
+ * Directory in which to look for scripts
+ */
+#define ENCODE_ARGS_WITH_STATE(L, value) \
+ _Generic((value), \
+long long * : lua_pushintegerp, \
+struct prefix * : lua_pushprefix, \
+struct interface * : lua_pushinterface, \
+struct in_addr * : lua_pushinaddr, \
+struct in6_addr * : lua_pushin6addr, \
+union sockunion * : lua_pushsockunion, \
+time_t * : lua_pushtimet, \
+char * : lua_pushstring_wrapper, \
+struct attr * : lua_pushattr, \
+struct peer * : lua_pushpeer, \
+const struct prefix * : lua_pushprefix \
+)(L, value)
+
+#define DECODE_ARGS_WITH_STATE(L, value) \
+ _Generic((value), \
+long long * : lua_decode_integerp, \
+struct prefix * : lua_decode_prefix, \
+struct interface * : lua_decode_interface, \
+struct in_addr * : lua_decode_inaddr, \
+struct in6_addr * : lua_decode_in6addr, \
+union sockunion * : lua_decode_sockunion, \
+time_t * : lua_decode_timet, \
+char * : lua_decode_stringp, \
+struct attr * : lua_decode_attr, \
+struct peer * : lua_decode_noop, \
+const struct prefix * : lua_decode_noop \
+)(L, -1, value)
/*
* Call script.
@@ -103,14 +154,31 @@ void frrscript_init(const char *scriptdir);
* fs
* The script to call; this is obtained from frrscript_load().
*
- * env
- * The script's environment. Specify this as an array of frrscript_env.
- *
* Returns:
* 0 if the script ran successfully, nonzero otherwise.
*/
-int frrscript_call(struct frrscript *fs, struct frrscript_env *env);
+int _frrscript_call(struct frrscript *fs);
+/*
+ * Wrapper for call script. Maps values passed in to their encoder
+ * and decoder types.
+ *
+ * fs
+ * The script to call; this is obtained from frrscript_load().
+ *
+ * Returns:
+ * 0 if the script ran successfully, nonzero otherwise.
+ */
+#define frrscript_call(fs, ...) \
+ ({ \
+ lua_State *L = fs->L; \
+ MAP_LISTS(ENCODE_ARGS, ##__VA_ARGS__); \
+ int ret = _frrscript_call(fs); \
+ if (ret == 0) { \
+ MAP_LISTS(DECODE_ARGS, ##__VA_ARGS__); \
+ } \
+ ret; \
+ })
/*
* Get result from finished script.
diff --git a/lib/prefix.c b/lib/prefix.c
index 370c8dc067..ef7d2e59da 100644
--- a/lib/prefix.c
+++ b/lib/prefix.c
@@ -577,7 +577,7 @@ int str2prefix_ipv4(const char *str, struct prefix_ipv4 *p)
/* Get prefix length. */
plen = (uint8_t)atoi(++pnt);
- if (plen > IPV4_MAX_PREFIXLEN)
+ if (plen > IPV4_MAX_BITLEN)
return 0;
p->family = AF_INET;
@@ -1129,7 +1129,7 @@ void apply_classful_mask_ipv4(struct prefix_ipv4 *p)
destination = ntohl(p->prefix.s_addr);
- if (p->prefixlen == IPV4_MAX_PREFIXLEN)
+ if (p->prefixlen == IPV4_MAX_BITLEN)
;
/* do nothing for host routes */
else if (IN_CLASSC(destination)) {
@@ -1149,12 +1149,13 @@ in_addr_t ipv4_broadcast_addr(in_addr_t hostaddr, int masklen)
struct in_addr mask;
masklen2ip(masklen, &mask);
- return (masklen != IPV4_MAX_PREFIXLEN - 1) ?
- /* normal case */
- (hostaddr | ~mask.s_addr)
- :
- /* For prefix 31 return 255.255.255.255 (RFC3021) */
- htonl(0xFFFFFFFF);
+ return (masklen != IPV4_MAX_BITLEN - 1)
+ ?
+ /* normal case */
+ (hostaddr | ~mask.s_addr)
+ :
+ /* For prefix 31 return 255.255.255.255 (RFC3021) */
+ htonl(0xFFFFFFFF);
}
/* Utility function to convert ipv4 netmask to prefixes
diff --git a/lib/prefix.h b/lib/prefix.h
index 217a23d561..bc4cb7f441 100644
--- a/lib/prefix.h
+++ b/lib/prefix.h
@@ -372,7 +372,6 @@ union prefixconstptr {
/* Max bit/byte length of IPv4 address. */
#define IPV4_MAX_BYTELEN 4
#define IPV4_MAX_BITLEN 32
-#define IPV4_MAX_PREFIXLEN 32
#define IPV4_ADDR_CMP(D,S) memcmp ((D), (S), IPV4_MAX_BYTELEN)
static inline bool ipv4_addr_same(const struct in_addr *a,
@@ -398,7 +397,6 @@ static inline void ipv4_addr_copy(struct in_addr *dst,
/* Max bit/byte length of IPv6 address. */
#define IPV6_MAX_BYTELEN 16
#define IPV6_MAX_BITLEN 128
-#define IPV6_MAX_PREFIXLEN 128
#define IPV6_ADDR_CMP(D,S) memcmp ((D), (S), IPV6_MAX_BYTELEN)
#define IPV6_ADDR_SAME(D,S) (memcmp ((D), (S), IPV6_MAX_BYTELEN) == 0)
#define IPV6_ADDR_COPY(D,S) memcpy ((D), (S), IPV6_MAX_BYTELEN)
@@ -481,11 +479,6 @@ extern void prefix_ipv4_free(struct prefix_ipv4 **p);
extern int str2prefix_ipv4(const char *, struct prefix_ipv4 *);
extern void apply_mask_ipv4(struct prefix_ipv4 *);
-#define PREFIX_COPY(DST, SRC) \
- *((struct prefix *)(DST)) = *((const struct prefix *)(SRC))
-#define PREFIX_COPY_IPV4(DST, SRC) \
- *((struct prefix_ipv4 *)(DST)) = *((const struct prefix_ipv4 *)(SRC))
-
extern int prefix_ipv4_any(const struct prefix_ipv4 *);
extern void apply_classful_mask_ipv4(struct prefix_ipv4 *);
@@ -503,9 +496,6 @@ extern void prefix_ipv6_free(struct prefix_ipv6 **p);
extern int str2prefix_ipv6(const char *, struct prefix_ipv6 *);
extern void apply_mask_ipv6(struct prefix_ipv6 *);
-#define PREFIX_COPY_IPV6(DST, SRC) \
- *((struct prefix_ipv6 *)(DST)) = *((const struct prefix_ipv6 *)(SRC))
-
extern int ip6_masklen(struct in6_addr);
extern void masklen2ip6(const int, struct in6_addr *);
diff --git a/lib/sockunion.c b/lib/sockunion.c
index e6340a1743..c7af458e9e 100644
--- a/lib/sockunion.c
+++ b/lib/sockunion.c
@@ -606,8 +606,7 @@ static void __attribute__((unused)) sockunion_print(const union sockunion *su)
}
}
-static int in6addr_cmp(const struct in6_addr *addr1,
- const struct in6_addr *addr2)
+int in6addr_cmp(const struct in6_addr *addr1, const struct in6_addr *addr2)
{
unsigned int i;
const uint8_t *p1, *p2;
diff --git a/lib/sockunion.h b/lib/sockunion.h
index 2cc80bb70f..9e6719ccf9 100644
--- a/lib/sockunion.h
+++ b/lib/sockunion.h
@@ -73,6 +73,7 @@ enum connect_result { connect_error, connect_success, connect_in_progress };
/* Prototypes. */
extern int str2sockunion(const char *, union sockunion *);
extern const char *sockunion2str(const union sockunion *, char *, size_t);
+int in6addr_cmp(const struct in6_addr *addr1, const struct in6_addr *addr2);
extern int sockunion_cmp(const union sockunion *, const union sockunion *);
extern int sockunion_same(const union sockunion *, const union sockunion *);
extern unsigned int sockunion_hash(const union sockunion *);
diff --git a/lib/table.c b/lib/table.c
index dfd92c6189..e6030ca4ca 100644
--- a/lib/table.c
+++ b/lib/table.c
@@ -230,7 +230,7 @@ struct route_node *route_node_match_ipv4(struct route_table *table,
memset(&p, 0, sizeof(struct prefix_ipv4));
p.family = AF_INET;
- p.prefixlen = IPV4_MAX_PREFIXLEN;
+ p.prefixlen = IPV4_MAX_BITLEN;
p.prefix = *addr;
return route_node_match(table, (struct prefix *)&p);
@@ -243,7 +243,7 @@ struct route_node *route_node_match_ipv6(struct route_table *table,
memset(&p, 0, sizeof(struct prefix_ipv6));
p.family = AF_INET6;
- p.prefixlen = IPV6_MAX_PREFIXLEN;
+ p.prefixlen = IPV6_MAX_BITLEN;
p.prefix = *addr;
return route_node_match(table, &p);
diff --git a/lib/zclient.c b/lib/zclient.c
index 195ec589d3..dc83227659 100644
--- a/lib/zclient.c
+++ b/lib/zclient.c
@@ -446,7 +446,7 @@ enum zclient_send_status zclient_send_localsid(struct zclient *zclient,
struct nexthop nh = {};
p.family = AF_INET6;
- p.prefixlen = 128;
+ p.prefixlen = IPV6_MAX_BITLEN;
p.prefix = *sid;
api.vrf_id = VRF_DEFAULT;
@@ -1432,7 +1432,7 @@ int zapi_route_decode(struct stream *s, struct zapi_route *api)
STREAM_GETC(s, api->prefix.prefixlen);
switch (api->prefix.family) {
case AF_INET:
- if (api->prefix.prefixlen > IPV4_MAX_PREFIXLEN) {
+ if (api->prefix.prefixlen > IPV4_MAX_BITLEN) {
flog_err(
EC_LIB_ZAPI_ENCODE,
"%s: V4 prefixlen is %d which should not be more than 32",
@@ -1441,7 +1441,7 @@ int zapi_route_decode(struct stream *s, struct zapi_route *api)
}
break;
case AF_INET6:
- if (api->prefix.prefixlen > IPV6_MAX_PREFIXLEN) {
+ if (api->prefix.prefixlen > IPV6_MAX_BITLEN) {
flog_err(
EC_LIB_ZAPI_ENCODE,
"%s: v6 prefixlen is %d which should not be more than 128",
@@ -1460,7 +1460,7 @@ int zapi_route_decode(struct stream *s, struct zapi_route *api)
if (CHECK_FLAG(api->message, ZAPI_MESSAGE_SRCPFX)) {
api->src_prefix.family = AF_INET6;
STREAM_GETC(s, api->src_prefix.prefixlen);
- if (api->src_prefix.prefixlen > IPV6_MAX_PREFIXLEN) {
+ if (api->src_prefix.prefixlen > IPV6_MAX_BITLEN) {
flog_err(
EC_LIB_ZAPI_ENCODE,
"%s: SRC Prefix prefixlen received: %d is too large",
@@ -2269,10 +2269,13 @@ stream_failure:
}
struct interface *zebra_interface_link_params_read(struct stream *s,
- vrf_id_t vrf_id)
+ vrf_id_t vrf_id,
+ bool *changed)
{
struct if_link_params *iflp;
+ struct if_link_params iflp_copy;
ifindex_t ifindex;
+ bool params_changed = false;
STREAM_GETL(s, ifindex);
@@ -2285,12 +2288,23 @@ struct interface *zebra_interface_link_params_read(struct stream *s,
return NULL;
}
+ if (ifp->link_params == NULL)
+ params_changed = true;
+
if ((iflp = if_link_params_get(ifp)) == NULL)
return NULL;
+ memcpy(&iflp_copy, iflp, sizeof(iflp_copy));
+
if (link_params_set_value(s, iflp) != 0)
goto stream_failure;
+ if (memcmp(&iflp_copy, iflp, sizeof(iflp_copy)))
+ params_changed = true;
+
+ if (changed)
+ *changed = params_changed;
+
return ifp;
stream_failure:
diff --git a/lib/zclient.h b/lib/zclient.h
index 48de3425be..a25c5800b7 100644
--- a/lib/zclient.h
+++ b/lib/zclient.h
@@ -1043,7 +1043,8 @@ extern struct interface *zebra_interface_vrf_update_read(struct stream *s,
extern int zebra_router_id_update_read(struct stream *s, struct prefix *rid);
extern struct interface *zebra_interface_link_params_read(struct stream *s,
- vrf_id_t vrf_id);
+ vrf_id_t vrf_id,
+ bool *changed);
extern size_t zebra_interface_link_params_write(struct stream *,
struct interface *);
extern enum zclient_send_status