Mercurial > hg > dhcpcd
annotate src/script.c @ 5577:4da45107d87a draft
script: Use rt_proto_add to ensure no duplicate interfaces on OpenBSD
OpenBSD allows matching priorities, so we need to take the interfaces
in the order given to ensure uniqueness.
| author | Roy Marples <roy@marples.name> |
|---|---|
| date | Mon, 18 Jan 2021 11:31:05 +0000 |
| parents | 465cc5abc6d6 |
| children |
| rev | line source |
|---|---|
|
5288
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
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 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
29 #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
|
30 #include <sys/uio.h> |
|
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/wait.h> |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
32 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
33 #include <netinet/in.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 <arpa/inet.h> |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
35 |
|
4618
7eb6c52adf99
script: assert that the env strings are correctly terminated
Roy Marples <roy@marples.name>
parents:
4592
diff
changeset
|
36 #include <assert.h> |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
37 #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
|
38 #include <errno.h> |
|
4994
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
39 #include <pwd.h> |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
40 #include <signal.h> |
|
3955
40c5dcedcd9d
Fix compile with posix_spawn now being required.
Roy Marples <roy@marples.name>
parents:
3932
diff
changeset
|
41 #include <spawn.h> |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
42 #include <stdarg.h> |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
43 #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
|
44 #include <string.h> |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
45 #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
|
46 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
47 #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
|
48 #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
|
49 #include "dhcp.h" |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
50 #include "dhcp6.h" |
|
4840
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4811
diff
changeset
|
51 #include "eloop.h" |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
52 #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
|
53 #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
|
54 #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
|
55 #include "ipv6nd.h" |
| 4010 | 56 #include "logerr.h" |
|
4840
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4811
diff
changeset
|
57 #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
|
58 #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
|
59 |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
60 #define DEFAULT_PATH "/usr/bin:/usr/sbin:/bin:/sbin" |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
61 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
62 static const char * const if_params[] = { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
63 "interface", |
|
4176
612d80156afd
dhcpcd-run-hooks(8) should not attempt to guess the protocol.
Roy Marples <roy@marples.name>
parents:
4023
diff
changeset
|
64 "protocol", |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
65 "reason", |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
66 "pid", |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
67 "ifcarrier", |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
68 "ifmetric", |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
69 "ifwireless", |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
70 "ifflags", |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
71 "ssid", |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
72 "profile", |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
73 "interface_order", |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
74 NULL |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
75 }; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
76 |
|
5567
4fe5c2a71254
hooks: add NOCARRIER_ROAMING reason
Roy Marples <roy@marples.name>
parents:
5535
diff
changeset
|
77 static const char * true_str = "true"; |
|
4fe5c2a71254
hooks: add NOCARRIER_ROAMING reason
Roy Marples <roy@marples.name>
parents:
5535
diff
changeset
|
78 static const char * false_str = "false"; |
|
4fe5c2a71254
hooks: add NOCARRIER_ROAMING reason
Roy Marples <roy@marples.name>
parents:
5535
diff
changeset
|
79 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
80 void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
81 if_printoptions(void) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
82 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
83 const char * const *p; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
84 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
85 for (p = if_params; *p; p++) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
86 printf(" - %s\n", *p); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
87 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
88 |
|
4840
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4811
diff
changeset
|
89 pid_t |
|
5123
9422e8c904d5
scripts: Run with an empty sigmask
Christos Zoulas <christos@zoulas.com>
parents:
5094
diff
changeset
|
90 script_exec(char *const *argv, char *const *env) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
91 { |
|
4811
dd1237e36c28
script: Ensure pid is initialised.
Roy Marples <roy@marples.name>
parents:
4794
diff
changeset
|
92 pid_t pid = 0; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
93 posix_spawnattr_t attr; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
94 int r; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
95 #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
|
96 size_t i; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
97 short flags; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
98 sigset_t defsigs; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
99 #else |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
100 UNUSED(ctx); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
101 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
102 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
103 /* posix_spawn is a safe way of executing another image |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
104 * and changing signals back to how they should be. */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
105 if (posix_spawnattr_init(&attr) == -1) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
106 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
107 #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
|
108 flags = POSIX_SPAWN_SETSIGMASK | POSIX_SPAWN_SETSIGDEF; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
109 posix_spawnattr_setflags(&attr, flags); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
110 sigemptyset(&defsigs); |
|
5123
9422e8c904d5
scripts: Run with an empty sigmask
Christos Zoulas <christos@zoulas.com>
parents:
5094
diff
changeset
|
111 posix_spawnattr_setsigmask(&attr, &defsigs); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
112 for (i = 0; i < dhcpcd_signals_len; i++) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
113 sigaddset(&defsigs, dhcpcd_signals[i]); |
|
5227
7406014c9120
dhcpcd: allow sigpipe in scripts.
Roy Marples <roy@marples.name>
parents:
5209
diff
changeset
|
114 for (i = 0; i < dhcpcd_signals_ignore_len; i++) |
|
7406014c9120
dhcpcd: allow sigpipe in scripts.
Roy Marples <roy@marples.name>
parents:
5209
diff
changeset
|
115 sigaddset(&defsigs, dhcpcd_signals_ignore[i]); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
116 posix_spawnattr_setsigdefault(&attr, &defsigs); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
117 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
118 errno = 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
119 r = posix_spawn(&pid, argv[0], NULL, &attr, argv, env); |
|
3981
4cc60b4c804b
Call posix_spawnattr_destroy after calling posix_spawn so that
Roy Marples <roy@marples.name>
parents:
3960
diff
changeset
|
120 posix_spawnattr_destroy(&attr); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
121 if (r) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
122 errno = r; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
123 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
124 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
125 return pid; |
|
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 #ifdef INET |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
129 static int |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
130 append_config(FILE *fp, const char *prefix, const char *const *config) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
131 { |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
132 size_t i; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
133 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
134 if (config == NULL) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
135 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
136 |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
137 /* Do we need to replace existing config rather than append? */ |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
138 for (i = 0; config[i] != NULL; i++) { |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
139 if (efprintf(fp, "%s_%s", prefix, config[i]) == -1) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
140 return -1; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
141 } |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
142 return 1; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
143 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
144 |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
145 #endif |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
146 |
|
4196
ed557660dc3d
hooks: set protocol to link for link layer events
Roy Marples <roy@marples.name>
parents:
4176
diff
changeset
|
147 #define PROTO_LINK 0 |
|
4176
612d80156afd
dhcpcd-run-hooks(8) should not attempt to guess the protocol.
Roy Marples <roy@marples.name>
parents:
4023
diff
changeset
|
148 #define PROTO_DHCP 1 |
|
612d80156afd
dhcpcd-run-hooks(8) should not attempt to guess the protocol.
Roy Marples <roy@marples.name>
parents:
4023
diff
changeset
|
149 #define PROTO_IPV4LL 2 |
|
612d80156afd
dhcpcd-run-hooks(8) should not attempt to guess the protocol.
Roy Marples <roy@marples.name>
parents:
4023
diff
changeset
|
150 #define PROTO_RA 3 |
|
612d80156afd
dhcpcd-run-hooks(8) should not attempt to guess the protocol.
Roy Marples <roy@marples.name>
parents:
4023
diff
changeset
|
151 #define PROTO_DHCP6 4 |
|
612d80156afd
dhcpcd-run-hooks(8) should not attempt to guess the protocol.
Roy Marples <roy@marples.name>
parents:
4023
diff
changeset
|
152 #define PROTO_STATIC6 5 |
|
612d80156afd
dhcpcd-run-hooks(8) should not attempt to guess the protocol.
Roy Marples <roy@marples.name>
parents:
4023
diff
changeset
|
153 static const char *protocols[] = { |
|
4196
ed557660dc3d
hooks: set protocol to link for link layer events
Roy Marples <roy@marples.name>
parents:
4176
diff
changeset
|
154 "link", |
|
4176
612d80156afd
dhcpcd-run-hooks(8) should not attempt to guess the protocol.
Roy Marples <roy@marples.name>
parents:
4023
diff
changeset
|
155 "dhcp", |
|
612d80156afd
dhcpcd-run-hooks(8) should not attempt to guess the protocol.
Roy Marples <roy@marples.name>
parents:
4023
diff
changeset
|
156 "ipv4ll", |
|
612d80156afd
dhcpcd-run-hooks(8) should not attempt to guess the protocol.
Roy Marples <roy@marples.name>
parents:
4023
diff
changeset
|
157 "ra", |
|
612d80156afd
dhcpcd-run-hooks(8) should not attempt to guess the protocol.
Roy Marples <roy@marples.name>
parents:
4023
diff
changeset
|
158 "dhcp6", |
|
612d80156afd
dhcpcd-run-hooks(8) should not attempt to guess the protocol.
Roy Marples <roy@marples.name>
parents:
4023
diff
changeset
|
159 "static6" |
|
612d80156afd
dhcpcd-run-hooks(8) should not attempt to guess the protocol.
Roy Marples <roy@marples.name>
parents:
4023
diff
changeset
|
160 }; |
|
612d80156afd
dhcpcd-run-hooks(8) should not attempt to guess the protocol.
Roy Marples <roy@marples.name>
parents:
4023
diff
changeset
|
161 |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
162 int |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
163 efprintf(FILE *fp, const char *fmt, ...) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
164 { |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
165 va_list args; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
166 int r; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
167 |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
168 va_start(args, fmt); |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
169 r = vfprintf(fp, fmt, args); |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
170 va_end(args); |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
171 if (r == -1) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
172 return -1; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
173 /* Write a trailing NULL so we can easily create env strings. */ |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
174 if (fputc('\0', fp) == EOF) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
175 return -1; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
176 return r; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
177 } |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
178 |
|
4840
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4811
diff
changeset
|
179 char ** |
| 4794 | 180 script_buftoenv(struct dhcpcd_ctx *ctx, char *buf, size_t len) |
| 181 { | |
| 182 char **env, **envp, *bufp, *endp; | |
| 183 size_t nenv; | |
| 184 | |
| 185 /* Count the terminated env strings. | |
| 186 * Assert that the terminations are correct. */ | |
| 187 nenv = 0; | |
| 188 endp = buf + len; | |
| 189 for (bufp = buf; bufp < endp; bufp++) { | |
| 190 if (*bufp == '\0') { | |
| 191 #ifndef NDEBUG | |
| 192 if (bufp + 1 < endp) | |
| 193 assert(*(bufp + 1) != '\0'); | |
| 194 #endif | |
| 195 nenv++; | |
| 196 } | |
| 197 } | |
| 198 assert(*(bufp - 1) == '\0'); | |
|
5288
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
199 if (nenv == 0) |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
200 return NULL; |
| 4794 | 201 |
| 202 if (ctx->script_envlen < nenv) { | |
| 203 env = reallocarray(ctx->script_env, nenv + 1, sizeof(*env)); | |
| 204 if (env == NULL) | |
| 205 return NULL; | |
| 206 ctx->script_env = env; | |
| 207 ctx->script_envlen = nenv; | |
| 208 } | |
| 209 | |
| 210 bufp = buf; | |
| 211 envp = ctx->script_env; | |
| 212 *envp++ = bufp++; | |
| 213 endp--; /* Avoid setting the last \0 to an invalid pointer */ | |
| 214 for (; bufp < endp; bufp++) { | |
| 215 if (*bufp == '\0') | |
| 216 *envp++ = bufp + 1; | |
| 217 } | |
| 218 *envp = NULL; | |
| 219 | |
| 220 return ctx->script_env; | |
| 221 } | |
| 222 | |
|
4621
0a612323151a
script: Send the actual env len, not the buffer size to listeners.
Roy Marples <roy@marples.name>
parents:
4620
diff
changeset
|
223 static long |
|
4994
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
224 make_env(struct dhcpcd_ctx *ctx, const struct interface *ifp, |
|
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
225 const char *reason) |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
226 { |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
227 FILE *fp; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
228 long buf_pos, i; |
| 4794 | 229 char *path; |
| 4582 | 230 int protocol = PROTO_LINK; |
|
4994
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
231 const struct if_options *ifo; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
232 const struct interface *ifp2; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
233 int af; |
|
5567
4fe5c2a71254
hooks: add NOCARRIER_ROAMING reason
Roy Marples <roy@marples.name>
parents:
5535
diff
changeset
|
234 bool is_stdin = ifp->name[0] == '\0'; |
|
4fe5c2a71254
hooks: add NOCARRIER_ROAMING reason
Roy Marples <roy@marples.name>
parents:
5535
diff
changeset
|
235 const char *if_up, *if_down; |
|
4fe5c2a71254
hooks: add NOCARRIER_ROAMING reason
Roy Marples <roy@marples.name>
parents:
5535
diff
changeset
|
236 rb_tree_t ifaces; |
|
4fe5c2a71254
hooks: add NOCARRIER_ROAMING reason
Roy Marples <roy@marples.name>
parents:
5535
diff
changeset
|
237 struct rt *rt; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
238 #ifdef INET |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
239 const struct dhcp_state *state; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
240 #ifdef IPV4LL |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
241 const struct ipv4ll_state *istate; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
242 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
243 #endif |
|
4349
f87c2ed9ff46
DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents:
4333
diff
changeset
|
244 #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
|
245 const struct dhcp6_state *d6_state; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
246 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
247 |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
248 #ifdef HAVE_OPEN_MEMSTREAM |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
249 if (ctx->script_fp == NULL) { |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
250 fp = open_memstream(&ctx->script_buf, &ctx->script_buflen); |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
251 if (fp == NULL) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
252 goto eexit; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
253 ctx->script_fp = fp; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
254 } else { |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
255 fp = ctx->script_fp; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
256 rewind(fp); |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
257 } |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
258 #else |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
259 char tmpfile[] = "/tmp/dhcpcd-script-env-XXXXXX"; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
260 int tmpfd; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
261 |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
262 fp = NULL; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
263 tmpfd = mkstemp(tmpfile); |
|
5271
8fb09d31d388
For systems without open_memstream(3) warn that /tmp needs to exit
Roy Marples <roy@marples.name>
parents:
5259
diff
changeset
|
264 if (tmpfd == -1) { |
|
8fb09d31d388
For systems without open_memstream(3) warn that /tmp needs to exit
Roy Marples <roy@marples.name>
parents:
5259
diff
changeset
|
265 logerr("%s: mkstemp", __func__); |
|
8fb09d31d388
For systems without open_memstream(3) warn that /tmp needs to exit
Roy Marples <roy@marples.name>
parents:
5259
diff
changeset
|
266 return -1; |
|
8fb09d31d388
For systems without open_memstream(3) warn that /tmp needs to exit
Roy Marples <roy@marples.name>
parents:
5259
diff
changeset
|
267 } |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
268 unlink(tmpfile); |
|
4592
b61b15725a70
script: ensure that tmp files are removed
Roy Marples <roy@marples.name>
parents:
4582
diff
changeset
|
269 fp = fdopen(tmpfd, "w+"); |
|
b61b15725a70
script: ensure that tmp files are removed
Roy Marples <roy@marples.name>
parents:
4582
diff
changeset
|
270 if (fp == NULL) { |
|
b61b15725a70
script: ensure that tmp files are removed
Roy Marples <roy@marples.name>
parents:
4582
diff
changeset
|
271 close(tmpfd); |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
272 goto eexit; |
|
4592
b61b15725a70
script: ensure that tmp files are removed
Roy Marples <roy@marples.name>
parents:
4582
diff
changeset
|
273 } |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
274 #endif |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
275 |
|
5288
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
276 if (!(ifp->ctx->options & DHCPCD_DUMPLEASE)) { |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
277 /* Needed for scripts */ |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
278 path = getenv("PATH"); |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
279 if (efprintf(fp, "PATH=%s", |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
280 path == NULL ? DEFAULT_PATH : path) == -1) |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
281 goto eexit; |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
282 if (efprintf(fp, "pid=%d", getpid()) == -1) |
|
4994
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
283 goto eexit; |
|
4995
91c3d1ed3496
privsep: Note CHROOT script
Roy Marples <roy@marples.name>
parents:
4994
diff
changeset
|
284 } |
|
5567
4fe5c2a71254
hooks: add NOCARRIER_ROAMING reason
Roy Marples <roy@marples.name>
parents:
5535
diff
changeset
|
285 |
|
5288
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
286 if (!is_stdin) { |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
287 if (efprintf(fp, "reason=%s", reason) == -1) |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
288 goto eexit; |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
289 } |
|
4994
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
290 |
|
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
291 ifo = 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
|
292 #ifdef INET |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
293 state = D_STATE(ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
294 #ifdef IPV4LL |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
295 istate = IPV4LL_CSTATE(ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
296 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
297 #endif |
|
4349
f87c2ed9ff46
DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents:
4333
diff
changeset
|
298 #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
|
299 d6_state = D6_CSTATE(ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
300 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
301 if (strcmp(reason, "TEST") == 0) { |
|
4867
f06daa979f98
script: Document why this block is intentionally blank.
Roy Marples <roy@marples.name>
parents:
4840
diff
changeset
|
302 if (1 == 2) { |
|
f06daa979f98
script: Document why this block is intentionally blank.
Roy Marples <roy@marples.name>
parents:
4840
diff
changeset
|
303 /* This space left intentionally blank |
|
f06daa979f98
script: Document why this block is intentionally blank.
Roy Marples <roy@marples.name>
parents:
4840
diff
changeset
|
304 * as all the below statements are optional. */ |
|
f06daa979f98
script: Document why this block is intentionally blank.
Roy Marples <roy@marples.name>
parents:
4840
diff
changeset
|
305 } |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
306 #ifdef INET6 |
|
4349
f87c2ed9ff46
DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents:
4333
diff
changeset
|
307 #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
|
308 else if (d6_state && d6_state->new) |
|
4176
612d80156afd
dhcpcd-run-hooks(8) should not attempt to guess the protocol.
Roy Marples <roy@marples.name>
parents:
4023
diff
changeset
|
309 protocol = PROTO_DHCP6; |
|
4349
f87c2ed9ff46
DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents:
4333
diff
changeset
|
310 #endif |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
311 else if (ipv6nd_hasra(ifp)) |
|
4176
612d80156afd
dhcpcd-run-hooks(8) should not attempt to guess the protocol.
Roy Marples <roy@marples.name>
parents:
4023
diff
changeset
|
312 protocol = PROTO_RA; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
313 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
314 #ifdef INET |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
315 #ifdef IPV4LL |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
316 else if (istate && istate->addr != NULL) |
|
4176
612d80156afd
dhcpcd-run-hooks(8) should not attempt to guess the protocol.
Roy Marples <roy@marples.name>
parents:
4023
diff
changeset
|
317 protocol = PROTO_IPV4LL; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
318 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
319 else |
|
4176
612d80156afd
dhcpcd-run-hooks(8) should not attempt to guess the protocol.
Roy Marples <roy@marples.name>
parents:
4023
diff
changeset
|
320 protocol = PROTO_DHCP; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
321 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
322 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
323 #ifdef INET6 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
324 else if (strcmp(reason, "STATIC6") == 0) |
|
4176
612d80156afd
dhcpcd-run-hooks(8) should not attempt to guess the protocol.
Roy Marples <roy@marples.name>
parents:
4023
diff
changeset
|
325 protocol = PROTO_STATIC6; |
|
4349
f87c2ed9ff46
DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents:
4333
diff
changeset
|
326 #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
|
327 else if (reason[strlen(reason) - 1] == '6') |
|
4176
612d80156afd
dhcpcd-run-hooks(8) should not attempt to guess the protocol.
Roy Marples <roy@marples.name>
parents:
4023
diff
changeset
|
328 protocol = PROTO_DHCP6; |
|
4349
f87c2ed9ff46
DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents:
4333
diff
changeset
|
329 #endif |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
330 else if (strcmp(reason, "ROUTERADVERT") == 0) |
|
4176
612d80156afd
dhcpcd-run-hooks(8) should not attempt to guess the protocol.
Roy Marples <roy@marples.name>
parents:
4023
diff
changeset
|
331 protocol = PROTO_RA; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
332 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
333 else if (strcmp(reason, "PREINIT") == 0 || |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
334 strcmp(reason, "CARRIER") == 0 || |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
335 strcmp(reason, "NOCARRIER") == 0 || |
|
5567
4fe5c2a71254
hooks: add NOCARRIER_ROAMING reason
Roy Marples <roy@marples.name>
parents:
5535
diff
changeset
|
336 strcmp(reason, "NOCARRIER_ROAMING") == 0 || |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
337 strcmp(reason, "UNKNOWN") == 0 || |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
338 strcmp(reason, "DEPARTED") == 0 || |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
339 strcmp(reason, "STOPPED") == 0) |
|
4196
ed557660dc3d
hooks: set protocol to link for link layer events
Roy Marples <roy@marples.name>
parents:
4176
diff
changeset
|
340 protocol = PROTO_LINK; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
341 #ifdef INET |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
342 #ifdef IPV4LL |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
343 else if (strcmp(reason, "IPV4LL") == 0) |
|
4176
612d80156afd
dhcpcd-run-hooks(8) should not attempt to guess the protocol.
Roy Marples <roy@marples.name>
parents:
4023
diff
changeset
|
344 protocol = PROTO_IPV4LL; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
345 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
346 else |
|
4176
612d80156afd
dhcpcd-run-hooks(8) should not attempt to guess the protocol.
Roy Marples <roy@marples.name>
parents:
4023
diff
changeset
|
347 protocol = PROTO_DHCP; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
348 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
349 |
|
5288
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
350 if (!is_stdin) { |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
351 if (efprintf(fp, "interface=%s", ifp->name) == -1) |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
352 goto eexit; |
|
5379
ca610debb37b
script: Make visible some link level parameters to lease dumping
Roy Marples <roy@marples.name>
parents:
5328
diff
changeset
|
353 if (protocols[protocol] != NULL) { |
|
ca610debb37b
script: Make visible some link level parameters to lease dumping
Roy Marples <roy@marples.name>
parents:
5328
diff
changeset
|
354 if (efprintf(fp, "protocol=%s", |
|
ca610debb37b
script: Make visible some link level parameters to lease dumping
Roy Marples <roy@marples.name>
parents:
5328
diff
changeset
|
355 protocols[protocol]) == -1) |
|
ca610debb37b
script: Make visible some link level parameters to lease dumping
Roy Marples <roy@marples.name>
parents:
5328
diff
changeset
|
356 goto eexit; |
|
ca610debb37b
script: Make visible some link level parameters to lease dumping
Roy Marples <roy@marples.name>
parents:
5328
diff
changeset
|
357 } |
|
5288
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
358 } |
|
5379
ca610debb37b
script: Make visible some link level parameters to lease dumping
Roy Marples <roy@marples.name>
parents:
5328
diff
changeset
|
359 if (ifp->ctx->options & DHCPCD_DUMPLEASE && protocol != PROTO_LINK) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
360 goto dumplease; |
| 5535 | 361 if (efprintf(fp, "if_configured=%s", |
| 362 ifo->options & DHCPCD_CONFIGURE ? "true" : "false") == -1) | |
| 363 goto eexit; | |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
364 if (efprintf(fp, "ifcarrier=%s", |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
365 ifp->carrier == LINK_UNKNOWN ? "unknown" : |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
366 ifp->carrier == LINK_UP ? "up" : "down") == -1) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
367 goto eexit; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
368 if (efprintf(fp, "ifmetric=%d", ifp->metric) == -1) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
369 goto eexit; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
370 if (efprintf(fp, "ifwireless=%d", ifp->wireless) == -1) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
371 goto eexit; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
372 if (efprintf(fp, "ifflags=%u", ifp->flags) == -1) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
373 goto eexit; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
374 if (efprintf(fp, "ifmtu=%d", if_getmtu(ifp)) == -1) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
375 goto eexit; |
|
5379
ca610debb37b
script: Make visible some link level parameters to lease dumping
Roy Marples <roy@marples.name>
parents:
5328
diff
changeset
|
376 if (ifp->wireless) { |
|
ca610debb37b
script: Make visible some link level parameters to lease dumping
Roy Marples <roy@marples.name>
parents:
5328
diff
changeset
|
377 char pssid[IF_SSIDLEN * 4]; |
|
ca610debb37b
script: Make visible some link level parameters to lease dumping
Roy Marples <roy@marples.name>
parents:
5328
diff
changeset
|
378 |
|
ca610debb37b
script: Make visible some link level parameters to lease dumping
Roy Marples <roy@marples.name>
parents:
5328
diff
changeset
|
379 if (print_string(pssid, sizeof(pssid), OT_ESCSTRING, |
|
ca610debb37b
script: Make visible some link level parameters to lease dumping
Roy Marples <roy@marples.name>
parents:
5328
diff
changeset
|
380 ifp->ssid, ifp->ssid_len) != -1) |
|
ca610debb37b
script: Make visible some link level parameters to lease dumping
Roy Marples <roy@marples.name>
parents:
5328
diff
changeset
|
381 { |
|
ca610debb37b
script: Make visible some link level parameters to lease dumping
Roy Marples <roy@marples.name>
parents:
5328
diff
changeset
|
382 if (efprintf(fp, "ifssid=%s", pssid) == -1) |
|
ca610debb37b
script: Make visible some link level parameters to lease dumping
Roy Marples <roy@marples.name>
parents:
5328
diff
changeset
|
383 goto eexit; |
|
ca610debb37b
script: Make visible some link level parameters to lease dumping
Roy Marples <roy@marples.name>
parents:
5328
diff
changeset
|
384 } |
|
ca610debb37b
script: Make visible some link level parameters to lease dumping
Roy Marples <roy@marples.name>
parents:
5328
diff
changeset
|
385 } |
|
ca610debb37b
script: Make visible some link level parameters to lease dumping
Roy Marples <roy@marples.name>
parents:
5328
diff
changeset
|
386 if (*ifp->profile != '\0') { |
|
ca610debb37b
script: Make visible some link level parameters to lease dumping
Roy Marples <roy@marples.name>
parents:
5328
diff
changeset
|
387 if (efprintf(fp, "profile=%s", ifp->profile) == -1) |
|
ca610debb37b
script: Make visible some link level parameters to lease dumping
Roy Marples <roy@marples.name>
parents:
5328
diff
changeset
|
388 goto eexit; |
|
ca610debb37b
script: Make visible some link level parameters to lease dumping
Roy Marples <roy@marples.name>
parents:
5328
diff
changeset
|
389 } |
|
ca610debb37b
script: Make visible some link level parameters to lease dumping
Roy Marples <roy@marples.name>
parents:
5328
diff
changeset
|
390 if (ifp->ctx->options & DHCPCD_DUMPLEASE) |
|
ca610debb37b
script: Make visible some link level parameters to lease dumping
Roy Marples <roy@marples.name>
parents:
5328
diff
changeset
|
391 goto dumplease; |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
392 |
|
5577
4da45107d87a
script: Use rt_proto_add to ensure no duplicate interfaces on OpenBSD
Roy Marples <roy@marples.name>
parents:
5575
diff
changeset
|
393 ifp->ctx->rt_order = 0; |
|
5567
4fe5c2a71254
hooks: add NOCARRIER_ROAMING reason
Roy Marples <roy@marples.name>
parents:
5535
diff
changeset
|
394 rb_tree_init(&ifaces, &rt_compare_proto_ops); |
|
4fe5c2a71254
hooks: add NOCARRIER_ROAMING reason
Roy Marples <roy@marples.name>
parents:
5535
diff
changeset
|
395 TAILQ_FOREACH(ifp2, ifp->ctx->ifaces, next) { |
|
5575
465cc5abc6d6
script: ignore inactive interfaces for ordering
Roy Marples <roy@marples.name>
parents:
5567
diff
changeset
|
396 if (!ifp2->active) |
|
465cc5abc6d6
script: ignore inactive interfaces for ordering
Roy Marples <roy@marples.name>
parents:
5567
diff
changeset
|
397 continue; |
|
5567
4fe5c2a71254
hooks: add NOCARRIER_ROAMING reason
Roy Marples <roy@marples.name>
parents:
5535
diff
changeset
|
398 rt = rt_new(UNCONST(ifp2)); |
|
4fe5c2a71254
hooks: add NOCARRIER_ROAMING reason
Roy Marples <roy@marples.name>
parents:
5535
diff
changeset
|
399 if (rt == NULL) |
|
4fe5c2a71254
hooks: add NOCARRIER_ROAMING reason
Roy Marples <roy@marples.name>
parents:
5535
diff
changeset
|
400 goto eexit; |
|
5577
4da45107d87a
script: Use rt_proto_add to ensure no duplicate interfaces on OpenBSD
Roy Marples <roy@marples.name>
parents:
5575
diff
changeset
|
401 if (rt_proto_add(&ifaces, rt) != rt) |
|
5567
4fe5c2a71254
hooks: add NOCARRIER_ROAMING reason
Roy Marples <roy@marples.name>
parents:
5535
diff
changeset
|
402 goto eexit; |
|
4fe5c2a71254
hooks: add NOCARRIER_ROAMING reason
Roy Marples <roy@marples.name>
parents:
5535
diff
changeset
|
403 } |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
404 if (fprintf(fp, "interface_order=") == -1) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
405 goto eexit; |
|
5567
4fe5c2a71254
hooks: add NOCARRIER_ROAMING reason
Roy Marples <roy@marples.name>
parents:
5535
diff
changeset
|
406 RB_TREE_FOREACH(rt, &ifaces) { |
|
4fe5c2a71254
hooks: add NOCARRIER_ROAMING reason
Roy Marples <roy@marples.name>
parents:
5535
diff
changeset
|
407 if (rt != RB_TREE_MIN(&ifaces) && |
|
4fe5c2a71254
hooks: add NOCARRIER_ROAMING reason
Roy Marples <roy@marples.name>
parents:
5535
diff
changeset
|
408 fprintf(fp, "%s", " ") == -1) |
|
4fe5c2a71254
hooks: add NOCARRIER_ROAMING reason
Roy Marples <roy@marples.name>
parents:
5535
diff
changeset
|
409 goto eexit; |
|
4fe5c2a71254
hooks: add NOCARRIER_ROAMING reason
Roy Marples <roy@marples.name>
parents:
5535
diff
changeset
|
410 if (fprintf(fp, "%s", rt->rt_ifp->name) == -1) |
|
4fe5c2a71254
hooks: add NOCARRIER_ROAMING reason
Roy Marples <roy@marples.name>
parents:
5535
diff
changeset
|
411 goto eexit; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
412 } |
|
5567
4fe5c2a71254
hooks: add NOCARRIER_ROAMING reason
Roy Marples <roy@marples.name>
parents:
5535
diff
changeset
|
413 rt_headclear(&ifaces, AF_UNSPEC); |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
414 if (fputc('\0', fp) == EOF) |
|
5567
4fe5c2a71254
hooks: add NOCARRIER_ROAMING reason
Roy Marples <roy@marples.name>
parents:
5535
diff
changeset
|
415 goto eexit; |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
416 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
417 if (strcmp(reason, "STOPPED") == 0) { |
|
5567
4fe5c2a71254
hooks: add NOCARRIER_ROAMING reason
Roy Marples <roy@marples.name>
parents:
5535
diff
changeset
|
418 if_up = false_str; |
|
4fe5c2a71254
hooks: add NOCARRIER_ROAMING reason
Roy Marples <roy@marples.name>
parents:
5535
diff
changeset
|
419 if_down = ifo->options & DHCPCD_RELEASE ? true_str : false_str; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
420 } else if (strcmp(reason, "TEST") == 0 || |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
421 strcmp(reason, "PREINIT") == 0 || |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
422 strcmp(reason, "CARRIER") == 0 || |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
423 strcmp(reason, "UNKNOWN") == 0) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
424 { |
|
5567
4fe5c2a71254
hooks: add NOCARRIER_ROAMING reason
Roy Marples <roy@marples.name>
parents:
5535
diff
changeset
|
425 if_up = false_str; |
|
4fe5c2a71254
hooks: add NOCARRIER_ROAMING reason
Roy Marples <roy@marples.name>
parents:
5535
diff
changeset
|
426 if_down = false_str; |
|
4fe5c2a71254
hooks: add NOCARRIER_ROAMING reason
Roy Marples <roy@marples.name>
parents:
5535
diff
changeset
|
427 } else if (strcmp(reason, "NOCARRIER") == 0) { |
|
4fe5c2a71254
hooks: add NOCARRIER_ROAMING reason
Roy Marples <roy@marples.name>
parents:
5535
diff
changeset
|
428 if_up = false_str; |
|
4fe5c2a71254
hooks: add NOCARRIER_ROAMING reason
Roy Marples <roy@marples.name>
parents:
5535
diff
changeset
|
429 if_down = true_str; |
|
4fe5c2a71254
hooks: add NOCARRIER_ROAMING reason
Roy Marples <roy@marples.name>
parents:
5535
diff
changeset
|
430 } else if (strcmp(reason, "NOCARRIER_ROAMING") == 0) { |
|
4fe5c2a71254
hooks: add NOCARRIER_ROAMING reason
Roy Marples <roy@marples.name>
parents:
5535
diff
changeset
|
431 if_up = true_str; |
|
4fe5c2a71254
hooks: add NOCARRIER_ROAMING reason
Roy Marples <roy@marples.name>
parents:
5535
diff
changeset
|
432 if_down = false_str; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
433 } else if (1 == 2 /* appease ifdefs */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
434 #ifdef INET |
|
4176
612d80156afd
dhcpcd-run-hooks(8) should not attempt to guess the protocol.
Roy Marples <roy@marples.name>
parents:
4023
diff
changeset
|
435 || (protocol == PROTO_DHCP && state && state->new) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
436 #ifdef IPV4LL |
|
4176
612d80156afd
dhcpcd-run-hooks(8) should not attempt to guess the protocol.
Roy Marples <roy@marples.name>
parents:
4023
diff
changeset
|
437 || (protocol == PROTO_IPV4LL && IPV4LL_STATE_RUNNING(ifp)) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
438 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
439 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
440 #ifdef INET6 |
|
4176
612d80156afd
dhcpcd-run-hooks(8) should not attempt to guess the protocol.
Roy Marples <roy@marples.name>
parents:
4023
diff
changeset
|
441 || (protocol == PROTO_STATIC6 && IPV6_STATE_RUNNING(ifp)) |
|
4349
f87c2ed9ff46
DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents:
4333
diff
changeset
|
442 #ifdef DHCP6 |
|
4176
612d80156afd
dhcpcd-run-hooks(8) should not attempt to guess the protocol.
Roy Marples <roy@marples.name>
parents:
4023
diff
changeset
|
443 || (protocol == PROTO_DHCP6 && d6_state && d6_state->new) |
|
4349
f87c2ed9ff46
DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents:
4333
diff
changeset
|
444 #endif |
|
4176
612d80156afd
dhcpcd-run-hooks(8) should not attempt to guess the protocol.
Roy Marples <roy@marples.name>
parents:
4023
diff
changeset
|
445 || (protocol == PROTO_RA && ipv6nd_hasra(ifp)) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
446 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
447 ) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
448 { |
|
5567
4fe5c2a71254
hooks: add NOCARRIER_ROAMING reason
Roy Marples <roy@marples.name>
parents:
5535
diff
changeset
|
449 if_up = true_str; |
|
4fe5c2a71254
hooks: add NOCARRIER_ROAMING reason
Roy Marples <roy@marples.name>
parents:
5535
diff
changeset
|
450 if_down = false_str; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
451 } else { |
|
5567
4fe5c2a71254
hooks: add NOCARRIER_ROAMING reason
Roy Marples <roy@marples.name>
parents:
5535
diff
changeset
|
452 if_up = false_str; |
|
4fe5c2a71254
hooks: add NOCARRIER_ROAMING reason
Roy Marples <roy@marples.name>
parents:
5535
diff
changeset
|
453 if_down = true_str; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
454 } |
|
5567
4fe5c2a71254
hooks: add NOCARRIER_ROAMING reason
Roy Marples <roy@marples.name>
parents:
5535
diff
changeset
|
455 if (efprintf(fp, "if_up=%s", if_up) == -1) |
|
4fe5c2a71254
hooks: add NOCARRIER_ROAMING reason
Roy Marples <roy@marples.name>
parents:
5535
diff
changeset
|
456 goto eexit; |
|
4fe5c2a71254
hooks: add NOCARRIER_ROAMING reason
Roy Marples <roy@marples.name>
parents:
5535
diff
changeset
|
457 if (efprintf(fp, "if_down=%s", if_down) == -1) |
|
4fe5c2a71254
hooks: add NOCARRIER_ROAMING reason
Roy Marples <roy@marples.name>
parents:
5535
diff
changeset
|
458 goto eexit; |
|
4fe5c2a71254
hooks: add NOCARRIER_ROAMING reason
Roy Marples <roy@marples.name>
parents:
5535
diff
changeset
|
459 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
460 if ((af = dhcpcd_ifafwaiting(ifp)) != AF_MAX) { |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
461 if (efprintf(fp, "if_afwaiting=%d", af) == -1) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
462 goto eexit; |
|
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 ((af = dhcpcd_afwaiting(ifp->ctx)) != AF_MAX) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
465 TAILQ_FOREACH(ifp2, 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
|
466 if ((af = dhcpcd_ifafwaiting(ifp2)) != AF_MAX) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
467 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
468 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
469 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
470 if (af != AF_MAX) { |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
471 if (efprintf(fp, "af_waiting=%d", af) == -1) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
472 goto eexit; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
473 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
474 if (ifo->options & DHCPCD_DEBUG) { |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
475 if (efprintf(fp, "syslog_debug=true") == -1) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
476 goto eexit; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
477 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
478 #ifdef INET |
|
4176
612d80156afd
dhcpcd-run-hooks(8) should not attempt to guess the protocol.
Roy Marples <roy@marples.name>
parents:
4023
diff
changeset
|
479 if (protocol == PROTO_DHCP && state && state->old) { |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
480 if (dhcp_env(fp, "old", ifp, |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
481 state->old, state->old_len) == -1) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
482 goto eexit; |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
483 if (append_config(fp, "old", |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
484 (const char *const *)ifo->config) == -1) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
485 goto eexit; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
486 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
487 #endif |
|
4349
f87c2ed9ff46
DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents:
4333
diff
changeset
|
488 #ifdef DHCP6 |
|
4176
612d80156afd
dhcpcd-run-hooks(8) should not attempt to guess the protocol.
Roy Marples <roy@marples.name>
parents:
4023
diff
changeset
|
489 if (protocol == PROTO_DHCP6 && d6_state && d6_state->old) { |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
490 if (dhcp6_env(fp, "old", ifp, |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
491 d6_state->old, d6_state->old_len) == -1) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
492 goto eexit; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
493 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
494 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
495 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
496 dumplease: |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
497 #ifdef INET |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
498 #ifdef IPV4LL |
|
5011
ec0c1c259be4
IPv4LL: A state might not always exist when running the script.
Christos Zoulas <christos@netbsd.org>
parents:
4996
diff
changeset
|
499 if (protocol == PROTO_IPV4LL && istate) { |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
500 if (ipv4ll_env(fp, istate->down ? "old" : "new", ifp) == -1) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
501 goto eexit; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
502 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
503 #endif |
|
4176
612d80156afd
dhcpcd-run-hooks(8) should not attempt to guess the protocol.
Roy Marples <roy@marples.name>
parents:
4023
diff
changeset
|
504 if (protocol == PROTO_DHCP && state && state->new) { |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
505 if (dhcp_env(fp, "new", ifp, |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
506 state->new, state->new_len) == -1) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
507 goto eexit; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
508 if (append_config(fp, "new", |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
509 (const char *const *)ifo->config) == -1) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
510 goto eexit; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
511 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
512 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
513 #ifdef INET6 |
|
4176
612d80156afd
dhcpcd-run-hooks(8) should not attempt to guess the protocol.
Roy Marples <roy@marples.name>
parents:
4023
diff
changeset
|
514 if (protocol == PROTO_STATIC6) { |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
515 if (ipv6_env(fp, "new", ifp) == -1) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
516 goto eexit; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
517 } |
|
4349
f87c2ed9ff46
DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents:
4333
diff
changeset
|
518 #ifdef DHCP6 |
|
4176
612d80156afd
dhcpcd-run-hooks(8) should not attempt to guess the protocol.
Roy Marples <roy@marples.name>
parents:
4023
diff
changeset
|
519 if (protocol == PROTO_DHCP6 && D6_STATE_RUNNING(ifp)) { |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
520 if (dhcp6_env(fp, "new", ifp, |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
521 d6_state->new, d6_state->new_len) == -1) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
522 goto eexit; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
523 } |
|
4349
f87c2ed9ff46
DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents:
4333
diff
changeset
|
524 #endif |
|
4176
612d80156afd
dhcpcd-run-hooks(8) should not attempt to guess the protocol.
Roy Marples <roy@marples.name>
parents:
4023
diff
changeset
|
525 if (protocol == PROTO_RA) { |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
526 if (ipv6nd_env(fp, ifp) == -1) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
527 goto eexit; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
528 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
529 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
530 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
531 /* Add our base environment */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
532 if (ifo->environ) { |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
533 for (i = 0; ifo->environ[i] != NULL; i++) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
534 if (efprintf(fp, "%s", ifo->environ[i]) == -1) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
535 goto eexit; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
536 } |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
537 |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
538 /* Convert buffer to argv */ |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
539 fflush(fp); |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
540 |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
541 buf_pos = ftell(fp); |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
542 if (buf_pos == -1) { |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
543 logerr(__func__); |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
544 goto eexit; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
545 } |
| 4620 | 546 |
| 547 #ifndef HAVE_OPEN_MEMSTREAM | |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
548 size_t buf_len = (size_t)buf_pos; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
549 if (ctx->script_buflen < buf_len) { |
| 4620 | 550 char *buf = realloc(ctx->script_buf, buf_len); |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
551 if (buf == NULL) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
552 goto eexit; |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
553 ctx->script_buf = buf; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
554 ctx->script_buflen = buf_len; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
555 } |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
556 rewind(fp); |
| 4620 | 557 if (fread(ctx->script_buf, sizeof(char), buf_len, fp) != buf_len) |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
558 goto eexit; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
559 fclose(fp); |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
560 fp = NULL; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
561 #endif |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
562 |
|
5288
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
563 if (is_stdin) |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
564 return buf_pos; |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
565 |
| 4794 | 566 if (script_buftoenv(ctx, ctx->script_buf, (size_t)buf_pos) == NULL) |
| 567 goto eexit; | |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
568 |
|
5092
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
569 return buf_pos; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
570 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
571 eexit: |
| 4010 | 572 logerr(__func__); |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
573 #ifndef HAVE_OPEN_MEMSTREAM |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
574 if (fp != NULL) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
575 fclose(fp); |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
576 #endif |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
577 return -1; |
|
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 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
580 static int |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
581 send_interface1(struct fd_list *fd, const struct interface *ifp, |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
582 const char *reason) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
583 { |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
584 struct dhcpcd_ctx *ctx = ifp->ctx; |
|
4621
0a612323151a
script: Send the actual env len, not the buffer size to listeners.
Roy Marples <roy@marples.name>
parents:
4620
diff
changeset
|
585 long len; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
586 |
|
4994
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
587 len = make_env(ifp->ctx, ifp, reason); |
|
4621
0a612323151a
script: Send the actual env len, not the buffer size to listeners.
Roy Marples <roy@marples.name>
parents:
4620
diff
changeset
|
588 if (len == -1) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
589 return -1; |
|
5328
ea68407e5ac8
privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents:
5288
diff
changeset
|
590 return control_queue(fd, ctx->script_buf, (size_t)len); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
591 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
592 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
593 int |
|
5092
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
594 send_interface(struct fd_list *fd, const struct interface *ifp, int af) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
595 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
596 int retval = 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
597 #ifdef INET |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
598 const struct dhcp_state *d; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
599 #endif |
|
4349
f87c2ed9ff46
DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents:
4333
diff
changeset
|
600 #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
|
601 const struct dhcp6_state *d6; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
602 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
603 |
| 5094 | 604 #ifndef AF_LINK |
| 605 #define AF_LINK AF_PACKET | |
| 606 #endif | |
| 607 | |
|
5092
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
608 if (af == AF_UNSPEC || af == AF_LINK) { |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
609 const char *reason; |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
610 |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
611 switch (ifp->carrier) { |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
612 case LINK_UP: |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
613 reason = "CARRIER"; |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
614 break; |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
615 case LINK_DOWN: |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
616 reason = "NOCARRIER"; |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
617 break; |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
618 default: |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
619 reason = "UNKNOWN"; |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
620 break; |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
621 } |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
622 if (fd != NULL) { |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
623 if (send_interface1(fd, ifp, reason) == -1) |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
624 retval = -1; |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
625 } else |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
626 retval++; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
627 } |
|
5092
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
628 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
629 #ifdef INET |
|
5092
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
630 if (af == AF_UNSPEC || af == AF_INET) { |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
631 if (D_STATE_RUNNING(ifp)) { |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
632 d = D_CSTATE(ifp); |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
633 if (fd != NULL) { |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
634 if (send_interface1(fd, ifp, d->reason) == -1) |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
635 retval = -1; |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
636 } else |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
637 retval++; |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
638 } |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
639 #ifdef IPV4LL |
|
5092
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
640 if (IPV4LL_STATE_RUNNING(ifp)) { |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
641 if (fd != NULL) { |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
642 if (send_interface1(fd, ifp, "IPV4LL") == -1) |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
643 retval = -1; |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
644 } else |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
645 retval++; |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
646 } |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
647 #endif |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
648 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
649 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
650 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
651 #ifdef INET6 |
|
5092
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
652 if (af == AF_UNSPEC || af == AF_INET6) { |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
653 if (IPV6_STATE_RUNNING(ifp)) { |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
654 if (fd != NULL) { |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
655 if (send_interface1(fd, ifp, "STATIC6") == -1) |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
656 retval = -1; |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
657 } else |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
658 retval++; |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
659 } |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
660 if (RS_STATE_RUNNING(ifp)) { |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
661 if (fd != NULL) { |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
662 if (send_interface1(fd, ifp, |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
663 "ROUTERADVERT") == -1) |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
664 retval = -1; |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
665 } else |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
666 retval++; |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
667 } |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
668 #ifdef DHCP6 |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
669 if (D6_STATE_RUNNING(ifp)) { |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
670 d6 = D6_CSTATE(ifp); |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
671 if (fd != NULL) { |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
672 if (send_interface1(fd, ifp, d6->reason) == -1) |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
673 retval = -1; |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
674 } else |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
675 retval++; |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
676 } |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
677 #endif |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
678 } |
|
4349
f87c2ed9ff46
DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents:
4333
diff
changeset
|
679 #endif |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
680 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
681 return retval; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
682 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
683 |
|
4994
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
684 static int |
|
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
685 script_run(struct dhcpcd_ctx *ctx, char **argv) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
686 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
687 pid_t pid; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
688 int status = 0; |
|
4840
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4811
diff
changeset
|
689 |
|
5123
9422e8c904d5
scripts: Run with an empty sigmask
Christos Zoulas <christos@zoulas.com>
parents:
5094
diff
changeset
|
690 pid = script_exec(argv, 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
|
691 if (pid == -1) |
| 4010 | 692 logerr("%s: %s", __func__, 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
|
693 else if (pid != 0) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
694 /* Wait for the script to finish */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
695 while (waitpid(pid, &status, 0) == -1) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
696 if (errno != EINTR) { |
| 4010 | 697 logerr("%s: waitpid", __func__); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
698 status = 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
699 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
700 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
701 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
702 if (WIFEXITED(status)) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
703 if (WEXITSTATUS(status)) |
| 4010 | 704 logerrx("%s: %s: WEXITSTATUS %d", |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
705 __func__, argv[0], WEXITSTATUS(status)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
706 } else if (WIFSIGNALED(status)) |
| 4010 | 707 logerrx("%s: %s: %s", |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
708 __func__, argv[0], strsignal(WTERMSIG(status))); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
709 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
710 |
|
4994
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
711 return WEXITSTATUS(status); |
|
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
712 } |
|
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
713 |
|
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
714 int |
|
5288
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
715 script_dump(const char *env, size_t len) |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
716 { |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
717 const char *ep = env + len; |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
718 |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
719 if (len == 0) |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
720 return 0; |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
721 |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
722 if (*(ep - 1) != '\0') { |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
723 errno = EINVAL; |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
724 return -1; |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
725 } |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
726 |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
727 for (; env < ep; env += strlen(env) + 1) { |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
728 if (strncmp(env, "new_", 4) == 0) |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
729 env += 4; |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
730 printf("%s\n", env); |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
731 } |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
732 return 0; |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
733 } |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
734 |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
735 int |
|
4994
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
736 script_runreason(const struct interface *ifp, const char *reason) |
|
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
737 { |
|
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
738 struct dhcpcd_ctx *ctx = ifp->ctx; |
|
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
739 char *argv[2]; |
|
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
740 int status = 0; |
|
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
741 struct fd_list *fd; |
|
5288
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
742 long buflen; |
|
4994
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
743 |
|
5255
ee23398a68db
dhcpcd: Move the script file from per interface to global context
Roy Marples <roy@marples.name>
parents:
5227
diff
changeset
|
744 if (ctx->script == NULL && |
|
4994
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
745 TAILQ_FIRST(&ifp->ctx->control_fds) == NULL) |
|
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
746 return 0; |
|
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
747 |
|
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
748 /* Make our env */ |
|
5288
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
749 if ((buflen = make_env(ifp->ctx, ifp, reason)) == -1) { |
|
4994
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
750 logerr(__func__); |
|
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
751 return -1; |
|
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
752 } |
|
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
753 |
|
5288
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
754 if (strncmp(reason, "DUMP", 4) == 0) |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
755 return script_dump(ctx->script_buf, (size_t)buflen); |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
756 |
|
5255
ee23398a68db
dhcpcd: Move the script file from per interface to global context
Roy Marples <roy@marples.name>
parents:
5227
diff
changeset
|
757 if (ctx->script == NULL) |
|
4994
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
758 goto send_listeners; |
|
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
759 |
|
5255
ee23398a68db
dhcpcd: Move the script file from per interface to global context
Roy Marples <roy@marples.name>
parents:
5227
diff
changeset
|
760 argv[0] = ctx->script; |
|
4994
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
761 argv[1] = NULL; |
| 5494 | 762 logdebugx("%s: executing: %s %s", ifp->name, argv[0], reason); |
|
4994
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
763 |
|
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
764 #ifdef PRIVSEP |
|
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
765 if (ctx->options & DHCPCD_PRIVSEP) { |
|
5255
ee23398a68db
dhcpcd: Move the script file from per interface to global context
Roy Marples <roy@marples.name>
parents:
5227
diff
changeset
|
766 if (ps_root_script(ctx, |
|
4994
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
767 ctx->script_buf, ctx->script_buflen) == -1) |
|
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
768 logerr(__func__); |
|
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
769 goto send_listeners; |
|
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
770 } |
|
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
771 #endif |
|
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
772 |
|
5280
a986083da0ba
Fix some clang analyzer issues
Roy Marples <roy@marples.name>
parents:
5271
diff
changeset
|
773 script_run(ctx, argv); |
|
4994
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
774 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
775 send_listeners: |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
776 /* Send to our listeners */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
777 status = 0; |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
778 TAILQ_FOREACH(fd, &ctx->control_fds, next) { |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
779 if (!(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
|
780 continue; |
|
5328
ea68407e5ac8
privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents:
5288
diff
changeset
|
781 if (control_queue(fd, ctx->script_buf, ctx->script_buflen)== -1) |
| 4010 | 782 logerr("%s: control_queue", __func__); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
783 else |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
784 status = 1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
785 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
786 |
|
4994
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
787 return status; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
788 } |
