#define DHCPV6_INF_MAX_RT_MAX 86400
static bool dhcpv6_response_is_valid(const void *buf, ssize_t len,
- const uint8_t transaction[3], enum dhcpv6_msg type,
+ const uint8_t transaction[3], enum dhcpv6_msg req_msg_type,
const struct in6_addr *daddr);
static unsigned int dhcpv6_parse_ia(void *opt, void *end, int *ret);
return mode;
}
-static void dhcpv6_send(enum dhcpv6_msg type, uint8_t trid[3], uint32_t ecs)
+static void dhcpv6_send(enum dhcpv6_msg req_msg_type, uint8_t trid[3], uint32_t ecs)
{
// Build FQDN
char fqdn_buf[256];
struct odhcp6c_entry *pd_entries = odhcp6c_get_state(STATE_IA_PD, &ia_pd_entry_cnt);
ia_pd_entry_cnt /= sizeof(*pd_entries);
- if (type == DHCPV6_MSG_SOLICIT || (type == DHCPV6_MSG_REQUEST && ia_pd_entry_cnt == 0 && pd_mode != IA_MODE_NONE)) {
+ if (req_msg_type == DHCPV6_MSG_SOLICIT || (req_msg_type == DHCPV6_MSG_REQUEST && ia_pd_entry_cnt == 0 && pd_mode != IA_MODE_NONE)) {
odhcp6c_clear_state(STATE_IA_PD);
size_t n_prefixes;
struct odhcp6c_request_prefix *request_prefixes = odhcp6c_get_state(STATE_IA_PD_INIT, &n_prefixes);
.addr = pd_entries[j].target
};
- if (type == DHCPV6_MSG_REQUEST) {
+ if (req_msg_type == DHCPV6_MSG_REQUEST) {
p.preferred = htonl(pd_entries[j].preferred);
p.valid = htonl(pd_entries[j].valid);
}
ia_na_array[i].len = htons(sizeof(ia_na_array[i]) - DHCPV6_OPT_HDR_SIZE_U);
ia_na_array[i].addr = ia_entries[i].target;
- if (type == DHCPV6_MSG_REQUEST) {
+ if (req_msg_type == DHCPV6_MSG_REQUEST) {
ia_na_array[i].preferred = htonl(ia_entries[i].preferred);
ia_na_array[i].valid = htonl(ia_entries[i].valid);
} else {
if (!(opt->flags & OPT_ORO))
continue;
- if ((opt->flags & OPT_ORO_SOLICIT) && type != DHCPV6_MSG_SOLICIT)
+ if ((opt->flags & OPT_ORO_SOLICIT) && req_msg_type != DHCPV6_MSG_SOLICIT)
continue;
- if ((opt->flags & OPT_ORO_STATELESS) && type != DHCPV6_MSG_INFO_REQ)
+ if ((opt->flags & OPT_ORO_STATELESS) && req_msg_type != DHCPV6_MSG_INFO_REQ)
continue;
- if ((opt->flags & OPT_ORO_STATEFUL) && type == DHCPV6_MSG_INFO_REQ)
+ if ((opt->flags & OPT_ORO_STATEFUL) && req_msg_type == DHCPV6_MSG_INFO_REQ)
continue;
}
uint16_t oro_type;
uint16_t oro_len;
} hdr = {
- type, {trid[0], trid[1], trid[2]},
+ req_msg_type, {trid[0], trid[1], trid[2]},
htons(DHCPV6_OPT_ELAPSED), htons(2),
htons((ecs > 0xffff) ? 0xffff : ecs),
htons(DHCPV6_OPT_ORO), htons(oro_len),
};
size_t cnt = IOV_TOTAL;
- if (type == DHCPV6_MSG_INFO_REQ)
+ if (req_msg_type == DHCPV6_MSG_INFO_REQ)
cnt = IOV_HDR_IA_NA;
// Disable IAs if not used
- if (type != DHCPV6_MSG_SOLICIT && type != DHCPV6_MSG_REQUEST && ia_na_len == 0)
+ if (req_msg_type != DHCPV6_MSG_SOLICIT && req_msg_type != DHCPV6_MSG_REQUEST && ia_na_len == 0)
iov[IOV_HDR_IA_NA].iov_len = 0;
if (na_mode == IA_MODE_NONE)
iov[IOV_HDR_IA_NA].iov_len = 0;
- if ((type != DHCPV6_MSG_SOLICIT && type != DHCPV6_MSG_REQUEST) ||
+ if ((req_msg_type != DHCPV6_MSG_SOLICIT && req_msg_type != DHCPV6_MSG_REQUEST) ||
!(client_options & DHCPV6_ACCEPT_RECONFIGURE))
iov[IOV_RECONF_ACCEPT].iov_len = 0;
if (!(client_options & DHCPV6_CLIENT_FQDN)) {
iov[IOV_FQDN].iov_len = 0;
} else {
- switch (type) {
+ switch (req_msg_type) {
/* RFC4704 §5
A client MUST only include the Client FQDN option in SOLICIT,
REQUEST, RENEW, or REBIND messages.
struct msghdr msg = {.msg_name = &srv, .msg_namelen = sizeof(srv),
.msg_iov = iov, .msg_iovlen = cnt};
- switch (type) {
+ switch (req_msg_type) {
case DHCPV6_MSG_REQUEST:
case DHCPV6_MSG_RENEW:
case DHCPV6_MSG_RELEASE:
char in6_str[INET6_ADDRSTRLEN];
syslog(LOG_ERR, "Failed to send %s message to %s (%s)",
- dhcpv6_msg_to_str(type),
+ dhcpv6_msg_to_str(req_msg_type),
inet_ntop(AF_INET6, (const void *)&srv.sin6_addr,
in6_str, sizeof(in6_str)), strerror(errno));
dhcpv6_stats.transmit_failures++;
} else {
- dhcpv6_inc_counter(type);
+ dhcpv6_inc_counter(req_msg_type);
}
}
// Message validation checks according to RFC3315 chapter 15
static bool dhcpv6_response_is_valid(const void *buf, ssize_t len,
- const uint8_t transaction[3], enum dhcpv6_msg type,
+ const uint8_t transaction[3], enum dhcpv6_msg req_msg_type,
const struct in6_addr *daddr)
{
const struct dhcpv6_header *response_buf = buf;
transaction, sizeof(response_buf->tr_id)))
return false; // Invalid reply
- if (type == DHCPV6_MSG_SOLICIT) {
+ if (req_msg_type == DHCPV6_MSG_SOLICIT) {
if (response_buf->msg_type != DHCPV6_MSG_ADVERT &&
response_buf->msg_type != DHCPV6_MSG_REPLY)
return false;
- } else if (type == DHCPV6_MSG_UNKNOWN) {
+ } else if (req_msg_type == DHCPV6_MSG_UNKNOWN) {
if (!accept_reconfig || response_buf->msg_type != DHCPV6_MSG_RECONF)
return false;
} else if (response_buf->msg_type != DHCPV6_MSG_REPLY) {
if (!options_valid || ((odata + olen) > end))
return false;
- if (type == DHCPV6_MSG_INFO_REQ && ia_present)
+ if (req_msg_type == DHCPV6_MSG_INFO_REQ && ia_present)
return false;
if (response_buf->msg_type == DHCPV6_MSG_RECONF) {
return ret;
}
-int dhcpv6_send_request(enum dhcpv6_msg type)
+int dhcpv6_send_request(enum dhcpv6_msg req_msg_type)
{
- struct dhcpv6_retx *retx = &dhcpv6_retx[type];
+ struct dhcpv6_retx *retx = &dhcpv6_retx[req_msg_type];
uint64_t current_milli_time = 0;
if (!retx->is_retransmit) {
retx->timeout = UINT32_MAX;
retx->reply_ret = -1;
- if (type == DHCPV6_MSG_UNKNOWN)
+ if (req_msg_type == DHCPV6_MSG_UNKNOWN)
retx->timeout = t1;
- else if (type == DHCPV6_MSG_RENEW)
+ else if (req_msg_type == DHCPV6_MSG_RENEW)
retx->timeout = (t2 > t1) ? t2 - t1 : ((t1 == UINT32_MAX) ? UINT32_MAX : 0);
- else if (type == DHCPV6_MSG_REBIND)
+ else if (req_msg_type == DHCPV6_MSG_REBIND)
retx->timeout = (t3 > t2) ? t3 - t2 : ((t2 == UINT32_MAX) ? UINT32_MAX : 0);
if (retx->timeout == 0)
retx->name, retx->timeout, retx->max_rc);
// Generate transaction ID
- if (type != DHCPV6_MSG_UNKNOWN) {
+ if (req_msg_type != DHCPV6_MSG_UNKNOWN) {
odhcp6c_random(retx->tr_id, sizeof(retx->tr_id));
}
int64_t delay = dhcpv6_rand_delay(retx->init_timeo * 1000);
// First RT MUST be strictly greater than IRT for solicit messages (RFC3313 17.1.2)
- while (type == DHCPV6_MSG_SOLICIT && delay <= 0)
+ while (req_msg_type == DHCPV6_MSG_SOLICIT && delay <= 0)
delay = dhcpv6_rand_delay(retx->init_timeo * 1000);
retx->rto = (retx->init_timeo * 1000 + delay);
dhcpv6_set_state_timeout(retx->round_end - odhcp6c_get_milli_time());
// Built and send package
- switch (type) {
+ switch (req_msg_type) {
case DHCPV6_MSG_UNKNOWN:
break;
default:
_o_fallthrough;
case DHCPV6_MSG_SOLICIT:
case DHCPV6_MSG_INFO_REQ:
- dhcpv6_send(type, retx->tr_id, elapsed / 10);
+ dhcpv6_send(req_msg_type, retx->tr_id, elapsed / 10);
retx->rc++;
}
return 0;
}
-int dhcpv6_receive_response(enum dhcpv6_msg type)
+int dhcpv6_receive_response(enum dhcpv6_msg req_msg_type)
{
ssize_t len = -1;
- struct dhcpv6_retx *retx = &dhcpv6_retx[type];
+ struct dhcpv6_retx *retx = &dhcpv6_retx[req_msg_type];
uint8_t buf[1536];
union {
return -1;
}
- if (!dhcpv6_response_is_valid(buf, len, retx->tr_id, type,
+ if (!dhcpv6_response_is_valid(buf, len, retx->tr_id, req_msg_type,
&pktinfo->ipi6_addr)) {
dhcpv6_stats.discarded_packets++;
return -1;
dhcpv6_msg_to_str(hdr->msg_type), elapsed);
if (retx->handler_reply) {
- retx->reply_ret = retx->handler_reply(type, retx->rc, opt, opt_end, &addr);
+ retx->reply_ret = retx->handler_reply(req_msg_type, retx->rc, opt, opt_end, &addr);
len = retx->reply_ret;
}
return retx->reply_ret;
}
-int dhcpv6_state_processing(enum dhcpv6_msg type)
+int dhcpv6_state_processing(enum dhcpv6_msg req_msg_type)
{
- struct dhcpv6_retx *retx = &dhcpv6_retx[type];
+ struct dhcpv6_retx *retx = &dhcpv6_retx[req_msg_type];
int ret = retx->reply_ret;
retx->round_start = odhcp6c_get_milli_time();
uint64_t elapsed = retx->round_start - retx->start;
int nfds = 0;
int mode = DHCPV6_UNKNOWN;
- enum dhcpv6_msg msg_type = DHCPV6_MSG_UNKNOWN;
+ enum dhcpv6_msg req_msg_type = DHCPV6_MSG_UNKNOWN;
fds[DHCPV6_FD_INDEX].fd = -1;
fds[DHCPV6_FD_INDEX].events = POLLIN;
break;
}
- msg_type = DHCPV6_MSG_SOLICIT;
- dhcpv6_send_request(msg_type);
+ req_msg_type = DHCPV6_MSG_SOLICIT;
+ dhcpv6_send_request(req_msg_type);
break;
case DHCPV6_ADVERT:
break;
case DHCPV6_REQUEST:
- msg_type = (mode == DHCPV6_STATELESS) ? DHCPV6_MSG_INFO_REQ : DHCPV6_MSG_REQUEST;
- dhcpv6_send_request(msg_type);
+ req_msg_type = (mode == DHCPV6_STATELESS) ? DHCPV6_MSG_INFO_REQ : DHCPV6_MSG_REQUEST;
+ dhcpv6_send_request(req_msg_type);
break;
case DHCPV6_REPLY:
}
}
- msg_type = DHCPV6_MSG_UNKNOWN;
- dhcpv6_send_request(msg_type);
+ req_msg_type = DHCPV6_MSG_UNKNOWN;
+ dhcpv6_send_request(req_msg_type);
break;
case DHCPV6_BOUND_REPLY:
if (res == DHCPV6_MSG_RENEW || res == DHCPV6_MSG_REBIND ||
res == DHCPV6_MSG_INFO_REQ) {
- msg_type = res;
+ req_msg_type = res;
dhcpv6_set_state(DHCPV6_RECONF);
} else {
dhcpv6_set_state(DHCPV6_RECONF_REPLY);
break;
case DHCPV6_RECONF:
- dhcpv6_send_request(msg_type);
+ dhcpv6_send_request(req_msg_type);
break;
case DHCPV6_RECONF_REPLY:
break;
case DHCPV6_RENEW:
- msg_type = DHCPV6_MSG_RENEW;
- dhcpv6_send_request(msg_type);
+ req_msg_type = DHCPV6_MSG_RENEW;
+ dhcpv6_send_request(req_msg_type);
break;
case DHCPV6_RENEW_REPLY:
break;
}
- msg_type = DHCPV6_MSG_REBIND;
- dhcpv6_send_request(msg_type);
+ req_msg_type = DHCPV6_MSG_REBIND;
+ dhcpv6_send_request(req_msg_type);
break;
case DHCPV6_REBIND_REPLY:
break;
case DHCPV6_INFO:
- msg_type = DHCPV6_MSG_INFO_REQ;
- dhcpv6_send_request(msg_type);
+ req_msg_type = DHCPV6_MSG_INFO_REQ;
+ dhcpv6_send_request(req_msg_type);
break;
case DHCPV6_INFO_REPLY:
case DHCPV6_SOLICIT_PROCESSING:
case DHCPV6_REQUEST_PROCESSING:
- res = dhcpv6_state_processing(msg_type);
+ res = dhcpv6_state_processing(req_msg_type);
break;
case DHCPV6_BOUND_PROCESSING:
case DHCPV6_RECONF_PROCESSING:
case DHCPV6_REBIND_PROCESSING:
- res = dhcpv6_state_processing(msg_type);
+ res = dhcpv6_state_processing(req_msg_type);
if (signal_usr1)
dhcpv6_set_state(mode == DHCPV6_STATELESS ? DHCPV6_INFO : DHCPV6_RENEW);
case DHCPV6_RENEW_PROCESSING:
case DHCPV6_INFO_PROCESSING:
- res = dhcpv6_state_processing(msg_type);
+ res = dhcpv6_state_processing(req_msg_type);
if (signal_usr1)
signal_usr1 = false; // Acknowledged
}
if (fds[0].revents & POLLIN)
- dhcpv6_receive_response(msg_type);
+ dhcpv6_receive_response(req_msg_type);
#ifdef WITH_UBUS
if (fds[1].revents & POLLIN)