FD.io VPP  v17.07-30-g839fa73
Vector Packet Processing
p2p_ethernet.c
Go to the documentation of this file.
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>
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 *
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 
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 *
90 {
91  return 0;
92 }
93 
95 
96 /*
97  * fd.io coding-style-patch-verification: ON
98  *
99  * Local Variables:
100  * eval: (c-set-style "gnu")
101  * End:
102  */
unformat_function_t unformat_vnet_hw_interface
vnet_main_t * vnet_get_main(void)
Definition: misc.c:46
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:111
#define clib_error_return(e, args...)
Definition: error.h:99
static clib_error_t * p2p_ethernet_init(vlib_main_t *vm)
Definition: p2p_ethernet.c:89
struct _unformat_input_t unformat_input_t
int p2p_ethernet_add_del(vlib_main_t *vm, u32 parent_if_index, u8 *client_mac, int is_add)
Definition: p2p_ethernet.c:23
#define UNFORMAT_END_OF_INPUT
Definition: format.h:143
static clib_error_t * vnet_p2p_ethernet_add_del(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: p2p_ethernet.c:30
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:154
uword unformat_ethernet_address(unformat_input_t *input, va_list *args)
Definition: format.c:227
unsigned int u32
Definition: types.h:88
unsigned char u8
Definition: types.h:56
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:972
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:169