summaryrefslogtreecommitdiff
path: root/src/dhcp-manager/nm-dhcp-client.h
blob: a36ba67b693f51f1e722879cce0bdad21f6cadd0 (plain)
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
/* -*- 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 NM_DHCP_CLIENT_H
#define NM_DHCP_CLIENT_H

#include <glib.h>
#include <glib-object.h>

#include <nm-setting-ip4-config.h>
#include <nm-setting-ip6-config.h>
#include <nm-ip4-config.h>
#include <nm-ip6-config.h>

#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_INTERFACE "iface"
#define NM_DHCP_CLIENT_IFINDEX   "ifindex"
#define NM_DHCP_CLIENT_HWADDR    "hwaddr"
#define NM_DHCP_CLIENT_IPV6      "ipv6"
#define NM_DHCP_CLIENT_UUID      "uuid"
#define NM_DHCP_CLIENT_PRIORITY  "priority"
#define NM_DHCP_CLIENT_TIMEOUT   "timeout"

#define NM_DHCP_CLIENT_SIGNAL_STATE_CHANGED "state-changed"

typedef enum {
	NM_DHCP_STATE_UNKNOWN = 0,
	NM_DHCP_STATE_BOUND,        /* lease changed (state_is_bound) */
	NM_DHCP_STATE_TIMEOUT,      /* TIMEOUT */
	NM_DHCP_STATE_DONE,         /* END */
	NM_DHCP_STATE_FAIL,          /* failed or quit unexpectedly */
	__NM_DHCP_STATE_MAX,
	NM_DHCP_STATE_MAX = __NM_DHCP_STATE_MAX - 1,
} NMDhcpState;

typedef struct {
	GObject parent;
} NMDhcpClient;

typedef struct {
	GObjectClass parent;

	/* Methods */

	gboolean (*ip4_start)     (NMDhcpClient *self,
	                           const char *dhcp_client_id,
	                           GByteArray *anycast_addr,
	                           const char *hostname);

	gboolean (*ip6_start)     (NMDhcpClient *self,
	                           GByteArray *anycast_addr,
	                           const char *hostname,
	                           gboolean info_only,
	                           NMSettingIP6ConfigPrivacy privacy,
	                           const GByteArray *duid);

	void (*stop)              (NMDhcpClient *self,
	                           gboolean release,
	                           const GByteArray *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.
	 */
	GByteArray * (*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);

pid_t nm_dhcp_client_get_pid (NMDhcpClient *self);

const char *nm_dhcp_client_get_iface (NMDhcpClient *self);

int         nm_dhcp_client_get_ifindex (NMDhcpClient *self);

gboolean nm_dhcp_client_get_ipv6 (NMDhcpClient *self);

const char *nm_dhcp_client_get_uuid (NMDhcpClient *self);

const GByteArray *nm_dhcp_client_get_duid (NMDhcpClient *self);

const GByteArray *nm_dhcp_client_get_hw_addr (NMDhcpClient *self);

guint32 nm_dhcp_client_get_priority (NMDhcpClient *self);

gboolean nm_dhcp_client_start_ip4 (NMDhcpClient *self,
                                   const char *dhcp_client_id,
                                   GByteArray *dhcp_anycast_addr,
                                   const char *hostname);

gboolean nm_dhcp_client_start_ip6 (NMDhcpClient *self,
                                   GByteArray *dhcp_anycast_addr,
                                   const char *hostname,
                                   gboolean info_only,
                                   NMSettingIP6ConfigPrivacy privacy);

void nm_dhcp_client_stop (NMDhcpClient *self, gboolean release);

void nm_dhcp_client_new_options (NMDhcpClient *self,
                                 GHashTable *options,
                                 const char *reason);

/* 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_watch_child (NMDhcpClient *self, pid_t pid);

void nm_dhcp_client_set_state (NMDhcpClient *self,
                               NMDhcpState new_state,
                               GObject *ip_config,   /* NMIP4Config or NMIP6Config */
                               GHashTable *options); /* str:str hash */

#endif /* NM_DHCP_CLIENT_H */