FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
ipfixcollector.c
Go to the documentation of this file.
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>
20 
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
40 {
42  uword *p = NULL;
43  int i;
44  ipfix_client *client = 0;
45 
46  if ((!info) || (!info->client_name))
48 
49  p = hash_get (cm->client_reg_table, info->ipfix_setid);
50  client = p ? pool_elt_at_index (cm->client_reg_pool, (*p)) : NULL;
51 
52  if (info->del)
53  {
54  if (!client)
55  return 0; //There is no registered handler, so send success
56 
57  hash_unset (cm->client_reg_table, info->ipfix_setid);
58  vec_free (client->client_name);
59  pool_put (cm->client_reg_pool, client);
60  return 0;
61  }
62 
63  if (client)
65 
66  pool_get (cm->client_reg_pool, client);
67  i = client - cm->client_reg_pool;
68  client->client_name = vec_dup (info->client_name);
69  client->client_node = info->client_node;
72  client->client_node);
73  client->set_id = info->ipfix_setid;
74 
75  hash_set (cm->client_reg_table, info->ipfix_setid, i);
76 
77  if (!udp_is_valid_dst_port (UDP_DST_PORT_ipfix, 1))
78  udp_register_dst_port (vm, UDP_DST_PORT_ipfix,
79  ipfix_collector_node.index, 1);
80 
81  return 0;
82 }
83 
84 static clib_error_t *
86 {
87  clib_error_t *error = 0;
89 
90  cm->vlib_main = vm;
91  cm->vnet_main = vnet_get_main ();
92 
93  cm->client_reg_pool = NULL;
94  cm->client_reg_table = hash_create (0, sizeof (uword));
95 
96  return error;
97 }
98 
100 
101 /*
102  * fd.io coding-style-patch-verification: ON
103  *
104  * Local Variables:
105  * eval: (c-set-style "gnu")
106  * End:
107  */
vlib_node_add_next
static uword vlib_node_add_next(vlib_main_t *vm, uword node, uword next_node)
Definition: node_funcs.h:1177
ipfix_collector_node
vlib_node_registration_t ipfix_collector_node
(constructor) VLIB_REGISTER_NODE (ipfix_collector_node)
Definition: node.c:275
pool_elt_at_index
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:553
pool_put
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:305
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
ipfix_client_add_del_t
Structure other nodes to use for registering with IP-FIX collector.
Definition: ipfixcollector.h:30
ipfix_client::client_name
u8 * client_name
String containing name of the client interested in getting ip-fix packets.
Definition: ipfixcollector.h:53
ipfix_client_add_del_t::client_node
u32 client_node
Node index where packets have to be redirected.
Definition: ipfixcollector.h:37
hash_create
#define hash_create(elts, value_bytes)
Definition: hash.h:695
IPFIX_COLLECTOR_ERR_REG_EXISTS
#define IPFIX_COLLECTOR_ERR_REG_EXISTS
Definition: ipfixcollector.h:26
error
Definition: cJSON.c:88
ipfixcollector.h
ipfix_client_add_del_t::client_name
u8 * client_name
String containing name of the client interested in getting ip-fix packets.
Definition: ipfixcollector.h:34
hash_set
#define hash_set(h, key, value)
Definition: hash.h:255
ipfix_client::set_id
u16 set_id
Setid of IPFix for which client is interested in getting packets.
Definition: ipfixcollector.h:62
ipfix_collector_main_t
IP-FIX collector main structure to SetID to client node ID mapping.
Definition: ipfixcollector.h:68
vec_dup
#define vec_dup(V)
Return copy of vector (no header, no alignment)
Definition: vec.h:444
vnet_get_main
vnet_main_t * vnet_get_main(void)
Definition: pnat_test_stubs.h:56
udp_local.h
ipfix_client::client_next_node
u32 client_next_node
ipfix-collector next index where packets have to be redirected.
Definition: ipfixcollector.h:59
uword
u64 uword
Definition: types.h:112
hash_get
#define hash_get(h, key)
Definition: hash.h:249
udp_register_dst_port
void udp_register_dst_port(vlib_main_t *vm, udp_dst_port_t dst_port, u32 node_index, u8 is_ip4)
Definition: udp_local.c:468
i
sll srl srl sll sra u16x4 i
Definition: vector_sse42.h:261
ipfix_client
IP-FIX collector internal client structure to store SetID to client node ID.
Definition: ipfixcollector.h:49
cm
vnet_feature_config_main_t * cm
Definition: nat44_ei_hairpinning.c:591
pool_get
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
Definition: pool.h:255
udp_is_valid_dst_port
u8 udp_is_valid_dst_port(udp_dst_port_t dst_port, u8 is_ip4)
Definition: udp_local.c:529
plugin.h
ipfix_collector_main
ipfix_collector_main_t ipfix_collector_main
Definition: ipfixcollector.c:21
vec_free
#define vec_free(V)
Free vector's memory (no header).
Definition: vec.h:395
ip.h
VLIB_INIT_FUNCTION
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:172
ipfix_client_add_del_t::del
u16 del
Add(0) or del(1) operation.
Definition: ipfixcollector.h:43
hash_unset
#define hash_unset(h, key)
Definition: hash.h:261
vlib_main_t
Definition: main.h:102
clib_error_t
Definition: clib_error.h:21
vlib_init_function_t
clib_error_t *() vlib_init_function_t(struct vlib_main_t *vm)
Definition: init.h:51
ipfix_client::client_node
u32 client_node
Node index where packets have to be redirected.
Definition: ipfixcollector.h:56
IPFIX_COLLECTOR_ERR_INVALID_PARAM
#define IPFIX_COLLECTOR_ERR_INVALID_PARAM
Definition: ipfixcollector.h:25
ipfix_client_add_del_t::ipfix_setid
u16 ipfix_setid
Setid of IPFix for which client is interested in getting packets.
Definition: ipfixcollector.h:40
ipfix_collector_init
static clib_error_t * ipfix_collector_init(vlib_main_t *vm)
Definition: ipfixcollector.c:85
ipfix_collector_reg_setid
int ipfix_collector_reg_setid(vlib_main_t *vm, ipfix_client_add_del_t *info)
IP-FIX SetID registration function.
Definition: ipfixcollector.c:39