annotate src/dhcpcd.c @ 5570:f32e37b1d371 draft

dhcpcd: Don't roam when anonymous is set We can now remove the NOCARRIER_PRESERVE_IP define.
author Roy Marples <roy@marples.name>
date Sun, 27 Dec 2020 21:59:32 +0000
parents cebc093fd611
children 2a519da0f1a2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4548
c7df03794de3 Add SPDX identifiers to all dhcpcd source files.
Yegor Yefremov <yegorslists@googlemail.com>
parents: 4534
diff changeset
1 /* SPDX-License-Identifier: BSD-2-Clause */
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2 /*
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3 * dhcpcd - DHCP client daemon
4922
555d7d1a4939 Welcome to 2020!
Roy Marples <roy@marples.name>
parents: 4868
diff changeset
4 * Copyright (c) 2006-2020 Roy Marples <roy@marples.name>
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
5 * All rights reserved
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
6
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
7 * Redistribution and use in source and binary forms, with or without
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
8 * modification, are permitted provided that the following conditions
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
9 * are met:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
10 * 1. Redistributions of source code must retain the above copyright
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
11 * notice, this list of conditions and the following disclaimer.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
15 *
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
26 * SUCH DAMAGE.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
27 */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
28
5484
e01d8ea25a42 Clean up some warnings.
Sascha Wildner <saw@online.de>
parents: 5474
diff changeset
29 static const char dhcpcd_copyright[] = "Copyright (c) 2006-2020 Roy Marples";
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
30
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
31 #include <sys/file.h>
5288
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
32 #include <sys/ioctl.h>
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
33 #include <sys/socket.h>
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
34 #include <sys/stat.h>
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
35 #include <sys/time.h>
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
36 #include <sys/types.h>
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
37 #include <sys/uio.h>
4856
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
38 #include <sys/wait.h>
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
39
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
40 #include <ctype.h>
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
41 #include <errno.h>
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
42 #include <fcntl.h>
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
43 #include <getopt.h>
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
44 #include <limits.h>
4988
1369161bbc7c privsep: Close stdout/stderr after forking processes
Roy Marples <roy@marples.name>
parents: 4969
diff changeset
45 #include <paths.h>
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
46 #include <signal.h>
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
47 #include <stdio.h>
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
48 #include <stdlib.h>
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
49 #include <string.h>
5065
641e15827969 Be pedantic and move syslog.h into the right place
Roy Marples <roy@marples.name>
parents: 5064
diff changeset
50 #include <syslog.h>
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
51 #include <unistd.h>
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
52 #include <time.h>
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
53
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
54 #include "config.h"
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
55 #include "arp.h"
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
56 #include "common.h"
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
57 #include "control.h"
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
58 #include "dev.h"
4349
f87c2ed9ff46 DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents: 4348
diff changeset
59 #include "dhcp-common.h"
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
60 #include "dhcpcd.h"
4363
f51c65524444 fix build with --disable-inet6
Chris Clayton <chris2553@googlemail.com>
parents: 4355
diff changeset
61 #include "dhcp.h"
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
62 #include "dhcp6.h"
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
63 #include "duid.h"
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
64 #include "eloop.h"
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
65 #include "if.h"
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
66 #include "if-options.h"
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
67 #include "ipv4.h"
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
68 #include "ipv4ll.h"
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
69 #include "ipv6.h"
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
70 #include "ipv6nd.h"
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 4008
diff changeset
71 #include "logerr.h"
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4836
diff changeset
72 #include "privsep.h"
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
73 #include "script.h"
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
74
5231
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5228
diff changeset
75 #ifdef HAVE_CAPSICUM
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5228
diff changeset
76 #include <sys/capsicum.h>
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5228
diff changeset
77 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
78 #ifdef HAVE_UTIL_H
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
79 #include <util.h>
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
80 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
81
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
82 #ifdef USE_SIGNALS
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
83 const int dhcpcd_signals[] = {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
84 SIGTERM,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
85 SIGINT,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
86 SIGALRM,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
87 SIGHUP,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
88 SIGUSR1,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
89 SIGUSR2,
5304
04f26d9f1885 privsep: Don't wait for the process to finish when stopping it
Roy Marples <roy@marples.name>
parents: 5301
diff changeset
90 SIGCHLD,
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
91 };
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
92 const size_t dhcpcd_signals_len = __arraycount(dhcpcd_signals);
5227
7406014c9120 dhcpcd: allow sigpipe in scripts.
Roy Marples <roy@marples.name>
parents: 5223
diff changeset
93
7406014c9120 dhcpcd: allow sigpipe in scripts.
Roy Marples <roy@marples.name>
parents: 5223
diff changeset
94 const int dhcpcd_signals_ignore[] = {
7406014c9120 dhcpcd: allow sigpipe in scripts.
Roy Marples <roy@marples.name>
parents: 5223
diff changeset
95 SIGPIPE,
7406014c9120 dhcpcd: allow sigpipe in scripts.
Roy Marples <roy@marples.name>
parents: 5223
diff changeset
96 };
7406014c9120 dhcpcd: allow sigpipe in scripts.
Roy Marples <roy@marples.name>
parents: 5223
diff changeset
97 const size_t dhcpcd_signals_ignore_len = __arraycount(dhcpcd_signals_ignore);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
98 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
99
5255
ee23398a68db dhcpcd: Move the script file from per interface to global context
Roy Marples <roy@marples.name>
parents: 5252
diff changeset
100 const char *dhcpcd_default_script = SCRIPT;
ee23398a68db dhcpcd: Move the script file from per interface to global context
Roy Marples <roy@marples.name>
parents: 5252
diff changeset
101
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
102 static void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
103 usage(void)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
104 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
105
4305
f0d00cf65f76 Update usage() to match documented flags
Sevan Janiyan <venture37@geeklan.co.uk>
parents: 4289
diff changeset
106 printf("usage: "PACKAGE"\t[-146ABbDdEGgHJKLMNPpqTV]\n"
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
107 "\t\t[-C, --nohook hook] [-c, --script script]\n"
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
108 "\t\t[-e, --env value] [-F, --fqdn FQDN] [-f, --config file]\n"
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
109 "\t\t[-h, --hostname hostname] [-I, --clientid clientid]\n"
4305
f0d00cf65f76 Update usage() to match documented flags
Sevan Janiyan <venture37@geeklan.co.uk>
parents: 4289
diff changeset
110 "\t\t[-i, --vendorclassid vendorclassid] [-j, --logfile logfile]\n"
f0d00cf65f76 Update usage() to match documented flags
Sevan Janiyan <venture37@geeklan.co.uk>
parents: 4289
diff changeset
111 "\t\t[-l, --leasetime seconds] [-m, --metric metric]\n"
f0d00cf65f76 Update usage() to match documented flags
Sevan Janiyan <venture37@geeklan.co.uk>
parents: 4289
diff changeset
112 "\t\t[-O, --nooption option] [-o, --option option]\n"
f0d00cf65f76 Update usage() to match documented flags
Sevan Janiyan <venture37@geeklan.co.uk>
parents: 4289
diff changeset
113 "\t\t[-Q, --require option] [-r, --request address]\n"
f0d00cf65f76 Update usage() to match documented flags
Sevan Janiyan <venture37@geeklan.co.uk>
parents: 4289
diff changeset
114 "\t\t[-S, --static value]\n"
f0d00cf65f76 Update usage() to match documented flags
Sevan Janiyan <venture37@geeklan.co.uk>
parents: 4289
diff changeset
115 "\t\t[-s, --inform address[/cidr[/broadcast_address]]]\n [--inform6]"
f0d00cf65f76 Update usage() to match documented flags
Sevan Janiyan <venture37@geeklan.co.uk>
parents: 4289
diff changeset
116 "\t\t[-t, --timeout seconds] [-u, --userclass class]\n"
f0d00cf65f76 Update usage() to match documented flags
Sevan Janiyan <venture37@geeklan.co.uk>
parents: 4289
diff changeset
117 "\t\t[-v, --vendor code, value] [-W, --whitelist address[/cidr]] [-w]\n"
f0d00cf65f76 Update usage() to match documented flags
Sevan Janiyan <venture37@geeklan.co.uk>
parents: 4289
diff changeset
118 "\t\t[--waitip [4 | 6]] [-y, --reboot seconds]\n"
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
119 "\t\t[-X, --blacklist address[/cidr]] [-Z, --denyinterfaces pattern]\n"
4305
f0d00cf65f76 Update usage() to match documented flags
Sevan Janiyan <venture37@geeklan.co.uk>
parents: 4289
diff changeset
120 "\t\t[-z, --allowinterfaces pattern] [--inactive] [interface] [...]\n"
f0d00cf65f76 Update usage() to match documented flags
Sevan Janiyan <venture37@geeklan.co.uk>
parents: 4289
diff changeset
121 " "PACKAGE"\t-n, --rebind [interface]\n"
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
122 " "PACKAGE"\t-k, --release [interface]\n"
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
123 " "PACKAGE"\t-U, --dumplease interface\n"
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
124 " "PACKAGE"\t--version\n"
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
125 " "PACKAGE"\t-x, --exit [interface]\n");
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
126 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
127
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
128 static void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
129 free_globals(struct dhcpcd_ctx *ctx)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
130 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
131 struct dhcp_opt *opt;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
132
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
133 if (ctx->ifac) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
134 for (; ctx->ifac > 0; ctx->ifac--)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
135 free(ctx->ifav[ctx->ifac - 1]);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
136 free(ctx->ifav);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
137 ctx->ifav = NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
138 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
139 if (ctx->ifdc) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
140 for (; ctx->ifdc > 0; ctx->ifdc--)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
141 free(ctx->ifdv[ctx->ifdc - 1]);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
142 free(ctx->ifdv);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
143 ctx->ifdv = NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
144 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
145 if (ctx->ifcc) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
146 for (; ctx->ifcc > 0; ctx->ifcc--)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
147 free(ctx->ifcv[ctx->ifcc - 1]);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
148 free(ctx->ifcv);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
149 ctx->ifcv = NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
150 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
151
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
152 #ifdef INET
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
153 if (ctx->dhcp_opts) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
154 for (opt = ctx->dhcp_opts;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
155 ctx->dhcp_opts_len > 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
156 opt++, ctx->dhcp_opts_len--)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
157 free_dhcp_opt_embenc(opt);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
158 free(ctx->dhcp_opts);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
159 ctx->dhcp_opts = NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
160 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
161 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
162 #ifdef INET6
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
163 if (ctx->nd_opts) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
164 for (opt = ctx->nd_opts;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
165 ctx->nd_opts_len > 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
166 opt++, ctx->nd_opts_len--)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
167 free_dhcp_opt_embenc(opt);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
168 free(ctx->nd_opts);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
169 ctx->nd_opts = NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
170 }
4349
f87c2ed9ff46 DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents: 4348
diff changeset
171 #ifdef DHCP6
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
172 if (ctx->dhcp6_opts) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
173 for (opt = ctx->dhcp6_opts;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
174 ctx->dhcp6_opts_len > 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
175 opt++, ctx->dhcp6_opts_len--)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
176 free_dhcp_opt_embenc(opt);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
177 free(ctx->dhcp6_opts);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
178 ctx->dhcp6_opts = NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
179 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
180 #endif
4349
f87c2ed9ff46 DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents: 4348
diff changeset
181 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
182 if (ctx->vivso) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
183 for (opt = ctx->vivso;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
184 ctx->vivso_len > 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
185 opt++, ctx->vivso_len--)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
186 free_dhcp_opt_embenc(opt);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
187 free(ctx->vivso);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
188 ctx->vivso = NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
189 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
190 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
191
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
192 static void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
193 handle_exit_timeout(void *arg)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
194 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
195 struct dhcpcd_ctx *ctx;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
196
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
197 ctx = arg;
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 4008
diff changeset
198 logerrx("timed out");
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
199 if (!(ctx->options & DHCPCD_MASTER)) {
4777
e3c23b0413e8 dhcpcd: Run the STOPPED hook reason for the interface on timeout
Roy Marples <roy@marples.name>
parents: 4767
diff changeset
200 struct interface *ifp;
e3c23b0413e8 dhcpcd: Run the STOPPED hook reason for the interface on timeout
Roy Marples <roy@marples.name>
parents: 4767
diff changeset
201
e3c23b0413e8 dhcpcd: Run the STOPPED hook reason for the interface on timeout
Roy Marples <roy@marples.name>
parents: 4767
diff changeset
202 TAILQ_FOREACH(ifp, ctx->ifaces, next) {
e3c23b0413e8 dhcpcd: Run the STOPPED hook reason for the interface on timeout
Roy Marples <roy@marples.name>
parents: 4767
diff changeset
203 if (ifp->active == IF_ACTIVE_USER)
e3c23b0413e8 dhcpcd: Run the STOPPED hook reason for the interface on timeout
Roy Marples <roy@marples.name>
parents: 4767
diff changeset
204 script_runreason(ifp, "STOPPED");
e3c23b0413e8 dhcpcd: Run the STOPPED hook reason for the interface on timeout
Roy Marples <roy@marples.name>
parents: 4767
diff changeset
205 }
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
206 eloop_exit(ctx->eloop, EXIT_FAILURE);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
207 return;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
208 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
209 ctx->options |= DHCPCD_NOWAITIP;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
210 dhcpcd_daemonise(ctx);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
211 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
212
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
213 static const char *
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
214 dhcpcd_af(int af)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
215 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
216
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
217 switch (af) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
218 case AF_UNSPEC:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
219 return "IP";
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
220 case AF_INET:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
221 return "IPv4";
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
222 case AF_INET6:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
223 return "IPv6";
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
224 default:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
225 return NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
226 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
227 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
228
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
229 int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
230 dhcpcd_ifafwaiting(const struct interface *ifp)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
231 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
232 unsigned long long opts;
4351
b7a9f2b43d50 IP6ND: Remove #defines for functions when INET6 is disabled
Roy Marples <roy@marples.name>
parents: 4349
diff changeset
233 bool foundany = false;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
234
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
235 if (ifp->active != IF_ACTIVE_USER)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
236 return AF_MAX;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
237
4351
b7a9f2b43d50 IP6ND: Remove #defines for functions when INET6 is disabled
Roy Marples <roy@marples.name>
parents: 4349
diff changeset
238 #define DHCPCD_WAITALL (DHCPCD_WAITIP4 | DHCPCD_WAITIP6)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
239 opts = ifp->options->options;
4348
437e53e4ea26 IP4: Remove #defines for functions when INET is disabled
Roy Marples <roy@marples.name>
parents: 4347
diff changeset
240 #ifdef INET
4351
b7a9f2b43d50 IP6ND: Remove #defines for functions when INET6 is disabled
Roy Marples <roy@marples.name>
parents: 4349
diff changeset
241 if (opts & DHCPCD_WAITIP4 ||
b7a9f2b43d50 IP6ND: Remove #defines for functions when INET6 is disabled
Roy Marples <roy@marples.name>
parents: 4349
diff changeset
242 (opts & DHCPCD_WAITIP && !(opts & DHCPCD_WAITALL)))
b7a9f2b43d50 IP6ND: Remove #defines for functions when INET6 is disabled
Roy Marples <roy@marples.name>
parents: 4349
diff changeset
243 {
b7a9f2b43d50 IP6ND: Remove #defines for functions when INET6 is disabled
Roy Marples <roy@marples.name>
parents: 4349
diff changeset
244 bool foundaddr = ipv4_hasaddr(ifp);
b7a9f2b43d50 IP6ND: Remove #defines for functions when INET6 is disabled
Roy Marples <roy@marples.name>
parents: 4349
diff changeset
245
b7a9f2b43d50 IP6ND: Remove #defines for functions when INET6 is disabled
Roy Marples <roy@marples.name>
parents: 4349
diff changeset
246 if (opts & DHCPCD_WAITIP4 && !foundaddr)
b7a9f2b43d50 IP6ND: Remove #defines for functions when INET6 is disabled
Roy Marples <roy@marples.name>
parents: 4349
diff changeset
247 return AF_INET;
b7a9f2b43d50 IP6ND: Remove #defines for functions when INET6 is disabled
Roy Marples <roy@marples.name>
parents: 4349
diff changeset
248 if (foundaddr)
b7a9f2b43d50 IP6ND: Remove #defines for functions when INET6 is disabled
Roy Marples <roy@marples.name>
parents: 4349
diff changeset
249 foundany = true;
b7a9f2b43d50 IP6ND: Remove #defines for functions when INET6 is disabled
Roy Marples <roy@marples.name>
parents: 4349
diff changeset
250 }
4348
437e53e4ea26 IP4: Remove #defines for functions when INET is disabled
Roy Marples <roy@marples.name>
parents: 4347
diff changeset
251 #endif
4351
b7a9f2b43d50 IP6ND: Remove #defines for functions when INET6 is disabled
Roy Marples <roy@marples.name>
parents: 4349
diff changeset
252 #ifdef INET6
b7a9f2b43d50 IP6ND: Remove #defines for functions when INET6 is disabled
Roy Marples <roy@marples.name>
parents: 4349
diff changeset
253 if (opts & DHCPCD_WAITIP6 ||
b7a9f2b43d50 IP6ND: Remove #defines for functions when INET6 is disabled
Roy Marples <roy@marples.name>
parents: 4349
diff changeset
254 (opts & DHCPCD_WAITIP && !(opts & DHCPCD_WAITALL)))
b7a9f2b43d50 IP6ND: Remove #defines for functions when INET6 is disabled
Roy Marples <roy@marples.name>
parents: 4349
diff changeset
255 {
b7a9f2b43d50 IP6ND: Remove #defines for functions when INET6 is disabled
Roy Marples <roy@marples.name>
parents: 4349
diff changeset
256 bool foundaddr = ipv6_hasaddr(ifp);
b7a9f2b43d50 IP6ND: Remove #defines for functions when INET6 is disabled
Roy Marples <roy@marples.name>
parents: 4349
diff changeset
257
b7a9f2b43d50 IP6ND: Remove #defines for functions when INET6 is disabled
Roy Marples <roy@marples.name>
parents: 4349
diff changeset
258 if (opts & DHCPCD_WAITIP6 && !foundaddr)
b7a9f2b43d50 IP6ND: Remove #defines for functions when INET6 is disabled
Roy Marples <roy@marples.name>
parents: 4349
diff changeset
259 return AF_INET;
b7a9f2b43d50 IP6ND: Remove #defines for functions when INET6 is disabled
Roy Marples <roy@marples.name>
parents: 4349
diff changeset
260 if (foundaddr)
b7a9f2b43d50 IP6ND: Remove #defines for functions when INET6 is disabled
Roy Marples <roy@marples.name>
parents: 4349
diff changeset
261 foundany = true;
b7a9f2b43d50 IP6ND: Remove #defines for functions when INET6 is disabled
Roy Marples <roy@marples.name>
parents: 4349
diff changeset
262 }
4348
437e53e4ea26 IP4: Remove #defines for functions when INET is disabled
Roy Marples <roy@marples.name>
parents: 4347
diff changeset
263 #endif
4351
b7a9f2b43d50 IP6ND: Remove #defines for functions when INET6 is disabled
Roy Marples <roy@marples.name>
parents: 4349
diff changeset
264
b7a9f2b43d50 IP6ND: Remove #defines for functions when INET6 is disabled
Roy Marples <roy@marples.name>
parents: 4349
diff changeset
265 if (opts & DHCPCD_WAITIP && !(opts & DHCPCD_WAITALL) && !foundany)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
266 return AF_UNSPEC;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
267 return AF_MAX;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
268 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
269
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
270 int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
271 dhcpcd_afwaiting(const struct dhcpcd_ctx *ctx)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
272 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
273 unsigned long long opts;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
274 const struct interface *ifp;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
275 int af;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
276
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
277 if (!(ctx->options & DHCPCD_WAITOPTS))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
278 return AF_MAX;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
279
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
280 opts = ctx->options;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
281 TAILQ_FOREACH(ifp, ctx->ifaces, next) {
4348
437e53e4ea26 IP4: Remove #defines for functions when INET is disabled
Roy Marples <roy@marples.name>
parents: 4347
diff changeset
282 #ifdef INET
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
283 if (opts & (DHCPCD_WAITIP | DHCPCD_WAITIP4) &&
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
284 ipv4_hasaddr(ifp))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
285 opts &= ~(DHCPCD_WAITIP | DHCPCD_WAITIP4);
4348
437e53e4ea26 IP4: Remove #defines for functions when INET is disabled
Roy Marples <roy@marples.name>
parents: 4347
diff changeset
286 #endif
4351
b7a9f2b43d50 IP6ND: Remove #defines for functions when INET6 is disabled
Roy Marples <roy@marples.name>
parents: 4349
diff changeset
287 #ifdef INET6
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
288 if (opts & (DHCPCD_WAITIP | DHCPCD_WAITIP6) &&
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
289 ipv6_hasaddr(ifp))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
290 opts &= ~(DHCPCD_WAITIP | DHCPCD_WAITIP6);
4351
b7a9f2b43d50 IP6ND: Remove #defines for functions when INET6 is disabled
Roy Marples <roy@marples.name>
parents: 4349
diff changeset
291 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
292 if (!(opts & DHCPCD_WAITOPTS))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
293 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
294 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
295 if (opts & DHCPCD_WAITIP)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
296 af = AF_UNSPEC;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
297 else if (opts & DHCPCD_WAITIP4)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
298 af = AF_INET;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
299 else if (opts & DHCPCD_WAITIP6)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
300 af = AF_INET6;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
301 else
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
302 return AF_MAX;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
303 return af;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
304 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
305
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
306 static int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
307 dhcpcd_ipwaited(struct dhcpcd_ctx *ctx)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
308 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
309 struct interface *ifp;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
310 int af;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
311
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
312 TAILQ_FOREACH(ifp, ctx->ifaces, next) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
313 if ((af = dhcpcd_ifafwaiting(ifp)) != AF_MAX) {
4023
66f9399ba5c6 Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents: 4021
diff changeset
314 logdebugx("%s: waiting for an %s address",
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
315 ifp->name, dhcpcd_af(af));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
316 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
317 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
318 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
319
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
320 if ((af = dhcpcd_afwaiting(ctx)) != AF_MAX) {
4023
66f9399ba5c6 Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents: 4021
diff changeset
321 logdebugx("waiting for an %s address",
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
322 dhcpcd_af(af));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
323 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
324 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
325
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
326 return 1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
327 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
328
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
329 /* Returns the pid of the child, otherwise 0. */
4856
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
330 void
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
331 dhcpcd_daemonise(struct dhcpcd_ctx *ctx)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
332 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
333 #ifdef THERE_IS_NO_FORK
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
334 eloop_timeout_delete(ctx->eloop, handle_exit_timeout, ctx);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
335 errno = ENOSYS;
5410
e7ca98611c22 src/dhcpcd.c: fix build without fork
Fabrice Fontaine <fontaine.fabrice@gmail.com>
parents: 5404
diff changeset
336 return;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
337 #else
4856
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
338 int i;
5394
b7f0ddd5d9bd dhcpcd: Turn off stderr logging rather than closing stderr
Roy Marples <roy@marples.name>
parents: 5393
diff changeset
339 unsigned int logopts = loggetopts();
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
340
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
341 if (ctx->options & DHCPCD_DAEMONISE &&
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
342 !(ctx->options & (DHCPCD_DAEMONISED | DHCPCD_NOWAITIP)))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
343 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
344 if (!dhcpcd_ipwaited(ctx))
4856
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
345 return;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
346 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
347
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
348 if (ctx->options & DHCPCD_ONESHOT) {
4024
0984f93d896e To be consitent, do the same to loginfo as we just did for logdebug.
Roy Marples <roy@marples.name>
parents: 4023
diff changeset
349 loginfox("exiting due to oneshot");
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
350 eloop_exit(ctx->eloop, EXIT_SUCCESS);
4856
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
351 return;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
352 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
353
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
354 eloop_timeout_delete(ctx->eloop, handle_exit_timeout, ctx);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
355 if (ctx->options & DHCPCD_DAEMONISED ||
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
356 !(ctx->options & DHCPCD_DAEMONISE))
4856
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
357 return;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
358
4997
774f445ed677 logging: Always log to syslog(3).
Roy Marples <roy@marples.name>
parents: 4994
diff changeset
359 /* Don't use loginfo because this makes no sense in a log. */
5454
68ef863871d1 dhcpcd: Only manipulate stdin, stdout and stderr when valid
Roy Marples <roy@marples.name>
parents: 5451
diff changeset
360 if (!(logopts & LOGERR_QUIET) && ctx->stderr_valid)
5441
ff7c7b4799b3 dhcpcd: Redirect stdout/stderr to the launcher stderr descriptor
Roy Marples <roy@marples.name>
parents: 5440
diff changeset
361 (void)fprintf(stderr,
5419
25b6d0d2a59d dhcpcd: Fix logging we forked at exit.
Roy Marples <roy@marples.name>
parents: 5410
diff changeset
362 "forked to background, child pid %d\n", getpid());
4856
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
363 i = EXIT_SUCCESS;
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
364 if (write(ctx->fork_fd, &i, sizeof(i)) == -1)
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
365 logerr("write");
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
366 ctx->options |= DHCPCD_DAEMONISED;
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
367 eloop_event_delete(ctx->eloop, ctx->fork_fd);
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
368 close(ctx->fork_fd);
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
369 ctx->fork_fd = -1;
5394
b7f0ddd5d9bd dhcpcd: Turn off stderr logging rather than closing stderr
Roy Marples <roy@marples.name>
parents: 5393
diff changeset
370
5441
ff7c7b4799b3 dhcpcd: Redirect stdout/stderr to the launcher stderr descriptor
Roy Marples <roy@marples.name>
parents: 5440
diff changeset
371 /*
ff7c7b4799b3 dhcpcd: Redirect stdout/stderr to the launcher stderr descriptor
Roy Marples <roy@marples.name>
parents: 5440
diff changeset
372 * Stop writing to stderr.
ff7c7b4799b3 dhcpcd: Redirect stdout/stderr to the launcher stderr descriptor
Roy Marples <roy@marples.name>
parents: 5440
diff changeset
373 * On the happy path, only the master process writes to stderr,
ff7c7b4799b3 dhcpcd: Redirect stdout/stderr to the launcher stderr descriptor
Roy Marples <roy@marples.name>
parents: 5440
diff changeset
374 * so this just stops wasting fprintf calls to nowhere.
ff7c7b4799b3 dhcpcd: Redirect stdout/stderr to the launcher stderr descriptor
Roy Marples <roy@marples.name>
parents: 5440
diff changeset
375 * All other calls - ie errors in privsep processes or script output,
ff7c7b4799b3 dhcpcd: Redirect stdout/stderr to the launcher stderr descriptor
Roy Marples <roy@marples.name>
parents: 5440
diff changeset
376 * will error when printing.
ff7c7b4799b3 dhcpcd: Redirect stdout/stderr to the launcher stderr descriptor
Roy Marples <roy@marples.name>
parents: 5440
diff changeset
377 * If we *really* want to fix that, then we need to suck
ff7c7b4799b3 dhcpcd: Redirect stdout/stderr to the launcher stderr descriptor
Roy Marples <roy@marples.name>
parents: 5440
diff changeset
378 * stderr/stdout in the master process and either disacrd it or pass
ff7c7b4799b3 dhcpcd: Redirect stdout/stderr to the launcher stderr descriptor
Roy Marples <roy@marples.name>
parents: 5440
diff changeset
379 * it to the launcher process and then to stderr.
ff7c7b4799b3 dhcpcd: Redirect stdout/stderr to the launcher stderr descriptor
Roy Marples <roy@marples.name>
parents: 5440
diff changeset
380 */
ff7c7b4799b3 dhcpcd: Redirect stdout/stderr to the launcher stderr descriptor
Roy Marples <roy@marples.name>
parents: 5440
diff changeset
381 logopts &= ~LOGERR_ERR;
ff7c7b4799b3 dhcpcd: Redirect stdout/stderr to the launcher stderr descriptor
Roy Marples <roy@marples.name>
parents: 5440
diff changeset
382 logsetopts(logopts);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
383 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
384 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
385
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
386 static void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
387 dhcpcd_drop(struct interface *ifp, int stop)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
388 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
389
4285
92c215d75a0c Fix compile without INET6
Roy Marples <roy@marples.name>
parents: 4279
diff changeset
390 #ifdef DHCP6
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
391 dhcp6_drop(ifp, stop ? NULL : "EXPIRE6");
4285
92c215d75a0c Fix compile without INET6
Roy Marples <roy@marples.name>
parents: 4279
diff changeset
392 #endif
92c215d75a0c Fix compile without INET6
Roy Marples <roy@marples.name>
parents: 4279
diff changeset
393 #ifdef INET6
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
394 ipv6nd_drop(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
395 ipv6_drop(ifp);
4285
92c215d75a0c Fix compile without INET6
Roy Marples <roy@marples.name>
parents: 4279
diff changeset
396 #endif
92c215d75a0c Fix compile without INET6
Roy Marples <roy@marples.name>
parents: 4279
diff changeset
397 #ifdef IPV4LL
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
398 ipv4ll_drop(ifp);
4285
92c215d75a0c Fix compile without INET6
Roy Marples <roy@marples.name>
parents: 4279
diff changeset
399 #endif
4289
2d4ea1b35d15 Fix my dumb mistake with the compile fixes which caused dhcpcd to
Roy Marples <roy@marples.name>
parents: 4285
diff changeset
400 #ifdef INET
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
401 dhcp_drop(ifp, stop ? "STOP" : "EXPIRE");
4285
92c215d75a0c Fix compile without INET6
Roy Marples <roy@marples.name>
parents: 4279
diff changeset
402 #endif
4135
64796240ee75 arp: RFC5227 kernels need to send ARP too
Roy Marples <roy@marples.name>
parents: 4132
diff changeset
403 #ifdef ARP
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
404 arp_drop(ifp);
4135
64796240ee75 arp: RFC5227 kernels need to send ARP too
Roy Marples <roy@marples.name>
parents: 4132
diff changeset
405 #endif
4285
92c215d75a0c Fix compile without INET6
Roy Marples <roy@marples.name>
parents: 4279
diff changeset
406 #if !defined(DHCP6) && !defined(DHCP)
92c215d75a0c Fix compile without INET6
Roy Marples <roy@marples.name>
parents: 4279
diff changeset
407 UNUSED(stop);
92c215d75a0c Fix compile without INET6
Roy Marples <roy@marples.name>
parents: 4279
diff changeset
408 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
409 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
410
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
411 static void
5501
5b2272a0f3c3 privsep: Only log chrooting from the launcher process
Roy Marples <roy@marples.name>
parents: 5499
diff changeset
412 stop_interface(struct interface *ifp, const char *reason)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
413 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
414 struct dhcpcd_ctx *ctx;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
415
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
416 ctx = ifp->ctx;
4024
0984f93d896e To be consitent, do the same to loginfo as we just did for logdebug.
Roy Marples <roy@marples.name>
parents: 4023
diff changeset
417 loginfox("%s: removing interface", ifp->name);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
418 ifp->options->options |= DHCPCD_STOPPING;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
419
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
420 dhcpcd_drop(ifp, 1);
5501
5b2272a0f3c3 privsep: Only log chrooting from the launcher process
Roy Marples <roy@marples.name>
parents: 5499
diff changeset
421 script_runreason(ifp, reason == NULL ? "STOPPED" : reason);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
422
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
423 /* Delete all timeouts for the interfaces */
5038
1e35e845790a eloop: define eloop queue numbers in common.h
Roy Marples <roy@marples.name>
parents: 5008
diff changeset
424 eloop_q_timeout_delete(ctx->eloop, ELOOP_QUEUE_ALL, NULL, ifp);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
425
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
426 /* De-activate the interface */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
427 ifp->active = IF_INACTIVE;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
428 ifp->options->options &= ~DHCPCD_STOPPING;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
429
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
430 if (!(ctx->options & (DHCPCD_MASTER | DHCPCD_TEST)))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
431 eloop_exit(ctx->eloop, EXIT_FAILURE);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
432 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
433
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
434 static void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
435 configure_interface1(struct interface *ifp)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
436 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
437 struct if_options *ifo = ifp->options;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
438
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
439 /* Do any platform specific configuration */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
440 if_conf(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
441
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
442 /* If we want to release a lease, we can't really persist the
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
443 * address either. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
444 if (ifo->options & DHCPCD_RELEASE)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
445 ifo->options &= ~DHCPCD_PERSISTENT;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
446
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
447 if (ifp->flags & (IFF_POINTOPOINT | IFF_LOOPBACK)) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
448 ifo->options &= ~DHCPCD_ARP;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
449 if (!(ifp->flags & IFF_MULTICAST))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
450 ifo->options &= ~DHCPCD_IPV6RS;
4632
a52cb3bec112 DHCP: Allow DHCP over PtP interfaces.
Roy Marples <roy@marples.name>
parents: 4622
diff changeset
451 if (!(ifo->options & (DHCPCD_INFORM | DHCPCD_WANTDHCP)))
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
452 ifo->options |= DHCPCD_STATIC;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
453 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
454
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
455 if (ifo->metric != -1)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
456 ifp->metric = (unsigned int)ifo->metric;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
457
3982
abf628d2e1fd Only disable kernel IPv6RA if we're sending IPv6RS.
Roy Marples <roy@marples.name>
parents: 3977
diff changeset
458 #ifdef INET6
4218
f618f850efdc inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents: 4214
diff changeset
459 /* We want to setup INET6 on the interface as soon as possible. */
4195
d16878b8acac ipv6: disable kernel RA if interface is active
Roy Marples <roy@marples.name>
parents: 4189
diff changeset
460 if (ifp->active == IF_ACTIVE_USER &&
4218
f618f850efdc inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents: 4214
diff changeset
461 ifo->options & DHCPCD_IPV6 &&
f618f850efdc inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents: 4214
diff changeset
462 !(ifp->ctx->options & (DHCPCD_DUMPLEASE | DHCPCD_TEST)))
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
463 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
464 /* If not doing any DHCP, disable the RDNSS requirement. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
465 if (!(ifo->options & (DHCPCD_DHCP | DHCPCD_DHCP6)))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
466 ifo->options &= ~DHCPCD_IPV6RA_REQRDNSS;
4218
f618f850efdc inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents: 4214
diff changeset
467 if_setup_inet6(ifp);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
468 }
3982
abf628d2e1fd Only disable kernel IPv6RA if we're sending IPv6RS.
Roy Marples <roy@marples.name>
parents: 3977
diff changeset
469 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
470
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
471 if (!(ifo->options & DHCPCD_IAID)) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
472 /*
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
473 * An IAID is for identifying a unqiue interface within
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
474 * the client. It is 4 bytes long. Working out a default
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
475 * value is problematic.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
476 *
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
477 * Interface name and number are not stable
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
478 * between different OS's. Some OS's also cannot make
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
479 * up their mind what the interface should be called
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
480 * (yes, udev, I'm looking at you).
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
481 * Also, the name could be longer than 4 bytes.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
482 * Also, with pluggable interfaces the name and index
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
483 * could easily get swapped per actual interface.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
484 *
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
485 * The MAC address is 6 bytes long, the final 3
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
486 * being unique to the manufacturer and the initial 3
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
487 * being unique to the organisation which makes it.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
488 * We could use the last 4 bytes of the MAC address
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
489 * as the IAID as it's the most stable part given the
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
490 * above, but equally it's not guaranteed to be
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
491 * unique.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
492 *
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
493 * Given the above, and our need to reliably work
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
494 * between reboots without persitent storage,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
495 * generating the IAID from the MAC address is the only
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
496 * logical default.
4052
08038b46c0f5 Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents: 4051
diff changeset
497 * Saying that, if a VLANID has been specified then we
08038b46c0f5 Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents: 4051
diff changeset
498 * can use that. It's possible that different interfaces
08038b46c0f5 Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents: 4051
diff changeset
499 * can have the same VLANID, but this is no worse than
08038b46c0f5 Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents: 4051
diff changeset
500 * generating the IAID from the duplicate MAC address.
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
501 *
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
502 * dhclient uses the last 4 bytes of the MAC address.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
503 * dibbler uses an increamenting counter.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
504 * wide-dhcpv6 uses 0 or a configured value.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
505 * odhcp6c uses 1.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
506 * Windows 7 uses the first 3 bytes of the MAC address
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
507 * and an unknown byte.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
508 * dhcpcd-6.1.0 and earlier used the interface name,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
509 * falling back to interface index if name > 4.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
510 */
4052
08038b46c0f5 Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents: 4051
diff changeset
511 if (ifp->vlanid != 0) {
08038b46c0f5 Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents: 4051
diff changeset
512 uint32_t vlanid;
08038b46c0f5 Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents: 4051
diff changeset
513
08038b46c0f5 Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents: 4051
diff changeset
514 /* Maximal VLANID is 4095, so prefix with 0xff
08038b46c0f5 Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents: 4051
diff changeset
515 * so we don't conflict with an interface index. */
08038b46c0f5 Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents: 4051
diff changeset
516 vlanid = htonl(ifp->vlanid | 0xff000000);
08038b46c0f5 Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents: 4051
diff changeset
517 memcpy(ifo->iaid, &vlanid, sizeof(vlanid));
4958
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4955
diff changeset
518 } else if (ifo->options & DHCPCD_ANONYMOUS)
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4955
diff changeset
519 memset(ifo->iaid, 0, sizeof(ifo->iaid));
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4955
diff changeset
520 else if (ifp->hwlen >= sizeof(ifo->iaid)) {
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
521 memcpy(ifo->iaid,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
522 ifp->hwaddr + ifp->hwlen - sizeof(ifo->iaid),
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
523 sizeof(ifo->iaid));
4052
08038b46c0f5 Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents: 4051
diff changeset
524 } else {
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
525 uint32_t len;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
526
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
527 len = (uint32_t)strlen(ifp->name);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
528 if (len <= sizeof(ifo->iaid)) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
529 memcpy(ifo->iaid, ifp->name, len);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
530 if (len < sizeof(ifo->iaid))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
531 memset(ifo->iaid + len, 0,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
532 sizeof(ifo->iaid) - len);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
533 } else {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
534 /* IAID is the same size as a uint32_t */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
535 len = htonl(ifp->index);
4052
08038b46c0f5 Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents: 4051
diff changeset
536 memcpy(ifo->iaid, &len, sizeof(ifo->iaid));
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
537 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
538 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
539 ifo->options |= DHCPCD_IAID;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
540 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
541
4349
f87c2ed9ff46 DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents: 4348
diff changeset
542 #ifdef DHCP6
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
543 if (ifo->ia_len == 0 && ifo->options & DHCPCD_IPV6 &&
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
544 ifp->name[0] != '\0')
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
545 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
546 ifo->ia = malloc(sizeof(*ifo->ia));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
547 if (ifo->ia == NULL)
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 4008
diff changeset
548 logerr(__func__);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
549 else {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
550 ifo->ia_len = 1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
551 ifo->ia->ia_type = D6_OPTION_IA_NA;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
552 memcpy(ifo->ia->iaid, ifo->iaid, sizeof(ifo->iaid));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
553 memset(&ifo->ia->addr, 0, sizeof(ifo->ia->addr));
4072
475b9492af64 Warn about IA_PD support not being compiled in when requesting it
Roy Marples <roy@marples.name>
parents: 4059
diff changeset
554 #ifndef SMALL
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
555 ifo->ia->sla = NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
556 ifo->ia->sla_len = 0;
4072
475b9492af64 Warn about IA_PD support not being compiled in when requesting it
Roy Marples <roy@marples.name>
parents: 4059
diff changeset
557 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
558 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
559 } else {
3982
abf628d2e1fd Only disable kernel IPv6RA if we're sending IPv6RS.
Roy Marples <roy@marples.name>
parents: 3977
diff changeset
560 size_t i;
abf628d2e1fd Only disable kernel IPv6RA if we're sending IPv6RS.
Roy Marples <roy@marples.name>
parents: 3977
diff changeset
561
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
562 for (i = 0; i < ifo->ia_len; i++) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
563 if (!ifo->ia[i].iaid_set) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
564 memcpy(&ifo->ia[i].iaid, ifo->iaid,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
565 sizeof(ifo->ia[i].iaid));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
566 ifo->ia[i].iaid_set = 1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
567 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
568 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
569 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
570 #endif
4704
7c7de254053e DHCP: If root fs is network mounted, enable last lease extend
Roy Marples <roy@marples.name>
parents: 4682
diff changeset
571
7c7de254053e DHCP: If root fs is network mounted, enable last lease extend
Roy Marples <roy@marples.name>
parents: 4682
diff changeset
572 /* If root is network mounted, we don't want to kill the connection
7c7de254053e DHCP: If root fs is network mounted, enable last lease extend
Roy Marples <roy@marples.name>
parents: 4682
diff changeset
573 * if the DHCP server goes the way of the dodo OR dhcpcd is rebooting
7c7de254053e DHCP: If root fs is network mounted, enable last lease extend
Roy Marples <roy@marples.name>
parents: 4682
diff changeset
574 * and the lease file has expired. */
7c7de254053e DHCP: If root fs is network mounted, enable last lease extend
Roy Marples <roy@marples.name>
parents: 4682
diff changeset
575 if (is_root_local() == 0)
7c7de254053e DHCP: If root fs is network mounted, enable last lease extend
Roy Marples <roy@marples.name>
parents: 4682
diff changeset
576 ifo->options |= DHCPCD_LASTLEASE_EXTEND;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
577 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
578
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
579 int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
580 dhcpcd_selectprofile(struct interface *ifp, const char *profile)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
581 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
582 struct if_options *ifo;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
583 char pssid[PROFILE_LEN];
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
584
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
585 if (ifp->ssid_len) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
586 ssize_t r;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
587
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
588 r = print_string(pssid, sizeof(pssid), OT_ESCSTRING,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
589 ifp->ssid, ifp->ssid_len);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
590 if (r == -1) {
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 4008
diff changeset
591 logerr(__func__);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
592 pssid[0] = '\0';
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
593 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
594 } else
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
595 pssid[0] = '\0';
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
596 ifo = read_config(ifp->ctx, ifp->name, pssid, profile);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
597 if (ifo == NULL) {
4023
66f9399ba5c6 Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents: 4021
diff changeset
598 logdebugx("%s: no profile %s", ifp->name, profile);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
599 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
600 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
601 if (profile != NULL) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
602 strlcpy(ifp->profile, profile, sizeof(ifp->profile));
4024
0984f93d896e To be consitent, do the same to loginfo as we just did for logdebug.
Roy Marples <roy@marples.name>
parents: 4023
diff changeset
603 loginfox("%s: selected profile %s", ifp->name, profile);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
604 } else
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
605 *ifp->profile = '\0';
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
606
4249
c30233f8cca3 routes: allow a head clear with a context
Roy Marples <roy@marples.name>
parents: 4246
diff changeset
607 free_options(ifp->ctx, ifp->options);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
608 ifp->options = ifo;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
609 if (profile) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
610 add_options(ifp->ctx, ifp->name, ifp->options,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
611 ifp->ctx->argc, ifp->ctx->argv);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
612 configure_interface1(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
613 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
614 return 1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
615 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
616
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
617 static void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
618 configure_interface(struct interface *ifp, int argc, char **argv,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
619 unsigned long long options)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
620 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
621 time_t old;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
622
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
623 old = ifp->options ? ifp->options->mtime : 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
624 dhcpcd_selectprofile(ifp, NULL);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
625 if (ifp->options == NULL) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
626 /* dhcpcd cannot continue with this interface. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
627 ifp->active = IF_INACTIVE;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
628 return;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
629 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
630 add_options(ifp->ctx, ifp->name, ifp->options, argc, argv);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
631 ifp->options->options |= options;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
632 configure_interface1(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
633
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
634 /* If the mtime has changed drop any old lease */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
635 if (old != 0 && ifp->options->mtime != old) {
4988
1369161bbc7c privsep: Close stdout/stderr after forking processes
Roy Marples <roy@marples.name>
parents: 4969
diff changeset
636 logwarnx("%s: config file changed, expiring leases",
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 4008
diff changeset
637 ifp->name);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
638 dhcpcd_drop(ifp, 0);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
639 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
640 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
641
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
642 static void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
643 dhcpcd_initstate2(struct interface *ifp, unsigned long long options)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
644 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
645 struct if_options *ifo;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
646
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
647 if (options) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
648 if ((ifo = default_config(ifp->ctx)) == NULL) {
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 4008
diff changeset
649 logerr(__func__);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
650 return;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
651 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
652 ifo->options |= options;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
653 free(ifp->options);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
654 ifp->options = ifo;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
655 } else
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
656 ifo = ifp->options;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
657
4119
fcddf3690162 Fix compile without INET6.
Roy Marples <roy@marples.name>
parents: 4113
diff changeset
658 #ifdef INET6
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
659 if (ifo->options & DHCPCD_IPV6 && ipv6_init(ifp->ctx) == -1) {
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 4008
diff changeset
660 logerr(__func__);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
661 ifo->options &= ~DHCPCD_IPV6;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
662 }
4119
fcddf3690162 Fix compile without INET6.
Roy Marples <roy@marples.name>
parents: 4113
diff changeset
663 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
664 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
665
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
666 static void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
667 dhcpcd_initstate1(struct interface *ifp, int argc, char **argv,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
668 unsigned long long options)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
669 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
670
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
671 configure_interface(ifp, argc, argv, options);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
672 if (ifp->active)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
673 dhcpcd_initstate2(ifp, 0);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
674 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
675
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
676 static void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
677 dhcpcd_initstate(struct interface *ifp, unsigned long long options)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
678 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
679
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
680 dhcpcd_initstate1(ifp, ifp->ctx->argc, ifp->ctx->argv, options);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
681 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
682
4823
a287a14cf718 dhcpcd: report SSID connected to when we gain carrier
Roy Marples <roy@marples.name>
parents: 4799
diff changeset
683 static void
a287a14cf718 dhcpcd: report SSID connected to when we gain carrier
Roy Marples <roy@marples.name>
parents: 4799
diff changeset
684 dhcpcd_reportssid(struct interface *ifp)
a287a14cf718 dhcpcd: report SSID connected to when we gain carrier
Roy Marples <roy@marples.name>
parents: 4799
diff changeset
685 {
a287a14cf718 dhcpcd: report SSID connected to when we gain carrier
Roy Marples <roy@marples.name>
parents: 4799
diff changeset
686 char pssid[IF_SSIDLEN * 4];
a287a14cf718 dhcpcd: report SSID connected to when we gain carrier
Roy Marples <roy@marples.name>
parents: 4799
diff changeset
687
a287a14cf718 dhcpcd: report SSID connected to when we gain carrier
Roy Marples <roy@marples.name>
parents: 4799
diff changeset
688 if (print_string(pssid, sizeof(pssid), OT_ESCSTRING,
a287a14cf718 dhcpcd: report SSID connected to when we gain carrier
Roy Marples <roy@marples.name>
parents: 4799
diff changeset
689 ifp->ssid, ifp->ssid_len) == -1)
a287a14cf718 dhcpcd: report SSID connected to when we gain carrier
Roy Marples <roy@marples.name>
parents: 4799
diff changeset
690 {
a287a14cf718 dhcpcd: report SSID connected to when we gain carrier
Roy Marples <roy@marples.name>
parents: 4799
diff changeset
691 logerr(__func__);
a287a14cf718 dhcpcd: report SSID connected to when we gain carrier
Roy Marples <roy@marples.name>
parents: 4799
diff changeset
692 return;
a287a14cf718 dhcpcd: report SSID connected to when we gain carrier
Roy Marples <roy@marples.name>
parents: 4799
diff changeset
693 }
a287a14cf718 dhcpcd: report SSID connected to when we gain carrier
Roy Marples <roy@marples.name>
parents: 4799
diff changeset
694
5494
0fbde4769bbe Don't log backticks.
Roy Marples <roy@marples.name>
parents: 5490
diff changeset
695 loginfox("%s: connected to Access Point: %s", ifp->name, pssid);
4823
a287a14cf718 dhcpcd: report SSID connected to when we gain carrier
Roy Marples <roy@marples.name>
parents: 4799
diff changeset
696 }
a287a14cf718 dhcpcd: report SSID connected to when we gain carrier
Roy Marples <roy@marples.name>
parents: 4799
diff changeset
697
5557
e65d193a1960 Linux: Support wireless IP roaming
Roy Marples <roy@marples.name>
parents: 5552
diff changeset
698 static void
e65d193a1960 Linux: Support wireless IP roaming
Roy Marples <roy@marples.name>
parents: 5552
diff changeset
699 dhcpcd_nocarrier_roaming(struct interface *ifp)
e65d193a1960 Linux: Support wireless IP roaming
Roy Marples <roy@marples.name>
parents: 5552
diff changeset
700 {
e65d193a1960 Linux: Support wireless IP roaming
Roy Marples <roy@marples.name>
parents: 5552
diff changeset
701
e65d193a1960 Linux: Support wireless IP roaming
Roy Marples <roy@marples.name>
parents: 5552
diff changeset
702 loginfox("%s: carrier lost - roaming", ifp->name);
e65d193a1960 Linux: Support wireless IP roaming
Roy Marples <roy@marples.name>
parents: 5552
diff changeset
703
e65d193a1960 Linux: Support wireless IP roaming
Roy Marples <roy@marples.name>
parents: 5552
diff changeset
704 #ifdef ARP
e65d193a1960 Linux: Support wireless IP roaming
Roy Marples <roy@marples.name>
parents: 5552
diff changeset
705 arp_drop(ifp);
e65d193a1960 Linux: Support wireless IP roaming
Roy Marples <roy@marples.name>
parents: 5552
diff changeset
706 #endif
e65d193a1960 Linux: Support wireless IP roaming
Roy Marples <roy@marples.name>
parents: 5552
diff changeset
707 #ifdef INET
e65d193a1960 Linux: Support wireless IP roaming
Roy Marples <roy@marples.name>
parents: 5552
diff changeset
708 dhcp_abort(ifp);
e65d193a1960 Linux: Support wireless IP roaming
Roy Marples <roy@marples.name>
parents: 5552
diff changeset
709 #endif
e65d193a1960 Linux: Support wireless IP roaming
Roy Marples <roy@marples.name>
parents: 5552
diff changeset
710 #ifdef DHCP6
e65d193a1960 Linux: Support wireless IP roaming
Roy Marples <roy@marples.name>
parents: 5552
diff changeset
711 dhcp6_abort(ifp);
e65d193a1960 Linux: Support wireless IP roaming
Roy Marples <roy@marples.name>
parents: 5552
diff changeset
712 #endif
5568
cebc093fd611 Adjust prior to build routes and run script after aborting protocols for roaming
Roy Marples <roy@marples.name>
parents: 5567
diff changeset
713
cebc093fd611 Adjust prior to build routes and run script after aborting protocols for roaming
Roy Marples <roy@marples.name>
parents: 5567
diff changeset
714 rt_build(ifp->ctx, AF_UNSPEC);
cebc093fd611 Adjust prior to build routes and run script after aborting protocols for roaming
Roy Marples <roy@marples.name>
parents: 5567
diff changeset
715 script_runreason(ifp, "NOCARRIER_ROAMING");
5557
e65d193a1960 Linux: Support wireless IP roaming
Roy Marples <roy@marples.name>
parents: 5552
diff changeset
716 }
e65d193a1960 Linux: Support wireless IP roaming
Roy Marples <roy@marples.name>
parents: 5552
diff changeset
717
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
718 void
5486
8e2b8ce8c972 BSD: struct if_data->ifi_link_state is the single source of truth
Roy Marples <roy@marples.name>
parents: 5484
diff changeset
719 dhcpcd_handlecarrier(struct interface *ifp, int carrier, unsigned int flags)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
720 {
5499
6a2da5651841 dhcpcd: Simplify the link handling even more
Roy Marples <roy@marples.name>
parents: 5497
diff changeset
721 bool was_link_up = if_is_link_up(ifp);
5557
e65d193a1960 Linux: Support wireless IP roaming
Roy Marples <roy@marples.name>
parents: 5552
diff changeset
722 bool was_roaming = if_roaming(ifp);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
723
5499
6a2da5651841 dhcpcd: Simplify the link handling even more
Roy Marples <roy@marples.name>
parents: 5497
diff changeset
724 ifp->carrier = carrier;
5486
8e2b8ce8c972 BSD: struct if_data->ifi_link_state is the single source of truth
Roy Marples <roy@marples.name>
parents: 5484
diff changeset
725 ifp->flags = flags;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
726
5499
6a2da5651841 dhcpcd: Simplify the link handling even more
Roy Marples <roy@marples.name>
parents: 5497
diff changeset
727 if (!if_is_link_up(ifp)) {
5557
e65d193a1960 Linux: Support wireless IP roaming
Roy Marples <roy@marples.name>
parents: 5552
diff changeset
728 if (!ifp->active || (!was_link_up && !was_roaming))
5497
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
729 return;
5557
e65d193a1960 Linux: Support wireless IP roaming
Roy Marples <roy@marples.name>
parents: 5552
diff changeset
730
e65d193a1960 Linux: Support wireless IP roaming
Roy Marples <roy@marples.name>
parents: 5552
diff changeset
731 /*
e65d193a1960 Linux: Support wireless IP roaming
Roy Marples <roy@marples.name>
parents: 5552
diff changeset
732 * If the interface is roaming (generally on wireless)
e65d193a1960 Linux: Support wireless IP roaming
Roy Marples <roy@marples.name>
parents: 5552
diff changeset
733 * then while we are not up, we are not down either.
e65d193a1960 Linux: Support wireless IP roaming
Roy Marples <roy@marples.name>
parents: 5552
diff changeset
734 * Preserve the network state until we either disconnect
e65d193a1960 Linux: Support wireless IP roaming
Roy Marples <roy@marples.name>
parents: 5552
diff changeset
735 * or re-connect.
e65d193a1960 Linux: Support wireless IP roaming
Roy Marples <roy@marples.name>
parents: 5552
diff changeset
736 */
5570
f32e37b1d371 dhcpcd: Don't roam when anonymous is set
Roy Marples <roy@marples.name>
parents: 5568
diff changeset
737 if (!(ifp->options->options & DHCPCD_ANONYMOUS) &&
f32e37b1d371 dhcpcd: Don't roam when anonymous is set
Roy Marples <roy@marples.name>
parents: 5568
diff changeset
738 if_roaming(ifp))
f32e37b1d371 dhcpcd: Don't roam when anonymous is set
Roy Marples <roy@marples.name>
parents: 5568
diff changeset
739 {
5557
e65d193a1960 Linux: Support wireless IP roaming
Roy Marples <roy@marples.name>
parents: 5552
diff changeset
740 dhcpcd_nocarrier_roaming(ifp);
e65d193a1960 Linux: Support wireless IP roaming
Roy Marples <roy@marples.name>
parents: 5552
diff changeset
741 return;
e65d193a1960 Linux: Support wireless IP roaming
Roy Marples <roy@marples.name>
parents: 5552
diff changeset
742 }
e65d193a1960 Linux: Support wireless IP roaming
Roy Marples <roy@marples.name>
parents: 5552
diff changeset
743
e65d193a1960 Linux: Support wireless IP roaming
Roy Marples <roy@marples.name>
parents: 5552
diff changeset
744 loginfox("%s: carrier lost", ifp->name);
e65d193a1960 Linux: Support wireless IP roaming
Roy Marples <roy@marples.name>
parents: 5552
diff changeset
745 script_runreason(ifp, "NOCARRIER");
e65d193a1960 Linux: Support wireless IP roaming
Roy Marples <roy@marples.name>
parents: 5552
diff changeset
746 dhcpcd_drop(ifp, 0);
e65d193a1960 Linux: Support wireless IP roaming
Roy Marples <roy@marples.name>
parents: 5552
diff changeset
747
5497
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
748 if (ifp->options->options & DHCPCD_ANONYMOUS) {
5499
6a2da5651841 dhcpcd: Simplify the link handling even more
Roy Marples <roy@marples.name>
parents: 5497
diff changeset
749 bool is_up = ifp->flags & IFF_UP;
5497
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
750
5499
6a2da5651841 dhcpcd: Simplify the link handling even more
Roy Marples <roy@marples.name>
parents: 5497
diff changeset
751 if (is_up)
5497
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
752 if_down(ifp);
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
753 if (if_randomisemac(ifp) == -1 && errno != ENXIO)
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
754 logerr(__func__);
5499
6a2da5651841 dhcpcd: Simplify the link handling even more
Roy Marples <roy@marples.name>
parents: 5497
diff changeset
755 if (is_up)
5497
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
756 if_up(ifp);
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
757 }
5557
e65d193a1960 Linux: Support wireless IP roaming
Roy Marples <roy@marples.name>
parents: 5552
diff changeset
758
5497
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
759 return;
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
760 }
5005
ffb5b2280ed2 dhcpcd: For anonymous do not bring interface up if was down
Roy Marples <roy@marples.name>
parents: 4997
diff changeset
761
5497
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
762 /*
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
763 * At this point carrier is NOT DOWN and we have IFF_UP.
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
764 * We should treat LINK_UNKNOWN as up as the driver may not support
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
765 * link state changes.
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
766 * The consideration of any other information about carrier should
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
767 * be handled in the OS specific if_carrier() function.
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
768 */
5499
6a2da5651841 dhcpcd: Simplify the link handling even more
Roy Marples <roy@marples.name>
parents: 5497
diff changeset
769 if (was_link_up)
5497
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
770 return;
5499
6a2da5651841 dhcpcd: Simplify the link handling even more
Roy Marples <roy@marples.name>
parents: 5497
diff changeset
771
5497
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
772 if (ifp->active) {
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
773 if (carrier == LINK_UNKNOWN)
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
774 loginfox("%s: carrier unknown, assuming up", ifp->name);
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
775 else
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
776 loginfox("%s: carrier acquired", ifp->name);
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
777 }
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
778
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
779 #if !defined(__linux__) && !defined(__NetBSD__)
5497
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
780 /* BSD does not emit RTM_NEWADDR or RTM_CHGADDR when the
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
781 * hardware address changes so we have to go
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
782 * through the disovery process to work it out. */
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
783 dhcpcd_handleinterface(ifp->ctx, 0, ifp->name);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
784 #endif
5497
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
785
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
786 if (ifp->wireless) {
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
787 uint8_t ossid[IF_SSIDLEN];
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
788 size_t olen;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
789
5497
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
790 olen = ifp->ssid_len;
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
791 memcpy(ossid, ifp->ssid, ifp->ssid_len);
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
792 if_getssid(ifp);
4341
990fde22c376 IPv4LL: Preserve address when carrier drops
Roy Marples <roy@marples.name>
parents: 4335
diff changeset
793
5497
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
794 /* If we changed SSID network, drop leases */
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
795 if ((ifp->ssid_len != olen ||
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
796 memcmp(ifp->ssid, ossid, ifp->ssid_len)) && ifp->active)
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
797 {
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
798 dhcpcd_reportssid(ifp);
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
799 dhcpcd_drop(ifp, 0);
4345
b9694106b686 IPv4LL: Fix build if not enabled.
Roy Marples <roy@marples.name>
parents: 4342
diff changeset
800 #ifdef IPV4LL
5497
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
801 ipv4ll_reset(ifp);
4345
b9694106b686 IPv4LL: Fix build if not enabled.
Roy Marples <roy@marples.name>
parents: 4342
diff changeset
802 #endif
5497
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
803 }
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
804 }
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
805
5499
6a2da5651841 dhcpcd: Simplify the link handling even more
Roy Marples <roy@marples.name>
parents: 5497
diff changeset
806 if (!ifp->active)
5497
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
807 return;
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
808
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
809 dhcpcd_initstate(ifp, 0);
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
810 script_runreason(ifp, "CARRIER");
5557
e65d193a1960 Linux: Support wireless IP roaming
Roy Marples <roy@marples.name>
parents: 5552
diff changeset
811
4351
b7a9f2b43d50 IP6ND: Remove #defines for functions when INET6 is disabled
Roy Marples <roy@marples.name>
parents: 4349
diff changeset
812 #ifdef INET6
5497
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
813 /* Set any IPv6 Routers we remembered to expire faster than they
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
814 * would normally as we maybe on a new network. */
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
815 ipv6nd_startexpire(ifp);
5128
d4668acf8d76 Fix build on Linux
Roy Marples <roy@marples.name>
parents: 5127
diff changeset
816 #ifdef IPV6_MANAGETEMPADDR
5497
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
817 /* RFC4941 Section 3.5 */
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
818 ipv6_regentempaddrs(ifp);
4351
b7a9f2b43d50 IP6ND: Remove #defines for functions when INET6 is disabled
Roy Marples <roy@marples.name>
parents: 4349
diff changeset
819 #endif
5128
d4668acf8d76 Fix build on Linux
Roy Marples <roy@marples.name>
parents: 5127
diff changeset
820 #endif
5557
e65d193a1960 Linux: Support wireless IP roaming
Roy Marples <roy@marples.name>
parents: 5552
diff changeset
821
5497
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
822 dhcpcd_startinterface(ifp);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
823 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
824
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
825 static void
4279
cdffb0137daa dhcp6: IAID is now unique for IA type
Roy Marples <roy@marples.name>
parents: 4250
diff changeset
826 warn_iaid_conflict(struct interface *ifp, uint16_t ia_type, uint8_t *iaid)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
827 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
828 struct interface *ifn;
4285
92c215d75a0c Fix compile without INET6
Roy Marples <roy@marples.name>
parents: 4279
diff changeset
829 #ifdef INET6
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
830 size_t i;
4279
cdffb0137daa dhcp6: IAID is now unique for IA type
Roy Marples <roy@marples.name>
parents: 4250
diff changeset
831 struct if_ia *ia;
4285
92c215d75a0c Fix compile without INET6
Roy Marples <roy@marples.name>
parents: 4279
diff changeset
832 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
833
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
834 TAILQ_FOREACH(ifn, ifp->ctx->ifaces, next) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
835 if (ifn == ifp || !ifn->active)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
836 continue;
4965
78a1e76b04bd dhcpcd: Don't report DUID or IAID in anonymous.
Roy Marples <roy@marples.name>
parents: 4959
diff changeset
837 if (ifn->options->options & DHCPCD_ANONYMOUS)
78a1e76b04bd dhcpcd: Don't report DUID or IAID in anonymous.
Roy Marples <roy@marples.name>
parents: 4959
diff changeset
838 continue;
4279
cdffb0137daa dhcp6: IAID is now unique for IA type
Roy Marples <roy@marples.name>
parents: 4250
diff changeset
839 if (ia_type == 0 &&
cdffb0137daa dhcp6: IAID is now unique for IA type
Roy Marples <roy@marples.name>
parents: 4250
diff changeset
840 memcmp(ifn->options->iaid, iaid,
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
841 sizeof(ifn->options->iaid)) == 0)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
842 break;
4285
92c215d75a0c Fix compile without INET6
Roy Marples <roy@marples.name>
parents: 4279
diff changeset
843 #ifdef INET6
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
844 for (i = 0; i < ifn->options->ia_len; i++) {
4279
cdffb0137daa dhcp6: IAID is now unique for IA type
Roy Marples <roy@marples.name>
parents: 4250
diff changeset
845 ia = &ifn->options->ia[i];
cdffb0137daa dhcp6: IAID is now unique for IA type
Roy Marples <roy@marples.name>
parents: 4250
diff changeset
846 if (ia->ia_type == ia_type &&
cdffb0137daa dhcp6: IAID is now unique for IA type
Roy Marples <roy@marples.name>
parents: 4250
diff changeset
847 memcmp(ia->iaid, iaid, sizeof(ia->iaid)) == 0)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
848 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
849 }
4285
92c215d75a0c Fix compile without INET6
Roy Marples <roy@marples.name>
parents: 4279
diff changeset
850 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
851 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
852
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
853 /* This is only a problem if the interfaces are on the same network. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
854 if (ifn)
4050
b3337611d1b1 Don't report a real error here.
Roy Marples <roy@marples.name>
parents: 4047
diff changeset
855 logerrx("%s: IAID conflicts with one assigned to %s",
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
856 ifp->name, ifn->name);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
857 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
858
5207
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
859 static void
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
860 dhcpcd_initduid(struct dhcpcd_ctx *ctx, struct interface *ifp)
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
861 {
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
862 char buf[DUID_LEN * 3];
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
863
5551
0c4608a6cc2a options: Allow duid to take a value
Roy Marples <roy@marples.name>
parents: 5550
diff changeset
864 if (ctx->duid != NULL) {
0c4608a6cc2a options: Allow duid to take a value
Roy Marples <roy@marples.name>
parents: 5550
diff changeset
865 if (ifp == NULL)
0c4608a6cc2a options: Allow duid to take a value
Roy Marples <roy@marples.name>
parents: 5550
diff changeset
866 goto log;
5207
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
867 return;
5551
0c4608a6cc2a options: Allow duid to take a value
Roy Marples <roy@marples.name>
parents: 5550
diff changeset
868 }
5207
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
869
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
870 duid_init(ctx, ifp);
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
871 if (ctx->duid == NULL)
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
872 return;
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
873
5551
0c4608a6cc2a options: Allow duid to take a value
Roy Marples <roy@marples.name>
parents: 5550
diff changeset
874 log:
5207
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
875 loginfox("DUID %s",
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
876 hwaddr_ntoa(ctx->duid, ctx->duid_len, buf, sizeof(buf)));
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
877 }
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
878
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
879 void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
880 dhcpcd_startinterface(void *arg)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
881 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
882 struct interface *ifp = arg;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
883 struct if_options *ifo = ifp->options;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
884
5499
6a2da5651841 dhcpcd: Simplify the link handling even more
Roy Marples <roy@marples.name>
parents: 5497
diff changeset
885 if (ifo->options & DHCPCD_LINK && !if_is_link_up(ifp)) {
5486
8e2b8ce8c972 BSD: struct if_data->ifi_link_state is the single source of truth
Roy Marples <roy@marples.name>
parents: 5484
diff changeset
886 loginfox("%s: waiting for carrier", ifp->name);
8e2b8ce8c972 BSD: struct if_data->ifi_link_state is the single source of truth
Roy Marples <roy@marples.name>
parents: 5484
diff changeset
887 return;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
888 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
889
4965
78a1e76b04bd dhcpcd: Don't report DUID or IAID in anonymous.
Roy Marples <roy@marples.name>
parents: 4959
diff changeset
890 if (ifo->options & (DHCPCD_DUID | DHCPCD_IPV6) &&
78a1e76b04bd dhcpcd: Don't report DUID or IAID in anonymous.
Roy Marples <roy@marples.name>
parents: 4959
diff changeset
891 !(ifo->options & DHCPCD_ANONYMOUS))
78a1e76b04bd dhcpcd: Don't report DUID or IAID in anonymous.
Roy Marples <roy@marples.name>
parents: 4959
diff changeset
892 {
5207
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
893 char buf[sizeof(ifo->iaid) * 3];
4965
78a1e76b04bd dhcpcd: Don't report DUID or IAID in anonymous.
Roy Marples <roy@marples.name>
parents: 4959
diff changeset
894 #ifdef INET6
78a1e76b04bd dhcpcd: Don't report DUID or IAID in anonymous.
Roy Marples <roy@marples.name>
parents: 4959
diff changeset
895 size_t i;
78a1e76b04bd dhcpcd: Don't report DUID or IAID in anonymous.
Roy Marples <roy@marples.name>
parents: 4959
diff changeset
896 struct if_ia *ia;
78a1e76b04bd dhcpcd: Don't report DUID or IAID in anonymous.
Roy Marples <roy@marples.name>
parents: 4959
diff changeset
897 #endif
78a1e76b04bd dhcpcd: Don't report DUID or IAID in anonymous.
Roy Marples <roy@marples.name>
parents: 4959
diff changeset
898
5207
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
899 /* Try and init DUID from the interface hardware address */
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
900 dhcpcd_initduid(ifp->ctx, ifp);
4279
cdffb0137daa dhcp6: IAID is now unique for IA type
Roy Marples <roy@marples.name>
parents: 4250
diff changeset
901
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
902 /* Report IAIDs */
4024
0984f93d896e To be consitent, do the same to loginfo as we just did for logdebug.
Roy Marples <roy@marples.name>
parents: 4023
diff changeset
903 loginfox("%s: IAID %s", ifp->name,
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
904 hwaddr_ntoa(ifo->iaid, sizeof(ifo->iaid),
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
905 buf, sizeof(buf)));
4279
cdffb0137daa dhcp6: IAID is now unique for IA type
Roy Marples <roy@marples.name>
parents: 4250
diff changeset
906 warn_iaid_conflict(ifp, 0, ifo->iaid);
5207
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
907
4285
92c215d75a0c Fix compile without INET6
Roy Marples <roy@marples.name>
parents: 4279
diff changeset
908 #ifdef INET6
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
909 for (i = 0; i < ifo->ia_len; i++) {
4279
cdffb0137daa dhcp6: IAID is now unique for IA type
Roy Marples <roy@marples.name>
parents: 4250
diff changeset
910 ia = &ifo->ia[i];
cdffb0137daa dhcp6: IAID is now unique for IA type
Roy Marples <roy@marples.name>
parents: 4250
diff changeset
911 if (memcmp(ifo->iaid, ia->iaid, sizeof(ifo->iaid))) {
cdffb0137daa dhcp6: IAID is now unique for IA type
Roy Marples <roy@marples.name>
parents: 4250
diff changeset
912 loginfox("%s: IA type %u IAID %s",
cdffb0137daa dhcp6: IAID is now unique for IA type
Roy Marples <roy@marples.name>
parents: 4250
diff changeset
913 ifp->name, ia->ia_type,
cdffb0137daa dhcp6: IAID is now unique for IA type
Roy Marples <roy@marples.name>
parents: 4250
diff changeset
914 hwaddr_ntoa(ia->iaid, sizeof(ia->iaid),
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
915 buf, sizeof(buf)));
4279
cdffb0137daa dhcp6: IAID is now unique for IA type
Roy Marples <roy@marples.name>
parents: 4250
diff changeset
916 warn_iaid_conflict(ifp, ia->ia_type, ia->iaid);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
917 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
918 }
4285
92c215d75a0c Fix compile without INET6
Roy Marples <roy@marples.name>
parents: 4279
diff changeset
919 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
920 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
921
4351
b7a9f2b43d50 IP6ND: Remove #defines for functions when INET6 is disabled
Roy Marples <roy@marples.name>
parents: 4349
diff changeset
922 #ifdef INET6
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
923 if (ifo->options & DHCPCD_IPV6 && ipv6_start(ifp) == -1) {
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 4008
diff changeset
924 logerr("%s: ipv6_start", ifp->name);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
925 ifo->options &= ~DHCPCD_IPV6;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
926 }
4351
b7a9f2b43d50 IP6ND: Remove #defines for functions when INET6 is disabled
Roy Marples <roy@marples.name>
parents: 4349
diff changeset
927
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
928 if (ifo->options & DHCPCD_IPV6) {
4111
2e9728768a4b dhcpcd starts inactive interfaces erroneously.
Roy Marples <roy@marples.name>
parents: 4076
diff changeset
929 if (ifp->active == IF_ACTIVE_USER) {
2e9728768a4b dhcpcd starts inactive interfaces erroneously.
Roy Marples <roy@marples.name>
parents: 4076
diff changeset
930 ipv6_startstatic(ifp);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
931
4111
2e9728768a4b dhcpcd starts inactive interfaces erroneously.
Roy Marples <roy@marples.name>
parents: 4076
diff changeset
932 if (ifo->options & DHCPCD_IPV6RS)
2e9728768a4b dhcpcd starts inactive interfaces erroneously.
Roy Marples <roy@marples.name>
parents: 4076
diff changeset
933 ipv6nd_startrs(ifp);
2e9728768a4b dhcpcd starts inactive interfaces erroneously.
Roy Marples <roy@marples.name>
parents: 4076
diff changeset
934 }
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
935
4349
f87c2ed9ff46 DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents: 4348
diff changeset
936 #ifdef DHCP6
5343
8b216a105409 DHCP6: Apply delegations to interface on carrier up
Roy Marples <roy@marples.name>
parents: 5331
diff changeset
937 /* DHCPv6 could be turned off, but the interface
8b216a105409 DHCP6: Apply delegations to interface on carrier up
Roy Marples <roy@marples.name>
parents: 5331
diff changeset
938 * is still delegated to. */
8b216a105409 DHCP6: Apply delegations to interface on carrier up
Roy Marples <roy@marples.name>
parents: 5331
diff changeset
939 if (ifp->active)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
940 dhcp6_find_delegates(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
941
5343
8b216a105409 DHCP6: Apply delegations to interface on carrier up
Roy Marples <roy@marples.name>
parents: 5331
diff changeset
942 if (ifo->options & DHCPCD_DHCP6) {
4183
115cbfa711e2 DHCPv6: confirm lease on carrier up
Roy Marples <roy@marples.name>
parents: 4135
diff changeset
943 if (ifp->active == IF_ACTIVE_USER) {
115cbfa711e2 DHCPv6: confirm lease on carrier up
Roy Marples <roy@marples.name>
parents: 4135
diff changeset
944 enum DH6S d6_state;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
945
4183
115cbfa711e2 DHCPv6: confirm lease on carrier up
Roy Marples <roy@marples.name>
parents: 4135
diff changeset
946 if (ifo->options & DHCPCD_IA_FORCED)
115cbfa711e2 DHCPv6: confirm lease on carrier up
Roy Marples <roy@marples.name>
parents: 4135
diff changeset
947 d6_state = DH6S_INIT;
115cbfa711e2 DHCPv6: confirm lease on carrier up
Roy Marples <roy@marples.name>
parents: 4135
diff changeset
948 else if (ifo->options & DHCPCD_INFORM6)
115cbfa711e2 DHCPv6: confirm lease on carrier up
Roy Marples <roy@marples.name>
parents: 4135
diff changeset
949 d6_state = DH6S_INFORM;
115cbfa711e2 DHCPv6: confirm lease on carrier up
Roy Marples <roy@marples.name>
parents: 4135
diff changeset
950 else
115cbfa711e2 DHCPv6: confirm lease on carrier up
Roy Marples <roy@marples.name>
parents: 4135
diff changeset
951 d6_state = DH6S_CONFIRM;
115cbfa711e2 DHCPv6: confirm lease on carrier up
Roy Marples <roy@marples.name>
parents: 4135
diff changeset
952 if (dhcp6_start(ifp, d6_state) == -1)
115cbfa711e2 DHCPv6: confirm lease on carrier up
Roy Marples <roy@marples.name>
parents: 4135
diff changeset
953 logerr("%s: dhcp6_start", ifp->name);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
954 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
955 }
4349
f87c2ed9ff46 DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents: 4348
diff changeset
956 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
957 }
4351
b7a9f2b43d50 IP6ND: Remove #defines for functions when INET6 is disabled
Roy Marples <roy@marples.name>
parents: 4349
diff changeset
958 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
959
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
960 #ifdef INET
4111
2e9728768a4b dhcpcd starts inactive interfaces erroneously.
Roy Marples <roy@marples.name>
parents: 4076
diff changeset
961 if (ifo->options & DHCPCD_IPV4 && ifp->active == IF_ACTIVE_USER) {
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
962 /* Ensure we have an IPv4 state before starting DHCP */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
963 if (ipv4_getstate(ifp) != NULL)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
964 dhcp_start(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
965 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
966 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
967 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
968
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
969 static void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
970 dhcpcd_prestartinterface(void *arg)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
971 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
972 struct interface *ifp = arg;
5376
66bbeeebbe92 dhcpcd: Add an option to poll the interface carrier state
Roy Marples <roy@marples.name>
parents: 5373
diff changeset
973 struct dhcpcd_ctx *ctx = ifp->ctx;
5055
db92f78f92b4 dhcpcd: randomise hardware address on start if no carrier
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
974 bool anondown;
db92f78f92b4 dhcpcd: randomise hardware address on start if no carrier
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
975
5497
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
976 if (ifp->carrier <= LINK_DOWN &&
5055
db92f78f92b4 dhcpcd: randomise hardware address on start if no carrier
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
977 ifp->options->options & DHCPCD_ANONYMOUS &&
db92f78f92b4 dhcpcd: randomise hardware address on start if no carrier
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
978 ifp->flags & IFF_UP)
db92f78f92b4 dhcpcd: randomise hardware address on start if no carrier
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
979 {
db92f78f92b4 dhcpcd: randomise hardware address on start if no carrier
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
980 if_down(ifp);
db92f78f92b4 dhcpcd: randomise hardware address on start if no carrier
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
981 anondown = true;
db92f78f92b4 dhcpcd: randomise hardware address on start if no carrier
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
982 } else
db92f78f92b4 dhcpcd: randomise hardware address on start if no carrier
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
983 anondown = false;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
984
5376
66bbeeebbe92 dhcpcd: Add an option to poll the interface carrier state
Roy Marples <roy@marples.name>
parents: 5373
diff changeset
985 if ((!(ctx->options & DHCPCD_MASTER) ||
5055
db92f78f92b4 dhcpcd: randomise hardware address on start if no carrier
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
986 ifp->options->options & DHCPCD_IF_UP || anondown) &&
4959
1b7325caa3ce dhcpcd: carrier up does not mean interface is up
Roy Marples <roy@marples.name>
parents: 4958
diff changeset
987 !(ifp->flags & IFF_UP))
4958
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4955
diff changeset
988 {
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4955
diff changeset
989 if (ifp->options->options & DHCPCD_ANONYMOUS &&
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4955
diff changeset
990 if_randomisemac(ifp) == -1)
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4955
diff changeset
991 logerr(__func__);
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4955
diff changeset
992 if (if_up(ifp) == -1)
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4955
diff changeset
993 logerr(__func__);
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4955
diff changeset
994 }
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
995
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
996 dhcpcd_startinterface(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
997 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
998
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
999 static void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1000 run_preinit(struct interface *ifp)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1001 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1002
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1003 if (ifp->ctx->options & DHCPCD_TEST)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1004 return;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1005
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1006 script_runreason(ifp, "PREINIT");
5499
6a2da5651841 dhcpcd: Simplify the link handling even more
Roy Marples <roy@marples.name>
parents: 5497
diff changeset
1007 if (ifp->wireless && if_is_link_up(ifp))
4823
a287a14cf718 dhcpcd: report SSID connected to when we gain carrier
Roy Marples <roy@marples.name>
parents: 4799
diff changeset
1008 dhcpcd_reportssid(ifp);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1009 if (ifp->options->options & DHCPCD_LINK && ifp->carrier != LINK_UNKNOWN)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1010 script_runreason(ifp,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1011 ifp->carrier == LINK_UP ? "CARRIER" : "NOCARRIER");
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1012 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1013
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1014 void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1015 dhcpcd_activateinterface(struct interface *ifp, unsigned long long options)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1016 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1017
5547
c9182c3618e6 Improve readability.
Roy Marples <roy@marples.name>
parents: 5538
diff changeset
1018 if (ifp->active)
c9182c3618e6 Improve readability.
Roy Marples <roy@marples.name>
parents: 5538
diff changeset
1019 return;
c9182c3618e6 Improve readability.
Roy Marples <roy@marples.name>
parents: 5538
diff changeset
1020
c9182c3618e6 Improve readability.
Roy Marples <roy@marples.name>
parents: 5538
diff changeset
1021 ifp->active = IF_ACTIVE;
c9182c3618e6 Improve readability.
Roy Marples <roy@marples.name>
parents: 5538
diff changeset
1022 dhcpcd_initstate2(ifp, options);
c9182c3618e6 Improve readability.
Roy Marples <roy@marples.name>
parents: 5538
diff changeset
1023
c9182c3618e6 Improve readability.
Roy Marples <roy@marples.name>
parents: 5538
diff changeset
1024 /* It's possible we might not have been able to load
c9182c3618e6 Improve readability.
Roy Marples <roy@marples.name>
parents: 5538
diff changeset
1025 * a config. */
c9182c3618e6 Improve readability.
Roy Marples <roy@marples.name>
parents: 5538
diff changeset
1026 if (!ifp->active)
c9182c3618e6 Improve readability.
Roy Marples <roy@marples.name>
parents: 5538
diff changeset
1027 return;
c9182c3618e6 Improve readability.
Roy Marples <roy@marples.name>
parents: 5538
diff changeset
1028
c9182c3618e6 Improve readability.
Roy Marples <roy@marples.name>
parents: 5538
diff changeset
1029 configure_interface1(ifp);
c9182c3618e6 Improve readability.
Roy Marples <roy@marples.name>
parents: 5538
diff changeset
1030 run_preinit(ifp);
c9182c3618e6 Improve readability.
Roy Marples <roy@marples.name>
parents: 5538
diff changeset
1031 dhcpcd_prestartinterface(ifp);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1032 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1033
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1034 int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1035 dhcpcd_handleinterface(void *arg, int action, const char *ifname)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1036 {
5490
df4ea0197ce8 BSD: Fix compile for non NetBSD
Roy Marples <roy@marples.name>
parents: 5486
diff changeset
1037 struct dhcpcd_ctx *ctx = arg;
4189
0b088d803b61 dhcp6: don't listen on IPv6 addresses when not using DHCP6
Roy Marples <roy@marples.name>
parents: 4184
diff changeset
1038 struct ifaddrs *ifaddrs;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1039 struct if_head *ifs;
4205
bf0ca777e4fa dhcp: don't loop needlessly when handling an interface
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1040 struct interface *ifp, *iff;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1041 const char * const argv[] = { ifname };
4571
727f73f1ffab dhcpcd: Don't leak resources if we can't find a newly added interface
Roy Marples <roy@marples.name>
parents: 4570
diff changeset
1042 int e;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1043
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1044 if (action == -1) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1045 ifp = if_find(ctx->ifaces, ifname);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1046 if (ifp == NULL) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1047 errno = ESRCH;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1048 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1049 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1050 if (ifp->active) {
4023
66f9399ba5c6 Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents: 4021
diff changeset
1051 logdebugx("%s: interface departed", ifp->name);
5501
5b2272a0f3c3 privsep: Only log chrooting from the launcher process
Roy Marples <roy@marples.name>
parents: 5499
diff changeset
1052 stop_interface(ifp, "DEPARTED");
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1053 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1054 TAILQ_REMOVE(ctx->ifaces, ifp, next);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1055 if_free(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1056 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1057 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1058
4189
0b088d803b61 dhcp6: don't listen on IPv6 addresses when not using DHCP6
Roy Marples <roy@marples.name>
parents: 4184
diff changeset
1059 ifs = if_discover(ctx, &ifaddrs, -1, UNCONST(argv));
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1060 if (ifs == NULL) {
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 4008
diff changeset
1061 logerr(__func__);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1062 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1063 }
4571
727f73f1ffab dhcpcd: Don't leak resources if we can't find a newly added interface
Roy Marples <roy@marples.name>
parents: 4570
diff changeset
1064
4205
bf0ca777e4fa dhcp: don't loop needlessly when handling an interface
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1065 ifp = if_find(ifs, ifname);
bf0ca777e4fa dhcp: don't loop needlessly when handling an interface
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1066 if (ifp == NULL) {
bf0ca777e4fa dhcp: don't loop needlessly when handling an interface
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1067 /* This can happen if an interface is quickly added
bf0ca777e4fa dhcp: don't loop needlessly when handling an interface
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1068 * and then removed. */
bf0ca777e4fa dhcp: don't loop needlessly when handling an interface
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1069 errno = ENOENT;
4571
727f73f1ffab dhcpcd: Don't leak resources if we can't find a newly added interface
Roy Marples <roy@marples.name>
parents: 4570
diff changeset
1070 e = -1;
727f73f1ffab dhcpcd: Don't leak resources if we can't find a newly added interface
Roy Marples <roy@marples.name>
parents: 4570
diff changeset
1071 goto out;
4205
bf0ca777e4fa dhcp: don't loop needlessly when handling an interface
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1072 }
4571
727f73f1ffab dhcpcd: Don't leak resources if we can't find a newly added interface
Roy Marples <roy@marples.name>
parents: 4570
diff changeset
1073 e = 1;
727f73f1ffab dhcpcd: Don't leak resources if we can't find a newly added interface
Roy Marples <roy@marples.name>
parents: 4570
diff changeset
1074
4205
bf0ca777e4fa dhcp: don't loop needlessly when handling an interface
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1075 /* Check if we already have the interface */
bf0ca777e4fa dhcp: don't loop needlessly when handling an interface
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1076 iff = if_find(ctx->ifaces, ifp->name);
4246
687273d5849d BSD: fix segfault when on carrier when IPv6 addresses are present
Roy Marples <roy@marples.name>
parents: 4239
diff changeset
1077
4205
bf0ca777e4fa dhcp: don't loop needlessly when handling an interface
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1078 if (iff != NULL) {
bf0ca777e4fa dhcp: don't loop needlessly when handling an interface
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1079 if (iff->active)
bf0ca777e4fa dhcp: don't loop needlessly when handling an interface
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1080 logdebugx("%s: interface updated", iff->name);
bf0ca777e4fa dhcp: don't loop needlessly when handling an interface
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1081 /* The flags and hwaddr could have changed */
bf0ca777e4fa dhcp: don't loop needlessly when handling an interface
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1082 iff->flags = ifp->flags;
bf0ca777e4fa dhcp: don't loop needlessly when handling an interface
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1083 iff->hwlen = ifp->hwlen;
bf0ca777e4fa dhcp: don't loop needlessly when handling an interface
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1084 if (ifp->hwlen != 0)
bf0ca777e4fa dhcp: don't loop needlessly when handling an interface
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1085 memcpy(iff->hwaddr, ifp->hwaddr, iff->hwlen);
bf0ca777e4fa dhcp: don't loop needlessly when handling an interface
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1086 } else {
bf0ca777e4fa dhcp: don't loop needlessly when handling an interface
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1087 TAILQ_REMOVE(ifs, ifp, next);
bf0ca777e4fa dhcp: don't loop needlessly when handling an interface
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1088 TAILQ_INSERT_TAIL(ctx->ifaces, ifp, next);
bf0ca777e4fa dhcp: don't loop needlessly when handling an interface
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1089 if (ifp->active) {
4023
66f9399ba5c6 Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents: 4021
diff changeset
1090 logdebugx("%s: interface added", ifp->name);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1091 dhcpcd_initstate(ifp, 0);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1092 run_preinit(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1093 }
4205
bf0ca777e4fa dhcp: don't loop needlessly when handling an interface
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1094 iff = ifp;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1095 }
4246
687273d5849d BSD: fix segfault when on carrier when IPv6 addresses are present
Roy Marples <roy@marples.name>
parents: 4239
diff changeset
1096
687273d5849d BSD: fix segfault when on carrier when IPv6 addresses are present
Roy Marples <roy@marples.name>
parents: 4239
diff changeset
1097 if (action > 0) {
687273d5849d BSD: fix segfault when on carrier when IPv6 addresses are present
Roy Marples <roy@marples.name>
parents: 4239
diff changeset
1098 if_learnaddrs(ctx, ifs, &ifaddrs);
687273d5849d BSD: fix segfault when on carrier when IPv6 addresses are present
Roy Marples <roy@marples.name>
parents: 4239
diff changeset
1099 if (iff->active)
687273d5849d BSD: fix segfault when on carrier when IPv6 addresses are present
Roy Marples <roy@marples.name>
parents: 4239
diff changeset
1100 dhcpcd_prestartinterface(iff);
687273d5849d BSD: fix segfault when on carrier when IPv6 addresses are present
Roy Marples <roy@marples.name>
parents: 4239
diff changeset
1101 }
4189
0b088d803b61 dhcp6: don't listen on IPv6 addresses when not using DHCP6
Roy Marples <roy@marples.name>
parents: 4184
diff changeset
1102
4571
727f73f1ffab dhcpcd: Don't leak resources if we can't find a newly added interface
Roy Marples <roy@marples.name>
parents: 4570
diff changeset
1103 out:
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1104 /* Free our discovered list */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1105 while ((ifp = TAILQ_FIRST(ifs))) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1106 TAILQ_REMOVE(ifs, ifp, next);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1107 if_free(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1108 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1109 free(ifs);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1110
4571
727f73f1ffab dhcpcd: Don't leak resources if we can't find a newly added interface
Roy Marples <roy@marples.name>
parents: 4570
diff changeset
1111 return e;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1112 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1113
4235
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1114 static void
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1115 dhcpcd_handlelink(void *arg)
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1116 {
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1117 struct dhcpcd_ctx *ctx = arg;
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1118
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1119 if (if_handlelink(ctx) == -1) {
4236
f6be46401658 Test for ENOMEM as well.
Roy Marples <roy@marples.name>
parents: 4235
diff changeset
1120 if (errno == ENOBUFS || errno == ENOMEM) {
4235
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1121 dhcpcd_linkoverflow(ctx);
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1122 return;
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1123 }
4503
9784c3171a22 BSD: Ignore coverity errors
Roy Marples <roy@marples.name>
parents: 4498
diff changeset
1124 if (errno != ENOTSUP)
9784c3171a22 BSD: Ignore coverity errors
Roy Marples <roy@marples.name>
parents: 4498
diff changeset
1125 logerr(__func__);
4235
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1126 }
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1127 }
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1128
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1129 static void
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1130 dhcpcd_checkcarrier(void *arg)
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1131 {
5486
8e2b8ce8c972 BSD: struct if_data->ifi_link_state is the single source of truth
Roy Marples <roy@marples.name>
parents: 5484
diff changeset
1132 struct interface *ifp0 = arg, *ifp;
4235
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1133
5486
8e2b8ce8c972 BSD: struct if_data->ifi_link_state is the single source of truth
Roy Marples <roy@marples.name>
parents: 5484
diff changeset
1134 ifp = if_find(ifp0->ctx->ifaces, ifp0->name);
8e2b8ce8c972 BSD: struct if_data->ifi_link_state is the single source of truth
Roy Marples <roy@marples.name>
parents: 5484
diff changeset
1135 if (ifp == NULL || ifp->carrier == ifp0->carrier)
8e2b8ce8c972 BSD: struct if_data->ifi_link_state is the single source of truth
Roy Marples <roy@marples.name>
parents: 5484
diff changeset
1136 return;
8e2b8ce8c972 BSD: struct if_data->ifi_link_state is the single source of truth
Roy Marples <roy@marples.name>
parents: 5484
diff changeset
1137
8e2b8ce8c972 BSD: struct if_data->ifi_link_state is the single source of truth
Roy Marples <roy@marples.name>
parents: 5484
diff changeset
1138 dhcpcd_handlecarrier(ifp, ifp0->carrier, ifp0->flags);
8e2b8ce8c972 BSD: struct if_data->ifi_link_state is the single source of truth
Roy Marples <roy@marples.name>
parents: 5484
diff changeset
1139 if_free(ifp0);
4235
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1140 }
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1141
4415
4eb8ce6f854c options: add link_rcvbuf variable
Roy Marples <roy@marples.name>
parents: 4394
diff changeset
1142 #ifndef SMALL
4eb8ce6f854c options: add link_rcvbuf variable
Roy Marples <roy@marples.name>
parents: 4394
diff changeset
1143 static void
4eb8ce6f854c options: add link_rcvbuf variable
Roy Marples <roy@marples.name>
parents: 4394
diff changeset
1144 dhcpcd_setlinkrcvbuf(struct dhcpcd_ctx *ctx)
4eb8ce6f854c options: add link_rcvbuf variable
Roy Marples <roy@marples.name>
parents: 4394
diff changeset
1145 {
4eb8ce6f854c options: add link_rcvbuf variable
Roy Marples <roy@marples.name>
parents: 4394
diff changeset
1146 socklen_t socklen;
4eb8ce6f854c options: add link_rcvbuf variable
Roy Marples <roy@marples.name>
parents: 4394
diff changeset
1147
4eb8ce6f854c options: add link_rcvbuf variable
Roy Marples <roy@marples.name>
parents: 4394
diff changeset
1148 if (ctx->link_rcvbuf == 0)
4eb8ce6f854c options: add link_rcvbuf variable
Roy Marples <roy@marples.name>
parents: 4394
diff changeset
1149 return;
4eb8ce6f854c options: add link_rcvbuf variable
Roy Marples <roy@marples.name>
parents: 4394
diff changeset
1150
5008
28209b094c6c dhcpcd: report how large a route rocket receive buffer size we set
Roy Marples <roy@marples.name>
parents: 5007
diff changeset
1151 logdebugx("setting route socket receive buffer size to %d bytes",
28209b094c6c dhcpcd: report how large a route rocket receive buffer size we set
Roy Marples <roy@marples.name>
parents: 5007
diff changeset
1152 ctx->link_rcvbuf);
28209b094c6c dhcpcd: report how large a route rocket receive buffer size we set
Roy Marples <roy@marples.name>
parents: 5007
diff changeset
1153
4415
4eb8ce6f854c options: add link_rcvbuf variable
Roy Marples <roy@marples.name>
parents: 4394
diff changeset
1154 socklen = sizeof(ctx->link_rcvbuf);
4eb8ce6f854c options: add link_rcvbuf variable
Roy Marples <roy@marples.name>
parents: 4394
diff changeset
1155 if (setsockopt(ctx->link_fd, SOL_SOCKET,
4eb8ce6f854c options: add link_rcvbuf variable
Roy Marples <roy@marples.name>
parents: 4394
diff changeset
1156 SO_RCVBUF, &ctx->link_rcvbuf, socklen) == -1)
4eb8ce6f854c options: add link_rcvbuf variable
Roy Marples <roy@marples.name>
parents: 4394
diff changeset
1157 logerr(__func__);
4eb8ce6f854c options: add link_rcvbuf variable
Roy Marples <roy@marples.name>
parents: 4394
diff changeset
1158 }
4eb8ce6f854c options: add link_rcvbuf variable
Roy Marples <roy@marples.name>
parents: 4394
diff changeset
1159 #endif
4eb8ce6f854c options: add link_rcvbuf variable
Roy Marples <roy@marples.name>
parents: 4394
diff changeset
1160
5427
f6d641a87e0a dhcpcd: init new interfaces from route(4) overflow
Roy Marples <roy@marples.name>
parents: 5419
diff changeset
1161 static void
5431
f8d95f002758 dhcpcd: Rename function for prior now it no longer inits
Roy Marples <roy@marples.name>
parents: 5430
diff changeset
1162 dhcpcd_runprestartinterface(void *arg)
5427
f6d641a87e0a dhcpcd: init new interfaces from route(4) overflow
Roy Marples <roy@marples.name>
parents: 5419
diff changeset
1163 {
f6d641a87e0a dhcpcd: init new interfaces from route(4) overflow
Roy Marples <roy@marples.name>
parents: 5419
diff changeset
1164 struct interface *ifp = arg;
f6d641a87e0a dhcpcd: init new interfaces from route(4) overflow
Roy Marples <roy@marples.name>
parents: 5419
diff changeset
1165
f6d641a87e0a dhcpcd: init new interfaces from route(4) overflow
Roy Marples <roy@marples.name>
parents: 5419
diff changeset
1166 run_preinit(ifp);
f6d641a87e0a dhcpcd: init new interfaces from route(4) overflow
Roy Marples <roy@marples.name>
parents: 5419
diff changeset
1167 dhcpcd_prestartinterface(ifp);
f6d641a87e0a dhcpcd: init new interfaces from route(4) overflow
Roy Marples <roy@marples.name>
parents: 5419
diff changeset
1168 }
f6d641a87e0a dhcpcd: init new interfaces from route(4) overflow
Roy Marples <roy@marples.name>
parents: 5419
diff changeset
1169
4235
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1170 void
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1171 dhcpcd_linkoverflow(struct dhcpcd_ctx *ctx)
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1172 {
5007
a5d64cd4b391 dhcpcd: When route socket overflows, report how large it is.
Roy Marples <roy@marples.name>
parents: 5005
diff changeset
1173 socklen_t socklen;
a5d64cd4b391 dhcpcd: When route socket overflows, report how large it is.
Roy Marples <roy@marples.name>
parents: 5005
diff changeset
1174 int rcvbuflen;
5282
8afafcabcfa5 privsep: Drain the link socket as we can't re-open it.
Roy Marples <roy@marples.name>
parents: 5281
diff changeset
1175 char buf[2048];
8afafcabcfa5 privsep: Drain the link socket as we can't re-open it.
Roy Marples <roy@marples.name>
parents: 5281
diff changeset
1176 ssize_t rlen;
8afafcabcfa5 privsep: Drain the link socket as we can't re-open it.
Roy Marples <roy@marples.name>
parents: 5281
diff changeset
1177 size_t rcnt;
4235
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1178 struct if_head *ifaces;
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1179 struct ifaddrs *ifaddrs;
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1180 struct interface *ifp, *ifn, *ifp1;
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1181
5007
a5d64cd4b391 dhcpcd: When route socket overflows, report how large it is.
Roy Marples <roy@marples.name>
parents: 5005
diff changeset
1182 socklen = sizeof(rcvbuflen);
a5d64cd4b391 dhcpcd: When route socket overflows, report how large it is.
Roy Marples <roy@marples.name>
parents: 5005
diff changeset
1183 if (getsockopt(ctx->link_fd, SOL_SOCKET,
5559
301bcad7c710 link: Report errors obtaining recv buffer size on link overflow
Roy Marples <roy@marples.name>
parents: 5558
diff changeset
1184 SO_RCVBUF, &rcvbuflen, &socklen) == -1) {
301bcad7c710 link: Report errors obtaining recv buffer size on link overflow
Roy Marples <roy@marples.name>
parents: 5558
diff changeset
1185 logerr("%s: getsockopt", __func__);
5007
a5d64cd4b391 dhcpcd: When route socket overflows, report how large it is.
Roy Marples <roy@marples.name>
parents: 5005
diff changeset
1186 rcvbuflen = 0;
5559
301bcad7c710 link: Report errors obtaining recv buffer size on link overflow
Roy Marples <roy@marples.name>
parents: 5558
diff changeset
1187 }
5007
a5d64cd4b391 dhcpcd: When route socket overflows, report how large it is.
Roy Marples <roy@marples.name>
parents: 5005
diff changeset
1188 #ifdef __linux__
a5d64cd4b391 dhcpcd: When route socket overflows, report how large it is.
Roy Marples <roy@marples.name>
parents: 5005
diff changeset
1189 else
a5d64cd4b391 dhcpcd: When route socket overflows, report how large it is.
Roy Marples <roy@marples.name>
parents: 5005
diff changeset
1190 rcvbuflen /= 2;
a5d64cd4b391 dhcpcd: When route socket overflows, report how large it is.
Roy Marples <roy@marples.name>
parents: 5005
diff changeset
1191 #endif
a5d64cd4b391 dhcpcd: When route socket overflows, report how large it is.
Roy Marples <roy@marples.name>
parents: 5005
diff changeset
1192
a5d64cd4b391 dhcpcd: When route socket overflows, report how large it is.
Roy Marples <roy@marples.name>
parents: 5005
diff changeset
1193 logerrx("route socket overflowed (rcvbuflen %d)"
a5d64cd4b391 dhcpcd: When route socket overflows, report how large it is.
Roy Marples <roy@marples.name>
parents: 5005
diff changeset
1194 " - learning interface state", rcvbuflen);
4235
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1195
5282
8afafcabcfa5 privsep: Drain the link socket as we can't re-open it.
Roy Marples <roy@marples.name>
parents: 5281
diff changeset
1196 /* Drain the socket.
8afafcabcfa5 privsep: Drain the link socket as we can't re-open it.
Roy Marples <roy@marples.name>
parents: 5281
diff changeset
1197 * We cannot open a new one due to privsep. */
8afafcabcfa5 privsep: Drain the link socket as we can't re-open it.
Roy Marples <roy@marples.name>
parents: 5281
diff changeset
1198 rcnt = 0;
8afafcabcfa5 privsep: Drain the link socket as we can't re-open it.
Roy Marples <roy@marples.name>
parents: 5281
diff changeset
1199 do {
8afafcabcfa5 privsep: Drain the link socket as we can't re-open it.
Roy Marples <roy@marples.name>
parents: 5281
diff changeset
1200 rlen = read(ctx->link_fd, buf, sizeof(buf));
5284
2b5f56e079b0 route: improve overflow logging
Roy Marples <roy@marples.name>
parents: 5282
diff changeset
1201 if (++rcnt % 1000 == 0)
5282
8afafcabcfa5 privsep: Drain the link socket as we can't re-open it.
Roy Marples <roy@marples.name>
parents: 5281
diff changeset
1202 logwarnx("drained %zu messages", rcnt);
8afafcabcfa5 privsep: Drain the link socket as we can't re-open it.
Roy Marples <roy@marples.name>
parents: 5281
diff changeset
1203 } while (rlen != -1 || errno == ENOBUFS || errno == ENOMEM);
5284
2b5f56e079b0 route: improve overflow logging
Roy Marples <roy@marples.name>
parents: 5282
diff changeset
1204 if (rcnt % 1000 != 0)
5282
8afafcabcfa5 privsep: Drain the link socket as we can't re-open it.
Roy Marples <roy@marples.name>
parents: 5281
diff changeset
1205 logwarnx("drained %zu messages", rcnt);
4235
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1206
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1207 /* Work out the current interfaces. */
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1208 ifaces = if_discover(ctx, &ifaddrs, ctx->ifc, ctx->ifv);
4570
6baf24a8cc49 dhcpcd: Don't leak memory when routing socket overflows
Roy Marples <roy@marples.name>
parents: 4549
diff changeset
1209 if (ifaces == NULL) {
6baf24a8cc49 dhcpcd: Don't leak memory when routing socket overflows
Roy Marples <roy@marples.name>
parents: 4549
diff changeset
1210 logerr(__func__);
6baf24a8cc49 dhcpcd: Don't leak memory when routing socket overflows
Roy Marples <roy@marples.name>
parents: 4549
diff changeset
1211 return;
6baf24a8cc49 dhcpcd: Don't leak memory when routing socket overflows
Roy Marples <roy@marples.name>
parents: 4549
diff changeset
1212 }
4235
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1213
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1214 /* Punt departed interfaces */
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1215 TAILQ_FOREACH_SAFE(ifp, ctx->ifaces, next, ifn) {
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1216 if (if_find(ifaces, ifp->name) != NULL)
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1217 continue;
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1218 dhcpcd_handleinterface(ctx, -1, ifp->name);
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1219 }
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1220
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1221 /* Add new interfaces */
4570
6baf24a8cc49 dhcpcd: Don't leak memory when routing socket overflows
Roy Marples <roy@marples.name>
parents: 4549
diff changeset
1222 while ((ifp = TAILQ_FIRST(ifaces)) != NULL ) {
6baf24a8cc49 dhcpcd: Don't leak memory when routing socket overflows
Roy Marples <roy@marples.name>
parents: 4549
diff changeset
1223 TAILQ_REMOVE(ifaces, ifp, next);
4235
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1224 ifp1 = if_find(ctx->ifaces, ifp->name);
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1225 if (ifp1 != NULL) {
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1226 /* If the interface already exists,
5486
8e2b8ce8c972 BSD: struct if_data->ifi_link_state is the single source of truth
Roy Marples <roy@marples.name>
parents: 5484
diff changeset
1227 * check carrier state.
8e2b8ce8c972 BSD: struct if_data->ifi_link_state is the single source of truth
Roy Marples <roy@marples.name>
parents: 5484
diff changeset
1228 * dhcpcd_checkcarrier will free ifp. */
4235
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1229 eloop_timeout_add_sec(ctx->eloop, 0,
5486
8e2b8ce8c972 BSD: struct if_data->ifi_link_state is the single source of truth
Roy Marples <roy@marples.name>
parents: 5484
diff changeset
1230 dhcpcd_checkcarrier, ifp);
4235
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1231 continue;
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1232 }
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1233 TAILQ_INSERT_TAIL(ctx->ifaces, ifp, next);
5430
c2b796cf7e94 dhcpcd: Adjust prior to ensure options exist for active interfaces before timeouts
Roy Marples <roy@marples.name>
parents: 5427
diff changeset
1234 if (ifp->active) {
c2b796cf7e94 dhcpcd: Adjust prior to ensure options exist for active interfaces before timeouts
Roy Marples <roy@marples.name>
parents: 5427
diff changeset
1235 dhcpcd_initstate(ifp, 0);
4235
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1236 eloop_timeout_add_sec(ctx->eloop, 0,
5431
f8d95f002758 dhcpcd: Rename function for prior now it no longer inits
Roy Marples <roy@marples.name>
parents: 5430
diff changeset
1237 dhcpcd_runprestartinterface, ifp);
5430
c2b796cf7e94 dhcpcd: Adjust prior to ensure options exist for active interfaces before timeouts
Roy Marples <roy@marples.name>
parents: 5427
diff changeset
1238 }
4235
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1239 }
4570
6baf24a8cc49 dhcpcd: Don't leak memory when routing socket overflows
Roy Marples <roy@marples.name>
parents: 4549
diff changeset
1240 free(ifaces);
4235
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1241
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1242 /* Update address state. */
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1243 if_markaddrsstale(ctx->ifaces);
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1244 if_learnaddrs(ctx, ctx->ifaces, &ifaddrs);
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1245 if_deletestaleaddrs(ctx->ifaces);
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1246 }
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1247
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1248 void
5168
1f5dc6102f9b if: support changing hardware address type on Linux
Roy Marples <roy@marples.name>
parents: 5148
diff changeset
1249 dhcpcd_handlehwaddr(struct interface *ifp,
1f5dc6102f9b if: support changing hardware address type on Linux
Roy Marples <roy@marples.name>
parents: 5148
diff changeset
1250 uint16_t hwtype, const void *hwaddr, uint8_t hwlen)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1251 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1252 char buf[sizeof(ifp->hwaddr) * 3];
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1253
5168
1f5dc6102f9b if: support changing hardware address type on Linux
Roy Marples <roy@marples.name>
parents: 5148
diff changeset
1254 if (hwaddr == NULL || !if_valid_hwaddr(hwaddr, hwlen))
4076
9433864aa014 Hardware Address validation
Roy Marples <roy@marples.name>
parents: 4075
diff changeset
1255 hwlen = 0;
9433864aa014 Hardware Address validation
Roy Marples <roy@marples.name>
parents: 4075
diff changeset
1256
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1257 if (hwlen > sizeof(ifp->hwaddr)) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1258 errno = ENOBUFS;
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 4008
diff changeset
1259 logerr("%s: %s", __func__, ifp->name);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1260 return;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1261 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1262
5168
1f5dc6102f9b if: support changing hardware address type on Linux
Roy Marples <roy@marples.name>
parents: 5148
diff changeset
1263 if (ifp->hwtype != hwtype) {
5558
e27177daaf0a link: Only report hardware address changes for active interfaces
Roy Marples <roy@marples.name>
parents: 5557
diff changeset
1264 if (ifp->active)
e27177daaf0a link: Only report hardware address changes for active interfaces
Roy Marples <roy@marples.name>
parents: 5557
diff changeset
1265 loginfox("%s: hardware address type changed"
e27177daaf0a link: Only report hardware address changes for active interfaces
Roy Marples <roy@marples.name>
parents: 5557
diff changeset
1266 " from %d to %d", ifp->name, ifp->hwtype, hwtype);
5168
1f5dc6102f9b if: support changing hardware address type on Linux
Roy Marples <roy@marples.name>
parents: 5148
diff changeset
1267 ifp->hwtype = hwtype;
1f5dc6102f9b if: support changing hardware address type on Linux
Roy Marples <roy@marples.name>
parents: 5148
diff changeset
1268 }
1f5dc6102f9b if: support changing hardware address type on Linux
Roy Marples <roy@marples.name>
parents: 5148
diff changeset
1269
1f5dc6102f9b if: support changing hardware address type on Linux
Roy Marples <roy@marples.name>
parents: 5148
diff changeset
1270 if (ifp->hwlen == hwlen &&
1f5dc6102f9b if: support changing hardware address type on Linux
Roy Marples <roy@marples.name>
parents: 5148
diff changeset
1271 (hwlen == 0 || memcmp(ifp->hwaddr, hwaddr, hwlen) == 0))
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1272 return;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1273
5558
e27177daaf0a link: Only report hardware address changes for active interfaces
Roy Marples <roy@marples.name>
parents: 5557
diff changeset
1274 if (ifp->active) {
e27177daaf0a link: Only report hardware address changes for active interfaces
Roy Marples <roy@marples.name>
parents: 5557
diff changeset
1275 loginfox("%s: old hardware address: %s", ifp->name,
e27177daaf0a link: Only report hardware address changes for active interfaces
Roy Marples <roy@marples.name>
parents: 5557
diff changeset
1276 hwaddr_ntoa(ifp->hwaddr, ifp->hwlen, buf, sizeof(buf)));
e27177daaf0a link: Only report hardware address changes for active interfaces
Roy Marples <roy@marples.name>
parents: 5557
diff changeset
1277 loginfox("%s: new hardware address: %s", ifp->name,
e27177daaf0a link: Only report hardware address changes for active interfaces
Roy Marples <roy@marples.name>
parents: 5557
diff changeset
1278 hwaddr_ntoa(hwaddr, hwlen, buf, sizeof(buf)));
e27177daaf0a link: Only report hardware address changes for active interfaces
Roy Marples <roy@marples.name>
parents: 5557
diff changeset
1279 }
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1280 ifp->hwlen = hwlen;
5280
a986083da0ba Fix some clang analyzer issues
Roy Marples <roy@marples.name>
parents: 5269
diff changeset
1281 if (hwaddr != NULL)
a986083da0ba Fix some clang analyzer issues
Roy Marples <roy@marples.name>
parents: 5269
diff changeset
1282 memcpy(ifp->hwaddr, hwaddr, hwlen);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1283 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1284
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1285 static void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1286 if_reboot(struct interface *ifp, int argc, char **argv)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1287 {
4582
1accf1291b4b Fix build without INET.
Roy Marples <roy@marples.name>
parents: 4571
diff changeset
1288 #ifdef INET
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1289 unsigned long long oldopts;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1290
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1291 oldopts = ifp->options->options;
4582
1accf1291b4b Fix build without INET.
Roy Marples <roy@marples.name>
parents: 4571
diff changeset
1292 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1293 script_runreason(ifp, "RECONFIGURE");
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1294 dhcpcd_initstate1(ifp, argc, argv, 0);
4347
fb677abacc16 DHCP: Remove #defines for functions when INET is disabled
Roy Marples <roy@marples.name>
parents: 4346
diff changeset
1295 #ifdef INET
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1296 dhcp_reboot_newopts(ifp, oldopts);
4347
fb677abacc16 DHCP: Remove #defines for functions when INET is disabled
Roy Marples <roy@marples.name>
parents: 4346
diff changeset
1297 #endif
4349
f87c2ed9ff46 DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents: 4348
diff changeset
1298 #ifdef DHCP6
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1299 dhcp6_reboot(ifp);
4349
f87c2ed9ff46 DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents: 4348
diff changeset
1300 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1301 dhcpcd_prestartinterface(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1302 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1303
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1304 static void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1305 reload_config(struct dhcpcd_ctx *ctx)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1306 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1307 struct if_options *ifo;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1308
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1309 free_globals(ctx);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1310 if ((ifo = read_config(ctx, NULL, NULL, NULL)) == NULL)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1311 return;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1312 add_options(ctx, NULL, ifo, ctx->argc, ctx->argv);
5373
086c01fecfca dhcpcd: preserve the STARTED option when reloading options
Roy Marples <roy@marples.name>
parents: 5365
diff changeset
1313 /* We need to preserve these options. */
086c01fecfca dhcpcd: preserve the STARTED option when reloading options
Roy Marples <roy@marples.name>
parents: 5365
diff changeset
1314 if (ctx->options & DHCPCD_STARTED)
086c01fecfca dhcpcd: preserve the STARTED option when reloading options
Roy Marples <roy@marples.name>
parents: 5365
diff changeset
1315 ifo->options |= DHCPCD_STARTED;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1316 if (ctx->options & DHCPCD_MASTER)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1317 ifo->options |= DHCPCD_MASTER;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1318 if (ctx->options & DHCPCD_DAEMONISED)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1319 ifo->options |= DHCPCD_DAEMONISED;
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4836
diff changeset
1320 if (ctx->options & DHCPCD_PRIVSEP)
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4836
diff changeset
1321 ifo->options |= DHCPCD_PRIVSEP;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1322 ctx->options = ifo->options;
4249
c30233f8cca3 routes: allow a head clear with a context
Roy Marples <roy@marples.name>
parents: 4246
diff changeset
1323 free_options(ctx, ifo);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1324 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1325
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1326 static void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1327 reconf_reboot(struct dhcpcd_ctx *ctx, int action, int argc, char **argv, int oi)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1328 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1329 int i;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1330 struct interface *ifp;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1331
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1332 TAILQ_FOREACH(ifp, ctx->ifaces, next) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1333 for (i = oi; i < argc; i++) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1334 if (strcmp(ifp->name, argv[i]) == 0)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1335 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1336 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1337 if (oi != argc && i == argc)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1338 continue;
4075
5dca392a6e39 Only reboot activated user interfaces.
Roy Marples <roy@marples.name>
parents: 4072
diff changeset
1339 if (ifp->active == IF_ACTIVE_USER) {
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1340 if (action)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1341 if_reboot(ifp, argc, argv);
4348
437e53e4ea26 IP4: Remove #defines for functions when INET is disabled
Roy Marples <roy@marples.name>
parents: 4347
diff changeset
1342 #ifdef INET
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1343 else
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1344 ipv4_applyaddr(ifp);
4348
437e53e4ea26 IP4: Remove #defines for functions when INET is disabled
Roy Marples <roy@marples.name>
parents: 4347
diff changeset
1345 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1346 } else if (i != argc) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1347 ifp->active = IF_ACTIVE_USER;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1348 dhcpcd_initstate1(ifp, argc, argv, 0);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1349 run_preinit(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1350 dhcpcd_prestartinterface(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1351 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1352 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1353 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1354
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1355 static void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1356 stop_all_interfaces(struct dhcpcd_ctx *ctx, unsigned long long opts)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1357 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1358 struct interface *ifp;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1359
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1360 ctx->options |= DHCPCD_EXITING;
5296
3fd9a92dd852 ifaces could be NULL here
Roy Marples <roy@marples.name>
parents: 5292
diff changeset
1361 if (ctx->ifaces == NULL)
3fd9a92dd852 ifaces could be NULL here
Roy Marples <roy@marples.name>
parents: 5292
diff changeset
1362 return;
3fd9a92dd852 ifaces could be NULL here
Roy Marples <roy@marples.name>
parents: 5292
diff changeset
1363
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1364 /* Drop the last interface first */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1365 TAILQ_FOREACH_REVERSE(ifp, ctx->ifaces, if_head, next) {
5266
9ea5c678d8a6 dhcpcd: Fix releasing addresses
Roy Marples <roy@marples.name>
parents: 5262
diff changeset
1366 if (!ifp->active)
9ea5c678d8a6 dhcpcd: Fix releasing addresses
Roy Marples <roy@marples.name>
parents: 5262
diff changeset
1367 continue;
9ea5c678d8a6 dhcpcd: Fix releasing addresses
Roy Marples <roy@marples.name>
parents: 5262
diff changeset
1368 ifp->options->options |= opts;
9ea5c678d8a6 dhcpcd: Fix releasing addresses
Roy Marples <roy@marples.name>
parents: 5262
diff changeset
1369 if (ifp->options->options & DHCPCD_RELEASE)
9ea5c678d8a6 dhcpcd: Fix releasing addresses
Roy Marples <roy@marples.name>
parents: 5262
diff changeset
1370 ifp->options->options &= ~DHCPCD_PERSISTENT;
9ea5c678d8a6 dhcpcd: Fix releasing addresses
Roy Marples <roy@marples.name>
parents: 5262
diff changeset
1371 ifp->options->options |= DHCPCD_EXITING;
5501
5b2272a0f3c3 privsep: Only log chrooting from the launcher process
Roy Marples <roy@marples.name>
parents: 5499
diff changeset
1372 stop_interface(ifp, NULL);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1373 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1374 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1375
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1376 static void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1377 dhcpcd_ifrenew(struct interface *ifp)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1378 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1379
3976
518eef876db3 dhcpcd: fix crash forcing lease renewals on inactive interfaces.
Roy Marples <roy@marples.name>
parents: 3965
diff changeset
1380 if (!ifp->active)
518eef876db3 dhcpcd: fix crash forcing lease renewals on inactive interfaces.
Roy Marples <roy@marples.name>
parents: 3965
diff changeset
1381 return;
518eef876db3 dhcpcd: fix crash forcing lease renewals on inactive interfaces.
Roy Marples <roy@marples.name>
parents: 3965
diff changeset
1382
5499
6a2da5651841 dhcpcd: Simplify the link handling even more
Roy Marples <roy@marples.name>
parents: 5497
diff changeset
1383 if (ifp->options->options & DHCPCD_LINK && !if_is_link_up(ifp))
3976
518eef876db3 dhcpcd: fix crash forcing lease renewals on inactive interfaces.
Roy Marples <roy@marples.name>
parents: 3965
diff changeset
1384 return;
518eef876db3 dhcpcd: fix crash forcing lease renewals on inactive interfaces.
Roy Marples <roy@marples.name>
parents: 3965
diff changeset
1385
4347
fb677abacc16 DHCP: Remove #defines for functions when INET is disabled
Roy Marples <roy@marples.name>
parents: 4346
diff changeset
1386 #ifdef INET
3976
518eef876db3 dhcpcd: fix crash forcing lease renewals on inactive interfaces.
Roy Marples <roy@marples.name>
parents: 3965
diff changeset
1387 dhcp_renew(ifp);
4347
fb677abacc16 DHCP: Remove #defines for functions when INET is disabled
Roy Marples <roy@marples.name>
parents: 4346
diff changeset
1388 #endif
4351
b7a9f2b43d50 IP6ND: Remove #defines for functions when INET6 is disabled
Roy Marples <roy@marples.name>
parents: 4349
diff changeset
1389 #ifdef INET6
3976
518eef876db3 dhcpcd: fix crash forcing lease renewals on inactive interfaces.
Roy Marples <roy@marples.name>
parents: 3965
diff changeset
1390 #define DHCPCD_RARENEW (DHCPCD_IPV6 | DHCPCD_IPV6RS)
518eef876db3 dhcpcd: fix crash forcing lease renewals on inactive interfaces.
Roy Marples <roy@marples.name>
parents: 3965
diff changeset
1391 if ((ifp->options->options & DHCPCD_RARENEW) == DHCPCD_RARENEW)
518eef876db3 dhcpcd: fix crash forcing lease renewals on inactive interfaces.
Roy Marples <roy@marples.name>
parents: 3965
diff changeset
1392 ipv6nd_startrs(ifp);
4351
b7a9f2b43d50 IP6ND: Remove #defines for functions when INET6 is disabled
Roy Marples <roy@marples.name>
parents: 4349
diff changeset
1393 #endif
4349
f87c2ed9ff46 DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents: 4348
diff changeset
1394 #ifdef DHCP6
3976
518eef876db3 dhcpcd: fix crash forcing lease renewals on inactive interfaces.
Roy Marples <roy@marples.name>
parents: 3965
diff changeset
1395 dhcp6_renew(ifp);
4349
f87c2ed9ff46 DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents: 4348
diff changeset
1396 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1397 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1398
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1399 static void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1400 dhcpcd_renew(struct dhcpcd_ctx *ctx)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1401 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1402 struct interface *ifp;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1403
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1404 TAILQ_FOREACH(ifp, ctx->ifaces, next) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1405 dhcpcd_ifrenew(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1406 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1407 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1408
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1409 #ifdef USE_SIGNALS
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1410 #define sigmsg "received %s, %s"
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1411 static void
4850
c5a24b79f6b5 dhcpcd: signal_cb -> dhcpcd_signal_cb
Roy Marples <roy@marples.name>
parents: 4841
diff changeset
1412 dhcpcd_signal_cb(int sig, void *arg)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1413 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1414 struct dhcpcd_ctx *ctx = arg;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1415 unsigned long long opts;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1416 int exit_code;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1417
5328
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1418 if (ctx->options & DHCPCD_DUMPLEASE) {
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1419 eloop_exit(ctx->eloop, EXIT_FAILURE);
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1420 return;
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1421 }
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1422
5304
04f26d9f1885 privsep: Don't wait for the process to finish when stopping it
Roy Marples <roy@marples.name>
parents: 5301
diff changeset
1423 if (sig != SIGCHLD && ctx->options & DHCPCD_FORKED) {
5467
49e119831377 privsep: Send signal from launcher to master over the socket
Roy Marples <roy@marples.name>
parents: 5466
diff changeset
1424 if (sig != SIGHUP &&
49e119831377 privsep: Send signal from launcher to master over the socket
Roy Marples <roy@marples.name>
parents: 5466
diff changeset
1425 write(ctx->fork_fd, &sig, sizeof(sig)) == -1)
49e119831377 privsep: Send signal from launcher to master over the socket
Roy Marples <roy@marples.name>
parents: 5466
diff changeset
1426 logerr("%s: write", __func__);
4856
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
1427 return;
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
1428 }
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
1429
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1430 opts = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1431 exit_code = EXIT_FAILURE;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1432 switch (sig) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1433 case SIGINT:
4024
0984f93d896e To be consitent, do the same to loginfo as we just did for logdebug.
Roy Marples <roy@marples.name>
parents: 4023
diff changeset
1434 loginfox(sigmsg, "SIGINT", "stopping");
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1435 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1436 case SIGTERM:
4024
0984f93d896e To be consitent, do the same to loginfo as we just did for logdebug.
Roy Marples <roy@marples.name>
parents: 4023
diff changeset
1437 loginfox(sigmsg, "SIGTERM", "stopping");
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1438 exit_code = EXIT_SUCCESS;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1439 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1440 case SIGALRM:
4024
0984f93d896e To be consitent, do the same to loginfo as we just did for logdebug.
Roy Marples <roy@marples.name>
parents: 4023
diff changeset
1441 loginfox(sigmsg, "SIGALRM", "releasing");
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1442 opts |= DHCPCD_RELEASE;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1443 exit_code = EXIT_SUCCESS;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1444 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1445 case SIGHUP:
4024
0984f93d896e To be consitent, do the same to loginfo as we just did for logdebug.
Roy Marples <roy@marples.name>
parents: 4023
diff changeset
1446 loginfox(sigmsg, "SIGHUP", "rebinding");
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1447 reload_config(ctx);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1448 /* Preserve any options passed on the commandline
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1449 * when we were started. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1450 reconf_reboot(ctx, 1, ctx->argc, ctx->argv,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1451 ctx->argc - ctx->ifc);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1452 return;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1453 case SIGUSR1:
4024
0984f93d896e To be consitent, do the same to loginfo as we just did for logdebug.
Roy Marples <roy@marples.name>
parents: 4023
diff changeset
1454 loginfox(sigmsg, "SIGUSR1", "renewing");
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1455 dhcpcd_renew(ctx);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1456 return;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1457 case SIGUSR2:
4024
0984f93d896e To be consitent, do the same to loginfo as we just did for logdebug.
Roy Marples <roy@marples.name>
parents: 4023
diff changeset
1458 loginfox(sigmsg, "SIGUSR2", "reopening log");
5530
226b850d158d Fix compile without various defines
Roy Marples <roy@marples.name>
parents: 5527
diff changeset
1459 #ifdef PRIVSEP
5526
b1a3d9055662 privsep: Allow logfile reopening in a chroot
Roy Marples <roy@marples.name>
parents: 5525
diff changeset
1460 if (IN_PRIVSEP(ctx)) {
b1a3d9055662 privsep: Allow logfile reopening in a chroot
Roy Marples <roy@marples.name>
parents: 5525
diff changeset
1461 if (ps_root_logreopen(ctx) == -1)
b1a3d9055662 privsep: Allow logfile reopening in a chroot
Roy Marples <roy@marples.name>
parents: 5525
diff changeset
1462 logerr("ps_root_logreopen");
5530
226b850d158d Fix compile without various defines
Roy Marples <roy@marples.name>
parents: 5527
diff changeset
1463 return;
5526
b1a3d9055662 privsep: Allow logfile reopening in a chroot
Roy Marples <roy@marples.name>
parents: 5525
diff changeset
1464 }
5530
226b850d158d Fix compile without various defines
Roy Marples <roy@marples.name>
parents: 5527
diff changeset
1465 #endif
226b850d158d Fix compile without various defines
Roy Marples <roy@marples.name>
parents: 5527
diff changeset
1466 if (logopen(ctx->logfile) == -1)
226b850d158d Fix compile without various defines
Roy Marples <roy@marples.name>
parents: 5527
diff changeset
1467 logerr("logopen");
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1468 return;
5304
04f26d9f1885 privsep: Don't wait for the process to finish when stopping it
Roy Marples <roy@marples.name>
parents: 5301
diff changeset
1469 case SIGCHLD:
04f26d9f1885 privsep: Don't wait for the process to finish when stopping it
Roy Marples <roy@marples.name>
parents: 5301
diff changeset
1470 while (waitpid(-1, NULL, WNOHANG) > 0)
04f26d9f1885 privsep: Don't wait for the process to finish when stopping it
Roy Marples <roy@marples.name>
parents: 5301
diff changeset
1471 ;
04f26d9f1885 privsep: Don't wait for the process to finish when stopping it
Roy Marples <roy@marples.name>
parents: 5301
diff changeset
1472 return;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1473 default:
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 4008
diff changeset
1474 logerrx("received signal %d but don't know what to do with it",
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1475 sig);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1476 return;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1477 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1478
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1479 if (!(ctx->options & DHCPCD_TEST))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1480 stop_all_interfaces(ctx, opts);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1481 eloop_exit(ctx->eloop, exit_code);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1482 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1483 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1484
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1485 int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1486 dhcpcd_handleargs(struct dhcpcd_ctx *ctx, struct fd_list *fd,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1487 int argc, char **argv)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1488 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1489 struct interface *ifp;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1490 unsigned long long opts;
5092
995a49ee3418 dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents: 5089
diff changeset
1491 int opt, oi, do_reboot, do_renew, af = AF_UNSPEC;
5328
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1492 size_t len, l, nifaces;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1493 char *tmp, *p;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1494
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1495 /* Special commands for our control socket
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1496 * as the other end should be blocking until it gets the
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1497 * expected reply we should be safely able just to change the
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1498 * write callback on the fd */
5328
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1499 /* Make any change here in privsep-control.c as well. */
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1500 if (strcmp(*argv, "--version") == 0) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1501 return control_queue(fd, UNCONST(VERSION),
5328
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1502 strlen(VERSION) + 1);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1503 } else if (strcmp(*argv, "--getconfigfile") == 0) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1504 return control_queue(fd, UNCONST(fd->ctx->cffile),
5328
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1505 strlen(fd->ctx->cffile) + 1);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1506 } else if (strcmp(*argv, "--getinterfaces") == 0) {
5328
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1507 optind = argc = 0;
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1508 goto dumplease;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1509 } else if (strcmp(*argv, "--listen") == 0) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1510 fd->flags |= FD_LISTEN;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1511 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1512 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1513
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1514 /* Log the command */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1515 len = 1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1516 for (opt = 0; opt < argc; opt++)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1517 len += strlen(argv[opt]) + 1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1518 tmp = malloc(len);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1519 if (tmp == NULL)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1520 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1521 p = tmp;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1522 for (opt = 0; opt < argc; opt++) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1523 l = strlen(argv[opt]);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1524 strlcpy(p, argv[opt], len);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1525 len -= l + 1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1526 p += l;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1527 *p++ = ' ';
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1528 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1529 *--p = '\0';
4024
0984f93d896e To be consitent, do the same to loginfo as we just did for logdebug.
Roy Marples <roy@marples.name>
parents: 4023
diff changeset
1530 loginfox("control command: %s", tmp);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1531 free(tmp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1532
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1533 optind = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1534 oi = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1535 opts = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1536 do_reboot = do_renew = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1537 while ((opt = getopt_long(argc, argv, IF_OPTS, cf_options, &oi)) != -1)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1538 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1539 switch (opt) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1540 case 'g':
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1541 /* Assumed if below not set */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1542 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1543 case 'k':
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1544 opts |= DHCPCD_RELEASE;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1545 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1546 case 'n':
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1547 do_reboot = 1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1548 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1549 case 'p':
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1550 opts |= DHCPCD_PERSISTENT;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1551 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1552 case 'x':
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1553 opts |= DHCPCD_EXITING;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1554 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1555 case 'N':
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1556 do_renew = 1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1557 break;
5092
995a49ee3418 dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents: 5089
diff changeset
1558 case 'U':
995a49ee3418 dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents: 5089
diff changeset
1559 opts |= DHCPCD_DUMPLEASE;
995a49ee3418 dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents: 5089
diff changeset
1560 break;
995a49ee3418 dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents: 5089
diff changeset
1561 case '4':
995a49ee3418 dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents: 5089
diff changeset
1562 af = AF_INET;
995a49ee3418 dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents: 5089
diff changeset
1563 break;
995a49ee3418 dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents: 5089
diff changeset
1564 case '6':
995a49ee3418 dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents: 5089
diff changeset
1565 af = AF_INET6;
995a49ee3418 dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents: 5089
diff changeset
1566 break;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1567 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1568 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1569
5092
995a49ee3418 dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents: 5089
diff changeset
1570 if (opts & DHCPCD_DUMPLEASE) {
995a49ee3418 dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents: 5089
diff changeset
1571 ctx->options |= DHCPCD_DUMPLEASE;
5328
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1572 dumplease:
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1573 nifaces = 0;
5121
200e3a305ec5 dhcpcd: dump all variables and optionally all interfaces
Roy Marples <roy@marples.name>
parents: 5112
diff changeset
1574 TAILQ_FOREACH(ifp, ctx->ifaces, next) {
5092
995a49ee3418 dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents: 5089
diff changeset
1575 if (!ifp->active)
995a49ee3418 dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents: 5089
diff changeset
1576 continue;
5121
200e3a305ec5 dhcpcd: dump all variables and optionally all interfaces
Roy Marples <roy@marples.name>
parents: 5112
diff changeset
1577 for (oi = optind; oi < argc; oi++) {
200e3a305ec5 dhcpcd: dump all variables and optionally all interfaces
Roy Marples <roy@marples.name>
parents: 5112
diff changeset
1578 if (strcmp(ifp->name, argv[oi]) == 0)
200e3a305ec5 dhcpcd: dump all variables and optionally all interfaces
Roy Marples <roy@marples.name>
parents: 5112
diff changeset
1579 break;
200e3a305ec5 dhcpcd: dump all variables and optionally all interfaces
Roy Marples <roy@marples.name>
parents: 5112
diff changeset
1580 }
200e3a305ec5 dhcpcd: dump all variables and optionally all interfaces
Roy Marples <roy@marples.name>
parents: 5112
diff changeset
1581 if (optind == argc || oi < argc) {
200e3a305ec5 dhcpcd: dump all variables and optionally all interfaces
Roy Marples <roy@marples.name>
parents: 5112
diff changeset
1582 opt = send_interface(NULL, ifp, af);
200e3a305ec5 dhcpcd: dump all variables and optionally all interfaces
Roy Marples <roy@marples.name>
parents: 5112
diff changeset
1583 if (opt == -1)
200e3a305ec5 dhcpcd: dump all variables and optionally all interfaces
Roy Marples <roy@marples.name>
parents: 5112
diff changeset
1584 goto dumperr;
5092
995a49ee3418 dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents: 5089
diff changeset
1585 nifaces += (size_t)opt;
5121
200e3a305ec5 dhcpcd: dump all variables and optionally all interfaces
Roy Marples <roy@marples.name>
parents: 5112
diff changeset
1586 }
5092
995a49ee3418 dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents: 5089
diff changeset
1587 }
995a49ee3418 dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents: 5089
diff changeset
1588 if (write(fd->fd, &nifaces, sizeof(nifaces)) != sizeof(nifaces))
5121
200e3a305ec5 dhcpcd: dump all variables and optionally all interfaces
Roy Marples <roy@marples.name>
parents: 5112
diff changeset
1589 goto dumperr;
200e3a305ec5 dhcpcd: dump all variables and optionally all interfaces
Roy Marples <roy@marples.name>
parents: 5112
diff changeset
1590 TAILQ_FOREACH(ifp, ctx->ifaces, next) {
5092
995a49ee3418 dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents: 5089
diff changeset
1591 if (!ifp->active)
995a49ee3418 dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents: 5089
diff changeset
1592 continue;
5121
200e3a305ec5 dhcpcd: dump all variables and optionally all interfaces
Roy Marples <roy@marples.name>
parents: 5112
diff changeset
1593 for (oi = optind; oi < argc; oi++) {
200e3a305ec5 dhcpcd: dump all variables and optionally all interfaces
Roy Marples <roy@marples.name>
parents: 5112
diff changeset
1594 if (strcmp(ifp->name, argv[oi]) == 0)
200e3a305ec5 dhcpcd: dump all variables and optionally all interfaces
Roy Marples <roy@marples.name>
parents: 5112
diff changeset
1595 break;
200e3a305ec5 dhcpcd: dump all variables and optionally all interfaces
Roy Marples <roy@marples.name>
parents: 5112
diff changeset
1596 }
200e3a305ec5 dhcpcd: dump all variables and optionally all interfaces
Roy Marples <roy@marples.name>
parents: 5112
diff changeset
1597 if (optind == argc || oi < argc) {
200e3a305ec5 dhcpcd: dump all variables and optionally all interfaces
Roy Marples <roy@marples.name>
parents: 5112
diff changeset
1598 if (send_interface(fd, ifp, af) == -1)
200e3a305ec5 dhcpcd: dump all variables and optionally all interfaces
Roy Marples <roy@marples.name>
parents: 5112
diff changeset
1599 goto dumperr;
200e3a305ec5 dhcpcd: dump all variables and optionally all interfaces
Roy Marples <roy@marples.name>
parents: 5112
diff changeset
1600 }
5092
995a49ee3418 dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents: 5089
diff changeset
1601 }
995a49ee3418 dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents: 5089
diff changeset
1602 ctx->options &= ~DHCPCD_DUMPLEASE;
995a49ee3418 dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents: 5089
diff changeset
1603 return 0;
5121
200e3a305ec5 dhcpcd: dump all variables and optionally all interfaces
Roy Marples <roy@marples.name>
parents: 5112
diff changeset
1604 dumperr:
200e3a305ec5 dhcpcd: dump all variables and optionally all interfaces
Roy Marples <roy@marples.name>
parents: 5112
diff changeset
1605 ctx->options &= ~DHCPCD_DUMPLEASE;
200e3a305ec5 dhcpcd: dump all variables and optionally all interfaces
Roy Marples <roy@marples.name>
parents: 5112
diff changeset
1606 return -1;
5092
995a49ee3418 dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents: 5089
diff changeset
1607 }
995a49ee3418 dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents: 5089
diff changeset
1608
995a49ee3418 dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents: 5089
diff changeset
1609 /* Only privileged users can control dhcpcd via the socket. */
995a49ee3418 dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents: 5089
diff changeset
1610 if (fd->flags & FD_UNPRIV) {
995a49ee3418 dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents: 5089
diff changeset
1611 errno = EPERM;
995a49ee3418 dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents: 5089
diff changeset
1612 return -1;
995a49ee3418 dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents: 5089
diff changeset
1613 }
995a49ee3418 dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents: 5089
diff changeset
1614
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1615 if (opts & (DHCPCD_EXITING | DHCPCD_RELEASE)) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1616 if (optind == argc) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1617 stop_all_interfaces(ctx, opts);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1618 eloop_exit(ctx->eloop, EXIT_SUCCESS);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1619 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1620 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1621 for (oi = optind; oi < argc; oi++) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1622 if ((ifp = if_find(ctx->ifaces, argv[oi])) == NULL)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1623 continue;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1624 if (!ifp->active)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1625 continue;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1626 ifp->options->options |= opts;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1627 if (opts & DHCPCD_RELEASE)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1628 ifp->options->options &= ~DHCPCD_PERSISTENT;
5501
5b2272a0f3c3 privsep: Only log chrooting from the launcher process
Roy Marples <roy@marples.name>
parents: 5499
diff changeset
1629 stop_interface(ifp, NULL);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1630 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1631 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1632 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1633
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1634 if (do_renew) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1635 if (optind == argc) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1636 dhcpcd_renew(ctx);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1637 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1638 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1639 for (oi = optind; oi < argc; oi++) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1640 if ((ifp = if_find(ctx->ifaces, argv[oi])) == NULL)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1641 continue;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1642 dhcpcd_ifrenew(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1643 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1644 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1645 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1646
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1647 reload_config(ctx);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1648 /* XXX: Respect initial commandline options? */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1649 reconf_reboot(ctx, do_reboot, argc, argv, optind - 1);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1650 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1651 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1652
5328
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1653 static void dhcpcd_readdump1(void *);
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1654
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1655 static void
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1656 dhcpcd_readdump2(void *arg)
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1657 {
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1658 struct dhcpcd_ctx *ctx = arg;
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1659 ssize_t len;
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1660 int exit_code = EXIT_FAILURE;
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1661
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1662 len = read(ctx->control_fd, ctx->ctl_buf + ctx->ctl_bufpos,
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1663 ctx->ctl_buflen - ctx->ctl_bufpos);
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1664 if (len == -1) {
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1665 logerr(__func__);
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1666 goto finished;
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1667 } else if (len == 0)
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1668 goto finished;
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1669 if ((size_t)len + ctx->ctl_bufpos != ctx->ctl_buflen) {
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1670 ctx->ctl_bufpos += (size_t)len;
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1671 return;
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1672 }
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1673
5348
5d4210eb0187 dhcpcd: Ensure dump is terminated
Roy Marples <roy@marples.name>
parents: 5345
diff changeset
1674 if (ctx->ctl_buf[ctx->ctl_buflen - 1] != '\0') /* unlikely */
5d4210eb0187 dhcpcd: Ensure dump is terminated
Roy Marples <roy@marples.name>
parents: 5345
diff changeset
1675 ctx->ctl_buf[ctx->ctl_buflen - 1] = '\0';
5328
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1676 script_dump(ctx->ctl_buf, ctx->ctl_buflen);
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1677 fflush(stdout);
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1678 if (--ctx->ctl_extra != 0) {
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1679 putchar('\n');
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1680 eloop_event_add(ctx->eloop, ctx->control_fd,
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1681 dhcpcd_readdump1, ctx);
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1682 return;
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1683 }
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1684 exit_code = EXIT_SUCCESS;
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1685
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1686 finished:
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1687 shutdown(ctx->control_fd, SHUT_RDWR);
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1688 eloop_exit(ctx->eloop, exit_code);
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1689 }
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1690
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1691 static void
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1692 dhcpcd_readdump1(void *arg)
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1693 {
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1694 struct dhcpcd_ctx *ctx = arg;
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1695 ssize_t len;
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1696
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1697 len = read(ctx->control_fd, &ctx->ctl_buflen, sizeof(ctx->ctl_buflen));
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1698 if (len != sizeof(ctx->ctl_buflen)) {
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1699 if (len != -1)
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1700 errno = EINVAL;
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1701 goto err;
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1702 }
5345
f6051f78e441 Try and guard against impossibly large data.
Roy Marples <roy@marples.name>
parents: 5343
diff changeset
1703 if (ctx->ctl_buflen > SSIZE_MAX) {
f6051f78e441 Try and guard against impossibly large data.
Roy Marples <roy@marples.name>
parents: 5343
diff changeset
1704 errno = ENOBUFS;
f6051f78e441 Try and guard against impossibly large data.
Roy Marples <roy@marples.name>
parents: 5343
diff changeset
1705 goto err;
f6051f78e441 Try and guard against impossibly large data.
Roy Marples <roy@marples.name>
parents: 5343
diff changeset
1706 }
5328
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1707
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1708 free(ctx->ctl_buf);
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1709 ctx->ctl_buf = malloc(ctx->ctl_buflen);
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1710 if (ctx->ctl_buf == NULL)
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1711 goto err;
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1712
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1713 ctx->ctl_bufpos = 0;
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1714 eloop_event_add(ctx->eloop, ctx->control_fd,
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1715 dhcpcd_readdump2, ctx);
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1716 return;
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1717
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1718 err:
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1719 logerr(__func__);
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1720 eloop_exit(ctx->eloop, EXIT_FAILURE);
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1721 }
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1722
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1723 static void
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1724 dhcpcd_readdump0(void *arg)
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1725 {
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1726 struct dhcpcd_ctx *ctx = arg;
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1727 ssize_t len;
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1728
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1729 len = read(ctx->control_fd, &ctx->ctl_extra, sizeof(ctx->ctl_extra));
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1730 if (len != sizeof(ctx->ctl_extra)) {
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1731 if (len != -1)
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1732 errno = EINVAL;
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1733 logerr(__func__);
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1734 eloop_exit(ctx->eloop, EXIT_FAILURE);
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1735 return;
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1736 }
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1737
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1738 if (ctx->ctl_extra == 0) {
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1739 eloop_exit(ctx->eloop, EXIT_SUCCESS);
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1740 return;
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1741 }
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1742
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1743 eloop_event_add(ctx->eloop, ctx->control_fd,
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1744 dhcpcd_readdump1, ctx);
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1745 }
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1746
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1747 static void
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1748 dhcpcd_readdumptimeout(void *arg)
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1749 {
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1750 struct dhcpcd_ctx *ctx = arg;
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1751
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1752 logerrx(__func__);
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1753 eloop_exit(ctx->eloop, EXIT_FAILURE);
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1754 }
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1755
5092
995a49ee3418 dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents: 5089
diff changeset
1756 static int
995a49ee3418 dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents: 5089
diff changeset
1757 dhcpcd_readdump(struct dhcpcd_ctx *ctx)
995a49ee3418 dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents: 5089
diff changeset
1758 {
995a49ee3418 dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents: 5089
diff changeset
1759
5328
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1760 ctx->options |= DHCPCD_FORKED;
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1761 if (eloop_timeout_add_sec(ctx->eloop, 5,
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1762 dhcpcd_readdumptimeout, ctx) == -1)
5092
995a49ee3418 dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents: 5089
diff changeset
1763 return -1;
5328
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1764 return eloop_event_add(ctx->eloop, ctx->control_fd,
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1765 dhcpcd_readdump0, ctx);
5092
995a49ee3418 dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents: 5089
diff changeset
1766 }
995a49ee3418 dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents: 5089
diff changeset
1767
4856
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
1768 static void
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
1769 dhcpcd_fork_cb(void *arg)
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
1770 {
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
1771 struct dhcpcd_ctx *ctx = arg;
4868
119c8986dfc8 privsep: Enable ARP BPF filtering for interesting addresses
Roy Marples <roy@marples.name>
parents: 4861
diff changeset
1772 int exit_code;
4856
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
1773 ssize_t len;
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
1774
5467
49e119831377 privsep: Send signal from launcher to master over the socket
Roy Marples <roy@marples.name>
parents: 5466
diff changeset
1775 len = read(ctx->fork_fd, &exit_code, sizeof(exit_code));
4868
119c8986dfc8 privsep: Enable ARP BPF filtering for interesting addresses
Roy Marples <roy@marples.name>
parents: 4861
diff changeset
1776 if (len == -1) {
4856
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
1777 logerr(__func__);
4868
119c8986dfc8 privsep: Enable ARP BPF filtering for interesting addresses
Roy Marples <roy@marples.name>
parents: 4861
diff changeset
1778 exit_code = EXIT_FAILURE;
119c8986dfc8 privsep: Enable ARP BPF filtering for interesting addresses
Roy Marples <roy@marples.name>
parents: 4861
diff changeset
1779 } else if ((size_t)len < sizeof(exit_code)) {
119c8986dfc8 privsep: Enable ARP BPF filtering for interesting addresses
Roy Marples <roy@marples.name>
parents: 4861
diff changeset
1780 logerrx("%s: truncated read %zd (expected %zu)",
119c8986dfc8 privsep: Enable ARP BPF filtering for interesting addresses
Roy Marples <roy@marples.name>
parents: 4861
diff changeset
1781 __func__, len, sizeof(exit_code));
119c8986dfc8 privsep: Enable ARP BPF filtering for interesting addresses
Roy Marples <roy@marples.name>
parents: 4861
diff changeset
1782 exit_code = EXIT_FAILURE;
119c8986dfc8 privsep: Enable ARP BPF filtering for interesting addresses
Roy Marples <roy@marples.name>
parents: 4861
diff changeset
1783 }
5467
49e119831377 privsep: Send signal from launcher to master over the socket
Roy Marples <roy@marples.name>
parents: 5466
diff changeset
1784 if (ctx->options & DHCPCD_FORKED)
5466
8bf1ce29152c privsep: sandbox the launcher process
Roy Marples <roy@marples.name>
parents: 5458
diff changeset
1785 eloop_exit(ctx->eloop, exit_code);
5467
49e119831377 privsep: Send signal from launcher to master over the socket
Roy Marples <roy@marples.name>
parents: 5466
diff changeset
1786 else
49e119831377 privsep: Send signal from launcher to master over the socket
Roy Marples <roy@marples.name>
parents: 5466
diff changeset
1787 dhcpcd_signal_cb(exit_code, ctx);
4856
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
1788 }
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
1789
5439
35210bb8687c dhcpcd: Setup a socketpair in the launcher to write to stderr
Roy Marples <roy@marples.name>
parents: 5431
diff changeset
1790 static void
35210bb8687c dhcpcd: Setup a socketpair in the launcher to write to stderr
Roy Marples <roy@marples.name>
parents: 5431
diff changeset
1791 dhcpcd_stderr_cb(void *arg)
35210bb8687c dhcpcd: Setup a socketpair in the launcher to write to stderr
Roy Marples <roy@marples.name>
parents: 5431
diff changeset
1792 {
35210bb8687c dhcpcd: Setup a socketpair in the launcher to write to stderr
Roy Marples <roy@marples.name>
parents: 5431
diff changeset
1793 struct dhcpcd_ctx *ctx = arg;
35210bb8687c dhcpcd: Setup a socketpair in the launcher to write to stderr
Roy Marples <roy@marples.name>
parents: 5431
diff changeset
1794 char log[BUFSIZ];
35210bb8687c dhcpcd: Setup a socketpair in the launcher to write to stderr
Roy Marples <roy@marples.name>
parents: 5431
diff changeset
1795 ssize_t len;
35210bb8687c dhcpcd: Setup a socketpair in the launcher to write to stderr
Roy Marples <roy@marples.name>
parents: 5431
diff changeset
1796
35210bb8687c dhcpcd: Setup a socketpair in the launcher to write to stderr
Roy Marples <roy@marples.name>
parents: 5431
diff changeset
1797 len = read(ctx->stderr_fd, log, sizeof(log));
35210bb8687c dhcpcd: Setup a socketpair in the launcher to write to stderr
Roy Marples <roy@marples.name>
parents: 5431
diff changeset
1798 if (len == -1) {
5446
560e67bb9f6f dhcpcd: stderr callback fd may the reset by peer
Roy Marples <roy@marples.name>
parents: 5445
diff changeset
1799 if (errno != ECONNRESET)
560e67bb9f6f dhcpcd: stderr callback fd may the reset by peer
Roy Marples <roy@marples.name>
parents: 5445
diff changeset
1800 logerr(__func__);
5439
35210bb8687c dhcpcd: Setup a socketpair in the launcher to write to stderr
Roy Marples <roy@marples.name>
parents: 5431
diff changeset
1801 return;
35210bb8687c dhcpcd: Setup a socketpair in the launcher to write to stderr
Roy Marples <roy@marples.name>
parents: 5431
diff changeset
1802 }
35210bb8687c dhcpcd: Setup a socketpair in the launcher to write to stderr
Roy Marples <roy@marples.name>
parents: 5431
diff changeset
1803
35210bb8687c dhcpcd: Setup a socketpair in the launcher to write to stderr
Roy Marples <roy@marples.name>
parents: 5431
diff changeset
1804 log[len] = '\0';
35210bb8687c dhcpcd: Setup a socketpair in the launcher to write to stderr
Roy Marples <roy@marples.name>
parents: 5431
diff changeset
1805 fprintf(stderr, "%s", log);
35210bb8687c dhcpcd: Setup a socketpair in the launcher to write to stderr
Roy Marples <roy@marples.name>
parents: 5431
diff changeset
1806 }
35210bb8687c dhcpcd: Setup a socketpair in the launcher to write to stderr
Roy Marples <roy@marples.name>
parents: 5431
diff changeset
1807
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1808 int
5510
b9a2c4481c2e setproctitle compat requires envp, not environ
Roy Marples <roy@marples.name>
parents: 5507
diff changeset
1809 main(int argc, char **argv, char **envp)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1810 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1811 struct dhcpcd_ctx ctx;
4189
0b088d803b61 dhcp6: don't listen on IPv6 addresses when not using DHCP6
Roy Marples <roy@marples.name>
parents: 4184
diff changeset
1812 struct ifaddrs *ifaddrs = NULL;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1813 struct if_options *ifo;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1814 struct interface *ifp;
5170
8c6a66d852f4 This should really be sa_family_t.
Roy Marples <roy@marples.name>
parents: 5169
diff changeset
1815 sa_family_t family = AF_UNSPEC;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1816 int opt, oi = 0, i;
4923
4fcca755943e eloop: Allow for for timeouts greater than time_t and time wrapping
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
1817 unsigned int logopts, t;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1818 ssize_t len;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1819 #if defined(USE_SIGNALS) || !defined(THERE_IS_NO_FORK)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1820 pid_t pid;
5439
35210bb8687c dhcpcd: Setup a socketpair in the launcher to write to stderr
Roy Marples <roy@marples.name>
parents: 5431
diff changeset
1821 int fork_fd[2], stderr_fd[2];
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1822 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1823 #ifdef USE_SIGNALS
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1824 int sig = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1825 const char *siga = NULL;
5227
7406014c9120 dhcpcd: allow sigpipe in scripts.
Roy Marples <roy@marples.name>
parents: 5223
diff changeset
1826 size_t si;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1827 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1828
5507
78f2fda6ee5d compat: Use libbsd's setproctitle(3)
Roy Marples <roy@marples.name>
parents: 5503
diff changeset
1829 #ifdef SETPROCTITLE_H
5510
b9a2c4481c2e setproctitle compat requires envp, not environ
Roy Marples <roy@marples.name>
parents: 5507
diff changeset
1830 setproctitle_init(argc, argv, envp);
5511
618c0ef1bae8 BSD doesn't use envp
Roy Marples <roy@marples.name>
parents: 5510
diff changeset
1831 #else
618c0ef1bae8 BSD doesn't use envp
Roy Marples <roy@marples.name>
parents: 5510
diff changeset
1832 UNUSED(envp);
5507
78f2fda6ee5d compat: Use libbsd's setproctitle(3)
Roy Marples <roy@marples.name>
parents: 5503
diff changeset
1833 #endif
78f2fda6ee5d compat: Use libbsd's setproctitle(3)
Roy Marples <roy@marples.name>
parents: 5503
diff changeset
1834
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1835 /* Test for --help and --version */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1836 if (argc > 1) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1837 if (strcmp(argv[1], "--help") == 0) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1838 usage();
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1839 return EXIT_SUCCESS;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1840 } else if (strcmp(argv[1], "--version") == 0) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1841 printf(""PACKAGE" "VERSION"\n%s\n", dhcpcd_copyright);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1842 printf("Compiled in features:"
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1843 #ifdef INET
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1844 " INET"
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1845 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1846 #ifdef ARP
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1847 " ARP"
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1848 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1849 #ifdef ARPING
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1850 " ARPing"
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1851 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1852 #ifdef IPV4LL
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1853 " IPv4LL"
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1854 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1855 #ifdef INET6
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1856 " INET6"
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1857 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1858 #ifdef DHCP6
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1859 " DHCPv6"
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1860 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1861 #ifdef AUTH
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1862 " AUTH"
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1863 #endif
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4836
diff changeset
1864 #ifdef PRIVSEP
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4836
diff changeset
1865 " PRIVSEP"
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4836
diff changeset
1866 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1867 "\n");
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1868 return EXIT_SUCCESS;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1869 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1870 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1871
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1872 memset(&ctx, 0, sizeof(ctx));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1873
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1874 ifo = NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1875 ctx.cffile = CONFIG;
5255
ee23398a68db dhcpcd: Move the script file from per interface to global context
Roy Marples <roy@marples.name>
parents: 5252
diff changeset
1876 ctx.script = UNCONST(dhcpcd_default_script);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1877 ctx.control_fd = ctx.control_unpriv_fd = ctx.link_fd = -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1878 ctx.pf_inet_fd = -1;
5311
fd78486b12a7 if: Keep the PF_LINK socket open throughout
Roy Marples <roy@marples.name>
parents: 5310
diff changeset
1879 #ifdef PF_LINK
fd78486b12a7 if: Keep the PF_LINK socket open throughout
Roy Marples <roy@marples.name>
parents: 5310
diff changeset
1880 ctx.pf_link_fd = -1;
fd78486b12a7 if: Keep the PF_LINK socket open throughout
Roy Marples <roy@marples.name>
parents: 5310
diff changeset
1881 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1882
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1883 TAILQ_INIT(&ctx.control_fds);
4856
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
1884 #ifdef USE_SIGNALS
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
1885 ctx.fork_fd = -1;
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
1886 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1887 #ifdef PLUGIN_DEV
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1888 ctx.dev_fd = -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1889 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1890 #ifdef INET
5231
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5228
diff changeset
1891 ctx.udp_rfd = -1;
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5228
diff changeset
1892 ctx.udp_wfd = -1;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1893 #endif
4841
bace61b4b4ff Solaris: Fix non PRIVSEP compile
Roy Marples <roy@marples.name>
parents: 4840
diff changeset
1894 #if defined(INET6) && !defined(__sun)
4834
4684eb2ca980 build: Move rundir from /var/run to /var/run/dhcpcd
Roy Marples <roy@marples.name>
parents: 4823
diff changeset
1895 ctx.nd_fd = -1;
4684eb2ca980 build: Move rundir from /var/run to /var/run/dhcpcd
Roy Marples <roy@marples.name>
parents: 4823
diff changeset
1896 #endif
4684eb2ca980 build: Move rundir from /var/run to /var/run/dhcpcd
Roy Marples <roy@marples.name>
parents: 4823
diff changeset
1897 #ifdef DHCP6
5231
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5228
diff changeset
1898 ctx.dhcp6_rfd = -1;
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5228
diff changeset
1899 ctx.dhcp6_wfd = -1;
4834
4684eb2ca980 build: Move rundir from /var/run to /var/run/dhcpcd
Roy Marples <roy@marples.name>
parents: 4823
diff changeset
1900 #endif
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4836
diff changeset
1901 #ifdef PRIVSEP
5526
b1a3d9055662 privsep: Allow logfile reopening in a chroot
Roy Marples <roy@marples.name>
parents: 5525
diff changeset
1902 ctx.ps_root_fd = ctx.ps_log_fd = ctx.ps_data_fd = -1;
5385
0397759ce185 privsep: init more fd -1
Roy Marples <roy@marples.name>
parents: 5380
diff changeset
1903 ctx.ps_inet_fd = ctx.ps_control_fd = -1;
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4836
diff changeset
1904 TAILQ_INIT(&ctx.ps_processes);
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4836
diff changeset
1905 #endif
4249
c30233f8cca3 routes: allow a head clear with a context
Roy Marples <roy@marples.name>
parents: 4246
diff changeset
1906
5454
68ef863871d1 dhcpcd: Only manipulate stdin, stdout and stderr when valid
Roy Marples <roy@marples.name>
parents: 5451
diff changeset
1907 /* Check our streams for validity */
68ef863871d1 dhcpcd: Only manipulate stdin, stdout and stderr when valid
Roy Marples <roy@marples.name>
parents: 5451
diff changeset
1908 ctx.stdin_valid = fcntl(STDIN_FILENO, F_GETFD) != -1;
68ef863871d1 dhcpcd: Only manipulate stdin, stdout and stderr when valid
Roy Marples <roy@marples.name>
parents: 5451
diff changeset
1909 ctx.stdout_valid = fcntl(STDOUT_FILENO, F_GETFD) != -1;
68ef863871d1 dhcpcd: Only manipulate stdin, stdout and stderr when valid
Roy Marples <roy@marples.name>
parents: 5451
diff changeset
1910 ctx.stderr_valid = fcntl(STDERR_FILENO, F_GETFD) != -1;
68ef863871d1 dhcpcd: Only manipulate stdin, stdout and stderr when valid
Roy Marples <roy@marples.name>
parents: 5451
diff changeset
1911
68ef863871d1 dhcpcd: Only manipulate stdin, stdout and stderr when valid
Roy Marples <roy@marples.name>
parents: 5451
diff changeset
1912 logopts = LOGERR_LOG | LOGERR_LOG_DATE | LOGERR_LOG_PID;
68ef863871d1 dhcpcd: Only manipulate stdin, stdout and stderr when valid
Roy Marples <roy@marples.name>
parents: 5451
diff changeset
1913 if (ctx.stderr_valid)
68ef863871d1 dhcpcd: Only manipulate stdin, stdout and stderr when valid
Roy Marples <roy@marples.name>
parents: 5451
diff changeset
1914 logopts |= LOGERR_ERR;
68ef863871d1 dhcpcd: Only manipulate stdin, stdout and stderr when valid
Roy Marples <roy@marples.name>
parents: 5451
diff changeset
1915
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1916 i = 0;
5550
dba7608e00b3 options: allow --ia_na=1 and --ia_pd=2 on the command line
Roy Marples <roy@marples.name>
parents: 5547
diff changeset
1917
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1918 while ((opt = getopt_long(argc, argv,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1919 ctx.options & DHCPCD_PRINT_PIDFILE ? NOERR_IF_OPTS : IF_OPTS,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1920 cf_options, &oi)) != -1)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1921 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1922 switch (opt) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1923 case '4':
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1924 family = AF_INET;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1925 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1926 case '6':
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1927 family = AF_INET6;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1928 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1929 case 'f':
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1930 ctx.cffile = optarg;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1931 break;
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 4008
diff changeset
1932 case 'j':
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 4008
diff changeset
1933 free(ctx.logfile);
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 4008
diff changeset
1934 ctx.logfile = strdup(optarg);
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 4008
diff changeset
1935 break;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1936 #ifdef USE_SIGNALS
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1937 case 'k':
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1938 sig = SIGALRM;
4005
03e498b6ba82 transposition police!
Roy Marples <roy@marples.name>
parents: 3982
diff changeset
1939 siga = "ALRM";
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1940 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1941 case 'n':
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1942 sig = SIGHUP;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1943 siga = "HUP";
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1944 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1945 case 'g':
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1946 case 'p':
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1947 /* Force going via command socket as we're
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1948 * out of user definable signals. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1949 i = 4;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1950 break;
3960
42a6a3d1596e Remove custom logger and output all diagnostics via syslog(3).
Roy Marples <roy@marples.name>
parents: 3932
diff changeset
1951 case 'q':
5251
50eb48a9b47b dhcpcd: Silence console output entirely with more -q
Roy Marples <roy@marples.name>
parents: 5231
diff changeset
1952 /* -qq disables console output entirely.
5252
bae9ab6cd868 Apparently case is important.
Roy Marples <roy@marples.name>
parents: 5251
diff changeset
1953 * This is important for systemd because it logs
5251
50eb48a9b47b dhcpcd: Silence console output entirely with more -q
Roy Marples <roy@marples.name>
parents: 5231
diff changeset
1954 * both console AND syslog to the same log
50eb48a9b47b dhcpcd: Silence console output entirely with more -q
Roy Marples <roy@marples.name>
parents: 5231
diff changeset
1955 * resulting in untold confusion. */
50eb48a9b47b dhcpcd: Silence console output entirely with more -q
Roy Marples <roy@marples.name>
parents: 5231
diff changeset
1956 if (logopts & LOGERR_QUIET)
50eb48a9b47b dhcpcd: Silence console output entirely with more -q
Roy Marples <roy@marples.name>
parents: 5231
diff changeset
1957 logopts &= ~LOGERR_ERR;
50eb48a9b47b dhcpcd: Silence console output entirely with more -q
Roy Marples <roy@marples.name>
parents: 5231
diff changeset
1958 else
50eb48a9b47b dhcpcd: Silence console output entirely with more -q
Roy Marples <roy@marples.name>
parents: 5231
diff changeset
1959 logopts |= LOGERR_QUIET;
3960
42a6a3d1596e Remove custom logger and output all diagnostics via syslog(3).
Roy Marples <roy@marples.name>
parents: 3932
diff changeset
1960 break;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1961 case 'x':
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1962 sig = SIGTERM;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1963 siga = "TERM";
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1964 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1965 case 'N':
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1966 sig = SIGUSR1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1967 siga = "USR1";
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1968 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1969 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1970 case 'P':
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1971 ctx.options |= DHCPCD_PRINT_PIDFILE;
4051
91fb234797c2 Don't log anything when printing the pidfile.
Roy Marples <roy@marples.name>
parents: 4050
diff changeset
1972 logopts &= ~(LOGERR_LOG | LOGERR_ERR);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1973 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1974 case 'T':
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1975 i = 1;
4019
fe2f1ad133a2 Write syslog entries in logfile:
Roy Marples <roy@marples.name>
parents: 4010
diff changeset
1976 logopts &= ~LOGERR_LOG;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1977 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1978 case 'U':
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1979 i = 3;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1980 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1981 case 'V':
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1982 i = 2;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1983 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1984 case '?':
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1985 if (ctx.options & DHCPCD_PRINT_PIDFILE)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1986 continue;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1987 usage();
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1988 goto exit_failure;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1989 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1990 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1991
5550
dba7608e00b3 options: allow --ia_na=1 and --ia_pd=2 on the command line
Roy Marples <roy@marples.name>
parents: 5547
diff changeset
1992 if (optind != argc - 1)
dba7608e00b3 options: allow --ia_na=1 and --ia_pd=2 on the command line
Roy Marples <roy@marples.name>
parents: 5547
diff changeset
1993 ctx.options |= DHCPCD_MASTER;
dba7608e00b3 options: allow --ia_na=1 and --ia_pd=2 on the command line
Roy Marples <roy@marples.name>
parents: 5547
diff changeset
1994
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 4008
diff changeset
1995 logsetopts(logopts);
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 4008
diff changeset
1996 logopen(ctx.logfile);
3960
42a6a3d1596e Remove custom logger and output all diagnostics via syslog(3).
Roy Marples <roy@marples.name>
parents: 3932
diff changeset
1997
4766
cacf3b10beef Revert "compat: Use more portable setproctitle from nginx"
Roy Marples <roy@marples.name>
parents: 4765
diff changeset
1998 ctx.argv = argv;
cacf3b10beef Revert "compat: Use more portable setproctitle from nginx"
Roy Marples <roy@marples.name>
parents: 4765
diff changeset
1999 ctx.argc = argc;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2000 ctx.ifc = argc - optind;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2001 ctx.ifv = argv + optind;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2002
5454
68ef863871d1 dhcpcd: Only manipulate stdin, stdout and stderr when valid
Roy Marples <roy@marples.name>
parents: 5451
diff changeset
2003 rt_init(&ctx);
68ef863871d1 dhcpcd: Only manipulate stdin, stdout and stderr when valid
Roy Marples <roy@marples.name>
parents: 5451
diff changeset
2004
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2005 ifo = read_config(&ctx, NULL, NULL, NULL);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2006 if (ifo == NULL) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2007 if (ctx.options & DHCPCD_PRINT_PIDFILE)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2008 goto printpidfile;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2009 goto exit_failure;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2010 }
5550
dba7608e00b3 options: allow --ia_na=1 and --ia_pd=2 on the command line
Roy Marples <roy@marples.name>
parents: 5547
diff changeset
2011
4766
cacf3b10beef Revert "compat: Use more portable setproctitle from nginx"
Roy Marples <roy@marples.name>
parents: 4765
diff changeset
2012 opt = add_options(&ctx, NULL, ifo, argc, argv);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2013 if (opt != 1) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2014 if (ctx.options & DHCPCD_PRINT_PIDFILE)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2015 goto printpidfile;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2016 if (opt == 0)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2017 usage();
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2018 goto exit_failure;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2019 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2020 if (i == 2) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2021 printf("Interface options:\n");
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2022 if (optind == argc - 1) {
4249
c30233f8cca3 routes: allow a head clear with a context
Roy Marples <roy@marples.name>
parents: 4246
diff changeset
2023 free_options(&ctx, ifo);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2024 ifo = read_config(&ctx, argv[optind], NULL, NULL);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2025 if (ifo == NULL)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2026 goto exit_failure;
4766
cacf3b10beef Revert "compat: Use more portable setproctitle from nginx"
Roy Marples <roy@marples.name>
parents: 4765
diff changeset
2027 add_options(&ctx, NULL, ifo, argc, argv);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2028 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2029 if_printoptions();
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2030 #ifdef INET
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2031 if (family == 0 || family == AF_INET) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2032 printf("\nDHCPv4 options:\n");
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2033 dhcp_printoptions(&ctx,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2034 ifo->dhcp_override, ifo->dhcp_override_len);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2035 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2036 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2037 #ifdef INET6
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2038 if (family == 0 || family == AF_INET6) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2039 printf("\nND options:\n");
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2040 ipv6nd_printoptions(&ctx,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2041 ifo->nd_override, ifo->nd_override_len);
4349
f87c2ed9ff46 DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents: 4348
diff changeset
2042 #ifdef DHCP6
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2043 printf("\nDHCPv6 options:\n");
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2044 dhcp6_printoptions(&ctx,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2045 ifo->dhcp6_override, ifo->dhcp6_override_len);
4349
f87c2ed9ff46 DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents: 4348
diff changeset
2046 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2047 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2048 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2049 goto exit_success;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2050 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2051 ctx.options |= ifo->options;
5550
dba7608e00b3 options: allow --ia_na=1 and --ia_pd=2 on the command line
Roy Marples <roy@marples.name>
parents: 5547
diff changeset
2052
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2053 if (i == 1 || i == 3) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2054 if (i == 1)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2055 ctx.options |= DHCPCD_TEST;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2056 else
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2057 ctx.options |= DHCPCD_DUMPLEASE;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2058 ctx.options |= DHCPCD_PERSISTENT;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2059 ctx.options &= ~DHCPCD_DAEMONISE;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2060 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2061
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2062 #ifdef THERE_IS_NO_FORK
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2063 ctx.options &= ~DHCPCD_DAEMONISE;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2064 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2065
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2066 if (ctx.options & DHCPCD_DEBUG)
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 4008
diff changeset
2067 logsetopts(logopts | LOGERR_DEBUG);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2068
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2069 if (!(ctx.options & (DHCPCD_TEST | DHCPCD_DUMPLEASE))) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2070 printpidfile:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2071 /* If we have any other args, we should run as a single dhcpcd
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2072 * instance for that interface. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2073 if (optind == argc - 1 && !(ctx.options & DHCPCD_MASTER)) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2074 const char *per;
4047
b4e680c56be8 Should check that an interface name actually exists when
Roy Marples <roy@marples.name>
parents: 4027
diff changeset
2075 const char *ifname;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2076
4047
b4e680c56be8 Should check that an interface name actually exists when
Roy Marples <roy@marples.name>
parents: 4027
diff changeset
2077 ifname = *ctx.ifv;
b4e680c56be8 Should check that an interface name actually exists when
Roy Marples <roy@marples.name>
parents: 4027
diff changeset
2078 if (ifname == NULL || strlen(ifname) > IF_NAMESIZE) {
b4e680c56be8 Should check that an interface name actually exists when
Roy Marples <roy@marples.name>
parents: 4027
diff changeset
2079 errno = ifname == NULL ? EINVAL : E2BIG;
b4e680c56be8 Should check that an interface name actually exists when
Roy Marples <roy@marples.name>
parents: 4027
diff changeset
2080 logerr("%s: ", ifname);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2081 goto exit_failure;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2082 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2083 /* Allow a dhcpcd interface per address family */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2084 switch(family) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2085 case AF_INET:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2086 per = "-4";
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2087 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2088 case AF_INET6:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2089 per = "-6";
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2090 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2091 default:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2092 per = "";
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2093 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2094 snprintf(ctx.pidfile, sizeof(ctx.pidfile),
4834
4684eb2ca980 build: Move rundir from /var/run to /var/run/dhcpcd
Roy Marples <roy@marples.name>
parents: 4823
diff changeset
2095 PIDFILE, ifname, per, ".");
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2096 } else {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2097 snprintf(ctx.pidfile, sizeof(ctx.pidfile),
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2098 PIDFILE, "", "", "");
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2099 ctx.options |= DHCPCD_MASTER;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2100 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2101 if (ctx.options & DHCPCD_PRINT_PIDFILE) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2102 printf("%s\n", ctx.pidfile);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2103 goto exit_success;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2104 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2105 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2106
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2107 if (chdir("/") == -1)
5494
0fbde4769bbe Don't log backticks.
Roy Marples <roy@marples.name>
parents: 5490
diff changeset
2108 logerr("%s: chdir: /", __func__);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2109
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2110 /* Freeing allocated addresses from dumping leases can trigger
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2111 * eloop removals as well, so init here. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2112 if ((ctx.eloop = eloop_new()) == NULL) {
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 4008
diff changeset
2113 logerr("%s: eloop_init", __func__);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2114 goto exit_failure;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2115 }
4968
34d8fe622a9a dhcpcd: Ignore SIGPIPE, prefer EPIPE.
Roy Marples <roy@marples.name>
parents: 4965
diff changeset
2116
4184
548f1baa118d Init the signal handler ASAP so random stuff can be cleaned up.
Roy Marples <roy@marples.name>
parents: 4183
diff changeset
2117 #ifdef USE_SIGNALS
5227
7406014c9120 dhcpcd: allow sigpipe in scripts.
Roy Marples <roy@marples.name>
parents: 5223
diff changeset
2118 for (si = 0; si < dhcpcd_signals_ignore_len; si++)
5280
a986083da0ba Fix some clang analyzer issues
Roy Marples <roy@marples.name>
parents: 5269
diff changeset
2119 signal(dhcpcd_signals_ignore[si], SIG_IGN);
4968
34d8fe622a9a dhcpcd: Ignore SIGPIPE, prefer EPIPE.
Roy Marples <roy@marples.name>
parents: 4965
diff changeset
2120
4184
548f1baa118d Init the signal handler ASAP so random stuff can be cleaned up.
Roy Marples <roy@marples.name>
parents: 4183
diff changeset
2121 /* Save signal mask, block and redirect signals to our handler */
5301
e6f1372f2cf0 eloop: Just use ppoll(2)
Roy Marples <roy@marples.name>
parents: 5296
diff changeset
2122 eloop_signal_set_cb(ctx.eloop,
4184
548f1baa118d Init the signal handler ASAP so random stuff can be cleaned up.
Roy Marples <roy@marples.name>
parents: 4183
diff changeset
2123 dhcpcd_signals, dhcpcd_signals_len,
5301
e6f1372f2cf0 eloop: Just use ppoll(2)
Roy Marples <roy@marples.name>
parents: 5296
diff changeset
2124 dhcpcd_signal_cb, &ctx);
4184
548f1baa118d Init the signal handler ASAP so random stuff can be cleaned up.
Roy Marples <roy@marples.name>
parents: 4183
diff changeset
2125 if (eloop_signal_mask(ctx.eloop, &ctx.sigset) == -1) {
548f1baa118d Init the signal handler ASAP so random stuff can be cleaned up.
Roy Marples <roy@marples.name>
parents: 4183
diff changeset
2126 logerr("%s: eloop_signal_mask", __func__);
548f1baa118d Init the signal handler ASAP so random stuff can be cleaned up.
Roy Marples <roy@marples.name>
parents: 4183
diff changeset
2127 goto exit_failure;
548f1baa118d Init the signal handler ASAP so random stuff can be cleaned up.
Roy Marples <roy@marples.name>
parents: 4183
diff changeset
2128 }
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2129
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2130 if (sig != 0) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2131 pid = pidfile_read(ctx.pidfile);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2132 if (pid != 0 && pid != -1)
4024
0984f93d896e To be consitent, do the same to loginfo as we just did for logdebug.
Roy Marples <roy@marples.name>
parents: 4023
diff changeset
2133 loginfox("sending signal %s to pid %d", siga, pid);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2134 if (pid == 0 || pid == -1 || kill(pid, sig) != 0) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2135 if (sig != SIGHUP && sig != SIGUSR1 && errno != EPERM)
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 4008
diff changeset
2136 logerrx(PACKAGE" not running");
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2137 if (pid != 0 && pid != -1 && errno != ESRCH) {
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 4008
diff changeset
2138 logerr("kill");
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2139 goto exit_failure;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2140 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2141 unlink(ctx.pidfile);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2142 if (sig != SIGHUP && sig != SIGUSR1)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2143 goto exit_failure;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2144 } else {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2145 struct timespec ts;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2146
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2147 if (sig == SIGHUP || sig == SIGUSR1)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2148 goto exit_success;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2149 /* Spin until it exits */
4024
0984f93d896e To be consitent, do the same to loginfo as we just did for logdebug.
Roy Marples <roy@marples.name>
parents: 4023
diff changeset
2150 loginfox("waiting for pid %d to exit", pid);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2151 ts.tv_sec = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2152 ts.tv_nsec = 100000000; /* 10th of a second */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2153 for(i = 0; i < 100; i++) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2154 nanosleep(&ts, NULL);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2155 if (pidfile_read(ctx.pidfile) == -1)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2156 goto exit_success;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2157 }
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 4008
diff changeset
2158 logerrx("pid %d failed to exit", pid);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2159 goto exit_failure;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2160 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2161 }
5169
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2162 #endif
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2163
5445
2070a61faddd privsep: Dump leases from stdin in a limited sandbox
Roy Marples <roy@marples.name>
parents: 5442
diff changeset
2164 #ifdef PRIVSEP
2070a61faddd privsep: Dump leases from stdin in a limited sandbox
Roy Marples <roy@marples.name>
parents: 5442
diff changeset
2165 ps_init(&ctx);
2070a61faddd privsep: Dump leases from stdin in a limited sandbox
Roy Marples <roy@marples.name>
parents: 5442
diff changeset
2166 #endif
2070a61faddd privsep: Dump leases from stdin in a limited sandbox
Roy Marples <roy@marples.name>
parents: 5442
diff changeset
2167
5288
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2168 #ifndef SMALL
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2169 if (ctx.options & DHCPCD_DUMPLEASE &&
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2170 ioctl(fileno(stdin), FIONREAD, &i, sizeof(i)) == 0 &&
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2171 i > 0)
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2172 {
5445
2070a61faddd privsep: Dump leases from stdin in a limited sandbox
Roy Marples <roy@marples.name>
parents: 5442
diff changeset
2173 ctx.options |= DHCPCD_FORKED; /* pretend child process */
2070a61faddd privsep: Dump leases from stdin in a limited sandbox
Roy Marples <roy@marples.name>
parents: 5442
diff changeset
2174 #ifdef PRIVSEP
5466
8bf1ce29152c privsep: sandbox the launcher process
Roy Marples <roy@marples.name>
parents: 5458
diff changeset
2175 if (IN_PRIVSEP(&ctx) && ps_mastersandbox(&ctx, NULL) == -1)
5445
2070a61faddd privsep: Dump leases from stdin in a limited sandbox
Roy Marples <roy@marples.name>
parents: 5442
diff changeset
2176 goto exit_failure;
2070a61faddd privsep: Dump leases from stdin in a limited sandbox
Roy Marples <roy@marples.name>
parents: 5442
diff changeset
2177 #endif
5288
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2178 ifp = calloc(1, sizeof(*ifp));
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2179 if (ifp == NULL) {
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2180 logerr(__func__);
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2181 goto exit_failure;
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2182 }
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2183 ifp->ctx = &ctx;
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2184 ifp->options = ifo;
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2185 switch (family) {
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2186 case AF_INET:
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2187 #ifdef INET
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2188 if (dhcp_dump(ifp) == -1)
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2189 goto exit_failure;
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2190 break;
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2191 #else
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2192 logerrx("No DHCP support");
5292
2f2b53b05dc5 Fix compile without DHCP or DHCP6
Roy Marples <roy@marples.name>
parents: 5288
diff changeset
2193 goto exit_failure;
5288
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2194 #endif
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2195 case AF_INET6:
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2196 #ifdef DHCP6
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2197 if (dhcp6_dump(ifp) == -1)
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2198 goto exit_failure;
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2199 break;
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2200 #else
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2201 logerrx("No DHCP6 support");
5292
2f2b53b05dc5 Fix compile without DHCP or DHCP6
Roy Marples <roy@marples.name>
parents: 5288
diff changeset
2202 goto exit_failure;
5288
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2203 #endif
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2204 default:
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2205 logerrx("Family not specified. Please use -4 or -6.");
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2206 goto exit_failure;
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2207 }
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2208 goto exit_success;
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2209 }
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2210 #endif
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2211
5169
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2212 /* Test against siga instead of sig to avoid gcc
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2213 * warning about a bogus potential signed overflow.
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2214 * The end result will be the same. */
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2215 if ((siga == NULL || i == 4 || ctx.ifc != 0) &&
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2216 !(ctx.options & DHCPCD_TEST))
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2217 {
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2218 ctx.options |= DHCPCD_FORKED; /* avoid socket unlink */
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2219 if (!(ctx.options & DHCPCD_MASTER))
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2220 ctx.control_fd = control_open(argv[optind], family,
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2221 ctx.options & DHCPCD_DUMPLEASE);
5537
4492d1d88fdd control: create an unpriv socket for non master mode
Roy Marples <roy@marples.name>
parents: 5530
diff changeset
2222 if (!(ctx.options & DHCPCD_MASTER) && ctx.control_fd == -1)
4492d1d88fdd control: create an unpriv socket for non master mode
Roy Marples <roy@marples.name>
parents: 5530
diff changeset
2223 ctx.control_fd = control_open(argv[optind], AF_UNSPEC,
4492d1d88fdd control: create an unpriv socket for non master mode
Roy Marples <roy@marples.name>
parents: 5530
diff changeset
2224 ctx.options & DHCPCD_DUMPLEASE);
5169
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2225 if (ctx.control_fd == -1)
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2226 ctx.control_fd = control_open(NULL, AF_UNSPEC,
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2227 ctx.options & DHCPCD_DUMPLEASE);
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2228 if (ctx.control_fd != -1) {
5447
66512375d759 privsep: dump leases in a sandbox
Roy Marples <roy@marples.name>
parents: 5446
diff changeset
2229 #ifdef PRIVSEP
5466
8bf1ce29152c privsep: sandbox the launcher process
Roy Marples <roy@marples.name>
parents: 5458
diff changeset
2230 if (IN_PRIVSEP(&ctx) &&
8bf1ce29152c privsep: sandbox the launcher process
Roy Marples <roy@marples.name>
parents: 5458
diff changeset
2231 ps_mastersandbox(&ctx, NULL) == -1)
5447
66512375d759 privsep: dump leases in a sandbox
Roy Marples <roy@marples.name>
parents: 5446
diff changeset
2232 goto exit_failure;
66512375d759 privsep: dump leases in a sandbox
Roy Marples <roy@marples.name>
parents: 5446
diff changeset
2233 #endif
5169
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2234 if (!(ctx.options & DHCPCD_DUMPLEASE))
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2235 loginfox("sending commands to dhcpcd process");
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2236 len = control_send(&ctx, argc, argv);
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2237 if (len > 0)
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2238 logdebugx("send OK");
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2239 else {
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2240 logerr("%s: control_send", __func__);
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2241 goto exit_failure;
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2242 }
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2243 if (ctx.options & DHCPCD_DUMPLEASE) {
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2244 if (dhcpcd_readdump(&ctx) == -1) {
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2245 logerr("%s: dhcpcd_readdump", __func__);
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2246 goto exit_failure;
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2247 }
5328
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
2248 goto run_loop;
5169
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2249 }
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2250 goto exit_success;
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2251 } else {
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2252 if (errno != ENOENT)
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2253 logerr("%s: control_open", __func__);
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2254 if (ctx.options & DHCPCD_DUMPLEASE) {
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2255 if (errno == ENOENT)
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2256 logerrx("dhcpcd is not running");
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2257 goto exit_failure;
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2258 }
5328
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
2259 if (errno == EPERM || errno == EACCES)
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
2260 goto exit_failure;
5169
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2261 }
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2262 ctx.options &= ~DHCPCD_FORKED;
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2263 }
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2264
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2265 if (!(ctx.options & DHCPCD_TEST)) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2266 /* Ensure we have the needed directories */
5404
ad6e9cbeb6e8 Make DBDIR permissions same as the files it creates
Roy Marples <roy@marples.name>
parents: 5402
diff changeset
2267 if (mkdir(DBDIR, 0750) == -1 && errno != EEXIST)
5494
0fbde4769bbe Don't log backticks.
Roy Marples <roy@marples.name>
parents: 5490
diff changeset
2268 logerr("%s: mkdir: %s", __func__, DBDIR);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2269 if (mkdir(RUNDIR, 0755) == -1 && errno != EEXIST)
5494
0fbde4769bbe Don't log backticks.
Roy Marples <roy@marples.name>
parents: 5490
diff changeset
2270 logerr("%s: mkdir: %s", __func__, RUNDIR);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2271 if ((pid = pidfile_lock(ctx.pidfile)) != 0) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2272 if (pid == -1)
4834
4684eb2ca980 build: Move rundir from /var/run to /var/run/dhcpcd
Roy Marples <roy@marples.name>
parents: 4823
diff changeset
2273 logerr("%s: pidfile_lock: %s",
4684eb2ca980 build: Move rundir from /var/run to /var/run/dhcpcd
Roy Marples <roy@marples.name>
parents: 4823
diff changeset
2274 __func__, ctx.pidfile);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2275 else
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 4008
diff changeset
2276 logerrx(PACKAGE
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2277 " already running on pid %d (%s)",
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2278 pid, ctx.pidfile);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2279 goto exit_failure;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2280 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2281 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2282
5132
2b98d2fb5702 dhcpcd: always emit version when starting.
Roy Marples <roy@marples.name>
parents: 5128
diff changeset
2283 loginfox(PACKAGE "-" VERSION " starting");
5454
68ef863871d1 dhcpcd: Only manipulate stdin, stdout and stderr when valid
Roy Marples <roy@marples.name>
parents: 5451
diff changeset
2284 if (ctx.stdin_valid && freopen(_PATH_DEVNULL, "w", stdin) == NULL)
68ef863871d1 dhcpcd: Only manipulate stdin, stdout and stderr when valid
Roy Marples <roy@marples.name>
parents: 5451
diff changeset
2285 logwarn("freopen stdin");
5395
3ed7914080a9 dhcpcd: improve prior to log to another fd
Roy Marples <roy@marples.name>
parents: 5394
diff changeset
2286
5566
e90bef3160d7 src/dhcpcd.c: fix build without fork or signals (#20)
Fabrice Fontaine <fontaine.fabrice@gmail.com>
parents: 5559
diff changeset
2287 #if defined(USE_SIGNALS) && !defined(THERE_IS_NO_FORK)
5538
fc24946f9b2a dhcpcd: Don't create launcher process if keeping in foreground
Roy Marples <roy@marples.name>
parents: 5537
diff changeset
2288 if (!(ctx.options & DHCPCD_DAEMONISE))
fc24946f9b2a dhcpcd: Don't create launcher process if keeping in foreground
Roy Marples <roy@marples.name>
parents: 5537
diff changeset
2289 goto start_master;
fc24946f9b2a dhcpcd: Don't create launcher process if keeping in foreground
Roy Marples <roy@marples.name>
parents: 5537
diff changeset
2290
5439
35210bb8687c dhcpcd: Setup a socketpair in the launcher to write to stderr
Roy Marples <roy@marples.name>
parents: 5431
diff changeset
2291 if (xsocketpair(AF_UNIX, SOCK_DGRAM | SOCK_CXNB, 0, fork_fd) == -1 ||
5454
68ef863871d1 dhcpcd: Only manipulate stdin, stdout and stderr when valid
Roy Marples <roy@marples.name>
parents: 5451
diff changeset
2292 (ctx.stderr_valid &&
68ef863871d1 dhcpcd: Only manipulate stdin, stdout and stderr when valid
Roy Marples <roy@marples.name>
parents: 5451
diff changeset
2293 xsocketpair(AF_UNIX, SOCK_DGRAM | SOCK_CXNB, 0, stderr_fd) == -1))
5439
35210bb8687c dhcpcd: Setup a socketpair in the launcher to write to stderr
Roy Marples <roy@marples.name>
parents: 5431
diff changeset
2294 {
35210bb8687c dhcpcd: Setup a socketpair in the launcher to write to stderr
Roy Marples <roy@marples.name>
parents: 5431
diff changeset
2295 logerr("socketpair");
4856
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2296 goto exit_failure;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2297 }
4856
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2298 switch (pid = fork()) {
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2299 case -1:
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2300 logerr("fork");
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2301 goto exit_failure;
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2302 case 0:
5439
35210bb8687c dhcpcd: Setup a socketpair in the launcher to write to stderr
Roy Marples <roy@marples.name>
parents: 5431
diff changeset
2303 ctx.fork_fd = fork_fd[1];
35210bb8687c dhcpcd: Setup a socketpair in the launcher to write to stderr
Roy Marples <roy@marples.name>
parents: 5431
diff changeset
2304 close(fork_fd[0]);
5440
248013138b09 privsep: Fix prior for FreeBSD.
Roy Marples <roy@marples.name>
parents: 5439
diff changeset
2305 #ifdef PRIVSEP_RIGHTS
5503
18a7063f70c1 privsep: Improve rights on launcher fork and stderr fds
Roy Marples <roy@marples.name>
parents: 5501
diff changeset
2306 if (ps_rights_limit_fd(ctx.fork_fd) == -1) {
5440
248013138b09 privsep: Fix prior for FreeBSD.
Roy Marples <roy@marples.name>
parents: 5439
diff changeset
2307 logerr("ps_rights_limit_fdpair");
248013138b09 privsep: Fix prior for FreeBSD.
Roy Marples <roy@marples.name>
parents: 5439
diff changeset
2308 goto exit_failure;
248013138b09 privsep: Fix prior for FreeBSD.
Roy Marples <roy@marples.name>
parents: 5439
diff changeset
2309 }
248013138b09 privsep: Fix prior for FreeBSD.
Roy Marples <roy@marples.name>
parents: 5439
diff changeset
2310 #endif
5467
49e119831377 privsep: Send signal from launcher to master over the socket
Roy Marples <roy@marples.name>
parents: 5466
diff changeset
2311 eloop_event_add(ctx.eloop, ctx.fork_fd, dhcpcd_fork_cb, &ctx);
49e119831377 privsep: Send signal from launcher to master over the socket
Roy Marples <roy@marples.name>
parents: 5466
diff changeset
2312
5442
a069d919d44c FreeBSD: Don't rights limit stderr
Roy Marples <roy@marples.name>
parents: 5441
diff changeset
2313 /*
a069d919d44c FreeBSD: Don't rights limit stderr
Roy Marples <roy@marples.name>
parents: 5441
diff changeset
2314 * Redirect stderr to the stderr socketpair.
5441
ff7c7b4799b3 dhcpcd: Redirect stdout/stderr to the launcher stderr descriptor
Roy Marples <roy@marples.name>
parents: 5440
diff changeset
2315 * Redirect stdout as well.
ff7c7b4799b3 dhcpcd: Redirect stdout/stderr to the launcher stderr descriptor
Roy Marples <roy@marples.name>
parents: 5440
diff changeset
2316 * dhcpcd doesn't output via stdout, but something in
5442
a069d919d44c FreeBSD: Don't rights limit stderr
Roy Marples <roy@marples.name>
parents: 5441
diff changeset
2317 * a called script might.
a069d919d44c FreeBSD: Don't rights limit stderr
Roy Marples <roy@marples.name>
parents: 5441
diff changeset
2318 */
5454
68ef863871d1 dhcpcd: Only manipulate stdin, stdout and stderr when valid
Roy Marples <roy@marples.name>
parents: 5451
diff changeset
2319 if (ctx.stderr_valid) {
68ef863871d1 dhcpcd: Only manipulate stdin, stdout and stderr when valid
Roy Marples <roy@marples.name>
parents: 5451
diff changeset
2320 if (dup2(stderr_fd[1], STDERR_FILENO) == -1 ||
68ef863871d1 dhcpcd: Only manipulate stdin, stdout and stderr when valid
Roy Marples <roy@marples.name>
parents: 5451
diff changeset
2321 (ctx.stdout_valid &&
68ef863871d1 dhcpcd: Only manipulate stdin, stdout and stderr when valid
Roy Marples <roy@marples.name>
parents: 5451
diff changeset
2322 dup2(stderr_fd[1], STDOUT_FILENO) == -1))
68ef863871d1 dhcpcd: Only manipulate stdin, stdout and stderr when valid
Roy Marples <roy@marples.name>
parents: 5451
diff changeset
2323 logerr("dup2");
68ef863871d1 dhcpcd: Only manipulate stdin, stdout and stderr when valid
Roy Marples <roy@marples.name>
parents: 5451
diff changeset
2324 close(stderr_fd[0]);
68ef863871d1 dhcpcd: Only manipulate stdin, stdout and stderr when valid
Roy Marples <roy@marples.name>
parents: 5451
diff changeset
2325 close(stderr_fd[1]);
68ef863871d1 dhcpcd: Only manipulate stdin, stdout and stderr when valid
Roy Marples <roy@marples.name>
parents: 5451
diff changeset
2326 } else if (ctx.stdout_valid) {
68ef863871d1 dhcpcd: Only manipulate stdin, stdout and stderr when valid
Roy Marples <roy@marples.name>
parents: 5451
diff changeset
2327 if (freopen(_PATH_DEVNULL, "w", stdout) == NULL)
68ef863871d1 dhcpcd: Only manipulate stdin, stdout and stderr when valid
Roy Marples <roy@marples.name>
parents: 5451
diff changeset
2328 logerr("freopen stdout");
68ef863871d1 dhcpcd: Only manipulate stdin, stdout and stderr when valid
Roy Marples <roy@marples.name>
parents: 5451
diff changeset
2329 }
4856
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2330 if (setsid() == -1) {
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2331 logerr("%s: setsid", __func__);
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2332 goto exit_failure;
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2333 }
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2334 /* Ensure we can never get a controlling terminal */
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2335 switch (pid = fork()) {
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2336 case -1:
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2337 logerr("fork");
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2338 goto exit_failure;
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2339 case 0:
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2340 break;
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2341 default:
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2342 ctx.options |= DHCPCD_FORKED; /* A lie */
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2343 i = EXIT_SUCCESS;
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2344 goto exit1;
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2345 }
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2346 break;
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2347 default:
5466
8bf1ce29152c privsep: sandbox the launcher process
Roy Marples <roy@marples.name>
parents: 5458
diff changeset
2348 setproctitle("[launcher]");
5501
5b2272a0f3c3 privsep: Only log chrooting from the launcher process
Roy Marples <roy@marples.name>
parents: 5499
diff changeset
2349 ctx.options |= DHCPCD_FORKED | DHCPCD_LAUNCHER;
5439
35210bb8687c dhcpcd: Setup a socketpair in the launcher to write to stderr
Roy Marples <roy@marples.name>
parents: 5431
diff changeset
2350 ctx.fork_fd = fork_fd[0];
35210bb8687c dhcpcd: Setup a socketpair in the launcher to write to stderr
Roy Marples <roy@marples.name>
parents: 5431
diff changeset
2351 close(fork_fd[1]);
5440
248013138b09 privsep: Fix prior for FreeBSD.
Roy Marples <roy@marples.name>
parents: 5439
diff changeset
2352 #ifdef PRIVSEP_RIGHTS
5503
18a7063f70c1 privsep: Improve rights on launcher fork and stderr fds
Roy Marples <roy@marples.name>
parents: 5501
diff changeset
2353 if (ps_rights_limit_fd(ctx.fork_fd) == -1) {
18a7063f70c1 privsep: Improve rights on launcher fork and stderr fds
Roy Marples <roy@marples.name>
parents: 5501
diff changeset
2354 logerr("ps_rights_limit_fd");
5440
248013138b09 privsep: Fix prior for FreeBSD.
Roy Marples <roy@marples.name>
parents: 5439
diff changeset
2355 goto exit_failure;
248013138b09 privsep: Fix prior for FreeBSD.
Roy Marples <roy@marples.name>
parents: 5439
diff changeset
2356 }
248013138b09 privsep: Fix prior for FreeBSD.
Roy Marples <roy@marples.name>
parents: 5439
diff changeset
2357 #endif
4856
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2358 eloop_event_add(ctx.eloop, ctx.fork_fd, dhcpcd_fork_cb, &ctx);
5454
68ef863871d1 dhcpcd: Only manipulate stdin, stdout and stderr when valid
Roy Marples <roy@marples.name>
parents: 5451
diff changeset
2359
68ef863871d1 dhcpcd: Only manipulate stdin, stdout and stderr when valid
Roy Marples <roy@marples.name>
parents: 5451
diff changeset
2360 if (ctx.stderr_valid) {
68ef863871d1 dhcpcd: Only manipulate stdin, stdout and stderr when valid
Roy Marples <roy@marples.name>
parents: 5451
diff changeset
2361 ctx.stderr_fd = stderr_fd[0];
68ef863871d1 dhcpcd: Only manipulate stdin, stdout and stderr when valid
Roy Marples <roy@marples.name>
parents: 5451
diff changeset
2362 close(stderr_fd[1]);
68ef863871d1 dhcpcd: Only manipulate stdin, stdout and stderr when valid
Roy Marples <roy@marples.name>
parents: 5451
diff changeset
2363 #ifdef PRIVSEP_RIGHTS
5503
18a7063f70c1 privsep: Improve rights on launcher fork and stderr fds
Roy Marples <roy@marples.name>
parents: 5501
diff changeset
2364 if (ps_rights_limit_fd(ctx.stderr_fd) == 1) {
18a7063f70c1 privsep: Improve rights on launcher fork and stderr fds
Roy Marples <roy@marples.name>
parents: 5501
diff changeset
2365 logerr("ps_rights_limit_fd");
5454
68ef863871d1 dhcpcd: Only manipulate stdin, stdout and stderr when valid
Roy Marples <roy@marples.name>
parents: 5451
diff changeset
2366 goto exit_failure;
68ef863871d1 dhcpcd: Only manipulate stdin, stdout and stderr when valid
Roy Marples <roy@marples.name>
parents: 5451
diff changeset
2367 }
68ef863871d1 dhcpcd: Only manipulate stdin, stdout and stderr when valid
Roy Marples <roy@marples.name>
parents: 5451
diff changeset
2368 #endif
5503
18a7063f70c1 privsep: Improve rights on launcher fork and stderr fds
Roy Marples <roy@marples.name>
parents: 5501
diff changeset
2369 eloop_event_add(ctx.eloop, ctx.stderr_fd,
18a7063f70c1 privsep: Improve rights on launcher fork and stderr fds
Roy Marples <roy@marples.name>
parents: 5501
diff changeset
2370 dhcpcd_stderr_cb, &ctx);
5454
68ef863871d1 dhcpcd: Only manipulate stdin, stdout and stderr when valid
Roy Marples <roy@marples.name>
parents: 5451
diff changeset
2371 }
5466
8bf1ce29152c privsep: sandbox the launcher process
Roy Marples <roy@marples.name>
parents: 5458
diff changeset
2372 #ifdef PRIVSEP
5467
49e119831377 privsep: Send signal from launcher to master over the socket
Roy Marples <roy@marples.name>
parents: 5466
diff changeset
2373 if (IN_PRIVSEP(&ctx) && ps_mastersandbox(&ctx, NULL) == -1)
5466
8bf1ce29152c privsep: sandbox the launcher process
Roy Marples <roy@marples.name>
parents: 5458
diff changeset
2374 goto exit_failure;
8bf1ce29152c privsep: sandbox the launcher process
Roy Marples <roy@marples.name>
parents: 5458
diff changeset
2375 #endif
4856
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2376 goto run_loop;
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2377 }
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2378
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2379 /* We have now forked, setsid, forked once more.
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2380 * From this point on, we are the controlling daemon. */
5538
fc24946f9b2a dhcpcd: Don't create launcher process if keeping in foreground
Roy Marples <roy@marples.name>
parents: 5537
diff changeset
2381 logdebugx("spawned master process on PID %d", getpid());
fc24946f9b2a dhcpcd: Don't create launcher process if keeping in foreground
Roy Marples <roy@marples.name>
parents: 5537
diff changeset
2382 start_master:
4856
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2383 ctx.options |= DHCPCD_STARTED;
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2384 if ((pid = pidfile_lock(ctx.pidfile)) != 0) {
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2385 logerr("%s: pidfile_lock %d", __func__, pid);
5451
840cdf8beeb8 dhcpcd: avoid privsep errors if we error locking the pidfile
Roy Marples <roy@marples.name>
parents: 5447
diff changeset
2386 #ifdef PRIVSEP
840cdf8beeb8 dhcpcd: avoid privsep errors if we error locking the pidfile
Roy Marples <roy@marples.name>
parents: 5447
diff changeset
2387 /* privsep has not started ... */
840cdf8beeb8 dhcpcd: avoid privsep errors if we error locking the pidfile
Roy Marples <roy@marples.name>
parents: 5447
diff changeset
2388 ctx.options &= ~DHCPCD_PRIVSEP;
840cdf8beeb8 dhcpcd: avoid privsep errors if we error locking the pidfile
Roy Marples <roy@marples.name>
parents: 5447
diff changeset
2389 #endif
4856
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2390 goto exit_failure;
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2391 }
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2392 #endif
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2393
5458
dd8347a0ea1c Adjust prior so that message is logged before starting dev
Roy Marples <roy@marples.name>
parents: 5454
diff changeset
2394 os_init();
dd8347a0ea1c Adjust prior so that message is logged before starting dev
Roy Marples <roy@marples.name>
parents: 5454
diff changeset
2395
5397
4c2de9b44e60 BSD: Setup sysctls before redirecting stderr
Roy Marples <roy@marples.name>
parents: 5395
diff changeset
2396 #if defined(BSD) && defined(INET6)
4c2de9b44e60 BSD: Setup sysctls before redirecting stderr
Roy Marples <roy@marples.name>
parents: 5395
diff changeset
2397 /* Disable the kernel RTADV sysctl as early as possible. */
4c2de9b44e60 BSD: Setup sysctls before redirecting stderr
Roy Marples <roy@marples.name>
parents: 5395
diff changeset
2398 if (ctx.options & DHCPCD_IPV6 && ctx.options & DHCPCD_IPV6RS)
4c2de9b44e60 BSD: Setup sysctls before redirecting stderr
Roy Marples <roy@marples.name>
parents: 5395
diff changeset
2399 if_disable_rtadv();
4c2de9b44e60 BSD: Setup sysctls before redirecting stderr
Roy Marples <roy@marples.name>
parents: 5395
diff changeset
2400 #endif
4c2de9b44e60 BSD: Setup sysctls before redirecting stderr
Roy Marples <roy@marples.name>
parents: 5395
diff changeset
2401
4953
109206a59cc6 privsep: Delay control startup after starting privsep
Roy Marples <roy@marples.name>
parents: 4937
diff changeset
2402 #ifdef PRIVSEP
5328
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
2403 if (IN_PRIVSEP(&ctx) && ps_start(&ctx) == -1) {
4953
109206a59cc6 privsep: Delay control startup after starting privsep
Roy Marples <roy@marples.name>
parents: 4937
diff changeset
2404 logerr("ps_start");
109206a59cc6 privsep: Delay control startup after starting privsep
Roy Marples <roy@marples.name>
parents: 4937
diff changeset
2405 goto exit_failure;
109206a59cc6 privsep: Delay control startup after starting privsep
Roy Marples <roy@marples.name>
parents: 4937
diff changeset
2406 }
109206a59cc6 privsep: Delay control startup after starting privsep
Roy Marples <roy@marples.name>
parents: 4937
diff changeset
2407 if (ctx.options & DHCPCD_FORKED)
109206a59cc6 privsep: Delay control startup after starting privsep
Roy Marples <roy@marples.name>
parents: 4937
diff changeset
2408 goto run_loop;
109206a59cc6 privsep: Delay control startup after starting privsep
Roy Marples <roy@marples.name>
parents: 4937
diff changeset
2409 #endif
109206a59cc6 privsep: Delay control startup after starting privsep
Roy Marples <roy@marples.name>
parents: 4937
diff changeset
2410
5328
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
2411 if (!(ctx.options & DHCPCD_TEST)) {
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
2412 if (control_start(&ctx,
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
2413 ctx.options & DHCPCD_MASTER ?
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
2414 NULL : argv[optind], family) == -1)
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
2415 {
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
2416 logerr("%s: control_start", __func__);
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
2417 goto exit_failure;
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
2418 }
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2419 }
4059
dd134e7e2ef6 dhcpcd.c: Fix -n opening sockets.
Roy Marples <roy@marples.name>
parents: 4052
diff changeset
2420
5262
f168a25dd330 privsep: Fix compile for prior without dev plugins
Roy Marples <roy@marples.name>
parents: 5260
diff changeset
2421 #ifdef PLUGIN_DEV
4994
af9de589341f Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents: 4989
diff changeset
2422 /* Start any dev listening plugin which may want to
af9de589341f Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents: 4989
diff changeset
2423 * change the interface name provided by the kernel */
5260
7571d82b48da privsep: Allow dev plugins to work
Roy Marples <roy@marples.name>
parents: 5259
diff changeset
2424 if (!IN_PRIVSEP(&ctx) &&
7571d82b48da privsep: Allow dev plugins to work
Roy Marples <roy@marples.name>
parents: 5259
diff changeset
2425 (ctx.options & (DHCPCD_MASTER | DHCPCD_DEV)) ==
4994
af9de589341f Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents: 4989
diff changeset
2426 (DHCPCD_MASTER | DHCPCD_DEV))
5260
7571d82b48da privsep: Allow dev plugins to work
Roy Marples <roy@marples.name>
parents: 5259
diff changeset
2427 dev_start(&ctx, dhcpcd_handleinterface);
5262
f168a25dd330 privsep: Fix compile for prior without dev plugins
Roy Marples <roy@marples.name>
parents: 5260
diff changeset
2428 #endif
4994
af9de589341f Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents: 4989
diff changeset
2429
4223
467600defbe4 Add support for setproctitle(3).
Roy Marples <roy@marples.name>
parents: 4218
diff changeset
2430 setproctitle("%s%s%s",
467600defbe4 Add support for setproctitle(3).
Roy Marples <roy@marples.name>
parents: 4218
diff changeset
2431 ctx.options & DHCPCD_MASTER ? "[master]" : argv[optind],
467600defbe4 Add support for setproctitle(3).
Roy Marples <roy@marples.name>
parents: 4218
diff changeset
2432 ctx.options & DHCPCD_IPV4 ? " [ip4]" : "",
467600defbe4 Add support for setproctitle(3).
Roy Marples <roy@marples.name>
parents: 4218
diff changeset
2433 ctx.options & DHCPCD_IPV6 ? " [ip6]" : "");
467600defbe4 Add support for setproctitle(3).
Roy Marples <roy@marples.name>
parents: 4218
diff changeset
2434
4059
dd134e7e2ef6 dhcpcd.c: Fix -n opening sockets.
Roy Marples <roy@marples.name>
parents: 4052
diff changeset
2435 if (if_opensockets(&ctx) == -1) {
dd134e7e2ef6 dhcpcd.c: Fix -n opening sockets.
Roy Marples <roy@marples.name>
parents: 4052
diff changeset
2436 logerr("%s: if_opensockets", __func__);
dd134e7e2ef6 dhcpcd.c: Fix -n opening sockets.
Roy Marples <roy@marples.name>
parents: 4052
diff changeset
2437 goto exit_failure;
dd134e7e2ef6 dhcpcd.c: Fix -n opening sockets.
Roy Marples <roy@marples.name>
parents: 4052
diff changeset
2438 }
4415
4eb8ce6f854c options: add link_rcvbuf variable
Roy Marples <roy@marples.name>
parents: 4394
diff changeset
2439 #ifndef SMALL
4eb8ce6f854c options: add link_rcvbuf variable
Roy Marples <roy@marples.name>
parents: 4394
diff changeset
2440 dhcpcd_setlinkrcvbuf(&ctx);
4eb8ce6f854c options: add link_rcvbuf variable
Roy Marples <roy@marples.name>
parents: 4394
diff changeset
2441 #endif
4059
dd134e7e2ef6 dhcpcd.c: Fix -n opening sockets.
Roy Marples <roy@marples.name>
parents: 4052
diff changeset
2442
5207
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
2443 /* Try and create DUID from the machine UUID. */
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
2444 dhcpcd_initduid(&ctx, NULL);
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
2445
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
2446 /* Cache the default vendor option. */
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
2447 if (dhcp_vendor(ctx.vendor, sizeof(ctx.vendor)) == -1)
5380
c8d7d4d5dd1c dhcpcd: Report error when caching vendor
Roy Marples <roy@marples.name>
parents: 5377
diff changeset
2448 logerr("dhcp_vendor");
5207
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
2449
5331
d075e31eb148 privsep: For Linux and Solaris, set RLIMIT_NOFILES to nevents
Roy Marples <roy@marples.name>
parents: 5328
diff changeset
2450 /* Start handling kernel messages for interfaces, addresses and
d075e31eb148 privsep: For Linux and Solaris, set RLIMIT_NOFILES to nevents
Roy Marples <roy@marples.name>
parents: 5328
diff changeset
2451 * routes. */
d075e31eb148 privsep: For Linux and Solaris, set RLIMIT_NOFILES to nevents
Roy Marples <roy@marples.name>
parents: 5328
diff changeset
2452 eloop_event_add(ctx.eloop, ctx.link_fd, dhcpcd_handlelink, &ctx);
d075e31eb148 privsep: For Linux and Solaris, set RLIMIT_NOFILES to nevents
Roy Marples <roy@marples.name>
parents: 5328
diff changeset
2453
5204
47f18579daae privsep: Implement pledge(2) support as found on OpenBSD
Roy Marples <roy@marples.name>
parents: 5197
diff changeset
2454 #ifdef PRIVSEP
5466
8bf1ce29152c privsep: sandbox the launcher process
Roy Marples <roy@marples.name>
parents: 5458
diff changeset
2455 if (IN_PRIVSEP(&ctx) && ps_mastersandbox(&ctx, "stdio route") == -1)
5321
41b99a2a12cf privsep: Limit rights generically rather than Capsicum specifc
Roy Marples <roy@marples.name>
parents: 5318
diff changeset
2456 goto exit_failure;
5204
47f18579daae privsep: Implement pledge(2) support as found on OpenBSD
Roy Marples <roy@marples.name>
parents: 5197
diff changeset
2457 #endif
47f18579daae privsep: Implement pledge(2) support as found on OpenBSD
Roy Marples <roy@marples.name>
parents: 5197
diff changeset
2458
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2459 /* When running dhcpcd against a single interface, we need to retain
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2460 * the old behaviour of waiting for an IP address */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2461 if (ctx.ifc == 1 && !(ctx.options & DHCPCD_BACKGROUND))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2462 ctx.options |= DHCPCD_WAITIP;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2463
4189
0b088d803b61 dhcp6: don't listen on IPv6 addresses when not using DHCP6
Roy Marples <roy@marples.name>
parents: 4184
diff changeset
2464 ctx.ifaces = if_discover(&ctx, &ifaddrs, ctx.ifc, ctx.ifv);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2465 if (ctx.ifaces == NULL) {
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 4008
diff changeset
2466 logerr("%s: if_discover", __func__);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2467 goto exit_failure;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2468 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2469 for (i = 0; i < ctx.ifc; i++) {
5089
4af70397cd7d dhcpcd: Improve error when interface does not exist vs invalid config
Roy Marples <roy@marples.name>
parents: 5088
diff changeset
2470 if ((ifp = if_find(ctx.ifaces, ctx.ifv[i])) == NULL)
4af70397cd7d dhcpcd: Improve error when interface does not exist vs invalid config
Roy Marples <roy@marples.name>
parents: 5088
diff changeset
2471 logerrx("%s: interface not found",
4af70397cd7d dhcpcd: Improve error when interface does not exist vs invalid config
Roy Marples <roy@marples.name>
parents: 5088
diff changeset
2472 ctx.ifv[i]);
4af70397cd7d dhcpcd: Improve error when interface does not exist vs invalid config
Roy Marples <roy@marples.name>
parents: 5088
diff changeset
2473 else if (!ifp->active)
4af70397cd7d dhcpcd: Improve error when interface does not exist vs invalid config
Roy Marples <roy@marples.name>
parents: 5088
diff changeset
2474 logerrx("%s: interface has an invalid configuration",
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2475 ctx.ifv[i]);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2476 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2477 TAILQ_FOREACH(ifp, ctx.ifaces, next) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2478 if (ifp->active == IF_ACTIVE_USER)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2479 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2480 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2481 if (ifp == NULL) {
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 4008
diff changeset
2482 if (ctx.ifc == 0) {
5064
7721231839f5 logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents: 5063
diff changeset
2483 int loglevel;
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 4008
diff changeset
2484
5064
7721231839f5 logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents: 5063
diff changeset
2485 loglevel = ctx.options & DHCPCD_INACTIVE ?
7721231839f5 logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents: 5063
diff changeset
2486 LOG_DEBUG : LOG_ERR;
7721231839f5 logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents: 5063
diff changeset
2487 logmessage(loglevel, "no valid interfaces found");
5148
5f4227456653 dhcpcd: daemomize if no valid interfaces found
Roy Marples <roy@marples.name>
parents: 5144
diff changeset
2488 dhcpcd_daemonise(&ctx);
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 4008
diff changeset
2489 } else
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2490 goto exit_failure;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2491 if (!(ctx.options & DHCPCD_LINK)) {
4226
fdca1e4dfd1e dhcpcd: Don't report errno when aborting here.
Roy Marples <roy@marples.name>
parents: 4223
diff changeset
2492 logerrx("aborting as link detection is disabled");
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2493 goto exit_failure;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2494 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2495 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2496
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2497 TAILQ_FOREACH(ifp, ctx.ifaces, next) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2498 if (ifp->active)
4766
cacf3b10beef Revert "compat: Use more portable setproctitle from nginx"
Roy Marples <roy@marples.name>
parents: 4765
diff changeset
2499 dhcpcd_initstate1(ifp, argc, argv, 0);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2500 }
4189
0b088d803b61 dhcp6: don't listen on IPv6 addresses when not using DHCP6
Roy Marples <roy@marples.name>
parents: 4184
diff changeset
2501 if_learnaddrs(&ctx, ctx.ifaces, &ifaddrs);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2502
4856
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2503 if (ctx.options & DHCPCD_BACKGROUND)
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2504 dhcpcd_daemonise(&ctx);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2505
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2506 opt = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2507 TAILQ_FOREACH(ifp, ctx.ifaces, next) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2508 if (ifp->active) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2509 run_preinit(ifp);
5499
6a2da5651841 dhcpcd: Simplify the link handling even more
Roy Marples <roy@marples.name>
parents: 5497
diff changeset
2510 if (if_is_link_up(ifp))
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2511 opt = 1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2512 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2513 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2514
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2515 if (!(ctx.options & DHCPCD_BACKGROUND)) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2516 if (ctx.options & DHCPCD_MASTER)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2517 t = ifo->timeout;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2518 else {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2519 t = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2520 TAILQ_FOREACH(ifp, ctx.ifaces, next) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2521 if (ifp->active) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2522 t = ifp->options->timeout;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2523 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2524 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2525 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2526 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2527 if (opt == 0 &&
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2528 ctx.options & DHCPCD_LINK &&
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2529 !(ctx.options & DHCPCD_WAITIP))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2530 {
5064
7721231839f5 logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents: 5063
diff changeset
2531 int loglevel;
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 4008
diff changeset
2532
5064
7721231839f5 logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents: 5063
diff changeset
2533 loglevel = ctx.options & DHCPCD_INACTIVE ?
7721231839f5 logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents: 5063
diff changeset
2534 LOG_DEBUG : LOG_WARNING;
7721231839f5 logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents: 5063
diff changeset
2535 logmessage(loglevel, "no interfaces have a carrier");
4856
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2536 dhcpcd_daemonise(&ctx);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2537 } else if (t > 0 &&
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2538 /* Test mode removes the daemonise bit, so check for both */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2539 ctx.options & (DHCPCD_DAEMONISE | DHCPCD_TEST))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2540 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2541 eloop_timeout_add_sec(ctx.eloop, t,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2542 handle_exit_timeout, &ctx);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2543 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2544 }
4249
c30233f8cca3 routes: allow a head clear with a context
Roy Marples <roy@marples.name>
parents: 4246
diff changeset
2545 free_options(&ctx, ifo);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2546 ifo = NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2547
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2548 TAILQ_FOREACH(ifp, ctx.ifaces, next) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2549 if (ifp->active)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2550 eloop_timeout_add_sec(ctx.eloop, 0,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2551 dhcpcd_prestartinterface, ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2552 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2553
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4836
diff changeset
2554 run_loop:
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2555 i = eloop_start(ctx.eloop, &ctx.sigset);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2556 if (i < 0) {
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 4008
diff changeset
2557 logerr("%s: eloop_start", __func__);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2558 goto exit_failure;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2559 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2560 goto exit1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2561
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2562 exit_success:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2563 i = EXIT_SUCCESS;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2564 goto exit1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2565
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2566 exit_failure:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2567 i = EXIT_FAILURE;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2568
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2569 exit1:
5552
66dc60bf133d Don't stop control in test
Roy Marples <roy@marples.name>
parents: 5551
diff changeset
2570 if (!(ctx.options & DHCPCD_TEST) && control_stop(&ctx) == -1)
4989
ca9234046989 privsep: chroot the master process
Roy Marples <roy@marples.name>
parents: 4988
diff changeset
2571 logerr("%s: control_stop", __func__);
5318
8611693d307f Linux: more freeifaddrs
Roy Marples <roy@marples.name>
parents: 5311
diff changeset
2572 if (ifaddrs != NULL) {
8611693d307f Linux: more freeifaddrs
Roy Marples <roy@marples.name>
parents: 5311
diff changeset
2573 #ifdef PRIVSEP_GETIFADDRS
8611693d307f Linux: more freeifaddrs
Roy Marples <roy@marples.name>
parents: 5311
diff changeset
2574 if (IN_PRIVSEP(&ctx))
8611693d307f Linux: more freeifaddrs
Roy Marples <roy@marples.name>
parents: 5311
diff changeset
2575 free(ifaddrs);
8611693d307f Linux: more freeifaddrs
Roy Marples <roy@marples.name>
parents: 5311
diff changeset
2576 else
8611693d307f Linux: more freeifaddrs
Roy Marples <roy@marples.name>
parents: 5311
diff changeset
2577 #endif
8611693d307f Linux: more freeifaddrs
Roy Marples <roy@marples.name>
parents: 5311
diff changeset
2578 freeifaddrs(ifaddrs);
8611693d307f Linux: more freeifaddrs
Roy Marples <roy@marples.name>
parents: 5311
diff changeset
2579 }
5470
d7a5671d08c5 privsep: Don't remove pidfile at exit
Roy Marples <roy@marples.name>
parents: 5467
diff changeset
2580 /* ps_stop will clear DHCPCD_PRIVSEP but we need to
d7a5671d08c5 privsep: Don't remove pidfile at exit
Roy Marples <roy@marples.name>
parents: 5467
diff changeset
2581 * remember it to avoid attemping to remove the pidfile */
d7a5671d08c5 privsep: Don't remove pidfile at exit
Roy Marples <roy@marples.name>
parents: 5467
diff changeset
2582 oi = ctx.options & DHCPCD_PRIVSEP ? 1 : 0;
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4836
diff changeset
2583 #ifdef PRIVSEP
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4836
diff changeset
2584 ps_stop(&ctx);
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4836
diff changeset
2585 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2586 /* Free memory and close fd's */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2587 if (ctx.ifaces) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2588 while ((ifp = TAILQ_FIRST(ctx.ifaces))) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2589 TAILQ_REMOVE(ctx.ifaces, ifp, next);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2590 if_free(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2591 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2592 free(ctx.ifaces);
4797
f0b3096122f6 dhcpcd: Set ctx.ifaces to NULL after freeing
Roy Marples <roy@marples.name>
parents: 4777
diff changeset
2593 ctx.ifaces = NULL;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2594 }
4607
8e54887526a6 routes: Fix a NULL dereference error for global static routes
Roy Marples <roy@marples.name>
parents: 4583
diff changeset
2595 free_options(&ctx, ifo);
4583
4b6fda3e83d8 Free script buffers before exiting from a fork.
Roy Marples <roy@marples.name>
parents: 4582
diff changeset
2596 #ifdef HAVE_OPEN_MEMSTREAM
4b6fda3e83d8 Free script buffers before exiting from a fork.
Roy Marples <roy@marples.name>
parents: 4582
diff changeset
2597 if (ctx.script_fp)
4b6fda3e83d8 Free script buffers before exiting from a fork.
Roy Marples <roy@marples.name>
parents: 4582
diff changeset
2598 fclose(ctx.script_fp);
4b6fda3e83d8 Free script buffers before exiting from a fork.
Roy Marples <roy@marples.name>
parents: 4582
diff changeset
2599 #endif
4b6fda3e83d8 Free script buffers before exiting from a fork.
Roy Marples <roy@marples.name>
parents: 4582
diff changeset
2600 free(ctx.script_buf);
4b6fda3e83d8 Free script buffers before exiting from a fork.
Roy Marples <roy@marples.name>
parents: 4582
diff changeset
2601 free(ctx.script_env);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2602 rt_dispose(&ctx);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2603 free(ctx.duid);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2604 if (ctx.link_fd != -1) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2605 eloop_event_delete(ctx.eloop, ctx.link_fd);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2606 close(ctx.link_fd);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2607 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2608 if_closesockets(&ctx);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2609 free_globals(&ctx);
4351
b7a9f2b43d50 IP6ND: Remove #defines for functions when INET6 is disabled
Roy Marples <roy@marples.name>
parents: 4349
diff changeset
2610 #ifdef INET6
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2611 ipv6_ctxfree(&ctx);
4351
b7a9f2b43d50 IP6ND: Remove #defines for functions when INET6 is disabled
Roy Marples <roy@marples.name>
parents: 4349
diff changeset
2612 #endif
5262
f168a25dd330 privsep: Fix compile for prior without dev plugins
Roy Marples <roy@marples.name>
parents: 5260
diff changeset
2613 #ifdef PLUGIN_DEV
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2614 dev_stop(&ctx);
5262
f168a25dd330 privsep: Fix compile for prior without dev plugins
Roy Marples <roy@marples.name>
parents: 5260
diff changeset
2615 #endif
4851
b615d58905ad privsep: Use another eloop instead of a blocking read.
Roy Marples <roy@marples.name>
parents: 4850
diff changeset
2616 #ifdef PRIVSEP
b615d58905ad privsep: Use another eloop instead of a blocking read.
Roy Marples <roy@marples.name>
parents: 4850
diff changeset
2617 eloop_free(ctx.ps_eloop);
b615d58905ad privsep: Use another eloop instead of a blocking read.
Roy Marples <roy@marples.name>
parents: 4850
diff changeset
2618 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2619 eloop_free(ctx.eloop);
5255
ee23398a68db dhcpcd: Move the script file from per interface to global context
Roy Marples <roy@marples.name>
parents: 5252
diff changeset
2620 if (ctx.script != dhcpcd_default_script)
ee23398a68db dhcpcd: Move the script file from per interface to global context
Roy Marples <roy@marples.name>
parents: 5252
diff changeset
2621 free(ctx.script);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2622 if (ctx.options & DHCPCD_STARTED && !(ctx.options & DHCPCD_FORKED))
4024
0984f93d896e To be consitent, do the same to loginfo as we just did for logdebug.
Roy Marples <roy@marples.name>
parents: 4023
diff changeset
2623 loginfox(PACKAGE " exited");
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 4008
diff changeset
2624 logclose();
4027
afec1b835c80 Free logfile.
Roy Marples <roy@marples.name>
parents: 4024
diff changeset
2625 free(ctx.logfile);
5328
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
2626 free(ctx.ctl_buf);
4767
bc57b9b804a8 compat: Go back to linux specific setproctitle
Roy Marples <roy@marples.name>
parents: 4766
diff changeset
2627 #ifdef SETPROCTITLE_H
5507
78f2fda6ee5d compat: Use libbsd's setproctitle(3)
Roy Marples <roy@marples.name>
parents: 5503
diff changeset
2628 setproctitle_fini();
4767
bc57b9b804a8 compat: Go back to linux specific setproctitle
Roy Marples <roy@marples.name>
parents: 4766
diff changeset
2629 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2630 #ifdef USE_SIGNALS
5470
d7a5671d08c5 privsep: Don't remove pidfile at exit
Roy Marples <roy@marples.name>
parents: 5467
diff changeset
2631 if (ctx.options & DHCPCD_STARTED) {
4856
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2632 /* Try to detach from the launch process. */
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2633 if (ctx.fork_fd != -1 &&
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2634 write(ctx.fork_fd, &i, sizeof(i)) == -1)
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2635 logerr("%s: write", __func__);
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2636 }
5470
d7a5671d08c5 privsep: Don't remove pidfile at exit
Roy Marples <roy@marples.name>
parents: 5467
diff changeset
2637 if (ctx.options & DHCPCD_FORKED || oi != 0)
d7a5671d08c5 privsep: Don't remove pidfile at exit
Roy Marples <roy@marples.name>
parents: 5467
diff changeset
2638 _exit(i); /* so atexit won't remove our pidfile */
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2639 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2640 return i;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2641 }