--- /dev/null
+# Basic .clang-format taken from FreeBSD
+---
+BasedOnStyle: WebKit
+AlignAfterOpenBracket: DontAlign
+AlignConsecutiveMacros: AcrossEmptyLines
+AlignConsecutiveAssignments: false
+AlignConsecutiveDeclarations: false
+AlignEscapedNewlines: Left
+AlignOperands: false
+AlignTrailingComments: true
+AllowAllArgumentsOnNextLine: false
+AllowAllParametersOfDeclarationOnNextLine: false
+AllowShortBlocksOnASingleLine: Never
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: InlineOnly
+AllowShortIfStatementsOnASingleLine: Never
+AllowShortLoopsOnASingleLine: false
+AlwaysBreakAfterReturnType: TopLevelDefinitions
+AlwaysBreakBeforeMultilineStrings: false
+AlwaysBreakTemplateDeclarations: MultiLine
+BinPackArguments: true
+BinPackParameters: true
+BreakBeforeBinaryOperators: None
+BreakBeforeBraces: WebKit
+BreakBeforeTernaryOperators: false
+# TODO: BreakStringLiterals can cause very strange formatting so turn it off?
+BreakStringLiterals: false
+# Prefer:
+# some_var = function(arg1,
+# arg2)
+# over:
+# some_var =
+# function(arg1, arg2)
+PenaltyBreakAssignment: 100
+# Prefer:
+# some_long_function(arg1, arg2
+# arg3)
+# over:
+# some_long_function(
+# arg1, arg2, arg3)
+PenaltyBreakBeforeFirstCallParameter: 100
+CompactNamespaces: true
+DerivePointerAlignment: false
+DisableFormat: false
+ForEachMacros:
+ - ARB_ARRFOREACH
+ - ARB_ARRFOREACH_REVWCOND
+ - ARB_ARRFOREACH_REVERSE
+ - ARB_FOREACH
+ - ARB_FOREACH_FROM
+ - ARB_FOREACH_SAFE
+ - ARB_FOREACH_REVERSE
+ - ARB_FOREACH_REVERSE_FROM
+ - ARB_FOREACH_REVERSE_SAFE
+ - BIT_FOREACH_ISCLR
+ - BIT_FOREACH_ISSET
+ - CPU_FOREACH
+ - CPU_FOREACH_ISCLR
+ - CPU_FOREACH_ISSET
+ - FOREACH_THREAD_IN_PROC
+ - FOREACH_PROC_IN_SYSTEM
+ - FOREACH_PRISON_CHILD
+ - FOREACH_PRISON_DESCENDANT
+ - FOREACH_PRISON_DESCENDANT_LOCKED
+ - FOREACH_PRISON_DESCENDANT_LOCKED_LEVEL
+ - MNT_VNODE_FOREACH_ALL
+ - MNT_VNODE_FOREACH_ACTIVE
+ - RB_FOREACH
+ - RB_FOREACH_FROM
+ - RB_FOREACH_SAFE
+ - RB_FOREACH_REVERSE
+ - RB_FOREACH_REVERSE_FROM
+ - RB_FOREACH_REVERSE_SAFE
+ - SLIST_FOREACH
+ - SLIST_FOREACH_FROM
+ - SLIST_FOREACH_FROM_SAFE
+ - SLIST_FOREACH_SAFE
+ - SLIST_FOREACH_PREVPTR
+ - SPLAY_FOREACH
+ - LIST_FOREACH
+ - LIST_FOREACH_FROM
+ - LIST_FOREACH_FROM_SAFE
+ - LIST_FOREACH_SAFE
+ - STAILQ_FOREACH
+ - STAILQ_FOREACH_FROM
+ - STAILQ_FOREACH_FROM_SAFE
+ - STAILQ_FOREACH_SAFE
+ - TAILQ_FOREACH
+ - TAILQ_FOREACH_FROM
+ - TAILQ_FOREACH_FROM_SAFE
+ - TAILQ_FOREACH_REVERSE
+ - TAILQ_FOREACH_REVERSE_FROM
+ - TAILQ_FOREACH_REVERSE_FROM_SAFE
+ - TAILQ_FOREACH_REVERSE_SAFE
+ - TAILQ_FOREACH_SAFE
+ - VM_MAP_ENTRY_FOREACH
+ - VM_PAGE_DUMP_FOREACH
+SpaceBeforeParens: ControlStatementsExceptForEachMacros
+IndentCaseLabels: false
+IndentPPDirectives: None
+Language: Cpp
+NamespaceIndentation: None
+PointerAlignment: Right
+ContinuationIndentWidth: 4
+IndentWidth: 8
+TabWidth: 8
+ColumnLimit: 80
+UseTab: Always
+SpaceAfterCStyleCast: false
+IncludeBlocks: Regroup
+IncludeCategories:
+ - Regex: '^\"opt_.*\.h\"'
+ Priority: 1
+ SortPriority: 10
+ - Regex: '^<sys/cdefs\.h>'
+ Priority: 2
+ SortPriority: 20
+ - Regex: '^<sys/types\.h>'
+ Priority: 2
+ SortPriority: 21
+ - Regex: '^<sys/param\.h>'
+ Priority: 2
+ SortPriority: 22
+ - Regex: '^<sys/systm\.h>'
+ Priority: 2
+ SortPriority: 23
+ - Regex: '^<sys.*/'
+ Priority: 2
+ SortPriority: 24
+ - Regex: '^<vm/vm\.h>'
+ Priority: 3
+ SortPriority: 30
+ - Regex: '^<vm/'
+ Priority: 3
+ SortPriority: 31
+ - Regex: '^<machine/'
+ Priority: 4
+ SortPriority: 40
+ - Regex: '^<(x86|amd64|i386|xen)/'
+ Priority: 5
+ SortPriority: 50
+ - Regex: '^<dev/'
+ Priority: 6
+ SortPriority: 60
+# Most BSD require <netinet/in.h> before this ...
+ - Regex: '^<netinet/if_ether.h>'
+ Priority: 7
+ SortPriority: 71
+ - Regex: '^<net.*/'
+ Priority: 7
+ SortPriority: 70
+ - Regex: '^<protocols/'
+ Priority: 7
+ SortPriority: 72
+ - Regex: '^<(fs|nfs(|client|server)|ufs)/'
+ Priority: 8
+ SortPriority: 80
+ - Regex: '^<[^/].*\.h'
+ Priority: 9
+ SortPriority: 90
+ - Regex: '^\".*\.h\"'
+ Priority: 10
+ SortPriority: 100
+# LLVM's header include ordering style is almost the exact opposite of ours.
+# Unfortunately, they have hard-coded their preferences into clang-format.
+# Clobbering this regular expression to avoid matching prevents non-system
+# headers from being forcibly moved to the top of the include list.
+# http://llvm.org/docs/CodingStandards.html#include-style
+IncludeIsMainRegex: 'BLAH_DONT_MATCH_ANYTHING'
+SortIncludes: true
+KeepEmptyLinesAtTheStartOfBlocks: false
+TypenameMacros:
+ - ARB_ELMTYPE
+ - ARB_HEAD
+ - ARB8_HEAD
+ - ARB16_HEAD
+ - ARB32_HEAD
+ - ARB_ENTRY
+ - ARB8_ENTRY
+ - ARB16_ENTRY
+ - ARB32_ENTRY
+ - LIST_CLASS_ENTRY
+ - LIST_CLASS_HEAD
+ - LIST_ENTRY
+ - LIST_HEAD
+ - QUEUE_TYPEOF
+ - RB_ENTRY
+ - RB_HEAD
+ - SLIST_CLASS_HEAD
+ - SLIST_CLASS_ENTRY
+ - SLIST_HEAD
+ - SLIST_ENTRY
+ - SMR_POINTER
+ - SPLAY_ENTRY
+ - SPLAY_HEAD
+ - STAILQ_CLASS_ENTRY
+ - STAILQ_CLASS_HEAD
+ - STAILQ_ENTRY
+ - STAILQ_HEAD
+ - TAILQ_CLASS_ENTRY
+ - TAILQ_CLASS_HEAD
+ - TAILQ_ENTRY
+ - TAILQ_HEAD
--- /dev/null
+# Disable DeprecatedOrUnsafeBufferHandling - our use of these is fine
+# and musl does not support the the _s variants.
+# Disable valist due to clang-tidy bug fixed in v19?
+Checks: "cert-*,-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling,-clang-analyzer-valist.Uninitialized"
+HeaderFilterRegex: ".*"
If:
PathMatch: src/dev/.*\.c
CompileFlags:
- Add: [-I.., -I../.., -I../../compat]
+ Add: [-I.., -I../.., -I../../compat, -I../../vendor]
---
If:
- PathMatch: src/.*\.c
+ PathMatch: src/.*\.(c|h)
CompileFlags:
- Add: [-I.., -I../compat]
+ Add: [-I.., -I../compat, -I../vendor]
---
CompileFlags:
Add: [-DINET, -DARP, -DARPING, -DIPV4LL, -DINET6, -DDHCP6, -DPLUGIN_DEV, -DAUTH, -DPRIVSEP]
- name: Tests
run: make tests
- openbsd:
- runs-on: ubuntu-latest
- steps:
- - name: Bootstrap OpenBSD-latest
- uses: mario-campos/emulate@v1
- with:
- operating-system: openbsd-latest
-
- - name: Install Dependencies
- run: pkg_add git
-
- - name: Build
- run: |
- git clone --depth=1 "${{ github.server_url }}/${{ github.repository }}" build
- cd build
- [ "${{ github.event.pull_request.number }}" = "" ] || (echo "fetching PR ${{ github.event.pull_request.number }}"; git fetch origin pull/${{ github.event.pull_request.number }}/head:pr-${{ github.event.pull_request.number }} && git checkout "pr-${{ github.event.pull_request.number }}")
- ./configure
- make
-
- - name: Tests
- run: |
- ulimit -n 1024
- cd build
- make tests
-
- freebsd:
- runs-on: ubuntu-latest
- steps:
- - name: Bootstrap FreeBSD-latest
- uses: mario-campos/emulate@v1
- with:
- operating-system: freebsd-latest
-
- - name: Install Dependencies
- run: pkg install -y git
-
- - name: Build
- run: |
- git clone --depth=1 "${{ github.server_url }}/${{ github.repository }}" build
- cd build
- [ "${{ github.event.pull_request.number }}" = "" ] || (echo "fetching PR ${{ github.event.pull_request.number }}"; git fetch origin pull/${{ github.event.pull_request.number }}/head:pr-${{ github.event.pull_request.number }} && git checkout "pr-${{ github.event.pull_request.number }}")
- ./configure
- make
-
- - name: Tests
- run: |
- cd build
- make tests
-
- netbsd:
- strategy:
- matrix:
- args:
- -
- - --disable-ipv4
- - --disable-arp
- - --disable-ipv4ll
- - --disable-ipv6
- - --disable-dhcp6
- cppflags:
- -
- - -DSMALL
- runs-on: ubuntu-latest
- steps:
- - name: Bootstrap NetBSD-latest
- uses: mario-campos/emulate@v1
- with:
- operating-system: netbsd-latest
-
- - name: Build
- run: |
- git clone --depth=1 "${{ github.server_url }}/${{ github.repository }}" build
- cd build
- [ "${{ github.event.pull_request.number }}" = "" ] || (echo "fetching PR ${{ github.event.pull_request.number }}"; git fetch origin pull/${{ github.event.pull_request.number }}/head:pr-${{ github.event.pull_request.number }} && git checkout "pr-${{ github.event.pull_request.number }}")
- CFLAGS=-Werror CPPFLAGS="${{ matrix.cppflags }}" ./configure ${{ matrix.args }}
- make
-
- - name: Tests
- run: |
- cd build
- make tests
+ # Sadly the BSDs have stopped building ....
+
+ # openbsd:
+ # runs-on: ubuntu-latest
+ # steps:
+ # - name: Bootstrap OpenBSD-latest
+ # uses: mario-campos/emulate@v1
+ # with:
+ # operating-system: openbsd-latest
+
+ # - name: Install Dependencies
+ # run: pkg_add git
+
+ # - name: Build
+ # run: |
+ # git clone --depth=1 "${{ github.server_url }}/${{ github.repository }}" build
+ # cd build
+ # [ "${{ github.event.pull_request.number }}" = "" ] || (echo "fetching PR ${{ github.event.pull_request.number }}"; git fetch origin pull/${{ github.event.pull_request.number }}/head:pr-${{ github.event.pull_request.number }} && git checkout "pr-${{ github.event.pull_request.number }}")
+ # ./configure
+ # make
+
+ # - name: Tests
+ # run: |
+ # ulimit -n 1024
+ # cd build
+ # make tests
+
+ # freebsd:
+ # runs-on: ubuntu-latest
+ # steps:
+ # - name: Bootstrap FreeBSD-latest
+ # uses: mario-campos/emulate@v1
+ # with:
+ # operating-system: freebsd-latest
+
+ # - name: Install Dependencies
+ # run: pkg install -y git
+
+ # - name: Build
+ # run: |
+ # git clone --depth=1 "${{ github.server_url }}/${{ github.repository }}" build
+ # cd build
+ # [ "${{ github.event.pull_request.number }}" = "" ] || (echo "fetching PR ${{ github.event.pull_request.number }}"; git fetch origin pull/${{ github.event.pull_request.number }}/head:pr-${{ github.event.pull_request.number }} && git checkout "pr-${{ github.event.pull_request.number }}")
+ # ./configure
+ # make
+
+ # - name: Tests
+ # run: |
+ # cd build
+ # make tests
+
+ # netbsd:
+ # strategy:
+ # matrix:
+ # args:
+ # -
+ # - --disable-ipv4
+ # - --disable-arp
+ # - --disable-ipv4ll
+ # - --disable-ipv6
+ # - --disable-dhcp6
+ # cppflags:
+ # -
+ # - -DSMALL
+ # runs-on: ubuntu-latest
+ # steps:
+ # - name: Bootstrap NetBSD-latest
+ # uses: mario-campos/emulate@v1
+ # with:
+ # operating-system: netbsd-latest
+
+ # - name: Build
+ # run: |
+ # git clone --depth=1 "${{ github.server_url }}/${{ github.repository }}" build
+ # cd build
+ # [ "${{ github.event.pull_request.number }}" = "" ] || (echo "fetching PR ${{ github.event.pull_request.number }}"; git fetch origin pull/${{ github.event.pull_request.number }}/head:pr-${{ github.event.pull_request.number }} && git checkout "pr-${{ github.event.pull_request.number }}")
+ # CFLAGS=-Werror CPPFLAGS="${{ matrix.cppflags }}" ./configure ${{ matrix.args }}
+ # make
+
+ # - name: Tests
+ # run: |
+ # cd build
+ # make tests
--- /dev/null
+name: Clang Format Checker
+on:
+ push:
+ pull_request:
+ branches: [master]
+jobs:
+ clang-format-checking:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v5
+ # This is pinned to clang-format v19
+ - uses: RafikFarhad/clang-format-github-action@v5
+ with:
+ style: "file"
+ sources: "src/**/*.h,src/**/*.c"
# DragonFlyBSD builds base version with private crypto
if [ `uname` = DragonFly ]; then rm ${DESTDIR}/compat/crypt/md5* ${DESTDIR}/compat/crypt/sha256*; fi
-include ${TOP}/Makefile.inc
+include Makefile.inc
--- /dev/null
+check-format:
+ find . -iname "*.c" -o -iname "*.h" | \
+ xargs -- clang-format --dry-run --Werror
+
+format:
+ find . -iname "*.c" -o -iname "*.h" | \
+ xargs -- clang-format -i
+
+_lint:
+ clang-tidy ${SRCS} -- ${CPPFLAGS} ${CFLAGS} -isystem ${TOP}/vendor
+
+include ${TOP}/Makefile.inc
* SUCH DAMAGE.
*/
-#include <sys/socket.h>
#include <sys/types.h>
-
-#include <arpa/inet.h>
+#include <sys/socket.h>
#include <net/if.h>
#include <netinet/in.h>
#include <netinet/if_ether.h>
+#include <arpa/inet.h>
#include <errno.h>
-#include <stdlib.h>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#define ELOOP_QUEUE ELOOP_ARP
-#include "config.h"
+#define ELOOP_QUEUE ELOOP_ARP
#include "arp.h"
#include "bpf.h"
-#include "ipv4.h"
#include "common.h"
+#include "config.h"
#include "dhcpcd.h"
#include "eloop.h"
-#include "if.h"
#include "if-options.h"
+#include "if.h"
+#include "ipv4.h"
#include "ipv4ll.h"
#include "logerr.h"
#include "privsep.h"
#if defined(ARP)
-#define ARP_LEN \
- (FRAMEHDRLEN_MAX + \
- sizeof(struct arphdr) + (2 * sizeof(uint32_t)) + (2 * HWADDR_LEN))
+#define ARP_LEN \
+ (FRAMEHDRLEN_MAX + sizeof(struct arphdr) + (2 * sizeof(uint32_t)) + \
+ (2 * HWADDR_LEN))
/* ARP debugging can be quite noisy. Enable this for more noise! */
-//#define ARP_DEBUG
+// #define ARP_DEBUG
/* Assert the correct structure size for on wire */
__CTASSERT(sizeof(struct arphdr) == 8);
static ssize_t
-arp_request(const struct arp_state *astate,
- const struct in_addr *sip)
+arp_request(const struct arp_state *astate, const struct in_addr *sip)
{
const struct interface *ifp = astate->iface;
const struct in_addr *tip = &astate->addr;
p = arp_buffer;
len = 0;
-#define CHECK(fun, b, l) \
- do { \
- if (len + (l) > sizeof(arp_buffer)) \
- goto eexit; \
- fun(p, (b), (l)); \
- p += (l); \
- len += (l); \
+#define CHECK(fun, b, l) \
+ do { \
+ if (len + (l) > sizeof(arp_buffer)) \
+ goto eexit; \
+ fun(p, (b), (l)); \
+ p += (l); \
+ len += (l); \
} while (/* CONSTCOND */ 0)
-#define APPEND(b, l) CHECK(memcpy, b, l)
-#define ZERO(l) CHECK(memset, 0, l)
+#define APPEND(b, l) CHECK(memcpy, b, l)
+#define ZERO(l) CHECK(memset, 0, l)
APPEND(&ar, sizeof(ar));
APPEND(ifp->hwaddr, ifp->hwlen);
char fbuf[HWADDR_LEN * 3];
if (amsg == NULL) {
- logerrx("%s: DAD detected %s",
- astate->iface->name, inet_ntoa(astate->addr));
+ logerrx("%s: DAD detected %s", astate->iface->name,
+ inet_ntoa(astate->addr));
return;
}
hwaddr_ntoa(amsg->sha, astate->iface->hwlen, abuf, sizeof(abuf));
if (bpf_frame_header_len(astate->iface) == 0) {
- logwarnx("%s: %s claims %s",
- astate->iface->name, abuf, inet_ntoa(astate->addr));
+ logwarnx("%s: %s claims %s", astate->iface->name, abuf,
+ inet_ntoa(astate->addr));
return;
}
- logwarnx("%s: %s(%s) claims %s",
- astate->iface->name, abuf,
+ logwarnx("%s: %s(%s) claims %s", astate->iface->name, abuf,
hwaddr_ntoa(amsg->fsha, astate->iface->hwlen, fbuf, sizeof(fbuf)),
inet_ntoa(astate->addr));
}
* ignored. */
clock_gettime(CLOCK_MONOTONIC, &now);
if (timespecisset(&astate->defend) &&
- eloop_timespec_diff(&now, &astate->defend, NULL) < DEFEND_INTERVAL)
- {
- logwarnx("%s: %d second defence failed for %s",
- ifp->name, DEFEND_INTERVAL, inet_ntoa(astate->addr));
+ eloop_timespec_diff(&now, &astate->defend, NULL) <
+ DEFEND_INTERVAL) {
+ logwarnx("%s: %d second defence failed for %s", ifp->name,
+ DEFEND_INTERVAL, inet_ntoa(astate->addr));
if (ifp->options->options & DHCPCD_ARP_PERSISTDEFENCE)
return;
- }
- else if (arp_request(astate, &astate->addr) == -1)
+ } else if (arp_request(astate, &astate->addr) == -1)
logerr(__func__);
else {
- logdebugx("%s: defended address %s",
- ifp->name, inet_ntoa(astate->addr));
+ logdebugx("%s: defended address %s", ifp->name,
+ inet_ntoa(astate->addr));
astate->defend = now;
return;
}
static bool
arp_validate(const struct interface *ifp, struct arphdr *arp)
{
-
/* Address type must match */
if (arp->ar_hrd != htons(ifp->hwtype))
return false;
return;
/* Ignore messages from ourself */
if (ar.ar_hln == ifp->hwlen &&
- memcmp(hw_s, ifp->hwaddr, ifp->hwlen) == 0)
- {
+ memcmp(hw_s, ifp->hwaddr, ifp->hwlen) == 0) {
#ifdef ARP_DEBUG
logdebugx("%s: ignoring ARP from self", ifp->name);
#endif
memcpy(&arm.tip.s_addr, hw_t + ar.ar_hln, ar.ar_pln);
#ifndef KERNEL_RFC5227
- /* During ARP probe the 'sender hardware address' MUST contain the hardware
- * address of the interface sending the packet. RFC5227, 1.1 */
- is_probe = ar.ar_op == htons(ARPOP_REQUEST) && IN_IS_ADDR_UNSPECIFIED(&arm.sip) &&
- bpf_flags & BPF_BCAST;
- if (is_probe && falen > 0 && (falen != ar.ar_hln ||
- memcmp(&arm.sha, &arm.fsha, ar.ar_hln))) {
+ /* During ARP probe the 'sender hardware address' MUST contain the
+ * hardware address of the interface sending the packet. RFC5227, 1.1 */
+ is_probe = ar.ar_op == htons(ARPOP_REQUEST) &&
+ IN_IS_ADDR_UNSPECIFIED(&arm.sip) && bpf_flags & BPF_BCAST;
+ if (is_probe && falen > 0 &&
+ (falen != ar.ar_hln || memcmp(&arm.sha, &arm.fsha, ar.ar_hln))) {
char abuf[HWADDR_LEN * 3];
char fbuf[HWADDR_LEN * 3];
hwaddr_ntoa(&arm.sha, ar.ar_hln, abuf, sizeof(abuf));
hwaddr_ntoa(&arm.fsha, falen, fbuf, sizeof(fbuf));
- logwarnx("%s: invalid ARP probe, sender hw address mismatch (%s, %s)",
+ logwarnx(
+ "%s: invalid ARP probe, sender hw address mismatch (%s, %s)",
ifp->name, abuf, fbuf);
return;
}
TAILQ_FOREACH_SAFE(astate, &state->arp_states, next, astaten) {
if (IN_ARE_ADDR_EQUAL(&arm.sip, &astate->addr) ||
(IN_IS_ADDR_UNSPECIFIED(&arm.sip) &&
- IN_ARE_ADDR_EQUAL(&arm.tip, &astate->addr) &&
- bpf_flags & BPF_BCAST))
+ IN_ARE_ADDR_EQUAL(&arm.tip, &astate->addr) &&
+ bpf_flags & BPF_BCAST))
arp_found(astate, &arm);
}
}
if (++astate->probes < PROBE_NUM) {
delay = (PROBE_MIN * MSEC_PER_SEC) +
(arc4random_uniform(
- (PROBE_MAX - PROBE_MIN) * MSEC_PER_SEC));
- eloop_timeout_add_msec(ifp->ctx->eloop, delay, arp_probe1, astate);
+ (PROBE_MAX - PROBE_MIN) * MSEC_PER_SEC));
+ eloop_timeout_add_msec(ifp->ctx->eloop, delay, arp_probe1,
+ astate);
} else {
- delay = ANNOUNCE_WAIT * MSEC_PER_SEC;
- eloop_timeout_add_msec(ifp->ctx->eloop, delay, arp_probed, astate);
+ delay = ANNOUNCE_WAIT * MSEC_PER_SEC;
+ eloop_timeout_add_msec(ifp->ctx->eloop, delay, arp_probed,
+ astate);
}
logdebugx("%s: ARP probing %s (%d of %d), next in %0.1f seconds",
ifp->name, inet_ntoa(astate->addr),
void
arp_probe(struct arp_state *astate)
{
-
astate->probes = 0;
- logdebugx("%s: probing for %s",
- astate->iface->name, inet_ntoa(astate->addr));
+ logdebugx("%s: probing for %s", astate->iface->name,
+ inet_ntoa(astate->addr));
arp_probe1(astate);
}
-#endif /* ARP */
+#endif /* ARP */
struct arp_state *
arp_find(struct interface *ifp, const struct in_addr *addr)
if (++astate->claims < ANNOUNCE_NUM)
logdebugx("%s: ARP announcing %s (%d of %d), "
- "next in %d.0 seconds",
- ifp->name, inet_ntoa(astate->addr),
- astate->claims, ANNOUNCE_NUM, ANNOUNCE_WAIT);
+ "next in %d.0 seconds",
+ ifp->name, inet_ntoa(astate->addr), astate->claims,
+ ANNOUNCE_NUM, ANNOUNCE_WAIT);
else
- logdebugx("%s: ARP announcing %s (%d of %d)",
- ifp->name, inet_ntoa(astate->addr),
- astate->claims, ANNOUNCE_NUM);
+ logdebugx("%s: ARP announcing %s (%d of %d)", ifp->name,
+ inet_ntoa(astate->addr), astate->claims, ANNOUNCE_NUM);
/* The kernel will send a Gratuitous ARP for newly added addresses.
* So we can avoid sending the same.
a2->addr.s_addr != astate->addr.s_addr)
continue;
r = eloop_timeout_delete(a2->iface->ctx->eloop,
- a2->claims < ANNOUNCE_NUM
- ? arp_announce1 : arp_announced,
+ a2->claims < ANNOUNCE_NUM ? arp_announce1 :
+ arp_announced,
a2);
if (r == -1)
logerr(__func__);
else if (r != 0) {
logdebugx("%s: ARP announcement "
- "of %s cancelled",
- a2->iface->name,
- inet_ntoa(a2->addr));
+ "of %s cancelled",
+ a2->iface->name, inet_ntoa(a2->addr));
arp_announced(a2);
}
}
free(astate);
return NULL;
}
- if (eloop_event_add(ifp->ctx->eloop, astate->bpf->bpf_fd, ELE_READ,
- arp_read, astate) == -1)
+ if (eloop_event_add(ifp->ctx->eloop, astate->bpf->bpf_fd,
+ ELE_READ, arp_read, astate) == -1)
logerr("%s: eloop_event_add", __func__);
}
-
state = ARP_STATE(ifp);
TAILQ_INSERT_TAIL(&state->arp_states, astate, next);
return astate;
ctx = ifp->ctx;
eloop_timeout_delete(ctx->eloop, NULL, astate);
- state = ARP_STATE(ifp);
+ state = ARP_STATE(ifp);
TAILQ_REMOVE(&state->arp_states, astate, next);
if (astate->free_cb)
astate->free_cb(astate);
#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
+#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 "bpf.h"
#include "dhcpcd.h"
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])
+#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 ARP
void arp_packet(struct interface *, uint8_t *, size_t, unsigned int);
struct arp_state *arp_new(struct interface *, const struct in_addr *);
void arp_probe(struct arp_state *);
-struct arp_state *arp_ifannounceaddr(struct interface *, const struct in_addr *);
-struct arp_state * arp_find(struct interface *, const struct in_addr *);
+struct arp_state *arp_ifannounceaddr(struct interface *,
+ const struct in_addr *);
+struct arp_state *arp_find(struct interface *, const struct in_addr *);
void arp_free(struct arp_state *);
void arp_freeaddr(struct interface *, const struct in_addr *);
void arp_drop(struct interface *);
#include <time.h>
#include <unistd.h>
-#include "config.h"
#include "auth.h"
+#include "config.h"
#include "dhcp.h"
#include "dhcp6.h"
#include "dhcpcd.h"
#ifndef htonll
#if (BYTE_ORDER == LITTLE_ENDIAN)
-#define htonll(x) ((uint64_t)htonl((uint32_t)((x) >> 32)) | \
- (uint64_t)htonl((uint32_t)((x) & 0x00000000ffffffffULL)) << 32)
-#else /* (BYTE_ORDER == LITTLE_ENDIAN) */
-#define htonll(x) (x)
+#define htonll(x) \
+ ((uint64_t)htonl((uint32_t)((x) >> 32)) | \
+ (uint64_t)htonl((uint32_t)((x) & 0x00000000ffffffffULL)) << 32)
+#else /* (BYTE_ORDER == LITTLE_ENDIAN) */
+#define htonll(x) (x)
#endif
-#endif /* htonll */
+#endif /* htonll */
#ifndef ntohll
#if (BYTE_ORDER == LITTLE_ENDIAN)
-#define ntohll(x) ((uint64_t)ntohl((uint32_t)((x) >> 32)) | \
- (uint64_t)ntohl((uint32_t)((x) & 0x00000000ffffffffULL)) << 32)
-#else /* (BYTE_ORDER == LITTLE_ENDIAN) */
-#define ntohll(x) (x)
+#define ntohll(x) \
+ ((uint64_t)ntohl((uint32_t)((x) >> 32)) | \
+ (uint64_t)ntohl((uint32_t)((x) & 0x00000000ffffffffULL)) << 32)
+#else /* (BYTE_ORDER == LITTLE_ENDIAN) */
+#define ntohll(x) (x)
#endif
-#endif /* ntohll */
+#endif /* ntohll */
-#define HMAC_LENGTH 16
+#define HMAC_LENGTH 16
void
dhcp_auth_reset(struct authstate *state)
{
-
state->replay = 0;
if (state->token) {
free(state->token->key);
*/
const struct token *
dhcp_auth_validate(struct authstate *state, const struct auth *auth,
- const void *vm, size_t mlen, int mp, int mt,
- const void *vdata, size_t dlen)
+ const void *vm, size_t mlen, int mp, int mt, const void *vdata, size_t dlen)
{
const uint8_t *m, *data;
uint8_t protocol, algorithm, rdm, *mm, type;
errno = EINVAL;
return NULL;
}
- } else if (protocol != auth->protocol ||
- algorithm != auth->algorithm ||
- rdm != auth->rdm)
- {
+ } 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)
- {
+ auth->options & DHCPCD_AUTH_REQUIRE) {
errno = EPERM;
return NULL;
}
return NULL;
}
}
- d+= sizeof(replay);
+ d += sizeof(replay);
dlen -= sizeof(replay);
realm = NULL;
switch (type) {
case 1:
if ((mp == 4 && mt == DHCP_ACK) ||
- (mp == 6 && mt == DHCP6_REPLY))
- {
+ (mp == 6 && mt == DHCP6_REPLY)) {
if (state->reconf == NULL) {
- state->reconf =
- malloc(sizeof(*state->reconf));
+ state->reconf = malloc(
+ sizeof(*state->reconf));
if (state->reconf == NULL)
return NULL;
state->reconf->key = malloc(16);
return state->reconf;
case 2:
if (!((mp == 4 && mt == DHCP_FORCERENEW) ||
- (mp == 6 && mt == DHCP6_RECONFIGURE)))
- {
+ (mp == 6 && mt == DHCP6_RECONFIGURE))) {
errno = EINVAL;
return NULL;
}
/* Find a token for the realm and secret */
TAILQ_FOREACH(t, &auth->tokens, next) {
- if (t->secretid == secretid &&
- t->realm_len == realm_len &&
+ if (t->secretid == secretid && t->realm_len == realm_len &&
(t->realm_len == 0 ||
- memcmp(t->realm, realm, t->realm_len) == 0))
+ memcmp(t->realm, realm, t->realm_len) == 0))
break;
}
if (t == NULL) {
/* 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)))
- {
+ state->token->realm_len != t->realm_len ||
+ memcmp(state->token->realm, t->realm, t->realm_len))) {
errno = EPERM;
return NULL;
}
memset(hmac_code, 0, sizeof(hmac_code));
switch (algorithm) {
case AUTH_ALG_HMAC_MD5:
- hmac("md5", t->key, t->key_len, mm, mlen,
- hmac_code, sizeof(hmac_code));
+ hmac("md5", t->key, t->key_len, mm, mlen, hmac_code,
+ sizeof(hmac_code));
break;
default:
errno = ENOSYS;
}
(*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 (fseek(fp, 0, SEEK_SET) == -1 || ftruncate(fileno(fp), 0) == -1 ||
+ fprintf(fp, "0x%016" PRIu64 "\n", *rdm) != 19 || fflush(fp) == EOF)
err = -1;
else
err = 0;
return err;
}
-#define NTP_EPOCH 2208988800U /* 1970 - 1900 in seconds */
-#define NTP_SCALE_FRAC 4294967295.0 /* max value of the fractional part */
+#define NTP_EPOCH 2208988800U /* 1970 - 1900 in seconds */
+#define NTP_SCALE_FRAC 4294967295.0 /* max value of the fractional part */
static uint64_t
get_next_rdm_monotonic_clock(struct auth *auth)
{
#ifdef PRIVSEP
if (IN_PRIVSEP(ctx)) {
-
err = ps_root_getauthrdm(ctx, &rdm);
} else
#endif
*/
ssize_t
dhcp_auth_encode(struct dhcpcd_ctx *ctx, struct auth *auth,
- const struct token *t,
- void *vm, size_t mlen, int mp, int mt,
- void *vdata, size_t dlen)
+ const struct token *t, void *vm, size_t mlen, int mp, int mt, void *vdata,
+ size_t dlen)
{
uint64_t rdm;
uint8_t hmac_code[HMAC_LENGTH];
}
}
- switch(auth->protocol) {
+ switch (auth->protocol) {
case AUTH_PROTO_TOKEN:
case AUTH_PROTO_DELAYED:
case AUTH_PROTO_DELAYEDREALM:
return -1;
}
- switch(auth->algorithm) {
+ switch (auth->algorithm) {
case AUTH_ALG_NONE:
case AUTH_ALG_HMAC_MD5:
break;
return -1;
}
- switch(auth->rdm) {
+ switch (auth->rdm) {
case AUTH_RDM_MONOTONIC:
break;
default:
* We only need to do this for DISCOVER messages */
if (vdata == NULL) {
dlen = 1 + 1 + 1 + 8;
- switch(auth->protocol) {
+ switch (auth->protocol) {
case AUTH_PROTO_TOKEN:
dlen += t->key_len;
break;
* which is probably a good idea because both states start from zero.
*/
if (auth_info ||
- !(auth->protocol & (AUTH_PROTO_DELAYED | AUTH_PROTO_DELAYEDREALM)))
- {
+ !(auth->protocol &
+ (AUTH_PROTO_DELAYED | AUTH_PROTO_DELAYEDREALM))) {
*data++ = auth->rdm;
switch (auth->rdm) {
case AUTH_RDM_MONOTONIC:
rdm = htonll(rdm);
memcpy(data, &rdm, 8);
} else {
- *data++ = 0; /* rdm */
- memset(data, 0, 8); /* replay detection data */
+ *data++ = 0; /* rdm */
+ memset(data, 0, 8); /* replay detection data */
}
data += 8;
dlen -= 1 + 1 + 1 + 8;
return -1;
}
if (dlen < t->key_len) {
- errno = ENOBUFS;
+ errno = ENOBUFS;
return -1;
}
memcpy(data, t->key, t->key_len);
/* Write out the SecretID */
if (auth->protocol == AUTH_PROTO_DELAYED ||
- auth->protocol == AUTH_PROTO_DELAYEDREALM)
- {
+ auth->protocol == AUTH_PROTO_DELAYEDREALM) {
if (dlen < sizeof(t->secretid)) {
errno = ENOBUFS;
return -1;
}
/* Create our hash and write it out */
- switch(auth->algorithm) {
+ switch (auth->algorithm) {
case AUTH_ALG_HMAC_MD5:
- hmac("md5", t->key, t->key_len, m, mlen,
- hmac_code, sizeof(hmac_code));
+ hmac("md5", t->key, t->key_len, m, mlen, hmac_code,
+ sizeof(hmac_code));
memcpy(data, hmac_code, sizeof(hmac_code));
break;
}
#define DHCPCD_AUTH_SEND (1 << 0)
#define DHCPCD_AUTH_REQUIRE (1 << 1)
-#define DHCPCD_AUTH_RDM_COUNTER (1 << 2)
+#define DHCPCD_AUTH_RDM_COUNTER (1 << 2)
-#define DHCPCD_AUTH_SENDREQUIRE (DHCPCD_AUTH_SEND | DHCPCD_AUTH_REQUIRE)
+#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_DELAYEDREALM 2
#define AUTH_PROTO_RECONFKEY 3
#define AUTH_ALG_NONE 0
void dhcp_auth_reset(struct authstate *);
-const struct token * dhcp_auth_validate(struct authstate *,
- const struct auth *,
- const void *, size_t, int, int,
- const void *, size_t);
+const struct token *dhcp_auth_validate(struct authstate *, const struct auth *,
+ const void *, size_t, int, int, const void *, size_t);
struct dhcpcd_ctx;
ssize_t dhcp_auth_encode(struct dhcpcd_ctx *, struct auth *,
- const struct token *,
- void *, size_t, int, int,
- void *, size_t);
+ const struct token *, void *, size_t, int, int, void *, size_t);
int auth_get_rdm_monotonic(uint64_t *rdm);
#endif
#include <sys/ioctl.h>
#include <sys/socket.h>
-#include <arpa/inet.h>
-
#include <net/if.h>
#include <netinet/in.h>
#include <netinet/if_ether.h>
+#include <arpa/inet.h>
+
#ifdef __linux__
/* Special BPF snowflake. */
#include <linux/filter.h>
-#define bpf_insn sock_filter
+#define bpf_insn sock_filter
#else
#include <net/bpf.h>
#endif
#include <stdlib.h>
#include <string.h>
-#include "common.h"
#include "arp.h"
#include "bpf.h"
+#include "common.h"
#include "dhcp.h"
#include "if.h"
#include "logerr.h"
/* BPF helper macros */
#ifdef __linux__
-#define BPF_WHOLEPACKET 0x7fffffff /* work around buggy LPF filters */
+#define BPF_WHOLEPACKET 0x7fffffff /* work around buggy LPF filters */
#else
-#define BPF_WHOLEPACKET ~0U
+#define BPF_WHOLEPACKET ~0U
#endif
/* Macros to update the BPF structure */
-#define BPF_SET_STMT(insn, c, v) { \
- (insn)->code = (c); \
- (insn)->jt = 0; \
- (insn)->jf = 0; \
- (insn)->k = (uint32_t)(v); \
-}
+#define BPF_SET_STMT(insn, c, v) \
+ { \
+ (insn)->code = (c); \
+ (insn)->jt = 0; \
+ (insn)->jf = 0; \
+ (insn)->k = (uint32_t)(v); \
+ }
-#define BPF_SET_JUMP(insn, c, v, t, f) { \
- (insn)->code = (c); \
- (insn)->jt = (t); \
- (insn)->jf = (f); \
- (insn)->k = (uint32_t)(v); \
-}
+#define BPF_SET_JUMP(insn, c, v, t, f) \
+ { \
+ (insn)->code = (c); \
+ (insn)->jt = (t); \
+ (insn)->jf = (f); \
+ (insn)->k = (uint32_t)(v); \
+ }
size_t
bpf_frame_header_len(const struct interface *ifp)
{
-
switch (ifp->hwtype) {
case ARPHRD_ETHER:
return sizeof(struct ether_header);
return f + offsetof(struct ether_header, ether_shost);
default:
*len = 0;
- errno = ENOTSUP;
+ errno = ENOTSUP;
return NULL;
}
}
return f + offsetof(struct ether_header, ether_dhost);
default:
*len = 0;
- errno = ENOTSUP;
+ errno = ENOTSUP;
return NULL;
}
}
-static const uint8_t etherbcastaddr[] =
- { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
+static const uint8_t etherbcastaddr[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
int
bpf_frame_bcast(const struct interface *ifp, const void *frame)
{
-
switch (ifp->hwtype) {
case ARPHRD_ETHER:
return memcmp((const char *)frame +
- offsetof(struct ether_header, ether_dhost),
+ offsetof(struct ether_header, ether_dhost),
etherbcastaddr, sizeof(etherbcastaddr));
default:
return -1;
else
bpf->bpf_flags &= ~BPF_BCAST;
memcpy(data, payload, (size_t)bytes);
-next:
- bpf->bpf_pos += BPF_WORDALIGN(packet.bh_hdrlen +
- packet.bh_caplen);
+ next:
+ bpf->bpf_pos += BPF_WORDALIGN(
+ packet.bh_hdrlen + packet.bh_caplen);
if (bpf->bpf_pos >= bpf->bpf_len) {
bpf->bpf_len = bpf->bpf_pos = 0;
bpf->bpf_flags |= BPF_EOF;
#ifndef __sun
/* SunOS is special too - sending via BPF goes nowhere. */
ssize_t
-bpf_send(const struct bpf *bpf, uint16_t protocol,
- const void *data, size_t len)
+bpf_send(const struct bpf *bpf, uint16_t protocol, const void *data, size_t len)
{
struct iovec iov[2];
struct ether_header eh;
- switch(bpf->bpf_ifp->hwtype) {
+ switch (bpf->bpf_ifp->hwtype) {
case ARPHRD_ETHER:
memset(&eh.ether_dhost, 0xff, sizeof(eh.ether_dhost));
memcpy(&eh.ether_shost, bpf->bpf_ifp->hwaddr,
void
bpf_close(struct bpf *bpf)
{
-
close(bpf->bpf_fd);
free(bpf->bpf_buffer);
free(bpf);
}
#ifdef ARP
-#define BPF_CMP_HWADDR_LEN ((((HWADDR_LEN / 4) + 2) * 2) + 1)
+#define BPF_CMP_HWADDR_LEN ((((HWADDR_LEN / 4) + 2) * 2) + 1)
static unsigned int
-bpf_cmp_hwaddr(struct bpf_insn *bpf, size_t bpf_len, size_t off,
- bool equal, const uint8_t *hwaddr, size_t hwaddr_len)
+bpf_cmp_hwaddr(struct bpf_insn *bpf, size_t bpf_len, size_t off, bool equal,
+ const uint8_t *hwaddr, size_t hwaddr_len)
{
struct bpf_insn *bp;
size_t maclen, nlft, njmps;
nlft = nlft % 2;
if (nlft)
njmps += 2;
-
}
/* Skip to positive finish. */
bp = bpf;
for (; hwaddr_len > 0;
- hwaddr += maclen, hwaddr_len -= maclen, off += maclen)
- {
+ hwaddr += maclen, hwaddr_len -= maclen, off += maclen) {
if (bpf_len < 3) {
errno = ENOBUFS;
return 0;
BPF_SET_STMT(bp, BPF_LD + BPF_W + BPF_IND, off);
bp++;
BPF_SET_JUMP(bp, BPF_JMP + BPF_JEQ + BPF_K,
- htonl(mac32), jt, jf);
+ htonl(mac32), jt, jf);
} else if (hwaddr_len >= 2) {
maclen = sizeof(mac16);
memcpy(&mac16, hwaddr, maclen);
BPF_SET_STMT(bp, BPF_LD + BPF_H + BPF_IND, off);
bp++;
BPF_SET_JUMP(bp, BPF_JMP + BPF_JEQ + BPF_K,
- htons(mac16), jt, jf);
+ htons(mac16), jt, jf);
} else {
maclen = sizeof(*hwaddr);
BPF_SET_STMT(bp, BPF_LD + BPF_B + BPF_IND, off);
bp++;
- BPF_SET_JUMP(bp, BPF_JMP + BPF_JEQ + BPF_K,
- *hwaddr, jt, jf);
+ BPF_SET_JUMP(bp, BPF_JMP + BPF_JEQ + BPF_K, *hwaddr, jt,
+ jf);
}
if (jt)
jt = (uint8_t)(jt - 2);
#endif
#ifdef ARP
-static const struct bpf_insn bpf_arp_ether [] = {
+static const struct bpf_insn bpf_arp_ether[] = {
/* Check this is an ARP packet. */
BPF_STMT(BPF_LD + BPF_H + BPF_ABS,
- offsetof(struct ether_header, ether_type)),
+ offsetof(struct ether_header, ether_type)),
BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, ETHERTYPE_ARP, 1, 0),
BPF_STMT(BPF_RET + BPF_K, 0),
/* Make sure the hardware length matches. */
BPF_STMT(BPF_LD + BPF_B + BPF_IND, offsetof(struct arphdr, ar_hln)),
BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K,
- sizeof(((struct ether_arp *)0)->arp_sha), 1, 0),
+ sizeof(((struct ether_arp *)0)->arp_sha), 1, 0),
BPF_STMT(BPF_RET + BPF_K, 0),
};
-#define BPF_ARP_ETHER_LEN __arraycount(bpf_arp_ether)
+#define BPF_ARP_ETHER_LEN __arraycount(bpf_arp_ether)
-static const struct bpf_insn bpf_arp_filter [] = {
+static const struct bpf_insn bpf_arp_filter[] = {
/* Make sure this is for IP. */
BPF_STMT(BPF_LD + BPF_H + BPF_IND, offsetof(struct arphdr, ar_pro)),
BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, ETHERTYPE_IP, 1, 0),
BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, sizeof(in_addr_t), 1, 0),
BPF_STMT(BPF_RET + BPF_K, 0),
};
-#define BPF_ARP_FILTER_LEN __arraycount(bpf_arp_filter)
+#define BPF_ARP_FILTER_LEN __arraycount(bpf_arp_filter)
/* One address is two checks of two statements. */
-#define BPF_NADDRS 1
-#define BPF_ARP_ADDRS_LEN 5 + ((BPF_NADDRS * 2) * 2)
+#define BPF_NADDRS 1
+#define BPF_ARP_ADDRS_LEN 5 + ((BPF_NADDRS * 2) * 2)
-#define BPF_ARP_LEN BPF_ARP_ETHER_LEN + BPF_ARP_FILTER_LEN + \
- BPF_CMP_HWADDR_LEN + BPF_ARP_ADDRS_LEN
+#define BPF_ARP_LEN \
+ BPF_ARP_ETHER_LEN + BPF_ARP_FILTER_LEN + BPF_CMP_HWADDR_LEN + \
+ BPF_ARP_ADDRS_LEN
static int
bpf_arp_rw(const struct bpf *bpf, const struct in_addr *ia, bool recv)
bp = buf;
/* Check frame header. */
- switch(ifp->hwtype) {
+ switch (ifp->hwtype) {
case ARPHRD_ETHER:
memcpy(bp, bpf_arp_ether, sizeof(bpf_arp_ether));
bp += BPF_ARP_ETHER_LEN;
- arp_len = sizeof(struct ether_header)+sizeof(struct ether_arp);
+ arp_len = sizeof(struct ether_header) +
+ sizeof(struct ether_arp);
break;
default:
errno = EINVAL;
/* Ensure it's not from us. */
bp += bpf_cmp_hwaddr(bp, BPF_CMP_HWADDR_LEN, sizeof(struct arphdr),
- !recv, ifp->hwaddr, ifp->hwlen);
+ !recv, ifp->hwaddr, ifp->hwlen);
/* Match sender protocol address */
BPF_SET_STMT(bp, BPF_LD + BPF_W + BPF_IND,
bp++;
/* Match target protocol address */
- BPF_SET_STMT(bp, BPF_LD + BPF_W + BPF_IND, (sizeof(struct arphdr) +
- (size_t)(ifp->hwlen * 2) + sizeof(in_addr_t)));
+ BPF_SET_STMT(bp, BPF_LD + BPF_W + BPF_IND,
+ (sizeof(struct arphdr) + (size_t)(ifp->hwlen * 2) +
+ sizeof(in_addr_t)));
bp++;
BPF_SET_JUMP(bp, BPF_JMP + BPF_JEQ + BPF_K, htonl(ia->s_addr), 0, 1);
bp++;
int
bpf_arp(const struct bpf *bpf, const struct in_addr *ia)
{
-
#ifdef BIOCSETWF
if (bpf_arp_rw(bpf, ia, true) == -1 ||
bpf_arp_rw(bpf, ia, false) == -1 ||
#endif
#ifdef ARPHRD_NONE
-static const struct bpf_insn bpf_bootp_none[] = {
-};
-#define BPF_BOOTP_NONE_LEN __arraycount(bpf_bootp_none)
+static const struct bpf_insn bpf_bootp_none[] = {};
+#define BPF_BOOTP_NONE_LEN __arraycount(bpf_bootp_none)
#endif
static const struct bpf_insn bpf_bootp_ether[] = {
/* Make sure this is an IP packet. */
BPF_STMT(BPF_LD + BPF_H + BPF_ABS,
- offsetof(struct ether_header, ether_type)),
+ offsetof(struct ether_header, ether_type)),
BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, ETHERTYPE_IP, 1, 0),
BPF_STMT(BPF_RET + BPF_K, 0),
/* Advance to the IP header. */
BPF_STMT(BPF_LDX + BPF_K, sizeof(struct ether_header)),
};
-#define BPF_BOOTP_ETHER_LEN __arraycount(bpf_bootp_ether)
+#define BPF_BOOTP_ETHER_LEN __arraycount(bpf_bootp_ether)
static const struct bpf_insn bpf_bootp_base[] = {
/* Make sure it's an IPv4 packet. */
BPF_STMT(BPF_ALU + BPF_ADD + BPF_X, 0),
BPF_STMT(BPF_MISC + BPF_TAX, 0),
};
-#define BPF_BOOTP_BASE_LEN __arraycount(bpf_bootp_base)
+#define BPF_BOOTP_BASE_LEN __arraycount(bpf_bootp_base)
static const struct bpf_insn bpf_bootp_read[] = {
/* Make sure it's to the right port.
BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, BOOTPC, 1, 0),
BPF_STMT(BPF_RET + BPF_K, 0),
};
-#define BPF_BOOTP_READ_LEN __arraycount(bpf_bootp_read)
+#define BPF_BOOTP_READ_LEN __arraycount(bpf_bootp_read)
#ifdef BIOCSETWF
static const struct bpf_insn bpf_bootp_write[] = {
BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, (BOOTPC << 16) + BOOTPS, 1, 0),
BPF_STMT(BPF_RET + BPF_K, 0),
};
-#define BPF_BOOTP_WRITE_LEN __arraycount(bpf_bootp_write)
+#define BPF_BOOTP_WRITE_LEN __arraycount(bpf_bootp_write)
#endif
-#define BPF_BOOTP_CHADDR_LEN ((BOOTP_CHADDR_LEN / 4) * 3)
-#define BPF_BOOTP_XID_LEN 4 /* BOUND check is 4 instructions */
+#define BPF_BOOTP_CHADDR_LEN ((BOOTP_CHADDR_LEN / 4) * 3)
+#define BPF_BOOTP_XID_LEN 4 /* BOUND check is 4 instructions */
-#define BPF_BOOTP_LEN BPF_BOOTP_ETHER_LEN + \
- BPF_BOOTP_BASE_LEN + BPF_BOOTP_READ_LEN + \
- BPF_BOOTP_XID_LEN + BPF_BOOTP_CHADDR_LEN + 4
+#define BPF_BOOTP_LEN \
+ BPF_BOOTP_ETHER_LEN + BPF_BOOTP_BASE_LEN + BPF_BOOTP_READ_LEN + \
+ BPF_BOOTP_XID_LEN + BPF_BOOTP_CHADDR_LEN + 4
static int
bpf_bootp_rw(const struct bpf *bpf, bool read)
bp = buf;
/* Check frame header. */
- switch(bpf->bpf_ifp->hwtype) {
+ switch (bpf->bpf_ifp->hwtype) {
#ifdef ARPHRD_NONE
case ARPHRD_NONE:
memcpy(bp, bpf_bootp_none, sizeof(bpf_bootp_none));
int
bpf_bootp(const struct bpf *bpf, __unused const struct in_addr *ia)
{
-
#ifdef BIOCSETWF
- if (bpf_bootp_rw(bpf, true) == -1 ||
- bpf_bootp_rw(bpf, false) == -1 ||
+ if (bpf_bootp_rw(bpf, true) == -1 || bpf_bootp_rw(bpf, false) == -1 ||
ioctl(bpf->bpf_fd, BIOCLOCK) == -1)
return -1;
return 0;
#ifndef BPF_HEADER
#define BPF_HEADER
-#define BPF_EOF 0x01U
-#define BPF_PARTIALCSUM 0x02U
-#define BPF_BCAST 0x04U
+#define BPF_EOF 0x01U
+#define BPF_PARTIALCSUM 0x02U
+#define BPF_BCAST 0x04U
/*
* Even though we program the BPF filter should we trust it?
* If you want to be notified of any packet failing the BPF filter,
* define BPF_DEBUG below.
*/
-//#define BPF_DEBUG
+// #define BPF_DEBUG
#include "dhcpcd.h"
void *bpf_frame_header_src(const struct interface *, void *, size_t *);
void *bpf_frame_header_dst(const struct interface *, void *, size_t *);
int bpf_frame_bcast(const struct interface *, const void *);
-struct bpf * bpf_open(const struct interface *,
+struct bpf *bpf_open(const struct interface *,
int (*)(const struct bpf *, const struct in_addr *),
const struct in_addr *);
void bpf_close(struct bpf *);
p = buf;
while (hp < ep) {
if (hp != hwaddr)
- *p ++= ':';
+ *p++ = ':';
p += snprintf(p, 3, "%.2x", *hp++);
}
- *p ++= '\0';
+ *p++ = '\0';
return buf;
}
/* Skip separators */
c[0] = *p++;
switch (c[0]) {
- case '\n': /* long duid split on lines */
- case ':': /* typical mac address */
- case '-': /* uuid */
+ case '\n': /* long duid split on lines */
+ case ':': /* typical mac address */
+ case '-': /* uuid */
continue;
}
c[1] = *p++;
/* Ensure that digits are hex */
if (isxdigit((unsigned char)c[0]) == 0 ||
- isxdigit((unsigned char)c[1]) == 0)
- {
+ isxdigit((unsigned char)c[1]) == 0) {
errno = EINVAL;
return 0;
}
* We strip leading space and avoid comment lines, making the code that calls
* us smaller. */
char *
-get_line(char ** __restrict buf, ssize_t * __restrict buflen)
+get_line(char **__restrict buf, ssize_t *__restrict buflen)
{
char *p, *c;
bool quoted;
return p;
}
-
int
is_root_local(void)
{
}
uint32_t
-lifetime_left(uint32_t lifetime, const struct timespec *acquired, struct timespec *now)
+lifetime_left(uint32_t lifetime, const struct timespec *acquired,
+ struct timespec *now)
{
uint32_t elapsed;
struct timespec n;
#ifndef COMMON_H
#define COMMON_H
+#include <sys/types.h>
#include <sys/param.h>
#include <sys/time.h>
-#include <sys/types.h>
+
#include <stdint.h>
#include <stdio.h>
/* Define eloop queues here, as other apps share eloop.h */
-#define ELOOP_DHCPCD 1 /* default queue */
-#define ELOOP_DHCP 2
-#define ELOOP_ARP 3
-#define ELOOP_IPV4LL 4
-#define ELOOP_IPV6 5
-#define ELOOP_IPV6ND 6
-#define ELOOP_IPV6RA_EXPIRE 7
-#define ELOOP_DHCP6 8
-#define ELOOP_IF 9
+#define ELOOP_DHCPCD 1 /* default queue */
+#define ELOOP_DHCP 2
+#define ELOOP_ARP 3
+#define ELOOP_IPV4LL 4
+#define ELOOP_IPV6 5
+#define ELOOP_IPV6ND 6
+#define ELOOP_IPV6RA_EXPIRE 7
+#define ELOOP_DHCP6 8
+#define ELOOP_IF 9
#ifndef HOSTNAME_MAX_LEN
-#define HOSTNAME_MAX_LEN 250 /* 255 - 3 (FQDN) - 2 (DNS enc) */
+#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))
+#define MIN(a, b) ((/*CONSTCOND*/ (a) < (b)) ? (a) : (b))
+#define MAX(a, b) ((/*CONSTCOND*/ (a) > (b)) ? (a) : (b))
#endif
-#define UNCONST(a) ((void *)(uintptr_t)(const void *)(a))
-#define STRINGIFY(a) #a
-#define TOSTRING(a) STRINGIFY(a)
-#define UNUSED(a) (void)(a)
+#define UNCONST(a) ((void *)(uintptr_t)(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 ROUNDUP4(a) (1 + (((a) - 1) | 3))
+#define ROUNDUP8(a) (1 + (((a) - 1) | 7))
/* 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 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; \
- } \
+#define timespecclear(tsp) (tsp)->tv_sec = (time_t)((tsp)->tv_nsec = 0L)
+#define timespecisset(tsp) ((tsp)->tv_sec || (tsp)->tv_nsec)
+#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 (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; \
- } \
+#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 (0)
#endif
#if __GNUC__ > 2 || defined(__INTEL_COMPILER)
-# ifndef __unused
-# define __unused __attribute__((__unused__))
-# endif
+#ifndef __unused
+#define __unused __attribute__((__unused__))
+#endif
#else
-# ifndef __unused
-# define __unused
-# endif
+#ifndef __unused
+#define __unused
+#endif
#endif
/* Needed for rbtree(3) compat */
#define __RCSID(a)
#endif
#ifndef __predict_false
-# if __GNUC__ > 2
-# define __predict_true(exp) __builtin_expect((exp) != 0, 1)
-# define __predict_false(exp) __builtin_expect((exp) != 0, 0)
+#if __GNUC__ > 2
+#define __predict_true(exp) __builtin_expect((exp) != 0, 1)
+#define __predict_false(exp) __builtin_expect((exp) != 0, 0)
#else
-# define __predict_true(exp) (exp)
-# define __predict_false(exp) (exp)
-# endif
+#define __predict_true(exp) (exp)
+#define __predict_false(exp) (exp)
+#endif
#endif
#ifndef __BEGIN_DECLS
-# if defined(__cplusplus)
-# define __BEGIN_DECLS extern "C" {
-# define __END_DECLS };
-# else /* __BEGIN_DECLS */
-# define __BEGIN_DECLS
-# define __END_DECLS
-# endif /* __BEGIN_DECLS */
+#if defined(__cplusplus)
+#define __BEGIN_DECLS extern "C" {
+#define __END_DECLS \
+ } \
+ ;
+#else /* __BEGIN_DECLS */
+#define __BEGIN_DECLS
+#define __END_DECLS
+#endif /* __BEGIN_DECLS */
#endif /* __BEGIN_DECLS */
#ifndef __fallthrough
-# if __GNUC__ >= 7
-# define __fallthrough __attribute__((fallthrough))
-# else
-# define __fallthrough
-# endif
+#if __GNUC__ >= 7
+#define __fallthrough __attribute__((fallthrough))
+#else
+#define __fallthrough
+#endif
#endif
/*
* Compile Time Assertion.
*/
#ifndef __CTASSERT
-# ifdef __COUNTER__
-# define __CTASSERT(x) __CTASSERT0(x, __ctassert, __COUNTER__)
-# else
-# define __CTASSERT(x) __CTASSERT99(x, __INCLUDE_LEVEL__, __LINE__)
-# define __CTASSERT99(x, a, b) __CTASSERT0(x, __CONCAT(__ctassert,a), \
- __CONCAT(_,b))
-# endif
-# define __CTASSERT0(x, y, z) __CTASSERT1(x, y, z)
-# define __CTASSERT1(x, y, z) typedef char y ## z[/*CONSTCOND*/(x) ? 1 : -1] __unused
+#ifdef __COUNTER__
+#define __CTASSERT(x) __CTASSERT0(x, __ctassert, __COUNTER__)
+#else
+#define __CTASSERT(x) __CTASSERT99(x, __INCLUDE_LEVEL__, __LINE__)
+#define __CTASSERT99(x, a, b) \
+ __CTASSERT0(x, __CONCAT(__ctassert, a), __CONCAT(_, b))
+#endif
+#define __CTASSERT0(x, y, z) __CTASSERT1(x, y, z)
+#define __CTASSERT1(x, y, z) \
+ typedef char y##z[/*CONSTCOND*/ (x) ? 1 : -1] __unused
#endif
#ifndef __arraycount
-# define __arraycount(__x) (sizeof(__x) / sizeof(__x[0]))
+#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
+#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
#define INFINITE_LIFETIME (~0U)
ssize_t readfile(const char *, void *, size_t);
ssize_t writefile(const char *, mode_t, const void *, size_t);
int filemtime(const char *, time_t *);
-char *get_line(char ** __restrict, ssize_t * __restrict);
+char *get_line(char **__restrict, ssize_t *__restrict);
int is_root_local(void);
uint32_t lifetime_left(uint32_t, const struct timespec *, struct timespec *);
#endif
#include <time.h>
#include <unistd.h>
-#include "config.h"
#include "common.h"
-#include "dhcpcd.h"
+#include "config.h"
#include "control.h"
+#include "dhcpcd.h"
#include "eloop.h"
#include "if.h"
#include "logerr.h"
#ifndef SUN_LEN
#define SUN_LEN(su) \
- (sizeof(*(su)) - sizeof((su)->sun_path) + strlen((su)->sun_path))
+ (sizeof(*(su)) - sizeof((su)->sun_path) + strlen((su)->sun_path))
#endif
static void control_handle_data(void *, unsigned short);
void
control_free(struct fd_list *fd)
{
-
#ifdef PRIVSEP
if (fd->ctx->ps_control_client == fd)
fd->ctx->ps_control_client = NULL;
static void
control_hangup(struct fd_list *fd)
{
-
#ifdef PRIVSEP
if (IN_PRIVSEP(fd->ctx)) {
if (ps_ctl_sendeof(fd) == -1)
/* Done sending data, stop watching write to fd */
if (eloop_event_add(fd->ctx->eloop, fd->fd, ELE_READ,
- control_handle_data, fd) == -1)
+ control_handle_data, fd) == -1)
logerr("%s: eloop_event_add", __func__);
return 0;
}
;
else
#endif
- fd_flags |= FD_SENDLEN;
+ fd_flags |= FD_SENDLEN;
l = control_new(ctx, fd, fd_flags);
if (l == NULL)
goto error;
- if (eloop_event_add(ctx->eloop, l->fd, ELE_READ,
- control_handle_data, l) == -1)
+ if (eloop_event_add(ctx->eloop, l->fd, ELE_READ, control_handle_data,
+ l) == -1)
logerr("%s: eloop_event_add", __func__);
return;
const char *per;
const char *sunpriv;
- switch(family) {
+ switch (family) {
case AF_INET:
per = "-4";
break;
sunpriv = ifname ? ".unpriv" : "unpriv.";
else
sunpriv = "";
- return snprintf(path, len, CONTROLSOCKET,
- ifname ? ifname : "", ifname ? per : "",
- sunpriv, ifname ? "." : "");
+ return snprintf(path, len, CONTROLSOCKET, ifname ? ifname : "",
+ ifname ? per : "", sunpriv, ifname ? "." : "");
}
static int
return fd;
}
-#define S_PRIV (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP)
+#define S_PRIV (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP)
#define S_UNPRIV (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)
static int
if (bind(fd, (struct sockaddr *)&sa, len) == -1 ||
chmod(sa.sun_path, fmode) == -1 ||
(ctx->control_group &&
- chown(sa.sun_path, geteuid(), ctx->control_group) == -1) ||
- listen(fd, sizeof(ctx->control_fds)) == -1)
- {
+ chown(sa.sun_path, geteuid(), ctx->control_group) == -1) ||
+ listen(fd, sizeof(ctx->control_fds)) == -1) {
close(fd);
unlink(sa.sun_path);
return -1;
#ifdef PRIVSEP
if (IN_PRIVSEP_SE(ctx)) {
- make_path(ctx->control_sock, sizeof(ctx->control_sock),
- ifname, family, false);
+ make_path(ctx->control_sock, sizeof(ctx->control_sock), ifname,
+ family, false);
make_path(ctx->control_sock_unpriv,
- sizeof(ctx->control_sock_unpriv),
- ifname, family, true);
+ sizeof(ctx->control_sock_unpriv), ifname, family, true);
return 0;
}
#endif
return -1;
ctx->control_fd = fd;
- if (eloop_event_add(ctx->eloop, fd, ELE_READ,
- control_handle, ctx) == -1)
+ if (eloop_event_add(ctx->eloop, fd, ELE_READ, control_handle, ctx) ==
+ -1)
logerr("%s: eloop_event_add", __func__);
if ((fd = control_start1(ctx, ifname, family, S_UNPRIV)) != -1) {
ctx->control_unpriv_fd = fd;
if (eloop_event_add(ctx->eloop, fd, ELE_READ,
- control_handle_unpriv, ctx) == -1)
+ control_handle_unpriv, ctx) == -1)
logerr("%s: eloop_event_add", __func__);
}
return ctx->control_fd;
retval = (int)ps_root_unlink(ctx, file);
else
#else
- UNUSED(ctx);
+ UNUSED(ctx);
#endif
retval = unlink(file);
}
ssize_t
-control_send(struct dhcpcd_ctx *ctx, int argc, char * const *argv)
+control_send(struct dhcpcd_ctx *ctx, int argc, char *const *argv)
{
char buffer[1024];
int i;
#ifndef CONTROL_H
#define CONTROL_H
+#include <sys/socket.h>
+
#include <stdbool.h>
-#include "dhcpcd.h"
#include "queue.h"
#if !defined(CTL_FREE_LIST)
-#define CTL_FREE_LIST 1
+#define CTL_FREE_LIST 1
#elif CTL_FREE_LIST == 0
-#undef CTL_FREE_LIST
+#undef CTL_FREE_LIST
#endif
/* Limit queue size per fd */
-#define CONTROL_QUEUE_MAX 100
+#define CONTROL_QUEUE_MAX 100
struct fd_data {
TAILQ_ENTRY(fd_data) next;
};
TAILQ_HEAD(fd_list_head, fd_list);
-#define FD_LISTEN 0x01U
-#define FD_UNPRIV 0x02U
-#define FD_SENDLEN 0x04U
+#define FD_LISTEN 0x01U
+#define FD_UNPRIV 0x02U
+#define FD_SENDLEN 0x04U
int control_start(struct dhcpcd_ctx *, const char *, sa_family_t);
int control_stop(struct dhcpcd_ctx *);
int control_open(const char *, sa_family_t, bool);
-ssize_t control_send(struct dhcpcd_ctx *, int, char * const *);
+ssize_t control_send(struct dhcpcd_ctx *, int, char *const *);
struct fd_list *control_new(struct dhcpcd_ctx *, int, unsigned int);
void control_free(struct fd_list *);
void control_delete(struct fd_list *);
#ifndef DEFS_H
#define DEFS_H
-#define PACKAGE "dhcpcd"
-#define VERSION "10.3.2"
+#define PACKAGE "dhcpcd"
+#define VERSION "10.3.2"
#ifndef PRIVSEP_USER
-# define PRIVSEP_USER "_" PACKAGE
+#define PRIVSEP_USER "_" PACKAGE
#endif
#ifndef CONFIG
-# define CONFIG SYSCONFDIR "/" PACKAGE ".conf"
+#define CONFIG SYSCONFDIR "/" PACKAGE ".conf"
#endif
#ifndef SCRIPT
-# define SCRIPT LIBEXECDIR "/" PACKAGE "-run-hooks"
+#define SCRIPT LIBEXECDIR "/" PACKAGE "-run-hooks"
#endif
#ifndef DEVDIR
-# define DEVDIR LIBDIR "/" PACKAGE "/dev"
+#define DEVDIR LIBDIR "/" PACKAGE "/dev"
#endif
#ifndef DUID
-# define DUID DBDIR "/duid"
+#define DUID DBDIR "/duid"
#endif
#ifndef SECRET
-# define SECRET DBDIR "/secret"
+#define SECRET DBDIR "/secret"
#endif
#ifndef LEASEFILE
-# define LEASEFILE DBDIR "/%s%s.lease"
+#define LEASEFILE DBDIR "/%s%s.lease"
#endif
#ifndef LEASEFILE6
-# define LEASEFILE6 LEASEFILE "6"
+#define LEASEFILE6 LEASEFILE "6"
#endif
#ifndef PIDFILE
-# define PIDFILE RUNDIR "/%s%s%spid"
+#define PIDFILE RUNDIR "/%s%s%spid"
#endif
#ifndef CONTROLSOCKET
-# define CONTROLSOCKET RUNDIR "/%s%s%s%ssock"
+#define CONTROLSOCKET RUNDIR "/%s%s%s%ssock"
#endif
#ifndef RDM_MONOFILE
-# define RDM_MONOFILE DBDIR "/rdm_monotonic"
+#define RDM_MONOFILE DBDIR "/rdm_monotonic"
#endif
#ifndef NO_SIGNALS
-# define USE_SIGNALS
+#define USE_SIGNALS
#endif
#ifndef USE_SIGNALS
-# ifndef THERE_IS_NO_FORK
-# define THERE_IS_NO_FORK
-# endif
+#ifndef THERE_IS_NO_FORK
+#define THERE_IS_NO_FORK
+#endif
#endif
#endif
#define _INDEV
#include "common.h"
#include "dev.h"
-#include "eloop.h"
#include "dhcpcd.h"
+#include "eloop.h"
#include "logerr.h"
int
dev_initialised(struct dhcpcd_ctx *ctx, const char *ifname)
{
-
#ifdef PRIVSEP
if (ctx->options & DHCPCD_PRIVSEP &&
!(ctx->options & DHCPCD_PRIVSEPROOT))
int
dev_listening(struct dhcpcd_ctx *ctx)
{
-
#ifdef PRIVSEP
if (ctx->options & DHCPCD_PRIVSEP &&
!(ctx->options & DHCPCD_PRIVSEPROOT))
static void
dev_stop1(struct dhcpcd_ctx *ctx, int stop)
{
-
if (ctx->dev) {
if (stop)
logdebugx("dev: unloaded %s", ctx->dev->name);
void
dev_stop(struct dhcpcd_ctx *ctx)
{
-
dev_stop1(ctx, !(ctx->options & DHCPCD_FORKED));
}
return -1;
}
fptr(ctx->dev, dev_dhcpcd);
- if (ctx->dev->start == NULL || (r = ctx->dev->start()) == -1) {
+ if (ctx->dev->start == NULL || (r = ctx->dev->start()) == -1) {
free(ctx->dev);
ctx->dev = NULL;
dlclose(h);
ctx->dev_fd = dev_start1(ctx, &dev_dhcpcd);
if (ctx->dev_fd != -1) {
if (eloop_event_add(ctx->eloop, ctx->dev_fd, ELE_READ,
- dev_handle_data, ctx) == -1)
- {
+ dev_handle_data, ctx) == -1) {
logerr(__func__);
dev_stop1(ctx, 1);
return -1;
clean:
rm -f ${CLEANFILES}
+
+include ${TOP}/src//Makefile.inc
*/
#ifdef LIBUDEV_NOINIT
-# define LIBUDEV_I_KNOW_THE_API_IS_SUBJECT_TO_CHANGE
-# warning This version of udev is too old does not support
-# warning per device initialization checks.
-# warning As such, dhcpcd will need to depend on the
-# warning udev-settle service or similar if starting
-# warning in master mode.
+#define LIBUDEV_I_KNOW_THE_API_IS_SUBJECT_TO_CHANGE
+#warning This version of udev is too old does not support
+#warning per device initialization checks.
+#warning As such, dhcpcd will need to depend on the
+#warning udev-settle service or similar if starting
+#warning in master mode.
#endif
#include <libudev.h>
static int
udev_listening(void)
{
-
return monitor ? 1 : 0;
}
static void
udev_stop(void)
{
-
if (monitor) {
udev_monitor_unref(monitor);
monitor = NULL;
goto bad;
}
#ifndef LIBUDEV_NOFILTER
- if (udev_monitor_filter_add_match_subsystem_devtype(monitor,
- "net", NULL) != 0)
- {
+ if (udev_monitor_filter_add_match_subsystem_devtype(monitor, "net",
+ NULL) != 0) {
logerr("udev_monitor_filter_add_match_subsystem_devtype");
goto bad;
}
int
dev_init(struct dev *dev, const struct dev_dhcpcd *dev_dhcpcd)
{
-
dev->name = udev_name;
dev->initialised = udev_initialised;
dev->listening = udev_listening;
#include <string.h>
#include <unistd.h>
-#include "config.h"
-
#include "common.h"
+#include "config.h"
#include "dhcp-common.h"
#include "dhcp.h"
#include "if.h"
const char *
dhcp_get_hostname(char *buf, size_t buf_len, const struct if_options *ifo)
{
-
if (ifo->hostname[0] == '\0') {
if (gethostname(buf, buf_len) != 0)
return NULL;
strlcpy(buf, ifo->hostname, buf_len);
/* Deny sending of these local hostnames */
- if (buf[0] == '\0' || buf[0] == '.' ||
- strcmp(buf, "(none)") == 0 ||
+ if (buf[0] == '\0' || buf[0] == '.' || strcmp(buf, "(none)") == 0 ||
strcmp(buf, "localhost") == 0 ||
strncmp(buf, "localhost.", strlen("localhost.")) == 0)
return NULL;
void
dhcp_print_option_encoding(const struct dhcp_opt *opt, int cols)
{
-
while (cols < 40) {
putchar(' ');
cols++;
ifp = arg;
for (i = 0, opt = ifp->options->vivso_override;
- i < ifp->options->vivso_override_len;
- i++, opt++)
+ i < ifp->options->vivso_override_len; i++, opt++)
if (opt->option == iana_en)
return opt;
- for (i = 0, opt = ifp->ctx->vivso;
- i < ifp->ctx->vivso_len;
- i++, opt++)
+ for (i = 0, opt = ifp->ctx->vivso; i < ifp->ctx->vivso_len; i++, opt++)
if (opt->option == iana_en)
return opt;
return NULL;
int l;
if (uname(&utn) == -1)
- return (ssize_t)snprintf(str, len, "%s-%s",
- PACKAGE, VERSION);
+ return (ssize_t)snprintf(str, len, "%s-%s", PACKAGE, VERSION);
p = str;
- l = snprintf(p, len,
- "%s-%s:%s-%s:%s", PACKAGE, VERSION,
- utn.sysname, utn.release, utn.machine);
+ l = snprintf(p, len, "%s-%s:%s-%s:%s", PACKAGE, VERSION, utn.sysname,
+ utn.release, utn.machine);
if (l == -1 || (size_t)(l + 1) > len)
return -1;
p += l;
int
make_option_mask(const struct dhcp_opt *dopts, size_t dopts_len,
- const struct dhcp_opt *odopts, size_t odopts_len,
- uint8_t *mask, const char *opts, int add)
+ const struct dhcp_opt *odopts, size_t odopts_len, uint8_t *mask,
+ const char *opts, int add)
{
char *token, *o, *p;
const struct dhcp_opt *opt;
if (strcmp(opt->var, token) == 0)
match = 1;
else {
- n = (unsigned int)strtou(token, NULL, 0,
- 0, UINT_MAX, &e);
+ n = (unsigned int)strtou(token, NULL, 0, 0,
+ UINT_MAX, &e);
if (e == 0 && opt->option == n)
match = 1;
}
if (match == 0) {
for (i = 0, opt = dopts; i < dopts_len; i++, opt++) {
if (strcmp(opt->var, token) == 0)
- match = 1;
+ match = 1;
else {
n = (unsigned int)strtou(token, NULL, 0,
0, UINT_MAX, &e);
* combinations. */
errno = ENOTSUP;
return -1;
- }
- else if (ltype == 0xc0) { /* pointer */
+ } else if (ltype == 0xc0) { /* pointer */
if (q == e) {
errno = ERANGE;
return -1;
len = 0;
continue;
}
- if (((c == '-' || c == '_') &&
- !start && *lbl != ' ' && *lbl != '\0') ||
- isalnum(c))
- {
+ if (((c == '-' || c == '_') && !start && *lbl != ' ' &&
+ *lbl != '\0') ||
+ isalnum(c)) {
if (++len > NS_MAXLABEL) {
errno = ERANGE;
errset = true;
c = *data++;
if (type & OT_BINHEX) {
if (dst) {
- if (len == 0 || len == 1) {
+ if (len == 0 || len == 1) {
errno = ENOBUFS;
return -1;
}
break;
}
if (!(type & (OT_ASCII | OT_RAW | OT_ESCSTRING | OT_ESCFILE)) &&
- (!isascii(c) && !isprint(c)))
- {
+ (!isascii(c) && !isprint(c))) {
errno = EINVAL;
break;
}
break;
}
if ((type & (OT_ESCSTRING | OT_ESCFILE) &&
- (c == '\\' || !isascii(c) || !isprint(c))) ||
- (type & OT_ESCFILE && (c == '/' || c == ' ')))
- {
+ (c == '\\' || !isascii(c) || !isprint(c))) ||
+ (type & OT_ESCFILE && (c == '/' || c == ' '))) {
errno = EINVAL;
if (c == '\\') {
if (dst) {
- if (len == 0 || len == 1) {
+ if (len == 0 || len == 1) {
errno = ENOBUFS;
return -1;
}
- *dst++ = '\\'; *dst++ = '\\';
+ *dst++ = '\\';
+ *dst++ = '\\';
len -= 2;
}
bytes += 2;
return -1;
}
*dst++ = '\\';
- *dst++ = (char)(((c >> 6) & 03) + '0');
- *dst++ = (char)(((c >> 3) & 07) + '0');
- *dst++ = (char)(( c & 07) + '0');
+ *dst++ = (char)(((c >> 6) & 03) + '0');
+ *dst++ = (char)(((c >> 3) & 07) + '0');
+ *dst++ = (char)((c & 07) + '0');
len -= 4;
}
bytes += 4;
*odst = '\0';
return 1;
}
-
}
return (ssize_t)bytes;
}
-#define ADDR6SZ 16
+#define ADDR6SZ 16
static ssize_t
dhcp_optlen(const struct dhcp_opt *opt, size_t dl)
{
static ssize_t
print_option(FILE *fp, const char *prefix, const struct dhcp_opt *opt,
- int vname,
- const uint8_t *data, size_t dl, const char *ifname)
+ int vname, const uint8_t *data, size_t dl, const char *ifname)
{
fpos_t fp_pos;
const uint8_t *e, *t;
goto err;
}
- if (print_string(buf, sizeof(buf),
- opt->type, data, sz) == -1)
+ if (print_string(buf, sizeof(buf), opt->type, data,
+ sz) == -1)
goto err;
if (first)
/* bitflags are a string, MSB first, such as ABCDEFGH
* where A is 10000000, B is 01000000, etc. */
for (l = 0, sl = sizeof(opt->bitflags) - 1;
- l < sizeof(opt->bitflags);
- l++, sl--)
- {
+ l < sizeof(opt->bitflags); l++, sl--) {
if (opt->bitflags[l] == '1') {
if (fprintf(fp, "%d", *data & (1 << sl)) == -1)
goto err;
}
/* Don't print NULL or 0 flags */
if (opt->bitflags[l] != '\0' &&
- opt->bitflags[l] != '0' &&
- *data & (1 << sl))
- {
+ opt->bitflags[l] != '0' && *data & (1 << sl)) {
if (fputc(opt->bitflags[l], fp) == EOF)
goto err;
}
data += sizeof(addr.s_addr);
} else if (opt->type & OT_ADDRIPV6) {
uint8_t databuf[sizeof(struct in6_addr)] = { 0 };
- size_t datalen = e - data >= 16 ? 16 : (size_t)(e - data);
+ size_t datalen = e - data >= 16 ? 16 :
+ (size_t)(e - data);
char buf[INET6_ADDRSTRLEN];
/* avoid inet_ntop going beyond our option space by
* copying out into a temporary buffer. */
memcpy(databuf, data, datalen);
- if (inet_ntop(AF_INET6, databuf, buf, sizeof(buf)) == NULL)
+ if (inet_ntop(AF_INET6, databuf, buf, sizeof(buf)) ==
+ NULL)
goto err;
if (fprintf(fp, "%s", buf) == -1)
goto err;
if (data[0] == 0xfe && (data[1] & 0xc0) == 0x80) {
- if (fprintf(fp,"%%%s", ifname) == -1)
+ if (fprintf(fp, "%%%s", ifname) == -1)
goto err;
}
data += 16;
if (ifp->wireless) {
ssid[0] = '-';
- print_string(ssid + 1, sizeof(ssid) - 1,
- OT_ESCFILE,
+ print_string(ssid + 1, sizeof(ssid) - 1, OT_ESCFILE,
(const uint8_t *)ifp->ssid, ifp->ssid_len);
} else
ssid[0] = '\0';
return snprintf(leasefile, len,
- family == AF_INET ? LEASEFILE : LEASEFILE6,
- ifp->name, ssid);
+ family == AF_INET ? LEASEFILE : LEASEFILE6, ifp->name, ssid);
}
void
dhcp_envoption(struct dhcpcd_ctx *ctx, FILE *fp, const char *prefix,
const char *ifname, struct dhcp_opt *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 *(*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)
{
size_t i, eos, eol;
/* Create a new prefix based on the option */
if (opt->type & OT_INDEX) {
- if (asprintf(&pfx, "%s_%s%d",
- prefix, opt->var, ++opt->index) == -1)
+ if (asprintf(&pfx, "%s_%s%d", prefix, opt->var, ++opt->index) ==
+ -1)
pfx = NULL;
} else {
if (asprintf(&pfx, "%s_%s", prefix, opt->var) == -1)
eo = dhcp_optlen(eopt, ol);
if (eo == -1) {
logerrx("%s: %s %d.%d/%zu: "
- "malformed embedded option",
- ifname, __func__, opt->option,
- eopt->option, i);
+ "malformed embedded option",
+ ifname, __func__, opt->option, eopt->option, i);
goto out;
}
if (eo == 0) {
* option which is optional. */
if (ol != 0 || !(eopt->type & OT_OPTIONAL))
logerrx("%s: %s %d.%d/%zu: "
- "missing embedded option",
- ifname, __func__, opt->option,
- eopt->option, i);
+ "missing embedded option",
+ ifname, __func__, opt->option, eopt->option,
+ i);
goto out;
}
/* Use the option prefix if the embedded option
if (!(eopt->type & OT_RESERVED)) {
ov = strcmp(opt->var, eopt->var);
if (print_option(fp, pfx, eopt, ov, od, (size_t)eo,
- ifname) == -1)
- logerr("%s: %s %d.%d/%zu",
- ifname, __func__,
+ ifname) == -1)
+ logerr("%s: %s %d.%d/%zu", ifname, __func__,
opt->option, eopt->option, i);
}
od += (size_t)eo;
/* Zero any option indexes
* We assume that referenced encapsulated options are NEVER
* recursive as the index order could break. */
- for (i = 0, eopt = opt->encopts;
- i < opt->encopts_len;
- i++, eopt++)
- {
+ for (i = 0, eopt = opt->encopts; i < opt->encopts_len;
+ i++, eopt++) {
eoc = opt->option;
if (eopt->type & OT_OPTION) {
dgetopt(ctx, NULL, &eoc, NULL, NULL, 0, &oopt);
}
while ((eod = dgetopt(ctx, &eos, &eoc, &eol, od, ol, &oopt))) {
- for (i = 0, eopt = opt->encopts;
- i < opt->encopts_len;
- i++, eopt++)
- {
+ for (i = 0, eopt = opt->encopts; i < opt->encopts_len;
+ i++, eopt++) {
if (eopt->option != eoc)
continue;
if (eopt->type & OT_OPTION) {
continue;
}
dhcp_envoption(ctx, fp, pfx, ifname,
- eopt->type & OT_OPTION ? oopt:eopt,
+ eopt->type & OT_OPTION ? oopt : eopt,
dgetopt, eod, eol);
}
od += eos + eol;
ssize_t
dhcp_readfile(struct dhcpcd_ctx *ctx, const char *file, void *data, size_t len)
{
-
#ifdef PRIVSEP
if (ctx->options & DHCPCD_PRIVSEP &&
!(ctx->options & DHCPCD_PRIVSEPROOT))
dhcp_writefile(struct dhcpcd_ctx *ctx, const char *file, mode_t mode,
const void *data, size_t len)
{
-
#ifdef PRIVSEP
if (ctx->options & DHCPCD_PRIVSEP &&
!(ctx->options & DHCPCD_PRIVSEPROOT))
int
dhcp_filemtime(struct dhcpcd_ctx *ctx, const char *file, time_t *time)
{
-
#ifdef PRIVSEP
if (ctx->options & DHCPCD_PRIVSEP &&
!(ctx->options & DHCPCD_PRIVSEPROOT))
int
dhcp_unlink(struct dhcpcd_ctx *ctx, const char *file)
{
-
#ifdef PRIVSEP
if (ctx->options & DHCPCD_PRIVSEP &&
!(ctx->options & DHCPCD_PRIVSEPROOT))
*/
#ifndef DHCPCOMMON_H
-#define DHCPCOMMON_H
+#define DHCPCOMMON_H
-#include <arpa/inet.h>
#include <netinet/in.h>
-#include <stdint.h>
-
+#include <arpa/inet.h>
#include <arpa/nameser.h> /* after normal includes for sunos */
+#include <stdint.h>
#include "common.h"
#include "dhcpcd.h"
/* Support very old arpa/nameser.h as found in OpenBSD */
#ifndef NS_MAXDNAME
#define NS_MAXCDNAME MAXCDNAME
-#define NS_MAXDNAME MAXDNAME
-#define NS_MAXLABEL MAXLABEL
+#define NS_MAXDNAME MAXDNAME
+#define NS_MAXLABEL MAXLABEL
#endif
-#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)
-#define OT_URI (1 << 29)
-#define OT_TRUNCATED (1 << 30)
-
-#define DHC_REQ(r, n, o) \
+#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)
+#define OT_URI (1 << 29)
+#define OT_TRUNCATED (1 << 30)
+
+#define DHC_REQ(r, n, o) \
(has_option_mask((r), (o)) && !has_option_mask((n), (o)))
-#define DHC_REQOPT(o, r, n) \
- (!((o)->type & OT_NOREQ) && \
- ((o)->type & OT_REQUEST || has_option_mask((r), (o)->option)) && \
- !has_option_mask((n), (o)->option))
+#define DHC_REQOPT(o, r, n) \
+ (!((o)->type & OT_NOREQ) && \
+ ((o)->type & OT_REQUEST || has_option_mask((r), (o)->option)) && \
+ !has_option_mask((n), (o)->option))
struct dhcp_opt {
uint32_t option; /* Also used for IANA Enterpise Number */
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) \
+#define add_option_mask(var, val) \
((var)[(val) >> 3] = (uint8_t)((var)[(val) >> 3] | 1 << ((val) & 7)))
-#define del_option_mask(var, val) \
+#define del_option_mask(var, val) \
((var)[(val) >> 3] = (uint8_t)((var)[(val) >> 3] & ~(1 << ((val) & 7))))
-#define has_option_mask(var, val) \
+#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);
+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 *);
-void dhcp_envoption(struct dhcpcd_ctx *,
- FILE *, 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 **),
+void dhcp_envoption(struct dhcpcd_ctx *, FILE *, 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 *);
ssize_t dhcp_readfile(struct dhcpcd_ctx *, const char *, void *, size_t);
-ssize_t dhcp_writefile(struct dhcpcd_ctx *, const char *, mode_t,
- const void *, size_t);
+ssize_t dhcp_writefile(struct dhcpcd_ctx *, const char *, mode_t, const void *,
+ size_t);
int dhcp_filemtime(struct dhcpcd_ctx *, const char *, time_t *);
int dhcp_unlink(struct dhcpcd_ctx *, const char *);
size_t dhcp_read_hwaddr_aton(struct dhcpcd_ctx *, uint8_t **, const char *);
#include <sys/param.h>
#include <sys/socket.h>
-#include <arpa/inet.h>
#include <net/if.h>
#include <net/route.h>
-#include <netinet/if_ether.h>
-#include <netinet/in_systm.h>
#include <netinet/in.h>
+#include <netinet/in_systm.h>
#include <netinet/ip.h>
+#include <netinet/if_ether.h>
+
+#include <arpa/inet.h>
#define __FAVOR_BSD /* Nasty glibc hack so we can use BSD semantics for UDP */
#include <netinet/udp.h>
#undef __FAVOR_BSD
#ifdef AF_LINK
-# include <net/if_dl.h>
+#include <net/if_dl.h>
#endif
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <unistd.h>
#include <syslog.h>
+#include <unistd.h>
-#define ELOOP_QUEUE ELOOP_DHCP
-#include "config.h"
+#define ELOOP_QUEUE ELOOP_DHCP
#include "arp.h"
#include "bpf.h"
#include "common.h"
+#include "config.h"
+#include "dhcp-common.h"
#include "dhcp.h"
#include "dhcpcd.h"
-#include "dhcp-common.h"
#include "duid.h"
#include "eloop.h"
#include "if.h"
#include "sa.h"
#include "script.h"
-#define DAD "Duplicate address detected"
-#define DHCP_MIN_LEASE 20
+#define DAD "Duplicate address detected"
+#define DHCP_MIN_LEASE 20
-#define IPV4A ADDRIPV4 | ARRAY
-#define IPV4R ADDRIPV4 | REQUEST
+#define IPV4A ADDRIPV4 | ARRAY
+#define IPV4R ADDRIPV4 | REQUEST
/* We should define a maximum for the NAK exponential backoff */
-#define NAKOFF_MAX 60
+#define NAKOFF_MAX 60
#ifndef IPDEFTTL
#define IPDEFTTL 64 /* RFC1340 */
#endif
/* Assert the correct structure size for on wire */
-__CTASSERT(sizeof(struct ip) == 20);
-__CTASSERT(sizeof(struct udphdr) == 8);
-__CTASSERT(sizeof(struct bootp) == 300);
-#define IP_UDP_SIZE (sizeof(struct ip) + sizeof(struct udphdr))
-#define BOOTP_MIN_MTU (IP_UDP_SIZE + sizeof(struct bootp))
+__CTASSERT(sizeof(struct ip) == 20);
+__CTASSERT(sizeof(struct udphdr) == 8);
+__CTASSERT(sizeof(struct bootp) == 300);
+#define IP_UDP_SIZE (sizeof(struct ip) + sizeof(struct udphdr))
+#define BOOTP_MIN_MTU (IP_UDP_SIZE + sizeof(struct bootp))
struct dhcp_op {
uint8_t value;
const char *name;
};
-static const struct dhcp_op dhcp_ops[] = {
- { DHCP_DISCOVER, "DISCOVER" },
- { DHCP_OFFER, "OFFER" },
- { DHCP_REQUEST, "REQUEST" },
- { DHCP_DECLINE, "DECLINE" },
- { DHCP_ACK, "ACK" },
- { DHCP_NAK, "NAK" },
- { DHCP_RELEASE, "RELEASE" },
- { DHCP_INFORM, "INFORM" },
- { DHCP_FORCERENEW, "FORCERENEW"},
- { 0, NULL }
-};
+static const struct dhcp_op dhcp_ops[] = { { DHCP_DISCOVER, "DISCOVER" },
+ { DHCP_OFFER, "OFFER" }, { DHCP_REQUEST, "REQUEST" },
+ { DHCP_DECLINE, "DECLINE" }, { DHCP_ACK, "ACK" }, { DHCP_NAK, "NAK" },
+ { DHCP_RELEASE, "RELEASE" }, { DHCP_INFORM, "INFORM" },
+ { DHCP_FORCERENEW, "FORCERENEW" }, { 0, NULL } };
-static const char * const dhcp_params[] = {
- "ip_address",
- "subnet_cidr",
- "network_number",
- "filename",
- "server_name",
- NULL
-};
+static const char *const dhcp_params[] = { "ip_address", "subnet_cidr",
+ "network_number", "filename", "server_name", NULL };
static int dhcp_openbpf(struct interface *);
static void dhcp_start1(void *);
static int dhcp_initstate(struct interface *);
void
-dhcp_printoptions(const struct dhcpcd_ctx *ctx,
- const struct dhcp_opt *opts, size_t opts_len)
+dhcp_printoptions(const struct dhcpcd_ctx *ctx, const struct dhcp_opt *opts,
+ size_t opts_len)
{
- const char * const *p;
+ const char *const *p;
size_t i, j;
const struct dhcp_opt *opt, *opt2;
int cols;
}
static const uint8_t *
-get_option(struct dhcpcd_ctx *ctx,
- const struct bootp *bootp, size_t bootp_len,
+get_option(struct dhcpcd_ctx *ctx, const struct bootp *bootp, size_t bootp_len,
unsigned int opt, size_t *opt_len)
{
const uint8_t *p, *e;
uint8_t *nb;
if (bp)
- pos = (size_t)
- (bp - ctx->opt_buffer);
+ pos = (size_t)(bp -
+ ctx->opt_buffer);
else
pos = 0;
nb = realloc(ctx->opt_buffer, bl + l);
}
static int
-get_option_addr(struct dhcpcd_ctx *ctx,
- struct in_addr *a, const struct bootp *bootp, size_t bootp_len,
- uint8_t option)
+get_option_addr(struct dhcpcd_ctx *ctx, struct in_addr *a,
+ const struct bootp *bootp, size_t bootp_len, uint8_t option)
{
const uint8_t *p;
size_t len;
}
static int
-get_option_uint32(struct dhcpcd_ctx *ctx,
- uint32_t *i, const struct bootp *bootp, size_t bootp_len, uint8_t option)
+get_option_uint32(struct dhcpcd_ctx *ctx, uint32_t *i,
+ const struct bootp *bootp, size_t bootp_len, uint8_t option)
{
const uint8_t *p;
size_t len;
}
static int
-get_option_uint16(struct dhcpcd_ctx *ctx,
- uint16_t *i, const struct bootp *bootp, size_t bootp_len, uint8_t option)
+get_option_uint16(struct dhcpcd_ctx *ctx, uint16_t *i,
+ const struct bootp *bootp, size_t bootp_len, uint8_t option)
{
const uint8_t *p;
size_t len;
}
static int
-get_option_uint8(struct dhcpcd_ctx *ctx,
- uint8_t *i, const struct bootp *bootp, size_t bootp_len, uint8_t option)
+get_option_uint8(struct dhcpcd_ctx *ctx, uint8_t *i, const struct bootp *bootp,
+ size_t bootp_len, uint8_t option)
{
const uint8_t *p;
size_t len;
}
static int
-decode_rfc3442_rt(rb_tree_t *routes, struct interface *ifp,
- const uint8_t *data, size_t dl)
+decode_rfc3442_rt(rb_tree_t *routes, struct interface *ifp, const uint8_t *data,
+ size_t dl)
{
const uint8_t *p = data;
const uint8_t *e;
break;
}
addr.s_addr = INADDR_BROADCAST;
- for (;
- dl != 0;
- data += sizeof(addr.s_addr), dl -= sizeof(addr.s_addr))
- {
+ for (; dl != 0;
+ data += sizeof(addr.s_addr), dl -= sizeof(addr.s_addr)) {
memcpy(&addr.s_addr, data, sizeof(addr.s_addr));
if (fprintf(fp, "%s", inet_ntoa(addr)) == -1)
return -1;
}
static char *
-get_option_string(struct dhcpcd_ctx *ctx,
- const struct bootp *bootp, size_t bootp_len, uint8_t option)
+get_option_string(struct dhcpcd_ctx *ctx, const struct bootp *bootp,
+ size_t bootp_len, uint8_t option)
{
size_t len;
const uint8_t *p;
state = D_CSTATE(ifp);
if (!(ifo->options & DHCPCD_CSR_WARNED) &&
- !(state->added & STATE_FAKE))
- {
+ !(state->added & STATE_FAKE)) {
logdebugx("%s: using %sClassless Static Routes",
ifp->name, csr);
ifo->options |= DHCPCD_CSR_WARNED;
n = 0;
/* OK, get our static routes first. */
if (!has_option_mask(ifo->nomask, DHO_STATICROUTE))
- p = get_option(ifp->ctx, bootp, bootp_len,
- DHO_STATICROUTE, &len);
+ p = get_option(ifp->ctx, bootp, bootp_len, DHO_STATICROUTE,
+ &len);
else
p = NULL;
/* RFC 2131 Section 5.8 states length MUST be in multiples of 8 */
/* A on-link host route is normally set by having the
* gateway match the destination or assigned address */
if (gateway.s_addr == dest.s_addr ||
- (gateway.s_addr == bootp->yiaddr ||
- gateway.s_addr == bootp->ciaddr))
- {
+ (gateway.s_addr == bootp->yiaddr ||
+ gateway.s_addr == bootp->ciaddr)) {
gateway.s_addr = INADDR_ANY;
netmask.s_addr = INADDR_BROADCAST;
} else
mtu = 0; /* bogus gcc warning */
if ((state = D_CSTATE(ifp)) == NULL ||
has_option_mask(ifp->options->nomask, DHO_MTU) ||
- get_option_uint16(ifp->ctx, &mtu,
- state->new, state->new_len, DHO_MTU) == -1)
+ get_option_uint16(ifp->ctx, &mtu, state->new, state->new_len,
+ DHO_MTU) == -1)
return 0;
if (mtu < IPV4_MMTU)
return IPV4_MMTU;
/* Assumes DHCP options */
static int
-dhcp_message_add_addr(struct bootp *bootp,
- uint8_t type, struct in_addr addr)
+dhcp_message_add_addr(struct bootp *bootp, uint8_t type, struct in_addr addr)
{
uint8_t *p;
size_t len;
static ssize_t
rfc3396_write_byte(struct rfc3396_ctx *ctx, uint8_t byte)
{
-
return rfc3396_write(ctx, &byte, sizeof(byte));
}
static uint8_t *
-rfc3396_zero(struct rfc3396_ctx *ctx) {
+rfc3396_zero(struct rfc3396_ctx *ctx)
+{
uint8_t *zerop = *ctx->buf, zero = 0;
if (rfc3396_write(ctx, &zero, sizeof(zero)) == -1)
return -1;
}
if ((size_t)mtu < BOOTP_MIN_MTU) {
- logerr("%s: interface mtu is too small (%d<%zu)",
- ifp->name, mtu, BOOTP_MIN_MTU);
+ logerr("%s: interface mtu is too small (%d<%zu)", ifp->name,
+ mtu, BOOTP_MIN_MTU);
return -1;
}
if (state->addr != NULL &&
(type == DHCP_INFORM || type == DHCP_RELEASE ||
- (type == DHCP_REQUEST &&
- state->addr->mask.s_addr == lease->mask.s_addr &&
- (state->new == NULL || IS_DHCP(state->new)) &&
- !(state->added & (STATE_FAKE | STATE_EXPIRED)))))
+ (type == DHCP_REQUEST &&
+ state->addr->mask.s_addr == lease->mask.s_addr &&
+ (state->new == NULL || IS_DHCP(state->new)) &&
+ !(state->added & (STATE_FAKE | STATE_EXPIRED)))))
bootp->ciaddr = state->addr->addr.s_addr;
bootp->op = BOOTREQUEST;
memcpy(&bootp->chaddr, &ifp->hwaddr, ifp->hwlen);
}
- if (ifo->options & DHCPCD_BROADCAST &&
- bootp->ciaddr == INADDR_ANY &&
- type != DHCP_DECLINE &&
- type != DHCP_RELEASE)
+ if (ifo->options & DHCPCD_BROADCAST && bootp->ciaddr == INADDR_ANY &&
+ type != DHCP_DECLINE && type != DHCP_RELEASE)
bootp->flags = htons(BROADCAST_FLAG);
if (type != DHCP_DECLINE && type != DHCP_RELEASE) {
return sizeof(*bootp);
p = bootp->vend;
- e = (uint8_t *)bootp + ((size_t)mtu - IP_UDP_SIZE - 1/* DHO_END */);
+ e = (uint8_t *)bootp + ((size_t)mtu - IP_UDP_SIZE - 1 /* DHO_END */);
ul = htonl(MAGIC_COOKIE);
memcpy(p, &ul, sizeof(ul));
p += sizeof(ul);
-#define AREA_LEFT (size_t)(e - p)
-#define AREA_FIT(s) if ((s) > AREA_LEFT) goto toobig
-#define AREA_CHECK(s) if ((s) + 2UL > AREA_LEFT) goto toobig
-#define PUT_ADDR(o, a) do { \
- AREA_CHECK(4); \
- *p++ = (o); \
- *p++ = 4; \
- memcpy(p, &(a)->s_addr, 4); \
- p += 4; \
-} while (0 /* CONSTCOND */)
+#define AREA_LEFT (size_t)(e - p)
+#define AREA_FIT(s) \
+ if ((s) > AREA_LEFT) \
+ goto toobig
+#define AREA_CHECK(s) \
+ if ((s) + 2UL > AREA_LEFT) \
+ goto toobig
+#define PUT_ADDR(o, a) \
+ do { \
+ AREA_CHECK(4); \
+ *p++ = (o); \
+ *p++ = 4; \
+ memcpy(p, &(a)->s_addr, 4); \
+ p += 4; \
+ } while (0 /* CONSTCOND */)
/*
* RFC 7844 3.1 says options should be randomised, but if not
if (lease->addr.s_addr && lease->cookie == htonl(MAGIC_COOKIE)) {
if (type == DHCP_DECLINE ||
(type == DHCP_REQUEST &&
- (state->addr == NULL ||
- state->added & (STATE_FAKE | STATE_EXPIRED) ||
- lease->addr.s_addr != state->addr->addr.s_addr)))
- {
+ (state->addr == NULL ||
+ state->added & (STATE_FAKE | STATE_EXPIRED) ||
+ lease->addr.s_addr != state->addr->addr.s_addr))) {
putip = true;
PUT_ADDR(DHO_IPADDRESS, &lease->addr);
}
}
}
-#define DHCP_DIR(type) ((type) == DHCP_DISCOVER || (type) == DHCP_INFORM || \
- (type) == DHCP_REQUEST)
+#define DHCP_DIR(type) \
+ ((type) == DHCP_DISCOVER || (type) == DHCP_INFORM || \
+ (type) == DHCP_REQUEST)
if (DHCP_DIR(type)) {
/* vendor is already encoded correctly, so just add it */
n_params = p;
*p++ = 0;
for (i = 0, opt = ifp->ctx->dhcp_opts;
- i < ifp->ctx->dhcp_opts_len;
- i++, opt++)
- {
+ i < ifp->ctx->dhcp_opts_len; i++, opt++) {
if (!DHC_REQOPT(opt, ifo->requestmask, ifo->nomask))
continue;
if (type == DHCP_INFORM &&
*p++ = (uint8_t)opt->option;
}
for (i = 0, opt = ifo->dhcp_override;
- i < ifo->dhcp_override_len;
- i++, opt++)
- {
+ i < ifo->dhcp_override_len; i++, opt++) {
/* Check if added above */
for (lp = n_params + 1; lp < p; lp++)
if (*lp == (uint8_t)opt->option)
*n_params = (uint8_t)(p - n_params - 1);
if (mtu != -1 &&
- !(has_option_mask(ifo->nomask, DHO_MAXMESSAGESIZE)))
- {
+ !(has_option_mask(ifo->nomask, DHO_MAXMESSAGESIZE))) {
AREA_CHECK(2);
*p++ = DHO_MAXMESSAGESIZE;
*p++ = 2;
}
if (ifo->userclass[0] &&
- !has_option_mask(ifo->nomask, DHO_USERCLASS))
- {
+ !has_option_mask(ifo->nomask, DHO_USERCLASS)) {
AREA_CHECK(ifo->userclass[0]);
*p++ = DHO_USERCLASS;
memcpy(p, ifo->userclass,
if (DHCP_DIR(type) &&
!has_option_mask(ifo->nomask, DHO_VENDORCLASSID) &&
- ifo->vendorclassid[0])
- {
+ ifo->vendorclassid[0]) {
AREA_CHECK(ifo->vendorclassid[0]);
*p++ = DHO_VENDORCLASSID;
- memcpy(p, ifo->vendorclassid, (size_t)ifo->vendorclassid[0]+1);
+ memcpy(p, ifo->vendorclassid,
+ (size_t)ifo->vendorclassid[0] + 1);
p += ifo->vendorclassid[0] + 1;
}
- if (type == DHCP_DISCOVER &&
- !(ifp->ctx->options & DHCPCD_TEST) &&
- DHC_REQ(ifo->requestmask, ifo->nomask, DHO_RAPIDCOMMIT))
- {
+ if (type == DHCP_DISCOVER && !(ifp->ctx->options & DHCPCD_TEST) &&
+ DHC_REQ(ifo->requestmask, ifo->nomask, DHO_RAPIDCOMMIT)) {
/* RFC 4039 Section 3 */
AREA_CHECK(0);
*p++ = DHO_RAPIDCOMMIT;
}
#ifdef AUTH
- auth = NULL; /* appease GCC */
+ auth = NULL; /* appease GCC */
auth_len = 0;
if (ifo->auth.options & DHCPCD_AUTH_SEND) {
ssize_t alen = dhcp_auth_encode(ifp->ctx, &ifo->auth,
- state->auth.token,
- NULL, 0, 4, type, NULL, 0);
+ state->auth.token, NULL, 0, 4, type, NULL, 0);
if (alen != -1 && alen > UINT8_MAX) {
errno = ERANGE;
alen = -1;
/* RFC 2563 Auto Configure */
if (type == DHCP_DISCOVER && ifo->options & DHCPCD_IPV4LL &&
- !(has_option_mask(ifo->nomask, DHO_AUTOCONFIGURE)))
- {
+ !(has_option_mask(ifo->nomask, DHO_AUTOCONFIGURE))) {
AREA_CHECK(1);
*p++ = DHO_AUTOCONFIGURE;
*p++ = 1;
if (DHCP_DIR(type)) {
if (ifo->mudurl[0]) {
- AREA_CHECK(ifo->mudurl[0]);
- *p++ = DHO_MUDURL;
- memcpy(p, ifo->mudurl, (size_t)ifo->mudurl[0] + 1);
- p += ifo->mudurl[0] + 1;
+ AREA_CHECK(ifo->mudurl[0]);
+ *p++ = DHO_MUDURL;
+ memcpy(p, ifo->mudurl, (size_t)ifo->mudurl[0] + 1);
+ p += ifo->mudurl[0] + 1;
}
#ifndef SMALL
if (ifo->vivco_len &&
- !has_option_mask(ifo->nomask, DHO_VIVCO))
- {
+ !has_option_mask(ifo->nomask, DHO_VIVCO)) {
struct vivco *vivco = ifo->vivco;
size_t vlen = ifo->vivco_len;
struct rfc3396_ctx rctx = {
if (lp == NULL)
goto toobig;
if (rfc3396_write_byte(&rctx,
- (uint8_t)vivco->len) == -1)
+ (uint8_t)vivco->len) == -1)
goto toobig;
- if (rfc3396_write(&rctx,
- vivco->data, vivco->len) == -1)
+ if (rfc3396_write(&rctx, vivco->data,
+ vivco->len) == -1)
goto toobig;
*lp = (uint8_t)(*lp + vivco->len + 1);
}
}
-
- if (ifo->vsio_len &&
- !has_option_mask(ifo->nomask, DHO_VIVSO))
- {
+
+ if (ifo->vsio_len && !has_option_mask(ifo->nomask, DHO_VIVSO)) {
struct vsio *vso = ifo->vsio;
size_t vlen = ifo->vsio_len;
struct vsio_so *so;
for (; slen > 0; so++, slen--) {
if (rfc3396_write_byte(&rctx,
- (uint8_t)so->opt) == -1)
+ (uint8_t)so->opt) == -1)
goto toobig;
if (rfc3396_write_byte(&rctx,
- (uint8_t)so->len) == -1)
+ (uint8_t)so->len) == -1)
goto toobig;
- if (rfc3396_write(&rctx,
- so->data, so->len) == -1)
+ if (rfc3396_write(&rctx, so->data,
+ so->len) == -1)
goto toobig;
*lp = (uint8_t)(*lp + so->len + 2);
}
#ifdef AUTH
if ((ifo->auth.options & DHCPCD_AUTH_SENDREQUIRE) !=
- DHCPCD_AUTH_SENDREQUIRE &&
- !has_option_mask(ifo->nomask, DHO_FORCERENEW_NONCE))
- {
+ DHCPCD_AUTH_SENDREQUIRE &&
+ !has_option_mask(ifo->nomask, DHO_FORCERENEW_NONCE)) {
/* We support HMAC-MD5 */
AREA_CHECK(1);
*p++ = DHO_FORCERENEW_NONCE;
logdebugx("reading standard input");
sbytes = read(fileno(stdin), buf.buf, sizeof(buf.buf));
} else {
- logdebugx("%s: reading lease: %s",
- ifp->name, state->leasefile);
- sbytes = dhcp_readfile(ifp->ctx, state->leasefile,
- buf.buf, sizeof(buf.buf));
+ logdebugx("%s: reading lease: %s", ifp->name, state->leasefile);
+ sbytes = dhcp_readfile(ifp->ctx, state->leasefile, buf.buf,
+ sizeof(buf.buf));
}
if (sbytes == -1) {
if (errno != ENOENT)
/* We may have found a BOOTP server */
if (get_option_uint8(ifp->ctx, &type, &buf.bootp, bytes,
- DHO_MESSAGETYPE) == -1)
+ DHO_MESSAGETYPE) == -1)
type = 0;
#ifdef AUTH
/* Authenticate the message */
- auth = get_option(ifp->ctx, &buf.bootp, bytes,
- DHO_AUTHENTICATION, &auth_len);
+ auth = get_option(ifp->ctx, &buf.bootp, bytes, DHO_AUTHENTICATION,
+ &auth_len);
if (auth) {
if (dhcp_auth_validate(&state->auth, &ifp->options->auth,
- &buf.bootp, bytes, 4, type, auth, auth_len) == NULL)
- {
+ &buf.bootp, bytes, 4, type, auth, auth_len) == NULL) {
logerr("%s: authentication failed", ifp->name);
return 0;
}
if (state->auth.token)
- logdebugx("%s: validated using 0x%08" PRIu32,
- ifp->name, state->auth.token->secretid);
+ logdebugx("%s: validated using 0x%08" PRIu32, ifp->name,
+ state->auth.token->secretid);
else
logdebugx("%s: accepted reconfigure key", ifp->name);
} else if ((ifp->options->auth.options & DHCPCD_AUTH_SENDREQUIRE) ==
- DHCPCD_AUTH_SENDREQUIRE)
- {
+ DHCPCD_AUTH_SENDREQUIRE) {
logerrx("%s: authentication now required", ifp->name);
return 0;
}
size_t i;
const struct dhcp_opt *opt;
- for (i = 0, opt = ifo->dhcp_override;
- i < ifo->dhcp_override_len;
- i++, opt++)
- {
+ for (i = 0, opt = ifo->dhcp_override; i < ifo->dhcp_override_len;
+ i++, opt++) {
if (opt->option == o)
return opt;
}
}
static const uint8_t *
-dhcp_getoption(struct dhcpcd_ctx *ctx,
- size_t *os, unsigned int *code, size_t *len,
- const uint8_t *od, size_t ol, struct dhcp_opt **oopt)
+dhcp_getoption(struct dhcpcd_ctx *ctx, size_t *os, unsigned int *code,
+ size_t *len, const uint8_t *od, size_t ol, struct dhcp_opt **oopt)
{
size_t i;
struct dhcp_opt *opt;
ifo = ifp->options;
if (get_option_uint8(ifp->ctx, &overl, bootp, bootp_len,
- DHO_OPTSOVERLOADED) == -1)
+ DHO_OPTSOVERLOADED) == -1)
overl = 0;
if (bootp->yiaddr || bootp->ciaddr) {
/* Set some useful variables that we derive from the DHCP
* message but are not necessarily in the options */
addr.s_addr = bootp->yiaddr ? bootp->yiaddr : bootp->ciaddr;
- if (efprintf(fenv, "%s_ip_address=%s",
- prefix, inet_ntoa(addr)) == -1)
+ if (efprintf(fenv, "%s_ip_address=%s", prefix,
+ inet_ntoa(addr)) == -1)
return -1;
- if (get_option_addr(ifp->ctx, &net,
- bootp, bootp_len, DHO_SUBNETMASK) == -1) {
+ if (get_option_addr(ifp->ctx, &net, bootp, bootp_len,
+ DHO_SUBNETMASK) == -1) {
net.s_addr = ipv4_getnetmask(addr.s_addr);
- if (efprintf(fenv, "%s_subnet_mask=%s",
- prefix, inet_ntoa(net)) == -1)
+ if (efprintf(fenv, "%s_subnet_mask=%s", prefix,
+ inet_ntoa(net)) == -1)
return -1;
}
- if (efprintf(fenv, "%s_subnet_cidr=%d",
- prefix, inet_ntocidr(net))== -1)
+ if (efprintf(fenv, "%s_subnet_cidr=%d", prefix,
+ inet_ntocidr(net)) == -1)
return -1;
- if (get_option_addr(ifp->ctx, &brd,
- bootp, bootp_len, DHO_BROADCAST) == -1)
- {
+ if (get_option_addr(ifp->ctx, &brd, bootp, bootp_len,
+ DHO_BROADCAST) == -1) {
brd.s_addr = addr.s_addr | ~net.s_addr;
- if (efprintf(fenv, "%s_broadcast_address=%s",
- prefix, inet_ntoa(brd)) == -1)
+ if (efprintf(fenv, "%s_broadcast_address=%s", prefix,
+ inet_ntoa(brd)) == -1)
return -1;
}
addr.s_addr = bootp->yiaddr & net.s_addr;
- if (efprintf(fenv, "%s_network_number=%s",
- prefix, inet_ntoa(addr)) == -1)
+ if (efprintf(fenv, "%s_network_number=%s", prefix,
+ inet_ntoa(addr)) == -1)
return -1;
}
if (*bootp->file && !(overl & 1)) {
- print_string(safe, sizeof(safe), OT_STRING,
- bootp->file, sizeof(bootp->file));
+ print_string(safe, sizeof(safe), OT_STRING, bootp->file,
+ sizeof(bootp->file));
if (efprintf(fenv, "%s_filename=%s", prefix, safe) == -1)
return -1;
}
}
/* Zero our indexes */
- for (i = 0, opt = ifp->ctx->dhcp_opts;
- i < ifp->ctx->dhcp_opts_len;
+ for (i = 0, opt = ifp->ctx->dhcp_opts; i < ifp->ctx->dhcp_opts_len;
i++, opt++)
dhcp_zero_index(opt);
for (i = 0, opt = ifp->options->dhcp_override;
- i < ifp->options->dhcp_override_len;
- i++, opt++)
+ i < ifp->options->dhcp_override_len; i++, opt++)
dhcp_zero_index(opt);
- for (i = 0, opt = ifp->ctx->vivso;
- i < ifp->ctx->vivso_len;
- i++, opt++)
+ for (i = 0, opt = ifp->ctx->vivso; i < ifp->ctx->vivso_len; i++, opt++)
dhcp_zero_index(opt);
- for (i = 0, opt = ifp->ctx->dhcp_opts;
- i < ifp->ctx->dhcp_opts_len;
- i++, opt++)
- {
+ for (i = 0, opt = ifp->ctx->dhcp_opts; i < ifp->ctx->dhcp_opts_len;
+ i++, opt++) {
if (has_option_mask(ifo->nomask, opt->option))
continue;
if (dhcp_getoverride(ifo, opt->option))
p = get_option(ifp->ctx, bootp, bootp_len, opt->option, &pl);
if (p == NULL)
continue;
- dhcp_envoption(ifp->ctx, fenv, prefix, ifp->name,
- opt, dhcp_getoption, p, pl);
+ dhcp_envoption(ifp->ctx, fenv, prefix, ifp->name, opt,
+ dhcp_getoption, p, pl);
if (opt->option != DHO_VIVSO || pl <= (int)sizeof(uint32_t))
continue;
/* Skip over en + total size */
p += sizeof(en) + 1;
pl -= sizeof(en) + 1;
- dhcp_envoption(ifp->ctx, fenv, prefix, ifp->name,
- vo, dhcp_getoption, p, pl);
+ dhcp_envoption(ifp->ctx, fenv, prefix, ifp->name, vo,
+ dhcp_getoption, p, pl);
}
- for (i = 0, opt = ifo->dhcp_override;
- i < ifo->dhcp_override_len;
- i++, opt++)
- {
+ for (i = 0, opt = ifo->dhcp_override; i < ifo->dhcp_override_len;
+ i++, opt++) {
if (has_option_mask(ifo->nomask, opt->option))
continue;
p = get_option(ifp->ctx, bootp, bootp_len, opt->option, &pl);
if (p == NULL)
continue;
- dhcp_envoption(ifp->ctx, fenv, prefix, ifp->name,
- opt, dhcp_getoption, p, pl);
+ dhcp_envoption(ifp->ctx, fenv, prefix, ifp->name, opt,
+ dhcp_getoption, p, pl);
}
return 1;
}
static void
-get_lease(struct interface *ifp,
- struct dhcp_lease *lease, const struct bootp *bootp, size_t len)
+get_lease(struct interface *ifp, struct dhcp_lease *lease,
+ const struct bootp *bootp, size_t len)
{
struct dhcpcd_ctx *ctx;
if (ifp->options->req_brd.s_addr != INADDR_ANY)
lease->brd = ifp->options->req_brd;
else
- lease->brd.s_addr =
- lease->addr.s_addr | ~lease->mask.s_addr;
+ lease->brd.s_addr = lease->addr.s_addr |
+ ~lease->mask.s_addr;
} else {
const struct ipv4_addr *ia;
ia = ipv4_iffindaddr(ifp, &lease->addr, NULL);
if (ia == NULL) {
- lease->mask.s_addr =
- ipv4_getnetmask(lease->addr.s_addr);
- lease->brd.s_addr =
- lease->addr.s_addr | ~lease->mask.s_addr;
+ lease->mask.s_addr = ipv4_getnetmask(
+ lease->addr.s_addr);
+ lease->brd.s_addr = lease->addr.s_addr |
+ ~lease->mask.s_addr;
} else {
lease->mask = ia->mask;
lease->brd = ia->brd;
}
} else {
if (get_option_addr(ctx, &lease->mask, bootp, len,
- DHO_SUBNETMASK) == -1)
- lease->mask.s_addr =
- ipv4_getnetmask(lease->addr.s_addr);
+ DHO_SUBNETMASK) == -1)
+ lease->mask.s_addr = ipv4_getnetmask(
+ lease->addr.s_addr);
if (get_option_addr(ctx, &lease->brd, bootp, len,
- DHO_BROADCAST) == -1)
- lease->brd.s_addr =
- lease->addr.s_addr | ~lease->mask.s_addr;
+ DHO_BROADCAST) == -1)
+ lease->brd.s_addr = lease->addr.s_addr |
+ ~lease->mask.s_addr;
}
- if (get_option_uint32(ctx, &lease->leasetime,
- bootp, len, DHO_LEASETIME) != 0)
+ if (get_option_uint32(ctx, &lease->leasetime, bootp, len,
+ DHO_LEASETIME) != 0)
lease->leasetime = DHCP_INFINITE_LIFETIME;
- if (get_option_uint32(ctx, &lease->renewaltime,
- bootp, len, DHO_RENEWALTIME) != 0)
+ if (get_option_uint32(ctx, &lease->renewaltime, bootp, len,
+ DHO_RENEWALTIME) != 0)
lease->renewaltime = 0;
- if (get_option_uint32(ctx, &lease->rebindtime,
- bootp, len, DHO_REBINDTIME) != 0)
+ if (get_option_uint32(ctx, &lease->rebindtime, bootp, len,
+ DHO_REBINDTIME) != 0)
lease->rebindtime = 0;
if (get_option_addr(ctx, &lease->server, bootp, len, DHO_SERVERID) != 0)
lease->server.s_addr = INADDR_ANY;
(ifp->hwaddr + ifp->hwlen) - sizeof(state->xid),
sizeof(state->xid));
else {
-again:
+ again:
state->xid = arc4random();
}
}
if (ifp1 != NULL) {
if (ifp->options->options & DHCPCD_XID_HWADDR &&
- ifp->hwlen >= sizeof(state->xid))
- {
- logerrx("%s: duplicate xid on %s",
- ifp->name, ifp1->name);
- return;
+ ifp->hwlen >= sizeof(state->xid)) {
+ logerrx("%s: duplicate xid on %s", ifp->name,
+ ifp1->name);
+ return;
}
goto again;
}
static struct bootp_pkt *
dhcp_makeudppacket(size_t *sz, const uint8_t *data, size_t length,
- struct in_addr source, struct in_addr dest)
+ struct in_addr source, struct in_addr dest)
{
struct bootp_pkt *udpp;
struct ip *ip;
#endif
};
struct udphdr udp = {
- .uh_sport = htons(BOOTPC),
- .uh_dport = htons(BOOTPS),
- .uh_ulen = htons((uint16_t)(sizeof(udp) + len)),
+ .uh_sport = htons(BOOTPC),
+ .uh_dport = htons(BOOTPS),
+ .uh_ulen = htons((uint16_t)(sizeof(udp) + len)),
};
struct iovec iov[] = {
- { .iov_base = &udp, .iov_len = sizeof(udp), },
- { .iov_base = data, .iov_len = len, },
+ {
+ .iov_base = &udp,
+ .iov_len = sizeof(udp),
+ },
+ {
+ .iov_base = data,
+ .iov_len = len,
+ },
};
struct msghdr msg = {
.msg_name = (void *)&sin,
}
static void
-send_message(struct interface *ifp, uint8_t type,
- void (*callback)(void *))
+send_message(struct interface *ifp, uint8_t type, void (*callback)(void *))
{
struct dhcp_state *state = D_STATE(ifp);
struct if_options *ifo = ifp->options;
/* No carrier? Don't bother sending the packet. */
if (!if_is_link_up(ifp))
return;
- logdebugx("%s: sending %s with xid 0x%x",
- ifp->name,
+ logdebugx("%s: sending %s with xid 0x%x", ifp->name,
ifo->options & DHCPCD_BOOTP ? "BOOTP" : get_dhcp_op(type),
state->xid);
RT = 0; /* bogus gcc warning */
logdebugx("%s: sending %s (xid 0x%x), next in %0.1f seconds",
ifp->name,
ifo->options & DHCPCD_BOOTP ? "BOOTP" : get_dhcp_op(type),
- state->xid,
- (float)RT / MSEC_PER_SEC);
+ state->xid, (float)RT / MSEC_PER_SEC);
}
r = make_message(&bootp, ifp, type);
* stopping the interface. */
if (r == -1) {
logerr("%s: bpf_send", ifp->name);
- switch(errno) {
+ switch (errno) {
case ENETDOWN:
case ENETRESET:
case ENETUNREACH:
default:
if (!(ifp->ctx->options & DHCPCD_TEST))
dhcp_drop(ifp, "FAIL");
- eloop_timeout_delete(ifp->ctx->eloop,
- NULL, ifp);
+ eloop_timeout_delete(ifp->ctx->eloop, NULL, ifp);
callback = NULL;
}
}
static void
send_inform(void *arg)
{
-
send_message((struct interface *)arg, DHCP_INFORM, send_inform);
}
static void
send_discover(void *arg)
{
-
send_message((struct interface *)arg, DHCP_DISCOVER, send_discover);
}
static void
send_request(void *arg)
{
-
send_message((struct interface *)arg, DHCP_REQUEST, send_request);
}
static void
send_renew(void *arg)
{
-
send_message((struct interface *)arg, DHCP_REQUEST, send_renew);
}
static void
send_rebind(void *arg)
{
-
send_message((struct interface *)arg, DHCP_REQUEST, send_rebind);
}
ifo->fallback_time, dhcp_fallback, ifp);
#ifdef IPV4LL
else if (ifo->options & DHCPCD_IPV4LL)
- eloop_timeout_add_sec(ifp->ctx->eloop,
- ifo->ipv4ll_time, ipv4ll_start, ifp);
+ eloop_timeout_add_sec(ifp->ctx->eloop, ifo->ipv4ll_time,
+ ipv4ll_start, ifp);
#endif
}
if (ifo->options & DHCPCD_REQUEST)
loginfox("%s: soliciting a DHCP lease (requesting %s)",
ifp->name, inet_ntoa(ifo->req_addr));
else
- loginfox("%s: soliciting a %s lease",
- ifp->name, ifo->options & DHCPCD_BOOTP ? "BOOTP" : "DHCP");
+ loginfox("%s: soliciting a %s lease", ifp->name,
+ ifo->options & DHCPCD_BOOTP ? "BOOTP" : "DHCP");
send_discover(ifp);
}
return;
/* Only renew in the bound or renew states */
- if (state->state != DHS_BOUND &&
- state->state != DHS_RENEW)
+ if (state->state != DHS_BOUND && state->state != DHS_RENEW)
return;
/* Remove the timeout as the renew may have been forced. */
void
dhcp_renew(struct interface *ifp)
{
-
dhcp_startrenew(ifp);
}
struct dhcp_lease *lease = &state->lease;
logwarnx("%s: failed to renew DHCP, rebinding", ifp->name);
- logdebugx("%s: expire in %"PRIu32" seconds",
- ifp->name, lease->leasetime - lease->rebindtime);
+ logdebugx("%s: expire in %" PRIu32 " seconds", ifp->name,
+ lease->leasetime - lease->rebindtime);
state->state = DHS_REBIND;
eloop_timeout_delete(ifp->ctx->eloop, send_renew, ifp);
state->lease.server.s_addr = INADDR_ANY;
state->interval = 0;
- ifp->options->options &= ~(DHCPCD_CSR_WARNED |
- DHCPCD_ROUTER_HOST_ROUTE_WARNED);
+ ifp->options->options &= ~(
+ DHCPCD_CSR_WARNED | DHCPCD_ROUTER_HOST_ROUTE_WARNED);
send_rebind(ifp);
}
#ifdef IPV4LL
/* Stop IPv4LL now we have a working DHCP address */
- if ((!IN_LINKLOCAL(ntohl(ia->s_addr)))
- && (ifp->options->options & DHCPCD_IPV4LL))
+ if ((!IN_LINKLOCAL(ntohl(ia->s_addr))) &&
+ (ifp->options->options & DHCPCD_IPV4LL))
ipv4ll_drop(ifp);
#endif
eloop_exit(ifp->ctx->eloop, EXIT_FAILURE);
return deleted;
}
- eloop_timeout_add_sec(ifp->ctx->eloop,
- DHCP_RAND_MAX, dhcp_discover, ifp);
+ eloop_timeout_add_sec(ifp->ctx->eloop, DHCP_RAND_MAX, dhcp_discover,
+ ifp);
return deleted;
}
#endif
static void
dhcp_arp_announced(struct arp_state *state)
{
-
arp_free(state);
}
#endif
// Delay restarting to give time for the BPF ARP process to exit
// as we may spawn a new one with a different filter fairly quickly
delay = MSEC_PER_SEC +
- (arc4random_uniform(MSEC_PER_SEC * 2) - MSEC_PER_SEC);
+ (arc4random_uniform(MSEC_PER_SEC * 2) - MSEC_PER_SEC);
eloop_timeout_add_msec(ifp->ctx->eloop, delay, dhcp_start1, ifp);
}
#endif
ifo = ifp->options;
if (state->arping_index != -1 &&
- state->arping_index < ifo->arping_len &&
- amsg &&
- amsg->sip.s_addr == ifo->arping[state->arping_index])
- {
+ state->arping_index < ifo->arping_len && amsg &&
+ amsg->sip.s_addr == ifo->arping[state->arping_index]) {
char buf[HWADDR_LEN * 3];
hwaddr_ntoa(amsg->sha, ifp->hwlen, buf, sizeof(buf));
if (dhcpcd_selectprofile(ifp, buf) == -1 &&
- dhcpcd_selectprofile(ifp, inet_ntoa(amsg->sip)) == -1)
- {
+ dhcpcd_selectprofile(ifp, inet_ntoa(amsg->sip)) == -1) {
/* We didn't find a profile for this
* address or hwaddr, so move to the next
* arping profile */
if (ctx->options & DHCPCD_MANAGER ||
ifp->options->options & DHCPCD_STATIC ||
(state->old != NULL &&
- state->old->yiaddr == state->new->yiaddr &&
- old_state & STATE_ADDED && !(old_state & STATE_FAKE)))
+ state->old->yiaddr ==
+ state->new->yiaddr &&old_state &STATE_ADDED &&
+ !(old_state & STATE_FAKE)))
return;
dhcp_closeinet(ifp);
#ifdef PRIVSEP
if (IN_PRIVSEP_SE(ctx)) {
if (ps_inet_openbootp(state->addr) == -1)
- logerr(__func__);
+ logerr(__func__);
return;
}
#endif
}
if (eloop_event_add(ctx->eloop, state->udp_rfd, ELE_READ,
- dhcp_handleifudp, ifp) == -1)
+ dhcp_handleifudp, ifp) == -1)
logerr("%s: eloop_event_add", __func__);
}
}
get_lease(ifp, lease, state->new, state->new_len);
if (ifo->options & DHCPCD_STATIC) {
- loginfox("%s: using static address %s/%d",
- ifp->name, inet_ntoa(lease->addr),
- inet_ntocidr(lease->mask));
+ loginfox("%s: using static address %s/%d", ifp->name,
+ inet_ntoa(lease->addr), inet_ntocidr(lease->mask));
lease->leasetime = DHCP_INFINITE_LIFETIME;
state->reason = "STATIC";
} else if (ifo->options & DHCPCD_INFORM) {
- loginfox("%s: received approval for %s",
- ifp->name, inet_ntoa(lease->addr));
+ loginfox("%s: received approval for %s", ifp->name,
+ inet_ntoa(lease->addr));
lease->leasetime = DHCP_INFINITE_LIFETIME;
state->reason = "INFORM";
} else {
if (lease->frominfo)
state->reason = "TIMEOUT";
if (lease->leasetime == DHCP_INFINITE_LIFETIME) {
- lease->renewaltime =
- lease->rebindtime =
+ lease->renewaltime = lease->rebindtime =
lease->leasetime;
- loginfox("%s: leased %s for infinity",
- ifp->name, inet_ntoa(lease->addr));
+ loginfox("%s: leased %s for infinity", ifp->name,
+ inet_ntoa(lease->addr));
} else {
if (lease->leasetime < DHCP_MIN_LEASE) {
logwarnx("%s: minimum lease is %d seconds",
lease->rebindtime =
(uint32_t)(lease->leasetime * T2);
logwarnx("%s: rebind time greater than lease "
- "time, forcing to %"PRIu32" seconds",
+ "time, forcing to %" PRIu32 " seconds",
ifp->name, lease->rebindtime);
}
if (lease->renewaltime == 0)
lease->renewaltime =
(uint32_t)(lease->leasetime * T1);
logwarnx("%s: renewal time greater than "
- "rebind time, forcing to %"PRIu32" seconds",
+ "rebind time, forcing to %" PRIu32
+ " seconds",
ifp->name, lease->renewaltime);
}
if (state->state == DHS_RENEW && state->addr &&
lease->addr.s_addr == state->addr->addr.s_addr &&
!(state->added & STATE_FAKE))
- logdebugx("%s: leased %s for %"PRIu32" seconds",
+ logdebugx("%s: leased %s for %" PRIu32
+ " seconds",
ifp->name, inet_ntoa(lease->addr),
lease->leasetime);
else
- loginfox("%s: leased %s for %"PRIu32" seconds",
+ loginfox("%s: leased %s for %" PRIu32
+ " seconds",
ifp->name, inet_ntoa(lease->addr),
lease->leasetime);
}
}
if (state->reason == NULL) {
if (state->old &&
- !(state->added & (STATE_FAKE | STATE_EXPIRED)))
- {
+ !(state->added & (STATE_FAKE | STATE_EXPIRED))) {
if (state->old->yiaddr == state->new->yiaddr &&
- lease->server.s_addr &&
- state->state != DHS_REBIND)
+ lease->server.s_addr && state->state != DHS_REBIND)
state->reason = "RENEW";
else
state->reason = "REBIND";
if (lease->leasetime == DHCP_INFINITE_LIFETIME)
lease->renewaltime = lease->rebindtime = lease->leasetime;
else {
- eloop_timeout_add_sec(ctx->eloop,
- lease->renewaltime, dhcp_startrenew, ifp);
- eloop_timeout_add_sec(ctx->eloop,
- lease->rebindtime, dhcp_rebind, ifp);
- eloop_timeout_add_sec(ctx->eloop,
- lease->leasetime, dhcp_expire, ifp);
- logdebugx("%s: renew in %"PRIu32" seconds, rebind in %"PRIu32
- " seconds",
+ eloop_timeout_add_sec(ctx->eloop, lease->renewaltime,
+ dhcp_startrenew, ifp);
+ eloop_timeout_add_sec(ctx->eloop, lease->rebindtime,
+ dhcp_rebind, ifp);
+ eloop_timeout_add_sec(ctx->eloop, lease->leasetime, dhcp_expire,
+ ifp);
+ logdebugx("%s: renew in %" PRIu32 " seconds, rebind in %" PRIu32
+ " seconds",
ifp->name, lease->renewaltime, lease->rebindtime);
}
state->state = DHS_BOUND;
if (!state->lease.frominfo &&
!(ifo->options & (DHCPCD_INFORM | DHCPCD_STATIC))) {
- logdebugx("%s: writing lease: %s",
- ifp->name, state->leasefile);
- if (dhcp_writefile(ifp->ctx, state->leasefile, 0640,
- state->new, state->new_len) == -1)
+ logdebugx("%s: writing lease: %s", ifp->name, state->leasefile);
+ if (dhcp_writefile(ifp->ctx, state->leasefile, 0640, state->new,
+ state->new_len) == -1)
logerr("dhcp_writefile: %s", state->leasefile);
}
}
static size_t
-dhcp_message_new(struct bootp **bootp,
- const struct in_addr *addr, const struct in_addr *mask)
+dhcp_message_new(struct bootp **bootp, const struct in_addr *addr,
+ const struct in_addr *mask)
{
uint8_t *p;
uint32_t cookie;
*p++ = DHO_SUBNETMASK;
*p++ = sizeof(mask->s_addr);
memcpy(p, &mask->s_addr, sizeof(mask->s_addr));
- p+= sizeof(mask->s_addr);
+ p += sizeof(mask->s_addr);
}
*p = DHO_END;
state = D_STATE(ifp);
addr.s_addr = state->offer->yiaddr == INADDR_ANY ?
- state->offer->ciaddr : state->offer->yiaddr;
+ state->offer->ciaddr :
+ state->offer->yiaddr;
/* If the interface already has the address configured
* then we can't ARP for duplicate detection. */
ia = ipv4_iffindaddr(ifp, &addr, NULL);
get_lease(ifp, &l, state->offer, state->offer_len);
/* Add the address now, let the kernel handle DAD. */
- ipv4_addaddr(ifp, &l.addr, &l.mask, &l.brd,
- l.leasetime, l.rebindtime);
+ ipv4_addaddr(ifp, &l.addr, &l.mask, &l.brd, l.leasetime,
+ l.rebindtime);
} else if (ia->addr_flags & IN_IFF_DUPLICATED)
dhcp_addr_duplicated(ifp, &ia->addr);
else
- loginfox("%s: waiting for DAD on %s",
- ifp->name, inet_ntoa(addr));
+ loginfox("%s: waiting for DAD on %s", ifp->name,
+ inet_ntoa(addr));
return 0;
}
#else
- if (!(ifp->flags & IFF_NOARP) &&
- ifp->options->options & DHCPCD_ARP)
- {
+ if (!(ifp->flags & IFF_NOARP) && ifp->options->options & DHCPCD_ARP) {
struct arp_state *astate;
struct dhcp_lease l;
if (ia == NULL) {
state->state = DHS_PROBE;
get_lease(ifp, &l, state->offer, state->offer_len);
- loginfox("%s: probing address %s/%d",
- ifp->name, inet_ntoa(l.addr), inet_ntocidr(l.mask));
+ loginfox("%s: probing address %s/%d", ifp->name,
+ inet_ntoa(l.addr), inet_ntocidr(l.mask));
/* We need to handle DAD. */
arp_probe(astate);
return 0;
static void
dhcp_arp_bind(struct interface *ifp)
{
-
- if (ifp->ctx->options & DHCPCD_TEST ||
- dhcp_arp_address(ifp) == 1)
+ if (ifp->ctx->options & DHCPCD_TEST || dhcp_arp_address(ifp) == 1)
dhcp_bind(ifp);
}
#endif
ia = NULL;
if (ifo->req_addr.s_addr == INADDR_ANY &&
- (ia = ipv4_iffindaddr(ifp, NULL, NULL)) == NULL)
- {
+ (ia = ipv4_iffindaddr(ifp, NULL, NULL)) == NULL) {
loginfox("%s: waiting for 3rd party to "
- "configure IP address", ifp->name);
+ "configure IP address",
+ ifp->name);
state->reason = "3RDPARTY";
script_runreason(ifp, state->reason);
return;
}
state->offer_len = dhcp_message_new(&state->offer,
- ia ? &ia->addr : &ifo->req_addr,
- ia ? &ia->mask : &ifo->req_mask);
+ ia ? &ia->addr : &ifo->req_addr, ia ? &ia->mask : &ifo->req_mask);
if (state->offer_len)
#if defined(ARP) || defined(KERNEL_RFC5227)
dhcp_arp_bind(ifp);
ia = ipv4_iffindaddr(ifp, NULL, NULL);
if (ia == NULL) {
loginfox("%s: waiting for 3rd party to "
- "configure IP address",
+ "configure IP address",
ifp->name);
if (!(ifp->ctx->options & DHCPCD_TEST)) {
state->reason = "3RDPARTY";
ia = ipv4_iffindaddr(ifp, &ifo->req_addr, &ifo->req_mask);
if (ia == NULL) {
if (ifp->ctx->options & DHCPCD_TEST) {
- logerrx("%s: cannot add IP address in test mode",
+ logerrx(
+ "%s: cannot add IP address in test mode",
ifp->name);
return;
}
if (dhcp_arp_address(ifp) != 1)
return;
#endif
- ia = ipv4_iffindaddr(ifp,
- &ifo->req_addr, &ifo->req_mask);
+ ia = ipv4_iffindaddr(ifp, &ifo->req_addr,
+ &ifo->req_mask);
assert(ia != NULL);
}
}
state->state = DHS_INFORM;
state->addr = ia;
- state->offer_len = dhcp_message_new(&state->offer,
- &ia->addr, &ia->mask);
+ state->offer_len = dhcp_message_new(&state->offer, &ia->addr,
+ &ia->mask);
if (state->offer_len) {
dhcp_new_xid(ifp);
get_lease(ifp, &state->lease, state->offer, state->offer_len);
ifo = ifp->options;
if ((ifo->options & (DHCPCD_INFORM | DHCPCD_STATIC) &&
(state->addr == NULL ||
- state->addr->addr.s_addr != ifo->req_addr.s_addr)) ||
+ state->addr->addr.s_addr != ifo->req_addr.s_addr)) ||
(oldopts & (DHCPCD_INFORM | DHCPCD_STATIC) &&
- !(ifo->options & (DHCPCD_INFORM | DHCPCD_STATIC))))
- {
+ !(ifo->options & (DHCPCD_INFORM | DHCPCD_STATIC)))) {
dhcp_drop(ifp, "EXPIRE");
}
}
return;
}
if (ifo->options & DHCPCD_INFORM) {
- loginfox("%s: informing address of %s",
- ifp->name, inet_ntoa(state->lease.addr));
+ loginfox("%s: informing address of %s", ifp->name,
+ inet_ntoa(state->lease.addr));
dhcp_inform(ifp);
return;
}
if (!IS_DHCP(state->offer))
return;
- loginfox("%s: rebinding lease of %s",
- ifp->name, inet_ntoa(state->lease.addr));
+ loginfox("%s: rebinding lease of %s", ifp->name,
+ inet_ntoa(state->lease.addr));
#if defined(ARP) && !defined(KERNEL_RFC5227)
/* Create the DHCP ARP state so we can defend it. */
#ifdef IPV4LL
/* Need to add this before dhcp_expire and friends. */
if (!ifo->fallback && ifo->options & DHCPCD_IPV4LL)
- eloop_timeout_add_sec(ifp->ctx->eloop,
- ifo->ipv4ll_time, ipv4ll_start, ifp);
+ eloop_timeout_add_sec(ifp->ctx->eloop, ifo->ipv4ll_time,
+ ipv4ll_start, ifp);
#endif
if (ifo->options & DHCPCD_LASTLEASE && state->lease.frominfo)
- eloop_timeout_add_sec(ifp->ctx->eloop,
- ifo->reboot, dhcp_lastlease, ifp);
+ eloop_timeout_add_sec(ifp->ctx->eloop, ifo->reboot,
+ dhcp_lastlease, ifp);
else if (!(ifo->options & DHCPCD_INFORM))
- eloop_timeout_add_sec(ifp->ctx->eloop,
- ifo->reboot, dhcp_expire, ifp);
+ eloop_timeout_add_sec(ifp->ctx->eloop, ifo->reboot, dhcp_expire,
+ ifp);
/* Don't bother ARP checking as the server could NAK us first.
* Don't call dhcp_request as that would change the state */
state->state = DHS_RELEASE;
dhcp_unlink(ifp->ctx, state->leasefile);
- if (if_is_link_up(ifp) &&
- state->new != NULL &&
- state->lease.server.s_addr != INADDR_ANY)
- {
+ if (if_is_link_up(ifp) && state->new != NULL &&
+ state->lease.server.s_addr != INADDR_ANY) {
/* We need to delay removal of the IP address so the
* message can be sent.
* Unlike DHCPv6, there is no acknowledgement. */
.tv_sec = 1,
};
- loginfox("%s: releasing lease of %s",
- ifp->name, inet_ntoa(state->lease.addr));
+ loginfox("%s: releasing lease of %s", ifp->name,
+ inet_ntoa(state->lease.addr));
dhcp_new_xid(ifp);
send_message(ifp, DHCP_RELEASE, NULL);
eloop_timeout_delete(ifp->ctx->eloop, NULL, ifp);
- eloop_timeout_add_tv(ifp->ctx->eloop,
- &delay, dhcp_deconfigure, ifp);
+ eloop_timeout_add_tv(ifp->ctx->eloop, &delay,
+ dhcp_deconfigure, ifp);
return;
}
}
return 0;
}
-#define WHTLST_NONE 0
-#define WHTLST_MATCH 1
-#define WHTLST_NOMATCH 2
+#define WHTLST_NONE 0
+#define WHTLST_MATCH 1
+#define WHTLST_NOMATCH 2
static unsigned int
whitelisted_ip(const struct if_options *ifo, in_addr_t addr)
{
}
static void
-log_dhcp(int loglevel, const char *msg,
- const struct interface *ifp, const struct bootp *bootp, size_t bootp_len,
- const struct in_addr *from, int ad)
+log_dhcp(int loglevel, const char *msg, const struct interface *ifp,
+ const struct bootp *bootp, size_t bootp_len, const struct in_addr *from,
+ int ad)
{
const char *tfrom;
char *a, sname[sizeof(bootp->sname) * 4];
tfrom = "from";
r = get_option_addr(ifp->ctx, &addr, bootp, bootp_len, DHO_SERVERID);
if (get_option_uint8(ifp->ctx, &overl, bootp, bootp_len,
- DHO_OPTSOVERLOADED) == -1)
+ DHO_OPTSOVERLOADED) == -1)
overl = 0;
if (bootp->sname[0] && r == 0 && !(overl & 2)) {
print_string(sname, sizeof(sname), OT_STRING | OT_DOMAIN,
bootp->sname, sizeof(bootp->sname));
if (a == NULL)
- logmessage(loglevel, "%s: %s %s %s %s",
- ifp->name, msg, tfrom, inet_ntoa(addr), sname);
+ logmessage(loglevel, "%s: %s %s %s %s", ifp->name, msg,
+ tfrom, inet_ntoa(addr), sname);
else
- logmessage(loglevel, "%s: %s %s %s %s %s",
- ifp->name, msg, a, tfrom, inet_ntoa(addr), sname);
+ logmessage(loglevel, "%s: %s %s %s %s %s", ifp->name,
+ msg, a, tfrom, inet_ntoa(addr), sname);
} else {
if (r != 0) {
tfrom = "via";
addr = *from;
}
if (a == NULL)
- logmessage(loglevel, "%s: %s %s %s",
- ifp->name, msg, tfrom, inet_ntoa(addr));
+ logmessage(loglevel, "%s: %s %s %s", ifp->name, msg,
+ tfrom, inet_ntoa(addr));
else
- logmessage(loglevel, "%s: %s %s %s %s",
- ifp->name, msg, a, tfrom, inet_ntoa(addr));
+ logmessage(loglevel, "%s: %s %s %s %s", ifp->name, msg,
+ a, tfrom, inet_ntoa(addr));
}
free(a);
}
if (ifn->hwlen <= sizeof(bootp->chaddr) &&
memcmp(bootp->chaddr, ifn->hwaddr, ifn->hwlen))
continue;
- logdebugx("%s: redirecting DHCP message to %s",
- ifp->name, ifn->name);
+ logdebugx("%s: redirecting DHCP message to %s", ifp->name,
+ ifn->name);
dhcp_handledhcp(ifn, bootp, bootp_len, from);
}
}
struct ipv4_addr *ia;
#endif
-#define LOGDHCP0(l, m) \
- log_dhcp((l), (m), ifp, bootp, bootp_len, from, 0)
-#define LOGDHCP(l, m) \
- log_dhcp((l), (m), ifp, bootp, bootp_len, from, 1)
+#define LOGDHCP0(l, m) log_dhcp((l), (m), ifp, bootp, bootp_len, from, 0)
+#define LOGDHCP(l, m) log_dhcp((l), (m), ifp, bootp, bootp_len, from, 1)
-#define IS_STATE_ACTIVE(s) ((s)-state != DHS_NONE && \
- (s)->state != DHS_INIT && (s)->state != DHS_BOUND)
+#define IS_STATE_ACTIVE(s) \
+ ((s) - state != DHS_NONE && (s)->state != DHS_INIT && \
+ (s)->state != DHS_BOUND)
/* Don't do anything if the user hasn't configured it. */
if (ifp->active != IF_ACTIVE_USER ||
if (bootp->op != BOOTREPLY) {
if (IS_STATE_ACTIVE(state))
- logdebugx("%s: op (%d) is not BOOTREPLY",
- ifp->name, bootp->op);
+ logdebugx("%s: op (%d) is not BOOTREPLY", ifp->name,
+ bootp->op);
return;
}
}
if (ifp->hwlen <= sizeof(bootp->chaddr) &&
- memcmp(bootp->chaddr, ifp->hwaddr, ifp->hwlen))
- {
+ memcmp(bootp->chaddr, ifp->hwaddr, ifp->hwlen)) {
if (IS_STATE_ACTIVE(state)) {
char buf[sizeof(bootp->chaddr) * 3];
- logdebugx("%s: xid 0x%x is for hwaddr %s",
- ifp->name, ntohl(bootp->xid),
+ logdebugx("%s: xid 0x%x is for hwaddr %s", ifp->name,
+ ntohl(bootp->xid),
hwaddr_ntoa(bootp->chaddr, sizeof(bootp->chaddr),
- buf, sizeof(buf)));
+ buf, sizeof(buf)));
}
dhcp_redirect_dhcp(ifp, bootp, bootp_len, from);
return;
i = whitelisted_ip(ifp->options, from->s_addr);
switch (i) {
case WHTLST_NOMATCH:
- logwarnx("%s: non whitelisted DHCP packet from %s",
- ifp->name, inet_ntoa(*from));
+ logwarnx("%s: non whitelisted DHCP packet from %s", ifp->name,
+ inet_ntoa(*from));
return;
case WHTLST_MATCH:
break;
}
/* We may have found a BOOTP server */
- if (get_option_uint8(ifp->ctx, &type,
- bootp, bootp_len, DHO_MESSAGETYPE) == -1)
+ if (get_option_uint8(ifp->ctx, &type, bootp, bootp_len,
+ DHO_MESSAGETYPE) == -1)
type = 0;
else if (ifo->options & DHCPCD_BOOTP) {
logdebugx("%s: ignoring DHCP reply (expecting BOOTP)",
#ifdef AUTH
/* Authenticate the message */
- auth = get_option(ifp->ctx, bootp, bootp_len,
- DHO_AUTHENTICATION, &auth_len);
+ auth = get_option(ifp->ctx, bootp, bootp_len, DHO_AUTHENTICATION,
+ &auth_len);
if (auth) {
if (dhcp_auth_validate(&state->auth, &ifo->auth,
- (uint8_t *)bootp, bootp_len, 4, type,
- auth, auth_len) == NULL)
- {
+ (uint8_t *)bootp, bootp_len, 4, type, auth,
+ auth_len) == NULL) {
LOGDHCP0(LOG_ERR, "authentication failed");
return;
}
if (state->auth.token)
- logdebugx("%s: validated using 0x%08" PRIu32,
- ifp->name, state->auth.token->secretid);
+ logdebugx("%s: validated using 0x%08" PRIu32, ifp->name,
+ state->auth.token->secretid);
else
loginfox("%s: accepted reconfigure key", ifp->name);
} else if (ifo->auth.options & DHCPCD_AUTH_SEND) {
/* RFC 3203 */
if (type == DHCP_FORCERENEW) {
if (from->s_addr == INADDR_ANY ||
- from->s_addr == INADDR_BROADCAST)
- {
+ from->s_addr == INADDR_BROADCAST) {
LOGDHCP(LOG_ERR, "discarding Force Renew");
return;
}
if (state->state == DHS_BOUND)
dhcp_renew(ifp);
else {
- eloop_timeout_delete(ifp->ctx->eloop,
- send_inform, ifp);
+ eloop_timeout_delete(ifp->ctx->eloop, send_inform, ifp);
dhcp_inform(ifp);
}
#else
/* Ensure that no reject options are present */
for (i = 1; i < 255; i++) {
if (has_option_mask(ifo->rejectmask, i) &&
- get_option(ifp->ctx, bootp, bootp_len, (uint8_t)i, NULL))
- {
+ get_option(ifp->ctx, bootp, bootp_len, (uint8_t)i, NULL)) {
LOGDHCP(LOG_WARNING, "reject DHCP");
return;
}
if (type == DHCP_NAK) {
/* For NAK, only check if we require the ServerID */
if (has_option_mask(ifo->requiremask, DHO_SERVERID) &&
- get_option_addr(ifp->ctx, &addr,
- bootp, bootp_len, DHO_SERVERID) == -1)
- {
+ get_option_addr(ifp->ctx, &addr, bootp, bootp_len,
+ DHO_SERVERID) == -1) {
LOGDHCP(LOG_WARNING, "reject NAK");
return;
}
/* We should restart on a NAK */
LOGDHCP(LOG_WARNING, "NAK:");
- if ((msg = get_option_string(ifp->ctx,
- bootp, bootp_len, DHO_MESSAGE)))
- {
+ if ((msg = get_option_string(ifp->ctx, bootp, bootp_len,
+ DHO_MESSAGE))) {
logwarnx("%s: message: %s", ifp->name, msg);
free(msg);
}
}
/* If we constantly get NAKS then we should slowly back off */
- eloop_timeout_add_sec(ifp->ctx->eloop,
- state->nakoff, dhcp_discover, ifp);
+ eloop_timeout_add_sec(ifp->ctx->eloop, state->nakoff,
+ dhcp_discover, ifp);
if (state->nakoff == 0)
state->nakoff = 1;
else {
/* Ensure that all required options are present */
for (i = 1; i < 255; i++) {
if (has_option_mask(ifo->requiremask, i) &&
- !get_option(ifp->ctx, bootp, bootp_len, (uint8_t)i, NULL))
- {
+ !get_option(ifp->ctx, bootp, bootp_len, (uint8_t)i, NULL)) {
/* If we are BOOTP, then ignore the need for serverid.
* To ignore BOOTP, require dhcp_message_type.
* However, nothing really stops BOOTP from providing
if (has_option_mask(ifo->requestmask, DHO_IPV6_PREFERRED_ONLY)) {
if (get_option_uint32(ifp->ctx, &v6only_time, bootp, bootp_len,
- DHO_IPV6_PREFERRED_ONLY) == 0 &&
+ DHO_IPV6_PREFERRED_ONLY) == 0 &&
(state->state == DHS_DISCOVER ||
- state->state == DHS_REBOOT || state->state == DHS_NONE))
- {
+ state->state == DHS_REBOOT ||
+ state->state == DHS_NONE)) {
char v6msg[128];
use_v6only = true;
/* DHCP Auto-Configure, RFC 2563 */
if (type == DHCP_OFFER && bootp->yiaddr == INADDR_ANY) {
LOGDHCP(LOG_WARNING, "no address offered");
- if ((msg = get_option_string(ifp->ctx,
- bootp, bootp_len, DHO_MESSAGE)))
- {
+ if ((msg = get_option_string(ifp->ctx, bootp, bootp_len,
+ DHO_MESSAGE))) {
logwarnx("%s: message: %s", ifp->name, msg);
free(msg);
}
#ifdef IPV4LL
if (state->state == DHS_DISCOVER &&
get_option_uint8(ifp->ctx, &tmp, bootp, bootp_len,
- DHO_AUTOCONFIGURE) == 0)
- {
+ DHO_AUTOCONFIGURE) == 0) {
has_auto_conf = true;
switch (tmp) {
case 0:
break;
default:
logerrx("%s: unknown auto configuration "
- "option %d",
+ "option %d",
ifp->name, tmp);
break;
}
if (use_v6only || has_auto_conf) {
eloop_timeout_delete(ifp->ctx->eloop, NULL, ifp);
eloop_timeout_add_sec(ifp->ctx->eloop,
- use_v6only ? v6only_time : DHCP_MAX,
- dhcp_discover, ifp);
+ use_v6only ? v6only_time : DHCP_MAX, dhcp_discover, ifp);
return;
}
/* Ensure that the address offered is valid */
if ((type == 0 || type == DHCP_OFFER || type == DHCP_ACK) &&
- (bootp->ciaddr == INADDR_ANY || bootp->ciaddr == INADDR_BROADCAST)
- &&
- (bootp->yiaddr == INADDR_ANY || bootp->yiaddr == INADDR_BROADCAST))
- {
+ (bootp->ciaddr == INADDR_ANY ||
+ bootp->ciaddr == INADDR_BROADCAST) &&
+ (bootp->yiaddr == INADDR_ANY ||
+ bootp->yiaddr == INADDR_BROADCAST)) {
LOGDHCP(LOG_WARNING, "reject invalid address");
return;
}
dhcp_decline(ifp);
ipv4_deladdr(ia, 0);
eloop_timeout_delete(ifp->ctx->eloop, NULL, ifp);
- eloop_timeout_add_sec(ifp->ctx->eloop,
- DHCP_RAND_MAX, dhcp_discover, ifp);
+ eloop_timeout_add_sec(ifp->ctx->eloop, DHCP_RAND_MAX,
+ dhcp_discover, ifp);
return;
}
#endif
lease->addr.s_addr = bootp->yiaddr;
memcpy(&lease->cookie, bootp->vend, sizeof(lease->cookie));
if (type == 0 ||
- get_option_addr(ifp->ctx,
- &lease->server, bootp, bootp_len, DHO_SERVERID) != 0)
+ get_option_addr(ifp->ctx, &lease->server, bootp, bootp_len,
+ DHO_SERVERID) != 0)
lease->server.s_addr = INADDR_ANY;
/* Test for rapid commit in the OFFER */
if (!(ifp->ctx->options & DHCPCD_TEST) &&
has_option_mask(ifo->requestmask, DHO_RAPIDCOMMIT) &&
- get_option(ifp->ctx, bootp, bootp_len,
- DHO_RAPIDCOMMIT, NULL))
- {
+ get_option(ifp->ctx, bootp, bootp_len, DHO_RAPIDCOMMIT,
+ NULL)) {
state->state = DHS_REQUEST;
goto rapidcommit;
}
if (state->state == DHS_DISCOVER) {
/* We only allow ACK of rapid commit DISCOVER. */
if (has_option_mask(ifo->requestmask,
- DHO_RAPIDCOMMIT) &&
+ DHO_RAPIDCOMMIT) &&
get_option(ifp->ctx, bootp, bootp_len,
- DHO_RAPIDCOMMIT, NULL))
+ DHO_RAPIDCOMMIT, NULL))
state->state = DHS_REQUEST;
else {
LOGDHCP(LOG_DEBUG, "ignoring ack of");
}
}
-rapidcommit:
+ rapidcommit:
if (!(ifo->options & DHCPCD_INFORM))
LOGDHCP(LOG_DEBUG, "acknowledged");
else
- ifo->options &= ~DHCPCD_STATIC;
+ ifo->options &= ~DHCPCD_STATIC;
}
/* No NAK, so reset the backoff
/* Lengths have already been checked. */
static bool
-checksums_valid(const void *packet,
- struct in_addr *from, unsigned int flags)
+checksums_valid(const void *packet, struct in_addr *from, unsigned int flags)
{
const struct ip *ip = packet;
size_t ip_hlen;
/* Trim frame header */
if (fl != 0) {
if (len < fl) {
- logerrx("%s: %s: short frame header %zu",
- __func__, ifp->name, len);
+ logerrx("%s: %s: short frame header %zu", __func__,
+ ifp->name, len);
return;
}
len -= fl;
}
if (!checksums_valid(data, &from, bpf_flags)) {
- logerrx("%s: checksum failure from %s",
- ifp->name, inet_ntoa(from));
+ logerrx("%s: checksum failure from %s", ifp->name,
+ inet_ntoa(from));
return;
}
}
if (iov->iov_len < offsetof(struct bootp, vend)) {
- logerrx("%s: truncated packet (%zu) from %s",
- ifp->name, iov->iov_len, inet_ntoa(from->sin_addr));
+ logerrx("%s: truncated packet (%zu) from %s", ifp->name,
+ iov->iov_len, inet_ntoa(from->sin_addr));
return;
}
}
#endif
- dhcp_handlebootp(ifp, iov->iov_base, iov->iov_len,
- &from->sin_addr);
+ dhcp_handlebootp(ifp, iov->iov_base, iov->iov_len, &from->sin_addr);
}
static void
#endif
} cmsgbuf = { .buf = { 0 } };
struct msghdr msg = {
- .msg_name = &from, .msg_namelen = sizeof(from),
- .msg_iov = &iov, .msg_iovlen = 1,
- .msg_control = cmsgbuf.buf, .msg_controllen = sizeof(cmsgbuf.buf),
+ .msg_name = &from,
+ .msg_namelen = sizeof(from),
+ .msg_iov = &iov,
+ .msg_iovlen = 1,
+ .msg_control = cmsgbuf.buf,
+ .msg_controllen = sizeof(cmsgbuf.buf),
};
int s;
ssize_t bytes;
}
if (eloop_event_add(ifp->ctx->eloop, state->bpf->bpf_fd, ELE_READ,
- dhcp_readbpf, ifp) == -1)
+ dhcp_readbpf, ifp) == -1)
logerr("%s: eloop_event_add", __func__);
return 0;
}
state->state = DHS_INIT;
state->reason = "PREINIT";
state->nakoff = 0;
- dhcp_set_leasefile(state->leasefile, sizeof(state->leasefile),
- AF_INET, ifp);
+ dhcp_set_leasefile(state->leasefile, sizeof(state->leasefile), AF_INET,
+ ifp);
ifo = ifp->options;
/* We need to drop the leasefile so that dhcp_start
state->clientid = malloc(ifp->ctx->duid_len + 6);
if (state->clientid == NULL)
goto eexit;
- state->clientid[0] =(uint8_t)(ifp->ctx->duid_len + 5);
+ state->clientid[0] = (uint8_t)(ifp->ctx->duid_len + 5);
state->clientid[1] = 255; /* RFC 4361 */
memcpy(state->clientid + 2, ifo->iaid, 4);
memcpy(state->clientid + 6, ifp->ctx->duid,
ifp->ctx->duid_len);
} else {
-make_clientid:
+ make_clientid:
len = (uint8_t)(ifp->hwlen + 1);
state->clientid = malloc((size_t)len + 1);
if (state->clientid == NULL)
goto eexit;
state->clientid[0] = len;
state->clientid[1] = (uint8_t)ifp->hwtype;
- memcpy(state->clientid + 2, ifp->hwaddr,
- ifp->hwlen);
+ memcpy(state->clientid + 2, ifp->hwaddr, ifp->hwlen);
}
}
if (ifo->options & DHCPCD_CLIENTID && state->clientid != NULL)
logdebugx("%s: using ClientID %s", ifp->name,
- hwaddr_ntoa(state->clientid + 1, state->clientid[0],
- buf, sizeof(buf)));
+ hwaddr_ntoa(state->clientid + 1, state->clientid[0], buf,
+ sizeof(buf)));
else if (ifp->hwlen)
logdebugx("%s: using hwaddr %s", ifp->name,
hwaddr_ntoa(ifp->hwaddr, ifp->hwlen, buf, sizeof(buf)));
* ICMP port unreachable message back to the DHCP server.
* Only do this in manager mode so we don't swallow messages
* for dhcpcd running on another interface. */
- if ((ctx->options & (DHCPCD_MANAGER|DHCPCD_PRIVSEP)) == DHCPCD_MANAGER
- && ctx->udp_rfd == -1)
- {
+ if ((ctx->options & (DHCPCD_MANAGER | DHCPCD_PRIVSEP)) ==
+ DHCPCD_MANAGER &&
+ ctx->udp_rfd == -1) {
ctx->udp_rfd = dhcp_openudp(NULL);
if (ctx->udp_rfd == -1) {
logerr(__func__);
return;
}
if (eloop_event_add(ctx->eloop, ctx->udp_rfd, ELE_READ,
- dhcp_handleudp, ctx) == -1)
+ dhcp_handleudp, ctx) == -1)
logerr("%s: eloop_event_add", __func__);
}
if (!IN_PRIVSEP(ctx) && ctx->udp_wfd == -1) {
- ctx->udp_wfd = xsocket(PF_INET, SOCK_RAW|SOCK_CXNB,IPPROTO_UDP);
+ ctx->udp_wfd = xsocket(PF_INET, SOCK_RAW | SOCK_CXNB,
+ IPPROTO_UDP);
if (ctx->udp_wfd == -1) {
logerr(__func__);
return;
#endif
if ((!IS_DHCP(state->offer) &&
- !(ifo->options & DHCPCD_BOOTP)) ||
+ !(ifo->options & DHCPCD_BOOTP)) ||
#ifdef IN_IFF_DUPLICATED
(ia && ia->addr_flags & IN_IFF_DUPLICATED) ||
#endif
(IS_DHCP(state->offer) &&
- ifo->options & DHCPCD_BOOTP))
- {
+ ifo->options & DHCPCD_BOOTP)) {
free(state->offer);
state->offer = NULL;
state->offer_len = 0;
get_lease(ifp, &state->lease, state->offer, state->offer_len);
state->lease.frominfo = 1;
if (state->new == NULL &&
- (ia = ipv4_iffindaddr(ifp,
- &state->lease.addr, &state->lease.mask)) != NULL)
- {
+ (ia = ipv4_iffindaddr(ifp, &state->lease.addr,
+ &state->lease.mask)) != NULL) {
/* We still have the IP address from the last lease.
* Fake add the address and routes from it so the lease
* can be cleaned up. */
state->new = malloc(state->offer_len);
if (state->new) {
- memcpy(state->new,
- state->offer, state->offer_len);
+ memcpy(state->new, state->offer,
+ state->offer_len);
state->new_len = state->offer_len;
state->addr = ia;
state->added |= STATE_ADDED | STATE_FAKE;
state->offer_len = 0;
} else if (!(ifo->options & DHCPCD_LASTLEASE_EXTEND) &&
state->lease.leasetime != DHCP_INFINITE_LIFETIME &&
- dhcp_filemtime(ifp->ctx, state->leasefile, &mtime) == 0)
- {
+ dhcp_filemtime(ifp->ctx, state->leasefile, &mtime) == 0) {
time_t now;
/* Offset lease times and check expiry */
now = time(NULL);
if (now == -1 ||
- (time_t)state->lease.leasetime < now - mtime)
- {
+ (time_t)state->lease.leasetime < now - mtime) {
logdebugx("%s: discarding expired lease",
ifp->name);
free(state->offer);
}
#endif
- if (state->offer == NULL ||
- !IS_DHCP(state->offer) ||
+ if (state->offer == NULL || !IS_DHCP(state->offer) ||
ifo->options & DHCPCD_ANONYMOUS)
dhcp_discover(ifp);
else
* set it now. */
if (ifp->options->req_addr.s_addr != INADDR_ANY &&
ifp->options->req_mask.s_addr == INADDR_ANY)
- ifp->options->req_mask.s_addr =
- ipv4_getnetmask(ifp->options->req_addr.s_addr);
+ ifp->options->req_mask.s_addr = ipv4_getnetmask(
+ ifp->options->req_addr.s_addr);
/* If we haven't specified a ClientID and our hardware address
* length is greater than BOOTP CHADDR then we enforce a ClientID
/* Firewire and InfiniBand interfaces require ClientID and
* the broadcast option being set. */
switch (ifp->hwtype) {
- case ARPHRD_IEEE1394: /* FALLTHROUGH */
+ case ARPHRD_IEEE1394: /* FALLTHROUGH */
case ARPHRD_INFINIBAND:
ifp->options->options |= DHCPCD_CLIENTID | DHCPCD_BROADCAST;
break;
/* No point in delaying a static configuration */
if (ifp->options->options & DHCPCD_STATIC ||
- !(ifp->options->options & DHCPCD_INITIAL_DELAY))
- {
+ !(ifp->options->options & DHCPCD_INITIAL_DELAY)) {
dhcp_start1(ifp);
return;
}
}
#endif
delay = MSEC_PER_SEC +
- (arc4random_uniform(MSEC_PER_SEC * 2) - MSEC_PER_SEC);
- logdebugx("%s: delaying IPv4 for %0.1f seconds",
- ifp->name, (float)delay / MSEC_PER_SEC);
+ (arc4random_uniform(MSEC_PER_SEC * 2) - MSEC_PER_SEC);
+ logdebugx("%s: delaying IPv4 for %0.1f seconds", ifp->name,
+ (float)delay / MSEC_PER_SEC);
eloop_timeout_add_msec(ifp->ctx->eloop, delay, dhcp_start1, ifp);
}
if (cmd == RTM_DELADDR) {
if (state->addr == ia) {
- loginfox("%s: pid %d deleted IP address %s",
- ifp->name, (int)pid, ia->saddr);
+ loginfox("%s: pid %d deleted IP address %s", ifp->name,
+ (int)pid, ia->saddr);
dhcp_close(ifp);
state->addr = NULL;
/* Don't clear the added state as we need
ifo = ifp->options;
if (!(ifp->ctx->options & (DHCPCD_MANAGER | DHCPCD_CONFIGURE)) &&
- IN_ARE_ADDR_EQUAL(&state->lease.addr, &ia->addr))
- {
+ IN_ARE_ADDR_EQUAL(&state->lease.addr, &ia->addr)) {
uint8_t old_state = state->added;
state->addr = ia;
if (ifp->flags & IFF_POINTOPOINT) {
for (i = 1; i < 255; i++)
- if (i != DHO_ROUTER && has_option_mask(ifo->dstmask,i))
+ if (i != DHO_ROUTER && has_option_mask(ifo->dstmask, i))
dhcp_message_add_addr(state->new, i, ia->brd);
}
#ifndef DHCP_H
#define DHCP_H
-#include <arpa/inet.h>
#include <netinet/in.h>
-
#include <netinet/ip.h>
+
+#include <arpa/inet.h>
#define __FAVOR_BSD /* Nasty glibc hack so we can use BSD semantics for UDP */
#include <netinet/udp.h>
#undef __FAVOR_BSD
#include <stdint.h>
#include "arp.h"
-#include "bpf.h"
#include "auth.h"
+#include "bpf.h"
#include "dhcp-common.h"
/* UDP port numbers for BOOTP */
-#define BOOTPS 67
-#define BOOTPC 68
+#define BOOTPS 67
+#define BOOTPC 68
-#define MAGIC_COOKIE 0x63825363
-#define BROADCAST_FLAG 0x8000
+#define MAGIC_COOKIE 0x63825363
+#define BROADCAST_FLAG 0x8000
/* BOOTP message OP code */
-#define BOOTREQUEST 1
-#define BOOTREPLY 2
+#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
+#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
+#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
+#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
+#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_IPV6_PREFERRED_ONLY = 108, /* RFC 8925 */
- 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_MUDURL = 161, /* draft-ietf-opsawg-mud */
- DHO_SIXRD = 212, /* RFC 5969 */
- DHO_MSCSR = 249, /* MS code for RFC 3442 */
- DHO_END = 255
+ 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_IPV6_PREFERRED_ONLY = 108, /* RFC 8925 */
+ 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_MUDURL = 161, /* draft-ietf-opsawg-mud */
+ DHO_SIXRD = 212, /* RFC 5969 */
+ DHO_MSCSR = 249, /* MS code for RFC 3442 */
+ DHO_END = 255
};
/* FQDN values - lsnybble used in flags
* and to allow 0x00 to mean disable
*/
enum FQDN {
- FQDN_DISABLE = 0x00,
- FQDN_NONE = 0x18,
- FQDN_PTR = 0x20,
- FQDN_BOTH = 0x31
+ FQDN_DISABLE = 0x00,
+ FQDN_NONE = 0x18,
+ FQDN_PTR = 0x20,
+ FQDN_BOTH = 0x31
};
-#define MIN_V6ONLY_WAIT 300 /* seconds, RFC 8925 */
+#define MIN_V6ONLY_WAIT 300 /* seconds, RFC 8925 */
/* Sizes for BOOTP options */
-#define BOOTP_CHADDR_LEN 16
-#define BOOTP_SNAME_LEN 64
-#define BOOTP_FILE_LEN 128
-#define BOOTP_VEND_LEN 64
+#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 */
+ 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 */
};
-#define DHCP_MIN_LEN (offsetof(struct bootp, vend) + 4)
+#define DHCP_MIN_LEN (offsetof(struct bootp, vend) + 4)
-struct bootp_pkt
-{
+struct bootp_pkt {
struct ip ip;
struct udphdr udp;
struct bootp bootp;
};
#ifndef DHCP_INFINITE_LIFETIME
-# define DHCP_INFINITE_LIFETIME (~0U)
+#define DHCP_INFINITE_LIFETIME (~0U)
#endif
enum DHS {
};
#ifdef INET
-#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) \
+#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)
+#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"
int dhcp_openudp(struct in_addr *);
void dhcp_packet(struct interface *, uint8_t *, size_t, unsigned int);
void dhcp_recvmsg(struct dhcpcd_ctx *, struct msghdr *);
-void dhcp_printoptions(const struct dhcpcd_ctx *,
- const struct dhcp_opt *, size_t);
+void dhcp_printoptions(const struct dhcpcd_ctx *, const struct dhcp_opt *,
+ size_t);
uint16_t dhcp_get_mtu(const struct interface *);
int dhcp_get_routes(rb_tree_t *, struct interface *);
ssize_t dhcp_env(FILE *, const char *, const struct interface *,
* SUCH DAMAGE.
*/
-#include <sys/utsname.h>
#include <sys/types.h>
+#include <sys/utsname.h>
#include <netinet/in.h>
#include <netinet/ip6.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
-#include <unistd.h>
-#include <fcntl.h>
#include <syslog.h>
+#include <unistd.h>
-#define ELOOP_QUEUE ELOOP_DHCP6
-#include "config.h"
+#define ELOOP_QUEUE ELOOP_DHCP6
#include "common.h"
+#include "config.h"
#include "dhcp.h"
#include "dhcp6.h"
#include "duid.h"
#include "eloop.h"
-#include "if.h"
#include "if-options.h"
+#include "if.h"
#include "ipv6nd.h"
#include "logerr.h"
#include "privsep.h"
#define DHCPCD_IANA_PEN 40712
/* Unsure if I want this */
-//#define VENDOR_SPLIT
+// #define VENDOR_SPLIT
/* Support older systems with different defines */
#if !defined(IPV6_RECVPKTINFO) && defined(IPV6_PKTINFO)
__CTASSERT(sizeof(struct dhcp6_pd_addr) == 8 + 1 + 16);
#endif
-#define DHCP6_PD_ADDR_SIZE (8 + 1 + 16)
-#define DHCP6_PD_ADDR_PLTIME 0
-#define DHCP6_PD_ADDR_VLTIME 4
-#define DHCP6_PD_ADDR_PLEN 8
-#define DHCP6_PD_ADDR_PREFIX 9
+#define DHCP6_PD_ADDR_SIZE (8 + 1 + 16)
+#define DHCP6_PD_ADDR_PLTIME 0
+#define DHCP6_PD_ADDR_VLTIME 4
+#define DHCP6_PD_ADDR_PLEN 8
+#define DHCP6_PD_ADDR_PREFIX 9
struct dhcp6_op {
uint16_t type;
const char *name;
};
-static const struct dhcp6_op dhcp6_ops[] = {
- { DHCP6_SOLICIT, "SOLICIT6" },
- { DHCP6_ADVERTISE, "ADVERTISE6" },
- { DHCP6_REQUEST, "REQUEST6" },
- { DHCP6_REPLY, "REPLY6" },
- { DHCP6_RENEW, "RENEW6" },
- { DHCP6_REBIND, "REBIND6" },
- { DHCP6_CONFIRM, "CONFIRM6" },
- { DHCP6_INFORMATION_REQ, "INFORM6" },
- { DHCP6_RELEASE, "RELEASE6" },
- { DHCP6_RECONFIGURE, "RECONFIGURE6" },
- { DHCP6_DECLINE, "DECLINE6" },
- { 0, NULL }
-};
+static const struct dhcp6_op dhcp6_ops[] = { { DHCP6_SOLICIT, "SOLICIT6" },
+ { DHCP6_ADVERTISE, "ADVERTISE6" }, { DHCP6_REQUEST, "REQUEST6" },
+ { DHCP6_REPLY, "REPLY6" }, { DHCP6_RENEW, "RENEW6" },
+ { DHCP6_REBIND, "REBIND6" }, { DHCP6_CONFIRM, "CONFIRM6" },
+ { DHCP6_INFORMATION_REQ, "INFORM6" }, { DHCP6_RELEASE, "RELEASE6" },
+ { DHCP6_RECONFIGURE, "RECONFIGURE6" }, { DHCP6_DECLINE, "DECLINE6" },
+ { 0, NULL } };
struct dhcp_compat {
uint8_t dhcp_opt;
* But we can support both as the hook scripts will uniqify the
* results if the server returns both options.
*/
-static const struct dhcp_compat dhcp_compats[] = {
- { DHO_DNSSERVER, D6_OPTION_DNS_SERVERS },
- { DHO_HOSTNAME, D6_OPTION_FQDN },
- { DHO_DNSDOMAIN, D6_OPTION_FQDN },
- { DHO_NISSERVER, D6_OPTION_NIS_SERVERS },
- { DHO_NTPSERVER, D6_OPTION_SNTP_SERVERS },
- { DHO_NTPSERVER, D6_OPTION_NTP_SERVER },
- { DHO_RAPIDCOMMIT, D6_OPTION_RAPID_COMMIT },
- { DHO_FQDN, D6_OPTION_FQDN },
- { DHO_VIVCO, D6_OPTION_VENDOR_CLASS },
- { DHO_VIVSO, D6_OPTION_VENDOR_OPTS },
- { DHO_DNSSEARCH, D6_OPTION_DOMAIN_LIST },
- { 0, 0 }
-};
-
-static const char * const dhcp6_statuses[] = {
- "Success",
- "Unspecified Failure",
- "No Addresses Available",
- "No Binding",
- "Not On Link",
- "Use Multicast",
- "No Prefix Available"
-};
+static const struct dhcp_compat dhcp_compats[] = { { DHO_DNSSERVER,
+ D6_OPTION_DNS_SERVERS },
+ { DHO_HOSTNAME, D6_OPTION_FQDN }, { DHO_DNSDOMAIN, D6_OPTION_FQDN },
+ { DHO_NISSERVER, D6_OPTION_NIS_SERVERS },
+ { DHO_NTPSERVER, D6_OPTION_SNTP_SERVERS },
+ { DHO_NTPSERVER, D6_OPTION_NTP_SERVER },
+ { DHO_RAPIDCOMMIT, D6_OPTION_RAPID_COMMIT },
+ { DHO_FQDN, D6_OPTION_FQDN }, { DHO_VIVCO, D6_OPTION_VENDOR_CLASS },
+ { DHO_VIVSO, D6_OPTION_VENDOR_OPTS },
+ { DHO_DNSSEARCH, D6_OPTION_DOMAIN_LIST }, { 0, 0 } };
+
+static const char *const dhcp6_statuses[] = { "Success", "Unspecified Failure",
+ "No Addresses Available", "No Binding", "Not On Link", "Use Multicast",
+ "No Prefix Available" };
static void dhcp6_bind(struct interface *, const char *, const char *);
static void dhcp6_failinform(void *);
static void dhcp6_startrequest(struct interface *);
#ifdef SMALL
-#define dhcp6_hasprefixdelegation(a) (0)
+#define dhcp6_hasprefixdelegation(a) (0)
#else
static int dhcp6_hasprefixdelegation(struct interface *);
#endif
-#define DECLINE_IA(ia) \
- ((ia)->addr_flags & IN6_IFF_DUPLICATED && \
- (ia)->ia_type != 0 && (ia)->ia_type != D6_OPTION_IA_PD && \
- !((ia)->flags & IPV6_AF_STALE) && \
- (ia)->prefix_vltime != 0)
-
+#define DECLINE_IA(ia) \
+ ((ia)->addr_flags & IN6_IFF_DUPLICATED && (ia)->ia_type != 0 && \
+ (ia)->ia_type != D6_OPTION_IA_PD && \
+ !((ia)->flags & IPV6_AF_STALE) && (ia)->prefix_vltime != 0)
/* Gets a pointer to the length part of the option to fill it
* in later. */
#define NEXTLEN(p) ((p) + offsetof(struct dhcp6_option, len))
void
-dhcp6_printoptions(const struct dhcpcd_ctx *ctx,
- const struct dhcp_opt *opts, size_t opts_len)
+dhcp6_printoptions(const struct dhcpcd_ctx *ctx, const struct dhcp_opt *opts,
+ size_t opts_len)
{
size_t i, j;
const struct dhcp_opt *opt, *opt2;
int cols;
- for (i = 0, opt = ctx->dhcp6_opts;
- i < ctx->dhcp6_opts_len; i++, opt++)
- {
+ for (i = 0, opt = ctx->dhcp6_opts; i < ctx->dhcp6_opts_len;
+ i++, opt++) {
for (j = 0, opt2 = opts; j < opts_len; j++, opt2++)
if (opt2->option == opt->option)
break;
ifo = ifp->options;
if (ifo->vivco_len > 0) {
- for (i = 0, vivco = ifo->vivco;
- i < ifo->vivco_len;
+ for (i = 0, vivco = ifo->vivco; i < ifo->vivco_len;
i++, vivco++)
- len += sizeof(o) + sizeof(uint32_t) + sizeof(uint16_t) + vivco->len;
+ len += sizeof(o) + sizeof(uint32_t) + sizeof(uint16_t) +
+ vivco->len;
} else if (ifo->vendorclassid[0] != '\0') {
/* dhcpcd owns DHCPCD_IANA_PEN.
* If you need your own string, get your own IANA PEN. */
p = data;
if (ifo->vivco_len > 0) {
- for (i = 0, vivco = ifo->vivco;
- i < ifo->vivco_len;
+ for (i = 0, vivco = ifo->vivco; i < ifo->vivco_len;
i++, vivco++) {
- optlen = sizeof(uint32_t) + sizeof(uint16_t) + vivco->len;
+ optlen = sizeof(uint32_t) + sizeof(uint16_t) +
+ vivco->len;
o.code = htons(D6_OPTION_VENDOR_CLASS);
o.len = htons((uint16_t)optlen);
memcpy(p, &o, sizeof(o));
so_endp = vsio->so + vsio->so_len;
for (so = vsio->so; so != so_endp; so++) {
- if (olen + sizeof(opt) + sizeof(slen)
- + so->len > UINT16_MAX)
- {
+ if (olen + sizeof(opt) + sizeof(slen) + so->len >
+ UINT16_MAX) {
logerrx("%s: option too big", __func__);
break;
}
}
static void *
-dhcp6_findmoption(void *data, size_t data_len, uint16_t code,
- uint16_t *len)
+dhcp6_findmoption(void *data, size_t data_len, uint16_t code, uint16_t *len)
{
uint8_t *d;
}
static const uint8_t *
-dhcp6_getoption(struct dhcpcd_ctx *ctx,
- size_t *os, unsigned int *code, size_t *len,
- const uint8_t *od, size_t ol, struct dhcp_opt **oopt)
+dhcp6_getoption(struct dhcpcd_ctx *ctx, size_t *os, unsigned int *code,
+ size_t *len, const uint8_t *od, size_t ol, struct dhcp_opt **oopt)
{
struct dhcp6_option o;
size_t i;
}
*oopt = NULL;
- for (i = 0, opt = ctx->dhcp6_opts;
- i < ctx->dhcp6_opts_len; i++, opt++)
- {
+ for (i = 0, opt = ctx->dhcp6_opts; i < ctx->dhcp6_opts_len;
+ i++, opt++) {
if (opt->option == *code) {
*oopt = opt;
break;
if (secs >= (UINT16_MAX / CSEC_PER_SEC) + 1)
hsec = UINT16_MAX;
else {
- hsec = (secs * CSEC_PER_SEC) +
- (nsecs / NSEC_PER_CSEC);
+ hsec = (secs * CSEC_PER_SEC) + (nsecs / NSEC_PER_CSEC);
if (hsec > UINT16_MAX)
hsec = UINT16_MAX;
}
memcpy(&xid, (ifp->hwaddr + ifp->hwlen) - sizeof(xid),
sizeof(xid));
else {
-again:
+ again:
xid = arc4random();
}
continue;
if ((state1 = D6_CSTATE(ifp1)) == NULL)
continue;
- if (state1->send != NULL &&
- state1->send->xid[0] == m->xid[0] &&
+ if (state1->send != NULL && state1->send->xid[0] == m->xid[0] &&
state1->send->xid[1] == m->xid[1] &&
state1->send->xid[2] == m->xid[2])
break;
if (ifp1 != NULL) {
if (ifp->options->options & DHCPCD_XID_HWADDR &&
- ifp->hwlen >= sizeof(xid))
- {
- logerrx("%s: duplicate xid on %s",
- ifp->name, ifp1->name);
- return;
+ ifp->hwlen >= sizeof(xid)) {
+ logerrx("%s: duplicate xid on %s", ifp->name,
+ ifp1->name);
+ return;
}
goto again;
}
if (asla.prefix_len <= 64)
asla.prefix_len = 64;
else
- asla.prefix_len =
- (uint8_t)ROUNDUP4(asla.prefix_len);
+ asla.prefix_len = (uint8_t)ROUNDUP4(
+ asla.prefix_len);
}
-#define BIT(n) (1UL << (n))
+#define BIT(n) (1UL << (n))
#define BIT_MASK(len) (BIT(len) - 1)
if (ia->sla_max == 0) {
/* Work out the real sla_max from our bits used */
}
}
- if (ipv6_userprefix(&prefix->prefix, prefix->prefix_len,
- sla->sla, addr, sla->prefix_len) == -1)
- {
- sa = inet_ntop(AF_INET6, &prefix->prefix,
- sabuf, sizeof(sabuf));
- logerr("%s: invalid prefix %s/%d + %d/%d",
- ifp->name, sa, prefix->prefix_len,
- sla->sla, sla->prefix_len);
+ if (ipv6_userprefix(&prefix->prefix, prefix->prefix_len, sla->sla, addr,
+ sla->prefix_len) == -1) {
+ sa = inet_ntop(AF_INET6, &prefix->prefix, sabuf, sizeof(sabuf));
+ logerr("%s: invalid prefix %s/%d + %d/%d", ifp->name, sa,
+ prefix->prefix_len, sla->sla, sla->prefix_len);
return -1;
}
if (prefix->prefix_exclude_len &&
- IN6_ARE_ADDR_EQUAL(addr, &prefix->prefix_exclude))
- {
- sa = inet_ntop(AF_INET6, &prefix->prefix_exclude,
- sabuf, sizeof(sabuf));
- logerrx("%s: cannot delegate excluded prefix %s/%d",
- ifp->name, sa, prefix->prefix_exclude_len);
+ IN6_ARE_ADDR_EQUAL(addr, &prefix->prefix_exclude)) {
+ sa = inet_ntop(AF_INET6, &prefix->prefix_exclude, sabuf,
+ sizeof(sabuf));
+ logerrx("%s: cannot delegate excluded prefix %s/%d", ifp->name,
+ sa, prefix->prefix_exclude_len);
return -1;
}
state->send = NULL;
}
- switch(state->state) {
+ switch (state->state) {
case DH6S_INIT: /* FALLTHROUGH */
case DH6S_DISCOVER:
type = DHCP6_SOLICIT;
/* RFC 4704 Section 5 says we can only send FQDN for these
* message types. */
- switch(type) {
+ switch (type) {
case DHCP6_SOLICIT:
case DHCP6_REQUEST:
case DHCP6_RENEW:
hl = 0; /* Appease gcc */
if (state->state != DH6S_RELEASE && state->state != DH6S_DECLINE) {
for (l = 0, opt = ifp->ctx->dhcp6_opts;
- l < ifp->ctx->dhcp6_opts_len;
- l++, opt++)
- {
+ l < ifp->ctx->dhcp6_opts_len; l++, opt++) {
for (n = 0, opt2 = ifo->dhcp6_override;
- n < ifo->dhcp6_override_len;
- n++, opt2++)
- {
+ n < ifo->dhcp6_override_len; n++, opt2++) {
if (opt->option == opt2->option)
break;
}
}
#ifndef SMALL
for (l = 0, opt = ifo->dhcp6_override;
- l < ifo->dhcp6_override_len;
- l++, opt++)
- {
+ l < ifo->dhcp6_override_len; l++, opt++) {
if (!DHC_REQOPT(opt, ifo->requestmask6, ifo->nomask6))
continue;
n_options++;
#ifdef AUTH
if ((ifo->auth.options & DHCPCD_AUTH_SENDREQUIRE) !=
- DHCPCD_AUTH_SENDREQUIRE &&
+ DHCPCD_AUTH_SENDREQUIRE &&
DHC_REQ(ifo->requestmask6, ifo->nomask6,
- D6_OPTION_RECONF_ACCEPT))
+ D6_OPTION_RECONF_ACCEPT))
len += sizeof(o); /* Reconfigure Accept */
#endif
}
/* IA */
m = NULL;
ml = 0;
- switch(state->state) {
+ switch (state->state) {
case DH6S_REQUEST:
m = state->recv;
ml = state->recv_len;
continue;
if (!(ap->flags & IPV6_AF_REQUEST) &&
(ap->prefix_vltime == 0 ||
- state->state == DH6S_DISCOVER))
+ state->state == DH6S_DISCOVER))
continue;
if (DECLINE_IA(ap) && state->state != DH6S_DECLINE)
continue;
if (ap->prefix_exclude_len)
len += sizeof(o) + 1 +
(uint8_t)((ap->prefix_exclude_len -
- ap->prefix_len - 1) / NBBY) + 1;
+ ap->prefix_len - 1) /
+ NBBY) +
+ 1;
#endif
} else
len += sizeof(o) + sizeof(struct dhcp6_ia_addr);
ml = state->new_len;
}
- switch(state->state) {
+ switch (state->state) {
case DH6S_REQUEST: /* FALLTHROUGH */
case DH6S_RENEW: /* FALLTHROUGH */
case DH6S_RELEASE:
dhcp6_newxid(ifp, state->send);
-#define COPYIN1(_code, _len) { \
- o.code = htons((_code)); \
- o.len = htons((_len)); \
- memcpy(p, &o, sizeof(o)); \
- p += sizeof(o); \
-}
-#define COPYIN(_code, _data, _len) do { \
- COPYIN1((_code), (_len)); \
- if ((_len) != 0) { \
- memcpy(p, (_data), (_len)); \
- p += (_len); \
- } \
-} while (0 /* CONSTCOND */)
+#define COPYIN1(_code, _len) \
+ { \
+ o.code = htons((_code)); \
+ o.len = htons((_len)); \
+ memcpy(p, &o, sizeof(o)); \
+ p += sizeof(o); \
+ }
+#define COPYIN(_code, _data, _len) \
+ do { \
+ COPYIN1((_code), (_len)); \
+ if ((_len) != 0) { \
+ memcpy(p, (_data), (_len)); \
+ p += (_len); \
+ } \
+ } while (0 /* CONSTCOND */)
/* Options are listed in numerical order as per RFC 7844 Section 4.1
* XXX: They should be randomised. */
p = (uint8_t *)state->send + sizeof(*state->send);
if (ifo->options & DHCPCD_ANONYMOUS)
- COPYIN(D6_OPTION_CLIENTID, duid,
- (uint16_t)duid_len);
+ COPYIN(D6_OPTION_CLIENTID, duid, (uint16_t)duid_len);
else
COPYIN(D6_OPTION_CLIENTID, ifp->ctx->duid,
(uint16_t)ifp->ctx->duid_len);
continue;
if (!(ap->flags & IPV6_AF_REQUEST) &&
(ap->prefix_vltime == 0 ||
- state->state == DH6S_DISCOVER))
+ state->state == DH6S_DISCOVER))
continue;
if (DECLINE_IA(ap) && state->state != DH6S_DECLINE)
continue;
uint8_t pdp[DHCP6_PD_ADDR_SIZE];
memset(pdp, 0, DHCP6_PD_ADDR_PLEN);
- pdp[DHCP6_PD_ADDR_PLEN] = (uint8_t)ap->prefix_len;
+ pdp[DHCP6_PD_ADDR_PLEN] = (uint8_t)
+ ap->prefix_len;
memcpy(pdp + DHCP6_PD_ADDR_PREFIX, &ap->prefix,
DHCP6_PD_ADDR_SIZE - DHCP6_PD_ADDR_PREFIX);
COPYIN(D6_OPTION_IAPREFIX, pdp, sizeof(pdp));
- ia_na_len = (uint16_t)
- (ia_na_len + sizeof(o) + sizeof(pdp));
+ ia_na_len = (uint16_t)(ia_na_len + sizeof(o) +
+ sizeof(pdp));
/* RFC6603 Section 4.2 */
if (ap->prefix_exclude_len) {
const uint8_t *pp;
n = (size_t)((ap->prefix_exclude_len -
- ap->prefix_len - 1) / NBBY) + 1;
+ ap->prefix_len - 1) /
+ NBBY) +
+ 1;
ep = exb;
*ep++ = (uint8_t)ap->prefix_exclude_len;
pp = ap->prefix_exclude.s6_addr;
- pp += (size_t)
- ((ap->prefix_len - 1) / NBBY) +
+ pp += (size_t)((ap->prefix_len - 1) /
+ NBBY) +
(n - 1);
u8 = ap->prefix_len % NBBY;
if (u8)
}
COPYIN(D6_OPTION_PD_EXCLUDE, exb,
(uint16_t)n);
- ia_na_len = (uint16_t)
- (ia_na_len + sizeof(o) + n);
+ ia_na_len = (uint16_t)(ia_na_len +
+ sizeof(o) + n);
}
#endif
} else {
struct dhcp6_ia_addr ia = {
- .addr = ap->addr,
- /*
- * RFC 8415 21.6 states that the
- * valid and preferred lifetimes sent by
- * the client SHOULD be zero and MUST
- * be ignored by the server.
- */
+ .addr = ap->addr,
+ /*
+ * RFC 8415 21.6 states that the
+ * valid and preferred lifetimes sent by
+ * the client SHOULD be zero and MUST
+ * be ignored by the server.
+ */
};
COPYIN(D6_OPTION_IA_ADDR, &ia, sizeof(ia));
- ia_na_len = (uint16_t)
- (ia_na_len + sizeof(o) + sizeof(ia));
+ ia_na_len = (uint16_t)(ia_na_len + sizeof(o) +
+ sizeof(ia));
}
}
}
if (state->send->type != DHCP6_RELEASE &&
- state->send->type != DHCP6_DECLINE &&
- n_options)
- {
+ state->send->type != DHCP6_DECLINE && n_options) {
o_lenp = NEXTLEN(p);
o.len = 0;
COPYIN1(D6_OPTION_ORO, 0);
for (l = 0, opt = ifp->ctx->dhcp6_opts;
- l < ifp->ctx->dhcp6_opts_len;
- l++, opt++)
- {
+ l < ifp->ctx->dhcp6_opts_len; l++, opt++) {
#ifndef SMALL
for (n = 0, opt2 = ifo->dhcp6_override;
- n < ifo->dhcp6_override_len;
- n++, opt2++)
- {
+ n < ifo->dhcp6_override_len; n++, opt2++) {
if (opt->option == opt2->option)
break;
}
if (n < ifo->dhcp6_override_len)
- continue;
+ continue;
#endif
if (!DHC_REQOPT(opt, ifo->requestmask6, ifo->nomask6))
continue;
}
#ifndef SMALL
for (l = 0, opt = ifo->dhcp6_override;
- l < ifo->dhcp6_override_len;
- l++, opt++)
- {
+ l < ifo->dhcp6_override_len; l++, opt++) {
if (!DHC_REQOPT(opt, ifo->requestmask6, ifo->nomask6))
continue;
o.code = htons((uint16_t)opt->option);
#endif
if (state->send->type != DHCP6_RELEASE &&
- state->send->type != DHCP6_DECLINE)
- {
+ state->send->type != DHCP6_DECLINE) {
if (fqdn != FQDN_DISABLE) {
o_lenp = NEXTLEN(p);
COPYIN1(D6_OPTION_FQDN, 0);
if (!has_option_mask(ifo->nomask6, D6_OPTION_MUDURL) &&
ifo->mudurl[0])
- COPYIN(D6_OPTION_MUDURL,
- ifo->mudurl + 1, ifo->mudurl[0]);
+ COPYIN(D6_OPTION_MUDURL, ifo->mudurl + 1,
+ ifo->mudurl[0]);
#ifdef AUTH
if ((ifo->auth.options & DHCPCD_AUTH_SENDREQUIRE) !=
- DHCPCD_AUTH_SENDREQUIRE &&
+ DHCPCD_AUTH_SENDREQUIRE &&
DHC_REQ(ifo->requestmask6, ifo->nomask6,
- D6_OPTION_RECONF_ACCEPT))
+ D6_OPTION_RECONF_ACCEPT))
COPYIN1(D6_OPTION_RECONF_ACCEPT, 0);
#endif
-
}
#ifdef AUTH
}
#ifndef SMALL
-static void dhcp6_delete_delegates(struct interface *ifp)
+static void
+dhcp6_delete_delegates(struct interface *ifp)
{
struct interface *ifp0;
unsigned int RT;
bool multicast = true;
struct sockaddr_in6 dst = {
- .sin6_family = AF_INET6,
- /* Setting the port on Linux gives EINVAL when sending.
- * This looks like a kernel bug as the equivalent works
- * fine with the DHCP counterpart. */
+ .sin6_family = AF_INET6,
+ /* Setting the port on Linux gives EINVAL when sending.
+ * This looks like a kernel bug as the equivalent works
+ * fine with the DHCP counterpart. */
#ifndef __linux__
- .sin6_port = htons(DHCP6_SERVER_PORT),
+ .sin6_port = htons(DHCP6_SERVER_PORT),
#endif
};
struct udphdr udp = {
- .uh_sport = htons(DHCP6_CLIENT_PORT),
- .uh_dport = htons(DHCP6_SERVER_PORT),
- .uh_ulen = htons((uint16_t)(sizeof(udp) + state->send_len)),
+ .uh_sport = htons(DHCP6_CLIENT_PORT),
+ .uh_dport = htons(DHCP6_SERVER_PORT),
+ .uh_ulen = htons((uint16_t)(sizeof(udp) + state->send_len)),
};
struct iovec iov[] = {
- { .iov_base = &udp, .iov_len = sizeof(udp), },
- { .iov_base = state->send, .iov_len = state->send_len, },
+ {
+ .iov_base = &udp,
+ .iov_len = sizeof(udp),
+ },
+ {
+ .iov_base = state->send,
+ .iov_len = state->send_len,
+ },
};
union {
struct cmsghdr hdr;
uint8_t buf[CMSG_SPACE(sizeof(struct in6_pktinfo))];
} cmsgbuf = { .buf = { 0 } };
struct msghdr msg = {
- .msg_name = &dst, .msg_namelen = sizeof(dst),
- .msg_iov = iov, .msg_iovlen = __arraycount(iov),
+ .msg_name = &dst,
+ .msg_namelen = sizeof(dst),
+ .msg_iov = iov,
+ .msg_iovlen = __arraycount(iov),
};
char uaddr[INET6_ADDRSTRLEN];
if (!IN6_IS_ADDR_UNSPECIFIED(&state->unicast)) {
switch (state->send->type) {
- case DHCP6_SOLICIT: /* FALLTHROUGH */
- case DHCP6_CONFIRM: /* FALLTHROUGH */
+ case DHCP6_SOLICIT: /* FALLTHROUGH */
+ case DHCP6_CONFIRM: /* FALLTHROUGH */
case DHCP6_REBIND:
/* Unicasting is denied for these types. */
break;
dst.sin6_addr = multicast ? alldhcp : state->unicast;
if (!callback) {
- logdebugx("%s: %s %s with xid 0x%02x%02x%02x%s%s",
- ifp->name,
+ logdebugx("%s: %s %s with xid 0x%02x%02x%02x%s%s", ifp->name,
multicast ? "multicasting" : "unicasting",
- dhcp6_get_op(state->send->type),
- state->send->xid[0],
- state->send->xid[1],
- state->send->xid[2],
- !multicast ? " " : "",
- !multicast ? uaddr : "");
+ dhcp6_get_op(state->send->type), state->send->xid[0],
+ state->send->xid[1], state->send->xid[2],
+ !multicast ? " " : "", !multicast ? uaddr : "");
RT = 0;
} else {
if (state->IMD &&
}
/* Add -.1 to .1 * RT randomness as per RFC8415 section 15 */
- uint32_t lru = arc4random_uniform(
- state->RTC == 0 ? DHCP6_RAND_MAX
- : DHCP6_RAND_MAX - DHCP6_RAND_MIN);
+ uint32_t lru = arc4random_uniform(state->RTC == 0 ?
+ DHCP6_RAND_MAX :
+ DHCP6_RAND_MAX - DHCP6_RAND_MIN);
int lr = (int)lru - (state->RTC == 0 ? 0 : DHCP6_RAND_MAX);
- RT = state->RT
- + (unsigned int)((float)state->RT
- * ((float)lr / DHCP6_RAND_DIV));
+ RT = state->RT +
+ (unsigned int)((float)state->RT *
+ ((float)lr / DHCP6_RAND_DIV));
if (if_is_link_up(ifp))
logdebugx("%s: %s %s (xid 0x%02x%02x%02x)%s%s,"
- " next in %0.1f seconds",
+ " next in %0.1f seconds",
ifp->name,
state->IMD != 0 ? "delaying" :
- multicast ? "multicasting" : "unicasting",
+ multicast ? "multicasting" :
+ "unicasting",
dhcp6_get_op(state->send->type),
- state->send->xid[0],
- state->send->xid[1],
+ state->send->xid[0], state->send->xid[1],
state->send->xid[2],
state->IMD == 0 && !multicast ? " " : "",
state->IMD == 0 && !multicast ? uaddr : "",
dhcp6_updateelapsed(ifp, state->send, state->send_len);
#ifdef AUTH
if (ifp->options->auth.options & DHCPCD_AUTH_SEND &&
- dhcp6_update_auth(ifp, state->send, state->send_len) == -1)
- {
+ dhcp6_update_auth(ifp, state->send, state->send_len) == -1) {
logerr("%s: %s: dhcp6_updateauth", __func__, ifp->name);
if (errno != ESRCH)
return -1;
if (state->RT < RT) /* Check overflow */
state->RT = RT;
if (state->MRC == 0 || state->RTC <= state->MRC)
- eloop_timeout_add_msec(ctx->eloop,
- RT, callback, ifp);
+ eloop_timeout_add_msec(ctx->eloop, RT, callback, ifp);
else if (state->MRC != 0 && state->MRCcallback)
- eloop_timeout_add_msec(ctx->eloop,
- RT, state->MRCcallback, ifp);
+ eloop_timeout_add_msec(ctx->eloop, RT,
+ state->MRCcallback, ifp);
else
- logwarnx("%s: sent %d times with no reply",
- ifp->name, state->RTC);
+ logwarnx("%s: sent %d times with no reply", ifp->name,
+ state->RTC);
}
return 0;
}
static void
dhcp6_sendinform(void *arg)
{
-
dhcp6_sendmessage(arg, dhcp6_sendinform);
}
static void
dhcp6_senddiscover2(void *arg)
{
-
dhcp6_sendmessage(arg, dhcp6_senddiscover2);
}
static void
dhcp6_sendrequest(void *arg)
{
-
dhcp6_sendmessage(arg, dhcp6_sendrequest);
}
static void
dhcp6_sendrebind(void *arg)
{
-
dhcp6_sendmessage(arg, dhcp6_sendrebind);
}
static void
dhcp6_sendrenew(void *arg)
{
-
dhcp6_sendmessage(arg, dhcp6_sendrenew);
}
static void
dhcp6_sendconfirm(void *arg)
{
-
dhcp6_sendmessage(arg, dhcp6_sendconfirm);
}
static void
dhcp6_senddecline(void *arg)
{
-
dhcp6_sendmessage(arg, dhcp6_senddecline);
}
static void
dhcp6_sendrelease(void *arg)
{
-
dhcp6_sendmessage(arg, dhcp6_sendrelease);
}
return;
/* Only renew in the bound or renew states */
- if (state->state != DH6S_BOUND &&
- state->state != DH6S_RENEW)
+ if (state->state != DH6S_BOUND && state->state != DH6S_RENEW)
return;
/* Remove the timeout as the renew may have been forced. */
dhcp6_sendrenew(ifp);
}
-void dhcp6_renew(struct interface *ifp)
+void
+dhcp6_renew(struct interface *ifp)
{
-
dhcp6_startrenew(ifp);
}
oneduplicated = false;
TAILQ_FOREACH(ia2, &state->addrs, next) {
if (ia2->flags & IPV6_AF_ADDED &&
- !(ia2->flags & IPV6_AF_DADCOMPLETED))
- {
+ !(ia2->flags & IPV6_AF_DADCOMPLETED)) {
completed = false;
break;
}
#ifndef SMALL
ia->delegating_prefix ? "DELEGATED6" :
#endif
- state->reason);
+ state->reason);
if (valid)
dhcpcd_daemonise(ifp->ctx);
}
for (i = 0; i < ifp->options->ia_len; i++) {
ia = &ifp->options->ia[i];
if (!((ia->ia_type == D6_OPTION_IA_PD && ia->prefix_len) ||
- !IN6_IS_ADDR_UNSPECIFIED(&ia->addr)))
+ !IN6_IS_ADDR_UNSPECIFIED(&ia->addr)))
continue;
a = ipv6_newaddr(ifp, &ia->addr,
- /*
- * RFC 5942 Section 5
- * We cannot assume any prefix length, nor tie the
- * address to an existing one as it could expire
- * before the address.
- * As such we just give it a 128 prefix.
- */
+ /*
+ * RFC 5942 Section 5
+ * We cannot assume any prefix length, nor tie the
+ * address to an existing one as it could expire
+ * before the address.
+ * As such we just give it a 128 prefix.
+ */
ia->ia_type == D6_OPTION_IA_PD ? ia->prefix_len : 128,
IPV6_AF_REQUEST);
if (a == NULL)
dhcp6_delete_delegates(ifp);
#endif
/* Ensure we never request INFO_REFRESH_TIME,
- * this only belongs in Information-Request messages */
+ * this only belongs in Information-Request messages */
del_option_mask(ifo->requestmask6, D6_OPTION_INFO_REFRESH_TIME);
if (state->new == NULL && !state->failed)
* This poor wording might explain the lack of similar text for INFORM
* in 18.1.5 because there are no addresses in the INFORM message. */
if (!state->failed)
- eloop_timeout_add_sec(ifp->ctx->eloop,
- INF_MAX_RD, dhcp6_failinform, ifp);
+ eloop_timeout_add_sec(ifp->ctx->eloop, INF_MAX_RD,
+ dhcp6_failinform, ifp);
}
static bool
dhcp_unlink(ifp->ctx, state->leasefile);
dhcp6_addrequestedaddrs(ifp);
eloop_timeout_delete(ifp->ctx->eloop, NULL, ifp);
- } else if ((state->state == DH6S_CONFIRM || state->state == DH6S_REBIND) &&
- ifp->options->options & DHCPCD_LASTLEASE) {
+ } else if ((state->state == DH6S_CONFIRM ||
+ state->state == DH6S_REBIND) &&
+ ifp->options->options & DHCPCD_LASTLEASE) {
dhcp6_bind(ifp, NULL, NULL);
state->state = DH6S_REBIND;
dhcp6_startrebind(ifp);
}
if (!dhcp6_startdiscoinform(ifp)) {
- logwarnx("%s: no advertising IPv6 router wants DHCP",ifp->name);
+ logwarnx("%s: no advertising IPv6 router wants DHCP",
+ ifp->name);
state->state = DH6S_INIT;
}
}
ifp->name);
eloop_timeout_delete(ifp->ctx->eloop, dhcp6_sendconfirm, ifp);
- /* RFC8415 18.2.3 says that prior addresses SHOULD be used on failure. */
+ /* RFC8415 18.2.3 says that prior addresses SHOULD be used on failure.
+ */
dhcp6_fail(ifp, false);
}
eloop_timeout_delete(ifp->ctx->eloop, dhcp6_sendrebind, ifp);
/* RFC8415 18.2.3 says that prior addresses SHOULD be used on failure.
- * 18.2 says REBIND rather than CONFIRM with PD but use CONFIRM timings. */
+ * 18.2 says REBIND rather than CONFIRM with PD but use CONFIRM timings.
+ */
dhcp6_fail(ifp, false);
}
state->IMD = CNF_MAX_DELAY;
state->IRT = CNF_TIMEOUT;
state->MRT = CNF_MAX_RT;
- eloop_timeout_add_sec(ifp->ctx->eloop,
- CNF_MAX_RD, dhcp6_failrebindpd, ifp);
+ eloop_timeout_add_sec(ifp->ctx->eloop, CNF_MAX_RD,
+ dhcp6_failrebindpd, ifp);
}
#endif
}
return;
}
dhcp6_sendconfirm(ifp);
- eloop_timeout_add_sec(ifp->ctx->eloop,
- CNF_MAX_RD, dhcp6_failconfirm, ifp);
+ eloop_timeout_add_sec(ifp->ctx->eloop, CNF_MAX_RD, dhcp6_failconfirm,
+ ifp);
}
static void
}
static int
-dhcp6_checkstatusok(const struct interface *ifp,
- struct dhcp6_message *m, uint8_t *p, size_t len)
+dhcp6_checkstatusok(const struct interface *ifp, struct dhcp6_message *m,
+ uint8_t *p, size_t len)
{
struct dhcp6_state *state;
uint8_t *opt;
uint16_t opt_len, code;
size_t mlen;
- void * (*f)(void *, size_t, uint16_t, uint16_t *), *farg;
+ void *(*f)(void *, size_t, uint16_t, uint16_t *), *farg;
char buf[32], *sbuf;
const char *status;
int loglevel;
else
farg = m;
if ((opt = f(farg, len, D6_OPTION_STATUS_CODE, &opt_len)) == NULL) {
- //logdebugx("%s: no status", ifp->name);
+ // logdebugx("%s: no status", ifp->name);
state->lerror = 0;
errno = ESRCH;
return 0;
/* RFC 3315 22.6 */
if (ia.pltime > ia.vltime) {
errno = EINVAL;
- logerr("%s: IA Address pltime %"PRIu32
- " > vltime %"PRIu32,
+ logerr("%s: IA Address pltime %" PRIu32
+ " > vltime %" PRIu32,
ifp->name, ia.pltime, ia.vltime);
continue;
}
a->prefix_vltime = ia.vltime;
}
if (a->prefix_pltime && a->prefix_pltime < state->lowpl)
- state->lowpl = a->prefix_pltime;
+ state->lowpl = a->prefix_pltime;
if (a->prefix_vltime && a->prefix_vltime > state->expire)
- state->expire = a->prefix_vltime;
+ state->expire = a->prefix_vltime;
i++;
}
return i;
#ifndef SMALL
static int
-dhcp6_findpd(struct interface *ifp, const uint8_t *iaid,
- uint8_t *d, size_t l, const struct timespec *acquired)
+dhcp6_findpd(struct interface *ifp, const uint8_t *iaid, uint8_t *d, size_t l,
+ const struct timespec *acquired)
{
struct dhcp6_state *state;
uint8_t *o, *nd;
/* RFC 3315 22.6 */
if (pdp_pltime > pdp_vltime) {
errno = EINVAL;
- logerrx("%s: IA Prefix pltime %"PRIu32
- " > vltime %"PRIu32,
+ logerrx("%s: IA Prefix pltime %" PRIu32
+ " > vltime %" PRIu32,
ifp->name, pdp_pltime, pdp_vltime);
continue;
}
l -= sizeof(o) + o.len;
o.code = ntohs(o.code);
- switch(o.code) {
+ switch (o.code) {
case D6_OPTION_IA_TA:
nl = 4;
break;
break;
}
if (j == ifo->ia_len &&
- !(ifo->ia_len == 0 && ifp->ctx->options & DHCPCD_DUMPLEASE))
- {
- logdebugx("%s: ignoring unrequested IAID %s",
- ifp->name,
- hwaddr_ntoa(ia.iaid, sizeof(ia.iaid),
- buf, sizeof(buf)));
+ !(ifo->ia_len == 0 &&
+ ifp->ctx->options & DHCPCD_DUMPLEASE)) {
+ logdebugx("%s: ignoring unrequested IAID %s", ifp->name,
+ hwaddr_ntoa(ia.iaid, sizeof(ia.iaid), buf,
+ sizeof(buf)));
continue;
}
logwarnx("%s: IAID %s T1(%d) > T2(%d) from %s",
ifp->name,
hwaddr_ntoa(iaid, sizeof(iaid), buf,
- sizeof(buf)),
+ sizeof(buf)),
ia.t1, ia.t2, sfrom);
continue;
}
}
if (o.code == D6_OPTION_IA_PD) {
#ifndef SMALL
- if (dhcp6_findpd(ifp, ia.iaid, p, o.len,
- acquired) == 0)
- {
+ if (dhcp6_findpd(ifp, ia.iaid, p, o.len, acquired) ==
+ 0) {
logwarnx("%s: %s: DHCPv6 REPLY missing Prefix",
ifp->name, sfrom);
continue;
#endif
} else {
if (dhcp6_findna(ifp, o.code, ia.iaid, p, o.len,
- acquired) == 0)
- {
+ acquired) == 0) {
logwarnx("%s: %s: DHCPv6 REPLY missing "
- "IA Address",
+ "IA Address",
ifp->name, sfrom);
continue;
}
* try and prefer other addresses. */
ia->prefix_pltime = 0;
} else if (ia->prefix_vltime == 0)
- loginfox("%s: %s: no valid lifetime",
- ia->iface->name, ia->saddr);
+ loginfox("%s: %s: no valid lifetime", ia->iface->name,
+ ia->saddr);
else
continue;
}
static int
-dhcp6_validatelease(struct interface *ifp,
- struct dhcp6_message *m, size_t len,
+dhcp6_validatelease(struct interface *ifp, struct dhcp6_message *m, size_t len,
const char *sfrom, const struct timespec *acquired)
{
struct dhcp6_state *state;
state->has_no_binding = false;
nia = dhcp6_findia(ifp, m, len, sfrom, acquired);
if (nia == 0 && state->state == DH6S_CONFIRM && ok_errno == 0 &&
- state->new && state->new_len)
- {
+ state->new && state->new_len) {
state->has_no_binding = false;
- nia = dhcp6_findia(ifp, state->new, state->new_len,
- sfrom, acquired);
+ nia = dhcp6_findia(ifp, state->new, state->new_len, sfrom,
+ acquired);
}
if (nia == 0) {
logerrx("%s: no useable IA found in lease", ifp->name);
logdebugx("reading standard input");
bytes = read(fileno(stdin), buf.buf, sizeof(buf.buf));
} else {
- logdebugx("%s: reading lease: %s",
- ifp->name, state->leasefile);
- bytes = dhcp_readfile(ifp->ctx, state->leasefile,
- buf.buf, sizeof(buf.buf));
+ logdebugx("%s: reading lease: %s", ifp->name, state->leasefile);
+ bytes = dhcp_readfile(ifp->ctx, state->leasefile, buf.buf,
+ sizeof(buf.buf));
}
if (bytes == -1)
goto ex;
}
if (state->expire != ND6_INFINITE_LIFETIME &&
- (time_t)state->expire < now - mtime)
- {
+ (time_t)state->expire < now - mtime) {
logdebugx("%s: discarding expired lease", ifp->name);
bytes = 0;
goto ex;
o = dhcp6_findmoption(&buf.dhcp6, (size_t)bytes, D6_OPTION_AUTH, &ol);
if (o) {
if (dhcp_auth_validate(&state->auth, &ifp->options->auth,
- buf.buf, (size_t)bytes, 6, buf.dhcp6.type, o, ol) == NULL)
- {
+ buf.buf, (size_t)bytes, 6, buf.dhcp6.type, o,
+ ol) == NULL) {
logerr("%s: authentication failed", ifp->name);
bytes = 0;
goto ex;
}
if (state->auth.token)
- logdebugx("%s: validated using 0x%08" PRIu32,
- ifp->name, state->auth.token->secretid);
+ logdebugx("%s: validated using 0x%08" PRIu32, ifp->name,
+ state->auth.token->secretid);
else
loginfox("%s: accepted reconfigure key", ifp->name);
} else if ((ifp->options->auth.options & DHCPCD_AUTH_SENDREQUIRE) ==
- DHCPCD_AUTH_SENDREQUIRE)
- {
+ DHCPCD_AUTH_SENDREQUIRE) {
logerrx("%s: authentication now required", ifp->name);
goto ex;
}
}
}
- if (!(ifp->ctx->options & DHCPCD_TEST) &&
- !(has_ta && !has_non_ta) &&
- ifo->reboot != 0)
- {
+ if (!(ifp->ctx->options & DHCPCD_TEST) && !(has_ta && !has_non_ta) &&
+ ifo->reboot != 0) {
r = dhcp6_readlease(ifp, 1);
if (r == -1) {
if (errno != ENOENT && errno != ESRCH)
logerr("%s: %s", __func__, state->leasefile);
- } else if (r != 0 &&
- !(ifo->options & DHCPCD_ANONYMOUS))
- {
+ } else if (r != 0 && !(ifo->options & DHCPCD_ANONYMOUS)) {
/* RFC 3633 section 12.1 */
#ifndef SMALL
if (state->state == DH6S_MANUALREBIND ||
/* Don't spam the log automatically */
if (sla != NULL)
logwarnx("%s: DHCPv6 server does not support "
- "OPTION_PD_EXCLUDE",
+ "OPTION_PD_EXCLUDE",
ifp->name);
return NULL;
}
pfxlen = prefix->prefix_exclude_len;
memcpy(&addr, &prefix->prefix_exclude, sizeof(addr));
- } else if ((pfxlen = dhcp6_delegateaddr(&addr, ifp, prefix,
- sla, if_ia)) == -1)
+ } else if ((pfxlen = dhcp6_delegateaddr(&addr, ifp, prefix, sla,
+ if_ia)) == -1)
return NULL;
if (sla != NULL && fls64(sla->suffix) > 128 - pfxlen) {
if (ap->flags & IPV6_AF_ONLINK) {
if (!(ap->flags & IPV6_AF_DADCOMPLETED) &&
ipv6_iffindaddr(ap->iface, &ap->addr,
- IN6_IFF_TENTATIVE))
+ IN6_IFF_TENTATIVE))
ap->flags |= IPV6_AF_DADCOMPLETED;
if ((ap->flags & IPV6_AF_DADCOMPLETED) == 0
#ifndef SMALL
&& ((delegated && ap->delegating_prefix) ||
- (!delegated && !ap->delegating_prefix))
+ (!delegated && !ap->delegating_prefix))
#endif
- )
- {
+ ) {
completed = 0;
break;
}
size_t
dhcp6_find_delegates(__unused struct interface *ifp)
{
-
return 0;
}
#else
if (ia->ia_type != D6_OPTION_IA_PD)
continue;
if (memcmp(ia->iaid, ap->iaid,
- sizeof(ia->iaid)))
+ sizeof(ia->iaid)))
continue;
if (ia->sla_len == 0) {
/* no SLA configured, so lets
carrier_warned = true;
break;
}
- if (dhcp6_ifdelegateaddr(ifd, ap,
- NULL, ia))
+ if (dhcp6_ifdelegateaddr(ifd, ap, NULL,
+ ia))
k++;
}
for (j = 0; j < ia->sla_len; j++) {
carrier_warned = true;
break;
}
- if (dhcp6_ifdelegateaddr(ifd, ap,
- sla, ia))
+ if (dhcp6_ifdelegateaddr(ifd, ap, sla,
+ ia))
k++;
}
if (carrier_warned)
static void
dhcp6_find_delegates1(void *arg)
{
-
dhcp6_find_delegates(arg);
}
struct if_sla *sla;
struct interface *ifd;
- if (ifp->options != NULL &&
- !(ifp->options->options & DHCPCD_CONFIGURE))
+ if (ifp->options != NULL && !(ifp->options->options & DHCPCD_CONFIGURE))
return 0;
k = 0;
if (ia->ia_type != D6_OPTION_IA_PD)
continue;
if (memcmp(ia->iaid, ap->iaid,
- sizeof(ia->iaid)))
+ sizeof(ia->iaid)))
continue;
for (j = 0; j < ia->sla_len; j++) {
sla = &ia->sla[j];
dhcp6_find_delegates1, ifp);
return 1;
}
- if (dhcp6_ifdelegateaddr(ifp, ap,
- sla, ia))
- k++;
+ if (dhcp6_ifdelegateaddr(ifp, ap, sla,
+ ia))
+ k++;
}
}
}
state->new_start = false;
if (!timedout) {
- logmessage(loglevel, "%s: %s received from %s",
- ifp->name, op, sfrom);
+ logmessage(loglevel, "%s: %s received from %s", ifp->name, op,
+ sfrom);
#ifndef SMALL
/* If we delegated from an unconfirmed lease we MUST drop
* them now. Hopefully we have new delegations. */
eloop_timeout_delete(ifp->ctx->eloop, NULL, ifp);
clock_gettime(CLOCK_MONOTONIC, &now);
- switch(state->state) {
- case DH6S_INFORM:
- {
+ switch (state->state) {
+ case DH6S_INFORM: {
struct dhcp6_option *o;
uint16_t ol;
if (state->reason == NULL)
state->reason = "INFORM6";
o = dhcp6_findmoption(state->recv, state->recv_len,
- D6_OPTION_INFO_REFRESH_TIME, &ol);
+ D6_OPTION_INFO_REFRESH_TIME, &ol);
if (o == NULL || ol != sizeof(uint32_t))
state->renew = IRT_DEFAULT;
else {
state->rebind = 0;
state->expire = ND6_INFINITE_LIFETIME;
state->lowpl = ND6_INFINITE_LIFETIME;
- }
- break;
+ } break;
case DH6S_REQUEST:
if (state->reason == NULL)
TAILQ_FOREACH(ia, &state->addrs, next) {
if (ia->flags & IPV6_AF_STALE)
continue;
- if (!(state->renew == ND6_INFINITE_LIFETIME
- && ia->prefix_vltime == ND6_INFINITE_LIFETIME)
- && ia->prefix_vltime != 0
- && ia->prefix_vltime <= state->renew)
+ if (!(state->renew == ND6_INFINITE_LIFETIME &&
+ ia->prefix_vltime ==
+ ND6_INFINITE_LIFETIME) &&
+ ia->prefix_vltime != 0 &&
+ ia->prefix_vltime <= state->renew)
logwarnx(
"%s: %s will expire before renewal",
ifp->name, ia->saddr);
* and T2 fields for the T1 and T2 parameters,
* unless those values in those fields are 0.
*/
- logwarnx("%s: ignoring T1 %"PRIu32
- " due to address expiry",
+ logwarnx("%s: ignoring T1 %" PRIu32
+ " due to address expiry",
ifp->name, state->renew);
state->renew = state->rebind = 0;
}
/* Reduce timers based on when we got the lease. */
uint32_t elapsed;
- elapsed = (uint32_t)eloop_timespec_diff(&now,
- &state->acquired, NULL);
+ elapsed = (uint32_t)eloop_timespec_diff(&now, &state->acquired,
+ NULL);
if (state->renew && state->renew != ND6_INFINITE_LIFETIME) {
if (state->renew > elapsed)
state->renew -= elapsed;
* or REBIND right away if the timers have expired */
if ((state->renew || (state->rebind && confirmed)) &&
state->renew != ND6_INFINITE_LIFETIME)
- eloop_timeout_add_sec(ifp->ctx->eloop,
- state->renew,
- state->state == DH6S_INFORMED ?
- dhcp6_startinform : dhcp6_startrenew, ifp);
+ eloop_timeout_add_sec(ifp->ctx->eloop, state->renew,
+ state->state == DH6S_INFORMED ? dhcp6_startinform :
+ dhcp6_startrenew,
+ ifp);
if ((state->rebind || (state->expire && confirmed)) &&
state->rebind != ND6_INFINITE_LIFETIME)
- eloop_timeout_add_sec(ifp->ctx->eloop,
- state->rebind, dhcp6_startrebind, ifp);
+ eloop_timeout_add_sec(ifp->ctx->eloop, state->rebind,
+ dhcp6_startrebind, ifp);
if (state->expire != ND6_INFINITE_LIFETIME)
- eloop_timeout_add_sec(ifp->ctx->eloop,
- state->expire, dhcp6_startexpire, ifp);
+ eloop_timeout_add_sec(ifp->ctx->eloop, state->expire,
+ dhcp6_startexpire, ifp);
if (ifp->options->options & DHCPCD_CONFIGURE) {
ipv6_addaddrs(&state->addrs);
}
if (state->state == DH6S_INFORMED)
- logmessage(loglevel, "%s: refresh in %"PRIu32" seconds",
- ifp->name, state->renew);
+ logmessage(loglevel,
+ "%s: refresh in %" PRIu32 " seconds", ifp->name,
+ state->renew);
else if (state->renew == ND6_INFINITE_LIFETIME)
logmessage(loglevel, "%s: leased for infinity",
ifp->name);
else if (state->renew || state->rebind)
- logmessage(loglevel, "%s: renew in %"PRIu32", "
- "rebind in %"PRIu32", "
- "expire in %"PRIu32" seconds",
- ifp->name,
- state->renew, state->rebind, state->expire);
+ logmessage(loglevel,
+ "%s: renew in %" PRIu32 ", "
+ "rebind in %" PRIu32 ", "
+ "expire in %" PRIu32 " seconds",
+ ifp->name, state->renew, state->rebind,
+ state->expire);
else if (state->expire == 0)
logmessage(loglevel, "%s: will expire", ifp->name);
else
- logmessage(loglevel, "%s: expire in %"PRIu32" seconds",
- ifp->name, state->expire);
+ logmessage(loglevel,
+ "%s: expire in %" PRIu32 " seconds", ifp->name,
+ state->expire);
rt_build(ifp->ctx, AF_INET6);
if (!confirmed && !timedout) {
- logdebugx("%s: writing lease: %s",
- ifp->name, state->leasefile);
+ logdebugx("%s: writing lease: %s", ifp->name,
+ state->leasefile);
if (dhcp_writefile(ifp->ctx, state->leasefile, 0640,
- state->new, state->new_len) == -1)
- logerr("dhcp_writefile: %s",state->leasefile);
+ state->new, state->new_len) == -1)
+ logerr("dhcp_writefile: %s", state->leasefile);
}
#ifndef SMALL
dhcp6_delegate_prefix(ifp);
}
static void
-dhcp6_adjust_max_rt(struct interface *ifp,
- struct dhcp6_message *r, size_t len)
+dhcp6_adjust_max_rt(struct interface *ifp, struct dhcp6_message *r, size_t len)
{
struct dhcp6_state *state = D6_STATE(ifp);
uint8_t *o;
memcpy(&max_rt, o, sizeof(max_rt));
max_rt = ntohl(max_rt);
if (max_rt >= 60 && max_rt <= 86400) {
- logdebugx("%s: SOL_MAX_RT %llu -> %u",
- ifp->name,
- (unsigned long long)state->sol_max_rt,
- max_rt);
+ logdebugx("%s: SOL_MAX_RT %llu -> %u", ifp->name,
+ (unsigned long long)state->sol_max_rt, max_rt);
state->sol_max_rt = max_rt;
} else
logerrx("%s: invalid SOL_MAX_RT %u", ifp->name, max_rt);
memcpy(&max_rt, o, sizeof(max_rt));
max_rt = ntohl(max_rt);
if (max_rt >= 60 && max_rt <= 86400) {
- logdebugx("%s: INF_MAX_RT %llu -> %u",
- ifp->name,
- (unsigned long long)state->inf_max_rt,
- max_rt);
+ logdebugx("%s: INF_MAX_RT %llu -> %u", ifp->name,
+ (unsigned long long)state->inf_max_rt, max_rt);
state->inf_max_rt = max_rt;
} else
logerrx("%s: invalid INF_MAX_RT %u", ifp->name, max_rt);
}
static void
-dhcp6_recvif(struct interface *ifp, const char *sfrom,
- struct dhcp6_message *r, size_t len)
+dhcp6_recvif(struct interface *ifp, const char *sfrom, struct dhcp6_message *r,
+ size_t len)
{
struct dhcpcd_ctx *ctx;
size_t i;
/* We're already bound and this message is for another machine */
/* XXX DELEGATED? */
if (r->type != DHCP6_RECONFIGURE &&
- (state->state == DH6S_BOUND || state->state == DH6S_INFORMED))
- {
+ (state->state == DH6S_BOUND || state->state == DH6S_INFORMED)) {
logdebugx("%s: DHCPv6 reply received but already bound",
ifp->name);
return;
}
ifo = ifp->options;
- for (i = 0, opt = ctx->dhcp6_opts;
- i < ctx->dhcp6_opts_len;
- i++, opt++)
- {
+ for (i = 0, opt = ctx->dhcp6_opts; i < ctx->dhcp6_opts_len;
+ i++, opt++) {
if (has_option_mask(ifo->requiremask6, opt->option) &&
- !dhcp6_findmoption(r, len, (uint16_t)opt->option, NULL))
- {
+ !dhcp6_findmoption(r, len, (uint16_t)opt->option, NULL)) {
logwarnx("%s: reject DHCPv6 (no option %s) from %s",
ifp->name, opt->var, sfrom);
return;
}
if (has_option_mask(ifo->rejectmask6, opt->option) &&
- dhcp6_findmoption(r, len, (uint16_t)opt->option, NULL))
- {
+ dhcp6_findmoption(r, len, (uint16_t)opt->option, NULL)) {
logwarnx("%s: reject DHCPv6 (option %s) from %s",
ifp->name, opt->var, sfrom);
return;
/* Authenticate the message */
auth = dhcp6_findmoption(r, len, D6_OPTION_AUTH, &auth_len);
if (auth != NULL) {
- if (dhcp_auth_validate(&state->auth, &ifo->auth,
- (uint8_t *)r, len, 6, r->type, auth, auth_len) == NULL)
- {
- logerr("%s: authentication failed from %s",
- ifp->name, sfrom);
+ if (dhcp_auth_validate(&state->auth, &ifo->auth, (uint8_t *)r,
+ len, 6, r->type, auth, auth_len) == NULL) {
+ logerr("%s: authentication failed from %s", ifp->name,
+ sfrom);
return;
}
if (state->auth.token)
- logdebugx("%s: validated using 0x%08" PRIu32,
- ifp->name, state->auth.token->secretid);
+ logdebugx("%s: validated using 0x%08" PRIu32, ifp->name,
+ state->auth.token->secretid);
else
loginfox("%s: accepted reconfigure key", ifp->name);
} else if (ifo->auth.options & DHCPCD_AUTH_SEND) {
if (ifo->auth.options & DHCPCD_AUTH_REQUIRE) {
- logerrx("%s: no authentication from %s",
- ifp->name, sfrom);
+ logerrx("%s: no authentication from %s", ifp->name,
+ sfrom);
return;
}
logwarnx("%s: no authentication from %s", ifp->name, sfrom);
op = dhcp6_get_op(r->type);
valid_op = op != NULL;
- switch(r->type) {
+ switch (r->type) {
case DHCP6_REPLY:
- switch(state->state) {
+ switch (state->state) {
case DH6S_INFORM:
if (dhcp6_checkstatusok(ifp, r, NULL, len) != 0)
return;
break;
case DH6S_CONFIRM:
- if (dhcp6_validatelease(ifp, r, len, sfrom, NULL) == -1)
- {
+ if (dhcp6_validatelease(ifp, r, len, sfrom, NULL) ==
+ -1) {
dhcp6_startdiscoinform(ifp);
return;
}
/* Only accept REPLY in DISCOVER for RAPID_COMMIT.
* Normally we get an ADVERTISE for a DISCOVER. */
if (!has_option_mask(ifo->requestmask6,
- D6_OPTION_RAPID_COMMIT) ||
+ D6_OPTION_RAPID_COMMIT) ||
!dhcp6_findmoption(r, len, D6_OPTION_RAPID_COMMIT,
- NULL))
- {
+ NULL)) {
valid_op = false;
break;
}
/* Validate lease before setting state to REQUEST. */
/* FALLTHROUGH */
case DH6S_REQUEST: /* FALLTHROUGH */
- case DH6S_RENEW: /* FALLTHROUGH */
+ case DH6S_RENEW: /* FALLTHROUGH */
case DH6S_REBIND:
dhcp6_adjust_max_rt(ifp, r, len);
- if (dhcp6_validatelease(ifp, r, len, sfrom, NULL) == -1)
- {
+ if (dhcp6_validatelease(ifp, r, len, sfrom, NULL) ==
+ -1) {
/*
* If we can't use the lease, fallback to
* DISCOVER and try and get a new one.
}
/* RFC8415 18.2.10.1 */
if ((state->state == DH6S_RENEW ||
- state->state == DH6S_REBIND) &&
- state->has_no_binding)
- {
+ state->state == DH6S_REBIND) &&
+ state->has_no_binding) {
dhcp6_startrequest(ifp);
return;
}
case DH6S_DECLINE:
/* This isnt really a failure, but an
* acknowledgement of one. */
- loginfox("%s: %s acknowledged DECLINE6",
- ifp->name, sfrom);
+ loginfox("%s: %s acknowledged DECLINE6", ifp->name,
+ sfrom);
dhcp6_fail(ifp, true);
return;
case DH6S_RELEASE:
- loginfox("%s: %s acknowledged RELEASE6",
- ifp->name, sfrom);
+ loginfox("%s: %s acknowledged RELEASE6", ifp->name,
+ sfrom);
dhcp6_finishrelease(ifp);
return;
default:
#ifdef AUTH
if (auth == NULL) {
#endif
- logerrx("%s: unauthenticated %s from %s",
- ifp->name, op, sfrom);
+ logerrx("%s: unauthenticated %s from %s", ifp->name, op,
+ sfrom);
if (ifo->auth.options & DHCPCD_AUTH_REQUIRE)
return;
#ifdef AUTH
ifp->name);
return;
}
- switch(*o) {
+ switch (*o) {
case DHCP6_RENEW:
if (state->state != DH6S_BOUND) {
- logerrx("%s: not bound, ignoring %s",
- ifp->name, op);
+ logerrx("%s: not bound, ignoring %s", ifp->name,
+ op);
return;
}
dhcp6_startrenew(ifp);
ifp->name, op);
return;
}
- eloop_timeout_delete(ifp->ctx->eloop,
- dhcp6_sendinform, ifp);
+ eloop_timeout_delete(ifp->ctx->eloop, dhcp6_sendinform,
+ ifp);
dhcp6_startinform(ifp);
break;
default:
- logerr("%s: unsupported %s type %d",
- ifp->name, op, *o);
+ logerr("%s: unsupported %s type %d", ifp->name, op, *o);
break;
}
return;
break;
#endif
default:
- logerrx("%s: invalid DHCP6 type %s (%d)",
- ifp->name, op, r->type);
+ logerrx("%s: invalid DHCP6 type %s (%d)", ifp->name, op,
+ r->type);
return;
}
if (!valid_op) {
- logwarnx("%s: invalid state for DHCP6 type %s (%d)",
- ifp->name, op, r->type);
+ logwarnx("%s: invalid state for DHCP6 type %s (%d)", ifp->name,
+ op, r->type);
return;
}
if (ia == NULL)
ia = TAILQ_FIRST(&state->addrs);
if (ia == NULL)
- loginfox("%s: ADV (no address) from %s (%u)",
- ifp->name, sfrom, preference);
+ loginfox("%s: ADV (no address) from %s (%u)", ifp->name,
+ sfrom, preference);
else
- loginfox("%s: ADV %s from %s (%u)",
- ifp->name, ia->saddr, sfrom, preference);
+ loginfox("%s: ADV %s from %s (%u)", ifp->name,
+ ia->saddr, sfrom, preference);
/*
* RFC 8415 18.2.1 says we must collect until ADVERTISEMENTs
dp = ctx->duid;
}
if (o == NULL || ol != duid_len || memcmp(o, dp, ol) != 0) {
- logdebugx("%s: incorrect client ID from %s",
- ifp->name, sfrom);
+ logdebugx("%s: incorrect client ID from %s", ifp->name, sfrom);
return;
}
if (dhcp6_findmoption(r, len, D6_OPTION_SERVERID, NULL) == NULL) {
- logdebugx("%s: no DHCPv6 server ID from %s",
- ifp->name, sfrom);
+ logdebugx("%s: no DHCPv6 server ID from %s", ifp->name, sfrom);
return;
}
}
state = D6_CSTATE(ifp);
- if (state == NULL ||
- r->xid[0] != state->send->xid[0] ||
+ if (state == NULL || r->xid[0] != state->send->xid[0] ||
r->xid[1] != state->send->xid[1] ||
- r->xid[2] != state->send->xid[2])
- {
+ r->xid[2] != state->send->xid[2]) {
struct interface *ifp1;
const struct dhcp6_state *state1;
if (ifp1 == NULL) {
if (state != NULL)
logdebugx("%s: wrong xid 0x%02x%02x%02x"
- " (expecting 0x%02x%02x%02x) from %s",
- ifp->name,
- r->xid[0], r->xid[1], r->xid[2],
- state->send->xid[0],
- state->send->xid[1],
- state->send->xid[2],
- sfrom);
+ " (expecting 0x%02x%02x%02x) from %s",
+ ifp->name, r->xid[0], r->xid[1], r->xid[2],
+ state->send->xid[0], state->send->xid[1],
+ state->send->xid[2], sfrom);
return;
}
- logdebugx("%s: redirecting DHCP6 message to %s",
- ifp->name, ifp1->name);
+ logdebugx("%s: redirecting DHCP6 message to %s", ifp->name,
+ ifp1->name);
ifp = ifp1;
}
uint8_t buf[UDPLEN_MAX]; /* Maximum UDP message size */
} iovbuf;
struct iovec iov = {
- .iov_base = iovbuf.buf, .iov_len = sizeof(iovbuf.buf),
+ .iov_base = iovbuf.buf,
+ .iov_len = sizeof(iovbuf.buf),
};
union {
struct cmsghdr hdr;
uint8_t buf[CMSG_SPACE(sizeof(struct in6_pktinfo))];
} cmsgbuf = { .buf = { 0 } };
struct msghdr msg = {
- .msg_name = &from, .msg_namelen = sizeof(from),
- .msg_iov = &iov, .msg_iovlen = 1,
- .msg_control = cmsgbuf.buf, .msg_controllen = sizeof(cmsgbuf.buf),
+ .msg_name = &from,
+ .msg_namelen = sizeof(from),
+ .msg_iov = &iov,
+ .msg_iovlen = 1,
+ .msg_control = cmsgbuf.buf,
+ .msg_controllen = sizeof(cmsgbuf.buf),
};
int s;
ssize_t bytes;
size_t i;
const struct dhcp_compat *dhc;
- if ((ctx->options & (DHCPCD_MANAGER|DHCPCD_PRIVSEP)) == DHCPCD_MANAGER &&
- ctx->dhcp6_rfd == -1)
- {
+ if ((ctx->options & (DHCPCD_MANAGER | DHCPCD_PRIVSEP)) ==
+ DHCPCD_MANAGER &&
+ ctx->dhcp6_rfd == -1) {
ctx->dhcp6_rfd = dhcp6_openudp(0, NULL);
if (ctx->dhcp6_rfd == -1) {
logerr(__func__);
return;
}
if (eloop_event_add(ctx->eloop, ctx->dhcp6_rfd, ELE_READ,
- dhcp6_recvctx, ctx) == -1)
+ dhcp6_recvctx, ctx) == -1)
logerr("%s: eloop_event_add", __func__);
}
}
if (i == sizeof(ifo->requestmask6)) {
for (dhc = dhcp_compats; dhc->dhcp_opt; dhc++) {
- if (DHC_REQ(ifo->requestmask, ifo->nomask, dhc->dhcp_opt))
+ if (DHC_REQ(ifo->requestmask, ifo->nomask,
+ dhc->dhcp_opt))
add_option_mask(ifo->requestmask6,
dhc->dhcp6_opt);
}
* pl/vl time of the RA changing. */
if (state->state == DH6S_INIT ||
(state->state == DH6S_DISCOVER &&
- !(ifp->options->options & DHCPCD_IA_FORCED) &&
- !ipv6nd_hasradhcp(ifp, true)))
+ !(ifp->options->options & DHCPCD_IA_FORCED) &&
+ !ipv6nd_hasradhcp(ifp, true)))
dhcp6_startinform(ifp);
break;
case DH6S_REQUEST:
if (ifp->options->options & DHCPCD_DHCP6 &&
(state->state == DH6S_INIT ||
- state->state == DH6S_INFORM ||
- state->state == DH6S_INFORMED ||
- state->state == DH6S_DELEGATED))
- {
+ state->state == DH6S_INFORM ||
+ state->state == DH6S_INFORMED ||
+ state->state == DH6S_DELEGATED)) {
/* Change from stateless to stateful */
init_state = DH6S_INIT;
goto gogogo;
state->new_start = true;
state->lerror = 0;
state->failed = false;
- dhcp_set_leasefile(state->leasefile, sizeof(state->leasefile),
- AF_INET6, ifp);
+ dhcp_set_leasefile(state->leasefile, sizeof(state->leasefile), AF_INET6,
+ ifp);
if (ipv6_linklocal(ifp) == NULL) {
logdebugx("%s: delaying DHCPv6 for LL address", ifp->name);
ipv6_addlinklocalcallback(ifp, dhcp6_start1, ifp);
}
if (drop && options & DHCPCD_RELEASE &&
- state->state != DH6S_DELEGATED)
- {
+ state->state != DH6S_DELEGATED) {
if (if_is_link_up(ifp) &&
state->state != DH6S_RELEASED &&
- state->state != DH6S_INFORMED)
- {
+ state->state != DH6S_INFORMED) {
dhcp6_startrelease(ifp);
return;
}
state->new = NULL;
state->new_len = 0;
if (drop && state->old &&
- (options & DHCPCD_NODROP) != DHCPCD_NODROP)
- {
+ (options & DHCPCD_NODROP) != DHCPCD_NODROP) {
if (reason == NULL)
reason = "STOP6";
script_runreason(ifp, reason);
void
dhcp6_drop(struct interface *ifp, const char *reason)
{
-
dhcp6_freedrop(ifp, 1, reason);
}
void
dhcp6_free(struct interface *ifp)
{
-
dhcp6_freedrop(ifp, 0, NULL);
}
eloop_timeout_delete(ifp->ctx->eloop, dhcp6_sendinform, ifp);
switch (state->state) {
- case DH6S_DISCOVER: /* FALLTHROUGH */
- case DH6S_REQUEST: /* FALLTHROUGH */
+ case DH6S_DISCOVER: /* FALLTHROUGH */
+ case DH6S_REQUEST: /* FALLTHROUGH */
case DH6S_INFORM:
state->state = DH6S_INIT;
break;
struct interface *ifp = ia->iface;
/* If not running in manager mode, listen to this address */
- if (cmd == RTM_NEWADDR &&
- !(ia->addr_flags & IN6_IFF_NOTUSEABLE) &&
+ if (cmd == RTM_NEWADDR && !(ia->addr_flags & IN6_IFF_NOTUSEABLE) &&
ifp->active == IF_ACTIVE_USER &&
!(ifp->ctx->options & DHCPCD_MANAGER) &&
- ifp->options->options & DHCPCD_DHCP6)
- {
+ ifp->options->options & DHCPCD_DHCP6) {
#ifdef PRIVSEP
if (IN_PRIVSEP_SE(ifp->ctx)) {
if (ps_inet_opendhcp6(ia) == -1)
ia->dhcp6_fd = dhcp6_openudp(ia->iface->index,
&ia->addr);
if (ia->dhcp6_fd != -1 &&
- eloop_event_add(ia->iface->ctx->eloop,
- ia->dhcp6_fd, ELE_READ, dhcp6_recvaddr, ia) == -1)
+ eloop_event_add(ia->iface->ctx->eloop, ia->dhcp6_fd,
+ ELE_READ, dhcp6_recvaddr, ia) == -1)
logerr("%s: eloop_event_add", __func__);
}
}
ctx = ifp->ctx;
/* Zero our indexes */
- for (i = 0, opt = ctx->dhcp6_opts;
- i < ctx->dhcp6_opts_len;
- i++, opt++)
+ for (i = 0, opt = ctx->dhcp6_opts; i < ctx->dhcp6_opts_len; i++, opt++)
dhcp_zero_index(opt);
for (i = 0, opt = ifp->options->dhcp6_override;
- i < ifp->options->dhcp6_override_len;
- i++, opt++)
+ i < ifp->options->dhcp6_override_len; i++, opt++)
dhcp_zero_index(opt);
- for (i = 0, opt = ctx->vivso;
- i < ctx->vivso_len;
- i++, opt++)
+ for (i = 0, opt = ctx->vivso; i < ctx->vivso_len; i++, opt++)
dhcp_zero_index(opt);
if (asprintf(&pfx, "%s_dhcp6", prefix) == -1)
return -1;
len -= sizeof(o);
o.len = ntohs(o.len);
if (len < o.len) {
- errno = EINVAL;
+ errno = EINVAL;
break;
}
o.code = ntohs(o.code);
if (has_option_mask(ifo->nomask6, o.code))
continue;
for (i = 0, opt = ifo->dhcp6_override;
- i < ifo->dhcp6_override_len;
- i++, opt++)
+ i < ifo->dhcp6_override_len; i++, opt++)
if (opt->option == o.code)
break;
if (i == ifo->dhcp6_override_len &&
- o.code == D6_OPTION_VENDOR_OPTS &&
- o.len > sizeof(en))
- {
+ o.code == D6_OPTION_VENDOR_OPTS && o.len > sizeof(en)) {
memcpy(&en, p, sizeof(en));
en = ntohl(en);
vo = vivso_find(en, ifp);
vo = NULL;
if (i == ifo->dhcp6_override_len) {
for (i = 0, opt = ctx->dhcp6_opts;
- i < ctx->dhcp6_opts_len;
- i++, opt++)
+ i < ctx->dhcp6_opts_len; i++, opt++)
if (opt->option == o.code)
break;
if (i == ctx->dhcp6_opts_len)
opt = NULL;
}
if (opt) {
- dhcp_envoption(ifp->ctx,
- fp, pfx, ifp->name,
- opt, dhcp6_getoption, p, o.len);
+ dhcp_envoption(ifp->ctx, fp, pfx, ifp->name, opt,
+ dhcp6_getoption, p, o.len);
}
if (vo) {
- dhcp_envoption(ifp->ctx,
- fp, pfx, ifp->name,
- vo, dhcp6_getoption,
- p + sizeof(en),
+ dhcp_envoption(ifp->ctx, fp, pfx, ifp->name, vo,
+ dhcp6_getoption, p + sizeof(en),
o.len - sizeof(en));
}
}
#include "dhcpcd.h"
-#define IN6ADDR_LINKLOCAL_ALLDHCP_INIT \
- {{{ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02 }}}
+#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
+#define DHCP6_CLIENT_PORT 546
+#define DHCP6_SERVER_PORT 547
/* DHCP message type */
#define DHCP6_SOLICIT 1
#define DHCP6_RELAY_FLOW 12
#define DHCP6_RELAY_REPL 13
#define DHCP6_RECONFIGURE_REQ 18
-#define DHCP6_RECONFIGURE_REPLY 19
+#define DHCP6_RECONFIGURE_REPLY 19
#ifdef DHCP6
-#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_USER_CLASS 15
-#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_NTP_SERVER 56
-#define D6_OPTION_PD_EXCLUDE 67
-#define D6_OPTION_SOL_MAX_RT 82
-#define D6_OPTION_INF_MAX_RT 83
-#define D6_OPTION_MUDURL 112
-
-#define D6_FQDN_PTR 0x00
-#define D6_FQDN_BOTH 0x01
-#define D6_FQDN_NONE 0x04
+#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_USER_CLASS 15
+#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_NTP_SERVER 56
+#define D6_OPTION_PD_EXCLUDE 67
+#define D6_OPTION_SOL_MAX_RT 82
+#define D6_OPTION_INF_MAX_RT 83
+#define D6_OPTION_MUDURL 112
+
+#define D6_FQDN_PTR 0x00
+#define D6_FQDN_BOTH 0x01
+#define D6_FQDN_NONE 0x04
#include "dhcp.h"
#include "ipv6.h"
-#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 /* RFC 8415 */
-#define SOL_MAX_RC 0
-#define REQ_MAX_DELAY 0
-#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_RC 0
-#define CNF_MAX_RD 10
-#define REN_MAX_DELAY 0
-#define REN_TIMEOUT 10
-#define REN_MAX_RT 600
-#define REB_MAX_DELAY 0
-#define REB_TIMEOUT 10
-#define REB_MAX_RT 600
-#define INF_MAX_DELAY 1
-#define INF_TIMEOUT 1
-#define INF_MAX_RD CNF_MAX_RD /* NOT RFC defined */
-#define INF_MAX_RT 3600 /* RFC 8415*/
-#define REL_MAX_DELAY 0
-#define REL_TIMEOUT 1
-#define REL_MAX_RT 0
-#define REL_MAX_RC 4 /* RFC 8415 */
-#define DEC_MAX_DELAY 0
-#define DEC_TIMEOUT 1
-#define DEC_MAX_RC 4 /* RFC 8415 */
-#define REC_MAX_DELAY 0
-#define REC_TIMEOUT 2
-#define REC_MAX_RC 8
-#define HOP_COUNT_LIMIT 32
+#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 /* RFC 8415 */
+#define SOL_MAX_RC 0
+#define REQ_MAX_DELAY 0
+#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_RC 0
+#define CNF_MAX_RD 10
+#define REN_MAX_DELAY 0
+#define REN_TIMEOUT 10
+#define REN_MAX_RT 600
+#define REB_MAX_DELAY 0
+#define REB_TIMEOUT 10
+#define REB_MAX_RT 600
+#define INF_MAX_DELAY 1
+#define INF_TIMEOUT 1
+#define INF_MAX_RD CNF_MAX_RD /* NOT RFC defined */
+#define INF_MAX_RT 3600 /* RFC 8415*/
+#define REL_MAX_DELAY 0
+#define REL_TIMEOUT 1
+#define REL_MAX_RT 0
+#define REL_MAX_RC 4 /* RFC 8415 */
+#define DEC_MAX_DELAY 0
+#define DEC_TIMEOUT 1
+#define DEC_MAX_RC 4 /* RFC 8415 */
+#define REC_MAX_DELAY 0
+#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 IRT_DEFAULT 86400
+#define IRT_MINIMUM 600
/* These should give -.1 to .1 randomness */
-#define DHCP6_RAND_MIN -100
-#define DHCP6_RAND_MAX 100
-#define DHCP6_RAND_DIV 1000.0f
+#define DHCP6_RAND_MIN -100
+#define DHCP6_RAND_MAX 100
+#define DHCP6_RAND_DIV 1000.0f
enum DH6S {
DH6S_INIT,
void (*MRCcallback)(void *);
unsigned int sol_max_rt;
unsigned int inf_max_rt;
- unsigned int RT; /* retransmission timer in milliseconds
- * maximal RT is 1 day + RAND,
- * so should be enough */
+ unsigned int RT; /* retransmission timer in milliseconds
+ * maximal RT is 1 day + RAND,
+ * so should be enough */
struct dhcp6_message *send;
size_t send_len;
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];
+ char leasefile[sizeof(LEASEFILE6) + IF_NAMESIZE + (IF_SSIDLEN * 4) + 3];
const char *reason;
uint16_t lerror; /* Last error received from DHCPv6 reply. */
bool has_no_binding;
- bool failed; /* Entered the failed state - used to rate limit log. */
+ bool failed; /* Entered the failed state - used to rate limit log. */
bool new_start; /* New external start, to determine log type. */
#ifdef AUTH
struct authstate auth;
#endif
};
-#define D6_STATE(ifp) \
- ((struct dhcp6_state *)(ifp)->if_data[IF_DATA_DHCP6])
-#define D6_CSTATE(ifp) \
+#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_STATE_RUNNING(ifp) \
+ (D6_CSTATE((ifp)) && D6_CSTATE((ifp))->reason && \
+ dhcp6_dadcompleted((ifp)))
int dhcp6_openraw(void);
int dhcp6_openudp(unsigned int, struct in6_addr *);
void dhcp6_recvmsg(struct dhcpcd_ctx *, struct msghdr *, struct ipv6_addr *);
-void dhcp6_printoptions(const struct dhcpcd_ctx *,
- const struct dhcp_opt *, size_t);
+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, unsigned int flags);
struct ipv6_addr *dhcp6_findaddr(struct dhcpcd_ctx *, const struct in6_addr *,
static const char dhcpcd_copyright[] = "Copyright (c) 2006-2025 Roy Marples";
+#include <sys/types.h>
#include <sys/file.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/time.h>
-#include <sys/types.h>
#include <sys/uio.h>
#include <sys/wait.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
-#include <unistd.h>
#include <time.h>
+#include <unistd.h>
-#include "config.h"
#include "arp.h"
#include "common.h"
+#include "config.h"
#include "control.h"
#include "dev.h"
#include "dhcp-common.h"
-#include "dhcpcd.h"
#include "dhcp.h"
#include "dhcp6.h"
+#include "dhcpcd.h"
#include "duid.h"
#include "eloop.h"
-#include "if.h"
#include "if-options.h"
+#include "if.h"
#include "ipv4.h"
#include "ipv4ll.h"
#include "ipv6.h"
static void
usage(void)
{
-
-printf("usage: "PACKAGE"\t[-146ABbDdEGgHJKLMNPpqTV]\n"
- "\t\t[-C, --nohook hook] [-c, --script script]\n"
- "\t\t[-e, --env value] [-F, --fqdn FQDN] [-f, --config file]\n"
- "\t\t[-h, --hostname hostname] [-I, --clientid clientid]\n"
- "\t\t[-i, --vendorclassid vendorclassid] [-j, --logfile logfile]\n"
- "\t\t[-l, --leasetime seconds] [-m, --metric metric]\n"
- "\t\t[-O, --nooption option] [-o, --option option]\n"
- "\t\t[-Q, --require option] [-r, --request address]\n"
- "\t\t[-S, --static value]\n"
- "\t\t[-s, --inform address[/cidr[/broadcast_address]]] [--inform6]\n"
- "\t\t[-t, --timeout seconds] [-u, --userclass class]\n"
- "\t\t[-v, --vendor code, value] [-W, --whitelist address[/cidr]] [-w]\n"
- "\t\t[--waitip [4 | 6]] [-y, --reboot seconds]\n"
- "\t\t[-X, --blacklist address[/cidr]] [-Z, --denyinterfaces pattern]\n"
- "\t\t[-z, --allowinterfaces pattern] [--inactive] [interface] [...]\n"
- " "PACKAGE"\t-n, --rebind [interface]\n"
- " "PACKAGE"\t-k, --release [interface]\n"
- " "PACKAGE"\t-U, --dumplease interface\n"
- " "PACKAGE"\t--version\n"
- " "PACKAGE"\t-x, --exit [interface]\n");
+ printf(
+ "usage: " PACKAGE "\t[-146ABbDdEGgHJKLMNPpqTV]\n"
+ "\t\t[-C, --nohook hook] [-c, --script script]\n"
+ "\t\t[-e, --env value] [-F, --fqdn FQDN] [-f, --config file]\n"
+ "\t\t[-h, --hostname hostname] [-I, --clientid clientid]\n"
+ "\t\t[-i, --vendorclassid vendorclassid] [-j, --logfile logfile]\n"
+ "\t\t[-l, --leasetime seconds] [-m, --metric metric]\n"
+ "\t\t[-O, --nooption option] [-o, --option option]\n"
+ "\t\t[-Q, --require option] [-r, --request address]\n"
+ "\t\t[-S, --static value]\n"
+ "\t\t[-s, --inform address[/cidr[/broadcast_address]]] [--inform6]\n"
+ "\t\t[-t, --timeout seconds] [-u, --userclass class]\n"
+ "\t\t[-v, --vendor code, value] [-W, --whitelist address[/cidr]] [-w]\n"
+ "\t\t[--waitip [4 | 6]] [-y, --reboot seconds]\n"
+ "\t\t[-X, --blacklist address[/cidr]] [-Z, --denyinterfaces pattern]\n"
+ "\t\t[-z, --allowinterfaces pattern] [--inactive] [interface] [...]\n"
+ " " PACKAGE "\t-n, --rebind [interface]\n"
+ " " PACKAGE "\t-k, --release [interface]\n"
+ " " PACKAGE "\t-U, --dumplease interface\n"
+ " " PACKAGE "\t--version\n"
+ " " PACKAGE "\t-x, --exit [interface]\n");
}
static void
#ifdef INET
if (ctx->dhcp_opts) {
- for (opt = ctx->dhcp_opts;
- ctx->dhcp_opts_len > 0;
+ for (opt = ctx->dhcp_opts; ctx->dhcp_opts_len > 0;
opt++, ctx->dhcp_opts_len--)
free_dhcp_opt_embenc(opt);
free(ctx->dhcp_opts);
#endif
#ifdef INET6
if (ctx->nd_opts) {
- for (opt = ctx->nd_opts;
- ctx->nd_opts_len > 0;
+ for (opt = ctx->nd_opts; ctx->nd_opts_len > 0;
opt++, ctx->nd_opts_len--)
free_dhcp_opt_embenc(opt);
free(ctx->nd_opts);
}
#ifdef DHCP6
if (ctx->dhcp6_opts) {
- for (opt = ctx->dhcp6_opts;
- ctx->dhcp6_opts_len > 0;
+ for (opt = ctx->dhcp6_opts; ctx->dhcp6_opts_len > 0;
opt++, ctx->dhcp6_opts_len--)
free_dhcp_opt_embenc(opt);
free(ctx->dhcp6_opts);
#endif
#endif
if (ctx->vivso) {
- for (opt = ctx->vivso;
- ctx->vivso_len > 0;
+ for (opt = ctx->vivso; ctx->vivso_len > 0;
opt++, ctx->vivso_len--)
free_dhcp_opt_embenc(opt);
free(ctx->vivso);
static const char *
dhcpcd_af(int af)
{
-
switch (af) {
case AF_UNSPEC:
return "IP";
if (ifp->active != IF_ACTIVE_USER)
return AF_MAX;
-#define DHCPCD_WAITALL (DHCPCD_WAITIP4 | DHCPCD_WAITIP6)
+#define DHCPCD_WAITALL (DHCPCD_WAITIP4 | DHCPCD_WAITIP6)
opts = ifp->options->options;
#ifdef INET
if (opts & DHCPCD_WAITIP4 ||
- (opts & DHCPCD_WAITIP && !(opts & DHCPCD_WAITALL)))
- {
+ (opts & DHCPCD_WAITIP && !(opts & DHCPCD_WAITALL))) {
bool foundaddr = ipv4_hasaddr(ifp);
if (opts & DHCPCD_WAITIP4 && !foundaddr)
#endif
#ifdef INET6
if (opts & DHCPCD_WAITIP6 ||
- (opts & DHCPCD_WAITIP && !(opts & DHCPCD_WAITALL)))
- {
+ (opts & DHCPCD_WAITIP && !(opts & DHCPCD_WAITALL))) {
bool foundaddr = ipv6_hasaddr(ifp);
if (opts & DHCPCD_WAITIP6 && !foundaddr)
TAILQ_FOREACH(ifp, ctx->ifaces, next) {
if ((af = dhcpcd_ifafwaiting(ifp)) != AF_MAX) {
- logdebugx("%s: waiting for an %s address",
- ifp->name, dhcpcd_af(af));
+ logdebugx("%s: waiting for an %s address", ifp->name,
+ dhcpcd_af(af));
return 0;
}
}
if ((af = dhcpcd_afwaiting(ctx)) != AF_MAX) {
- logdebugx("waiting for an %s address",
- dhcpcd_af(af));
+ logdebugx("waiting for an %s address", dhcpcd_af(af));
return 0;
}
int exit_code;
if (ctx->options & DHCPCD_DAEMONISE &&
- !(ctx->options & (DHCPCD_DAEMONISED | DHCPCD_BACKGROUND)))
- {
+ !(ctx->options & (DHCPCD_DAEMONISED | DHCPCD_BACKGROUND))) {
if (!dhcpcd_ipwaited(ctx))
return;
}
static void
dhcpcd_drop_af(struct interface *ifp, int stop, int af)
{
-
if (af == AF_UNSPEC || af == AF_INET6) {
#ifdef DHCP6
dhcp6_drop(ifp, stop ? NULL : "EXPIRE6");
static void
dhcpcd_drop(struct interface *ifp, int stop)
{
-
dhcpcd_drop_af(ifp, stop, AF_UNSPEC);
}
static bool
dhcpcd_ifrunning(struct interface *ifp)
{
-
#ifdef INET
if (D_CSTATE(ifp) != NULL)
return true;
struct dhcpcd_ctx *ctx = ifp->ctx;
if (ifp->options == NULL ||
- !(ifp->options->options & DHCPCD_STOPPING) ||
- dhcpcd_ifrunning(ifp))
+ !(ifp->options->options & DHCPCD_STOPPING) || dhcpcd_ifrunning(ifp))
return;
/* De-activate the interface */
static void
stop_interface(struct interface *ifp)
{
-
loginfox("%s: removing interface", ifp->name);
ifp->options->options |= DHCPCD_STOPPING;
dhcpcd_drop(ifp, 1);
#ifdef INET6
/* We want to setup INET6 on the interface as soon as possible. */
- if (ifp->active == IF_ACTIVE_USER &&
- ifo->options & DHCPCD_IPV6 &&
- !(ifp->ctx->options & (DHCPCD_DUMPLEASE | DHCPCD_TEST)))
- {
+ if (ifp->active == IF_ACTIVE_USER && ifo->options & DHCPCD_IPV6 &&
+ !(ifp->ctx->options & (DHCPCD_DUMPLEASE | DHCPCD_TEST))) {
/* If not doing any DHCP, disable the RDNSS requirement. */
if (!(ifo->options & (DHCPCD_DHCP | DHCPCD_DHCP6)))
ifo->options &= ~DHCPCD_IPV6RA_REQRDNSS;
#ifdef DHCP6
if (ifo->ia_len == 0 && ifo->options & DHCPCD_IPV6 &&
- ifp->name[0] != '\0')
- {
+ ifp->name[0] != '\0') {
ifo->ia = malloc(sizeof(*ifo->ia));
if (ifo->ia == NULL)
logerr(__func__);
if (ifp->ssid_len) {
ssize_t r;
- r = print_string(pssid, sizeof(pssid), OT_ESCSTRING,
- ifp->ssid, ifp->ssid_len);
+ r = print_string(pssid, sizeof(pssid), OT_ESCSTRING, ifp->ssid,
+ ifp->ssid_len);
if (r == -1) {
logerr(__func__);
pssid[0] = '\0';
free_options(ifp->ctx, ifp->options);
ifp->options = ifo;
if (profile) {
- add_options(ifp->ctx, ifp->name, ifp->options,
- ifp->ctx->argc, ifp->ctx->argv);
+ add_options(ifp->ctx, ifp->name, ifp->options, ifp->ctx->argc,
+ ifp->ctx->argv);
configure_interface1(ifp);
}
return 1;
/* If the mtime has changed drop any old lease */
if (old != 0 && ifp->options->mtime != old) {
- logwarnx("%s: config file changed, expiring leases",
- ifp->name);
+ logwarnx("%s: config file changed, expiring leases", ifp->name);
dhcpcd_drop(ifp, 0);
}
}
static void
dhcpcd_initstate(struct interface *ifp, unsigned long long options)
{
-
- dhcpcd_initstate1(ifp,
- ifp->argv ? ifp->argc : ifp->ctx->argc,
- ifp->argv ? ifp->argv : ifp->ctx->argv,
- options);
+ dhcpcd_initstate1(ifp, ifp->argv ? ifp->argc : ifp->ctx->argc,
+ ifp->argv ? ifp->argv : ifp->ctx->argv, options);
}
static void
{
char pssid[IF_SSIDLEN * 4];
- if (print_string(pssid, sizeof(pssid), OT_ESCSTRING,
- ifp->ssid, ifp->ssid_len) == -1)
- {
+ if (print_string(pssid, sizeof(pssid), OT_ESCSTRING, ifp->ssid,
+ ifp->ssid_len) == -1) {
logerr(__func__);
return;
}
static void
dhcpcd_nocarrier_roaming(struct interface *ifp)
{
-
loginfox("%s: carrier lost - roaming", ifp->name);
#ifdef ARP
/* If we changed SSID network, drop leases */
if ((ifp->ssid_len != olen ||
- memcmp(ifp->ssid, ossid, ifp->ssid_len)) && ifp->active)
- {
+ memcmp(ifp->ssid, ossid, ifp->ssid_len)) &&
+ ifp->active) {
dhcpcd_reportssid(ifp);
dhcpcd_drop(ifp, 0);
#ifdef IPV4LL
continue;
if (ia_type == 0 &&
memcmp(ifn->options->iaid, iaid,
- sizeof(ifn->options->iaid)) == 0)
+ sizeof(ifn->options->iaid)) == 0)
break;
#ifdef INET6
for (i = 0; i < ifn->options->ia_len; i++) {
/* This is only a problem if the interfaces are on the same network. */
if (ifn)
- logerrx("%s: IAID conflicts with one assigned to %s",
- ifp->name, ifn->name);
+ logerrx("%s: IAID conflicts with one assigned to %s", ifp->name,
+ ifn->name);
}
static void
}
if (ifo->options & (DHCPCD_DUID | DHCPCD_IPV6) &&
- !(ifo->options & DHCPCD_ANONYMOUS))
- {
+ !(ifo->options & DHCPCD_ANONYMOUS)) {
char buf[sizeof(ifo->iaid) * 3];
#ifdef INET6
size_t i;
/* Report IAIDs */
loginfox("%s: IAID %s", ifp->name,
- hwaddr_ntoa(ifo->iaid, sizeof(ifo->iaid),
- buf, sizeof(buf)));
+ hwaddr_ntoa(ifo->iaid, sizeof(ifo->iaid), buf,
+ sizeof(buf)));
warn_iaid_conflict(ifp, 0, ifo->iaid);
#ifdef INET6
for (i = 0; i < ifo->ia_len; i++) {
ia = &ifo->ia[i];
if (memcmp(ifo->iaid, ia->iaid, sizeof(ifo->iaid))) {
- loginfox("%s: IA type %u IAID %s",
- ifp->name, ia->ia_type,
- hwaddr_ntoa(ia->iaid, sizeof(ia->iaid),
- buf, sizeof(buf)));
+ loginfox("%s: IA type %u IAID %s", ifp->name,
+ ia->ia_type,
+ hwaddr_ntoa(ia->iaid, sizeof(ia->iaid), buf,
+ sizeof(buf)));
warn_iaid_conflict(ifp, ia->ia_type, ia->iaid);
}
}
struct dhcpcd_ctx *ctx = ifp->ctx;
bool randmac_down;
- if (ifp->carrier <= LINK_DOWN &&
- ifp->options->randomise_hwaddr &&
- ifp->flags & IFF_UP)
- {
+ if (ifp->carrier <= LINK_DOWN && ifp->options->randomise_hwaddr &&
+ ifp->flags & IFF_UP) {
if_down(ifp);
randmac_down = true;
} else
randmac_down = false;
if ((!(ctx->options & DHCPCD_MANAGER) ||
- ifp->options->options & DHCPCD_IF_UP || randmac_down) &&
- !(ifp->flags & IFF_UP))
- {
+ ifp->options->options & DHCPCD_IF_UP || randmac_down) &&
+ !(ifp->flags & IFF_UP)) {
if (ifp->options->randomise_hwaddr &&
if_randomisemac(ifp) == -1)
logerr(__func__);
static void
run_preinit(struct interface *ifp)
{
-
if (ifp->ctx->options & DHCPCD_TEST)
return;
void
dhcpcd_activateinterface(struct interface *ifp, unsigned long long options)
{
-
if (ifp->active)
return;
struct ifaddrs *ifaddrs;
struct if_head *ifs;
struct interface *ifp, *iff;
- const char * const argv[] = { ifname };
+ const char *const argv[] = { ifname };
int e;
if (action == -1) {
ctx->link_rcvbuf);
socklen = sizeof(ctx->link_rcvbuf);
- if (setsockopt(ctx->link_fd, SOL_SOCKET,
- SO_RCVBUF, &ctx->link_rcvbuf, socklen) == -1)
+ if (setsockopt(ctx->link_fd, SOL_SOCKET, SO_RCVBUF, &ctx->link_rcvbuf,
+ socklen) == -1)
logerr(__func__);
}
#endif
struct interface *ifp, *ifn, *ifp1;
socklen = sizeof(rcvbuflen);
- if (getsockopt(ctx->link_fd, SOL_SOCKET,
- SO_RCVBUF, &rcvbuflen, &socklen) == -1) {
+ if (getsockopt(ctx->link_fd, SOL_SOCKET, SO_RCVBUF, &rcvbuflen,
+ &socklen) == -1) {
logerr("%s: getsockopt", __func__);
rcvbuflen = 0;
}
#endif
logerrx("route socket overflowed (rcvbuflen %d)"
- " - learning interface state", rcvbuflen);
+ " - learning interface state",
+ rcvbuflen);
/* Drain the socket.
* We cannot open a new one due to privsep. */
}
/* Add new interfaces */
- while ((ifp = TAILQ_FIRST(ifaces)) != NULL ) {
+ while ((ifp = TAILQ_FIRST(ifaces)) != NULL) {
TAILQ_REMOVE(ifaces, ifp, next);
ifp1 = if_find(ctx->ifaces, ifp->name);
if (ifp1 != NULL) {
}
void
-dhcpcd_handlehwaddr(struct interface *ifp,
- uint16_t hwtype, const void *hwaddr, uint8_t hwlen)
+dhcpcd_handlehwaddr(struct interface *ifp, uint16_t hwtype, const void *hwaddr,
+ uint8_t hwlen)
{
char buf[sizeof(ifp->hwaddr) * 3];
if (ifp->hwtype != hwtype) {
if (ifp->active)
loginfox("%s: hardware address type changed"
- " from %d to %d", ifp->name, ifp->hwtype, hwtype);
+ " from %d to %d",
+ ifp->name, ifp->hwtype, hwtype);
ifp->hwtype = hwtype;
}
}
static void
-reconf_reboot(struct dhcpcd_ctx *ctx, const bool reboot,
- const int argc, char **argv, const int oi)
+reconf_reboot(struct dhcpcd_ctx *ctx, const bool reboot, const int argc,
+ char **argv, const int oi)
{
int i;
struct interface *ifp;
}
ifp->argc = argc;
} else {
-alloc_args_err:
+ alloc_args_err:
ifp->argv = NULL;
ifp->argc = 0;
}
static void
dhcpcd_ifrenew(struct interface *ifp)
{
-
if (!ifp->active)
return;
return;
}
- if (sig != SIGCHLD && ctx->options & DHCPCD_FORKED)
- {
+ if (sig != SIGCHLD && ctx->options & DHCPCD_FORKED) {
if (ctx->fork_fd != -1 && sig != SIGHUP &&
send(ctx->fork_fd, &sig, sizeof(sig), MSG_EOR) == -1)
logerr("%s: send", __func__);
return;
ctx->options |= DHCPCD_EXITING;
- if (!(ctx->options & DHCPCD_TEST) &&
- stop_all_interfaces(ctx, opts))
- {
+ if (!(ctx->options & DHCPCD_TEST) && stop_all_interfaces(ctx, opts)) {
/* We stopped something, we will exit once that is done. */
return;
}
#endif
int
-dhcpcd_handleargs(struct dhcpcd_ctx *ctx, struct fd_list *fd,
- int argc, char **argv)
+dhcpcd_handleargs(struct dhcpcd_ctx *ctx, struct fd_list *fd, int argc,
+ char **argv)
{
struct interface *ifp;
struct if_options *ifo;
* write callback on the fd */
/* Make any change here in privsep-control.c as well. */
if (strcmp(*argv, "--version") == 0) {
- return control_queue(fd, UNCONST(VERSION),
- strlen(VERSION) + 1);
+ return control_queue(fd, UNCONST(VERSION), strlen(VERSION) + 1);
} else if (strcmp(*argv, "--getconfigfile") == 0) {
return control_queue(fd, UNCONST(fd->ctx->cffile),
strlen(fd->ctx->cffile) + 1);
oi = 0;
opts = 0;
do_reboot = do_renew = false;
- while ((opt = getopt_long(argc, argv, IF_OPTS, cf_options, &oi)) != -1)
- {
+ while (
+ (opt = getopt_long(argc, argv, IF_OPTS, cf_options, &oi)) != -1) {
switch (opt) {
case 'g':
/* Assumed if below not set */
if (opts & DHCPCD_DUMPLEASE) {
ctx->options |= DHCPCD_DUMPLEASE;
-dumplease:
+ dumplease:
nifaces = 0;
TAILQ_FOREACH(ifp, ctx->ifaces, next) {
if (!ifp->active)
}
ctx->options &= ~DHCPCD_DUMPLEASE;
return 0;
-dumperr:
+ dumperr:
ctx->options &= ~DHCPCD_DUMPLEASE;
return -1;
}
if (--ctx->ctl_extra != 0) {
putchar('\n');
if (eloop_event_add(ctx->eloop, ctx->control_fd, ELE_READ,
- dhcpcd_readdump1, ctx) == -1)
+ dhcpcd_readdump1, ctx) == -1)
logerr("%s: eloop_event_add", __func__);
return;
}
ctx->ctl_bufpos = 0;
if (eloop_event_add(ctx->eloop, ctx->control_fd, ELE_READ,
- dhcpcd_readdump2, ctx) == -1)
+ dhcpcd_readdump2, ctx) == -1)
logerr("%s: eloop_event_add", __func__);
return;
}
if (eloop_event_add(ctx->eloop, ctx->control_fd, ELE_READ,
- dhcpcd_readdump1, ctx) == -1)
+ dhcpcd_readdump1, ctx) == -1)
logerr("%s: eloop_event_add", __func__);
}
static int
dhcpcd_readdump(struct dhcpcd_ctx *ctx)
{
-
- ctx->options |= DHCPCD_FORKED;
- if (eloop_timeout_add_sec(ctx->eloop, 5,
- dhcpcd_readdumptimeout, ctx) == -1)
+ ctx->options |= DHCPCD_FORKED;
+ if (eloop_timeout_add_sec(ctx->eloop, 5, dhcpcd_readdumptimeout, ctx) ==
+ -1)
return -1;
return eloop_event_add(ctx->eloop, ctx->control_fd, ELE_READ,
dhcpcd_readdump0, ctx);
return;
}
if ((size_t)len < sizeof(exit_code)) {
- logerrx("%s: truncated read %zd (expected %zu)",
- __func__, len, sizeof(exit_code));
+ logerrx("%s: truncated read %zd (expected %zu)", __func__, len,
+ sizeof(exit_code));
eloop_exit(ctx->eloop, EXIT_FAILURE);
return;
}
if (pid == -1)
eloop_exit(ctx->eloop, EXIT_SUCCESS);
else
- eloop_timeout_add_msec(ctx->eloop, 100,
- dhcpcd_pidfile_timeout, ctx);
+ eloop_timeout_add_msec(ctx->eloop, 100, dhcpcd_pidfile_timeout,
+ ctx);
}
static void
}
}
-static int dup_null(int fd)
+static int
+dup_null(int fd)
{
int fd_null = open(_PATH_DEVNULL, O_WRONLY);
int err;
usage();
return EXIT_SUCCESS;
} else if (strcmp(argv[1], "--version") == 0) {
- printf(""PACKAGE" "VERSION"\n%s\n", dhcpcd_copyright);
+ printf("" PACKAGE " " VERSION "\n%s\n",
+ dhcpcd_copyright);
printf("Compiled in features:"
#ifdef INET
- " INET"
+ " INET"
#endif
#ifdef ARP
- " ARP"
+ " ARP"
#endif
#ifdef ARPING
- " ARPing"
+ " ARPing"
#endif
#ifdef IPV4LL
- " IPv4LL"
+ " IPv4LL"
#endif
#ifdef INET6
- " INET6"
+ " INET6"
#endif
#ifdef DHCP6
- " DHCPv6"
+ " DHCPv6"
#endif
#ifdef AUTH
- " AUTH"
+ " AUTH"
#endif
#ifdef PRIVSEP
- " PRIVSEP"
+ " PRIVSEP"
#endif
- "\n");
+ "\n");
return EXIT_SUCCESS;
}
}
/* Ensure we have stdin, stdout and stderr file descriptors.
* This is important as we do run scripts which expect these. */
- if (fcntl(STDIN_FILENO, F_GETFD) == -1)
+ if (fcntl(STDIN_FILENO, F_GETFD) == -1)
dup_null(STDIN_FILENO);
- if (fcntl(STDOUT_FILENO, F_GETFD) == -1)
+ if (fcntl(STDOUT_FILENO, F_GETFD) == -1)
dup_null(STDOUT_FILENO);
- if (fcntl(STDERR_FILENO, F_GETFD) == -1)
+ if (fcntl(STDERR_FILENO, F_GETFD) == -1)
dup_null(STDERR_FILENO);
else
logopts |= LOGERR_ERR;
i = 0;
- while ((opt = getopt_long(argc, argv,
- ctx.options & DHCPCD_PRINT_PIDFILE ? NOERR_IF_OPTS : IF_OPTS,
- cf_options, &oi)) != -1)
- {
+ while (
+ (opt = getopt_long(argc, argv,
+ ctx.options & DHCPCD_PRINT_PIDFILE ? NOERR_IF_OPTS : IF_OPTS,
+ cf_options, &oi)) != -1) {
switch (opt) {
case '4':
family = AF_INET;
#ifdef INET
if (family == 0 || family == AF_INET) {
printf("\nDHCPv4 options:\n");
- dhcp_printoptions(&ctx,
- ifo->dhcp_override, ifo->dhcp_override_len);
+ dhcp_printoptions(&ctx, ifo->dhcp_override,
+ ifo->dhcp_override_len);
}
#endif
#ifdef INET6
if (family == 0 || family == AF_INET6) {
printf("\nND options:\n");
- ipv6nd_printoptions(&ctx,
- ifo->nd_override, ifo->nd_override_len);
+ ipv6nd_printoptions(&ctx, ifo->nd_override,
+ ifo->nd_override_len);
#ifdef DHCP6
printf("\nDHCPv6 options:\n");
- dhcp6_printoptions(&ctx,
- ifo->dhcp6_override, ifo->dhcp6_override_len);
+ dhcp6_printoptions(&ctx, ifo->dhcp6_override,
+ ifo->dhcp6_override_len);
#endif
}
#endif
#endif
if (!(ctx.options & (DHCPCD_TEST | DHCPCD_DUMPLEASE))) {
-printpidfile:
+ printpidfile:
/* If we have any other args, we should run as a single dhcpcd
* instance for that interface. */
if (optind == argc - 1 && !(ctx.options & DHCPCD_MANAGER)) {
goto exit_failure;
}
/* Allow a dhcpcd interface per address family */
- switch(family) {
+ switch (family) {
case AF_INET:
per = "-4";
break;
default:
per = "";
}
- snprintf(ctx.pidfile, sizeof(ctx.pidfile),
- PIDFILE, ifname, per, ".");
+ snprintf(ctx.pidfile, sizeof(ctx.pidfile), PIDFILE,
+ ifname, per, ".");
} else {
- snprintf(ctx.pidfile, sizeof(ctx.pidfile),
- PIDFILE, "", "", "");
+ snprintf(ctx.pidfile, sizeof(ctx.pidfile), PIDFILE, "",
+ "", "");
ctx.options |= DHCPCD_MANAGER;
/*
signal(dhcpcd_signals_ignore[si], SIG_IGN);
/* Save signal mask, block and redirect signals to our handler */
- if (eloop_signal_set_cb(ctx.eloop,
- dhcpcd_signals, dhcpcd_signals_len,
- dhcpcd_signal_cb, &ctx) == -1)
- {
+ if (eloop_signal_set_cb(ctx.eloop, dhcpcd_signals, dhcpcd_signals_len,
+ dhcpcd_signal_cb, &ctx) == -1) {
logerr("%s: eloop_signal_set_cb", __func__);
goto exit_failure;
}
loginfox("waiting for pid %d to exit", (int)pid);
dhcpcd_pidfile_timeout(&ctx);
eloop_timeout_add_sec(ctx.eloop, 50,
- dhcpcd_exit_timeout, &ctx);
+ dhcpcd_exit_timeout, &ctx);
goto run_loop;
}
}
#ifdef HAVE_OPENSSL
OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_CIPHERS |
- OPENSSL_INIT_ADD_ALL_DIGESTS | OPENSSL_INIT_LOAD_CONFIG, NULL);
+ OPENSSL_INIT_ADD_ALL_DIGESTS | OPENSSL_INIT_LOAD_CONFIG,
+ NULL);
#endif
#ifdef PRIVSEP
#endif
#ifndef SMALL
- if (ctx.options & DHCPCD_DUMPLEASE &&
- ctx.ifc == 1 && ctx.ifv[0][0] == '-' && ctx.ifv[0][1] == '\0')
- {
+ if (ctx.options & DHCPCD_DUMPLEASE && ctx.ifc == 1 &&
+ ctx.ifv[0][0] == '-' && ctx.ifv[0][1] == '\0') {
ctx.options |= DHCPCD_FORKED; /* pretend child process */
#ifdef PRIVSEP
if (IN_PRIVSEP(&ctx) && ps_managersandbox(&ctx, NULL) == -1)
/* If asking dhcpcd to exit and we failed to
* send a signal or a message then we
* don't proceed past here. */
- if (ctx.options & DHCPCD_DUMPLEASE ||
- sig == SIGTERM || sig == SIGALRM)
- {
+ if (ctx.options & DHCPCD_DUMPLEASE || sig == SIGTERM ||
+ sig == SIGALRM) {
if (errno == ENOENT)
- logerrx(PACKAGE" is not running");
+ logerrx(PACKAGE " is not running");
goto exit_failure;
}
if (errno == EPERM || errno == EACCES)
logerr("%s: mkdir: %s", __func__, RUNDIR);
if ((pid = pidfile_lock(ctx.pidfile)) != 0) {
if (pid == -1)
- logerr("%s: pidfile_lock: %s",
- __func__, ctx.pidfile);
+ logerr("%s: pidfile_lock: %s", __func__,
+ ctx.pidfile);
else
logerrx(PACKAGE
" already running on pid %d (%s)",
if (!(ctx.options & DHCPCD_DAEMONISE))
goto start_manager;
- if (xsocketpair(AF_UNIX, SOCK_SEQPACKET|SOCK_CXNB, 0, fork_fd) == -1) {
+ if (xsocketpair(AF_UNIX, SOCK_SEQPACKET | SOCK_CXNB, 0, fork_fd) ==
+ -1) {
logerr("socketpair");
goto exit_failure;
}
goto exit_failure;
}
if (eloop_event_add(ctx.eloop, ctx.fork_fd, ELE_READ,
- dhcpcd_fork_cb, &ctx) == -1)
- {
+ dhcpcd_fork_cb, &ctx) == -1) {
logerr("%s: eloop_event_add", __func__);
goto exit_failure;
}
}
#endif
if (eloop_event_add(ctx.eloop, ctx.fork_fd, ELE_READ,
- dhcpcd_fork_cb, &ctx) == -1)
+ dhcpcd_fork_cb, &ctx) == -1)
logerr("%s: eloop_event_add", __func__);
#ifdef PRIVSEP
if (!(ctx.options & DHCPCD_TEST)) {
if (control_start(&ctx,
- ctx.options & DHCPCD_MANAGER ?
- NULL : argv[optind], family) == -1)
- {
+ ctx.options & DHCPCD_MANAGER ? NULL : argv[optind],
+ family) == -1) {
logerr("%s: control_start", __func__);
goto exit_failure;
}
* change the interface name provided by the kernel */
if (!IN_PRIVSEP(&ctx) &&
(ctx.options & (DHCPCD_MANAGER | DHCPCD_DEV)) ==
- (DHCPCD_MANAGER | DHCPCD_DEV))
+ (DHCPCD_MANAGER | DHCPCD_DEV))
dev_start(&ctx, dhcpcd_handleinterface);
#endif
/* Start handling kernel messages for interfaces, addresses and
* routes. */
- if (eloop_event_add(ctx.eloop, ctx.link_fd, ELE_READ,
- dhcpcd_handlelink, &ctx) == -1)
+ if (eloop_event_add(ctx.eloop, ctx.link_fd, ELE_READ, dhcpcd_handlelink,
+ &ctx) == -1)
logerr("%s: eloop_event_add", __func__);
#ifdef PRIVSEP
}
for (i = 0; i < ctx.ifc; i++) {
if ((ifp = if_find(ctx.ifaces, ctx.ifv[i])) == NULL)
- logerrx("%s: interface not found",
- ctx.ifv[i]);
+ logerrx("%s: interface not found", ctx.ifv[i]);
else if (!ifp->active)
logerrx("%s: interface has an invalid configuration",
ctx.ifv[i]);
if (ctx.ifc == 0) {
int loglevel;
- loglevel = ctx.options & DHCPCD_INACTIVE ?
- LOG_DEBUG : LOG_ERR;
+ loglevel = ctx.options & DHCPCD_INACTIVE ? LOG_DEBUG :
+ LOG_ERR;
logmessage(loglevel, "no valid interfaces found");
dhcpcd_daemonise(&ctx);
} else
}
}
}
- if (opt == 0 &&
- ctx.options & DHCPCD_LINK &&
- !(ctx.options & DHCPCD_WAITIP))
- {
+ if (opt == 0 && ctx.options & DHCPCD_LINK &&
+ !(ctx.options & DHCPCD_WAITIP)) {
int loglevel;
- loglevel = ctx.options & DHCPCD_INACTIVE ?
- LOG_DEBUG : LOG_WARNING;
+ loglevel = ctx.options & DHCPCD_INACTIVE ? LOG_DEBUG :
+ LOG_WARNING;
logmessage(loglevel, "no interfaces have a carrier");
dhcpcd_daemonise(&ctx);
} else if (t > 0 &&
/* Test mode removes the daemonise bit, so check for both */
- ctx.options & (DHCPCD_DAEMONISE | DHCPCD_TEST))
- {
- eloop_timeout_add_sec(ctx.eloop, t,
- handle_exit_timeout, &ctx);
+ ctx.options & (DHCPCD_DAEMONISE | DHCPCD_TEST)) {
+ eloop_timeout_add_sec(ctx.eloop, t, handle_exit_timeout,
+ &ctx);
}
}
free_options(&ctx, ifo);
#define DHCPCD_H
#include <sys/socket.h>
+
#include <net/if.h>
#include <stdio.h>
#include "config.h"
-#include "defs.h"
#include "control.h"
+#include "defs.h"
#include "if-options.h"
#include "queue.h"
-#define HWADDR_LEN 20
-#define IF_SSIDLEN 32
-#define PROFILE_LEN 64
-#define SECRET_LEN 64
+#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 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 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
+#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
#ifdef __QNX__
/* QNX carries defines for, but does not actually support PF_LINK */
/* dhcpcd requires CMSG_SPACE to evaluate to a compile time constant. */
#if defined(__QNX) || \
- (defined(__NetBSD_Version__) && __NetBSD_Version__ < 600000000)
+ (defined(__NetBSD_Version__) && __NetBSD_Version__ < 600000000)
#undef CMSG_SPACE
#endif
#define ALIGNBYTES (sizeof(int) - 1)
#endif
#ifndef ALIGN
-#define ALIGN(p) (((unsigned int)(p) + ALIGNBYTES) & ~ALIGNBYTES)
+#define ALIGN(p) (((unsigned int)(p) + ALIGNBYTES) & ~ALIGNBYTES)
#endif
#ifndef CMSG_SPACE
-#define CMSG_SPACE(len) (ALIGN(sizeof(struct cmsghdr)) + ALIGN(len))
+#define CMSG_SPACE(len) (ALIGN(sizeof(struct cmsghdr)) + ALIGN(len))
#endif
struct passwd;
struct dhcpcd_ctx {
char pidfile[sizeof(PIDFILE) + IF_NAMESIZE + 1];
char vendor[256];
- int fork_fd; /* FD for the fork init signal pipe */
+ int fork_fd; /* FD for the fork init signal pipe */
const char *cffile;
unsigned long long options;
char *logfile;
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 */
+ 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 */
uint8_t duid_type;
unsigned char *duid;
size_t duid_len;
size_t ctl_bufpos;
size_t ctl_extra;
- rb_tree_t routes; /* our routes */
+ rb_tree_t routes; /* our routes */
#ifdef RT_FREE_ROUTE_TABLE
- rb_tree_t froutes; /* free routes for re-use */
+ rb_tree_t froutes; /* free routes for re-use */
#endif
- size_t rt_order; /* route order storage */
+ size_t rt_order; /* route order storage */
int pf_inet_fd;
#ifdef PF_LINK
#ifndef SMALL
int link_rcvbuf;
#endif
- int seq; /* route message sequence no */
- int sseq; /* successful seq no sent */
+ int seq; /* route message sequence no */
+ int sseq; /* successful seq no sent */
struct eloop *eloop;
#endif
#ifdef PRIVSEP
- struct passwd *ps_user; /* struct passwd for privsep user */
- struct ps_process_head ps_processes; /* List of spawned processes */
+ struct passwd *ps_user; /* struct passwd for privsep user */
+ struct ps_process_head ps_processes; /* List of spawned processes */
struct ps_process *ps_root;
struct ps_process *ps_inet;
struct ps_process *ps_ctl;
- int ps_data_fd; /* data returned from processes */
- int ps_log_fd; /* chroot logging */
- int ps_log_root_fd; /* outside chroot log reader */
- struct fd_list *ps_control; /* Queue for the above */
- struct fd_list *ps_control_client; /* Queue for the above */
+ int ps_data_fd; /* data returned from processes */
+ int ps_log_fd; /* chroot logging */
+ int ps_log_root_fd; /* outside chroot log reader */
+ struct fd_list *ps_control; /* Queue for the above */
+ struct fd_list *ps_control_client; /* Queue for the above */
#endif
#ifdef INET
* SUCH DAMAGE.
*/
-#define UUID_LEN 36
-#define DUID_TIME_EPOCH 946684800
+#define UUID_LEN 36
+#define DUID_TIME_EPOCH 946684800
+#include <sys/types.h>
#include <sys/param.h>
#include <sys/socket.h>
-#include <sys/types.h>
#ifdef BSD
-# include <sys/sysctl.h>
+#include <sys/sysctl.h>
#endif
-#include <arpa/inet.h>
-
#include <net/if.h>
#include <net/if_arp.h>
+#include <arpa/inet.h>
#include <errno.h>
#include <stdint.h>
#include <stdio.h>
#if defined(HW_UUID) /* OpenBSD */
int mib[] = { CTL_HW, HW_UUID };
- r = sysctl(mib, sizeof(mib)/sizeof(mib[0]), uuid, &len, NULL, 0);
+ r = sysctl(mib, sizeof(mib) / sizeof(mib[0]), uuid, &len, NULL, 0);
#elif defined(KERN_HOSTUUID) /* FreeBSD */
int mib[] = { CTL_KERN, KERN_HOSTUUID };
- r = sysctl(mib, sizeof(mib)/sizeof(mib[0]), uuid, &len, NULL, 0);
+ r = sysctl(mib, sizeof(mib) / sizeof(mib[0]), uuid, &len, NULL, 0);
#elif defined(__NetBSD__)
r = sysctlbyname("machdep.dmi.system-uuid", uuid, &len, NULL, 0);
#elif defined(__linux__)
} else {
if (ctx->duid_type != DUID_LL)
logwarnx("no interfaces have a fixed hardware "
- "address");
+ "address");
return duid_make(data, ifp, DUID_LL);
}
}
size_t
duid_init(struct dhcpcd_ctx *ctx, const struct interface *ifp)
{
-
if (ctx->duid == NULL)
ctx->duid_len = duid_get(ctx, ifp);
return ctx->duid_len;
#ifndef DUID_H
#define DUID_H
-#define DUID_LEN 128 + 2
-#define DUID_DEFAULT 0
-#define DUID_LLT 1
-#define DUID_LL 3
-#define DUID_UUID 4
+#define DUID_LEN 128 + 2
+#define DUID_DEFAULT 0
+#define DUID_LLT 1
+#define DUID_LL 3
+#define DUID_UUID 4
size_t duid_make(void *, const struct interface *, uint16_t);
size_t duid_init(struct dhcpcd_ctx *, const struct interface *);
* SUCH DAMAGE.
*/
-#include <sys/ioctl.h>
+#include <sys/types.h>
#include <sys/param.h>
+#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/sysctl.h>
#include <sys/time.h>
-#include <sys/types.h>
#include <sys/uio.h>
#include <sys/utsname.h>
-#include "config.h"
-
-#include <arpa/inet.h>
#include <net/bpf.h>
#include <net/if.h>
#include <net/if_dl.h>
#include <net/if_media.h>
#include <net/route.h>
-#include <netinet/if_ether.h>
#include <netinet/in.h>
#include <netinet/in_var.h>
#include <netinet6/in6_var.h>
#include <netinet6/nd6.h>
+#include <netinet/if_ether.h>
+
+#include <arpa/inet.h>
+
+#include "config.h"
#ifdef __NetBSD__
#include <net/if_vlanvar.h> /* Needs netinet/if_ether.h */
#elif defined(__DragonFly__)
#include <net/if_vlan_var.h>
#endif
#ifdef __DragonFly__
-# include <netproto/802_11/ieee80211_ioctl.h>
+#include <netproto/802_11/ieee80211_ioctl.h>
#else
-# include <net80211/ieee80211.h>
-# include <net80211/ieee80211_ioctl.h>
+#include <net80211/ieee80211.h>
+#include <net80211/ieee80211_ioctl.h>
#endif
#include <assert.h>
#include "common.h"
#include "dhcp.h"
-#include "if.h"
#include "if-options.h"
+#include "if.h"
#include "ipv4.h"
#include "ipv4ll.h"
#include "ipv6.h"
#include "sa.h"
#ifndef RT_ROUNDUP
-#define RT_ROUNDUP(a) \
+#define RT_ROUNDUP(a) \
((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long))
#define RT_ADVANCE(x, n) (x += RT_ROUNDUP((n)->sa_len))
#endif
/* Ignore these interface names which look like ethernet but are virtual or
* just won't work without explicit configuration. */
-static const char * const ifnames_ignore[] = {
- "bridge",
- "epair", /* Virtual patch cable */
- "fwe", /* Firewire */
- "fwip", /* Firewire */
- "tap",
- "vether",
- "xvif", /* XEN DOM0 -> guest interface */
- NULL
-};
-
-struct rtm
-{
+static const char *const ifnames_ignore[] = { "bridge",
+ "epair", /* Virtual patch cable */
+ "fwe", /* Firewire */
+ "fwip", /* Firewire */
+ "tap", "vether", "xvif", /* XEN DOM0 -> guest interface */
+ NULL };
+
+struct rtm {
struct rt_msghdr hdr;
char buffer[sizeof(struct sockaddr_storage) * RTAX_MAX];
};
struct priv *priv;
int n;
#if defined(RO_MSGFILTER) || defined(ROUTE_MSGFILTER)
- unsigned char msgfilter[] = {
- RTM_IFINFO,
+ unsigned char msgfilter[] = { RTM_IFINFO,
#ifdef RTM_IFANNOUNCE
- RTM_IFANNOUNCE,
+ RTM_IFANNOUNCE,
#endif
- RTM_ADD, RTM_CHANGE, RTM_DELETE, RTM_MISS,
+ RTM_ADD, RTM_CHANGE, RTM_DELETE, RTM_MISS,
#ifdef RTM_CHGADDR
- RTM_CHGADDR,
+ RTM_CHGADDR,
#endif
#ifdef RTM_DESYNC
- RTM_DESYNC,
+ RTM_DESYNC,
#endif
- RTM_NEWADDR, RTM_DELADDR
- };
+ RTM_NEWADDR, RTM_DELADDR };
#ifdef ROUTE_MSGFILTER
unsigned int i, msgfilter_mask;
#endif
#ifdef SO_RERROR
n = 1;
- if (setsockopt(ctx->link_fd, SOL_SOCKET, SO_RERROR, &n,sizeof(n)) == -1)
+ if (setsockopt(ctx->link_fd, SOL_SOCKET, SO_RERROR, &n, sizeof(n)) ==
+ -1)
logerr("%s: SO_RERROR", __func__);
#endif
* Sadly there is no way of doing this for route(4) messages
* generated from addresses we add/delete. */
n = 0;
- if (setsockopt(ctx->link_fd, SOL_SOCKET, SO_USELOOPBACK,
- &n, sizeof(n)) == -1)
+ if (setsockopt(ctx->link_fd, SOL_SOCKET, SO_USELOOPBACK, &n,
+ sizeof(n)) == -1)
logerr("%s: SO_USELOOPBACK", __func__);
#ifdef PRIVSEP
* a small as possible buffer size. */
socklen_t smallbuf = 1;
- if (setsockopt(ctx->link_fd, SOL_SOCKET, SO_RCVBUF,
- &smallbuf, (socklen_t)sizeof(smallbuf)) == -1)
+ if (setsockopt(ctx->link_fd, SOL_SOCKET, SO_RCVBUF, &smallbuf,
+ (socklen_t)sizeof(smallbuf)) == -1)
logerr("%s: setsockopt(SO_RCVBUF)", __func__);
}
#endif
#if defined(RO_MSGFILTER)
- if (setsockopt(ctx->link_fd, PF_ROUTE, RO_MSGFILTER,
- &msgfilter, sizeof(msgfilter)) == -1)
+ if (setsockopt(ctx->link_fd, PF_ROUTE, RO_MSGFILTER, &msgfilter,
+ sizeof(msgfilter)) == -1)
logerr(__func__);
#elif defined(ROUTE_MSGFILTER)
/* Convert the array into a bitmask. */
msgfilter_mask = 0;
for (i = 0; i < __arraycount(msgfilter); i++)
msgfilter_mask |= ROUTE_FILTER(msgfilter[i]);
- if (setsockopt(ctx->link_fd, PF_ROUTE, ROUTE_MSGFILTER,
- &msgfilter_mask, sizeof(msgfilter_mask)) == -1)
+ if (setsockopt(ctx->link_fd, PF_ROUTE, ROUTE_MSGFILTER, &msgfilter_mask,
+ sizeof(msgfilter_mask)) == -1)
logerr(__func__);
#else
#warning kernel does not support route message filtering
int
if_setmac(struct interface *ifp, void *mac, uint8_t maclen)
{
-
if (ifp->hwlen != maclen) {
errno = EINVAL;
return -1;
static bool
if_ignore1(const char *drvname)
{
- const char * const *p;
+ const char *const *p;
for (p = ifnames_ignore; *p; p++) {
if (strcmp(*p, drvname) == 0)
strlcpy(ifgr.ifgr_name, ifname, sizeof(ifgr.ifgr_name));
if (ioctl(s, SIOCGIFGROUP, &ifgr) == -1 ||
(ifgr.ifgr_groups = malloc(ifgr.ifgr_len)) == NULL ||
- ioctl(s, SIOCGIFGROUP, &ifgr) == -1)
- {
+ ioctl(s, SIOCGIFGROUP, &ifgr) == -1) {
logerr(__func__);
return -1;
}
for (ifg = ifgr.ifgr_groups, ifg_len = ifgr.ifgr_len;
- ifg && ifg_len >= sizeof(*ifg);
- ifg++, ifg_len -= sizeof(*ifg))
- {
+ ifg && ifg_len >= sizeof(*ifg); ifg++, ifg_len -= sizeof(*ifg)) {
if (if_ignore1(ifg->ifgrq_group))
return 1;
}
return ps_root_ifignoregroup(ctx, ifname) == 1 ? true : false;
#endif
else
- return if_ignoregroup(ctx->pf_inet_fd, ifname) == 1 ?
- true : false;
+ return if_ignoregroup(ctx->pf_inet_fd, ifname) == 1 ? true :
+ false;
#else
UNUSED(ctx);
return false;
#endif
}
-static int if_indirect_ioctl(struct dhcpcd_ctx *ctx,
- const char *ifname, unsigned long cmd, void *data, size_t len)
+static int
+if_indirect_ioctl(struct dhcpcd_ctx *ctx, const char *ifname, unsigned long cmd,
+ void *data, size_t len)
{
struct ifreq ifr = { .ifr_flags = 0 };
bool
if_roaming(struct interface *ifp)
{
-
/* Check for NetBSD as a safety measure.
* If other BSD's gain IN_IFF_TENTATIVE check they re-do DAD
* when the carrier comes up again. */
static void
if_linkaddr(struct sockaddr_dl *sdl, const struct interface *ifp)
{
-
memset(sdl, 0, sizeof(*sdl));
sdl->sdl_family = AF_LINK;
sdl->sdl_len = sizeof(*sdl);
#if defined(SIOCG80211NWID) /* NetBSD */
memset(&nwid, 0, sizeof(nwid));
- if (if_indirect_ioctl(ctx, ifname, SIOCG80211NWID,
- &nwid, sizeof(nwid)) == 0)
- {
+ if (if_indirect_ioctl(ctx, ifname, SIOCG80211NWID, &nwid,
+ sizeof(nwid)) == 0) {
if (ssid == NULL)
retval = nwid.i_len;
else if (nwid.i_len > IF_SSIDLEN)
retval = ireq.i_len;
else if (ireq.i_len > IF_SSIDLEN)
errno = ENOBUFS;
- else {
+ else {
retval = ireq.i_len;
memcpy(ssid, nwid, ireq.i_len);
}
if (r == -1)
return -1;
if (ifmr.ifm_status & IFM_AVALID &&
- IFM_TYPE(ifmr.ifm_active) == IFM_IEEE80211)
- {
+ IFM_TYPE(ifmr.ifm_active) == IFM_IEEE80211) {
if (if_getssid1(ctx, ifname, NULL) == -1)
return 1;
}
#ifdef SIOCGETVLAN
struct vlanreq vlr = { .vlr_tag = 0 };
- if (if_indirect_ioctl(ifp->ctx, ifp->name, SIOCGETVLAN,
- &vlr, sizeof(vlr)) != 0)
+ if (if_indirect_ioctl(ifp->ctx, ifp->name, SIOCGETVLAN, &vlr,
+ sizeof(vlr)) != 0)
return 0; /* 0 means no VLANID */
return vlr.vlr_tag;
#elif defined(SIOCGVNETID)
static struct interface *
if_findsdl(struct dhcpcd_ctx *ctx, const struct sockaddr_dl *sdl)
{
-
if (sdl->sdl_index)
return if_findindex(ctx->ifaces, sdl->sdl_index);
TAILQ_FOREACH(ifp, ctx->ifaces, next) {
if (ifp->hwlen == sdl->sdl_alen &&
- memcmp(ifp->hwaddr,
- sdl->sdl_data, sdl->sdl_alen) == 0)
+ memcmp(ifp->hwaddr, sdl->sdl_data, sdl->sdl_alen) ==
+ 0)
return ifp;
}
}
}
switch (sa->sa_family) {
- case AF_LINK:
- {
+ case AF_LINK: {
const struct sockaddr_dl *sdl;
sdl = (const void *)sa;
return if_findsdl(ctx, sdl);
}
#ifdef INET
- case AF_INET:
- {
+ case AF_INET: {
const struct sockaddr_in *sin;
struct ipv4_addr *ia;
}
#endif
#ifdef INET6
- case AF_INET6:
- {
+ case AF_INET6: {
const struct sockaddr_in6 *sin;
unsigned int scope;
struct ipv6_addr *ia;
static void
if_copysa(struct sockaddr *dst, const struct sockaddr *src)
{
-
assert(dst != NULL);
assert(src != NULL);
assert(rt->rt_ifp->ctx != NULL);
ctx = rt->rt_ifp->ctx;
-#define ADDSA(sa) do { \
- memcpy(bp, (sa), (sa)->sa_len); \
- bp += RT_ROUNDUP((sa)->sa_len); \
- } while (0 /* CONSTCOND */)
+#define ADDSA(sa) \
+ do { \
+ memcpy(bp, (sa), (sa)->sa_len); \
+ bp += RT_ROUNDUP((sa)->sa_len); \
+ } while (0 /* CONSTCOND */)
memset(&rtmsg, 0, sizeof(rtmsg));
rtm->rtm_version = RTM_VERSION;
rtm->rtm_flags |= RTF_UP;
rtm->rtm_addrs |= RTA_GATEWAY;
if (!(rtm->rtm_flags & RTF_REJECT) &&
- !sa_is_loopback(&rt->rt_gateway))
- {
+ !sa_is_loopback(&rt->rt_gateway)) {
rtm->rtm_index = (unsigned short)rt->rt_ifp->index;
/*
* OpenBSD rejects this for on-link routes when there is no default route
*/
#ifdef __OpenBSD__
#warning kernel does not allow IPv6 address sharing
- if (!gateway_unspec || rt->rt_dest.sa_family!=AF_INET6)
+ if (!gateway_unspec ||
+ rt->rt_dest.sa_family != AF_INET6)
#endif
- rtm->rtm_addrs |= RTA_IFP;
+ rtm->rtm_addrs |= RTA_IFP;
if (!sa_is_unspecified(&rt->rt_ifa))
rtm->rtm_addrs |= RTA_IFA;
}
static bool
if_realroute(const struct rt_msghdr *rtm)
{
-
#ifdef RTF_CLONED
if (rtm->rtm_flags & RTF_CLONED)
return false;
}
if (get_addrs(rtm->rtm_addrs, (const char *)rtm + sizeof(*rtm),
- rtm->rtm_msglen - sizeof(*rtm), rti_info) == -1)
+ rtm->rtm_msglen - sizeof(*rtm), rti_info) == -1)
return -1;
memset(rt, 0, sizeof(*rt));
if (rti_info[RTAX_GATEWAY]->sa_family == AF_LINK) {
const struct sockaddr_dl *sdl;
- sdl = (const struct sockaddr_dl*)
- (const void *)rti_info[RTAX_GATEWAY];
+ sdl = (const struct sockaddr_dl *)(const void *)
+ rti_info[RTAX_GATEWAY];
if (sdl->sdl_alen != 0)
rt->rt_dflags |= RTDF_GATELINK;
} else if (rtm->rtm_flags & RTF_GATEWAY)
}
static int
-if_sysctl(struct dhcpcd_ctx *ctx,
- const int *name, u_int namelen,
- void *oldp, size_t *oldlenp, void *newp, size_t newlen)
+if_sysctl(struct dhcpcd_ctx *ctx, const int *name, u_int namelen, void *oldp,
+ size_t *oldlenp, void *newp, size_t newlen)
{
#if defined(PRIVSEP) && defined(HAVE_CAPSICUM)
if (IN_PRIVSEP(ctx))
- return (int)ps_root_sysctl(ctx, name, namelen,
- oldp, oldlenp, newp, newlen);
+ return (int)ps_root_sysctl(ctx, name, namelen, oldp, oldlenp,
+ newp, newlen);
#else
UNUSED(ctx);
#endif
if ((p = realloc(buf, bufl)) == NULL)
goto err;
buf = p;
- if (if_sysctl(ctx, mib, __arraycount(mib), buf, &bufl, NULL, 0) == -1)
- {
+ if (if_sysctl(ctx, mib, __arraycount(mib), buf, &bufl, NULL, 0) == -1) {
if (errno == ENOMEM)
goto again;
goto err;
memset(&ifra, 0, sizeof(ifra));
strlcpy(ifra.ifra_name, ia->iface->name, sizeof(ifra.ifra_name));
-#define ADDADDR(var, addr) do { \
- (var)->sin_family = AF_INET; \
- (var)->sin_len = sizeof(*(var)); \
- (var)->sin_addr = *(addr); \
- } while (/*CONSTCOND*/0)
+#define ADDADDR(var, addr) \
+ do { \
+ (var)->sin_family = AF_INET; \
+ (var)->sin_len = sizeof(*(var)); \
+ (var)->sin_addr = *(addr); \
+ } while (/*CONSTCOND*/ 0)
ADDADDR(&ifra.ifra_addr, &ia->addr);
ADDADDR(&ifra.ifra_mask, &ia->mask);
if (cmd == RTM_NEWADDR && ia->brd.s_addr != INADDR_ANY)
ADDADDR(&ifra.ifra_broadaddr, &ia->brd);
#undef ADDADDR
- r = if_ioctl(ctx,
- cmd == RTM_DELADDR ? SIOCDIFADDR : SIOCAIFADDR, &ifra,sizeof(ifra));
+ r = if_ioctl(ctx, cmd == RTM_DELADDR ? SIOCDIFADDR : SIOCAIFADDR, &ifra,
+ sizeof(ifra));
return r;
}
ifa.ifra_flags |= IN6_IFF_TEMPORARY;
#endif
-#define ADDADDR(v, addr) { \
- (v)->sin6_family = AF_INET6; \
- (v)->sin6_len = sizeof(*v); \
- (v)->sin6_addr = *(addr); \
+#define ADDADDR(v, addr) \
+ { \
+ (v)->sin6_family = AF_INET6; \
+ (v)->sin6_len = sizeof(*v); \
+ (v)->sin6_addr = *(addr); \
}
ADDADDR(&ifa.ifra_addr, &ia->addr);
*/
#if !((defined(__NetBSD_Version__) && __NetBSD_Version__ >= 799003600) || \
- (defined(__OpenBSD__) && OpenBSD >= 201605))
+ (defined(__OpenBSD__) && OpenBSD >= 201605))
if (cmd == RTM_NEWADDR && !(ia->flags & IPV6_AF_ADDED)) {
ifa.ifra_lifetime.ia6t_vltime = ND6_INFINITE_LIFETIME;
ifa.ifra_lifetime.ia6t_pltime = ND6_INFINITE_LIFETIME;
#endif
return if_ioctl6(ctx,
- cmd == RTM_DELADDR ? SIOCDIFADDR_IN6 : SIOCAIFADDR_IN6,
- &ifa, sizeof(ifa));
+ cmd == RTM_DELADDR ? SIOCDIFADDR_IN6 : SIOCAIFADDR_IN6, &ifa,
+ sizeof(ifa));
}
int
static int
if_announce(struct dhcpcd_ctx *ctx, const struct if_announcemsghdr *ifan)
{
-
if (ifan->ifan_msglen < sizeof(*ifan)) {
errno = EINVAL;
return -1;
}
- switch(ifan->ifan_what) {
+ switch (ifan->ifan_what) {
case IFAN_ARRIVAL:
return dhcpcd_handleinterface(ctx, 1, ifan->ifan_name);
case IFAN_DEPARTURE:
*/
if (rt.rt_dest.sa_family == AF_INET6 &&
(rt.rt_flags & RTF_HOST || rtm->rtm_type == RTM_MISS) &&
- !(rtm->rtm_type == RTM_ADD && !(rt.rt_dflags & RTDF_GATELINK)))
- {
+ !(rtm->rtm_type == RTM_ADD && !(rt.rt_dflags & RTDF_GATELINK))) {
bool reachable;
reachable = (rtm->rtm_type == RTM_ADD ||
- rtm->rtm_type == RTM_CHANGE) &&
+ rtm->rtm_type == RTM_CHANGE) &&
rt.rt_dflags & RTDF_GATELINK;
ipv6nd_neighbour(ctx, &rt.rt_ss_dest.sin6.sin6_addr, reachable);
}
return 0;
if (get_addrs(ifam->ifam_addrs, (const char *)ifam + sizeof(*ifam),
- ifam->ifam_msglen - sizeof(*ifam), rti_info) == -1)
+ ifam->ifam_msglen - sizeof(*ifam), rti_info) == -1)
return -1;
/* All BSD's set IFF_UP on the interface when adding an address.
}
switch (rti_info[RTAX_IFA]->sa_family) {
- case AF_LINK:
- {
+ case AF_LINK: {
struct sockaddr_dl sdl;
#ifdef RTM_CHGADDR
break;
#endif
memcpy(&sdl, rti_info[RTAX_IFA], rti_info[RTAX_IFA]->sa_len);
- dhcpcd_handlehwaddr(ifp, ifp->hwtype,
- CLLADDR(&sdl), sdl.sdl_alen);
+ dhcpcd_handlehwaddr(ifp, ifp->hwtype, CLLADDR(&sdl),
+ sdl.sdl_alen);
break;
}
#ifdef INET
sin = (const void *)rti_info[RTAX_IFA];
addr.s_addr = sin != NULL && sin->sin_family == AF_INET ?
- sin->sin_addr.s_addr : INADDR_ANY;
+ sin->sin_addr.s_addr :
+ INADDR_ANY;
sin = (const void *)rti_info[RTAX_NETMASK];
mask.s_addr = sin != NULL && sin->sin_family == AF_INET ?
- sin->sin_addr.s_addr : INADDR_ANY;
+ sin->sin_addr.s_addr :
+ INADDR_ANY;
sin = (const void *)rti_info[RTAX_BRD];
bcast.s_addr = sin != NULL && sin->sin_family == AF_INET ?
- sin->sin_addr.s_addr : INADDR_ANY;
+ sin->sin_addr.s_addr :
+ INADDR_ANY;
/*
* NetBSD-7 and older send an invalid broadcast address.
}
} else
#endif
- if (getifaddrs(&ifaddrs) == -1) {
+ if (getifaddrs(&ifaddrs) == -1) {
logerr("getifaddrs");
break;
}
free(ifaddrs);
else
#endif
- freeifaddrs(ifaddrs);
+ freeifaddrs(ifaddrs);
if (ifam->ifam_type == RTM_DELADDR) {
if (ifa != NULL)
break;
flags = 0;
#endif
- ipv4_handleifa(ctx, ifam->ifam_type, NULL, ifp->name,
- &addr, &mask, &bcast, flags, pid);
+ ipv4_handleifa(ctx, ifam->ifam_type, NULL, ifp->name, &addr,
+ &mask, &bcast, flags, pid);
break;
}
#endif
#ifdef INET6
- case AF_INET6:
- {
+ case AF_INET6: {
struct in6_addr addr6, mask6;
const struct in6_addr *dstaddr6;
const struct sockaddr_in6 *sin6;
addr6.s6_addr[2] = addr6.s6_addr[3] = '\0';
#endif
- ipv6_handleifa(ctx, ifam->ifam_type, NULL,
- ifp->name, &addr6, ipv6_prefixlen(&mask6),
- dstaddr6, flags, pid);
+ ipv6_handleifa(ctx, ifam->ifam_type, NULL, ifp->name, &addr6,
+ ipv6_prefixlen(&mask6), dstaddr6, flags, pid);
break;
}
#endif
static int
if_dispatch(struct dhcpcd_ctx *ctx, const struct rt_msghdr *rtm)
{
-
if (rtm->rtm_version != RTM_VERSION)
return 0;
- switch(rtm->rtm_type) {
+ switch (rtm->rtm_type) {
#ifdef RTM_IFANNOUNCE
case RTM_IFANNOUNCE:
return if_announce(ctx, (const void *)rtm);
#endif
case RTM_IFINFO:
return if_ifinfo(ctx, (const void *)rtm);
- case RTM_ADD: /* FALLTHROUGH */
- case RTM_CHANGE: /* FALLTHROUGH */
- case RTM_DELETE: /* FALLTHROUGH */
+ case RTM_ADD: /* FALLTHROUGH */
+ case RTM_CHANGE: /* FALLTHROUGH */
+ case RTM_DELETE: /* FALLTHROUGH */
case RTM_MISS:
return if_rtm(ctx, (const void *)rtm);
#ifdef RTM_CHGADDR
- case RTM_CHGADDR: /* FALLTHROUGH */
+ case RTM_CHGADDR: /* FALLTHROUGH */
#endif
- case RTM_DELADDR: /* FALLTHROUGH */
+ case RTM_DELADDR: /* FALLTHROUGH */
case RTM_NEWADDR:
return if_ifa(ctx, (const void *)rtm);
#ifdef RTM_DESYNC
int
if_missfilter(struct interface *ifp, struct sockaddr *sa)
{
-
return if_missfilter0(ifp->ctx, ifp, sa);
}
#ifdef RO_MISSFILTER
if (ctx->rt_missfilterlen == 0) {
struct sockaddr sa = {
- .sa_family = AF_UNSPEC,
- .sa_len = sizeof(sa),
+ .sa_family = AF_UNSPEC,
+ .sa_len = sizeof(sa),
};
if (if_missfilter0(ctx, NULL, &sa) == -1)
if (len == 0)
return 0;
if ((size_t)len < sizeof(rtm.hdr.rtm_msglen) ||
- len != rtm.hdr.rtm_msglen)
- {
+ len != rtm.hdr.rtm_msglen) {
errno = EINVAL;
return -1;
}
return if_dispatch(ctx, &rtm.hdr);
}
-#ifndef SYS_NMLN /* OSX */
-# define SYS_NMLN __SYS_NAMELEN
+#ifndef SYS_NMLN /* OSX */
+#define SYS_NMLN __SYS_NAMELEN
#endif
#ifndef HW_MACHINE_ARCH
-# ifdef HW_MODEL /* OpenBSD */
-# define HW_MACHINE_ARCH HW_MODEL
-# endif
+#ifdef HW_MODEL /* OpenBSD */
+#define HW_MACHINE_ARCH HW_MODEL
+#endif
#endif
int
if_machinearch(char *str, size_t len)
#ifdef INET6
#if (defined(IPV6CTL_ACCEPT_RTADV) && !defined(ND6_IFF_ACCEPT_RTADV))
-#define get_inet6_sysctl(code) inet6_sysctl(code, 0, 0)
+#define get_inet6_sysctl(code) inet6_sysctl(code, 0, 0)
#define set_inet6_sysctl(code, val) inet6_sysctl(code, val, 1)
static int
inet6_sysctl(int code, int val, int action)
* dhcpcd is instructed not to do auto configuration of addresses.
*/
#if defined(ND6_IFF_ACCEPT_RTADV)
-#define BSD_AUTOCONF DHCPCD_IPV6RS
+#define BSD_AUTOCONF DHCPCD_IPV6RS
#else
-#define BSD_AUTOCONF DHCPCD_IPV6RA_AUTOCONF
+#define BSD_AUTOCONF DHCPCD_IPV6RA_AUTOCONF
#endif
if (ifp->options->options & BSD_AUTOCONF)
flags &= ~IFXF_AUTOCONF6;
/* OpenBSD removed ND6 flags entirely, so we need to check for their
* existance. */
-#if defined(ND6_IFF_AUTO_LINKLOCAL) || \
- defined(ND6_IFF_PERFORMNUD) || \
- defined(ND6_IFF_ACCEPT_RTADV) || \
- defined(ND6_IFF_OVERRIDE_RTADV) || \
+#if defined(ND6_IFF_AUTO_LINKLOCAL) || defined(ND6_IFF_PERFORMNUD) || \
+ defined(ND6_IFF_ACCEPT_RTADV) || defined(ND6_IFF_OVERRIDE_RTADV) || \
defined(ND6_IFF_IFDISABLED)
-#define ND6_NDI_FLAGS
+#define ND6_NDI_FLAGS
#endif
void
if (ra == -1) {
if (errno != ENOENT)
logerr("IPV6CTL_ACCEPT_RTADV");
- else if (ra != 0)
- if (set_inet6_sysctl(IPV6CTL_ACCEPT_RTADV, 0) == -1)
- logerr("IPV6CTL_ACCEPT_RTADV");
+ else if (ra != 0)
+ if (set_inet6_sysctl(IPV6CTL_ACCEPT_RTADV, 0) == -1)
+ logerr("IPV6CTL_ACCEPT_RTADV");
}
#endif
}
if (nd.ndi.flags != (uint32_t)flags) {
nd.ndi.flags = (uint32_t)flags;
- if (if_ioctl6(ifp->ctx, SIOCSIFINFO_FLAGS,
- &nd, sizeof(nd)) == -1)
+ if (if_ioctl6(ifp->ctx, SIOCSIFINFO_FLAGS, &nd, sizeof(nd)) ==
+ -1)
logerr("%s: SIOCSIFINFO_FLAGS", ifp->name);
}
#endif /* ND6_NDI_FLAGS */
memset(&ifr, 0, sizeof(ifr));
strlcpy(ifr.ifr_name, ifp->name, sizeof(ifr.ifr_name));
- if (if_ioctl6(ifp->ctx, SIOCSRTRFLUSH_IN6,
- &ifr, sizeof(ifr)) == -1 &&
+ if (if_ioctl6(ifp->ctx, SIOCSRTRFLUSH_IN6, &ifr, sizeof(ifr)) ==
+ -1 &&
errno != ENOTSUP && errno != ENOTTY)
logwarn("SIOCSRTRFLUSH_IN6 %d", errno);
#ifdef SIOCSPFXFLUSH_IN6
- if (if_ioctl6(ifp->ctx, SIOCSPFXFLUSH_IN6,
- &ifr, sizeof(ifr)) == -1 &&
+ if (if_ioctl6(ifp->ctx, SIOCSPFXFLUSH_IN6, &ifr, sizeof(ifr)) ==
+ -1 &&
errno != ENOTSUP && errno != ENOTTY)
logwarn("SIOCSPFXFLUSH_IN6");
#endif
#include <sys/ioctl.h>
#include <sys/socket.h>
-#include <linux/types.h>
#include <linux/rtnetlink.h>
+#include <linux/types.h>
/* Support older kernels */
#ifdef IFLA_WIRELESS
-# include <linux/if.h>
-# include <linux/wireless.h>
+#include <linux/if.h>
+#include <linux/wireless.h>
#else
-# define IFLA_WIRELESS (IFLA_MASTER + 1)
+#define IFLA_WIRELESS (IFLA_MASTER + 1)
#endif
#include <string.h>
* SUCH DAMAGE.
*/
-#include <asm/types.h> /* Needed for 2.4 kernels */
-
#include <sys/types.h>
+#include <sys/param.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
-#include <sys/param.h>
#include <sys/stat.h>
+#include <net/if.h>
+#include <net/route.h>
+#include <netinet/in.h>
+#include <netinet/in_systm.h>
+
+#include <arpa/inet.h>
+#include <asm/types.h> /* Needed for 2.4 kernels */
+#include <linux/filter.h>
#include <linux/icmpv6.h>
#include <linux/if_addr.h>
#include <linux/if_link.h>
#include <linux/if_packet.h>
#include <linux/if_tun.h>
#include <linux/if_vlan.h>
-#include <linux/filter.h>
#include <linux/netlink.h>
-#include <linux/sockios.h>
#include <linux/rtnetlink.h>
-
-#include <arpa/inet.h>
-#include <net/if.h>
-#include <netinet/in_systm.h>
-#include <netinet/in.h>
-#include <net/route.h>
+#include <linux/sockios.h>
/* musl has its own definition of struct ethhdr, so only include
* netinet/if_ether.h on systems with GLIBC. For the ARPHRD constants,
#include <linux/if_arp.h>
#endif
+#include <ctype.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
-#include <ctype.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
#include <time.h>
#include <unistd.h>
-#include "config.h"
#include "bpf.h"
#include "common.h"
+#include "config.h"
#include "dev.h"
#include "dhcp.h"
#include "if.h"
/* Buggy CentOS and RedHat */
#ifndef SOL_NETLINK
-#define SOL_NETLINK 270
+#define SOL_NETLINK 270
#endif
/*
*/
#ifdef IFLA_LINKINFO
#ifndef IFF_LOWER_UP
-#define IFF_LOWER_UP 0x10000
+#define IFF_LOWER_UP 0x10000
#endif
#ifndef IFF_DORMANT
-#define IFF_DORMANT 0x20000
+#define IFF_DORMANT 0x20000
#endif
#endif
#undef NLA_ALIGNTO
#undef NLA_ALIGN
#undef NLA_HDRLEN
-#define NLA_ALIGNTO 4U
-#define NLA_ALIGN(len) (((len) + NLA_ALIGNTO - 1) & ~(NLA_ALIGNTO - 1))
-#define NLA_HDRLEN ((int) NLA_ALIGN(sizeof(struct nlattr)))
+#define NLA_ALIGNTO 4U
+#define NLA_ALIGN(len) (((len) + NLA_ALIGNTO - 1) & ~(NLA_ALIGNTO - 1))
+#define NLA_HDRLEN ((int)NLA_ALIGN(sizeof(struct nlattr)))
#undef IFA_RTA
-#define IFA_RTA(r) ((struct rtattr *)(void *)(((char *)(r)) \
- + NLMSG_ALIGN(sizeof(struct ifaddrmsg))))
+#define IFA_RTA(r) \
+ ((struct rtattr *)(void *)(((char *)(r)) + \
+ NLMSG_ALIGN(sizeof(struct ifaddrmsg))))
#undef IFLA_RTA
-#define IFLA_RTA(r) ((struct rtattr *)(void *)(((char *)(r)) \
- + NLMSG_ALIGN(sizeof(struct ifinfomsg))))
+#define IFLA_RTA(r) \
+ ((struct rtattr *)(void *)(((char *)(r)) + \
+ NLMSG_ALIGN(sizeof(struct ifinfomsg))))
#undef NLMSG_NEXT
-#define NLMSG_NEXT(nlh, len) ((len) -= NLMSG_ALIGN((nlh)->nlmsg_len), \
- (struct nlmsghdr *)(void *)(((char *)(nlh)) \
- + NLMSG_ALIGN((nlh)->nlmsg_len)))
+#define NLMSG_NEXT(nlh, len) \
+ ((len) -= NLMSG_ALIGN((nlh)->nlmsg_len), \
+ (struct nlmsghdr *)(void *)(((char *)(nlh)) + \
+ NLMSG_ALIGN((nlh)->nlmsg_len)))
#undef RTM_RTA
#define RTM_RTA(r) (void *)(((char *)(r)) + NLMSG_ALIGN(sizeof(struct rtmsg)))
#undef RTA_NEXT
-#define RTA_NEXT(rta, attrlen) ((attrlen) -= RTA_ALIGN((rta)->rta_len), \
- (struct rtattr *)(void *)(((char *)(rta)) \
- + RTA_ALIGN((rta)->rta_len)))
+#define RTA_NEXT(rta, attrlen) \
+ ((attrlen) -= RTA_ALIGN((rta)->rta_len), \
+ (struct rtattr *)(void *)(((char *)(rta)) + \
+ RTA_ALIGN((rta)->rta_len)))
/* We need this to send a broadcast for InfiniBand.
* Our old code used sendto, but our new code writes to a raw BPF socket.
static int if_addressexists(struct interface *, struct in_addr *);
-#define PROC_PROMOTE "/proc/sys/net/ipv4/conf/%s/promote_secondaries"
-#define SYS_BRIDGE "/sys/class/net/%s/bridge/bridge_id"
-#define SYS_LAYER2 "/sys/class/net/%s/device/layer2"
-#define SYS_TUNTAP "/sys/class/net/%s/tun_flags"
+#define PROC_PROMOTE "/proc/sys/net/ipv4/conf/%s/promote_secondaries"
+#define SYS_BRIDGE "/sys/class/net/%s/bridge/bridge_id"
+#define SYS_LAYER2 "/sys/class/net/%s/device/layer2"
+#define SYS_TUNTAP "/sys/class/net/%s/tun_flags"
#if defined(__aarch64__)
static const char *mproc = "AArch64";
int
if_machinearch(char *str, size_t len)
{
-
return snprintf(str, len, "%s", mproc);
}
#else
static const char *mproc =
#if defined(__alpha__)
- "system type"
+ "system type"
#elif defined(__arm__)
- "Hardware"
+ "Hardware"
#elif defined(__avr32__)
- "cpu family"
+ "cpu family"
#elif defined(__bfin__)
- "BOARD Name"
+ "BOARD Name"
#elif defined(__cris__)
- "cpu model"
+ "cpu model"
#elif defined(__frv__)
- "System"
+ "System"
#elif defined(__hppa__)
- "model"
+ "model"
#elif defined(__i386__) || defined(__x86_64__)
- "vendor_id"
+ "vendor_id"
#elif defined(__ia64__)
- "vendor"
+ "vendor"
#elif defined(__m68k__)
- "MMU"
+ "MMU"
#elif defined(__mips__)
- "system type"
+ "system type"
#elif defined(__powerpc__) || defined(__powerpc64__)
- "machine"
+ "machine"
#elif defined(__riscv)
- "uarch"
+ "uarch"
#elif defined(__s390__) || defined(__s390x__)
- "Manufacturer"
+ "Manufacturer"
#elif defined(__sh__)
- "machine"
+ "machine"
#elif defined(sparc) || defined(__sparc__)
- "cpu"
+ "cpu"
#elif defined(__vax__)
- "cpu"
+ "cpu"
#else
- NULL
+ NULL
#endif
- ;
+ ;
int
if_machinearch(char *str, size_t len)
while (fscanf(fp, "%255s : ", buf) != EOF) {
if (strncmp(buf, mproc, strlen(mproc)) == 0 &&
- fscanf(fp, "%255s", buf) == 1)
- {
+ fscanf(fp, "%255s", buf) == 1) {
fclose(fp);
return snprintf(str, len, "%s", buf);
}
bool
if_ignore(struct dhcpcd_ctx *ctx, const char *ifname)
{
-
if (if_tap(ctx, ifname) || if_bridge(ctx, ifname))
return true;
return false;
int
if_vimaster(__unused struct dhcpcd_ctx *ctx, __unused const char *ifname)
{
-
return 0;
}
if (ctx->link_fd == -1)
return -1;
#ifdef NETLINK_BROADCAST_ERROR
- if (setsockopt(ctx->link_fd, SOL_NETLINK, NETLINK_BROADCAST_ERROR,
- &on, sizeof(on)) == -1)
+ if (setsockopt(ctx->link_fd, SOL_NETLINK, NETLINK_BROADCAST_ERROR, &on,
+ sizeof(on)) == -1)
logerr("%s: NETLINK_BROADCAST_ERROR", __func__);
#endif
return if_ioctl(ifp->ctx, SIOCSIFHWADDR, &ifr, sizeof(ifr));
}
-static int if_carrier_from_flags(unsigned int flags)
+static int
+if_carrier_from_flags(unsigned int flags)
{
-
#ifdef IFF_LOWER_UP
return ((flags & (IFF_LOWER_UP | IFF_RUNNING)) ==
- (IFF_LOWER_UP | IFF_RUNNING))
+ (IFF_LOWER_UP | IFF_RUNNING))
#ifdef IFF_DORMANT
/*
* IFF_DORMANT means L1 is up but waiting for an external
*/
&& !(flags & IFF_DORMANT)
#endif
- ? LINK_UP : LINK_DOWN;
+ ?
+ LINK_UP :
+ LINK_DOWN;
#else
return flags & IFF_RUNNING ? LINK_UP : LINK_DOWN;
#endif
return if_carrier_from_flags(ifp->flags);
}
-
bool
if_roaming(struct interface *ifp)
{
-
return
#ifdef IFF_DORMANT
- ifp->flags & IFF_DORMANT ||
+ ifp->flags & IFF_DORMANT ||
#endif
#ifdef IFF_LOWER_UP
- /*
- * IFF_DORMANT only occurs for supplicant initiated roaming.
- * For firmware initiated roaming we don't get IFF_DORMANT.
- * Seems weird that the driver can't set it though.
- * We can check that IFF_RUNNING is not set but UP and L1 are
- * to get the same effect.
- */
- (ifp->flags & (IFF_UP | IFF_LOWER_UP | IFF_RUNNING)) ==
- (IFF_UP | IFF_LOWER_UP) ||
+ /*
+ * IFF_DORMANT only occurs for supplicant initiated roaming.
+ * For firmware initiated roaming we don't get IFF_DORMANT.
+ * Seems weird that the driver can't set it though.
+ * We can check that IFF_RUNNING is not set but UP and L1 are
+ * to get the same effect.
+ */
+ (ifp->flags & (IFF_UP | IFF_LOWER_UP | IFF_RUNNING)) ==
+ (IFF_UP | IFF_LOWER_UP) ||
#endif
false;
}
{
struct sockaddr_nl nladdr = { .nl_pid = 0 };
struct msghdr msg = {
- .msg_name = &nladdr, .msg_namelen = sizeof(nladdr),
- .msg_iov = iov, .msg_iovlen = 1,
+ .msg_name = &nladdr,
+ .msg_namelen = sizeof(nladdr),
+ .msg_iov = iov,
+ .msg_iovlen = 1,
};
size_t len;
struct nlmsghdr *nlm;
again = 0;
terminated = false;
- for (nlm = iov->iov_base;
- nlm && NLMSG_OK(nlm, len);
- nlm = NLMSG_NEXT(nlm, len))
- {
+ for (nlm = iov->iov_base; nlm && NLMSG_OK(nlm, len);
+ nlm = NLMSG_NEXT(nlm, len)) {
again = (nlm->nlmsg_flags & NLM_F_MULTI);
if (nlm->nlmsg_type == NLMSG_NOOP)
continue;
case RTA_DST:
sa = &rt->rt_dest;
break;
- case RTA_SRC:
- {
+ case RTA_SRC: {
union sa_ss ssa;
struct sockaddr *psa = (struct sockaddr *)&ssa;
socklen_t salen;
psa->sa_family = rtm->rtm_family;
salen = sa_addrlen(psa);
- memcpy((char *)psa + sa_addroffset(psa),
- RTA_DATA(rta), MIN(salen, RTA_PAYLOAD(rta)));
+ memcpy((char *)psa + sa_addroffset(psa), RTA_DATA(rta),
+ MIN(salen, RTA_PAYLOAD(rta)));
/* if ip-route "from" address is not unspecified,
- route is source-based, eg:
- <dest-net> from <source-net> via ... dev ...
- ignore the route as may otherwise appear to overlap
- with routes set/removed by dhcpcd */
+ route is source-based, eg:
+ <dest-net> from <source-net> via ... dev ...
+ ignore the route as may otherwise appear to overlap
+ with routes set/removed by dhcpcd */
if (!sa_is_unspecified(psa)) {
errno = ENOTSUP;
return -1;
case RTA_PRIORITY:
rt->rt_metric = *(unsigned int *)RTA_DATA(rta);
break;
- case RTA_METRICS:
- {
+ case RTA_METRICS: {
struct rtattr *r2;
size_t l2;
for (; RTA_OK(r2, l2); r2 = RTA_NEXT(r2, l2)) {
switch (r2->rta_type) {
case RTAX_MTU:
- rt->rt_mtu = *(unsigned int *)RTA_DATA(r2);
+ rt->rt_mtu = *(unsigned int *)RTA_DATA(
+ r2);
break;
}
}
break;
}
#ifdef HAVE_ROUTE_LIFETIME
- case RTA_CACHEINFO:
- {
+ case RTA_CACHEINFO: {
struct rta_cacheinfo ci;
static long hz;
if (sa_is_allones(&rt->rt_netmask))
rt->rt_flags |= RTF_HOST;
- #if 0
+#if 0
if (rt->rtp_ifp == NULL && rt->src.s_addr != INADDR_ANY) {
struct ipv4_addr *ap;
if ((ap = ipv4_findaddr(ctx, &rt->src)))
rt->iface = ap->iface;
}
- #endif
+#endif
if (rt->rt_ifp == NULL) {
errno = ESRCH;
nlm->nlmsg_pid == (uint32_t)ctx->ps_root->psp_pid)
return 0;
#endif
- priv = (struct priv*)ctx->priv;
+ priv = (struct priv *)ctx->priv;
if (nlm->nlmsg_pid == priv->route_pid)
return 0;
}
break;
}
- ipv4_handleifa(ctx, nlm->nlmsg_type, NULL, ifp->name,
- &addr, &net, &brd, ifa->ifa_flags, (pid_t)nlm->nlmsg_pid);
+ ipv4_handleifa(ctx, nlm->nlmsg_type, NULL, ifp->name, &addr,
+ &net, &brd, ifa->ifa_flags, (pid_t)nlm->nlmsg_pid);
break;
#endif
#ifdef INET6
case AF_INET6:
for (; RTA_OK(rta, len); rta = RTA_NEXT(rta, len)) {
- switch (rta->rta_type) {
+ switch (rta->rta_type) {
case IFA_ADDRESS:
addr6 = (struct in6_addr *)RTA_DATA(rta);
break;
break;
}
- ipv6_handleifa(ctx, nlm->nlmsg_type, NULL, ifp->name,
- addr6, ifa->ifa_prefixlen, dstaddr6,
- ifa->ifa_flags, (pid_t)nlm->nlmsg_pid);
+ ipv6_handleifa(ctx, nlm->nlmsg_type, NULL, ifp->name, addr6,
+ ifa->ifa_prefixlen, dstaddr6, ifa->ifa_flags,
+ (pid_t)nlm->nlmsg_pid);
break;
#endif
}
static uint8_t
l2addr_len(unsigned short if_type)
{
-
switch (if_type) {
- case ARPHRD_ETHER: /* FALLTHROUGH */
+ case ARPHRD_ETHER: /* FALLTHROUGH */
case ARPHRD_IEEE802: /*FALLTHROUGH */
case ARPHRD_IEEE80211:
return 6;
switch (rta->rta_type) {
case NDA_DST:
memcpy(&addr6.s6_addr, RTA_DATA(rta),
- sizeof(addr6.s6_addr));
+ sizeof(addr6.s6_addr));
break;
}
}
dhcpcd_handlehwaddr(ifp, ifi->ifi_type, hwa, hwl);
}
- dhcpcd_handlecarrier(ifp,
- if_carrier_from_flags(ifi->ifi_flags),
+ dhcpcd_handlecarrier(ifp, if_carrier_from_flags(ifi->ifi_flags),
ifi->ifi_flags);
return 0;
}
static bool
if_netlinkpriv(int protocol, struct nlmsghdr *nlm)
{
-
if (protocol != NETLINK_ROUTE)
return false;
- switch(nlm->nlmsg_type) {
- case RTM_NEWADDR: /* FALLTHROUGH */
- case RTM_DELADDR: /* FALLTHROUGH */
- case RTM_NEWROUTE: /* FALLTHROUGH */
- case RTM_DELROUTE: /* FALLTHROUGH */
+ switch (nlm->nlmsg_type) {
+ case RTM_NEWADDR: /* FALLTHROUGH */
+ case RTM_DELADDR: /* FALLTHROUGH */
+ case RTM_NEWROUTE: /* FALLTHROUGH */
+ case RTM_DELROUTE: /* FALLTHROUGH */
case RTM_NEWLINK:
return true;
default:
int s;
struct sockaddr_nl snl = { .nl_family = AF_NETLINK };
struct iovec iov = { .iov_base = hdr, .iov_len = hdr->nlmsg_len };
- struct msghdr msg = {
- .msg_name = &snl, .msg_namelen = sizeof(snl),
- .msg_iov = &iov, .msg_iovlen = 1
- };
+ struct msghdr msg = { .msg_name = &snl,
+ .msg_namelen = sizeof(snl),
+ .msg_iov = &iov,
+ .msg_iovlen = 1 };
struct priv *priv = (struct priv *)ctx->priv;
unsigned char buf[16 * 1024];
struct iovec riov = {
return if_getnetlink(ctx, &riov, s, 0, cb, cbarg);
}
-#define NLMSG_TAIL(nmsg) \
+#define NLMSG_TAIL(nmsg) \
((struct rtattr *)(void *)(((char *)(nmsg)) + \
NLMSG_ALIGN((nmsg)->nlmsg_len)))
add_attr_8(struct nlmsghdr *n, unsigned short maxlen, unsigned short type,
uint8_t data)
{
-
return add_attr_l(n, maxlen, type, &data, sizeof(data));
}
#endif
}
static int
-rta_add_attr_32(struct rtattr *rta, unsigned short maxlen,
- unsigned short type, uint32_t data)
+rta_add_attr_32(struct rtattr *rta, unsigned short maxlen, unsigned short type,
+ uint32_t data)
{
unsigned short len = RTA_LENGTH(sizeof(data));
struct rtattr *subrta;
return -1;
}
- subrta = (void *)((char*)rta + RTA_ALIGN(rta->rta_len));
+ subrta = (void *)((char *)rta + RTA_ALIGN(rta->rta_len));
subrta->rta_type = type;
subrta->rta_len = len;
memcpy(RTA_DATA(subrta), &data, sizeof(data));
static struct nlattr *
nla_next(struct nlattr *nla, size_t *rem)
{
-
*rem -= (size_t)NLA_ALIGN(nla->nla_len);
return (void *)((char *)nla + NLA_ALIGN(nla->nla_len));
}
#define NLA_TYPE(nla) ((nla)->nla_type & NLA_TYPE_MASK)
-#define NLA_LEN(nla) (unsigned int)((nla)->nla_len - NLA_HDRLEN)
-#define NLA_OK(nla, rem) \
+#define NLA_LEN(nla) (unsigned int)((nla)->nla_len - NLA_HDRLEN)
+#define NLA_OK(nla, rem) \
((rem) >= sizeof(struct nlattr) && \
- (nla)->nla_len >= sizeof(struct nlattr) && \
- (nla)->nla_len <= rem)
+ (nla)->nla_len >= sizeof(struct nlattr) && (nla)->nla_len <= rem)
#define NLA_DATA(nla) (void *)((char *)(nla) + NLA_HDRLEN)
-#define NLA_FOR_EACH_ATTR(pos, head, len, rem) \
- for (pos = head, rem = len; \
- NLA_OK(pos, rem); \
- pos = nla_next(pos, &(rem)))
+#define NLA_FOR_EACH_ATTR(pos, head, len, rem) \
+ for (pos = head, rem = len; NLA_OK(pos, rem); \
+ pos = nla_next(pos, &(rem)))
-struct nlmg
-{
+struct nlmg {
struct nlmsghdr hdr;
struct genlmsghdr ghdr;
char buffer[64];
};
static int
-nla_put_32(struct nlmsghdr *n, unsigned short maxlen,
- unsigned short type, uint32_t data)
+nla_put_32(struct nlmsghdr *n, unsigned short maxlen, unsigned short type,
+ uint32_t data)
{
unsigned short len;
struct nlattr *nla;
}
static int
-nla_put_string(struct nlmsghdr *n, unsigned short maxlen,
- unsigned short type, const char *data)
+nla_put_string(struct nlmsghdr *n, unsigned short maxlen, unsigned short type,
+ const char *data)
{
struct nlattr *nla;
size_t len, sl;
int type;
memset(tb, 0, sizeof(*tb) * ((unsigned int)maxtype + 1));
- NLA_FOR_EACH_ATTR(nla, head, len, rem) {
+ NLA_FOR_EACH_ATTR(nla, head, len, rem)
+ {
type = NLA_TYPE(nla);
if (type > maxtype)
continue;
nlm.hdr.nlmsg_flags = NLM_F_REQUEST;
nlm.ghdr.cmd = CTRL_CMD_GETFAMILY;
nlm.ghdr.version = 1;
- if (nla_put_string(&nlm.hdr, sizeof(nlm),
- CTRL_ATTR_FAMILY_NAME, name) == -1)
+ if (nla_put_string(&nlm.hdr, sizeof(nlm), CTRL_ATTR_FAMILY_NAME,
+ name) == -1)
return -1;
- return if_sendnetlink(ctx, NETLINK_GENERIC, &nlm.hdr,
- &_gnl_getfamily, NULL);
+ return if_sendnetlink(ctx, NETLINK_GENERIC, &nlm.hdr, &_gnl_getfamily,
+ NULL);
}
static int
if (tb[NL80211_ATTR_BSS] == NULL)
return 0;
- if (nla_parse(bss,
- NLA_DATA(tb[NL80211_ATTR_BSS]),
- NLA_LEN(tb[NL80211_ATTR_BSS]),
- NL80211_BSS_STATUS) == -1)
+ if (nla_parse(bss, NLA_DATA(tb[NL80211_ATTR_BSS]),
+ NLA_LEN(tb[NL80211_ATTR_BSS]), NL80211_BSS_STATUS) == -1)
return 0;
if (bss[NL80211_BSS_BSSID] == NULL || bss[NL80211_BSS_STATUS] == NULL)
nlm.hdr.nlmsg_flags = NLM_F_REQUEST;
nlm.ghdr.cmd = NL80211_CMD_GET_WIPHY;
nla_put_32(&nlm.hdr, sizeof(nlm), NL80211_ATTR_IFINDEX, ifp->index);
- if (if_sendnetlink(ifp->ctx, NETLINK_GENERIC, &nlm.hdr,
- NULL, NULL) == -1)
+ if (if_sendnetlink(ifp->ctx, NETLINK_GENERIC, &nlm.hdr, NULL, NULL) ==
+ -1)
return -1;
/* We need to parse out the list of scan results and find the one
return r;
}
-struct nlma
-{
+struct nlma {
struct nlmsghdr hdr;
struct ifaddrmsg ifa;
char buffer[64];
};
#ifdef INET
-struct ifiaddr
-{
+struct ifiaddr {
unsigned int ifa_ifindex;
struct in_addr ifa_addr;
bool ifa_found;
};
static int
-_if_addressexists(__unused struct dhcpcd_ctx *ctx,
- void *arg, struct nlmsghdr *nlm)
+_if_addressexists(__unused struct dhcpcd_ctx *ctx, void *arg,
+ struct nlmsghdr *nlm)
{
struct ifiaddr *ia = arg;
in_addr_t this_addr;
.ifa_found = false,
};
struct nlma nlm = {
- .hdr.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg)),
- .hdr.nlmsg_type = RTM_GETADDR,
- .hdr.nlmsg_flags = NLM_F_REQUEST | NLM_F_MATCH,
- .ifa.ifa_family = AF_INET,
- .ifa.ifa_index = ifp->index,
+ .hdr.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg)),
+ .hdr.nlmsg_type = RTM_GETADDR,
+ .hdr.nlmsg_flags = NLM_F_REQUEST | NLM_F_MATCH,
+ .ifa.ifa_family = AF_INET,
+ .ifa.ifa_index = ifp->index,
};
int error = if_sendnetlink(ifp->ctx, NETLINK_ROUTE, &nlm.hdr,
}
#endif
-struct nlmr
-{
+struct nlmr {
struct nlmsghdr hdr;
struct rtmsg rt;
char buffer[256];
else
#endif
#ifdef RTPROT_DHCP
- if (rt->rt_dflags & RTDF_DHCP)
+ if (rt->rt_dflags & RTDF_DHCP)
nlm.rt.rtm_protocol = RTPROT_DHCP;
else
#endif
- if (rt->rt_dflags & RTDF_IFA_ROUTE)
+ if (rt->rt_dflags & RTDF_IFA_ROUTE)
nlm.rt.rtm_protocol = RTPROT_KERNEL;
else
nlm.rt.rtm_protocol = RTPROT_BOOT;
nlm.rt.rtm_type = RTN_UNICAST;
}
-#define ADDSA(type, sa) \
- add_attr_l(&nlm.hdr, sizeof(nlm), (type), \
- (const char *)(sa) + sa_addroffset((sa)), \
+#define ADDSA(type, sa) \
+ add_attr_l(&nlm.hdr, sizeof(nlm), (type), \
+ (const char *)(sa) + sa_addroffset((sa)), \
(unsigned short)sa_addrlen((sa)));
nlm.rt.rtm_dst_len = (unsigned char)sa_toprefix(&rt->rt_netmask);
/* rt->rt_dest and rt->gateway are unions where sockaddr_in6
metrics->rta_type = RTA_METRICS;
metrics->rta_len = RTA_LENGTH(0);
- rta_add_attr_32(metrics, sizeof(metricsbuf),
- RTAX_MTU, rt->rt_mtu);
+ rta_add_attr_32(metrics, sizeof(metricsbuf), RTAX_MTU,
+ rt->rt_mtu);
add_attr_l(&nlm.hdr, sizeof(nlm), RTA_METRICS,
RTA_DATA(metrics),
(unsigned short)RTA_PAYLOAD(metrics));
if (rt->rt_dflags & RTDF_RA) {
uint8_t pref;
- switch(rt->rt_pref) {
+ switch (rt->rt_pref) {
case RTPREF_LOW:
pref = ICMPV6_ROUTER_PREF_LOW;
break;
#endif
if (rt->rt_metric != 0)
- add_attr_32(&nlm.hdr, sizeof(nlm), RTA_PRIORITY,
- rt->rt_metric);
+ add_attr_32(&nlm.hdr, sizeof(nlm), RTA_PRIORITY, rt->rt_metric);
- return if_sendnetlink(rt->rt_ifp->ctx, NETLINK_ROUTE, &nlm.hdr,
- NULL, NULL);
+ return if_sendnetlink(rt->rt_ifp->ctx, NETLINK_ROUTE, &nlm.hdr, NULL,
+ NULL);
}
static int
-_if_initrt(struct dhcpcd_ctx *ctx, void *arg,
- struct nlmsghdr *nlm)
+_if_initrt(struct dhcpcd_ctx *ctx, void *arg, struct nlmsghdr *nlm)
{
struct rt rt, *rtn;
rb_tree_t *kroutes = arg;
if_initrt(struct dhcpcd_ctx *ctx, rb_tree_t *kroutes, int af)
{
struct nlmr nlm = {
- .hdr.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg)),
- .hdr.nlmsg_type = RTM_GETROUTE,
- .hdr.nlmsg_flags = NLM_F_REQUEST | NLM_F_MATCH,
- .rt.rtm_table = RT_TABLE_MAIN,
- .rt.rtm_family = (unsigned char)af,
+ .hdr.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg)),
+ .hdr.nlmsg_type = RTM_GETROUTE,
+ .hdr.nlmsg_flags = NLM_F_REQUEST | NLM_F_MATCH,
+ .rt.rtm_table = RT_TABLE_MAIN,
+ .rt.rtm_family = (unsigned char)af,
};
- return if_sendnetlink(ctx, NETLINK_ROUTE, &nlm.hdr,
- &_if_initrt, kroutes);
+ return if_sendnetlink(ctx, NETLINK_ROUTE, &nlm.hdr, &_if_initrt,
+ kroutes);
}
#ifdef INET
struct sockaddr sa;
struct sockaddr_ll sll;
struct sockaddr_storage ss;
- } su = {
- .sll = {
- .sll_family = PF_PACKET,
- .sll_protocol = htons(ETH_P_ALL),
- .sll_ifindex = (int)ifp->index,
- }
- };
+ } su = { .sll = {
+ .sll_family = PF_PACKET,
+ .sll_protocol = htons(ETH_P_ALL),
+ .sll_ifindex = (int)ifp->index,
+ } };
#ifdef PACKET_AUXDATA
int n;
#endif
if (bpf->bpf_buffer == NULL)
goto eexit;
- bpf->bpf_fd = xsocket(PF_PACKET, SOCK_RAW|SOCK_CXNB,htons(ETH_P_ALL));
+ bpf->bpf_fd = xsocket(PF_PACKET, SOCK_RAW | SOCK_CXNB,
+ htons(ETH_P_ALL));
if (bpf->bpf_fd == -1)
goto eexit;
/* In the ideal world, this would be set before the bind and filter. */
#ifdef PACKET_AUXDATA
n = 1;
- if (setsockopt(bpf->bpf_fd, SOL_PACKET, PACKET_AUXDATA,
- &n, sizeof(n)) != 0) {
+ if (setsockopt(bpf->bpf_fd, SOL_PACKET, PACKET_AUXDATA, &n,
+ sizeof(n)) != 0) {
if (errno != ENOPROTOOPT)
goto eexit;
}
* There is no way of flushing them from userland.
* As such, consumers need to inspect each packet to ensure it's valid.
* Or to put it another way, don't trust the Linux BPF filter.
- */
+ */
return bpf;
bytes = (ssize_t)len;
memcpy(data, bpf->bpf_buffer, (size_t)bytes);
#ifdef PACKET_AUXDATA
- for (cmsg = CMSG_FIRSTHDR(&msg);
- cmsg;
- cmsg = CMSG_NXTHDR(&msg, cmsg))
- {
+ for (cmsg = CMSG_FIRSTHDR(&msg); cmsg;
+ cmsg = CMSG_NXTHDR(&msg, cmsg)) {
if (cmsg->cmsg_level == SOL_PACKET &&
cmsg->cmsg_type == PACKET_AUXDATA) {
aux = (void *)CMSG_DATA(cmsg);
(unsigned short)(strlen(ia->iface->alias) + 1));
#endif
- add_attr_l(&nlm.hdr, sizeof(nlm), IFA_LOCAL,
- &ia->addr.s_addr, sizeof(ia->addr.s_addr));
+ add_attr_l(&nlm.hdr, sizeof(nlm), IFA_LOCAL, &ia->addr.s_addr,
+ sizeof(ia->addr.s_addr));
if (cmd == RTM_NEWADDR) {
#ifdef IFA_F_NOPREFIXROUTE
memset(&cinfo, 0, sizeof(cinfo));
cinfo.ifa_prefered = ia->pltime;
cinfo.ifa_valid = ia->vltime;
- add_attr_l(&nlm.hdr, sizeof(nlm), IFA_CACHEINFO,
- &cinfo, sizeof(cinfo));
+ add_attr_l(&nlm.hdr, sizeof(nlm), IFA_CACHEINFO, &cinfo,
+ sizeof(cinfo));
}
- if (if_sendnetlink(ia->iface->ctx, NETLINK_ROUTE, &nlm.hdr,
- NULL, NULL) == -1)
+ if (if_sendnetlink(ia->iface->ctx, NETLINK_ROUTE, &nlm.hdr, NULL,
+ NULL) == -1)
retval = -1;
return retval;
}
int
if_addrflags(__unused const struct interface *ifp,
-__unused const struct in_addr *addr, __unused const char *alias)
+ __unused const struct in_addr *addr, __unused const char *alias)
{
-
/* Linux has no support for IPv4 address flags */
return 0;
}
add_attr_l(&nlm.hdr, sizeof(nlm), IFA_LABEL,
ia->iface->alias, (unsigned short)(strlen(ia->iface->alias) + 1));
#endif
- add_attr_l(&nlm.hdr, sizeof(nlm), IFA_LOCAL,
- &ia->addr.s6_addr, sizeof(ia->addr.s6_addr));
+ add_attr_l(&nlm.hdr, sizeof(nlm), IFA_LOCAL, &ia->addr.s6_addr,
+ sizeof(ia->addr.s6_addr));
if (cmd == RTM_NEWADDR) {
#ifdef IPV6_MANAGETEMPADDR
memset(&cinfo, 0, sizeof(cinfo));
cinfo.ifa_prefered = ia->prefix_pltime;
cinfo.ifa_valid = ia->prefix_vltime;
- add_attr_l(&nlm.hdr, sizeof(nlm), IFA_CACHEINFO,
- &cinfo, sizeof(cinfo));
+ add_attr_l(&nlm.hdr, sizeof(nlm), IFA_CACHEINFO, &cinfo,
+ sizeof(cinfo));
}
- return if_sendnetlink(ia->iface->ctx, NETLINK_ROUTE, &nlm.hdr,
- NULL, NULL);
+ return if_sendnetlink(ia->iface->ctx, NETLINK_ROUTE, &nlm.hdr, NULL,
+ NULL);
}
-struct ifiaddr6
-{
+struct ifiaddr6 {
unsigned int ifa_ifindex;
struct in6_addr ifa_addr;
uint32_t ifa_flags;
};
static int
-_if_addrflags6(__unused struct dhcpcd_ctx *ctx,
- void *arg, struct nlmsghdr *nlm)
+_if_addrflags6(__unused struct dhcpcd_ctx *ctx, void *arg, struct nlmsghdr *nlm)
{
struct ifiaddr6 *ia = arg;
size_t len;
}
if (local) {
- if (IN6_ARE_ADDR_EQUAL(&ia->ifa_addr, local))
+ if (IN6_ARE_ADDR_EQUAL(&ia->ifa_addr, local))
ia->ifa_found = true;
} else if (address) {
- if (IN6_ARE_ADDR_EQUAL(&ia->ifa_addr, address))
+ if (IN6_ARE_ADDR_EQUAL(&ia->ifa_addr, address))
ia->ifa_found = true;
}
if (ia->ifa_found)
.ifa_found = false,
};
struct nlma nlm = {
- .hdr.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg)),
- .hdr.nlmsg_type = RTM_GETADDR,
- .hdr.nlmsg_flags = NLM_F_REQUEST | NLM_F_MATCH,
- .ifa.ifa_family = AF_INET6,
- .ifa.ifa_index = ifp->index,
+ .hdr.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg)),
+ .hdr.nlmsg_type = RTM_GETADDR,
+ .hdr.nlmsg_flags = NLM_F_REQUEST | NLM_F_MATCH,
+ .ifa.ifa_family = AF_INET6,
+ .ifa.ifa_index = ifp->index,
};
int error = if_sendnetlink(ifp->ctx, NETLINK_ROUTE, &nlm.hdr,
int
if_getlifetime6(__unused struct ipv6_addr *ia)
{
-
/* God knows how to work out address lifetimes on Linux */
errno = ENOTSUP;
return -1;
}
-struct nlml
-{
+struct nlml {
struct nlmsghdr hdr;
struct ifinfomsg i;
char buffer[32];
static void
add_attr_nest_end(struct nlmsghdr *n, struct rtattr *nest)
{
-
nest->rta_len = (unsigned short)((char *)NLMSG_TAIL(n) - (char *)nest);
}
#endif
}
if (rap->retrans != 0) {
- snprintf(path, sizeof(path), "%s/%s/retrans_time_ms",
- p_neigh, ifname);
+ snprintf(path, sizeof(path), "%s/%s/retrans_time_ms", p_neigh,
+ ifname);
if (if_writepathuint(ctx, path, rap->retrans) == -1)
error = -1;
}
* SUCH DAMAGE.
*/
-#include <sys/param.h>
#include <sys/types.h>
+#include <sys/param.h>
#include <arpa/inet.h>
-
+#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <fnmatch.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <unistd.h>
#include <time.h>
-#include <assert.h>
+#include <unistd.h>
-#include "config.h"
#include "common.h"
+#include "config.h"
#include "dhcp.h"
#include "dhcp6.h"
#include "dhcpcd-embedded.h"
#include "duid.h"
-#include "if.h"
#include "if-options.h"
+#include "if.h"
#include "ipv4.h"
#include "logerr.h"
#include "sa.h"
-#define IN_CONFIG_BLOCK(ifo) ((ifo)->options & DHCPCD_FORKED)
-#define SET_CONFIG_BLOCK(ifo) ((ifo)->options |= DHCPCD_FORKED)
-#define CLEAR_CONFIG_BLOCK(ifo) ((ifo)->options &= ~DHCPCD_FORKED)
+#define IN_CONFIG_BLOCK(ifo) ((ifo)->options & DHCPCD_FORKED)
+#define SET_CONFIG_BLOCK(ifo) ((ifo)->options |= DHCPCD_FORKED)
+#define CLEAR_CONFIG_BLOCK(ifo) ((ifo)->options &= ~DHCPCD_FORKED)
static unsigned long long default_options;
-const struct option cf_options[] = {
- {"background", no_argument, NULL, 'b'},
- {"script", required_argument, NULL, 'c'},
- {"debug", no_argument, NULL, 'd'},
- {"env", required_argument, NULL, 'e'},
- {"config", required_argument, NULL, 'f'},
- {"reconfigure", no_argument, NULL, 'g'},
- {"hostname", optional_argument, NULL, 'h'},
- {"vendorclassid", optional_argument, NULL, 'i'},
- {"logfile", required_argument, NULL, 'j'},
- {"release", no_argument, NULL, 'k'},
- {"leasetime", required_argument, NULL, 'l'},
- {"metric", required_argument, NULL, 'm'},
- {"rebind", no_argument, NULL, 'n'},
- {"option", required_argument, NULL, 'o'},
- {"persistent", no_argument, NULL, 'p'},
- {"quiet", no_argument, NULL, 'q'},
- {"request", optional_argument, NULL, 'r'},
- {"inform", optional_argument, NULL, 's'},
- {"inform6", optional_argument, NULL, O_INFORM6},
- {"timeout", required_argument, NULL, 't'},
- {"userclass", required_argument, NULL, 'u'},
+const struct option cf_options[] = { { "background", no_argument, NULL, 'b' },
+ { "script", required_argument, NULL, 'c' },
+ { "debug", no_argument, NULL, 'd' },
+ { "env", required_argument, NULL, 'e' },
+ { "config", required_argument, NULL, 'f' },
+ { "reconfigure", no_argument, NULL, 'g' },
+ { "hostname", optional_argument, NULL, 'h' },
+ { "vendorclassid", optional_argument, NULL, 'i' },
+ { "logfile", required_argument, NULL, 'j' },
+ { "release", no_argument, NULL, 'k' },
+ { "leasetime", required_argument, NULL, 'l' },
+ { "metric", required_argument, NULL, 'm' },
+ { "rebind", no_argument, NULL, 'n' },
+ { "option", required_argument, NULL, 'o' },
+ { "persistent", no_argument, NULL, 'p' },
+ { "quiet", no_argument, NULL, 'q' },
+ { "request", optional_argument, NULL, 'r' },
+ { "inform", optional_argument, NULL, 's' },
+ { "inform6", optional_argument, NULL, O_INFORM6 },
+ { "timeout", required_argument, NULL, 't' },
+ { "userclass", required_argument, NULL, 'u' },
#ifndef SMALL
- {"msuserclass", required_argument, NULL, O_MSUSERCLASS},
+ { "msuserclass", required_argument, NULL, O_MSUSERCLASS },
#endif
- {"vsio", required_argument, NULL, O_VSIO},
- {"vsio6", required_argument, NULL, O_VSIO6},
- {"vendor", required_argument, NULL, 'v'},
- {"waitip", optional_argument, NULL, 'w'},
- {"exit", no_argument, NULL, 'x'},
- {"allowinterfaces", required_argument, NULL, 'z'},
- {"reboot", required_argument, NULL, 'y'},
- {"noarp", no_argument, NULL, 'A'},
- {"nobackground", no_argument, NULL, 'B'},
- {"nohook", required_argument, NULL, 'C'},
- {"duid", optional_argument, NULL, 'D'},
- {"lastlease", no_argument, NULL, 'E'},
- {"fqdn", optional_argument, NULL, 'F'},
- {"nogateway", no_argument, NULL, 'G'},
- {"xidhwaddr", no_argument, NULL, 'H'},
- {"clientid", optional_argument, NULL, 'I'},
- {"broadcast", no_argument, NULL, 'J'},
- {"nolink", no_argument, NULL, 'K'},
- {"noipv4ll", no_argument, NULL, 'L'},
- {"manager", no_argument, NULL, 'M'},
- {"renew", no_argument, NULL, 'N'},
- {"nooption", required_argument, NULL, 'O'},
- {"printpidfile", no_argument, NULL, 'P'},
- {"require", required_argument, NULL, 'Q'},
- {"static", required_argument, NULL, 'S'},
- {"test", no_argument, NULL, 'T'},
- {"dumplease", no_argument, NULL, 'U'},
- {"variables", no_argument, NULL, 'V'},
- {"whitelist", required_argument, NULL, 'W'},
- {"blacklist", required_argument, NULL, 'X'},
- {"denyinterfaces", required_argument, NULL, 'Z'},
- {"oneshot", no_argument, NULL, '1'},
- {"ipv4only", no_argument, NULL, '4'},
- {"ipv6only", no_argument, NULL, '6'},
- {"anonymous", no_argument, NULL, O_ANONYMOUS},
- {"randomise_hwaddr",no_argument, NULL, O_RANDOMISE_HWADDR},
- {"arping", required_argument, NULL, O_ARPING},
- {"destination", required_argument, NULL, O_DESTINATION},
- {"fallback", required_argument, NULL, O_FALLBACK},
- {"ipv6rs", no_argument, NULL, O_IPV6RS},
- {"noipv6rs", no_argument, NULL, O_NOIPV6RS},
- {"ipv6ra_autoconf", no_argument, NULL, O_IPV6RA_AUTOCONF},
- {"ipv6ra_noautoconf", no_argument, NULL, O_IPV6RA_NOAUTOCONF},
- {"ipv6ra_fork", no_argument, NULL, O_IPV6RA_FORK},
- {"ipv4", no_argument, NULL, O_IPV4},
- {"noipv4", no_argument, NULL, O_NOIPV4},
- {"ipv6", no_argument, NULL, O_IPV6},
- {"noipv6", no_argument, NULL, O_NOIPV6},
- {"noalias", no_argument, NULL, O_NOALIAS},
- {"iaid", required_argument, NULL, O_IAID},
- {"ia_na", optional_argument, NULL, O_IA_NA},
- {"ia_ta", optional_argument, NULL, O_IA_TA},
- {"ia_pd", optional_argument, NULL, O_IA_PD},
- {"hostname_short", no_argument, NULL, O_HOSTNAME_SHORT},
- {"dev", required_argument, NULL, O_DEV},
- {"nodev", no_argument, NULL, O_NODEV},
- {"define", required_argument, NULL, O_DEFINE},
- {"definend", required_argument, NULL, O_DEFINEND},
- {"define6", required_argument, NULL, O_DEFINE6},
- {"embed", required_argument, NULL, O_EMBED},
- {"encap", required_argument, NULL, O_ENCAP},
- {"vendopt", required_argument, NULL, O_VENDOPT},
- {"vendclass", required_argument, NULL, O_VENDCLASS},
- {"authprotocol", required_argument, NULL, O_AUTHPROTOCOL},
- {"authtoken", required_argument, NULL, O_AUTHTOKEN},
- {"noauthrequired", no_argument, NULL, O_AUTHNOTREQUIRED},
- {"dhcp", no_argument, NULL, O_DHCP},
- {"nodhcp", no_argument, NULL, O_NODHCP},
- {"dhcp6", no_argument, NULL, O_DHCP6},
- {"nodhcp6", no_argument, NULL, O_NODHCP6},
- {"controlgroup", required_argument, NULL, O_CONTROLGRP},
- {"slaac", required_argument, NULL, O_SLAAC},
- {"gateway", no_argument, NULL, O_GATEWAY},
- {"reject", required_argument, NULL, O_REJECT},
- {"bootp", no_argument, NULL, O_BOOTP},
- {"nodelay", no_argument, NULL, O_NODELAY},
- {"noup", no_argument, NULL, O_NOUP},
- {"lastleaseextend", no_argument, NULL, O_LASTLEASE_EXTEND},
- {"inactive", no_argument, NULL, O_INACTIVE},
- {"mudurl", required_argument, NULL, O_MUDURL},
- {"link_rcvbuf", required_argument, NULL, O_LINK_RCVBUF},
- {"configure", no_argument, NULL, O_CONFIGURE},
- {"noconfigure", no_argument, NULL, O_NOCONFIGURE},
- {"arp_persistdefence", no_argument, NULL, O_ARP_PERSISTDEFENCE},
- {"request_time", required_argument, NULL, O_REQUEST_TIME},
- {"fallback_time", required_argument, NULL, O_FALLBACK_TIME},
- {"ipv4ll_time", required_argument, NULL, O_IPV4LL_TIME},
- {"nosyslog", no_argument, NULL, O_NOSYSLOG},
- {NULL, 0, NULL, '\0'}
-};
+ { "vsio", required_argument, NULL, O_VSIO },
+ { "vsio6", required_argument, NULL, O_VSIO6 },
+ { "vendor", required_argument, NULL, 'v' },
+ { "waitip", optional_argument, NULL, 'w' },
+ { "exit", no_argument, NULL, 'x' },
+ { "allowinterfaces", required_argument, NULL, 'z' },
+ { "reboot", required_argument, NULL, 'y' },
+ { "noarp", no_argument, NULL, 'A' },
+ { "nobackground", no_argument, NULL, 'B' },
+ { "nohook", required_argument, NULL, 'C' },
+ { "duid", optional_argument, NULL, 'D' },
+ { "lastlease", no_argument, NULL, 'E' },
+ { "fqdn", optional_argument, NULL, 'F' },
+ { "nogateway", no_argument, NULL, 'G' },
+ { "xidhwaddr", no_argument, NULL, 'H' },
+ { "clientid", optional_argument, NULL, 'I' },
+ { "broadcast", no_argument, NULL, 'J' },
+ { "nolink", no_argument, NULL, 'K' },
+ { "noipv4ll", no_argument, NULL, 'L' },
+ { "manager", no_argument, NULL, 'M' },
+ { "renew", no_argument, NULL, 'N' },
+ { "nooption", required_argument, NULL, 'O' },
+ { "printpidfile", no_argument, NULL, 'P' },
+ { "require", required_argument, NULL, 'Q' },
+ { "static", required_argument, NULL, 'S' },
+ { "test", no_argument, NULL, 'T' },
+ { "dumplease", no_argument, NULL, 'U' },
+ { "variables", no_argument, NULL, 'V' },
+ { "whitelist", required_argument, NULL, 'W' },
+ { "blacklist", required_argument, NULL, 'X' },
+ { "denyinterfaces", required_argument, NULL, 'Z' },
+ { "oneshot", no_argument, NULL, '1' },
+ { "ipv4only", no_argument, NULL, '4' },
+ { "ipv6only", no_argument, NULL, '6' },
+ { "anonymous", no_argument, NULL, O_ANONYMOUS },
+ { "randomise_hwaddr", no_argument, NULL, O_RANDOMISE_HWADDR },
+ { "arping", required_argument, NULL, O_ARPING },
+ { "destination", required_argument, NULL, O_DESTINATION },
+ { "fallback", required_argument, NULL, O_FALLBACK },
+ { "ipv6rs", no_argument, NULL, O_IPV6RS },
+ { "noipv6rs", no_argument, NULL, O_NOIPV6RS },
+ { "ipv6ra_autoconf", no_argument, NULL, O_IPV6RA_AUTOCONF },
+ { "ipv6ra_noautoconf", no_argument, NULL, O_IPV6RA_NOAUTOCONF },
+ { "ipv6ra_fork", no_argument, NULL, O_IPV6RA_FORK },
+ { "ipv4", no_argument, NULL, O_IPV4 },
+ { "noipv4", no_argument, NULL, O_NOIPV4 },
+ { "ipv6", no_argument, NULL, O_IPV6 },
+ { "noipv6", no_argument, NULL, O_NOIPV6 },
+ { "noalias", no_argument, NULL, O_NOALIAS },
+ { "iaid", required_argument, NULL, O_IAID },
+ { "ia_na", optional_argument, NULL, O_IA_NA },
+ { "ia_ta", optional_argument, NULL, O_IA_TA },
+ { "ia_pd", optional_argument, NULL, O_IA_PD },
+ { "hostname_short", no_argument, NULL, O_HOSTNAME_SHORT },
+ { "dev", required_argument, NULL, O_DEV },
+ { "nodev", no_argument, NULL, O_NODEV },
+ { "define", required_argument, NULL, O_DEFINE },
+ { "definend", required_argument, NULL, O_DEFINEND },
+ { "define6", required_argument, NULL, O_DEFINE6 },
+ { "embed", required_argument, NULL, O_EMBED },
+ { "encap", required_argument, NULL, O_ENCAP },
+ { "vendopt", required_argument, NULL, O_VENDOPT },
+ { "vendclass", required_argument, NULL, O_VENDCLASS },
+ { "authprotocol", required_argument, NULL, O_AUTHPROTOCOL },
+ { "authtoken", required_argument, NULL, O_AUTHTOKEN },
+ { "noauthrequired", no_argument, NULL, O_AUTHNOTREQUIRED },
+ { "dhcp", no_argument, NULL, O_DHCP },
+ { "nodhcp", no_argument, NULL, O_NODHCP },
+ { "dhcp6", no_argument, NULL, O_DHCP6 },
+ { "nodhcp6", no_argument, NULL, O_NODHCP6 },
+ { "controlgroup", required_argument, NULL, O_CONTROLGRP },
+ { "slaac", required_argument, NULL, O_SLAAC },
+ { "gateway", no_argument, NULL, O_GATEWAY },
+ { "reject", required_argument, NULL, O_REJECT },
+ { "bootp", no_argument, NULL, O_BOOTP },
+ { "nodelay", no_argument, NULL, O_NODELAY },
+ { "noup", no_argument, NULL, O_NOUP },
+ { "lastleaseextend", no_argument, NULL, O_LASTLEASE_EXTEND },
+ { "inactive", no_argument, NULL, O_INACTIVE },
+ { "mudurl", required_argument, NULL, O_MUDURL },
+ { "link_rcvbuf", required_argument, NULL, O_LINK_RCVBUF },
+ { "configure", no_argument, NULL, O_CONFIGURE },
+ { "noconfigure", no_argument, NULL, O_NOCONFIGURE },
+ { "arp_persistdefence", no_argument, NULL, O_ARP_PERSISTDEFENCE },
+ { "request_time", required_argument, NULL, O_REQUEST_TIME },
+ { "fallback_time", required_argument, NULL, O_FALLBACK_TIME },
+ { "ipv4ll_time", required_argument, NULL, O_IPV4LL_TIME },
+ { "nosyslog", no_argument, NULL, O_NOSYSLOG },
+ { NULL, 0, NULL, '\0' } };
static char *
add_environ(char ***array, const char *value, int uniq)
return newlist[i];
}
-#define PARSE_STRING 0
-#define PARSE_STRING_NULL 1
-#define PARSE_HWADDR 2
-#define parse_string(a, b, c) parse_str((a), (b), (c), PARSE_STRING)
+#define PARSE_STRING 0
+#define PARSE_STRING_NULL 1
+#define PARSE_HWADDR 2
+#define parse_string(a, b, c) parse_str((a), (b), (c), PARSE_STRING)
#define parse_nstring(a, b, c) parse_str((a), (b), (c), PARSE_STRING_NULL)
-#define parse_hwaddr(a, b, c) parse_str((a), (b), (c), PARSE_HWADDR)
+#define parse_hwaddr(a, b, c) parse_str((a), (b), (c), PARSE_HWADDR)
static ssize_t
parse_str(char *sbuf, size_t slen, const char *str, int flags)
{
}
if (*str == '\\') {
str++;
- switch((cmd = *str++)) {
+ switch ((cmd = *str++)) {
case '\0':
str--;
break;
if (c[1] != '\0') {
c[2] = '\0';
if (sbuf)
- *sbuf++ = (char)strtol(c, NULL, 16);
+ *sbuf++ = (char)strtol(c, NULL,
+ 16);
} else
l--;
break;
static int
parse_iaid(uint8_t *iaid, const char *arg, size_t len)
{
-
return parse_iaid1(iaid, arg, len, 1);
}
static int
parse_uint32(uint32_t *i, const char *arg)
{
-
return parse_iaid1((uint8_t *)i, arg, sizeof(uint32_t), 0);
}
#endif
*p++ = '\0';
i = strtoi(p, NULL, 10, 0, 32, &e);
if (e != 0 ||
- (net != NULL && inet_cidrtoaddr((int)i, net) != 0))
- {
+ (net != NULL && inet_cidrtoaddr((int)i, net) != 0)) {
logerrx("invalid CIDR: %s", p);
return -1;
}
parse_addr(__unused struct in_addr *addr, __unused struct in_addr *net,
__unused const char *arg)
{
-
logerrx("No IPv4 support");
return -1;
}
#endif
static void
-set_option_space(struct dhcpcd_ctx *ctx,
- const char *arg,
- const struct dhcp_opt **d, size_t *dl,
- const struct dhcp_opt **od, size_t *odl,
- struct if_options *ifo,
- uint8_t *request[], uint8_t *require[], uint8_t *no[], uint8_t *reject[])
+set_option_space(struct dhcpcd_ctx *ctx, const char *arg,
+ const struct dhcp_opt **d, size_t *dl, const struct dhcp_opt **od,
+ size_t *odl, struct if_options *ifo, uint8_t *request[], uint8_t *require[],
+ uint8_t *no[], uint8_t *reject[])
{
-
#if !defined(INET) && !defined(INET6)
UNUSED(ctx);
#endif
static char *
strwhite(const char *s)
{
-
if (s == NULL)
return NULL;
while (*s != ' ' && *s != '\t') {
static char *
strskipwhite(const char *s)
{
-
if (s == NULL || *s == '\0')
return NULL;
while (*s == ' ' || *s == '\t') {
static char *
strend(const char *s)
{
-
s = strskipwhite(s);
if (s == NULL)
return NULL;
if (*s != '"')
return strchr(s, ' ');
s++;
- for (; *s != '"' ; s++) {
+ for (; *s != '"'; s++) {
if (*s == '\0')
return NULL;
if (*s == '\\') {
/* Add a guard for static analysers.
* This should not be needed really because of the argument_required option
* in the options declaration above. */
-#define ARG_REQUIRED if (arg == NULL) goto arg_required
+#define ARG_REQUIRED \
+ if (arg == NULL) \
+ goto arg_required
- switch(opt) {
+ switch (opt) {
case 'f': /* FALLTHROUGH */
case 'g': /* FALLTHROUGH */
case 'n': /* FALLTHROUGH */
ARG_REQUIRED;
if (IN_CONFIG_BLOCK(ifo)) {
logerrx("%s: per interface scripts"
- " are no longer supported",
+ " are no longer supported",
ifname);
return -1;
}
return -1;
}
s = parse_nstring(ctx->script, dl, arg);
- if (s == -1 ||
- ctx->script[0] == '\0' ||
- strcmp(ctx->script, "/dev/null") == 0)
- {
+ if (s == -1 || ctx->script[0] == '\0' ||
+ strcmp(ctx->script, "/dev/null") == 0) {
free(ctx->script);
ctx->script = NULL;
}
ifo->leasetime = DHCP_INFINITE_LIFETIME;
break;
}
- ifo->leasetime = (uint32_t)strtou(arg, NULL,
- 0, 0, UINT32_MAX, &e);
+ ifo->leasetime = (uint32_t)strtou(arg, NULL, 0, 0, UINT32_MAX,
+ &e);
if (e) {
logerrx("failed to convert leasetime %s", arg);
return -1;
ARG_REQUIRED;
if (ctx->options & DHCPCD_PRINT_PIDFILE)
break;
- set_option_space(ctx, arg, &d, &dl, &od, &odl, ifo,
- &request, &require, &no, &reject);
+ set_option_space(ctx, arg, &d, &dl, &od, &odl, ifo, &request,
+ &require, &no, &reject);
if (make_option_mask(d, dl, od, odl, request, arg, 1) != 0 ||
make_option_mask(d, dl, od, odl, no, arg, -1) != 0 ||
- make_option_mask(d, dl, od, odl, reject, arg, -1) != 0)
- {
+ make_option_mask(d, dl, od, odl, reject, arg, -1) != 0) {
logerrx("unknown option: %s", arg);
return -1;
}
ARG_REQUIRED;
if (ctx->options & DHCPCD_PRINT_PIDFILE)
break;
- set_option_space(ctx, arg, &d, &dl, &od, &odl, ifo,
- &request, &require, &no, &reject);
+ set_option_space(ctx, arg, &d, &dl, &od, &odl, ifo, &request,
+ &require, &no, &reject);
if (make_option_mask(d, dl, od, odl, reject, arg, 1) != 0 ||
make_option_mask(d, dl, od, odl, request, arg, -1) != 0 ||
- make_option_mask(d, dl, od, odl, require, arg, -1) != 0)
- {
+ make_option_mask(d, dl, od, odl, require, arg, -1) != 0) {
logerrx("unknown option: %s", arg);
return -1;
}
break;
case 't':
ARG_REQUIRED;
- ifo->timeout = (uint32_t)strtou(arg, NULL, 0, 0, UINT32_MAX, &e);
+ ifo->timeout = (uint32_t)strtou(arg, NULL, 0, 0, UINT32_MAX,
+ &e);
if (e) {
logerrx("failed to convert timeout %s", arg);
return -1;
break;
case 'u':
dl = sizeof(ifo->userclass) - ifo->userclass[0] - 1;
- s = parse_string((char *)ifo->userclass +
- ifo->userclass[0] + 2, dl, arg);
+ s = parse_string((char *)ifo->userclass + ifo->userclass[0] + 2,
+ dl, arg);
if (s == -1) {
logerr("userclass");
return -1;
}
if (s != 0) {
ifo->userclass[ifo->userclass[0] + 1] = (uint8_t)s;
- ifo->userclass[0] = (uint8_t)(ifo->userclass[0] + s +1);
+ ifo->userclass[0] = (uint8_t)(ifo->userclass[0] + s +
+ 1);
}
break;
#ifndef SMALL
*p = ',';
if (e) {
logerrx("vendor option should be between"
- " 1 and %zu inclusive", opt_max);
+ " 1 and %zu inclusive",
+ opt_max);
return -1;
}
vsio->so_len = 0;
}
- for (sl = 0, vsio_so = vsio->so;
- sl < vsio->so_len;
+ for (sl = 0, vsio_so = vsio->so; sl < vsio->so_len;
sl++, vsio_so++)
opt_max -= opt_header + vsio_so->len;
if (opt_header + dl > opt_max) {
*p = ',';
if (e) {
logerrx("vendor option should be between"
- " 1 and 254 inclusive");
+ " 1 and 254 inclusive");
return -1;
}
s = sizeof(addr.s_addr);
}
} else {
- s = parse_string((char *)ifo->vendor +
- ifo->vendor[0] + 3, (size_t)s, arg);
+ s = parse_string((char *)ifo->vendor + ifo->vendor[0] +
+ 3,
+ (size_t)s, arg);
}
if (s == -1) {
logerr("vendor");
ARG_REQUIRED;
if (ctx->options & DHCPCD_PRINT_PIDFILE)
break;
- set_option_space(ctx, arg, &d, &dl, &od, &odl, ifo,
- &request, &require, &no, &reject);
+ set_option_space(ctx, arg, &d, &dl, &od, &odl, ifo, &request,
+ &require, &no, &reject);
if (make_option_mask(d, dl, od, odl, request, arg, -1) != 0 ||
make_option_mask(d, dl, od, odl, require, arg, -1) != 0 ||
- make_option_mask(d, dl, od, odl, no, arg, 1) != 0)
- {
+ make_option_mask(d, dl, od, odl, no, arg, 1) != 0) {
logerrx("unknown option: %s", arg);
return -1;
}
ARG_REQUIRED;
if (ctx->options & DHCPCD_PRINT_PIDFILE)
break;
- set_option_space(ctx, arg, &d, &dl, &od, &odl, ifo,
- &request, &require, &no, &reject);
+ set_option_space(ctx, arg, &d, &dl, &od, &odl, ifo, &request,
+ &require, &no, &reject);
if (make_option_mask(d, dl, od, odl, require, arg, 1) != 0 ||
make_option_mask(d, dl, od, odl, request, arg, 1) != 0 ||
make_option_mask(d, dl, od, odl, no, arg, -1) != 0 ||
- make_option_mask(d, dl, od, odl, reject, arg, -1) != 0)
- {
+ make_option_mask(d, dl, od, odl, reject, arg, -1) != 0) {
logerrx("unknown option: %s", arg);
return -1;
}
break;
}
if (parse_addr(&ifo->req_addr,
- ifo->req_mask.s_addr == 0 ? &ifo->req_mask : NULL,
- p) != 0)
+ ifo->req_mask.s_addr == 0 ? &ifo->req_mask :
+ NULL,
+ p) != 0)
return -1;
ifo->options |= DHCPCD_STATIC;
ifo->options &= ~DHCPCD_INFORM;
- } else if (strncmp(arg, "subnet_mask=",
- strlen("subnet_mask=")) == 0)
- {
+ } else if (strncmp(arg,
+ "subnet_mask=", strlen("subnet_mask=")) == 0) {
if (p == NULL) {
ifo->req_mask.s_addr = INADDR_ANY;
break;
if (parse_addr(&ifo->req_mask, NULL, p) != 0)
return -1;
} else if (strncmp(arg, "broadcast_address=",
- strlen("broadcast_address=")) == 0)
- {
+ strlen("broadcast_address=")) == 0) {
if (p == NULL) {
ifo->req_brd.s_addr = INADDR_ANY;
break;
if (parse_addr(&ifo->req_brd, NULL, p) != 0)
return -1;
} else if (strncmp(arg, "routes=", strlen("routes=")) == 0 ||
- strncmp(arg, "static_routes=",
- strlen("static_routes=")) == 0 ||
+ strncmp(arg, "static_routes=", strlen("static_routes=")) ==
+ 0 ||
strncmp(arg, "classless_static_routes=",
- strlen("classless_static_routes=")) == 0 ||
+ strlen("classless_static_routes=")) == 0 ||
strncmp(arg, "ms_classless_static_routes=",
- strlen("ms_classless_static_routes=")) == 0)
- {
+ strlen("ms_classless_static_routes=")) == 0) {
#ifdef INET
struct in_addr addr3;
*np++ = '\0';
np = strskipwhite(np);
if (parse_addr(&addr, &addr2, p) == -1 ||
- parse_addr(&addr3, NULL, np) == -1)
- {
+ parse_addr(&addr3, NULL, np) == -1) {
*fp = ' ';
return -1;
}
return -1;
#endif
} else if (strncmp(arg, "interface_mtu=",
- strlen("interface_mtu=")) == 0 ||
- strncmp(arg, "mtu=", strlen("mtu=")) == 0)
- {
+ strlen("interface_mtu=")) == 0 ||
+ strncmp(arg, "mtu=", strlen("mtu=")) == 0) {
if (p == NULL)
break;
- ifo->mtu = (unsigned int)strtou(p, NULL, 0,
- IPV4_MMTU, UINT_MAX, &e);
+ ifo->mtu = (unsigned int)strtou(p, NULL, 0, IPV4_MMTU,
+ UINT_MAX, &e);
if (e) {
logerrx("invalid MTU %s", p);
return -1;
}
- } else if (strncmp(arg, "ip6_address=", strlen("ip6_address=")) == 0) {
+ } else if (strncmp(arg,
+ "ip6_address=", strlen("ip6_address=")) == 0) {
#ifdef INET6
if (p == NULL) {
memset(&ifo->req_addr6, 0,
np = strchr(p, '/');
if (np)
*np++ = '\0';
- if ((i = inet_pton(AF_INET6, p, &ifo->req_addr6)) == 1) {
+ if ((i = inet_pton(AF_INET6, p, &ifo->req_addr6)) ==
+ 1) {
if (np) {
- ifo->req_prefix_len = (uint8_t)strtou(np,
- NULL, 0, 0, 128, &e);
+ ifo->req_prefix_len = (uint8_t)
+ strtou(np, NULL, 0, 0, 128, &e);
if (e) {
logerrx("%s: failed to "
- "convert prefix len",
+ "convert prefix len",
ifname);
return -1;
}
return -1;
if (strchr(arg, '/') == NULL)
addr2.s_addr = INADDR_BROADCAST;
- naddr = reallocarray(ifo->whitelist,
- ifo->whitelist_len + 2, sizeof(in_addr_t));
+ naddr = reallocarray(ifo->whitelist, ifo->whitelist_len + 2,
+ sizeof(in_addr_t));
if (naddr == NULL) {
logerr(__func__);
return -1;
return -1;
if (strchr(arg, '/') == NULL)
addr2.s_addr = INADDR_BROADCAST;
- naddr = reallocarray(ifo->blacklist,
- ifo->blacklist_len + 2, sizeof(in_addr_t));
+ naddr = reallocarray(ifo->blacklist, ifo->blacklist_len + 2,
+ sizeof(in_addr_t));
if (naddr == NULL) {
logerr(__func__);
return -1;
ARG_REQUIRED;
if (ctx->options & DHCPCD_PRINT_PIDFILE)
break;
- set_option_space(ctx, arg, &d, &dl, &od, &odl, ifo,
- &request, &require, &no, &reject);
- if (make_option_mask(d, dl, od, odl,
- ifo->dstmask, arg, 2) != 0)
- {
+ set_option_space(ctx, arg, &d, &dl, &od, &odl, ifo, &request,
+ &require, &no, &reject);
+ if (make_option_mask(d, dl, od, odl, ifo->dstmask, arg, 2) !=
+ 0) {
if (errno == EINVAL)
logerrx("option does not take"
- " an IPv4 address: %s", arg);
+ " an IPv4 address: %s",
+ arg);
else
logerrx("unknown option: %s", arg);
return -1;
return -1;
#else
if (ctx->options & DHCPCD_MANAGER &&
- !IN_CONFIG_BLOCK(ifo))
- {
+ !IN_CONFIG_BLOCK(ifo)) {
logerrx("IA PD must belong in an "
- "interface block");
+ "interface block");
return -1;
}
i = D6_OPTION_IA_PD;
#endif
}
- if (ctx->options & DHCPCD_MANAGER &&
- !IN_CONFIG_BLOCK(ifo) && arg)
- {
+ if (ctx->options & DHCPCD_MANAGER && !IN_CONFIG_BLOCK(ifo) &&
+ arg) {
logerrx("IA with IAID must belong in an "
- "interface block");
+ "interface block");
return -1;
}
ifo->options |= DHCPCD_IA_FORCED;
for (sl = 0; sl < ifo->ia_len; sl++) {
if ((arg == NULL && !ifo->ia[sl].iaid_set) ||
(arg != NULL && ifo->ia[sl].iaid_set &&
- ifo->ia[sl].ia_type == (uint16_t)i &&
- ifo->ia[sl].iaid[0] == iaid[0] &&
- ifo->ia[sl].iaid[1] == iaid[1] &&
- ifo->ia[sl].iaid[2] == iaid[2] &&
- ifo->ia[sl].iaid[3] == iaid[3]))
- {
- ia = &ifo->ia[sl];
+ ifo->ia[sl].ia_type == (uint16_t)i &&
+ ifo->ia[sl].iaid[0] == iaid[0] &&
+ ifo->ia[sl].iaid[1] == iaid[1] &&
+ ifo->ia[sl].iaid[2] == iaid[2] &&
+ ifo->ia[sl].iaid[3] == iaid[3])) {
+ ia = &ifo->ia[sl];
break;
}
}
if (ia == NULL) {
- ia = reallocarray(ifo->ia,
- ifo->ia_len + 1, sizeof(*ifo->ia));
+ ia = reallocarray(ifo->ia, ifo->ia_len + 1,
+ sizeof(*ifo->ia));
if (ia == NULL) {
logerr(__func__);
return -1;
ia->iaid_set = 1;
} else
ia->iaid_set = 0;
- if (!ia->iaid_set ||
- p == NULL ||
- ia->ia_type == D6_OPTION_IA_TA)
- {
+ if (!ia->iaid_set || p == NULL ||
+ ia->ia_type == D6_OPTION_IA_TA) {
memset(&ia->addr, 0, sizeof(ia->addr));
ia->prefix_len = 0;
} else {
NULL, 0, 8, 120, &e);
if (e) {
logerrx("%s: failed to convert"
- " prefix len",
+ " prefix len",
p);
ia->prefix_len = 0;
}
*fp++ = '\0';
fp = strskipwhite(fp);
}
- sla = reallocarray(ia->sla,
- ia->sla_len + 1, sizeof(*ia->sla));
+ sla = reallocarray(ia->sla, ia->sla_len + 1,
+ sizeof(*ia->sla));
if (sla == NULL) {
logerr(__func__);
return -1;
np = strchr(p, '/');
if (np)
*np++ = '\0';
- if (strlcpy(sla->ifname, p,
- sizeof(sla->ifname)) >= sizeof(sla->ifname))
- {
+ if (strlcpy(sla->ifname, p, sizeof(sla->ifname)) >=
+ sizeof(sla->ifname)) {
logerrx("%s: interface name too long", arg);
goto err_sla;
}
if (np)
*np++ = '\0';
if (*p != '\0') {
- sla->sla = (uint32_t)strtou(p, NULL,
- 0, 0, UINT32_MAX, &e);
+ sla->sla = (uint32_t)strtou(p, NULL, 0,
+ 0, UINT32_MAX, &e);
sla->sla_set = true;
if (e) {
logerrx("%s: failed to convert "
- "sla",
+ "sla",
ifname);
goto err_sla;
}
*np++ = '\0';
if (*p != '\0') {
sla->prefix_len = (uint8_t)strtou(p,
- NULL, 0, 0, 120, &e);
+ NULL, 0, 0, 120, &e);
if (e) {
logerrx("%s: failed to "
- "convert prefix len",
+ "convert prefix len",
ifname);
goto err_sla;
}
0, 0, UINT64_MAX, &e);
if (e) {
logerrx("%s: failed to "
- "convert suffix",
+ "convert suffix",
ifname);
goto err_sla;
}
slap = &ia->sla[sl];
if (slap->sla_set != sla->sla_set) {
logerrx("%s: cannot mix automatic "
- "and fixed SLA",
+ "and fixed SLA",
sla->ifname);
goto err_sla;
}
if (ia->prefix_len &&
(sla->prefix_len == ia->prefix_len ||
- slap->prefix_len == ia->prefix_len))
- {
+ slap->prefix_len == ia->prefix_len)) {
logerrx("%s: cannot delegte the same"
- "prefix length more than once",
+ "prefix length more than once",
sla->ifname);
goto err_sla;
}
if (!sla->sla_set &&
- strcmp(slap->ifname, sla->ifname) == 0)
- {
+ strcmp(slap->ifname, sla->ifname) == 0) {
logwarnx("%s: cannot specify the "
- "same interface twice with "
- "an automatic SLA",
+ "same interface twice with "
+ "an automatic SLA",
sla->ifname);
goto err_sla;
}
if (slap->sla_set && sla->sla_set &&
- slap->sla == sla->sla)
- {
+ slap->sla == sla->sla) {
logerrx("%s: cannot"
- " assign the same SLA %u"
- " more than once",
+ " assign the same SLA %u"
+ " more than once",
sla->ifname, sla->sla);
goto err_sla;
}
ia->sla_max = sla->sla;
}
break;
-err_sla:
+ err_sla:
ia->sla_len--;
return -1;
#endif
dop_len = &(*ldop)->embopts_len;
} else {
logerrx("embed must be after a define "
- "or encap");
+ "or encap");
return -1;
}
}
t |= OT_EMBED;
else if (strcasecmp(arg, "encap") == 0)
t |= OT_ENCAP;
- else if (strcasecmp(arg, "rfc3361") ==0)
+ else if (strcasecmp(arg, "rfc3361") == 0)
t |= OT_STRING | OT_RFC3361;
- else if (strcasecmp(arg, "rfc3442") ==0)
+ else if (strcasecmp(arg, "rfc3442") == 0)
t |= OT_STRING | OT_RFC3442;
else if (strcasecmp(arg, "option") == 0)
t |= OT_OPTION;
l = 0;
}
if (t & OT_ARRAY && t & (OT_STRING | OT_BINHEX) &&
- !(t & (OT_RFC1035 | OT_DOMAIN)))
- {
+ !(t & (OT_RFC1035 | OT_DOMAIN))) {
logwarnx("ignoring array for strings");
t &= ~OT_ARRAY;
}
/* variable */
if (!fp) {
if (!(t & OT_OPTION)) {
- logerrx("type %s requires a variable name",
+ logerrx("type %s requires a variable name",
arg);
return -1;
}
return -1;
}
if (opt != O_EMBED) {
- for (dl = 0, ndop = *dop; dl < *dop_len; dl++, ndop++)
- {
+ for (dl = 0, ndop = *dop; dl < *dop_len; dl++, ndop++) {
/* type 0 seems freshly malloced struct
* for us to use */
if (ndop->option == u || ndop->type == 0)
case O_VENDCLASS:
ARG_REQUIRED;
#ifdef SMALL
- logwarnx("%s: vendor options not compiled in", ifname);
- return -1;
+ logwarnx("%s: vendor options not compiled in", ifname);
+ return -1;
#else
fp = strwhite(arg);
if (fp)
}
for (vivco = ifo->vivco; vivco != vivco_endp; vivco++) {
if (vivco->en == (uint32_t)u) {
- logerrx("vendor class option for enterprise number %u already defined", vivco->en);
+ logerrx(
+ "vendor class option for enterprise number %u already defined",
+ vivco->en);
return -1;
}
}
dl = 0;
np = NULL;
}
- vivco = reallocarray(ifo->vivco,
- ifo->vivco_len + 1, sizeof(*ifo->vivco));
+ vivco = reallocarray(ifo->vivco, ifo->vivco_len + 1,
+ sizeof(*ifo->vivco));
if (vivco == NULL) {
- logerr( __func__);
+ logerr(__func__);
free(np);
return -1;
}
else
np = NULL;
}
- if (parse_uint32(&ifo->auth.token_snd_secretid,
- arg) == -1)
+ if (parse_uint32(&ifo->auth.token_snd_secretid, arg) ==
+ -1)
logerrx("%s: not a number", arg);
else
ifo->auth.token_rcv_secretid =
ifo->auth.token_snd_secretid;
if (np &&
- parse_uint32(&ifo->auth.token_rcv_secretid,
- np) == -1)
+ parse_uint32(&ifo->auth.token_rcv_secretid, np) ==
+ -1)
logerrx("%s: not a number", arg);
} else {
if (strcasecmp(arg, "hmacmd5") == 0 ||
if (strcasecmp(arg, "monocounter") == 0) {
ifo->auth.rdm = AUTH_RDM_MONOTONIC;
ifo->auth.options |= DHCPCD_AUTH_RDM_COUNTER;
- } else if (strcasecmp(arg, "monotonic") ==0 ||
+ } else if (strcasecmp(arg, "monotonic") == 0 ||
strcasecmp(arg, "monotime") == 0)
ifo->auth.rdm = AUTH_RDM_MONOTONIC;
else {
*np = '\0';
}
if (strcmp(arg, "0") == 0 || strcasecmp(arg, "forever") == 0)
- token->expire =0;
+ token->expire = 0;
else {
struct tm tm;
TAILQ_INSERT_TAIL(&ifo->auth.tokens, token, next);
break;
-invalid_token:
+ invalid_token:
free(token->realm);
free(token);
#else
logerr(__func__);
return -1;
}
- while ((i = getgrnam_r(arg, &grpbuf, p, dl, &grp)) ==
- ERANGE)
- {
+ while ((i = getgrnam_r(arg, &grpbuf, p, dl, &grp)) == ERANGE) {
size_t nl = dl * 2;
if (nl < dl) {
logerrx("control_group: out of buffer");
break;
case O_REQUEST_TIME:
ARG_REQUIRED;
- ifo->request_time =
- (uint32_t)strtou(arg, NULL, 0, 0, UINT32_MAX, &e);
+ ifo->request_time = (uint32_t)strtou(arg, NULL, 0, 0,
+ UINT32_MAX, &e);
if (e) {
logerrx("invalid request time: %s", arg);
return -1;
#ifdef INET
case O_FALLBACK_TIME:
ARG_REQUIRED;
- ifo->fallback_time =
- (uint32_t)strtou(arg, NULL, 0, 0, UINT32_MAX, &e);
+ ifo->fallback_time = (uint32_t)strtou(arg, NULL, 0, 0,
+ UINT32_MAX, &e);
if (e) {
logerrx("invalid fallback time: %s", arg);
return -1;
break;
case O_IPV4LL_TIME:
ARG_REQUIRED;
- ifo->ipv4ll_time =
- (uint32_t)strtou(arg, NULL, 0, 0, UINT32_MAX, &e);
+ ifo->ipv4ll_time = (uint32_t)strtou(arg, NULL, 0, 0, UINT32_MAX,
+ &e);
if (e) {
logerrx("invalid ipv4ll time: %s", arg);
return -1;
}
break;
#endif
- case O_NOSYSLOG:
- {
- unsigned int logopts = loggetopts();
+ case O_NOSYSLOG: {
+ unsigned int logopts = loggetopts();
- logopts &= ~LOGERR_LOG;
- logsetopts(logopts);
- }
- break;
+ logopts &= ~LOGERR_LOG;
+ logsetopts(logopts);
+ } break;
default:
return 0;
}
static int
parse_config_line(struct dhcpcd_ctx *ctx, const char *ifname,
- struct if_options *ifo, const char *opt, char *line,
- struct dhcp_opt **ldop, struct dhcp_opt **edop)
+ struct if_options *ifo, const char *opt, char *line, struct dhcp_opt **ldop,
+ struct dhcp_opt **edop)
{
unsigned int i;
for (i = 0; i < sizeof(cf_options) / sizeof(cf_options[0]); i++) {
- if (!cf_options[i].name ||
- strcmp(cf_options[i].name, opt) != 0)
+ if (!cf_options[i].name || strcmp(cf_options[i].name, opt) != 0)
continue;
if (cf_options[i].has_arg == required_argument && !line) {
static void
finish_config(struct if_options *ifo)
{
-
/* Terminate the encapsulated options */
if (ifo->vendor[0] && !(ifo->options & DHCPCD_VENDORRAW)) {
ifo->vendor[0]++;
ifo->options &= ~(DHCPCD_DHCP | DHCPCD_IPV4LL | DHCPCD_WAITIP4);
if (!(ifo->options & DHCPCD_IPV6))
- ifo->options &=
- ~(DHCPCD_IPV6RS | DHCPCD_DHCP6 | DHCPCD_WAITIP6);
+ ifo->options &= ~(
+ DHCPCD_IPV6RS | DHCPCD_DHCP6 | DHCPCD_WAITIP6);
if (!(ifo->options & DHCPCD_IPV6RS))
- ifo->options &=
- ~(DHCPCD_IPV6RA_AUTOCONF | DHCPCD_IPV6RA_REQRDNSS);
+ ifo->options &= ~(
+ DHCPCD_IPV6RA_AUTOCONF | DHCPCD_IPV6RA_REQRDNSS);
}
static struct if_options *
}
struct if_options *
-read_config(struct dhcpcd_ctx *ctx,
- const char *ifname, const char *ssid, const char *profile)
+read_config(struct dhcpcd_ctx *ctx, const char *ifname, const char *ssid,
+ const char *profile)
{
struct if_options *ifo;
char buf[UDPLEN_MAX], *bp; /* 64k max config file size */
if (ifname == NULL && !(ctx->options & DHCPCD_PRINT_PIDFILE)) {
/* Space for initial estimates */
#if defined(INET) && defined(INITDEFINES)
- ifo->dhcp_override =
- calloc(INITDEFINES, sizeof(*ifo->dhcp_override));
+ ifo->dhcp_override = calloc(INITDEFINES,
+ sizeof(*ifo->dhcp_override));
if (ifo->dhcp_override == NULL)
logerr(__func__);
else
#endif
#if defined(INET6) && defined(INITDEFINENDS)
- ifo->nd_override =
- calloc(INITDEFINENDS, sizeof(*ifo->nd_override));
+ ifo->nd_override = calloc(INITDEFINENDS,
+ sizeof(*ifo->nd_override));
if (ifo->nd_override == NULL)
logerr(__func__);
else
ifo->nd_override_len = INITDEFINENDS;
#endif
#if defined(INET6) && defined(INITDEFINE6S)
- ifo->dhcp6_override =
- calloc(INITDEFINE6S, sizeof(*ifo->dhcp6_override));
+ ifo->dhcp6_override = calloc(INITDEFINE6S,
+ sizeof(*ifo->dhcp6_override));
if (ifo->dhcp6_override == NULL)
logerr(__func__);
else
/* Trim trailing whitespace */
if (line) {
p = line + strlen(line) - 1;
- while (p != line &&
- (*p == ' ' || *p == '\t') &&
+ while (p != line && (*p == ' ' || *p == '\t') &&
*(p - 1) != '\\')
*p-- = '\0';
}
- parse_config_line(ctx, NULL, ifo, option, line,
- &ldop, &edop);
+ parse_config_line(ctx, NULL, ifo, option, line, &ldop,
+ &edop);
}
#ifdef INET
ctx->dhcp_opts_len = ifo->dhcp_override_len;
#else
for (i = 0, opt = ifo->dhcp_override;
- i < ifo->dhcp_override_len;
- i++, opt++)
+ i < ifo->dhcp_override_len; i++, opt++)
free_dhcp_opt_embenc(opt);
free(ifo->dhcp_override);
#endif
ctx->dhcp6_opts_len = ifo->dhcp6_override_len;
#endif
#else
- for (i = 0, opt = ifo->nd_override;
- i < ifo->nd_override_len;
+ for (i = 0, opt = ifo->nd_override; i < ifo->nd_override_len;
i++, opt++)
free_dhcp_opt_embenc(opt);
free(ifo->nd_override);
for (i = 0, opt = ifo->dhcp6_override;
- i < ifo->dhcp6_override_len;
- i++, opt++)
+ i < ifo->dhcp6_override_len; i++, opt++)
free_dhcp_opt_embenc(opt);
free(ifo->dhcp6_override);
#endif
/* Trim trailing whitespace */
if (line) {
p = line + strlen(line) - 1;
- while (p != line &&
- (*p == ' ' || *p == '\t') &&
+ while (p != line && (*p == ' ' || *p == '\t') &&
*(p - 1) != '\\')
*p-- = '\0';
}
if (ifname)
continue;
- n = reallocarray(ctx->ifcv,
- (size_t)ctx->ifcc + 1, sizeof(char *));
+ n = reallocarray(ctx->ifcv, (size_t)ctx->ifcc + 1,
+ sizeof(char *));
if (n == NULL) {
logerr(__func__);
continue;
}
int
-add_options(struct dhcpcd_ctx *ctx, const char *ifname,
- struct if_options *ifo, int argc, char **argv)
+add_options(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo,
+ int argc, char **argv)
{
int oi, opt, r;
unsigned long long wait_opts;
* only use the dhcpcd.conf entry for that. */
if (ifname != NULL)
wait_opts = ifo->options & DHCPCD_WAITOPTS;
- while ((opt = getopt_long(argc, argv,
- ctx->options & DHCPCD_PRINT_PIDFILE ? NOERR_IF_OPTS : IF_OPTS,
- cf_options, &oi)) != -1)
- {
+ while (
+ (opt = getopt_long(argc, argv,
+ ctx->options & DHCPCD_PRINT_PIDFILE ? NOERR_IF_OPTS : IF_OPTS,
+ cf_options, &oi)) != -1) {
r = parse_option(ctx, ifname, ifo, opt, optarg, NULL, NULL);
if (r != 1)
break;
return r;
}
-char
-**alloc_args(int argc, char **argv)
+char **
+alloc_args(int argc, char **argv)
{
int i;
size_t strslen = 0, len;
size_t nptrs = (size_t)argc;
- size_t ptrslen = nptrs * sizeof(char *);
+ size_t ptrslen = nptrs * sizeof(char *);
void *buf;
char **ptrs, *strsp;
* free list. */
ifp = ctx->ifaces != NULL ? TAILQ_FIRST(ctx->ifaces) : NULL;
if (ifp != NULL) {
- RB_TREE_FOREACH(rt, &ifo->routes) {
+ RB_TREE_FOREACH(rt, &ifo->routes)
+ {
if (rt->rt_ifp == NULL)
rt->rt_ifp = ifp;
}
free(ifo->blacklist);
free(ifo->fallback);
- for (opt = ifo->dhcp_override;
- ifo->dhcp_override_len > 0;
+ for (opt = ifo->dhcp_override; ifo->dhcp_override_len > 0;
opt++, ifo->dhcp_override_len--)
free_dhcp_opt_embenc(opt);
free(ifo->dhcp_override);
- for (opt = ifo->nd_override;
- ifo->nd_override_len > 0;
+ for (opt = ifo->nd_override; ifo->nd_override_len > 0;
opt++, ifo->nd_override_len--)
free_dhcp_opt_embenc(opt);
free(ifo->nd_override);
- for (opt = ifo->dhcp6_override;
- ifo->dhcp6_override_len > 0;
+ for (opt = ifo->dhcp6_override; ifo->dhcp6_override_len > 0;
opt++, ifo->dhcp6_override_len--)
free_dhcp_opt_embenc(opt);
free(ifo->dhcp6_override);
#ifndef SMALL
- for (vo = ifo->vivco;
- ifo->vivco_len > 0;
- vo++, ifo->vivco_len--)
+ for (vo = ifo->vivco; ifo->vivco_len > 0; vo++, ifo->vivco_len--)
free(vo->data);
free(ifo->vivco);
- for (vsio = ifo->vsio;
- ifo->vsio_len > 0;
- vsio++, ifo->vsio_len--)
- {
- for (vsio_so = vsio->so;
- vsio->so_len > 0;
+ for (vsio = ifo->vsio; ifo->vsio_len > 0; vsio++, ifo->vsio_len--) {
+ for (vsio_so = vsio->so; vsio->so_len > 0;
vsio_so++, vsio->so_len--)
free(vsio_so->data);
free(vsio->so);
}
free(ifo->vsio);
- for (vsio = ifo->vsio6;
- ifo->vsio6_len > 0;
- vsio++, ifo->vsio6_len--)
- {
- for (vsio_so = vsio->so;
- vsio->so_len > 0;
+ for (vsio = ifo->vsio6; ifo->vsio6_len > 0; vsio++, ifo->vsio6_len--) {
+ for (vsio_so = vsio->so; vsio->so_len > 0;
vsio_so++, vsio->so_len--)
free(vsio_so->data);
free(vsio->so);
}
free(ifo->vsio6);
#endif
- for (opt = ifo->vivso_override;
- ifo->vivso_override_len > 0;
+ for (opt = ifo->vivso_override; ifo->vivso_override_len > 0;
opt++, ifo->vivso_override_len--)
free_dhcp_opt_embenc(opt);
free(ifo->vivso_override);
#include <sys/param.h>
#include <sys/socket.h>
+
#include <net/if.h>
#include <netinet/in.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 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
-#define DEFAULT_REQUEST 180 /* secs to request, mirror DHCP6 */
-#define DEFAULT_FALLBACK 5 /* secs until fallback */
-#define DEFAULT_IPV4LL 5 /* secs until ipv4ll */
+#define DEFAULT_TIMEOUT 30
+#define DEFAULT_REBOOT 5
+#define DEFAULT_REQUEST 180 /* secs to request, mirror DHCP6 */
+#define DEFAULT_FALLBACK 5 /* secs until fallback */
+#define DEFAULT_IPV4LL 5 /* secs until ipv4ll */
#ifndef HOSTNAME_MAX_LEN
-#define HOSTNAME_MAX_LEN 250 /* 255 - 3 (FQDN) - 2 (DNS enc) */
+#define HOSTNAME_MAX_LEN 250 /* 255 - 3 (FQDN) - 2 (DNS enc) */
#endif
-#define DHCP_OPTION_MAX_LEN 255
+#define DHCP_OPTION_MAX_LEN 255
-#define DHCPCD_ARP (1ULL << 0)
-#define DHCPCD_RELEASE (1ULL << 1)
-#define DHCPCD_RTBUILD (1ULL << 2)
-#define DHCPCD_GATEWAY (1ULL << 3)
-#define DHCPCD_STATIC (1ULL << 4)
+#define DHCPCD_ARP (1ULL << 0)
+#define DHCPCD_RELEASE (1ULL << 1)
+#define DHCPCD_RTBUILD (1ULL << 2)
+#define DHCPCD_GATEWAY (1ULL << 3)
+#define DHCPCD_STATIC (1ULL << 4)
// unused (1ULL << 5)
-#define DHCPCD_ARP_PERSISTDEFENCE (1ULL << 6)
-#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_MANAGER (1ULL << 17)
-#define DHCPCD_HOSTNAME (1ULL << 18)
-#define DHCPCD_CLIENTID (1ULL << 19)
-#define DHCPCD_LINK (1ULL << 20)
-#define DHCPCD_ANONYMOUS (1ULL << 21)
-#define DHCPCD_BACKGROUND (1ULL << 22)
-#define DHCPCD_VENDORRAW (1ULL << 23)
+#define DHCPCD_ARP_PERSISTDEFENCE (1ULL << 6)
+#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_MANAGER (1ULL << 17)
+#define DHCPCD_HOSTNAME (1ULL << 18)
+#define DHCPCD_CLIENTID (1ULL << 19)
+#define DHCPCD_LINK (1ULL << 20)
+#define DHCPCD_ANONYMOUS (1ULL << 21)
+#define DHCPCD_BACKGROUND (1ULL << 22)
+#define DHCPCD_VENDORRAW (1ULL << 23)
// unused (1ULL << 24)
#define DHCPCD_WAITIP (1ULL << 25)
#define DHCPCD_SLAACPRIVATE (1ULL << 26)
#define DHCPCD_INFORM6 (1ULL << 52)
#define DHCPCD_WANTDHCP (1ULL << 53)
#define DHCPCD_IPV6RA_AUTOCONF (1ULL << 54)
-#define DHCPCD_ROUTER_HOST_ROUTE_WARNED (1ULL << 55)
+#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_SLAACTEMP (1ULL << 62)
+#define DHCPCD_SLAACTEMP (1ULL << 62)
#define DHCPCD_PRIVSEPROOT (1ULL << 63)
-#define DHCPCD_NODROP (DHCPCD_EXITING | DHCPCD_PERSISTENT)
+#define DHCPCD_NODROP (DHCPCD_EXITING | DHCPCD_PERSISTENT)
-#define DHCPCD_WAITOPTS (DHCPCD_WAITIP | DHCPCD_WAITIP4 | DHCPCD_WAITIP6)
+#define DHCPCD_WAITOPTS (DHCPCD_WAITIP | DHCPCD_WAITIP4 | DHCPCD_WAITIP6)
-#define DHCPCD_WARNINGS (DHCPCD_CSR_WARNED | \
- DHCPCD_ROUTER_HOST_ROUTE_WARNED)
+#define DHCPCD_WARNINGS (DHCPCD_CSR_WARNED | DHCPCD_ROUTER_HOST_ROUTE_WARNED)
/* These options only make sense in the config file, so don't use any
valid short options for them */
-#define O_BASE MAX('z', 'Z') + 1
-#define O_ARPING O_BASE + 1
-#define O_FALLBACK O_BASE + 2
-#define O_DESTINATION O_BASE + 3
-#define O_IPV6RS O_BASE + 4
-#define O_NOIPV6RS O_BASE + 5
-#define O_IPV6RA_FORK O_BASE + 6
-#define O_LINK_RCVBUF O_BASE + 7
-#define O_ANONYMOUS O_BASE + 8
-#define O_NOALIAS O_BASE + 9
-#define O_IA_NA O_BASE + 10
-#define O_IA_TA O_BASE + 11
-#define O_IA_PD O_BASE + 12
-#define O_HOSTNAME_SHORT O_BASE + 13
-#define O_DEV O_BASE + 14
-#define O_NODEV O_BASE + 15
-#define O_NOIPV4 O_BASE + 16
-#define O_NOIPV6 O_BASE + 17
-#define O_IAID O_BASE + 18
-#define O_DEFINE O_BASE + 19
-#define O_DEFINE6 O_BASE + 20
-#define O_EMBED O_BASE + 21
-#define O_ENCAP O_BASE + 22
-#define O_VENDOPT O_BASE + 23
-#define O_VENDCLASS O_BASE + 24
-#define O_AUTHPROTOCOL O_BASE + 25
-#define O_AUTHTOKEN O_BASE + 26
-#define O_AUTHNOTREQUIRED O_BASE + 27
-#define O_NODHCP O_BASE + 28
-#define O_NODHCP6 O_BASE + 29
-#define O_DHCP O_BASE + 30
-#define O_DHCP6 O_BASE + 31
-#define O_IPV4 O_BASE + 32
-#define O_IPV6 O_BASE + 33
-#define O_CONTROLGRP O_BASE + 34
-#define O_SLAAC O_BASE + 35
-#define O_GATEWAY O_BASE + 36
-#define O_NOUP O_BASE + 37
-#define O_IPV6RA_AUTOCONF O_BASE + 38
-#define O_IPV6RA_NOAUTOCONF O_BASE + 39
-#define O_REJECT O_BASE + 40
-#define O_BOOTP O_BASE + 42
-#define O_DEFINEND O_BASE + 43
-#define O_NODELAY O_BASE + 44
-#define O_INFORM6 O_BASE + 45
-#define O_LASTLEASE_EXTEND O_BASE + 46
-#define O_INACTIVE O_BASE + 47
-#define O_MUDURL O_BASE + 48
-#define O_MSUSERCLASS O_BASE + 49
-#define O_CONFIGURE O_BASE + 50
-#define O_NOCONFIGURE O_BASE + 51
-#define O_RANDOMISE_HWADDR O_BASE + 52
-#define O_ARP_PERSISTDEFENCE O_BASE + 53
-#define O_REQUEST_TIME O_BASE + 54
-#define O_FALLBACK_TIME O_BASE + 55
-#define O_IPV4LL_TIME O_BASE + 56
-#define O_VSIO O_BASE + 57
-#define O_VSIO6 O_BASE + 58
-#define O_NOSYSLOG O_BASE + 59
+#define O_BASE MAX('z', 'Z') + 1
+#define O_ARPING O_BASE + 1
+#define O_FALLBACK O_BASE + 2
+#define O_DESTINATION O_BASE + 3
+#define O_IPV6RS O_BASE + 4
+#define O_NOIPV6RS O_BASE + 5
+#define O_IPV6RA_FORK O_BASE + 6
+#define O_LINK_RCVBUF O_BASE + 7
+#define O_ANONYMOUS O_BASE + 8
+#define O_NOALIAS O_BASE + 9
+#define O_IA_NA O_BASE + 10
+#define O_IA_TA O_BASE + 11
+#define O_IA_PD O_BASE + 12
+#define O_HOSTNAME_SHORT O_BASE + 13
+#define O_DEV O_BASE + 14
+#define O_NODEV O_BASE + 15
+#define O_NOIPV4 O_BASE + 16
+#define O_NOIPV6 O_BASE + 17
+#define O_IAID O_BASE + 18
+#define O_DEFINE O_BASE + 19
+#define O_DEFINE6 O_BASE + 20
+#define O_EMBED O_BASE + 21
+#define O_ENCAP O_BASE + 22
+#define O_VENDOPT O_BASE + 23
+#define O_VENDCLASS O_BASE + 24
+#define O_AUTHPROTOCOL O_BASE + 25
+#define O_AUTHTOKEN O_BASE + 26
+#define O_AUTHNOTREQUIRED O_BASE + 27
+#define O_NODHCP O_BASE + 28
+#define O_NODHCP6 O_BASE + 29
+#define O_DHCP O_BASE + 30
+#define O_DHCP6 O_BASE + 31
+#define O_IPV4 O_BASE + 32
+#define O_IPV6 O_BASE + 33
+#define O_CONTROLGRP O_BASE + 34
+#define O_SLAAC O_BASE + 35
+#define O_GATEWAY O_BASE + 36
+#define O_NOUP O_BASE + 37
+#define O_IPV6RA_AUTOCONF O_BASE + 38
+#define O_IPV6RA_NOAUTOCONF O_BASE + 39
+#define O_REJECT O_BASE + 40
+#define O_BOOTP O_BASE + 42
+#define O_DEFINEND O_BASE + 43
+#define O_NODELAY O_BASE + 44
+#define O_INFORM6 O_BASE + 45
+#define O_LASTLEASE_EXTEND O_BASE + 46
+#define O_INACTIVE O_BASE + 47
+#define O_MUDURL O_BASE + 48
+#define O_MSUSERCLASS O_BASE + 49
+#define O_CONFIGURE O_BASE + 50
+#define O_NOCONFIGURE O_BASE + 51
+#define O_RANDOMISE_HWADDR O_BASE + 52
+#define O_ARP_PERSISTDEFENCE O_BASE + 53
+#define O_REQUEST_TIME O_BASE + 54
+#define O_FALLBACK_TIME O_BASE + 55
+#define O_IPV4LL_TIME O_BASE + 56
+#define O_VSIO O_BASE + 57
+#define O_VSIO6 O_BASE + 58
+#define O_NOSYSLOG O_BASE + 59
extern const struct option cf_options[];
struct auth auth;
};
-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 **);
+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 dhcpcd_ctx *, struct if_options *);
* SUCH DAMAGE.
*/
+#include <sys/ioctl.h>
+#include <sys/mac.h>
+#include <sys/pfmod.h>
+#include <sys/tihdr.h>
+#include <sys/utsname.h>
+
+#include <net/if_dl.h>
+#include <net/if_types.h>
+#include <netinet/udp.h>
+#include <netinet/if_ether.h>
+
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <ifaddrs.h>
-#include <libdlpi.h>
+#include <inet/ip.h>
#include <kstat.h>
+#include <libdlpi.h>
#include <stddef.h>
#include <stdlib.h>
-#include <stropts.h>
#include <string.h>
+#include <stropts.h>
#include <unistd.h>
-#include <inet/ip.h>
-
-#include <net/if_dl.h>
-#include <net/if_types.h>
-
-#include <netinet/if_ether.h>
-#include <netinet/udp.h>
-
-#include <sys/ioctl.h>
-#include <sys/mac.h>
-#include <sys/pfmod.h>
-#include <sys/tihdr.h>
-#include <sys/utsname.h>
-
/* Private libsocket interface we can hook into to get
* a better getifaddrs(3).
* From libsocket_priv.h, which is not always distributed so is here. */
extern int getallifaddrs(sa_family_t, struct ifaddrs **, int64_t);
-#include "config.h"
#include "bpf.h"
#include "common.h"
+#include "config.h"
#include "dhcp.h"
-#include "if.h"
#include "if-options.h"
+#include "if.h"
#include "ipv4.h"
#include "ipv6.h"
#include "ipv6nd.h"
#include "sa.h"
#ifndef ARP_MOD_NAME
-# define ARP_MOD_NAME "arp"
+#define ARP_MOD_NAME "arp"
#endif
#ifndef RT_ROUNDUP
-#define RT_ROUNDUP(a) \
- ((a) > 0 ? (1 + (((a) - 1) | (sizeof(int32_t) - 1))) : sizeof(int32_t))
+#define RT_ROUNDUP(a) \
+ ((a) > 0 ? (1 + (((a) - 1) | (sizeof(int32_t) - 1))) : sizeof(int32_t))
#define RT_ADVANCE(x, n) ((x) += RT_ROUNDUP(sa_len((n))))
#endif
-#define COPYOUT(sin, sa) do { \
- if ((sa) && ((sa)->sa_family == AF_INET)) \
- (sin) = ((const struct sockaddr_in *)(const void *) \
- (sa))->sin_addr; \
+#define COPYOUT(sin, sa) \
+ do { \
+ if ((sa) && ((sa)->sa_family == AF_INET)) \
+ (sin) = \
+ ((const struct sockaddr_in *)(const void *)(sa)) \
+ ->sin_addr; \
} while (0)
-#define COPYOUT6(sin, sa) do { \
- if ((sa) && ((sa)->sa_family == AF_INET6)) \
- (sin) = ((const struct sockaddr_in6 *)(const void *) \
- (sa))->sin6_addr; \
+#define COPYOUT6(sin, sa) \
+ do { \
+ if ((sa) && ((sa)->sa_family == AF_INET6)) \
+ (sin) = \
+ ((const struct sockaddr_in6 *)(const void *)(sa)) \
+ ->sin6_addr; \
} while (0)
#define COPYSA(dst, src) memcpy((dst), (src), sa_len((src)))
-struct rtm
-{
+struct rtm {
struct rt_msghdr hdr;
char buffer[sizeof(struct sockaddr_storage) * RTAX_MAX];
};
int
if_init(struct interface *ifp)
{
-
#ifdef INET
if (if_plumb(RTM_NEWADDR, ifp->ctx, AF_INET, ifp->name) == -1 &&
errno != EEXIST)
int
if_conf(__unused struct interface *ifp)
{
-
return 0;
}
int
if_opensockets_os(struct dhcpcd_ctx *ctx)
{
- struct priv *priv;
- int n;
+ struct priv *priv;
+ int n;
if ((priv = malloc(sizeof(*priv))) == NULL)
return -1;
* Sadly there is no way of doing this for route(4) messages
* generated from addresses we add/delete. */
n = 0;
- if (setsockopt(ctx->link_fd, SOL_SOCKET, SO_USELOOPBACK,
- &n, sizeof(n)) == -1)
+ if (setsockopt(ctx->link_fd, SOL_SOCKET, SO_USELOOPBACK, &n,
+ sizeof(n)) == -1)
logerr("%s: SO_USELOOPBACK", __func__);
return 0;
if_closesockets_os(struct dhcpcd_ctx *ctx)
{
#ifdef INET6
- struct priv *priv;
+ struct priv *priv;
priv = (struct priv *)ctx->priv;
if (priv && priv->pf_inet6_fd != -1)
int
if_setmac(struct interface *ifp, void *mac, uint8_t maclen)
{
-
errno = ENOTSUP;
return -1;
}
int
if_carrier(struct interface *ifp, __unused const void *ifadata)
{
- kstat_ctl_t *kcp;
- kstat_t *ksp;
- kstat_named_t *knp;
- link_state_t linkstate;
+ kstat_ctl_t *kcp;
+ kstat_t *ksp;
+ kstat_named_t *knp;
+ link_state_t linkstate;
kcp = kstat_open();
if (kcp == NULL)
bool
if_roaming(__unused struct interface *ifp)
{
-
return false;
}
int
if_mtu_os(const struct interface *ifp)
{
- dlpi_handle_t dh;
- dlpi_info_t dlinfo;
- int mtu;
+ dlpi_handle_t dh;
+ dlpi_info_t dlinfo;
+ int mtu;
if (dlpi_open(ifp->name, &dh, 0) != DLPI_SUCCESS)
return -1;
int
if_getssid(__unused struct interface *ifp)
{
-
errno = ENOTSUP;
return -1;
}
bool
if_ignore(__unused struct dhcpcd_ctx *ctx, __unused const char *ifname)
{
-
return false;
}
unsigned short
if_vlanid(__unused const struct interface *ifp)
{
-
return 0;
}
int
if_vimaster(__unused struct dhcpcd_ctx *ctx, __unused const char *ifname)
{
-
return 0;
}
int
if_machinearch(__unused char *str, __unused size_t len)
{
-
/* There is no extra data really.
* isainfo -v does return amd64, but also i386. */
return 0;
}
struct linkwalk {
- struct ifaddrs *lw_ifa;
- int lw_error;
+ struct ifaddrs *lw_ifa;
+ int lw_error;
};
static boolean_t
if_newaddr(const char *ifname, void *arg)
{
- struct linkwalk *lw = arg;
+ struct linkwalk *lw = arg;
int error;
- struct ifaddrs *ifa;
- dlpi_handle_t dh;
- dlpi_info_t dlinfo;
- uint8_t pa[DLPI_PHYSADDR_MAX];
- size_t pa_len;
- struct sockaddr_dl *sdl;
+ struct ifaddrs *ifa;
+ dlpi_handle_t dh;
+ dlpi_info_t dlinfo;
+ uint8_t pa[DLPI_PHYSADDR_MAX];
+ size_t pa_len;
+ struct sockaddr_dl *sdl;
ifa = NULL;
error = dlpi_open(ifname, &dh, 0);
* physical address, it's all zero's.
* So cal dlpi_get_physaddr. */
pa_len = DLPI_PHYSADDR_MAX;
- if (dlpi_get_physaddr(dh, DL_CURR_PHYS_ADDR,
- pa, &pa_len) != DLPI_SUCCESS)
+ if (dlpi_get_physaddr(dh, DL_CURR_PHYS_ADDR, pa, &pa_len) !=
+ DLPI_SUCCESS)
goto failed;
if ((ifa = calloc(1, sizeof(*ifa))) == NULL)
static struct ifaddrs *
if_ifa_lo0(void)
{
- struct ifaddrs *ifa;
- struct sockaddr_dl *sdl;
+ struct ifaddrs *ifa;
+ struct sockaddr_dl *sdl;
if ((ifa = calloc(1, sizeof(*ifa))) == NULL)
return NULL;
int
if_getifaddrs(struct ifaddrs **ifap)
{
- struct linkwalk lw;
- struct ifaddrs *ifa;
+ struct linkwalk lw;
+ struct ifaddrs *ifa;
/* Private libc function which we should not have to call
* to get non UP addresses. */
static void
if_linkaddr(struct sockaddr_dl *sdl, const struct interface *ifp)
{
-
memset(sdl, 0, sizeof(*sdl));
sdl->sdl_family = AF_LINK;
sdl->sdl_nlen = sdl->sdl_alen = sdl->sdl_slen = 0;
static struct interface *
if_findsdl(struct dhcpcd_ctx *ctx, const struct sockaddr_dl *sdl)
{
-
if (sdl->sdl_index)
return if_findindex(ctx->ifaces, sdl->sdl_index);
TAILQ_FOREACH(ifp, ctx->ifaces, next) {
if (ifp->hwlen == sdl->sdl_alen &&
- memcmp(ifp->hwaddr,
- sdl->sdl_data, sdl->sdl_alen) == 0)
+ memcmp(ifp->hwaddr, sdl->sdl_data, sdl->sdl_alen) ==
+ 0)
return ifp;
}
}
}
switch (sa->sa_family) {
- case AF_LINK:
- {
+ case AF_LINK: {
const struct sockaddr_dl *sdl;
sdl = (const void *)sa;
return if_findsdl(ctx, sdl);
}
#ifdef INET
- case AF_INET:
- {
+ case AF_INET: {
const struct sockaddr_in *sin;
struct ipv4_addr *ia;
}
#endif
#ifdef INET6
- case AF_INET6:
- {
+ case AF_INET6: {
const struct sockaddr_in6 *sin;
struct ipv6_addr *ia;
}
static void
-if_route0(struct dhcpcd_ctx *ctx, struct rtm *rtmsg,
- unsigned char cmd, const struct rt *rt)
+if_route0(struct dhcpcd_ctx *ctx, struct rtm *rtmsg, unsigned char cmd,
+ const struct rt *rt)
{
struct rt_msghdr *rtm;
char *bp = rtmsg->buffer;
/* WARNING: Solaris will not allow you to delete RTF_KERNEL routes.
* This includes subnet/prefix routes. */
-#define ADDSA(sa) do { \
- sl = sa_len((sa)); \
- memcpy(bp, (sa), sl); \
- bp += RT_ROUNDUP(sl); \
+#define ADDSA(sa) \
+ do { \
+ sl = sa_len((sa)); \
+ memcpy(bp, (sa), sl); \
+ bp += RT_ROUNDUP(sl); \
} while (/* CONSTCOND */ 0)
memset(rtmsg, 0, sizeof(*rtmsg));
rtm->rtm_flags |= RTF_UP;
if (!(rtm->rtm_flags & RTF_REJECT) &&
- !sa_is_loopback(&rt->rt_gateway))
- {
+ !sa_is_loopback(&rt->rt_gateway)) {
rtm->rtm_addrs |= RTA_IFP;
/* RTA_IFA is currently ignored by the kernel.
* RTA_SRC and RTF_SETSRC look like what we want,
}
if (get_addrs(rtm->rtm_addrs, (const char *)rtm + sizeof(*rtm),
- rtm->rtm_msglen - sizeof(*rtm), rti_info) == -1)
+ rtm->rtm_msglen - sizeof(*rtm), rti_info) == -1)
return -1;
memset(rt, 0, sizeof(*rt));
if (rti_info[RTAX_GATEWAY]->sa_family == AF_LINK) {
const struct sockaddr_dl *sdl;
- sdl = (const struct sockaddr_dl*)
- (const void *)rti_info[RTAX_GATEWAY];
+ sdl = (const struct sockaddr_dl *)(const void *)
+ rti_info[RTAX_GATEWAY];
if (sdl->sdl_alen != 0)
rt->rt_dflags |= RTDF_GATELINK;
} else if (rtm->rtm_flags & RTF_GATEWAY)
* dhcpcd has a blank gateway here to indicate a
* subnet route. */
if (!sa_is_unspecified(&rt->rt_dest) &&
- !sa_is_unspecified(&rt->rt_gateway))
- {
- switch(rt->rt_gateway.sa_family) {
+ !sa_is_unspecified(&rt->rt_gateway)) {
+ switch (rt->rt_gateway.sa_family) {
#ifdef INET
- case AF_INET:
- {
+ case AF_INET: {
struct in_addr *in;
in = &satosin(&rt->rt_gateway)->sin_addr;
}
#endif
#ifdef INET6
- case AF_INET6:
- {
+ case AF_INET6: {
struct in6_addr *in6;
in6 = &satosin6(&rt->rt_gateway)->sin6_addr;
if (if_route_get(ctx, rt) == NULL) {
rt->rt_ifp = if_loopback(ctx);
if (rt->rt_ifp == NULL)
- return - 1;
+ return -1;
}
}
static int
if_addrflags0(int fd, int af, const char *ifname)
{
- struct lifreq lifr;
+ struct lifreq lifr;
int flags;
memset(&lifr, 0, sizeof(lifr));
flags = 0;
if (lifr.lifr_flags & IFF_DUPLICATE)
- flags |= af == AF_INET6 ? IN6_IFF_DUPLICATED:IN_IFF_DUPLICATED;
+ flags |= af == AF_INET6 ? IN6_IFF_DUPLICATED :
+ IN_IFF_DUPLICATED;
else if (!(lifr.lifr_flags & IFF_UP))
- flags |= af == AF_INET6 ? IN6_IFF_TENTATIVE:IN_IFF_TENTATIVE;
+ flags |= af == AF_INET6 ? IN6_IFF_TENTATIVE : IN_IFF_TENTATIVE;
return flags;
}
*/
if (rt.rt_dest.sa_family == AF_INET6 &&
(rt.rt_flags & RTF_HOST || rtm->rtm_type == RTM_MISS) &&
- !(rtm->rtm_type == RTM_ADD && !(rt.rt_dflags & RTDF_GATELINK)))
- {
+ !(rtm->rtm_type == RTM_ADD && !(rt.rt_dflags & RTDF_GATELINK))) {
bool reachable;
reachable = (rtm->rtm_type == RTM_ADD ||
- rtm->rtm_type == RTM_CHANGE) &&
+ rtm->rtm_type == RTM_CHANGE) &&
rt.rt_dflags & RTDF_GATELINK;
ipv6nd_neighbour(ctx, &rt.rt_ss_dest.sin6.sin6_addr, reachable);
}
static bool
if_getalias(struct interface *ifp, const struct sockaddr *sa, char *alias)
{
- struct ifaddrs *ifaddrs, *ifa;
- struct interface *ifpx;
- bool found;
+ struct ifaddrs *ifaddrs, *ifa;
+ struct interface *ifpx;
+ bool found;
ifaddrs = NULL;
if (getallifaddrs(sa->sa_family, &ifaddrs, 0) == -1)
static int
if_ifa(struct dhcpcd_ctx *ctx, const struct ifa_msghdr *ifam)
{
- struct interface *ifp;
- const struct sockaddr *sa, *rti_info[RTAX_MAX];
- int flags;
- char ifalias[IF_NAMESIZE];
+ struct interface *ifp;
+ const struct sockaddr *sa, *rti_info[RTAX_MAX];
+ int flags;
+ char ifalias[IF_NAMESIZE];
if (ifam->ifam_msglen < sizeof(*ifam)) {
errno = EINVAL;
return 0;
if (get_addrs(ifam->ifam_addrs, (const char *)ifam + sizeof(*ifam),
- ifam->ifam_msglen - sizeof(*ifam), rti_info) == -1)
+ ifam->ifam_msglen - sizeof(*ifam), rti_info) == -1)
return -1;
sa = rti_info[RTAX_IFA];
return 0;
switch (sa->sa_family) {
- case AF_LINK:
- {
+ case AF_LINK: {
struct sockaddr_dl sdl;
if (ifam->ifam_type != RTM_CHGADDR &&
ifam->ifam_type != RTM_NEWADDR)
break;
memcpy(&sdl, rti_info[RTAX_IFA], sizeof(sdl));
- dhcpcd_handlehwaddr(ifp, ifp->hwtype,
- CLLADDR(&sdl), sdl.sdl_alen);
+ dhcpcd_handlehwaddr(ifp, ifp->hwtype, CLLADDR(&sdl),
+ sdl.sdl_alen);
break;
}
#ifdef INET
- case AF_INET:
- {
+ case AF_INET: {
struct in_addr addr, mask, bcast;
COPYOUT(addr, rti_info[RTAX_IFA]);
return 0;
ipv4_handleifa(ctx,
- ifam->ifam_type == RTM_CHGADDR ?
- RTM_NEWADDR : ifam->ifam_type,
+ ifam->ifam_type == RTM_CHGADDR ? RTM_NEWADDR :
+ ifam->ifam_type,
NULL, ifalias, &addr, &mask, &bcast, flags, 0);
break;
}
#endif
#ifdef INET6
- case AF_INET6:
- {
- struct in6_addr addr6, mask6;
- const struct in6_addr *dstaddr6;
- const struct sockaddr_in6 *sin6;
+ case AF_INET6: {
+ struct in6_addr addr6, mask6;
+ const struct in6_addr *dstaddr6;
+ const struct sockaddr_in6 *sin6;
sin6 = (const void *)rti_info[RTAX_IFA];
addr6 = sin6->sin6_addr;
dstaddr6 = sin6 ? &sin6->sin6_addr : NULL;
if (ifam->ifam_type == RTM_DELADDR) {
- struct ipv6_addr *ia;
+ struct ipv6_addr *ia;
ia = ipv6_iffindaddr(ifp, &addr6, 0);
if (ia == NULL)
return 0;
ipv6_handleifa(ctx,
- ifam->ifam_type == RTM_CHGADDR ?
- RTM_NEWADDR : ifam->ifam_type,
- NULL, ifalias, &addr6, ipv6_prefixlen(&mask6),
- dstaddr6, flags, 0);
+ ifam->ifam_type == RTM_CHGADDR ? RTM_NEWADDR :
+ ifam->ifam_type,
+ NULL, ifalias, &addr6, ipv6_prefixlen(&mask6), dstaddr6,
+ flags, 0);
break;
}
#endif
static int
if_dispatch(struct dhcpcd_ctx *ctx, const struct rt_msghdr *rtm)
{
-
if (rtm->rtm_version != RTM_VERSION)
return 0;
- switch(rtm->rtm_type) {
+ switch (rtm->rtm_type) {
case RTM_IFINFO:
return if_ifinfo(ctx, (const void *)rtm);
- case RTM_ADD: /* FALLTHROUGH */
- case RTM_CHANGE: /* FALLTHROUGH */
- case RTM_DELETE: /* FALLTHROUGH */
+ case RTM_ADD: /* FALLTHROUGH */
+ case RTM_CHANGE: /* FALLTHROUGH */
+ case RTM_DELETE: /* FALLTHROUGH */
case RTM_MISS:
return if_rtm(ctx, (const void *)rtm);
- case RTM_CHGADDR: /* FALLTHROUGH */
- case RTM_DELADDR: /* FALLTHROUGH */
+ case RTM_CHGADDR: /* FALLTHROUGH */
+ case RTM_DELADDR: /* FALLTHROUGH */
case RTM_NEWADDR:
return if_ifa(ctx, (const void *)rtm);
}
if (len == 0)
return 0;
if ((size_t)len < sizeof(rtm.hdr.rtm_msglen) ||
- len != rtm.hdr.rtm_msglen)
- {
+ len != rtm.hdr.rtm_msglen) {
errno = EINVAL;
return -1;
}
static void
if_octetstr(char *buf, const Octet_t *o, ssize_t len)
{
- int i;
- char *p;
+ int i;
+ char *p;
p = buf;
for (i = 0; i < o->o_length; i++) {
static int
if_setflags(int fd, const char *ifname, uint64_t flags)
{
- struct lifreq lifr = { .lifr_addrlen = 0 };
+ struct lifreq lifr = { .lifr_addrlen = 0 };
strlcpy(lifr.lifr_name, ifname, sizeof(lifr.lifr_name));
if (ioctl(fd, SIOCGLIFFLAGS, &lifr) == -1)
}
static int
-if_addaddr(int fd, const char *ifname,
- struct sockaddr_storage *addr, struct sockaddr_storage *mask,
- struct sockaddr_storage *brd, uint8_t plen)
+if_addaddr(int fd, const char *ifname, struct sockaddr_storage *addr,
+ struct sockaddr_storage *mask, struct sockaddr_storage *brd, uint8_t plen)
{
- struct lifreq lifr = { .lifr_addrlen = plen };
+ struct lifreq lifr = { .lifr_addrlen = plen };
strlcpy(lifr.lifr_name, ifname, sizeof(lifr.lifr_name));
static int
if_getaf_fd(const struct dhcpcd_ctx *ctx, int af)
{
-
if (af == AF_INET)
return ctx->pf_inet_fd;
if (af == AF_INET6) {
- struct priv *priv;
+ struct priv *priv;
priv = (struct priv *)ctx->priv;
return priv->pf_inet6_fd;
}
int
-if_getsubnet(struct dhcpcd_ctx *ctx, const char *ifname, int af,
- void *subnet, size_t subnet_len)
+if_getsubnet(struct dhcpcd_ctx *ctx, const char *ifname, int af, void *subnet,
+ size_t subnet_len)
{
- struct lifreq lifr = { .lifr_addrlen = 0 };
+ struct lifreq lifr = { .lifr_addrlen = 0 };
int fd;
fd = if_getaf_fd(ctx, af);
strlcpy(lifr.lifr_name, ifname, sizeof(lifr.lifr_name));
if (ioctl(fd, SIOCGLIFSUBNET, &lifr) == -1)
return -1;
- memcpy(subnet, &lifr.lifr_addr, MIN(subnet_len,sizeof(lifr.lifr_addr)));
+ memcpy(subnet, &lifr.lifr_addr,
+ MIN(subnet_len, sizeof(lifr.lifr_addr)));
return 0;
}
static int
if_plumblif(int cmd, const struct dhcpcd_ctx *ctx, int af, const char *ifname)
{
- struct lifreq lifr;
- int s;
+ struct lifreq lifr;
+ int s;
memset(&lifr, 0, sizeof(lifr));
strlcpy(lifr.lifr_name, ifname, sizeof(lifr.lifr_name));
lifr.lifr_addr.ss_family = af;
s = if_getaf_fd(ctx, af);
- return ioctl(s,
- cmd == RTM_NEWADDR ? SIOCLIFADDIF : SIOCLIFREMOVEIF,
- &lifr) == -1 && errno != EEXIST ? -1 : 0;
+ return ioctl(s, cmd == RTM_NEWADDR ? SIOCLIFADDIF : SIOCLIFREMOVEIF,
+ &lifr) == -1 &&
+ errno != EEXIST ?
+ -1 :
+ 0;
}
static int
if_plumbif(const struct dhcpcd_ctx *ctx, int af, const char *ifname)
{
- dlpi_handle_t dh, dh_arp = NULL;
- int fd, af_fd, mux_fd, arp_fd = -1, mux_id, retval;
- uint64_t flags;
- struct lifreq lifr;
- const char *udp_dev;
- struct strioctl ioc;
- struct if_spec spec;
+ dlpi_handle_t dh, dh_arp = NULL;
+ int fd, af_fd, mux_fd, arp_fd = -1, mux_id, retval;
+ uint64_t flags;
+ struct lifreq lifr;
+ const char *udp_dev;
+ struct strioctl ioc;
+ struct if_spec spec;
if (if_nametospec(ifname, &spec) == -1)
return -1;
;
if (errno != EINVAL)
goto out;
- if(ioctl(mux_fd, I_PUSH, ARP_MOD_NAME) == -1)
+ if (ioctl(mux_fd, I_PUSH, ARP_MOD_NAME) == -1)
goto out;
if (flags & (IFF_NOARP | IFF_IPV6)) {
static int
if_unplumbif(const struct dhcpcd_ctx *ctx, int af, const char *ifname)
{
- struct sockaddr_storage addr = { .ss_family = af };
- int fd;
+ struct sockaddr_storage addr = { .ss_family = af };
+ int fd;
/* For the time being, don't unplumb the interface, just
* set the address to zero. */
static int
if_plumb(int cmd, const struct dhcpcd_ctx *ctx, int af, const char *ifname)
{
- struct if_spec spec;
+ struct if_spec spec;
if (if_nametospec(ifname, &spec) == -1)
return -1;
#endif
static int
-if_parsert(struct dhcpcd_ctx *ctx, rb_tree_t *routes,
- unsigned int level, unsigned int name,
+if_parsert(struct dhcpcd_ctx *ctx, rb_tree_t *routes, unsigned int level,
+ unsigned int name,
int (*walkrt)(struct dhcpcd_ctx *, rb_tree_t *, char *, size_t))
{
- int s, retval, code, flags;
- uintptr_t buf[512 / sizeof(uintptr_t)];
- struct strbuf ctlbuf, databuf;
- struct T_optmgmt_req *tor = (struct T_optmgmt_req *)buf;
- struct T_optmgmt_ack *toa = (struct T_optmgmt_ack *)buf;
- struct T_error_ack *tea = (struct T_error_ack *)buf;
- struct opthdr *req;
+ int s, retval, code, flags;
+ uintptr_t buf[512 / sizeof(uintptr_t)];
+ struct strbuf ctlbuf, databuf;
+ struct T_optmgmt_req *tor = (struct T_optmgmt_req *)buf;
+ struct T_optmgmt_ack *toa = (struct T_optmgmt_ack *)buf;
+ struct T_error_ack *tea = (struct T_error_ack *)buf;
+ struct opthdr *req;
if ((s = open("/dev/arp", O_RDWR)) == -1)
return -1;
retval = -1;
tor->PRIM_type = T_SVR4_OPTMGMT_REQ;
- tor->OPT_offset = sizeof (struct T_optmgmt_req);
- tor->OPT_length = sizeof (struct opthdr);
+ tor->OPT_offset = sizeof(struct T_optmgmt_req);
+ tor->OPT_length = sizeof(struct opthdr);
tor->MGMT_flags = T_CURRENT;
req = (struct opthdr *)&tor[1];
flags = 0;
if ((code = getmsg(s, &ctlbuf, 0, &flags)) == -1)
break;
- if (code == 0 &&
- toa->PRIM_type == T_OPTMGMT_ACK &&
+ if (code == 0 && toa->PRIM_type == T_OPTMGMT_ACK &&
toa->MGMT_flags == T_SUCCESS &&
- (size_t)ctlbuf.len >= sizeof(struct T_optmgmt_ack))
- {
+ (size_t)ctlbuf.len >= sizeof(struct T_optmgmt_ack)) {
/* End of messages, so return success! */
retval = 0;
break;
}
if (tea->PRIM_type == T_ERROR_ACK) {
- errno = tea->TLI_error == TSYSERR ?
- tea->UNIX_error : EPROTO;
+ errno = tea->TLI_error == TSYSERR ? tea->UNIX_error :
+ EPROTO;
break;
}
- if (code != MOREDATA ||
- toa->PRIM_type != T_OPTMGMT_ACK ||
- toa->MGMT_flags != T_SUCCESS)
- {
+ if (code != MOREDATA || toa->PRIM_type != T_OPTMGMT_ACK ||
+ toa->MGMT_flags != T_SUCCESS) {
errno = ENOMSG;
break;
}
return retval;
}
-
int
if_initrt(struct dhcpcd_ctx *ctx, rb_tree_t *routes, int af)
{
-
#ifdef INET
if ((af == AF_UNSPEC || af == AF_INET) &&
- if_parsert(ctx, routes, MIB2_IP,MIB2_IP_ROUTE, if_walkrt) == -1)
+ if_parsert(ctx, routes, MIB2_IP, MIB2_IP_ROUTE, if_walkrt) == -1)
return -1;
#endif
#ifdef INET6
return 0;
}
-
#ifdef INET
/* XXX We should fix this to write via the BPF interface. */
ssize_t
bpf_send(const struct bpf *bpf, uint16_t protocol, const void *data, size_t len)
{
const struct interface *ifp = bpf->bpf_ifp;
- dlpi_handle_t dh;
- dlpi_info_t di;
- int r;
+ dlpi_handle_t dh;
+ dlpi_info_t di;
+ int r;
if (dlpi_open(ifp->name, &dh, 0) != DLPI_SUCCESS)
return -1;
if_address(unsigned char cmd, const struct ipv4_addr *ia)
{
union {
- struct sockaddr sa;
+ struct sockaddr sa;
struct sockaddr_storage ss;
} addr, mask, brd;
int fd = ia->iface->ctx->pf_inet_fd;
}
int
-if_addrflags(const struct interface *ifp, __unused const struct in_addr * ia,
+if_addrflags(const struct interface *ifp, __unused const struct in_addr *ia,
const char *alias)
{
-
return if_addrflags0(ifp->ctx->pf_inet_fd, AF_INET, alias);
}
if_address6(unsigned char cmd, const struct ipv6_addr *ia)
{
union {
- struct sockaddr sa;
- struct sockaddr_in6 sin6;
+ struct sockaddr sa;
+ struct sockaddr_in6 sin6;
struct sockaddr_storage ss;
} addr, mask;
- int fd, r;
+ int fd, r;
/* Either remove the alias or ensure it exists. */
if (if_plumb(cmd, ia->iface->ctx, AF_INET6, ia->alias) == -1 &&
fd = if_getaf_fd(ia->iface->ctx, AF_INET6);
if (!(ia->flags & IPV6_AF_AUTOCONF) && ia->flags & IPV6_AF_RAPFX) {
- if (if_setflags(fd, ia->alias, IFF_NOLOCAL) ==-1)
+ if (if_setflags(fd, ia->alias, IFF_NOLOCAL) == -1)
return -1;
sa_in6_init(&mask.sa, &ia->prefix);
- r = if_addaddr(fd, ia->alias,
- NULL, &mask.ss, NULL, ia->prefix_len);
+ r = if_addaddr(fd, ia->alias, NULL, &mask.ss, NULL,
+ ia->prefix_len);
} else {
sa_in6_init(&addr.sa, &ia->addr);
mask.sin6.sin6_family = AF_INET6;
ipv6_mask(&mask.sin6.sin6_addr, ia->prefix_len);
- r = if_addaddr(fd, ia->alias,
- &addr.ss, &mask.ss, NULL, ia->prefix_len);
+ r = if_addaddr(fd, ia->alias, &addr.ss, &mask.ss, NULL,
+ ia->prefix_len);
}
if (r == -1 && errno == EEXIST)
return 0;
if_addrflags6(const struct interface *ifp, __unused const struct in6_addr *ia,
const char *alias)
{
- int fd;
+ int fd;
fd = if_getaf_fd(ifp->ctx, AF_INET6);
return if_addrflags0(fd, AF_INET6, alias);
int
if_getlifetime6(struct ipv6_addr *addr)
{
-
UNUSED(addr);
errno = ENOTSUP;
return -1;
int
if_applyra(const struct ra *rap)
{
- struct lifreq lifr = {
+ struct lifreq lifr = {
.lifr_ifinfo.lir_maxhops = rap->hoplimit,
.lifr_ifinfo.lir_reachtime = rap->reachable,
.lifr_ifinfo.lir_reachretrans = rap->retrans,
void
if_setup_inet6(__unused const struct interface *ifp)
{
-
}
#endif
* SUCH DAMAGE.
*/
-#include <sys/param.h>
#include <sys/types.h>
+#include <sys/param.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
-#include <fcntl.h> /* Needs to be here for old Linux */
-
-#include "config.h"
-
#include <net/if.h>
#include <net/if_arp.h>
#include <netinet/in.h>
+
+#include <fcntl.h> /* Needs to be here for old Linux */
+
+#include "config.h"
#ifdef AF_LINK
-# include <net/if_dl.h>
-# include <net/if_types.h>
-# include <netinet/in_var.h>
-# undef AF_PACKET /* Newer Illumos defines this */
+#include <net/if_dl.h>
+#include <net/if_types.h>
+#include <netinet/in_var.h>
+#undef AF_PACKET /* Newer Illumos defines this */
#endif
#ifdef AF_PACKET
-# include <netpacket/packet.h>
+#include <netpacket/packet.h>
#endif
#ifdef SIOCGIFMEDIA
-# include <net/if_media.h>
+#include <net/if_media.h>
#endif
#include <net/route.h>
#include <ctype.h>
#include <errno.h>
+#include <fnmatch.h>
#include <ifaddrs.h>
#include <inttypes.h>
-#include <fnmatch.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <syslog.h>
#include <unistd.h>
-#define ELOOP_QUEUE ELOOP_IF
+#define ELOOP_QUEUE ELOOP_IF
#include "common.h"
-#include "eloop.h"
#include "dev.h"
#include "dhcp.h"
#include "dhcp6.h"
-#include "if.h"
+#include "eloop.h"
#include "if-options.h"
+#include "if.h"
#include "ipv4.h"
#include "ipv4ll.h"
#include "ipv6nd.h"
void
if_free(struct interface *ifp)
{
-
if (ifp == NULL)
return;
#ifdef IPV4LL
int
if_opensockets(struct dhcpcd_ctx *ctx)
{
-
if (if_opensockets_os(ctx) == -1)
return -1;
void
if_closesockets(struct dhcpcd_ctx *ctx)
{
-
if (ctx->link_fd != -1) {
eloop_event_delete(ctx->eloop, ctx->link_fd);
close(ctx->link_fd);
int
if_ioctl(struct dhcpcd_ctx *ctx, ioctl_request_t req, void *data, size_t len)
{
-
#ifdef PRIVSEP
if (ctx->options & DHCPCD_PRIVSEP)
return (int)ps_root_ioctl(ctx, req, data, len);
bool
if_is_link_up(const struct interface *ifp)
{
-
return ifp->flags & IFF_UP &&
(ifp->carrier != LINK_DOWN ||
- (ifp->options != NULL && !(ifp->options->options & DHCPCD_LINK)));
+ (ifp->options != NULL &&
+ !(ifp->options->options & DHCPCD_LINK)));
}
int
buf[0] &= 0xFC;
buf[0] |= 0x02;
- logdebugx("%s: hardware address randomised to %s",
- ifp->name,
+ logdebugx("%s: hardware address randomised to %s", ifp->name,
hwaddr_ntoa(buf, ifp->hwlen, sbuf, sizeof(sbuf)));
retval = if_setmac(ifp, buf, ifp->hwlen);
if (retval == 0)
#ifdef HAVE_IFADDRS_ADDRFLAGS
addrflags = (int)ifa->ifa_addrflags;
#endif
- switch(ifa->ifa_addr->sa_family) {
+ switch (ifa->ifa_addr->sa_family) {
#ifdef INET
case AF_INET:
addr = (void *)ifa->ifa_addr;
char dbuf[INET_ADDRSTRLEN];
const char *dbp;
- dbp = inet_ntop(AF_INET, &addr->sin_addr,
- dbuf, sizeof(dbuf));
+ dbp = inet_ntop(AF_INET,
+ &addr->sin_addr, dbuf,
+ sizeof(dbuf));
logerr("%s: if_addrflags: %s%%%s",
__func__, dbp, ifp->name);
}
}
#endif
ipv4_handleifa(ctx, RTM_NEWADDR, ifs, ifa->ifa_name,
- &addr->sin_addr, &net->sin_addr,
- brd ? &brd->sin_addr : NULL, addrflags, 0);
+ &addr->sin_addr, &net->sin_addr,
+ brd ? &brd->sin_addr : NULL, addrflags, 0);
break;
#endif
#ifdef INET6
char dbuf[INET6_ADDRSTRLEN];
const char *dbp;
- dbp = inet_ntop(AF_INET6, &addr6->sin6_addr,
- dbuf, sizeof(dbuf));
+ dbp = inet_ntop(AF_INET6,
+ &addr6->sin6_addr, dbuf,
+ sizeof(dbuf));
logerr("%s: if_addrflags6: %s%%%s",
__func__, dbp, ifp->name);
}
continue;
}
#endif
- ipv6_handleifa(ctx, RTM_NEWADDR, ifs,
- ifa->ifa_name, &addr6->sin6_addr,
- ipv6_prefixlen(&net6->sin6_addr),
- dstaddr6 ? &dstaddr6->sin6_addr : NULL,
- addrflags, 0);
+ ipv6_handleifa(ctx, RTM_NEWADDR, ifs, ifa->ifa_name,
+ &addr6->sin6_addr, ipv6_prefixlen(&net6->sin6_addr),
+ dstaddr6 ? &dstaddr6->sin6_addr : NULL, addrflags,
+ 0);
break;
#endif
}
}
}
-void if_freeifaddrs(struct dhcpcd_ctx *ctx, struct ifaddrs **ifaddrs)
+void
+if_freeifaddrs(struct dhcpcd_ctx *ctx, struct ifaddrs **ifaddrs)
{
#ifndef PRIVSEP_GETIFADDRS
UNUSED(ctx);
static unsigned int
if_check_arphrd(struct interface *ifp, unsigned int active, bool if_noconf)
{
-
- switch(ifp->hwtype) {
+ switch (ifp->hwtype) {
case ARPHRD_ETHER: /* FALLTHROUGH */
case ARPHRD_IEEE1394: /* FALLTHROUGH */
- case ARPHRD_INFINIBAND: /* FALLTHROUGH */
+ case ARPHRD_INFINIBAND: /* FALLTHROUGH */
case ARPHRD_NONE: /* FALLTHROUGH */
break;
case ARPHRD_LOOPBACK:
case ARPHRD_PPP:
if (if_noconf && active) {
logdebugx("%s: ignoring due to interface type and"
- " no config",
+ " no config",
ifp->name);
active = IF_INACTIVE;
}
if (if_noconf)
active = IF_INACTIVE;
i = active ? LOG_WARNING : LOG_DEBUG;
- logmessage(i, "%s: unsupported"
+ logmessage(i,
+ "%s: unsupported"
" interface type 0x%.2x",
ifp->name, ifp->hwtype);
}
#endif
struct if_head *
-if_discover(struct dhcpcd_ctx *ctx, struct ifaddrs **ifaddrs,
- int argc, char * const *argv)
+if_discover(struct dhcpcd_ctx *ctx, struct ifaddrs **ifaddrs, int argc,
+ char *const *argv)
{
struct ifaddrs *ifa;
int i;
}
} else
#endif
- if (getifaddrs(ifaddrs) == -1) {
+ if (getifaddrs(ifaddrs) == -1) {
logerr("getifaddrs");
free(ifs);
return NULL;
if (argc == -1 && strcmp(argv[0], spec.devname) != 0)
continue;
active = ctx->options & DHCPCD_INACTIVE ?
- IF_INACTIVE: IF_ACTIVE_USER;
+ IF_INACTIVE :
+ IF_ACTIVE_USER;
}
for (i = 0; i < ctx->ifdc; i++)
/* Don't allow some reserved interface names unless explicit. */
if (if_noconf && if_ignore(ctx, spec.devname)) {
logdebugx("%s: ignoring due to interface type and"
- " no config", spec.devname);
+ " no config",
+ spec.devname);
active = IF_INACTIVE;
}
iflr.flags = IFLR_PREFIX;
iflr.prefixlen = (unsigned int)sdl->sdl_alen * NBBY;
if (ioctl(ctx->pf_link_fd, SIOCGLIFADDR, &iflr) == -1 ||
- !(iflr.flags & IFLR_ACTIVE))
- {
+ !(iflr.flags & IFLR_ACTIVE)) {
if_free(ifp);
continue;
}
#endif
ifp->index = sdl->sdl_index;
- switch(sdl->sdl_type) {
+ switch (sdl->sdl_type) {
#ifdef IFT_BRIDGE
case IFT_BRIDGE: /* FALLTHROUGH */
#endif
/* Don't allow unless explicit */
if (if_noconf && active) {
logdebugx("%s: ignoring due to"
- " interface type and"
- " no config",
+ " interface type and"
+ " no config",
ifp->name);
active = IF_INACTIVE;
}
__fallthrough; /* appease gcc */
- /* FALLTHROUGH */
+ /* FALLTHROUGH */
#ifdef IFT_L2VLAN
case IFT_L2VLAN: /* FALLTHROUGH */
#endif
if (if_noconf)
active = IF_INACTIVE;
i = active ? LOG_WARNING : LOG_DEBUG;
- logmessage(i, "%s: unsupported"
+ logmessage(i,
+ "%s: unsupported"
" interface type 0x%.2x",
ifp->name, sdl->sdl_type);
}
if (ifname == NULL || *ifname == '\0' ||
strlcpy(spec->ifname, ifname, sizeof(spec->ifname)) >=
- sizeof(spec->ifname) ||
+ sizeof(spec->ifname) ||
strlcpy(spec->drvname, ifname, sizeof(spec->drvname)) >=
- sizeof(spec->drvname))
- {
+ sizeof(spec->drvname)) {
errno = EINVAL;
return -1;
}
static struct interface *
if_findindexname(struct if_head *ifaces, unsigned int idx, const char *name)
{
-
if (ifaces != NULL) {
struct if_spec spec;
struct interface *ifp;
struct interface *
if_find(struct if_head *ifaces, const char *name)
{
-
return if_findindexname(ifaces, 0, name);
}
struct interface *
if_findindex(struct if_head *ifaces, unsigned int idx)
{
-
return if_findindexname(ifaces, idx, NULL);
}
int
if_makealias(char *alias, size_t alias_len, const char *ifname, int lun)
{
-
if (lun == 0)
return strlcpy(alias, ifname, alias_len);
return snprintf(alias, alias_len, "%s:%u", ifname, lun);
UNUSED(hoplimit);
#endif
- for (cm = (struct cmsghdr *)CMSG_FIRSTHDR(msg);
- cm;
- cm = (struct cmsghdr *)CMSG_NXTHDR(msg, cm))
- {
+ for (cm = (struct cmsghdr *)CMSG_FIRSTHDR(msg); cm;
+ cm = (struct cmsghdr *)CMSG_NXTHDR(msg, cm)) {
#ifdef INET
if (cm->cmsg_level == IPPROTO_IP) {
- switch(cm->cmsg_type) {
+ switch (cm->cmsg_type) {
#ifdef IP_RECVIF
case IP_RECVIF:
if (cm->cmsg_len <
offsetof(struct sockaddr_dl, sdl_index) +
- sizeof(sdl.sdl_index))
+ sizeof(sdl.sdl_index))
continue;
memcpy(&sdl, CMSG_DATA(cm),
MIN(sizeof(sdl), cm->cmsg_len));
#endif
#ifdef INET6
if (cm->cmsg_level == IPPROTO_IPV6) {
- switch(cm->cmsg_type) {
+ switch (cm->cmsg_type) {
case IPV6_PKTINFO:
if (cm->cmsg_len != CMSG_LEN(sizeof(ipi6)))
continue;
if ((s = socket(domain, type, protocol)) == -1)
return -1;
#ifdef DEBUG_FD
- logerrx("pid %d fd=%d domain=%d type=%d protocol=%d",
- getpid(), s, domain, type, protocol);
+ logerrx("pid %d fd=%d domain=%d type=%d protocol=%d", getpid(), s,
+ domain, type, protocol);
#endif
#ifndef HAVE_SOCK_CLOEXEC
- if ((xtype & SOCK_CLOEXEC) && ((xflags = fcntl(s, F_GETFD)) == -1 ||
- fcntl(s, F_SETFD, xflags | FD_CLOEXEC) == -1))
+ if ((xtype & SOCK_CLOEXEC) &&
+ ((xflags = fcntl(s, F_GETFD)) == -1 ||
+ fcntl(s, F_SETFD, xflags | FD_CLOEXEC) == -1))
goto out;
#endif
#ifndef HAVE_SOCK_NONBLOCK
- if ((xtype & SOCK_NONBLOCK) && ((xflags = fcntl(s, F_GETFL)) == -1 ||
- fcntl(s, F_SETFL, xflags | O_NONBLOCK) == -1))
+ if ((xtype & SOCK_NONBLOCK) &&
+ ((xflags = fcntl(s, F_GETFL)) == -1 ||
+ fcntl(s, F_SETFL, xflags | O_NONBLOCK) == -1))
goto out;
#endif
#endif
#ifndef HAVE_SOCK_CLOEXEC
- if ((xtype & SOCK_CLOEXEC) && ((xflags = fcntl(fd[0], F_GETFD)) == -1 ||
- fcntl(fd[0], F_SETFD, xflags | FD_CLOEXEC) == -1))
+ if ((xtype & SOCK_CLOEXEC) &&
+ ((xflags = fcntl(fd[0], F_GETFD)) == -1 ||
+ fcntl(fd[0], F_SETFD, xflags | FD_CLOEXEC) == -1))
goto out;
- if ((xtype & SOCK_CLOEXEC) && ((xflags = fcntl(fd[1], F_GETFD)) == -1 ||
- fcntl(fd[1], F_SETFD, xflags | FD_CLOEXEC) == -1))
+ if ((xtype & SOCK_CLOEXEC) &&
+ ((xflags = fcntl(fd[1], F_GETFD)) == -1 ||
+ fcntl(fd[1], F_SETFD, xflags | FD_CLOEXEC) == -1))
goto out;
#endif
#ifndef HAVE_SOCK_NONBLOCK
- if ((xtype & SOCK_NONBLOCK) && ((xflags = fcntl(fd[0], F_GETFL)) == -1 ||
- fcntl(fd[0], F_SETFL, xflags | O_NONBLOCK) == -1))
+ if ((xtype & SOCK_NONBLOCK) &&
+ ((xflags = fcntl(fd[0], F_GETFL)) == -1 ||
+ fcntl(fd[0], F_SETFL, xflags | O_NONBLOCK) == -1))
goto out;
- if ((xtype & SOCK_NONBLOCK) && ((xflags = fcntl(fd[1], F_GETFL)) == -1 ||
- fcntl(fd[1], F_SETFL, xflags | O_NONBLOCK) == -1))
+ if ((xtype & SOCK_NONBLOCK) &&
+ ((xflags = fcntl(fd[1], F_GETFL)) == -1 ||
+ fcntl(fd[1], F_SETFL, xflags | O_NONBLOCK) == -1))
goto out;
#endif
#define INTERFACE_H
#include <net/if.h>
-#include <net/route.h> /* for RTM_ADD et all */
+#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 */
+#include <netinet/in_var.h> /* for IN_IFF_TENTATIVE et all */
#endif
#include <ifaddrs.h>
/* 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 */
+#define IF_POLL_UP 100 /* milliseconds */
/*
* Systems which handle 1 address per alias.
* restriction.
*/
#ifndef ALIAS_ADDR
-# ifdef __sun
-# define ALIAS_ADDR
-# endif
+#ifdef __sun
+#define ALIAS_ADDR
+#endif
#endif
#include "config.h"
* Everyone else use an unsigned long, which happens to be the bigger one
* so we use that in our on wire API. */
#ifdef IOCTL_REQUEST_TYPE
-typedef IOCTL_REQUEST_TYPE ioctl_request_t;
+typedef IOCTL_REQUEST_TYPE ioctl_request_t;
#else
-typedef unsigned long ioctl_request_t;
+typedef unsigned long ioctl_request_t;
#endif
#include "dhcpcd.h"
#include "ipv6.h"
#include "route.h"
-#define EUI64_ADDR_LEN 8
-#define INFINIBAND_ADDR_LEN 20
+#define EUI64_ADDR_LEN 8
+#define INFINIBAND_ADDR_LEN 20
/* Linux 2.4 doesn't define this */
#ifndef ARPHRD_IEEE1394
-# define ARPHRD_IEEE1394 24
+#define ARPHRD_IEEE1394 24
#endif
/* The BSD's don't define this yet */
#ifndef ARPHRD_INFINIBAND
-# define ARPHRD_INFINIBAND 32
+#define ARPHRD_INFINIBAND 32
#endif
/* Maximum frame length.
* Support jumbo frames and some extra. */
-#define FRAMEHDRLEN_MAX 14 /* only ethernet support */
-#define FRAMELEN_MAX (FRAMEHDRLEN_MAX + 9216)
+#define FRAMEHDRLEN_MAX 14 /* only ethernet support */
+#define FRAMELEN_MAX (FRAMEHDRLEN_MAX + 9216)
-#define UDPLEN_MAX 64 * 1024
+#define UDPLEN_MAX 64 * 1024
/* Work out if we have a private address or not
* 10/8
* 192.168/16
*/
#ifndef IN_PRIVATE
-# define IN_PRIVATE(addr) (((addr & IN_CLASSA_NET) == 0x0a000000) || \
- ((addr & 0xfff00000) == 0xac100000) || \
+#define IN_PRIVATE(addr) \
+ (((addr & IN_CLASSA_NET) == 0x0a000000) || \
+ ((addr & 0xfff00000) == 0xac100000) || \
((addr & IN_CLASSB_NET) == 0xc0a80000))
#endif
#ifndef CLLADDR
#ifdef AF_LINK
-# define CLLADDR(sdl) (const void *)((sdl)->sdl_data + (sdl)->sdl_nlen)
+#define CLLADDR(sdl) (const void *)((sdl)->sdl_data + (sdl)->sdl_nlen)
#endif
#endif
* See if-sun.c for details why. */
struct ifaddrs;
int if_getifaddrs(struct ifaddrs **);
-#define getifaddrs if_getifaddrs
+#define getifaddrs if_getifaddrs
int if_getsubnet(struct dhcpcd_ctx *, const char *, int, void *, size_t);
#endif
int if_ioctl(struct dhcpcd_ctx *, ioctl_request_t, void *, size_t);
#ifdef HAVE_PLEDGE
-#define pioctl(ctx, req, data, len) if_ioctl((ctx), (req), (data), (len))
+#define pioctl(ctx, req, data, len) if_ioctl((ctx), (req), (data), (len))
#else
-#define pioctl(ctx, req, data, len) ioctl((ctx)->pf_inet_fd, (req),(data),(len))
+#define pioctl(ctx, req, data, len) \
+ ioctl((ctx)->pf_inet_fd, (req), (data), (len))
#endif
int if_setflag(struct interface *, short, short);
int if_getmtu(const struct interface *);
-#define if_up(ifp) if_setflag((ifp), (IFF_UP | IFF_RUNNING), 0)
+#define if_up(ifp) if_setflag((ifp), (IFF_UP | IFF_RUNNING), 0)
#define if_down(ifp) if_setflag((ifp), 0, IFF_UP);
bool if_is_link_up(const struct interface *);
bool if_valid_hwaddr(const uint8_t *, size_t);
-struct if_head *if_discover(struct dhcpcd_ctx *, struct ifaddrs **,
- int, char * const *);
+struct if_head *if_discover(struct dhcpcd_ctx *, struct ifaddrs **, int,
+ char *const *);
void if_freeifaddrs(struct dhcpcd_ctx *ctx, struct ifaddrs **);
void if_markaddrsstale(struct if_head *);
void if_learnaddrs(struct dhcpcd_ctx *, struct if_head *, struct ifaddrs **);
bool if_ignore(struct dhcpcd_ctx *, const char *);
int if_vimaster(struct dhcpcd_ctx *ctx, const char *);
unsigned short if_vlanid(const struct interface *);
-char * if_getnetworknamespace(char *, size_t); /* used by udev */
+char *if_getnetworknamespace(char *, size_t); /* used by udev */
int if_opensockets(struct dhcpcd_ctx *);
int if_opensockets_os(struct dhcpcd_ctx *);
void if_closesockets(struct dhcpcd_ctx *);
* 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 */
+#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
+#define HAVE_SOCK_CLOEXEC
#else
-# define SOCK_CLOEXEC 0x10000000
+#define SOCK_CLOEXEC 0x10000000
#endif
#ifdef SOCK_NONBLOCK
-# define HAVE_SOCK_NONBLOCK
+#define HAVE_SOCK_NONBLOCK
#else
-# define SOCK_NONBLOCK 0x20000000
+#define SOCK_NONBLOCK 0x20000000
#endif
#ifndef SOCK_CXNB
-#define SOCK_CXNB SOCK_CLOEXEC | SOCK_NONBLOCK
+#define SOCK_CXNB SOCK_CLOEXEC | SOCK_NONBLOCK
#endif
int xsocket(int, int, int);
int xsocketpair(int, int, int, int[2]);
#endif
int if_machinearch(char *, size_t);
-struct interface *if_findifpfromcmsg(struct dhcpcd_ctx *,
- struct msghdr *, int *);
+struct interface *if_findifpfromcmsg(struct dhcpcd_ctx *, struct msghdr *,
+ int *);
#ifdef __linux__
int if_linksocket(struct sockaddr_nl *, int, int);
* SUCH DAMAGE.
*/
-#include <sys/socket.h>
#include <sys/types.h>
+#include <sys/socket.h>
-#include <arpa/inet.h>
#include <net/if.h>
#include <net/route.h>
-#include <netinet/if_ether.h>
#include <netinet/in.h>
+#include <netinet/if_ether.h>
+#include <arpa/inet.h>
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
-#include "config.h"
#include "arp.h"
#include "common.h"
-#include "dhcpcd.h"
+#include "config.h"
#include "dhcp.h"
+#include "dhcpcd.h"
#include "eloop.h"
-#include "if.h"
#include "if-options.h"
+#include "if.h"
#include "ipv4.h"
#include "ipv4ll.h"
#include "logerr.h"
#include "route.h"
-#include "script.h"
#include "sa.h"
+#include "script.h"
#define IPV4_LOOPBACK_ROUTE
#if defined(__linux__) || defined(__sun) || (defined(BSD) && defined(RTF_LOCAL))
}
struct ipv4_addr *
-ipv4_iffindaddr(struct interface *ifp,
- const struct in_addr *addr, const struct in_addr *mask)
+ipv4_iffindaddr(struct interface *ifp, const struct in_addr *addr,
+ const struct in_addr *mask)
{
struct ipv4_state *state;
struct ipv4_addr *ap;
state = IPV4_STATE(ifp);
if (state) {
- TAILQ_FOREACH (ap, &state->addrs, next) {
+ TAILQ_FOREACH(ap, &state->addrs, next) {
if ((ap->addr.s_addr & ap->mask.s_addr) ==
(addr->s_addr & ap->mask.s_addr))
return ap;
state = IPV4_STATE(ifp);
if (state) {
- TAILQ_FOREACH (ap, &state->addrs, next) {
+ TAILQ_FOREACH(ap, &state->addrs, next) {
if ((ap->brd.s_addr & ap->mask.s_addr) ==
(addr->s_addr & ap->mask.s_addr))
return ap;
#endif
dstate = D_CSTATE(ifp);
- return (dstate &&
- dstate->added == STATE_ADDED &&
- dstate->addr != NULL);
+ return (dstate && dstate->added == STATE_ADDED && dstate->addr != NULL);
}
/* Interface comparer for working out ordering. */
sa_in_init(&rt->rt_dest, &in);
in.s_addr = state->addr->mask.s_addr;
sa_in_init(&rt->rt_netmask, &in);
- //in.s_addr = INADDR_ANY;
- //sa_in_init(&rt->rt_gateway, &in);
+ // in.s_addr = INADDR_ANY;
+ // sa_in_init(&rt->rt_gateway, &in);
rt->rt_gateway.sa_family = AF_UNSPEC;
rt_proto_add(&nroutes, rt);
}
/* If any set routes, grab them, otherwise DHCP routes. */
if (RB_TREE_MIN(&ifp->options->routes)) {
- RB_TREE_FOREACH(r, &ifp->options->routes) {
+ RB_TREE_FOREACH(r, &ifp->options->routes)
+ {
if (sa_is_unspecified(&r->rt_gateway))
break;
if ((rt = rt_new0(ifp->ctx)) == NULL)
/* If configured, install a gateway to the desintion
* for P2P interfaces. */
if (ifp->flags & IFF_POINTOPOINT &&
- has_option_mask(ifp->options->dstmask, DHO_ROUTER))
- {
+ has_option_mask(ifp->options->dstmask, DHO_ROUTER)) {
if ((rt = rt_new(ifp)) == NULL)
return -1;
in.s_addr = INADDR_ANY;
rb_tree_init(&troutes, &rt_compare_proto_ops);
- RB_TREE_FOREACH(rt, routes) {
+ RB_TREE_FOREACH(rt, routes)
+ {
if (rt->rt_dest.sa_family != AF_INET)
continue;
if (!sa_is_unspecified(&rt->rt_dest) ||
continue;
gateway = satosin(&rt->rt_gateway);
/* Scan for a route to match */
- RB_TREE_FOREACH(rth, routes) {
+ RB_TREE_FOREACH(rth, routes)
+ {
if (rth == rt)
break;
/* match host */
ifo = ifp->options;
if (ifp->flags & IFF_NOARP) {
if (!(ifo->options & DHCPCD_ROUTER_HOST_ROUTE_WARNED) &&
- !(state->added & STATE_FAKE))
- {
+ !(state->added & STATE_FAKE)) {
char buf[INET_MAX_ADDRSTRLEN];
ifo->options |= DHCPCD_ROUTER_HOST_ROUTE_WARNED;
logwarnx("%s: forcing router %s through "
- "interface",
+ "interface",
ifp->name,
- sa_addrtop(&rt->rt_gateway,
- buf, sizeof(buf)));
+ sa_addrtop(&rt->rt_gateway, buf,
+ sizeof(buf)));
}
gateway->sin_addr.s_addr = INADDR_ANY;
continue;
}
if (!(ifo->options & DHCPCD_ROUTER_HOST_ROUTE_WARNED) &&
- !(state->added & STATE_FAKE))
- {
+ !(state->added & STATE_FAKE)) {
char buf[INET_MAX_ADDRSTRLEN];
ifo->options |= DHCPCD_ROUTER_HOST_ROUTE_WARNED;
return true;
TAILQ_FOREACH(ifp, ctx->ifaces, next) {
- if (ifp->active &&
- ipv4ll_defaultroute(routes, ifp) == 1)
+ if (ifp->active && ipv4ll_defaultroute(routes, ifp) == 1)
break;
}
#endif
struct ipv4_addr *ap;
assert(addr != NULL);
- logdebugx("%s: deleting IP address %s",
- addr->iface->name, addr->saddr);
+ logdebugx("%s: deleting IP address %s", addr->iface->name, addr->saddr);
r = if_address(RTM_DELADDR, addr);
- if (r == -1 &&
- errno != EADDRNOTAVAIL && errno != ESRCH &&
+ if (r == -1 && errno != EADDRNOTAVAIL && errno != ESRCH &&
errno != ENXIO && errno != ENODEV)
logerr("%s: %s", addr->iface->name, __func__);
state = IPV4_STATE(ifp);
if (state == NULL) {
- ifp->if_data[IF_DATA_IPV4] = malloc(sizeof(*state));
+ ifp->if_data[IF_DATA_IPV4] = malloc(sizeof(*state));
state = IPV4_STATE(ifp);
if (state == NULL) {
logerr(__func__);
state = IPV4_STATE(ia->iface);
find_lun:
if (if_makealias(alias, IF_NAMESIZE, ia->iface->name, lun) >=
- IF_NAMESIZE)
- {
+ IF_NAMESIZE) {
errno = ENOMEM;
return -1;
}
struct ipv4_addr *
ipv4_addaddr(struct interface *ifp, const struct in_addr *addr,
- const struct in_addr *mask, const struct in_addr *bcast,
- uint32_t vltime, uint32_t pltime)
+ const struct in_addr *mask, const struct in_addr *bcast, uint32_t vltime,
+ uint32_t pltime)
{
struct ipv4_state *state;
struct ipv4_addr *ia;
UNUSED(vltime);
UNUSED(pltime);
#endif
- snprintf(ia->saddr, sizeof(ia->saddr), "%s/%d",
- inet_ntoa(*addr), inet_ntocidr(*mask));
+ snprintf(ia->saddr, sizeof(ia->saddr), "%s/%d", inet_ntoa(*addr),
+ inet_ntocidr(*mask));
#ifdef ALIAS_ADDR
blank = (ia->alias[0] == '\0');
logdebugx("%s: aliased %s", ia->alias, ia->saddr);
#endif
- logdebugx("%s: adding IP address %s %s %s",
- ifp->name, ia->saddr,
+ logdebugx("%s: adding IP address %s %s %s", ifp->name, ia->saddr,
ifp->flags & IFF_POINTOPOINT ? "destination" : "broadcast",
inet_ntoa(*bcast));
if (if_address(RTM_NEWADDR, ia) == -1) {
if (errno != EEXIST)
- logerr("%s: if_addaddress",
- __func__);
+ logerr("%s: if_addaddress", __func__);
if (ia->flags & IPV4_AF_NEW)
free(ia);
return NULL;
lease = &state->lease;
if (state->new == NULL) {
if ((ifo->options & (DHCPCD_EXITING | DHCPCD_PERSISTENT)) !=
- (DHCPCD_EXITING | DHCPCD_PERSISTENT))
- {
+ (DHCPCD_EXITING | DHCPCD_PERSISTENT)) {
if (state->added) {
/* Someone might have deleted our address */
if (state->addr != NULL)
* If IP addresses do not have lifetimes, there is a very real chance
* that re-adding them will scrub the subnet route temporarily
* which is a bad thing, so avoid it. */
- if (ia != NULL &&
- ia->mask.s_addr == lease->mask.s_addr &&
- ia->brd.s_addr == lease->brd.s_addr)
- {
+ if (ia != NULL && ia->mask.s_addr == lease->mask.s_addr &&
+ ia->brd.s_addr == lease->brd.s_addr) {
#ifndef IP_LIFETIME
- logdebugx("%s: IP address %s already exists",
- ifp->name, ia->saddr);
+ logdebugx("%s: IP address %s already exists", ifp->name,
+ ia->saddr);
#endif
} else {
#ifdef __linux__
TAILQ_FOREACH_SAFE(ia, &state->addrs, next, ia1) {
if (!(ia->flags & IPV4_AF_STALE))
continue;
- ipv4_handleifa(ifp->ctx, RTM_DELADDR,
- ifp->ctx->ifaces, ifp->name,
- &ia->addr, &ia->mask, &ia->brd, 0, getpid());
+ ipv4_handleifa(ifp->ctx, RTM_DELADDR, ifp->ctx->ifaces,
+ ifp->name, &ia->addr, &ia->mask, &ia->brd, 0, getpid());
}
}
void
-ipv4_handleifa(struct dhcpcd_ctx *ctx,
- int cmd, struct if_head *ifs, const char *ifname,
- const struct in_addr *addr, const struct in_addr *mask,
+ipv4_handleifa(struct dhcpcd_ctx *ctx, int cmd, struct if_head *ifs,
+ const char *ifname, const struct in_addr *addr, const struct in_addr *mask,
const struct in_addr *brd, int addrflags, pid_t pid)
{
struct interface *ifp;
/* Mask could have changed */
if (ia_is_new ||
(mask->s_addr != INADDR_ANY &&
- mask->s_addr != ia->mask.s_addr))
- {
+ mask->s_addr != ia->mask.s_addr)) {
ia->mask = *mask;
snprintf(ia->saddr, sizeof(ia->saddr), "%s/%d",
inet_ntoa(*addr), inet_ntocidr(*mask));
#endif
#ifndef BYTE_ORDER
-#define BIG_ENDIAN 1234
-#define LITTLE_ENDIAN 4321
+#define BIG_ENDIAN 1234
+#define LITTLE_ENDIAN 4321
#if defined(_BIG_ENDIAN)
-#define BYTE_ORDER BIG_ENDIAN
+#define BYTE_ORDER BIG_ENDIAN
#elif defined(_LITTLE_ENDIAN)
-#define BYTE_ORDER LITTLE_ENDIAN
+#define BYTE_ORDER LITTLE_ENDIAN
#else
#error Endian unknown
#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))
+#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 */
#ifndef IPV4_MMTU
#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 IN_IFF_TENTATIVE 0x01
-# define IN_IFF_DUPLICATED 0x02
-# define IN_IFF_DETACHED 0x00
+/* 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 0x01
+#define IN_IFF_DUPLICATED 0x02
+#define IN_IFF_DETACHED 0x00
#endif
#ifdef IN_IFF_TENTATIVE
#define IN_IFF_NOTUSEABLE \
- (IN_IFF_TENTATIVE | IN_IFF_DUPLICATED | IN_IFF_DETACHED)
+ (IN_IFF_TENTATIVE | IN_IFF_DUPLICATED | IN_IFF_DETACHED)
#endif
-#define IN_ARE_ADDR_EQUAL(a, b) ((a)->s_addr == (b)->s_addr)
-#define IN_IS_ADDR_UNSPECIFIED(a) ((a)->s_addr == INADDR_ANY)
+#define IN_ARE_ADDR_EQUAL(a, b) ((a)->s_addr == (b)->s_addr)
+#define IN_IS_ADDR_UNSPECIFIED(a) ((a)->s_addr == INADDR_ANY)
#ifdef __linux__
#define IP_LIFETIME
};
TAILQ_HEAD(ipv4_addrhead, ipv4_addr);
-#define IPV4_AF_STALE (1U << 0)
-#define IPV4_AF_NEW (1U << 1)
+#define IPV4_AF_STALE (1U << 0)
+#define IPV4_AF_NEW (1U << 1)
-#define IPV4_ADDR_EQ(a1, a2) ((a1) && (a1)->addr.s_addr == (a2)->addr.s_addr)
-#define IPV4_MASK1_EQ(a1, a2) ((a1) && (a1)->mask.s_addr == (a2)->mask.s_addr)
-#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))
+#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;
};
-#define IPV4_STATE(ifp) \
- ((struct ipv4_state *)(ifp)->if_data[IF_DATA_IPV4])
-#define IPV4_CSTATE(ifp) \
+#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
bool inet_getroutes(struct dhcpcd_ctx *, rb_tree_t *);
-#define STATE_ADDED 0x01
-#define STATE_FAKE 0x02
-#define STATE_EXPIRED 0x04
+#define STATE_ADDED 0x01
+#define STATE_FAKE 0x02
+#define STATE_EXPIRED 0x04
int ipv4_deladdr(struct ipv4_addr *, int);
-struct ipv4_addr *ipv4_addaddr(struct interface *,
- const struct in_addr *, const struct in_addr *, const struct in_addr *,
- uint32_t, uint32_t);
+struct ipv4_addr *ipv4_addaddr(struct interface *, const struct in_addr *,
+ const struct in_addr *, const struct in_addr *, uint32_t, uint32_t);
struct ipv4_addr *ipv4_applyaddr(void *);
-struct ipv4_addr *ipv4_iffindaddr(struct interface *,
- const struct in_addr *, const struct in_addr *);
+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 *);
-struct ipv4_addr *ipv4_findmaskbrd(struct dhcpcd_ctx *,
- const struct in_addr *);
+struct ipv4_addr *ipv4_findmaskbrd(struct dhcpcd_ctx *, const struct in_addr *);
void ipv4_markaddrsstale(struct interface *);
void ipv4_deletestaleaddrs(struct interface *);
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, pid_t);
+ const struct in_addr *, const struct in_addr *, const struct in_addr *, int,
+ pid_t);
void ipv4_free(struct interface *);
#endif /* INET */
*/
#include <arpa/inet.h>
-
#include <assert.h>
#include <errno.h>
#include <stdbool.h>
#include <string.h>
#include <unistd.h>
-#define ELOOP_QUEUE IPV4LL
-#include "config.h"
+#define ELOOP_QUEUE IPV4LL
#include "arp.h"
#include "common.h"
+#include "config.h"
#include "dhcp.h"
#include "eloop.h"
-#include "if.h"
#include "if-options.h"
+#include "if.h"
#include "ipv4.h"
#include "ipv4ll.h"
#include "logerr.h"
static void ipv4ll_start_arp(void *arg);
-static const struct in_addr inaddr_llmask = {
- .s_addr = HTONL(LINKLOCAL_MASK)
-};
-static const struct in_addr inaddr_llbcast = {
- .s_addr = HTONL(LINKLOCAL_BCAST)
-};
+static const struct in_addr inaddr_llmask = { .s_addr = HTONL(LINKLOCAL_MASK) };
+static const struct in_addr inaddr_llbcast = { .s_addr = HTONL(
+ LINKLOCAL_BCAST) };
static void
ipv4ll_pickaddr(struct interface *ifp)
do {
long r;
-again:
+ again:
/* RFC 3927 Section 2.1 states that the first 256 and
* last 256 addresses are reserved for future use.
* See ipv4ll_start for why we don't use arc4random. */
/* coverity[dont_call] */
r = random();
- addr.s_addr = ntohl(LINKLOCAL_ADDR |
- ((uint32_t)(r % 0xFD00) + 0x0100));
+ addr.s_addr = ntohl(
+ LINKLOCAL_ADDR | ((uint32_t)(r % 0xFD00) + 0x0100));
/* No point using a failed address */
if (IN_ARE_ADDR_EQUAL(&addr, &state->pickedaddr))
struct in_addr in;
assert(ifp != NULL);
- if ((state = IPV4LL_STATE(ifp)) == NULL ||
- state->addr == NULL)
+ if ((state = IPV4LL_STATE(ifp)) == NULL || state->addr == NULL)
return 0;
if ((rt = rt_new(ifp)) == NULL)
struct in_addr in;
assert(ifp != NULL);
- if ((state = IPV4LL_STATE(ifp)) == NULL ||
- state->addr == NULL)
+ if ((state = IPV4LL_STATE(ifp)) == NULL || state->addr == NULL)
return 0;
if ((rt = rt_new(ifp)) == NULL)
return 0;
/* Emulate a DHCP environment */
- if (efprintf(fp, "%s%sip_address=%s",
- prefix, pf, inet_ntoa(state->addr->addr)) == -1)
+ if (efprintf(fp, "%s%sip_address=%s", prefix, pf,
+ inet_ntoa(state->addr->addr)) == -1)
return -1;
- if (efprintf(fp, "%s%ssubnet_mask=%s",
- prefix, pf, inet_ntoa(state->addr->mask)) == -1)
+ if (efprintf(fp, "%s%ssubnet_mask=%s", prefix, pf,
+ inet_ntoa(state->addr->mask)) == -1)
return -1;
- if (efprintf(fp, "%s%ssubnet_cidr=%d",
- prefix, pf, inet_ntocidr(state->addr->mask)) == -1)
+ if (efprintf(fp, "%s%ssubnet_cidr=%d", prefix, pf,
+ inet_ntocidr(state->addr->mask)) == -1)
return -1;
- if (efprintf(fp, "%s%sbroadcast_address=%s",
- prefix, pf, inet_ntoa(state->addr->brd)) == -1)
+ if (efprintf(fp, "%s%sbroadcast_address=%s", prefix, pf,
+ inet_ntoa(state->addr->brd)) == -1)
return -1;
netnum.s_addr = state->addr->addr.s_addr & state->addr->mask.s_addr;
- if (efprintf(fp, "%s%snetwork_number=%s",
- prefix, pf, inet_ntoa(netnum)) == -1)
+ if (efprintf(fp, "%s%snetwork_number=%s", prefix, pf,
+ inet_ntoa(netnum)) == -1)
return -1;
return 5;
}
state->arp = NULL;
}
#else
-#define ipv4ll_freearp(ifp)
+#define ipv4ll_freearp(ifp)
#endif
static void
#ifdef IN_IFF_NOTREADY
if (ia == NULL || ia->addr_flags & IN_IFF_NOTREADY)
#endif
- loginfox("%s: using IPv4LL address %s",
- ifp->name, inet_ntoa(state->pickedaddr));
+ loginfox("%s: using IPv4LL address %s", ifp->name,
+ inet_ntoa(state->pickedaddr));
if (ia == NULL) {
if (ifp->ctx->options & DHCPCD_TEST) {
ia = malloc(sizeof(*ia));
ifp->name, inet_ntoa(state->pickedaddr));
return;
}
- ia = ipv4_addaddr(ifp, &state->pickedaddr,
- &inaddr_llmask, &inaddr_llbcast,
- DHCP_INFINITE_LIFETIME, DHCP_INFINITE_LIFETIME);
+ ia = ipv4_addaddr(ifp, &state->pickedaddr, &inaddr_llmask,
+ &inaddr_llbcast, DHCP_INFINITE_LIFETIME,
+ DHCP_INFINITE_LIFETIME);
}
if (ia == NULL)
return;
ipv4ll_freearp(ifp);
if (++state->conflicts == MAX_CONFLICTS)
- logerrx("%s: failed to acquire an IPv4LL address",
- ifp->name);
+ logerrx("%s: failed to acquire an IPv4LL address", ifp->name);
ipv4ll_pickaddr(ifp);
eloop_timeout_add_sec(ifp->ctx->eloop,
- state->conflicts >= MAX_CONFLICTS ?
- RATE_LIMIT_INTERVAL : PROBE_WAIT,
+ state->conflicts >= MAX_CONFLICTS ? RATE_LIMIT_INTERVAL :
+ PROBE_WAIT,
ipv4ll_start_arp, ifp);
}
static void
ipv4ll_not_found_arp(struct arp_state *astate)
{
-
ipv4ll_not_found(astate->iface);
}
static void
ipv4ll_found_arp(struct arp_state *astate, __unused const struct arp_msg *amsg)
{
-
ipv4ll_found(astate->iface);
}
static void
ipv4ll_defend_failed_arp(struct arp_state *astate)
{
-
ipv4ll_defend_failed(astate->iface);
}
#endif
memcpy(&seed, ifp->hwaddr + ifp->hwlen - sizeof(seed),
sizeof(seed));
/* coverity[dont_call] */
- orig = initstate(seed,
- state->randomstate, sizeof(state->randomstate));
+ orig = initstate(seed, state->randomstate,
+ sizeof(state->randomstate));
/* Save the original state. */
if (ifp->ctx->randomstate == NULL)
void
ipv4ll_free(struct interface *ifp)
{
-
assert(ifp != NULL);
ipv4ll_freearp(ifp);
if (state == NULL)
return ia;
- if (cmd == RTM_DELADDR &&
- state->addr != NULL &&
- IN_ARE_ADDR_EQUAL(&state->addr->addr, &ia->addr))
- {
- loginfox("%s: pid %d deleted IP address %s",
- ifp->name, (int)pid, ia->saddr);
+ if (cmd == RTM_DELADDR && state->addr != NULL &&
+ IN_ARE_ADDR_EQUAL(&state->addr->addr, &ia->addr)) {
+ loginfox("%s: pid %d deleted IP address %s", ifp->name,
+ (int)pid, ia->saddr);
ipv4ll_defend_failed(ifp);
return ia;
}
#ifndef IPV4LL_H
#define IPV4LL_H
-#define LINKLOCAL_ADDR 0xa9fe0000
-#define LINKLOCAL_MASK IN_CLASSB_NET
-#define LINKLOCAL_BCAST (LINKLOCAL_ADDR | ~LINKLOCAL_MASK)
+#define LINKLOCAL_ADDR 0xa9fe0000
+#define LINKLOCAL_MASK IN_CLASSB_NET
+#define LINKLOCAL_BCAST (LINKLOCAL_ADDR | ~LINKLOCAL_MASK)
#ifndef IN_LINKLOCAL
-# define IN_LINKLOCAL(addr) ((addr & IN_CLASSB_NET) == LINKLOCAL_ADDR)
+#define IN_LINKLOCAL(addr) ((addr & IN_CLASSB_NET) == LINKLOCAL_ADDR)
#endif
#ifdef IPV4LL
#endif
};
-#define IPV4LL_STATE(ifp) \
+#define IPV4LL_STATE(ifp) \
((struct ipv4ll_state *)(ifp)->if_data[IF_DATA_IPV4LL])
-#define IPV4LL_CSTATE(ifp) \
+#define IPV4LL_CSTATE(ifp) \
((const struct ipv4ll_state *)(ifp)->if_data[IF_DATA_IPV4LL])
-#define IPV4LL_STATE_RUNNING(ifp) \
- (IPV4LL_CSTATE((ifp)) && !IPV4LL_CSTATE((ifp))->down && \
- (IPV4LL_CSTATE((ifp))->addr != NULL))
+#define IPV4LL_STATE_RUNNING(ifp) \
+ (IPV4LL_CSTATE((ifp)) && !IPV4LL_CSTATE((ifp))->down && \
+ (IPV4LL_CSTATE((ifp))->addr != NULL))
int ipv4ll_subnetroute(rb_tree_t *, struct interface *);
-int ipv4ll_defaultroute(rb_tree_t *,struct interface *);
+int ipv4ll_defaultroute(rb_tree_t *, struct interface *);
ssize_t ipv4ll_env(FILE *, const char *, const struct interface *);
void ipv4ll_start(void *);
void ipv4ll_claimed(void *);
* SUCH DAMAGE.
*/
-#include <sys/param.h>
#include <sys/types.h>
+#include <sys/param.h>
#include <sys/socket.h>
#include <sys/stat.h>
-#include <arpa/inet.h>
#include <net/if.h>
#include <net/route.h>
#include <netinet/in.h>
#include <netinet/if_ether.h>
+#include <arpa/inet.h>
+
#include "config.h"
#ifdef HAVE_SYS_BITOPS_H
#ifdef BSD
/* Purely for the ND6_IFF_AUTO_LINKLOCAL #define which is solely used
* to generate our CAN_ADD_LLADDR #define. */
-# include <netinet6/in6_var.h>
-# include <netinet6/nd6.h>
+#include <netinet6/in6_var.h>
+#include <netinet6/nd6.h>
#endif
#include <errno.h>
#include <syslog.h>
#include <unistd.h>
-#define ELOOP_QUEUE ELOOP_IPV6
+#define ELOOP_QUEUE ELOOP_IPV6
#include "common.h"
-#include "if.h"
-#include "dhcpcd.h"
#include "dhcp6.h"
+#include "dhcpcd.h"
#include "eloop.h"
+#include "if.h"
#include "ipv6.h"
#include "ipv6nd.h"
#include "logerr.h"
#include "script.h"
#ifdef HAVE_MD5_H
-# ifndef DEPGEN
-# include <md5.h>
-# endif
+#ifndef DEPGEN
+#include <md5.h>
+#endif
#endif
#ifdef SHA2_H
-# include SHA2_H
+#include SHA2_H
#endif
#ifndef SHA256_DIGEST_LENGTH
-# define SHA256_DIGEST_LENGTH 32
+#define SHA256_DIGEST_LENGTH 32
#endif
#ifdef IPV6_POLLADDRFLAG
-# warning kernel does not report IPv6 address flag changes
+#warning kernel does not report IPv6 address flag changes
#endif
/* Hackery at it's finest. */
#ifndef s6_addr32
-# ifdef __sun
-# define s6_addr32 _S6_un._S6_u32
-# else
-# define s6_addr32 __u6_addr.__u6_addr32
-# endif
+#ifdef __sun
+#define s6_addr32 _S6_un._S6_u32
+#else
+#define s6_addr32 __u6_addr.__u6_addr32
+#endif
#endif
#if defined(HAVE_IN6_ADDR_GEN_MODE_NONE) || defined(ND6_IFF_AUTO_LINKLOCAL) || \
defined(IFF_NOLINKLOCAL)
/* Only add the LL address if we have a carrier, so DaD works. */
-#define CAN_ADD_LLADDR(ifp) \
- (!((ifp)->options->options & DHCPCD_LINK) || if_is_link_up((ifp)))
+#define CAN_ADD_LLADDR(ifp) \
+ (!((ifp)->options->options & DHCPCD_LINK) || if_is_link_up((ifp)))
#ifdef __sun
/* Although we can add our own LL address, we cannot drop it
* without unplumbing the if which is a lot of code.
* So just keep it for the time being. */
-#define CAN_DROP_LLADDR(ifp) (0)
+#define CAN_DROP_LLADDR(ifp) (0)
#else
-#define CAN_DROP_LLADDR(ifp) (1)
+#define CAN_DROP_LLADDR(ifp) (1)
#endif
#else
/* We have no control over the OS adding the LLADDR, so just let it do it
* as we cannot force our own view on it. */
-#define CAN_ADD_LLADDR(ifp) (0)
-#define CAN_DROP_LLADDR(ifp) (0)
+#define CAN_ADD_LLADDR(ifp) (0)
+#define CAN_DROP_LLADDR(ifp) (0)
#endif
#ifdef IPV6_MANAGETEMPADDR
int
ipv6_init(struct dhcpcd_ctx *ctx)
{
-
if (ctx->ra_routers != NULL)
return 0;
} reslowhigh[] = {
/* RFC4291 + RFC6543 */
{ { 0x02, 0x00, 0x5e, 0xff, 0xfe, 0x00, 0x00, 0x00 },
- { 0x02, 0x00, 0x5e, 0xff, 0xfe, 0xff, 0xff, 0xff } },
+ { 0x02, 0x00, 0x5e, 0xff, 0xfe, 0xff, 0xff, 0xff } },
/* RFC2526 */
{ { 0xfd, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80 },
- { 0xfd, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } }
+ { 0xfd, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } }
};
static bool
}
static int
-ipv6_makehwaddr(struct in6_addr *addr,
- const struct in6_addr *prefix, int prefix_len, const struct interface *ifp)
+ipv6_makehwaddr(struct in6_addr *addr, const struct in6_addr *prefix,
+ int prefix_len, const struct interface *ifp)
{
-
if (prefix_len > 64) {
errno = EINVAL;
return -1;
switch (ifp->hwtype) {
case ARPHRD_ETHER:
if (ifp->hwlen == 6) {
- addr->s6_addr[ 8] = ifp->hwaddr[0];
- addr->s6_addr[ 9] = ifp->hwaddr[1];
+ addr->s6_addr[8] = ifp->hwaddr[0];
+ addr->s6_addr[9] = ifp->hwaddr[1];
addr->s6_addr[10] = ifp->hwaddr[2];
addr->s6_addr[11] = 0xff;
addr->s6_addr[12] = 0xfe;
/* RFC7217 */
static int
-ipv6_makestableprivate1(struct dhcpcd_ctx *ctx,
- struct in6_addr *addr, const struct in6_addr *prefix, int prefix_len,
+ipv6_makestableprivate1(struct dhcpcd_ctx *ctx, struct in6_addr *addr,
+ const struct in6_addr *prefix, int prefix_len,
const unsigned char *netiface, size_t netiface_len,
- const unsigned char *netid, size_t netid_len,
- unsigned short vlanid,
+ const unsigned char *netid, size_t netid_len, unsigned short vlanid,
uint32_t *dad_counter)
{
unsigned char buf[2048], *p, digest[SHA256_DIGEST_LENGTH];
}
int
-ipv6_makestableprivate(struct in6_addr *addr,
- const struct in6_addr *prefix, int prefix_len,
- const struct interface *ifp,
- int *dad_counter)
+ipv6_makestableprivate(struct in6_addr *addr, const struct in6_addr *prefix,
+ int prefix_len, const struct interface *ifp, int *dad_counter)
{
uint32_t dad;
int r;
/* For our implementation, we shall set the hardware address
* as the interface identifier */
r = ipv6_makestableprivate1(ifp->ctx, addr, prefix, prefix_len,
- ifp->hwaddr, ifp->hwlen,
- ifp->ssid, ifp->ssid_len,
- ifp->vlanid, &dad);
+ ifp->hwaddr, ifp->hwlen, ifp->ssid, ifp->ssid_len, ifp->vlanid,
+ &dad);
if (r == 0)
*dad_counter = (int)dad;
#ifdef IPV6_AF_TEMPORARY
static int
-ipv6_maketemporaryaddress(struct in6_addr *addr,
- const struct in6_addr *prefix, int prefix_len,
- const struct interface *ifp)
+ipv6_maketemporaryaddress(struct in6_addr *addr, const struct in6_addr *prefix,
+ int prefix_len, const struct interface *ifp)
{
struct in6_addr mask;
struct interface *ifpn;
int
ipv6_mask(struct in6_addr *mask, int len)
{
- static const unsigned char masks[NBBY] =
- { 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff };
+ static const unsigned char masks[NBBY] = { 0x80, 0xc0, 0xe0, 0xf0, 0xf8,
+ 0xfc, 0xfe, 0xff };
int bytes, bits, i;
if (len < 0 || len > 128) {
if (ifo->options & DHCPCD_SLAACPRIVATE) {
dad = 0;
- if (ipv6_makestableprivate(addr,
- prefix, prefix_len, ifp, &dad) == -1)
+ if (ipv6_makestableprivate(addr, prefix, prefix_len, ifp,
+ &dad) == -1)
return -1;
return dad;
} else if (!IN6_IS_ADDR_UNSPECIFIED(&ifo->token)) {
* address to base it on. */
if (ifp->hwlen == 0) {
if ((ap = ipv6_linklocal(ifp)) == NULL) {
- /* We delay a few functions until we get a local-link address
- * so this should never be hit. */
+ /* We delay a few functions until we get a local-link
+ * address so this should never be hit. */
errno = ENOENT;
return -1;
}
static void
in6_to_h64(uint64_t *vhigh, uint64_t *vlow, const struct in6_addr *addr)
{
-
*vhigh = be64dec(addr->s6_addr);
*vlow = be64dec(addr->s6_addr + 8);
}
static void
h64_to_in6(struct in6_addr *addr, uint64_t vhigh, uint64_t vlow)
{
-
be64enc(addr->s6_addr, vhigh);
be64enc(addr->s6_addr + 8, vlow);
}
int
-ipv6_userprefix(
- const struct in6_addr *prefix, // prefix from router
- short prefix_len, // length of prefix received
- uint64_t user_number, // "random" number from user
- struct in6_addr *result, // resultant prefix
- short result_len) // desired prefix length
+ipv6_userprefix(const struct in6_addr *prefix, // prefix from router
+ short prefix_len, // length of prefix received
+ uint64_t user_number, // "random" number from user
+ struct in6_addr *result, // resultant prefix
+ short result_len) // desired prefix length
{
uint64_t vh, vl, user_low, user_high;
- if (prefix_len < 1 || prefix_len > 128 ||
- result_len < 1 || result_len > 128)
- {
+ if (prefix_len < 1 || prefix_len > 128 || result_len < 1 ||
+ result_len > 128) {
errno = EINVAL;
return -1;
}
/* Check that the user_number fits inside result_len less prefix_len */
if (result_len < prefix_len ||
- fls64(user_number) > result_len - prefix_len)
- {
- errno = ERANGE;
- return -1;
+ fls64(user_number) > result_len - prefix_len) {
+ errno = ERANGE;
+ return -1;
}
/* If user_number is zero, just copy the prefix into the result. */
if (!(flags & IN6_IFF_TENTATIVE)) {
/* Simulate the kernel announcing the new address. */
ipv6_handleifa(ia->iface->ctx, RTM_NEWADDR,
- ia->iface->ctx->ifaces, ia->iface->name,
- &ia->addr, ia->prefix_len, &ia->dstaddr, flags, 0);
+ ia->iface->ctx->ifaces, ia->iface->name, &ia->addr,
+ ia->prefix_len, &ia->dstaddr, flags, 0);
} else {
/* Still tentative? Check again in a bit. */
- eloop_timeout_add_msec(ia->iface->ctx->eloop,
- RETRANS_TIMER / 2, ipv6_checkaddrflags, ia);
+ eloop_timeout_add_msec(ia->iface->ctx->eloop, RETRANS_TIMER / 2,
+ ipv6_checkaddrflags, ia);
}
}
#endif
static void
ipv6_deletedaddr(struct ipv6_addr *ia)
{
-
#ifdef DHCP6
#ifdef PRIVSEP
if (!(ia->iface->ctx->options & DHCPCD_MANAGER))
struct ipv6_addr *ap;
loginfox("%s: deleting address %s", ia->iface->name, ia->saddr);
- if (if_address6(RTM_DELADDR, ia) == -1 &&
- errno != EADDRNOTAVAIL && errno != ESRCH &&
- errno != ENXIO && errno != ENODEV)
+ if (if_address6(RTM_DELADDR, ia) == -1 && errno != EADDRNOTAVAIL &&
+ errno != ESRCH && errno != ENXIO && errno != ENODEV)
logerr(__func__);
ipv6_deletedaddr(ia);
state = IPV6_STATE(ifp);
if (state == NULL) {
- ifp->if_data[IF_DATA_IPV6] = calloc(1, sizeof(*state));
+ ifp->if_data[IF_DATA_IPV6] = calloc(1, sizeof(*state));
state = IPV6_STATE(ifp);
if (state == NULL) {
logerr(__func__);
* route will be scrubbed and re-added. Something might
* be using it, so let's avoid it. */
if (ia->flags & IPV6_AF_DADCOMPLETED) {
- logdebugx("%s: IP address %s already exists",
- ia->iface->name, ia->saddr);
+ logdebugx("%s: IP address %s already exists", ia->iface->name,
+ ia->saddr);
return 0;
}
#endif
ia->saddr);
if (ia->prefix_pltime == ND6_INFINITE_LIFETIME &&
ia->prefix_vltime == ND6_INFINITE_LIFETIME)
- logdebugx("%s: pltime infinity, vltime infinity",
- ifp->name);
+ logdebugx("%s: pltime infinity, vltime infinity", ifp->name);
else if (ia->prefix_pltime == ND6_INFINITE_LIFETIME)
- logdebugx("%s: pltime infinity, vltime %"PRIu32" seconds",
+ logdebugx("%s: pltime infinity, vltime %" PRIu32 " seconds",
ifp->name, ia->prefix_vltime);
else if (ia->prefix_vltime == ND6_INFINITE_LIFETIME)
- logdebugx("%s: pltime %"PRIu32"seconds, vltime infinity",
+ logdebugx("%s: pltime %" PRIu32 "seconds, vltime infinity",
ifp->name, ia->prefix_pltime);
else
- logdebugx("%s: pltime %"PRIu32" seconds, vltime %"PRIu32
- " seconds",
+ logdebugx("%s: pltime %" PRIu32 " seconds, vltime %" PRIu32
+ " seconds",
ifp->name, ia->prefix_pltime, ia->prefix_vltime);
if (if_address6(RTM_NEWADDR, ia) == -1) {
#ifdef IPV6_MANAGETEMPADDR
/* RFC4941 Section 3.4 */
- if (ia->flags & IPV6_AF_TEMPORARY &&
- ia->prefix_pltime &&
- ia->prefix_vltime &&
- ifp->options->options & DHCPCD_SLAACTEMP)
+ if (ia->flags & IPV6_AF_TEMPORARY && ia->prefix_pltime &&
+ ia->prefix_vltime && ifp->options->options & DHCPCD_SLAACTEMP)
eloop_timeout_add_sec(ifp->ctx->eloop,
- ia->prefix_pltime - REGEN_ADVANCE,
- ipv6_regentempaddr, ia);
+ ia->prefix_pltime - REGEN_ADVANCE, ipv6_regentempaddr, ia);
#endif
/* Restore real pltime and vltime */
#endif
#ifdef IPV6_POLLADDRFLAG
- eloop_timeout_delete(ifp->ctx->eloop,
- ipv6_checkaddrflags, ia);
+ eloop_timeout_delete(ifp->ctx->eloop, ipv6_checkaddrflags, ia);
if (!(ia->flags & IPV6_AF_DADCOMPLETED)) {
- eloop_timeout_add_msec(ifp->ctx->eloop,
- RETRANS_TIMER / 2, ipv6_checkaddrflags, ia);
+ eloop_timeout_add_msec(ifp->ctx->eloop, RETRANS_TIMER / 2,
+ ipv6_checkaddrflags, ia);
}
#endif
* maintain their own lists of addresses. */
TAILQ_FOREACH(iap, &state->addrs, next) {
if (iap->alias[0] != '\0' &&
- IN6_ARE_ADDR_EQUAL(&iap->addr, &ia->addr))
- {
+ IN6_ARE_ADDR_EQUAL(&iap->addr, &ia->addr)) {
strlcpy(ia->alias, iap->alias, sizeof(ia->alias));
return 0;
}
lun = 0;
find_unit:
if (if_makealias(alias, IF_NAMESIZE, ia->iface->name, lun) >=
- IF_NAMESIZE)
- {
+ IF_NAMESIZE) {
errno = ENOMEM;
return -1;
}
ipv6_findaddrmatch(const struct ipv6_addr *addr, const struct in6_addr *match,
unsigned int flags)
{
-
if (match == NULL) {
- if ((addr->flags &
- (IPV6_AF_ADDED | IPV6_AF_DADCOMPLETED)) ==
+ if ((addr->flags & (IPV6_AF_ADDED | IPV6_AF_DADCOMPLETED)) ==
(IPV6_AF_ADDED | IPV6_AF_DADCOMPLETED))
return 1;
} else if (addr->prefix_vltime &&
}
struct ipv6_addr *
-ipv6_findaddr(struct dhcpcd_ctx *ctx, const struct in6_addr *addr, unsigned int flags)
+ipv6_findaddr(struct dhcpcd_ctx *ctx, const struct in6_addr *addr,
+ unsigned int flags)
{
struct ipv6_addr *nap;
#ifdef DHCP6
int
ipv6_doaddr(struct ipv6_addr *ia, struct timespec *now)
{
-
/* A delegated prefix is not an address. */
if (ia->flags & IPV6_AF_PFXDELEGATION)
return 0;
if (ia->prefix_vltime == 0) {
if (ia->flags & IPV6_AF_ADDED)
ipv6_deleteaddr(ia);
- eloop_q_timeout_delete(ia->iface->ctx->eloop,
- ELOOP_QUEUE_ALL, NULL, ia);
+ eloop_q_timeout_delete(ia->iface->ctx->eloop, ELOOP_QUEUE_ALL,
+ NULL, ia);
if (ia->flags & IPV6_AF_REQUEST) {
ia->flags &= ~IPV6_AF_ADDED;
return 0;
return -1;
}
- if (ia->flags & IPV6_AF_STALE ||
- IN6_IS_ADDR_UNSPECIFIED(&ia->addr))
+ if (ia->flags & IPV6_AF_STALE || IN6_IS_ADDR_UNSPECIFIED(&ia->addr))
return 0;
ipv6_addaddr(ia, now);
#ifndef SMALL
if (ifd != NULL &&
(ap->delegating_prefix == NULL ||
- ap->delegating_prefix->iface != ifd))
+ ap->delegating_prefix->iface != ifd))
continue;
#endif
if (drop != 2)
TAILQ_REMOVE(addrs, ap, next);
if (drop && ap->flags & IPV6_AF_ADDED &&
(ap->iface->options->options &
- (DHCPCD_EXITING | DHCPCD_PERSISTENT)) !=
- (DHCPCD_EXITING | DHCPCD_PERSISTENT))
- {
+ (DHCPCD_EXITING | DHCPCD_PERSISTENT)) !=
+ (DHCPCD_EXITING | DHCPCD_PERSISTENT)) {
/* Don't drop link-local addresses. */
if (!IN6_IS_ADDR_LINKLOCAL(&ap->addr) ||
- CAN_DROP_LLADDR(ap->iface))
- {
+ CAN_DROP_LLADDR(ap->iface)) {
if (drop == 2)
TAILQ_REMOVE(addrs, ap, next);
/* Find the same address somewhere else */
apf = ipv6_findaddr(ap->iface->ctx, &ap->addr,
0);
- if ((apf == NULL ||
- (apf->iface != ap->iface)))
+ if ((apf == NULL || (apf->iface != ap->iface)))
ipv6_deleteaddr(ap);
if (!(ap->iface->options->options &
- DHCPCD_EXITING) && apf)
+ DHCPCD_EXITING) &&
+ apf)
ipv6_addaddr(apf, &now);
if (drop == 2)
ipv6_freeaddr(ap);
}
void
-ipv6_handleifa(struct dhcpcd_ctx *ctx,
- int cmd, struct if_head *ifs, const char *ifname,
- const struct in6_addr *addr, uint8_t prefix_len,
+ipv6_handleifa(struct dhcpcd_ctx *ctx, int cmd, struct if_head *ifs,
+ const char *ifname, const struct in6_addr *addr, uint8_t prefix_len,
const struct in6_addr *dstaddr, int addrflags, pid_t pid)
{
struct interface *ifp;
/* Solaris on-link route is an unspecified address! */
if (IN6_IS_ADDR_UNSPECIFIED(addr)) {
- if (if_getsubnet(ctx, ifname, AF_INET6,
- &subnet, sizeof(subnet)) == -1)
- {
+ if (if_getsubnet(ctx, ifname, AF_INET6, &subnet,
+ sizeof(subnet)) == -1) {
logerr(__func__);
return;
}
* As we can't extend infinite, we'll
* create a new temporary address. */
ia->prefix_pltime = 0;
- ia->prefix_vltime =
- ND6_INFINITE_LIFETIME;
+ ia->prefix_vltime = ND6_INFINITE_LIFETIME;
}
/* This is a minor regression against RFC 4941
* because the kernel only knows when the
#ifdef IPV6_POLLADDRFLAG
if ((IN6_IS_ADDR_LINKLOCAL(&ia->addr) || ia->dadcallback) &&
- ia->addr_flags & IN6_IFF_TENTATIVE)
- {
- eloop_timeout_add_msec(
- ia->iface->ctx->eloop,
+ ia->addr_flags & IN6_IFF_TENTATIVE) {
+ eloop_timeout_add_msec(ia->iface->ctx->eloop,
RETRANS_TIMER / 2, ipv6_checkaddrflags, ia);
}
#endif
if (ia == NULL)
return;
- if (ia->dadcallback && ((ia->addr_flags &
- (IN6_IFF_DETACHED | IN6_IFF_TENTATIVE)) == 0 ||
- ia->addr_flags & IN6_IFF_DUPLICATED))
+ if (ia->dadcallback &&
+ ((ia->addr_flags & (IN6_IFF_DETACHED | IN6_IFF_TENTATIVE)) == 0 ||
+ ia->addr_flags & IN6_IFF_DUPLICATED))
ia->dadcallback(ia);
if (IN6_IS_ADDR_LINKLOCAL(&ia->addr) &&
- !(ia->addr_flags & IN6_IFF_NOTUSEABLE))
- {
+ !(ia->addr_flags & IN6_IFF_NOTUSEABLE)) {
/* Now run any callbacks.
* Typically IPv6RS or DHCPv6 */
- while ((cb = TAILQ_FIRST(&state->ll_callbacks)))
- {
+ while ((cb = TAILQ_FIRST(&state->ll_callbacks))) {
TAILQ_REMOVE(&state->ll_callbacks, cb, next);
cb->callback(cb->arg);
free(cb);
* call rt_build to add/remove the default route. */
if (ifp->active &&
((ifp->options != NULL && ifp->options->options & DHCPCD_IPV6) ||
- (ifp->options == NULL && ctx->options & DHCPCD_IPV6)) &&
+ (ifp->options == NULL && ctx->options & DHCPCD_IPV6)) &&
!(ctx->options & DHCPCD_RTBUILD) &&
(ipv6_anyglobal(ifp) != NULL) != anyglobal)
rt_build(ctx, AF_INET6);
int
ipv6_hasaddr(const struct interface *ifp)
{
-
if (ipv6nd_iffindaddr(ifp, NULL, 0) != NULL)
return 1;
#ifdef DHCP6
return NULL;
}
-
static struct ipv6_addr *
ipv6_iffinddstaddr(const struct interface *ifp, const struct in6_addr *addr)
{
}
int
-ipv6_addlinklocalcallback(struct interface *ifp,
- void (*callback)(void *), void *arg)
+ipv6_addlinklocalcallback(struct interface *ifp, void (*callback)(void *),
+ void *arg)
{
struct ipv6_state *state;
struct ll_callback *cb;
}
static const uint8_t allzero[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
-static const uint8_t allone[8] =
- { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
+static const uint8_t allone[8] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff };
static int
ipv6_addlinklocal(struct interface *ifp)
return -1;
}
if (memcmp(ifp->hwaddr, allzero, ifp->hwlen) == 0 ||
- memcmp(ifp->hwaddr, allone, ifp->hwlen) == 0)
- {
+ memcmp(ifp->hwaddr, allone, ifp->hwlen) == 0) {
errno = EINVAL;
return -1;
}
dadcounter = 0;
if (ifp->options->options & DHCPCD_SLAACPRIVATE) {
-nextslaacprivate:
- if (ipv6_makestableprivate(&ap->addr,
- &ap->prefix, ap->prefix_len, ifp, &dadcounter) == -1)
- {
+ nextslaacprivate:
+ if (ipv6_makestableprivate(&ap->addr, &ap->prefix,
+ ap->prefix_len, ifp, &dadcounter) == -1) {
free(ap);
return -1;
}
ap->dadcounter = dadcounter;
- } else if (ipv6_makehwaddr(&ap->addr,
- &ap->prefix, ap->prefix_len, ifp) == -1) {
+ } else if (ipv6_makehwaddr(&ap->addr, &ap->prefix, ap->prefix_len,
+ ifp) == -1) {
free(ap);
return -1;
}
if (IN6_ARE_ADDR_EQUAL(&ap->addr, &ap2->addr)) {
if (ap2->addr_flags & IN6_IFF_DUPLICATED) {
if (ifp->options->options &
- DHCPCD_SLAACPRIVATE)
- {
+ DHCPCD_SLAACPRIVATE) {
dadcounter++;
goto nextslaacprivate;
}
logwarnx("%s: waiting for %s to complete",
ap2->iface->name, ap2->saddr);
free(ap);
- errno = EEXIST;
+ errno = EEXIST;
return 0;
}
}
if (ia != NULL) {
#ifdef IPV6_POLLADDRFLAG
if (ia->addr_flags & IN6_IFF_TENTATIVE) {
- eloop_timeout_add_msec(
- ia->iface->ctx->eloop,
+ eloop_timeout_add_msec(ia->iface->ctx->eloop,
RETRANS_TIMER / 2, ipv6_checkaddrflags, ia);
}
#endif
void
ipv6_setscope(struct sockaddr_in6 *sin, unsigned int ifindex)
{
-
#ifdef __KAME__
/* KAME based systems want to store the scope inside the sin6_addr
* for link local addresses */
if (IN6_IS_ADDR_LINKLOCAL(&sin->sin6_addr)) {
uint16_t scope = htons((uint16_t)ifindex);
- memcpy(&sin->sin6_addr.s6_addr[2], &scope,
- sizeof(scope));
+ memcpy(&sin->sin6_addr.s6_addr[2], &scope, sizeof(scope));
}
sin->sin6_scope_id = 0;
#else
memcpy(&ia->addr, &iaf->addr, sizeof(ia->addr));
else {
ia->dadcounter = ipv6_makeaddr(&ia->addr, ifp,
- &ia->prefix,
- ia->prefix_len,
- ia->flags);
+ &ia->prefix, ia->prefix_len, ia->flags);
if (ia->dadcounter == -1)
goto err;
}
cbp = inet_ntop(AF_INET6, &ia->prefix, buf, sizeof(buf));
goto paddr;
} else {
-makepfx:
+ makepfx:
ia->addr = *addr;
- if (ipv6_makeprefix(&ia->prefix,
- &ia->addr, ia->prefix_len) == -1)
+ if (ipv6_makeprefix(&ia->prefix, &ia->addr, ia->prefix_len) ==
+ -1)
goto err;
}
wascompleted = (ia->flags & IPV6_AF_DADCOMPLETED);
ia->flags |= IPV6_AF_DADCOMPLETED;
if (ia->addr_flags & IN6_IFF_DUPLICATED)
- logwarnx("%s: DAD detected %s", ia->iface->name,
- ia->saddr);
+ logwarnx("%s: DAD detected %s", ia->iface->name, ia->saddr);
else if (!wascompleted) {
- logdebugx("%s: IPv6 static DAD completed",
- ia->iface->name);
+ logdebugx("%s: IPv6 static DAD completed", ia->iface->name);
}
#define FINISHED (IPV6_AF_ADDED | IPV6_AF_DADCOMPLETED)
state = IPV6_STATE(ifp);
TAILQ_FOREACH(ia, &state->addrs, next) {
if (ia->flags & IPV6_AF_STATIC &&
- (ia->flags & FINISHED) != FINISHED)
- {
+ (ia->flags & FINISHED) != FINISHED) {
wascompleted = 1;
break;
}
ia = ipv6_iffindaddr(ifp, &ifp->options->req_addr6, 0);
if (ia != NULL &&
(ia->prefix_len != ifp->options->req_prefix_len ||
- ia->addr_flags & IN6_IFF_NOTUSEABLE))
- {
+ ia->addr_flags & IN6_IFF_NOTUSEABLE)) {
ipv6_deleteaddr(ia);
ia = NULL;
}
void
ipv6_ctxfree(struct dhcpcd_ctx *ctx)
{
-
free(ctx->ra_routers);
free(ctx->secret);
}
int
-ipv6_handleifa_addrs(int cmd,
- struct ipv6_addrhead *addrs, const struct ipv6_addr *addr, pid_t pid)
+ipv6_handleifa_addrs(int cmd, struct ipv6_addrhead *addrs,
+ const struct ipv6_addr *addr, pid_t pid)
{
struct ipv6_addr *ia, *ian;
int found = 0, alldadcompleted = 1;
/* Check DAD.
* On Linux we can get IN6_IFF_DUPLICATED via RTM_DELADDR. */
if (((ia->addr_flags &
- (IN6_IFF_DETACHED | IN6_IFF_TENTATIVE)) == 0 ||
- ia->addr_flags & IN6_IFF_DUPLICATED) &&
- (ia->flags & IPV6_AF_DADCOMPLETED) == 0)
- {
+ (IN6_IFF_DETACHED | IN6_IFF_TENTATIVE)) == 0 ||
+ ia->addr_flags & IN6_IFF_DUPLICATED) &&
+ (ia->flags & IPV6_AF_DADCOMPLETED) == 0) {
found++;
if (ia->dadcallback)
ia->dadcallback(ia);
if (state->desync_factor && !force && state->desync_factor < max)
return;
if (state->desync_factor == 0)
- state->desync_factor =
- arc4random_uniform(MIN(MAX_DESYNC_FACTOR, max));
+ state->desync_factor = arc4random_uniform(
+ MIN(MAX_DESYNC_FACTOR, max));
max = TEMP_PREFERRED_LIFETIME - state->desync_factor - REGEN_ADVANCE;
eloop_timeout_add_sec(ifp->ctx->eloop, max, ipv6_regentempaddrs, ifp);
}
TEMP_PREFERRED_LIFETIME - state->desync_factor);
ia->prefix_vltime = MIN(ia0->prefix_vltime, TEMP_VALID_LIFETIME);
if (ia->prefix_pltime <= REGEN_ADVANCE ||
- ia->prefix_pltime > ia0->prefix_vltime)
- {
- errno = EINVAL;
+ ia->prefix_pltime > ia0->prefix_vltime) {
+ errno = EINVAL;
free(ia);
return NULL;
}
state = IPV6_STATE(ia->iface);
first = NULL;
TAILQ_FOREACH_REVERSE(ap, &state->addrs, ipv6_addrhead, next) {
- if (ap->flags & IPV6_AF_TEMPORARY &&
- ap->prefix_pltime &&
- IN6_ARE_ADDR_EQUAL(&ia->prefix, &ap->prefix))
- {
+ if (ap->flags & IPV6_AF_TEMPORARY && ap->prefix_pltime &&
+ IN6_ARE_ADDR_EQUAL(&ia->prefix, &ap->prefix)) {
unsigned int max, ext;
if (flags == 0) {
if (ap->prefix_pltime -
- (uint32_t)(ia->acquired.tv_sec -
- ap->acquired.tv_sec)
- < REGEN_ADVANCE)
+ (uint32_t)(ia->acquired.tv_sec -
+ ap->acquired.tv_sec) <
+ REGEN_ADVANCE)
continue;
return ap;
/* RFC4941 Section 3.3.2
* Extend temporary times, but ensure that they
* never last beyond the system limit. */
- ext = (unsigned int)ia->acquired.tv_sec
- + ia->prefix_pltime;
+ ext = (unsigned int)ia->acquired.tv_sec +
+ ia->prefix_pltime;
max = (unsigned int)(ap->created.tv_sec +
- TEMP_PREFERRED_LIFETIME -
- state->desync_factor);
+ TEMP_PREFERRED_LIFETIME - state->desync_factor);
if (ext < max)
ap->prefix_pltime = ia->prefix_pltime;
else
- ap->prefix_pltime =
- (uint32_t)(max - ia->acquired.tv_sec);
+ ap->prefix_pltime = (uint32_t)(max -
+ ia->acquired.tv_sec);
-valid:
+ valid:
ext = (unsigned int)ia->acquired.tv_sec +
ia->prefix_vltime;
max = (unsigned int)(ap->created.tv_sec +
if (ext < max)
ap->prefix_vltime = ia->prefix_vltime;
else
- ap->prefix_vltime =
- (uint32_t)(max - ia->acquired.tv_sec);
+ ap->prefix_vltime = (uint32_t)(max -
+ ia->acquired.tv_sec);
/* Just extend the latest matching prefix */
ap->acquired = ia->acquired;
/* Mark addresses for regen so we don't infinite loop. */
TAILQ_FOREACH(ia, &state->addrs, next) {
if (ia->flags & IPV6_AF_TEMPORARY &&
- ia->flags & IPV6_AF_ADDED &&
- !(ia->flags & IPV6_AF_STALE))
+ ia->flags & IPV6_AF_ADDED && !(ia->flags & IPV6_AF_STALE))
ia->flags |= IPV6_AF_REGEN;
else
ia->flags &= ~IPV6_AF_REGEN;
TAILQ_FOREACH_SAFE(ia, &state->addrs, next, ia1) {
if (ia->flags & IPV6_AF_STALE)
- ipv6_handleifa(ifp->ctx, RTM_DELADDR,
- ifp->ctx->ifaces, ifp->name,
- &ia->addr, ia->prefix_len,
- &ia->dstaddr, 0, getpid());
+ ipv6_handleifa(ifp->ctx, RTM_DELADDR, ifp->ctx->ifaces,
+ ifp->name, &ia->addr, ia->prefix_len, &ia->dstaddr,
+ 0, getpid());
}
}
-
static struct rt *
inet6_makeroute(struct interface *ifp, const struct ra *rap)
{
}
if (lo0 == NULL)
logwarnx("cannot find a loopback interface "
- "to reject via");
+ "to reject via");
else
ifp = lo0;
}
return rt;
}
-#define RT_IS_DEFAULT(rtp) \
- (IN6_ARE_ADDR_EQUAL(&((rtp)->dest), &in6addr_any) && \
+#define RT_IS_DEFAULT(rtp) \
+ (IN6_ARE_ADDR_EQUAL(&((rtp)->dest), &in6addr_any) && \
IN6_ARE_ADDR_EQUAL(&((rtp)->mask), &in6addr_any))
static int
continue;
TAILQ_FOREACH(ia, &state->addrs, next) {
if ((ia->flags & (IPV6_AF_ADDED | IPV6_AF_STATIC)) ==
- (IPV6_AF_ADDED | IPV6_AF_STATIC))
- {
+ (IPV6_AF_ADDED | IPV6_AF_STATIC)) {
rt = inet6_makeprefix(ifp, NULL, ia);
if (rt)
rt_proto_add(routes, rt);
continue;
/* add rfc4191 route information routes */
- TAILQ_FOREACH (rinfo, &rap->rinfos, next) {
- if(rinfo->lifetime == 0)
+ TAILQ_FOREACH(rinfo, &rap->rinfos, next) {
+ if (rinfo->lifetime == 0)
continue;
if ((rt = inet6_makeroute(rap->iface, rap)) == NULL)
continue;
#ifdef DHCP6
static int
-inet6_dhcproutes(rb_tree_t *routes, struct dhcpcd_ctx *ctx,
- enum DH6S dstate)
+inet6_dhcproutes(rb_tree_t *routes, struct dhcpcd_ctx *ctx, enum DH6S dstate)
{
struct interface *ifp;
const struct dhcp6_state *d6_state;
bool
inet6_getroutes(struct dhcpcd_ctx *ctx, rb_tree_t *routes)
{
-
/* Should static take priority? */
if (inet6_staticroutes(routes, ctx) == -1)
return false;
#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
+#if !defined(__QNX__) && !defined(__sun)
+#include <sys/endian.h>
+#endif
+#include <net/if.h>
+#ifndef __sun
+#include <netinet6/in6_var.h>
+#endif
#endif
-#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)
+#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)
+#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_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
/* RFC7217 constants */
-#define IDGEN_RETRIES 3
-#define IDGEN_DELAY 1 /* second */
+#define IDGEN_RETRIES 3
+#define IDGEN_DELAY 1 /* second */
/* Interface identifier length. Prefix + this == 128 for autoconf */
-#define ipv6_ifidlen(ifp) 64
-#define IA6_CANAUTOCONF(ia) \
+#define ipv6_ifidlen(ifp) 64
+#define IA6_CANAUTOCONF(ia) \
((ia)->prefix_len + ipv6_ifidlen((ia)->iface) == 128)
#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 )
+#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
#ifndef IN6ADDR_LINKLOCAL_ALLNODES_INIT
-#define IN6ADDR_LINKLOCAL_ALLNODES_INIT \
- {{{ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}}
+#define IN6ADDR_LINKLOCAL_ALLNODES_INIT \
+ { \
+ {{ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }} \
+ }
#endif
#ifndef IN6ADDR_LINKLOCAL_ALLROUTERS_INIT
-#define IN6ADDR_LINKLOCAL_ALLROUTERS_INIT \
- {{{ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 }}}
+#define IN6ADDR_LINKLOCAL_ALLROUTERS_INIT \
+ { \
+ {{ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 }} \
+ }
#endif
/*
*/
#ifndef __linux__
/* We guard here to avoid breaking a compile on linux ppc-64 headers */
-# include <sys/param.h>
+#include <sys/param.h>
#endif
#ifdef BSD
-# define IPV6_POLLADDRFLAG
+#define IPV6_POLLADDRFLAG
#endif
/* This was fixed in NetBSD */
#if (defined(__DragonFly_version) && __DragonFly_version >= 500704) || \
(defined(__NetBSD_Version__) && __NetBSD_Version__ >= 699002000)
-# undef IPV6_POLLADDRFLAG
+#undef IPV6_POLLADDRFLAG
#endif
/* Of course OpenBSD has their own special name. */
#if !defined(IN6_IFF_TEMPORARY) && defined(IN6_IFF_PRIVACY)
-#define IN6_IFF_TEMPORARY IN6_IFF_PRIVACY
+#define IN6_IFF_TEMPORARY IN6_IFF_PRIVACY
#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 0x02
-# define IN6_IFF_DUPLICATED 0x04
-# define IN6_IFF_DETACHED 0x00
+/* 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 0x02
+#define IN6_IFF_DUPLICATED 0x04
+#define IN6_IFF_DETACHED 0x00
#endif
#define IN6_IFF_NOTUSEABLE \
* Linux-3.18 allows the marking of addresses from which to manage temp addrs.
*/
#if defined(IN6_IFF_TEMPORARY) && !defined(__linux__)
-#define IPV6_MANAGETEMPADDR
+#define IPV6_MANAGETEMPADDR
#endif
#ifdef __linux__
- /* Match Linux defines to BSD */
-# ifdef IFA_F_TEMPORARY
-# define IN6_IFF_TEMPORARY IFA_F_TEMPORARY
-# endif
-# 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
+/* Match Linux defines to BSD */
+#ifdef IFA_F_TEMPORARY
+#define IN6_IFF_TEMPORARY IFA_F_TEMPORARY
+#endif
+#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 INET6
#endif
};
-#define IPV6_AF_ONLINK (1U << 0)
-#define IPV6_AF_NEW (1U << 1)
-#define IPV6_AF_STALE (1U << 2)
-#define IPV6_AF_ADDED (1U << 3)
-#define IPV6_AF_AUTOCONF (1U << 4)
-#define IPV6_AF_DADCOMPLETED (1U << 5)
-#define IPV6_AF_PFXDELEGATION (1U << 6)
-#define IPV6_AF_DELEGATED (1U << 7)
-#define IPV6_AF_NOREJECT (1U << 8)
-#define IPV6_AF_REQUEST (1U << 9)
-#define IPV6_AF_STATIC (1U << 10)
-#define IPV6_AF_DELEGATEDLOG (1U << 11)
-#define IPV6_AF_RAPFX (1U << 12)
-#define IPV6_AF_EXTENDED (1U << 13)
-#define IPV6_AF_REGEN (1U << 14)
-#define IPV6_AF_ROUTER (1U << 15)
-#define IPV6_AF_ADVERTISED (1U << 16)
+#define IPV6_AF_ONLINK (1U << 0)
+#define IPV6_AF_NEW (1U << 1)
+#define IPV6_AF_STALE (1U << 2)
+#define IPV6_AF_ADDED (1U << 3)
+#define IPV6_AF_AUTOCONF (1U << 4)
+#define IPV6_AF_DADCOMPLETED (1U << 5)
+#define IPV6_AF_PFXDELEGATION (1U << 6)
+#define IPV6_AF_DELEGATED (1U << 7)
+#define IPV6_AF_NOREJECT (1U << 8)
+#define IPV6_AF_REQUEST (1U << 9)
+#define IPV6_AF_STATIC (1U << 10)
+#define IPV6_AF_DELEGATEDLOG (1U << 11)
+#define IPV6_AF_RAPFX (1U << 12)
+#define IPV6_AF_EXTENDED (1U << 13)
+#define IPV6_AF_REGEN (1U << 14)
+#define IPV6_AF_ROUTER (1U << 15)
+#define IPV6_AF_ADVERTISED (1U << 16)
#ifdef IPV6_MANAGETEMPADDR
-#define IPV6_AF_TEMPORARY (1U << 17)
+#define IPV6_AF_TEMPORARY (1U << 17)
#endif
struct ll_callback {
#endif
};
-#define IPV6_STATE(ifp) \
- ((struct ipv6_state *)(ifp)->if_data[IF_DATA_IPV6])
-#define IPV6_CSTATE(ifp) \
+#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))
-
int ipv6_init(struct dhcpcd_ctx *);
-int ipv6_makestableprivate(struct in6_addr *,
- const struct in6_addr *, int, const struct interface *, int *);
+int ipv6_makestableprivate(struct in6_addr *, const struct in6_addr *, int,
+ const struct interface *, int *);
int ipv6_makeaddr(struct in6_addr *, struct interface *,
const struct in6_addr *, int, unsigned 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,
+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 *);
void ipv6_markaddrsstale(struct interface *, unsigned int);
void ipv6_deleteaddr(struct ipv6_addr *);
void ipv6_freedrop_addrs(struct ipv6_addrhead *, int, unsigned int,
const struct interface *);
-void ipv6_handleifa(struct dhcpcd_ctx *ctx, int, struct if_head *,
- const char *, const struct in6_addr *, uint8_t,
- const struct in6_addr *, int, pid_t);
+void ipv6_handleifa(struct dhcpcd_ctx *ctx, int, struct if_head *, const char *,
+ const struct in6_addr *, uint8_t, const struct in6_addr *, int, pid_t);
int ipv6_handleifa_addrs(int, struct ipv6_addrhead *, const struct ipv6_addr *,
pid_t);
-struct ipv6_addr *ipv6_iffindaddr(struct interface *,
- const struct in6_addr *, int);
+struct ipv6_addr *ipv6_iffindaddr(struct interface *, const struct in6_addr *,
+ int);
int ipv6_hasaddr(const struct interface *);
struct ipv6_addr *ipv6_anyglobal(struct interface *);
int ipv6_findaddrmatch(const struct ipv6_addr *, const struct in6_addr *,
unsigned int);
-struct ipv6_addr *ipv6_findaddr(struct dhcpcd_ctx *,
- const struct in6_addr *, unsigned int);
+struct ipv6_addr *ipv6_findaddr(struct dhcpcd_ctx *, const struct in6_addr *,
+ unsigned int);
struct ipv6_addr *ipv6_findmaskaddr(struct dhcpcd_ctx *,
const struct in6_addr *);
struct ipv6_addr *ipv6_finddstaddr(struct dhcpcd_ctx *,
* SUCH DAMAGE.
*/
-#include <sys/ioctl.h>
#include <sys/param.h>
+#include <sys/ioctl.h>
#include <sys/socket.h>
+
#include <net/if.h>
#include <net/route.h>
+#include <netinet/icmp6.h>
#include <netinet/in.h>
#include <netinet/ip6.h>
-#include <netinet/icmp6.h>
#include <assert.h>
#include <errno.h>
#include <syslog.h>
#include <unistd.h>
-#define ELOOP_QUEUE ELOOP_IPV6ND
+#define ELOOP_QUEUE ELOOP_IPV6ND
#include "common.h"
-#include "dhcpcd.h"
#include "dhcp-common.h"
#include "dhcp6.h"
+#include "dhcpcd.h"
#include "eloop.h"
#include "if.h"
#include "ipv6.h"
#include "script.h"
/* Debugging Router Solicitations is a lot of spam, so disable it */
-//#define DEBUG_RS
+// #define DEBUG_RS
#ifndef ND_RA_FLAG_HOME_AGENT
-#define ND_RA_FLAG_HOME_AGENT 0x20 /* Home Agent flag in RA */
+#define ND_RA_FLAG_HOME_AGENT 0x20 /* Home Agent flag in RA */
#endif
#ifndef ND_RA_FLAG_PROXY
-#define ND_RA_FLAG_PROXY 0x04 /* Proxy */
+#define ND_RA_FLAG_PROXY 0x04 /* Proxy */
#endif
#ifndef ND_OPT_PI_FLAG_ROUTER
-#define ND_OPT_PI_FLAG_ROUTER 0x20 /* Router flag in PI */
+#define ND_OPT_PI_FLAG_ROUTER 0x20 /* Router flag in PI */
#endif
#ifndef ND_OPT_RI
-#define ND_OPT_RI 24
-struct nd_opt_ri { /* Route Information option RFC4191 */
- uint8_t nd_opt_ri_type;
- uint8_t nd_opt_ri_len;
- uint8_t nd_opt_ri_prefixlen;
- uint8_t nd_opt_ri_flags_reserved;
+#define ND_OPT_RI 24
+struct nd_opt_ri { /* Route Information option RFC4191 */
+ uint8_t nd_opt_ri_type;
+ uint8_t nd_opt_ri_len;
+ uint8_t nd_opt_ri_prefixlen;
+ uint8_t nd_opt_ri_flags_reserved;
uint32_t nd_opt_ri_lifetime;
struct in6_addr nd_opt_ri_prefix;
};
#endif
#ifndef ND_OPT_RDNSS
-#define ND_OPT_RDNSS 25
-struct nd_opt_rdnss { /* RDNSS option RFC 6106 */
- uint8_t nd_opt_rdnss_type;
- uint8_t nd_opt_rdnss_len;
- uint16_t nd_opt_rdnss_reserved;
- uint32_t nd_opt_rdnss_lifetime;
+#define ND_OPT_RDNSS 25
+struct nd_opt_rdnss { /* RDNSS option RFC 6106 */
+ uint8_t nd_opt_rdnss_type;
+ uint8_t nd_opt_rdnss_len;
+ uint16_t nd_opt_rdnss_reserved;
+ uint32_t nd_opt_rdnss_lifetime;
/* followed by list of IP prefixes */
};
__CTASSERT(sizeof(struct nd_opt_rdnss) == 8);
#endif
#ifndef ND_OPT_DNSSL
-#define ND_OPT_DNSSL 31
-struct nd_opt_dnssl { /* DNSSL option RFC 6106 */
- uint8_t nd_opt_dnssl_type;
- uint8_t nd_opt_dnssl_len;
- uint16_t nd_opt_dnssl_reserved;
- uint32_t nd_opt_dnssl_lifetime;
+#define ND_OPT_DNSSL 31
+struct nd_opt_dnssl { /* DNSSL option RFC 6106 */
+ uint8_t nd_opt_dnssl_type;
+ uint8_t nd_opt_dnssl_len;
+ uint16_t nd_opt_dnssl_reserved;
+ uint32_t nd_opt_dnssl_lifetime;
/* followed by list of DNS servers */
};
__CTASSERT(sizeof(struct nd_opt_dnssl) == 8);
#endif
/* Impossible options, so we can easily add extras */
-#define _ND_OPT_PREFIX_ADDR 255 + 1
+#define _ND_OPT_PREFIX_ADDR 255 + 1
/* Minimal IPv6 MTU */
#ifndef IPV6_MMTU
#endif
#ifndef ND_RA_FLAG_RTPREF_HIGH
-#define ND_RA_FLAG_RTPREF_MASK 0x18
-#define ND_RA_FLAG_RTPREF_HIGH 0x08
-#define ND_RA_FLAG_RTPREF_MEDIUM 0x00
-#define ND_RA_FLAG_RTPREF_LOW 0x18
-#define ND_RA_FLAG_RTPREF_RSV 0x10
+#define ND_RA_FLAG_RTPREF_MASK 0x18
+#define ND_RA_FLAG_RTPREF_HIGH 0x08
+#define ND_RA_FLAG_RTPREF_MEDIUM 0x00
+#define ND_RA_FLAG_RTPREF_LOW 0x18
+#define ND_RA_FLAG_RTPREF_RSV 0x10
#endif
-#define EXPIRED_MAX 5 /* Remember 5 expired routers to avoid
- logspam. */
+#define EXPIRED_MAX \
+ 5 /* Remember 5 expired routers to avoid \
+ logspam. */
-#define MIN_RANDOM_FACTOR 500 /* millisecs */
-#define MAX_RANDOM_FACTOR 1500 /* millisecs */
-#define MIN_RANDOM_FACTOR_U MIN_RANDOM_FACTOR * 1000 /* usecs */
-#define MAX_RANDOM_FACTOR_U MAX_RANDOM_FACTOR * 1000 /* usecs */
+#define MIN_RANDOM_FACTOR 500 /* millisecs */
+#define MAX_RANDOM_FACTOR 1500 /* millisecs */
+#define MIN_RANDOM_FACTOR_U MIN_RANDOM_FACTOR * 1000 /* usecs */
+#define MAX_RANDOM_FACTOR_U MAX_RANDOM_FACTOR * 1000 /* usecs */
#if BYTE_ORDER == BIG_ENDIAN
-#define IPV6_ADDR_INT32_ONE 1
-#define IPV6_ADDR_INT16_MLL 0xff02
+#define IPV6_ADDR_INT32_ONE 1
+#define IPV6_ADDR_INT16_MLL 0xff02
#elif BYTE_ORDER == LITTLE_ENDIAN
-#define IPV6_ADDR_INT32_ONE 0x01000000
-#define IPV6_ADDR_INT16_MLL 0x02ff
+#define IPV6_ADDR_INT32_ONE 0x01000000
+#define IPV6_ADDR_INT16_MLL 0x02ff
#endif
/* Debugging Neighbor Solicitations is a lot of spam, so disable it */
-//#define DEBUG_NS
+// #define DEBUG_NS
//
static void ipv6nd_handledata(void *, unsigned short);
-static struct routeinfo *routeinfo_findalloc(struct ra *, const struct in6_addr *, uint8_t);
+static struct routeinfo *routeinfo_findalloc(struct ra *,
+ const struct in6_addr *, uint8_t);
static void routeinfohead_free(struct routeinfohead *);
/*
#define ICMP6_FILTER_SETPASS(type, filterp) \
((((filterp)->icmp6_filt[(type) >> 5]) &= ~(1 << ((type) & 31))))
#define ICMP6_FILTER_SETBLOCK(type, filterp) \
- ((((filterp)->icmp6_filt[(type) >> 5]) |= (1 << ((type) & 31))))
+ ((((filterp)->icmp6_filt[(type) >> 5]) |= (1 << ((type) & 31))))
#define ICMP6_FILTER_SETPASSALL(filterp) \
memset(filterp, 0, sizeof(struct icmp6_filter));
#define ICMP6_FILTER_SETBLOCKALL(filterp) \
#endif
/* Handy defines */
-#define ipv6nd_free_ra(ra) ipv6nd_freedrop_ra((ra), 0)
-#define ipv6nd_drop_ra(ra) ipv6nd_freedrop_ra((ra), 1)
+#define ipv6nd_free_ra(ra) ipv6nd_freedrop_ra((ra), 0)
+#define ipv6nd_drop_ra(ra) ipv6nd_freedrop_ra((ra), 1)
/* Clear these addrflags on receipt of a new RA before adding the new flags
* dervived from the RA. */
(IPV6_AF_ONLINK | IPV6_AF_AUTOCONF | IPV6_AF_ROUTER | IPV6_AF_STALE)
void
-ipv6nd_printoptions(const struct dhcpcd_ctx *ctx,
- const struct dhcp_opt *opts, size_t opts_len)
+ipv6nd_printoptions(const struct dhcpcd_ctx *ctx, const struct dhcp_opt *opts,
+ size_t opts_len)
{
size_t i, j;
const struct dhcp_opt *opt, *opt2;
int cols;
- for (i = 0, opt = ctx->nd_opts;
- i < ctx->nd_opts_len; i++, opt++)
- {
+ for (i = 0, opt = ctx->nd_opts; i < ctx->nd_opts_len; i++, opt++) {
for (j = 0, opt2 = opts; j < opts_len; j++, opt2++)
if (opt2->option == opt->option)
break;
/* RFC4861 4.1 */
on = 255;
- if (setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS,
- &on, sizeof(on)) == -1)
+ if (setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, &on,
+ sizeof(on)) == -1)
goto eexit;
if (recv) {
on = 1;
- if (setsockopt(fd, IPPROTO_IPV6, IPV6_RECVPKTINFO,
- &on, sizeof(on)) == -1)
+ if (setsockopt(fd, IPPROTO_IPV6, IPV6_RECVPKTINFO, &on,
+ sizeof(on)) == -1)
goto eexit;
on = 1;
- if (setsockopt(fd, IPPROTO_IPV6, IPV6_RECVHOPLIMIT,
- &on, sizeof(on)) == -1)
+ if (setsockopt(fd, IPPROTO_IPV6, IPV6_RECVHOPLIMIT, &on,
+ sizeof(on)) == -1)
goto eexit;
ICMP6_FILTER_SETPASS(ND_ROUTER_ADVERT, &filt);
#ifdef SO_RERROR
on = 1;
- if (setsockopt(fd, SOL_SOCKET, SO_RERROR,
- &on, sizeof(on)) == -1)
+ if (setsockopt(fd, SOL_SOCKET, SO_RERROR, &on, sizeof(on)) ==
+ -1)
goto eexit;
#endif
}
- if (setsockopt(fd, IPPROTO_ICMPV6, ICMP6_FILTER,
- &filt, sizeof(filt)) == -1)
+ if (setsockopt(fd, IPPROTO_ICMPV6, ICMP6_FILTER, &filt, sizeof(filt)) ==
+ -1)
goto eexit;
return fd;
{
int fd;
struct ipv6_mreq mreq = {
- .ipv6mr_multiaddr = IN6ADDR_LINKLOCAL_ALLNODES_INIT,
- .ipv6mr_interface = ifp->index
+ .ipv6mr_multiaddr = IN6ADDR_LINKLOCAL_ALLNODES_INIT,
+ .ipv6mr_interface = ifp->index
};
struct rs_state *state = RS_STATE(ifp);
uint_t ifindex = ifp->index;
if (fd == -1)
return -1;
- if (setsockopt(fd, IPPROTO_IPV6, IPV6_BOUND_IF,
- &ifindex, sizeof(ifindex)) == -1)
- {
+ if (setsockopt(fd, IPPROTO_IPV6, IPV6_BOUND_IF, &ifindex,
+ sizeof(ifindex)) == -1) {
close(fd);
return -1;
}
- if (setsockopt(fd, IPPROTO_IPV6, IPV6_JOIN_GROUP,
- &mreq, sizeof(mreq)) == -1)
- {
+ if (setsockopt(fd, IPPROTO_IPV6, IPV6_JOIN_GROUP, &mreq,
+ sizeof(mreq)) == -1) {
close(fd);
return -1;
}
- if (eloop_event_add(ifp->ctx->eloop, fd, ELE_READ,
- ipv6nd_handledata, ifp) == -1)
- {
+ if (eloop_event_add(ifp->ctx->eloop, fd, ELE_READ, ipv6nd_handledata,
+ ifp) == -1) {
close(fd);
return -1;
}
return -1;
rs = state->rs;
rs->nd_rs_type = ND_ROUTER_SOLICIT;
- //rs->nd_rs_code = 0;
- //rs->nd_rs_cksum = 0;
- //rs->nd_rs_reserved = 0;
+ // rs->nd_rs_code = 0;
+ // rs->nd_rs_cksum = 0;
+ // rs->nd_rs_reserved = 0;
if (ifp->hwlen != 0) {
struct nd_opt_hdr *nd;
uint8_t buf[CMSG_SPACE(sizeof(struct in6_pktinfo))];
} cmsgbuf = { .buf = { 0 } };
struct msghdr msg = {
- .msg_name = &dst, .msg_namelen = sizeof(dst),
- .msg_iov = &iov, .msg_iovlen = 1,
- .msg_control = cmsgbuf.buf, .msg_controllen = sizeof(cmsgbuf.buf),
+ .msg_name = &dst,
+ .msg_namelen = sizeof(dst),
+ .msg_iov = &iov,
+ .msg_iovlen = 1,
+ .msg_control = cmsgbuf.buf,
+ .msg_controllen = sizeof(cmsgbuf.buf),
};
struct cmsghdr *cm;
struct in6_pktinfo pi = { .ipi6_ifindex = ifp->index };
return;
}
if (eloop_event_add(ctx->eloop, ctx->nd_fd, ELE_READ,
- ipv6nd_handledata, ctx) == -1)
+ ipv6nd_handledata, ctx) == -1)
logerr("%s: eloop_event_add", __func__);
}
s = ifp->ctx->nd_fd;
int
ipv6nd_rtpref(uint8_t flags)
{
-
switch (flags & ND_RA_FLAG_RTPREF_MASK) {
case ND_RA_FLAG_RTPREF_HIGH:
return RTPREF_HIGH;
continue;
if (!ra1->isreachable && ra2->isreachable)
continue;
- if (ipv6nd_rtpref(ra1->flags) <= ipv6nd_rtpref(ra2->flags))
+ if (ipv6nd_rtpref(ra1->flags) <=
+ ipv6nd_rtpref(ra2->flags))
continue;
/* All things being equal, prefer older routers. */
/* We don't need to check time, becase newer
struct rs_state *state = RS_STATE(ifp);
struct ra defra = {
.iface = ifp,
- .hoplimit = IPV6_DEFHLIM ,
+ .hoplimit = IPV6_DEFHLIM,
.reachable = REACHABLE_TIME,
.retrans = RETRANS_TIMER,
};
}
static struct ipv6_addr *
-ipv6nd_rapfindprefix(struct ra *rap,
- const struct in6_addr *pfx, uint8_t pfxlen)
+ipv6nd_rapfindprefix(struct ra *rap, const struct in6_addr *pfx, uint8_t pfxlen)
{
struct ipv6_addr *ia;
}
struct ipv6_addr *
-ipv6nd_iffindprefix(struct interface *ifp,
- const struct in6_addr *pfx, uint8_t pfxlen)
+ipv6nd_iffindprefix(struct interface *ifp, const struct in6_addr *pfx,
+ uint8_t pfxlen)
{
struct ra *rap;
struct ipv6_addr *ia;
static void
ipv6nd_freedrop_ra(struct ra *rap, int drop)
{
-
ipv6nd_removefreedrop_ra(rap, 1, drop);
}
/* If all addresses have completed DAD run the script */
TAILQ_FOREACH(ap, &rap->addrs, next) {
if ((ap->flags & (IPV6_AF_AUTOCONF | IPV6_AF_ADDED)) ==
- (IPV6_AF_AUTOCONF | IPV6_AF_ADDED))
- {
+ (IPV6_AF_AUTOCONF | IPV6_AF_ADDED)) {
hasaddress = 1;
if (!(ap->flags & IPV6_AF_DADCOMPLETED) &&
ipv6_iffindaddr(ap->iface, &ap->addr,
- IN6_IFF_TENTATIVE))
+ IN6_IFF_TENTATIVE))
ap->flags |= IPV6_AF_DADCOMPLETED;
if ((ap->flags & IPV6_AF_DADCOMPLETED) == 0) {
logdebugx("%s: waiting for Router Advertisement"
- " DAD to complete",
+ " DAD to complete",
rap->iface->name);
return;
}
}
script_runreason(rap->iface, "ROUTERADVERT");
- if (hasdns && (hasaddress ||
- !(rap->flags & (ND_RA_FLAG_MANAGED | ND_RA_FLAG_OTHER))))
+ if (hasdns &&
+ (hasaddress ||
+ !(rap->flags & (ND_RA_FLAG_MANAGED | ND_RA_FLAG_OTHER))))
dhcpcd_daemonise(rap->iface->ctx);
#if 0
else if (options & DHCPCD_DAEMONISE &&
* a different address is generated. */
/* XXX Cache DAD counter per prefix/id/ssid? */
if (ifp->options->options & DHCPCD_SLAACPRIVATE &&
- IA6_CANAUTOCONF(ia))
- {
+ IA6_CANAUTOCONF(ia)) {
unsigned int delay;
if (ia->dadcounter >= IDGEN_RETRIES) {
logerrx("%s: unable to obtain a"
- " stable private address",
+ " stable private address",
ifp->name);
goto try_script;
}
- loginfox("%s: deleting address %s",
- ifp->name, ia->saddr);
+ loginfox("%s: deleting address %s", ifp->name,
+ ia->saddr);
if (if_address6(RTM_DELADDR, ia) == -1 &&
errno != EADDRNOTAVAIL && errno != ENXIO)
logerr(__func__);
dadcounter = ia->dadcounter;
- if (ipv6_makestableprivate(&ia->addr,
- &ia->prefix, ia->prefix_len,
- ifp, &dadcounter) == -1)
- {
+ if (ipv6_makestableprivate(&ia->addr, &ia->prefix,
+ ia->prefix_len, ifp, &dadcounter) == -1) {
logerr("ipv6_makestableprivate");
return;
}
ia->flags |= IPV6_AF_NEW;
p = inet_ntop(AF_INET6, &ia->addr, buf, sizeof(buf));
if (p)
- snprintf(ia->saddr,
- sizeof(ia->saddr),
- "%s/%d",
+ snprintf(ia->saddr, sizeof(ia->saddr), "%s/%d",
p, ia->prefix_len);
else
ia->saddr[0] = '\0';
TAILQ_FOREACH(rapap, &rap->addrs, next) {
if (rapap->flags & IPV6_AF_AUTOCONF &&
rapap->flags & IPV6_AF_ADDED &&
- (rapap->flags & IPV6_AF_DADCOMPLETED) == 0)
- {
+ (rapap->flags & IPV6_AF_DADCOMPLETED) ==
+ 0) {
wascompleted = 0;
break;
}
if (wascompleted && found) {
logdebugx("%s: Router Advertisement DAD "
- "completed",
+ "completed",
rap->iface->name);
ipv6nd_scriptrun(rap);
}
struct ipv6_addr *ia2;
TAILQ_FOREACH(rap2, ctx->ra_routers, next) {
- if (rap2 == rap ||
- rap2->iface != rap->iface ||
- rap2->expired)
+ if (rap2 == rap || rap2->iface != rap->iface || rap2->expired)
continue;
TAILQ_FOREACH(ia2, &rap2->addrs, next) {
if (!IN6_ARE_ADDR_EQUAL(&ia->prefix, &ia2->prefix))
static int
dhcp6_start(__unused struct interface *ifp, __unused enum DH6S init_state)
{
-
errno = ENOTSUP;
return -1;
}
#endif
static void
-ipv6nd_handlera(struct dhcpcd_ctx *ctx,
- const struct sockaddr_in6 *from, const char *sfrom,
- struct interface *ifp, struct icmp6_hdr *icp, size_t len, int hoplimit)
+ipv6nd_handlera(struct dhcpcd_ctx *ctx, const struct sockaddr_in6 *from,
+ const char *sfrom, struct interface *ifp, struct icmp6_hdr *icp, size_t len,
+ int hoplimit)
{
size_t i, olen;
struct nd_router_advert *nd_ra;
bool new_ia;
#endif
-#define FREE_RAP(rap) \
- if (new_rap) \
- ipv6nd_removefreedrop_ra(rap, 0, 0); \
- else \
- ipv6nd_free_ra(rap); \
+#define FREE_RAP(rap) \
+ if (new_rap) \
+ ipv6nd_removefreedrop_ra(rap, 0, 0); \
+ else \
+ ipv6nd_free_ra(rap);
if (ifp == NULL || RS_STATE(ifp) == NULL) {
#ifdef DEBUG_RS
/* We could receive a RA before we sent a RS*/
if (ipv6_linklocal(ifp) == NULL) {
#ifdef DEBUG_RS
- logdebugx("%s: received RA from %s (no link-local)",
- ifp->name, sfrom);
+ logdebugx("%s: received RA from %s (no link-local)", ifp->name,
+ sfrom);
#endif
return;
}
if (ipv6_iffindaddr(ifp, &from->sin6_addr, IN6_IFF_TENTATIVE)) {
- logdebugx("%s: ignoring RA from ourself %s",
- ifp->name, sfrom);
+ logdebugx("%s: ignoring RA from ourself %s", ifp->name, sfrom);
return;
}
/* We don't want to spam the log with the fact we got an RA every
* 30 seconds or so, so only spam the log if it's different. */
- if (rap == NULL || (rap->data_len != len ||
- memcmp(rap->data, (unsigned char *)icp, rap->data_len) != 0))
- {
+ if (rap == NULL ||
+ (rap->data_len != len ||
+ memcmp(rap->data, (unsigned char *)icp, rap->data_len) != 0)) {
if (rap) {
free(rap->data);
rap->data_len = 0;
* much needless log spam. */
if (rap->willexpire)
new_data = true;
- loglevel = new_rap || rap->willexpire || !rap->isreachable ?
- LOG_INFO : LOG_DEBUG;
- logmessage(loglevel, "%s: Router Advertisement from %s",
- ifp->name, rap->sfrom);
+ loglevel = new_rap || rap->willexpire || !rap->isreachable ? LOG_INFO :
+ LOG_DEBUG;
+ logmessage(loglevel, "%s: Router Advertisement from %s", ifp->name,
+ rap->sfrom);
clock_gettime(CLOCK_MONOTONIC, &rap->acquired);
rap->flags = nd_ra->nd_ra_flags_reserved;
return;
}
if (olen > len) {
- logerrx("%s: option length exceeds message",
- ifp->name);
+ logerrx("%s: option length exceeds message", ifp->name);
break;
}
if (has_option_mask(ifp->options->rejectmasknd,
- ndo.nd_opt_type))
- {
- for (i = 0, dho = ctx->nd_opts;
- i < ctx->nd_opts_len;
- i++, dho++)
- {
+ ndo.nd_opt_type)) {
+ for (i = 0, dho = ctx->nd_opts; i < ctx->nd_opts_len;
+ i++, dho++) {
if (dho->option == ndo.nd_opt_type)
break;
}
continue;
switch (ndo.nd_opt_type) {
- case ND_OPT_PREFIX_INFORMATION:
- {
+ case ND_OPT_PREFIX_INFORMATION: {
uint32_t vltime, pltime;
loglevel = new_data ? LOG_ERR : LOG_DEBUG;
memcpy(&pi_prefix, &pi.nd_opt_pi_prefix,
sizeof(pi_prefix));
if (IN6_IS_ADDR_MULTICAST(&pi_prefix) ||
- IN6_IS_ADDR_LINKLOCAL(&pi_prefix))
- {
+ IN6_IS_ADDR_LINKLOCAL(&pi_prefix)) {
logmessage(loglevel, "%s: invalid prefix in RA",
ifp->name);
continue;
flags |= IPV6_AF_ONLINK;
if (pi.nd_opt_pi_flags_reserved & ND_OPT_PI_FLAG_AUTO &&
rap->iface->options->options &
- DHCPCD_IPV6RA_AUTOCONF)
+ DHCPCD_IPV6RA_AUTOCONF)
flags |= IPV6_AF_AUTOCONF;
if (pi.nd_opt_pi_flags_reserved & ND_OPT_PI_FLAG_ROUTER)
flags |= IPV6_AF_ROUTER;
- ia = ipv6nd_rapfindprefix(rap,
- &pi_prefix, pi.nd_opt_pi_prefix_len);
+ ia = ipv6nd_rapfindprefix(rap, &pi_prefix,
+ pi.nd_opt_pi_prefix_len);
if (ia == NULL) {
- ia = ipv6_newaddr(rap->iface,
- &pi_prefix, pi.nd_opt_pi_prefix_len, flags);
+ ia = ipv6_newaddr(rap->iface, &pi_prefix,
+ pi.nd_opt_pi_prefix_len, flags);
if (ia == NULL)
break;
* create a new one */
if (flags & IPV6_AF_AUTOCONF &&
ipv6_iffindaddr(ifp, &ia->addr,
- IN6_IFF_NOTUSEABLE) &&
+ IN6_IFF_NOTUSEABLE) &&
ipv6_settemptime(ia, 0))
new_ia = false;
else
if (ia->prefix_vltime) {
uint32_t elapsed;
- elapsed = (uint32_t)eloop_timespec_diff(
- &rap->acquired, &ia->acquired,
- NULL);
+ elapsed = (uint32_t)
+ eloop_timespec_diff(&rap->acquired,
+ &ia->acquired, NULL);
rmtime = ia->prefix_vltime - elapsed;
if (rmtime > ia->prefix_vltime)
rmtime = 0;
/* RFC4941 Section 3.3.3 */
if (ia->flags & IPV6_AF_AUTOCONF &&
ia->iface->options->options & DHCPCD_SLAACTEMP &&
- IA6_CANAUTOCONF(ia))
- {
+ IA6_CANAUTOCONF(ia)) {
if (!new_ia) {
if (ipv6_settemptime(ia, 1) == NULL)
new_ia = true;
}
if (new_ia && ia->prefix_pltime) {
if (ipv6_createtempaddr(ia,
- &ia->acquired) == NULL)
+ &ia->acquired) == NULL)
logerr("ipv6_createtempaddr");
}
}
case ND_OPT_MTU:
if (len < sizeof(mtu)) {
- logmessage(loglevel, "%s: short MTU option", ifp->name);
+ logmessage(loglevel, "%s: short MTU option",
+ ifp->name);
break;
}
memcpy(&mtu, p, sizeof(mtu));
if (ifmtu == -1)
logerr("if_getmtu");
else if (mtu.nd_opt_mtu_mtu > (uint32_t)ifmtu) {
- logmessage(loglevel, "%s: advertised MTU %d"
+ logmessage(loglevel,
+ "%s: advertised MTU %d"
" is greater than link MTU %d",
ifp->name, mtu.nd_opt_mtu_mtu, ifmtu);
rap->mtu = (uint32_t)ifmtu;
break;
case ND_OPT_RDNSS:
if (len < sizeof(rdnss)) {
- logmessage(loglevel, "%s: short RDNSS option", ifp->name);
+ logmessage(loglevel, "%s: short RDNSS option",
+ ifp->name);
break;
}
memcpy(&rdnss, p, sizeof(rdnss));
break;
case ND_OPT_RI:
if (ndo.nd_opt_len > 3) {
- logmessage(loglevel, "%s: invalid route info option",
- ifp->name);
+ logmessage(loglevel,
+ "%s: invalid route info option", ifp->name);
break;
}
memset(&ri, 0, sizeof(ri));
- memcpy(&ri, p, olen); /* may be smaller than sizeof(ri), pad with zero */
- if(ri.nd_opt_ri_prefixlen > 128) {
- logmessage(loglevel, "%s: invalid route info prefix length",
+ memcpy(&ri, p, olen); /* may be smaller than sizeof(ri),
+ pad with zero */
+ if (ri.nd_opt_ri_prefixlen > 128) {
+ logmessage(loglevel,
+ "%s: invalid route info prefix length",
ifp->name);
break;
}
/* rfc4191 3.1 - RI for ::/0 applies to default route */
- if(ri.nd_opt_ri_prefixlen == 0) {
+ if (ri.nd_opt_ri_prefixlen == 0) {
rap->lifetime = ntohl(ri.nd_opt_ri_lifetime);
- /* Update preference leaving other flags intact */
- rap->flags = ((rap->flags & (~ (unsigned int)ND_RA_FLAG_RTPREF_MASK))
- | ri.nd_opt_ri_flags_reserved) & 0xff;
+ /* Update preference leaving other flags intact
+ */
+ rap->flags =
+ ((rap->flags &
+ (~(unsigned int)
+ ND_RA_FLAG_RTPREF_MASK)) |
+ ri.nd_opt_ri_flags_reserved) &
+ 0xff;
break;
}
- /* Update existing route info instead of rebuilding all routes so that
- previously announced but now absent routes can stay alive. To kill a
- route early, an RI with lifetime=0 needs to be received (rfc4191 3.1)*/
- rinfo = routeinfo_findalloc(rap, &ri.nd_opt_ri_prefix, ri.nd_opt_ri_prefixlen);
- if(rinfo == NULL) {
+ /* Update existing route info instead of rebuilding all
+ routes so that previously announced but now absent
+ routes can stay alive. To kill a route early, an RI
+ with lifetime=0 needs to be received (rfc4191 3.1)*/
+ rinfo = routeinfo_findalloc(rap, &ri.nd_opt_ri_prefix,
+ ri.nd_opt_ri_prefixlen);
+ if (rinfo == NULL) {
logerr(__func__);
break;
}
}
}
- for (i = 0, dho = ctx->nd_opts;
- i < ctx->nd_opts_len;
- i++, dho++)
- {
- if (has_option_mask(ifp->options->requiremasknd,
- dho->option))
- {
+ for (i = 0, dho = ctx->nd_opts; i < ctx->nd_opts_len; i++, dho++) {
+ if (has_option_mask(ifp->options->requiremasknd, dho->option)) {
logwarnx("%s: reject RA (no option %s) from %s",
ifp->name, dho->var, rap->sfrom);
FREE_RAP(rap);
goto nodhcp6;
/* Only log a DHCPv6 start error if compiled in or debugging is enabled. */
#ifdef DHCP6
-#define LOG_DHCP6 logerr
+#define LOG_DHCP6 logerr
#else
-#define LOG_DHCP6 logdebug
+#define LOG_DHCP6 logdebug
#endif
if (rap->flags & ND_RA_FLAG_MANAGED) {
if (new_data && dhcp6_start(ifp, DH6S_REQUEST) == -1)
if (new_data)
logdebugx("%s: No DHCPv6 instruction in RA", ifp->name);
#endif
-nodhcp6:
+ nodhcp6:
if (ifp->ctx->options & DHCPCD_TEST) {
eloop_exit(ifp->ctx->eloop, EXIT_SUCCESS);
return;
if (ifp->ctx->ra_routers) {
TAILQ_FOREACH(rap, ifp->ctx->ra_routers, next)
- if (rap->iface == ifp &&
- !rap->expired &&
- (!lifetime ||rap->lifetime))
+ if (rap->iface == ifp && !rap->expired &&
+ (!lifetime || rap->lifetime))
return true;
}
return false;
if (ifp->ctx->ra_routers) {
TAILQ_FOREACH(rap, ifp->ctx->ra_routers, next) {
- if (rap->iface == ifp &&
- !rap->expired && !rap->willexpire &&
+ if (rap->iface == ifp && !rap->expired &&
+ !rap->willexpire &&
((managed && rap->flags & ND_RA_FLAG_MANAGED) ||
- (!managed && rap->flags & ND_RA_FLAG_OTHER)))
+ (!managed && rap->flags & ND_RA_FLAG_OTHER)))
return true;
}
}
}
static const uint8_t *
-ipv6nd_getoption(struct dhcpcd_ctx *ctx,
- size_t *os, unsigned int *code, size_t *len,
- const uint8_t *od, size_t ol, struct dhcp_opt **oopt)
+ipv6nd_getoption(struct dhcpcd_ctx *ctx, size_t *os, unsigned int *code,
+ size_t *len, const uint8_t *od, size_t ol, struct dhcp_opt **oopt)
{
struct nd_opt_hdr ndo;
size_t i;
*code = ndo.nd_opt_type;
}
- for (i = 0, opt = ctx->nd_opts;
- i < ctx->nd_opts_len; i++, opt++)
- {
+ for (i = 0, opt = ctx->nd_opts; i < ctx->nd_opts_len; i++, opt++) {
if (opt->option == *code) {
*oopt = opt;
break;
if (efprintf(fp, "%s_from=%s", ndprefix, rap->sfrom) == -1)
return -1;
if (efprintf(fp, "%s_acquired=%lld", ndprefix,
- (long long)rap->acquired.tv_sec) == -1)
+ (long long)rap->acquired.tv_sec) == -1)
return -1;
if (efprintf(fp, "%s_now=%lld", ndprefix,
- (long long)now.tv_sec) == -1)
+ (long long)now.tv_sec) == -1)
return -1;
- if (efprintf(fp, "%s_hoplimit=%u", ndprefix, rap->hoplimit) == -1)
+ if (efprintf(fp, "%s_hoplimit=%u", ndprefix, rap->hoplimit) ==
+ -1)
return -1;
pref = ipv6nd_rtpref(rap->flags);
if (efprintf(fp, "%s_flags=%s%s%s%s%s", ndprefix,
- rap->flags & ND_RA_FLAG_MANAGED ? "M" : "",
- rap->flags & ND_RA_FLAG_OTHER ? "O" : "",
- rap->flags & ND_RA_FLAG_HOME_AGENT ? "H" : "",
- pref == RTPREF_HIGH ? "h" : pref == RTPREF_LOW ? "l" : "",
- rap->flags & ND_RA_FLAG_PROXY ? "P" : "") == -1)
+ rap->flags & ND_RA_FLAG_MANAGED ? "M" : "",
+ rap->flags & ND_RA_FLAG_OTHER ? "O" : "",
+ rap->flags & ND_RA_FLAG_HOME_AGENT ? "H" : "",
+ pref == RTPREF_HIGH ? "h" :
+ pref == RTPREF_LOW ? "l" :
+ "",
+ rap->flags & ND_RA_FLAG_PROXY ? "P" : "") == -1)
return -1;
- if (efprintf(fp, "%s_lifetime=%u", ndprefix, rap->lifetime) == -1)
+ if (efprintf(fp, "%s_lifetime=%u", ndprefix, rap->lifetime) ==
+ -1)
return -1;
/* Zero our indexes */
for (j = 0, opt = rap->iface->ctx->nd_opts;
- j < rap->iface->ctx->nd_opts_len;
- j++, opt++)
+ j < rap->iface->ctx->nd_opts_len; j++, opt++)
dhcp_zero_index(opt);
for (j = 0, opt = rap->iface->options->nd_override;
- j < rap->iface->options->nd_override_len;
- j++, opt++)
+ j < rap->iface->options->nd_override_len; j++, opt++)
dhcp_zero_index(opt);
/* Unlike DHCP, ND6 options *may* occur more than once.
* unlike DHCP. */
len = rap->data_len - sizeof(struct nd_router_advert);
for (p = rap->data + sizeof(struct nd_router_advert);
- len >= sizeof(ndo);
- p += olen, len -= olen)
- {
+ len >= sizeof(ndo); p += olen, len -= olen) {
memcpy(&ndo, p, sizeof(ndo));
olen = (size_t)(ndo.nd_opt_len * 8);
if (olen > len) {
- errno = EINVAL;
+ errno = EINVAL;
break;
}
if (has_option_mask(rap->iface->options->nomasknd,
- ndo.nd_opt_type))
+ ndo.nd_opt_type))
continue;
for (j = 0, opt = rap->iface->options->nd_override;
j < rap->iface->options->nd_override_len;
}
if (opt == NULL)
continue;
- dhcp_envoption(rap->iface->ctx, fp,
- ndprefix, rap->iface->name,
- opt, ipv6nd_getoption,
+ dhcp_envoption(rap->iface->ctx, fp, ndprefix,
+ rap->iface->name, opt, ipv6nd_getoption,
p + sizeof(ndo), olen - sizeof(ndo));
}
!(ia->flags & IPV6_AF_ADDED) ||
ia->prefix_vltime == 0)
continue;
- if (efprintf(fp, "%s_addr%zu=%s",
- ndprefix, ++j, ia->saddr) == -1)
+ if (efprintf(fp, "%s_addr%zu=%s", ndprefix, ++j,
+ ia->saddr) == -1)
return -1;
}
}
if (rap->iface != ifp || rap->expired)
continue;
valid = false;
- /* lifetime may be set to infinite by rfc4191 route information */
+ /* lifetime may be set to infinite by rfc4191 route information
+ */
if (rap->lifetime) {
- ltime = lifetime_left(rap->lifetime,
- &rap->acquired, &now);
+ ltime = lifetime_left(rap->lifetime, &rap->acquired,
+ &now);
if (ltime == 0 || rap->doexpire) {
if (!rap->expired) {
logwarnx("%s: %s: router expired",
TAILQ_FOREACH(ia, &rap->addrs, next) {
if (ia->prefix_vltime == 0)
continue;
- ltime = lifetime_left(ia->prefix_vltime,
- &ia->acquired, &now);
+ ltime = lifetime_left(ia->prefix_vltime, &ia->acquired,
+ &now);
if (ltime == 0 || rap->doexpire) {
if (ia->flags & IPV6_AF_ADDED) {
logwarnx("%s: expired %s %s",
ia->iface->name,
ia->flags & IPV6_AF_AUTOCONF ?
- "address" : "prefix",
+ "address" :
+ "prefix",
ia->saddr);
- if (if_address6(RTM_DELADDR, ia)== -1 &&
+ if (if_address6(RTM_DELADDR, ia) ==
+ -1 &&
errno != EADDRNOTAVAIL &&
errno != ENXIO)
logerr(__func__);
}
ia->prefix_vltime = ia->prefix_pltime = 0;
- ia->flags &=
- ~(IPV6_AF_ADDED | IPV6_AF_DADCOMPLETED);
+ ia->flags &= ~(
+ IPV6_AF_ADDED | IPV6_AF_DADCOMPLETED);
expired = true;
} else {
valid = true;
/* Expire route information */
TAILQ_FOREACH_SAFE(rinfo, &rap->rinfos, next, rinfob) {
- ltime = lifetime_left(rinfo->lifetime,
- &rinfo->acquired, &now);
+ ltime = lifetime_left(rinfo->lifetime, &rinfo->acquired,
+ &now);
if (ltime == 0 || rap->doexpire) {
logwarnx("%s: expired route %s",
rap->iface->name, rinfo->sprefix);
}
/* Work out expiry for ND options */
- elapsed = (uint32_t)eloop_timespec_diff(&now,
- &rap->acquired, NULL);
+ elapsed = (uint32_t)eloop_timespec_diff(&now, &rap->acquired,
+ NULL);
len = rap->data_len - sizeof(struct nd_router_advert);
for (p = rap->data + sizeof(struct nd_router_advert);
- len >= sizeof(ndo);
- p += olen, len -= olen)
- {
+ len >= sizeof(ndo); p += olen, len -= olen) {
memcpy(&ndo, p, sizeof(ndo));
olen = (size_t)(ndo.nd_opt_len * 8);
if (olen > len) {
- errno = EINVAL;
+ errno = EINVAL;
break;
}
if (has_option_mask(rap->iface->options->nomasknd,
- ndo.nd_opt_type))
+ ndo.nd_opt_type))
continue;
switch (ndo.nd_opt_type) {
- /* Prefix info is already checked in the above loop. */
+ /* Prefix info is already checked in the above
+ * loop. */
#if 0
case ND_OPT_PREFIX_INFORMATION:
if (len < sizeof(pi))
}
if (next != 0)
- eloop_timeout_add_sec(ifp->ctx->eloop,
- next, ipv6nd_expirera, ifp);
+ eloop_timeout_add_sec(ifp->ctx->eloop, next, ipv6nd_expirera,
+ ifp);
if (expired) {
logwarnx("%s: part of a Router Advertisement expired",
ifp->name);
icp = (struct icmp6_hdr *)msg->msg_iov[0].iov_base;
if (icp->icmp6_code == 0) {
- switch(icp->icmp6_type) {
- case ND_ROUTER_ADVERT:
- ipv6nd_handlera(ctx, from, sfrom,
- ifp, icp, (size_t)len, hoplimit);
- return;
+ switch (icp->icmp6_type) {
+ case ND_ROUTER_ADVERT:
+ ipv6nd_handlera(ctx, from, sfrom, ifp, icp, (size_t)len,
+ hoplimit);
+ return;
}
}
- logerrx("invalid IPv6 type %d or code %d from %s",
- icp->icmp6_type, icp->icmp6_code, sfrom);
+ logerrx("invalid IPv6 type %d or code %d from %s", icp->icmp6_type,
+ icp->icmp6_code, sfrom);
}
static void
uint8_t buf[64 * 1024]; /* Maximum ICMPv6 size */
} iovbuf;
struct iovec iov = {
- .iov_base = iovbuf.buf, .iov_len = sizeof(iovbuf.buf),
+ .iov_base = iovbuf.buf,
+ .iov_len = sizeof(iovbuf.buf),
};
union {
struct cmsghdr hdr;
CMSG_SPACE(sizeof(int))];
} cmsgbuf = { .buf = { 0 } };
struct msghdr msg = {
- .msg_name = &from, .msg_namelen = sizeof(from),
- .msg_iov = &iov, .msg_iovlen = 1,
- .msg_control = cmsgbuf.buf, .msg_controllen = sizeof(cmsgbuf.buf),
+ .msg_name = &from,
+ .msg_namelen = sizeof(from),
+ .msg_iov = &iov,
+ .msg_iovlen = 1,
+ .msg_control = cmsgbuf.buf,
+ .msg_controllen = sizeof(cmsgbuf.buf),
};
ssize_t len;
void
ipv6nd_startrs(struct interface *ifp)
{
-
if (ipv6_linklocal(ifp) == NULL) {
logdebugx("%s: "
- "delaying IPv6 Router Solicitation for LL address",
+ "delaying IPv6 Router Solicitation for LL address",
ifp->name);
ipv6_addlinklocalcallback(ifp, ipv6nd_startrs1, ifp);
} else
void
ipv6nd_abort(struct interface *ifp)
{
-
eloop_timeout_delete(ifp->ctx->eloop, ipv6nd_startrs1, ifp);
eloop_timeout_delete(ifp->ctx->eloop, ipv6nd_startrs2, ifp);
eloop_timeout_delete(ifp->ctx->eloop, ipv6nd_sendrsprobe, ifp);
}
-static struct routeinfo *routeinfo_findalloc(struct ra *rap, const struct in6_addr *prefix, uint8_t prefix_len)
+static struct routeinfo *
+routeinfo_findalloc(struct ra *rap, const struct in6_addr *prefix,
+ uint8_t prefix_len)
{
struct routeinfo *ri;
char buf[INET6_ADDRSTRLEN];
ri->prefix_len = prefix_len;
p = inet_ntop(AF_INET6, prefix, buf, sizeof(buf));
if (p)
- snprintf(ri->sprefix,
- sizeof(ri->sprefix),
- "%s/%d",
- p, prefix_len);
+ snprintf(ri->sprefix, sizeof(ri->sprefix), "%s/%d", p,
+ prefix_len);
else
ri->sprefix[0] = '\0';
TAILQ_INSERT_TAIL(&rap->rinfos, ri, next);
return ri;
}
-static void routeinfohead_free(struct routeinfohead *head)
+static void
+routeinfohead_free(struct routeinfohead *head)
{
struct routeinfo *ri;
TAILQ_HEAD(routeinfohead, routeinfo);
-
struct ra {
TAILQ_ENTRY(ra) next;
struct interface *iface;
#endif
};
-#define RS_STATE(a) ((struct rs_state *)(ifp)->if_data[IF_DATA_IPV6ND])
-#define RS_CSTATE(a) ((const struct rs_state *)(ifp)->if_data[IF_DATA_IPV6ND])
-#define RS_STATE_RUNNING(a) (ipv6nd_hasra((a)) && ipv6nd_dadcompleted((a)))
+#define RS_STATE(a) ((struct rs_state *)(ifp)->if_data[IF_DATA_IPV6ND])
+#define RS_CSTATE(a) ((const struct rs_state *)(ifp)->if_data[IF_DATA_IPV6ND])
+#define RS_STATE_RUNNING(a) (ipv6nd_hasra((a)) && ipv6nd_dadcompleted((a)))
#ifndef MAX_RTR_SOLICITATION_DELAY
-#define MAX_RTR_SOLICITATION_DELAY 1 /* seconds */
-#define MAX_UNICAST_SOLICIT 3 /* 3 transmissions */
-#define RTR_SOLICITATION_INTERVAL 4 /* seconds */
-#define MAX_RTR_SOLICITATIONS 3 /* times */
-#define MAX_NEIGHBOR_ADVERTISEMENT 3 /* 3 transmissions */
+#define MAX_RTR_SOLICITATION_DELAY 1 /* seconds */
+#define MAX_UNICAST_SOLICIT 3 /* 3 transmissions */
+#define RTR_SOLICITATION_INTERVAL 4 /* seconds */
+#define MAX_RTR_SOLICITATIONS 3 /* times */
+#define MAX_NEIGHBOR_ADVERTISEMENT 3 /* 3 transmissions */
#ifndef IPV6_DEFHLIM
-#define IPV6_DEFHLIM 64
+#define IPV6_DEFHLIM 64
#endif
#endif
/* On carrier up, expire known routers after RTR_CARRIER_EXPIRE seconds. */
-#define RTR_CARRIER_EXPIRE \
- (MAX_RTR_SOLICITATION_DELAY + \
- (MAX_RTR_SOLICITATIONS + 1) * \
- RTR_SOLICITATION_INTERVAL)
+#define RTR_CARRIER_EXPIRE \
+ (MAX_RTR_SOLICITATION_DELAY + \
+ (MAX_RTR_SOLICITATIONS + 1) * RTR_SOLICITATION_INTERVAL)
-#define MAX_REACHABLE_TIME 3600000 /* milliseconds */
-#define REACHABLE_TIME 30000 /* milliseconds */
-#define RETRANS_TIMER 1000 /* milliseconds */
-#define DELAY_FIRST_PROBE_TIME 5 /* seconds */
+#define MAX_REACHABLE_TIME 3600000 /* milliseconds */
+#define REACHABLE_TIME 30000 /* milliseconds */
+#define RETRANS_TIMER 1000 /* milliseconds */
+#define DELAY_FIRST_PROBE_TIME 5 /* seconds */
-#define MIN_EXTENDED_VLTIME 7200 /* seconds */
+#define MIN_EXTENDED_VLTIME 7200 /* seconds */
int ipv6nd_open(bool);
#ifdef __sun
#endif
void ipv6nd_recvmsg(struct dhcpcd_ctx *, struct msghdr *);
int ipv6nd_rtpref(uint8_t);
-void ipv6nd_printoptions(const struct dhcpcd_ctx *,
- const struct dhcp_opt *, size_t);
+void ipv6nd_printoptions(const struct dhcpcd_ctx *, const struct dhcp_opt *,
+ size_t);
void ipv6nd_startrs(struct interface *);
ssize_t ipv6nd_env(FILE *, const struct interface *);
const struct ipv6_addr *ipv6nd_iffindaddr(const struct interface *ifp,
const struct in6_addr *addr, unsigned int flags);
-struct ipv6_addr *ipv6nd_findaddr(struct dhcpcd_ctx *,
- const struct in6_addr *, unsigned int);
+struct ipv6_addr *ipv6nd_findaddr(struct dhcpcd_ctx *, const struct in6_addr *,
+ unsigned int);
struct ipv6_addr *ipv6nd_iffindprefix(struct interface *,
const struct in6_addr *, uint8_t);
ssize_t ipv6nd_free(struct interface *);
void ipv6nd_expirera(void *arg);
bool ipv6nd_hasralifetime(const struct interface *, bool);
-#define ipv6nd_hasra(i) ipv6nd_hasralifetime((i), false)
+#define ipv6nd_hasra(i) ipv6nd_hasralifetime((i), false)
bool ipv6nd_hasradhcp(const struct interface *, bool);
void ipv6nd_handleifa(int, struct ipv6_addr *, pid_t);
int ipv6nd_dadcompleted(const struct interface *);
#include <sys/time.h>
#include <errno.h>
-#include <stdbool.h>
#include <stdarg.h>
+#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "logerr.h"
-#ifndef LOGERR_SYSLOG_FACILITY
-#define LOGERR_SYSLOG_FACILITY LOG_DAEMON
+#ifndef LOGERR_SYSLOG_FACILITY
+#define LOGERR_SYSLOG_FACILITY LOG_DAEMON
#endif
#ifdef SMALL
#endif
/* syslog protocol is 1k message max, RFC 3164 section 4.1 */
-#define LOGERR_SYSLOGBUF 1024 + sizeof(int) + sizeof(pid_t)
+#define LOGERR_SYSLOGBUF 1024 + sizeof(int) + sizeof(pid_t)
-#define UNUSED(a) (void)(a)
+#define UNUSED(a) (void)(a)
struct logctx {
- char log_buf[BUFSIZ];
- unsigned int log_opts;
- int log_fd;
- pid_t log_pid;
+ char log_buf[BUFSIZ];
+ unsigned int log_opts;
+ int log_fd;
+ pid_t log_pid;
#ifndef SMALL
- FILE *log_file;
+ FILE *log_file;
#ifdef LOGERR_TAG
- const char *log_tag;
+ const char *log_tag;
#endif
#endif
};
}
#endif
-__printflike(3, 0) static int
-vlogprintf_r(struct logctx *ctx, FILE *stream, const char *fmt, va_list args)
+__printflike(3, 0) static int vlogprintf_r(struct logctx *ctx, FILE *stream,
+ const char *fmt, va_list args)
{
int len = 0, e;
va_list a;
#endif
if ((stream == stderr && ctx->log_opts & LOGERR_ERR_DATE) ||
- (stream != stderr && ctx->log_opts & LOGERR_LOG_DATE))
- {
+ (stream != stderr && ctx->log_opts & LOGERR_LOG_DATE)) {
if ((e = logprintdate(stream)) == -1)
return -1;
len += e;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmissing-format-attribute"
#endif
-__printflike(2, 0) static int
-vlogmessage(int pri, const char *fmt, va_list args)
+__printflike(2, 0) static int vlogmessage(int pri, const char *fmt,
+ va_list args)
{
struct logctx *ctx = &_logctx;
int len = 0;
if (ctx->log_opts & LOGERR_ERR &&
(pri <= LOG_ERR ||
- (!(ctx->log_opts & LOGERR_QUIET) && pri <= LOG_INFO) ||
- (ctx->log_opts & LOGERR_DEBUG && pri <= LOG_DEBUG)))
+ (!(ctx->log_opts & LOGERR_QUIET) && pri <= LOG_INFO) ||
+ (ctx->log_opts & LOGERR_DEBUG && pri <= LOG_DEBUG)))
len = vlogprintf_r(ctx, stderr, fmt, args);
#ifndef SMALL
#pragma GCC diagnostic pop
#endif
-__printflike(2, 3) void
-logmessage(int pri, const char *fmt, ...)
+__printflike(2, 3) void logmessage(int pri, const char *fmt, ...)
{
va_list args;
va_end(args);
}
-__printflike(2, 0) static void
-vlogerrmessage(int pri, const char *fmt, va_list args)
+__printflike(2, 0) static void vlogerrmessage(int pri, const char *fmt,
+ va_list args)
{
int _errno = errno;
char buf[1024];
errno = _errno;
}
-__printflike(2, 3) void
-logerrmessage(int pri, const char *fmt, ...)
+__printflike(2, 3) void logerrmessage(int pri, const char *fmt, ...)
{
va_list args;
struct iovec iov[] = {
{ .iov_base = &pri, .iov_len = sizeof(pri) },
{ .iov_base = &pid, .iov_len = sizeof(pid) },
- { .iov_base = buf, .iov_len = sizeof(buf) },
- };
- struct msghdr msg = {
- .msg_iov = iov,
- .msg_iovlen = sizeof(iov) / sizeof(iov[0])
+ { .iov_base = buf, .iov_len = sizeof(buf) },
};
+ struct msghdr msg = { .msg_iov = iov,
+ .msg_iovlen = sizeof(iov) / sizeof(iov[0]) };
ssize_t len;
len = recvmsg(fd, &msg, MSG_WAITALL);
#ifndef __printflike
#if __GNUC__ > 2 || defined(__INTEL_COMPILER)
-#define __printflike(a, b) __attribute__((format(printf, a, b)))
+#define __printflike(a, b) __attribute__((format(printf, a, b)))
#else
-#define __printflike(a, b)
+#define __printflike(a, b)
#endif
#endif /* !__printflike */
__printflike(1, 2) void log_warnx(const char *, ...);
__printflike(1, 2) void log_err(const char *, ...);
__printflike(1, 2) void log_errx(const char *, ...);
-#define LOGERROR logerr("%s: %d", __FILE__, __LINE__)
+#define LOGERROR logerr("%s: %d", __FILE__, __LINE__)
__printflike(2, 3) void logmessage(int pri, const char *fmt, ...);
__printflike(2, 3) void logerrmessage(int pri, const char *fmt, ...);
* The solution is to put fmt into __VA_ARGS__.
* It's not pretty but it's 100% portable.
*/
-#define logdebug(...) log_debug(__VA_ARGS__)
-#define logdebugx(...) log_debugx(__VA_ARGS__)
-#define loginfo(...) log_info(__VA_ARGS__)
-#define loginfox(...) log_infox(__VA_ARGS__)
-#define logwarn(...) log_warn(__VA_ARGS__)
-#define logwarnx(...) log_warnx(__VA_ARGS__)
-#define logerr(...) log_err(__VA_ARGS__)
-#define logerrx(...) log_errx(__VA_ARGS__)
+#define logdebug(...) log_debug(__VA_ARGS__)
+#define logdebugx(...) log_debugx(__VA_ARGS__)
+#define loginfo(...) log_info(__VA_ARGS__)
+#define loginfox(...) log_infox(__VA_ARGS__)
+#define logwarn(...) log_warn(__VA_ARGS__)
+#define logwarnx(...) log_warnx(__VA_ARGS__)
+#define logerr(...) log_err(__VA_ARGS__)
+#define logerrx(...) log_errx(__VA_ARGS__)
/* For logging in a chroot using SOCK_SEQPACKET */
int loggetfd(void);
unsigned int loggetopts(void);
void logsetopts(unsigned int);
-#define LOGERR_DEBUG (1U << 6)
-#define LOGERR_QUIET (1U << 7)
-#define LOGERR_LOG (1U << 11)
-#define LOGERR_LOG_DATE (1U << 12)
-#define LOGERR_LOG_HOST (1U << 13)
-#define LOGERR_LOG_TAG (1U << 14)
-#define LOGERR_LOG_PID (1U << 15)
-#define LOGERR_ERR (1U << 21)
-#define LOGERR_ERR_DATE (1U << 22)
-#define LOGERR_ERR_HOST (1U << 23)
-#define LOGERR_ERR_TAG (1U << 24)
-#define LOGERR_ERR_PID (1U << 25)
+#define LOGERR_DEBUG (1U << 6)
+#define LOGERR_QUIET (1U << 7)
+#define LOGERR_LOG (1U << 11)
+#define LOGERR_LOG_DATE (1U << 12)
+#define LOGERR_LOG_HOST (1U << 13)
+#define LOGERR_LOG_TAG (1U << 14)
+#define LOGERR_LOG_PID (1U << 15)
+#define LOGERR_ERR (1U << 21)
+#define LOGERR_ERR_DATE (1U << 22)
+#define LOGERR_ERR_HOST (1U << 23)
+#define LOGERR_ERR_TAG (1U << 24)
+#define LOGERR_ERR_PID (1U << 25)
/* To build tag support or not. */
-//#define LOGERR_TAG
+// #define LOGERR_TAG
#if defined(LOGERR_TAG)
void logsettag(const char *);
#endif
* SUCH DAMAGE.
*/
-#include <sys/socket.h>
#include <sys/types.h>
+#include <sys/socket.h>
/* Need these headers just for if_ether on some OS. */
#ifndef __NetBSD__
#include <netinet/if_ether.h>
#include <assert.h>
-#include <pwd.h>
#include <errno.h>
+#include <pwd.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
logerrx("%s: IN cmd %x, psp %p", __func__, psm->ps_cmd, psp);
#endif
- switch(psm->ps_cmd) {
+ switch (psm->ps_cmd) {
#ifdef ARP
- case PS_BPF_ARP: /* FALLTHROUGH */
+ case PS_BPF_ARP: /* FALLTHROUGH */
#endif
case PS_BPF_BOOTP:
break;
return -1;
}
- return bpf_send(psp->psp_bpf, psp->psp_proto,
- iov->iov_base, iov->iov_len);
+ return bpf_send(psp->psp_bpf, psp->psp_proto, iov->iov_base,
+ iov->iov_len);
}
static void
{
struct ps_process *psp = arg;
- if (ps_recvpsmsg(psp->psp_ctx, psp->psp_fd, events,
- ps_bpf_recvmsgcb, arg) == -1)
+ if (ps_recvpsmsg(psp->psp_ctx, psp->psp_fd, events, ps_bpf_recvmsgcb,
+ arg) == -1)
logerr(__func__);
}
logdebugx("pid %d bpf_fd=%d", getpid(), psp->psp_bpf->bpf_fd);
#endif
if (psp->psp_bpf == NULL)
- logerr("%s: bpf_open",__func__);
+ logerr("%s: bpf_open", __func__);
#ifdef PRIVSEP_RIGHTS
else if (ps_rights_limit_fd(psp->psp_bpf->bpf_fd) == -1)
logerr("%s: ps_rights_limit_fd", __func__);
#endif
else if (eloop_event_add(ctx->eloop, psp->psp_bpf->bpf_fd, ELE_READ,
- ps_bpf_recvbpf, psp) == -1)
+ ps_bpf_recvbpf, psp) == -1)
logerr("%s: eloop_event_add", __func__);
else {
psp->psp_work_fd = psp->psp_bpf->bpf_fd;
switch (cmd) {
#ifdef ARP
- case PS_BPF_ARP: /* FALLTHROUGH */
+ case PS_BPF_ARP: /* FALLTHROUGH */
#endif
case PS_BPF_BOOTP:
break;
else
addr = inet_ntoa(*ia);
snprintf(psp->psp_name, sizeof(psp->psp_name), "BPF %s%s%s",
- psp->psp_protostr,
- addr != NULL ? " " : "", addr != NULL ? addr : "");
+ psp->psp_protostr, addr != NULL ? " " : "",
+ addr != NULL ? addr : "");
- start = ps_startprocess(psp, ps_bpf_recvmsg, NULL,
- ps_bpf_start_bpf, PSF_DROPPRIVS);
+ start = ps_startprocess(psp, ps_bpf_recvmsg, NULL, ps_bpf_start_bpf,
+ PSF_DROPPRIVS);
switch (start) {
case -1:
ps_entersandbox("stdio", NULL);
break;
default:
- logdebugx("%s: spawned %s on PID %d",
- psp->psp_ifname, psp->psp_name, psp->psp_pid);
+ logdebugx("%s: spawned %s on PID %d", psp->psp_ifname,
+ psp->psp_name, psp->psp_pid);
break;
}
return start;
}
ssize_t
-ps_bpf_dispatch(struct dhcpcd_ctx *ctx,
- struct ps_msghdr *psm, struct msghdr *msg)
+ps_bpf_dispatch(struct dhcpcd_ctx *ctx, struct ps_msghdr *psm,
+ struct msghdr *msg)
{
struct iovec *iov = msg->msg_iov;
struct interface *ifp;
}
static ssize_t
-ps_bpf_send(const struct interface *ifp, const struct in_addr *ia,
- uint16_t cmd, const void *data, size_t len)
+ps_bpf_send(const struct interface *ifp, const struct in_addr *ia, uint16_t cmd,
+ const void *data, size_t len)
{
struct dhcpcd_ctx *ctx = ifp->ctx;
struct ps_msghdr psm = {
ssize_t
ps_bpf_openarp(const struct interface *ifp, const struct in_addr *ia)
{
-
assert(ia != NULL);
- return ps_bpf_send(ifp, ia, PS_BPF_ARP | PS_START,
- ifp, sizeof(*ifp));
+ return ps_bpf_send(ifp, ia, PS_BPF_ARP | PS_START, ifp, sizeof(*ifp));
}
ssize_t
ps_bpf_closearp(const struct interface *ifp, const struct in_addr *ia)
{
-
return ps_bpf_send(ifp, ia, PS_BPF_ARP | PS_STOP, NULL, 0);
}
ps_bpf_sendarp(const struct interface *ifp, const struct in_addr *ia,
const void *data, size_t len)
{
-
assert(ia != NULL);
return ps_bpf_send(ifp, ia, PS_BPF_ARP, data, len);
}
ssize_t
ps_bpf_openbootp(const struct interface *ifp)
{
-
- return ps_bpf_send(ifp, NULL, PS_BPF_BOOTP | PS_START,
- ifp, sizeof(*ifp));
+ return ps_bpf_send(ifp, NULL, PS_BPF_BOOTP | PS_START, ifp,
+ sizeof(*ifp));
}
ssize_t
ps_bpf_closebootp(const struct interface *ifp)
{
-
return ps_bpf_send(ifp, NULL, PS_BPF_BOOTP | PS_STOP, NULL, 0);
}
ssize_t
ps_bpf_sendbootp(const struct interface *ifp, const void *data, size_t len)
{
-
return ps_bpf_send(ifp, NULL, PS_BPF_BOOTP, data, len);
}
#ifndef PRIVSEP_BPF_H
#define PRIVSEP_BPF_H
-ssize_t ps_bpf_cmd(struct dhcpcd_ctx *,
- struct ps_msghdr *, struct msghdr *);
-ssize_t ps_bpf_dispatch(struct dhcpcd_ctx *,
- struct ps_msghdr *, struct msghdr *);
+ssize_t ps_bpf_cmd(struct dhcpcd_ctx *, struct ps_msghdr *, struct msghdr *);
+ssize_t ps_bpf_dispatch(struct dhcpcd_ctx *, struct ps_msghdr *,
+ struct msghdr *);
#ifdef ARP
ssize_t ps_bpf_openarp(const struct interface *, const struct in_addr *);
* SUCH DAMAGE.
*/
-#include <sys/ioctl.h>
#include <sys/types.h>
+#include <sys/ioctl.h>
#include <sys/sysctl.h>
/* Need these for filtering the ioctls */
-#include <arpa/inet.h>
#include <net/if.h>
-#include <netinet/if_ether.h>
#include <netinet/in.h>
#include <netinet6/in6_var.h>
#include <netinet6/nd6.h>
-#ifdef __NetBSD__
#include <netinet/if_ether.h>
+
+#include <arpa/inet.h>
+#ifdef __NetBSD__
#include <net/if_vlanvar.h> /* Needs netinet/if_ether.h */
+#include <netinet/if_ether.h>
#elif defined(__DragonFly__)
#include <net/vlan/if_vlan_var.h>
#else
#include <net/if_vlan_var.h>
#endif
#ifdef __DragonFly__
-# include <netproto/802_11/ieee80211_ioctl.h>
+#include <netproto/802_11/ieee80211_ioctl.h>
#else
-# include <net80211/ieee80211.h>
-# include <net80211/ieee80211_ioctl.h>
+#include <net80211/ieee80211.h>
+#include <net80211/ieee80211_ioctl.h>
#endif
#include <errno.h>
#include "privsep.h"
static ssize_t
-ps_root_doioctldom(struct dhcpcd_ctx *ctx, int domain, unsigned long req, void *data, size_t len)
+ps_root_doioctldom(struct dhcpcd_ctx *ctx, int domain, unsigned long req,
+ void *data, size_t len)
{
#if defined(INET6) || (defined(SIOCALIFADDR) && defined(IFLR_ACTIVE))
struct priv *priv = (struct priv *)ctx->priv;
#endif
int s;
- switch(domain) {
+ switch (domain) {
#ifdef INET
case PF_INET:
s = ctx->pf_inet_fd;
}
/* Only allow these ioctls */
- switch(req) {
+ switch (req) {
#ifdef SIOCGIFDATA
- case SIOCGIFDATA: /* FALLTHROUGH */
+ case SIOCGIFDATA: /* FALLTHROUGH */
#endif
#ifdef SIOCG80211NWID
- case SIOCG80211NWID: /* FALLTHROUGH */
+ case SIOCG80211NWID: /* FALLTHROUGH */
#endif
#ifdef SIOCGETVLAN
- case SIOCGETVLAN: /* FALLTHROUGH */
+ case SIOCGETVLAN: /* FALLTHROUGH */
#endif
#ifdef SIOCIFAFATTACH
- case SIOCIFAFATTACH: /* FALLTHROUGH */
+ case SIOCIFAFATTACH: /* FALLTHROUGH */
#endif
#ifdef SIOCSIFXFLAGS
- case SIOCSIFXFLAGS: /* FALLTHROUGH */
+ case SIOCSIFXFLAGS: /* FALLTHROUGH */
#endif
#ifdef SIOCSIFINFO_FLAGS
- case SIOCSIFINFO_FLAGS: /* FALLTHROUGH */
+ case SIOCSIFINFO_FLAGS: /* FALLTHROUGH */
#endif
#ifdef SIOCSRTRFLUSH_IN6
- case SIOCSRTRFLUSH_IN6: /* FALLTHROUGH */
+ case SIOCSRTRFLUSH_IN6: /* FALLTHROUGH */
case SIOCSPFXFLUSH_IN6: /* FALLTHROUGH */
#endif
#if defined(SIOCALIFADDR) && defined(IFLR_ACTIVE)
- case SIOCALIFADDR: /* FALLTHROUGH */
- case SIOCDLIFADDR: /* FALLTHROUGH */
+ case SIOCALIFADDR: /* FALLTHROUGH */
+ case SIOCDLIFADDR: /* FALLTHROUGH */
#else
- case SIOCSIFLLADDR: /* FALLTHROUGH */
+ case SIOCSIFLLADDR: /* FALLTHROUGH */
#endif
#ifdef SIOCSIFINFO_IN6
- case SIOCSIFINFO_IN6: /* FALLTHROUGH */
+ case SIOCSIFINFO_IN6: /* FALLTHROUGH */
#endif
- case SIOCAIFADDR_IN6: /* FALLTHROUGH */
+ case SIOCAIFADDR_IN6: /* FALLTHROUGH */
case SIOCDIFADDR_IN6:
break;
default:
static ssize_t
ps_root_doroute(struct dhcpcd_ctx *ctx, void *data, size_t len)
{
-
return write(ctx->link_fd, data, len);
}
#if defined(HAVE_CAPSICUM) || defined(HAVE_PLEDGE)
static ssize_t
-ps_root_doindirectioctl(struct dhcpcd_ctx *ctx,
- unsigned long req, void *data, size_t len)
+ps_root_doindirectioctl(struct dhcpcd_ctx *ctx, unsigned long req, void *data,
+ size_t len)
{
char *p = data;
struct ifreq ifr = { .ifr_flags = 0 };
static ssize_t
ps_root_doifignoregroup(struct dhcpcd_ctx *ctx, void *data, size_t len)
{
-
if (len == 0 || ((const char *)data)[len - 1] != '\0') {
errno = EINVAL;
return -1;
#ifdef HAVE_CAPSICUM
static ssize_t
-ps_root_dosysctl(unsigned long flags,
- void *data, size_t len, void **rdata, size_t *rlen)
+ps_root_dosysctl(unsigned long flags, void *data, size_t len, void **rdata,
+ size_t *rlen)
{
char *p = data, *e = p + len;
int name[10];
switch (psm->ps_cmd) {
case PS_IOCTLLINK:
- err = ps_root_doioctldom(ctx, PF_LINK, psm->ps_flags, data, len);
+ err = ps_root_doioctldom(ctx, PF_LINK, psm->ps_flags, data,
+ len);
break;
case PS_IOCTL6:
- err = ps_root_doioctldom(ctx, PF_INET6, psm->ps_flags, data, len);
+ err = ps_root_doioctldom(ctx, PF_INET6, psm->ps_flags, data,
+ len);
break;
case PS_ROUTE:
return ps_root_doroute(ctx, data, len);
*free_rdata = true;
return ps_root_dosysctl(psm->ps_flags, data, len, rdata, rlen);
#else
- UNUSED(free_rdata);
+ UNUSED(free_rdata);
#endif
default:
errno = ENOTSUP;
ps_root_ioctldom(struct dhcpcd_ctx *ctx, uint16_t domain, unsigned long request,
void *data, size_t len)
{
-
- if (ps_sendcmd(ctx, PS_ROOT_FD(ctx), domain,
- request, data, len) == -1)
+ if (ps_sendcmd(ctx, PS_ROOT_FD(ctx), domain, request, data, len) == -1)
return -1;
return ps_root_readerror(ctx, data, len);
}
ssize_t
-ps_root_ioctllink(struct dhcpcd_ctx *ctx, unsigned long request,
- void *data, size_t len)
+ps_root_ioctllink(struct dhcpcd_ctx *ctx, unsigned long request, void *data,
+ size_t len)
{
-
return ps_root_ioctldom(ctx, PS_IOCTLLINK, request, data, len);
}
ssize_t
-ps_root_ioctl6(struct dhcpcd_ctx *ctx, unsigned long request,
- void *data, size_t len)
+ps_root_ioctl6(struct dhcpcd_ctx *ctx, unsigned long request, void *data,
+ size_t len)
{
-
return ps_root_ioctldom(ctx, PS_IOCTL6, request, data, len);
}
ssize_t
ps_root_route(struct dhcpcd_ctx *ctx, void *data, size_t len)
{
-
if (ps_sendcmd(ctx, PS_ROOT_FD(ctx), PS_ROUTE, 0, data, len) == -1)
return -1;
return ps_root_readerror(ctx, data, len);
{
size_t ifnamelen = strlen(ifname + 1);
- struct iovec iov[] = {
- {
- .iov_base = &ifnamelen,
- .iov_len = sizeof(ifnamelen),
- },
+ struct iovec iov[] = { {
+ .iov_base = &ifnamelen,
+ .iov_len = sizeof(ifnamelen),
+ },
{
- .iov_base = UNCONST(ifname),
- .iov_len = ifnamelen,
+ .iov_base = UNCONST(ifname),
+ .iov_len = ifnamelen,
},
{
- .iov_base = data,
- .iov_len = len,
- }
- };
+ .iov_base = data,
+ .iov_len = len,
+ } };
struct msghdr msg = {
.msg_iov = iov,
.msg_iovlen = __arraycount(iov),
};
- if (ps_sendcmdmsg(ctx, PS_ROOT_FD(ctx), PS_IOCTLINDIRECT,
- request, &msg) == -1)
+ if (ps_sendcmdmsg(ctx, PS_ROOT_FD(ctx), PS_IOCTLINDIRECT, request,
+ &msg) == -1)
return -1;
return ps_root_readerror(ctx, data, len);
}
ssize_t
ps_root_ifignoregroup(struct dhcpcd_ctx *ctx, const char *ifname)
{
-
- if (ps_sendcmd(ctx, PS_ROOT_FD(ctx), PS_IFIGNOREGRP, 0,
- ifname, strlen(ifname) + 1) == -1)
+ if (ps_sendcmd(ctx, PS_ROOT_FD(ctx), PS_IFIGNOREGRP, 0, ifname,
+ strlen(ifname) + 1) == -1)
return -1;
return ps_root_readerror(ctx, NULL, 0);
}
#ifdef HAVE_CAPSICUM
ssize_t
-ps_root_sysctl(struct dhcpcd_ctx *ctx,
- const int *name, unsigned int namelen,
+ps_root_sysctl(struct dhcpcd_ctx *ctx, const int *name, unsigned int namelen,
void *oldp, size_t *oldlenp, const void *newp, size_t newlen)
{
char buf[PS_BUFLEN], *p = buf;
unsigned long flags = 0;
size_t olen = (oldp && oldlenp) ? *oldlenp : 0, nolen;
- if (sizeof(namelen) + (sizeof(*name) * namelen) +
- sizeof(oldlenp) +
- sizeof(newlen) + newlen > sizeof(buf))
- {
+ if (sizeof(namelen) + (sizeof(*name) * namelen) + sizeof(oldlenp) +
+ sizeof(newlen) + newlen >
+ sizeof(buf)) {
errno = ENOBUFS;
return -1;
}
p += newlen;
}
- if (ps_sendcmd(ctx, PS_ROOT_FD(ctx), PS_SYSCTL,
- flags, buf, (size_t)(p - buf)) == -1)
+ if (ps_sendcmd(ctx, PS_ROOT_FD(ctx), PS_SYSCTL, flags, buf,
+ (size_t)(p - buf)) == -1)
return -1;
if (ps_root_readerror(ctx, buf, sizeof(buf)) == -1)
#include <stdlib.h>
#include <string.h>
-#include "dhcpcd.h"
#include "control.h"
+#include "dhcpcd.h"
#include "eloop.h"
#include "logerr.h"
#include "privsep.h"
setproctitle("[control proxy]");
af = AF_UNSPEC;
} else {
- setproctitle("[control proxy] %s%s%s",
- ctx->ifv[0],
+ setproctitle("[control proxy] %s%s%s", ctx->ifv[0],
ctx->options & DHCPCD_IPV4 ? " [ip4]" : "",
ctx->options & DHCPCD_IPV6 ? " [ip6]" : "");
- if ((ctx->options &
- (DHCPCD_IPV4 | DHCPCD_IPV6)) == DHCPCD_IPV4)
+ if ((ctx->options & (DHCPCD_IPV4 | DHCPCD_IPV6)) == DHCPCD_IPV4)
af = AF_INET;
- else if ((ctx->options &
- (DHCPCD_IPV4 | DHCPCD_IPV6)) == DHCPCD_IPV6)
+ else if ((ctx->options & (DHCPCD_IPV4 | DHCPCD_IPV6)) ==
+ DHCPCD_IPV6)
af = AF_INET6;
else
af = AF_UNSPEC;
ssize_t
ps_ctl_handleargs(struct fd_list *fd, char *data, size_t len)
{
-
/* Make any change here in dhcpcd.c as well. */
- if (strncmp(data, "--version",
- MIN(strlen("--version"), len)) == 0) {
- return control_queue(fd, UNCONST(VERSION),
- strlen(VERSION) + 1);
+ if (strncmp(data, "--version", MIN(strlen("--version"), len)) == 0) {
+ return control_queue(fd, UNCONST(VERSION), strlen(VERSION) + 1);
} else if (strncmp(data, "--getconfigfile",
- MIN(strlen("--getconfigfile"), len)) == 0) {
+ MIN(strlen("--getconfigfile"), len)) == 0) {
return control_queue(fd, UNCONST(fd->ctx->cffile),
strlen(fd->ctx->cffile) + 1);
- } else if (strncmp(data, "--listen",
- MIN(strlen("--listen"), len)) == 0) {
+ } else if (strncmp(data, "--listen", MIN(strlen("--listen"), len)) ==
+ 0) {
fd->flags |= FD_LISTEN;
return 0;
}
if (fd->ctx->ps_control_client != NULL &&
- fd->ctx->ps_control_client != fd)
- {
+ fd->ctx->ps_control_client != fd) {
logerrx("%s: cannot handle another client", __func__);
return 0;
}
{
struct ps_process *psp = arg;
- if (ps_recvpsmsg(psp->psp_ctx, psp->psp_fd, events,
- ps_ctl_dispatch, psp->psp_ctx) == -1)
+ if (ps_recvpsmsg(psp->psp_ctx, psp->psp_fd, events, ps_ctl_dispatch,
+ psp->psp_ctx) == -1)
logerr(__func__);
}
__func__, ctx->ps_ctl->psp_work_fd, len);
else {
errno = 0;
- if (control_queue(ctx->ps_control_client,
- buf, (size_t)len) == -1)
+ if (control_queue(ctx->ps_control_client, buf,
+ (size_t)len) == -1)
logerr("%s: control_queue", __func__);
}
}
TAILQ_FOREACH(fd, &ctx->control_fds, next) {
if (!(fd->flags & FD_LISTEN))
continue;
- if (control_queue(fd, buf, (size_t)len)== -1)
+ if (control_queue(fd, buf, (size_t)len) == -1)
logerr("%s: control_queue", __func__);
}
}
psp->psp_work_fd = work_fd[0];
close(work_fd[1]);
close(listen_fd[1]);
- ctx->ps_control = control_new(ctx,
- listen_fd[0], FD_SENDLEN | FD_LISTEN);
+ ctx->ps_control = control_new(ctx, listen_fd[0],
+ FD_SENDLEN | FD_LISTEN);
if (ctx->ps_control == NULL)
return -1;
return pid;
close(listen_fd[0]);
psp->psp_work_fd = work_fd[1];
- if (eloop_event_add(ctx->eloop, psp->psp_work_fd, ELE_READ,
- ps_ctl_recv, ctx) == -1)
+ if (eloop_event_add(ctx->eloop, psp->psp_work_fd, ELE_READ, ps_ctl_recv,
+ ctx) == -1)
return -1;
ctx->ps_control = control_new(ctx, listen_fd[1], 0);
if (ctx->ps_control == NULL)
return -1;
if (eloop_event_add(ctx->eloop, ctx->ps_control->fd, ELE_READ,
- ps_ctl_listen, ctx) == -1)
+ ps_ctl_listen, ctx) == -1)
return -1;
ps_entersandbox("stdio inet", NULL);
int
ps_ctl_stop(struct dhcpcd_ctx *ctx)
{
-
return ps_stopprocess(ctx->ps_ctl);
}
logerrx("%s: cannot deal with another client", __func__);
ctx->ps_control_client = fd;
return ps_sendcmd(ctx, ctx->ps_ctl->psp_fd, PS_CTL,
- fd->flags & FD_UNPRIV ? PS_CTL_UNPRIV : PS_CTL_PRIV,
- data, len);
+ fd->flags & FD_UNPRIV ? PS_CTL_UNPRIV : PS_CTL_PRIV, data, len);
}
ssize_t
#define PRIVSEP_CTL_H
#define IN_PRIVSEP_CONTROLLER(ctx) \
- (IN_PRIVSEP((ctx)) && (ctx)->ps_control_pid == getpid())
+ (IN_PRIVSEP((ctx)) && (ctx)->ps_control_pid == getpid())
pid_t ps_ctl_start(struct dhcpcd_ctx *);
int ps_ctl_stop(struct dhcpcd_ctx *);
* SUCH DAMAGE.
*/
-#include <sys/socket.h>
#include <sys/types.h>
+#include <sys/socket.h>
-#include <netinet/in.h>
#include <netinet/icmp6.h>
+#include <netinet/in.h>
#include <assert.h>
#include <errno.h>
{
struct dhcpcd_ctx *ctx = arg;
- if (ps_recvmsg(ctx->udp_rfd, events,
- PS_BOOTP, ctx->ps_inet->psp_fd) == -1)
+ if (ps_recvmsg(ctx->udp_rfd, events, PS_BOOTP, ctx->ps_inet->psp_fd) ==
+ -1)
logerr(__func__);
}
#endif
struct rs_state *state = RS_STATE(ifp);
struct dhcpcd_ctx *ctx = ifp->ctx;
- if (ps_recvmsg(state->nd_fd, events,
- PS_ND, ctx->ps_inet->psp_fd) == -1)
+ if (ps_recvmsg(state->nd_fd, events, PS_ND, ctx->ps_inet->psp_fd) == -1)
logerr(__func__);
#else
struct dhcpcd_ctx *ctx = arg;
- if (ps_recvmsg(ctx->nd_fd, events,
- PS_ND, ctx->ps_inet->psp_fd) == -1)
+ if (ps_recvmsg(ctx->nd_fd, events, PS_ND, ctx->ps_inet->psp_fd) == -1)
logerr(__func__);
#endif
}
{
struct dhcpcd_ctx *ctx = arg;
- if (ps_recvmsg(ctx->dhcp6_rfd, events,
- PS_DHCP6, ctx->ps_inet->psp_fd) == -1)
+ if (ps_recvmsg(ctx->dhcp6_rfd, events, PS_DHCP6,
+ ctx->ps_inet->psp_fd) == -1)
logerr(__func__);
}
#endif
bool
ps_inet_canstart(const struct dhcpcd_ctx *ctx)
{
-
#ifdef INET
if ((ctx->options & (DHCPCD_IPV4 | DHCPCD_MANAGER)) ==
(DHCPCD_IPV4 | DHCPCD_MANAGER))
#ifdef INET
if ((ctx->options & (DHCPCD_IPV4 | DHCPCD_MANAGER)) ==
- (DHCPCD_IPV4 | DHCPCD_MANAGER))
- {
+ (DHCPCD_IPV4 | DHCPCD_MANAGER)) {
ctx->udp_rfd = dhcp_openudp(NULL);
if (ctx->udp_rfd == -1)
logerr("%s: dhcp_open", __func__);
}
#endif
else if (eloop_event_add(ctx->eloop, ctx->udp_rfd, ELE_READ,
- ps_inet_recvbootp, ctx) == -1)
- {
+ ps_inet_recvbootp, ctx) == -1) {
logerr("%s: eloop_event_add DHCP", __func__);
close(ctx->udp_rfd);
ctx->udp_rfd = -1;
}
#endif
else if (eloop_event_add(ctx->eloop, ctx->nd_fd, ELE_READ,
- ps_inet_recvra, ctx) == -1)
- {
+ ps_inet_recvra, ctx) == -1) {
logerr("%s: eloop_event_add RA", __func__);
close(ctx->nd_fd);
ctx->nd_fd = -1;
#endif
#ifdef DHCP6
if ((ctx->options & (DHCPCD_IPV6 | DHCPCD_MANAGER)) ==
- (DHCPCD_IPV6 | DHCPCD_MANAGER))
- {
+ (DHCPCD_IPV6 | DHCPCD_MANAGER)) {
ctx->dhcp6_rfd = dhcp6_openudp(0, NULL);
if (ctx->dhcp6_rfd == -1)
logerr("%s: dhcp6_open", __func__);
}
#endif
else if (eloop_event_add(ctx->eloop, ctx->dhcp6_rfd, ELE_READ,
- ps_inet_recvdhcp6, ctx) == -1)
- {
+ ps_inet_recvdhcp6, ctx) == -1) {
logerr("%s: eloop_event_add DHCP6", __func__);
close(ctx->dhcp6_rfd);
ctx->dhcp6_rfd = -1;
}
memcpy(&icmp6, iov->iov_base, sizeof(icmp6));
- switch(icmp6.icmp6_type) {
+ switch (icmp6.icmp6_type) {
case ND_ROUTER_SOLICIT:
case ND_NEIGHBOR_ADVERT:
break;
#endif
static ssize_t
-ps_inet_sendmsg(struct dhcpcd_ctx *ctx,
- struct ps_msghdr *psm, struct msghdr *msg)
+ps_inet_sendmsg(struct dhcpcd_ctx *ctx, struct ps_msghdr *psm,
+ struct msghdr *msg)
{
struct ps_process *psp;
int s;
#endif
#ifdef DHCP6
case PS_DHCP6:
- if (!ps_inet_validudp(msg, DHCP6_CLIENT_PORT,DHCP6_SERVER_PORT))
+ if (!ps_inet_validudp(msg, DHCP6_CLIENT_PORT,
+ DHCP6_SERVER_PORT))
return -1;
s = ctx->dhcp6_wfd;
break;
{
struct ps_process *psp = arg;
- if (ps_recvpsmsg(psp->psp_ctx, psp->psp_fd, events,
- ps_inet_dispatch, psp->psp_ctx) == -1)
+ if (ps_recvpsmsg(psp->psp_ctx, psp->psp_fd, events, ps_inet_dispatch,
+ psp->psp_ctx) == -1)
logerr(__func__);
}
int
ps_inet_stop(struct dhcpcd_ctx *ctx)
{
-
return ps_stopprocess(ctx->ps_inet);
}
{
struct ps_process *psp = arg;
- if (ps_recvmsg(psp->psp_work_fd, events,
- PS_BOOTP, psp->psp_ctx->ps_data_fd) == -1)
+ if (ps_recvmsg(psp->psp_work_fd, events, PS_BOOTP,
+ psp->psp_ctx->ps_data_fd) == -1)
logerr(__func__);
}
#endif
if (eloop_event_add(psp->psp_ctx->eloop, psp->psp_work_fd, ELE_READ,
- ps_inet_recvinbootp, psp) == -1)
- {
+ ps_inet_recvinbootp, psp) == -1) {
logerr("%s: eloop_event_add DHCP", __func__);
return -1;
}
{
struct ps_process *psp = arg;
- if (ps_recvmsg(psp->psp_work_fd,
- PS_ND, psp->psp_ctx->ps_data_fd) == -1)
+ if (ps_recvmsg(psp->psp_work_fd, PS_ND, psp->psp_ctx->ps_data_fd) == -1)
logerr(__func__);
}
static int
ps_inet_listennd(struct ps_process *psp)
{
-
setproctitle("[ND network proxy]");
psp->psp_work_fd = ipv6nd_open(&psp->psp_ifp);
#endif
if (eloop_event_add(psp->psp_ctx->eloop, psp->psp_work_fd,
- ps_inet_recvin6nd, psp) == -1)
- {
+ ps_inet_recvin6nd, psp) == -1) {
logerr(__func__);
return -1;
}
{
struct ps_process *psp = arg;
- if (ps_recvmsg(psp->psp_work_fd, events,
- PS_DHCP6, psp->psp_ctx->ps_data_fd) == -1)
+ if (ps_recvmsg(psp->psp_work_fd, events, PS_DHCP6,
+ psp->psp_ctx->ps_data_fd) == -1)
logerr(__func__);
}
#endif
if (eloop_event_add(psp->psp_ctx->eloop, psp->psp_work_fd, ELE_READ,
- ps_inet_recvin6dhcp6, psp) == -1)
- {
+ ps_inet_recvin6dhcp6, psp) == -1) {
logerr("%s: eloop_event_add DHCP", __func__);
return -1;
}
if (psp == NULL)
return -1;
-
switch (cmd) {
#ifdef INET
case PS_BOOTP:
return -1;
}
- snprintf(psp->psp_name, sizeof(psp->psp_name),
- "%s proxy %s", psp->psp_protostr,
+ snprintf(psp->psp_name, sizeof(psp->psp_name), "%s proxy %s",
+ psp->psp_protostr,
inet_ntop(psa->psa_family, ia, buf, sizeof(buf)));
- start = ps_startprocess(psp, ps_inet_recvmsgpsp, NULL,
- start_func, PSF_DROPPRIVS);
+ start = ps_startprocess(psp, ps_inet_recvmsgpsp, NULL, start_func,
+ PSF_DROPPRIVS);
switch (start) {
case -1:
ps_freeprocess(psp);
ps_entersandbox("stdio", NULL);
break;
default:
- logdebugx("%s: spawned %s on PID %d",
- psp->psp_ifname, psp->psp_name, psp->psp_pid);
+ logdebugx("%s: spawned %s on PID %d", psp->psp_ifname,
+ psp->psp_name, psp->psp_pid);
break;
}
return start;
ssize_t
ps_inet_openbootp(struct ipv4_addr *ia)
{
-
return ps_inet_in_docmd(ia, PS_START | PS_BOOTP, NULL);
}
ssize_t
ps_inet_closebootp(struct ipv4_addr *ia)
{
-
return ps_inet_in_docmd(ia, PS_STOP | PS_BOOTP, NULL);
}
ssize_t
ps_inet_opennd(struct interface *ifp)
{
-
return ps_inet_ifp_docmd(ifp, PS_ND | PS_START, NULL);
}
ssize_t
ps_inet_closend(struct interface *ifp)
{
-
return ps_inet_ifp_docmd(ifp, PS_ND | PS_STOP, NULL);
}
ssize_t
ps_inet_sendnd(struct interface *ifp, const struct msghdr *msg)
{
-
return ps_inet_ifp_docmd(ifp, PS_ND, msg);
}
#else
ssize_t
ps_inet_opendhcp6(struct ipv6_addr *ia)
{
-
return ps_inet_in6_docmd(ia, PS_DHCP6 | PS_START, NULL);
}
ssize_t
ps_inet_closedhcp6(struct ipv6_addr *ia)
{
-
return ps_inet_in6_docmd(ia, PS_DHCP6 | PS_STOP, NULL);
}
#include <sys/socket.h>
#include <sys/syscall.h>
+#include <errno.h>
+#include <fcntl.h>
#include <linux/audit.h>
#include <linux/filter.h>
#include <linux/net.h>
#include <linux/seccomp.h>
#include <linux/sockios.h>
-
-#include <errno.h>
-#include <fcntl.h>
#include <signal.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <termios.h> /* For TCGETS */
+#include <termios.h> /* For TCGETS */
#include <unistd.h>
#include "common.h"
* the failing syscall into the __NR_name define we need to use below.
* DO NOT ENABLE THIS FOR PRODUCTION BUILDS!
*/
-//#define SECCOMP_FILTER_DEBUG
+// #define SECCOMP_FILTER_DEBUG
static ssize_t
ps_root_dosendnetlink(struct dhcpcd_ctx *ctx, int protocol, struct msghdr *msg)
.iov_len = sizeof(buf),
};
- switch(protocol) {
+ switch (protocol) {
case NETLINK_GENERIC:
s = priv->generic_fd;
break;
ps_root_os(struct dhcpcd_ctx *ctx, struct ps_msghdr *psm, struct msghdr *msg,
__unused void **rdata, __unused size_t *rlen, __unused bool *free_data)
{
-
switch (psm->ps_cmd) {
case PS_ROUTE:
return ps_root_dosendnetlink(ctx, (int)psm->ps_flags, msg);
ssize_t
ps_root_sendnetlink(struct dhcpcd_ctx *ctx, int protocol, struct msghdr *msg)
{
-
- if (ps_sendmsg(ctx, PS_ROOT_FD(ctx), PS_ROUTE,
- (unsigned long)protocol, msg) == -1)
+ if (ps_sendmsg(ctx, PS_ROOT_FD(ctx), PS_ROUTE, (unsigned long)protocol,
+ msg) == -1)
return -1;
return ps_root_readerror(ctx, NULL, 0);
}
#else
#if (BYTE_ORDER == LITTLE_ENDIAN)
-# define SECCOMP_ARG_LO 0
-# define SECCOMP_ARG_HI sizeof(uint32_t)
+#define SECCOMP_ARG_LO 0
+#define SECCOMP_ARG_HI sizeof(uint32_t)
#elif (BYTE_ORDER == BIG_ENDIAN)
-# define SECCOMP_ARG_LO sizeof(uint32_t)
-# define SECCOMP_ARG_HI 0
+#define SECCOMP_ARG_LO sizeof(uint32_t)
+#define SECCOMP_ARG_HI 0
#else
-# error "Uknown endian"
-#endif
-
-#define SECCOMP_ALLOW(_nr) \
- BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, (_nr), 0, 1), \
- BPF_STMT(BPF_RET + BPF_K, SECCOMP_RET_ALLOW)
-
-#define SECCOMP_ALLOW_ARG(_nr, _arg, _val) \
- BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, (_nr), 0, 6), \
- BPF_STMT(BPF_LD + BPF_W + BPF_ABS, \
- offsetof(struct seccomp_data, args[(_arg)]) + SECCOMP_ARG_LO), \
- BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, \
- ((_val) & 0xffffffff), 0, 3), \
- BPF_STMT(BPF_LD + BPF_W + BPF_ABS, \
- offsetof(struct seccomp_data, args[(_arg)]) + SECCOMP_ARG_HI), \
- BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, \
- (((uint32_t)((uint64_t)(_val) >> 32)) & 0xffffffff), 0, 1), \
- BPF_STMT(BPF_RET + BPF_K, SECCOMP_RET_ALLOW), \
- BPF_STMT(BPF_LD + BPF_W + BPF_ABS, \
+#error "Uknown endian"
+#endif
+
+#define SECCOMP_ALLOW(_nr) \
+ BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, (_nr), 0, 1), \
+ BPF_STMT(BPF_RET + BPF_K, SECCOMP_RET_ALLOW)
+
+#define SECCOMP_ALLOW_ARG(_nr, _arg, _val) \
+ BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, (_nr), 0, 6), \
+ BPF_STMT(BPF_LD + BPF_W + BPF_ABS, \
+ offsetof(struct seccomp_data, args[(_arg)]) + SECCOMP_ARG_LO), \
+ BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, ((_val) & 0xffffffff), 0, 3), \
+ BPF_STMT(BPF_LD + BPF_W + BPF_ABS, \
+ offsetof(struct seccomp_data, args[(_arg)]) + SECCOMP_ARG_HI), \
+ BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, \
+ (((uint32_t)((uint64_t)(_val) >> 32)) & 0xffffffff), 0, 1), \
+ BPF_STMT(BPF_RET + BPF_K, SECCOMP_RET_ALLOW), \
+ BPF_STMT(BPF_LD + BPF_W + BPF_ABS, \
offsetof(struct seccomp_data, nr))
#ifdef SECCOMP_FILTER_DEBUG
-#define SECCOMP_FILTER_FAIL SECCOMP_RET_TRAP
+#define SECCOMP_FILTER_FAIL SECCOMP_RET_TRAP
#else
-#define SECCOMP_FILTER_FAIL SECCOMP_RET_KILL
+#define SECCOMP_FILTER_FAIL SECCOMP_RET_KILL
#endif
/* I personally find this quite nutty.
* Why can a system header not define a default for this? */
#if defined(__i386__)
-# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_I386
+#define SECCOMP_AUDIT_ARCH AUDIT_ARCH_I386
#elif defined(__x86_64__)
-# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_X86_64
+#define SECCOMP_AUDIT_ARCH AUDIT_ARCH_X86_64
#elif defined(__arc__)
-# if defined(__A7__)
-# if (BYTE_ORDER == LITTLE_ENDIAN)
-# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_ARCOMPACT
-# else
-# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_ARCOMPACTBE
-# endif
-# elif defined(__HS__)
-# if (BYTE_ORDER == LITTLE_ENDIAN)
-# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_ARCV2
-# else
-# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_ARCV2BE
-# endif
-# else
-# error "Platform does not support seccomp filter yet"
-# endif
+#if defined(__A7__)
+#if (BYTE_ORDER == LITTLE_ENDIAN)
+#define SECCOMP_AUDIT_ARCH AUDIT_ARCH_ARCOMPACT
+#else
+#define SECCOMP_AUDIT_ARCH AUDIT_ARCH_ARCOMPACTBE
+#endif
+#elif defined(__HS__)
+#if (BYTE_ORDER == LITTLE_ENDIAN)
+#define SECCOMP_AUDIT_ARCH AUDIT_ARCH_ARCV2
+#else
+#define SECCOMP_AUDIT_ARCH AUDIT_ARCH_ARCV2BE
+#endif
+#else
+#error "Platform does not support seccomp filter yet"
+#endif
#elif defined(__ARCV3__)
-# if defined(__ARC64__)
-# if (BYTE_ORDER == LITTLE_ENDIAN)
-# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_ARCV3
-# else
-# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_ARCV3BE
-# endif
-# else
-# error "Platform does not support seccomp filter yet"
-# endif
+#if defined(__ARC64__)
+#if (BYTE_ORDER == LITTLE_ENDIAN)
+#define SECCOMP_AUDIT_ARCH AUDIT_ARCH_ARCV3
+#else
+#define SECCOMP_AUDIT_ARCH AUDIT_ARCH_ARCV3BE
+#endif
+#else
+#error "Platform does not support seccomp filter yet"
+#endif
#elif defined(__arm__)
-# ifndef EM_ARM
-# define EM_ARM 40
-# endif
-# if (BYTE_ORDER == LITTLE_ENDIAN)
-# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_ARM
-# else
-# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_ARMEB
-# endif
+#ifndef EM_ARM
+#define EM_ARM 40
+#endif
+#if (BYTE_ORDER == LITTLE_ENDIAN)
+#define SECCOMP_AUDIT_ARCH AUDIT_ARCH_ARM
+#else
+#define SECCOMP_AUDIT_ARCH AUDIT_ARCH_ARMEB
+#endif
#elif defined(__aarch64__)
-# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_AARCH64
+#define SECCOMP_AUDIT_ARCH AUDIT_ARCH_AARCH64
#elif defined(__alpha__)
-# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_ALPHA
+#define SECCOMP_AUDIT_ARCH AUDIT_ARCH_ALPHA
#elif defined(__hppa__)
-# if defined(__LP64__)
-# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_PARISC64
-# else
-# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_PARISC
-# endif
+#if defined(__LP64__)
+#define SECCOMP_AUDIT_ARCH AUDIT_ARCH_PARISC64
+#else
+#define SECCOMP_AUDIT_ARCH AUDIT_ARCH_PARISC
+#endif
#elif defined(__ia64__)
-# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_IA64
+#define SECCOMP_AUDIT_ARCH AUDIT_ARCH_IA64
#elif defined(__loongarch__)
-# if defined(__LP64__)
-# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_LOONGARCH64
-# else
-# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_LOONGARCH32
-# endif
+#if defined(__LP64__)
+#define SECCOMP_AUDIT_ARCH AUDIT_ARCH_LOONGARCH64
+#else
+#define SECCOMP_AUDIT_ARCH AUDIT_ARCH_LOONGARCH32
+#endif
#elif defined(__microblaze__)
-# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_MICROBLAZE
+#define SECCOMP_AUDIT_ARCH AUDIT_ARCH_MICROBLAZE
#elif defined(__m68k__)
-# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_M68K
+#define SECCOMP_AUDIT_ARCH AUDIT_ARCH_M68K
#elif defined(__mips__)
-# if defined(__MIPSEL__)
-# if defined(__LP64__)
-# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_MIPSEL64
-# else
-# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_MIPSEL
-# endif
-# elif defined(__LP64__)
-# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_MIPS64
-# else
-# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_MIPS
-# endif
+#if defined(__MIPSEL__)
+#if defined(__LP64__)
+#define SECCOMP_AUDIT_ARCH AUDIT_ARCH_MIPSEL64
+#else
+#define SECCOMP_AUDIT_ARCH AUDIT_ARCH_MIPSEL
+#endif
+#elif defined(__LP64__)
+#define SECCOMP_AUDIT_ARCH AUDIT_ARCH_MIPS64
+#else
+#define SECCOMP_AUDIT_ARCH AUDIT_ARCH_MIPS
+#endif
#elif defined(__nds32__)
-# if (BYTE_ORDER == LITTLE_ENDIAN)
-# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_NDS32
+#if (BYTE_ORDER == LITTLE_ENDIAN)
+#define SECCOMP_AUDIT_ARCH AUDIT_ARCH_NDS32
#else
-# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_NDS32BE
+#define SECCOMP_AUDIT_ARCH AUDIT_ARCH_NDS32BE
#endif
#elif defined(__nios2__)
-# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_NIOS2
+#define SECCOMP_AUDIT_ARCH AUDIT_ARCH_NIOS2
#elif defined(__or1k__)
-# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_OPENRISC
+#define SECCOMP_AUDIT_ARCH AUDIT_ARCH_OPENRISC
#elif defined(__powerpc64__)
-# if (BYTE_ORDER == LITTLE_ENDIAN)
-# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_PPC64LE
-# else
-# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_PPC64
-# endif
+#if (BYTE_ORDER == LITTLE_ENDIAN)
+#define SECCOMP_AUDIT_ARCH AUDIT_ARCH_PPC64LE
+#else
+#define SECCOMP_AUDIT_ARCH AUDIT_ARCH_PPC64
+#endif
#elif defined(__powerpc__)
-# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_PPC
+#define SECCOMP_AUDIT_ARCH AUDIT_ARCH_PPC
#elif defined(__riscv)
-# if defined(__LP64__)
-# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_RISCV64
-# else
-# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_RISCV32
-# endif
+#if defined(__LP64__)
+#define SECCOMP_AUDIT_ARCH AUDIT_ARCH_RISCV64
+#else
+#define SECCOMP_AUDIT_ARCH AUDIT_ARCH_RISCV32
+#endif
#elif defined(__s390x__)
-# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_S390X
+#define SECCOMP_AUDIT_ARCH AUDIT_ARCH_S390X
#elif defined(__s390__)
-# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_S390
+#define SECCOMP_AUDIT_ARCH AUDIT_ARCH_S390
#elif defined(__sh__)
-# if defined(__LP64__)
-# if (BYTE_ORDER == LITTLE_ENDIAN)
-# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_SHEL64
-# else
-# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_SH64
-# endif
-# else
-# if (BYTE_ORDER == LITTLE_ENDIAN)
-# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_SHEL
-# else
-# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_SH
-# endif
-# endif
+#if defined(__LP64__)
+#if (BYTE_ORDER == LITTLE_ENDIAN)
+#define SECCOMP_AUDIT_ARCH AUDIT_ARCH_SHEL64
+#else
+#define SECCOMP_AUDIT_ARCH AUDIT_ARCH_SH64
+#endif
+#else
+#if (BYTE_ORDER == LITTLE_ENDIAN)
+#define SECCOMP_AUDIT_ARCH AUDIT_ARCH_SHEL
+#else
+#define SECCOMP_AUDIT_ARCH AUDIT_ARCH_SH
+#endif
+#endif
#elif defined(__sparc__)
-# if defined(__arch64__)
-# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_SPARC64
-# else
-# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_SPARC
-# endif
+#if defined(__arch64__)
+#define SECCOMP_AUDIT_ARCH AUDIT_ARCH_SPARC64
+#else
+#define SECCOMP_AUDIT_ARCH AUDIT_ARCH_SPARC
+#endif
#elif defined(__xtensa__)
-# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_XTENSA
+#define SECCOMP_AUDIT_ARCH AUDIT_ARCH_XTENSA
#else
-# error "Platform does not support seccomp filter yet"
+#error "Platform does not support seccomp filter yet"
#endif
static struct sock_filter ps_seccomp_filter[] = {
/* Check syscall arch */
- BPF_STMT(BPF_LD + BPF_W + BPF_ABS,
- offsetof(struct seccomp_data, arch)),
+ BPF_STMT(BPF_LD + BPF_W + BPF_ABS, offsetof(struct seccomp_data, arch)),
BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, SECCOMP_AUDIT_ARCH, 1, 0),
BPF_STMT(BPF_RET + BPF_K, SECCOMP_FILTER_FAIL),
/* Allow syscalls */
- BPF_STMT(BPF_LD + BPF_W + BPF_ABS,
- offsetof(struct seccomp_data, nr)),
+ BPF_STMT(BPF_LD + BPF_W + BPF_ABS, offsetof(struct seccomp_data, nr)),
#ifdef __NR_accept
SECCOMP_ALLOW(__NR_accept),
#endif
SECCOMP_ALLOW_ARG(__NR_ioctl, 1, TCGETS),
/* dumping leases on musl requires this */
SECCOMP_ALLOW_ARG(__NR_ioctl, 1, TIOCGWINSZ),
- /* SECCOMP BPF is newer than nl80211 so we don't need SIOCGIWESSID
- * which lives in the impossible to include linux/wireless.h header */
+/* SECCOMP BPF is newer than nl80211 so we don't need SIOCGIWESSID
+ * which lives in the impossible to include linux/wireless.h header */
#endif
#ifdef __NR_madvise /* needed for musl */
SECCOMP_ALLOW(__NR_madvise),
SECCOMP_ALLOW_ARG(__NR_socketcall, 0, SYS_ACCEPT),
SECCOMP_ALLOW_ARG(__NR_socketcall, 0, SYS_ACCEPT4),
SECCOMP_ALLOW_ARG(__NR_socketcall, 0, SYS_LISTEN),
- SECCOMP_ALLOW_ARG(__NR_socketcall, 0, SYS_GETSOCKOPT), /* overflow */
+ SECCOMP_ALLOW_ARG(__NR_socketcall, 0, SYS_GETSOCKOPT), /* overflow */
SECCOMP_ALLOW_ARG(__NR_socketcall, 0, SYS_RECV),
SECCOMP_ALLOW_ARG(__NR_socketcall, 0, SYS_RECVFROM),
SECCOMP_ALLOW_ARG(__NR_socketcall, 0, SYS_RECVMSG),
static void
ps_seccomp_violation(__unused int signum, siginfo_t *si, __unused void *context)
{
-
- logerrx("%s: unexpected syscall %d (arch=0x%x)",
- __func__, si->si_syscall, si->si_arch);
+ logerrx("%s: unexpected syscall %d (arch=0x%x)", __func__,
+ si->si_syscall, si->si_arch);
_exit(EXIT_FAILURE);
}
#endif
if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0) == -1 ||
- prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &ps_seccomp_prog) == -1)
- {
+ prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &ps_seccomp_prog) ==
+ -1) {
if (errno == EINVAL)
errno = ENOSYS;
return -1;
* SUCH DAMAGE.
*/
+#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/time.h>
-#include <sys/types.h>
#include <sys/wait.h>
#include <assert.h>
#include "auth.h"
#include "common.h"
#include "dev.h"
-#include "dhcpcd.h"
#include "dhcp6.h"
+#include "dhcpcd.h"
#include "eloop.h"
#include "if.h"
#include "ipv6nd.h"
__CTASSERT(sizeof(ioctl_request_t) <= sizeof(unsigned long));
-struct psr_error
-{
+struct psr_error {
ssize_t psr_result;
int psr_errno;
char psr_pad[sizeof(ssize_t) - sizeof(int)];
struct msghdr msg = { .msg_iov = iov, .msg_iovlen = __arraycount(iov) };
ssize_t len;
-#define PSR_ERROR(e) \
- do { \
- psr_error->psr_errno = (e); \
- goto error; \
+#define PSR_ERROR(e) \
+ do { \
+ psr_error->psr_errno = (e); \
+ goto error; \
} while (0 /* CONSTCOND */)
if (eloop_waitfd(fd) == -1)
ssize_t
ps_root_readerror(struct dhcpcd_ctx *ctx, void *data, size_t len)
{
- struct psr_ctx pc = {
- .psr_ctx = ctx,
+ struct psr_ctx pc = { .psr_ctx = ctx,
.psr_data = data,
.psr_datalen = len,
- .psr_mallocdata = false
- };
+ .psr_mallocdata = false };
ps_root_readerrorcb(&pc);
ssize_t
ps_root_mreaderror(struct dhcpcd_ctx *ctx, void **data, size_t *len)
{
- struct psr_ctx pc = {
- .psr_ctx = ctx,
+ struct psr_ctx pc = { .psr_ctx = ctx,
.psr_data = NULL,
.psr_datalen = 0,
- .psr_mallocdata = true
- };
+ .psr_mallocdata = true };
ps_root_readerrorcb(&pc);
}
static ssize_t
-ps_root_writeerror(struct dhcpcd_ctx *ctx, ssize_t result,
- void *data, size_t len)
+ps_root_writeerror(struct dhcpcd_ctx *ctx, ssize_t result, void *data,
+ size_t len)
{
struct psr_error psr = {
.psr_result = result,
/* Error sending the message? Try sending the error of sending. */
if (err == -1 && errno != EPIPE) {
- logerr("%s: result=%zd, data=%p, len=%zu",
- __func__, result, data, len);
+ logerr("%s: result=%zd, data=%p, len=%zu", __func__, result,
+ data, len);
psr.psr_result = err;
psr.psr_errno = errno;
psr.psr_datalen = 0;
int s, err;
/* Only allow these ioctls */
- switch(req) {
+ switch (req) {
#ifdef SIOCAIFADDR
- case SIOCAIFADDR: /* FALLTHROUGH */
- case SIOCDIFADDR: /* FALLTHROUGH */
+ case SIOCAIFADDR: /* FALLTHROUGH */
+ case SIOCDIFADDR: /* FALLTHROUGH */
#endif
#ifdef SIOCSIFHWADDR
- case SIOCSIFHWADDR: /* FALLTHROUGH */
+ case SIOCSIFHWADDR: /* FALLTHROUGH */
#endif
#ifdef SIOCGIFPRIORITY
- case SIOCGIFPRIORITY: /* FALLTHROUGH */
+ case SIOCGIFPRIORITY: /* FALLTHROUGH */
#endif
- case SIOCSIFFLAGS: /* FALLTHROUGH */
+ case SIOCSIFFLAGS: /* FALLTHROUGH */
case SIOCGIFMTU:
break;
default:
ps_root_run_script(struct dhcpcd_ctx *ctx, const void *data, size_t len)
{
const char *envbuf = data;
- char * const argv[] = { ctx->script, NULL };
+ char *const argv[] = { ctx->script, NULL };
pid_t pid;
int status;
static bool
ps_root_validpath(const struct dhcpcd_ctx *ctx, uint16_t cmd, const char *path)
{
-
/* Avoid a previous directory attack to avoid /proc/../
* dhcpcd should never use a path with double dots. */
if (strstr(path, "..") != NULL)
}
static ssize_t
-ps_root_dowritefile(const struct dhcpcd_ctx *ctx,
- mode_t mode, void *data, size_t len)
+ps_root_dowritefile(const struct dhcpcd_ctx *ctx, mode_t mode, void *data,
+ size_t len)
{
char *file = data, *nc;
static ssize_t
ps_root_monordm(uint64_t *rdm, size_t len)
{
-
if (len != sizeof(*rdm)) {
errno = EINVAL;
return -1;
#endif
#ifdef PRIVSEP_GETIFADDRS
-#define IFA_NADDRS 4
+#define IFA_NADDRS 4
static ssize_t
ps_root_dogetifaddrs(void **rdata, size_t *rlen)
{
sap = buf;
buf += ALIGN(sizeof(salen) * IFA_NADDRS);
-#define COPYINSA(addr) \
- do { \
- if ((addr) != NULL) \
- salen = sa_len((addr)); \
- else \
- salen = 0; \
- if (salen != 0) { \
- memcpy(sap, &salen, sizeof(salen)); \
- memcpy(buf, (addr), salen); \
- buf += ALIGN(salen); \
- } \
- sap += sizeof(salen); \
+#define COPYINSA(addr) \
+ do { \
+ if ((addr) != NULL) \
+ salen = sa_len((addr)); \
+ else \
+ salen = 0; \
+ if (salen != 0) { \
+ memcpy(sap, &salen, sizeof(salen)); \
+ memcpy(buf, (addr), salen); \
+ buf += ALIGN(salen); \
+ } \
+ sap += sizeof(salen); \
} while (0 /*CONSTCOND */)
COPYINSA(ifa->ifa_addr);
#ifdef BSD
if (ifa->ifa_addr != NULL &&
- ifa->ifa_addr->sa_family == AF_LINK)
- {
+ ifa->ifa_addr->sa_family == AF_LINK) {
salen = (socklen_t)sizeof(struct if_data);
memcpy(buf, ifa->ifa_data, salen);
buf += ALIGN(salen);
err = ps_sendpsmmsg(ctx, psp->psp_fd, psm, msg);
if (err == -1) {
- logerr("%s: failed to send message to pid %d",
- __func__, psp->psp_pid);
+ logerr("%s: failed to send message to pid %d", __func__,
+ psp->psp_pid);
ps_freeprocess(psp);
}
return 0;
switch (cmd) {
#ifdef INET
#ifdef ARP
- case PS_BPF_ARP: /* FALLTHROUGH */
+ case PS_BPF_ARP: /* FALLTHROUGH */
#endif
case PS_BPF_BOOTP:
return ps_bpf_cmd(ctx, psm, msg);
#endif
#ifdef INET6
#ifdef DHCP6
- case PS_DHCP6: /* FALLTHROUGH */
+ case PS_DHCP6: /* FALLTHROUGH */
#endif
case PS_ND:
return ps_inet_cmd(ctx, psm, msg);
}
break;
case PS_WRITEFILE:
- err = ps_root_dowritefile(ctx, (mode_t)psm->ps_flags,
- data, len);
+ err = ps_root_dowritefile(ctx, (mode_t)psm->ps_flags, data,
+ len);
break;
case PS_FILEMTIME:
err = filemtime(data, &mtime);
{
struct ps_process *psp = arg;
- if (ps_recvpsmsg(psp->psp_ctx, psp->psp_fd, events,
- ps_root_recvmsgcb, psp->psp_ctx) == -1)
+ if (ps_recvpsmsg(psp->psp_ctx, psp->psp_fd, events, ps_root_recvmsgcb,
+ psp->psp_ctx) == -1)
logerr(__func__);
}
return -1;
}
- return (int)ps_sendcmd(ctx, ctx->ps_data_fd, PS_DEV_IFCMD,
- flag, ifname, strlen(ifname) + 1);
+ return (int)ps_sendcmd(ctx, ctx->ps_data_fd, PS_DEV_IFCMD, flag, ifname,
+ strlen(ifname) + 1);
}
#endif
if (ctx->options & DHCPCD_MANAGER)
setproctitle("[privileged proxy]");
else
- setproctitle("[privileged proxy] %s%s%s",
- ctx->ifv[0],
+ setproctitle("[privileged proxy] %s%s%s", ctx->ifv[0],
ctx->options & DHCPCD_IPV4 ? " [ip4]" : "",
ctx->options & DHCPCD_IPV6 ? " [ip6]" : "");
ctx->options |= DHCPCD_PRIVSEPROOT;
if (ctx->options & DHCPCD_IPV4) {
int buflen = 1;
- ctx->udp_wfd = xsocket(PF_INET,
- SOCK_RAW | SOCK_CXNB, IPPROTO_UDP);
+ ctx->udp_wfd = xsocket(PF_INET, SOCK_RAW | SOCK_CXNB,
+ IPPROTO_UDP);
if (ctx->udp_wfd == -1)
logerr("%s: dhcp_openraw", __func__);
else if (setsockopt(ctx->udp_wfd, SOL_SOCKET, SO_RCVBUF,
- &buflen, sizeof(buflen)) == -1)
+ &buflen, sizeof(buflen)) == -1)
logerr("%s: setsockopt SO_RCVBUF DHCP", __func__);
}
#endif
ctx->nd_fd = ipv6nd_open(false);
if (ctx->nd_fd == -1)
logerr("%s: ipv6nd_open", __func__);
- else if (setsockopt(ctx->nd_fd, SOL_SOCKET, SO_RCVBUF,
- &buflen, sizeof(buflen)) == -1)
+ else if (setsockopt(ctx->nd_fd, SOL_SOCKET, SO_RCVBUF, &buflen,
+ sizeof(buflen)) == -1)
logerr("%s: setsockopt SO_RCVBUF ND", __func__);
}
#endif
if (ctx->dhcp6_wfd == -1)
logerr("%s: dhcp6_openraw", __func__);
else if (setsockopt(ctx->dhcp6_wfd, SOL_SOCKET, SO_RCVBUF,
- &buflen, sizeof(buflen)) == -1)
+ &buflen, sizeof(buflen)) == -1)
logerr("%s: setsockopt SO_RCVBUF DHCP6", __func__);
}
#endif
if (WIFEXITED(status) && WEXITSTATUS(status) != 0)
logerrx("%s%s%s exited unexpectedly from PID %d,"
- " code=%d",
- ifname, ifname[0] != '\0' ? ": " : "",
- name, pid, WEXITSTATUS(status));
+ " code=%d",
+ ifname, ifname[0] != '\0' ? ": " : "", name, pid,
+ WEXITSTATUS(status));
else if (WIFSIGNALED(status))
logerrx("%s%s%s exited unexpectedly from PID %d,"
- " signal=%s",
- ifname, ifname[0] != '\0' ? ": " : "",
- name, pid, strsignal(WTERMSIG(status)));
+ " signal=%s",
+ ifname, ifname[0] != '\0' ? ": " : "", name, pid,
+ strsignal(WTERMSIG(status)));
else
- logdebugx("%s%s%s exited from PID %d",
- ifname, ifname[0] != '\0' ? ": " : "",
- name, pid);
+ logdebugx("%s%s%s exited from PID %d", ifname,
+ ifname[0] != '\0' ? ": " : "", name, pid);
if (psp != NULL)
ps_freeprocess(psp);
return -1;
}
- switch(psm->ps_flags) {
+ switch (psm->ps_flags) {
case PS_DEV_IFADDED:
action = 1;
break;
struct dhcpcd_ctx *ctx = arg;
ssize_t err;
- switch(psm->ps_cmd) {
+ switch (psm->ps_cmd) {
#ifdef PLUGIN_DEV
case PS_DEV_IFCMD:
err = ps_root_devcb(ctx, psm, msg);
{
struct dhcpcd_ctx *ctx = arg;
- if (ps_recvpsmsg(ctx, ctx->ps_data_fd, events,
- ps_root_dispatchcb, ctx) == -1)
+ if (ps_recvpsmsg(ctx, ctx->ps_data_fd, events, ps_root_dispatchcb,
+ ctx) == -1)
logerr(__func__);
}
.psi_cmd = PS_ROOT,
};
struct ps_process *psp;
- int logfd[2] = { -1, -1}, datafd[2] = { -1, -1};
+ int logfd[2] = { -1, -1 }, datafd[2] = { -1, -1 };
pid_t pid;
if (xsocketpair(AF_UNIX, SOCK_SEQPACKET | SOCK_CXNB, 0, logfd) == -1)
return -1;
strlcpy(psp->psp_name, "privileged proxy", sizeof(psp->psp_name));
- pid = ps_startprocess(psp, ps_root_recvmsg, NULL,
- ps_root_startcb, PSF_ELOOP);
+ pid = ps_startprocess(psp, ps_root_recvmsg, NULL, ps_root_startcb,
+ PSF_ELOOP);
if (pid == -1)
return -1;
ctx->ps_log_fd = logfd[0]; /* Keep open to pass to processes */
ctx->ps_log_root_fd = logfd[1];
if (eloop_event_add(ctx->eloop, ctx->ps_log_root_fd, ELE_READ,
- ps_root_log, ctx) == -1)
+ ps_root_log, ctx) == -1)
return -1;
ctx->ps_data_fd = datafd[1];
close(datafd[0]);
ctx->ps_data_fd = datafd[0];
close(datafd[1]);
if (eloop_event_add(ctx->eloop, ctx->ps_data_fd, ELE_READ,
- ps_root_dispatch, ctx) == -1)
+ ps_root_dispatch, ctx) == -1)
return -1;
return pid;
void
ps_root_close(struct dhcpcd_ctx *ctx)
{
-
if_closesockets(ctx);
#ifdef INET
* So we just log the intent to exit.
* Even sending this will be a race to exit. */
if (psp) {
- logdebugx("%s%s%s will exit from PID %d",
- psp->psp_ifname,
- psp->psp_ifname[0] != '\0' ? ": " : "",
- psp->psp_name, psp->psp_pid);
+ logdebugx("%s%s%s will exit from PID %d", psp->psp_ifname,
+ psp->psp_ifname[0] != '\0' ? ": " : "", psp->psp_name,
+ psp->psp_pid);
if (ps_stopprocess(psp) == -1)
return -1;
ssize_t
ps_root_stopprocesses(struct dhcpcd_ctx *ctx)
{
-
if (!(IN_PRIVSEP_SE(ctx)))
return 0;
- if (ps_sendcmd(ctx, PS_ROOT_FD(ctx), PS_STOPPROCS, 0,
- NULL, 0) == -1)
+ if (ps_sendcmd(ctx, PS_ROOT_FD(ctx), PS_STOPPROCS, 0, NULL, 0) == -1)
return -1;
return ps_root_readerror(ctx, NULL, 0);
}
ssize_t
ps_root_script(struct dhcpcd_ctx *ctx, const void *data, size_t len)
{
-
- if (ps_sendcmd(ctx, PS_ROOT_FD(ctx), PS_SCRIPT,
- 0, data, len) == -1)
+ if (ps_sendcmd(ctx, PS_ROOT_FD(ctx), PS_SCRIPT, 0, data, len) == -1)
return -1;
return ps_root_readerror(ctx, NULL, 0);
}
ssize_t
ps_root_unlink(struct dhcpcd_ctx *ctx, const char *file)
{
-
- if (ps_sendcmd(ctx, PS_ROOT_FD(ctx), PS_UNLINK, 0,
- file, strlen(file) + 1) == -1)
+ if (ps_sendcmd(ctx, PS_ROOT_FD(ctx), PS_UNLINK, 0, file,
+ strlen(file) + 1) == -1)
return -1;
return ps_root_readerror(ctx, NULL, 0);
}
ssize_t
-ps_root_readfile(struct dhcpcd_ctx *ctx, const char *file,
- void *data, size_t len)
+ps_root_readfile(struct dhcpcd_ctx *ctx, const char *file, void *data,
+ size_t len)
{
- if (ps_sendcmd(ctx, PS_ROOT_FD(ctx), PS_READFILE, 0,
- file, strlen(file) + 1) == -1)
+ if (ps_sendcmd(ctx, PS_ROOT_FD(ctx), PS_READFILE, 0, file,
+ strlen(file) + 1) == -1)
return -1;
return ps_root_readerror(ctx, data, len);
}
}
memcpy(buf + flen, data, len);
- if (ps_sendcmd(ctx, PS_ROOT_FD(ctx), PS_WRITEFILE, mode,
- buf, flen + len) == -1)
+ if (ps_sendcmd(ctx, PS_ROOT_FD(ctx), PS_WRITEFILE, mode, buf,
+ flen + len) == -1)
return -1;
return ps_root_readerror(ctx, NULL, 0);
}
ssize_t
ps_root_filemtime(struct dhcpcd_ctx *ctx, const char *file, time_t *time)
{
-
- if (ps_sendcmd(ctx, PS_ROOT_FD(ctx), PS_FILEMTIME, 0,
- file, strlen(file) + 1) == -1)
+ if (ps_sendcmd(ctx, PS_ROOT_FD(ctx), PS_FILEMTIME, 0, file,
+ strlen(file) + 1) == -1)
return -1;
return ps_root_readerror(ctx, time, sizeof(*time));
}
ssize_t
ps_root_logreopen(struct dhcpcd_ctx *ctx)
{
-
- if (ps_sendcmd(ctx, PS_ROOT_FD(ctx), PS_LOGREOPEN, 0,
- NULL, 0) == -1)
+ if (ps_sendcmd(ctx, PS_ROOT_FD(ctx), PS_LOGREOPEN, 0, NULL, 0) == -1)
return -1;
return ps_root_readerror(ctx, NULL, 0);
}
size_t len;
ssize_t err;
- if (ps_sendcmd(ctx, PS_ROOT_FD(ctx),
- PS_GETIFADDRS, 0, NULL, 0) == -1)
+ if (ps_sendcmd(ctx, PS_ROOT_FD(ctx), PS_GETIFADDRS, 0, NULL, 0) == -1)
return -1;
err = ps_root_mreaderror(ctx, &buf, &len);
bp = buf;
*ifahead = (struct ifaddrs *)(void *)bp;
for (ifa = *ifahead; ifa != NULL; ifa = ifa->ifa_next) {
- if (len < ALIGN(sizeof(*ifa)) +
- ALIGN(IFNAMSIZ) + ALIGN(sizeof(salen) * IFA_NADDRS))
+ if (len < ALIGN(sizeof(*ifa)) + ALIGN(IFNAMSIZ) +
+ ALIGN(sizeof(salen) * IFA_NADDRS))
goto err;
bp += ALIGN(sizeof(*ifa));
ifa->ifa_name = bp;
bp += ALIGN(IFNAMSIZ);
sap = bp;
bp += ALIGN(sizeof(salen) * IFA_NADDRS);
- len -= ALIGN(sizeof(*ifa)) +
- ALIGN(IFNAMSIZ) + ALIGN(sizeof(salen) * IFA_NADDRS);
-
-#define COPYOUTSA(addr) \
- do { \
- memcpy(&salen, sap, sizeof(salen)); \
- if (len < salen) \
- goto err; \
- if (salen != 0) { \
- (addr) = (struct sockaddr *)(void *)bp; \
- bp += ALIGN(salen); \
- len -= ALIGN(salen); \
- } \
- sap += sizeof(salen); \
+ len -= ALIGN(sizeof(*ifa)) + ALIGN(IFNAMSIZ) +
+ ALIGN(sizeof(salen) * IFA_NADDRS);
+
+#define COPYOUTSA(addr) \
+ do { \
+ memcpy(&salen, sap, sizeof(salen)); \
+ if (len < salen) \
+ goto err; \
+ if (salen != 0) { \
+ (addr) = (struct sockaddr *)(void *)bp; \
+ bp += ALIGN(salen); \
+ len -= ALIGN(salen); \
+ } \
+ sap += sizeof(salen); \
} while (0 /* CONSTCOND */)
COPYOUTSA(ifa->ifa_addr);
int
ps_root_getauthrdm(struct dhcpcd_ctx *ctx, uint64_t *rdm)
{
-
- if (ps_sendcmd(ctx, PS_ROOT_FD(ctx), PS_AUTH_MONORDM, 0,
- rdm, sizeof(*rdm))== -1)
+ if (ps_sendcmd(ctx, PS_ROOT_FD(ctx), PS_AUTH_MONORDM, 0, rdm,
+ sizeof(*rdm)) == -1)
return -1;
return (int)ps_root_readerror(ctx, rdm, sizeof(*rdm));
}
int
ps_root_dev_initialised(struct dhcpcd_ctx *ctx, const char *ifname)
{
-
- if (ps_sendcmd(ctx, PS_ROOT_FD(ctx), PS_DEV_INITTED, 0,
- ifname, strlen(ifname) + 1)== -1)
+ if (ps_sendcmd(ctx, PS_ROOT_FD(ctx), PS_DEV_INITTED, 0, ifname,
+ strlen(ifname) + 1) == -1)
return -1;
return (int)ps_root_readerror(ctx, NULL, 0);
}
int
-ps_root_dev_listening(struct dhcpcd_ctx * ctx)
+ps_root_dev_listening(struct dhcpcd_ctx *ctx)
{
-
- if (ps_sendcmd(ctx, PS_ROOT_FD(ctx), PS_DEV_LISTENING,
- 0, NULL, 0) == -1)
+ if (ps_sendcmd(ctx, PS_ROOT_FD(ctx), PS_DEV_LISTENING, 0, NULL, 0) ==
+ -1)
return -1;
return (int)ps_root_readerror(ctx, NULL, 0);
}
ssize_t ps_root_indirectioctl(struct dhcpcd_ctx *, unsigned long, const char *,
void *, size_t);
ssize_t ps_root_ifignoregroup(struct dhcpcd_ctx *, const char *);
-ssize_t ps_root_sysctl(struct dhcpcd_ctx *, const int *, unsigned int,
- void *, size_t *, const void *, size_t);
+ssize_t ps_root_sysctl(struct dhcpcd_ctx *, const int *, unsigned int, void *,
+ size_t *, const void *, size_t);
#endif
#ifdef __linux__
ssize_t ps_root_sendnetlink(struct dhcpcd_ctx *, int, struct msghdr *);
}
ssize_t
-ps_root_os(struct ps_msghdr *psm, struct msghdr *msg,
- void **rdata, size_t *rlen, __unused bool *free_rdata)
+ps_root_os(struct ps_msghdr *psm, struct msghdr *msg, void **rdata,
+ size_t *rlen, __unused bool *free_rdata)
{
struct iovec *iov = msg->msg_iov;
void *data = iov->iov_base;
}
ssize_t
-ps_root_ioctl6(struct dhcpcd_ctx *ctx, unsigned long request, void *data, size_t len)
+ps_root_ioctl6(struct dhcpcd_ctx *ctx, unsigned long request, void *data,
+ size_t len)
{
-
- if (ps_sendcmd(ctx, PS_ROOT_FD(ctx), PS_IOCTL6,
- request, data, len) == -1)
+ if (ps_sendcmd(ctx, PS_ROOT_FD(ctx), PS_IOCTL6, request, data, len) ==
+ -1)
return -1;
return ps_root_readerror(ctx, data, len);
}
ssize_t
ps_root_route(struct dhcpcd_ctx *ctx, void *data, size_t len)
{
-
if (ps_sendcmd(ctx, PS_ROOT_FD(ctx), PS_ROUTE, 0, data, len) == -1)
return -1;
return ps_root_readerror(ctx, data, len);
* this in a script or something.
*/
+#include <sys/types.h>
#include <sys/resource.h>
#include <sys/socket.h>
#include <sys/stat.h>
-#include <sys/types.h>
#include <sys/wait.h>
#ifdef AF_LINK
#include <grp.h>
#include <paths.h>
#include <pwd.h>
-#include <stddef.h> /* For offsetof, struct padding debug */
#include <signal.h>
+#include <stddef.h> /* For offsetof, struct padding debug */
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#ifdef HAVE_CAPSICUM
#include <sys/capsicum.h>
#include <sys/procdesc.h>
+
#include <capsicum_helpers.h>
#endif
#ifdef HAVE_UTIL_H
/* CMSG_ALIGN is a Linux extension */
#ifndef CMSG_ALIGN
-#define CMSG_ALIGN(n) (CMSG_SPACE((n)) - CMSG_SPACE(0))
+#define CMSG_ALIGN(n) (CMSG_SPACE((n)) - CMSG_SPACE(0))
#endif
/* Calculate number of padding bytes to achieve 'struct cmsghdr' alignment */
#define CALC_CMSG_PADLEN(has_cmsg, pos) \
- ((has_cmsg) ? (socklen_t)(CMSG_ALIGN((pos)) - (pos)) : 0)
+ ((has_cmsg) ? (socklen_t)(CMSG_ALIGN((pos)) - (pos)) : 0)
int
ps_init(struct dhcpcd_ctx *ctx)
if (stat(pw->pw_dir, &st) == -1 || !S_ISDIR(st.st_mode)) {
ctx->options &= ~DHCPCD_PRIVSEP;
- logerrx("refusing chroot: %s: %s",
- PRIVSEP_USER, pw->pw_dir);
+ logerrx("refusing chroot: %s: %s", PRIVSEP_USER, pw->pw_dir);
errno = 0;
return -1;
}
ps_dropprivs(struct dhcpcd_ctx *ctx)
{
struct passwd *pw = ctx->ps_user;
- int fd_out = ctx->options & DHCPCD_DUMPLEASE ?
- STDOUT_FILENO : STDERR_FILENO;
+ int fd_out = ctx->options & DHCPCD_DUMPLEASE ? STDOUT_FILENO :
+ STDERR_FILENO;
if (ctx->options & DHCPCD_LAUNCHER)
#ifdef ASAN
if (chdir("/") == -1)
logerr("%s: chdir: /", __func__);
- if ((setgroups(1, &pw->pw_gid) == -1 ||
- setgid(pw->pw_gid) == -1 ||
- setuid(pw->pw_uid) == -1) &&
- (errno != EPERM || ctx->options & DHCPCD_FORKED))
- {
+ if ((setgroups(1, &pw->pw_gid) == -1 || setgid(pw->pw_gid) == -1 ||
+ setuid(pw->pw_uid) == -1) &&
+ (errno != EPERM || ctx->options & DHCPCD_FORKED)) {
logerr("failed to drop privileges");
return -1;
}
* Linux:seccomp, FreeBSD:capsicum, OpenBSD:pledge
* Solaris users are sadly out of luck on both counts.
*/
-#if defined(__NetBSD__) || defined(__DragonFly__) || \
- defined(HAVE_KQUEUE) || defined(HAVE_EPOLL)
+#if defined(__NetBSD__) || defined(__DragonFly__) || defined(HAVE_KQUEUE) || \
+ defined(HAVE_EPOLL)
/* The control proxy *does* need to create new fd's via accept(2). */
if (ctx->ps_ctl == NULL || ctx->ps_ctl->psp_pid != getpid()) {
if (setrlimit(RLIMIT_NOFILE, &rzero) == -1)
}
#endif
-#define DHC_NOCHKIO (DHCPCD_STARTED | DHCPCD_DAEMONISE)
+#define DHC_NOCHKIO (DHCPCD_STARTED | DHCPCD_DAEMONISE)
/* Prohibit writing to files.
* Obviously this won't work if we are using a logfile
* or redirecting stderr to a file. */
if ((ctx->options & DHC_NOCHKIO) == DHC_NOCHKIO ||
- (ctx->logfile == NULL && isatty(fd_out) == 1))
- {
+ (ctx->logfile == NULL && isatty(fd_out) == 1)) {
if (setrlimit(RLIMIT_FSIZE, &rzero) == -1)
logerr("setrlimit RLIMIT_FSIZE");
}
int minlen = (int)sizeof(struct ps_msg);
if (ps_setbuf0(fd, SO_RCVBUF, minlen) == -1 ||
- ps_setbuf0(fd, SO_SNDBUF, minlen * 2) == -1)
- {
+ ps_setbuf0(fd, SO_SNDBUF, minlen * 2) == -1) {
logerr(__func__);
return -1;
}
int
ps_setbuf_fdpair(int fd[])
{
-
if (ps_setbuf(fd[0]) == -1 || ps_setbuf(fd[1]) == -1)
return -1;
return 0;
{
cap_rights_t rights;
- cap_rights_init(&rights, CAP_READ, CAP_WRITE, CAP_EVENT,
- CAP_ACCEPT, CAP_FCNTL);
+ cap_rights_init(&rights, CAP_READ, CAP_WRITE, CAP_EVENT, CAP_ACCEPT,
+ CAP_FCNTL);
if (cap_rights_limit(fd, &rights) == -1 && errno != ENOSYS)
return -1;
return 0;
{
cap_rights_t rights;
- cap_rights_init(&rights, CAP_READ, CAP_WRITE, CAP_EVENT,
- CAP_GETSOCKOPT, CAP_SETSOCKOPT);
+ cap_rights_init(&rights, CAP_READ, CAP_WRITE, CAP_EVENT, CAP_GETSOCKOPT,
+ CAP_SETSOCKOPT);
if (cap_rights_limit(fd, &rights) == -1 && errno != ENOSYS)
return -1;
return 0;
int
ps_rights_limit_fdpair(int fd[])
{
-
if (ps_rights_limit_fd(fd[0]) == -1 || ps_rights_limit_fd(fd[1]) == -1)
return -1;
return 0;
if (!(events & ELE_HANGUP))
logerrx("%s: unexpected event 0x%04x", __func__, events);
- logdebugx("%s%s%s exited from PID %d",
- psp->psp_ifname, psp->psp_ifname[0] != '\0' ? ": " : "",
- psp->psp_name, psp->psp_pid);
+ logdebugx("%s%s%s exited from PID %d", psp->psp_ifname,
+ psp->psp_ifname[0] != '\0' ? ": " : "", psp->psp_name,
+ psp->psp_pid);
ps_freeprocess(psp);
ps_startprocess(struct ps_process *psp,
void (*recv_msg)(void *, unsigned short),
void (*recv_unpriv_msg)(void *, unsigned short),
- int (*callback)(struct ps_process *),
- unsigned int flags)
+ int (*callback)(struct ps_process *), unsigned int flags)
{
struct dhcpcd_ctx *ctx = psp->psp_ctx;
int fd[2];
if (recv_unpriv_msg == NULL)
;
else if (eloop_event_add(ctx->eloop, psp->psp_fd, ELE_READ,
- recv_unpriv_msg, psp) == -1)
- {
- logerr("%s: eloop_event_add fd %d",
- __func__, psp->psp_fd);
+ recv_unpriv_msg, psp) == -1) {
+ logerr("%s: eloop_event_add fd %d", __func__,
+ psp->psp_fd);
return -1;
}
#ifdef HAVE_CAPSICUM
if (eloop_event_add(ctx->eloop, psp->psp_pfd, ELE_HANGUP,
- ps_processhangup, psp) == -1)
- {
- logerr("%s: eloop_event_add pfd %d",
- __func__, psp->psp_pfd);
+ ps_processhangup, psp) == -1) {
+ logerr("%s: eloop_event_add pfd %d", __func__,
+ psp->psp_pfd);
return -1;
}
#endif
logsetfd(ctx->ps_log_fd);
#ifdef DEBUG_FD
- logerrx("pid %d log_fd=%d data_fd=%d psp_fd=%d",
- getpid(), ctx->ps_log_fd, ctx->ps_data_fd, psp->psp_fd);
+ logerrx("pid %d log_fd=%d data_fd=%d psp_fd=%d", getpid(),
+ ctx->ps_log_fd, ctx->ps_data_fd, psp->psp_fd);
#endif
if (ctx->fork_fd != -1) {
#endif
}
- if (eloop_event_add(ctx->eloop, psp->psp_fd, ELE_READ,
- recv_msg, psp) == -1)
- {
+ if (eloop_event_add(ctx->eloop, psp->psp_fd, ELE_READ, recv_msg, psp) ==
+ -1) {
logerr("%s: eloop_event_add", __func__);
goto errexit;
}
psp->psp_started = false;
#ifdef PRIVSEP_DEBUG
- logdebugx("%s: me=%d pid=%d fd=%d %s", __func__,
- getpid(), psp->psp_pid, psp->psp_fd, psp->psp_name);
+ logdebugx("%s: me=%d pid=%d fd=%d %s", __func__, getpid(), psp->psp_pid,
+ psp->psp_fd, psp->psp_name);
#endif
if (psp->psp_fd != -1) {
int
ps_entersandbox(const char *_pledge, const char **sandbox)
{
-
#if !defined(HAVE_PLEDGE)
UNUSED(_pledge);
#endif
#ifdef PRIVSEP_RIGHTS
if ((ctx->pf_inet_fd != -1 &&
- ps_rights_limit_ioctl(ctx->pf_inet_fd) == -1) ||
- ps_rights_limit_stdio() == -1)
- {
+ ps_rights_limit_ioctl(ctx->pf_inet_fd) == -1) ||
+ ps_rights_limit_stdio() == -1) {
logerr("%s: cap_rights_limit", __func__);
return -1;
}
logerr("%s: %s", __func__, sandbox);
return -1;
} else if (ctx->options & DHCPCD_LAUNCHER ||
- ((!(ctx->options & DHCPCD_DAEMONISE)) &&
- ctx->options & DHCPCD_MANAGER))
+ ((!(ctx->options & DHCPCD_DAEMONISE)) &&
+ ctx->options & DHCPCD_MANAGER))
logdebugx("sandbox: %s", sandbox);
return 0;
}
{
int r, ret = 0;
- if (!(ctx->options & DHCPCD_PRIVSEP) ||
- ctx->options & DHCPCD_FORKED ||
+ if (!(ctx->options & DHCPCD_PRIVSEP) || ctx->options & DHCPCD_FORKED ||
ctx->eloop == NULL)
return 0;
ctx->options |= DHCPCD_EXITING;
if (eloop_timeout_add_sec(ctx->eloop, PS_PROCESS_TIMEOUT,
- ps_process_timeout, ctx) == -1)
+ ps_process_timeout, ctx) == -1)
logerr("%s: eloop_timeout_add_sec", __func__);
#ifdef HAVE_CAPSICUM
TAILQ_FOREACH(psp, &ctx->ps_processes, next) {
if (psp->psp_pfd == -1)
continue;
- if (eloop_event_add(ctx->eloop, psp->psp_pfd,
- ELE_HANGUP, ps_processhangup, psp) == -1)
- logerr("%s: eloop_event_add pfd %d",
- __func__, psp->psp_pfd);
+ if (eloop_event_add(ctx->eloop, psp->psp_pfd, ELE_HANGUP,
+ ps_processhangup, psp) == -1)
+ logerr("%s: eloop_event_add pfd %d", __func__,
+ psp->psp_pfd);
}
#endif
}
int
-ps_unrollmsg(struct msghdr *msg, struct ps_msghdr *psm,
- const void *data, size_t len)
+ps_unrollmsg(struct msghdr *msg, struct ps_msghdr *psm, const void *data,
+ size_t len)
{
uint8_t *datap, *namep, *controlp;
- socklen_t cmsg_padlen =
- CALC_CMSG_PADLEN(psm->ps_controllen, psm->ps_namelen);
+ socklen_t cmsg_padlen = CALC_CMSG_PADLEN(psm->ps_controllen,
+ psm->ps_namelen);
namep = UNCONST(data);
controlp = namep + psm->ps_namelen + cmsg_padlen;
}
ssize_t
-ps_sendpsmmsg(struct dhcpcd_ctx *ctx, int fd,
- struct ps_msghdr *psm, const struct msghdr *msg)
+ps_sendpsmmsg(struct dhcpcd_ctx *ctx, int fd, struct ps_msghdr *psm,
+ const struct msghdr *msg)
{
long padding[1] = { 0 };
struct iovec iov[] = {
{ .iov_base = UNCONST(psm), .iov_len = sizeof(*psm) },
- { .iov_base = NULL, }, /* name */
- { .iov_base = NULL, }, /* control padding */
- { .iov_base = NULL, }, /* control */
- { .iov_base = NULL, }, /* payload 1 */
- { .iov_base = NULL, }, /* payload 2 */
- { .iov_base = NULL, }, /* payload 3 */
+ {
+ .iov_base = NULL,
+ }, /* name */
+ {
+ .iov_base = NULL,
+ }, /* control padding */
+ {
+ .iov_base = NULL,
+ }, /* control */
+ {
+ .iov_base = NULL,
+ }, /* payload 1 */
+ {
+ .iov_base = NULL,
+ }, /* payload 2 */
+ {
+ .iov_base = NULL,
+ }, /* payload 3 */
};
struct msghdr m = { .msg_iov = iov, .msg_iovlen = 1 };
ssize_t len;
iovp++;
m.msg_iovlen++;
- cmsg_padlen =
- CALC_CMSG_PADLEN(msg->msg_controllen, msg->msg_namelen);
+ cmsg_padlen = CALC_CMSG_PADLEN(msg->msg_controllen,
+ msg->msg_namelen);
assert(cmsg_padlen <= sizeof(padding));
iovp->iov_len = cmsg_padlen;
iovp->iov_base = cmsg_padlen != 0 ? padding : NULL;
for (i = 0; i < (int)msg->msg_iovlen; i++) {
if ((size_t)(m.msg_iovlen++) > __arraycount(iov)) {
- errno = ENOBUFS;
+ errno = ENOBUFS;
return -1;
}
iovp->iov_base = msg->msg_iov[i].iov_base;
}
ssize_t
-ps_sendpsmdata(struct dhcpcd_ctx *ctx, int fd,
- struct ps_msghdr *psm, const void *data, size_t len)
+ps_sendpsmdata(struct dhcpcd_ctx *ctx, int fd, struct ps_msghdr *psm,
+ const void *data, size_t len)
{
struct iovec iov[] = {
{ .iov_base = UNCONST(data), .iov_len = len },
};
struct msghdr msg = {
- .msg_iov = iov, .msg_iovlen = 1,
+ .msg_iov = iov,
+ .msg_iovlen = 1,
};
return ps_sendpsmmsg(ctx, fd, psm, &msg);
}
-
ssize_t
ps_sendmsg(struct dhcpcd_ctx *ctx, int fd, uint16_t cmd, unsigned long flags,
const struct msghdr *msg)
for (i = 0; i < (size_t)msg->msg_iovlen; i++)
psm.ps_datalen += msg->msg_iov[i].iov_len;
-#if 0 /* For debugging structure padding. */
+#if 0 /* For debugging structure padding. */
logerrx("psa.family %lu %zu", offsetof(struct ps_addr, psa_family), sizeof(psm.ps_id.psi_addr.psa_family));
logerrx("psa.pad %lu %zu", offsetof(struct ps_addr, psa_pad), sizeof(psm.ps_id.psi_addr.psa_pad));
logerrx("psa.psa_u %lu %zu", offsetof(struct ps_addr, psa_u), sizeof(psm.ps_id.psi_addr.psa_u));
.ps_cmd = cmd,
.ps_flags = flags,
};
- struct iovec iov[] = {
- { .iov_base = UNCONST(data), .iov_len = len }
- };
+ struct iovec iov[] = { { .iov_base = UNCONST(data), .iov_len = len } };
struct msghdr msg = {
- .msg_iov = iov, .msg_iovlen = 1,
+ .msg_iov = iov,
+ .msg_iovlen = 1,
};
return ps_sendpsmmsg(ctx, fd, &psm, &msg);
}
ssize_t
-ps_sendcmdmsg(struct dhcpcd_ctx *ctx, int fd, uint16_t cmd,
- unsigned long flags, const struct msghdr *msg)
+ps_sendcmdmsg(struct dhcpcd_ctx *ctx, int fd, uint16_t cmd, unsigned long flags,
+ const struct msghdr *msg)
{
struct ps_msghdr psm = { .ps_cmd = cmd, .ps_flags = flags };
struct sockaddr_storage ss = { .ss_family = AF_UNSPEC };
uint8_t controlbuf[sizeof(struct sockaddr_storage)] = { 0 };
uint8_t databuf[64 * 1024];
- struct iovec iov[] = {
- { .iov_base = databuf, .iov_len = sizeof(databuf) }
- };
+ struct iovec iov[] = { { .iov_base = databuf,
+ .iov_len = sizeof(databuf) } };
struct msghdr msg = {
- .msg_name = &ss, .msg_namelen = sizeof(ss),
- .msg_control = controlbuf, .msg_controllen = sizeof(controlbuf),
- .msg_iov = iov, .msg_iovlen = 1,
+ .msg_name = &ss,
+ .msg_namelen = sizeof(ss),
+ .msg_control = controlbuf,
+ .msg_controllen = sizeof(controlbuf),
+ .msg_iov = iov,
+ .msg_iovlen = 1,
};
ssize_t len;
TAILQ_FOREACH(psp, &ctx->ps_processes, next) {
if (psp->psp_pid == getpid())
continue;
- if (ps_sendcmd(psp->psp_ctx, psp->psp_fd, PS_DAEMONISED,
- 0, NULL, 0) == -1)
+ if (ps_sendcmd(psp->psp_ctx, psp->psp_fd, PS_DAEMONISED, 0,
+ NULL, 0) == -1)
err = -1;
}
}
if (stop) {
-stop:
+ stop:
ctx->options |= DHCPCD_EXITING;
#ifdef PRIVSEP_DEBUG
logdebugx("process %d stopping", getpid());
#ifndef PRIVSEP_H
#define PRIVSEP_H
-//#define PRIVSEP_DEBUG
+// #define PRIVSEP_DEBUG
/* Start flags */
-#define PSF_DROPPRIVS 0x01
-#define PSF_ELOOP 0x02
+#define PSF_DROPPRIVS 0x01
+#define PSF_ELOOP 0x02
/* Protocols */
-#define PS_BOOTP 0x0001
-#define PS_ND 0x0002
-#define PS_DHCP6 0x0003
-#define PS_BPF_BOOTP 0x0004
-#define PS_BPF_ARP 0x0005
+#define PS_BOOTP 0x0001
+#define PS_ND 0x0002
+#define PS_DHCP6 0x0003
+#define PS_BPF_BOOTP 0x0004
+#define PS_BPF_ARP 0x0005
/* Generic commands */
-#define PS_IOCTL 0x0010
-#define PS_ROUTE 0x0011 /* Also used for NETLINK */
-#define PS_SCRIPT 0x0012
-#define PS_UNLINK 0x0013
-#define PS_READFILE 0x0014
-#define PS_WRITEFILE 0x0015
-#define PS_FILEMTIME 0x0016
-#define PS_AUTH_MONORDM 0x0017
-#define PS_CTL 0x0018
-#define PS_CTL_EOF 0x0019
-#define PS_LOGREOPEN 0x0020
-#define PS_STOPPROCS 0x0021
-#define PS_DAEMONISED 0x0022
+#define PS_IOCTL 0x0010
+#define PS_ROUTE 0x0011 /* Also used for NETLINK */
+#define PS_SCRIPT 0x0012
+#define PS_UNLINK 0x0013
+#define PS_READFILE 0x0014
+#define PS_WRITEFILE 0x0015
+#define PS_FILEMTIME 0x0016
+#define PS_AUTH_MONORDM 0x0017
+#define PS_CTL 0x0018
+#define PS_CTL_EOF 0x0019
+#define PS_LOGREOPEN 0x0020
+#define PS_STOPPROCS 0x0021
+#define PS_DAEMONISED 0x0022
/* Domains */
-#define PS_ROOT 0x0101
-#define PS_INET 0x0102
-#define PS_CONTROL 0x0103
+#define PS_ROOT 0x0101
+#define PS_INET 0x0102
+#define PS_CONTROL 0x0103
/* BSD Commands */
-#define PS_IOCTLLINK 0x0201
-#define PS_IOCTL6 0x0202
-#define PS_IOCTLINDIRECT 0x0203
-#define PS_IP6FORWARDING 0x0204
-#define PS_GETIFADDRS 0x0205
-#define PS_IFIGNOREGRP 0x0206
-#define PS_SYSCTL 0x0207
+#define PS_IOCTLLINK 0x0201
+#define PS_IOCTL6 0x0202
+#define PS_IOCTLINDIRECT 0x0203
+#define PS_IP6FORWARDING 0x0204
+#define PS_GETIFADDRS 0x0205
+#define PS_IFIGNOREGRP 0x0206
+#define PS_SYSCTL 0x0207
/* Dev Commands */
-#define PS_DEV_LISTENING 0x1001
-#define PS_DEV_INITTED 0x1002
-#define PS_DEV_IFCMD 0x1003
+#define PS_DEV_LISTENING 0x1001
+#define PS_DEV_INITTED 0x1002
+#define PS_DEV_IFCMD 0x1003
/* Dev Interface Commands (via flags) */
-#define PS_DEV_IFADDED 0x0001
-#define PS_DEV_IFREMOVED 0x0002
-#define PS_DEV_IFUPDATED 0x0003
+#define PS_DEV_IFADDED 0x0001
+#define PS_DEV_IFREMOVED 0x0002
+#define PS_DEV_IFUPDATED 0x0003
/* Control Type (via flags) */
-#define PS_CTL_PRIV 0x0004
-#define PS_CTL_UNPRIV 0x0005
+#define PS_CTL_PRIV 0x0004
+#define PS_CTL_UNPRIV 0x0005
/* Sysctl Needs (via flags) */
-#define PS_SYSCTL_OLEN 0x0001
-#define PS_SYSCTL_ODATA 0x0002
+#define PS_SYSCTL_OLEN 0x0001
+#define PS_SYSCTL_ODATA 0x0002
/* Process commands */
-#define PS_START 0x4000
-#define PS_STOP 0x8000
+#define PS_START 0x4000
+#define PS_STOP 0x8000
/* Max INET message size + meta data for IPC */
-#define PS_BUFLEN ((64 * 1024) + \
- sizeof(struct ps_msghdr) + \
- sizeof(struct msghdr) + \
- CMSG_SPACE(sizeof(struct in6_pktinfo) + \
- sizeof(int)))
+#define PS_BUFLEN \
+ ((64 * 1024) + sizeof(struct ps_msghdr) + sizeof(struct msghdr) + \
+ CMSG_SPACE(sizeof(struct in6_pktinfo) + sizeof(int)))
-#define PSP_NAMESIZE 16 + INET_MAX_ADDRSTRLEN
+#define PSP_NAMESIZE 16 + INET_MAX_ADDRSTRLEN
/* Handy macro to work out if in the privsep engine or not. */
-#define IN_PRIVSEP(ctx) \
- ((ctx)->options & DHCPCD_PRIVSEP)
-#define IN_PRIVSEP_SE(ctx) \
+#define IN_PRIVSEP(ctx) ((ctx)->options & DHCPCD_PRIVSEP)
+#define IN_PRIVSEP_SE(ctx) \
(((ctx)->options & (DHCPCD_PRIVSEP | DHCPCD_FORKED)) == DHCPCD_PRIVSEP)
-#define PS_PROCESS_TIMEOUT 5 /* seconds to stop all processes */
+#define PS_PROCESS_TIMEOUT 5 /* seconds to stop all processes */
#ifdef PRIVSEP
-# ifdef HAVE_CAPSICUM
-# define PRIVSEP_RIGHTS
-# endif
+#ifdef HAVE_CAPSICUM
+#define PRIVSEP_RIGHTS
+#endif
/* Pledge and Capsicum deny nearly all sysctls.
* Linux needs directory access to sysctls. */
-# if defined(HAVE_CAPSICUM) ||defined(HAVE_PLEDGE) || defined(__linux__)
-# define PRIVSEP_SYSCTL
-# endif
+#if defined(HAVE_CAPSICUM) || defined(HAVE_PLEDGE) || defined(__linux__)
+#define PRIVSEP_SYSCTL
+#endif
#endif
#define PS_ROOT_FD(ctx) ((ctx)->ps_root ? (ctx)->ps_root->psp_fd : -1)
#if !defined(DISABLE_SECCOMP) && defined(__linux__)
-# include <linux/version.h>
-# if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0)
-# define HAVE_SECCOMP
-# endif
+#include <linux/version.h>
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0)
+#define HAVE_SECCOMP
+#endif
#endif
-#include "config.h"
#include "arp.h"
+#include "config.h"
#include "dhcp.h"
#include "dhcpcd.h"
struct in_addr psau_in_addr;
struct in6_addr psau_in6_addr;
} psa_u;
-#define psa_in_addr psa_u.psau_in_addr
-#define psa_in6_addr psa_u.psau_in6_addr
+#define psa_in_addr psa_u.psau_in_addr
+#define psa_in6_addr psa_u.psau_in6_addr
};
/* Uniquely identify a process */
ssize_t ps_daemonised(struct dhcpcd_ctx *);
int ps_unrollmsg(struct msghdr *, struct ps_msghdr *, const void *, size_t);
-ssize_t ps_sendpsmmsg(struct dhcpcd_ctx *, int,
- struct ps_msghdr *, const struct msghdr *);
-ssize_t ps_sendpsmdata(struct dhcpcd_ctx *, int,
- struct ps_msghdr *, const void *, size_t);
+ssize_t ps_sendpsmmsg(struct dhcpcd_ctx *, int, struct ps_msghdr *,
+ const struct msghdr *);
+ssize_t ps_sendpsmdata(struct dhcpcd_ctx *, int, struct ps_msghdr *,
+ const void *, size_t);
ssize_t ps_sendmsg(struct dhcpcd_ctx *, int, uint16_t, unsigned long,
const struct msghdr *);
ssize_t ps_sendcmd(struct dhcpcd_ctx *, int, uint16_t, unsigned long,
ssize_t (*callback)(void *, struct ps_msghdr *, struct msghdr *), void *);
/* Internal privsep functions. */
-int ps_setbuf_fdpair(int []);
+int ps_setbuf_fdpair(int[]);
#ifdef PRIVSEP_RIGHTS
int ps_rights_limit_ioctl(int);
int ps_rights_limit_fd_rdonly(int);
int ps_rights_limit_fd_sockopt(int);
int ps_rights_limit_fd(int);
-int ps_rights_limit_fdpair(int []);
+int ps_rights_limit_fdpair(int[]);
#endif
#ifdef HAVE_SECCOMP
pid_t ps_startprocess(struct ps_process *,
void (*recv_msg)(void *, unsigned short),
void (*recv_unpriv_msg)(void *, unsigned short),
- int (*callback)(struct ps_process *),
- unsigned int);
+ int (*callback)(struct ps_process *), unsigned int);
int ps_stopprocess(struct ps_process *);
struct ps_process *ps_findprocess(struct dhcpcd_ctx *, struct ps_id *);
struct ps_process *ps_findprocesspid(struct dhcpcd_ctx *, pid_t);
#include <sys/queue.h>
/* Dragonfly BSD needs this :( */
#if !defined(TAILQ_FOREACH_SAFE) && defined(TAILQ_FOREACH_MUTABLE)
-#define TAILQ_FOREACH_SAFE TAILQ_FOREACH_MUTABLE
+#define TAILQ_FOREACH_SAFE TAILQ_FOREACH_MUTABLE
#endif
#else
#include "../vendor/queue.h"
#include <syslog.h>
#include <unistd.h>
-#include "config.h"
#include "common.h"
+#include "config.h"
#include "dhcpcd.h"
-#include "if.h"
#include "if-options.h"
+#include "if.h"
#include "ipv4.h"
#include "ipv4ll.h"
#include "ipv6.h"
#define RB_TREE_NEXT(T, N) rb_tree_iterate((T), (N), RB_DIR_RIGHT)
#define RB_TREE_PREV(T, N) rb_tree_iterate((T), (N), RB_DIR_LEFT)
#endif
-#define RB_TREE_FOREACH_SAFE(N, T, S) \
- for ((N) = RB_TREE_MIN(T); \
- (N) && ((S) = RB_TREE_NEXT((T), (N)), 1); \
- (N) = (S))
-#define RB_TREE_FOREACH_REVERSE_SAFE(N, T, S) \
- for ((N) = RB_TREE_MAX(T); \
- (N) && ((S) = RB_TREE_PREV((T), (N)), 1); \
- (N) = (S))
+#define RB_TREE_FOREACH_SAFE(N, T, S) \
+ for ((N) = RB_TREE_MIN(T); (N) && ((S) = RB_TREE_NEXT((T), (N)), 1); \
+ (N) = (S))
+#define RB_TREE_FOREACH_REVERSE_SAFE(N, T, S) \
+ for ((N) = RB_TREE_MAX(T); (N) && ((S) = RB_TREE_PREV((T), (N)), 1); \
+ (N) = (S))
#endif
/*
* If we change the route, we want to flush anything dynamically created.
*/
#if defined(BSD) && !defined(RTF_CLONING) && defined(RTF_CONNECTED)
-#define RTF_CLONING RTF_CONNECTED
+#define RTF_CLONING RTF_CONNECTED
#endif
#ifdef RT_FREE_ROUTE_TABLE_STATS
#endif
static void
-rt_maskedaddr(struct sockaddr *dst,
- const struct sockaddr *addr, const struct sockaddr *netmask)
+rt_maskedaddr(struct sockaddr *dst, const struct sockaddr *addr,
+ const struct sockaddr *netmask)
{
const char *addrp = addr->sa_data, *netmaskp = netmask->sa_data;
char *dstp = dst->sa_data;
static int
rt_cmp_netmask(const struct rt *rt1, const struct rt *rt2)
{
-
if (rt1->rt_flags & RTF_HOST && rt2->rt_flags & RTF_HOST)
return 0;
return sa_cmp(&rt1->rt_netmask, &rt2->rt_netmask);
/* IPv4LL routes always come last */
if (rt1->rt_dflags & RTDF_IPV4LL && !(rt2->rt_dflags & RTDF_IPV4LL))
return -1;
- else if (!(rt1->rt_dflags & RTDF_IPV4LL) && rt2->rt_dflags & RTDF_IPV4LL)
+ else if (!(rt1->rt_dflags & RTDF_IPV4LL) &&
+ rt2->rt_dflags & RTDF_IPV4LL)
return 1;
#endif
static int
rt_compare_free(__unused void *context, const void *node1, const void *node2)
{
-
return node1 == node2 ? 0 : node1 < node2 ? -1 : 1;
}
void
rt_init(struct dhcpcd_ctx *ctx)
{
-
rb_tree_init(&ctx->routes, &rt_compare_os_ops);
#ifdef RT_FREE_ROUTE_TABLE
rb_tree_init(&ctx->froutes, &rt_compare_free_ops);
bool
rt_is_default(const struct rt *rt)
{
-
return sa_is_unspecified(&rt->rt_dest) &&
sa_is_unspecified(&rt->rt_netmask);
}
if (rt->rt_flags & RTF_HOST) {
if (gateway_unspec)
- logmessage(loglevel, "%s: %s host route to %s",
- ifname, cmd, dest);
+ logmessage(loglevel, "%s: %s host route to %s", ifname,
+ cmd, dest);
else
logmessage(loglevel, "%s: %s host route to %s via %s",
ifname, cmd, dest, gateway);
} else if (rt_is_default(rt)) {
if (gateway_unspec)
- logmessage(loglevel, "%s: %s default route",
- ifname, cmd);
+ logmessage(loglevel, "%s: %s default route", ifname,
+ cmd);
else
logmessage(loglevel, "%s: %s default route via %s",
ifname, cmd, gateway);
} else if (gateway_unspec)
- logmessage(loglevel, "%s: %s%s route to %s/%d",
- ifname, cmd,
- rt->rt_flags & RTF_REJECT ? " reject" : "",
- dest, prefix);
+ logmessage(loglevel, "%s: %s%s route to %s/%d", ifname, cmd,
+ rt->rt_flags & RTF_REJECT ? " reject" : "", dest, prefix);
else
- logmessage(loglevel, "%s: %s%s route to %s/%d via %s",
- ifname, cmd,
- rt->rt_flags & RTF_REJECT ? " reject" : "",
- dest, prefix, gateway);
+ logmessage(loglevel, "%s: %s%s route to %s/%d via %s", ifname,
+ cmd, rt->rt_flags & RTF_REJECT ? " reject" : "", dest,
+ prefix, gateway);
}
void
assert(&ctx->froutes != rts);
#endif
- RB_TREE_FOREACH_SAFE(rt, rts, rtn) {
- if (af != AF_UNSPEC &&
- rt->rt_dest.sa_family != af &&
+ RB_TREE_FOREACH_SAFE(rt, rts, rtn)
+ {
+ if (af != AF_UNSPEC && rt->rt_dest.sa_family != af &&
rt->rt_gateway.sa_family != af)
continue;
rb_tree_remove_node(rts, rt);
void
rt_dispose(struct dhcpcd_ctx *ctx)
{
-
assert(ctx != NULL);
rt_headfree(&ctx->routes);
#ifdef RT_FREE_ROUTE_TABLE
#endif
} else
#endif
- if ((rt = malloc(sizeof(*rt))) == NULL) {
+ if ((rt = malloc(sizeof(*rt))) == NULL) {
logerr(__func__);
return NULL;
}
void
rt_setif(struct rt *rt, struct interface *ifp)
{
-
assert(rt != NULL);
assert(ifp != NULL);
rt->rt_ifp = ifp;
struct rt *
rt_proto_add_ctx(rb_tree_t *tree, struct rt *rt, struct dhcpcd_ctx *ctx)
{
-
rt->rt_order = ctx->rt_order++;
if (rb_tree_insert_node(tree, rt) == rt)
return rt;
struct rt *
rt_proto_add(rb_tree_t *tree, struct rt *rt)
{
-
- assert (rt->rt_ifp != NULL);
+ assert(rt->rt_ifp != NULL);
return rt_proto_add_ctx(tree, rt, rt->rt_ifp->ctx);
}
if (ifp == NULL)
return;
ctx = ifp->ctx;
- RB_TREE_FOREACH_SAFE(rt, &ctx->routes, rtn) {
+ RB_TREE_FOREACH_SAFE(rt, &ctx->routes, rtn)
+ {
if (rt->rt_ifp == ifp) {
rb_tree_remove_node(&ctx->routes, rt);
rt_free(rt);
ctx = rt->rt_ifp->ctx;
- switch(cmd) {
+ switch (cmd) {
case RTM_DELETE:
f = rb_tree_find_node(&ctx->routes, rt);
if (f != NULL) {
* and get the VPN to inject the default route into dhcpcd somehow.
*/
if (((nrt->rt_ifp->active &&
- !(nrt->rt_ifp->options->options & DHCPCD_GATEWAY)) ||
- (!nrt->rt_ifp->active && !(ctx->options & DHCPCD_GATEWAY))) &&
+ !(nrt->rt_ifp->options->options & DHCPCD_GATEWAY)) ||
+ (!nrt->rt_ifp->active && !(ctx->options & DHCPCD_GATEWAY))) &&
sa_is_unspecified(&nrt->rt_dest) &&
sa_is_unspecified(&nrt->rt_netmask))
return false;
krt = rb_tree_find_node(kroutes, nrt);
- if (krt != NULL &&
- krt->rt_ifp == nrt->rt_ifp &&
+ if (krt != NULL && krt->rt_ifp == nrt->rt_ifp &&
/* Only test flags dhcpcd controls */
(krt->rt_flags & (RTF_HOST | RTF_REJECT)) == nrt->rt_flags &&
#ifdef HAVE_ROUTE_METRIC
sa_cmp(&krt->rt_dest, &nrt->rt_dest) == 0 &&
rt_cmp_netmask(krt, nrt) == 0 &&
sa_cmp(&krt->rt_gateway, &nrt->rt_gateway) == 0 &&
- (nrt->rt_ifp->flags & IFF_LOOPBACK || rt_cmp_mtu(krt, nrt) == 0))
- {
+ (nrt->rt_ifp->flags & IFF_LOOPBACK || rt_cmp_mtu(krt, nrt) == 0)) {
#ifdef HAVE_ROUTE_LIFETIME
if (rt_cmp_lifetime(krt, nrt) == 0) {
rt_desc(LOG_DEBUG, "keeping", krt);
#endif
/* Reject routes have a gateway, non reject routes don't.
* BSD kernels at least preserve RTF_GATEWAY so we need to punt it. */
- if (change && krt->rt_flags & RTF_REJECT && !(nrt->rt_flags & RTF_REJECT))
+ if (change && krt->rt_flags & RTF_REJECT &&
+ !(nrt->rt_flags & RTF_REJECT))
change = false;
if (change) {
static int
rt_cmp(const struct rt *r1, const struct rt *r2)
{
-
if (r1->rt_ifp == r2->rt_ifp &&
#ifdef HAVE_ROUTE_METRIC
r1->rt_metric == r2->rt_metric &&
rt_doroute(rb_tree_t *kroutes, struct rt *rt)
{
struct dhcpcd_ctx *ctx;
- struct rt *or;
+ struct rt * or ;
ctx = rt->rt_ifp->ctx;
/* Do we already manage it? */
if (or != NULL) {
if (rt->rt_dflags & RTDF_FAKE)
return true;
- if (or->rt_dflags & RTDF_FAKE ||
- rt_cmp(rt, or) != 0 ||
+ if (or->rt_dflags & RTDF_FAKE || rt_cmp(rt, or) != 0 ||
(rt->rt_ifa.sa_family != AF_UNSPEC &&
- sa_cmp(&or->rt_ifa, &rt->rt_ifa) != 0) ||
+ sa_cmp(&or->rt_ifa, &rt->rt_ifa) != 0) ||
#ifdef HAVE_ROUTE_LIFETIME
rt_cmp_lifetime(rt, or) != 0 ||
#endif
- rt_cmp_mtu(rt, or) != 0)
- {
+ rt_cmp_mtu(rt, or) != 0) {
if (!rt_add(kroutes, rt, or))
return false;
}
ctx->rt_missfilterlen = 0;
#endif
- RB_TREE_FOREACH_SAFE(rt, &routes, rtn) {
+ RB_TREE_FOREACH_SAFE(rt, &routes, rtn)
+ {
if (rt->rt_ifp->active) {
if (!(rt->rt_ifp->options->options & DHCPCD_CONFIGURE))
continue;
logerr("if_missfilter");
#endif
if ((rt->rt_dest.sa_family != af &&
- rt->rt_dest.sa_family != AF_UNSPEC) ||
+ rt->rt_dest.sa_family != AF_UNSPEC) ||
(rt->rt_gateway.sa_family != af &&
- rt->rt_gateway.sa_family != AF_UNSPEC))
+ rt->rt_gateway.sa_family != AF_UNSPEC))
continue;
/* Is this route already in our table? */
if (rb_tree_find_node(&added, rt) != NULL)
#endif
/* Remove old routes we used to manage. */
- RB_TREE_FOREACH_REVERSE_SAFE(rt, &ctx->routes, rtn) {
+ RB_TREE_FOREACH_REVERSE_SAFE(rt, &ctx->routes, rtn)
+ {
if ((rt->rt_dest.sa_family != af &&
- rt->rt_dest.sa_family != AF_UNSPEC) ||
+ rt->rt_dest.sa_family != AF_UNSPEC) ||
(rt->rt_gateway.sa_family != af &&
- rt->rt_gateway.sa_family != AF_UNSPEC))
+ rt->rt_gateway.sa_family != AF_UNSPEC))
continue;
rb_tree_remove_node(&ctx->routes, rt);
if (rb_tree_find_node(&added, rt) == NULL) {
- o = rt->rt_ifp->options ?
- rt->rt_ifp->options->options :
- ctx->options;
- if ((o &
- (DHCPCD_EXITING | DHCPCD_PERSISTENT)) !=
- (DHCPCD_EXITING | DHCPCD_PERSISTENT))
+ o = rt->rt_ifp->options ? rt->rt_ifp->options->options :
+ ctx->options;
+ if ((o & (DHCPCD_EXITING | DHCPCD_PERSISTENT)) !=
+ (DHCPCD_EXITING | DHCPCD_PERSISTENT))
rt_delete(rt);
}
rt_free(rt);
#endif
#include <sys/socket.h>
+
#include <net/route.h>
#include <stdbool.h>
* when dealing with millions of routes.
*/
#if !defined(RT_FREE_ROUTE_TABLE)
-#define RT_FREE_ROUTE_TABLE 1
+#define RT_FREE_ROUTE_TABLE 1
#elif RT_FREE_ROUTE_TABLE == 0
-#undef RT_FREE_ROUTE_TABLE
+#undef RT_FREE_ROUTE_TABLE
#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
+#if defined(__linux__)
+#define HAVE_ROUTE_METRIC 1
+#endif
#endif
#ifdef __linux__
-# include <linux/version.h> /* RTA_PREF is only an enum.... */
-# if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 1, 0)
-# define HAVE_ROUTE_PREF
-# endif
-# if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 5, 0)
-# define HAVE_ROUTE_LIFETIME /* For IPv6 routes only */
-# endif
+#include <linux/version.h> /* RTA_PREF is only an enum.... */
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 1, 0)
+#define HAVE_ROUTE_PREF
+#endif
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 5, 0)
+#define HAVE_ROUTE_LIFETIME /* For IPv6 routes only */
+#endif
#endif
-#if defined(__OpenBSD__) || defined (__sun)
-# define ROUTE_PER_GATEWAY
+#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
#endif
struct rt {
- union sa_ss rt_ss_dest;
-#define rt_dest rt_ss_dest.sa
- union sa_ss rt_ss_netmask;
-#define rt_netmask rt_ss_netmask.sa
- union sa_ss rt_ss_gateway;
-#define rt_gateway rt_ss_gateway.sa
- struct interface *rt_ifp;
- union sa_ss rt_ss_ifa;
-#define rt_ifa rt_ss_ifa.sa
- unsigned int rt_flags;
- unsigned int rt_mtu;
+ union sa_ss rt_ss_dest;
+#define rt_dest rt_ss_dest.sa
+ union sa_ss rt_ss_netmask;
+#define rt_netmask rt_ss_netmask.sa
+ union sa_ss rt_ss_gateway;
+#define rt_gateway rt_ss_gateway.sa
+ struct interface *rt_ifp;
+ union sa_ss rt_ss_ifa;
+#define rt_ifa rt_ss_ifa.sa
+ unsigned int rt_flags;
+ unsigned int rt_mtu;
#ifdef HAVE_ROUTE_METRIC
- unsigned int rt_metric;
+ unsigned int rt_metric;
#endif
/* Maximum interface index is generally USHORT_MAX or 65535.
* Add some padding for other stuff and we get offsets for the
* below that should work automatically.
* This is only an issue if the user defines higher metrics in
* their configuration, but then they might wish to override also. */
-#define RTMETRIC_BASE 1000U
-#define RTMETRIC_WIRELESS 2000U
-#define RTMETRIC_IPV4LL 1000000U
-#define RTMETRIC_ROAM 2000000U
+#define RTMETRIC_BASE 1000U
+#define RTMETRIC_WIRELESS 2000U
+#define RTMETRIC_IPV4LL 1000000U
+#define RTMETRIC_ROAM 2000000U
#ifdef HAVE_ROUTE_PREF
- int rt_pref;
+ int rt_pref;
#endif
#define RTPREF_HIGH 1
-#define RTPREF_MEDIUM 0 /* has to be zero */
+#define RTPREF_MEDIUM 0 /* has to be zero */
#define RTPREF_LOW (-1)
-#define RTPREF_RESERVED (-2)
-#define RTPREF_INVALID (-3) /* internal */
- unsigned int rt_dflags;
-#define RTDF_IFA_ROUTE 0x01 /* Address generated route */
-#define RTDF_FAKE 0x02 /* Maybe us on lease reboot */
-#define RTDF_IPV4LL 0x04 /* IPv4LL route */
-#define RTDF_RA 0x08 /* Router Advertisement */
-#define RTDF_DHCP 0x10 /* DHCP route */
-#define RTDF_STATIC 0x20 /* Configured in dhcpcd */
-#define RTDF_GATELINK 0x40 /* Gateway is on link */
- size_t rt_order;
- rb_node_t rt_tree;
+#define RTPREF_RESERVED (-2)
+#define RTPREF_INVALID (-3) /* internal */
+ unsigned int rt_dflags;
+#define RTDF_IFA_ROUTE 0x01 /* Address generated route */
+#define RTDF_FAKE 0x02 /* Maybe us on lease reboot */
+#define RTDF_IPV4LL 0x04 /* IPv4LL route */
+#define RTDF_RA 0x08 /* Router Advertisement */
+#define RTDF_DHCP 0x10 /* DHCP route */
+#define RTDF_STATIC 0x20 /* Configured in dhcpcd */
+#define RTDF_GATELINK 0x40 /* Gateway is on link */
+ size_t rt_order;
+ rb_node_t rt_tree;
#ifdef HAVE_ROUTE_LIFETIME
- struct timespec rt_aquired; /* timestamp of aquisition */
- uint32_t rt_lifetime; /* current lifetime of route */
-#define RTLIFETIME_DEV_MAX 2 /* max deviation for cmp */
+ struct timespec rt_aquired; /* timestamp of aquisition */
+ uint32_t rt_lifetime; /* current lifetime of route */
+#define RTLIFETIME_DEV_MAX 2 /* max deviation for cmp */
#endif
};
void rt_headclear0(struct dhcpcd_ctx *, rb_tree_t *, int);
void rt_headclear(rb_tree_t *, int);
void rt_headfreeif(rb_tree_t *);
-struct rt * rt_new0(struct dhcpcd_ctx *);
+struct rt *rt_new0(struct dhcpcd_ctx *);
void rt_setif(struct rt *, struct interface *);
-struct rt * rt_new(struct interface *);
-struct rt * rt_proto_add_ctx(rb_tree_t *, struct rt *, struct dhcpcd_ctx *);
-struct rt * rt_proto_add(rb_tree_t *, struct rt *);
+struct rt *rt_new(struct interface *);
+struct rt *rt_proto_add_ctx(rb_tree_t *, struct rt *, struct dhcpcd_ctx *);
+struct rt *rt_proto_add(rb_tree_t *, struct rt *);
int rt_cmp_dest(const struct rt *, const struct rt *);
void rt_recvrt(int, const struct rt *, pid_t);
void rt_build(struct dhcpcd_ctx *, int);
* SUCH DAMAGE.
*/
-#include <sys/socket.h>
#include <sys/types.h>
+#include <sys/socket.h>
#include <arpa/inet.h>
#ifdef AF_LINK
#include <errno.h>
#include <stdbool.h>
#include <stddef.h>
-#include <stdio.h>
#include <stdint.h>
+#include <stdio.h>
#include <string.h>
-#include "config.h"
#include "common.h"
+#include "config.h"
#include "sa.h"
#ifndef NDEBUG
socklen_t
sa_addroffset(const struct sockaddr *sa)
{
-
assert(sa != NULL);
- switch(sa->sa_family) {
+ switch (sa->sa_family) {
#ifdef INET
case AF_INET:
return offsetof(struct sockaddr_in, sin_addr) +
- offsetof(struct in_addr, s_addr);
+ offsetof(struct in_addr, s_addr);
#endif /* INET */
#ifdef INET6
case AF_INET6:
return offsetof(struct sockaddr_in6, sin6_addr) +
- offsetof(struct in6_addr, s6_addr);
+ offsetof(struct in6_addr, s6_addr);
#endif /* INET6 */
default:
errno = EAFNOSUPPORT;
{
#define membersize(type, member) sizeof(((type *)0)->member)
assert(sa != NULL);
- switch(sa->sa_family) {
+ switch (sa->sa_family) {
#ifdef INET
case AF_INET:
return membersize(struct in_addr, s_addr);
socklen_t
sa_len(const struct sockaddr *sa)
{
-
switch (sa->sa_family) {
#ifdef AF_LINK
case AF_LINK:
bool
sa_is_unspecified(const struct sockaddr *sa)
{
-
assert(sa != NULL);
- switch(sa->sa_family) {
+ switch (sa->sa_family) {
case AF_UNSPEC:
return true;
#ifdef INET
#ifdef INET6
#ifndef IN6MASK128
-#define IN6MASK128 {{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }}}
+#define IN6MASK128 \
+ { \
+ {{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }} \
+ }
#endif
static const struct in6_addr in6allones = IN6MASK128;
#endif
bool
sa_is_allones(const struct sockaddr *sa)
{
-
assert(sa != NULL);
- switch(sa->sa_family) {
+ switch (sa->sa_family) {
case AF_UNSPEC:
return false;
#ifdef INET
- case AF_INET:
- {
+ case AF_INET: {
const struct sockaddr_in *sin;
sin = satocsin(sa);
}
#endif /* INET */
#ifdef INET6
- case AF_INET6:
- {
+ case AF_INET6: {
const struct sockaddr_in6 *sin6;
sin6 = satocsin6(sa);
bool
sa_is_loopback(const struct sockaddr *sa)
{
-
assert(sa != NULL);
- switch(sa->sa_family) {
+ switch (sa->sa_family) {
case AF_UNSPEC:
return false;
#ifdef INET
- case AF_INET:
- {
+ case AF_INET: {
const struct sockaddr_in *sin;
sin = satocsin(sa);
}
#endif /* INET */
#ifdef INET6
- case AF_INET6:
- {
+ case AF_INET6: {
const struct sockaddr_in6 *sin6;
sin6 = satocsin6(sa);
int prefix;
assert(sa != NULL);
- switch(sa->sa_family) {
+ switch (sa->sa_family) {
#ifdef INET
- case AF_INET:
- {
+ case AF_INET: {
const struct sockaddr_in *sin;
uint32_t mask;
break;
}
mask = ntohl(sin->sin_addr.s_addr);
- prefix = 33 - ffs((int)mask); /* 33 - (1 .. 32) -> 32 .. 1 */
- if (prefix < 32) { /* more than 1 bit in mask */
+ prefix = 33 - ffs((int)mask); /* 33 - (1 .. 32) -> 32 .. 1 */
+ if (prefix < 32) { /* more than 1 bit in mask */
/* check for non-contig netmask */
- if ((mask^(((1U << prefix)-1) << (32 - prefix))) != 0) {
+ if ((mask ^ (((1U << prefix) - 1) << (32 - prefix))) !=
+ 0) {
errno = EINVAL;
- return -1; /* noncontig, no pfxlen */
+ return -1; /* noncontig, no pfxlen */
}
}
break;
}
#endif
#ifdef INET6
- case AF_INET6:
- {
+ case AF_INET6: {
const struct sockaddr_in6 *sin6;
int x, y;
const uint8_t *lim, *p;
uint8_t a;
a = 0xff;
- a = (uint8_t)(a << (8 - bits));
+ a = (uint8_t)(a << (8 - bits));
*ap++ = a;
}
bytes = (max_prefix - prefix) / NBBY;
break;
}
- return memcmp((const char *)sa1 + offset,
- (const char *)sa2 + offset,
+ return memcmp((const char *)sa1 + offset, (const char *)sa2 + offset,
len);
}
#define SA_H
#include <sys/socket.h>
+
#include <netinet/in.h>
union sa_ss {
- struct sockaddr sa;
- struct sockaddr_in sin;
- struct sockaddr_in6 sin6;
+ struct sockaddr sa;
+ struct sockaddr_in sin;
+ struct sockaddr_in6 sin6;
};
#ifdef BSD
#endif
/* Allow for a sockaddr_dl being printed too. */
-#define INET_MAX_ADDRSTRLEN (20 * 3)
+#define INET_MAX_ADDRSTRLEN (20 * 3)
#ifdef INET
-#define satosin(sa) ((struct sockaddr_in *)(void *)(sa))
+#define satosin(sa) ((struct sockaddr_in *)(void *)(sa))
#define satocsin(sa) ((const struct sockaddr_in *)(const void *)(sa))
#endif
#ifdef INET6
-#define satosin6(sa) ((struct sockaddr_in6 *)(void *)(sa))
+#define satosin6(sa) ((struct sockaddr_in6 *)(void *)(sa))
#define satocsin6(sa) ((const struct sockaddr_in6 *)(const void *)(sa))
#endif
socklen_t sa_addroffset(const struct sockaddr *sa);
socklen_t sa_addrlen(const struct sockaddr *sa);
#ifdef HAVE_SA_LEN
-#define sa_len(sa) ((sa)->sa_len)
+#define sa_len(sa) ((sa)->sa_len)
#else
socklen_t sa_len(const struct sockaddr *sa);
#endif
#include <sys/wait.h>
#include <netinet/in.h>
-#include <arpa/inet.h>
+#include <arpa/inet.h>
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
-#include "config.h"
#include "common.h"
+#include "config.h"
#include "dhcp.h"
#include "dhcp6.h"
#include "eloop.h"
-#include "if.h"
#include "if-options.h"
+#include "if.h"
#include "ipv4ll.h"
#include "ipv6nd.h"
#include "logerr.h"
#include "privsep.h"
#include "script.h"
-#define DEFAULT_PATH "/usr/bin:/usr/sbin:/bin:/sbin"
-
-static const char * const if_params[] = {
- "interface",
- "protocol",
- "reason",
- "pid",
- "ifcarrier",
- "ifmetric",
- "ifwireless",
- "ifflags",
- "ssid",
- "profile",
- "interface_order",
- NULL
-};
-
-static const char * true_str = "true";
-static const char * false_str = "false";
+#define DEFAULT_PATH "/usr/bin:/usr/sbin:/bin:/sbin"
+
+static const char *const if_params[] = { "interface", "protocol", "reason",
+ "pid", "ifcarrier", "ifmetric", "ifwireless", "ifflags", "ssid",
+ "profile", "interface_order", NULL };
+
+static const char *true_str = "true";
+static const char *false_str = "false";
void
if_printoptions(void)
{
- const char * const *p;
+ const char *const *p;
for (p = if_params; *p; p++)
printf(" - %s\n", *p);
#endif
-#define PROTO_LINK 0
-#define PROTO_DHCP 1
-#define PROTO_IPV4LL 2
-#define PROTO_RA 3
-#define PROTO_DHCP6 4
-#define PROTO_STATIC6 5
-static const char *protocols[] = {
- "link",
- "dhcp",
- "ipv4ll",
- "ra",
- "dhcp6",
- "static6"
-};
+#define PROTO_LINK 0
+#define PROTO_DHCP 1
+#define PROTO_IPV4LL 2
+#define PROTO_RA 3
+#define PROTO_DHCP6 4
+#define PROTO_STATIC6 5
+static const char *protocols[] = { "link", "dhcp", "ipv4ll", "ra", "dhcp6",
+ "static6" };
int
efprintf(FILE *fp, const char *fmt, ...)
/* Needed for scripts */
path = getenv("PATH");
if (efprintf(fp, "PATH=%s",
- path == NULL ? DEFAULT_PATH : path) == -1)
+ path == NULL ? DEFAULT_PATH : path) == -1)
goto eexit;
if (efprintf(fp, "pid=%d", (int)getpid()) == -1)
goto eexit;
strcmp(reason, "CARRIER") == 0 ||
strcmp(reason, "NOCARRIER") == 0 ||
strcmp(reason, "NOCARRIER_ROAMING") == 0 ||
- strcmp(reason, "UNKNOWN") == 0 ||
- strcmp(reason, "DEPARTED") == 0 ||
+ strcmp(reason, "UNKNOWN") == 0 || strcmp(reason, "DEPARTED") == 0 ||
strcmp(reason, "STOPPED") == 0)
protocol = PROTO_LINK;
#ifdef INET
if (efprintf(fp, "interface=%s", ifp->name) == -1)
goto eexit;
if (protocols[protocol] != NULL) {
- if (efprintf(fp, "protocol=%s",
- protocols[protocol]) == -1)
+ if (efprintf(fp, "protocol=%s", protocols[protocol]) ==
+ -1)
goto eexit;
}
}
if (ifp->ctx->options & DHCPCD_DUMPLEASE && protocol != PROTO_LINK)
goto dumplease;
if (efprintf(fp, "if_configured=%s",
- ifo->options & DHCPCD_CONFIGURE ? "true" : "false") == -1)
+ ifo->options & DHCPCD_CONFIGURE ? "true" : "false") == -1)
goto eexit;
if (efprintf(fp, "ifcarrier=%s",
- ifp->carrier == LINK_UNKNOWN ? "unknown" :
- ifp->carrier == LINK_UP ? "up" : "down") == -1)
+ ifp->carrier == LINK_UNKNOWN ? "unknown" :
+ ifp->carrier == LINK_UP ? "up" :
+ "down") == -1)
goto eexit;
if (efprintf(fp, "ifmetric=%d", ifp->metric) == -1)
goto eexit;
if (ifp->wireless) {
char pssid[IF_SSIDLEN * 4];
- if (print_string(pssid, sizeof(pssid), OT_ESCSTRING,
- ifp->ssid, ifp->ssid_len) != -1)
- {
+ if (print_string(pssid, sizeof(pssid), OT_ESCSTRING, ifp->ssid,
+ ifp->ssid_len) != -1) {
if (efprintf(fp, "ifssid=%s", pssid) == -1)
goto eexit;
}
}
if (fprintf(fp, "interface_order=") == -1)
goto eexit;
- RB_TREE_FOREACH(rt, &ifaces) {
- if (rt != RB_TREE_MIN(&ifaces) &&
- fprintf(fp, "%s", " ") == -1)
+ RB_TREE_FOREACH(rt, &ifaces)
+ {
+ if (rt != RB_TREE_MIN(&ifaces) && fprintf(fp, "%s", " ") == -1)
goto eexit;
if (fprintf(fp, "%s", rt->rt_ifp->name) == -1)
goto eexit;
if_up = false_str;
if_down = ifo->options & DHCPCD_RELEASE ? true_str : false_str;
} else if (strcmp(reason, "TEST") == 0 ||
- strcmp(reason, "PREINIT") == 0 ||
- strcmp(reason, "CARRIER") == 0 ||
- strcmp(reason, "STOP") == 0 ||
- strcmp(reason, "UNKNOWN") == 0)
- {
+ strcmp(reason, "PREINIT") == 0 || strcmp(reason, "CARRIER") == 0 ||
+ strcmp(reason, "STOP") == 0 || strcmp(reason, "UNKNOWN") == 0) {
if_up = false_str;
if_down = false_str;
} else if (strcmp(reason, "NOCARRIER") == 0) {
#endif
|| (protocol == PROTO_RA && ipv6nd_hasra(ifp))
#endif
- )
- {
+ ) {
if_up = true_str;
if_down = false_str;
} else {
}
#ifdef INET
if (protocol == PROTO_DHCP && state && state->old) {
- if (dhcp_env(fp, "old", ifp,
- state->old, state->old_len) == -1)
+ if (dhcp_env(fp, "old", ifp, state->old, state->old_len) == -1)
goto eexit;
if (append_config(fp, "old",
- (const char *const *)ifo->config) == -1)
+ (const char *const *)ifo->config) == -1)
goto eexit;
}
#endif
#ifdef DHCP6
if (protocol == PROTO_DHCP6 && d6_state && d6_state->old) {
- if (dhcp6_env(fp, "old", ifp,
- d6_state->old, d6_state->old_len) == -1)
+ if (dhcp6_env(fp, "old", ifp, d6_state->old,
+ d6_state->old_len) == -1)
goto eexit;
}
#endif
}
#endif
if (protocol == PROTO_DHCP && state && state->new) {
- if (dhcp_env(fp, "new", ifp,
- state->new, state->new_len) == -1)
+ if (dhcp_env(fp, "new", ifp, state->new, state->new_len) == -1)
goto eexit;
if (append_config(fp, "new",
- (const char *const *)ifo->config) == -1)
+ (const char *const *)ifo->config) == -1)
goto eexit;
}
#endif
}
#ifdef DHCP6
if (protocol == PROTO_DHCP6 && D6_STATE_RUNNING(ifp)) {
- if (dhcp6_env(fp, "new", ifp,
- d6_state->new, d6_state->new_len) == -1)
+ if (dhcp6_env(fp, "new", ifp, d6_state->new,
+ d6_state->new_len) == -1)
goto eexit;
}
#endif
#endif
#ifndef AF_LINK
-#define AF_LINK AF_PACKET
+#define AF_LINK AF_PACKET
#endif
if (af == AF_UNSPEC || af == AF_LINK) {
}
if (RS_STATE_RUNNING(ifp)) {
if (fd != NULL) {
- if (send_interface1(fd, ifp,
- "ROUTERADVERT") == -1)
+ if (send_interface1(fd, ifp, "ROUTERADVERT") ==
+ -1)
retval = -1;
} else
retval++;
static int
script_status(const char *script, int status)
{
-
if (WIFEXITED(status)) {
if (WEXITSTATUS(status))
- logerrx("%s: %s: WEXITSTATUS %d",
- __func__, script, WEXITSTATUS(status));
+ logerrx("%s: %s: WEXITSTATUS %d", __func__, script,
+ WEXITSTATUS(status));
} else if (WIFSIGNALED(status))
- logerrx("%s: %s: %s",
- __func__, script, strsignal(WTERMSIG(status)));
+ logerrx("%s: %s: %s", __func__, script,
+ strsignal(WTERMSIG(status)));
return WEXITSTATUS(status);
}
struct fd_list *fd;
long buflen;
- if (ctx->script == NULL &&
- TAILQ_FIRST(&ifp->ctx->control_fds) == NULL)
+ if (ctx->script == NULL && TAILQ_FIRST(&ifp->ctx->control_fds) == NULL)
return 0;
/* Make our env */
TAILQ_FOREACH(fd, &ctx->control_fds, next) {
if (!(fd->flags & FD_LISTEN))
continue;
- if (control_queue(fd, ctx->script_buf, ctx->script_buflen)== -1)
+ if (control_queue(fd, ctx->script_buf, ctx->script_buflen) ==
+ -1)
logerr("%s: control_queue", __func__);
else
status = 1;
__printflike(2, 3) int efprintf(FILE *, const char *, ...);
void if_printoptions(void);
-char ** script_buftoenv(struct dhcpcd_ctx *, char *, size_t);
+char **script_buftoenv(struct dhcpcd_ctx *, char *, size_t);
pid_t script_exec(char *const *, char *const *);
int send_interface(struct fd_list *, const struct interface *, int);
int script_dump(const char *, size_t);