|
From: | Benjamin Schelte |
Subject: | RE: [lwip-users] How to securely switch between DHCP and static IP assignment? |
Date: | Fri, 23 Jul 2010 08:53:07 +0200 |
Thank you for your
advice. I will take it into account in my implementation. Benjamin From: address@hidden
[mailto:address@hidden On Behalf Of
Bill Auerbach I have to do the same
thing as you, as well as be able to switch from DHCP to static (or back) with
an Ethernet cable change. I also needed to support optional AutoIP or
fallback to static. It’s all possible and quite reliable. You need to add:
netif_set_down( &sNetif ); after: dhcp_stop(&sNetif); Otherwise your code is exactly like mine
(for switching from DHCP to static that is). Bill From:
address@hidden [mailto:address@hidden
On Behalf Of Benjamin Schelte Hallo all, I am having trouble to securely switch
between DHCP and static IP assignment. The way I am doing this at the moment is
sometimes leading to an assert (please read further). So far I am quite satisfied with the
lwip-stack and its performance, but this problem gives me a headache. Description: My environment needs to be able to switch
between static IP and DHCP during runtime. This should be possible at any point
in time (although once configured it will most likely stay the same…). Info: I am using a Realtime OS. So after initialization either with DHCP or
static IP address assignment I use two functions to switch between those 2
modes. Both functions are called out of a user
menu. The code looks like the following: int iEthCtrl_UseStaticIP(unsigned long ulIPAddress,
unsigned long
ulIPGateway, unsigned long
ulIPSubnetMask) {
struct ip_addr xIpAddr, xNetMask, xGateway;
// Check, if the network connection is up and DHCP is activated
if ((sNetif.flags
& NETIF_FLAG_UP) && (sNetif.flags
& NETIF_FLAG_DHCP)) {
// Release the DHCP lease (it already calls netif_set_down()
function)
dhcp_release(&sNetif);
// Stop the dhcp service
dhcp_stop(&sNetif);
xIpAddr.addr = ulIPAddress;
xGateway.addr = ulIPGateway;
xNetMask.addr = ulIPSubnetMask;
// Set the new ip address
netif_set_addr(&sNetif, &xIpAddr, &xNetMask,
&xGateway);
// Bring the interface up again
netif_set_up(&sNetif);
} ... } int iEthCtrl_UseDHCP(void) {
struct ip_addr xIpAddr, xNetMask, xGateway;
IP4_ADDR(&xIpAddr, 0, 0, 0, 0);
IP4_ADDR(&xNetMask, 0, 0, 0, 0);
IP4_ADDR(&xGateway, 0, 0, 0, 0);
// Check, if the network connection is up and DHCP is NOT
activated
if ((sNetif.flags
& NETIF_FLAG_UP) && !(sNetif.flags
& NETIF_FLAG_DHCP)) {
// Bring the current interface down
netif_set_down(&sNetif);
// Set the IP addresses to "0.0.0.0" so the DHCP
server can send a reply.
// Otherwise the previous static IP might be out of the network
class of the DHCP server
netif_set_addr(&sNetif, &xIpAddr, &xNetMask,
&xGateway);
// Start DHCP negotiation
if (sNetif.dhcp ==
NULL) {
dhcp_start(&sNetif);
}
else {
dhcp_network_changed(&sNetif);
} ...
} ... } Furthermore I am using a callback function
to read the (cable) link status from the PHY every 500ms: static void vPrvEthCtrl_CheckLinkStatusCallback(void*
pvParams) {
volatile avr32_macb_t
*macb = &AVR32_MACB;
unsigned long
ulStatusReg;
ulStatusReg = ulReadMDIO(macb, PHY_BMSR); //
Can be blocking!
if (ulStatusReg & BMSR_LSTATUS) {
// If the cable was disconnected previously we set the link up
again
if (bLinkStatus ==
FALSE) {
netif_set_link_up(&sNetif);
}
bLinkStatus = TRUE;
}
else {
if (bLinkStatus ==
TRUE) {
netif_set_link_down(&sNetif);
netif_set_down(&sNetif);
}
bLinkStatus = FALSE; } } So the problem occurs after calling the
function iEthCtrl_UseDHCP(). After doing so it sometimes happens to stop
executing on an assert in dhcp_create_request(). Assert: LWIP_ASSERT("dhcp_create_request:
dhcp->p_out == NULL", dhcp->p_out == NULL); Callstack: dhcp_create_request dhcp_select dhcp_handle_offer dhcp_recv udp_input ip_input ethernet_input tcpip_thread So my questions are the following. Why is a DHCP-request forwarded to the
DHCP-handler, although dhcp_stop() has been called before? Is the way I switch from static IP to DHCP
and vice versa correct? Any comment or advice is appreciated. Thanks in advance! Best regards, Benjamin Schelte |
[Prev in Thread] | Current Thread | [Next in Thread] |