2
* dhcpcd - DHCP client daemon
3
* Copyright (c) 2006-2015 Roy Marples <roy@marples.name>
6
* Redistribution and use in source and binary forms, with or without
7
* modification, are permitted provided that the following conditions
9
* 1. Redistributions of source code must retain the above copyright
10
* notice, this list of conditions and the following disclaimer.
11
* 2. Redistributions in binary form must reproduce the above copyright
12
* notice, this list of conditions and the following disclaimer in the
13
* documentation and/or other materials provided with the distribution.
15
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33
#include <net/if_var.h>
35
#include <net/route.h> /* for RTM_ADD et all */
36
#include <netinet/in.h>
38
#include <netinet/in_var.h> /* for IN_IFF_TENTATIVE et all */
41
/* Some systems have route metrics.
42
* OpenBSD route priority is not this. */
43
#ifndef HAVE_ROUTE_METRIC
44
# if defined(__linux__)
45
# define HAVE_ROUTE_METRIC 1
49
/* Some systems have in-built IPv4 DAD.
50
* However, we need them to do DAD at carrier up as well. */
51
#ifdef IN_IFF_TENTATIVE
53
# define NOCARRIER_PRESERVE_IP
62
#define EUI64_ADDR_LEN 8
63
#define INFINIBAND_ADDR_LEN 20
65
/* Linux 2.4 doesn't define this */
66
#ifndef ARPHRD_IEEE1394
67
# define ARPHRD_IEEE1394 24
70
/* The BSD's don't define this yet */
71
#ifndef ARPHRD_INFINIBAND
72
# define ARPHRD_INFINIBAND 32
75
/* Work out if we have a private address or not
81
# define IN_PRIVATE(addr) (((addr & IN_CLASSA_NET) == 0x0a000000) || \
82
((addr & 0xfff00000) == 0xac100000) || \
83
((addr & IN_CLASSB_NET) == 0xc0a80000))
86
#define LINKLOCAL_ADDR 0xa9fe0000
87
#define LINKLOCAL_MASK IN_CLASSB_NET
88
#define LINKLOCAL_BRDC (LINKLOCAL_ADDR | ~LINKLOCAL_MASK)
91
# define IN_LINKLOCAL(addr) ((addr & IN_CLASSB_NET) == LINKLOCAL_ADDR)
94
#define RAW_EOF 1 << 0
95
#define RAW_PARTIALCSUM 2 << 0
97
int if_setflag(struct interface *ifp, short flag);
98
#define if_up(ifp) if_setflag((ifp), (IFF_UP | IFF_RUNNING))
99
struct if_head *if_discover(struct dhcpcd_ctx *, int, char * const *);
100
struct interface *if_find(struct if_head *, const char *);
101
struct interface *if_findindex(struct if_head *, unsigned int);
102
void if_sortinterfaces(struct dhcpcd_ctx *);
103
void if_free(struct interface *);
104
int if_domtu(const char *, short int);
105
#define if_getmtu(iface) if_domtu(iface, 0)
106
#define if_setmtu(iface, mtu) if_domtu(iface, mtu)
107
int if_carrier(struct interface *);
109
/* The below functions are provided by if-KERNEL.c */
110
int if_conf(struct interface *);
111
int if_init(struct interface *);
112
int if_getssid(struct interface *);
113
int if_vimaster(const char *);
114
int if_openlinksocket(void);
115
int if_managelink(struct dhcpcd_ctx *);
117
/* dhcpcd uses the same routing flags as BSD.
118
* If the platform doesn't use these flags,
119
* map them in the platform interace file. */
121
#define RTM_ADD 0x1 /* Add Route */
122
#define RTM_DELETE 0x2 /* Delete Route */
123
#define RTM_CHANGE 0x3 /* Change Metrics or flags */
124
#define RTM_GET 0x4 /* Report Metrics */
128
extern const char *if_pfname;
129
int if_openrawsocket(struct interface *, uint16_t);
130
ssize_t if_sendrawpacket(const struct interface *,
131
uint16_t, const void *, size_t);
132
ssize_t if_readrawpacket(struct interface *, uint16_t, void *, size_t, int *);
134
int if_address(const struct interface *,
135
const struct in_addr *, const struct in_addr *,
136
const struct in_addr *, int);
137
#define if_addaddress(ifp, addr, net, brd) \
138
if_address(ifp, addr, net, brd, 1)
139
#define if_deladdress(ifp, addr, net) \
140
if_address(ifp, addr, net, NULL, -1)
142
int if_addrflags(const struct in_addr *, const struct interface *);
144
int if_route(unsigned char, const struct rt *rt);
145
int if_initrt(struct interface *);
149
int if_checkipv6(struct dhcpcd_ctx *ctx, const struct interface *, int);
150
#ifdef IPV6_MANAGETEMPADDR
151
int ip6_use_tempaddr(const char *ifname);
152
int ip6_temp_preferred_lifetime(const char *ifname);
153
int ip6_temp_valid_lifetime(const char *ifname);
155
#define ip6_use_tempaddr(a) (0)
158
int if_address6(const struct ipv6_addr *, int);
159
#define if_addaddress6(a) if_address6(a, 1)
160
#define if_deladdress6(a) if_address6(a, -1)
162
int if_addrflags6(const struct in6_addr *, const struct interface *);
163
int if_getlifetime6(struct ipv6_addr *);
165
int if_route6(unsigned char, const struct rt6 *rt);
166
int if_initrt6(struct interface *);
168
#define if_checkipv6(a, b, c) (-1)
171
int if_machinearch(char *, size_t);