MCPcopy Create free account
hub / github.com/F-Stack/f-stack / sad_lookup

Function sad_lookup

dpdk/examples/ipsec-secgw/sad.h:60–168  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

58}
59
60static inline void
61sad_lookup(struct ipsec_sad *sad, struct rte_mbuf *pkts[],
62 void *sa[], uint16_t nb_pkts)
63{
64 uint32_t i;
65 uint32_t nb_v4 = 0, nb_v6 = 0;
66 struct rte_esp_hdr *esp;
67 struct rte_ipv4_hdr *ipv4;
68 struct rte_ipv6_hdr *ipv6;
69 struct rte_ipsec_sadv4_key v4[nb_pkts];
70 struct rte_ipsec_sadv6_key v6[nb_pkts];
71 int v4_idxes[nb_pkts];
72 int v6_idxes[nb_pkts];
73 const union rte_ipsec_sad_key *keys_v4[nb_pkts];
74 const union rte_ipsec_sad_key *keys_v6[nb_pkts];
75 void *v4_res[nb_pkts];
76 void *v6_res[nb_pkts];
77 uint32_t spi, cache_idx;
78 struct ipsec_sad_cache *cache;
79 struct ipsec_sa *cached_sa;
80 uint16_t udp_hdr_len = 0;
81 int is_ipv4;
82
83 cache = &RTE_PER_LCORE(sad_cache);
84
85 /* split received packets by address family into two arrays */
86 for (i = 0; i < nb_pkts; i++) {
87 ipv4 = rte_pktmbuf_mtod(pkts[i], struct rte_ipv4_hdr *);
88 ipv6 = rte_pktmbuf_mtod(pkts[i], struct rte_ipv6_hdr *);
89 if ((pkts[i]->packet_type &
90 (RTE_PTYPE_TUNNEL_MASK | RTE_PTYPE_L4_MASK)) ==
91 MBUF_PTYPE_TUNNEL_ESP_IN_UDP)
92 udp_hdr_len = sizeof(struct rte_udp_hdr);
93 esp = rte_pktmbuf_mtod_offset(pkts[i], struct rte_esp_hdr *,
94 pkts[i]->l3_len + udp_hdr_len);
95
96 is_ipv4 = pkts[i]->packet_type & RTE_PTYPE_L3_IPV4;
97 spi = rte_be_to_cpu_32(esp->spi);
98 cache_idx = SPI2IDX(spi, cache->mask);
99
100 if (is_ipv4) {
101 cached_sa = (cache->mask != 0) ?
102 cache->v4[cache_idx] : NULL;
103 /* check SAD cache entry */
104 if ((cached_sa != NULL) && (cached_sa->spi == spi)) {
105 if (cmp_sa_key(cached_sa, 1, ipv4, ipv6)) {
106 /* cache hit */
107 sa[i] = cached_sa;
108 continue;
109 }
110 }
111 /*
112 * cache miss
113 * preparing sad key to proceed with sad lookup
114 */
115 v4[nb_v4].spi = esp->spi;
116 v4[nb_v4].dip = ipv4->dst_addr;
117 v4[nb_v4].sip = ipv4->src_addr;

Callers 3

inbound_sa_lookupFunction · 0.85
process_ipsec_ev_inboundFunction · 0.85

Calls 4

cmp_sa_keyFunction · 0.85
rte_ipsec_sad_lookupFunction · 0.85
sa_cache_updateFunction · 0.85
memcpyFunction · 0.50

Tested by

no test coverage detected