annotate src/if-bsd.c @ 5557:e65d193a1960 draft

Linux: Support wireless IP roaming This is achieved by checking that the interface is wireless, IFF_UP and IFF_LOWER_UP are present, but IFF_RUNNING is missing. This gives exactly the same support as modern NetBSD when carrier loss is detected, but without the address verifications when the carrier comes back as that needs to be handled in the kernel. While IP setup is maintained, other configuration data is discarded. Note that this should be improved in the future. Thanks to Boris Krasnovskiy <borkra@gmail.com> for helping with this.
author Roy Marples <roy@marples.name>
date Sat, 12 Dec 2020 13:12:26 +0000
parents 6a2da5651841
children 80fba4edc6c5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4548
c7df03794de3 Add SPDX identifiers to all dhcpcd source files.
Yegor Yefremov <yegorslists@googlemail.com>
parents: 4511
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 * BSD interface driver for dhcpcd
4922
555d7d1a4939 Welcome to 2020!
Roy Marples <roy@marples.name>
parents: 4840
diff changeset
4 * Copyright (c) 2006-2020 Roy Marples <roy@marples.name>
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
5 * All rights reserved
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
6
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
7 * Redistribution and use in source and binary forms, with or without
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
8 * modification, are permitted provided that the following conditions
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
9 * are met:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
10 * 1. Redistributions of source code must retain the above copyright
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
11 * notice, this list of conditions and the following disclaimer.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
15 *
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
26 * SUCH DAMAGE.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
27 */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
28
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
29 #include <sys/ioctl.h>
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
30 #include <sys/param.h>
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
31 #include <sys/socket.h>
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
32 #include <sys/stat.h>
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
33 #include <sys/sysctl.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/time.h>
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
35 #include <sys/types.h>
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
36 #include <sys/uio.h>
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
37 #include <sys/utsname.h>
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
38
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
39 #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
40
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
41 #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
42 #include <net/bpf.h>
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
43 #include <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
44 #include <net/if_dl.h>
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
45 #include <net/if_media.h>
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
46 #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
47 #include <netinet/if_ether.h>
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
48 #include <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
49 #include <netinet/in_var.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 <netinet6/in6_var.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 <netinet6/nd6.h>
4052
08038b46c0f5 Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents: 4049
diff changeset
52 #ifdef __NetBSD__
08038b46c0f5 Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents: 4049
diff changeset
53 #include <net/if_vlanvar.h> /* Needs netinet/if_ether.h */
4602
4315e1265f1c DragonFlyBSD: Fix compile
Roy Marples <roy@marples.name>
parents: 4576
diff changeset
54 #elif defined(__DragonFly__)
4315e1265f1c DragonFlyBSD: Fix compile
Roy Marples <roy@marples.name>
parents: 4576
diff changeset
55 #include <net/vlan/if_vlan_var.h>
4052
08038b46c0f5 Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents: 4049
diff changeset
56 #else
08038b46c0f5 Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents: 4049
diff changeset
57 #include <net/if_vlan_var.h>
08038b46c0f5 Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents: 4049
diff changeset
58 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
59 #ifdef __DragonFly__
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
60 # include <netproto/802_11/ieee80211_ioctl.h>
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
61 #else
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
62 # include <net80211/ieee80211.h>
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
63 # include <net80211/ieee80211_ioctl.h>
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
64 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
65
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
66 #include <assert.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 <errno.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 <fcntl.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 <fnmatch.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 <paths.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 <stddef.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 <stdio.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 <stdlib.h>
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
74 #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
75 #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
76
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
77 #if defined(OpenBSD) && OpenBSD >= 201411
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
78 /* OpenBSD dropped the global setting from sysctl but left the #define
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
79 * which causes a EPERM error when trying to use it.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
80 * I think both the error and keeping the define are wrong, so we #undef it. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
81 #undef IPV6CTL_ACCEPT_RTADV
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
82 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
83
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
84 #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
85 #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
86 #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
87 #include "if-options.h"
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
88 #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
89 #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
90 #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
91 #include "ipv6nd.h"
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 4004
diff changeset
92 #include "logerr.h"
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
93 #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
94 #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
95 #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
96
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
97 #ifndef RT_ROUNDUP
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
98 #define RT_ROUNDUP(a) \
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
99 ((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
100 #define RT_ADVANCE(x, n) (x += RT_ROUNDUP((n)->sa_len))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
101 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
102
5298
95d69db26ac5 BSD: Ignore fwip(4)
Roy Marples <roy@marples.name>
parents: 5238
diff changeset
103 /* Ignore these interface names which look like ethernet but are virtual or
95d69db26ac5 BSD: Ignore fwip(4)
Roy Marples <roy@marples.name>
parents: 5238
diff changeset
104 * just won't work without explicit configuration. */
4747
c995401f5572 if: Ignore TAP interfaces by default
Roy Marples <roy@marples.name>
parents: 4706
diff changeset
105 static const char * const ifnames_ignore[] = {
4751
3da1a505a6dd BSD: Ignore bridge interfaces
Roy Marples <roy@marples.name>
parents: 4749
diff changeset
106 "bridge",
3da1a505a6dd BSD: Ignore bridge interfaces
Roy Marples <roy@marples.name>
parents: 4749
diff changeset
107 "fwe", /* Firewire */
5298
95d69db26ac5 BSD: Ignore fwip(4)
Roy Marples <roy@marples.name>
parents: 5238
diff changeset
108 "fwip", /* Firewire */
4747
c995401f5572 if: Ignore TAP interfaces by default
Roy Marples <roy@marples.name>
parents: 4706
diff changeset
109 "tap",
5485
6792cb73e021 BSD: Ignore vether(4) devices by default.
Roy Marples <roy@marples.name>
parents: 5483
diff changeset
110 "vether",
5024
c79de58c1533 BSD: ignore XEN DOM0 virtual interface xvif
Roy Marples <roy@marples.name>
parents: 5020
diff changeset
111 "xvif", /* XEN DOM0 -> guest interface */
4747
c995401f5572 if: Ignore TAP interfaces by default
Roy Marples <roy@marples.name>
parents: 4706
diff changeset
112 NULL
c995401f5572 if: Ignore TAP interfaces by default
Roy Marples <roy@marples.name>
parents: 4706
diff changeset
113 };
c995401f5572 if: Ignore TAP interfaces by default
Roy Marples <roy@marples.name>
parents: 4706
diff changeset
114
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
115 struct priv {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
116 int pf_inet6_fd;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
117 };
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
118
4437
5f768f1d37ad BSD: Simplify rtm usage
Roy Marples <roy@marples.name>
parents: 4422
diff changeset
119 struct rtm
5f768f1d37ad BSD: Simplify rtm usage
Roy Marples <roy@marples.name>
parents: 4422
diff changeset
120 {
5f768f1d37ad BSD: Simplify rtm usage
Roy Marples <roy@marples.name>
parents: 4422
diff changeset
121 struct rt_msghdr hdr;
5f768f1d37ad BSD: Simplify rtm usage
Roy Marples <roy@marples.name>
parents: 4422
diff changeset
122 char buffer[sizeof(struct sockaddr_storage) * RTAX_MAX];
5f768f1d37ad BSD: Simplify rtm usage
Roy Marples <roy@marples.name>
parents: 4422
diff changeset
123 };
5f768f1d37ad BSD: Simplify rtm usage
Roy Marples <roy@marples.name>
parents: 4422
diff changeset
124
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
125 int
5458
dd8347a0ea1c Adjust prior so that message is logged before starting dev
Roy Marples <roy@marples.name>
parents: 5376
diff changeset
126 os_init(void)
dd8347a0ea1c Adjust prior so that message is logged before starting dev
Roy Marples <roy@marples.name>
parents: 5376
diff changeset
127 {
dd8347a0ea1c Adjust prior so that message is logged before starting dev
Roy Marples <roy@marples.name>
parents: 5376
diff changeset
128 return 0;
dd8347a0ea1c Adjust prior so that message is logged before starting dev
Roy Marples <roy@marples.name>
parents: 5376
diff changeset
129 }
dd8347a0ea1c Adjust prior so that message is logged before starting dev
Roy Marples <roy@marples.name>
parents: 5376
diff changeset
130
dd8347a0ea1c Adjust prior so that message is logged before starting dev
Roy Marples <roy@marples.name>
parents: 5376
diff changeset
131 int
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
132 if_init(__unused struct interface *iface)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
133 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
134 /* BSD promotes secondary address by default */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
135 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
136 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
137
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
138 int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
139 if_conf(__unused struct interface *iface)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
140 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
141 /* No extra checks needed on BSD */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
142 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
143 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
144
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
145 int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
146 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
147 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
148 struct priv *priv;
4326
009a47703a99 BSD: don't listen to own route messages
Roy Marples <roy@marples.name>
parents: 4324
diff changeset
149 int n;
4018
09f02b15da2a Use RO_MSGFILER on NetBSD to filter route(4) messages.
Roy Marples <roy@marples.name>
parents: 4010
diff changeset
150 #if defined(RO_MSGFILTER) || defined(ROUTE_MSGFILTER)
09f02b15da2a Use RO_MSGFILER on NetBSD to filter route(4) messages.
Roy Marples <roy@marples.name>
parents: 4010
diff changeset
151 unsigned char msgfilter[] = {
09f02b15da2a Use RO_MSGFILER on NetBSD to filter route(4) messages.
Roy Marples <roy@marples.name>
parents: 4010
diff changeset
152 RTM_IFINFO,
4004
76a49ad4eb15 Move ROUTER_FILTER assignments to variable declaration.
Roy Marples <roy@marples.name>
parents: 4003
diff changeset
153 #ifdef RTM_IFANNOUNCE
4018
09f02b15da2a Use RO_MSGFILER on NetBSD to filter route(4) messages.
Roy Marples <roy@marples.name>
parents: 4010
diff changeset
154 RTM_IFANNOUNCE,
4004
76a49ad4eb15 Move ROUTER_FILTER assignments to variable declaration.
Roy Marples <roy@marples.name>
parents: 4003
diff changeset
155 #endif
4678
f61e4eeb8351 BSD: Handle RTM_MISS
Roy Marples <roy@marples.name>
parents: 4672
diff changeset
156 RTM_ADD, RTM_CHANGE, RTM_DELETE, RTM_MISS,
4004
76a49ad4eb15 Move ROUTER_FILTER assignments to variable declaration.
Roy Marples <roy@marples.name>
parents: 4003
diff changeset
157 #ifdef RTM_CHGADDR
4018
09f02b15da2a Use RO_MSGFILER on NetBSD to filter route(4) messages.
Roy Marples <roy@marples.name>
parents: 4010
diff changeset
158 RTM_CHGADDR,
4004
76a49ad4eb15 Move ROUTER_FILTER assignments to variable declaration.
Roy Marples <roy@marples.name>
parents: 4003
diff changeset
159 #endif
4018
09f02b15da2a Use RO_MSGFILER on NetBSD to filter route(4) messages.
Roy Marples <roy@marples.name>
parents: 4010
diff changeset
160 RTM_NEWADDR, RTM_DELADDR
09f02b15da2a Use RO_MSGFILER on NetBSD to filter route(4) messages.
Roy Marples <roy@marples.name>
parents: 4010
diff changeset
161 };
09f02b15da2a Use RO_MSGFILER on NetBSD to filter route(4) messages.
Roy Marples <roy@marples.name>
parents: 4010
diff changeset
162 #ifdef ROUTE_MSGFILTER
09f02b15da2a Use RO_MSGFILER on NetBSD to filter route(4) messages.
Roy Marples <roy@marples.name>
parents: 4010
diff changeset
163 unsigned int i, msgfilter_mask;
09f02b15da2a Use RO_MSGFILER on NetBSD to filter route(4) messages.
Roy Marples <roy@marples.name>
parents: 4010
diff changeset
164 #endif
4003
af7f37938597 if-bsd: support ROUTE_MSGFILTER socket option
Roy Marples <roy@marples.name>
parents: 3980
diff changeset
165 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
166
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
167 if ((priv = malloc(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
168 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
169 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
170
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
171 #ifdef INET6
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
172 priv->pf_inet6_fd = xsocket(PF_INET6, SOCK_DGRAM | SOCK_CLOEXEC, 0);
5321
41b99a2a12cf privsep: Limit rights generically rather than Capsicum specifc
Roy Marples <roy@marples.name>
parents: 5319
diff changeset
173 #ifdef PRIVSEP_RIGHTS
41b99a2a12cf privsep: Limit rights generically rather than Capsicum specifc
Roy Marples <roy@marples.name>
parents: 5319
diff changeset
174 if (IN_PRIVSEP(ctx))
41b99a2a12cf privsep: Limit rights generically rather than Capsicum specifc
Roy Marples <roy@marples.name>
parents: 5319
diff changeset
175 ps_rights_limit_ioctl(priv->pf_inet6_fd);
41b99a2a12cf privsep: Limit rights generically rather than Capsicum specifc
Roy Marples <roy@marples.name>
parents: 5319
diff changeset
176 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
177 /* Don't return an error so we at least work on kernels witout INET6
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
178 * even though we expect INET6 support.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
179 * We will fail noisily elsewhere anyway. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
180 #else
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
181 priv->pf_inet6_fd = -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
182 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
183
5231
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5207
diff changeset
184 ctx->link_fd = xsocket(PF_ROUTE, SOCK_RAW | SOCK_CXNB, AF_UNSPEC);
4046
9292d1ba3acf BSD: if failed to open PF_ROUTE socket, don't set filters.
Roy Marples <roy@marples.name>
parents: 4025
diff changeset
185 if (ctx->link_fd == -1)
9292d1ba3acf BSD: if failed to open PF_ROUTE socket, don't set filters.
Roy Marples <roy@marples.name>
parents: 4025
diff changeset
186 return -1;
4003
af7f37938597 if-bsd: support ROUTE_MSGFILTER socket option
Roy Marples <roy@marples.name>
parents: 3980
diff changeset
187
5231
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5207
diff changeset
188 #ifdef SO_RERROR
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5207
diff changeset
189 n = 1;
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5207
diff changeset
190 if (setsockopt(ctx->link_fd, SOL_SOCKET, SO_RERROR, &n,sizeof(n)) == -1)
5232
d09c879cc4d5 Fix compile for prior on NetBSD
Roy Marples <roy@marples.name>
parents: 5231
diff changeset
191 logerr("%s: SO_RERROR", __func__);
5231
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5207
diff changeset
192 #endif
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5207
diff changeset
193
4326
009a47703a99 BSD: don't listen to own route messages
Roy Marples <roy@marples.name>
parents: 4324
diff changeset
194 /* Ignore our own route(4) messages.
009a47703a99 BSD: don't listen to own route messages
Roy Marples <roy@marples.name>
parents: 4324
diff changeset
195 * Sadly there is no way of doing this for route(4) messages
009a47703a99 BSD: don't listen to own route messages
Roy Marples <roy@marples.name>
parents: 4324
diff changeset
196 * generated from addresses we add/delete. */
009a47703a99 BSD: don't listen to own route messages
Roy Marples <roy@marples.name>
parents: 4324
diff changeset
197 n = 0;
009a47703a99 BSD: don't listen to own route messages
Roy Marples <roy@marples.name>
parents: 4324
diff changeset
198 if (setsockopt(ctx->link_fd, SOL_SOCKET, SO_USELOOPBACK,
009a47703a99 BSD: don't listen to own route messages
Roy Marples <roy@marples.name>
parents: 4324
diff changeset
199 &n, sizeof(n)) == -1)
009a47703a99 BSD: don't listen to own route messages
Roy Marples <roy@marples.name>
parents: 4324
diff changeset
200 logerr("%s: SO_USELOOPBACK", __func__);
009a47703a99 BSD: don't listen to own route messages
Roy Marples <roy@marples.name>
parents: 4324
diff changeset
201
4018
09f02b15da2a Use RO_MSGFILER on NetBSD to filter route(4) messages.
Roy Marples <roy@marples.name>
parents: 4010
diff changeset
202 #if defined(RO_MSGFILTER)
09f02b15da2a Use RO_MSGFILER on NetBSD to filter route(4) messages.
Roy Marples <roy@marples.name>
parents: 4010
diff changeset
203 if (setsockopt(ctx->link_fd, PF_ROUTE, RO_MSGFILTER,
09f02b15da2a Use RO_MSGFILER on NetBSD to filter route(4) messages.
Roy Marples <roy@marples.name>
parents: 4010
diff changeset
204 &msgfilter, sizeof(msgfilter)) == -1)
09f02b15da2a Use RO_MSGFILER on NetBSD to filter route(4) messages.
Roy Marples <roy@marples.name>
parents: 4010
diff changeset
205 logerr(__func__);
09f02b15da2a Use RO_MSGFILER on NetBSD to filter route(4) messages.
Roy Marples <roy@marples.name>
parents: 4010
diff changeset
206 #elif defined(ROUTE_MSGFILTER)
09f02b15da2a Use RO_MSGFILER on NetBSD to filter route(4) messages.
Roy Marples <roy@marples.name>
parents: 4010
diff changeset
207 /* Convert the array into a bitmask. */
09f02b15da2a Use RO_MSGFILER on NetBSD to filter route(4) messages.
Roy Marples <roy@marples.name>
parents: 4010
diff changeset
208 msgfilter_mask = 0;
09f02b15da2a Use RO_MSGFILER on NetBSD to filter route(4) messages.
Roy Marples <roy@marples.name>
parents: 4010
diff changeset
209 for (i = 0; i < __arraycount(msgfilter); i++)
09f02b15da2a Use RO_MSGFILER on NetBSD to filter route(4) messages.
Roy Marples <roy@marples.name>
parents: 4010
diff changeset
210 msgfilter_mask |= ROUTE_FILTER(msgfilter[i]);
4003
af7f37938597 if-bsd: support ROUTE_MSGFILTER socket option
Roy Marples <roy@marples.name>
parents: 3980
diff changeset
211 if (setsockopt(ctx->link_fd, PF_ROUTE, ROUTE_MSGFILTER,
4018
09f02b15da2a Use RO_MSGFILER on NetBSD to filter route(4) messages.
Roy Marples <roy@marples.name>
parents: 4010
diff changeset
212 &msgfilter_mask, sizeof(msgfilter_mask)) == -1)
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 4004
diff changeset
213 logerr(__func__);
4614
41a47878e407 BSD: warn if kernel does not support route(4) filtering
Roy Marples <roy@marples.name>
parents: 4613
diff changeset
214 #else
4615
a4aff1c603f3 Fix prior.
Roy Marples <roy@marples.name>
parents: 4614
diff changeset
215 #warning kernel does not support route message filtering
4003
af7f37938597 if-bsd: support ROUTE_MSGFILTER socket option
Roy Marples <roy@marples.name>
parents: 3980
diff changeset
216 #endif
af7f37938597 if-bsd: support ROUTE_MSGFILTER socket option
Roy Marples <roy@marples.name>
parents: 3980
diff changeset
217
5492
9fe902232341 privsep: allow CAP_SETSOCKOPT for route(4) fd.
Roy Marples <roy@marples.name>
parents: 5486
diff changeset
218 #ifdef PRIVSEP_RIGHTS
5493
41d06921177b privsep: We need getsockopt as well as setsockopt on the link socket
Roy Marples <roy@marples.name>
parents: 5492
diff changeset
219 /* We need to getsockopt for SO_RCVBUF and
41d06921177b privsep: We need getsockopt as well as setsockopt on the link socket
Roy Marples <roy@marples.name>
parents: 5492
diff changeset
220 * setsockopt for RO_MISSFILTER. */
5492
9fe902232341 privsep: allow CAP_SETSOCKOPT for route(4) fd.
Roy Marples <roy@marples.name>
parents: 5486
diff changeset
221 if (IN_PRIVSEP(ctx))
5493
41d06921177b privsep: We need getsockopt as well as setsockopt on the link socket
Roy Marples <roy@marples.name>
parents: 5492
diff changeset
222 ps_rights_limit_fd_sockopt(ctx->link_fd);
5492
9fe902232341 privsep: allow CAP_SETSOCKOPT for route(4) fd.
Roy Marples <roy@marples.name>
parents: 5486
diff changeset
223 #endif
9fe902232341 privsep: allow CAP_SETSOCKOPT for route(4) fd.
Roy Marples <roy@marples.name>
parents: 5486
diff changeset
224
4046
9292d1ba3acf BSD: if failed to open PF_ROUTE socket, don't set filters.
Roy Marples <roy@marples.name>
parents: 4025
diff changeset
225 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
226 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
227
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
228 void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
229 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
230 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
231 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
232
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
233 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
234 if (priv->pf_inet6_fd != -1)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
235 close(priv->pf_inet6_fd);
4958
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
236 free(priv);
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
237 ctx->priv = NULL;
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
238 }
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
239
5056
f402f3ef7c23 DragonFlyBSD: Fix compile
Roy Marples <roy@marples.name>
parents: 5024
diff changeset
240 #if defined(SIOCALIFADDR) && defined(IFLR_ACTIVE) /*NetBSD */
4958
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
241 static int
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
242 if_ioctllink(struct dhcpcd_ctx *ctx, unsigned long req, void *data, size_t len)
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
243 {
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
244 int s;
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
245 int retval;
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
246
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
247 #ifdef PRIVSEP
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
248 if (ctx->options & DHCPCD_PRIVSEP)
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
249 return (int)ps_root_ioctllink(ctx, req, data, len);
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
250 #else
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
251 UNUSED(ctx);
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
252 #endif
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
253
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
254 s = socket(PF_LINK, SOCK_DGRAM, 0);
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
255 if (s == -1)
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
256 return -1;
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
257 retval = ioctl(s, req, data, len);
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
258 close(s);
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
259 return retval;
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
260 }
4961
cd7f5f9ed3cb FreeBSD: Support hardware address randomisation
Roy Marples <roy@marples.name>
parents: 4958
diff changeset
261 #endif
4958
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
262
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
263 int
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
264 if_setmac(struct interface *ifp, void *mac, uint8_t maclen)
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
265 {
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
266
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
267 if (ifp->hwlen != maclen) {
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
268 errno = EINVAL;
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
269 return -1;
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
270 }
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
271
5056
f402f3ef7c23 DragonFlyBSD: Fix compile
Roy Marples <roy@marples.name>
parents: 5024
diff changeset
272 #if defined(SIOCALIFADDR) && defined(IFLR_ACTIVE) /*NetBSD */
4961
cd7f5f9ed3cb FreeBSD: Support hardware address randomisation
Roy Marples <roy@marples.name>
parents: 4958
diff changeset
273 struct if_laddrreq iflr = { .flags = IFLR_ACTIVE };
cd7f5f9ed3cb FreeBSD: Support hardware address randomisation
Roy Marples <roy@marples.name>
parents: 4958
diff changeset
274 struct sockaddr_dl *sdl = satosdl(&iflr.addr);
cd7f5f9ed3cb FreeBSD: Support hardware address randomisation
Roy Marples <roy@marples.name>
parents: 4958
diff changeset
275 int retval;
cd7f5f9ed3cb FreeBSD: Support hardware address randomisation
Roy Marples <roy@marples.name>
parents: 4958
diff changeset
276
4958
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
277 strlcpy(iflr.iflr_name, ifp->name, sizeof(iflr.iflr_name));
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
278 sdl->sdl_family = AF_LINK;
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
279 sdl->sdl_len = sizeof(*sdl);
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
280 sdl->sdl_alen = maclen;
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
281 memcpy(LLADDR(sdl), mac, maclen);
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
282 retval = if_ioctllink(ifp->ctx, SIOCALIFADDR, &iflr, sizeof(iflr));
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
283
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
284 /* Try and remove the old address */
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
285 memcpy(LLADDR(sdl), ifp->hwaddr, ifp->hwlen);
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
286 if_ioctllink(ifp->ctx, SIOCDLIFADDR, &iflr, sizeof(iflr));
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
287
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
288 return retval;
4961
cd7f5f9ed3cb FreeBSD: Support hardware address randomisation
Roy Marples <roy@marples.name>
parents: 4958
diff changeset
289 #else
cd7f5f9ed3cb FreeBSD: Support hardware address randomisation
Roy Marples <roy@marples.name>
parents: 4958
diff changeset
290 struct ifreq ifr = {
cd7f5f9ed3cb FreeBSD: Support hardware address randomisation
Roy Marples <roy@marples.name>
parents: 4958
diff changeset
291 .ifr_addr.sa_family = AF_LINK,
cd7f5f9ed3cb FreeBSD: Support hardware address randomisation
Roy Marples <roy@marples.name>
parents: 4958
diff changeset
292 .ifr_addr.sa_len = maclen,
cd7f5f9ed3cb FreeBSD: Support hardware address randomisation
Roy Marples <roy@marples.name>
parents: 4958
diff changeset
293 };
cd7f5f9ed3cb FreeBSD: Support hardware address randomisation
Roy Marples <roy@marples.name>
parents: 4958
diff changeset
294
cd7f5f9ed3cb FreeBSD: Support hardware address randomisation
Roy Marples <roy@marples.name>
parents: 4958
diff changeset
295 strlcpy(ifr.ifr_name, ifp->name, sizeof(ifr.ifr_name));
cd7f5f9ed3cb FreeBSD: Support hardware address randomisation
Roy Marples <roy@marples.name>
parents: 4958
diff changeset
296 memcpy(ifr.ifr_addr.sa_data, mac, maclen);
cd7f5f9ed3cb FreeBSD: Support hardware address randomisation
Roy Marples <roy@marples.name>
parents: 4958
diff changeset
297 return if_ioctl(ifp->ctx, SIOCSIFLLADDR, &ifr, sizeof(ifr));
cd7f5f9ed3cb FreeBSD: Support hardware address randomisation
Roy Marples <roy@marples.name>
parents: 4958
diff changeset
298 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
299 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
300
4748
4cfd9d38741f BSD: Ignore interface groups as we would the interface name
Roy Marples <roy@marples.name>
parents: 4747
diff changeset
301 static bool
4cfd9d38741f BSD: Ignore interface groups as we would the interface name
Roy Marples <roy@marples.name>
parents: 4747
diff changeset
302 if_ignore1(const char *drvname)
4747
c995401f5572 if: Ignore TAP interfaces by default
Roy Marples <roy@marples.name>
parents: 4706
diff changeset
303 {
c995401f5572 if: Ignore TAP interfaces by default
Roy Marples <roy@marples.name>
parents: 4706
diff changeset
304 const char * const *p;
c995401f5572 if: Ignore TAP interfaces by default
Roy Marples <roy@marples.name>
parents: 4706
diff changeset
305
c995401f5572 if: Ignore TAP interfaces by default
Roy Marples <roy@marples.name>
parents: 4706
diff changeset
306 for (p = ifnames_ignore; *p; p++) {
c995401f5572 if: Ignore TAP interfaces by default
Roy Marples <roy@marples.name>
parents: 4706
diff changeset
307 if (strcmp(*p, drvname) == 0)
c995401f5572 if: Ignore TAP interfaces by default
Roy Marples <roy@marples.name>
parents: 4706
diff changeset
308 return true;
c995401f5572 if: Ignore TAP interfaces by default
Roy Marples <roy@marples.name>
parents: 4706
diff changeset
309 }
c995401f5572 if: Ignore TAP interfaces by default
Roy Marples <roy@marples.name>
parents: 4706
diff changeset
310 return false;
c995401f5572 if: Ignore TAP interfaces by default
Roy Marples <roy@marples.name>
parents: 4706
diff changeset
311 }
c995401f5572 if: Ignore TAP interfaces by default
Roy Marples <roy@marples.name>
parents: 4706
diff changeset
312
5310
0a6bde63868b privsep: Remove pledges inet and dns from the master process
Roy Marples <roy@marples.name>
parents: 5298
diff changeset
313 #ifdef SIOCGIFGROUP
0a6bde63868b privsep: Remove pledges inet and dns from the master process
Roy Marples <roy@marples.name>
parents: 5298
diff changeset
314 int
0a6bde63868b privsep: Remove pledges inet and dns from the master process
Roy Marples <roy@marples.name>
parents: 5298
diff changeset
315 if_ignoregroup(int s, const char *ifname)
0a6bde63868b privsep: Remove pledges inet and dns from the master process
Roy Marples <roy@marples.name>
parents: 5298
diff changeset
316 {
0a6bde63868b privsep: Remove pledges inet and dns from the master process
Roy Marples <roy@marples.name>
parents: 5298
diff changeset
317 struct ifgroupreq ifgr = { .ifgr_len = 0 };
0a6bde63868b privsep: Remove pledges inet and dns from the master process
Roy Marples <roy@marples.name>
parents: 5298
diff changeset
318 struct ifg_req *ifg;
0a6bde63868b privsep: Remove pledges inet and dns from the master process
Roy Marples <roy@marples.name>
parents: 5298
diff changeset
319 size_t ifg_len;
0a6bde63868b privsep: Remove pledges inet and dns from the master process
Roy Marples <roy@marples.name>
parents: 5298
diff changeset
320
0a6bde63868b privsep: Remove pledges inet and dns from the master process
Roy Marples <roy@marples.name>
parents: 5298
diff changeset
321 /* Sadly it is possible to remove the device name
0a6bde63868b privsep: Remove pledges inet and dns from the master process
Roy Marples <roy@marples.name>
parents: 5298
diff changeset
322 * from the interface groups, but hopefully this
0a6bde63868b privsep: Remove pledges inet and dns from the master process
Roy Marples <roy@marples.name>
parents: 5298
diff changeset
323 * will be very unlikely.... */
0a6bde63868b privsep: Remove pledges inet and dns from the master process
Roy Marples <roy@marples.name>
parents: 5298
diff changeset
324
0a6bde63868b privsep: Remove pledges inet and dns from the master process
Roy Marples <roy@marples.name>
parents: 5298
diff changeset
325 strlcpy(ifgr.ifgr_name, ifname, sizeof(ifgr.ifgr_name));
0a6bde63868b privsep: Remove pledges inet and dns from the master process
Roy Marples <roy@marples.name>
parents: 5298
diff changeset
326 if (ioctl(s, SIOCGIFGROUP, &ifgr) == -1 ||
0a6bde63868b privsep: Remove pledges inet and dns from the master process
Roy Marples <roy@marples.name>
parents: 5298
diff changeset
327 (ifgr.ifgr_groups = malloc(ifgr.ifgr_len)) == NULL ||
0a6bde63868b privsep: Remove pledges inet and dns from the master process
Roy Marples <roy@marples.name>
parents: 5298
diff changeset
328 ioctl(s, SIOCGIFGROUP, &ifgr) == -1)
0a6bde63868b privsep: Remove pledges inet and dns from the master process
Roy Marples <roy@marples.name>
parents: 5298
diff changeset
329 {
0a6bde63868b privsep: Remove pledges inet and dns from the master process
Roy Marples <roy@marples.name>
parents: 5298
diff changeset
330 logerr(__func__);
0a6bde63868b privsep: Remove pledges inet and dns from the master process
Roy Marples <roy@marples.name>
parents: 5298
diff changeset
331 return -1;
0a6bde63868b privsep: Remove pledges inet and dns from the master process
Roy Marples <roy@marples.name>
parents: 5298
diff changeset
332 }
0a6bde63868b privsep: Remove pledges inet and dns from the master process
Roy Marples <roy@marples.name>
parents: 5298
diff changeset
333
0a6bde63868b privsep: Remove pledges inet and dns from the master process
Roy Marples <roy@marples.name>
parents: 5298
diff changeset
334 for (ifg = ifgr.ifgr_groups, ifg_len = ifgr.ifgr_len;
0a6bde63868b privsep: Remove pledges inet and dns from the master process
Roy Marples <roy@marples.name>
parents: 5298
diff changeset
335 ifg && ifg_len >= sizeof(*ifg);
0a6bde63868b privsep: Remove pledges inet and dns from the master process
Roy Marples <roy@marples.name>
parents: 5298
diff changeset
336 ifg++, ifg_len -= sizeof(*ifg))
0a6bde63868b privsep: Remove pledges inet and dns from the master process
Roy Marples <roy@marples.name>
parents: 5298
diff changeset
337 {
0a6bde63868b privsep: Remove pledges inet and dns from the master process
Roy Marples <roy@marples.name>
parents: 5298
diff changeset
338 if (if_ignore1(ifg->ifgrq_group))
0a6bde63868b privsep: Remove pledges inet and dns from the master process
Roy Marples <roy@marples.name>
parents: 5298
diff changeset
339 return 1;
0a6bde63868b privsep: Remove pledges inet and dns from the master process
Roy Marples <roy@marples.name>
parents: 5298
diff changeset
340 }
0a6bde63868b privsep: Remove pledges inet and dns from the master process
Roy Marples <roy@marples.name>
parents: 5298
diff changeset
341 return 0;
0a6bde63868b privsep: Remove pledges inet and dns from the master process
Roy Marples <roy@marples.name>
parents: 5298
diff changeset
342 }
0a6bde63868b privsep: Remove pledges inet and dns from the master process
Roy Marples <roy@marples.name>
parents: 5298
diff changeset
343 #endif
0a6bde63868b privsep: Remove pledges inet and dns from the master process
Roy Marples <roy@marples.name>
parents: 5298
diff changeset
344
4748
4cfd9d38741f BSD: Ignore interface groups as we would the interface name
Roy Marples <roy@marples.name>
parents: 4747
diff changeset
345 bool
4cfd9d38741f BSD: Ignore interface groups as we would the interface name
Roy Marples <roy@marples.name>
parents: 4747
diff changeset
346 if_ignore(struct dhcpcd_ctx *ctx, const char *ifname)
4cfd9d38741f BSD: Ignore interface groups as we would the interface name
Roy Marples <roy@marples.name>
parents: 4747
diff changeset
347 {
4cfd9d38741f BSD: Ignore interface groups as we would the interface name
Roy Marples <roy@marples.name>
parents: 4747
diff changeset
348 struct if_spec spec;
4cfd9d38741f BSD: Ignore interface groups as we would the interface name
Roy Marples <roy@marples.name>
parents: 4747
diff changeset
349
4cfd9d38741f BSD: Ignore interface groups as we would the interface name
Roy Marples <roy@marples.name>
parents: 4747
diff changeset
350 if (if_nametospec(ifname, &spec) != 0)
4cfd9d38741f BSD: Ignore interface groups as we would the interface name
Roy Marples <roy@marples.name>
parents: 4747
diff changeset
351 return false;
4cfd9d38741f BSD: Ignore interface groups as we would the interface name
Roy Marples <roy@marples.name>
parents: 4747
diff changeset
352
4cfd9d38741f BSD: Ignore interface groups as we would the interface name
Roy Marples <roy@marples.name>
parents: 4747
diff changeset
353 if (if_ignore1(spec.drvname))
4cfd9d38741f BSD: Ignore interface groups as we would the interface name
Roy Marples <roy@marples.name>
parents: 4747
diff changeset
354 return true;
4cfd9d38741f BSD: Ignore interface groups as we would the interface name
Roy Marples <roy@marples.name>
parents: 4747
diff changeset
355
4cfd9d38741f BSD: Ignore interface groups as we would the interface name
Roy Marples <roy@marples.name>
parents: 4747
diff changeset
356 #ifdef SIOCGIFGROUP
5310
0a6bde63868b privsep: Remove pledges inet and dns from the master process
Roy Marples <roy@marples.name>
parents: 5298
diff changeset
357 #if defined(PRIVSEP) && defined(HAVE_PLEDGE)
0a6bde63868b privsep: Remove pledges inet and dns from the master process
Roy Marples <roy@marples.name>
parents: 5298
diff changeset
358 if (IN_PRIVSEP(ctx))
0a6bde63868b privsep: Remove pledges inet and dns from the master process
Roy Marples <roy@marples.name>
parents: 5298
diff changeset
359 return ps_root_ifignoregroup(ctx, ifname) == 1 ? true : false;
5204
47f18579daae privsep: Implement pledge(2) support as found on OpenBSD
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
360 #endif
5310
0a6bde63868b privsep: Remove pledges inet and dns from the master process
Roy Marples <roy@marples.name>
parents: 5298
diff changeset
361 else
0a6bde63868b privsep: Remove pledges inet and dns from the master process
Roy Marples <roy@marples.name>
parents: 5298
diff changeset
362 return if_ignoregroup(ctx->pf_inet_fd, ifname) == 1 ?
0a6bde63868b privsep: Remove pledges inet and dns from the master process
Roy Marples <roy@marples.name>
parents: 5298
diff changeset
363 true : false;
4748
4cfd9d38741f BSD: Ignore interface groups as we would the interface name
Roy Marples <roy@marples.name>
parents: 4747
diff changeset
364 #else
4cfd9d38741f BSD: Ignore interface groups as we would the interface name
Roy Marples <roy@marples.name>
parents: 4747
diff changeset
365 UNUSED(ctx);
5310
0a6bde63868b privsep: Remove pledges inet and dns from the master process
Roy Marples <roy@marples.name>
parents: 5298
diff changeset
366 return false;
4748
4cfd9d38741f BSD: Ignore interface groups as we would the interface name
Roy Marples <roy@marples.name>
parents: 4747
diff changeset
367 #endif
4cfd9d38741f BSD: Ignore interface groups as we would the interface name
Roy Marples <roy@marples.name>
parents: 4747
diff changeset
368 }
4cfd9d38741f BSD: Ignore interface groups as we would the interface name
Roy Marples <roy@marples.name>
parents: 4747
diff changeset
369
5482
7f7968235543 BSD: NetBSD is the odd man out with SIOCGIFDATA
Roy Marples <roy@marples.name>
parents: 5480
diff changeset
370 static int if_indirect_ioctl(struct dhcpcd_ctx *ctx,
7f7968235543 BSD: NetBSD is the odd man out with SIOCGIFDATA
Roy Marples <roy@marples.name>
parents: 5480
diff changeset
371 const char *ifname, unsigned long cmd, void *data, size_t len)
7f7968235543 BSD: NetBSD is the odd man out with SIOCGIFDATA
Roy Marples <roy@marples.name>
parents: 5480
diff changeset
372 {
7f7968235543 BSD: NetBSD is the odd man out with SIOCGIFDATA
Roy Marples <roy@marples.name>
parents: 5480
diff changeset
373 struct ifreq ifr = { .ifr_flags = 0 };
7f7968235543 BSD: NetBSD is the odd man out with SIOCGIFDATA
Roy Marples <roy@marples.name>
parents: 5480
diff changeset
374
5483
f137886e6211 FreeBSD: Anticipate SIOCGIFDATA not working in Capsicum
Roy Marples <roy@marples.name>
parents: 5482
diff changeset
375 #if defined(PRIVSEP) && (defined(HAVE_CAPSICUM) || defined(HAVE_PLEDGE))
5482
7f7968235543 BSD: NetBSD is the odd man out with SIOCGIFDATA
Roy Marples <roy@marples.name>
parents: 5480
diff changeset
376 if (IN_PRIVSEP(ctx))
7f7968235543 BSD: NetBSD is the odd man out with SIOCGIFDATA
Roy Marples <roy@marples.name>
parents: 5480
diff changeset
377 return (int)ps_root_indirectioctl(ctx, cmd, ifname, data, len);
7f7968235543 BSD: NetBSD is the odd man out with SIOCGIFDATA
Roy Marples <roy@marples.name>
parents: 5480
diff changeset
378 #else
7f7968235543 BSD: NetBSD is the odd man out with SIOCGIFDATA
Roy Marples <roy@marples.name>
parents: 5480
diff changeset
379 UNUSED(len);
7f7968235543 BSD: NetBSD is the odd man out with SIOCGIFDATA
Roy Marples <roy@marples.name>
parents: 5480
diff changeset
380 #endif
7f7968235543 BSD: NetBSD is the odd man out with SIOCGIFDATA
Roy Marples <roy@marples.name>
parents: 5480
diff changeset
381
7f7968235543 BSD: NetBSD is the odd man out with SIOCGIFDATA
Roy Marples <roy@marples.name>
parents: 5480
diff changeset
382 strlcpy(ifr.ifr_name, ifname, IFNAMSIZ);
7f7968235543 BSD: NetBSD is the odd man out with SIOCGIFDATA
Roy Marples <roy@marples.name>
parents: 5480
diff changeset
383 ifr.ifr_data = data;
7f7968235543 BSD: NetBSD is the odd man out with SIOCGIFDATA
Roy Marples <roy@marples.name>
parents: 5480
diff changeset
384 return ioctl(ctx->pf_inet_fd, cmd, &ifr);
7f7968235543 BSD: NetBSD is the odd man out with SIOCGIFDATA
Roy Marples <roy@marples.name>
parents: 5480
diff changeset
385 }
7f7968235543 BSD: NetBSD is the odd man out with SIOCGIFDATA
Roy Marples <roy@marples.name>
parents: 5480
diff changeset
386
5486
8e2b8ce8c972 BSD: struct if_data->ifi_link_state is the single source of truth
Roy Marples <roy@marples.name>
parents: 5485
diff changeset
387 int
5499
6a2da5651841 dhcpcd: Simplify the link handling even more
Roy Marples <roy@marples.name>
parents: 5493
diff changeset
388 if_carrier(struct interface *ifp, const void *ifadata)
4495
74aa6ad52b0d BSD: RTM_IFINFO is not emitted for all interfaces past unknown link
Roy Marples <roy@marples.name>
parents: 4483
diff changeset
389 {
5486
8e2b8ce8c972 BSD: struct if_data->ifi_link_state is the single source of truth
Roy Marples <roy@marples.name>
parents: 5485
diff changeset
390 const struct if_data *ifi = ifadata;
5482
7f7968235543 BSD: NetBSD is the odd man out with SIOCGIFDATA
Roy Marples <roy@marples.name>
parents: 5480
diff changeset
391
5486
8e2b8ce8c972 BSD: struct if_data->ifi_link_state is the single source of truth
Roy Marples <roy@marples.name>
parents: 5485
diff changeset
392 /*
8e2b8ce8c972 BSD: struct if_data->ifi_link_state is the single source of truth
Roy Marples <roy@marples.name>
parents: 5485
diff changeset
393 * Every BSD returns this and it is the sole source of truth.
8e2b8ce8c972 BSD: struct if_data->ifi_link_state is the single source of truth
Roy Marples <roy@marples.name>
parents: 5485
diff changeset
394 * Not all BSD's support SIOCGIFDATA and not all interfaces
8e2b8ce8c972 BSD: struct if_data->ifi_link_state is the single source of truth
Roy Marples <roy@marples.name>
parents: 5485
diff changeset
395 * support SIOCGIFMEDIA.
8e2b8ce8c972 BSD: struct if_data->ifi_link_state is the single source of truth
Roy Marples <roy@marples.name>
parents: 5485
diff changeset
396 */
8e2b8ce8c972 BSD: struct if_data->ifi_link_state is the single source of truth
Roy Marples <roy@marples.name>
parents: 5485
diff changeset
397 assert(ifadata != NULL);
5476
4f7691185a75 BSD: Use SIOCGIFDATA if no media support and no ifa_data
Roy Marples <roy@marples.name>
parents: 5475
diff changeset
398
5486
8e2b8ce8c972 BSD: struct if_data->ifi_link_state is the single source of truth
Roy Marples <roy@marples.name>
parents: 5485
diff changeset
399 if (ifi->ifi_link_state >= LINK_STATE_UP)
5476
4f7691185a75 BSD: Use SIOCGIFDATA if no media support and no ifa_data
Roy Marples <roy@marples.name>
parents: 5475
diff changeset
400 return LINK_UP;
5499
6a2da5651841 dhcpcd: Simplify the link handling even more
Roy Marples <roy@marples.name>
parents: 5493
diff changeset
401 if (ifi->ifi_link_state == LINK_STATE_UNKNOWN) {
6a2da5651841 dhcpcd: Simplify the link handling even more
Roy Marples <roy@marples.name>
parents: 5493
diff changeset
402 /*
6a2da5651841 dhcpcd: Simplify the link handling even more
Roy Marples <roy@marples.name>
parents: 5493
diff changeset
403 * Work around net80211 issues in some BSDs.
6a2da5651841 dhcpcd: Simplify the link handling even more
Roy Marples <roy@marples.name>
parents: 5493
diff changeset
404 * Wireless MUST support link state change.
6a2da5651841 dhcpcd: Simplify the link handling even more
Roy Marples <roy@marples.name>
parents: 5493
diff changeset
405 */
6a2da5651841 dhcpcd: Simplify the link handling even more
Roy Marples <roy@marples.name>
parents: 5493
diff changeset
406 if (ifp->wireless)
6a2da5651841 dhcpcd: Simplify the link handling even more
Roy Marples <roy@marples.name>
parents: 5493
diff changeset
407 return LINK_DOWN;
5486
8e2b8ce8c972 BSD: struct if_data->ifi_link_state is the single source of truth
Roy Marples <roy@marples.name>
parents: 5485
diff changeset
408 return LINK_UNKNOWN;
5499
6a2da5651841 dhcpcd: Simplify the link handling even more
Roy Marples <roy@marples.name>
parents: 5493
diff changeset
409 }
5486
8e2b8ce8c972 BSD: struct if_data->ifi_link_state is the single source of truth
Roy Marples <roy@marples.name>
parents: 5485
diff changeset
410 return LINK_DOWN;
5475
8dcd62252f2d BSD: Detect initial link state in ifa_data
Roy Marples <roy@marples.name>
parents: 5458
diff changeset
411 }
8dcd62252f2d BSD: Detect initial link state in ifa_data
Roy Marples <roy@marples.name>
parents: 5458
diff changeset
412
5557
e65d193a1960 Linux: Support wireless IP roaming
Roy Marples <roy@marples.name>
parents: 5499
diff changeset
413 bool
e65d193a1960 Linux: Support wireless IP roaming
Roy Marples <roy@marples.name>
parents: 5499
diff changeset
414 if_roaming(__unused struct interface *ifp)
e65d193a1960 Linux: Support wireless IP roaming
Roy Marples <roy@marples.name>
parents: 5499
diff changeset
415 {
e65d193a1960 Linux: Support wireless IP roaming
Roy Marples <roy@marples.name>
parents: 5499
diff changeset
416
e65d193a1960 Linux: Support wireless IP roaming
Roy Marples <roy@marples.name>
parents: 5499
diff changeset
417 return false;
e65d193a1960 Linux: Support wireless IP roaming
Roy Marples <roy@marples.name>
parents: 5499
diff changeset
418 }
e65d193a1960 Linux: Support wireless IP roaming
Roy Marples <roy@marples.name>
parents: 5499
diff changeset
419
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
420 static void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
421 if_linkaddr(struct sockaddr_dl *sdl, 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
422 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
423
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
424 memset(sdl, 0, sizeof(*sdl));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
425 sdl->sdl_family = AF_LINK;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
426 sdl->sdl_len = sizeof(*sdl);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
427 sdl->sdl_nlen = sdl->sdl_alen = sdl->sdl_slen = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
428 sdl->sdl_index = (unsigned short)ifp->index;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
429 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
430
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
431 static int
5204
47f18579daae privsep: Implement pledge(2) support as found on OpenBSD
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
432 if_getssid1(struct dhcpcd_ctx *ctx, const char *ifname, void *ssid)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
433 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
434 int retval = -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
435 #if defined(SIOCG80211NWID)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
436 struct ieee80211_nwid nwid;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
437 #elif defined(IEEE80211_IOC_SSID)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
438 struct ieee80211req ireq;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
439 char nwid[IEEE80211_NWID_LEN];
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
440 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
441
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
442 #if defined(SIOCG80211NWID) /* NetBSD */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
443 memset(&nwid, 0, sizeof(nwid));
5204
47f18579daae privsep: Implement pledge(2) support as found on OpenBSD
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
444 if (if_indirect_ioctl(ctx, ifname, SIOCG80211NWID,
47f18579daae privsep: Implement pledge(2) support as found on OpenBSD
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
445 &nwid, sizeof(nwid)) == 0)
47f18579daae privsep: Implement pledge(2) support as found on OpenBSD
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
446 {
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
447 if (ssid == NULL)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
448 retval = nwid.i_len;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
449 else if (nwid.i_len > IF_SSIDLEN)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
450 errno = ENOBUFS;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
451 else {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
452 retval = nwid.i_len;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
453 memcpy(ssid, nwid.i_nwid, nwid.i_len);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
454 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
455 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
456 #elif defined(IEEE80211_IOC_SSID) /* FreeBSD */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
457 memset(&ireq, 0, sizeof(ireq));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
458 strlcpy(ireq.i_name, ifname, sizeof(ireq.i_name));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
459 ireq.i_type = IEEE80211_IOC_SSID;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
460 ireq.i_val = -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
461 memset(nwid, 0, sizeof(nwid));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
462 ireq.i_data = &nwid;
5204
47f18579daae privsep: Implement pledge(2) support as found on OpenBSD
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
463 if (ioctl(ctx->pf_inet_fd, SIOCG80211, &ireq) == 0) {
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
464 if (ssid == NULL)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
465 retval = ireq.i_len;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
466 else if (ireq.i_len > IF_SSIDLEN)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
467 errno = ENOBUFS;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
468 else {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
469 retval = ireq.i_len;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
470 memcpy(ssid, nwid, ireq.i_len);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
471 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
472 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
473 #else
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
474 errno = ENOSYS;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
475 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
476
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
477 return retval;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
478 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
479
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
480 int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
481 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
482 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
483 int r;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
484
5204
47f18579daae privsep: Implement pledge(2) support as found on OpenBSD
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
485 r = if_getssid1(ifp->ctx, ifp->name, ifp->ssid);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
486 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
487 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
488 else
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
489 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
490 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
491 return r;
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
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
494 /*
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
495 * FreeBSD allows for Virtual Access Points
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
496 * We need to check if the interface is a Virtual Interface Master
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
497 * and if so, don't use it.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
498 * This check is made by virtue of being a IEEE80211 device but
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
499 * returning the SSID gives an error.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
500 */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
501 int
5204
47f18579daae privsep: Implement pledge(2) support as found on OpenBSD
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
502 if_vimaster(struct dhcpcd_ctx *ctx, 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
503 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
504 int r;
5205
cac489d5a8fa privsep: Fix prior for non pledge systems
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
505 struct ifmediareq ifmr = { .ifm_active = 0 };
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
506
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
507 strlcpy(ifmr.ifm_name, ifname, sizeof(ifmr.ifm_name));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
508 r = ioctl(ctx->pf_inet_fd, SIOCGIFMEDIA, &ifmr);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
509 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
510 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
511 if (ifmr.ifm_status & IFM_AVALID &&
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
512 IFM_TYPE(ifmr.ifm_active) == IFM_IEEE80211)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
513 {
5204
47f18579daae privsep: Implement pledge(2) support as found on OpenBSD
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
514 if (if_getssid1(ctx, ifname, 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
515 return 1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
516 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
517 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
518 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
519
4052
08038b46c0f5 Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents: 4049
diff changeset
520 unsigned short
08038b46c0f5 Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents: 4049
diff changeset
521 if_vlanid(const struct interface *ifp)
08038b46c0f5 Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents: 4049
diff changeset
522 {
08038b46c0f5 Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents: 4049
diff changeset
523 #ifdef SIOCGETVLAN
5204
47f18579daae privsep: Implement pledge(2) support as found on OpenBSD
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
524 struct vlanreq vlr = { .vlr_tag = 0 };
4052
08038b46c0f5 Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents: 4049
diff changeset
525
5204
47f18579daae privsep: Implement pledge(2) support as found on OpenBSD
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
526 if (if_indirect_ioctl(ifp->ctx, ifp->name, SIOCGETVLAN,
47f18579daae privsep: Implement pledge(2) support as found on OpenBSD
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
527 &vlr, sizeof(vlr)) != 0)
4052
08038b46c0f5 Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents: 4049
diff changeset
528 return 0; /* 0 means no VLANID */
08038b46c0f5 Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents: 4049
diff changeset
529 return vlr.vlr_tag;
08038b46c0f5 Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents: 4049
diff changeset
530 #elif defined(SIOCGVNETID)
5204
47f18579daae privsep: Implement pledge(2) support as found on OpenBSD
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
531 struct ifreq ifr = { .ifr_vnetid = 0 };
4052
08038b46c0f5 Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents: 4049
diff changeset
532
08038b46c0f5 Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents: 4049
diff changeset
533 strlcpy(ifr.ifr_name, ifp->name, sizeof(ifr.ifr_name));
08038b46c0f5 Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents: 4049
diff changeset
534 if (ioctl(ifp->ctx->pf_inet_fd, SIOCGVNETID, &ifr) != 0)
08038b46c0f5 Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents: 4049
diff changeset
535 return 0; /* 0 means no VLANID */
08038b46c0f5 Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents: 4049
diff changeset
536 return ifr.ifr_vnetid;
08038b46c0f5 Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents: 4049
diff changeset
537 #else
08038b46c0f5 Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents: 4049
diff changeset
538 UNUSED(ifp);
08038b46c0f5 Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents: 4049
diff changeset
539 return 0; /* 0 means no VLANID */
08038b46c0f5 Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents: 4049
diff changeset
540 #endif
08038b46c0f5 Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents: 4049
diff changeset
541 }
08038b46c0f5 Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents: 4049
diff changeset
542
4502
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
543 static int
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
544 get_addrs(int type, const void *data, size_t data_len,
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
545 const struct sockaddr **sa)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
546 {
4502
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
547 const char *cp, *ep;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
548 int i;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
549
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
550 cp = data;
4502
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
551 ep = cp + data_len;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
552 for (i = 0; i < RTAX_MAX; i++) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
553 if (type & (1 << i)) {
4502
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
554 if (cp >= ep) {
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
555 errno = EINVAL;
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
556 return -1;
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
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 sa[i] = (const struct sockaddr *)cp;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
559 RT_ADVANCE(cp, sa[i]);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
560 } else
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
561 sa[i] = NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
562 }
4502
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
563
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
564 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
565 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
566
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
567 static struct interface *
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
568 if_findsdl(struct dhcpcd_ctx *ctx, const struct sockaddr_dl *sdl)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
569 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
570
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
571 if (sdl->sdl_index)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
572 return if_findindex(ctx->ifaces, sdl->sdl_index);
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 (sdl->sdl_nlen) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
575 char ifname[IF_NAMESIZE];
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
576
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
577 memcpy(ifname, sdl->sdl_data, sdl->sdl_nlen);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
578 ifname[sdl->sdl_nlen] = '\0';
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
579 return if_find(ctx->ifaces, ifname);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
580 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
581 if (sdl->sdl_alen) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
582 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
583
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
584 TAILQ_FOREACH(ifp, ctx->ifaces, next) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
585 if (ifp->hwlen == sdl->sdl_alen &&
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
586 memcmp(ifp->hwaddr,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
587 sdl->sdl_data, sdl->sdl_alen) == 0)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
588 return ifp;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
589 }
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
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
592 errno = ENOENT;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
593 return NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
594 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
595
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
596 static struct interface *
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
597 if_findsa(struct dhcpcd_ctx *ctx, const 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
598 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
599 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
600 errno = EINVAL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
601 return NULL;
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
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
604 switch (sa->sa_family) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
605 case AF_LINK:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
606 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
607 const struct sockaddr_dl *sdl;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
608
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
609 sdl = (const void *)sa;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
610 return if_findsdl(ctx, sdl);
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 #ifdef INET
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
613 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
614 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
615 const struct sockaddr_in *sin;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
616 struct ipv4_addr *ia;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
617
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
618 sin = (const void *)sa;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
619 if ((ia = ipv4_findmaskaddr(ctx, &sin->sin_addr)))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
620 return ia->iface;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
621 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
622 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
623 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
624 #ifdef INET6
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
625 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
626 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
627 const struct sockaddr_in6 *sin;
4422
344851420e71 BSD: Fix detecting the interface for scoped routes
Roy Marples <roy@marples.name>
parents: 4421
diff changeset
628 unsigned int scope;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
629 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
630
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
631 sin = (const void *)sa;
5195
45226e01fbdd inet6: Move BSD get/set scope function to ipv6 for general use
Roy Marples <roy@marples.name>
parents: 5177
diff changeset
632 scope = ipv6_getscope(sin);
4422
344851420e71 BSD: Fix detecting the interface for scoped routes
Roy Marples <roy@marples.name>
parents: 4421
diff changeset
633 if (scope != 0)
344851420e71 BSD: Fix detecting the interface for scoped routes
Roy Marples <roy@marples.name>
parents: 4421
diff changeset
634 return if_findindex(ctx->ifaces, scope);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
635 if ((ia = ipv6_findmaskaddr(ctx, &sin->sin6_addr)))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
636 return ia->iface;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
637 break;
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 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
640 default:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
641 errno = EAFNOSUPPORT;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
642 return NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
643 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
644
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
645 errno = ENOENT;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
646 return NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
647 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
648
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
649 static void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
650 if_copysa(struct sockaddr *dst, const struct sockaddr *src)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
651 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
652
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
653 assert(dst != NULL);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
654 assert(src != NULL);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
655
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
656 memcpy(dst, src, src->sa_len);
4119
fcddf3690162 Fix compile without INET6.
Roy Marples <roy@marples.name>
parents: 4118
diff changeset
657 #if defined(INET6) && defined(__KAME__)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
658 if (dst->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
659 struct in6_addr *in6;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
660
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
661 in6 = &satosin6(dst)->sin6_addr;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
662 if (IN6_IS_ADDR_LINKLOCAL(in6))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
663 in6->s6_addr[2] = in6->s6_addr[3] = '\0';
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 #endif
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
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
668 int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
669 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
670 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
671 struct dhcpcd_ctx *ctx;
4437
5f768f1d37ad BSD: Simplify rtm usage
Roy Marples <roy@marples.name>
parents: 4422
diff changeset
672 struct rtm rtmsg;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
673 struct rt_msghdr *rtm = &rtmsg.hdr;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
674 char *bp = rtmsg.buffer;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
675 struct sockaddr_dl sdl;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
676 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
677
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
678 assert(rt != NULL);
4390
1ac28c1a47b0 OpenBSD: add some asserts
Roy Marples <roy@marples.name>
parents: 4371
diff changeset
679 assert(rt->rt_ifp != NULL);
1ac28c1a47b0 OpenBSD: add some asserts
Roy Marples <roy@marples.name>
parents: 4371
diff changeset
680 assert(rt->rt_ifp->ctx != NULL);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
681 ctx = rt->rt_ifp->ctx;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
682
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
683 #define ADDSA(sa) do { \
3980
503ec96b63bc Initialise the whole rt msg buffer to avoid valgrind errors.
Roy Marples <roy@marples.name>
parents: 3967
diff changeset
684 memcpy(bp, (sa), (sa)->sa_len); \
503ec96b63bc Initialise the whole rt msg buffer to avoid valgrind errors.
Roy Marples <roy@marples.name>
parents: 3967
diff changeset
685 bp += RT_ROUNDUP((sa)->sa_len); \
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
686 } while (0 /* CONSTCOND */)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
687
3980
503ec96b63bc Initialise the whole rt msg buffer to avoid valgrind errors.
Roy Marples <roy@marples.name>
parents: 3967
diff changeset
688 memset(&rtmsg, 0, sizeof(rtmsg));
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
689 rtm->rtm_version = RTM_VERSION;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
690 rtm->rtm_type = cmd;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
691 #ifdef __OpenBSD__
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
692 rtm->rtm_pid = getpid();
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
693 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
694 rtm->rtm_seq = ++ctx->seq;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
695 rtm->rtm_flags = (int)rt->rt_flags;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
696 rtm->rtm_addrs = RTA_DST;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
697 #ifdef RTF_PINNED
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
698 if (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
699 rtm->rtm_flags |= RTF_PINNED;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
700 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
701
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
702 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
703
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
704 if (cmd == RTM_ADD || cmd == RTM_CHANGE) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
705 bool netmask_bcast = sa_is_allones(&rt->rt_netmask);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
706
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
707 rtm->rtm_flags |= RTF_UP;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
708 rtm->rtm_addrs |= RTA_GATEWAY;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
709 if (!(rtm->rtm_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
710 !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
711 {
4256
4cc5f8d94727 BSD: move the interface hint up the stack
Roy Marples <roy@marples.name>
parents: 4254
diff changeset
712 rtm->rtm_index = (unsigned short)rt->rt_ifp->index;
4354
2fdc1a515676 FreeBSD: avoid kernel panics when adding on-link IPv6 routes
Roy Marples <roy@marples.name>
parents: 4352
diff changeset
713 /*
2fdc1a515676 FreeBSD: avoid kernel panics when adding on-link IPv6 routes
Roy Marples <roy@marples.name>
parents: 4352
diff changeset
714 * OpenBSD rejects the message for on-link routes.
2fdc1a515676 FreeBSD: avoid kernel panics when adding on-link IPv6 routes
Roy Marples <roy@marples.name>
parents: 4352
diff changeset
715 * FreeBSD-12 kernel apparently panics.
2fdc1a515676 FreeBSD: avoid kernel panics when adding on-link IPv6 routes
Roy Marples <roy@marples.name>
parents: 4352
diff changeset
716 * I can't replicate the panic, but better safe than sorry!
2fdc1a515676 FreeBSD: avoid kernel panics when adding on-link IPv6 routes
Roy Marples <roy@marples.name>
parents: 4352
diff changeset
717 * https://roy.marples.name/archives/dhcpcd-discuss/0002286.html
2fdc1a515676 FreeBSD: avoid kernel panics when adding on-link IPv6 routes
Roy Marples <roy@marples.name>
parents: 4352
diff changeset
718 *
2fdc1a515676 FreeBSD: avoid kernel panics when adding on-link IPv6 routes
Roy Marples <roy@marples.name>
parents: 4352
diff changeset
719 * Neither OS currently allows IPv6 address sharing anyway, so let's
2fdc1a515676 FreeBSD: avoid kernel panics when adding on-link IPv6 routes
Roy Marples <roy@marples.name>
parents: 4352
diff changeset
720 * try to encourage someone to fix that by logging a waring during compile.
2fdc1a515676 FreeBSD: avoid kernel panics when adding on-link IPv6 routes
Roy Marples <roy@marples.name>
parents: 4352
diff changeset
721 */
2fdc1a515676 FreeBSD: avoid kernel panics when adding on-link IPv6 routes
Roy Marples <roy@marples.name>
parents: 4352
diff changeset
722 #if defined(__FreeBSD__) || defined(__OpenBSD__)
4604
1224950f9862 BSD: Warn when kernel does not support sending ND6 advertisements
Roy Marples <roy@marples.name>
parents: 4602
diff changeset
723 #warning kernel does not allow IPv6 address sharing
4329
9eca323ed30a Fix prior logic.Doh!
Roy Marples <roy@marples.name>
parents: 4328
diff changeset
724 if (!gateway_unspec || rt->rt_dest.sa_family!=AF_INET6)
4328
6f8187999803 BSD: Always set RTA_IFP for routes
Roy Marples <roy@marples.name>
parents: 4327
diff changeset
725 #endif
6f8187999803 BSD: Always set RTA_IFP for routes
Roy Marples <roy@marples.name>
parents: 4327
diff changeset
726 rtm->rtm_addrs |= RTA_IFP;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
727 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
728 rtm->rtm_addrs |= RTA_IFA;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
729 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
730 if (netmask_bcast)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
731 rtm->rtm_flags |= RTF_HOST;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
732 /* Network routes are cloning or connected if supported.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
733 * All other routes are static. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
734 if (gateway_unspec) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
735 #ifdef RTF_CLONING
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
736 rtm->rtm_flags |= RTF_CLONING;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
737 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
738 #ifdef RTF_CONNECTED
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
739 rtm->rtm_flags |= RTF_CONNECTED;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
740 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
741 #ifdef RTP_CONNECTED
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
742 rtm->rtm_priority = RTP_CONNECTED;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
743 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
744 #ifdef RTF_CLONING
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
745 if (netmask_bcast) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
746 /*
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
747 * We add a cloning network route for a single
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
748 * host. Traffic to the host will generate a
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
749 * cloned route and the hardware address will
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
750 * resolve correctly.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
751 * It might be more correct to use RTF_HOST
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
752 * instead of RTF_CLONING, and that does work,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
753 * but some OS generate an arp warning
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
754 * diagnostic which we don't want to do.
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 rtm->rtm_flags &= ~RTF_HOST;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
757 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
758 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
759 } else
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
760 rtm->rtm_flags |= RTF_GATEWAY;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
761
5356
39a8d5dfe695 BSD: Mark routes as static only from static config
Roy Marples <roy@marples.name>
parents: 5355
diff changeset
762 if (rt->rt_dflags & RTDF_STATIC)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
763 rtm->rtm_flags |= RTF_STATIC;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
764
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
765 if (rt->rt_mtu != 0) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
766 rtm->rtm_inits |= RTV_MTU;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
767 rtm->rtm_rmx.rmx_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
768 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
769 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
770
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
771 if (!(rtm->rtm_flags & RTF_HOST))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
772 rtm->rtm_addrs |= RTA_NETMASK;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
773
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
774 if_linkaddr(&sdl, rt->rt_ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
775
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
776 ADDSA(&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
777
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
778 if (rtm->rtm_addrs & RTA_GATEWAY) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
779 if (gateway_unspec)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
780 ADDSA((struct sockaddr *)&sdl);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
781 else {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
782 union sa_ss gateway;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
783
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
784 if_copysa(&gateway.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
785 #ifdef INET6
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
786 if (gateway.sa.sa_family == AF_INET6)
5195
45226e01fbdd inet6: Move BSD get/set scope function to ipv6 for general use
Roy Marples <roy@marples.name>
parents: 5177
diff changeset
787 ipv6_setscope(&gateway.sin6, rt->rt_ifp->index);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
788 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
789 ADDSA(&gateway.sa);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
790 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
791 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
792
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
793 if (rtm->rtm_addrs & RTA_NETMASK)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
794 ADDSA(&rt->rt_netmask);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
795
4256
4cc5f8d94727 BSD: move the interface hint up the stack
Roy Marples <roy@marples.name>
parents: 4254
diff changeset
796 if (rtm->rtm_addrs & RTA_IFP)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
797 ADDSA((struct sockaddr *)&sdl);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
798
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
799 if (rtm->rtm_addrs & RTA_IFA)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
800 ADDSA(&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
801
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
802 #undef ADDSA
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
803
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
804 rtm->rtm_msglen = (unsigned short)(bp - (char *)rtm);
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
805
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
806 #ifdef PRIVSEP
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
807 if (ctx->options & DHCPCD_PRIVSEP) {
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
808 if (ps_root_route(ctx, rtm, rtm->rtm_msglen) == -1)
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
809 return -1;
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
810 return 0;
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
811 }
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
812 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
813 if (write(ctx->link_fd, rtm, rtm->rtm_msglen) == -1)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
814 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
815 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
816 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
817
5058
607d2d75b835 BSD: Fix processing RTM_MISS for non NetBSD BSDs
Roy Marples <roy@marples.name>
parents: 5057
diff changeset
818 static bool
607d2d75b835 BSD: Fix processing RTM_MISS for non NetBSD BSDs
Roy Marples <roy@marples.name>
parents: 5057
diff changeset
819 if_realroute(const struct rt_msghdr *rtm)
607d2d75b835 BSD: Fix processing RTM_MISS for non NetBSD BSDs
Roy Marples <roy@marples.name>
parents: 5057
diff changeset
820 {
607d2d75b835 BSD: Fix processing RTM_MISS for non NetBSD BSDs
Roy Marples <roy@marples.name>
parents: 5057
diff changeset
821
607d2d75b835 BSD: Fix processing RTM_MISS for non NetBSD BSDs
Roy Marples <roy@marples.name>
parents: 5057
diff changeset
822 #ifdef RTF_CLONED
607d2d75b835 BSD: Fix processing RTM_MISS for non NetBSD BSDs
Roy Marples <roy@marples.name>
parents: 5057
diff changeset
823 if (rtm->rtm_flags & RTF_CLONED)
607d2d75b835 BSD: Fix processing RTM_MISS for non NetBSD BSDs
Roy Marples <roy@marples.name>
parents: 5057
diff changeset
824 return false;
607d2d75b835 BSD: Fix processing RTM_MISS for non NetBSD BSDs
Roy Marples <roy@marples.name>
parents: 5057
diff changeset
825 #endif
607d2d75b835 BSD: Fix processing RTM_MISS for non NetBSD BSDs
Roy Marples <roy@marples.name>
parents: 5057
diff changeset
826 #ifdef RTF_WASCLONED
607d2d75b835 BSD: Fix processing RTM_MISS for non NetBSD BSDs
Roy Marples <roy@marples.name>
parents: 5057
diff changeset
827 if (rtm->rtm_flags & RTF_WASCLONED)
607d2d75b835 BSD: Fix processing RTM_MISS for non NetBSD BSDs
Roy Marples <roy@marples.name>
parents: 5057
diff changeset
828 return false;
607d2d75b835 BSD: Fix processing RTM_MISS for non NetBSD BSDs
Roy Marples <roy@marples.name>
parents: 5057
diff changeset
829 #endif
607d2d75b835 BSD: Fix processing RTM_MISS for non NetBSD BSDs
Roy Marples <roy@marples.name>
parents: 5057
diff changeset
830 #ifdef RTF_LOCAL
607d2d75b835 BSD: Fix processing RTM_MISS for non NetBSD BSDs
Roy Marples <roy@marples.name>
parents: 5057
diff changeset
831 if (rtm->rtm_flags & RTF_LOCAL)
607d2d75b835 BSD: Fix processing RTM_MISS for non NetBSD BSDs
Roy Marples <roy@marples.name>
parents: 5057
diff changeset
832 return false;
607d2d75b835 BSD: Fix processing RTM_MISS for non NetBSD BSDs
Roy Marples <roy@marples.name>
parents: 5057
diff changeset
833 #endif
607d2d75b835 BSD: Fix processing RTM_MISS for non NetBSD BSDs
Roy Marples <roy@marples.name>
parents: 5057
diff changeset
834 #ifdef RTF_BROADCAST
607d2d75b835 BSD: Fix processing RTM_MISS for non NetBSD BSDs
Roy Marples <roy@marples.name>
parents: 5057
diff changeset
835 if (rtm->rtm_flags & RTF_BROADCAST)
607d2d75b835 BSD: Fix processing RTM_MISS for non NetBSD BSDs
Roy Marples <roy@marples.name>
parents: 5057
diff changeset
836 return false;
607d2d75b835 BSD: Fix processing RTM_MISS for non NetBSD BSDs
Roy Marples <roy@marples.name>
parents: 5057
diff changeset
837 #endif
607d2d75b835 BSD: Fix processing RTM_MISS for non NetBSD BSDs
Roy Marples <roy@marples.name>
parents: 5057
diff changeset
838 return true;
607d2d75b835 BSD: Fix processing RTM_MISS for non NetBSD BSDs
Roy Marples <roy@marples.name>
parents: 5057
diff changeset
839 }
607d2d75b835 BSD: Fix processing RTM_MISS for non NetBSD BSDs
Roy Marples <roy@marples.name>
parents: 5057
diff changeset
840
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
841 static int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
842 if_copyrt(struct dhcpcd_ctx *ctx, struct rt *rt, const struct rt_msghdr *rtm)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
843 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
844 const struct sockaddr *rti_info[RTAX_MAX];
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
845
4678
f61e4eeb8351 BSD: Handle RTM_MISS
Roy Marples <roy@marples.name>
parents: 4672
diff changeset
846 if (!(rtm->rtm_addrs & RTA_DST)) {
f61e4eeb8351 BSD: Handle RTM_MISS
Roy Marples <roy@marples.name>
parents: 4672
diff changeset
847 errno = EINVAL;
f61e4eeb8351 BSD: Handle RTM_MISS
Roy Marples <roy@marples.name>
parents: 4672
diff changeset
848 return -1;
f61e4eeb8351 BSD: Handle RTM_MISS
Roy Marples <roy@marples.name>
parents: 4672
diff changeset
849 }
f61e4eeb8351 BSD: Handle RTM_MISS
Roy Marples <roy@marples.name>
parents: 4672
diff changeset
850 if (rtm->rtm_type != RTM_MISS && !(rtm->rtm_addrs & RTA_GATEWAY)) {
4422
344851420e71 BSD: Fix detecting the interface for scoped routes
Roy Marples <roy@marples.name>
parents: 4421
diff changeset
851 errno = EINVAL;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
852 return -1;
4422
344851420e71 BSD: Fix detecting the interface for scoped routes
Roy Marples <roy@marples.name>
parents: 4421
diff changeset
853 }
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
854
4628
8408291093fd BSD: Address some coverity issues
Roy Marples <roy@marples.name>
parents: 4615
diff changeset
855 if (get_addrs(rtm->rtm_addrs, (const char *)rtm + sizeof(*rtm),
8408291093fd BSD: Address some coverity issues
Roy Marples <roy@marples.name>
parents: 4615
diff changeset
856 rtm->rtm_msglen - sizeof(*rtm), rti_info) == -1)
4502
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
857 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
858 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
859
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
860 rt->rt_flags = (unsigned int)rtm->rtm_flags;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
861 if_copysa(&rt->rt_dest, rti_info[RTAX_DST]);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
862 if (rtm->rtm_addrs & RTA_NETMASK) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
863 if_copysa(&rt->rt_netmask, rti_info[RTAX_NETMASK]);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
864 if (rt->rt_netmask.sa_family == 255) /* Why? */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
865 rt->rt_netmask.sa_family = 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
866 }
4678
f61e4eeb8351 BSD: Handle RTM_MISS
Roy Marples <roy@marples.name>
parents: 4672
diff changeset
867
4645
7d0f6ee7b39e BSD: Fix router reachability tests
Roy Marples <roy@marples.name>
parents: 4643
diff changeset
868 /* dhcpcd likes an unspecified gateway to indicate via the link.
7d0f6ee7b39e BSD: Fix router reachability tests
Roy Marples <roy@marples.name>
parents: 4643
diff changeset
869 * However we need to know if gateway was a link with an address. */
4678
f61e4eeb8351 BSD: Handle RTM_MISS
Roy Marples <roy@marples.name>
parents: 4672
diff changeset
870 if (rtm->rtm_addrs & RTA_GATEWAY) {
f61e4eeb8351 BSD: Handle RTM_MISS
Roy Marples <roy@marples.name>
parents: 4672
diff changeset
871 if (rti_info[RTAX_GATEWAY]->sa_family == AF_LINK) {
f61e4eeb8351 BSD: Handle RTM_MISS
Roy Marples <roy@marples.name>
parents: 4672
diff changeset
872 const struct sockaddr_dl *sdl;
4645
7d0f6ee7b39e BSD: Fix router reachability tests
Roy Marples <roy@marples.name>
parents: 4643
diff changeset
873
4678
f61e4eeb8351 BSD: Handle RTM_MISS
Roy Marples <roy@marples.name>
parents: 4672
diff changeset
874 sdl = (const struct sockaddr_dl*)
f61e4eeb8351 BSD: Handle RTM_MISS
Roy Marples <roy@marples.name>
parents: 4672
diff changeset
875 (const void *)rti_info[RTAX_GATEWAY];
f61e4eeb8351 BSD: Handle RTM_MISS
Roy Marples <roy@marples.name>
parents: 4672
diff changeset
876 if (sdl->sdl_alen != 0)
f61e4eeb8351 BSD: Handle RTM_MISS
Roy Marples <roy@marples.name>
parents: 4672
diff changeset
877 rt->rt_dflags |= RTDF_GATELINK;
f61e4eeb8351 BSD: Handle RTM_MISS
Roy Marples <roy@marples.name>
parents: 4672
diff changeset
878 } else if (rtm->rtm_flags & RTF_GATEWAY)
f61e4eeb8351 BSD: Handle RTM_MISS
Roy Marples <roy@marples.name>
parents: 4672
diff changeset
879 if_copysa(&rt->rt_gateway, rti_info[RTAX_GATEWAY]);
f61e4eeb8351 BSD: Handle RTM_MISS
Roy Marples <roy@marples.name>
parents: 4672
diff changeset
880 }
f61e4eeb8351 BSD: Handle RTM_MISS
Roy Marples <roy@marples.name>
parents: 4672
diff changeset
881
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
882 if (rtm->rtm_addrs & RTA_IFA)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
883 if_copysa(&rt->rt_ifa, rti_info[RTAX_IFA]);
4678
f61e4eeb8351 BSD: Handle RTM_MISS
Roy Marples <roy@marples.name>
parents: 4672
diff changeset
884
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
885 rt->rt_mtu = (unsigned int)rtm->rtm_rmx.rmx_mtu;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
886
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
887 if (rtm->rtm_index)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
888 rt->rt_ifp = if_findindex(ctx->ifaces, rtm->rtm_index);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
889 else if (rtm->rtm_addrs & RTA_IFP)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
890 rt->rt_ifp = if_findsa(ctx, rti_info[RTAX_IFP]);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
891 else if (rtm->rtm_addrs & RTA_GATEWAY)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
892 rt->rt_ifp = if_findsa(ctx, rti_info[RTAX_GATEWAY]);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
893 else
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
894 rt->rt_ifp = if_findsa(ctx, rti_info[RTAX_DST]);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
895
4679
b788dd0853bd BSD: RTM_MISS doesn't always have a gateway
Roy Marples <roy@marples.name>
parents: 4678
diff changeset
896 if (rt->rt_ifp == NULL && rtm->rtm_type == RTM_MISS)
b788dd0853bd BSD: RTM_MISS doesn't always have a gateway
Roy Marples <roy@marples.name>
parents: 4678
diff changeset
897 rt->rt_ifp = if_find(ctx->ifaces, "lo0");
b788dd0853bd BSD: RTM_MISS doesn't always have a gateway
Roy Marples <roy@marples.name>
parents: 4678
diff changeset
898
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
899 if (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
900 errno = ESRCH;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
901 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
902 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
903 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
904 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
905
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
906 int
4400
2d6a2c8c6b56 route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents: 4390
diff changeset
907 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
908 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
909 struct rt_msghdr *rtm;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
910 int mib[6];
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
911 size_t needed;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
912 char *buf, *p, *end;
4400
2d6a2c8c6b56 route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents: 4390
diff changeset
913 struct rt rt, *rtn;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
914
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
915 mib[0] = CTL_NET;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
916 mib[1] = PF_ROUTE;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
917 mib[2] = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
918 mib[3] = af;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
919 mib[4] = NET_RT_DUMP;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
920 mib[5] = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
921
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
922 if (sysctl(mib, 6, NULL, &needed, NULL, 0) == -1)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
923 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
924 if (needed == 0)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
925 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
926 if ((buf = malloc(needed)) == NULL)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
927 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
928 if (sysctl(mib, 6, buf, &needed, NULL, 0) == -1) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
929 free(buf);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
930 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
931 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
933 end = buf + needed;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
934 for (p = buf; p < end; p += rtm->rtm_msglen) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
935 rtm = (void *)p;
4502
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
936 if (p + rtm->rtm_msglen >= end) {
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
937 errno = EINVAL;
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
938 break;
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
939 }
5058
607d2d75b835 BSD: Fix processing RTM_MISS for non NetBSD BSDs
Roy Marples <roy@marples.name>
parents: 5057
diff changeset
940 if (!if_realroute(rtm))
607d2d75b835 BSD: Fix processing RTM_MISS for non NetBSD BSDs
Roy Marples <roy@marples.name>
parents: 5057
diff changeset
941 continue;
4400
2d6a2c8c6b56 route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents: 4390
diff changeset
942 if (if_copyrt(ctx, &rt, rtm) != 0)
2d6a2c8c6b56 route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents: 4390
diff changeset
943 continue;
2d6a2c8c6b56 route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents: 4390
diff changeset
944 if ((rtn = rt_new(rt.rt_ifp)) == NULL) {
2d6a2c8c6b56 route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents: 4390
diff changeset
945 logerr(__func__);
2d6a2c8c6b56 route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents: 4390
diff changeset
946 break;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
947 }
4400
2d6a2c8c6b56 route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents: 4390
diff changeset
948 memcpy(rtn, &rt, sizeof(*rtn));
2d6a2c8c6b56 route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents: 4390
diff changeset
949 if (rb_tree_insert_node(kroutes, rtn) != rtn)
2d6a2c8c6b56 route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents: 4390
diff changeset
950 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
951 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
952 free(buf);
4502
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
953 return p == end ? 0 : -1;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
954 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
955
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
956 #ifdef INET
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
957 int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
958 if_address(unsigned char cmd, const struct ipv4_addr *ia)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
959 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
960 int r;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
961 struct in_aliasreq ifra;
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
962 struct dhcpcd_ctx *ctx = ia->iface->ctx;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
963
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
964 memset(&ifra, 0, sizeof(ifra));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
965 strlcpy(ifra.ifra_name, ia->iface->name, sizeof(ifra.ifra_name));
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 #define ADDADDR(var, addr) do { \
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
968 (var)->sin_family = AF_INET; \
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
969 (var)->sin_len = sizeof(*(var)); \
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
970 (var)->sin_addr = *(addr); \
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
971 } while (/*CONSTCOND*/0)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
972 ADDADDR(&ifra.ifra_addr, &ia->addr);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
973 ADDADDR(&ifra.ifra_mask, &ia->mask);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
974 if (cmd == RTM_NEWADDR && ia->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
975 ADDADDR(&ifra.ifra_broadaddr, &ia->brd);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
976 #undef ADDADDR
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
977
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
978 r = if_ioctl(ctx,
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
979 cmd == RTM_DELADDR ? SIOCDIFADDR : SIOCAIFADDR, &ifra,sizeof(ifra));
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
980 return r;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
981 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
982
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
983 #if !(defined(HAVE_IFADDRS_ADDRFLAGS) && defined(HAVE_IFAM_ADDRFLAGS))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
984 int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
985 if_addrflags(const struct interface *ifp, const struct in_addr *addr,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
986 __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
987 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
988 #ifdef SIOCGIFAFLAG_IN
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
989 struct ifreq ifr;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
990 struct sockaddr_in *sin;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
991
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
992 memset(&ifr, 0, sizeof(ifr));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
993 strlcpy(ifr.ifr_name, ifp->name, sizeof(ifr.ifr_name));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
994 sin = (void *)&ifr.ifr_addr;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
995 sin->sin_family = AF_INET;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
996 sin->sin_addr = *addr;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
997 if (ioctl(ifp->ctx->pf_inet_fd, SIOCGIFAFLAG_IN, &ifr) == -1)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
998 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
999 return ifr.ifr_addrflags;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1000 #else
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1001 UNUSED(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1002 UNUSED(addr);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1003 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1004 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1005 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1006 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1007 #endif /* INET */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1008
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1009 #ifdef INET6
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
1010 static int
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
1011 if_ioctl6(struct dhcpcd_ctx *ctx, unsigned long req, void *data, size_t len)
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
1012 {
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
1013 struct priv *priv;
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
1014
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
1015 #ifdef PRIVSEP
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
1016 if (ctx->options & DHCPCD_PRIVSEP)
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
1017 return (int)ps_root_ioctl6(ctx, req, data, len);
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
1018 #endif
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
1019
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
1020 priv = ctx->priv;
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
1021 return ioctl(priv->pf_inet6_fd, req, data, len);
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
1022 }
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
1023
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1024 int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1025 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
1026 {
5156
abb54c79cc7f OpenBSD: set IN6_IFF_AUTOCONF for addresses generated from a RA
Roy Marples <roy@marples.name>
parents: 5153
diff changeset
1027 struct in6_aliasreq ifa = { .ifra_flags = 0 };
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1028 struct in6_addr mask;
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
1029 struct dhcpcd_ctx *ctx = ia->iface->ctx;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1030
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1031 strlcpy(ifa.ifra_name, ia->iface->name, sizeof(ifa.ifra_name));
4327
8a8423f206f5 FreeBSD: Mark INET6 addresses as tentative when adding them
Roy Marples <roy@marples.name>
parents: 4326
diff changeset
1032 #if defined(__FreeBSD__) || defined(__DragonFly__)
5156
abb54c79cc7f OpenBSD: set IN6_IFF_AUTOCONF for addresses generated from a RA
Roy Marples <roy@marples.name>
parents: 5153
diff changeset
1033 /* This is a bug - the kernel should work this out. */
4327
8a8423f206f5 FreeBSD: Mark INET6 addresses as tentative when adding them
Roy Marples <roy@marples.name>
parents: 4326
diff changeset
1034 if (ia->addr_flags & IN6_IFF_TENTATIVE)
8a8423f206f5 FreeBSD: Mark INET6 addresses as tentative when adding them
Roy Marples <roy@marples.name>
parents: 4326
diff changeset
1035 ifa.ifra_flags |= IN6_IFF_TENTATIVE;
8a8423f206f5 FreeBSD: Mark INET6 addresses as tentative when adding them
Roy Marples <roy@marples.name>
parents: 4326
diff changeset
1036 #endif
5364
fe45c5b59de1 BSD: Allow non NetBSD and OpenBSD to set IN6_IFF_AUTOCONF
Roy Marples <roy@marples.name>
parents: 5356
diff changeset
1037 #if (defined(__NetBSD__) || defined(__OpenBSD__)) && \
fe45c5b59de1 BSD: Allow non NetBSD and OpenBSD to set IN6_IFF_AUTOCONF
Roy Marples <roy@marples.name>
parents: 5356
diff changeset
1038 (defined(IPV6CTL_ACCEPT_RTADV) || defined(ND6_IFF_ACCEPT_RTADV))
fe45c5b59de1 BSD: Allow non NetBSD and OpenBSD to set IN6_IFF_AUTOCONF
Roy Marples <roy@marples.name>
parents: 5356
diff changeset
1039 /* These kernels don't accept userland setting IN6_IFF_AUTOCONF */
fe45c5b59de1 BSD: Allow non NetBSD and OpenBSD to set IN6_IFF_AUTOCONF
Roy Marples <roy@marples.name>
parents: 5356
diff changeset
1040 #else
5156
abb54c79cc7f OpenBSD: set IN6_IFF_AUTOCONF for addresses generated from a RA
Roy Marples <roy@marples.name>
parents: 5153
diff changeset
1041 if (ia->flags & IPV6_AF_AUTOCONF)
abb54c79cc7f OpenBSD: set IN6_IFF_AUTOCONF for addresses generated from a RA
Roy Marples <roy@marples.name>
parents: 5153
diff changeset
1042 ifa.ifra_flags |= IN6_IFF_AUTOCONF;
abb54c79cc7f OpenBSD: set IN6_IFF_AUTOCONF for addresses generated from a RA
Roy Marples <roy@marples.name>
parents: 5153
diff changeset
1043 #endif
5125
6f14f7261828 BSD: Fix temporary address management
Roy Marples <roy@marples.name>
parents: 5113
diff changeset
1044 #ifdef IPV6_MANAGETEMPADDR
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1045 if (ia->flags & IPV6_AF_TEMPORARY)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1046 ifa.ifra_flags |= IN6_IFF_TEMPORARY;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1047 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1048
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1049 #define ADDADDR(v, addr) { \
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1050 (v)->sin6_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
1051 (v)->sin6_len = sizeof(*v); \
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1052 (v)->sin6_addr = *(addr); \
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1053 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1054
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1055 ADDADDR(&ifa.ifra_addr, &ia->addr);
5195
45226e01fbdd inet6: Move BSD get/set scope function to ipv6 for general use
Roy Marples <roy@marples.name>
parents: 5177
diff changeset
1056 ipv6_setscope(&ifa.ifra_addr, 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
1057 ipv6_mask(&mask, ia->prefix_len);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1058 ADDADDR(&ifa.ifra_prefixmask, &mask);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1059
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1060 #undef ADDADDR
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1061
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1062 /*
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1063 * Every BSD kernel wants to add the prefix of the address to it's
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1064 * list of RA received prefixes.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1065 * THIS IS WRONG because there (as the comments in the kernel state)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1066 * is no API for managing prefix lifetime and the kernel should not
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1067 * pretend it's from a RA either.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1068 *
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1069 * The issue is that the very first assigned prefix will inherit the
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1070 * lifetime of the address, but any subsequent alteration of the
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1071 * address OR it's lifetime will not affect the prefix lifetime.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1072 * As such, we cannot stop the prefix from timing out and then
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1073 * constantly removing the prefix route dhcpcd is capable of adding
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1074 * in it's absense.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1075 *
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1076 * What we can do to mitigate the issue is to add the address with
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1077 * infinite lifetimes, so the prefix route will never time out.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1078 * Once done, we can then set lifetimes on the address and all is good.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1079 * The downside of this approach is that we need to manually remove
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1080 * the kernel route because it has no lifetime, but this is OK as
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1081 * dhcpcd will handle this too.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1082 *
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1083 * This issue is discussed on the NetBSD mailing lists here:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1084 * http://mail-index.netbsd.org/tech-net/2016/08/05/msg006044.html
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1085 *
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1086 * Fixed in NetBSD-7.99.36
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1087 * NOT fixed in FreeBSD - bug 195197
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1088 * Fixed in OpenBSD-5.9
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1089 */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1090
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1091 #if !((defined(__NetBSD_Version__) && __NetBSD_Version__ >= 799003600) || \
4049
22e5b911ceaa Newer OpenBSD is fixed for userland affecting address lifetime.
Roy Marples <roy@marples.name>
parents: 4046
diff changeset
1092 (defined(__OpenBSD__) && OpenBSD >= 201605))
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1093 if (cmd == RTM_NEWADDR && !(ia->flags & IPV6_AF_ADDED)) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1094 ifa.ifra_lifetime.ia6t_vltime = ND6_INFINITE_LIFETIME;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1095 ifa.ifra_lifetime.ia6t_pltime = ND6_INFINITE_LIFETIME;
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
1096 (void)if_ioctl6(ctx, SIOCAIFADDR_IN6, &ifa, sizeof(ifa));
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1097 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1098 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1099
4049
22e5b911ceaa Newer OpenBSD is fixed for userland affecting address lifetime.
Roy Marples <roy@marples.name>
parents: 4046
diff changeset
1100 #if defined(__OpenBSD__) && OpenBSD <= 201705
22e5b911ceaa Newer OpenBSD is fixed for userland affecting address lifetime.
Roy Marples <roy@marples.name>
parents: 4046
diff changeset
1101 /* BUT OpenBSD older than 6.2 does not reset the address lifetime
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1102 * for subsequent calls...
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1103 * Luckily dhcpcd will remove the lease when it expires so
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1104 * just set an infinite lifetime, unless a temporary address. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1105 if (ifa.ifra_flags & IN6_IFF_PRIVACY) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1106 ifa.ifra_lifetime.ia6t_vltime = 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
1107 ifa.ifra_lifetime.ia6t_pltime = 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
1108 } else {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1109 ifa.ifra_lifetime.ia6t_vltime = ND6_INFINITE_LIFETIME;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1110 ifa.ifra_lifetime.ia6t_pltime = ND6_INFINITE_LIFETIME;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1111 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1112 #else
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1113 ifa.ifra_lifetime.ia6t_vltime = 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
1114 ifa.ifra_lifetime.ia6t_pltime = 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
1115 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1116
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
1117 return if_ioctl6(ctx,
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
1118 cmd == RTM_DELADDR ? SIOCDIFADDR_IN6 : SIOCAIFADDR_IN6,
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
1119 &ifa, sizeof(ifa));
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1120 }
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 int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1123 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
1124 __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
1125 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1126 int flags;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1127 struct in6_ifreq ifr6;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1128 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
1129
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1130 memset(&ifr6, 0, sizeof(ifr6));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1131 strlcpy(ifr6.ifr_name, ifp->name, sizeof(ifr6.ifr_name));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1132 ifr6.ifr_addr.sin6_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
1133 ifr6.ifr_addr.sin6_addr = *addr;
5195
45226e01fbdd inet6: Move BSD get/set scope function to ipv6 for general use
Roy Marples <roy@marples.name>
parents: 5177
diff changeset
1134 ipv6_setscope(&ifr6.ifr_addr, ifp->index);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1135 priv = (struct priv *)ifp->ctx->priv;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1136 if (ioctl(priv->pf_inet6_fd, SIOCGIFAFLAG_IN6, &ifr6) != -1)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1137 flags = ifr6.ifr_ifru.ifru_flags6;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1138 else
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1139 flags = -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1140 return flags;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1141 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1142
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1143 int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1144 if_getlifetime6(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
1145 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1146 struct in6_ifreq ifr6;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1147 time_t t;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1148 struct in6_addrlifetime *lifetime;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1149 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
1150
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1151 memset(&ifr6, 0, sizeof(ifr6));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1152 strlcpy(ifr6.ifr_name, ia->iface->name, sizeof(ifr6.ifr_name));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1153 ifr6.ifr_addr.sin6_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
1154 ifr6.ifr_addr.sin6_addr = ia->addr;
5195
45226e01fbdd inet6: Move BSD get/set scope function to ipv6 for general use
Roy Marples <roy@marples.name>
parents: 5177
diff changeset
1155 ipv6_setscope(&ifr6.ifr_addr, 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
1156 priv = (struct priv *)ia->iface->ctx->priv;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1157 if (ioctl(priv->pf_inet6_fd, SIOCGIFALIFETIME_IN6, &ifr6) == -1)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1158 return -1;
4483
e2f5a58c978a FreeBSD: Fix fetching the IPv6 address lifetime
Roy Marples <roy@marples.name>
parents: 4437
diff changeset
1159 clock_gettime(CLOCK_MONOTONIC, &ia->created);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1160
4483
e2f5a58c978a FreeBSD: Fix fetching the IPv6 address lifetime
Roy Marples <roy@marples.name>
parents: 4437
diff changeset
1161 #if defined(__FreeBSD__) || defined(__DragonFly__)
e2f5a58c978a FreeBSD: Fix fetching the IPv6 address lifetime
Roy Marples <roy@marples.name>
parents: 4437
diff changeset
1162 t = ia->created.tv_sec;
e2f5a58c978a FreeBSD: Fix fetching the IPv6 address lifetime
Roy Marples <roy@marples.name>
parents: 4437
diff changeset
1163 #else
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1164 t = time(NULL);
4483
e2f5a58c978a FreeBSD: Fix fetching the IPv6 address lifetime
Roy Marples <roy@marples.name>
parents: 4437
diff changeset
1165 #endif
e2f5a58c978a FreeBSD: Fix fetching the IPv6 address lifetime
Roy Marples <roy@marples.name>
parents: 4437
diff changeset
1166
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1167 lifetime = &ifr6.ifr_ifru.ifru_lifetime;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1168 if (lifetime->ia6t_preferred)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1169 ia->prefix_pltime = (uint32_t)(lifetime->ia6t_preferred -
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1170 MIN(t, lifetime->ia6t_preferred));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1171 else
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1172 ia->prefix_pltime = ND6_INFINITE_LIFETIME;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1173 if (lifetime->ia6t_expire) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1174 ia->prefix_vltime = (uint32_t)(lifetime->ia6t_expire -
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1175 MIN(t, lifetime->ia6t_expire));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1176 /* Calculate the created time */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1177 ia->created.tv_sec -= lifetime->ia6t_vltime - 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
1178 } else
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1179 ia->prefix_vltime = ND6_INFINITE_LIFETIME;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1180 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1181 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1182 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1183
4502
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1184 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
1185 if_announce(struct dhcpcd_ctx *ctx, const struct if_announcemsghdr *ifan)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1186 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1187
4502
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1188 if (ifan->ifan_msglen < sizeof(*ifan)) {
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1189 errno = EINVAL;
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1190 return -1;
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1191 }
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1192
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1193 switch(ifan->ifan_what) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1194 case IFAN_ARRIVAL:
4502
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1195 return dhcpcd_handleinterface(ctx, 1, ifan->ifan_name);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1196 case IFAN_DEPARTURE:
4502
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1197 return dhcpcd_handleinterface(ctx, -1, ifan->ifan_name);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1198 }
4502
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1199
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1200 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
1201 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1202
4502
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1203 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
1204 if_ifinfo(struct dhcpcd_ctx *ctx, const struct if_msghdr *ifm)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1205 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1206 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
1207 int link_state;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1208
4502
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1209 if (ifm->ifm_msglen < sizeof(*ifm)) {
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1210 errno = EINVAL;
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1211 return -1;
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1212 }
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1213
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1214 if ((ifp = if_findindex(ctx->ifaces, ifm->ifm_index)) == NULL)
4502
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1215 return 0;
4340
1de0bba2f0b2 BSD: Fix UP/DOWN for interfaces which dont' report media changes
Roy Marples <roy@marples.name>
parents: 4339
diff changeset
1216
5486
8e2b8ce8c972 BSD: struct if_data->ifi_link_state is the single source of truth
Roy Marples <roy@marples.name>
parents: 5485
diff changeset
1217 link_state = if_carrier(ifp, &ifm->ifm_data);
8e2b8ce8c972 BSD: struct if_data->ifi_link_state is the single source of truth
Roy Marples <roy@marples.name>
parents: 5485
diff changeset
1218 dhcpcd_handlecarrier(ifp, link_state, (unsigned int)ifm->ifm_flags);
4502
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1219 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
1220 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1221
4502
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1222 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
1223 if_rtm(struct dhcpcd_ctx *ctx, const struct rt_msghdr *rtm)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1224 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1225 struct rt rt;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1226
4502
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1227 if (rtm->rtm_msglen < sizeof(*rtm)) {
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1228 errno = EINVAL;
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1229 return -1;
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1230 }
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1231
4025
e20d2e8dca5b Ignore route(4) errors.
Roy Marples <roy@marples.name>
parents: 4023
diff changeset
1232 /* Ignore errors. */
e20d2e8dca5b Ignore route(4) errors.
Roy Marples <roy@marples.name>
parents: 4023
diff changeset
1233 if (rtm->rtm_errno != 0)
4502
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1234 return 0;
4025
e20d2e8dca5b Ignore route(4) errors.
Roy Marples <roy@marples.name>
parents: 4023
diff changeset
1235
4971
d050161827d1 BSD: Ignore messages from ourself in privsep.
Roy Marples <roy@marples.name>
parents: 4961
diff changeset
1236 /* Ignore messages from ourself. */
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
1237 #ifdef PRIVSEP
4971
d050161827d1 BSD: Ignore messages from ourself in privsep.
Roy Marples <roy@marples.name>
parents: 4961
diff changeset
1238 if (ctx->ps_root_pid != 0) {
d050161827d1 BSD: Ignore messages from ourself in privsep.
Roy Marples <roy@marples.name>
parents: 4961
diff changeset
1239 if (rtm->rtm_pid == ctx->ps_root_pid)
d050161827d1 BSD: Ignore messages from ourself in privsep.
Roy Marples <roy@marples.name>
parents: 4961
diff changeset
1240 return 0;
4972
c38657775fb4 BSD: Disable checking rtm_pid and comment why.
Roy Marples <roy@marples.name>
parents: 4971
diff changeset
1241 }
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
1242 #endif
4972
c38657775fb4 BSD: Disable checking rtm_pid and comment why.
Roy Marples <roy@marples.name>
parents: 4971
diff changeset
1243
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1244 if (if_copyrt(ctx, &rt, rtm) == -1)
4678
f61e4eeb8351 BSD: Handle RTM_MISS
Roy Marples <roy@marples.name>
parents: 4672
diff changeset
1245 return errno == ENOTSUP ? 0 : -1;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1246
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1247 #ifdef INET6
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1248 /*
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1249 * BSD announces host routes.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1250 * As such, we should be notified of reachability by its
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1251 * existance with a hardware address.
4669
ec9d26e0de41 inet6: Stop reacting to kernel neighbour messages about a router
Roy Marples <roy@marples.name>
parents: 4666
diff changeset
1252 * Ensure we don't call this for a newly incomplete state.
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1253 */
4645
7d0f6ee7b39e BSD: Fix router reachability tests
Roy Marples <roy@marples.name>
parents: 4643
diff changeset
1254 if (rt.rt_dest.sa_family == AF_INET6 &&
4678
f61e4eeb8351 BSD: Handle RTM_MISS
Roy Marples <roy@marples.name>
parents: 4672
diff changeset
1255 (rt.rt_flags & RTF_HOST || rtm->rtm_type == RTM_MISS) &&
4666
ebe041d24998 BSD: Listen for Router -> Host messages via RTM_CHANGE
Roy Marples <roy@marples.name>
parents: 4645
diff changeset
1256 !(rtm->rtm_type == RTM_ADD && !(rt.rt_dflags & RTDF_GATELINK)))
ebe041d24998 BSD: Listen for Router -> Host messages via RTM_CHANGE
Roy Marples <roy@marples.name>
parents: 4645
diff changeset
1257 {
4669
ec9d26e0de41 inet6: Stop reacting to kernel neighbour messages about a router
Roy Marples <roy@marples.name>
parents: 4666
diff changeset
1258 bool reachable;
4666
ebe041d24998 BSD: Listen for Router -> Host messages via RTM_CHANGE
Roy Marples <roy@marples.name>
parents: 4645
diff changeset
1259
4678
f61e4eeb8351 BSD: Handle RTM_MISS
Roy Marples <roy@marples.name>
parents: 4672
diff changeset
1260 reachable = (rtm->rtm_type == RTM_ADD ||
f61e4eeb8351 BSD: Handle RTM_MISS
Roy Marples <roy@marples.name>
parents: 4672
diff changeset
1261 rtm->rtm_type == RTM_CHANGE) &&
4669
ec9d26e0de41 inet6: Stop reacting to kernel neighbour messages about a router
Roy Marples <roy@marples.name>
parents: 4666
diff changeset
1262 rt.rt_dflags & RTDF_GATELINK;
ec9d26e0de41 inet6: Stop reacting to kernel neighbour messages about a router
Roy Marples <roy@marples.name>
parents: 4666
diff changeset
1263 ipv6nd_neighbour(ctx, &rt.rt_ss_dest.sin6.sin6_addr, reachable);
4666
ebe041d24998 BSD: Listen for Router -> Host messages via RTM_CHANGE
Roy Marples <roy@marples.name>
parents: 4645
diff changeset
1264 }
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1265 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1266
5058
607d2d75b835 BSD: Fix processing RTM_MISS for non NetBSD BSDs
Roy Marples <roy@marples.name>
parents: 5057
diff changeset
1267 if (rtm->rtm_type != RTM_MISS && if_realroute(rtm))
4678
f61e4eeb8351 BSD: Handle RTM_MISS
Roy Marples <roy@marples.name>
parents: 4672
diff changeset
1268 rt_recvrt(rtm->rtm_type, &rt, rtm->rtm_pid);
4502
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1269 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
1270 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1271
4502
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1272 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
1273 if_ifa(struct dhcpcd_ctx *ctx, const struct ifa_msghdr *ifam)
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 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
1276 const struct sockaddr *rti_info[RTAX_MAX];
4984
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1277 int flags;
4232
8b92c1844860 Log the pid of the process deleting an assigned address.
Roy Marples <roy@marples.name>
parents: 4229
diff changeset
1278 pid_t pid;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1279
4502
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1280 if (ifam->ifam_msglen < sizeof(*ifam)) {
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1281 errno = EINVAL;
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1282 return -1;
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1283 }
4971
d050161827d1 BSD: Ignore messages from ourself in privsep.
Roy Marples <roy@marples.name>
parents: 4961
diff changeset
1284
d050161827d1 BSD: Ignore messages from ourself in privsep.
Roy Marples <roy@marples.name>
parents: 4961
diff changeset
1285 #ifdef HAVE_IFAM_PID
4985
d9cb0a6245a4 Only ignore address messages from ourself for deletion.
Roy Marples <roy@marples.name>
parents: 4984
diff changeset
1286 /* Ignore address deletions from ourself.
d9cb0a6245a4 Only ignore address messages from ourself for deletion.
Roy Marples <roy@marples.name>
parents: 4984
diff changeset
1287 * We need to process address flag changes though. */
d9cb0a6245a4 Only ignore address messages from ourself for deletion.
Roy Marples <roy@marples.name>
parents: 4984
diff changeset
1288 if (ifam->ifam_type == RTM_DELADDR) {
4971
d050161827d1 BSD: Ignore messages from ourself in privsep.
Roy Marples <roy@marples.name>
parents: 4961
diff changeset
1289 #ifdef PRIVSEP
4985
d9cb0a6245a4 Only ignore address messages from ourself for deletion.
Roy Marples <roy@marples.name>
parents: 4984
diff changeset
1290 if (ctx->ps_root_pid != 0) {
d9cb0a6245a4 Only ignore address messages from ourself for deletion.
Roy Marples <roy@marples.name>
parents: 4984
diff changeset
1291 if (ifam->ifam_pid == ctx->ps_root_pid)
d9cb0a6245a4 Only ignore address messages from ourself for deletion.
Roy Marples <roy@marples.name>
parents: 4984
diff changeset
1292 return 0;
d9cb0a6245a4 Only ignore address messages from ourself for deletion.
Roy Marples <roy@marples.name>
parents: 4984
diff changeset
1293 } else
4971
d050161827d1 BSD: Ignore messages from ourself in privsep.
Roy Marples <roy@marples.name>
parents: 4961
diff changeset
1294 #endif
4985
d9cb0a6245a4 Only ignore address messages from ourself for deletion.
Roy Marples <roy@marples.name>
parents: 4984
diff changeset
1295 /* address management is done via ioctl,
d9cb0a6245a4 Only ignore address messages from ourself for deletion.
Roy Marples <roy@marples.name>
parents: 4984
diff changeset
1296 * so SO_USELOOPBACK has no effect,
d9cb0a6245a4 Only ignore address messages from ourself for deletion.
Roy Marples <roy@marples.name>
parents: 4984
diff changeset
1297 * so we do need to check the pid. */
d9cb0a6245a4 Only ignore address messages from ourself for deletion.
Roy Marples <roy@marples.name>
parents: 4984
diff changeset
1298 if (ifam->ifam_pid == getpid())
d9cb0a6245a4 Only ignore address messages from ourself for deletion.
Roy Marples <roy@marples.name>
parents: 4984
diff changeset
1299 return 0;
d9cb0a6245a4 Only ignore address messages from ourself for deletion.
Roy Marples <roy@marples.name>
parents: 4984
diff changeset
1300 }
4971
d050161827d1 BSD: Ignore messages from ourself in privsep.
Roy Marples <roy@marples.name>
parents: 4961
diff changeset
1301 pid = ifam->ifam_pid;
d050161827d1 BSD: Ignore messages from ourself in privsep.
Roy Marples <roy@marples.name>
parents: 4961
diff changeset
1302 #else
d050161827d1 BSD: Ignore messages from ourself in privsep.
Roy Marples <roy@marples.name>
parents: 4961
diff changeset
1303 pid = 0;
d050161827d1 BSD: Ignore messages from ourself in privsep.
Roy Marples <roy@marples.name>
parents: 4961
diff changeset
1304 #endif
d050161827d1 BSD: Ignore messages from ourself in privsep.
Roy Marples <roy@marples.name>
parents: 4961
diff changeset
1305
4503
9784c3171a22 BSD: Ignore coverity errors
Roy Marples <roy@marples.name>
parents: 4502
diff changeset
1306 if (~ifam->ifam_addrs & RTA_IFA)
9784c3171a22 BSD: Ignore coverity errors
Roy Marples <roy@marples.name>
parents: 4502
diff changeset
1307 return 0;
3943
361c6b6906bc Test address family to test the correct address flags.
Roy Marples <roy@marples.name>
parents: 3939
diff changeset
1308 if ((ifp = if_findindex(ctx->ifaces, ifam->ifam_index)) == NULL)
4502
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1309 return 0;
4503
9784c3171a22 BSD: Ignore coverity errors
Roy Marples <roy@marples.name>
parents: 4502
diff changeset
1310
4628
8408291093fd BSD: Address some coverity issues
Roy Marples <roy@marples.name>
parents: 4615
diff changeset
1311 if (get_addrs(ifam->ifam_addrs, (const char *)ifam + sizeof(*ifam),
4502
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1312 ifam->ifam_msglen - sizeof(*ifam), rti_info) == -1)
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1313 return -1;
3943
361c6b6906bc Test address family to test the correct address flags.
Roy Marples <roy@marples.name>
parents: 3939
diff changeset
1314
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1315 switch (rti_info[RTAX_IFA]->sa_family) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1316 case AF_LINK:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1317 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1318 struct sockaddr_dl sdl;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1319
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1320 #ifdef RTM_CHGADDR
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1321 if (ifam->ifam_type != RTM_CHGADDR)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1322 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1323 #else
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1324 if (ifam->ifam_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
1325 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1326 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1327 memcpy(&sdl, rti_info[RTAX_IFA], rti_info[RTAX_IFA]->sa_len);
5168
1f5dc6102f9b if: support changing hardware address type on Linux
Roy Marples <roy@marples.name>
parents: 5156
diff changeset
1328 dhcpcd_handlehwaddr(ifp, ifp->hwtype,
1f5dc6102f9b if: support changing hardware address type on Linux
Roy Marples <roy@marples.name>
parents: 5156
diff changeset
1329 CLLADDR(&sdl), sdl.sdl_alen);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1330 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1331 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1332 #ifdef INET
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1333 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
1334 case 255: /* FIXME: Why 255? */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1335 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1336 const struct sockaddr_in *sin;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1337 struct in_addr addr, mask, bcast;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1338
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1339 sin = (const void *)rti_info[RTAX_IFA];
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1340 addr.s_addr = sin != NULL && sin->sin_family == AF_INET ?
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1341 sin->sin_addr.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
1342 sin = (const void *)rti_info[RTAX_NETMASK];
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1343 mask.s_addr = sin != NULL && sin->sin_family == AF_INET ?
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1344 sin->sin_addr.s_addr : INADDR_ANY;
4326
009a47703a99 BSD: don't listen to own route messages
Roy Marples <roy@marples.name>
parents: 4324
diff changeset
1345 sin = (const void *)rti_info[RTAX_BRD];
009a47703a99 BSD: don't listen to own route messages
Roy Marples <roy@marples.name>
parents: 4324
diff changeset
1346 bcast.s_addr = sin != NULL && sin->sin_family == AF_INET ?
009a47703a99 BSD: don't listen to own route messages
Roy Marples <roy@marples.name>
parents: 4324
diff changeset
1347 sin->sin_addr.s_addr : INADDR_ANY;
4300
82a8e37ab298 Workaround NetBSD-7 sending an invalid bcast address in RTM_NEWADDR
Roy Marples <roy@marples.name>
parents: 4256
diff changeset
1348
4326
009a47703a99 BSD: don't listen to own route messages
Roy Marples <roy@marples.name>
parents: 4324
diff changeset
1349 /*
009a47703a99 BSD: don't listen to own route messages
Roy Marples <roy@marples.name>
parents: 4324
diff changeset
1350 * NetBSD-7 and older send an invalid broadcast address.
4300
82a8e37ab298 Workaround NetBSD-7 sending an invalid bcast address in RTM_NEWADDR
Roy Marples <roy@marples.name>
parents: 4256
diff changeset
1351 * So we need to query the actual address to get
4326
009a47703a99 BSD: don't listen to own route messages
Roy Marples <roy@marples.name>
parents: 4324
diff changeset
1352 * the right one.
4984
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1353 * We can also use this to test if the address
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1354 * has really been added or deleted.
4326
009a47703a99 BSD: don't listen to own route messages
Roy Marples <roy@marples.name>
parents: 4324
diff changeset
1355 */
009a47703a99 BSD: don't listen to own route messages
Roy Marples <roy@marples.name>
parents: 4324
diff changeset
1356 #ifdef SIOCGIFALIAS
4984
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1357 struct in_aliasreq ifra;
4300
82a8e37ab298 Workaround NetBSD-7 sending an invalid bcast address in RTM_NEWADDR
Roy Marples <roy@marples.name>
parents: 4256
diff changeset
1358
4984
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1359 memset(&ifra, 0, sizeof(ifra));
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1360 strlcpy(ifra.ifra_name, ifp->name, sizeof(ifra.ifra_name));
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1361 ifra.ifra_addr.sin_family = AF_INET;
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1362 ifra.ifra_addr.sin_len = sizeof(ifra.ifra_addr);
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1363 ifra.ifra_addr.sin_addr = addr;
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1364 if (ioctl(ctx->pf_inet_fd, SIOCGIFALIAS, &ifra) == -1) {
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1365 if (errno != ENXIO && errno != EADDRNOTAVAIL)
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1366 logerr("%s: SIOCGIFALIAS", __func__);
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1367 if (ifam->ifam_type != RTM_DELADDR)
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1368 break;
4987
9e85855c49b6 BSD: Improve RTM_NEWADDR/RTM_DELADDR validaton some more
Roy Marples <roy@marples.name>
parents: 4985
diff changeset
1369 } else {
9e85855c49b6 BSD: Improve RTM_NEWADDR/RTM_DELADDR validaton some more
Roy Marples <roy@marples.name>
parents: 4985
diff changeset
1370 if (ifam->ifam_type == RTM_DELADDR)
9e85855c49b6 BSD: Improve RTM_NEWADDR/RTM_DELADDR validaton some more
Roy Marples <roy@marples.name>
parents: 4985
diff changeset
1371 break;
4326
009a47703a99 BSD: don't listen to own route messages
Roy Marples <roy@marples.name>
parents: 4324
diff changeset
1372 #if defined(__NetBSD_Version__) && __NetBSD_Version__ < 800000000
4984
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1373 bcast = ifra.ifra_broadaddr.sin_addr;
4326
009a47703a99 BSD: don't listen to own route messages
Roy Marples <roy@marples.name>
parents: 4324
diff changeset
1374 #endif
4987
9e85855c49b6 BSD: Improve RTM_NEWADDR/RTM_DELADDR validaton some more
Roy Marples <roy@marples.name>
parents: 4985
diff changeset
1375 }
4300
82a8e37ab298 Workaround NetBSD-7 sending an invalid bcast address in RTM_NEWADDR
Roy Marples <roy@marples.name>
parents: 4256
diff changeset
1376 #else
4326
009a47703a99 BSD: don't listen to own route messages
Roy Marples <roy@marples.name>
parents: 4324
diff changeset
1377 #warning No SIOCGIFALIAS support
4984
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1378 /*
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1379 * No SIOCGIFALIAS? That sucks!
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1380 * This makes this call very heavy weight, but we
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1381 * really need to know if the message is late or not.
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1382 */
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1383 const struct sockaddr *sa;
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1384 struct ifaddrs *ifaddrs = NULL, *ifa;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1385
4984
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1386 sa = rti_info[RTAX_IFA];
5319
3180f8b46cc4 BSD: In privsep with no GIFALIAS support? getifaddrs over privsep
Roy Marples <roy@marples.name>
parents: 5310
diff changeset
1387 #ifdef PRIVSEP_GETIFADDRS
3180f8b46cc4 BSD: In privsep with no GIFALIAS support? getifaddrs over privsep
Roy Marples <roy@marples.name>
parents: 5310
diff changeset
1388 if (IN_PRIVSEP(ctx)) {
3180f8b46cc4 BSD: In privsep with no GIFALIAS support? getifaddrs over privsep
Roy Marples <roy@marples.name>
parents: 5310
diff changeset
1389 if (ps_root_getifaddrs(ctx, &ifaddrs) == -1) {
3180f8b46cc4 BSD: In privsep with no GIFALIAS support? getifaddrs over privsep
Roy Marples <roy@marples.name>
parents: 5310
diff changeset
1390 logerr("ps_root_getifaddrs");
3180f8b46cc4 BSD: In privsep with no GIFALIAS support? getifaddrs over privsep
Roy Marples <roy@marples.name>
parents: 5310
diff changeset
1391 break;
3180f8b46cc4 BSD: In privsep with no GIFALIAS support? getifaddrs over privsep
Roy Marples <roy@marples.name>
parents: 5310
diff changeset
1392 }
3180f8b46cc4 BSD: In privsep with no GIFALIAS support? getifaddrs over privsep
Roy Marples <roy@marples.name>
parents: 5310
diff changeset
1393 } else
3180f8b46cc4 BSD: In privsep with no GIFALIAS support? getifaddrs over privsep
Roy Marples <roy@marples.name>
parents: 5310
diff changeset
1394 #endif
3180f8b46cc4 BSD: In privsep with no GIFALIAS support? getifaddrs over privsep
Roy Marples <roy@marples.name>
parents: 5310
diff changeset
1395 if (getifaddrs(&ifaddrs) == -1) {
3180f8b46cc4 BSD: In privsep with no GIFALIAS support? getifaddrs over privsep
Roy Marples <roy@marples.name>
parents: 5310
diff changeset
1396 logerr("getifaddrs");
3180f8b46cc4 BSD: In privsep with no GIFALIAS support? getifaddrs over privsep
Roy Marples <roy@marples.name>
parents: 5310
diff changeset
1397 break;
3180f8b46cc4 BSD: In privsep with no GIFALIAS support? getifaddrs over privsep
Roy Marples <roy@marples.name>
parents: 5310
diff changeset
1398 }
4984
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1399 for (ifa = ifaddrs; ifa; ifa = ifa->ifa_next) {
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1400 if (ifa->ifa_addr == NULL)
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1401 continue;
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1402 if (sa_cmp(ifa->ifa_addr, sa) == 0 &&
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1403 strcmp(ifa->ifa_name, ifp->name) == 0)
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1404 break;
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1405 }
5319
3180f8b46cc4 BSD: In privsep with no GIFALIAS support? getifaddrs over privsep
Roy Marples <roy@marples.name>
parents: 5310
diff changeset
1406 #ifdef PRIVSEP_GETIFADDRS
3180f8b46cc4 BSD: In privsep with no GIFALIAS support? getifaddrs over privsep
Roy Marples <roy@marples.name>
parents: 5310
diff changeset
1407 if (IN_PRIVSEP(ctx))
3180f8b46cc4 BSD: In privsep with no GIFALIAS support? getifaddrs over privsep
Roy Marples <roy@marples.name>
parents: 5310
diff changeset
1408 free(ifaddrs);
3180f8b46cc4 BSD: In privsep with no GIFALIAS support? getifaddrs over privsep
Roy Marples <roy@marples.name>
parents: 5310
diff changeset
1409 else
3180f8b46cc4 BSD: In privsep with no GIFALIAS support? getifaddrs over privsep
Roy Marples <roy@marples.name>
parents: 5310
diff changeset
1410 #endif
4984
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1411 freeifaddrs(ifaddrs);
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1412 if (ifam->ifam_type == RTM_DELADDR) {
4326
009a47703a99 BSD: don't listen to own route messages
Roy Marples <roy@marples.name>
parents: 4324
diff changeset
1413 if (ifa != NULL)
4984
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1414 break;
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1415 } else {
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1416 if (ifa == NULL)
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1417 break;
3932
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 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1420
4984
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1421 #ifdef HAVE_IFAM_ADDRFLAGS
5004
8abc8f810b83 BSD: Fix INET flags on RTM_NEWADDR messages.
Roy Marples <roy@marples.name>
parents: 4987
diff changeset
1422 flags = ifam->ifam_addrflags;
4984
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1423 #else
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1424 flags = 0;
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1425 #endif
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1426
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1427 ipv4_handleifa(ctx, ifam->ifam_type, NULL, ifp->name,
4984
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1428 &addr, &mask, &bcast, flags, pid);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1429 break;
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 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1432 #ifdef INET6
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1433 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
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 in6_addr addr6, mask6;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1436 const struct sockaddr_in6 *sin6;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1437
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1438 sin6 = (const void *)rti_info[RTAX_IFA];
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1439 addr6 = sin6->sin6_addr;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1440 sin6 = (const void *)rti_info[RTAX_NETMASK];
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1441 mask6 = sin6->sin6_addr;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1442
4326
009a47703a99 BSD: don't listen to own route messages
Roy Marples <roy@marples.name>
parents: 4324
diff changeset
1443 /*
009a47703a99 BSD: don't listen to own route messages
Roy Marples <roy@marples.name>
parents: 4324
diff changeset
1444 * If the address was deleted, lets check if it's
009a47703a99 BSD: don't listen to own route messages
Roy Marples <roy@marples.name>
parents: 4324
diff changeset
1445 * a late message and it still exists (maybe modified).
009a47703a99 BSD: don't listen to own route messages
Roy Marples <roy@marples.name>
parents: 4324
diff changeset
1446 * If so, ignore it as deleting an address causes
009a47703a99 BSD: don't listen to own route messages
Roy Marples <roy@marples.name>
parents: 4324
diff changeset
1447 * dhcpcd to drop any lease to which it belongs.
4984
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1448 * Also check an added address was really added.
4326
009a47703a99 BSD: don't listen to own route messages
Roy Marples <roy@marples.name>
parents: 4324
diff changeset
1449 */
4987
9e85855c49b6 BSD: Improve RTM_NEWADDR/RTM_DELADDR validaton some more
Roy Marples <roy@marples.name>
parents: 4985
diff changeset
1450 flags = if_addrflags6(ifp, &addr6, NULL);
9e85855c49b6 BSD: Improve RTM_NEWADDR/RTM_DELADDR validaton some more
Roy Marples <roy@marples.name>
parents: 4985
diff changeset
1451 if (flags == -1) {
5014
c785a95166d8 BSD: Don't log an error failing to get inet6 adress flags
Roy Marples <roy@marples.name>
parents: 5004
diff changeset
1452 if (errno != ENXIO && errno != EADDRNOTAVAIL)
4987
9e85855c49b6 BSD: Improve RTM_NEWADDR/RTM_DELADDR validaton some more
Roy Marples <roy@marples.name>
parents: 4985
diff changeset
1453 logerr("%s: if_addrflags6", __func__);
9e85855c49b6 BSD: Improve RTM_NEWADDR/RTM_DELADDR validaton some more
Roy Marples <roy@marples.name>
parents: 4985
diff changeset
1454 if (ifam->ifam_type != RTM_DELADDR)
4326
009a47703a99 BSD: don't listen to own route messages
Roy Marples <roy@marples.name>
parents: 4324
diff changeset
1455 break;
4984
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1456 flags = 0;
4987
9e85855c49b6 BSD: Improve RTM_NEWADDR/RTM_DELADDR validaton some more
Roy Marples <roy@marples.name>
parents: 4985
diff changeset
1457 } else if (ifam->ifam_type == RTM_DELADDR)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1458 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1459
4181
4224319f0887 BSD: Strip scope from link-local addresses for KAME stacks
Roy Marples <roy@marples.name>
parents: 4165
diff changeset
1460 #ifdef __KAME__
4224319f0887 BSD: Strip scope from link-local addresses for KAME stacks
Roy Marples <roy@marples.name>
parents: 4165
diff changeset
1461 if (IN6_IS_ADDR_LINKLOCAL(&addr6))
4224319f0887 BSD: Strip scope from link-local addresses for KAME stacks
Roy Marples <roy@marples.name>
parents: 4165
diff changeset
1462 /* Remove the scope from the address */
4224319f0887 BSD: Strip scope from link-local addresses for KAME stacks
Roy Marples <roy@marples.name>
parents: 4165
diff changeset
1463 addr6.s6_addr[2] = addr6.s6_addr[3] = '\0';
4224319f0887 BSD: Strip scope from link-local addresses for KAME stacks
Roy Marples <roy@marples.name>
parents: 4165
diff changeset
1464 #endif
4224319f0887 BSD: Strip scope from link-local addresses for KAME stacks
Roy Marples <roy@marples.name>
parents: 4165
diff changeset
1465
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1466 ipv6_handleifa(ctx, ifam->ifam_type, NULL,
4984
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1467 ifp->name, &addr6, ipv6_prefixlen(&mask6), flags, pid);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1468 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1469 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1470 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1471 }
4502
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1472
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1473 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
1474 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1475
4502
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1476 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
1477 if_dispatch(struct dhcpcd_ctx *ctx, const struct rt_msghdr *rtm)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1478 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1479
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1480 if (rtm->rtm_version != RTM_VERSION)
4502
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1481 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
1482
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1483 switch(rtm->rtm_type) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1484 #ifdef RTM_IFANNOUNCE
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1485 case RTM_IFANNOUNCE:
4502
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1486 return if_announce(ctx, (const void *)rtm);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1487 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1488 case RTM_IFINFO:
4502
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1489 return if_ifinfo(ctx, (const void *)rtm);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1490 case RTM_ADD: /* FALLTHROUGH */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1491 case RTM_CHANGE: /* FALLTHROUGH */
4678
f61e4eeb8351 BSD: Handle RTM_MISS
Roy Marples <roy@marples.name>
parents: 4672
diff changeset
1492 case RTM_DELETE: /* FALLTHROUGH */
f61e4eeb8351 BSD: Handle RTM_MISS
Roy Marples <roy@marples.name>
parents: 4672
diff changeset
1493 case RTM_MISS:
4502
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1494 return if_rtm(ctx, (const void *)rtm);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1495 #ifdef RTM_CHGADDR
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1496 case RTM_CHGADDR: /* FALLTHROUGH */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1497 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1498 case RTM_DELADDR: /* FALLTHROUGH */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1499 case RTM_NEWADDR:
4502
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1500 return if_ifa(ctx, (const void *)rtm);
4235
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4232
diff changeset
1501 #ifdef RTM_DESYNC
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4232
diff changeset
1502 case RTM_DESYNC:
4565
a5889b07c310 OpenBSD: Fix compile.
Roy Marples <roy@marples.name>
parents: 4548
diff changeset
1503 dhcpcd_linkoverflow(ctx);
4611
cb9637799511 FreeBSD: warn that we cannot detect overflow on the route socket.
Roy Marples <roy@marples.name>
parents: 4604
diff changeset
1504 #elif !defined(SO_RERROR)
cb9637799511 FreeBSD: warn that we cannot detect overflow on the route socket.
Roy Marples <roy@marples.name>
parents: 4604
diff changeset
1505 #warning cannot detect route socket overflow within kernel
4235
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4232
diff changeset
1506 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1507 }
4503
9784c3171a22 BSD: Ignore coverity errors
Roy Marples <roy@marples.name>
parents: 4502
diff changeset
1508
9784c3171a22 BSD: Ignore coverity errors
Roy Marples <roy@marples.name>
parents: 4502
diff changeset
1509 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
1510 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1511
5057
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1512 static int
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1513 if_missfilter0(struct dhcpcd_ctx *ctx, struct interface *ifp,
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1514 struct sockaddr *sa)
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1515 {
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1516 size_t salen = (size_t)RT_ROUNDUP(sa->sa_len);
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1517 size_t newlen = ctx->rt_missfilterlen + salen;
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1518 size_t diff = salen - (sa->sa_len);
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1519 uint8_t *cp;
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1520
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1521 if (ctx->rt_missfiltersize < newlen) {
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1522 void *n = realloc(ctx->rt_missfilter, newlen);
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1523 if (n == NULL)
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1524 return -1;
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1525 ctx->rt_missfilter = n;
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1526 ctx->rt_missfiltersize = newlen;
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1527 }
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1528
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1529 #ifdef INET6
5087
6d80da6b2f56 BSD: use satosin6 rather than a direct cast
Roy Marples <roy@marples.name>
parents: 5058
diff changeset
1530 if (sa->sa_family == AF_INET6)
5195
45226e01fbdd inet6: Move BSD get/set scope function to ipv6 for general use
Roy Marples <roy@marples.name>
parents: 5177
diff changeset
1531 ipv6_setscope(satosin6(sa), ifp->index);
5112
899adcd7f449 Fix build without INET or INET6
Roy Marples <roy@marples.name>
parents: 5097
diff changeset
1532 #else
899adcd7f449 Fix build without INET or INET6
Roy Marples <roy@marples.name>
parents: 5097
diff changeset
1533 UNUSED(ifp);
5057
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1534 #endif
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1535
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1536 cp = ctx->rt_missfilter + ctx->rt_missfilterlen;
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1537 memcpy(cp, sa, sa->sa_len);
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1538 if (diff != 0)
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1539 memset(cp + sa->sa_len, 0, diff);
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1540 ctx->rt_missfilterlen += salen;
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1541
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1542 #ifdef INET6
5087
6d80da6b2f56 BSD: use satosin6 rather than a direct cast
Roy Marples <roy@marples.name>
parents: 5058
diff changeset
1543 if (sa->sa_family == AF_INET6)
5195
45226e01fbdd inet6: Move BSD get/set scope function to ipv6 for general use
Roy Marples <roy@marples.name>
parents: 5177
diff changeset
1544 ipv6_setscope(satosin6(sa), 0);
5057
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1545 #endif
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1546
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1547 return 0;
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1548 }
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1549
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1550 int
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1551 if_missfilter(struct interface *ifp, struct sockaddr *sa)
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1552 {
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1553
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1554 return if_missfilter0(ifp->ctx, ifp, sa);
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1555 }
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1556
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1557 int
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1558 if_missfilter_apply(struct dhcpcd_ctx *ctx)
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1559 {
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1560 #ifdef RO_MISSFILTER
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1561 if (ctx->rt_missfilterlen == 0) {
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1562 struct sockaddr sa = {
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1563 .sa_family = AF_UNSPEC,
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1564 .sa_len = sizeof(sa),
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1565 };
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1566
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1567 if (if_missfilter0(ctx, NULL, &sa) == -1)
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1568 return -1;
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1569 }
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1570
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1571 return setsockopt(ctx->link_fd, PF_ROUTE, RO_MISSFILTER,
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1572 ctx->rt_missfilter, (socklen_t)ctx->rt_missfilterlen);
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1573 #else
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1574 #warning kernel does not support RTM_MISS DST filtering
5097
8c82e8beb9cb FreeBSD: Remove unused compile warning
Roy Marples <roy@marples.name>
parents: 5087
diff changeset
1575 UNUSED(ctx);
5057
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1576 errno = ENOTSUP;
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1577 return -1;
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1578 #endif
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1579 }
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1580
4628
8408291093fd BSD: Address some coverity issues
Roy Marples <roy@marples.name>
parents: 4615
diff changeset
1581 __CTASSERT(offsetof(struct rt_msghdr, rtm_msglen) == 0);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1582 int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1583 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
1584 {
4437
5f768f1d37ad BSD: Simplify rtm usage
Roy Marples <roy@marples.name>
parents: 4422
diff changeset
1585 struct rtm rtm;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1586 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
1587
4612
a19f5fd758f6 BSD: Use read instead of recvmsg
Roy Marples <roy@marples.name>
parents: 4604
diff changeset
1588 len = read(ctx->link_fd, &rtm, sizeof(rtm));
4235
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4232
diff changeset
1589 if (len == -1)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1590 return -1;
4502
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1591 if (len == 0)
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1592 return 0;
4628
8408291093fd BSD: Address some coverity issues
Roy Marples <roy@marples.name>
parents: 4615
diff changeset
1593 if ((size_t)len < sizeof(rtm.hdr.rtm_msglen) ||
8408291093fd BSD: Address some coverity issues
Roy Marples <roy@marples.name>
parents: 4615
diff changeset
1594 len != rtm.hdr.rtm_msglen)
8408291093fd BSD: Address some coverity issues
Roy Marples <roy@marples.name>
parents: 4615
diff changeset
1595 {
4502
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1596 errno = EINVAL;
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1597 return -1;
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1598 }
4628
8408291093fd BSD: Address some coverity issues
Roy Marples <roy@marples.name>
parents: 4615
diff changeset
1599 /*
8408291093fd BSD: Address some coverity issues
Roy Marples <roy@marples.name>
parents: 4615
diff changeset
1600 * Coverity thinks that the data could be tainted from here.
8408291093fd BSD: Address some coverity issues
Roy Marples <roy@marples.name>
parents: 4615
diff changeset
1601 * I have no idea how because the length of the data we read
8408291093fd BSD: Address some coverity issues
Roy Marples <roy@marples.name>
parents: 4615
diff changeset
1602 * is guarded by len and checked to match rtm_msglen.
8408291093fd BSD: Address some coverity issues
Roy Marples <roy@marples.name>
parents: 4615
diff changeset
1603 * The issue seems to be related to extracting the addresses
8408291093fd BSD: Address some coverity issues
Roy Marples <roy@marples.name>
parents: 4615
diff changeset
1604 * at the end of the header, but seems to have no issues with the
8408291093fd BSD: Address some coverity issues
Roy Marples <roy@marples.name>
parents: 4615
diff changeset
1605 * equivalent call in if_initrt.
8408291093fd BSD: Address some coverity issues
Roy Marples <roy@marples.name>
parents: 4615
diff changeset
1606 */
4643
6aa99a23a825 BSD: Dismiss a coverity error
Roy Marples <roy@marples.name>
parents: 4628
diff changeset
1607 /* coverity[tainted_data] */
4502
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1608 return if_dispatch(ctx, &rtm.hdr);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1609 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1610
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1611 #ifndef SYS_NMLN /* OSX */
5207
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5206
diff changeset
1612 # define SYS_NMLN __SYS_NAMELEN
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1613 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1614 #ifndef HW_MACHINE_ARCH
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1615 # ifdef HW_MODEL /* OpenBSD */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1616 # define HW_MACHINE_ARCH HW_MODEL
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1617 # endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1618 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1619 int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1620 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
1621 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1622 int mib[2] = { CTL_HW, HW_MACHINE_ARCH };
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1623
5207
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5206
diff changeset
1624 return sysctl(mib, sizeof(mib) / sizeof(mib[0]), str, &len, NULL, 0);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1625 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1626
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1627 #ifdef INET6
4220
14058f9c6962 Satisfy FreeBSD and NetBSD.
Roy Marples <roy@marples.name>
parents: 4219
diff changeset
1628 #if (defined(IPV6CTL_ACCEPT_RTADV) && !defined(ND6_IFF_ACCEPT_RTADV)) || \
4335
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
1629 defined(IPV6CTL_FORWARDING)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1630 #define get_inet6_sysctl(code) inet6_sysctl(code, 0, 0)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1631 #define set_inet6_sysctl(code, val) inet6_sysctl(code, val, 1)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1632 static int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1633 inet6_sysctl(int code, int val, int action)
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 int mib[] = { CTL_NET, PF_INET6, IPPROTO_IPV6, 0 };
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1636 size_t size;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1637
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1638 mib[3] = code;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1639 size = sizeof(val);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1640 if (action) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1641 if (sysctl(mib, sizeof(mib)/sizeof(mib[0]),
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1642 NULL, 0, &val, size) == -1)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1643 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1644 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1645 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1646 if (sysctl(mib, sizeof(mib)/sizeof(mib[0]), &val, &size, NULL, 0) == -1)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1647 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1648 return val;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1649 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1650 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1651
4813
ef33eb73e97d INET6: Apply hoplimit, reachable and retrans timer values from RA.
Roy Marples <roy@marples.name>
parents: 4799
diff changeset
1652 int
ef33eb73e97d INET6: Apply hoplimit, reachable and retrans timer values from RA.
Roy Marples <roy@marples.name>
parents: 4799
diff changeset
1653 if_applyra(const struct ra *rap)
ef33eb73e97d INET6: Apply hoplimit, reachable and retrans timer values from RA.
Roy Marples <roy@marples.name>
parents: 4799
diff changeset
1654 {
4817
92d3d8e9960c OpenBSD: Fix prior - OS cannot set any RA bits such as hop limit.
Roy Marples <roy@marples.name>
parents: 4816
diff changeset
1655 #ifdef SIOCSIFINFO_IN6
5020
d5297c3e1e7f BSD: When applying RA base information, get info without privsep
Roy Marples <roy@marples.name>
parents: 5019
diff changeset
1656 struct in6_ndireq nd = { .ndi.chlim = 0 };
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
1657 struct dhcpcd_ctx *ctx = rap->iface->ctx;
4818
22acf0138b3a BSD: Try and set linkmtu for the interface just to be nice.
Roy Marples <roy@marples.name>
parents: 4817
diff changeset
1658 int error;
4813
ef33eb73e97d INET6: Apply hoplimit, reachable and retrans timer values from RA.
Roy Marples <roy@marples.name>
parents: 4799
diff changeset
1659
5020
d5297c3e1e7f BSD: When applying RA base information, get info without privsep
Roy Marples <roy@marples.name>
parents: 5019
diff changeset
1660 strlcpy(nd.ifname, rap->iface->name, sizeof(nd.ifname));
5177
1d16a9434290 NetBSD: Gear up for kernel RA removal.
Roy Marples <roy@marples.name>
parents: 5173
diff changeset
1661
1d16a9434290 NetBSD: Gear up for kernel RA removal.
Roy Marples <roy@marples.name>
parents: 5173
diff changeset
1662 #ifdef IPV6CTL_ACCEPT_RTADV
1d16a9434290 NetBSD: Gear up for kernel RA removal.
Roy Marples <roy@marples.name>
parents: 5173
diff changeset
1663 struct priv *priv = ctx->priv;
1d16a9434290 NetBSD: Gear up for kernel RA removal.
Roy Marples <roy@marples.name>
parents: 5173
diff changeset
1664
1d16a9434290 NetBSD: Gear up for kernel RA removal.
Roy Marples <roy@marples.name>
parents: 5173
diff changeset
1665 /*
1d16a9434290 NetBSD: Gear up for kernel RA removal.
Roy Marples <roy@marples.name>
parents: 5173
diff changeset
1666 * NetBSD changed SIOCSIFINFO_IN6 to NOT set flags when kernel
1d16a9434290 NetBSD: Gear up for kernel RA removal.
Roy Marples <roy@marples.name>
parents: 5173
diff changeset
1667 * RA was removed, however both FreeBSD and DragonFlyBSD still do.
1d16a9434290 NetBSD: Gear up for kernel RA removal.
Roy Marples <roy@marples.name>
parents: 5173
diff changeset
1668 * linkmtu was also removed.
1d16a9434290 NetBSD: Gear up for kernel RA removal.
Roy Marples <roy@marples.name>
parents: 5173
diff changeset
1669 * Hopefully this guard will still work if either remove kernel RA.
1d16a9434290 NetBSD: Gear up for kernel RA removal.
Roy Marples <roy@marples.name>
parents: 5173
diff changeset
1670 */
5020
d5297c3e1e7f BSD: When applying RA base information, get info without privsep
Roy Marples <roy@marples.name>
parents: 5019
diff changeset
1671 if (ioctl(priv->pf_inet6_fd, SIOCGIFINFO_IN6, &nd, sizeof(nd)) == -1)
4813
ef33eb73e97d INET6: Apply hoplimit, reachable and retrans timer values from RA.
Roy Marples <roy@marples.name>
parents: 4799
diff changeset
1672 return -1;
ef33eb73e97d INET6: Apply hoplimit, reachable and retrans timer values from RA.
Roy Marples <roy@marples.name>
parents: 4799
diff changeset
1673
5020
d5297c3e1e7f BSD: When applying RA base information, get info without privsep
Roy Marples <roy@marples.name>
parents: 5019
diff changeset
1674 nd.ndi.linkmtu = rap->mtu;
5177
1d16a9434290 NetBSD: Gear up for kernel RA removal.
Roy Marples <roy@marples.name>
parents: 5173
diff changeset
1675 #endif
1d16a9434290 NetBSD: Gear up for kernel RA removal.
Roy Marples <roy@marples.name>
parents: 5173
diff changeset
1676
5020
d5297c3e1e7f BSD: When applying RA base information, get info without privsep
Roy Marples <roy@marples.name>
parents: 5019
diff changeset
1677 nd.ndi.chlim = rap->hoplimit;
d5297c3e1e7f BSD: When applying RA base information, get info without privsep
Roy Marples <roy@marples.name>
parents: 5019
diff changeset
1678 nd.ndi.retrans = rap->retrans;
d5297c3e1e7f BSD: When applying RA base information, get info without privsep
Roy Marples <roy@marples.name>
parents: 5019
diff changeset
1679 nd.ndi.basereachable = rap->reachable;
d5297c3e1e7f BSD: When applying RA base information, get info without privsep
Roy Marples <roy@marples.name>
parents: 5019
diff changeset
1680 error = if_ioctl6(ctx, SIOCSIFINFO_IN6, &nd, sizeof(nd));
5177
1d16a9434290 NetBSD: Gear up for kernel RA removal.
Roy Marples <roy@marples.name>
parents: 5173
diff changeset
1681 #ifdef IPV6CTL_ACCEPT_RTADV
4818
22acf0138b3a BSD: Try and set linkmtu for the interface just to be nice.
Roy Marples <roy@marples.name>
parents: 4817
diff changeset
1682 if (error == -1 && errno == EINVAL) {
22acf0138b3a BSD: Try and set linkmtu for the interface just to be nice.
Roy Marples <roy@marples.name>
parents: 4817
diff changeset
1683 /*
22acf0138b3a BSD: Try and set linkmtu for the interface just to be nice.
Roy Marples <roy@marples.name>
parents: 4817
diff changeset
1684 * Very likely that this is caused by a dodgy MTU
22acf0138b3a BSD: Try and set linkmtu for the interface just to be nice.
Roy Marples <roy@marples.name>
parents: 4817
diff changeset
1685 * setting specific to the interface.
22acf0138b3a BSD: Try and set linkmtu for the interface just to be nice.
Roy Marples <roy@marples.name>
parents: 4817
diff changeset
1686 * Let's set it to "unspecified" and try again.
22acf0138b3a BSD: Try and set linkmtu for the interface just to be nice.
Roy Marples <roy@marples.name>
parents: 4817
diff changeset
1687 * Doesn't really matter as we fix the MTU against the
22acf0138b3a BSD: Try and set linkmtu for the interface just to be nice.
Roy Marples <roy@marples.name>
parents: 4817
diff changeset
1688 * routes we add as not all OS support SIOCSIFINFO_IN6.
22acf0138b3a BSD: Try and set linkmtu for the interface just to be nice.
Roy Marples <roy@marples.name>
parents: 4817
diff changeset
1689 */
5020
d5297c3e1e7f BSD: When applying RA base information, get info without privsep
Roy Marples <roy@marples.name>
parents: 5019
diff changeset
1690 nd.ndi.linkmtu = 0;
d5297c3e1e7f BSD: When applying RA base information, get info without privsep
Roy Marples <roy@marples.name>
parents: 5019
diff changeset
1691 error = if_ioctl6(ctx, SIOCSIFINFO_IN6, &nd, sizeof(nd));
4818
22acf0138b3a BSD: Try and set linkmtu for the interface just to be nice.
Roy Marples <roy@marples.name>
parents: 4817
diff changeset
1692 }
5177
1d16a9434290 NetBSD: Gear up for kernel RA removal.
Roy Marples <roy@marples.name>
parents: 5173
diff changeset
1693 #endif
4818
22acf0138b3a BSD: Try and set linkmtu for the interface just to be nice.
Roy Marples <roy@marples.name>
parents: 4817
diff changeset
1694 return error;
4817
92d3d8e9960c OpenBSD: Fix prior - OS cannot set any RA bits such as hop limit.
Roy Marples <roy@marples.name>
parents: 4816
diff changeset
1695 #else
92d3d8e9960c OpenBSD: Fix prior - OS cannot set any RA bits such as hop limit.
Roy Marples <roy@marples.name>
parents: 4816
diff changeset
1696 #warning OS does not allow setting of RA bits hoplimit, retrans or reachable
92d3d8e9960c OpenBSD: Fix prior - OS cannot set any RA bits such as hop limit.
Roy Marples <roy@marples.name>
parents: 4816
diff changeset
1697 UNUSED(rap);
92d3d8e9960c OpenBSD: Fix prior - OS cannot set any RA bits such as hop limit.
Roy Marples <roy@marples.name>
parents: 4816
diff changeset
1698 return 0;
92d3d8e9960c OpenBSD: Fix prior - OS cannot set any RA bits such as hop limit.
Roy Marples <roy@marples.name>
parents: 4816
diff changeset
1699 #endif
4813
ef33eb73e97d INET6: Apply hoplimit, reachable and retrans timer values from RA.
Roy Marples <roy@marples.name>
parents: 4799
diff changeset
1700 }
ef33eb73e97d INET6: Apply hoplimit, reachable and retrans timer values from RA.
Roy Marples <roy@marples.name>
parents: 4799
diff changeset
1701
5153
8248b3a04908 inet6: Add 'temporary' directive to the slaac option
Roy Marples <roy@marples.name>
parents: 5152
diff changeset
1702 #ifndef IPV6CTL_FORWARDING
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1703 #define get_inet6_sysctlbyname(code) inet6_sysctlbyname(code, 0, 0)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1704 #define set_inet6_sysctlbyname(code, val) inet6_sysctlbyname(code, val, 1)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1705 static int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1706 inet6_sysctlbyname(const char *name, int val, int action)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1707 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1708 size_t size;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1709
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1710 size = sizeof(val);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1711 if (action) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1712 if (sysctlbyname(name, NULL, 0, &val, size) == -1)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1713 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1714 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1715 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1716 if (sysctlbyname(name, &val, &size, NULL, 0) == -1)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1717 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1718 return val;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1719 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1720 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1721
4335
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
1722 int
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
1723 ip6_forwarding(__unused const char *ifname)
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
1724 {
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
1725 int val;
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
1726
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
1727 #ifdef IPV6CTL_FORWARDING
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
1728 val = get_inet6_sysctl(IPV6CTL_FORWARDING);
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
1729 #else
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
1730 val = get_inet6_sysctlbyname("net.inet6.ip6.forwarding");
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
1731 #endif
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
1732 return val < 0 ? 0 : val;
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
1733 }
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
1734
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1735 #ifdef SIOCIFAFATTACH
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1736 static int
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
1737 if_af_attach(const struct interface *ifp, int af)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1738 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1739 struct if_afreq ifar;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1740
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1741 strlcpy(ifar.ifar_name, ifp->name, sizeof(ifar.ifar_name));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1742 ifar.ifar_af = af;
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
1743 return if_ioctl6(ifp->ctx, SIOCIFAFATTACH, &ifar, sizeof(ifar));
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1744 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1745 #endif
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 #ifdef SIOCGIFXFLAGS
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1748 static int
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
1749 if_set_ifxflags(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
1750 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1751 struct ifreq ifr;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1752 int flags;
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
1753 struct priv *priv = ifp->ctx->priv;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1754
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1755 strlcpy(ifr.ifr_name, ifp->name, sizeof(ifr.ifr_name));
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
1756 if (ioctl(priv->pf_inet6_fd, SIOCGIFXFLAGS, &ifr) == -1)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1757 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1758 flags = ifr.ifr_flags;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1759 #ifdef IFXF_NOINET6
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1760 flags &= ~IFXF_NOINET6;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1761 #endif
4218
f618f850efdc inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1762 /*
4229
12388193ccdc inet6: remove references to the crazies.
Roy Marples <roy@marples.name>
parents: 4220
diff changeset
1763 * 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: 4220
diff changeset
1764 * If we need to, we should have another option actively disable it.
4321
c9409ab7664d OpenBSD: Allow dhcpcd to work alongside slaacd
Roy Marples <roy@marples.name>
parents: 4301
diff changeset
1765 *
c9409ab7664d OpenBSD: Allow dhcpcd to work alongside slaacd
Roy Marples <roy@marples.name>
parents: 4301
diff changeset
1766 * OpenBSD moved from kernel based SLAAC to userland via slaacd(8).
c9409ab7664d OpenBSD: Allow dhcpcd to work alongside slaacd
Roy Marples <roy@marples.name>
parents: 4301
diff changeset
1767 * It has a similar featureset to dhcpcd such as stable private
c9409ab7664d OpenBSD: Allow dhcpcd to work alongside slaacd
Roy Marples <roy@marples.name>
parents: 4301
diff changeset
1768 * addresses, but lacks the ability to handle DNS inside the RA
c9409ab7664d OpenBSD: Allow dhcpcd to work alongside slaacd
Roy Marples <roy@marples.name>
parents: 4301
diff changeset
1769 * which is a serious shortfall in this day and age.
c9409ab7664d OpenBSD: Allow dhcpcd to work alongside slaacd
Roy Marples <roy@marples.name>
parents: 4301
diff changeset
1770 * Appease their user base by working alongside slaacd(8) if
c9409ab7664d OpenBSD: Allow dhcpcd to work alongside slaacd
Roy Marples <roy@marples.name>
parents: 4301
diff changeset
1771 * dhcpcd is instructed not to do auto configuration of addresses.
4218
f618f850efdc inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1772 */
4321
c9409ab7664d OpenBSD: Allow dhcpcd to work alongside slaacd
Roy Marples <roy@marples.name>
parents: 4301
diff changeset
1773 #if defined(ND6_IFF_ACCEPT_RTADV)
c9409ab7664d OpenBSD: Allow dhcpcd to work alongside slaacd
Roy Marples <roy@marples.name>
parents: 4301
diff changeset
1774 #define BSD_AUTOCONF DHCPCD_IPV6RS
c9409ab7664d OpenBSD: Allow dhcpcd to work alongside slaacd
Roy Marples <roy@marples.name>
parents: 4301
diff changeset
1775 #else
c9409ab7664d OpenBSD: Allow dhcpcd to work alongside slaacd
Roy Marples <roy@marples.name>
parents: 4301
diff changeset
1776 #define BSD_AUTOCONF DHCPCD_IPV6RA_AUTOCONF
c9409ab7664d OpenBSD: Allow dhcpcd to work alongside slaacd
Roy Marples <roy@marples.name>
parents: 4301
diff changeset
1777 #endif
c9409ab7664d OpenBSD: Allow dhcpcd to work alongside slaacd
Roy Marples <roy@marples.name>
parents: 4301
diff changeset
1778 if (ifp->options->options & BSD_AUTOCONF)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1779 flags &= ~IFXF_AUTOCONF6;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1780 if (ifr.ifr_flags == flags)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1781 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1782 ifr.ifr_flags = flags;
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
1783 return if_ioctl6(ifp->ctx, SIOCSIFXFLAGS, &ifr, sizeof(ifr));
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1784 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1785 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1786
4118
ed1a6b24e5d2 if-bsd: compile on recent OpenBSD without ND6 flags
Roy Marples <roy@marples.name>
parents: 4103
diff changeset
1787 /* OpenBSD removed ND6 flags entirely, so we need to check for their
4218
f618f850efdc inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1788 * existance. */
4118
ed1a6b24e5d2 if-bsd: compile on recent OpenBSD without ND6 flags
Roy Marples <roy@marples.name>
parents: 4103
diff changeset
1789 #if defined(ND6_IFF_AUTO_LINKLOCAL) || \
ed1a6b24e5d2 if-bsd: compile on recent OpenBSD without ND6 flags
Roy Marples <roy@marples.name>
parents: 4103
diff changeset
1790 defined(ND6_IFF_PERFORMNUD) || \
ed1a6b24e5d2 if-bsd: compile on recent OpenBSD without ND6 flags
Roy Marples <roy@marples.name>
parents: 4103
diff changeset
1791 defined(ND6_IFF_ACCEPT_RTADV) || \
ed1a6b24e5d2 if-bsd: compile on recent OpenBSD without ND6 flags
Roy Marples <roy@marples.name>
parents: 4103
diff changeset
1792 defined(ND6_IFF_OVERRIDE_RTADV) || \
ed1a6b24e5d2 if-bsd: compile on recent OpenBSD without ND6 flags
Roy Marples <roy@marples.name>
parents: 4103
diff changeset
1793 defined(ND6_IFF_IFDISABLED)
ed1a6b24e5d2 if-bsd: compile on recent OpenBSD without ND6 flags
Roy Marples <roy@marples.name>
parents: 4103
diff changeset
1794 #define ND6_NDI_FLAGS
ed1a6b24e5d2 if-bsd: compile on recent OpenBSD without ND6 flags
Roy Marples <roy@marples.name>
parents: 4103
diff changeset
1795 #endif
ed1a6b24e5d2 if-bsd: compile on recent OpenBSD without ND6 flags
Roy Marples <roy@marples.name>
parents: 4103
diff changeset
1796
4218
f618f850efdc inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1797 void
4799
95842881a2ef BSD: Disable kernel RTADV sysctl earlier
Roy Marples <roy@marples.name>
parents: 4751
diff changeset
1798 if_disable_rtadv(void)
95842881a2ef BSD: Disable kernel RTADV sysctl earlier
Roy Marples <roy@marples.name>
parents: 4751
diff changeset
1799 {
95842881a2ef BSD: Disable kernel RTADV sysctl earlier
Roy Marples <roy@marples.name>
parents: 4751
diff changeset
1800 #if defined(IPV6CTL_ACCEPT_RTADV) && !defined(ND6_IFF_ACCEPT_RTADV)
95842881a2ef BSD: Disable kernel RTADV sysctl earlier
Roy Marples <roy@marples.name>
parents: 4751
diff changeset
1801 int ra = get_inet6_sysctl(IPV6CTL_ACCEPT_RTADV);
95842881a2ef BSD: Disable kernel RTADV sysctl earlier
Roy Marples <roy@marples.name>
parents: 4751
diff changeset
1802
95842881a2ef BSD: Disable kernel RTADV sysctl earlier
Roy Marples <roy@marples.name>
parents: 4751
diff changeset
1803 if (ra == -1) {
95842881a2ef BSD: Disable kernel RTADV sysctl earlier
Roy Marples <roy@marples.name>
parents: 4751
diff changeset
1804 if (errno != ENOENT)
95842881a2ef BSD: Disable kernel RTADV sysctl earlier
Roy Marples <roy@marples.name>
parents: 4751
diff changeset
1805 logerr("IPV6CTL_ACCEPT_RTADV");
95842881a2ef BSD: Disable kernel RTADV sysctl earlier
Roy Marples <roy@marples.name>
parents: 4751
diff changeset
1806 else if (ra != 0)
95842881a2ef BSD: Disable kernel RTADV sysctl earlier
Roy Marples <roy@marples.name>
parents: 4751
diff changeset
1807 if (set_inet6_sysctl(IPV6CTL_ACCEPT_RTADV, 0) == -1)
95842881a2ef BSD: Disable kernel RTADV sysctl earlier
Roy Marples <roy@marples.name>
parents: 4751
diff changeset
1808 logerr("IPV6CTL_ACCEPT_RTADV");
95842881a2ef BSD: Disable kernel RTADV sysctl earlier
Roy Marples <roy@marples.name>
parents: 4751
diff changeset
1809 }
95842881a2ef BSD: Disable kernel RTADV sysctl earlier
Roy Marples <roy@marples.name>
parents: 4751
diff changeset
1810 #endif
95842881a2ef BSD: Disable kernel RTADV sysctl earlier
Roy Marples <roy@marples.name>
parents: 4751
diff changeset
1811 }
95842881a2ef BSD: Disable kernel RTADV sysctl earlier
Roy Marples <roy@marples.name>
parents: 4751
diff changeset
1812
95842881a2ef BSD: Disable kernel RTADV sysctl earlier
Roy Marples <roy@marples.name>
parents: 4751
diff changeset
1813 void
4218
f618f850efdc inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1814 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
1815 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1816 struct priv *priv;
4218
f618f850efdc inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1817 int s;
f618f850efdc inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1818 #ifdef ND6_NDI_FLAGS
f618f850efdc inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1819 struct in6_ndireq nd;
5019
b7da0da3e019 Revert "BSD: When applying RA base information, ensure flags are correct"
Roy Marples <roy@marples.name>
parents: 5018
diff changeset
1820 int flags;
4218
f618f850efdc inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1821 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1822
4218
f618f850efdc inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1823 priv = (struct priv *)ifp->ctx->priv;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1824 s = priv->pf_inet6_fd;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1825
4118
ed1a6b24e5d2 if-bsd: compile on recent OpenBSD without ND6 flags
Roy Marples <roy@marples.name>
parents: 4103
diff changeset
1826 #ifdef ND6_NDI_FLAGS
4218
f618f850efdc inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1827 memset(&nd, 0, sizeof(nd));
f618f850efdc inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1828 strlcpy(nd.ifname, ifp->name, sizeof(nd.ifname));
f618f850efdc inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1829 if (ioctl(s, SIOCGIFINFO_IN6, &nd) == -1)
5019
b7da0da3e019 Revert "BSD: When applying RA base information, ensure flags are correct"
Roy Marples <roy@marples.name>
parents: 5018
diff changeset
1830 logerr("%s: SIOCGIFINFO_FLAGS", ifp->name);
b7da0da3e019 Revert "BSD: When applying RA base information, ensure flags are correct"
Roy Marples <roy@marples.name>
parents: 5018
diff changeset
1831 flags = (int)nd.ndi.flags;
b7da0da3e019 Revert "BSD: When applying RA base information, ensure flags are correct"
Roy Marples <roy@marples.name>
parents: 5018
diff changeset
1832 #endif
b7da0da3e019 Revert "BSD: When applying RA base information, ensure flags are correct"
Roy Marples <roy@marples.name>
parents: 5018
diff changeset
1833
b7da0da3e019 Revert "BSD: When applying RA base information, ensure flags are correct"
Roy Marples <roy@marples.name>
parents: 5018
diff changeset
1834 #ifdef ND6_IFF_AUTO_LINKLOCAL
5173
81f78bbc8d48 Whitespace
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
1835 /* Unlike the kernel, dhcpcd make make a stable private address. */
5019
b7da0da3e019 Revert "BSD: When applying RA base information, ensure flags are correct"
Roy Marples <roy@marples.name>
parents: 5018
diff changeset
1836 flags &= ~ND6_IFF_AUTO_LINKLOCAL;
b7da0da3e019 Revert "BSD: When applying RA base information, ensure flags are correct"
Roy Marples <roy@marples.name>
parents: 5018
diff changeset
1837 #endif
b7da0da3e019 Revert "BSD: When applying RA base information, ensure flags are correct"
Roy Marples <roy@marples.name>
parents: 5018
diff changeset
1838
b7da0da3e019 Revert "BSD: When applying RA base information, ensure flags are correct"
Roy Marples <roy@marples.name>
parents: 5018
diff changeset
1839 #ifdef ND6_IFF_PERFORMNUD
b7da0da3e019 Revert "BSD: When applying RA base information, ensure flags are correct"
Roy Marples <roy@marples.name>
parents: 5018
diff changeset
1840 /* NUD is kind of essential. */
b7da0da3e019 Revert "BSD: When applying RA base information, ensure flags are correct"
Roy Marples <roy@marples.name>
parents: 5018
diff changeset
1841 flags |= ND6_IFF_PERFORMNUD;
b7da0da3e019 Revert "BSD: When applying RA base information, ensure flags are correct"
Roy Marples <roy@marples.name>
parents: 5018
diff changeset
1842 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1843
5019
b7da0da3e019 Revert "BSD: When applying RA base information, ensure flags are correct"
Roy Marples <roy@marples.name>
parents: 5018
diff changeset
1844 #ifdef ND6_IFF_IFDISABLED
b7da0da3e019 Revert "BSD: When applying RA base information, ensure flags are correct"
Roy Marples <roy@marples.name>
parents: 5018
diff changeset
1845 /* Ensure the interface is not disabled. */
b7da0da3e019 Revert "BSD: When applying RA base information, ensure flags are correct"
Roy Marples <roy@marples.name>
parents: 5018
diff changeset
1846 flags &= ~ND6_IFF_IFDISABLED;
b7da0da3e019 Revert "BSD: When applying RA base information, ensure flags are correct"
Roy Marples <roy@marples.name>
parents: 5018
diff changeset
1847 #endif
4218
f618f850efdc inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1848
5019
b7da0da3e019 Revert "BSD: When applying RA base information, ensure flags are correct"
Roy Marples <roy@marples.name>
parents: 5018
diff changeset
1849 /*
b7da0da3e019 Revert "BSD: When applying RA base information, ensure flags are correct"
Roy Marples <roy@marples.name>
parents: 5018
diff changeset
1850 * If not doing autoconf, don't disable the kernel from doing it.
b7da0da3e019 Revert "BSD: When applying RA base information, ensure flags are correct"
Roy Marples <roy@marples.name>
parents: 5018
diff changeset
1851 * If we need to, we should have another option actively disable it.
b7da0da3e019 Revert "BSD: When applying RA base information, ensure flags are correct"
Roy Marples <roy@marples.name>
parents: 5018
diff changeset
1852 */
b7da0da3e019 Revert "BSD: When applying RA base information, ensure flags are correct"
Roy Marples <roy@marples.name>
parents: 5018
diff changeset
1853 #ifdef ND6_IFF_ACCEPT_RTADV
b7da0da3e019 Revert "BSD: When applying RA base information, ensure flags are correct"
Roy Marples <roy@marples.name>
parents: 5018
diff changeset
1854 if (ifp->options->options & DHCPCD_IPV6RS)
b7da0da3e019 Revert "BSD: When applying RA base information, ensure flags are correct"
Roy Marples <roy@marples.name>
parents: 5018
diff changeset
1855 flags &= ~ND6_IFF_ACCEPT_RTADV;
b7da0da3e019 Revert "BSD: When applying RA base information, ensure flags are correct"
Roy Marples <roy@marples.name>
parents: 5018
diff changeset
1856 #ifdef ND6_IFF_OVERRIDE_RTADV
b7da0da3e019 Revert "BSD: When applying RA base information, ensure flags are correct"
Roy Marples <roy@marples.name>
parents: 5018
diff changeset
1857 if (ifp->options->options & DHCPCD_IPV6RS)
b7da0da3e019 Revert "BSD: When applying RA base information, ensure flags are correct"
Roy Marples <roy@marples.name>
parents: 5018
diff changeset
1858 flags |= ND6_IFF_OVERRIDE_RTADV;
b7da0da3e019 Revert "BSD: When applying RA base information, ensure flags are correct"
Roy Marples <roy@marples.name>
parents: 5018
diff changeset
1859 #endif
b7da0da3e019 Revert "BSD: When applying RA base information, ensure flags are correct"
Roy Marples <roy@marples.name>
parents: 5018
diff changeset
1860 #endif
b7da0da3e019 Revert "BSD: When applying RA base information, ensure flags are correct"
Roy Marples <roy@marples.name>
parents: 5018
diff changeset
1861
b7da0da3e019 Revert "BSD: When applying RA base information, ensure flags are correct"
Roy Marples <roy@marples.name>
parents: 5018
diff changeset
1862 #ifdef ND6_NDI_FLAGS
b7da0da3e019 Revert "BSD: When applying RA base information, ensure flags are correct"
Roy Marples <roy@marples.name>
parents: 5018
diff changeset
1863 if (nd.ndi.flags != (uint32_t)flags) {
b7da0da3e019 Revert "BSD: When applying RA base information, ensure flags are correct"
Roy Marples <roy@marples.name>
parents: 5018
diff changeset
1864 nd.ndi.flags = (uint32_t)flags;
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
1865 if (if_ioctl6(ifp->ctx, SIOCSIFINFO_FLAGS,
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
1866 &nd, sizeof(nd)) == -1)
4218
f618f850efdc inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1867 logerr("%s: SIOCSIFINFO_FLAGS", ifp->name);
f618f850efdc inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1868 }
4118
ed1a6b24e5d2 if-bsd: compile on recent OpenBSD without ND6 flags
Roy Marples <roy@marples.name>
parents: 4103
diff changeset
1869 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1870
4218
f618f850efdc inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1871 /* Enabling IPv6 by whatever means must be the
f618f850efdc inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1872 * last action undertaken to ensure kernel RS and
f618f850efdc inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1873 * LLADDR auto configuration are disabled where applicable. */
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1874 #ifdef SIOCIFAFATTACH
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
1875 if (if_af_attach(ifp, AF_INET6) == -1)
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
1876 logerr("%s: if_af_attach", ifp->name);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1877 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1878
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1879 #ifdef SIOCGIFXFLAGS
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
1880 if (if_set_ifxflags(ifp) == -1)
4218
f618f850efdc inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1881 logerr("%s: set_ifxflags", ifp->name);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1882 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1883
5152
352c272ba3c3 BSD: Dont warn if the kernel does not support flushing routers
Roy Marples <roy@marples.name>
parents: 5125
diff changeset
1884 #ifdef SIOCSRTRFLUSH_IN6
4218
f618f850efdc inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1885 /* Flush the kernel knowledge of advertised routers
f618f850efdc inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1886 * and prefixes so the kernel does not expire prefixes
f618f850efdc inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1887 * and default routes we are trying to own. */
f618f850efdc inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1888 if (ifp->options->options & DHCPCD_IPV6RS) {
4331
836ab952fde5 BSD: SIOCSRTRFLUSH_IN6 and SIOCSPFXFLUSH_IN6 require in6_ifreq
Roy Marples <roy@marples.name>
parents: 4329
diff changeset
1889 struct in6_ifreq ifr;
4218
f618f850efdc inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1890
4331
836ab952fde5 BSD: SIOCSRTRFLUSH_IN6 and SIOCSPFXFLUSH_IN6 require in6_ifreq
Roy Marples <roy@marples.name>
parents: 4329
diff changeset
1891 memset(&ifr, 0, sizeof(ifr));
836ab952fde5 BSD: SIOCSRTRFLUSH_IN6 and SIOCSPFXFLUSH_IN6 require in6_ifreq
Roy Marples <roy@marples.name>
parents: 4329
diff changeset
1892 strlcpy(ifr.ifr_name, ifp->name, sizeof(ifr.ifr_name));
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
1893 if (if_ioctl6(ifp->ctx, SIOCSRTRFLUSH_IN6,
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
1894 &ifr, sizeof(ifr)) == -1 &&
5152
352c272ba3c3 BSD: Dont warn if the kernel does not support flushing routers
Roy Marples <roy@marples.name>
parents: 5125
diff changeset
1895 errno != ENOTSUP && errno != ENOTTY)
352c272ba3c3 BSD: Dont warn if the kernel does not support flushing routers
Roy Marples <roy@marples.name>
parents: 5125
diff changeset
1896 logwarn("SIOCSRTRFLUSH_IN6 %d", errno);
352c272ba3c3 BSD: Dont warn if the kernel does not support flushing routers
Roy Marples <roy@marples.name>
parents: 5125
diff changeset
1897 #ifdef SIOCSPFXFLUSH_IN6
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
1898 if (if_ioctl6(ifp->ctx, SIOCSPFXFLUSH_IN6,
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
1899 &ifr, sizeof(ifr)) == -1 &&
5152
352c272ba3c3 BSD: Dont warn if the kernel does not support flushing routers
Roy Marples <roy@marples.name>
parents: 5125
diff changeset
1900 errno != ENOTSUP && errno != ENOTTY)
4218
f618f850efdc inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1901 logwarn("SIOCSPFXFLUSH_IN6");
5152
352c272ba3c3 BSD: Dont warn if the kernel does not support flushing routers
Roy Marples <roy@marples.name>
parents: 5125
diff changeset
1902 #endif
4218
f618f850efdc inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1903 }
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1904 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1905 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1906 #endif