+ errmsg ("missing bridge domain");
+ return -99;
+ }
+
+ M (BRIDGE_FLAGS, mp);
+
+ mp->bd_id = ntohl (bd_id);
+ mp->flags = ntohl (flags);
+ mp->is_set = is_set;
+
+ S (mp);
+ W (ret);
+ return ret;
+}
+
+static int
+api_bd_ip_mac_add_del (vat_main_t * vam)
+{
+ vl_api_address_t ip = VL_API_ZERO_ADDRESS;
+ vl_api_mac_address_t mac = { 0 };
+ unformat_input_t *i = vam->input;
+ vl_api_bd_ip_mac_add_del_t *mp;
+ ip46_type_t type;
+ u32 bd_id;
+ u8 is_ipv6 = 0;
+ u8 is_add = 1;
+ u8 bd_id_set = 0;
+ u8 ip_set = 0;
+ u8 mac_set = 0;
+ u8 macaddr[6];
+ int ret;
+
+
+ /* Parse args required to build the message */
+ while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
+ {
+ if (unformat (i, "bd_id %d", &bd_id))
+ {
+ bd_id_set++;
+ }
+ else if (unformat (i, "%U", unformat_vl_api_address, &ip))
+ {
+ ip_set++;
+ }
+ else if (unformat (i, "%U", unformat_vl_api_mac_address, &mac))
+ {
+ mac_set++;
+ }
+ else if (unformat (i, "del"))
+ is_add = 0;
+ else
+ break;
+ }
+
+ if (bd_id_set == 0)
+ {
+ errmsg ("missing bridge domain");
+ return -99;
+ }
+ else if (ip_set == 0)
+ {
+ errmsg ("missing IP address");
+ return -99;
+ }
+ else if (mac_set == 0)
+ {
+ errmsg ("missing MAC address");
+ return -99;
+ }
+
+ M (BD_IP_MAC_ADD_DEL, mp);
+
+ mp->bd_id = ntohl (bd_id);
+ mp->is_add = is_add;
+
+ clib_memcpy (&mp->ip, &ip, sizeof (ip));
+ clib_memcpy (&mp->mac, &mac, sizeof (mac));
+
+ S (mp);
+ W (ret);
+ return ret;
+}
+
+static int
+api_bd_ip_mac_flush (vat_main_t * vam)
+{
+ unformat_input_t *i = vam->input;
+ vl_api_bd_ip_mac_flush_t *mp;
+ u32 bd_id;
+ u8 bd_id_set = 0;
+ int ret;
+
+ while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
+ {
+ if (unformat (i, "bd_id %d", &bd_id))
+ {
+ bd_id_set++;
+ }
+ else
+ break;
+ }
+
+ if (bd_id_set == 0)
+ {
+ errmsg ("missing bridge domain");
+ return -99;
+ }
+
+ M (BD_IP_MAC_FLUSH, mp);
+
+ mp->bd_id = ntohl (bd_id);
+
+ S (mp);
+ W (ret);
+ return ret;
+}
+
+static void vl_api_bd_ip_mac_details_t_handler
+ (vl_api_bd_ip_mac_details_t * mp)
+{
+ vat_main_t *vam = &vat_main;
+ u8 *ip = 0;
+
+ if (!mp->is_ipv6)
+ ip =
+ format (0, "%U", format_ip4_address, (ip4_address_t *) mp->ip_address);
+ else
+ ip =
+ format (0, "%U", format_ip6_address, (ip6_address_t *) mp->ip_address);
+
+ print (vam->ofp,
+ "\n%-5d %-7s %-20U %-30s",
+ ntohl (mp->bd_id), mp->is_ipv6 ? "ip6" : "ip4",
+ format_ethernet_address, mp->mac_address, ip);
+
+ vec_free (ip);
+}
+
+static void vl_api_bd_ip_mac_details_t_handler_json
+ (vl_api_bd_ip_mac_details_t * mp)
+{
+ vat_main_t *vam = &vat_main;
+ vat_json_node_t *node = NULL;
+
+ if (VAT_JSON_ARRAY != vam->json_tree.type)
+ {
+ ASSERT (VAT_JSON_NONE == vam->json_tree.type);
+ vat_json_init_array (&vam->json_tree);
+ }
+ node = vat_json_array_add (&vam->json_tree);
+
+ vat_json_init_object (node);
+ vat_json_object_add_uint (node, "bd_id", ntohl (mp->bd_id));
+ vat_json_object_add_uint (node, "is_ipv6", mp->is_ipv6);
+ vat_json_object_add_string_copy (node, "mac_address",
+ format (0, "%U", format_ethernet_address,
+ &mp->mac_address));
+ u8 *ip = 0;
+
+ if (!mp->is_ipv6)
+ ip =
+ format (0, "%U", format_ip4_address, (ip4_address_t *) mp->ip_address);
+ else
+ ip =
+ format (0, "%U", format_ip6_address, (ip6_address_t *) mp->ip_address);
+ vat_json_object_add_string_copy (node, "ip_address", ip);
+ vec_free (ip);
+}
+
+static int
+api_bd_ip_mac_dump (vat_main_t * vam)
+{
+ unformat_input_t *i = vam->input;
+ vl_api_bd_ip_mac_dump_t *mp;
+ vl_api_control_ping_t *mp_ping;
+ int ret;
+ u32 bd_id;
+ u8 bd_id_set = 0;
+
+ while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
+ {
+ if (unformat (i, "bd_id %d", &bd_id))
+ {
+ bd_id_set++;
+ }
+ else
+ break;
+ }
+
+ print (vam->ofp,
+ "\n%-5s %-7s %-20s %-30s",
+ "bd_id", "is_ipv6", "mac_address", "ip_address");
+
+ /* Dump Bridge Domain Ip to Mac entries */
+ M (BD_IP_MAC_DUMP, mp);
+
+ if (bd_id_set)
+ mp->bd_id = htonl (bd_id);
+ else
+ mp->bd_id = ~0;
+
+ S (mp);
+
+ /* Use a control ping for synchronization */
+ MPING (CONTROL_PING, mp_ping);
+ S (mp_ping);
+
+ W (ret);
+ return ret;
+}
+
+static int
+api_tap_create_v2 (vat_main_t * vam)
+{
+ unformat_input_t *i = vam->input;
+ vl_api_tap_create_v2_t *mp;
+ u8 mac_address[6];
+ u8 random_mac = 1;
+ u32 id = ~0;
+ u8 *host_if_name = 0;
+ u8 *host_ns = 0;
+ u8 host_mac_addr[6];
+ u8 host_mac_addr_set = 0;
+ u8 *host_bridge = 0;
+ ip4_address_t host_ip4_addr;
+ ip4_address_t host_ip4_gw;
+ u8 host_ip4_gw_set = 0;
+ u32 host_ip4_prefix_len = 0;
+ ip6_address_t host_ip6_addr;
+ ip6_address_t host_ip6_gw;
+ u8 host_ip6_gw_set = 0;
+ u32 host_ip6_prefix_len = 0;
+ int ret;
+ u32 rx_ring_sz = 0, tx_ring_sz = 0;
+
+ clib_memset (mac_address, 0, sizeof (mac_address));
+
+ /* Parse args required to build the message */
+ while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
+ {
+ if (unformat (i, "hw-addr %U", unformat_ethernet_address, mac_address))
+ {
+ random_mac = 0;
+ }
+ else if (unformat (i, "id %u", &id))
+ ;
+ else if (unformat (i, "host-if-name %s", &host_if_name))
+ ;
+ else if (unformat (i, "host-ns %s", &host_ns))
+ ;
+ else if (unformat (i, "host-mac-addr %U", unformat_ethernet_address,
+ host_mac_addr))
+ host_mac_addr_set = 1;
+ else if (unformat (i, "host-bridge %s", &host_bridge))
+ ;
+ else if (unformat (i, "host-ip4-addr %U/%d", unformat_ip4_address,
+ &host_ip4_addr, &host_ip4_prefix_len))
+ ;
+ else if (unformat (i, "host-ip6-addr %U/%d", unformat_ip6_address,
+ &host_ip6_addr, &host_ip6_prefix_len))
+ ;
+ else if (unformat (i, "host-ip4-gw %U", unformat_ip4_address,
+ &host_ip4_gw))
+ host_ip4_gw_set = 1;
+ else if (unformat (i, "host-ip6-gw %U", unformat_ip6_address,
+ &host_ip6_gw))
+ host_ip6_gw_set = 1;
+ else if (unformat (i, "rx-ring-size %d", &rx_ring_sz))
+ ;
+ else if (unformat (i, "tx-ring-size %d", &tx_ring_sz))
+ ;
+ else
+ break;
+ }
+
+ if (vec_len (host_if_name) > 63)
+ {
+ errmsg ("tap name too long. ");
+ return -99;
+ }
+ if (vec_len (host_ns) > 63)
+ {
+ errmsg ("host name space too long. ");
+ return -99;
+ }
+ if (vec_len (host_bridge) > 63)
+ {
+ errmsg ("host bridge name too long. ");
+ return -99;
+ }
+ if (host_ip4_prefix_len > 32)
+ {
+ errmsg ("host ip4 prefix length not valid. ");
+ return -99;
+ }
+ if (host_ip6_prefix_len > 128)
+ {
+ errmsg ("host ip6 prefix length not valid. ");
+ return -99;
+ }
+ if (!is_pow2 (rx_ring_sz))
+ {
+ errmsg ("rx ring size must be power of 2. ");
+ return -99;
+ }
+ if (rx_ring_sz > 32768)
+ {
+ errmsg ("rx ring size must be 32768 or lower. ");
+ return -99;
+ }
+ if (!is_pow2 (tx_ring_sz))
+ {
+ errmsg ("tx ring size must be power of 2. ");
+ return -99;
+ }
+ if (tx_ring_sz > 32768)
+ {
+ errmsg ("tx ring size must be 32768 or lower. ");