MCPcopy Create free account
hub / github.com/F-Stack/f-stack / link_vmdq

Function link_vmdq

dpdk/examples/vhost/main.c:941–984  ·  view source on GitHub ↗

* This function learns the MAC address of the device and registers this along with a * vlan tag to a VMDQ. */

Source from the content-addressed store, hash-verified

939 * vlan tag to a VMDQ.
940 */
941static int
942link_vmdq(struct vhost_dev *vdev, struct rte_mbuf *m)
943{
944 struct rte_ether_hdr *pkt_hdr;
945 int i, ret;
946
947 /* Learn MAC address of guest device from packet */
948 pkt_hdr = rte_pktmbuf_mtod(m, struct rte_ether_hdr *);
949
950 if (find_vhost_dev(&pkt_hdr->src_addr)) {
951 RTE_LOG(ERR, VHOST_DATA,
952 "(%d) device is using a registered MAC!\n",
953 vdev->vid);
954 return -1;
955 }
956
957 for (i = 0; i < RTE_ETHER_ADDR_LEN; i++)
958 vdev->mac_address.addr_bytes[i] =
959 pkt_hdr->src_addr.addr_bytes[i];
960
961 /* vlan_tag currently uses the device_id. */
962 vdev->vlan_tag = vlan_tags[vdev->vid];
963
964 /* Print out VMDQ registration info. */
965 RTE_LOG(INFO, VHOST_DATA,
966 "(%d) mac " RTE_ETHER_ADDR_PRT_FMT " and vlan %d registered\n",
967 vdev->vid, RTE_ETHER_ADDR_BYTES(&vdev->mac_address),
968 vdev->vlan_tag);
969
970 /* Register the MAC address. */
971 ret = rte_eth_dev_mac_addr_add(ports[0], &vdev->mac_address,
972 (uint32_t)vdev->vid + vmdq_pool_base);
973 if (ret)
974 RTE_LOG(ERR, VHOST_DATA,
975 "(%d) failed to add device MAC address to VMDQ\n",
976 vdev->vid);
977
978 rte_eth_dev_set_vlan_strip_on_queue(ports[0], vdev->vmdq_rx_q, 1);
979
980 /* Set device as ready for RX. */
981 vdev->ready = DEVICE_RX;
982
983 return 0;
984}
985
986/*
987 * Removes MAC address and vlan tag from VMDQ. Ensures that nothing is adding buffers to the RX

Callers 1

drain_virtio_txFunction · 0.85

Calls 3

find_vhost_devFunction · 0.85
rte_eth_dev_mac_addr_addFunction · 0.85

Tested by

no test coverage detected