FD.io VPP  v21.10.1-2-g0a485f517
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/feature/feature.api_enum.h>
25 #include <vnet/feature/feature.api_types.h>
26 
27 #define REPLY_MSG_ID_BASE msg_id_base
29 
31 
32 static void
34 {
35  vl_api_feature_enable_disable_reply_t *rmp;
36  int rv = 0;
37 
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 
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  {
65  rv = VNET_API_ERROR_CANNOT_ENABLE_DISABLE_FEATURE;
66  }
67  }
68 
69  vec_free (feature_name);
70  vec_free (arc_name);
71 
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 *
81 {
82  /*
83  * Set up the (msg_name, crc, message-id) table
84  */
86 
87  return 0;
88 }
89 
91 
92 /*
93  * fd.io coding-style-patch-verification: ON
94  *
95  * Local Variables:
96  * eval: (c-set-style "gnu")
97  * End:
98  */
VLIB_API_INIT_FUNCTION
VLIB_API_INIT_FUNCTION(feature_api_hookup)
VALIDATE_SW_IF_INDEX
#define VALIDATE_SW_IF_INDEX(mp)
Definition: api_helper_macros.h:281
api.h
vl_api_feature_enable_disable_t::enable
bool enable
Definition: feature.api:36
vnet_get_feature_reg
vnet_feature_registration_t * vnet_get_feature_reg(const char *arc_name, const char *node_name)
Definition: feature.c:212
u16
unsigned short u16
Definition: types.h:57
msg_id_base
static u16 msg_id_base
Definition: feature_api.c:30
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
vnet_feature_registration_t
struct _vnet_feature_registration vnet_feature_registration_t
feature registration object
clib_error_report
#define clib_error_report(e)
Definition: error.h:113
error
Definition: cJSON.c:88
feature.h
REPLY_MACRO
#define REPLY_MACRO(t)
Definition: api_helper_macros.h:30
setup_message_id_table
static void setup_message_id_table(api_main_t *am)
Definition: sr_mpls_api.c:174
vl_api_feature_enable_disable_t::sw_if_index
vl_api_interface_index_t sw_if_index
Definition: feature.api:35
BAD_SW_IF_INDEX_LABEL
#define BAD_SW_IF_INDEX_LABEL
Definition: api_helper_macros.h:289
vl_api_feature_enable_disable_t_handler
static void vl_api_feature_enable_disable_t_handler(vl_api_feature_enable_disable_t *mp)
Definition: feature_api.c:33
vec_free
#define vec_free(V)
Free vector's memory (no header).
Definition: vec.h:395
format
description fragment has unexpected format
Definition: map.api:433
u32
unsigned int u32
Definition: types.h:88
vl_api_feature_enable_disable_t
Feature path enable/disable request.
Definition: feature.api:32
vl_api_feature_enable_disable_t::arc_name
string arc_name[64]
Definition: feature.api:37
api_helper_macros.h
vnet_feature_enable_disable
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: pnat_test_stubs.h:50
vlib_main_t
Definition: main.h:102
u8
unsigned char u8
Definition: types.h:56
clib_error_t
Definition: clib_error.h:21
vl_api_feature_enable_disable_t::feature_name
string feature_name[64]
Definition: feature.api:38
vec_terminate_c_string
#define vec_terminate_c_string(V)
(If necessary) NULL terminate a vector containing a c-string.
Definition: vec.h:1132
rv
int __clib_unused rv
Definition: application.c:491
vnet.h
sw_if_index
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:34
feature_api_hookup
static clib_error_t * feature_api_hookup(vlib_main_t *vm)
Definition: feature_api.c:80