annotate src/dhcpcd.c @ 5525:26b5d9bc2985 draft

privsep: Send all log messages to the privileged actioneer If dhcpcd starts and no syslogd implementation is running then various syscall filters could be triggered when dhcpcd wants to syslog and it's already in a chroot. Not all libc openlog implementations support LOG_NDELAY and openlog does not return an error code and can also mask errno back to 0. So we have no way of knowing if we have a syslog connection or not. This means we cannot cache the connection at startup because syslog itself will try and open if no connection. As such, all logging is now directed to the dhcpcd privileged actioneer process which will handle all the syslog and log file writing actions. The only downside of this approach (other than an extra fd per process) is that we no longer know which PID raised the message. While we could put the correct PID in the logfile as we control the API, we cannot put it into syslog as we cannot control that API. As all privsep errors should log which function they came from this will hopefully not be an issue as on the happy path only the master process will log stuff.
author Roy Marples <roy@marples.name>
date Fri, 30 Oct 2020 03:43:51 +0000
parents 618c0ef1bae8
children b1a3d9055662
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
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
698 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
699 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
700 {
5499
6a2da5651841 dhcpcd: Simplify the link handling even more
Roy Marples <roy@marples.name>
parents: 5497
diff changeset
701 bool was_link_up = 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
702
5499
6a2da5651841 dhcpcd: Simplify the link handling even more
Roy Marples <roy@marples.name>
parents: 5497
diff changeset
703 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
704 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
705
5499
6a2da5651841 dhcpcd: Simplify the link handling even more
Roy Marples <roy@marples.name>
parents: 5497
diff changeset
706 if (!if_is_link_up(ifp)) {
6a2da5651841 dhcpcd: Simplify the link handling even more
Roy Marples <roy@marples.name>
parents: 5497
diff changeset
707 if (!was_link_up || !ifp->active)
5497
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
708 return;
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
709 loginfox("%s: carrier lost", ifp->name);
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
710 script_runreason(ifp, "NOCARRIER");
4355
226e00ec9457 link: introduce LINK_DOWN_IFFUP
Roy Marples <roy@marples.name>
parents: 4351
diff changeset
711 #ifdef NOCARRIER_PRESERVE_IP
5497
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
712 if (ifp->flags & IFF_UP &&
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
713 !(ifp->options->options & DHCPCD_ANONYMOUS))
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
714 {
4135
64796240ee75 arp: RFC5227 kernels need to send ARP too
Roy Marples <roy@marples.name>
parents: 4132
diff changeset
715 #ifdef ARP
5497
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
716 arp_drop(ifp);
4135
64796240ee75 arp: RFC5227 kernels need to send ARP too
Roy Marples <roy@marples.name>
parents: 4132
diff changeset
717 #endif
4347
fb677abacc16 DHCP: Remove #defines for functions when INET is disabled
Roy Marples <roy@marples.name>
parents: 4346
diff changeset
718 #ifdef INET
5497
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
719 dhcp_abort(ifp);
4347
fb677abacc16 DHCP: Remove #defines for functions when INET is disabled
Roy Marples <roy@marples.name>
parents: 4346
diff changeset
720 #endif
4349
f87c2ed9ff46 DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents: 4348
diff changeset
721 #ifdef DHCP6
5497
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
722 dhcp6_abort(ifp);
4349
f87c2ed9ff46 DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents: 4348
diff changeset
723 #endif
5497
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
724 } else
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
725 #endif
5497
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
726 dhcpcd_drop(ifp, 0);
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
727 if (ifp->options->options & DHCPCD_ANONYMOUS) {
5499
6a2da5651841 dhcpcd: Simplify the link handling even more
Roy Marples <roy@marples.name>
parents: 5497
diff changeset
728 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
729
5499
6a2da5651841 dhcpcd: Simplify the link handling even more
Roy Marples <roy@marples.name>
parents: 5497
diff changeset
730 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
731 if_down(ifp);
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
732 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
733 logerr(__func__);
5499
6a2da5651841 dhcpcd: Simplify the link handling even more
Roy Marples <roy@marples.name>
parents: 5497
diff changeset
734 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
735 if_up(ifp);
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
736 }
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
737 return;
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
738 }
5005
ffb5b2280ed2 dhcpcd: For anonymous do not bring interface up if was down
Roy Marples <roy@marples.name>
parents: 4997
diff changeset
739
5497
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
740 /*
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
741 * 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
742 * 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
743 * link state changes.
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
744 * 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
745 * 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
746 */
5499
6a2da5651841 dhcpcd: Simplify the link handling even more
Roy Marples <roy@marples.name>
parents: 5497
diff changeset
747 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
748 return;
5499
6a2da5651841 dhcpcd: Simplify the link handling even more
Roy Marples <roy@marples.name>
parents: 5497
diff changeset
749
5497
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
750 if (ifp->active) {
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
751 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
752 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
753 else
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
754 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
755 }
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
756
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
757 #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
758 /* 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
759 * 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
760 * 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
761 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
762 #endif
5497
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
763
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
764 if (ifp->wireless) {
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
765 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
766 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
767
5497
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
768 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
769 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
770 if_getssid(ifp);
4341
990fde22c376 IPv4LL: Preserve address when carrier drops
Roy Marples <roy@marples.name>
parents: 4335
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 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
773 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
774 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
775 {
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
776 dhcpcd_reportssid(ifp);
4341
990fde22c376 IPv4LL: Preserve address when carrier drops
Roy Marples <roy@marples.name>
parents: 4335
diff changeset
777 #ifdef NOCARRIER_PRESERVE_IP
5497
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
778 dhcpcd_drop(ifp, 0);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
779 #endif
4345
b9694106b686 IPv4LL: Fix build if not enabled.
Roy Marples <roy@marples.name>
parents: 4342
diff changeset
780 #ifdef IPV4LL
5497
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
781 ipv4ll_reset(ifp);
4345
b9694106b686 IPv4LL: Fix build if not enabled.
Roy Marples <roy@marples.name>
parents: 4342
diff changeset
782 #endif
5497
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
783 }
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
784 }
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
785
5499
6a2da5651841 dhcpcd: Simplify the link handling even more
Roy Marples <roy@marples.name>
parents: 5497
diff changeset
786 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
787 return;
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
788
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
789 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
790 script_runreason(ifp, "CARRIER");
4351
b7a9f2b43d50 IP6ND: Remove #defines for functions when INET6 is disabled
Roy Marples <roy@marples.name>
parents: 4349
diff changeset
791 #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
792 #ifdef NOCARRIER_PRESERVE_IP
5497
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
793 /* 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
794 * 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
795 ipv6nd_startexpire(ifp);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
796 #endif
5128
d4668acf8d76 Fix build on Linux
Roy Marples <roy@marples.name>
parents: 5127
diff changeset
797 #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
798 /* 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
799 ipv6_regentempaddrs(ifp);
4351
b7a9f2b43d50 IP6ND: Remove #defines for functions when INET6 is disabled
Roy Marples <roy@marples.name>
parents: 4349
diff changeset
800 #endif
5128
d4668acf8d76 Fix build on Linux
Roy Marples <roy@marples.name>
parents: 5127
diff changeset
801 #endif
5497
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
802 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
803 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
804
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
805 static void
4279
cdffb0137daa dhcp6: IAID is now unique for IA type
Roy Marples <roy@marples.name>
parents: 4250
diff changeset
806 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
807 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
808 struct interface *ifn;
4285
92c215d75a0c Fix compile without INET6
Roy Marples <roy@marples.name>
parents: 4279
diff changeset
809 #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
810 size_t i;
4279
cdffb0137daa dhcp6: IAID is now unique for IA type
Roy Marples <roy@marples.name>
parents: 4250
diff changeset
811 struct if_ia *ia;
4285
92c215d75a0c Fix compile without INET6
Roy Marples <roy@marples.name>
parents: 4279
diff changeset
812 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
813
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
814 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
815 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
816 continue;
4965
78a1e76b04bd dhcpcd: Don't report DUID or IAID in anonymous.
Roy Marples <roy@marples.name>
parents: 4959
diff changeset
817 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
818 continue;
4279
cdffb0137daa dhcp6: IAID is now unique for IA type
Roy Marples <roy@marples.name>
parents: 4250
diff changeset
819 if (ia_type == 0 &&
cdffb0137daa dhcp6: IAID is now unique for IA type
Roy Marples <roy@marples.name>
parents: 4250
diff changeset
820 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
821 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
822 break;
4285
92c215d75a0c Fix compile without INET6
Roy Marples <roy@marples.name>
parents: 4279
diff changeset
823 #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
824 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
825 ia = &ifn->options->ia[i];
cdffb0137daa dhcp6: IAID is now unique for IA type
Roy Marples <roy@marples.name>
parents: 4250
diff changeset
826 if (ia->ia_type == ia_type &&
cdffb0137daa dhcp6: IAID is now unique for IA type
Roy Marples <roy@marples.name>
parents: 4250
diff changeset
827 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
828 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
829 }
4285
92c215d75a0c Fix compile without INET6
Roy Marples <roy@marples.name>
parents: 4279
diff changeset
830 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
831 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
832
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
833 /* 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
834 if (ifn)
4050
b3337611d1b1 Don't report a real error here.
Roy Marples <roy@marples.name>
parents: 4047
diff changeset
835 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
836 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
837 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
838
5207
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
839 static void
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
840 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
841 {
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
842 char buf[DUID_LEN * 3];
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
843
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
844 if (ctx->duid != NULL)
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
845 return;
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
846
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
847 duid_init(ctx, ifp);
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
848 if (ctx->duid == NULL)
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
849 return;
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
850
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
851 loginfox("DUID %s",
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
852 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
853 }
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
854
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
855 void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
856 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
857 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
858 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
859 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
860
5499
6a2da5651841 dhcpcd: Simplify the link handling even more
Roy Marples <roy@marples.name>
parents: 5497
diff changeset
861 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
862 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
863 return;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
864 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
865
4965
78a1e76b04bd dhcpcd: Don't report DUID or IAID in anonymous.
Roy Marples <roy@marples.name>
parents: 4959
diff changeset
866 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
867 !(ifo->options & DHCPCD_ANONYMOUS))
78a1e76b04bd dhcpcd: Don't report DUID or IAID in anonymous.
Roy Marples <roy@marples.name>
parents: 4959
diff changeset
868 {
5207
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
869 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
870 #ifdef INET6
78a1e76b04bd dhcpcd: Don't report DUID or IAID in anonymous.
Roy Marples <roy@marples.name>
parents: 4959
diff changeset
871 size_t i;
78a1e76b04bd dhcpcd: Don't report DUID or IAID in anonymous.
Roy Marples <roy@marples.name>
parents: 4959
diff changeset
872 struct if_ia *ia;
78a1e76b04bd dhcpcd: Don't report DUID or IAID in anonymous.
Roy Marples <roy@marples.name>
parents: 4959
diff changeset
873 #endif
78a1e76b04bd dhcpcd: Don't report DUID or IAID in anonymous.
Roy Marples <roy@marples.name>
parents: 4959
diff changeset
874
5207
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
875 /* 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
876 dhcpcd_initduid(ifp->ctx, ifp);
4279
cdffb0137daa dhcp6: IAID is now unique for IA type
Roy Marples <roy@marples.name>
parents: 4250
diff changeset
877
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
878 /* 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
879 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
880 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
881 buf, sizeof(buf)));
4279
cdffb0137daa dhcp6: IAID is now unique for IA type
Roy Marples <roy@marples.name>
parents: 4250
diff changeset
882 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
883
4285
92c215d75a0c Fix compile without INET6
Roy Marples <roy@marples.name>
parents: 4279
diff changeset
884 #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
885 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
886 ia = &ifo->ia[i];
cdffb0137daa dhcp6: IAID is now unique for IA type
Roy Marples <roy@marples.name>
parents: 4250
diff changeset
887 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
888 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
889 ifp->name, ia->ia_type,
cdffb0137daa dhcp6: IAID is now unique for IA type
Roy Marples <roy@marples.name>
parents: 4250
diff changeset
890 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
891 buf, sizeof(buf)));
4279
cdffb0137daa dhcp6: IAID is now unique for IA type
Roy Marples <roy@marples.name>
parents: 4250
diff changeset
892 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
893 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
894 }
4285
92c215d75a0c Fix compile without INET6
Roy Marples <roy@marples.name>
parents: 4279
diff changeset
895 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
896 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
897
4351
b7a9f2b43d50 IP6ND: Remove #defines for functions when INET6 is disabled
Roy Marples <roy@marples.name>
parents: 4349
diff changeset
898 #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
899 if (ifo->options & DHCPCD_IPV6 && ipv6_start(ifp) == -1) {
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 4008
diff changeset
900 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
901 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
902 }
4351
b7a9f2b43d50 IP6ND: Remove #defines for functions when INET6 is disabled
Roy Marples <roy@marples.name>
parents: 4349
diff changeset
903
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
904 if (ifo->options & DHCPCD_IPV6) {
4111
2e9728768a4b dhcpcd starts inactive interfaces erroneously.
Roy Marples <roy@marples.name>
parents: 4076
diff changeset
905 if (ifp->active == IF_ACTIVE_USER) {
2e9728768a4b dhcpcd starts inactive interfaces erroneously.
Roy Marples <roy@marples.name>
parents: 4076
diff changeset
906 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
907
4111
2e9728768a4b dhcpcd starts inactive interfaces erroneously.
Roy Marples <roy@marples.name>
parents: 4076
diff changeset
908 if (ifo->options & DHCPCD_IPV6RS)
2e9728768a4b dhcpcd starts inactive interfaces erroneously.
Roy Marples <roy@marples.name>
parents: 4076
diff changeset
909 ipv6nd_startrs(ifp);
2e9728768a4b dhcpcd starts inactive interfaces erroneously.
Roy Marples <roy@marples.name>
parents: 4076
diff changeset
910 }
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
911
4349
f87c2ed9ff46 DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents: 4348
diff changeset
912 #ifdef DHCP6
5343
8b216a105409 DHCP6: Apply delegations to interface on carrier up
Roy Marples <roy@marples.name>
parents: 5331
diff changeset
913 /* 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
914 * is still delegated to. */
8b216a105409 DHCP6: Apply delegations to interface on carrier up
Roy Marples <roy@marples.name>
parents: 5331
diff changeset
915 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
916 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
917
5343
8b216a105409 DHCP6: Apply delegations to interface on carrier up
Roy Marples <roy@marples.name>
parents: 5331
diff changeset
918 if (ifo->options & DHCPCD_DHCP6) {
4183
115cbfa711e2 DHCPv6: confirm lease on carrier up
Roy Marples <roy@marples.name>
parents: 4135
diff changeset
919 if (ifp->active == IF_ACTIVE_USER) {
115cbfa711e2 DHCPv6: confirm lease on carrier up
Roy Marples <roy@marples.name>
parents: 4135
diff changeset
920 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
921
4183
115cbfa711e2 DHCPv6: confirm lease on carrier up
Roy Marples <roy@marples.name>
parents: 4135
diff changeset
922 if (ifo->options & DHCPCD_IA_FORCED)
115cbfa711e2 DHCPv6: confirm lease on carrier up
Roy Marples <roy@marples.name>
parents: 4135
diff changeset
923 d6_state = DH6S_INIT;
115cbfa711e2 DHCPv6: confirm lease on carrier up
Roy Marples <roy@marples.name>
parents: 4135
diff changeset
924 else if (ifo->options & DHCPCD_INFORM6)
115cbfa711e2 DHCPv6: confirm lease on carrier up
Roy Marples <roy@marples.name>
parents: 4135
diff changeset
925 d6_state = DH6S_INFORM;
115cbfa711e2 DHCPv6: confirm lease on carrier up
Roy Marples <roy@marples.name>
parents: 4135
diff changeset
926 else
115cbfa711e2 DHCPv6: confirm lease on carrier up
Roy Marples <roy@marples.name>
parents: 4135
diff changeset
927 d6_state = DH6S_CONFIRM;
115cbfa711e2 DHCPv6: confirm lease on carrier up
Roy Marples <roy@marples.name>
parents: 4135
diff changeset
928 if (dhcp6_start(ifp, d6_state) == -1)
115cbfa711e2 DHCPv6: confirm lease on carrier up
Roy Marples <roy@marples.name>
parents: 4135
diff changeset
929 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
930 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
931 }
4349
f87c2ed9ff46 DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents: 4348
diff changeset
932 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
933 }
4351
b7a9f2b43d50 IP6ND: Remove #defines for functions when INET6 is disabled
Roy Marples <roy@marples.name>
parents: 4349
diff changeset
934 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
935
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
936 #ifdef INET
4111
2e9728768a4b dhcpcd starts inactive interfaces erroneously.
Roy Marples <roy@marples.name>
parents: 4076
diff changeset
937 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
938 /* 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
939 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
940 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
941 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
942 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
943 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
944
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
945 static void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
946 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
947 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
948 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
949 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
950 bool anondown;
db92f78f92b4 dhcpcd: randomise hardware address on start if no carrier
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
951
5497
2737c3236e66 dhcpcd: Simplify carrier handling more by using IS_LINK_UP macro
Roy Marples <roy@marples.name>
parents: 5494
diff changeset
952 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
953 ifp->options->options & DHCPCD_ANONYMOUS &&
db92f78f92b4 dhcpcd: randomise hardware address on start if no carrier
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
954 ifp->flags & IFF_UP)
db92f78f92b4 dhcpcd: randomise hardware address on start if no carrier
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
955 {
db92f78f92b4 dhcpcd: randomise hardware address on start if no carrier
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
956 if_down(ifp);
db92f78f92b4 dhcpcd: randomise hardware address on start if no carrier
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
957 anondown = true;
db92f78f92b4 dhcpcd: randomise hardware address on start if no carrier
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
958 } else
db92f78f92b4 dhcpcd: randomise hardware address on start if no carrier
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
959 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
960
5376
66bbeeebbe92 dhcpcd: Add an option to poll the interface carrier state
Roy Marples <roy@marples.name>
parents: 5373
diff changeset
961 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
962 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
963 !(ifp->flags & IFF_UP))
4958
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4955
diff changeset
964 {
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4955
diff changeset
965 if (ifp->options->options & DHCPCD_ANONYMOUS &&
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4955
diff changeset
966 if_randomisemac(ifp) == -1)
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4955
diff changeset
967 logerr(__func__);
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4955
diff changeset
968 if (if_up(ifp) == -1)
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4955
diff changeset
969 logerr(__func__);
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4955
diff changeset
970 }
3932
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 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
973 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
974
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
975 static void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
976 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
977 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
978
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
979 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
980 return;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
981
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
982 script_runreason(ifp, "PREINIT");
5499
6a2da5651841 dhcpcd: Simplify the link handling even more
Roy Marples <roy@marples.name>
parents: 5497
diff changeset
983 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
984 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
985 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
986 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
987 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
988 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
989
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
990 void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
991 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
992 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
993
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
994 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
995 ifp->active = IF_ACTIVE;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
996 dhcpcd_initstate2(ifp, options);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
997 /* It's possible we might not have been able to load
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
998 * a config. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
999 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
1000 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
1001 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
1002 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
1003 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1004 }
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
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1007 int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1008 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
1009 {
5490
df4ea0197ce8 BSD: Fix compile for non NetBSD
Roy Marples <roy@marples.name>
parents: 5486
diff changeset
1010 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
1011 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
1012 struct if_head *ifs;
4205
bf0ca777e4fa dhcp: don't loop needlessly when handling an interface
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1013 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
1014 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
1015 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
1016
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1017 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
1018 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
1019 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
1020 errno = ESRCH;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1021 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1022 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1023 if (ifp->active) {
4023
66f9399ba5c6 Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents: 4021
diff changeset
1024 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
1025 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
1026 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1027 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
1028 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
1029 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1030 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1031
4189
0b088d803b61 dhcp6: don't listen on IPv6 addresses when not using DHCP6
Roy Marples <roy@marples.name>
parents: 4184
diff changeset
1032 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
1033 if (ifs == NULL) {
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 4008
diff changeset
1034 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
1035 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1036 }
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
1037
4205
bf0ca777e4fa dhcp: don't loop needlessly when handling an interface
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1038 ifp = if_find(ifs, ifname);
bf0ca777e4fa dhcp: don't loop needlessly when handling an interface
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1039 if (ifp == NULL) {
bf0ca777e4fa dhcp: don't loop needlessly when handling an interface
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1040 /* 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
1041 * and then removed. */
bf0ca777e4fa dhcp: don't loop needlessly when handling an interface
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1042 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
1043 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
1044 goto out;
4205
bf0ca777e4fa dhcp: don't loop needlessly when handling an interface
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1045 }
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
1046 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
1047
4205
bf0ca777e4fa dhcp: don't loop needlessly when handling an interface
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1048 /* 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
1049 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
1050
4205
bf0ca777e4fa dhcp: don't loop needlessly when handling an interface
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1051 if (iff != NULL) {
bf0ca777e4fa dhcp: don't loop needlessly when handling an interface
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1052 if (iff->active)
bf0ca777e4fa dhcp: don't loop needlessly when handling an interface
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1053 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
1054 /* 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
1055 iff->flags = ifp->flags;
bf0ca777e4fa dhcp: don't loop needlessly when handling an interface
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1056 iff->hwlen = ifp->hwlen;
bf0ca777e4fa dhcp: don't loop needlessly when handling an interface
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1057 if (ifp->hwlen != 0)
bf0ca777e4fa dhcp: don't loop needlessly when handling an interface
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1058 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
1059 } else {
bf0ca777e4fa dhcp: don't loop needlessly when handling an interface
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1060 TAILQ_REMOVE(ifs, ifp, next);
bf0ca777e4fa dhcp: don't loop needlessly when handling an interface
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1061 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
1062 if (ifp->active) {
4023
66f9399ba5c6 Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents: 4021
diff changeset
1063 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
1064 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
1065 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
1066 }
4205
bf0ca777e4fa dhcp: don't loop needlessly when handling an interface
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1067 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
1068 }
4246
687273d5849d BSD: fix segfault when on carrier when IPv6 addresses are present
Roy Marples <roy@marples.name>
parents: 4239
diff changeset
1069
687273d5849d BSD: fix segfault when on carrier when IPv6 addresses are present
Roy Marples <roy@marples.name>
parents: 4239
diff changeset
1070 if (action > 0) {
687273d5849d BSD: fix segfault when on carrier when IPv6 addresses are present
Roy Marples <roy@marples.name>
parents: 4239
diff changeset
1071 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
1072 if (iff->active)
687273d5849d BSD: fix segfault when on carrier when IPv6 addresses are present
Roy Marples <roy@marples.name>
parents: 4239
diff changeset
1073 dhcpcd_prestartinterface(iff);
687273d5849d BSD: fix segfault when on carrier when IPv6 addresses are present
Roy Marples <roy@marples.name>
parents: 4239
diff changeset
1074 }
4189
0b088d803b61 dhcp6: don't listen on IPv6 addresses when not using DHCP6
Roy Marples <roy@marples.name>
parents: 4184
diff changeset
1075
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
1076 out:
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1077 /* 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
1078 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
1079 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
1080 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
1081 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1082 free(ifs);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1083
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
1084 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
1085 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1086
4235
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1087 static void
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1088 dhcpcd_handlelink(void *arg)
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1089 {
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1090 struct dhcpcd_ctx *ctx = arg;
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1091
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1092 if (if_handlelink(ctx) == -1) {
4236
f6be46401658 Test for ENOMEM as well.
Roy Marples <roy@marples.name>
parents: 4235
diff changeset
1093 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
1094 dhcpcd_linkoverflow(ctx);
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1095 return;
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1096 }
4503
9784c3171a22 BSD: Ignore coverity errors
Roy Marples <roy@marples.name>
parents: 4498
diff changeset
1097 if (errno != ENOTSUP)
9784c3171a22 BSD: Ignore coverity errors
Roy Marples <roy@marples.name>
parents: 4498
diff changeset
1098 logerr(__func__);
4235
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1099 }
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1100 }
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1101
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1102 static void
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1103 dhcpcd_checkcarrier(void *arg)
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1104 {
5486
8e2b8ce8c972 BSD: struct if_data->ifi_link_state is the single source of truth
Roy Marples <roy@marples.name>
parents: 5484
diff changeset
1105 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
1106
5486
8e2b8ce8c972 BSD: struct if_data->ifi_link_state is the single source of truth
Roy Marples <roy@marples.name>
parents: 5484
diff changeset
1107 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
1108 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
1109 return;
8e2b8ce8c972 BSD: struct if_data->ifi_link_state is the single source of truth
Roy Marples <roy@marples.name>
parents: 5484
diff changeset
1110
8e2b8ce8c972 BSD: struct if_data->ifi_link_state is the single source of truth
Roy Marples <roy@marples.name>
parents: 5484
diff changeset
1111 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
1112 if_free(ifp0);
4235
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1113 }
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1114
4415
4eb8ce6f854c options: add link_rcvbuf variable
Roy Marples <roy@marples.name>
parents: 4394
diff changeset
1115 #ifndef SMALL
4eb8ce6f854c options: add link_rcvbuf variable
Roy Marples <roy@marples.name>
parents: 4394
diff changeset
1116 static void
4eb8ce6f854c options: add link_rcvbuf variable
Roy Marples <roy@marples.name>
parents: 4394
diff changeset
1117 dhcpcd_setlinkrcvbuf(struct dhcpcd_ctx *ctx)
4eb8ce6f854c options: add link_rcvbuf variable
Roy Marples <roy@marples.name>
parents: 4394
diff changeset
1118 {
4eb8ce6f854c options: add link_rcvbuf variable
Roy Marples <roy@marples.name>
parents: 4394
diff changeset
1119 socklen_t socklen;
4eb8ce6f854c options: add link_rcvbuf variable
Roy Marples <roy@marples.name>
parents: 4394
diff changeset
1120
4eb8ce6f854c options: add link_rcvbuf variable
Roy Marples <roy@marples.name>
parents: 4394
diff changeset
1121 if (ctx->link_rcvbuf == 0)
4eb8ce6f854c options: add link_rcvbuf variable
Roy Marples <roy@marples.name>
parents: 4394
diff changeset
1122 return;
4eb8ce6f854c options: add link_rcvbuf variable
Roy Marples <roy@marples.name>
parents: 4394
diff changeset
1123
5008
28209b094c6c dhcpcd: report how large a route rocket receive buffer size we set
Roy Marples <roy@marples.name>
parents: 5007
diff changeset
1124 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
1125 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
1126
4415
4eb8ce6f854c options: add link_rcvbuf variable
Roy Marples <roy@marples.name>
parents: 4394
diff changeset
1127 socklen = sizeof(ctx->link_rcvbuf);
4eb8ce6f854c options: add link_rcvbuf variable
Roy Marples <roy@marples.name>
parents: 4394
diff changeset
1128 if (setsockopt(ctx->link_fd, SOL_SOCKET,
4eb8ce6f854c options: add link_rcvbuf variable
Roy Marples <roy@marples.name>
parents: 4394
diff changeset
1129 SO_RCVBUF, &ctx->link_rcvbuf, socklen) == -1)
4eb8ce6f854c options: add link_rcvbuf variable
Roy Marples <roy@marples.name>
parents: 4394
diff changeset
1130 logerr(__func__);
4eb8ce6f854c options: add link_rcvbuf variable
Roy Marples <roy@marples.name>
parents: 4394
diff changeset
1131 }
4eb8ce6f854c options: add link_rcvbuf variable
Roy Marples <roy@marples.name>
parents: 4394
diff changeset
1132 #endif
4eb8ce6f854c options: add link_rcvbuf variable
Roy Marples <roy@marples.name>
parents: 4394
diff changeset
1133
5427
f6d641a87e0a dhcpcd: init new interfaces from route(4) overflow
Roy Marples <roy@marples.name>
parents: 5419
diff changeset
1134 static void
5431
f8d95f002758 dhcpcd: Rename function for prior now it no longer inits
Roy Marples <roy@marples.name>
parents: 5430
diff changeset
1135 dhcpcd_runprestartinterface(void *arg)
5427
f6d641a87e0a dhcpcd: init new interfaces from route(4) overflow
Roy Marples <roy@marples.name>
parents: 5419
diff changeset
1136 {
f6d641a87e0a dhcpcd: init new interfaces from route(4) overflow
Roy Marples <roy@marples.name>
parents: 5419
diff changeset
1137 struct interface *ifp = arg;
f6d641a87e0a dhcpcd: init new interfaces from route(4) overflow
Roy Marples <roy@marples.name>
parents: 5419
diff changeset
1138
f6d641a87e0a dhcpcd: init new interfaces from route(4) overflow
Roy Marples <roy@marples.name>
parents: 5419
diff changeset
1139 run_preinit(ifp);
f6d641a87e0a dhcpcd: init new interfaces from route(4) overflow
Roy Marples <roy@marples.name>
parents: 5419
diff changeset
1140 dhcpcd_prestartinterface(ifp);
f6d641a87e0a dhcpcd: init new interfaces from route(4) overflow
Roy Marples <roy@marples.name>
parents: 5419
diff changeset
1141 }
f6d641a87e0a dhcpcd: init new interfaces from route(4) overflow
Roy Marples <roy@marples.name>
parents: 5419
diff changeset
1142
4235
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1143 void
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1144 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
1145 {
5007
a5d64cd4b391 dhcpcd: When route socket overflows, report how large it is.
Roy Marples <roy@marples.name>
parents: 5005
diff changeset
1146 socklen_t socklen;
a5d64cd4b391 dhcpcd: When route socket overflows, report how large it is.
Roy Marples <roy@marples.name>
parents: 5005
diff changeset
1147 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
1148 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
1149 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
1150 size_t rcnt;
4235
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1151 struct if_head *ifaces;
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1152 struct ifaddrs *ifaddrs;
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1153 struct interface *ifp, *ifn, *ifp1;
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1154
5007
a5d64cd4b391 dhcpcd: When route socket overflows, report how large it is.
Roy Marples <roy@marples.name>
parents: 5005
diff changeset
1155 socklen = sizeof(rcvbuflen);
a5d64cd4b391 dhcpcd: When route socket overflows, report how large it is.
Roy Marples <roy@marples.name>
parents: 5005
diff changeset
1156 if (getsockopt(ctx->link_fd, SOL_SOCKET,
a5d64cd4b391 dhcpcd: When route socket overflows, report how large it is.
Roy Marples <roy@marples.name>
parents: 5005
diff changeset
1157 SO_RCVBUF, &rcvbuflen, &socklen) == -1)
a5d64cd4b391 dhcpcd: When route socket overflows, report how large it is.
Roy Marples <roy@marples.name>
parents: 5005
diff changeset
1158 rcvbuflen = 0;
a5d64cd4b391 dhcpcd: When route socket overflows, report how large it is.
Roy Marples <roy@marples.name>
parents: 5005
diff changeset
1159 #ifdef __linux__
a5d64cd4b391 dhcpcd: When route socket overflows, report how large it is.
Roy Marples <roy@marples.name>
parents: 5005
diff changeset
1160 else
a5d64cd4b391 dhcpcd: When route socket overflows, report how large it is.
Roy Marples <roy@marples.name>
parents: 5005
diff changeset
1161 rcvbuflen /= 2;
a5d64cd4b391 dhcpcd: When route socket overflows, report how large it is.
Roy Marples <roy@marples.name>
parents: 5005
diff changeset
1162 #endif
a5d64cd4b391 dhcpcd: When route socket overflows, report how large it is.
Roy Marples <roy@marples.name>
parents: 5005
diff changeset
1163
a5d64cd4b391 dhcpcd: When route socket overflows, report how large it is.
Roy Marples <roy@marples.name>
parents: 5005
diff changeset
1164 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
1165 " - learning interface state", rcvbuflen);
4235
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1166
5282
8afafcabcfa5 privsep: Drain the link socket as we can't re-open it.
Roy Marples <roy@marples.name>
parents: 5281
diff changeset
1167 /* 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
1168 * 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
1169 rcnt = 0;
8afafcabcfa5 privsep: Drain the link socket as we can't re-open it.
Roy Marples <roy@marples.name>
parents: 5281
diff changeset
1170 do {
8afafcabcfa5 privsep: Drain the link socket as we can't re-open it.
Roy Marples <roy@marples.name>
parents: 5281
diff changeset
1171 rlen = read(ctx->link_fd, buf, sizeof(buf));
5284
2b5f56e079b0 route: improve overflow logging
Roy Marples <roy@marples.name>
parents: 5282
diff changeset
1172 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
1173 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
1174 } while (rlen != -1 || errno == ENOBUFS || errno == ENOMEM);
5284
2b5f56e079b0 route: improve overflow logging
Roy Marples <roy@marples.name>
parents: 5282
diff changeset
1175 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
1176 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
1177
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1178 /* Work out the current interfaces. */
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1179 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
1180 if (ifaces == NULL) {
6baf24a8cc49 dhcpcd: Don't leak memory when routing socket overflows
Roy Marples <roy@marples.name>
parents: 4549
diff changeset
1181 logerr(__func__);
6baf24a8cc49 dhcpcd: Don't leak memory when routing socket overflows
Roy Marples <roy@marples.name>
parents: 4549
diff changeset
1182 return;
6baf24a8cc49 dhcpcd: Don't leak memory when routing socket overflows
Roy Marples <roy@marples.name>
parents: 4549
diff changeset
1183 }
4235
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1184
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1185 /* Punt departed interfaces */
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1186 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
1187 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
1188 continue;
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1189 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
1190 }
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1191
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1192 /* Add new interfaces */
4570
6baf24a8cc49 dhcpcd: Don't leak memory when routing socket overflows
Roy Marples <roy@marples.name>
parents: 4549
diff changeset
1193 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
1194 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
1195 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
1196 if (ifp1 != NULL) {
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1197 /* 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
1198 * 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
1199 * 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
1200 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
1201 dhcpcd_checkcarrier, ifp);
4235
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1202 continue;
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1203 }
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1204 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
1205 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
1206 dhcpcd_initstate(ifp, 0);
4235
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1207 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
1208 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
1209 }
4235
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1210 }
4570
6baf24a8cc49 dhcpcd: Don't leak memory when routing socket overflows
Roy Marples <roy@marples.name>
parents: 4549
diff changeset
1211 free(ifaces);
4235
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1212
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1213 /* Update address state. */
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1214 if_markaddrsstale(ctx->ifaces);
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1215 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
1216 if_deletestaleaddrs(ctx->ifaces);
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1217 }
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4226
diff changeset
1218
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1219 void
5168
1f5dc6102f9b if: support changing hardware address type on Linux
Roy Marples <roy@marples.name>
parents: 5148
diff changeset
1220 dhcpcd_handlehwaddr(struct interface *ifp,
1f5dc6102f9b if: support changing hardware address type on Linux
Roy Marples <roy@marples.name>
parents: 5148
diff changeset
1221 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
1222 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1223 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
1224
5168
1f5dc6102f9b if: support changing hardware address type on Linux
Roy Marples <roy@marples.name>
parents: 5148
diff changeset
1225 if (hwaddr == NULL || !if_valid_hwaddr(hwaddr, hwlen))
4076
9433864aa014 Hardware Address validation
Roy Marples <roy@marples.name>
parents: 4075
diff changeset
1226 hwlen = 0;
9433864aa014 Hardware Address validation
Roy Marples <roy@marples.name>
parents: 4075
diff changeset
1227
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1228 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
1229 errno = ENOBUFS;
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 4008
diff changeset
1230 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
1231 return;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1232 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1233
5168
1f5dc6102f9b if: support changing hardware address type on Linux
Roy Marples <roy@marples.name>
parents: 5148
diff changeset
1234 if (ifp->hwtype != hwtype) {
1f5dc6102f9b if: support changing hardware address type on Linux
Roy Marples <roy@marples.name>
parents: 5148
diff changeset
1235 loginfox("%s: hardware address type changed from %d to %d",
1f5dc6102f9b if: support changing hardware address type on Linux
Roy Marples <roy@marples.name>
parents: 5148
diff changeset
1236 ifp->name, ifp->hwtype, hwtype);
1f5dc6102f9b if: support changing hardware address type on Linux
Roy Marples <roy@marples.name>
parents: 5148
diff changeset
1237 ifp->hwtype = hwtype;
1f5dc6102f9b if: support changing hardware address type on Linux
Roy Marples <roy@marples.name>
parents: 5148
diff changeset
1238 }
1f5dc6102f9b if: support changing hardware address type on Linux
Roy Marples <roy@marples.name>
parents: 5148
diff changeset
1239
1f5dc6102f9b if: support changing hardware address type on Linux
Roy Marples <roy@marples.name>
parents: 5148
diff changeset
1240 if (ifp->hwlen == hwlen &&
1f5dc6102f9b if: support changing hardware address type on Linux
Roy Marples <roy@marples.name>
parents: 5148
diff changeset
1241 (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
1242 return;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1243
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
1244 loginfox("%s: new hardware address: %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
1245 hwaddr_ntoa(hwaddr, hwlen, buf, sizeof(buf)));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1246 ifp->hwlen = hwlen;
5280
a986083da0ba Fix some clang analyzer issues
Roy Marples <roy@marples.name>
parents: 5269
diff changeset
1247 if (hwaddr != NULL)
a986083da0ba Fix some clang analyzer issues
Roy Marples <roy@marples.name>
parents: 5269
diff changeset
1248 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
1249 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1250
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1251 static void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1252 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
1253 {
4582
1accf1291b4b Fix build without INET.
Roy Marples <roy@marples.name>
parents: 4571
diff changeset
1254 #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
1255 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
1256
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1257 oldopts = ifp->options->options;
4582
1accf1291b4b Fix build without INET.
Roy Marples <roy@marples.name>
parents: 4571
diff changeset
1258 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1259 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
1260 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
1261 #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
1262 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
1263 #endif
4349
f87c2ed9ff46 DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents: 4348
diff changeset
1264 #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
1265 dhcp6_reboot(ifp);
4349
f87c2ed9ff46 DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents: 4348
diff changeset
1266 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1267 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
1268 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1269
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1270 static void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1271 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
1272 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1273 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
1274
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1275 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
1276 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
1277 return;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1278 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
1279 /* We need to preserve these options. */
086c01fecfca dhcpcd: preserve the STARTED option when reloading options
Roy Marples <roy@marples.name>
parents: 5365
diff changeset
1280 if (ctx->options & DHCPCD_STARTED)
086c01fecfca dhcpcd: preserve the STARTED option when reloading options
Roy Marples <roy@marples.name>
parents: 5365
diff changeset
1281 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
1282 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
1283 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
1284 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
1285 ifo->options |= DHCPCD_DAEMONISED;
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4836
diff changeset
1286 if (ctx->options & DHCPCD_PRIVSEP)
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4836
diff changeset
1287 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
1288 ctx->options = ifo->options;
4249
c30233f8cca3 routes: allow a head clear with a context
Roy Marples <roy@marples.name>
parents: 4246
diff changeset
1289 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
1290 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1291
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1292 static void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1293 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
1294 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1295 int i;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1296 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
1297
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1298 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
1299 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
1300 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
1301 break;
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 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
1304 continue;
4075
5dca392a6e39 Only reboot activated user interfaces.
Roy Marples <roy@marples.name>
parents: 4072
diff changeset
1305 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
1306 if (action)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1307 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
1308 #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
1309 else
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1310 ipv4_applyaddr(ifp);
4348
437e53e4ea26 IP4: Remove #defines for functions when INET is disabled
Roy Marples <roy@marples.name>
parents: 4347
diff changeset
1311 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1312 } 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
1313 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
1314 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
1315 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
1316 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
1317 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1318 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1319 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1320
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1321 static void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1322 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
1323 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1324 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
1325
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1326 ctx->options |= DHCPCD_EXITING;
5296
3fd9a92dd852 ifaces could be NULL here
Roy Marples <roy@marples.name>
parents: 5292
diff changeset
1327 if (ctx->ifaces == NULL)
3fd9a92dd852 ifaces could be NULL here
Roy Marples <roy@marples.name>
parents: 5292
diff changeset
1328 return;
3fd9a92dd852 ifaces could be NULL here
Roy Marples <roy@marples.name>
parents: 5292
diff changeset
1329
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1330 /* 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
1331 TAILQ_FOREACH_REVERSE(ifp, ctx->ifaces, if_head, next) {
5266
9ea5c678d8a6 dhcpcd: Fix releasing addresses
Roy Marples <roy@marples.name>
parents: 5262
diff changeset
1332 if (!ifp->active)
9ea5c678d8a6 dhcpcd: Fix releasing addresses
Roy Marples <roy@marples.name>
parents: 5262
diff changeset
1333 continue;
9ea5c678d8a6 dhcpcd: Fix releasing addresses
Roy Marples <roy@marples.name>
parents: 5262
diff changeset
1334 ifp->options->options |= opts;
9ea5c678d8a6 dhcpcd: Fix releasing addresses
Roy Marples <roy@marples.name>
parents: 5262
diff changeset
1335 if (ifp->options->options & DHCPCD_RELEASE)
9ea5c678d8a6 dhcpcd: Fix releasing addresses
Roy Marples <roy@marples.name>
parents: 5262
diff changeset
1336 ifp->options->options &= ~DHCPCD_PERSISTENT;
9ea5c678d8a6 dhcpcd: Fix releasing addresses
Roy Marples <roy@marples.name>
parents: 5262
diff changeset
1337 ifp->options->options |= DHCPCD_EXITING;
5501
5b2272a0f3c3 privsep: Only log chrooting from the launcher process
Roy Marples <roy@marples.name>
parents: 5499
diff changeset
1338 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
1339 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1340 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1341
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1342 static void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1343 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
1344 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1345
3976
518eef876db3 dhcpcd: fix crash forcing lease renewals on inactive interfaces.
Roy Marples <roy@marples.name>
parents: 3965
diff changeset
1346 if (!ifp->active)
518eef876db3 dhcpcd: fix crash forcing lease renewals on inactive interfaces.
Roy Marples <roy@marples.name>
parents: 3965
diff changeset
1347 return;
518eef876db3 dhcpcd: fix crash forcing lease renewals on inactive interfaces.
Roy Marples <roy@marples.name>
parents: 3965
diff changeset
1348
5499
6a2da5651841 dhcpcd: Simplify the link handling even more
Roy Marples <roy@marples.name>
parents: 5497
diff changeset
1349 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
1350 return;
518eef876db3 dhcpcd: fix crash forcing lease renewals on inactive interfaces.
Roy Marples <roy@marples.name>
parents: 3965
diff changeset
1351
4347
fb677abacc16 DHCP: Remove #defines for functions when INET is disabled
Roy Marples <roy@marples.name>
parents: 4346
diff changeset
1352 #ifdef INET
3976
518eef876db3 dhcpcd: fix crash forcing lease renewals on inactive interfaces.
Roy Marples <roy@marples.name>
parents: 3965
diff changeset
1353 dhcp_renew(ifp);
4347
fb677abacc16 DHCP: Remove #defines for functions when INET is disabled
Roy Marples <roy@marples.name>
parents: 4346
diff changeset
1354 #endif
4351
b7a9f2b43d50 IP6ND: Remove #defines for functions when INET6 is disabled
Roy Marples <roy@marples.name>
parents: 4349
diff changeset
1355 #ifdef INET6
3976
518eef876db3 dhcpcd: fix crash forcing lease renewals on inactive interfaces.
Roy Marples <roy@marples.name>
parents: 3965
diff changeset
1356 #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
1357 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
1358 ipv6nd_startrs(ifp);
4351
b7a9f2b43d50 IP6ND: Remove #defines for functions when INET6 is disabled
Roy Marples <roy@marples.name>
parents: 4349
diff changeset
1359 #endif
4349
f87c2ed9ff46 DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents: 4348
diff changeset
1360 #ifdef DHCP6
3976
518eef876db3 dhcpcd: fix crash forcing lease renewals on inactive interfaces.
Roy Marples <roy@marples.name>
parents: 3965
diff changeset
1361 dhcp6_renew(ifp);
4349
f87c2ed9ff46 DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents: 4348
diff changeset
1362 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1363 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1364
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1365 static void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1366 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
1367 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1368 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
1369
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1370 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
1371 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
1372 }
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 #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
1376 #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
1377 static void
4850
c5a24b79f6b5 dhcpcd: signal_cb -> dhcpcd_signal_cb
Roy Marples <roy@marples.name>
parents: 4841
diff changeset
1378 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
1379 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1380 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
1381 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
1382 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
1383
5328
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1384 if (ctx->options & DHCPCD_DUMPLEASE) {
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1385 eloop_exit(ctx->eloop, EXIT_FAILURE);
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1386 return;
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1387 }
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1388
5304
04f26d9f1885 privsep: Don't wait for the process to finish when stopping it
Roy Marples <roy@marples.name>
parents: 5301
diff changeset
1389 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
1390 if (sig != SIGHUP &&
49e119831377 privsep: Send signal from launcher to master over the socket
Roy Marples <roy@marples.name>
parents: 5466
diff changeset
1391 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
1392 logerr("%s: write", __func__);
4856
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
1393 return;
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
1394 }
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
1395
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1396 opts = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1397 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
1398 switch (sig) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1399 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
1400 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
1401 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1402 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
1403 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
1404 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
1405 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1406 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
1407 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
1408 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
1409 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
1410 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1411 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
1412 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
1413 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
1414 /* 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
1415 * 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
1416 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
1417 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
1418 return;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1419 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
1420 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
1421 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
1422 return;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1423 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
1424 loginfox(sigmsg, "SIGUSR2", "reopening log");
4997
774f445ed677 logging: Always log to syslog(3).
Roy Marples <roy@marples.name>
parents: 4994
diff changeset
1425 /* XXX This may not work that well in a chroot */
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 4008
diff changeset
1426 logclose();
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 4008
diff changeset
1427 if (logopen(ctx->logfile) == -1)
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 4008
diff changeset
1428 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
1429 return;
5304
04f26d9f1885 privsep: Don't wait for the process to finish when stopping it
Roy Marples <roy@marples.name>
parents: 5301
diff changeset
1430 case SIGCHLD:
04f26d9f1885 privsep: Don't wait for the process to finish when stopping it
Roy Marples <roy@marples.name>
parents: 5301
diff changeset
1431 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
1432 ;
04f26d9f1885 privsep: Don't wait for the process to finish when stopping it
Roy Marples <roy@marples.name>
parents: 5301
diff changeset
1433 return;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1434 default:
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 4008
diff changeset
1435 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
1436 sig);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1437 return;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1438 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1439
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1440 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
1441 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
1442 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
1443 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1444 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1445
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1446 int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1447 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
1448 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
1449 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1450 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
1451 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
1452 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
1453 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
1454 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
1455
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1456 /* 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
1457 * 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
1458 * 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
1459 * write callback on the fd */
5328
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1460 /* 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
1461 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
1462 return control_queue(fd, UNCONST(VERSION),
5328
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1463 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
1464 } 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
1465 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
1466 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
1467 } else if (strcmp(*argv, "--getinterfaces") == 0) {
5328
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1468 optind = argc = 0;
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1469 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
1470 } 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
1471 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
1472 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1473 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1474
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1475 /* 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
1476 len = 1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1477 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
1478 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
1479 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
1480 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
1481 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1482 p = tmp;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1483 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
1484 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
1485 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
1486 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
1487 p += l;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1488 *p++ = ' ';
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1489 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1490 *--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
1491 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
1492 free(tmp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1493
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1494 optind = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1495 oi = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1496 opts = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1497 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
1498 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
1499 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1500 switch (opt) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1501 case 'g':
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1502 /* 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
1503 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1504 case 'k':
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1505 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
1506 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1507 case 'n':
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1508 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
1509 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1510 case 'p':
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1511 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
1512 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1513 case 'x':
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1514 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
1515 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1516 case 'N':
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1517 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
1518 break;
5092
995a49ee3418 dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents: 5089
diff changeset
1519 case 'U':
995a49ee3418 dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents: 5089
diff changeset
1520 opts |= DHCPCD_DUMPLEASE;
995a49ee3418 dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents: 5089
diff changeset
1521 break;
995a49ee3418 dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents: 5089
diff changeset
1522 case '4':
995a49ee3418 dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents: 5089
diff changeset
1523 af = AF_INET;
995a49ee3418 dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents: 5089
diff changeset
1524 break;
995a49ee3418 dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents: 5089
diff changeset
1525 case '6':
995a49ee3418 dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents: 5089
diff changeset
1526 af = AF_INET6;
995a49ee3418 dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents: 5089
diff changeset
1527 break;
3932
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 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1530
5092
995a49ee3418 dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents: 5089
diff changeset
1531 if (opts & DHCPCD_DUMPLEASE) {
995a49ee3418 dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents: 5089
diff changeset
1532 ctx->options |= DHCPCD_DUMPLEASE;
5328
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1533 dumplease:
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1534 nifaces = 0;
5121
200e3a305ec5 dhcpcd: dump all variables and optionally all interfaces
Roy Marples <roy@marples.name>
parents: 5112
diff changeset
1535 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
1536 if (!ifp->active)
995a49ee3418 dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents: 5089
diff changeset
1537 continue;
5121
200e3a305ec5 dhcpcd: dump all variables and optionally all interfaces
Roy Marples <roy@marples.name>
parents: 5112
diff changeset
1538 for (oi = optind; oi < argc; oi++) {
200e3a305ec5 dhcpcd: dump all variables and optionally all interfaces
Roy Marples <roy@marples.name>
parents: 5112
diff changeset
1539 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
1540 break;
200e3a305ec5 dhcpcd: dump all variables and optionally all interfaces
Roy Marples <roy@marples.name>
parents: 5112
diff changeset
1541 }
200e3a305ec5 dhcpcd: dump all variables and optionally all interfaces
Roy Marples <roy@marples.name>
parents: 5112
diff changeset
1542 if (optind == argc || oi < argc) {
200e3a305ec5 dhcpcd: dump all variables and optionally all interfaces
Roy Marples <roy@marples.name>
parents: 5112
diff changeset
1543 opt = send_interface(NULL, ifp, af);
200e3a305ec5 dhcpcd: dump all variables and optionally all interfaces
Roy Marples <roy@marples.name>
parents: 5112
diff changeset
1544 if (opt == -1)
200e3a305ec5 dhcpcd: dump all variables and optionally all interfaces
Roy Marples <roy@marples.name>
parents: 5112
diff changeset
1545 goto dumperr;
5092
995a49ee3418 dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents: 5089
diff changeset
1546 nifaces += (size_t)opt;
5121
200e3a305ec5 dhcpcd: dump all variables and optionally all interfaces
Roy Marples <roy@marples.name>
parents: 5112
diff changeset
1547 }
5092
995a49ee3418 dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents: 5089
diff changeset
1548 }
995a49ee3418 dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents: 5089
diff changeset
1549 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
1550 goto dumperr;
200e3a305ec5 dhcpcd: dump all variables and optionally all interfaces
Roy Marples <roy@marples.name>
parents: 5112
diff changeset
1551 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
1552 if (!ifp->active)
995a49ee3418 dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents: 5089
diff changeset
1553 continue;
5121
200e3a305ec5 dhcpcd: dump all variables and optionally all interfaces
Roy Marples <roy@marples.name>
parents: 5112
diff changeset
1554 for (oi = optind; oi < argc; oi++) {
200e3a305ec5 dhcpcd: dump all variables and optionally all interfaces
Roy Marples <roy@marples.name>
parents: 5112
diff changeset
1555 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
1556 break;
200e3a305ec5 dhcpcd: dump all variables and optionally all interfaces
Roy Marples <roy@marples.name>
parents: 5112
diff changeset
1557 }
200e3a305ec5 dhcpcd: dump all variables and optionally all interfaces
Roy Marples <roy@marples.name>
parents: 5112
diff changeset
1558 if (optind == argc || oi < argc) {
200e3a305ec5 dhcpcd: dump all variables and optionally all interfaces
Roy Marples <roy@marples.name>
parents: 5112
diff changeset
1559 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
1560 goto dumperr;
200e3a305ec5 dhcpcd: dump all variables and optionally all interfaces
Roy Marples <roy@marples.name>
parents: 5112
diff changeset
1561 }
5092
995a49ee3418 dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents: 5089
diff changeset
1562 }
995a49ee3418 dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents: 5089
diff changeset
1563 ctx->options &= ~DHCPCD_DUMPLEASE;
995a49ee3418 dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents: 5089
diff changeset
1564 return 0;
5121
200e3a305ec5 dhcpcd: dump all variables and optionally all interfaces
Roy Marples <roy@marples.name>
parents: 5112
diff changeset
1565 dumperr:
200e3a305ec5 dhcpcd: dump all variables and optionally all interfaces
Roy Marples <roy@marples.name>
parents: 5112
diff changeset
1566 ctx->options &= ~DHCPCD_DUMPLEASE;
200e3a305ec5 dhcpcd: dump all variables and optionally all interfaces
Roy Marples <roy@marples.name>
parents: 5112
diff changeset
1567 return -1;
5092
995a49ee3418 dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents: 5089
diff changeset
1568 }
995a49ee3418 dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents: 5089
diff changeset
1569
995a49ee3418 dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents: 5089
diff changeset
1570 /* 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
1571 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
1572 errno = EPERM;
995a49ee3418 dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents: 5089
diff changeset
1573 return -1;
995a49ee3418 dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents: 5089
diff changeset
1574 }
995a49ee3418 dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents: 5089
diff changeset
1575
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1576 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
1577 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
1578 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
1579 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
1580 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1581 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1582 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
1583 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
1584 continue;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1585 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
1586 continue;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1587 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
1588 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
1589 ifp->options->options &= ~DHCPCD_PERSISTENT;
5501
5b2272a0f3c3 privsep: Only log chrooting from the launcher process
Roy Marples <roy@marples.name>
parents: 5499
diff changeset
1590 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
1591 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1592 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1593 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1594
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1595 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
1596 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
1597 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
1598 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1599 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1600 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
1601 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
1602 continue;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1603 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
1604 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1605 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1606 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1607
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1608 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
1609 /* 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
1610 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
1611 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1612 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1613
5328
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1614 static void dhcpcd_readdump1(void *);
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1615
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1616 static void
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1617 dhcpcd_readdump2(void *arg)
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1618 {
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1619 struct dhcpcd_ctx *ctx = arg;
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1620 ssize_t len;
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1621 int exit_code = EXIT_FAILURE;
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1622
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1623 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
1624 ctx->ctl_buflen - ctx->ctl_bufpos);
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1625 if (len == -1) {
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1626 logerr(__func__);
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1627 goto finished;
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1628 } else if (len == 0)
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1629 goto finished;
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1630 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
1631 ctx->ctl_bufpos += (size_t)len;
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1632 return;
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1633 }
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1634
5348
5d4210eb0187 dhcpcd: Ensure dump is terminated
Roy Marples <roy@marples.name>
parents: 5345
diff changeset
1635 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
1636 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
1637 script_dump(ctx->ctl_buf, ctx->ctl_buflen);
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1638 fflush(stdout);
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1639 if (--ctx->ctl_extra != 0) {
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1640 putchar('\n');
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1641 eloop_event_add(ctx->eloop, ctx->control_fd,
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1642 dhcpcd_readdump1, ctx);
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1643 return;
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1644 }
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1645 exit_code = EXIT_SUCCESS;
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1646
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1647 finished:
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1648 shutdown(ctx->control_fd, SHUT_RDWR);
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1649 eloop_exit(ctx->eloop, exit_code);
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1650 }
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1651
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1652 static void
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1653 dhcpcd_readdump1(void *arg)
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 struct dhcpcd_ctx *ctx = arg;
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1656 ssize_t len;
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 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
1659 if (len != sizeof(ctx->ctl_buflen)) {
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1660 if (len != -1)
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1661 errno = EINVAL;
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1662 goto err;
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1663 }
5345
f6051f78e441 Try and guard against impossibly large data.
Roy Marples <roy@marples.name>
parents: 5343
diff changeset
1664 if (ctx->ctl_buflen > SSIZE_MAX) {
f6051f78e441 Try and guard against impossibly large data.
Roy Marples <roy@marples.name>
parents: 5343
diff changeset
1665 errno = ENOBUFS;
f6051f78e441 Try and guard against impossibly large data.
Roy Marples <roy@marples.name>
parents: 5343
diff changeset
1666 goto err;
f6051f78e441 Try and guard against impossibly large data.
Roy Marples <roy@marples.name>
parents: 5343
diff changeset
1667 }
5328
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1668
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1669 free(ctx->ctl_buf);
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1670 ctx->ctl_buf = malloc(ctx->ctl_buflen);
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1671 if (ctx->ctl_buf == NULL)
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1672 goto err;
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1673
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1674 ctx->ctl_bufpos = 0;
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1675 eloop_event_add(ctx->eloop, ctx->control_fd,
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1676 dhcpcd_readdump2, ctx);
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1677 return;
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1678
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1679 err:
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1680 logerr(__func__);
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1681 eloop_exit(ctx->eloop, EXIT_FAILURE);
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1682 }
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 static void
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1685 dhcpcd_readdump0(void *arg)
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1686 {
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1687 struct dhcpcd_ctx *ctx = arg;
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1688 ssize_t len;
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 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
1691 if (len != sizeof(ctx->ctl_extra)) {
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1692 if (len != -1)
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1693 errno = EINVAL;
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1694 logerr(__func__);
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1695 eloop_exit(ctx->eloop, EXIT_FAILURE);
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1696 return;
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1697 }
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1698
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1699 if (ctx->ctl_extra == 0) {
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1700 eloop_exit(ctx->eloop, EXIT_SUCCESS);
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1701 return;
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1702 }
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1703
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1704 eloop_event_add(ctx->eloop, ctx->control_fd,
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1705 dhcpcd_readdump1, ctx);
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1706 }
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 static void
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1709 dhcpcd_readdumptimeout(void *arg)
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1710 {
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1711 struct dhcpcd_ctx *ctx = arg;
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 logerrx(__func__);
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1714 eloop_exit(ctx->eloop, EXIT_FAILURE);
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1715 }
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1716
5092
995a49ee3418 dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents: 5089
diff changeset
1717 static int
995a49ee3418 dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents: 5089
diff changeset
1718 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
1719 {
995a49ee3418 dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents: 5089
diff changeset
1720
5328
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1721 ctx->options |= DHCPCD_FORKED;
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1722 if (eloop_timeout_add_sec(ctx->eloop, 5,
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1723 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
1724 return -1;
5328
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
1725 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
1726 dhcpcd_readdump0, ctx);
5092
995a49ee3418 dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents: 5089
diff changeset
1727 }
995a49ee3418 dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents: 5089
diff changeset
1728
4856
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
1729 static void
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
1730 dhcpcd_fork_cb(void *arg)
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
1731 {
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
1732 struct dhcpcd_ctx *ctx = arg;
4868
119c8986dfc8 privsep: Enable ARP BPF filtering for interesting addresses
Roy Marples <roy@marples.name>
parents: 4861
diff changeset
1733 int exit_code;
4856
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
1734 ssize_t len;
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
1735
5467
49e119831377 privsep: Send signal from launcher to master over the socket
Roy Marples <roy@marples.name>
parents: 5466
diff changeset
1736 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
1737 if (len == -1) {
4856
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
1738 logerr(__func__);
4868
119c8986dfc8 privsep: Enable ARP BPF filtering for interesting addresses
Roy Marples <roy@marples.name>
parents: 4861
diff changeset
1739 exit_code = EXIT_FAILURE;
119c8986dfc8 privsep: Enable ARP BPF filtering for interesting addresses
Roy Marples <roy@marples.name>
parents: 4861
diff changeset
1740 } 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
1741 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
1742 __func__, len, sizeof(exit_code));
119c8986dfc8 privsep: Enable ARP BPF filtering for interesting addresses
Roy Marples <roy@marples.name>
parents: 4861
diff changeset
1743 exit_code = EXIT_FAILURE;
119c8986dfc8 privsep: Enable ARP BPF filtering for interesting addresses
Roy Marples <roy@marples.name>
parents: 4861
diff changeset
1744 }
5467
49e119831377 privsep: Send signal from launcher to master over the socket
Roy Marples <roy@marples.name>
parents: 5466
diff changeset
1745 if (ctx->options & DHCPCD_FORKED)
5466
8bf1ce29152c privsep: sandbox the launcher process
Roy Marples <roy@marples.name>
parents: 5458
diff changeset
1746 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
1747 else
49e119831377 privsep: Send signal from launcher to master over the socket
Roy Marples <roy@marples.name>
parents: 5466
diff changeset
1748 dhcpcd_signal_cb(exit_code, ctx);
4856
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
1749 }
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
1750
5439
35210bb8687c dhcpcd: Setup a socketpair in the launcher to write to stderr
Roy Marples <roy@marples.name>
parents: 5431
diff changeset
1751 static void
35210bb8687c dhcpcd: Setup a socketpair in the launcher to write to stderr
Roy Marples <roy@marples.name>
parents: 5431
diff changeset
1752 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
1753 {
35210bb8687c dhcpcd: Setup a socketpair in the launcher to write to stderr
Roy Marples <roy@marples.name>
parents: 5431
diff changeset
1754 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
1755 char log[BUFSIZ];
35210bb8687c dhcpcd: Setup a socketpair in the launcher to write to stderr
Roy Marples <roy@marples.name>
parents: 5431
diff changeset
1756 ssize_t len;
35210bb8687c dhcpcd: Setup a socketpair in the launcher to write to stderr
Roy Marples <roy@marples.name>
parents: 5431
diff changeset
1757
35210bb8687c dhcpcd: Setup a socketpair in the launcher to write to stderr
Roy Marples <roy@marples.name>
parents: 5431
diff changeset
1758 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
1759 if (len == -1) {
5446
560e67bb9f6f dhcpcd: stderr callback fd may the reset by peer
Roy Marples <roy@marples.name>
parents: 5445
diff changeset
1760 if (errno != ECONNRESET)
560e67bb9f6f dhcpcd: stderr callback fd may the reset by peer
Roy Marples <roy@marples.name>
parents: 5445
diff changeset
1761 logerr(__func__);
5439
35210bb8687c dhcpcd: Setup a socketpair in the launcher to write to stderr
Roy Marples <roy@marples.name>
parents: 5431
diff changeset
1762 return;
35210bb8687c dhcpcd: Setup a socketpair in the launcher to write to stderr
Roy Marples <roy@marples.name>
parents: 5431
diff changeset
1763 }
35210bb8687c dhcpcd: Setup a socketpair in the launcher to write to stderr
Roy Marples <roy@marples.name>
parents: 5431
diff changeset
1764
35210bb8687c dhcpcd: Setup a socketpair in the launcher to write to stderr
Roy Marples <roy@marples.name>
parents: 5431
diff changeset
1765 log[len] = '\0';
35210bb8687c dhcpcd: Setup a socketpair in the launcher to write to stderr
Roy Marples <roy@marples.name>
parents: 5431
diff changeset
1766 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
1767 }
35210bb8687c dhcpcd: Setup a socketpair in the launcher to write to stderr
Roy Marples <roy@marples.name>
parents: 5431
diff changeset
1768
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1769 int
5510
b9a2c4481c2e setproctitle compat requires envp, not environ
Roy Marples <roy@marples.name>
parents: 5507
diff changeset
1770 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
1771 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1772 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
1773 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
1774 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
1775 struct interface *ifp;
5170
8c6a66d852f4 This should really be sa_family_t.
Roy Marples <roy@marples.name>
parents: 5169
diff changeset
1776 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
1777 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
1778 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
1779 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
1780 #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
1781 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
1782 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
1783 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1784 #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
1785 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
1786 const char *siga = NULL;
5227
7406014c9120 dhcpcd: allow sigpipe in scripts.
Roy Marples <roy@marples.name>
parents: 5223
diff changeset
1787 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
1788 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1789
5507
78f2fda6ee5d compat: Use libbsd's setproctitle(3)
Roy Marples <roy@marples.name>
parents: 5503
diff changeset
1790 #ifdef SETPROCTITLE_H
5510
b9a2c4481c2e setproctitle compat requires envp, not environ
Roy Marples <roy@marples.name>
parents: 5507
diff changeset
1791 setproctitle_init(argc, argv, envp);
5511
618c0ef1bae8 BSD doesn't use envp
Roy Marples <roy@marples.name>
parents: 5510
diff changeset
1792 #else
618c0ef1bae8 BSD doesn't use envp
Roy Marples <roy@marples.name>
parents: 5510
diff changeset
1793 UNUSED(envp);
5507
78f2fda6ee5d compat: Use libbsd's setproctitle(3)
Roy Marples <roy@marples.name>
parents: 5503
diff changeset
1794 #endif
78f2fda6ee5d compat: Use libbsd's setproctitle(3)
Roy Marples <roy@marples.name>
parents: 5503
diff changeset
1795
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1796 /* 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
1797 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
1798 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
1799 usage();
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1800 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
1801 } 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
1802 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
1803 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
1804 #ifdef INET
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1805 " INET"
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1806 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1807 #ifdef ARP
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1808 " ARP"
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1809 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1810 #ifdef ARPING
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1811 " ARPing"
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1812 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1813 #ifdef IPV4LL
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1814 " IPv4LL"
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1815 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1816 #ifdef INET6
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1817 " INET6"
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1818 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1819 #ifdef DHCP6
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1820 " DHCPv6"
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1821 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1822 #ifdef AUTH
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1823 " AUTH"
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1824 #endif
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4836
diff changeset
1825 #ifdef PRIVSEP
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4836
diff changeset
1826 " PRIVSEP"
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4836
diff changeset
1827 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1828 "\n");
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1829 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
1830 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1831 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1832
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1833 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
1834
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1835 ifo = NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1836 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
1837 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
1838 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
1839 ctx.pf_inet_fd = -1;
5311
fd78486b12a7 if: Keep the PF_LINK socket open throughout
Roy Marples <roy@marples.name>
parents: 5310
diff changeset
1840 #ifdef PF_LINK
fd78486b12a7 if: Keep the PF_LINK socket open throughout
Roy Marples <roy@marples.name>
parents: 5310
diff changeset
1841 ctx.pf_link_fd = -1;
fd78486b12a7 if: Keep the PF_LINK socket open throughout
Roy Marples <roy@marples.name>
parents: 5310
diff changeset
1842 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1843
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1844 TAILQ_INIT(&ctx.control_fds);
4856
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
1845 #ifdef USE_SIGNALS
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
1846 ctx.fork_fd = -1;
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
1847 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1848 #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
1849 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
1850 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1851 #ifdef INET
5231
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5228
diff changeset
1852 ctx.udp_rfd = -1;
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5228
diff changeset
1853 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
1854 #endif
4841
bace61b4b4ff Solaris: Fix non PRIVSEP compile
Roy Marples <roy@marples.name>
parents: 4840
diff changeset
1855 #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
1856 ctx.nd_fd = -1;
4684eb2ca980 build: Move rundir from /var/run to /var/run/dhcpcd
Roy Marples <roy@marples.name>
parents: 4823
diff changeset
1857 #endif
4684eb2ca980 build: Move rundir from /var/run to /var/run/dhcpcd
Roy Marples <roy@marples.name>
parents: 4823
diff changeset
1858 #ifdef DHCP6
5231
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5228
diff changeset
1859 ctx.dhcp6_rfd = -1;
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5228
diff changeset
1860 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
1861 #endif
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4836
diff changeset
1862 #ifdef PRIVSEP
5525
26b5d9bc2985 privsep: Send all log messages to the privileged actioneer
Roy Marples <roy@marples.name>
parents: 5511
diff changeset
1863 ctx.ps_root_fd = ctx.ps_syslog_fd = ctx.ps_data_fd = -1;
5385
0397759ce185 privsep: init more fd -1
Roy Marples <roy@marples.name>
parents: 5380
diff changeset
1864 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
1865 TAILQ_INIT(&ctx.ps_processes);
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4836
diff changeset
1866 #endif
4249
c30233f8cca3 routes: allow a head clear with a context
Roy Marples <roy@marples.name>
parents: 4246
diff changeset
1867
5454
68ef863871d1 dhcpcd: Only manipulate stdin, stdout and stderr when valid
Roy Marples <roy@marples.name>
parents: 5451
diff changeset
1868 /* Check our streams for validity */
68ef863871d1 dhcpcd: Only manipulate stdin, stdout and stderr when valid
Roy Marples <roy@marples.name>
parents: 5451
diff changeset
1869 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
1870 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
1871 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
1872
68ef863871d1 dhcpcd: Only manipulate stdin, stdout and stderr when valid
Roy Marples <roy@marples.name>
parents: 5451
diff changeset
1873 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
1874 if (ctx.stderr_valid)
68ef863871d1 dhcpcd: Only manipulate stdin, stdout and stderr when valid
Roy Marples <roy@marples.name>
parents: 5451
diff changeset
1875 logopts |= LOGERR_ERR;
68ef863871d1 dhcpcd: Only manipulate stdin, stdout and stderr when valid
Roy Marples <roy@marples.name>
parents: 5451
diff changeset
1876
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1877 i = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1878 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
1879 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
1880 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
1881 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1882 switch (opt) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1883 case '4':
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1884 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
1885 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1886 case '6':
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1887 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
1888 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1889 case 'f':
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1890 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
1891 break;
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 4008
diff changeset
1892 case 'j':
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 4008
diff changeset
1893 free(ctx.logfile);
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 4008
diff changeset
1894 ctx.logfile = strdup(optarg);
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 4008
diff changeset
1895 break;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1896 #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
1897 case 'k':
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1898 sig = SIGALRM;
4005
03e498b6ba82 transposition police!
Roy Marples <roy@marples.name>
parents: 3982
diff changeset
1899 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
1900 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1901 case 'n':
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1902 sig = SIGHUP;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1903 siga = "HUP";
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1904 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1905 case 'g':
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1906 case 'p':
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1907 /* 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
1908 * 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
1909 i = 4;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1910 break;
3960
42a6a3d1596e Remove custom logger and output all diagnostics via syslog(3).
Roy Marples <roy@marples.name>
parents: 3932
diff changeset
1911 case 'q':
5251
50eb48a9b47b dhcpcd: Silence console output entirely with more -q
Roy Marples <roy@marples.name>
parents: 5231
diff changeset
1912 /* -qq disables console output entirely.
5252
bae9ab6cd868 Apparently case is important.
Roy Marples <roy@marples.name>
parents: 5251
diff changeset
1913 * 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
1914 * 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
1915 * resulting in untold confusion. */
50eb48a9b47b dhcpcd: Silence console output entirely with more -q
Roy Marples <roy@marples.name>
parents: 5231
diff changeset
1916 if (logopts & LOGERR_QUIET)
50eb48a9b47b dhcpcd: Silence console output entirely with more -q
Roy Marples <roy@marples.name>
parents: 5231
diff changeset
1917 logopts &= ~LOGERR_ERR;
50eb48a9b47b dhcpcd: Silence console output entirely with more -q
Roy Marples <roy@marples.name>
parents: 5231
diff changeset
1918 else
50eb48a9b47b dhcpcd: Silence console output entirely with more -q
Roy Marples <roy@marples.name>
parents: 5231
diff changeset
1919 logopts |= LOGERR_QUIET;
3960
42a6a3d1596e Remove custom logger and output all diagnostics via syslog(3).
Roy Marples <roy@marples.name>
parents: 3932
diff changeset
1920 break;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1921 case 'x':
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1922 sig = SIGTERM;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1923 siga = "TERM";
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1924 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1925 case 'N':
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1926 sig = SIGUSR1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1927 siga = "USR1";
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 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1930 case 'P':
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1931 ctx.options |= DHCPCD_PRINT_PIDFILE;
4051
91fb234797c2 Don't log anything when printing the pidfile.
Roy Marples <roy@marples.name>
parents: 4050
diff changeset
1932 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
1933 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1934 case 'T':
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1935 i = 1;
4019
fe2f1ad133a2 Write syslog entries in logfile:
Roy Marples <roy@marples.name>
parents: 4010
diff changeset
1936 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
1937 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1938 case 'U':
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1939 i = 3;
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 'V':
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1942 i = 2;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1943 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1944 case '?':
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1945 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
1946 continue;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1947 usage();
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1948 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
1949 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1950 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1951
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 4008
diff changeset
1952 logsetopts(logopts);
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 4008
diff changeset
1953 logopen(ctx.logfile);
3960
42a6a3d1596e Remove custom logger and output all diagnostics via syslog(3).
Roy Marples <roy@marples.name>
parents: 3932
diff changeset
1954
4766
cacf3b10beef Revert "compat: Use more portable setproctitle from nginx"
Roy Marples <roy@marples.name>
parents: 4765
diff changeset
1955 ctx.argv = argv;
cacf3b10beef Revert "compat: Use more portable setproctitle from nginx"
Roy Marples <roy@marples.name>
parents: 4765
diff changeset
1956 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
1957 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
1958 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
1959
5454
68ef863871d1 dhcpcd: Only manipulate stdin, stdout and stderr when valid
Roy Marples <roy@marples.name>
parents: 5451
diff changeset
1960 rt_init(&ctx);
68ef863871d1 dhcpcd: Only manipulate stdin, stdout and stderr when valid
Roy Marples <roy@marples.name>
parents: 5451
diff changeset
1961
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1962 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
1963 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
1964 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
1965 goto printpidfile;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1966 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
1967 }
4766
cacf3b10beef Revert "compat: Use more portable setproctitle from nginx"
Roy Marples <roy@marples.name>
parents: 4765
diff changeset
1968 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
1969 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
1970 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
1971 goto printpidfile;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1972 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
1973 usage();
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1974 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
1975 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1976 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
1977 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
1978 if (optind == argc - 1) {
4249
c30233f8cca3 routes: allow a head clear with a context
Roy Marples <roy@marples.name>
parents: 4246
diff changeset
1979 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
1980 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
1981 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
1982 goto exit_failure;
4766
cacf3b10beef Revert "compat: Use more portable setproctitle from nginx"
Roy Marples <roy@marples.name>
parents: 4765
diff changeset
1983 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
1984 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1985 if_printoptions();
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1986 #ifdef INET
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1987 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
1988 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
1989 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
1990 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
1991 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1992 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1993 #ifdef INET6
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1994 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
1995 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
1996 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
1997 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
1998 #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
1999 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
2000 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
2001 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
2002 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2003 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2004 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2005 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
2006 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2007 ctx.options |= ifo->options;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2008 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
2009 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
2010 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
2011 else
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2012 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
2013 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
2014 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
2015 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2016
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2017 #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
2018 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
2019 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2020
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2021 if (ctx.options & DHCPCD_DEBUG)
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 4008
diff changeset
2022 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
2023
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2024 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
2025 printpidfile:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2026 /* 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
2027 * 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
2028 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
2029 const char *per;
4047
b4e680c56be8 Should check that an interface name actually exists when
Roy Marples <roy@marples.name>
parents: 4027
diff changeset
2030 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
2031
4047
b4e680c56be8 Should check that an interface name actually exists when
Roy Marples <roy@marples.name>
parents: 4027
diff changeset
2032 ifname = *ctx.ifv;
b4e680c56be8 Should check that an interface name actually exists when
Roy Marples <roy@marples.name>
parents: 4027
diff changeset
2033 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
2034 errno = ifname == NULL ? EINVAL : E2BIG;
b4e680c56be8 Should check that an interface name actually exists when
Roy Marples <roy@marples.name>
parents: 4027
diff changeset
2035 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
2036 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
2037 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2038 /* 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
2039 switch(family) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2040 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
2041 per = "-4";
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2042 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2043 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
2044 per = "-6";
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2045 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2046 default:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2047 per = "";
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2048 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2049 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
2050 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
2051 } else {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2052 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
2053 PIDFILE, "", "", "");
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2054 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
2055 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2056 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
2057 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
2058 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
2059 }
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 if (chdir("/") == -1)
5494
0fbde4769bbe Don't log backticks.
Roy Marples <roy@marples.name>
parents: 5490
diff changeset
2063 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
2064
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2065 /* 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
2066 * 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
2067 if ((ctx.eloop = eloop_new()) == NULL) {
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 4008
diff changeset
2068 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
2069 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
2070 }
4968
34d8fe622a9a dhcpcd: Ignore SIGPIPE, prefer EPIPE.
Roy Marples <roy@marples.name>
parents: 4965
diff changeset
2071
4184
548f1baa118d Init the signal handler ASAP so random stuff can be cleaned up.
Roy Marples <roy@marples.name>
parents: 4183
diff changeset
2072 #ifdef USE_SIGNALS
5227
7406014c9120 dhcpcd: allow sigpipe in scripts.
Roy Marples <roy@marples.name>
parents: 5223
diff changeset
2073 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
2074 signal(dhcpcd_signals_ignore[si], SIG_IGN);
4968
34d8fe622a9a dhcpcd: Ignore SIGPIPE, prefer EPIPE.
Roy Marples <roy@marples.name>
parents: 4965
diff changeset
2075
4184
548f1baa118d Init the signal handler ASAP so random stuff can be cleaned up.
Roy Marples <roy@marples.name>
parents: 4183
diff changeset
2076 /* 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
2077 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
2078 dhcpcd_signals, dhcpcd_signals_len,
5301
e6f1372f2cf0 eloop: Just use ppoll(2)
Roy Marples <roy@marples.name>
parents: 5296
diff changeset
2079 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
2080 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
2081 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
2082 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
2083 }
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2084
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2085 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
2086 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
2087 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
2088 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
2089 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
2090 if (sig != SIGHUP && sig != SIGUSR1 && errno != EPERM)
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 4008
diff changeset
2091 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
2092 if (pid != 0 && pid != -1 && errno != ESRCH) {
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 4008
diff changeset
2093 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
2094 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
2095 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2096 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
2097 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
2098 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
2099 } else {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2100 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
2101
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2102 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
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 /* 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
2105 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
2106 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
2107 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
2108 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
2109 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
2110 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
2111 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
2112 }
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 4008
diff changeset
2113 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
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 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2116 }
5169
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2117 #endif
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2118
5445
2070a61faddd privsep: Dump leases from stdin in a limited sandbox
Roy Marples <roy@marples.name>
parents: 5442
diff changeset
2119 #ifdef PRIVSEP
2070a61faddd privsep: Dump leases from stdin in a limited sandbox
Roy Marples <roy@marples.name>
parents: 5442
diff changeset
2120 ps_init(&ctx);
2070a61faddd privsep: Dump leases from stdin in a limited sandbox
Roy Marples <roy@marples.name>
parents: 5442
diff changeset
2121 #endif
2070a61faddd privsep: Dump leases from stdin in a limited sandbox
Roy Marples <roy@marples.name>
parents: 5442
diff changeset
2122
5288
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2123 #ifndef SMALL
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2124 if (ctx.options & DHCPCD_DUMPLEASE &&
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2125 ioctl(fileno(stdin), FIONREAD, &i, sizeof(i)) == 0 &&
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2126 i > 0)
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2127 {
5445
2070a61faddd privsep: Dump leases from stdin in a limited sandbox
Roy Marples <roy@marples.name>
parents: 5442
diff changeset
2128 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
2129 #ifdef PRIVSEP
5466
8bf1ce29152c privsep: sandbox the launcher process
Roy Marples <roy@marples.name>
parents: 5458
diff changeset
2130 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
2131 goto exit_failure;
2070a61faddd privsep: Dump leases from stdin in a limited sandbox
Roy Marples <roy@marples.name>
parents: 5442
diff changeset
2132 #endif
5288
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2133 ifp = calloc(1, sizeof(*ifp));
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2134 if (ifp == NULL) {
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2135 logerr(__func__);
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2136 goto exit_failure;
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2137 }
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2138 ifp->ctx = &ctx;
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2139 ifp->options = ifo;
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2140 switch (family) {
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2141 case AF_INET:
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2142 #ifdef INET
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2143 if (dhcp_dump(ifp) == -1)
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2144 goto exit_failure;
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2145 break;
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2146 #else
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2147 logerrx("No DHCP support");
5292
2f2b53b05dc5 Fix compile without DHCP or DHCP6
Roy Marples <roy@marples.name>
parents: 5288
diff changeset
2148 goto exit_failure;
5288
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2149 #endif
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2150 case AF_INET6:
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2151 #ifdef DHCP6
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2152 if (dhcp6_dump(ifp) == -1)
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2153 goto exit_failure;
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2154 break;
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2155 #else
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2156 logerrx("No DHCP6 support");
5292
2f2b53b05dc5 Fix compile without DHCP or DHCP6
Roy Marples <roy@marples.name>
parents: 5288
diff changeset
2157 goto exit_failure;
5288
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2158 #endif
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2159 default:
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2160 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
2161 goto exit_failure;
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2162 }
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2163 goto exit_success;
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2164 }
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2165 #endif
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5284
diff changeset
2166
5169
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2167 /* 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
2168 * 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
2169 * 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
2170 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
2171 !(ctx.options & DHCPCD_TEST))
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2172 {
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2173 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
2174 if (!(ctx.options & DHCPCD_MASTER))
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2175 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
2176 ctx.options & DHCPCD_DUMPLEASE);
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2177 if (ctx.control_fd == -1)
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2178 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
2179 ctx.options & DHCPCD_DUMPLEASE);
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2180 if (ctx.control_fd != -1) {
5447
66512375d759 privsep: dump leases in a sandbox
Roy Marples <roy@marples.name>
parents: 5446
diff changeset
2181 #ifdef PRIVSEP
5466
8bf1ce29152c privsep: sandbox the launcher process
Roy Marples <roy@marples.name>
parents: 5458
diff changeset
2182 if (IN_PRIVSEP(&ctx) &&
8bf1ce29152c privsep: sandbox the launcher process
Roy Marples <roy@marples.name>
parents: 5458
diff changeset
2183 ps_mastersandbox(&ctx, NULL) == -1)
5447
66512375d759 privsep: dump leases in a sandbox
Roy Marples <roy@marples.name>
parents: 5446
diff changeset
2184 goto exit_failure;
66512375d759 privsep: dump leases in a sandbox
Roy Marples <roy@marples.name>
parents: 5446
diff changeset
2185 #endif
5169
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2186 if (!(ctx.options & DHCPCD_DUMPLEASE))
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2187 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
2188 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
2189 if (len > 0)
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2190 logdebugx("send OK");
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2191 else {
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2192 logerr("%s: control_send", __func__);
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2193 goto exit_failure;
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2194 }
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2195 if (ctx.options & DHCPCD_DUMPLEASE) {
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2196 if (dhcpcd_readdump(&ctx) == -1) {
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2197 logerr("%s: dhcpcd_readdump", __func__);
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2198 goto exit_failure;
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2199 }
5328
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
2200 goto run_loop;
5169
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2201 }
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2202 goto exit_success;
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2203 } else {
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2204 if (errno != ENOENT)
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2205 logerr("%s: control_open", __func__);
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2206 if (ctx.options & DHCPCD_DUMPLEASE) {
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2207 if (errno == ENOENT)
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2208 logerrx("dhcpcd is not running");
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2209 goto exit_failure;
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2210 }
5328
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
2211 if (errno == EPERM || errno == EACCES)
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
2212 goto exit_failure;
5169
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2213 }
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2214 ctx.options &= ~DHCPCD_FORKED;
f1a2ce25a64b dhcpcd: Fix separation of per interface and per family
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
2215 }
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2216
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2217 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
2218 /* 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
2219 if (mkdir(DBDIR, 0750) == -1 && errno != EEXIST)
5494
0fbde4769bbe Don't log backticks.
Roy Marples <roy@marples.name>
parents: 5490
diff changeset
2220 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
2221 if (mkdir(RUNDIR, 0755) == -1 && errno != EEXIST)
5494
0fbde4769bbe Don't log backticks.
Roy Marples <roy@marples.name>
parents: 5490
diff changeset
2222 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
2223 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
2224 if (pid == -1)
4834
4684eb2ca980 build: Move rundir from /var/run to /var/run/dhcpcd
Roy Marples <roy@marples.name>
parents: 4823
diff changeset
2225 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
2226 __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
2227 else
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 4008
diff changeset
2228 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
2229 " 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
2230 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
2231 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
2232 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2233 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2234
5132
2b98d2fb5702 dhcpcd: always emit version when starting.
Roy Marples <roy@marples.name>
parents: 5128
diff changeset
2235 loginfox(PACKAGE "-" VERSION " starting");
5454
68ef863871d1 dhcpcd: Only manipulate stdin, stdout and stderr when valid
Roy Marples <roy@marples.name>
parents: 5451
diff changeset
2236 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
2237 logwarn("freopen stdin");
5395
3ed7914080a9 dhcpcd: improve prior to log to another fd
Roy Marples <roy@marples.name>
parents: 5394
diff changeset
2238
5410
e7ca98611c22 src/dhcpcd.c: fix build without fork
Fabrice Fontaine <fontaine.fabrice@gmail.com>
parents: 5404
diff changeset
2239 #if defined(USE_SIGNALS) && !defined(THERE_IS_NO_FORK)
5439
35210bb8687c dhcpcd: Setup a socketpair in the launcher to write to stderr
Roy Marples <roy@marples.name>
parents: 5431
diff changeset
2240 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
2241 (ctx.stderr_valid &&
68ef863871d1 dhcpcd: Only manipulate stdin, stdout and stderr when valid
Roy Marples <roy@marples.name>
parents: 5451
diff changeset
2242 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
2243 {
35210bb8687c dhcpcd: Setup a socketpair in the launcher to write to stderr
Roy Marples <roy@marples.name>
parents: 5431
diff changeset
2244 logerr("socketpair");
4856
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2245 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
2246 }
4856
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2247 switch (pid = fork()) {
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2248 case -1:
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2249 logerr("fork");
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2250 goto exit_failure;
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2251 case 0:
5439
35210bb8687c dhcpcd: Setup a socketpair in the launcher to write to stderr
Roy Marples <roy@marples.name>
parents: 5431
diff changeset
2252 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
2253 close(fork_fd[0]);
5440
248013138b09 privsep: Fix prior for FreeBSD.
Roy Marples <roy@marples.name>
parents: 5439
diff changeset
2254 #ifdef PRIVSEP_RIGHTS
5503
18a7063f70c1 privsep: Improve rights on launcher fork and stderr fds
Roy Marples <roy@marples.name>
parents: 5501
diff changeset
2255 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
2256 logerr("ps_rights_limit_fdpair");
248013138b09 privsep: Fix prior for FreeBSD.
Roy Marples <roy@marples.name>
parents: 5439
diff changeset
2257 goto exit_failure;
248013138b09 privsep: Fix prior for FreeBSD.
Roy Marples <roy@marples.name>
parents: 5439
diff changeset
2258 }
248013138b09 privsep: Fix prior for FreeBSD.
Roy Marples <roy@marples.name>
parents: 5439
diff changeset
2259 #endif
5467
49e119831377 privsep: Send signal from launcher to master over the socket
Roy Marples <roy@marples.name>
parents: 5466
diff changeset
2260 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
2261
5442
a069d919d44c FreeBSD: Don't rights limit stderr
Roy Marples <roy@marples.name>
parents: 5441
diff changeset
2262 /*
a069d919d44c FreeBSD: Don't rights limit stderr
Roy Marples <roy@marples.name>
parents: 5441
diff changeset
2263 * 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
2264 * Redirect stdout as well.
ff7c7b4799b3 dhcpcd: Redirect stdout/stderr to the launcher stderr descriptor
Roy Marples <roy@marples.name>
parents: 5440
diff changeset
2265 * 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
2266 * a called script might.
a069d919d44c FreeBSD: Don't rights limit stderr
Roy Marples <roy@marples.name>
parents: 5441
diff changeset
2267 */
5454
68ef863871d1 dhcpcd: Only manipulate stdin, stdout and stderr when valid
Roy Marples <roy@marples.name>
parents: 5451
diff changeset
2268 if (ctx.stderr_valid) {
68ef863871d1 dhcpcd: Only manipulate stdin, stdout and stderr when valid
Roy Marples <roy@marples.name>
parents: 5451
diff changeset
2269 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
2270 (ctx.stdout_valid &&
68ef863871d1 dhcpcd: Only manipulate stdin, stdout and stderr when valid
Roy Marples <roy@marples.name>
parents: 5451
diff changeset
2271 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
2272 logerr("dup2");
68ef863871d1 dhcpcd: Only manipulate stdin, stdout and stderr when valid
Roy Marples <roy@marples.name>
parents: 5451
diff changeset
2273 close(stderr_fd[0]);
68ef863871d1 dhcpcd: Only manipulate stdin, stdout and stderr when valid
Roy Marples <roy@marples.name>
parents: 5451
diff changeset
2274 close(stderr_fd[1]);
68ef863871d1 dhcpcd: Only manipulate stdin, stdout and stderr when valid
Roy Marples <roy@marples.name>
parents: 5451
diff changeset
2275 } else if (ctx.stdout_valid) {
68ef863871d1 dhcpcd: Only manipulate stdin, stdout and stderr when valid
Roy Marples <roy@marples.name>
parents: 5451
diff changeset
2276 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
2277 logerr("freopen stdout");
68ef863871d1 dhcpcd: Only manipulate stdin, stdout and stderr when valid
Roy Marples <roy@marples.name>
parents: 5451
diff changeset
2278 }
4856
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2279 if (setsid() == -1) {
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2280 logerr("%s: setsid", __func__);
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2281 goto exit_failure;
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2282 }
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2283 /* Ensure we can never get a controlling terminal */
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2284 switch (pid = fork()) {
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2285 case -1:
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2286 logerr("fork");
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2287 goto exit_failure;
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2288 case 0:
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2289 break;
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2290 default:
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2291 ctx.options |= DHCPCD_FORKED; /* A lie */
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2292 i = EXIT_SUCCESS;
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2293 goto exit1;
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2294 }
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2295 break;
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2296 default:
5466
8bf1ce29152c privsep: sandbox the launcher process
Roy Marples <roy@marples.name>
parents: 5458
diff changeset
2297 setproctitle("[launcher]");
5501
5b2272a0f3c3 privsep: Only log chrooting from the launcher process
Roy Marples <roy@marples.name>
parents: 5499
diff changeset
2298 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
2299 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
2300 close(fork_fd[1]);
5440
248013138b09 privsep: Fix prior for FreeBSD.
Roy Marples <roy@marples.name>
parents: 5439
diff changeset
2301 #ifdef PRIVSEP_RIGHTS
5503
18a7063f70c1 privsep: Improve rights on launcher fork and stderr fds
Roy Marples <roy@marples.name>
parents: 5501
diff changeset
2302 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
2303 logerr("ps_rights_limit_fd");
5440
248013138b09 privsep: Fix prior for FreeBSD.
Roy Marples <roy@marples.name>
parents: 5439
diff changeset
2304 goto exit_failure;
248013138b09 privsep: Fix prior for FreeBSD.
Roy Marples <roy@marples.name>
parents: 5439
diff changeset
2305 }
248013138b09 privsep: Fix prior for FreeBSD.
Roy Marples <roy@marples.name>
parents: 5439
diff changeset
2306 #endif
4856
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2307 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
2308
68ef863871d1 dhcpcd: Only manipulate stdin, stdout and stderr when valid
Roy Marples <roy@marples.name>
parents: 5451
diff changeset
2309 if (ctx.stderr_valid) {
68ef863871d1 dhcpcd: Only manipulate stdin, stdout and stderr when valid
Roy Marples <roy@marples.name>
parents: 5451
diff changeset
2310 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
2311 close(stderr_fd[1]);
68ef863871d1 dhcpcd: Only manipulate stdin, stdout and stderr when valid
Roy Marples <roy@marples.name>
parents: 5451
diff changeset
2312 #ifdef PRIVSEP_RIGHTS
5503
18a7063f70c1 privsep: Improve rights on launcher fork and stderr fds
Roy Marples <roy@marples.name>
parents: 5501
diff changeset
2313 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
2314 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
2315 goto exit_failure;
68ef863871d1 dhcpcd: Only manipulate stdin, stdout and stderr when valid
Roy Marples <roy@marples.name>
parents: 5451
diff changeset
2316 }
68ef863871d1 dhcpcd: Only manipulate stdin, stdout and stderr when valid
Roy Marples <roy@marples.name>
parents: 5451
diff changeset
2317 #endif
5503
18a7063f70c1 privsep: Improve rights on launcher fork and stderr fds
Roy Marples <roy@marples.name>
parents: 5501
diff changeset
2318 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
2319 dhcpcd_stderr_cb, &ctx);
5454
68ef863871d1 dhcpcd: Only manipulate stdin, stdout and stderr when valid
Roy Marples <roy@marples.name>
parents: 5451
diff changeset
2320 }
5466
8bf1ce29152c privsep: sandbox the launcher process
Roy Marples <roy@marples.name>
parents: 5458
diff changeset
2321 #ifdef PRIVSEP
5467
49e119831377 privsep: Send signal from launcher to master over the socket
Roy Marples <roy@marples.name>
parents: 5466
diff changeset
2322 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
2323 goto exit_failure;
8bf1ce29152c privsep: sandbox the launcher process
Roy Marples <roy@marples.name>
parents: 5458
diff changeset
2324 #endif
4856
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2325 goto run_loop;
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2326 }
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2327
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2328 /* We have now forked, setsid, forked once more.
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2329 * From this point on, we are the controlling daemon. */
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2330 ctx.options |= DHCPCD_STARTED;
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2331 if ((pid = pidfile_lock(ctx.pidfile)) != 0) {
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2332 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
2333 #ifdef PRIVSEP
840cdf8beeb8 dhcpcd: avoid privsep errors if we error locking the pidfile
Roy Marples <roy@marples.name>
parents: 5447
diff changeset
2334 /* privsep has not started ... */
840cdf8beeb8 dhcpcd: avoid privsep errors if we error locking the pidfile
Roy Marples <roy@marples.name>
parents: 5447
diff changeset
2335 ctx.options &= ~DHCPCD_PRIVSEP;
840cdf8beeb8 dhcpcd: avoid privsep errors if we error locking the pidfile
Roy Marples <roy@marples.name>
parents: 5447
diff changeset
2336 #endif
4856
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2337 goto exit_failure;
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2338 }
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2339 #endif
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2340
5458
dd8347a0ea1c Adjust prior so that message is logged before starting dev
Roy Marples <roy@marples.name>
parents: 5454
diff changeset
2341 os_init();
dd8347a0ea1c Adjust prior so that message is logged before starting dev
Roy Marples <roy@marples.name>
parents: 5454
diff changeset
2342
5397
4c2de9b44e60 BSD: Setup sysctls before redirecting stderr
Roy Marples <roy@marples.name>
parents: 5395
diff changeset
2343 #if defined(BSD) && defined(INET6)
4c2de9b44e60 BSD: Setup sysctls before redirecting stderr
Roy Marples <roy@marples.name>
parents: 5395
diff changeset
2344 /* 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
2345 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
2346 if_disable_rtadv();
4c2de9b44e60 BSD: Setup sysctls before redirecting stderr
Roy Marples <roy@marples.name>
parents: 5395
diff changeset
2347 #endif
4c2de9b44e60 BSD: Setup sysctls before redirecting stderr
Roy Marples <roy@marples.name>
parents: 5395
diff changeset
2348
4953
109206a59cc6 privsep: Delay control startup after starting privsep
Roy Marples <roy@marples.name>
parents: 4937
diff changeset
2349 #ifdef PRIVSEP
5328
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
2350 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
2351 logerr("ps_start");
109206a59cc6 privsep: Delay control startup after starting privsep
Roy Marples <roy@marples.name>
parents: 4937
diff changeset
2352 goto exit_failure;
109206a59cc6 privsep: Delay control startup after starting privsep
Roy Marples <roy@marples.name>
parents: 4937
diff changeset
2353 }
109206a59cc6 privsep: Delay control startup after starting privsep
Roy Marples <roy@marples.name>
parents: 4937
diff changeset
2354 if (ctx.options & DHCPCD_FORKED)
109206a59cc6 privsep: Delay control startup after starting privsep
Roy Marples <roy@marples.name>
parents: 4937
diff changeset
2355 goto run_loop;
109206a59cc6 privsep: Delay control startup after starting privsep
Roy Marples <roy@marples.name>
parents: 4937
diff changeset
2356 #endif
109206a59cc6 privsep: Delay control startup after starting privsep
Roy Marples <roy@marples.name>
parents: 4937
diff changeset
2357
5328
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
2358 if (!(ctx.options & DHCPCD_TEST)) {
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
2359 if (control_start(&ctx,
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
2360 ctx.options & DHCPCD_MASTER ?
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
2361 NULL : argv[optind], family) == -1)
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
2362 {
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
2363 logerr("%s: control_start", __func__);
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
2364 goto exit_failure;
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
2365 }
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2366 }
4059
dd134e7e2ef6 dhcpcd.c: Fix -n opening sockets.
Roy Marples <roy@marples.name>
parents: 4052
diff changeset
2367
5262
f168a25dd330 privsep: Fix compile for prior without dev plugins
Roy Marples <roy@marples.name>
parents: 5260
diff changeset
2368 #ifdef PLUGIN_DEV
4994
af9de589341f Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents: 4989
diff changeset
2369 /* Start any dev listening plugin which may want to
af9de589341f Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents: 4989
diff changeset
2370 * 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
2371 if (!IN_PRIVSEP(&ctx) &&
7571d82b48da privsep: Allow dev plugins to work
Roy Marples <roy@marples.name>
parents: 5259
diff changeset
2372 (ctx.options & (DHCPCD_MASTER | DHCPCD_DEV)) ==
4994
af9de589341f Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents: 4989
diff changeset
2373 (DHCPCD_MASTER | DHCPCD_DEV))
5260
7571d82b48da privsep: Allow dev plugins to work
Roy Marples <roy@marples.name>
parents: 5259
diff changeset
2374 dev_start(&ctx, dhcpcd_handleinterface);
5262
f168a25dd330 privsep: Fix compile for prior without dev plugins
Roy Marples <roy@marples.name>
parents: 5260
diff changeset
2375 #endif
4994
af9de589341f Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents: 4989
diff changeset
2376
4223
467600defbe4 Add support for setproctitle(3).
Roy Marples <roy@marples.name>
parents: 4218
diff changeset
2377 setproctitle("%s%s%s",
467600defbe4 Add support for setproctitle(3).
Roy Marples <roy@marples.name>
parents: 4218
diff changeset
2378 ctx.options & DHCPCD_MASTER ? "[master]" : argv[optind],
467600defbe4 Add support for setproctitle(3).
Roy Marples <roy@marples.name>
parents: 4218
diff changeset
2379 ctx.options & DHCPCD_IPV4 ? " [ip4]" : "",
467600defbe4 Add support for setproctitle(3).
Roy Marples <roy@marples.name>
parents: 4218
diff changeset
2380 ctx.options & DHCPCD_IPV6 ? " [ip6]" : "");
467600defbe4 Add support for setproctitle(3).
Roy Marples <roy@marples.name>
parents: 4218
diff changeset
2381
4059
dd134e7e2ef6 dhcpcd.c: Fix -n opening sockets.
Roy Marples <roy@marples.name>
parents: 4052
diff changeset
2382 if (if_opensockets(&ctx) == -1) {
dd134e7e2ef6 dhcpcd.c: Fix -n opening sockets.
Roy Marples <roy@marples.name>
parents: 4052
diff changeset
2383 logerr("%s: if_opensockets", __func__);
dd134e7e2ef6 dhcpcd.c: Fix -n opening sockets.
Roy Marples <roy@marples.name>
parents: 4052
diff changeset
2384 goto exit_failure;
dd134e7e2ef6 dhcpcd.c: Fix -n opening sockets.
Roy Marples <roy@marples.name>
parents: 4052
diff changeset
2385 }
4415
4eb8ce6f854c options: add link_rcvbuf variable
Roy Marples <roy@marples.name>
parents: 4394
diff changeset
2386 #ifndef SMALL
4eb8ce6f854c options: add link_rcvbuf variable
Roy Marples <roy@marples.name>
parents: 4394
diff changeset
2387 dhcpcd_setlinkrcvbuf(&ctx);
4eb8ce6f854c options: add link_rcvbuf variable
Roy Marples <roy@marples.name>
parents: 4394
diff changeset
2388 #endif
4059
dd134e7e2ef6 dhcpcd.c: Fix -n opening sockets.
Roy Marples <roy@marples.name>
parents: 4052
diff changeset
2389
5207
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
2390 /* 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
2391 dhcpcd_initduid(&ctx, NULL);
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
2392
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
2393 /* Cache the default vendor option. */
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
2394 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
2395 logerr("dhcp_vendor");
5207
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
2396
5331
d075e31eb148 privsep: For Linux and Solaris, set RLIMIT_NOFILES to nevents
Roy Marples <roy@marples.name>
parents: 5328
diff changeset
2397 /* 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
2398 * routes. */
d075e31eb148 privsep: For Linux and Solaris, set RLIMIT_NOFILES to nevents
Roy Marples <roy@marples.name>
parents: 5328
diff changeset
2399 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
2400
5204
47f18579daae privsep: Implement pledge(2) support as found on OpenBSD
Roy Marples <roy@marples.name>
parents: 5197
diff changeset
2401 #ifdef PRIVSEP
5466
8bf1ce29152c privsep: sandbox the launcher process
Roy Marples <roy@marples.name>
parents: 5458
diff changeset
2402 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
2403 goto exit_failure;
5204
47f18579daae privsep: Implement pledge(2) support as found on OpenBSD
Roy Marples <roy@marples.name>
parents: 5197
diff changeset
2404 #endif
47f18579daae privsep: Implement pledge(2) support as found on OpenBSD
Roy Marples <roy@marples.name>
parents: 5197
diff changeset
2405
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2406 /* 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
2407 * 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
2408 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
2409 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
2410
4189
0b088d803b61 dhcp6: don't listen on IPv6 addresses when not using DHCP6
Roy Marples <roy@marples.name>
parents: 4184
diff changeset
2411 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
2412 if (ctx.ifaces == NULL) {
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 4008
diff changeset
2413 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
2414 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
2415 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2416 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
2417 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
2418 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
2419 ctx.ifv[i]);
4af70397cd7d dhcpcd: Improve error when interface does not exist vs invalid config
Roy Marples <roy@marples.name>
parents: 5088
diff changeset
2420 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
2421 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
2422 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
2423 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2424 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
2425 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
2426 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2427 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2428 if (ifp == NULL) {
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 4008
diff changeset
2429 if (ctx.ifc == 0) {
5064
7721231839f5 logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents: 5063
diff changeset
2430 int loglevel;
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 4008
diff changeset
2431
5064
7721231839f5 logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents: 5063
diff changeset
2432 loglevel = ctx.options & DHCPCD_INACTIVE ?
7721231839f5 logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents: 5063
diff changeset
2433 LOG_DEBUG : LOG_ERR;
7721231839f5 logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents: 5063
diff changeset
2434 logmessage(loglevel, "no valid interfaces found");
5148
5f4227456653 dhcpcd: daemomize if no valid interfaces found
Roy Marples <roy@marples.name>
parents: 5144
diff changeset
2435 dhcpcd_daemonise(&ctx);
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 4008
diff changeset
2436 } else
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2437 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
2438 if (!(ctx.options & DHCPCD_LINK)) {
4226
fdca1e4dfd1e dhcpcd: Don't report errno when aborting here.
Roy Marples <roy@marples.name>
parents: 4223
diff changeset
2439 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
2440 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
2441 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2442 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2443
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2444 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
2445 if (ifp->active)
4766
cacf3b10beef Revert "compat: Use more portable setproctitle from nginx"
Roy Marples <roy@marples.name>
parents: 4765
diff changeset
2446 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
2447 }
4189
0b088d803b61 dhcp6: don't listen on IPv6 addresses when not using DHCP6
Roy Marples <roy@marples.name>
parents: 4184
diff changeset
2448 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
2449
4856
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2450 if (ctx.options & DHCPCD_BACKGROUND)
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2451 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
2452
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2453 opt = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2454 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
2455 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
2456 run_preinit(ifp);
5499
6a2da5651841 dhcpcd: Simplify the link handling even more
Roy Marples <roy@marples.name>
parents: 5497
diff changeset
2457 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
2458 opt = 1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2459 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2460 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2461
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2462 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
2463 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
2464 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
2465 else {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2466 t = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2467 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
2468 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
2469 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
2470 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2471 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2472 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2473 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2474 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
2475 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
2476 !(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
2477 {
5064
7721231839f5 logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents: 5063
diff changeset
2478 int loglevel;
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 4008
diff changeset
2479
5064
7721231839f5 logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents: 5063
diff changeset
2480 loglevel = ctx.options & DHCPCD_INACTIVE ?
7721231839f5 logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents: 5063
diff changeset
2481 LOG_DEBUG : LOG_WARNING;
7721231839f5 logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents: 5063
diff changeset
2482 logmessage(loglevel, "no interfaces have a carrier");
4856
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2483 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
2484 } 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
2485 /* 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
2486 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
2487 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2488 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
2489 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
2490 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2491 }
4249
c30233f8cca3 routes: allow a head clear with a context
Roy Marples <roy@marples.name>
parents: 4246
diff changeset
2492 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
2493 ifo = NULL;
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 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
2496 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
2497 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
2498 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
2499 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2500
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4836
diff changeset
2501 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
2502 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
2503 if (i < 0) {
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 4008
diff changeset
2504 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
2505 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
2506 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2507 goto exit1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2508
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2509 exit_success:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2510 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
2511 goto exit1;
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 exit_failure:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2514 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
2515
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2516 exit1:
4989
ca9234046989 privsep: chroot the master process
Roy Marples <roy@marples.name>
parents: 4988
diff changeset
2517 if (control_stop(&ctx) == -1)
ca9234046989 privsep: chroot the master process
Roy Marples <roy@marples.name>
parents: 4988
diff changeset
2518 logerr("%s: control_stop", __func__);
5318
8611693d307f Linux: more freeifaddrs
Roy Marples <roy@marples.name>
parents: 5311
diff changeset
2519 if (ifaddrs != NULL) {
8611693d307f Linux: more freeifaddrs
Roy Marples <roy@marples.name>
parents: 5311
diff changeset
2520 #ifdef PRIVSEP_GETIFADDRS
8611693d307f Linux: more freeifaddrs
Roy Marples <roy@marples.name>
parents: 5311
diff changeset
2521 if (IN_PRIVSEP(&ctx))
8611693d307f Linux: more freeifaddrs
Roy Marples <roy@marples.name>
parents: 5311
diff changeset
2522 free(ifaddrs);
8611693d307f Linux: more freeifaddrs
Roy Marples <roy@marples.name>
parents: 5311
diff changeset
2523 else
8611693d307f Linux: more freeifaddrs
Roy Marples <roy@marples.name>
parents: 5311
diff changeset
2524 #endif
8611693d307f Linux: more freeifaddrs
Roy Marples <roy@marples.name>
parents: 5311
diff changeset
2525 freeifaddrs(ifaddrs);
8611693d307f Linux: more freeifaddrs
Roy Marples <roy@marples.name>
parents: 5311
diff changeset
2526 }
5470
d7a5671d08c5 privsep: Don't remove pidfile at exit
Roy Marples <roy@marples.name>
parents: 5467
diff changeset
2527 /* 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
2528 * 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
2529 oi = ctx.options & DHCPCD_PRIVSEP ? 1 : 0;
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4836
diff changeset
2530 #ifdef PRIVSEP
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4836
diff changeset
2531 ps_stop(&ctx);
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4836
diff changeset
2532 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2533 /* 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
2534 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
2535 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
2536 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
2537 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
2538 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2539 free(ctx.ifaces);
4797
f0b3096122f6 dhcpcd: Set ctx.ifaces to NULL after freeing
Roy Marples <roy@marples.name>
parents: 4777
diff changeset
2540 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
2541 }
4607
8e54887526a6 routes: Fix a NULL dereference error for global static routes
Roy Marples <roy@marples.name>
parents: 4583
diff changeset
2542 free_options(&ctx, ifo);
4583
4b6fda3e83d8 Free script buffers before exiting from a fork.
Roy Marples <roy@marples.name>
parents: 4582
diff changeset
2543 #ifdef HAVE_OPEN_MEMSTREAM
4b6fda3e83d8 Free script buffers before exiting from a fork.
Roy Marples <roy@marples.name>
parents: 4582
diff changeset
2544 if (ctx.script_fp)
4b6fda3e83d8 Free script buffers before exiting from a fork.
Roy Marples <roy@marples.name>
parents: 4582
diff changeset
2545 fclose(ctx.script_fp);
4b6fda3e83d8 Free script buffers before exiting from a fork.
Roy Marples <roy@marples.name>
parents: 4582
diff changeset
2546 #endif
4b6fda3e83d8 Free script buffers before exiting from a fork.
Roy Marples <roy@marples.name>
parents: 4582
diff changeset
2547 free(ctx.script_buf);
4b6fda3e83d8 Free script buffers before exiting from a fork.
Roy Marples <roy@marples.name>
parents: 4582
diff changeset
2548 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
2549 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
2550 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
2551 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
2552 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
2553 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
2554 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2555 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
2556 free_globals(&ctx);
4351
b7a9f2b43d50 IP6ND: Remove #defines for functions when INET6 is disabled
Roy Marples <roy@marples.name>
parents: 4349
diff changeset
2557 #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
2558 ipv6_ctxfree(&ctx);
4351
b7a9f2b43d50 IP6ND: Remove #defines for functions when INET6 is disabled
Roy Marples <roy@marples.name>
parents: 4349
diff changeset
2559 #endif
5262
f168a25dd330 privsep: Fix compile for prior without dev plugins
Roy Marples <roy@marples.name>
parents: 5260
diff changeset
2560 #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
2561 dev_stop(&ctx);
5262
f168a25dd330 privsep: Fix compile for prior without dev plugins
Roy Marples <roy@marples.name>
parents: 5260
diff changeset
2562 #endif
4851
b615d58905ad privsep: Use another eloop instead of a blocking read.
Roy Marples <roy@marples.name>
parents: 4850
diff changeset
2563 #ifdef PRIVSEP
b615d58905ad privsep: Use another eloop instead of a blocking read.
Roy Marples <roy@marples.name>
parents: 4850
diff changeset
2564 eloop_free(ctx.ps_eloop);
b615d58905ad privsep: Use another eloop instead of a blocking read.
Roy Marples <roy@marples.name>
parents: 4850
diff changeset
2565 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2566 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
2567 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
2568 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
2569 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
2570 loginfox(PACKAGE " exited");
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 4008
diff changeset
2571 logclose();
4027
afec1b835c80 Free logfile.
Roy Marples <roy@marples.name>
parents: 4024
diff changeset
2572 free(ctx.logfile);
5328
ea68407e5ac8 privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents: 5321
diff changeset
2573 free(ctx.ctl_buf);
4767
bc57b9b804a8 compat: Go back to linux specific setproctitle
Roy Marples <roy@marples.name>
parents: 4766
diff changeset
2574 #ifdef SETPROCTITLE_H
5507
78f2fda6ee5d compat: Use libbsd's setproctitle(3)
Roy Marples <roy@marples.name>
parents: 5503
diff changeset
2575 setproctitle_fini();
4767
bc57b9b804a8 compat: Go back to linux specific setproctitle
Roy Marples <roy@marples.name>
parents: 4766
diff changeset
2576 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2577 #ifdef USE_SIGNALS
5470
d7a5671d08c5 privsep: Don't remove pidfile at exit
Roy Marples <roy@marples.name>
parents: 5467
diff changeset
2578 if (ctx.options & DHCPCD_STARTED) {
4856
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2579 /* Try to detach from the launch process. */
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2580 if (ctx.fork_fd != -1 &&
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2581 write(ctx.fork_fd, &i, sizeof(i)) == -1)
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2582 logerr("%s: write", __func__);
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4851
diff changeset
2583 }
5470
d7a5671d08c5 privsep: Don't remove pidfile at exit
Roy Marples <roy@marples.name>
parents: 5467
diff changeset
2584 if (ctx.options & DHCPCD_FORKED || oi != 0)
d7a5671d08c5 privsep: Don't remove pidfile at exit
Roy Marples <roy@marples.name>
parents: 5467
diff changeset
2585 _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
2586 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2587 return i;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2588 }