1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2016 Intel Corporation
8 static __rte_always_inline void
9 l3fwd_em_simple_forward(struct rte_mbuf *m, uint16_t portid,
10 struct lcore_conf *qconf)
12 struct rte_ether_hdr *eth_hdr;
13 struct rte_ipv4_hdr *ipv4_hdr;
18 eth_hdr = rte_pktmbuf_mtod(m, struct rte_ether_hdr *);
19 tcp_or_udp = m->packet_type & (RTE_PTYPE_L4_TCP | RTE_PTYPE_L4_UDP);
20 l3_ptypes = m->packet_type & RTE_PTYPE_L3_MASK;
22 if (tcp_or_udp && (l3_ptypes == RTE_PTYPE_L3_IPV4)) {
23 /* Handle IPv4 headers.*/
24 ipv4_hdr = rte_pktmbuf_mtod_offset(m, struct rte_ipv4_hdr *,
25 sizeof(struct rte_ether_hdr));
27 #ifdef DO_RFC_1812_CHECKS
28 /* Check to make sure the packet is valid (RFC1812) */
29 if (is_valid_ipv4_pkt(ipv4_hdr, m->pkt_len) < 0) {
34 dst_port = em_get_ipv4_dst_port(ipv4_hdr, portid,
35 qconf->ipv4_lookup_struct);
37 if (dst_port >= RTE_MAX_ETHPORTS ||
38 (enabled_port_mask & 1 << dst_port) == 0)
41 #ifdef DO_RFC_1812_CHECKS
42 /* Update time to live and header checksum */
43 --(ipv4_hdr->time_to_live);
44 ++(ipv4_hdr->hdr_checksum);
47 *(uint64_t *)ð_hdr->d_addr = dest_eth_addr[dst_port];
50 rte_ether_addr_copy(&ports_eth_addr[dst_port],
53 send_single_packet(qconf, m, dst_port);
54 } else if (tcp_or_udp && (l3_ptypes == RTE_PTYPE_L3_IPV6)) {
55 /* Handle IPv6 headers.*/
56 struct rte_ipv6_hdr *ipv6_hdr;
58 ipv6_hdr = rte_pktmbuf_mtod_offset(m, struct rte_ipv6_hdr *,
59 sizeof(struct rte_ether_hdr));
61 dst_port = em_get_ipv6_dst_port(ipv6_hdr, portid,
62 qconf->ipv6_lookup_struct);
64 if (dst_port >= RTE_MAX_ETHPORTS ||
65 (enabled_port_mask & 1 << dst_port) == 0)
69 *(uint64_t *)ð_hdr->d_addr = dest_eth_addr[dst_port];
72 rte_ether_addr_copy(&ports_eth_addr[dst_port],
75 send_single_packet(qconf, m, dst_port);
77 /* Free the mbuf that contains non-IPV4/IPV6 packet */
83 * Buffer non-optimized handling of packets, invoked
87 l3fwd_em_no_opt_send_packets(int nb_rx, struct rte_mbuf **pkts_burst,
88 uint16_t portid, struct lcore_conf *qconf)
92 /* Prefetch first packets */
93 for (j = 0; j < PREFETCH_OFFSET && j < nb_rx; j++)
94 rte_prefetch0(rte_pktmbuf_mtod(pkts_burst[j], void *));
97 * Prefetch and forward already prefetched
100 for (j = 0; j < (nb_rx - PREFETCH_OFFSET); j++) {
101 rte_prefetch0(rte_pktmbuf_mtod(pkts_burst[
102 j + PREFETCH_OFFSET], void *));
103 l3fwd_em_simple_forward(pkts_burst[j], portid, qconf);
106 /* Forward remaining prefetched packets */
107 for (; j < nb_rx; j++)
108 l3fwd_em_simple_forward(pkts_burst[j], portid, qconf);
111 #endif /* __L3FWD_EM_H__ */