xref: /freebsd/sys/net/debugnet_int.h (revision fde2cf65ce9bcc407bad46acad5fe16e93d16c52)
17790c8c1SConrad Meyer /*-
27790c8c1SConrad Meyer  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
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,
537790c8c1SConrad Meyer };
547790c8c1SConrad Meyer 
557790c8c1SConrad Meyer struct debugnet_pcb {
567790c8c1SConrad Meyer 	uint64_t		dp_rcvd_acks;
577790c8c1SConrad Meyer 
587790c8c1SConrad Meyer 	in_addr_t		dp_client;
597790c8c1SConrad Meyer 	in_addr_t		dp_server;
607790c8c1SConrad Meyer 	in_addr_t		dp_gateway;
617790c8c1SConrad Meyer 	uint32_t		dp_seqno;
627790c8c1SConrad Meyer 
637790c8c1SConrad Meyer 	struct ether_addr	dp_gw_mac;
647790c8c1SConrad Meyer 	uint16_t		dp_server_port;
657790c8c1SConrad Meyer 
667790c8c1SConrad Meyer 	struct ifnet		*dp_ifp;
677790c8c1SConrad Meyer 	/* Saved driver if_input to restore on close. */
687790c8c1SConrad Meyer 	void			(*dp_drv_input)(struct ifnet *, struct mbuf *);
697790c8c1SConrad Meyer 
707790c8c1SConrad Meyer 	enum dnet_pcb_st	dp_state;
717790c8c1SConrad Meyer 	uint16_t		dp_client_ack_port;
72*fde2cf65SConrad Meyer 	bool			dp_event_started;
737790c8c1SConrad Meyer };
747790c8c1SConrad Meyer 
757790c8c1SConrad Meyer /* TODO(CEM): Obviate this assertion by using a BITSET(9) for acks. */
767790c8c1SConrad Meyer CTASSERT(sizeof(((struct debugnet_pcb *)0)->dp_rcvd_acks) * NBBY >=
777790c8c1SConrad Meyer     DEBUGNET_MAX_IN_FLIGHT);
787790c8c1SConrad Meyer 
797790c8c1SConrad Meyer extern unsigned debugnet_debug;
807790c8c1SConrad Meyer SYSCTL_DECL(_net_debugnet);
817790c8c1SConrad Meyer 
827790c8c1SConrad Meyer int debugnet_ether_output(struct mbuf *, struct ifnet *, struct ether_addr,
837790c8c1SConrad Meyer     u_short);
847790c8c1SConrad Meyer void debugnet_handle_udp(struct debugnet_pcb *, struct mbuf **);
857790c8c1SConrad Meyer void debugnet_network_poll(struct ifnet *);
867790c8c1SConrad Meyer 
877790c8c1SConrad Meyer #ifdef INET
887790c8c1SConrad Meyer int debugnet_arp_gw(struct debugnet_pcb *);
897790c8c1SConrad Meyer void debugnet_handle_arp(struct debugnet_pcb *, struct mbuf **);
907790c8c1SConrad Meyer void debugnet_handle_ip(struct debugnet_pcb *, struct mbuf **);
917790c8c1SConrad Meyer int debugnet_ip_output(struct debugnet_pcb *, struct mbuf *);
927790c8c1SConrad Meyer #endif
93