blob: aedfcad855e055e98e08d9e63a6a21566ef0f1f3 [file] [log] [blame]
Alexander Popovsky (apopovsk)4a7e58b2016-10-05 22:31:23 -07001/*
2 * Copyright (c) 2016 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/**
17 * @file
18 * @brief Local TCP/IP stack punt infrastructure.
19 *
Ole Troanf7a55ad2017-05-16 14:59:29 +020020 * Provides a set of VPP nodes together with the relevant APIs and CLI
Alexander Popovsky (apopovsk)4a7e58b2016-10-05 22:31:23 -070021 * commands in order to adjust and dispatch packets from the VPP data plane
22 * to the local TCP/IP stack
23 */
Ole Troanf7a55ad2017-05-16 14:59:29 +020024
25#include <vnet/ip/ip.h>
Alexander Popovsky (apopovsk)4a7e58b2016-10-05 22:31:23 -070026#include <vlib/vlib.h>
Dave Barach68b0fb02017-02-28 15:15:56 -050027#include <vnet/udp/udp.h>
Pierre Pfister7fe51f32017-09-20 08:48:36 +020028#include <vnet/tcp/tcp.h>
Alexander Popovsky (apopovsk)4a7e58b2016-10-05 22:31:23 -070029#include <vnet/ip/punt.h>
Ole Troanf7a55ad2017-05-16 14:59:29 +020030#include <vlib/unix/unix.h>
Alexander Popovsky (apopovsk)4a7e58b2016-10-05 22:31:23 -070031
Ole Troanf7a55ad2017-05-16 14:59:29 +020032#include <stdio.h>
33#include <unistd.h>
34#include <sys/socket.h>
Marco Varlese22349832017-09-08 10:40:34 +020035#include <sys/uio.h>
Ole Troanf7a55ad2017-05-16 14:59:29 +020036#include <stdlib.h>
Ole Troanf7a55ad2017-05-16 14:59:29 +020037
Ole Troanf7a55ad2017-05-16 14:59:29 +020038punt_main_t punt_main;
39
40char *
41vnet_punt_get_server_pathname (void)
42{
43 punt_main_t *pm = &punt_main;
44 return pm->sun_path;
45}
Alexander Popovsky (apopovsk)4a7e58b2016-10-05 22:31:23 -070046
Ole Troanf7a55ad2017-05-16 14:59:29 +020047static void
Neale Ranns50f0ac02019-05-15 02:13:37 -070048punt_client_l4_db_add (ip_address_family_t af, u16 port, u32 index)
Ole Troanf7a55ad2017-05-16 14:59:29 +020049{
50 punt_main_t *pm = &punt_main;
Ole Troanf7a55ad2017-05-16 14:59:29 +020051
Neale Ranns50f0ac02019-05-15 02:13:37 -070052 pm->db.clients_by_l4_port = hash_set (pm->db.clients_by_l4_port,
53 punt_client_l4_mk_key (af, port),
54 index);
Ole Troanf7a55ad2017-05-16 14:59:29 +020055}
56
Neale Ranns50f0ac02019-05-15 02:13:37 -070057static u32
58punt_client_l4_db_remove (ip_address_family_t af, u16 port)
Ole Troanf7a55ad2017-05-16 14:59:29 +020059{
Neale Ranns50f0ac02019-05-15 02:13:37 -070060 punt_main_t *pm = &punt_main;
61 u32 key, index = ~0;
62 uword *p;
63
64 key = punt_client_l4_mk_key (af, port);
65 p = hash_get (pm->db.clients_by_l4_port, key);
66
67 if (p)
68 index = p[0];
69
70 hash_unset (pm->db.clients_by_l4_port, key);
71
72 return (index);
73}
74
75static void
Neale Rannsb538dd82019-05-21 06:54:54 -070076punt_client_ip_proto_db_add (ip_address_family_t af,
77 ip_protocol_t proto, u32 index)
78{
79 punt_main_t *pm = &punt_main;
80
81 pm->db.clients_by_ip_proto = hash_set (pm->db.clients_by_ip_proto,
82 punt_client_ip_proto_mk_key (af,
83 proto),
84 index);
85}
86
87static u32
88punt_client_ip_proto_db_remove (ip_address_family_t af, ip_protocol_t proto)
89{
90 punt_main_t *pm = &punt_main;
91 u32 key, index = ~0;
92 uword *p;
93
94 key = punt_client_ip_proto_mk_key (af, proto);
95 p = hash_get (pm->db.clients_by_ip_proto, key);
96
97 if (p)
98 index = p[0];
99
100 hash_unset (pm->db.clients_by_ip_proto, key);
101
102 return (index);
103}
104
105static void
Neale Ranns50f0ac02019-05-15 02:13:37 -0700106punt_client_exception_db_add (vlib_punt_reason_t reason, u32 pci)
107{
108 punt_main_t *pm = &punt_main;
109
110 vec_validate_init_empty (pm->db.clients_by_exception, reason, ~0);
111
112 pm->db.clients_by_exception[reason] = pci;
113}
114
115static u32
116punt_client_exception_db_remove (vlib_punt_reason_t reason)
117{
118 punt_main_t *pm = &punt_main;
119 u32 pci = ~0;
120
121 if (punt_client_exception_get (reason))
122 {
123 pci = pm->db.clients_by_exception[reason];
124 pm->db.clients_by_exception[reason] = ~0;
125 }
126
127 return pci;
128}
Ole Troanf7a55ad2017-05-16 14:59:29 +0200129
130static clib_error_t *
Damjan Marion56dd5432017-09-08 19:52:02 +0200131punt_socket_read_ready (clib_file_t * uf)
Ole Troanf7a55ad2017-05-16 14:59:29 +0200132{
133 vlib_main_t *vm = vlib_get_main ();
134 punt_main_t *pm = &punt_main;
135
136 /** Schedule the rx node */
137 vlib_node_set_interrupt_pending (vm, punt_socket_rx_node.index);
138 vec_add1 (pm->ready_fds, uf->file_descriptor);
139
140 return 0;
141}
142
Neale Ranns50f0ac02019-05-15 02:13:37 -0700143static clib_error_t *
144punt_socket_register_l4 (vlib_main_t * vm,
145 ip_address_family_t af,
146 u8 protocol, u16 port, char *client_pathname)
Ole Troanf7a55ad2017-05-16 14:59:29 +0200147{
148 punt_main_t *pm = &punt_main;
Neale Ranns50f0ac02019-05-15 02:13:37 -0700149 punt_client_t *c;
Ole Troanf7a55ad2017-05-16 14:59:29 +0200150
Ole Troanf7a55ad2017-05-16 14:59:29 +0200151 if (port == (u16) ~ 0)
Ole Troan56b8abc2023-09-05 08:27:53 +0200152 return clib_error_return (0, "Port number required");
153
154 u32 node_index;
155 switch (protocol)
156 {
157 case IP_PROTOCOL_UDP:
158 node_index = (af == AF_IP4 ? udp4_punt_socket_node.index :
159 udp6_punt_socket_node.index);
160 udp_register_dst_port (vm, port, node_index, af == AF_IP4);
161 break;
162 case IP_PROTOCOL_ICMP6:
163 if (af != AF_IP6)
164 return clib_error_return (
165 0, "only UDP or ICMP6 protocol (%d, %d) is supported, got %d",
166 IP_PROTOCOL_UDP, IP_PROTOCOL_ICMP6, protocol);
167
168 node_index = icmp6_punt_socket_node.index;
169 icmp6_register_type (vm, port, node_index);
170 break;
171 default:
172 return clib_error_return (
173 0, "only UDP or ICMP6 protocol (%d) is supported, got %d",
174 IP_PROTOCOL_UDP, protocol);
175 }
Ole Troanf7a55ad2017-05-16 14:59:29 +0200176
Neale Ranns50f0ac02019-05-15 02:13:37 -0700177 c = punt_client_l4_get (af, port);
Ole Troanf7a55ad2017-05-16 14:59:29 +0200178
Neale Ranns50f0ac02019-05-15 02:13:37 -0700179 if (NULL == c)
180 {
181 pool_get_zero (pm->punt_client_pool, c);
182 punt_client_l4_db_add (af, port, c - pm->punt_client_pool);
183 }
Ole Troanf7a55ad2017-05-16 14:59:29 +0200184
BenoƮt Ganneedb0d452021-10-12 10:14:30 +0200185 snprintf (c->caddr.sun_path, sizeof (c->caddr.sun_path), "%s",
186 client_pathname);
Neale Ranns50f0ac02019-05-15 02:13:37 -0700187 c->caddr.sun_family = AF_UNIX;
188 c->reg.type = PUNT_TYPE_L4;
189 c->reg.punt.l4.port = port;
190 c->reg.punt.l4.protocol = protocol;
191 c->reg.punt.l4.af = af;
192
Neale Ranns50f0ac02019-05-15 02:13:37 -0700193 return (NULL);
194}
195
196static clib_error_t *
Neale Rannsb538dd82019-05-21 06:54:54 -0700197punt_socket_register_ip_proto (vlib_main_t * vm,
198 ip_address_family_t af,
199 ip_protocol_t proto, char *client_pathname)
200{
201 punt_main_t *pm = &punt_main;
202 punt_client_t *c;
203
204 c = punt_client_ip_proto_get (af, proto);
205
206 if (NULL == c)
207 {
208 pool_get_zero (pm->punt_client_pool, c);
209 punt_client_ip_proto_db_add (af, proto, c - pm->punt_client_pool);
210 }
211
BenoƮt Ganneedb0d452021-10-12 10:14:30 +0200212 snprintf (c->caddr.sun_path, sizeof (c->caddr.sun_path), "%s",
213 client_pathname);
Neale Rannsb538dd82019-05-21 06:54:54 -0700214 c->caddr.sun_family = AF_UNIX;
215 c->reg.type = PUNT_TYPE_IP_PROTO;
216 c->reg.punt.ip_proto.protocol = proto;
217 c->reg.punt.ip_proto.af = af;
218
219 if (af == AF_IP4)
220 ip4_register_protocol (proto, ip4_proto_punt_socket_node.index);
221 else
222 ip6_register_protocol (proto, ip6_proto_punt_socket_node.index);
223
224 return (NULL);
225}
226
227static clib_error_t *
Neale Ranns50f0ac02019-05-15 02:13:37 -0700228punt_socket_register_exception (vlib_main_t * vm,
229 vlib_punt_reason_t reason,
230 char *client_pathname)
231{
232 punt_main_t *pm = &punt_main;
233 punt_client_t *pc;
234
235 pc = punt_client_exception_get (reason);
236
237 if (NULL == pc)
238 {
239 pool_get_zero (pm->punt_client_pool, pc);
240 punt_client_exception_db_add (reason, pc - pm->punt_client_pool);
241 }
242
BenoƮt Ganneedb0d452021-10-12 10:14:30 +0200243 snprintf (pc->caddr.sun_path, sizeof (pc->caddr.sun_path), "%s",
244 client_pathname);
Neale Ranns50f0ac02019-05-15 02:13:37 -0700245 pc->caddr.sun_family = AF_UNIX;
246 pc->reg.type = PUNT_TYPE_EXCEPTION;
247 pc->reg.punt.exception.reason = reason;
248
249 vlib_punt_register (pm->hdl,
250 pc->reg.punt.exception.reason, "exception-punt-socket");
251
252 return (NULL);
253}
254
255static clib_error_t *
256punt_socket_unregister_l4 (ip_address_family_t af,
257 ip_protocol_t protocol, u16 port)
258{
259 u32 pci;
260
261 udp_unregister_dst_port (vlib_get_main (), port, af == AF_IP4);
262
263 pci = punt_client_l4_db_remove (af, port);
264
265 if (~0 != pci)
266 pool_put_index (punt_main.punt_client_pool, pci);
267
268 return (NULL);
269}
270
271static clib_error_t *
Neale Rannsb538dd82019-05-21 06:54:54 -0700272punt_socket_unregister_ip_proto (ip_address_family_t af, ip_protocol_t proto)
273{
274 u32 pci;
275
276 if (af == AF_IP4)
277 ip4_unregister_protocol (proto);
278 else
279 ip6_unregister_protocol (proto);
280
281 pci = punt_client_ip_proto_db_remove (af, proto);
282
283 if (~0 != pci)
284 pool_put_index (punt_main.punt_client_pool, pci);
285
286 return (NULL);
287}
288
289static clib_error_t *
Neale Ranns50f0ac02019-05-15 02:13:37 -0700290punt_socket_unregister_exception (vlib_punt_reason_t reason)
291{
292 u32 pci;
293
294 pci = punt_client_exception_db_remove (reason);
295
296 if (~0 != pci)
297 pool_put_index (punt_main.punt_client_pool, pci);
298
299 return (NULL);
Ole Troanf7a55ad2017-05-16 14:59:29 +0200300}
301
302clib_error_t *
Neale Ranns50f0ac02019-05-15 02:13:37 -0700303vnet_punt_socket_add (vlib_main_t * vm, u32 header_version,
304 const punt_reg_t * pr, char *client_pathname)
Ole Troanf7a55ad2017-05-16 14:59:29 +0200305{
306 punt_main_t *pm = &punt_main;
307
308 if (!pm->is_configured)
309 return clib_error_return (0, "socket is not configured");
310
Neale Ranns50f0ac02019-05-15 02:13:37 -0700311 if (header_version != PUNT_PACKETDESC_VERSION)
312 return clib_error_return (0, "Invalid packet descriptor version");
313
Neale Rannsb538dd82019-05-21 06:54:54 -0700314 if (strncmp (client_pathname, vnet_punt_get_server_pathname (),
315 UNIX_PATH_MAX) == 0)
316 return clib_error_return (0,
317 "Punt socket: Invalid client path: %s",
318 client_pathname);
319
Neale Ranns50f0ac02019-05-15 02:13:37 -0700320 /* Register client */
321 switch (pr->type)
322 {
323 case PUNT_TYPE_L4:
324 return (punt_socket_register_l4 (vm,
325 pr->punt.l4.af,
326 pr->punt.l4.protocol,
327 pr->punt.l4.port, client_pathname));
Neale Rannsb538dd82019-05-21 06:54:54 -0700328 case PUNT_TYPE_IP_PROTO:
329 return (punt_socket_register_ip_proto (vm,
330 pr->punt.ip_proto.af,
331 pr->punt.ip_proto.protocol,
332 client_pathname));
Neale Ranns50f0ac02019-05-15 02:13:37 -0700333 case PUNT_TYPE_EXCEPTION:
334 return (punt_socket_register_exception (vm,
335 pr->punt.exception.reason,
336 client_pathname));
337 }
338
339 return 0;
340}
341
342clib_error_t *
343vnet_punt_socket_del (vlib_main_t * vm, const punt_reg_t * pr)
344{
345 punt_main_t *pm = &punt_main;
346
347 if (!pm->is_configured)
348 return clib_error_return (0, "socket is not configured");
349
350 switch (pr->type)
351 {
352 case PUNT_TYPE_L4:
353 return (punt_socket_unregister_l4 (pr->punt.l4.af,
354 pr->punt.l4.protocol,
355 pr->punt.l4.port));
Neale Rannsb538dd82019-05-21 06:54:54 -0700356 case PUNT_TYPE_IP_PROTO:
357 return (punt_socket_unregister_ip_proto (pr->punt.ip_proto.af,
358 pr->punt.ip_proto.protocol));
Neale Ranns50f0ac02019-05-15 02:13:37 -0700359 case PUNT_TYPE_EXCEPTION:
360 return (punt_socket_unregister_exception (pr->punt.exception.reason));
361 }
Ole Troanf7a55ad2017-05-16 14:59:29 +0200362
363 return 0;
364}
365
Alexander Popovsky (apopovsk)4a7e58b2016-10-05 22:31:23 -0700366/**
Paul Vinciguerra32c4d382019-10-23 16:07:32 -0400367 * @brief Request IP L4 traffic punt to the local TCP/IP stack.
Alexander Popovsky (apopovsk)4a7e58b2016-10-05 22:31:23 -0700368 *
369 * @em Note
Paul Vinciguerra32c4d382019-10-23 16:07:32 -0400370 * - UDP is the only protocol supported in the current implementation
Alexander Popovsky (apopovsk)4a7e58b2016-10-05 22:31:23 -0700371 *
372 * @param vm vlib_main_t corresponding to the current thread
Neale Ranns50f0ac02019-05-15 02:13:37 -0700373 * @param af IP address family.
Alexander Popovsky (apopovsk)4a7e58b2016-10-05 22:31:23 -0700374 * @param protocol 8-bits L4 protocol value
Pierre Pfister7fe51f32017-09-20 08:48:36 +0200375 * UDP is 17
376 * TCP is 1
377 * @param port 16-bits L4 (TCP/IP) port number when applicable (UDP only)
Alexander Popovsky (apopovsk)4a7e58b2016-10-05 22:31:23 -0700378 *
379 * @returns 0 on success, non-zero value otherwise
380 */
Neale Ranns50f0ac02019-05-15 02:13:37 -0700381static clib_error_t *
382punt_l4_add_del (vlib_main_t * vm,
383 ip_address_family_t af,
384 ip_protocol_t protocol, u16 port, bool is_add)
Alexander Popovsky (apopovsk)4a7e58b2016-10-05 22:31:23 -0700385{
BenoƮt Ganne7c7b5052021-10-04 12:03:20 +0200386 int is_ip4 = af == AF_IP4;
387
Florin Coras3ffe6ca2019-06-26 16:27:13 -0700388 /* For now we only support TCP and UDP punt */
389 if (protocol != IP_PROTOCOL_UDP && protocol != IP_PROTOCOL_TCP)
Alexander Popovsky (apopovsk)740bcdb2016-11-15 15:36:23 -0800390 return clib_error_return (0,
Florin Coras3ffe6ca2019-06-26 16:27:13 -0700391 "only UDP (%d) and TCP (%d) protocols are supported, got %d",
392 IP_PROTOCOL_UDP, IP_PROTOCOL_TCP, protocol);
Alexander Popovsky (apopovsk)4a7e58b2016-10-05 22:31:23 -0700393
Alexander Popovsky (apopovsk)740bcdb2016-11-15 15:36:23 -0800394 if (port == (u16) ~ 0)
Alexander Popovsky (apopovsk)4a7e58b2016-10-05 22:31:23 -0700395 {
Neale Ranns50f0ac02019-05-15 02:13:37 -0700396 if (protocol == IP_PROTOCOL_UDP)
BenoƮt Ganne7c7b5052021-10-04 12:03:20 +0200397 udp_punt_unknown (vm, is_ip4, is_add);
Neale Ranns50f0ac02019-05-15 02:13:37 -0700398 else if (protocol == IP_PROTOCOL_TCP)
BenoƮt Ganne7c7b5052021-10-04 12:03:20 +0200399 tcp_punt_unknown (vm, is_ip4, is_add);
Alexander Popovsky (apopovsk)740bcdb2016-11-15 15:36:23 -0800400
401 return 0;
402 }
403
404 else if (is_add)
405 {
BenoƮt Ganne7c7b5052021-10-04 12:03:20 +0200406 const vlib_node_registration_t *punt_node =
407 is_ip4 ? &udp4_punt_node : &udp6_punt_node;
408
Florin Coras3ffe6ca2019-06-26 16:27:13 -0700409 if (protocol == IP_PROTOCOL_TCP)
410 return clib_error_return (0, "punt TCP ports is not supported yet");
Pierre Pfister7fe51f32017-09-20 08:48:36 +0200411
BenoƮt Ganne7c7b5052021-10-04 12:03:20 +0200412 udp_register_dst_port (vm, port, punt_node->index, is_ip4);
Alexander Popovsky (apopovsk)740bcdb2016-11-15 15:36:23 -0800413
414 return 0;
Alexander Popovsky (apopovsk)4a7e58b2016-10-05 22:31:23 -0700415 }
416 else
Pavel Kotucek41b923a2018-12-05 17:16:23 +0100417 {
Florin Coras3ffe6ca2019-06-26 16:27:13 -0700418 if (protocol == IP_PROTOCOL_TCP)
419 return clib_error_return (0, "punt TCP ports is not supported yet");
Pavel Kotucek41b923a2018-12-05 17:16:23 +0100420
BenoƮt Ganne7c7b5052021-10-04 12:03:20 +0200421 udp_unregister_dst_port (vm, port, is_ip4);
Pavel Kotucek41b923a2018-12-05 17:16:23 +0100422
423 return 0;
424 }
Alexander Popovsky (apopovsk)4a7e58b2016-10-05 22:31:23 -0700425}
Neale Ranns50f0ac02019-05-15 02:13:37 -0700426
Mohammed Hawari45723b82021-02-05 15:40:00 +0100427/**
428 * @brief Request exception traffic punt.
429 *
430 * @param reason Punting reason
431 *
432 * @returns 0 on success, non-zero value otherwise
433 */
434static clib_error_t *
435punt_exception_add_del (vlib_punt_reason_t reason, bool is_add)
436{
437 punt_main_t *pm = &punt_main;
438 int rv = 0;
439 vnet_punt_reason_flag_t flag = vlib_punt_reason_get_flags (reason);
440 const char *node_name =
441 vnet_punt_reason_flag_is_IP6_PACKET (flag) ? "ip6-punt" : "ip4-punt";
442 if (is_add)
443 rv = vlib_punt_register (pm->hdl, reason, node_name);
444 else
445 rv = vlib_punt_unregister (pm->hdl, reason, node_name);
446 if (!rv)
447 return 0;
448 else
449 return clib_error_return (0, is_add ? "Existing punting registration..." :
450 "Punting registration not found...");
451}
452
Neale Ranns50f0ac02019-05-15 02:13:37 -0700453clib_error_t *
454vnet_punt_add_del (vlib_main_t * vm, const punt_reg_t * pr, bool is_add)
455{
456 switch (pr->type)
457 {
458 case PUNT_TYPE_L4:
459 return (punt_l4_add_del (vm, pr->punt.l4.af, pr->punt.l4.protocol,
460 pr->punt.l4.port, is_add));
461 case PUNT_TYPE_EXCEPTION:
Mohammed Hawari45723b82021-02-05 15:40:00 +0100462 return punt_exception_add_del (pr->punt.exception.reason, is_add);
Neale Rannsb538dd82019-05-21 06:54:54 -0700463 case PUNT_TYPE_IP_PROTO:
464 break;
Neale Ranns50f0ac02019-05-15 02:13:37 -0700465 }
466
467 return (clib_error_return (0, "Unsupported punt type: %d", pr->type));
468}
Alexander Popovsky (apopovsk)4a7e58b2016-10-05 22:31:23 -0700469
470static clib_error_t *
Pierre Pfister7fe51f32017-09-20 08:48:36 +0200471punt_cli (vlib_main_t * vm,
BenoƮt Ganne9ae3c6a2020-07-27 18:27:57 +0200472 unformat_input_t * input__, vlib_cli_command_t * cmd)
Alexander Popovsky (apopovsk)4a7e58b2016-10-05 22:31:23 -0700473{
BenoƮt Ganne9ae3c6a2020-07-27 18:27:57 +0200474 unformat_input_t line_input, *input = &line_input;
Swarup Nayak1b708842017-12-13 13:27:23 +0530475 clib_error_t *error = NULL;
Neale Ranns50f0ac02019-05-15 02:13:37 -0700476 bool is_add = true;
Neale Ranns68577d22019-06-04 13:31:23 +0000477 /* *INDENT-OFF* */
Neale Ranns50f0ac02019-05-15 02:13:37 -0700478 punt_reg_t pr = {
479 .punt = {
Neale Ranns68577d22019-06-04 13:31:23 +0000480 .l4 = {
481 .af = AF_IP4,
482 .port = ~0,
Paul Vinciguerra32c4d382019-10-23 16:07:32 -0400483 .protocol = IP_PROTOCOL_UDP,
Neale Ranns68577d22019-06-04 13:31:23 +0000484 },
485 },
Neale Ranns50f0ac02019-05-15 02:13:37 -0700486 .type = PUNT_TYPE_L4,
487 };
Neale Ranns68577d22019-06-04 13:31:23 +0000488 u32 port;
489 /* *INDENT-ON* */
Alexander Popovsky (apopovsk)4a7e58b2016-10-05 22:31:23 -0700490
BenoƮt Ganne9ae3c6a2020-07-27 18:27:57 +0200491 if (!unformat_user (input__, unformat_line_input, input))
492 return 0;
493
Alexander Popovsky (apopovsk)4a7e58b2016-10-05 22:31:23 -0700494 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
495 {
496 if (unformat (input, "del"))
Ole Troanf7a55ad2017-05-16 14:59:29 +0200497 is_add = false;
Mohammed Hawari45723b82021-02-05 15:40:00 +0100498 else if (unformat (input, "reason %U", unformat_punt_reason,
499 &pr.punt.exception.reason))
500 pr.type = PUNT_TYPE_EXCEPTION;
Paul Vinciguerra32c4d382019-10-23 16:07:32 -0400501 else if (unformat (input, "ipv4"))
502 pr.punt.l4.af = AF_IP4;
Neale Ranns50f0ac02019-05-15 02:13:37 -0700503 else if (unformat (input, "ipv6"))
504 pr.punt.l4.af = AF_IP6;
505 else if (unformat (input, "ip6"))
506 pr.punt.l4.af = AF_IP6;
Neale Ranns68577d22019-06-04 13:31:23 +0000507 else if (unformat (input, "%d", &port))
508 pr.punt.l4.port = port;
Paul Vinciguerra32c4d382019-10-23 16:07:32 -0400509 else if (unformat (input, "all"))
510 pr.punt.l4.port = ~0;
Pierre Pfister7fe51f32017-09-20 08:48:36 +0200511 else if (unformat (input, "udp"))
Neale Ranns50f0ac02019-05-15 02:13:37 -0700512 pr.punt.l4.protocol = IP_PROTOCOL_UDP;
Pierre Pfister7fe51f32017-09-20 08:48:36 +0200513 else if (unformat (input, "tcp"))
Neale Ranns50f0ac02019-05-15 02:13:37 -0700514 pr.punt.l4.protocol = IP_PROTOCOL_TCP;
Swarup Nayak1b708842017-12-13 13:27:23 +0530515 else
516 {
517 error = clib_error_return (0, "parse error: '%U'",
518 format_unformat_error, input);
519 goto done;
520 }
Alexander Popovsky (apopovsk)4a7e58b2016-10-05 22:31:23 -0700521 }
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100522
523 /* punt both IPv6 and IPv4 when used in CLI */
Neale Ranns50f0ac02019-05-15 02:13:37 -0700524 error = vnet_punt_add_del (vm, &pr, is_add);
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100525 if (error)
526 {
527 clib_error_report (error);
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100528 }
529
Swarup Nayak1b708842017-12-13 13:27:23 +0530530done:
BenoƮt Ganne9ae3c6a2020-07-27 18:27:57 +0200531 unformat_free (input);
Swarup Nayak1b708842017-12-13 13:27:23 +0530532 return error;
Alexander Popovsky (apopovsk)4a7e58b2016-10-05 22:31:23 -0700533}
534
535/*?
536 * The set of '<em>set punt</em>' commands allows specific IP traffic to
537 * be punted to the host TCP/IP stack
538 *
539 * @em Note
540 * - UDP is the only protocol supported in the current implementation
Alexander Popovsky (apopovsk)4a7e58b2016-10-05 22:31:23 -0700541 * - All TCP traffic is currently punted to the host by default
542 *
543 * @cliexpar
544 * @parblock
545 * Example of how to request NTP traffic to be punted
546 * @cliexcmd{set punt udp 125}
547 *
Alexander Popovsky (apopovsk)740bcdb2016-11-15 15:36:23 -0800548 * Example of how to request all 'unknown' UDP traffic to be punted
549 * @cliexcmd{set punt udp all}
550 *
551 * Example of how to stop all 'unknown' UDP traffic to be punted
552 * @cliexcmd{set punt udp del all}
Alexander Popovsky (apopovsk)4a7e58b2016-10-05 22:31:23 -0700553 * @endparblock
554?*/
555/* *INDENT-OFF* */
Pierre Pfister7fe51f32017-09-20 08:48:36 +0200556VLIB_CLI_COMMAND (punt_command, static) = {
557 .path = "set punt",
Paul Vinciguerra32c4d382019-10-23 16:07:32 -0400558 .short_help = "set punt [IPV4|ip6|ipv6] [UDP|tcp] [del] [ALL|<port-num>]",
Pierre Pfister7fe51f32017-09-20 08:48:36 +0200559 .function = punt_cli,
Alexander Popovsky (apopovsk)4a7e58b2016-10-05 22:31:23 -0700560};
561/* *INDENT-ON* */
562
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100563static clib_error_t *
564punt_socket_register_cmd (vlib_main_t * vm,
BenoƮt Ganne9ae3c6a2020-07-27 18:27:57 +0200565 unformat_input_t * input__,
566 vlib_cli_command_t * cmd)
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100567{
BenoƮt Ganne9ae3c6a2020-07-27 18:27:57 +0200568 unformat_input_t line_input, *input = &line_input;
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100569 u8 *socket_name = 0;
570 clib_error_t *error = NULL;
Neale Ranns50f0ac02019-05-15 02:13:37 -0700571 /* *INDENT-OFF* */
572 punt_reg_t pr = {
573 .punt = {
574 .l4 = {
575 .af = AF_IP4,
576 .port = ~0,
Paul Vinciguerra32c4d382019-10-23 16:07:32 -0400577 .protocol = IP_PROTOCOL_UDP,
Neale Ranns50f0ac02019-05-15 02:13:37 -0700578 },
579 },
580 .type = PUNT_TYPE_L4,
581 };
582 /* *INDENT-ON* */
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100583
BenoƮt Ganne9ae3c6a2020-07-27 18:27:57 +0200584 if (!unformat_user (input__, unformat_line_input, input))
585 return 0;
586
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100587 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
588 {
589 if (unformat (input, "ipv4"))
Paul Vinciguerra32c4d382019-10-23 16:07:32 -0400590 pr.punt.l4.af = AF_IP4;
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100591 else if (unformat (input, "ipv6"))
Neale Ranns50f0ac02019-05-15 02:13:37 -0700592 pr.punt.l4.af = AF_IP6;
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100593 else if (unformat (input, "udp"))
Neale Ranns50f0ac02019-05-15 02:13:37 -0700594 pr.punt.l4.protocol = IP_PROTOCOL_UDP;
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100595 else if (unformat (input, "tcp"))
Neale Ranns50f0ac02019-05-15 02:13:37 -0700596 pr.punt.l4.protocol = IP_PROTOCOL_TCP;
597 else if (unformat (input, "%d", &pr.punt.l4.port))
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100598 ;
Paul Vinciguerra32c4d382019-10-23 16:07:32 -0400599 else if (unformat (input, "all"))
600 pr.punt.l4.port = ~0;
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100601 else if (unformat (input, "socket %s", &socket_name))
602 ;
Arthur de Kerhora80ff132021-04-12 08:16:56 -0700603 else if (unformat (input, "reason %U", unformat_punt_reason,
604 &pr.punt.exception.reason))
605 pr.type = PUNT_TYPE_EXCEPTION;
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100606 else
607 {
608 error = clib_error_return (0, "parse error: '%U'",
609 format_unformat_error, input);
610 goto done;
611 }
612 }
613
Neale Ranns4f3c1042019-06-11 01:39:08 -0700614 if (!socket_name)
615 error = clib_error_return (0, "socket name not specified");
616 else
617 error = vnet_punt_socket_add (vm, 1, &pr, (char *) socket_name);
Neale Ranns50f0ac02019-05-15 02:13:37 -0700618
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100619done:
BenoƮt Ganne9ae3c6a2020-07-27 18:27:57 +0200620 unformat_free (input);
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100621 return error;
622}
623
624/*?
625 *
626 * @cliexpar
Paul Vinciguerra32c4d382019-10-23 16:07:32 -0400627 * @cliexcmd{punt socket register socket punt_l4_foo.sock}
628
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100629 ?*/
630/* *INDENT-OFF* */
631VLIB_CLI_COMMAND (punt_socket_register_command, static) =
632{
633 .path = "punt socket register",
634 .function = punt_socket_register_cmd,
Paul Vinciguerra32c4d382019-10-23 16:07:32 -0400635 .short_help = "punt socket register [IPV4|ipv6] [UDP|tcp] [ALL|<port-num>] socket <socket>",
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100636 .is_mp_safe = 1,
637};
638/* *INDENT-ON* */
639
640static clib_error_t *
641punt_socket_deregister_cmd (vlib_main_t * vm,
BenoƮt Ganne9ae3c6a2020-07-27 18:27:57 +0200642 unformat_input_t * input__,
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100643 vlib_cli_command_t * cmd)
644{
BenoƮt Ganne9ae3c6a2020-07-27 18:27:57 +0200645 unformat_input_t line_input, *input = &line_input;
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100646 clib_error_t *error = NULL;
Neale Ranns50f0ac02019-05-15 02:13:37 -0700647 /* *INDENT-OFF* */
648 punt_reg_t pr = {
649 .punt = {
650 .l4 = {
651 .af = AF_IP4,
652 .port = ~0,
Paul Vinciguerra32c4d382019-10-23 16:07:32 -0400653 .protocol = IP_PROTOCOL_UDP,
Neale Ranns50f0ac02019-05-15 02:13:37 -0700654 },
655 },
656 .type = PUNT_TYPE_L4,
657 };
658 /* *INDENT-ON* */
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100659
BenoƮt Ganne9ae3c6a2020-07-27 18:27:57 +0200660 if (!unformat_user (input__, unformat_line_input, input))
661 return 0;
662
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100663 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
664 {
665 if (unformat (input, "ipv4"))
Paul Vinciguerra32c4d382019-10-23 16:07:32 -0400666 pr.punt.l4.af = AF_IP4;
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100667 else if (unformat (input, "ipv6"))
Neale Ranns50f0ac02019-05-15 02:13:37 -0700668 pr.punt.l4.af = AF_IP6;
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100669 else if (unformat (input, "udp"))
Neale Ranns50f0ac02019-05-15 02:13:37 -0700670 pr.punt.l4.protocol = IP_PROTOCOL_UDP;
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100671 else if (unformat (input, "tcp"))
Neale Ranns50f0ac02019-05-15 02:13:37 -0700672 pr.punt.l4.protocol = IP_PROTOCOL_TCP;
673 else if (unformat (input, "%d", &pr.punt.l4.port))
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100674 ;
Paul Vinciguerra32c4d382019-10-23 16:07:32 -0400675 else if (unformat (input, "all"))
676 pr.punt.l4.port = ~0;
Arthur de Kerhora80ff132021-04-12 08:16:56 -0700677 else if (unformat (input, "reason %U", unformat_punt_reason,
678 &pr.punt.exception.reason))
679 pr.type = PUNT_TYPE_EXCEPTION;
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100680 else
681 {
682 error = clib_error_return (0, "parse error: '%U'",
683 format_unformat_error, input);
684 goto done;
685 }
686 }
687
Neale Ranns50f0ac02019-05-15 02:13:37 -0700688 error = vnet_punt_socket_del (vm, &pr);
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100689done:
BenoƮt Ganne9ae3c6a2020-07-27 18:27:57 +0200690 unformat_free (input);
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100691 return error;
692}
693
694/*?
695 *
696 * @cliexpar
697 * @cliexcmd{punt socket register}
698 ?*/
699/* *INDENT-OFF* */
700VLIB_CLI_COMMAND (punt_socket_deregister_command, static) =
701{
702 .path = "punt socket deregister",
703 .function = punt_socket_deregister_cmd,
Paul Vinciguerra32c4d382019-10-23 16:07:32 -0400704 .short_help = "punt socket deregister [IPV4|ipv6] [UDP|tcp] [ALL|<port-num>]",
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100705 .is_mp_safe = 1,
706};
707/* *INDENT-ON* */
708
Neale Ranns50f0ac02019-05-15 02:13:37 -0700709void
710punt_client_walk (punt_type_t pt, punt_client_walk_cb_t cb, void *ctx)
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100711{
712 punt_main_t *pm = &punt_main;
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100713
Neale Ranns50f0ac02019-05-15 02:13:37 -0700714 switch (pt)
715 {
716 case PUNT_TYPE_L4:
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100717 {
Neale Rannsb538dd82019-05-21 06:54:54 -0700718 u32 pci, key;
Neale Ranns50f0ac02019-05-15 02:13:37 -0700719
720 /* *INDENT-OFF* */
Neale Rannsb538dd82019-05-21 06:54:54 -0700721 hash_foreach(key, pci, pm->db.clients_by_l4_port,
722 ({
723 cb (pool_elt_at_index(pm->punt_client_pool, pci), ctx);
724 }));
725 /* *INDENT-ON* */
726 break;
727 }
728 case PUNT_TYPE_IP_PROTO:
729 {
730 u32 pci, key;
731
732 /* *INDENT-OFF* */
733 hash_foreach(key, pci, pm->db.clients_by_ip_proto,
Neale Ranns50f0ac02019-05-15 02:13:37 -0700734 ({
735 cb (pool_elt_at_index(pm->punt_client_pool, pci), ctx);
736 }));
737 /* *INDENT-ON* */
738 break;
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100739 }
Neale Ranns50f0ac02019-05-15 02:13:37 -0700740 case PUNT_TYPE_EXCEPTION:
741 {
742 u32 *pci;
743
744 vec_foreach (pci, pm->db.clients_by_exception)
745 {
746 if (~0 != *pci)
747 cb (pool_elt_at_index (pm->punt_client_pool, *pci), ctx);
748 }
749
750 break;
751 }
752 }
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100753}
754
Neale Ranns50f0ac02019-05-15 02:13:37 -0700755static u8 *
756format_punt_client (u8 * s, va_list * args)
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100757{
Neale Ranns50f0ac02019-05-15 02:13:37 -0700758 punt_client_t *pc = va_arg (*args, punt_client_t *);
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100759
Neale Ranns50f0ac02019-05-15 02:13:37 -0700760 s = format (s, " punt ");
761
762 switch (pc->reg.type)
763 {
764 case PUNT_TYPE_L4:
765 s = format (s, "%U %U port %d",
766 format_ip_address_family, pc->reg.punt.l4.af,
767 format_ip_protocol, pc->reg.punt.l4.protocol,
768 pc->reg.punt.l4.port);
769 break;
Neale Rannsb538dd82019-05-21 06:54:54 -0700770 case PUNT_TYPE_IP_PROTO:
771 s = format (s, "%U %U",
772 format_ip_address_family, pc->reg.punt.ip_proto.af,
773 format_ip_protocol, pc->reg.punt.ip_proto.protocol);
774 break;
Neale Ranns50f0ac02019-05-15 02:13:37 -0700775 case PUNT_TYPE_EXCEPTION:
776 s = format (s, " %U", format_vlib_punt_reason,
777 pc->reg.punt.exception.reason);
778 break;
779 }
780
781 s = format (s, " to socket %s \n", pc->caddr.sun_path);
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100782
783 return (s);
784}
785
Neale Ranns50f0ac02019-05-15 02:13:37 -0700786static walk_rc_t
787punt_client_show_one (const punt_client_t * pc, void *ctx)
788{
789 vlib_cli_output (ctx, "%U", format_punt_client, pc);
790
791 return (WALK_CONTINUE);
792}
793
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100794static clib_error_t *
795punt_socket_show_cmd (vlib_main_t * vm,
BenoƮt Ganne9ae3c6a2020-07-27 18:27:57 +0200796 unformat_input_t * input__, vlib_cli_command_t * cmd)
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100797{
BenoƮt Ganne9ae3c6a2020-07-27 18:27:57 +0200798 unformat_input_t line_input, *input = &line_input;
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100799 clib_error_t *error = NULL;
Neale Ranns50f0ac02019-05-15 02:13:37 -0700800 punt_type_t pt;
801
802 pt = PUNT_TYPE_L4;
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100803
BenoƮt Ganne9ae3c6a2020-07-27 18:27:57 +0200804 if (!unformat_user (input__, unformat_line_input, input))
805 return 0;
806
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100807 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
808 {
Neale Ranns50f0ac02019-05-15 02:13:37 -0700809 if (unformat (input, "exception"))
810 pt = PUNT_TYPE_EXCEPTION;
811 else if (unformat (input, "l4"))
812 pt = PUNT_TYPE_L4;
Neale Rannsb538dd82019-05-21 06:54:54 -0700813 else if (unformat (input, "ip"))
814 pt = PUNT_TYPE_IP_PROTO;
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100815 else
816 {
817 error = clib_error_return (0, "parse error: '%U'",
818 format_unformat_error, input);
819 goto done;
820 }
821 }
822
Neale Ranns50f0ac02019-05-15 02:13:37 -0700823 punt_client_walk (pt, punt_client_show_one, vm);
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100824
825done:
BenoƮt Ganne9ae3c6a2020-07-27 18:27:57 +0200826 unformat_free (input);
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100827 return (error);
828}
829
830/*?
831 *
832 * @cliexpar
833 * @cliexcmd{show punt socket ipv4}
834 ?*/
835/* *INDENT-OFF* */
836VLIB_CLI_COMMAND (show_punt_socket_registration_command, static) =
837{
838 .path = "show punt socket registrations",
839 .function = punt_socket_show_cmd,
Neale Ranns50f0ac02019-05-15 02:13:37 -0700840 .short_help = "show punt socket registrations [l4|exception]",
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100841 .is_mp_safe = 1,
842};
843/* *INDENT-ON* */
844
Ole Troanf7a55ad2017-05-16 14:59:29 +0200845clib_error_t *
Neale Ranns76b56492018-09-28 15:16:14 +0000846ip_punt_init (vlib_main_t * vm)
Ole Troanf7a55ad2017-05-16 14:59:29 +0200847{
Neale Ranns50f0ac02019-05-15 02:13:37 -0700848 clib_error_t *error = NULL;
Ole Troanf7a55ad2017-05-16 14:59:29 +0200849 punt_main_t *pm = &punt_main;
Neale Ranns39040a62019-07-10 01:47:15 -0700850 vlib_thread_main_t *tm = vlib_get_thread_main ();
Ole Troanf7a55ad2017-05-16 14:59:29 +0200851
Ole Troanf7a55ad2017-05-16 14:59:29 +0200852 pm->is_configured = false;
Neale Ranns50f0ac02019-05-15 02:13:37 -0700853 pm->interface_output_node =
854 vlib_get_node_by_name (vm, (u8 *) "interface-output");
855
856 if ((error = vlib_call_init_function (vm, punt_init)))
857 return error;
858
859 pm->hdl = vlib_punt_client_register ("ip-punt");
860
Neale Ranns39040a62019-07-10 01:47:15 -0700861 vec_validate_aligned (pm->thread_data, tm->n_vlib_mains,
862 CLIB_CACHE_LINE_BYTES);
863
Neale Ranns50f0ac02019-05-15 02:13:37 -0700864 return (error);
Ole Troanf7a55ad2017-05-16 14:59:29 +0200865}
866
Mohammed Hawari45723b82021-02-05 15:40:00 +0100867u8 *
868format_vnet_punt_reason_flags (u8 *s, va_list *args)
869{
870 vnet_punt_reason_flag_t flag = va_arg (*args, int);
871#define _(pos, len, value, name, str) \
872 if (vnet_punt_reason_flag_is_##name (flag)) \
873 s = format (s, "%s ", str);
874
875 foreach_vnet_punt_reason_flag
876#undef _
877 return (s);
878}
879
Neale Ranns76b56492018-09-28 15:16:14 +0000880VLIB_INIT_FUNCTION (ip_punt_init);
Ole Troanf7a55ad2017-05-16 14:59:29 +0200881
882static clib_error_t *
883punt_config (vlib_main_t * vm, unformat_input_t * input)
884{
885 punt_main_t *pm = &punt_main;
886 char *socket_path = 0;
887
888 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
889 {
890 if (unformat (input, "socket %s", &socket_path))
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100891 strncpy (pm->sun_path, socket_path, UNIX_PATH_MAX - 1);
Ole Troanf7a55ad2017-05-16 14:59:29 +0200892 else
893 return clib_error_return (0, "unknown input `%U'",
894 format_unformat_error, input);
895 }
896
897 if (socket_path == 0)
898 return 0;
899
900 /* UNIX domain socket */
901 struct sockaddr_un addr;
902 if ((pm->socket_fd = socket (AF_UNIX, SOCK_DGRAM | SOCK_NONBLOCK, 0)) == -1)
903 {
904 return clib_error_return (0, "socket error");
905 }
906
Dave Barachb7b92992018-10-17 10:38:51 -0400907 clib_memset (&addr, 0, sizeof (addr));
Ole Troanf7a55ad2017-05-16 14:59:29 +0200908 addr.sun_family = AF_UNIX;
909 if (*socket_path == '\0')
910 {
911 *addr.sun_path = '\0';
912 strncpy (addr.sun_path + 1, socket_path + 1,
913 sizeof (addr.sun_path) - 2);
914 }
915 else
916 {
917 strncpy (addr.sun_path, socket_path, sizeof (addr.sun_path) - 1);
918 unlink (socket_path);
919 }
920
921 if (bind (pm->socket_fd, (struct sockaddr *) &addr, sizeof (addr)) == -1)
922 {
923 return clib_error_return (0, "bind error");
924 }
925
Neale Ranns50f0ac02019-05-15 02:13:37 -0700926 int n_bytes = 0x10000;
927
928 if (setsockopt
929 (pm->socket_fd, SOL_SOCKET, SO_SNDBUF, &n_bytes,
930 sizeof (n_bytes)) == -1)
931 {
932 return clib_error_return (0, "setsockopt error");
933 }
934
Ole Troanf7a55ad2017-05-16 14:59:29 +0200935 /* Register socket */
Damjan Marion56dd5432017-09-08 19:52:02 +0200936 clib_file_main_t *fm = &file_main;
937 clib_file_t template = { 0 };
Ole Troanf7a55ad2017-05-16 14:59:29 +0200938 template.read_function = punt_socket_read_ready;
939 template.file_descriptor = pm->socket_fd;
Paul Vinciguerra5481ad42020-01-28 14:47:17 -0500940 template.description = format (0, "punt socket %s", socket_path);
Damjan Marion56dd5432017-09-08 19:52:02 +0200941 pm->clib_file_index = clib_file_add (fm, &template);
Ole Troanf7a55ad2017-05-16 14:59:29 +0200942
943 pm->is_configured = true;
944
945 return 0;
946}
947
948VLIB_CONFIG_FUNCTION (punt_config, "punt");
949
Alexander Popovsky (apopovsk)4a7e58b2016-10-05 22:31:23 -0700950/*
951 * fd.io coding-style-patch-verification: ON
952 *
953 * Local Variables:
954 * eval: (c-set-style "gnu")
955 * End:
956 */