/* * Copyright (c) 2016 Cisco and/or its affiliates. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include cop_main_t cop_main; static clib_error_t * cop_sw_interface_add_del (vnet_main_t * vnm, u32 sw_if_index, u32 is_add) { cop_main_t * cm = &cop_main; cop_config_data_t _data, *data = &_data; vlib_main_t * vm = cm->vlib_main; vnet_hw_interface_t * hi = vnet_get_sup_hw_interface (vnm, sw_if_index);; cop_config_main_t * ccm; int address_family; u32 ci, default_next; memset (data, 0, sizeof(*data)); /* * Ignore local interface, pg interfaces. $$$ need a #define for the * first "real" interface. The answer is 5 at the moment. */ if (hi->dev_class_index == vnet_local_interface_device_class.index) return 0; for (address_family = VNET_COP_IP4; address_family < VNET_N_COPS; address_family++) { ccm = &cm->cop_config_mains[address_family]; /* * Once-only code to initialize the per-address-family * cop feature subgraphs. * Since the (single) start-node, cop-input, must be able * to push pkts into three separate subgraphs, we * use a unified cop_feature_type_t enumeration. */ if (!(ccm->config_main.node_index_by_feature_index)) { switch (address_family) { case VNET_COP_IP4: { static char * start_nodes[] = { "cop-input" }; static char * feature_nodes[] = { [IP4_RX_COP_WHITELIST] = "ip4-cop-whitelist", [IP4_RX_COP_INPUT] = "ip4-input", }; vnet_config_init (vm, &ccm->config_main, start_nodes, ARRAY_LEN(start_nodes), feature_nodes, ARRAY_LEN(feature_nodes)); } break; case VNET_COP_IP6: { static char * start_nodes[] = { "cop-input" }; static char * feature_nodes[] = { [IP6_RX_COP_WHITELIST] = "ip6-cop-whitelist", [IP6_RX_COP_INPUT] = "ip6-input", }; vnet_config_init (vm, &ccm->config_main, start_nodes, ARRAY_LEN(start_nodes), feature_nodes, ARRAY_LEN(feature_nodes)); } break; case VNET_COP_DEFAULT: { static char * start_nodes[] = { "cop-input" }; static char * feature_nodes[] = { [DEFAULT_RX_COP_WHITELIST] = "default-cop-whitelist", [DEFAULT_RX_COP_INPUT] = "ethernet-input", }; vnet_config_init (vm, &ccm->config_main, start_nodes, ARRAY_LEN(start_nodes), feature_nodes, ARRAY_LEN(feature_nodes)); } break; default: clib_warning ("bug"); break; } } vec_validate_init_empty (ccm->config_index_by_sw_if_index, sw_if_index, ~0); ci = ccm->config_index_by_sw_if_index[sw_if_index]; /* Create a sensible initial config: send pkts to xxx-input */ if (address_family == VNET_COP_IP4) default_next = IP4_RX_COP_INPUT; else if (address_family == VNET_COP_IP6) default_next = IP6_RX_COP_INPUT; else default_next = DEFAULT_RX_COP_INPUT; if (is_add) ci = vnet_config_add_feature (vm, &ccm->config_main, ci, default_next, data, sizeof(*data)); else ci = vnet_config_del_feature (vm, &ccm->config_main, ci, default_next, data, sizeof(*data)); ccm->config_index_by_sw_if_index[sw_if_index] = ci; } return 0; } VNET_SW_INTERFACE_ADD_DEL_FUNCTION (cop_sw_interface_add_del); static clib_error_t * cop_init (vlib_main_t *vm) { cop_main_t * cm = &cop_main; clib_error_t * error; if ((error = vlib_call_init_function (vm, ip4_whitelist_init))) return error; if ((error = vlib_call_init_function (vm, ip6_whitelist_init))) return error; cm->vlib_m