1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2016 Intel Corporation
8 static __rte_always_inline uint16_t
9 l3fwd_em_handle_ipv4(struct rte_mbuf *m, uint16_t portid,
10 struct rte_ether_hdr *eth_hdr, struct lcore_conf *qconf)
12 struct rte_ipv4_hdr *ipv4_hdr;
15 /* Handle IPv4 headers.*/
16 ipv4_hdr = rte_pktmbuf_mtod_offset(m, struct rte_ipv4_hdr *,
17 sizeof(struct rte_ether_hdr));
19 #ifdef DO_RFC_1812_CHECKS
20 /* Check to make sure the packet is valid (RFC1812) */
21 if (is_valid_ipv4_pkt(ipv4_hdr, m->pkt_len) < 0) {
26 dst_port = em_get_ipv4_dst_port(ipv4_hdr, portid,
27 qconf->ipv4_lookup_struct);
29 if (dst_port >= RTE_MAX_ETHPORTS ||
30 (enabled_port_mask & 1 << dst_port) == 0)
33 #ifdef DO_RFC_1812_CHECKS
34 /* Update time to live and header checksum */
35 --(ipv4_hdr->time_to_live);
36 ++(ipv4_hdr->hdr_checksum);
39 *(uint64_t *)ð_hdr->d_addr = dest_eth_addr[dst_port];
42 rte_ether_addr_copy(&ports_eth_addr[dst_port],
48 static __rte_always_inline uint16_t
49 l3fwd_em_handle_ipv6(struct rte_mbuf *m, uint16_t portid,
50 struct rte_ether_hdr *eth_hdr, struct lcore_conf *qconf)
52 /* Handle IPv6 headers.*/
53 struct rte_ipv6_hdr *ipv6_hdr;
56 ipv6_hdr = rte_pktmbuf_mtod_offset(m, struct rte_ipv6_hdr *,
57 sizeof(struct rte_ether_hdr));
59 dst_port = em_get_ipv6_dst_port(ipv6_hdr, portid,
60 qconf->ipv6_lookup_struct);
62 if (dst_port >= RTE_MAX_ETHPORTS ||
63 (enabled_port_mask & 1 << dst_port) == 0)
67 *(uint64_t *)ð_hdr->d_addr = dest_eth_addr[dst_port];
70 rte_ether_addr_copy(&ports_eth_addr[dst_port],
76 static __rte_always_inline void
77 l3fwd_em_simple_forward(struct rte_mbuf *m, uint16_t portid,
78 struct lcore_conf *qconf)
80 struct rte_ether_hdr *eth_hdr;
85 eth_hdr = rte_pktmbuf_mtod(m, struct rte_ether_hdr *);
86 tcp_or_udp = m->packet_type & (RTE_PTYPE_L4_TCP | RTE_PTYPE_L4_UDP);
87 l3_ptypes = m->packet_type & RTE_PTYPE_L3_MASK;
89 if (tcp_or_udp && (l3_ptypes == RTE_PTYPE_L3_IPV4)) {
90 dst_port = l3fwd_em_handle_ipv4(m, portid, eth_hdr, qconf);
91 send_single_packet(qconf, m, dst_port);
92 } else if (tcp_or_udp && (l3_ptypes == RTE_PTYPE_L3_IPV6)) {
93 dst_port = l3fwd_em_handle_ipv6(m, portid, eth_hdr, qconf);
94 send_single_packet(qconf, m, dst_port);
96 /* Free the mbuf that contains non-IPV4/IPV6 packet */
101 static __rte_always_inline void
102 l3fwd_em_simple_process(struct rte_mbuf *m, struct lcore_conf *qconf)
104 struct rte_ether_hdr *eth_hdr;
108 eth_hdr = rte_pktmbuf_mtod(m, struct rte_ether_hdr *);
109 tcp_or_udp = m->packet_type & (RTE_PTYPE_L4_TCP | RTE_PTYPE_L4_UDP);
110 l3_ptypes = m->packet_type & RTE_PTYPE_L3_MASK;
112 if (tcp_or_udp && (l3_ptypes == RTE_PTYPE_L3_IPV4))
113 m->port = l3fwd_em_handle_ipv4(m, m->port, eth_hdr, qconf);
114 else if (tcp_or_udp && (l3_ptypes == RTE_PTYPE_L3_IPV6))
115 m->port = l3fwd_em_handle_ipv6(m, m->port, eth_hdr, qconf);
121 * Buffer non-optimized handling of packets, invoked
125 l3fwd_em_no_opt_send_packets(int nb_rx, struct rte_mbuf **pkts_burst,
126 uint16_t portid, struct lcore_conf *qconf)
130 /* Prefetch first packets */
131 for (j = 0; j < PREFETCH_OFFSET && j < nb_rx; j++)
132 rte_prefetch0(rte_pktmbuf_mtod(pkts_burst[j], void *));
135 * Prefetch and forward already prefetched
138 for (j = 0; j < (nb_rx - PREFETCH_OFFSET); j++) {
139 rte_prefetch0(rte_pktmbuf_mtod(pkts_burst[
140 j + PREFETCH_OFFSET], void *));
141 l3fwd_em_simple_forward(pkts_burst[j], portid, qconf);
144 /* Forward remaining prefetched packets */
145 for (; j < nb_rx; j++)
146 l3fwd_em_simple_forward(pkts_burst[j], portid, qconf);
150 * Buffer non-optimized handling of events, invoked
154 l3fwd_em_no_opt_process_events(int nb_rx, struct rte_event **events,
155 struct lcore_conf *qconf)
159 /* Prefetch first packets */
160 for (j = 0; j < PREFETCH_OFFSET && j < nb_rx; j++)
161 rte_prefetch0(rte_pktmbuf_mtod(events[j]->mbuf, void *));
164 * Prefetch and forward already prefetched
167 for (j = 0; j < (nb_rx - PREFETCH_OFFSET); j++) {
168 rte_prefetch0(rte_pktmbuf_mtod(events[
169 j + PREFETCH_OFFSET]->mbuf, void *));
170 l3fwd_em_simple_process(events[j]->mbuf, qconf);
173 /* Forward remaining prefetched packets */
174 for (; j < nb_rx; j++)
175 l3fwd_em_simple_process(events[j]->mbuf, qconf);
178 #endif /* __L3FWD_EM_H__ */