531 ip4_addr_t requested_ip;
532 struct pbuf *out_msg = NULL;
533 struct dhcp_msg *srvr_msg = NULL;
534 u16_t options_len = 0;
537#if ETHARP_SUPPORT_STATIC_ENTRIES
538 struct eth_addr ethaddr;
541 LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, (
"handle_request: Processing Request Message\n"));
544 if (requested_ip.addr == 1) {
545 LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE,
546 (
"handle_request: Validation of request message failed. Dropping the packet.\n"));
551 if (out_msg == NULL) {
552 LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, (
"handle_request: Creating base message failed\n"));
556 srvr_msg = (
struct dhcp_msg *)out_msg->payload;
557 dhcp_common_option(srvr_msg, DHCP_OPTION_SERVER_ID, DHCP_OPTION_SERVER_ID_LEN, &options_len);
561 dhcp_common_option(srvr_msg, DHCP_OPTION_ROUTER, DHCP_OPTION_ROUTER_SIZE, &options_len);
564 if ((client_lease != NULL) && (client_lease->
cli_addr.addr == requested_ip.addr)) {
566 if (client_lease->
flags == DHCPS_ADDRESS_OFFERRED) {
575 client_lease->
flags = DHCPS_ADDRESS_BOUND;
576 srvr_msg->yiaddr.addr = htonl(client_lease->
cli_addr.addr);
578 dhcp_common_option(srvr_msg, DHCP_OPTION_MESSAGE_TYPE, DHCP_OPTION_MESSAGE_TYPE_LEN, &options_len);
581 dhcp_common_option(srvr_msg, DHCP_OPTION_LEASE_TIME, DHCP_OPTION_LEASE_TIME_SIZE, &options_len);
591 dhcp_common_option(srvr_msg, DHCP_OPTION_SUBNET_MASK, DHCP_OPTION_SUBNET_MASK_SIZE, &options_len);
595 LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE,
596 (
"handle_request: Send ACK. to=%"U32_F
" lease time=%"U32_F
"\n",
600 dhcp_common_option(srvr_msg, DHCP_OPTION_MESSAGE_TYPE, DHCP_OPTION_MESSAGE_TYPE_LEN, &options_len);
605 client_msg->flags |= htons(DHCP_BROADCAST_FLAG);
606 client_msg->ciaddr.addr = 0;
608 LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE,
609 (
"handle_request: Send NAK. Requested from=%"U32_F
"\n", requested_ip.addr));
613 requested_ip.addr = htonl(requested_ip.addr);
616 if (client_msg->ciaddr.addr != 0) {
617 LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, (
"handle_request: sendto(ACK, ciaddr, DHCP_CLIENT_PORT)\n"));
618 ip_addr_set_ip4_u32_val(dst_addr, (u32_t)(client_msg->ciaddr.addr));
619 (
void)udp_sendto_if_src(
dhcps->
pcb, out_msg, &dst_addr, DHCP_CLIENT_PORT, netif, &(netif->ip_addr));
620 }
else if (ntohs(client_msg->flags) & DHCP_BROADCAST_FLAG) {
621 LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, (
"handle_request: sending reply using brdcast \n"));
622 (
void)udp_sendto_if_src(
dhcps->
pcb, out_msg, IP_ADDR_BROADCAST, DHCP_CLIENT_PORT, netif, &(netif->ip_addr));
624#if ETHARP_SUPPORT_STATIC_ENTRIES
625 LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, (
"handle_request: Updating ARP Static Entry for unicast reply\n"));
626 if (memcpy_s(ethaddr.addr, ETHARP_HWADDR_LEN, client_msg->chaddr, client_msg->hlen) != EOK) {
627 LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, (
"handle_request: Copy chaddr failed\n"));
628 (
void)pbuf_free(out_msg);
631 if (ERR_OK != etharp_add_static_entry(&requested_ip, ðaddr)) {
632 LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, (
"handle_request: Adding static entry to arp cache failed\n"));
633 (
void)pbuf_free(out_msg);
639 LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE,
640 (
"handle_request: sending reply using unicast Client IP =%"U32_F
"\n", requested_ip.addr));
642 ip_send.u_addr.ip4.addr = requested_ip.addr;
643 ip_send.type = IPADDR_TYPE_V4;
644 (
void)udp_sendto_if_src(
dhcps->
pcb, out_msg, &ip_send, DHCP_CLIENT_PORT, netif, &(netif->ip_addr));
646#if ETHARP_SUPPORT_STATIC_ENTRIES
648 LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE,
649 (
"handle_request: Removing ARP Static Entry added for unicast reply\n"));
650 (
void)etharp_remove_static_entry(&requested_ip);
653 LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, (
"handle_request: deleting\n"));
655 (
void)pbuf_free(out_msg);
LWIP_STATIC ip4_addr_t validate_request_message(struct netif *netif, struct dhcp_msg *client_msg, struct dyn_lease_addr *client_lease, ip4_addr_t serverid)