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