lwip: format dhcpserver.c

This commit is contained in:
Wu Jian Gang
2016-09-01 19:05:50 +08:00
parent 1f4af47911
commit 87977b92f3

View File

@@ -102,22 +102,33 @@ static dhcps_time_t dhcps_lease_time = DHCPS_LEASE_TIME_DEF; //minute
void *dhcps_option_info(u8_t op_id, u32_t opt_len) void *dhcps_option_info(u8_t op_id, u32_t opt_len)
{ {
void *option_arg = NULL; void *option_arg = NULL;
switch (op_id) { switch (op_id) {
case IP_ADDRESS_LEASE_TIME: case IP_ADDRESS_LEASE_TIME:
if (opt_len == sizeof(dhcps_time_t)) if (opt_len == sizeof(dhcps_time_t)) {
option_arg = &dhcps_lease_time; option_arg = &dhcps_lease_time;
}
break; break;
case REQUESTED_IP_ADDRESS: case REQUESTED_IP_ADDRESS:
if (opt_len == sizeof(dhcps_lease_t)) if (opt_len == sizeof(dhcps_lease_t)) {
option_arg = &dhcps_poll; option_arg = &dhcps_poll;
}
break; break;
case ROUTER_SOLICITATION_ADDRESS: case ROUTER_SOLICITATION_ADDRESS:
if (opt_len == sizeof(dhcps_offer_t)) if (opt_len == sizeof(dhcps_offer_t)) {
option_arg = &dhcps_offer; option_arg = &dhcps_offer;
}
break; break;
default: default:
break; break;
} }
return option_arg; return option_arg;
} }
@@ -133,9 +144,10 @@ void node_insert_to_list(list_node **phead, list_node* pinsert)
list_node *plist = NULL; list_node *plist = NULL;
struct dhcps_pool *pdhcps_pool = NULL; struct dhcps_pool *pdhcps_pool = NULL;
struct dhcps_pool *pdhcps_node = NULL; struct dhcps_pool *pdhcps_node = NULL;
if (*phead == NULL)
if (*phead == NULL) {
*phead = pinsert; *phead = pinsert;
else { } else {
plist = *phead; plist = *phead;
pdhcps_node = pinsert->pnode; pdhcps_node = pinsert->pnode;
pdhcps_pool = plist->pnode; pdhcps_pool = plist->pnode;
@@ -146,11 +158,13 @@ void node_insert_to_list(list_node **phead, list_node* pinsert)
} else { } else {
while (plist->pnext != NULL) { while (plist->pnext != NULL) {
pdhcps_pool = plist->pnext->pnode; pdhcps_pool = plist->pnext->pnode;
if (pdhcps_node->ip.addr < pdhcps_pool->ip.addr) { if (pdhcps_node->ip.addr < pdhcps_pool->ip.addr) {
pinsert->pnext = plist->pnext; pinsert->pnext = plist->pnext;
plist->pnext = pinsert; plist->pnext = pinsert;
break; break;
} }
plist = plist->pnext; plist = plist->pnext;
} }
@@ -159,6 +173,7 @@ void node_insert_to_list(list_node **phead, list_node* pinsert)
} }
} }
} }
// pinsert->pnext = NULL; // pinsert->pnext = NULL;
} }
@@ -174,6 +189,7 @@ void node_remove_from_list(list_node **phead, list_node* pdelete)
list_node *plist = NULL; list_node *plist = NULL;
plist = *phead; plist = *phead;
if (plist == NULL) { if (plist == NULL) {
*phead = NULL; *phead = NULL;
} else { } else {
@@ -186,6 +202,7 @@ void node_remove_from_list(list_node **phead, list_node* pdelete)
plist->pnext = pdelete->pnext; plist->pnext = pdelete->pnext;
pdelete->pnext = NULL; pdelete->pnext = NULL;
} }
plist = plist->pnext; plist = plist->pnext;
} }
} }
@@ -394,6 +411,7 @@ static void send_offer(struct dhcps_msg *m)
#if DHCPS_DEBUG #if DHCPS_DEBUG
DHCPS_LOG("udhcp: send_offer>>p->ref = %d\n", p->ref); DHCPS_LOG("udhcp: send_offer>>p->ref = %d\n", p->ref);
#endif #endif
if (p != NULL) { if (p != NULL) {
#if DHCPS_DEBUG #if DHCPS_DEBUG
@@ -402,16 +420,19 @@ static void send_offer(struct dhcps_msg *m)
DHCPS_LOG("dhcps: send_offer>>p->len = %d\n", p->len); DHCPS_LOG("dhcps: send_offer>>p->len = %d\n", p->len);
#endif #endif
q = p; q = p;
while (q != NULL) { while (q != NULL) {
data = (u8_t *)q->payload; data = (u8_t *)q->payload;
for(i=0; i<q->len; i++)
{ for (i = 0; i < q->len; i++) {
data[i] = ((u8_t *) m)[cnt++]; data[i] = ((u8_t *) m)[cnt++];
#if DHCPS_DEBUG #if DHCPS_DEBUG
DHCPS_LOG("%02x ", data[i]); DHCPS_LOG("%02x ", data[i]);
if ((i + 1) % 16 == 0) { if ((i + 1) % 16 == 0) {
DHCPS_LOG("\n"); DHCPS_LOG("\n");
} }
#endif #endif
} }
@@ -431,6 +452,7 @@ static void send_offer(struct dhcps_msg *m)
#if DHCPS_DEBUG #if DHCPS_DEBUG
DHCPS_LOG("dhcps: send_offer>>udp_sendto result %x\n", SendOffer_err_t); DHCPS_LOG("dhcps: send_offer>>udp_sendto result %x\n", SendOffer_err_t);
#endif #endif
if (p->ref != 0) { if (p->ref != 0) {
#if DHCPS_DEBUG #if DHCPS_DEBUG
DHCPS_LOG("udhcp: send_offer>>free pbuf\n"); DHCPS_LOG("udhcp: send_offer>>free pbuf\n");
@@ -462,6 +484,7 @@ static void send_nak(struct dhcps_msg *m)
#if DHCPS_DEBUG #if DHCPS_DEBUG
DHCPS_LOG("udhcp: send_nak>>p->ref = %d\n", p->ref); DHCPS_LOG("udhcp: send_nak>>p->ref = %d\n", p->ref);
#endif #endif
if (p != NULL) { if (p != NULL) {
#if DHCPS_DEBUG #if DHCPS_DEBUG
@@ -470,16 +493,19 @@ static void send_nak(struct dhcps_msg *m)
DHCPS_LOG("dhcps: send_nak>>p->len = %d\n", p->len); DHCPS_LOG("dhcps: send_nak>>p->len = %d\n", p->len);
#endif #endif
q = p; q = p;
while (q != NULL) { while (q != NULL) {
data = (u8_t *)q->payload; data = (u8_t *)q->payload;
for(i=0; i<q->len; i++)
{ for (i = 0; i < q->len; i++) {
data[i] = ((u8_t *) m)[cnt++]; data[i] = ((u8_t *) m)[cnt++];
#if DHCPS_DEBUG #if DHCPS_DEBUG
DHCPS_LOG("%02x ", data[i]); DHCPS_LOG("%02x ", data[i]);
if ((i + 1) % 16 == 0) { if ((i + 1) % 16 == 0) {
DHCPS_LOG("\n"); DHCPS_LOG("\n");
} }
#endif #endif
} }
@@ -499,6 +525,7 @@ static void send_nak(struct dhcps_msg *m)
#if DHCPS_DEBUG #if DHCPS_DEBUG
DHCPS_LOG("dhcps: send_nak>>udp_sendto result %x\n", SendNak_err_t); DHCPS_LOG("dhcps: send_nak>>udp_sendto result %x\n", SendNak_err_t);
#endif #endif
if (p->ref != 0) { if (p->ref != 0) {
#if DHCPS_DEBUG #if DHCPS_DEBUG
DHCPS_LOG("udhcp: send_nak>>free pbuf\n"); DHCPS_LOG("udhcp: send_nak>>free pbuf\n");
@@ -531,6 +558,7 @@ static void send_ack(struct dhcps_msg *m)
#if DHCPS_DEBUG #if DHCPS_DEBUG
DHCPS_LOG("udhcp: send_ack>>p->ref = %d\n", p->ref); DHCPS_LOG("udhcp: send_ack>>p->ref = %d\n", p->ref);
#endif #endif
if (p != NULL) { if (p != NULL) {
#if DHCPS_DEBUG #if DHCPS_DEBUG
@@ -539,16 +567,19 @@ static void send_ack(struct dhcps_msg *m)
DHCPS_LOG("dhcps: send_ack>>p->len = %d\n", p->len); DHCPS_LOG("dhcps: send_ack>>p->len = %d\n", p->len);
#endif #endif
q = p; q = p;
while (q != NULL) { while (q != NULL) {
data = (u8_t *)q->payload; data = (u8_t *)q->payload;
for(i=0; i<q->len; i++)
{ for (i = 0; i < q->len; i++) {
data[i] = ((u8_t *) m)[cnt++]; data[i] = ((u8_t *) m)[cnt++];
#if DHCPS_DEBUG #if DHCPS_DEBUG
DHCPS_LOG("%02x ", data[i]); DHCPS_LOG("%02x ", data[i]);
if ((i + 1) % 16 == 0) { if ((i + 1) % 16 == 0) {
DHCPS_LOG("\n"); DHCPS_LOG("\n");
} }
#endif #endif
} }
@@ -601,6 +632,7 @@ static u8_t parse_options(u8_t *optptr, s16_t len)
#if DHCPS_DEBUG #if DHCPS_DEBUG
DHCPS_LOG("dhcps: (s16_t)*optptr = %d\n", (s16_t)*optptr); DHCPS_LOG("dhcps: (s16_t)*optptr = %d\n", (s16_t)*optptr);
#endif #endif
switch ((s16_t) *optptr) { switch ((s16_t) *optptr) {
case DHCP_OPTION_MSG_TYPE: //53 case DHCP_OPTION_MSG_TYPE: //53
@@ -619,9 +651,10 @@ static u8_t parse_options(u8_t *optptr, s16_t len)
#endif #endif
s.state = DHCPS_STATE_NAK; s.state = DHCPS_STATE_NAK;
} }
break; break;
case DHCP_OPTION_END:
{ case DHCP_OPTION_END: {
is_dhcp_parse_end = true; is_dhcp_parse_end = true;
} }
break; break;
@@ -650,10 +683,12 @@ static u8_t parse_options(u8_t *optptr, s16_t len)
} else { } else {
s.state = DHCPS_STATE_NAK; s.state = DHCPS_STATE_NAK;
} }
#if DHCPS_DEBUG #if DHCPS_DEBUG
DHCPS_LOG("dhcps: DHCPD_STATE_NAK\n"); DHCPS_LOG("dhcps: DHCPD_STATE_NAK\n");
#endif #endif
} }
break; break;
case DHCPDECLINE://4 case DHCPDECLINE://4
@@ -670,6 +705,7 @@ static u8_t parse_options(u8_t *optptr, s16_t len)
#endif #endif
break; break;
} }
#if DHCPS_DEBUG #if DHCPS_DEBUG
DHCPS_LOG("dhcps: return s.state = %d\n", s.state); DHCPS_LOG("dhcps: return s.state = %d\n", s.state);
#endif #endif
@@ -704,10 +740,12 @@ static s16_t parse_msg(struct dhcps_msg *m, u16_t len)
if (plist != NULL) { if (plist != NULL) {
for (pback_node = plist; pback_node != NULL; pback_node = pback_node->pnext) { for (pback_node = plist; pback_node != NULL; pback_node = pback_node->pnext) {
pdhcps_pool = pback_node->pnode; pdhcps_pool = pback_node->pnode;
if (memcmp(pdhcps_pool->mac, m->chaddr, sizeof(pdhcps_pool->mac)) == 0) { if (memcmp(pdhcps_pool->mac, m->chaddr, sizeof(pdhcps_pool->mac)) == 0) {
if (memcmp(&pdhcps_pool->ip.addr, m->ciaddr, sizeof(pdhcps_pool->ip.addr)) == 0) { if (memcmp(&pdhcps_pool->ip.addr, m->ciaddr, sizeof(pdhcps_pool->ip.addr)) == 0) {
renew = true; renew = true;
} }
client_address.addr = pdhcps_pool->ip.addr; client_address.addr = pdhcps_pool->ip.addr;
pdhcps_pool->lease_timer = dhcps_lease_time; pdhcps_pool->lease_timer = dhcps_lease_time;
pnode = pback_node; pnode = pback_node;
@@ -736,6 +774,7 @@ static s16_t parse_msg(struct dhcps_msg *m, u16_t len)
if (client_address_plus.addr > dhcps_poll.end_ip.addr) { if (client_address_plus.addr > dhcps_poll.end_ip.addr) {
client_address.addr = first_address.addr; client_address.addr = first_address.addr;
} }
if (client_address.addr > dhcps_poll.end_ip.addr) { if (client_address.addr > dhcps_poll.end_ip.addr) {
client_address_plus.addr = dhcps_poll.start_ip.addr; client_address_plus.addr = dhcps_poll.start_ip.addr;
pdhcps_pool = NULL; pdhcps_pool = NULL;
@@ -753,6 +792,7 @@ static s16_t parse_msg(struct dhcps_msg *m, u16_t len)
pnode->pnode = pdhcps_pool; pnode->pnode = pdhcps_pool;
pnode->pnext = NULL; pnode->pnext = NULL;
node_insert_to_list(&plist, pnode); node_insert_to_list(&plist, pnode);
if (client_address.addr == dhcps_poll.end_ip.addr) { if (client_address.addr == dhcps_poll.end_ip.addr) {
client_address_plus.addr = dhcps_poll.start_ip.addr; client_address_plus.addr = dhcps_poll.start_ip.addr;
} else { } else {
@@ -763,6 +803,7 @@ static s16_t parse_msg(struct dhcps_msg *m, u16_t len)
} }
POOL_CHECK: POOL_CHECK:
if ((client_address.addr > dhcps_poll.end_ip.addr) || (ip4_addr_isany(&client_address))) { if ((client_address.addr > dhcps_poll.end_ip.addr) || (ip4_addr_isany(&client_address))) {
if (pnode != NULL) { if (pnode != NULL) {
node_remove_from_list(&plist, pnode); node_remove_from_list(&plist, pnode);
@@ -774,6 +815,7 @@ static s16_t parse_msg(struct dhcps_msg *m, u16_t len)
free(pdhcps_pool); free(pdhcps_pool);
pdhcps_pool = NULL; pdhcps_pool = NULL;
} }
return 4; return 4;
} }
@@ -790,6 +832,7 @@ static s16_t parse_msg(struct dhcps_msg *m, u16_t len)
free(pdhcps_pool); free(pdhcps_pool);
pdhcps_pool = NULL; pdhcps_pool = NULL;
} }
memset(&client_address, 0x0, sizeof(client_address)); memset(&client_address, 0x0, sizeof(client_address));
} }
@@ -799,6 +842,7 @@ static s16_t parse_msg(struct dhcps_msg *m, u16_t len)
#endif #endif
return ret; return ret;
} }
return 0; return 0;
} }
@@ -828,7 +872,10 @@ static void handle_dhcp(void *arg,
#if DHCPS_DEBUG #if DHCPS_DEBUG
DHCPS_LOG("dhcps: handle_dhcp-> receive a packet\n"); DHCPS_LOG("dhcps: handle_dhcp-> receive a packet\n");
#endif #endif
if (p==NULL) return;
if (p == NULL) {
return;
}
pmsg_dhcps = (struct dhcps_msg *)malloc(sizeof(struct dhcps_msg)); pmsg_dhcps = (struct dhcps_msg *)malloc(sizeof(struct dhcps_msg));
memset(pmsg_dhcps , 0x00 , sizeof(struct dhcps_msg)); memset(pmsg_dhcps , 0x00 , sizeof(struct dhcps_msg));
@@ -837,6 +884,7 @@ static void handle_dhcp(void *arg,
pbuf_free(p); pbuf_free(p);
return; return;
} }
p_dhcps_msg = (u8_t *)pmsg_dhcps; p_dhcps_msg = (u8_t *)pmsg_dhcps;
tlen = p->tot_len; tlen = p->tot_len;
data = p->payload; data = p->payload;
@@ -850,9 +898,11 @@ static void handle_dhcp(void *arg,
p_dhcps_msg[dhcps_msg_cnt++] = data[i]; p_dhcps_msg[dhcps_msg_cnt++] = data[i];
#if DHCPS_DEBUG #if DHCPS_DEBUG
DHCPS_LOG("%02x ", data[i]); DHCPS_LOG("%02x ", data[i]);
if ((i + 1) % 16 == 0) { if ((i + 1) % 16 == 0) {
DHCPS_LOG("\n"); DHCPS_LOG("\n");
} }
#endif #endif
} }
@@ -864,13 +914,16 @@ static void handle_dhcp(void *arg,
#endif #endif
data = p->next->payload; data = p->next->payload;
for (i = 0; i < p->next->len; i++) { for (i = 0; i < p->next->len; i++) {
p_dhcps_msg[dhcps_msg_cnt++] = data[i]; p_dhcps_msg[dhcps_msg_cnt++] = data[i];
#if DHCPS_DEBUG #if DHCPS_DEBUG
DHCPS_LOG("%02x ", data[i]); DHCPS_LOG("%02x ", data[i]);
if ((i + 1) % 16 == 0) { if ((i + 1) % 16 == 0) {
DHCPS_LOG("\n"); DHCPS_LOG("\n");
} }
#endif #endif
} }
} }
@@ -886,21 +939,25 @@ static void handle_dhcp(void *arg,
#endif #endif
send_offer(pmsg_dhcps); send_offer(pmsg_dhcps);
break; break;
case DHCPS_STATE_ACK://3 case DHCPS_STATE_ACK://3
#if DHCPS_DEBUG #if DHCPS_DEBUG
DHCPS_LOG("dhcps: handle_dhcp-> DHCPD_STATE_ACK\n"); DHCPS_LOG("dhcps: handle_dhcp-> DHCPD_STATE_ACK\n");
#endif #endif
send_ack(pmsg_dhcps); send_ack(pmsg_dhcps);
break; break;
case DHCPS_STATE_NAK://4 case DHCPS_STATE_NAK://4
#if DHCPS_DEBUG #if DHCPS_DEBUG
DHCPS_LOG("dhcps: handle_dhcp-> DHCPD_STATE_NAK\n"); DHCPS_LOG("dhcps: handle_dhcp-> DHCPD_STATE_NAK\n");
#endif #endif
send_nak(pmsg_dhcps); send_nak(pmsg_dhcps);
break; break;
default : default :
break; break;
} }
#if DHCPS_DEBUG #if DHCPS_DEBUG
DHCPS_LOG("dhcps: handle_dhcp-> pbuf_free(p)\n"); DHCPS_LOG("dhcps: handle_dhcp-> pbuf_free(p)\n");
#endif #endif
@@ -920,16 +977,19 @@ static void dhcps_poll_set(u32_t ip)
u32_t softap_ip = 0, local_ip = 0; u32_t softap_ip = 0, local_ip = 0;
u32_t start_ip = 0; u32_t start_ip = 0;
u32_t end_ip = 0; u32_t end_ip = 0;
if (dhcps_poll.enable == true) { if (dhcps_poll.enable == true) {
softap_ip = htonl(ip); softap_ip = htonl(ip);
start_ip = htonl(dhcps_poll.start_ip.addr); start_ip = htonl(dhcps_poll.start_ip.addr);
end_ip = htonl(dhcps_poll.end_ip.addr); end_ip = htonl(dhcps_poll.end_ip.addr);
/*config ip information can't contain local ip*/ /*config ip information can't contain local ip*/
if ((start_ip <= softap_ip) && (softap_ip <= end_ip)) { if ((start_ip <= softap_ip) && (softap_ip <= end_ip)) {
dhcps_poll.enable = false; dhcps_poll.enable = false;
} else { } else {
/*config ip information must be in the same segment as the local ip*/ /*config ip information must be in the same segment as the local ip*/
softap_ip >>= 8; softap_ip >>= 8;
if (((start_ip >> 8 != softap_ip) || (end_ip >> 8 != softap_ip)) if (((start_ip >> 8 != softap_ip) || (end_ip >> 8 != softap_ip))
|| (end_ip - start_ip > DHCPS_MAX_LEASE)) { || (end_ip - start_ip > DHCPS_MAX_LEASE)) {
dhcps_poll.enable = false; dhcps_poll.enable = false;
@@ -941,10 +1001,12 @@ static void dhcps_poll_set(u32_t ip)
local_ip = softap_ip = htonl(ip); local_ip = softap_ip = htonl(ip);
softap_ip &= 0xFFFFFF00; softap_ip &= 0xFFFFFF00;
local_ip &= 0xFF; local_ip &= 0xFF;
if (local_ip >= 0x80)
if (local_ip >= 0x80) {
local_ip -= DHCPS_MAX_LEASE; local_ip -= DHCPS_MAX_LEASE;
else } else {
local_ip ++; local_ip ++;
}
bzero(&dhcps_poll, sizeof(dhcps_poll)); bzero(&dhcps_poll, sizeof(dhcps_poll));
dhcps_poll.start_ip.addr = softap_ip | local_ip; dhcps_poll.start_ip.addr = softap_ip | local_ip;
@@ -970,10 +1032,13 @@ void dhcps_start(struct netif *netif, struct ip_info *info)
if (apnetif->dhcps_pcb != NULL) { if (apnetif->dhcps_pcb != NULL) {
udp_remove(apnetif->dhcps_pcb); udp_remove(apnetif->dhcps_pcb);
} }
pcb_dhcps = udp_new(); pcb_dhcps = udp_new();
if (pcb_dhcps == NULL || info == NULL) { if (pcb_dhcps == NULL || info == NULL) {
printf("dhcps_start(): could not obtain pcb\n"); printf("dhcps_start(): could not obtain pcb\n");
} }
apnetif->dhcps_pcb = pcb_dhcps; apnetif->dhcps_pcb = pcb_dhcps;
IP4_ADDR(&broadcast_dhcps, 255, 255, 255, 255); IP4_ADDR(&broadcast_dhcps, 255, 255, 255, 255);
@@ -1000,11 +1065,12 @@ void dhcps_start(struct netif *netif, struct ip_info *info)
void dhcps_stop(struct netif *netif) void dhcps_stop(struct netif *netif)
{ {
struct netif *apnetif = netif; struct netif *apnetif = netif;
if(apnetif == NULL)
{ if (apnetif == NULL) {
printf("dhcps_stop: apnetif == NULL\n"); printf("dhcps_stop: apnetif == NULL\n");
return; return;
} }
udp_disconnect(pcb_dhcps); udp_disconnect(pcb_dhcps);
if (apnetif->dhcps_pcb != NULL) { if (apnetif->dhcps_pcb != NULL) {
@@ -1015,6 +1081,7 @@ void dhcps_stop(struct netif *netif )
list_node *pnode = NULL; list_node *pnode = NULL;
list_node *pback_node = NULL; list_node *pback_node = NULL;
pnode = plist; pnode = plist;
while (pnode != NULL) { while (pnode != NULL) {
pback_node = pnode; pback_node = pnode;
pnode = pback_node->pnext; pnode = pback_node->pnext;
@@ -1041,16 +1108,20 @@ static void kill_oldest_dhcps_pool(void)
p = pre->pnext; p = pre->pnext;
minpre = pre; minpre = pre;
minp = p; minp = p;
while (p != NULL) { while (p != NULL) {
pdhcps_pool = p->pnode; pdhcps_pool = p->pnode;
pmin_pool = minp->pnode; pmin_pool = minp->pnode;
if (pdhcps_pool->lease_timer < pmin_pool->lease_timer) { if (pdhcps_pool->lease_timer < pmin_pool->lease_timer) {
minp = p; minp = p;
minpre = pre; minpre = pre;
} }
pre = p; pre = p;
p = p->pnext; p = p->pnext;
} }
minpre->pnext = minp->pnext; minpre->pnext = minp->pnext;
free(minp->pnode); free(minp->pnode);
minp->pnode = NULL; minp->pnode = NULL;
@@ -1071,9 +1142,11 @@ void dhcps_coarse_tmr(void)
list_node *pnode = NULL; list_node *pnode = NULL;
struct dhcps_pool *pdhcps_pool = NULL; struct dhcps_pool *pdhcps_pool = NULL;
pnode = plist; pnode = plist;
while (pnode != NULL) { while (pnode != NULL) {
pdhcps_pool = pnode->pnode; pdhcps_pool = pnode->pnode;
pdhcps_pool->lease_timer --; pdhcps_pool->lease_timer --;
if (pdhcps_pool->lease_timer == 0) { if (pdhcps_pool->lease_timer == 0) {
pback_node = pnode; pback_node = pnode;
pnode = pback_node->pnext; pnode = pback_node->pnext;
@@ -1088,9 +1161,10 @@ void dhcps_coarse_tmr(void)
} }
} }
if (num_dhcps_pool >= MAX_STATION_NUM) if (num_dhcps_pool >= MAX_STATION_NUM) {
kill_oldest_dhcps_pool(); kill_oldest_dhcps_pool();
} }
}
/****************************************************************************** /******************************************************************************
* FunctionName : dhcp_search_ip_on_mac * FunctionName : dhcp_search_ip_on_mac
@@ -1107,6 +1181,7 @@ bool dhcp_search_ip_on_mac(u8_t *mac, ip4_addr_t *ip)
for (pback_node = plist; pback_node != NULL; pback_node = pback_node->pnext) { for (pback_node = plist; pback_node != NULL; pback_node = pback_node->pnext) {
pdhcps_pool = pback_node->pnode; pdhcps_pool = pback_node->pnode;
if (memcmp(pdhcps_pool->mac, mac, sizeof(pdhcps_pool->mac)) == 0) { if (memcmp(pdhcps_pool->mac, mac, sizeof(pdhcps_pool->mac)) == 0) {
memcpy(&ip->addr, &pdhcps_pool->ip.addr, sizeof(pdhcps_pool->ip.addr)); memcpy(&ip->addr, &pdhcps_pool->ip.addr, sizeof(pdhcps_pool->ip.addr));
ret = true; ret = true;