[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [lwip-users] How to securely switch between DHCP and static IP assi
From: |
Martin Velek |
Subject: |
Re: [lwip-users] How to securely switch between DHCP and static IP assignment? |
Date: |
Fri, 23 Jul 2010 08:43:20 +0200 |
Hi,
if you are running RTOS, I think that your functions are not called
from tcp_ip thread, you should switch your netif* functions to these
as stated Simon:
#define netifapi_netif_remove(n) netifapi_netif_common(n,
netif_remove, NULL)
#define netifapi_netif_set_up(n) netifapi_netif_common(n,
netif_set_up, NULL)
#define netifapi_netif_set_down(n) netifapi_netif_common(n,
netif_set_down, NULL)
#define netifapi_netif_set_default(n) netifapi_netif_common(n,
netif_set_default, NULL)
#define netifapi_dhcp_start(n) netifapi_netif_common(n, NULL, dhcp_start)
#define netifapi_dhcp_stop(n) netifapi_netif_common(n, dhcp_stop, NULL)
#define netifapi_autoip_start(n) netifapi_netif_common(n, NULL,
autoip_start)
#define netifapi_autoip_stop(n) netifapi_netif_common(n, NULL,
autoip_stop)
in lwip 1.3.2 defined in netifapi.h
Martin
On 22 July 2010 17:07, Benjamin Schelte <address@hidden> wrote:
> 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
>
>
>
> _______________________________________________
> lwip-users mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/lwip-users
>
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: [lwip-users] How to securely switch between DHCP and static IP assignment?,
Martin Velek <=