1ac70bd8de9fe712342cc86e723870cf3b4982ed
[vpp.git] / vnet / vnet / sr / sr.h
1 /*
2  * Copyright (c) 2015 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 #ifndef included_vnet_sr_h
16 #define included_vnet_sr_h
17
18 #include <vnet/vnet.h>
19 #include <vnet/sr/sr_packet.h>
20 #include <vnet/ip/ip6_packet.h>
21
22 #include <openssl/opensslconf.h>
23 #include <stdlib.h>
24 #include <string.h>
25
26 #include <openssl/crypto.h>
27 #include <openssl/sha.h>
28 #include <openssl/opensslv.h>
29 #include <openssl/hmac.h>
30
31 typedef struct
32 {
33   ip6_address_t src;
34   ip6_address_t dst;
35 } ip6_sr_tunnel_key_t;
36
37 typedef struct
38 {
39   /* src, dst address */
40   ip6_sr_tunnel_key_t key;
41
42   /* optional tunnel name */
43   u8 *name;
44
45   /* mask width for FIB entry */
46   u32 dst_mask_width;
47
48   /* first hop, to save 1 elt in the segment list */
49   ip6_address_t first_hop;
50
51   /* Fib indices */
52   u32 rx_fib_index;
53   u32 tx_fib_index;
54
55   /* The actual ip6 sr header */
56   u8 *rewrite;
57
58   /* Indicates that this tunnel is part of a policy comprising
59      of multiple tunnels. */
60   u32 policy_index;
61 } ip6_sr_tunnel_t;
62
63 typedef struct
64 {
65   u8 *shared_secret;
66 } ip6_sr_hmac_key_t;
67
68 typedef struct
69 {
70   /* Key (header imposition case) */
71   ip6_address_t *src_address;
72   ip6_address_t *dst_address;
73   u32 dst_mask_width;
74   u32 rx_table_id;
75   u32 tx_table_id;
76
77   /* optional name argument - for referencing SR tunnel/policy by name */
78   u8 *name;
79
80   /* optional policy name */
81   u8 *policy_name;
82
83   /* segment list, when inserting an ip6 SR header */
84   ip6_address_t *segments;
85
86   /*
87    * "Tag" list, aka segments inserted at the end of the list,
88    * past last_seg
89    */
90   ip6_address_t *tags;
91
92   /* Shared secret => generate SHA-256 HMAC security fields */
93   u8 *shared_secret;
94
95   /* Flags, e.g. cleanup, policy-list flags */
96   u16 flags_net_byte_order;
97
98   /* Delete the tunnnel? */
99   u8 is_del;
100 } ip6_sr_add_del_tunnel_args_t;
101
102 typedef struct
103 {
104   /* policy name */
105   u8 *name;
106
107   /* tunnel names */
108   u8 **tunnel_names;
109
110   /* Delete the policy? */
111   u8 is_del;
112 } ip6_sr_add_del_policy_args_t;
113
114
115 typedef struct
116 {
117   /* name of policy */
118   u8 *name;
119
120   /* vector to SR tunnel index */
121   u32 *tunnel_indices;
122
123 } ip6_sr_policy_t;
124
125 typedef struct
126 {
127   /* multicast IP6 address */
128   ip6_address_t *multicast_address;
129
130   /* name of policy to map to */
131   u8 *policy_name;
132
133   /* Delete the mapping */
134   u8 is_del;
135
136 } ip6_sr_add_del_multicastmap_args_t;
137
138 typedef struct
139 {
140   /* pool of tunnel instances, sr entry only */
141   ip6_sr_tunnel_t *tunnels;
142
143   /* find an sr "tunnel" by its outer-IP src/dst */
144   uword *tunnel_index_by_key;
145
146   /* find an sr "tunnel" by its name */
147   uword *tunnel_index_by_name;
148
149   /* policy pool */
150   ip6_sr_policy_t *policies;
151
152   /* find a policy by name */
153   uword *policy_index_by_policy_name;
154
155   /* multicast address to policy mapping */
156   uword *policy_index_by_multicast_address;
157
158   /* ip6-lookup next index for imposition FIB entries */
159   u32 ip6_lookup_sr_next_index;
160
161   /* hmac key id by shared secret */
162   uword *hmac_key_by_shared_secret;
163
164   /* ip6-rewrite next index for reinstalling the original dst address */
165   u32 ip6_rewrite_sr_next_index;
166
167   /* ip6-replicate next index for multicast tunnel */
168   u32 ip6_lookup_sr_replicate_index;
169
170   /* application API callback */
171   void *sr_local_cb;
172
173   /* validate hmac keys */
174   u8 validate_hmac;
175
176   /* pool of hmac keys */
177   ip6_sr_hmac_key_t *hmac_keys;
178
179   /* Openssl vbls */
180   EVP_MD *md;
181   HMAC_CTX *hmac_ctx;
182
183   /* enable debug spew */
184   u8 is_debug;
185
186   /* convenience */
187   vlib_main_t *vlib_main;
188   vnet_main_t *vnet_main;
189 } ip6_sr_main_t;
190
191 ip6_sr_main_t sr_main;
192
193 format_function_t format_ip6_sr_header;
194 format_function_t format_ip6_sr_header_with_length;
195
196 vlib_node_registration_t ip6_sr_input_node;
197
198 #if DPDK > 0
199 extern vlib_node_registration_t sr_replicate_node;
200 #endif /* DPDK */
201
202 int ip6_sr_add_del_tunnel (ip6_sr_add_del_tunnel_args_t * a);
203 int ip6_sr_add_del_policy (ip6_sr_add_del_policy_args_t * a);
204 int ip6_sr_add_del_multicastmap (ip6_sr_add_del_multicastmap_args_t * a);
205
206 void vnet_register_sr_app_callback (void *cb);
207
208 void sr_fix_hmac (ip6_sr_main_t * sm, ip6_header_t * ip,
209                   ip6_sr_header_t * sr);
210
211 #endif /* included_vnet_sr_h */
212
213 /*
214  * fd.io coding-style-patch-verification: ON
215  *
216  * Local Variables:
217  * eval: (c-set-style "gnu")
218  * End:
219  */