FreeBSD kernel IPv4 code
netdump_client.c File Reference
#include <sys/cdefs.h>
#include "opt_ddb.h"
#include <sys/param.h>
#include <sys/conf.h>
#include <sys/disk.h>
#include <sys/endian.h>
#include <sys/eventhandler.h>
#include <sys/jail.h>
#include <sys/kernel.h>
#include <sys/kerneldump.h>
#include <sys/mbuf.h>
#include <sys/module.h>
#include <sys/priv.h>
#include <sys/proc.h>
#include <sys/protosw.h>
#include <sys/socket.h>
#include <sys/sysctl.h>
#include <sys/syslog.h>
#include <sys/systm.h>
#include <net/ethernet.h>
#include <net/if.h>
#include <net/if_arp.h>
#include <net/if_dl.h>
#include <net/if_types.h>
#include <net/if_var.h>
#include <net/debugnet.h>
#include <netinet/in.h>
#include <netinet/in_systm.h>
#include <netinet/in_var.h>
#include <netinet/ip.h>
#include <netinet/ip_var.h>
#include <netinet/ip_options.h>
#include <netinet/udp.h>
#include <netinet/udp_var.h>
#include <netinet/netdump/netdump.h>
#include <machine/in_cksum.h>
#include <machine/pcb.h>
Include dependency graph for netdump_client.c:

Go to the source code of this file.

Macros

#define NETDDEBUGV(f, ...)
 
#define nd_server   nd_conf.ndc_server.in4
 
#define nd_client   nd_conf.ndc_client.in4
 
#define nd_gateway   nd_conf.ndc_gateway.in4
 
#define NETDUMP_WLOCK()   sx_xlock(&nd_conf_lk)
 
#define NETDUMP_WUNLOCK()   sx_xunlock(&nd_conf_lk)
 
#define NETDUMP_RLOCK()   sx_slock(&nd_conf_lk)
 
#define NETDUMP_RUNLOCK()   sx_sunlock(&nd_conf_lk)
 
#define NETDUMP_ASSERT_WLOCKED()   sx_assert(&nd_conf_lk, SA_XLOCKED)
 
#define NETDUMP_ASSERT_LOCKED()   sx_assert(&nd_conf_lk, SA_LOCKED)
 
#define COPY_SIZED(elm)
 

Functions

 __FBSDID ("$FreeBSD$")
 
static void netdump_cleanup (void)
 
static int netdump_configure (struct diocskerneldump_arg *, struct thread *)
 
static int netdump_dumper (void *priv __unused, void *virtual, vm_offset_t physical __unused, off_t offset, size_t length)
 
static bool netdump_enabled (void)
 
static int netdump_enabled_sysctl (SYSCTL_HANDLER_ARGS)
 
static int netdump_ioctl (struct cdev *dev __unused, u_long cmd, caddr_t addr, int flags __unused, struct thread *td)
 
static int netdump_modevent (module_t mod, int type, void *priv)
 
static int netdump_start (struct dumperinfo *di, void *key, uint32_t keysize)
 
static void netdump_unconfigure (void)
 
 SX_SYSINIT (nd_conf, &nd_conf_lk, "netdump configuration lock")
 
 FEATURE (netdump, "Netdump client support")
 
static SYSCTL_NODE (_net, OID_AUTO, netdump, CTLFLAG_RD|CTLFLAG_MPSAFE, NULL, "netdump parameters")
 
 SYSCTL_INT (_net_netdump, OID_AUTO, debug, CTLFLAG_RWTUN, &nd_debug, 0, "Debug message verbosity")
 
 SYSCTL_PROC (_net_netdump, OID_AUTO, enabled, CTLFLAG_RD|CTLTYPE_INT|CTLFLAG_MPSAFE, NULL, 0, netdump_enabled_sysctl, "I", "netdump configuration status")
 
 SYSCTL_STRING (_net_netdump, OID_AUTO, path, CTLFLAG_RW, nd_path, sizeof(nd_path), "Server path for output files")
 
 SYSCTL_INT (_net_netdump, OID_AUTO, polls, CTLFLAG_RWTUN, &debugnet_npolls, 0, "Number of times to poll before assuming packet loss (0.5ms per poll)")
 
 SYSCTL_INT (_net_netdump, OID_AUTO, retries, CTLFLAG_RWTUN, &debugnet_nretries, 0, "Number of retransmit attempts before giving up")
 
 SYSCTL_INT (_net_netdump, OID_AUTO, arp_retries, CTLFLAG_RWTUN, &debugnet_arp_nretries, 0, "Number of ARP attempts before giving up")
 
