diff options
Diffstat (limited to 'src/core/dhcp/nm-dhcp-client.h')
-rw-r--r-- | src/core/dhcp/nm-dhcp-client.h | 259 |
1 files changed, 162 insertions, 97 deletions
diff --git a/src/core/dhcp/nm-dhcp-client.h b/src/core/dhcp/nm-dhcp-client.h index 2e7e021650..372acc752c 100644 --- a/src/core/dhcp/nm-dhcp-client.h +++ b/src/core/dhcp/nm-dhcp-client.h @@ -8,8 +8,6 @@ #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 */ @@ -24,25 +22,7 @@ #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_ANYCAST_ADDRESS "anycast-address" -#define NM_DHCP_CLIENT_FLAGS "flags" -#define NM_DHCP_CLIENT_HWADDR "hwaddr" -#define NM_DHCP_CLIENT_BROADCAST_HWADDR "broadcast-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_HOSTNAME "hostname" -#define NM_DHCP_CLIENT_MUD_URL "mud-url" -#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_IAID "iaid" -#define NM_DHCP_CLIENT_IAID_EXPLICIT "iaid-explicit" -#define NM_DHCP_CLIENT_HOSTNAME_FLAGS "hostname-flags" -#define NM_DHCP_CLIENT_VENDOR_CLASS_IDENTIFIER "vendor-class-identifier" -#define NM_DHCP_CLIENT_REJECT_SERVERS "reject-servers" +#define NM_DHCP_CLIENT_CONFIG "config" #define NM_DHCP_CLIENT_NOTIFY "dhcp-notify" @@ -59,7 +39,27 @@ typedef enum { } NMDhcpState; typedef enum _nm_packed { - NM_DHCP_CLIENT_NOTIFY_TYPE_STATE_CHANGED, + NM_DHCP_CLIENT_NOTIFY_TYPE_LEASE_UPDATE, + + /* When NM_DHCP_CLIENT_NO_LEASE_TIMEOUT expired and the state + * switched from NM_DHCP_CLIENT_STATE_NO_LEASE to + * NM_DHCP_CLIENT_STATE_NO_LEASE_WITH_TIMEOUT. */ + NM_DHCP_CLIENT_NOTIFY_TYPE_NO_LEASE_TIMEOUT, + + /* NMDhcpClient will indefinitely try to get/renew the lease. + * As such, it's never officially in a non-recoverable state. + * However, there are cases when it really looks like we won't + * be able to get a lease. For example, if the underlying interface + * is layer 3 only, if we have no IPv6 link local address for a prolonged + * time, or if dhclient is not installed. + * But even these cases are potentially recoverable. This is only + * a hint to the user (which they might ignore). + * + * In particular, NM_DHCP_CLIENT_NOTIFY_TYPE_NO_LEASE_TIMEOUT might mean + * that the DHCP is currently not running, but that could change + * at any moment and from client's side, it does not look bad. */ + NM_DHCP_CLIENT_NOTIFY_TYPE_IT_LOOKS_BAD, + NM_DHCP_CLIENT_NOTIFY_TYPE_PREFIX_DELEGATED, } NMDhcpClientNotifyType; @@ -67,18 +67,126 @@ typedef struct { NMDhcpClientNotifyType notify_type; union { struct { - NMIPConfig *ip_config; - GHashTable *options; - NMDhcpState dhcp_state; - } state_changed; + /* This is either the new lease information we just received, + * or NULL (if a previous lease timed out). It can also be the + * previous lease, that was injected. */ + const NML3ConfigData *l3cd; + } lease_update; struct { const NMPlatformIP6Address *prefix; } prefix_delegated; + struct { + const char *reason; + } it_looks_bad; }; } NMDhcpClientNotifyData; const char *nm_dhcp_state_to_string(NMDhcpState state); +/* FIXME(l3cfg:dhcp:config): nm_dhcp_manager_start_ip[46]() has a gazillion of parameters, + * those get passed on as CONSTRUCT_ONLY properties to the NMDhcpClient. Drop + * all these parameters, and let the caller provide one NMDhcpClientConfig + * instance. There will be only one GObject property (NM_DHCP_CLIENT_CONFIG), + * which is CONSTRUCT_ONLY and takes a (mandatory) G_TYPE_POINTER for the + * configuration. + * + * Since NMDhcpClientConfig has an addr_family, we also don't need separate + * nm_dhcp_manager_start_ip[46]() methods. */ +typedef struct { + int addr_family; + + /* The NML3Cfg instance is the manager object for the ifindex on which + * NMDhcpClient is supposed to run. */ + NML3Cfg *l3cfg; + + /* FIXME(l3cfg:dhcp:previous-lease): most parameters of NMDhcpClient are immutable, + * so to change them (during reapply), we need to create and start + * a new NMDhcpClient instance. + * + * However, while the restart happens, we want to stick to the previous + * lease (if any). Allow the caller to provide such a previous lease, + * and if present, the instance starts by pretending that it just received + * this lease, before really starting. */ + const NML3ConfigData *previous_lease; + + const char *iface; + + /* The hardware address */ + GBytes *hwaddr; + + /* The broadcast hardware address */ + GBytes *bcast_hwaddr; + + /* Timeout in seconds before reporting failure */ + guint32 timeout; + + /* Flags for the hostname and FQDN DHCP options */ + NMDhcpHostnameFlags hostname_flags; + + /* The UUID of the connection. Used mainly to build + * lease file names. */ + const char *uuid; + + /* Set to reduce the number of broadcast packets when the + * anycast hardware address of the DHCP service is known. */ + const char *anycast_address; + + /* The hostname or FQDN to send. */ + const char *hostname; + + /* The Manufacturer Usage Description (RFC 8520) URL to send */ + const char *mud_url; + + /* The value for the Vendor Class Identifier option */ + GBytes *vendor_class_identifier; + + /* A list of servers from which offers should be rejected */ + const char *const *reject_servers; + + /* The client identifier (DHCPv4) or DUID (DHCPv6) to send */ + GBytes *client_id; + + /* Whether to send the hostname or FQDN option */ + bool send_hostname : 1; + + /* Whether to send the hostname as HOSTNAME option or FQDN. + * For DHCPv6 this is always TRUE. */ + bool use_fqdn : 1; + + union { + struct { + /* Set BOOTP broadcast flag in request packets, so that servers + * will always broadcast replies. */ + bool request_broadcast : 1; + + /* The address from the previous lease */ + const char *last_address; + } v4; + struct { + /* The link-local IPv6 address for UDP socket bind() */ + const struct in6_addr *ll_addr; + + /* If set, the DUID from the connection is used; otherwise + * the one from an existing lease is used. */ + gboolean enforce_duid; + + /* The IAID to use */ + guint32 iaid; + + /* Whether the IAID was explicitly set in the connection or + * as global default */ + gboolean iaid_explicit; + + /* Number to prefixes (IA_PD) to request */ + guint needed_prefixes; + + /* Use Information-request to get stateless configuration + * parameters (don't request a IA_NA) */ + bool info_only : 1; + } v6; + }; +} NMDhcpClientConfig; + struct _NMDhcpClientPrivate; typedef struct { @@ -100,17 +208,13 @@ typedef enum _nm_packed { typedef struct { GObjectClass parent; - gboolean (*ip4_start)(NMDhcpClient *self, const char *last_ip4_address, GError **error); + gboolean (*ip4_start)(NMDhcpClient *self, GError **error); gboolean (*accept)(NMDhcpClient *self, GError **error); gboolean (*decline)(NMDhcpClient *self, const char *error_message, GError **error); - gboolean (*ip6_start)(NMDhcpClient * self, - const struct in6_addr * ll_addr, - NMSettingIP6ConfigPrivacy privacy, - guint needed_prefixes, - GError ** error); + gboolean (*ip6_start)(NMDhcpClient *self, GError **error); void (*stop)(NMDhcpClient *self, gboolean release); @@ -128,64 +232,25 @@ typedef struct { 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); - -GBytes *nm_dhcp_client_get_broadcast_hw_addr(NMDhcpClient *self); - -const char *nm_dhcp_client_get_anycast_address(NMDhcpClient *self); - -guint32 nm_dhcp_client_get_route_table(NMDhcpClient *self); - -void nm_dhcp_client_set_route_table(NMDhcpClient *self, guint32 route_table); +gboolean nm_dhcp_client_start_ip4(NMDhcpClient *self, GError **error); +gboolean nm_dhcp_client_start_ip6(NMDhcpClient *self, GError **error); -guint32 nm_dhcp_client_get_route_metric(NMDhcpClient *self); +const NMDhcpClientConfig *nm_dhcp_client_get_config(NMDhcpClient *self); -void nm_dhcp_client_set_route_metric(NMDhcpClient *self, guint32 route_metric); - -guint32 nm_dhcp_client_get_timeout(NMDhcpClient *self); - -guint32 nm_dhcp_client_get_iaid(NMDhcpClient *self); - -gboolean nm_dhcp_client_get_iaid_explicit(NMDhcpClient *self); - -GBytes *nm_dhcp_client_get_client_id(NMDhcpClient *self); - -const char * nm_dhcp_client_get_hostname(NMDhcpClient *self); -const char * nm_dhcp_client_get_mud_url(NMDhcpClient *self); -const char *const *nm_dhcp_client_get_reject_servers(NMDhcpClient *self); - -NMDhcpHostnameFlags nm_dhcp_client_get_hostname_flags(NMDhcpClient *self); - -NMDhcpClientFlags nm_dhcp_client_get_client_flags(NMDhcpClient *self); - -GBytes *nm_dhcp_client_get_vendor_class_identifier(NMDhcpClient *self); - -gboolean nm_dhcp_client_start_ip4(NMDhcpClient *self, - GBytes * client_id, - const char * last_ip4_address, - GError ** error); +pid_t nm_dhcp_client_get_pid(NMDhcpClient *self); -gboolean nm_dhcp_client_start_ip6(NMDhcpClient * self, - GBytes * client_id, - gboolean enforce_duid, - const struct in6_addr * ll_addr, - NMSettingIP6ConfigPrivacy privacy, - guint needed_prefixes, - GError ** error); +static inline const NML3ConfigData * +nm_dhcp_client_get_lease(NMDhcpClient *self) +{ + /* FIXME(l3cfg:dhcp:previous-lease): this function returns the currently + * valid, exposed lease. + * + * Note that NMDhcpClient should accept as construct argument a *previous* lease, + * and (if that lease is still valid), pretend that it's good to use. The point is + * so that during reapply we keep using the current address, until a new lease + * was received. */ + return NULL; +} gboolean nm_dhcp_client_accept(NMDhcpClient *self, GError **error); gboolean nm_dhcp_client_can_accept(NMDhcpClient *self); @@ -205,10 +270,8 @@ void nm_dhcp_client_watch_child(NMDhcpClient *self, pid_t pid); void nm_dhcp_client_stop_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 */ +void +nm_dhcp_client_set_state(NMDhcpClient *self, NMDhcpState new_state, const NML3ConfigData *l3cd); gboolean nm_dhcp_client_handle_event(gpointer unused, const char * iface, @@ -217,17 +280,19 @@ gboolean nm_dhcp_client_handle_event(gpointer unused, 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); - void nm_dhcp_client_emit_ipv6_prefix_delegated(NMDhcpClient * self, const NMPlatformIP6Address *prefix); gboolean nm_dhcp_client_server_id_is_rejected(NMDhcpClient *self, gconstpointer addr); +int nm_dhcp_client_get_addr_family(NMDhcpClient *self); +const char * nm_dhcp_client_get_iface(NMDhcpClient *self); +NMDedupMultiIndex *nm_dhcp_client_get_multi_idx(NMDhcpClient *self); +int nm_dhcp_client_get_ifindex(NMDhcpClient *self); + +void nm_dhcp_client_set_effective_client_id(NMDhcpClient *self, GBytes *client_id); +GBytes *nm_dhcp_client_get_effective_client_id(NMDhcpClient *self); + /***************************************************************************** * Client data *****************************************************************************/ |