blob: 610b36996f38949f22cefdc7296730d33a02ecd1 [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
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 */
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -070015/**
16 * @file
17 * @brief Segment Routing header
18 *
19 * @note sr_replicate only works using DPDK today
20 */
Ed Warnickecb9cada2015-12-08 15:45:58 -070021#ifndef included_vnet_sr_h
22#define included_vnet_sr_h
23
24#include <vnet/vnet.h>
25#include <vnet/sr/sr_packet.h>
26#include <vnet/ip/ip6_packet.h>
27
28#include <openssl/opensslconf.h>
29#include <stdlib.h>
30#include <string.h>
31
32#include <openssl/crypto.h>
33#include <openssl/sha.h>
34#include <openssl/opensslv.h>
35#include <openssl/hmac.h>
36
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -070037/**
38 * @brief Segment Route tunnel key
39 */
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -070040typedef struct
41{
Ed Warnickecb9cada2015-12-08 15:45:58 -070042 ip6_address_t src;
43 ip6_address_t dst;
44} ip6_sr_tunnel_key_t;
45
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -070046/**
47 * @brief Segment Route tunnel
48 */
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -070049typedef struct
50{
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -070051 /** src, dst address */
Ed Warnickecb9cada2015-12-08 15:45:58 -070052 ip6_sr_tunnel_key_t key;
53
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -070054 /** Pptional tunnel name */
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -070055 u8 *name;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -070056
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -070057 /** Mask width for FIB entry */
Ed Warnickecb9cada2015-12-08 15:45:58 -070058 u32 dst_mask_width;
59
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -070060 /** First hop, to save 1 elt in the segment list */
Ed Warnickecb9cada2015-12-08 15:45:58 -070061 ip6_address_t first_hop;
62
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -070063 /** RX Fib index */
Ed Warnickecb9cada2015-12-08 15:45:58 -070064 u32 rx_fib_index;
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -070065 /** TX Fib index */
Ed Warnickecb9cada2015-12-08 15:45:58 -070066 u32 tx_fib_index;
67
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -070068 /** The actual ip6 SR header */
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -070069 u8 *rewrite;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -070070
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -070071 /** Indicates that this tunnel is part of a policy comprising
72 of multiple tunnels. If == ~0 tunnel is not part of a policy */
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -070073 u32 policy_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -070074} ip6_sr_tunnel_t;
75
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -070076/**
77 * @brief Shared secret for keyed-hash message authentication code (HMAC).
78 */
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -070079typedef struct
80{
81 u8 *shared_secret;
Ed Warnickecb9cada2015-12-08 15:45:58 -070082} ip6_sr_hmac_key_t;
83
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -070084/**
85 * @brief Args required for add/del tunnel.
86 *
87 * Else we end up passing a LOT of parameters around.
88 */
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -070089typedef struct
90{
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -070091 /** Key (header imposition case) */
Ed Warnickecb9cada2015-12-08 15:45:58 -070092 ip6_address_t *src_address;
93 ip6_address_t *dst_address;
94 u32 dst_mask_width;
95 u32 rx_table_id;
96 u32 tx_table_id;
97
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -070098 /** optional name argument - for referencing SR tunnel/policy by name */
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -070099 u8 *name;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700100
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -0700101 /** optional policy name */
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700102 u8 *policy_name;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700103
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -0700104 /** segment list, when inserting an ip6 SR header */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700105 ip6_address_t *segments;
106
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -0700107 /**
Ed Warnickecb9cada2015-12-08 15:45:58 -0700108 * "Tag" list, aka segments inserted at the end of the list,
109 * past last_seg
110 */
111 ip6_address_t *tags;
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700112
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -0700113 /** Shared secret => generate SHA-256 HMAC security fields */
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700114 u8 *shared_secret;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700115
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -0700116 /** Flags, e.g. cleanup, policy-list flags */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700117 u16 flags_net_byte_order;
118
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -0700119 /** Delete the tunnnel? */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700120 u8 is_del;
121} ip6_sr_add_del_tunnel_args_t;
122
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -0700123/**
124 * @brief Args for creating a policy.
125 *
126 * Typically used for multicast replication.
127 * ie a multicast address can be associated with a policy,
128 * then replicated across a number of unicast SR tunnels.
129 */
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700130typedef struct
131{
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -0700132 /** policy name */
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700133 u8 *name;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700134
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -0700135 /** tunnel names */
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700136 u8 **tunnel_names;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700137
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -0700138 /** Delete the policy? */
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700139 u8 is_del;
140} ip6_sr_add_del_policy_args_t;
141
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -0700142/**
143 * @brief Segment Routing policy.
144 *
145 * Typically used for multicast replication.
146 * ie a multicast address can be associated with a policy,
147 * then replicated across a number of unicast SR tunnels.
148 */
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700149typedef struct
150{
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -0700151 /** name of policy */
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700152 u8 *name;
153
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -0700154 /** vector to SR tunnel index */
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700155 u32 *tunnel_indices;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700156
157} ip6_sr_policy_t;
158
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -0700159/**
160 * @brief Args for mapping of multicast address to policy name.
161 *
162 * Typically used for multicast replication.
163 * ie a multicast address can be associated with a policy,
164 * then replicated across a number of unicast SR tunnels.
165 */
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700166typedef struct
167{
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -0700168 /** multicast IP6 address */
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700169 ip6_address_t *multicast_address;
170
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -0700171 /** name of policy to map to */
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700172 u8 *policy_name;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700173
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -0700174 /** Delete the mapping */
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700175 u8 is_del;
176
177} ip6_sr_add_del_multicastmap_args_t;
178
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -0700179/**
180 * @brief Segment Routing state.
181 */
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700182typedef struct
183{
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -0700184 /** pool of tunnel instances, sr entry only */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700185 ip6_sr_tunnel_t *tunnels;
186
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -0700187 /** find an sr "tunnel" by its outer-IP src/dst */
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700188 uword *tunnel_index_by_key;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700189
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -0700190 /** find an sr "tunnel" by its name */
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700191 uword *tunnel_index_by_name;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700192
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -0700193 /** policy pool */
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700194 ip6_sr_policy_t *policies;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700195
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -0700196 /** find a policy by name */
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700197 uword *policy_index_by_policy_name;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700198
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -0700199 /** multicast address to policy mapping */
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700200 uword *policy_index_by_multicast_address;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700201
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -0700202 /** hmac key id by shared secret */
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700203 uword *hmac_key_by_shared_secret;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700204
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -0700205 /** ip6-rewrite next index for reinstalling the original dst address */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700206 u32 ip6_rewrite_sr_next_index;
207
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -0700208 /** ip6-replicate next index for multicast tunnel */
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700209 u32 ip6_lookup_sr_replicate_index;
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700210
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -0700211 /** application API callback */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700212 void *sr_local_cb;
213
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -0700214 /** validate hmac keys */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700215 u8 validate_hmac;
216
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -0700217 /** pool of hmac keys */
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700218 ip6_sr_hmac_key_t *hmac_keys;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700219
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -0700220 /** Openssl var */
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700221 EVP_MD *md;
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -0700222 /** Openssl var */
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700223 HMAC_CTX *hmac_ctx;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700224
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -0700225 /** enable debug spew */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700226 u8 is_debug;
227
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -0700228 /** convenience */
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700229 vlib_main_t *vlib_main;
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -0700230 /** convenience */
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700231 vnet_main_t *vnet_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700232} ip6_sr_main_t;
233
234ip6_sr_main_t sr_main;
235
236format_function_t format_ip6_sr_header;
237format_function_t format_ip6_sr_header_with_length;
238
239vlib_node_registration_t ip6_sr_input_node;
240
Keith Burns (alagalah)21c33bb2016-05-02 13:13:46 -0700241#if DPDK > 0
Chris Luke633134b2016-05-02 16:00:43 -0400242extern vlib_node_registration_t sr_replicate_node;
Keith Burns (alagalah)21c33bb2016-05-02 13:13:46 -0700243#endif /* DPDK */
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700244
Ed Warnickecb9cada2015-12-08 15:45:58 -0700245int ip6_sr_add_del_tunnel (ip6_sr_add_del_tunnel_args_t * a);
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700246int ip6_sr_add_del_policy (ip6_sr_add_del_policy_args_t * a);
247int ip6_sr_add_del_multicastmap (ip6_sr_add_del_multicastmap_args_t * a);
248
Ed Warnickecb9cada2015-12-08 15:45:58 -0700249void vnet_register_sr_app_callback (void *cb);
250
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700251void sr_fix_hmac (ip6_sr_main_t * sm, ip6_header_t * ip,
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700252 ip6_sr_header_t * sr);
253
Ed Warnickecb9cada2015-12-08 15:45:58 -0700254#endif /* included_vnet_sr_h */
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700255
256/*
257 * fd.io coding-style-patch-verification: ON
258 *
259 * Local Variables:
260 * eval: (c-set-style "gnu")
261 * End:
262 */