My modifications v.3
Lennart Hellström (ERA)
Lennart.Hellstrom at era.ericsson.se
Fri Sep 3 14:50:57 UTC 1999
Hi again,
I hope you haven't had time to look at my last code, since I found some bugs and error
in it just recently... :-}
Please have a look at this code instead, which compiles without errors. The question is
wheter it will work or not... I hope you can refer to your earlier comments (in my last request
for reviewing) on what should be corrected. (I think those parts really are corrected, but I wouldn't bet money on it)
Thanx for your help!
*******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, packet -> options,
(struct lease *)0, oc))
{
struct subnet *subnet;
ia.len = 4;
memcpy (ia.iabuf, data.data, 4);
data_string_forget (&data, "dhcprequest"); /* Otherwise we have a memory leak */
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 */
if (packet -> shared_network)
return 1;
return 0;
}
*****smipadds.c**********
/* release_addr
* Releases an IP address after a new one is aquired
*
* Arguments:
* struct iaddr ip_addr: the IP-address to release
*
* Returns:
* 1 on success (DHCP standard!)
* 0 if ip_addr not hold by client
*
* Side effects:
* Rewrites the corresonding lease
*/
int release_addr (struct iaddr ip_addr)
// struct iaddr;
{
struct interface_info *ip;
struct client_lease *lp;
struct client_state *sp;
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 (sp = ip -> client; sp; sp = sp -> next) {
lp = (struct client_lease *)0;
for (lp = sp -> leases; lp; lp = lp -> next) {
if (lp -> address.len == ip_addr.len &&
!memcmp (lp -> address.iabuf, ip_addr.iabuf,
ip_addr.len))
{
if (lp -> expiry > cur_time ) { /* The lease has not
expired*/
make_release (sp, lp);
send_release (ip);
write_client_lease (sp, lp, 0);
/* below is copied
from clparse.c
if (pl)
pl -> next = lp -> next;
else
client -> leases = lp -> next;
destroy_client_lease (lp);
/* Would this make anything better? */
return 1;
}
}
}
}
}
return 0; /* No matching leases found */
}
/* client_renew
* Renews the addresses or discovers new ones if
* the leases were expired.
*
* Argument:
* none
*
* Returns:
* 0 if a valid lease was found => state_bound
* 1 if no valid leases found => state_init
*
* Side effects:
*
*/
void client_renew ()
{
struct interface_info *ip;
struct client_state *sp;
/* cycle through all interfaces and try to renew the addresses */
for (ip = interfaces; ip; ip = ip -> next) {
for (sp = ip -> client; sp; sp = sp -> next) {
if (sp -> active && sp -> active -> expiry > cur_time) {
/* active lease still valid => state_bound */
ip -> client -> state = S_BOUND;
state_bound (sp);
}
else if (sp -> active && sp -> active -> expiry <= cur_time) {
/* if the lease has expired we must call state_init () */
ip -> client -> state = S_INIT;
state_init (sp);
}
}
}
}
/* discover_addr
* Sends a discovery on the physical interface
*
* Arguments:
*
* Returns:
* 1 on success (DHCP standard)
* 0 on failure
*
* Side effects:
* Release the old address or expire the old lease?
*
*/
int discover_addr ()
{
struct interface_info *ip;
struct client_state *sp;
for (ip = interfaces; ip; ip = ip -> next) {
if (ip -> name == "physical") { /*given that the physical interface was given this name
ip -> client -> state = S_INIT;
state_init (sp);
return 1; }}
return 0;
}
/* END SMIP PATCH */
/ 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