Import dhcpcd-6.11.4 with the following changes:
* Fixed octal and hex string parsing in options. * Several statically sized buffers have been removed and replaced with dynamically sized ones where we have no real idea of what the size will be. * Reverse IPv4 route removal order. * Added --small configure directive to reduce binary size * Allow DHCPv6, IPv4lL and authentication to be compiled out * Add support for ifa_addrflags in getifaddrs(3) * Add support for ifam_addrflags and ifam_pid from route(4) * If T1 or T2 are not set in DHCPv6 messages, use a default from the lowest pltime instead of the expiration time. * Validate lease before moving to REQUEST when both ends use rapid commit. * If lease validation fails, don't restart the DISCOVER phase if we're already in it.
This commit is contained in:
parent
84670d8d34
commit
b2a8abed61
97
external/bsd/dhcpcd/dist/crypt/arp.h
vendored
Normal file
97
external/bsd/dhcpcd/dist/crypt/arp.h
vendored
Normal file
@ -0,0 +1,97 @@
|
||||
/*
|
||||
* dhcpcd - DHCP client daemon
|
||||
* Copyright (c) 2006-2015 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 ARP_H
|
||||
#define ARP_H
|
||||
|
||||
/* ARP timings from RFC5227 */
|
||||
#define PROBE_WAIT 1
|
||||
#define PROBE_NUM 3
|
||||
#define PROBE_MIN 1
|
||||
#define PROBE_MAX 2
|
||||
#define ANNOUNCE_WAIT 2
|
||||
#define ANNOUNCE_NUM 2
|
||||
#define ANNOUNCE_INTERVAL 2
|
||||
#define MAX_CONFLICTS 10
|
||||
#define RATE_LIMIT_INTERVAL 60
|
||||
#define DEFEND_INTERVAL 10
|
||||
|
||||
#include "dhcpcd.h"
|
||||
#include "if.h"
|
||||
|
||||
struct arp_msg {
|
||||
uint16_t op;
|
||||
unsigned char sha[HWADDR_LEN];
|
||||
struct in_addr sip;
|
||||
unsigned char tha[HWADDR_LEN];
|
||||
struct in_addr tip;
|
||||
};
|
||||
|
||||
struct arp_state {
|
||||
TAILQ_ENTRY(arp_state) next;
|
||||
struct interface *iface;
|
||||
|
||||
void (*probed_cb)(struct arp_state *);
|
||||
void (*announced_cb)(struct arp_state *);
|
||||
void (*conflicted_cb)(struct arp_state *, const struct arp_msg *);
|
||||
void (*free_cb)(struct arp_state *);
|
||||
|
||||
struct in_addr addr;
|
||||
int probes;
|
||||
int claims;
|
||||
struct in_addr failed;
|
||||
};
|
||||
TAILQ_HEAD(arp_statehead, arp_state);
|
||||
|
||||
struct iarp_state {
|
||||
int fd;
|
||||
struct arp_statehead arp_states;
|
||||
};
|
||||
|
||||
#define ARP_STATE(ifp) \
|
||||
((struct iarp_state *)(ifp)->if_data[IF_DATA_ARP])
|
||||
#define ARP_CSTATE(ifp) \
|
||||
((const struct iarp_state *)(ifp)->if_data[IF_DATA_ARP])
|
||||
|
||||
#ifdef INET
|
||||
int arp_open(struct interface *);
|
||||
ssize_t arp_request(const struct interface *, in_addr_t, in_addr_t);
|
||||
void arp_report_conflicted(const struct arp_state *, const struct arp_msg *);
|
||||
void arp_announce(struct arp_state *);
|
||||
void arp_probe(struct arp_state *);
|
||||
struct arp_state *arp_new(struct interface *, const struct in_addr *);
|
||||
void arp_cancel(struct arp_state *);
|
||||
void arp_free(struct arp_state *);
|
||||
void arp_free_but(struct arp_state *);
|
||||
struct arp_state *arp_find(struct interface *, const struct in_addr *);
|
||||
void arp_close(struct interface *);
|
||||
|
||||
void arp_handleifa(int, struct ipv4_addr *);
|
||||
#else
|
||||
#define arp_close(a) {}
|
||||
#endif
|
||||
#endif
|
671
external/bsd/dhcpcd/dist/crypt/auth.c
vendored
Normal file
671
external/bsd/dhcpcd/dist/crypt/auth.c
vendored
Normal file
@ -0,0 +1,671 @@
|
||||
/*
|
||||
* dhcpcd - DHCP client daemon
|
||||
* Copyright (c) 2006-2015 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/file.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <inttypes.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "auth.h"
|
||||
#include "crypt/crypt.h"
|
||||
#include "dhcp.h"
|
||||
#include "dhcp6.h"
|
||||
#include "dhcpcd.h"
|
||||
|
||||
#ifdef __sun
|
||||
#define htonll
|
||||
#define ntohll
|
||||
#endif
|
||||
|
||||
#ifndef htonll
|
||||
#if (BYTE_ORDER == LITTLE_ENDIAN)
|
||||
static inline uint64_t
|
||||
htonll(uint64_t x)
|
||||
{
|
||||
|
||||
return (uint64_t)htonl((uint32_t)(x >> 32)) |
|
||||
(uint64_t)htonl((uint32_t)(x & 0xffffffff)) << 32;
|
||||
}
|
||||
#else /* (BYTE_ORDER == LITTLE_ENDIAN) */
|
||||
#define htonll(x) (x)
|
||||
#endif
|
||||
#endif /* htonll */
|
||||
|
||||
#ifndef ntohll
|
||||
#if (BYTE_ORDER == LITTLE_ENDIAN)
|
||||
static inline uint64_t
|
||||
ntohll(uint64_t x)
|
||||
{
|
||||
|
||||
return (uint64_t)ntohl((uint32_t)(x >> 32)) |
|
||||
(uint64_t)ntohl((uint32_t)(x & 0xffffffff)) << 32;
|
||||
}
|
||||
#else /* (BYTE_ORDER == LITTLE_ENDIAN) */
|
||||
#define ntohll(x) (x)
|
||||
#endif
|
||||
#endif /* ntohll */
|
||||
|
||||
#define HMAC_LENGTH 16
|
||||
|
||||
void
|
||||
dhcp_auth_reset(struct authstate *state)
|
||||
{
|
||||
|
||||
state->replay = 0;
|
||||
if (state->token) {
|
||||
free(state->token->key);
|
||||
free(state->token->realm);
|
||||
free(state->token);
|
||||
state->token = NULL;
|
||||
}
|
||||
if (state->reconf) {
|
||||
free(state->reconf->key);
|
||||
free(state->reconf->realm);
|
||||
free(state->reconf);
|
||||
state->reconf = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Authenticate a DHCP message.
|
||||
* m and mlen refer to the whole message.
|
||||
* t is the DHCP type, pass it 4 or 6.
|
||||
* data and dlen refer to the authentication option within the message.
|
||||
*/
|
||||
const struct token *
|
||||
dhcp_auth_validate(struct authstate *state, const struct auth *auth,
|
||||
const uint8_t *m, size_t mlen, int mp, int mt,
|
||||
const uint8_t *data, size_t dlen)
|
||||
{
|
||||
uint8_t protocol, algorithm, rdm, *mm, type;
|
||||
uint64_t replay;
|
||||
uint32_t secretid;
|
||||
const uint8_t *d, *realm;
|
||||
size_t realm_len;
|
||||
const struct token *t;
|
||||
time_t now;
|
||||
uint8_t hmac[HMAC_LENGTH];
|
||||
|
||||
if (dlen < 3 + sizeof(replay)) {
|
||||
errno = EINVAL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Ensure that d is inside m which *may* not be the case for DHPCPv4 */
|
||||
if (data < m || data > m + mlen || data + dlen > m + mlen) {
|
||||
errno = ERANGE;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
d = data;
|
||||
protocol = *d++;
|
||||
algorithm = *d++;
|
||||
rdm = *d++;
|
||||
if (!(auth->options & DHCPCD_AUTH_SEND)) {
|
||||
/* If we didn't send any authorisation, it can only be a
|
||||
* reconfigure key */
|
||||
if (protocol != AUTH_PROTO_RECONFKEY) {
|
||||
errno = EINVAL;
|
||||
return NULL;
|
||||
}
|
||||
} else if (protocol != auth->protocol ||
|
||||
algorithm != auth->algorithm ||
|
||||
rdm != auth->rdm)
|
||||
{
|
||||
/* As we don't require authentication, we should still
|
||||
* accept a reconfigure key */
|
||||
if (protocol != AUTH_PROTO_RECONFKEY ||
|
||||
auth->options & DHCPCD_AUTH_REQUIRE)
|
||||
{
|
||||
errno = EPERM;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
dlen -= 3;
|
||||
|
||||
memcpy(&replay, d, sizeof(replay));
|
||||
replay = ntohll(replay);
|
||||
if (state->token) {
|
||||
if (state->replay == (replay ^ 0x8000000000000000ULL)) {
|
||||
/* We don't know if the singular point is increasing
|
||||
* or decreasing. */
|
||||
errno = EPERM;
|
||||
return NULL;
|
||||
}
|
||||
if ((uint64_t)(replay - state->replay) <= 0) {
|
||||
/* Replay attack detected */
|
||||
errno = EPERM;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
d+= sizeof(replay);
|
||||
dlen -= sizeof(replay);
|
||||
|
||||
realm = NULL;
|
||||
realm_len = 0;
|
||||
|
||||
/* Extract realm and secret.
|
||||
* Rest of data is MAC. */
|
||||
switch (protocol) {
|
||||
case AUTH_PROTO_TOKEN:
|
||||
secretid = 0;
|
||||
break;
|
||||
case AUTH_PROTO_DELAYED:
|
||||
if (dlen < sizeof(secretid) + sizeof(hmac)) {
|
||||
errno = EINVAL;
|
||||
return NULL;
|
||||
}
|
||||
memcpy(&secretid, d, sizeof(secretid));
|
||||
d += sizeof(secretid);
|
||||
dlen -= sizeof(secretid);
|
||||
break;
|
||||
case AUTH_PROTO_DELAYEDREALM:
|
||||
if (dlen < sizeof(secretid) + sizeof(hmac)) {
|
||||
errno = EINVAL;
|
||||
return NULL;
|
||||
}
|
||||
realm_len = dlen - (sizeof(secretid) + sizeof(hmac));
|
||||
if (realm_len) {
|
||||
realm = d;
|
||||
d += realm_len;
|
||||
dlen -= realm_len;
|
||||
}
|
||||
memcpy(&secretid, d, sizeof(secretid));
|
||||
d += sizeof(secretid);
|
||||
dlen -= sizeof(secretid);
|
||||
break;
|
||||
case AUTH_PROTO_RECONFKEY:
|
||||
if (dlen != 1 + 16) {
|
||||
errno = EINVAL;
|
||||
return NULL;
|
||||
}
|
||||
type = *d++;
|
||||
dlen--;
|
||||
switch (type) {
|
||||
case 1:
|
||||
if ((mp == 4 && mt == DHCP_ACK) ||
|
||||
(mp == 6 && mt == DHCP6_REPLY))
|
||||
{
|
||||
if (state->reconf == NULL) {
|
||||
state->reconf =
|
||||
malloc(sizeof(*state->reconf));
|
||||
if (state->reconf == NULL)
|
||||
return NULL;
|
||||
state->reconf->key = malloc(16);
|
||||
if (state->reconf->key == NULL) {
|
||||
free(state->reconf);
|
||||
state->reconf = NULL;
|
||||
return NULL;
|
||||
}
|
||||
state->reconf->secretid = 0;
|
||||
state->reconf->expire = 0;
|
||||
state->reconf->realm = NULL;
|
||||
state->reconf->realm_len = 0;
|
||||
state->reconf->key_len = 16;
|
||||
}
|
||||
memcpy(state->reconf->key, d, 16);
|
||||
} else {
|
||||
errno = EINVAL;
|
||||
return NULL;
|
||||
}
|
||||
if (state->reconf == NULL)
|
||||
errno = ENOENT;
|
||||
/* Free the old token so we log acceptance */
|
||||
if (state->token) {
|
||||
free(state->token);
|
||||
state->token = NULL;
|
||||
}
|
||||
/* Nothing to validate, just accepting the key */
|
||||
return state->reconf;
|
||||
case 2:
|
||||
if (!((mp == 4 && mt == DHCP_FORCERENEW) ||
|
||||
(mp == 6 && mt == DHCP6_RECONFIGURE)))
|
||||
{
|
||||
errno = EINVAL;
|
||||
return NULL;
|
||||
}
|
||||
if (state->reconf == NULL) {
|
||||
errno = ENOENT;
|
||||
return NULL;
|
||||
}
|
||||
t = state->reconf;
|
||||
goto gottoken;
|
||||
default:
|
||||
errno = EINVAL;
|
||||
return NULL;
|
||||
}
|
||||
default:
|
||||
errno = ENOTSUP;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Find a token for the realm and secret */
|
||||
secretid = ntohl(secretid);
|
||||
TAILQ_FOREACH(t, &auth->tokens, next) {
|
||||
if (t->secretid == secretid &&
|
||||
t->realm_len == realm_len &&
|
||||
(t->realm_len == 0 ||
|
||||
memcmp(t->realm, realm, t->realm_len) == 0))
|
||||
break;
|
||||
}
|
||||
if (t == NULL) {
|
||||
errno = ESRCH;
|
||||
return NULL;
|
||||
}
|
||||
if (t->expire) {
|
||||
if (time(&now) == -1)
|
||||
return NULL;
|
||||
if (t->expire < now) {
|
||||
errno = EFAULT;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
gottoken:
|
||||
/* First message from the server */
|
||||
if (state->token &&
|
||||
(state->token->secretid != t->secretid ||
|
||||
state->token->realm_len != t->realm_len ||
|
||||
memcmp(state->token->realm, t->realm, t->realm_len)))
|
||||
{
|
||||
errno = EPERM;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Special case as no hashing needs to be done. */
|
||||
if (protocol == AUTH_PROTO_TOKEN) {
|
||||
if (dlen != t->key_len || memcmp(d, t->key, dlen)) {
|
||||
errno = EPERM;
|
||||
return NULL;
|
||||
}
|
||||
goto finish;
|
||||
}
|
||||
|
||||
/* Make a duplicate of the message, but zero out the MAC part */
|
||||
mm = malloc(mlen);
|
||||
if (mm == NULL)
|
||||
return NULL;
|
||||
memcpy(mm, m, mlen);
|
||||
memset(mm + (d - m), 0, dlen);
|
||||
|
||||
/* RFC3318, section 5.2 - zero giaddr and hops */
|
||||
if (mp == 4) {
|
||||
*(mm + offsetof(struct bootp, hops)) = '\0';
|
||||
memset(mm + offsetof(struct bootp, giaddr), 0, 4);
|
||||
}
|
||||
|
||||
memset(hmac, 0, sizeof(hmac));
|
||||
switch (algorithm) {
|
||||
case AUTH_ALG_HMAC_MD5:
|
||||
hmac_md5(mm, mlen, t->key, t->key_len, hmac);
|
||||
break;
|
||||
default:
|
||||
errno = ENOSYS;
|
||||
free(mm);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
free(mm);
|
||||
if (memcmp(d, &hmac, dlen)) {
|
||||
errno = EPERM;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
finish:
|
||||
/* If we got here then authentication passed */
|
||||
state->replay = replay;
|
||||
if (state->token == NULL) {
|
||||
/* We cannot just save a pointer because a reconfigure will
|
||||
* recreate the token list. So we duplicate it. */
|
||||
state->token = malloc(sizeof(*state->token));
|
||||
if (state->token) {
|
||||
state->token->secretid = t->secretid;
|
||||
state->token->key = malloc(t->key_len);
|
||||
if (state->token->key) {
|
||||
state->token->key_len = t->key_len;
|
||||
memcpy(state->token->key, t->key, t->key_len);
|
||||
} else {
|
||||
free(state->token);
|
||||
state->token = NULL;
|
||||
return NULL;
|
||||
}
|
||||
if (t->realm_len) {
|
||||
state->token->realm = malloc(t->realm_len);
|
||||
if (state->token->realm) {
|
||||
state->token->realm_len = t->realm_len;
|
||||
memcpy(state->token->realm, t->realm,
|
||||
t->realm_len);
|
||||
} else {
|
||||
free(state->token->key);
|
||||
free(state->token);
|
||||
state->token = NULL;
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
state->token->realm = NULL;
|
||||
state->token->realm_len = 0;
|
||||
}
|
||||
}
|
||||
/* If we cannot save the token, we must invalidate */
|
||||
if (state->token == NULL)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
static uint64_t
|
||||
get_next_rdm_monotonic_counter(struct auth *auth)
|
||||
{
|
||||
FILE *fp;
|
||||
uint64_t rdm;
|
||||
#ifdef LOCK_EX
|
||||
int flocked;
|
||||
#endif
|
||||
|
||||
fp = fopen(RDM_MONOFILE, "r+");
|
||||
if (fp == NULL) {
|
||||
if (errno != ENOENT)
|
||||
return ++auth->last_replay; /* report error? */
|
||||
fp = fopen(RDM_MONOFILE, "w");
|
||||
if (fp == NULL)
|
||||
return ++auth->last_replay; /* report error? */
|
||||
#ifdef LOCK_EX
|
||||
flocked = flock(fileno(fp), LOCK_EX);
|
||||
#endif
|
||||
rdm = 0;
|
||||
} else {
|
||||
#ifdef LOCK_EX
|
||||
flocked = flock(fileno(fp), LOCK_EX);
|
||||
#endif
|
||||
if (fscanf(fp, "0x%016" PRIu64, &rdm) != 1)
|
||||
rdm = 0; /* truncated? report error? */
|
||||
}
|
||||
|
||||
rdm++;
|
||||
if (fseek(fp, 0, SEEK_SET) == -1 ||
|
||||
ftruncate(fileno(fp), 0) == -1 ||
|
||||
fprintf(fp, "0x%016" PRIu64 "\n", rdm) != 19 ||
|
||||
fflush(fp) == EOF)
|
||||
{
|
||||
if (!auth->last_replay_set) {
|
||||
auth->last_replay = rdm;
|
||||
auth->last_replay_set = 1;
|
||||
} else
|
||||
rdm = ++auth->last_replay;
|
||||
/* report error? */
|
||||
}
|
||||
#ifdef LOCK_EX
|
||||
if (flocked == 0)
|
||||
flock(fileno(fp), LOCK_UN);
|
||||
#endif
|
||||
fclose(fp);
|
||||
return rdm;
|
||||
}
|
||||
|
||||
#define JAN_1970 2208988800U /* 1970 - 1900 in seconds */
|
||||
static uint64_t
|
||||
get_next_rdm_monotonic_clock(struct auth *auth)
|
||||
{
|
||||
struct timespec ts;
|
||||
uint32_t pack[2];
|
||||
double frac;
|
||||
uint64_t rdm;
|
||||
|
||||
if (clock_gettime(CLOCK_REALTIME, &ts) != 0)
|
||||
return ++auth->last_replay; /* report error? */
|
||||
pack[0] = htonl((uint32_t)ts.tv_sec + JAN_1970);
|
||||
frac = ((double)ts.tv_nsec / 1e9 * 0x100000000ULL);
|
||||
pack[1] = htonl((uint32_t)frac);
|
||||
|
||||
memcpy(&rdm, &pack, sizeof(rdm));
|
||||
return rdm;
|
||||
}
|
||||
|
||||
static uint64_t
|
||||
get_next_rdm_monotonic(struct auth *auth)
|
||||
{
|
||||
|
||||
if (auth->options & DHCPCD_AUTH_RDM_COUNTER)
|
||||
return get_next_rdm_monotonic_counter(auth);
|
||||
return get_next_rdm_monotonic_clock(auth);
|
||||
}
|
||||
|
||||
/*
|
||||
* Encode a DHCP message.
|
||||
* Either we know which token to use from the server response
|
||||
* or we are using a basic configuration token.
|
||||
* token is the token to encrypt with.
|
||||
* m and mlen refer to the whole message.
|
||||
* mp is the DHCP type, pass it 4 or 6.
|
||||
* mt is the DHCP message type.
|
||||
* data and dlen refer to the authentication option within the message.
|
||||
*/
|
||||
ssize_t
|
||||
dhcp_auth_encode(struct auth *auth, const struct token *t,
|
||||
uint8_t *m, size_t mlen, int mp, int mt,
|
||||
uint8_t *data, size_t dlen)
|
||||
{
|
||||
uint64_t rdm;
|
||||
uint8_t hmac[HMAC_LENGTH];
|
||||
time_t now;
|
||||
uint8_t hops, *p, info;
|
||||
uint32_t giaddr, secretid;
|
||||
|
||||
if (auth->protocol == 0 && t == NULL) {
|
||||
TAILQ_FOREACH(t, &auth->tokens, next) {
|
||||
if (t->secretid == 0 &&
|
||||
t->realm_len == 0)
|
||||
break;
|
||||
}
|
||||
if (t == NULL) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
if (t->expire) {
|
||||
if (time(&now) == -1)
|
||||
return -1;
|
||||
if (t->expire < now) {
|
||||
errno = EPERM;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch(auth->protocol) {
|
||||
case AUTH_PROTO_TOKEN:
|
||||
case AUTH_PROTO_DELAYED:
|
||||
case AUTH_PROTO_DELAYEDREALM:
|
||||
/* We don't ever send a reconf key */
|
||||
break;
|
||||
default:
|
||||
errno = ENOTSUP;
|
||||
return -1;
|
||||
}
|
||||
|
||||
switch(auth->algorithm) {
|
||||
case AUTH_ALG_HMAC_MD5:
|
||||
break;
|
||||
default:
|
||||
errno = ENOTSUP;
|
||||
return -1;
|
||||
}
|
||||
|
||||
switch(auth->rdm) {
|
||||
case AUTH_RDM_MONOTONIC:
|
||||
break;
|
||||
default:
|
||||
errno = ENOTSUP;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* DISCOVER or INFORM messages don't write auth info */
|
||||
if ((mp == 4 && (mt == DHCP_DISCOVER || mt == DHCP_INFORM)) ||
|
||||
(mp == 6 && (mt == DHCP6_SOLICIT || mt == DHCP6_INFORMATION_REQ)))
|
||||
info = 0;
|
||||
else
|
||||
info = 1;
|
||||
|
||||
/* Work out the auth area size.
|
||||
* We only need to do this for DISCOVER messages */
|
||||
if (data == NULL) {
|
||||
dlen = 1 + 1 + 1 + 8;
|
||||
switch(auth->protocol) {
|
||||
case AUTH_PROTO_TOKEN:
|
||||
dlen += t->key_len;
|
||||
break;
|
||||
case AUTH_PROTO_DELAYEDREALM:
|
||||
if (info && t)
|
||||
dlen += t->realm_len;
|
||||
/* FALLTHROUGH */
|
||||
case AUTH_PROTO_DELAYED:
|
||||
if (info && t)
|
||||
dlen += sizeof(t->secretid) + sizeof(hmac);
|
||||
break;
|
||||
}
|
||||
return (ssize_t)dlen;
|
||||
}
|
||||
|
||||
if (dlen < 1 + 1 + 1 + 8) {
|
||||
errno = ENOBUFS;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Ensure that d is inside m which *may* not be the case for DHPCPv4 */
|
||||
if (data < m || data > m + mlen || data + dlen > m + mlen) {
|
||||
errno = ERANGE;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Write out our option */
|
||||
*data++ = auth->protocol;
|
||||
*data++ = auth->algorithm;
|
||||
*data++ = auth->rdm;
|
||||
switch (auth->rdm) {
|
||||
case AUTH_RDM_MONOTONIC:
|
||||
rdm = get_next_rdm_monotonic(auth);
|
||||
break;
|
||||
default:
|
||||
/* This block appeases gcc, clang doesn't need it */
|
||||
rdm = get_next_rdm_monotonic(auth);
|
||||
break;
|
||||
}
|
||||
rdm = htonll(rdm);
|
||||
memcpy(data, &rdm, 8);
|
||||
data += 8;
|
||||
dlen -= 1 + 1 + 1 + 8;
|
||||
|
||||
/* Special case as no hashing needs to be done. */
|
||||
if (auth->protocol == AUTH_PROTO_TOKEN) {
|
||||
/* Should be impossible, but still */
|
||||
if (t == NULL) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
if (dlen < t->key_len) {
|
||||
errno = ENOBUFS;
|
||||
return -1;
|
||||
}
|
||||
memcpy(data, t->key, t->key_len);
|
||||
return (ssize_t)(dlen - t->key_len);
|
||||
}
|
||||
|
||||
/* DISCOVER or INFORM messages don't write auth info */
|
||||
if (!info)
|
||||
return (ssize_t)dlen;
|
||||
|
||||
/* Loading a saved lease without an authentication option */
|
||||
if (t == NULL)
|
||||
return 0;
|
||||
|
||||
/* Write out the Realm */
|
||||
if (auth->protocol == AUTH_PROTO_DELAYEDREALM) {
|
||||
if (dlen < t->realm_len) {
|
||||
errno = ENOBUFS;
|
||||
return -1;
|
||||
}
|
||||
memcpy(data, t->realm, t->realm_len);
|
||||
data += t->realm_len;
|
||||
dlen -= t->realm_len;
|
||||
}
|
||||
|
||||
/* Write out the SecretID */
|
||||
if (auth->protocol == AUTH_PROTO_DELAYED ||
|
||||
auth->protocol == AUTH_PROTO_DELAYEDREALM)
|
||||
{
|
||||
if (dlen < sizeof(t->secretid)) {
|
||||
errno = ENOBUFS;
|
||||
return -1;
|
||||
}
|
||||
secretid = htonl(t->secretid);
|
||||
memcpy(data, &secretid, sizeof(secretid));
|
||||
data += sizeof(secretid);
|
||||
dlen -= sizeof(secretid);
|
||||
}
|
||||
|
||||
/* Zero what's left, the MAC */
|
||||
memset(data, 0, dlen);
|
||||
|
||||
/* RFC3318, section 5.2 - zero giaddr and hops */
|
||||
if (mp == 4) {
|
||||
p = m + offsetof(struct bootp, hops);
|
||||
hops = *p;
|
||||
*p = '\0';
|
||||
p = m + offsetof(struct bootp, giaddr);
|
||||
memcpy(&giaddr, p, sizeof(giaddr));
|
||||
memset(p, 0, sizeof(giaddr));
|
||||
} else {
|
||||
/* appease GCC again */
|
||||
hops = 0;
|
||||
giaddr = 0;
|
||||
}
|
||||
|
||||
/* Create our hash and write it out */
|
||||
switch(auth->algorithm) {
|
||||
case AUTH_ALG_HMAC_MD5:
|
||||
hmac_md5(m, mlen, t->key, t->key_len, hmac);
|
||||
memcpy(data, hmac, sizeof(hmac));
|
||||
break;
|
||||
}
|
||||
|
||||
/* RFC3318, section 5.2 - restore giaddr and hops */
|
||||
if (mp == 4) {
|
||||
p = m + offsetof(struct bootp, hops);
|
||||
*p = hops;
|
||||
p = m + offsetof(struct bootp, giaddr);
|
||||
memcpy(p, &giaddr, sizeof(giaddr));
|
||||
}
|
||||
|
||||
/* Done! */
|
||||
return (int)(dlen - sizeof(hmac)); /* should be zero */
|
||||
}
|
92
external/bsd/dhcpcd/dist/crypt/auth.h
vendored
Normal file
92
external/bsd/dhcpcd/dist/crypt/auth.h
vendored
Normal file
@ -0,0 +1,92 @@
|
||||
/*
|
||||
* dhcpcd - DHCP client daemon
|
||||
* Copyright (c) 2006-2015 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 AUTH_H
|
||||
#define AUTH_H
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#ifdef HAVE_SYS_QUEUE_H
|
||||
#include <sys/queue.h>
|
||||
#endif
|
||||
|
||||
#define DHCPCD_AUTH_SEND (1 << 0)
|
||||
#define DHCPCD_AUTH_REQUIRE (1 << 1)
|
||||
#define DHCPCD_AUTH_RDM_COUNTER (1 << 2)
|
||||
|
||||
#define DHCPCD_AUTH_SENDREQUIRE (DHCPCD_AUTH_SEND | DHCPCD_AUTH_REQUIRE)
|
||||
|
||||
#define AUTH_PROTO_TOKEN 0
|
||||
#define AUTH_PROTO_DELAYED 1
|
||||
#define AUTH_PROTO_DELAYEDREALM 2
|
||||
#define AUTH_PROTO_RECONFKEY 3
|
||||
|
||||
#define AUTH_ALG_HMAC_MD5 1
|
||||
|
||||
#define AUTH_RDM_MONOTONIC 0
|
||||
|
||||
struct token {
|
||||
TAILQ_ENTRY(token) next;
|
||||
uint32_t secretid;
|
||||
size_t realm_len;
|
||||
unsigned char *realm;
|
||||
size_t key_len;
|
||||
unsigned char *key;
|
||||
time_t expire;
|
||||
};
|
||||
|
||||
TAILQ_HEAD(token_head, token);
|
||||
|
||||
struct auth {
|
||||
int options;
|
||||
#ifdef AUTH
|
||||
uint8_t protocol;
|
||||
uint8_t algorithm;
|
||||
uint8_t rdm;
|
||||
uint64_t last_replay;
|
||||
uint8_t last_replay_set;
|
||||
struct token_head tokens;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct authstate {
|
||||
uint64_t replay;
|
||||
struct token *token;
|
||||
struct token *reconf;
|
||||
};
|
||||
|
||||
void dhcp_auth_reset(struct authstate *);
|
||||
|
||||
const struct token * dhcp_auth_validate(struct authstate *,
|
||||
const struct auth *,
|
||||
const uint8_t *, size_t, int, int,
|
||||
const uint8_t *, size_t);
|
||||
|
||||
ssize_t dhcp_auth_encode(struct auth *, const struct token *,
|
||||
uint8_t *, size_t, int, int,
|
||||
uint8_t *, size_t);
|
||||
#endif
|
205
external/bsd/dhcpcd/dist/crypt/common.h
vendored
Normal file
205
external/bsd/dhcpcd/dist/crypt/common.h
vendored
Normal file
@ -0,0 +1,205 @@
|
||||
/*
|
||||
* dhcpcd - DHCP client daemon
|
||||
* Copyright (c) 2006-2016 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 COMMON_H
|
||||
#define COMMON_H
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/time.h>
|
||||
#include <stdio.h>
|
||||
#include <syslog.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "defs.h"
|
||||
#include "dhcpcd.h"
|
||||
|
||||
#ifndef HOSTNAME_MAX_LEN
|
||||
#define HOSTNAME_MAX_LEN 250 /* 255 - 3 (FQDN) - 2 (DNS enc) */
|
||||
#endif
|
||||
|
||||
#ifndef MIN
|
||||
#define MIN(a,b) ((/*CONSTCOND*/(a)<(b))?(a):(b))
|
||||
#define MAX(a,b) ((/*CONSTCOND*/(a)>(b))?(a):(b))
|
||||
#endif
|
||||
|
||||
#define UNCONST(a) ((void *)(unsigned long)(const void *)(a))
|
||||
#define STRINGIFY(a) #a
|
||||
#define TOSTRING(a) STRINGIFY(a)
|
||||
#define UNUSED(a) (void)(a)
|
||||
|
||||
#define ROUNDUP4(a) (1 + (((a) - 1) | 3))
|
||||
#define ROUNDUP8(a) (1 + (((a) - 1) | 7))
|
||||
|
||||
#define USEC_PER_SEC 1000000L
|
||||
#define USEC_PER_NSEC 1000L
|
||||
#define NSEC_PER_SEC 1000000000L
|
||||
#define NSEC_PER_MSEC 1000000L
|
||||
#define MSEC_PER_SEC 1000L
|
||||
#define CSEC_PER_SEC 100L
|
||||
#define NSEC_PER_CSEC 10000000L
|
||||
|
||||
/* Some systems don't define timespec macros */
|
||||
#ifndef timespecclear
|
||||
#define timespecclear(tsp) (tsp)->tv_sec = (time_t)((tsp)->tv_nsec = 0L)
|
||||
#define timespecisset(tsp) ((tsp)->tv_sec || (tsp)->tv_nsec)
|
||||
#define timespeccmp(tsp, usp, cmp) \
|
||||
(((tsp)->tv_sec == (usp)->tv_sec) ? \
|
||||
((tsp)->tv_nsec cmp (usp)->tv_nsec) : \
|
||||
((tsp)->tv_sec cmp (usp)->tv_sec))
|
||||
#define timespecadd(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 >= 1000000000L) { \
|
||||
(vsp)->tv_sec++; \
|
||||
(vsp)->tv_nsec -= 1000000000L; \
|
||||
} \
|
||||
} while (/* CONSTCOND */ 0)
|
||||
#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
|
||||
|
||||
#define timespec_to_double(tv) \
|
||||
((double)(tv)->tv_sec + (double)((tv)->tv_nsec) / 1000000000.0)
|
||||
#define timespecnorm(tv) do { \
|
||||
while ((tv)->tv_nsec >= NSEC_PER_SEC) { \
|
||||
(tv)->tv_sec++; \
|
||||
(tv)->tv_nsec -= NSEC_PER_SEC; \
|
||||
} \
|
||||
} while (0 /* CONSTCOND */);
|
||||
#define ts_to_ms(ms, tv) do { \
|
||||
ms = (tv)->tv_sec * MSEC_PER_SEC; \
|
||||
ms += (tv)->tv_nsec / NSEC_PER_MSEC; \
|
||||
} while (0 /* CONSTCOND */);
|
||||
#define ms_to_ts(tv, ms) do { \
|
||||
(tv)->tv_sec = ms / MSEC_PER_SEC; \
|
||||
(tv)->tv_nsec = (suseconds_t)(ms - ((tv)->tv_sec * MSEC_PER_SEC)) \
|
||||
* NSEC_PER_MSEC; \
|
||||
} while (0 /* CONSTCOND */);
|
||||
|
||||
#ifndef TIMEVAL_TO_TIMESPEC
|
||||
#define TIMEVAL_TO_TIMESPEC(tv, ts) do { \
|
||||
(ts)->tv_sec = (tv)->tv_sec; \
|
||||
(ts)->tv_nsec = (tv)->tv_usec * USEC_PER_NSEC; \
|
||||
} while (0 /* CONSTCOND */)
|
||||
#endif
|
||||
|
||||
#if __GNUC__ > 2 || defined(__INTEL_COMPILER)
|
||||
# ifndef __packed
|
||||
# define __packed __attribute__((__packed__))
|
||||
# endif
|
||||
# ifndef __sysloglike
|
||||
# ifndef __syslog_attribute_
|
||||
# define __syslog__ __printf__
|
||||
# endif
|
||||
# define __sysloglike(a, b) __attribute__((format(__syslog__, a, b)))
|
||||
# endif
|
||||
# ifndef __unused
|
||||
# define __unused __attribute__((__unused__))
|
||||
# endif
|
||||
#else
|
||||
# ifndef __packed
|
||||
# define __packed
|
||||
# endif
|
||||
# ifndef __sysloglike
|
||||
# define __sysloglike
|
||||
# endif
|
||||
# ifndef __unused
|
||||
# define __unused
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef __arraycount
|
||||
# define __arraycount(__x) (sizeof(__x) / sizeof(__x[0]))
|
||||
#endif
|
||||
|
||||
/* We don't really need this as our supported systems define __restrict
|
||||
* automatically for us, but it is here for completeness. */
|
||||
#ifndef __restrict
|
||||
# if defined(__lint__)
|
||||
# define __restrict
|
||||
# elif __STDC_VERSION__ >= 199901L
|
||||
# define __restrict restrict
|
||||
# elif !(2 < __GNUC__ || (2 == __GNU_C && 95 <= __GNUC_VERSION__))
|
||||
# define __restrict
|
||||
# endif
|
||||
#endif
|
||||
|
||||
void get_line_free(void);
|
||||
extern int clock_monotonic;
|
||||
int get_monotonic(struct timespec *);
|
||||
|
||||
/* We could shave a few k off the binary size by just using the
|
||||
* syslog(3) interface.
|
||||
* However, this results in a ugly output on the command line
|
||||
* and relies on syslogd(8) starting before dhcpcd which is not
|
||||
* always the case. */
|
||||
#ifdef SMALL
|
||||
# undef USE_LOGFILE
|
||||
# define USE_LOGFILE 0
|
||||
#endif
|
||||
#ifndef USE_LOGFILE
|
||||
# define USE_LOGFILE 1
|
||||
#endif
|
||||
#if USE_LOGFILE
|
||||
void logger_open(struct dhcpcd_ctx *);
|
||||
#define logger_mask(ctx, lvl) setlogmask((lvl))
|
||||
void logger(struct dhcpcd_ctx *, int, const char *, ...) __sysloglike(3, 4);
|
||||
void logger_close(struct dhcpcd_ctx *);
|
||||
#else
|
||||
#define logger_open(ctx) openlog(PACKAGE, LOG_PERROR | LOG_PID, LOG_DAEMON)
|
||||
#define logger_mask(ctx, lvl) setlogmask((lvl))
|
||||
#define logger(ctx, pri, fmt, ...) \
|
||||
do { \
|
||||
UNUSED((ctx)); \
|
||||
syslog((pri), (fmt), ##__VA_ARGS__); \
|
||||
} while (0 /*CONSTCOND */)
|
||||
#define logger_close(ctx) closelog()
|
||||
#endif
|
||||
|
||||
ssize_t setvar(struct dhcpcd_ctx *,
|
||||
char **, const char *, const char *, const char *);
|
||||
ssize_t setvard(struct dhcpcd_ctx *,
|
||||
char **, const char *, const char *, size_t);
|
||||
ssize_t addvar(struct dhcpcd_ctx *,
|
||||
char ***, const char *, const char *, const char *);
|
||||
ssize_t addvard(struct dhcpcd_ctx *,
|
||||
char ***, const char *, const char *, size_t);
|
||||
|
||||
char *hwaddr_ntoa(const uint8_t *, size_t, char *, size_t);
|
||||
size_t hwaddr_aton(uint8_t *, const char *);
|
||||
size_t read_hwaddr_aton(uint8_t **, const char *);
|
||||
|
||||
ssize_t recvmsg_realloc(int, struct msghdr *, int);
|
||||
#endif
|
19
external/bsd/dhcpcd/dist/crypt/config.h
vendored
Normal file
19
external/bsd/dhcpcd/dist/crypt/config.h
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
/* netbsd */
|
||||
#define SYSCONFDIR "/etc"
|
||||
#define SBINDIR "/sbin"
|
||||
#define LIBDIR "/lib"
|
||||
#define LIBEXECDIR "/libexec"
|
||||
#define DBDIR "/var/db"
|
||||
#define RUNDIR "/var/run"
|
||||
#define HAVE_IFAM_PID
|
||||
#define HAVE_IFAM_ADDRFLAGS
|
||||
#define HAVE_IFADDRS_ADDRFLAGS
|
||||
#define HAVE_UTIL_H
|
||||
#define HAVE_SYS_QUEUE_H
|
||||
#define HAVE_SPAWN_H
|
||||
#define HAVE_REALLOCARRAY
|
||||
#define HAVE_KQUEUE
|
||||
#define HAVE_KQUEUE1
|
||||
#define HAVE_SYS_BITOPS_H
|
||||
#define HAVE_MD5_H
|
||||
#define SHA2_H <sha2.h>
|
64
external/bsd/dhcpcd/dist/crypt/control.h
vendored
Normal file
64
external/bsd/dhcpcd/dist/crypt/control.h
vendored
Normal file
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* dhcpcd - DHCP client daemon
|
||||
* Copyright (c) 2006-2016 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 CONTROL_H
|
||||
#define CONTROL_H
|
||||
|
||||
#include "dhcpcd.h"
|
||||
|
||||
/* Limit queue size per fd */
|
||||
#define CONTROL_QUEUE_MAX 100
|
||||
|
||||
struct fd_data {
|
||||
TAILQ_ENTRY(fd_data) next;
|
||||
char *data;
|
||||
size_t data_len;
|
||||
uint8_t freeit;
|
||||
};
|
||||
TAILQ_HEAD(fd_data_head, fd_data);
|
||||
|
||||
struct fd_list {
|
||||
TAILQ_ENTRY(fd_list) next;
|
||||
struct dhcpcd_ctx *ctx;
|
||||
int fd;
|
||||
unsigned int flags;
|
||||
struct fd_data_head queue;
|
||||
struct fd_data_head free_queue;
|
||||
};
|
||||
TAILQ_HEAD(fd_list_head, fd_list);
|
||||
|
||||
#define FD_LISTEN (1<<0)
|
||||
#define FD_UNPRIV (1<<1)
|
||||
|
||||
int control_start(struct dhcpcd_ctx *, const char *);
|
||||
int control_stop(struct dhcpcd_ctx *);
|
||||
int control_open(const char *);
|
||||
ssize_t control_send(struct dhcpcd_ctx *, int, char * const *);
|
||||
int control_queue(struct fd_list *fd, char *data, size_t data_len, uint8_t fit);
|
||||
void control_close(struct dhcpcd_ctx *ctx);
|
||||
|
||||
#endif
|
76
external/bsd/dhcpcd/dist/crypt/defs.h
vendored
Normal file
76
external/bsd/dhcpcd/dist/crypt/defs.h
vendored
Normal file
@ -0,0 +1,76 @@
|
||||
/*
|
||||
* dhcpcd - DHCP client daemon
|
||||
* Copyright (c) 2006-2016 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.
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_H
|
||||
#define CONFIG_H
|
||||
|
||||
#define PACKAGE "dhcpcd"
|
||||
#define VERSION "6.11.4"
|
||||
|
||||
#ifndef CONFIG
|
||||
# define CONFIG SYSCONFDIR "/" PACKAGE ".conf"
|
||||
#endif
|
||||
#ifndef SCRIPT
|
||||
# define SCRIPT LIBEXECDIR "/" PACKAGE "-run-hooks"
|
||||
#endif
|
||||
#ifndef DEVDIR
|
||||
# define DEVDIR LIBDIR "/" PACKAGE "/dev"
|
||||
#endif
|
||||
#ifndef DUID
|
||||
# define DUID SYSCONFDIR "/" PACKAGE ".duid"
|
||||
#endif
|
||||
#ifndef SECRET
|
||||
# define SECRET SYSCONFDIR "/" PACKAGE ".secret"
|
||||
#endif
|
||||
#ifndef LEASEFILE
|
||||
# define LEASEFILE DBDIR "/" PACKAGE "-%s%s.lease"
|
||||
#endif
|
||||
#ifndef LEASEFILE6
|
||||
# define LEASEFILE6 LEASEFILE "6"
|
||||
#endif
|
||||
#ifndef PIDFILE
|
||||
# define PIDFILE RUNDIR "/" PACKAGE "%s%s%s.pid"
|
||||
#endif
|
||||
#ifndef CONTROLSOCKET
|
||||
# define CONTROLSOCKET RUNDIR "/" PACKAGE "%s%s.sock"
|
||||
#endif
|
||||
#ifndef UNPRIVSOCKET
|
||||
# define UNPRIVSOCKET RUNDIR "/" PACKAGE ".unpriv.sock"
|
||||
#endif
|
||||
#ifndef RDM_MONOFILE
|
||||
# define RDM_MONOFILE DBDIR "/" PACKAGE "-rdm.monotonic"
|
||||
#endif
|
||||
|
||||
#ifndef NO_SIGNALS
|
||||
# define USE_SIGNALS
|
||||
#endif
|
||||
#ifndef USE_SIGNALS
|
||||
# ifndef THERE_IS_NO_FORK
|
||||
# define THERE_IS_NO_FORK
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#endif
|
123
external/bsd/dhcpcd/dist/crypt/dhcp-common.h
vendored
Normal file
123
external/bsd/dhcpcd/dist/crypt/dhcp-common.h
vendored
Normal file
@ -0,0 +1,123 @@
|
||||
/*
|
||||
* dhcpcd - DHCP client daemon
|
||||
* Copyright (c) 2006-2015 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 DHCPCOMMON_H
|
||||
#define DHCPCOMMON_H
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "common.h"
|
||||
#include "dhcpcd.h"
|
||||
|
||||
/* Max MTU - defines dhcp option length */
|
||||
#define IP_UDP_SIZE 28
|
||||
#define MTU_MAX 1500 - IP_UDP_SIZE
|
||||
#define MTU_MIN 576 + IP_UDP_SIZE
|
||||
|
||||
#define OT_REQUEST (1 << 0)
|
||||
#define OT_UINT8 (1 << 1)
|
||||
#define OT_INT8 (1 << 2)
|
||||
#define OT_UINT16 (1 << 3)
|
||||
#define OT_INT16 (1 << 4)
|
||||
#define OT_UINT32 (1 << 5)
|
||||
#define OT_INT32 (1 << 6)
|
||||
#define OT_ADDRIPV4 (1 << 7)
|
||||
#define OT_STRING (1 << 8)
|
||||
#define OT_ARRAY (1 << 9)
|
||||
#define OT_RFC3361 (1 << 10)
|
||||
#define OT_RFC1035 (1 << 11)
|
||||
#define OT_RFC3442 (1 << 12)
|
||||
#define OT_OPTIONAL (1 << 13)
|
||||
#define OT_ADDRIPV6 (1 << 14)
|
||||
#define OT_BINHEX (1 << 15)
|
||||
#define OT_FLAG (1 << 16)
|
||||
#define OT_NOREQ (1 << 17)
|
||||
#define OT_EMBED (1 << 18)
|
||||
#define OT_ENCAP (1 << 19)
|
||||
#define OT_INDEX (1 << 20)
|
||||
#define OT_OPTION (1 << 21)
|
||||
#define OT_DOMAIN (1 << 22)
|
||||
#define OT_ASCII (1 << 23)
|
||||
#define OT_RAW (1 << 24)
|
||||
#define OT_ESCSTRING (1 << 25)
|
||||
#define OT_ESCFILE (1 << 26)
|
||||
#define OT_BITFLAG (1 << 27)
|
||||
#define OT_RESERVED (1 << 28)
|
||||
|
||||
struct dhcp_opt {
|
||||
uint32_t option; /* Also used for IANA Enterpise Number */
|
||||
int type;
|
||||
size_t len;
|
||||
char *var;
|
||||
|
||||
int index; /* Index counter for many instances of the same option */
|
||||
char bitflags[8];
|
||||
|
||||
/* Embedded options.
|
||||
* The option code is irrelevant here. */
|
||||
struct dhcp_opt *embopts;
|
||||
size_t embopts_len;
|
||||
|
||||
/* Encapsulated options */
|
||||
struct dhcp_opt *encopts;
|
||||
size_t encopts_len;
|
||||
};
|
||||
|
||||
const char *dhcp_get_hostname(char *, size_t, const struct if_options *);
|
||||
struct dhcp_opt *vivso_find(uint32_t, const void *);
|
||||
|
||||
ssize_t dhcp_vendor(char *, size_t);
|
||||
|
||||
void dhcp_print_option_encoding(const struct dhcp_opt *opt, int cols);
|
||||
#define add_option_mask(var, val) \
|
||||
((var)[(val) >> 3] = (uint8_t)((var)[(val) >> 3] | 1 << ((val) & 7)))
|
||||
#define del_option_mask(var, val) \
|
||||
((var)[(val) >> 3] = (uint8_t)((var)[(val) >> 3] & ~(1 << ((val) & 7))))
|
||||
#define has_option_mask(var, val) \
|
||||
((var)[(val) >> 3] & (uint8_t)(1 << ((val) & 7)))
|
||||
int make_option_mask(const struct dhcp_opt *, size_t,
|
||||
const struct dhcp_opt *, size_t,
|
||||
uint8_t *, const char *, int);
|
||||
|
||||
size_t encode_rfc1035(const char *src, uint8_t *dst);
|
||||
ssize_t decode_rfc1035(char *, size_t, const uint8_t *, size_t);
|
||||
ssize_t print_string(char *, size_t, int, const uint8_t *, size_t);
|
||||
int dhcp_set_leasefile(char *, size_t, int, const struct interface *);
|
||||
|
||||
size_t dhcp_envoption(struct dhcpcd_ctx *,
|
||||
char **, const char *, const char *, struct dhcp_opt *,
|
||||
const uint8_t *(*dgetopt)(struct dhcpcd_ctx *,
|
||||
size_t *, unsigned int *, size_t *,
|
||||
const uint8_t *, size_t, struct dhcp_opt **),
|
||||
const uint8_t *od, size_t ol);
|
||||
void dhcp_zero_index(struct dhcp_opt *);
|
||||
size_t dhcp_read_lease_fd(int, uint8_t **);
|
||||
|
||||
#endif
|
276
external/bsd/dhcpcd/dist/crypt/dhcp.h
vendored
Normal file
276
external/bsd/dhcpcd/dist/crypt/dhcp.h
vendored
Normal file
@ -0,0 +1,276 @@
|
||||
/*
|
||||
* dhcpcd - DHCP client daemon
|
||||
* Copyright (c) 2006-2016 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 DHCP_H
|
||||
#define DHCP_H
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "arp.h"
|
||||
#include "auth.h"
|
||||
#include "dhcp-common.h"
|
||||
|
||||
/* UDP port numbers for BOOTP */
|
||||
#define BOOTPS 67
|
||||
#define BOOTPC 68
|
||||
|
||||
#define MAGIC_COOKIE 0x63825363
|
||||
#define BROADCAST_FLAG 0x8000
|
||||
|
||||
/* BOOTP message OP code */
|
||||
#define BOOTREQUEST 1
|
||||
#define BOOTREPLY 2
|
||||
|
||||
/* DHCP message type */
|
||||
#define DHCP_DISCOVER 1
|
||||
#define DHCP_OFFER 2
|
||||
#define DHCP_REQUEST 3
|
||||
#define DHCP_DECLINE 4
|
||||
#define DHCP_ACK 5
|
||||
#define DHCP_NAK 6
|
||||
#define DHCP_RELEASE 7
|
||||
#define DHCP_INFORM 8
|
||||
#define DHCP_FORCERENEW 9
|
||||
|
||||
/* Constants taken from RFC 2131. */
|
||||
#define T1 0.5
|
||||
#define T2 0.875
|
||||
#define DHCP_BASE 4
|
||||
#define DHCP_MAX 64
|
||||
#define DHCP_RAND_MIN -1
|
||||
#define DHCP_RAND_MAX 1
|
||||
|
||||
#ifdef RFC2131_STRICT
|
||||
/* Be strictly conformant for section 4.1.1 */
|
||||
# define DHCP_MIN_DELAY 1
|
||||
# define DHCP_MAX_DELAY 10
|
||||
#else
|
||||
/* or mirror the more modern IPv6RS and DHCPv6 delays */
|
||||
# define DHCP_MIN_DELAY 0
|
||||
# define DHCP_MAX_DELAY 1
|
||||
#endif
|
||||
|
||||
/* DHCP options */
|
||||
enum DHO {
|
||||
DHO_PAD = 0,
|
||||
DHO_SUBNETMASK = 1,
|
||||
DHO_ROUTER = 3,
|
||||
DHO_DNSSERVER = 6,
|
||||
DHO_HOSTNAME = 12,
|
||||
DHO_DNSDOMAIN = 15,
|
||||
DHO_MTU = 26,
|
||||
DHO_BROADCAST = 28,
|
||||
DHO_STATICROUTE = 33,
|
||||
DHO_NISDOMAIN = 40,
|
||||
DHO_NISSERVER = 41,
|
||||
DHO_NTPSERVER = 42,
|
||||
DHO_VENDOR = 43,
|
||||
DHO_IPADDRESS = 50,
|
||||
DHO_LEASETIME = 51,
|
||||
DHO_OPTSOVERLOADED = 52,
|
||||
DHO_MESSAGETYPE = 53,
|
||||
DHO_SERVERID = 54,
|
||||
DHO_PARAMETERREQUESTLIST = 55,
|
||||
DHO_MESSAGE = 56,
|
||||
DHO_MAXMESSAGESIZE = 57,
|
||||
DHO_RENEWALTIME = 58,
|
||||
DHO_REBINDTIME = 59,
|
||||
DHO_VENDORCLASSID = 60,
|
||||
DHO_CLIENTID = 61,
|
||||
DHO_USERCLASS = 77, /* RFC 3004 */
|
||||
DHO_RAPIDCOMMIT = 80, /* RFC 4039 */
|
||||
DHO_FQDN = 81,
|
||||
DHO_AUTHENTICATION = 90, /* RFC 3118 */
|
||||
DHO_AUTOCONFIGURE = 116, /* RFC 2563 */
|
||||
DHO_DNSSEARCH = 119, /* RFC 3397 */
|
||||
DHO_CSR = 121, /* RFC 3442 */
|
||||
DHO_VIVCO = 124, /* RFC 3925 */
|
||||
DHO_VIVSO = 125, /* RFC 3925 */
|
||||
DHO_FORCERENEW_NONCE = 145, /* RFC 6704 */
|
||||
DHO_SIXRD = 212, /* RFC 5969 */
|
||||
DHO_MSCSR = 249, /* MS code for RFC 3442 */
|
||||
DHO_END = 255
|
||||
};
|
||||
|
||||
/* FQDN values - lsnybble used in flags
|
||||
* hsnybble to create order
|
||||
* and to allow 0x00 to mean disable
|
||||
*/
|
||||
enum FQDN {
|
||||
FQDN_DISABLE = 0x00,
|
||||
FQDN_NONE = 0x18,
|
||||
FQDN_PTR = 0x20,
|
||||
FQDN_BOTH = 0x31
|
||||
};
|
||||
|
||||
/* Don't import common.h as that defines __unused which causes problems
|
||||
* on some Linux systems which define it as part of a structure */
|
||||
#if __GNUC__ > 2 || defined(__INTEL_COMPILER)
|
||||
# ifndef __packed
|
||||
# define __packed __attribute__((__packed__))
|
||||
# endif
|
||||
#else
|
||||
# ifndef __packed
|
||||
# define __packed
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Sizes for BOOTP options */
|
||||
#define BOOTP_CHADDR_LEN 16
|
||||
#define BOOTP_SNAME_LEN 64
|
||||
#define BOOTP_FILE_LEN 128
|
||||
#define BOOTP_VEND_LEN 64
|
||||
|
||||
/* DHCP is basically an extension to BOOTP */
|
||||
struct bootp {
|
||||
uint8_t op; /* message type */
|
||||
uint8_t htype; /* hardware address type */
|
||||
uint8_t hlen; /* hardware address length */
|
||||
uint8_t hops; /* should be zero in client message */
|
||||
uint32_t xid; /* transaction id */
|
||||
uint16_t secs; /* elapsed time in sec. from boot */
|
||||
uint16_t flags; /* such as broadcast flag */
|
||||
uint32_t ciaddr; /* (previously allocated) client IP */
|
||||
uint32_t yiaddr; /* 'your' client IP address */
|
||||
uint32_t siaddr; /* should be zero in client's messages */
|
||||
uint32_t giaddr; /* should be zero in client's messages */
|
||||
uint8_t chaddr[BOOTP_CHADDR_LEN]; /* client's hardware address */
|
||||
uint8_t sname[BOOTP_SNAME_LEN]; /* server host name */
|
||||
uint8_t file[BOOTP_FILE_LEN]; /* boot file name */
|
||||
uint8_t vend[BOOTP_VEND_LEN]; /* vendor specific area */
|
||||
/* DHCP allows a variable length vendor area */
|
||||
} __packed;
|
||||
|
||||
struct dhcp_lease {
|
||||
struct in_addr addr;
|
||||
struct in_addr mask;
|
||||
struct in_addr brd;
|
||||
uint32_t leasetime;
|
||||
uint32_t renewaltime;
|
||||
uint32_t rebindtime;
|
||||
struct in_addr server;
|
||||
uint8_t frominfo;
|
||||
uint32_t cookie;
|
||||
};
|
||||
|
||||
enum DHS {
|
||||
DHS_INIT,
|
||||
DHS_DISCOVER,
|
||||
DHS_REQUEST,
|
||||
DHS_PROBE,
|
||||
DHS_BOUND,
|
||||
DHS_RENEW,
|
||||
DHS_REBIND,
|
||||
DHS_REBOOT,
|
||||
DHS_INFORM,
|
||||
DHS_RENEW_REQUESTED,
|
||||
DHS_RELEASE
|
||||
};
|
||||
|
||||
struct dhcp_state {
|
||||
enum DHS state;
|
||||
struct bootp *sent;
|
||||
size_t sent_len;
|
||||
struct bootp *offer;
|
||||
size_t offer_len;
|
||||
struct bootp *new;
|
||||
size_t new_len;
|
||||
struct bootp *old;
|
||||
size_t old_len;
|
||||
struct dhcp_lease lease;
|
||||
const char *reason;
|
||||
time_t interval;
|
||||
time_t nakoff;
|
||||
uint32_t xid;
|
||||
int socket;
|
||||
|
||||
int raw_fd;
|
||||
struct ipv4_addr *addr;
|
||||
uint8_t added;
|
||||
|
||||
char leasefile[sizeof(LEASEFILE) + IF_NAMESIZE + (IF_SSIDLEN * 4)];
|
||||
struct timespec started;
|
||||
unsigned char *clientid;
|
||||
struct authstate auth;
|
||||
size_t arping_index;
|
||||
};
|
||||
|
||||
#define D_STATE(ifp) \
|
||||
((struct dhcp_state *)(ifp)->if_data[IF_DATA_DHCP])
|
||||
#define D_CSTATE(ifp) \
|
||||
((const struct dhcp_state *)(ifp)->if_data[IF_DATA_DHCP])
|
||||
#define D_STATE_RUNNING(ifp) \
|
||||
(D_CSTATE((ifp)) && D_CSTATE((ifp))->new && D_CSTATE((ifp))->reason)
|
||||
|
||||
#define IS_DHCP(b) ((b)->vend[0] == 0x63 && \
|
||||
(b)->vend[1] == 0x82 && \
|
||||
(b)->vend[2] == 0x53 && \
|
||||
(b)->vend[3] == 0x63)
|
||||
|
||||
#include "dhcpcd.h"
|
||||
#include "if-options.h"
|
||||
|
||||
#ifdef INET
|
||||
char *decode_rfc3361(const uint8_t *, size_t);
|
||||
ssize_t decode_rfc3442(char *, size_t, const uint8_t *p, size_t);
|
||||
|
||||
void dhcp_printoptions(const struct dhcpcd_ctx *,
|
||||
const struct dhcp_opt *, size_t);
|
||||
uint16_t dhcp_get_mtu(const struct interface *);
|
||||
struct rt_head *dhcp_get_routes(struct interface *);
|
||||
ssize_t dhcp_env(char **, const char *, const struct bootp *, size_t,
|
||||
const struct interface *);
|
||||
|
||||
void dhcp_handleifa(int, struct ipv4_addr *);
|
||||
void dhcp_drop(struct interface *, const char *);
|
||||
void dhcp_start(struct interface *);
|
||||
void dhcp_abort(struct interface *);
|
||||
void dhcp_discover(void *);
|
||||
void dhcp_inform(struct interface *);
|
||||
void dhcp_renew(struct interface *);
|
||||
void dhcp_bind(struct interface *);
|
||||
void dhcp_reboot_newopts(struct interface *, unsigned long long);
|
||||
void dhcp_close(struct interface *);
|
||||
void dhcp_free(struct interface *);
|
||||
int dhcp_dump(struct interface *);
|
||||
#else
|
||||
#define dhcp_drop(a, b) {}
|
||||
#define dhcp_start(a) {}
|
||||
#define dhcp_abort(a) {}
|
||||
#define dhcp_renew(a) {}
|
||||
#define dhcp_reboot(a, b) (b = b)
|
||||
#define dhcp_reboot_newopts(a, b) (b = b)
|
||||
#define dhcp_close(a) {}
|
||||
#define dhcp_free(a) {}
|
||||
#define dhcp_dump(a) (-1)
|
||||
#endif
|
||||
|
||||
#endif
|
269
external/bsd/dhcpcd/dist/crypt/dhcp6.h
vendored
Normal file
269
external/bsd/dhcpcd/dist/crypt/dhcp6.h
vendored
Normal file
@ -0,0 +1,269 @@
|
||||
/*
|
||||
* dhcpcd - DHCP client daemon
|
||||
* Copyright (c) 2006-2015 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 DHCP6_H
|
||||
#define DHCP6_H
|
||||
|
||||
#include "dhcpcd.h"
|
||||
|
||||
#define IN6ADDR_LINKLOCAL_ALLDHCP_INIT \
|
||||
{{{ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02 }}}
|
||||
|
||||
/* UDP port numbers for DHCP */
|
||||
#define DHCP6_CLIENT_PORT 546
|
||||
#define DHCP6_SERVER_PORT 547
|
||||
|
||||
/* DHCP message type */
|
||||
#define DHCP6_SOLICIT 1
|
||||
#define DHCP6_ADVERTISE 2
|
||||
#define DHCP6_REQUEST 3
|
||||
#define DHCP6_CONFIRM 4
|
||||
#define DHCP6_RENEW 5
|
||||
#define DHCP6_REBIND 6
|
||||
#define DHCP6_REPLY 7
|
||||
#define DHCP6_RELEASE 8
|
||||
#define DHCP6_DECLINE 9
|
||||
#define DHCP6_RECONFIGURE 10
|
||||
#define DHCP6_INFORMATION_REQ 11
|
||||
#define DHCP6_RELAY_FLOW 12
|
||||
#define DHCP6_RELAY_REPL 13
|
||||
#define DHCP6_RECONFIGURE_REQ 18
|
||||
#define DHCP6_RECONFIGURE_REPLY 19
|
||||
|
||||
#define D6_OPTION_CLIENTID 1
|
||||
#define D6_OPTION_SERVERID 2
|
||||
#define D6_OPTION_IA_NA 3
|
||||
#define D6_OPTION_IA_TA 4
|
||||
#define D6_OPTION_ORO 6
|
||||
#define D6_OPTION_IA_ADDR 5
|
||||
#define D6_OPTION_PREFERENCE 7
|
||||
#define D6_OPTION_ELAPSED 8
|
||||
#define D6_OPTION_AUTH 11
|
||||
#define D6_OPTION_UNICAST 12
|
||||
#define D6_OPTION_STATUS_CODE 13
|
||||
#define D6_OPTION_RAPID_COMMIT 14
|
||||
#define D6_OPTION_VENDOR_CLASS 16
|
||||
#define D6_OPTION_VENDOR_OPTS 17
|
||||
#define D6_OPTION_INTERFACE_ID 18
|
||||
#define D6_OPTION_RECONF_MSG 19
|
||||
#define D6_OPTION_RECONF_ACCEPT 20
|
||||
#define D6_OPTION_SIP_SERVERS_NAME 21
|
||||
#define D6_OPTION_SIP_SERVERS_ADDRESS 22
|
||||
#define D6_OPTION_DNS_SERVERS 23
|
||||
#define D6_OPTION_DOMAIN_LIST 24
|
||||
#define D6_OPTION_IA_PD 25
|
||||
#define D6_OPTION_IAPREFIX 26
|
||||
#define D6_OPTION_NIS_SERVERS 27
|
||||
#define D6_OPTION_NISP_SERVERS 28
|
||||
#define D6_OPTION_NIS_DOMAIN_NAME 29
|
||||
#define D6_OPTION_NISP_DOMAIN_NAME 30
|
||||
#define D6_OPTION_SNTP_SERVERS 31
|
||||
#define D6_OPTION_INFO_REFRESH_TIME 32
|
||||
#define D6_OPTION_BCMS_SERVER_D 33
|
||||
#define D6_OPTION_BCMS_SERVER_A 34
|
||||
#define D6_OPTION_FQDN 39
|
||||
#define D6_OPTION_POSIX_TIMEZONE 41
|
||||
#define D6_OPTION_TZDB_TIMEZONE 42
|
||||
#define D6_OPTION_PD_EXCLUDE 67
|
||||
#define D6_OPTION_SOL_MAX_RT 82
|
||||
#define D6_OPTION_INF_MAX_RT 83
|
||||
|
||||
#define D6_FQDN_PTR 0x00
|
||||
#define D6_FQDN_BOTH 0x01
|
||||
#define D6_FQDN_NONE 0x04
|
||||
|
||||
#include "dhcp.h"
|
||||
#include "ipv6.h"
|
||||
|
||||
struct dhcp6_message {
|
||||
uint8_t type;
|
||||
uint8_t xid[3];
|
||||
/* followed by options */
|
||||
} __packed;
|
||||
|
||||
struct dhcp6_option {
|
||||
uint16_t code;
|
||||
uint16_t len;
|
||||
/* followed by data */
|
||||
} __packed;
|
||||
|
||||
#define D6_STATUS_OK 0
|
||||
#define D6_STATUS_FAIL 1
|
||||
#define D6_STATUS_NOADDR 2
|
||||
#define D6_STATUS_NOBINDING 3
|
||||
#define D6_STATUS_NOTONLINK 4
|
||||
#define D6_STATUS_USEMULTICAST 5
|
||||
|
||||
#define SOL_MAX_DELAY 1
|
||||
#define SOL_TIMEOUT 1
|
||||
#define SOL_MAX_RT 3600 /* RFC7083 */
|
||||
#define REQ_TIMEOUT 1
|
||||
#define REQ_MAX_RT 30
|
||||
#define REQ_MAX_RC 10
|
||||
#define CNF_MAX_DELAY 1
|
||||
#define CNF_TIMEOUT 1
|
||||
#define CNF_MAX_RT 4
|
||||
#define CNF_MAX_RD 10
|
||||
#define REN_TIMEOUT 10
|
||||
#define REN_MAX_RT 600
|
||||
#define REB_TIMEOUT 10
|
||||
#define REB_MAX_RT 600
|
||||
#define INF_MAX_DELAY 1
|
||||
#define INF_TIMEOUT 1
|
||||
#define INF_MAX_RT 3600 /* RFC7083 */
|
||||
#define REL_TIMEOUT 1
|
||||
#define REL_MAX_RC 5
|
||||
#define DEC_TIMEOUT 1
|
||||
#define DEC_MAX_RC 5
|
||||
#define REC_TIMEOUT 2
|
||||
#define REC_MAX_RC 8
|
||||
#define HOP_COUNT_LIMIT 32
|
||||
|
||||
/* RFC4242 3.1 */
|
||||
#define IRT_DEFAULT 86400
|
||||
#define IRT_MINIMUM 600
|
||||
|
||||
#define DHCP6_RAND_MIN -100
|
||||
#define DHCP6_RAND_MAX 100
|
||||
|
||||
enum DH6S {
|
||||
DH6S_INIT,
|
||||
DH6S_DISCOVER,
|
||||
DH6S_REQUEST,
|
||||
DH6S_BOUND,
|
||||
DH6S_RENEW,
|
||||
DH6S_REBIND,
|
||||
DH6S_CONFIRM,
|
||||
DH6S_INFORM,
|
||||
DH6S_INFORMED,
|
||||
DH6S_RENEW_REQUESTED,
|
||||
DH6S_PROBE,
|
||||
DH6S_DELEGATED,
|
||||
DH6S_RELEASE,
|
||||
DH6S_RELEASED
|
||||
};
|
||||
|
||||
struct dhcp6_state {
|
||||
enum DH6S state;
|
||||
struct timespec started;
|
||||
|
||||
/* Message retransmission timings */
|
||||
struct timespec RT;
|
||||
unsigned int IMD;
|
||||
unsigned int RTC;
|
||||
time_t IRT;
|
||||
unsigned int MRC;
|
||||
time_t MRT;
|
||||
void (*MRCcallback)(void *);
|
||||
time_t sol_max_rt;
|
||||
time_t inf_max_rt;
|
||||
|
||||
struct dhcp6_message *send;
|
||||
size_t send_len;
|
||||
struct dhcp6_message *recv;
|
||||
size_t recv_len;
|
||||
struct dhcp6_message *new;
|
||||
size_t new_len;
|
||||
struct dhcp6_message *old;
|
||||
size_t old_len;
|
||||
|
||||
uint32_t renew;
|
||||
uint32_t rebind;
|
||||
uint32_t expire;
|
||||
struct in6_addr unicast;
|
||||
struct ipv6_addrhead addrs;
|
||||
uint32_t lowpl;
|
||||
/* The +3 is for the possible .pd extension for prefix delegation */
|
||||
char leasefile[sizeof(LEASEFILE6) + IF_NAMESIZE + (IF_SSIDLEN * 4) +3];
|
||||
const char *reason;
|
||||
|
||||
struct authstate auth;
|
||||
};
|
||||
|
||||
#define D6_STATE(ifp) \
|
||||
((struct dhcp6_state *)(ifp)->if_data[IF_DATA_DHCP6])
|
||||
#define D6_CSTATE(ifp) \
|
||||
((const struct dhcp6_state *)(ifp)->if_data[IF_DATA_DHCP6])
|
||||
#define D6_STATE_RUNNING(ifp) \
|
||||
(D6_CSTATE((ifp)) && \
|
||||
D6_CSTATE((ifp))->reason && dhcp6_dadcompleted((ifp)))
|
||||
|
||||
#define D6_FIRST_OPTION(m) \
|
||||
((struct dhcp6_option *) \
|
||||
((uint8_t *)(m) + sizeof(struct dhcp6_message)))
|
||||
#define D6_NEXT_OPTION(o) \
|
||||
((struct dhcp6_option *) \
|
||||
(((uint8_t *)o) + sizeof(struct dhcp6_option) + ntohs((o)->len)))
|
||||
#define D6_OPTION_DATA(o) \
|
||||
((uint8_t *)(o) + sizeof(struct dhcp6_option))
|
||||
#define D6_CFIRST_OPTION(m) \
|
||||
((const struct dhcp6_option *) \
|
||||
((const uint8_t *)(m) + sizeof(struct dhcp6_message)))
|
||||
#define D6_CNEXT_OPTION(o) \
|
||||
((const struct dhcp6_option *) \
|
||||
(((const uint8_t *)o) + sizeof(struct dhcp6_option) + ntohs((o)->len)))
|
||||
#define D6_COPTION_DATA(o) \
|
||||
((const uint8_t *)(o) + sizeof(struct dhcp6_option))
|
||||
|
||||
#ifdef DHCP6
|
||||
void dhcp6_printoptions(const struct dhcpcd_ctx *,
|
||||
const struct dhcp_opt *, size_t);
|
||||
const struct ipv6_addr *dhcp6_iffindaddr(const struct interface *ifp,
|
||||
const struct in6_addr *addr, short flags);
|
||||
struct ipv6_addr *dhcp6_findaddr(struct dhcpcd_ctx *, const struct in6_addr *,
|
||||
short);
|
||||
size_t dhcp6_find_delegates(struct interface *);
|
||||
int dhcp6_start(struct interface *, enum DH6S);
|
||||
void dhcp6_reboot(struct interface *);
|
||||
void dhcp6_renew(struct interface *);
|
||||
ssize_t dhcp6_env(char **, const char *, const struct interface *,
|
||||
const struct dhcp6_message *, size_t);
|
||||
void dhcp6_free(struct interface *);
|
||||
void dhcp6_handleifa(int, struct ipv6_addr *);
|
||||
int dhcp6_dadcompleted(const struct interface *);
|
||||
void dhcp6_drop(struct interface *, const char *);
|
||||
void dhcp6_dropnondelegates(struct interface *ifp);
|
||||
int dhcp6_dump(struct interface *);
|
||||
#else
|
||||
#define dhcp6_printoptions(a, b, c) {}
|
||||
#define dhcp6_iffindaddr(a, b, c) (NULL)
|
||||
#define dhcp6_findaddr(a, b, c) (NULL)
|
||||
#define dhcp6_find_delegates(a) {}
|
||||
#define dhcp6_start(a, b) (0)
|
||||
#define dhcp6_reboot(a) {}
|
||||
#define dhcp6_renew(a) {}
|
||||
#define dhcp6_env(a, b, c, d, e) (0)
|
||||
#define dhcp6_free(a) {}
|
||||
#define dhcp6_handleifa(a, b) {}
|
||||
#define dhcp6_dadcompleted(a) (0)
|
||||
#define dhcp6_drop(a, b) {}
|
||||
#define dhcp6_dropnondelegates(a) {}
|
||||
#define dhcp6_dump(a) (-1)
|
||||
#endif
|
||||
|
||||
#endif
|
206
external/bsd/dhcpcd/dist/crypt/dhcpcd.h
vendored
Normal file
206
external/bsd/dhcpcd/dist/crypt/dhcpcd.h
vendored
Normal file
@ -0,0 +1,206 @@
|
||||
/*
|
||||
* dhcpcd - DHCP client daemon
|
||||
* Copyright (c) 2006-2016 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 DHCPCD_H
|
||||
#define DHCPCD_H
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include <net/if.h>
|
||||
|
||||
#include "config.h"
|
||||
#ifdef HAVE_SYS_QUEUE_H
|
||||
#include <sys/queue.h>
|
||||
#endif
|
||||
|
||||
#include "defs.h"
|
||||
#include "control.h"
|
||||
#include "if-options.h"
|
||||
|
||||
#define HWADDR_LEN 20
|
||||
#define IF_SSIDLEN 32
|
||||
#define PROFILE_LEN 64
|
||||
#define SECRET_LEN 64
|
||||
|
||||
#define IF_INACTIVE 0
|
||||
#define IF_ACTIVE 1
|
||||
#define IF_ACTIVE_USER 2
|
||||
|
||||
#define LINK_UP 1
|
||||
#define LINK_UNKNOWN 0
|
||||
#define LINK_DOWN -1
|
||||
|
||||
#define IF_DATA_IPV4 0
|
||||
#define IF_DATA_ARP 1
|
||||
#define IF_DATA_IPV4LL 2
|
||||
#define IF_DATA_DHCP 3
|
||||
#define IF_DATA_IPV6 4
|
||||
#define IF_DATA_IPV6ND 5
|
||||
#define IF_DATA_DHCP6 6
|
||||
#define IF_DATA_MAX 7
|
||||
|
||||
/* If the interface does not support carrier status (ie PPP),
|
||||
* dhcpcd can poll it for the relevant flags periodically */
|
||||
#define IF_POLL_UP 100 /* milliseconds */
|
||||
|
||||
#ifdef __QNX__
|
||||
/* QNX carries defines for, but does not actually support PF_LINK */
|
||||
#undef IFLR_ACTIVE
|
||||
#endif
|
||||
|
||||
struct interface {
|
||||
struct dhcpcd_ctx *ctx;
|
||||
TAILQ_ENTRY(interface) next;
|
||||
char name[IF_NAMESIZE];
|
||||
unsigned int index;
|
||||
unsigned int active;
|
||||
unsigned int flags;
|
||||
sa_family_t family;
|
||||
unsigned char hwaddr[HWADDR_LEN];
|
||||
uint8_t hwlen;
|
||||
unsigned int metric;
|
||||
int carrier;
|
||||
int wireless;
|
||||
uint8_t ssid[IF_SSIDLEN + 1]; /* NULL terminated */
|
||||
unsigned int ssid_len;
|
||||
|
||||
char profile[PROFILE_LEN];
|
||||
struct if_options *options;
|
||||
void *if_data[IF_DATA_MAX];
|
||||
};
|
||||
TAILQ_HEAD(if_head, interface);
|
||||
|
||||
struct dhcpcd_ctx {
|
||||
char pidfile[sizeof(PIDFILE) + IF_NAMESIZE + 1];
|
||||
const char *cffile;
|
||||
unsigned long long options;
|
||||
char *logfile;
|
||||
int log_fd;
|
||||
int argc;
|
||||
char **argv;
|
||||
int ifac; /* allowed interfaces */
|
||||
char **ifav; /* allowed interfaces */
|
||||
int ifdc; /* denied interfaces */
|
||||
char **ifdv; /* denied interfaces */
|
||||
int ifc; /* listed interfaces */
|
||||
char **ifv; /* listed interfaces */
|
||||
int ifcc; /* configured interfaces */
|
||||
char **ifcv; /* configured interfaces */
|
||||
unsigned char *duid;
|
||||
size_t duid_len;
|
||||
struct if_head *ifaces;
|
||||
|
||||
int pf_inet_fd;
|
||||
#ifdef IFLR_ACTIVE
|
||||
int pf_link_fd;
|
||||
#endif
|
||||
void *priv;
|
||||
int link_fd;
|
||||
int seq; /* route message sequence no */
|
||||
int sseq; /* successful seq no sent */
|
||||
struct iovec iov[1]; /* generic iovec buffer */
|
||||
|
||||
#ifdef USE_SIGNALS
|
||||
sigset_t sigset;
|
||||
#endif
|
||||
struct eloop *eloop;
|
||||
|
||||
int control_fd;
|
||||
int control_unpriv_fd;
|
||||
struct fd_list_head control_fds;
|
||||
char control_sock[sizeof(CONTROLSOCKET) + IF_NAMESIZE];
|
||||
gid_t control_group;
|
||||
|
||||
/* DHCP Enterprise options, RFC3925 */
|
||||
struct dhcp_opt *vivso;
|
||||
size_t vivso_len;
|
||||
|
||||
char *randomstate; /* original state */
|
||||
|
||||
/* Used to track the last routing message,
|
||||
* so we can ignore messages the parent process sent
|
||||
* but the child receives when forking.
|
||||
* getppid(2) is unreliable because we detach. */
|
||||
pid_t ppid; /* parent pid */
|
||||
int pseq; /* last seq in parent */
|
||||
|
||||
#ifdef INET
|
||||
struct dhcp_opt *dhcp_opts;
|
||||
size_t dhcp_opts_len;
|
||||
struct rt_head *ipv4_routes;
|
||||
struct rt_head *ipv4_kroutes;
|
||||
|
||||
int udp_fd;
|
||||
|
||||
/* Our aggregate option buffer.
|
||||
* We ONLY use this when options are split, which for most purposes is
|
||||
* practically never. See RFC3396 for details. */
|
||||
uint8_t *opt_buffer;
|
||||
size_t opt_buffer_len;
|
||||
#endif
|
||||
#ifdef INET6
|
||||
uint8_t *secret;
|
||||
size_t secret_len;
|
||||
|
||||
struct dhcp_opt *nd_opts;
|
||||
size_t nd_opts_len;
|
||||
struct dhcp_opt *dhcp6_opts;
|
||||
size_t dhcp6_opts_len;
|
||||
struct ipv6_ctx *ipv6;
|
||||
#ifndef __linux__
|
||||
int ra_global;
|
||||
#endif
|
||||
#endif /* INET6 */
|
||||
|
||||
#ifdef PLUGIN_DEV
|
||||
char *dev_load;
|
||||
int dev_fd;
|
||||
struct dev *dev;
|
||||
void *dev_handle;
|
||||
#endif
|
||||
};
|
||||
|
||||
#ifdef USE_SIGNALS
|
||||
extern const int dhcpcd_signals[];
|
||||
extern const size_t dhcpcd_signals_len;
|
||||
#endif
|
||||
|
||||
int dhcpcd_ifafwaiting(const struct interface *);
|
||||
int dhcpcd_afwaiting(const struct dhcpcd_ctx *);
|
||||
pid_t dhcpcd_daemonise(struct dhcpcd_ctx *);
|
||||
|
||||
int dhcpcd_handleargs(struct dhcpcd_ctx *, struct fd_list *, int, char **);
|
||||
void dhcpcd_handlecarrier(struct dhcpcd_ctx *, int, unsigned int, const char *);
|
||||
int dhcpcd_handleinterface(void *, int, const char *);
|
||||
void dhcpcd_handlehwaddr(struct dhcpcd_ctx *, const char *,
|
||||
const void *, uint8_t);
|
||||
void dhcpcd_dropinterface(struct interface *, const char *);
|
||||
int dhcpcd_selectprofile(struct interface *, const char *);
|
||||
|
||||
void dhcpcd_startinterface(void *);
|
||||
void dhcpcd_activateinterface(struct interface *, unsigned long long);
|
||||
|
||||
#endif
|
229
external/bsd/dhcpcd/dist/crypt/if-options.h
vendored
Normal file
229
external/bsd/dhcpcd/dist/crypt/if-options.h
vendored
Normal file
@ -0,0 +1,229 @@
|
||||
/*
|
||||
* dhcpcd - DHCP client daemon
|
||||
* Copyright (c) 2006-2016 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 IF_OPTIONS_H
|
||||
#define IF_OPTIONS_H
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/socket.h>
|
||||
#include <net/if.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include <getopt.h>
|
||||
#include <limits.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "auth.h"
|
||||
|
||||
/* Don't set any optional arguments here so we retain POSIX
|
||||
* compatibility with getopt */
|
||||
#define IF_OPTS "146bc:de:f:gh:i:j:kl:m:no:pqr:s:t:u:v:wxy:z:" \
|
||||
"ABC:DEF:GHI:JKLMNO:PQ:S:TUVW:X:Z:"
|
||||
#define NOERR_IF_OPTS ":" IF_OPTS
|
||||
|
||||
#define DEFAULT_TIMEOUT 30
|
||||
#define DEFAULT_REBOOT 5
|
||||
|
||||
#ifndef HOSTNAME_MAX_LEN
|
||||
#define HOSTNAME_MAX_LEN 250 /* 255 - 3 (FQDN) - 2 (DNS enc) */
|
||||
#endif
|
||||
#define VENDORCLASSID_MAX_LEN 255
|
||||
#define CLIENTID_MAX_LEN 48
|
||||
#define USERCLASS_MAX_LEN 255
|
||||
#define VENDOR_MAX_LEN 255
|
||||
|
||||
#define DHCPCD_ARP (1ULL << 0)
|
||||
#define DHCPCD_RELEASE (1ULL << 1)
|
||||
#define DHCPCD_DOMAIN (1ULL << 2)
|
||||
#define DHCPCD_GATEWAY (1ULL << 3)
|
||||
#define DHCPCD_STATIC (1ULL << 4)
|
||||
#define DHCPCD_DEBUG (1ULL << 5)
|
||||
#define DHCPCD_LASTLEASE (1ULL << 7)
|
||||
#define DHCPCD_INFORM (1ULL << 8)
|
||||
#define DHCPCD_REQUEST (1ULL << 9)
|
||||
#define DHCPCD_IPV4LL (1ULL << 10)
|
||||
#define DHCPCD_DUID (1ULL << 11)
|
||||
#define DHCPCD_PERSISTENT (1ULL << 12)
|
||||
#define DHCPCD_DAEMONISE (1ULL << 14)
|
||||
#define DHCPCD_DAEMONISED (1ULL << 15)
|
||||
#define DHCPCD_TEST (1ULL << 16)
|
||||
#define DHCPCD_MASTER (1ULL << 17)
|
||||
#define DHCPCD_HOSTNAME (1ULL << 18)
|
||||
#define DHCPCD_CLIENTID (1ULL << 19)
|
||||
#define DHCPCD_LINK (1ULL << 20)
|
||||
#define DHCPCD_QUIET (1ULL << 21)
|
||||
#define DHCPCD_BACKGROUND (1ULL << 22)
|
||||
#define DHCPCD_VENDORRAW (1ULL << 23)
|
||||
#define DHCPCD_NOWAITIP (1ULL << 24) /* To force daemonise */
|
||||
#define DHCPCD_WAITIP (1ULL << 25)
|
||||
#define DHCPCD_SLAACPRIVATE (1ULL << 26)
|
||||
#define DHCPCD_CSR_WARNED (1ULL << 27)
|
||||
#define DHCPCD_XID_HWADDR (1ULL << 28)
|
||||
#define DHCPCD_BROADCAST (1ULL << 29)
|
||||
#define DHCPCD_DUMPLEASE (1ULL << 30)
|
||||
#define DHCPCD_IPV6RS (1ULL << 31)
|
||||
#define DHCPCD_IPV6RA_REQRDNSS (1ULL << 32)
|
||||
#define DHCPCD_IPV6RA_OWN (1ULL << 33)
|
||||
#define DHCPCD_IPV6RA_OWN_DEFAULT (1ULL << 34)
|
||||
#define DHCPCD_IPV4 (1ULL << 35)
|
||||
#define DHCPCD_FORKED (1ULL << 36)
|
||||
#define DHCPCD_IPV6 (1ULL << 37)
|
||||
#define DHCPCD_STARTED (1ULL << 38)
|
||||
#define DHCPCD_NOALIAS (1ULL << 39)
|
||||
#define DHCPCD_IA_FORCED (1ULL << 40)
|
||||
#define DHCPCD_STOPPING (1ULL << 41)
|
||||
#define DHCPCD_DEPARTED (1ULL << 42)
|
||||
#define DHCPCD_HOSTNAME_SHORT (1ULL << 43)
|
||||
#define DHCPCD_EXITING (1ULL << 44)
|
||||
#define DHCPCD_WAITIP4 (1ULL << 45)
|
||||
#define DHCPCD_WAITIP6 (1ULL << 46)
|
||||
#define DHCPCD_DEV (1ULL << 47)
|
||||
#define DHCPCD_IAID (1ULL << 48)
|
||||
#define DHCPCD_DHCP (1ULL << 49)
|
||||
#define DHCPCD_DHCP6 (1ULL << 50)
|
||||
#define DHCPCD_IF_UP (1ULL << 51)
|
||||
#define DHCPCD_INFORM6 (1ULL << 52)
|
||||
#define DHCPCD_RTM_PPID (1ULL << 53)
|
||||
#define DHCPCD_IPV6RA_AUTOCONF (1ULL << 54)
|
||||
#define DHCPCD_ROUTER_HOST_ROUTE_WARNED (1ULL << 55)
|
||||
#define DHCPCD_LASTLEASE_EXTEND (1ULL << 56)
|
||||
#define DHCPCD_BOOTP (1ULL << 57)
|
||||
#define DHCPCD_INITIAL_DELAY (1ULL << 58)
|
||||
#define DHCPCD_PRINT_PIDFILE (1ULL << 59)
|
||||
#define DHCPCD_ONESHOT (1ULL << 60)
|
||||
#define DHCPCD_INACTIVE (1ULL << 61)
|
||||
|
||||
#define DHCPCD_NODROP (DHCPCD_EXITING | DHCPCD_PERSISTENT)
|
||||
|
||||
#define DHCPCD_WAITOPTS (DHCPCD_WAITIP | DHCPCD_WAITIP4 | DHCPCD_WAITIP6)
|
||||
|
||||
#define DHCPCD_WARNINGS (DHCPCD_CSR_WARNED | \
|
||||
DHCPCD_ROUTER_HOST_ROUTE_WARNED)
|
||||
|
||||
extern const struct option cf_options[];
|
||||
|
||||
struct if_sla {
|
||||
char ifname[IF_NAMESIZE];
|
||||
uint32_t sla;
|
||||
uint8_t prefix_len;
|
||||
uint64_t suffix;
|
||||
int8_t sla_set;
|
||||
};
|
||||
|
||||
struct if_ia {
|
||||
uint8_t iaid[4];
|
||||
#ifdef INET6
|
||||
uint16_t ia_type;
|
||||
uint8_t iaid_set;
|
||||
struct in6_addr addr;
|
||||
uint8_t prefix_len;
|
||||
uint32_t sla_max;
|
||||
size_t sla_len;
|
||||
struct if_sla *sla;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct vivco {
|
||||
size_t len;
|
||||
uint8_t *data;
|
||||
};
|
||||
|
||||
struct if_options {
|
||||
time_t mtime;
|
||||
uint8_t iaid[4];
|
||||
int metric;
|
||||
uint8_t requestmask[256 / NBBY];
|
||||
uint8_t requiremask[256 / NBBY];
|
||||
uint8_t nomask[256 / NBBY];
|
||||
uint8_t rejectmask[256 / NBBY];
|
||||
uint8_t dstmask[256 / NBBY];
|
||||
uint8_t requestmasknd[(UINT16_MAX + 1) / NBBY];
|
||||
uint8_t requiremasknd[(UINT16_MAX + 1) / NBBY];
|
||||
uint8_t nomasknd[(UINT16_MAX + 1) / NBBY];
|
||||
uint8_t rejectmasknd[(UINT16_MAX + 1) / NBBY];
|
||||
uint8_t requestmask6[(UINT16_MAX + 1) / NBBY];
|
||||
uint8_t requiremask6[(UINT16_MAX + 1) / NBBY];
|
||||
uint8_t nomask6[(UINT16_MAX + 1) / NBBY];
|
||||
uint8_t rejectmask6[(UINT16_MAX + 1) / NBBY];
|
||||
uint32_t leasetime;
|
||||
time_t timeout;
|
||||
time_t reboot;
|
||||
unsigned long long options;
|
||||
|
||||
struct in_addr req_addr;
|
||||
struct in_addr req_mask;
|
||||
struct rt_head *routes;
|
||||
struct in6_addr req_addr6;
|
||||
uint8_t req_prefix_len;
|
||||
unsigned int mtu;
|
||||
char **config;
|
||||
|
||||
char **environ;
|
||||
char *script;
|
||||
|
||||
char hostname[HOSTNAME_MAX_LEN + 1]; /* We don't store the length */
|
||||
uint8_t fqdn;
|
||||
uint8_t vendorclassid[VENDORCLASSID_MAX_LEN + 2];
|
||||
uint8_t clientid[CLIENTID_MAX_LEN + 2];
|
||||
uint8_t userclass[USERCLASS_MAX_LEN + 2];
|
||||
uint8_t vendor[VENDOR_MAX_LEN + 2];
|
||||
|
||||
size_t blacklist_len;
|
||||
in_addr_t *blacklist;
|
||||
size_t whitelist_len;
|
||||
in_addr_t *whitelist;
|
||||
size_t arping_len;
|
||||
in_addr_t *arping;
|
||||
char *fallback;
|
||||
|
||||
struct if_ia *ia;
|
||||
size_t ia_len;
|
||||
|
||||
struct dhcp_opt *dhcp_override;
|
||||
size_t dhcp_override_len;
|
||||
struct dhcp_opt *nd_override;
|
||||
size_t nd_override_len;
|
||||
struct dhcp_opt *dhcp6_override;
|
||||
size_t dhcp6_override_len;
|
||||
uint32_t vivco_en;
|
||||
struct vivco *vivco;
|
||||
size_t vivco_len;
|
||||
struct dhcp_opt *vivso_override;
|
||||
size_t vivso_override_len;
|
||||
|
||||
struct auth auth;
|
||||
};
|
||||
|
||||
struct if_options *default_config(struct dhcpcd_ctx *);
|
||||
struct if_options *read_config(struct dhcpcd_ctx *,
|
||||
const char *, const char *, const char *);
|
||||
int add_options(struct dhcpcd_ctx *, const char *,
|
||||
struct if_options *, int, char **);
|
||||
void free_dhcp_opt_embenc(struct dhcp_opt *);
|
||||
void free_options(struct if_options *);
|
||||
|
||||
#endif
|
218
external/bsd/dhcpcd/dist/crypt/if.h
vendored
Normal file
218
external/bsd/dhcpcd/dist/crypt/if.h
vendored
Normal file
@ -0,0 +1,218 @@
|
||||
/*
|
||||
* dhcpcd - DHCP client daemon
|
||||
* Copyright (c) 2006-2015 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 INTERFACE_H
|
||||
#define INTERFACE_H
|
||||
|
||||
#include <net/if.h>
|
||||
#include <net/route.h> /* for RTM_ADD et all */
|
||||
#include <netinet/in.h>
|
||||
#ifdef BSD
|
||||
#include <netinet/in_var.h> /* for IN_IFF_TENTATIVE et all */
|
||||
#endif
|
||||
|
||||
/* Some systems have route metrics.
|
||||
* OpenBSD route priority is not this. */
|
||||
#ifndef HAVE_ROUTE_METRIC
|
||||
# if defined(__linux__)
|
||||
# define HAVE_ROUTE_METRIC 1
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(__OpenBSD) || defined (__sun)
|
||||
# define ROUTE_PER_GATEWAY
|
||||
/* XXX dhcpcd doesn't really support this yet.
|
||||
* But that's generally OK if only dhcpcd is managing routes. */
|
||||
#endif
|
||||
|
||||
/* Some systems have in-built IPv4 DAD.
|
||||
* However, we need them to do DAD at carrier up as well. */
|
||||
#ifdef IN_IFF_TENTATIVE
|
||||
# ifdef __NetBSD__
|
||||
# define NOCARRIER_PRESERVE_IP
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Systems which handle 1 address per alias.
|
||||
* Currenly this is just Solaris.
|
||||
* While Linux can do aliased addresses, it is only useful for their
|
||||
* legacy ifconfig(8) tool which cannot display >1 IPv4 address
|
||||
* (it can display many IPv6 addresses which makes the limitation odd).
|
||||
* Linux has ip(8) which is a more feature rich tool, without the above
|
||||
* restriction.
|
||||
*/
|
||||
#ifndef ALIAS_ADDR
|
||||
# ifdef __sun
|
||||
# define ALIAS_ADDR
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#include "config.h"
|
||||
#include "dhcpcd.h"
|
||||
#include "ipv4.h"
|
||||
#include "ipv6.h"
|
||||
|
||||
#define EUI64_ADDR_LEN 8
|
||||
#define INFINIBAND_ADDR_LEN 20
|
||||
|
||||
/* Linux 2.4 doesn't define this */
|
||||
#ifndef ARPHRD_IEEE1394
|
||||
# define ARPHRD_IEEE1394 24
|
||||
#endif
|
||||
|
||||
/* The BSD's don't define this yet */
|
||||
#ifndef ARPHRD_INFINIBAND
|
||||
# define ARPHRD_INFINIBAND 32
|
||||
#endif
|
||||
|
||||
/* Work out if we have a private address or not
|
||||
* 10/8
|
||||
* 172.16/12
|
||||
* 192.168/16
|
||||
*/
|
||||
#ifndef IN_PRIVATE
|
||||
# define IN_PRIVATE(addr) (((addr & IN_CLASSA_NET) == 0x0a000000) || \
|
||||
((addr & 0xfff00000) == 0xac100000) || \
|
||||
((addr & IN_CLASSB_NET) == 0xc0a80000))
|
||||
#endif
|
||||
|
||||
#define RAW_EOF 1 << 0
|
||||
#define RAW_PARTIALCSUM 2 << 0
|
||||
|
||||
#ifdef __sun
|
||||
/* Solaris stupidly defines this for compat with BSD
|
||||
* but then ignores it. */
|
||||
#undef RTF_CLONING
|
||||
|
||||
/* Solaris getifaddrs is very un-suitable for dhcpcd.
|
||||
* See if-sun.c for details why. */
|
||||
struct ifaddrs;
|
||||
int if_getifaddrs(struct ifaddrs **);
|
||||
#define getifaddrs if_getifaddrs
|
||||
#endif
|
||||
|
||||
int if_setflag(struct interface *ifp, short flag);
|
||||
#define if_up(ifp) if_setflag((ifp), (IFF_UP | IFF_RUNNING))
|
||||
struct if_head *if_discover(struct dhcpcd_ctx *, int, char * const *);
|
||||
struct interface *if_find(struct if_head *, const char *);
|
||||
struct interface *if_findindex(struct if_head *, unsigned int);
|
||||
void if_sortinterfaces(struct dhcpcd_ctx *);
|
||||
void if_free(struct interface *);
|
||||
int if_domtu(const struct interface *, short int);
|
||||
#define if_getmtu(ifp) if_domtu((ifp), 0)
|
||||
#define if_setmtu(ifp, mtu) if_domtu((ifp), (mtu))
|
||||
int if_carrier(struct interface *);
|
||||
|
||||
/*
|
||||
* Helper to decode an interface name of bge0:1 to
|
||||
* devname = bge0, drvname = bge0, ppa = 0, lun = 1.
|
||||
* If ppa or lun are invalid they are set to -1.
|
||||
*/
|
||||
struct if_spec {
|
||||
char ifname[IF_NAMESIZE];
|
||||
char devname[IF_NAMESIZE];
|
||||
char drvname[IF_NAMESIZE];
|
||||
int ppa;
|
||||
int lun;
|
||||
};
|
||||
int if_nametospec(const char *, struct if_spec *);
|
||||
|
||||
/* The below functions are provided by if-KERNEL.c */
|
||||
int if_conf(struct interface *);
|
||||
int if_init(struct interface *);
|
||||
int if_getssid(struct interface *);
|
||||
int if_vimaster(const struct dhcpcd_ctx *ctx, const char *);
|
||||
int if_opensockets(struct dhcpcd_ctx *);
|
||||
int if_opensockets_os(struct dhcpcd_ctx *);
|
||||
void if_closesockets(struct dhcpcd_ctx *);
|
||||
void if_closesockets_os(struct dhcpcd_ctx *);
|
||||
int if_handlelink(struct dhcpcd_ctx *);
|
||||
|
||||
/* dhcpcd uses the same routing flags as BSD.
|
||||
* If the platform doesn't use these flags,
|
||||
* map them in the platform interace file. */
|
||||
#ifndef RTM_ADD
|
||||
#define RTM_ADD 0x1 /* Add Route */
|
||||
#define RTM_DELETE 0x2 /* Delete Route */
|
||||
#define RTM_CHANGE 0x3 /* Change Metrics or flags */
|
||||
#define RTM_GET 0x4 /* Report Metrics */
|
||||
#endif
|
||||
|
||||
/* Define SOCK_CLOEXEC and SOCK_NONBLOCK for systems that lack it.
|
||||
* xsocket() in if.c will map them to fctnl FD_CLOEXEC and O_NONBLOCK. */
|
||||
#ifdef SOCK_CLOEXEC
|
||||
# define HAVE_SOCK_CLOEXEC
|
||||
#else
|
||||
# define SOCK_CLOEXEC 0x10000000
|
||||
#endif
|
||||
#ifdef SOCK_NONBLOCK
|
||||
# define HAVE_SOCK_NONBLOCK
|
||||
#else
|
||||
# define SOCK_NONBLOCK 0x20000000
|
||||
#endif
|
||||
|
||||
#ifdef INET
|
||||
extern const char *if_pfname;
|
||||
int if_openraw(struct interface *, uint16_t);
|
||||
ssize_t if_sendraw(const struct interface *, int, uint16_t,
|
||||
const void *, size_t);
|
||||
ssize_t if_readraw(struct interface *, int, void *, size_t, int *);
|
||||
void if_closeraw(struct interface *, int);
|
||||
|
||||
int if_address(unsigned char, const struct ipv4_addr *);
|
||||
int if_addrflags(const struct interface *, const struct in_addr *,
|
||||
const char *);
|
||||
|
||||
int if_route(unsigned char, const struct rt *rt);
|
||||
int if_initrt(struct dhcpcd_ctx *);
|
||||
#endif
|
||||
|
||||
#ifdef INET6
|
||||
int if_checkipv6(struct dhcpcd_ctx *ctx, const struct interface *, int);
|
||||
#ifdef IPV6_MANAGETEMPADDR
|
||||
int ip6_use_tempaddr(const char *ifname);
|
||||
int ip6_temp_preferred_lifetime(const char *ifname);
|
||||
int ip6_temp_valid_lifetime(const char *ifname);
|
||||
#else
|
||||
#define ip6_use_tempaddr(a) (0)
|
||||
#endif
|
||||
|
||||
int if_address6(unsigned char, const struct ipv6_addr *);
|
||||
int if_addrflags6(const struct interface *, const struct in6_addr *,
|
||||
const char *);
|
||||
int if_getlifetime6(struct ipv6_addr *);
|
||||
|
||||
int if_route6(unsigned char, const struct rt6 *rt);
|
||||
int if_initrt6(struct dhcpcd_ctx *);
|
||||
#else
|
||||
#define if_checkipv6(a, b, c) (-1)
|
||||
#endif
|
||||
|
||||
int if_machinearch(char *, size_t);
|
||||
int xsocket(int, int, int);
|
||||
#endif
|
173
external/bsd/dhcpcd/dist/crypt/ipv4.h
vendored
Normal file
173
external/bsd/dhcpcd/dist/crypt/ipv4.h
vendored
Normal file
@ -0,0 +1,173 @@
|
||||
/*
|
||||
* dhcpcd - DHCP client daemon
|
||||
* Copyright (c) 2006-2016 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 IPV4_H
|
||||
#define IPV4_H
|
||||
|
||||
#include "dhcpcd.h"
|
||||
|
||||
/* Prefer our macro */
|
||||
#ifdef HTONL
|
||||
#undef HTONL
|
||||
#endif
|
||||
|
||||
#ifndef BYTE_ORDER
|
||||
#define BIG_ENDIAN 1234
|
||||
#define LITTLE_ENDIAN 4321
|
||||
#if defined(_BIG_ENDIAN)
|
||||
#define BYTE_ORDER BIG_ENDIAN
|
||||
#elif defined(_LITTLE_ENDIAN)
|
||||
#define BYTE_ORDER LITTLE_ENDIAN
|
||||
#else
|
||||
#error Endian unknown
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if BYTE_ORDER == BIG_ENDIAN
|
||||
#define HTONL(A) (A)
|
||||
#elif BYTE_ORDER == LITTLE_ENDIAN
|
||||
#define HTONL(A) \
|
||||
((((uint32_t)(A) & 0xff000000) >> 24) | \
|
||||
(((uint32_t)(A) & 0x00ff0000) >> 8) | \
|
||||
(((uint32_t)(A) & 0x0000ff00) << 8) | \
|
||||
(((uint32_t)(A) & 0x000000ff) << 24))
|
||||
#endif /* BYTE_ORDER */
|
||||
|
||||
#ifdef __sun
|
||||
/* Solaris lacks these defines.
|
||||
* While it supports DaD, to seems to only expose IFF_DUPLICATE
|
||||
* so we have no way of knowing if it's tentative or not.
|
||||
* I don't even know if Solaris has any special treatment for tentative. */
|
||||
# define IN_IFF_TENTATIVE 0
|
||||
# define IN_IFF_DUPLICATED 0x02
|
||||
# define IN_IFF_DETACHED 0
|
||||
#endif
|
||||
|
||||
#ifdef IN_IFF_TENTATIVE
|
||||
#define IN_IFF_NOTUSEABLE \
|
||||
(IN_IFF_TENTATIVE | IN_IFF_DUPLICATED | IN_IFF_DETACHED)
|
||||
#endif
|
||||
|
||||
struct rt {
|
||||
TAILQ_ENTRY(rt) next;
|
||||
struct in_addr dest;
|
||||
struct in_addr mask;
|
||||
struct in_addr gate;
|
||||
const struct interface *iface;
|
||||
#ifdef HAVE_ROUTE_METRIC
|
||||
unsigned int metric;
|
||||
#endif
|
||||
unsigned int mtu;
|
||||
struct in_addr src;
|
||||
unsigned int flags;
|
||||
unsigned int state;
|
||||
};
|
||||
TAILQ_HEAD(rt_head, rt);
|
||||
|
||||
struct ipv4_addr {
|
||||
TAILQ_ENTRY(ipv4_addr) next;
|
||||
struct in_addr addr;
|
||||
struct in_addr mask;
|
||||
struct in_addr brd;
|
||||
struct interface *iface;
|
||||
int addr_flags;
|
||||
char saddr[INET_ADDRSTRLEN + 3];
|
||||
#ifdef ALIAS_ADDR
|
||||
char alias[IF_NAMESIZE];
|
||||
#endif
|
||||
};
|
||||
TAILQ_HEAD(ipv4_addrhead, ipv4_addr);
|
||||
|
||||
#define IPV4_ADDR_EQ(a1, a2) ((a1) && (a1)->addr.s_addr == (a2)->addr.s_addr)
|
||||
#define IPV4_MASK1_EQ(a1, a2) ((a1) && (a1)->mask.s_addr == (a2)->mask.s_addr)
|
||||
#define IPV4_MASK_EQ(a1, a2) (IPV4_ADDR_EQ(a1, a2) && IPV4_MASK1_EQ(a1, a2))
|
||||
#define IPV4_BRD1_EQ(a1, a2) ((a1) && (a1)->brd.s_addr == (a2)->brd.s_addr)
|
||||
#define IPV4_BRD_EQ(a1, a2) (IPV4_MASK_EQ(a1, a2) && IPV4_BRD1_EQ(a1, a2))
|
||||
|
||||
struct ipv4_state {
|
||||
struct ipv4_addrhead addrs;
|
||||
struct rt_head routes;
|
||||
|
||||
#ifdef BSD
|
||||
/* Buffer for BPF */
|
||||
size_t buffer_size, buffer_len, buffer_pos;
|
||||
char *buffer;
|
||||
#endif
|
||||
};
|
||||
|
||||
#define IPV4_STATE(ifp) \
|
||||
((struct ipv4_state *)(ifp)->if_data[IF_DATA_IPV4])
|
||||
#define IPV4_CSTATE(ifp) \
|
||||
((const struct ipv4_state *)(ifp)->if_data[IF_DATA_IPV4])
|
||||
|
||||
#ifdef INET
|
||||
struct ipv4_state *ipv4_getstate(struct interface *);
|
||||
int ipv4_init(struct dhcpcd_ctx *);
|
||||
int ipv4_ifcmp(const struct interface *, const struct interface *);
|
||||
uint8_t inet_ntocidr(struct in_addr);
|
||||
int inet_cidrtoaddr(int, struct in_addr *);
|
||||
uint32_t ipv4_getnetmask(uint32_t);
|
||||
int ipv4_hasaddr(const struct interface *);
|
||||
|
||||
#define STATE_ADDED 0x01
|
||||
#define STATE_FAKE 0x02
|
||||
|
||||
void ipv4_buildroutes(struct dhcpcd_ctx *);
|
||||
int ipv4_deladdr(struct ipv4_addr *, int);
|
||||
int ipv4_preferanother(struct interface *);
|
||||
struct ipv4_addr *ipv4_addaddr(struct interface *,
|
||||
const struct in_addr *, const struct in_addr *, const struct in_addr *);
|
||||
void ipv4_applyaddr(void *);
|
||||
int ipv4_handlert(struct dhcpcd_ctx *, int, const struct rt *, int);
|
||||
void ipv4_freerts(struct rt_head *);
|
||||
|
||||
struct ipv4_addr *ipv4_iffindaddr(struct interface *,
|
||||
const struct in_addr *, const struct in_addr *);
|
||||
struct ipv4_addr *ipv4_iffindlladdr(struct interface *);
|
||||
struct ipv4_addr *ipv4_findaddr(struct dhcpcd_ctx *, const struct in_addr *);
|
||||
struct ipv4_addr *ipv4_findmaskaddr(struct dhcpcd_ctx *,
|
||||
const struct in_addr *);
|
||||
void ipv4_handleifa(struct dhcpcd_ctx *, int, struct if_head *, const char *,
|
||||
const struct in_addr *, const struct in_addr *, const struct in_addr *,
|
||||
int);
|
||||
|
||||
void ipv4_freeroutes(struct rt_head *);
|
||||
|
||||
void ipv4_free(struct interface *);
|
||||
void ipv4_ctxfree(struct dhcpcd_ctx *);
|
||||
#else
|
||||
#define ipv4_init(a) (-1)
|
||||
#define ipv4_sortinterfaces(a) {}
|
||||
#define ipv4_applyaddr(a) {}
|
||||
#define ipv4_freeroutes(a) {}
|
||||
#define ipv4_free(a) {}
|
||||
#define ipv4_ctxfree(a) {}
|
||||
#define ipv4_hasaddr(a) (0)
|
||||
#define ipv4_preferanother(a) {}
|
||||
#endif
|
||||
|
||||
#endif
|
352
external/bsd/dhcpcd/dist/crypt/ipv6.h
vendored
Normal file
352
external/bsd/dhcpcd/dist/crypt/ipv6.h
vendored
Normal file
@ -0,0 +1,352 @@
|
||||
/*
|
||||
* dhcpcd - DHCP client daemon
|
||||
* Copyright (c) 2006-2016 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 IPV6_H
|
||||
#define IPV6_H
|
||||
|
||||
#include <sys/uio.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "if.h"
|
||||
|
||||
#ifndef __linux__
|
||||
# if !defined(__QNX__) && !defined(__sun)
|
||||
# include <sys/endian.h>
|
||||
# endif
|
||||
# include <net/if.h>
|
||||
# ifndef __sun
|
||||
# include <netinet6/in6_var.h>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#define ALLROUTERS "ff02::2"
|
||||
|
||||
#define EUI64_GBIT 0x01
|
||||
#define EUI64_UBIT 0x02
|
||||
#define EUI64_TO_IFID(in6) do {(in6)->s6_addr[8] ^= EUI64_UBIT; } while (0)
|
||||
#define EUI64_GROUP(in6) ((in6)->s6_addr[8] & EUI64_GBIT)
|
||||
|
||||
#ifndef ND6_INFINITE_LIFETIME
|
||||
# define ND6_INFINITE_LIFETIME ((uint32_t)~0)
|
||||
#endif
|
||||
|
||||
/* RFC4941 constants */
|
||||
#define TEMP_VALID_LIFETIME 604800 /* 1 week */
|
||||
#define TEMP_PREFERRED_LIFETIME 86400 /* 1 day */
|
||||
#define REGEN_ADVANCE 5 /* seconds */
|
||||
#define MAX_DESYNC_FACTOR 600 /* 10 minutes */
|
||||
|
||||
#define TEMP_IDGEN_RETRIES 3
|
||||
#define GEN_TEMPID_RETRY_MAX 5
|
||||
|
||||
/* RFC7217 constants */
|
||||
#define IDGEN_RETRIES 3
|
||||
#define IDGEN_DELAY 1 /* second */
|
||||
|
||||
#ifndef IN6_ARE_MASKED_ADDR_EQUAL
|
||||
#define IN6_ARE_MASKED_ADDR_EQUAL(d, a, m) ( \
|
||||
(((d)->s6_addr32[0] ^ (a)->s6_addr32[0]) & (m)->s6_addr32[0]) == 0 && \
|
||||
(((d)->s6_addr32[1] ^ (a)->s6_addr32[1]) & (m)->s6_addr32[1]) == 0 && \
|
||||
(((d)->s6_addr32[2] ^ (a)->s6_addr32[2]) & (m)->s6_addr32[2]) == 0 && \
|
||||
(((d)->s6_addr32[3] ^ (a)->s6_addr32[3]) & (m)->s6_addr32[3]) == 0 )
|
||||
#endif
|
||||
|
||||
/*
|
||||
* BSD kernels don't inform userland of DAD results.
|
||||
* See the discussion here:
|
||||
* http://mail-index.netbsd.org/tech-net/2013/03/15/msg004019.html
|
||||
*/
|
||||
#ifndef __linux__
|
||||
/* We guard here to avoid breaking a compile on linux ppc-64 headers */
|
||||
# include <sys/param.h>
|
||||
#endif
|
||||
#ifdef BSD
|
||||
# define IPV6_POLLADDRFLAG
|
||||
#endif
|
||||
|
||||
/* This was fixed in NetBSD */
|
||||
#if defined(__NetBSD_Version__) && __NetBSD_Version__ >= 699002000
|
||||
# undef IPV6_POLLADDRFLAG
|
||||
#endif
|
||||
|
||||
/*
|
||||
* If dhcpcd handles RA processing instead of the kernel, the kernel needs
|
||||
* to either allow userland to set temporary addresses or mark an address
|
||||
* for the kernel to manage temporary addresses from.
|
||||
* If the kernel allows the former, a global #define is needed, otherwise
|
||||
* the address marking will be handled in the platform specific address handler.
|
||||
*
|
||||
* Some BSDs do not allow userland to set temporary addresses.
|
||||
* Linux-3.18 allows the marking of addresses from which to manage temp addrs.
|
||||
*/
|
||||
#if defined(BSD) && defined(IN6_IFF_TEMPORARY)
|
||||
#define IPV6_MANAGETEMPADDR
|
||||
#endif
|
||||
|
||||
/*
|
||||
* You could enable IPV6_MANAGETEMPADDR anyway and disable the platform
|
||||
* specific address marking to test dhcpcd's temporary address handling as well,
|
||||
* but this will not affect source address selection so is of very limited use.
|
||||
*/
|
||||
#if 0
|
||||
/* Pretend we have an old Linux kernel. */
|
||||
#undef IFA_F_MANAGETEMPADDR
|
||||
/* Enable dhcpcd handling temporary addresses. */
|
||||
#define IPV6_MANAGETEMPADDR
|
||||
#endif
|
||||
|
||||
#ifdef __linux__
|
||||
/* Match Linux defines to BSD */
|
||||
# define IN6_IFF_TEMPORARY IFA_F_TEMPORARY
|
||||
# ifdef IFA_F_OPTIMISTIC
|
||||
# define IN6_IFF_TENTATIVE (IFA_F_TENTATIVE | IFA_F_OPTIMISTIC)
|
||||
# else
|
||||
# define IN6_IFF_TENTATIVE (IFA_F_TENTATIVE | 0x04)
|
||||
# endif
|
||||
# ifdef IF_F_DADFAILED
|
||||
# define IN6_IFF_DUPLICATED IFA_F_DADFAILED
|
||||
# else
|
||||
# define IN6_IFF_DUPLICATED 0x08
|
||||
# endif
|
||||
# define IN6_IFF_DETACHED 0
|
||||
#endif
|
||||
|
||||
#ifdef __sun
|
||||
/* Solaris lacks these defines.
|
||||
* While it supports DaD, to seems to only expose IFF_DUPLICATE
|
||||
* so we have no way of knowing if it's tentative or not.
|
||||
* I don't even know if Solaris has any special treatment for tentative. */
|
||||
# define IN6_IFF_TENTATIVE 0
|
||||
# define IN6_IFF_DUPLICATED 0x04
|
||||
# define IN6_IFF_DETACHED 0
|
||||
#endif
|
||||
|
||||
#define IN6_IFF_NOTUSEABLE \
|
||||
(IN6_IFF_TENTATIVE | IN6_IFF_DUPLICATED | IN6_IFF_DETACHED)
|
||||
|
||||
TAILQ_HEAD(ipv6_addrhead, ipv6_addr);
|
||||
struct ipv6_addr {
|
||||
TAILQ_ENTRY(ipv6_addr) next;
|
||||
struct interface *iface;
|
||||
struct in6_addr prefix;
|
||||
uint8_t prefix_len;
|
||||
uint32_t prefix_vltime;
|
||||
uint32_t prefix_pltime;
|
||||
struct timespec created;
|
||||
struct timespec acquired;
|
||||
struct in6_addr addr;
|
||||
int addr_flags;
|
||||
short flags;
|
||||
char saddr[INET6_ADDRSTRLEN];
|
||||
uint8_t iaid[4];
|
||||
uint16_t ia_type;
|
||||
|
||||
struct ipv6_addr *delegating_prefix;
|
||||
struct ipv6_addrhead pd_pfxs;
|
||||
TAILQ_ENTRY(ipv6_addr) pd_next;
|
||||
|
||||
uint8_t prefix_exclude_len;
|
||||
struct in6_addr prefix_exclude;
|
||||
|
||||
void (*dadcallback)(void *);
|
||||
int dadcounter;
|
||||
uint8_t *ns;
|
||||
size_t nslen;
|
||||
int nsprobes;
|
||||
|
||||
#ifdef ALIAS_ADDR
|
||||
char alias[IF_NAMESIZE];
|
||||
#endif
|
||||
};
|
||||
|
||||
#define IPV6_AF_ONLINK 0x0001
|
||||
#define IPV6_AF_NEW 0x0002
|
||||
#define IPV6_AF_STALE 0x0004
|
||||
#define IPV6_AF_ADDED 0x0008
|
||||
#define IPV6_AF_AUTOCONF 0x0010
|
||||
#define IPV6_AF_DUPLICATED 0x0020
|
||||
#define IPV6_AF_DADCOMPLETED 0x0040
|
||||
#define IPV6_AF_DELEGATED 0x0080
|
||||
#define IPV6_AF_DELEGATEDPFX 0x0100
|
||||
#define IPV6_AF_NOREJECT 0x0200
|
||||
#define IPV6_AF_REQUEST 0x0400
|
||||
#define IPV6_AF_STATIC 0x0800
|
||||
#define IPV6_AF_DELEGATEDLOG 0x1000
|
||||
#ifdef IPV6_MANAGETEMPADDR
|
||||
#define IPV6_AF_TEMPORARY 0X2000
|
||||
#endif
|
||||
|
||||
struct rt6 {
|
||||
TAILQ_ENTRY(rt6) next;
|
||||
struct in6_addr dest;
|
||||
struct in6_addr mask;
|
||||
struct in6_addr gate;
|
||||
const struct interface *iface;
|
||||
struct in6_addr src;
|
||||
unsigned int flags;
|
||||
#ifdef HAVE_ROUTE_METRIC
|
||||
unsigned int metric;
|
||||
#endif
|
||||
unsigned int mtu;
|
||||
};
|
||||
TAILQ_HEAD(rt6_head, rt6);
|
||||
|
||||
struct ll_callback {
|
||||
TAILQ_ENTRY(ll_callback) next;
|
||||
void (*callback)(void *);
|
||||
void *arg;
|
||||
};
|
||||
TAILQ_HEAD(ll_callback_head, ll_callback);
|
||||
|
||||
struct ipv6_state {
|
||||
struct ipv6_addrhead addrs;
|
||||
struct ll_callback_head ll_callbacks;
|
||||
|
||||
#ifdef IPV6_MANAGETEMPADDR
|
||||
time_t desync_factor;
|
||||
uint8_t randomseed0[8]; /* upper 64 bits of MD5 digest */
|
||||
uint8_t randomseed1[8]; /* lower 64 bits */
|
||||
uint8_t randomid[8];
|
||||
#endif
|
||||
};
|
||||
|
||||
#define IPV6_STATE(ifp) \
|
||||
((struct ipv6_state *)(ifp)->if_data[IF_DATA_IPV6])
|
||||
#define IPV6_CSTATE(ifp) \
|
||||
((const struct ipv6_state *)(ifp)->if_data[IF_DATA_IPV6])
|
||||
#define IPV6_STATE_RUNNING(ifp) ipv6_staticdadcompleted((ifp))
|
||||
|
||||
/* dhcpcd requires CMSG_SPACE to evaluate to a compile time constant. */
|
||||
#if defined(__QNX) || \
|
||||
(defined(__NetBSD_Version__) && __NetBSD_Version__ < 600000000)
|
||||
#undef CMSG_SPACE
|
||||
#endif
|
||||
|
||||
#ifndef ALIGNBYTES
|
||||
#define ALIGNBYTES (sizeof(int) - 1)
|
||||
#endif
|
||||
#ifndef ALIGN
|
||||
#define ALIGN(p) (((unsigned int)(p) + ALIGNBYTES) & ~ALIGNBYTES)
|
||||
#endif
|
||||
#ifndef CMSG_SPACE
|
||||
#define CMSG_SPACE(len) (ALIGN(sizeof(struct cmsghdr)) + ALIGN(len))
|
||||
#endif
|
||||
|
||||
#define IP6BUFLEN (CMSG_SPACE(sizeof(struct in6_pktinfo)) + \
|
||||
CMSG_SPACE(sizeof(int)))
|
||||
|
||||
#ifdef INET6
|
||||
struct ipv6_ctx {
|
||||
unsigned char ctlbuf[IP6BUFLEN];
|
||||
struct sockaddr_in6 from;
|
||||
struct msghdr sndhdr;
|
||||
struct iovec sndiov[1];
|
||||
unsigned char sndbuf[CMSG_SPACE(sizeof(struct in6_pktinfo))];
|
||||
struct msghdr rcvhdr;
|
||||
char ntopbuf[INET6_ADDRSTRLEN];
|
||||
const char *sfrom;
|
||||
|
||||
int nd_fd;
|
||||
struct ra_head *ra_routers;
|
||||
struct rt6_head *routes;
|
||||
|
||||
struct rt6_head kroutes;
|
||||
|
||||
int dhcp_fd;
|
||||
};
|
||||
|
||||
struct ipv6_ctx *ipv6_init(struct dhcpcd_ctx *);
|
||||
int ipv6_makestableprivate(struct in6_addr *addr,
|
||||
const struct in6_addr *prefix, int prefix_len,
|
||||
const struct interface *ifp, int *dad_counter);
|
||||
int ipv6_makeaddr(struct in6_addr *, struct interface *,
|
||||
const struct in6_addr *, int);
|
||||
int ipv6_makeprefix(struct in6_addr *, const struct in6_addr *, int);
|
||||
int ipv6_mask(struct in6_addr *, int);
|
||||
uint8_t ipv6_prefixlen(const struct in6_addr *);
|
||||
int ipv6_userprefix( const struct in6_addr *, short prefix_len,
|
||||
uint64_t user_number, struct in6_addr *result, short result_len);
|
||||
void ipv6_checkaddrflags(void *);
|
||||
int ipv6_addaddr(struct ipv6_addr *, const struct timespec *);
|
||||
ssize_t ipv6_addaddrs(struct ipv6_addrhead *addrs);
|
||||
void ipv6_freedrop_addrs(struct ipv6_addrhead *, int,
|
||||
const struct interface *);
|
||||
void ipv6_handleifa(struct dhcpcd_ctx *ctx, int, struct if_head *,
|
||||
const char *, const struct in6_addr *, uint8_t, int);
|
||||
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 *);
|
||||
int ipv6_findaddrmatch(const struct ipv6_addr *, const struct in6_addr *,
|
||||
short);
|
||||
struct ipv6_addr *ipv6_findaddr(struct dhcpcd_ctx *,
|
||||
const struct in6_addr *, short);
|
||||
struct ipv6_addr *ipv6_findmaskaddr(struct dhcpcd_ctx *,
|
||||
const struct in6_addr *);
|
||||
#define ipv6_linklocal(ifp) ipv6_iffindaddr((ifp), NULL, IN6_IFF_NOTUSEABLE)
|
||||
int ipv6_addlinklocalcallback(struct interface *, void (*)(void *), void *);
|
||||
void ipv6_freeaddr(struct ipv6_addr *);
|
||||
void ipv6_freedrop(struct interface *, int);
|
||||
#define ipv6_free(ifp) ipv6_freedrop((ifp), 0)
|
||||
#define ipv6_drop(ifp) ipv6_freedrop((ifp), 2)
|
||||
|
||||
#ifdef IPV6_MANAGETEMPADDR
|
||||
void ipv6_gentempifid(struct interface *);
|
||||
void ipv6_settempstale(struct interface *);
|
||||
struct ipv6_addr *ipv6_createtempaddr(struct ipv6_addr *,
|
||||
const struct timespec *);
|
||||
struct ipv6_addr *ipv6_settemptime(struct ipv6_addr *, int);
|
||||
void ipv6_addtempaddrs(struct interface *, const struct timespec *);
|
||||
#else
|
||||
#define ipv6_gentempifid(a) {}
|
||||
#define ipv6_settempstale(a) {}
|
||||
#endif
|
||||
|
||||
int ipv6_start(struct interface *);
|
||||
int ipv6_staticdadcompleted(const struct interface *);
|
||||
int ipv6_startstatic(struct interface *);
|
||||
ssize_t ipv6_env(char **, const char *, const struct interface *);
|
||||
void ipv6_ctxfree(struct dhcpcd_ctx *);
|
||||
int ipv6_handlert(struct dhcpcd_ctx *, int cmd, const struct rt6 *);
|
||||
void ipv6_freerts(struct rt6_head *);
|
||||
void ipv6_buildroutes(struct dhcpcd_ctx *);
|
||||
|
||||
#else
|
||||
#define ipv6_init(a) (NULL)
|
||||
#define ipv6_start(a) (-1)
|
||||
#define ipv6_startstatic(a)
|
||||
#define ipv6_staticdadcompleted(a) (0)
|
||||
#define ipv6_hasaddr(a) (0)
|
||||
#define ipv6_free_ll_callbacks(a) {}
|
||||
#define ipv6_free(a) {}
|
||||
#define ipv6_drop(a) {}
|
||||
#define ipv6_ctxfree(a) {}
|
||||
#define ipv6_gentempifid(a) {}
|
||||
#endif
|
||||
|
||||
#endif
|
125
external/bsd/dhcpcd/dist/dhcpcd-definitions-small.conf
vendored
Normal file
125
external/bsd/dhcpcd/dist/dhcpcd-definitions-small.conf
vendored
Normal file
@ -0,0 +1,125 @@
|
||||
# Copyright (c) 2006-2016 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 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 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
|
@ -6,7 +6,7 @@
|
||||
|
||||
/*
|
||||
* dhcpcd - DHCP client daemon
|
||||
* Copyright (c) 2006-2015 Roy Marples <roy@marples.name>
|
||||
* Copyright (c) 2006-2016 Roy Marples <roy@marples.name>
|
||||
* All rights reserved
|
||||
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* dhcpcd - DHCP client daemon
|
||||
* Copyright (c) 2006-2015 Roy Marples <roy@marples.name>
|
||||
* Copyright (c) 2006-2016 Roy Marples <roy@marples.name>
|
||||
* All rights reserved
|
||||
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
18
external/bsd/dhcpcd/dist/genembedc
vendored
Executable file
18
external/bsd/dhcpcd/dist/genembedc
vendored
Executable file
@ -0,0 +1,18 @@
|
||||
#!/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" "};"
|
17
external/bsd/dhcpcd/dist/genembedh
vendored
Executable file
17
external/bsd/dhcpcd/dist/genembedh
vendored
Executable file
@ -0,0 +1,17 @@
|
||||
#!/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
|
Loading…
Reference in New Issue
Block a user