Author: cgutman
Date: Sat Jul 11 01:32:02 2009
New Revision: 41852
URL:
http://svn.reactos.org/svn/reactos?rev=41852&view=rev
Log:
- Fix more global variable abuse
- Fix some inaccurate cur_time values
Modified:
trunk/reactos/base/services/dhcp/dhclient.c
trunk/reactos/base/services/dhcp/dispatch.c
trunk/reactos/base/services/dhcp/include/rosdhcp.h
Modified: trunk/reactos/base/services/dhcp/dhclient.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/services/dhcp/dhclien…
==============================================================================
--- trunk/reactos/base/services/dhcp/dhclient.c [iso-8859-1] (original)
+++ trunk/reactos/base/services/dhcp/dhclient.c [iso-8859-1] Sat Jul 11 01:32:02 2009
@@ -72,8 +72,6 @@
#define domainchar(c) ((c) > 0x20 && (c) < 0x7f)
unsigned long debug_trace_level = 0; /* DEBUG_ULTRA */
-time_t cur_time;
-time_t default_lease_time = 43200; /* 12 hours... */
char *path_dhclient_conf = _PATH_DHCLIENT_CONF;
char *path_dhclient_db = NULL;
@@ -85,7 +83,6 @@
struct iaddr iaddr_broadcast = { 4, { 255, 255, 255, 255 } };
struct in_addr inaddr_any;
struct sockaddr_in sockaddr_broadcast;
-unsigned long old_default_route = 0;
/*
* ASSERT_STATE() does nothing now; it used to be
@@ -139,7 +136,6 @@
PipeInit();
tzset();
- time(&cur_time);
memset(&sockaddr_broadcast, 0, sizeof(sockaddr_broadcast));
sockaddr_broadcast.sin_family = AF_INET;
@@ -249,7 +245,7 @@
flags. */
make_request(ip, ip->client->active);
ip->client->destination = iaddr_broadcast;
- ip->client->first_sending = cur_time;
+ time(&ip->client->first_sending);
ip->client->interval = ip->client->config->initial_interval;
/* Zap the medium list... */
@@ -276,7 +272,7 @@
ip->client->xid = ip->client->packet.xid;
ip->client->destination = iaddr_broadcast;
ip->client->state = S_SELECTING;
- ip->client->first_sending = cur_time;
+ time(&ip->client->first_sending);
ip->client->interval = ip->client->config->initial_interval;
/* Add an immediate timeout to cause the first DHCPDISCOVER packet
@@ -293,8 +289,11 @@
{
struct interface_info *ip = ipp;
struct client_lease *lp, *next, *picked;
+ time_t cur_time;
ASSERT_STATE(state, S_SELECTING);
+
+ time(&cur_time);
/* Cancel state_selecting and send_discover timeouts, since either
one could have got us here. */
@@ -371,6 +370,9 @@
{
struct interface_info *ip = packet->interface;
struct client_lease *lease;
+ time_t cur_time;
+
+ time(&cur_time);
/* If we're not receptive to an offer right now, or if the offer
has an unrecognizable transaction id, then just drop it. */
@@ -404,7 +406,7 @@
ip->client->new->expiry = getULong(
ip->client->new->options[DHO_DHCP_LEASE_TIME].data);
else
- ip->client->new->expiry = default_lease_time;
+ ip->client->new->expiry = DHCP_DEFAULT_LEASE_TIME;
/* A number that looks negative here is really just very large,
because the lease expiry offset is unsigned. */
if (ip->client->new->expiry < 0)
@@ -539,28 +541,24 @@
}
if( new_lease->options[DHO_ROUTERS].len ) {
- MIB_IPFORWARDROW RouterMib;
NTSTATUS Status;
- RouterMib.dwForwardDest = 0; /* Default route */
- RouterMib.dwForwardMask = 0;
- RouterMib.dwForwardMetric1 = 1;
-
- if( old_default_route ) {
+ Adapter->RouterMib.dwForwardDest = 0; /* Default route */
+ Adapter->RouterMib.dwForwardMask = 0;
+ Adapter->RouterMib.dwForwardMetric1 = 1;
+
+ if( Adapter->RouterMib.dwForwardNextHop ) {
/* If we set a default route before, delete it before continuing */
- RouterMib.dwForwardDest = old_default_route;
- DeleteIpForwardEntry( &RouterMib );
+ DeleteIpForwardEntry( &Adapter->RouterMib );
}
- RouterMib.dwForwardNextHop =
+ Adapter->RouterMib.dwForwardNextHop =
*((ULONG*)new_lease->options[DHO_ROUTERS].data);
- Status = CreateIpForwardEntry( &RouterMib );
+ Status = CreateIpForwardEntry( &Adapter->RouterMib );
if( !NT_SUCCESS(Status) )
warning("CreateIpForwardEntry: %lx\n", Status);
- else
- old_default_route = RouterMib.dwForwardNextHop;
if (hkey) {
Buffer[0] = '\0';
@@ -585,6 +583,9 @@
{
PDHCP_ADAPTER Adapter;
struct client_lease *new_lease = ip->client->new;
+ time_t cur_time;
+
+ time(&cur_time);
/* Remember the medium. */
ip->client->new->medium = ip->client->medium;
@@ -638,7 +639,7 @@
} else
ip->client->destination = iaddr_broadcast;
- ip->client->first_sending = cur_time;
+ time(&ip->client->first_sending);
ip->client->interval = ip->client->config->initial_interval;
ip->client->state = S_RENEWING;
@@ -711,6 +712,9 @@
int arp_timeout_needed = 0, stop_selecting;
char *name = packet->options[DHO_DHCP_MESSAGE_TYPE].len ?
"DHCPOFFER" : "BOOTREPLY";
+ time_t cur_time;
+
+ time(&cur_time);
/* If we're not receptive to an offer right now, or if the offer
has an unrecognizable transaction id, then just drop it. */
@@ -949,8 +953,11 @@
{
struct interface_info *ip = ipp;
int interval, increase = 1;
+ time_t cur_time;
DH_DbgPrint(MID_TRACE,("Doing discover on interface %p\n",ip));
+
+ time(&cur_time);
/* Figure out how long it's been since we started transmitting. */
interval = cur_time - ip->client->first_sending;
@@ -1053,8 +1060,11 @@
struct interface_info *ip = ipp;
struct client_lease *loop = ip->client->active;
struct client_lease *lp;
+ time_t cur_time;
note("No DHCPOFFERS received.");
+
+ time(&cur_time);
/* We may not have an active lease, but we may have some
predefined leases that we can try. */
@@ -1140,6 +1150,9 @@
struct sockaddr_in destination;
struct in_addr from;
int interval;
+ time_t cur_time;
+
+ time(&cur_time);
/* Figure out how long it's been since we started transmitting. */
interval = cur_time - ip->client->first_sending;
Modified: trunk/reactos/base/services/dhcp/dispatch.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/services/dhcp/dispatc…
==============================================================================
--- trunk/reactos/base/services/dhcp/dispatch.c [iso-8859-1] (original)
+++ trunk/reactos/base/services/dhcp/dispatch.c [iso-8859-1] Sat Jul 11 01:32:02 2009
@@ -96,7 +96,7 @@
int count, i, to_msec, nfds = 0;
struct protocol *l;
fd_set fds;
- time_t howlong;
+ time_t howlong, cur_time;
struct timeval timeval;
ApiLock();
@@ -112,6 +112,8 @@
* a timeout registered, time out the select call then.
*/
another:
+ time(&cur_time);
+
if (timeouts) {
struct timeout *t;
@@ -183,16 +185,12 @@
/* Not likely to be transitory... */
if (count == SOCKET_ERROR) {
if (errno == EAGAIN || errno == EINTR) {
- time(&cur_time);
continue;
} else {
error("poll: %s", strerror(errno));
break;
}
}
-
- /* Get the current time... */
- time(&cur_time);
i = 0;
for (l = protocols; l; l = l->next) {
Modified: trunk/reactos/base/services/dhcp/include/rosdhcp.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/services/dhcp/include…
==============================================================================
--- trunk/reactos/base/services/dhcp/include/rosdhcp.h [iso-8859-1] (original)
+++ trunk/reactos/base/services/dhcp/include/rosdhcp.h [iso-8859-1] Sat Jul 11 01:32:02
2009
@@ -25,6 +25,7 @@
#define DHCP_REBOOT_TIMEOUT 300
#define DHCP_PANIC_TIMEOUT DHCP_REBOOT_TIMEOUT * 3
#define DHCP_BACKOFF_MAX 300
+#define DHCP_DEFAULT_LEASE_TIME 43200 /* 12 hours */
#define _PATH_DHCLIENT_PID
"\\systemroot\\system32\\drivers\\etc\\dhclient.pid"
typedef void *VOIDPTR;
@@ -54,6 +55,7 @@
typedef struct _DHCP_ADAPTER {
LIST_ENTRY ListEntry;
MIB_IFROW IfMib;
+ MIB_IPFORWARDROW RouterMib;
MIB_IPADDRROW IfAddr;
SOCKADDR Address;
ULONG NteContext,NteInstance;