blob: ce949421dad818b77408481ab728555d6df36d10 [file] [log] [blame]
Neale Ranns76b56492018-09-28 15:16:14 +00001/*
2 * Copyright (c) 2018 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#ifndef __PUNT_H__
17#define __PUNT_H__
18
19#include <vlib/vlib.h>
20
21/**
22 * The 'syatem' defined punt reasons.
23 * Only add to this list reasons defined and used within the vlib subsystem.
24 * To define new reasons in e.g. plgins, use punt_reason_alloc()
25 */
26typedef enum vlib_punt_reason_t_
27{
28 PUNT_N_REASONS,
29} vlib_punt_reason_t;
30
Neale Ranns50f0ac02019-05-15 02:13:37 -070031/**
32 * Walk each punt reason
33 */
Mohammed Hawari45723b82021-02-05 15:40:00 +010034typedef int (*punt_reason_walk_cb_t) (vlib_punt_reason_t id, const u8 *name,
35 void *ctx);
Neale Ranns50f0ac02019-05-15 02:13:37 -070036
37extern void punt_reason_walk (punt_reason_walk_cb_t cb, void *cxt);
Neale Ranns76b56492018-09-28 15:16:14 +000038
39/**
40 * @brief Format a punt reason
41 */
42extern u8 *format_vlib_punt_reason (u8 * s, va_list * args);
43
44/**
Mohammed Hawari45723b82021-02-05 15:40:00 +010045 * @brief Unformat a punt reason
46 */
47extern uword unformat_punt_reason (unformat_input_t *input, va_list *args);
48
49/**
Neale Ranns76b56492018-09-28 15:16:14 +000050 * Typedef for a client handle
51 */
52typedef int vlib_punt_hdl_t;
53
54/**
55 * @brief Register a new clinet
56 *
57 * @param who - The name of the client
58 *
59 * @retrun the handle the punt infra allocated for this client that must
60 * be used when the client wishes to use the infra
61 */
62vlib_punt_hdl_t vlib_punt_client_register (const char *who);
63
Neale Ranns8d6d74c2020-02-20 09:45:16 +000064typedef void (*punt_interested_listener_t) (vlib_enable_or_disable_t i,
65 void *data);
66
Neale Ranns76b56492018-09-28 15:16:14 +000067/**
68 * Allocate a new punt reason
Mohammed Hawari45723b82021-02-05 15:40:00 +010069 * @param fn - A callback to invoke when an entity becomes
70 * [un]interested in the punt code.
71 * @param data - To be passed in the callback function.
72 * @param flags - flags associated with the punt reason
73 * @param flags_format - formatting function to display those flags (may be
74 * NULL)
Neale Ranns76b56492018-09-28 15:16:14 +000075 */
76extern int vlib_punt_reason_alloc (vlib_punt_hdl_t client,
77 const char *reason_name,
Mohammed Hawari45723b82021-02-05 15:40:00 +010078 punt_interested_listener_t fn, void *data,
79 vlib_punt_reason_t *reason, u32 flags,
80 format_function_t *flags_format);
Neale Ranns76b56492018-09-28 15:16:14 +000081
82/**
Neale Ranns50f0ac02019-05-15 02:13:37 -070083 * Validate that a punt reason is assigned
84 */
85extern int vlib_punt_reason_validate (vlib_punt_reason_t reason);
86
87/**
Neale Ranns76b56492018-09-28 15:16:14 +000088 * @brief Register a node to receive particular punted buffers
89 *
90 * @paran client - The registered client registering for the packets
91 * @param reason - The reason the packet was punted
92 * @param node - The node to which the punted packets will be sent
93 */
94extern int vlib_punt_register (vlib_punt_hdl_t client,
95 vlib_punt_reason_t reason, const char *node);
96extern int vlib_punt_unregister (vlib_punt_hdl_t client,
97 vlib_punt_reason_t pr, const char *node);
98
Mohammed Hawari45723b82021-02-05 15:40:00 +010099extern u32 vlib_punt_reason_get_flags (vlib_punt_reason_t pr);
100
Neale Ranns76b56492018-09-28 15:16:14 +0000101/**
102 * FOR USE IN THE DP ONLY
103 *
104 * Arc[s] to follow for each reason
105 */
106extern u16 **punt_dp_db;
107
108/**
109 * FOR USE IN THE DP ONLY
110 *
111 * Per-reason counters
112 */
113extern vlib_combined_counter_main_t punt_counters;
114
115#endif
116
117/*
118 * fd.io coding-style-patch-verification: ON
119 *
120 * Local Variables:
121 * eval: (c-set-style "gnu")
122 * End:
123 */