summaryrefslogtreecommitdiffstats
path: root/bgpd/rfapi/rfapi_nve_addr.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 09:53:30 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 09:53:30 +0000
commit2c7cac91ed6e7db0f6937923d2b57f97dbdbc337 (patch)
treec05dc0f8e6aa3accc84e3e5cffc933ed94941383 /bgpd/rfapi/rfapi_nve_addr.c
parentInitial commit. (diff)
downloadfrr-2c7cac91ed6e7db0f6937923d2b57f97dbdbc337.tar.xz
frr-2c7cac91ed6e7db0f6937923d2b57f97dbdbc337.zip
Adding upstream version 8.4.4.upstream/8.4.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'bgpd/rfapi/rfapi_nve_addr.c')
-rw-r--r--bgpd/rfapi/rfapi_nve_addr.c158
1 files changed, 158 insertions, 0 deletions
diff --git a/bgpd/rfapi/rfapi_nve_addr.c b/bgpd/rfapi/rfapi_nve_addr.c
new file mode 100644
index 0000000..b8193f1
--- /dev/null
+++ b/bgpd/rfapi/rfapi_nve_addr.c
@@ -0,0 +1,158 @@
+/*
+ *
+ * Copyright 2009-2016, LabN Consulting, L.L.C.
+ *
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; see the file COPYING; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+
+#include "lib/zebra.h"
+#include "lib/prefix.h"
+#include "lib/agg_table.h"
+#include "lib/vty.h"
+#include "lib/memory.h"
+#include "lib/skiplist.h"
+
+
+#include "bgpd/bgpd.h"
+
+#include "bgpd/rfapi/bgp_rfapi_cfg.h"
+#include "bgpd/rfapi/rfapi.h"
+#include "bgpd/rfapi/rfapi_backend.h"
+
+#include "bgpd/rfapi/rfapi_import.h"
+#include "bgpd/rfapi/rfapi_private.h"
+#include "bgpd/rfapi/rfapi_nve_addr.h"
+#include "bgpd/rfapi/rfapi_vty.h"
+#include "bgpd/rfapi/vnc_debug.h"
+
+#define DEBUG_NVE_ADDR 0
+
+void rfapiNveAddr2Str(struct rfapi_nve_addr *, char *, int);
+
+
+#if DEBUG_NVE_ADDR
+static void logdifferent(const char *tag, struct rfapi_nve_addr *a,
+ struct rfapi_nve_addr *b)
+{
+ char a_str[BUFSIZ];
+ char b_str[BUFSIZ];
+
+ rfapiNveAddr2Str(a, a_str, BUFSIZ);
+ rfapiNveAddr2Str(b, b_str, BUFSIZ);
+ vnc_zlog_debug_verbose("%s: [%s] [%s]", tag, a_str, b_str);
+}
+#endif
+
+
+int rfapi_nve_addr_cmp(const void *k1, const void *k2)
+{
+ const struct rfapi_nve_addr *a = (struct rfapi_nve_addr *)k1;
+ const struct rfapi_nve_addr *b = (struct rfapi_nve_addr *)k2;
+ int ret = 0;
+
+ if (!a || !b) {
+#if DEBUG_NVE_ADDR
+ vnc_zlog_debug_verbose("%s: missing address a=%p b=%p",
+ __func__, a, b);
+#endif
+ return (a - b);
+ }
+ if (a->un.addr_family != b->un.addr_family) {
+#if DEBUG_NVE_ADDR
+ vnc_zlog_debug_verbose(
+ "diff: UN addr fam a->un.af=%d, b->un.af=%d",
+ a->un.addr_family, b->un.addr_family);
+#endif
+ return (a->un.addr_family - b->un.addr_family);
+ }
+ if (a->un.addr_family == AF_INET) {
+ ret = IPV4_ADDR_CMP(&a->un.addr.v4, &b->un.addr.v4);
+ if (ret != 0) {
+#if DEBUG_NVE_ADDR
+ logdifferent("diff: UN addr", a, b);
+#endif
+ return ret;
+ }
+ } else if (a->un.addr_family == AF_INET6) {
+ ret = IPV6_ADDR_CMP(&a->un.addr.v6, &b->un.addr.v6);
+ if (ret == 0) {
+#if DEBUG_NVE_ADDR
+ logdifferent("diff: UN addr", a, b);
+#endif
+ return ret;
+ }
+ } else {
+ assert(0);
+ }
+ if (a->vn.addr_family != b->vn.addr_family) {
+#if DEBUG_NVE_ADDR
+ vnc_zlog_debug_verbose(
+ "diff: pT addr fam a->vn.af=%d, b->vn.af=%d",
+ a->vn.addr_family, b->vn.addr_family);
+#endif
+ return (a->vn.addr_family - b->vn.addr_family);
+ }
+ if (a->vn.addr_family == AF_INET) {
+ ret = IPV4_ADDR_CMP(&a->vn.addr.v4, &b->vn.addr.v4);
+ if (ret != 0) {
+#if DEBUG_NVE_ADDR
+ logdifferent("diff: VN addr", a, b);
+#endif
+ return ret;
+ }
+ } else if (a->vn.addr_family == AF_INET6) {
+ ret = IPV6_ADDR_CMP(&a->vn.addr.v6, &b->vn.addr.v6);
+ if (ret == 0) {
+#if DEBUG_NVE_ADDR
+ logdifferent("diff: VN addr", a, b);
+#endif
+ return ret;
+ }
+ } else {
+ assert(0);
+ }
+ return 0;
+}
+
+void rfapiNveAddr2Str(struct rfapi_nve_addr *na, char *buf, int bufsize)
+{
+ char *p = buf;
+ int r;
+
+#define REMAIN (bufsize - (p-buf))
+#define INCP {p += (r > REMAIN)? REMAIN: r;}
+
+ if (bufsize < 1)
+ return;
+
+ r = snprintf(p, REMAIN, "VN=");
+ INCP;
+
+ if (!rfapiRfapiIpAddr2Str(&na->vn, p, REMAIN))
+ goto done;
+
+ buf[bufsize - 1] = 0;
+ p = buf + strlen(buf);
+
+ r = snprintf(p, REMAIN, ", UN=");
+ INCP;
+
+ rfapiRfapiIpAddr2Str(&na->un, p, REMAIN);
+
+done:
+ buf[bufsize - 1] = 0;
+}