1 /* $NetBSD: ipv4.h,v 1.13 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 #ifdef IN_IFF_TENTATIVE
36 #define IN_IFF_NOTUSEABLE \
37 (IN_IFF_TENTATIVE | IN_IFF_DUPLICATED | IN_IFF_DETACHED)
40 /* Prefer our macro */
45 #if BYTE_ORDER == BIG_ENDIAN
47 #elif BYTE_ORDER == LITTLE_ENDIAN
49 ((((uint32_t)(A) & 0xff000000) >> 24) | \
50 (((uint32_t)(A) & 0x00ff0000) >> 8) | \
51 (((uint32_t)(A) & 0x0000ff00) << 8) | \
52 (((uint32_t)(A) & 0x000000ff) << 24))
55 #endif /* BYTE_ORDER */
62 const struct interface
*iface
;
63 #ifdef HAVE_ROUTE_METRIC
71 TAILQ_HEAD(rt_head
, rt
);
74 TAILQ_ENTRY(ipv4_addr
) next
;
78 struct interface
*iface
;
81 TAILQ_HEAD(ipv4_addrhead
, ipv4_addr
);
84 struct ipv4_addrhead addrs
;
85 struct rt_head routes
;
89 size_t buffer_size
, buffer_len
, buffer_pos
;
90 unsigned char *buffer
;
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])
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
*,
130 void ipv4_freeroutes(struct rt_head
*);
132 void ipv4_free(struct interface
*);
133 void ipv4_ctxfree(struct dhcpcd_ctx
*);
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)