--- embedaddon/quagga/lib/prefix.c 2012/10/09 09:22:28 1.1.1.2 +++ embedaddon/quagga/lib/prefix.c 2016/11/02 10:09:11 1.1.1.3 @@ -27,7 +27,7 @@ #include "sockunion.h" #include "memory.h" #include "log.h" - + /* Maskbit. */ static const u_char maskbit[] = {0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff}; @@ -186,7 +186,18 @@ prefix6_bit (const struct in6_addr *prefix, const u_ch { return prefix_bit((const u_char *) &prefix->s6_addr, prefixlen); } - + +int +str2family(const char *string) +{ + if (!strcmp("ipv4", string)) + return AF_INET; + else if (!strcmp("ipv6", string)) + return AF_INET6; + else + return -1; +} + /* Address Famiy Identifier to Address Family converter. */ int afi2family (afi_t afi) @@ -212,6 +223,22 @@ family2afi (int family) return 0; } +const char * +safi2str(safi_t safi) +{ + switch (safi) { + case SAFI_UNICAST: + return "unicast"; + case SAFI_MULTICAST: + return "multicast"; + case SAFI_ENCAP: + return "encap"; + case SAFI_MPLS_VPN: + return "vpn"; + } + return NULL; +} + /* If n includes p prefix then return 1 else return 0. */ int prefix_match (const struct prefix *n, const struct prefix *p) @@ -494,7 +521,7 @@ prefix_ipv4_any (const struct prefix_ipv4 *p) { return (p->prefix.s_addr == 0 && p->prefixlen == 0); } - + #ifdef HAVE_IPV6 /* Allocate a new ip version 6 route */ @@ -681,13 +708,13 @@ sockunion2prefix (const union sockunion *dest, /* Utility function of convert between struct prefix <=> union sockunion. */ struct prefix * -sockunion2hostprefix (const union sockunion *su) +sockunion2hostprefix (const union sockunion *su, struct prefix *prefix) { if (su->sa.sa_family == AF_INET) { struct prefix_ipv4 *p; - p = prefix_ipv4_new (); + p = prefix ? (struct prefix_ipv4 *) prefix : prefix_ipv4_new (); p->family = AF_INET; p->prefix = su->sin.sin_addr; p->prefixlen = IPV4_MAX_BITLEN; @@ -698,7 +725,7 @@ sockunion2hostprefix (const union sockunion *su) { struct prefix_ipv6 *p; - p = prefix_ipv6_new (); + p = prefix ? (struct prefix_ipv6 *) prefix : prefix_ipv6_new (); p->family = AF_INET6; p->prefixlen = IPV6_MAX_BITLEN; memcpy (&p->prefix, &su->sin6.sin6_addr, sizeof (struct in6_addr)); @@ -760,14 +787,15 @@ str2prefix (const char *str, struct prefix *p) return 0; } -int -prefix2str (const struct prefix *p, char *str, int size) +const char * +prefix2str (union prefix46constptr pu, char *str, int size) { + const struct prefix *p = pu.p; char buf[BUFSIZ]; inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ); snprintf (str, size, "%s/%d", buf, p->prefixlen); - return 0; + return str; } struct prefix *