annotate src/dhcpcd.c @ 5557:e65d193a1960 draft

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