Fix minor compilation issue on recent gcc compilers
[samplevnf.git] / VNFs / DPPD-PROX / handle_qinq_encap4.h
1 /*
2 // Copyright (c) 2010-2017 Intel Corporation
3 //
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
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
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.
15 */
16
17 #ifndef _HANDLE_QINQ_ENCAP4_H_
18 #define _HANDLE_QINQ_ENCAP4_H_
19
20 #include <rte_ip.h>
21 #include <rte_ether.h>
22
23 #include "log.h"
24 #include "prox_assert.h"
25 #include "etypes.h"
26 #include "mpls.h"
27 #include "task_init.h"
28 #include "handle_sched.h"
29
30 struct task_qinq_encap4 {
31         struct task_base base;
32         struct rte_table_hash  *cpe_table;
33         uint16_t         qinq_tag;
34         uint64_t         src_mac[PROX_MAX_PORTS];
35         int              offload_crc;
36         uint8_t          runtime_flags;
37         uint8_t          *dscp;
38         uint64_t         keys[64];
39         struct rte_mbuf* fake_packets[64];
40         uint64_t         cpe_timeout;
41 #ifdef ENABLE_EXTRA_USER_STATISTICS
42         uint32_t        *stats_per_user;
43         uint32_t        n_users;
44 #endif
45         struct rte_sched_port *sched_port;
46 };
47
48 struct qinq_gre_entry {
49         uint16_t svlan;
50         uint16_t cvlan;
51         uint32_t gre_id;
52         uint32_t user;
53         uint32_t rss; // RSS based on Toeplitz_hash(svlan and cvlan)
54 };
55
56 struct qinq_gre_map {
57         uint32_t              count;
58         struct qinq_gre_entry entries[0];
59 };
60
61 struct qinq_gre_map *get_qinq_gre_map(struct task_args *targ);
62
63 struct task_args;
64 struct prox_shared;
65
66 void init_qinq_gre_table(struct task_args *targ, struct qinq_gre_map *qinq_gre_map);
67 void init_qinq_gre_hash(struct task_args *targ, struct qinq_gre_map *qinq_gre_map);
68 void init_cpe4_table(struct task_args *targ);
69 void init_cpe4_hash(struct task_args *targ);
70
71 static inline uint8_t mpls_untag(struct rte_mbuf *mbuf)
72 {
73         prox_rte_ether_hdr *peth = rte_pktmbuf_mtod(mbuf, prox_rte_ether_hdr *);
74         const uint16_t eth_type = peth->ether_type;
75
76         if (eth_type == ETYPE_MPLSU) {
77                 prox_rte_ether_hdr *pneweth = (prox_rte_ether_hdr *)rte_pktmbuf_adj(mbuf, 4);
78                 const struct mpls_hdr *mpls = (const struct mpls_hdr *)(peth + 1);
79
80                 if (mpls->bos == 0) {
81                         // Double MPLS tag
82                         pneweth = (prox_rte_ether_hdr *)rte_pktmbuf_adj(mbuf, 4);
83                         PROX_ASSERT(pneweth);
84                 }
85
86                 const prox_rte_ipv4_hdr *pip = (const prox_rte_ipv4_hdr *)(pneweth + 1);
87                 if ((pip->version_ihl >> 4) == 4) {
88                         pneweth->ether_type = ETYPE_IPv4;
89                         return 1;
90                 }
91                 else if ((pip->version_ihl >> 4) == 6) {
92                         pneweth->ether_type = ETYPE_IPv6;
93                         return 1;
94                 }
95
96                 plog_info("Error removing MPLS: unexpected IP version: %d\n", pip->version_ihl >> 4);
97                 return 0;
98         }
99         if (eth_type != ETYPE_LLDP) {
100                 plog_info("Error Removing MPLS: ether_type = %#06x\n", eth_type);
101         }
102         return 0;
103 }
104
105 #endif /* _HANDLE_QINQ_ENCAP4_H_ */