dhcpv6: Send domain list option to server
[platform/upstream/connman.git] / gdhcp / gdhcp.h
1 /*
2  *
3  *  DHCP library with GLib integration
4  *
5  *  Copyright (C) 2009-2012  Intel Corporation. All rights reserved.
6  *
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License version 2 as
9  *  published by the Free Software Foundation.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  */
21
22 #ifndef __G_DHCP_H
23 #define __G_DHCP_H
24
25 #include <stdint.h>
26
27 #include <glib.h>
28
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32
33 /* DHCP Client part*/
34 struct _GDHCPClient;
35
36 typedef struct _GDHCPClient GDHCPClient;
37
38 typedef enum {
39         G_DHCP_CLIENT_ERROR_NONE,
40         G_DHCP_CLIENT_ERROR_INTERFACE_UNAVAILABLE,
41         G_DHCP_CLIENT_ERROR_INTERFACE_IN_USE,
42         G_DHCP_CLIENT_ERROR_INTERFACE_DOWN,
43         G_DHCP_CLIENT_ERROR_NOMEM,
44         G_DHCP_CLIENT_ERROR_INVALID_INDEX,
45         G_DHCP_CLIENT_ERROR_INVALID_OPTION
46 } GDHCPClientError;
47
48 typedef enum {
49         G_DHCP_CLIENT_EVENT_LEASE_AVAILABLE,
50         G_DHCP_CLIENT_EVENT_IPV4LL_AVAILABLE,
51         G_DHCP_CLIENT_EVENT_NO_LEASE,
52         G_DHCP_CLIENT_EVENT_LEASE_LOST,
53         G_DHCP_CLIENT_EVENT_IPV4LL_LOST,
54         G_DHCP_CLIENT_EVENT_ADDRESS_CONFLICT,
55         G_DHCP_CLIENT_EVENT_INFORMATION_REQ,
56         G_DHCP_CLIENT_EVENT_SOLICITATION,
57         G_DHCP_CLIENT_EVENT_ADVERTISE,
58         G_DHCP_CLIENT_EVENT_REQUEST,
59         G_DHCP_CLIENT_EVENT_RENEW,
60         G_DHCP_CLIENT_EVENT_REBIND,
61         G_DHCP_CLIENT_EVENT_RELEASE,
62         G_DHCP_CLIENT_EVENT_CONFIRM,
63 } GDHCPClientEvent;
64
65 typedef enum {
66         G_DHCP_IPV4,
67         G_DHCP_IPV6,
68         G_DHCP_IPV4LL,
69 } GDHCPType;
70
71 #define G_DHCP_SUBNET           0x01
72 #define G_DHCP_ROUTER           0x03
73 #define G_DHCP_TIME_SERVER      0x04
74 #define G_DHCP_DNS_SERVER       0x06
75 #define G_DHCP_DOMAIN_NAME      0x0f
76 #define G_DHCP_HOST_NAME        0x0c
77 #define G_DHCP_NTP_SERVER       0x2a
78 #define G_DHCP_CLIENT_ID        0x3d
79
80 #define G_DHCPV6_CLIENTID       1
81 #define G_DHCPV6_SERVERID       2
82 #define G_DHCPV6_IA_NA          3
83 #define G_DHCPV6_IA_TA          4
84 #define G_DHCPV6_IAADDR         5
85 #define G_DHCPV6_ORO            6
86 #define G_DHCPV6_ELAPSED_TIME   8
87 #define G_DHCPV6_STATUS_CODE    13
88 #define G_DHCPV6_RAPID_COMMIT   14
89 #define G_DHCPV6_DNS_SERVERS    23
90 #define G_DHCPV6_DOMAIN_LIST    24
91 #define G_DHCPV6_SNTP_SERVERS   31
92
93 #define G_DHCPV6_ERROR_SUCCESS  0
94 #define G_DHCPV6_ERROR_FAILURE  1
95 #define G_DHCPV6_ERROR_NO_ADDR  2
96 #define G_DHCPV6_ERROR_BINDING  3
97 #define G_DHCPV6_ERROR_LINK     4
98 #define G_DHCPV6_ERROR_MCAST    5
99
100 typedef enum {
101         G_DHCPV6_DUID_LLT = 1,
102         G_DHCPV6_DUID_EN  = 2,
103         G_DHCPV6_DUID_LL  = 3,
104 } GDHCPDuidType;
105
106 typedef void (*GDHCPClientEventFunc) (GDHCPClient *client, gpointer user_data);
107
108 typedef void (*GDHCPDebugFunc)(const char *str, gpointer user_data);
109
110 GDHCPClient *g_dhcp_client_new(GDHCPType type, int index,
111                                                 GDHCPClientError *error);
112
113 int g_dhcp_client_start(GDHCPClient *client, const char *last_address);
114 void g_dhcp_client_stop(GDHCPClient *client);
115
116 GDHCPClient *g_dhcp_client_ref(GDHCPClient *client);
117 void g_dhcp_client_unref(GDHCPClient *client);
118
119 void g_dhcp_client_register_event(GDHCPClient *client,
120                                         GDHCPClientEvent event,
121                                         GDHCPClientEventFunc func,
122                                         gpointer user_data);
123
124 GDHCPClientError g_dhcp_client_set_request(GDHCPClient *client,
125                                                 unsigned int option_code);
126 void g_dhcp_client_clear_requests(GDHCPClient *dhcp_client);
127 void g_dhcp_client_clear_values(GDHCPClient *dhcp_client);
128 GDHCPClientError g_dhcp_client_set_id(GDHCPClient *client);
129 GDHCPClientError g_dhcp_client_set_send(GDHCPClient *client,
130                                                 unsigned char option_code,
131                                                 const char *option_value);
132
133 char *g_dhcp_client_get_address(GDHCPClient *client);
134 char *g_dhcp_client_get_netmask(GDHCPClient *client);
135 GList *g_dhcp_client_get_option(GDHCPClient *client,
136                                                 unsigned char option_code);
137 int g_dhcp_client_get_index(GDHCPClient *client);
138
139 void g_dhcp_client_set_debug(GDHCPClient *client,
140                                 GDHCPDebugFunc func, gpointer user_data);
141 int g_dhcpv6_create_duid(GDHCPDuidType duid_type, int index, int type,
142                         unsigned char **duid, int *duid_len);
143 int g_dhcpv6_client_set_duid(GDHCPClient *dhcp_client, unsigned char *duid,
144                         int duid_len);
145 void g_dhcpv6_client_set_send(GDHCPClient *dhcp_client, uint16_t option_code,
146                         uint8_t *option_value, uint16_t option_len);
147 uint16_t g_dhcpv6_client_get_status(GDHCPClient *dhcp_client);
148 int g_dhcpv6_client_set_oro(GDHCPClient *dhcp_client, int args, ...);
149 void g_dhcpv6_client_create_iaid(GDHCPClient *dhcp_client, int index,
150                                 unsigned char *iaid);
151 int g_dhcpv6_client_get_timeouts(GDHCPClient *dhcp_client,
152                                 uint32_t *T1, uint32_t *T2,
153                                 time_t *last_renew, time_t *last_rebind,
154                                 time_t *expire);
155 uint32_t g_dhcpv6_client_get_iaid(GDHCPClient *dhcp_client);
156 int g_dhcpv6_client_set_ia(GDHCPClient *dhcp_client, int index,
157                         int code, uint32_t *T1, uint32_t *T2,
158                         gboolean add_addresses, const char *address);
159 void g_dhcpv6_client_reset_renew(GDHCPClient *dhcp_client);
160 void g_dhcpv6_client_reset_rebind(GDHCPClient *dhcp_client);
161 void g_dhcpv6_client_set_expire(GDHCPClient *dhcp_client, uint32_t timeout);
162 void g_dhcpv6_client_set_retransmit(GDHCPClient *dhcp_client);
163 void g_dhcpv6_client_clear_retransmit(GDHCPClient *dhcp_client);
164
165 /* DHCP Server */
166 typedef enum {
167         G_DHCP_SERVER_ERROR_NONE,
168         G_DHCP_SERVER_ERROR_INTERFACE_UNAVAILABLE,
169         G_DHCP_SERVER_ERROR_INTERFACE_IN_USE,
170         G_DHCP_SERVER_ERROR_INTERFACE_DOWN,
171         G_DHCP_SERVER_ERROR_NOMEM,
172         G_DHCP_SERVER_ERROR_INVALID_INDEX,
173         G_DHCP_SERVER_ERROR_INVALID_OPTION,
174         G_DHCP_SERVER_ERROR_IP_ADDRESS_INVALID
175 } GDHCPServerError;
176
177 typedef void (*GDHCPSaveLeaseFunc) (unsigned char *mac,
178                         unsigned int nip, unsigned int expire);
179 struct _GDHCPServer;
180
181 typedef struct _GDHCPServer GDHCPServer;
182
183 GDHCPServer *g_dhcp_server_new(GDHCPType type,
184                 int ifindex, GDHCPServerError *error);
185 int g_dhcp_server_start(GDHCPServer *server);
186 void g_dhcp_server_stop(GDHCPServer *server);
187
188 GDHCPServer *g_dhcp_server_ref(GDHCPServer *server);
189 void g_dhcp_server_unref(GDHCPServer *server);
190
191 int g_dhcp_server_set_option(GDHCPServer *server,
192                 unsigned char option_code, const char *option_value);
193 int g_dhcp_server_set_ip_range(GDHCPServer *server,
194                 const char *start_ip, const char *end_ip);
195 void g_dhcp_server_set_debug(GDHCPServer *server,
196                                 GDHCPDebugFunc func, gpointer user_data);
197 void g_dhcp_server_set_lease_time(GDHCPServer *dhcp_server,
198                                                 unsigned int lease_time);
199 void g_dhcp_server_set_save_lease(GDHCPServer *dhcp_server,
200                                 GDHCPSaveLeaseFunc func, gpointer user_data);
201 #ifdef __cplusplus
202 }
203 #endif
204
205 #endif /* __G_DHCP_H */