Line data Source code
1 : /* 2 : * Copyright (c) 2017 Cisco and/or its affiliates. 3 : * Licensed under the Apache License, Version 2.0 (the "License"); 4 : * you may not use this file except in compliance with the License. 5 : * You may obtain a copy of the License at: 6 : * 7 : * http://www.apache.org/licenses/LICENSE-2.0 8 : * 9 : * Unless required by applicable law or agreed to in writing, software 10 : * distributed under the License is distributed on an "AS IS" BASIS, 11 : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 : * See the License for the specific language governing permissions and 13 : * limitations under the License. 14 : */ 15 : 16 : #include <vnet/ip/ip.h> 17 : #include <vnet/plugin/plugin.h> 18 : #include <vnet/udp/udp_local.h> 19 : #include <ioam/ipfixcollector/ipfixcollector.h> 20 : 21 : ipfix_collector_main_t ipfix_collector_main; 22 : 23 : /** 24 : * @brief IP-FIX SetID registration function. 25 : * 26 : * This function can be used by other VPP graph nodes to receive IP-FIX packets 27 : * with a particular setid. 28 : * 29 : * @param vm Vlib main of the graph node which is interested in 30 : * getting IP-Fix packet. 31 : * @param info Structure describing the client node which 32 : * is interested in getting the IP-Fix packets for 33 : * a SetID. 34 : * 35 : * @returns 0 on success. 36 : * @returns Error codes(<0) otherwise. 37 : */ 38 : int 39 0 : ipfix_collector_reg_setid (vlib_main_t * vm, ipfix_client_add_del_t * info) 40 : { 41 0 : ipfix_collector_main_t *cm = &ipfix_collector_main; 42 0 : uword *p = NULL; 43 : int i; 44 0 : ipfix_client *client = 0; 45 : 46 0 : if ((!info) || (!info->client_name)) 47 0 : return IPFIX_COLLECTOR_ERR_INVALID_PARAM; 48 : 49 0 : p = hash_get (cm->client_reg_table, info->ipfix_setid); 50 0 : client = p ? pool_elt_at_index (cm->client_reg_pool, (*p)) : NULL; 51 : 52 0 : if (info->del) 53 : { 54 0 : if (!client) 55 0 : return 0; //There is no registered handler, so send success 56 : 57 0 : hash_unset (cm->client_reg_table, info->ipfix_setid); 58 0 : vec_free (client->client_name); 59 0 : pool_put (cm->client_reg_pool, client); 60 0 : return 0; 61 : } 62 : 63 0 : if (client) 64 0 : return IPFIX_COLLECTOR_ERR_REG_EXISTS; 65 : 66 0 : pool_get (cm->client_reg_pool, client); 67 0 : i = client - cm->client_reg_pool; 68 0 : client->client_name = vec_dup (info->client_name); 69 0 : client->client_node = info->client_node; 70 0 : client->client_next_node = vlib_node_add_next (vm, 71 0 : ipfix_collector_node.index, 72 0 : client->client_node); 73 0 : client->set_id = info->ipfix_setid; 74 : 75 0 : hash_set (cm->client_reg_table, info->ipfix_setid, i); 76 : 77 0 : if (!udp_is_valid_dst_port (UDP_DST_PORT_ipfix, 1)) 78 0 : udp_register_dst_port (vm, UDP_DST_PORT_ipfix, 79 : ipfix_collector_node.index, 1); 80 : 81 0 : return 0; 82 : } 83 : 84 : static clib_error_t * 85 559 : ipfix_collector_init (vlib_main_t * vm) 86 : { 87 559 : clib_error_t *error = 0; 88 559 : ipfix_collector_main_t *cm = &ipfix_collector_main; 89 : 90 559 : cm->vlib_main = vm; 91 559 : cm->vnet_main = vnet_get_main (); 92 : 93 559 : cm->client_reg_pool = NULL; 94 559 : cm->client_reg_table = hash_create (0, sizeof (uword)); 95 : 96 559 : return error; 97 : } 98 : 99 5599 : VLIB_INIT_FUNCTION (ipfix_collector_init); 100 : 101 : /* 102 : * fd.io coding-style-patch-verification: ON 103 : * 104 : * Local Variables: 105 : * eval: (c-set-style "gnu") 106 : * End: 107 : */