#define ETH_ALEN 6
#endif
+#define ESI_BYTES 10
+#define ESI_STR_LEN (3 * ESI_BYTES)
+
#define ETHER_ADDR_STRLEN (3*ETH_ALEN)
/*
* there isn't a portable ethernet address type. We define our
* own to simplify internal handling
*/
struct ethaddr {
- u_char octet[ETH_ALEN];
+ uint8_t octet[ETH_ALEN];
} __attribute__((packed));
#define PREFIX_LEN_ROUTE_TYPE_5_IPV4 (18*8)
#define PREFIX_LEN_ROUTE_TYPE_5_IPV6 (30*8)
-/* EVPN address (RFC 7432) */
-struct evpn_addr {
- u_char route_type;
- u_char ip_prefix_length;
+typedef struct esi_t_ {
+ uint8_t val[10];
+} esi_t;
+
+struct evpn_ead_addr {
+ esi_t esi;
+ uint32_t eth_tag;
+};
+
+struct evpn_macip_addr {
+ uint32_t eth_tag;
+ uint8_t ip_prefix_length;
struct ethaddr mac;
+ struct ipaddr ip;
+};
+
+struct evpn_imet_addr {
uint32_t eth_tag;
+ uint8_t ip_prefix_length;
struct ipaddr ip;
-#if 0
- union
- {
- u_char addr;
- struct in_addr v4_addr;
- struct in6_addr v6_addr;
- } ip;
-#endif
};
-#define IS_EVPN_PREFIX_IPADDR_NONE(evp) IS_IPADDR_NONE(&(evp)->prefix.ip)
-#define IS_EVPN_PREFIX_IPADDR_V4(evp) IS_IPADDR_V4(&(evp)->prefix.ip)
-#define IS_EVPN_PREFIX_IPADDR_V6(evp) IS_IPADDR_V6(&(evp)->prefix.ip)
+struct evpn_es_addr {
+ esi_t esi;
+ uint8_t ip_prefix_length;
+ struct ipaddr ip;
+};
+
+struct evpn_prefix_addr {
+ uint32_t eth_tag;
+ uint8_t ip_prefix_length;
+ struct ipaddr ip;
+};
+
+/* EVPN address (RFC 7432) */
+struct evpn_addr {
+ uint8_t route_type;
+ union {
+ struct evpn_ead_addr _ead_addr;
+ struct evpn_macip_addr _macip_addr;
+ struct evpn_imet_addr _imet_addr;
+ struct evpn_es_addr _es_addr;
+ struct evpn_prefix_addr _prefix_addr;
+ } u;
+#define ead_addr u._ead_addr
+#define macip_addr u._macip_addr
+#define imet_addr u._imet_addr
+#define es_addr u._es_addr
+#define prefix_addr u._prefix_addr
+};
/*
* A struct prefix contains an address family, a prefix length, and an
#define AF_EVPN (AF_MAX + 1)
#endif
+#if !defined(AF_FLOWSPEC)
+#define AF_FLOWSPEC (AF_MAX + 2)
+#endif
+
+struct flowspec_prefix {
+ uint16_t prefixlen; /* length in bytes */
+ uintptr_t ptr;
+};
+
/* FRR generic prefix structure. */
struct prefix {
- u_char family;
- u_char prefixlen;
+ uint8_t family;
+ uint8_t prefixlen;
union {
- u_char prefix;
+ uint8_t prefix;
struct in_addr prefix4;
struct in6_addr prefix6;
struct {
struct in_addr adv_router;
} lp;
struct ethaddr prefix_eth; /* AF_ETHERNET */
- u_char val[16];
+ uint8_t val[16];
uintptr_t ptr;
struct evpn_addr prefix_evpn; /* AF_EVPN */
+ struct flowspec_prefix prefix_flowspec; /* AF_FLOWSPEC */
} u __attribute__((aligned(8)));
};
/* IPv4 prefix structure. */
struct prefix_ipv4 {
- u_char family;
- u_char prefixlen;
+ uint8_t family;
+ uint8_t prefixlen;
struct in_addr prefix __attribute__((aligned(8)));
};
/* IPv6 prefix structure. */
struct prefix_ipv6 {
- u_char family;
- u_char prefixlen;
+ uint8_t family;
+ uint8_t prefixlen;
struct in6_addr prefix __attribute__((aligned(8)));
};
struct prefix_ls {
- u_char family;
- u_char prefixlen;
+ uint8_t family;
+ uint8_t prefixlen;
struct in_addr id __attribute__((aligned(8)));
struct in_addr adv_router;
};
/* Prefix for routing distinguisher. */
struct prefix_rd {
- u_char family;
- u_char prefixlen;
- u_char val[8] __attribute__((aligned(8)));
+ uint8_t family;
+ uint8_t prefixlen;
+ uint8_t val[8] __attribute__((aligned(8)));
};
/* Prefix for ethernet. */
struct prefix_eth {
- u_char family;
- u_char prefixlen;
+ uint8_t family;
+ uint8_t prefixlen;
struct ethaddr eth_addr __attribute__((aligned(8))); /* AF_ETHERNET */
};
/* EVPN prefix structure. */
struct prefix_evpn {
- u_char family;
- u_char prefixlen;
+ uint8_t family;
+ uint8_t prefixlen;
struct evpn_addr prefix __attribute__((aligned(8)));
};
+static inline int is_evpn_prefix_ipaddr_none(const struct prefix_evpn *evp)
+{
+ if (evp->prefix.route_type == 2)
+ return IS_IPADDR_NONE(&(evp)->prefix.macip_addr.ip);
+ if (evp->prefix.route_type == 3)
+ return IS_IPADDR_NONE(&(evp)->prefix.imet_addr.ip);
+ if (evp->prefix.route_type == 4)
+ return IS_IPADDR_NONE(&(evp)->prefix.es_addr.ip);
+ if (evp->prefix.route_type == 5)
+ return IS_IPADDR_NONE(&(evp)->prefix.prefix_addr.ip);
+ return 0;
+}
+
+static inline int is_evpn_prefix_ipaddr_v4(const struct prefix_evpn *evp)
+{
+ if (evp->prefix.route_type == 2)
+ return IS_IPADDR_V4(&(evp)->prefix.macip_addr.ip);
+ if (evp->prefix.route_type == 3)
+ return IS_IPADDR_V4(&(evp)->prefix.imet_addr.ip);
+ if (evp->prefix.route_type == 4)
+ return IS_IPADDR_V4(&(evp)->prefix.es_addr.ip);
+ if (evp->prefix.route_type == 5)
+ return IS_IPADDR_V4(&(evp)->prefix.prefix_addr.ip);
+ return 0;
+}
+
+static inline int is_evpn_prefix_ipaddr_v6(const struct prefix_evpn *evp)
+{
+ if (evp->prefix.route_type == 2)
+ return IS_IPADDR_V6(&(evp)->prefix.macip_addr.ip);
+ if (evp->prefix.route_type == 3)
+ return IS_IPADDR_V6(&(evp)->prefix.imet_addr.ip);
+ if (evp->prefix.route_type == 4)
+ return IS_IPADDR_V6(&(evp)->prefix.es_addr.ip);
+ if (evp->prefix.route_type == 5)
+ return IS_IPADDR_V6(&(evp)->prefix.prefix_addr.ip);
+ return 0;
+}
+
/* Prefix for a generic pointer */
struct prefix_ptr {
- u_char family;
- u_char prefixlen;
+ uint8_t family;
+ uint8_t prefixlen;
uintptr_t prefix __attribute__((aligned(8)));
};
+/* Prefix for a Flowspec entry */
+struct prefix_fs {
+ uint8_t family;
+ uint8_t prefixlen; /* unused */
+ struct flowspec_prefix prefix __attribute__((aligned(8)));
+};
+
struct prefix_sg {
- u_char family;
- u_char prefixlen;
+ uint8_t family;
+ uint8_t prefixlen;
struct in_addr src __attribute__((aligned(8)));
struct in_addr grp;
};
struct prefix_ipv4 *p4;
struct prefix_ipv6 *p6;
struct prefix_evpn *evp;
+ const struct prefix_fs *fs;
} __attribute__((transparent_union));
union prefixconstptr {
const struct prefix_ipv4 *p4;
const struct prefix_ipv6 *p6;
const struct prefix_evpn *evp;
+ const struct prefix_fs *fs;
} __attribute__((transparent_union));
#ifndef INET_ADDRSTRLEN
}
#define IPV4_ADDR_COPY(D,S) ipv4_addr_copy((D), (S))
-#define IPV4_NET0(a) ((((u_int32_t) (a)) & 0xff000000) == 0x00000000)
-#define IPV4_NET127(a) ((((u_int32_t) (a)) & 0xff000000) == 0x7f000000)
-#define IPV4_LINKLOCAL(a) ((((u_int32_t) (a)) & 0xffff0000) == 0xa9fe0000)
-#define IPV4_CLASS_DE(a) ((((u_int32_t) (a)) & 0xe0000000) == 0xe0000000)
-#define IPV4_MC_LINKLOCAL(a) ((((u_int32_t) (a)) & 0xffffff00) == 0xe0000000)
+#define IPV4_NET0(a) ((((uint32_t)(a)) & 0xff000000) == 0x00000000)
+#define IPV4_NET127(a) ((((uint32_t)(a)) & 0xff000000) == 0x7f000000)
+#define IPV4_LINKLOCAL(a) ((((uint32_t)(a)) & 0xffff0000) == 0xa9fe0000)
+#define IPV4_CLASS_DE(a) ((((uint32_t)(a)) & 0xe0000000) == 0xe0000000)
+#define IPV4_MC_LINKLOCAL(a) ((((uint32_t)(a)) & 0xffffff00) == 0xe0000000)
/* Max bit/byte length of IPv6 address. */
#define IPV6_MAX_BYTELEN 16
extern int str2family(const char *);
extern int afi2family(afi_t);
extern afi_t family2afi(int);
+extern const char *family2str(int family);
extern const char *safi2str(safi_t safi);
extern const char *afi2str(afi_t afi);
/* Check bit of the prefix. */
-extern unsigned int prefix_bit(const u_char *prefix, const u_char prefixlen);
+extern unsigned int prefix_bit(const uint8_t *prefix, const uint8_t prefixlen);
extern unsigned int prefix6_bit(const struct in6_addr *prefix,
- const u_char prefixlen);
+ const uint8_t prefixlen);
extern struct prefix *prefix_new(void);
extern void prefix_free(struct prefix *);
extern int str2prefix_ipv4(const char *, struct prefix_ipv4 *);
extern void apply_mask_ipv4(struct prefix_ipv4 *);
-#define PREFIX_COPY(DST, SRC) \
+#define PREFIX_COPY(DST, SRC) \
*((struct prefix *)(DST)) = *((const struct prefix *)(SRC))
-#define PREFIX_COPY_IPV4(DST, 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 *);
-extern u_char ip_masklen(struct in_addr);
+extern uint8_t ip_masklen(struct in_addr);
extern void masklen2ip(const int, struct in_addr *);
/* returns the network portion of the host address */
extern in_addr_t ipv4_network_addr(in_addr_t hostaddr, int masklen);
extern unsigned prefix_hash_key(void *pp);
+extern int str_to_esi(const char *str, esi_t *esi);
+extern char *esi_to_str(const esi_t *esi, char *buf, int size);
+extern void prefix_hexdump(const struct prefix *p);
+extern void prefix_evpn_hexdump(const struct prefix_evpn *p);
+
static inline int ipv6_martian(struct in6_addr *addr)
{
struct in6_addr localhost_addr;
return 0;
}
-extern int all_digit(const char *);
extern int macstr2prefix_evpn(const char *str, struct prefix_evpn *p);
/* NOTE: This routine expects the address argument in network byte order. */
if (!p)
return 0;
- if ((p->family == AF_INET) &&
- (p->u.prefix4.s_addr == INADDR_ANY) &&
- (p->prefixlen == 0))
+ if ((p->family == AF_INET) && (p->u.prefix4.s_addr == INADDR_ANY)
+ && (p->prefixlen == 0))
return 1;
- if ((p->family == AF_INET6) &&
- (p->prefixlen == 0) &&
- (!memcmp(&p->u.prefix6, &in6addr_any,
- sizeof(struct in6_addr))))
+ if ((p->family == AF_INET6) && (p->prefixlen == 0)
+ && (!memcmp(&p->u.prefix6, &in6addr_any, sizeof(struct in6_addr))))
return 1;
return 0;
return (p->prefixlen == IPV6_MAX_BITLEN);
return 0;
}
-
#endif /* _ZEBRA_PREFIX_H */