1 | /* |
---|
2 | * dhcpcd - DHCP client daemon |
---|
3 | * Copyright (c) 2006-2013 Roy Marples <roy@marples.name> |
---|
4 | * All rights reserved |
---|
5 | |
---|
6 | * Redistribution and use in source and binary forms, with or without |
---|
7 | * modification, are permitted provided that the following conditions |
---|
8 | * are met: |
---|
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. |
---|
14 | * |
---|
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 |
---|
25 | * SUCH DAMAGE. |
---|
26 | */ |
---|
27 | |
---|
28 | #ifndef IPV4_H |
---|
29 | #define IPV4_H |
---|
30 | |
---|
31 | #include "dhcpcd.h" |
---|
32 | |
---|
33 | struct rt { |
---|
34 | TAILQ_ENTRY(rt) next; |
---|
35 | struct in_addr dest; |
---|
36 | struct in_addr net; |
---|
37 | struct in_addr gate; |
---|
38 | const struct interface *iface; |
---|
39 | int metric; |
---|
40 | struct in_addr src; |
---|
41 | }; |
---|
42 | TAILQ_HEAD(rt_head, rt); |
---|
43 | |
---|
44 | struct ipv4_addr { |
---|
45 | TAILQ_ENTRY(ipv4_addr) next; |
---|
46 | struct in_addr addr; |
---|
47 | struct in_addr net; |
---|
48 | struct in_addr dst; |
---|
49 | }; |
---|
50 | TAILQ_HEAD(ipv4_addrhead, ipv4_addr); |
---|
51 | |
---|
52 | struct ipv4_state { |
---|
53 | struct ipv4_addrhead addrs; |
---|
54 | }; |
---|
55 | |
---|
56 | #define IPV4_STATE(ifp) \ |
---|
57 | ((struct ipv4_state *)(ifp)->if_data[IF_DATA_IPV4]) |
---|
58 | #define IPV4_CSTATE(ifp) \ |
---|
59 | ((const struct ipv4_state *)(ifp)->if_data[IF_DATA_IPV4]) |
---|
60 | |
---|
61 | #ifdef INET |
---|
62 | int ipv4_init(void); |
---|
63 | int inet_ntocidr(struct in_addr); |
---|
64 | int inet_cidrtoaddr(int, struct in_addr *); |
---|
65 | uint32_t ipv4_getnetmask(uint32_t); |
---|
66 | int ipv4_addrexists(const struct in_addr *); |
---|
67 | |
---|
68 | void ipv4_buildroutes(void); |
---|
69 | void ipv4_applyaddr(void *); |
---|
70 | int ipv4_routedeleted(const struct rt *); |
---|
71 | |
---|
72 | struct ipv4_addr *ipv4_findaddr(struct interface *, |
---|
73 | const struct in_addr *, const struct in_addr *); |
---|
74 | void ipv4_handleifa(int, struct if_head *, const char *, |
---|
75 | const struct in_addr *, const struct in_addr *, const struct in_addr *); |
---|
76 | |
---|
77 | int if_address(const struct interface *, |
---|
78 | const struct in_addr *, const struct in_addr *, |
---|
79 | const struct in_addr *, int); |
---|
80 | #define ipv4_addaddress(iface, addr, net, brd) \ |
---|
81 | if_address(iface, addr, net, brd, 1) |
---|
82 | #define ipv4_setaddress(iface, addr, net, brd) \ |
---|
83 | if_address(iface, addr, net, brd, 2) |
---|
84 | #define ipv4_deleteaddress(iface, addr, net) \ |
---|
85 | if_address(iface, addr, net, NULL, -1) |
---|
86 | |
---|
87 | int if_route(const struct rt *rt, int); |
---|
88 | #define ipv4_addroute(rt) if_route(rt, 1) |
---|
89 | #define ipv4_changeroute(rt) if_route(rt, 0) |
---|
90 | #define ipv4_deleteroute(rt) if_route(rt, -1) |
---|
91 | #define del_src_route(rt) i_route(rt, -2); |
---|
92 | void ipv4_freeroutes(struct rt_head *); |
---|
93 | |
---|
94 | int ipv4_opensocket(struct interface *, int); |
---|
95 | ssize_t ipv4_sendrawpacket(const struct interface *, |
---|
96 | int, const void *, ssize_t); |
---|
97 | ssize_t ipv4_getrawpacket(struct interface *, int, void *, ssize_t, int *); |
---|
98 | void ipv4_free(struct interface *); |
---|
99 | #else |
---|
100 | #define ipv4_init() (-1) |
---|
101 | #define ipv4_applyaddr(a) {} |
---|
102 | #define ipv4_freeroutes(a) {} |
---|
103 | #define ipv4_free(a) {} |
---|
104 | #define ipv4_addrexists(a) (0) |
---|
105 | #endif |
---|
106 | |
---|
107 | #endif |
---|