vxlan: multiarch optimization of vxlan
[vpp.git] / extras / deprecated / plugins / gbp / gbp_classify.h
1 /*
2  * gbp.h : Group Based Policy
3  *
4  * Copyright (c) 2018 Cisco and/or its affiliates.
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at:
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 #ifndef __GBP_CLASSIFY_H__
19 #define __GBP_CLASSIFY_H__
20
21 #include <plugins/gbp/gbp.h>
22 #include <vnet/ethernet/arp_packet.h>
23
24 typedef enum gbp_src_classify_type_t_
25 {
26   GBP_SRC_CLASSIFY_NULL,
27   GBP_SRC_CLASSIFY_PORT,
28   GBP_SRC_CLASSIFY_LPM,
29   GBP_SRC_CLASSIFY_LPM_ANON,
30   GBP_SRC_N_CLASSIFY
31 #define GBP_SRC_N_CLASSIFY GBP_SRC_N_CLASSIFY
32 } gbp_src_classify_type_t;
33
34 /**
35  * Grouping of global data for the GBP source EPG classification feature
36  */
37 typedef struct gbp_src_classify_main_t_
38 {
39   /**
40    * Next nodes for L2 output features
41    */
42   u32 l2_input_feat_next[GBP_SRC_N_CLASSIFY][32];
43 } gbp_src_classify_main_t;
44
45 extern gbp_src_classify_main_t gbp_src_classify_main;
46
47 enum gbp_classify_get_ip_way
48 {
49   GBP_CLASSIFY_GET_IP_SRC = 0,
50   GBP_CLASSIFY_GET_IP_DST = 1
51 };
52
53 static_always_inline dpo_proto_t
54 gbp_classify_get_ip_address (const ethernet_header_t * eh0,
55                              const ip4_address_t ** ip4,
56                              const ip6_address_t ** ip6,
57                              const enum gbp_classify_get_ip_way way)
58 {
59   u16 etype = clib_net_to_host_u16 (eh0->type);
60   const void *l3h0 = eh0 + 1;
61
62   if (ETHERNET_TYPE_VLAN == etype)
63     {
64       const ethernet_vlan_header_t *vh0 =
65         (ethernet_vlan_header_t *) (eh0 + 1);
66       etype = clib_net_to_host_u16 (vh0->type);
67       l3h0 = vh0 + 1;
68     }
69
70   switch (etype)
71     {
72     case ETHERNET_TYPE_IP4:
73       *ip4 = &(&((const ip4_header_t *) l3h0)->src_address)[way];
74       return DPO_PROTO_IP4;
75     case ETHERNET_TYPE_IP6:
76       *ip6 = &(&((const ip6_header_t *) l3h0)->src_address)[way];
77       return DPO_PROTO_IP6;
78     case ETHERNET_TYPE_ARP:
79       *ip4 = &((ethernet_arp_header_t *) l3h0)->ip4_over_ethernet[way].ip4;
80       return DPO_PROTO_IP4;
81     }
82
83   return DPO_PROTO_NONE;
84 }
85
86 #endif
87
88 /*
89  * fd.io coding-style-patch-verification: ON
90  *
91  * Local Variables:
92  * eval: (c-set-style "gnu")
93  * End:
94  */