Remove building with NOCRYPTO option
[minix3.git] / external / bsd / dhcpcd / dist / ipv4.h
blob8373f0cbfaa2a82b88afbddb2d4ba6522aaaf0c3
1 /* $NetBSD: ipv4.h,v 1.13 2015/08/21 10:39:00 roy Exp $ */
3 /*
4 * dhcpcd - DHCP client daemon
5 * Copyright (c) 2006-2015 Roy Marples <roy@marples.name>
6 * All rights reserved
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.
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.
30 #ifndef IPV4_H
31 #define IPV4_H
33 #include "dhcpcd.h"
35 #ifdef IN_IFF_TENTATIVE
36 #define IN_IFF_NOTUSEABLE \
37 (IN_IFF_TENTATIVE | IN_IFF_DUPLICATED | IN_IFF_DETACHED)
38 #endif
40 /* Prefer our macro */
41 #ifdef HTONL
42 #undef HTONL
43 #endif
45 #if BYTE_ORDER == BIG_ENDIAN
46 #define HTONL(A) (A)
47 #elif BYTE_ORDER == LITTLE_ENDIAN
48 #define HTONL(A) \
49 ((((uint32_t)(A) & 0xff000000) >> 24) | \
50 (((uint32_t)(A) & 0x00ff0000) >> 8) | \
51 (((uint32_t)(A) & 0x0000ff00) << 8) | \
52 (((uint32_t)(A) & 0x000000ff) << 24))
53 #else
54 #error Endian unknown
55 #endif /* BYTE_ORDER */
57 struct rt {
58 TAILQ_ENTRY(rt) next;
59 struct in_addr dest;
60 struct in_addr net;
61 struct in_addr gate;
62 const struct interface *iface;
63 #ifdef HAVE_ROUTE_METRIC
64 unsigned int metric;
65 #endif
66 unsigned int mtu;
67 struct in_addr src;
68 unsigned int flags;
69 unsigned int state;
71 TAILQ_HEAD(rt_head, rt);
73 struct ipv4_addr {
74 TAILQ_ENTRY(ipv4_addr) next;
75 struct in_addr addr;
76 struct in_addr net;
77 struct in_addr dst;
78 struct interface *iface;
79 int addr_flags;
81 TAILQ_HEAD(ipv4_addrhead, ipv4_addr);
83 struct ipv4_state {
84 struct ipv4_addrhead addrs;
85 struct rt_head routes;
87 #ifdef BSD
88 /* Buffer for BPF */
89 size_t buffer_size, buffer_len, buffer_pos;
90 unsigned char *buffer;
91 #endif
94 #define IPV4_STATE(ifp) \
95 ((struct ipv4_state *)(ifp)->if_data[IF_DATA_IPV4])
96 #define IPV4_CSTATE(ifp) \
97 ((const struct ipv4_state *)(ifp)->if_data[IF_DATA_IPV4])
99 #ifdef INET
100 struct ipv4_state *ipv4_getstate(struct interface *);
101 int ipv4_init(struct dhcpcd_ctx *);
102 int ipv4_protocol_fd(const struct interface *, uint16_t);
103 int ipv4_ifcmp(const struct interface *, const struct interface *);
104 uint8_t inet_ntocidr(struct in_addr);
105 int inet_cidrtoaddr(int, struct in_addr *);
106 uint32_t ipv4_getnetmask(uint32_t);
107 int ipv4_hasaddr(const struct interface *);
109 #define STATE_ADDED 0x01
110 #define STATE_FAKE 0x02
112 void ipv4_buildroutes(struct dhcpcd_ctx *);
113 int ipv4_deladdr(struct interface *, const struct in_addr *,
114 const struct in_addr *, int);
115 int ipv4_preferanother(struct interface *);
116 struct ipv4_addr *ipv4_addaddr(struct interface *,
117 const struct in_addr *, const struct in_addr *, const struct in_addr *);
118 void ipv4_applyaddr(void *);
119 int ipv4_handlert(struct dhcpcd_ctx *, int, struct rt *);
120 void ipv4_freerts(struct rt_head *);
122 struct ipv4_addr *ipv4_iffindaddr(struct interface *,
123 const struct in_addr *, const struct in_addr *);
124 struct ipv4_addr *ipv4_iffindlladdr(struct interface *);
125 struct ipv4_addr *ipv4_findaddr(struct dhcpcd_ctx *, const struct in_addr *);
126 void ipv4_handleifa(struct dhcpcd_ctx *, int, struct if_head *, const char *,
127 const struct in_addr *, const struct in_addr *, const struct in_addr *,
128 int);
130 void ipv4_freeroutes(struct rt_head *);
132 void ipv4_free(struct interface *);
133 void ipv4_ctxfree(struct dhcpcd_ctx *);
134 #else
135 #define ipv4_init(a) (-1)
136 #define ipv4_sortinterfaces(a) {}
137 #define ipv4_applyaddr(a) {}
138 #define ipv4_freeroutes(a) {}
139 #define ipv4_free(a) {}
140 #define ipv4_ctxfree(a) {}
141 #define ipv4_hasaddr(a) (0)
142 #define ipv4_preferanother(a) (0)
143 #endif
145 #endif