An interesting piece of code in Discover_interfaces
Ned Rhodes
dhcp at softsysgrp.com
Thu Jun 20 21:14:05 UTC 2002
I am porting the dhcp server to an embedded system based on a Motorola 8260
PowerPC. Since I dont have a unix environment, I am having to step through
code to figure out what I need to change/add so that it will work with my
box. I am currently on the hunt to get it to recognize my three Ethernet
interfaces so I can receive dhcp requests.
So, I am currently exploring the routine discover_interfaces in discover.c
(1.1.2.1 2002/05/20). One of my experiments was to set the
INTERFACES_RUNNING flag thinking that would help the process of figuring
what interface the server should be using. A search of the code does not
reveal that that flag is ever really used and it is not clear to me how an
interface would actually set that flag.
But, I did discover that if that flag is set in the loop below, you remain
in an infinite loop in the while(tmp) block. This, I believe, is due to the
continue statement that goes to the end of the loop and is supposed to look
for the next thing on the link list. Problem is that the code never gets the
next thing on the list, you remain on the current thing and never leave.
while (tmp) {
if (next)
interface_dereference (&next, MDL);
if (tmp -> next)
interface_reference (&next, tmp -> next, MDL);
/* skip interfaces that are running already */
if (tmp -> flags & INTERFACE_RUNNING)
continue;
if ((tmp -> flags & INTERFACE_AUTOMATIC) &&
state == DISCOVER_REQUESTED)
tmp -> flags &= ~(INTERFACE_AUTOMATIC |
INTERFACE_REQUESTED);
I believe the fix is to either replace the continue; with a goto next; or
interface_dereference (&tmp, MDL);
if (next)
interface_reference (&tmp, next, MDL);
and then the continue;
I think this never comes up as the INTERFACE_RUNNING flag is never set.
So, other than a possible bug, what is the purpose of the INTERFACE_RUNNING
flag? And what is the purpose of checking for that flag being set (may be
the same question).
More information about the dhcp-hackers
mailing list