xref: /f-stack/freebsd/net/debugnet_int.h (revision 22ce4aff)
1*22ce4affSfengbojiang /*-
2*22ce4affSfengbojiang  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3*22ce4affSfengbojiang  *
4*22ce4affSfengbojiang  * Copyright (c) 2019 Isilon Systems, LLC.
5*22ce4affSfengbojiang  *
6*22ce4affSfengbojiang  * Redistribution and use in source and binary forms, with or without
7*22ce4affSfengbojiang  * modification, are permitted provided that the following conditions
8*22ce4affSfengbojiang  * are met:
9*22ce4affSfengbojiang  * 1. Redistributions of source code must retain the above copyright
10*22ce4affSfengbojiang  *    notice, this list of conditions and the following disclaimer.
11*22ce4affSfengbojiang  * 2. Redistributions in binary form must reproduce the above copyright
12*22ce4affSfengbojiang  *    notice, this list of conditions and the following disclaimer in the
13*22ce4affSfengbojiang  *    documentation and/or other materials provided with the distribution.
14*22ce4affSfengbojiang  *
15*22ce4affSfengbojiang  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16*22ce4affSfengbojiang  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17*22ce4affSfengbojiang  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18*22ce4affSfengbojiang  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19*22ce4affSfengbojiang  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20*22ce4affSfengbojiang  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21*22ce4affSfengbojiang  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22*22ce4affSfengbojiang  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23*22ce4affSfengbojiang  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24*22ce4affSfengbojiang  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25*22ce4affSfengbojiang  * SUCH DAMAGE.
26*22ce4affSfengbojiang  *
27*22ce4affSfengbojiang  * $FreeBSD$
28*22ce4affSfengbojiang  */
29*22ce4affSfengbojiang 
30*22ce4affSfengbojiang #pragma once
31*22ce4affSfengbojiang 
32*22ce4affSfengbojiang #ifndef DEBUGNET_INTERNAL
33*22ce4affSfengbojiang #error "Don't include this"
34*22ce4affSfengbojiang #endif
35*22ce4affSfengbojiang 
36*22ce4affSfengbojiang #define	DNETDEBUG(f, ...) do {						\
37*22ce4affSfengbojiang 	if (debugnet_debug > 0)						\
38*22ce4affSfengbojiang 		printf(("%s: " f), __func__, ## __VA_ARGS__);		\
39*22ce4affSfengbojiang } while (0)
40*22ce4affSfengbojiang #define	DNETDEBUG_IF(i, f, ...) do {					\
41*22ce4affSfengbojiang 	if (debugnet_debug > 0)						\
42*22ce4affSfengbojiang 		if_printf((i), ("%s: " f), __func__, ## __VA_ARGS__);	\
43*22ce4affSfengbojiang } while (0)
44*22ce4affSfengbojiang #define	DNETDEBUGV(f, ...) do {						\
45*22ce4affSfengbojiang 	if (debugnet_debug > 1)						\
46*22ce4affSfengbojiang 		printf(("%s: " f), __func__, ## __VA_ARGS__);		\
47*22ce4affSfengbojiang } while (0)
48*22ce4affSfengbojiang 
49*22ce4affSfengbojiang enum dnet_pcb_st {
50*22ce4affSfengbojiang 	DN_STATE_INIT = 1,
51*22ce4affSfengbojiang 	DN_STATE_HAVE_GW_MAC,
52*22ce4affSfengbojiang 	DN_STATE_GOT_HERALD_PORT,
53*22ce4affSfengbojiang 	DN_STATE_REMOTE_CLOSED,
54*22ce4affSfengbojiang };
55*22ce4affSfengbojiang 
56*22ce4affSfengbojiang struct debugnet_pcb {
57*22ce4affSfengbojiang 	uint64_t		dp_rcvd_acks;
58*22ce4affSfengbojiang 
59*22ce4affSfengbojiang 	in_addr_t		dp_client;
60*22ce4affSfengbojiang 	in_addr_t		dp_server;
61*22ce4affSfengbojiang 	in_addr_t		dp_gateway;
62*22ce4affSfengbojiang 	uint32_t		dp_seqno;
63*22ce4affSfengbojiang 
64*22ce4affSfengbojiang 	struct ether_addr	dp_gw_mac;
65*22ce4affSfengbojiang 	uint16_t		dp_server_port;
66*22ce4affSfengbojiang 
67*22ce4affSfengbojiang 	struct ifnet		*dp_ifp;
68*22ce4affSfengbojiang 	/* Saved driver if_input to restore on close. */
69*22ce4affSfengbojiang 	void			(*dp_drv_input)(struct ifnet *, struct mbuf *);
70*22ce4affSfengbojiang 
71*22ce4affSfengbojiang 	/* RX handler for bidirectional protocols. */
72*22ce4affSfengbojiang 	void			(*dp_rx_handler)(struct debugnet_pcb *,
73*22ce4affSfengbojiang 				    struct mbuf **);
74*22ce4affSfengbojiang 
75*22ce4affSfengbojiang 	enum dnet_pcb_st	dp_state;
76*22ce4affSfengbojiang 	uint16_t		dp_client_port;
77*22ce4affSfengbojiang 	bool			dp_event_started;
78*22ce4affSfengbojiang };
79*22ce4affSfengbojiang 
80*22ce4affSfengbojiang /* TODO(CEM): Obviate this assertion by using a BITSET(9) for acks. */
81*22ce4affSfengbojiang CTASSERT(sizeof(((struct debugnet_pcb *)0)->dp_rcvd_acks) * NBBY >=
82*22ce4affSfengbojiang     DEBUGNET_MAX_IN_FLIGHT);
83*22ce4affSfengbojiang 
84*22ce4affSfengbojiang extern unsigned debugnet_debug;
85*22ce4affSfengbojiang SYSCTL_DECL(_net_debugnet);
86*22ce4affSfengbojiang 
87*22ce4affSfengbojiang int debugnet_ether_output(struct mbuf *, struct ifnet *, struct ether_addr,
88*22ce4affSfengbojiang     u_short);
89*22ce4affSfengbojiang void debugnet_handle_udp(struct debugnet_pcb *, struct mbuf **);
90*22ce4affSfengbojiang 
91*22ce4affSfengbojiang #ifdef INET
92*22ce4affSfengbojiang int debugnet_arp_gw(struct debugnet_pcb *);
93*22ce4affSfengbojiang void debugnet_handle_arp(struct debugnet_pcb *, struct mbuf **);
94*22ce4affSfengbojiang void debugnet_handle_ip(struct debugnet_pcb *, struct mbuf **);
95*22ce4affSfengbojiang int debugnet_ip_output(struct debugnet_pcb *, struct mbuf *);
96*22ce4affSfengbojiang #endif
97