--- embedaddon/quagga/bgpd/bgp_ecommunity.c 2013/07/21 23:54:37 1.1.1.3 +++ embedaddon/quagga/bgpd/bgp_ecommunity.c 2016/11/02 10:09:10 1.1.1.4 @@ -24,6 +24,7 @@ Software Foundation, Inc., 59 Temple Place - Suite 330 #include "memory.h" #include "prefix.h" #include "command.h" +#include "filter.h" #include "bgpd/bgpd.h" #include "bgpd/bgp_ecommunity.h" @@ -31,7 +32,7 @@ Software Foundation, Inc., 59 Temple Place - Suite 330 /* Hash of community attribute. */ static struct hash *ecomhash; - + /* Allocate a new ecommunities. */ static struct ecommunity * ecommunity_new (void) @@ -277,14 +278,14 @@ ecommunity_finish (void) hash_free (ecomhash); ecomhash = NULL; } - + /* Extended Communities token enum. */ enum ecommunity_token { + ecommunity_token_unknown = 0, ecommunity_token_rt, ecommunity_token_soo, ecommunity_token_val, - ecommunity_token_unknown }; /* Get next Extended Communities token from the string. */ @@ -511,7 +512,7 @@ struct ecommunity * ecommunity_str2com (const char *str, int type, int keyword_included) { struct ecommunity *ecom = NULL; - enum ecommunity_token token; + enum ecommunity_token token = ecommunity_token_unknown; struct ecommunity_val eval; int keyword = 0; @@ -642,15 +643,34 @@ ecommunity_ecom2str (struct ecommunity *ecom, int form /* High-order octet of type. */ encode = *pnt++; - if (encode != ECOMMUNITY_ENCODE_AS && encode != ECOMMUNITY_ENCODE_IP - && encode != ECOMMUNITY_ENCODE_AS4) - { - len = sprintf (str_buf + str_pnt, "?"); - str_pnt += len; - first = 0; - continue; - } - + + switch (encode) + { + case ECOMMUNITY_ENCODE_AS: + case ECOMMUNITY_ENCODE_IP: + case ECOMMUNITY_ENCODE_AS4: + break; + + case ECOMMUNITY_ENCODE_OPAQUE: + if (*pnt == ECOMMUNITY_OPAQUE_SUBTYPE_ENCAP) + { + uint16_t tunneltype; + memcpy (&tunneltype, pnt + 5, 2); + tunneltype = ntohs(tunneltype); + len = sprintf (str_buf + str_pnt, "ET:%d", tunneltype); + str_pnt += len; + first = 0; + continue; + } + /* fall through */ + + default: + len = sprintf (str_buf + str_pnt, "?"); + str_pnt += len; + first = 0; + continue; + } + /* Low-order octet of type. */ type = *pnt++; if (type != ECOMMUNITY_ROUTE_TARGET && type != ECOMMUNITY_SITE_ORIGIN) @@ -688,7 +708,7 @@ ecommunity_ecom2str (struct ecommunity *ecom, int form eas.val = (*pnt++ << 8); eas.val |= (*pnt++); - len = sprintf( str_buf + str_pnt, "%s%u:%d", prefix, + len = sprintf( str_buf + str_pnt, "%s%u:%u", prefix, eas.as, eas.val ); str_pnt += len; first = 0; @@ -703,7 +723,7 @@ ecommunity_ecom2str (struct ecommunity *ecom, int form eas.val |= (*pnt++ << 8); eas.val |= (*pnt++); - len = sprintf (str_buf + str_pnt, "%s%u:%d", prefix, + len = sprintf (str_buf + str_pnt, "%s%u:%u", prefix, eas.as, eas.val); str_pnt += len; first = 0; @@ -715,7 +735,7 @@ ecommunity_ecom2str (struct ecommunity *ecom, int form eip.val = (*pnt++ << 8); eip.val |= (*pnt++); - len = sprintf (str_buf + str_pnt, "%s%s:%d", prefix, + len = sprintf (str_buf + str_pnt, "%s%s:%u", prefix, inet_ntoa (eip.ip), eip.val); str_pnt += len; first = 0;