4 * Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #ifndef __L3FWD_LPM_H__
35 #define __L3FWD_LPM_H__
37 static __rte_always_inline void
38 l3fwd_lpm_simple_forward(struct rte_mbuf *m, uint8_t portid,
39 struct lcore_conf *qconf)
41 struct ether_hdr *eth_hdr;
42 struct ipv4_hdr *ipv4_hdr;
45 eth_hdr = rte_pktmbuf_mtod(m, struct ether_hdr *);
47 if (RTE_ETH_IS_IPV4_HDR(m->packet_type)) {
48 /* Handle IPv4 headers.*/
49 ipv4_hdr = rte_pktmbuf_mtod_offset(m, struct ipv4_hdr *,
50 sizeof(struct ether_hdr));
52 #ifdef DO_RFC_1812_CHECKS
53 /* Check to make sure the packet is valid (RFC1812) */
54 if (is_valid_ipv4_pkt(ipv4_hdr, m->pkt_len) < 0) {
59 dst_port = lpm_get_ipv4_dst_port(ipv4_hdr, portid,
60 qconf->ipv4_lookup_struct);
62 if (dst_port >= RTE_MAX_ETHPORTS ||
63 (enabled_port_mask & 1 << dst_port) == 0)
66 #ifdef DO_RFC_1812_CHECKS
67 /* Update time to live and header checksum */
68 --(ipv4_hdr->time_to_live);
69 ++(ipv4_hdr->hdr_checksum);
72 *(uint64_t *)ð_hdr->d_addr = dest_eth_addr[dst_port];
75 ether_addr_copy(&ports_eth_addr[dst_port], ð_hdr->s_addr);
77 send_single_packet(qconf, m, dst_port);
78 } else if (RTE_ETH_IS_IPV6_HDR(m->packet_type)) {
79 /* Handle IPv6 headers.*/
80 struct ipv6_hdr *ipv6_hdr;
82 ipv6_hdr = rte_pktmbuf_mtod_offset(m, struct ipv6_hdr *,
83 sizeof(struct ether_hdr));
85 dst_port = lpm_get_ipv6_dst_port(ipv6_hdr, portid,
86 qconf->ipv6_lookup_struct);
88 if (dst_port >= RTE_MAX_ETHPORTS ||
89 (enabled_port_mask & 1 << dst_port) == 0)
93 *(uint64_t *)ð_hdr->d_addr = dest_eth_addr[dst_port];
96 ether_addr_copy(&ports_eth_addr[dst_port], ð_hdr->s_addr);
98 send_single_packet(qconf, m, dst_port);
100 /* Free the mbuf that contains non-IPV4/IPV6 packet */
106 l3fwd_lpm_no_opt_send_packets(int nb_rx, struct rte_mbuf **pkts_burst,
107 uint8_t portid, struct lcore_conf *qconf)
111 /* Prefetch first packets */
112 for (j = 0; j < PREFETCH_OFFSET && j < nb_rx; j++)
113 rte_prefetch0(rte_pktmbuf_mtod(pkts_burst[j], void *));
115 /* Prefetch and forward already prefetched packets. */
116 for (j = 0; j < (nb_rx - PREFETCH_OFFSET); j++) {
117 rte_prefetch0(rte_pktmbuf_mtod(pkts_burst[
118 j + PREFETCH_OFFSET], void *));
119 l3fwd_lpm_simple_forward(pkts_burst[j], portid, qconf);
122 /* Forward remaining prefetched packets */
123 for (; j < nb_rx; j++)
124 l3fwd_lpm_simple_forward(pkts_burst[j], portid, qconf);
127 #endif /* __L3FWD_LPM_H__ */