35 #include <sys/socket.h> 153 if (protocol != IP_PROTOCOL_UDP)
155 "only UDP protocol (%d) is supported, got %d",
156 IP_PROTOCOL_UDP, protocol);
158 if (port == (
u16) ~ 0)
169 memcpy (c->
caddr.sun_path, client_pathname, sizeof (c->
caddr.sun_path));
170 c->
caddr.sun_family = AF_UNIX;
201 memcpy (c->
caddr.sun_path, client_pathname, sizeof (c->
caddr.sun_path));
202 c->
caddr.sun_family = AF_UNIX;
203 c->
reg.
type = PUNT_TYPE_IP_PROTO;
218 char *client_pathname)
231 memcpy (pc->
caddr.sun_path, client_pathname, sizeof (pc->
caddr.sun_path));
232 pc->
caddr.sun_family = AF_UNIX;
233 pc->
reg.
type = PUNT_TYPE_EXCEPTION;
304 "Punt socket: Invalid client path: %s",
315 case PUNT_TYPE_IP_PROTO:
320 case PUNT_TYPE_EXCEPTION:
343 case PUNT_TYPE_IP_PROTO:
346 case PUNT_TYPE_EXCEPTION:
374 if (protocol != IP_PROTOCOL_UDP && protocol != IP_PROTOCOL_TCP)
376 "only UDP (%d) and TCP (%d) protocols are supported, got %d",
377 IP_PROTOCOL_UDP, IP_PROTOCOL_TCP, protocol);
379 if (port == (
u16) ~ 0)
381 if (protocol == IP_PROTOCOL_UDP)
383 else if (protocol == IP_PROTOCOL_TCP)
391 if (protocol == IP_PROTOCOL_TCP)
400 if (protocol == IP_PROTOCOL_TCP)
417 case PUNT_TYPE_EXCEPTION:
418 case PUNT_TYPE_IP_PROTO:
438 .protocol = IP_PROTOCOL_UDP,
441 .type = PUNT_TYPE_L4,
459 else if (
unformat (input,
"%d", &port))
510 .short_help =
"set punt [IPV4|ip6|ipv6] [UDP|tcp] [del] [ALL|<port-num>]",
529 .protocol = IP_PROTOCOL_UDP,
532 .type = PUNT_TYPE_L4,
553 else if (
unformat (input,
"socket %s", &socket_name))
582 .path =
"punt socket register",
584 .short_help =
"punt socket register [IPV4|ipv6] [UDP|tcp] [ALL|<port-num>] socket <socket>",
602 .protocol = IP_PROTOCOL_UDP,
605 .type = PUNT_TYPE_L4,
648 .path =
"punt socket deregister",
650 .short_help =
"punt socket deregister [IPV4|ipv6] [UDP|tcp] [ALL|<port-num>]",
669 cb (pool_elt_at_index(pm->punt_client_pool, pci), ctx);
674 case PUNT_TYPE_IP_PROTO:
681 cb (pool_elt_at_index(pm->punt_client_pool, pci), ctx);
686 case PUNT_TYPE_EXCEPTION:
711 s =
format (s,
"%U %U port %d",
716 case PUNT_TYPE_IP_PROTO:
721 case PUNT_TYPE_EXCEPTION:
727 s =
format (s,
" to socket %s \n", pc->
caddr.sun_path);
756 pt = PUNT_TYPE_EXCEPTION;
760 pt = PUNT_TYPE_IP_PROTO;
784 .path =
"show punt socket registrations",
786 .short_help =
"show punt socket registrations [l4|exception]",
819 char *socket_path = 0;
823 if (
unformat (input,
"socket %s", &socket_path))
824 strncpy (pm->
sun_path, socket_path, UNIX_PATH_MAX - 1);
830 if (socket_path == 0)
834 struct sockaddr_un addr;
835 if ((pm->
socket_fd = socket (AF_UNIX, SOCK_DGRAM | SOCK_NONBLOCK, 0)) == -1)
841 addr.sun_family = AF_UNIX;
842 if (*socket_path ==
'\0')
844 *addr.sun_path =
'\0';
845 strncpy (addr.sun_path + 1, socket_path + 1,
846 sizeof (addr.sun_path) - 2);
850 strncpy (addr.sun_path, socket_path, sizeof (addr.sun_path) - 1);
851 unlink (socket_path);
854 if (bind (pm->
socket_fd, (
struct sockaddr *) &addr, sizeof (addr)) == -1)
859 int n_bytes = 0x10000;
862 (pm->
socket_fd, SOL_SOCKET, SO_SNDBUF, &n_bytes,
863 sizeof (n_bytes)) == -1)
872 template.file_descriptor = pm->
socket_fd;
873 template.description =
format (0,
"%s", socket_path);
vlib_node_t * interface_output_node
enum punt_type_t_ punt_type_t
static u32 punt_client_exception_db_remove(vlib_punt_reason_t reason)
A registration, by a client, to direct punted traffic to a given node.
static u8 * format_punt_client(u8 *s, va_list *args)
#define hash_set(h, key, value)
#define hash_unset(h, key)
void ip6_register_protocol(u32 protocol, u32 node_index)
#define pool_get_zero(P, E)
Allocate an object E from a pool P and zero it.
void ip6_unregister_protocol(u32 protocol)
static clib_error_t * punt_config(vlib_main_t *vm, unformat_input_t *input)
static_always_inline u32 punt_client_l4_mk_key(ip_address_family_t af, u16 port)
static clib_error_t * punt_socket_read_ready(clib_file_t *uf)
static void vlib_node_set_interrupt_pending(vlib_main_t *vm, u32 node_index)
vlib_node_registration_t ip4_proto_punt_socket_node
(constructor) VLIB_REGISTER_NODE (ip4_proto_punt_socket_node)
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
static_always_inline punt_client_t * punt_client_l4_get(ip_address_family_t af, u16 port)
vlib_node_registration_t udp4_punt_socket_node
(constructor) VLIB_REGISTER_NODE (udp4_punt_socket_node)
static walk_rc_t punt_client_show_one(const punt_client_t *pc, void *ctx)
clib_error_t * vnet_punt_socket_del(vlib_main_t *vm, const punt_reg_t *pr)
static_always_inline punt_client_t * punt_client_ip_proto_get(ip_address_family_t af, ip_protocol_t proto)
#define vec_validate_aligned(V, I, A)
Make sure vector is long enough for given index (no header, specified alignment)
void ip4_register_protocol(u32 protocol, u32 node_index)
punt_thread_data_t * thread_data
clib_error_t * vnet_punt_socket_add(vlib_main_t *vm, u32 header_version, const punt_reg_t *pr, char *client_pathname)
clib_file_function_t * read_function
u8 * format_vlib_punt_reason(u8 *s, va_list *args)
Format a punt reason.
static clib_error_t * punt_socket_register_cmd(vlib_main_t *vm, unformat_input_t *input__, vlib_cli_command_t *cmd)
enum walk_rc_t_ walk_rc_t
Walk return code.
vl_api_ip_proto_t protocol
static clib_error_t * punt_socket_deregister_cmd(vlib_main_t *vm, unformat_input_t *input__, vlib_cli_command_t *cmd)
static void punt_client_ip_proto_db_add(ip_address_family_t af, ip_protocol_t proto, u32 index)
#define VLIB_INIT_FUNCTION(x)
punt_client_t * punt_client_pool
#define hash_foreach(key_var, value_var, h, body)
static u32 punt_client_ip_proto_db_remove(ip_address_family_t af, ip_protocol_t proto)
#define clib_error_return(e, args...)
clib_file_main_t file_main
static_always_inline punt_client_t * punt_client_exception_get(vlib_punt_reason_t reason)
#define vlib_call_init_function(vm, x)
static clib_error_t * punt_cli(vlib_main_t *vm, unformat_input_t *input__, vlib_cli_command_t *cmd)
vlib_punt_hdl_t vlib_punt_client_register(const char *who)
Register a new clinet.
static_always_inline u32 punt_client_ip_proto_mk_key(ip_address_family_t af, ip_protocol_t proto)
enum ip_protocol ip_protocol_t
static void punt_client_exception_db_add(vlib_punt_reason_t reason, u32 pci)
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
vlib_node_t * vlib_get_node_by_name(vlib_main_t *vm, u8 *name)
static clib_error_t * punt_l4_add_del(vlib_main_t *vm, ip_address_family_t af, ip_protocol_t protocol, u16 port, bool is_add)
Request IP L4 traffic punt to the local TCP/IP stack.
#define VLIB_CONFIG_FUNCTION(x, n,...)
vlib_node_registration_t punt_socket_rx_node
(constructor) VLIB_REGISTER_NODE (punt_socket_rx_node)
u8 * format_ip_address_family(u8 *s, va_list *args)
static clib_error_t * punt_init(vlib_main_t *vm)
static clib_error_t * punt_socket_show_cmd(vlib_main_t *vm, unformat_input_t *input__, vlib_cli_command_t *cmd)
punt_exception_t exception
void udp_punt_unknown(vlib_main_t *vm, u8 is_ip4, u8 is_add)
vlib_node_registration_t udp6_punt_socket_node
(constructor) VLIB_REGISTER_NODE (udp6_punt_socket_node)
static clib_error_t * punt_socket_unregister_exception(vlib_punt_reason_t reason)
void udp_unregister_dst_port(vlib_main_t *vm, udp_dst_port_t dst_port, u8 is_ip4)
static clib_error_t * punt_socket_register_exception(vlib_main_t *vm, vlib_punt_reason_t reason, char *client_pathname)
static clib_error_t * punt_socket_register_ip_proto(vlib_main_t *vm, ip_address_family_t af, ip_protocol_t proto, char *client_pathname)
#define VLIB_CLI_COMMAND(x,...)
static clib_error_t * punt_socket_unregister_ip_proto(ip_address_family_t af, ip_protocol_t proto)
#define pool_put_index(p, i)
Free pool element with given index.
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
walk_rc_t(* punt_client_walk_cb_t)(const punt_client_t *pc, void *ctx)
static uword clib_file_add(clib_file_main_t *um, clib_file_t *template)
char sun_path[sizeof(struct sockaddr_un)]
static u32 punt_client_l4_db_remove(ip_address_family_t af, u16 port)
#define clib_error_report(e)
static vlib_main_t * vlib_get_main(void)
u32 * clients_by_exception
enum ip_address_family_t_ ip_address_family_t
void tcp_punt_unknown(vlib_main_t *vm, u8 is_ip4, u8 is_add)
int vlib_punt_register(vlib_punt_hdl_t client, vlib_punt_reason_t reason, const char *node_name)
Register a node to receive particular punted buffers.
static void punt_client_l4_db_add(ip_address_family_t af, u16 port, u32 index)
void * clients_by_ip_proto
vlib_node_registration_t ip6_proto_punt_socket_node
(constructor) VLIB_REGISTER_NODE (ip6_proto_punt_socket_node)
static clib_error_t * punt_socket_register_l4(vlib_main_t *vm, ip_address_family_t af, u8 protocol, u16 port, char *client_pathname)
#define PUNT_PACKETDESC_VERSION
static clib_error_t * punt_socket_unregister_l4(ip_address_family_t af, ip_protocol_t protocol, u16 port)
static vlib_thread_main_t * vlib_get_thread_main()
#define vec_foreach(var, vec)
Vector iterator.
clib_error_t * ip_punt_init(vlib_main_t *vm)
void udp_register_dst_port(vlib_main_t *vm, udp_dst_port_t dst_port, u32 node_index, u8 is_ip4)
#define vec_validate_init_empty(V, I, INIT)
Make sure vector is long enough for given index and initialize empty space (no header, unspecified alignment)
#define CLIB_CACHE_LINE_BYTES
clib_error_t * vnet_punt_add_del(vlib_main_t *vm, const punt_reg_t *pr, bool is_add)
vlib_punt_reason_t reason
enum vlib_punt_reason_t_ vlib_punt_reason_t
The 'syatem' defined punt reasons.
char * vnet_punt_get_server_pathname(void)
void * clients_by_l4_port
vlib_node_registration_t udp4_punt_node
(constructor) VLIB_REGISTER_NODE (udp4_punt_node)
void ip4_unregister_protocol(u32 protocolx)
void punt_client_walk(punt_type_t pt, punt_client_walk_cb_t cb, void *ctx)
Definitions for punt infrastructure.