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

Function virtio_tx_route

dpdk/examples/vhost/main.c:1251–1335  ·  view source on GitHub ↗

* This function routes the TX packet to the correct interface. This * may be a local device or the physical port. */

Source from the content-addressed store, hash-verified

1249 * may be a local device or the physical port.
1250 */
1251static __rte_always_inline void
1252virtio_tx_route(struct vhost_dev *vdev, struct rte_mbuf *m, uint16_t vlan_tag)
1253{
1254 struct mbuf_table *tx_q;
1255 unsigned offset = 0;
1256 const uint16_t lcore_id = rte_lcore_id();
1257 struct rte_ether_hdr *nh;
1258
1259
1260 nh = rte_pktmbuf_mtod(m, struct rte_ether_hdr *);
1261 if (unlikely(rte_is_broadcast_ether_addr(&nh->dst_addr))) {
1262 struct vhost_dev *vdev2;
1263
1264 TAILQ_FOREACH(vdev2, &vhost_dev_list, global_vdev_entry) {
1265 if (vdev2 != vdev)
1266 sync_virtio_xmit(vdev2, vdev, m);
1267 }
1268 goto queue2nic;
1269 }
1270
1271 /*check if destination is local VM*/
1272 if ((vm2vm_mode == VM2VM_SOFTWARE) && (virtio_tx_local(vdev, m) == 0))
1273 return;
1274
1275 if (unlikely(vm2vm_mode == VM2VM_HARDWARE)) {
1276 if (unlikely(find_local_dest(vdev, m, &offset,
1277 &vlan_tag) != 0)) {
1278 rte_pktmbuf_free(m);
1279 return;
1280 }
1281 }
1282
1283 RTE_LOG_DP(DEBUG, VHOST_DATA,
1284 "(%d) TX: MAC address is external\n", vdev->vid);
1285
1286queue2nic:
1287
1288 /*Add packet to the port tx queue*/
1289 tx_q = &lcore_tx_queue[lcore_id];
1290
1291 nh = rte_pktmbuf_mtod(m, struct rte_ether_hdr *);
1292 if (unlikely(nh->ether_type == rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN))) {
1293 /* Guest has inserted the vlan tag. */
1294 struct rte_vlan_hdr *vh = (struct rte_vlan_hdr *) (nh + 1);
1295 uint16_t vlan_tag_be = rte_cpu_to_be_16(vlan_tag);
1296 if ((vm2vm_mode == VM2VM_HARDWARE) &&
1297 (vh->vlan_tci != vlan_tag_be))
1298 vh->vlan_tci = vlan_tag_be;
1299 } else {
1300 m->ol_flags |= RTE_MBUF_F_TX_VLAN;
1301
1302 /*
1303 * Find the right seg to adjust the data len when offset is
1304 * bigger than tail room size.
1305 */
1306 if (unlikely(vm2vm_mode == VM2VM_HARDWARE)) {
1307 if (likely(offset <= rte_pktmbuf_tailroom(m)))
1308 m->data_len += offset;

Callers 1

drain_virtio_txFunction · 0.85

Calls 9

rte_lcore_idFunction · 0.85
sync_virtio_xmitFunction · 0.85
virtio_tx_localFunction · 0.85
find_local_destFunction · 0.85
rte_pktmbuf_freeFunction · 0.85
rte_pktmbuf_tailroomFunction · 0.85
virtio_tx_offloadFunction · 0.85
do_drain_mbuf_tableFunction · 0.85

Tested by

no test coverage detected