Mercurial > hg > dhcpcd
annotate src/if-linux.c @ 5534:605f7f9a20c0 draft
fix if_getnetworknamespace matching bug. (#19)
Co-authored-by: Ted Feng <Ted.Feng@Aviatnet.com>
| author | Ted Feng <artisdom@gmail.com> |
|---|---|
| date | Wed, 04 Nov 2020 11:31:40 +1300 |
| parents | 8f117781bb06 |
| children | e65d193a1960 |
| 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 |
|
4840
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4828
diff
changeset
|
518 int |
|
4808
8761aaee4efe
Linux: improve the netlink API more
Roy Marples <roy@marples.name>
parents:
4804
diff
changeset
|
519 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
|
520 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
|
521 { |
|
4371
a7f3d85f54ce
Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents:
4366
diff
changeset
|
522 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
|
523 struct msghdr msg = { |
|
a7f3d85f54ce
Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents:
4366
diff
changeset
|
524 .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
|
525 .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
|
526 }; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
527 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
|
528 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
|
529 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
|
530 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
|
531 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
|
532 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
533 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
|
534 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
|
535 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
|
536 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
|
537 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
538 /* Check sender */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
539 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
|
540 errno = EINVAL; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
541 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
542 } |
|
5386
b28b0962bfe2
Linux: keep the generic netlink socket around to get ssid with privsep
Roy Marples <roy@marples.name>
parents:
5384
diff
changeset
|
543 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
544 /* 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
|
545 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
|
546 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
547 |
|
4781
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
548 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
|
549 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
|
550 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
|
551 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
|
552 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
|
553 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
554 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
|
555 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
|
556 continue; |
|
5386
b28b0962bfe2
Linux: keep the generic netlink socket around to get ssid with privsep
Roy Marples <roy@marples.name>
parents:
5384
diff
changeset
|
557 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
558 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
|
559 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
|
560 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
561 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
|
562 errno = EBADMSG; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
563 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
564 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
565 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
|
566 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
|
567 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
|
568 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
569 } |
|
5386
b28b0962bfe2
Linux: keep the generic netlink socket around to get ssid with privsep
Roy Marples <roy@marples.name>
parents:
5384
diff
changeset
|
570 again = 0; |
|
b28b0962bfe2
Linux: keep the generic netlink socket around to get ssid with privsep
Roy Marples <roy@marples.name>
parents:
5384
diff
changeset
|
571 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
|
572 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
573 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
574 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
|
575 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
|
576 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
|
577 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
578 } |
|
5387
08cbef5c8e9e
Linux: Warn if netlink(7) seq number doesn't match expectation.
Roy Marples <roy@marples.name>
parents:
5386
diff
changeset
|
579 if (cb == NULL) |
|
08cbef5c8e9e
Linux: Warn if netlink(7) seq number doesn't match expectation.
Roy Marples <roy@marples.name>
parents:
5386
diff
changeset
|
580 continue; |
|
08cbef5c8e9e
Linux: Warn if netlink(7) seq number doesn't match expectation.
Roy Marples <roy@marples.name>
parents:
5386
diff
changeset
|
581 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
|
582 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
|
583 __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
|
584 else |
|
5386
b28b0962bfe2
Linux: keep the generic netlink socket around to get ssid with privsep
Roy Marples <roy@marples.name>
parents:
5384
diff
changeset
|
585 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
|
586 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
587 |
|
5386
b28b0962bfe2
Linux: keep the generic netlink socket around to get ssid with privsep
Roy Marples <roy@marples.name>
parents:
5384
diff
changeset
|
588 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
|
589 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
|
590 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
591 return r; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
592 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
593 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
594 static int |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
595 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
|
596 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
597 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
|
598 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
|
599 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
|
600 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
|
601 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
|
602 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
603 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
|
604 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
|
605 errno = EBADMSG; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
606 return -1; |
|
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 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
|
609 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
|
610 return -1; |
|
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 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
|
613 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
|
614 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
|
615 |
|
4884
1378ef92e8bc
Linux: remove some casts no longer needed
Roy Marples <roy@marples.name>
parents:
4840
diff
changeset
|
616 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
|
617 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
|
618 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
|
619 sa = NULL; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
620 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
|
621 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
|
622 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
|
623 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
624 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
|
625 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
|
626 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
627 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
|
628 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
|
629 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
630 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
|
631 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
|
632 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
|
633 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
634 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
|
635 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
|
636 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
637 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
|
638 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
639 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
|
640 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
|
641 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
642 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
|
643 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
|
644 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
|
645 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
|
646 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
|
647 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
|
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 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
650 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
651 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
652 } |
|
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 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
655 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
|
656 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
|
657 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
658 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
|
659 salen = sa_addrlen(sa); |
|
4572
e438211a2b44
Linux: Work around a coverity issue
Roy Marples <roy@marples.name>
parents:
4569
diff
changeset
|
660 /* 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
|
661 /* 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
|
662 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
|
663 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
|
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 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
667 /* 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
|
668 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
|
669 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
|
670 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
671 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
|
672 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
|
673 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
|
674 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
|
675 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
676 #if 0 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
677 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
|
678 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
|
679 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
680 /* 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
|
681 * 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
|
682 * 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
|
683 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
|
684 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
|
685 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
686 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
687 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
688 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
|
689 errno = ESRCH; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
690 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
691 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
692 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
693 } |
|
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 static int |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
696 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
|
697 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
|
698 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
699 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
|
700 int cmd; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
701 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
|
702 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
|
703 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
704 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
|
705 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
|
706 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
|
707 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
708 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
|
709 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
|
710 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
711 default: |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
712 return 0; |
|
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 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
715 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
|
716 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
|
717 errno = EBADMSG; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
718 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
719 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
720 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
721 /* 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
|
722 #ifdef PRIVSEP |
|
64b25cbb621f
Linux: Use the persistent route socket for writing netlink msgs
Roy Marples <roy@marples.name>
parents:
4962
diff
changeset
|
723 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
|
724 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
|
725 return 0; |
|
64b25cbb621f
Linux: Use the persistent route socket for writing netlink msgs
Roy Marples <roy@marples.name>
parents:
4962
diff
changeset
|
726 #endif |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
727 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
|
728 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
|
729 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
730 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
731 if (if_copyrt(ctx, &rt, nlm) == 0) |
|
4421
1c0d24d49b16
route: log which pid deletes routes
Roy Marples <roy@marples.name>
parents:
4371
diff
changeset
|
732 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
|
733 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
734 return 0; |
|
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 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
737 static int |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
738 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
|
739 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
740 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
|
741 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
|
742 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
|
743 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
|
744 #ifdef INET |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
745 struct in_addr addr, net, brd; |
|
5533
8f117781bb06
Linux: Fix detecting existing IPv4 addresses
Roy Marples <roy@marples.name>
parents:
5486
diff
changeset
|
746 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
|
747 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
748 #ifdef INET6 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
749 struct in6_addr addr6; |
|
4779
66684c1c08bd
Linux: Validate RTM_DELADDR/RTM_NEWADDR messages for IPv6
Roy Marples <roy@marples.name>
parents:
4778
diff
changeset
|
750 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
|
751 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
752 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
753 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
|
754 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
755 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
756 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
|
757 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
|
758 errno = EBADMSG; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
759 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
760 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
761 |
|
4985
d9cb0a6245a4
Only ignore address messages from ourself for deletion.
Roy Marples <roy@marples.name>
parents:
4982
diff
changeset
|
762 /* Ignore address deletions from ourself. |
|
d9cb0a6245a4
Only ignore address messages from ourself for deletion.
Roy Marples <roy@marples.name>
parents:
4982
diff
changeset
|
763 * 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
|
764 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
|
765 #ifdef PRIVSEP |
|
4985
d9cb0a6245a4
Only ignore address messages from ourself for deletion.
Roy Marples <roy@marples.name>
parents:
4982
diff
changeset
|
766 if (ctx->ps_root_pid != 0 && |
|
d9cb0a6245a4
Only ignore address messages from ourself for deletion.
Roy Marples <roy@marples.name>
parents:
4982
diff
changeset
|
767 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
|
768 return 0; |
|
4970
64b25cbb621f
Linux: Use the persistent route socket for writing netlink msgs
Roy Marples <roy@marples.name>
parents:
4962
diff
changeset
|
769 #endif |
|
4985
d9cb0a6245a4
Only ignore address messages from ourself for deletion.
Roy Marples <roy@marples.name>
parents:
4982
diff
changeset
|
770 priv = (struct priv*)ctx->priv; |
|
d9cb0a6245a4
Only ignore address messages from ourself for deletion.
Roy Marples <roy@marples.name>
parents:
4982
diff
changeset
|
771 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
|
772 return 0; |
|
d9cb0a6245a4
Only ignore address messages from ourself for deletion.
Roy Marples <roy@marples.name>
parents:
4982
diff
changeset
|
773 } |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
774 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
775 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
|
776 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
|
777 /* 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
|
778 * 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
|
779 return 1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
780 } |
|
4884
1378ef92e8bc
Linux: remove some casts no longer needed
Roy Marples <roy@marples.name>
parents:
4840
diff
changeset
|
781 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
|
782 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
|
783 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
|
784 #ifdef INET |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
785 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
|
786 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
|
787 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
|
788 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
|
789 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
|
790 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
|
791 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
|
792 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
|
793 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
|
794 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
795 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
796 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
|
797 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
|
798 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
|
799 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
800 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
|
801 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
|
802 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
|
803 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
804 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
805 } |
|
4779
66684c1c08bd
Linux: Validate RTM_DELADDR/RTM_NEWADDR messages for IPv6
Roy Marples <roy@marples.name>
parents:
4778
diff
changeset
|
806 |
|
4781
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
807 /* 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
|
808 * and anything else really means address exists. */ |
|
5533
8f117781bb06
Linux: Fix detecting existing IPv4 addresses
Roy Marples <roy@marples.name>
parents:
5486
diff
changeset
|
809 ret = if_addressexists(ifp, &addr); |
|
8f117781bb06
Linux: Fix detecting existing IPv4 addresses
Roy Marples <roy@marples.name>
parents:
5486
diff
changeset
|
810 if (ret == -1) { |
|
8f117781bb06
Linux: Fix detecting existing IPv4 addresses
Roy Marples <roy@marples.name>
parents:
5486
diff
changeset
|
811 logerr("if_addressexists: %s", inet_ntoa(addr)); |
|
8f117781bb06
Linux: Fix detecting existing IPv4 addresses
Roy Marples <roy@marples.name>
parents:
5486
diff
changeset
|
812 break; |
|
8f117781bb06
Linux: Fix detecting existing IPv4 addresses
Roy Marples <roy@marples.name>
parents:
5486
diff
changeset
|
813 } 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
|
814 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
|
815 break; |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
816 } else { |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
817 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
|
818 break; |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
819 } |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
820 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
821 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
|
822 &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
|
823 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
824 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
825 #ifdef INET6 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
826 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
|
827 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
|
828 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
|
829 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
|
830 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
|
831 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
|
832 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
|
833 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
834 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
835 } |
|
4779
66684c1c08bd
Linux: Validate RTM_DELADDR/RTM_NEWADDR messages for IPv6
Roy Marples <roy@marples.name>
parents:
4778
diff
changeset
|
836 |
|
66684c1c08bd
Linux: Validate RTM_DELADDR/RTM_NEWADDR messages for IPv6
Roy Marples <roy@marples.name>
parents:
4778
diff
changeset
|
837 /* 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
|
838 * 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
|
839 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
|
840 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
|
841 if (flags != -1) |
|
66684c1c08bd
Linux: Validate RTM_DELADDR/RTM_NEWADDR messages for IPv6
Roy Marples <roy@marples.name>
parents:
4778
diff
changeset
|
842 break; |
|
66684c1c08bd
Linux: Validate RTM_DELADDR/RTM_NEWADDR messages for IPv6
Roy Marples <roy@marples.name>
parents:
4778
diff
changeset
|
843 } else { |
|
66684c1c08bd
Linux: Validate RTM_DELADDR/RTM_NEWADDR messages for IPv6
Roy Marples <roy@marples.name>
parents:
4778
diff
changeset
|
844 if (flags == -1) |
|
66684c1c08bd
Linux: Validate RTM_DELADDR/RTM_NEWADDR messages for IPv6
Roy Marples <roy@marples.name>
parents:
4778
diff
changeset
|
845 break; |
|
66684c1c08bd
Linux: Validate RTM_DELADDR/RTM_NEWADDR messages for IPv6
Roy Marples <roy@marples.name>
parents:
4778
diff
changeset
|
846 } |
|
66684c1c08bd
Linux: Validate RTM_DELADDR/RTM_NEWADDR messages for IPv6
Roy Marples <roy@marples.name>
parents:
4778
diff
changeset
|
847 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
848 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
|
849 &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
|
850 (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
|
851 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
852 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
853 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
854 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
855 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
856 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
857 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
|
858 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
|
859 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
860 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
861 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
|
862 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
|
863 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
|
864 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
|
865 return 6; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
866 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
|
867 return 8; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
868 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
|
869 return 20; |
|
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 /* Impossible */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
873 return 0; |
|
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 #ifdef INET6 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
877 static int |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
878 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
|
879 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
|
880 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
881 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
|
882 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
|
883 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
|
884 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
885 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
|
886 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
887 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
|
888 return -1; |
|
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 r = NLMSG_DATA(nlm); |
|
4884
1378ef92e8bc
Linux: remove some casts no longer needed
Roy Marples <roy@marples.name>
parents:
4840
diff
changeset
|
891 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
|
892 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
|
893 if (r->ndm_family == AF_INET6) { |
|
5115
bc8b0d0c68af
Linux: improve IPv6 router reachability
Roy Marples <roy@marples.name>
parents:
5064
diff
changeset
|
894 bool unreachable; |
|
4669
ec9d26e0de41
inet6: Stop reacting to kernel neighbour messages about a router
Roy Marples <roy@marples.name>
parents:
4636
diff
changeset
|
895 struct in6_addr addr6; |
|
ec9d26e0de41
inet6: Stop reacting to kernel neighbour messages about a router
Roy Marples <roy@marples.name>
parents:
4636
diff
changeset
|
896 |
|
5115
bc8b0d0c68af
Linux: improve IPv6 router reachability
Roy Marples <roy@marples.name>
parents:
5064
diff
changeset
|
897 unreachable = (nlm->nlmsg_type == RTM_NEWNEIGH && |
|
bc8b0d0c68af
Linux: improve IPv6 router reachability
Roy Marples <roy@marples.name>
parents:
5064
diff
changeset
|
898 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
|
899 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
|
900 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
|
901 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
|
902 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
|
903 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
|
904 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
|
905 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
906 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
907 } |
|
5115
bc8b0d0c68af
Linux: improve IPv6 router reachability
Roy Marples <roy@marples.name>
parents:
5064
diff
changeset
|
908 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
|
909 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
910 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
911 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
912 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
913 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
914 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
915 static int |
|
4521
9a0884e8ab97
linux: use correct prototype
Roy Marples <roy@marples.name>
parents:
4511
diff
changeset
|
916 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
|
917 { |
|
4521
9a0884e8ab97
linux: use correct prototype
Roy Marples <roy@marples.name>
parents:
4511
diff
changeset
|
918 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
|
919 int r; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
920 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
|
921 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
|
922 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
|
923 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
|
924 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
925 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
|
926 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
|
927 return r; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
928 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
|
929 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
|
930 return r; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
931 #ifdef INET6 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
932 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
|
933 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
|
934 return r; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
935 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
936 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
937 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
|
938 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
939 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
|
940 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
|
941 errno = EBADMSG; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
942 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
943 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
944 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
|
945 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
|
946 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
947 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
|
948 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
|
949 *ifn = '\0'; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
950 hwaddr = NULL; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
951 |
|
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
|
952 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
|
953 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
|
954 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
|
955 /* 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
|
956 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
|
957 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
|
958 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
959 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
960 case IFLA_IFNAME: |
|
4015
6aa00a675750
Cast away a coverity issue.
Roy Marples <roy@marples.name>
parents:
4010
diff
changeset
|
961 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
|
962 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
963 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
|
964 hwaddr = rta; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
965 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
966 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
967 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
968 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
969 if (nlm->nlmsg_type == RTM_DELLINK) { |
|
5285
7754eb6cd2eb
Linux: File compile without plugins
Julian Wollrath <julian@haerkules.de>
parents:
5282
diff
changeset
|
970 #ifdef PLUGIN_DEV |
|
4257
29971caaafc9
Linux: If listening to dev manager, let it remove interfaces
Roy Marples <roy@marples.name>
parents:
4255
diff
changeset
|
971 /* 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
|
972 * 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
|
973 if (dev_listening(ctx) < 1) |
|
5285
7754eb6cd2eb
Linux: File compile without plugins
Julian Wollrath <julian@haerkules.de>
parents:
5282
diff
changeset
|
974 #endif |
|
4257
29971caaafc9
Linux: If listening to dev manager, let it remove interfaces
Roy Marples <roy@marples.name>
parents:
4255
diff
changeset
|
975 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
|
976 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
977 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
978 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
979 /* 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
|
980 * 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
|
981 * 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
|
982 * 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
|
983 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
|
984 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
|
985 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
986 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
987 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
988 /* Check for a new interface */ |
|
4255
8524a8375483
Linux: Improve interface renaming
Roy Marples <roy@marples.name>
parents:
4232
diff
changeset
|
989 ifp = if_findindex(ctx->ifaces, (unsigned int)ifi->ifi_index); |
|
8524a8375483
Linux: Improve interface renaming
Roy Marples <roy@marples.name>
parents:
4232
diff
changeset
|
990 if (ifp == NULL) { |
|
5285
7754eb6cd2eb
Linux: File compile without plugins
Julian Wollrath <julian@haerkules.de>
parents:
5282
diff
changeset
|
991 #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
|
992 /* 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
|
993 * 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
|
994 if (dev_listening(ctx) < 1) |
|
5285
7754eb6cd2eb
Linux: File compile without plugins
Julian Wollrath <julian@haerkules.de>
parents:
5282
diff
changeset
|
995 #endif |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
996 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
|
997 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
998 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
999 |
|
4255
8524a8375483
Linux: Improve interface renaming
Roy Marples <roy@marples.name>
parents:
4232
diff
changeset
|
1000 /* Handle interface being renamed */ |
|
8524a8375483
Linux: Improve interface renaming
Roy Marples <roy@marples.name>
parents:
4232
diff
changeset
|
1001 if (strcmp(ifp->name, ifn) != 0) { |
|
8524a8375483
Linux: Improve interface renaming
Roy Marples <roy@marples.name>
parents:
4232
diff
changeset
|
1002 dhcpcd_handleinterface(ctx, -1, ifn); |
|
8524a8375483
Linux: Improve interface renaming
Roy Marples <roy@marples.name>
parents:
4232
diff
changeset
|
1003 dhcpcd_handleinterface(ctx, 1, ifn); |
|
8524a8375483
Linux: Improve interface renaming
Roy Marples <roy@marples.name>
parents:
4232
diff
changeset
|
1004 return 0; |
|
8524a8375483
Linux: Improve interface renaming
Roy Marples <roy@marples.name>
parents:
4232
diff
changeset
|
1005 } |
|
8524a8375483
Linux: Improve interface renaming
Roy Marples <roy@marples.name>
parents:
4232
diff
changeset
|
1006 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1007 /* 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
|
1008 if (!(ifi->ifi_flags & IFF_UP)) { |
|
1f5dc6102f9b
if: support changing hardware address type on Linux
Roy Marples <roy@marples.name>
parents:
5166
diff
changeset
|
1009 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
|
1010 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
|
1011 |
|
5168
1f5dc6102f9b
if: support changing hardware address type on Linux
Roy Marples <roy@marples.name>
parents:
5166
diff
changeset
|
1012 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
|
1013 hwa = NULL; |
|
1f5dc6102f9b
if: support changing hardware address type on Linux
Roy Marples <roy@marples.name>
parents:
5166
diff
changeset
|
1014 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
|
1015 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1016 |
|
5486
8e2b8ce8c972
BSD: struct if_data->ifi_link_state is the single source of truth
Roy Marples <roy@marples.name>
parents:
5475
diff
changeset
|
1017 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
|
1018 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
|
1019 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
|
1020 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1021 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1022 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1023 int |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1024 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
|
1025 { |
|
4371
a7f3d85f54ce
Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents:
4366
diff
changeset
|
1026 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
|
1027 struct iovec iov = { |
|
a7f3d85f54ce
Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents:
4366
diff
changeset
|
1028 .iov_base = buf, |
|
a7f3d85f54ce
Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents:
4366
diff
changeset
|
1029 .iov_len = sizeof(buf), |
|
a7f3d85f54ce
Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents:
4366
diff
changeset
|
1030 }; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1031 |
|
4808
8761aaee4efe
Linux: improve the netlink API more
Roy Marples <roy@marples.name>
parents:
4804
diff
changeset
|
1032 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
|
1033 &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
|
1034 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1035 |
|
4944
572ef46ecde3
Linux: clean up some compile warnings without privsep
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
1036 #ifdef PRIVSEP |
|
4840
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4828
diff
changeset
|
1037 static bool |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4828
diff
changeset
|
1038 if_netlinkpriv(int protocol, struct nlmsghdr *nlm) |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4828
diff
changeset
|
1039 { |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4828
diff
changeset
|
1040 |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4828
diff
changeset
|
1041 if (protocol != NETLINK_ROUTE) |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4828
diff
changeset
|
1042 return false; |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4828
diff
changeset
|
1043 |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4828
diff
changeset
|
1044 switch(nlm->nlmsg_type) { |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4828
diff
changeset
|
1045 case RTM_NEWADDR: /* FALLTHROUGH */ |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4828
diff
changeset
|
1046 case RTM_DELADDR: /* FALLTHROUGH */ |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4828
diff
changeset
|
1047 case RTM_NEWROUTE: /* FALLTHROUGH */ |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4828
diff
changeset
|
1048 case RTM_DELROUTE: /* FALLTHROUGH */ |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4828
diff
changeset
|
1049 case RTM_NEWLINK: |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4828
diff
changeset
|
1050 return true; |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4828
diff
changeset
|
1051 default: |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4828
diff
changeset
|
1052 return false; |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4828
diff
changeset
|
1053 } |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4828
diff
changeset
|
1054 } |
|
4944
572ef46ecde3
Linux: clean up some compile warnings without privsep
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
1055 #endif |
|
4840
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4828
diff
changeset
|
1056 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1057 static int |
|
4808
8761aaee4efe
Linux: improve the netlink API more
Roy Marples <roy@marples.name>
parents:
4804
diff
changeset
|
1058 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
|
1059 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
|
1060 { |
|
5386
b28b0962bfe2
Linux: keep the generic netlink socket around to get ssid with privsep
Roy Marples <roy@marples.name>
parents:
5384
diff
changeset
|
1061 int s; |
|
4371
a7f3d85f54ce
Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents:
4366
diff
changeset
|
1062 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
|
1063 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
|
1064 struct msghdr msg = { |
|
a7f3d85f54ce
Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents:
4366
diff
changeset
|
1065 .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
|
1066 .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
|
1067 }; |
|
5386
b28b0962bfe2
Linux: keep the generic netlink socket around to get ssid with privsep
Roy Marples <roy@marples.name>
parents:
5384
diff
changeset
|
1068 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
|
1069 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
|
1070 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
|
1071 .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
|
1072 .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
|
1073 }; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1074 |
|
4840
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4828
diff
changeset
|
1075 /* Request a reply */ |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4828
diff
changeset
|
1076 hdr->nlmsg_flags |= NLM_F_ACK; |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4828
diff
changeset
|
1077 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
|
1078 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
|
1079 ctx->seq = 0; |
|
4840
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4828
diff
changeset
|
1080 |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4828
diff
changeset
|
1081 #ifdef PRIVSEP |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4828
diff
changeset
|
1082 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
|
1083 return (int)ps_root_sendnetlink(ctx, protocol, &msg); |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4828
diff
changeset
|
1084 #endif |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4828
diff
changeset
|
1085 |
|
5386
b28b0962bfe2
Linux: keep the generic netlink socket around to get ssid with privsep
Roy Marples <roy@marples.name>
parents:
5384
diff
changeset
|
1086 switch (protocol) { |
|
b28b0962bfe2
Linux: keep the generic netlink socket around to get ssid with privsep
Roy Marples <roy@marples.name>
parents:
5384
diff
changeset
|
1087 case NETLINK_ROUTE: |
|
5533
8f117781bb06
Linux: Fix detecting existing IPv4 addresses
Roy Marples <roy@marples.name>
parents:
5486
diff
changeset
|
1088 s = priv->route_fd; |
|
8f117781bb06
Linux: Fix detecting existing IPv4 addresses
Roy Marples <roy@marples.name>
parents:
5486
diff
changeset
|
1089 break; |
|
5386
b28b0962bfe2
Linux: keep the generic netlink socket around to get ssid with privsep
Roy Marples <roy@marples.name>
parents:
5384
diff
changeset
|
1090 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
|
1091 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
|
1092 #if 0 |
|
4781
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1093 #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
|
1094 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
|
1095 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
|
1096 |
|
4970
64b25cbb621f
Linux: Use the persistent route socket for writing netlink msgs
Roy Marples <roy@marples.name>
parents:
4962
diff
changeset
|
1097 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
|
1098 &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
|
1099 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
|
1100 } |
|
64b25cbb621f
Linux: Use the persistent route socket for writing netlink msgs
Roy Marples <roy@marples.name>
parents:
4962
diff
changeset
|
1101 #endif |
|
5386
b28b0962bfe2
Linux: keep the generic netlink socket around to get ssid with privsep
Roy Marples <roy@marples.name>
parents:
5384
diff
changeset
|
1102 #endif |
|
b28b0962bfe2
Linux: keep the generic netlink socket around to get ssid with privsep
Roy Marples <roy@marples.name>
parents:
5384
diff
changeset
|
1103 break; |
|
b28b0962bfe2
Linux: keep the generic netlink socket around to get ssid with privsep
Roy Marples <roy@marples.name>
parents:
5384
diff
changeset
|
1104 default: |
|
b28b0962bfe2
Linux: keep the generic netlink socket around to get ssid with privsep
Roy Marples <roy@marples.name>
parents:
5384
diff
changeset
|
1105 errno = EINVAL; |
|
b28b0962bfe2
Linux: keep the generic netlink socket around to get ssid with privsep
Roy Marples <roy@marples.name>
parents:
5384
diff
changeset
|
1106 return -1; |
|
4804
4b8a5e58ffcc
Linux: always open a netlink socket when writing netlink messages
Roy Marples <roy@marples.name>
parents:
4781
diff
changeset
|
1107 } |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1108 |
|
5386
b28b0962bfe2
Linux: keep the generic netlink socket around to get ssid with privsep
Roy Marples <roy@marples.name>
parents:
5384
diff
changeset
|
1109 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
|
1110 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
|
1111 |
|
5386
b28b0962bfe2
Linux: keep the generic netlink socket around to get ssid with privsep
Roy Marples <roy@marples.name>
parents:
5384
diff
changeset
|
1112 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
|
1113 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1114 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1115 #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
|
1116 ((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
|
1117 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1118 static int |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1119 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
|
1120 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
|
1121 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1122 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
|
1123 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
|
1124 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1125 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
|
1126 errno = ENOBUFS; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1127 return -1; |
|
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 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
|
1131 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
|
1132 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
|
1133 if (alen) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1134 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
|
1135 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
|
1136 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1137 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1138 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1139 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1140 static int |
|
5130
d34c808ae81e
Linux: Note router preference when adding routes
Roy Marples <roy@marples.name>
parents:
5115
diff
changeset
|
1141 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
|
1142 uint8_t data) |
|
d34c808ae81e
Linux: Note router preference when adding routes
Roy Marples <roy@marples.name>
parents:
5115
diff
changeset
|
1143 { |
|
d34c808ae81e
Linux: Note router preference when adding routes
Roy Marples <roy@marples.name>
parents:
5115
diff
changeset
|
1144 |
|
d34c808ae81e
Linux: Note router preference when adding routes
Roy Marples <roy@marples.name>
parents:
5115
diff
changeset
|
1145 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
|
1146 } |
|
d34c808ae81e
Linux: Note router preference when adding routes
Roy Marples <roy@marples.name>
parents:
5115
diff
changeset
|
1147 |
|
d34c808ae81e
Linux: Note router preference when adding routes
Roy Marples <roy@marples.name>
parents:
5115
diff
changeset
|
1148 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
|
1149 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
|
1150 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
|
1151 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1152 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
|
1153 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
|
1154 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1155 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
|
1156 errno = ENOBUFS; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1157 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1158 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1159 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1160 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
|
1161 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
|
1162 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
|
1163 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
|
1164 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
|
1165 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1166 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1167 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1168 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1169 static int |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1170 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
|
1171 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
|
1172 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1173 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
|
1174 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
|
1175 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1176 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
|
1177 errno = ENOBUFS; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1178 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1179 } |
|
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 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
|
1182 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
|
1183 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
|
1184 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
|
1185 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
|
1186 return 0; |
|
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 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1189 #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
|
1190 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
|
1191 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
|
1192 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1193 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1194 *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
|
1195 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
|
1196 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1197 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1198 #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
|
1199 #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
|
1200 #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
|
1201 ((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
|
1202 (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
|
1203 (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
|
1204 #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
|
1205 #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
|
1206 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
|
1207 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
|
1208 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
|
1209 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1210 struct nlmg |
|
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 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
|
1213 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
|
1214 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
|
1215 }; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1216 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1217 static int |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1218 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
|
1219 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
|
1220 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1221 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
|
1222 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
|
1223 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1224 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
|
1225 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
|
1226 errno = ENOBUFS; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1227 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1228 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1229 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1230 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
|
1231 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
|
1232 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
|
1233 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
|
1234 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
|
1235 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1236 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1237 } |
|
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 static int |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1240 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
|
1241 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
|
1242 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1243 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
|
1244 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
|
1245 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1246 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
|
1247 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
|
1248 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
|
1249 errno = ENOBUFS; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1250 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1251 } |
|
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 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
|
1254 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
|
1255 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
|
1256 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
|
1257 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
|
1258 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1259 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1260 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1261 static int |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1262 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
|
1263 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1264 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
|
1265 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
|
1266 int type; |
|
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 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
|
1269 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
|
1270 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
|
1271 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
|
1272 continue; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1273 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
|
1274 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1275 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1276 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1277 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1278 static int |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1279 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
|
1280 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1281 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
|
1282 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
|
1283 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
|
1284 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1285 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
|
1286 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
|
1287 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
|
1288 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
|
1289 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1290 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1291 static int |
|
4400
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4371
diff
changeset
|
1292 _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
|
1293 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
|
1294 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1295 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
|
1296 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
|
1297 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1298 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
|
1299 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1300 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
|
1301 errno = ENOENT; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1302 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1303 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1304 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
|
1305 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
|
1306 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1307 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1308 static int |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1309 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
|
1310 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1311 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
|
1312 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1313 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
|
1314 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
|
1315 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
|
1316 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
|
1317 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
|
1318 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
|
1319 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
|
1320 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
|
1321 return -1; |
|
4808
8761aaee4efe
Linux: improve the netlink API more
Roy Marples <roy@marples.name>
parents:
4804
diff
changeset
|
1322 return if_sendnetlink(ctx, NETLINK_GENERIC, &nlm.hdr, |
|
8761aaee4efe
Linux: improve the netlink API more
Roy Marples <roy@marples.name>
parents:
4804
diff
changeset
|
1323 &_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
|
1324 } |
|
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 static int |
|
4400
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4371
diff
changeset
|
1327 _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
|
1328 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
|
1329 { |
|
4400
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4371
diff
changeset
|
1330 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
|
1331 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
|
1332 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
|
1333 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
|
1334 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
|
1335 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
|
1336 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1337 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
|
1338 return 0; |
|
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 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
|
1341 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1342 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1343 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
|
1344 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
|
1345 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
|
1346 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
|
1347 return 0; |
|
42a6a3d1596e
Remove custom logger and output all diagnostics via syslog(3).
Roy Marples <roy@marples.name>
parents:
3932
diff
changeset
|
1348 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1349 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
|
1350 return 0; |
|
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 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
|
1353 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
|
1354 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1355 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1356 if (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
|
1357 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1358 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1359 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
|
1360 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
|
1361 /* 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
|
1362 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
|
1363 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
|
1364 /* SSID */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1365 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
|
1366 errno = ENOBUFS; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1367 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1368 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1369 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
|
1370 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
|
1371 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
|
1372 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1373 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
|
1374 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
|
1375 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1376 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1377 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1378 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1379 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1380 static int |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1381 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
|
1382 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1383 int family; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1384 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
|
1385 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1386 errno = 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1387 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
|
1388 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
|
1389 return -1; |
|
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 /* 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
|
1392 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
|
1393 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
|
1394 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
|
1395 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
|
1396 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
|
1397 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
|
1398 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
|
1399 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
|
1400 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1401 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1402 /* 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
|
1403 * 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
|
1404 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
|
1405 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
|
1406 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
|
1407 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
|
1408 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
|
1409 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
|
1410 |
|
4808
8761aaee4efe
Linux: improve the netlink API more
Roy Marples <roy@marples.name>
parents:
4804
diff
changeset
|
1411 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
|
1412 &_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
|
1413 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1414 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1415 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1416 int |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1417 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
|
1418 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1419 int r; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1420 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1421 #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
|
1422 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
|
1423 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
|
1424 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
|
1425 #else |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1426 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
|
1427 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
|
1428 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
|
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 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
|
1432 return r; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1433 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1434 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1435 struct nlma |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1436 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1437 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
|
1438 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
|
1439 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
|
1440 }; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1441 |
|
4781
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1442 #ifdef INET |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1443 struct ifiaddr |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1444 { |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1445 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
|
1446 struct in_addr ifa_addr; |
|
5533
8f117781bb06
Linux: Fix detecting existing IPv4 addresses
Roy Marples <roy@marples.name>
parents:
5486
diff
changeset
|
1447 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
|
1448 }; |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1449 |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1450 static int |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1451 _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
|
1452 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
|
1453 { |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1454 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
|
1455 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
|
1456 size_t len; |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1457 struct rtattr *rta; |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1458 struct ifaddrmsg *ifa; |
|
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 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
|
1461 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
|
1462 return 0; |
|
5533
8f117781bb06
Linux: Fix detecting existing IPv4 addresses
Roy Marples <roy@marples.name>
parents:
5486
diff
changeset
|
1463 |
|
4884
1378ef92e8bc
Linux: remove some casts no longer needed
Roy Marples <roy@marples.name>
parents:
4840
diff
changeset
|
1464 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
|
1465 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
|
1466 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
|
1467 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
|
1468 case IFA_LOCAL: |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1469 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
|
1470 if (this_addr == ia->ifa_addr.s_addr) { |
|
8f117781bb06
Linux: Fix detecting existing IPv4 addresses
Roy Marples <roy@marples.name>
parents:
5486
diff
changeset
|
1471 ia->ifa_found = true; |
|
8f117781bb06
Linux: Fix detecting existing IPv4 addresses
Roy Marples <roy@marples.name>
parents:
5486
diff
changeset
|
1472 return 1; |
|
8f117781bb06
Linux: Fix detecting existing IPv4 addresses
Roy Marples <roy@marples.name>
parents:
5486
diff
changeset
|
1473 } |
|
8f117781bb06
Linux: Fix detecting existing IPv4 addresses
Roy Marples <roy@marples.name>
parents:
5486
diff
changeset
|
1474 break; |
|
4781
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1475 } |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1476 } |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1477 return 0; |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1478 } |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1479 |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1480 static int |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1481 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
|
1482 { |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1483 struct ifiaddr ia = { |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1484 .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
|
1485 .ifa_addr = *addr, |
|
5533
8f117781bb06
Linux: Fix detecting existing IPv4 addresses
Roy Marples <roy@marples.name>
parents:
5486
diff
changeset
|
1486 .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
|
1487 }; |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1488 struct nlma nlm = { |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1489 .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
|
1490 .hdr.nlmsg_type = RTM_GETADDR, |
|
5533
8f117781bb06
Linux: Fix detecting existing IPv4 addresses
Roy Marples <roy@marples.name>
parents:
5486
diff
changeset
|
1491 .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
|
1492 .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
|
1493 .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
|
1494 }; |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1495 |
|
5533
8f117781bb06
Linux: Fix detecting existing IPv4 addresses
Roy Marples <roy@marples.name>
parents:
5486
diff
changeset
|
1496 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
|
1497 &_if_addressexists, &ia); |
|
5533
8f117781bb06
Linux: Fix detecting existing IPv4 addresses
Roy Marples <roy@marples.name>
parents:
5486
diff
changeset
|
1498 if (error == -1) |
|
8f117781bb06
Linux: Fix detecting existing IPv4 addresses
Roy Marples <roy@marples.name>
parents:
5486
diff
changeset
|
1499 return -1; |
|
8f117781bb06
Linux: Fix detecting existing IPv4 addresses
Roy Marples <roy@marples.name>
parents:
5486
diff
changeset
|
1500 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
|
1501 } |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1502 #endif |
|
090b21343985
Linux: validate RTM_NEWADDR/RTM_DELADDR for AF_INET as well.
Roy Marples <roy@marples.name>
parents:
4779
diff
changeset
|
1503 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1504 struct nlmr |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1505 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1506 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
|
1507 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
|
1508 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
|
1509 }; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1510 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1511 int |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1512 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
|
1513 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1514 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
|
1515 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
|
1516 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1517 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
|
1518 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
|
1519 switch (cmd) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1520 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
|
1521 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
|
1522 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
|
1523 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1524 case RTM_ADD: |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1525 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
|
1526 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
|
1527 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1528 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
|
1529 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
|
1530 break; |
|
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 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
|
1533 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
|
1534 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
|
1535 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1536 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
|
1537 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1538 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
|
1539 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
|
1540 } else { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1541 /* 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
|
1542 * otherwise RTPROT_BOOT */ |
|
4161
a40c7c100a45
Set RA routes as RA in supported OS's.
Roy Marples <roy@marples.name>
parents:
4147
diff
changeset
|
1543 #ifdef RTPROT_RA |
|
a40c7c100a45
Set RA routes as RA in supported OS's.
Roy Marples <roy@marples.name>
parents:
4147
diff
changeset
|
1544 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
|
1545 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
|
1546 else |
|
a40c7c100a45
Set RA routes as RA in supported OS's.
Roy Marples <roy@marples.name>
parents:
4147
diff
changeset
|
1547 #endif |
|
4162
fbed6260b7e1
Set DHCP routes as DHCP in supported OS's.
Roy Marples <roy@marples.name>
parents:
4161
diff
changeset
|
1548 #ifdef RTPROT_DHCP |
|
fbed6260b7e1
Set DHCP routes as DHCP in supported OS's.
Roy Marples <roy@marples.name>
parents:
4161
diff
changeset
|
1549 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
|
1550 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
|
1551 else |
|
fbed6260b7e1
Set DHCP routes as DHCP in supported OS's.
Roy Marples <roy@marples.name>
parents:
4161
diff
changeset
|
1552 #endif |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1553 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
|
1554 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
|
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 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
|
1557 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
|
1558 nlm.rt.rtm_scope = RT_SCOPE_HOST; |
|
4292
3d4667e8f9c9
linux: fix adding host routes
Roy Marples <roy@marples.name>
parents:
4257
diff
changeset
|
1559 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
|
1560 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
|
1561 else |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1562 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
|
1563 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
|
1564 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
|
1565 else |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1566 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
|
1567 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1568 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1569 #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
|
1570 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
|
1571 (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
|
1572 (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
|
1573 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
|
1574 /* 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
|
1575 * 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
|
1576 * generic sockaddr and coverity thinks this will overrun. */ |
|
901ff4b0952b
Linux: Mark another coverity false positive.
Roy Marples <roy@marples.name>
parents:
4572
diff
changeset
|
1577 /* 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
|
1578 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
|
1579 if (cmd == RTM_ADD || cmd == RTM_CHANGE) { |
|
4574
901ff4b0952b
Linux: Mark another coverity false positive.
Roy Marples <roy@marples.name>
parents:
4572
diff
changeset
|
1580 if (!gateway_unspec) { |
|
901ff4b0952b
Linux: Mark another coverity false positive.
Roy Marples <roy@marples.name>
parents:
4572
diff
changeset
|
1581 /* 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
|
1582 ADDSA(RTA_GATEWAY, &rt->rt_gateway); |
|
4574
901ff4b0952b
Linux: Mark another coverity false positive.
Roy Marples <roy@marples.name>
parents:
4572
diff
changeset
|
1583 } |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1584 /* 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
|
1585 * 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
|
1586 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
|
1587 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
|
1588 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
|
1589 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
|
1590 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
|
1591 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
|
1592 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1593 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
|
1594 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
|
1595 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
|
1596 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
|
1597 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
|
1598 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
|
1599 (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
|
1600 } |
|
5130
d34c808ae81e
Linux: Note router preference when adding routes
Roy Marples <roy@marples.name>
parents:
5115
diff
changeset
|
1601 |
|
5341
b5656c618975
Linux: Fix compile for systems without route preference
Roy Marples <roy@marples.name>
parents:
5285
diff
changeset
|
1602 #ifdef HAVE_ROUTE_PREF |
|
5130
d34c808ae81e
Linux: Note router preference when adding routes
Roy Marples <roy@marples.name>
parents:
5115
diff
changeset
|
1603 if (rt->rt_dflags & RTDF_RA) { |
|
d34c808ae81e
Linux: Note router preference when adding routes
Roy Marples <roy@marples.name>
parents:
5115
diff
changeset
|
1604 uint8_t pref; |
|
d34c808ae81e
Linux: Note router preference when adding routes
Roy Marples <roy@marples.name>
parents:
5115
diff
changeset
|
1605 |
|
d34c808ae81e
Linux: Note router preference when adding routes
Roy Marples <roy@marples.name>
parents:
5115
diff
changeset
|
1606 switch(rt->rt_pref) { |
|
d34c808ae81e
Linux: Note router preference when adding routes
Roy Marples <roy@marples.name>
parents:
5115
diff
changeset
|
1607 case RTPREF_LOW: |
|
d34c808ae81e
Linux: Note router preference when adding routes
Roy Marples <roy@marples.name>
parents:
5115
diff
changeset
|
1608 pref = ICMPV6_ROUTER_PREF_LOW; |
|
d34c808ae81e
Linux: Note router preference when adding routes
Roy Marples <roy@marples.name>
parents:
5115
diff
changeset
|
1609 break; |
|
d34c808ae81e
Linux: Note router preference when adding routes
Roy Marples <roy@marples.name>
parents:
5115
diff
changeset
|
1610 case RTPREF_MEDIUM: |
|
d34c808ae81e
Linux: Note router preference when adding routes
Roy Marples <roy@marples.name>
parents:
5115
diff
changeset
|
1611 pref = ICMPV6_ROUTER_PREF_MEDIUM; |
|
d34c808ae81e
Linux: Note router preference when adding routes
Roy Marples <roy@marples.name>
parents:
5115
diff
changeset
|
1612 break; |
|
d34c808ae81e
Linux: Note router preference when adding routes
Roy Marples <roy@marples.name>
parents:
5115
diff
changeset
|
1613 case RTPREF_HIGH: |
|
d34c808ae81e
Linux: Note router preference when adding routes
Roy Marples <roy@marples.name>
parents:
5115
diff
changeset
|
1614 pref = ICMPV6_ROUTER_PREF_HIGH; |
|
d34c808ae81e
Linux: Note router preference when adding routes
Roy Marples <roy@marples.name>
parents:
5115
diff
changeset
|
1615 break; |
|
d34c808ae81e
Linux: Note router preference when adding routes
Roy Marples <roy@marples.name>
parents:
5115
diff
changeset
|
1616 default: |
|
d34c808ae81e
Linux: Note router preference when adding routes
Roy Marples <roy@marples.name>
parents:
5115
diff
changeset
|
1617 pref = ICMPV6_ROUTER_PREF_INVALID; |
|
d34c808ae81e
Linux: Note router preference when adding routes
Roy Marples <roy@marples.name>
parents:
5115
diff
changeset
|
1618 break; |
|
d34c808ae81e
Linux: Note router preference when adding routes
Roy Marples <roy@marples.name>
parents:
5115
diff
changeset
|
1619 } |
|
d34c808ae81e
Linux: Note router preference when adding routes
Roy Marples <roy@marples.name>
parents:
5115
diff
changeset
|
1620 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
|
1621 } |
|
5341
b5656c618975
Linux: Fix compile for systems without route preference
Roy Marples <roy@marples.name>
parents:
5285
diff
changeset
|
1622 #endif |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1623 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1624 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1625 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
|
1626 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
|
1627 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1628 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
|
1629 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
|
1630 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
|
1631 |
|
4808
8761aaee4efe
Linux: improve the netlink API more
Roy Marples <roy@marples.name>
parents:
4804
diff
changeset
|
1632 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
|
1633 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
|
1634 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1635 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1636 static int |
|
4400
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4371
diff
changeset
|
1637 _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
|
1638 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
|
1639 { |
|
4400
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4371
diff
changeset
|
1640 struct rt rt, *rtn; |
|
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4371
diff
changeset
|
1641 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
|
1642 |
|
4400
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4371
diff
changeset
|
1643 if (if_copyrt(ctx, &rt, nlm) != 0) |
|
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4371
diff
changeset
|
1644 return 0; |
|
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4371
diff
changeset
|
1645 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
|
1646 logerr(__func__); |
|
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4371
diff
changeset
|
1647 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
|
1648 } |
|
4400
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4371
diff
changeset
|
1649 memcpy(rtn, &rt, sizeof(*rtn)); |
|
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4371
diff
changeset
|
1650 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
|
1651 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
|
1652 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1653 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1654 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1655 int |
|
4400
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4371
diff
changeset
|
1656 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
|
1657 { |
|
4371
a7f3d85f54ce
Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents:
4366
diff
changeset
|
1658 struct nlmr nlm = { |
|
a7f3d85f54ce
Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents:
4366
diff
changeset
|
1659 .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
|
1660 .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
|
1661 .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
|
1662 .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
|
1663 .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
|
1664 }; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1665 |
|
4808
8761aaee4efe
Linux: improve the netlink API more
Roy Marples <roy@marples.name>
parents:
4804
diff
changeset
|
1666 return if_sendnetlink(ctx, NETLINK_ROUTE, &nlm.hdr, |
|
8761aaee4efe
Linux: improve the netlink API more
Roy Marples <roy@marples.name>
parents:
4804
diff
changeset
|
1667 &_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
|
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 #ifdef INET |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1671 /* 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
|
1672 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
|
1673 |
|
4757
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4750
diff
changeset
|
1674 /* Linux is a special snowflake for opening BPF. */ |
| 5234 | 1675 struct bpf * |
| 1676 bpf_open(const struct interface *ifp, | |
| 1677 int (*filter)(const struct bpf *, const struct in_addr *), | |
| 1678 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
|
1679 { |
| 5234 | 1680 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
|
1681 union sockunion { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1682 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
|
1683 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
|
1684 struct sockaddr_storage ss; |
|
4757
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4750
diff
changeset
|
1685 } su = { |
|
5383
5f88487cbf65
Linux: fix a compile warning for older compilers
Roy Marples <roy@marples.name>
parents:
5382
diff
changeset
|
1686 .sll = { |
|
5f88487cbf65
Linux: fix a compile warning for older compilers
Roy Marples <roy@marples.name>
parents:
5382
diff
changeset
|
1687 .sll_family = PF_PACKET, |
|
5f88487cbf65
Linux: fix a compile warning for older compilers
Roy Marples <roy@marples.name>
parents:
5382
diff
changeset
|
1688 .sll_protocol = htons(ETH_P_ALL), |
|
5f88487cbf65
Linux: fix a compile warning for older compilers
Roy Marples <roy@marples.name>
parents:
5382
diff
changeset
|
1689 .sll_ifindex = (int)ifp->index, |
|
5f88487cbf65
Linux: fix a compile warning for older compilers
Roy Marples <roy@marples.name>
parents:
5382
diff
changeset
|
1690 } |
|
4757
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4750
diff
changeset
|
1691 }; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1692 #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
|
1693 int n; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1694 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1695 |
| 5234 | 1696 bpf = calloc(1, sizeof(*bpf)); |
| 1697 if (bpf == NULL) | |
| 1698 return NULL; | |
| 1699 bpf->bpf_ifp = ifp; | |
|
4757
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4750
diff
changeset
|
1700 |
| 5234 | 1701 /* Allocate a suitably large buffer for a single packet. */ |
| 1702 bpf->bpf_size = ETH_DATA_LEN; | |
| 1703 bpf->bpf_buffer = malloc(bpf->bpf_size); | |
| 1704 if (bpf->bpf_buffer == NULL) | |
| 1705 goto eexit; | |
|
4757
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4750
diff
changeset
|
1706 |
| 5234 | 1707 bpf->bpf_fd = xsocket(PF_PACKET, SOCK_RAW|SOCK_CXNB,htons(ETH_P_ALL)); |
| 1708 if (bpf->bpf_fd == -1) | |
| 1709 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
|
1710 |
|
4757
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4750
diff
changeset
|
1711 /* We cannot validate the correct interface, |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4750
diff
changeset
|
1712 * so we MUST set this first. */ |
| 5234 | 1713 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
|
1714 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
|
1715 |
| 5234 | 1716 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
|
1717 goto eexit; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1718 |
|
4757
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4750
diff
changeset
|
1719 /* 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
|
1720 #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
|
1721 n = 1; |
| 5234 | 1722 if (setsockopt(bpf->bpf_fd, SOL_PACKET, PACKET_AUXDATA, |
| 1723 &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
|
1724 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
|
1725 goto eexit; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1726 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1727 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1728 |
|
4757
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4750
diff
changeset
|
1729 /* |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4750
diff
changeset
|
1730 * 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
|
1731 * 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
|
1732 * 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
|
1733 * 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
|
1734 * 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
|
1735 * 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
|
1736 */ |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4750
diff
changeset
|
1737 |
| 5234 | 1738 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
|
1739 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1740 eexit: |
| 5234 | 1741 if (bpf->bpf_fd != -1) |
| 1742 close(bpf->bpf_fd); | |
| 1743 free(bpf->bpf_buffer); | |
| 1744 free(bpf); | |
| 1745 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
|
1746 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1747 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1748 /* 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
|
1749 * 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
|
1750 ssize_t |
| 5234 | 1751 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
|
1752 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1753 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
|
1754 struct iovec iov = { |
| 5234 | 1755 .iov_base = bpf->bpf_buffer, |
| 1756 .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
|
1757 }; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1758 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
|
1759 #ifdef PACKET_AUXDATA |
| 5172 | 1760 union { |
| 1761 struct cmsghdr hdr; | |
| 1762 uint8_t buf[CMSG_SPACE(sizeof(struct tpacket_auxdata))]; | |
| 1763 } 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
|
1764 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
|
1765 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
|
1766 #endif |
|
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 #ifdef PACKET_AUXDATA |
| 5172 | 1769 msg.msg_control = cmsgbuf.buf; |
| 1770 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
|
1771 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1772 |
| 5234 | 1773 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
|
1774 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
|
1775 return -1; |
| 5234 | 1776 bpf->bpf_flags |= BPF_EOF; /* We only ever read one packet. */ |
| 1777 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
|
1778 if (bytes) { |
| 5234 | 1779 if (bpf_frame_bcast(bpf->bpf_ifp, bpf->bpf_buffer) == 0) |
| 1780 bpf->bpf_flags |= BPF_BCAST; | |
|
4456
101b31471d89
BPF: Set BPF_MCAST flag as on BSD
Roy Marples <roy@marples.name>
parents:
4421
diff
changeset
|
1781 else |
| 5234 | 1782 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
|
1783 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
|
1784 bytes = (ssize_t)len; |
| 5234 | 1785 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
|
1786 #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
|
1787 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
|
1788 cmsg; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1789 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
|
1790 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1791 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
|
1792 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
|
1793 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
|
1794 if (aux->tp_status & TP_STATUS_CSUMNOTREADY) |
| 5234 | 1795 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
|
1796 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1797 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1798 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1799 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1800 return bytes; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1801 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1802 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1803 int |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1804 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
|
1805 { |
| 4636 | 1806 struct sock_fprog pf = { |
| 1807 .filter = filter, | |
|
4694
426e04b84902
Linux: cast away a compile warning
Roy Marples <roy@marples.name>
parents:
4670
diff
changeset
|
1808 .len = (unsigned short)filter_len, |
| 4636 | 1809 }; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1810 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1811 /* Install the filter. */ |
|
5230
92569921a974
Linux: Lock the BPF filter from future changes
Roy Marples <roy@marples.name>
parents:
5215
diff
changeset
|
1812 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
|
1813 return -1; |
|
92569921a974
Linux: Lock the BPF filter from future changes
Roy Marples <roy@marples.name>
parents:
5215
diff
changeset
|
1814 |
|
92569921a974
Linux: Lock the BPF filter from future changes
Roy Marples <roy@marples.name>
parents:
5215
diff
changeset
|
1815 #ifdef SO_LOCK_FILTER |
|
92569921a974
Linux: Lock the BPF filter from future changes
Roy Marples <roy@marples.name>
parents:
5215
diff
changeset
|
1816 int on = 1; |
|
92569921a974
Linux: Lock the BPF filter from future changes
Roy Marples <roy@marples.name>
parents:
5215
diff
changeset
|
1817 |
|
92569921a974
Linux: Lock the BPF filter from future changes
Roy Marples <roy@marples.name>
parents:
5215
diff
changeset
|
1818 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
|
1819 return -1; |
|
92569921a974
Linux: Lock the BPF filter from future changes
Roy Marples <roy@marples.name>
parents:
5215
diff
changeset
|
1820 #endif |
|
92569921a974
Linux: Lock the BPF filter from future changes
Roy Marples <roy@marples.name>
parents:
5215
diff
changeset
|
1821 |
|
92569921a974
Linux: Lock the BPF filter from future changes
Roy Marples <roy@marples.name>
parents:
5215
diff
changeset
|
1822 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
|
1823 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1824 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1825 int |
|
4555
93b4eb29d297
DHCP: Set address vltime and pltime to the length of the lease
Roy Marples <roy@marples.name>
parents:
4548
diff
changeset
|
1826 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
|
1827 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1828 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
|
1829 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
|
1830 int retval = 0; |
| 4609 | 1831 #ifdef IFA_F_NOPREFIXROUTE |
|
4194
f82c8bde229d
linux: use IFA_F_NOPREFIXROUTE for ipv4 addresses
Roy Marples <roy@marples.name>
parents:
4180
diff
changeset
|
1832 uint32_t flags = 0; |
| 4609 | 1833 #endif |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1834 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1835 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
|
1836 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
|
1837 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
|
1838 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
|
1839 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
|
1840 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
|
1841 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
|
1842 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
|
1843 |
|
93b4eb29d297
DHCP: Set address vltime and pltime to the length of the lease
Roy Marples <roy@marples.name>
parents:
4548
diff
changeset
|
1844 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
|
1845 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1846 #if 0 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1847 /* 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
|
1848 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
|
1849 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
|
1850 (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
|
1851 #endif |
|
f82c8bde229d
linux: use IFA_F_NOPREFIXROUTE for ipv4 addresses
Roy Marples <roy@marples.name>
parents:
4180
diff
changeset
|
1852 |
|
4555
93b4eb29d297
DHCP: Set address vltime and pltime to the length of the lease
Roy Marples <roy@marples.name>
parents:
4548
diff
changeset
|
1853 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
|
1854 &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
|
1855 |
|
93b4eb29d297
DHCP: Set address vltime and pltime to the length of the lease
Roy Marples <roy@marples.name>
parents:
4548
diff
changeset
|
1856 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
|
1857 #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
|
1858 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
|
1859 flags |= IFA_F_NOPREFIXROUTE; |
| 4609 | 1860 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
|
1861 #endif |
|
93b4eb29d297
DHCP: Set address vltime and pltime to the length of the lease
Roy Marples <roy@marples.name>
parents:
4548
diff
changeset
|
1862 |
|
93b4eb29d297
DHCP: Set address vltime and pltime to the length of the lease
Roy Marples <roy@marples.name>
parents:
4548
diff
changeset
|
1863 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
|
1864 &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
|
1865 |
|
93b4eb29d297
DHCP: Set address vltime and pltime to the length of the lease
Roy Marples <roy@marples.name>
parents:
4548
diff
changeset
|
1866 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
|
1867 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
|
1868 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
|
1869 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
|
1870 &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
|
1871 } |
|
93b4eb29d297
DHCP: Set address vltime and pltime to the length of the lease
Roy Marples <roy@marples.name>
parents:
4548
diff
changeset
|
1872 |
|
4808
8761aaee4efe
Linux: improve the netlink API more
Roy Marples <roy@marples.name>
parents:
4804
diff
changeset
|
1873 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
|
1874 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
|
1875 retval = -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1876 return retval; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1877 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1878 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1879 int |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1880 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
|
1881 __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
|
1882 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1883 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1884 /* 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
|
1885 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1886 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1887 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1888 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1889 #ifdef INET6 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1890 int |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1891 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
|
1892 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1893 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
|
1894 struct ifa_cacheinfo cinfo; |
| 4609 | 1895 #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
|
1896 uint32_t flags = 0; |
| 4609 | 1897 #endif |
|
3932
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 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
|
1900 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
|
1901 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
|
1902 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
|
1903 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
|
1904 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
|
1905 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
|
1906 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
|
1907 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1908 /* 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
|
1909 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
|
1910 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1911 #if 0 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1912 /* 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
|
1913 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
|
1914 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
|
1915 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1916 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
|
1917 &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
|
1918 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1919 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
|
1920 #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
|
1921 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
|
1922 /* 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
|
1923 #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
|
1924 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
|
1925 #else |
|
93b4eb29d297
DHCP: Set address vltime and pltime to the length of the lease
Roy Marples <roy@marples.name>
parents:
4548
diff
changeset
|
1926 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
|
1927 #endif |
|
93b4eb29d297
DHCP: Set address vltime and pltime to the length of the lease
Roy Marples <roy@marples.name>
parents:
4548
diff
changeset
|
1928 } |
|
93b4eb29d297
DHCP: Set address vltime and pltime to the length of the lease
Roy Marples <roy@marples.name>
parents:
4548
diff
changeset
|
1929 #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
|
1930 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
|
1931 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
|
1932 #endif |
|
93b4eb29d297
DHCP: Set address vltime and pltime to the length of the lease
Roy Marples <roy@marples.name>
parents:
4548
diff
changeset
|
1933 #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
|
1934 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
|
1935 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
|
1936 #endif |
| 4609 | 1937 #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
|
1938 add_attr_32(&nlm.hdr, sizeof(nlm), IFA_FLAGS, flags); |
| 4609 | 1939 #endif |
|
4555
93b4eb29d297
DHCP: Set address vltime and pltime to the length of the lease
Roy Marples <roy@marples.name>
parents:
4548
diff
changeset
|
1940 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1941 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
|
1942 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
|
1943 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
|
1944 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
|
1945 &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
|
1946 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1947 |
|
4808
8761aaee4efe
Linux: improve the netlink API more
Roy Marples <roy@marples.name>
parents:
4804
diff
changeset
|
1948 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
|
1949 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
|
1950 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1951 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1952 int |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1953 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
|
1954 __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
|
1955 { |
|
5258
f29e384aa13e
privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
1956 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
|
1957 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
|
1958 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
|
1959 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
|
1960 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
|
1961 |
|
5258
f29e384aa13e
privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
1962 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
|
1963 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
|
1964 return -1; |
|
5258
f29e384aa13e
privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
1965 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
|
1966 errno = ENOBUFS; |
|
f29e384aa13e
privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
1967 return -1; |
|
f29e384aa13e
privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
1968 } |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1969 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1970 p = ifaddress; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1971 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
|
1972 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
|
1973 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1974 *p = '\0'; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1975 |
|
5258
f29e384aa13e
privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
1976 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
|
1977 if (sscanf(line, |
|
f29e384aa13e
privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
1978 "%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
|
1979 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
|
1980 strlen(address) != 32) |
|
f29e384aa13e
privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
1981 { |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1982 errno = EINVAL; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1983 return -1; |
|
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 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
|
1986 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
|
1987 return flags; |
|
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 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1990 errno = ESRCH; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1991 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1992 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1993 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1994 int |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1995 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
|
1996 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1997 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1998 /* 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
|
1999 errno = ENOTSUP; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2000 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2001 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2002 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2003 struct nlml |
|
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 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
|
2006 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
|
2007 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
|
2008 }; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2009 |
|
5134
3b4dcb6c284c
linux: Remove warning when HAVE_IN6_ADDR_GEN_MODE_NONE isn't supported
Roy Marples <roy@marples.name>
parents:
5130
diff
changeset
|
2010 #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
|
2011 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
|
2012 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
|
2013 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2014 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
|
2015 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2016 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
|
2017 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
|
2018 return nest; |
|
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 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2021 static void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2022 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
|
2023 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2024 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2025 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
|
2026 } |
|
5134
3b4dcb6c284c
linux: Remove warning when HAVE_IN6_ADDR_GEN_MODE_NONE isn't supported
Roy Marples <roy@marples.name>
parents:
5130
diff
changeset
|
2027 #endif |
|
3932
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 static int |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2030 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
|
2031 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2032 #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
|
2033 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
|
2034 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
|
2035 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2036 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
|
2037 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
|
2038 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
|
2039 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
|
2040 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
|
2041 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
|
2042 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
|
2043 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
|
2044 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
|
2045 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
|
2046 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
|
2047 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
|
2048 |
|
4808
8761aaee4efe
Linux: improve the netlink API more
Roy Marples <roy@marples.name>
parents:
4804
diff
changeset
|
2049 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
|
2050 #else |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2051 UNUSED(ctx); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2052 UNUSED(ifindex); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2053 errno = ENOTSUP; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2054 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2055 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2056 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2057 |
|
4814
409f831b6585
Linux: fix compile for prior
Roy Marples <roy@marples.name>
parents:
4813
diff
changeset
|
2058 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
|
2059 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
|
2060 |
|
4218
f618f850efdc
inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents:
4197
diff
changeset
|
2061 void |
|
f618f850efdc
inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents:
4197
diff
changeset
|
2062 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
|
2063 { |
|
5258
f29e384aa13e
privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
2064 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
|
2065 int ra; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2066 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
|
2067 |
|
5384
6d1812f4a3ac
Linux: Sweep errors about disabling autogeneration of LL addrs
Roy Marples <roy@marples.name>
parents:
5383
diff
changeset
|
2068 /* 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
|
2069 * 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
|
2070 * 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
|
2071 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
|
2072 errno != ENODEV && errno != ENOTSUP && errno != EINVAL) |
|
4218
f618f850efdc
inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents:
4197
diff
changeset
|
2073 logdebug("%s: if_disable_autolinklocal", ifp->name); |
|
f618f850efdc
inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents:
4197
diff
changeset
|
2074 |
|
f618f850efdc
inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents:
4197
diff
changeset
|
2075 /* |
|
4229
12388193ccdc
inet6: remove references to the crazies.
Roy Marples <roy@marples.name>
parents:
4225
diff
changeset
|
2076 * 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
|
2077 * 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
|
2078 */ |
|
f618f850efdc
inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents:
4197
diff
changeset
|
2079 if (!(ifp->options->options & DHCPCD_IPV6RS)) |
|
f618f850efdc
inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents:
4197
diff
changeset
|
2080 return; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2081 |
|
4814
409f831b6585
Linux: fix compile for prior
Roy Marples <roy@marples.name>
parents:
4813
diff
changeset
|
2082 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
|
2083 ra = check_proc_int(ctx, path); |
|
4218
f618f850efdc
inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents:
4197
diff
changeset
|
2084 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
|
2085 if (if_writepathuint(ctx, path, 0) == -1) |
| 4010 | 2086 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
|
2087 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2088 |
|
4814
409f831b6585
Linux: fix compile for prior
Roy Marples <roy@marples.name>
parents:
4813
diff
changeset
|
2089 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
|
2090 ra = check_proc_int(ctx, path); |
| 4010 | 2091 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
|
2092 /* 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
|
2093 * 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
|
2094 if (errno != ENOENT) |
|
7721231839f5
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5051
diff
changeset
|
2095 logerr("%s: %s", __func__, path); |
|
4218
f618f850efdc
inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents:
4197
diff
changeset
|
2096 } else if (ra != 0) { |
|
5258
f29e384aa13e
privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
2097 if (if_writepathuint(ctx, path, 0) == -1) |
| 4010 | 2098 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
|
2099 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2100 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2101 |
|
4813
ef33eb73e97d
INET6: Apply hoplimit, reachable and retrans timer values from RA.
Roy Marples <roy@marples.name>
parents:
4809
diff
changeset
|
2102 int |
|
ef33eb73e97d
INET6: Apply hoplimit, reachable and retrans timer values from RA.
Roy Marples <roy@marples.name>
parents:
4809
diff
changeset
|
2103 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
|
2104 { |
|
4814
409f831b6585
Linux: fix compile for prior
Roy Marples <roy@marples.name>
parents:
4813
diff
changeset
|
2105 char path[256]; |
|
409f831b6585
Linux: fix compile for prior
Roy Marples <roy@marples.name>
parents:
4813
diff
changeset
|
2106 const char *ifname = rap->iface->name; |
|
4840
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4828
diff
changeset
|
2107 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
|
2108 int error = 0; |
|
ef33eb73e97d
INET6: Apply hoplimit, reachable and retrans timer values from RA.
Roy Marples <roy@marples.name>
parents:
4809
diff
changeset
|
2109 |
|
5178
fbe055b8e53d
Linux: Only set positive reachable timers
Roy Marples <roy@marples.name>
parents:
5172
diff
changeset
|
2110 if (rap->hoplimit != 0) { |
|
fbe055b8e53d
Linux: Only set positive reachable timers
Roy Marples <roy@marples.name>
parents:
5172
diff
changeset
|
2111 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
|
2112 if (if_writepathuint(ctx, path, rap->hoplimit) == -1) |
|
fbe055b8e53d
Linux: Only set positive reachable timers
Roy Marples <roy@marples.name>
parents:
5172
diff
changeset
|
2113 error = -1; |
|
fbe055b8e53d
Linux: Only set positive reachable timers
Roy Marples <roy@marples.name>
parents:
5172
diff
changeset
|
2114 } |
| 4826 | 2115 |
|
5178
fbe055b8e53d
Linux: Only set positive reachable timers
Roy Marples <roy@marples.name>
parents:
5172
diff
changeset
|
2116 if (rap->retrans != 0) { |
|
fbe055b8e53d
Linux: Only set positive reachable timers
Roy Marples <roy@marples.name>
parents:
5172
diff
changeset
|
2117 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
|
2118 p_neigh, ifname); |
|
fbe055b8e53d
Linux: Only set positive reachable timers
Roy Marples <roy@marples.name>
parents:
5172
diff
changeset
|
2119 if (if_writepathuint(ctx, path, rap->retrans) == -1) |
|
fbe055b8e53d
Linux: Only set positive reachable timers
Roy Marples <roy@marples.name>
parents:
5172
diff
changeset
|
2120 error = -1; |
|
fbe055b8e53d
Linux: Only set positive reachable timers
Roy Marples <roy@marples.name>
parents:
5172
diff
changeset
|
2121 } |
| 4826 | 2122 |
|
5178
fbe055b8e53d
Linux: Only set positive reachable timers
Roy Marples <roy@marples.name>
parents:
5172
diff
changeset
|
2123 if (rap->reachable != 0) { |
|
fbe055b8e53d
Linux: Only set positive reachable timers
Roy Marples <roy@marples.name>
parents:
5172
diff
changeset
|
2124 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
|
2125 p_neigh, ifname); |
|
fbe055b8e53d
Linux: Only set positive reachable timers
Roy Marples <roy@marples.name>
parents:
5172
diff
changeset
|
2126 if (if_writepathuint(ctx, path, rap->reachable) == -1) |
|
fbe055b8e53d
Linux: Only set positive reachable timers
Roy Marples <roy@marples.name>
parents:
5172
diff
changeset
|
2127 error = -1; |
|
fbe055b8e53d
Linux: Only set positive reachable timers
Roy Marples <roy@marples.name>
parents:
5172
diff
changeset
|
2128 } |
|
4916
7513775ead91
inet6: Adjust prior so that we don't support old kernels
Roy Marples <roy@marples.name>
parents:
4914
diff
changeset
|
2129 |
|
4813
ef33eb73e97d
INET6: Apply hoplimit, reachable and retrans timer values from RA.
Roy Marples <roy@marples.name>
parents:
4809
diff
changeset
|
2130 return error; |
|
ef33eb73e97d
INET6: Apply hoplimit, reachable and retrans timer values from RA.
Roy Marples <roy@marples.name>
parents:
4809
diff
changeset
|
2131 } |
|
ef33eb73e97d
INET6: Apply hoplimit, reachable and retrans timer values from RA.
Roy Marples <roy@marples.name>
parents:
4809
diff
changeset
|
2132 |
|
4335
d0519e1f2f5f
ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents:
4333
diff
changeset
|
2133 int |
|
d0519e1f2f5f
ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents:
4333
diff
changeset
|
2134 ip6_forwarding(const char *ifname) |
|
d0519e1f2f5f
ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents:
4333
diff
changeset
|
2135 { |
|
5258
f29e384aa13e
privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
2136 char path[256], buf[64]; |
|
f29e384aa13e
privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
2137 int error, i; |
|
4335
d0519e1f2f5f
ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents:
4333
diff
changeset
|
2138 |
|
d0519e1f2f5f
ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents:
4333
diff
changeset
|
2139 if (ifname == NULL) |
|
d0519e1f2f5f
ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents:
4333
diff
changeset
|
2140 ifname = "all"; |
|
4814
409f831b6585
Linux: fix compile for prior
Roy Marples <roy@marples.name>
parents:
4813
diff
changeset
|
2141 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
|
2142 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
|
2143 return 0; |
|
f29e384aa13e
privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
2144 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
|
2145 if (error != 0 && error != ENOTSUP) |
| 5281 | 2146 return 0; |
| 2147 return i; | |
|
4335
d0519e1f2f5f
ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents:
4333
diff
changeset
|
2148 } |
|
d0519e1f2f5f
ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents:
4333
diff
changeset
|
2149 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2150 #endif /* INET6 */ |
