summaryrefslogtreecommitdiff
path: root/dhcpctl/dhcpctl.c
diff options
context:
space:
mode:
Diffstat (limited to 'dhcpctl/dhcpctl.c')
-rw-r--r--dhcpctl/dhcpctl.c145
1 files changed, 144 insertions, 1 deletions
diff --git a/dhcpctl/dhcpctl.c b/dhcpctl/dhcpctl.c
index 3c78bc19..e8834382 100644
--- a/dhcpctl/dhcpctl.c
+++ b/dhcpctl/dhcpctl.c
@@ -29,6 +29,10 @@
#include "dhcpd.h"
#include <omapip/omapip_p.h>
#include "dhcpctl.h"
+#include <sys/time.h>
+
+
+/* #define DEBUG_DHCPCTL 1 */
omapi_object_type_t *dhcpctl_callback_type;
omapi_object_type_t *dhcpctl_remote_type;
@@ -97,6 +101,9 @@ dhcpctl_status dhcpctl_connect (dhcpctl_handle *connection,
dhcpctl_handle authinfo)
{
isc_result_t status;
+#ifdef DEBUG_DHCPCTL
+ log_debug("dhcpctl_connect(%s:%d)", server_name, port);
+#endif
status = omapi_generic_new (connection, MDL);
if (status != ISC_R_SUCCESS) {
@@ -105,19 +112,35 @@ dhcpctl_status dhcpctl_connect (dhcpctl_handle *connection,
status = omapi_protocol_connect (*connection, server_name,
(unsigned)port, authinfo);
- if (status == ISC_R_SUCCESS)
+ if (status == ISC_R_SUCCESS) {
+#ifdef DEBUG_DHCPCTL
+ log_debug("dhcpctl_connect success");
+#endif
return status;
+ }
+
if (status != DHCP_R_INCOMPLETE) {
omapi_object_dereference (connection, MDL);
+#ifdef DEBUG_DHCPCTL
+ log_debug("dhcpctl_connect failed:%s",
+ isc_result_totext (status));
+#endif
return status;
}
status = omapi_wait_for_completion (*connection, 0);
if (status != ISC_R_SUCCESS) {
omapi_object_dereference (connection, MDL);
+#ifdef DEBUG_DHCPCTL
+ log_debug("dhcpctl_connect, wait failed:%s",
+ isc_result_totext (status));
+#endif
return status;
}
+#ifdef DEBUG_DHCPCTL
+ log_debug("dhcpctl_connect success");
+#endif
return status;
}
@@ -137,8 +160,58 @@ dhcpctl_status dhcpctl_connect (dhcpctl_handle *connection,
dhcpctl_status dhcpctl_wait_for_completion (dhcpctl_handle h,
dhcpctl_status *s)
{
+#ifdef DEBUG_DHCPCTL
+ log_debug("dhcpctl_wait_for_completion");
+#endif
isc_result_t status;
status = omapi_wait_for_completion (h, 0);
+ if (status != ISC_R_SUCCESS) {
+ return status;
+ }
+ if (h -> type == dhcpctl_remote_type)
+ *s = ((dhcpctl_remote_object_t *)h) -> waitstatus;
+
+ return ISC_R_SUCCESS;
+}
+
+/* dhcpctl_wait_for_completion
+
+ synchronous
+ returns zero if the callback completes, a nonzero status if
+ there was some problem relating to the wait operation. The
+ status of the queued request will be stored through s, and
+ will also be either zero for success or nonzero for some kind
+ of failure. Never returns until completion or until the
+ connection to the server is lost. This performs the same
+ function as dhcpctl_set_callback and the subsequent callback,
+ for programs that want to do inline execution instead of using
+ callbacks. */
+
+dhcpctl_status dhcpctl_timed_wait_for_completion (dhcpctl_handle h,
+ dhcpctl_status *s,
+ struct timeval *t)
+{
+ isc_result_t status;
+ struct timeval adjusted_t;
+
+#ifdef DEBUG_DHCPCTL
+ if (t) {
+ log_debug ("dhcpctl_timed_wait_for_completion(%u.%u secs.usecs)",
+ (unsigned int)(t->tv_sec),
+ (unsigned int)(t->tv_usec));
+ } else {
+ log_debug ("dhcpctl_timed_wait_for_completion(no timeout)");
+ }
+#endif
+
+ if (t) {
+ struct timeval now;
+ gettimeofday (&now, (struct timezone *)0);
+ adjusted_t.tv_sec = now.tv_sec + t->tv_sec;
+ adjusted_t.tv_usec = now.tv_usec + t->tv_usec;
+ }
+
+ status = omapi_wait_for_completion (h, (t ? &adjusted_t : 0));
if (status != ISC_R_SUCCESS)
return status;
if (h -> type == dhcpctl_remote_type)
@@ -146,6 +219,7 @@ dhcpctl_status dhcpctl_wait_for_completion (dhcpctl_handle h,
return ISC_R_SUCCESS;
}
+
/* dhcpctl_get_value
synchronous
@@ -168,6 +242,9 @@ dhcpctl_status dhcpctl_get_value (dhcpctl_data_string *result,
omapi_value_t *tv = (omapi_value_t *)0;
unsigned len;
int ip;
+#ifdef DEBUG_DHCPCTL
+ log_debug("dhcpctl_get_value(%s)", value_name);
+#endif
status = omapi_get_value_str (h, (omapi_object_t *)0, value_name, &tv);
if (status != ISC_R_SUCCESS)
@@ -232,6 +309,10 @@ dhcpctl_status dhcpctl_get_boolean (int *result,
isc_result_t status;
dhcpctl_data_string data = (dhcpctl_data_string)0;
int rv;
+
+#ifdef DEBUG_DHCPCTL
+ log_debug("dhcpctl_get_boolean(%s)", value_name);
+#endif
status = dhcpctl_get_value (&data, h, value_name);
if (status != ISC_R_SUCCESS)
@@ -258,6 +339,9 @@ dhcpctl_status dhcpctl_set_value (dhcpctl_handle h, dhcpctl_data_string value,
isc_result_t status;
omapi_typed_data_t *tv = (omapi_typed_data_t *)0;
omapi_data_string_t *name = (omapi_data_string_t *)0;
+#ifdef DEBUG_DHCPCTL
+ log_debug("dhcpctl_set_value(%s)", value_name);
+#endif
status = omapi_data_string_new (&name, strlen (value_name), MDL);
if (status != ISC_R_SUCCESS)
@@ -291,6 +375,9 @@ dhcpctl_status dhcpctl_set_string_value (dhcpctl_handle h, const char *value,
isc_result_t status;
omapi_typed_data_t *tv = (omapi_typed_data_t *)0;
omapi_data_string_t *name = (omapi_data_string_t *)0;
+#ifdef DEBUG_DHCPCTL
+ log_debug("dhcpctl_set_string_value(%s)", value_name);
+#endif
status = omapi_data_string_new (&name, strlen (value_name), MDL);
if (status != ISC_R_SUCCESS)
@@ -324,6 +411,9 @@ dhcpctl_status dhcpctl_set_data_value (dhcpctl_handle h,
omapi_typed_data_t *tv = (omapi_typed_data_t *)0;
omapi_data_string_t *name = (omapi_data_string_t *)0;
unsigned ll;
+#ifdef DEBUG_DHCPCTL
+ log_debug("dhcpctl_set_data_value(%s)", value_name);
+#endif
ll = strlen (value_name);
status = omapi_data_string_new (&name, ll, MDL);
@@ -355,6 +445,9 @@ dhcpctl_status dhcpctl_set_null_value (dhcpctl_handle h,
isc_result_t status;
omapi_data_string_t *name = (omapi_data_string_t *)0;
unsigned ll;
+#ifdef DEBUG_DHCPCTL
+ log_debug("dhcpctl_set_null_value(%s)", value_name);
+#endif
ll = strlen (value_name);
status = omapi_data_string_new (&name, ll, MDL);
@@ -379,6 +472,9 @@ dhcpctl_status dhcpctl_set_boolean_value (dhcpctl_handle h, int value,
isc_result_t status;
omapi_typed_data_t *tv = (omapi_typed_data_t *)0;
omapi_data_string_t *name = (omapi_data_string_t *)0;
+#ifdef DEBUG_DHCPCTL
+ log_debug("dhcpctl_set_boolean_value(%s)", value_name);
+#endif
status = omapi_data_string_new (&name, strlen (value_name), MDL);
if (status != ISC_R_SUCCESS)
@@ -408,6 +504,9 @@ dhcpctl_status dhcpctl_set_int_value (dhcpctl_handle h, int value,
isc_result_t status;
omapi_typed_data_t *tv = (omapi_typed_data_t *)0;
omapi_data_string_t *name = (omapi_data_string_t *)0;
+#ifdef DEBUG_DHCPCTL
+ log_debug("dhcpctl_set_int_value(%s)", value_name);
+#endif
status = omapi_data_string_new (&name, strlen (value_name), MDL);
if (status != ISC_R_SUCCESS)
@@ -438,6 +537,9 @@ dhcpctl_status dhcpctl_object_update (dhcpctl_handle connection,
isc_result_t status;
omapi_object_t *message = (omapi_object_t *)0;
dhcpctl_remote_object_t *ro;
+#ifdef DEBUG_DHCPCTL
+ log_debug("dhcpctl_object_update");
+#endif
if (h -> type != dhcpctl_remote_type)
return DHCP_R_INVALIDARG;
@@ -487,6 +589,9 @@ dhcpctl_status dhcpctl_object_refresh (dhcpctl_handle connection,
isc_result_t status;
omapi_object_t *message = (omapi_object_t *)0;
dhcpctl_remote_object_t *ro;
+#ifdef DEBUG_DHCPCTL
+ log_debug("dhcpctl_object_refresh");
+#endif
if (h -> type != dhcpctl_remote_type)
return DHCP_R_INVALIDARG;
@@ -540,6 +645,9 @@ dhcpctl_status dhcpctl_object_remove (dhcpctl_handle connection,
isc_result_t status;
omapi_object_t *message = (omapi_object_t *)0;
dhcpctl_remote_object_t *ro;
+#ifdef DEBUG_DHCPCTL
+ log_debug("dhcpctl_object_remove");
+#endif
if (h -> type != dhcpctl_remote_type)
return DHCP_R_INVALIDARG;
@@ -582,5 +690,40 @@ dhcpctl_status dhcpctl_object_remove (dhcpctl_handle connection,
isc_result_t dhcpctl_data_string_dereference (dhcpctl_data_string *vp,
const char *file, int line)
{
+#ifdef DEBUG_DHCPCTL
+ log_debug("dhcpctl_data_string_dereference");
+#endif
return omapi_data_string_dereference (vp, file, line);
}
+
+dhcpctl_status dhcpctl_disconnect (dhcpctl_handle *connection,
+ int force)
+{
+ isc_result_t status;
+#ifdef DEBUG_DHCPCTL
+ log_debug("dhcpctl_disconnect()");
+#endif
+ if (!connection || !((*connection)->outer) ||
+ !((*connection)->outer->type) ||
+ ((*connection)->outer->type != omapi_type_protocol) ||
+ !((*connection)->outer->outer)) {
+ log_debug("dhcpctl_disconnect detected invalid arg");
+ return DHCP_R_INVALIDARG;
+ }
+
+ status = omapi_disconnect ((*connection)->outer->outer, force);
+ if (status == ISC_R_SUCCESS) {
+#ifdef DEBUG_DHCPCTL
+ log_debug("dhcpctl_disconnect success");
+#endif
+ omapi_object_dereference (connection, MDL);
+ return status;
+ }
+
+#ifdef DEBUG_DHCPCTL
+ log_debug("dhcpctl_disconnect failed:%s",
+ isc_result_totext (status));
+#endif
+ return status;
+}
+