1 /* $NetBSD: if.h,v 1.12 2015/08/21 10:39:00 roy Exp $ */ 2 3 /* 4 * dhcpcd - DHCP client daemon 5 * Copyright (c) 2006-2015 Roy Marples <roy@marples.name> 6 * All rights reserved 7 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 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. 16 * 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 27 * SUCH DAMAGE. 28 */ 29 30 #ifndef INTERFACE_H 31 #define INTERFACE_H 32 33 #include <net/if.h> 34 #ifdef __FreeBSD__ 35 #include <net/if_var.h> 36 #endif 37 #include <net/route.h> /* for RTM_ADD et all */ 38 #include <netinet/in.h> 39 #ifdef BSD 40 #include <netinet/in_var.h> /* for IN_IFF_TENTATIVE et all */ 41 #endif 42 43 #if defined(__minix) 44 /* 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 52 * what we want. 53 */ 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) */ 60 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 66 # endif 67 #endif 68 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 72 # ifdef __NetBSD__ 73 # define NOCARRIER_PRESERVE_IP 74 # endif 75 #endif 76 77 #include "config.h" 78 #include "dhcpcd.h" 79 #include "ipv4.h" 80 #include "ipv6.h" 81 82 #define EUI64_ADDR_LEN 8 83 #define INFINIBAND_ADDR_LEN 20 84 85 /* Linux 2.4 doesn't define this */ 86 #ifndef ARPHRD_IEEE1394 87 # define ARPHRD_IEEE1394 24 88 #endif 89 90 /* The BSD's don't define this yet */ 91 #ifndef ARPHRD_INFINIBAND 92 # define ARPHRD_INFINIBAND 32 93 #endif 94 95 /* Work out if we have a private address or not 96 * 10/8 97 * 172.16/12 98 * 192.168/16 99 */ 100 #ifndef IN_PRIVATE 101 # define IN_PRIVATE(addr) (((addr & IN_CLASSA_NET) == 0x0a000000) || \ 102 ((addr & 0xfff00000) == 0xac100000) || \ 103 ((addr & IN_CLASSB_NET) == 0xc0a80000)) 104 #endif 105 106 #define RAW_EOF 1 << 0 107 #define RAW_PARTIALCSUM 2 << 0 108 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 *); 120 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 *); 129 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. */ 133 #ifndef RTM_ADD 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 */ 138 #endif 139 140 #ifdef INET 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 *); 146 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) 154 155 int if_addrflags(const struct in_addr *, const struct interface *); 156 157 int if_route(unsigned char, const struct rt *rt); 158 int if_initrt(struct interface *); 159 #endif 160 161 #ifdef INET6 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); 167 #else 168 #define ip6_use_tempaddr(a) (0) 169 #endif 170 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) 174 175 int if_addrflags6(const struct in6_addr *, const struct interface *); 176 int if_getlifetime6(struct ipv6_addr *); 177 178 int if_route6(unsigned char, const struct rt6 *rt); 179 int if_initrt6(struct interface *); 180 #else 181 #define if_checkipv6(a, b, c) (-1) 182 #endif 183 184 int if_machinearch(char *, size_t); 185 int xsocket(int, int, int, int); 186 #endif 187