Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1 | /* |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 2 | * Copyright (c) 2016 Cisco and/or its affiliates. |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 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 | */ |
Florin Coras | ff0bf13 | 2016-09-05 19:30:35 +0200 | [diff] [blame] | 15 | /** |
| 16 | * @file |
| 17 | * @brief Common utility functions for IPv4, IPv6 and L2 LISP-GPE tunnels. |
| 18 | * |
| 19 | */ |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 20 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 21 | #include <vnet/lisp-gpe/lisp_gpe.h> |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 22 | #include <vnet/lisp-gpe/lisp_gpe_fwd_entry.h> |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 23 | #include <vnet/lisp-gpe/lisp_gpe_adjacency.h> |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 24 | #include <vnet/lisp-gpe/lisp_gpe_tenant.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 25 | |
Florin Coras | ff0bf13 | 2016-09-05 19:30:35 +0200 | [diff] [blame] | 26 | /** LISP-GPE global state */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 27 | lisp_gpe_main_t lisp_gpe_main; |
| 28 | |
Florin Coras | 1a1adc7 | 2016-07-22 01:45:30 +0200 | [diff] [blame] | 29 | |
Florin Coras | ff0bf13 | 2016-09-05 19:30:35 +0200 | [diff] [blame] | 30 | /** CLI command to add/del forwarding entry. */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 31 | static clib_error_t * |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 32 | lisp_gpe_add_del_fwd_entry_command_fn (vlib_main_t * vm, |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 33 | unformat_input_t * input, |
| 34 | vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 35 | { |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 36 | unformat_input_t _line_input, *line_input = &_line_input; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 37 | u8 is_add = 1; |
Florin Coras | bb5c22f | 2016-08-02 02:31:03 +0200 | [diff] [blame] | 38 | ip_address_t lloc, rloc; |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 39 | clib_error_t *error = 0; |
| 40 | gid_address_t _reid, *reid = &_reid, _leid, *leid = &_leid; |
Filip Tehlar | c3af7bf | 2017-01-13 14:13:09 +0100 | [diff] [blame] | 41 | u8 reid_set = 0, leid_set = 0, is_negative = 0, dp_table_set = 0, |
| 42 | vni_set = 0; |
| 43 | u32 vni = 0, dp_table = 0, action = ~0, w; |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 44 | locator_pair_t pair, *pairs = 0; |
Andrej Kozemcak | 8ebb2a1 | 2016-06-07 12:25:20 +0200 | [diff] [blame] | 45 | int rv; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 46 | |
Filip Tehlar | c3af7bf | 2017-01-13 14:13:09 +0100 | [diff] [blame] | 47 | memset (leid, 0, sizeof (*leid)); |
| 48 | memset (reid, 0, sizeof (*reid)); |
| 49 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 50 | /* Get a line of input. */ |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 51 | if (!unformat_user (input, unformat_line_input, line_input)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 52 | return 0; |
| 53 | |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 54 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 55 | { |
| 56 | if (unformat (line_input, "del")) |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 57 | is_add = 0; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 58 | else if (unformat (line_input, "add")) |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 59 | is_add = 1; |
| 60 | else if (unformat (line_input, "leid %U", unformat_gid_address, leid)) |
| 61 | { |
| 62 | leid_set = 1; |
| 63 | } |
| 64 | else if (unformat (line_input, "reid %U", unformat_gid_address, reid)) |
| 65 | { |
| 66 | reid_set = 1; |
| 67 | } |
Florin Coras | 03c4f99 | 2016-07-19 15:27:58 +0200 | [diff] [blame] | 68 | else if (unformat (line_input, "vni %u", &vni)) |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 69 | { |
| 70 | gid_address_vni (leid) = vni; |
| 71 | gid_address_vni (reid) = vni; |
| 72 | vni_set = 1; |
| 73 | } |
Filip Tehlar | c3af7bf | 2017-01-13 14:13:09 +0100 | [diff] [blame] | 74 | else if (unformat (line_input, "vrf %u", &dp_table)) |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 75 | { |
Filip Tehlar | c3af7bf | 2017-01-13 14:13:09 +0100 | [diff] [blame] | 76 | dp_table_set = 1; |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 77 | } |
Filip Tehlar | c3af7bf | 2017-01-13 14:13:09 +0100 | [diff] [blame] | 78 | else if (unformat (line_input, "bd %u", &dp_table)) |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 79 | { |
Filip Tehlar | c3af7bf | 2017-01-13 14:13:09 +0100 | [diff] [blame] | 80 | dp_table_set = 1; |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 81 | } |
Florin Coras | 03c4f99 | 2016-07-19 15:27:58 +0200 | [diff] [blame] | 82 | else if (unformat (line_input, "negative action %U", |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 83 | unformat_negative_mapping_action, &action)) |
| 84 | { |
| 85 | is_negative = 1; |
| 86 | } |
Filip Tehlar | c3af7bf | 2017-01-13 14:13:09 +0100 | [diff] [blame] | 87 | else if (unformat (line_input, "loc-pair %U %U w %d", |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 88 | unformat_ip_address, &lloc, |
Filip Tehlar | c3af7bf | 2017-01-13 14:13:09 +0100 | [diff] [blame] | 89 | unformat_ip_address, &rloc, &w)) |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 90 | { |
| 91 | pair.lcl_loc = lloc; |
| 92 | pair.rmt_loc = rloc; |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 93 | pair.weight = w; |
Florin Coras | 42e480d | 2017-01-16 00:57:02 -0800 | [diff] [blame] | 94 | pair.priority = 0; |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 95 | vec_add1 (pairs, pair); |
| 96 | } |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 97 | else |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 98 | { |
| 99 | error = unformat_parse_error (line_input); |
Filip Tehlar | c3af7bf | 2017-01-13 14:13:09 +0100 | [diff] [blame] | 100 | vlib_cli_output (vm, "parse error: '%U'", |
| 101 | format_unformat_error, line_input); |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 102 | goto done; |
| 103 | } |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 104 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 105 | |
Florin Coras | 03c4f99 | 2016-07-19 15:27:58 +0200 | [diff] [blame] | 106 | if (!reid_set) |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 107 | { |
Filip Tehlar | c3af7bf | 2017-01-13 14:13:09 +0100 | [diff] [blame] | 108 | vlib_cli_output (vm, "remote eid must be set!"); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 109 | goto done; |
| 110 | } |
| 111 | |
Florin Coras | b69111e | 2017-02-13 23:55:27 -0800 | [diff] [blame] | 112 | if (gid_address_type (reid) != GID_ADDR_NSH && (!vni_set || !dp_table_set)) |
| 113 | { |
| 114 | vlib_cli_output (vm, "vni and vrf/bd must be set!"); |
| 115 | goto done; |
| 116 | } |
| 117 | |
Florin Coras | 03c4f99 | 2016-07-19 15:27:58 +0200 | [diff] [blame] | 118 | if (is_negative) |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 119 | { |
Florin Coras | 03c4f99 | 2016-07-19 15:27:58 +0200 | [diff] [blame] | 120 | if (~0 == action) |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 121 | { |
Filip Tehlar | c3af7bf | 2017-01-13 14:13:09 +0100 | [diff] [blame] | 122 | vlib_cli_output (vm, "no action set for negative tunnel!"); |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 123 | goto done; |
| 124 | } |
Florin Coras | 03c4f99 | 2016-07-19 15:27:58 +0200 | [diff] [blame] | 125 | } |
| 126 | else |
| 127 | { |
Florin Coras | bb5c22f | 2016-08-02 02:31:03 +0200 | [diff] [blame] | 128 | if (vec_len (pairs) == 0) |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 129 | { |
Filip Tehlar | c3af7bf | 2017-01-13 14:13:09 +0100 | [diff] [blame] | 130 | vlib_cli_output (vm, "expected ip4/ip6 locators"); |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 131 | goto done; |
| 132 | } |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 133 | } |
| 134 | |
Florin Coras | 03c4f99 | 2016-07-19 15:27:58 +0200 | [diff] [blame] | 135 | if (!leid_set) |
| 136 | { |
| 137 | /* if leid not set, make sure it's the same AFI like reid */ |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 138 | gid_address_type (leid) = gid_address_type (reid); |
Florin Coras | 03c4f99 | 2016-07-19 15:27:58 +0200 | [diff] [blame] | 139 | if (GID_ADDR_IP_PREFIX == gid_address_type (reid)) |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 140 | gid_address_ip_version (leid) = gid_address_ip_version (reid); |
Florin Coras | 03c4f99 | 2016-07-19 15:27:58 +0200 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | /* add fwd entry */ |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 144 | vnet_lisp_gpe_add_del_fwd_entry_args_t _a, *a = &_a; |
| 145 | memset (a, 0, sizeof (a[0])); |
Florin Coras | 03c4f99 | 2016-07-19 15:27:58 +0200 | [diff] [blame] | 146 | |
| 147 | a->is_add = is_add; |
Florin Coras | 82bf7cd | 2016-09-26 18:59:44 +0300 | [diff] [blame] | 148 | a->is_negative = is_negative; |
Florin Coras | 03c4f99 | 2016-07-19 15:27:58 +0200 | [diff] [blame] | 149 | a->vni = vni; |
Filip Tehlar | c3af7bf | 2017-01-13 14:13:09 +0100 | [diff] [blame] | 150 | a->table_id = dp_table; |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 151 | gid_address_copy (&a->lcl_eid, leid); |
| 152 | gid_address_copy (&a->rmt_eid, reid); |
Florin Coras | bb5c22f | 2016-08-02 02:31:03 +0200 | [diff] [blame] | 153 | a->locator_pairs = pairs; |
Florin Coras | ce1b4c7 | 2017-01-26 14:25:34 -0800 | [diff] [blame] | 154 | a->action = action; |
Florin Coras | 03c4f99 | 2016-07-19 15:27:58 +0200 | [diff] [blame] | 155 | |
| 156 | rv = vnet_lisp_gpe_add_del_fwd_entry (a, 0); |
| 157 | if (0 != rv) |
| 158 | { |
Filip Tehlar | c3af7bf | 2017-01-13 14:13:09 +0100 | [diff] [blame] | 159 | vlib_cli_output (vm, "failed to %s gpe tunnel!", |
| 160 | is_add ? "add" : "delete"); |
Florin Coras | 03c4f99 | 2016-07-19 15:27:58 +0200 | [diff] [blame] | 161 | } |
| 162 | |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 163 | done: |
Filip Tehlar | c3af7bf | 2017-01-13 14:13:09 +0100 | [diff] [blame] | 164 | unformat_free (line_input); |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 165 | vec_free (pairs); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 166 | return error; |
| 167 | } |
| 168 | |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 169 | /* *INDENT-OFF* */ |
Florin Coras | ed09a05 | 2016-05-06 14:22:40 +0200 | [diff] [blame] | 170 | VLIB_CLI_COMMAND (lisp_gpe_add_del_fwd_entry_command, static) = { |
Filip Tehlar | 82786c4 | 2017-02-20 15:20:37 +0100 | [diff] [blame] | 171 | .path = "gpe entry", |
| 172 | .short_help = "gpe entry add/del vni <vni> vrf/bd <id> [leid <leid>]" |
Filip Tehlar | c3af7bf | 2017-01-13 14:13:09 +0100 | [diff] [blame] | 173 | "reid <reid> [loc-pair <lloc> <rloc> w <weight>] " |
Florin Coras | ff0bf13 | 2016-09-05 19:30:35 +0200 | [diff] [blame] | 174 | "[negative action <action>]", |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 175 | .function = lisp_gpe_add_del_fwd_entry_command_fn, |
| 176 | }; |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 177 | /* *INDENT-ON* */ |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 178 | |
Florin Coras | ff0bf13 | 2016-09-05 19:30:35 +0200 | [diff] [blame] | 179 | /** Check if LISP-GPE is enabled. */ |
Andrej Kozemcak | a9edd85 | 2016-05-02 12:14:33 +0200 | [diff] [blame] | 180 | u8 |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 181 | vnet_lisp_gpe_enable_disable_status (void) |
Andrej Kozemcak | a9edd85 | 2016-05-02 12:14:33 +0200 | [diff] [blame] | 182 | { |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 183 | lisp_gpe_main_t *lgm = &lisp_gpe_main; |
Andrej Kozemcak | a9edd85 | 2016-05-02 12:14:33 +0200 | [diff] [blame] | 184 | |
| 185 | return lgm->is_en; |
| 186 | } |
| 187 | |
Florin Coras | ff0bf13 | 2016-09-05 19:30:35 +0200 | [diff] [blame] | 188 | /** Enable/disable LISP-GPE. */ |
Florin Coras | 577c355 | 2016-04-21 00:45:40 +0200 | [diff] [blame] | 189 | clib_error_t * |
| 190 | vnet_lisp_gpe_enable_disable (vnet_lisp_gpe_enable_disable_args_t * a) |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 191 | { |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 192 | lisp_gpe_main_t *lgm = &lisp_gpe_main; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 193 | |
Florin Coras | 577c355 | 2016-04-21 00:45:40 +0200 | [diff] [blame] | 194 | if (a->is_en) |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 195 | { |
Andrej Kozemcak | a9edd85 | 2016-05-02 12:14:33 +0200 | [diff] [blame] | 196 | lgm->is_en = 1; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 197 | } |
| 198 | else |
| 199 | { |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 200 | /* remove all entries */ |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 201 | vnet_lisp_gpe_fwd_entry_flush (); |
Florin Coras | 577c355 | 2016-04-21 00:45:40 +0200 | [diff] [blame] | 202 | |
Florin Coras | 1a1adc7 | 2016-07-22 01:45:30 +0200 | [diff] [blame] | 203 | /* disable all l3 ifaces */ |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 204 | lisp_gpe_tenant_flush (); |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 205 | |
Andrej Kozemcak | a9edd85 | 2016-05-02 12:14:33 +0200 | [diff] [blame] | 206 | lgm->is_en = 0; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 207 | } |
Florin Coras | 577c355 | 2016-04-21 00:45:40 +0200 | [diff] [blame] | 208 | |
| 209 | return 0; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 210 | } |
| 211 | |
Florin Coras | ff0bf13 | 2016-09-05 19:30:35 +0200 | [diff] [blame] | 212 | /** CLI command to enable/disable LISP-GPE. */ |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 213 | static clib_error_t * |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 214 | lisp_gpe_enable_disable_command_fn (vlib_main_t * vm, |
| 215 | unformat_input_t * input, |
| 216 | vlib_cli_command_t * cmd) |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 217 | { |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 218 | unformat_input_t _line_input, *line_input = &_line_input; |
Florin Coras | 577c355 | 2016-04-21 00:45:40 +0200 | [diff] [blame] | 219 | u8 is_en = 1; |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 220 | vnet_lisp_gpe_enable_disable_args_t _a, *a = &_a; |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 221 | clib_error_t *error = NULL; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 222 | |
| 223 | /* Get a line of input. */ |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 224 | if (!unformat_user (input, unformat_line_input, line_input)) |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 225 | return 0; |
| 226 | |
| 227 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 228 | { |
Florin Coras | 577c355 | 2016-04-21 00:45:40 +0200 | [diff] [blame] | 229 | if (unformat (line_input, "enable")) |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 230 | is_en = 1; |
Florin Coras | 577c355 | 2016-04-21 00:45:40 +0200 | [diff] [blame] | 231 | else if (unformat (line_input, "disable")) |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 232 | is_en = 0; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 233 | else |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 234 | { |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 235 | error = clib_error_return (0, "parse error: '%U'", |
| 236 | format_unformat_error, line_input); |
| 237 | goto done; |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 238 | } |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 239 | } |
Florin Coras | 577c355 | 2016-04-21 00:45:40 +0200 | [diff] [blame] | 240 | a->is_en = is_en; |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 241 | error = vnet_lisp_gpe_enable_disable (a); |
| 242 | |
| 243 | done: |
| 244 | unformat_free (line_input); |
| 245 | |
| 246 | return error; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 247 | } |
| 248 | |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 249 | /* *INDENT-OFF* */ |
Florin Coras | 577c355 | 2016-04-21 00:45:40 +0200 | [diff] [blame] | 250 | VLIB_CLI_COMMAND (enable_disable_lisp_gpe_command, static) = { |
Filip Tehlar | 82786c4 | 2017-02-20 15:20:37 +0100 | [diff] [blame] | 251 | .path = "gpe", |
| 252 | .short_help = "gpe [enable|disable]", |
Florin Coras | 577c355 | 2016-04-21 00:45:40 +0200 | [diff] [blame] | 253 | .function = lisp_gpe_enable_disable_command_fn, |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 254 | }; |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 255 | /* *INDENT-ON* */ |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 256 | |
Florin Coras | ff0bf13 | 2016-09-05 19:30:35 +0200 | [diff] [blame] | 257 | /** CLI command to show LISP-GPE interfaces. */ |
Filip Tehlar | 53f09e3 | 2016-05-19 14:25:44 +0200 | [diff] [blame] | 258 | static clib_error_t * |
| 259 | lisp_show_iface_command_fn (vlib_main_t * vm, |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 260 | unformat_input_t * input, |
| 261 | vlib_cli_command_t * cmd) |
Filip Tehlar | 53f09e3 | 2016-05-19 14:25:44 +0200 | [diff] [blame] | 262 | { |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 263 | lisp_gpe_main_t *lgm = &lisp_gpe_main; |
| 264 | hash_pair_t *p; |
Filip Tehlar | 53f09e3 | 2016-05-19 14:25:44 +0200 | [diff] [blame] | 265 | |
| 266 | vlib_cli_output (vm, "%=10s%=12s", "vrf", "hw_if_index"); |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 267 | |
| 268 | /* *INDENT-OFF* */ |
Florin Coras | 1a1adc7 | 2016-07-22 01:45:30 +0200 | [diff] [blame] | 269 | hash_foreach_pair (p, lgm->l3_ifaces.hw_if_index_by_dp_table, ({ |
Filip Tehlar | 53f09e3 | 2016-05-19 14:25:44 +0200 | [diff] [blame] | 270 | vlib_cli_output (vm, "%=10d%=10d", p->key, p->value[0]); |
| 271 | })); |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 272 | /* *INDENT-ON* */ |
Florin Coras | 1a1adc7 | 2016-07-22 01:45:30 +0200 | [diff] [blame] | 273 | |
| 274 | if (0 != lgm->l2_ifaces.hw_if_index_by_dp_table) |
| 275 | { |
| 276 | vlib_cli_output (vm, "%=10s%=12s", "bd_id", "hw_if_index"); |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 277 | /* *INDENT-OFF* */ |
Florin Coras | 1a1adc7 | 2016-07-22 01:45:30 +0200 | [diff] [blame] | 278 | hash_foreach_pair (p, lgm->l2_ifaces.hw_if_index_by_dp_table, ({ |
| 279 | vlib_cli_output (vm, "%=10d%=10d", p->key, p->value[0]); |
| 280 | })); |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 281 | /* *INDENT-ON* */ |
Florin Coras | 1a1adc7 | 2016-07-22 01:45:30 +0200 | [diff] [blame] | 282 | } |
Filip Tehlar | 53f09e3 | 2016-05-19 14:25:44 +0200 | [diff] [blame] | 283 | return 0; |
| 284 | } |
| 285 | |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 286 | /* *INDENT-OFF* */ |
Filip Tehlar | 53f09e3 | 2016-05-19 14:25:44 +0200 | [diff] [blame] | 287 | VLIB_CLI_COMMAND (lisp_show_iface_command) = { |
Filip Tehlar | 82786c4 | 2017-02-20 15:20:37 +0100 | [diff] [blame] | 288 | .path = "show gpe interface", |
| 289 | .short_help = "show gpe interface", |
Filip Tehlar | 53f09e3 | 2016-05-19 14:25:44 +0200 | [diff] [blame] | 290 | .function = lisp_show_iface_command_fn, |
| 291 | }; |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 292 | /* *INDENT-ON* */ |
Florin Coras | 1a1adc7 | 2016-07-22 01:45:30 +0200 | [diff] [blame] | 293 | |
Florin Coras | ff0bf13 | 2016-09-05 19:30:35 +0200 | [diff] [blame] | 294 | /** Format LISP-GPE status. */ |
Florin Coras | 1a1adc7 | 2016-07-22 01:45:30 +0200 | [diff] [blame] | 295 | u8 * |
| 296 | format_vnet_lisp_gpe_status (u8 * s, va_list * args) |
| 297 | { |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 298 | lisp_gpe_main_t *lgm = &lisp_gpe_main; |
Florin Coras | 1a1adc7 | 2016-07-22 01:45:30 +0200 | [diff] [blame] | 299 | return format (s, "%s", lgm->is_en ? "enabled" : "disabled"); |
| 300 | } |
| 301 | |
Florin Coras | ff0bf13 | 2016-09-05 19:30:35 +0200 | [diff] [blame] | 302 | /** LISP-GPE init function. */ |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 303 | clib_error_t * |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 304 | lisp_gpe_init (vlib_main_t * vm) |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 305 | { |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 306 | lisp_gpe_main_t *lgm = &lisp_gpe_main; |
| 307 | clib_error_t *error = 0; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 308 | |
| 309 | if ((error = vlib_call_init_function (vm, ip_main_init))) |
| 310 | return error; |
| 311 | |
| 312 | if ((error = vlib_call_init_function (vm, ip4_lookup_init))) |
| 313 | return error; |
| 314 | |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 315 | lgm->vnet_main = vnet_get_main (); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 316 | lgm->vlib_main = vm; |
| 317 | lgm->im4 = &ip4_main; |
Florin Coras | 02655bd | 2016-04-26 00:17:24 +0200 | [diff] [blame] | 318 | lgm->im6 = &ip6_main; |
| 319 | lgm->lm4 = &ip4_main.lookup_main; |
| 320 | lgm->lm6 = &ip6_main.lookup_main; |
Florin Coras | 577c355 | 2016-04-21 00:45:40 +0200 | [diff] [blame] | 321 | |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 322 | lgm->lisp_gpe_fwd_entries = |
| 323 | hash_create_mem (0, sizeof (lisp_gpe_fwd_entry_key_t), sizeof (uword)); |
Florin Coras | 1a1adc7 | 2016-07-22 01:45:30 +0200 | [diff] [blame] | 324 | |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 325 | udp_register_dst_port (vm, UDP_DST_PORT_lisp_gpe, |
| 326 | lisp_gpe_ip4_input_node.index, 1 /* is_ip4 */ ); |
Florin Coras | 02655bd | 2016-04-26 00:17:24 +0200 | [diff] [blame] | 327 | udp_register_dst_port (vm, UDP_DST_PORT_lisp_gpe6, |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 328 | lisp_gpe_ip6_input_node.index, 0 /* is_ip4 */ ); |
Florin Coras | 263440e | 2017-02-22 23:38:08 -0800 | [diff] [blame] | 329 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 330 | return 0; |
| 331 | } |
| 332 | |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 333 | VLIB_INIT_FUNCTION (lisp_gpe_init); |
| 334 | |
| 335 | /* |
| 336 | * fd.io coding-style-patch-verification: ON |
| 337 | * |
| 338 | * Local Variables: |
| 339 | * eval: (c-set-style "gnu") |
| 340 | * End: |
| 341 | */ |