From c0b699ba88f1b7b9e92c3c14a3daa11524984086 Mon Sep 17 00:00:00 2001 From: "Nicholas J. Kain" Date: Fri, 24 Dec 2010 10:12:41 -0500 Subject: [PATCH] Rename script.[ch] to ifchange.[ch]. --- ndhc/CMakeLists.txt | 2 +- ndhc/arp.c | 12 ++++++------ ndhc/config.h | 1 - ndhc/{script.c => ifchange.c} | 16 ++++++++-------- ndhc/ifchange.h | 15 +++++++++++++++ ndhc/ndhc.c | 9 ++++----- ndhc/packet.c | 6 +++--- ndhc/script.h | 15 --------------- ndhc/timeout.c | 6 +++--- 9 files changed, 40 insertions(+), 42 deletions(-) rename ndhc/{script.c => ifchange.c} (96%) create mode 100644 ndhc/ifchange.h delete mode 100644 ndhc/script.h diff --git a/ndhc/CMakeLists.txt b/ndhc/CMakeLists.txt index ebda059..60496bb 100644 --- a/ndhc/CMakeLists.txt +++ b/ndhc/CMakeLists.txt @@ -8,7 +8,7 @@ set(NDHC_SRCS socket.c packet.c timeout.c - script.c + ifchange.c dhcpmsg.c arp.c ndhc.c diff --git a/ndhc/arp.c b/ndhc/arp.c index 143fe77..c3c3863 100644 --- a/ndhc/arp.c +++ b/ndhc/arp.c @@ -19,7 +19,7 @@ #include "dhcpmsg.h" #include "packet.h" #include "sys.h" -#include "script.h" +#include "ifchange.h" #include "dhcpd.h" #include "log.h" #include "strl.h" @@ -98,7 +98,7 @@ static void arp_failed(struct client_state_t *cs) send_decline(cs->xid, cs->serverAddr, arp_dhcp_packet.yiaddr); if (cs->arpPrevState != DS_REQUESTING) - run_script(NULL, SCRIPT_DECONFIG); + ifchange(NULL, IFCHANGE_DECONFIG); cs->dhcpState = DS_INIT_SELECTING; cs->requestedIP = 0; cs->timeout = 0; @@ -124,10 +124,10 @@ void arp_success(struct client_state_t *cs) log_line("Lease of %s obtained, lease time %ld.", inet_ntoa(temp_addr), cs->lease); cs->requestedIP = arp_dhcp_packet.yiaddr; - run_script(&arp_dhcp_packet, - ((cs->arpPrevState == DS_RENEWING || - cs->arpPrevState == DS_REBINDING) - ? SCRIPT_RENEW : SCRIPT_BOUND)); + ifchange(&arp_dhcp_packet, + ((cs->arpPrevState == DS_RENEWING || + cs->arpPrevState == DS_REBINDING) + ? IFCHANGE_RENEW : IFCHANGE_BOUND)); cs->dhcpState = DS_BOUND; change_listen_mode(cs, LM_NONE); diff --git a/ndhc/config.h b/ndhc/config.h index d542c47..60ddf04 100644 --- a/ndhc/config.h +++ b/ndhc/config.h @@ -42,7 +42,6 @@ struct client_config_t { char abort_if_no_lease; /* Abort if no lease */ char background_if_no_lease; /* Fork to background if no lease */ char *interface; /* The name of the interface to use */ - char *script; /* User script to run at dhcp events */ unsigned char *clientid; /* Optional client id to use */ unsigned char *hostname; /* Optional hostname to use */ int ifindex; /* Index number of the interface to use */ diff --git a/ndhc/script.c b/ndhc/ifchange.c similarity index 96% rename from ndhc/script.c rename to ndhc/ifchange.c index 41a0c1e..e7ad27b 100644 --- a/ndhc/script.c +++ b/ndhc/ifchange.c @@ -1,4 +1,4 @@ -/* script.c +/* ifchange.c * * Functions to call the interface change daemon * @@ -39,7 +39,7 @@ #include "options.h" #include "log.h" #include "io.h" -#include "script.h" +#include "ifchange.h" static int snprintip(char *dest, size_t size, unsigned char *ip) { @@ -234,23 +234,23 @@ static void bound_if(struct dhcpMessage *packet) close(sockfd); } -void run_script(struct dhcpMessage *packet, int mode) +void ifchange(struct dhcpMessage *packet, int mode) { switch (mode) { - case SCRIPT_DECONFIG: + case IFCHANGE_DECONFIG: deconfig_if(); break; - case SCRIPT_BOUND: + case IFCHANGE_BOUND: bound_if(packet); break; - case SCRIPT_RENEW: + case IFCHANGE_RENEW: bound_if(packet); break; - case SCRIPT_NAK: + case IFCHANGE_NAK: deconfig_if(); break; default: - log_error("invalid script mode: %d", mode); + log_error("invalid ifchange mode: %d", mode); break; } } diff --git a/ndhc/ifchange.h b/ndhc/ifchange.h new file mode 100644 index 0000000..471c2de --- /dev/null +++ b/ndhc/ifchange.h @@ -0,0 +1,15 @@ +#ifndef IFCHANGE_H_ +#define IFCHANGE_H_ + +#include "packet.h" + +enum { + IFCHANGE_DECONFIG = 0, + IFCHANGE_BOUND = 1, + IFCHANGE_RENEW = 2, + IFCHANGE_NAK = 4 +}; + +void ifchange(struct dhcpMessage *packet, int mode); + +#endif diff --git a/ndhc/ndhc.c b/ndhc/ndhc.c index 72338a6..067a219 100644 --- a/ndhc/ndhc.c +++ b/ndhc/ndhc.c @@ -49,7 +49,7 @@ #include "packet.h" #include "timeout.h" #include "sys.h" -#include "script.h" +#include "ifchange.h" #include "socket.h" #include "arp.h" #include "log.h" @@ -88,7 +88,6 @@ struct client_config_t client_config = { .quit_after_lease = 0, .background_if_no_lease = 0, .interface = "eth0", - .script = "none", .clientid = NULL, .hostname = NULL, .ifindex = 0, @@ -137,7 +136,7 @@ static void perform_renew(void) cs.dhcpState = DS_RENEW_REQUESTED; break; case DS_RENEW_REQUESTED: /* impatient are we? fine, square 1 */ - run_script(NULL, SCRIPT_DECONFIG); + ifchange(NULL, IFCHANGE_DECONFIG); case DS_REQUESTING: case DS_RELEASED: change_listen_mode(&cs, LM_RAW); @@ -169,7 +168,7 @@ static void perform_release(void) log_line("Unicasting a release of %s to %s.", inet_ntoa(temp_raddr), inet_ntoa(temp_saddr)); send_release(cs.serverAddr, cs.requestedIP); /* unicast */ - run_script(NULL, SCRIPT_DECONFIG); + ifchange(NULL, IFCHANGE_DECONFIG); } log_line("Entering released state."); @@ -406,7 +405,7 @@ int main(int argc, char **argv) "cap_net_bind_service,cap_net_broadcast,cap_net_raw=ep"); drop_root(uid, gid); - run_script(NULL, SCRIPT_DECONFIG); + ifchange(NULL, IFCHANGE_DECONFIG); do_work(); diff --git a/ndhc/packet.c b/ndhc/packet.c index c7ec2af..8d194bf 100644 --- a/ndhc/packet.c +++ b/ndhc/packet.c @@ -12,7 +12,7 @@ #include "packet.h" #include "dhcpmsg.h" #include "socket.h" -#include "script.h" +#include "ifchange.h" #include "sys.h" #include "log.h" #include "io.h" @@ -253,9 +253,9 @@ static void dhcp_ack_or_nak_packet(struct client_state_t *cs, } else if (*message == DHCPNAK) { /* return to init state */ log_line("Received DHCP NAK."); - run_script(packet, SCRIPT_NAK); + ifchange(packet, IFCHANGE_NAK); if (cs->dhcpState != DS_REQUESTING) - run_script(NULL, SCRIPT_DECONFIG); + ifchange(NULL, IFCHANGE_DECONFIG); cs->dhcpState = DS_INIT_SELECTING; cs->timeout = 0; cs->requestedIP = 0; diff --git a/ndhc/script.h b/ndhc/script.h deleted file mode 100644 index 84e7c2c..0000000 --- a/ndhc/script.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef SCRIPT_H_ -#define SCRIPT_H_ - -#include "packet.h" - -enum { - SCRIPT_DECONFIG = 0, - SCRIPT_BOUND = 1, - SCRIPT_RENEW = 2, - SCRIPT_NAK = 4 -}; - -void run_script(struct dhcpMessage *packet, int mode); - -#endif diff --git a/ndhc/timeout.c b/ndhc/timeout.c index 3407fd8..f186f6d 100644 --- a/ndhc/timeout.c +++ b/ndhc/timeout.c @@ -3,7 +3,7 @@ #include "timeout.h" #include "config.h" -#include "script.h" +#include "ifchange.h" #include "packet.h" #include "dhcpmsg.h" #include "arp.h" @@ -42,7 +42,7 @@ static void renew_requested_timeout(struct client_state_t *cs) cs->packetNum++; } else { /* timed out, go back to init state */ - run_script(NULL, SCRIPT_DECONFIG); + ifchange(NULL, IFCHANGE_DECONFIG); cs->dhcpState = DS_INIT_SELECTING; cs->timeout = 0; cs->packetNum = 0; @@ -99,7 +99,7 @@ static void rebinding_timeout(struct client_state_t *cs) /* timed out, enter init state */ cs->dhcpState = DS_INIT_SELECTING; log_line("Lease lost, entering init state."); - run_script(NULL, SCRIPT_DECONFIG); + ifchange(NULL, IFCHANGE_DECONFIG); cs->timeout = 0; cs->packetNum = 0; change_listen_mode(cs, LM_RAW);