xref: /freebsd/sys/net/debugnet_int.h (revision b498331b037f20bde90b46fc37678fbd421dcf09)
17790c8c1SConrad Meyer /*-
24d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
37790c8c1SConrad Meyer  *
47790c8c1SConrad Meyer  * Copyright (c) 2019 Isilon Systems, LLC.
57790c8c1SConrad Meyer  *
67790c8c1SConrad Meyer  * Redistribution and use in source and binary forms, with or without
77790c8c1SConrad Meyer  * modification, are permitted provided that the following conditions
87790c8c1SConrad Meyer  * are met:
97790c8c1SConrad Meyer  * 1. Redistributions of source code must retain the above copyright
107790c8c1SConrad Meyer  *    notice, this list of conditions and the following disclaimer.
117790c8c1SConrad Meyer  * 2. Redistributions in binary form must reproduce the above copyright
127790c8c1SConrad Meyer  *    notice, this list of conditions and the following disclaimer in the
137790c8c1SConrad Meyer  *    documentation and/or other materials provided with the distribution.
147790c8c1SConrad Meyer  *
157790c8c1SConrad Meyer  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
167790c8c1SConrad Meyer  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
177790c8c1SConrad Meyer  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
187790c8c1SConrad Meyer  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
197790c8c1SConrad Meyer  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
207790c8c1SConrad Meyer  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
217790c8c1SConrad Meyer  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
227790c8c1SConrad Meyer  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
237790c8c1SConrad Meyer  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
247790c8c1SConrad Meyer  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
257790c8c1SConrad Meyer  * SUCH DAMAGE.
267790c8c1SConrad Meyer  *
277790c8c1SConrad Meyer  * $FreeBSD$
287790c8c1SConrad Meyer  */
297790c8c1SConrad Meyer 
307790c8c1SConrad Meyer #pragma once
317790c8c1SConrad Meyer 
327790c8c1SConrad Meyer #ifndef DEBUGNET_INTERNAL
337790c8c1SConrad Meyer #error "Don't include this"
347790c8c1SConrad Meyer #endif
357790c8c1SConrad Meyer 
367790c8c1SConrad Meyer #define	DNETDEBUG(f, ...) do {						\
377790c8c1SConrad Meyer 	if (debugnet_debug > 0)						\
387790c8c1SConrad Meyer 		printf(("%s: " f), __func__, ## __VA_ARGS__);		\
397790c8c1SConrad Meyer } while (0)
407790c8c1SConrad Meyer #define	DNETDEBUG_IF(i, f, ...) do {					\
417790c8c1SConrad Meyer 	if (debugnet_debug > 0)						\
427790c8c1SConrad Meyer 		if_printf((i), ("%s: " f), __func__, ## __VA_ARGS__);	\
437790c8c1SConrad Meyer } while (0)
447790c8c1SConrad Meyer #define	DNETDEBUGV(f, ...) do {						\
457790c8c1SConrad Meyer 	if (debugnet_debug > 1)						\
467790c8c1SConrad Meyer 		printf(("%s: " f), __func__, ## __VA_ARGS__);		\
477790c8c1SConrad Meyer } while (0)
487790c8c1SConrad Meyer 
497790c8c1SConrad Meyer enum dnet_pcb_st {
507790c8c1SConrad Meyer 	DN_STATE_INIT = 1,
517790c8c1SConrad Meyer 	DN_STATE_HAVE_GW_MAC,
527790c8c1SConrad Meyer 	DN_STATE_GOT_HERALD_PORT,
53e9c69625SConrad Meyer 	DN_STATE_REMOTE_CLOSED,
547790c8c1SConrad Meyer };
557790c8c1SConrad Meyer 
567790c8c1SConrad Meyer struct debugnet_pcb {
577790c8c1SConrad Meyer 	uint64_t		dp_rcvd_acks;
587790c8c1SConrad Meyer 
597790c8c1SConrad Meyer 	in_addr_t		dp_client;
607790c8c1SConrad Meyer 	in_addr_t		dp_server;
617790c8c1SConrad Meyer 	in_addr_t		dp_gateway;
627790c8c1SConrad Meyer 	uint32_t		dp_seqno;
637790c8c1SConrad Meyer 
647790c8c1SConrad Meyer 	struct ether_addr	dp_gw_mac;
657790c8c1SConrad Meyer 	uint16_t		dp_server_port;
667790c8c1SConrad Meyer 
677790c8c1SConrad Meyer 	struct ifnet		*dp_ifp;
687790c8c1SConrad Meyer 	/* Saved driver if_input to restore on close. */
697790c8c1SConrad Meyer 	void			(*dp_drv_input)(struct ifnet *, struct mbuf *);
707790c8c1SConrad Meyer 
71e9c69625SConrad Meyer 	/* RX handler for bidirectional protocols. */
72*b498331bSJohn Reimer 	int			(*dp_rx_handler)(struct mbuf *);
73*b498331bSJohn Reimer 
74*b498331bSJohn Reimer 	/* Cleanup signal for bidirectional protocols. */
75*b498331bSJohn Reimer 	void			(*dp_finish_handler)(void);
76e9c69625SConrad Meyer 
777790c8c1SConrad Meyer 	enum dnet_pcb_st	dp_state;
78e9c69625SConrad Meyer 	uint16_t		dp_client_port;
79fde2cf65SConrad Meyer 	bool			dp_event_started;
807790c8c1SConrad Meyer };
817790c8c1SConrad Meyer 
827790c8c1SConrad Meyer /* TODO(CEM): Obviate this assertion by using a BITSET(9) for acks. */
837790c8c1SConrad Meyer CTASSERT(sizeof(((struct debugnet_pcb *)0)->dp_rcvd_acks) * NBBY >=
847790c8c1SConrad Meyer     DEBUGNET_MAX_IN_FLIGHT);
857790c8c1SConrad Meyer 
867790c8c1SConrad Meyer extern unsigned debugnet_debug;
877790c8c1SConrad Meyer SYSCTL_DECL(_net_debugnet);
887790c8c1SConrad Meyer 
897790c8c1SConrad Meyer int debugnet_ether_output(struct mbuf *, struct ifnet *, struct ether_addr,
907790c8c1SConrad Meyer     u_short);
917790c8c1SConrad Meyer void debugnet_handle_udp(struct debugnet_pcb *, struct mbuf **);
927790c8c1SConrad Meyer 
937790c8c1SConrad Meyer #ifdef INET
947790c8c1SConrad Meyer int debugnet_arp_gw(struct debugnet_pcb *);
957790c8c1SConrad Meyer void debugnet_handle_arp(struct debugnet_pcb *, struct mbuf **);
967790c8c1SConrad Meyer void debugnet_handle_ip(struct debugnet_pcb *, struct mbuf **);
977790c8c1SConrad Meyer int debugnet_ip_output(struct debugnet_pcb *, struct mbuf *);
987790c8c1SConrad Meyer #endif
99