This commit is contained in:
roy 2019-09-13 11:01:49 +00:00
parent 8fc24ed95e
commit 318ea603b5
70 changed files with 53 additions and 11881 deletions

View File

@ -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

View File

@ -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.

View File

@ -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

View File

@ -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'

View File

@ -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;
}

View File

@ -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);
}

View File

@ -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

View File

@ -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;
}

View File

@ -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

View File

@ -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_ */

View File

@ -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 */

View File

@ -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;
}

View File

@ -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

View File

@ -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 */
}

View File

@ -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

View File

@ -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));
}

View File

@ -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

View File

@ -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;
}

View File

@ -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

View File

@ -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

View File

@ -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;
}

View File

@ -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

View File

@ -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 */

File diff suppressed because it is too large Load Diff

View File

@ -1,211 +0,0 @@
/* $NetBSD: rbtree.h,v 1.1.1.2 2019/09/04 13:27:50 roy 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_*/

View File

@ -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);
}

View File

@ -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

View File

@ -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 */
}

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -1,3 +0,0 @@
# This space left intentionally blank
DHCPCD_SRCS+= dhcpcd-embedded.c

File diff suppressed because it is too large Load Diff

View File

@ -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"

View File

@ -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

View File

@ -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

View File

@ -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}

View File

@ -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

View File

@ -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

View File

@ -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;
}

View File

@ -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}

View File

@ -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;
}

View File

@ -3250,7 +3250,7 @@ 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 ip_len, udp_len, uh_sum;
struct udphdr *udp;
uint32_t csum;
@ -3276,27 +3276,31 @@ valid_udp_packet(void *packet, size_t plen, struct in_addr *from,
errno = ERANGE;
return -1;
}
/* Check we don't go beyond the payload */
/* Check IP doesn't go beyond the payload */
if (ip_len > plen) {
errno = ENOBUFS;
return -1;
}
if (flags & BPF_PARTIALCSUM)
/* Check UDP doesn't go beyond the payload */
udp = (struct udphdr *)(void *)((char *)ip + ip_hlen);
udp_len = ntohs(udp->uh_ulen);
if (udp_len > plen - ip_hlen) {
errno = ENOBUFS;
return -1;
}
if (udp->uh_sum == 0 || 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;
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);
csum = in_cksum(udp, udp_len, &csum);
if (csum != uh_sum) {
errno = EINVAL;
return -1;
@ -3338,12 +3342,13 @@ dhcp_handlepacket(struct interface *ifp, uint8_t *data, size_t len)
const struct dhcp_state *state = D_CSTATE(ifp);
if (valid_udp_packet(data, len, &from, state->bpf_flags) == -1) {
const char *errstr;
if (errno == EINVAL)
logerrx("%s: checksum failure from %s",
ifp->name, inet_ntoa(from));
errstr = "checksum failure";
else
logerr("%s: invalid UDP packet from %s",
ifp->name, inet_ntoa(from));
errstr = "invalid UDP packet";
logerrx("%s: %s from %s", errstr, ifp->name, inet_ntoa(from));
return;
}

View File

@ -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

View File

@ -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

View File

@ -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[] = {

View File

@ -1,32 +0,0 @@
/*
* 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.
*/
#define INITDEFINES @INITDEFINES@
#define INITDEFINENDS @INITDEFINENDS@
#define INITDEFINE6S @INITDEFINE6S@
extern const char * const dhcpcd_embedded_conf[];

View File

@ -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

View File

@ -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" "};"

View File

@ -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

View File

@ -653,6 +653,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;

View File

@ -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
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -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(ia, &state->addrs, next) {
if (IN6_IS_ADDR_LINKLOCAL(&ia->addr))
TAILQ_FOREACH(ifp, sifp->ctx->ifaces, next) {
if (ifp != sifp && ip6_forwarding(ifp->name) != 1)
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;
state = IPV6_STATE(ifp);
if (state == NULL)
continue;
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)

View File

@ -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 *,

View File

@ -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);

View File

@ -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

View File

@ -1 +0,0 @@
run-test

View File

@ -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

View File

@ -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}

View File

@ -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.

View File

@ -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;
}

View File

@ -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

View File

@ -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;
}

View File

@ -1 +0,0 @@
eloop-bench

View File

@ -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}

View File

@ -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.

View File

@ -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);
}