debugnet_int.h 3.1 KB

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