- struct ether_hdr *eth_hdr;
- struct ipv4_hdr *ipv4_hdr;
- void *tmp;
- uint8_t dst_port;
-
- eth_hdr = rte_pktmbuf_mtod(m, struct ether_hdr *);
-
- ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(m, unsigned char *) +
- sizeof(struct ether_hdr));
-
-#ifdef DO_RFC_1812_CHECKS
- /* Check to make sure the packet is valid (RFC1812) */
- if (is_valid_ipv4_pkt(ipv4_hdr, m->pkt.pkt_len) < 0) {
- rte_pktmbuf_free(m);
- return;
- }
-#endif
-
- dst_port = get_dst_port(ipv4_hdr, portid, l3fwd_lookup_struct);
- if (dst_port >= MAX_PORTS || (enabled_port_mask & 1 << dst_port) == 0)
- dst_port = portid;
-
- /* 00:09:c0:00:00:xx */
- tmp = ð_hdr->d_addr.addr_bytes[0];
- *((uint64_t *)tmp) = 0x000000c00900 + (dst_port << 24);
-
-#ifdef DO_RFC_1812_CHECKS
- /* Update time to live and header checksum */
- --(ipv4_hdr->time_to_live);
- ++(ipv4_hdr->hdr_checksum);
-#endif
-
- /* src addr */
- ether_addr_copy(&ports_eth_addr[dst_port], ð_hdr->s_addr);
-
- send_single_packet(m, dst_port);
-
-}
-
-/* main processing loop */
-static __attribute__((noreturn)) int
-main_loop(__attribute__((unused)) void *dummy)
-{
- struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
- unsigned lcore_id;
- uint64_t prev_tsc = 0;
- uint64_t diff_tsc, cur_tsc;
- int i, j, nb_rx;
- uint8_t portid, queueid;
- struct lcore_conf *qconf;
-
- lcore_id = rte_lcore_id();
- qconf = &lcore_conf[lcore_id];
-
- if (qconf->n_rx_queue == 0) {
- RTE_LOG(INFO, L3FWD, "lcore %u has nothing to do\n", lcore_id);
- while(1);
- }
-
- RTE_LOG(INFO, L3FWD, "entering main loop on lcore %u\n", lcore_id);
-
- for (i = 0; i < qconf->n_rx_queue; i++) {
-
- portid = qconf->rx_queue_list[i].port_id;
- queueid = qconf->rx_queue_list[i].queue_id;
- RTE_LOG(INFO, L3FWD, " -- lcoreid=%u portid=%hhu rxqueueid=%hhu\n", lcore_id,
- portid, queueid);
- }
-
- while (1) {
-
- cur_tsc = rte_rdtsc();
-
- /*
- * TX burst queue drain
- */
- diff_tsc = cur_tsc - prev_tsc;
- if (unlikely(diff_tsc > BURST_TX_DRAIN)) {
-
- /*
- * This could be optimized (use queueid instead of
- * portid), but it is not called so often
- */
- for (portid = 0; portid < MAX_PORTS; portid++) {
- if (qconf->tx_mbufs[portid].len == 0)
- continue;
- send_burst(&lcore_conf[lcore_id],
- qconf->tx_mbufs[portid].len,
- portid);
- qconf->tx_mbufs[portid].len = 0;
- }
-
- prev_tsc = cur_tsc;
- }
-
- /*
- * Read packet from RX queues
- */
- for (i = 0; i < qconf->n_rx_queue; ++i) {
-
- portid = qconf->rx_queue_list[i].port_id;
- queueid = qconf->rx_queue_list[i].queue_id;
- nb_rx = rte_eth_rx_burst(portid, queueid, pkts_burst, MAX_PKT_BURST);
-
- /* Prefetch first packets */
- for (j = 0; j < PREFETCH_OFFSET && j < nb_rx; j++) {
- rte_prefetch0(rte_pktmbuf_mtod(
- pkts_burst[j], void *));
- }
-
- /* Prefetch and forward already prefetched packets */
- for (j = 0; j < (nb_rx - PREFETCH_OFFSET); j++) {
- rte_prefetch0(rte_pktmbuf_mtod(pkts_burst[
- j + PREFETCH_OFFSET], void *));
- l3fwd_simple_forward(pkts_burst[j], portid, qconf->lookup_struct);
- }
-
- /* Forward remaining prefetched packets */
- for (; j < nb_rx; j++) {
- l3fwd_simple_forward(pkts_burst[j], portid, qconf->lookup_struct);
- }
- }
- }