static void netdump_set_enabled (bool status)
 
static int netdump_flush_buf (void)
 
static int netdump_write_headers (struct dumperinfo *di, struct kerneldumpheader *kdh)
 
static void netdump_ifdetach (void *arg __unused, struct ifnet *ifp)
 
static int netdump_modevent (module_t mod __unused, int what, void *priv __unused)
 
 MODULE_VERSION (netdump, 1)
 
 DECLARE_MODULE (netdump, netdump_mod, SI_SUB_PSEUDO, SI_ORDER_ANY)
 

Variables

static unsigned char nd_buf [MAXDUMPPGS *PAGE_SIZE]
 
static int dump_failed
 
struct {
   char   ndc_iface [IFNAMSIZ]
 
   union kd_ip   ndc_server
 
   union kd_ip   ndc_client
 
   union kd_ip   ndc_gateway
 
   uint8_t   ndc_af
 
   struct debugnet_pcb *   nd_pcb
 
   off_t   nd_tx_off
 
   size_t   nd_buf_len
 
nd_conf
 
static struct sx nd_conf_lk
 
static struct ifnet * nd_ifp
 
static eventhandler_tag nd_detach_cookie
 
static int nd_debug
 
static char nd_path [MAXPATHLEN]
 
static bool nd_is_enabled
 
static struct cdevsw netdump_cdevsw
 
static struct cdev * netdump_cdev
 
static moduledata_t netdump_mod
 

Macro Definition Documentation

◆ COPY_SIZED

#define COPY_SIZED (   elm)
Value:
do { \
_Static_assert(sizeof(nd_conf.ndc_ ## elm) == \
sizeof(conf->kda_ ## elm), "elm " __XSTRING(elm) " mismatch"); \
memcpy(&nd_conf.ndc_ ## elm, &conf->kda_ ## elm, \
sizeof(nd_conf.ndc_ ## elm)); \
} while (0)
static struct @31 nd_conf

◆ nd_client

#define nd_client   nd_conf.ndc_client.in4

Definition at line 119 of file netdump_client.c.

◆ nd_gateway

#define nd_gateway   nd_conf.ndc_gateway.in4

Definition at line 120 of file netdump_client.c.

◆ nd_server

#define nd_server   nd_conf.ndc_server.in4

Definition at line 118 of file netdump_client.c.

◆ NETDDEBUGV

#define NETDDEBUGV (   f,
  ... 
)
Value:
do { \
if (nd_debug > 1) \
printf(("%s: " f), __func__, ## __VA_ARGS__); \
} while (0)
static int nd_debug

Definition at line 83 of file netdump_client.c.

◆ NETDUMP_ASSERT_LOCKED

#define NETDUMP_ASSERT_LOCKED ( )    sx_assert(&nd_conf_lk, SA_LOCKED)

Definition at line 130 of file netdump_client.c.

◆ NETDUMP_ASSERT_WLOCKED

#define NETDUMP_ASSERT_WLOCKED ( )    sx_assert(&nd_conf_lk, SA_XLOCKED)

Definition at line 129 of file netdump_client.c.

◆ NETDUMP_RLOCK

#define NETDUMP_RLOCK ( )    sx_slock(&nd_conf_lk)

Definition at line 127 of file netdump_client.c.

◆ NETDUMP_RUNLOCK

#define NETDUMP_RUNLOCK ( )    sx_sunlock(&nd_conf_lk)

Definition at line 128 of file netdump_client.c.

◆ NETDUMP_WLOCK

#define NETDUMP_WLOCK ( )    sx_xlock(&nd_conf_lk)

Definition at line 125 of file netdump_client.c.

◆ NETDUMP_WUNLOCK

#define NETDUMP_WUNLOCK ( )    sx_xunlock(&nd_conf_lk)

Definition at line 126 of file netdump_client.c.

Function Documentation

◆ __FBSDID()

__FBSDID ( "$FreeBSD$"  )

◆ DECLARE_MODULE()

DECLARE_MODULE ( netdump  ,
netdump_mod  ,
SI_SUB_PSEUDO  ,
SI_ORDER_ANY   
)

◆ FEATURE()

FEATURE ( netdump  ,
"Netdump client support"   
)

◆ MODULE_VERSION()

MODULE_VERSION ( netdump  ,
 
)

◆ netdump_cleanup()

static void netdump_cleanup ( void  )
static

Definition at line 387 of file netdump_client.c.

References nd_conf.

Referenced by netdump_dumper(), netdump_start(), and netdump_write_headers().

Here is the caller graph for this function:

◆ netdump_configure()

static int netdump_configure ( struct diocskerneldump_arg *  conf,
struct thread *  td 
)
static

Definition at line 445 of file netdump_client.c.

References COPY_SIZED, nd_ifp, NETDUMP_ASSERT_WLOCKED, and netdump_set_enabled().

Referenced by netdump_ioctl(), and netdump_modevent().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ netdump_dumper()

static int netdump_dumper ( void *priv  __unused,
void *  virtual,
vm_offset_t physical  __unused,
off_t  offset,
size_t  length 
)
static

Definition at line 239 of file netdump_client.c.

References dump_failed, nd_buf, nd_conf, NETDDEBUGV, netdump_cleanup(), and netdump_flush_buf().

Referenced by netdump_ioctl().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ netdump_enabled()

static bool netdump_enabled ( void  )
static

Definition at line 167 of file netdump_client.c.

References nd_is_enabled, and NETDUMP_ASSERT_LOCKED.

Referenced by netdump_enabled_sysctl(), netdump_ioctl(), netdump_modevent(), netdump_start(), and netdump_unconfigure().

Here is the caller graph for this function:

◆ netdump_enabled_sysctl()

static int netdump_enabled_sysctl ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 183 of file netdump_client.c.

References netdump_enabled(), NETDUMP_RLOCK, and NETDUMP_RUNLOCK.

Here is the call graph for this function:

◆ netdump_flush_buf()

static int netdump_flush_buf ( void  )
static

Definition at line 205 of file netdump_client.c.

References nd_buf, and nd_conf.

Referenced by netdump_dumper(), and netdump_write_headers().

Here is the caller graph for this function:

◆ netdump_ifdetach()

static void netdump_ifdetach ( void *arg  __unused,
struct ifnet *  ifp 
)
static

Definition at line 431 of file netdump_client.c.

References nd_ifp, netdump_unconfigure(), NETDUMP_WLOCK, and NETDUMP_WUNLOCK.

Referenced by netdump_modevent().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ netdump_ioctl()

◆ netdump_modevent() [1/2]

static int netdump_modevent ( module_t mod  __unused,
int  what,
void *priv  __unused 
)
static

◆ netdump_modevent() [2/2]

static int netdump_modevent ( module_t  mod,
int  type,
void *  priv 
)
static

◆ netdump_set_enabled()

static void netdump_set_enabled ( bool  status)
static

Definition at line 175 of file netdump_client.c.

References nd_is_enabled, and NETDUMP_ASSERT_LOCKED.

Referenced by netdump_configure(), and netdump_unconfigure().

Here is the caller graph for this function:

◆ netdump_start()

static int netdump_start ( struct dumperinfo *  di,
void *  key,
uint32_t  keysize 
)
static

Definition at line 289 of file netdump_client.c.

References INADDR_ANY, inet_ntoa_r(), nd_buf, nd_client, nd_conf, nd_gateway, nd_ifp, nd_path, nd_server, NETDUMP_ACKPORT, netdump_cleanup(), NETDUMP_EKCD_KEY, netdump_enabled(), and NETDUMP_PORT.

Referenced by netdump_ioctl().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ netdump_unconfigure()

static void netdump_unconfigure ( void  )
static

Definition at line 408 of file netdump_client.c.

References nd_conf, nd_ifp, NETDUMP_ASSERT_WLOCKED, netdump_enabled(), and netdump_set_enabled().

Referenced by netdump_ifdetach(), netdump_ioctl(), and netdump_modevent().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ netdump_write_headers()

static int netdump_write_headers ( struct dumperinfo *  di,
struct kerneldumpheader *  kdh 
)
static

Definition at line 367 of file netdump_client.c.

References nd_buf, nd_conf, netdump_cleanup(), netdump_flush_buf(), and NETDUMP_KDH.

Referenced by netdump_ioctl().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SX_SYSINIT()

SX_SYSINIT ( nd_conf  ,
nd_conf_lk,
"netdump configuration lock"   
)

◆ SYSCTL_INT() [1/4]

SYSCTL_INT ( _net_netdump  ,
OID_AUTO  ,
arp_retries  ,
CTLFLAG_RWTUN  ,
debugnet_arp_nretries,
,
"Number of ARP attempts before giving up"   
)

◆ SYSCTL_INT() [2/4]

SYSCTL_INT ( _net_netdump  ,
OID_AUTO  ,
debug  ,
CTLFLAG_RWTUN  ,
nd_debug,
,
"Debug message verbosity"   
)

◆ SYSCTL_INT() [3/4]

SYSCTL_INT ( _net_netdump  ,
OID_AUTO  ,
polls  ,
CTLFLAG_RWTUN  ,
debugnet_npolls,
,
"Number of times to poll before assuming packet loss (0.5ms per poll)"   
)

◆ SYSCTL_INT() [4/4]

SYSCTL_INT ( _net_netdump  ,
OID_AUTO  ,
retries  ,
CTLFLAG_RWTUN  ,
debugnet_nretries,
,
"Number of retransmit attempts before giving up"   
)

◆ SYSCTL_NODE()

static SYSCTL_NODE ( _net  ,
OID_AUTO  ,
netdump  ,
CTLFLAG_RD|  CTLFLAG_MPSAFE,
NULL  ,
"netdump parameters"   
)
static

◆ SYSCTL_PROC()

SYSCTL_PROC ( _net_netdump  ,
OID_AUTO  ,
enabled  ,
CTLFLAG_RD|CTLTYPE_INT|  CTLFLAG_MPSAFE,
NULL  ,
,
netdump_enabled_sysctl  ,
"I"  ,
"netdump configuration status"   
)

◆ SYSCTL_STRING()

SYSCTL_STRING ( _net_netdump  ,
OID_AUTO  ,
path  ,
CTLFLAG_RW  ,
nd_path  ,
sizeof(nd_path ,
"Server path for output files"   
)

Variable Documentation

◆ dump_failed

int dump_failed
static

Definition at line 104 of file netdump_client.c.

Referenced by netdump_dumper().

◆ nd_buf

unsigned char nd_buf[MAXDUMPPGS *PAGE_SIZE]
static

◆ nd_buf_len

size_t nd_buf_len

Definition at line 116 of file netdump_client.c.

◆ 

◆ nd_conf_lk

struct sx nd_conf_lk
static

Definition at line 123 of file netdump_client.c.

◆ nd_debug

int nd_debug
static

Definition at line 139 of file netdump_client.c.

◆ nd_detach_cookie

eventhandler_tag nd_detach_cookie
static

Definition at line 132 of file netdump_client.c.

Referenced by netdump_modevent().

◆ nd_ifp

struct ifnet* nd_ifp
static

◆ nd_is_enabled

bool nd_is_enabled
static

Definition at line 165 of file netdump_client.c.

Referenced by netdump_enabled(), and netdump_set_enabled().

◆ nd_path

char nd_path[MAXPATHLEN]
static

Definition at line 147 of file netdump_client.c.

Referenced by netdump_start().

◆ nd_pcb

struct debugnet_pcb* nd_pcb

Definition at line 114 of file netdump_client.c.

◆ nd_tx_off

off_t nd_tx_off

Definition at line 115 of file netdump_client.c.

◆ ndc_af

uint8_t ndc_af

Definition at line 112 of file netdump_client.c.

◆ ndc_client

union kd_ip ndc_client

Definition at line 110 of file netdump_client.c.

◆ ndc_gateway

union kd_ip ndc_gateway

Definition at line 111 of file netdump_client.c.

◆ ndc_iface

char ndc_iface[IFNAMSIZ]

Definition at line 108 of file netdump_client.c.

◆ ndc_server

union kd_ip ndc_server

Definition at line 109 of file netdump_client.c.

◆ netdump_cdev

struct cdev* netdump_cdev
static

Definition at line 405 of file netdump_client.c.

Referenced by netdump_modevent().

◆ netdump_cdevsw

struct cdevsw netdump_cdevsw
static
Initial value:
= {
.d_version = D_VERSION,
.d_ioctl = netdump_ioctl,
.d_name = "netdump",
}
static int netdump_ioctl(struct cdev *dev __unused, u_long cmd, caddr_t addr, int flags __unused, struct thread *td)

Definition at line 399 of file netdump_client.c.

Referenced by netdump_modevent().

◆ netdump_mod

moduledata_t netdump_mod
static
Initial value:
= {
"netdump",
NULL,
}
static int netdump_modevent(module_t mod, int type, void *priv)

Definition at line 767 of file netdump_client.c.