1
2
3
4
5#ifndef __L3FWD_LPM_H__
6#define __L3FWD_LPM_H__
7
8static __rte_always_inline void
9l3fwd_lpm_simple_forward(struct rte_mbuf *m, uint16_t portid,
10 struct lcore_conf *qconf)
11{
12 struct rte_ether_hdr *eth_hdr;
13 struct rte_ipv4_hdr *ipv4_hdr;
14 uint16_t dst_port;
15
16 eth_hdr = rte_pktmbuf_mtod(m, struct rte_ether_hdr *);
17
18 if (RTE_ETH_IS_IPV4_HDR(m->packet_type)) {
19
20 ipv4_hdr = rte_pktmbuf_mtod_offset(m, struct rte_ipv4_hdr *,
21 sizeof(struct rte_ether_hdr));
22
23#ifdef DO_RFC_1812_CHECKS
24
25 if (is_valid_ipv4_pkt(ipv4_hdr, m->pkt_len) < 0) {
26 rte_pktmbuf_free(m);
27 return;
28 }
29#endif
30 dst_port = lpm_get_ipv4_dst_port(ipv4_hdr, portid,
31 qconf->ipv4_lookup_struct);
32
33 if (dst_port >= RTE_MAX_ETHPORTS ||
34 (enabled_port_mask & 1 << dst_port) == 0)
35 dst_port = portid;
36
37#ifdef DO_RFC_1812_CHECKS
38
39 --(ipv4_hdr->time_to_live);
40 ++(ipv4_hdr->hdr_checksum);
41#endif
42
43 *(uint64_t *)ð_hdr->d_addr = dest_eth_addr[dst_port];
44
45
46 rte_ether_addr_copy(&ports_eth_addr[dst_port],
47 ð_hdr->s_addr);
48
49 send_single_packet(qconf, m, dst_port);
50 } else if (RTE_ETH_IS_IPV6_HDR(m->packet_type)) {
51
52 struct rte_ipv6_hdr *ipv6_hdr;
53
54 ipv6_hdr = rte_pktmbuf_mtod_offset(m, struct rte_ipv6_hdr *,
55 sizeof(struct rte_ether_hdr));
56
57 dst_port = lpm_get_ipv6_dst_port(ipv6_hdr, portid,
58 qconf->ipv6_lookup_struct);
59
60 if (dst_port >= RTE_MAX_ETHPORTS ||
61 (enabled_port_mask & 1 << dst_port) == 0)
62 dst_port = portid;
63
64
65 *(uint64_t *)ð_hdr->d_addr = dest_eth_addr[dst_port];
66
67
68 rte_ether_addr_copy(&ports_eth_addr[dst_port],
69 ð_hdr->s_addr);
70
71 send_single_packet(qconf, m, dst_port);
72 } else {
73
74 rte_pktmbuf_free(m);
75 }
76}
77
78static inline void
79l3fwd_lpm_no_opt_send_packets(int nb_rx, struct rte_mbuf **pkts_burst,
80 uint16_t portid, struct lcore_conf *qconf)
81{
82 int32_t j;
83
84
85 for (j = 0; j < PREFETCH_OFFSET && j < nb_rx; j++)
86 rte_prefetch0(rte_pktmbuf_mtod(pkts_burst[j], void *));
87
88
89 for (j = 0; j < (nb_rx - PREFETCH_OFFSET); j++) {
90 rte_prefetch0(rte_pktmbuf_mtod(pkts_burst[
91 j + PREFETCH_OFFSET], void *));
92 l3fwd_lpm_simple_forward(pkts_burst[j], portid, qconf);
93 }
94
95
96 for (; j < nb_rx; j++)
97 l3fwd_lpm_simple_forward(pkts_burst[j], portid, qconf);
98}
99
100#endif
101