memset(&routermac_ecom, 0, sizeof(struct ecommunity_val));
routermac_ecom.val[0] = ECOMMUNITY_ENCODE_EVPN;
routermac_ecom.val[1] = ECOMMUNITY_EVPN_SUBTYPE_ROUTERMAC;
- memcpy(&routermac_ecom.val[2], routermac, MAC_LEN);
+ memcpy(&routermac_ecom.val[2], routermac, ETHER_ADDR_LEN);
if (!attr->extra->ecommunity)
attr->extra->ecommunity = ecommunity_new();
ecommunity_add_val(attr->extra->ecommunity, &routermac_ecom);
return 0;
}
-/* converts to internal representation of mac address
- * returns 1 on success, 0 otherwise
- * format accepted: AA:BB:CC:DD:EE:FF
- * if mac parameter is null, then check only
- */
-int str2mac(const char *str, char *mac)
-{
- unsigned int k = 0, i, j;
- uint8_t *ptr, *ptr2;
- size_t len;
- uint8_t car;
-
- if (!str)
- return 0;
-
- if (str[0] == ':' && str[1] == '\0')
- return 1;
-
- i = 0;
- ptr = (uint8_t *) str;
- while (i < 6) {
- uint8_t temp[5];
- int error = 0;
- ptr2 = (uint8_t *) strchr((const char *)ptr, ':');
- if (ptr2 == NULL) {
- /* if last occurence return ok */
- if (i != 5) {
- zlog_err("[%s]: format non recognized", mac);
- return 0;
- }
- len = strlen((char *)ptr);
- } else {
- len = ptr2 - ptr;
- }
- if (len > 5) {
- zlog_err("[%s]: format non recognized", mac);
- return 0;
- }
- memcpy(temp, ptr, len);
- for (j = 0; j < len; j++) {
- if (k >= MAC_LEN)
- return 0;
- if (mac)
- mac[k] = 0;
- car = convertchartohexa(&temp[j], &error);
- if (error)
- return 0;
- if (mac)
- mac[k] = car << 4;
- j++;
- if (j == len)
- return 0;
- car = convertchartohexa(&temp[j], &error) & 0xf;
- if (error)
- return 0;
- if (mac)
- mac[k] |= car & 0xf;
- k++;
- i++;
- }
- ptr = ptr2;
- if (ptr == NULL)
- break;
- ptr++;
- }
- if (mac && 0) {
- zlog_err("leave correct : %02x:%02x:%02x:%02x:%02x:%02x",
- mac[0] & 0xff, mac[1] & 0xff, mac[2] & 0xff,
- mac[3] & 0xff, mac[4] & 0xff, mac[5] & 0xff);
- }
- return 1;
-}
-
/* converts to an esi
* returns 1 on success, 0 otherwise
* format accepted: AA:BB:CC:DD:EE:FF:GG:HH:II:JJ
return ptr;
}
-char *mac2str(char *mac)
-{
- char *ptr;
-
- if (!mac)
- return NULL;
-
- ptr = (char *)malloc((MAC_LEN * 2 + MAC_LEN - 1 + 1) * sizeof(char));
-
- snprintf(ptr, (MAC_LEN * 2 + MAC_LEN - 1 + 1),
- "%02x:%02x:%02x:%02x:%02x:%02x", (uint8_t) mac[0],
- (uint8_t) mac[1], (uint8_t) mac[2], (uint8_t) mac[3],
- (uint8_t) mac[4], (uint8_t) mac[5]);
-
- return ptr;
-}
-
char *ecom_mac2str(char *ecom_mac)
{
char *en;
en = ecom_mac;
en += 2;
- return mac2str(en);
+ return mac2str(en, NULL, 0);
}
/* dst prefix must be AF_INET or AF_INET6 prefix, to forge EVPN prefix */
}
if( routermac)
{
- bgp_static->router_mac = XCALLOC (MTYPE_ATTR, MAC_LEN+1);
+ bgp_static->router_mac = XCALLOC (MTYPE_ATTR, ETHER_ADDR_LEN+1);
str2mac (routermac, bgp_static->router_mac);
}
if (gwip)
if(mac)
{
vty_out (vty, "/%s",(char *)mac);
- free(mac);
+ XFREE(MTYPE_TMP, mac);
}
}
}
char *esi = NULL;
if(bgp_static->router_mac)
- macrouter = mac2str(bgp_static->router_mac);
+ macrouter = mac2str(bgp_static->router_mac, NULL, 0);
if(bgp_static->eth_s_id)
esi = esi2str(bgp_static->eth_s_id);
p = &rn->p;
buf, rdbuf, p->u.prefix_evpn.eth_tag,
decode_label (bgp_static->tag), esi, buf2 , macrouter);
vty_out (vty, "%s", VTY_NEWLINE);
+ if (macrouter)
+ XFREE (MTYPE_TMP, macrouter);
}
return 0;
}