summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAnuradha Karuppiah <anuradhak@cumulusnetworks.com>2019-03-19 19:36:41 +0100
committerAnuradha Karuppiah <anuradhak@cumulusnetworks.com>2019-04-20 17:33:20 +0200
commitc6b6b53b294ae37e35f802769a6da21a88f63e18 (patch)
tree32d383a4c109206d71d609d8c9916a44ea21dfda /lib
parentzebra: install flood FDB entry only if the remote VTEP asked for HER (diff)
downloadfrr-c6b6b53b294ae37e35f802769a6da21a88f63e18.tar.xz
frr-c6b6b53b294ae37e35f802769a6da21a88f63e18.zip
lib: move SG prefix2str APIs from pimd to lib
This is to allow zebra to use these APIs instead of re-defining. Signed-off-by: Anuradha Karuppiah <anuradhak@cumulusnetworks.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/prefix.c29
-rw-r--r--lib/prefix.h12
2 files changed, 41 insertions, 0 deletions
diff --git a/lib/prefix.c b/lib/prefix.c
index 52bb266f1..6b9196921 100644
--- a/lib/prefix.c
+++ b/lib/prefix.c
@@ -1359,6 +1359,35 @@ const char *prefix2str(union prefixconstptr pu, char *str, int size)
return str;
}
+void prefix_mcast_inet4_dump(const char *onfail, struct in_addr addr,
+ char *buf, int buf_size)
+{
+ int save_errno = errno;
+
+ if (addr.s_addr == INADDR_ANY)
+ strcpy(buf, "*");
+ else {
+ if (!inet_ntop(AF_INET, &addr, buf, buf_size)) {
+ if (onfail)
+ snprintf(buf, buf_size, "%s", onfail);
+ }
+ }
+
+ errno = save_errno;
+}
+
+const char *prefix_sg2str(const struct prefix_sg *sg, char *sg_str)
+{
+ char src_str[INET_ADDRSTRLEN];
+ char grp_str[INET_ADDRSTRLEN];
+
+ prefix_mcast_inet4_dump("<src?>", sg->src, src_str, sizeof(src_str));
+ prefix_mcast_inet4_dump("<grp?>", sg->grp, grp_str, sizeof(grp_str));
+ snprintf(sg_str, PREFIX_SG_STR_LEN, "(%s,%s)", src_str, grp_str);
+
+ return sg_str;
+}
+
struct prefix *prefix_new(void)
{
struct prefix *p;
diff --git a/lib/prefix.h b/lib/prefix.h
index a1c2086b8..ffc973f6e 100644
--- a/lib/prefix.h
+++ b/lib/prefix.h
@@ -321,6 +321,15 @@ union prefixconstptr {
/* Maximum string length of the result of prefix2str */
#define PREFIX_STRLEN 80
+/*
+ * Longest possible length of a (S,G) string is 36 bytes
+ * 123.123.123.123 = 16 * 2
+ * (,) = 3
+ * NULL Character at end = 1
+ * (123.123.123.123,123.123.123.123)
+ */
+#define PREFIX_SG_STR_LEN 36
+
/* Max bit/byte length of IPv4 address. */
#define IPV4_MAX_BYTELEN 4
#define IPV4_MAX_BITLEN 32
@@ -394,6 +403,9 @@ extern int str2prefix(const char *, struct prefix *);
#define PREFIX2STR_BUFFER PREFIX_STRLEN
+extern void prefix_mcast_inet4_dump(const char *onfail, struct in_addr addr,
+ char *buf, int buf_size);
+extern const char *prefix_sg2str(const struct prefix_sg *sg, char *str);
extern const char *prefix2str(union prefixconstptr, char *, int);
extern int prefix_match(const struct prefix *, const struct prefix *);
extern int prefix_match_network_statement(const struct prefix *,