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