Lines Matching +full:opt +full:- +full:in
8 * SPDX-License-Identifier: Apache-2.0
85 for (int i = 0; i < ARRAY_SIZE(ctx->addr_pool); i++) { in dhcpv4_server_timeout_recalc()
86 struct dhcpv4_addr_slot *slot = &ctx->addr_pool[i]; in dhcpv4_server_timeout_recalc()
88 if (slot->state == DHCPV4_SERVER_ADDR_RESERVED || in dhcpv4_server_timeout_recalc()
89 slot->state == DHCPV4_SERVER_ADDR_ALLOCATED || in dhcpv4_server_timeout_recalc()
90 slot->state == DHCPV4_SERVER_ADDR_DECLINED) { in dhcpv4_server_timeout_recalc()
91 if (sys_timepoint_cmp(slot->expiry, next) < 0) { in dhcpv4_server_timeout_recalc()
92 next = slot->expiry; in dhcpv4_server_timeout_recalc()
101 k_work_cancel_delayable(&ctx->timeout_work); in dhcpv4_server_timeout_recalc()
103 k_work_reschedule(&ctx->timeout_work, timeout); in dhcpv4_server_timeout_recalc()
112 uint8_t *opt = NULL; in dhcpv4_find_option() local
123 datalen--; in dhcpv4_find_option()
144 opt = data + 2; in dhcpv4_find_option()
150 datalen -= len + 2; in dhcpv4_find_option()
153 return opt; in dhcpv4_find_option()
159 uint8_t *opt; in dhcpv4_find_message_type_option() local
162 opt = dhcpv4_find_option(data, datalen, &optlen, in dhcpv4_find_message_type_option()
164 if (opt == NULL) { in dhcpv4_find_message_type_option()
165 return -ENOENT; in dhcpv4_find_message_type_option()
169 return -EINVAL; in dhcpv4_find_message_type_option()
172 *msgtype = *opt; in dhcpv4_find_message_type_option()
180 uint8_t *opt; in dhcpv4_find_server_id_option() local
183 opt = dhcpv4_find_option(data, datalen, &optlen, in dhcpv4_find_server_id_option()
185 if (opt == NULL) { in dhcpv4_find_server_id_option()
186 return -ENOENT; in dhcpv4_find_server_id_option()
190 return -EINVAL; in dhcpv4_find_server_id_option()
193 memcpy(server_id, opt, sizeof(struct in_addr)); in dhcpv4_find_server_id_option()
201 uint8_t *opt; in dhcpv4_find_client_id_option() local
204 opt = dhcpv4_find_option(data, datalen, &optlen, in dhcpv4_find_client_id_option()
206 if (opt == NULL) { in dhcpv4_find_client_id_option()
207 return -ENOENT; in dhcpv4_find_client_id_option()
211 return -EINVAL; in dhcpv4_find_client_id_option()
216 return -ENOMEM; in dhcpv4_find_client_id_option()
219 memcpy(client_id, opt, optlen); in dhcpv4_find_client_id_option()
228 uint8_t *opt; in dhcpv4_find_requested_ip_option() local
231 opt = dhcpv4_find_option(data, datalen, &optlen, in dhcpv4_find_requested_ip_option()
233 if (opt == NULL) { in dhcpv4_find_requested_ip_option()
234 return -ENOENT; in dhcpv4_find_requested_ip_option()
238 return -EINVAL; in dhcpv4_find_requested_ip_option()
241 memcpy(requested_ip, opt, sizeof(struct in_addr)); in dhcpv4_find_requested_ip_option()
249 uint8_t *opt; in dhcpv4_find_ip_lease_time_option() local
252 opt = dhcpv4_find_option(data, datalen, &optlen, in dhcpv4_find_ip_lease_time_option()
254 if (opt == NULL) { in dhcpv4_find_ip_lease_time_option()
255 return -ENOENT; in dhcpv4_find_ip_lease_time_option()
259 return -EINVAL; in dhcpv4_find_ip_lease_time_option()
262 *lease_time = sys_get_be32(opt); in dhcpv4_find_ip_lease_time_option()
271 uint8_t *opt; in dhcpv4_find_parameter_request_list_option() local
274 opt = dhcpv4_find_option(data, datalen, &optlen, in dhcpv4_find_parameter_request_list_option()
276 if (opt == NULL) { in dhcpv4_find_parameter_request_list_option()
277 return -ENOENT; in dhcpv4_find_parameter_request_list_option()
280 if (optlen > sizeof(params->list)) { in dhcpv4_find_parameter_request_list_option()
282 optlen = sizeof(params->list); in dhcpv4_find_parameter_request_list_option()
285 memcpy(params->list, opt, optlen); in dhcpv4_find_parameter_request_list_option()
286 params->count = optlen; in dhcpv4_find_parameter_request_list_option()
301 *buflen -= SIZE_OF_MAGIC_COOKIE; in dhcpv4_encode_magic_cookie()
317 *buflen -= DHCPV4_OPTIONS_IP_LEASE_TIME_SIZE; in dhcpv4_encode_ip_lease_time_option()
333 *buflen -= DHCPV4_OPTIONS_MSG_TYPE_SIZE; in dhcpv4_encode_message_type_option()
347 memcpy(&buf[2], server_id->s4_addr, sizeof(struct in_addr)); in dhcpv4_encode_server_id_option()
349 *buflen -= DHCPV4_OPTIONS_SERVER_ID_SIZE; in dhcpv4_encode_server_id_option()
357 if (buf == NULL || *buflen < client_id->len + 2) { in dhcpv4_encode_client_id_option()
362 buf[1] = client_id->len; in dhcpv4_encode_client_id_option()
363 memcpy(&buf[2], client_id->buf, client_id->len); in dhcpv4_encode_client_id_option()
365 *buflen -= client_id->len + 2; in dhcpv4_encode_client_id_option()
367 return buf + client_id->len + 2; in dhcpv4_encode_client_id_option()
379 memcpy(&buf[2], mask->s4_addr, sizeof(struct in_addr)); in dhcpv4_encode_subnet_mask_option()
381 *buflen -= DHCPV4_OPTIONS_SUBNET_MASK_SIZE; in dhcpv4_encode_subnet_mask_option()
395 memcpy(&buf[2], router->s4_addr, sizeof(struct in_addr)); in dhcpv4_encode_router_option()
397 *buflen -= DHCPV4_OPTIONS_ROUTER_SIZE; in dhcpv4_encode_router_option()
420 *buflen -= DHCPV4_OPTIONS_DNS_SERVER_SIZE; in dhcpv4_encode_dns_server_option()
433 *buflen -= 1; in dhcpv4_encode_end_option()
450 reply_msg->op = DHCPV4_MSG_BOOT_REPLY; in dhcpv4_encode_header()
451 reply_msg->htype = msg->htype; in dhcpv4_encode_header()
452 reply_msg->hlen = msg->hlen; in dhcpv4_encode_header()
453 reply_msg->hops = 0; in dhcpv4_encode_header()
454 reply_msg->xid = msg->xid; in dhcpv4_encode_header()
455 reply_msg->secs = 0; in dhcpv4_encode_header()
456 reply_msg->flags = msg->flags; in dhcpv4_encode_header()
457 memcpy(reply_msg->ciaddr, msg->ciaddr, sizeof(reply_msg->ciaddr)); in dhcpv4_encode_header()
459 memcpy(reply_msg->yiaddr, yiaddr, sizeof(struct in_addr)); in dhcpv4_encode_header()
461 memset(reply_msg->yiaddr, 0, sizeof(reply_msg->ciaddr)); in dhcpv4_encode_header()
463 memset(reply_msg->siaddr, 0, sizeof(reply_msg->siaddr)); in dhcpv4_encode_header()
464 memcpy(reply_msg->giaddr, msg->giaddr, sizeof(reply_msg->giaddr)); in dhcpv4_encode_header()
465 memcpy(reply_msg->chaddr, msg->chaddr, sizeof(reply_msg->chaddr)); in dhcpv4_encode_header()
467 *buflen -= sizeof(struct dhcp_msg); in dhcpv4_encode_header()
485 strncpy(buf, str, max_len - 1); in dhcpv4_encode_string()
488 *buflen -= max_len; in dhcpv4_encode_string()
508 for (uint8_t i = 0; i < params->count; i++) { in dhcpv4_encode_requested_params()
509 switch (params->list[i]) { in dhcpv4_encode_requested_params()
512 buf, buflen, &ctx->netmask); in dhcpv4_encode_requested_params()
520 buf, buflen, &ctx->iface->config.ip.ipv4->gw); in dhcpv4_encode_requested_params()
532 /* Others - just ignore. */ in dhcpv4_encode_requested_params()
554 memcpy(&giaddr, msg->giaddr, sizeof(giaddr)); in dhcpv4_send()
555 memcpy(&ciaddr, msg->ciaddr, sizeof(ciaddr)); in dhcpv4_send()
557 /* Select destination address as described in ch. 4.1. */ in dhcpv4_send()
559 /* If the 'giaddr' field in a DHCP message from a client is in dhcpv4_send()
560 * non-zero, the server sends any return messages to the in dhcpv4_send()
562 * appears in 'giaddr'. in dhcpv4_send()
567 /* In all cases, when 'giaddr' is zero, the server broadcasts in dhcpv4_send()
574 * messages to the address in 'ciaddr'. in dhcpv4_send()
577 } else if (ntohs(msg->flags) & DHCPV4_MSG_BROADCAST) { in dhcpv4_send()
591 memcpy(&hwaddr, msg->chaddr, sizeof(hwaddr)); in dhcpv4_send()
592 net_arp_update(ctx->iface, yiaddr, &hwaddr, false, true); in dhcpv4_send()
596 return -EDESTADDRREQ; in dhcpv4_send()
599 ret = zsock_sendto(ctx->sock, reply, len, 0, (struct sockaddr *)&dst_addr, in dhcpv4_send()
602 return -errno; in dhcpv4_send()
626 buf = dhcpv4_encode_server_id_option(buf, &buflen, &ctx->server_addr); in dhcpv4_send_offer()
633 return -ENOMEM; in dhcpv4_send_offer()
636 reply_len = sizeof(reply) - buflen; in dhcpv4_send_offer()
669 buf = dhcpv4_encode_server_id_option(buf, &buflen, &ctx->server_addr); in dhcpv4_send_ack()
678 return -ENOMEM; in dhcpv4_send_ack()
681 reply_len = sizeof(reply) - buflen; in dhcpv4_send_ack()
708 buf = dhcpv4_encode_server_id_option(buf, &buflen, &ctx->server_addr); in dhcpv4_send_nak()
714 return -ENOMEM; in dhcpv4_send_nak()
717 reply_len = sizeof(reply) - buflen; in dhcpv4_send_nak()
736 client_id->len = sizeof(client_id->buf); in dhcpv4_get_client_id()
738 ret = dhcpv4_find_client_id_option(options, optlen, client_id->buf, in dhcpv4_get_client_id()
739 &client_id->len); in dhcpv4_get_client_id()
745 if (msg->hlen > sizeof(msg->chaddr)) { in dhcpv4_get_client_id()
747 return -EINVAL; in dhcpv4_get_client_id()
750 client_id->buf[0] = msg->htype; in dhcpv4_get_client_id()
751 memcpy(client_id->buf + 1, msg->chaddr, msg->hlen); in dhcpv4_get_client_id()
752 client_id->len = msg->hlen + 1; in dhcpv4_get_client_id()
775 .sin_addr = slot->addr, in dhcpv4_probe_address()
779 ret = net_icmp_send_echo_request(&ctx->probe_ctx.icmp_ctx, ctx->iface, in dhcpv4_probe_address()
811 probe_ctx = &ctx->probe_ctx; in echo_reply_handler()
813 if (probe_ctx->slot == NULL) { in echo_reply_handler()
817 if (ip_hdr->family != AF_INET) { in echo_reply_handler()
821 net_ipv4_addr_copy_raw((uint8_t *)&peer_addr, ip_hdr->ipv4->src); in echo_reply_handler()
822 if (!net_ipv4_addr_cmp(&peer_addr, &probe_ctx->slot->addr)) { in echo_reply_handler()
827 net_sprint_ipv4_addr(&probe_ctx->slot->addr)); in echo_reply_handler()
829 probe_ctx->slot->state = DHCPV4_SERVER_ADDR_DECLINED; in echo_reply_handler()
830 probe_ctx->slot->expiry = sys_timepoint_calc(ADDRESS_DECLINED_TIMEOUT); in echo_reply_handler()
833 for (int i = 0; i < ARRAY_SIZE(ctx->addr_pool); i++) { in echo_reply_handler()
834 struct dhcpv4_addr_slot *slot = &ctx->addr_pool[i]; in echo_reply_handler()
836 if (slot->state == DHCPV4_SERVER_ADDR_FREE) { in echo_reply_handler()
844 probe_ctx->slot = NULL; in echo_reply_handler()
850 probe_ctx->slot = NULL; in echo_reply_handler()
855 new_slot->state = DHCPV4_SERVER_ADDR_RESERVED; in echo_reply_handler()
856 new_slot->expiry = sys_timepoint_calc(ADDRESS_PROBE_TIMEOUT); in echo_reply_handler()
857 new_slot->client_id.len = probe_ctx->slot->client_id.len; in echo_reply_handler()
858 memcpy(new_slot->client_id.buf, probe_ctx->slot->client_id.buf, in echo_reply_handler()
859 new_slot->client_id.len); in echo_reply_handler()
860 new_slot->lease_time = probe_ctx->slot->lease_time; in echo_reply_handler()
862 probe_ctx->slot = new_slot; in echo_reply_handler()
874 return net_icmp_init_ctx(&ctx->probe_ctx.icmp_ctx, in dhcpv4_server_probing_init()
881 (void)net_icmp_cleanup_ctx(&ctx->probe_ctx.icmp_ctx); in dhcpv4_server_probing_deinit()
892 if (ctx->probe_ctx.slot != NULL) { in dhcpv4_server_probe_setup()
893 return -EBUSY; in dhcpv4_server_probe_setup()
901 ctx->probe_ctx.slot = slot; in dhcpv4_server_probe_setup()
902 ctx->probe_ctx.discovery = *msg; in dhcpv4_server_probe_setup()
903 ctx->probe_ctx.params = *params; in dhcpv4_server_probe_setup()
904 ctx->probe_ctx.client_id = *client_id; in dhcpv4_server_probe_setup()
913 ctx->probe_ctx.slot = NULL; in dhcpv4_server_probe_timeout()
915 (void)net_arp_clear_pending(ctx->iface, &slot->addr); in dhcpv4_server_probe_timeout()
917 if (dhcpv4_send_offer(ctx, &ctx->probe_ctx.discovery, &slot->addr, in dhcpv4_server_probe_timeout()
918 slot->lease_time, &ctx->probe_ctx.params, in dhcpv4_server_probe_timeout()
919 &ctx->probe_ctx.client_id) < 0) { in dhcpv4_server_probe_timeout()
920 slot->state = DHCPV4_SERVER_ADDR_FREE; in dhcpv4_server_probe_timeout()
924 slot->expiry = sys_timepoint_calc(ADDRESS_RESERVED_TIMEOUT); in dhcpv4_server_probe_timeout()
930 return (ctx->probe_ctx.slot == slot); in dhcpv4_server_is_slot_probed()
935 #define dhcpv4_server_probe_setup(...) (-ENOTSUP)
958 * described in 4.3.1 in dhcpv4_handle_discover()
962 for (int i = 0; i < ARRAY_SIZE(ctx->addr_pool); i++) { in dhcpv4_handle_discover()
963 struct dhcpv4_addr_slot *slot = &ctx->addr_pool[i]; in dhcpv4_handle_discover()
965 if ((slot->state == DHCPV4_SERVER_ADDR_RESERVED || in dhcpv4_handle_discover()
966 slot->state == DHCPV4_SERVER_ADDR_ALLOCATED) && in dhcpv4_handle_discover()
967 slot->client_id.len == client_id.len && in dhcpv4_handle_discover()
968 memcmp(slot->client_id.buf, client_id.buf, in dhcpv4_handle_discover()
970 if (slot->state == DHCPV4_SERVER_ADDR_RESERVED && in dhcpv4_handle_discover()
972 LOG_DBG("ICMP probing in progress, ignore Discovery"); in dhcpv4_handle_discover()
976 /* Got match in current bindings. */ in dhcpv4_handle_discover()
982 if (slot->state == DHCPV4_SERVER_ADDR_FREE && in dhcpv4_handle_discover()
984 ret = address_provider_callback(ctx->iface, &client_id, &addr, in dhcpv4_handle_discover()
988 slot->addr = addr; in dhcpv4_handle_discover()
1003 for (int i = 0; i < ARRAY_SIZE(ctx->addr_pool); i++) { in dhcpv4_handle_discover()
1005 &ctx->addr_pool[i]; in dhcpv4_handle_discover()
1007 if (net_ipv4_addr_cmp(&slot->addr, in dhcpv4_handle_discover()
1009 slot->state == DHCPV4_SERVER_ADDR_FREE) { in dhcpv4_handle_discover()
1023 memcpy(&giaddr, msg->giaddr, sizeof(giaddr)); in dhcpv4_handle_discover()
1025 /* Only addresses in local subnet supported for now. */ in dhcpv4_handle_discover()
1029 for (int i = 0; i < ARRAY_SIZE(ctx->addr_pool); i++) { in dhcpv4_handle_discover()
1030 struct dhcpv4_addr_slot *slot = &ctx->addr_pool[i]; in dhcpv4_handle_discover()
1032 if (slot->state == DHCPV4_SERVER_ADDR_FREE) { in dhcpv4_handle_discover()
1041 /* In case no free address slot was found, as a last resort, try to in dhcpv4_handle_discover()
1045 for (int i = 0; i < ARRAY_SIZE(ctx->addr_pool); i++) { in dhcpv4_handle_discover()
1046 struct dhcpv4_addr_slot *slot = &ctx->addr_pool[i]; in dhcpv4_handle_discover()
1048 if (slot->state != DHCPV4_SERVER_ADDR_DECLINED) { in dhcpv4_handle_discover()
1054 (sys_timepoint_cmp(slot->expiry, in dhcpv4_handle_discover()
1055 selected->expiry) < 0)) { in dhcpv4_handle_discover()
1063 LOG_ERR("No free address found in address pool"); in dhcpv4_handle_discover()
1070 /* Probing context already in use or failed to in dhcpv4_handle_discover()
1077 selected->expiry = in dhcpv4_handle_discover()
1080 if (dhcpv4_send_offer(ctx, msg, &selected->addr, in dhcpv4_handle_discover()
1085 selected->expiry = in dhcpv4_handle_discover()
1089 LOG_DBG("DHCPv4 processing Discover - reserved %s", in dhcpv4_handle_discover()
1090 net_sprint_ipv4_addr(&selected->addr)); in dhcpv4_handle_discover()
1092 selected->state = DHCPV4_SERVER_ADDR_RESERVED; in dhcpv4_handle_discover()
1093 selected->client_id.len = client_id.len; in dhcpv4_handle_discover()
1094 memcpy(selected->client_id.buf, client_id.buf, client_id.len); in dhcpv4_handle_discover()
1095 selected->lease_time = lease_time; in dhcpv4_handle_discover()
1110 memcpy(&ciaddr, msg->ciaddr, sizeof(ciaddr)); in dhcpv4_handle_request()
1111 memcpy(&giaddr, msg->giaddr, sizeof(giaddr)); in dhcpv4_handle_request()
1114 /* Only addresses in local subnet supported for now. */ in dhcpv4_handle_request()
1129 if (!net_ipv4_addr_cmp(&ctx->server_addr, &server_id)) { in dhcpv4_handle_request()
1146 for (int i = 0; i < ARRAY_SIZE(ctx->addr_pool); i++) { in dhcpv4_handle_request()
1147 struct dhcpv4_addr_slot *slot = &ctx->addr_pool[i]; in dhcpv4_handle_request()
1149 if (net_ipv4_addr_cmp(&slot->addr, &requested_ip) && in dhcpv4_handle_request()
1150 slot->client_id.len == client_id.len && in dhcpv4_handle_request()
1151 memcmp(slot->client_id.buf, client_id.buf, in dhcpv4_handle_request()
1153 (slot->state == DHCPV4_SERVER_ADDR_RESERVED || in dhcpv4_handle_request()
1154 slot->state == DHCPV4_SERVER_ADDR_ALLOCATED)) { in dhcpv4_handle_request()
1165 if (dhcpv4_send_ack(ctx, msg, &selected->addr, lease_time, in dhcpv4_handle_request()
1170 LOG_DBG("DHCPv4 processing Request - allocated %s", in dhcpv4_handle_request()
1171 net_sprint_ipv4_addr(&selected->addr)); in dhcpv4_handle_request()
1173 selected->lease_time = lease_time; in dhcpv4_handle_request()
1174 selected->expiry = sys_timepoint_calc( in dhcpv4_handle_request()
1176 selected->state = DHCPV4_SERVER_ADDR_ALLOCATED; in dhcpv4_handle_request()
1183 /* No server ID option - check requested address. */ in dhcpv4_handle_request()
1186 /* Requested IP present, Request generated during INIT-REBOOT. */ in dhcpv4_handle_request()
1192 if (!net_if_ipv4_addr_mask_cmp(ctx->iface, &requested_ip)) { in dhcpv4_handle_request()
1197 for (int i = 0; i < ARRAY_SIZE(ctx->addr_pool); i++) { in dhcpv4_handle_request()
1198 struct dhcpv4_addr_slot *slot = &ctx->addr_pool[i]; in dhcpv4_handle_request()
1200 if (slot->client_id.len == client_id.len && in dhcpv4_handle_request()
1201 memcmp(slot->client_id.buf, client_id.buf, in dhcpv4_handle_request()
1203 (slot->state == DHCPV4_SERVER_ADDR_RESERVED || in dhcpv4_handle_request()
1204 slot->state == DHCPV4_SERVER_ADDR_ALLOCATED)) { in dhcpv4_handle_request()
1211 if (net_ipv4_addr_cmp(&selected->addr, &requested_ip)) { in dhcpv4_handle_request()
1215 if (dhcpv4_send_ack(ctx, msg, &selected->addr, in dhcpv4_handle_request()
1221 selected->lease_time = lease_time; in dhcpv4_handle_request()
1222 selected->expiry = sys_timepoint_calc( in dhcpv4_handle_request()
1240 if (!net_if_ipv4_addr_mask_cmp(ctx->iface, &ciaddr)) { in dhcpv4_handle_request()
1245 for (int i = 0; i < ARRAY_SIZE(ctx->addr_pool); i++) { in dhcpv4_handle_request()
1246 struct dhcpv4_addr_slot *slot = &ctx->addr_pool[i]; in dhcpv4_handle_request()
1248 if (net_ipv4_addr_cmp(&slot->addr, &ciaddr)) { in dhcpv4_handle_request()
1255 if (selected->state == DHCPV4_SERVER_ADDR_ALLOCATED && in dhcpv4_handle_request()
1256 selected->client_id.len == client_id.len && in dhcpv4_handle_request()
1257 memcmp(selected->client_id.buf, client_id.buf, in dhcpv4_handle_request()
1267 selected->lease_time = lease_time; in dhcpv4_handle_request()
1268 selected->expiry = sys_timepoint_calc( in dhcpv4_handle_request()
1291 if (!net_ipv4_addr_cmp(&ctx->server_addr, &server_id)) { in dhcpv4_handle_decline()
1309 LOG_ERR("Received DHCPv4 Decline for %s (address already in use)", in dhcpv4_handle_decline()
1312 for (int i = 0; i < ARRAY_SIZE(ctx->addr_pool); i++) { in dhcpv4_handle_decline()
1313 struct dhcpv4_addr_slot *slot = &ctx->addr_pool[i]; in dhcpv4_handle_decline()
1315 if (net_ipv4_addr_cmp(&slot->addr, &requested_ip) && in dhcpv4_handle_decline()
1316 slot->client_id.len == client_id.len && in dhcpv4_handle_decline()
1317 memcmp(slot->client_id.buf, client_id.buf, in dhcpv4_handle_decline()
1319 (slot->state == DHCPV4_SERVER_ADDR_RESERVED || in dhcpv4_handle_decline()
1320 slot->state == DHCPV4_SERVER_ADDR_ALLOCATED)) { in dhcpv4_handle_decline()
1321 slot->state = DHCPV4_SERVER_ADDR_DECLINED; in dhcpv4_handle_decline()
1322 slot->expiry = in dhcpv4_handle_decline()
1344 if (!net_ipv4_addr_cmp(&ctx->server_addr, &server_id)) { in dhcpv4_handle_release()
1355 memcpy(&ciaddr, msg->ciaddr, sizeof(ciaddr)); in dhcpv4_handle_release()
1357 for (int i = 0; i < ARRAY_SIZE(ctx->addr_pool); i++) { in dhcpv4_handle_release()
1358 struct dhcpv4_addr_slot *slot = &ctx->addr_pool[i]; in dhcpv4_handle_release()
1360 if (net_ipv4_addr_cmp(&slot->addr, &ciaddr) && in dhcpv4_handle_release()
1361 slot->client_id.len == client_id.len && in dhcpv4_handle_release()
1362 memcmp(slot->client_id.buf, client_id.buf, in dhcpv4_handle_release()
1364 (slot->state == DHCPV4_SERVER_ADDR_RESERVED || in dhcpv4_handle_release()
1365 slot->state == DHCPV4_SERVER_ADDR_ALLOCATED)) { in dhcpv4_handle_release()
1366 LOG_DBG("DHCPv4 processing Release - %s", in dhcpv4_handle_release()
1367 net_sprint_ipv4_addr(&slot->addr)); in dhcpv4_handle_release()
1369 slot->state = DHCPV4_SERVER_ADDR_FREE; in dhcpv4_handle_release()
1370 slot->expiry = sys_timepoint_calc(K_FOREVER); in dhcpv4_handle_release()
1384 (void)dhcpv4_send_ack(ctx, msg, (struct in_addr *)msg->ciaddr, 0, in dhcpv4_handle_inform()
1398 for (int i = 0; i < ARRAY_SIZE(ctx->addr_pool); i++) { in dhcpv4_server_timeout()
1399 struct dhcpv4_addr_slot *slot = &ctx->addr_pool[i]; in dhcpv4_server_timeout()
1401 if ((slot->state == DHCPV4_SERVER_ADDR_RESERVED || in dhcpv4_server_timeout()
1402 slot->state == DHCPV4_SERVER_ADDR_ALLOCATED) && in dhcpv4_server_timeout()
1403 sys_timepoint_expired(slot->expiry)) { in dhcpv4_server_timeout()
1404 if (slot->state == DHCPV4_SERVER_ADDR_RESERVED && in dhcpv4_server_timeout()
1409 net_sprint_ipv4_addr(&slot->addr)); in dhcpv4_server_timeout()
1410 slot->state = DHCPV4_SERVER_ADDR_FREE; in dhcpv4_server_timeout()
1414 if (slot->state == DHCPV4_SERVER_ADDR_DECLINED && in dhcpv4_server_timeout()
1415 sys_timepoint_expired(slot->expiry)) { in dhcpv4_server_timeout()
1416 slot->state = DHCPV4_SERVER_ADDR_FREE; in dhcpv4_server_timeout()
1439 if (msg->op != DHCPV4_MSG_BOOT_REQUEST) { in dhcpv4_process_data()
1445 datalen -= sizeof(struct dhcp_msg); in dhcpv4_process_data()
1453 datalen -= SIZE_OF_SNAME + SIZE_OF_FILE + SIZE_OF_MAGIC_COOKIE; in dhcpv4_process_data()
1499 if (server_ctx[i].sock == evt->event.fd) { in dhcpv4_server_cb()
1510 if (evt->event.revents & ZSOCK_POLLERR) { in dhcpv4_server_cb()
1512 net_dhcpv4_server_stop(ctx->iface); in dhcpv4_server_cb()
1516 if (!(evt->event.revents & ZSOCK_POLLIN)) { in dhcpv4_server_cb()
1520 ret = zsock_recvfrom(evt->event.fd, recv_buf, sizeof(recv_buf), in dhcpv4_server_cb()
1528 net_dhcpv4_server_stop(ctx->iface); in dhcpv4_server_cb()
1546 int ret, sock = -1, slot = -1; in net_dhcpv4_server_start()
1551 return -EINVAL; in net_dhcpv4_server_start()
1556 return -EINVAL; in net_dhcpv4_server_start()
1562 return -EINVAL; in net_dhcpv4_server_start()
1565 if ((htonl(server_addr->s_addr) >= htonl(base_addr->s_addr)) && in net_dhcpv4_server_start()
1566 (htonl(server_addr->s_addr) < in net_dhcpv4_server_start()
1567 htonl(base_addr->s_addr) + CONFIG_NET_DHCPV4_SERVER_ADDR_COUNT)) { in net_dhcpv4_server_start()
1569 return -EINVAL; in net_dhcpv4_server_start()
1575 return -EINVAL; in net_dhcpv4_server_start()
1584 ret = -EALREADY; in net_dhcpv4_server_start()
1596 ret = -ENOMEM; in net_dhcpv4_server_start()
1608 ret = -errno; in net_dhcpv4_server_start()
1616 ret = -errno; in net_dhcpv4_server_start()
1624 ret = -errno; in net_dhcpv4_server_start()
1644 htonl(ntohl(base_addr->s_addr) + i); in net_dhcpv4_server_start()
1671 fds[slot].fd = -1; in net_dhcpv4_server_start()
1686 int slot = -1; in net_dhcpv4_server_stop()
1691 return -EINVAL; in net_dhcpv4_server_stop()
1704 ret = -ENOENT; in net_dhcpv4_server_stop()
1708 fds[slot].fd = -1; in net_dhcpv4_server_stop()
1740 for (int i = 0; i < ARRAY_SIZE(ctx->addr_pool); i++) { in dhcpv4_server_foreach_lease_on_ctx()
1741 struct dhcpv4_addr_slot *addr = &ctx->addr_pool[i]; in dhcpv4_server_foreach_lease_on_ctx()
1743 if (addr->state != DHCPV4_SERVER_ADDR_FREE) { in dhcpv4_server_foreach_lease_on_ctx()
1744 cb(ctx->iface, addr, user_data); in dhcpv4_server_foreach_lease_on_ctx()
1753 int slot = -1; in net_dhcpv4_server_foreach_lease()
1777 ret = -ENOENT; in net_dhcpv4_server_foreach_lease()
1801 fds[i].fd = -1; in net_dhcpv4_server_init()