Pavel Kotucek | 6899a30 | 2017-06-08 08:46:10 +0200 | [diff] [blame] | 1 | /* |
| 2 | * p2p_ethernet.c: p2p ethernet |
| 3 | * |
| 4 | * Copyright (c) 2012 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 <vppinfra/bihash_16_8.h> |
| 19 | #include <vnet/vnet.h> |
| 20 | #include <vnet/ethernet/p2p_ethernet.h> |
| 21 | |
| 22 | int |
| 23 | p2p_ethernet_add_del (vlib_main_t * vm, u32 parent_if_index, |
| 24 | u8 * client_mac, int is_add) |
| 25 | { |
| 26 | return 0; |
| 27 | } |
| 28 | |
| 29 | static clib_error_t * |
| 30 | vnet_p2p_ethernet_add_del (vlib_main_t * vm, unformat_input_t * input, |
| 31 | vlib_cli_command_t * cmd) |
| 32 | { |
| 33 | vnet_main_t *vnm = vnet_get_main (); |
| 34 | |
| 35 | int is_add = 1; |
| 36 | int remote_mac = 0; |
| 37 | u32 hw_if_index = ~0; |
| 38 | u8 client_mac[6]; |
| 39 | |
| 40 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
| 41 | { |
| 42 | if (unformat |
| 43 | (input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index)) |
| 44 | ; |
| 45 | else if (unformat (input, "%U", unformat_ethernet_address, &client_mac)) |
| 46 | remote_mac = 1; |
| 47 | else if (unformat (input, "del")) |
| 48 | is_add = 0; |
| 49 | else |
| 50 | break; |
| 51 | } |
| 52 | |
| 53 | if (hw_if_index == ~0) |
| 54 | return clib_error_return (0, "Please specify parent interface ..."); |
| 55 | if (!remote_mac) |
| 56 | return clib_error_return (0, "Please specify client MAC address ..."); |
| 57 | |
| 58 | u32 rv; |
| 59 | rv = p2p_ethernet_add_del (vm, hw_if_index, client_mac, is_add); |
| 60 | switch (rv) |
| 61 | { |
| 62 | case VNET_API_ERROR_BOND_SLAVE_NOT_ALLOWED: |
| 63 | return clib_error_return (0, |
| 64 | "not allowed as parent interface belongs to a BondEthernet interface"); |
| 65 | case -1: |
| 66 | return clib_error_return (0, |
| 67 | "p2p ethernet for given parent interface and client mac already exists"); |
| 68 | case -2: |
| 69 | return clib_error_return (0, |
| 70 | "couldn't create p2p ethernet subinterface"); |
| 71 | case -3: |
| 72 | return clib_error_return (0, |
| 73 | "p2p ethernet for given parent interface and client mac doesn't exist"); |
| 74 | default: |
| 75 | break; |
| 76 | } |
| 77 | return 0; |
| 78 | } |
| 79 | |
| 80 | /* *INDENT-OFF* */ |
| 81 | VLIB_CLI_COMMAND (p2p_ethernet_add_del_command, static) = |
| 82 | { |
| 83 | .path = "p2p_ethernet ", |
| 84 | .function = vnet_p2p_ethernet_add_del, |
| 85 | .short_help = "p2p_ethernet <intfc> <mac-address> [del]",}; |
| 86 | /* *INDENT-ON* */ |
| 87 | |
| 88 | static clib_error_t * |
| 89 | p2p_ethernet_init (vlib_main_t * vm) |
| 90 | { |
| 91 | return 0; |
| 92 | } |
| 93 | |
| 94 | VLIB_INIT_FUNCTION (p2p_ethernet_init); |
| 95 | |
| 96 | /* |
| 97 | * fd.io coding-style-patch-verification: ON |
| 98 | * |
| 99 | * Local Variables: |
| 100 | * eval: (c-set-style "gnu") |
| 101 | * End: |
| 102 | */ |