blob: a8c74277788dedd4377587d64166eec9cb6123aa [file] [log] [blame]
Neale Rannsb8d44812017-11-10 06:53:54 -08001/*
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
Filip Tehlarbf8c54a2021-06-21 12:43:35 +000024#include <vnet/feature/feature.api_enum.h>
25#include <vnet/feature/feature.api_types.h>
Neale Rannsb8d44812017-11-10 06:53:54 -080026
Filip Tehlarbf8c54a2021-06-21 12:43:35 +000027#define REPLY_MSG_ID_BASE msg_id_base
Neale Rannsb8d44812017-11-10 06:53:54 -080028#include <vlibapi/api_helper_macros.h>
29
Filip Tehlarbf8c54a2021-06-21 12:43:35 +000030static u16 msg_id_base;
Neale Rannsb8d44812017-11-10 06:53:54 -080031
32static void
33vl_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
Filip Tehlarbf8c54a2021-06-21 12:43:35 +000077#include <vnet/feature/feature.api.c>
Neale Rannsb8d44812017-11-10 06:53:54 -080078
79static clib_error_t *
80feature_api_hookup (vlib_main_t * vm)
81{
Neale Rannsb8d44812017-11-10 06:53:54 -080082 /*
83 * Set up the (msg_name, crc, message-id) table
84 */
Filip Tehlarbf8c54a2021-06-21 12:43:35 +000085 msg_id_base = setup_message_id_table ();
Neale Rannsb8d44812017-11-10 06:53:54 -080086
87 return 0;
88}
89
90VLIB_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 */