annotate src/if.h @ 5570:f32e37b1d371 draft

dhcpcd: Don't roam when anonymous is set We can now remove the NOCARRIER_PRESERVE_IP define.
author Roy Marples <roy@marples.name>
date Sun, 27 Dec 2020 21:59:32 +0000
parents e65d193a1960
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 * dhcpcd - DHCP client daemon
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 #ifndef INTERFACE_H
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
30 #define INTERFACE_H
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
31
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
32 #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
33 #include <net/route.h> /* for RTM_ADD et all */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
34 #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
35 #ifdef BSD
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
36 #include <netinet/in_var.h> /* for IN_IFF_TENTATIVE et all */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
37 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
38
4189
0b088d803b61 dhcp6: don't listen on IPv6 addresses when not using DHCP6
Roy Marples <roy@marples.name>
parents: 4076
diff changeset
39 #include <ifaddrs.h>
0b088d803b61 dhcp6: don't listen on IPv6 addresses when not using DHCP6
Roy Marples <roy@marples.name>
parents: 4076
diff changeset
40
5376
66bbeeebbe92 dhcpcd: Add an option to poll the interface carrier state
Roy Marples <roy@marples.name>
parents: 5310
diff changeset
41 /* If the interface does not support carrier status (ie PPP),
66bbeeebbe92 dhcpcd: Add an option to poll the interface carrier state
Roy Marples <roy@marples.name>
parents: 5310
diff changeset
42 * dhcpcd can poll it for the relevant flags periodically */
66bbeeebbe92 dhcpcd: Add an option to poll the interface carrier state
Roy Marples <roy@marples.name>
parents: 5310
diff changeset
43 #define IF_POLL_UP 100 /* milliseconds */
66bbeeebbe92 dhcpcd: Add an option to poll the interface carrier state
Roy Marples <roy@marples.name>
parents: 5310
diff changeset
44
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
45 /*
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
46 * Systems which handle 1 address per alias.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
47 * Currenly this is just Solaris.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
48 * While Linux can do aliased addresses, it is only useful for their
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
49 * legacy ifconfig(8) tool which cannot display >1 IPv4 address
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
50 * (it can display many IPv6 addresses which makes the limitation odd).
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
51 * Linux has ip(8) which is a more feature rich tool, without the above
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
52 * restriction.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
53 */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
54 #ifndef ALIAS_ADDR
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
55 # ifdef __sun
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
56 # define ALIAS_ADDR
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
57 # endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
58 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
59
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
60 #include "config.h"
4948
b664b38faf10 ioctl: The POSIX signature differs from BSD and glibc
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
61
b664b38faf10 ioctl: The POSIX signature differs from BSD and glibc
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
62 /* POSIX defines ioctl request as an int, which Solaris and musl use.
b664b38faf10 ioctl: The POSIX signature differs from BSD and glibc
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
63 * Everyone else use an unsigned long, which happens to be the bigger one
b664b38faf10 ioctl: The POSIX signature differs from BSD and glibc
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
64 * so we use that in our on wire API. */
b664b38faf10 ioctl: The POSIX signature differs from BSD and glibc
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
65 #ifdef IOCTL_REQUEST_TYPE
b664b38faf10 ioctl: The POSIX signature differs from BSD and glibc
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
66 typedef IOCTL_REQUEST_TYPE ioctl_request_t;
b664b38faf10 ioctl: The POSIX signature differs from BSD and glibc
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
67 #else
b664b38faf10 ioctl: The POSIX signature differs from BSD and glibc
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
68 typedef unsigned long ioctl_request_t;
b664b38faf10 ioctl: The POSIX signature differs from BSD and glibc
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
69 #endif
b664b38faf10 ioctl: The POSIX signature differs from BSD and glibc
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
70
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
71 #include "dhcpcd.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 "ipv4.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 "ipv6.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 "route.h"
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
75
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
76 #define EUI64_ADDR_LEN 8
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
77 #define INFINIBAND_ADDR_LEN 20
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
78
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
79 /* Linux 2.4 doesn't define this */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
80 #ifndef ARPHRD_IEEE1394
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
81 # define ARPHRD_IEEE1394 24
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 /* The BSD's don't define this yet */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
85 #ifndef ARPHRD_INFINIBAND
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
86 # define ARPHRD_INFINIBAND 32
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
87 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
88
5028
c06163d3bc14 DHCP: Support jumbo frames
Roy Marples <roy@marples.name>
parents: 4958
diff changeset
89 /* Maximum frame length.
c06163d3bc14 DHCP: Support jumbo frames
Roy Marples <roy@marples.name>
parents: 4958
diff changeset
90 * Support jumbo frames and some extra. */
5029
f979cefdddcf ARP: Recalculate ARP buffer taking into account max frame length
Roy Marples <roy@marples.name>
parents: 5028
diff changeset
91 #define FRAMEHDRLEN_MAX 14 /* only ethernet support */
f979cefdddcf ARP: Recalculate ARP buffer taking into account max frame length
Roy Marples <roy@marples.name>
parents: 5028
diff changeset
92 #define FRAMELEN_MAX (FRAMEHDRLEN_MAX + 9216)
5028
c06163d3bc14 DHCP: Support jumbo frames
Roy Marples <roy@marples.name>
parents: 4958
diff changeset
93
5207
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
94 #define UDPLEN_MAX 64 * 1024
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
95
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
96 /* Work out if we have a private address or not
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
97 * 10/8
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
98 * 172.16/12
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
99 * 192.168/16
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
100 */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
101 #ifndef IN_PRIVATE
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
102 # define IN_PRIVATE(addr) (((addr & IN_CLASSA_NET) == 0x0a000000) || \
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
103 ((addr & 0xfff00000) == 0xac100000) || \
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
104 ((addr & IN_CLASSB_NET) == 0xc0a80000))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
105 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
106
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
107 #ifndef CLLADDR
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
108 #ifdef AF_LINK
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
109 # define CLLADDR(sdl) (const void *)((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
110 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
111 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
112
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
113 #ifdef __sun
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
114 /* Solaris stupidly defines this for compat with BSD
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
115 * but then ignores it. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
116 #undef RTF_CLONING
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
117
5279
cab28576ec7e Solaris: IP_RECVIF is busted on DilOS at least
Roy Marples <roy@marples.name>
parents: 5231
diff changeset
118 /* This interface is busted on DilOS at least.
cab28576ec7e Solaris: IP_RECVIF is busted on DilOS at least
Roy Marples <roy@marples.name>
parents: 5231
diff changeset
119 * It used to work, but lukily Solaris can fall back to
cab28576ec7e Solaris: IP_RECVIF is busted on DilOS at least
Roy Marples <roy@marples.name>
parents: 5231
diff changeset
120 * IP_PKTINFO. */
cab28576ec7e Solaris: IP_RECVIF is busted on DilOS at least
Roy Marples <roy@marples.name>
parents: 5231
diff changeset
121 #undef IP_RECVIF
cab28576ec7e Solaris: IP_RECVIF is busted on DilOS at least
Roy Marples <roy@marples.name>
parents: 5231
diff changeset
122
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
123 /* Solaris getifaddrs is very un-suitable for dhcpcd.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
124 * See if-sun.c for details why. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
125 struct ifaddrs;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
126 int if_getifaddrs(struct ifaddrs **);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
127 #define getifaddrs if_getifaddrs
4692
4a8c51be0604 Solaris: Get the subnet in ipv6 ifa handler
Roy Marples <roy@marples.name>
parents: 4605
diff changeset
128 int if_getsubnet(struct dhcpcd_ctx *, const char *, int, void *, size_t);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
129 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
130
4948
b664b38faf10 ioctl: The POSIX signature differs from BSD and glibc
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
131 int if_ioctl(struct dhcpcd_ctx *, ioctl_request_t, void *, size_t);
5204
47f18579daae privsep: Implement pledge(2) support as found on OpenBSD
Roy Marples <roy@marples.name>
parents: 5153
diff changeset
132 #ifdef HAVE_PLEDGE
47f18579daae privsep: Implement pledge(2) support as found on OpenBSD
Roy Marples <roy@marples.name>
parents: 5153
diff changeset
133 #define pioctl(ctx, req, data, len) if_ioctl((ctx), (req), (data), (len))
47f18579daae privsep: Implement pledge(2) support as found on OpenBSD
Roy Marples <roy@marples.name>
parents: 5153
diff changeset
134 #else
47f18579daae privsep: Implement pledge(2) support as found on OpenBSD
Roy Marples <roy@marples.name>
parents: 5153
diff changeset
135 #define pioctl(ctx, req, data, len) ioctl((ctx)->pf_inet_fd, (req),(data),(len))
47f18579daae privsep: Implement pledge(2) support as found on OpenBSD
Roy Marples <roy@marples.name>
parents: 5153
diff changeset
136 #endif
4958
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4948
diff changeset
137 int if_getflags(struct interface *);
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4948
diff changeset
138 int if_setflag(struct interface *, short, short);
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4948
diff changeset
139 #define if_up(ifp) if_setflag((ifp), (IFF_UP | IFF_RUNNING), 0)
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4948
diff changeset
140 #define if_down(ifp) if_setflag((ifp), 0, IFF_UP);
5499
6a2da5651841 dhcpcd: Simplify the link handling even more
Roy Marples <roy@marples.name>
parents: 5486
diff changeset
141 bool if_is_link_up(const struct interface *);
4076
9433864aa014 Hardware Address validation
Roy Marples <roy@marples.name>
parents: 4052
diff changeset
142 bool if_valid_hwaddr(const uint8_t *, size_t);
4189
0b088d803b61 dhcp6: don't listen on IPv6 addresses when not using DHCP6
Roy Marples <roy@marples.name>
parents: 4076
diff changeset
143 struct if_head *if_discover(struct dhcpcd_ctx *, struct ifaddrs **,
0b088d803b61 dhcp6: don't listen on IPv6 addresses when not using DHCP6
Roy Marples <roy@marples.name>
parents: 4076
diff changeset
144 int, char * const *);
4235
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4218
diff changeset
145 void if_markaddrsstale(struct if_head *);
4189
0b088d803b61 dhcp6: don't listen on IPv6 addresses when not using DHCP6
Roy Marples <roy@marples.name>
parents: 4076
diff changeset
146 void if_learnaddrs(struct dhcpcd_ctx *, struct if_head *, struct ifaddrs **);
4235
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4218
diff changeset
147 void if_deletestaleaddrs(struct if_head *);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
148 struct interface *if_find(struct if_head *, const char *);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
149 struct interface *if_findindex(struct if_head *, unsigned int);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
150 struct interface *if_loopback(struct dhcpcd_ctx *);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
151 void if_free(struct interface *);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
152 int if_domtu(const struct interface *, short int);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
153 #define if_getmtu(ifp) if_domtu((ifp), 0)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
154 #define if_setmtu(ifp, mtu) if_domtu((ifp), (mtu))
5486
8e2b8ce8c972 BSD: struct if_data->ifi_link_state is the single source of truth
Roy Marples <roy@marples.name>
parents: 5475
diff changeset
155 int if_carrier(struct interface *, const void *);
5557
e65d193a1960 Linux: Support wireless IP roaming
Roy Marples <roy@marples.name>
parents: 5499
diff changeset
156 bool if_roaming(struct interface *);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
157
4439
5ed513825ce5 if: Add a generic function to create an aliased address name
Roy Marples <roy@marples.name>
parents: 4433
diff changeset
158 #ifdef ALIAS_ADDR
5ed513825ce5 if: Add a generic function to create an aliased address name
Roy Marples <roy@marples.name>
parents: 4433
diff changeset
159 int if_makealias(char *, size_t, const char *, int);
5ed513825ce5 if: Add a generic function to create an aliased address name
Roy Marples <roy@marples.name>
parents: 4433
diff changeset
160 #endif
5ed513825ce5 if: Add a generic function to create an aliased address name
Roy Marples <roy@marples.name>
parents: 4433
diff changeset
161
4433
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4374
diff changeset
162 int if_mtu_os(const struct interface *);
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4374
diff changeset
163
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
164 /*
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
165 * Helper to decode an interface name of bge0:1 to
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
166 * devname = bge0, drvname = bge0, ppa = 0, lun = 1.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
167 * If ppa or lun are invalid they are set to -1.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
168 */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
169 struct if_spec {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
170 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
171 char devname[IF_NAMESIZE];
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
172 char drvname[IF_NAMESIZE];
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
173 int ppa;
5071
e09697275eda if: Decode vlid from the interface name
Roy Marples <roy@marples.name>
parents: 5057
diff changeset
174 int vlid;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
175 int lun;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
176 };
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
177 int if_nametospec(const char *, struct if_spec *);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
178
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
179 /* The below functions are provided by if-KERNEL.c */
5458
dd8347a0ea1c Adjust prior so that message is logged before starting dev
Roy Marples <roy@marples.name>
parents: 5457
diff changeset
180 int os_init(void);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
181 int if_conf(struct interface *);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
182 int if_init(struct interface *);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
183 int if_getssid(struct interface *);
5310
0a6bde63868b privsep: Remove pledges inet and dns from the master process
Roy Marples <roy@marples.name>
parents: 5282
diff changeset
184 int if_ignoregroup(int, const char *);
4748
4cfd9d38741f BSD: Ignore interface groups as we would the interface name
Roy Marples <roy@marples.name>
parents: 4747
diff changeset
185 bool if_ignore(struct dhcpcd_ctx *, const char *);
5204
47f18579daae privsep: Implement pledge(2) support as found on OpenBSD
Roy Marples <roy@marples.name>
parents: 5153
diff changeset
186 int if_vimaster(struct dhcpcd_ctx *ctx, const char *);
4052
08038b46c0f5 Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents: 3983
diff changeset
187 unsigned short if_vlanid(const struct interface *);
5457
7fb0274b9127 Linux: detect network namespace and deny udev in one
Roy Marples <roy@marples.name>
parents: 5436
diff changeset
188 char * if_getnetworknamespace(char *, size_t);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
189 int if_opensockets(struct dhcpcd_ctx *);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
190 int if_opensockets_os(struct dhcpcd_ctx *);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
191 void if_closesockets(struct dhcpcd_ctx *);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
192 void if_closesockets_os(struct dhcpcd_ctx *);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
193 int if_handlelink(struct dhcpcd_ctx *);
4958
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4948
diff changeset
194 int if_randomisemac(struct interface *);
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4948
diff changeset
195 int if_setmac(struct interface *ifp, void *, uint8_t);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
196
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
197 /* dhcpcd uses the same routing flags as BSD.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
198 * If the platform doesn't use these flags,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
199 * map them in the platform interace file. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
200 #ifndef RTM_ADD
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
201 #define RTM_ADD 0x1 /* Add Route */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
202 #define RTM_DELETE 0x2 /* Delete Route */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
203 #define RTM_CHANGE 0x3 /* Change Metrics or flags */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
204 #define RTM_GET 0x4 /* Report Metrics */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
205 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
206
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
207 /* Define SOCK_CLOEXEC and SOCK_NONBLOCK for systems that lack it.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
208 * xsocket() in if.c will map them to fctnl FD_CLOEXEC and O_NONBLOCK. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
209 #ifdef SOCK_CLOEXEC
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
210 # define HAVE_SOCK_CLOEXEC
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
211 #else
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
212 # define SOCK_CLOEXEC 0x10000000
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
213 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
214 #ifdef SOCK_NONBLOCK
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
215 # define HAVE_SOCK_NONBLOCK
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
216 #else
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
217 # define SOCK_NONBLOCK 0x20000000
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
218 #endif
5231
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5207
diff changeset
219 #ifndef SOCK_CXNB
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5207
diff changeset
220 #define SOCK_CXNB SOCK_CLOEXEC | SOCK_NONBLOCK
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5207
diff changeset
221 #endif
5436
56c934c73aa8 if: introduce xsocketpair, similar to xsocket
Roy Marples <roy@marples.name>
parents: 5376
diff changeset
222 int xsocket(int, int, int);
56c934c73aa8 if: introduce xsocketpair, similar to xsocket
Roy Marples <roy@marples.name>
parents: 5376
diff changeset
223 int xsocketpair(int, int, int, int[2]);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
224
3983
45f0408b6c28 These functions are AF agnostic now.
Roy Marples <roy@marples.name>
parents: 3965
diff changeset
225 int if_route(unsigned char, const struct rt *rt);
4400
2d6a2c8c6b56 route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents: 4394
diff changeset
226 int if_initrt(struct dhcpcd_ctx *, rb_tree_t *, int);
3983
45f0408b6c28 These functions are AF agnostic now.
Roy Marples <roy@marples.name>
parents: 3965
diff changeset
227
5057
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5029
diff changeset
228 int if_missfilter(struct interface *, struct sockaddr *);
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5029
diff changeset
229 int if_missfilter_apply(struct dhcpcd_ctx *);
a5fd2097d40f BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents: 5029
diff changeset
230
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
231 #ifdef INET
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
232 int if_address(unsigned char, const struct ipv4_addr *);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
233 int if_addrflags(const struct interface *, const struct in_addr *,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
234 const char *);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
235
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
236 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
237
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
238 #ifdef INET6
4799
95842881a2ef BSD: Disable kernel RTADV sysctl earlier
Roy Marples <roy@marples.name>
parents: 4748
diff changeset
239 void if_disable_rtadv(void);
4218
f618f850efdc inet6: simplify setup of kernel
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
240 void if_setup_inet6(const struct interface *);
4335
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
241 int ip6_forwarding(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
242
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4813
diff changeset
243 struct ra;
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4813
diff changeset
244 struct ipv6_addr;
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4813
diff changeset
245
4813
ef33eb73e97d INET6: Apply hoplimit, reachable and retrans timer values from RA.
Roy Marples <roy@marples.name>
parents: 4799
diff changeset
246 int if_applyra(const struct ra *);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
247 int if_address6(unsigned char, const struct ipv6_addr *);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
248 int if_addrflags6(const struct interface *, const struct in6_addr *,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
249 const char *);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
250 int if_getlifetime6(struct ipv6_addr *);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
251
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
252 #else
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
253 #define if_checkipv6(a, b, c) (-1)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
254 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
255
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
256 int if_machinearch(char *, size_t);
4374
d67204739087 Fold all CMSG parsing into a common function.
Roy Marples <roy@marples.name>
parents: 4335
diff changeset
257 struct interface *if_findifpfromcmsg(struct dhcpcd_ctx *,
d67204739087 Fold all CMSG parsing into a common function.
Roy Marples <roy@marples.name>
parents: 4335
diff changeset
258 struct msghdr *, int *);
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4813
diff changeset
259
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4813
diff changeset
260 #ifdef __linux__
5282
8afafcabcfa5 privsep: Drain the link socket as we can't re-open it.
Roy Marples <roy@marples.name>
parents: 5279
diff changeset
261 int if_linksocket(struct sockaddr_nl *, int, int);
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4813
diff changeset
262 int if_getnetlink(struct dhcpcd_ctx *, struct iovec *, int, int,
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4813
diff changeset
263 int (*)(struct dhcpcd_ctx *, void *, struct nlmsghdr *), void *);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
264 #endif
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4813
diff changeset
265 #endif