diff options
| author | martin <martin@NetBSD.org> | 2019-10-12 14:44:31 +0000 |
|---|---|---|
| committer | martin <martin@NetBSD.org> | 2019-10-12 14:44:31 +0000 |
| commit | 4d159082f4de4ffef9f888d0ee1a97afbb71f790 (patch) | |
| tree | 73f4cf54e699378ddb56c2aae9203bd1adc6c228 | |
| parent | a9647209da86eb9cdb5238c6b052eb6fa4e92e0e (diff) | |
Pull up the following revisions, requested by roy in ticket #302:
external/bsd/dhcpcd/dist/src/dhcpcd-embedded.c up to 1.1.1.2
external/bsd/dhcpcd/dist/src/dhcpcd-embedded.h up to 1.1.1.2
external/bsd/dhcpcd/NetBSD-upgrade up to 1.2
external/bsd/dhcpcd/dist/compat/crypt/sha256.c delete
external/bsd/dhcpcd/dist/compat/crypt/hmac.c delete
external/bsd/dhcpcd/dist/compat/crypt/hmac.h delete
external/bsd/dhcpcd/dist/compat/crypt/md5.c delete
external/bsd/dhcpcd/dist/compat/crypt/md5.h delete
external/bsd/dhcpcd/dist/compat/crypt/sha256.h delete
external/bsd/dhcpcd/dist/compat/_strtoi.h delete
external/bsd/dhcpcd/dist/compat/arc4random.c delete
external/bsd/dhcpcd/dist/compat/arc4random.h delete
external/bsd/dhcpcd/dist/compat/arc4random_uniform.c delete
external/bsd/dhcpcd/dist/compat/arc4random_uniform.h delete
external/bsd/dhcpcd/dist/compat/bitops.h delete
external/bsd/dhcpcd/dist/compat/consttime_memequal.h delete
external/bsd/dhcpcd/dist/compat/dprintf.c delete
external/bsd/dhcpcd/dist/compat/dprintf.h delete
external/bsd/dhcpcd/dist/compat/endian.h delete
external/bsd/dhcpcd/dist/compat/pidfile.c delete
external/bsd/dhcpcd/dist/compat/pidfile.h delete
external/bsd/dhcpcd/dist/compat/queue.h delete
external/bsd/dhcpcd/dist/compat/rb.c delete
external/bsd/dhcpcd/dist/compat/rbtree.h delete
external/bsd/dhcpcd/dist/compat/reallocarray.c delete
external/bsd/dhcpcd/dist/compat/reallocarray.h delete
external/bsd/dhcpcd/dist/compat/strlcpy.c delete
external/bsd/dhcpcd/dist/compat/strlcpy.h delete
external/bsd/dhcpcd/dist/compat/strtoi.c delete
external/bsd/dhcpcd/dist/compat/strtoi.h delete
external/bsd/dhcpcd/dist/compat/strtou.c delete
external/bsd/dhcpcd/dist/.gitignore delete
external/bsd/dhcpcd/dist/BUILDING.md delete
external/bsd/dhcpcd/dist/Makefile delete
external/bsd/dhcpcd/dist/Makefile.inc delete
external/bsd/dhcpcd/dist/config-null.mk delete
external/bsd/dhcpcd/dist/configure delete
external/bsd/dhcpcd/dist/iconfig.mk delete
external/bsd/dhcpcd/dist/hooks/Makefile delete
external/bsd/dhcpcd/dist/hooks/50-dhcpcd-compat delete
external/bsd/dhcpcd/dist/hooks/50-yp.conf delete
external/bsd/dhcpcd/dist/src/Makefile delete
external/bsd/dhcpcd/dist/src/GNUmakefile delete
external/bsd/dhcpcd/dist/src/dev.c delete
external/bsd/dhcpcd/dist/src/dhcpcd-definitions-small.conf delete
external/bsd/dhcpcd/dist/src/dhcpcd-definitions.conf delete
external/bsd/dhcpcd/dist/src/dhcpcd-embedded.c.in delete
external/bsd/dhcpcd/dist/src/dhcpcd-embedded.h.in delete
external/bsd/dhcpcd/dist/src/genembedc delete
external/bsd/dhcpcd/dist/src/genembedh delete
external/bsd/dhcpcd/dist/src/if-linux-wext.c delete
external/bsd/dhcpcd/dist/src/if-linux.c delete
external/bsd/dhcpcd/dist/src/if-sun.c delete
external/bsd/dhcpcd/dist/src/dev/Makefile delete
external/bsd/dhcpcd/dist/src/dev/udev.c delete
external/bsd/dhcpcd/dist/tests/crypt/.gitignore delete
external/bsd/dhcpcd/dist/tests/crypt/GNUmakefile delete
external/bsd/dhcpcd/dist/tests/crypt/Makefile delete
external/bsd/dhcpcd/dist/tests/crypt/README.md delete
external/bsd/dhcpcd/dist/tests/crypt/run-test.c delete
external/bsd/dhcpcd/dist/tests/crypt/test.h delete
external/bsd/dhcpcd/dist/tests/crypt/test_hmac_md5.c delete
external/bsd/dhcpcd/dist/tests/Makefile delete
external/bsd/dhcpcd/dist/tests/eloop-bench/.gitignore delete
external/bsd/dhcpcd/dist/tests/eloop-bench/Makefile delete
external/bsd/dhcpcd/dist/tests/eloop-bench/README.md delete
external/bsd/dhcpcd/dist/tests/eloop-bench/eloop-bench.c delete
external/bsd/dhcpcd/dist/src/arp.c up to 1.1.1.12
external/bsd/dhcpcd/dist/src/bpf.c up to 1.13
external/bsd/dhcpcd/dist/src/bpf.h up to 1.1.1.7
external/bsd/dhcpcd/dist/src/common.c up to 1.1.1.9
external/bsd/dhcpcd/dist/src/common.h up to 1.1.1.9
external/bsd/dhcpcd/dist/src/control.h up to 1.1.1.6
external/bsd/dhcpcd/dist/src/defs.h up to 1.1.1.30
external/bsd/dhcpcd/dist/src/dhcp-common.c up to 1.1.1.9
external/bsd/dhcpcd/dist/src/dhcp-common.h up to 1.1.1.5
external/bsd/dhcpcd/dist/src/dhcp.c up to 1.28
external/bsd/dhcpcd/dist/src/dhcp.h up to 1.1.1.11
external/bsd/dhcpcd/dist/src/dhcp6.c up to 1.13
external/bsd/dhcpcd/dist/src/dhcpcd.8.in up to 1.4
external/bsd/dhcpcd/dist/src/dhcpcd.c up to 1.27
external/bsd/dhcpcd/dist/src/dhcpcd.conf.5.in up to 1.1.1.15
external/bsd/dhcpcd/dist/src/if-bsd.c up to 1.14
external/bsd/dhcpcd/dist/src/if-options.c up to 1.18
external/bsd/dhcpcd/dist/src/if.c up to 1.1.1.17
external/bsd/dhcpcd/dist/src/if.h up to 1.1.1.12
external/bsd/dhcpcd/dist/src/ipv4.c up to 1.1.1.18
external/bsd/dhcpcd/dist/src/ipv4.h up to 1.1.1.11
external/bsd/dhcpcd/dist/src/ipv4ll.c up to 1.1.1.10
external/bsd/dhcpcd/dist/src/ipv4ll.h up to 1.1.1.8
external/bsd/dhcpcd/dist/src/ipv6.c up to 1.5
external/bsd/dhcpcd/dist/src/ipv6.h up to 1.6
external/bsd/dhcpcd/dist/src/ipv6nd.c up to 1.12
external/bsd/dhcpcd/dist/src/route.c up to 1.1.1.15
external/bsd/dhcpcd/sbin/dhcpcd/Makefile up to 1.49
doc/3RDPARTY modified manually
Import dhcpcd-8.1.0 with the following changes:
* Fix carrier status after a route socket overflow
* Allow domain spaced options
* DHCP: Allow not sending Force Renew Nonce or Reconf Accept
* IPv4LL: Now passes Apple Bonjour test versions 1.4 and 1.5
* ARP: Fix a typo and remove pragma (thus working with old gcc)
* DHCP6: Fix a cosmetic issue with infinite leases
* DHCP6: SLA 0 and Prefix Len 0 will now add a delegatd /64 address
* Ignore some virtual interfaces such as Tap and Bridge by default
* BPF: Move validation logic out of BPF and back into dhcpcd
95 files changed, 999 insertions, 12186 deletions
diff --git a/doc/3RDPARTY b/doc/3RDPARTY index ab778070eb5..4ec7573d011 100644 --- a/doc/3RDPARTY +++ b/doc/3RDPARTY @@ -1,4 +1,4 @@ -# $NetBSD: 3RDPARTY,v 1.1640.2.3 2019/09/17 19:51:12 martin Exp $ +# $NetBSD: 3RDPARTY,v 1.1640.2.4 2019/10/12 14:44:31 martin Exp $ # # This file contains a list of the software that has been integrated into # NetBSD where we are not the primary maintainer. @@ -341,12 +341,12 @@ Notes: Use the dhcp2netbsd script. Package: dhcpcd -Version: 8.0.2 -Current Vers: 8.0.2 +Version: 8.1.0 +Current Vers: 8.1.0 Maintainer: roy Archive Site: ftp://roy.marples.name/pub/dhcpcd/ Home Page: http://roy.marples.name/projects/dhcpcd/ -Date: 2019-07-30 +Date: 2019-10-12 Mailing List: dhcpcd-discuss@marples.name License: BSD (2-clause) Location: external/bsd/dhcpcd/dist diff --git a/external/bsd/dhcpcd/NetBSD-upgrade b/external/bsd/dhcpcd/NetBSD-upgrade new file mode 100644 index 00000000000..1888e07936f --- /dev/null +++ b/external/bsd/dhcpcd/NetBSD-upgrade @@ -0,0 +1,18 @@ +$NetBSD: NetBSD-upgrade,v 1.2.2.2 2019/10/12 14:44:31 martin Exp $ + +dhcpcd releases can be found at https://roy.marples.name/downloads/dhcpcd/ + +For the import there is a handy autoamated approach + tar -xf dhcpcd-X.Y.Z.tar.xz + cd dhcpcd-X.Y.Z + ./configure + make import-src + cd /tmp/dhcpcd-X.Y.Z + cvs import src/external/bsd/dhcpcd/dist ROY dhcpcd-X_Y_Z + +To make local changes to dhcpcd, simply patch and commit +to the main branch (aka HEAD). Never make local changes on the +vendor (ROY) branch. + +All local changes should be submitted to Roy Marples for inclusion in +the next vendor release. diff --git a/external/bsd/dhcpcd/dist/.gitignore b/external/bsd/dhcpcd/dist/.gitignore deleted file mode 100644 index 1ca2859ee6f..00000000000 --- a/external/bsd/dhcpcd/dist/.gitignore +++ /dev/null @@ -1,31 +0,0 @@ -# Ignore configure generated files -config.h -config.mk -config.log - -# Ignore object files -.depend -*.o -*.So -*.so -dhcpcd - -# Ignore generated embedded files -dhcpcd-embedded.c -dhcpcd-embedded.h - -# Ignore generated man pages and scripts -dhcpcd.8 -dhcpcd-run-hooks -dhcpcd-run-hooks.8 -dhcpcd.conf.5 -hooks/50-ypbind - -# Ignore distribution -dhcpcd*.xz* - -# Ignore swap files -*.swp - -# Ignore Coverity -cov-int diff --git a/external/bsd/dhcpcd/dist/BUILDING.md b/external/bsd/dhcpcd/dist/BUILDING.md deleted file mode 100644 index 6779ccec1e3..00000000000 --- a/external/bsd/dhcpcd/dist/BUILDING.md +++ /dev/null @@ -1,173 +0,0 @@ -# Building dhcpcd - -This attempts to document various ways of building dhcpcd for your -platform. - -## Size is an issue -To compile small dhcpcd, maybe to be used for installation media where -size is a concern, you can use the `--small` configure option to enable -a reduced feature set within dhcpcd. -Currently this just removes non important options out of -`dhcpcd-definitions.conf`, the logfile option, -DHCPv6 Prefix Delegation and IPv6 address announcement *(to prefer an -address on another interface)*. -Other features maybe dropped as and when required. -dhcpcd can also be made smaller by removing the IPv4 or IPv6 stack: - * `--disable-inet` - * `--disable-inet6` - -Or by removing the following features: - * `--disable-auth` - * `--disable-arp` - * `--disable-arping` - * `--disable-ipv4ll` - * `--disable-dhcp6` - -You can also move the embedded extended configuration from the dhcpcd binary -to an external file (LIBEXECDIR/dhcpcd-definitions.conf) - * `--disable-embedded` -If dhcpcd cannot load this file at runtime, dhcpcd will work but will not be -able to decode any DHCP/DHCPv6 options that are not defined by the user -in /etc/dhcpcd.conf. This does not really change the total on disk size. - -## Cross compiling -If you're cross compiling you may need set the platform if OS is different -from the host. -`--target=sparc-sun-netbsd5.0` - -If you're building for an MMU-less system where fork() does not work, you -should `./configure --disable-fork`. -This also puts the `--no-background` flag on and stops the `--background` flag -from working. - -## Default directories -You can change the default dirs with these knobs. -For example, to satisfy FHS compliance you would do this: -`./configure --libexecdir=/lib/dhcpcd dbdir=/var/lib/dhcpcd` - -## Compile Issues -We now default to using `-std=c99`. For 64-bit linux, this always works, but -for 32-bit linux it requires either gnu99 or a patch to `asm/types.h`. -Most distros patch linux headers so this should work fine. -linux-2.6.24 finally ships with a working 32-bit header. -If your linux headers are older, or your distro hasn't patched them you can -set `CSTD=gnu99` to work around this. - -ArchLinux presently sanitises all kernel headers to the latest version -regardless of the version for your CPU. As such, Arch presently ships a -3.12 kernel with 3.17 headers which claim that it supports temporary address -management and no automatic prefix route generation, both of which are -obviously false. You will have to patch support either in the kernel or -out of the headers (or dhcpcd itself) to have correct operation. - -## OS specific issues -Some BSD systems do not allow the manipulation of automatically added subnet -routes. You can find discussion here: - http://mail-index.netbsd.org/tech-net/2008/12/03/msg000896.html -BSD systems where this has been fixed or is known to work are: - NetBSD-5.0 - FreeBSD-10.0 - -Some BSD systems protect against IPv6 NS/NA messages by ensuring that the -source address matches a prefix on the recieved by a RA message. -This is an error as the correct check is for on-link prefixes as the -kernel may not be handling RA itself. -BSD systems where this has been fixed or is known to work are: - NetBSD-7.0 - OpenBSD-5.0 - patch submitted against FreeBSD-10.0 - -Some BSD systems do not announce IPv6 address flag changes, such as -`IN6_IFF_TENTATIVE`, `IN6_IFF_DUPLICATED`, etc. On these systems, -dhcpcd will poll a freshly added address until either `IN6_IFF_TENTATIVE` is -cleared or `IN6_IFF_DUPLICATED` is set and take action accordingly. -BSD systems where this has been fixed or is known to work are: - NetBSD-7.0 - -OpenBSD will always add it's own link-local address if no link-local address -exists, because it doesn't check if the address we are adding is a link-local -address or not. - -Some BSD systems do not announce cached neighbour route changes based -on reachability to userland. For such systems, IPv6 routers will always -be assumed to be reachable until they either stop being a router or expire. -BSD systems where this has been fixed or is known to work are: - NetBSD-7.99.3 - -Linux prior to 3.17 won't allow userland to manage IPv6 temporary addresses. -Either upgrade or don't allow dhcpcd to manage the RA, -so don't set either `ipv6ra_own` or `slaac private` in `dhcpcd.conf` if you -want to have working IPv6 temporary addresses. -SLAAC private addresses are just as private, just stable. - -## Init systems -We try and detect how dhcpcd should interact with system services at runtime. -If we cannot auto-detect how do to this, or it is wrong then -you can change this by passing shell commands to `--serviceexists`, -`--servicecmd` and optionally `--servicestatus` to `./configure` or overriding -the service variables in a hook. - - -## /dev management -Some systems have `/dev` management systems and some of these like to rename -interfaces. As this system would listen in the same way as dhcpcd to new -interface arrivals, dhcpcd needs to listen to the `/dev` management sytem -instead of the kernel. However, if the `/dev` management system breaks, stops -working, or changes to a new one, dhcpcd should still try and continue to work. -To facilitate this, dhcpcd allows a plugin to load to instruct dhcpcd when it -can use an interface. As of the time of writing only udev support is included. -You can disable this with `--without-dev`, or `without-udev`. -NOTE: in Gentoo at least, `sys-fs/udev` as provided by systemd leaks memory -`sys-fs/eudev`, the fork of udev does not and as such is recommended. - -## select -dhcpcd uses eloop.c, which is a portable main event loop with timeouts and -signal handling. Unlike libevent and similar, it can be transplanted directly -within the application - the only caveat outside of POSIX calls is that -you provide queue.h based on a recent BSD (glibc sys/queue.h is not enough). -eloop supports the following polling mechanisms, listed in order of preference: - kqueue, epoll, pollts, ppoll and pselect. -If signal handling is disabled (ie in RTEMS or other single process -OS's) then eloop can use poll. -You can decide which polling mechanism dhcpcd will select in eloop like so -`./configure --with-poll=[kqueue|epoll|pselect|pollts|ppoll]` - - -## Importing into another source control system -To import the full sources, use the import target. -To import only the needed sources and documentation, use the import-src -target. -Both targets support DESTDIR to set the installation directory, -if unset it defaults to `/tmp/dhcpcd-$VERSION` -Example: `make DESTDIR=/usr/src/contrib/dhcpcd import-src` - -In this instance, you may wish to disable some configured tests when -the binary has to run on older versions which lack support, such as getline. -`./configure --without-getline` - - -## Hooks -Not all the hooks in dhcpcd-hooks are installed by default. -By default we install `01-test`, `02-dump`, `10-mtu`, `20-resolv.conf` -and `30-hostname`. -The other hooks, `10-wpa_supplicant`, `15-timezone` and `29-lookup-hostname` -are installed to `$(datadir)/dhcpcd/hooks` by default and need to be -copied to `$(libexecdir)/dhcpcd-hooks` for use. -The configure program attempts to find hooks for systems you have installed. -To add more simply -`./configure -with-hook=ntp.conf` - -Some system services expose the name of the service we are in, -by default dhcpcd will pick `RC_SVCNAME` from the environment. -You can override this in `CPPFLAGS+= -DRC_SVCNAME="YOUR_SVCNAME"`. -This is important because dhcpcd will scrub the environment aside from `$PATH` -before running hooks. -This variable could be used to facilitate service re-entry so this chain could -happen in a custom OS hook: - dhcpcd service marked inactive && dhcpcd service starts - dependant services are not started because dhcpcd is inactive (not stopped) - dhcpcd hook tests if `$if_up = true` and `$af_waiting` is empty or unset. - if true, mark the dhcpcd service as started and then start dependencies - if false and the dhcpcd service was previously started, mark as inactive and - stop any dependant services. - diff --git a/external/bsd/dhcpcd/dist/Makefile b/external/bsd/dhcpcd/dist/Makefile deleted file mode 100644 index dcd4624c957..00000000000 --- a/external/bsd/dhcpcd/dist/Makefile +++ /dev/null @@ -1,106 +0,0 @@ -SUBDIRS= src hooks - -VERSION!= sed -n 's/\#define VERSION[[:space:]]*"\(.*\)".*/\1/p' src/defs.h - -DIST!= if test -d .git; then echo "dist-git"; \ - else echo "dist-inst"; fi -FOSSILID?= current -GITREF?= HEAD - -DISTSUFFIX= -DISTPREFIX?= dhcpcd-${VERSION}${DISTSUFFIX} -DISTFILEGZ?= ${DISTPREFIX}.tar.gz -DISTFILE?= ${DISTPREFIX}.tar.xz -DISTINFO= ${DISTFILE}.distinfo -DISTINFOSIGN= ${DISTINFO}.asc - -CLEANFILES+= *.tar.xz - -.PHONY: hooks import import-bsd tests - -.SUFFIXES: .in - -all: config.h - for x in ${SUBDIRS}; do cd $$x; ${MAKE} $@ || exit $$?; cd ..; done - -depend: config.h - for x in ${SUBDIRS}; do cd $$x; ${MAKE} $@ || exit $$?; cd ..; done - -tests: - cd $@; ${MAKE} $@ - -test: tests - -hooks: - cd $@; ${MAKE} - -eginstall: - for x in ${SUBDIRS}; do cd $$x; ${MAKE} $@ || exit $$?; cd ..; done - -install: - for x in ${SUBDIRS}; do cd $$x; ${MAKE} $@ || exit $$?; cd ..; done - -proginstall: - for x in ${SUBDIRS}; do cd $$x; ${MAKE} $@ || exit $$?; cd ..; done - -clean: - rm -rf cov-int dhcpcd.xz - for x in ${SUBDIRS} tests; do cd $$x; ${MAKE} $@ || exit $$?; cd ..; done - -distclean: clean - rm -f config.h config.mk config.log \ - ${DISTFILE} ${DISTFILEGZ} ${DISTINFO} ${DISTINFOSIGN} - -dist-git: - git archive --prefix=${DISTPREFIX}/ ${GITREF} | xz >${DISTFILE} - -dist-inst: - mkdir /tmp/${DISTPREFIX} - cp -RPp * /tmp/${DISTPREFIX} - (cd /tmp/${DISTPREFIX}; make clean) - tar -cvjpf ${DISTFILE} -C /tmp ${DISTPREFIX} - rm -rf /tmp/${DISTPREFIX} - -dist: ${DIST} - -distinfo: dist - rm -f ${DISTINFO} ${DISTINFOSIGN} - ${CKSUM} ${DISTFILE} >${DISTINFO} - #printf "SIZE (${DISTFILE}) = %s\n" $$(wc -c <${DISTFILE}) >>${DISTINFO} - ${PGP} --clearsign --output=${DISTINFOSIGN} ${DISTINFO} - chmod 644 ${DISTINFOSIGN} - ls -l ${DISTFILE} ${DISTINFO} ${DISTINFOSIGN} - -snapshot: - rm -rf /tmp/${DISTPREFIX} - ${INSTALL} -d /tmp/${DISTPREFIX} - cp -RPp * /tmp/${DISTPREFIX} - ${MAKE} -C /tmp/${DISTPREFIX} distclean - tar cf - -C /tmp ${DISTPREFIX} | xz >${DISTFILE} - ls -l ${DISTFILE} - -_import: dist - rm -rf ${DESTDIR}/* - ${INSTALL} -d ${DESTDIR} - tar xvpf ${DISTFILE} -C ${DESTDIR} --strip 1 - @${ECHO} - @${ECHO} "=============================================================" - @${ECHO} "dhcpcd-${VERSION} imported to ${DESTDIR}" - -import: - ${MAKE} _import DESTDIR=`if [ -n "${DESTDIR}" ]; then echo "${DESTDIR}"; else echo /tmp/${DISTPREFIX}; fi` - - -_import-src: - rm -rf ${DESTDIR}/* - ${INSTALL} -d ${DESTDIR} - cp LICENSE README.md ${DESTDIR}; - for x in ${SUBDIRS}; do cd $$x; ${MAKE} DESTDIR=${DESTDIR} $@ || exit $$?; cd ..; done - @${ECHO} - @${ECHO} "=============================================================" - @${ECHO} "dhcpcd-${VERSION} imported to ${DESTDIR}" - -import-src: - ${MAKE} _import-src DESTDIR=`if [ -n "${DESTDIR}" ]; then echo "${DESTDIR}"; else echo /tmp/${DISTPREFIX}; fi` - -include Makefile.inc diff --git a/external/bsd/dhcpcd/dist/Makefile.inc b/external/bsd/dhcpcd/dist/Makefile.inc deleted file mode 100644 index 3561ba35837..00000000000 --- a/external/bsd/dhcpcd/dist/Makefile.inc +++ /dev/null @@ -1,34 +0,0 @@ -# System definitions - -PICFLAG?= -fPIC - -BINMODE?= 0555 -NONBINMODE?= 0444 -MANMODE?= ${NONBINMODE} -CONFMODE?= 0644 - -CC?= cc -ECHO?= echo -INSTALL?= install -LINT?= lint -SED?= sed -HOST_SH?= /bin/sh - -# This isn't very portable, but I generaly make releases from NetBSD -CKSUM?= cksum -a SHA256 -PGP?= netpgp - -SCRIPT= ${LIBEXECDIR}/dhcpcd-run-hooks -HOOKDIR= ${LIBEXECDIR}/dhcpcd-hooks - -SED_RUNDIR= -e 's:@RUNDIR@:${RUNDIR}:g' -SED_DBDIR= -e 's:@DBDIR@:${DBDIR}:g' -SED_LIBDIR= -e 's:@LIBDIR@:${LIBDIR}:g' -SED_DATADIR= -e 's:@DATADIR@:${DATADIR}:g' -SED_HOOKDIR= -e 's:@HOOKDIR@:${HOOKDIR}:g' -SED_SERVICEEXISTS= -e 's:@SERVICEEXISTS@:${SERVICEEXISTS}:g' -SED_SERVICECMD= -e 's:@SERVICECMD@:${SERVICECMD}:g' -SED_SERVICESTATUS= -e 's:@SERVICESTATUS@:${SERVICESTATUS}:g' -SED_STATUSARG= -e 's:@STATUSARG@:${STATUSARG}:g' -SED_SCRIPT= -e 's:@SCRIPT@:${SCRIPT}:g' -SED_SYS= -e 's:@SYSCONFDIR@:${SYSCONFDIR}:g' diff --git a/external/bsd/dhcpcd/dist/compat/_strtoi.h b/external/bsd/dhcpcd/dist/compat/_strtoi.h deleted file mode 100644 index 68c087dace2..00000000000 --- a/external/bsd/dhcpcd/dist/compat/_strtoi.h +++ /dev/null @@ -1,93 +0,0 @@ -/* $NetBSD: _strtoi.h,v 1.1.1.1 2017/03/31 20:51:15 roy Exp $ */ - -/*- - * Copyright (c) 1990, 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. - * - * Original version ID: - * NetBSD: src/lib/libc/locale/_wcstoul.h,v 1.2 2003/08/07 16:43:03 agc Exp - * - * Created by Kamil Rytarowski, based on ID: - * NetBSD: src/common/lib/libc/stdlib/_strtoul.h,v 1.7 2013/05/17 12:55:56 joerg Exp - */ - -/* - * function template for strtoi and strtou - * - * parameters: - * _FUNCNAME : function name - * __TYPE : return and range limits type - * __WRAPPED : wrapped function, strtoimax or strtoumax - */ - -__TYPE -_FUNCNAME(const char * __restrict nptr, char ** __restrict endptr, int base, - __TYPE lo, __TYPE hi, int * rstatus) -{ - int serrno; - __TYPE im; - char *ep; - int rep; - - /* endptr may be NULL */ - - if (endptr == NULL) - endptr = &ep; - - if (rstatus == NULL) - rstatus = &rep; - - serrno = errno; - errno = 0; - - im = __WRAPPED(nptr, endptr, base); - - *rstatus = errno; - errno = serrno; - - if (*rstatus == 0) { - /* No digits were found */ - if (nptr == *endptr) - *rstatus = ECANCELED; - /* There are further characters after number */ - else if (**endptr != '\0') - *rstatus = ENOTSUP; - } - - if (im < lo) { - if (*rstatus == 0) - *rstatus = ERANGE; - return lo; - } - if (im > hi) { - if (*rstatus == 0) - *rstatus = ERANGE; - return hi; - } - - return im; -} diff --git a/external/bsd/dhcpcd/dist/compat/arc4random.c b/external/bsd/dhcpcd/dist/compat/arc4random.c deleted file mode 100644 index ab06df04492..00000000000 --- a/external/bsd/dhcpcd/dist/compat/arc4random.c +++ /dev/null @@ -1,158 +0,0 @@ -/* - * Arc4 random number generator for OpenBSD. - * Copyright 1996 David Mazieres <dm@lcs.mit.edu>. - * - * Modification and redistribution in source and binary forms is - * permitted provided that due credit is given to the author and the - * OpenBSD project by leaving this copyright notice intact. - */ - -/* - * This code is derived from section 17.1 of Applied Cryptography, - * second edition, which describes a stream cipher allegedly - * compatible with RSA Labs "RC4" cipher (the actual description of - * which is a trade secret). The same algorithm is used as a stream - * cipher called "arcfour" in Tatu Ylonen's ssh package. - * - * Here the stream cipher has been modified always to include the time - * when initializing the state. That makes it impossible to - * regenerate the same random sequence twice, so this can't be used - * for encryption, but will generate good random numbers. - * - * RC4 is a registered trademark of RSA Laboratories. - */ - -#include <sys/time.h> - -#include <fcntl.h> -#include <stdint.h> -#include <stdlib.h> -#include <unistd.h> - -#include "arc4random.h" - -struct arc4_stream { - uint8_t i; - uint8_t j; - uint8_t s[256]; - size_t count; - pid_t stir_pid; -}; - -#define S(n) (n) -#define S4(n) S(n), S(n + 1), S(n + 2), S(n + 3) -#define S16(n) S4(n), S4(n + 4), S4(n + 8), S4(n + 12) -#define S64(n) S16(n), S16(n + 16), S16(n + 32), S16(n + 48) -#define S256 S64(0), S64(64), S64(128), S64(192) - -static struct arc4_stream rs = { .i = 0xff, .j = 0, .s = { S256 }, - .count = 0, .stir_pid = 0 }; - -#undef S -#undef S4 -#undef S16 -#undef S64 -#undef S256 - -static void -arc4_addrandom(struct arc4_stream *as, unsigned char *dat, int datlen) -{ - int n; - uint8_t si; - - as->i--; - for (n = 0; n < 256; n++) { - as->i = (uint8_t)(as->i + 1); - si = as->s[as->i]; - as->j = (uint8_t)(as->j + si + dat[n % datlen]); - as->s[as->i] = as->s[as->j]; - as->s[as->j] = si; - } - as->j = as->i; -} - -static uint8_t -arc4_getbyte(struct arc4_stream *as) -{ - uint8_t si, sj; - - as->i = (uint8_t)(as->i + 1); - si = as->s[as->i]; - as->j = (uint8_t)(as->j + si); - sj = as->s[as->j]; - as->s[as->i] = sj; - as->s[as->j] = si; - return (as->s[(si + sj) & 0xff]); -} - -static uint32_t -arc4_getword(struct arc4_stream *as) -{ - int val; - - val = arc4_getbyte(as) << 24; - val |= arc4_getbyte(as) << 16; - val |= arc4_getbyte(as) << 8; - val |= arc4_getbyte(as); - return (uint32_t)val; -} - -/* We don't care about any error on read, just use what we have - * on the stack. So mask off this GCC warning. */ -#pragma GCC diagnostic ignored "-Wunused-result" -static void -arc4_stir(struct arc4_stream *as) -{ - int fd; - struct { - struct timeval tv; - unsigned int rnd[(128 - sizeof(struct timeval)) / - sizeof(unsigned int)]; - } rdat; - size_t n; - - gettimeofday(&rdat.tv, NULL); - fd = open("/dev/urandom", O_RDONLY); - if (fd != -1) { - /* If there is an error reading, just use what is - * on the stack. */ - /* coverity[check_return] */ - (void)read(fd, rdat.rnd, sizeof(rdat.rnd)); - close(fd); - } - - /* fd < 0? Ah, what the heck. We'll just take - * whatever was on the stack... */ - /* coverity[uninit_use_in_call] */ - arc4_addrandom(as, (void *) &rdat, sizeof(rdat)); - - /* - * Throw away the first N words of output, as suggested in the - * paper "Weaknesses in the Key Scheduling Algorithm of RC4" - * by Fluher, Mantin, and Shamir. (N = 256 in our case.) - */ - for (n = 0; n < 256 * sizeof(uint32_t); n++) - arc4_getbyte(as); - as->count = 1600000; -} - -static void -arc4_stir_if_needed(struct arc4_stream *as) -{ - pid_t pid; - - pid = getpid(); - if (as->count <= sizeof(uint32_t) || as->stir_pid != pid) { - as->stir_pid = pid; - arc4_stir(as); - } else - as->count -= sizeof(uint32_t); -} - -uint32_t -arc4random() -{ - - arc4_stir_if_needed(&rs); - return arc4_getword(&rs); -} diff --git a/external/bsd/dhcpcd/dist/compat/arc4random.h b/external/bsd/dhcpcd/dist/compat/arc4random.h deleted file mode 100644 index a975fef3cd1..00000000000 --- a/external/bsd/dhcpcd/dist/compat/arc4random.h +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Arc4 random number generator for OpenBSD. - * Copyright 1996 David Mazieres <dm@lcs.mit.edu>. - * - * Modification and redistribution in source and binary forms is - * permitted provided that due credit is given to the author and the - * OpenBSD project by leaving this copyright notice intact. - */ - -#ifndef ARC4RANDOM_H -#define ARC4RANDOM_H - -#include <stdint.h> - -uint32_t arc4random(void); -#endif diff --git a/external/bsd/dhcpcd/dist/compat/arc4random_uniform.c b/external/bsd/dhcpcd/dist/compat/arc4random_uniform.c deleted file mode 100644 index 0f1b7b29675..00000000000 --- a/external/bsd/dhcpcd/dist/compat/arc4random_uniform.c +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2008, Damien Miller <djm@openbsd.org> - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include <stdint.h> -#include <stdlib.h> - -/* We need to include config.h so we pickup either the system arc4random - * or our compat one. */ -#include "config.h" - -/* - * Calculate a uniformly distributed random number less than upper_bound - * avoiding "modulo bias". - * - * Uniformity is achieved by generating new random numbers until the one - * returned is outside the range [0, 2**32 % upper_bound). This - * guarantees the selected random number will be inside - * [2**32 % upper_bound, 2**32) which maps back to [0, upper_bound) - * after reduction modulo upper_bound. - */ -uint32_t -arc4random_uniform(uint32_t upper_bound) -{ - uint32_t r, min; - - if (upper_bound < 2) - return 0; - - /* 2**32 % x == (2**32 - x) % x */ - min = -upper_bound % upper_bound; - - /* - * This could theoretically loop forever but each retry has - * p > 0.5 (worst case, usually far better) of selecting a - * number inside the range we need, so it should rarely need - * to re-roll. - */ - do - r = arc4random(); - while (r < min); - - return r % upper_bound; -} diff --git a/external/bsd/dhcpcd/dist/compat/arc4random_uniform.h b/external/bsd/dhcpcd/dist/compat/arc4random_uniform.h deleted file mode 100644 index d7c0a35d4cb..00000000000 --- a/external/bsd/dhcpcd/dist/compat/arc4random_uniform.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) 2008, Damien Miller <djm@openbsd.org> - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef ARC4RANDOM_UNIFORM_H -#define ARC4RANDOM_UNIFORM_H - -#include <stdint.h> - -uint32_t arc4random_uniform(uint32_t); -#endif diff --git a/external/bsd/dhcpcd/dist/compat/bitops.h b/external/bsd/dhcpcd/dist/compat/bitops.h deleted file mode 100644 index b826275a35f..00000000000 --- a/external/bsd/dhcpcd/dist/compat/bitops.h +++ /dev/null @@ -1,188 +0,0 @@ -/* $NetBSD: bitops.h,v 1.1.1.1 2017/03/31 20:51:15 roy Exp $ */ - -/*- - * Copyright (c) 2007, 2010 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software contributed to The NetBSD Foundation - * by Christos Zoulas and Joerg Sonnenberger. - * - * 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. - * - * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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. - */ - -#ifndef COMPAT_BITOPS_H -#define COMPAT_BITOPS_H - -#include <stdint.h> -#include "common.h" - -/* - * Find First Set functions - */ -#ifndef ffs32 -static inline int __unused -ffs32(uint32_t _n) -{ - int _v; - - if (!_n) - return 0; - - _v = 1; - if ((_n & 0x0000FFFFU) == 0) { - _n >>= 16; - _v += 16; - } - if ((_n & 0x000000FFU) == 0) { - _n >>= 8; - _v += 8; - } - if ((_n & 0x0000000FU) == 0) { - _n >>= 4; - _v += 4; - } - if ((_n & 0x00000003U) == 0) { - _n >>= 2; - _v += 2; - } - if ((_n & 0x00000001U) == 0) { - //_n >>= 1; - _v += 1; - } - return _v; -} -#endif - -#ifndef ffs64 -static inline int __unused -ffs64(uint64_t _n) -{ - int _v; - - if (!_n) - return 0; - - _v = 1; - if ((_n & 0x00000000FFFFFFFFULL) == 0) { - _n >>= 32; - _v += 32; - } - if ((_n & 0x000000000000FFFFULL) == 0) { - _n >>= 16; - _v += 16; - } - if ((_n & 0x00000000000000FFULL) == 0) { - _n >>= 8; - _v += 8; - } - if ((_n & 0x000000000000000FULL) == 0) { - _n >>= 4; - _v += 4; - } - if ((_n & 0x0000000000000003ULL) == 0) { - _n >>= 2; - _v += 2; - } - if ((_n & 0x0000000000000001ULL) == 0) { - //_n >>= 1; - _v += 1; - } - return _v; -} -#endif - -/* - * Find Last Set functions - */ -#ifndef fls32 -static __inline int __unused -fls32(uint32_t _n) -{ - int _v; - - if (!_n) - return 0; - - _v = 32; - if ((_n & 0xFFFF0000U) == 0) { - _n <<= 16; - _v -= 16; - } - if ((_n & 0xFF000000U) == 0) { - _n <<= 8; - _v -= 8; - } - if ((_n & 0xF0000000U) == 0) { - _n <<= 4; - _v -= 4; - } - if ((_n & 0xC0000000U) == 0) { - _n <<= 2; - _v -= 2; - } - if ((_n & 0x80000000U) == 0) { - //_n <<= 1; - _v -= 1; - } - return _v; -} -#endif - -#ifndef fls64 -static int __unused -fls64(uint64_t _n) -{ - int _v; - - if (!_n) - return 0; - - _v = 64; - if ((_n & 0xFFFFFFFF00000000ULL) == 0) { - _n <<= 32; - _v -= 32; - } - if ((_n & 0xFFFF000000000000ULL) == 0) { - _n <<= 16; - _v -= 16; - } - if ((_n & 0xFF00000000000000ULL) == 0) { - _n <<= 8; - _v -= 8; - } - if ((_n & 0xF000000000000000ULL) == 0) { - _n <<= 4; - _v -= 4; - } - if ((_n & 0xC000000000000000ULL) == 0) { - _n <<= 2; - _v -= 2; - } - if ((_n & 0x8000000000000000ULL) == 0) { - //_n <<= 1; - _v -= 1; - } - return _v; -} -#endif - -#endif /* COMPAT_BITOPS_H_ */ diff --git a/external/bsd/dhcpcd/dist/compat/consttime_memequal.h b/external/bsd/dhcpcd/dist/compat/consttime_memequal.h deleted file mode 100644 index 98306484107..00000000000 --- a/external/bsd/dhcpcd/dist/compat/consttime_memequal.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Written by Matthias Drochner <drochner@NetBSD.org>. - * Public domain. - */ - -#ifndef CONSTTIME_MEMEQUAL_H -#define CONSTTIME_MEMEQUAL_H -inline static int -consttime_memequal(const void *b1, const void *b2, size_t len) -{ - const unsigned char *c1 = b1, *c2 = b2; - unsigned int res = 0; - - while (len--) - res |= *c1++ ^ *c2++; - - /* - * Map 0 to 1 and [1, 256) to 0 using only constant-time - * arithmetic. - * - * This is not simply `!res' because although many CPUs support - * branchless conditional moves and many compilers will take - * advantage of them, certain compilers generate branches on - * certain CPUs for `!res'. - */ - return (1 & ((res - 1) >> 8)); -} -#endif /* CONSTTIME_MEMEQUAL_H */ diff --git a/external/bsd/dhcpcd/dist/compat/crypt/hmac.c b/external/bsd/dhcpcd/dist/compat/crypt/hmac.c deleted file mode 100644 index 81de2c6c87f..00000000000 --- a/external/bsd/dhcpcd/dist/compat/crypt/hmac.c +++ /dev/null @@ -1,191 +0,0 @@ -/* $NetBSD: hmac.c,v 1.1.1.1 2017/10/07 14:05:36 roy Exp $ */ - -/*- - * Copyright (c) 2016 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software contributed to The NetBSD Foundation - * by Christos Zoulas. - * - * 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. - * - * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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. - */ - -#include <string.h> -#include <stdlib.h> - -#include "config.h" - -#if defined(HAVE_MD5_H) && !defined(DEPGEN) -#include <md5.h> -#endif - -#ifdef SHA2_H -# include SHA2_H -#endif - -#ifndef __arraycount -#define __arraycount(__x) (sizeof(__x) / sizeof(__x[0])) -#endif - -#if 0 -#include <md2.h> -#include <md4.h> -#include <md5.h> -#include <rmd160.h> -#include <sha1.h> -#include <sha2.h> -#endif - -#ifndef MD5_BLOCK_LENGTH -#define MD5_BLOCK_LENGTH 64 -#endif -#ifndef SHA256_BLOCK_LENGTH -#define SHA256_BLOCK_LENGTH 64 -#endif - -#define HMAC_SIZE 128 -#define HMAC_IPAD 0x36 -#define HMAC_OPAD 0x5C - -static const struct hmac { - const char *name; - size_t ctxsize; - size_t digsize; - size_t blocksize; - void (*init)(void *); - void (*update)(void *, const uint8_t *, unsigned int); - void (*final)(uint8_t *, void *); -} hmacs[] = { -#if 0 - { - "md2", sizeof(MD2_CTX), MD2_DIGEST_LENGTH, MD2_BLOCK_LENGTH, - (void *)MD2Init, (void *)MD2Update, (void *)MD2Final, - }, - { - "md4", sizeof(MD4_CTX), MD4_DIGEST_LENGTH, MD4_BLOCK_LENGTH, - (void *)MD4Init, (void *)MD4Update, (void *)MD4Final, - }, -#endif - { - "md5", sizeof(MD5_CTX), MD5_DIGEST_LENGTH, MD5_BLOCK_LENGTH, - (void *)MD5Init, (void *)MD5Update, (void *)MD5Final, - }, -#if 0 - { - "rmd160", sizeof(RMD160_CTX), RMD160_DIGEST_LENGTH, - RMD160_BLOCK_LENGTH, - (void *)RMD160Init, (void *)RMD160Update, (void *)RMD160Final, - }, - { - "sha1", sizeof(SHA1_CTX), SHA1_DIGEST_LENGTH, SHA1_BLOCK_LENGTH, - (void *)SHA1Init, (void *)SHA1Update, (void *)SHA1Final, - }, - { - "sha224", sizeof(SHA224_CTX), SHA224_DIGEST_LENGTH, - SHA224_BLOCK_LENGTH, - (void *)SHA224_Init, (void *)SHA224_Update, - (void *)SHA224_Final, - }, -#endif - { - "sha256", sizeof(SHA256_CTX), SHA256_DIGEST_LENGTH, - SHA256_BLOCK_LENGTH, - (void *)SHA256_Init, (void *)SHA256_Update, - (void *)SHA256_Final, - }, -#if 0 - { - "sha384", sizeof(SHA384_CTX), SHA384_DIGEST_LENGTH, - SHA384_BLOCK_LENGTH, - (void *)SHA384_Init, (void *)SHA384_Update, - (void *)SHA384_Final, - }, - { - "sha512", sizeof(SHA512_CTX), SHA512_DIGEST_LENGTH, - SHA512_BLOCK_LENGTH, - (void *)SHA512_Init, (void *)SHA512_Update, - (void *)SHA512_Final, - }, -#endif -}; - -static const struct hmac * -hmac_find(const char *name) -{ - for (size_t i = 0; i < __arraycount(hmacs); i++) { - if (strcmp(hmacs[i].name, name) != 0) - continue; - return &hmacs[i]; - } - return NULL; -} - -ssize_t -hmac(const char *name, - const void *key, size_t klen, - const void *text, size_t tlen, - void *digest, size_t dlen) -{ - uint8_t ipad[HMAC_SIZE], opad[HMAC_SIZE], d[HMAC_SIZE]; - const uint8_t *k = key; - const struct hmac *h; - uint64_t c[32]; - void *p; - - if ((h = hmac_find(name)) == NULL) - return -1; - - - if (klen > h->blocksize) { - (*h->init)(c); - (*h->update)(c, k, (unsigned int)klen); - (*h->final)(d, c); - k = (void *)d; - klen = h->digsize; - } - - /* Form input and output pads for the digests */ - for (size_t i = 0; i < sizeof(ipad); i++) { - ipad[i] = (i < klen ? k[i] : 0) ^ HMAC_IPAD; - opad[i] = (i < klen ? k[i] : 0) ^ HMAC_OPAD; - } - - p = dlen >= h->digsize ? digest : d; - if (p != digest) { - memcpy(p, digest, dlen); - memset((char *)p + dlen, 0, h->digsize - dlen); - } - (*h->init)(c); - (*h->update)(c, ipad, (unsigned int)h->blocksize); - (*h->update)(c, text, (unsigned int)tlen); - (*h->final)(p, c); - - (*h->init)(c); - (*h->update)(c, opad, (unsigned int)h->blocksize); - (*h->update)(c, digest, (unsigned int)h->digsize); - (*h->final)(p, c); - - if (p != digest) - memcpy(digest, p, dlen); - - return (ssize_t)h->digsize; -} diff --git a/external/bsd/dhcpcd/dist/compat/crypt/hmac.h b/external/bsd/dhcpcd/dist/compat/crypt/hmac.h deleted file mode 100644 index 18b859e917c..00000000000 --- a/external/bsd/dhcpcd/dist/compat/crypt/hmac.h +++ /dev/null @@ -1,40 +0,0 @@ -/* $NetBSD: hmac.h,v 1.1.1.1 2017/10/07 14:05:36 roy Exp $ */ - -/*- - * Copyright (c) 2016 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software contributed to The NetBSD Foundation - * by Christos Zoulas. - * - * 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. - * - * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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. - */ - -#ifndef HMAC_H -#define HMAC_H - -#include <sys/types.h> - -ssize_t hmac(const char *, const void *, size_t, const void *, size_t, void *, - size_t); - -#endif diff --git a/external/bsd/dhcpcd/dist/compat/crypt/md5.c b/external/bsd/dhcpcd/dist/compat/crypt/md5.c deleted file mode 100644 index dea2356de76..00000000000 --- a/external/bsd/dhcpcd/dist/compat/crypt/md5.c +++ /dev/null @@ -1,242 +0,0 @@ -/* - * This code implements the MD5 message-digest algorithm. - * The algorithm is due to Ron Rivest. This code was - * written by Colin Plumb in 1993, no copyright is claimed. - * This code is in the public domain; do with it what you wish. - * - * Equivalent code is available from RSA Data Security, Inc. - * This code has been tested against that, and is equivalent, - * except that you don't need to include two pages of legalese - * with every copy. - * - * To compute the message digest of a chunk of bytes, declare an - * MD5Context structure, pass it to MD5Init, call MD5Update as - * needed on buffers full of bytes, and then call MD5Final, which - * will fill a supplied 16-byte array with the digest. - */ - -#include <sys/param.h> -#include <inttypes.h> - -#include <string.h> - -#include "md5.h" - -#define PUT_64BIT_LE(cp, value) do { \ - (cp)[7] = (uint8_t)((value) >> 56); \ - (cp)[6] = (uint8_t)((value) >> 48); \ - (cp)[5] = (uint8_t)((value) >> 40); \ - (cp)[4] = (uint8_t)((value) >> 32); \ - (cp)[3] = (uint8_t)((value) >> 24); \ - (cp)[2] = (uint8_t)((value) >> 16); \ - (cp)[1] = (uint8_t)((value) >> 8); \ - (cp)[0] = (uint8_t)(value); } while (0) - -#define PUT_32BIT_LE(cp, value) do { \ - (cp)[3] = (uint8_t)((value) >> 24); \ - (cp)[2] = (uint8_t)((value) >> 16); \ - (cp)[1] = (uint8_t)((value) >> 8); \ - (cp)[0] = (uint8_t)(value); } while (0) - -static uint8_t PADDING[MD5_BLOCK_LENGTH] = { - 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 -}; - -/* - * Start MD5 accumulation. Set bit count to 0 and buffer to mysterious - * initialization constants. - */ -void -MD5Init(MD5_CTX *ctx) -{ - ctx->count = 0; - ctx->state[0] = 0x67452301; - ctx->state[1] = 0xefcdab89; - ctx->state[2] = 0x98badcfe; - ctx->state[3] = 0x10325476; -} - - -/* The four core functions - F1 is optimized somewhat */ - -/* #define F1(x, y, z) (x & y | ~x & z) */ -#define F1(x, y, z) (z ^ (x & (y ^ z))) -#define F2(x, y, z) F1(z, x, y) -#define F3(x, y, z) (x ^ y ^ z) -#define F4(x, y, z) (y ^ (x | ~z)) - -/* This is the central step in the MD5 algorithm. */ -#define MD5STEP(f, w, x, y, z, data, s) \ - ( w += f(x, y, z) + data, w = w<<s | w>>(32-s), w += x ) - -/* - * The core of the MD5 algorithm, this alters an existing MD5 hash to - * reflect the addition of 16 longwords of new data. MD5Update blocks - * the data and converts bytes into longwords for this routine. - */ -static void -MD5Transform(uint32_t state[4], const uint8_t block[MD5_BLOCK_LENGTH]) -{ - uint32_t a, b, c, d, in[MD5_BLOCK_LENGTH / 4]; - -#if BYTE_ORDER == LITTLE_ENDIAN - memcpy(in, block, sizeof(in)); -#else - for (a = 0; a < MD5_BLOCK_LENGTH / 4; a++) { - in[a] = (uint32_t)( - (uint32_t)(block[a * 4 + 0]) | - (uint32_t)(block[a * 4 + 1]) << 8 | - (uint32_t)(block[a * 4 + 2]) << 16 | - (uint32_t)(block[a * 4 + 3]) << 24); - } -#endif - - a = state[0]; - b = state[1]; - c = state[2]; - d = state[3]; - - MD5STEP(F1, a, b, c, d, in[ 0] + 0xd76aa478, 7); - MD5STEP(F1, d, a, b, c, in[ 1] + 0xe8c7b756, 12); - MD5STEP(F1, c, d, a, b, in[ 2] + 0x242070db, 17); - MD5STEP(F1, b, c, d, a, in[ 3] + 0xc1bdceee, 22); - MD5STEP(F1, a, b, c, d, in[ 4] + 0xf57c0faf, 7); - MD5STEP(F1, d, a, b, c, in[ 5] + 0x4787c62a, 12); - MD5STEP(F1, c, d, a, b, in[ 6] + 0xa8304613, 17); - MD5STEP(F1, b, c, d, a, in[ 7] + 0xfd469501, 22); - MD5STEP(F1, a, b, c, d, in[ 8] + 0x698098d8, 7); - MD5STEP(F1, d, a, b, c, in[ 9] + 0x8b44f7af, 12); - MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17); - MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22); - MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7); - MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12); - MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17); - MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22); - - MD5STEP(F2, a, b, c, d, in[ 1] + 0xf61e2562, 5); - MD5STEP(F2, d, a, b, c, in[ 6] + 0xc040b340, 9); - MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14); - MD5STEP(F2, b, c, d, a, in[ 0] + 0xe9b6c7aa, 20); - MD5STEP(F2, a, b, c, d, in[ 5] + 0xd62f105d, 5); - MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9); - MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14); - MD5STEP(F2, b, c, d, a, in[ 4] + 0xe7d3fbc8, 20); - MD5STEP(F2, a, b, c, d, in[ 9] + 0x21e1cde6, 5); - MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9); - MD5STEP(F2, c, d, a, b, in[ 3] + 0xf4d50d87, 14); - MD5STEP(F2, b, c, d, a, in[ 8] + 0x455a14ed, 20); - MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5); - MD5STEP(F2, d, a, b, c, in[ 2] + 0xfcefa3f8, 9); - MD5STEP(F2, c, d, a, b, in[ 7] + 0x676f02d9, 14); - MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20); - - MD5STEP(F3, a, b, c, d, in[ 5] + 0xfffa3942, 4); - MD5STEP(F3, d, a, b, c, in[ 8] + 0x8771f681, 11); - MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16); - MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23); - MD5STEP(F3, a, b, c, d, in[ 1] + 0xa4beea44, 4); - MD5STEP(F3, d, a, b, c, in[ 4] + 0x4bdecfa9, 11); - MD5STEP(F3, c, d, a, b, in[ 7] + 0xf6bb4b60, 16); - MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23); - MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4); - MD5STEP(F3, d, a, b, c, in[ 0] + 0xeaa127fa, 11); - MD5STEP(F3, c, d, a, b, in[ 3] + 0xd4ef3085, 16); - MD5STEP(F3, b, c, d, a, in[ 6] + 0x04881d05, 23); - MD5STEP(F3, a, b, c, d, in[ 9] + 0xd9d4d039, 4); - MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11); - MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16); - MD5STEP(F3, b, c, d, a, in[2 ] + 0xc4ac5665, 23); - - MD5STEP(F4, a, b, c, d, in[ 0] + 0xf4292244, 6); - MD5STEP(F4, d, a, b, c, in[7 ] + 0x432aff97, 10); - MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15); - MD5STEP(F4, b, c, d, a, in[5 ] + 0xfc93a039, 21); - MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6); - MD5STEP(F4, d, a, b, c, in[3 ] + 0x8f0ccc92, 10); - MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15); - MD5STEP(F4, b, c, d, a, in[1 ] + 0x85845dd1, 21); - MD5STEP(F4, a, b, c, d, in[8 ] + 0x6fa87e4f, 6); - MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10); - MD5STEP(F4, c, d, a, b, in[6 ] + 0xa3014314, 15); - MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21); - MD5STEP(F4, a, b, c, d, in[4 ] + 0xf7537e82, 6); - MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10); - MD5STEP(F4, c, d, a, b, in[2 ] + 0x2ad7d2bb, 15); - MD5STEP(F4, b, c, d, a, in[9 ] + 0xeb86d391, 21); - - state[0] += a; - state[1] += b; - state[2] += c; - state[3] += d; -} - -/* - * Update context to reflect the concatenation of another buffer full - * of bytes. - */ -void -MD5Update(MD5_CTX *ctx, const unsigned char *input, size_t len) -{ - size_t have, need; - - /* Check how many bytes we already have and how many more we need. */ - have = (size_t)((ctx->count >> 3) & (MD5_BLOCK_LENGTH - 1)); - need = MD5_BLOCK_LENGTH - have; - - /* Update bitcount */ - ctx->count += (uint64_t)len << 3; - - if (len >= need) { - if (have != 0) { - memcpy(ctx->buffer + have, input, need); - MD5Transform(ctx->state, ctx->buffer); - input += need; - len -= need; - have = 0; - } - - /* Process data in MD5_BLOCK_LENGTH-byte chunks. */ - while (len >= MD5_BLOCK_LENGTH) { - MD5Transform(ctx->state, input); - input += MD5_BLOCK_LENGTH; - len -= MD5_BLOCK_LENGTH; - } - } - - /* Handle any remaining bytes of data. */ - if (len != 0) - memcpy(ctx->buffer + have, input, len); -} - -/* - * Final wrapup - pad to 64-byte boundary with the bit pattern - * 1 0* (64-bit count of bits processed, MSB-first) - */ -void -MD5Final(unsigned char digest[MD5_DIGEST_LENGTH], MD5_CTX *ctx) -{ - uint8_t count[8]; - size_t padlen; - int i; - - /* Convert count to 8 bytes in little endian order. */ - PUT_64BIT_LE(count, ctx->count); - - /* Pad out to 56 mod 64. */ - padlen = MD5_BLOCK_LENGTH - - ((ctx->count >> 3) & (MD5_BLOCK_LENGTH - 1)); - if (padlen < 1 + 8) - padlen += MD5_BLOCK_LENGTH; - MD5Update(ctx, PADDING, padlen - 8); /* padlen - 8 <= 64 */ - MD5Update(ctx, count, 8); - - if (digest != NULL) { - for (i = 0; i < 4; i++) - PUT_32BIT_LE(digest + i * 4, ctx->state[i]); - } - memset(ctx, 0, sizeof(*ctx)); /* in case it's sensitive */ -} - - diff --git a/external/bsd/dhcpcd/dist/compat/crypt/md5.h b/external/bsd/dhcpcd/dist/compat/crypt/md5.h deleted file mode 100644 index dd156163315..00000000000 --- a/external/bsd/dhcpcd/dist/compat/crypt/md5.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * This code implements the MD5 message-digest algorithm. - * The algorithm is due to Ron Rivest. This code was - * written by Colin Plumb in 1993, no copyright is claimed. - * This code is in the public domain; do with it what you wish. - * - * Equivalent code is available from RSA Data Security, Inc. - * This code has been tested against that, and is equivalent, - * except that you don't need to include two pages of legalese - * with every copy. - * - * To compute the message digest of a chunk of bytes, declare an - * MD5Context structure, pass it to MD5Init, call MD5Update as - * needed on buffers full of bytes, and then call MD5Final, which - * will fill a supplied 16-byte array with the digest. - */ - -#ifndef MD5_H_ -#define MD5_H_ - -#define MD5_DIGEST_LENGTH 16 -#define MD5_BLOCK_LENGTH 64ULL - -typedef struct MD5Context { - uint32_t state[4]; /* state (ABCD) */ - uint64_t count; /* number of bits, modulo 2^64 (lsb first) */ - unsigned char buffer[MD5_BLOCK_LENGTH]; /* input buffer */ -} MD5_CTX; - -void MD5Init(MD5_CTX *); -void MD5Update(MD5_CTX *, const unsigned char *, size_t); -void MD5Final(unsigned char[MD5_DIGEST_LENGTH], MD5_CTX *); -#endif diff --git a/external/bsd/dhcpcd/dist/compat/crypt/sha256.c b/external/bsd/dhcpcd/dist/compat/crypt/sha256.c deleted file mode 100644 index 73c43c037fa..00000000000 --- a/external/bsd/dhcpcd/dist/compat/crypt/sha256.c +++ /dev/null @@ -1,303 +0,0 @@ -/*- - * Copyright 2005 Colin Percival - * 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. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. - */ - -#include <inttypes.h> - -#include <string.h> - -#ifdef __GLIBC__ -# include <endian.h> -#endif -#ifdef BSD -# ifndef __QNX__ -# include <sys/endian.h> -# endif -#endif - -#include "config.h" -#include "sha256.h" - -#if BYTE_ORDER == BIG_ENDIAN - -/* Copy a vector of big-endian uint32_t into a vector of bytes */ -#define be32enc_vect(dst, src, len) \ - memcpy((void *)dst, (const void *)src, (size_t)len) - -/* Copy a vector of bytes into a vector of big-endian uint32_t */ -#define be32dec_vect(dst, src, len) \ - memcpy((void *)dst, (const void *)src, (size_t)len) - -#else /* BYTE_ORDER != BIG_ENDIAN */ - -/* - * Encode a length len/4 vector of (uint32_t) into a length len vector of - * (unsigned char) in big-endian form. Assumes len is a multiple of 4. - */ -static void -be32enc_vect(unsigned char *dst, const uint32_t *src, size_t len) -{ - size_t i; - - for (i = 0; i < len / 4; i++) - be32enc(dst + i * 4, src[i]); -} - -/* - * Decode a big-endian length len vector of (unsigned char) into a length - * len/4 vector of (uint32_t). Assumes len is a multiple of 4. - */ -static void -be32dec_vect(uint32_t *dst, const unsigned char *src, size_t len) -{ - size_t i; - - for (i = 0; i < len / 4; i++) - dst[i] = be32dec(src + i * 4); -} - -#endif /* BYTE_ORDER != BIG_ENDIAN */ - -/* Elementary functions used by SHA256 */ -#define Ch(x, y, z) ((x & (y ^ z)) ^ z) -#define Maj(x, y, z) ((x & (y | z)) | (y & z)) -#define SHR(x, n) (x >> n) -#define ROTR(x, n) ((x >> n) | (x << (32 - n))) -#define S0(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22)) -#define S1(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25)) -#define s0(x) (ROTR(x, 7) ^ ROTR(x, 18) ^ SHR(x, 3)) -#define s1(x) (ROTR(x, 17) ^ ROTR(x, 19) ^ SHR(x, 10)) - -/* SHA256 round function */ -#define RND(a, b, c, d, e, f, g, h, k) \ - t0 = h + S1(e) + Ch(e, f, g) + k; \ - t1 = S0(a) + Maj(a, b, c); \ - d += t0; \ - h = t0 + t1; - -/* Adjusted round function for rotating state */ -#define RNDr(S, W, i, k) \ - RND(S[(64 - i) % 8], S[(65 - i) % 8], \ - S[(66 - i) % 8], S[(67 - i) % 8], \ - S[(68 - i) % 8], S[(69 - i) % 8], \ - S[(70 - i) % 8], S[(71 - i) % 8], \ - W[i] + k) - -/* - * SHA256 block compression function. The 256-bit state is transformed via - * the 512-bit input block to produce a new state. - */ -static void -SHA256_Transform(uint32_t * state, const unsigned char block[64]) -{ - uint32_t W[64]; - uint32_t S[8]; - uint32_t t0, t1; - int i; - - /* 1. Prepare message schedule W. */ - be32dec_vect(W, block, 64); - for (i = 16; i < 64; i++) - W[i] = s1(W[i - 2]) + W[i - 7] + s0(W[i - 15]) + W[i - 16]; - - /* 2. Initialize working variables. */ - memcpy(S, state, 32); - - /* 3. Mix. */ - RNDr(S, W, 0, 0x428a2f98); - RNDr(S, W, 1, 0x71374491); - RNDr(S, W, 2, 0xb5c0fbcf); - RNDr(S, W, 3, 0xe9b5dba5); - RNDr(S, W, 4, 0x3956c25b); - RNDr(S, W, 5, 0x59f111f1); - RNDr(S, W, 6, 0x923f82a4); - RNDr(S, W, 7, 0xab1c5ed5); - RNDr(S, W, 8, 0xd807aa98); - RNDr(S, W, 9, 0x12835b01); - RNDr(S, W, 10, 0x243185be); - RNDr(S, W, 11, 0x550c7dc3); - RNDr(S, W, 12, 0x72be5d74); - RNDr(S, W, 13, 0x80deb1fe); - RNDr(S, W, 14, 0x9bdc06a7); - RNDr(S, W, 15, 0xc19bf174); - RNDr(S, W, 16, 0xe49b69c1); - RNDr(S, W, 17, 0xefbe4786); - RNDr(S, W, 18, 0x0fc19dc6); - RNDr(S, W, 19, 0x240ca1cc); - RNDr(S, W, 20, 0x2de92c6f); - RNDr(S, W, 21, 0x4a7484aa); - RNDr(S, W, 22, 0x5cb0a9dc); - RNDr(S, W, 23, 0x76f988da); - RNDr(S, W, 24, 0x983e5152); - RNDr(S, W, 25, 0xa831c66d); - RNDr(S, W, 26, 0xb00327c8); - RNDr(S, W, 27, 0xbf597fc7); - RNDr(S, W, 28, 0xc6e00bf3); - RNDr(S, W, 29, 0xd5a79147); - RNDr(S, W, 30, 0x06ca6351); - RNDr(S, W, 31, 0x14292967); - RNDr(S, W, 32, 0x27b70a85); - RNDr(S, W, 33, 0x2e1b2138); - RNDr(S, W, 34, 0x4d2c6dfc); - RNDr(S, W, 35, 0x53380d13); - RNDr(S, W, 36, 0x650a7354); - RNDr(S, W, 37, 0x766a0abb); - RNDr(S, W, 38, 0x81c2c92e); - RNDr(S, W, 39, 0x92722c85); - RNDr(S, W, 40, 0xa2bfe8a1); - RNDr(S, W, 41, 0xa81a664b); - RNDr(S, W, 42, 0xc24b8b70); - RNDr(S, W, 43, 0xc76c51a3); - RNDr(S, W, 44, 0xd192e819); - RNDr(S, W, 45, 0xd6990624); - RNDr(S, W, 46, 0xf40e3585); - RNDr(S, W, 47, 0x106aa070); - RNDr(S, W, 48, 0x19a4c116); - RNDr(S, W, 49, 0x1e376c08); - RNDr(S, W, 50, 0x2748774c); - RNDr(S, W, 51, 0x34b0bcb5); - RNDr(S, W, 52, 0x391c0cb3); - RNDr(S, W, 53, 0x4ed8aa4a); - RNDr(S, W, 54, 0x5b9cca4f); - RNDr(S, W, 55, 0x682e6ff3); - RNDr(S, W, 56, 0x748f82ee); - RNDr(S, W, 57, 0x78a5636f); - RNDr(S, W, 58, 0x84c87814); - RNDr(S, W, 59, 0x8cc70208); - RNDr(S, W, 60, 0x90befffa); - RNDr(S, W, 61, 0xa4506ceb); - RNDr(S, W, 62, 0xbef9a3f7); - RNDr(S, W, 63, 0xc67178f2); - - /* 4. Mix local working variables into global state */ - for (i = 0; i < 8; i++) - state[i] += S[i]; -} - -static unsigned char PAD[64] = { - 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 -}; - -/* Add padding and terminating bit-count. */ -static void -SHA256_Pad(SHA256_CTX * ctx) -{ - unsigned char len[8]; - uint32_t r, plen; - - /* - * Convert length to a vector of bytes -- we do this now rather - * than later because the length will change after we pad. - */ - be64enc(len, ctx->count); - - /* Add 1--64 bytes so that the resulting length is 56 mod 64 */ - r = (ctx->count >> 3) & 0x3f; - plen = (r < 56) ? (56 - r) : (120 - r); - SHA256_Update(ctx, PAD, (size_t)plen); - - /* Add the terminating bit-count */ - SHA256_Update(ctx, len, 8); -} - -/* SHA-256 initialization. Begins a SHA-256 operation. */ -void -SHA256_Init(SHA256_CTX * ctx) -{ - - /* Zero bits processed so far */ - ctx->count = 0; - - /* Magic initialization constants */ - ctx->state[0] = 0x6A09E667; - ctx->state[1] = 0xBB67AE85; - ctx->state[2] = 0x3C6EF372; - ctx->state[3] = 0xA54FF53A; - ctx->state[4] = 0x510E527F; - ctx->state[5] = 0x9B05688C; - ctx->state[6] = 0x1F83D9AB; - ctx->state[7] = 0x5BE0CD19; -} - -/* Add bytes into the hash */ -void -SHA256_Update(SHA256_CTX * ctx, const void *in, size_t len) -{ - uint64_t bitlen; - uint32_t r; - const unsigned char *src = in; - - /* Number of bytes left in the buffer from previous updates */ - r = (ctx->count >> 3) & 0x3f; - - /* Convert the length into a number of bits */ - bitlen = len << 3; - - /* Update number of bits */ - ctx->count += bitlen; - - /* Handle the case where we don't need to perform any transforms */ - if (len < 64 - r) { - memcpy(&ctx->buf[r], src, len); - return; - } - - /* Finish the current block */ - memcpy(&ctx->buf[r], src, 64 - r); - SHA256_Transform(ctx->state, ctx->buf); - src += 64 - r; - len -= 64 - r; - - /* Perform complete blocks */ - while (len >= 64) { - SHA256_Transform(ctx->state, src); - src += 64; - len -= 64; - } - - /* Copy left over data into buffer */ - memcpy(ctx->buf, src, len); -} - -/* - * SHA-256 finalization. Pads the input data, exports the hash value, - * and clears the context state. - */ -void -SHA256_Final(unsigned char digest[32], SHA256_CTX * ctx) -{ - - /* Add padding */ - SHA256_Pad(ctx); - - /* Write the hash */ - be32enc_vect(digest, ctx->state, 32); - - /* Clear the context state */ - memset((void *)ctx, 0, sizeof(*ctx)); -} diff --git a/external/bsd/dhcpcd/dist/compat/crypt/sha256.h b/external/bsd/dhcpcd/dist/compat/crypt/sha256.h deleted file mode 100644 index 02a09f935b2..00000000000 --- a/external/bsd/dhcpcd/dist/compat/crypt/sha256.h +++ /dev/null @@ -1,46 +0,0 @@ -/*- - * Copyright 2005 Colin Percival - * 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. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. - * - * $FreeBSD$ - */ - -#ifndef SHA256_H_ -#define SHA256_H_ - -#include <sys/types.h> - -#define SHA256_DIGEST_LENGTH 32 - -typedef struct SHA256Context { - uint32_t state[8]; - uint64_t count; - unsigned char buf[64]; -} SHA256_CTX; - -void SHA256_Init(SHA256_CTX *); -void SHA256_Update(SHA256_CTX *, const void *, size_t); -void SHA256_Final(unsigned char [32], SHA256_CTX *); - -#endif diff --git a/external/bsd/dhcpcd/dist/compat/dprintf.c b/external/bsd/dhcpcd/dist/compat/dprintf.c deleted file mode 100644 index 2ef81ade814..00000000000 --- a/external/bsd/dhcpcd/dist/compat/dprintf.c +++ /dev/null @@ -1,64 +0,0 @@ -/* - * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2017 Roy Marples <roy@marples.name> - * 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. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. - */ - -#include <stdlib.h> -#include <stdio.h> -#include <stdarg.h> -#include <unistd.h> - -#include "dprintf.h" - -int -vdprintf(int fd, const char * __restrict fmt, va_list va) -{ - int e; - FILE *fp; - - if ((e = dup(fd)) == -1) - return -1; - - if ((fp = fdopen(e, "a")) == NULL) { - close(e); - return -1; - } - - e = vfprintf(fp, fmt, va); - fclose(fp); - return e; -} - -int -dprintf(int fd, const char * __restrict fmt, ...) -{ - int e; - va_list va; - - va_start(va, fmt); - e = vdprintf(fd, fmt, va); - va_end(va); - return e; -} diff --git a/external/bsd/dhcpcd/dist/compat/dprintf.h b/external/bsd/dhcpcd/dist/compat/dprintf.h deleted file mode 100644 index 9defbcb835f..00000000000 --- a/external/bsd/dhcpcd/dist/compat/dprintf.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2017 Roy Marples <roy@marples.name> - * 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. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. - */ - -#ifndef DPRINTF_H -#define DPRINTF_H - -#include <stdarg.h> - -#ifndef __printflike -# if __GNUC__ > 2 || defined(__INTEL_COMPILER) -# define __printflike(a, b) __attribute__((format(printf, a, b))) -# else -# define __printflike(a, b) -# endif -#endif - -__printflike(2, 0) int vdprintf(int, const char * __restrict, va_list); -__printflike(2, 3) int dprintf(int, const char * __restrict, ...); -#endif diff --git a/external/bsd/dhcpcd/dist/compat/endian.h b/external/bsd/dhcpcd/dist/compat/endian.h deleted file mode 100644 index 8d01738bd24..00000000000 --- a/external/bsd/dhcpcd/dist/compat/endian.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2014 Roy Marples <roy@marples.name> - * 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. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. - */ - -#ifndef ENDIAN_H -#define ENDIAN_H - -#include <stdint.h> - -inline static void -be32enc(uint8_t *buf, uint32_t u) -{ - - buf[0] = (uint8_t)((u >> 24) & 0xff); - buf[1] = (uint8_t)((u >> 16) & 0xff); - buf[2] = (uint8_t)((u >> 8) & 0xff); - buf[3] = (uint8_t)(u & 0xff); -} - -inline static void -be64enc(uint8_t *buf, uint64_t u) -{ - - be32enc(buf, (uint32_t)(u >> 32)); - be32enc(buf + sizeof(uint32_t), (uint32_t)(u & 0xffffffffULL)); -} - -inline static uint16_t -be16dec(const uint8_t *buf) -{ - - return (uint16_t)(buf[0] << 8 | buf[1]); -} - -inline static uint32_t -be32dec(const uint8_t *buf) -{ - - return (uint32_t)((uint32_t)be16dec(buf) << 16 | be16dec(buf + 2)); -} - -inline static uint64_t -be64dec(const uint8_t *buf) -{ - - return (uint64_t)((uint64_t)be32dec(buf) << 32 | be32dec(buf + 4)); -} -#endif diff --git a/external/bsd/dhcpcd/dist/compat/pidfile.c b/external/bsd/dhcpcd/dist/compat/pidfile.c deleted file mode 100644 index 658bc7f0111..00000000000 --- a/external/bsd/dhcpcd/dist/compat/pidfile.c +++ /dev/null @@ -1,269 +0,0 @@ -/* $NetBSD: pidfile.c,v 1.1.1.1 2017/03/31 20:51:15 roy Exp $ */ - -/*- - * Copyright (c) 1999, 2016 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software contributed to The NetBSD Foundation - * by Jason R. Thorpe, Matthias Scheler, Julio Merino and Roy Marples. - * - * 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. - * - * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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. - */ - -#include <sys/param.h> - -#include <errno.h> -#include <fcntl.h> -#include <inttypes.h> -#include <limits.h> -#include <paths.h> -#include <stdbool.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <unistd.h> - -#include <sys/file.h> /* for flock(2) */ -#include "config.h" -#include "defs.h" - -static pid_t pidfile_pid; -static char pidfile_path[PATH_MAX]; -static int pidfile_fd = -1; - -/* Closes pidfile resources. - * - * Returns 0 on success, otherwise -1. */ -static int -pidfile_close(void) -{ - int error; - - pidfile_pid = 0; - error = close(pidfile_fd); - pidfile_fd = -1; - pidfile_path[0] = '\0'; - return error; -} - -/* Truncate, close and unlink an existent pidfile, - * if and only if it was created by this process. - * The pidfile is truncated because we may have dropped permissions - * or entered a chroot and thus unable to unlink it. - * - * Returns 0 on truncation success, otherwise -1. */ -int -pidfile_clean(void) -{ - int error; - - if (pidfile_fd == -1) { - errno = EBADF; - return -1; - } - - if (pidfile_pid != getpid()) - error = EPERM; - else if (ftruncate(pidfile_fd, 0) == -1) - error = errno; - else { - (void) unlink(pidfile_path); - error = 0; - } - - (void) pidfile_close(); - - if (error != 0) { - errno = error; - return -1; - } - return 0; -} - -/* atexit shim for pidfile_clean */ -static void -pidfile_cleanup(void) -{ - - pidfile_clean(); -} - -/* Constructs a name for a pidfile in the default location (/var/run). - * If 'bname' is NULL, uses the name of the current program for the name of - * the pidfile. - * - * Returns 0 on success, otherwise -1. */ -static int -pidfile_varrun_path(char *path, size_t len, const char *bname) -{ - - if (bname == NULL) - bname = PACKAGE; - - /* _PATH_VARRUN includes trailing / */ - if ((size_t)snprintf(path, len, "%s%s.pid", _PATH_VARRUN, bname) >= len) - { - errno = ENAMETOOLONG; - return -1; - } - return 0; -} - -/* Returns the process ID inside path on success, otherwise -1. - * If no path is given, use the last pidfile path, othewise the default one. */ -pid_t -pidfile_read(const char *path) -{ - char dpath[PATH_MAX], buf[16], *eptr; - int fd, error; - ssize_t n; - pid_t pid; - - if (path == NULL && pidfile_path[0] != '\0') - path = pidfile_path; - if (path == NULL || strchr(path, '/') == NULL) { - if (pidfile_varrun_path(dpath, sizeof(dpath), path) == -1) - return -1; - path = dpath; - } - - if ((fd = open(path, O_RDONLY | O_NONBLOCK)) == -1) - return -1; - n = read(fd, buf, sizeof(buf) - 1); - error = errno; - (void) close(fd); - if (n == -1) { - errno = error; - return -1; - } - buf[n] = '\0'; - pid = (pid_t)strtoi(buf, &eptr, 10, 1, INT_MAX, &error); - if (error && !(error == ENOTSUP && *eptr == '\n')) { - errno = error; - return -1; - } - return pid; -} - -/* Locks the pidfile specified by path and writes the process pid to it. - * The new pidfile is "registered" in the global variables pidfile_fd, - * pidfile_path and pidfile_pid so that any further call to pidfile_lock(3) - * can check if we are recreating the same file or a new one. - * - * Returns 0 on success, otherwise the pid of the process who owns the - * lock if it can be read, otherwise -1. */ -pid_t -pidfile_lock(const char *path) -{ - char dpath[PATH_MAX]; - static bool registered_atexit = false; - - /* Register for cleanup with atexit. */ - if (!registered_atexit) { - if (atexit(pidfile_cleanup) == -1) - return -1; - registered_atexit = true; - } - - if (path == NULL || strchr(path, '/') == NULL) { - if (pidfile_varrun_path(dpath, sizeof(dpath), path) == -1) - return -1; - path = dpath; - } - - /* If path has changed (no good reason), clean up the old pidfile. */ - if (pidfile_fd != -1 && strcmp(pidfile_path, path) != 0) - pidfile_clean(); - - if (pidfile_fd == -1) { - int fd, opts; - - opts = O_WRONLY | O_CREAT | O_NONBLOCK; -#ifdef O_CLOEXEC - opts |= O_CLOEXEC; -#endif -#ifdef O_EXLOCK - opts |= O_EXLOCK; -#endif - if ((fd = open(path, opts, 0644)) == -1) - goto return_pid; -#ifndef O_CLOEXEC - if ((opts = fcntl(fd, F_GETFD)) == -1 || - fctnl(fd, F_SETFL, opts | FD_CLOEXEC) == -1) - { - int error = errno; - - (void) close(fd); - errno = error; - return -1; - } -#endif -#ifndef O_EXLOCK - if (flock(fd, LOCK_EX | LOCK_NB) == -1) { - int error = errno; - - (void) close(fd); - if (error != EAGAIN) { - errno = error; - return -1; - } - fd = -1; - } -#endif - -return_pid: - if (fd == -1) { - pid_t pid; - - if (errno == EAGAIN) { - /* The pidfile is locked, return the process ID - * it contains. - * If sucessful, set errno to EEXIST. */ - if ((pid = pidfile_read(path)) != -1) - errno = EEXIST; - } else - pid = -1; - - return pid; - } - pidfile_fd = fd; - strlcpy(pidfile_path, path, sizeof(pidfile_path)); - } - - pidfile_pid = getpid(); - - /* Truncate the file, as we could be re-writing it. - * Then write the process ID. */ - if (ftruncate(pidfile_fd, 0) == -1 || - lseek(pidfile_fd, 0, SEEK_SET) == -1 || - dprintf(pidfile_fd, "%d\n", pidfile_pid) == -1) - { - int error = errno; - - pidfile_cleanup(); - errno = error; - return -1; - } - - /* Hold the fd open to persist the lock. */ - return 0; -} diff --git a/external/bsd/dhcpcd/dist/compat/pidfile.h b/external/bsd/dhcpcd/dist/compat/pidfile.h deleted file mode 100644 index ed833e15232..00000000000 --- a/external/bsd/dhcpcd/dist/compat/pidfile.h +++ /dev/null @@ -1,39 +0,0 @@ -/*- - * Copyright (c) 1999, 2016 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software contributed to The NetBSD Foundation - * by Jason R. Thorpe, Matthias Scheler, Julio Merino and Roy Marples. - * - * 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. - * - * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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. - */ - -#ifndef PIDFILE_H -#define PIDFILE_H - -#include <unistd.h> - -int pidfile_clean(void); -pid_t pidfile_lock(const char *); -pid_t pidfile_read(const char *); - -#endif diff --git a/external/bsd/dhcpcd/dist/compat/queue.h b/external/bsd/dhcpcd/dist/compat/queue.h deleted file mode 100644 index d6622afccec..00000000000 --- a/external/bsd/dhcpcd/dist/compat/queue.h +++ /dev/null @@ -1,175 +0,0 @@ -/* $NetBSD: queue.h,v 1.1.1.1 2017/03/31 20:51:15 roy Exp $ */ - -/* - * Copyright (c) 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. - * - * @(#)queue.h 8.5 (Berkeley) 8/20/94 - */ - -#ifndef COMPAT_QUEUE_H -#define COMPAT_QUEUE_H - -/* - * Tail queue definitions. - */ -#ifndef TAILQ_END -#define TAILQ_END(head) (NULL) -#endif - -#ifndef TAILQ_HEAD -#define _TAILQ_HEAD(name, type, qual) \ -struct name { \ - qual type *tqh_first; /* first element */ \ - qual type *qual *tqh_last; /* addr of last next element */ \ -} -#define TAILQ_HEAD(name, type) _TAILQ_HEAD(name, struct type,) - -#define TAILQ_HEAD_INITIALIZER(head) \ - { TAILQ_END(head), &(head).tqh_first } - -#define _TAILQ_ENTRY(type, qual) \ -struct { \ - qual type *tqe_next; /* next element */ \ - qual type *qual *tqe_prev; /* address of previous next element */\ -} -#define TAILQ_ENTRY(type) _TAILQ_ENTRY(struct type,) -#endif /* !TAILQ_HEAD */ - -/* - * Tail queue access methods. - */ -#ifndef TAILQ_FIRST -#define TAILQ_FIRST(head) ((head)->tqh_first) -#define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next) -#define TAILQ_LAST(head, headname) \ - (*(((struct headname *)((head)->tqh_last))->tqh_last)) -#define TAILQ_PREV(elm, headname, field) \ - (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last)) -#define TAILQ_EMPTY(head) (TAILQ_FIRST(head) == TAILQ_END(head)) -#endif /* !TAILQ_FIRST */ - -#ifndef TAILQ_FOREACH -#define TAILQ_FOREACH(var, head, field) \ - for ((var) = ((head)->tqh_first); \ - (var) != TAILQ_END(head); \ - (var) = ((var)->field.tqe_next)) - -#define TAILQ_FOREACH_REVERSE(var, head, headname, field) \ - for ((var) = (*(((struct headname *)((head)->tqh_last))->tqh_last));\ - (var) != TAILQ_END(head); \ - (var) = (*(((struct headname *)((var)->field.tqe_prev))->tqh_last))) -#endif /* !TAILQ_FOREACH */ - -#ifndef TAILQ_INIT -#define TAILQ_INIT(head) do { \ - (head)->tqh_first = TAILQ_END(head); \ - (head)->tqh_last = &(head)->tqh_first; \ -} while (/*CONSTCOND*/0) - -#define TAILQ_INSERT_HEAD(head, elm, field) do { \ - if (((elm)->field.tqe_next = (head)->tqh_first) != TAILQ_END(head))\ - (head)->tqh_first->field.tqe_prev = \ - &(elm)->field.tqe_next; \ - else \ - (head)->tqh_last = &(elm)->field.tqe_next; \ - (head)->tqh_first = (elm); \ - (elm)->field.tqe_prev = &(head)->tqh_first; \ -} while (/*CONSTCOND*/0) - -#define TAILQ_INSERT_TAIL(head, elm, field) do { \ - (elm)->field.tqe_next = TAILQ_END(head); \ - (elm)->field.tqe_prev = (head)->tqh_last; \ - *(head)->tqh_last = (elm); \ - (head)->tqh_last = &(elm)->field.tqe_next; \ -} while (/*CONSTCOND*/0) - -#define TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \ - if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != \ - TAILQ_END(head)) \ - (elm)->field.tqe_next->field.tqe_prev = \ - &(elm)->field.tqe_next; \ - else \ - (head)->tqh_last = &(elm)->field.tqe_next; \ - (listelm)->field.tqe_next = (elm); \ - (elm)->field.tqe_prev = &(listelm)->field.tqe_next; \ -} while (/*CONSTCOND*/0) - -#define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \ - (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \ - (elm)->field.tqe_next = (listelm); \ - *(listelm)->field.tqe_prev = (elm); \ - (listelm)->field.tqe_prev = &(elm)->field.tqe_next; \ -} while (/*CONSTCOND*/0) - -#define TAILQ_REMOVE(head, elm, field) do { \ - if (((elm)->field.tqe_next) != TAILQ_END(head)) \ - (elm)->field.tqe_next->field.tqe_prev = \ - (elm)->field.tqe_prev; \ - else \ - (head)->tqh_last = (elm)->field.tqe_prev; \ - *(elm)->field.tqe_prev = (elm)->field.tqe_next; \ -} while (/*CONSTCOND*/0) -#endif /* !TAILQ_INIT */ - -#ifndef TAILQ_REPLACE -#define TAILQ_REPLACE(head, elm, elm2, field) do { \ - if (((elm2)->field.tqe_next = (elm)->field.tqe_next) != \ - TAILQ_END(head)) \ - (elm2)->field.tqe_next->field.tqe_prev = \ - &(elm2)->field.tqe_next; \ - else \ - (head)->tqh_last = &(elm2)->field.tqe_next; \ - (elm2)->field.tqe_prev = (elm)->field.tqe_prev; \ - *(elm2)->field.tqe_prev = (elm2); \ -} while (/*CONSTCOND*/0) -#endif /* !TAILQ_REPLACE */ - -#ifndef TAILQ_FOREACH_SAFE -#define TAILQ_FOREACH_SAFE(var, head, field, next) \ - for ((var) = TAILQ_FIRST(head); \ - (var) != TAILQ_END(head) && \ - ((next) = TAILQ_NEXT(var, field), 1); (var) = (next)) - -#define TAILQ_FOREACH_REVERSE_SAFE(var, head, headname, field, prev) \ - for ((var) = TAILQ_LAST((head), headname); \ - (var) != TAILQ_END(head) && \ - ((prev) = TAILQ_PREV((var), headname, field), 1); (var) = (prev)) -#endif /* !TAILQ_FOREACH_SAFE */ - -#ifndef TAILQ_CONCAT -#define TAILQ_CONCAT(head1, head2, field) do { \ - if (!TAILQ_EMPTY(head2)) { \ - *(head1)->tqh_last = (head2)->tqh_first; \ - (head2)->tqh_first->field.tqe_prev = (head1)->tqh_last; \ - (head1)->tqh_last = (head2)->tqh_last; \ - TAILQ_INIT((head2)); \ - } \ -} while (/*CONSTCOND*/0) -#endif /* !TAILQ_CONCAT */ - -#endif /* !COMAPT_QUEUE_H */ diff --git a/external/bsd/dhcpcd/dist/compat/rb.c b/external/bsd/dhcpcd/dist/compat/rb.c deleted file mode 100644 index 3f2629e0e5f..00000000000 --- a/external/bsd/dhcpcd/dist/compat/rb.c +++ /dev/null @@ -1,1346 +0,0 @@ -/* $NetBSD: rb.c,v 1.1.1.1.2.1 2019/09/05 08:56:55 martin Exp $ */ - -/*- - * Copyright (c) 2001 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software contributed to The NetBSD Foundation - * by Matt Thomas <matt@3am-software.com>. - * - * 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. - * - * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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. - */ - -#include "config.h" -#include "common.h" - -#if !defined(_KERNEL) && !defined(_STANDALONE) -#include <sys/types.h> -#include <stddef.h> -#include <assert.h> -#include <stdbool.h> -#ifdef RBDEBUG -#define KASSERT(s) assert(s) -#define __rbt_unused -#else -#define KASSERT(s) do { } while (/*CONSTCOND*/ 0) -#define __rbt_unused __unused -#endif -__RCSID("$NetBSD: rb.c,v 1.1.1.1.2.1 2019/09/05 08:56:55 martin Exp $"); -#else -#include <lib/libkern/libkern.h> -__KERNEL_RCSID(0, "$NetBSD: rb.c,v 1.1.1.1.2.1 2019/09/05 08:56:55 martin Exp $"); -#ifndef DIAGNOSTIC -#define __rbt_unused __unused -#else -#define __rbt_unused -#endif -#endif - -#ifdef _LIBC -__weak_alias(rb_tree_init, _rb_tree_init) -__weak_alias(rb_tree_find_node, _rb_tree_find_node) -__weak_alias(rb_tree_find_node_geq, _rb_tree_find_node_geq) -__weak_alias(rb_tree_find_node_leq, _rb_tree_find_node_leq) -__weak_alias(rb_tree_insert_node, _rb_tree_insert_node) -__weak_alias(rb_tree_remove_node, _rb_tree_remove_node) -__weak_alias(rb_tree_iterate, _rb_tree_iterate) -#ifdef RBDEBUG -__weak_alias(rb_tree_check, _rb_tree_check) -__weak_alias(rb_tree_depths, _rb_tree_depths) -#endif - -#include "namespace.h" -#endif - -#ifdef RBTEST -#include "rbtree.h" -#else -#include <sys/rbtree.h> -#endif - -static void rb_tree_insert_rebalance(struct rb_tree *, struct rb_node *); -static void rb_tree_removal_rebalance(struct rb_tree *, struct rb_node *, - unsigned int); -#ifdef RBDEBUG -static const struct rb_node *rb_tree_iterate_const(const struct rb_tree *, - const struct rb_node *, const unsigned int); -static bool rb_tree_check_node(const struct rb_tree *, const struct rb_node *, - const struct rb_node *, bool); -#else -#define rb_tree_check_node(a, b, c, d) true -#endif - -#define RB_NODETOITEM(rbto, rbn) \ - ((void *)((uintptr_t)(rbn) - (rbto)->rbto_node_offset)) -#define RB_ITEMTONODE(rbto, rbn) \ - ((rb_node_t *)((uintptr_t)(rbn) + (rbto)->rbto_node_offset)) - -#define RB_SENTINEL_NODE NULL - -void -rb_tree_init(struct rb_tree *rbt, const rb_tree_ops_t *ops) -{ - - rbt->rbt_ops = ops; - rbt->rbt_root = RB_SENTINEL_NODE; - RB_TAILQ_INIT(&rbt->rbt_nodes); -#ifndef RBSMALL - rbt->rbt_minmax[RB_DIR_LEFT] = rbt->rbt_root; /* minimum node */ - rbt->rbt_minmax[RB_DIR_RIGHT] = rbt->rbt_root; /* maximum node */ -#endif -#ifdef RBSTATS - rbt->rbt_count = 0; - rbt->rbt_insertions = 0; - rbt->rbt_removals = 0; - rbt->rbt_insertion_rebalance_calls = 0; - rbt->rbt_insertion_rebalance_passes = 0; - rbt->rbt_removal_rebalance_calls = 0; - rbt->rbt_removal_rebalance_passes = 0; -#endif -} - -void * -rb_tree_find_node(struct rb_tree *rbt, const void *key) -{ - const rb_tree_ops_t *rbto = rbt->rbt_ops; - rbto_compare_key_fn compare_key = rbto->rbto_compare_key; - struct rb_node *parent = rbt->rbt_root; - - while (!RB_SENTINEL_P(parent)) { - void *pobj = RB_NODETOITEM(rbto, parent); - const signed int diff = (*compare_key)(rbto->rbto_context, - pobj, key); - if (diff == 0) - return pobj; - parent = parent->rb_nodes[diff < 0]; - } - - return NULL; -} - -void * -rb_tree_find_node_geq(struct rb_tree *rbt, const void *key) -{ - const rb_tree_ops_t *rbto = rbt->rbt_ops; - rbto_compare_key_fn compare_key = rbto->rbto_compare_key; - struct rb_node *parent = rbt->rbt_root, *last = NULL; - - while (!RB_SENTINEL_P(parent)) { - void *pobj = RB_NODETOITEM(rbto, parent); - const signed int diff = (*compare_key)(rbto->rbto_context, - pobj, key); - if (diff == 0) - return pobj; - if (diff > 0) - last = parent; - parent = parent->rb_nodes[diff < 0]; - } - - return last == NULL ? NULL : RB_NODETOITEM(rbto, last); -} - -void * -rb_tree_find_node_leq(struct rb_tree *rbt, const void *key) -{ - const rb_tree_ops_t *rbto = rbt->rbt_ops; - rbto_compare_key_fn compare_key = rbto->rbto_compare_key; - struct rb_node *parent = rbt->rbt_root, *last = NULL; - - while (!RB_SENTINEL_P(parent)) { - void *pobj = RB_NODETOITEM(rbto, parent); - const signed int diff = (*compare_key)(rbto->rbto_context, - pobj, key); - if (diff == 0) - return pobj; - if (diff < 0) - last = parent; - parent = parent->rb_nodes[diff < 0]; - } - - return last == NULL ? NULL : RB_NODETOITEM(rbto, last); -} - -void * -rb_tree_insert_node(struct rb_tree *rbt, void *object) -{ - const rb_tree_ops_t *rbto = rbt->rbt_ops; - rbto_compare_nodes_fn compare_nodes = rbto->rbto_compare_nodes; - struct rb_node *parent, *tmp, *self = RB_ITEMTONODE(rbto, object); - unsigned int position; - bool rebalance; - - RBSTAT_INC(rbt->rbt_insertions); - - tmp = rbt->rbt_root; - /* - * This is a hack. Because rbt->rbt_root is just a struct rb_node *, - * just like rb_node->rb_nodes[RB_DIR_LEFT], we can use this fact to - * avoid a lot of tests for root and know that even at root, - * updating RB_FATHER(rb_node)->rb_nodes[RB_POSITION(rb_node)] will - * update rbt->rbt_root. - */ - parent = (struct rb_node *)(void *)&rbt->rbt_root; - position = RB_DIR_LEFT; - - /* - * Find out where to place this new leaf. - */ - while (!RB_SENTINEL_P(tmp)) { - void *tobj = RB_NODETOITEM(rbto, tmp); - const signed int diff = (*compare_nodes)(rbto->rbto_context, - tobj, object); - if (__predict_false(diff == 0)) { - /* - * Node already exists; return it. - */ - return tobj; - } - parent = tmp; - position = (diff < 0); - tmp = parent->rb_nodes[position]; - } - -#ifdef RBDEBUG - { - struct rb_node *prev = NULL, *next = NULL; - - if (position == RB_DIR_RIGHT) - prev = parent; - else if (tmp != rbt->rbt_root) - next = parent; - - /* - * Verify our sequential position - */ - KASSERT(prev == NULL || !RB_SENTINEL_P(prev)); - KASSERT(next == NULL || !RB_SENTINEL_P(next)); - if (prev != NULL && next == NULL) - next = TAILQ_NEXT(prev, rb_link); - if (prev == NULL && next != NULL) - prev = TAILQ_PREV(next, rb_node_qh, rb_link); - KASSERT(prev == NULL || !RB_SENTINEL_P(prev)); - KASSERT(next == NULL || !RB_SENTINEL_P(next)); - KASSERT(prev == NULL || (*compare_nodes)(rbto->rbto_context, - RB_NODETOITEM(rbto, prev), RB_NODETOITEM(rbto, self)) < 0); - KASSERT(next == NULL || (*compare_nodes)(rbto->rbto_context, - RB_NODETOITEM(rbto, self), RB_NODETOITEM(rbto, next)) < 0); - } -#endif - - /* - * Initialize the node and insert as a leaf into the tree. - */ - RB_SET_FATHER(self, parent); - RB_SET_POSITION(self, position); - if (__predict_false(parent == (struct rb_node *)(void *)&rbt->rbt_root)) { - RB_MARK_BLACK(self); /* root is always black */ -#ifndef RBSMALL - rbt->rbt_minmax[RB_DIR_LEFT] = self; - rbt->rbt_minmax[RB_DIR_RIGHT] = self; -#endif - rebalance = false; - } else { - KASSERT(position == RB_DIR_LEFT || position == RB_DIR_RIGHT); -#ifndef RBSMALL - /* - * Keep track of the minimum and maximum nodes. If our - * parent is a minmax node and we on their min/max side, - * we must be the new min/max node. - */ - if (parent == rbt->rbt_minmax[position]) - rbt->rbt_minmax[position] = self; -#endif /* !RBSMALL */ - /* - * All new nodes are colored red. We only need to rebalance - * if our parent is also red. - */ - RB_MARK_RED(self); - rebalance = RB_RED_P(parent); - } - KASSERT(RB_SENTINEL_P(parent->rb_nodes[position])); - self->rb_left = parent->rb_nodes[position]; - self->rb_right = parent->rb_nodes[position]; - parent->rb_nodes[position] = self; - KASSERT(RB_CHILDLESS_P(self)); - - /* - * Insert the new node into a sorted list for easy sequential access - */ - RBSTAT_INC(rbt->rbt_count); -#ifdef RBDEBUG - if (RB_ROOT_P(rbt, self)) { - RB_TAILQ_INSERT_HEAD(&rbt->rbt_nodes, self, rb_link); - } else if (position == RB_DIR_LEFT) { - KASSERT((*compare_nodes)(rbto->rbto_context, - RB_NODETOITEM(rbto, self), - RB_NODETOITEM(rbto, RB_FATHER(self))) < 0); - RB_TAILQ_INSERT_BEFORE(RB_FATHER(self), self, rb_link); - } else { - KASSERT((*compare_nodes)(rbto->rbto_context, - RB_NODETOITEM(rbto, RB_FATHER(self)), - RB_NODETOITEM(rbto, self)) < 0); - RB_TAILQ_INSERT_AFTER(&rbt->rbt_nodes, RB_FATHER(self), - self, rb_link); - } -#endif - KASSERT(rb_tree_check_node(rbt, self, NULL, !rebalance)); - - /* - * Rebalance tree after insertion - */ - if (rebalance) { - rb_tree_insert_rebalance(rbt, self); - KASSERT(rb_tree_check_node(rbt, self, NULL, true)); - } - - /* Succesfully inserted, return our node pointer. */ - return object; -} - -/* - * Swap the location and colors of 'self' and its child @ which. The child - * can not be a sentinel node. This is our rotation function. However, - * since it preserves coloring, it great simplifies both insertion and - * removal since rotation almost always involves the exchanging of colors - * as a separate step. - */ -static void -rb_tree_reparent_nodes(__rbt_unused struct rb_tree *rbt, - struct rb_node *old_father, const unsigned int which) -{ - const unsigned int other = which ^ RB_DIR_OTHER; - struct rb_node * const grandpa = RB_FATHER(old_father); - struct rb_node * const old_child = old_father->rb_nodes[which]; - struct rb_node * const new_father = old_child; - struct rb_node * const new_child = old_father; - - KASSERT(which == RB_DIR_LEFT || which == RB_DIR_RIGHT); - - KASSERT(!RB_SENTINEL_P(old_child)); - KASSERT(RB_FATHER(old_child) == old_father); - - KASSERT(rb_tree_check_node(rbt, old_father, NULL, false)); - KASSERT(rb_tree_check_node(rbt, old_child, NULL, false)); - KASSERT(RB_ROOT_P(rbt, old_father) || - rb_tree_check_node(rbt, grandpa, NULL, false)); - - /* - * Exchange descendant linkages. - */ - grandpa->rb_nodes[RB_POSITION(old_father)] = new_father; - new_child->rb_nodes[which] = old_child->rb_nodes[other]; - new_father->rb_nodes[other] = new_child; - - /* - * Update ancestor linkages - */ - RB_SET_FATHER(new_father, grandpa); - RB_SET_FATHER(new_child, new_father); - - /* - * Exchange properties between new_father and new_child. The only - * change is that new_child's position is now on the other side. - */ -#if 0 - { - struct rb_node tmp; - tmp.rb_info = 0; - RB_COPY_PROPERTIES(&tmp, old_child); - RB_COPY_PROPERTIES(new_father, old_father); - RB_COPY_PROPERTIES(new_child, &tmp); - } -#else - RB_SWAP_PROPERTIES(new_father, new_child); -#endif - RB_SET_POSITION(new_child, other); - - /* - * Make sure to reparent the new child to ourself. - */ - if (!RB_SENTINEL_P(new_child->rb_nodes[which])) { - RB_SET_FATHER(new_child->rb_nodes[which], new_child); - RB_SET_POSITION(new_child->rb_nodes[which], which); - } - - KASSERT(rb_tree_check_node(rbt, new_father, NULL, false)); - KASSERT(rb_tree_check_node(rbt, new_child, NULL, false)); - KASSERT(RB_ROOT_P(rbt, new_father) || - rb_tree_check_node(rbt, grandpa, NULL, false)); -} - -static void -rb_tree_insert_rebalance(struct rb_tree *rbt, struct rb_node *self) -{ - struct rb_node * father = RB_FATHER(self); - struct rb_node * grandpa = RB_FATHER(father); - struct rb_node * uncle; - unsigned int which; - unsigned int other; - - KASSERT(!RB_ROOT_P(rbt, self)); - KASSERT(RB_RED_P(self)); - KASSERT(RB_RED_P(father)); - RBSTAT_INC(rbt->rbt_insertion_rebalance_calls); - - for (;;) { - KASSERT(!RB_SENTINEL_P(self)); - - KASSERT(RB_RED_P(self)); - KASSERT(RB_RED_P(father)); - /* - * We are red and our parent is red, therefore we must have a - * grandfather and he must be black. - */ - grandpa = RB_FATHER(father); - KASSERT(RB_BLACK_P(grandpa)); - KASSERT(RB_DIR_RIGHT == 1 && RB_DIR_LEFT == 0); - which = (father == grandpa->rb_right); - other = which ^ RB_DIR_OTHER; - uncle = grandpa->rb_nodes[other]; - - if (RB_BLACK_P(uncle)) - break; - - RBSTAT_INC(rbt->rbt_insertion_rebalance_passes); - /* - * Case 1: our uncle is red - * Simply invert the colors of our parent and - * uncle and make our grandparent red. And - * then solve the problem up at his level. - */ - RB_MARK_BLACK(uncle); - RB_MARK_BLACK(father); - if (__predict_false(RB_ROOT_P(rbt, grandpa))) { - /* - * If our grandpa is root, don't bother - * setting him to red, just return. - */ - KASSERT(RB_BLACK_P(grandpa)); - return; - } - RB_MARK_RED(grandpa); - self = grandpa; - father = RB_FATHER(self); - KASSERT(RB_RED_P(self)); - if (RB_BLACK_P(father)) { - /* - * If our greatgrandpa is black, we're done. - */ - KASSERT(RB_BLACK_P(rbt->rbt_root)); - return; - } - } - - KASSERT(!RB_ROOT_P(rbt, self)); - KASSERT(RB_RED_P(self)); - KASSERT(RB_RED_P(father)); - KASSERT(RB_BLACK_P(uncle)); - KASSERT(RB_BLACK_P(grandpa)); - /* - * Case 2&3: our uncle is black. - */ - if (self == father->rb_nodes[other]) { - /* - * Case 2: we are on the same side as our uncle - * Swap ourselves with our parent so this case - * becomes case 3. Basically our parent becomes our - * child. - */ - rb_tree_reparent_nodes(rbt, father, other); - KASSERT(RB_FATHER(father) == self); - KASSERT(self->rb_nodes[which] == father); - KASSERT(RB_FATHER(self) == grandpa); - self = father; - father = RB_FATHER(self); - } - KASSERT(RB_RED_P(self) && RB_RED_P(father)); - KASSERT(grandpa->rb_nodes[which] == father); - /* - * Case 3: we are opposite a child of a black uncle. - * Swap our parent and grandparent. Since our grandfather - * is black, our father will become black and our new sibling - * (former grandparent) will become red. - */ - rb_tree_reparent_nodes(rbt, grandpa, which); - KASSERT(RB_FATHER(self) == father); - KASSERT(RB_FATHER(self)->rb_nodes[RB_POSITION(self) ^ RB_DIR_OTHER] == grandpa); - KASSERT(RB_RED_P(self)); - KASSERT(RB_BLACK_P(father)); - KASSERT(RB_RED_P(grandpa)); - - /* - * Final step: Set the root to black. - */ - RB_MARK_BLACK(rbt->rbt_root); -} - -static void -rb_tree_prune_node(struct rb_tree *rbt, struct rb_node *self, bool rebalance) -{ - const unsigned int which = RB_POSITION(self); - struct rb_node *father = RB_FATHER(self); -#ifndef RBSMALL - const bool was_root = RB_ROOT_P(rbt, self); -#endif - - KASSERT(rebalance || (RB_ROOT_P(rbt, self) || RB_RED_P(self))); - KASSERT(!rebalance || RB_BLACK_P(self)); - KASSERT(RB_CHILDLESS_P(self)); - KASSERT(rb_tree_check_node(rbt, self, NULL, false)); - - /* - * Since we are childless, we know that self->rb_left is pointing - * to the sentinel node. - */ - father->rb_nodes[which] = self->rb_left; - - /* - * Remove ourselves from the node list, decrement the count, - * and update min/max. - */ - RB_TAILQ_REMOVE(&rbt->rbt_nodes, self, rb_link); - RBSTAT_DEC(rbt->rbt_count); -#ifndef RBSMALL - if (__predict_false(rbt->rbt_minmax[RB_POSITION(self)] == self)) { - rbt->rbt_minmax[RB_POSITION(self)] = father; - /* - * When removing the root, rbt->rbt_minmax[RB_DIR_LEFT] is - * updated automatically, but we also need to update - * rbt->rbt_minmax[RB_DIR_RIGHT]; - */ - if (__predict_false(was_root)) { - rbt->rbt_minmax[RB_DIR_RIGHT] = father; - } - } - RB_SET_FATHER(self, NULL); -#endif - - /* - * Rebalance if requested. - */ - if (rebalance) - rb_tree_removal_rebalance(rbt, father, which); - KASSERT(was_root || rb_tree_check_node(rbt, father, NULL, true)); -} - -/* - * When deleting an interior node - */ -static void -rb_tree_swap_prune_and_rebalance(struct rb_tree *rbt, struct rb_node *self, - struct rb_node *standin) -{ - const unsigned int standin_which = RB_POSITION(standin); - unsigned int standin_other = standin_which ^ RB_DIR_OTHER; - struct rb_node *standin_son; - struct rb_node *standin_father = RB_FATHER(standin); - bool rebalance = RB_BLACK_P(standin); - - if (standin_father == self) { - /* - * As a child of self, any childen would be opposite of - * our parent. - */ - KASSERT(RB_SENTINEL_P(standin->rb_nodes[standin_other])); - standin_son = standin->rb_nodes[standin_which]; - } else { - /* - * Since we aren't a child of self, any childen would be - * on the same side as our parent. - */ - KASSERT(RB_SENTINEL_P(standin->rb_nodes[standin_which])); - standin_son = standin->rb_nodes[standin_other]; - } - - /* - * the node we are removing must have two children. - */ - KASSERT(RB_TWOCHILDREN_P(self)); - /* - * If standin has a child, it must be red. - */ - KASSERT(RB_SENTINEL_P(standin_son) || RB_RED_P(standin_son)); - - /* - * Verify things are sane. - */ - KASSERT(rb_tree_check_node(rbt, self, NULL, false)); - KASSERT(rb_tree_check_node(rbt, standin, NULL, false)); - - if (__predict_false(RB_RED_P(standin_son))) { - /* - * We know we have a red child so if we flip it to black - * we don't have to rebalance. - */ - KASSERT(rb_tree_check_node(rbt, standin_son, NULL, true)); - RB_MARK_BLACK(standin_son); - rebalance = false; - - if (standin_father == self) { - KASSERT(RB_POSITION(standin_son) == standin_which); - } else { - KASSERT(RB_POSITION(standin_son) == standin_other); - /* - * Change the son's parentage to point to his grandpa. - */ - RB_SET_FATHER(standin_son, standin_father); - RB_SET_POSITION(standin_son, standin_which); - } - } - - if (standin_father == self) { - /* - * If we are about to delete the standin's father, then when - * we call rebalance, we need to use ourselves as our father. - * Otherwise remember our original father. Also, sincef we are - * our standin's father we only need to reparent the standin's - * brother. - * - * | R --> S | - * | Q S --> Q T | - * | t --> | - */ - KASSERT(RB_SENTINEL_P(standin->rb_nodes[standin_other])); - KASSERT(!RB_SENTINEL_P(self->rb_nodes[standin_other])); - KASSERT(self->rb_nodes[standin_which] == standin); - /* - * Have our son/standin adopt his brother as his new son. - */ - standin_father = standin; - } else { - /* - * | R --> S . | - * | / \ | T --> / \ | / | - * | ..... | S --> ..... | T | - * - * Sever standin's connection to his father. - */ - standin_father->rb_nodes[standin_which] = standin_son; - /* - * Adopt the far son. - */ - standin->rb_nodes[standin_other] = self->rb_nodes[standin_other]; - RB_SET_FATHER(standin->rb_nodes[standin_other], standin); - KASSERT(RB_POSITION(self->rb_nodes[standin_other]) == standin_other); - /* - * Use standin_other because we need to preserve standin_which - * for the removal_rebalance. - */ - standin_other = standin_which; - } - - /* - * Move the only remaining son to our standin. If our standin is our - * son, this will be the only son needed to be moved. - */ - KASSERT(standin->rb_nodes[standin_other] != self->rb_nodes[standin_other]); - standin->rb_nodes[standin_other] = self->rb_nodes[standin_other]; - RB_SET_FATHER(standin->rb_nodes[standin_other], standin); - - /* - * Now copy the result of self to standin and then replace - * self with standin in the tree. - */ - RB_COPY_PROPERTIES(standin, self); - RB_SET_FATHER(standin, RB_FATHER(self)); - RB_FATHER(standin)->rb_nodes[RB_POSITION(standin)] = standin; - - /* - * Remove ourselves from the node list, decrement the count, - * and update min/max. - */ - RB_TAILQ_REMOVE(&rbt->rbt_nodes, self, rb_link); - RBSTAT_DEC(rbt->rbt_count); -#ifndef RBSMALL - if (__predict_false(rbt->rbt_minmax[RB_POSITION(self)] == self)) - rbt->rbt_minmax[RB_POSITION(self)] = RB_FATHER(self); - RB_SET_FATHER(self, NULL); -#endif - - KASSERT(rb_tree_check_node(rbt, standin, NULL, false)); - KASSERT(RB_FATHER_SENTINEL_P(standin) - || rb_tree_check_node(rbt, standin_father, NULL, false)); - KASSERT(RB_LEFT_SENTINEL_P(standin) - || rb_tree_check_node(rbt, standin->rb_left, NULL, false)); - KASSERT(RB_RIGHT_SENTINEL_P(standin) - || rb_tree_check_node(rbt, standin->rb_right, NULL, false)); - - if (!rebalance) - return; - - rb_tree_removal_rebalance(rbt, standin_father, standin_which); - KASSERT(rb_tree_check_node(rbt, standin, NULL, true)); -} - -/* - * We could do this by doing - * rb_tree_node_swap(rbt, self, which); - * rb_tree_prune_node(rbt, self, false); - * - * But it's more efficient to just evalate and recolor the child. - */ -static void -rb_tree_prune_blackred_branch(struct rb_tree *rbt, struct rb_node *self, - unsigned int which) -{ - struct rb_node *father = RB_FATHER(self); - struct rb_node *son = self->rb_nodes[which]; -#ifndef RBSMALL - const bool was_root = RB_ROOT_P(rbt, self); -#endif - - KASSERT(which == RB_DIR_LEFT || which == RB_DIR_RIGHT); - KASSERT(RB_BLACK_P(self) && RB_RED_P(son)); - KASSERT(!RB_TWOCHILDREN_P(son)); - KASSERT(RB_CHILDLESS_P(son)); - KASSERT(rb_tree_check_node(rbt, self, NULL, false)); - KASSERT(rb_tree_check_node(rbt, son, NULL, false)); - - /* - * Remove ourselves from the tree and give our former child our - * properties (position, color, root). - */ - RB_COPY_PROPERTIES(son, self); - father->rb_nodes[RB_POSITION(son)] = son; - RB_SET_FATHER(son, father); - - /* - * Remove ourselves from the node list, decrement the count, - * and update minmax. - */ - RB_TAILQ_REMOVE(&rbt->rbt_nodes, self, rb_link); - RBSTAT_DEC(rbt->rbt_count); -#ifndef RBSMALL - if (__predict_false(was_root)) { - KASSERT(rbt->rbt_minmax[which] == son); - rbt->rbt_minmax[which ^ RB_DIR_OTHER] = son; - } else if (rbt->rbt_minmax[RB_POSITION(self)] == self) { - rbt->rbt_minmax[RB_POSITION(self)] = son; - } - RB_SET_FATHER(self, NULL); -#endif - - KASSERT(was_root || rb_tree_check_node(rbt, father, NULL, true)); - KASSERT(rb_tree_check_node(rbt, son, NULL, true)); -} - -void -rb_tree_remove_node(struct rb_tree *rbt, void *object) -{ - const rb_tree_ops_t *rbto = rbt->rbt_ops; - struct rb_node *standin, *self = RB_ITEMTONODE(rbto, object); - unsigned int which; - - KASSERT(!RB_SENTINEL_P(self)); - RBSTAT_INC(rbt->rbt_removals); - - /* - * In the following diagrams, we (the node to be removed) are S. Red - * nodes are lowercase. T could be either red or black. - * - * Remember the major axiom of the red-black tree: the number of - * black nodes from the root to each leaf is constant across all - * leaves, only the number of red nodes varies. - * - * Thus removing a red leaf doesn't require any other changes to a - * red-black tree. So if we must remove a node, attempt to rearrange - * the tree so we can remove a red node. - * - * The simpliest case is a childless red node or a childless root node: - * - * | T --> T | or | R --> * | - * | s --> * | - */ - if (RB_CHILDLESS_P(self)) { - const bool rebalance = RB_BLACK_P(self) && !RB_ROOT_P(rbt, self); - rb_tree_prune_node(rbt, self, rebalance); - return; - } - KASSERT(!RB_CHILDLESS_P(self)); - if (!RB_TWOCHILDREN_P(self)) { - /* - * The next simpliest case is the node we are deleting is - * black and has one red child. - * - * | T --> T --> T | - * | S --> R --> R | - * | r --> s --> * | - */ - which = RB_LEFT_SENTINEL_P(self) ? RB_DIR_RIGHT : RB_DIR_LEFT; - KASSERT(RB_BLACK_P(self)); - KASSERT(RB_RED_P(self->rb_nodes[which])); - KASSERT(RB_CHILDLESS_P(self->rb_nodes[which])); - rb_tree_prune_blackred_branch(rbt, self, which); - return; - } - KASSERT(RB_TWOCHILDREN_P(self)); - - /* - * We invert these because we prefer to remove from the inside of - * the tree. - */ - which = RB_POSITION(self) ^ RB_DIR_OTHER; - - /* - * Let's find the node closes to us opposite of our parent - * Now swap it with ourself, "prune" it, and rebalance, if needed. - */ - standin = RB_ITEMTONODE(rbto, rb_tree_iterate(rbt, object, which)); - rb_tree_swap_prune_and_rebalance(rbt, self, standin); -} - -static void -rb_tree_removal_rebalance(struct rb_tree *rbt, struct rb_node *parent, - unsigned int which) -{ - KASSERT(!RB_SENTINEL_P(parent)); - KASSERT(RB_SENTINEL_P(parent->rb_nodes[which])); - KASSERT(which == RB_DIR_LEFT || which == RB_DIR_RIGHT); - RBSTAT_INC(rbt->rbt_removal_rebalance_calls); - - while (RB_BLACK_P(parent->rb_nodes[which])) { - unsigned int other = which ^ RB_DIR_OTHER; - struct rb_node *brother = parent->rb_nodes[other]; - - RBSTAT_INC(rbt->rbt_removal_rebalance_passes); - - KASSERT(!RB_SENTINEL_P(brother)); - /* - * For cases 1, 2a, and 2b, our brother's children must - * be black and our father must be black - */ - if (RB_BLACK_P(parent) - && RB_BLACK_P(brother->rb_left) - && RB_BLACK_P(brother->rb_right)) { - if (RB_RED_P(brother)) { - /* - * Case 1: Our brother is red, swap its - * position (and colors) with our parent. - * This should now be case 2b (unless C or E - * has a red child which is case 3; thus no - * explicit branch to case 2b). - * - * B -> D - * A d -> b E - * C E -> A C - */ - KASSERT(RB_BLACK_P(parent)); - rb_tree_reparent_nodes(rbt, parent, other); - brother = parent->rb_nodes[other]; - KASSERT(!RB_SENTINEL_P(brother)); - KASSERT(RB_RED_P(parent)); - KASSERT(RB_BLACK_P(brother)); - KASSERT(rb_tree_check_node(rbt, brother, NULL, false)); - KASSERT(rb_tree_check_node(rbt, parent, NULL, false)); - } else { - /* - * Both our parent and brother are black. - * Change our brother to red, advance up rank - * and go through the loop again. - * - * B -> *B - * *A D -> A d - * C E -> C E - */ - RB_MARK_RED(brother); - KASSERT(RB_BLACK_P(brother->rb_left)); - KASSERT(RB_BLACK_P(brother->rb_right)); - if (RB_ROOT_P(rbt, parent)) - return; /* root == parent == black */ - KASSERT(rb_tree_check_node(rbt, brother, NULL, false)); - KASSERT(rb_tree_check_node(rbt, parent, NULL, false)); - which = RB_POSITION(parent); - parent = RB_FATHER(parent); - continue; - } - } - /* - * Avoid an else here so that case 2a above can hit either - * case 2b, 3, or 4. - */ - if (RB_RED_P(parent) - && RB_BLACK_P(brother) - && RB_BLACK_P(brother->rb_left) - && RB_BLACK_P(brother->rb_right)) { - KASSERT(RB_RED_P(parent)); - KASSERT(RB_BLACK_P(brother)); - KASSERT(RB_BLACK_P(brother->rb_left)); - KASSERT(RB_BLACK_P(brother->rb_right)); - /* - * We are black, our father is red, our brother and - * both nephews are black. Simply invert/exchange the - * colors of our father and brother (to black and red - * respectively). - * - * | f --> F | - * | * B --> * b | - * | N N --> N N | - */ - RB_MARK_BLACK(parent); - RB_MARK_RED(brother); - KASSERT(rb_tree_check_node(rbt, brother, NULL, true)); - break; /* We're done! */ - } else { - /* - * Our brother must be black and have at least one - * red child (it may have two). - */ - KASSERT(RB_BLACK_P(brother)); - KASSERT(RB_RED_P(brother->rb_nodes[which]) || - RB_RED_P(brother->rb_nodes[other])); - if (RB_BLACK_P(brother->rb_nodes[other])) { - /* - * Case 3: our brother is black, our near - * nephew is red, and our far nephew is black. - * Swap our brother with our near nephew. - * This result in a tree that matches case 4. - * (Our father could be red or black). - * - * | F --> F | - * | x B --> x B | - * | n --> n | - */ - KASSERT(RB_RED_P(brother->rb_nodes[which])); - rb_tree_reparent_nodes(rbt, brother, which); - KASSERT(RB_FATHER(brother) == parent->rb_nodes[other]); - brother = parent->rb_nodes[other]; - KASSERT(RB_RED_P(brother->rb_nodes[other])); - } - /* - * Case 4: our brother is black and our far nephew - * is red. Swap our father and brother locations and - * change our far nephew to black. (these can be - * done in either order so we change the color first). - * The result is a valid red-black tree and is a - * terminal case. (again we don't care about the - * father's color) - * - * If the father is red, we will get a red-black-black - * tree: - * | f -> f --> b | - * | B -> B --> F N | - * | n -> N --> | - * - * If the father is black, we will get an all black - * tree: - * | F -> F --> B | - * | B -> B --> F N | - * | n -> N --> | - * - * If we had two red nephews, then after the swap, - * our former father would have a red grandson. - */ - KASSERT(RB_BLACK_P(brother)); - KASSERT(RB_RED_P(brother->rb_nodes[other])); - RB_MARK_BLACK(brother->rb_nodes[other]); - rb_tree_reparent_nodes(rbt, parent, other); - break; /* We're done! */ - } - } - KASSERT(rb_tree_check_node(rbt, parent, NULL, true)); -} - -void * -rb_tree_iterate(struct rb_tree *rbt, void *object, const unsigned int direction) -{ - const rb_tree_ops_t *rbto = rbt->rbt_ops; - const unsigned int other = direction ^ RB_DIR_OTHER; - struct rb_node *self; - - KASSERT(direction == RB_DIR_LEFT || direction == RB_DIR_RIGHT); - - if (object == NULL) { -#ifndef RBSMALL - if (RB_SENTINEL_P(rbt->rbt_root)) - return NULL; - return RB_NODETOITEM(rbto, rbt->rbt_minmax[direction]); -#else - self = rbt->rbt_root; - if (RB_SENTINEL_P(self)) - return NULL; - while (!RB_SENTINEL_P(self->rb_nodes[direction])) - self = self->rb_nodes[direction]; - return RB_NODETOITEM(rbto, self); -#endif /* !RBSMALL */ - } - self = RB_ITEMTONODE(rbto, object); - KASSERT(!RB_SENTINEL_P(self)); - /* - * We can't go any further in this direction. We proceed up in the - * opposite direction until our parent is in direction we want to go. - */ - if (RB_SENTINEL_P(self->rb_nodes[direction])) { - while (!RB_ROOT_P(rbt, self)) { - if (other == RB_POSITION(self)) - return RB_NODETOITEM(rbto, RB_FATHER(self)); - self = RB_FATHER(self); - } - return NULL; - } - - /* - * Advance down one in current direction and go down as far as possible - * in the opposite direction. - */ - self = self->rb_nodes[direction]; - KASSERT(!RB_SENTINEL_P(self)); - while (!RB_SENTINEL_P(self->rb_nodes[other])) - self = self->rb_nodes[other]; - return RB_NODETOITEM(rbto, self); -} - -#ifdef RBDEBUG -static const struct rb_node * -rb_tree_iterate_const(const struct rb_tree *rbt, const struct rb_node *self, - const unsigned int direction) -{ - const unsigned int other = direction ^ RB_DIR_OTHER; - KASSERT(direction == RB_DIR_LEFT || direction == RB_DIR_RIGHT); - - if (self == NULL) { -#ifndef RBSMALL - if (RB_SENTINEL_P(rbt->rbt_root)) - return NULL; - return rbt->rbt_minmax[direction]; -#else - self = rbt->rbt_root; - if (RB_SENTINEL_P(self)) - return NULL; - while (!RB_SENTINEL_P(self->rb_nodes[direction])) - self = self->rb_nodes[direction]; - return self; -#endif /* !RBSMALL */ - } - KASSERT(!RB_SENTINEL_P(self)); - /* - * We can't go any further in this direction. We proceed up in the - * opposite direction until our parent is in direction we want to go. - */ - if (RB_SENTINEL_P(self->rb_nodes[direction])) { - while (!RB_ROOT_P(rbt, self)) { - if (other == RB_POSITION(self)) - return RB_FATHER(self); - self = RB_FATHER(self); - } - return NULL; - } - - /* - * Advance down one in current direction and go down as far as possible - * in the opposite direction. - */ - self = self->rb_nodes[direction]; - KASSERT(!RB_SENTINEL_P(self)); - while (!RB_SENTINEL_P(self->rb_nodes[other])) - self = self->rb_nodes[other]; - return self; -} - -static unsigned int -rb_tree_count_black(const struct rb_node *self) -{ - unsigned int left, right; - - if (RB_SENTINEL_P(self)) - return 0; - - left = rb_tree_count_black(self->rb_left); - right = rb_tree_count_black(self->rb_right); - - KASSERT(left == right); - - return left + RB_BLACK_P(self); -} - -static bool -rb_tree_check_node(const struct rb_tree *rbt, const struct rb_node *self, - const struct rb_node *prev, bool red_check) -{ - const rb_tree_ops_t *rbto = rbt->rbt_ops; - rbto_compare_nodes_fn compare_nodes = rbto->rbto_compare_nodes; - - KASSERT(!RB_SENTINEL_P(self)); - KASSERT(prev == NULL || (*compare_nodes)(rbto->rbto_context, - RB_NODETOITEM(rbto, prev), RB_NODETOITEM(rbto, self)) < 0); - - /* - * Verify our relationship to our parent. - */ - if (RB_ROOT_P(rbt, self)) { - KASSERT(self == rbt->rbt_root); - KASSERT(RB_POSITION(self) == RB_DIR_LEFT); - KASSERT(RB_FATHER(self)->rb_nodes[RB_DIR_LEFT] == self); - KASSERT(RB_FATHER(self) == (const struct rb_node *) &rbt->rbt_root); - } else { - int diff = (*compare_nodes)(rbto->rbto_context, - RB_NODETOITEM(rbto, self), - RB_NODETOITEM(rbto, RB_FATHER(self))); - - KASSERT(self != rbt->rbt_root); - KASSERT(!RB_FATHER_SENTINEL_P(self)); - if (RB_POSITION(self) == RB_DIR_LEFT) { - KASSERT(diff < 0); - KASSERT(RB_FATHER(self)->rb_nodes[RB_DIR_LEFT] == self); - } else { - KASSERT(diff > 0); - KASSERT(RB_FATHER(self)->rb_nodes[RB_DIR_RIGHT] == self); - } - } - - /* - * Verify our position in the linked list against the tree itself. - */ - { - const struct rb_node *prev0 = rb_tree_iterate_const(rbt, self, RB_DIR_LEFT); - const struct rb_node *next0 = rb_tree_iterate_const(rbt, self, RB_DIR_RIGHT); - KASSERT(prev0 == TAILQ_PREV(self, rb_node_qh, rb_link)); - KASSERT(next0 == TAILQ_NEXT(self, rb_link)); -#ifndef RBSMALL - KASSERT(prev0 != NULL || self == rbt->rbt_minmax[RB_DIR_LEFT]); - KASSERT(next0 != NULL || self == rbt->rbt_minmax[RB_DIR_RIGHT]); -#endif - } - - /* - * The root must be black. - * There can never be two adjacent red nodes. - */ - if (red_check) { - KASSERT(!RB_ROOT_P(rbt, self) || RB_BLACK_P(self)); - (void) rb_tree_count_black(self); - if (RB_RED_P(self)) { - const struct rb_node *brother; - KASSERT(!RB_ROOT_P(rbt, self)); - brother = RB_FATHER(self)->rb_nodes[RB_POSITION(self) ^ RB_DIR_OTHER]; - KASSERT(RB_BLACK_P(RB_FATHER(self))); - /* - * I'm red and have no children, then I must either - * have no brother or my brother also be red and - * also have no children. (black count == 0) - */ - KASSERT(!RB_CHILDLESS_P(self) - || RB_SENTINEL_P(brother) - || RB_RED_P(brother) - || RB_CHILDLESS_P(brother)); - /* - * If I'm not childless, I must have two children - * and they must be both be black. - */ - KASSERT(RB_CHILDLESS_P(self) - || (RB_TWOCHILDREN_P(self) - && RB_BLACK_P(self->rb_left) - && RB_BLACK_P(self->rb_right))); - /* - * If I'm not childless, thus I have black children, - * then my brother must either be black or have two - * black children. - */ - KASSERT(RB_CHILDLESS_P(self) - || RB_BLACK_P(brother) - || (RB_TWOCHILDREN_P(brother) - && RB_BLACK_P(brother->rb_left) - && RB_BLACK_P(brother->rb_right))); - } else { - /* - * If I'm black and have one child, that child must - * be red and childless. - */ - KASSERT(RB_CHILDLESS_P(self) - || RB_TWOCHILDREN_P(self) - || (!RB_LEFT_SENTINEL_P(self) - && RB_RIGHT_SENTINEL_P(self) - && RB_RED_P(self->rb_left) - && RB_CHILDLESS_P(self->rb_left)) - || (!RB_RIGHT_SENTINEL_P(self) - && RB_LEFT_SENTINEL_P(self) - && RB_RED_P(self->rb_right) - && RB_CHILDLESS_P(self->rb_right))); - - /* - * If I'm a childless black node and my parent is - * black, my 2nd closet relative away from my parent - * is either red or has a red parent or red children. - */ - if (!RB_ROOT_P(rbt, self) - && RB_CHILDLESS_P(self) - && RB_BLACK_P(RB_FATHER(self))) { - const unsigned int which = RB_POSITION(self); - const unsigned int other = which ^ RB_DIR_OTHER; - const struct rb_node *relative0, *relative; - - relative0 = rb_tree_iterate_const(rbt, - self, other); - KASSERT(relative0 != NULL); - relative = rb_tree_iterate_const(rbt, - relative0, other); - KASSERT(relative != NULL); - KASSERT(RB_SENTINEL_P(relative->rb_nodes[which])); -#if 0 - KASSERT(RB_RED_P(relative) - || RB_RED_P(relative->rb_left) - || RB_RED_P(relative->rb_right) - || RB_RED_P(RB_FATHER(relative))); -#endif - } - } - /* - * A grandparent's children must be real nodes and not - * sentinels. First check out grandparent. - */ - KASSERT(RB_ROOT_P(rbt, self) - || RB_ROOT_P(rbt, RB_FATHER(self)) - || RB_TWOCHILDREN_P(RB_FATHER(RB_FATHER(self)))); - /* - * If we are have grandchildren on our left, then - * we must have a child on our right. - */ - KASSERT(RB_LEFT_SENTINEL_P(self) - || RB_CHILDLESS_P(self->rb_left) - || !RB_RIGHT_SENTINEL_P(self)); - /* - * If we are have grandchildren on our right, then - * we must have a child on our left. - */ - KASSERT(RB_RIGHT_SENTINEL_P(self) - || RB_CHILDLESS_P(self->rb_right) - || !RB_LEFT_SENTINEL_P(self)); - - /* - * If we have a child on the left and it doesn't have two - * children make sure we don't have great-great-grandchildren on - * the right. - */ - KASSERT(RB_TWOCHILDREN_P(self->rb_left) - || RB_CHILDLESS_P(self->rb_right) - || RB_CHILDLESS_P(self->rb_right->rb_left) - || RB_CHILDLESS_P(self->rb_right->rb_left->rb_left) - || RB_CHILDLESS_P(self->rb_right->rb_left->rb_right) - || RB_CHILDLESS_P(self->rb_right->rb_right) - || RB_CHILDLESS_P(self->rb_right->rb_right->rb_left) - || RB_CHILDLESS_P(self->rb_right->rb_right->rb_right)); - - /* - * If we have a child on the right and it doesn't have two - * children make sure we don't have great-great-grandchildren on - * the left. - */ - KASSERT(RB_TWOCHILDREN_P(self->rb_right) - || RB_CHILDLESS_P(self->rb_left) - || RB_CHILDLESS_P(self->rb_left->rb_left) - || RB_CHILDLESS_P(self->rb_left->rb_left->rb_left) - || RB_CHILDLESS_P(self->rb_left->rb_left->rb_right) - || RB_CHILDLESS_P(self->rb_left->rb_right) - || RB_CHILDLESS_P(self->rb_left->rb_right->rb_left) - || RB_CHILDLESS_P(self->rb_left->rb_right->rb_right)); - - /* - * If we are fully interior node, then our predecessors and - * successors must have no children in our direction. - */ - if (RB_TWOCHILDREN_P(self)) { - const struct rb_node *prev0; - const struct rb_node *next0; - - prev0 = rb_tree_iterate_const(rbt, self, RB_DIR_LEFT); - KASSERT(prev0 != NULL); - KASSERT(RB_RIGHT_SENTINEL_P(prev0)); - - next0 = rb_tree_iterate_const(rbt, self, RB_DIR_RIGHT); - KASSERT(next0 != NULL); - KASSERT(RB_LEFT_SENTINEL_P(next0)); - } - } - - return true; -} - -void -rb_tree_check(const struct rb_tree *rbt, bool red_check) -{ - const struct rb_node *self; - const struct rb_node *prev; -#ifdef RBSTATS - unsigned int count = 0; -#endif - - KASSERT(rbt->rbt_root != NULL); - KASSERT(RB_LEFT_P(rbt->rbt_root)); - -#if defined(RBSTATS) && !defined(RBSMALL) - KASSERT(rbt->rbt_count > 1 - || rbt->rbt_minmax[RB_DIR_LEFT] == rbt->rbt_minmax[RB_DIR_RIGHT]); -#endif - - prev = NULL; - TAILQ_FOREACH(self, &rbt->rbt_nodes, rb_link) { - rb_tree_check_node(rbt, self, prev, false); -#ifdef RBSTATS - count++; -#endif - } -#ifdef RBSTATS - KASSERT(rbt->rbt_count == count); -#endif - if (red_check) { - KASSERT(RB_BLACK_P(rbt->rbt_root)); - KASSERT(RB_SENTINEL_P(rbt->rbt_root) - || rb_tree_count_black(rbt->rbt_root)); - - /* - * The root must be black. - * There can never be two adjacent red nodes. - */ - TAILQ_FOREACH(self, &rbt->rbt_nodes, rb_link) { - rb_tree_check_node(rbt, self, NULL, true); - } - } -} -#endif /* RBDEBUG */ - -#ifdef RBSTATS -static void -rb_tree_mark_depth(const struct rb_tree *rbt, const struct rb_node *self, - size_t *depths, size_t depth) -{ - if (RB_SENTINEL_P(self)) - return; - - if (RB_TWOCHILDREN_P(self)) { - rb_tree_mark_depth(rbt, self->rb_left, depths, depth + 1); - rb_tree_mark_depth(rbt, self->rb_right, depths, depth + 1); - return; - } - depths[depth]++; - if (!RB_LEFT_SENTINEL_P(self)) { - rb_tree_mark_depth(rbt, self->rb_left, depths, depth + 1); - } - if (!RB_RIGHT_SENTINEL_P(self)) { - rb_tree_mark_depth(rbt, self->rb_right, depths, depth + 1); - } -} - -void -rb_tree_depths(const struct rb_tree *rbt, size_t *depths) -{ - rb_tree_mark_depth(rbt, rbt->rbt_root, depths, 1); -} -#endif /* RBSTATS */ diff --git a/external/bsd/dhcpcd/dist/compat/rbtree.h b/external/bsd/dhcpcd/dist/compat/rbtree.h deleted file mode 100644 index c8bf313fcbe..00000000000 --- a/external/bsd/dhcpcd/dist/compat/rbtree.h +++ /dev/null @@ -1,211 +0,0 @@ -/* $NetBSD: rbtree.h,v 1.1.1.1.2.1 2019/09/05 08:56:55 martin Exp $ */ - -/*- - * Copyright (c) 2001 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software contributed to The NetBSD Foundation - * by Matt Thomas <matt@3am-software.com>. - * - * 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. - * - * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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. - */ - -#ifndef _SYS_RBTREE_H_ -#define _SYS_RBTREE_H_ - -#include "config.h" -#include "common.h" - -#if defined(_KERNEL) || defined(_STANDALONE) -#include <sys/types.h> -#else -#include <stdbool.h> -#include <inttypes.h> -#endif -#ifdef HAVE_SYS_QUEUE_H -#include <sys/queue.h> -#else -#include "queue.h" -#endif -#if !defined(__linux__) && !defined(__QNX__) && !defined(__sun) -#include <sys/endian.h> -#else -#include "endian.h" -#endif - -__BEGIN_DECLS - -typedef struct rb_node { - struct rb_node *rb_nodes[2]; -#define RB_DIR_LEFT 0 -#define RB_DIR_RIGHT 1 -#define RB_DIR_OTHER 1 -#define rb_left rb_nodes[RB_DIR_LEFT] -#define rb_right rb_nodes[RB_DIR_RIGHT] - - /* - * rb_info contains the two flags and the parent back pointer. - * We put the two flags in the low two bits since we know that - * rb_node will have an alignment of 4 or 8 bytes. - */ - uintptr_t rb_info; -#define RB_FLAG_POSITION (uintptr_t)0x2 -#define RB_FLAG_RED (uintptr_t)0x1 -#define RB_FLAG_MASK (RB_FLAG_POSITION|RB_FLAG_RED) -#define RB_FATHER(rb) \ - ((struct rb_node *)((rb)->rb_info & ~RB_FLAG_MASK)) -#define RB_SET_FATHER(rb, father) \ - ((void)((rb)->rb_info = (uintptr_t)(father)|((rb)->rb_info & RB_FLAG_MASK))) - -#define RB_SENTINEL_P(rb) ((rb) == NULL) -#define RB_LEFT_SENTINEL_P(rb) RB_SENTINEL_P((rb)->rb_left) -#define RB_RIGHT_SENTINEL_P(rb) RB_SENTINEL_P((rb)->rb_right) -#define RB_FATHER_SENTINEL_P(rb) RB_SENTINEL_P(RB_FATHER((rb))) -#define RB_CHILDLESS_P(rb) \ - (RB_SENTINEL_P(rb) || (RB_LEFT_SENTINEL_P(rb) && RB_RIGHT_SENTINEL_P(rb))) -#define RB_TWOCHILDREN_P(rb) \ - (!RB_SENTINEL_P(rb) && !RB_LEFT_SENTINEL_P(rb) && !RB_RIGHT_SENTINEL_P(rb)) - -#define RB_POSITION(rb) \ - (((rb)->rb_info & RB_FLAG_POSITION) ? RB_DIR_RIGHT : RB_DIR_LEFT) -#define RB_RIGHT_P(rb) (RB_POSITION(rb) == RB_DIR_RIGHT) -#define RB_LEFT_P(rb) (RB_POSITION(rb) == RB_DIR_LEFT) -#define RB_RED_P(rb) (!RB_SENTINEL_P(rb) && ((rb)->rb_info & RB_FLAG_RED) != 0) -#define RB_BLACK_P(rb) (RB_SENTINEL_P(rb) || ((rb)->rb_info & RB_FLAG_RED) == 0) -#define RB_MARK_RED(rb) ((void)((rb)->rb_info |= RB_FLAG_RED)) -#define RB_MARK_BLACK(rb) ((void)((rb)->rb_info &= ~RB_FLAG_RED)) -#define RB_INVERT_COLOR(rb) ((void)((rb)->rb_info ^= RB_FLAG_RED)) -#define RB_ROOT_P(rbt, rb) ((rbt)->rbt_root == (rb)) -#define RB_SET_POSITION(rb, position) \ - ((void)((position) ? ((rb)->rb_info |= RB_FLAG_POSITION) : \ - ((rb)->rb_info &= ~RB_FLAG_POSITION))) -#define RB_ZERO_PROPERTIES(rb) ((void)((rb)->rb_info &= ~RB_FLAG_MASK)) -#define RB_COPY_PROPERTIES(dst, src) \ - ((void)((dst)->rb_info ^= ((dst)->rb_info ^ (src)->rb_info) & RB_FLAG_MASK)) -#define RB_SWAP_PROPERTIES(a, b) do { \ - uintptr_t xorinfo = ((a)->rb_info ^ (b)->rb_info) & RB_FLAG_MASK; \ - (a)->rb_info ^= xorinfo; \ - (b)->rb_info ^= xorinfo; \ - } while (/*CONSTCOND*/ 0) -#ifdef RBDEBUG - TAILQ_ENTRY(rb_node) rb_link; -#endif -} rb_node_t; - -#define RB_TREE_MIN(T) rb_tree_iterate((T), NULL, RB_DIR_LEFT) -#define RB_TREE_MAX(T) rb_tree_iterate((T), NULL, RB_DIR_RIGHT) -#define RB_TREE_NEXT(T, N) rb_tree_iterate((T), (N), RB_DIR_RIGHT) -#define RB_TREE_PREV(T, N) rb_tree_iterate((T), (N), RB_DIR_LEFT) -#define RB_TREE_FOREACH(N, T) \ - for ((N) = RB_TREE_MIN(T); (N); (N) = RB_TREE_NEXT((T), (N))) -#define RB_TREE_FOREACH_REVERSE(N, T) \ - for ((N) = RB_TREE_MAX(T); (N); (N) = RB_TREE_PREV((T), (N))) -#define RB_TREE_FOREACH_SAFE(N, T, S) \ - for ((N) = RB_TREE_MIN(T); \ - (N) && ((S) = RB_TREE_NEXT((T), (N)), 1); \ - (N) = (S)) -#define RB_TREE_FOREACH_REVERSE_SAFE(N, T, S) \ - for ((N) = RB_TREE_MAX(T); \ - (N) && ((S) = RB_TREE_PREV((T), (N)), 1); \ - (N) = (S)) - -#ifdef RBDEBUG -TAILQ_HEAD(rb_node_qh, rb_node); - -#define RB_TAILQ_REMOVE(a, b, c) TAILQ_REMOVE(a, b, c) -#define RB_TAILQ_INIT(a) TAILQ_INIT(a) -#define RB_TAILQ_INSERT_HEAD(a, b, c) TAILQ_INSERT_HEAD(a, b, c) -#define RB_TAILQ_INSERT_BEFORE(a, b, c) TAILQ_INSERT_BEFORE(a, b, c) -#define RB_TAILQ_INSERT_AFTER(a, b, c, d) TAILQ_INSERT_AFTER(a, b, c, d) -#else -#define RB_TAILQ_REMOVE(a, b, c) do { } while (/*CONSTCOND*/0) -#define RB_TAILQ_INIT(a) do { } while (/*CONSTCOND*/0) -#define RB_TAILQ_INSERT_HEAD(a, b, c) do { } while (/*CONSTCOND*/0) -#define RB_TAILQ_INSERT_BEFORE(a, b, c) do { } while (/*CONSTCOND*/0) -#define RB_TAILQ_INSERT_AFTER(a, b, c, d) do { } while (/*CONSTCOND*/0) -#endif /* RBDEBUG */ - -/* - * rbto_compare_nodes_fn: - * return a positive value if the first node > the second node. - * return a negative value if the first node < the second node. - * return 0 if they are considered same. - * - * rbto_compare_key_fn: - * return a positive value if the node > the key. - * return a negative value if the node < the key. - * return 0 if they are considered same. - */ - -typedef signed int (*rbto_compare_nodes_fn)(void *, const void *, const void *); -typedef signed int (*rbto_compare_key_fn)(void *, const void *, const void *); - -typedef struct { - rbto_compare_nodes_fn rbto_compare_nodes; - rbto_compare_key_fn rbto_compare_key; - size_t rbto_node_offset; - void *rbto_context; -} rb_tree_ops_t; - -typedef struct rb_tree { - struct rb_node *rbt_root; - const rb_tree_ops_t *rbt_ops; - struct rb_node *rbt_minmax[2]; -#ifdef RBDEBUG - struct rb_node_qh rbt_nodes; -#endif -#ifdef RBSTATS - unsigned int rbt_count; - unsigned int rbt_insertions; - unsigned int rbt_removals; - unsigned int rbt_insertion_rebalance_calls; - unsigned int rbt_insertion_rebalance_passes; - unsigned int rbt_removal_rebalance_calls; - unsigned int rbt_removal_rebalance_passes; -#endif -} rb_tree_t; - -#ifdef RBSTATS -#define RBSTAT_INC(v) ((void)((v)++)) -#define RBSTAT_DEC(v) ((void)((v)--)) -#else -#define RBSTAT_INC(v) do { } while (/*CONSTCOND*/0) -#define RBSTAT_DEC(v) do { } while (/*CONSTCOND*/0) -#endif - -void rb_tree_init(rb_tree_t *, const rb_tree_ops_t *); -void * rb_tree_insert_node(rb_tree_t *, void *); -void * rb_tree_find_node(rb_tree_t *, const void *); -void * rb_tree_find_node_geq(rb_tree_t *, const void *); -void * rb_tree_find_node_leq(rb_tree_t *, const void *); -void rb_tree_remove_node(rb_tree_t *, void *); -void * rb_tree_iterate(rb_tree_t *, void *, const unsigned int); -#ifdef RBDEBUG -void rb_tree_check(const rb_tree_t *, bool); -#endif -#ifdef RBSTATS -void rb_tree_depths(const rb_tree_t *, size_t *); -#endif - -__END_DECLS - -#endif /* _SYS_RBTREE_H_*/ diff --git a/external/bsd/dhcpcd/dist/compat/reallocarray.c b/external/bsd/dhcpcd/dist/compat/reallocarray.c deleted file mode 100644 index ff3ff4f11a0..00000000000 --- a/external/bsd/dhcpcd/dist/compat/reallocarray.c +++ /dev/null @@ -1,60 +0,0 @@ -/* $NetBSD: reallocarray.c,v 1.1.1.1 2017/03/31 20:51:15 roy Exp $ */ - -/*- - * Copyright (c) 2015 Joerg Sonnenberger <joerg@NetBSD.org>. - * 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. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 - * COPYRIGHT HOLDERS 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. - */ - -#include <errno.h> -#include <limits.h> -#include <stddef.h> -#include <stdint.h> -#include <stdlib.h> - -/* - * To be clear, this is NetBSD's more refined reallocarr(3) function - * made to look like OpenBSD's more useable reallocarray(3) interface. - */ -#include "reallocarray.h" - -#define SQRT_SIZE_MAX (((size_t)1) << (sizeof(size_t) * CHAR_BIT / 2)) -void * -reallocarray(void *ptr, size_t n, size_t size) -{ - - /* - * Try to avoid division here. - * - * It isn't possible to overflow during multiplication if neither - * operand uses any of the most significant half of the bits. - */ - if ((n | size) >= SQRT_SIZE_MAX && n > SIZE_MAX / size) { - errno = EOVERFLOW; - return NULL; - } - return realloc(ptr, n * size); -} diff --git a/external/bsd/dhcpcd/dist/compat/reallocarray.h b/external/bsd/dhcpcd/dist/compat/reallocarray.h deleted file mode 100644 index 09b66054772..00000000000 --- a/external/bsd/dhcpcd/dist/compat/reallocarray.h +++ /dev/null @@ -1,37 +0,0 @@ -/* $NetBSD: reallocarray.h,v 1.1.1.1 2017/03/31 20:51:15 roy Exp $ */ - -/*- - * Copyright (c) 2015 Joerg Sonnenberger <joerg@NetBSD.org>. - * 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. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 - * COPYRIGHT HOLDERS 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. - */ - -#ifndef REALLOCARRAY_H -#define REALLOCARRAY_H - -void *reallocarray(void *, size_t, size_t); - -#endif diff --git a/external/bsd/dhcpcd/dist/compat/strlcpy.c b/external/bsd/dhcpcd/dist/compat/strlcpy.c deleted file mode 100644 index 1fb4a2f9615..00000000000 --- a/external/bsd/dhcpcd/dist/compat/strlcpy.c +++ /dev/null @@ -1,51 +0,0 @@ -/* $OpenBSD: strlcpy.c,v 1.15 2016/10/16 17:37:39 dtucker Exp $ */ - -/* - * Copyright (c) 1998, 2015 Todd C. Miller <Todd.Miller@courtesan.com> - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include <sys/types.h> - -#include "strlcpy.h" - -/* - * Copy string src to buffer dst of size dsize. At most dsize-1 - * chars will be copied. Always NUL terminates (unless dsize == 0). - * Returns strlen(src); if retval >= dsize, truncation occurred. - */ -size_t -strlcpy(char *dst, const char *src, size_t dsize) -{ - const char *osrc = src; - size_t nleft = dsize; - - /* Copy as many bytes as will fit. */ - if (nleft != 0) { - while (--nleft != 0) { - if ((*dst++ = *src++) == '\0') - break; - } - } - - /* Not enough room in dst, add NUL and traverse rest of src. */ - if (nleft == 0) { - if (dsize != 0) - *dst = '\0'; /* NUL-terminate dst */ - while (*src++) - ; - } - - return (size_t)(src - osrc - 1); /* count does not include NUL */ -} diff --git a/external/bsd/dhcpcd/dist/compat/strlcpy.h b/external/bsd/dhcpcd/dist/compat/strlcpy.h deleted file mode 100644 index 2131cdec305..00000000000 --- a/external/bsd/dhcpcd/dist/compat/strlcpy.h +++ /dev/null @@ -1,24 +0,0 @@ -/* $OpenBSD: strlcpy.c,v 1.15 2016/10/16 17:37:39 dtucker Exp $ */ - -/* - * Copyright (c) 1998, 2015 Todd C. Miller <Todd.Miller@courtesan.com> - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef STRLCPY_H -#define STRLCPY_H - -size_t strlcpy(char *, const char *, size_t); - -#endif diff --git a/external/bsd/dhcpcd/dist/compat/strtoi.c b/external/bsd/dhcpcd/dist/compat/strtoi.c deleted file mode 100644 index 3cdeba8ff61..00000000000 --- a/external/bsd/dhcpcd/dist/compat/strtoi.c +++ /dev/null @@ -1,68 +0,0 @@ -/* $NetBSD: strtoi.c,v 1.1.1.1 2017/03/31 20:51:15 roy Exp $ */ - -/*- - * Copyright (c) 2005 The DragonFly Project. All rights reserved. - * Copyright (c) 2003 Citrus Project, - * 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. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. - * - * Created by Kamil Rytarowski, based on ID: - * NetBSD: src/common/lib/libc/stdlib/strtoul.c,v 1.3 2008/08/20 19:58:34 oster Exp - */ - -#if HAVE_NBTOOL_CONFIG_H -#include "nbtool_config.h" -#endif - -#ifdef _LIBC -#include "namespace.h" -#endif - -#if defined(_KERNEL) -#include <sys/param.h> -#include <sys/types.h> -#include <lib/libkern/libkern.h> -#elif defined(_STANDALONE) -#include <sys/param.h> -#include <sys/types.h> -#include <lib/libkern/libkern.h> -#include <lib/libsa/stand.h> -#else -#include <stddef.h> -#include <assert.h> -#include <errno.h> -#include <inttypes.h> -#endif - -#include "strtoi.h" - -#define _FUNCNAME strtoi -#define __TYPE intmax_t -#define __WRAPPED strtoimax - -#include "_strtoi.h" - -#ifdef _LIBC -__weak_alias(strtoi, _strtoi) -__weak_alias(strtoi_l, _strtoi_l) -#endif diff --git a/external/bsd/dhcpcd/dist/compat/strtoi.h b/external/bsd/dhcpcd/dist/compat/strtoi.h deleted file mode 100644 index bd976fcf3ca..00000000000 --- a/external/bsd/dhcpcd/dist/compat/strtoi.h +++ /dev/null @@ -1,45 +0,0 @@ -/*- - * Copyright (c) 1990, 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. - * - * Original version ID: - * NetBSD: src/lib/libc/locale/_wcstoul.h,v 1.2 2003/08/07 16:43:03 agc Exp - * - * Created by Kamil Rytarowski, based on ID: - * NetBSD: src/common/lib/libc/stdlib/_strtoul.h,v 1.7 2013/05/17 12:55:56 joerg Exp - */ - -#ifndef STRTOI_H -#define STRTOI_H - -#include <inttypes.h> - -intmax_t strtoi(const char * __restrict nptr, char ** __restrict endptr, - int base, intmax_t lo, intmax_t hi, int *rstatus); -uintmax_t strtou(const char * __restrict nptr, char ** __restrict endptr, - int base, uintmax_t lo, uintmax_t hi, int *rstatus); -#endif diff --git a/external/bsd/dhcpcd/dist/compat/strtou.c b/external/bsd/dhcpcd/dist/compat/strtou.c deleted file mode 100644 index 6a3df65ac2b..00000000000 --- a/external/bsd/dhcpcd/dist/compat/strtou.c +++ /dev/null @@ -1,68 +0,0 @@ -/* $NetBSD: strtou.c,v 1.1.1.1 2017/03/31 20:51:15 roy Exp $ */ - -/*- - * Copyright (c) 2005 The DragonFly Project. All rights reserved. - * Copyright (c) 2003 Citrus Project, - * 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. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. - * - * Created by Kamil Rytarowski, based on ID: - * NetBSD: src/common/lib/libc/stdlib/strtoul.c,v 1.3 2008/08/20 19:58:34 oster Exp - */ - -#if HAVE_NBTOOL_CONFIG_H -#include "nbtool_config.h" -#endif - -#ifdef _LIBC -#include "namespace.h" -#endif - -#if defined(_KERNEL) -#include <sys/param.h> -#include <sys/types.h> -#include <lib/libkern/libkern.h> -#elif defined(_STANDALONE) -#include <sys/param.h> -#include <sys/types.h> -#include <lib/libkern/libkern.h> -#include <lib/libsa/stand.h> -#else -#include <stddef.h> -#include <assert.h> -#include <errno.h> -#include <inttypes.h> -#endif - -#include "strtoi.h" - -#define _FUNCNAME strtou -#define __TYPE uintmax_t -#define __WRAPPED strtoumax - -#include "_strtoi.h" - -#ifdef _LIBC -__weak_alias(strtou, _strtou) -__weak_alias(strtou_l, _strtou_l) -#endif diff --git a/external/bsd/dhcpcd/dist/config-null.mk b/external/bsd/dhcpcd/dist/config-null.mk deleted file mode 100644 index c7a8de384f4..00000000000 --- a/external/bsd/dhcpcd/dist/config-null.mk +++ /dev/null @@ -1,3 +0,0 @@ -# This space left intentionally blank - -DHCPCD_SRCS+= dhcpcd-embedded.c diff --git a/external/bsd/dhcpcd/dist/configure b/external/bsd/dhcpcd/dist/configure deleted file mode 100755 index 67a5bed75d5..00000000000 --- a/external/bsd/dhcpcd/dist/configure +++ /dev/null @@ -1,1639 +0,0 @@ -#!/bin/sh -# Try and be like autotools configure, but without autotools - -echo "configure args: $*" -exec 3>config.log - -# Ensure that we do not inherit these from env -HOOKSET=false -INET= -ARP= -ARPING= -IPV4LL= -INET6= -ARC4RANDOM= -CLOSEFROM= -RBTREE= -CONSTTIME_MEMEQUAL= -OPEN_MEMSTREAM= -STRLCPY= -UDEV= -OS= -BUILD= -HOST= -HOSTCC= -TARGET= -INCLUDEDIR= -DEBUG= -FORK= -STATIC= -DEVS= -EMBEDDED= -AUTH= -POLL= -SMALL= -STATUSARG= - -DHCPCD_DEFS=dhcpcd-definitions.conf - -for x do - opt=${x%%=*} - var=${x#*=} - case "$opt" in - --os|OS) OS=$var;; - --debug) DEBUG=$var;; - --disable-debug) DEBUG=no;; - --enable-debug) DEBUG=yes;; - --fork) FORK=$var;; - --disable-fork) FORK=no;; - --enable-fork) FORK=yes;; - --disable-static) STATIC=no;; - --enable-static) STATIC=yes;; - --disable-ipv4|--disable-inet) INET=no; ARP=no; ARPING=no; IPV4LL=no;; - --enable-ipv4|--enable-inet) INET=yes;; - --disable-arp) ARP=no; ARPING=no; IPV4LL=no;; - --enable-arp) ARP=yes; INET=yes;; - --disable-arping) ARPING=no;; - --enable-arping) ARPING=yes; ARP=yes; INET=yes;; - --disable-ipv4ll) IPV4LL=no;; - --enable-ipv4ll) IPV4LL=yes; ARP=yes; INET=yes;; - --disable-ipv6|--disable-inet6) INET6=no; DHCP6=no;; - --enable-ipv6|--enable-inet6) INET6=yes;; - --disable-dhcp6) DHCP6=no;; - --enable-dhcp6) DHCP6=yes;; - --disable-embedded) EMBEDDED=no;; - --enable-embedded) EMBEDDED=yes;; - --disable-auth) AUTH=no;; - --enable-auth) AUTH=yes;; - --prefix) PREFIX=$var;; - --sysconfdir) SYSCONFDIR=$var;; - --bindir|--sbindir) SBINDIR=$var;; - --libexecdir) LIBEXECDIR=$var;; - --statedir|--localstatedir) STATEDIR=$var;; - --dbdir) DBDIR=$var;; - --rundir) RUNDIR=$var;; - --mandir) MANDIR=$var;; - --datadir) DATADIR=$var;; - --with-ccopts|CFLAGS) CFLAGS=$var;; - -I|--includedir) INCLUDEDIR="$INCLUDEDIR${INCLUDEDIR:+ }-I$var";; - CC) CC=$var;; - CPPFLAGS) CPPFLAGS=$var;; - PKG_CONFIG) PKG_CONFIG=$var;; - --with-hook) HOOKSCRIPTS="$HOOKSCRIPTS${HOOKSCRIPTS:+ }$var";; - --with-hooks|HOOKSCRIPTS) HOOKSCRIPTS=$var; HOOKSET=true;; - --build) BUILD=$var;; - --host) HOST=$var; HOSTCC=$var-;; - --target) TARGET=$var;; - --libdir) LIBDIR=$var;; - --without-arc4random) ARC4RANDOM=no;; - --without-strlcpy) STRLCPY=no;; - --without-pidfile_lock) PIDFILE_LOCK=no;; - --without-reallocarrray) REALLOCARRAY=no;; - --without-md5) MD5=no;; - --without-sha2) SHA2=no;; - --without-sha256) SHA2=no;; - --without-hmac) HMAC=no;; - --without-dev) DEV=no;; - --with-udev) DEV=yes; UDEV=yes;; - --without-udev) UDEV=no;; - --with-poll) POLL="$var";; - --serviceexists) SERVICEEXISTS=$var;; - --servicecmd) SERVICECMD=$var;; - --servicestatus) SERVICESTATUS=$var;; - --small) SMALL=yes;; - --statusarg) STATUSARG=$var;; - --infodir) ;; # ignore autotools - --disable-maintainer-mode|--disable-dependency-tracking) ;; - --disable-silent-rules) ;; - -V|--version) - v=$(sed -ne 's/.*VERSION[[:space:]]*"\([^"]*\).*/\1/p' defs.h); - c=$(sed -ne 's/^.*copyright\[\] = "\([^"]*\).*/\1/p' dhcpcd.c); - echo "dhcpcd-$v $c"; - exit 0;; - -h|--help) cat <<EOF -\`configure' configures this package to adapt to many kinds of systems. - -Usage: configure [OPTION]... [VAR=VALUE]... - -To assign environment variables (e.g., CC, CFLAGS...), specify them as -VAR=VALUE. See below for descriptions of some of the useful variables. - -Defaults for the options are specified in brackets. - -Configuration: - -h, --help display this help and exit - --help=short display options specific to this package - -V, --version display version information and exit - -Installation directories: - --prefix=PREFIX install architecture-independent files in PREFIX [/] - -By default, \`make install' will install all the files in \'/sbin', -\`/libexec', etc. You can specify -an installation prefix other than \`/' using \`--prefix', -for instance \`--prefix=$HOME'. - -For better control, use the options below. - -Fine tuning of the installation directories: - --bindir=DIR user executables [PREFIX/bin] - --sbindir=DIR system admin executables [PREFIX/sbin] - --libexecdir=DIR program executables [PREFIX/libexec] - --sysconfdir=DIR read-only single-machine data [PREFIX/etc] - --localstatedir=DIR modifiable single-machine data [/var] - --libdir=DIR object code libraries [PREFIX/lib] - --includedir=DIR C header files [PREFIX/include] - --mandir=DIR man documentation [PREFIX/man] - -System types: - --build=BUILD configure for building on BUILD [guessed] - --host=HOST build programs to run on HOST [BUILD] - --target=TARGET configure for building compilers for TARGET [HOST] - -Optional Features: - --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no) - --enable-FEATURE[=ARG] include FEATURE [ARG=yes] - -Some influential environment variables: - CC C compiler command - CFLAGS C compiler flags - LDFLAGS linker flags, e.g. -L<lib dir> if you have libraries in a - nonstandard directory <lib dir> - CPPFLAGS C/C++ preprocessor flags, e.g. -I<include dir> if you have - headers in a nonstandard directory <include dir> - CPP C preprocessor - PKG_CONFIG pkg-config executable - -Use these variables to override the choices made by \`configure' or to help -it to find libraries and programs with nonstandard names/locations. -EOF -exit 0 -;; - *) echo "$0: WARNING: unknown option $opt" >&2;; - esac -done - -: ${SED:=sed} -: ${GREP:=grep} -: ${PKG_CONFIG:=pkg-config} -: ${WC:=wc} - -: ${FORK:=yes} -_which() -{ - x="$(which "$1" 2>/dev/null)" - if [ $? = 0 -a -n "$x" ]; then - echo "$x" - return 0 - fi - for x in /sbin/"$1" /usr/sbin/"$1" \ - /usr/pkg/sbin/"$1" /usr/local/sbin/"$1" - do - if [ -e "$x" ]; then - echo "$x" - return 0 - fi - done - return 1 -} - -CONFIG_H=config.h -CONFIG_MK=config.mk - -if [ -z "$BUILD" ]; then - # autoconf target triplet: cpu-vendor-os - BUILD=$(uname -m)-unknown-$(uname -s | tr '[:upper:]' '[:lower:]') -fi -: ${HOST:=$BUILD} - -if [ -z "$OS" ]; then - echo "Deriving operating system from ... $HOST" - # Derive OS from cpu-vendor-[kernel-]os - CPU=${HOST%%-*} - REST=${HOST#*-} - if [ "$CPU" != "$REST" ]; then - VENDOR=${REST%%-*} - REST=${REST#*-} - if [ "$VENDOR" != "$REST" ]; then - # Use kernel if given, otherwise os - OS=${REST%%-*} - else - # 2 tupple - OS=$VENDOR - VENDOR= - fi - fi - - # Work with cpu-kernel-os, ie Debian - case "$VENDOR" in - linux*|kfreebsd*) OS=$VENDOR; VENDOR= ;; - esac - case "$REST" in - gnu/kfreebsd*) OS="kfreebsd"; VENDOR= ;; - esac - # Special case - case "$OS" in - dragonfly*) - # This means /usr HAS to be mounted not via dhcpcd - : ${LIBEXECDIR:=${PREFIX:-/usr}/libexec} - ;; - gnu*) OS=hurd;; # No HURD support as yet - esac -fi - -echo "Configuring dhcpcd for ... $OS" -rm -f $CONFIG_H $CONFIG_MK -echo "# $OS" >$CONFIG_MK -echo "/* $OS */" >$CONFIG_H - -: ${SYSCONFDIR:=$PREFIX/etc} -: ${SBINDIR:=$PREFIX/sbin} -: ${LIBDIR:=$PREFIX/lib} -: ${LIBEXECDIR:=$PREFIX/libexec} -: ${STATEDIR:=/var} -: ${DBDIR:=$STATEDIR/db/dhcpcd} -: ${RUNDIR:=$STATEDIR/run} -: ${MANDIR:=${PREFIX:-/usr}/share/man} -: ${DATADIR:=${PREFIX:-/usr}/share} - -eval SYSCONFDIR="$SYSCONFDIR" -eval LIBDIR="$LIBDIR" -eval LIBEXECDIR="$LIBEXECDIR" -eval STATEDIR="$STATEDIR" -eval DBDIR="$DBDIR" -eval RUNDIR="$RUNDIR" -eval MANDIR="$MANDIR" -eval DATADIR="$DATADIR" - -echo "#ifndef SYSCONFDIR" >>$CONFIG_H -for x in SYSCONFDIR SBINDIR LIBDIR LIBEXECDIR DBDIR RUNDIR; do - eval v=\$$x - # Make files look nice for import - l=$((10 - ${#x})) - unset t - [ $l -gt 3 ] && t=" " - echo "$x=$t $v" >>$CONFIG_MK - unset t - [ $l -gt 2 ] && t=" " - echo "#define $x$t \"$v\"" >>$CONFIG_H -done -echo "#endif" >>$CONFIG_H - -echo "LIBDIR= $LIBDIR" >>$CONFIG_MK -echo "MANDIR= $MANDIR" >>$CONFIG_MK -echo "DATADIR= $DATADIR" >>$CONFIG_MK - -# Always obey CC. -if [ -n "$CC" ]; then - HOSTCC= -else - CC=cc - _COMPILERS="cc clang gcc pcc icc" -fi -# Only look for a cross compiler if --host and --build are not the same -if [ -n "$HOSTCC" -a "$BUILD" != "$HOST" ]; then - for _CC in $_COMPILERS; do - _CC=$(_which "$HOSTCC$_CC") - if [ -x "$_CC" ]; then - CC=$_CC - break - fi - done -fi -if ! type "$CC" >/dev/null 2>&1; then - for _CC in $_COMPILERS; do - _CC=$(_which "$_CC") - if [ -x "$_CC" ]; then - CC=$_CC - break - fi - done -fi - -# Set to blank, then append user config -# We do this so our SED call to append to XCC remains portable -if [ -n "$CFLAGS" ]; then - echo "CFLAGS=" >>$CONFIG_MK - echo "CFLAGS+= $CFLAGS" >>$CONFIG_MK -fi -if [ -n "$CPPFLAGS" ]; then - echo "CPPFLAGS=" >>$CONFIG_MK - echo "CPPFLAGS+= $CPPFLAGS" >>$CONFIG_MK -fi -if [ -n "$INCLUDEDIR" ]; then - echo "CPPFLAGS+= $INCLUDEDIR" >>$CONFIG_MK -fi -if [ -n "$LDFLAGS" ]; then - echo "LDFLAGS=" >>$CONFIG_MK - echo "LDFLAGS+= $LDFLAGS" >>$CONFIG_MK -fi - -echo "CPPFLAGS+= -DHAVE_CONFIG_H" >>$CONFIG_MK - -# NetBSD: Even if we build for $PREFIX, the clueless user might move us to / -LDELF=/libexec/ld.elf_so -if [ -e "$LDELF" ]; then - echo "Linking against $LDELF" - echo "LDFLAGS+= -Wl,-dynamic-linker=$LDELF" >>$CONFIG_MK - echo "LDFLAGS+= -Wl,-rpath=${LIBDIR}" >>$CONFIG_MK -fi - -if [ -z "$PREFIX" -o "$PREFIX" = / ]; then - ALLOW_USR_LIBS=false -else - ALLOW_USR_LIBS=true -fi -case "$OS" in -linux*|sunos*|kfreebsd*) ;; -*) - # There might be more than one ... - for LDELFN in /libexec/ld-elf.so.[0-9]*; do - [ -x "$LDELFN" ] && break - done - if ! [ -x "$LDELF" -o -x "$LDELFN" ] && \ - [ -z "$PREFIX" -o "$PREFIX" = "/" ] - then - echo "Forcing a static build for $OS and \$PREFIX of /" - STATIC=yes - ALLOW_USR_LIBS=true - fi - ;; -esac -if [ "$STATIC" = yes ]; then - echo "LDFLAGS+= -static" >>$CONFIG_MK -fi - -if [ -z "$DEBUG" -a -f .fslckout ]; then - printf "Found fossil checkout ... " - DEBUG=yes -fi -if [ -z "$DEBUG" -a -d .git ]; then - printf "Found git checkout ... " - DEBUG=yes -fi -if [ -n "$DEBUG" -a "$DEBUG" != no -a "$DEBUG" != false ]; then - echo "Adding debugging CFLAGS" - cat <<EOF >>$CONFIG_MK -CFLAGS+= -g -Wall -Wextra -CFLAGS+= -Wmissing-prototypes -Wmissing-declarations -CFLAGS+= -Wmissing-format-attribute -Wnested-externs -CFLAGS+= -Winline -Wcast-align -Wcast-qual -Wpointer-arith -CFLAGS+= -Wreturn-type -Wswitch -Wshadow -CFLAGS+= -Wcast-qual -Wwrite-strings -CFLAGS+= -Wformat=2 -CFLAGS+= -Wpointer-sign -Wmissing-noreturn -EOF - case "$OS" in - mirbsd*|openbsd*);; # OpenBSD has many redundant decs in system headers - bitrig*|sunos*) echo "CFLAGS+= -Wredundant-decls" >>$CONFIG_MK - ;; # Bitrig spouts many conversion errors with htons - # sunos has many as well - *) echo "CFLAGS+= -Wredundant-decls" >>$CONFIG_MK - echo "CFLAGS+= -Wconversion" >>$CONFIG_MK - ;; - esac - - case "$OS" in - sunos*);; - *) echo "CFLAGS+= -Wstrict-overflow" >>$CONFIG_MK;; - esac - - # Turn on extra per compiler debugging - case "$CC" in - *gcc*) echo "CFLAGS+= -Wlogical-op" >>$CONFIG_MK;; - esac -else - echo "CPPFLAGS+= -DNDEBUG" >>$CONFIG_MK -fi - -if [ -n "$FORK" -a "$FORK" != yes -a "$FORK" != true ]; then - echo "There is no fork" - echo "CPPFLAGS+= -DTHERE_IS_NO_FORK" >>$CONFIG_MK -fi - -if [ "$SMALL" = yes ]; then - echo "Building with -DSMALL" - echo "CPPFLAGS+= -DSMALL" >>$CONFIG_MK - DHCPCD_DEFS=dhcpcd-definitions-small.conf - echo "DHCPCD_DEFS= $DHCPCD_DEFS" >>$CONFIG_MK -fi - -case "$OS" in -freebsd*|kfreebsd*) - # FreeBSD hide some newer POSIX APIs behind _GNU_SOURCE ... - echo "CPPFLAGS+= -D_GNU_SOURCE" >>$CONFIG_MK - case "$OS" in - kfreebsd*) echo "CPPFLAGS+= -DBSD" >>$CONFIG_MK;; - esac - echo "DHCPCD_SRCS+= if-bsd.c" >>$CONFIG_MK - # Whacky includes needed to buck the trend - case "$OS" in - kfreebsd*) echo "#include <inttypes.h>" >>$CONFIG_H; - esac - echo "#include <net/if.h>" >>$CONFIG_H - echo "#include <net/if_var.h>" >>$CONFIG_H - ;; -netbsd*) - # reallocarray(3) is guarded by _OPENBSD_SOURCE - echo "CPPFLAGS+= -D_OPENBSD_SOURCE" >>$CONFIG_MK - echo "DHCPCD_SRCS+= if-bsd.c" >>$CONFIG_MK - ;; -linux*) - echo "CPPFLAGS+= -D_GNU_SOURCE" >>$CONFIG_MK - # Large File Support, should be fine for 32-bit systems. - # But if this is the case, why is it not set by default? - echo "CPPFLAGS+= -D_FILE_OFFSET_BITS=64" >>$CONFIG_MK - echo "CPPFLAGS+= -D_LARGEFILE_SOURCE" >>$CONFIG_MK - echo "CPPFLAGS+= -D_LARGEFILE64_SOURCE" >>$CONFIG_MK - echo "DHCPCD_SRCS+= if-linux.c" >>$CONFIG_MK - # for RTM_NEWADDR and friends - echo "#include <asm/types.h> /* fix broken headers */" >>$CONFIG_H - echo "#include <sys/socket.h> /* fix broken headers */" >>$CONFIG_H - echo "#include <linux/rtnetlink.h>" >>$CONFIG_H - # cksum does't support -a and netpgp is rare - echo "CKSUM= sha256sum --tag" >>$CONFIG_MK - echo "PGP= gpg2" >>$CONFIG_MK - ;; -qnx*) - echo "CPPFLAGS+= -D__EXT" >>$CONFIG_MK - echo "DHCPCD_SRCS+= if-bsd.c" >>$CONFIG_MK - ;; -sunos*) - echo "CPPFLAGS+= -D_XPG4_2 -D__EXTENSIONS__ -DBSD_COMP" \ - >>$CONFIG_MK - echo "DHCPCD_SRCS+= if-sun.c" >>$CONFIG_MK - echo "LDADD+= -ldlpi -lkstat" >>$CONFIG_MK - ;; -*) - echo "DHCPCD_SRCS+= if-bsd.c" >>$CONFIG_MK - ;; -esac - -if [ -z "$INET" -o "$INET" = yes ]; then - echo "Enabling INET support" - echo "CPPFLAGS+= -DINET" >>$CONFIG_MK - echo "DHCPCD_SRCS+= dhcp.c ipv4.c bpf.c" >>$CONFIG_MK - if [ -z "$ARP" -o "$ARP" = yes ]; then - echo "Enabling ARP support" - echo "CPPFLAGS+= -DARP" >>$CONFIG_MK - echo "DHCPCD_SRCS+= arp.c" >>$CONFIG_MK - fi - if [ -z "$ARPING" -o "$ARPING" = yes ]; then - echo "Enabling ARPing support" - echo "CPPFLAGS+= -DARPING" >>$CONFIG_MK - fi - if [ -z "$IPV4LL" -o "$IPV4LL" = yes ]; then - echo "Enabling IPv4LL support" - echo "CPPFLAGS+= -DIPV4LL" >>$CONFIG_MK - echo "DHCPCD_SRCS+= ipv4ll.c" >>$CONFIG_MK - fi -fi -if [ -z "$INET6" -o "$INET6" = yes ]; then - echo "Enabling INET6 support" - echo "CPPFLAGS+= -DINET6" >>$CONFIG_MK - echo "DHCPCD_SRCS+= ipv6.c ipv6nd.c" >>$CONFIG_MK - if [ -z "$DHCP6" -o "$DHCP6" = yes ]; then - echo "Enabling DHCPv6 support" - echo "CPPFLAGS+= -DDHCP6" >>$CONFIG_MK - echo "DHCPCD_SRCS+= dhcp6.c" >>$CONFIG_MK - fi -fi -if [ -z "$AUTH" -o "$AUTH" = yes ]; then - echo "Enabling Authentication" - echo "CPPFLAGS+= -DAUTH" >>$CONFIG_MK - echo "SRCS+= auth.c" >>$CONFIG_MK -fi - -echo "Using compiler .. $CC" -# Add CPPFLAGS and CFLAGS to CC for testing features -XCC="$CC `$SED -n -e 's/CPPFLAGS+=*\(.*\)/\1/p' $CONFIG_MK`" -XCC="$XCC `$SED -n -e 's/CFLAGS+=*\(.*\)/\1/p' $CONFIG_MK`" - -# When running tests, treat all warnings as errors. -# This avoids the situation where we link to a libc symbol -# without the correct header because it might be hidden behind -# a _*_SOURCE #define guard. -XCC="$XCC -Wall -Werror" - -# Now test we can use the compiler with our CFLAGS -cat <<EOF >_test.c -int main(void) { - return 0; -} -EOF -_CC=false -if $XCC _test.c -o _test >/dev/null 2>&3; then - [ -x _test ] && _CC=true -fi -rm -f _test.c _test -if ! $_CC; then - echo "$CC does not create executables" >&2 - exit 1 -fi -[ "$CC" != cc ] && echo "CC= $CC" >>$CONFIG_MK -$CC --version | $SED -e '1!d' - -if [ -z "$EMBEDDED" -o "$EMBEDDED" = yes ]; then - echo "$DHCPCD_DEFS will be embedded in dhcpcd itself" - echo "DHCPCD_SRCS+= dhcpcd-embedded.c" >>$CONFIG_MK -else - echo "$DHCPCD_DEFS will be installed to $LIBEXECDIR" - echo "CPPFLAGS+= -DEMBEDDED_CONFIG=\\\"$LIBEXECDIR/dhcpcd-definitions.conf\\\"" >>$CONFIG_MK - echo "EMBEDDEDINSTALL= _embeddedinstall" >>$CONFIG_MK -fi - -if [ "$OS" = linux ]; then - printf "Testing for nl80211 ... " - cat <<EOF >_nl80211.c -#include <linux/nl80211.h> -int main(void) { - return 0; -} -EOF - if $XCC _nl80211.c -o _nl80211 2>&3; then - echo "yes" - echo "#define HAVE_NL80211_H" >>$CONFIG_H - else - echo "no" - echo "DHCPCD_SRCS+= if-linux-wext.c" >>$CONFIG_MK - fi - rm -f _nl80211.c _nl80211 - - printf "Testing for IN6_ADDR_GEN_MODE_NONE ... " - cat <<EOF >_IN6_ADDR_GEN_MODE_NONE.c -#include <linux/if_link.h> -int main(void) { - int x = IN6_ADDR_GEN_MODE_NONE; - return x; -} -EOF - if $XCC _IN6_ADDR_GEN_MODE_NONE.c -o _IN6_ADDR_GEN_MODE_NONE 2>&3; then - echo "yes" - echo "#define HAVE_IN6_ADDR_GEN_MODE_NONE" >>$CONFIG_H - else - echo "no" - fi - rm -f _IN6_ADDR_GEN_MODE_NONE.c _IN6_ADDR_GEN_MODE_NONE -else - printf "Testing for ifam_pid ... " - cat <<EOF >_ifam_pid.c -#include <net/if.h> -int main(void) { - struct ifa_msghdr ifam = { }; - return (int)ifam.ifam_pid; -} -EOF - if $XCC _ifam_pid.c -o _ifam_pid 2>&3; then - echo "yes" - echo "#define HAVE_IFAM_PID" >>$CONFIG_H - else - echo "no" - fi - rm -f _ifam_pid.c _ifam_pid - - printf "Testing for ifam_addrflags ... " - cat <<EOF >_ifam_addrflags.c -#include <net/if.h> -int main(void) { - struct ifa_msghdr ifam = { }; - return (int)ifam.ifam_addrflags; -} -EOF - if $XCC _ifam_addrflags.c -o _ifam_addrflags 2>&3; then - echo "yes" - echo "#define HAVE_IFAM_ADDRFLAGS" >>$CONFIG_H - else - echo "no" - fi - rm -f _ifam_addrflags.c _ifam_addrflags -fi - -abort=false -# We require the libc to support non standard functions, like getifaddrs -printf "Testing for getifaddrs ... " -cat <<EOF >_getifaddrs.c -#include <sys/types.h> -#include <ifaddrs.h> -int main(void) { - struct ifaddrs *ifap; - return getifaddrs(&ifap); -} -EOF -LIBSOCKET= -if $XCC _getifaddrs.c -o _getifaddrs 2>&3; then - echo "yes" -elif $XCC _getifaddrs.c -o _getifaddrs -lsocket 2>&3; then - LIBSOCKET=-lsocket - echo "yes (-lsocket)" - echo "LDADD+= -lsocket" >>$CONFIG_MK -else - echo "no" - echo "libc support for getifaddrs is required - aborting" >&2 - abort=true -fi -rm -f _getifaddrs.c _getifaddrs -$abort && exit 1 - -printf "Testing for ifaddrs.ifa_addrflags ... " -cat <<EOF >_getifaddrs_addrflags.c -#include <sys/types.h> -#include <ifaddrs.h> -int main(void) { - struct ifaddrs *ifap; - getifaddrs(&ifap); - return (int)ifap->ifa_addrflags; -} -EOF -if $XCC _getifaddrs_addrflags.c -o _getifaddrs_addrflags $LIBSOCKET 2>&3; then - echo "yes" - echo "#define HAVE_IFADDRS_ADDRFLAGS" >>$CONFIG_H -else - echo "no" -fi -rm -f _getifaddrs_addrflags.c _getifaddrs_addrflags - -printf "Testing for clock_gettime ... " -cat <<EOF >_clock_gettime.c -#include <time.h> -int main(void) { - struct timespec ts; - return clock_gettime(CLOCK_MONOTONIC, &ts); -} -EOF -if $XCC _clock_gettime.c -o _clock_gettime 2>&3; then - echo "yes" -elif $XCC _clock_gettime.c -lrt -o _clock_gettime 2>&3; then - echo "yes (-lrt)" - echo "LDADD+= -lrt" >>$CONFIG_MK -else - echo "no" - echo "libc support for clock_getttime is required - aborting" >&2 - abort=true -fi -rm -f _clock_gettime.c _clock_gettime -$abort && exit 1 - -printf "Testing for inet_ntoa ... " -cat <<EOF >_inet_ntoa.c -#include <netinet/in.h> -#include <arpa/inet.h> -int main(void) { - struct in_addr in = { .s_addr = 0 }; - inet_ntoa(in); - return 0; -} -EOF -if $XCC _inet_ntoa.c -o _inet_ntoa 2>&3; then - echo "yes" -elif $XCC _inet_ntoa.c -lnsl -o _inet_ntoa 2>&3; then - echo "yes (-lnsl)" - echo "LDADD+= -lnsl" >>$CONFIG_MK -elif $XCC _inet_ntoa.c -lsocket -o _inet_ntoa 2>&3; then - echo "yes (-lsocket)" - echo "LDADD+= -lsocket" >>$CONFIG_MK -else - echo "no" - echo "libc support for inet_ntoa is required - aborting" >&2 - abort=true -fi -rm -f _inet_ntoa.c _inet_ntoa -$abort && exit 1 - -if [ -z "$ARC4RANDOM" ]; then - printf "Testing for arc4random ... " - cat <<EOF >_arc4random.c -#include <stdlib.h> -int main(void) { - arc4random(); - return 0; -} -EOF - if $XCC _arc4random.c -o _arc4random 2>&3; then - ARC4RANDOM=yes - else - ARC4RANDOM=no - fi - echo "$ARC4RANDOM" - rm -f _arc4random.c _arc4random -fi -if [ "$ARC4RANDOM" = no ]; then - echo "COMPAT_SRCS+= compat/arc4random.c" >>$CONFIG_MK - echo "#include \"compat/arc4random.h\"" >>$CONFIG_H -fi - -if [ -z "$ARC4RANDOM_UNIFORM" ]; then - printf "Testing for arc4random_uniform ... " - cat <<EOF >_arc4random_uniform.c -#include <stdlib.h> -int main(void) { - arc4random_uniform(100); - return 0; -} -EOF - if $XCC _arc4random_uniform.c -o _arc4random_uniform 2>&3; then - ARC4RANDOM_UNIFORM=yes - else - ARC4RANDOM_UNIFORM=no - fi - echo "$ARC4RANDOM_UNIFORM" - rm -f _arc4random_uniform.c _arc4random_uniform -fi -if [ "$ARC4RANDOM_UNIFORM" = no ]; then - echo "COMPAT_SRCS+= compat/arc4random_uniform.c" >>$CONFIG_MK - echo "#include \"compat/arc4random_uniform.h\"" >>$CONFIG_H -fi - -if [ -z "$OPEN_MEMSTREAM" ]; then - printf "Testing for open_memstream ... " - cat <<EOF >_open_memstream.c -#include <stdio.h> -int main(void) { - return open_memstream(NULL, NULL) != NULL ? 0 : 1; -} -EOF - if $XCC _open_memstream.c -o _open_memstream 2>&3; then - OPEN_MEMSTREAM=yes - else - OPEN_MEMSTREAM=no - fi - echo "$OPEN_MEMSTREAM" - rm -f _open_memstream.c _open_memstream -fi -if [ "$OPEN_MEMSTREAM" = yes ]; then - echo "#define HAVE_OPEN_MEMSTREAM" >>$CONFIG_H -fi - -if [ -z "$PIDFILE_LOCK" ]; then - printf "Testing for pidfile_lock ... " - cat <<EOF >_pidfile.c -#include <stdlib.h> -#include <util.h> -int main(void) { - pidfile_lock(NULL); - return 0; -} -EOF - # We only want to link to libutil if it exists in /lib - if $ALLOW_USR_LIBS; then - set -- / - else - set -- $(ls /lib/libutil.so.* 2>/dev/null) - fi - if $XCC _pidfile.c -o _pidfile 2>&3; then - PIDFILE_LOCK=yes - elif [ -e "$1" ] && $XCC _pidfile.c -o _pidfile -lutil 2>&3; then - PIDFILE_LOCK="yes (-lutil)" - LIBUTIL="-lutil" - else - PIDFILE_LOCK=no - fi - echo "$PIDFILE_LOCK" - rm -f _pidfile.c _pidfile -fi -if [ "$PIDFILE_LOCK" = no ]; then - echo "COMPAT_SRCS+= compat/pidfile.c" >>$CONFIG_MK - echo "#include \"compat/pidfile.h\"" >>$CONFIG_H -else - echo "#define HAVE_UTIL_H" >>$CONFIG_H - if [ -n "$LIBUTIL" ]; then - echo "LDADD+= $LIBUTIL" >>$CONFIG_MK - fi -fi - -if [ -z "$SETPROCTITLE" ]; then - printf "Testing for setproctitle ... " - cat << EOF >_setproctitle.c -#include <stdlib.h> -int main(void) { - setproctitle("foo"); - return 0; -} -EOF - if $XCC _setproctitle.c -o _setproctitle 2>&3; then - SETPROCTITLE=yes - else - SETPROCTITLE=no - fi - echo "$SETPROCTITLE" - rm -f _setproctitle.c _setproctitle -fi -if [ "$SETPROCTITLE" = yes ]; then - echo "#define HAVE_SETPROCTITLE" >>$CONFIG_H -fi - -if [ -z "$STRLCPY" ]; then - printf "Testing for strlcpy ... " - cat <<EOF >_strlcpy.c -#include <string.h> -int main(void) { - const char s1[] = "foo"; - char s2[10]; - strlcpy(s2, s1, sizeof(s2)); - return 0; -} -EOF - if $XCC _strlcpy.c -o _strlcpy 2>&3; then - STRLCPY=yes - else - STRLCPY=no - fi - echo "$STRLCPY" - rm -f _strlcpy.c _strlcpy -fi -if [ "$STRLCPY" = no ]; then - echo "COMPAT_SRCS+= compat/strlcpy.c" >>$CONFIG_MK - echo "#include \"compat/strlcpy.h\"" >>$CONFIG_H -fi - -if [ -z "$STRTOI" ]; then - printf "Testing for strtoi ... " - cat <<EOF >_strtoi.c -#include <stdlib.h> -#include <limits.h> -#include <inttypes.h> -int main(void) { - int e; - strtoi("1234", NULL, 0, 0, INT32_MAX, &e); - return 0; -} -EOF - if $XCC _strtoi.c -o _strtoi 2>&3; then - STRTOI=yes - else - STRTOI=no - fi - echo "$STRTOI" - rm -f _strtoi.c _strtoi -fi -if [ "$STRTOI" = no ]; then - echo "COMPAT_SRCS+= compat/strtoi.c compat/strtou.c" >>$CONFIG_MK - echo "#include \"compat/strtoi.h\"" >>$CONFIG_H -fi - -if [ -z "$CONSTTIME_MEMEQUAL" ]; then - printf "Testing for consttime_memequal ... " - cat <<EOF >_consttime_memequal.c -#include <string.h> -int main(void) { - return consttime_memequal("deadbeef", "deadbeef", 8); -} -EOF - if $XCC _consttime_memequal.c -o _consttime_memequal 2>&3; then - CONSTTIME_MEMEQUAL=yes - else - CONSTTIME_MEMEQUAL=no - fi - echo "$CONSTTIME_MEMEQUAL" - rm -f _consttime_memequal.c _consttime_memequal -fi -if [ "$CONSTTIME_MEMEQUAL" = no ]; then - echo "#include \"compat/consttime_memequal.h\"" \ - >>$CONFIG_H -fi - -if [ -z "$DPRINTF" ]; then - printf "Testing for dprintf ... " - cat <<EOF >_dprintf.c -#include <stdio.h> -int main(void) { - return dprintf(0, "%d", 0); -} -EOF - if $XCC _dprintf.c -o _dprintf 2>&3; then - DPRINTF=yes - else - DPRINTF=no - fi - echo "$DPRINTF" - rm -f _dprintf.c _dprintf -fi -if [ "$DPRINTF" = no ]; then - echo "COMPAT_SRCS+= compat/dprintf.c" >>$CONFIG_MK - echo "#include \"compat/dprintf.h\"" >>$CONFIG_H -fi - -if [ -z "$TAILQ_FOREACH_SAFE" ]; then - printf "Testing for TAILQ_FOREACH_SAFE ... " - cat <<EOF >_queue.c -#include <sys/queue.h> -int main(void) { -#ifndef TAILQ_FOREACH_SAFE -#error TAILQ_FOREACH_SAFE -#endif - return 0; -} -EOF - if $XCC _queue.c -o _queue 2>&3; then - TAILQ_FOREACH_SAFE=yes - TAILQ_FOREACH=yes - else - TAILQ_FOREACH_SAFE=no - fi - echo "$TAILQ_FOREACH_SAFE" - rm -f _queue.c _queue -fi -if [ "$TAILQ_FOREACH_SAFE" = no ] && [ -z "$TAILQ_FOREACH_MUTABLE" ]; then - printf "Testing for TAILQ_FOREACH_MUTABLE ... " - cat <<EOF >_queue.c -#include <sys/queue.h> -int main(void) { -#ifndef TAILQ_FOREACH_MUTABLE -#error TAILQ_FOREACH_MUTABLE -#endif - return 0; -} -EOF - if $XCC _queue.c -o _queue 2>&3; then - TAILQ_FOREACH_MUTABLE=yes - TAILQ_FOREACH_SAFE=yes - TAILQ_FOREACH=yes - echo "#define TAILQ_FOREACH_SAFE TAILQ_FOREACH_MUTABLE" \ - >> $CONFIG_H - else - TAILQ_FOREACH_MUTABLE=no - fi - echo "$TAILQ_FOREACH_MUTABLE" - rm -f _queue.c _queue -fi - - -if [ -z "$TAILQ_CONCAT" ]; then - printf "Testing for TAILQ_CONCAT ..." - cat <<EOF >_queue.c -#include <sys/queue.h> -int main(void) { -#ifndef TAILQ_CONCAT -#error TAILQ_CONCAT -#endif - return 0; -} -EOF - if $XCC _queue.c -o _queue 2>&3; then - TAILQ_CONCAT=yes - TAILQ_FOREACH=yes - else - TAILQ_CONCAT=no - fi - echo "$TAILQ_CONCAT" - rm -f _queue.c _queue -fi - -if [ -z "$TAILQ_FOREACH" ]; then - printf "Testing for TAILQ_FOREACH ... " - cat <<EOF >_queue.c -#include <sys/queue.h> -int main(void) { -#ifndef TAILQ_FOREACH -#error TAILQ_FOREACH -#endif - return 0; -} -EOF - if $XCC _queue.c -o _queue 2>&3; then - TAILQ_FOREACH=yes - else - TAILQ_FOREACH=no - fi - echo "$TAILQ_FOREACH" - rm -f _queue.c _queue -fi - -if [ "$TAILQ_FOREACH_SAFE" = no -o "$TAILQ_CONCAT" = no ]; then - # If we don't include sys/queue.h then clang analyser finds - # too many false positives. - # See http://llvm.org/bugs/show_bug.cgi?id=18222 - # Strictly speaking this isn't needed, but I like it to help - # catch any nasties. - if [ "$TAILQ_FOREACH" = yes ]; then - echo "#include <sys/queue.h>">>$CONFIG_H - fi - echo "#include \"compat/queue.h\"">>$CONFIG_H -else - echo "#define HAVE_SYS_QUEUE_H" >>$CONFIG_H -fi - -if [ -z "$RBTREE" ]; then - printf "Testing for rb_tree_init ... " - cat <<EOF >_rbtree.c -#include <sys/rbtree.h> -static rb_tree_ops_t ops; -int main(void) { - rb_tree_t tree; - rb_tree_init(&tree, &ops); - return 0; -} -EOF - if $XCC _rbtree.c -o _rbtree 2>&3; then - RBTREE=yes - else - RBTREE=no - fi - echo "$RBTREE" - rm -f _rbtree.c _rbtree -fi -if [ "$RBTREE" = no ]; then - echo "#define RBTEST" >>$CONFIG_H - echo "COMPAT_SRCS+= compat/rb.c" >>$CONFIG_MK - echo "#include \"compat/rbtree.h\"" >>$CONFIG_H -else - echo "#define HAVE_SYS_RBTREE_H" >>$CONFIG_H -fi - -if [ -z "$REALLOCARRAY" ]; then - printf "Testing for reallocarray ... " - cat <<EOF >_reallocarray.c -#include <stdlib.h> - -int main(void) { - void *foo = reallocarray(NULL, 0, 0); - return foo == NULL ? 1 : 0; -} -EOF - if $XCC _reallocarray.c -o _reallocarray 2>&3; then - REALLOCARRAY=yes - else - REALLOCARRAY=no - fi - echo "$REALLOCARRAY" - rm -f _reallocarray.c _reallocarray -fi -if [ "$REALLOCARRAY" = no ]; then - echo "COMPAT_SRCS+= compat/reallocarray.c" >>$CONFIG_MK - echo "#include \"compat/reallocarray.h\"">>$CONFIG_H -fi -# Set this for eloop -echo "#define HAVE_REALLOCARRAY" >>$CONFIG_H - -if [ -z "$POLL" ]; then - printf "Testing for kqueue1 ... " - cat <<EOF >_kqueue.c -#include <sys/types.h> -#include <sys/event.h> -int main(void) { - return kqueue1(0); -} -EOF - if $XCC _kqueue.c -o _kqueue 2>&3; then - POLL=kqueue1 - echo "yes" - else - echo "no" - fi - rm -f _kqueue.c _kqueue -fi -if [ -z "$POLL" ]; then - printf "Testing for kqueue ... " - cat <<EOF >_kqueue.c -#include <sys/types.h> -#include <sys/event.h> -int main(void) { - return kqueue(); -} -EOF - if $XCC _kqueue.c -o _kqueue 2>&3; then - POLL=kqueue - echo "yes" - else - echo "no" - fi - rm -f _kqueue.c _kqueue -fi -if [ -z "$POLL" ]; then - printf "Testing for epoll ... " - cat <<EOF >_epoll.c -#ifdef __linux__ -#include <linux/version.h> -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 37) -#error kernel has buggy epoll_wait timeout -#endif -#endif - -#include <sys/epoll.h> -#include <unistd.h> -int main(void) { - epoll_create1(EPOLL_CLOEXEC); - epoll_pwait(-1, NULL, 0, 0, NULL); - return 0; -} -EOF - if $XCC _epoll.c -o _epoll 2>&3; then - POLL=epoll - echo "#define HAVE_EPOLL" >>$CONFIG_MK - echo "yes" - else - echo "no" - fi - rm -f _epoll.c _epoll -fi -if [ -z "$POLL" ]; then - printf "Testing for pselect ... " - cat <<EOF >_pselect.c -#include <sys/select.h> -#include <stdlib.h> -int main(void) { - pselect(0, NULL, NULL, NULL, NULL, NULL); - return 0; -} -EOF - if $XCC _pselect.c -o _pselect 2>&3; then - POLL=pselect - echo "yes" - else - echo "no" - fi - rm -f _pselect.c _pselect -fi -case "$POLL" in -kqueue1) - echo "#define HAVE_KQUEUE" >>$CONFIG_H - echo "#define HAVE_KQUEUE1" >>$CONFIG_H - ;; -kqueue) - echo "#define HAVE_KQUEUE" >>$CONFIG_H - ;; -epoll) - echo "#define HAVE_EPOLL" >>$CONFIG_H - ;; -pollts) - echo "#define HAVE_POLLTS" >>$CONFIG_H - ;; -ppoll) - echo "#define HAVE_PPOLL" >>$CONFIG_H - ;; -pselect) - echo "#define HAVE_PSELECT" >>$CONFIG_H - ;; -*) - echo "No suitable polling function is available, not even pselect" >&2 - exit 1 - ;; -esac - -if [ -z "$BE64ENC" ]; then - printf "Testing for be64enc ... " - cat <<EOF >_be64enc.c -#include <sys/endian.h> -#include <stdlib.h> -int main(void) { - be64enc(NULL, 0); - return 0; -} -EOF - if $XCC _be64enc.c -o _be64enc 2>&3; then - BE64ENC=yes - else - BE64ENC=no - fi - echo "$BE64ENC" - rm -f _be64enc.c _be64enc -fi -if [ "$BE64ENC" = no ]; then - echo "#include \"compat/endian.h\"" >>$CONFIG_H -fi - -if [ -z "$FLS64" ]; then - printf "Testing for fls64 ... " - cat <<EOF >_fls64.c -#include <sys/bitops.h> -int main(void) { - return (int)fls64(1337); -} -EOF - if $XCC _fls64.c -o _fls64 2>&3; then - FLS64=yes - else - FLS64=no - fi - echo "$FLS64" - rm -f _fls64.c _fls64 -fi -if [ "$FLS64" = yes ]; then - echo "#define HAVE_SYS_BITOPS_H" >>$CONFIG_H -fi - -# Workaround for DragonFlyBSD import -if [ "$OS" = dragonfly ]; then - echo "#ifdef USE_PRIVATECRYPTO" >>$CONFIG_H - echo "#define HAVE_MD5_H" >>$CONFIG_H - echo "#define SHA2_H <sha256.h>" >>$CONFIG_H - echo "#else" >>$CONFIG_H -fi - -if [ -z "$MD5" ]; then - MD5_LIB= - printf "Testing for MD5Init ... " - cat <<EOF >_md5.c -#include <sys/types.h> -#include <md5.h> -#include <stdlib.h> -int main(void) { - MD5_CTX context; - MD5Init(&context); - return 0; -} -EOF - # We only want to link to libmd if it exists in /lib - if $ALLOW_USR_LIBS; then - set -- / - else - set -- $(ls /lib/libmd.so.* 2>/dev/null) - fi - if $XCC _md5.c -o _md5 2>&3; then - MD5=yes - elif [ -e "$1" ] && $XCC _md5.c -lmd -o _md5 2>&3; then - MD5="yes (-lmd)" - MD5_LIB=-lmd - else - MD5=no - fi - echo "$MD5" - rm -f _md5.c _md5 -fi -if [ "$MD5" = no ]; then - echo "#include \"compat/crypt/md5.h\"" >>$CONFIG_H - echo "MD5_SRC= compat/crypt/md5.c" >>$CONFIG_MK -else - echo "MD5_SRC=" >>$CONFIG_MK - echo "#define HAVE_MD5_H" >>$CONFIG_H - [ -n "$MD5_LIB" ] && echo "LDADD+= $MD5_LIB" >>$CONFIG_MK -fi - -if [ -z "$SHA2_H" -a -z "$SHA2" -o "$SHA2" != no ]; then - printf "Testing for sha2.h ... " - if [ -e /usr/include/sha2.h ]; then - SHA2_H=sha2.h - elif [ -e /usr/include/sha256.h ]; then - SHA2_H=sha256.h - fi - if [ -n "$SHA2_H" ]; then - echo "$SHA2_H" - else - echo "no" - fi -fi - -if [ -z "$SHA2" ]; then - SHA2_LIB= - SHA2_RENAMED= - printf "Testing for SHA256_Init ... " - cat <<EOF >_sha256.c -#include <sys/types.h> -EOF - [ -n "$SHA2_H" ] && echo "#include <$SHA2_H>">>_sha256.c - cat <<EOF >>_sha256.c -#include <stdlib.h> -int main(void) { - SHA256_CTX context; - SHA256_Init(&context); - return 0; -} -EOF - # We only want to link to libmd if it exists in /lib - if $ALLOW_USR_LIBS; then - set -- / - else - set -- $(ls /lib/libmd.so.* 2>/dev/null) - fi - if $XCC _sha256.c -o _sha256 2>&3; then - SHA2=yes - elif [ -e "$1" ] && $XCC _sha256.c -lmd -o _sha256 2>&3; then - SHA2="yes (-lmd)" - SHA2_LIB=-lmd - else - SHA2=no - fi - echo "$SHA2" - rm -f _sha256.c _sha256 - if [ "$SHA2" = no ]; then - # Did OpenBSD really change this? grrrr - printf "Testing for SHA256Init ... " - cat <<EOF >_sha256.c -#include <sys/types.h> -EOF - [ -n "$SHA2_H" ] && echo "#include <$SHA2_H>">>_sha256.c - cat <<EOF >>_sha256.c -#include <stdlib.h> -int main(void) { - SHA2_CTX context; - SHA256Init(&context); - return 0; -} -EOF - # We only want to link to libmd if it exists in /lib - if $ALLOW_USR_LIBS; then - set -- / - else - set -- $(ls /lib/libmd.so.* 2>/dev/null) - fi - if $XCC _sha256.c -o _sha256 2>&3; then - SHA2=yes - SHA2_RENAMED=yes - elif [ -e "$1" ] && $XCC _sha256.c -lmd -o _sha256 2>&3 - then - SHA2="yes (-lmd)" - SHA2_LIB=-lmd - SHA2_RENAMED=yes - else - SHA2=no - fi - echo "$SHA2" - rm -f _sha256.c _sha256 - fi -fi -if [ "$SHA2" = no ]; then - echo "#include \"compat/crypt/sha256.h\"" >>$CONFIG_H - echo "SHA256_SRC= compat/crypt/sha256.c" >>$CONFIG_MK -else - echo "SHA256_SRC=" >>$CONFIG_MK - echo "#define SHA2_H <$SHA2_H>" >>$CONFIG_H - if [ "$SHA2_RENAMED" = yes ]; then - echo "#define SHA256_CTX SHA2_CTX" >>$CONFIG_H - echo "#define SHA256_Init SHA256Init" >>$CONFIG_H - echo "#define SHA256_Update SHA256Update" >>$CONFIG_H - echo "#define SHA256_Final SHA256Final" >>$CONFIG_H - fi - [ -n "$SHA2_LIB" ] && echo "LDADD+= $SHA2_LIB" >>$CONFIG_MK -fi - -# Workarond for DragonFlyBSD import -[ "$OS" = dragonfly ] && echo "#endif" >>$CONFIG_H - -if [ -z "$HMAC" ]; then - HMAC_LIB= - printf "Testing for hmac ... " - cat <<EOF >_hmac.c -#include <stdlib.h> -#include <hmac.h> -int main(void) { - hmac(NULL, NULL, 0, NULL, 0, NULL, 0); - return 0; -} -EOF - if $XCC _hmac.c $MD5_LIB -o _hmac 2>&3; then - HMAC=yes - echo "#define HAVE_HMAC_H" >>$CONFIG_H - else - # Remove this test if NetBSD-8 ships with - # hmac in it's own header and not stdlib.h - cat <<EOF >_hmac.c -#include <stdlib.h> -int main(void) { - hmac(NULL, NULL, 0, NULL, 0, NULL, 0); - return 0; -} -EOF - if $XCC _hmac.c $MD5_LIB -o _hmac 2>&3; then - HMAC=yes - else - HMAC=no - fi - fi - echo "$HMAC" - rm -f _hmac.c _hmac -fi -if [ "$HMAC" = no ]; then - echo "#include \"compat/crypt/hmac.h\"" >>$CONFIG_H - echo "HMAC_SRC= compat/crypt/hmac.c" >>$CONFIG_MK -else - # echo "#define HAVE_HMAC_H" >>$CONFIG_H - echo "HMAC_SRC=" >>$CONFIG_MK -fi - -if [ -z "$AUTH" ] || [ "$AUTH" = yes ]; then - if [ "$HMAC" = no ]; then - echo "CRYPT_SRCS+= \${HMAC_SRC}" >>$CONFIG_MK - fi -fi -if [ -z "$INET6" ] || [ "$INET6" = yes ] || \ - [ -z "$AUTH" ] || [ "$AUTH" = yes ]; then - if [ "$MD5" = no ]; then - echo "CRYPT_SRCS+= \${MD5_SRC}" >>$CONFIG_MK - fi - if [ "$SHA2" = no ]; then - echo "CRYPT_SRCS+= \${SHA256_SRC}" >>$CONFIG_MK - fi -fi - -if [ "$DEV" != no -a "$UDEV" != no ]; then - printf "Checking for libudev ... " - if type "$PKG_CONFIG" >/dev/null 2>&1; then - LIBUDEV_CFLAGS=$("$PKG_CONFIG" --cflags libudev 2>&3) - LIBUDEV_LIBS=$("$PKG_CONFIG" --libs libudev 2>&3) - fi -fi -if [ "$DEV" != no -a "$UDEV" != no -a -n "$LIBUDEV_LIBS" ]; then - echo "yes" - [ -z "$DEV" ] && DEV=yes - echo "DEV_PLUGINS+= udev" >>$CONFIG_MK - if [ -n "$LIBUDEV_CFLAGS" ]; then - echo "LIBUDEV_CFLAGS= $LIBUDEV_CFLAGS" >>$CONFIG_MK - fi - echo "LIBUDEV_LIBS= $LIBUDEV_LIBS" >>$CONFIG_MK - - printf "Checking udev_monitor_filter_add_match_subsystem_devtype ... " - cat <<EOF >_udev.c -#include <libudev.h> -#include <stdlib.h> -int main(void) { - udev_monitor_filter_add_match_subsystem_devtype(NULL, NULL, NULL); - return 0; -} -EOF - if $XCC $LIBUDEV_CFLAGS _udev.c -o _udev $LIBUDEV_LIBS 2>&3 - then - echo "yes" - else - echo "LIBUDEV_CPPFLAGS+= -DLIBUDEV_NOFILTER" >>$CONFIG_MK - echo "no" - fi - rm -f _udev.c _udev - - printf "Checking udev_device_get_is_initialized ... " - cat <<EOF >_udev.c -#include <libudev.h> -#include <stdlib.h> -int main(void) { - udev_device_get_is_initialized(NULL); - return 0; -} -EOF - if $XCC $LIBUDEV_CFLAGS _udev.c -o _udev $LIBUDEV_LIBS 2>&3 - then - echo "yes" - else - echo "LIBUDEV_CPPFLAGS+= -DLIBUDEV_NOINIT" >>$CONFIG_MK - echo "no" - fi - rm -f _udev.c _udev -elif [ "$DEV" != no -a "$UDEV" != no ]; then - echo "no" - if [ -n "$UDEV" ]; then - echo "udev has been explicitly requested ... aborting" >&2 - exit 1 - fi -fi - -if [ "$DEV" = yes ]; then - echo "DHCPCD_SRCS+= dev.c" >>$CONFIG_MK - echo "CPPFLAGS+= -DPLUGIN_DEV" >>$CONFIG_MK - echo "MKDIRS+= dev" >>$CONFIG_MK - - # So the plugins have access to logerr - echo "LDFLAGS+= -Wl,-export-dynamic" >>$CONFIG_MK - - printf "Testing for dlopen ... " - cat <<EOF >_dlopen.c -#include <dlfcn.h> -#include <stdlib.h> -int main(void) { - dlopen(NULL, 0); - return 0; -} -EOF - if $XCC _dlopen.c -o _dlopen 2>&3; then - echo "yes" - elif $XCC _dlopen.c -ldl -o _dlopen 2>&3; then - echo "yes (-ldl)" - echo "LDADD+= -ldl" >>$CONFIG_MK - else - echo "no" - echo "libc for dlopen is required - aborting" - fi - rm -f _dlopen.c _dlopen - $abort && exit 1 -fi - -# Transform for a make file -SERVICEEXISTS=$(echo "$SERVICEEXISTS" | $SED \ - -e 's:\\:\\\\:g' \ - -e 's:\&:\\\&:g' \ - -e 's:\$:\\\\\$\$:g' \ -) -echo "SERVICEEXISTS= $SERVICEEXISTS" >>config.mk -SERVICECMD=$(echo "$SERVICECMD" | $SED \ - -e 's:\\:\\\\:g' \ - -e 's:\&:\\\&:g' \ - -e 's:\$:\\\\\$\$:g' \ -) -echo "SERVICECMD= $SERVICECMD" >>config.mk -SERVICESTATUS=$(echo "$SERVICESTATUS" | $SED \ - -e 's:\\:\\\\:g' \ - -e 's:\&:\\\&:g' \ - -e 's:\$:\\\\\$\$:g' \ -) -echo "SERVICESTATUS= $SERVICESTATUS" >>config.mk -if [ -z "$STATUSARG" ]; then - case "$OS" in - freebsd*) STATUSARG="onestatus";; - esac -fi -echo "STATUSARG= $STATUSARG" >>config.mk - -HOOKS= -if ! $HOOKSET; then - printf "Checking for ntpd ... " - NTPD=$(_which ntpd) - if [ -n "$NTPD" ]; then - echo "$NTPD (50-ntp.conf)" - else - echo "not found" - fi - printf "Checking for chronyd ... " - CHRONYD=$(_which chronyd) - if [ -n "$CHRONYD" ]; then - echo "$CHRONYD (50-ntp.conf)" - else - echo "not found" - fi - if [ -n "$NTPD" -o -n "$CHRONYD" ]; then - HOOKS="$HOOKS${HOOKS:+ }50-ntp.conf" - fi - # Warn if both are detected - if [ -n "$NTPD" -a -n "$CHRONYD" ]; then - echo "NTP will default to $NTPD" - fi - - printf "Checking for ypbind ... " - YPBIND=$(_which ypbind) - if [ -n "$YPBIND" ]; then - YPHOOK="50-ypbind" - if strings "$YPBIND" | $GREP -q yp\\.conf; then - YPHOOK="50-yp.conf" - YPOS="Linux" - elif strings "$YPBIND" | $GREP -q \\.ypservers; then - YPOS="NetBSD" - echo "YPDOMAIN_DIR= /var/yp" >>$CONFIG_MK - echo "YPDOMAIN_SUFFIX=.ypservers" >>$CONFIG_MK - elif strings "$YPBIND" | $GREP -q /etc/yp; then - YPOS="OpenBSD" - echo "YPDOMAIN_DIR= /etc/yp" >>$CONFIG_MK - echo "YPDOMAIN_SUFFIX=" >>$CONFIG_MK - else - YPOS="FreeBSD" - echo "YPDOMAIN_DIR=" >>$CONFIG_MK - echo "YPDOMAIN_SUFFIX=" >>$CONFIG_MK - fi - echo "$YPBIND ($YPHOOK${YPOS:+ }$YPOS)" - EGHOOKS="$EGHOOKS${EGHOOKS:+ }$YPHOOK" - else - echo "not found" - fi -fi - -if cd hooks; then - for x in $HOOKSCRIPTS; do - printf "Finding hook $x ... " - for h in [0-9][0-9]"-$x" \ - [0-9][0-9]"-$x.sh" \ - [0-9][0-9]"-$x.conf" - do - [ -e "$h" ] && break - done - if [ ! -e "$h" ]; then - echo "no" - else - echo "$h" - case " $HOOKS " in - *" $h "*) ;; - *) HOOKS="$HOOKS${HOOKS:+ }$h";; - esac - fi - done - for x in $EGHOOKSCRIPTS; do - printf "Finding example hook $x ... " - for h in [0-9][0-9]"-$x" \ - [0-9][0-9]"-$x.sh" \ - [0-9][0-9]"-$x.conf" - do - [ -e "$h" ] && break - done - if [ ! -e "$h" ]; then - echo "no" - else - echo "$h" - case " $EGHOOKS " in - *" $h "*) ;; - *) EGHOOKS="$EGHOOKS${EGHOOKS:+ }$h";; - esac - fi - done - cd .. -fi -echo "HOOKSCRIPTS= $HOOKS" >>$CONFIG_MK -echo "EGHOOKSCRIPTS= $EGHOOKS" >>$CONFIG_MK - -echo -echo " SYSCONFDIR = $SYSCONFDIR" -echo " SBINDIR = $SBINDIR" -echo " LIBDIR = $LIBDIR" -echo " LIBEXECDIR = $LIBEXECDIR" -echo " DBDIR = $DBDIR" -echo " RUNDIR = $RUNDIR" -echo " MANDIR = $MANDIR" -echo " DATADIR = $DATADIR" -echo " HOOKSCRIPTS = $HOOKS" -echo " EGHOOKSCRIPTS = $EGHOOKS" -echo " STATUSARG = $STATUSARG" -echo - -rm -f dhcpcd tests/test diff --git a/external/bsd/dhcpcd/dist/hooks/50-dhcpcd-compat b/external/bsd/dhcpcd/dist/hooks/50-dhcpcd-compat deleted file mode 100644 index 0d6256e6ae6..00000000000 --- a/external/bsd/dhcpcd/dist/hooks/50-dhcpcd-compat +++ /dev/null @@ -1,41 +0,0 @@ -# Compat enter hook shim for older dhcpcd versions - -IPADDR=$new_ip_address -INTERFACE=$interface -NETMASK=$new_subnet_mask -BROADCAST=$new_broadcast_address -NETWORK=$new_network_number -DHCPSID=$new_dhcp_server_identifier -GATEWAYS=$new_routers -DNSSERVERS=$new_domain_name_servers -DNSDOMAIN=$new_domain_name -DNSSEARCH=$new_domain_search -NISDOMAIN=$new_nis_domain -NISSERVERS=$new_nis_servers -NTPSERVERS=$new_ntp_servers - -GATEWAY= -for x in $new_routers; do - GATEWAY="$GATEWAY${GATEWAY:+,}$x" -done -DNS= -for x in $new_domain_name_servers; do - DNS="$DNS${DNS:+,}$x" -done - -r="down" -case "$reason" in -RENEW) r="up";; -BOUND|INFORM|REBIND|REBOOT|TEST|TIMEOUT|IPV4LL) r="new";; -esac - -if [ "$r" != "down" ]; then - rm -f /var/lib/dhcpcd-"$INTERFACE".info - for x in IPADDR INTERFACE NETMASK BROADCAST NETWORK DHCPSID GATEWAYS \ - DNSSERVERS DNSDOMAIN DNSSEARCH NISDOMAIN NISSERVERS \ - NTPSERVERS GATEWAY DNS; do - eval echo "$x=\'\$$x\'" >> /var/lib/dhcpcd-"$INTERFACE".info - done -fi - -set -- /var/lib/dhcpcd-"$INTERFACE".info "$r" diff --git a/external/bsd/dhcpcd/dist/hooks/50-yp.conf b/external/bsd/dhcpcd/dist/hooks/50-yp.conf deleted file mode 100644 index abe6a4334ee..00000000000 --- a/external/bsd/dhcpcd/dist/hooks/50-yp.conf +++ /dev/null @@ -1,57 +0,0 @@ -# Sample dhcpcd hook for ypbind -# This script is only suitable for the Linux version. - -ypbind_pid() -{ - [ -s /var/run/ypbind.pid ] && cat /var/run/ypbind.pid -} - -make_yp_conf() -{ - [ -z "${new_nis_domain}${new_nis_servers}" ] && return 0 - cf=/etc/yp.conf."$ifname" - rm -f "$cf" - echo "$signature" > "$cf" - prefix= - if [ -n "$new_nis_domain" ]; then - if ! valid_domainname "$new_nis_domain"; then - syslog err "Invalid NIS domain name: $new_nis_domain" - rm -f "$cf" - return 1 - fi - domainname "$new_nis_domain" - if [ -n "$new_nis_servers" ]; then - prefix="domain $new_nis_domain server " - else - echo "domain $new_nis_domain broadcast" >> "$cf" - fi - else - prefix="ypserver " - fi - for x in $new_nis_servers; do - echo "$prefix$x" >> "$cf" - done - save_conf /etc/yp.conf - cat "$cf" > /etc/yp.conf - rm -f "$cf" - pid="$(ypbind_pid)" - if [ -n "$pid" ]; then - kill -HUP "$pid" - fi -} - -restore_yp_conf() -{ - [ -n "$old_nis_domain" ] && domainname "" - restore_conf /etc/yp.conf || return 0 - pid="$(ypbind_pid)" - if [ -n "$pid" ]; then - kill -HUP "$pid" - fi -} - -if $if_up; then - make_yp_conf -elif $if_down; then - restore_yp_conf -fi diff --git a/external/bsd/dhcpcd/dist/hooks/Makefile b/external/bsd/dhcpcd/dist/hooks/Makefile deleted file mode 100644 index e8fb70a8b47..00000000000 --- a/external/bsd/dhcpcd/dist/hooks/Makefile +++ /dev/null @@ -1,71 +0,0 @@ -TOP?= ../ -include ${TOP}/iconfig.mk - -PROG= dhcpcd-run-hooks -BINDIR= ${LIBEXECDIR} -CLEANFILES= dhcpcd-run-hooks -MAN8= dhcpcd-run-hooks.8 -CLEANFILES+= dhcpcd-run-hooks.8 - -SCRIPTSDIR= ${HOOKDIR} -SCRIPTS= 01-test 02-dump -SCRIPTS+= 20-resolv.conf -SCRIPTS+= 30-hostname -SCRIPTS+= ${HOOKSCRIPTS} - -# Some hooks should not be installed by default -FILESDIR= ${DATADIR}/dhcpcd/hooks -FILES= 10-wpa_supplicant -FILES+= 15-timezone -FILES+= 29-lookup-hostname -FILES+= ${EGHOOKSCRIPTS} - -.SUFFIXES: .in - -.in: Makefile ${TOP}/config.mk - ${SED} ${SED_RUNDIR} ${SED_DBDIR} ${SED_LIBDIR} ${SED_HOOKDIR} \ - ${SED_SYS} ${SED_SCRIPT} ${SED_DATADIR} \ - ${SED_SERVICEEXISTS} ${SED_SERVICECMD} ${SED_SERVICESTATUS} \ - ${SED_STATUSARG} \ - -e 's:@YPDOMAIN_DIR@:${YPDOMAIN_DIR}:g' \ - -e 's:@YPDOMAIN_SUFFIX@:${YPDOMAIN_SUFFIX}:g' \ - $< > $@ - -all: ${PROG} ${MAN8} ${SCRIPTS} ${EGHOOKSCRIPTS} - -clean: - rm -f ${CLEANFILES} 50-ypbind - -depend: - -proginstall: ${PROG} ${HOOKSCRIPTS} - ${INSTALL} -d ${DESTDIR}${BINDIR} - ${INSTALL} -m ${BINMODE} ${PROG} ${DESTDIR}${BINDIR} - ${INSTALL} -d ${DESTDIR}${SCRIPTSDIR} - ${INSTALL} -m ${NONBINMODE} ${SCRIPTS} ${DESTDIR}${SCRIPTSDIR} - # We need to remove the old MTU change script if we at all can. - rm -f ${DESTDIR}${SCRIPTSDIR}/10-mtu - -eginstall: ${EGHOOKSCRIPTS} - ${INSTALL} -d ${DESTDIR}${FILESDIR} - ${INSTALL} -m ${NONBINMODE} ${FILES} ${DESTDIR}${FILESDIR} - -maninstall: ${MAN8} - ${INSTALL} -d ${DESTDIR}${MANDIR}/man8 - ${INSTALL} -m ${MANMODE} ${MAN8} ${DESTDIR}${MANDIR}/man8 - -install: proginstall eginstall maninstall - -import: ${HOOKSCRIPTS} - ${INSTALL} -d /tmp/${DISTPREFIX}/dhcpcd-hooks - ${INSTALL} -m ${NONBINMODE} ${SCRIPTS} /tmp/${DISTPREFIX}/dhcpcd-hooks - ${INSTALL} -m ${NONBINMODE} ${FILES} /tmp/${DISTPREFIX}/dhcpcd-hooks - -_import-src: - ${INSTALL} -d ${DESTDIR}/hooks - cp dhcpcd-run-hooks.in dhcpcd-run-hooks.8.in [0-9]* ${DESTDIR}/hooks - rm ${DESTDIR}/hooks/50-dhcpcd-compat - if [ `uname` = Linux ]; then rm ${DESTDIR}/hooks/50-ypbind.in; \ - else rm ${DESTDIR}/hooks/50-yp.conf; fi - -include ${TOP}/Makefile.inc diff --git a/external/bsd/dhcpcd/dist/iconfig.mk b/external/bsd/dhcpcd/dist/iconfig.mk deleted file mode 100644 index 50c50340c17..00000000000 --- a/external/bsd/dhcpcd/dist/iconfig.mk +++ /dev/null @@ -1,8 +0,0 @@ -# Nasty hack so that make clean works without configure being run -TOP?= . -_CONFIG_MK!= test -e ${TOP}/config.mk && \ - echo config.mk || echo config-null.mk -_CONFIG_MK?= $(shell test -e ${TOP}/config.mk && \ - echo config.mk || echo config-null.mk) -CONFIG_MK?= ${_CONFIG_MK} -include ${TOP}/${CONFIG_MK} diff --git a/external/bsd/dhcpcd/dist/src/GNUmakefile b/external/bsd/dhcpcd/dist/src/GNUmakefile deleted file mode 100644 index f66ad94c6e0..00000000000 --- a/external/bsd/dhcpcd/dist/src/GNUmakefile +++ /dev/null @@ -1,12 +0,0 @@ -# GNU Make does not automagically include .depend -# Luckily it does read GNUmakefile over Makefile so we can work around it - -# Nasty hack so that make clean works without configure being run -TOP?= .. -CONFIG_MK?= $(shell test -e ${TOP}/config.mk && \ - echo config.mk || echo config-null.mk) - -include Makefile -ifneq ($(wildcard .depend), ) -include .depend -endif diff --git a/external/bsd/dhcpcd/dist/src/Makefile b/external/bsd/dhcpcd/dist/src/Makefile deleted file mode 100644 index ef16def535f..00000000000 --- a/external/bsd/dhcpcd/dist/src/Makefile +++ /dev/null @@ -1,172 +0,0 @@ -# dhcpcd Makefile - -PROG= dhcpcd -SRCS= common.c control.c dhcpcd.c duid.c eloop.c logerr.c -SRCS+= if.c if-options.c sa.c route.c -SRCS+= dhcp-common.c script.c - -CFLAGS?= -O2 -SUBDIRS+= ${MKDIRS} - -TOP?= .. -include ${TOP}/iconfig.mk - -CSTD?= c99 -CFLAGS+= -std=${CSTD} -CPPFLAGS+= -I${TOP} -I${TOP}/src -I./crypt - -SRCS+= ${DHCPCD_SRCS} -DHCPCD_DEFS?= dhcpcd-definitions.conf - -PCOMPAT_SRCS= ${COMPAT_SRCS:compat/%=${TOP}/compat/%} -PCRYPT_SRCS= ${CRYPT_SRCS:compat/%=${TOP}/compat/%} -OBJS+= ${SRCS:.c=.o} ${PCRYPT_SRCS:.c=.o} ${PCOMPAT_SRCS:.c=.o} - -MAN5= dhcpcd.conf.5 -MAN8= dhcpcd.8 -CLEANFILES= dhcpcd.conf.5 dhcpcd.8 - -FILES= dhcpcd.conf -FILESDIR= ${SYSCONFDIR} - -DEPEND!= test -e .depend && echo ".depend" || echo "" - -CLEANFILES+= *.tar.xz - -.PHONY: import import-bsd dev test - -.SUFFIXES: .in - -.in: Makefile ${TOP}/config.mk - ${SED} ${SED_RUNDIR} ${SED_DBDIR} ${SED_LIBDIR} ${SED_HOOKDIR} \ - ${SED_SYS} ${SED_SCRIPT} ${SED_DATADIR} \ - ${SED_SERVICEEXISTS} ${SED_SERVICECMD} ${SED_SERVICESTATUS} \ - ${SED_STATUSARG} \ - $< > $@ - -all: ${TOP}/config.h ${PROG} ${SCRIPTS} ${MAN5} ${MAN8} - for x in ${SUBDIRS}; do cd $$x; ${MAKE} $@ || exit $$?; cd ..; done - -dev: - cd dev && ${MAKE} - -.c.o: Makefile ${TOP}/config.mk - ${CC} ${CFLAGS} ${CPPFLAGS} -c $< -o $@ - -CLEANFILES+= dhcpcd-embedded.h dhcpcd-embedded.c - -dhcpcd-embedded.h: genembedh ${DHCPCD_DEFS} dhcpcd-embedded.h.in - ${HOST_SH} ${.ALLSRC} $^ > $@ - -dhcpcd-embedded.c: genembedc ${DHCPCD_DEFS} dhcpcd-embedded.c.in - ${HOST_SH} ${.ALLSRC} $^ > $@ - -if-options.c: dhcpcd-embedded.h - -.depend: ${SRCS} ${COMPAT_SRCS} ${CRYPT_SRCS} - ${CC} ${CPPFLAGS} -MM ${SRCS} ${COMPAT_SRCS} ${CRYPT_SRCS} > .depend - -depend: .depend - -${PROG}: ${DEPEND} ${OBJS} - ${CC} ${LDFLAGS} -o $@ ${OBJS} ${LDADD} - -lint: - ${LINT} -Suz ${CPPFLAGS} ${SRCS} ${PCRYPT_SRCS} ${PCOMPAT_SRCS} - -_embeddedinstall: ${DHCPCD_DEFS} - ${INSTALL} -d ${DESTDIR}${LIBEXECDIR} - ${INSTALL} -m ${CONFMODE} ${DHCPCD_DEFS} ${DESTDIR}${LIBEXECDIR} - -_proginstall: ${PROG} - ${INSTALL} -d ${DESTDIR}${SBINDIR} - ${INSTALL} -m ${BINMODE} ${PROG} ${DESTDIR}${SBINDIR} - ${INSTALL} -d ${DESTDIR}${DBDIR} - -proginstall: _proginstall ${EMBEDDEDINSTALL} - for x in ${SUBDIRS}; do cd $$x; ${MAKE} $@ || exit $$?; cd ..; done - -_maninstall: ${MAN5} ${MAN8} - ${INSTALL} -d ${DESTDIR}${MANDIR}/man5 - ${INSTALL} -m ${MANMODE} ${MAN5} ${DESTDIR}${MANDIR}/man5 - ${INSTALL} -d ${DESTDIR}${MANDIR}/man8 - ${INSTALL} -m ${MANMODE} ${MAN8} ${DESTDIR}${MANDIR}/man8 - -_confinstall: - ${INSTALL} -d ${DESTDIR}${SYSCONFDIR} - # Install a new default config if not present - test -e ${DESTDIR}${SYSCONFDIR}/dhcpcd.conf || \ - ${INSTALL} -m ${CONFMODE} dhcpcd.conf ${DESTDIR}${SYSCONFDIR} - # Attempt to move files from sysconfig to dbdir - if [ ! -e ${DESTDIR}${DBDIR}/duid -a \ - -e ${DESTDIR}${SYSCONFDIR}/dhcpcd.duid ]; \ - then \ - mv ${DESTDIR}${SYSCONFDIR}/dhcpcd.duid \ - ${DESTDIR}${DBDIR}/duid; \ - fi - if [ ! -e ${DESTDIR}${DBDIR}/secret -a \ - -e ${DESTDIR}${SYSCONFDIR}/dhcpcd.secret ]; \ - then \ - mv ${DESTDIR}${SYSCONFDIR}/dhcpcd.secret \ - ${DESTDIR}${DBDIR}/secret; \ - fi - # Move leases to new location - for lease in ${DESTDIR}${DBDIR}/../dhcpcd-*.lease*; do \ - [ -f "$$lease" ] || continue; \ - newlease=$$(basename "$$lease" | ${SED} -e "s/dhcpcd-//"); \ - mv "$$lease" ${DESTDIR}${DBDIR}/"$$newlease"; \ - done - # Move RDM monotonic to new location - if [ ! -e ${DESTDIR}${DBDIR}/rdm_monotonic -a \ - -e ${DESTDIR}${DBDIR}/../dhcpcd-rdm.monotonic ]; \ - then \ - mv ${DESTDIR}${DBDIR}/../dhcpcd-rdm.monotonic \ - ${DESTDIR}${DBDIR}/rdm_monotonic; \ - fi - -eginstall: - -install: proginstall _maninstall _confinstall eginstall - -clean: - rm -f ${OBJS} ${PROG} ${PROG}.core ${CLEANFILES} - for x in ${SUBDIRS}; do cd $$x; ${MAKE} $@ || exit $$?; cd ..; done - -distclean: clean - rm -f .depend - -_import-src: ${SRCS} - ${INSTALL} -d ${DESTDIR}/src - touch if-bsd.h if-linux.h if-sun.h - cp defs.h ${SRCS} ${SRCS:.c=.h} dev.h ${MAN5}.in ${MAN8}.in ${DESTDIR}/src - rm if-bsd.h if-linux.h if-sun.h - rm -f ${DESTDIR}/src/if-bsd.h ${DESTDIR}/src/if-linux.h ${DESTDIR}/src/if-sun.h - if [ -n "${COMPAT_SRCS}" ]; then \ - ${INSTALL} -d ${DESTDIR}/compat; \ - cd ..; \ - touch compat/rb.h compat/strtou.h; \ - cp ${COMPAT_SRCS} ${COMPAT_SRCS:.c=.h} ${DESTDIR}/compat; \ - rm compat/rb.h compat/strtou.h; \ - rm -f ${DESTDIR}/compat/rb.h ${DESTDIR}/compat/strtou.h; \ - fi - if ! grep HAVE_SYS_BITOPS_H ../config.h; then \ - cp ../compat/bitops.h ${DESTDIR}/compat; \ - fi - if grep compat/consttime_memequal.h ../config.h; then \ - cp ../compat/consttime_memequal.h ${DESTDIR}/compat; \ - fi - if [ -e ${DESTDIR}/compat/rb.c ]; then \ - cp ../compat/rbtree.h ${DESTDIR}/compat; \ - fi - if [ -e ${DESTDIR}/compat/strtoi.c ]; then \ - cp ../compat/_strtoi.h ${DESTDIR}/compat; \ - fi - if [ -n "${CRYPT_SRCS}" ]; then \ - ${INSTALL} -d ${DESTDIR}/compat/crypt; \ - cd ..; \ - cp ${CRYPT_SRCS} ${CRYPT_SRCS:.c=.h} ${DESTDIR}/compat/crypt; \ - fi - # DragonFlyBSD builds base version with private crypto - if [ `uname` = DragonFly ]; then rm ${DESTDIR}/compat/crypt/md5* ${DESTDIR}/compat/crypt/sha256*; fi - -include ${TOP}/Makefile.inc diff --git a/external/bsd/dhcpcd/dist/src/arp.c b/external/bsd/dhcpcd/dist/src/arp.c index 49393f5a528..ba3755e6923 100644 --- a/external/bsd/dhcpcd/dist/src/arp.c +++ b/external/bsd/dhcpcd/dist/src/arp.c @@ -129,12 +129,11 @@ arp_report_conflicted(const struct arp_state *astate, inet_ntoa(astate->addr)); } - static void arp_found(struct arp_state *astate, const struct arp_msg *amsg) { struct interface *ifp; - struct ivp4_addr *ia; + struct ipv4_addr *ia; #ifndef KERNEL_RFC5227 struct timespec now, defend; #endif @@ -142,11 +141,8 @@ arp_found(struct arp_state *astate, const struct arp_msg *amsg) arp_report_conflicted(astate, amsg); ifp = astate->iface; -#pragma GCC diagnostic push /* GCC is clearly wrong about this warning. */ -#pragma GCC diagnostic ignored "-Wincompatible-pointer-types" /* If we haven't added the address we're doing a probe. */ ia = ipv4_iffindaddr(ifp, &astate->addr, NULL); -#pragma GCC diagnostic pop if (ia == NULL) { if (astate->found_cb != NULL) astate->found_cb(astate, amsg); @@ -182,6 +178,35 @@ arp_found(struct arp_state *astate, const struct arp_msg *amsg) astate->defend_failed_cb(astate); } +static bool +arp_validate(const struct interface *ifp, struct arphdr *arp) +{ + + /* Families must match */ + if (arp->ar_hrd != htons(ifp->family)) + return false; + + /* Protocol must be IP. */ + if (arp->ar_pro != htons(ETHERTYPE_IP)) + return false; + + /* lladdr length matches */ + if (arp->ar_hln != ifp->hwlen) + return false; + + /* Protocol length must match in_addr_t */ + if (arp->ar_pln != sizeof(in_addr_t)) + return false; + + /* Only these types are recognised */ + if (arp->ar_op != htons(ARPOP_REPLY) && + arp->ar_op != htons(ARPOP_REQUEST)) + return false; + + return true; +} + + static void arp_packet(struct interface *ifp, uint8_t *data, size_t len) { @@ -197,25 +222,12 @@ arp_packet(struct interface *ifp, uint8_t *data, size_t len) return; memcpy(&ar, data, sizeof(ar)); - /* These checks are enforced in the BPF filter. */ -#if 0 - /* Families must match */ - if (ar.ar_hrd != htons(ifp->family)) - return; - /* Protocol must be IP. */ - if (ar.ar_pro != htons(ETHERTYPE_IP)) - continue; - /* lladdr length matches */ - if (ar.ar_hln != ifp->hwlen) - continue; - /* Protocol length must match in_addr_t */ - if (ar.ar_pln != sizeof(arm.sip.s_addr)) - return; - /* Only these types are recognised */ - if (ar.ar_op != htons(ARPOP_REPLY) && - ar.ar_op != htons(ARPOP_REQUEST)) - continue; + if (!arp_validate(ifp, &ar)) { +#ifdef BPF_DEBUG + logerrx("%s: ARP BPF validation failure", ifp->name); #endif + return; + } /* Get pointers to the hardware addresses */ hw_s = data + sizeof(ar); @@ -329,10 +341,8 @@ arp_open(struct interface *ifp) state = ARP_STATE(ifp); if (state->bpf_fd == -1) { state->bpf_fd = bpf_open(ifp, bpf_arp); - if (state->bpf_fd == -1) { - logerr("%s: %s", __func__, ifp->name); + if (state->bpf_fd == -1) return -1; - } eloop_event_add(ifp->ctx->eloop, state->bpf_fd, arp_read, ifp); } return state->bpf_fd; @@ -428,6 +438,7 @@ arp_announce1(void *arg) { struct arp_state *astate = arg; struct interface *ifp = astate->iface; + struct ipv4_addr *ia; if (++astate->claims < ANNOUNCE_NUM) logdebugx("%s: ARP announcing %s (%d of %d), " @@ -438,24 +449,31 @@ arp_announce1(void *arg) logdebugx("%s: ARP announcing %s (%d of %d)", ifp->name, inet_ntoa(astate->addr), astate->claims, ANNOUNCE_NUM); + + /* The kernel will send a Gratuitous ARP for newly added addresses. + * So we can avoid sending the same. + * Linux is special and doesn't send one. */ + ia = ipv4_iffindaddr(ifp, &astate->addr, NULL); +#ifndef __linux__ + if (astate->claims == 1 && ia != NULL && ia->flags & IPV4_AF_NEW) + goto skip_request; +#endif + if (arp_request(ifp, &astate->addr, &astate->addr) == -1) logerr(__func__); + +#ifndef __linux__ +skip_request: +#endif + /* No longer a new address. */ + if (ia != NULL) + ia->flags |= ~IPV4_AF_NEW; + eloop_timeout_add_sec(ifp->ctx->eloop, ANNOUNCE_WAIT, astate->claims < ANNOUNCE_NUM ? arp_announce1 : arp_announced, astate); } -/* - * XXX FIXME - * Kernels supporting RFC5227 will announce the address when it's - * added. - * dhcpcd should not announce when this happens, nor need to open - * a BPF socket for it. - * Also, an address might be added to a non preferred inteface when - * the same address exists on a preferred one so we need to instruct - * the kernel not to announce the address somehow. - */ - void arp_announce(struct arp_state *astate) { @@ -501,6 +519,9 @@ arp_ifannounceaddr(struct interface *ifp, const struct in_addr *ia) { struct arp_state *astate; + if (ifp->flags & IFF_NOARP) + return; + astate = arp_find(ifp, ia); if (astate == NULL) { astate = arp_new(ifp, ia); diff --git a/external/bsd/dhcpcd/dist/src/bpf.c b/external/bsd/dhcpcd/dist/src/bpf.c index 06bbf3f1e1b..6c31bc2cafc 100644 --- a/external/bsd/dhcpcd/dist/src/bpf.c +++ b/external/bsd/dhcpcd/dist/src/bpf.c @@ -410,13 +410,7 @@ bpf_cmp_hwaddr(struct bpf_insn *bpf, size_t bpf_len, size_t off, #endif #ifdef ARP - static const struct bpf_insn bpf_arp_ether [] = { - /* Ensure packet is at least correct size. */ - BPF_STMT(BPF_LD + BPF_W + BPF_LEN, 0), - BPF_JUMP(BPF_JMP + BPF_JGE + BPF_K, sizeof(struct ether_arp), 1, 0), - BPF_STMT(BPF_RET + BPF_K, 0), - /* Check this is an ARP packet. */ BPF_STMT(BPF_LD + BPF_H + BPF_ABS, offsetof(struct ether_header, ether_type)), @@ -552,17 +546,8 @@ bpf_arp(struct interface *ifp, int fd) } #endif -#define BPF_M_FHLEN 0 -#define BPF_M_IPHLEN 1 -#define BPF_M_IPLEN 2 -#define BPF_M_UDP 3 -#define BPF_M_UDPLEN 4 - #ifdef ARPHRD_NONE static const struct bpf_insn bpf_bootp_none[] = { - /* Set the frame header length to zero. */ - BPF_STMT(BPF_LD + BPF_IMM, 0), - BPF_STMT(BPF_ST, BPF_M_FHLEN), }; #define BPF_BOOTP_NONE_LEN __arraycount(bpf_bootp_none) #endif @@ -574,13 +559,14 @@ static const struct bpf_insn bpf_bootp_ether[] = { BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, ETHERTYPE_IP, 1, 0), BPF_STMT(BPF_RET + BPF_K, 0), - /* Load frame header length into X. */ - BPF_STMT(BPF_LDX + BPF_W + BPF_IMM, sizeof(struct ether_header)), - /* Copy frame header length to memory */ - BPF_STMT(BPF_STX, BPF_M_FHLEN), + /* Advance to the IP header. */ + BPF_STMT(BPF_LDX + BPF_K, sizeof(struct ether_header)), }; #define BPF_BOOTP_ETHER_LEN __arraycount(bpf_bootp_ether) +#define BOOTP_MIN_SIZE sizeof(struct ip) + sizeof(struct udphdr) + \ + sizeof(struct bootp) + static const struct bpf_insn bpf_bootp_filter[] = { /* Make sure it's an IPv4 packet. */ BPF_STMT(BPF_LD + BPF_B + BPF_IND, 0), @@ -588,15 +574,6 @@ static const struct bpf_insn bpf_bootp_filter[] = { BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, 0x40, 1, 0), BPF_STMT(BPF_RET + BPF_K, 0), - /* Ensure IP header length is big enough and - * store the IP header length in memory. */ - BPF_STMT(BPF_LD + BPF_B + BPF_IND, 0), - BPF_STMT(BPF_ALU + BPF_AND + BPF_K, 0x0f), - BPF_STMT(BPF_ALU + BPF_MUL + BPF_K, 4), - BPF_JUMP(BPF_JMP + BPF_JGE + BPF_K, sizeof(struct ip), 1, 0), - BPF_STMT(BPF_RET + BPF_K, 0), - BPF_STMT(BPF_ST, BPF_M_IPHLEN), - /* Make sure it's a UDP packet. */ BPF_STMT(BPF_LD + BPF_B + BPF_IND, offsetof(struct ip, ip_p)), BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, IPPROTO_UDP, 1, 0), @@ -607,49 +584,17 @@ static const struct bpf_insn bpf_bootp_filter[] = { BPF_JUMP(BPF_JMP + BPF_JSET + BPF_K, 0x1fff, 0, 1), BPF_STMT(BPF_RET + BPF_K, 0), - /* Store IP length. */ - BPF_STMT(BPF_LD + BPF_H + BPF_IND, offsetof(struct ip, ip_len)), - BPF_STMT(BPF_ST, BPF_M_IPLEN), - /* Advance to the UDP header. */ - BPF_STMT(BPF_LD + BPF_MEM, BPF_M_IPHLEN), + BPF_STMT(BPF_LD + BPF_B + BPF_IND, 0), + BPF_STMT(BPF_ALU + BPF_AND + BPF_K, 0x0f), + BPF_STMT(BPF_ALU + BPF_MUL + BPF_K, 4), BPF_STMT(BPF_ALU + BPF_ADD + BPF_X, 0), BPF_STMT(BPF_MISC + BPF_TAX, 0), - /* Store UDP location */ - BPF_STMT(BPF_STX, BPF_M_UDP), - /* Make sure it's from and to the right port. */ BPF_STMT(BPF_LD + BPF_W + BPF_IND, 0), BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, (BOOTPS << 16) + BOOTPC, 1, 0), BPF_STMT(BPF_RET + BPF_K, 0), - - /* Store UDP length. */ - BPF_STMT(BPF_LD + BPF_H + BPF_IND, offsetof(struct udphdr, uh_ulen)), - BPF_STMT(BPF_ST, BPF_M_UDPLEN), - - /* Ensure that UDP length + IP header length == IP length */ - /* Copy IP header length to X. */ - BPF_STMT(BPF_LDX + BPF_MEM, BPF_M_IPHLEN), - /* Add UDP length (A) to IP header length (X). */ - BPF_STMT(BPF_ALU + BPF_ADD + BPF_X, 0), - /* Store result in X. */ - BPF_STMT(BPF_MISC + BPF_TAX, 0), - /* Copy IP length to A. */ - BPF_STMT(BPF_LD + BPF_MEM, BPF_M_IPLEN), - /* Ensure X == A. */ - BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_X, 0, 1, 0), - BPF_STMT(BPF_RET + BPF_K, 0), - - /* Advance to the BOOTP packet. */ - BPF_STMT(BPF_LD + BPF_MEM, BPF_M_UDP), - BPF_STMT(BPF_ALU + BPF_ADD + BPF_K, sizeof(struct udphdr)), - BPF_STMT(BPF_MISC + BPF_TAX, 0), - - /* Make sure it's BOOTREPLY. */ - BPF_STMT(BPF_LD + BPF_B + BPF_IND, offsetof(struct bootp, op)), - BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, BOOTREPLY, 1, 0), - BPF_STMT(BPF_RET + BPF_K, 0), }; #define BPF_BOOTP_FILTER_LEN __arraycount(bpf_bootp_filter) @@ -729,14 +674,8 @@ bpf_bootp(struct interface *ifp, int fd) } #endif - /* All passed, return the packet - frame length + ip length */ - BPF_SET_STMT(bp, BPF_LD + BPF_MEM, BPF_M_FHLEN); - bp++; - BPF_SET_STMT(bp, BPF_LDX + BPF_MEM, BPF_M_IPLEN); - bp++; - BPF_SET_STMT(bp, BPF_ALU + BPF_ADD + BPF_X, 0); - bp++; - BPF_SET_STMT(bp, BPF_RET + BPF_A, 0); + /* All passed, return the packet. */ + BPF_SET_STMT(bp, BPF_RET + BPF_K, BPF_WHOLEPACKET); bp++; return bpf_attach(fd, bpf, (unsigned int)(bp - bpf)); diff --git a/external/bsd/dhcpcd/dist/src/bpf.h b/external/bsd/dhcpcd/dist/src/bpf.h index e886f9c3be4..46bc6c379e8 100644 --- a/external/bsd/dhcpcd/dist/src/bpf.h +++ b/external/bsd/dhcpcd/dist/src/bpf.h @@ -34,6 +34,25 @@ #define BPF_PARTIALCSUM (1U << 2) #define BPF_BCAST (1U << 3) +/* + * Even though we program the BPF filter should we trust it? + * On Linux at least there is a window between opening the socket, + * binding the interface and setting the filter where we receive data. + * This data is NOT checked OR flushed and IS returned when reading. + * We have no way of flushing it other than reading these packets! + * But we don't know if they passed the filter or not ..... so we need + * to validate each and every packet that comes through ourselves as well. + * Even if Linux does fix this sorry state, who is to say other kernels + * don't have bugs causing a similar effect? + * + * As such, let's strive to keep the filters just for pattern matching + * to avoid waking dhcpcd up. + * + * If you want to be notified of any packet failing the BPF filter, + * define BPF_DEBUG below. + */ +//#define BPF_DEBUG + #include "dhcpcd.h" extern const char *bpf_name; diff --git a/external/bsd/dhcpcd/dist/src/common.c b/external/bsd/dhcpcd/dist/src/common.c index 31998c0ede7..8b45a30709c 100644 --- a/external/bsd/dhcpcd/dist/src/common.c +++ b/external/bsd/dhcpcd/dist/src/common.c @@ -26,28 +26,12 @@ * SUCH DAMAGE. */ -#include <sys/param.h> -#include <sys/time.h> -#ifdef __sun -#include <sys/sysmacros.h> -#endif +#include <sys/statvfs.h> -#include <assert.h> #include <ctype.h> -#include <err.h> #include <errno.h> -#include <fcntl.h> -#include <limits.h> -#ifdef BSD -# include <paths.h> -#endif -#include <stdarg.h> -#include <stdint.h> #include <stdio.h> #include <stdlib.h> -#include <string.h> -#include <time.h> -#include <unistd.h> #include "common.h" #include "dhcpcd.h" @@ -153,3 +137,18 @@ read_hwaddr_aton(uint8_t **data, const char *path) fclose(fp); return len; } + +int +is_root_local(void) +{ +#ifdef ST_LOCAL + struct statvfs vfs; + + if (statvfs("/", &vfs) == -1) + return -1; + return vfs.f_flag & ST_LOCAL ? 1 : 0; +#else + errno = ENOTSUP; + return -1; +#endif +} diff --git a/external/bsd/dhcpcd/dist/src/common.h b/external/bsd/dhcpcd/dist/src/common.h index 301c8869b54..4e8bcdead66 100644 --- a/external/bsd/dhcpcd/dist/src/common.h +++ b/external/bsd/dhcpcd/dist/src/common.h @@ -197,4 +197,5 @@ int get_monotonic(struct timespec *); const char *hwaddr_ntoa(const void *, size_t, char *, size_t); size_t hwaddr_aton(uint8_t *, const char *); size_t read_hwaddr_aton(uint8_t **, const char *); +int is_root_local(void); #endif diff --git a/external/bsd/dhcpcd/dist/src/control.h b/external/bsd/dhcpcd/dist/src/control.h index e52343dba14..d9f77daa5c0 100644 --- a/external/bsd/dhcpcd/dist/src/control.h +++ b/external/bsd/dhcpcd/dist/src/control.h @@ -29,6 +29,8 @@ #ifndef CONTROL_H #define CONTROL_H +#include <stdbool.h> + #include "dhcpcd.h" #if !defined(CTL_FREE_LIST) diff --git a/external/bsd/dhcpcd/dist/src/defs.h b/external/bsd/dhcpcd/dist/src/defs.h index eb39c04424d..e0cd63c74c8 100644 --- a/external/bsd/dhcpcd/dist/src/defs.h +++ b/external/bsd/dhcpcd/dist/src/defs.h @@ -29,7 +29,7 @@ #define CONFIG_H #define PACKAGE "dhcpcd" -#define VERSION "8.0.4" +#define VERSION "8.1.0" #ifndef CONFIG # define CONFIG SYSCONFDIR "/" PACKAGE ".conf" diff --git a/external/bsd/dhcpcd/dist/src/dev.c b/external/bsd/dhcpcd/dist/src/dev.c deleted file mode 100644 index d84a42c6e62..00000000000 --- a/external/bsd/dhcpcd/dist/src/dev.c +++ /dev/null @@ -1,191 +0,0 @@ -/* SPDX-License-Identifier: BSD-2-Clause */ -/* - * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2019 Roy Marples <roy@marples.name> - * - * 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. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. - */ - -#include <dirent.h> -#include <dlfcn.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#define _INDEV -#include "common.h" -#include "dev.h" -#include "eloop.h" -#include "dhcpcd.h" -#include "logerr.h" - -int -dev_initialized(struct dhcpcd_ctx *ctx, const char *ifname) -{ - - if (ctx->dev == NULL) - return 1; - return ctx->dev->initialized(ifname); -} - -int -dev_listening(struct dhcpcd_ctx *ctx) -{ - - if (ctx->dev == NULL) - return 0; - return ctx->dev->listening(); -} - -static void -dev_stop1(struct dhcpcd_ctx *ctx, int stop) -{ - - if (ctx->dev) { - if (stop) - logdebugx("dev: unloaded %s", ctx->dev->name); - eloop_event_delete(ctx->eloop, ctx->dev_fd); - ctx->dev->stop(); - free(ctx->dev); - ctx->dev = NULL; - ctx->dev_fd = -1; - } - if (ctx->dev_handle) { - dlclose(ctx->dev_handle); - ctx->dev_handle = NULL; - } -} - -void -dev_stop(struct dhcpcd_ctx *ctx) -{ - - dev_stop1(ctx,!(ctx->options & DHCPCD_FORKED)); -} - -static int -dev_start2(struct dhcpcd_ctx *ctx, const char *name) -{ - char file[PATH_MAX]; - void *h; - void (*fptr)(struct dev *, const struct dev_dhcpcd *); - int r; - struct dev_dhcpcd dev_dhcpcd; - - snprintf(file, sizeof(file), DEVDIR "/%s", name); - h = dlopen(file, RTLD_LAZY); - if (h == NULL) { - logerrx("dlopen: %s", dlerror()); - return -1; - } - fptr = (void (*)(struct dev *, const struct dev_dhcpcd *)) - dlsym(h, "dev_init"); - if (fptr == NULL) { - logerrx("dlsym: %s", dlerror()); - dlclose(h); - return -1; - } - if ((ctx->dev = calloc(1, sizeof(*ctx->dev))) == NULL) { - logerr("%s: calloc", __func__); - dlclose(h); - return -1; - } - dev_dhcpcd.handle_interface = &dhcpcd_handleinterface; - fptr(ctx->dev, &dev_dhcpcd); - if (ctx->dev->start == NULL || (r = ctx->dev->start()) == -1) { - free(ctx->dev); - ctx->dev = NULL; - dlclose(h); - return -1; - } - loginfox("dev: loaded %s", ctx->dev->name); - ctx->dev_handle = h; - return r; -} - -static int -dev_start1(struct dhcpcd_ctx *ctx) -{ - DIR *dp; - struct dirent *d; - int r; - - if (ctx->dev) { - logerrx("dev: already started %s", ctx->dev->name); - return -1; - } - - if (ctx->dev_load) - return dev_start2(ctx, ctx->dev_load); - - dp = opendir(DEVDIR); - if (dp == NULL) { - logdebug("dev: %s", DEVDIR); - return 0; - } - - r = 0; - while ((d = readdir(dp))) { - if (d->d_name[0] == '.') - continue; - - r = dev_start2(ctx, d->d_name); - if (r != -1) - break; - } - closedir(dp); - return r; -} - -static void -dev_handle_data(void *arg) -{ - struct dhcpcd_ctx *ctx; - - ctx = arg; - if (ctx->dev->handle_device(arg) == -1) { - /* XXX: an error occured. should we restart dev? */ - } -} - -int -dev_start(struct dhcpcd_ctx *ctx) -{ - - if (ctx->dev_fd != -1) { - logerrx("%s: already started on fd %d", __func__, ctx->dev_fd); - return ctx->dev_fd; - } - - ctx->dev_fd = dev_start1(ctx); - if (ctx->dev_fd != -1) { - if (eloop_event_add(ctx->eloop, ctx->dev_fd, - dev_handle_data, ctx) == -1) - { - logerr(__func__); - dev_stop1(ctx, 1); - return -1; - } - } - - return ctx->dev_fd; -} diff --git a/external/bsd/dhcpcd/dist/src/dev/Makefile b/external/bsd/dhcpcd/dist/src/dev/Makefile deleted file mode 100644 index 13832b9e743..00000000000 --- a/external/bsd/dhcpcd/dist/src/dev/Makefile +++ /dev/null @@ -1,45 +0,0 @@ -TOP?= ../../ -include ${TOP}/Makefile.inc -include ${TOP}/config.mk - -CFLAGS?= -O2 -CSTD?= c99 -CFLAGS+= -std=${CSTD} -CPPFLAGS+= -I${TOP} -I${TOP}/src - -DEVDIR= ${LIBDIR}/dhcpcd/dev -DSRC= ${DEV_PLUGINS:=.c} -DOBJ= ${DSRC:.c=.o} -DSOBJ= ${DOBJ:.o=.So} -DPLUGS= ${DEV_PLUGINS:=.so} - -CLEANFILES+= ${DSOBJ} ${DPLUGS} - -.SUFFIXES: .So .so - -.c.So: - ${CC} ${PICFLAG} -DPIC ${CPPFLAGS} ${CFLAGS} -c $< -o $@ - -.So.so: ${DSOBJ} - ${CC} ${LDFLAGS} -shared -Wl,-x -o $@ -Wl,-soname,$@ \ - $< ${LIBS} - -all: ${DPLUGS} - -udev.So: -CFLAGS+= ${LIBUDEV_CFLAGS} -CPPFLAGS+= ${LIBUDEV_CPPFLAGS} - -udev.so: -LIBS+= ${LIBUDEV_LIBS} - -proginstall: ${DPLUGS} - ${INSTALL} -d ${DESTDIR}${DEVDIR} - ${INSTALL} -m ${BINMODE} ${PROG} ${DPLUGS} ${DESTDIR}${DEVDIR} - -eginstall: - -install: proginstall - -clean: - rm -f ${CLEANFILES} diff --git a/external/bsd/dhcpcd/dist/src/dev/udev.c b/external/bsd/dhcpcd/dist/src/dev/udev.c deleted file mode 100644 index feca9ca91e1..00000000000 --- a/external/bsd/dhcpcd/dist/src/dev/udev.c +++ /dev/null @@ -1,179 +0,0 @@ -/* SPDX-License-Identifier: BSD-2-Clause */ -/* - * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2019 Roy Marples <roy@marples.name> - * - * 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. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. - */ - -#ifdef LIBUDEV_NOINIT -# define LIBUDEV_I_KNOW_THE_API_IS_SUBJECT_TO_CHANGE -# warning This version of udev is too old does not support -# warning per device initialization checks. -# warning As such, dhcpcd will need to depend on the -# warning udev-settle service or similar if starting -# warning in master mode. -#endif - -#include <libudev.h> -#include <string.h> - -#include "../common.h" -#include "../dev.h" -#include "../logerr.h" - -static const char udev_name[] = "udev"; -static struct udev *udev; -static struct udev_monitor *monitor; - -static struct dev_dhcpcd dhcpcd; - -static int -udev_listening(void) -{ - - return monitor ? 1 : 0; -} - -static int -udev_initialized(const char *ifname) -{ - struct udev_device *device; - int r; - - device = udev_device_new_from_subsystem_sysname(udev, "net", ifname); - if (device) { -#ifndef LIBUDEV_NOINIT - r = udev_device_get_is_initialized(device); -#else - r = 1; -#endif - udev_device_unref(device); - } else - r = 0; - return r; -} - -static int -udev_handle_device(void *ctx) -{ - struct udev_device *device; - const char *subsystem, *ifname, *action; - - device = udev_monitor_receive_device(monitor); - if (device == NULL) { - logerrx("libudev: received NULL device"); - return -1; - } - - subsystem = udev_device_get_subsystem(device); - ifname = udev_device_get_sysname(device); - action = udev_device_get_action(device); - - /* udev filter documentation says "usually" so double check */ - if (strcmp(subsystem, "net") == 0) { - logdebugx("%s: libudev: %s", ifname, action); - if (strcmp(action, "add") == 0 || strcmp(action, "move") == 0) - dhcpcd.handle_interface(ctx, 1, ifname); - else if (strcmp(action, "remove") == 0) - dhcpcd.handle_interface(ctx, -1, ifname); - } - - udev_device_unref(device); - return 1; -} - -static void -udev_stop(void) -{ - - if (monitor) { - udev_monitor_unref(monitor); - monitor = NULL; - } - - if (udev) { - udev_unref(udev); - udev = NULL; - } -} - -static int -udev_start(void) -{ - int fd; - - if (udev) { - logerrx("udev: already started"); - return -1; - } - - logdebugx("udev: starting"); - udev = udev_new(); - if (udev == NULL) { - logerr("udev_new"); - return -1; - } - monitor = udev_monitor_new_from_netlink(udev, "udev"); - if (monitor == NULL) { - logerr("udev_monitor_new_from_netlink"); - goto bad; - } -#ifndef LIBUDEV_NOFILTER - if (udev_monitor_filter_add_match_subsystem_devtype(monitor, - "net", NULL) != 0) - { - logerr("udev_monitor_filter_add_match_subsystem_devtype"); - goto bad; - } -#endif - if (udev_monitor_enable_receiving(monitor) != 0) { - logerr("udev_monitor_enable_receiving"); - goto bad; - } - fd = udev_monitor_get_fd(monitor); - if (fd == -1) { - logerr("udev_monitor_get_fd"); - goto bad; - } - return fd; - -bad: - udev_stop(); - return -1; -} - -int -dev_init(struct dev *dev, const struct dev_dhcpcd *dev_dhcpcd) -{ - - dev->name = udev_name; - dev->initialized = udev_initialized; - dev->listening = udev_listening; - dev->handle_device = udev_handle_device; - dev->stop = udev_stop; - dev->start = udev_start; - - dhcpcd = *dev_dhcpcd; - - return 0; -} diff --git a/external/bsd/dhcpcd/dist/src/dhcp-common.c b/external/bsd/dhcpcd/dist/src/dhcp-common.c index dab20a2e92a..e26ddd021c7 100644 --- a/external/bsd/dhcpcd/dist/src/dhcp-common.c +++ b/external/bsd/dhcpcd/dist/src/dhcp-common.c @@ -200,6 +200,10 @@ make_option_mask(const struct dhcp_opt *dopts, size_t dopts_len, while ((token = strsep(&p, ", "))) { if (*token == '\0') continue; + if (strncmp(token, "dhcp6_", 6) == 0) + token += 6; + if (strncmp(token, "nd6_", 4) == 0) + token += 4; match = 0; for (i = 0, opt = odopts; i < odopts_len; i++, opt++) { if (opt->var == NULL || opt->option == 0) diff --git a/external/bsd/dhcpcd/dist/src/dhcp-common.h b/external/bsd/dhcpcd/dist/src/dhcp-common.h index 2732823afd2..a711a184a25 100644 --- a/external/bsd/dhcpcd/dist/src/dhcp-common.h +++ b/external/bsd/dhcpcd/dist/src/dhcp-common.h @@ -81,6 +81,11 @@ #define OT_BITFLAG (1 << 27) #define OT_RESERVED (1 << 28) +#define DHC_REQOPT(o, r, n) \ + (!((o)->type & OT_NOREQ) && \ + ((o)->type & OT_REQUEST || has_option_mask((r), (o)->option)) && \ + !has_option_mask((n), (o)->option)) + struct dhcp_opt { uint32_t option; /* Also used for IANA Enterpise Number */ int type; diff --git a/external/bsd/dhcpcd/dist/src/dhcp.c b/external/bsd/dhcpcd/dist/src/dhcp.c index eafd6e7aa49..ab0ae90b3a1 100644 --- a/external/bsd/dhcpcd/dist/src/dhcp.c +++ b/external/bsd/dhcpcd/dist/src/dhcp.c @@ -988,7 +988,8 @@ make_message(struct bootp **bootpm, const struct interface *ifp, uint8_t type) #ifdef AUTH if ((ifo->auth.options & DHCPCD_AUTH_SENDREQUIRE) != - DHCPCD_AUTH_SENDREQUIRE) + DHCPCD_AUTH_SENDREQUIRE && + !has_option_mask(ifo->nomask, DHO_FORCERENEW_NONCE)) { /* We support HMAC-MD5 */ AREA_CHECK(1); @@ -1032,10 +1033,7 @@ make_message(struct bootp **bootpm, const struct interface *ifp, uint8_t type) i < ifp->ctx->dhcp_opts_len; i++, opt++) { - if (!(opt->type & OT_REQUEST || - has_option_mask(ifo->requestmask, opt->option))) - continue; - if (opt->type & OT_NOREQ) + if (!DHC_REQOPT(opt, ifo->requestmask, ifo->nomask)) continue; if (type == DHCP_INFORM && (opt->option == DHO_RENEWALTIME || @@ -1054,10 +1052,7 @@ make_message(struct bootp **bootpm, const struct interface *ifp, uint8_t type) break; if (lp < p) continue; - if (!(opt->type & OT_REQUEST || - has_option_mask(ifo->requestmask, opt->option))) - continue; - if (opt->type & OT_NOREQ) + if (!DHC_REQOPT(opt, ifo->requestmask, ifo->nomask)) continue; if (type == DHCP_INFORM && (opt->option == DHO_RENEWALTIME || @@ -1738,15 +1733,32 @@ send_message(struct interface *ifp, uint8_t type, if (r == -1) goto fail; len = (size_t)r; - from.s_addr = bootp->ciaddr; - if (from.s_addr != INADDR_ANY) + + if (ipv4_iffindaddr(ifp, &state->lease.addr, NULL) != NULL) + from.s_addr = state->lease.addr.s_addr; + else + from.s_addr = INADDR_ANY; + if (from.s_addr != INADDR_ANY && + state->lease.server.s_addr != INADDR_ANY) to.s_addr = state->lease.server.s_addr; else - to.s_addr = INADDR_ANY; + to.s_addr = INADDR_BROADCAST; - /* If unicasting, try and avoid sending by BPF so we don't - * use a L2 broadcast. */ - if (to.s_addr != INADDR_ANY && to.s_addr != INADDR_BROADCAST) { + /* + * If not listening on the unspecified address we can + * only receive broadcast messages via BPF. + * Sockets bound to an address cannot receive broadcast messages + * even if they are setup to send them. + * Broadcasting from UDP is only an optimisation for rebinding + * and on BSD, at least, is reliant on the subnet route being + * correctly configured to recieve the unicast reply. + * As such, we always broadcast and receive the reply to it via BPF. + * This also guarantees we have a DHCP server attached to the + * interface we want to configure because we can't dictate the + * interface via IP_PKTINFO unlike for IPv6. + */ + if (to.s_addr != INADDR_BROADCAST) + { if (dhcp_sendudp(ifp, &to, bootp, len) != -1) goto out; logerr("%s: dhcp_sendudp", ifp->name); @@ -2001,30 +2013,44 @@ dhcp_finish_dad(struct interface *ifp, struct in_addr *ia) } -static void +static bool dhcp_addr_duplicated(struct interface *ifp, struct in_addr *ia) { struct dhcp_state *state = D_STATE(ifp); + unsigned long long opts = ifp->options->options; + struct dhcpcd_ctx *ctx = ifp->ctx; + bool deleted = false; #ifdef IN_IFF_DUPLICATED struct ipv4_addr *iap; #endif if ((state->offer == NULL || state->offer->yiaddr != ia->s_addr) && !IN_ARE_ADDR_EQUAL(ia, &state->lease.addr)) - return; + return deleted; /* RFC 2131 3.1.5, Client-server interaction */ logerrx("%s: DAD detected %s", ifp->name, inet_ntoa(*ia)); unlink(state->leasefile); - if (!(ifp->options->options & DHCPCD_STATIC) && !state->lease.frominfo) + if (!(opts & DHCPCD_STATIC) && !state->lease.frominfo) dhcp_decline(ifp); #ifdef IN_IFF_DUPLICATED - if ((iap = ipv4_iffindaddr(ifp, ia, NULL)) != NULL) + if ((iap = ipv4_iffindaddr(ifp, ia, NULL)) != NULL) { ipv4_deladdr(iap, 0); + deleted = true; + } #endif - eloop_timeout_delete(ifp->ctx->eloop, NULL, ifp); + eloop_timeout_delete(ctx->eloop, NULL, ifp); + if (opts & (DHCPCD_STATIC | DHCPCD_INFORM)) { + state->reason = "EXPIRE"; + script_runreason(ifp, state->reason); +#define NOT_ONLY_SELF (DHCPCD_MASTER | DHCPCD_IPV6RS | DHCPCD_DHCP6) + if (!(ctx->options & NOT_ONLY_SELF)) + eloop_exit(ifp->ctx->eloop, EXIT_FAILURE); + return deleted; + } eloop_timeout_add_sec(ifp->ctx->eloop, DHCP_RAND_MAX, dhcp_discover, ifp); + return deleted; } #endif @@ -2362,7 +2388,9 @@ dhcp_arp_address(struct interface *ifp) /* Add the address now, let the kernel handle DAD. */ ipv4_addaddr(ifp, &l.addr, &l.mask, &l.brd, l.leasetime, l.rebindtime); - } else + } else if (ia->addr_flags & IN_IFF_DUPLICATED) + dhcp_addr_duplicated(ifp, &ia->addr); + else loginfox("%s: waiting for DAD on %s", ifp->name, inet_ntoa(addr)); return 0; @@ -2841,14 +2869,18 @@ dhcp_handledhcp(struct interface *ifp, struct bootp *bootp, size_t bootp_len, #define LOGDHCP(l, m) \ log_dhcp((l), (m), ifp, bootp, bootp_len, from, 1) +#define IS_STATE_ACTIVE(s) ((s)-state != DHS_NONE && \ + (s)->state != DHS_INIT && (s)->state != DHS_BOUND) + if (bootp->op != BOOTREPLY) { - logdebugx("%s: op (%d) is not BOOTREPLY", - ifp->name, bootp->op); + if (IS_STATE_ACTIVE(state)) + logdebugx("%s: op (%d) is not BOOTREPLY", + ifp->name, bootp->op); return; } if (state->xid != ntohl(bootp->xid)) { - if (state->state != DHS_BOUND && state->state != DHS_NONE) + if (IS_STATE_ACTIVE(state)) logdebugx("%s: wrong xid 0x%x (expecting 0x%x) from %s", ifp->name, ntohl(bootp->xid), state->xid, inet_ntoa(*from)); @@ -2859,12 +2891,14 @@ dhcp_handledhcp(struct interface *ifp, struct bootp *bootp, size_t bootp_len, if (ifp->hwlen <= sizeof(bootp->chaddr) && memcmp(bootp->chaddr, ifp->hwaddr, ifp->hwlen)) { - char buf[sizeof(bootp->chaddr) * 3]; + if (IS_STATE_ACTIVE(state)) { + char buf[sizeof(bootp->chaddr) * 3]; - logdebugx("%s: xid 0x%x is for hwaddr %s", - ifp->name, ntohl(bootp->xid), - hwaddr_ntoa(bootp->chaddr, sizeof(bootp->chaddr), - buf, sizeof(buf))); + logdebugx("%s: xid 0x%x is for hwaddr %s", + ifp->name, ntohl(bootp->xid), + hwaddr_ntoa(bootp->chaddr, sizeof(bootp->chaddr), + buf, sizeof(buf))); + } dhcp_redirect_dhcp(ifp, bootp, bootp_len, from); return; } @@ -2959,10 +2993,7 @@ dhcp_handledhcp(struct interface *ifp, struct bootp *bootp, size_t bootp_len, } if (state->state == DHS_BOUND) { - /* Before we supported FORCERENEW we closed off the raw - * port so we effectively ignored all messages. - * As such we'll not log by default here. */ - //LOGDHCP(logdebugx, "bound, ignoring"); + LOGDHCP(logdebugx, "bound, ignoring"); return; } @@ -3239,9 +3270,40 @@ get_udp_data(void *packet, size_t *len) return p; } -static int -valid_udp_packet(void *packet, size_t plen, struct in_addr *from, - unsigned int flags) +static bool +is_packet_udp_bootp(void *packet, size_t plen) +{ + struct ip *ip = packet; + size_t ip_hlen; + struct udphdr *udp; + + if (sizeof(*ip) > plen) + return false; + + if (ip->ip_v != IPVERSION || ip->ip_p != IPPROTO_UDP) + return false; + + /* Sanity. */ + if (ntohs(ip->ip_len) != plen) + return false; + + ip_hlen = (size_t)ip->ip_hl * 4; + /* Check we have a UDP header and BOOTP. */ + if (ip_hlen + sizeof(*udp) + offsetof(struct bootp, vend) > plen) + return false; + + /* Check it's to and from the right ports. */ + udp = (struct udphdr *)(void *)((char *)ip + ip_hlen); + if (udp->uh_dport != htons(BOOTPC) || udp->uh_sport != htons(BOOTPS)) + return false; + + return true; +} + +/* Lengths have already been checked. */ +static bool +checksums_valid(void *packet, + struct in_addr *from, unsigned int flags) { struct ip *ip = packet; struct ip pseudo_ip = { @@ -3250,59 +3312,34 @@ valid_udp_packet(void *packet, size_t plen, struct in_addr *from, .ip_dst = ip->ip_dst }; size_t ip_hlen; - uint16_t ip_len, uh_sum; + uint16_t udp_len, uh_sum; struct udphdr *udp; uint32_t csum; - if (plen < sizeof(*ip)) { - if (from != NULL) - from->s_addr = INADDR_ANY; - errno = ERANGE; - return -1; - } - if (from != NULL) from->s_addr = ip->ip_src.s_addr; ip_hlen = (size_t)ip->ip_hl * 4; - if (in_cksum(ip, ip_hlen, NULL) != 0) { - errno = EINVAL; - return -1; - } - - /* Check we have a payload */ - ip_len = ntohs(ip->ip_len); - if (ip_len <= ip_hlen + sizeof(*udp)) { - errno = ERANGE; - return -1; - } - /* Check we don't go beyond the payload */ - if (ip_len > plen) { - errno = ENOBUFS; - return -1; - } + if (in_cksum(ip, ip_hlen, NULL) != 0) + return false; if (flags & BPF_PARTIALCSUM) return 0; - /* UDP checksum is based on a pseudo IP header alongside - * the UDP header and payload. */ udp = (struct udphdr *)(void *)((char *)ip + ip_hlen); if (udp->uh_sum == 0) return 0; + /* UDP checksum is based on a pseudo IP header alongside + * the UDP header and payload. */ + udp_len = ntohs(udp->uh_ulen); uh_sum = udp->uh_sum; udp->uh_sum = 0; pseudo_ip.ip_len = udp->uh_ulen; csum = 0; in_cksum(&pseudo_ip, sizeof(pseudo_ip), &csum); - csum = in_cksum(udp, ntohs(udp->uh_ulen), &csum); - if (csum != uh_sum) { - errno = EINVAL; - return -1; - } - - return 0; + csum = in_cksum(udp, udp_len, &csum); + return csum == uh_sum; } static void @@ -3311,13 +3348,12 @@ dhcp_handlebootp(struct interface *ifp, struct bootp *bootp, size_t len, { size_t v; - /* udp_len must be correct because the values are checked in - * valid_udp_packet(). */ if (len < offsetof(struct bootp, vend)) { logerrx("%s: truncated packet (%zu) from %s", ifp->name, len, inet_ntoa(*from)); return; } + /* To make our IS_DHCP macro easy, ensure the vendor * area has at least 4 octets. */ v = len - offsetof(struct bootp, vend); @@ -3330,20 +3366,24 @@ dhcp_handlebootp(struct interface *ifp, struct bootp *bootp, size_t len, } static void -dhcp_handlepacket(struct interface *ifp, uint8_t *data, size_t len) +dhcp_handlebpf(struct interface *ifp, uint8_t *data, size_t len) { struct bootp *bootp; struct in_addr from; size_t udp_len; const struct dhcp_state *state = D_CSTATE(ifp); - if (valid_udp_packet(data, len, &from, state->bpf_flags) == -1) { - if (errno == EINVAL) - logerrx("%s: checksum failure from %s", - ifp->name, inet_ntoa(from)); - else - logerr("%s: invalid UDP packet from %s", - ifp->name, inet_ntoa(from)); + /* Validate filter. */ + if (!is_packet_udp_bootp(data, len)) { +#ifdef BPF_DEBUG + logerrx("%s: DHCP BPF validation failure", ifp->name); +#endif + return; + } + + if (!checksums_valid(data, &from, state->bpf_flags)) { + logerrx("%s: checksum failure from %s", + ifp->name, inet_ntoa(from)); return; } @@ -3359,7 +3399,7 @@ dhcp_handlepacket(struct interface *ifp, uint8_t *data, size_t len) } static void -dhcp_readpacket(void *arg) +dhcp_readbpf(void *arg) { struct interface *ifp = arg; uint8_t buf[MTU_MAX]; @@ -3381,7 +3421,7 @@ dhcp_readpacket(void *arg) } break; } - dhcp_handlepacket(ifp, buf, (size_t)bytes); + dhcp_handlebpf(ifp, buf, (size_t)bytes); /* Check we still have a state after processing. */ if ((state = D_STATE(ifp)) == NULL) break; @@ -3494,7 +3534,7 @@ dhcp_openbpf(struct interface *ifp) } eloop_event_add(ifp->ctx->eloop, - state->bpf_fd, dhcp_readpacket, ifp); + state->bpf_fd, dhcp_readbpf, ifp); return 0; } @@ -3926,7 +3966,7 @@ dhcp_abort(struct interface *ifp) } } -void +struct ipv4_addr * dhcp_handleifa(int cmd, struct ipv4_addr *ia, pid_t pid) { struct interface *ifp; @@ -3937,7 +3977,7 @@ dhcp_handleifa(int cmd, struct ipv4_addr *ia, pid_t pid) ifp = ia->iface; state = D_STATE(ifp); if (state == NULL || state->state == DHS_NONE) - return; + return ia; if (cmd == RTM_DELADDR) { if (state->addr == ia) { @@ -3948,37 +3988,37 @@ dhcp_handleifa(int cmd, struct ipv4_addr *ia, pid_t pid) * to drop the lease. */ dhcp_drop(ifp, "EXPIRE"); dhcp_start1(ifp); + return NULL; } - return; } if (cmd != RTM_NEWADDR) - return; + return ia; #ifdef IN_IFF_NOTUSEABLE if (!(ia->addr_flags & IN_IFF_NOTUSEABLE)) dhcp_finish_dad(ifp, &ia->addr); else if (ia->addr_flags & IN_IFF_DUPLICATED) - dhcp_addr_duplicated(ifp, &ia->addr); + return dhcp_addr_duplicated(ifp, &ia->addr) ? NULL : ia; #endif ifo = ifp->options; if (ifo->options & DHCPCD_INFORM) { if (state->state != DHS_INFORM) dhcp_inform(ifp); - return; + return ia; } if (!(ifo->options & DHCPCD_STATIC)) - return; + return ia; if (ifo->req_addr.s_addr != INADDR_ANY) - return; + return ia; free(state->old); state->old = state->new; state->new_len = dhcp_message_new(&state->new, &ia->addr, &ia->mask); if (state->new == NULL) - return; + return ia; if (ifp->flags & IFF_POINTOPOINT) { for (i = 1; i < 255; i++) if (i != DHO_ROUTER && has_option_mask(ifo->dstmask,i)) @@ -3994,4 +4034,6 @@ dhcp_handleifa(int cmd, struct ipv4_addr *ia, pid_t pid) state->addr = ia; dhcp_inform(ifp); } + + return ia; } diff --git a/external/bsd/dhcpcd/dist/src/dhcp.h b/external/bsd/dhcpcd/dist/src/dhcp.h index 4b6311a38bb..98a8b1e4899 100644 --- a/external/bsd/dhcpcd/dist/src/dhcp.h +++ b/external/bsd/dhcpcd/dist/src/dhcp.h @@ -260,7 +260,7 @@ int dhcp_get_routes(rb_tree_t *, struct interface *); ssize_t dhcp_env(FILE *, const char *, const struct interface *, const struct bootp *, size_t); -void dhcp_handleifa(int, struct ipv4_addr *, pid_t pid); +struct ipv4_addr *dhcp_handleifa(int, struct ipv4_addr *, pid_t pid); void dhcp_drop(struct interface *, const char *); void dhcp_start(struct interface *); void dhcp_abort(struct interface *); diff --git a/external/bsd/dhcpcd/dist/src/dhcp6.c b/external/bsd/dhcpcd/dist/src/dhcp6.c index 3c22005c1a9..4ef2e565e96 100644 --- a/external/bsd/dhcpcd/dist/src/dhcp6.c +++ b/external/bsd/dhcpcd/dist/src/dhcp6.c @@ -532,13 +532,6 @@ dhcp6_delegateaddr(struct in6_addr *addr, struct interface *ifp, asla.prefix_len = 0; asla.sla_set = 0; sla = &asla; - } else if (sla->sla == 0 && sla->prefix_len == 0) { - /* An SLA of 0 was set with no prefix length specified. - * This means we delegate the whole prefix. */ - asla.sla = sla->sla; - asla.prefix_len = prefix->prefix_len; - asla.sla_set = 0; - sla = &asla; } else if (sla->prefix_len == 0) { /* An SLA was given, but prefix length was not. * We need to work out a suitable prefix length for @@ -680,27 +673,21 @@ dhcp6_makemessage(struct interface *ifp) break; } if (n < ifo->dhcp6_override_len) - continue; - if (!(opt->type & OT_NOREQ) && - (opt->type & OT_REQUEST || - has_option_mask(ifo->requestmask6, opt->option))) - { - n_options++; - len += sizeof(o.len); - } + continue; + if (!DHC_REQOPT(opt, ifo->requestmask6, ifo->nomask6)) + continue; + n_options++; + len += sizeof(o.len); } #ifndef SMALL for (l = 0, opt = ifo->dhcp6_override; l < ifo->dhcp6_override_len; l++, opt++) { - if (!(opt->type & OT_NOREQ) && - (opt->type & OT_REQUEST || - has_option_mask(ifo->requestmask6, opt->option))) - { - n_options++; - len += sizeof(o.len); - } + if (!DHC_REQOPT(opt, ifo->requestmask6, ifo->nomask6)) + continue; + n_options++; + len += sizeof(o.len); } if (dhcp6_findselfsla(ifp)) { n_options++; @@ -1037,7 +1024,8 @@ dhcp6_makemessage(struct interface *ifp) #ifdef AUTH if ((ifo->auth.options & DHCPCD_AUTH_SENDREQUIRE) != - DHCPCD_AUTH_SENDREQUIRE) + DHCPCD_AUTH_SENDREQUIRE && + !has_option_mask(ifo->nomask6, D6_OPTION_RECONF_ACCEPT)) COPYIN1(D6_OPTION_RECONF_ACCEPT, 0); #endif @@ -1060,34 +1048,26 @@ dhcp6_makemessage(struct interface *ifp) if (n < ifo->dhcp6_override_len) continue; #endif - if (!(opt->type & OT_NOREQ) && - (opt->type & OT_REQUEST || - has_option_mask(ifo->requestmask6, - opt->option))) - { - o.code = htons((uint16_t)opt->option); - memcpy(p, &o.code, sizeof(o.code)); - p += sizeof(o.code); - o.len = (uint16_t) - (o.len + sizeof(o.code)); - } + if (!DHC_REQOPT(opt, ifo->requestmask6, + ifo->nomask6)) + continue; + o.code = htons((uint16_t)opt->option); + memcpy(p, &o.code, sizeof(o.code)); + p += sizeof(o.code); + o.len = (uint16_t)(o.len + sizeof(o.code)); } #ifndef SMALL for (l = 0, opt = ifo->dhcp6_override; l < ifo->dhcp6_override_len; l++, opt++) { - if (!(opt->type & OT_NOREQ) && - (opt->type & OT_REQUEST || - has_option_mask(ifo->requestmask6, - opt->option))) - { - o.code = htons((uint16_t)opt->option); - memcpy(p, &o.code, sizeof(o.code)); - p += sizeof(o.code); - o.len = (uint16_t) - (o.len + sizeof(o.code)); - } + if (!DHC_REQOPT(opt, ifo->requestmask6, + ifo->nomask6)) + continue; + o.code = htons((uint16_t)opt->option); + memcpy(p, &o.code, sizeof(o.code)); + p += sizeof(o.code); + o.len = (uint16_t)(o.len + sizeof(o.code)); } if (dhcp6_findselfsla(ifp)) { o.code = htons(D6_OPTION_PD_EXCLUDE); @@ -3008,7 +2988,9 @@ dhcp6_bind(struct interface *ifp, const char *op, const char *sfrom) TAILQ_FOREACH(ia, &state->addrs, next) { if (ia->flags & IPV6_AF_STALE) continue; - if (ia->prefix_vltime <= state->renew) + if (!(state->renew == ND6_INFINITE_LIFETIME && + ia->prefix_vltime == ND6_INFINITE_LIFETIME) + && ia->prefix_vltime <= state->renew) logwarnx( "%s: %s will expire before renewal", ifp->name, ia->saddr); @@ -3152,6 +3134,8 @@ dhcp6_bind(struct interface *ifp, const char *op, const char *sfrom) if (state->state == DH6S_INFORMED) lognewinfo("%s: refresh in %"PRIu32" seconds", ifp->name, state->renew); + else if (state->renew == ND6_INFINITE_LIFETIME) + lognewinfo("%s: leased for infinity", ifp->name); else if (state->renew || state->rebind) lognewinfo("%s: renew in %"PRIu32", " "rebind in %"PRIu32", " diff --git a/external/bsd/dhcpcd/dist/src/dhcpcd-definitions-small.conf b/external/bsd/dhcpcd/dist/src/dhcpcd-definitions-small.conf deleted file mode 100644 index 17873d7eb1d..00000000000 --- a/external/bsd/dhcpcd/dist/src/dhcpcd-definitions-small.conf +++ /dev/null @@ -1,126 +0,0 @@ -# Copyright (c) 2006-2017 Roy Marples -# All rights reserved - -# Bare essentials for automatic IP configuration - -############################################################################## -# DHCP RFC2132 options unless otheriwse stated -define 1 request ipaddress subnet_mask -# RFC3442 states that the CSR has to come before all other routes -# For completeness we also specify static routes then routers -define 121 rfc3442 classless_static_routes -# Option 249 is an IANA assigned private number used by Windows DHCP servers -# to provide the exact same information as option 121, classless static routes -define 249 rfc3442 ms_classless_static_routes -define 33 request array ipaddress static_routes -define 3 request array ipaddress routers -define 6 array ipaddress domain_name_servers -define 12 dname host_name -define 15 array dname domain_name -define 26 uint16 interface_mtu -define 28 request ipaddress broadcast_address -define 50 ipaddress dhcp_requested_address -define 51 request uint32 dhcp_lease_time -define 52 byte dhcp_option_overload -define 53 byte dhcp_message_type -define 54 ipaddress dhcp_server_identifier -define 55 array byte dhcp_parameter_request_list -define 56 string dhcp_message -define 57 uint16 dhcp_max_message_size -define 58 request uint32 dhcp_renewal_time -define 59 request uint32 dhcp_rebinding_time -define 60 string vendor_class_identifier -define 61 binhex dhcp_client_identifier - -# DHCP Rapid Commit, RFC4039 -define 80 norequest flag rapid_commit - -# DHCP Fully Qualified Domain Name, RFC4702 -define 81 embed fqdn -embed bitflags=0000NEOS flags -embed byte rcode1 -embed byte rcode2 -# dhcpcd always sets the E bit which means the fqdn itself is always -# RFC1035 encoded. -# The server MUST use the encoding as specified by the client as noted -# in RFC4702 Section 2.1. -embed optional domain fqdn - -# DHCP Domain Search, RFC3397 -define 119 array domain domain_search - -############################################################################## -# ND6 options, RFC4861 -definend 1 binhex source_address -definend 2 binhex target_address - -definend 3 index embed prefix_information -embed byte length -embed bitflags=LA flags -embed uint32 vltime -embed uint32 pltime -embed uint32 reserved -embed array ip6address prefix - -# option 4 is only for Redirect messages - -definend 5 embed mtu -embed uint16 reserved -embed uint32 mtu - -# ND6 options, RFC6101 -definend 25 index embed rdnss -embed uint16 reserved -embed uint32 lifetime -embed array ip6address servers - -definend 31 index embed dnssl -embed uint16 reserved -embed uint32 lifetime -embed domain search - -############################################################################## -# DHCPv6 options, RFC3315 -define6 1 binhex client_id -define6 2 binhex server_id - -define6 3 norequest index embed ia_na -embed binhex:4 iaid -embed uint32 t1 -embed uint32 t2 -encap 5 option -encap 13 option - -define6 4 norequest index embed ia_ta -embed uint32 iaid -encap 5 option -encap 13 option - -define6 5 norequest index embed ia_addr -embed ip6address ia_addr -embed uint32 pltime -embed uint32 vltime -encap 13 option - -define6 12 ip6address unicast - -define6 13 norequest embed status_code -embed uint16 status_code -embed optional string message - -define6 18 binhex interface_id -define6 19 byte reconfigure_msg -define6 20 flag reconfigure_accept - -# DHCPv6 DNS Configuration Options, RFC3646 -define6 23 array ip6address name_servers -define6 24 array domain domain_search - -# DHCPv6 Fully Qualified Domain Name, RFC4704 -define6 39 embed fqdn -embed bitflags=00000NOS flags -embed optional domain fqdn - -# DHCPv6 SOL_MAX_RT, RFC7083 -define6 82 request uint32 sol_max_rt -define6 83 request uint32 inf_max_rt diff --git a/external/bsd/dhcpcd/dist/src/dhcpcd-definitions.conf b/external/bsd/dhcpcd/dist/src/dhcpcd-definitions.conf deleted file mode 100644 index e0ab2b79f2e..00000000000 --- a/external/bsd/dhcpcd/dist/src/dhcpcd-definitions.conf +++ /dev/null @@ -1,626 +0,0 @@ -# Copyright (c) 2006-2017 Roy Marples -# All rights reserved - -# DHCP option definitions for dhcpcd(8) -# These are used to translate DHCP options into shell variables -# for use in dhcpcd-run-hooks(8) -# See dhcpcd.conf(5) for details - -############################################################################## -# DHCP RFC2132 options unless otheriwse stated -define 1 request ipaddress subnet_mask -# RFC3442 states that the CSR has to come before all other routes -# For completeness we also specify static routes then routers -define 121 rfc3442 classless_static_routes -# Option 249 is an IANA assigned private number used by Windows DHCP servers -# to provide the exact same information as option 121, classless static routes -define 249 rfc3442 ms_classless_static_routes -define 33 request array ipaddress static_routes -define 3 request array ipaddress routers -define 2 uint32 time_offset -define 4 array ipaddress time_servers -define 5 array ipaddress ien116_name_servers -define 6 array ipaddress domain_name_servers -define 7 array ipaddress log_servers -define 8 array ipaddress cookie_servers -define 9 array ipaddress lpr_servers -define 10 array ipaddress impress_servers -define 11 array ipaddress resource_location_servers -define 12 dname host_name -define 13 uint16 boot_size -define 14 string merit_dump -# Technically domain_name is not an array, but many servers expect clients -# to treat it as one. -define 15 array dname domain_name -define 16 ipaddress swap_server -define 17 string root_path -define 18 string extensions_path -define 19 byte ip_forwarding -define 20 byte non_local_source_routing -define 21 array ipaddress policy_filter -define 22 uint16 max_dgram_reassembly -define 23 byte default_ip_ttl -define 24 uint32 path_mtu_aging_timeout -define 25 array uint16 path_mtu_plateau_table -define 26 uint16 interface_mtu -define 27 byte all_subnets_local -define 28 request ipaddress broadcast_address -define 29 byte perform_mask_discovery -define 30 byte mask_supplier -define 31 byte router_discovery -define 32 ipaddress router_solicitation_address -define 34 byte trailer_encapsulation -define 35 uint32 arp_cache_timeout -define 36 uint16 ieee802_3_encapsulation -define 37 byte default_tcp_ttl -define 38 uint32 tcp_keepalive_interval -define 39 byte tcp_keepalive_garbage -define 40 string nis_domain -define 41 array ipaddress nis_servers -define 42 array ipaddress ntp_servers -define 43 binhex vendor_encapsulated_options -define 44 array ipaddress netbios_name_servers -define 45 ipaddress netbios_dd_server -define 46 byte netbios_node_type -define 47 string netbios_scope -define 48 array ipaddress font_servers -define 49 array ipaddress x_display_manager -define 50 ipaddress dhcp_requested_address -define 51 request uint32 dhcp_lease_time -define 52 byte dhcp_option_overload -define 53 byte dhcp_message_type -define 54 ipaddress dhcp_server_identifier -define 55 array byte dhcp_parameter_request_list -define 56 string dhcp_message -define 57 uint16 dhcp_max_message_size -define 58 request uint32 dhcp_renewal_time -define 59 request uint32 dhcp_rebinding_time -define 60 string vendor_class_identifier -define 61 binhex dhcp_client_identifier -define 64 string nisplus_domain -define 65 array ipaddress nisplus_servers -define 66 dname tftp_server_name -define 67 string bootfile_name -define 68 array ipaddress mobile_ip_home_agent -define 69 array ipaddress smtp_server -define 70 array ipaddress pop_server -define 71 array ipaddress nntp_server -define 72 array ipaddress www_server -define 73 array ipaddress finger_server -define 74 array ipaddress irc_server -define 75 array ipaddress streettalk_server -define 76 array ipaddress streettalk_directory_assistance_server - -# DHCP User Class, RFC3004 -define 77 binhex user_class - -# DHCP SLP Directory Agent, RFC2610 -define 78 embed slp_agent -embed byte mandatory -embed array ipaddress address -define 79 embed slp_service -embed byte mandatory -embed ascii scope_list - -# DHCP Rapid Commit, RFC4039 -define 80 norequest flag rapid_commit - -# DHCP Fully Qualified Domain Name, RFC4702 -define 81 embed fqdn -embed bitflags=0000NEOS flags -embed byte rcode1 -embed byte rcode2 -# dhcpcd always sets the E bit which means the fqdn itself is always -# RFC1035 encoded. -# The server MUST use the encoding as specified by the client as noted -# in RFC4702 Section 2.1. -embed optional domain fqdn - -# Option 82 is for Relay Agents and DHCP servers - -# iSNS, RFC4174 -define 83 embed isns -embed byte reserved1 -embed bitflags=00000SAE functions -embed byte reserved2 -embed bitflags=00fFsSCE dd -embed byte reserved3 -embed bitflags=0000DMHE admin -embed uint16 reserved4 -embed byte reserved5 -embed bitflags=0TXPAMSE server_security -embed array ipaddress servers - -# Option 84 are unused, RFC3679 - -# DHCP Novell Directory Services, RFC2241 -define 85 array ipaddress nds_servers -define 86 raw nds_tree_name -define 87 raw nds_context - -# DHCP Broadcast and Multicast Control Server, RFC4280 -define 88 array domain bcms_controller_names -define 89 array ipaddress bcms_controller_address - -# DHCP Authentication, RFC3118 -define 90 embed auth -embed byte protocol -embed byte algorithm -embed byte rdm -embed binhex:8 replay -embed binhex information - -# DHCP Leasequery, RFC4388 -define 91 uint32 client_last_transaction_time -define 92 array ipaddress associated_ip - -# DHCP Options for Intel Preboot eXecution Environent (PXE), RFC4578 -# Options 93, 94 and 97 are used but of no use to dhcpcd - -# Option 95 used by Apple but never published RFC3679 -# Option 96 is unused, RFC3679 - -# DHCP The Open Group's User Authentication Protocol, RFC2485 -define 98 string uap_servers - -# DHCP Civic Addresses Configuration Information, RFC4776 -define 99 encap geoconf_civic -embed byte what -embed uint16 country_code -# The rest of this option is not supported - -# DHCP Timezone, RFC4883 -define 100 string posix_timezone -define 101 string tzdb_timezone - -# Options 102-115 are unused, RFC3679 - -# DHCP Auto-Configuration, RFC2563 -define 116 byte auto_configure - -# DHCP Name Service Search, RFC2937 -define 117 array uint16 name_service_search - -# DHCP Subnet Selection, RFC3011 -define 118 ipaddress subnet_selection - -# DHCP Domain Search, RFC3397 -define 119 array domain domain_search - -# DHCP Session Initiated Protocol Servers, RFC3361 -define 120 rfc3361 sip_server - -# Option 121 is defined at the top of this file - -# DHCP CableLabs Client, RFC3495 -define 122 encap tsp -encap 1 ipaddress dhcp_server -encap 2 ipaddress dhcp_secondary_server -encap 3 rfc3361 provisioning_server -encap 4 embed as_req_as_rep_backoff -embed uint32 nominal -embed uint32 maximum -embed uint32 retry -encap 5 embed ap_req_ap_rep_backoff -embed uint32 nominal -embed uint32 maximum -embed uint32 retry -encap 6 domain kerberos_realm -encap 7 byte ticket_granting_server_utilization -encap 8 byte provisioning_timer - -# DHCP Coordinate LCI, RFC6225 -# We have no means of expressing 6 bit lengths -define 123 binhex geoconf - -# DHCP Vendor-Identifying Vendor Options, RFC3925 -define 124 binhex vivco -define 125 embed vivso -embed uint32 enterprise_number -# Vendor options are shared between DHCP/DHCPv6 -# Their code is matched to the enterprise number defined above -# see the end of this file for an example - -# Options 126 and 127 are unused, RFC3679 - -# DHCP Options for Intel Preboot eXecution Environent (PXE), RFC4578 -# Options 128-135 are used but of no use to dhcpcd - -# DHCP PANA Authentication Agent, RFC5192 -define 136 array ipaddress pana_agent - -# DHCP Lost Server, RFC5223 -define 137 domain lost_server - -# DHCP CAPWAP, RFC5417 -define 138 array ipaddress capwap_ac - -# DHCP Mobility Services, RFC5678 -define 139 encap mos_ip -encap 1 array ipaddress is -encap 2 array ipaddress cs -encap 3 array ipaddress es -define 140 encap mos_domain -encap 1 domain is -encap 2 domain cs -encap 3 domain es - -# DHCP SIP UA, RFC6011 -define 141 array domain sip_ua_cs_list - -# DHCP ANDSF, RFC6153 -define 142 array ipaddress andsf -define 143 array ip6address andsf6 - -# DHCP Coordinate LCI, RFC6225 -# We have no means of expressing 6 bit lengths -define 144 binhex geoloc - -# DHCP FORCERENEW Nonce Capability, RFC6704 -define 145 array byte forcerenew_nonce_capable - -# DHCP RDNSS Selection for MIF Nodes, RFC6731 -define 146 embed rdnss_selection -embed byte prf -embed ipaddress primary -embed ipaddress secondary -embed array domain domains - -# Options 147, 148 and 149 are unused, RFC3942 - -# DHCP TFTP Server Address, RFC5859 -define 150 array ipaddress tftp_servers - -# DHCP MUD URL, draft-ietf-opsawg-mud -define 161 string mudurl - -# Apart from 161... -# Options 151-157 are used for Lease Query, RFC6926 and not for dhcpcd -# Options 158-174 are unused, RFC3942 - -# Options 175-177 are tentativel assigned for Etherboot -# Options 178-207 are unused, RFC3942 - -# DHCP PXELINUX, RFC5071 -define 208 binhex pxelinux_magic -define 209 string config_file -define 210 string path_prefix -define 211 uint32 reboot_time - -# DHCP IPv6 Rapid Deployment on IPv4 Infrastructures, RFC5969 -define 212 embed sixrd -embed byte mask_len -embed byte prefix_len -embed ip6address prefix -embed array ipaddress brip_address - -# DHCP Access Network Domain Name, RFC5986 -define 213 domain access_domain - -# Options 214-219 are unused, RFC3942 - -# DHCP Subnet Allocation, RFC6656 -# Option 220 looks specific to Cisco hardware. - -# DHCP Virtual Subnet Selection, RFC6607 -define 221 encap vss -encap 0 string nvt -encap 1 binhex vpn_id -encap 255 flag global - -# Options 222 and 223 are unused, RFC3942 - -# Options 224-254 are reserved for Private Use -# However, an expired RFC for Web Proxy Auto Discovery Protocol does define -# Option 252 which is commonly used by major browsers. -# Apparently the code was assigned by agreement of the DHC working group chair. -define 252 string wpad_url - -# Option 255 End - -############################################################################## -# ND6 options, RFC4861 -definend 1 binhex source_address -definend 2 binhex target_address - -definend 3 index embed prefix_information -embed byte length -embed bitflags=LA flags -embed uint32 vltime -embed uint32 pltime -embed uint32 reserved -embed array ip6address prefix - -# option 4 is only for Redirect messages - -definend 5 embed mtu -embed uint16 reserved -embed uint32 mtu - -# ND6 options, RFC6101 -definend 25 index embed rdnss -embed uint16 reserved -embed uint32 lifetime -embed array ip6address servers - -definend 31 index embed dnssl -embed uint16 reserved -embed uint32 lifetime -embed domain search - -############################################################################## -# DHCPv6 options, RFC3315 -define6 1 binhex client_id -define6 2 binhex server_id - -define6 3 norequest index embed ia_na -embed binhex:4 iaid -embed uint32 t1 -embed uint32 t2 -encap 5 option -encap 13 option - -define6 4 norequest index embed ia_ta -embed uint32 iaid -encap 5 option -encap 13 option - -define6 5 norequest index embed ia_addr -embed ip6address ia_addr -embed uint32 pltime -embed uint32 vltime -encap 13 option - -define6 6 array uint16 option_request -define6 7 byte preference -define6 8 uint16 elased_time -define6 9 binhex dhcp_relay_msg - -# Option 10 is unused - -define6 11 embed auth -embed byte protocol -embed byte algorithm -embed byte rdm -embed binhex:8 replay -embed binhex information - -define6 12 ip6address unicast - -define6 13 norequest embed status_code -embed uint16 status_code -embed optional string message - -define6 14 norequest flag rapid_commit -define6 15 binhex user_class - -define6 16 binhex vivco -define6 17 embed vivso -embed uint32 enterprise_number -# Vendor options are shared between DHCP/DHCPv6 -# Their code is matched to the enterprise number defined above -# See the end of this file for an example - -define6 18 binhex interface_id -define6 19 byte reconfigure_msg -define6 20 flag reconfigure_accept - -# DHCPv6 Session Initiation Protocol Options, RFC3319 -define6 21 array domain sip_servers_names -define6 22 array ip6address sip_servers_addresses - -# DHCPv6 DNS Configuration Options, RFC3646 -define6 23 array ip6address name_servers -define6 24 array domain domain_search - -# DHCPv6 Prefix Options, RFC6603 -define6 25 norequest index embed ia_pd -embed binhex:4 iaid -embed uint32 t1 -embed uint32 t2 -encap 26 option -define6 26 index embed prefix -embed uint32 pltime -embed uint32 vltime -embed byte length -embed ip6address prefix -encap 13 option -encap 67 option - -# DHCPv6 Network Information Service Options, RFC3898 -define6 27 array ip6address nis_servers -define6 28 array ip6address nisp_servers -define6 29 string nis_domain_name -define6 30 string nisp_domain_name - -# DHCPv6 Simple Network Time Protocol Servers Option, RFC4075 -define6 31 array ip6address sntp_servers - -# DHCPv6 Information Refresh Time, RFC4242 -define6 32 uint32 info_refresh_time - -# DHCPv6 Broadcast and Multicast Control Server, RFC4280 -define6 33 array domain bcms_server_d -define6 34 array ip6address bcms_server_a - -# DHCP Civic Addresses Configuration Information, RFC4776 -define6 36 encap geoconf_civic -embed byte what -embed uint16 country_code -# The rest of this option is not supported - -# DHCP Relay Agent Remote-ID, RFC4649 -define6 37 embed remote_id -embed uint32 enterprise_number -embed binhex remote_id - -# DHCP Relay Agent Subscriber-ID, RFC4580 -define6 38 binhex subscriber_id - -# DHCPv6 Fully Qualified Domain Name, RFC4704 -define6 39 embed fqdn -embed bitflags=00000NOS flags -embed optional domain fqdn - -# DHCPv6 PANA Authentication Agnet, RC5192 -define6 40 array ip6address pana_agent - -# DHCPv6 Timezone options, RFC4883 -define6 41 string posix_timezone -define6 42 string tzdb_timezone - -# DHCPv6 Relay Agent Echo Request -define6 43 array uint16 ero - -# Options 44-48 are used for Lease Query, RFC5007 and not for dhcpcd - -# DHCPv6 Home Info Discovery in MIPv6, RFC6610 -define6 49 domain mip6_hnidf -define6 50 encap mip6_vdinf -encap 71 option -encap 72 option -encap 73 option - -# DHCPv6 Lost Server, RFC5223 -define6 51 domain lost_server - -# DHCPv6 CAPWAP, RFC5417 -define6 52 array ip6address capwap_ac - -# DHCPv6 Relay-ID, RFC5460 -define6 53 binhex relay_id - -# DHCP Mobility Services, RFC5678 -define6 54 encap mos_ip -encap 1 array ip6address is -encap 2 array ip6address cs -encap 3 array ip6address es -define6 55 encap mos_domain -encap 1 domain is -encap 2 domain cs -encap 3 domain es - -# DHCPv6 Network Time Protocol Server, RFC5908 -define6 56 encap ntp_server -encap 1 ip6address addr -encap 2 ip6address mcast_addr -encap 3 ip6address fqdn - -# DHCPv6 LIS Discovery, RFC5986 -define6 57 domain access_domain - -# DHCPv6 SIP UA, RFC6011 -define6 58 array domain sip_ua_cs_list - -# DHCPv6 Network Boot, RFC5970 -define6 59 string bootfile_url -# We presently cannot decode bootfile_param -define6 60 binhex bootfile_param -define6 61 array uint16 architecture_types -define6 62 embed nii -embed byte type -embed byte major -embed byte minor - -# DHCPv6 Coordinate LCI, RFC6225 -# We have no means of expressing 6 bit lengths -define6 63 binhex geoloc - -# DHCPv6 AFTR-Name, RFC6334 -define6 64 domain aftr_name - -# DHCPv6 Prefix Exclude Option, RFC6603 -define6 67 embed pd_exclude -embed byte prefix_len -embed binhex subnetID - -# DHCPv6 Home Info Discovery in MIPv6, RFC6610 -define6 69 encap mip6_idinf -encap 71 option -encap 72 option -encap 73 option -define6 70 encap mip6_udinf -encap 71 option -encap 72 option -encap 73 option -define6 71 embed mip6_hnp -embed byte prefix_len -embed ip6address prefix -define6 72 ip6address mip6_haa -define6 73 domain mip6_haf - -# DHCPv6 RDNSS Selection for MIF Nodes, RFC6731 -define6 74 embed rdnss_selection -embed ip6address server -embed byte prf -embed array domain domains - -# DHCPv6 Kerberos, RFC6784 -define6 75 string krb_principal_name -define6 76 string krb_realm_name -define6 78 embed krb_kdc -embed uint16 priority -embed uint16 weight -embed byte transport_type -embed uint16 port -embed ip6address address -embed string realm_name - -# DHCPv6 Client Link-Layer Address, RFC6939 -# Section 7 states that clients MUST ignore the option 79 - -# DHCPv6 Relay-Triggered Reconfiguraion, RFC6977 -define6 80 ip6address link_address - -# DHCPv6 Radius, RFC7037 -# Section 7 states that clients MUST ignore the option 81 - -# DHCPv6 SOL_MAX_RT, RFC7083 -define6 82 request uint32 sol_max_rt -define6 83 request uint32 inf_max_rt - -# DHCPv6 Softwire Address and Port-Mapped Clients, RFC7598 -define6 89 embed s46_rule -embed bitflags=0000000F flags -embed byte ea_len -embed byte prefix4_len -embed ipaddress ipv4_prefix -embed ip6address ipv6_prefix -define6 90 ip6address s64_br -define6 91 embed s46_dmr -embed byte prefix_len -embed binhex prefix -define6 92 embed s46_v4v6bind -embed ipaddress ipv4_address -embed byte ipv6_prefix_len -embed binhex ipv6_prefix_and_options -# Cannot decode options after variable length address ... -#encap 93 option -define6 93 embed s46_portparams -embed byte offset -embed byte psid_len -embed uint16 psid -define6 94 embed s46_cont_mape -encap 89 option -encap 90 option -define6 95 embed s46_cont_mapt -encap 89 option -encap 91 option -define6 96 embed s46_cont_lw -encap 90 option -encap 92 option - -# DHCPv6 Address Selection Policy -# Currently not supported - -# DHCPv6 MUD URL, draft-ietf-opsawg-mud -define6 112 string mudurl - -# Options 86-65535 are unasssinged - -############################################################################## -# Vendor-Identifying Vendor Options -# An example: -#vendopt 12345 encap frobozzco -#encap 1 string maze_location -#encap 2 byte grue_probability diff --git a/external/bsd/dhcpcd/dist/src/dhcpcd-embedded.c b/external/bsd/dhcpcd/dist/src/dhcpcd-embedded.c new file mode 100644 index 00000000000..68efae12157 --- /dev/null +++ b/external/bsd/dhcpcd/dist/src/dhcpcd-embedded.c @@ -0,0 +1,490 @@ +/* + * DO NOT EDIT! + * Automatically generated from dhcpcd-embedded.conf + * Ths allows us to simply generate DHCP structure without any C programming. + */ + +/* + * dhcpcd - DHCP client daemon + * Copyright (c) 2006-2019 Roy Marples <roy@marples.name> + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include <unistd.h> + +const char * const dhcpcd_embedded_conf[] = { +#ifdef SMALL +"define 1 request ipaddress subnet_mask", +"define 121 rfc3442 classless_static_routes", +"define 249 rfc3442 ms_classless_static_routes", +"define 33 request array ipaddress static_routes", +"define 3 request array ipaddress routers", +"define 6 array ipaddress domain_name_servers", +"define 12 dname host_name", +"define 15 array dname domain_name", +"define 26 uint16 interface_mtu", +"define 28 request ipaddress broadcast_address", +"define 50 ipaddress dhcp_requested_address", +"define 51 request uint32 dhcp_lease_time", +"define 52 byte dhcp_option_overload", +"define 53 byte dhcp_message_type", +"define 54 ipaddress dhcp_server_identifier", +"define 55 array byte dhcp_parameter_request_list", +"define 56 string dhcp_message", +"define 57 uint16 dhcp_max_message_size", +"define 58 request uint32 dhcp_renewal_time", +"define 59 request uint32 dhcp_rebinding_time", +"define 60 string vendor_class_identifier", +"define 61 binhex dhcp_client_identifier", +"define 80 norequest flag rapid_commit", +"define 81 embed fqdn", +"embed bitflags=0000NEOS flags", +"embed byte rcode1", +"embed byte rcode2", +"embed optional domain fqdn", +"define 119 array domain domain_search", +"definend 1 binhex source_address", +"definend 2 binhex target_address", +"definend 3 index embed prefix_information", +"embed byte length", +"embed bitflags=LA flags", +"embed uint32 vltime", +"embed uint32 pltime", +"embed uint32 reserved", +"embed array ip6address prefix", +"definend 5 embed mtu", +"embed uint16 reserved", +"embed uint32 mtu", +"definend 25 index embed rdnss", +"embed uint16 reserved", +"embed uint32 lifetime", +"embed array ip6address servers", +"definend 31 index embed dnssl", +"embed uint16 reserved", +"embed uint32 lifetime", +"embed domain search", +"define6 1 binhex client_id", +"define6 2 binhex server_id", +"define6 3 norequest index embed ia_na", +"embed binhex:4 iaid", +"embed uint32 t1", +"embed uint32 t2", +"encap 5 option", +"encap 13 option", +"define6 4 norequest index embed ia_ta", +"embed uint32 iaid", +"encap 5 option", +"encap 13 option", +"define6 5 norequest index embed ia_addr", +"embed ip6address ia_addr", +"embed uint32 pltime", +"embed uint32 vltime", +"encap 13 option", +"define6 12 ip6address unicast", +"define6 13 norequest embed status_code", +"embed uint16 status_code", +"embed optional string message", +"define6 18 binhex interface_id", +"define6 19 byte reconfigure_msg", +"define6 20 flag reconfigure_accept", +"define6 23 array ip6address name_servers", +"define6 24 array domain domain_search", +"define6 39 embed fqdn", +"embed bitflags=00000NOS flags", +"embed optional domain fqdn", +"define6 82 request uint32 sol_max_rt", +"define6 83 request uint32 inf_max_rt", +#else +"define 1 request ipaddress subnet_mask", +"define 121 rfc3442 classless_static_routes", +"define 249 rfc3442 ms_classless_static_routes", +"define 33 request array ipaddress static_routes", +"define 3 request array ipaddress routers", +"define 2 uint32 time_offset", +"define 4 array ipaddress time_servers", +"define 5 array ipaddress ien116_name_servers", +"define 6 array ipaddress domain_name_servers", +"define 7 array ipaddress log_servers", +"define 8 array ipaddress cookie_servers", +"define 9 array ipaddress lpr_servers", +"define 10 array ipaddress impress_servers", +"define 11 array ipaddress resource_location_servers", +"define 12 dname host_name", +"define 13 uint16 boot_size", +"define 14 string merit_dump", +"define 15 array dname domain_name", +"define 16 ipaddress swap_server", +"define 17 string root_path", +"define 18 string extensions_path", +"define 19 byte ip_forwarding", +"define 20 byte non_local_source_routing", +"define 21 array ipaddress policy_filter", +"define 22 uint16 max_dgram_reassembly", +"define 23 byte default_ip_ttl", +"define 24 uint32 path_mtu_aging_timeout", +"define 25 array uint16 path_mtu_plateau_table", +"define 26 uint16 interface_mtu", +"define 27 byte all_subnets_local", +"define 28 request ipaddress broadcast_address", +"define 29 byte perform_mask_discovery", +"define 30 byte mask_supplier", +"define 31 byte router_discovery", +"define 32 ipaddress router_solicitation_address", +"define 34 byte trailer_encapsulation", +"define 35 uint32 arp_cache_timeout", +"define 36 uint16 ieee802_3_encapsulation", +"define 37 byte default_tcp_ttl", +"define 38 uint32 tcp_keepalive_interval", +"define 39 byte tcp_keepalive_garbage", +"define 40 string nis_domain", +"define 41 array ipaddress nis_servers", +"define 42 array ipaddress ntp_servers", +"define 43 binhex vendor_encapsulated_options", +"define 44 array ipaddress netbios_name_servers", +"define 45 ipaddress netbios_dd_server", +"define 46 byte netbios_node_type", +"define 47 string netbios_scope", +"define 48 array ipaddress font_servers", +"define 49 array ipaddress x_display_manager", +"define 50 ipaddress dhcp_requested_address", +"define 51 request uint32 dhcp_lease_time", +"define 52 byte dhcp_option_overload", +"define 53 byte dhcp_message_type", +"define 54 ipaddress dhcp_server_identifier", +"define 55 array byte dhcp_parameter_request_list", +"define 56 string dhcp_message", +"define 57 uint16 dhcp_max_message_size", +"define 58 request uint32 dhcp_renewal_time", +"define 59 request uint32 dhcp_rebinding_time", +"define 60 string vendor_class_identifier", +"define 61 binhex dhcp_client_identifier", +"define 64 string nisplus_domain", +"define 65 array ipaddress nisplus_servers", +"define 66 dname tftp_server_name", +"define 67 string bootfile_name", +"define 68 array ipaddress mobile_ip_home_agent", +"define 69 array ipaddress smtp_server", +"define 70 array ipaddress pop_server", +"define 71 array ipaddress nntp_server", +"define 72 array ipaddress www_server", +"define 73 array ipaddress finger_server", +"define 74 array ipaddress irc_server", +"define 75 array ipaddress streettalk_server", +"define 76 array ipaddress streettalk_directory_assistance_server", +"define 77 binhex user_class", +"define 78 embed slp_agent", +"embed byte mandatory", +"embed array ipaddress address", +"define 79 embed slp_service", +"embed byte mandatory", +"embed ascii scope_list", +"define 80 norequest flag rapid_commit", +"define 81 embed fqdn", +"embed bitflags=0000NEOS flags", +"embed byte rcode1", +"embed byte rcode2", +"embed optional domain fqdn", +"define 83 embed isns", +"embed byte reserved1", +"embed bitflags=00000SAE functions", +"embed byte reserved2", +"embed bitflags=00fFsSCE dd", +"embed byte reserved3", +"embed bitflags=0000DMHE admin", +"embed uint16 reserved4", +"embed byte reserved5", +"embed bitflags=0TXPAMSE server_security", +"embed array ipaddress servers", +"define 85 array ipaddress nds_servers", +"define 86 raw nds_tree_name", +"define 87 raw nds_context", +"define 88 array domain bcms_controller_names", +"define 89 array ipaddress bcms_controller_address", +"define 90 embed auth", +"embed byte protocol", +"embed byte algorithm", +"embed byte rdm", +"embed binhex:8 replay", +"embed binhex information", +"define 91 uint32 client_last_transaction_time", +"define 92 array ipaddress associated_ip", +"define 98 string uap_servers", +"define 99 encap geoconf_civic", +"embed byte what", +"embed uint16 country_code", +"define 100 string posix_timezone", +"define 101 string tzdb_timezone", +"define 116 byte auto_configure", +"define 117 array uint16 name_service_search", +"define 118 ipaddress subnet_selection", +"define 119 array domain domain_search", +"define 120 rfc3361 sip_server", +"define 122 encap tsp", +"encap 1 ipaddress dhcp_server", +"encap 2 ipaddress dhcp_secondary_server", +"encap 3 rfc3361 provisioning_server", +"encap 4 embed as_req_as_rep_backoff", +"embed uint32 nominal", +"embed uint32 maximum", +"embed uint32 retry", +"encap 5 embed ap_req_ap_rep_backoff", +"embed uint32 nominal", +"embed uint32 maximum", +"embed uint32 retry", +"encap 6 domain kerberos_realm", +"encap 7 byte ticket_granting_server_utilization", +"encap 8 byte provisioning_timer", +"define 123 binhex geoconf", +"define 124 binhex vivco", +"define 125 embed vivso", +"embed uint32 enterprise_number", +"define 136 array ipaddress pana_agent", +"define 137 domain lost_server", +"define 138 array ipaddress capwap_ac", +"define 139 encap mos_ip", +"encap 1 array ipaddress is", +"encap 2 array ipaddress cs", +"encap 3 array ipaddress es", +"define 140 encap mos_domain", +"encap 1 domain is", +"encap 2 domain cs", +"encap 3 domain es", +"define 141 array domain sip_ua_cs_list", +"define 142 array ipaddress andsf", +"define 143 array ip6address andsf6", +"define 144 binhex geoloc", +"define 145 array byte forcerenew_nonce_capable", +"define 146 embed rdnss_selection", +"embed byte prf", +"embed ipaddress primary", +"embed ipaddress secondary", +"embed array domain domains", +"define 150 array ipaddress tftp_servers", +"define 161 string mudurl", +"define 208 binhex pxelinux_magic", +"define 209 string config_file", +"define 210 string path_prefix", +"define 211 uint32 reboot_time", +"define 212 embed sixrd", +"embed byte mask_len", +"embed byte prefix_len", +"embed ip6address prefix", +"embed array ipaddress brip_address", +"define 213 domain access_domain", +"define 221 encap vss", +"encap 0 string nvt", +"encap 1 binhex vpn_id", +"encap 255 flag global", +"define 252 string wpad_url", +"definend 1 binhex source_address", +"definend 2 binhex target_address", +"definend 3 index embed prefix_information", +"embed byte length", +"embed bitflags=LA flags", +"embed uint32 vltime", +"embed uint32 pltime", +"embed uint32 reserved", +"embed array ip6address prefix", +"definend 5 embed mtu", +"embed uint16 reserved", +"embed uint32 mtu", +"definend 25 index embed rdnss", +"embed uint16 reserved", +"embed uint32 lifetime", +"embed array ip6address servers", +"definend 31 index embed dnssl", +"embed uint16 reserved", +"embed uint32 lifetime", +"embed domain search", +"define6 1 binhex client_id", +"define6 2 binhex server_id", +"define6 3 norequest index embed ia_na", +"embed binhex:4 iaid", +"embed uint32 t1", +"embed uint32 t2", +"encap 5 option", +"encap 13 option", +"define6 4 norequest index embed ia_ta", +"embed uint32 iaid", +"encap 5 option", +"encap 13 option", +"define6 5 norequest index embed ia_addr", +"embed ip6address ia_addr", +"embed uint32 pltime", +"embed uint32 vltime", +"encap 13 option", +"define6 6 array uint16 option_request", +"define6 7 byte preference", +"define6 8 uint16 elased_time", +"define6 9 binhex dhcp_relay_msg", +"define6 11 embed auth", +"embed byte protocol", +"embed byte algorithm", +"embed byte rdm", +"embed binhex:8 replay", +"embed binhex information", +"define6 12 ip6address unicast", +"define6 13 norequest embed status_code", +"embed uint16 status_code", +"embed optional string message", +"define6 14 norequest flag rapid_commit", +"define6 15 binhex user_class", +"define6 16 binhex vivco", +"define6 17 embed vivso", +"embed uint32 enterprise_number", +"define6 18 binhex interface_id", +"define6 19 byte reconfigure_msg", +"define6 20 flag reconfigure_accept", +"define6 21 array domain sip_servers_names", +"define6 22 array ip6address sip_servers_addresses", +"define6 23 array ip6address name_servers", +"define6 24 array domain domain_search", +"define6 25 norequest index embed ia_pd", +"embed binhex:4 iaid", +"embed uint32 t1", +"embed uint32 t2", +"encap 26 option", +"define6 26 index embed prefix", +"embed uint32 pltime", +"embed uint32 vltime", +"embed byte length", +"embed ip6address prefix", +"encap 13 option", +"encap 67 option", +"define6 27 array ip6address nis_servers", +"define6 28 array ip6address nisp_servers", +"define6 29 string nis_domain_name", +"define6 30 string nisp_domain_name", +"define6 31 array ip6address sntp_servers", +"define6 32 uint32 info_refresh_time", +"define6 33 array domain bcms_server_d", +"define6 34 array ip6address bcms_server_a", +"define6 36 encap geoconf_civic", +"embed byte what", +"embed uint16 country_code", +"define6 37 embed remote_id", +"embed uint32 enterprise_number", +"embed binhex remote_id", +"define6 38 binhex subscriber_id", +"define6 39 embed fqdn", +"embed bitflags=00000NOS flags", +"embed optional domain fqdn", +"define6 40 array ip6address pana_agent", +"define6 41 string posix_timezone", +"define6 42 string tzdb_timezone", +"define6 43 array uint16 ero", +"define6 49 domain mip6_hnidf", +"define6 50 encap mip6_vdinf", +"encap 71 option", +"encap 72 option", +"encap 73 option", +"define6 51 domain lost_server", +"define6 52 array ip6address capwap_ac", +"define6 53 binhex relay_id", +"define6 54 encap mos_ip", +"encap 1 array ip6address is", +"encap 2 array ip6address cs", +"encap 3 array ip6address es", +"define6 55 encap mos_domain", +"encap 1 domain is", +"encap 2 domain cs", +"encap 3 domain es", +"define6 56 encap ntp_server", +"encap 1 ip6address addr", +"encap 2 ip6address mcast_addr", +"encap 3 ip6address fqdn", +"define6 57 domain access_domain", +"define6 58 array domain sip_ua_cs_list", +"define6 59 string bootfile_url", +"define6 60 binhex bootfile_param", +"define6 61 array uint16 architecture_types", +"define6 62 embed nii", +"embed byte type", +"embed byte major", +"embed byte minor", +"define6 63 binhex geoloc", +"define6 64 domain aftr_name", +"define6 67 embed pd_exclude", +"embed byte prefix_len", +"embed binhex subnetID", +"define6 69 encap mip6_idinf", +"encap 71 option", +"encap 72 option", +"encap 73 option", +"define6 70 encap mip6_udinf", +"encap 71 option", +"encap 72 option", +"encap 73 option", +"define6 71 embed mip6_hnp", +"embed byte prefix_len", +"embed ip6address prefix", +"define6 72 ip6address mip6_haa", +"define6 73 domain mip6_haf", +"define6 74 embed rdnss_selection", +"embed ip6address server", +"embed byte prf", +"embed array domain domains", +"define6 75 string krb_principal_name", +"define6 76 string krb_realm_name", +"define6 78 embed krb_kdc", +"embed uint16 priority", +"embed uint16 weight", +"embed byte transport_type", +"embed uint16 port", +"embed ip6address address", +"embed string realm_name", +"define6 80 ip6address link_address", +"define6 82 request uint32 sol_max_rt", +"define6 83 request uint32 inf_max_rt", +"define6 89 embed s46_rule", +"embed bitflags=0000000F flags", +"embed byte ea_len", +"embed byte prefix4_len", +"embed ipaddress ipv4_prefix", +"embed ip6address ipv6_prefix", +"define6 90 ip6address s64_br", +"define6 91 embed s46_dmr", +"embed byte prefix_len", +"embed binhex prefix", +"define6 92 embed s46_v4v6bind", +"embed ipaddress ipv4_address", +"embed byte ipv6_prefix_len", +"embed binhex ipv6_prefix_and_options", +"define6 93 embed s46_portparams", +"embed byte offset", +"embed byte psid_len", +"embed uint16 psid", +"define6 94 embed s46_cont_mape", +"encap 89 option", +"encap 90 option", +"define6 95 embed s46_cont_mapt", +"encap 89 option", +"encap 91 option", +"define6 96 embed s46_cont_lw", +"encap 90 option", +"encap 92 option", +"define6 112 string mudurl", +#endif +NULL +}; diff --git a/external/bsd/dhcpcd/dist/src/dhcpcd-embedded.c.in b/external/bsd/dhcpcd/dist/src/dhcpcd-embedded.c.in deleted file mode 100644 index 9ac6da3bdcc..00000000000 --- a/external/bsd/dhcpcd/dist/src/dhcpcd-embedded.c.in +++ /dev/null @@ -1,36 +0,0 @@ -/* - * DO NOT EDIT! - * Automatically generated from dhcpcd-embedded.conf - * Ths allows us to simply generate DHCP structure without any C programming. - */ - -/* - * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2019 Roy Marples <roy@marples.name> - * 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. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. - */ - -#include <unistd.h> - -const char * const dhcpcd_embedded_conf[] = { diff --git a/external/bsd/dhcpcd/dist/src/dhcpcd-embedded.h.in b/external/bsd/dhcpcd/dist/src/dhcpcd-embedded.h index 883d53bdd2c..d904e4ad30c 100644 --- a/external/bsd/dhcpcd/dist/src/dhcpcd-embedded.h.in +++ b/external/bsd/dhcpcd/dist/src/dhcpcd-embedded.h @@ -25,8 +25,14 @@ * SUCH DAMAGE. */ -#define INITDEFINES @INITDEFINES@ -#define INITDEFINENDS @INITDEFINENDS@ -#define INITDEFINE6S @INITDEFINE6S@ +#ifdef SMALL +#define INITDEFINES 25 +#define INITDEFINENDS 6 +#define INITDEFINE6S 14 +#else +#define INITDEFINES 124 +#define INITDEFINENDS 6 +#define INITDEFINE6S 69 +#endif extern const char * const dhcpcd_embedded_conf[]; diff --git a/external/bsd/dhcpcd/dist/src/dhcpcd.8.in b/external/bsd/dhcpcd/dist/src/dhcpcd.8.in index ae218f937f8..0199df883a7 100644 --- a/external/bsd/dhcpcd/dist/src/dhcpcd.8.in +++ b/external/bsd/dhcpcd/dist/src/dhcpcd.8.in @@ -24,7 +24,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd August 28, 2019 +.Dd October 9, 2019 .Dt DHCPCD 8 .Os .Sh NAME @@ -203,6 +203,15 @@ changes the routes to use the interface with the same route and the lowest metric. See options below for controlling which interfaces we allow and deny through the use of patterns. +.Pp +Non-ethernet interfaces and some virtual ethernet interfaces +such as TAP and bridge are ignored by default, +as is the FireWire interface. +To work with these devices they either need to be specified on the command line, +be listed in +.Fl Fl allowinterfaces +or have an interface directive in +.Pa @SYSCONFDIR@/dhcpcd.conf . .Ss Hooking into events .Nm runs diff --git a/external/bsd/dhcpcd/dist/src/dhcpcd.c b/external/bsd/dhcpcd/dist/src/dhcpcd.c index 6d361e49a37..e9b8a023418 100644 --- a/external/bsd/dhcpcd/dist/src/dhcpcd.c +++ b/external/bsd/dhcpcd/dist/src/dhcpcd.c @@ -590,6 +590,12 @@ configure_interface1(struct interface *ifp) } } #endif + + /* If root is network mounted, we don't want to kill the connection + * if the DHCP server goes the way of the dodo OR dhcpcd is rebooting + * and the lease file has expired. */ + if (is_root_local() == 0) + ifo->options |= DHCPCD_LASTLEASE_EXTEND; } int @@ -1088,8 +1094,13 @@ static void dhcpcd_checkcarrier(void *arg) { struct interface *ifp = arg; + int carrier; - dhcpcd_handlecarrier(ifp->ctx, LINK_UNKNOWN, ifp->flags, ifp->name); + /* Check carrier here rather than setting LINK_UNKNOWN. + * This is because we force LINK_UNKNOWN as down for wireless which + * we do not want when dealing with a route socket overflow. */ + carrier = if_carrier(ifp); + dhcpcd_handlecarrier(ifp->ctx, carrier, ifp->flags, ifp->name); } #ifndef SMALL diff --git a/external/bsd/dhcpcd/dist/src/dhcpcd.conf.5.in b/external/bsd/dhcpcd/dist/src/dhcpcd.conf.5.in index cf8036359c5..14b31d0f458 100644 --- a/external/bsd/dhcpcd/dist/src/dhcpcd.conf.5.in +++ b/external/bsd/dhcpcd/dist/src/dhcpcd.conf.5.in @@ -24,7 +24,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd August 28, 2019 +.Dd September 8, 2019 .Dt DHCPCD.CONF 5 .Os .Sh NAME @@ -454,7 +454,7 @@ Metrics are used to prefer an interface over another one, lowest wins. will supply a default metric of 200 + .Xr if_nametoindex 3 . An extra 100 will be added for wireless interfaces. -.It Ic mudurl Ar url +.It Ic mudurl Ar url Specifies the URL for a Manufacturer Usage Description (MUD). The description is used by upstream network devices to instantiate any desired access lists. @@ -725,7 +725,7 @@ DHCP, ND and DHCPv6 allow for the use of custom options, and RFC 3925 vendor options for DHCP can also be supplied. Each option needs to be started with the .Ic define , -.Ic definend, +.Ic definend , .Ic define6 or .Ic vendopt diff --git a/external/bsd/dhcpcd/dist/src/genembedc b/external/bsd/dhcpcd/dist/src/genembedc deleted file mode 100755 index 27b58539945..00000000000 --- a/external/bsd/dhcpcd/dist/src/genembedc +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/sh -set -e - -: ${TOOL_CAT:=cat} -: ${TOOL_SED:=sed} -CONF=${1:-dhcpcd-definitions.conf} -C=${2:-dhcpcd-embedded.c.in} - -$TOOL_CAT $C -$TOOL_SED \ - -e 's/#.*$//' \ - -e '/^$/d' \ - -e 's/^/"/g' \ - -e 's/$/\",/g' \ - -e 's/ [ ]*/ /g' \ - -e 's/ [ ]*/ /g' \ - $CONF -printf "%s\n%s\n" "NULL" "};" diff --git a/external/bsd/dhcpcd/dist/src/genembedh b/external/bsd/dhcpcd/dist/src/genembedh deleted file mode 100755 index cd97cbb44d7..00000000000 --- a/external/bsd/dhcpcd/dist/src/genembedh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/sh -set -e - -: ${TOOL_SED:=sed} -: ${TOOL_GREP:=grep} -: ${TOOL_WC:=wc} -CONF=${1:-dhcpcd-definitions.conf} -H=${2:-dhcpcd-embedded.h.in} - -INITDEFINES=$($TOOL_GREP "^define " $CONF | $TOOL_WC -l) -INITDEFINENDS=$($TOOL_GREP "^definend " $CONF | $TOOL_WC -l) -INITDEFINE6S=$($TOOL_GREP "^define6 " $CONF | $TOOL_WC -l) -$TOOL_SED \ - -e "s/@INITDEFINES@/$INITDEFINES/" \ - -e "s/@INITDEFINENDS@/$INITDEFINENDS/" \ - -e "s/@INITDEFINE6S@/$INITDEFINE6S/" \ - $H diff --git a/external/bsd/dhcpcd/dist/src/if-bsd.c b/external/bsd/dhcpcd/dist/src/if-bsd.c index 8348d42dcfa..a2c613edcb3 100644 --- a/external/bsd/dhcpcd/dist/src/if-bsd.c +++ b/external/bsd/dhcpcd/dist/src/if-bsd.c @@ -101,6 +101,14 @@ #define RT_ADVANCE(x, n) (x += RT_ROUNDUP((n)->sa_len)) #endif +/* Ignore these interface names which look like ethernet but are virtual. */ +static const char * const ifnames_ignore[] = { + "bridge", + "fwe", /* Firewire */ + "tap", + NULL +}; + #ifdef INET6 static void ifa_setscope(struct sockaddr_in6 *, unsigned int); static unsigned int ifa_getscope(const struct sockaddr_in6 *); @@ -208,6 +216,61 @@ if_closesockets_os(struct dhcpcd_ctx *ctx) close(priv->pf_inet6_fd); } +static bool +if_ignore1(const char *drvname) +{ + const char * const *p; + + for (p = ifnames_ignore; *p; p++) { + if (strcmp(*p, drvname) == 0) + return true; + } + return false; +} + +bool +if_ignore(struct dhcpcd_ctx *ctx, const char *ifname) +{ + struct if_spec spec; + + if (if_nametospec(ifname, &spec) != 0) + return false; + + if (if_ignore1(spec.drvname)) + return true; + +#ifdef SIOCGIFGROUP + struct ifgroupreq ifgr = { .ifgr_len = 0 }; + struct ifg_req *ifg; + size_t ifg_len; + + /* Sadly it is possible to remove the device name + * from the interface groups, but hopefully this + * will be very unlikely.... */ + + strlcpy(ifgr.ifgr_name, ifname, sizeof(ifgr.ifgr_name)); + if (ioctl(ctx->pf_inet_fd, SIOCGIFGROUP, &ifgr) == -1 || + (ifgr.ifgr_groups = malloc(ifgr.ifgr_len)) == NULL || + ioctl(ctx->pf_inet_fd, SIOCGIFGROUP, &ifgr) == -1) + { + logerr(__func__); + return false; + } + + for (ifg = ifgr.ifgr_groups, ifg_len = ifgr.ifgr_len; + ifg && ifg_len >= sizeof(*ifg); + ifg++, ifg_len -= sizeof(*ifg)) + { + if (if_ignore1(ifg->ifgrq_group)) + return true; + } +#else + UNUSED(ctx); +#endif + + return false; +} + int if_carrier(struct interface *ifp) { @@ -653,6 +716,12 @@ if_copyrt(struct dhcpcd_ctx *ctx, struct rt *rt, const struct rt_msghdr *rtm) return -1; } #endif +#ifdef RTF_WASCLONED + if (rtm->rtm_flags & RTF_WASCLONED) { + errno = ENOTSUP; + return -1; + } +#endif #ifdef RTF_LOCAL if (rtm->rtm_flags & RTF_LOCAL) { errno = ENOTSUP; diff --git a/external/bsd/dhcpcd/dist/src/if-linux-wext.c b/external/bsd/dhcpcd/dist/src/if-linux-wext.c deleted file mode 100644 index dd4a9e08481..00000000000 --- a/external/bsd/dhcpcd/dist/src/if-linux-wext.c +++ /dev/null @@ -1,90 +0,0 @@ -/* SPDX-License-Identifier: BSD-2-Clause */ -/* - * dhcpcd - DHCP client daemon - * Copyright (c) 2009-2019 Roy Marples <roy@marples.name> - * 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. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. - */ - -/* - * THIS IS A NASTY HACK THAT SHOULD NEVER HAVE HAPPENED - * Basically we cannot include linux/if.h and net/if.h because - * they have conflicting structures. - * Sadly, linux/wireless.h includes linux/if.h all the time. - * Some kernel-header installs fix this and some do not. - * This file solely exists for those who do not. - * - * We *could* include wireless.h as that is designed for userspace, - * but that then depends on the correct version of wireless-tools being - * installed which isn't always the case. - */ - -#include <sys/ioctl.h> -#include <sys/socket.h> - -#include <linux/types.h> -#include <linux/rtnetlink.h> -/* Support older kernels */ -#ifdef IFLA_WIRELESS -# include <linux/if.h> -# include <linux/wireless.h> -#else -# define IFLA_WIRELESS (IFLA_MASTER + 1) -#endif - -#include <string.h> -#include <unistd.h> - -#include "config.h" - -/* We can't include if.h or dhcpcd.h because - * they would pull in net/if.h, which defeats the purpose of this hack. */ -#define IF_SSIDLEN 32 -int if_getssid_wext(const char *ifname, uint8_t *ssid); - -int -if_getssid_wext(const char *ifname, uint8_t *ssid) -{ -#ifdef SIOCGIWESSID - int s, retval; - struct iwreq iwr; - - if ((s = socket(PF_INET, SOCK_DGRAM, 0)) == -1) - return -1; - memset(&iwr, 0, sizeof(iwr)); - strlcpy(iwr.ifr_name, ifname, sizeof(iwr.ifr_name)); - iwr.u.essid.pointer = ssid; - iwr.u.essid.length = IF_SSIDLEN; - - if (ioctl(s, SIOCGIWESSID, &iwr) == 0) - retval = iwr.u.essid.length; - else - retval = -1; - close(s); - return retval; -#else - /* Stop gcc warning about unused parameters */ - ifname = ssid; - return -1; -#endif -} diff --git a/external/bsd/dhcpcd/dist/src/if-linux.c b/external/bsd/dhcpcd/dist/src/if-linux.c deleted file mode 100644 index e569596f597..00000000000 --- a/external/bsd/dhcpcd/dist/src/if-linux.c +++ /dev/null @@ -1,1806 +0,0 @@ -/* SPDX-License-Identifier: BSD-2-Clause */ -/* - * Linux interface driver for dhcpcd - * Copyright (c) 2006-2019 Roy Marples <roy@marples.name> - * 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. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. - */ - -#include <asm/types.h> /* Needed for 2.4 kernels */ - -#include <sys/types.h> -#include <sys/ioctl.h> -#include <sys/socket.h> -#include <sys/param.h> - -#include <linux/if_addr.h> -#include <linux/if_link.h> -#include <linux/if_packet.h> -#include <linux/if_vlan.h> -#include <linux/filter.h> -#include <linux/netlink.h> -#include <linux/sockios.h> -#include <linux/rtnetlink.h> - -#include <arpa/inet.h> -#include <net/if.h> -#include <netinet/if_ether.h> -#include <netinet/in_systm.h> -#include <netinet/in.h> -#include <net/route.h> - -#include <errno.h> -#include <fcntl.h> -#include <ctype.h> -#include <stdbool.h> -#include <stddef.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <time.h> -#include <unistd.h> - -#include "config.h" -#include "bpf.h" -#include "common.h" -#include "dev.h" -#include "dhcp.h" -#include "if.h" -#include "ipv4.h" -#include "ipv4ll.h" -#include "ipv6.h" -#include "ipv6nd.h" -#include "logerr.h" -#include "route.h" -#include "sa.h" - -#ifdef HAVE_NL80211_H -#include <linux/genetlink.h> -#include <linux/nl80211.h> -#else -int if_getssid_wext(const char *ifname, uint8_t *ssid); -#endif - -/* Support older kernels */ -#ifndef IFLA_WIRELESS -#define IFLA_WIRELESS (IFLA_MASTER + 1) -#endif - -/* For some reason, glibc doesn't include newer flags from linux/if.h - * However, we cannot include linux/if.h directly as it conflicts - * with the glibc version. D'oh! */ -#ifndef IFF_LOWER_UP -#define IFF_LOWER_UP 0x10000 /* driver signals L1 up */ -#endif - -/* Buggy CentOS and RedHat */ -#ifndef SOL_NETLINK -#define SOL_NETLINK 270 -#endif - -#define bpf_insn sock_filter -#define BPF_SKIPTYPE -#define BPF_ETHCOOK -ETH_HLEN -#define BPF_WHOLEPACKET 0x0fffffff /* work around buggy LPF filters */ - -struct priv { - int route_fd; - uint32_t route_pid; -}; - -/* We need this to send a broadcast for InfiniBand. - * Our old code used sendto, but our new code writes to a raw BPF socket. - * What header structure does IPoIB use? */ -#if 0 -/* Broadcast address for IPoIB */ -static const uint8_t ipv4_bcast_addr[] = { - 0x00, 0xff, 0xff, 0xff, - 0xff, 0x12, 0x40, 0x1b, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff -}; -#endif - -#define PROC_INET6 "/proc/net/if_inet6" -#define PROC_PROMOTE "/proc/sys/net/ipv4/conf/%s/promote_secondaries" -#define SYS_LAYER2 "/sys/class/net/%s/device/layer2" - -static const char *mproc = -#if defined(__alpha__) - "system type" -#elif defined(__arm__) - "Hardware" -#elif defined(__avr32__) - "cpu family" -#elif defined(__bfin__) - "BOARD Name" -#elif defined(__cris__) - "cpu model" -#elif defined(__frv__) - "System" -#elif defined(__i386__) || defined(__x86_64__) - "vendor_id" -#elif defined(__ia64__) - "vendor" -#elif defined(__hppa__) - "model" -#elif defined(__m68k__) - "MMU" -#elif defined(__mips__) - "system type" -#elif defined(__powerpc__) || defined(__powerpc64__) - "machine" -#elif defined(__s390__) || defined(__s390x__) - "Manufacturer" -#elif defined(__sh__) - "machine" -#elif defined(sparc) || defined(__sparc__) - "cpu" -#elif defined(__vax__) - "cpu" -#else - NULL -#endif - ; - -int -if_machinearch(char *str, size_t len) -{ - FILE *fp; - char buf[256]; - - if (mproc == NULL) { - errno = EINVAL; - return -1; - } - - fp = fopen("/proc/cpuinfo", "r"); - if (fp == NULL) - return -1; - - while (fscanf(fp, "%255s : ", buf) != EOF) { - if (strncmp(buf, mproc, strlen(mproc)) == 0 && - fscanf(fp, "%255s", buf) == 1) - { - fclose(fp); - return snprintf(str, len, ":%s", buf); - } - } - fclose(fp); - errno = ESRCH; - return -1; -} - -static int -check_proc_int(const char *path) -{ - FILE *fp; - int i; - - fp = fopen(path, "r"); - if (fp == NULL) - return -1; - if (fscanf(fp, "%d", &i) != 1) - i = -1; - fclose(fp); - return i; -} - -static ssize_t -write_path(const char *path, const char *val) -{ - FILE *fp; - ssize_t r; - - fp = fopen(path, "w"); - if (fp == NULL) - return -1; - r = fprintf(fp, "%s\n", val); - fclose(fp); - return r; -} - -int -if_init(struct interface *ifp) -{ - char path[sizeof(PROC_PROMOTE) + IF_NAMESIZE]; - int n; - - /* We enable promote_secondaries so that we can do this - * add 192.168.1.2/24 - * add 192.168.1.3/24 - * del 192.168.1.2/24 - * and the subnet mask moves onto 192.168.1.3/24 - * This matches the behaviour of BSD which makes coding dhcpcd - * a little easier as there's just one behaviour. */ - snprintf(path, sizeof(path), PROC_PROMOTE, ifp->name); - n = check_proc_int(path); - if (n == -1) - return errno == ENOENT ? 0 : -1; - if (n == 1) - return 0; - return write_path(path, "1") == -1 ? -1 : 0; -} - -int -if_conf(struct interface *ifp) -{ - char path[sizeof(SYS_LAYER2) + IF_NAMESIZE]; - int n; - - /* Some qeth setups require the use of the broadcast flag. */ - snprintf(path, sizeof(path), SYS_LAYER2, ifp->name); - n = check_proc_int(path); - if (n == -1) - return errno == ENOENT ? 0 : -1; - if (n == 0) - ifp->options->options |= DHCPCD_BROADCAST; - return 0; -} - -/* XXX work out Virtal Interface Masters */ -int -if_vimaster(__unused const struct dhcpcd_ctx *ctx, __unused const char *ifname) -{ - - return 0; -} - -unsigned short -if_vlanid(const struct interface *ifp) -{ - struct vlan_ioctl_args v; - - memset(&v, 0, sizeof(v)); - strlcpy(v.device1, ifp->name, sizeof(v.device1)); - v.cmd = GET_VLAN_VID_CMD; - if (ioctl(ifp->ctx->pf_inet_fd, SIOCSIFVLAN, &v) != 0) - return 0; /* 0 means no VLANID */ - return (unsigned short)v.u.VID; -} - -static int -_open_link_socket(struct sockaddr_nl *nl, int protocol) -{ - int fd; - - if ((fd = xsocket(AF_NETLINK, SOCK_RAW | SOCK_CLOEXEC, protocol)) == -1) - return -1; - nl->nl_family = AF_NETLINK; - if (bind(fd, (struct sockaddr *)nl, sizeof(*nl)) == -1) { - close(fd); - return -1; - } - return fd; -} - -int -if_opensockets_os(struct dhcpcd_ctx *ctx) -{ - struct priv *priv; - struct sockaddr_nl snl; - socklen_t len; -#ifdef NETLINK_BROADCAST_ERROR - int on = 1; -#endif - - /* Open the link socket first so it gets pid() for the socket. - * Then open our persistent route socket so we get a unique - * pid that doesn't clash with a process id for after we fork. */ - memset(&snl, 0, sizeof(snl)); - snl.nl_groups = RTMGRP_LINK; - -#ifdef INET - snl.nl_groups |= RTMGRP_IPV4_ROUTE | RTMGRP_IPV4_IFADDR; -#endif -#ifdef INET6 - snl.nl_groups |= RTMGRP_IPV6_ROUTE | RTMGRP_IPV6_IFADDR | RTMGRP_NEIGH; -#endif - - ctx->link_fd = _open_link_socket(&snl, NETLINK_ROUTE); - if (ctx->link_fd == -1) - return -1; -#ifdef NETLINK_BROADCAST_ERROR - if (setsockopt(ctx->link_fd, SOL_NETLINK, NETLINK_BROADCAST_ERROR, - &on, sizeof(on)) == -1) - logerr("%s: NETLINK_BROADCAST_ERROR", __func__); -#endif - - if ((priv = calloc(1, sizeof(*priv))) == NULL) - return -1; - - ctx->priv = priv; - memset(&snl, 0, sizeof(snl)); - priv->route_fd = _open_link_socket(&snl, NETLINK_ROUTE); - if (priv->route_fd == -1) - return -1; - len = sizeof(snl); - if (getsockname(priv->route_fd, (struct sockaddr *)&snl, &len) == -1) - return -1; - priv->route_pid = snl.nl_pid; - return 0; -} - -void -if_closesockets_os(struct dhcpcd_ctx *ctx) -{ - struct priv *priv; - - if (ctx->priv != NULL) { - priv = (struct priv *)ctx->priv; - close(priv->route_fd); - } -} - -int -if_carrier(struct interface *ifp) -{ - - if (if_getflags(ifp) == -1) - return LINK_UNKNOWN; - return ifp->flags & IFF_RUNNING ? LINK_UP : LINK_DOWN; -} - -static int -get_netlink(struct dhcpcd_ctx *ctx, struct iovec *iov, - void *arg, int fd, int flags, - int (*callback)(struct dhcpcd_ctx *, void *, struct nlmsghdr *)) -{ - struct sockaddr_nl nladdr = { .nl_pid = 0 }; - struct msghdr msg = { - .msg_name = &nladdr, .msg_namelen = sizeof(nladdr), - .msg_iov = iov, .msg_iovlen = 1, - }; - ssize_t len; - struct nlmsghdr *nlm; - int r; - unsigned int again; - -recv_again: - if ((len = recvmsg(fd, &msg, flags)) == -1) - return -1; - if (len == 0) - return 0; - - /* Check sender */ - if (msg.msg_namelen != sizeof(nladdr)) { - errno = EINVAL; - return -1; - } - /* Ignore message if it is not from kernel */ - if (nladdr.nl_pid != 0) - return 0; - - r = 0; - again = 0; /* Appease static analysis */ - for (nlm = iov->iov_base; - nlm && NLMSG_OK(nlm, (size_t)len); - nlm = NLMSG_NEXT(nlm, len)) - { - again = (nlm->nlmsg_flags & NLM_F_MULTI); - if (nlm->nlmsg_type == NLMSG_NOOP) - continue; - if (nlm->nlmsg_type == NLMSG_ERROR) { - struct nlmsgerr *err; - - if (nlm->nlmsg_len - sizeof(*nlm) < sizeof(*err)) { - errno = EBADMSG; - return -1; - } - err = (struct nlmsgerr *)NLMSG_DATA(nlm); - if (err->error != 0) { - errno = -err->error; - return -1; - } - break; - } - if (nlm->nlmsg_type == NLMSG_DONE) { - again = 0; - break; - } - if (callback && (r = callback(ctx, arg, nlm)) != 0) - break; - } - - if (r == 0 && again) - goto recv_again; - - return r; -} - -static int -if_copyrt(struct dhcpcd_ctx *ctx, struct rt *rt, struct nlmsghdr *nlm) -{ - size_t len; - struct rtmsg *rtm; - struct rtattr *rta; - unsigned int ifindex; - struct sockaddr *sa; - - len = nlm->nlmsg_len - sizeof(*nlm); - if (len < sizeof(*rtm)) { - errno = EBADMSG; - return -1; - } - rtm = (struct rtmsg *)NLMSG_DATA(nlm); - if (rtm->rtm_table != RT_TABLE_MAIN) - return -1; - - memset(rt, 0, sizeof(*rt)); - if (rtm->rtm_type == RTN_UNREACHABLE) - rt->rt_flags |= RTF_REJECT; - - rta = (struct rtattr *)RTM_RTA(rtm); - len = RTM_PAYLOAD(nlm); - while (RTA_OK(rta, len)) { - sa = NULL; - switch (rta->rta_type) { - case RTA_DST: - sa = &rt->rt_dest; - break; - case RTA_GATEWAY: - sa = &rt->rt_gateway; - break; - case RTA_PREFSRC: - sa = &rt->rt_ifa; - break; - case RTA_OIF: - ifindex = *(unsigned int *)RTA_DATA(rta); - rt->rt_ifp = if_findindex(ctx->ifaces, ifindex); - break; - case RTA_PRIORITY: - rt->rt_metric = *(unsigned int *)RTA_DATA(rta); - break; - case RTA_METRICS: - { - struct rtattr *r2; - size_t l2; - - l2 = rta->rta_len; - r2 = (struct rtattr *)RTA_DATA(rta); - while (RTA_OK(r2, l2)) { - switch (r2->rta_type) { - case RTAX_MTU: - rt->rt_mtu = *(unsigned int *)RTA_DATA(r2); - break; - } - r2 = RTA_NEXT(r2, l2); - } - break; - } - } - - if (sa != NULL) { - socklen_t salen; - - sa->sa_family = rtm->rtm_family; - salen = sa_addrlen(sa); - /* sa is a union where sockaddr_in6 is the biggest. */ - /* coverity[overrun-buffer-arg] */ - memcpy((char *)sa + sa_addroffset(sa), RTA_DATA(rta), - MIN(salen, RTA_PAYLOAD(rta))); - } - - rta = RTA_NEXT(rta, len); - } - - /* If no RTA_DST set the unspecified address for the family. */ - if (rt->rt_dest.sa_family == AF_UNSPEC) - rt->rt_dest.sa_family = rtm->rtm_family; - - rt->rt_netmask.sa_family = rtm->rtm_family; - sa_fromprefix(&rt->rt_netmask, rtm->rtm_dst_len); - if (sa_is_allones(&rt->rt_netmask)) - rt->rt_flags |= RTF_HOST; - - #if 0 - if (rt->rtp_ifp == NULL && rt->src.s_addr != INADDR_ANY) { - struct ipv4_addr *ap; - - /* For some reason the default route comes back with the - * loopback interface in RTA_OIF? Lets find it by - * preferred source address */ - if ((ap = ipv4_findaddr(ctx, &rt->src))) - rt->iface = ap->iface; - } - #endif - - if (rt->rt_ifp == NULL) { - errno = ESRCH; - return -1; - } - return 0; -} - -static int -link_route(struct dhcpcd_ctx *ctx, __unused struct interface *ifp, - struct nlmsghdr *nlm) -{ - size_t len; - int cmd; - struct priv *priv; - struct rt rt; - - switch (nlm->nlmsg_type) { - case RTM_NEWROUTE: - cmd = RTM_ADD; - break; - case RTM_DELROUTE: - cmd = RTM_DELETE; - break; - default: - return 0; - } - - len = nlm->nlmsg_len - sizeof(*nlm); - if (len < sizeof(struct rtmsg)) { - errno = EBADMSG; - return -1; - } - - /* Ignore messages we sent. */ - priv = (struct priv *)ctx->priv; - if (nlm->nlmsg_pid == priv->route_pid) - return 0; - - if (if_copyrt(ctx, &rt, nlm) == 0) - rt_recvrt(cmd, &rt, (pid_t)nlm->nlmsg_pid); - - return 0; -} - -static int -link_addr(struct dhcpcd_ctx *ctx, struct interface *ifp, struct nlmsghdr *nlm) -{ - size_t len; - struct rtattr *rta; - struct ifaddrmsg *ifa; - struct priv *priv; -#ifdef INET - struct in_addr addr, net, brd; -#endif -#ifdef INET6 - struct in6_addr addr6; -#endif - - if (nlm->nlmsg_type != RTM_DELADDR && nlm->nlmsg_type != RTM_NEWADDR) - return 0; - - len = nlm->nlmsg_len - sizeof(*nlm); - if (len < sizeof(*ifa)) { - errno = EBADMSG; - return -1; - } - - /* Ignore messages we sent. */ - priv = (struct priv*)ctx->priv; - if (nlm->nlmsg_pid == priv->route_pid) - return 0; - - ifa = NLMSG_DATA(nlm); - if ((ifp = if_findindex(ctx->ifaces, ifa->ifa_index)) == NULL) { - /* We don't know about the interface the address is for - * so it's not really an error */ - return 1; - } - rta = (struct rtattr *)IFA_RTA(ifa); - len = NLMSG_PAYLOAD(nlm, sizeof(*ifa)); - switch (ifa->ifa_family) { -#ifdef INET - case AF_INET: - addr.s_addr = brd.s_addr = INADDR_ANY; - inet_cidrtoaddr(ifa->ifa_prefixlen, &net); - while (RTA_OK(rta, len)) { - switch (rta->rta_type) { - case IFA_ADDRESS: - if (ifp->flags & IFF_POINTOPOINT) { - memcpy(&brd.s_addr, RTA_DATA(rta), - sizeof(brd.s_addr)); - } - break; - case IFA_BROADCAST: - memcpy(&brd.s_addr, RTA_DATA(rta), - sizeof(brd.s_addr)); - break; - case IFA_LOCAL: - memcpy(&addr.s_addr, RTA_DATA(rta), - sizeof(addr.s_addr)); - break; - } - rta = RTA_NEXT(rta, len); - } - ipv4_handleifa(ctx, nlm->nlmsg_type, NULL, ifp->name, - &addr, &net, &brd, ifa->ifa_flags, (pid_t)nlm->nlmsg_pid); - break; -#endif -#ifdef INET6 - case AF_INET6: - memset(&addr6, 0, sizeof(addr6)); - while (RTA_OK(rta, len)) { - switch (rta->rta_type) { - case IFA_ADDRESS: - memcpy(&addr6.s6_addr, RTA_DATA(rta), - sizeof(addr6.s6_addr)); - break; - } - rta = RTA_NEXT(rta, len); - } - ipv6_handleifa(ctx, nlm->nlmsg_type, NULL, ifp->name, - &addr6, ifa->ifa_prefixlen, ifa->ifa_flags, - (pid_t)nlm->nlmsg_pid); - break; -#endif - } - return 0; -} - -static uint8_t -l2addr_len(unsigned short if_type) -{ - - switch (if_type) { - case ARPHRD_ETHER: /* FALLTHROUGH */ - case ARPHRD_IEEE802: /*FALLTHROUGH */ - case ARPHRD_IEEE80211: - return 6; - case ARPHRD_IEEE1394: - return 8; - case ARPHRD_INFINIBAND: - return 20; - } - - /* Impossible */ - return 0; -} - -#ifdef INET6 -static int -link_neigh(struct dhcpcd_ctx *ctx, __unused struct interface *ifp, - struct nlmsghdr *nlm) -{ - struct ndmsg *r; - struct rtattr *rta; - size_t len; - - if (nlm->nlmsg_type != RTM_NEWNEIGH && nlm->nlmsg_type != RTM_DELNEIGH) - return 0; - if (nlm->nlmsg_len < sizeof(*r)) - return -1; - - r = NLMSG_DATA(nlm); - rta = (struct rtattr *)RTM_RTA(r); - len = RTM_PAYLOAD(nlm); - if (r->ndm_family == AF_INET6) { - bool reachable; - struct in6_addr addr6; - - reachable = (nlm->nlmsg_type == RTM_NEWNEIGH && - r->ndm_state & - (NUD_REACHABLE | NUD_STALE | NUD_DELAY | NUD_PROBE | - NUD_PERMANENT)); - memset(&addr6, 0, sizeof(addr6)); - while (RTA_OK(rta, len)) { - switch (rta->rta_type) { - case NDA_DST: - memcpy(&addr6.s6_addr, RTA_DATA(rta), - sizeof(addr6.s6_addr)); - break; - } - rta = RTA_NEXT(rta, len); - } - ipv6nd_neighbour(ctx, &addr6, reachable); - } - - return 0; -} -#endif - -static int -link_netlink(struct dhcpcd_ctx *ctx, void *arg, struct nlmsghdr *nlm) -{ - struct interface *ifp = arg; - int r; - size_t len; - struct rtattr *rta, *hwaddr; - struct ifinfomsg *ifi; - char ifn[IF_NAMESIZE + 1]; - - r = link_route(ctx, ifp, nlm); - if (r != 0) - return r; - r = link_addr(ctx, ifp, nlm); - if (r != 0) - return r; -#ifdef INET6 - r = link_neigh(ctx, ifp, nlm); - if (r != 0) - return r; -#endif - - if (nlm->nlmsg_type != RTM_NEWLINK && nlm->nlmsg_type != RTM_DELLINK) - return 0; - len = nlm->nlmsg_len - sizeof(*nlm); - if ((size_t)len < sizeof(*ifi)) { - errno = EBADMSG; - return -1; - } - ifi = NLMSG_DATA(nlm); - if (ifi->ifi_flags & IFF_LOOPBACK) - return 0; - rta = (void *)((char *)ifi + NLMSG_ALIGN(sizeof(*ifi))); - len = NLMSG_PAYLOAD(nlm, sizeof(*ifi)); - *ifn = '\0'; - hwaddr = NULL; - - while (RTA_OK(rta, len)) { - switch (rta->rta_type) { - case IFLA_WIRELESS: - /* Ignore wireless messages */ - if (nlm->nlmsg_type == RTM_NEWLINK && - ifi->ifi_change == 0) - return 0; - break; - case IFLA_IFNAME: - strlcpy(ifn, (char *)RTA_DATA(rta), sizeof(ifn)); - break; - case IFLA_ADDRESS: - hwaddr = rta; - break; - } - rta = RTA_NEXT(rta, len); - } - - if (nlm->nlmsg_type == RTM_DELLINK) { - /* If are listening to a dev manager, let that remove - * the interface rather than the kernel. */ - if (dev_listening(ctx) < 1) - dhcpcd_handleinterface(ctx, -1, ifn); - return 0; - } - - /* Virtual interfaces may not get a valid hardware address - * at this point. - * To trigger a valid hardware address pickup we need to pretend - * that that don't exist until they have one. */ - if (ifi->ifi_flags & IFF_MASTER && !hwaddr) { - dhcpcd_handleinterface(ctx, -1, ifn); - return 0; - } - - /* Check for a new interface */ - ifp = if_findindex(ctx->ifaces, (unsigned int)ifi->ifi_index); - if (ifp == NULL) { - /* If are listening to a dev manager, let that announce - * the interface rather than the kernel. */ - if (dev_listening(ctx) < 1) - dhcpcd_handleinterface(ctx, 1, ifn); - return 0; - } - - /* Handle interface being renamed */ - if (strcmp(ifp->name, ifn) != 0) { - dhcpcd_handleinterface(ctx, -1, ifn); - dhcpcd_handleinterface(ctx, 1, ifn); - return 0; - } - - /* Re-read hardware address and friends */ - if (!(ifi->ifi_flags & IFF_UP) && hwaddr) { - uint8_t l; - - l = l2addr_len(ifi->ifi_type); - if (hwaddr->rta_len == RTA_LENGTH(l)) - dhcpcd_handlehwaddr(ctx, ifn, RTA_DATA(hwaddr), l); - } - - dhcpcd_handlecarrier(ctx, - ifi->ifi_flags & IFF_RUNNING ? LINK_UP : LINK_DOWN, - ifi->ifi_flags, ifn); - return 0; -} - -int -if_handlelink(struct dhcpcd_ctx *ctx) -{ - unsigned char buf[16 * 1024]; - struct iovec iov = { - .iov_base = buf, - .iov_len = sizeof(buf), - }; - - return get_netlink(ctx, &iov, NULL, - ctx->link_fd, MSG_DONTWAIT, &link_netlink); -} - -static int -send_netlink(struct dhcpcd_ctx *ctx, void *arg, - int protocol, struct nlmsghdr *hdr, - int (*callback)(struct dhcpcd_ctx *, void *, struct nlmsghdr *)) -{ - int s, r; - struct sockaddr_nl snl = { .nl_family = AF_NETLINK }; - struct iovec iov = { .iov_base = hdr, .iov_len = hdr->nlmsg_len }; - struct msghdr msg = { - .msg_name = &snl, .msg_namelen = sizeof(snl), - .msg_iov = &iov, .msg_iovlen = 1 - }; - - if (protocol == NETLINK_ROUTE) { - struct priv *priv; - - priv = (struct priv *)ctx->priv; - s = priv->route_fd; - } else { - if ((s = _open_link_socket(&snl, protocol)) == -1) - return -1; - } - - /* Request a reply */ - hdr->nlmsg_flags |= NLM_F_ACK; - hdr->nlmsg_seq = (uint32_t)++ctx->seq; - if (sendmsg(s, &msg, 0) != -1) { - unsigned char buf[16 * 1024]; - struct iovec riov = { - .iov_base = buf, - .iov_len = sizeof(buf), - }; - - r = get_netlink(ctx, &riov, arg, s, 0, callback); - } else - r = -1; - if (protocol != NETLINK_ROUTE) - close(s); - return r; -} - -#define NLMSG_TAIL(nmsg) \ - ((struct rtattr *)(((ptrdiff_t)(nmsg))+NLMSG_ALIGN((nmsg)->nlmsg_len))) - -static int -add_attr_l(struct nlmsghdr *n, unsigned short maxlen, unsigned short type, - const void *data, unsigned short alen) -{ - unsigned short len = (unsigned short)RTA_LENGTH(alen); - struct rtattr *rta; - - if (NLMSG_ALIGN(n->nlmsg_len) + RTA_ALIGN(len) > maxlen) { - errno = ENOBUFS; - return -1; - } - - rta = NLMSG_TAIL(n); - rta->rta_type = type; - rta->rta_len = len; - if (alen) - memcpy(RTA_DATA(rta), data, alen); - n->nlmsg_len = NLMSG_ALIGN(n->nlmsg_len) + RTA_ALIGN(len); - - return 0; -} - -static int -add_attr_32(struct nlmsghdr *n, unsigned short maxlen, unsigned short type, - uint32_t data) -{ - unsigned short len = RTA_LENGTH(sizeof(data)); - struct rtattr *rta; - - if (NLMSG_ALIGN(n->nlmsg_len) + len > maxlen) { - errno = ENOBUFS; - return -1; - } - - rta = NLMSG_TAIL(n); - rta->rta_type = type; - rta->rta_len = len; - memcpy(RTA_DATA(rta), &data, sizeof(data)); - n->nlmsg_len = NLMSG_ALIGN(n->nlmsg_len) + len; - - return 0; -} - -static int -rta_add_attr_32(struct rtattr *rta, unsigned short maxlen, - unsigned short type, uint32_t data) -{ - unsigned short len = RTA_LENGTH(sizeof(data)); - struct rtattr *subrta; - - if (RTA_ALIGN(rta->rta_len) + len > maxlen) { - errno = ENOBUFS; - return -1; - } - - subrta = (void *)((char*)rta + RTA_ALIGN(rta->rta_len)); - subrta->rta_type = type; - subrta->rta_len = len; - memcpy(RTA_DATA(subrta), &data, sizeof(data)); - rta->rta_len = (unsigned short)(NLMSG_ALIGN(rta->rta_len) + len); - return 0; -} - -#ifdef HAVE_NL80211_H -static struct nlattr * -nla_next(struct nlattr *nla, size_t *rem) -{ - - *rem -= (size_t)NLA_ALIGN(nla->nla_len); - return (void *)((char *)nla + NLA_ALIGN(nla->nla_len)); -} - -#define NLA_TYPE(nla) ((nla)->nla_type & NLA_TYPE_MASK) -#define NLA_LEN(nla) (unsigned int)((nla)->nla_len - NLA_HDRLEN) -#define NLA_OK(nla, rem) \ - ((rem) >= sizeof(struct nlattr) && \ - (nla)->nla_len >= sizeof(struct nlattr) && \ - (nla)->nla_len <= rem) -#define NLA_DATA(nla) (void *)((char *)(nla) + NLA_HDRLEN) -#define NLA_FOR_EACH_ATTR(pos, head, len, rem) \ - for (pos = head, rem = len; \ - NLA_OK(pos, rem); \ - pos = nla_next(pos, &(rem))) - -struct nlmg -{ - struct nlmsghdr hdr; - struct genlmsghdr ghdr; - char buffer[64]; -}; - -static int -nla_put_32(struct nlmsghdr *n, unsigned short maxlen, - unsigned short type, uint32_t data) -{ - unsigned short len; - struct nlattr *nla; - - len = NLA_ALIGN(NLA_HDRLEN + sizeof(data)); - if (NLMSG_ALIGN(n->nlmsg_len) + len > maxlen) { - errno = ENOBUFS; - return -1; - } - - nla = (struct nlattr *)NLMSG_TAIL(n); - nla->nla_type = type; - nla->nla_len = len; - memcpy(NLA_DATA(nla), &data, sizeof(data)); - n->nlmsg_len = NLMSG_ALIGN(n->nlmsg_len) + len; - - return 0; -} - -static int -nla_put_string(struct nlmsghdr *n, unsigned short maxlen, - unsigned short type, const char *data) -{ - struct nlattr *nla; - size_t len, sl; - - sl = strlen(data) + 1; - len = NLA_ALIGN(NLA_HDRLEN + sl); - if (NLMSG_ALIGN(n->nlmsg_len) + len > maxlen) { - errno = ENOBUFS; - return -1; - } - - nla = (struct nlattr *)NLMSG_TAIL(n); - nla->nla_type = type; - nla->nla_len = (unsigned short)len; - memcpy(NLA_DATA(nla), data, sl); - n->nlmsg_len = NLMSG_ALIGN(n->nlmsg_len) + (unsigned short)len; - return 0; -} - -static int -nla_parse(struct nlattr *tb[], struct nlattr *head, size_t len, int maxtype) -{ - struct nlattr *nla; - size_t rem; - int type; - - memset(tb, 0, sizeof(*tb) * ((unsigned int)maxtype + 1)); - NLA_FOR_EACH_ATTR(nla, head, len, rem) { - type = NLA_TYPE(nla); - if (type > maxtype) - continue; - tb[type] = nla; - } - return 0; -} - -static int -genl_parse(struct nlmsghdr *nlm, struct nlattr *tb[], int maxtype) -{ - struct genlmsghdr *ghdr; - struct nlattr *head; - size_t len; - - ghdr = NLMSG_DATA(nlm); - head = (void *)((char *)ghdr + GENL_HDRLEN); - len = nlm->nlmsg_len - GENL_HDRLEN - NLMSG_HDRLEN; - return nla_parse(tb, head, len, maxtype); -} - -static int -_gnl_getfamily(__unused struct dhcpcd_ctx *ctx, __unused void *arg, - struct nlmsghdr *nlm) -{ - struct nlattr *tb[CTRL_ATTR_FAMILY_ID + 1]; - uint16_t family; - - if (genl_parse(nlm, tb, CTRL_ATTR_FAMILY_ID) == -1) - return -1; - if (tb[CTRL_ATTR_FAMILY_ID] == NULL) { - errno = ENOENT; - return -1; - } - memcpy(&family, NLA_DATA(tb[CTRL_ATTR_FAMILY_ID]), sizeof(family)); - return (int)family; -} - -static int -gnl_getfamily(struct dhcpcd_ctx *ctx, const char *name) -{ - struct nlmg nlm; - - memset(&nlm, 0, sizeof(nlm)); - nlm.hdr.nlmsg_len = NLMSG_LENGTH(sizeof(struct genlmsghdr)); - nlm.hdr.nlmsg_type = GENL_ID_CTRL; - nlm.hdr.nlmsg_flags = NLM_F_REQUEST; - nlm.ghdr.cmd = CTRL_CMD_GETFAMILY; - nlm.ghdr.version = 1; - if (nla_put_string(&nlm.hdr, sizeof(nlm), - CTRL_ATTR_FAMILY_NAME, name) == -1) - return -1; - return send_netlink(ctx, NULL, NETLINK_GENERIC, &nlm.hdr, - &_gnl_getfamily); -} - -static int -_if_getssid_nl80211(__unused struct dhcpcd_ctx *ctx, void *arg, - struct nlmsghdr *nlm) -{ - struct interface *ifp = arg; - struct nlattr *tb[NL80211_ATTR_BSS + 1]; - struct nlattr *bss[NL80211_BSS_STATUS + 1]; - uint32_t status; - unsigned char *ie; - int ie_len; - - if (genl_parse(nlm, tb, NL80211_ATTR_BSS) == -1) - return 0; - - if (tb[NL80211_ATTR_BSS] == NULL) - return 0; - - if (nla_parse(bss, - NLA_DATA(tb[NL80211_ATTR_BSS]), - NLA_LEN(tb[NL80211_ATTR_BSS]), - NL80211_BSS_STATUS) == -1) - return 0; - - if (bss[NL80211_BSS_BSSID] == NULL || bss[NL80211_BSS_STATUS] == NULL) - return 0; - - memcpy(&status, NLA_DATA(bss[NL80211_BSS_STATUS]), sizeof(status)); - if (status != NL80211_BSS_STATUS_ASSOCIATED) - return 0; - - if (bss[NL80211_BSS_INFORMATION_ELEMENTS] == NULL) - return 0; - - ie = NLA_DATA(bss[NL80211_BSS_INFORMATION_ELEMENTS]); - ie_len = (int)NLA_LEN(bss[NL80211_BSS_INFORMATION_ELEMENTS]); - /* ie[0] is type, ie[1] is lenth, ie[2..] is data */ - while (ie_len >= 2 && ie_len >= ie[1]) { - if (ie[0] == 0) { - /* SSID */ - if (ie[1] > IF_SSIDLEN) { - errno = ENOBUFS; - return -1; - } - ifp->ssid_len = ie[1]; - memcpy(ifp->ssid, ie + 2, ifp->ssid_len); - return (int)ifp->ssid_len; - } - ie_len -= ie[1] + 2; - ie += ie[1] + 2; - } - - return 0; -} - -static int -if_getssid_nl80211(struct interface *ifp) -{ - int family; - struct nlmg nlm; - - errno = 0; - family = gnl_getfamily(ifp->ctx, "nl80211"); - if (family == -1) - return -1; - - /* Is this a wireless interface? */ - memset(&nlm, 0, sizeof(nlm)); - nlm.hdr.nlmsg_len = NLMSG_LENGTH(sizeof(struct genlmsghdr)); - nlm.hdr.nlmsg_type = (unsigned short)family; - nlm.hdr.nlmsg_flags = NLM_F_REQUEST; - nlm.ghdr.cmd = NL80211_CMD_GET_WIPHY; - nla_put_32(&nlm.hdr, sizeof(nlm), NL80211_ATTR_IFINDEX, ifp->index); - if (send_netlink(ifp->ctx, ifp, NETLINK_GENERIC, &nlm.hdr, NULL) == -1) - return -1; - - /* We need to parse out the list of scan results and find the one - * we are connected to. */ - memset(&nlm, 0, sizeof(nlm)); - nlm.hdr.nlmsg_len = NLMSG_LENGTH(sizeof(struct genlmsghdr)); - nlm.hdr.nlmsg_type = (unsigned short)family; - nlm.hdr.nlmsg_flags = NLM_F_REQUEST | NLM_F_DUMP; - nlm.ghdr.cmd = NL80211_CMD_GET_SCAN; - nla_put_32(&nlm.hdr, sizeof(nlm), NL80211_ATTR_IFINDEX, ifp->index); - - return send_netlink(ifp->ctx, ifp, - NETLINK_GENERIC, &nlm.hdr, &_if_getssid_nl80211); -} -#endif - -int -if_getssid(struct interface *ifp) -{ - int r; - -#ifdef HAVE_NL80211_H - r = if_getssid_nl80211(ifp); - if (r == -1) - ifp->ssid_len = 0; -#else - r = if_getssid_wext(ifp->name, ifp->ssid); - if (r != -1) - ifp->ssid_len = (unsigned int)r; -#endif - - ifp->ssid[ifp->ssid_len] = '\0'; - return r; -} - -struct nlma -{ - struct nlmsghdr hdr; - struct ifaddrmsg ifa; - char buffer[64]; -}; - -struct nlmr -{ - struct nlmsghdr hdr; - struct rtmsg rt; - char buffer[256]; -}; - -int -if_route(unsigned char cmd, const struct rt *rt) -{ - struct nlmr nlm; - bool gateway_unspec; - - memset(&nlm, 0, sizeof(nlm)); - nlm.hdr.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg)); - switch (cmd) { - case RTM_CHANGE: - nlm.hdr.nlmsg_type = RTM_NEWROUTE; - nlm.hdr.nlmsg_flags = NLM_F_CREATE | NLM_F_REPLACE; - break; - case RTM_ADD: - nlm.hdr.nlmsg_type = RTM_NEWROUTE; - nlm.hdr.nlmsg_flags = NLM_F_CREATE | NLM_F_EXCL; - break; - case RTM_DELETE: - nlm.hdr.nlmsg_type = RTM_DELROUTE; - break; - } - nlm.hdr.nlmsg_flags |= NLM_F_REQUEST; - nlm.rt.rtm_family = (unsigned char)rt->rt_dest.sa_family; - nlm.rt.rtm_table = RT_TABLE_MAIN; - - gateway_unspec = sa_is_unspecified(&rt->rt_gateway); - - if (cmd == RTM_DELETE) { - nlm.rt.rtm_scope = RT_SCOPE_NOWHERE; - } else { - /* Address generated routes are RTPROT_KERNEL, - * otherwise RTPROT_BOOT */ -#ifdef RTPROT_RA - if (rt->rt_dflags & RTDF_RA) - nlm.rt.rtm_protocol = RTPROT_RA; - else -#endif -#ifdef RTPROT_DHCP - if (rt->rt_dflags & RTDF_DHCP) - nlm.rt.rtm_protocol = RTPROT_DHCP; - else -#endif - if (rt->rt_dflags & RTDF_IFA_ROUTE) - nlm.rt.rtm_protocol = RTPROT_KERNEL; - else - nlm.rt.rtm_protocol = RTPROT_BOOT; - if (rt->rt_ifp->flags & IFF_LOOPBACK) - nlm.rt.rtm_scope = RT_SCOPE_HOST; - else if (gateway_unspec) - nlm.rt.rtm_scope = RT_SCOPE_LINK; - else - nlm.rt.rtm_scope = RT_SCOPE_UNIVERSE; - if (rt->rt_flags & RTF_REJECT) - nlm.rt.rtm_type = RTN_UNREACHABLE; - else - nlm.rt.rtm_type = RTN_UNICAST; - } - -#define ADDSA(type, sa) \ - add_attr_l(&nlm.hdr, sizeof(nlm), (type), \ - (const char *)(sa) + sa_addroffset((sa)), \ - (unsigned short)sa_addrlen((sa))); - nlm.rt.rtm_dst_len = (unsigned char)sa_toprefix(&rt->rt_netmask); - /* rt->rt_dest and rt->gateway are unions where sockaddr_in6 - * is the biggest member. However, we access them as the - * generic sockaddr and coverity thinks this will overrun. */ - /* coverity[overrun-buffer-arg] */ - ADDSA(RTA_DST, &rt->rt_dest); - if (cmd == RTM_ADD || cmd == RTM_CHANGE) { - if (!gateway_unspec) { - /* coverity[overrun-buffer-arg] */ - ADDSA(RTA_GATEWAY, &rt->rt_gateway); - } - /* Cannot add tentative source addresses. - * We don't know this here, so just skip INET6 ifa's.*/ - if (!sa_is_unspecified(&rt->rt_ifa) && - rt->rt_ifa.sa_family != AF_INET6) - ADDSA(RTA_PREFSRC, &rt->rt_ifa); - if (rt->rt_mtu) { - char metricsbuf[32]; - struct rtattr *metrics = (void *)metricsbuf; - - metrics->rta_type = RTA_METRICS; - metrics->rta_len = RTA_LENGTH(0); - rta_add_attr_32(metrics, sizeof(metricsbuf), - RTAX_MTU, rt->rt_mtu); - add_attr_l(&nlm.hdr, sizeof(nlm), RTA_METRICS, - RTA_DATA(metrics), - (unsigned short)RTA_PAYLOAD(metrics)); - } - } - - if (!sa_is_loopback(&rt->rt_gateway)) - add_attr_32(&nlm.hdr, sizeof(nlm), RTA_OIF, rt->rt_ifp->index); - - if (rt->rt_metric != 0) - add_attr_32(&nlm.hdr, sizeof(nlm), RTA_PRIORITY, - rt->rt_metric); - - return send_netlink(rt->rt_ifp->ctx, NULL, - NETLINK_ROUTE, &nlm.hdr, NULL); -} - -static int -_if_initrt(struct dhcpcd_ctx *ctx, void *arg, - struct nlmsghdr *nlm) -{ - struct rt rt, *rtn; - rb_tree_t *kroutes = arg; - - if (if_copyrt(ctx, &rt, nlm) != 0) - return 0; - if ((rtn = rt_new(rt.rt_ifp)) == NULL) { - logerr(__func__); - return 0; - } - memcpy(rtn, &rt, sizeof(*rtn)); - if (rb_tree_insert_node(kroutes, rtn) != rtn) - rt_free(rtn); - return 0; -} - -int -if_initrt(struct dhcpcd_ctx *ctx, rb_tree_t *kroutes, int af) -{ - struct nlmr nlm = { - .hdr.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg)), - .hdr.nlmsg_type = RTM_GETROUTE, - .hdr.nlmsg_flags = NLM_F_REQUEST | NLM_F_MATCH, - .rt.rtm_table = RT_TABLE_MAIN, - .rt.rtm_family = (unsigned char)af, - }; - - return send_netlink(ctx, kroutes, NETLINK_ROUTE, &nlm.hdr, &_if_initrt); -} - - -#ifdef INET -/* Linux is a special snowflake when it comes to BPF. */ -const char *bpf_name = "Packet Socket"; -#define BPF_BUFFER_LEN 1500 - -int -bpf_open(struct interface *ifp, int (*filter)(struct interface *, int)) -{ - struct ipv4_state *state; -/* Linux is a special snowflake for opening BPF. */ - int s; - union sockunion { - struct sockaddr sa; - struct sockaddr_ll sll; - struct sockaddr_storage ss; - } su; -#ifdef PACKET_AUXDATA - int n; -#endif - -#define SF SOCK_CLOEXEC | SOCK_NONBLOCK - if ((s = xsocket(PF_PACKET, SOCK_RAW | SF, htons(ETH_P_ALL))) == -1) - return -1; -#undef SF - - /* Allocate a suitably large buffer for a single packet. */ - state = ipv4_getstate(ifp); - if (state == NULL) - goto eexit; - if (state->buffer_size < ETH_DATA_LEN) { - void *nb; - - if ((nb = realloc(state->buffer, ETH_DATA_LEN)) == NULL) - goto eexit; - state->buffer = nb; - state->buffer_size = ETH_DATA_LEN; - state->buffer_len = state->buffer_pos = 0; - } - - if (filter(ifp, s) != 0) - goto eexit; - -#ifdef PACKET_AUXDATA - n = 1; - if (setsockopt(s, SOL_PACKET, PACKET_AUXDATA, &n, sizeof(n)) != 0) { - if (errno != ENOPROTOOPT) - goto eexit; - } -#endif - - memset(&su, 0, sizeof(su)); - su.sll.sll_family = PF_PACKET; - su.sll.sll_protocol = htons(ETH_P_ALL); - su.sll.sll_ifindex = (int)ifp->index; - if (bind(s, &su.sa, sizeof(su.sll)) == -1) - goto eexit; - return s; - -eexit: - if (state != NULL) { - free(state->buffer); - state->buffer = NULL; - } - close(s); - return -1; -} - -/* BPF requires that we read the entire buffer. - * So we pass the buffer in the API so we can loop on >1 packet. */ -ssize_t -bpf_read(struct interface *ifp, int s, void *data, size_t len, - unsigned int *flags) -{ - ssize_t bytes; - struct ipv4_state *state = IPV4_STATE(ifp); - - struct iovec iov = { - .iov_base = state->buffer, - .iov_len = state->buffer_size - }; - struct msghdr msg = { .msg_iov = &iov, .msg_iovlen = 1 }; -#ifdef PACKET_AUXDATA - unsigned char cmsgbuf[CMSG_LEN(sizeof(struct tpacket_auxdata))] = { 0 }; - struct cmsghdr *cmsg; - struct tpacket_auxdata *aux; -#endif - -#ifdef PACKET_AUXDATA - msg.msg_control = cmsgbuf; - msg.msg_controllen = sizeof(cmsgbuf); -#endif - - bytes = recvmsg(s, &msg, 0); - if (bytes == -1) - return -1; - *flags |= BPF_EOF; /* We only ever read one packet. */ - *flags &= ~BPF_PARTIALCSUM; - if (bytes) { - ssize_t fl = (ssize_t)bpf_frame_header_len(ifp); - - if (bpf_frame_bcast(ifp, state->buffer) == 0) - *flags |= BPF_BCAST; - else - *flags &= ~BPF_BCAST; - bytes -= fl; - if ((size_t)bytes > len) - bytes = (ssize_t)len; - memcpy(data, state->buffer + fl, (size_t)bytes); -#ifdef PACKET_AUXDATA - for (cmsg = CMSG_FIRSTHDR(&msg); - cmsg; - cmsg = CMSG_NXTHDR(&msg, cmsg)) - { - if (cmsg->cmsg_level == SOL_PACKET && - cmsg->cmsg_type == PACKET_AUXDATA) { - aux = (void *)CMSG_DATA(cmsg); - if (aux->tp_status & TP_STATUS_CSUMNOTREADY) - *flags |= BPF_PARTIALCSUM; - } - } -#endif - } - return bytes; -} - -int -bpf_attach(int s, void *filter, unsigned int filter_len) -{ - struct sock_fprog pf = { - .filter = filter, - .len = (unsigned short)filter_len, - }; - - /* Install the filter. */ - return setsockopt(s, SOL_SOCKET, SO_ATTACH_FILTER, &pf, sizeof(pf)); -} - -int -if_address(unsigned char cmd, const struct ipv4_addr *ia) -{ - struct nlma nlm; - struct ifa_cacheinfo cinfo; - int retval = 0; -#ifdef IFA_F_NOPREFIXROUTE - uint32_t flags = 0; -#endif - - memset(&nlm, 0, sizeof(nlm)); - nlm.hdr.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg)); - nlm.hdr.nlmsg_flags = NLM_F_REQUEST; - nlm.hdr.nlmsg_type = cmd; - if (cmd == RTM_NEWADDR) - nlm.hdr.nlmsg_flags |= NLM_F_CREATE | NLM_F_REPLACE; - nlm.ifa.ifa_index = ia->iface->index; - nlm.ifa.ifa_family = AF_INET; - - nlm.ifa.ifa_prefixlen = inet_ntocidr(ia->mask); - -#if 0 - /* This creates the aliased interface */ - add_attr_l(&nlm.hdr, sizeof(nlm), IFA_LABEL, - ia->iface->alias, - (unsigned short)(strlen(ia->iface->alias) + 1)); -#endif - - add_attr_l(&nlm.hdr, sizeof(nlm), IFA_LOCAL, - &ia->addr.s_addr, sizeof(ia->addr.s_addr)); - - if (cmd == RTM_NEWADDR) { -#ifdef IFA_F_NOPREFIXROUTE - if (nlm.ifa.ifa_prefixlen < 32) - flags |= IFA_F_NOPREFIXROUTE; - add_attr_32(&nlm.hdr, sizeof(nlm), IFA_FLAGS, flags); -#endif - - add_attr_l(&nlm.hdr, sizeof(nlm), IFA_BROADCAST, - &ia->brd.s_addr, sizeof(ia->brd.s_addr)); - - memset(&cinfo, 0, sizeof(cinfo)); - cinfo.ifa_prefered = ia->pltime; - cinfo.ifa_valid = ia->vltime; - add_attr_l(&nlm.hdr, sizeof(nlm), IFA_CACHEINFO, - &cinfo, sizeof(cinfo)); - } - - if (send_netlink(ia->iface->ctx, NULL, - NETLINK_ROUTE, &nlm.hdr, NULL) == -1) - retval = -1; - return retval; -} - -int -if_addrflags(__unused const struct interface *ifp, -__unused const struct in_addr *addr, __unused const char *alias) -{ - - /* Linux has no support for IPv4 address flags */ - return 0; -} -#endif - -#ifdef INET6 -int -if_address6(unsigned char cmd, const struct ipv6_addr *ia) -{ - struct nlma nlm; - struct ifa_cacheinfo cinfo; -#if defined(IFA_F_MANAGETEMPADDR) || defined(IFA_F_NOPREFIXROUTE) - uint32_t flags = 0; -#endif - - memset(&nlm, 0, sizeof(nlm)); - nlm.hdr.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg)); - nlm.hdr.nlmsg_flags = NLM_F_REQUEST; - nlm.hdr.nlmsg_type = cmd; - if (cmd == RTM_NEWADDR) - nlm.hdr.nlmsg_flags |= NLM_F_CREATE | NLM_F_REPLACE; - nlm.ifa.ifa_index = ia->iface->index; - nlm.ifa.ifa_family = AF_INET6; - - /* Add as /128 if no IFA_F_NOPREFIXROUTE ? */ - nlm.ifa.ifa_prefixlen = ia->prefix_len; - -#if 0 - /* This creates the aliased interface */ - add_attr_l(&nlm.hdr, sizeof(nlm), IFA_LABEL, - ia->iface->alias, (unsigned short)(strlen(ia->iface->alias) + 1)); -#endif - add_attr_l(&nlm.hdr, sizeof(nlm), IFA_LOCAL, - &ia->addr.s6_addr, sizeof(ia->addr.s6_addr)); - - if (cmd == RTM_NEWADDR) { -#ifdef IPV6_MANAGETEMPADDR - if (ia->flags & IPV6_AF_TEMPORARY) { - /* Currently the kernel filters out these flags */ -#ifdef IFA_F_NOPREFIXROUTE - flags |= IFA_F_TEMPORARY; -#else - nlm.ifa.ifa_flags |= IFA_F_TEMPORARY; -#endif - } -#elif IFA_F_MANAGETEMPADDR - if (ia->flags & IPV6_AF_AUTOCONF) - flags |= IFA_F_MANAGETEMPADDR; -#endif -#ifdef IFA_F_NOPREFIXROUTE - if (!IN6_IS_ADDR_LINKLOCAL(&ia->addr)) - flags |= IFA_F_NOPREFIXROUTE; -#endif -#if defined(IFA_F_MANAGETEMPADDR) || defined(IFA_F_NOPREFIXROUTE) - add_attr_32(&nlm.hdr, sizeof(nlm), IFA_FLAGS, flags); -#endif - - memset(&cinfo, 0, sizeof(cinfo)); - cinfo.ifa_prefered = ia->prefix_pltime; - cinfo.ifa_valid = ia->prefix_vltime; - add_attr_l(&nlm.hdr, sizeof(nlm), IFA_CACHEINFO, - &cinfo, sizeof(cinfo)); - } - - return send_netlink(ia->iface->ctx, NULL, - NETLINK_ROUTE, &nlm.hdr, NULL); -} - -int -if_addrflags6(const struct interface *ifp, const struct in6_addr *addr, - __unused const char *alias) -{ - FILE *fp; - char *p, ifaddress[33], address[33], name[IF_NAMESIZE + 1]; - unsigned int ifindex; - int prefix, scope, flags, i; - - fp = fopen(PROC_INET6, "r"); - if (fp == NULL) - return -1; - - p = ifaddress; - for (i = 0; i < (int)sizeof(addr->s6_addr); i++) { - p += snprintf(p, 3, "%.2x", addr->s6_addr[i]); - } - *p = '\0'; - - while (fscanf(fp, "%32[a-f0-9] %x %x %x %x %"TOSTRING(IF_NAMESIZE)"s\n", - address, &ifindex, &prefix, &scope, &flags, name) == 6) - { - if (strlen(address) != 32) { - fclose(fp); - errno = EINVAL; - return -1; - } - if (strcmp(name, ifp->name) == 0 && - strcmp(ifaddress, address) == 0) - { - fclose(fp); - return flags; - } - } - - fclose(fp); - errno = ESRCH; - return -1; -} - -int -if_getlifetime6(__unused struct ipv6_addr *ia) -{ - - /* God knows how to work out address lifetimes on Linux */ - errno = ENOTSUP; - return -1; -} - -struct nlml -{ - struct nlmsghdr hdr; - struct ifinfomsg i; - char buffer[32]; -}; - -static int -add_attr_8(struct nlmsghdr *n, unsigned short maxlen, unsigned short type, - uint8_t data) -{ - - return add_attr_l(n, maxlen, type, &data, sizeof(data)); -} - -static struct rtattr * -add_attr_nest(struct nlmsghdr *n, unsigned short maxlen, unsigned short type) -{ - struct rtattr *nest; - - nest = NLMSG_TAIL(n); - add_attr_l(n, maxlen, type, NULL, 0); - return nest; -} - -static void -add_attr_nest_end(struct nlmsghdr *n, struct rtattr *nest) -{ - - nest->rta_len = (unsigned short)((char *)NLMSG_TAIL(n) - (char *)nest); -} - -static int -if_disable_autolinklocal(struct dhcpcd_ctx *ctx, unsigned int ifindex) -{ -#ifdef HAVE_IN6_ADDR_GEN_MODE_NONE - struct nlml nlm; - struct rtattr *afs, *afs6; - - memset(&nlm, 0, sizeof(nlm)); - nlm.hdr.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg)); - nlm.hdr.nlmsg_type = RTM_NEWLINK; - nlm.hdr.nlmsg_flags = NLM_F_REQUEST; - nlm.i.ifi_family = AF_INET6; - nlm.i.ifi_index = (int)ifindex; - afs = add_attr_nest(&nlm.hdr, sizeof(nlm), IFLA_AF_SPEC); - afs6 = add_attr_nest(&nlm.hdr, sizeof(nlm), AF_INET6); - add_attr_8(&nlm.hdr, sizeof(nlm), IFLA_INET6_ADDR_GEN_MODE, - IN6_ADDR_GEN_MODE_NONE); - add_attr_nest_end(&nlm.hdr, afs6); - add_attr_nest_end(&nlm.hdr, afs); - - return send_netlink(ctx, NULL, NETLINK_ROUTE, &nlm.hdr, NULL); -#else - UNUSED(ctx); - UNUSED(ifindex); - errno = ENOTSUP; - return -1; -#endif -} - -static const char *prefix = "/proc/sys/net/ipv6/conf"; - -void -if_setup_inet6(const struct interface *ifp) -{ - int ra; - char path[256]; - - /* The kernel cannot make stable private addresses. */ - if (if_disable_autolinklocal(ifp->ctx, ifp->index) == -1) - logdebug("%s: if_disable_autolinklocal", ifp->name); - - /* - * If not doing autoconf, don't disable the kernel from doing it. - * If we need to, we should have another option actively disable it. - */ - if (!(ifp->options->options & DHCPCD_IPV6RS)) - return; - - snprintf(path, sizeof(path), "%s/%s/autoconf", prefix, ifp->name); - ra = check_proc_int(path); - if (ra != 1 && ra != -1) { - if (write_path(path, "0") == -1) - logerr("%s: %s", __func__, path); - } - - snprintf(path, sizeof(path), "%s/%s/accept_ra", prefix, ifp->name); - ra = check_proc_int(path); - if (ra == -1) { - logfunc_t *logfunc = errno == ENOENT? logdebug : logwarn; - - /* The sysctl probably doesn't exist, but this isn't an - * error as such so just log it and continue */ - logfunc("%s", path); - } else if (ra != 0) { - if (write_path(path, "0") == -1) - logerr("%s: %s", __func__, path); - } -} - -#ifdef IPV6_MANAGETEMPADDR -int -ip6_use_tempaddr(const char *ifname) -{ - char path[256]; - int val; - - if (ifname == NULL) - ifname = "all"; - snprintf(path, sizeof(path), "%s/%s/use_tempaddr", prefix, ifname); - val = check_proc_int(path); - return val == -1 ? 0 : val; -} - -int -ip6_temp_preferred_lifetime(const char *ifname) -{ - char path[256]; - int val; - - if (ifname == NULL) - ifname = "all"; - snprintf(path, sizeof(path), "%s/%s/temp_prefered_lft", prefix, - ifname); - val = check_proc_int(path); - return val < 0 ? TEMP_PREFERRED_LIFETIME : val; -} - -int -ip6_temp_valid_lifetime(const char *ifname) -{ - char path[256]; - int val; - - if (ifname == NULL) - ifname = "all"; - snprintf(path, sizeof(path), "%s/%s/temp_valid_lft", prefix, ifname); - val = check_proc_int(path); - return val < 0 ? TEMP_VALID_LIFETIME : val; -} -#endif /* IPV6_MANAGETEMPADDR */ - -int -ip6_forwarding(const char *ifname) -{ - char path[256]; - int val; - - if (ifname == NULL) - ifname = "all"; - snprintf(path, sizeof(path), "%s/%s/forwarding", prefix, ifname); - val = check_proc_int(path); - return val == -1 ? 0 : val; -} - -#endif /* INET6 */ diff --git a/external/bsd/dhcpcd/dist/src/if-options.c b/external/bsd/dhcpcd/dist/src/if-options.c index f0165c13b7c..f3f12316a2b 100644 --- a/external/bsd/dhcpcd/dist/src/if-options.c +++ b/external/bsd/dhcpcd/dist/src/if-options.c @@ -520,7 +520,7 @@ parse_addr(__unused struct in_addr *addr, __unused struct in_addr *net, } #endif -static const char * +static void set_option_space(struct dhcpcd_ctx *ctx, const char *arg, const struct dhcp_opt **d, size_t *dl, @@ -543,7 +543,7 @@ set_option_space(struct dhcpcd_ctx *ctx, *require = ifo->requiremasknd; *no = ifo->nomasknd; *reject = ifo->rejectmasknd; - return arg + strlen("nd_"); + return; } #ifdef DHCP6 @@ -556,7 +556,7 @@ set_option_space(struct dhcpcd_ctx *ctx, *require = ifo->requiremask6; *no = ifo->nomask6; *reject = ifo->rejectmask6; - return arg + strlen("dhcp6_"); + return; } #endif #endif @@ -576,7 +576,6 @@ set_option_space(struct dhcpcd_ctx *ctx, *require = ifo->requiremask; *no = ifo->nomask; *reject = ifo->rejectmask; - return arg; } void @@ -806,7 +805,7 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo, break; case 'o': ARG_REQUIRED; - arg = set_option_space(ctx, arg, &d, &dl, &od, &odl, ifo, + set_option_space(ctx, arg, &d, &dl, &od, &odl, ifo, &request, &require, &no, &reject); if (make_option_mask(d, dl, od, odl, request, arg, 1) != 0 || make_option_mask(d, dl, od, odl, no, arg, -1) != 0 || @@ -818,7 +817,7 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo, break; case O_REJECT: ARG_REQUIRED; - arg = set_option_space(ctx, arg, &d, &dl, &od, &odl, ifo, + set_option_space(ctx, arg, &d, &dl, &od, &odl, ifo, &request, &require, &no, &reject); if (make_option_mask(d, dl, od, odl, reject, arg, 1) != 0 || make_option_mask(d, dl, od, odl, request, arg, -1) != 0 || @@ -1053,7 +1052,7 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo, break; case 'O': ARG_REQUIRED; - arg = set_option_space(ctx, arg, &d, &dl, &od, &odl, ifo, + set_option_space(ctx, arg, &d, &dl, &od, &odl, ifo, &request, &require, &no, &reject); if (make_option_mask(d, dl, od, odl, request, arg, -1) != 0 || make_option_mask(d, dl, od, odl, require, arg, -1) != 0 || @@ -1065,7 +1064,7 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo, break; case 'Q': ARG_REQUIRED; - arg = set_option_space(ctx, arg, &d, &dl, &od, &odl, ifo, + set_option_space(ctx, arg, &d, &dl, &od, &odl, ifo, &request, &require, &no, &reject); if (make_option_mask(d, dl, od, odl, require, arg, 1) != 0 || make_option_mask(d, dl, od, odl, request, arg, 1) != 0 || @@ -1253,7 +1252,7 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo, break; case O_DESTINATION: ARG_REQUIRED; - arg = set_option_space(ctx, arg, &d, &dl, &od, &odl, ifo, + set_option_space(ctx, arg, &d, &dl, &od, &odl, ifo, &request, &require, &no, &reject); if (make_option_mask(d, dl, od, odl, ifo->dstmask, arg, 2) != 0) diff --git a/external/bsd/dhcpcd/dist/src/if-sun.c b/external/bsd/dhcpcd/dist/src/if-sun.c deleted file mode 100644 index 687a6ad093d..00000000000 --- a/external/bsd/dhcpcd/dist/src/if-sun.c +++ /dev/null @@ -1,1719 +0,0 @@ -/* SPDX-License-Identifier: BSD-2-Clause */ -/* - * Solaris interface driver for dhcpcd - * Copyright (c) 2016-2019 Roy Marples <roy@marples.name> - * 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. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. - */ - -#include <assert.h> -#include <errno.h> -#include <fcntl.h> -#include <ifaddrs.h> -#include <libdlpi.h> -#include <kstat.h> -#include <stddef.h> -#include <stdlib.h> -#include <stropts.h> -#include <string.h> -#include <unistd.h> - -#include <inet/ip.h> - -#include <net/if_dl.h> -#include <net/if_types.h> - -#include <netinet/if_ether.h> -#include <netinet/udp.h> - -#include <sys/ioctl.h> -#include <sys/mac.h> -#include <sys/pfmod.h> -#include <sys/tihdr.h> -#include <sys/utsname.h> - -/* Private libsocket interface we can hook into to get - * a better getifaddrs(3). - * From libsocket_priv.h, which is not always distributed so is here. */ -extern int getallifaddrs(sa_family_t, struct ifaddrs **, int64_t); - -#include "config.h" -#include "bpf.h" -#include "common.h" -#include "dhcp.h" -#include "if.h" -#include "if-options.h" -#include "ipv4.h" -#include "ipv6.h" -#include "ipv6nd.h" -#include "logerr.h" -#include "route.h" -#include "sa.h" - -#ifndef ARP_MOD_NAME -# define ARP_MOD_NAME "arp" -#endif - -#ifndef RT_ROUNDUP -#define RT_ROUNDUP(a) \ - ((a) > 0 ? (1 + (((a) - 1) | (sizeof(int32_t) - 1))) : sizeof(int32_t)) -#define RT_ADVANCE(x, n) ((x) += RT_ROUNDUP(sa_len((n)))) -#endif - -#define COPYOUT(sin, sa) do { \ - if ((sa) && ((sa)->sa_family == AF_INET)) \ - (sin) = ((const struct sockaddr_in *)(const void *) \ - (sa))->sin_addr; \ - } while (0) - -#define COPYOUT6(sin, sa) do { \ - if ((sa) && ((sa)->sa_family == AF_INET6)) \ - (sin) = ((const struct sockaddr_in6 *)(const void *) \ - (sa))->sin6_addr; \ - } while (0) - -#define COPYSA(dst, src) memcpy((dst), (src), sa_len((src))) - -struct priv { -#ifdef INET6 - int pf_inet6_fd; -#endif -}; - -struct rtm -{ - struct rt_msghdr hdr; - char buffer[sizeof(struct sockaddr_storage) * RTAX_MAX]; -}; - -static int if_plumb(int, const struct dhcpcd_ctx *, int, const char *); - -int -if_init(struct interface *ifp) -{ - -#ifdef INET - if (if_plumb(RTM_NEWADDR, ifp->ctx, AF_INET, ifp->name) == -1 && - errno != EEXIST) - return -1; -#endif - -#ifdef INET6 - if (if_plumb(RTM_NEWADDR, ifp->ctx, AF_INET6, ifp->name) == -1 && - errno != EEXIST) - return -1; -#endif - - if (ifp->index == 0) - ifp->index = if_nametoindex(ifp->name); - - return 0; -} - -int -if_conf(__unused struct interface *ifp) -{ - - return 0; -} - -int -if_opensockets_os(struct dhcpcd_ctx *ctx) -{ - struct priv *priv; - int n; - - if ((priv = malloc(sizeof(*priv))) == NULL) - return -1; - ctx->priv = priv; - -#ifdef INET6 - priv->pf_inet6_fd = xsocket(PF_INET6, SOCK_DGRAM | SOCK_CLOEXEC, 0); - /* Don't return an error so we at least work on kernels witout INET6 - * even though we expect INET6 support. - * We will fail noisily elsewhere anyway. */ -#endif - - ctx->link_fd = socket(PF_ROUTE, - SOCK_RAW | SOCK_CLOEXEC | SOCK_NONBLOCK, 0); - - if (ctx->link_fd == -1) { - free(ctx->priv); - return -1; - } - - /* Ignore our own route(4) messages. - * Sadly there is no way of doing this for route(4) messages - * generated from addresses we add/delete. */ - n = 0; - if (setsockopt(ctx->link_fd, SOL_SOCKET, SO_USELOOPBACK, - &n, sizeof(n)) == -1) - logerr("%s: SO_USELOOPBACK", __func__); - - return 0; -} - -void -if_closesockets_os(struct dhcpcd_ctx *ctx) -{ -#ifdef INET6 - struct priv *priv; - - priv = (struct priv *)ctx->priv; - if (priv->pf_inet6_fd != -1) - close(priv->pf_inet6_fd); -#endif - - /* each interface should have closed itself */ - free(ctx->priv); -} - -int -if_carrier(struct interface *ifp) -{ - kstat_ctl_t *kcp; - kstat_t *ksp; - kstat_named_t *knp; - link_state_t linkstate; - - if (if_getflags(ifp) == -1) - return LINK_UNKNOWN; - - kcp = kstat_open(); - if (kcp == NULL) - goto err; - ksp = kstat_lookup(kcp, UNCONST("link"), 0, ifp->name); - if (ksp == NULL) - goto err; - if (kstat_read(kcp, ksp, NULL) == -1) - goto err; - knp = kstat_data_lookup(ksp, UNCONST("link_state")); - if (knp == NULL) - goto err; - if (knp->data_type != KSTAT_DATA_UINT32) - goto err; - linkstate = (link_state_t)knp->value.ui32; - kstat_close(kcp); - - switch (linkstate) { - case LINK_STATE_UP: - ifp->flags |= IFF_UP; - return LINK_UP; - case LINK_STATE_DOWN: - return LINK_DOWN; - default: - return LINK_UNKNOWN; - } - -err: - if (kcp != NULL) - kstat_close(kcp); - return LINK_UNKNOWN; -} - -int -if_mtu_os(const struct interface *ifp) -{ - dlpi_handle_t dh; - dlpi_info_t dlinfo; - int mtu; - - if (dlpi_open(ifp->name, &dh, 0) != DLPI_SUCCESS) - return -1; - if (dlpi_info(dh, &dlinfo, 0) == DLPI_SUCCESS) - mtu = dlinfo.di_max_sdu; - else - mtu = -1; - dlpi_close(dh); - return mtu; -} - -int -if_getssid(struct interface *ifp) -{ - - UNUSED(ifp); - errno = ENOTSUP; - return -1; -} - -unsigned short -if_vlanid(__unused const struct interface *ifp) -{ - - return 0; -} - -int -if_vimaster(__unused const struct dhcpcd_ctx *ctx, __unused const char *ifname) -{ - - return 0; -} - -int -if_machinearch(__unused char *str, __unused size_t len) -{ - - /* There is no extra data really. - * isainfo -v does return amd64, but also i386. */ - return 0; -} - -struct linkwalk { - struct ifaddrs *lw_ifa; - int lw_error; -}; - -static boolean_t -if_newaddr(const char *ifname, void *arg) -{ - struct linkwalk *lw = arg; - int error; - struct ifaddrs *ifa; - dlpi_handle_t dh; - dlpi_info_t dlinfo; - uint8_t pa[DLPI_PHYSADDR_MAX]; - size_t pa_len; - struct sockaddr_dl *sdl; - - ifa = NULL; - error = dlpi_open(ifname, &dh, 0); - if (error == DLPI_ENOLINK) /* Just vanished or in global zone */ - return B_FALSE; - if (error != DLPI_SUCCESS) - goto failed1; - if (dlpi_info(dh, &dlinfo, 0) != DLPI_SUCCESS) - goto failed; - - /* For some reason, dlpi_info won't return the - * physical address, it's all zero's. - * So cal dlpi_get_physaddr. */ - pa_len = DLPI_PHYSADDR_MAX; - if (dlpi_get_physaddr(dh, DL_CURR_PHYS_ADDR, - pa, &pa_len) != DLPI_SUCCESS) - goto failed; - - if ((ifa = calloc(1, sizeof(*ifa))) == NULL) - goto failed; - if ((ifa->ifa_name = strdup(ifname)) == NULL) - goto failed; - if ((sdl = calloc(1, sizeof(*sdl))) == NULL) - goto failed; - - ifa->ifa_addr = (struct sockaddr *)sdl; - sdl->sdl_index = if_nametoindex(ifname); - sdl->sdl_family = AF_LINK; - switch (dlinfo.di_mactype) { - case DL_ETHER: - sdl->sdl_type = IFT_ETHER; - break; - case DL_IB: - sdl->sdl_type = IFT_IB; - break; - default: - sdl->sdl_type = IFT_OTHER; - break; - } - - sdl->sdl_alen = pa_len; - memcpy(sdl->sdl_data, pa, pa_len); - - ifa->ifa_next = lw->lw_ifa; - lw->lw_ifa = ifa; - dlpi_close(dh); - return B_FALSE; - -failed: - dlpi_close(dh); - if (ifa != NULL) { - free(ifa->ifa_name); - free(ifa->ifa_addr); - free(ifa); - } -failed1: - lw->lw_error = errno; - return B_TRUE; -} - -/* Creates an empty sockaddr_dl for lo0. */ -static struct ifaddrs * -if_ifa_lo0(void) -{ - struct ifaddrs *ifa; - struct sockaddr_dl *sdl; - - if ((ifa = calloc(1, sizeof(*ifa))) == NULL) - return NULL; - if ((sdl = calloc(1, sizeof(*sdl))) == NULL) { - free(ifa); - return NULL; - } - if ((ifa->ifa_name = strdup("lo0")) == NULL) { - free(ifa); - free(sdl); - return NULL; - } - - ifa->ifa_addr = (struct sockaddr *)sdl; - ifa->ifa_flags = IFF_LOOPBACK; - sdl->sdl_family = AF_LINK; - sdl->sdl_index = if_nametoindex("lo0"); - - return ifa; -} - -/* getifaddrs(3) does not support AF_LINK, strips aliases and won't - * report addresses that are not UP. - * As such it's just totally useless, so we need to roll our own. */ -int -if_getifaddrs(struct ifaddrs **ifap) -{ - struct linkwalk lw; - struct ifaddrs *ifa; - - /* Private libc function which we should not have to call - * to get non UP addresses. */ - if (getallifaddrs(AF_UNSPEC, &lw.lw_ifa, 0) == -1) - return -1; - - /* Start with some AF_LINK addresses. */ - lw.lw_error = 0; - dlpi_walk(if_newaddr, &lw, 0); - if (lw.lw_error != 0) { - freeifaddrs(lw.lw_ifa); - errno = lw.lw_error; - return -1; - } - - /* lo0 doesn't appear in dlpi_walk, so fudge it. */ - if ((ifa = if_ifa_lo0()) == NULL) { - freeifaddrs(lw.lw_ifa); - return -1; - } - ifa->ifa_next = lw.lw_ifa; - - *ifap = ifa; - return 0; -} - -static void -if_linkaddr(struct sockaddr_dl *sdl, const struct interface *ifp) -{ - - memset(sdl, 0, sizeof(*sdl)); - sdl->sdl_family = AF_LINK; - sdl->sdl_nlen = sdl->sdl_alen = sdl->sdl_slen = 0; - sdl->sdl_index = (unsigned short)ifp->index; -} - -static int -get_addrs(int type, const void *data, size_t data_len, - const struct sockaddr **sa) -{ - const char *cp, *ep; - int i; - - cp = data; - ep = cp + data_len; - for (i = 0; i < RTAX_MAX; i++) { - if (type & (1 << i)) { - if (cp >= ep) { - errno = EINVAL; - return -1; - } - sa[i] = (const struct sockaddr *)cp; - RT_ADVANCE(cp, sa[i]); - } else - sa[i] = NULL; - } - - return 0; -} - -static struct interface * -if_findsdl(struct dhcpcd_ctx *ctx, const struct sockaddr_dl *sdl) -{ - - if (sdl->sdl_index) - return if_findindex(ctx->ifaces, sdl->sdl_index); - - if (sdl->sdl_nlen) { - char ifname[IF_NAMESIZE]; - - memcpy(ifname, sdl->sdl_data, sdl->sdl_nlen); - ifname[sdl->sdl_nlen] = '\0'; - return if_find(ctx->ifaces, ifname); - } - if (sdl->sdl_alen) { - struct interface *ifp; - - TAILQ_FOREACH(ifp, ctx->ifaces, next) { - if (ifp->hwlen == sdl->sdl_alen && - memcmp(ifp->hwaddr, - sdl->sdl_data, sdl->sdl_alen) == 0) - return ifp; - } - } - - errno = ENOENT; - return NULL; -} - -static struct interface * -if_findsa(struct dhcpcd_ctx *ctx, const struct sockaddr *sa) -{ - if (sa == NULL) { - errno = EINVAL; - return NULL; - } - - switch (sa->sa_family) { - case AF_LINK: - { - const struct sockaddr_dl *sdl; - - sdl = (const void *)sa; - return if_findsdl(ctx, sdl); - } -#ifdef INET - case AF_INET: - { - const struct sockaddr_in *sin; - struct ipv4_addr *ia; - - sin = (const void *)sa; - if ((ia = ipv4_findmaskaddr(ctx, &sin->sin_addr))) - return ia->iface; - break; - } -#endif -#ifdef INET6 - case AF_INET6: - { - const struct sockaddr_in6 *sin; - struct ipv6_addr *ia; - - sin = (const void *)sa; - if ((ia = ipv6_findmaskaddr(ctx, &sin->sin6_addr))) - return ia->iface; - break; - } -#endif - default: - errno = EAFNOSUPPORT; - return NULL; - } - - errno = ENOENT; - return NULL; -} - -static void -if_route0(struct dhcpcd_ctx *ctx, struct rtm *rtmsg, - unsigned char cmd, const struct rt *rt) -{ - struct rt_msghdr *rtm; - char *bp = rtmsg->buffer; - socklen_t sl; - bool gateway_unspec; - - /* WARNING: Solaris will not allow you to delete RTF_KERNEL routes. - * This includes subnet/prefix routes. */ - -#define ADDSA(sa) do { \ - sl = sa_len((sa)); \ - memcpy(bp, (sa), sl); \ - bp += RT_ROUNDUP(sl); \ - } while (/* CONSTCOND */ 0) - - memset(rtmsg, 0, sizeof(*rtmsg)); - rtm = &rtmsg->hdr; - rtm->rtm_version = RTM_VERSION; - rtm->rtm_type = cmd; - rtm->rtm_seq = ++ctx->seq; - rtm->rtm_flags = rt->rt_flags; - rtm->rtm_addrs = RTA_DST | RTA_GATEWAY; - - gateway_unspec = sa_is_unspecified(&rt->rt_gateway); - - if (cmd == RTM_ADD || cmd == RTM_CHANGE) { - bool netmask_bcast = sa_is_allones(&rt->rt_netmask); - - rtm->rtm_flags |= RTF_UP; - if (!(rtm->rtm_flags & RTF_REJECT) && - !sa_is_loopback(&rt->rt_gateway)) - { - rtm->rtm_addrs |= RTA_IFP; - /* RTA_IFA is currently ignored by the kernel. - * RTA_SRC and RTF_SETSRC look like what we want, - * but they don't work with RTF_GATEWAY. - * We set RTA_IFA just in the hope that the - * kernel will one day support this. */ - if (!sa_is_unspecified(&rt->rt_ifa)) - rtm->rtm_addrs |= RTA_IFA; - } - - if (netmask_bcast) - rtm->rtm_flags |= RTF_HOST; - else if (!gateway_unspec) - rtm->rtm_flags |= RTF_GATEWAY; - - /* Emulate the kernel by marking address generated - * network routes non-static. */ - if (!(rt->rt_dflags & RTDF_IFA_ROUTE)) - rtm->rtm_flags |= RTF_STATIC; - - if (rt->rt_mtu != 0) { - rtm->rtm_inits |= RTV_MTU; - rtm->rtm_rmx.rmx_mtu = rt->rt_mtu; - } - } - - if (!(rtm->rtm_flags & RTF_HOST)) - rtm->rtm_addrs |= RTA_NETMASK; - - ADDSA(&rt->rt_dest); - - if (gateway_unspec) - ADDSA(&rt->rt_ifa); - else - ADDSA(&rt->rt_gateway); - - if (rtm->rtm_addrs & RTA_NETMASK) - ADDSA(&rt->rt_netmask); - - if (rtm->rtm_addrs & RTA_IFP) { - struct sockaddr_dl sdl; - - if_linkaddr(&sdl, rt->rt_ifp); - ADDSA((struct sockaddr *)&sdl); - } - - if (rtm->rtm_addrs & RTA_IFA) - ADDSA(&rt->rt_ifa); - -#if 0 - if (rtm->rtm_addrs & RTA_SRC) - ADDSA(&rt->rt_ifa); -#endif - - rtm->rtm_msglen = (unsigned short)(bp - (char *)rtm); -} - -int -if_route(unsigned char cmd, const struct rt *rt) -{ - struct rtm rtm; - struct dhcpcd_ctx *ctx = rt->rt_ifp->ctx; - - if_route0(ctx, &rtm, cmd, rt); - - if (write(ctx->link_fd, &rtm, rtm.hdr.rtm_msglen) == -1) - return -1; - return 0; -} - -static int -if_copyrt(struct dhcpcd_ctx *ctx, struct rt *rt, const struct rt_msghdr *rtm) -{ - const struct sockaddr *rti_info[RTAX_MAX]; - - if (~rtm->rtm_addrs & RTA_DST) { - errno = EINVAL; - return -1; - } - - if (get_addrs(rtm->rtm_addrs, (const char *)rtm + sizeof(*rtm), - rtm->rtm_msglen - sizeof(*rtm), rti_info) == -1) - return -1; - - memset(rt, 0, sizeof(*rt)); - - rt->rt_flags = (unsigned int)rtm->rtm_flags; - COPYSA(&rt->rt_dest, rti_info[RTAX_DST]); - if (rtm->rtm_addrs & RTA_NETMASK) - COPYSA(&rt->rt_netmask, rti_info[RTAX_NETMASK]); - - /* dhcpcd likes an unspecified gateway to indicate via the link. - * However we need to know if gateway was a link with an address. */ - if (rtm->rtm_addrs & RTA_GATEWAY) { - if (rti_info[RTAX_GATEWAY]->sa_family == AF_LINK) { - const struct sockaddr_dl *sdl; - - sdl = (const struct sockaddr_dl*) - (const void *)rti_info[RTAX_GATEWAY]; - if (sdl->sdl_alen != 0) - rt->rt_dflags |= RTDF_GATELINK; - } else if (rtm->rtm_flags & RTF_GATEWAY) - COPYSA(&rt->rt_gateway, rti_info[RTAX_GATEWAY]); - } - - if (rtm->rtm_addrs & RTA_SRC) - COPYSA(&rt->rt_ifa, rti_info[RTAX_SRC]); - rt->rt_mtu = (unsigned int)rtm->rtm_rmx.rmx_mtu; - - if (rtm->rtm_index) - rt->rt_ifp = if_findindex(ctx->ifaces, rtm->rtm_index); - else if (rtm->rtm_addrs & RTA_IFP) - rt->rt_ifp = if_findsa(ctx, rti_info[RTAX_IFP]); - else if (rtm->rtm_addrs & RTA_GATEWAY) - rt->rt_ifp = if_findsa(ctx, rti_info[RTAX_GATEWAY]); - else - rt->rt_ifp = if_findsa(ctx, rti_info[RTAX_DST]); - - if (rt->rt_ifp == NULL && rtm->rtm_type == RTM_MISS) - rt->rt_ifp = if_loopback(ctx); - - if (rt->rt_ifp == NULL) { - errno = ESRCH; - return -1; - } - - return 0; -} - -static struct rt * -if_route_get(struct dhcpcd_ctx *ctx, struct rt *rt) -{ - struct rtm rtm; - int s; - struct iovec iov = { .iov_base = &rtm, .iov_len = sizeof(rtm) }; - struct msghdr msg = { .msg_iov = &iov, .msg_iovlen = 1 }; - ssize_t len; - struct rt *rtw = rt; - - if_route0(ctx, &rtm, RTM_GET, rt); - rt = NULL; - s = socket(PF_ROUTE, SOCK_RAW | SOCK_CLOEXEC, 0); - if (s == -1) - return NULL; - if (write(s, &rtm, rtm.hdr.rtm_msglen) == -1) - goto out; - if ((len = recvmsg(s, &msg, 0)) == -1) - goto out; - if ((size_t)len < sizeof(rtm.hdr) || len < rtm.hdr.rtm_msglen) { - errno = EINVAL; - goto out; - } - if (if_copyrt(ctx, rtw, &rtm.hdr) == -1) - goto out; - rt = rtw; - -out: - close(s); - return rt; -} - -static int -if_finishrt(struct dhcpcd_ctx *ctx, struct rt *rt) -{ - int mtu; - - /* Solaris has a subnet route with the gateway - * of the owning address. - * dhcpcd has a blank gateway here to indicate a - * subnet route. */ - if (!sa_is_unspecified(&rt->rt_dest) && - !sa_is_unspecified(&rt->rt_gateway)) - { - switch(rt->rt_gateway.sa_family) { -#ifdef INET - case AF_INET: - { - struct in_addr *in; - - in = &satosin(&rt->rt_gateway)->sin_addr; - if (ipv4_findaddr(ctx, in)) - in->s_addr = INADDR_ANY; - break; - } -#endif -#ifdef INET6 - case AF_INET6: - { - struct in6_addr *in6; - - in6 = &satosin6(&rt->rt_gateway)->sin6_addr; - if (ipv6_findaddr(ctx, in6, 0)) - *in6 = in6addr_any; - break; - } -#endif - } - } - - /* Solaris doesn't set interfaces for some routes. - * This sucks, so we need to call RTM_GET to - * work out the interface. */ - if (rt->rt_ifp == NULL) { - if (if_route_get(ctx, rt) == NULL) { - rt->rt_ifp = if_loopback(ctx); - if (rt->rt_ifp == NULL) - return - 1; - } - } - - /* Solaris likes to set route MTU to match - * interface MTU when adding routes. - * This confuses dhcpcd as it expects MTU to be 0 - * when no explicit MTU has been set. */ - mtu = if_getmtu(rt->rt_ifp); - if (mtu == -1) - return -1; - if (rt->rt_mtu == (unsigned int)mtu) - rt->rt_mtu = 0; - - return 0; -} - -static int -if_addrflags0(int fd, int af, const char *ifname) -{ - struct lifreq lifr; - int flags; - - memset(&lifr, 0, sizeof(lifr)); - strlcpy(lifr.lifr_name, ifname, sizeof(lifr.lifr_name)); - if (ioctl(fd, SIOCGLIFFLAGS, &lifr) == -1) - return -1; - - flags = 0; - if (lifr.lifr_flags & IFF_DUPLICATE) - flags |= af == AF_INET6 ? IN6_IFF_DUPLICATED:IN_IFF_DUPLICATED; - else if (!(lifr.lifr_flags & IFF_UP)) - flags |= af == AF_INET6 ? IN6_IFF_TENTATIVE:IN_IFF_TENTATIVE; - return flags; -} - -static int -if_rtm(struct dhcpcd_ctx *ctx, const struct rt_msghdr *rtm) -{ - const struct sockaddr *sa; - struct rt rt; - - if (rtm->rtm_msglen < sizeof(*rtm) + sizeof(*sa)) { - errno = EINVAL; - return -1; - } - - if (if_copyrt(ctx, &rt, rtm) == -1 && errno != ESRCH) - return -1; - -#ifdef INET6 - /* - * BSD announces host routes. - * As such, we should be notified of reachability by its - * existance with a hardware address. - * Ensure we don't call this for a newly incomplete state. - */ - if (rt.rt_dest.sa_family == AF_INET6 && - (rt.rt_flags & RTF_HOST || rtm->rtm_type == RTM_MISS) && - !(rtm->rtm_type == RTM_ADD && !(rt.rt_dflags & RTDF_GATELINK))) - { - bool reachable; - - reachable = (rtm->rtm_type == RTM_ADD || - rtm->rtm_type == RTM_CHANGE) && - rt.rt_dflags & RTDF_GATELINK; - ipv6nd_neighbour(ctx, &rt.rt_ss_dest.sin6.sin6_addr, reachable); - } -#endif - - if (if_finishrt(ctx, &rt) == -1) - return -1; - rt_recvrt(rtm->rtm_type, &rt, rtm->rtm_pid); - return 0; -} - -static bool -if_getalias(struct interface *ifp, const struct sockaddr *sa, char *alias) -{ - struct ifaddrs *ifaddrs, *ifa; - struct interface *ifpx; - bool found; - - ifaddrs = NULL; - if (getallifaddrs(sa->sa_family, &ifaddrs, 0) == -1) - return false; - found = false; - for (ifa = ifaddrs; ifa != NULL; ifa = ifa->ifa_next) { - if (ifa->ifa_addr == NULL) - continue; - if (sa_cmp(sa, ifa->ifa_addr) != 0) - continue; - /* Check it's for the right interace. */ - ifpx = if_find(ifp->ctx->ifaces, ifa->ifa_name); - if (ifp == ifpx) { - strlcpy(alias, ifa->ifa_name, IF_NAMESIZE); - found = true; - break; - } - } - freeifaddrs(ifaddrs); - return found; -} - -static int -if_getbrdaddr(struct dhcpcd_ctx *ctx, const char *ifname, struct in_addr *brd) -{ - struct lifreq lifr = { 0 }; - int r; - - memset(&lifr, 0, sizeof(lifr)); - strlcpy(lifr.lifr_name, ifname, sizeof(lifr.lifr_name)); - errno = 0; - r = ioctl(ctx->pf_inet_fd, SIOCGLIFBRDADDR, &lifr, sizeof(lifr)); - if (r != -1) - COPYOUT(*brd, (struct sockaddr *)&lifr.lifr_broadaddr); - return r; -} - -static int -if_ifa(struct dhcpcd_ctx *ctx, const struct ifa_msghdr *ifam) -{ - struct interface *ifp; - const struct sockaddr *sa, *rti_info[RTAX_MAX]; - int flags; - char ifalias[IF_NAMESIZE]; - - if (ifam->ifam_msglen < sizeof(*ifam)) { - errno = EINVAL; - return -1; - } - if (~ifam->ifam_addrs & RTA_IFA) - return 0; - - if (get_addrs(ifam->ifam_addrs, (const char *)ifam + sizeof(*ifam), - ifam->ifam_msglen - sizeof(*ifam), rti_info) == -1) - return -1; - sa = rti_info[RTAX_IFA]; - - /* XXX We have no way of knowing who generated these - * messages wich truely sucks because we want to - * avoid listening to our own delete messages. */ - if ((ifp = if_findindex(ctx->ifaces, ifam->ifam_index)) == NULL) - return 0; - - /* - * ifa_msghdr does not supply the alias, just the interface index. - * This is very bad, because it means we have to call getifaddrs - * and trawl the list of addresses to find the added address. - * To make life worse, you can have the same address on the same - * interface with different aliases. - * So this hack is not entirely accurate. - * - * IF anyone is going to fix Solaris, plesse consider adding the - * following fields to extend ifa_msghdr: - * ifam_alias - * ifam_pid - */ - if (ifam->ifam_type != RTM_DELADDR && !if_getalias(ifp, sa, ifalias)) - return 0; - - switch (sa->sa_family) { - case AF_LINK: - { - struct sockaddr_dl sdl; - - if (ifam->ifam_type != RTM_CHGADDR && - ifam->ifam_type != RTM_NEWADDR) - break; - memcpy(&sdl, rti_info[RTAX_IFA], sizeof(sdl)); - dhcpcd_handlehwaddr(ctx, ifp->name, CLLADDR(&sdl),sdl.sdl_alen); - break; - } -#ifdef INET - case AF_INET: - { - struct in_addr addr, mask, bcast; - - COPYOUT(addr, rti_info[RTAX_IFA]); - COPYOUT(mask, rti_info[RTAX_NETMASK]); - COPYOUT(bcast, rti_info[RTAX_BRD]); - - if (ifam->ifam_type == RTM_DELADDR) { - struct ipv4_addr *ia; - - ia = ipv4_iffindaddr(ifp, &addr, &mask); - if (ia == NULL) - return 0; - strlcpy(ifalias, ia->alias, sizeof(ifalias)); - } else if (bcast.s_addr == INADDR_ANY) { - /* Work around a bug where broadcast - * address is not correctly reported. */ - if (if_getbrdaddr(ctx, ifalias, &bcast) == -1) - return 0; - } - flags = if_addrflags(ifp, NULL, ifalias); - if (ifam->ifam_type == RTM_DELADDR) { - if (flags != -1) - return 0; - } else if (flags == -1) - return 0; - - ipv4_handleifa(ctx, - ifam->ifam_type == RTM_CHGADDR ? - RTM_NEWADDR : ifam->ifam_type, - NULL, ifalias, &addr, &mask, &bcast, flags, 0); - break; - } -#endif -#ifdef INET6 - case AF_INET6: - { - struct in6_addr addr6, mask6; - const struct sockaddr_in6 *sin6; - - sin6 = (const void *)rti_info[RTAX_IFA]; - addr6 = sin6->sin6_addr; - sin6 = (const void *)rti_info[RTAX_NETMASK]; - mask6 = sin6->sin6_addr; - - if (ifam->ifam_type == RTM_DELADDR) { - struct ipv6_addr *ia; - - ia = ipv6_iffindaddr(ifp, &addr6, 0); - if (ia == NULL) - return 0; - strlcpy(ifalias, ia->alias, sizeof(ifalias)); - } - flags = if_addrflags6(ifp, NULL, ifalias); - if (ifam->ifam_type == RTM_DELADDR) { - if (flags != -1) - return 0; - } else if (flags == -1) - return 0; - - ipv6_handleifa(ctx, - ifam->ifam_type == RTM_CHGADDR ? - RTM_NEWADDR : ifam->ifam_type, - NULL, ifalias, &addr6, ipv6_prefixlen(&mask6), flags, 0); - break; - } -#endif - } - - return 0; -} - -static int -if_ifinfo(struct dhcpcd_ctx *ctx, const struct if_msghdr *ifm) -{ - struct interface *ifp; - int state; - unsigned int flags; - - if (ifm->ifm_msglen < sizeof(*ifm)) { - errno = EINVAL; - return -1; - } - - if ((ifp = if_findindex(ctx->ifaces, ifm->ifm_index)) == NULL) - return 0; - flags = (unsigned int)ifm->ifm_flags; - if (ifm->ifm_flags & IFF_OFFLINE) - state = LINK_DOWN; - else { - state = LINK_UP; - flags |= IFF_UP; - } - dhcpcd_handlecarrier(ctx, state, flags, ifp->name); - return 0; -} - -static int -if_dispatch(struct dhcpcd_ctx *ctx, const struct rt_msghdr *rtm) -{ - - if (rtm->rtm_version != RTM_VERSION) - return 0; - - switch(rtm->rtm_type) { - case RTM_IFINFO: - return if_ifinfo(ctx, (const void *)rtm); - case RTM_ADD: /* FALLTHROUGH */ - case RTM_CHANGE: /* FALLTHROUGH */ - case RTM_DELETE: /* FALLTHROUGH */ - case RTM_MISS: - return if_rtm(ctx, (const void *)rtm); - case RTM_CHGADDR: /* FALLTHROUGH */ - case RTM_DELADDR: /* FALLTHROUGH */ - case RTM_NEWADDR: - return if_ifa(ctx, (const void *)rtm); - } - - return 0; -} - -int -if_handlelink(struct dhcpcd_ctx *ctx) -{ - struct rtm rtm; - ssize_t len; - - len = read(ctx->link_fd, &rtm, sizeof(rtm)); - if (len == -1) - return -1; - if (len == 0) - return 0; - if ((size_t)len < sizeof(rtm.hdr.rtm_msglen) || - len != rtm.hdr.rtm_msglen) - { - errno = EINVAL; - return -1; - } - /* - * Coverity thinks that the data could be tainted from here. - * I have no idea how because the length of the data we read - * is guarded by len and checked to match rtm_msglen. - * The issue seems to be related to extracting the addresses - * at the end of the header, but seems to have no issues with the - * equivalent call in if_initrt. - */ - /* coverity[tainted_data] */ - return if_dispatch(ctx, &rtm.hdr); -} - -static void -if_octetstr(char *buf, const Octet_t *o, ssize_t len) -{ - int i; - char *p; - - p = buf; - for (i = 0; i < o->o_length; i++) { - if ((p + 1) - buf < len) - *p++ = o->o_bytes[i]; - else - break; - } - *p = '\0'; -} - -static int -if_setflags(int fd, const char *ifname, uint64_t flags) -{ - struct lifreq lifr = { .lifr_addrlen = 0 }; - - strlcpy(lifr.lifr_name, ifname, sizeof(lifr.lifr_name)); - if (ioctl(fd, SIOCGLIFFLAGS, &lifr) == -1) - return -1; - if ((lifr.lifr_flags & flags) != flags) { - lifr.lifr_flags |= flags; - if (ioctl(fd, SIOCSLIFFLAGS, &lifr) == -1) - return -1; - } - return 0; -} - -static int -if_addaddr(int fd, const char *ifname, - struct sockaddr_storage *addr, struct sockaddr_storage *mask, - struct sockaddr_storage *brd, uint8_t plen) -{ - struct lifreq lifr = { .lifr_addrlen = plen }; - - strlcpy(lifr.lifr_name, ifname, sizeof(lifr.lifr_name)); - - /* First assign the netmask. */ - lifr.lifr_addr = *mask; - if (addr == NULL) { - lifr.lifr_addrlen = plen; - if (ioctl(fd, SIOCSLIFSUBNET, &lifr) == -1) - return -1; - goto up; - } else { - if (ioctl(fd, SIOCSLIFNETMASK, &lifr) == -1) - return -1; - } - - /* Then assign the address. */ - lifr.lifr_addr = *addr; - if (ioctl(fd, SIOCSLIFADDR, &lifr) == -1) - return -1; - - /* Then assign the broadcast address. */ - if (brd != NULL) { - lifr.lifr_broadaddr = *brd; - if (ioctl(fd, SIOCSLIFBRDADDR, &lifr) == -1) - return -1; - } - -up: - return if_setflags(fd, ifname, IFF_UP); -} - -static int -if_getaf_fd(const struct dhcpcd_ctx *ctx, int af) -{ - - if (af == AF_INET) - return ctx->pf_inet_fd; - if (af == AF_INET6) { - struct priv *priv; - - priv = (struct priv *)ctx->priv; - return priv->pf_inet6_fd; - } - - errno = EAFNOSUPPORT; - return -1; -} - -int -if_getsubnet(struct dhcpcd_ctx *ctx, const char *ifname, int af, - void *subnet, size_t subnet_len) -{ - struct lifreq lifr = { .lifr_addrlen = 0 }; - int fd; - - fd = if_getaf_fd(ctx, af); - strlcpy(lifr.lifr_name, ifname, sizeof(lifr.lifr_name)); - if (ioctl(fd, SIOCGLIFSUBNET, &lifr) == -1) - return -1; - memcpy(subnet, &lifr.lifr_addr, MIN(subnet_len,sizeof(lifr.lifr_addr))); - return 0; -} - -static int -if_plumblif(int cmd, const struct dhcpcd_ctx *ctx, int af, const char *ifname) -{ - struct lifreq lifr; - int s; - - memset(&lifr, 0, sizeof(lifr)); - strlcpy(lifr.lifr_name, ifname, sizeof(lifr.lifr_name)); - lifr.lifr_addr.ss_family = af; - s = if_getaf_fd(ctx, af); - return ioctl(s, - cmd == RTM_NEWADDR ? SIOCLIFADDIF : SIOCLIFREMOVEIF, - &lifr) == -1 && errno != EEXIST ? -1 : 0; -} - -static int -if_plumbif(const struct dhcpcd_ctx *ctx, int af, const char *ifname) -{ - dlpi_handle_t dh, dh_arp = NULL; - int fd, af_fd, mux_fd, arp_fd = -1, mux_id, retval; - uint64_t flags; - struct lifreq lifr; - const char *udp_dev; - struct strioctl ioc; - struct if_spec spec; - - if (if_nametospec(ifname, &spec) == -1) - return -1; - - af_fd = if_getaf_fd(ctx, af); - - switch (af) { - case AF_INET: - flags = IFF_IPV4; - udp_dev = UDP_DEV_NAME; - break; - case AF_INET6: - /* We will take care of setting the link local address. */ - flags = IFF_IPV6 | IFF_NOLINKLOCAL; - udp_dev = UDP6_DEV_NAME; - break; - default: - errno = EPROTONOSUPPORT; - return -1; - } - - if (dlpi_open(ifname, &dh, DLPI_NOATTACH) != DLPI_SUCCESS) { - errno = EINVAL; - return -1; - } - - fd = dlpi_fd(dh); - retval = -1; - mux_fd = -1; - if (ioctl(fd, I_PUSH, IP_MOD_NAME) == -1) - goto out; - memset(&lifr, 0, sizeof(lifr)); - strlcpy(lifr.lifr_name, ifname, sizeof(lifr.lifr_name)); - lifr.lifr_ppa = spec.ppa; - lifr.lifr_flags = flags; - if (ioctl(fd, SIOCSLIFNAME, &lifr) == -1) - goto out; - - /* Get full flags. */ - if (ioctl(af_fd, SIOCGLIFFLAGS, &lifr) == -1) - goto out; - flags = lifr.lifr_flags; - - /* Open UDP as a multiplexor to PLINK the interface stream. - * UDP is used because STREAMS will not let you PLINK a driver - * under itself and IP is generally at the bottom of the stream. */ - if ((mux_fd = open(udp_dev, O_RDWR)) == -1) - goto out; - /* POP off all undesired modules. */ - while (ioctl(mux_fd, I_POP, 0) != -1) - ; - if (errno != EINVAL) - goto out; - if(ioctl(mux_fd, I_PUSH, ARP_MOD_NAME) == -1) - goto out; - - if (flags & (IFF_NOARP | IFF_IPV6)) { - /* PLINK the interface stream so it persists. */ - if (ioctl(mux_fd, I_PLINK, fd) == -1) - goto out; - goto done; - } - - if (dlpi_open(ifname, &dh_arp, DLPI_NOATTACH) != DLPI_SUCCESS) - goto out; - arp_fd = dlpi_fd(dh_arp); - if (ioctl(arp_fd, I_PUSH, ARP_MOD_NAME) == -1) - goto out; - - memset(&lifr, 0, sizeof(lifr)); - strlcpy(lifr.lifr_name, ifname, sizeof(lifr.lifr_name)); - lifr.lifr_ppa = spec.ppa; - lifr.lifr_flags = flags; - memset(&ioc, 0, sizeof(ioc)); - ioc.ic_cmd = SIOCSLIFNAME; - ioc.ic_dp = (char *)&lifr; - ioc.ic_len = sizeof(lifr); - if (ioctl(arp_fd, I_STR, &ioc) == -1) - goto out; - - /* PLINK the interface stream so it persists. */ - mux_id = ioctl(mux_fd, I_PLINK, fd); - if (mux_id == -1) - goto out; - if (ioctl(mux_fd, I_PLINK, arp_fd) == -1) { - ioctl(mux_fd, I_PUNLINK, mux_id); - goto out; - } - -done: - retval = 0; - -out: - dlpi_close(dh); - if (dh_arp != NULL) - dlpi_close(dh_arp); - if (mux_fd != -1) - close(mux_fd); - return retval; -} - -static int -if_unplumbif(const struct dhcpcd_ctx *ctx, int af, const char *ifname) -{ - struct sockaddr_storage addr = { .ss_family = af }; - int fd; - - /* For the time being, don't unplumb the interface, just - * set the address to zero. */ - fd = if_getaf_fd(ctx, af); - return if_addaddr(fd, ifname, &addr, &addr, - af == AF_INET ? &addr : NULL, 0); -} - -static int -if_plumb(int cmd, const struct dhcpcd_ctx *ctx, int af, const char *ifname) -{ - struct if_spec spec; - - if (if_nametospec(ifname, &spec) == -1) - return -1; - if (spec.lun != -1) - return if_plumblif(cmd, ctx, af, ifname); - if (cmd == RTM_NEWADDR) - return if_plumbif(ctx, af, ifname); - else - return if_unplumbif(ctx, af, ifname); -} - -#ifdef INET -static int -if_walkrt(struct dhcpcd_ctx *ctx, rb_tree_t *routes, char *data, size_t len) -{ - mib2_ipRouteEntry_t *re, *e; - struct rt rt, *rtn; - char ifname[IF_NAMESIZE]; - struct in_addr in; - - if (len % sizeof(*re) != 0) { - errno = EINVAL; - return -1; - } - - re = (mib2_ipRouteEntry_t *)data; - e = (mib2_ipRouteEntry_t *)(data + len); - do { - /* Skip route types we don't want. */ - switch (re->ipRouteInfo.re_ire_type) { - case IRE_IF_CLONE: - case IRE_BROADCAST: - case IRE_MULTICAST: - case IRE_NOROUTE: - case IRE_LOCAL: - continue; - default: - break; - } - - memset(&rt, 0, sizeof(rt)); - in.s_addr = re->ipRouteDest; - sa_in_init(&rt.rt_dest, &in); - in.s_addr = re->ipRouteMask; - sa_in_init(&rt.rt_netmask, &in); - in.s_addr = re->ipRouteNextHop; - sa_in_init(&rt.rt_gateway, &in); - rt.rt_flags = re->ipRouteInfo.re_flags; - in.s_addr = re->ipRouteInfo.re_src_addr; - sa_in_init(&rt.rt_ifa, &in); - rt.rt_mtu = re->ipRouteInfo.re_max_frag; - if_octetstr(ifname, &re->ipRouteIfIndex, sizeof(ifname)); - rt.rt_ifp = if_find(ctx->ifaces, ifname); - if (if_finishrt(ctx, &rt) == -1) { - logerr(__func__); - continue; - } - if ((rtn = rt_new(rt.rt_ifp)) == NULL) { - logerr(__func__); - break; - } - memcpy(rtn, &rt, sizeof(*rtn)); - if (rb_tree_insert_node(routes, rtn) != rtn) - rt_free(rtn); - } while (++re < e); - return 0; -} -#endif - -#ifdef INET6 -static int -if_walkrt6(struct dhcpcd_ctx *ctx, rb_tree_t *routes, char *data, size_t len) -{ - mib2_ipv6RouteEntry_t *re, *e; - struct rt rt, *rtn; - char ifname[IF_NAMESIZE]; - struct in6_addr in6; - - if (len % sizeof(*re) != 0) { - errno = EINVAL; - return -1; - } - - re = (mib2_ipv6RouteEntry_t *)data; - e = (mib2_ipv6RouteEntry_t *)(data + len); - - do { - /* Skip route types we don't want. */ - switch (re->ipv6RouteInfo.re_ire_type) { - case IRE_IF_CLONE: - case IRE_BROADCAST: - case IRE_MULTICAST: - case IRE_NOROUTE: - case IRE_LOCAL: - continue; - default: - break; - } - - memset(&rt, 0, sizeof(rt)); - sa_in6_init(&rt.rt_dest, &re->ipv6RouteDest); - ipv6_mask(&in6, re->ipv6RoutePfxLength); - sa_in6_init(&rt.rt_netmask, &in6); - sa_in6_init(&rt.rt_gateway, &re->ipv6RouteNextHop); - sa_in6_init(&rt.rt_ifa, &re->ipv6RouteInfo.re_src_addr); - rt.rt_mtu = re->ipv6RouteInfo.re_max_frag; - if_octetstr(ifname, &re->ipv6RouteIfIndex, sizeof(ifname)); - rt.rt_ifp = if_find(ctx->ifaces, ifname); - if (if_finishrt(ctx, &rt) == -1) { - logerr(__func__); - continue; - } - if ((rtn = rt_new(rt.rt_ifp)) == NULL) { - logerr(__func__); - break; - } - memcpy(rtn, &rt, sizeof(*rtn)); - if (rb_tree_insert_node(routes, rtn) != rtn) - rt_free(rtn); - } while (++re < e); - return 0; -} -#endif - -static int -if_parsert(struct dhcpcd_ctx *ctx, rb_tree_t *routes, - unsigned int level, unsigned int name, - int (*walkrt)(struct dhcpcd_ctx *, rb_tree_t *, char *, size_t)) -{ - int s, retval, code, flags; - uintptr_t buf[512 / sizeof(uintptr_t)]; - struct strbuf ctlbuf, databuf; - struct T_optmgmt_req *tor = (struct T_optmgmt_req *)buf; - struct T_optmgmt_ack *toa = (struct T_optmgmt_ack *)buf; - struct T_error_ack *tea = (struct T_error_ack *)buf; - struct opthdr *req; - - if ((s = open("/dev/arp", O_RDWR)) == -1) - return -1; - - /* Assume we are erroring. */ - retval = -1; - - tor->PRIM_type = T_SVR4_OPTMGMT_REQ; - tor->OPT_offset = sizeof (struct T_optmgmt_req); - tor->OPT_length = sizeof (struct opthdr); - tor->MGMT_flags = T_CURRENT; - - req = (struct opthdr *)&tor[1]; - req->level = EXPER_IP_AND_ALL_IRES; - req->name = 0; - req->len = 1; - - ctlbuf.buf = (char *)buf; - ctlbuf.len = tor->OPT_length + tor->OPT_offset; - if (putmsg(s, &ctlbuf, NULL, 0) == 1) - goto out; - - req = (struct opthdr *)&toa[1]; - ctlbuf.maxlen = sizeof(buf); - - /* Create a reasonable buffer to start with */ - databuf.maxlen = BUFSIZ * 2; - if ((databuf.buf = malloc(databuf.maxlen)) == NULL) - goto out; - - for (;;) { - flags = 0; - if ((code = getmsg(s, &ctlbuf, 0, &flags)) == -1) - break; - if (code == 0 && - toa->PRIM_type == T_OPTMGMT_ACK && - toa->MGMT_flags == T_SUCCESS && - (size_t)ctlbuf.len >= sizeof(struct T_optmgmt_ack)) - { - /* End of messages, so return success! */ - retval = 0; - break; - } - if (tea->PRIM_type == T_ERROR_ACK) { - errno = tea->TLI_error == TSYSERR ? - tea->UNIX_error : EPROTO; - break; - } - if (code != MOREDATA || - toa->PRIM_type != T_OPTMGMT_ACK || - toa->MGMT_flags != T_SUCCESS) - { - errno = ENOMSG; - break; - } - - /* Try to ensure out buffer is big enough - * for future messages as well. */ - if ((size_t)databuf.maxlen < req->len) { - size_t newlen; - - free(databuf.buf); - newlen = roundup(req->len, BUFSIZ); - if ((databuf.buf = malloc(newlen)) == NULL) - break; - databuf.maxlen = newlen; - } - - flags = 0; - if (getmsg(s, NULL, &databuf, &flags) == -1) - break; - - /* We always have to get the data before moving onto - * the next item, so don't move this test higher up - * to avoid the buffer allocation and getmsg calls. */ - if (req->level == level && req->name == name) { - if (walkrt(ctx, routes, databuf.buf, req->len) == -1) - break; - } - } - - free(databuf.buf); -out: - close(s); - return retval; -} - - -int -if_initrt(struct dhcpcd_ctx *ctx, rb_tree_t *routes, int af) -{ - -#ifdef INET - if ((af == AF_UNSPEC || af == AF_INET) && - if_parsert(ctx, routes, MIB2_IP,MIB2_IP_ROUTE, if_walkrt) == -1) - return -1; -#endif -#ifdef INET6 - if ((af == AF_UNSPEC || af == AF_INET6) && - if_parsert(ctx, routes, MIB2_IP6, MIB2_IP6_ROUTE, if_walkrt6) == -1) - return -1; -#endif - return 0; -} - - -#ifdef INET -/* XXX We should fix this to write via the BPF interface. */ -ssize_t -bpf_send(const struct interface *ifp, __unused int fd, uint16_t protocol, - const void *data, size_t len) -{ - dlpi_handle_t dh; - dlpi_info_t di; - int r; - - if (dlpi_open(ifp->name, &dh, 0) != DLPI_SUCCESS) - return -1; - if ((r = dlpi_info(dh, &di, 0)) == DLPI_SUCCESS && - (r = dlpi_bind(dh, protocol, NULL)) == DLPI_SUCCESS) - r = dlpi_send(dh, di.di_bcastaddr, ifp->hwlen, data, len, NULL); - dlpi_close(dh); - return r == DLPI_SUCCESS ? (ssize_t)len : -1; -} - -int -if_address(unsigned char cmd, const struct ipv4_addr *ia) -{ - union { - struct sockaddr sa; - struct sockaddr_storage ss; - } addr, mask, brd; - int fd = ia->iface->ctx->pf_inet_fd; - - /* Either remove the alias or ensure it exists. */ - if (if_plumb(cmd, ia->iface->ctx, AF_INET, ia->alias) == -1 && - errno != EEXIST) - return -1; - - if (cmd == RTM_DELADDR) - return 0; - - if (cmd != RTM_NEWADDR) { - errno = EINVAL; - return -1; - } - - /* We need to update the index now */ - ia->iface->index = if_nametoindex(ia->alias); - - sa_in_init(&addr.sa, &ia->addr); - sa_in_init(&mask.sa, &ia->mask); - sa_in_init(&brd.sa, &ia->brd); - return if_addaddr(fd, ia->alias, &addr.ss, &mask.ss, &brd.ss, 0); -} - -int -if_addrflags(const struct interface *ifp, __unused const struct in_addr * ia, - const char *alias) -{ - - return if_addrflags0(ifp->ctx->pf_inet_fd, AF_INET, alias); -} - -#endif - -#ifdef INET6 -int -if_address6(unsigned char cmd, const struct ipv6_addr *ia) -{ - union { - struct sockaddr sa; - struct sockaddr_in6 sin6; - struct sockaddr_storage ss; - } addr, mask; - int fd, r; - - /* Either remove the alias or ensure it exists. */ - if (if_plumb(cmd, ia->iface->ctx, AF_INET6, ia->alias) == -1 && - errno != EEXIST) - return -1; - - if (cmd == RTM_DELADDR) - return 0; - - if (cmd != RTM_NEWADDR) { - errno = EINVAL; - return -1; - } - - fd = if_getaf_fd(ia->iface->ctx, AF_INET6); - - if (!(ia->flags & IPV6_AF_AUTOCONF) && ia->flags & IPV6_AF_RAPFX) { - if (if_setflags(fd, ia->alias, IFF_NOLOCAL) ==-1) - return -1; - sa_in6_init(&mask.sa, &ia->prefix); - r = if_addaddr(fd, ia->alias, - NULL, &mask.ss, NULL, ia->prefix_len); - } else { - sa_in6_init(&addr.sa, &ia->addr); - mask.sin6.sin6_family = AF_INET6; - ipv6_mask(&mask.sin6.sin6_addr, ia->prefix_len); - r = if_addaddr(fd, ia->alias, - &addr.ss, &mask.ss, NULL, ia->prefix_len); - } - if (r == -1 && errno == EEXIST) - return 0; - return r; -} - -int -if_addrflags6(const struct interface *ifp, __unused const struct in6_addr *ia, - const char *alias) -{ - int fd; - - fd = if_getaf_fd(ifp->ctx, AF_INET6); - return if_addrflags0(fd, AF_INET6, alias); -} - -int -if_getlifetime6(struct ipv6_addr *addr) -{ - - UNUSED(addr); - errno = ENOTSUP; - return -1; -} - -void -if_setup_inet6(__unused const struct interface *ifp) -{ - -} - -int -ip6_forwarding(__unused const char *ifname) -{ - - return 1; -} -#endif diff --git a/external/bsd/dhcpcd/dist/src/if.c b/external/bsd/dhcpcd/dist/src/if.c index c483f046ff2..459af3afd5a 100644 --- a/external/bsd/dhcpcd/dist/src/if.c +++ b/external/bsd/dhcpcd/dist/src/if.c @@ -312,6 +312,7 @@ if_discover(struct dhcpcd_ctx *ctx, struct ifaddrs **ifaddrs, struct if_head *ifs; struct interface *ifp; struct if_spec spec; + bool if_noconf; #ifdef AF_LINK const struct sockaddr_dl *sdl; #ifdef IFLR_ACTIVE @@ -405,13 +406,6 @@ if_discover(struct dhcpcd_ctx *ctx, struct ifaddrs **ifaddrs, continue; #endif - /* Don't allow loopback or pointopoint unless explicit */ - if (ifa->ifa_flags & (IFF_LOOPBACK | IFF_POINTOPOINT)) { - if ((argc == 0 || argc == -1) && - ctx->ifac == 0 && !if_hasconf(ctx, spec.devname)) - active = IF_INACTIVE; - } - if (if_vimaster(ctx, spec.devname) == 1) { logfunc_t *logfunc = argc != 0 ? logerrx : logdebugx; logfunc("%s: is a Virtual Interface Master, skipping", @@ -419,6 +413,17 @@ if_discover(struct dhcpcd_ctx *ctx, struct ifaddrs **ifaddrs, continue; } + if_noconf = ((argc == 0 || argc == -1) && ctx->ifac == 0 && + !if_hasconf(ctx, spec.devname)); + + /* Don't allow loopback or pointopoint unless explicit. + * Don't allow some reserved interface names unless explicit. */ + if (if_noconf) { + if (ifa->ifa_flags & (IFF_LOOPBACK | IFF_POINTOPOINT) || + if_ignore(ctx, spec.devname)) + active = IF_INACTIVE; + } + ifp = calloc(1, sizeof(*ifp)); if (ifp == NULL) { logerr(__func__); @@ -453,27 +458,23 @@ if_discover(struct dhcpcd_ctx *ctx, struct ifaddrs **ifaddrs, #ifdef IFT_BRIDGE case IFT_BRIDGE: /* FALLTHROUGH */ #endif -#ifdef IFT_PPP - case IFT_PPP: /* FALLTHROUGH */ -#endif #ifdef IFT_PROPVIRTUAL - case IFT_PROPVIRTUAL: + case IFT_PROPVIRTUAL: /* FALLTHROUGH */ #endif -#if defined(IFT_BRIDGE) || defined(IFT_PPP) || defined(IFT_PROPVIRTUAL) +#ifdef IFT_TUNNEL + case IFT_TUNNEL: /* FALLTHROUGH */ +#endif + case IFT_PPP: /* Don't allow unless explicit */ - if ((argc == 0 || argc == -1) && - ctx->ifac == 0 && active && - !if_hasconf(ctx, ifp->name)) - { + if (if_noconf) { logdebugx("%s: ignoring due to" " interface type and" " no config", ifp->name); active = IF_INACTIVE; } - __fallthrough; /* Appease gcc-7 */ + __fallthrough; /* appease gcc */ /* FALLTHROUGH */ -#endif #ifdef IFT_L2VLAN case IFT_L2VLAN: /* FALLTHROUGH */ #endif @@ -495,13 +496,11 @@ if_discover(struct dhcpcd_ctx *ctx, struct ifaddrs **ifaddrs, #endif default: /* Don't allow unless explicit */ - if ((argc == 0 || argc == -1) && - ctx->ifac == 0 && - !if_hasconf(ctx, ifp->name)) + if (if_noconf) active = IF_INACTIVE; if (active) logwarnx("%s: unsupported" - " interface type %.2x", + " interface type 0x%.2x", ifp->name, sdl->sdl_type); /* Pretend it's ethernet */ ifp->family = ARPHRD_ETHER; @@ -564,7 +563,7 @@ if_discover(struct dhcpcd_ctx *ctx, struct ifaddrs **ifaddrs, default: if (active) logwarnx("%s: unsupported" - " interface family %.2x", + " interface family 0x%.2x", ifp->name, ifp->family); break; #endif diff --git a/external/bsd/dhcpcd/dist/src/if.h b/external/bsd/dhcpcd/dist/src/if.h index 4126fd33e4c..19b6b2fe1b9 100644 --- a/external/bsd/dhcpcd/dist/src/if.h +++ b/external/bsd/dhcpcd/dist/src/if.h @@ -152,6 +152,7 @@ int if_nametospec(const char *, struct if_spec *); int if_conf(struct interface *); int if_init(struct interface *); int if_getssid(struct interface *); +bool if_ignore(struct dhcpcd_ctx *, const char *); int if_vimaster(const struct dhcpcd_ctx *ctx, const char *); unsigned short if_vlanid(const struct interface *); int if_opensockets(struct dhcpcd_ctx *); diff --git a/external/bsd/dhcpcd/dist/src/ipv4.c b/external/bsd/dhcpcd/dist/src/ipv4.c index 05fc8066aff..c55a7da6cb1 100644 --- a/external/bsd/dhcpcd/dist/src/ipv4.c +++ b/external/bsd/dhcpcd/dist/src/ipv4.c @@ -145,7 +145,7 @@ ipv4_iffindlladdr(struct interface *ifp) state = IPV4_STATE(ifp); if (state) { TAILQ_FOREACH(ap, &state->addrs, next) { - if (IN_LINKLOCAL(htonl(ap->addr.s_addr))) + if (IN_LINKLOCAL(ntohl(ap->addr.s_addr))) return ap; } } @@ -622,7 +622,6 @@ ipv4_addaddr(struct interface *ifp, const struct in_addr *addr, { struct ipv4_state *state; struct ipv4_addr *ia; - bool is_new = false; #ifdef ALIAS_ADDR int replaced, blank; struct ipv4_addr *replaced_ia; @@ -653,8 +652,9 @@ ipv4_addaddr(struct interface *ifp, const struct in_addr *addr, #ifdef IN_IFF_TENTATIVE ia->addr_flags = IN_IFF_TENTATIVE; #endif - is_new = true; - } + ia->flags = IPV4_AF_NEW; + } else + ia->flags |= ~IPV4_AF_NEW; ia->mask = *mask; ia->brd = *bcast; @@ -698,7 +698,7 @@ ipv4_addaddr(struct interface *ifp, const struct in_addr *addr, } #endif - if (is_new) + if (ia->flags & IPV4_AF_NEW) TAILQ_INSERT_TAIL(&state->addrs, ia, next); return ia; } @@ -743,8 +743,7 @@ ipv4_applyaddr(void *arg) #ifdef ARP /* Announce the preferred address to * kick ARP caches. */ - if (!(ifp->flags & IFF_NOARP)) - arp_announceaddr(ifp->ctx,&lease->addr); + arp_announceaddr(ifp->ctx,&lease->addr); #endif } script_runreason(ifp, state->reason); @@ -806,8 +805,7 @@ ipv4_applyaddr(void *arg) rt_build(ifp->ctx, AF_INET); #ifdef ARP - if (!(ifp->flags & IFF_NOARP)) - arp_announceaddr(ifp->ctx, &state->addr->addr); + arp_announceaddr(ifp->ctx, &state->addr->addr); #endif if (state->state == DHS_BOUND) { @@ -936,13 +934,14 @@ ipv4_handleifa(struct dhcpcd_ctx *ctx, } if (addr->s_addr != INADDR_ANY && addr->s_addr != INADDR_BROADCAST) { - dhcp_handleifa(cmd, ia, pid); + ia = dhcp_handleifa(cmd, ia, pid); #ifdef IPV4LL - ipv4ll_handleifa(cmd, ia, pid); + if (ia != NULL) + ipv4ll_handleifa(cmd, ia, pid); #endif } - if (cmd == RTM_DELADDR) + if (cmd == RTM_DELADDR && ia != NULL) free(ia); } diff --git a/external/bsd/dhcpcd/dist/src/ipv4.h b/external/bsd/dhcpcd/dist/src/ipv4.h index eaa0dcce9ab..59b48a53b04 100644 --- a/external/bsd/dhcpcd/dist/src/ipv4.h +++ b/external/bsd/dhcpcd/dist/src/ipv4.h @@ -100,6 +100,7 @@ struct ipv4_addr { TAILQ_HEAD(ipv4_addrhead, ipv4_addr); #define IPV4_AF_STALE (1U << 0) +#define IPV4_AF_NEW (1U << 1) #define IPV4_ADDR_EQ(a1, a2) ((a1) && (a1)->addr.s_addr == (a2)->addr.s_addr) #define IPV4_MASK1_EQ(a1, a2) ((a1) && (a1)->mask.s_addr == (a2)->mask.s_addr) diff --git a/external/bsd/dhcpcd/dist/src/ipv4ll.c b/external/bsd/dhcpcd/dist/src/ipv4ll.c index 4b0038b76f5..42a6a78416a 100644 --- a/external/bsd/dhcpcd/dist/src/ipv4ll.c +++ b/external/bsd/dhcpcd/dist/src/ipv4ll.c @@ -198,12 +198,16 @@ ipv4ll_not_found(struct interface *ifp) struct ipv4_addr *ia; #ifdef KERNEL_RFC5227 struct arp_state *astate; + bool new_addr; #endif state = IPV4LL_STATE(ifp); assert(state != NULL); ia = ipv4_iffindaddr(ifp, &state->pickedaddr, &inaddr_llmask); +#ifdef KERNEL_RFC5227 + new_addr = ia == NULL; +#endif #ifdef IN_IFF_NOTREADY if (ia == NULL || ia->addr_flags & IN_IFF_NOTREADY) #endif @@ -233,11 +237,13 @@ test: } rt_build(ifp->ctx, AF_INET); #ifdef KERNEL_RFC5227 - astate = arp_new(ifp, &ia->addr); - if (astate != NULL) { - astate->announced_cb = ipv4ll_announced_arp; - astate->free_cb = ipv4ll_arpfree; - arp_announce(astate); + if (!new_addr) { + astate = arp_new(ifp, &ia->addr); + if (astate != NULL) { + astate->announced_cb = ipv4ll_announced_arp; + astate->free_cb = ipv4ll_arpfree; + arp_announce(astate); + } } #else arp_announce(state->arp); @@ -261,10 +267,12 @@ ipv4ll_found(struct interface *ifp) { struct ipv4ll_state *state = IPV4LL_STATE(ifp); - arp_cancel(state->arp); + if (state->arp != NULL) + arp_cancel(state->arp); if (++state->conflicts == MAX_CONFLICTS) - logerr("%s: failed to acquire an IPv4LL address", + logerrx("%s: failed to acquire an IPv4LL address", ifp->name); + state->pickedaddr.s_addr = ipv4ll_pickaddr(ifp); eloop_timeout_add_sec(ifp->ctx->eloop, state->conflicts >= MAX_CONFLICTS ? RATE_LIMIT_INTERVAL : PROBE_WAIT, @@ -276,11 +284,14 @@ ipv4ll_defend_failed(struct interface *ifp) { struct ipv4ll_state *state = IPV4LL_STATE(ifp); + if (state->arp != NULL) + arp_cancel(state->arp); ipv4_deladdr(state->addr, 1); state->down = true; state->addr = NULL; rt_build(ifp->ctx, AF_INET); script_runreason(ifp, "IPV4LL"); + state->pickedaddr.s_addr = ipv4ll_pickaddr(ifp); ipv4ll_start1(ifp, state->arp); } @@ -544,7 +555,7 @@ ipv4ll_recvrt(__unused int cmd, const struct rt *rt) } #endif -void +struct ipv4_addr * ipv4ll_handleifa(int cmd, struct ipv4_addr *ia, pid_t pid) { struct interface *ifp; @@ -553,7 +564,7 @@ ipv4ll_handleifa(int cmd, struct ipv4_addr *ia, pid_t pid) ifp = ia->iface; state = IPV4LL_STATE(ifp); if (state == NULL) - return; + return ia; if (cmd == RTM_DELADDR && state->addr != NULL && @@ -562,20 +573,28 @@ ipv4ll_handleifa(int cmd, struct ipv4_addr *ia, pid_t pid) loginfox("%s: pid %d deleted IP address %s", ifp->name, pid, ia->saddr); ipv4ll_defend_failed(ifp); - return; + return ia; } #ifdef IN_IFF_DUPLICATED if (cmd != RTM_NEWADDR) - return; + return ia; if (!IN_ARE_ADDR_EQUAL(&state->pickedaddr, &ia->addr)) - return; + return ia; if (!(ia->addr_flags & IN_IFF_NOTUSEABLE)) ipv4ll_not_found(ifp); else if (ia->addr_flags & IN_IFF_DUPLICATED) { logerrx("%s: DAD detected %s", ifp->name, ia->saddr); - ipv4_deladdr(state->addr, 1); +#ifdef KERNEL_RFC5227 + arp_freeaddr(ifp, &ia->addr); +#endif + ipv4_deladdr(ia, 1); + state->addr = NULL; + rt_build(ifp->ctx, AF_INET); ipv4ll_found(ifp); + return NULL; } #endif + + return ia; } diff --git a/external/bsd/dhcpcd/dist/src/ipv4ll.h b/external/bsd/dhcpcd/dist/src/ipv4ll.h index dd68d30a1df..d955d1e06c3 100644 --- a/external/bsd/dhcpcd/dist/src/ipv4ll.h +++ b/external/bsd/dhcpcd/dist/src/ipv4ll.h @@ -64,7 +64,7 @@ ssize_t ipv4ll_env(FILE *, const char *, const struct interface *); void ipv4ll_start(void *); void ipv4ll_claimed(void *); void ipv4ll_handle_failure(void *); -void ipv4ll_handleifa(int, struct ipv4_addr *, pid_t pid); +struct ipv4_addr *ipv4ll_handleifa(int, struct ipv4_addr *, pid_t pid); #ifdef HAVE_ROUTE_METRIC int ipv4ll_recvrt(int, const struct rt *); #endif diff --git a/external/bsd/dhcpcd/dist/src/ipv6.c b/external/bsd/dhcpcd/dist/src/ipv6.c index ca54dab91a1..99f6a8a4232 100644 --- a/external/bsd/dhcpcd/dist/src/ipv6.c +++ b/external/bsd/dhcpcd/dist/src/ipv6.c @@ -1065,28 +1065,31 @@ ipv6_getstate(struct interface *ifp) } struct ipv6_addr * -ipv6_ifanyglobal(struct interface *ifp) +ipv6_anyglobal(struct interface *sifp) { + struct interface *ifp; struct ipv6_state *state; struct ipv6_addr *ia; - if (ifp->carrier == LINK_DOWN) - return NULL; - - state = IPV6_STATE(ifp); - if (state == NULL) - return NULL; + TAILQ_FOREACH(ifp, sifp->ctx->ifaces, next) { + if (ifp != sifp && ip6_forwarding(ifp->name) != 1) + continue; - TAILQ_FOREACH(ia, &state->addrs, next) { - if (IN6_IS_ADDR_LINKLOCAL(&ia->addr)) + state = IPV6_STATE(ifp); + if (state == NULL) continue; - /* Let's be optimistic. - * Any decent OS won't forward or accept traffic - * from/to tentative or detached addresses. */ - if (!(ia->addr_flags & IN6_IFF_DUPLICATED)) - break; + + TAILQ_FOREACH(ia, &state->addrs, next) { + if (IN6_IS_ADDR_LINKLOCAL(&ia->addr)) + continue; + /* Let's be optimistic. + * Any decent OS won't forward or accept traffic + * from/to tentative or detached addresses. */ + if (!(ia->addr_flags & IN6_IFF_DUPLICATED)) + return ia; + } } - return ia; + return NULL; } void @@ -1133,7 +1136,7 @@ ipv6_handleifa(struct dhcpcd_ctx *ctx, return; if ((state = ipv6_getstate(ifp)) == NULL) return; - anyglobal = ipv6_ifanyglobal(ifp) != NULL; + anyglobal = ipv6_anyglobal(ifp) != NULL; TAILQ_FOREACH(ia, &state->addrs, next) { if (IN6_ARE_ADDR_EQUAL(&ia->addr, addr)) @@ -1252,7 +1255,7 @@ out: * call rt_build to add/remove the default route. */ if (ifp->active && ifp->options->options & DHCPCD_IPV6 && !(ctx->options & DHCPCD_RTBUILD) && - (ipv6_ifanyglobal(ifp) != NULL) != anyglobal) + (ipv6_anyglobal(ifp) != NULL) != anyglobal) rt_build(ctx, AF_INET6); } @@ -2335,7 +2338,7 @@ inet6_raroutes(rb_tree_t *routes, struct dhcpcd_ctx *ctx) } if (rap->lifetime == 0) continue; - if (ipv6_ifanyglobal(rap->iface) == NULL) + if (ipv6_anyglobal(rap->iface) == NULL) continue; rt = inet6_makerouter(rap); if (rt == NULL) diff --git a/external/bsd/dhcpcd/dist/src/ipv6.h b/external/bsd/dhcpcd/dist/src/ipv6.h index 7dbf4fe6924..547957eb15d 100644 --- a/external/bsd/dhcpcd/dist/src/ipv6.h +++ b/external/bsd/dhcpcd/dist/src/ipv6.h @@ -273,7 +273,7 @@ int ipv6_handleifa_addrs(int, struct ipv6_addrhead *, const struct ipv6_addr *, struct ipv6_addr *ipv6_iffindaddr(struct interface *, const struct in6_addr *, int); int ipv6_hasaddr(const struct interface *); -struct ipv6_addr *ipv6_ifanyglobal(struct interface *); +struct ipv6_addr *ipv6_anyglobal(struct interface *); int ipv6_findaddrmatch(const struct ipv6_addr *, const struct in6_addr *, unsigned int); struct ipv6_addr *ipv6_findaddr(struct dhcpcd_ctx *, diff --git a/external/bsd/dhcpcd/dist/src/ipv6nd.c b/external/bsd/dhcpcd/dist/src/ipv6nd.c index affc911708b..929b071d090 100644 --- a/external/bsd/dhcpcd/dist/src/ipv6nd.c +++ b/external/bsd/dhcpcd/dist/src/ipv6nd.c @@ -1290,7 +1290,7 @@ ipv6nd_handlera(struct dhcpcd_ctx *ctx, } } - if (new_data && !has_address && rap->lifetime && !ipv6_ifanyglobal(ifp)) + if (new_data && !has_address && rap->lifetime && !ipv6_anyglobal(ifp)) logwarnx("%s: no global addresses for default route", ifp->name); diff --git a/external/bsd/dhcpcd/dist/src/route.c b/external/bsd/dhcpcd/dist/src/route.c index 01bf8df9dfa..a9d971024d0 100644 --- a/external/bsd/dhcpcd/dist/src/route.c +++ b/external/bsd/dhcpcd/dist/src/route.c @@ -594,7 +594,9 @@ rt_add(rb_tree_t *kroutes, struct rt *nrt, struct rt *ort) } #endif - if (if_route(RTM_ADD, nrt) != -1) { + /* Shouldn't need to check for EEXIST, but some kernels don't + * dump the subnet route just after we added the address. */ + if (if_route(RTM_ADD, nrt) != -1 || errno == EEXIST) { result = true; goto out; } diff --git a/external/bsd/dhcpcd/dist/tests/Makefile b/external/bsd/dhcpcd/dist/tests/Makefile deleted file mode 100644 index 1ae0a8b2448..00000000000 --- a/external/bsd/dhcpcd/dist/tests/Makefile +++ /dev/null @@ -1,16 +0,0 @@ -SUBDIRS= crypt eloop-bench - -all: - for x in ${SUBDIRS}; do cd $$x; ${MAKE} $@ || exit $$?; cd ..; done - -install: - -proginstall: - -clean: - for x in ${SUBDIRS}; do cd $$x; ${MAKE} $@ || exit $$?; cd ..; done - -test: - for x in ${SUBDIRS}; do cd $$x; ${MAKE} $@ || exit $$?; cd ..; done - -tests: test diff --git a/external/bsd/dhcpcd/dist/tests/crypt/.gitignore b/external/bsd/dhcpcd/dist/tests/crypt/.gitignore deleted file mode 100644 index 4390dc85072..00000000000 --- a/external/bsd/dhcpcd/dist/tests/crypt/.gitignore +++ /dev/null @@ -1 +0,0 @@ -run-test diff --git a/external/bsd/dhcpcd/dist/tests/crypt/GNUmakefile b/external/bsd/dhcpcd/dist/tests/crypt/GNUmakefile deleted file mode 100644 index 2e838d5e728..00000000000 --- a/external/bsd/dhcpcd/dist/tests/crypt/GNUmakefile +++ /dev/null @@ -1,7 +0,0 @@ -# GNU Make does not automagically include .depend -# Luckily it does read GNUmakefile over Makefile so we can work around it - -include Makefile -ifneq ($(wildcard .depend), ) -include .depend -endif diff --git a/external/bsd/dhcpcd/dist/tests/crypt/Makefile b/external/bsd/dhcpcd/dist/tests/crypt/Makefile deleted file mode 100644 index 9b2a3231dec..00000000000 --- a/external/bsd/dhcpcd/dist/tests/crypt/Makefile +++ /dev/null @@ -1,35 +0,0 @@ -TOP?= ../.. -include ${TOP}/iconfig.mk - -PROG= run-test -SRCS= run-test.c -SRCS+= test_hmac_md5.c - -CFLAGS?= -O2 -CSTD?= c99 -CFLAGS+= -std=${CSTD} - -CPPFLAGS+= -I${TOP} -I${TOP}/src - -PCRYPT_SRCS= ${CRYPT_SRCS:compat/%=${TOP}/compat/%} -OBJS+= ${SRCS:.c=.o} ${PCRYPT_SRCS:.c=.o} - -.c.o: - ${CC} ${CFLAGS} ${CPPFLAGS} -c $< -o $@ - -all: ${PROG} - -clean: - rm -f ${OBJS} ${PROG} ${PROG}.core ${CLEANFILES} - -distclean: clean - rm -f .depend - -.depend: ${SRCS} ${PCRYPT_SRCS} - ${CC} ${CPPFLAGS} -MM ${SRCS} ${PCRYPT_SRCS} - -${PROG}: ${DEPEND} ${OBJS} - ${CC} ${LDFLAGS} -o $@ ${OBJS} ${LDADD} - -test: ${PROG} - ./${PROG} diff --git a/external/bsd/dhcpcd/dist/tests/crypt/README.md b/external/bsd/dhcpcd/dist/tests/crypt/README.md deleted file mode 100644 index 8269e51fee5..00000000000 --- a/external/bsd/dhcpcd/dist/tests/crypt/README.md +++ /dev/null @@ -1,8 +0,0 @@ -# dhcpcd Test Suite - -Currently this just tests the RFC2202 MD5 implementation in dhcpcd. -This is important, because dhcpcd will either use the system MD5 -implementation if found, otherwise some compat code. - -This test suit ensures that it works in accordance with known standards -on your platform. diff --git a/external/bsd/dhcpcd/dist/tests/crypt/run-test.c b/external/bsd/dhcpcd/dist/tests/crypt/run-test.c deleted file mode 100644 index 42f52d1fce2..00000000000 --- a/external/bsd/dhcpcd/dist/tests/crypt/run-test.c +++ /dev/null @@ -1,38 +0,0 @@ -/* - * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2018 Roy Marples <roy@marples.name> - * 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. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. - */ - -#include "test.h" - -int main(void) -{ - int r = 0; - - if (test_hmac_md5()) - r = -1; - - return r; -} diff --git a/external/bsd/dhcpcd/dist/tests/crypt/test.h b/external/bsd/dhcpcd/dist/tests/crypt/test.h deleted file mode 100644 index 4f716f1220f..00000000000 --- a/external/bsd/dhcpcd/dist/tests/crypt/test.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2018 Roy Marples <roy@marples.name> - * 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. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. - */ - -#ifndef TEST_H - -int test_hmac_md5(void); - -#endif diff --git a/external/bsd/dhcpcd/dist/tests/crypt/test_hmac_md5.c b/external/bsd/dhcpcd/dist/tests/crypt/test_hmac_md5.c deleted file mode 100644 index aed6345d570..00000000000 --- a/external/bsd/dhcpcd/dist/tests/crypt/test_hmac_md5.c +++ /dev/null @@ -1,209 +0,0 @@ -/* - * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2018 Roy Marples <roy@marples.name> - * 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. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. - */ - -#include <stdio.h> -#include <stdint.h> -#include <stdlib.h> -#include <string.h> - -#include "config.h" -#include "test.h" - -#ifdef HAVE_HMAC_H -#include <hmac.h> -#endif - -static void -print_hmac(FILE *stream, const uint8_t *hmac) -{ - int i; - - fprintf(stream, "digest = 0x"); - for (i = 0; i < 16; i++) - fprintf(stream, "%02x", *hmac++); - fprintf(stream, "\n"); -} - -static void -test_hmac(const uint8_t *hmac, const uint8_t *tst) -{ - print_hmac(stdout, hmac); - if (memcmp(hmac, tst, 16) == 0) - return; - fprintf(stderr, "FAILED!\nExpected\t\t\t"); - print_hmac(stderr, tst); - exit(EXIT_FAILURE); -} - -static void -hmac_md5_test1(void) -{ - const uint8_t text[] = "Hi There"; - uint8_t key[16]; - const uint8_t expect[16] = { - 0x92, 0x94, 0x72, 0x7a, 0x36, 0x38, 0xbb, 0x1c, - 0x13, 0xf4, 0x8e, 0xf8, 0x15, 0x8b, 0xfc, 0x9d, - }; - uint8_t digest[16]; - int i; - - printf ("HMAC MD5 Test 1:\t\t"); - for (i = 0; i < 16; i++) - key[i] = 0x0b; - hmac("md5", key, 16, text, 8, digest, sizeof(digest)); - test_hmac(digest, expect); -} - -static void -hmac_md5_test2(void) -{ - const uint8_t text[] = "what do ya want for nothing?"; - const uint8_t key[] = "Jefe"; - const uint8_t expect[16] = { - 0x75, 0x0c, 0x78, 0x3e, 0x6a, 0xb0, 0xb5, 0x03, - 0xea, 0xa8, 0x6e, 0x31, 0x0a, 0x5d, 0xb7, 0x38, - }; - uint8_t digest[16]; - - printf("HMAC MD5 Test 2:\t\t"); - hmac("md5", key, 4, text, 28, digest, sizeof(digest)); - test_hmac(digest, expect); -} - -static void -hmac_md5_test3(void) -{ - const uint8_t expect[16] = { - 0x56, 0xbe, 0x34, 0x52, 0x1d, 0x14, 0x4c, 0x88, - 0xdb, 0xb8, 0xc7, 0x33, 0xf0, 0xe8, 0xb3, 0xf6, - }; - uint8_t digest[16]; - uint8_t text[50]; - uint8_t key[16]; - int i; - - printf ("HMAC MD5 Test 3:\t\t"); - for (i = 0; i < 50; i++) - text[i] = 0xdd; - for (i = 0; i < 16; i++) - key[i] = 0xaa; - hmac("md5", key, 16, text, 50, digest, sizeof(digest)); - test_hmac(digest, expect); -} - -static void -hmac_md5_test4(void) -{ - const uint8_t expect[16] = { - 0x69, 0x7e, 0xaf, 0x0a, 0xca, 0x3a, 0x3a, 0xea, - 0x3a, 0x75, 0x16, 0x47, 0x46, 0xff, 0xaa, 0x79, - }; - uint8_t digest[16]; - uint8_t text[50]; - uint8_t key[25]; - uint8_t i; - - printf ("HMAC MD5 Test 4:\t\t"); - for (i = 0; i < 50; i++) - text[i] = 0xcd; - for (i = 0; i < 25; i++) - key[i] = (uint8_t)(i + 1); - hmac("md5", key, 25, text, 50, digest, sizeof(digest)); - test_hmac(digest, expect); -} - -static void -hmac_md5_test5(void) -{ - const uint8_t text[] = "Test With Truncation"; - const uint8_t expect[] = { - 0x56, 0x46, 0x1e, 0xf2, 0x34, 0x2e, 0xdc, 0x00, - 0xf9, 0xba, 0xb9, 0x95, 0x69, 0x0e, 0xfd, 0x4c, - }; - uint8_t digest[16]; - uint8_t key[16]; - int i; - - printf ("HMAC MD5 Test 5:\t\t"); - for (i = 0; i < 16; i++) - key[i] = 0x0c; - hmac("md5", key, 16, text, 20, digest, sizeof(digest)); - test_hmac(digest, expect); -} - -static void -hmac_md5_test6(void) -{ - const uint8_t text[] = "Test Using Larger Than Block-Size Key - Hash Key First"; - const uint8_t expect[] = { - 0x6b, 0x1a, 0xb7, 0xfe, 0x4b, 0xd7, 0xbf, 0x8f, - 0x0b, 0x62, 0xe6, 0xce, 0x61, 0xb9, 0xd0, 0xcd, - }; - uint8_t digest[16]; - uint8_t key[80]; - int i; - - printf ("HMAC MD5 Test 6:\t\t"); - for (i = 0; i < 80; i++) - key[i] = 0xaa; - hmac("md5", key, 80, text, 54, digest, sizeof(digest)); - test_hmac(digest, expect); -} - -static void -hmac_md5_test7(void) -{ - const uint8_t text[] = "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data"; - const uint8_t expect[] = { - 0x6f, 0x63, 0x0f, 0xad, 0x67, 0xcd, 0xa0, 0xee, - 0x1f, 0xb1, 0xf5, 0x62, 0xdb, 0x3a, 0xa5, 0x3e, - }; - uint8_t digest[16]; - uint8_t key[80]; - int i; - - printf ("HMAC MD5 Test 7:\t\t"); - for (i = 0; i < 80; i++) - key[i] = 0xaa; - hmac("md5", key, 80, text, 73, digest, sizeof(digest)); - test_hmac(digest, expect); -} - -int test_hmac_md5(void) -{ - - printf ("Starting RFC2202 HMAC MD5 tests...\n\n"); - hmac_md5_test1(); - hmac_md5_test2(); - hmac_md5_test3(); - hmac_md5_test4(); - hmac_md5_test5(); - hmac_md5_test6(); - hmac_md5_test7(); - printf("\nAll tests pass.\n"); - return 0; -} diff --git a/external/bsd/dhcpcd/dist/tests/eloop-bench/.gitignore b/external/bsd/dhcpcd/dist/tests/eloop-bench/.gitignore deleted file mode 100644 index 346bbde39b1..00000000000 --- a/external/bsd/dhcpcd/dist/tests/eloop-bench/.gitignore +++ /dev/null @@ -1 +0,0 @@ -eloop-bench diff --git a/external/bsd/dhcpcd/dist/tests/eloop-bench/Makefile b/external/bsd/dhcpcd/dist/tests/eloop-bench/Makefile deleted file mode 100644 index a0d30983c36..00000000000 --- a/external/bsd/dhcpcd/dist/tests/eloop-bench/Makefile +++ /dev/null @@ -1,44 +0,0 @@ -TOP?= ../.. -include ${TOP}/iconfig.mk - -PROG= eloop-bench -SRCS= eloop-bench.c -SRCS+= ${TOP}/src/eloop.c - -CFLAGS?= -O2 -CSTD?= c99 -CFLAGS+= -std=${CSTD} - -#CPPFLAGS+= -DNO_CONFIG_H -#CPPFLAGS+= -DQUEUE_H=../compat/queue.h -CPPFLAGS+= -I${TOP} -I${TOP}/src - -# Default is to let eloop decide -#CPPFLAGS+= -DHAVE_KQUEUE -#CPPFLAGS+= -DHAVE_POLLTS -#CPPFLAGS+= -DHAVE_PSELECT -#CPPFLAGS+= -DHAVE_EPOLL -#CPPFLAGS+= -DHAVE_PPOLL -CPPFLAGS+= -DWARN_SELECT - -PCOMPAT_SRCS= ${COMPAT_SRCS:compat/%=${TOP}/compat/%} -OBJS+= ${SRCS:.c=.o} ${PCOMPAT_SRCS:.c=.o} - -.c.o: Makefile - ${CC} ${CFLAGS} ${CPPFLAGS} -c $< -o $@ - -all: ${PROG} - -clean: - rm -f ${OBJS} ${PROG} ${PROG}.core ${CLEANFILES} - -distclean: clean - rm -f .depend - -depend: - -${PROG}: ${DEPEND} ${OBJS} - ${CC} ${LDFLAGS} -o $@ ${OBJS} - -test: ${PROG} - ./${PROG} diff --git a/external/bsd/dhcpcd/dist/tests/eloop-bench/README.md b/external/bsd/dhcpcd/dist/tests/eloop-bench/README.md deleted file mode 100644 index 6f4a20c7ea8..00000000000 --- a/external/bsd/dhcpcd/dist/tests/eloop-bench/README.md +++ /dev/null @@ -1,53 +0,0 @@ -# eloop-bench - -eloop is a portable event loop designed to be dropped into the code of a -program. It is not in any library to date. -The basic requirement of eloop is a descriptor polling mechanism which -allows the safe delivery of signals. -As such, select(2) and poll(2) are not suitable. - -This is an eloop benchmark to test the performance of the various -polling mechanisms. It's inspired by libevent/bench. - -eloop needs to be compiled for a specific polling mechanism. -eloop will try and work out which one to use, but you can influence which one -by giving one of these CPPFLAGS to the Makefile: - * `HAVE_KQUEUE` - * `HAVE_EPOLL` - * `HAVE_PSELECT` - * `HAVE_POLLTS` - * `HAVE_PPOLL` - -kqueue(2) is found on modern BSD kernels. -epoll(7) is found on modern Linux and Solaris kernels. -These two *should* be the best performers. - -pselect(2) *should* be found on any POSIX libc. -This *should* be the worst performer. - -pollts(2) and ppoll(2) are NetBSD and Linux specific variants on poll(2), -but allow safe signal delivery like pselect(2). -Aside from the function name, the arguments and functionality are identical. -They are of little use as both platforms have kqueue(2) and epoll(2), -but there is an edge case where system doesn't have epoll(2) compiled hence -it's inclusion here. - -## using eloop-bench - -The benchmark runs by setting up npipes to read/write to and attaching -an eloop callback for each pipe reader. -Once setup, it will perform a run by writing to nactive pipes. -For each successful pipe read, if nwrites >0 then the reader will reduce -nwrites by one on successful write back to itself. -Once nwrites is 0, the timed run will end once the last write has been read. -At the end of run, the time taken in seconds and nanoseconds is printed. - -The following arguments can influence the benchmark: - * `-a active` - The number of active pipes, default 1. - * `-n pipes` - The number of pipes to create and attach an eloop callback to, defalt 100. - * `-r runs` - The number of timed runs to make, default 25. - * `-w writes` - The number of writes to make by the read callback, default 100. diff --git a/external/bsd/dhcpcd/dist/tests/eloop-bench/eloop-bench.c b/external/bsd/dhcpcd/dist/tests/eloop-bench/eloop-bench.c deleted file mode 100644 index 0f90e824c3a..00000000000 --- a/external/bsd/dhcpcd/dist/tests/eloop-bench/eloop-bench.c +++ /dev/null @@ -1,184 +0,0 @@ -/* - * eloop benchmark - * Copyright (c) 2006-2018 Roy Marples <roy@marples.name> - * 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. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. - */ - -#include <sys/resource.h> - -#include <err.h> -#include <fcntl.h> -#include <stdio.h> -#include <stdlib.h> -#include <time.h> -#include <unistd.h> - -#include "eloop.h" - -#ifndef timespecsub -#define timespecsub(tsp, usp, vsp) \ - do { \ - (vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec; \ - (vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec; \ - if ((vsp)->tv_nsec < 0) { \ - (vsp)->tv_sec--; \ - (vsp)->tv_nsec += 1000000000L; \ - } \ - } while (/* CONSTCOND */ 0) -#endif - -struct pipe { - int fd[2]; -}; - -static size_t good, bad, writes, fired; -static size_t npipes = 100, nwrites = 100, nactive = 1; -static struct pipe *pipes; -static struct eloop *e; - -static void -read_cb(void *arg) -{ - struct pipe *p = arg; - unsigned char buf[1]; - - if (read(p->fd[0], buf, 1) != 1) { - warn("%s: read", __func__); - bad++; - } else - good++; - - if (writes != 0) { - writes--; - if (write(p->fd[1], "e", 1) != 1) { - warn("%s: write", __func__); - bad++; - } else - fired++; - } - - if (writes == 0 && fired == good) { - //printf("fired %zu, good %zu, bad %zu\n", fired, good, bad); - eloop_exit(e, good == fired && bad == 0 ? - EXIT_SUCCESS : EXIT_FAILURE); - } -} - -static int -runone(struct timespec *t) -{ - size_t i; - struct pipe *p; - struct timespec ts, te; - int result; - - writes = nwrites; - fired = good = 0; - - for (i = 0, p = pipes; i < nactive; i++, p++) { - if (write(p->fd[1], "e", 1) != 1) - err(EXIT_FAILURE, "send"); - writes--; - fired++; - } - - if (clock_gettime(CLOCK_MONOTONIC, &ts) == -1) - err(EXIT_FAILURE, "clock_gettime"); - result = eloop_start(e, NULL); - if (clock_gettime(CLOCK_MONOTONIC, &te) == -1) - err(EXIT_FAILURE, "clock_gettime"); - - timespecsub(&te, &ts, t); - return result; -} - -int -main(int argc, char **argv) -{ - int c, result, exit_code; - size_t i, nruns = 25; - struct pipe *p; - struct timespec ts, te, t; - - while ((c = getopt(argc, argv, "a:n:r:w:")) != -1) { - switch (c) { - case 'a': - nactive = (size_t)atoi(optarg); - break; - case 'n': - npipes = (size_t)atoi(optarg); - break; - case 'r': - nruns = (size_t)atoi(optarg); - break; - case 'w': - nwrites = (size_t)atoi(optarg); - break; - default: - errx(EXIT_FAILURE, "illegal argument `%c'", c); - } - } - - if (clock_gettime(CLOCK_MONOTONIC, &ts) == -1) - err(EXIT_FAILURE, "clock_gettime"); - - if ((e = eloop_new()) == NULL) - err(EXIT_FAILURE, "eloop_init"); - - if (nactive > npipes) - nactive = npipes; - - pipes = calloc(npipes, sizeof(*p)); - if (pipes == NULL) - err(EXIT_FAILURE, "malloc"); - - for (i = 0, p = pipes; i < npipes; i++, p++) { - if (pipe2(p->fd, O_CLOEXEC | O_NONBLOCK) == -1) - err(EXIT_FAILURE, "pipe"); - if (eloop_event_add(e, p->fd[0], read_cb, p) == -1) - err(EXIT_FAILURE, "eloop_event_add"); - } - - printf("active = %zu, pipes = %zu, runs = %zu, writes = %zu\n", - nactive, npipes, nruns, nwrites); - - exit_code = EXIT_SUCCESS; - for (i = 0; i < nruns; i++) { - result = runone(&t); - if (result != EXIT_SUCCESS) - exit_code = result; - printf("run %zu took %lld.%.9ld seconds, result %d\n", - i + 1, (long long)t.tv_sec, t.tv_nsec, result); - } - - eloop_free(e); - free(pipes); - - if (clock_gettime(CLOCK_MONOTONIC, &te) == -1) - err(EXIT_FAILURE, "clock_gettime"); - timespecsub(&te, &ts, &t); - printf("total %lld.%.9ld seconds, result %d\n", - (long long)t.tv_sec, t.tv_nsec, exit_code); - exit(exit_code); -} diff --git a/external/bsd/dhcpcd/sbin/dhcpcd/Makefile b/external/bsd/dhcpcd/sbin/dhcpcd/Makefile index 7b6250bf70a..db9a4287f4e 100644 --- a/external/bsd/dhcpcd/sbin/dhcpcd/Makefile +++ b/external/bsd/dhcpcd/sbin/dhcpcd/Makefile @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.48 2019/07/26 10:49:06 roy Exp $ +# $NetBSD: Makefile,v 1.48.2.1 2019/10/12 14:44:33 martin Exp $ # WARNS?= 6 @@ -13,18 +13,13 @@ SRCS+= if.c if-options.c route.c sa.c script.c SRCS+= dhcp-common.c dhcpcd-embedded.c SRCS+= if-bsd.c -# Need to generate this for dependencies -DPSRCS+= dhcpcd-embedded.h dhcpcd-embedded.c - CPPFLAGS+= -DHAVE_CONFIG_H -D_OPENBSD_SOURCE USE_INET?= yes .if defined(SMALLPROG) CPPFLAGS+= -DSMALL -DHCPCD_DEFS= dhcpcd-definitions-small.conf .else -DHCPCD_DEFS= dhcpcd-definitions.conf CPPFLAGS+= -DAUTH SRCS+= auth.c .endif @@ -50,7 +45,7 @@ CPPFLAGS+= -DDHCP6 SRCS+= dhcp6.c .endif -CPPFLAGS+= -I${SRCDIR}/include -I${DIST}/src -I${.OBJDIR} +CPPFLAGS+= -I${SRCDIR}/include -I${DIST}/src DPADD+= ${LIBUTIL} LDADD+= -lutil @@ -64,14 +59,6 @@ FILESMODE_dhcpcd.conf= 644 # -rw-r--r-- MAN= dhcpcd.conf.5 dhcpcd.8 CLEANFILES= dhcpcd.conf.5 dhcpcd.8 -dhcpcd-embedded.h: genembedh ${DHCPCD_DEFS} dhcpcd-embedded.h.in - ${HOST_SH} ${.ALLSRC} $^ > $@ - -dhcpcd-embedded.c: genembedc ${DHCPCD_DEFS} dhcpcd-embedded.c.in - ${HOST_SH} ${.ALLSRC} $^ > $@ - -CLEANFILES+= dhcpcd-embedded.c dhcpcd-embedded.h - .for f in dhcpcd.conf.5 dhcpcd.8 ${f}: ${f}.in ${TOOL_SED} ${SED_SYS} ${DIST}/src/${f}.in > $@ |
