2 // Copyright (c) 2010-2017 Intel Corporation
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
20 #include <rte_ether.h>
23 #include <rte_byteorder.h>
25 #include "prox_compat.h"
30 #include "hash_entry_types.h"
34 struct qinq_hdr qinq_hdr;
36 prox_rte_ether_hdr ether_hdr;
38 prox_rte_ipv4_hdr ipv4_hdr;
39 prox_rte_udp_hdr udp_hdr;
40 } __attribute__((packed));
42 struct cpe_packet_arp {
43 struct qinq_hdr qinq_hdr;
45 } __attribute__((packed));
47 /* Struct used for setting all the values a packet
48 going to the core netwerk. Payload may follow
49 after the headers, but no need to touch that. */
50 struct core_net_pkt_m {
51 prox_rte_ether_hdr ether_hdr;
58 prox_rte_ipv4_hdr tunnel_ip_hdr;
59 struct gre_hdr gre_hdr;
60 prox_rte_ipv4_hdr ip_hdr;
61 prox_rte_udp_hdr udp_hdr;
62 } __attribute__((packed));
65 prox_rte_ether_hdr ether_hdr;
66 prox_rte_ipv4_hdr tunnel_ip_hdr;
67 struct gre_hdr gre_hdr;
68 prox_rte_ipv4_hdr ip_hdr;
69 prox_rte_udp_hdr udp_hdr;
70 } __attribute__((packed));
72 #define UPSTREAM_DELTA ((uint32_t)(sizeof(struct core_net_pkt) - sizeof(struct cpe_pkt)))
73 #define DOWNSTREAM_DELTA ((uint32_t)(sizeof(struct core_net_pkt_m) - sizeof(struct cpe_pkt)))
75 struct cpe_pkt_delta {
76 uint8_t encap[DOWNSTREAM_DELTA];
78 } __attribute__((packed));
80 static inline void extract_key_cpe(struct rte_mbuf *mbuf, uint64_t* key)
82 uint8_t* packet = rte_pktmbuf_mtod(mbuf, uint8_t*);
84 *key = (*(uint64_t *)(packet + 12)) & 0xFF0FFFFFFF0FFFFF;
86 *key = rte_bswap32(*(uint32_t *)(packet + 26)) & 0x00FFFFFF;
90 static inline void key_core(struct gre_hdr* gre, __attribute__((unused)) prox_rte_ipv4_hdr* ip, uint64_t* key)
92 struct cpe_key *cpe_key = (struct cpe_key*)key;
94 cpe_key->gre_id = rte_be_to_cpu_32(gre->gre_id) & 0xFFFFFFF;
97 cpe_key->ip = ip->dst_addr;
103 static inline void extract_key_core(struct rte_mbuf *mbuf, uint64_t* key)
105 struct core_net_pkt *packet = rte_pktmbuf_mtod(mbuf, struct core_net_pkt *);
106 key_core(&packet->gre_hdr, &packet->ip_hdr, key);
109 static inline void extract_key_core_m(struct rte_mbuf *mbuf, uint64_t* key)
111 struct core_net_pkt_m *packet = rte_pktmbuf_mtod(mbuf, struct core_net_pkt_m *);
112 key_core(&packet->gre_hdr, &packet->ip_hdr, key);
115 #endif /* _BNG_PKTS_H_ */