[klibc] ciaddr in dhcp_proto.c

Shou-Lien Chen driftheart at gmail.com
Wed Mar 11 19:36:46 PDT 2009


Hi, hpa:

Thanks for your reply.
I am also new to DHCP protocol.

I've find a dhcp code of dhcp3-client by "apt-get source dhcp3-client"
under Ubuntu.
under the root of source dir, client/dhclient.c
There is a piece of code in make_request() function:

	/* If we own the address we're requesting, put it in ciaddr;
	   otherwise set ciaddr to zero. */
	if (client -> state == S_BOUND ||
	    client -> state == S_RENEWING ||
	    client -> state == S_REBINDING) {
		memcpy (&client -> packet.ciaddr,
			lease -> address.iabuf, lease -> address.len);
		client -> packet.flags = 0;
	} else {
		memset (&client -> packet.ciaddr, 0,
			sizeof client -> packet.ciaddr);
		if (can_receive_unicast_unconfigured (client -> interface))
			client -> packet.flags = 0;
		else
			client -> packet.flags = htons (BOOTP_BROADCAST);
	}

and the lease variable uses the structure "client_lease" in the
beginning of make_request()

/* DHCP client lease structure... */
struct client_lease {
	struct client_lease *next;		      /* Next lease in list. */
	TIME expiry, renewal, rebind;			  /* Lease timeouts. */
	struct iaddr address;			    /* Address being leased. */
	char *server_name;			     /* Name of boot server. */
	char *filename;		     /* Name of file we're supposed to boot. */
	struct string_list *medium;			  /* Network medium. */
	struct auth_key *key;      /* Key used in basic DHCP authentication. */

	unsigned int is_static : 1;    /* If set, lease is from config file. */
	unsigned int is_bootp: 1;  /* If set, lease was acquired with BOOTP. */

	struct option_state *options;	     /* Options supplied with lease. */
};

In RFC 2131, page 34, Figure 5:  State-transition diagram for DHCP clients:
http://www.ietf.org/rfc/rfc2131.txt  (search "Figure 5:
State-transition diagram for DHCP clients")

BOUND seems mean that the device have finish a dhcp transaction and
own an ip address.
RENEWING and REBINDING is used after BOUND state. When the T1, and T2
expired, go to REWING and REBINDING state.
T1 and T2 are got during the transaction that make state to BOUND.

If we are using ipconfig in initrd image, the ipconfig is the first
program dealing with ip address of network card.
And the network card will not have a ip addr since we are booting a machine.
So we are not in BOUND, RENEWING and REBINDING state and seems we
safely can set ciaddr to 0.


PS. If booting via PXE, the bios will also make a DHCP transaction to
DHCP server, I am not sure if the ip address requested in PXE boot
will still remembered in network card when ipconfig is excuted.





2009/3/12 H. Peter Anvin <hpa at zytor.com>:
> Shou-Lien Chen wrote:
>> Hello all:
>>
>> According to rfc 2131, page 9:
>> "ciaddr        Client IP address; only filled in if client is in
>>                   BOUND, RENEW or REBINDING state and can respond
>>                   to ARP requests.
>> "
>>
>> Is it ideal to change "boot.ciaddr = dev-> ip_addr" to "boot.ciaddr =
>> INADDR_ANY" in dhcp_send() function?
>>
>> I've used a TP-LINK TL-R402M router and it will give a DHCPNAK if
>> ciaddr is not empty.
>>
>
> Makes sense to me, but I'm not a DHCP expert.  Anyone who has more insight?
>
>        -hpa
>
> --
> H. Peter Anvin, Intel Open Source Technology Center
> I work for Intel.  I don't speak on their behalf.
>
>



More information about the klibc mailing list