#ifndef _ZEBRA_PREFIX_H
#define _ZEBRA_PREFIX_H
+#ifdef SUNOS_5
+# include <sys/ethernet.h>
+#else
+# ifdef GNU_LINUX
+# include <net/ethernet.h>
+# else
+# include <netinet/if_ether.h>
+# endif
+#endif
#include "sockunion.h"
+#ifndef ETHER_ADDR_LEN
+#ifdef ETHERADDRL
+#define ETHER_ADDR_LEN ETHERADDRL
+#else
+#define ETHER_ADDR_LEN 6
+#endif
+#endif
+
+#define ETHER_ADDR_STRLEN (3*ETHER_ADDR_LEN)
+/*
+ * there isn't a portable ethernet address type. We define our
+ * own to simplify internal handling
+ */
+struct ethaddr {
+ u_char octet[ETHER_ADDR_LEN];
+} __attribute__ ((packed));
+
+
+/* length is the number of valuable bits of prefix structure
+* 18 bytes is current length in structure, if address is ipv4
+* 30 bytes is in case of ipv6
+*/
+#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 flags;
+#define IP_ADDR_NONE 0x0
+#define IP_ADDR_V4 0x1
+#define IP_ADDR_V6 0x2
+#define IP_PREFIX_V4 0x4
+#define IP_PREFIX_V6 0x8
+ struct ethaddr mac;
+ uint32_t eth_tag;
+ u_char ip_prefix_length;
+ union
+ {
+ u_char addr;
+ struct in_addr v4_addr;
+ struct in6_addr v6_addr;
+ } ip;
+};
+
+/* EVPN prefix structure. */
+struct prefix_evpn
+{
+ u_char family;
+ u_char prefixlen;
+ struct evpn_addr prefix __attribute__ ((aligned (8)));
+};
+
/*
* A struct prefix contains an address family, a prefix length, and an
* address. This can represent either a 'network prefix' as defined
* interface.
*/
+/* different OSes use different names */
+#if defined(AF_PACKET)
+#define AF_ETHERNET AF_PACKET
+#else
+#if defined(AF_LINK)
+#define AF_ETHERNET AF_LINK
+#endif
+#endif
+
/* IPv4 and IPv6 unified prefix structure. */
struct prefix
{
{
u_char prefix;
struct in_addr prefix4;
-#ifdef HAVE_IPV6
struct in6_addr prefix6;
-#endif /* HAVE_IPV6 */
struct
{
struct in_addr id;
struct in_addr adv_router;
} lp;
+ struct ethaddr prefix_eth; /* AF_ETHERNET */
u_char val[8];
uintptr_t ptr;
+ struct evpn_addr prefix_evpn;
} u __attribute__ ((aligned (8)));
};
};
/* IPv6 prefix structure. */
-#ifdef HAVE_IPV6
struct prefix_ipv6
{
u_char family;
u_char prefixlen;
struct in6_addr prefix __attribute__ ((aligned (8)));
};
-#endif /* HAVE_IPV6 */
struct prefix_ls
{
u_char val[8] __attribute__ ((aligned (8)));
};
+/* Prefix for ethernet. */
+struct prefix_eth
+{
+ u_char family;
+ u_char prefixlen;
+ struct ethaddr eth_addr __attribute__ ((aligned (8))); /* AF_ETHERNET */
+};
+
/* Prefix for a generic pointer */
struct prefix_ptr
{
uintptr_t prefix __attribute__ ((aligned (8)));
};
+struct prefix_sg
+{
+ u_char family;
+ u_char prefixlen;
+ struct in_addr src __attribute ((aligned (8)));
+ struct in_addr grp;
+};
+
/* helper to get type safety/avoid casts on calls
* (w/o this, functions accepting all prefix types need casts on the caller
* side, which strips type safety since the cast will accept any pointer
* type.)
*/
-union prefix46ptr
+union prefixptr
{
struct prefix *p;
struct prefix_ipv4 *p4;
struct prefix_ipv6 *p6;
+ struct prefix_evpn *evp;
} __attribute__ ((transparent_union));
-union prefix46constptr
+union prefixconstptr
{
const struct prefix *p;
const struct prefix_ipv4 *p4;
const struct prefix_ipv6 *p6;
+ const struct prefix_evpn *evp;
} __attribute__ ((transparent_union));
#ifndef INET_ADDRSTRLEN
extern int afi2family (afi_t);
extern afi_t family2afi (int);
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 int prefix_blen (const struct prefix *);
extern int str2prefix (const char *, struct prefix *);
-/*
- * 8 groups of 4 bytes of hexadecimal + 7 seperators is 39
- * /128 = 4 bytes
- * Null = 1 byte
- * 39 + 4 + 1 = 44 bytes
- */
-#define PREFIX2STR_BUFFER 44
-extern const char *prefix2str (union prefix46constptr, char *, int);
+#define PREFIX2STR_BUFFER PREFIX_STRLEN
+
+extern const char *prefix2str (union prefixconstptr, char *, int);
extern int prefix_match (const struct prefix *, const struct prefix *);
extern int prefix_same (const struct prefix *, const struct prefix *);
extern int prefix_cmp (const struct prefix *, const struct prefix *);
extern struct prefix *sockunion2hostprefix (const union sockunion *, struct prefix *p);
extern void prefix2sockunion (const struct prefix *, union sockunion *);
+extern int str2prefix_eth (const char *, struct prefix_eth *);
+
extern struct prefix_ipv4 *prefix_ipv4_new (void);
extern void prefix_ipv4_free (struct prefix_ipv4 *);
extern int str2prefix_ipv4 (const char *, struct prefix_ipv4 *);
extern int netmask_str2prefix_str (const char *, const char *, char *);
-#ifdef HAVE_IPV6
extern struct prefix_ipv6 *prefix_ipv6_new (void);
extern void prefix_ipv6_free (struct prefix_ipv6 *);
extern int str2prefix_ipv6 (const char *, struct prefix_ipv6 *);
extern int ip6_masklen (struct in6_addr);
extern void masklen2ip6 (const int, struct in6_addr *);
-extern void str2in6_addr (const char *, struct in6_addr *);
extern const char *inet6_ntoa (struct in6_addr);
+extern int prefix_str2mac(const char *str, struct ethaddr *mac);
+extern char *prefix_mac2str(const struct ethaddr *mac, char *buf, int size);
+
static inline int ipv6_martian (struct in6_addr *addr)
{
struct in6_addr localhost_addr;
return 0;
}
-#endif /* HAVE_IPV6 */
-
extern int all_digit (const char *);
/* NOTE: This routine expects the address argument in network byte order. */