Line data Source code
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 8 : 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 8 : int rv = 0; 37 : 38 8 : VALIDATE_SW_IF_INDEX (mp); 39 : 40 8 : u8 *arc_name = format (0, "%s%c", mp->arc_name, 0); 41 8 : u8 *feature_name = format (0, "%s%c", mp->feature_name, 0); 42 : 43 8 : vec_terminate_c_string (arc_name); 44 8 : vec_terminate_c_string (feature_name); 45 : 46 : vnet_feature_registration_t *reg = 47 8 : vnet_get_feature_reg ((const char *) arc_name, 48 : (const char *) feature_name); 49 8 : if (reg == 0) 50 0 : rv = VNET_API_ERROR_INVALID_VALUE; 51 : else 52 : { 53 8 : u32 sw_if_index = ntohl (mp->sw_if_index); 54 8 : clib_error_t *error = 0; 55 : 56 8 : if (reg->enable_disable_cb) 57 0 : error = reg->enable_disable_cb (sw_if_index, mp->enable); 58 8 : if (!error) 59 8 : vnet_feature_enable_disable ((const char *) arc_name, 60 : (const char *) feature_name, 61 8 : sw_if_index, mp->enable, 0, 0); 62 : else 63 : { 64 0 : clib_error_report (error); 65 0 : rv = VNET_API_ERROR_CANNOT_ENABLE_DISABLE_FEATURE; 66 : } 67 : } 68 : 69 8 : vec_free (feature_name); 70 8 : vec_free (arc_name); 71 : 72 8 : BAD_SW_IF_INDEX_LABEL; 73 : 74 8 : REPLY_MACRO (VL_API_FEATURE_ENABLE_DISABLE_REPLY); 75 : } 76 : 77 : #include <vnet/feature/feature.api.c> 78 : 79 : static clib_error_t * 80 559 : feature_api_hookup (vlib_main_t * vm) 81 : { 82 : /* 83 : * Set up the (msg_name, crc, message-id) table 84 : */ 85 559 : msg_id_base = setup_message_id_table (); 86 : 87 559 : return 0; 88 : } 89 : 90 17359 : 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 : */