--- embedaddon/quagga/lib/prefix.h 2012/10/09 09:22:28 1.1.1.2 +++ embedaddon/quagga/lib/prefix.h 2016/11/02 10:09:10 1.1.1.3 @@ -52,6 +52,7 @@ struct prefix struct in_addr adv_router; } lp; u_char val[8]; + uintptr_t ptr; } u __attribute__ ((aligned (8))); }; @@ -89,6 +90,33 @@ struct prefix_rd u_char val[8] __attribute__ ((aligned (8))); }; +/* Prefix for a generic pointer */ +struct prefix_ptr +{ + u_char family; + u_char prefixlen; + uintptr_t prefix __attribute__ ((aligned (8))); +}; + +/* 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 +{ + struct prefix *p; + struct prefix_ipv4 *p4; + struct prefix_ipv6 *p6; +} __attribute__ ((transparent_union)); + +union prefix46constptr +{ + const struct prefix *p; + const struct prefix_ipv4 *p4; + const struct prefix_ipv6 *p6; +} __attribute__ ((transparent_union)); + #ifndef INET_ADDRSTRLEN #define INET_ADDRSTRLEN 16 #endif /* INET_ADDRSTRLEN */ @@ -101,6 +129,9 @@ struct prefix_rd #define INET6_BUFSIZ 51 #endif /* INET6_BUFSIZ */ +/* Maximum prefix string length (IPv6) */ +#define PREFIX_STRLEN 51 + /* Max bit/byte length of IPv4 address. */ #define IPV4_MAX_BYTELEN 4 #define IPV4_MAX_BITLEN 32 @@ -128,9 +159,21 @@ struct prefix_rd /* Prefix's family member. */ #define PREFIX_FAMILY(p) ((p)->family) +/* glibc defines s6_addr32 to __in6_u.__u6_addr32 if __USE_{MISC || GNU} */ +#ifndef s6_addr32 +#if defined(SUNOS_5) +/* Some SunOS define s6_addr32 only to kernel */ +#define s6_addr32 _S6_un._S6_u32 +#else +#define s6_addr32 __u6_addr.__u6_addr32 +#endif /* SUNOS_5 */ +#endif /*s6_addr32*/ + /* Prototypes. */ +extern int str2family(const char *); extern int afi2family (afi_t); extern afi_t family2afi (int); +extern const char *safi2str(safi_t safi); /* Check bit of the prefix. */ extern unsigned int prefix_bit (const u_char *prefix, const u_char prefixlen); @@ -141,7 +184,7 @@ extern void prefix_free (struct prefix *); extern const char *prefix_family_str (const struct prefix *); extern int prefix_blen (const struct prefix *); extern int str2prefix (const char *, struct prefix *); -extern int prefix2str (const struct prefix *, char *, int); +extern const char *prefix2str (union prefix46constptr, 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 *); @@ -151,7 +194,7 @@ extern void apply_mask (struct prefix *); extern struct prefix *sockunion2prefix (const union sockunion *dest, const union sockunion *mask); -extern struct prefix *sockunion2hostprefix (const union sockunion *); +extern struct prefix *sockunion2hostprefix (const union sockunion *, struct prefix *p); extern void prefix2sockunion (const struct prefix *, union sockunion *); extern struct prefix_ipv4 *prefix_ipv4_new (void); @@ -195,5 +238,15 @@ extern const char *inet6_ntoa (struct in6_addr); #endif /* HAVE_IPV6 */ extern int all_digit (const char *); + +static inline int ipv4_martian (struct in_addr *addr) +{ + in_addr_t ip = addr->s_addr; + + if (IPV4_NET0(ip) || IPV4_NET127(ip) || IPV4_CLASS_DE(ip)) { + return 1; + } + return 0; +} #endif /* _ZEBRA_PREFIX_H */