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 287790c8c1SConrad Meyer #pragma once 297790c8c1SConrad Meyer 307790c8c1SConrad Meyer #ifndef DEBUGNET_INTERNAL 317790c8c1SConrad Meyer #error "Don't include this" 327790c8c1SConrad Meyer #endif 337790c8c1SConrad Meyer 347790c8c1SConrad Meyer #define DNETDEBUG(f, ...) do { \ 357790c8c1SConrad Meyer if (debugnet_debug > 0) \ 367790c8c1SConrad Meyer printf(("%s: " f), __func__, ## __VA_ARGS__); \ 377790c8c1SConrad Meyer } while (0) 387790c8c1SConrad Meyer #define DNETDEBUG_IF(i, f, ...) do { \ 397790c8c1SConrad Meyer if (debugnet_debug > 0) \ 407790c8c1SConrad Meyer if_printf((i), ("%s: " f), __func__, ## __VA_ARGS__); \ 417790c8c1SConrad Meyer } while (0) 427790c8c1SConrad Meyer #define DNETDEBUGV(f, ...) do { \ 437790c8c1SConrad Meyer if (debugnet_debug > 1) \ 447790c8c1SConrad Meyer printf(("%s: " f), __func__, ## __VA_ARGS__); \ 457790c8c1SConrad Meyer } while (0) 467790c8c1SConrad Meyer 477790c8c1SConrad Meyer enum dnet_pcb_st { 487790c8c1SConrad Meyer DN_STATE_INIT = 1, 497790c8c1SConrad Meyer DN_STATE_HAVE_GW_MAC, 507790c8c1SConrad Meyer DN_STATE_GOT_HERALD_PORT, 51e9c69625SConrad Meyer DN_STATE_REMOTE_CLOSED, 527790c8c1SConrad Meyer }; 537790c8c1SConrad Meyer 547790c8c1SConrad Meyer struct debugnet_pcb { 557790c8c1SConrad Meyer uint64_t dp_rcvd_acks; 567790c8c1SConrad Meyer 577790c8c1SConrad Meyer in_addr_t dp_client; 587790c8c1SConrad Meyer in_addr_t dp_server; 597790c8c1SConrad Meyer in_addr_t dp_gateway; 607790c8c1SConrad Meyer uint32_t dp_seqno; 617790c8c1SConrad Meyer 627790c8c1SConrad Meyer struct ether_addr dp_gw_mac; 637790c8c1SConrad Meyer uint16_t dp_server_port; 647790c8c1SConrad Meyer 657790c8c1SConrad Meyer struct ifnet *dp_ifp; 667790c8c1SConrad Meyer /* Saved driver if_input to restore on close. */ 677790c8c1SConrad Meyer void (*dp_drv_input)(struct ifnet *, struct mbuf *); 687790c8c1SConrad Meyer 69e9c69625SConrad Meyer /* RX handler for bidirectional protocols. */ 70*b498331bSJohn Reimer int (*dp_rx_handler)(struct mbuf *); 71*b498331bSJohn Reimer 72*b498331bSJohn Reimer /* Cleanup signal for bidirectional protocols. */ 73*b498331bSJohn Reimer void (*dp_finish_handler)(void); 74e9c69625SConrad Meyer 757790c8c1SConrad Meyer enum dnet_pcb_st dp_state; 76e9c69625SConrad Meyer uint16_t dp_client_port; 77fde2cf65SConrad Meyer bool dp_event_started; 787790c8c1SConrad Meyer }; 797790c8c1SConrad Meyer 807790c8c1SConrad Meyer /* TODO(CEM): Obviate this assertion by using a BITSET(9) for acks. */ 817790c8c1SConrad Meyer CTASSERT(sizeof(((struct debugnet_pcb *)0)->dp_rcvd_acks) * NBBY >= 827790c8c1SConrad Meyer DEBUGNET_MAX_IN_FLIGHT); 837790c8c1SConrad Meyer 847790c8c1SConrad Meyer extern unsigned debugnet_debug; 857790c8c1SConrad Meyer SYSCTL_DECL(_net_debugnet); 867790c8c1SConrad Meyer 877790c8c1SConrad Meyer int debugnet_ether_output(struct mbuf *, struct ifnet *, struct ether_addr, 887790c8c1SConrad Meyer u_short); 897790c8c1SConrad Meyer void debugnet_handle_udp(struct debugnet_pcb *, struct mbuf **); 907790c8c1SConrad Meyer 917790c8c1SConrad Meyer #ifdef INET 927790c8c1SConrad Meyer int debugnet_arp_gw(struct debugnet_pcb *); 937790c8c1SConrad Meyer void debugnet_handle_arp(struct debugnet_pcb *, struct mbuf **); 947790c8c1SConrad Meyer void debugnet_handle_ip(struct debugnet_pcb *, struct mbuf **); 957790c8c1SConrad Meyer int debugnet_ip_output(struct debugnet_pcb *, struct mbuf *); 967790c8c1SConrad Meyer #endif 97