1 /* $NetBSD: if.h,v 1.12 2015/08/21 10:39:00 roy Exp $ */
4 * dhcpcd - DHCP client daemon
5 * Copyright (c) 2006-2015 Roy Marples <roy@marples.name>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 #include <net/if_var.h>
37 #include <net/route.h> /* for RTM_ADD et all */
38 #include <netinet/in.h>
40 #include <netinet/in_var.h> /* for IN_IFF_TENTATIVE et all */
45 * These flags are used for IPv4 autoconfiguration (RFC 3927). The MINIX 3
46 * TCP/IP service does not support IPv4 autoconfiguration, because lwIP's
47 * AUTOIP implementation is all-or-nothing by nature: either it implements the
48 * whole thing fully itself, or no support is present at all. dhcpcd(8) needs
49 * a more hybrid implementation if at all. It appears that by undefining the
50 * following flags, dhcpcd(8) will assume that no support is present for them
51 * in the operating system, and do everything itself instead, which is exactly
54 #undef IN_IFF_TENTATIVE
55 #undef IN_IFF_DUPLICATED
56 #undef IN_IFF_DETACHED
57 #undef IN_IFF_TRYTENTATIVE
58 #undef IN_IFF_NOTREADY
59 #endif /* defined(__minix) */
61 /* Some systems have route metrics.
62 * OpenBSD route priority is not this. */
63 #ifndef HAVE_ROUTE_METRIC
64 # if defined(__linux__)
65 # define HAVE_ROUTE_METRIC 1
69 /* Some systems have in-built IPv4 DAD.
70 * However, we need them to do DAD at carrier up as well. */
71 #ifdef IN_IFF_TENTATIVE
73 # define NOCARRIER_PRESERVE_IP
82 #define EUI64_ADDR_LEN 8
83 #define INFINIBAND_ADDR_LEN 20
85 /* Linux 2.4 doesn't define this */
86 #ifndef ARPHRD_IEEE1394
87 # define ARPHRD_IEEE1394 24
90 /* The BSD's don't define this yet */
91 #ifndef ARPHRD_INFINIBAND
92 # define ARPHRD_INFINIBAND 32
95 /* Work out if we have a private address or not
101 # define IN_PRIVATE(addr) (((addr & IN_CLASSA_NET) == 0x0a000000) || \
102 ((addr & 0xfff00000) == 0xac100000) || \
103 ((addr & IN_CLASSB_NET) == 0xc0a80000))
106 #define RAW_EOF 1 << 0
107 #define RAW_PARTIALCSUM 2 << 0
109 int if_setflag(struct interface
*ifp
, short flag
);
110 #define if_up(ifp) if_setflag((ifp), (IFF_UP | IFF_RUNNING))
111 struct if_head
*if_discover(struct dhcpcd_ctx
*, int, char * const *);
112 struct interface
*if_find(struct if_head
*, const char *);
113 struct interface
*if_findindex(struct if_head
*, unsigned int);
114 void if_sortinterfaces(struct dhcpcd_ctx
*);
115 void if_free(struct interface
*);
116 int if_domtu(const struct interface
*, short int);
117 #define if_getmtu(ifp) if_domtu((ifp), 0)
118 #define if_setmtu(ifp, mtu) if_domtu((ifp), (mtu))
119 int if_carrier(struct interface
*);
121 /* The below functions are provided by if-KERNEL.c */
122 int if_conf(struct interface
*);
123 int if_init(struct interface
*);
124 int if_getssid(struct interface
*);
125 int if_vimaster(const struct dhcpcd_ctx
*ctx
, const char *);
126 int if_opensockets(struct dhcpcd_ctx
*);
127 int if_openlinksocket(void);
128 int if_managelink(struct dhcpcd_ctx
*);
130 /* dhcpcd uses the same routing flags as BSD.
131 * If the platform doesn't use these flags,
132 * map them in the platform interace file. */
134 #define RTM_ADD 0x1 /* Add Route */
135 #define RTM_DELETE 0x2 /* Delete Route */
136 #define RTM_CHANGE 0x3 /* Change Metrics or flags */
137 #define RTM_GET 0x4 /* Report Metrics */
141 extern const char *if_pfname
;
142 int if_openrawsocket(struct interface
*, uint16_t);
143 ssize_t
if_sendrawpacket(const struct interface
*,
144 uint16_t, const void *, size_t);
145 ssize_t
if_readrawpacket(struct interface
*, uint16_t, void *, size_t, int *);
147 int if_address(const struct interface
*,
148 const struct in_addr
*, const struct in_addr
*,
149 const struct in_addr
*, int);
150 #define if_addaddress(ifp, addr, net, brd) \
151 if_address(ifp, addr, net, brd, 1)
152 #define if_deladdress(ifp, addr, net) \
153 if_address(ifp, addr, net, NULL, -1)
155 int if_addrflags(const struct in_addr
*, const struct interface
*);
157 int if_route(unsigned char, const struct rt
*rt
);
158 int if_initrt(struct interface
*);
162 int if_checkipv6(struct dhcpcd_ctx
*ctx
, const struct interface
*, int);
163 #ifdef IPV6_MANAGETEMPADDR
164 int ip6_use_tempaddr(const char *ifname
);
165 int ip6_temp_preferred_lifetime(const char *ifname
);
166 int ip6_temp_valid_lifetime(const char *ifname
);
168 #define ip6_use_tempaddr(a) (0)
171 int if_address6(const struct ipv6_addr
*, int);
172 #define if_addaddress6(a) if_address6(a, 1)
173 #define if_deladdress6(a) if_address6(a, -1)
175 int if_addrflags6(const struct in6_addr
*, const struct interface
*);
176 int if_getlifetime6(struct ipv6_addr
*);
178 int if_route6(unsigned char, const struct rt6
*rt
);
179 int if_initrt6(struct interface
*);
181 #define if_checkipv6(a, b, c) (-1)
184 int if_machinearch(char *, size_t);
185 int xsocket(int, int, int, int);