X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvnet%2Fethernet%2Finterface.c;h=a0fa61c25f49809d356edafaabe872ef29cd86f4;hb=d459bf344e20ffb38a869c9fef2211f55d766b02;hp=0f54aa1e393a66bad0da28dee61919192b61c396;hpb=dd4d8ac29202fe54e74a13ce86d1ba3f79d1555f;p=vpp.git diff --git a/src/vnet/ethernet/interface.c b/src/vnet/ethernet/interface.c index 0f54aa1e393..a0fa61c25f4 100644 --- a/src/vnet/ethernet/interface.c +++ b/src/vnet/ethernet/interface.c @@ -892,6 +892,53 @@ ethernet_get_interface (ethernet_main_t * em, u32 hw_if_index) index ? pool_elt_at_index (em->interfaces, i->hw_instance) : 0); } +mac_address_t * +ethernet_interface_add_del_address (ethernet_main_t * em, + u32 hw_if_index, const u8 * address, + u8 is_add) +{ + ethernet_interface_t *ei = ethernet_get_interface (em, hw_if_index); + mac_address_t *if_addr = 0; + + /* return if there is not an ethernet interface for this hw interface */ + if (!ei) + return 0; + + /* determine whether the address is configured on the interface */ + vec_foreach (if_addr, ei->secondary_addrs) + { + if (!ethernet_mac_address_equal (if_addr->bytes, address)) + continue; + + break; + } + + if (if_addr && vec_is_member (ei->secondary_addrs, if_addr)) + { + /* delete found address */ + if (!is_add) + { + vec_delete (ei->secondary_addrs, 1, if_addr - ei->secondary_addrs); + if_addr = 0; + } + /* address already found, so nothing needs to be done if adding */ + } + else + { + /* if_addr could be 0 or past the end of the vector. reset to 0 */ + if_addr = 0; + + /* add new address */ + if (is_add) + { + vec_add2 (ei->secondary_addrs, if_addr, 1); + clib_memcpy (&if_addr->bytes, address, sizeof (if_addr->bytes)); + } + } + + return if_addr; +} + int vnet_delete_loopback_interface (u32 sw_if_index) {