eeb1d81d4d0a0947ae446a7d79b0a823208111fb
[vpp.git] / vnet / vnet / interface_api.c
1 /*
2  *------------------------------------------------------------------
3  * interface_api.c - vnet interface api
4  *
5  * Copyright (c) 2016 Cisco and/or its affiliates.
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at:
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *------------------------------------------------------------------
18  */
19
20 #include <vnet/vnet.h>
21 #include <vlibmemory/api.h>
22
23 #include <vnet/interface.h>
24 #include <vnet/api_errno.h>
25
26 #include <vnet/vnet_msg_enum.h>
27
28 #define vl_typedefs             /* define message structures */
29 #include <vnet/vnet_all_api_h.h>
30 #undef vl_typedefs
31
32 #define vl_endianfun            /* define message structures */
33 #include <vnet/vnet_all_api_h.h>
34 #undef vl_endianfun
35
36 /* instantiate all the print functions we know about */
37 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
38 #define vl_printfun
39 #include <vnet/vnet_all_api_h.h>
40 #undef vl_printfun
41
42 #include <vlibapi/api_helper_macros.h>
43
44 #define foreach_vpe_api_msg                             \
45 _(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags)
46
47 static void
48 vl_api_sw_interface_set_flags_t_handler (vl_api_sw_interface_set_flags_t * mp)
49 {
50   vl_api_sw_interface_set_flags_reply_t *rmp;
51   vnet_main_t *vnm = vnet_get_main ();
52   int rv = 0;
53   clib_error_t *error;
54   u16 flags;
55
56   VALIDATE_SW_IF_INDEX (mp);
57
58   flags = mp->admin_up_down ? VNET_SW_INTERFACE_FLAG_ADMIN_UP : 0;
59
60   error = vnet_sw_interface_set_flags (vnm, ntohl (mp->sw_if_index), flags);
61   if (error)
62     {
63       rv = -1;
64       clib_error_report (error);
65     }
66
67   BAD_SW_IF_INDEX_LABEL;
68   REPLY_MACRO (VL_API_SW_INTERFACE_SET_FLAGS_REPLY);
69 }
70
71
72 /*
73  * vpe_api_hookup
74  * Add vpe's API message handlers to the table.
75  * vlib has alread mapped shared memory and
76  * added the client registration handlers.
77  * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
78  */
79 #define vl_msg_name_crc_list
80 #include <vnet/vnet_all_api_h.h>
81 #undef vl_msg_name_crc_list
82
83 static void
84 setup_message_id_table (api_main_t * am)
85 {
86 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
87   foreach_vl_msg_name_crc_interface;
88 #undef _
89 }
90
91 static clib_error_t *
92 interface_api_hookup (vlib_main_t * vm)
93 {
94   api_main_t *am = &api_main;
95
96 #define _(N,n)                                                  \
97     vl_msg_api_set_handlers(VL_API_##N, #n,                     \
98                            vl_api_##n##_t_handler,              \
99                            vl_noop_handler,                     \
100                            vl_api_##n##_t_endian,               \
101                            vl_api_##n##_t_print,                \
102                            sizeof(vl_api_##n##_t), 1);
103   foreach_vpe_api_msg;
104 #undef _
105
106   /*
107    * Set up the (msg_name, crc, message-id) table
108    */
109   setup_message_id_table (am);
110
111   return 0;
112 }
113
114 VLIB_API_INIT_FUNCTION (interface_api_hookup);
115
116 /*
117  * fd.io coding-style-patch-verification: ON
118  *
119  * Local Variables:
120  * eval: (c-set-style "gnu")
121  * End:
122  */