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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * @brief Definitions for punt infrastructure.
20 #ifndef included_punt_h
21 #define included_punt_h
25 #include <vnet/ip/ip.h>
27 #define foreach_punt_type \
29 _(EXCEPTION, "exception") \
30 _(IP_PROTO, "ip-proto")
32 typedef enum punt_type_t_
34 #define _(v, s) PUNT_TYPE_##v,
39 typedef struct punt_l4_t_
41 ip_address_family_t af;
42 ip_protocol_t protocol;
46 typedef struct punt_ip_proto_t_
48 ip_address_family_t af;
49 ip_protocol_t protocol;
52 typedef struct punt_exception_t_
54 vlib_punt_reason_t reason;
57 typedef struct punt_union_t_
59 punt_exception_t exception;
61 punt_ip_proto_t ip_proto;
64 typedef struct punt_reg_t_
71 clib_error_t *vnet_punt_add_del (vlib_main_t * vm,
72 const punt_reg_t * pr, bool is_add);
73 clib_error_t *vnet_punt_socket_add (vlib_main_t * vm,
75 const punt_reg_t * pr,
76 char *client_pathname);
77 clib_error_t *vnet_punt_socket_del (vlib_main_t * vm, const punt_reg_t * pr);
78 char *vnet_punt_get_server_pathname (void);
88 * Packet descriptor header. Version 1
89 * If this header changes, the version must also change to notify clients.
91 #define PUNT_PACKETDESC_VERSION 1
92 typedef struct __attribute__ ((packed))
94 u32 sw_if_index; /* RX or TX interface */
95 enum punt_action_e action;
104 struct sockaddr_un caddr;
107 typedef struct punt_client_db_t_
109 void *clients_by_l4_port;
110 u32 *clients_by_exception;
111 void *clients_by_ip_proto;
117 char sun_path[sizeof (struct sockaddr_un)];
119 punt_client_t *punt_client_pool;
122 vlib_node_t *interface_output_node;
128 extern punt_main_t punt_main;
130 typedef walk_rc_t (*punt_client_walk_cb_t) (const punt_client_t * pc,
132 extern void punt_client_walk (punt_type_t pt,
133 punt_client_walk_cb_t cb, void *ctx);
136 * inlines for the data-plane
138 static_always_inline u32
139 punt_client_l4_mk_key (ip_address_family_t af, u16 port)
141 return (af << BITS (port) | port);
144 static_always_inline punt_client_t *
145 punt_client_l4_get (ip_address_family_t af, u16 port)
147 punt_main_t *pm = &punt_main;
150 p = hash_get (pm->db.clients_by_l4_port, punt_client_l4_mk_key (af, port));
153 return (pool_elt_at_index (pm->punt_client_pool, p[0]));
158 static_always_inline u32
159 punt_client_ip_proto_mk_key (ip_address_family_t af, ip_protocol_t proto)
161 return (af << 16 | proto);
164 static_always_inline punt_client_t *
165 punt_client_ip_proto_get (ip_address_family_t af, ip_protocol_t proto)
167 punt_main_t *pm = &punt_main;
171 hash_get (pm->db.clients_by_ip_proto,
172 punt_client_ip_proto_mk_key (af, proto));
175 return (pool_elt_at_index (pm->punt_client_pool, p[0]));
180 static_always_inline punt_client_t *
181 punt_client_exception_get (vlib_punt_reason_t reason)
183 punt_main_t *pm = &punt_main;
186 if (reason >= vec_len (pm->db.clients_by_exception))
189 pci = pm->db.clients_by_exception[reason];
192 return (pool_elt_at_index (pm->punt_client_pool, pci));
197 extern vlib_node_registration_t udp4_punt_node;
198 extern vlib_node_registration_t udp6_punt_node;
199 extern vlib_node_registration_t udp4_punt_socket_node;
200 extern vlib_node_registration_t udp6_punt_socket_node;
201 extern vlib_node_registration_t ip4_proto_punt_socket_node;
202 extern vlib_node_registration_t ip6_proto_punt_socket_node;
203 extern vlib_node_registration_t punt_socket_rx_node;
208 * fd.io coding-style-patch-verification: ON
211 * eval: (c-set-style "gnu")