@@ -126,7 +126,7 @@ struct dhcps_t {
126
126
struct netif * dhcps_netif ;
127
127
ip4_addr_t broadcast_dhcps ;
128
128
ip4_addr_t server_address ;
129
- ip4_addr_t dns_server ;
129
+ ip4_addr_t dns_server [ DNS_TYPE_MAX ] ;
130
130
ip4_addr_t client_address ;
131
131
ip4_addr_t client_address_plus ;
132
132
ip4_addr_t dhcps_mask ;
@@ -155,7 +155,11 @@ dhcps_t *dhcps_new(void)
155
155
return NULL ;
156
156
}
157
157
dhcps -> dhcps_netif = NULL ;
158
- dhcps -> dns_server .addr = 0 ;
158
+
159
+ for (int i = 0 ; i < DNS_TYPE_MAX ; i ++ )
160
+ {
161
+ dhcps -> dns_server [i ].addr = 0 ;
162
+ }
159
163
#ifdef USE_CLASS_B_NET
160
164
dhcps -> dhcps_mask .addr = PP_HTONL (LWIP_MAKEU32 (255 , 240 , 0 , 0 ));
161
165
#else
@@ -454,16 +458,31 @@ static u8_t *add_offer_options(dhcps_t *dhcps, u8_t *optptr)
454
458
}
455
459
}
456
460
461
+ // In order of preference
462
+ * optptr ++ = DHCP_OPTION_DNS_SERVER ;
457
463
if (dhcps_dns_enabled (dhcps -> dhcps_dns )) {
458
- * optptr ++ = DHCP_OPTION_DNS_SERVER ;
459
- * optptr ++ = 4 ;
460
- * optptr ++ = ip4_addr1 (& dhcps -> dns_server );
461
- * optptr ++ = ip4_addr2 (& dhcps -> dns_server );
462
- * optptr ++ = ip4_addr3 (& dhcps -> dns_server );
463
- * optptr ++ = ip4_addr4 (& dhcps -> dns_server );
464
+ uint8_t size = 4 ;
465
+
466
+ if (dhcps -> dns_server [DNS_TYPE_BACKUP ].addr )
467
+ {
468
+ size += 4 ;
469
+ }
470
+ * optptr ++ = size ;
471
+
472
+ * optptr ++ = ip4_addr1 (& dhcps -> dns_server [DNS_TYPE_MAIN ]);
473
+ * optptr ++ = ip4_addr2 (& dhcps -> dns_server [DNS_TYPE_MAIN ]);
474
+ * optptr ++ = ip4_addr3 (& dhcps -> dns_server [DNS_TYPE_MAIN ]);
475
+ * optptr ++ = ip4_addr4 (& dhcps -> dns_server [DNS_TYPE_MAIN ]);
476
+
477
+ if (dhcps -> dns_server [DNS_TYPE_BACKUP ].addr )
478
+ {
479
+ * optptr ++ = ip4_addr1 (& dhcps -> dns_server [DNS_TYPE_BACKUP ]);
480
+ * optptr ++ = ip4_addr2 (& dhcps -> dns_server [DNS_TYPE_BACKUP ]);
481
+ * optptr ++ = ip4_addr3 (& dhcps -> dns_server [DNS_TYPE_BACKUP ]);
482
+ * optptr ++ = ip4_addr4 (& dhcps -> dns_server [DNS_TYPE_BACKUP ]);
483
+ }
464
484
#ifdef CONFIG_LWIP_DHCPS_ADD_DNS
465
485
}else {
466
- * optptr ++ = DHCP_OPTION_DNS_SERVER ;
467
486
* optptr ++ = 4 ;
468
487
* optptr ++ = ip4_addr1 (& ipadd );
469
488
* optptr ++ = ip4_addr2 (& ipadd );
@@ -1535,31 +1554,33 @@ bool dhcp_search_ip_on_mac(dhcps_t *dhcps, u8_t *mac, ip4_addr_t *ip)
1535
1554
* FunctionName : dhcps_dns_setserver
1536
1555
* Description : set DNS server address for dhcpserver
1537
1556
* Parameters : dnsserver -- The DNS server address
1557
+ * type -- The DNS type
1538
1558
* Returns : ERR_ARG if invalid handle, ERR_OK on success
1539
1559
*******************************************************************************/
1540
- err_t dhcps_dns_setserver (dhcps_t * dhcps , const ip_addr_t * dnsserver )
1560
+ err_t dhcps_dns_setserver (dhcps_t * dhcps , const ip_addr_t * dnsserver , dns_type_t type )
1541
1561
{
1542
1562
if (dhcps == NULL ) {
1543
1563
return ERR_ARG ;
1544
1564
}
1545
1565
if (dnsserver != NULL ) {
1546
- dhcps -> dns_server = * (ip_2_ip4 (dnsserver ));
1566
+ dhcps -> dns_server [ type ] = * (ip_2_ip4 (dnsserver ));
1547
1567
} else {
1548
- dhcps -> dns_server = * (ip_2_ip4 (IP_ADDR_ANY ));
1568
+ dhcps -> dns_server [ type ] = * (ip_2_ip4 (IP_ADDR_ANY ));
1549
1569
}
1550
1570
return ERR_OK ;
1551
1571
}
1552
1572
1553
1573
/******************************************************************************
1554
1574
* FunctionName : dhcps_dns_getserver
1555
1575
* Description : get DNS server address for dhcpserver
1556
- * Parameters : none
1557
- * Returns : ip4_addr_t
1576
+ * Parameters : dnsserver -- The DNS server address
1577
+ * type -- The DNS type
1578
+ * Returns : ERR_ARG if invalid handle, ERR_OK on success
1558
1579
*******************************************************************************/
1559
- err_t dhcps_dns_getserver (dhcps_t * dhcps , ip4_addr_t * dnsserver )
1580
+ err_t dhcps_dns_getserver (dhcps_t * dhcps , ip4_addr_t * dnsserver , dns_type_t type )
1560
1581
{
1561
1582
if (dhcps ) {
1562
- * dnsserver = dhcps -> dns_server ;
1583
+ * dnsserver = dhcps -> dns_server [ type ] ;
1563
1584
return ERR_OK ;
1564
1585
}
1565
1586
return ERR_ARG ;
0 commit comments