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