My modifications
Lennart Hellström (ERA)
Lennart.Hellstrom at era.ericsson.se
Fri Aug 27 11:12:56 UTC 1999
Good morning!
It feels like I'm actually getting somewhere with my modifications.
I still am a bit uncertain about a few (a lot) of things, which I have commented in the code
below. Do you think you have time to check if my code looks ok, just to make sure that I won't
mess anything up, please?
< To enable subnet selection. In dispatch.c>
int locate_network (packet)
struct packet *packet;
{
struct iaddr ia;
/* SMIP PATCH */
/* If the packet contains a subnet-selection-option, give an address from that net */
/* Look for subnet_selection option */
struct option_cache *oc;
struct data_string data;
oc = lookup_option (&dhcp_universe, packet -> options,
DHO_SUBNET_SELECTION);
memset (&data, 0, sizeof data);
if (oc &&
evaluate_option_cache (&data, packet, (struct lease *)0,
packet -> options, (struct option_state *)0,
oc))
{
struct subnet *subnet;
ia.len = 4;
memcpy (ia.iabuf, data.data, 4);
// data_string_forget (&data, "dhcprequest"); /* What shall I forget? */
subnet = find_subnet (ia);
if (subnet)
packet -> shared_network = subnet -> shared_network;
}
else{
/* END SMIP PATCH */
/* If this came through a gateway, find the corresponding subnet... */
if (packet -> raw -> giaddr.s_addr) {
struct subnet *subnet;
ia.len = 4;
memcpy (ia.iabuf, &packet -> raw -> giaddr, 4);
subnet = find_subnet (ia);
if (subnet)
packet -> shared_network = subnet -> shared_network;
else
packet -> shared_network = (struct shared_network *)0;
} else {
packet -> shared_network =
packet -> interface -> shared_network;
}
/* SMIP PATCH */
}
/* END SMIP PATCH */
< To send DHCP release. To be included in some file or in an own file >
/* release_addr
* Releases an IP address
*
* Arguments:
* struct iaddr ip_addr: the IP-address to release
*
* Returns:
* 0 on success
* 1 if ip_addr not hold by client
*
* Side effects:
* Destroys the corresonding lease
*/
void release_addr (ip_addr)
struct iaddr;
{
struct interface_info *ip;
struct client_lease *lp;
for (ip = interfaces; ip; ip = ip -> next) {
/* switch taken from client_reinit() handed through Ted.*/
/* What does it do, and is it complete? */
switch (ip -> client -> state) {
case S_SELECTING:
cancel_timeout (send_discover, ip);
break;
case S_BOUND:
cancel_timeout (state_bound, ip);
break;
case S_REBOOTING:
case S_REQUESTING:
case S_RENEWING:
cancel_timeout (send_request, ip);
break;
case S_INIT:
case S_REBINDING:
break;
}
/* scan all leases for a matching address */
for (lp = ip -> client -> leases; lp; lp = lp -> next)
{
if (lp -> address.len == ip_addr.len &&
!memcmp (lp -> address.iabuf, ip_addr.iabuf,
ip_addr.len))
{
if (ip -> client -> active) /* This lease is active */
{ /* Expire the lease after relase*/
make_release (ip, lp);
send_release (ip);
ip -> client -> active -> expiry = cur_time;
write_client_lease (ip, ip -> client -> active, 0);
}
/* In SMIP the unconfiguration of the lease is already done by the main process so don't do it here. */
/* The lease is not active. Send release */
/* When is a lease active and when isn't it? */
else {
make_release (ip, lp);
send_release (ip);
}
/* A lease was found and released. Now destroy that lease */
destroy_client_lease (lp);
return 0;
}
}
}
return 1; /* No matching leases found */
}
< To renew addresses. To be included in some file or in an own file >
/* client_reinit
* Renews the addresses or discovers new ones if the lease was expired.
*
* Argument:
* none
*
* Returns:
* nothing
* Side effects:
*
*/
/* Ths function feels a bit thin... It seems as if every old leases will trig
* a state_init() and that feels dangerous. */
void client_renew ()
{
struct interface_info *ip;
/* cycle through all interfaces and try to renew the addresses */
for (ip = interfaces; ip; ip = ip -> next)
{
if (ip -> client -> active)
{
/* if the lease hasn't expired just call state_bound() */
ip -> client -> state = S_BOUND;
state_bound (ip);
}
else
{
/* if the lease has expired we must(?) call state_init () */
/* doesn't this mean that all the old leases will trig this? */
ip -> client -> state = S_INIT;
state_init (ip);
}
}
}
That's all ;-)
/ Lelle
----------------------<<<<<<¤¤¤¤¤¤¤¤¤¤¤¤>>>>>>------------------------------------
Lennart Hellström ERA/KA/TA email: Lennart.Hellstrom at era.ericsson.se
Ericsson Radio Systems AB tel: +46 (0)8-585 347 81
SE-164 80 Stockholm mobile: +46 (0)70-432 64 27
Sweden
More information about the dhcp-hackers
mailing list