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.
17 #ifndef _HANDLE_QINQ_ENCAP4_H_
18 #define _HANDLE_QINQ_ENCAP4_H_
21 #include <rte_ether.h>
24 #include "prox_assert.h"
27 #include "task_init.h"
29 struct task_qinq_encap4 {
30 struct task_base base;
31 struct rte_table_hash *cpe_table;
33 uint64_t src_mac[PROX_MAX_PORTS];
35 uint8_t runtime_flags;
38 struct rte_mbuf* fake_packets[64];
40 #ifdef ENABLE_EXTRA_USER_STATISTICS
41 uint32_t *stats_per_user;
46 struct qinq_gre_entry {
51 uint32_t rss; // RSS based on Toeplitz_hash(svlan and cvlan)
56 struct qinq_gre_entry entries[0];
59 struct qinq_gre_map *get_qinq_gre_map(struct task_args *targ);
64 void init_qinq_gre_table(struct task_args *targ, struct qinq_gre_map *qinq_gre_map);
65 void init_qinq_gre_hash(struct task_args *targ, struct qinq_gre_map *qinq_gre_map);
66 void init_cpe4_table(struct task_args *targ);
67 void init_cpe4_hash(struct task_args *targ);
69 static inline uint8_t mpls_untag(struct rte_mbuf *mbuf)
71 struct ether_hdr *peth = rte_pktmbuf_mtod(mbuf, struct ether_hdr *);
72 const uint16_t eth_type = peth->ether_type;
74 if (eth_type == ETYPE_MPLSU) {
75 struct ether_hdr *pneweth = (struct ether_hdr *)rte_pktmbuf_adj(mbuf, 4);
76 const struct mpls_hdr *mpls = (const struct mpls_hdr *)(peth + 1);
80 pneweth = (struct ether_hdr *)rte_pktmbuf_adj(mbuf, 4);
84 const struct ipv4_hdr *pip = (const struct ipv4_hdr *)(pneweth + 1);
85 if ((pip->version_ihl >> 4) == 4) {
86 pneweth->ether_type = ETYPE_IPv4;
89 else if ((pip->version_ihl >> 4) == 6) {
90 pneweth->ether_type = ETYPE_IPv6;
94 plog_info("Error removing MPLS: unexpected IP version: %d\n", pip->version_ihl >> 4);
97 if (eth_type != ETYPE_LLDP) {
98 plog_info("Error Removing MPLS: ether_type = %#06x\n", eth_type);
103 #endif /* _HANDLE_QINQ_ENCAP4_H_ */