e2d652775bcaffacb5361398135695fa1cd9a900
[vpp.git] / src / vnet / udp / udp_encap.h
1 /*
2  * Copyright (c) 2016 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15
16 #ifndef __UDP_ENCAP_H__
17 #define __UDP_ENCAP_H__
18
19 #include <vnet/ip/ip.h>
20 #include <vnet/udp/udp.h>
21 #include <vnet/fib/fib_node.h>
22
23 /**
24  * UDP encapsualtion.
25  * A representation of the encapsulation of packets in UDP-over-IP.
26  * This is encapsulation only, there is no tunnel interface, hence
27  * it is uni-directional. For decap register a handler with the UDP port
28  * dispatcher.
29  */
30
31 /**
32  * Fixup behaviour. Actions performed on the encap in the data-plance
33  */
34 typedef enum udp_encap_fixup_flags_t_
35 {
36   UDP_ENCAP_FIXUP_NONE = 0,
37   /**
38    * UDP source port contains an entropy/hash value for load-balancing by downstream peers.
39    */
40   UDP_ENCAP_FIXUP_UDP_SRC_PORT_ENTROPY = (1 << 0),
41 } udp_encap_fixup_flags_t;
42
43 /**
44  * The UDP encap represenation
45  */
46 typedef struct udp_encap_t_
47 {
48   /**
49    * The first cacheline contains the data used in the data-plane
50    */
51   CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
52
53   /**
54    * The headers to paint, in packet painting order
55    */
56   union
57   {
58     struct
59     {
60       ip4_header_t ue_ip4;
61       udp_header_t ue_udp;
62     } __attribute__ ((packed)) ip4;
63     struct
64     {
65       ip6_header_t ue_ip6;
66       udp_header_t ue_udp;
67     } __attribute__ ((packed)) ip6;
68   } __attribute__ ((packed)) ue_hdrs;
69
70   /**
71    * Flags controlling fixup behaviour
72    */
73   udp_encap_fixup_flags_t ue_flags;
74
75   /**
76    * The DPO used to forward to the next node in the VLIB graph
77    */
78   dpo_id_t ue_dpo;
79
80   /**
81    * the protocol of the IP header imposed
82    */
83   fib_protocol_t ue_ip_proto;
84
85   /**
86    * The seond cacheline contains control-plane data
87    */
88     CLIB_CACHE_LINE_ALIGN_MARK (cacheline1);
89
90   /**
91    * linkage into the FIB graph
92    */
93   fib_node_t ue_fib_node;
94
95   /**
96    * The ID given by the user/client.
97    * This ID is used by the client for modifications.
98    */
99   u32 ue_id;
100
101   /**
102    * Tracking information for the IP destination
103    */
104   fib_node_index_t ue_fib_entry_index;
105   u32 ue_fib_sibling;
106
107   /**
108    * The FIB index in which the encap destination resides
109    */
110   index_t ue_fib_index;
111 } udp_encap_t;
112
113 extern index_t udp_encap_add_and_lock (u32 id,
114                                        fib_protocol_t proto,
115                                        index_t fib_index,
116                                        const ip46_address_t * src_ip,
117                                        const ip46_address_t * dst_ip,
118                                        u16 src_port,
119                                        u16 dst_port,
120                                        udp_encap_fixup_flags_t flags);
121
122 extern index_t udp_encap_find (u32 id);
123 extern void udp_encap_lock (u32 id);
124 extern void udp_encap_unlock (u32 id);
125 extern u8 *format_udp_encap (u8 * s, va_list * args);
126 extern void udp_encap_unlock_w_index (index_t uei);
127 extern void udp_encap_contribute_forwarding (u32 id,
128                                              dpo_proto_t proto,
129                                              dpo_id_t * dpo);
130
131 extern void udp_encap_get_stats (index_t uei, u64 * packets, u64 * bytes);
132
133 /**
134  * Callback function invoked when walking all encap objects.
135  * Return non-zero to continue the walk.
136  */
137 typedef walk_rc_t (*udp_encap_walk_cb_t) (index_t uei, void *ctx);
138
139 /**
140  * Walk each of the encap objects
141  */
142 extern void udp_encap_walk (udp_encap_walk_cb_t cb, void *ctx);
143
144 /**
145  * Pool of encaps
146  */
147 extern udp_encap_t *udp_encap_pool;
148
149 static inline udp_encap_t *
150 udp_encap_get (index_t uei)
151 {
152   return (pool_elt_at_index (udp_encap_pool, uei));
153 }
154
155 /*
156  * fd.io coding-style-patch-verification: ON
157  *
158  * Local Variables:
159  * eval: (c-set-style "gnu")
160  * End:
161  */
162
163 #endif