Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 1 | /* |
| 2 | *------------------------------------------------------------------ |
| 3 | * Copyright (c) 2016 Cisco and/or its affiliates. |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at: |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | *------------------------------------------------------------------ |
| 16 | */ |
Matus Fabian | 82e29c4 | 2016-05-11 04:49:46 -0700 | [diff] [blame] | 17 | #include <stdint.h> |
| 18 | #include <net/if.h> |
| 19 | #include <sys/ioctl.h> |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 20 | |
| 21 | #include <vlib/vlib.h> |
| 22 | #include <vlib/unix/unix.h> |
| 23 | #include <vnet/ethernet/ethernet.h> |
| 24 | |
Matus Fabian | 82e29c4 | 2016-05-11 04:49:46 -0700 | [diff] [blame] | 25 | #include <vnet/devices/netmap/net_netmap.h> |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 26 | #include <vnet/devices/netmap/netmap.h> |
| 27 | |
| 28 | static clib_error_t * |
| 29 | netmap_create_command_fn (vlib_main_t * vm, unformat_input_t * input, |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame^] | 30 | vlib_cli_command_t * cmd) |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 31 | { |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame^] | 32 | unformat_input_t _line_input, *line_input = &_line_input; |
| 33 | u8 *host_if_name = NULL; |
| 34 | u8 hwaddr[6]; |
| 35 | u8 *hw_addr_ptr = 0; |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 36 | int r; |
| 37 | u8 is_pipe = 0; |
| 38 | u8 is_master = 0; |
Pierre Pfister | 78ea9c2 | 2016-05-23 12:51:54 +0100 | [diff] [blame] | 39 | u32 sw_if_index = ~0; |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 40 | |
| 41 | /* Get a line of input. */ |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame^] | 42 | if (!unformat_user (input, unformat_line_input, line_input)) |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 43 | return 0; |
| 44 | |
| 45 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 46 | { |
| 47 | if (unformat (line_input, "name %s", &host_if_name)) |
| 48 | ; |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame^] | 49 | else |
| 50 | if (unformat |
| 51 | (line_input, "hw-addr %U", unformat_ethernet_address, hwaddr)) |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 52 | hw_addr_ptr = hwaddr; |
| 53 | else if (unformat (line_input, "pipe")) |
| 54 | is_pipe = 1; |
| 55 | else if (unformat (line_input, "master")) |
| 56 | is_master = 1; |
| 57 | else if (unformat (line_input, "slave")) |
| 58 | is_master = 0; |
| 59 | else |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame^] | 60 | return clib_error_return (0, "unknown input `%U'", |
| 61 | format_unformat_error, input); |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 62 | } |
| 63 | unformat_free (line_input); |
| 64 | |
| 65 | if (host_if_name == NULL) |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame^] | 66 | return clib_error_return (0, "missing host interface name"); |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 67 | |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame^] | 68 | r = |
| 69 | netmap_create_if (vm, host_if_name, hw_addr_ptr, is_pipe, is_master, |
| 70 | &sw_if_index); |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 71 | |
| 72 | if (r == VNET_API_ERROR_SYSCALL_ERROR_1) |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame^] | 73 | return clib_error_return (0, "%s (errno %d)", strerror (errno), errno); |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 74 | |
| 75 | if (r == VNET_API_ERROR_INVALID_INTERFACE) |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame^] | 76 | return clib_error_return (0, "Invalid interface name"); |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 77 | |
| 78 | if (r == VNET_API_ERROR_SUBIF_ALREADY_EXISTS) |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame^] | 79 | return clib_error_return (0, "Interface already exists"); |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 80 | |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame^] | 81 | vlib_cli_output (vm, "%U\n", format_vnet_sw_if_index_name, vnet_get_main (), |
| 82 | sw_if_index); |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 83 | return 0; |
| 84 | } |
| 85 | |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame^] | 86 | /* *INDENT-OFF* */ |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 87 | VLIB_CLI_COMMAND (netmap_create_command, static) = { |
| 88 | .path = "create netmap", |
| 89 | .short_help = "create netmap name [<intf name>|valeXXX:YYY] " |
| 90 | "[hw-addr <mac>] [pipe] [master|slave]", |
| 91 | .function = netmap_create_command_fn, |
| 92 | }; |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame^] | 93 | /* *INDENT-ON* */ |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 94 | |
| 95 | static clib_error_t * |
| 96 | netmap_delete_command_fn (vlib_main_t * vm, unformat_input_t * input, |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame^] | 97 | vlib_cli_command_t * cmd) |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 98 | { |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame^] | 99 | unformat_input_t _line_input, *line_input = &_line_input; |
| 100 | u8 *host_if_name = NULL; |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 101 | |
| 102 | /* Get a line of input. */ |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame^] | 103 | if (!unformat_user (input, unformat_line_input, line_input)) |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 104 | return 0; |
| 105 | |
| 106 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 107 | { |
| 108 | if (unformat (line_input, "name %s", &host_if_name)) |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame^] | 109 | ; |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 110 | else |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame^] | 111 | return clib_error_return (0, "unknown input `%U'", |
| 112 | format_unformat_error, input); |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 113 | } |
| 114 | unformat_free (line_input); |
| 115 | |
| 116 | if (host_if_name == NULL) |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame^] | 117 | return clib_error_return (0, "missing host interface name"); |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 118 | |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame^] | 119 | netmap_delete_if (vm, host_if_name); |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 120 | |
| 121 | return 0; |
| 122 | } |
| 123 | |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame^] | 124 | /* *INDENT-OFF* */ |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 125 | VLIB_CLI_COMMAND (netmap_delete_command, static) = { |
| 126 | .path = "delete netmap", |
| 127 | .short_help = "delete netmap name <interface name>", |
| 128 | .function = netmap_delete_command_fn, |
| 129 | }; |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame^] | 130 | /* *INDENT-ON* */ |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 131 | |
| 132 | clib_error_t * |
| 133 | netmap_cli_init (vlib_main_t * vm) |
| 134 | { |
| 135 | return 0; |
| 136 | } |
| 137 | |
| 138 | VLIB_INIT_FUNCTION (netmap_cli_init); |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame^] | 139 | |
| 140 | /* |
| 141 | * fd.io coding-style-patch-verification: ON |
| 142 | * |
| 143 | * Local Variables: |
| 144 | * eval: (c-set-style "gnu") |
| 145 | * End: |
| 146 | */ |