annotate src/if-bsd.c @ 5571:fb1831c903f6 draft

Check for NetBSD in prior, as we did before
author Roy Marples <roy@marples.name>
date Sun, 27 Dec 2020 22:04:45 +0000
parents 80fba4edc6c5
children
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
5569
80fba4edc6c5 NetBSD: Map IP Persistance to roaming
Roy Marples <roy@marples.name>
parents: 5557
diff changeset
414 if_roaming(struct interface *ifp)
5557
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
5571
fb1831c903f6 Check for NetBSD in prior, as we did before
Roy Marples <roy@marples.name>
parents: 5569
diff changeset
417 /* Check for NetBSD as a safety measure.
fb1831c903f6 Check for NetBSD in prior, as we did before
Roy Marples <roy@marples.name>
parents: 5569
diff changeset
418 * If other BSD's gain IN_IFF_TENTATIVE check they re-do DAD
fb1831c903f6 Check for NetBSD in prior, as we did before
Roy Marples <roy@marples.name>
parents: 5569
diff changeset
419 * when the carrier comes up again. */
fb1831c903f6 Check for NetBSD in prior, as we did before
Roy Marples <roy@marples.name>
parents: 5569
diff changeset
420 #if defined(IN_IFF_TENTATIVE) && defined(__NetBSD__)
5569
80fba4edc6c5 NetBSD: Map IP Persistance to roaming
Roy Marples <roy@marples.name>
parents: 5557
diff changeset
421 return ifp->flags & IFF_UP && ifp->carrier == LINK_DOWN;
80fba4edc6c5 NetBSD: Map IP Persistance to roaming
Roy Marples <roy@marples.name>
parents: 5557
diff changeset
422 #else
80fba4edc6c5 NetBSD: Map IP Persistance to roaming
Roy Marples <roy@marples.name>
parents: 5557
diff changeset
423 UNUSED(ifp);
5557
e65d193a1960 Linux: Support wireless IP roaming
Roy Marples <roy@marples.name>
parents: 5499
diff changeset
424 return false;
5569
80fba4edc6c5 NetBSD: Map IP Persistance to roaming
Roy Marples <roy@marples.name>
parents: 5557
diff changeset
425 #endif
5557
e65d193a1960 Linux: Support wireless IP roaming
Roy Marples <roy@marples.name>
parents: 5499
diff changeset
426 }
e65d193a1960 Linux: Support wireless IP roaming
Roy Marples <roy@marples.name>
parents: 5499
diff changeset
427
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
428 static void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
429 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
430 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
431
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
432 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
433 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
434 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
435 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
436 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
437 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
438
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
439 static int
5204
47f18579daae privsep: Implement pledge(2) support as found on OpenBSD
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
440 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
441 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
442 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
443 #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
444 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
445 #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
446 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
447 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
448 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
449
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
450 #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
451 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
452 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
453 &nwid, sizeof(nwid)) == 0)
47f18579daae privsep: Implement pledge(2) support as found on OpenBSD
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
454 {
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
455 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
456 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
457 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
458 errno = ENOBUFS;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
459 else {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
460 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
461 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
462 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
463 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
464 #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
465 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
466 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
467 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
468 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
469 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
470 ireq.i_data = &nwid;
5204
47f18579daae privsep: Implement pledge(2) support as found on OpenBSD
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
471 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
472 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
473 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
474 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
475 errno = ENOBUFS;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
476 else {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
477 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
478 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
479 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
480 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
481 #else
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
482 errno = ENOSYS;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
483 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
484
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
485 return retval;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
486 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
487
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
488 int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
489 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
490 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
491 int r;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
492
5204
47f18579daae privsep: Implement pledge(2) support as found on OpenBSD
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
493 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
494 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
495 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
496 else
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
497 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
498 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
499 return r;
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
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
502 /*
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
503 * 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
504 * 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
505 * 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
506 * 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
507 * 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
508 */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
509 int
5204
47f18579daae privsep: Implement pledge(2) support as found on OpenBSD
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
510 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
511 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
512 int r;
5205
cac489d5a8fa privsep: Fix prior for non pledge systems
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
513 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
514
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
515 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
516 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
517 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
518 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
519 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
520 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
521 {
5204
47f18579daae privsep: Implement pledge(2) support as found on OpenBSD
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
522 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
523 return 1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
524 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
525 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
526 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
527
4052
08038b46c0f5 Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents: 4049
diff changeset
528 unsigned short
08038b46c0f5 Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents: 4049
diff changeset
529 if_vlanid(const struct interface *ifp)
08038b46c0f5 Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents: 4049
diff changeset
530 {
08038b46c0f5 Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents: 4049
diff changeset
531 #ifdef SIOCGETVLAN
5204
47f18579daae privsep: Implement pledge(2) support as found on OpenBSD
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
532 struct vlanreq vlr = { .vlr_tag = 0 };
4052
08038b46c0f5 Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents: 4049
diff changeset
533
5204
47f18579daae privsep: Implement pledge(2) support as found on OpenBSD
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
534 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
535 &vlr, sizeof(vlr)) != 0)
4052
08038b46c0f5 Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents: 4049
diff changeset
536 return 0; /* 0 means no VLANID */
08038b46c0f5 Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents: 4049
diff changeset
537 return vlr.vlr_tag;
08038b46c0f5 Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents: 4049
diff changeset
538 #elif defined(SIOCGVNETID)
5204
47f18579daae privsep: Implement pledge(2) support as found on OpenBSD
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
539 struct ifreq ifr = { .ifr_vnetid = 0 };
4052
08038b46c0f5 Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents: 4049
diff changeset
540
08038b46c0f5 Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents: 4049
diff changeset
541 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
542 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
543 return 0; /* 0 means no VLANID */
08038b46c0f5 Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents: 4049
diff changeset
544 return ifr.ifr_vnetid;
08038b46c0f5 Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents: 4049
diff changeset
545 #else
08038b46c0f5 Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents: 4049
diff changeset
546 UNUSED(ifp);
08038b46c0f5 Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents: 4049
diff changeset
547 return 0; /* 0 means no VLANID */
08038b46c0f5 Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents: 4049
diff changeset
548 #endif
08038b46c0f5 Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents: 4049
diff changeset
549 }
08038b46c0f5 Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents: 4049
diff changeset
550
4502
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
551 static int
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
552 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
553 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
554 {
4502
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
555 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
556 int i;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
557
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
558 cp = data;
4502
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
559 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
560 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
561 if (type & (1 << i)) {
4502
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
562 if (cp >= ep) {
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
563 errno = EINVAL;
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
564 return -1;
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
565 }
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
566 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
567 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
568 } else
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
569 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
570 }
4502
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
571
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
572 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
573 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
574
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
575 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
576 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
577 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
578
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
579 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
580 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
581
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
582 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
583 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
584
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
585 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
586 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
587 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
588 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
589 if (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
590 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
591
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
592 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
593 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
594 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
595 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
596 return ifp;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
597 }
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
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
600 errno = ENOENT;
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 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
605 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
606 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
607 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
608 errno = EINVAL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
609 return NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
610 }
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 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
613 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
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_dl *sdl;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
616
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
617 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
618 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
619 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
620 #ifdef INET
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
621 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
622 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
623 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
624 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
625
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
626 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
627 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
628 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
629 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
630 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
631 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
632 #ifdef INET6
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
633 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
634 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
635 const struct sockaddr_in6 *sin;
4422
344851420e71 BSD: Fix detecting the interface for scoped routes
Roy Marples <roy@marples.name>
parents: 4421
diff changeset
636 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
637 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
638
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
639 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
640 scope = ipv6_getscope(sin);
4422
344851420e71 BSD: Fix detecting the interface for scoped routes
Roy Marples <roy@marples.name>
parents: 4421
diff changeset
641 if (scope != 0)
344851420e71 BSD: Fix detecting the interface for scoped routes
Roy Marples <roy@marples.name>
parents: 4421
diff changeset
642 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
643 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
644 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
645 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
646 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
647 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
648 default:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
649 errno = EAFNOSUPPORT;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
650 return NULL;
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 errno = ENOENT;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
654 return 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
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
657 static void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
658 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
659 {
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 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
662 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
663
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
664 memcpy(dst, src, src->sa_len);
4119
fcddf3690162 Fix compile without INET6.
Roy Marples <roy@marples.name>
parents: 4118
diff changeset
665 #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
666 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
667 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
668
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
669 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
670 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
671 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
672 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
673 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
674 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
675
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
676 int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
677 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
678 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
679 struct dhcpcd_ctx *ctx;
4437
5f768f1d37ad BSD: Simplify rtm usage
Roy Marples <roy@marples.name>
parents: 4422
diff changeset
680 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
681 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
682 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
683 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
684 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
685
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
686 assert(rt != NULL);
4390
1ac28c1a47b0 OpenBSD: add some asserts
Roy Marples <roy@marples.name>
parents: 4371
diff changeset
687 assert(rt->rt_ifp != NULL);
1ac28c1a47b0 OpenBSD: add some asserts
Roy Marples <roy@marples.name>
parents: 4371
diff changeset
688 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
689 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
690
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
691 #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
692 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
693 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
694 } 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
695
3980
503ec96b63bc Initialise the whole rt msg buffer to avoid valgrind errors.
Roy Marples <roy@marples.name>
parents: 3967
diff changeset
696 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
697 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
698 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
699 #ifdef __OpenBSD__
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
700 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
701 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
702 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
703 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
704 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
705 #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
706 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
707 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
708 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
709
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
710 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
711
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
712 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
713 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
714
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
715 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
716 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
717 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
718 !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
719 {
4256
4cc5f8d94727 BSD: move the interface hint up the stack
Roy Marples <roy@marples.name>
parents: 4254
diff changeset
720 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
721 /*
2fdc1a515676 FreeBSD: avoid kernel panics when adding on-link IPv6 routes
Roy Marples <roy@marples.name>
parents: 4352
diff changeset
722 * 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
723 * 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
724 * 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
725 * 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
726 *
2fdc1a515676 FreeBSD: avoid kernel panics when adding on-link IPv6 routes
Roy Marples <roy@marples.name>
parents: 4352
diff changeset
727 * 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
728 * 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
729 */
2fdc1a515676 FreeBSD: avoid kernel panics when adding on-link IPv6 routes
Roy Marples <roy@marples.name>
parents: 4352
diff changeset
730 #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
731 #warning kernel does not allow IPv6 address sharing
4329
9eca323ed30a Fix prior logic.Doh!
Roy Marples <roy@marples.name>
parents: 4328
diff changeset
732 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
733 #endif
6f8187999803 BSD: Always set RTA_IFP for routes
Roy Marples <roy@marples.name>
parents: 4327
diff changeset
734 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
735 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
736 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
737 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
738 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
739 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
740 /* 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
741 * 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
742 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
743 #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
744 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
745 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
746 #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
747 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
748 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
749 #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
750 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
751 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
752 #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
753 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
754 /*
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
755 * 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
756 * 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
757 * 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
758 * resolve correctly.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
759 * 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
760 * 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
761 * 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
762 * 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
763 */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
764 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
765 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
766 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
767 } else
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
768 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
769
5356
39a8d5dfe695 BSD: Mark routes as static only from static config
Roy Marples <roy@marples.name>
parents: 5355
diff changeset
770 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
771 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
772
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
773 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
774 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
775 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
776 }
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
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
779 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
780 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
781
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
782 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
783
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
784 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
785
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
786 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
787 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
788 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
789 else {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
790 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
791
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
792 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
793 #ifdef INET6
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
794 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
795 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
796 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
797 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
798 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
799 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
800
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
801 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
802 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
803
4256
4cc5f8d94727 BSD: move the interface hint up the stack
Roy Marples <roy@marples.name>
parents: 4254
diff changeset
804 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
805 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
806
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
807 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
808 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
809
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
810 #undef ADDSA
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
811
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
812 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
813
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
814 #ifdef PRIVSEP
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
815 if (ctx->options & DHCPCD_PRIVSEP) {
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
816 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
817 return -1;
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
818 return 0;
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
819 }
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
820 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
821 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
822 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
823 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
824 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
825
5058
607d2d75b835 BSD: Fix processing RTM_MISS for non NetBSD BSDs
Roy Marples <roy@marples.name>
parents: 5057
diff changeset
826 static bool
607d2d75b835 BSD: Fix processing RTM_MISS for non NetBSD BSDs
Roy Marples <roy@marples.name>
parents: 5057
diff changeset
827 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
828 {
607d2d75b835 BSD: Fix processing RTM_MISS for non NetBSD BSDs
Roy Marples <roy@marples.name>
parents: 5057
diff changeset
829
607d2d75b835 BSD: Fix processing RTM_MISS for non NetBSD BSDs
Roy Marples <roy@marples.name>
parents: 5057
diff changeset
830 #ifdef RTF_CLONED
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_CLONED)
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_WASCLONED
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_WASCLONED)
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 #ifdef RTF_LOCAL
607d2d75b835 BSD: Fix processing RTM_MISS for non NetBSD BSDs
Roy Marples <roy@marples.name>
parents: 5057
diff changeset
839 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
840 return false;
607d2d75b835 BSD: Fix processing RTM_MISS for non NetBSD BSDs
Roy Marples <roy@marples.name>
parents: 5057
diff changeset
841 #endif
607d2d75b835 BSD: Fix processing RTM_MISS for non NetBSD BSDs
Roy Marples <roy@marples.name>
parents: 5057
diff changeset
842 #ifdef RTF_BROADCAST
607d2d75b835 BSD: Fix processing RTM_MISS for non NetBSD BSDs
Roy Marples <roy@marples.name>
parents: 5057
diff changeset
843 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
844 return false;
607d2d75b835 BSD: Fix processing RTM_MISS for non NetBSD BSDs
Roy Marples <roy@marples.name>
parents: 5057
diff changeset
845 #endif
607d2d75b835 BSD: Fix processing RTM_MISS for non NetBSD BSDs
Roy Marples <roy@marples.name>
parents: 5057
diff changeset
846 return true;
607d2d75b835 BSD: Fix processing RTM_MISS for non NetBSD BSDs
Roy Marples <roy@marples.name>
parents: 5057
diff changeset
847 }
607d2d75b835 BSD: Fix processing RTM_MISS for non NetBSD BSDs
Roy Marples <roy@marples.name>
parents: 5057
diff changeset
848
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
849 static int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
850 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
851 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
852 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
853
4678
f61e4eeb8351 BSD: Handle RTM_MISS
Roy Marples <roy@marples.name>
parents: 4672
diff changeset
854 if (!(rtm->rtm_addrs & RTA_DST)) {
f61e4eeb8351 BSD: Handle RTM_MISS
Roy Marples <roy@marples.name>
parents: 4672
diff changeset
855 errno = EINVAL;
f61e4eeb8351 BSD: Handle RTM_MISS
Roy Marples <roy@marples.name>
parents: 4672
diff changeset
856 return -1;
f61e4eeb8351 BSD: Handle RTM_MISS
Roy Marples <roy@marples.name>
parents: 4672
diff changeset
857 }
f61e4eeb8351 BSD: Handle RTM_MISS
Roy Marples <roy@marples.name>
parents: 4672
diff changeset
858 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
859 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
860 return -1;
4422
344851420e71 BSD: Fix detecting the interface for scoped routes
Roy Marples <roy@marples.name>
parents: 4421
diff changeset
861 }
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
862
4628
8408291093fd BSD: Address some coverity issues
Roy Marples <roy@marples.name>
parents: 4615
diff changeset
863 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
864 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
865 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
866 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
867
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
868 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
869 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
870 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
871 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
872 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
873 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
874 }
4678
f61e4eeb8351 BSD: Handle RTM_MISS
Roy Marples <roy@marples.name>
parents: 4672
diff changeset
875
4645
7d0f6ee7b39e BSD: Fix router reachability tests
Roy Marples <roy@marples.name>
parents: 4643
diff changeset
876 /* 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
877 * 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
878 if (rtm->rtm_addrs & RTA_GATEWAY) {
f61e4eeb8351 BSD: Handle RTM_MISS
Roy Marples <roy@marples.name>
parents: 4672
diff changeset
879 if (rti_info[RTAX_GATEWAY]->sa_family == AF_LINK) {
f61e4eeb8351 BSD: Handle RTM_MISS
Roy Marples <roy@marples.name>
parents: 4672
diff changeset
880 const struct sockaddr_dl *sdl;
4645
7d0f6ee7b39e BSD: Fix router reachability tests
Roy Marples <roy@marples.name>
parents: 4643
diff changeset
881
4678
f61e4eeb8351 BSD: Handle RTM_MISS
Roy Marples <roy@marples.name>
parents: 4672
diff changeset
882 sdl = (const struct sockaddr_dl*)
f61e4eeb8351 BSD: Handle RTM_MISS
Roy Marples <roy@marples.name>
parents: 4672
diff changeset
883 (const void *)rti_info[RTAX_GATEWAY];
f61e4eeb8351 BSD: Handle RTM_MISS
Roy Marples <roy@marples.name>
parents: 4672
diff changeset
884 if (sdl->sdl_alen != 0)
f61e4eeb8351 BSD: Handle RTM_MISS
Roy Marples <roy@marples.name>
parents: 4672
diff changeset
885 rt->rt_dflags |= RTDF_GATELINK;
f61e4eeb8351 BSD: Handle RTM_MISS
Roy Marples <roy@marples.name>
parents: 4672
diff changeset
886 } else if (rtm->rtm_flags & RTF_GATEWAY)
f61e4eeb8351 BSD: Handle RTM_MISS
Roy Marples <roy@marples.name>
parents: 4672
diff changeset
887 if_copysa(&rt->rt_gateway, rti_info[RTAX_GATEWAY]);
f61e4eeb8351 BSD: Handle RTM_MISS
Roy Marples <roy@marples.name>
parents: 4672
diff changeset
888 }
f61e4eeb8351 BSD: Handle RTM_MISS
Roy Marples <roy@marples.name>
parents: 4672
diff changeset
889
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
890 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
891 if_copysa(&rt->rt_ifa, rti_info[RTAX_IFA]);
4678
f61e4eeb8351 BSD: Handle RTM_MISS
Roy Marples <roy@marples.name>
parents: 4672
diff changeset
892
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
893 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
894
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
895 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
896 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
897 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
898 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
899 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
900 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
901 else
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
902 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
903
4679
b788dd0853bd BSD: RTM_MISS doesn't always have a gateway
Roy Marples <roy@marples.name>
parents: 4678
diff changeset
904 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
905 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
906
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
907 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
908 errno = ESRCH;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
909 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
910 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
911 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
912 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
913
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
914 int
4400
2d6a2c8c6b56 route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents: 4390
diff changeset
915 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
916 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
917 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
918 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
919 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
920 char *buf, *p, *end;
4400
2d6a2c8c6b56 route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents: 4390
diff changeset
921 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
922
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
923 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
924 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
925 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
926 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
927 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
928 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
929
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
930 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
931 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
932 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
933 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
934 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
935 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
936 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
937 free(buf);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
938 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
939 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
940
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
941 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
942 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
943 rtm = (void *)p;
4502
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
944 if (p + rtm->rtm_msglen >= end) {
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
945 errno = EINVAL;
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
946 break;
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
947 }
5058
607d2d75b835 BSD: Fix processing RTM_MISS for non NetBSD BSDs
Roy Marples <roy@marples.name>
parents: 5057
diff changeset
948 if (!if_realroute(rtm))
607d2d75b835 BSD: Fix processing RTM_MISS for non NetBSD BSDs
Roy Marples <roy@marples.name>
parents: 5057
diff changeset
949 continue;
4400
2d6a2c8c6b56 route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents: 4390
diff changeset
950 if (if_copyrt(ctx, &rt, rtm) != 0)
2d6a2c8c6b56 route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents: 4390
diff changeset
951 continue;
2d6a2c8c6b56 route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents: 4390
diff changeset
952 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
953 logerr(__func__);
2d6a2c8c6b56 route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents: 4390
diff changeset
954 break;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
955 }
4400
2d6a2c8c6b56 route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents: 4390
diff changeset
956 memcpy(rtn, &rt, sizeof(*rtn));
2d6a2c8c6b56 route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents: 4390
diff changeset
957 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
958 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
959 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
960 free(buf);
4502
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
961 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
962 }
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 #ifdef INET
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
965 int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
966 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
967 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
968 int r;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
969 struct in_aliasreq ifra;
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
970 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
971
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
972 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
973 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
974
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
975 #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
976 (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
977 (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
978 (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
979 } 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
980 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
981 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
982 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
983 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
984 #undef ADDADDR
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
985
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
986 r = if_ioctl(ctx,
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
987 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
988 return r;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
989 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
990
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
991 #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
992 int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
993 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
994 __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
995 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
996 #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
997 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
998 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
999
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1000 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
1001 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
1002 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
1003 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
1004 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
1005 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
1006 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1007 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
1008 #else
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1009 UNUSED(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1010 UNUSED(addr);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1011 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1012 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1013 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1014 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1015 #endif /* INET */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1016
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1017 #ifdef INET6
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
1018 static int
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
1019 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
1020 {
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
1021 struct priv *priv;
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 #ifdef PRIVSEP
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
1024 if (ctx->options & DHCPCD_PRIVSEP)
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
1025 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
1026 #endif
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
1027
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
1028 priv = ctx->priv;
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
1029 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
1030 }
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
1031
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1032 int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1033 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
1034 {
5156
abb54c79cc7f OpenBSD: set IN6_IFF_AUTOCONF for addresses generated from a RA
Roy Marples <roy@marples.name>
parents: 5153
diff changeset
1035 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
1036 struct in6_addr mask;
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
1037 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
1038
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1039 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
1040 #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
1041 /* 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
1042 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
1043 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
1044 #endif
5364
fe45c5b59de1 BSD: Allow non NetBSD and OpenBSD to set IN6_IFF_AUTOCONF
Roy Marples <roy@marples.name>
parents: 5356
diff changeset
1045 #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
1046 (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
1047 /* 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
1048 #else
5156
abb54c79cc7f OpenBSD: set IN6_IFF_AUTOCONF for addresses generated from a RA
Roy Marples <roy@marples.name>
parents: 5153
diff changeset
1049 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
1050 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
1051 #endif
5125
6f14f7261828 BSD: Fix temporary address management
Roy Marples <roy@marples.name>
parents: 5113
diff changeset
1052 #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
1053 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
1054 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
1055 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1056
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1057 #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
1058 (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
1059 (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
1060 (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
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 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
1064 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
1065 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
1066 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
1067
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1068 #undef ADDADDR
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1069
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1070 /*
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1071 * 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
1072 * 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
1073 * 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
1074 * 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
1075 * 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
1076 *
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1077 * 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
1078 * 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
1079 * 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
1080 * 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
1081 * 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
1082 * 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
1083 *
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1084 * 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
1085 * 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
1086 * 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
1087 * 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
1088 * 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
1089 * 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
1090 *
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1091 * 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
1092 * 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
1093 *
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1094 * 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
1095 * 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
1096 * 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
1097 */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1098
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1099 #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
1100 (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
1101 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
1102 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
1103 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
1104 (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
1105 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1106 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1107
4049
22e5b911ceaa Newer OpenBSD is fixed for userland affecting address lifetime.
Roy Marples <roy@marples.name>
parents: 4046
diff changeset
1108 #if defined(__OpenBSD__) && OpenBSD <= 201705
22e5b911ceaa Newer OpenBSD is fixed for userland affecting address lifetime.
Roy Marples <roy@marples.name>
parents: 4046
diff changeset
1109 /* 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
1110 * 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
1111 * 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
1112 * 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
1113 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
1114 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
1115 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
1116 } else {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1117 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
1118 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
1119 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1120 #else
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1121 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
1122 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
1123 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1124
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
1125 return if_ioctl6(ctx,
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
1126 cmd == RTM_DELADDR ? SIOCDIFADDR_IN6 : SIOCAIFADDR_IN6,
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
1127 &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
1128 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1129
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1130 int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1131 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
1132 __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
1133 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1134 int flags;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1135 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
1136 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
1137
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1138 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
1139 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
1140 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
1141 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
1142 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
1143 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
1144 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
1145 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
1146 else
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1147 flags = -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1148 return flags;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1149 }
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 int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1152 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
1153 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1154 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
1155 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
1156 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
1157 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
1158
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1159 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
1160 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
1161 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
1162 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
1163 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
1164 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
1165 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
1166 return -1;
4483
e2f5a58c978a FreeBSD: Fix fetching the IPv6 address lifetime
Roy Marples <roy@marples.name>
parents: 4437
diff changeset
1167 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
1168
4483
e2f5a58c978a FreeBSD: Fix fetching the IPv6 address lifetime
Roy Marples <roy@marples.name>
parents: 4437
diff changeset
1169 #if defined(__FreeBSD__) || defined(__DragonFly__)
e2f5a58c978a FreeBSD: Fix fetching the IPv6 address lifetime
Roy Marples <roy@marples.name>
parents: 4437
diff changeset
1170 t = ia->created.tv_sec;
e2f5a58c978a FreeBSD: Fix fetching the IPv6 address lifetime
Roy Marples <roy@marples.name>
parents: 4437
diff changeset
1171 #else
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1172 t = time(NULL);
4483
e2f5a58c978a FreeBSD: Fix fetching the IPv6 address lifetime
Roy Marples <roy@marples.name>
parents: 4437
diff changeset
1173 #endif
e2f5a58c978a FreeBSD: Fix fetching the IPv6 address lifetime
Roy Marples <roy@marples.name>
parents: 4437
diff changeset
1174
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1175 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
1176 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
1177 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
1178 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
1179 else
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1180 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
1181 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
1182 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
1183 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
1184 /* 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
1185 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
1186 } else
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1187 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
1188 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1189 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1190 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1191
4502
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1192 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
1193 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
1194 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1195
4502
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1196 if (ifan->ifan_msglen < sizeof(*ifan)) {
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1197 errno = EINVAL;
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1198 return -1;
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
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1201 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
1202 case IFAN_ARRIVAL:
4502
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1203 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
1204 case IFAN_DEPARTURE:
4502
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1205 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
1206 }
4502
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1207
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1208 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
1209 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1210
4502
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1211 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
1212 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
1213 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1214 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
1215 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
1216
4502
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1217 if (ifm->ifm_msglen < sizeof(*ifm)) {
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1218 errno = EINVAL;
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1219 return -1;
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1220 }
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1221
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1222 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
1223 return 0;
4340
1de0bba2f0b2 BSD: Fix UP/DOWN for interfaces which dont' report media changes
Roy Marples <roy@marples.name>
parents: 4339
diff changeset
1224
5486
8e2b8ce8c972 BSD: struct if_data->ifi_link_state is the single source of truth
Roy Marples <roy@marples.name>
parents: 5485
diff changeset
1225 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
1226 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
1227 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
1228 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1229
4502
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1230 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
1231 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
1232 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1233 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
1234
4502
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1235 if (rtm->rtm_msglen < sizeof(*rtm)) {
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1236 errno = EINVAL;
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1237 return -1;
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1238 }
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1239
4025
e20d2e8dca5b Ignore route(4) errors.
Roy Marples <roy@marples.name>
parents: 4023
diff changeset
1240 /* Ignore errors. */
e20d2e8dca5b Ignore route(4) errors.
Roy Marples <roy@marples.name>
parents: 4023
diff changeset
1241 if (rtm->rtm_errno != 0)
4502
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1242 return 0;
4025
e20d2e8dca5b Ignore route(4) errors.
Roy Marples <roy@marples.name>
parents: 4023
diff changeset
1243
4971
d050161827d1 BSD: Ignore messages from ourself in privsep.
Roy Marples <roy@marples.name>
parents: 4961
diff changeset
1244 /* Ignore messages from ourself. */
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
1245 #ifdef PRIVSEP
4971
d050161827d1 BSD: Ignore messages from ourself in privsep.
Roy Marples <roy@marples.name>
parents: 4961
diff changeset
1246 if (ctx->ps_root_pid != 0) {
d050161827d1 BSD: Ignore messages from ourself in privsep.
Roy Marples <roy@marples.name>
parents: 4961
diff changeset
1247 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
1248 return 0;
4972
c38657775fb4 BSD: Disable checking rtm_pid and comment why.
Roy Marples <roy@marples.name>
parents: 4971
diff changeset
1249 }
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
1250 #endif
4972
c38657775fb4 BSD: Disable checking rtm_pid and comment why.
Roy Marples <roy@marples.name>
parents: 4971
diff changeset
1251
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1252 if (if_copyrt(ctx, &rt, rtm) == -1)
4678
f61e4eeb8351 BSD: Handle RTM_MISS
Roy Marples <roy@marples.name>
parents: 4672
diff changeset
1253 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
1254
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1255 #ifdef INET6
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1256 /*
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1257 * 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
1258 * 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
1259 * 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
1260 * 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
1261 */
4645
7d0f6ee7b39e BSD: Fix router reachability tests
Roy Marples <roy@marples.name>
parents: 4643
diff changeset
1262 if (rt.rt_dest.sa_family == AF_INET6 &&
4678
f61e4eeb8351 BSD: Handle RTM_MISS
Roy Marples <roy@marples.name>
parents: 4672
diff changeset
1263 (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
1264 !(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
1265 {
4669
ec9d26e0de41 inet6: Stop reacting to kernel neighbour messages about a router
Roy Marples <roy@marples.name>
parents: 4666
diff changeset
1266 bool reachable;
4666
ebe041d24998 BSD: Listen for Router -> Host messages via RTM_CHANGE
Roy Marples <roy@marples.name>
parents: 4645
diff changeset
1267
4678
f61e4eeb8351 BSD: Handle RTM_MISS
Roy Marples <roy@marples.name>
parents: 4672
diff changeset
1268 reachable = (rtm->rtm_type == RTM_ADD ||
f61e4eeb8351 BSD: Handle RTM_MISS
Roy Marples <roy@marples.name>
parents: 4672
diff changeset
1269 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
1270 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
1271 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
1272 }
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1273 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1274
5058
607d2d75b835 BSD: Fix processing RTM_MISS for non NetBSD BSDs
Roy Marples <roy@marples.name>
parents: 5057
diff changeset
1275 if (rtm->rtm_type != RTM_MISS && if_realroute(rtm))
4678
f61e4eeb8351 BSD: Handle RTM_MISS
Roy Marples <roy@marples.name>
parents: 4672
diff changeset
1276 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
1277 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
1278 }
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 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
1281 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
1282 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1283 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
1284 const struct sockaddr *rti_info[RTAX_MAX];
4984
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1285 int flags;
4232
8b92c1844860 Log the pid of the process deleting an assigned address.
Roy Marples <roy@marples.name>
parents: 4229
diff changeset
1286 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
1287
4502
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1288 if (ifam->ifam_msglen < sizeof(*ifam)) {
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1289 errno = EINVAL;
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1290 return -1;
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1291 }
4971
d050161827d1 BSD: Ignore messages from ourself in privsep.
Roy Marples <roy@marples.name>
parents: 4961
diff changeset
1292
d050161827d1 BSD: Ignore messages from ourself in privsep.
Roy Marples <roy@marples.name>
parents: 4961
diff changeset
1293 #ifdef HAVE_IFAM_PID
4985
d9cb0a6245a4 Only ignore address messages from ourself for deletion.
Roy Marples <roy@marples.name>
parents: 4984
diff changeset
1294 /* Ignore address deletions from ourself.
d9cb0a6245a4 Only ignore address messages from ourself for deletion.
Roy Marples <roy@marples.name>
parents: 4984
diff changeset
1295 * 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
1296 if (ifam->ifam_type == RTM_DELADDR) {
4971
d050161827d1 BSD: Ignore messages from ourself in privsep.
Roy Marples <roy@marples.name>
parents: 4961
diff changeset
1297 #ifdef PRIVSEP
4985
d9cb0a6245a4 Only ignore address messages from ourself for deletion.
Roy Marples <roy@marples.name>
parents: 4984
diff changeset
1298 if (ctx->ps_root_pid != 0) {
d9cb0a6245a4 Only ignore address messages from ourself for deletion.
Roy Marples <roy@marples.name>
parents: 4984
diff changeset
1299 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
1300 return 0;
d9cb0a6245a4 Only ignore address messages from ourself for deletion.
Roy Marples <roy@marples.name>
parents: 4984
diff changeset
1301 } else
4971
d050161827d1 BSD: Ignore messages from ourself in privsep.
Roy Marples <roy@marples.name>
parents: 4961
diff changeset
1302 #endif
4985
d9cb0a6245a4 Only ignore address messages from ourself for deletion.
Roy Marples <roy@marples.name>
parents: 4984
diff changeset
1303 /* address management is done via ioctl,
d9cb0a6245a4 Only ignore address messages from ourself for deletion.
Roy Marples <roy@marples.name>
parents: 4984
diff changeset
1304 * so SO_USELOOPBACK has no effect,
d9cb0a6245a4 Only ignore address messages from ourself for deletion.
Roy Marples <roy@marples.name>
parents: 4984
diff changeset
1305 * 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
1306 if (ifam->ifam_pid == getpid())
d9cb0a6245a4 Only ignore address messages from ourself for deletion.
Roy Marples <roy@marples.name>
parents: 4984
diff changeset
1307 return 0;
d9cb0a6245a4 Only ignore address messages from ourself for deletion.
Roy Marples <roy@marples.name>
parents: 4984
diff changeset
1308 }
4971
d050161827d1 BSD: Ignore messages from ourself in privsep.
Roy Marples <roy@marples.name>
parents: 4961
diff changeset
1309 pid = ifam->ifam_pid;
d050161827d1 BSD: Ignore messages from ourself in privsep.
Roy Marples <roy@marples.name>
parents: 4961
diff changeset
1310 #else
d050161827d1 BSD: Ignore messages from ourself in privsep.
Roy Marples <roy@marples.name>
parents: 4961
diff changeset
1311 pid = 0;
d050161827d1 BSD: Ignore messages from ourself in privsep.
Roy Marples <roy@marples.name>
parents: 4961
diff changeset
1312 #endif
d050161827d1 BSD: Ignore messages from ourself in privsep.
Roy Marples <roy@marples.name>
parents: 4961
diff changeset
1313
4503
9784c3171a22 BSD: Ignore coverity errors
Roy Marples <roy@marples.name>
parents: 4502
diff changeset
1314 if (~ifam->ifam_addrs & RTA_IFA)
9784c3171a22 BSD: Ignore coverity errors
Roy Marples <roy@marples.name>
parents: 4502
diff changeset
1315 return 0;
3943
361c6b6906bc Test address family to test the correct address flags.
Roy Marples <roy@marples.name>
parents: 3939
diff changeset
1316 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
1317 return 0;
4503
9784c3171a22 BSD: Ignore coverity errors
Roy Marples <roy@marples.name>
parents: 4502
diff changeset
1318
4628
8408291093fd BSD: Address some coverity issues
Roy Marples <roy@marples.name>
parents: 4615
diff changeset
1319 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
1320 ifam->ifam_msglen - sizeof(*ifam), rti_info) == -1)
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1321 return -1;
3943
361c6b6906bc Test address family to test the correct address flags.
Roy Marples <roy@marples.name>
parents: 3939
diff changeset
1322
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1323 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
1324 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
1325 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1326 struct 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
1327
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1328 #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
1329 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
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 #else
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1332 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
1333 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1334 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1335 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
1336 dhcpcd_handlehwaddr(ifp, ifp->hwtype,
1f5dc6102f9b if: support changing hardware address type on Linux
Roy Marples <roy@marples.name>
parents: 5156
diff changeset
1337 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
1338 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1339 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1340 #ifdef INET
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1341 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
1342 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
1343 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1344 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
1345 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
1346
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1347 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
1348 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
1349 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
1350 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
1351 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
1352 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
1353 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
1354 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
1355 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
1356
4326
009a47703a99 BSD: don't listen to own route messages
Roy Marples <roy@marples.name>
parents: 4324
diff changeset
1357 /*
009a47703a99 BSD: don't listen to own route messages
Roy Marples <roy@marples.name>
parents: 4324
diff changeset
1358 * 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
1359 * 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
1360 * the right one.
4984
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1361 * 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
1362 * 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
1363 */
009a47703a99 BSD: don't listen to own route messages
Roy Marples <roy@marples.name>
parents: 4324
diff changeset
1364 #ifdef SIOCGIFALIAS
4984
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1365 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
1366
4984
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1367 memset(&ifra, 0, sizeof(ifra));
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1368 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
1369 ifra.ifra_addr.sin_family = AF_INET;
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1370 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
1371 ifra.ifra_addr.sin_addr = addr;
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1372 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
1373 if (errno != ENXIO && errno != EADDRNOTAVAIL)
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1374 logerr("%s: SIOCGIFALIAS", __func__);
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1375 if (ifam->ifam_type != RTM_DELADDR)
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1376 break;
4987
9e85855c49b6 BSD: Improve RTM_NEWADDR/RTM_DELADDR validaton some more
Roy Marples <roy@marples.name>
parents: 4985
diff changeset
1377 } else {
9e85855c49b6 BSD: Improve RTM_NEWADDR/RTM_DELADDR validaton some more
Roy Marples <roy@marples.name>
parents: 4985
diff changeset
1378 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
1379 break;
4326
009a47703a99 BSD: don't listen to own route messages
Roy Marples <roy@marples.name>
parents: 4324
diff changeset
1380 #if defined(__NetBSD_Version__) && __NetBSD_Version__ < 800000000
4984
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1381 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
1382 #endif
4987
9e85855c49b6 BSD: Improve RTM_NEWADDR/RTM_DELADDR validaton some more
Roy Marples <roy@marples.name>
parents: 4985
diff changeset
1383 }
4300
82a8e37ab298 Workaround NetBSD-7 sending an invalid bcast address in RTM_NEWADDR
Roy Marples <roy@marples.name>
parents: 4256
diff changeset
1384 #else
4326
009a47703a99 BSD: don't listen to own route messages
Roy Marples <roy@marples.name>
parents: 4324
diff changeset
1385 #warning No SIOCGIFALIAS support
4984
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1386 /*
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1387 * No SIOCGIFALIAS? That sucks!
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1388 * 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
1389 * 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
1390 */
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1391 const struct sockaddr *sa;
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1392 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
1393
4984
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1394 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
1395 #ifdef PRIVSEP_GETIFADDRS
3180f8b46cc4 BSD: In privsep with no GIFALIAS support? getifaddrs over privsep
Roy Marples <roy@marples.name>
parents: 5310
diff changeset
1396 if (IN_PRIVSEP(ctx)) {
3180f8b46cc4 BSD: In privsep with no GIFALIAS support? getifaddrs over privsep
Roy Marples <roy@marples.name>
parents: 5310
diff changeset
1397 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
1398 logerr("ps_root_getifaddrs");
3180f8b46cc4 BSD: In privsep with no GIFALIAS support? getifaddrs over privsep
Roy Marples <roy@marples.name>
parents: 5310
diff changeset
1399 break;
3180f8b46cc4 BSD: In privsep with no GIFALIAS support? getifaddrs over privsep
Roy Marples <roy@marples.name>
parents: 5310
diff changeset
1400 }
3180f8b46cc4 BSD: In privsep with no GIFALIAS support? getifaddrs over privsep
Roy Marples <roy@marples.name>
parents: 5310
diff changeset
1401 } else
3180f8b46cc4 BSD: In privsep with no GIFALIAS support? getifaddrs over privsep
Roy Marples <roy@marples.name>
parents: 5310
diff changeset
1402 #endif
3180f8b46cc4 BSD: In privsep with no GIFALIAS support? getifaddrs over privsep
Roy Marples <roy@marples.name>
parents: 5310
diff changeset
1403 if (getifaddrs(&ifaddrs) == -1) {
3180f8b46cc4 BSD: In privsep with no GIFALIAS support? getifaddrs over privsep
Roy Marples <roy@marples.name>
parents: 5310
diff changeset
1404 logerr("getifaddrs");
3180f8b46cc4 BSD: In privsep with no GIFALIAS support? getifaddrs over privsep
Roy Marples <roy@marples.name>
parents: 5310
diff changeset
1405 break;
3180f8b46cc4 BSD: In privsep with no GIFALIAS support? getifaddrs over privsep
Roy Marples <roy@marples.name>
parents: 5310
diff changeset
1406 }
4984
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1407 for (ifa = ifaddrs; ifa; ifa = ifa->ifa_next) {
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1408 if (ifa->ifa_addr == NULL)
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1409 continue;
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1410 if (sa_cmp(ifa->ifa_addr, sa) == 0 &&
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1411 strcmp(ifa->ifa_name, ifp->name) == 0)
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1412 break;
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1413 }
5319
3180f8b46cc4 BSD: In privsep with no GIFALIAS support? getifaddrs over privsep
Roy Marples <roy@marples.name>
parents: 5310
diff changeset
1414 #ifdef PRIVSEP_GETIFADDRS
3180f8b46cc4 BSD: In privsep with no GIFALIAS support? getifaddrs over privsep
Roy Marples <roy@marples.name>
parents: 5310
diff changeset
1415 if (IN_PRIVSEP(ctx))
3180f8b46cc4 BSD: In privsep with no GIFALIAS support? getifaddrs over privsep
Roy Marples <roy@marples.name>
parents: 5310
diff changeset
1416 free(ifaddrs);
3180f8b46cc4 BSD: In privsep with no GIFALIAS support? getifaddrs over privsep
Roy Marples <roy@marples.name>
parents: 5310
diff changeset
1417 else
3180f8b46cc4 BSD: In privsep with no GIFALIAS support? getifaddrs over privsep
Roy Marples <roy@marples.name>
parents: 5310
diff changeset
1418 #endif
4984
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1419 freeifaddrs(ifaddrs);
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1420 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
1421 if (ifa != NULL)
4984
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1422 break;
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 if (ifa == NULL)
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1425 break;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1426 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1427 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1428
4984
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1429 #ifdef HAVE_IFAM_ADDRFLAGS
5004
8abc8f810b83 BSD: Fix INET flags on RTM_NEWADDR messages.
Roy Marples <roy@marples.name>
parents: 4987
diff changeset
1430 flags = ifam->ifam_addrflags;
4984
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1431 #else
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1432 flags = 0;
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1433 #endif
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1434
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1435 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
1436 &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
1437 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1438 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1439 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1440 #ifdef INET6
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1441 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
1442 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1443 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
1444 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
1445
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1446 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
1447 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
1448 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
1449 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
1450
4326
009a47703a99 BSD: don't listen to own route messages
Roy Marples <roy@marples.name>
parents: 4324
diff changeset
1451 /*
009a47703a99 BSD: don't listen to own route messages
Roy Marples <roy@marples.name>
parents: 4324
diff changeset
1452 * 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
1453 * 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
1454 * 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
1455 * 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
1456 * 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
1457 */
4987
9e85855c49b6 BSD: Improve RTM_NEWADDR/RTM_DELADDR validaton some more
Roy Marples <roy@marples.name>
parents: 4985
diff changeset
1458 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
1459 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
1460 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
1461 logerr("%s: if_addrflags6", __func__);
9e85855c49b6 BSD: Improve RTM_NEWADDR/RTM_DELADDR validaton some more
Roy Marples <roy@marples.name>
parents: 4985
diff changeset
1462 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
1463 break;
4984
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1464 flags = 0;
4987
9e85855c49b6 BSD: Improve RTM_NEWADDR/RTM_DELADDR validaton some more
Roy Marples <roy@marples.name>
parents: 4985
diff changeset
1465 } 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
1466 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1467
4181
4224319f0887 BSD: Strip scope from link-local addresses for KAME stacks
Roy Marples <roy@marples.name>
parents: 4165
diff changeset
1468 #ifdef __KAME__
4224319f0887 BSD: Strip scope from link-local addresses for KAME stacks
Roy Marples <roy@marples.name>
parents: 4165
diff changeset
1469 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
1470 /* 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
1471 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
1472 #endif
4224319f0887 BSD: Strip scope from link-local addresses for KAME stacks
Roy Marples <roy@marples.name>
parents: 4165
diff changeset
1473
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1474 ipv6_handleifa(ctx, ifam->ifam_type, NULL,
4984
c2c775f7811d BSD: Validate RTM_NEWADDR as well
Roy Marples <roy@marples.name>
parents: 4980
diff changeset
1475 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
1476 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1477 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1478 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1479 }
4502
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1480
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
4502
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1484 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
1485 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
1486 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1487
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1488 if (rtm->rtm_version != RTM_VERSION)
4502
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1489 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
1490
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1491 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
1492 #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
1493 case RTM_IFANNOUNCE:
4502
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1494 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
1495 #endif
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_IFINFO:
4502
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1497 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
1498 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
1499 case RTM_CHANGE: /* FALLTHROUGH */
4678
f61e4eeb8351 BSD: Handle RTM_MISS
Roy Marples <roy@marples.name>
parents: 4672
diff changeset
1500 case RTM_DELETE: /* FALLTHROUGH */
f61e4eeb8351 BSD: Handle RTM_MISS
Roy Marples <roy@marples.name>
parents: 4672
diff changeset
1501 case RTM_MISS:
4502
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1502 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
1503 #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
1504 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
1505 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1506 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
1507 case RTM_NEWADDR:
4502
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1508 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
1509 #ifdef RTM_DESYNC
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4232
diff changeset
1510 case RTM_DESYNC:
4565
a5889b07c310 OpenBSD: Fix compile.
Roy Marples <roy@marples.name>
parents: 4548
diff changeset
1511 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
1512 #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
1513 #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
1514 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1515 }
4503
9784c3171a22 BSD: Ignore coverity errors
Roy Marples <roy@marples.name>
parents: 4502
diff changeset
1516
9784c3171a22 BSD: Ignore coverity errors
Roy Marples <roy@marples.name>
parents: 4502
diff changeset
1517 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
1518 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1519
5057
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1520 static int
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1521 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
1522 struct sockaddr *sa)
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1523 {
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1524 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
1525 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
1526 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
1527 uint8_t *cp;
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 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
1530 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
1531 if (n == NULL)
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1532 return -1;
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1533 ctx->rt_missfilter = n;
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1534 ctx->rt_missfiltersize = newlen;
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
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1537 #ifdef INET6
5087
6d80da6b2f56 BSD: use satosin6 rather than a direct cast
Roy Marples <roy@marples.name>
parents: 5058
diff changeset
1538 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
1539 ipv6_setscope(satosin6(sa), ifp->index);
5112
899adcd7f449 Fix build without INET or INET6
Roy Marples <roy@marples.name>
parents: 5097
diff changeset
1540 #else
899adcd7f449 Fix build without INET or INET6
Roy Marples <roy@marples.name>
parents: 5097
diff changeset
1541 UNUSED(ifp);
5057
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1542 #endif
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1543
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1544 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
1545 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
1546 if (diff != 0)
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1547 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
1548 ctx->rt_missfilterlen += salen;
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 #ifdef INET6
5087
6d80da6b2f56 BSD: use satosin6 rather than a direct cast
Roy Marples <roy@marples.name>
parents: 5058
diff changeset
1551 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
1552 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
1553 #endif
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1554
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1555 return 0;
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
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1558 int
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1559 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
1560 {
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1561
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1562 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
1563 }
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1564
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1565 int
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1566 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
1567 {
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1568 #ifdef RO_MISSFILTER
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1569 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
1570 struct sockaddr sa = {
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1571 .sa_family = AF_UNSPEC,
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1572 .sa_len = sizeof(sa),
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1573 };
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1574
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1575 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
1576 return -1;
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1577 }
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1578
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1579 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
1580 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
1581 #else
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1582 #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
1583 UNUSED(ctx);
5057
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1584 errno = ENOTSUP;
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1585 return -1;
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1586 #endif
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1587 }
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5056
diff changeset
1588
4628
8408291093fd BSD: Address some coverity issues
Roy Marples <roy@marples.name>
parents: 4615
diff changeset
1589 __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
1590 int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1591 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
1592 {
4437
5f768f1d37ad BSD: Simplify rtm usage
Roy Marples <roy@marples.name>
parents: 4422
diff changeset
1593 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
1594 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
1595
4612
a19f5fd758f6 BSD: Use read instead of recvmsg
Roy Marples <roy@marples.name>
parents: 4604
diff changeset
1596 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
1597 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
1598 return -1;
4502
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1599 if (len == 0)
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1600 return 0;
4628
8408291093fd BSD: Address some coverity issues
Roy Marples <roy@marples.name>
parents: 4615
diff changeset
1601 if ((size_t)len < sizeof(rtm.hdr.rtm_msglen) ||
8408291093fd BSD: Address some coverity issues
Roy Marples <roy@marples.name>
parents: 4615
diff changeset
1602 len != rtm.hdr.rtm_msglen)
8408291093fd BSD: Address some coverity issues
Roy Marples <roy@marples.name>
parents: 4615
diff changeset
1603 {
4502
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1604 errno = EINVAL;
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1605 return -1;
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1606 }
4628
8408291093fd BSD: Address some coverity issues
Roy Marples <roy@marples.name>
parents: 4615
diff changeset
1607 /*
8408291093fd BSD: Address some coverity issues
Roy Marples <roy@marples.name>
parents: 4615
diff changeset
1608 * 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
1609 * 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
1610 * 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
1611 * 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
1612 * 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
1613 * equivalent call in if_initrt.
8408291093fd BSD: Address some coverity issues
Roy Marples <roy@marples.name>
parents: 4615
diff changeset
1614 */
4643
6aa99a23a825 BSD: Dismiss a coverity error
Roy Marples <roy@marples.name>
parents: 4628
diff changeset
1615 /* coverity[tainted_data] */
4502
5d361d74621c BSD: Validate RTM message lengths received
Roy Marples <roy@marples.name>
parents: 4497
diff changeset
1616 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
1617 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1618
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1619 #ifndef SYS_NMLN /* OSX */
5207
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5206
diff changeset
1620 # 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
1621 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1622 #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
1623 # 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
1624 # 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
1625 # endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1626 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1627 int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1628 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
1629 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1630 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
1631
5207
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5206
diff changeset
1632 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
1633 }
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 #ifdef INET6
4220
14058f9c6962 Satisfy FreeBSD and NetBSD.
Roy Marples <roy@marples.name>
parents: 4219
diff changeset
1636 #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
1637 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
1638 #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
1639 #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
1640 static int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1641 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
1642 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1643 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
1644 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
1645
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1646 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
1647 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
1648 if (action) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1649 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
1650 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
1651 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1652 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1653 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1654 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
1655 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1656 return val;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1657 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1658 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1659
4813
ef33eb73e97d INET6: Apply hoplimit, reachable and retrans timer values from RA.
Roy Marples <roy@marples.name>
parents: 4799
diff changeset
1660 int
ef33eb73e97d INET6: Apply hoplimit, reachable and retrans timer values from RA.
Roy Marples <roy@marples.name>
parents: 4799
diff changeset
1661 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
1662 {
4817
92d3d8e9960c OpenBSD: Fix prior - OS cannot set any RA bits such as hop limit.
Roy Marples <roy@marples.name>
parents: 4816
diff changeset
1663 #ifdef SIOCSIFINFO_IN6
5020
d5297c3e1e7f BSD: When applying RA base information, get info without privsep
Roy Marples <roy@marples.name>
parents: 5019
diff changeset
1664 struct in6_ndireq nd = { .ndi.chlim = 0 };
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
1665 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
1666 int error;
4813
ef33eb73e97d INET6: Apply hoplimit, reachable and retrans timer values from RA.
Roy Marples <roy@marples.name>
parents: 4799
diff changeset
1667
5020
d5297c3e1e7f BSD: When applying RA base information, get info without privsep
Roy Marples <roy@marples.name>
parents: 5019
diff changeset
1668 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
1669
1d16a9434290 NetBSD: Gear up for kernel RA removal.
Roy Marples <roy@marples.name>
parents: 5173
diff changeset
1670 #ifdef IPV6CTL_ACCEPT_RTADV
1d16a9434290 NetBSD: Gear up for kernel RA removal.
Roy Marples <roy@marples.name>
parents: 5173
diff changeset
1671 struct priv *priv = ctx->priv;
1d16a9434290 NetBSD: Gear up for kernel RA removal.
Roy Marples <roy@marples.name>
parents: 5173
diff changeset
1672
1d16a9434290 NetBSD: Gear up for kernel RA removal.
Roy Marples <roy@marples.name>
parents: 5173
diff changeset
1673 /*
1d16a9434290 NetBSD: Gear up for kernel RA removal.
Roy Marples <roy@marples.name>
parents: 5173
diff changeset
1674 * 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
1675 * 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
1676 * linkmtu was also removed.
1d16a9434290 NetBSD: Gear up for kernel RA removal.
Roy Marples <roy@marples.name>
parents: 5173
diff changeset
1677 * 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
1678 */
5020
d5297c3e1e7f BSD: When applying RA base information, get info without privsep
Roy Marples <roy@marples.name>
parents: 5019
diff changeset
1679 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
1680 return -1;
ef33eb73e97d INET6: Apply hoplimit, reachable and retrans timer values from RA.
Roy Marples <roy@marples.name>
parents: 4799
diff changeset
1681
5020
d5297c3e1e7f BSD: When applying RA base information, get info without privsep
Roy Marples <roy@marples.name>
parents: 5019
diff changeset
1682 nd.ndi.linkmtu = rap->mtu;
5177
1d16a9434290 NetBSD: Gear up for kernel RA removal.
Roy Marples <roy@marples.name>
parents: 5173
diff changeset
1683 #endif
1d16a9434290 NetBSD: Gear up for kernel RA removal.
Roy Marples <roy@marples.name>
parents: 5173
diff changeset
1684
5020
d5297c3e1e7f BSD: When applying RA base information, get info without privsep
Roy Marples <roy@marples.name>
parents: 5019
diff changeset
1685 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
1686 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
1687 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
1688 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
1689 #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
1690 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
1691 /*
22acf0138b3a BSD: Try and set linkmtu for the interface just to be nice.
Roy Marples <roy@marples.name>
parents: 4817
diff changeset
1692 * 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
1693 * 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
1694 * 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
1695 * 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
1696 * 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
1697 */
5020
d5297c3e1e7f BSD: When applying RA base information, get info without privsep
Roy Marples <roy@marples.name>
parents: 5019
diff changeset
1698 nd.ndi.linkmtu = 0;
d5297c3e1e7f BSD: When applying RA base information, get info without privsep
Roy Marples <roy@marples.name>
parents: 5019
diff changeset
1699 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
1700 }
5177
1d16a9434290 NetBSD: Gear up for kernel RA removal.
Roy Marples <roy@marples.name>
parents: 5173
diff changeset
1701 #endif
4818
22acf0138b3a BSD: Try and set linkmtu for the interface just to be nice.
Roy Marples <roy@marples.name>
parents: 4817
diff changeset
1702 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
1703 #else
92d3d8e9960c OpenBSD: Fix prior - OS cannot set any RA bits such as hop limit.
Roy Marples <roy@marples.name>
parents: 4816
diff changeset
1704 #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
1705 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
1706 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
1707 #endif
4813
ef33eb73e97d INET6: Apply hoplimit, reachable and retrans timer values from RA.
Roy Marples <roy@marples.name>
parents: 4799
diff changeset
1708 }
ef33eb73e97d INET6: Apply hoplimit, reachable and retrans timer values from RA.
Roy Marples <roy@marples.name>
parents: 4799
diff changeset
1709
5153
8248b3a04908 inet6: Add 'temporary' directive to the slaac option
Roy Marples <roy@marples.name>
parents: 5152
diff changeset
1710 #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
1711 #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
1712 #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
1713 static int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1714 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
1715 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1716 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
1717
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1718 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
1719 if (action) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1720 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
1721 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1722 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1723 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1724 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
1725 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1726 return val;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1727 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1728 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1729
4335
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
1730 int
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
1731 ip6_forwarding(__unused const char *ifname)
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
1732 {
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
1733 int val;
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
1734
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
1735 #ifdef IPV6CTL_FORWARDING
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
1736 val = get_inet6_sysctl(IPV6CTL_FORWARDING);
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
1737 #else
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
1738 val = get_inet6_sysctlbyname("net.inet6.ip6.forwarding");
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
1739 #endif
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
1740 return val < 0 ? 0 : val;
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
1741 }
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
1742
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1743 #ifdef SIOCIFAFATTACH
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1744 static int
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
1745 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
1746 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1747 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
1748
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1749 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
1750 ifar.ifar_af = af;
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
1751 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
1752 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1753 #endif
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 #ifdef SIOCGIFXFLAGS
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1756 static int
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
1757 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
1758 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1759 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
1760 int flags;
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
1761 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
1762
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1763 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
1764 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
1765 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1766 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
1767 #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
1768 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
1769 #endif
4218
f618f850efdc inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1770 /*
4229
12388193ccdc inet6: remove references to the crazies.
Roy Marples <roy@marples.name>
parents: 4220
diff changeset
1771 * 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
1772 * 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
1773 *
c9409ab7664d OpenBSD: Allow dhcpcd to work alongside slaacd
Roy Marples <roy@marples.name>
parents: 4301
diff changeset
1774 * 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
1775 * 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
1776 * 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
1777 * 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
1778 * 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
1779 * 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
1780 */
4321
c9409ab7664d OpenBSD: Allow dhcpcd to work alongside slaacd
Roy Marples <roy@marples.name>
parents: 4301
diff changeset
1781 #if defined(ND6_IFF_ACCEPT_RTADV)
c9409ab7664d OpenBSD: Allow dhcpcd to work alongside slaacd
Roy Marples <roy@marples.name>
parents: 4301
diff changeset
1782 #define BSD_AUTOCONF DHCPCD_IPV6RS
c9409ab7664d OpenBSD: Allow dhcpcd to work alongside slaacd
Roy Marples <roy@marples.name>
parents: 4301
diff changeset
1783 #else
c9409ab7664d OpenBSD: Allow dhcpcd to work alongside slaacd
Roy Marples <roy@marples.name>
parents: 4301
diff changeset
1784 #define BSD_AUTOCONF DHCPCD_IPV6RA_AUTOCONF
c9409ab7664d OpenBSD: Allow dhcpcd to work alongside slaacd
Roy Marples <roy@marples.name>
parents: 4301
diff changeset
1785 #endif
c9409ab7664d OpenBSD: Allow dhcpcd to work alongside slaacd
Roy Marples <roy@marples.name>
parents: 4301
diff changeset
1786 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
1787 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
1788 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
1789 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1790 ifr.ifr_flags = flags;
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
1791 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
1792 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1793 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1794
4118
ed1a6b24e5d2 if-bsd: compile on recent OpenBSD without ND6 flags
Roy Marples <roy@marples.name>
parents: 4103
diff changeset
1795 /* 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
1796 * existance. */
4118
ed1a6b24e5d2 if-bsd: compile on recent OpenBSD without ND6 flags
Roy Marples <roy@marples.name>
parents: 4103
diff changeset
1797 #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
1798 defined(ND6_IFF_PERFORMNUD) || \
ed1a6b24e5d2 if-bsd: compile on recent OpenBSD without ND6 flags
Roy Marples <roy@marples.name>
parents: 4103
diff changeset
1799 defined(ND6_IFF_ACCEPT_RTADV) || \
ed1a6b24e5d2 if-bsd: compile on recent OpenBSD without ND6 flags
Roy Marples <roy@marples.name>
parents: 4103
diff changeset
1800 defined(ND6_IFF_OVERRIDE_RTADV) || \
ed1a6b24e5d2 if-bsd: compile on recent OpenBSD without ND6 flags
Roy Marples <roy@marples.name>
parents: 4103
diff changeset
1801 defined(ND6_IFF_IFDISABLED)
ed1a6b24e5d2 if-bsd: compile on recent OpenBSD without ND6 flags
Roy Marples <roy@marples.name>
parents: 4103
diff changeset
1802 #define ND6_NDI_FLAGS
ed1a6b24e5d2 if-bsd: compile on recent OpenBSD without ND6 flags
Roy Marples <roy@marples.name>
parents: 4103
diff changeset
1803 #endif
ed1a6b24e5d2 if-bsd: compile on recent OpenBSD without ND6 flags
Roy Marples <roy@marples.name>
parents: 4103
diff changeset
1804
4218
f618f850efdc inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1805 void
4799
95842881a2ef BSD: Disable kernel RTADV sysctl earlier
Roy Marples <roy@marples.name>
parents: 4751
diff changeset
1806 if_disable_rtadv(void)
95842881a2ef BSD: Disable kernel RTADV sysctl earlier
Roy Marples <roy@marples.name>
parents: 4751
diff changeset
1807 {
95842881a2ef BSD: Disable kernel RTADV sysctl earlier
Roy Marples <roy@marples.name>
parents: 4751
diff changeset
1808 #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
1809 int ra = get_inet6_sysctl(IPV6CTL_ACCEPT_RTADV);
95842881a2ef BSD: Disable kernel RTADV sysctl earlier
Roy Marples <roy@marples.name>
parents: 4751
diff changeset
1810
95842881a2ef BSD: Disable kernel RTADV sysctl earlier
Roy Marples <roy@marples.name>
parents: 4751
diff changeset
1811 if (ra == -1) {
95842881a2ef BSD: Disable kernel RTADV sysctl earlier
Roy Marples <roy@marples.name>
parents: 4751
diff changeset
1812 if (errno != ENOENT)
95842881a2ef BSD: Disable kernel RTADV sysctl earlier
Roy Marples <roy@marples.name>
parents: 4751
diff changeset
1813 logerr("IPV6CTL_ACCEPT_RTADV");
95842881a2ef BSD: Disable kernel RTADV sysctl earlier
Roy Marples <roy@marples.name>
parents: 4751
diff changeset
1814 else if (ra != 0)
95842881a2ef BSD: Disable kernel RTADV sysctl earlier
Roy Marples <roy@marples.name>
parents: 4751
diff changeset
1815 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
1816 logerr("IPV6CTL_ACCEPT_RTADV");
95842881a2ef BSD: Disable kernel RTADV sysctl earlier
Roy Marples <roy@marples.name>
parents: 4751
diff changeset
1817 }
95842881a2ef BSD: Disable kernel RTADV sysctl earlier
Roy Marples <roy@marples.name>
parents: 4751
diff changeset
1818 #endif
95842881a2ef BSD: Disable kernel RTADV sysctl earlier
Roy Marples <roy@marples.name>
parents: 4751
diff changeset
1819 }
95842881a2ef BSD: Disable kernel RTADV sysctl earlier
Roy Marples <roy@marples.name>
parents: 4751
diff changeset
1820
95842881a2ef BSD: Disable kernel RTADV sysctl earlier
Roy Marples <roy@marples.name>
parents: 4751
diff changeset
1821 void
4218
f618f850efdc inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1822 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
1823 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1824 struct priv *priv;
4218
f618f850efdc inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1825 int s;
f618f850efdc inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1826 #ifdef ND6_NDI_FLAGS
f618f850efdc inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1827 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
1828 int flags;
4218
f618f850efdc inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1829 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1830
4218
f618f850efdc inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1831 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
1832 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
1833
4118
ed1a6b24e5d2 if-bsd: compile on recent OpenBSD without ND6 flags
Roy Marples <roy@marples.name>
parents: 4103
diff changeset
1834 #ifdef ND6_NDI_FLAGS
4218
f618f850efdc inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1835 memset(&nd, 0, sizeof(nd));
f618f850efdc inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1836 strlcpy(nd.ifname, ifp->name, sizeof(nd.ifname));
f618f850efdc inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1837 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
1838 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
1839 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
1840 #endif
b7da0da3e019 Revert "BSD: When applying RA base information, ensure flags are correct"
Roy Marples <roy@marples.name>
parents: 5018
diff changeset
1841
b7da0da3e019 Revert "BSD: When applying RA base information, ensure flags are correct"
Roy Marples <roy@marples.name>
parents: 5018
diff changeset
1842 #ifdef ND6_IFF_AUTO_LINKLOCAL
5173
81f78bbc8d48 Whitespace
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
1843 /* 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
1844 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
1845 #endif
b7da0da3e019 Revert "BSD: When applying RA base information, ensure flags are correct"
Roy Marples <roy@marples.name>
parents: 5018
diff changeset
1846
b7da0da3e019 Revert "BSD: When applying RA base information, ensure flags are correct"
Roy Marples <roy@marples.name>
parents: 5018
diff changeset
1847 #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
1848 /* 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
1849 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
1850 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1851
5019
b7da0da3e019 Revert "BSD: When applying RA base information, ensure flags are correct"
Roy Marples <roy@marples.name>
parents: 5018
diff changeset
1852 #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
1853 /* 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
1854 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
1855 #endif
4218
f618f850efdc inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1856
5019
b7da0da3e019 Revert "BSD: When applying RA base information, ensure flags are correct"
Roy Marples <roy@marples.name>
parents: 5018
diff changeset
1857 /*
b7da0da3e019 Revert "BSD: When applying RA base information, ensure flags are correct"
Roy Marples <roy@marples.name>
parents: 5018
diff changeset
1858 * 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
1859 * 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
1860 */
b7da0da3e019 Revert "BSD: When applying RA base information, ensure flags are correct"
Roy Marples <roy@marples.name>
parents: 5018
diff changeset
1861 #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
1862 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
1863 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
1864 #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
1865 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
1866 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
1867 #endif
b7da0da3e019 Revert "BSD: When applying RA base information, ensure flags are correct"
Roy Marples <roy@marples.name>
parents: 5018
diff changeset
1868 #endif
b7da0da3e019 Revert "BSD: When applying RA base information, ensure flags are correct"
Roy Marples <roy@marples.name>
parents: 5018
diff changeset
1869
b7da0da3e019 Revert "BSD: When applying RA base information, ensure flags are correct"
Roy Marples <roy@marples.name>
parents: 5018
diff changeset
1870 #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
1871 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
1872 nd.ndi.flags = (uint32_t)flags;
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
1873 if (if_ioctl6(ifp->ctx, SIOCSIFINFO_FLAGS,
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
1874 &nd, sizeof(nd)) == -1)
4218
f618f850efdc inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1875 logerr("%s: SIOCSIFINFO_FLAGS", ifp->name);
f618f850efdc inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1876 }
4118
ed1a6b24e5d2 if-bsd: compile on recent OpenBSD without ND6 flags
Roy Marples <roy@marples.name>
parents: 4103
diff changeset
1877 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1878
4218
f618f850efdc inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1879 /* Enabling IPv6 by whatever means must be the
f618f850efdc inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1880 * last action undertaken to ensure kernel RS and
f618f850efdc inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1881 * 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
1882 #ifdef SIOCIFAFATTACH
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
1883 if (if_af_attach(ifp, AF_INET6) == -1)
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
1884 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
1885 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1886
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1887 #ifdef SIOCGIFXFLAGS
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
1888 if (if_set_ifxflags(ifp) == -1)
4218
f618f850efdc inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1889 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
1890 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1891
5152
352c272ba3c3 BSD: Dont warn if the kernel does not support flushing routers
Roy Marples <roy@marples.name>
parents: 5125
diff changeset
1892 #ifdef SIOCSRTRFLUSH_IN6
4218
f618f850efdc inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1893 /* Flush the kernel knowledge of advertised routers
f618f850efdc inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1894 * and prefixes so the kernel does not expire prefixes
f618f850efdc inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1895 * and default routes we are trying to own. */
f618f850efdc inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1896 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
1897 struct in6_ifreq ifr;
4218
f618f850efdc inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1898
4331
836ab952fde5 BSD: SIOCSRTRFLUSH_IN6 and SIOCSPFXFLUSH_IN6 require in6_ifreq
Roy Marples <roy@marples.name>
parents: 4329
diff changeset
1899 memset(&ifr, 0, sizeof(ifr));
836ab952fde5 BSD: SIOCSRTRFLUSH_IN6 and SIOCSPFXFLUSH_IN6 require in6_ifreq
Roy Marples <roy@marples.name>
parents: 4329
diff changeset
1900 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
1901 if (if_ioctl6(ifp->ctx, SIOCSRTRFLUSH_IN6,
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
1902 &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
1903 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
1904 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
1905 #ifdef SIOCSPFXFLUSH_IN6
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
1906 if (if_ioctl6(ifp->ctx, SIOCSPFXFLUSH_IN6,
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4838
diff changeset
1907 &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
1908 errno != ENOTSUP && errno != ENOTTY)
4218
f618f850efdc inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1909 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
1910 #endif
4218
f618f850efdc inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1911 }
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1912 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1913 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1914 #endif