Copyright © 2014 Intel Corporation. All rights reserved.
***/
+#include <errno.h>
#include <netinet/ip6.h>
#include <netinet/udp.h>
#define DHCP6_REB_TIMEOUT 10 * USEC_PER_SEC
#define DHCP6_REB_MAX_RT 600 * USEC_PER_SEC
-enum DHCP6State {
- DHCP6_STATE_STOPPED = 0,
- DHCP6_STATE_INFORMATION_REQUEST = 1,
- DHCP6_STATE_SOLICITATION = 2,
- DHCP6_STATE_REQUEST = 3,
- DHCP6_STATE_BOUND = 4,
- DHCP6_STATE_RENEW = 5,
- DHCP6_STATE_REBIND = 6,
-};
+typedef enum DHCP6State {
+ DHCP6_STATE_STOPPED,
+ DHCP6_STATE_INFORMATION_REQUEST,
+ DHCP6_STATE_SOLICITATION,
+ DHCP6_STATE_REQUEST,
+ DHCP6_STATE_BOUND,
+ DHCP6_STATE_RENEW,
+ DHCP6_STATE_REBIND,
+ _DHCP6_STATE_MAX,
+ _DHCP6_STATE_INVALID = -EINVAL,
+} DHCP6State;
enum {
DHCP6_SOLICIT = 1,
_DHCP6_MESSAGE_MAX = 14,
};
-enum {
+typedef enum DHCP6NTPSubOption {
DHCP6_NTP_SUBOPTION_SRV_ADDR = 1,
DHCP6_NTP_SUBOPTION_MC_ADDR = 2,
DHCP6_NTP_SUBOPTION_SRV_FQDN = 3,
-};
+} DHCP6NTPSubOption;
/*
* RFC 8415, RFC 5007 and RFC 7653 status codes:
* https://www.iana.org/assignments/dhcpv6-parameters/dhcpv6-parameters.xhtml#dhcpv6-parameters-5
*/
-enum {
+typedef enum DHCP6Status {
DHCP6_STATUS_SUCCESS = 0,
DHCP6_STATUS_UNSPEC_FAIL = 1,
DHCP6_STATUS_NO_ADDRS_AVAIL = 2,
DHCP6_STATUS_SERVER_SHUTTING_DOWN = 20,
DHCP6_STATUS_DNS_UPDATE_NOT_SUPPORTED = 21,
DHCP6_STATUS_EXCESSIVE_TIME_SKEW = 22,
- _DHCP6_STATUS_MAX = 23,
-};
+ _DHCP6_STATUS_MAX,
+ _DHCP6_STATUS_INVALID = -EINVAL,
+} DHCP6Status;
-enum {
- DHCP6_FQDN_FLAG_S = (1 << 0),
- DHCP6_FQDN_FLAG_O = (1 << 1),
- DHCP6_FQDN_FLAG_N = (1 << 2),
-};
+typedef enum DHCP6FQDNFlag {
+ DHCP6_FQDN_FLAG_S = 1 << 0,
+ DHCP6_FQDN_FLAG_O = 1 << 1,
+ DHCP6_FQDN_FLAG_N = 1 << 2,
+} DHCP6FQDNFlag;
struct sd_dhcp6_client {
unsigned n_ref;
- enum DHCP6State state;
+ DHCP6State state;
sd_event *event;
int event_priority;
int ifindex;
#define DHCP6_CLIENT_DONT_DESTROY(client) \
_cleanup_(sd_dhcp6_client_unrefp) _unused_ sd_dhcp6_client *_dont_destroy_##client = sd_dhcp6_client_ref(client)
-static int client_start(sd_dhcp6_client *client, enum DHCP6State state);
+static int client_start(sd_dhcp6_client *client, DHCP6State state);
int sd_dhcp6_client_set_callback(
sd_dhcp6_client *client,
case DHCP6_STATE_STOPPED:
case DHCP6_STATE_BOUND:
return -EINVAL;
+ default:
+ assert_not_reached();
}
r = dhcp6_option_append(&opt, &optlen, SD_DHCP6_OPTION_ORO,
static int client_timeout_resend_expire(sd_event_source *s, uint64_t usec, void *userdata) {
sd_dhcp6_client *client = userdata;
DHCP6_CLIENT_DONT_DESTROY(client);
- enum DHCP6State state;
+ DHCP6State state;
assert(s);
assert(client);
case DHCP6_STATE_STOPPED:
case DHCP6_STATE_BOUND:
return 0;
+ default:
+ assert_not_reached();
}
if (max_retransmit_count > 0 &&
case DHCP6_STATE_STOPPED:
return 0;
+ default:
+ assert_not_reached();
}
log_dhcp6_client(client, "Recv %s",
return -ENOMSG;
}
-static int client_start(sd_dhcp6_client *client, enum DHCP6State state) {
+static int client_start(sd_dhcp6_client *client, DHCP6State state) {
int r;
usec_t timeout, time_now;
uint32_t lifetime_t1, lifetime_t2;
client->state = state;
return 0;
+ default:
+ assert_not_reached();
}
client->transaction_id = random_u32() & htobe32(0x00ffffff);
}
int sd_dhcp6_client_start(sd_dhcp6_client *client) {
- enum DHCP6State state = DHCP6_STATE_SOLICITATION;
+ DHCP6State state = DHCP6_STATE_SOLICITATION;
int r;
assert_return(client, -EINVAL);