summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorHiroki Shirokura <slank.dev@gmail.com>2020-01-09 04:00:43 +0100
committerHiroki Shirokura <slank.dev@gmail.com>2020-01-15 10:20:35 +0100
commite496b4203055c50806dc7193b9762304261c4bbd (patch)
tree3bbce6eb4c17c4a6d53cf10a68708f9a07a9e59e /lib
parentbgpd: extended nexthop capability for vpnv4-unicast (diff)
downloadfrr-e496b4203055c50806dc7193b9762304261c4bbd.tar.xz
frr-e496b4203055c50806dc7193b9762304261c4bbd.zip
bgpd: prefix-sid srv6 l3vpn service tlv
bgpd already supports BGP Prefix-SID path attribute and there are some sub-types of Prefix-SID path attribute. This commits makes bgpd to support additional sub-types. sub-Type-4 and sub-Type-5 for construct the VPNv4 SRv6 backend with vpnv4-unicast address family. This path attributes is already supported by Ciscos IOS-XR and NX-OS. Prefix-SID sub-Type-4 and sub-Type-5 is defined on following IETF-drafts. Supports(A-part-of): - https://tools.ietf.org/html/draft-dawra-idr-srv6-vpn-04 - https://tools.ietf.org/html/draft-dawra-idr-srv6-vpn-05 Signed-off-by: Hiroki Shirokura <slank.dev@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/srv6.c116
-rw-r--r--lib/srv6.h133
-rw-r--r--lib/subdir.am2
3 files changed, 251 insertions, 0 deletions
diff --git a/lib/srv6.c b/lib/srv6.c
new file mode 100644
index 000000000..be340f13f
--- /dev/null
+++ b/lib/srv6.c
@@ -0,0 +1,116 @@
+/*
+ * SRv6 definitions
+ * Copyright (C) 2020 Hiroki Shirokura, LINE Corporation
+ *
+ * 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 "srv6.h"
+#include "log.h"
+
+const char *seg6local_action2str(uint32_t action)
+{
+ switch (action) {
+ case ZEBRA_SEG6_LOCAL_ACTION_END:
+ return "End";
+ case ZEBRA_SEG6_LOCAL_ACTION_END_X:
+ return "End.X";
+ case ZEBRA_SEG6_LOCAL_ACTION_END_T:
+ return "End.T";
+ case ZEBRA_SEG6_LOCAL_ACTION_END_DX2:
+ return "End.DX2";
+ case ZEBRA_SEG6_LOCAL_ACTION_END_DX6:
+ return "End.DX6";
+ case ZEBRA_SEG6_LOCAL_ACTION_END_DX4:
+ return "End.DX4";
+ case ZEBRA_SEG6_LOCAL_ACTION_END_DT6:
+ return "End.DT6";
+ case ZEBRA_SEG6_LOCAL_ACTION_END_DT4:
+ return "End.DT4";
+ case ZEBRA_SEG6_LOCAL_ACTION_END_B6:
+ return "End.B6";
+ case ZEBRA_SEG6_LOCAL_ACTION_END_B6_ENCAP:
+ return "End.B6.Encap";
+ case ZEBRA_SEG6_LOCAL_ACTION_END_BM:
+ return "End.BM";
+ case ZEBRA_SEG6_LOCAL_ACTION_END_S:
+ return "End.S";
+ case ZEBRA_SEG6_LOCAL_ACTION_END_AS:
+ return "End.AS";
+ case ZEBRA_SEG6_LOCAL_ACTION_END_AM:
+ return "End.AM";
+ case ZEBRA_SEG6_LOCAL_ACTION_UNSPEC:
+ return "unspec";
+ default:
+ return "unknown";
+ }
+}
+
+int snprintf_seg6_segs(char *str,
+ size_t size, const struct seg6_segs *segs)
+{
+ str[0] = '\0';
+ for (size_t i = 0; i < segs->num_segs; i++) {
+ char addr[INET6_ADDRSTRLEN];
+ bool not_last = (i + 1) < segs->num_segs;
+
+ inet_ntop(AF_INET6, &segs->segs[i], addr, sizeof(addr));
+ strlcat(str, addr, size);
+ strlcat(str, not_last ? "," : "", size);
+ }
+ return strlen(str);
+}
+
+const char *seg6local_context2str(char *str, size_t size,
+ struct seg6local_context *ctx, uint32_t action)
+{
+ char b0[128];
+
+ switch (action) {
+
+ case ZEBRA_SEG6_LOCAL_ACTION_END:
+ snprintf(str, size, "USP");
+ return str;
+
+ case ZEBRA_SEG6_LOCAL_ACTION_END_X:
+ case ZEBRA_SEG6_LOCAL_ACTION_END_DX6:
+ inet_ntop(AF_INET6, &ctx->nh6, b0, 128);
+ snprintf(str, size, "nh6 %s", b0);
+ return str;
+
+ case ZEBRA_SEG6_LOCAL_ACTION_END_DX4:
+ inet_ntop(AF_INET, &ctx->nh4, b0, 128);
+ snprintf(str, size, "nh4 %s", b0);
+ return str;
+
+ case ZEBRA_SEG6_LOCAL_ACTION_END_T:
+ case ZEBRA_SEG6_LOCAL_ACTION_END_DT6:
+ case ZEBRA_SEG6_LOCAL_ACTION_END_DT4:
+ snprintf(str, size, "table %u", ctx->table);
+ return str;
+
+ case ZEBRA_SEG6_LOCAL_ACTION_END_DX2:
+ case ZEBRA_SEG6_LOCAL_ACTION_END_B6:
+ case ZEBRA_SEG6_LOCAL_ACTION_END_B6_ENCAP:
+ case ZEBRA_SEG6_LOCAL_ACTION_END_BM:
+ case ZEBRA_SEG6_LOCAL_ACTION_END_S:
+ case ZEBRA_SEG6_LOCAL_ACTION_END_AS:
+ case ZEBRA_SEG6_LOCAL_ACTION_END_AM:
+ case ZEBRA_SEG6_LOCAL_ACTION_UNSPEC:
+ default:
+ snprintf(str, size, "unknown(%s)", __func__);
+ return str;
+ }
+}
diff --git a/lib/srv6.h b/lib/srv6.h
new file mode 100644
index 000000000..24c7ffc3a
--- /dev/null
+++ b/lib/srv6.h
@@ -0,0 +1,133 @@
+/*
+ * SRv6 definitions
+ * Copyright (C) 2020 Hiroki Shirokura, LINE Corporation
+ *
+ * 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
+ */
+
+#ifndef _FRR_SRV6_H
+#define _FRR_SRV6_H
+
+#include <zebra.h>
+#include <arpa/inet.h>
+#include <netinet/in.h>
+
+#define SRV6_MAX_SIDS 16
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define sid2str(sid, str, size) \
+ inet_ntop(AF_INET6, sid, str, size)
+
+enum seg6_mode_t {
+ INLINE,
+ ENCAP,
+ L2ENCAP,
+};
+
+enum seg6local_action_t {
+ ZEBRA_SEG6_LOCAL_ACTION_UNSPEC = 0,
+ ZEBRA_SEG6_LOCAL_ACTION_END = 1,
+ ZEBRA_SEG6_LOCAL_ACTION_END_X = 2,
+ ZEBRA_SEG6_LOCAL_ACTION_END_T = 3,
+ ZEBRA_SEG6_LOCAL_ACTION_END_DX2 = 4,
+ ZEBRA_SEG6_LOCAL_ACTION_END_DX6 = 5,
+ ZEBRA_SEG6_LOCAL_ACTION_END_DX4 = 6,
+ ZEBRA_SEG6_LOCAL_ACTION_END_DT6 = 7,
+ ZEBRA_SEG6_LOCAL_ACTION_END_DT4 = 8,
+ ZEBRA_SEG6_LOCAL_ACTION_END_B6 = 9,
+ ZEBRA_SEG6_LOCAL_ACTION_END_B6_ENCAP = 10,
+ ZEBRA_SEG6_LOCAL_ACTION_END_BM = 11,
+ ZEBRA_SEG6_LOCAL_ACTION_END_S = 12,
+ ZEBRA_SEG6_LOCAL_ACTION_END_AS = 13,
+ ZEBRA_SEG6_LOCAL_ACTION_END_AM = 14,
+ ZEBRA_SEG6_LOCAL_ACTION_END_BPF = 15,
+};
+
+struct seg6_segs {
+ size_t num_segs;
+ struct in6_addr segs[256];
+};
+
+struct seg6local_context {
+ struct in_addr nh4;
+ struct in6_addr nh6;
+ uint32_t table;
+};
+
+static inline const char *seg6_mode2str(enum seg6_mode_t mode)
+{
+ switch (mode) {
+ case INLINE:
+ return "INLINE";
+ case ENCAP:
+ return "ENCAP";
+ case L2ENCAP:
+ return "L2ENCAP";
+ default:
+ return "unknown";
+ }
+}
+
+static inline bool sid_same(
+ const struct in6_addr *a,
+ const struct in6_addr *b)
+{
+ if (!a && !b)
+ return true;
+ else if (!(a && b))
+ return false;
+ else
+ return memcmp(a, b, sizeof(struct in6_addr)) == 0;
+}
+
+static inline bool sid_diff(
+ const struct in6_addr *a,
+ const struct in6_addr *b)
+{
+ return !sid_same(a, b);
+}
+
+static inline bool sid_zero(
+ const struct in6_addr *a)
+{
+ struct in6_addr zero = {};
+
+ return sid_same(a, &zero);
+}
+
+static inline void *sid_copy(struct in6_addr *dst,
+ const struct in6_addr *src)
+{
+ return memcpy(dst, src, sizeof(struct in6_addr));
+}
+
+const char *
+seg6local_action2str(uint32_t action);
+
+const char *
+seg6local_context2str(char *str, size_t size,
+ struct seg6local_context *ctx, uint32_t action);
+
+int snprintf_seg6_segs(char *str,
+ size_t size, const struct seg6_segs *segs);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/subdir.am b/lib/subdir.am
index cb6fa7a3b..d804d839d 100644
--- a/lib/subdir.am
+++ b/lib/subdir.am
@@ -51,6 +51,7 @@ lib_libfrr_la_SOURCES = \
lib/mlag.c \
lib/module.c \
lib/mpls.c \
+ lib/srv6.c \
lib/network.c \
lib/nexthop.c \
lib/netns_linux.c \
@@ -193,6 +194,7 @@ pkginclude_HEADERS += \
lib/module.h \
lib/monotime.h \
lib/mpls.h \
+ lib/srv6.h \
lib/network.h \
lib/nexthop.h \
lib/nexthop_group.h \