/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2019 Isilon Systems, LLC.4*5* Redistribution and use in source and binary forms, with or without6* modification, are permitted provided that the following conditions7* are met:8* 1. Redistributions of source code must retain the above copyright9* notice, this list of conditions and the following disclaimer.10* 2. Redistributions in binary form must reproduce the above copyright11* notice, this list of conditions and the following disclaimer in the12* documentation and/or other materials provided with the distribution.13*14* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND15* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE16* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE17* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE18* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL19* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS20* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)21* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT22* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY23* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF24* SUCH DAMAGE.25*/2627#pragma once2829#ifndef DEBUGNET_INTERNAL30#error "Don't include this"31#endif3233#define DNETDEBUG(f, ...) do { \34if (debugnet_debug > 0) \35printf(("%s: " f), __func__, ## __VA_ARGS__); \36} while (0)37#define DNETDEBUG_IF(i, f, ...) do { \38if (debugnet_debug > 0) \39if_printf((i), ("%s: " f), __func__, ## __VA_ARGS__); \40} while (0)41#define DNETDEBUGV(f, ...) do { \42if (debugnet_debug > 1) \43printf(("%s: " f), __func__, ## __VA_ARGS__); \44} while (0)4546enum dnet_pcb_st {47DN_STATE_INIT = 1,48DN_STATE_HAVE_GW_MAC,49DN_STATE_GOT_HERALD_PORT,50DN_STATE_REMOTE_CLOSED,51};5253struct debugnet_pcb {54uint64_t dp_rcvd_acks;5556in_addr_t dp_client;57in_addr_t dp_server;58in_addr_t dp_gateway;59uint32_t dp_seqno;6061struct ether_addr dp_gw_mac;62uint16_t dp_server_port;6364struct ifnet *dp_ifp;65/* Saved driver if_input to restore on close. */66void (*dp_drv_input)(struct ifnet *, struct mbuf *);6768/* RX handler for bidirectional protocols. */69int (*dp_rx_handler)(struct mbuf *);7071/* Cleanup signal for bidirectional protocols. */72void (*dp_finish_handler)(void);7374enum dnet_pcb_st dp_state;75uint16_t dp_client_port;76bool dp_event_started;77};7879/* TODO(CEM): Obviate this assertion by using a BITSET(9) for acks. */80CTASSERT(sizeof(((struct debugnet_pcb *)0)->dp_rcvd_acks) * NBBY >=81DEBUGNET_MAX_IN_FLIGHT);8283extern unsigned debugnet_debug;84SYSCTL_DECL(_net_debugnet);8586int debugnet_ether_output(struct mbuf *, struct ifnet *, struct ether_addr,87u_short);88void debugnet_handle_udp(struct debugnet_pcb *, struct mbuf **);8990#ifdef INET91int debugnet_arp_gw(struct debugnet_pcb *);92void debugnet_handle_arp(struct debugnet_pcb *, struct mbuf **);93void debugnet_handle_ip(struct debugnet_pcb *, struct mbuf **);94int debugnet_ip_output(struct debugnet_pcb *, struct mbuf *);95#endif969798