Neale Ranns | 2dd6852 | 2017-02-16 03:38:59 -0800 | [diff] [blame] | 1 | /* |
| 2 | * proxy_node.c: common dhcp v4 and v6 proxy node processing |
| 3 | * |
| 4 | * Copyright (c) 2013 Cisco and/or its affiliates. |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at: |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | #include <vnet/dhcp/dhcp_proxy.h> |
| 19 | #include <vnet/fib/fib_table.h> |
Neale Ranns | 358425b | 2017-02-20 09:42:36 -0800 | [diff] [blame] | 20 | #include <vnet/mfib/mfib_table.h> |
Neale Ranns | 2dd6852 | 2017-02-16 03:38:59 -0800 | [diff] [blame] | 21 | |
| 22 | /** |
| 23 | * @brief Shard 4/6 instance of DHCP main |
| 24 | */ |
| 25 | dhcp_proxy_main_t dhcp_proxy_main; |
| 26 | |
Neale Ranns | 358425b | 2017-02-20 09:42:36 -0800 | [diff] [blame] | 27 | static void |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 28 | dhcp_proxy_rx_table_lock (fib_protocol_t proto, u32 fib_index) |
Neale Ranns | 358425b | 2017-02-20 09:42:36 -0800 | [diff] [blame] | 29 | { |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 30 | if (FIB_PROTOCOL_IP4 == proto) |
| 31 | fib_table_lock (fib_index, proto, FIB_SOURCE_DHCP); |
| 32 | else |
| 33 | mfib_table_lock (fib_index, proto, MFIB_SOURCE_DHCP); |
Neale Ranns | 358425b | 2017-02-20 09:42:36 -0800 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | static void |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 37 | dhcp_proxy_rx_table_unlock (fib_protocol_t proto, u32 fib_index) |
Neale Ranns | 358425b | 2017-02-20 09:42:36 -0800 | [diff] [blame] | 38 | { |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 39 | if (FIB_PROTOCOL_IP4 == proto) |
| 40 | fib_table_unlock (fib_index, proto, FIB_SOURCE_DHCP); |
| 41 | else |
| 42 | mfib_table_unlock (fib_index, proto, MFIB_SOURCE_DHCP); |
Neale Ranns | 358425b | 2017-02-20 09:42:36 -0800 | [diff] [blame] | 43 | } |
| 44 | |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 45 | u32 |
| 46 | dhcp_proxy_rx_table_get_table_id (fib_protocol_t proto, u32 fib_index) |
Neale Ranns | 358425b | 2017-02-20 09:42:36 -0800 | [diff] [blame] | 47 | { |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 48 | if (FIB_PROTOCOL_IP4 == proto) |
| 49 | { |
| 50 | fib_table_t *fib; |
Neale Ranns | 358425b | 2017-02-20 09:42:36 -0800 | [diff] [blame] | 51 | |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 52 | fib = fib_table_get (fib_index, proto); |
Neale Ranns | 358425b | 2017-02-20 09:42:36 -0800 | [diff] [blame] | 53 | |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 54 | return (fib->ft_table_id); |
| 55 | } |
| 56 | else |
| 57 | { |
| 58 | mfib_table_t *mfib; |
Neale Ranns | 358425b | 2017-02-20 09:42:36 -0800 | [diff] [blame] | 59 | |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 60 | mfib = mfib_table_get (fib_index, proto); |
Neale Ranns | 358425b | 2017-02-20 09:42:36 -0800 | [diff] [blame] | 61 | |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 62 | return (mfib->mft_table_id); |
Neale Ranns | 2dd6852 | 2017-02-16 03:38:59 -0800 | [diff] [blame] | 63 | } |
| 64 | } |
| 65 | |
| 66 | void |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 67 | dhcp_proxy_walk (fib_protocol_t proto, dhcp_proxy_walk_fn_t fn, void *ctx) |
Neale Ranns | 2dd6852 | 2017-02-16 03:38:59 -0800 | [diff] [blame] | 68 | { |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 69 | dhcp_proxy_main_t *dpm = &dhcp_proxy_main; |
| 70 | dhcp_proxy_t *server; |
| 71 | u32 server_index, i; |
| 72 | |
| 73 | vec_foreach_index (i, dpm->dhcp_server_index_by_rx_fib_index[proto]) |
| 74 | { |
| 75 | server_index = dpm->dhcp_server_index_by_rx_fib_index[proto][i]; |
| 76 | if (~0 == server_index) |
| 77 | continue; |
| 78 | |
| 79 | server = pool_elt_at_index (dpm->dhcp_servers[proto], server_index); |
| 80 | |
| 81 | if (!fn (server, ctx)) |
| 82 | break; |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | void |
| 87 | dhcp_vss_walk (fib_protocol_t proto, dhcp_vss_walk_fn_t fn, void *ctx) |
| 88 | { |
| 89 | dhcp_proxy_main_t *dpm = &dhcp_proxy_main; |
Neale Ranns | 358425b | 2017-02-20 09:42:36 -0800 | [diff] [blame] | 90 | mfib_table_t *mfib; |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 91 | dhcp_vss_t *vss; |
Neale Ranns | 2dd6852 | 2017-02-16 03:38:59 -0800 | [diff] [blame] | 92 | u32 vss_index, i; |
| 93 | fib_table_t *fib; |
| 94 | |
Neale Ranns | 2dd6852 | 2017-02-16 03:38:59 -0800 | [diff] [blame] | 95 | vec_foreach_index (i, dpm->vss_index_by_rx_fib_index[proto]) |
| 96 | { |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 97 | vss_index = dpm->vss_index_by_rx_fib_index[proto][i]; |
| 98 | if (~0 == vss_index) |
| 99 | continue; |
Neale Ranns | 2dd6852 | 2017-02-16 03:38:59 -0800 | [diff] [blame] | 100 | |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 101 | vss = pool_elt_at_index (dpm->vss[proto], vss_index); |
Neale Ranns | 2dd6852 | 2017-02-16 03:38:59 -0800 | [diff] [blame] | 102 | |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 103 | if (FIB_PROTOCOL_IP4 == proto) |
| 104 | { |
| 105 | fib = fib_table_get (i, proto); |
Neale Ranns | 2dd6852 | 2017-02-16 03:38:59 -0800 | [diff] [blame] | 106 | |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 107 | if (!fn (vss, fib->ft_table_id, ctx)) |
| 108 | break; |
| 109 | } |
| 110 | else |
| 111 | { |
| 112 | mfib = mfib_table_get (i, proto); |
Neale Ranns | 358425b | 2017-02-20 09:42:36 -0800 | [diff] [blame] | 113 | |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 114 | if (!fn (vss, mfib->mft_table_id, ctx)) |
| 115 | break; |
| 116 | } |
| 117 | } |
Neale Ranns | 2dd6852 | 2017-02-16 03:38:59 -0800 | [diff] [blame] | 118 | } |
| 119 | |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 120 | static u32 |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 121 | dhcp_proxy_server_find (dhcp_proxy_t * proxy, |
| 122 | fib_protocol_t proto, |
| 123 | ip46_address_t * addr, u32 server_table_id) |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 124 | { |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 125 | dhcp_server_t *server; |
| 126 | u32 ii, fib_index; |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 127 | |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 128 | vec_foreach_index (ii, proxy->dhcp_servers) |
| 129 | { |
| 130 | server = &proxy->dhcp_servers[ii]; |
| 131 | fib_index = fib_table_find (proto, server_table_id); |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 132 | |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 133 | if (ip46_address_is_equal (&server->dhcp_server, |
| 134 | addr) && |
| 135 | (server->server_fib_index == fib_index)) |
| 136 | { |
| 137 | return (ii); |
| 138 | } |
| 139 | } |
| 140 | return (~0); |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 141 | } |
| 142 | |
Neale Ranns | 2dd6852 | 2017-02-16 03:38:59 -0800 | [diff] [blame] | 143 | int |
| 144 | dhcp_proxy_server_del (fib_protocol_t proto, |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 145 | u32 rx_fib_index, |
| 146 | ip46_address_t * addr, u32 server_table_id) |
Neale Ranns | 2dd6852 | 2017-02-16 03:38:59 -0800 | [diff] [blame] | 147 | { |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 148 | dhcp_proxy_main_t *dpm = &dhcp_proxy_main; |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 149 | dhcp_proxy_t *proxy = 0; |
Neale Ranns | 2dd6852 | 2017-02-16 03:38:59 -0800 | [diff] [blame] | 150 | |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 151 | proxy = dhcp_get_proxy (dpm, rx_fib_index, proto); |
Neale Ranns | 2dd6852 | 2017-02-16 03:38:59 -0800 | [diff] [blame] | 152 | |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 153 | if (NULL != proxy) |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 154 | { |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 155 | dhcp_server_t *server; |
| 156 | u32 index; |
Neale Ranns | 2dd6852 | 2017-02-16 03:38:59 -0800 | [diff] [blame] | 157 | |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 158 | index = dhcp_proxy_server_find (proxy, proto, addr, server_table_id); |
Neale Ranns | 2dd6852 | 2017-02-16 03:38:59 -0800 | [diff] [blame] | 159 | |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 160 | if (~0 != index) |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 161 | { |
| 162 | server = &proxy->dhcp_servers[index]; |
| 163 | fib_table_unlock (server->server_fib_index, proto, FIB_SOURCE_DHCP); |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 164 | |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 165 | vec_del1 (proxy->dhcp_servers, index); |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 166 | |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 167 | if (0 == vec_len (proxy->dhcp_servers)) |
| 168 | { |
| 169 | /* no servers left, delete the proxy config */ |
| 170 | dpm->dhcp_server_index_by_rx_fib_index[proto][rx_fib_index] = |
| 171 | ~0; |
| 172 | vec_free (proxy->dhcp_servers); |
| 173 | pool_put (dpm->dhcp_servers[proto], proxy); |
| 174 | return (1); |
| 175 | } |
| 176 | } |
| 177 | } |
Neale Ranns | 2dd6852 | 2017-02-16 03:38:59 -0800 | [diff] [blame] | 178 | |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 179 | /* the proxy still exists */ |
| 180 | return (0); |
Neale Ranns | 2dd6852 | 2017-02-16 03:38:59 -0800 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | int |
| 184 | dhcp_proxy_server_add (fib_protocol_t proto, |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 185 | ip46_address_t * addr, |
| 186 | ip46_address_t * src_address, |
| 187 | u32 rx_fib_index, u32 server_table_id) |
Neale Ranns | 2dd6852 | 2017-02-16 03:38:59 -0800 | [diff] [blame] | 188 | { |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 189 | dhcp_proxy_main_t *dpm = &dhcp_proxy_main; |
| 190 | dhcp_proxy_t *proxy = 0; |
Neale Ranns | 2dd6852 | 2017-02-16 03:38:59 -0800 | [diff] [blame] | 191 | int new = 0; |
| 192 | |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 193 | proxy = dhcp_get_proxy (dpm, rx_fib_index, proto); |
Neale Ranns | 2dd6852 | 2017-02-16 03:38:59 -0800 | [diff] [blame] | 194 | |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 195 | if (NULL == proxy) |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 196 | { |
| 197 | vec_validate_init_empty (dpm->dhcp_server_index_by_rx_fib_index[proto], |
| 198 | rx_fib_index, ~0); |
Neale Ranns | 2dd6852 | 2017-02-16 03:38:59 -0800 | [diff] [blame] | 199 | |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 200 | pool_get (dpm->dhcp_servers[proto], proxy); |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 201 | clib_memset (proxy, 0, sizeof (*proxy)); |
Neale Ranns | 2dd6852 | 2017-02-16 03:38:59 -0800 | [diff] [blame] | 202 | new = 1; |
| 203 | |
| 204 | dpm->dhcp_server_index_by_rx_fib_index[proto][rx_fib_index] = |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 205 | proxy - dpm->dhcp_servers[proto]; |
Neale Ranns | 2dd6852 | 2017-02-16 03:38:59 -0800 | [diff] [blame] | 206 | |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 207 | proxy->dhcp_src_address = *src_address; |
| 208 | proxy->rx_fib_index = rx_fib_index; |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 209 | } |
Neale Ranns | 2dd6852 | 2017-02-16 03:38:59 -0800 | [diff] [blame] | 210 | else |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 211 | { |
| 212 | if (~0 != dhcp_proxy_server_find (proxy, proto, addr, server_table_id)) |
| 213 | { |
| 214 | return (new); |
| 215 | } |
| 216 | } |
Neale Ranns | 2dd6852 | 2017-02-16 03:38:59 -0800 | [diff] [blame] | 217 | |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 218 | dhcp_server_t server = { |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 219 | .dhcp_server = *addr, |
| 220 | .server_fib_index = fib_table_find_or_create_and_lock (proto, |
| 221 | server_table_id, |
| 222 | FIB_SOURCE_DHCP), |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 223 | }; |
| 224 | |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 225 | vec_add1 (proxy->dhcp_servers, server); |
Neale Ranns | 2dd6852 | 2017-02-16 03:38:59 -0800 | [diff] [blame] | 226 | |
| 227 | return (new); |
| 228 | } |
| 229 | |
| 230 | typedef struct dhcp4_proxy_dump_walk_ctx_t_ |
| 231 | { |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 232 | fib_protocol_t proto; |
| 233 | void *opaque; |
| 234 | u32 context; |
Neale Ranns | 2dd6852 | 2017-02-16 03:38:59 -0800 | [diff] [blame] | 235 | } dhcp_proxy_dump_walk_cxt_t; |
| 236 | |
| 237 | static int |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 238 | dhcp_proxy_dump_walk (dhcp_proxy_t * proxy, void *arg) |
Neale Ranns | 2dd6852 | 2017-02-16 03:38:59 -0800 | [diff] [blame] | 239 | { |
| 240 | dhcp_proxy_dump_walk_cxt_t *ctx = arg; |
Neale Ranns | 2dd6852 | 2017-02-16 03:38:59 -0800 | [diff] [blame] | 241 | |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 242 | dhcp_send_details (ctx->proto, ctx->opaque, ctx->context, proxy); |
Neale Ranns | 2dd6852 | 2017-02-16 03:38:59 -0800 | [diff] [blame] | 243 | |
| 244 | return (1); |
| 245 | } |
| 246 | |
| 247 | void |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 248 | dhcp_proxy_dump (fib_protocol_t proto, void *opaque, u32 context) |
Neale Ranns | 2dd6852 | 2017-02-16 03:38:59 -0800 | [diff] [blame] | 249 | { |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 250 | dhcp_proxy_dump_walk_cxt_t ctx = { |
| 251 | .proto = proto, |
| 252 | .opaque = opaque, |
| 253 | .context = context, |
| 254 | }; |
| 255 | dhcp_proxy_walk (proto, dhcp_proxy_dump_walk, &ctx); |
Neale Ranns | 2dd6852 | 2017-02-16 03:38:59 -0800 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | int |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 259 | dhcp_vss_show_walk (dhcp_vss_t * vss, u32 rx_table_id, void *ctx) |
Neale Ranns | 2dd6852 | 2017-02-16 03:38:59 -0800 | [diff] [blame] | 260 | { |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 261 | vlib_main_t *vm = ctx; |
Neale Ranns | 2dd6852 | 2017-02-16 03:38:59 -0800 | [diff] [blame] | 262 | |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 263 | if (vss->vss_type == VSS_TYPE_VPN_ID) |
| 264 | { |
| 265 | u32 oui = ((u32) vss->vpn_id[0] << 16) + ((u32) vss->vpn_id[1] << 8) |
| 266 | + ((u32) vss->vpn_id[2]); |
| 267 | u32 fib_id = ((u32) vss->vpn_id[3] << 24) + ((u32) vss->vpn_id[4] << 16) |
| 268 | + ((u32) vss->vpn_id[5] << 8) + ((u32) vss->vpn_id[6]); |
| 269 | vlib_cli_output (vm, " fib_table: %d oui: %d vpn_index: %d", |
| 270 | rx_table_id, oui, fib_id); |
| 271 | } |
| 272 | else if (vss->vss_type == VSS_TYPE_ASCII) |
| 273 | vlib_cli_output (vm, " fib_table: %d vpn_id: %s", |
| 274 | rx_table_id, vss->vpn_ascii_id); |
| 275 | else |
| 276 | vlib_cli_output (vm, " fib_table: %d default global vpn", rx_table_id); |
Neale Ranns | 2dd6852 | 2017-02-16 03:38:59 -0800 | [diff] [blame] | 277 | |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 278 | return (1); |
Neale Ranns | 2dd6852 | 2017-02-16 03:38:59 -0800 | [diff] [blame] | 279 | } |
| 280 | |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 281 | void |
| 282 | update_vss (dhcp_vss_t * v, |
| 283 | u8 vss_type, u8 * vpn_ascii_id, u32 oui, u32 vpn_index) |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 284 | { |
| 285 | v->vss_type = vss_type; |
| 286 | if (v->vpn_ascii_id) |
| 287 | { |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 288 | if (v->vpn_ascii_id == (u8 *) ~ 0) |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 289 | v->vpn_ascii_id = 0; |
| 290 | else |
| 291 | vec_free (v->vpn_ascii_id); |
| 292 | } |
| 293 | |
| 294 | if (vss_type == VSS_TYPE_ASCII) |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 295 | v->vpn_ascii_id = vpn_ascii_id; |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 296 | else if (vss_type == VSS_TYPE_VPN_ID) |
| 297 | { |
| 298 | v->vpn_id[0] = (oui >> 16) & 0xff; |
| 299 | v->vpn_id[1] = (oui >> 8) & 0xff; |
| 300 | v->vpn_id[2] = (oui >> 0) & 0xff; |
| 301 | v->vpn_id[3] = (vpn_index >> 24) & 0xff; |
| 302 | v->vpn_id[4] = (vpn_index >> 16) & 0xff; |
| 303 | v->vpn_id[5] = (vpn_index >> 8) & 0xff; |
| 304 | v->vpn_id[6] = (vpn_index >> 0) & 0xff; |
| 305 | } |
| 306 | } |
| 307 | |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 308 | int |
| 309 | dhcp_proxy_set_vss (fib_protocol_t proto, |
| 310 | u32 tbl_id, |
| 311 | u8 vss_type, |
| 312 | u8 * vpn_ascii_id, u32 oui, u32 vpn_index, u8 is_del) |
Neale Ranns | 2dd6852 | 2017-02-16 03:38:59 -0800 | [diff] [blame] | 313 | { |
| 314 | dhcp_proxy_main_t *dm = &dhcp_proxy_main; |
| 315 | dhcp_vss_t *v = NULL; |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 316 | u32 rx_fib_index; |
Neale Ranns | 2dd6852 | 2017-02-16 03:38:59 -0800 | [diff] [blame] | 317 | int rc = 0; |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 318 | |
Neale Ranns | 358425b | 2017-02-20 09:42:36 -0800 | [diff] [blame] | 319 | if (proto == FIB_PROTOCOL_IP4) |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 320 | rx_fib_index = fib_table_find_or_create_and_lock (proto, tbl_id, |
| 321 | FIB_SOURCE_DHCP); |
Neale Ranns | 358425b | 2017-02-20 09:42:36 -0800 | [diff] [blame] | 322 | else |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 323 | rx_fib_index = mfib_table_find_or_create_and_lock (proto, tbl_id, |
| 324 | MFIB_SOURCE_DHCP); |
| 325 | v = dhcp_get_vss_info (dm, rx_fib_index, proto); |
Neale Ranns | 2dd6852 | 2017-02-16 03:38:59 -0800 | [diff] [blame] | 326 | |
| 327 | if (NULL != v) |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 328 | { |
Neale Ranns | 2dd6852 | 2017-02-16 03:38:59 -0800 | [diff] [blame] | 329 | if (is_del) |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 330 | { |
| 331 | /* release the lock held on the table when the VSS |
| 332 | * info was created */ |
| 333 | dhcp_proxy_rx_table_unlock (proto, rx_fib_index); |
Neale Ranns | 2dd6852 | 2017-02-16 03:38:59 -0800 | [diff] [blame] | 334 | |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 335 | vec_free (v->vpn_ascii_id); |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 336 | pool_put (dm->vss[proto], v); |
| 337 | dm->vss_index_by_rx_fib_index[proto][rx_fib_index] = ~0; |
| 338 | } |
Neale Ranns | 2dd6852 | 2017-02-16 03:38:59 -0800 | [diff] [blame] | 339 | else |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 340 | { |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 341 | update_vss (v, vss_type, vpn_ascii_id, oui, vpn_index); |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 342 | } |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 343 | } |
Neale Ranns | 2dd6852 | 2017-02-16 03:38:59 -0800 | [diff] [blame] | 344 | else |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 345 | { |
Neale Ranns | 2dd6852 | 2017-02-16 03:38:59 -0800 | [diff] [blame] | 346 | if (is_del) |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 347 | rc = VNET_API_ERROR_NO_SUCH_ENTRY; |
Neale Ranns | 2dd6852 | 2017-02-16 03:38:59 -0800 | [diff] [blame] | 348 | else |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 349 | { |
| 350 | /* create a new entry */ |
| 351 | vec_validate_init_empty (dm->vss_index_by_rx_fib_index[proto], |
| 352 | rx_fib_index, ~0); |
Neale Ranns | 2dd6852 | 2017-02-16 03:38:59 -0800 | [diff] [blame] | 353 | |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 354 | /* hold a lock on the table whilst the VSS info exist */ |
| 355 | pool_get (dm->vss[proto], v); |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 356 | update_vss (v, vss_type, vpn_ascii_id, oui, vpn_index); |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 357 | dm->vss_index_by_rx_fib_index[proto][rx_fib_index] = |
| 358 | v - dm->vss[proto]; |
| 359 | dhcp_proxy_rx_table_lock (proto, rx_fib_index); |
| 360 | } |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 361 | } |
Neale Ranns | 2dd6852 | 2017-02-16 03:38:59 -0800 | [diff] [blame] | 362 | |
| 363 | /* Release the lock taken during the create_or_lock at the start */ |
Neale Ranns | 358425b | 2017-02-20 09:42:36 -0800 | [diff] [blame] | 364 | dhcp_proxy_rx_table_unlock (proto, rx_fib_index); |
| 365 | |
Neale Ranns | 2dd6852 | 2017-02-16 03:38:59 -0800 | [diff] [blame] | 366 | return (rc); |
| 367 | } |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 368 | |
| 369 | /* |
| 370 | * fd.io coding-style-patch-verification: ON |
| 371 | * |
| 372 | * Local Variables: |
| 373 | * eval: (c-set-style "gnu") |
| 374 | * End: |
| 375 | */ |