feature: api cleanup
[vpp.git] / src / vnet / feature / feature_api.c
1 /*
2  *------------------------------------------------------------------
3  * feature_api.c - vnet feature 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 #include <vnet/feature/feature.h>
23
24 #include <vnet/feature/feature.api_enum.h>
25 #include <vnet/feature/feature.api_types.h>
26
27 #define REPLY_MSG_ID_BASE msg_id_base
28 #include <vlibapi/api_helper_macros.h>
29
30 static u16 msg_id_base;
31
32 static void
33 vl_api_feature_enable_disable_t_handler (vl_api_feature_enable_disable_t * mp)
34 {
35   vl_api_feature_enable_disable_reply_t *rmp;
36   int rv = 0;
37
38   VALIDATE_SW_IF_INDEX (mp);
39
40   u8 *arc_name = format (0, "%s%c", mp->arc_name, 0);
41   u8 *feature_name = format (0, "%s%c", mp->feature_name, 0);
42
43   vec_terminate_c_string (arc_name);
44   vec_terminate_c_string (feature_name);
45
46   vnet_feature_registration_t *reg =
47     vnet_get_feature_reg ((const char *) arc_name,
48                           (const char *) feature_name);
49   if (reg == 0)
50     rv = VNET_API_ERROR_INVALID_VALUE;
51   else
52     {
53       u32 sw_if_index = ntohl (mp->sw_if_index);
54       clib_error_t *error = 0;
55
56       if (reg->enable_disable_cb)
57         error = reg->enable_disable_cb (sw_if_index, mp->enable);
58       if (!error)
59         vnet_feature_enable_disable ((const char *) arc_name,
60                                      (const char *) feature_name,
61                                      sw_if_index, mp->enable, 0, 0);
62       else
63         {
64           clib_error_report (error);
65           rv = VNET_API_ERROR_CANNOT_ENABLE_DISABLE_FEATURE;
66         }
67     }
68
69   vec_free (feature_name);
70   vec_free (arc_name);
71
72   BAD_SW_IF_INDEX_LABEL;
73
74   REPLY_MACRO (VL_API_FEATURE_ENABLE_DISABLE_REPLY);
75 }
76
77 #include <vnet/feature/feature.api.c>
78
79 static clib_error_t *
80 feature_api_hookup (vlib_main_t * vm)
81 {
82   /*
83    * Set up the (msg_name, crc, message-id) table
84    */
85   msg_id_base = setup_message_id_table ();
86
87   return 0;
88 }
89
90 VLIB_API_INIT_FUNCTION (feature_api_hookup);
91
92 /*
93  * fd.io coding-style-patch-verification: ON
94  *
95  * Local Variables:
96  * eval: (c-set-style "gnu")
97  * End:
98  */