summaryrefslogtreecommitdiff
path: root/lib/mpls.h
diff options
context:
space:
mode:
authorStephen Worley <sworley@nvidia.com>2021-04-01 11:31:44 -0400
committerStephen Worley <sworley@nvidia.com>2023-02-13 18:12:05 -0500
commit4645cb6bc2a4635925dae16533d6277b8da376c4 (patch)
tree4b1c93288f7125cb20dda7e5e3b81bd29dd06364 /lib/mpls.h
parent78d106e1cbb0af335409f60ababe5a2649da9704 (diff)
lib,zebra,bgpd,staticd: use label code to store VNI info
Use the already existing mpls label code to store VNI info for vxlan. VNI's are defined as labels just like mpls, we should be using the same code for both. This patch is the first part of that. Next we will need to abstract the label code to not be so mpls specific. Currently in this, we are just treating VXLAN as a label type and storing it that way. Signed-off-by: Stephen Worley <sworley@nvidia.com>
Diffstat (limited to 'lib/mpls.h')
-rw-r--r--lib/mpls.h33
1 files changed, 31 insertions, 2 deletions
diff --git a/lib/mpls.h b/lib/mpls.h
index 74bd7aae3e..f89d3246ff 100644
--- a/lib/mpls.h
+++ b/lib/mpls.h
@@ -23,6 +23,7 @@
#define _QUAGGA_MPLS_H
#include <zebra.h>
+#include <vxlan.h>
#include <arpa/inet.h>
#ifdef __cplusplus
@@ -129,10 +130,32 @@ enum lsp_types_t {
ZEBRA_LSP_ISIS_SR = 5,/* IS-IS Segment Routing LSP. */
ZEBRA_LSP_SHARP = 6, /* Identifier for test protocol */
ZEBRA_LSP_SRTE = 7, /* SR-TE LSP */
+ ZEBRA_LSP_EVPN = 8, /* EVPN VNI Label */
};
/* Functions for basic label operations. */
+static inline void vni2label(vni_t vni, mpls_label_t *label)
+{
+ uint8_t *tag = (uint8_t *)label;
+
+ tag[0] = (vni >> 16) & 0xFF;
+ tag[1] = (vni >> 8) & 0xFF;
+ tag[2] = vni & 0xFF;
+}
+
+static inline vni_t label2vni(const mpls_label_t *label)
+{
+ uint8_t *tag = (uint8_t *)label;
+ vni_t vni;
+
+ vni = ((uint32_t)*tag++ << 16);
+ vni |= (uint32_t)*tag++ << 8;
+ vni |= (uint32_t)(*tag & 0xFF);
+
+ return vni;
+}
+
/* Encode a label stack entry from fields; convert to network byte-order as
* the Netlink interface expects MPLS labels to be in this format.
*/
@@ -168,8 +191,14 @@ static inline void mpls_lse_decode(mpls_lse_t lse, mpls_label_t *label,
#define MPLS_INVALID_LABEL_INDEX 0xFFFFFFFF
/* Printable string for labels (with consideration for reserved values). */
-static inline char *label2str(mpls_label_t label, char *buf, size_t len)
+static inline char *label2str(mpls_label_t label, enum lsp_types_t type,
+ char *buf, size_t len)
{
+ if (type == ZEBRA_LSP_EVPN) {
+ snprintf(buf, len, "%u", label2vni(&label));
+ return (buf);
+ }
+
switch (label) {
case MPLS_LABEL_IPV4_EXPLICIT_NULL:
strlcpy(buf, "IPv4 Explicit Null", len);
@@ -217,7 +246,7 @@ int mpls_str2label(const char *label_str, uint8_t *num_labels,
* Label to string conversion, labels in string separated by '/'.
*/
char *mpls_label2str(uint8_t num_labels, const mpls_label_t *labels, char *buf,
- int len, int pretty);
+ int len, enum lsp_types_t type, int pretty);
#ifdef __cplusplus
}