BadVPN – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | /** |
2 | * @file BDHCPClientCore.h |
||
3 | * @author Ambroz Bizjak <ambrop7@gmail.com> |
||
4 | * |
||
5 | * @section LICENSE |
||
6 | * |
||
7 | * Redistribution and use in source and binary forms, with or without |
||
8 | * modification, are permitted provided that the following conditions 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 | * 3. Neither the name of the author nor the |
||
15 | * names of its contributors may be used to endorse or promote products |
||
16 | * derived from this software without specific prior written permission. |
||
17 | * |
||
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
||
19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
||
20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
||
21 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
||
22 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
||
23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
||
24 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
||
25 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
||
27 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
28 | * |
||
29 | * @section DESCRIPTION |
||
30 | * |
||
31 | * DHCP client, excluding system-dependent details. |
||
32 | */ |
||
33 | |||
34 | #ifndef BADVPN_DHCPCLIENT_BDHCPCLIENTCORE_H |
||
35 | #define BADVPN_DHCPCLIENT_BDHCPCLIENTCORE_H |
||
36 | |||
37 | #include <stdint.h> |
||
38 | #include <stddef.h> |
||
39 | |||
40 | #include <system/BReactor.h> |
||
41 | #include <base/DebugObject.h> |
||
42 | #include <random/BRandom2.h> |
||
43 | #include <flow/PacketPassInterface.h> |
||
44 | #include <flow/PacketRecvInterface.h> |
||
45 | |||
46 | #define BDHCPCLIENTCORE_EVENT_UP 1 |
||
47 | #define BDHCPCLIENTCORE_EVENT_DOWN 2 |
||
48 | |||
49 | #define BDHCPCLIENTCORE_MAX_DOMAIN_NAME_SERVERS 16 |
||
50 | |||
51 | typedef void (*BDHCPClientCore_func_getsendermac) (void *user, uint8_t *out_mac); |
||
52 | typedef void (*BDHCPClientCore_handler) (void *user, int event); |
||
53 | |||
54 | struct BDHCPClientCore_opts { |
||
55 | const char *hostname; |
||
56 | const char *vendorclassid; |
||
57 | const uint8_t *clientid; |
||
58 | size_t clientid_len; |
||
59 | }; |
||
60 | |||
61 | typedef struct { |
||
62 | PacketPassInterface *send_if; |
||
63 | PacketRecvInterface *recv_if; |
||
64 | uint8_t client_mac_addr[6]; |
||
65 | BReactor *reactor; |
||
66 | BRandom2 *random2; |
||
67 | void *user; |
||
68 | BDHCPClientCore_func_getsendermac func_getsendermac; |
||
69 | BDHCPClientCore_handler handler; |
||
70 | char *hostname; |
||
71 | char *vendorclassid; |
||
72 | uint8_t *clientid; |
||
73 | size_t clientid_len; |
||
74 | char *send_buf; |
||
75 | char *recv_buf; |
||
76 | int sending; |
||
77 | BTimer reset_timer; |
||
78 | BTimer request_timer; |
||
79 | BTimer renew_timer; |
||
80 | BTimer renew_request_timer; |
||
81 | BTimer lease_timer; |
||
82 | int state; |
||
83 | int request_count; |
||
84 | uint32_t xid; |
||
85 | int xid_reuse_counter; |
||
86 | struct { |
||
87 | uint32_t yiaddr; |
||
88 | uint32_t dhcp_server_identifier; |
||
89 | } offered; |
||
90 | struct { |
||
91 | uint32_t ip_address_lease_time; |
||
92 | uint32_t subnet_mask; |
||
93 | int have_router; |
||
94 | uint32_t router; |
||
95 | int domain_name_servers_count; |
||
96 | uint32_t domain_name_servers[BDHCPCLIENTCORE_MAX_DOMAIN_NAME_SERVERS]; |
||
97 | uint8_t server_mac[6]; |
||
98 | } acked; |
||
99 | DebugObject d_obj; |
||
100 | } BDHCPClientCore; |
||
101 | |||
102 | int BDHCPClientCore_Init (BDHCPClientCore *o, PacketPassInterface *send_if, PacketRecvInterface *recv_if, |
||
103 | uint8_t *client_mac_addr, struct BDHCPClientCore_opts opts, BReactor *reactor, |
||
104 | BRandom2 *random2, void *user, |
||
105 | BDHCPClientCore_func_getsendermac func_getsendermac, |
||
106 | BDHCPClientCore_handler handler); |
||
107 | void BDHCPClientCore_Free (BDHCPClientCore *o); |
||
108 | void BDHCPClientCore_GetClientIP (BDHCPClientCore *o, uint32_t *out_ip); |
||
109 | void BDHCPClientCore_GetClientMask (BDHCPClientCore *o, uint32_t *out_mask); |
||
110 | int BDHCPClientCore_GetRouter (BDHCPClientCore *o, uint32_t *out_router); |
||
111 | int BDHCPClientCore_GetDNS (BDHCPClientCore *o, uint32_t *out_dns_servers, size_t max_dns_servers); |
||
112 | void BDHCPClientCore_GetServerMAC (BDHCPClientCore *o, uint8_t *out_mac); |
||
113 | |||
114 | #endif |