Update of /cvsroot/dhcp-agent/dhcp-agent
In directory usw-pr-cvs1:/tmp/cvs-serv16708
Modified Files:
dhcp-agent.h dhcp-client-states.c dhcp-client.c dhcp-client.h
Log Message:
client states now in dispatch array
Index: dhcp-agent.h
===================================================================
RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-agent.h,v
retrieving revision 1.76
retrieving revision 1.77
diff -C2 -d -r1.76 -r1.77
*** dhcp-agent.h 26 Oct 2002 18:13:21 -0000 1.76
--- dhcp-agent.h 26 Oct 2002 22:39:32 -0000 1.77
***************
*** 499,513 ****
# define NETBIOS_H_NODE 0x06
- /* DHCP states
- * We use these internally
- * for the state machine. */
-
- #define STATE_FATAL_ERROR -1
- #define STATE_DISCOVER_OFFER 0
- #define STATE_REQUEST_ACK 1
- #define STATE_SETUP 3
- #define STATE_WAIT 4
- #define STATE_RELEASE 5
-
/* Parse types. */
--- 499,502 ----
Index: dhcp-client-states.c
===================================================================
RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-client-states.c,v
retrieving revision 1.42
retrieving revision 1.43
diff -C2 -d -r1.42 -r1.43
*** dhcp-client-states.c 23 Oct 2002 23:43:34 -0000 1.42
--- dhcp-client-states.c 26 Oct 2002 22:39:32 -0000 1.43
***************
*** 29,32 ****
--- 29,33 ----
#include <dhcp-agent.h>
+ #include <dhcp-client.h>
#include <dhcp-util.h>
#include <dhcp-sysconf.h>
***************
*** 485,486 ****
--- 486,494 ----
* return STATE_REQUEST_ACK here. */
}
+
+ int client_fatal_error(dhcp_client_control_t *dc)
+ {
+ FATAL_MESSAGE("encountered a fatal error. i'm giving up.");
+ exit(1); /* to get rid of compiler warning. */
+ }
+
Index: dhcp-client.c
===================================================================
RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-client.c,v
retrieving revision 1.47
retrieving revision 1.48
diff -C2 -d -r1.47 -r1.48
*** dhcp-client.c 22 Oct 2002 00:59:41 -0000 1.47
--- dhcp-client.c 26 Oct 2002 22:39:32 -0000 1.48
***************
*** 71,74 ****
--- 71,85 ----
};
+ /* client state dispatch: index constants in dhcp-client.h */
+ client_state client_states[] = {
+ client_discover_offer,
+ client_request_ack,
+ client_setup,
+ client_wait,
+ client_release,
+ client_fatal_error,
+ };
+
+
/* global vars affecting other code. */
int interactive = 1; /* by default we begin interactive (messages on stdout/stderr). */
***************
*** 239,275 ****
return state;
}
-
- switch(state) {
-
- case STATE_FATAL_ERROR:
- FATAL_MESSAGE("encountered fatal error. I'm giving up.");
-
- case STATE_DISCOVER_OFFER:
- state = client_discover_offer(dc);
- break;
-
- case STATE_REQUEST_ACK:
- state = client_request_ack(dc);
- break;
! case STATE_SETUP:
! state = client_setup(dc);
! have_setup = 1;
! break;
!
! case STATE_WAIT:
! state = client_wait(dc);
! break;
!
! case STATE_RELEASE:
! state = client_release(dc);
! break;
- default:
- break;
- }
}
! return STATE_FATAL_ERROR; /* we should never get here, but if we do... */
}
--- 250,259 ----
return state;
}
! state = client_states[state];
}
! return STATE_FATAL_ERROR; /* we should never get here, but if we do it's bad :) */
}
Index: dhcp-client.h
===================================================================
RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-client.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** dhcp-client.h 17 Jun 2002 13:23:07 -0000 1.3
--- dhcp-client.h 26 Oct 2002 22:39:32 -0000 1.4
***************
*** 28,32 ****
--- 28,34 ----
typedef void (*client_command)(char *interface);
typedef char *(*interface_lister)(void);
+ typedef int (*client_state)(dhcp_client_control_t *);
+ /* client commands. */
#define DO_VERSION 0
#define DO_KILL 1
***************
*** 35,38 ****
#define DO_CLIENT 4
! #endif
--- 37,55 ----
#define DO_CLIENT 4
! /* DHCP client states. */
+ #define STATE_DISCOVER_OFFER 0
+ #define STATE_REQUEST_ACK 1
+ #define STATE_SETUP 3
+ #define STATE_WAIT 4
+ #define STATE_RELEASE 5
+ #define STATE_FATAL_ERROR 6
+
+ extern int client_discover_offer(dhcp_client_control_t *dc);
+ extern int client_request_ack(dhcp_client_control_t *dc);
+ extern int client_wait(dhcp_client_control_t *dc);
+ extern int client_release(dhcp_client_control_t *dc);
+ extern int client_setup(dhcp_client_control_t *dc);
+ extern int client_fatal_error(dhcp_client_control_t *dc);
+
+ #endif
|