Mercurial > hg > dhcpcd
annotate src/if-linux.c @ 5557:e65d193a1960 draft
Linux: Support wireless IP roaming
This is achieved by checking that the interface is wireless,
IFF_UP and IFF_LOWER_UP are present, but IFF_RUNNING is missing.
This gives exactly the same support as modern NetBSD when carrier
loss is detected, but without the address verifications when the
carrier comes back as that needs to be handled in the kernel.
While IP setup is maintained, other configuration data is discarded.
Note that this should be improved in the future.
Thanks to Boris Krasnovskiy <borkra@gmail.com> for helping with this.
| author | Roy Marples <roy@marples.name> |
|---|---|
| date | Sat, 12 Dec 2020 13:12:26 +0000 |
| parents | 605f7f9a20c0 |
| children | dd1e6f7adadd |
| rev | line source |
|---|---|
|
4548
c7df03794de3
Add SPDX identifiers to all dhcpcd source files.
Yegor Yefremov <yegorslists@googlemail.com>
parents:
4521
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 * Linux interface driver for dhcpcd |
| 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 <asm/types.h> /* Needed for 2.4 kernels */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
30 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
31 #include <sys/types.h> |
|
4052
08038b46c0f5
Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents:
4026
diff
changeset
|
32 #include <sys/ioctl.h> |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
33 #include <sys/socket.h> |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
34 #include <sys/param.h> |
|
4750
121555ba3cbe
Linux: Ignore TAP and Bridge interfaces by default
Roy Marples <roy@marples.name>
parents:
4748
diff
changeset
|
35 #include <sys/stat.h> |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
36 |
|
5130
d34c808ae81e
Linux: Note router preference when adding routes
Roy Marples <roy@marples.name>
parents:
5115
diff
changeset
|
37 #include <linux/icmpv6.h> |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
38 #include <linux/if_addr.h> |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
39 #include <linux/if_link.h> |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
40 #include <linux/if_packet.h> |
|
4750
121555ba3cbe
Linux: Ignore TAP and Bridge interfaces by default
Roy Marples <roy@marples.name>
parents:
4748
diff
changeset
|
41 #include <linux/if_tun.h> |
|
4052
08038b46c0f5
Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents:
4026
diff
changeset
|
42 #include <linux/if_vlan.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 <linux/filter.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 <linux/netlink.h> |
|
4052
08038b46c0f5
Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents:
4026
diff
changeset
|
45 #include <linux/sockios.h> |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
46 #include <linux/rtnetlink.h> |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
47 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
48 #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
|
49 #include <net/if.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 <netinet/in_systm.h> |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
51 #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
|
52 #include <net/route.h> |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
53 |
|
4778
6640d0cfd4e0
Fix building on systems with musl (#10)
Peter Bui <pbui@github.bx612.space>
parents:
4757
diff
changeset
|
54 /* musl has its own definition of struct ethhdr, so only include |
|
6640d0cfd4e0
Fix building on systems with musl (#10)
Peter Bui <pbui@github.bx612.space>
parents:
4757
diff
changeset
|
55 * netinet/if_ether.h on systems with GLIBC. For the ARPHRD constants, |
|
6640d0cfd4e0
Fix building on systems with musl (#10)
Peter Bui <pbui@github.bx612.space>
parents:
4757
diff
changeset
|
56 * we must include linux/if_arp.h instead. */ |
|
6640d0cfd4e0
Fix building on systems with musl (#10)
Peter Bui <pbui@github.bx612.space>
parents:
4757
diff
changeset
|
57 #if defined(__GLIBC__) |
|
6640d0cfd4e0
Fix building on systems with musl (#10)
Peter Bui <pbui@github.bx612.space>
parents:
4757
diff
changeset
|
58 #include <netinet/if_ether.h> |
|
6640d0cfd4e0
Fix building on systems with musl (#10)
Peter Bui <pbui@github.bx612.space>
parents:
4757
diff
changeset
|
59 #else |
|
6640d0cfd4e0
Fix building on systems with musl (#10)
Peter Bui <pbui@github.bx612.space>
parents:
4757
diff
changeset
|
60 #include <linux/if_arp.h> |
|
6640d0cfd4e0
Fix building on systems with musl (#10)
Peter Bui <pbui@github.bx612.space>
parents:
4757
diff
changeset
|
61 #endif |
|
6640d0cfd4e0
Fix building on systems with musl (#10)
Peter Bui <pbui@github.bx612.space>
parents:
4757
diff
changeset
|
62 |
|
5457
7fb0274b9127
Linux: detect network namespace and deny udev in one
Roy Marples <roy@marples.name>
parents:
5414
diff
changeset
|
63 #include <dirent.h> |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
64 #include <errno.h> |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
65 #include <fcntl.h> |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
66 #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
|
67 #include <stdbool.h> |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
68 #include <stddef.h> |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
69 #include <stdio.h> |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
70 #include <stdlib.h> |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
71 #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
|
72 #include <time.h> |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
73 #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
|
74 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
75 #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
|
76 #include "bpf.h" |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
77 #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
|
78 #include "dev.h" |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
79 #include "dhcp.h" |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
80 #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
|
81 #include "ipv4.h" |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
82 #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
|
83 #include "ipv6.h" |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
84 #include "ipv6nd.h" |
| 4010 | 85 #include "logerr.h" |
|
4840
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4828
diff
changeset
|
86 #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
|
87 #include "route.h" |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
88 #include "sa.h" |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
89 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
90 #ifdef HAVE_NL80211_H |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
91 #include <linux/genetlink.h> |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
92 #include <linux/nl80211.h> |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
93 #else |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
94 int if_getssid_wext(const char *ifname, uint8_t *ssid); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
95 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
96 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
97 /* Support older kernels */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
98 #ifndef IFLA_WIRELESS |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
99 #define IFLA_WIRELESS (IFLA_MASTER + 1) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
100 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
101 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
102 /* For some reason, glibc doesn't include newer flags from linux/if.h |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
103 * However, we cannot include linux/if.h directly as it conflicts |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
104 * with the glibc version. D'oh! */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
105 #ifndef IFF_LOWER_UP |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
106 #define IFF_LOWER_UP 0x10000 /* driver signals L1 up */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
107 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
108 |
|
4366
702f7b1412c1
linux: Fix compile on old RedHat/CentOS systems
Roy Marples <roy@marples.name>
parents:
4335
diff
changeset
|
109 /* Buggy CentOS and RedHat */ |
|
702f7b1412c1
linux: Fix compile on old RedHat/CentOS systems
Roy Marples <roy@marples.name>
parents:
4335
diff
changeset
|
110 #ifndef SOL_NETLINK |
|
702f7b1412c1
linux: Fix compile on old RedHat/CentOS systems
Roy Marples <roy@marples.name>
parents:
4335
diff
changeset
|
111 #define SOL_NETLINK 270 |
|
702f7b1412c1
linux: Fix compile on old RedHat/CentOS systems
Roy Marples <roy@marples.name>
parents:
4335
diff
changeset
|
112 #endif |
|
702f7b1412c1
linux: Fix compile on old RedHat/CentOS systems
Roy Marples <roy@marples.name>
parents:
4335
diff
changeset
|
113 |
|
5388
9bb47d579f62
Linux: redefine NLA_ALIGNTO as 4U
Roy Marples <roy@marples.name>
parents:
5387
diff
changeset
|
114 /* |
|
9bb47d579f62
Linux: redefine NLA_ALIGNTO as 4U
Roy Marples <roy@marples.name>
parents:
5387
diff
changeset
|
115 * Someone should fix kernel headers for clang alignment warnings. |
|
9bb47d579f62
Linux: redefine NLA_ALIGNTO as 4U
Roy Marples <roy@marples.name>
parents:
5387
diff
changeset
|
116 * But this is unlikely. |
|
9bb47d579f62
Linux: redefine NLA_ALIGNTO as 4U
Roy Marples <roy@marples.name>
parents:
5387
diff
changeset
|
117 * https://www.spinics.net/lists/netdev/msg646934.html |
|
9bb47d579f62
Linux: redefine NLA_ALIGNTO as 4U
Roy Marples <roy@marples.name>
parents:
5387
diff
changeset
|
118 */ |
|
9bb47d579f62
Linux: redefine NLA_ALIGNTO as 4U
Roy Marples <roy@marples.name>
parents:
5387
diff
changeset
|
119 |
|
9bb47d579f62
Linux: redefine NLA_ALIGNTO as 4U
Roy Marples <roy@marples.name>
parents:
5387
diff
changeset
|
120 #undef NLA_ALIGNTO |
|
9bb47d579f62
Linux: redefine NLA_ALIGNTO as 4U
Roy Marples <roy@marples.name>
parents:
5387
diff
changeset
|
121 #undef NLA_ALIGN |
|
9bb47d579f62
Linux: redefine NLA_ALIGNTO as 4U
Roy Marples <roy@marples.name>
parents:
5387
diff
changeset
|
122 #undef NLA_HDRLEN |
|
9bb47d579f62
Linux: redefine NLA_ALIGNTO as 4U
Roy Marples <roy@marples.name>
parents:
5387
diff
changeset
|
123 #define NLA_ALIGNTO 4U |
|
9bb47d579f62
Linux: redefine NLA_ALIGNTO as 4U
Roy Marples <roy@marples.name>
parents:
5387
diff
changeset
|
124 #define NLA_ALIGN(len) (((len) + NLA_ALIGNTO - 1) & ~(NLA_ALIGNTO - 1)) |
|
9bb47d579f62
Linux: redefine NLA_ALIGNTO as 4U
Roy Marples <roy@marples.name>
parents:
5387
diff
changeset
|
125 #define NLA_HDRLEN ((int) NLA_ALIGN(sizeof(struct nlattr))) |
|
9bb47d579f62
Linux: redefine NLA_ALIGNTO as 4U
Roy Marples <roy@marples.name>
parents:
5387
diff
changeset
|
126 |
|
4885
c6dd4ab0a843
Linux: work around alignment isses with clang
Roy Marples <roy@marples.name>
parents:
4884
diff
changeset
|
127 #undef IFA_RTA |
|
c6dd4ab0a843
Linux: work around alignment isses with clang
Roy Marples <roy@marples.name>
parents:
4884
diff
changeset
|
128 #define IFA_RTA(r) ((struct rtattr *)(void *)(((char *)(r)) \ |
|
c6dd4ab0a843
Linux: work around alignment isses with clang
Roy Marples <roy@marples.name>
parents:
4884
diff
changeset
|
129 + NLMSG_ALIGN(sizeof(struct ifaddrmsg)))) |
|
c6dd4ab0a843
Linux: work around alignment isses with clang
Roy Marples <roy@marples.name>
parents:
4884
diff
changeset
|
130 #undef IFLA_RTA |
|
c6dd4ab0a843
Linux: work around alignment isses with clang
Roy Marples <roy@marples.name>
parents:
4884
diff
changeset
|
131 #define IFLA_RTA(r) ((struct rtattr *)(void *)(((char *)(r)) \ |
|
c6dd4ab0a843
Linux: work around alignment isses with clang
Roy Marples <roy@marples.name>
parents:
4884
diff
changeset
|
132 + NLMSG_ALIGN(sizeof(struct ifinfomsg)))) |
|
c6dd4ab0a843
Linux: work around alignment isses with clang
Roy Marples <roy@marples.name>
parents:
4884
diff
changeset
|
133 #undef NLMSG_NEXT |
|
c6dd4ab0a843
Linux: work around alignment isses with clang
Roy Marples <roy@marples.name>
parents:
4884
diff
changeset
|
134 #define NLMSG_NEXT(nlh, len) ((len) -= NLMSG_ALIGN((nlh)->nlmsg_len), \ |
|
c6dd4ab0a843
Linux: work around alignment isses with clang
Roy Marples <roy@marples.name>
parents:
4884
diff
changeset
|
135 (struct nlmsghdr *)(void *)(((char *)(nlh)) \ |
|
c6dd4ab0a843
Linux: work around alignment isses with clang
Roy Marples <roy@marples.name>
parents:
4884
diff
changeset
|
136 + NLMSG_ALIGN((nlh)->nlmsg_len))) |
|
c6dd4ab0a843
Linux: work around alignment isses with clang
Roy Marples <roy@marples.name>
parents:
4884
diff
changeset
|
137 #undef RTM_RTA |
|
c6dd4ab0a843
Linux: work around alignment isses with clang
Roy Marples <roy@marples.name>
parents:
4884
diff
changeset
|
138 #define RTM_RTA(r) (void *)(((char *)(r)) + NLMSG_ALIGN(sizeof(struct rtmsg))) |
|
c6dd4ab0a843
Linux: work around alignment isses with clang
Roy Marples <roy@marples.name>
parents:
4884
diff
changeset
|
139 #undef RTA_NEXT |
|
c6dd4ab0a843
Linux: work around alignment isses with clang
Roy Marples <roy@marples.name>
parents:
4884
diff
changeset
|
140 #define RTA_NEXT(rta, attrlen) ((attrlen) -= RTA_ALIGN((rta)->rta_len), \ |
|
c6dd4ab0a843
Linux: work around alignment isses with clang
Roy Marples <roy@marples.name>
parents:
4884
diff
changeset
|
141 (struct rtattr *)(void *)(((char *)(rta)) \ |
|
c6dd4ab0a843
Linux: work around alignment isses with clang
Roy Marples <roy@marples.name>
parents:
4884
diff
changeset
|
142 + RTA_ALIGN((rta)->rta_len))) |
|
c6dd4ab0a843
Linux: work around alignment isses with clang
Roy Marples <roy@marples.name>
parents:
4884
diff
changeset
|
143 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
144 struct priv { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
145 int route_fd; |
|
5386
b28b0962bfe2
Linux: keep the generic netlink socket around to get ssid with privsep
Roy Marples <roy@marples.name>
parents:
5384
diff
changeset
|
146 int generic_fd; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
147 uint32_t route_pid; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
148 }; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
149 |
|
4147
dba5fa9d56cc
Comment out IPoIB broadcast address with a comment.
Roy Marples <roy@marples.name>
parents:
4113
diff
changeset
|
150 /* We need this to send a broadcast for InfiniBand. |
|
dba5fa9d56cc
Comment out IPoIB broadcast address with a comment.
Roy Marples <roy@marples.name>
parents:
4113
diff
changeset
|
151 * Our old code used sendto, but our new code writes to a raw BPF socket. |
|
dba5fa9d56cc
Comment out IPoIB broadcast address with a comment.
Roy Marples <roy@marples.name>
parents:
4113
diff
changeset
|
152 * What header structure does IPoIB use? */ |
|
dba5fa9d56cc
Comment out IPoIB broadcast address with a comment.
Roy Marples <roy@marples.name>
parents:
4113
diff
changeset
|
153 #if 0 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
154 /* Broadcast address for IPoIB */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
155 static const uint8_t ipv4_bcast_addr[] = { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
156 0x00, 0xff, 0xff, 0xff, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
157 0xff, 0x12, 0x40, 0x1b, 0x00, 0x00, 0x00, 0x00, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
158 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
159 }; |
|
4147
dba5fa9d56cc
Comment out IPoIB broadcast address with a comment.
Roy Marples <roy@marples.name>
parents:
4113
diff
changeset
|
160 #endif |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
161 |
|
4781
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
162 static int if_addressexists(struct interface *, struct in_addr *); |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
163 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
164 #define PROC_INET6 "/proc/net/if_inet6" |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
165 #define PROC_PROMOTE "/proc/sys/net/ipv4/conf/%s/promote_secondaries" |
|
5258
f29e384aa13e
privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
166 #define SYS_BRIDGE "/sys/class/net/%s/bridge/bridge_id" |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
167 #define SYS_LAYER2 "/sys/class/net/%s/device/layer2" |
|
4750
121555ba3cbe
Linux: Ignore TAP and Bridge interfaces by default
Roy Marples <roy@marples.name>
parents:
4748
diff
changeset
|
168 #define SYS_TUNTAP "/sys/class/net/%s/tun_flags" |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
169 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
170 static const char *mproc = |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
171 #if defined(__alpha__) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
172 "system type" |
|
5382
294dba04aa07
Linux: support aarch64 for reading cpu info
Roy Marples <roy@marples.name>
parents:
5341
diff
changeset
|
173 #elif defined(__arm__) || defined(__aarch64__) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
174 "Hardware" |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
175 #elif defined(__avr32__) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
176 "cpu family" |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
177 #elif defined(__bfin__) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
178 "BOARD Name" |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
179 #elif defined(__cris__) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
180 "cpu model" |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
181 #elif defined(__frv__) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
182 "System" |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
183 #elif defined(__i386__) || defined(__x86_64__) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
184 "vendor_id" |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
185 #elif defined(__ia64__) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
186 "vendor" |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
187 #elif defined(__hppa__) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
188 "model" |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
189 #elif defined(__m68k__) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
190 "MMU" |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
191 #elif defined(__mips__) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
192 "system type" |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
193 #elif defined(__powerpc__) || defined(__powerpc64__) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
194 "machine" |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
195 #elif defined(__s390__) || defined(__s390x__) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
196 "Manufacturer" |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
197 #elif defined(__sh__) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
198 "machine" |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
199 #elif defined(sparc) || defined(__sparc__) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
200 "cpu" |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
201 #elif defined(__vax__) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
202 "cpu" |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
203 #else |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
204 NULL |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
205 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
206 ; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
207 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
208 int |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
209 if_machinearch(char *str, size_t len) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
210 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
211 FILE *fp; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
212 char buf[256]; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
213 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
214 if (mproc == NULL) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
215 errno = EINVAL; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
216 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
217 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
218 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
219 fp = fopen("/proc/cpuinfo", "r"); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
220 if (fp == NULL) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
221 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
222 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
223 while (fscanf(fp, "%255s : ", buf) != EOF) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
224 if (strncmp(buf, mproc, strlen(mproc)) == 0 && |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
225 fscanf(fp, "%255s", buf) == 1) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
226 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
227 fclose(fp); |
|
5207
84b63f09c8a4
privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents:
5178
diff
changeset
|
228 return snprintf(str, len, "%s", buf); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
229 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
230 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
231 fclose(fp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
232 errno = ESRCH; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
233 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
234 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
235 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
236 static int |
|
5258
f29e384aa13e
privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
237 check_proc_int(struct dhcpcd_ctx *ctx, const char *path) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
238 { |
|
5258
f29e384aa13e
privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
239 char buf[64]; |
|
f29e384aa13e
privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
240 int error, i; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
241 |
|
5258
f29e384aa13e
privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
242 if (dhcp_readfile(ctx, path, buf, sizeof(buf)) == -1) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
243 return -1; |
|
5258
f29e384aa13e
privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
244 i = (int)strtoi(buf, NULL, 0, INT_MIN, INT_MAX, &error); |
|
f29e384aa13e
privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
245 if (error != 0 && error != ENOTSUP) { |
|
f29e384aa13e
privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
246 errno = error; |
|
f29e384aa13e
privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
247 return -1; |
|
f29e384aa13e
privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
248 } |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
249 return i; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
250 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
251 |
|
4750
121555ba3cbe
Linux: Ignore TAP and Bridge interfaces by default
Roy Marples <roy@marples.name>
parents:
4748
diff
changeset
|
252 static int |
|
5258
f29e384aa13e
privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
253 check_proc_uint(struct dhcpcd_ctx *ctx, const char *path, unsigned int *u) |
|
4750
121555ba3cbe
Linux: Ignore TAP and Bridge interfaces by default
Roy Marples <roy@marples.name>
parents:
4748
diff
changeset
|
254 { |
|
5258
f29e384aa13e
privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
255 char buf[64]; |
|
f29e384aa13e
privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
256 int error; |
|
4750
121555ba3cbe
Linux: Ignore TAP and Bridge interfaces by default
Roy Marples <roy@marples.name>
parents:
4748
diff
changeset
|
257 |
|
5258
f29e384aa13e
privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
258 if (dhcp_readfile(ctx, path, buf, sizeof(buf)) == -1) |
|
4750
121555ba3cbe
Linux: Ignore TAP and Bridge interfaces by default
Roy Marples <roy@marples.name>
parents:
4748
diff
changeset
|
259 return -1; |
|
5258
f29e384aa13e
privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
260 *u = (unsigned int)strtou(buf, NULL, 0, 0, UINT_MAX, &error); |
|
f29e384aa13e
privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
261 if (error != 0 && error != ENOTSUP) { |
|
f29e384aa13e
privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
262 errno = error; |
|
f29e384aa13e
privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
263 return error; |
|
f29e384aa13e
privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
264 } |
|
f29e384aa13e
privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
265 return 0; |
|
4750
121555ba3cbe
Linux: Ignore TAP and Bridge interfaces by default
Roy Marples <roy@marples.name>
parents:
4748
diff
changeset
|
266 } |
|
121555ba3cbe
Linux: Ignore TAP and Bridge interfaces by default
Roy Marples <roy@marples.name>
parents:
4748
diff
changeset
|
267 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
268 static ssize_t |
|
4840
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4828
diff
changeset
|
269 if_writepathuint(struct dhcpcd_ctx *ctx, const char *path, unsigned int val) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
270 { |
|
5258
f29e384aa13e
privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
271 char buf[64]; |
|
5264
868ac20cdbad
Fix some memory issues with prior
Roy Marples <roy@marples.name>
parents:
5258
diff
changeset
|
272 int len; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
273 |
|
5264
868ac20cdbad
Fix some memory issues with prior
Roy Marples <roy@marples.name>
parents:
5258
diff
changeset
|
274 len = snprintf(buf, sizeof(buf), "%u\n", val); |
|
868ac20cdbad
Fix some memory issues with prior
Roy Marples <roy@marples.name>
parents:
5258
diff
changeset
|
275 if (len == -1) |
|
868ac20cdbad
Fix some memory issues with prior
Roy Marples <roy@marples.name>
parents:
5258
diff
changeset
|
276 return -1; |
|
868ac20cdbad
Fix some memory issues with prior
Roy Marples <roy@marples.name>
parents:
5258
diff
changeset
|
277 return dhcp_writefile(ctx, path, 0664, 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
|
278 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
279 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
280 int |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
281 if_init(struct interface *ifp) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
282 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
283 char path[sizeof(PROC_PROMOTE) + IF_NAMESIZE]; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
284 int n; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
285 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
286 /* We enable promote_secondaries so that we can do this |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
287 * add 192.168.1.2/24 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
288 * add 192.168.1.3/24 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
289 * del 192.168.1.2/24 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
290 * and the subnet mask moves onto 192.168.1.3/24 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
291 * This matches the behaviour of BSD which makes coding dhcpcd |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
292 * a little easier as there's just one behaviour. */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
293 snprintf(path, sizeof(path), PROC_PROMOTE, ifp->name); |
|
5258
f29e384aa13e
privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
294 n = check_proc_int(ifp->ctx, path); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
295 if (n == -1) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
296 return errno == ENOENT ? 0 : -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
297 if (n == 1) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
298 return 0; |
|
4840
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4828
diff
changeset
|
299 return if_writepathuint(ifp->ctx, path, 1) == -1 ? -1 : 0; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
300 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
301 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
302 int |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
303 if_conf(struct interface *ifp) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
304 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
305 char path[sizeof(SYS_LAYER2) + IF_NAMESIZE]; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
306 int n; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
307 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
308 /* Some qeth setups require the use of the broadcast flag. */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
309 snprintf(path, sizeof(path), SYS_LAYER2, ifp->name); |
|
5258
f29e384aa13e
privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
310 n = check_proc_int(ifp->ctx, path); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
311 if (n == -1) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
312 return errno == ENOENT ? 0 : -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
313 if (n == 0) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
314 ifp->options->options |= DHCPCD_BROADCAST; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
315 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
316 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
317 |
|
4750
121555ba3cbe
Linux: Ignore TAP and Bridge interfaces by default
Roy Marples <roy@marples.name>
parents:
4748
diff
changeset
|
318 static bool |
|
5258
f29e384aa13e
privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
319 if_bridge(struct dhcpcd_ctx *ctx, const char *ifname) |
|
4750
121555ba3cbe
Linux: Ignore TAP and Bridge interfaces by default
Roy Marples <roy@marples.name>
parents:
4748
diff
changeset
|
320 { |
|
5258
f29e384aa13e
privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
321 char path[sizeof(SYS_BRIDGE) + IF_NAMESIZE], buf[64]; |
|
4750
121555ba3cbe
Linux: Ignore TAP and Bridge interfaces by default
Roy Marples <roy@marples.name>
parents:
4748
diff
changeset
|
322 |
|
121555ba3cbe
Linux: Ignore TAP and Bridge interfaces by default
Roy Marples <roy@marples.name>
parents:
4748
diff
changeset
|
323 snprintf(path, sizeof(path), SYS_BRIDGE, ifname); |
|
5258
f29e384aa13e
privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
324 if (dhcp_readfile(ctx, path, buf, sizeof(buf)) == -1) |
|
f29e384aa13e
privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
325 return false; |
|
f29e384aa13e
privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
326 return true; |
|
4750
121555ba3cbe
Linux: Ignore TAP and Bridge interfaces by default
Roy Marples <roy@marples.name>
parents:
4748
diff
changeset
|
327 } |
|
121555ba3cbe
Linux: Ignore TAP and Bridge interfaces by default
Roy Marples <roy@marples.name>
parents:
4748
diff
changeset
|
328 |
|
121555ba3cbe
Linux: Ignore TAP and Bridge interfaces by default
Roy Marples <roy@marples.name>
parents:
4748
diff
changeset
|
329 static bool |
|
5258
f29e384aa13e
privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
330 if_tap(struct dhcpcd_ctx *ctx, const char *ifname) |
|
4750
121555ba3cbe
Linux: Ignore TAP and Bridge interfaces by default
Roy Marples <roy@marples.name>
parents:
4748
diff
changeset
|
331 { |
|
121555ba3cbe
Linux: Ignore TAP and Bridge interfaces by default
Roy Marples <roy@marples.name>
parents:
4748
diff
changeset
|
332 char path[sizeof(SYS_TUNTAP) + IF_NAMESIZE]; |
|
5258
f29e384aa13e
privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
333 unsigned int u; |
|
4750
121555ba3cbe
Linux: Ignore TAP and Bridge interfaces by default
Roy Marples <roy@marples.name>
parents:
4748
diff
changeset
|
334 |
|
121555ba3cbe
Linux: Ignore TAP and Bridge interfaces by default
Roy Marples <roy@marples.name>
parents:
4748
diff
changeset
|
335 snprintf(path, sizeof(path), SYS_TUNTAP, ifname); |
|
5258
f29e384aa13e
privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
336 if (check_proc_uint(ctx, path, &u) == -1) |
|
4750
121555ba3cbe
Linux: Ignore TAP and Bridge interfaces by default
Roy Marples <roy@marples.name>
parents:
4748
diff
changeset
|
337 return false; |
|
5258
f29e384aa13e
privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
338 return u & IFF_TAP; |
|
4750
121555ba3cbe
Linux: Ignore TAP and Bridge interfaces by default
Roy Marples <roy@marples.name>
parents:
4748
diff
changeset
|
339 } |
|
121555ba3cbe
Linux: Ignore TAP and Bridge interfaces by default
Roy Marples <roy@marples.name>
parents:
4748
diff
changeset
|
340 |
|
4747
c995401f5572
if: Ignore TAP interfaces by default
Roy Marples <roy@marples.name>
parents:
4721
diff
changeset
|
341 bool |
|
5258
f29e384aa13e
privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
342 if_ignore(struct dhcpcd_ctx *ctx, const char *ifname) |
|
4747
c995401f5572
if: Ignore TAP interfaces by default
Roy Marples <roy@marples.name>
parents:
4721
diff
changeset
|
343 { |
|
c995401f5572
if: Ignore TAP interfaces by default
Roy Marples <roy@marples.name>
parents:
4721
diff
changeset
|
344 |
|
5258
f29e384aa13e
privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
345 if (if_tap(ctx, ifname) || if_bridge(ctx, ifname)) |
|
4750
121555ba3cbe
Linux: Ignore TAP and Bridge interfaces by default
Roy Marples <roy@marples.name>
parents:
4748
diff
changeset
|
346 return true; |
|
4747
c995401f5572
if: Ignore TAP interfaces by default
Roy Marples <roy@marples.name>
parents:
4721
diff
changeset
|
347 return false; |
|
c995401f5572
if: Ignore TAP interfaces by default
Roy Marples <roy@marples.name>
parents:
4721
diff
changeset
|
348 } |
|
c995401f5572
if: Ignore TAP interfaces by default
Roy Marples <roy@marples.name>
parents:
4721
diff
changeset
|
349 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
350 /* XXX work out Virtal Interface Masters */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
351 int |
|
5215
c246c5e40b03
Fix compile on Linux and Solaris
Roy Marples <roy@marples.name>
parents:
5207
diff
changeset
|
352 if_vimaster(__unused struct dhcpcd_ctx *ctx, __unused const char *ifname) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
353 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
354 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
355 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
356 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
357 |
|
4052
08038b46c0f5
Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents:
4026
diff
changeset
|
358 unsigned short |
|
08038b46c0f5
Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents:
4026
diff
changeset
|
359 if_vlanid(const struct interface *ifp) |
|
08038b46c0f5
Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents:
4026
diff
changeset
|
360 { |
|
08038b46c0f5
Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents:
4026
diff
changeset
|
361 struct vlan_ioctl_args v; |
|
08038b46c0f5
Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents:
4026
diff
changeset
|
362 |
|
08038b46c0f5
Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents:
4026
diff
changeset
|
363 memset(&v, 0, sizeof(v)); |
|
08038b46c0f5
Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents:
4026
diff
changeset
|
364 strlcpy(v.device1, ifp->name, sizeof(v.device1)); |
|
08038b46c0f5
Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents:
4026
diff
changeset
|
365 v.cmd = GET_VLAN_VID_CMD; |
|
5460
5f999efcfe01
Linux: Use SIOCSIFVLAN rather than SIOCSIFVLAN
Roy Marples <roy@marples.name>
parents:
5458
diff
changeset
|
366 if (ioctl(ifp->ctx->pf_inet_fd, SIOCGIFVLAN, &v) != 0) |
|
4052
08038b46c0f5
Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents:
4026
diff
changeset
|
367 return 0; /* 0 means no VLANID */ |
|
08038b46c0f5
Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents:
4026
diff
changeset
|
368 return (unsigned short)v.u.VID; |
|
08038b46c0f5
Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents:
4026
diff
changeset
|
369 } |
|
08038b46c0f5
Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents:
4026
diff
changeset
|
370 |
|
4840
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4828
diff
changeset
|
371 int |
|
5282
8afafcabcfa5
privsep: Drain the link socket as we can't re-open it.
Roy Marples <roy@marples.name>
parents:
5281
diff
changeset
|
372 if_linksocket(struct sockaddr_nl *nl, int protocol, int flags) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
373 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
374 int fd; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
375 |
|
5282
8afafcabcfa5
privsep: Drain the link socket as we can't re-open it.
Roy Marples <roy@marples.name>
parents:
5281
diff
changeset
|
376 fd = xsocket(AF_NETLINK, SOCK_RAW | SOCK_CLOEXEC | flags, protocol); |
|
8afafcabcfa5
privsep: Drain the link socket as we can't re-open it.
Roy Marples <roy@marples.name>
parents:
5281
diff
changeset
|
377 if (fd == -1) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
378 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
379 nl->nl_family = AF_NETLINK; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
380 if (bind(fd, (struct sockaddr *)nl, sizeof(*nl)) == -1) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
381 close(fd); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
382 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
383 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
384 return fd; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
385 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
386 |
|
5457
7fb0274b9127
Linux: detect network namespace and deny udev in one
Roy Marples <roy@marples.name>
parents:
5414
diff
changeset
|
387 char * |
|
7fb0274b9127
Linux: detect network namespace and deny udev in one
Roy Marples <roy@marples.name>
parents:
5414
diff
changeset
|
388 if_getnetworknamespace(char *buf, size_t len) |
|
7fb0274b9127
Linux: detect network namespace and deny udev in one
Roy Marples <roy@marples.name>
parents:
5414
diff
changeset
|
389 { |
|
7fb0274b9127
Linux: detect network namespace and deny udev in one
Roy Marples <roy@marples.name>
parents:
5414
diff
changeset
|
390 struct stat sb_self, sb_netns; |
|
7fb0274b9127
Linux: detect network namespace and deny udev in one
Roy Marples <roy@marples.name>
parents:
5414
diff
changeset
|
391 DIR *dir; |
|
7fb0274b9127
Linux: detect network namespace and deny udev in one
Roy Marples <roy@marples.name>
parents:
5414
diff
changeset
|
392 struct dirent *de; |
|
7fb0274b9127
Linux: detect network namespace and deny udev in one
Roy Marples <roy@marples.name>
parents:
5414
diff
changeset
|
393 char file[PATH_MAX], *bufp = NULL; |
|
7fb0274b9127
Linux: detect network namespace and deny udev in one
Roy Marples <roy@marples.name>
parents:
5414
diff
changeset
|
394 |
|
7fb0274b9127
Linux: detect network namespace and deny udev in one
Roy Marples <roy@marples.name>
parents:
5414
diff
changeset
|
395 if (stat("/proc/self/ns/net", &sb_self) == -1) |
|
7fb0274b9127
Linux: detect network namespace and deny udev in one
Roy Marples <roy@marples.name>
parents:
5414
diff
changeset
|
396 return NULL; |
|
7fb0274b9127
Linux: detect network namespace and deny udev in one
Roy Marples <roy@marples.name>
parents:
5414
diff
changeset
|
397 |
|
7fb0274b9127
Linux: detect network namespace and deny udev in one
Roy Marples <roy@marples.name>
parents:
5414
diff
changeset
|
398 dir = opendir("/var/run/netns"); |
|
7fb0274b9127
Linux: detect network namespace and deny udev in one
Roy Marples <roy@marples.name>
parents:
5414
diff
changeset
|
399 if (dir == NULL) |
|
7fb0274b9127
Linux: detect network namespace and deny udev in one
Roy Marples <roy@marples.name>
parents:
5414
diff
changeset
|
400 return NULL; |
|
7fb0274b9127
Linux: detect network namespace and deny udev in one
Roy Marples <roy@marples.name>
parents:
5414
diff
changeset
|
401 |
|
7fb0274b9127
Linux: detect network namespace and deny udev in one
Roy Marples <roy@marples.name>
parents:
5414
diff
changeset
|
402 while ((de = readdir(dir)) != NULL) { |
|
7fb0274b9127
Linux: detect network namespace and deny udev in one
Roy Marples <roy@marples.name>
parents:
5414
diff
changeset
|
403 snprintf(file, sizeof(file), "/var/run/netns/%s", de->d_name); |
|
7fb0274b9127
Linux: detect network namespace and deny udev in one
Roy Marples <roy@marples.name>
parents:
5414
diff
changeset
|
404 if (stat(file, &sb_netns) == -1) |
|
7fb0274b9127
Linux: detect network namespace and deny udev in one
Roy Marples <roy@marples.name>
parents:
5414
diff
changeset
|
405 continue; |
|
5534
605f7f9a20c0
fix if_getnetworknamespace matching bug. (#19)
Ted Feng <artisdom@gmail.com>
parents:
5533
diff
changeset
|
406 if (sb_self.st_dev != sb_netns.st_dev || |
|
5457
7fb0274b9127
Linux: detect network namespace and deny udev in one
Roy Marples <roy@marples.name>
parents:
5414
diff
changeset
|
407 sb_self.st_ino != sb_netns.st_ino) |
|
7fb0274b9127
Linux: detect network namespace and deny udev in one
Roy Marples <roy@marples.name>
parents:
5414
diff
changeset
|
408 continue; |
|
7fb0274b9127
Linux: detect network namespace and deny udev in one
Roy Marples <roy@marples.name>
parents:
5414
diff
changeset
|
409 strlcpy(buf, de->d_name, len); |
|
7fb0274b9127
Linux: detect network namespace and deny udev in one
Roy Marples <roy@marples.name>
parents:
5414
diff
changeset
|
410 bufp = buf; |
|
7fb0274b9127
Linux: detect network namespace and deny udev in one
Roy Marples <roy@marples.name>
parents:
5414
diff
changeset
|
411 break; |
|
7fb0274b9127
Linux: detect network namespace and deny udev in one
Roy Marples <roy@marples.name>
parents:
5414
diff
changeset
|
412 } |
|
7fb0274b9127
Linux: detect network namespace and deny udev in one
Roy Marples <roy@marples.name>
parents:
5414
diff
changeset
|
413 closedir(dir); |
|
7fb0274b9127
Linux: detect network namespace and deny udev in one
Roy Marples <roy@marples.name>
parents:
5414
diff
changeset
|
414 return bufp; |
|
7fb0274b9127
Linux: detect network namespace and deny udev in one
Roy Marples <roy@marples.name>
parents:
5414
diff
changeset
|
415 } |
|
7fb0274b9127
Linux: detect network namespace and deny udev in one
Roy Marples <roy@marples.name>
parents:
5414
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 int |
|
5458
dd8347a0ea1c
Adjust prior so that message is logged before starting dev
Roy Marples <roy@marples.name>
parents:
5457
diff
changeset
|
418 os_init(void) |
|
dd8347a0ea1c
Adjust prior so that message is logged before starting dev
Roy Marples <roy@marples.name>
parents:
5457
diff
changeset
|
419 { |
|
dd8347a0ea1c
Adjust prior so that message is logged before starting dev
Roy Marples <roy@marples.name>
parents:
5457
diff
changeset
|
420 char netns[PATH_MAX], *p; |
|
dd8347a0ea1c
Adjust prior so that message is logged before starting dev
Roy Marples <roy@marples.name>
parents:
5457
diff
changeset
|
421 |
|
dd8347a0ea1c
Adjust prior so that message is logged before starting dev
Roy Marples <roy@marples.name>
parents:
5457
diff
changeset
|
422 p = if_getnetworknamespace(netns, sizeof(netns)); |
|
dd8347a0ea1c
Adjust prior so that message is logged before starting dev
Roy Marples <roy@marples.name>
parents:
5457
diff
changeset
|
423 if (p != NULL) |
|
dd8347a0ea1c
Adjust prior so that message is logged before starting dev
Roy Marples <roy@marples.name>
parents:
5457
diff
changeset
|
424 loginfox("network namespace: %s", p); |
|
dd8347a0ea1c
Adjust prior so that message is logged before starting dev
Roy Marples <roy@marples.name>
parents:
5457
diff
changeset
|
425 |
|
dd8347a0ea1c
Adjust prior so that message is logged before starting dev
Roy Marples <roy@marples.name>
parents:
5457
diff
changeset
|
426 return 0; |
|
dd8347a0ea1c
Adjust prior so that message is logged before starting dev
Roy Marples <roy@marples.name>
parents:
5457
diff
changeset
|
427 } |
|
dd8347a0ea1c
Adjust prior so that message is logged before starting dev
Roy Marples <roy@marples.name>
parents:
5457
diff
changeset
|
428 |
|
dd8347a0ea1c
Adjust prior so that message is logged before starting dev
Roy Marples <roy@marples.name>
parents:
5457
diff
changeset
|
429 int |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
430 if_opensockets_os(struct dhcpcd_ctx *ctx) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
431 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
432 struct priv *priv; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
433 struct sockaddr_nl snl; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
434 socklen_t len; |
|
4323
40f11bb944d4
Linux: Use NETLINK_BROADCAST_ERROR
Roy Marples <roy@marples.name>
parents:
4293
diff
changeset
|
435 #ifdef NETLINK_BROADCAST_ERROR |
|
40f11bb944d4
Linux: Use NETLINK_BROADCAST_ERROR
Roy Marples <roy@marples.name>
parents:
4293
diff
changeset
|
436 int on = 1; |
|
40f11bb944d4
Linux: Use NETLINK_BROADCAST_ERROR
Roy Marples <roy@marples.name>
parents:
4293
diff
changeset
|
437 #endif |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
438 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
439 /* Open the link socket first so it gets pid() for the socket. |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
440 * Then open our persistent route socket so we get a unique |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
441 * pid that doesn't clash with a process id for after we fork. */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
442 memset(&snl, 0, sizeof(snl)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
443 snl.nl_groups = RTMGRP_LINK; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
444 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
445 #ifdef INET |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
446 snl.nl_groups |= RTMGRP_IPV4_ROUTE | RTMGRP_IPV4_IFADDR; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
447 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
448 #ifdef INET6 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
449 snl.nl_groups |= RTMGRP_IPV6_ROUTE | RTMGRP_IPV6_IFADDR | RTMGRP_NEIGH; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
450 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
451 |
|
5282
8afafcabcfa5
privsep: Drain the link socket as we can't re-open it.
Roy Marples <roy@marples.name>
parents:
5281
diff
changeset
|
452 ctx->link_fd = if_linksocket(&snl, NETLINK_ROUTE, SOCK_NONBLOCK); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
453 if (ctx->link_fd == -1) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
454 return -1; |
|
4323
40f11bb944d4
Linux: Use NETLINK_BROADCAST_ERROR
Roy Marples <roy@marples.name>
parents:
4293
diff
changeset
|
455 #ifdef NETLINK_BROADCAST_ERROR |
|
4568
63aea27dd3bc
Linux: Care about the return of setsockopt
Roy Marples <roy@marples.name>
parents:
4555
diff
changeset
|
456 if (setsockopt(ctx->link_fd, SOL_NETLINK, NETLINK_BROADCAST_ERROR, |
|
63aea27dd3bc
Linux: Care about the return of setsockopt
Roy Marples <roy@marples.name>
parents:
4555
diff
changeset
|
457 &on, sizeof(on)) == -1) |
|
4569
5de548eda5ae
Change prior to be non-fatal
Roy Marples <roy@marples.name>
parents:
4568
diff
changeset
|
458 logerr("%s: NETLINK_BROADCAST_ERROR", __func__); |
|
4323
40f11bb944d4
Linux: Use NETLINK_BROADCAST_ERROR
Roy Marples <roy@marples.name>
parents:
4293
diff
changeset
|
459 #endif |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
460 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
461 if ((priv = calloc(1, sizeof(*priv))) == NULL) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
462 return -1; |
|
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 ctx->priv = priv; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
465 memset(&snl, 0, sizeof(snl)); |
|
5282
8afafcabcfa5
privsep: Drain the link socket as we can't re-open it.
Roy Marples <roy@marples.name>
parents:
5281
diff
changeset
|
466 priv->route_fd = if_linksocket(&snl, NETLINK_ROUTE, 0); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
467 if (priv->route_fd == -1) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
468 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
469 len = sizeof(snl); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
470 if (getsockname(priv->route_fd, (struct sockaddr *)&snl, &len) == -1) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
471 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
472 priv->route_pid = snl.nl_pid; |
|
5386
b28b0962bfe2
Linux: keep the generic netlink socket around to get ssid with privsep
Roy Marples <roy@marples.name>
parents:
5384
diff
changeset
|
473 |
|
b28b0962bfe2
Linux: keep the generic netlink socket around to get ssid with privsep
Roy Marples <roy@marples.name>
parents:
5384
diff
changeset
|
474 memset(&snl, 0, sizeof(snl)); |
|
b28b0962bfe2
Linux: keep the generic netlink socket around to get ssid with privsep
Roy Marples <roy@marples.name>
parents:
5384
diff
changeset
|
475 priv->generic_fd = if_linksocket(&snl, NETLINK_GENERIC, 0); |
|
b28b0962bfe2
Linux: keep the generic netlink socket around to get ssid with privsep
Roy Marples <roy@marples.name>
parents:
5384
diff
changeset
|
476 if (priv->generic_fd == -1) |
|
b28b0962bfe2
Linux: keep the generic netlink socket around to get ssid with privsep
Roy Marples <roy@marples.name>
parents:
5384
diff
changeset
|
477 return -1; |
|
b28b0962bfe2
Linux: keep the generic netlink socket around to get ssid with privsep
Roy Marples <roy@marples.name>
parents:
5384
diff
changeset
|
478 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
479 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
480 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
481 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
482 void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
483 if_closesockets_os(struct dhcpcd_ctx *ctx) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
484 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
485 struct priv *priv; |
|
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 if (ctx->priv != NULL) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
488 priv = (struct priv *)ctx->priv; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
489 close(priv->route_fd); |
|
5386
b28b0962bfe2
Linux: keep the generic netlink socket around to get ssid with privsep
Roy Marples <roy@marples.name>
parents:
5384
diff
changeset
|
490 close(priv->generic_fd); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
491 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
492 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
493 |
|
4495
74aa6ad52b0d
BSD: RTM_IFINFO is not emitted for all interfaces past unknown link
Roy Marples <roy@marples.name>
parents:
4421
diff
changeset
|
494 int |
|
4962
854219946ad4
Linux: Support hardware address randomisation
Roy Marples <roy@marples.name>
parents:
4944
diff
changeset
|
495 if_setmac(struct interface *ifp, void *mac, uint8_t maclen) |
|
854219946ad4
Linux: Support hardware address randomisation
Roy Marples <roy@marples.name>
parents:
4944
diff
changeset
|
496 { |
|
854219946ad4
Linux: Support hardware address randomisation
Roy Marples <roy@marples.name>
parents:
4944
diff
changeset
|
497 struct ifreq ifr = { |
|
5166
a70f6ddefe3c
Rename ifp->family -> ifp->hwtype so it's less confusing
Roy Marples <roy@marples.name>
parents:
5153
diff
changeset
|
498 .ifr_hwaddr.sa_family = ifp->hwtype, |
|
4962
854219946ad4
Linux: Support hardware address randomisation
Roy Marples <roy@marples.name>
parents:
4944
diff
changeset
|
499 }; |
|
854219946ad4
Linux: Support hardware address randomisation
Roy Marples <roy@marples.name>
parents:
4944
diff
changeset
|
500 |
|
854219946ad4
Linux: Support hardware address randomisation
Roy Marples <roy@marples.name>
parents:
4944
diff
changeset
|
501 if (ifp->hwlen != maclen || maclen > sizeof(ifr.ifr_hwaddr.sa_data)) { |
|
854219946ad4
Linux: Support hardware address randomisation
Roy Marples <roy@marples.name>
parents:
4944
diff
changeset
|
502 errno = EINVAL; |
|
854219946ad4
Linux: Support hardware address randomisation
Roy Marples <roy@marples.name>
parents:
4944
diff
changeset
|
503 return -1; |
|
854219946ad4
Linux: Support hardware address randomisation
Roy Marples <roy@marples.name>
parents:
4944
diff
changeset
|
504 } |
|
854219946ad4
Linux: Support hardware address randomisation
Roy Marples <roy@marples.name>
parents:
4944
diff
changeset
|
505 |
|
854219946ad4
Linux: Support hardware address randomisation
Roy Marples <roy@marples.name>
parents:
4944
diff
changeset
|
506 strlcpy(ifr.ifr_name, ifp->name, sizeof(ifr.ifr_name)); |
|
854219946ad4
Linux: Support hardware address randomisation
Roy Marples <roy@marples.name>
parents:
4944
diff
changeset
|
507 memcpy(ifr.ifr_hwaddr.sa_data, mac, maclen); |
|
854219946ad4
Linux: Support hardware address randomisation
Roy Marples <roy@marples.name>
parents:
4944
diff
changeset
|
508 return if_ioctl(ifp->ctx, SIOCSIFHWADDR, &ifr, sizeof(ifr)); |
|
854219946ad4
Linux: Support hardware address randomisation
Roy Marples <roy@marples.name>
parents:
4944
diff
changeset
|
509 } |
|
854219946ad4
Linux: Support hardware address randomisation
Roy Marples <roy@marples.name>
parents:
4944
diff
changeset
|
510 |
|
854219946ad4
Linux: Support hardware address randomisation
Roy Marples <roy@marples.name>
parents:
4944
diff
changeset
|
511 int |
|
5486
8e2b8ce8c972
BSD: struct if_data->ifi_link_state is the single source of truth
Roy Marples <roy@marples.name>
parents:
5475
diff
changeset
|
512 if_carrier(struct interface *ifp, __unused const void *ifadata) |
|
4495
74aa6ad52b0d
BSD: RTM_IFINFO is not emitted for all interfaces past unknown link
Roy Marples <roy@marples.name>
parents:
4421
diff
changeset
|
513 { |
|
74aa6ad52b0d
BSD: RTM_IFINFO is not emitted for all interfaces past unknown link
Roy Marples <roy@marples.name>
parents:
4421
diff
changeset
|
514 |
|
74aa6ad52b0d
BSD: RTM_IFINFO is not emitted for all interfaces past unknown link
Roy Marples <roy@marples.name>
parents:
4421
diff
changeset
|
515 return ifp->flags & IFF_RUNNING ? LINK_UP : LINK_DOWN; |
|
74aa6ad52b0d
BSD: RTM_IFINFO is not emitted for all interfaces past unknown link
Roy Marples <roy@marples.name>
parents:
4421
diff
changeset
|
516 } |
|
74aa6ad52b0d
BSD: RTM_IFINFO is not emitted for all interfaces past unknown link
Roy Marples <roy@marples.name>
parents:
4421
diff
changeset
|
517 |
|
5557
e65d193a1960
Linux: Support wireless IP roaming
Roy Marples <roy@marples.name>
parents:
5534
diff
changeset
|
518 bool |
|
e65d193a1960
Linux: Support wireless IP roaming
Roy Marples <roy@marples.name>
parents:
5534
diff
changeset
|
519 if_roaming(struct interface *ifp) |
|
e65d193a1960
Linux: Support wireless IP roaming
Roy Marples <roy@marples.name>
parents:
5534
diff
changeset
|
520 { |
|
e65d193a1960
Linux: Support wireless IP roaming
Roy Marples <roy@marples.name>
parents:
5534
diff
changeset
|
521 |
|
e65d193a1960
Linux: Support wireless IP roaming
Roy Marples <roy@marples.name>
parents:
5534
diff
changeset
|
522 #ifdef IFF_LOWER_UP |
|
e65d193a1960
Linux: Support wireless IP roaming
Roy Marples <roy@marples.name>
parents:
5534
diff
changeset
|
523 if (!ifp->wireless || |
|
e65d193a1960
Linux: Support wireless IP roaming
Roy Marples <roy@marples.name>
parents:
5534
diff
changeset
|
524 ifp->flags & IFF_RUNNING || |
|
e65d193a1960
Linux: Support wireless IP roaming
Roy Marples <roy@marples.name>
parents:
5534
diff
changeset
|
525 (ifp->flags & (IFF_UP | IFF_LOWER_UP)) != (IFF_UP | IFF_LOWER_UP)) |
|
e65d193a1960
Linux: Support wireless IP roaming
Roy Marples <roy@marples.name>
parents:
5534
diff
changeset
|
526 return false; |
|
e65d193a1960
Linux: Support wireless IP roaming
Roy Marples <roy@marples.name>
parents:
5534
diff
changeset
|
527 return true; |
|
e65d193a1960
Linux: Support wireless IP roaming
Roy Marples <roy@marples.name>
parents:
5534
diff
changeset
|
528 #else |
|
e65d193a1960
Linux: Support wireless IP roaming
Roy Marples <roy@marples.name>
parents:
5534
diff
changeset
|
529 return false; |
|
e65d193a1960
Linux: Support wireless IP roaming
Roy Marples <roy@marples.name>
parents:
5534
diff
changeset
|
530 #endif |
|
e65d193a1960
Linux: Support wireless IP roaming
Roy Marples <roy@marples.name>
parents:
5534
diff
changeset
|
531 } |
|
e65d193a1960
Linux: Support wireless IP roaming
Roy Marples <roy@marples.name>
parents:
5534
diff
changeset
|
532 |
|
4840
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4828
diff
changeset
|
533 int |
|
4808
8761aaee4efe
Linux: improve the netlink API more
Roy Marples <roy@marples.name>
parents:
4804
diff
changeset
|
534 if_getnetlink(struct dhcpcd_ctx *ctx, struct iovec *iov, int fd, int flags, |
|
8761aaee4efe
Linux: improve the netlink API more
Roy Marples <roy@marples.name>
parents:
4804
diff
changeset
|
535 int (*cb)(struct dhcpcd_ctx *, void *, struct nlmsghdr *), void *cbarg) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
536 { |
|
4371
a7f3d85f54ce
Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents:
4366
diff
changeset
|
537 struct sockaddr_nl nladdr = { .nl_pid = 0 }; |
|
a7f3d85f54ce
Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents:
4366
diff
changeset
|
538 struct msghdr msg = { |
|
a7f3d85f54ce
Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents:
4366
diff
changeset
|
539 .msg_name = &nladdr, .msg_namelen = sizeof(nladdr), |
|
a7f3d85f54ce
Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents:
4366
diff
changeset
|
540 .msg_iov = iov, .msg_iovlen = 1, |
|
a7f3d85f54ce
Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents:
4366
diff
changeset
|
541 }; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
542 ssize_t len; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
543 struct nlmsghdr *nlm; |
|
5386
b28b0962bfe2
Linux: keep the generic netlink socket around to get ssid with privsep
Roy Marples <roy@marples.name>
parents:
5384
diff
changeset
|
544 int r = 0; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
545 unsigned int again; |
|
5386
b28b0962bfe2
Linux: keep the generic netlink socket around to get ssid with privsep
Roy Marples <roy@marples.name>
parents:
5384
diff
changeset
|
546 bool terminated; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
547 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
548 recv_again: |
|
5386
b28b0962bfe2
Linux: keep the generic netlink socket around to get ssid with privsep
Roy Marples <roy@marples.name>
parents:
5384
diff
changeset
|
549 len = recvmsg(fd, &msg, flags); |
|
b28b0962bfe2
Linux: keep the generic netlink socket around to get ssid with privsep
Roy Marples <roy@marples.name>
parents:
5384
diff
changeset
|
550 if (len == -1 || len == 0) |
|
b28b0962bfe2
Linux: keep the generic netlink socket around to get ssid with privsep
Roy Marples <roy@marples.name>
parents:
5384
diff
changeset
|
551 return (int)len; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
552 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
553 /* Check sender */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
554 if (msg.msg_namelen != sizeof(nladdr)) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
555 errno = EINVAL; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
556 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
557 } |
|
5386
b28b0962bfe2
Linux: keep the generic netlink socket around to get ssid with privsep
Roy Marples <roy@marples.name>
parents:
5384
diff
changeset
|
558 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
559 /* Ignore message if it is not from kernel */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
560 if (nladdr.nl_pid != 0) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
561 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
562 |
|
4781
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
563 again = 0; |
|
5386
b28b0962bfe2
Linux: keep the generic netlink socket around to get ssid with privsep
Roy Marples <roy@marples.name>
parents:
5384
diff
changeset
|
564 terminated = false; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
565 for (nlm = iov->iov_base; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
566 nlm && NLMSG_OK(nlm, (size_t)len); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
567 nlm = NLMSG_NEXT(nlm, len)) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
568 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
569 again = (nlm->nlmsg_flags & NLM_F_MULTI); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
570 if (nlm->nlmsg_type == NLMSG_NOOP) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
571 continue; |
|
5386
b28b0962bfe2
Linux: keep the generic netlink socket around to get ssid with privsep
Roy Marples <roy@marples.name>
parents:
5384
diff
changeset
|
572 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
573 if (nlm->nlmsg_type == NLMSG_ERROR) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
574 struct nlmsgerr *err; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
575 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
576 if (nlm->nlmsg_len - sizeof(*nlm) < sizeof(*err)) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
577 errno = EBADMSG; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
578 return -1; |
|
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 err = (struct nlmsgerr *)NLMSG_DATA(nlm); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
581 if (err->error != 0) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
582 errno = -err->error; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
583 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
584 } |
|
5386
b28b0962bfe2
Linux: keep the generic netlink socket around to get ssid with privsep
Roy Marples <roy@marples.name>
parents:
5384
diff
changeset
|
585 again = 0; |
|
b28b0962bfe2
Linux: keep the generic netlink socket around to get ssid with privsep
Roy Marples <roy@marples.name>
parents:
5384
diff
changeset
|
586 terminated = true; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
587 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
588 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
589 if (nlm->nlmsg_type == NLMSG_DONE) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
590 again = 0; |
|
5386
b28b0962bfe2
Linux: keep the generic netlink socket around to get ssid with privsep
Roy Marples <roy@marples.name>
parents:
5384
diff
changeset
|
591 terminated = true; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
592 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
593 } |
|
5387
08cbef5c8e9e
Linux: Warn if netlink(7) seq number doesn't match expectation.
Roy Marples <roy@marples.name>
parents:
5386
diff
changeset
|
594 if (cb == NULL) |
|
08cbef5c8e9e
Linux: Warn if netlink(7) seq number doesn't match expectation.
Roy Marples <roy@marples.name>
parents:
5386
diff
changeset
|
595 continue; |
|
08cbef5c8e9e
Linux: Warn if netlink(7) seq number doesn't match expectation.
Roy Marples <roy@marples.name>
parents:
5386
diff
changeset
|
596 if (nlm->nlmsg_seq != (uint32_t)ctx->seq && fd != ctx->link_fd) |
|
08cbef5c8e9e
Linux: Warn if netlink(7) seq number doesn't match expectation.
Roy Marples <roy@marples.name>
parents:
5386
diff
changeset
|
597 logwarnx("%s: received sequence %u, expecting %d", |
|
08cbef5c8e9e
Linux: Warn if netlink(7) seq number doesn't match expectation.
Roy Marples <roy@marples.name>
parents:
5386
diff
changeset
|
598 __func__, nlm->nlmsg_seq, ctx->seq); |
|
08cbef5c8e9e
Linux: Warn if netlink(7) seq number doesn't match expectation.
Roy Marples <roy@marples.name>
parents:
5386
diff
changeset
|
599 else |
|
5386
b28b0962bfe2
Linux: keep the generic netlink socket around to get ssid with privsep
Roy Marples <roy@marples.name>
parents:
5384
diff
changeset
|
600 r = cb(ctx, cbarg, nlm); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
601 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
602 |
|
5386
b28b0962bfe2
Linux: keep the generic netlink socket around to get ssid with privsep
Roy Marples <roy@marples.name>
parents:
5384
diff
changeset
|
603 if ((again || !terminated) && (ctx != NULL && ctx->link_fd != fd)) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
604 goto recv_again; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
605 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
606 return r; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
607 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
608 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
609 static int |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
610 if_copyrt(struct dhcpcd_ctx *ctx, struct rt *rt, struct nlmsghdr *nlm) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
611 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
612 size_t len; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
613 struct rtmsg *rtm; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
614 struct rtattr *rta; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
615 unsigned int ifindex; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
616 struct sockaddr *sa; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
617 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
618 len = nlm->nlmsg_len - sizeof(*nlm); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
619 if (len < sizeof(*rtm)) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
620 errno = EBADMSG; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
621 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
622 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
623 rtm = (struct rtmsg *)NLMSG_DATA(nlm); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
624 if (rtm->rtm_table != RT_TABLE_MAIN) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
625 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
626 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
627 memset(rt, 0, sizeof(*rt)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
628 if (rtm->rtm_type == RTN_UNREACHABLE) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
629 rt->rt_flags |= RTF_REJECT; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
630 |
|
4884
1378ef92e8bc
Linux: remove some casts no longer needed
Roy Marples <roy@marples.name>
parents:
4840
diff
changeset
|
631 rta = RTM_RTA(rtm); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
632 len = RTM_PAYLOAD(nlm); |
|
4897
877cf2803035
Linux: Move RTA_OK and RTA_NEXT from a while to a for loop.
Roy Marples <roy@marples.name>
parents:
4885
diff
changeset
|
633 for (; RTA_OK(rta, len); rta = RTA_NEXT(rta, len)) { |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
634 sa = NULL; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
635 switch (rta->rta_type) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
636 case RTA_DST: |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
637 sa = &rt->rt_dest; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
638 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
639 case RTA_GATEWAY: |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
640 sa = &rt->rt_gateway; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
641 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
642 case RTA_PREFSRC: |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
643 sa = &rt->rt_ifa; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
644 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
645 case RTA_OIF: |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
646 ifindex = *(unsigned int *)RTA_DATA(rta); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
647 rt->rt_ifp = if_findindex(ctx->ifaces, ifindex); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
648 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
649 case RTA_PRIORITY: |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
650 rt->rt_metric = *(unsigned int *)RTA_DATA(rta); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
651 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
652 case RTA_METRICS: |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
653 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
654 struct rtattr *r2; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
655 size_t l2; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
656 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
657 l2 = rta->rta_len; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
658 r2 = (struct rtattr *)RTA_DATA(rta); |
|
4897
877cf2803035
Linux: Move RTA_OK and RTA_NEXT from a while to a for loop.
Roy Marples <roy@marples.name>
parents:
4885
diff
changeset
|
659 for (; RTA_OK(r2, l2); r2 = RTA_NEXT(r2, l2)) { |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
660 switch (r2->rta_type) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
661 case RTAX_MTU: |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
662 rt->rt_mtu = *(unsigned int *)RTA_DATA(r2); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
663 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
664 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
665 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
666 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
667 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
668 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
669 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
670 if (sa != NULL) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
671 socklen_t salen; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
672 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
673 sa->sa_family = rtm->rtm_family; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
674 salen = sa_addrlen(sa); |
|
4572
e438211a2b44
Linux: Work around a coverity issue
Roy Marples <roy@marples.name>
parents:
4569
diff
changeset
|
675 /* sa is a union where sockaddr_in6 is the biggest. */ |
|
e438211a2b44
Linux: Work around a coverity issue
Roy Marples <roy@marples.name>
parents:
4569
diff
changeset
|
676 /* coverity[overrun-buffer-arg] */ |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
677 memcpy((char *)sa + sa_addroffset(sa), RTA_DATA(rta), |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
678 MIN(salen, RTA_PAYLOAD(rta))); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
679 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
680 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
681 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
682 /* If no RTA_DST set the unspecified address for the family. */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
683 if (rt->rt_dest.sa_family == AF_UNSPEC) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
684 rt->rt_dest.sa_family = rtm->rtm_family; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
685 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
686 rt->rt_netmask.sa_family = rtm->rtm_family; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
687 sa_fromprefix(&rt->rt_netmask, rtm->rtm_dst_len); |
|
4293
63138e0b8d68
linux: set RTF_HOST correctly when reading kernel routes.
Roy Marples <roy@marples.name>
parents:
4292
diff
changeset
|
688 if (sa_is_allones(&rt->rt_netmask)) |
|
63138e0b8d68
linux: set RTF_HOST correctly when reading kernel routes.
Roy Marples <roy@marples.name>
parents:
4292
diff
changeset
|
689 rt->rt_flags |= RTF_HOST; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
690 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
691 #if 0 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
692 if (rt->rtp_ifp == NULL && rt->src.s_addr != INADDR_ANY) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
693 struct ipv4_addr *ap; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
694 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
695 /* For some reason the default route comes back with the |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
696 * loopback interface in RTA_OIF? Lets find it by |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
697 * preferred source address */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
698 if ((ap = ipv4_findaddr(ctx, &rt->src))) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
699 rt->iface = ap->iface; |
|
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 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
702 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
703 if (rt->rt_ifp == NULL) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
704 errno = ESRCH; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
705 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
706 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
707 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
708 } |
|
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 static int |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
711 link_route(struct dhcpcd_ctx *ctx, __unused struct interface *ifp, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
712 struct nlmsghdr *nlm) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
713 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
714 size_t len; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
715 int cmd; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
716 struct priv *priv; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
717 struct rt rt; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
718 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
719 switch (nlm->nlmsg_type) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
720 case RTM_NEWROUTE: |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
721 cmd = RTM_ADD; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
722 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
723 case RTM_DELROUTE: |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
724 cmd = RTM_DELETE; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
725 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
726 default: |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
727 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
728 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
729 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
730 len = nlm->nlmsg_len - sizeof(*nlm); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
731 if (len < sizeof(struct rtmsg)) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
732 errno = EBADMSG; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
733 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
734 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
735 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
736 /* Ignore messages we sent. */ |
|
4970
64b25cbb621f
Linux: Use the persistent route socket for writing netlink msgs
Roy Marples <roy@marples.name>
parents:
4962
diff
changeset
|
737 #ifdef PRIVSEP |
|
64b25cbb621f
Linux: Use the persistent route socket for writing netlink msgs
Roy Marples <roy@marples.name>
parents:
4962
diff
changeset
|
738 if (ctx->ps_root_pid != 0 && |
|
64b25cbb621f
Linux: Use the persistent route socket for writing netlink msgs
Roy Marples <roy@marples.name>
parents:
4962
diff
changeset
|
739 nlm->nlmsg_pid == (uint32_t)ctx->ps_root_pid) |
|
64b25cbb621f
Linux: Use the persistent route socket for writing netlink msgs
Roy Marples <roy@marples.name>
parents:
4962
diff
changeset
|
740 return 0; |
|
64b25cbb621f
Linux: Use the persistent route socket for writing netlink msgs
Roy Marples <roy@marples.name>
parents:
4962
diff
changeset
|
741 #endif |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
742 priv = (struct priv *)ctx->priv; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
743 if (nlm->nlmsg_pid == priv->route_pid) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
744 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
745 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
746 if (if_copyrt(ctx, &rt, nlm) == 0) |
|
4421
1c0d24d49b16
route: log which pid deletes routes
Roy Marples <roy@marples.name>
parents:
4371
diff
changeset
|
747 rt_recvrt(cmd, &rt, (pid_t)nlm->nlmsg_pid); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
748 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
749 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
750 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
751 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
752 static int |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
753 link_addr(struct dhcpcd_ctx *ctx, struct interface *ifp, struct nlmsghdr *nlm) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
754 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
755 size_t len; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
756 struct rtattr *rta; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
757 struct ifaddrmsg *ifa; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
758 struct priv *priv; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
759 #ifdef INET |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
760 struct in_addr addr, net, brd; |
|
5533
8f117781bb06
Linux: Fix detecting existing IPv4 addresses
Roy Marples <roy@marples.name>
parents:
5486
diff
changeset
|
761 int ret; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
762 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
763 #ifdef INET6 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
764 struct in6_addr addr6; |
|
4779
66684c1c08bd
Linux: Validate RTM_DELADDR/RTM_NEWADDR messages for IPv6
Roy Marples <roy@marples.name>
parents:
4778
diff
changeset
|
765 int flags; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
766 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
767 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
768 if (nlm->nlmsg_type != RTM_DELADDR && nlm->nlmsg_type != RTM_NEWADDR) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
769 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
770 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
771 len = nlm->nlmsg_len - sizeof(*nlm); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
772 if (len < sizeof(*ifa)) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
773 errno = EBADMSG; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
774 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
775 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
776 |
|
4985
d9cb0a6245a4
Only ignore address messages from ourself for deletion.
Roy Marples <roy@marples.name>
parents:
4982
diff
changeset
|
777 /* Ignore address deletions from ourself. |
|
d9cb0a6245a4
Only ignore address messages from ourself for deletion.
Roy Marples <roy@marples.name>
parents:
4982
diff
changeset
|
778 * We need to process address flag changes though. */ |
|
d9cb0a6245a4
Only ignore address messages from ourself for deletion.
Roy Marples <roy@marples.name>
parents:
4982
diff
changeset
|
779 if (nlm->nlmsg_type == RTM_DELADDR) { |
|
4970
64b25cbb621f
Linux: Use the persistent route socket for writing netlink msgs
Roy Marples <roy@marples.name>
parents:
4962
diff
changeset
|
780 #ifdef PRIVSEP |
|
4985
d9cb0a6245a4
Only ignore address messages from ourself for deletion.
Roy Marples <roy@marples.name>
parents:
4982
diff
changeset
|
781 if (ctx->ps_root_pid != 0 && |
|
d9cb0a6245a4
Only ignore address messages from ourself for deletion.
Roy Marples <roy@marples.name>
parents:
4982
diff
changeset
|
782 nlm->nlmsg_pid == (uint32_t)ctx->ps_root_pid) |
|
d9cb0a6245a4
Only ignore address messages from ourself for deletion.
Roy Marples <roy@marples.name>
parents:
4982
diff
changeset
|
783 return 0; |
|
4970
64b25cbb621f
Linux: Use the persistent route socket for writing netlink msgs
Roy Marples <roy@marples.name>
parents:
4962
diff
changeset
|
784 #endif |
|
4985
d9cb0a6245a4
Only ignore address messages from ourself for deletion.
Roy Marples <roy@marples.name>
parents:
4982
diff
changeset
|
785 priv = (struct priv*)ctx->priv; |
|
d9cb0a6245a4
Only ignore address messages from ourself for deletion.
Roy Marples <roy@marples.name>
parents:
4982
diff
changeset
|
786 if (nlm->nlmsg_pid == priv->route_pid) |
|
d9cb0a6245a4
Only ignore address messages from ourself for deletion.
Roy Marples <roy@marples.name>
parents:
4982
diff
changeset
|
787 return 0; |
|
d9cb0a6245a4
Only ignore address messages from ourself for deletion.
Roy Marples <roy@marples.name>
parents:
4982
diff
changeset
|
788 } |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
789 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
790 ifa = NLMSG_DATA(nlm); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
791 if ((ifp = if_findindex(ctx->ifaces, ifa->ifa_index)) == NULL) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
792 /* We don't know about the interface the address is for |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
793 * so it's not really an error */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
794 return 1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
795 } |
|
4884
1378ef92e8bc
Linux: remove some casts no longer needed
Roy Marples <roy@marples.name>
parents:
4840
diff
changeset
|
796 rta = IFA_RTA(ifa); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
797 len = NLMSG_PAYLOAD(nlm, sizeof(*ifa)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
798 switch (ifa->ifa_family) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
799 #ifdef INET |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
800 case AF_INET: |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
801 addr.s_addr = brd.s_addr = INADDR_ANY; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
802 inet_cidrtoaddr(ifa->ifa_prefixlen, &net); |
|
4897
877cf2803035
Linux: Move RTA_OK and RTA_NEXT from a while to a for loop.
Roy Marples <roy@marples.name>
parents:
4885
diff
changeset
|
803 for (; RTA_OK(rta, len); rta = RTA_NEXT(rta, len)) { |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
804 switch (rta->rta_type) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
805 case IFA_ADDRESS: |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
806 if (ifp->flags & IFF_POINTOPOINT) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
807 memcpy(&brd.s_addr, RTA_DATA(rta), |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
808 sizeof(brd.s_addr)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
809 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
810 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
811 case IFA_BROADCAST: |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
812 memcpy(&brd.s_addr, RTA_DATA(rta), |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
813 sizeof(brd.s_addr)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
814 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
815 case IFA_LOCAL: |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
816 memcpy(&addr.s_addr, RTA_DATA(rta), |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
817 sizeof(addr.s_addr)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
818 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
819 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
820 } |
|
4779
66684c1c08bd
Linux: Validate RTM_DELADDR/RTM_NEWADDR messages for IPv6
Roy Marples <roy@marples.name>
parents:
4778
diff
changeset
|
821 |
|
4781
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
822 /* Validate RTM_DELADDR really means address deleted |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
823 * and anything else really means address exists. */ |
|
5533
8f117781bb06
Linux: Fix detecting existing IPv4 addresses
Roy Marples <roy@marples.name>
parents:
5486
diff
changeset
|
824 ret = if_addressexists(ifp, &addr); |
|
8f117781bb06
Linux: Fix detecting existing IPv4 addresses
Roy Marples <roy@marples.name>
parents:
5486
diff
changeset
|
825 if (ret == -1) { |
|
8f117781bb06
Linux: Fix detecting existing IPv4 addresses
Roy Marples <roy@marples.name>
parents:
5486
diff
changeset
|
826 logerr("if_addressexists: %s", inet_ntoa(addr)); |
|
8f117781bb06
Linux: Fix detecting existing IPv4 addresses
Roy Marples <roy@marples.name>
parents:
5486
diff
changeset
|
827 break; |
|
8f117781bb06
Linux: Fix detecting existing IPv4 addresses
Roy Marples <roy@marples.name>
parents:
5486
diff
changeset
|
828 } else if (ret == 1) { |
|
4781
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
829 if (nlm->nlmsg_type == RTM_DELADDR) |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
830 break; |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
831 } else { |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
832 if (nlm->nlmsg_type != RTM_DELADDR) |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
833 break; |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
834 } |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
835 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
836 ipv4_handleifa(ctx, nlm->nlmsg_type, NULL, ifp->name, |
|
4232
8b92c1844860
Log the pid of the process deleting an assigned address.
Roy Marples <roy@marples.name>
parents:
4229
diff
changeset
|
837 &addr, &net, &brd, ifa->ifa_flags, (pid_t)nlm->nlmsg_pid); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
838 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
839 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
840 #ifdef INET6 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
841 case AF_INET6: |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
842 memset(&addr6, 0, sizeof(addr6)); |
|
4897
877cf2803035
Linux: Move RTA_OK and RTA_NEXT from a while to a for loop.
Roy Marples <roy@marples.name>
parents:
4885
diff
changeset
|
843 for (; RTA_OK(rta, len); rta = RTA_NEXT(rta, len)) { |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
844 switch (rta->rta_type) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
845 case IFA_ADDRESS: |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
846 memcpy(&addr6.s6_addr, RTA_DATA(rta), |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
847 sizeof(addr6.s6_addr)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
848 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
849 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
850 } |
|
4779
66684c1c08bd
Linux: Validate RTM_DELADDR/RTM_NEWADDR messages for IPv6
Roy Marples <roy@marples.name>
parents:
4778
diff
changeset
|
851 |
|
66684c1c08bd
Linux: Validate RTM_DELADDR/RTM_NEWADDR messages for IPv6
Roy Marples <roy@marples.name>
parents:
4778
diff
changeset
|
852 /* Validate RTM_DELADDR really means address deleted |
|
66684c1c08bd
Linux: Validate RTM_DELADDR/RTM_NEWADDR messages for IPv6
Roy Marples <roy@marples.name>
parents:
4778
diff
changeset
|
853 * and anything else really means address exists. */ |
|
66684c1c08bd
Linux: Validate RTM_DELADDR/RTM_NEWADDR messages for IPv6
Roy Marples <roy@marples.name>
parents:
4778
diff
changeset
|
854 flags = if_addrflags6(ifp, &addr6, NULL); |
|
66684c1c08bd
Linux: Validate RTM_DELADDR/RTM_NEWADDR messages for IPv6
Roy Marples <roy@marples.name>
parents:
4778
diff
changeset
|
855 if (nlm->nlmsg_type == RTM_DELADDR) { |
|
66684c1c08bd
Linux: Validate RTM_DELADDR/RTM_NEWADDR messages for IPv6
Roy Marples <roy@marples.name>
parents:
4778
diff
changeset
|
856 if (flags != -1) |
|
66684c1c08bd
Linux: Validate RTM_DELADDR/RTM_NEWADDR messages for IPv6
Roy Marples <roy@marples.name>
parents:
4778
diff
changeset
|
857 break; |
|
66684c1c08bd
Linux: Validate RTM_DELADDR/RTM_NEWADDR messages for IPv6
Roy Marples <roy@marples.name>
parents:
4778
diff
changeset
|
858 } else { |
|
66684c1c08bd
Linux: Validate RTM_DELADDR/RTM_NEWADDR messages for IPv6
Roy Marples <roy@marples.name>
parents:
4778
diff
changeset
|
859 if (flags == -1) |
|
66684c1c08bd
Linux: Validate RTM_DELADDR/RTM_NEWADDR messages for IPv6
Roy Marples <roy@marples.name>
parents:
4778
diff
changeset
|
860 break; |
|
66684c1c08bd
Linux: Validate RTM_DELADDR/RTM_NEWADDR messages for IPv6
Roy Marples <roy@marples.name>
parents:
4778
diff
changeset
|
861 } |
|
66684c1c08bd
Linux: Validate RTM_DELADDR/RTM_NEWADDR messages for IPv6
Roy Marples <roy@marples.name>
parents:
4778
diff
changeset
|
862 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
863 ipv6_handleifa(ctx, nlm->nlmsg_type, NULL, ifp->name, |
|
4232
8b92c1844860
Log the pid of the process deleting an assigned address.
Roy Marples <roy@marples.name>
parents:
4229
diff
changeset
|
864 &addr6, ifa->ifa_prefixlen, ifa->ifa_flags, |
|
8b92c1844860
Log the pid of the process deleting an assigned address.
Roy Marples <roy@marples.name>
parents:
4229
diff
changeset
|
865 (pid_t)nlm->nlmsg_pid); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
866 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
867 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
868 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
869 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
870 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
871 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
872 static uint8_t |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
873 l2addr_len(unsigned short if_type) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
874 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
875 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
876 switch (if_type) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
877 case ARPHRD_ETHER: /* FALLTHROUGH */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
878 case ARPHRD_IEEE802: /*FALLTHROUGH */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
879 case ARPHRD_IEEE80211: |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
880 return 6; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
881 case ARPHRD_IEEE1394: |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
882 return 8; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
883 case ARPHRD_INFINIBAND: |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
884 return 20; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
885 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
886 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
887 /* Impossible */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
888 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
889 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
890 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
891 #ifdef INET6 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
892 static int |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
893 link_neigh(struct dhcpcd_ctx *ctx, __unused struct interface *ifp, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
894 struct nlmsghdr *nlm) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
895 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
896 struct ndmsg *r; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
897 struct rtattr *rta; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
898 size_t len; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
899 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
900 if (nlm->nlmsg_type != RTM_NEWNEIGH && nlm->nlmsg_type != RTM_DELNEIGH) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
901 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
902 if (nlm->nlmsg_len < sizeof(*r)) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
903 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
904 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
905 r = NLMSG_DATA(nlm); |
|
4884
1378ef92e8bc
Linux: remove some casts no longer needed
Roy Marples <roy@marples.name>
parents:
4840
diff
changeset
|
906 rta = RTM_RTA(r); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
907 len = RTM_PAYLOAD(nlm); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
908 if (r->ndm_family == AF_INET6) { |
|
5115
bc8b0d0c68af
Linux: improve IPv6 router reachability
Roy Marples <roy@marples.name>
parents:
5064
diff
changeset
|
909 bool unreachable; |
|
4669
ec9d26e0de41
inet6: Stop reacting to kernel neighbour messages about a router
Roy Marples <roy@marples.name>
parents:
4636
diff
changeset
|
910 struct in6_addr addr6; |
|
ec9d26e0de41
inet6: Stop reacting to kernel neighbour messages about a router
Roy Marples <roy@marples.name>
parents:
4636
diff
changeset
|
911 |
|
5115
bc8b0d0c68af
Linux: improve IPv6 router reachability
Roy Marples <roy@marples.name>
parents:
5064
diff
changeset
|
912 unreachable = (nlm->nlmsg_type == RTM_NEWNEIGH && |
|
bc8b0d0c68af
Linux: improve IPv6 router reachability
Roy Marples <roy@marples.name>
parents:
5064
diff
changeset
|
913 r->ndm_state & NUD_FAILED); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
914 memset(&addr6, 0, sizeof(addr6)); |
|
4897
877cf2803035
Linux: Move RTA_OK and RTA_NEXT from a while to a for loop.
Roy Marples <roy@marples.name>
parents:
4885
diff
changeset
|
915 for (; RTA_OK(rta, len); rta = RTA_NEXT(rta, len)) { |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
916 switch (rta->rta_type) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
917 case NDA_DST: |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
918 memcpy(&addr6.s6_addr, RTA_DATA(rta), |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
919 sizeof(addr6.s6_addr)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
920 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
921 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
922 } |
|
5115
bc8b0d0c68af
Linux: improve IPv6 router reachability
Roy Marples <roy@marples.name>
parents:
5064
diff
changeset
|
923 ipv6nd_neighbour(ctx, &addr6, !unreachable); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
924 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
925 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
926 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
927 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
928 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
929 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
930 static int |
|
4521
9a0884e8ab97
linux: use correct prototype
Roy Marples <roy@marples.name>
parents:
4511
diff
changeset
|
931 link_netlink(struct dhcpcd_ctx *ctx, void *arg, struct nlmsghdr *nlm) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
932 { |
|
4521
9a0884e8ab97
linux: use correct prototype
Roy Marples <roy@marples.name>
parents:
4511
diff
changeset
|
933 struct interface *ifp = arg; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
934 int r; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
935 size_t len; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
936 struct rtattr *rta, *hwaddr; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
937 struct ifinfomsg *ifi; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
938 char ifn[IF_NAMESIZE + 1]; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
939 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
940 r = link_route(ctx, ifp, nlm); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
941 if (r != 0) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
942 return r; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
943 r = link_addr(ctx, ifp, nlm); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
944 if (r != 0) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
945 return r; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
946 #ifdef INET6 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
947 r = link_neigh(ctx, ifp, nlm); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
948 if (r != 0) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
949 return r; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
950 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
951 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
952 if (nlm->nlmsg_type != RTM_NEWLINK && nlm->nlmsg_type != RTM_DELLINK) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
953 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
954 len = nlm->nlmsg_len - sizeof(*nlm); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
955 if ((size_t)len < sizeof(*ifi)) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
956 errno = EBADMSG; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
957 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
958 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
959 ifi = NLMSG_DATA(nlm); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
960 if (ifi->ifi_flags & IFF_LOOPBACK) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
961 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
962 rta = (void *)((char *)ifi + NLMSG_ALIGN(sizeof(*ifi))); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
963 len = NLMSG_PAYLOAD(nlm, sizeof(*ifi)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
964 *ifn = '\0'; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
965 hwaddr = NULL; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
966 |
|
4897
877cf2803035
Linux: Move RTA_OK and RTA_NEXT from a while to a for loop.
Roy Marples <roy@marples.name>
parents:
4885
diff
changeset
|
967 for (; RTA_OK(rta, len); rta = RTA_NEXT(rta, len)) { |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
968 switch (rta->rta_type) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
969 case IFLA_WIRELESS: |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
970 /* Ignore wireless messages */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
971 if (nlm->nlmsg_type == RTM_NEWLINK && |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
972 ifi->ifi_change == 0) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
973 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
974 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
975 case IFLA_IFNAME: |
|
4015
6aa00a675750
Cast away a coverity issue.
Roy Marples <roy@marples.name>
parents:
4010
diff
changeset
|
976 strlcpy(ifn, (char *)RTA_DATA(rta), sizeof(ifn)); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
977 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
978 case IFLA_ADDRESS: |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
979 hwaddr = rta; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
980 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
981 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
982 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
983 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
984 if (nlm->nlmsg_type == RTM_DELLINK) { |
|
5285
7754eb6cd2eb
Linux: File compile without plugins
Julian Wollrath <julian@haerkules.de>
parents:
5282
diff
changeset
|
985 #ifdef PLUGIN_DEV |
|
4257
29971caaafc9
Linux: If listening to dev manager, let it remove interfaces
Roy Marples <roy@marples.name>
parents:
4255
diff
changeset
|
986 /* If are listening to a dev manager, let that remove |
|
29971caaafc9
Linux: If listening to dev manager, let it remove interfaces
Roy Marples <roy@marples.name>
parents:
4255
diff
changeset
|
987 * the interface rather than the kernel. */ |
|
29971caaafc9
Linux: If listening to dev manager, let it remove interfaces
Roy Marples <roy@marples.name>
parents:
4255
diff
changeset
|
988 if (dev_listening(ctx) < 1) |
|
5285
7754eb6cd2eb
Linux: File compile without plugins
Julian Wollrath <julian@haerkules.de>
parents:
5282
diff
changeset
|
989 #endif |
|
4257
29971caaafc9
Linux: If listening to dev manager, let it remove interfaces
Roy Marples <roy@marples.name>
parents:
4255
diff
changeset
|
990 dhcpcd_handleinterface(ctx, -1, ifn); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
991 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
992 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
993 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
994 /* Virtual interfaces may not get a valid hardware address |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
995 * at this point. |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
996 * To trigger a valid hardware address pickup we need to pretend |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
997 * that that don't exist until they have one. */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
998 if (ifi->ifi_flags & IFF_MASTER && !hwaddr) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
999 dhcpcd_handleinterface(ctx, -1, ifn); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1000 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1001 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1002 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1003 /* Check for a new interface */ |
|
4255
8524a8375483
Linux: Improve interface renaming
Roy Marples <roy@marples.name>
parents:
4232
diff
changeset
|
1004 ifp = if_findindex(ctx->ifaces, (unsigned int)ifi->ifi_index); |
|
8524a8375483
Linux: Improve interface renaming
Roy Marples <roy@marples.name>
parents:
4232
diff
changeset
|
1005 if (ifp == NULL) { |
|
5285
7754eb6cd2eb
Linux: File compile without plugins
Julian Wollrath <julian@haerkules.de>
parents:
5282
diff
changeset
|
1006 #ifdef PLUGIN_DEV |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1007 /* If are listening to a dev manager, let that announce |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1008 * the interface rather than the kernel. */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1009 if (dev_listening(ctx) < 1) |
|
5285
7754eb6cd2eb
Linux: File compile without plugins
Julian Wollrath <julian@haerkules.de>
parents:
5282
diff
changeset
|
1010 #endif |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1011 dhcpcd_handleinterface(ctx, 1, ifn); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1012 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1013 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1014 |
|
4255
8524a8375483
Linux: Improve interface renaming
Roy Marples <roy@marples.name>
parents:
4232
diff
changeset
|
1015 /* Handle interface being renamed */ |
|
8524a8375483
Linux: Improve interface renaming
Roy Marples <roy@marples.name>
parents:
4232
diff
changeset
|
1016 if (strcmp(ifp->name, ifn) != 0) { |
|
8524a8375483
Linux: Improve interface renaming
Roy Marples <roy@marples.name>
parents:
4232
diff
changeset
|
1017 dhcpcd_handleinterface(ctx, -1, ifn); |
|
8524a8375483
Linux: Improve interface renaming
Roy Marples <roy@marples.name>
parents:
4232
diff
changeset
|
1018 dhcpcd_handleinterface(ctx, 1, ifn); |
|
8524a8375483
Linux: Improve interface renaming
Roy Marples <roy@marples.name>
parents:
4232
diff
changeset
|
1019 return 0; |
|
8524a8375483
Linux: Improve interface renaming
Roy Marples <roy@marples.name>
parents:
4232
diff
changeset
|
1020 } |
|
8524a8375483
Linux: Improve interface renaming
Roy Marples <roy@marples.name>
parents:
4232
diff
changeset
|
1021 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1022 /* Re-read hardware address and friends */ |
|
5168
1f5dc6102f9b
if: support changing hardware address type on Linux
Roy Marples <roy@marples.name>
parents:
5166
diff
changeset
|
1023 if (!(ifi->ifi_flags & IFF_UP)) { |
|
1f5dc6102f9b
if: support changing hardware address type on Linux
Roy Marples <roy@marples.name>
parents:
5166
diff
changeset
|
1024 void *hwa = hwaddr != NULL ? RTA_DATA(hwaddr) : NULL; |
|
1f5dc6102f9b
if: support changing hardware address type on Linux
Roy Marples <roy@marples.name>
parents:
5166
diff
changeset
|
1025 uint8_t hwl = l2addr_len(ifi->ifi_type); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1026 |
|
5168
1f5dc6102f9b
if: support changing hardware address type on Linux
Roy Marples <roy@marples.name>
parents:
5166
diff
changeset
|
1027 if (hwaddr != NULL && hwaddr->rta_len != RTA_LENGTH(hwl)) |
|
1f5dc6102f9b
if: support changing hardware address type on Linux
Roy Marples <roy@marples.name>
parents:
5166
diff
changeset
|
1028 hwa = NULL; |
|
1f5dc6102f9b
if: support changing hardware address type on Linux
Roy Marples <roy@marples.name>
parents:
5166
diff
changeset
|
1029 dhcpcd_handlehwaddr(ifp, ifi->ifi_type, hwa, hwl); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1030 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1031 |
|
5486
8e2b8ce8c972
BSD: struct if_data->ifi_link_state is the single source of truth
Roy Marples <roy@marples.name>
parents:
5475
diff
changeset
|
1032 dhcpcd_handlecarrier(ifp, |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1033 ifi->ifi_flags & IFF_RUNNING ? LINK_UP : LINK_DOWN, |
|
5486
8e2b8ce8c972
BSD: struct if_data->ifi_link_state is the single source of truth
Roy Marples <roy@marples.name>
parents:
5475
diff
changeset
|
1034 ifi->ifi_flags); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1035 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1036 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1037 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1038 int |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1039 if_handlelink(struct dhcpcd_ctx *ctx) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1040 { |
|
4371
a7f3d85f54ce
Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents:
4366
diff
changeset
|
1041 unsigned char buf[16 * 1024]; |
|
a7f3d85f54ce
Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents:
4366
diff
changeset
|
1042 struct iovec iov = { |
|
a7f3d85f54ce
Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents:
4366
diff
changeset
|
1043 .iov_base = buf, |
|
a7f3d85f54ce
Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents:
4366
diff
changeset
|
1044 .iov_len = sizeof(buf), |
|
a7f3d85f54ce
Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents:
4366
diff
changeset
|
1045 }; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1046 |
|
4808
8761aaee4efe
Linux: improve the netlink API more
Roy Marples <roy@marples.name>
parents:
4804
diff
changeset
|
1047 return if_getnetlink(ctx, &iov, ctx->link_fd, MSG_DONTWAIT, |
|
8761aaee4efe
Linux: improve the netlink API more
Roy Marples <roy@marples.name>
parents:
4804
diff
changeset
|
1048 &link_netlink, NULL); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1049 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1050 |
|
4944
572ef46ecde3
Linux: clean up some compile warnings without privsep
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
1051 #ifdef PRIVSEP |
|
4840
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4828
diff
changeset
|
1052 static bool |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4828
diff
changeset
|
1053 if_netlinkpriv(int protocol, struct nlmsghdr *nlm) |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4828
diff
changeset
|
1054 { |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4828
diff
changeset
|
1055 |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4828
diff
changeset
|
1056 if (protocol != NETLINK_ROUTE) |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4828
diff
changeset
|
1057 return false; |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4828
diff
changeset
|
1058 |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4828
diff
changeset
|
1059 switch(nlm->nlmsg_type) { |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4828
diff
changeset
|
1060 case RTM_NEWADDR: /* FALLTHROUGH */ |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4828
diff
changeset
|
1061 case RTM_DELADDR: /* FALLTHROUGH */ |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4828
diff
changeset
|
1062 case RTM_NEWROUTE: /* FALLTHROUGH */ |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4828
diff
changeset
|
1063 case RTM_DELROUTE: /* FALLTHROUGH */ |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4828
diff
changeset
|
1064 case RTM_NEWLINK: |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4828
diff
changeset
|
1065 return true; |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4828
diff
changeset
|
1066 default: |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4828
diff
changeset
|
1067 return false; |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4828
diff
changeset
|
1068 } |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4828
diff
changeset
|
1069 } |
|
4944
572ef46ecde3
Linux: clean up some compile warnings without privsep
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
1070 #endif |
|
4840
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4828
diff
changeset
|
1071 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1072 static int |
|
4808
8761aaee4efe
Linux: improve the netlink API more
Roy Marples <roy@marples.name>
parents:
4804
diff
changeset
|
1073 if_sendnetlink(struct dhcpcd_ctx *ctx, int protocol, struct nlmsghdr *hdr, |
|
8761aaee4efe
Linux: improve the netlink API more
Roy Marples <roy@marples.name>
parents:
4804
diff
changeset
|
1074 int (*cb)(struct dhcpcd_ctx *, void *, struct nlmsghdr *), void *cbarg) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1075 { |
|
5386
b28b0962bfe2
Linux: keep the generic netlink socket around to get ssid with privsep
Roy Marples <roy@marples.name>
parents:
5384
diff
changeset
|
1076 int s; |
|
4371
a7f3d85f54ce
Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents:
4366
diff
changeset
|
1077 struct sockaddr_nl snl = { .nl_family = AF_NETLINK }; |
|
a7f3d85f54ce
Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents:
4366
diff
changeset
|
1078 struct iovec iov = { .iov_base = hdr, .iov_len = hdr->nlmsg_len }; |
|
a7f3d85f54ce
Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents:
4366
diff
changeset
|
1079 struct msghdr msg = { |
|
a7f3d85f54ce
Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents:
4366
diff
changeset
|
1080 .msg_name = &snl, .msg_namelen = sizeof(snl), |
|
a7f3d85f54ce
Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents:
4366
diff
changeset
|
1081 .msg_iov = &iov, .msg_iovlen = 1 |
|
a7f3d85f54ce
Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents:
4366
diff
changeset
|
1082 }; |
|
5386
b28b0962bfe2
Linux: keep the generic netlink socket around to get ssid with privsep
Roy Marples <roy@marples.name>
parents:
5384
diff
changeset
|
1083 struct priv *priv = (struct priv *)ctx->priv; |
|
b28b0962bfe2
Linux: keep the generic netlink socket around to get ssid with privsep
Roy Marples <roy@marples.name>
parents:
5384
diff
changeset
|
1084 unsigned char buf[16 * 1024]; |
|
b28b0962bfe2
Linux: keep the generic netlink socket around to get ssid with privsep
Roy Marples <roy@marples.name>
parents:
5384
diff
changeset
|
1085 struct iovec riov = { |
|
b28b0962bfe2
Linux: keep the generic netlink socket around to get ssid with privsep
Roy Marples <roy@marples.name>
parents:
5384
diff
changeset
|
1086 .iov_base = buf, |
|
b28b0962bfe2
Linux: keep the generic netlink socket around to get ssid with privsep
Roy Marples <roy@marples.name>
parents:
5384
diff
changeset
|
1087 .iov_len = sizeof(buf), |
|
b28b0962bfe2
Linux: keep the generic netlink socket around to get ssid with privsep
Roy Marples <roy@marples.name>
parents:
5384
diff
changeset
|
1088 }; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1089 |
|
4840
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4828
diff
changeset
|
1090 /* Request a reply */ |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4828
diff
changeset
|
1091 hdr->nlmsg_flags |= NLM_F_ACK; |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4828
diff
changeset
|
1092 hdr->nlmsg_seq = (uint32_t)++ctx->seq; |
|
5387
08cbef5c8e9e
Linux: Warn if netlink(7) seq number doesn't match expectation.
Roy Marples <roy@marples.name>
parents:
5386
diff
changeset
|
1093 if ((unsigned int)ctx->seq > UINT32_MAX) |
|
08cbef5c8e9e
Linux: Warn if netlink(7) seq number doesn't match expectation.
Roy Marples <roy@marples.name>
parents:
5386
diff
changeset
|
1094 ctx->seq = 0; |
|
4840
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4828
diff
changeset
|
1095 |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4828
diff
changeset
|
1096 #ifdef PRIVSEP |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4828
diff
changeset
|
1097 if (ctx->options & DHCPCD_PRIVSEP && if_netlinkpriv(protocol, hdr)) |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4828
diff
changeset
|
1098 return (int)ps_root_sendnetlink(ctx, protocol, &msg); |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4828
diff
changeset
|
1099 #endif |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4828
diff
changeset
|
1100 |
|
5386
b28b0962bfe2
Linux: keep the generic netlink socket around to get ssid with privsep
Roy Marples <roy@marples.name>
parents:
5384
diff
changeset
|
1101 switch (protocol) { |
|
b28b0962bfe2
Linux: keep the generic netlink socket around to get ssid with privsep
Roy Marples <roy@marples.name>
parents:
5384
diff
changeset
|
1102 case NETLINK_ROUTE: |
|
5533
8f117781bb06
Linux: Fix detecting existing IPv4 addresses
Roy Marples <roy@marples.name>
parents:
5486
diff
changeset
|
1103 s = priv->route_fd; |
|
8f117781bb06
Linux: Fix detecting existing IPv4 addresses
Roy Marples <roy@marples.name>
parents:
5486
diff
changeset
|
1104 break; |
|
5386
b28b0962bfe2
Linux: keep the generic netlink socket around to get ssid with privsep
Roy Marples <roy@marples.name>
parents:
5384
diff
changeset
|
1105 case NETLINK_GENERIC: |
|
b28b0962bfe2
Linux: keep the generic netlink socket around to get ssid with privsep
Roy Marples <roy@marples.name>
parents:
5384
diff
changeset
|
1106 s = priv->generic_fd; |
|
b28b0962bfe2
Linux: keep the generic netlink socket around to get ssid with privsep
Roy Marples <roy@marples.name>
parents:
5384
diff
changeset
|
1107 #if 0 |
|
4781
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1108 #ifdef NETLINK_GET_STRICT_CHK |
|
4970
64b25cbb621f
Linux: Use the persistent route socket for writing netlink msgs
Roy Marples <roy@marples.name>
parents:
4962
diff
changeset
|
1109 if (hdr->nlmsg_type == RTM_GETADDR) { |
|
64b25cbb621f
Linux: Use the persistent route socket for writing netlink msgs
Roy Marples <roy@marples.name>
parents:
4962
diff
changeset
|
1110 int on = 1; |
|
4781
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1111 |
|
4970
64b25cbb621f
Linux: Use the persistent route socket for writing netlink msgs
Roy Marples <roy@marples.name>
parents:
4962
diff
changeset
|
1112 if (setsockopt(s, SOL_NETLINK, NETLINK_GET_STRICT_CHK, |
|
5051
5f9bca74bad0
Linux: mask the NETLINK_GET_STRICT_CHK: Protocol not available error
Roy Marples <roy@marples.name>
parents:
5026
diff
changeset
|
1113 &on, sizeof(on)) == -1 && errno != ENOPROTOOPT) |
|
4970
64b25cbb621f
Linux: Use the persistent route socket for writing netlink msgs
Roy Marples <roy@marples.name>
parents:
4962
diff
changeset
|
1114 logerr("%s: NETLINK_GET_STRICT_CHK", __func__); |
|
64b25cbb621f
Linux: Use the persistent route socket for writing netlink msgs
Roy Marples <roy@marples.name>
parents:
4962
diff
changeset
|
1115 } |
|
64b25cbb621f
Linux: Use the persistent route socket for writing netlink msgs
Roy Marples <roy@marples.name>
parents:
4962
diff
changeset
|
1116 #endif |
|
5386
b28b0962bfe2
Linux: keep the generic netlink socket around to get ssid with privsep
Roy Marples <roy@marples.name>
parents:
5384
diff
changeset
|
1117 #endif |
|
b28b0962bfe2
Linux: keep the generic netlink socket around to get ssid with privsep
Roy Marples <roy@marples.name>
parents:
5384
diff
changeset
|
1118 break; |
|
b28b0962bfe2
Linux: keep the generic netlink socket around to get ssid with privsep
Roy Marples <roy@marples.name>
parents:
5384
diff
changeset
|
1119 default: |
|
b28b0962bfe2
Linux: keep the generic netlink socket around to get ssid with privsep
Roy Marples <roy@marples.name>
parents:
5384
diff
changeset
|
1120 errno = EINVAL; |
|
b28b0962bfe2
Linux: keep the generic netlink socket around to get ssid with privsep
Roy Marples <roy@marples.name>
parents:
5384
diff
changeset
|
1121 return -1; |
|
4804
4b8a5e58ffcc
Linux: always open a netlink socket when writing netlink messages
Roy Marples <roy@marples.name>
parents:
4781
diff
changeset
|
1122 } |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1123 |
|
5386
b28b0962bfe2
Linux: keep the generic netlink socket around to get ssid with privsep
Roy Marples <roy@marples.name>
parents:
5384
diff
changeset
|
1124 if (sendmsg(s, &msg, 0) == -1) |
|
b28b0962bfe2
Linux: keep the generic netlink socket around to get ssid with privsep
Roy Marples <roy@marples.name>
parents:
5384
diff
changeset
|
1125 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
|
1126 |
|
5386
b28b0962bfe2
Linux: keep the generic netlink socket around to get ssid with privsep
Roy Marples <roy@marples.name>
parents:
5384
diff
changeset
|
1127 return if_getnetlink(ctx, &riov, s, 0, cb, cbarg); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1128 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1129 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1130 #define NLMSG_TAIL(nmsg) \ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1131 ((struct rtattr *)(((ptrdiff_t)(nmsg))+NLMSG_ALIGN((nmsg)->nlmsg_len))) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1132 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1133 static int |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1134 add_attr_l(struct nlmsghdr *n, unsigned short maxlen, unsigned short type, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1135 const void *data, unsigned short alen) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1136 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1137 unsigned short len = (unsigned short)RTA_LENGTH(alen); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1138 struct rtattr *rta; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1139 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1140 if (NLMSG_ALIGN(n->nlmsg_len) + RTA_ALIGN(len) > maxlen) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1141 errno = ENOBUFS; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1142 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1143 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1144 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1145 rta = NLMSG_TAIL(n); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1146 rta->rta_type = type; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1147 rta->rta_len = len; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1148 if (alen) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1149 memcpy(RTA_DATA(rta), data, alen); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1150 n->nlmsg_len = NLMSG_ALIGN(n->nlmsg_len) + RTA_ALIGN(len); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1151 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1152 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1153 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1154 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1155 static int |
|
5130
d34c808ae81e
Linux: Note router preference when adding routes
Roy Marples <roy@marples.name>
parents:
5115
diff
changeset
|
1156 add_attr_8(struct nlmsghdr *n, unsigned short maxlen, unsigned short type, |
|
d34c808ae81e
Linux: Note router preference when adding routes
Roy Marples <roy@marples.name>
parents:
5115
diff
changeset
|
1157 uint8_t data) |
|
d34c808ae81e
Linux: Note router preference when adding routes
Roy Marples <roy@marples.name>
parents:
5115
diff
changeset
|
1158 { |
|
d34c808ae81e
Linux: Note router preference when adding routes
Roy Marples <roy@marples.name>
parents:
5115
diff
changeset
|
1159 |
|
d34c808ae81e
Linux: Note router preference when adding routes
Roy Marples <roy@marples.name>
parents:
5115
diff
changeset
|
1160 return add_attr_l(n, maxlen, type, &data, sizeof(data)); |
|
d34c808ae81e
Linux: Note router preference when adding routes
Roy Marples <roy@marples.name>
parents:
5115
diff
changeset
|
1161 } |
|
d34c808ae81e
Linux: Note router preference when adding routes
Roy Marples <roy@marples.name>
parents:
5115
diff
changeset
|
1162 |
|
d34c808ae81e
Linux: Note router preference when adding routes
Roy Marples <roy@marples.name>
parents:
5115
diff
changeset
|
1163 static int |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1164 add_attr_32(struct nlmsghdr *n, unsigned short maxlen, unsigned short type, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1165 uint32_t data) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1166 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1167 unsigned short len = RTA_LENGTH(sizeof(data)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1168 struct rtattr *rta; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1169 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1170 if (NLMSG_ALIGN(n->nlmsg_len) + len > maxlen) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1171 errno = ENOBUFS; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1172 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1173 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1174 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1175 rta = NLMSG_TAIL(n); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1176 rta->rta_type = type; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1177 rta->rta_len = len; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1178 memcpy(RTA_DATA(rta), &data, sizeof(data)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1179 n->nlmsg_len = NLMSG_ALIGN(n->nlmsg_len) + len; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1180 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1181 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1182 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1183 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1184 static int |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1185 rta_add_attr_32(struct rtattr *rta, unsigned short maxlen, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1186 unsigned short type, uint32_t data) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1187 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1188 unsigned short len = RTA_LENGTH(sizeof(data)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1189 struct rtattr *subrta; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1190 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1191 if (RTA_ALIGN(rta->rta_len) + len > maxlen) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1192 errno = ENOBUFS; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1193 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1194 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1195 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1196 subrta = (void *)((char*)rta + RTA_ALIGN(rta->rta_len)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1197 subrta->rta_type = type; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1198 subrta->rta_len = len; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1199 memcpy(RTA_DATA(subrta), &data, sizeof(data)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1200 rta->rta_len = (unsigned short)(NLMSG_ALIGN(rta->rta_len) + len); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1201 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1202 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1203 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1204 #ifdef HAVE_NL80211_H |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1205 static struct nlattr * |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1206 nla_next(struct nlattr *nla, size_t *rem) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1207 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1208 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1209 *rem -= (size_t)NLA_ALIGN(nla->nla_len); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1210 return (void *)((char *)nla + NLA_ALIGN(nla->nla_len)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1211 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1212 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1213 #define NLA_TYPE(nla) ((nla)->nla_type & NLA_TYPE_MASK) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1214 #define NLA_LEN(nla) (unsigned int)((nla)->nla_len - NLA_HDRLEN) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1215 #define NLA_OK(nla, rem) \ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1216 ((rem) >= sizeof(struct nlattr) && \ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1217 (nla)->nla_len >= sizeof(struct nlattr) && \ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1218 (nla)->nla_len <= rem) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1219 #define NLA_DATA(nla) (void *)((char *)(nla) + NLA_HDRLEN) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1220 #define NLA_FOR_EACH_ATTR(pos, head, len, rem) \ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1221 for (pos = head, rem = len; \ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1222 NLA_OK(pos, rem); \ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1223 pos = nla_next(pos, &(rem))) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1224 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1225 struct nlmg |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1226 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1227 struct nlmsghdr hdr; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1228 struct genlmsghdr ghdr; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1229 char buffer[64]; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1230 }; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1231 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1232 static int |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1233 nla_put_32(struct nlmsghdr *n, unsigned short maxlen, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1234 unsigned short type, uint32_t data) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1235 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1236 unsigned short len; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1237 struct nlattr *nla; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1238 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1239 len = NLA_ALIGN(NLA_HDRLEN + sizeof(data)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1240 if (NLMSG_ALIGN(n->nlmsg_len) + len > maxlen) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1241 errno = ENOBUFS; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1242 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1243 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1244 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1245 nla = (struct nlattr *)NLMSG_TAIL(n); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1246 nla->nla_type = type; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1247 nla->nla_len = len; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1248 memcpy(NLA_DATA(nla), &data, sizeof(data)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1249 n->nlmsg_len = NLMSG_ALIGN(n->nlmsg_len) + len; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1250 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1251 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1252 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1253 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1254 static int |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1255 nla_put_string(struct nlmsghdr *n, unsigned short maxlen, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1256 unsigned short type, const char *data) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1257 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1258 struct nlattr *nla; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1259 size_t len, sl; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1260 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1261 sl = strlen(data) + 1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1262 len = NLA_ALIGN(NLA_HDRLEN + sl); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1263 if (NLMSG_ALIGN(n->nlmsg_len) + len > maxlen) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1264 errno = ENOBUFS; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1265 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1266 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1267 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1268 nla = (struct nlattr *)NLMSG_TAIL(n); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1269 nla->nla_type = type; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1270 nla->nla_len = (unsigned short)len; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1271 memcpy(NLA_DATA(nla), data, sl); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1272 n->nlmsg_len = NLMSG_ALIGN(n->nlmsg_len) + (unsigned short)len; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1273 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1274 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1275 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1276 static int |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1277 nla_parse(struct nlattr *tb[], struct nlattr *head, size_t len, int maxtype) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1278 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1279 struct nlattr *nla; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1280 size_t rem; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1281 int type; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1282 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1283 memset(tb, 0, sizeof(*tb) * ((unsigned int)maxtype + 1)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1284 NLA_FOR_EACH_ATTR(nla, head, len, rem) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1285 type = NLA_TYPE(nla); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1286 if (type > maxtype) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1287 continue; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1288 tb[type] = nla; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1289 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1290 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1291 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1292 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1293 static int |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1294 genl_parse(struct nlmsghdr *nlm, struct nlattr *tb[], int maxtype) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1295 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1296 struct genlmsghdr *ghdr; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1297 struct nlattr *head; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1298 size_t len; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1299 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1300 ghdr = NLMSG_DATA(nlm); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1301 head = (void *)((char *)ghdr + GENL_HDRLEN); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1302 len = nlm->nlmsg_len - GENL_HDRLEN - NLMSG_HDRLEN; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1303 return nla_parse(tb, head, len, maxtype); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1304 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1305 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1306 static int |
|
4400
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4371
diff
changeset
|
1307 _gnl_getfamily(__unused struct dhcpcd_ctx *ctx, __unused void *arg, |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1308 struct nlmsghdr *nlm) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1309 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1310 struct nlattr *tb[CTRL_ATTR_FAMILY_ID + 1]; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1311 uint16_t family; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1312 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1313 if (genl_parse(nlm, tb, CTRL_ATTR_FAMILY_ID) == -1) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1314 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1315 if (tb[CTRL_ATTR_FAMILY_ID] == NULL) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1316 errno = ENOENT; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1317 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1318 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1319 memcpy(&family, NLA_DATA(tb[CTRL_ATTR_FAMILY_ID]), sizeof(family)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1320 return (int)family; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1321 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1322 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1323 static int |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1324 gnl_getfamily(struct dhcpcd_ctx *ctx, const char *name) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1325 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1326 struct nlmg nlm; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1327 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1328 memset(&nlm, 0, sizeof(nlm)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1329 nlm.hdr.nlmsg_len = NLMSG_LENGTH(sizeof(struct genlmsghdr)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1330 nlm.hdr.nlmsg_type = GENL_ID_CTRL; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1331 nlm.hdr.nlmsg_flags = NLM_F_REQUEST; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1332 nlm.ghdr.cmd = CTRL_CMD_GETFAMILY; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1333 nlm.ghdr.version = 1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1334 if (nla_put_string(&nlm.hdr, sizeof(nlm), |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1335 CTRL_ATTR_FAMILY_NAME, name) == -1) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1336 return -1; |
|
4808
8761aaee4efe
Linux: improve the netlink API more
Roy Marples <roy@marples.name>
parents:
4804
diff
changeset
|
1337 return if_sendnetlink(ctx, NETLINK_GENERIC, &nlm.hdr, |
|
8761aaee4efe
Linux: improve the netlink API more
Roy Marples <roy@marples.name>
parents:
4804
diff
changeset
|
1338 &_gnl_getfamily, NULL); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1339 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1340 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1341 static int |
|
4400
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4371
diff
changeset
|
1342 _if_getssid_nl80211(__unused struct dhcpcd_ctx *ctx, void *arg, |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1343 struct nlmsghdr *nlm) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1344 { |
|
4400
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4371
diff
changeset
|
1345 struct interface *ifp = arg; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1346 struct nlattr *tb[NL80211_ATTR_BSS + 1]; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1347 struct nlattr *bss[NL80211_BSS_STATUS + 1]; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1348 uint32_t status; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1349 unsigned char *ie; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1350 int ie_len; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1351 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1352 if (genl_parse(nlm, tb, NL80211_ATTR_BSS) == -1) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1353 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1354 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1355 if (tb[NL80211_ATTR_BSS] == NULL) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1356 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1357 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1358 if (nla_parse(bss, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1359 NLA_DATA(tb[NL80211_ATTR_BSS]), |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1360 NLA_LEN(tb[NL80211_ATTR_BSS]), |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1361 NL80211_BSS_STATUS) == -1) |
|
3960
42a6a3d1596e
Remove custom logger and output all diagnostics via syslog(3).
Roy Marples <roy@marples.name>
parents:
3932
diff
changeset
|
1362 return 0; |
|
42a6a3d1596e
Remove custom logger and output all diagnostics via syslog(3).
Roy Marples <roy@marples.name>
parents:
3932
diff
changeset
|
1363 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1364 if (bss[NL80211_BSS_BSSID] == NULL || bss[NL80211_BSS_STATUS] == NULL) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1365 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1366 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1367 memcpy(&status, NLA_DATA(bss[NL80211_BSS_STATUS]), sizeof(status)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1368 if (status != NL80211_BSS_STATUS_ASSOCIATED) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1369 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1370 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1371 if (bss[NL80211_BSS_INFORMATION_ELEMENTS] == NULL) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1372 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1373 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1374 ie = NLA_DATA(bss[NL80211_BSS_INFORMATION_ELEMENTS]); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1375 ie_len = (int)NLA_LEN(bss[NL80211_BSS_INFORMATION_ELEMENTS]); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1376 /* ie[0] is type, ie[1] is lenth, ie[2..] is data */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1377 while (ie_len >= 2 && ie_len >= ie[1]) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1378 if (ie[0] == 0) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1379 /* SSID */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1380 if (ie[1] > IF_SSIDLEN) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1381 errno = ENOBUFS; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1382 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1383 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1384 ifp->ssid_len = ie[1]; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1385 memcpy(ifp->ssid, ie + 2, ifp->ssid_len); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1386 return (int)ifp->ssid_len; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1387 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1388 ie_len -= ie[1] + 2; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1389 ie += ie[1] + 2; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1390 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1391 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1392 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1393 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1394 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1395 static int |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1396 if_getssid_nl80211(struct interface *ifp) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1397 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1398 int family; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1399 struct nlmg nlm; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1400 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1401 errno = 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1402 family = gnl_getfamily(ifp->ctx, "nl80211"); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1403 if (family == -1) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1404 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1405 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1406 /* Is this a wireless interface? */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1407 memset(&nlm, 0, sizeof(nlm)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1408 nlm.hdr.nlmsg_len = NLMSG_LENGTH(sizeof(struct genlmsghdr)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1409 nlm.hdr.nlmsg_type = (unsigned short)family; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1410 nlm.hdr.nlmsg_flags = NLM_F_REQUEST; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1411 nlm.ghdr.cmd = NL80211_CMD_GET_WIPHY; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1412 nla_put_32(&nlm.hdr, sizeof(nlm), NL80211_ATTR_IFINDEX, ifp->index); |
|
4808
8761aaee4efe
Linux: improve the netlink API more
Roy Marples <roy@marples.name>
parents:
4804
diff
changeset
|
1413 if (if_sendnetlink(ifp->ctx, NETLINK_GENERIC, &nlm.hdr, |
|
8761aaee4efe
Linux: improve the netlink API more
Roy Marples <roy@marples.name>
parents:
4804
diff
changeset
|
1414 NULL, NULL) == -1) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1415 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1416 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1417 /* We need to parse out the list of scan results and find the one |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1418 * we are connected to. */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1419 memset(&nlm, 0, sizeof(nlm)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1420 nlm.hdr.nlmsg_len = NLMSG_LENGTH(sizeof(struct genlmsghdr)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1421 nlm.hdr.nlmsg_type = (unsigned short)family; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1422 nlm.hdr.nlmsg_flags = NLM_F_REQUEST | NLM_F_DUMP; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1423 nlm.ghdr.cmd = NL80211_CMD_GET_SCAN; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1424 nla_put_32(&nlm.hdr, sizeof(nlm), NL80211_ATTR_IFINDEX, ifp->index); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1425 |
|
4808
8761aaee4efe
Linux: improve the netlink API more
Roy Marples <roy@marples.name>
parents:
4804
diff
changeset
|
1426 return if_sendnetlink(ifp->ctx, NETLINK_GENERIC, &nlm.hdr, |
|
8761aaee4efe
Linux: improve the netlink API more
Roy Marples <roy@marples.name>
parents:
4804
diff
changeset
|
1427 &_if_getssid_nl80211, ifp); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1428 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1429 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1430 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1431 int |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1432 if_getssid(struct interface *ifp) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1433 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1434 int r; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1435 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1436 #ifdef HAVE_NL80211_H |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1437 r = if_getssid_nl80211(ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1438 if (r == -1) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1439 ifp->ssid_len = 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1440 #else |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1441 r = if_getssid_wext(ifp->name, ifp->ssid); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1442 if (r != -1) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1443 ifp->ssid_len = (unsigned int)r; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1444 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1445 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1446 ifp->ssid[ifp->ssid_len] = '\0'; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1447 return r; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1448 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1449 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1450 struct nlma |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1451 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1452 struct nlmsghdr hdr; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1453 struct ifaddrmsg ifa; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1454 char buffer[64]; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1455 }; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1456 |
|
4781
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1457 #ifdef INET |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1458 struct ifiaddr |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1459 { |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1460 unsigned int ifa_ifindex; |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1461 struct in_addr ifa_addr; |
|
5533
8f117781bb06
Linux: Fix detecting existing IPv4 addresses
Roy Marples <roy@marples.name>
parents:
5486
diff
changeset
|
1462 bool ifa_found; |
|
4781
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1463 }; |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1464 |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1465 static int |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1466 _if_addressexists(__unused struct dhcpcd_ctx *ctx, |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1467 void *arg, struct nlmsghdr *nlm) |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1468 { |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1469 struct ifiaddr *ia = arg; |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1470 in_addr_t this_addr; |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1471 size_t len; |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1472 struct rtattr *rta; |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1473 struct ifaddrmsg *ifa; |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1474 |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1475 ifa = NLMSG_DATA(nlm); |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1476 if (ifa->ifa_index != ia->ifa_ifindex || ifa->ifa_family != AF_INET) |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1477 return 0; |
|
5533
8f117781bb06
Linux: Fix detecting existing IPv4 addresses
Roy Marples <roy@marples.name>
parents:
5486
diff
changeset
|
1478 |
|
4884
1378ef92e8bc
Linux: remove some casts no longer needed
Roy Marples <roy@marples.name>
parents:
4840
diff
changeset
|
1479 rta = IFA_RTA(ifa); |
|
4781
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1480 len = NLMSG_PAYLOAD(nlm, sizeof(*ifa)); |
|
4897
877cf2803035
Linux: Move RTA_OK and RTA_NEXT from a while to a for loop.
Roy Marples <roy@marples.name>
parents:
4885
diff
changeset
|
1481 for (; RTA_OK(rta, len); rta = RTA_NEXT(rta, len)) { |
|
4781
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1482 switch (rta->rta_type) { |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1483 case IFA_LOCAL: |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1484 memcpy(&this_addr, RTA_DATA(rta), sizeof(this_addr)); |
|
5533
8f117781bb06
Linux: Fix detecting existing IPv4 addresses
Roy Marples <roy@marples.name>
parents:
5486
diff
changeset
|
1485 if (this_addr == ia->ifa_addr.s_addr) { |
|
8f117781bb06
Linux: Fix detecting existing IPv4 addresses
Roy Marples <roy@marples.name>
parents:
5486
diff
changeset
|
1486 ia->ifa_found = true; |
|
8f117781bb06
Linux: Fix detecting existing IPv4 addresses
Roy Marples <roy@marples.name>
parents:
5486
diff
changeset
|
1487 return 1; |
|
8f117781bb06
Linux: Fix detecting existing IPv4 addresses
Roy Marples <roy@marples.name>
parents:
5486
diff
changeset
|
1488 } |
|
8f117781bb06
Linux: Fix detecting existing IPv4 addresses
Roy Marples <roy@marples.name>
parents:
5486
diff
changeset
|
1489 break; |
|
4781
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1490 } |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1491 } |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1492 return 0; |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1493 } |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1494 |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1495 static int |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1496 if_addressexists(struct interface *ifp, struct in_addr *addr) |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1497 { |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1498 struct ifiaddr ia = { |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1499 .ifa_ifindex = ifp->index, |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1500 .ifa_addr = *addr, |
|
5533
8f117781bb06
Linux: Fix detecting existing IPv4 addresses
Roy Marples <roy@marples.name>
parents:
5486
diff
changeset
|
1501 .ifa_found = false, |
|
4781
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1502 }; |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1503 struct nlma nlm = { |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1504 .hdr.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg)), |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1505 .hdr.nlmsg_type = RTM_GETADDR, |
|
5533
8f117781bb06
Linux: Fix detecting existing IPv4 addresses
Roy Marples <roy@marples.name>
parents:
5486
diff
changeset
|
1506 .hdr.nlmsg_flags = NLM_F_REQUEST | NLM_F_MATCH, |
|
4781
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1507 .ifa.ifa_family = AF_INET, |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1508 .ifa.ifa_index = ifp->index, |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1509 }; |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1510 |
|
5533
8f117781bb06
Linux: Fix detecting existing IPv4 addresses
Roy Marples <roy@marples.name>
parents:
5486
diff
changeset
|
1511 int error = if_sendnetlink(ifp->ctx, NETLINK_ROUTE, &nlm.hdr, |
|
4808
8761aaee4efe
Linux: improve the netlink API more
Roy Marples <roy@marples.name>
parents:
4804
diff
changeset
|
1512 &_if_addressexists, &ia); |
|
5533
8f117781bb06
Linux: Fix detecting existing IPv4 addresses
Roy Marples <roy@marples.name>
parents:
5486
diff
changeset
|
1513 if (error == -1) |
|
8f117781bb06
Linux: Fix detecting existing IPv4 addresses
Roy Marples <roy@marples.name>
parents:
5486
diff
changeset
|
1514 return -1; |
|
8f117781bb06
Linux: Fix detecting existing IPv4 addresses
Roy Marples <roy@marples.name>
parents:
5486
diff
changeset
|
1515 return ia.ifa_found ? 1 : 0; |
|
4781
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1516 } |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1517 #endif |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1518 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1519 struct nlmr |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1520 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1521 struct nlmsghdr hdr; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1522 struct rtmsg rt; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1523 char buffer[256]; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1524 }; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1525 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1526 int |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1527 if_route(unsigned char cmd, const struct rt *rt) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1528 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1529 struct nlmr nlm; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1530 bool gateway_unspec; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1531 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1532 memset(&nlm, 0, sizeof(nlm)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1533 nlm.hdr.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1534 switch (cmd) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1535 case RTM_CHANGE: |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1536 nlm.hdr.nlmsg_type = RTM_NEWROUTE; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1537 nlm.hdr.nlmsg_flags = NLM_F_CREATE | NLM_F_REPLACE; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1538 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1539 case RTM_ADD: |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1540 nlm.hdr.nlmsg_type = RTM_NEWROUTE; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1541 nlm.hdr.nlmsg_flags = NLM_F_CREATE | NLM_F_EXCL; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1542 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1543 case RTM_DELETE: |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1544 nlm.hdr.nlmsg_type = RTM_DELROUTE; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1545 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1546 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1547 nlm.hdr.nlmsg_flags |= NLM_F_REQUEST; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1548 nlm.rt.rtm_family = (unsigned char)rt->rt_dest.sa_family; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1549 nlm.rt.rtm_table = RT_TABLE_MAIN; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1550 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1551 gateway_unspec = sa_is_unspecified(&rt->rt_gateway); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1552 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1553 if (cmd == RTM_DELETE) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1554 nlm.rt.rtm_scope = RT_SCOPE_NOWHERE; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1555 } else { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1556 /* Address generated routes are RTPROT_KERNEL, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1557 * otherwise RTPROT_BOOT */ |
|
4161
a40c7c100a45
Set RA routes as RA in supported OS's.
Roy Marples <roy@marples.name>
parents:
4147
diff
changeset
|
1558 #ifdef RTPROT_RA |
|
a40c7c100a45
Set RA routes as RA in supported OS's.
Roy Marples <roy@marples.name>
parents:
4147
diff
changeset
|
1559 if (rt->rt_dflags & RTDF_RA) |
|
a40c7c100a45
Set RA routes as RA in supported OS's.
Roy Marples <roy@marples.name>
parents:
4147
diff
changeset
|
1560 nlm.rt.rtm_protocol = RTPROT_RA; |
|
a40c7c100a45
Set RA routes as RA in supported OS's.
Roy Marples <roy@marples.name>
parents:
4147
diff
changeset
|
1561 else |
|
a40c7c100a45
Set RA routes as RA in supported OS's.
Roy Marples <roy@marples.name>
parents:
4147
diff
changeset
|
1562 #endif |
|
4162
fbed6260b7e1
Set DHCP routes as DHCP in supported OS's.
Roy Marples <roy@marples.name>
parents:
4161
diff
changeset
|
1563 #ifdef RTPROT_DHCP |
|
fbed6260b7e1
Set DHCP routes as DHCP in supported OS's.
Roy Marples <roy@marples.name>
parents:
4161
diff
changeset
|
1564 if (rt->rt_dflags & RTDF_DHCP) |
|
fbed6260b7e1
Set DHCP routes as DHCP in supported OS's.
Roy Marples <roy@marples.name>
parents:
4161
diff
changeset
|
1565 nlm.rt.rtm_protocol = RTPROT_DHCP; |
|
fbed6260b7e1
Set DHCP routes as DHCP in supported OS's.
Roy Marples <roy@marples.name>
parents:
4161
diff
changeset
|
1566 else |
|
fbed6260b7e1
Set DHCP routes as DHCP in supported OS's.
Roy Marples <roy@marples.name>
parents:
4161
diff
changeset
|
1567 #endif |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1568 if (rt->rt_dflags & RTDF_IFA_ROUTE) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1569 nlm.rt.rtm_protocol = RTPROT_KERNEL; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1570 else |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1571 nlm.rt.rtm_protocol = RTPROT_BOOT; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1572 if (rt->rt_ifp->flags & IFF_LOOPBACK) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1573 nlm.rt.rtm_scope = RT_SCOPE_HOST; |
|
4292
3d4667e8f9c9
linux: fix adding host routes
Roy Marples <roy@marples.name>
parents:
4257
diff
changeset
|
1574 else if (gateway_unspec) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1575 nlm.rt.rtm_scope = RT_SCOPE_LINK; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1576 else |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1577 nlm.rt.rtm_scope = RT_SCOPE_UNIVERSE; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1578 if (rt->rt_flags & RTF_REJECT) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1579 nlm.rt.rtm_type = RTN_UNREACHABLE; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1580 else |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1581 nlm.rt.rtm_type = RTN_UNICAST; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1582 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1583 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1584 #define ADDSA(type, sa) \ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1585 add_attr_l(&nlm.hdr, sizeof(nlm), (type), \ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1586 (const char *)(sa) + sa_addroffset((sa)), \ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1587 (unsigned short)sa_addrlen((sa))); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1588 nlm.rt.rtm_dst_len = (unsigned char)sa_toprefix(&rt->rt_netmask); |
|
4574
901ff4b0952b
Linux: Mark another coverity false positive.
Roy Marples <roy@marples.name>
parents:
4572
diff
changeset
|
1589 /* rt->rt_dest and rt->gateway are unions where sockaddr_in6 |
|
901ff4b0952b
Linux: Mark another coverity false positive.
Roy Marples <roy@marples.name>
parents:
4572
diff
changeset
|
1590 * is the biggest member. However, we access them as the |
|
901ff4b0952b
Linux: Mark another coverity false positive.
Roy Marples <roy@marples.name>
parents:
4572
diff
changeset
|
1591 * generic sockaddr and coverity thinks this will overrun. */ |
|
901ff4b0952b
Linux: Mark another coverity false positive.
Roy Marples <roy@marples.name>
parents:
4572
diff
changeset
|
1592 /* coverity[overrun-buffer-arg] */ |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1593 ADDSA(RTA_DST, &rt->rt_dest); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1594 if (cmd == RTM_ADD || cmd == RTM_CHANGE) { |
|
4574
901ff4b0952b
Linux: Mark another coverity false positive.
Roy Marples <roy@marples.name>
parents:
4572
diff
changeset
|
1595 if (!gateway_unspec) { |
|
901ff4b0952b
Linux: Mark another coverity false positive.
Roy Marples <roy@marples.name>
parents:
4572
diff
changeset
|
1596 /* coverity[overrun-buffer-arg] */ |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1597 ADDSA(RTA_GATEWAY, &rt->rt_gateway); |
|
4574
901ff4b0952b
Linux: Mark another coverity false positive.
Roy Marples <roy@marples.name>
parents:
4572
diff
changeset
|
1598 } |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1599 /* Cannot add tentative source addresses. |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1600 * We don't know this here, so just skip INET6 ifa's.*/ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1601 if (!sa_is_unspecified(&rt->rt_ifa) && |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1602 rt->rt_ifa.sa_family != AF_INET6) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1603 ADDSA(RTA_PREFSRC, &rt->rt_ifa); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1604 if (rt->rt_mtu) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1605 char metricsbuf[32]; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1606 struct rtattr *metrics = (void *)metricsbuf; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1607 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1608 metrics->rta_type = RTA_METRICS; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1609 metrics->rta_len = RTA_LENGTH(0); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1610 rta_add_attr_32(metrics, sizeof(metricsbuf), |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1611 RTAX_MTU, rt->rt_mtu); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1612 add_attr_l(&nlm.hdr, sizeof(nlm), RTA_METRICS, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1613 RTA_DATA(metrics), |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1614 (unsigned short)RTA_PAYLOAD(metrics)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1615 } |
|
5130
d34c808ae81e
Linux: Note router preference when adding routes
Roy Marples <roy@marples.name>
parents:
5115
diff
changeset
|
1616 |
|
5341
b5656c618975
Linux: Fix compile for systems without route preference
Roy Marples <roy@marples.name>
parents:
5285
diff
changeset
|
1617 #ifdef HAVE_ROUTE_PREF |
|
5130
d34c808ae81e
Linux: Note router preference when adding routes
Roy Marples <roy@marples.name>
parents:
5115
diff
changeset
|
1618 if (rt->rt_dflags & RTDF_RA) { |
|
d34c808ae81e
Linux: Note router preference when adding routes
Roy Marples <roy@marples.name>
parents:
5115
diff
changeset
|
1619 uint8_t pref; |
|
d34c808ae81e
Linux: Note router preference when adding routes
Roy Marples <roy@marples.name>
parents:
5115
diff
changeset
|
1620 |
|
d34c808ae81e
Linux: Note router preference when adding routes
Roy Marples <roy@marples.name>
parents:
5115
diff
changeset
|
1621 switch(rt->rt_pref) { |
|
d34c808ae81e
Linux: Note router preference when adding routes
Roy Marples <roy@marples.name>
parents:
5115
diff
changeset
|
1622 case RTPREF_LOW: |
|
d34c808ae81e
Linux: Note router preference when adding routes
Roy Marples <roy@marples.name>
parents:
5115
diff
changeset
|
1623 pref = ICMPV6_ROUTER_PREF_LOW; |
|
d34c808ae81e
Linux: Note router preference when adding routes
Roy Marples <roy@marples.name>
parents:
5115
diff
changeset
|
1624 break; |
|
d34c808ae81e
Linux: Note router preference when adding routes
Roy Marples <roy@marples.name>
parents:
5115
diff
changeset
|
1625 case RTPREF_MEDIUM: |
|
d34c808ae81e
Linux: Note router preference when adding routes
Roy Marples <roy@marples.name>
parents:
5115
diff
changeset
|
1626 pref = ICMPV6_ROUTER_PREF_MEDIUM; |
|
d34c808ae81e
Linux: Note router preference when adding routes
Roy Marples <roy@marples.name>
parents:
5115
diff
changeset
|
1627 break; |
|
d34c808ae81e
Linux: Note router preference when adding routes
Roy Marples <roy@marples.name>
parents:
5115
diff
changeset
|
1628 case RTPREF_HIGH: |
|
d34c808ae81e
Linux: Note router preference when adding routes
Roy Marples <roy@marples.name>
parents:
5115
diff
changeset
|
1629 pref = ICMPV6_ROUTER_PREF_HIGH; |
|
d34c808ae81e
Linux: Note router preference when adding routes
Roy Marples <roy@marples.name>
parents:
5115
diff
changeset
|
1630 break; |
|
d34c808ae81e
Linux: Note router preference when adding routes
Roy Marples <roy@marples.name>
parents:
5115
diff
changeset
|
1631 default: |
|
d34c808ae81e
Linux: Note router preference when adding routes
Roy Marples <roy@marples.name>
parents:
5115
diff
changeset
|
1632 pref = ICMPV6_ROUTER_PREF_INVALID; |
|
d34c808ae81e
Linux: Note router preference when adding routes
Roy Marples <roy@marples.name>
parents:
5115
diff
changeset
|
1633 break; |
|
d34c808ae81e
Linux: Note router preference when adding routes
Roy Marples <roy@marples.name>
parents:
5115
diff
changeset
|
1634 } |
|
d34c808ae81e
Linux: Note router preference when adding routes
Roy Marples <roy@marples.name>
parents:
5115
diff
changeset
|
1635 add_attr_8(&nlm.hdr, sizeof(nlm), RTA_PREF, pref); |
|
d34c808ae81e
Linux: Note router preference when adding routes
Roy Marples <roy@marples.name>
parents:
5115
diff
changeset
|
1636 } |
|
5341
b5656c618975
Linux: Fix compile for systems without route preference
Roy Marples <roy@marples.name>
parents:
5285
diff
changeset
|
1637 #endif |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1638 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1639 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1640 if (!sa_is_loopback(&rt->rt_gateway)) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1641 add_attr_32(&nlm.hdr, sizeof(nlm), RTA_OIF, rt->rt_ifp->index); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1642 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1643 if (rt->rt_metric != 0) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1644 add_attr_32(&nlm.hdr, sizeof(nlm), RTA_PRIORITY, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1645 rt->rt_metric); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1646 |
|
4808
8761aaee4efe
Linux: improve the netlink API more
Roy Marples <roy@marples.name>
parents:
4804
diff
changeset
|
1647 return if_sendnetlink(rt->rt_ifp->ctx, NETLINK_ROUTE, &nlm.hdr, |
|
8761aaee4efe
Linux: improve the netlink API more
Roy Marples <roy@marples.name>
parents:
4804
diff
changeset
|
1648 NULL, NULL); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1649 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1650 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1651 static int |
|
4400
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4371
diff
changeset
|
1652 _if_initrt(struct dhcpcd_ctx *ctx, void *arg, |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1653 struct nlmsghdr *nlm) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1654 { |
|
4400
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4371
diff
changeset
|
1655 struct rt rt, *rtn; |
|
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4371
diff
changeset
|
1656 rb_tree_t *kroutes = arg; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1657 |
|
4400
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4371
diff
changeset
|
1658 if (if_copyrt(ctx, &rt, nlm) != 0) |
|
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4371
diff
changeset
|
1659 return 0; |
|
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4371
diff
changeset
|
1660 if ((rtn = rt_new(rt.rt_ifp)) == NULL) { |
|
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4371
diff
changeset
|
1661 logerr(__func__); |
|
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4371
diff
changeset
|
1662 return 0; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1663 } |
|
4400
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4371
diff
changeset
|
1664 memcpy(rtn, &rt, sizeof(*rtn)); |
|
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4371
diff
changeset
|
1665 if (rb_tree_insert_node(kroutes, rtn) != rtn) |
|
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4371
diff
changeset
|
1666 rt_free(rtn); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1667 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1668 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1669 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1670 int |
|
4400
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4371
diff
changeset
|
1671 if_initrt(struct dhcpcd_ctx *ctx, rb_tree_t *kroutes, 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
|
1672 { |
|
4371
a7f3d85f54ce
Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents:
4366
diff
changeset
|
1673 struct nlmr nlm = { |
|
a7f3d85f54ce
Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents:
4366
diff
changeset
|
1674 .hdr.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg)), |
|
a7f3d85f54ce
Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents:
4366
diff
changeset
|
1675 .hdr.nlmsg_type = RTM_GETROUTE, |
|
a7f3d85f54ce
Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents:
4366
diff
changeset
|
1676 .hdr.nlmsg_flags = NLM_F_REQUEST | NLM_F_MATCH, |
|
a7f3d85f54ce
Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents:
4366
diff
changeset
|
1677 .rt.rtm_table = RT_TABLE_MAIN, |
|
a7f3d85f54ce
Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents:
4366
diff
changeset
|
1678 .rt.rtm_family = (unsigned char)af, |
|
a7f3d85f54ce
Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents:
4366
diff
changeset
|
1679 }; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1680 |
|
4808
8761aaee4efe
Linux: improve the netlink API more
Roy Marples <roy@marples.name>
parents:
4804
diff
changeset
|
1681 return if_sendnetlink(ctx, NETLINK_ROUTE, &nlm.hdr, |
|
8761aaee4efe
Linux: improve the netlink API more
Roy Marples <roy@marples.name>
parents:
4804
diff
changeset
|
1682 &_if_initrt, kroutes); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1683 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1684 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1685 #ifdef INET |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1686 /* Linux is a special snowflake when it comes to BPF. */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1687 const char *bpf_name = "Packet Socket"; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1688 |
|
4757
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4750
diff
changeset
|
1689 /* Linux is a special snowflake for opening BPF. */ |
| 5234 | 1690 struct bpf * |
| 1691 bpf_open(const struct interface *ifp, | |
| 1692 int (*filter)(const struct bpf *, const struct in_addr *), | |
| 1693 const struct in_addr *ia) | |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1694 { |
| 5234 | 1695 struct bpf *bpf; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1696 union sockunion { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1697 struct sockaddr sa; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1698 struct sockaddr_ll sll; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1699 struct sockaddr_storage ss; |
|
4757
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4750
diff
changeset
|
1700 } su = { |
|
5383
5f88487cbf65
Linux: fix a compile warning for older compilers
Roy Marples <roy@marples.name>
parents:
5382
diff
changeset
|
1701 .sll = { |
|
5f88487cbf65
Linux: fix a compile warning for older compilers
Roy Marples <roy@marples.name>
parents:
5382
diff
changeset
|
1702 .sll_family = PF_PACKET, |
|
5f88487cbf65
Linux: fix a compile warning for older compilers
Roy Marples <roy@marples.name>
parents:
5382
diff
changeset
|
1703 .sll_protocol = htons(ETH_P_ALL), |
|
5f88487cbf65
Linux: fix a compile warning for older compilers
Roy Marples <roy@marples.name>
parents:
5382
diff
changeset
|
1704 .sll_ifindex = (int)ifp->index, |
|
5f88487cbf65
Linux: fix a compile warning for older compilers
Roy Marples <roy@marples.name>
parents:
5382
diff
changeset
|
1705 } |
|
4757
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4750
diff
changeset
|
1706 }; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1707 #ifdef PACKET_AUXDATA |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1708 int n; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1709 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1710 |
| 5234 | 1711 bpf = calloc(1, sizeof(*bpf)); |
| 1712 if (bpf == NULL) | |
| 1713 return NULL; | |
| 1714 bpf->bpf_ifp = ifp; | |
|
4757
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4750
diff
changeset
|
1715 |
| 5234 | 1716 /* Allocate a suitably large buffer for a single packet. */ |
| 1717 bpf->bpf_size = ETH_DATA_LEN; | |
| 1718 bpf->bpf_buffer = malloc(bpf->bpf_size); | |
| 1719 if (bpf->bpf_buffer == NULL) | |
| 1720 goto eexit; | |
|
4757
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4750
diff
changeset
|
1721 |
| 5234 | 1722 bpf->bpf_fd = xsocket(PF_PACKET, SOCK_RAW|SOCK_CXNB,htons(ETH_P_ALL)); |
| 1723 if (bpf->bpf_fd == -1) | |
| 1724 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
|
1725 |
|
4757
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4750
diff
changeset
|
1726 /* We cannot validate the correct interface, |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4750
diff
changeset
|
1727 * so we MUST set this first. */ |
| 5234 | 1728 if (bind(bpf->bpf_fd, &su.sa, sizeof(su.sll)) == -1) |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4052
diff
changeset
|
1729 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
|
1730 |
| 5234 | 1731 if (filter(bpf, ia) != 0) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1732 goto eexit; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1733 |
|
4757
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4750
diff
changeset
|
1734 /* In the ideal world, this would be set before the bind and filter. */ |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1735 #ifdef PACKET_AUXDATA |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1736 n = 1; |
| 5234 | 1737 if (setsockopt(bpf->bpf_fd, SOL_PACKET, PACKET_AUXDATA, |
| 1738 &n, sizeof(n)) != 0) { | |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1739 if (errno != ENOPROTOOPT) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1740 goto eexit; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1741 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1742 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1743 |
|
4757
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4750
diff
changeset
|
1744 /* |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4750
diff
changeset
|
1745 * At this point we could have received packets for the wrong |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4750
diff
changeset
|
1746 * interface or which don't pass the filter. |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4750
diff
changeset
|
1747 * Linux should flush upon setting the filter like every other OS. |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4750
diff
changeset
|
1748 * There is no way of flushing them from userland. |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4750
diff
changeset
|
1749 * As such, consumers need to inspect each packet to ensure it's valid. |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4750
diff
changeset
|
1750 * Or to put it another way, don't trust the Linux BPF filter. |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4750
diff
changeset
|
1751 */ |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4750
diff
changeset
|
1752 |
| 5234 | 1753 return bpf; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1754 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1755 eexit: |
| 5234 | 1756 if (bpf->bpf_fd != -1) |
| 1757 close(bpf->bpf_fd); | |
| 1758 free(bpf->bpf_buffer); | |
| 1759 free(bpf); | |
| 1760 return NULL; | |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1761 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1762 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1763 /* BPF requires that we read the entire buffer. |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1764 * So we pass the buffer in the API so we can loop on >1 packet. */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1765 ssize_t |
| 5234 | 1766 bpf_read(struct bpf *bpf, void *data, 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
|
1767 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1768 ssize_t bytes; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1769 struct iovec iov = { |
| 5234 | 1770 .iov_base = bpf->bpf_buffer, |
| 1771 .iov_len = bpf->bpf_size, | |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1772 }; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1773 struct msghdr msg = { .msg_iov = &iov, .msg_iovlen = 1 }; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1774 #ifdef PACKET_AUXDATA |
| 5172 | 1775 union { |
| 1776 struct cmsghdr hdr; | |
| 1777 uint8_t buf[CMSG_SPACE(sizeof(struct tpacket_auxdata))]; | |
| 1778 } cmsgbuf = { .buf = { 0 } }; | |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1779 struct cmsghdr *cmsg; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1780 struct tpacket_auxdata *aux; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1781 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1782 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1783 #ifdef PACKET_AUXDATA |
| 5172 | 1784 msg.msg_control = cmsgbuf.buf; |
| 1785 msg.msg_controllen = sizeof(cmsgbuf.buf); | |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1786 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1787 |
| 5234 | 1788 bytes = recvmsg(bpf->bpf_fd, &msg, 0); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1789 if (bytes == -1) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1790 return -1; |
| 5234 | 1791 bpf->bpf_flags |= BPF_EOF; /* We only ever read one packet. */ |
| 1792 bpf->bpf_flags &= ~BPF_PARTIALCSUM; | |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1793 if (bytes) { |
| 5234 | 1794 if (bpf_frame_bcast(bpf->bpf_ifp, bpf->bpf_buffer) == 0) |
| 1795 bpf->bpf_flags |= BPF_BCAST; | |
|
4456
101b31471d89
BPF: Set BPF_MCAST flag as on BSD
Roy Marples <roy@marples.name>
parents:
4421
diff
changeset
|
1796 else |
| 5234 | 1797 bpf->bpf_flags &= ~BPF_BCAST; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1798 if ((size_t)bytes > len) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1799 bytes = (ssize_t)len; |
| 5234 | 1800 memcpy(data, bpf->bpf_buffer, (size_t)bytes); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1801 #ifdef PACKET_AUXDATA |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1802 for (cmsg = CMSG_FIRSTHDR(&msg); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1803 cmsg; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1804 cmsg = CMSG_NXTHDR(&msg, cmsg)) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1805 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1806 if (cmsg->cmsg_level == SOL_PACKET && |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1807 cmsg->cmsg_type == PACKET_AUXDATA) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1808 aux = (void *)CMSG_DATA(cmsg); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1809 if (aux->tp_status & TP_STATUS_CSUMNOTREADY) |
| 5234 | 1810 bpf->bpf_flags |= BPF_PARTIALCSUM; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1811 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1812 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1813 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1814 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1815 return bytes; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1816 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1817 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1818 int |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1819 bpf_attach(int s, void *filter, unsigned int filter_len) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1820 { |
| 4636 | 1821 struct sock_fprog pf = { |
| 1822 .filter = filter, | |
|
4694
426e04b84902
Linux: cast away a compile warning
Roy Marples <roy@marples.name>
parents:
4670
diff
changeset
|
1823 .len = (unsigned short)filter_len, |
| 4636 | 1824 }; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1825 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1826 /* Install the filter. */ |
|
5230
92569921a974
Linux: Lock the BPF filter from future changes
Roy Marples <roy@marples.name>
parents:
5215
diff
changeset
|
1827 if (setsockopt(s, SOL_SOCKET, SO_ATTACH_FILTER, &pf, sizeof(pf)) == -1) |
|
92569921a974
Linux: Lock the BPF filter from future changes
Roy Marples <roy@marples.name>
parents:
5215
diff
changeset
|
1828 return -1; |
|
92569921a974
Linux: Lock the BPF filter from future changes
Roy Marples <roy@marples.name>
parents:
5215
diff
changeset
|
1829 |
|
92569921a974
Linux: Lock the BPF filter from future changes
Roy Marples <roy@marples.name>
parents:
5215
diff
changeset
|
1830 #ifdef SO_LOCK_FILTER |
|
92569921a974
Linux: Lock the BPF filter from future changes
Roy Marples <roy@marples.name>
parents:
5215
diff
changeset
|
1831 int on = 1; |
|
92569921a974
Linux: Lock the BPF filter from future changes
Roy Marples <roy@marples.name>
parents:
5215
diff
changeset
|
1832 |
|
92569921a974
Linux: Lock the BPF filter from future changes
Roy Marples <roy@marples.name>
parents:
5215
diff
changeset
|
1833 if (setsockopt(s, SOL_SOCKET, SO_LOCK_FILTER, &on, sizeof(on)) == -1) |
|
92569921a974
Linux: Lock the BPF filter from future changes
Roy Marples <roy@marples.name>
parents:
5215
diff
changeset
|
1834 return -1; |
|
92569921a974
Linux: Lock the BPF filter from future changes
Roy Marples <roy@marples.name>
parents:
5215
diff
changeset
|
1835 #endif |
|
92569921a974
Linux: Lock the BPF filter from future changes
Roy Marples <roy@marples.name>
parents:
5215
diff
changeset
|
1836 |
|
92569921a974
Linux: Lock the BPF filter from future changes
Roy Marples <roy@marples.name>
parents:
5215
diff
changeset
|
1837 return 0; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1838 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1839 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1840 int |
|
4555
93b4eb29d297
DHCP: Set address vltime and pltime to the length of the lease
Roy Marples <roy@marples.name>
parents:
4548
diff
changeset
|
1841 if_address(unsigned char cmd, const struct ipv4_addr *ia) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1842 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1843 struct nlma nlm; |
|
4555
93b4eb29d297
DHCP: Set address vltime and pltime to the length of the lease
Roy Marples <roy@marples.name>
parents:
4548
diff
changeset
|
1844 struct ifa_cacheinfo cinfo; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1845 int retval = 0; |
| 4609 | 1846 #ifdef IFA_F_NOPREFIXROUTE |
|
4194
f82c8bde229d
linux: use IFA_F_NOPREFIXROUTE for ipv4 addresses
Roy Marples <roy@marples.name>
parents:
4180
diff
changeset
|
1847 uint32_t flags = 0; |
| 4609 | 1848 #endif |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1849 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1850 memset(&nlm, 0, sizeof(nlm)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1851 nlm.hdr.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1852 nlm.hdr.nlmsg_flags = NLM_F_REQUEST; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1853 nlm.hdr.nlmsg_type = cmd; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1854 if (cmd == RTM_NEWADDR) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1855 nlm.hdr.nlmsg_flags |= NLM_F_CREATE | NLM_F_REPLACE; |
|
4555
93b4eb29d297
DHCP: Set address vltime and pltime to the length of the lease
Roy Marples <roy@marples.name>
parents:
4548
diff
changeset
|
1856 nlm.ifa.ifa_index = ia->iface->index; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1857 nlm.ifa.ifa_family = AF_INET; |
|
4555
93b4eb29d297
DHCP: Set address vltime and pltime to the length of the lease
Roy Marples <roy@marples.name>
parents:
4548
diff
changeset
|
1858 |
|
93b4eb29d297
DHCP: Set address vltime and pltime to the length of the lease
Roy Marples <roy@marples.name>
parents:
4548
diff
changeset
|
1859 nlm.ifa.ifa_prefixlen = inet_ntocidr(ia->mask); |
|
93b4eb29d297
DHCP: Set address vltime and pltime to the length of the lease
Roy Marples <roy@marples.name>
parents:
4548
diff
changeset
|
1860 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1861 #if 0 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1862 /* This creates the aliased interface */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1863 add_attr_l(&nlm.hdr, sizeof(nlm), IFA_LABEL, |
|
4555
93b4eb29d297
DHCP: Set address vltime and pltime to the length of the lease
Roy Marples <roy@marples.name>
parents:
4548
diff
changeset
|
1864 ia->iface->alias, |
|
93b4eb29d297
DHCP: Set address vltime and pltime to the length of the lease
Roy Marples <roy@marples.name>
parents:
4548
diff
changeset
|
1865 (unsigned short)(strlen(ia->iface->alias) + 1)); |
|
4194
f82c8bde229d
linux: use IFA_F_NOPREFIXROUTE for ipv4 addresses
Roy Marples <roy@marples.name>
parents:
4180
diff
changeset
|
1866 #endif |
|
f82c8bde229d
linux: use IFA_F_NOPREFIXROUTE for ipv4 addresses
Roy Marples <roy@marples.name>
parents:
4180
diff
changeset
|
1867 |
|
4555
93b4eb29d297
DHCP: Set address vltime and pltime to the length of the lease
Roy Marples <roy@marples.name>
parents:
4548
diff
changeset
|
1868 add_attr_l(&nlm.hdr, sizeof(nlm), IFA_LOCAL, |
|
93b4eb29d297
DHCP: Set address vltime and pltime to the length of the lease
Roy Marples <roy@marples.name>
parents:
4548
diff
changeset
|
1869 &ia->addr.s_addr, sizeof(ia->addr.s_addr)); |
|
93b4eb29d297
DHCP: Set address vltime and pltime to the length of the lease
Roy Marples <roy@marples.name>
parents:
4548
diff
changeset
|
1870 |
|
93b4eb29d297
DHCP: Set address vltime and pltime to the length of the lease
Roy Marples <roy@marples.name>
parents:
4548
diff
changeset
|
1871 if (cmd == RTM_NEWADDR) { |
|
93b4eb29d297
DHCP: Set address vltime and pltime to the length of the lease
Roy Marples <roy@marples.name>
parents:
4548
diff
changeset
|
1872 #ifdef IFA_F_NOPREFIXROUTE |
|
93b4eb29d297
DHCP: Set address vltime and pltime to the length of the lease
Roy Marples <roy@marples.name>
parents:
4548
diff
changeset
|
1873 if (nlm.ifa.ifa_prefixlen < 32) |
|
93b4eb29d297
DHCP: Set address vltime and pltime to the length of the lease
Roy Marples <roy@marples.name>
parents:
4548
diff
changeset
|
1874 flags |= IFA_F_NOPREFIXROUTE; |
| 4609 | 1875 add_attr_32(&nlm.hdr, sizeof(nlm), IFA_FLAGS, flags); |
|
4555
93b4eb29d297
DHCP: Set address vltime and pltime to the length of the lease
Roy Marples <roy@marples.name>
parents:
4548
diff
changeset
|
1876 #endif |
|
93b4eb29d297
DHCP: Set address vltime and pltime to the length of the lease
Roy Marples <roy@marples.name>
parents:
4548
diff
changeset
|
1877 |
|
93b4eb29d297
DHCP: Set address vltime and pltime to the length of the lease
Roy Marples <roy@marples.name>
parents:
4548
diff
changeset
|
1878 add_attr_l(&nlm.hdr, sizeof(nlm), IFA_BROADCAST, |
|
93b4eb29d297
DHCP: Set address vltime and pltime to the length of the lease
Roy Marples <roy@marples.name>
parents:
4548
diff
changeset
|
1879 &ia->brd.s_addr, sizeof(ia->brd.s_addr)); |
|
93b4eb29d297
DHCP: Set address vltime and pltime to the length of the lease
Roy Marples <roy@marples.name>
parents:
4548
diff
changeset
|
1880 |
|
93b4eb29d297
DHCP: Set address vltime and pltime to the length of the lease
Roy Marples <roy@marples.name>
parents:
4548
diff
changeset
|
1881 memset(&cinfo, 0, sizeof(cinfo)); |
|
93b4eb29d297
DHCP: Set address vltime and pltime to the length of the lease
Roy Marples <roy@marples.name>
parents:
4548
diff
changeset
|
1882 cinfo.ifa_prefered = ia->pltime; |
|
93b4eb29d297
DHCP: Set address vltime and pltime to the length of the lease
Roy Marples <roy@marples.name>
parents:
4548
diff
changeset
|
1883 cinfo.ifa_valid = ia->vltime; |
|
93b4eb29d297
DHCP: Set address vltime and pltime to the length of the lease
Roy Marples <roy@marples.name>
parents:
4548
diff
changeset
|
1884 add_attr_l(&nlm.hdr, sizeof(nlm), IFA_CACHEINFO, |
|
93b4eb29d297
DHCP: Set address vltime and pltime to the length of the lease
Roy Marples <roy@marples.name>
parents:
4548
diff
changeset
|
1885 &cinfo, sizeof(cinfo)); |
|
93b4eb29d297
DHCP: Set address vltime and pltime to the length of the lease
Roy Marples <roy@marples.name>
parents:
4548
diff
changeset
|
1886 } |
|
93b4eb29d297
DHCP: Set address vltime and pltime to the length of the lease
Roy Marples <roy@marples.name>
parents:
4548
diff
changeset
|
1887 |
|
4808
8761aaee4efe
Linux: improve the netlink API more
Roy Marples <roy@marples.name>
parents:
4804
diff
changeset
|
1888 if (if_sendnetlink(ia->iface->ctx, NETLINK_ROUTE, &nlm.hdr, |
|
8761aaee4efe
Linux: improve the netlink API more
Roy Marples <roy@marples.name>
parents:
4804
diff
changeset
|
1889 NULL, NULL) == -1) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1890 retval = -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1891 return retval; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1892 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1893 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1894 int |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1895 if_addrflags(__unused const struct interface *ifp, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1896 __unused const struct in_addr *addr, __unused const char *alias) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1897 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1898 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1899 /* Linux has no support for IPv4 address flags */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1900 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1901 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1902 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1903 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1904 #ifdef INET6 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1905 int |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1906 if_address6(unsigned char cmd, const struct ipv6_addr *ia) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1907 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1908 struct nlma nlm; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1909 struct ifa_cacheinfo cinfo; |
| 4609 | 1910 #if defined(IFA_F_MANAGETEMPADDR) || defined(IFA_F_NOPREFIXROUTE) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1911 uint32_t flags = 0; |
| 4609 | 1912 #endif |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1913 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1914 memset(&nlm, 0, sizeof(nlm)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1915 nlm.hdr.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1916 nlm.hdr.nlmsg_flags = NLM_F_REQUEST; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1917 nlm.hdr.nlmsg_type = cmd; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1918 if (cmd == RTM_NEWADDR) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1919 nlm.hdr.nlmsg_flags |= NLM_F_CREATE | NLM_F_REPLACE; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1920 nlm.ifa.ifa_index = ia->iface->index; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1921 nlm.ifa.ifa_family = AF_INET6; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1922 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1923 /* Add as /128 if no IFA_F_NOPREFIXROUTE ? */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1924 nlm.ifa.ifa_prefixlen = ia->prefix_len; |
|
4555
93b4eb29d297
DHCP: Set address vltime and pltime to the length of the lease
Roy Marples <roy@marples.name>
parents:
4548
diff
changeset
|
1925 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1926 #if 0 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1927 /* This creates the aliased interface */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1928 add_attr_l(&nlm.hdr, sizeof(nlm), IFA_LABEL, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1929 ia->iface->alias, (unsigned short)(strlen(ia->iface->alias) + 1)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1930 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1931 add_attr_l(&nlm.hdr, sizeof(nlm), IFA_LOCAL, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1932 &ia->addr.s6_addr, sizeof(ia->addr.s6_addr)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1933 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1934 if (cmd == RTM_NEWADDR) { |
|
4555
93b4eb29d297
DHCP: Set address vltime and pltime to the length of the lease
Roy Marples <roy@marples.name>
parents:
4548
diff
changeset
|
1935 #ifdef IPV6_MANAGETEMPADDR |
|
93b4eb29d297
DHCP: Set address vltime and pltime to the length of the lease
Roy Marples <roy@marples.name>
parents:
4548
diff
changeset
|
1936 if (ia->flags & IPV6_AF_TEMPORARY) { |
|
93b4eb29d297
DHCP: Set address vltime and pltime to the length of the lease
Roy Marples <roy@marples.name>
parents:
4548
diff
changeset
|
1937 /* Currently the kernel filters out these flags */ |
|
93b4eb29d297
DHCP: Set address vltime and pltime to the length of the lease
Roy Marples <roy@marples.name>
parents:
4548
diff
changeset
|
1938 #ifdef IFA_F_NOPREFIXROUTE |
|
93b4eb29d297
DHCP: Set address vltime and pltime to the length of the lease
Roy Marples <roy@marples.name>
parents:
4548
diff
changeset
|
1939 flags |= IFA_F_TEMPORARY; |
|
93b4eb29d297
DHCP: Set address vltime and pltime to the length of the lease
Roy Marples <roy@marples.name>
parents:
4548
diff
changeset
|
1940 #else |
|
93b4eb29d297
DHCP: Set address vltime and pltime to the length of the lease
Roy Marples <roy@marples.name>
parents:
4548
diff
changeset
|
1941 nlm.ifa.ifa_flags |= IFA_F_TEMPORARY; |
|
93b4eb29d297
DHCP: Set address vltime and pltime to the length of the lease
Roy Marples <roy@marples.name>
parents:
4548
diff
changeset
|
1942 #endif |
|
93b4eb29d297
DHCP: Set address vltime and pltime to the length of the lease
Roy Marples <roy@marples.name>
parents:
4548
diff
changeset
|
1943 } |
|
93b4eb29d297
DHCP: Set address vltime and pltime to the length of the lease
Roy Marples <roy@marples.name>
parents:
4548
diff
changeset
|
1944 #elif IFA_F_MANAGETEMPADDR |
|
4982
661857d82a40
inet6: Check if we can try a new address on DAD failure.
Roy Marples <roy@marples.name>
parents:
4978
diff
changeset
|
1945 if (ia->flags & IPV6_AF_AUTOCONF && IA6_CANAUTOCONF(ia)) |
|
4555
93b4eb29d297
DHCP: Set address vltime and pltime to the length of the lease
Roy Marples <roy@marples.name>
parents:
4548
diff
changeset
|
1946 flags |= IFA_F_MANAGETEMPADDR; |
|
93b4eb29d297
DHCP: Set address vltime and pltime to the length of the lease
Roy Marples <roy@marples.name>
parents:
4548
diff
changeset
|
1947 #endif |
|
93b4eb29d297
DHCP: Set address vltime and pltime to the length of the lease
Roy Marples <roy@marples.name>
parents:
4548
diff
changeset
|
1948 #ifdef IFA_F_NOPREFIXROUTE |
|
93b4eb29d297
DHCP: Set address vltime and pltime to the length of the lease
Roy Marples <roy@marples.name>
parents:
4548
diff
changeset
|
1949 if (!IN6_IS_ADDR_LINKLOCAL(&ia->addr)) |
|
93b4eb29d297
DHCP: Set address vltime and pltime to the length of the lease
Roy Marples <roy@marples.name>
parents:
4548
diff
changeset
|
1950 flags |= IFA_F_NOPREFIXROUTE; |
|
93b4eb29d297
DHCP: Set address vltime and pltime to the length of the lease
Roy Marples <roy@marples.name>
parents:
4548
diff
changeset
|
1951 #endif |
| 4609 | 1952 #if defined(IFA_F_MANAGETEMPADDR) || defined(IFA_F_NOPREFIXROUTE) |
|
4555
93b4eb29d297
DHCP: Set address vltime and pltime to the length of the lease
Roy Marples <roy@marples.name>
parents:
4548
diff
changeset
|
1953 add_attr_32(&nlm.hdr, sizeof(nlm), IFA_FLAGS, flags); |
| 4609 | 1954 #endif |
|
4555
93b4eb29d297
DHCP: Set address vltime and pltime to the length of the lease
Roy Marples <roy@marples.name>
parents:
4548
diff
changeset
|
1955 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1956 memset(&cinfo, 0, sizeof(cinfo)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1957 cinfo.ifa_prefered = ia->prefix_pltime; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1958 cinfo.ifa_valid = ia->prefix_vltime; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1959 add_attr_l(&nlm.hdr, sizeof(nlm), IFA_CACHEINFO, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1960 &cinfo, sizeof(cinfo)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1961 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1962 |
|
4808
8761aaee4efe
Linux: improve the netlink API more
Roy Marples <roy@marples.name>
parents:
4804
diff
changeset
|
1963 return if_sendnetlink(ia->iface->ctx, NETLINK_ROUTE, &nlm.hdr, |
|
8761aaee4efe
Linux: improve the netlink API more
Roy Marples <roy@marples.name>
parents:
4804
diff
changeset
|
1964 NULL, NULL); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1965 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1966 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1967 int |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1968 if_addrflags6(const struct interface *ifp, const struct in6_addr *addr, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1969 __unused const char *alias) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1970 { |
|
5258
f29e384aa13e
privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
1971 char buf[PS_BUFLEN], *bp = buf, *line; |
|
f29e384aa13e
privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
1972 ssize_t buflen; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1973 char *p, ifaddress[33], address[33], name[IF_NAMESIZE + 1]; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1974 unsigned int ifindex; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1975 int prefix, scope, flags, i; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1976 |
|
5258
f29e384aa13e
privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
1977 buflen = dhcp_readfile(ifp->ctx, PROC_INET6, buf, sizeof(buf)); |
|
f29e384aa13e
privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
1978 if (buflen == -1) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1979 return -1; |
|
5258
f29e384aa13e
privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
1980 if ((size_t)buflen == sizeof(buf)) { |
|
f29e384aa13e
privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
1981 errno = ENOBUFS; |
|
f29e384aa13e
privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
1982 return -1; |
|
f29e384aa13e
privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
1983 } |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1984 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1985 p = ifaddress; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1986 for (i = 0; i < (int)sizeof(addr->s6_addr); i++) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1987 p += snprintf(p, 3, "%.2x", addr->s6_addr[i]); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1988 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1989 *p = '\0'; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1990 |
|
5258
f29e384aa13e
privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
1991 while ((line = get_line(&bp, &buflen)) != NULL) { |
|
f29e384aa13e
privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
1992 if (sscanf(line, |
|
f29e384aa13e
privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
1993 "%32[a-f0-9] %x %x %x %x %"TOSTRING(IF_NAMESIZE)"s\n", |
|
f29e384aa13e
privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
1994 address, &ifindex, &prefix, &scope, &flags, name) != 6 || |
|
f29e384aa13e
privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
1995 strlen(address) != 32) |
|
f29e384aa13e
privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
1996 { |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1997 errno = EINVAL; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1998 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1999 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2000 if (strcmp(name, ifp->name) == 0 && |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2001 strcmp(ifaddress, address) == 0) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2002 return flags; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2003 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2004 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2005 errno = ESRCH; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2006 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2007 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2008 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2009 int |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2010 if_getlifetime6(__unused struct ipv6_addr *ia) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2011 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2012 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2013 /* God knows how to work out address lifetimes on Linux */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2014 errno = ENOTSUP; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2015 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2016 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2017 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2018 struct nlml |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2019 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2020 struct nlmsghdr hdr; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2021 struct ifinfomsg i; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2022 char buffer[32]; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2023 }; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2024 |
|
5134
3b4dcb6c284c
linux: Remove warning when HAVE_IN6_ADDR_GEN_MODE_NONE isn't supported
Roy Marples <roy@marples.name>
parents:
5130
diff
changeset
|
2025 #ifdef HAVE_IN6_ADDR_GEN_MODE_NONE |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2026 static struct rtattr * |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2027 add_attr_nest(struct nlmsghdr *n, unsigned short maxlen, unsigned short type) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2028 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2029 struct rtattr *nest; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2030 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2031 nest = NLMSG_TAIL(n); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2032 add_attr_l(n, maxlen, type, NULL, 0); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2033 return nest; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2034 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2035 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2036 static void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2037 add_attr_nest_end(struct nlmsghdr *n, struct rtattr *nest) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2038 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2039 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2040 nest->rta_len = (unsigned short)((char *)NLMSG_TAIL(n) - (char *)nest); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2041 } |
|
5134
3b4dcb6c284c
linux: Remove warning when HAVE_IN6_ADDR_GEN_MODE_NONE isn't supported
Roy Marples <roy@marples.name>
parents:
5130
diff
changeset
|
2042 #endif |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2043 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2044 static int |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2045 if_disable_autolinklocal(struct dhcpcd_ctx *ctx, unsigned int ifindex) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2046 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2047 #ifdef HAVE_IN6_ADDR_GEN_MODE_NONE |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2048 struct nlml nlm; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2049 struct rtattr *afs, *afs6; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2050 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2051 memset(&nlm, 0, sizeof(nlm)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2052 nlm.hdr.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2053 nlm.hdr.nlmsg_type = RTM_NEWLINK; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2054 nlm.hdr.nlmsg_flags = NLM_F_REQUEST; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2055 nlm.i.ifi_family = AF_INET6; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2056 nlm.i.ifi_index = (int)ifindex; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2057 afs = add_attr_nest(&nlm.hdr, sizeof(nlm), IFLA_AF_SPEC); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2058 afs6 = add_attr_nest(&nlm.hdr, sizeof(nlm), AF_INET6); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2059 add_attr_8(&nlm.hdr, sizeof(nlm), IFLA_INET6_ADDR_GEN_MODE, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2060 IN6_ADDR_GEN_MODE_NONE); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2061 add_attr_nest_end(&nlm.hdr, afs6); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2062 add_attr_nest_end(&nlm.hdr, afs); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2063 |
|
4808
8761aaee4efe
Linux: improve the netlink API more
Roy Marples <roy@marples.name>
parents:
4804
diff
changeset
|
2064 return if_sendnetlink(ctx, NETLINK_ROUTE, &nlm.hdr, NULL, NULL); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2065 #else |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2066 UNUSED(ctx); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2067 UNUSED(ifindex); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2068 errno = ENOTSUP; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2069 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2070 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2071 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2072 |
|
4814
409f831b6585
Linux: fix compile for prior
Roy Marples <roy@marples.name>
parents:
4813
diff
changeset
|
2073 static const char *p_conf = "/proc/sys/net/ipv6/conf"; |
|
409f831b6585
Linux: fix compile for prior
Roy Marples <roy@marples.name>
parents:
4813
diff
changeset
|
2074 static const char *p_neigh = "/proc/sys/net/ipv6/neigh"; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2075 |
|
4218
f618f850efdc
inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents:
4197
diff
changeset
|
2076 void |
|
f618f850efdc
inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents:
4197
diff
changeset
|
2077 if_setup_inet6(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
|
2078 { |
|
5258
f29e384aa13e
privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
2079 struct dhcpcd_ctx *ctx = ifp->ctx; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2080 int ra; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2081 char path[256]; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2082 |
|
5384
6d1812f4a3ac
Linux: Sweep errors about disabling autogeneration of LL addrs
Roy Marples <roy@marples.name>
parents:
5383
diff
changeset
|
2083 /* The kernel cannot make stable private addresses. |
|
6d1812f4a3ac
Linux: Sweep errors about disabling autogeneration of LL addrs
Roy Marples <roy@marples.name>
parents:
5383
diff
changeset
|
2084 * However, a lot of distros ship newer kernel headers than |
|
6d1812f4a3ac
Linux: Sweep errors about disabling autogeneration of LL addrs
Roy Marples <roy@marples.name>
parents:
5383
diff
changeset
|
2085 * the kernel itself so sweep that error under the table. */ |
|
6d1812f4a3ac
Linux: Sweep errors about disabling autogeneration of LL addrs
Roy Marples <roy@marples.name>
parents:
5383
diff
changeset
|
2086 if (if_disable_autolinklocal(ctx, ifp->index) == -1 && |
|
6d1812f4a3ac
Linux: Sweep errors about disabling autogeneration of LL addrs
Roy Marples <roy@marples.name>
parents:
5383
diff
changeset
|
2087 errno != ENODEV && errno != ENOTSUP && errno != EINVAL) |
|
4218
f618f850efdc
inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents:
4197
diff
changeset
|
2088 logdebug("%s: if_disable_autolinklocal", ifp->name); |
|
f618f850efdc
inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents:
4197
diff
changeset
|
2089 |
|
f618f850efdc
inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents:
4197
diff
changeset
|
2090 /* |
|
4229
12388193ccdc
inet6: remove references to the crazies.
Roy Marples <roy@marples.name>
parents:
4225
diff
changeset
|
2091 * If not doing autoconf, don't disable the kernel from doing it. |
|
12388193ccdc
inet6: remove references to the crazies.
Roy Marples <roy@marples.name>
parents:
4225
diff
changeset
|
2092 * If we need to, we should have another option actively disable it. |
|
4218
f618f850efdc
inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents:
4197
diff
changeset
|
2093 */ |
|
f618f850efdc
inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents:
4197
diff
changeset
|
2094 if (!(ifp->options->options & DHCPCD_IPV6RS)) |
|
f618f850efdc
inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents:
4197
diff
changeset
|
2095 return; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2096 |
|
4814
409f831b6585
Linux: fix compile for prior
Roy Marples <roy@marples.name>
parents:
4813
diff
changeset
|
2097 snprintf(path, sizeof(path), "%s/%s/autoconf", p_conf, ifp->name); |
|
5258
f29e384aa13e
privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
2098 ra = check_proc_int(ctx, path); |
|
4218
f618f850efdc
inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents:
4197
diff
changeset
|
2099 if (ra != 1 && ra != -1) { |
|
5258
f29e384aa13e
privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
2100 if (if_writepathuint(ctx, path, 0) == -1) |
| 4010 | 2101 logerr("%s: %s", __func__, path); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2102 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2103 |
|
4814
409f831b6585
Linux: fix compile for prior
Roy Marples <roy@marples.name>
parents:
4813
diff
changeset
|
2104 snprintf(path, sizeof(path), "%s/%s/accept_ra", p_conf, ifp->name); |
|
5258
f29e384aa13e
privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
2105 ra = check_proc_int(ctx, path); |
| 4010 | 2106 if (ra == -1) { |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2107 /* The sysctl probably doesn't exist, but this isn't an |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2108 * error as such so just log it and continue */ |
|
5064
7721231839f5
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5051
diff
changeset
|
2109 if (errno != ENOENT) |
|
7721231839f5
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5051
diff
changeset
|
2110 logerr("%s: %s", __func__, path); |
|
4218
f618f850efdc
inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents:
4197
diff
changeset
|
2111 } else if (ra != 0) { |
|
5258
f29e384aa13e
privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
2112 if (if_writepathuint(ctx, path, 0) == -1) |
| 4010 | 2113 logerr("%s: %s", __func__, path); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2114 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2115 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2116 |
|
4813
ef33eb73e97d
INET6: Apply hoplimit, reachable and retrans timer values from RA.
Roy Marples <roy@marples.name>
parents:
4809
diff
changeset
|
2117 int |
|
ef33eb73e97d
INET6: Apply hoplimit, reachable and retrans timer values from RA.
Roy Marples <roy@marples.name>
parents:
4809
diff
changeset
|
2118 if_applyra(const struct ra *rap) |
|
ef33eb73e97d
INET6: Apply hoplimit, reachable and retrans timer values from RA.
Roy Marples <roy@marples.name>
parents:
4809
diff
changeset
|
2119 { |
|
4814
409f831b6585
Linux: fix compile for prior
Roy Marples <roy@marples.name>
parents:
4813
diff
changeset
|
2120 char path[256]; |
|
409f831b6585
Linux: fix compile for prior
Roy Marples <roy@marples.name>
parents:
4813
diff
changeset
|
2121 const char *ifname = rap->iface->name; |
|
4840
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4828
diff
changeset
|
2122 struct dhcpcd_ctx *ctx = rap->iface->ctx; |
|
4813
ef33eb73e97d
INET6: Apply hoplimit, reachable and retrans timer values from RA.
Roy Marples <roy@marples.name>
parents:
4809
diff
changeset
|
2123 int error = 0; |
|
ef33eb73e97d
INET6: Apply hoplimit, reachable and retrans timer values from RA.
Roy Marples <roy@marples.name>
parents:
4809
diff
changeset
|
2124 |
|
5178
fbe055b8e53d
Linux: Only set positive reachable timers
Roy Marples <roy@marples.name>
parents:
5172
diff
changeset
|
2125 if (rap->hoplimit != 0) { |
|
fbe055b8e53d
Linux: Only set positive reachable timers
Roy Marples <roy@marples.name>
parents:
5172
diff
changeset
|
2126 snprintf(path, sizeof(path), "%s/%s/hop_limit", p_conf, ifname); |
|
fbe055b8e53d
Linux: Only set positive reachable timers
Roy Marples <roy@marples.name>
parents:
5172
diff
changeset
|
2127 if (if_writepathuint(ctx, path, rap->hoplimit) == -1) |
|
fbe055b8e53d
Linux: Only set positive reachable timers
Roy Marples <roy@marples.name>
parents:
5172
diff
changeset
|
2128 error = -1; |
|
fbe055b8e53d
Linux: Only set positive reachable timers
Roy Marples <roy@marples.name>
parents:
5172
diff
changeset
|
2129 } |
| 4826 | 2130 |
|
5178
fbe055b8e53d
Linux: Only set positive reachable timers
Roy Marples <roy@marples.name>
parents:
5172
diff
changeset
|
2131 if (rap->retrans != 0) { |
|
fbe055b8e53d
Linux: Only set positive reachable timers
Roy Marples <roy@marples.name>
parents:
5172
diff
changeset
|
2132 snprintf(path, sizeof(path), "%s/%s/retrans_time_ms", |
|
fbe055b8e53d
Linux: Only set positive reachable timers
Roy Marples <roy@marples.name>
parents:
5172
diff
changeset
|
2133 p_neigh, ifname); |
|
fbe055b8e53d
Linux: Only set positive reachable timers
Roy Marples <roy@marples.name>
parents:
5172
diff
changeset
|
2134 if (if_writepathuint(ctx, path, rap->retrans) == -1) |
|
fbe055b8e53d
Linux: Only set positive reachable timers
Roy Marples <roy@marples.name>
parents:
5172
diff
changeset
|
2135 error = -1; |
|
fbe055b8e53d
Linux: Only set positive reachable timers
Roy Marples <roy@marples.name>
parents:
5172
diff
changeset
|
2136 } |
| 4826 | 2137 |
|
5178
fbe055b8e53d
Linux: Only set positive reachable timers
Roy Marples <roy@marples.name>
parents:
5172
diff
changeset
|
2138 if (rap->reachable != 0) { |
|
fbe055b8e53d
Linux: Only set positive reachable timers
Roy Marples <roy@marples.name>
parents:
5172
diff
changeset
|
2139 snprintf(path, sizeof(path), "%s/%s/base_reachable_time_ms", |
|
fbe055b8e53d
Linux: Only set positive reachable timers
Roy Marples <roy@marples.name>
parents:
5172
diff
changeset
|
2140 p_neigh, ifname); |
|
fbe055b8e53d
Linux: Only set positive reachable timers
Roy Marples <roy@marples.name>
parents:
5172
diff
changeset
|
2141 if (if_writepathuint(ctx, path, rap->reachable) == -1) |
|
fbe055b8e53d
Linux: Only set positive reachable timers
Roy Marples <roy@marples.name>
parents:
5172
diff
changeset
|
2142 error = -1; |
|
fbe055b8e53d
Linux: Only set positive reachable timers
Roy Marples <roy@marples.name>
parents:
5172
diff
changeset
|
2143 } |
|
4916
7513775ead91
inet6: Adjust prior so that we don't support old kernels
Roy Marples <roy@marples.name>
parents:
4914
diff
changeset
|
2144 |
|
4813
ef33eb73e97d
INET6: Apply hoplimit, reachable and retrans timer values from RA.
Roy Marples <roy@marples.name>
parents:
4809
diff
changeset
|
2145 return error; |
|
ef33eb73e97d
INET6: Apply hoplimit, reachable and retrans timer values from RA.
Roy Marples <roy@marples.name>
parents:
4809
diff
changeset
|
2146 } |
|
ef33eb73e97d
INET6: Apply hoplimit, reachable and retrans timer values from RA.
Roy Marples <roy@marples.name>
parents:
4809
diff
changeset
|
2147 |
|
4335
d0519e1f2f5f
ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents:
4333
diff
changeset
|
2148 int |
|
d0519e1f2f5f
ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents:
4333
diff
changeset
|
2149 ip6_forwarding(const char *ifname) |
|
d0519e1f2f5f
ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents:
4333
diff
changeset
|
2150 { |
|
5258
f29e384aa13e
privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
2151 char path[256], buf[64]; |
|
f29e384aa13e
privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
2152 int error, i; |
|
4335
d0519e1f2f5f
ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents:
4333
diff
changeset
|
2153 |
|
d0519e1f2f5f
ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents:
4333
diff
changeset
|
2154 if (ifname == NULL) |
|
d0519e1f2f5f
ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents:
4333
diff
changeset
|
2155 ifname = "all"; |
|
4814
409f831b6585
Linux: fix compile for prior
Roy Marples <roy@marples.name>
parents:
4813
diff
changeset
|
2156 snprintf(path, sizeof(path), "%s/%s/forwarding", p_conf, ifname); |
|
5258
f29e384aa13e
privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
2157 if (readfile(path, buf, sizeof(buf)) == -1) |
|
f29e384aa13e
privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
2158 return 0; |
|
f29e384aa13e
privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
2159 i = (int)strtoi(buf, NULL, 0, INT_MIN, INT_MAX, &error); |
|
5414
bf786eeda3fc
Linux: fix reading the ipv6 forwarding proc entry
Roy Marples <roy@marples.name>
parents:
5388
diff
changeset
|
2160 if (error != 0 && error != ENOTSUP) |
| 5281 | 2161 return 0; |
| 2162 return i; | |
|
4335
d0519e1f2f5f
ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents:
4333
diff
changeset
|
2163 } |
|
d0519e1f2f5f
ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents:
4333
diff
changeset
|
2164 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2165 #endif /* INET6 */ |
