FD.io VPP  v18.04-17-g3a0d853
Vector Packet Processing
feature_api.c
Go to the documentation of this file.
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/vnet_msg_enum.h>
25 
26 #define vl_typedefs /* define message structures */
27 #include <vnet/vnet_all_api_h.h>
28 #undef vl_typedefs
29 
30 #define vl_endianfun /* define message structures */
31 #include <vnet/vnet_all_api_h.h>
32 #undef vl_endianfun
33 
34 /* instantiate all the print functions we know about */
35 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
36 #define vl_printfun
37 #include <vnet/vnet_all_api_h.h>
38 #undef vl_printfun
39 
41 
42 #define foreach_feature_api_msg \
43 _(FEATURE_ENABLE_DISABLE, feature_enable_disable)
44 
45 static void
47 {
48  vl_api_feature_enable_disable_reply_t *rmp;
49  int rv = 0;
50 
52 
53  u8 *arc_name = format (0, "%s%c", mp->arc_name, 0);
54  u8 *feature_name = format (0, "%s%c", mp->feature_name, 0);
55 
56  vec_terminate_c_string (arc_name);
57  vec_terminate_c_string (feature_name);
58 
60  vnet_get_feature_reg ((const char *) arc_name,
61  (const char *) feature_name);
62  if (reg == 0)
63  rv = VNET_API_ERROR_INVALID_VALUE;
64  else
65  {
66  u32 sw_if_index = ntohl (mp->sw_if_index);
67  clib_error_t *error = 0;
68 
69  if (reg->enable_disable_cb)
70  error = reg->enable_disable_cb (sw_if_index, mp->enable);
71  if (!error)
72  vnet_feature_enable_disable ((const char *) arc_name,
73  (const char *) feature_name,
74  sw_if_index, mp->enable, 0, 0);
75  else
76  {
77  clib_error_report (error);
78  rv = VNET_API_ERROR_CANNOT_ENABLE_DISABLE_FEATURE;
79  }
80  }
81 
82  vec_free (feature_name);
83  vec_free (arc_name);
84 
86 
87  REPLY_MACRO (VL_API_FEATURE_ENABLE_DISABLE_REPLY);
88 }
89 
90 #define vl_msg_name_crc_list
91 #include <vnet/feature/feature.api.h>
92 #undef vl_msg_name_crc_list
93 
94 static void
96 {
97 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
98  foreach_vl_msg_name_crc_feature;
99 #undef _
100 }
101 
102 static clib_error_t *
104 {
105  api_main_t *am = &api_main;
106 
107 #define _(N,n) \
108  vl_msg_api_set_handlers(VL_API_##N, #n, \
109  vl_api_##n##_t_handler, \
110  vl_noop_handler, \
111  vl_api_##n##_t_endian, \
112  vl_api_##n##_t_print, \
113  sizeof(vl_api_##n##_t), 1);
115 #undef _
116 
117  /*
118  * Set up the (msg_name, crc, message-id) table
119  */
121 
122  return 0;
123 }
124 
126 
127 /*
128  * fd.io coding-style-patch-verification: ON
129  *
130  * Local Variables:
131  * eval: (c-set-style "gnu")
132  * End:
133  */
#define vec_terminate_c_string(V)
(If necessary) NULL terminate a vector containing a c-string.
Definition: vec.h:992
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:419
vnet_feature_registration_t * vnet_get_feature_reg(const char *arc_name, const char *node_name)
Definition: feature.c:142
#define foreach_feature_api_msg
Definition: feature_api.c:42
static void vl_api_feature_enable_disable_t_handler(vl_api_feature_enable_disable_t *mp)
Definition: feature_api.c:46
VLIB_API_INIT_FUNCTION(feature_api_hookup)
static void setup_message_id_table(api_main_t *am)
Definition: feature_api.c:95
#define REPLY_MACRO(t)
API main structure, used by both vpp and binary API clients.
Definition: api_common.h:199
#define BAD_SW_IF_INDEX_LABEL
vlib_main_t * vm
Definition: buffer.c:294
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:336
Feature path enable/disable request.
Definition: feature.api:30
static clib_error_t * feature_api_hookup(vlib_main_t *vm)
Definition: feature_api.c:103
unsigned int u32
Definition: types.h:88
#define clib_error_report(e)
Definition: error.h:113
unsigned char u8
Definition: types.h:56
api_main_t api_main
Definition: api_shared.c:35
int vnet_feature_enable_disable(const char *arc_name, const char *node_name, u32 sw_if_index, int enable_disable, void *feature_config, u32 n_feature_config_bytes)
Definition: feature.c:233
#define VALIDATE_SW_IF_INDEX(mp)
struct _vnet_feature_registration vnet_feature_registration_t
feature registration object