1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
|
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Copyright (C) 2005 - 2010 Red Hat, Inc.
*/
#ifndef __NETWORKMANAGER_DHCP_CLIENT_H__
#define __NETWORKMANAGER_DHCP_CLIENT_H__
#include "nm-setting-ip4-config.h"
#include "nm-setting-ip6-config.h"
#include "nm-ip4-config.h"
#include "nm-ip6-config.h"
#include "nm-dhcp-utils.h"
#define NM_DHCP_TIMEOUT_DEFAULT ((guint32) 45) /* default DHCP timeout, in seconds */
#define NM_DHCP_TIMEOUT_INFINITY G_MAXINT32
#define NM_TYPE_DHCP_CLIENT (nm_dhcp_client_get_type ())
#define NM_DHCP_CLIENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_DHCP_CLIENT, NMDhcpClient))
#define NM_DHCP_CLIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_DHCP_CLIENT, NMDhcpClientClass))
#define NM_IS_DHCP_CLIENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_DHCP_CLIENT))
#define NM_IS_DHCP_CLIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_DHCP_CLIENT))
#define NM_DHCP_CLIENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DHCP_CLIENT, NMDhcpClientClass))
#define NM_DHCP_CLIENT_ADDR_FAMILY "addr-family"
#define NM_DHCP_CLIENT_FLAGS "flags"
#define NM_DHCP_CLIENT_HWADDR "hwaddr"
#define NM_DHCP_CLIENT_IFINDEX "ifindex"
#define NM_DHCP_CLIENT_INTERFACE "iface"
#define NM_DHCP_CLIENT_MULTI_IDX "multi-idx"
#define NM_DHCP_CLIENT_ROUTE_METRIC "route-metric"
#define NM_DHCP_CLIENT_ROUTE_TABLE "route-table"
#define NM_DHCP_CLIENT_TIMEOUT "timeout"
#define NM_DHCP_CLIENT_UUID "uuid"
#define NM_DHCP_CLIENT_SIGNAL_STATE_CHANGED "state-changed"
#define NM_DHCP_CLIENT_SIGNAL_PREFIX_DELEGATED "prefix-delegated"
typedef enum {
NM_DHCP_STATE_UNKNOWN = 0,
NM_DHCP_STATE_BOUND, /* new lease or lease changed */
NM_DHCP_STATE_TIMEOUT, /* timed out contacting server */
NM_DHCP_STATE_DONE, /* client quit or stopped */
NM_DHCP_STATE_EXPIRE, /* lease expired or NAKed */
NM_DHCP_STATE_FAIL, /* failed for some reason */
__NM_DHCP_STATE_MAX,
NM_DHCP_STATE_MAX = __NM_DHCP_STATE_MAX - 1,
} NMDhcpState;
struct _NMDhcpClientPrivate;
typedef struct {
GObject parent;
struct _NMDhcpClientPrivate *_priv;
CList dhcp_client_lst;
} NMDhcpClient;
typedef enum {
NM_DHCP_CLIENT_FLAGS_INFO_ONLY = (1LL << 0),
NM_DHCP_CLIENT_FLAGS_USE_FQDN = (1LL << 1),
} NMDhcpClientFlags;
typedef struct {
GObjectClass parent;
/* Methods */
gboolean (*ip4_start) (NMDhcpClient *self,
const char *anycast_addr,
const char *last_ip4_address);
gboolean (*ip6_start) (NMDhcpClient *self,
const char *anycast_addr,
const struct in6_addr *ll_addr,
NMSettingIP6ConfigPrivacy privacy,
GBytes *duid,
guint needed_prefixes);
void (*stop) (NMDhcpClient *self,
gboolean release,
GBytes *duid);
/**
* get_duid:
* @self: the #NMDhcpClient
*
* Attempts to find an existing DHCPv6 DUID for this client in the DHCP
* client's persistent configuration. Returned DUID should be the binary
* representation of the DUID. If no DUID is found, %NULL should be
* returned.
*/
GBytes *(*get_duid) (NMDhcpClient *self);
/* Signals */
void (*state_changed) (NMDhcpClient *self,
NMDhcpState state,
GObject *ip_config,
GHashTable *options);
} NMDhcpClientClass;
GType nm_dhcp_client_get_type (void);
struct _NMDedupMultiIndex *nm_dhcp_client_get_multi_idx (NMDhcpClient *self);
pid_t nm_dhcp_client_get_pid (NMDhcpClient *self);
int nm_dhcp_client_get_addr_family (NMDhcpClient *self);
const char *nm_dhcp_client_get_iface (NMDhcpClient *self);
int nm_dhcp_client_get_ifindex (NMDhcpClient *self);
const char *nm_dhcp_client_get_uuid (NMDhcpClient *self);
GBytes *nm_dhcp_client_get_duid (NMDhcpClient *self);
GBytes *nm_dhcp_client_get_hw_addr (NMDhcpClient *self);
guint32 nm_dhcp_client_get_route_table (NMDhcpClient *self);
guint32 nm_dhcp_client_get_route_metric (NMDhcpClient *self);
guint32 nm_dhcp_client_get_timeout (NMDhcpClient *self);
GBytes *nm_dhcp_client_get_client_id (NMDhcpClient *self);
const char *nm_dhcp_client_get_hostname (NMDhcpClient *self);
gboolean nm_dhcp_client_get_info_only (NMDhcpClient *self);
gboolean nm_dhcp_client_get_use_fqdn (NMDhcpClient *self);
gboolean nm_dhcp_client_start_ip4 (NMDhcpClient *self,
GBytes *client_id,
const char *dhcp_anycast_addr,
const char *hostname,
const char *last_ip4_address);
gboolean nm_dhcp_client_start_ip6 (NMDhcpClient *self,
GBytes *client_id,
gboolean enforce_duid,
const char *dhcp_anycast_addr,
const struct in6_addr *ll_addr,
const char *hostname,
NMSettingIP6ConfigPrivacy privacy,
guint needed_prefixes);
void nm_dhcp_client_stop (NMDhcpClient *self, gboolean release);
/* Backend helpers for subclasses */
void nm_dhcp_client_stop_existing (const char *pid_file, const char *binary_name);
void nm_dhcp_client_stop_pid (pid_t pid, const char *iface);
void nm_dhcp_client_start_timeout (NMDhcpClient *self);
void nm_dhcp_client_watch_child (NMDhcpClient *self, pid_t pid);
void nm_dhcp_client_set_state (NMDhcpClient *self,
NMDhcpState new_state,
NMIPConfig *ip_config,
GHashTable *options); /* str:str hash */
gboolean nm_dhcp_client_handle_event (gpointer unused,
const char *iface,
gint pid,
GVariant *options,
const char *reason,
NMDhcpClient *self);
void nm_dhcp_client_set_client_id (NMDhcpClient *self,
GBytes *client_id);
void nm_dhcp_client_set_client_id_bin (NMDhcpClient *self,
guint8 type,
const guint8 *client_id,
gsize len);
/*****************************************************************************
* Client data
*****************************************************************************/
typedef struct {
GType (*get_type)(void);
const char *name;
const char *(*get_path) (void);
} NMDhcpClientFactory;
extern const NMDhcpClientFactory _nm_dhcp_client_factory_dhcpcanon;
extern const NMDhcpClientFactory _nm_dhcp_client_factory_dhclient;
extern const NMDhcpClientFactory _nm_dhcp_client_factory_dhcpcd;
extern const NMDhcpClientFactory _nm_dhcp_client_factory_internal;
#endif /* __NETWORKMANAGER_DHCP_CLIENT_H__ */
|