3c6d981d17e5a22355e1146d5538a19207fecba4
[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   /* mask width for FIB entry */
41   u32 dst_mask_width;
42
43   /* first hop, to save 1 elt in the segment list */
44   ip6_address_t first_hop;
45
46   /* Fib indices */
47   u32 rx_fib_index;
48   u32 tx_fib_index;
49
50   /* The actual ip6 sr header */
51   u8 * rewrite;
52 } ip6_sr_tunnel_t;
53
54 typedef struct {
55   u8 * shared_secret;
56 } ip6_sr_hmac_key_t;
57
58 typedef struct {
59   /* Key (header imposition case) */
60   ip6_address_t *src_address;
61   ip6_address_t *dst_address;
62   u32 dst_mask_width;
63   u32 rx_table_id;
64   u32 tx_table_id;
65
66   /* segment list, when inserting an ip6 SR header*/
67   ip6_address_t *segments;
68
69   /* 
70    * "Tag" list, aka segments inserted at the end of the list,
71    * past last_seg
72    */
73   ip6_address_t *tags;
74      
75   /* Shared secret => generate SHA-256 HMAC security fields */
76   u8 * shared_secret;
77
78   /* Flags, e.g. cleanup, policy-list flags */
79   u16 flags_net_byte_order;
80
81   /* Delete the tunnnel? */
82   u8 is_del;
83 } ip6_sr_add_del_tunnel_args_t;
84
85 typedef struct {
86   /* pool of tunnel instances, sr entry only */
87   ip6_sr_tunnel_t *tunnels;
88
89   /* find an sr "tunnel" by its outer-IP src/dst */
90   uword * tunnel_index_by_key;
91   
92   /* ip6-lookup next index for imposition FIB entries */
93   u32 ip6_lookup_sr_next_index;
94
95   /* hmac key id by shared secret */
96   uword * hmac_key_by_shared_secret;
97
98   /* ip6-rewrite next index for reinstalling the original dst address */
99   u32 ip6_rewrite_sr_next_index;
100
101   /* application API callback */
102   void *sr_local_cb;
103
104   /* validate hmac keys */
105   u8 validate_hmac;
106
107   /* pool of hmac keys */
108   ip6_sr_hmac_key_t * hmac_keys;
109
110   /* Openssl vbls */
111   EVP_MD * md;
112   HMAC_CTX * hmac_ctx;
113
114   /* enable debug spew */
115   u8 is_debug;
116
117   /* convenience */
118   vlib_main_t * vlib_main;
119   vnet_main_t * vnet_main;
120 } ip6_sr_main_t;
121
122 ip6_sr_main_t sr_main;
123
124 format_function_t format_ip6_sr_header;
125 format_function_t format_ip6_sr_header_with_length;
126
127 vlib_node_registration_t ip6_sr_input_node;
128
129 int ip6_sr_add_del_tunnel (ip6_sr_add_del_tunnel_args_t * a);
130 void vnet_register_sr_app_callback (void *cb);
131
132 #endif /* included_vnet_sr_h */