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>
29 #include "hash_entry_types.h"
33 struct qinq_hdr qinq_hdr;
35 struct ether_hdr ether_hdr;
37 struct ipv4_hdr ipv4_hdr;
38 struct udp_hdr udp_hdr;
39 } __attribute__((packed));
41 struct cpe_packet_arp {
42 struct qinq_hdr qinq_hdr;
44 } __attribute__((packed));
46 /* Struct used for setting all the values a packet
47 going to the core netwerk. Payload may follow
48 after the headers, but no need to touch that. */
49 struct core_net_pkt_m {
50 struct ether_hdr ether_hdr;
57 struct ipv4_hdr tunnel_ip_hdr;
58 struct gre_hdr gre_hdr;
59 struct ipv4_hdr ip_hdr;
60 struct udp_hdr udp_hdr;
61 } __attribute__((packed));
64 struct ether_hdr ether_hdr;
65 struct ipv4_hdr tunnel_ip_hdr;
66 struct gre_hdr gre_hdr;
67 struct ipv4_hdr ip_hdr;
68 struct udp_hdr udp_hdr;
69 } __attribute__((packed));
71 #define UPSTREAM_DELTA ((uint32_t)(sizeof(struct core_net_pkt) - sizeof(struct cpe_pkt)))
72 #define DOWNSTREAM_DELTA ((uint32_t)(sizeof(struct core_net_pkt_m) - sizeof(struct cpe_pkt)))
74 struct cpe_pkt_delta {
75 uint8_t encap[DOWNSTREAM_DELTA];
77 } __attribute__((packed));
79 static inline void extract_key_cpe(struct rte_mbuf *mbuf, uint64_t* key)
81 uint8_t* packet = rte_pktmbuf_mtod(mbuf, uint8_t*);
83 *key = (*(uint64_t *)(packet + 12)) & 0xFF0FFFFFFF0FFFFF;
85 *key = rte_bswap32(*(uint32_t *)(packet + 26)) & 0x00FFFFFF;
89 static inline void key_core(struct gre_hdr* gre, __attribute__((unused)) struct ipv4_hdr* ip, uint64_t* key)
91 struct cpe_key *cpe_key = (struct cpe_key*)key;
93 cpe_key->gre_id = rte_be_to_cpu_32(gre->gre_id) & 0xFFFFFFF;
96 cpe_key->ip = ip->dst_addr;
102 static inline void extract_key_core(struct rte_mbuf *mbuf, uint64_t* key)
104 struct core_net_pkt *packet = rte_pktmbuf_mtod(mbuf, struct core_net_pkt *);
105 key_core(&packet->gre_hdr, &packet->ip_hdr, key);
108 static inline void extract_key_core_m(struct rte_mbuf *mbuf, uint64_t* key)
110 struct core_net_pkt_m *packet = rte_pktmbuf_mtod(mbuf, struct core_net_pkt_m *);
111 key_core(&packet->gre_hdr, &packet->ip_hdr, key);
114 #endif /* _BNG_PKTS_H_ */