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 ether_hdr *eth_hdr;
13 struct ipv4_hdr *ipv4_hdr;
18 eth_hdr = rte_pktmbuf_mtod(m, struct 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 ipv4_hdr *,
25 sizeof(struct 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 ether_addr_copy(&ports_eth_addr[dst_port], ð_hdr->s_addr);
52 send_single_packet(qconf, m, dst_port);
53 } else if (tcp_or_udp && (l3_ptypes == RTE_PTYPE_L3_IPV6)) {
54 /* Handle IPv6 headers.*/
55 struct ipv6_hdr *ipv6_hdr;
57 ipv6_hdr = rte_pktmbuf_mtod_offset(m, struct ipv6_hdr *,
58 sizeof(struct ether_hdr));
60 dst_port = em_get_ipv6_dst_port(ipv6_hdr, portid,
61 qconf->ipv6_lookup_struct);
63 if (dst_port >= RTE_MAX_ETHPORTS ||
64 (enabled_port_mask & 1 << dst_port) == 0)
68 *(uint64_t *)ð_hdr->d_addr = dest_eth_addr[dst_port];
71 ether_addr_copy(&ports_eth_addr[dst_port], ð_hdr->s_addr);
73 send_single_packet(qconf, m, dst_port);
75 /* Free the mbuf that contains non-IPV4/IPV6 packet */
81 * Buffer non-optimized handling of packets, invoked
85 l3fwd_em_no_opt_send_packets(int nb_rx, struct rte_mbuf **pkts_burst,
86 uint16_t portid, struct lcore_conf *qconf)
90 /* Prefetch first packets */
91 for (j = 0; j < PREFETCH_OFFSET && j < nb_rx; j++)
92 rte_prefetch0(rte_pktmbuf_mtod(pkts_burst[j], void *));
95 * Prefetch and forward already prefetched
98 for (j = 0; j < (nb_rx - PREFETCH_OFFSET); j++) {
99 rte_prefetch0(rte_pktmbuf_mtod(pkts_burst[
100 j + PREFETCH_OFFSET], void *));
101 l3fwd_em_simple_forward(pkts_burst[j], portid, qconf);
104 /* Forward remaining prefetched packets */
105 for (; j < nb_rx; j++)
106 l3fwd_em_simple_forward(pkts_burst[j], portid, qconf);
109 #endif /* __L3FWD_EM_H__ */