Index: head/sbin/dumpon/dumpon.8 =================================================================== --- head/sbin/dumpon/dumpon.8 (revision 340546) +++ head/sbin/dumpon/dumpon.8 (revision 340547) @@ -1,374 +1,375 @@ .\" Copyright (c) 1980, 1991, 1993 .\" The Regents of the University of California. All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" From: @(#)swapon.8 8.1 (Berkeley) 6/5/93 .\" $FreeBSD$ .\" -.Dd October 26, 2018 +.Dd November 17, 2018 .Dt DUMPON 8 .Os .Sh NAME .Nm dumpon .Nd "specify a device for crash dumps" .Sh SYNOPSIS .Nm .Op Fl v .Op Fl k Ar pubkey .Op Fl Z .Op Fl z .Ar device .Nm .Op Fl v .Op Fl k Ar pubkey .Op Fl Z .Op Fl z -.Op Fl g Ar gateway | Li default +.Op Fl g Ar gateway .Fl s Ar server .Fl c Ar client .Ar iface .Nm .Op Fl v .Cm off .Nm .Op Fl v .Fl l .Sh DESCRIPTION The .Nm utility is used to configure where the kernel can save a crash dump in the case of a panic. .Pp System administrators should typically configure .Nm in a persistent fashion using the .Xr rc.conf 5 variables .Va dumpdev and .Va dumpon_flags . For more information on this usage, see .Xr rc.conf 5 . .Ss General options .Bl -tag -width _k_pubkey .It Fl k Ar pubkey Configure encrypted kernel dumps. .Pp A random, one-time symmetric key is automatically generated for bulk kernel dump encryption every time .Nm is used. The provided .Ar pubkey is used to encrypt a copy of the symmetric key. The encrypted dump contents consist of a standard dump header, the pubkey-encrypted symmetric key contents, and the symmetric key encrypted core dump contents. .Pp As a result, only someone with the corresponding private key can decrypt the symmetric key. The symmetric key is necessary to decrypt the kernel core. The goal of the mechanism is to provide confidentiality. .Pp The .Va pubkey file should be a PEM-formatted RSA key of at least 1024 bits. .It Fl l List the currently configured dump device, or /dev/null if no device is configured. .It Fl v Enable verbose mode. .It Fl Z Enable compression (Zstandard). .It Fl z Enable compression (gzip). Only one compression method may be enabled at a time, so .Fl z is incompatible with .Fl Z . .Pp Zstandard provides superior compression ratio and performance. .El .Ss Netdump .Nm may also configure the kernel to dump to a remote .Xr netdumpd 8 server. (The .Xr netdumpd 8 server is available in ports.) .Xr netdump 4 eliminates the need to reserve space for crash dumps. It is especially useful in diskless environments. When .Nm is used to configure netdump, the .Ar device (or .Ar iface ) parameter should specify a network interface (e.g., .Va igb1 ) . The specified NIC must be up (online) to configure netdump. .Pp .Xr netdump 4 specific options include: .Bl -tag -width _g_gateway .It Fl c Ar client The local IP address of the .Xr netdump 4 client. .It Fl g Ar gateway -Optional. -If not specified, it is assumed that the -.Ar server -is on the same link as the -.Ar client . -.Pp -If specified, -.Ar gateway -is the address of the first-hop router between the +The first-hop router between .Ar client -and the +and .Ar server . -The special value -.Dv Dq default -indicates that the currently configured system default route should be used. +If the +.Fl g +option is not specified and the system has a default route, the default +router is used as the +.Xr netdump 4 +gateway. +If the +.Fl g +option is not specified and the system does not have a default route, +.Ar server +is assumed to be on the same link as +.Ar client . .It Fl s Ar server The IP address of the .Xr netdumpd 8 server. .El .Pp All of these options can be specified in the .Xr rc.conf 5 variable .Va dumpon_flags . .Ss Minidumps The default type of kernel crash dump is the mini crash dump. Mini crash dumps hold only memory pages in use by the kernel. Alternatively, full memory dumps can be enabled by setting the .Va debug.minidump .Xr sysctl 8 variable to 0. .Ss Full dumps For systems using full memory dumps, the size of the specified dump device must be at least the size of physical memory. Even though an additional 64 kB header is added to the dump, the BIOS for a platform typically holds back some memory, so it is not usually necessary to size the dump device larger than the actual amount of RAM available in the machine. Also, when using full memory dumps, the .Nm utility will refuse to enable a dump device which is smaller than the total amount of physical memory as reported by the .Va hw.physmem .Xr sysctl 8 variable. .Sh IMPLEMENTATION NOTES Because the file system layer is already dead by the time a crash dump is taken, it is not possible to send crash dumps directly to a file. .Pp The .Xr loader 8 variable .Va dumpdev may be used to enable early kernel core dumps for system panics which occur before userspace starts. .Sh EXAMPLES In order to generate an RSA private key, a user can use the .Xr genrsa 1 tool: .Pp .Dl # openssl genrsa -out private.pem 4096 .Pp A public key can be extracted from the private key using the .Xr rsa 1 tool: .Pp .Dl # openssl rsa -in private.pem -out public.pem -pubout .Pp Once the RSA keys are created in a safe place, the public key may be moved to the untrusted netdump client machine. Now .Pa public.pem can be used by .Nm to configure encrypted kernel crash dumps: .Pp .Dl # dumpon -k public.pem /dev/ada0s1b .Pp It is recommended to test if the kernel saves encrypted crash dumps using the current configuration. The easiest way to do that is to cause a kernel panic using the .Xr ddb 4 debugger: .Pp .Dl # sysctl debug.kdb.panic=1 .Pp In the debugger the following commands should be typed to write a core dump and reboot: .Pp .Dl db> call doadump(0) .Dl db> reset .Pp After reboot .Xr savecore 8 should be able to save the core dump in the .Va Dq dumpdir directory, which is .Pa /var/crash by default: .Pp .Dl # savecore /dev/ada0s1b .Pp Three files should be created in the core directory: .Pa info.# , .Pa key.# and .Pa vmcore_encrypted.# (where .Dq # is the number of the last core dump saved by .Xr savecore 8 ) . The .Pa vmcore_encrypted.# can be decrypted using the .Xr decryptcore 8 utility: .Pp .Dl # decryptcore -p private.pem -k key.# -e vmcore_encrypted.# -c vmcore.# .Pp or shorter: .Pp .Dl # decryptcore -p private.pem -n # .Pp The .Pa vmcore.# can be now examined using .Xr kgdb 1 : .Pp .Dl # kgdb /boot/kernel/kernel vmcore.# .Pp or shorter: .Pp .Dl # kgdb -n # .Pp The core was decrypted properly if .Xr kgdb 1 does not print any errors. Note that the live kernel might be at a different path which can be examined by looking at the .Va kern.bootfile .Xr sysctl 8 . .Sh SEE ALSO .Xr gzip 1 , .Xr kgdb 1 , .Xr zstd 1 , .Xr ddb 4 , .Xr netdump 4 , .Xr fstab 5 , .Xr rc.conf 5 , .Xr config 8 , .Xr decryptcore 8 , .Xr init 8 , .Xr loader 8 , .Xr rc 8 , .Xr savecore 8 , .Xr swapon 8 , .Xr panic 9 .Sh HISTORY The .Nm utility appeared in .Fx 2.0.5 . .Pp Support for encrypted kernel core dumps and netdump was added in .Fx 12.0 . .Sh AUTHORS The .Nm manual page was written by .An Mark Johnston Aq Mt markj@FreeBSD.org , .An Conrad Meyer Aq Mt cem@FreeBSD.org , .An Konrad Witaszczyk Aq Mt def@FreeBSD.org , and countless others. .Sh CAVEATS To configure encrypted kernel core dumps, the running kernel must have been compiled with the .Dv EKCD option. .Pp Netdump does not automatically update the configured .Ar gateway if routing topology changes. .Pp The size of a compressed dump or a minidump is not a fixed function of RAM size. Therefore, when at least one of these options is enabled, the .Nm utility cannot verify that the .Ar device has sufficient space for a dump. .Nm is also unable to verify that a configured .Xr netdumpd 8 server has sufficient space for a dump. .Pp .Fl Z requires a kernel compiled with the .Dv ZSTDIO kernel option. Similarly, .Fl z requires the .Dv GZIO option. .Sh BUGS It is currently not possible to configure both compression and encryption. The encrypted dump format assumes that the kernel dump size is a multiple of the cipher block size, which may not be true when the dump is compressed. .Pp Netdump only supports IPv4 at this time. .Sh SECURITY CONSIDERATIONS The current encrypted kernel core dump scheme does not provide integrity nor authentication. That is, the recipient of an encrypted kernel core dump cannot know if they received an intact core dump, nor can they verify the provenance of the dump. .Pp RSA keys smaller than 1024 bits are practical to factor and therefore weak. Even 1024 bit keys may not be large enough to ensure privacy for many years, so NIST recommends a minimum of 2048 bit RSA keys. As a seatbelt, .Nm prevents users from configuring encrypted kernel dumps with extremely weak RSA keys. If you do not care for cryptographic privacy guarantees, just use .Nm without specifying a .Fl k Ar pubkey option. .Pp This process is sandboxed using .Xr capsicum 4 . Index: head/sbin/dumpon/dumpon.c =================================================================== --- head/sbin/dumpon/dumpon.c (revision 340546) +++ head/sbin/dumpon/dumpon.c (revision 340547) @@ -1,520 +1,520 @@ /*- * SPDX-License-Identifier: BSD-3-Clause * * Copyright (c) 1980, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #if 0 #ifndef lint static const char copyright[] = "@(#) Copyright (c) 1980, 1993\n\ The Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ #ifndef lint static char sccsid[] = "From: @(#)swapon.c 8.1 (Berkeley) 6/5/93"; #endif /* not lint */ #endif #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef HAVE_CRYPTO #include #include #include #endif static int verbose; static void _Noreturn usage(void) { fprintf(stderr, "usage: dumpon [-v] [-k ] [-Zz] \n" " dumpon [-v] [-k ] [-Zz]\n" - " [-g |default] -s -c \n" + " [-g ] -s -c \n" " dumpon [-v] off\n" " dumpon [-v] -l\n"); exit(EX_USAGE); } /* * Look for a default route on the specified interface. */ static char * find_gateway(const char *ifname) { struct ifaddrs *ifa, *ifap; struct rt_msghdr *rtm; struct sockaddr *sa; struct sockaddr_dl *sdl; struct sockaddr_in *dst, *mask, *gw; char *buf, *next, *ret; size_t sz; int error, i, ifindex, mib[7]; - ret = NULL; - /* First look up the interface index. */ if (getifaddrs(&ifap) != 0) err(EX_OSERR, "getifaddrs"); for (ifa = ifap; ifa != NULL; ifa = ifa->ifa_next) { if (ifa->ifa_addr->sa_family != AF_LINK) continue; if (strcmp(ifa->ifa_name, ifname) == 0) { sdl = (struct sockaddr_dl *)(void *)ifa->ifa_addr; ifindex = sdl->sdl_index; break; } } if (ifa == NULL) errx(1, "couldn't find interface index for '%s'", ifname); freeifaddrs(ifap); /* Now get the IPv4 routing table. */ mib[0] = CTL_NET; mib[1] = PF_ROUTE; mib[2] = 0; mib[3] = AF_INET; mib[4] = NET_RT_DUMP; mib[5] = 0; mib[6] = -1; /* FIB */ for (;;) { if (sysctl(mib, nitems(mib), NULL, &sz, NULL, 0) != 0) err(EX_OSERR, "sysctl(NET_RT_DUMP)"); buf = malloc(sz); error = sysctl(mib, nitems(mib), buf, &sz, NULL, 0); if (error == 0) break; if (errno != ENOMEM) err(EX_OSERR, "sysctl(NET_RT_DUMP)"); free(buf); } + ret = NULL; for (next = buf; next < buf + sz; next += rtm->rtm_msglen) { rtm = (struct rt_msghdr *)(void *)next; if (rtm->rtm_version != RTM_VERSION) continue; if ((rtm->rtm_flags & RTF_GATEWAY) == 0 || rtm->rtm_index != ifindex) continue; dst = gw = mask = NULL; sa = (struct sockaddr *)(rtm + 1); for (i = 0; i < RTAX_MAX; i++) { if ((rtm->rtm_addrs & (1 << i)) != 0) { switch (i) { case RTAX_DST: dst = (void *)sa; break; case RTAX_GATEWAY: gw = (void *)sa; break; case RTAX_NETMASK: mask = (void *)sa; break; } } sa = (struct sockaddr *)((char *)sa + SA_SIZE(sa)); } if (dst->sin_addr.s_addr == INADDR_ANY && mask->sin_addr.s_addr == 0) { ret = inet_ntoa(gw->sin_addr); break; } } free(buf); return (ret); } static void check_size(int fd, const char *fn) { int name[] = { CTL_HW, HW_PHYSMEM }; size_t namelen = nitems(name); unsigned long physmem; size_t len; off_t mediasize; int minidump; len = sizeof(minidump); if (sysctlbyname("debug.minidump", &minidump, &len, NULL, 0) == 0 && minidump == 1) return; len = sizeof(physmem); if (sysctl(name, namelen, &physmem, &len, NULL, 0) != 0) err(EX_OSERR, "can't get memory size"); if (ioctl(fd, DIOCGMEDIASIZE, &mediasize) != 0) err(EX_OSERR, "%s: can't get size", fn); if ((uintmax_t)mediasize < (uintmax_t)physmem) { if (verbose) printf("%s is smaller than physical memory\n", fn); exit(EX_IOERR); } } #ifdef HAVE_CRYPTO static void genkey(const char *pubkeyfile, struct diocskerneldump_arg *kdap) { FILE *fp; RSA *pubkey; assert(pubkeyfile != NULL); assert(kdap != NULL); fp = NULL; pubkey = NULL; fp = fopen(pubkeyfile, "r"); if (fp == NULL) err(1, "Unable to open %s", pubkeyfile); if (caph_enter() < 0) err(1, "Unable to enter capability mode"); pubkey = RSA_new(); if (pubkey == NULL) { errx(1, "Unable to allocate an RSA structure: %s", ERR_error_string(ERR_get_error(), NULL)); } pubkey = PEM_read_RSA_PUBKEY(fp, &pubkey, NULL, NULL); fclose(fp); fp = NULL; if (pubkey == NULL) errx(1, "Unable to read data from %s.", pubkeyfile); /* * RSA keys under ~1024 bits are trivially factorable (2018). OpenSSL * provides an API for RSA keys to estimate the symmetric-cipher * "equivalent" bits of security (defined in NIST SP800-57), which as * of this writing equates a 2048-bit RSA key to 112 symmetric cipher * bits. * * Use this API as a seatbelt to avoid suggesting to users that their * privacy is protected by encryption when the key size is insufficient * to prevent compromise via factoring. * * Future work: Sanity check for weak 'e', and sanity check for absence * of 'd' (i.e., the supplied key is a public key rather than a full * keypair). */ #if OPENSSL_VERSION_NUMBER >= 0x10100000L if (RSA_security_bits(pubkey) < 112) #else if (RSA_size(pubkey) * 8 < 2048) #endif errx(1, "Small RSA keys (you provided: %db) can be " "factored cheaply. Please generate a larger key.", RSA_size(pubkey) * 8); kdap->kda_encryptedkeysize = RSA_size(pubkey); if (kdap->kda_encryptedkeysize > KERNELDUMP_ENCKEY_MAX_SIZE) { errx(1, "Public key has to be at most %db long.", 8 * KERNELDUMP_ENCKEY_MAX_SIZE); } kdap->kda_encryptedkey = calloc(1, kdap->kda_encryptedkeysize); if (kdap->kda_encryptedkey == NULL) err(1, "Unable to allocate encrypted key"); kdap->kda_encryption = KERNELDUMP_ENC_AES_256_CBC; arc4random_buf(kdap->kda_key, sizeof(kdap->kda_key)); if (RSA_public_encrypt(sizeof(kdap->kda_key), kdap->kda_key, kdap->kda_encryptedkey, pubkey, RSA_PKCS1_PADDING) != (int)kdap->kda_encryptedkeysize) { errx(1, "Unable to encrypt the one-time key."); } RSA_free(pubkey); } #endif static void listdumpdev(void) { char dumpdev[PATH_MAX]; struct netdump_conf ndconf; size_t len; const char *sysctlname = "kern.shutdown.dumpdevname"; int fd; len = sizeof(dumpdev); if (sysctlbyname(sysctlname, &dumpdev, &len, NULL, 0) != 0) { if (errno == ENOMEM) { err(EX_OSERR, "Kernel returned too large of a buffer for '%s'\n", sysctlname); } else { err(EX_OSERR, "Sysctl get '%s'\n", sysctlname); } } if (strlen(dumpdev) == 0) (void)strlcpy(dumpdev, _PATH_DEVNULL, sizeof(dumpdev)); if (verbose) printf("kernel dumps on "); printf("%s\n", dumpdev); /* If netdump is enabled, print the configuration parameters. */ if (verbose) { fd = open(_PATH_NETDUMP, O_RDONLY); if (fd < 0) { if (errno != ENOENT) err(EX_OSERR, "opening %s", _PATH_NETDUMP); return; } if (ioctl(fd, NETDUMPGCONF, &ndconf) != 0) { if (errno != ENXIO) err(EX_OSERR, "ioctl(NETDUMPGCONF)"); (void)close(fd); return; } printf("server address: %s\n", inet_ntoa(ndconf.ndc_server)); printf("client address: %s\n", inet_ntoa(ndconf.ndc_client)); printf("gateway address: %s\n", inet_ntoa(ndconf.ndc_gateway)); (void)close(fd); } } static int opendumpdev(const char *arg, char *dumpdev) { int fd, i; if (strncmp(arg, _PATH_DEV, sizeof(_PATH_DEV) - 1) == 0) strlcpy(dumpdev, arg, PATH_MAX); else { i = snprintf(dumpdev, PATH_MAX, "%s%s", _PATH_DEV, arg); if (i < 0) err(EX_OSERR, "%s", arg); if (i >= PATH_MAX) errc(EX_DATAERR, EINVAL, "%s", arg); } fd = open(dumpdev, O_RDONLY); if (fd < 0) err(EX_OSFILE, "%s", dumpdev); return (fd); } int main(int argc, char *argv[]) { char dumpdev[PATH_MAX]; struct diocskerneldump_arg _kda, *kdap; struct netdump_conf ndconf; struct addrinfo hints, *res; const char *dev, *pubkeyfile, *server, *client, *gateway; int ch, error, fd; bool enable, gzip, list, netdump, zstd; gzip = list = netdump = zstd = false; kdap = NULL; pubkeyfile = NULL; server = client = gateway = NULL; while ((ch = getopt(argc, argv, "c:g:k:ls:vZz")) != -1) switch ((char)ch) { case 'c': client = optarg; break; case 'g': gateway = optarg; break; case 'k': pubkeyfile = optarg; break; case 'l': list = true; break; case 's': server = optarg; break; case 'v': verbose = 1; break; case 'Z': zstd = true; break; case 'z': gzip = true; break; default: usage(); } if (gzip && zstd) errx(EX_USAGE, "The -z and -Z options are mutually exclusive."); argc -= optind; argv += optind; if (list) { listdumpdev(); exit(EX_OK); } if (argc != 1) usage(); #ifndef HAVE_CRYPTO if (pubkeyfile != NULL) errx(EX_UNAVAILABLE,"Unable to use the public key." " Recompile dumpon with OpenSSL support."); #endif if (server != NULL && client != NULL) { enable = true; dev = _PATH_NETDUMP; netdump = true; kdap = &ndconf.ndc_kda; } else if (server == NULL && client == NULL && argc > 0) { enable = strcmp(argv[0], "off") != 0; dev = enable ? argv[0] : _PATH_DEVNULL; netdump = false; kdap = &_kda; } else usage(); fd = opendumpdev(dev, dumpdev); if (!netdump && !gzip) check_size(fd, dumpdev); bzero(kdap, sizeof(*kdap)); kdap->kda_enable = 0; if (ioctl(fd, DIOCSKERNELDUMP, kdap) != 0) err(EX_OSERR, "ioctl(DIOCSKERNELDUMP)"); if (!enable) exit(EX_OK); explicit_bzero(kdap, sizeof(*kdap)); kdap->kda_enable = 1; kdap->kda_compression = KERNELDUMP_COMP_NONE; if (zstd) kdap->kda_compression = KERNELDUMP_COMP_ZSTD; else if (gzip) kdap->kda_compression = KERNELDUMP_COMP_GZIP; if (netdump) { memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_INET; hints.ai_protocol = IPPROTO_UDP; res = NULL; error = getaddrinfo(server, NULL, &hints, &res); if (error != 0) err(1, "%s", gai_strerror(error)); if (res == NULL) errx(1, "failed to resolve '%s'", server); server = inet_ntoa( ((struct sockaddr_in *)(void *)res->ai_addr)->sin_addr); freeaddrinfo(res); if (strlcpy(ndconf.ndc_iface, argv[0], sizeof(ndconf.ndc_iface)) >= sizeof(ndconf.ndc_iface)) errx(EX_USAGE, "invalid interface name '%s'", argv[0]); if (inet_aton(server, &ndconf.ndc_server) == 0) errx(EX_USAGE, "invalid server address '%s'", server); if (inet_aton(client, &ndconf.ndc_client) == 0) errx(EX_USAGE, "invalid client address '%s'", client); - if (gateway == NULL) + gateway = find_gateway(argv[0]); + if (gateway == NULL) { + if (verbose) + printf("failed to look up gateway for %s\n", + server); gateway = server; - else if (strcmp(gateway, "default") == 0 && - (gateway = find_gateway(argv[0])) == NULL) - errx(EX_NOHOST, - "failed to look up next-hop router for %s", server); + } if (inet_aton(gateway, &ndconf.ndc_gateway) == 0) errx(EX_USAGE, "invalid gateway address '%s'", gateway); #ifdef HAVE_CRYPTO if (pubkeyfile != NULL) genkey(pubkeyfile, kdap); #endif error = ioctl(fd, NETDUMPSCONF, &ndconf); if (error != 0) error = errno; explicit_bzero(kdap->kda_encryptedkey, kdap->kda_encryptedkeysize); free(kdap->kda_encryptedkey); explicit_bzero(kdap, sizeof(*kdap)); if (error != 0) errc(EX_OSERR, error, "ioctl(NETDUMPSCONF)"); } else { #ifdef HAVE_CRYPTO if (pubkeyfile != NULL) genkey(pubkeyfile, kdap); #endif error = ioctl(fd, DIOCSKERNELDUMP, kdap); if (error != 0) error = errno; explicit_bzero(kdap->kda_encryptedkey, kdap->kda_encryptedkeysize); free(kdap->kda_encryptedkey); explicit_bzero(kdap, sizeof(*kdap)); if (error != 0) errc(EX_OSERR, error, "ioctl(DIOCSKERNELDUMP)"); } if (verbose) printf("kernel dumps on %s\n", dumpdev); exit(EX_OK); }