Rename script.[ch] to ifchange.[ch].
This commit is contained in:
parent
eab048fec7
commit
c0b699ba88
@ -8,7 +8,7 @@ set(NDHC_SRCS
|
|||||||
socket.c
|
socket.c
|
||||||
packet.c
|
packet.c
|
||||||
timeout.c
|
timeout.c
|
||||||
script.c
|
ifchange.c
|
||||||
dhcpmsg.c
|
dhcpmsg.c
|
||||||
arp.c
|
arp.c
|
||||||
ndhc.c
|
ndhc.c
|
||||||
|
12
ndhc/arp.c
12
ndhc/arp.c
@ -19,7 +19,7 @@
|
|||||||
#include "dhcpmsg.h"
|
#include "dhcpmsg.h"
|
||||||
#include "packet.h"
|
#include "packet.h"
|
||||||
#include "sys.h"
|
#include "sys.h"
|
||||||
#include "script.h"
|
#include "ifchange.h"
|
||||||
#include "dhcpd.h"
|
#include "dhcpd.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "strl.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);
|
send_decline(cs->xid, cs->serverAddr, arp_dhcp_packet.yiaddr);
|
||||||
|
|
||||||
if (cs->arpPrevState != DS_REQUESTING)
|
if (cs->arpPrevState != DS_REQUESTING)
|
||||||
run_script(NULL, SCRIPT_DECONFIG);
|
ifchange(NULL, IFCHANGE_DECONFIG);
|
||||||
cs->dhcpState = DS_INIT_SELECTING;
|
cs->dhcpState = DS_INIT_SELECTING;
|
||||||
cs->requestedIP = 0;
|
cs->requestedIP = 0;
|
||||||
cs->timeout = 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.",
|
log_line("Lease of %s obtained, lease time %ld.",
|
||||||
inet_ntoa(temp_addr), cs->lease);
|
inet_ntoa(temp_addr), cs->lease);
|
||||||
cs->requestedIP = arp_dhcp_packet.yiaddr;
|
cs->requestedIP = arp_dhcp_packet.yiaddr;
|
||||||
run_script(&arp_dhcp_packet,
|
ifchange(&arp_dhcp_packet,
|
||||||
((cs->arpPrevState == DS_RENEWING ||
|
((cs->arpPrevState == DS_RENEWING ||
|
||||||
cs->arpPrevState == DS_REBINDING)
|
cs->arpPrevState == DS_REBINDING)
|
||||||
? SCRIPT_RENEW : SCRIPT_BOUND));
|
? IFCHANGE_RENEW : IFCHANGE_BOUND));
|
||||||
|
|
||||||
cs->dhcpState = DS_BOUND;
|
cs->dhcpState = DS_BOUND;
|
||||||
change_listen_mode(cs, LM_NONE);
|
change_listen_mode(cs, LM_NONE);
|
||||||
|
@ -42,7 +42,6 @@ struct client_config_t {
|
|||||||
char abort_if_no_lease; /* Abort if no lease */
|
char abort_if_no_lease; /* Abort if no lease */
|
||||||
char background_if_no_lease; /* Fork to background if no lease */
|
char background_if_no_lease; /* Fork to background if no lease */
|
||||||
char *interface; /* The name of the interface to use */
|
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 *clientid; /* Optional client id to use */
|
||||||
unsigned char *hostname; /* Optional hostname to use */
|
unsigned char *hostname; /* Optional hostname to use */
|
||||||
int ifindex; /* Index number of the interface to use */
|
int ifindex; /* Index number of the interface to use */
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* script.c
|
/* ifchange.c
|
||||||
*
|
*
|
||||||
* Functions to call the interface change daemon
|
* Functions to call the interface change daemon
|
||||||
*
|
*
|
||||||
@ -39,7 +39,7 @@
|
|||||||
#include "options.h"
|
#include "options.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "io.h"
|
#include "io.h"
|
||||||
#include "script.h"
|
#include "ifchange.h"
|
||||||
|
|
||||||
static int snprintip(char *dest, size_t size, unsigned char *ip)
|
static int snprintip(char *dest, size_t size, unsigned char *ip)
|
||||||
{
|
{
|
||||||
@ -234,23 +234,23 @@ static void bound_if(struct dhcpMessage *packet)
|
|||||||
close(sockfd);
|
close(sockfd);
|
||||||
}
|
}
|
||||||
|
|
||||||
void run_script(struct dhcpMessage *packet, int mode)
|
void ifchange(struct dhcpMessage *packet, int mode)
|
||||||
{
|
{
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case SCRIPT_DECONFIG:
|
case IFCHANGE_DECONFIG:
|
||||||
deconfig_if();
|
deconfig_if();
|
||||||
break;
|
break;
|
||||||
case SCRIPT_BOUND:
|
case IFCHANGE_BOUND:
|
||||||
bound_if(packet);
|
bound_if(packet);
|
||||||
break;
|
break;
|
||||||
case SCRIPT_RENEW:
|
case IFCHANGE_RENEW:
|
||||||
bound_if(packet);
|
bound_if(packet);
|
||||||
break;
|
break;
|
||||||
case SCRIPT_NAK:
|
case IFCHANGE_NAK:
|
||||||
deconfig_if();
|
deconfig_if();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
log_error("invalid script mode: %d", mode);
|
log_error("invalid ifchange mode: %d", mode);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
15
ndhc/ifchange.h
Normal file
15
ndhc/ifchange.h
Normal file
@ -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
|
@ -49,7 +49,7 @@
|
|||||||
#include "packet.h"
|
#include "packet.h"
|
||||||
#include "timeout.h"
|
#include "timeout.h"
|
||||||
#include "sys.h"
|
#include "sys.h"
|
||||||
#include "script.h"
|
#include "ifchange.h"
|
||||||
#include "socket.h"
|
#include "socket.h"
|
||||||
#include "arp.h"
|
#include "arp.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
@ -88,7 +88,6 @@ struct client_config_t client_config = {
|
|||||||
.quit_after_lease = 0,
|
.quit_after_lease = 0,
|
||||||
.background_if_no_lease = 0,
|
.background_if_no_lease = 0,
|
||||||
.interface = "eth0",
|
.interface = "eth0",
|
||||||
.script = "none",
|
|
||||||
.clientid = NULL,
|
.clientid = NULL,
|
||||||
.hostname = NULL,
|
.hostname = NULL,
|
||||||
.ifindex = 0,
|
.ifindex = 0,
|
||||||
@ -137,7 +136,7 @@ static void perform_renew(void)
|
|||||||
cs.dhcpState = DS_RENEW_REQUESTED;
|
cs.dhcpState = DS_RENEW_REQUESTED;
|
||||||
break;
|
break;
|
||||||
case DS_RENEW_REQUESTED: /* impatient are we? fine, square 1 */
|
case DS_RENEW_REQUESTED: /* impatient are we? fine, square 1 */
|
||||||
run_script(NULL, SCRIPT_DECONFIG);
|
ifchange(NULL, IFCHANGE_DECONFIG);
|
||||||
case DS_REQUESTING:
|
case DS_REQUESTING:
|
||||||
case DS_RELEASED:
|
case DS_RELEASED:
|
||||||
change_listen_mode(&cs, LM_RAW);
|
change_listen_mode(&cs, LM_RAW);
|
||||||
@ -169,7 +168,7 @@ static void perform_release(void)
|
|||||||
log_line("Unicasting a release of %s to %s.",
|
log_line("Unicasting a release of %s to %s.",
|
||||||
inet_ntoa(temp_raddr), inet_ntoa(temp_saddr));
|
inet_ntoa(temp_raddr), inet_ntoa(temp_saddr));
|
||||||
send_release(cs.serverAddr, cs.requestedIP); /* unicast */
|
send_release(cs.serverAddr, cs.requestedIP); /* unicast */
|
||||||
run_script(NULL, SCRIPT_DECONFIG);
|
ifchange(NULL, IFCHANGE_DECONFIG);
|
||||||
}
|
}
|
||||||
log_line("Entering released state.");
|
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");
|
"cap_net_bind_service,cap_net_broadcast,cap_net_raw=ep");
|
||||||
drop_root(uid, gid);
|
drop_root(uid, gid);
|
||||||
|
|
||||||
run_script(NULL, SCRIPT_DECONFIG);
|
ifchange(NULL, IFCHANGE_DECONFIG);
|
||||||
|
|
||||||
do_work();
|
do_work();
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
#include "packet.h"
|
#include "packet.h"
|
||||||
#include "dhcpmsg.h"
|
#include "dhcpmsg.h"
|
||||||
#include "socket.h"
|
#include "socket.h"
|
||||||
#include "script.h"
|
#include "ifchange.h"
|
||||||
#include "sys.h"
|
#include "sys.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "io.h"
|
#include "io.h"
|
||||||
@ -253,9 +253,9 @@ static void dhcp_ack_or_nak_packet(struct client_state_t *cs,
|
|||||||
} else if (*message == DHCPNAK) {
|
} else if (*message == DHCPNAK) {
|
||||||
/* return to init state */
|
/* return to init state */
|
||||||
log_line("Received DHCP NAK.");
|
log_line("Received DHCP NAK.");
|
||||||
run_script(packet, SCRIPT_NAK);
|
ifchange(packet, IFCHANGE_NAK);
|
||||||
if (cs->dhcpState != DS_REQUESTING)
|
if (cs->dhcpState != DS_REQUESTING)
|
||||||
run_script(NULL, SCRIPT_DECONFIG);
|
ifchange(NULL, IFCHANGE_DECONFIG);
|
||||||
cs->dhcpState = DS_INIT_SELECTING;
|
cs->dhcpState = DS_INIT_SELECTING;
|
||||||
cs->timeout = 0;
|
cs->timeout = 0;
|
||||||
cs->requestedIP = 0;
|
cs->requestedIP = 0;
|
||||||
|
@ -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
|
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#include "timeout.h"
|
#include "timeout.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "script.h"
|
#include "ifchange.h"
|
||||||
#include "packet.h"
|
#include "packet.h"
|
||||||
#include "dhcpmsg.h"
|
#include "dhcpmsg.h"
|
||||||
#include "arp.h"
|
#include "arp.h"
|
||||||
@ -42,7 +42,7 @@ static void renew_requested_timeout(struct client_state_t *cs)
|
|||||||
cs->packetNum++;
|
cs->packetNum++;
|
||||||
} else {
|
} else {
|
||||||
/* timed out, go back to init state */
|
/* timed out, go back to init state */
|
||||||
run_script(NULL, SCRIPT_DECONFIG);
|
ifchange(NULL, IFCHANGE_DECONFIG);
|
||||||
cs->dhcpState = DS_INIT_SELECTING;
|
cs->dhcpState = DS_INIT_SELECTING;
|
||||||
cs->timeout = 0;
|
cs->timeout = 0;
|
||||||
cs->packetNum = 0;
|
cs->packetNum = 0;
|
||||||
@ -99,7 +99,7 @@ static void rebinding_timeout(struct client_state_t *cs)
|
|||||||
/* timed out, enter init state */
|
/* timed out, enter init state */
|
||||||
cs->dhcpState = DS_INIT_SELECTING;
|
cs->dhcpState = DS_INIT_SELECTING;
|
||||||
log_line("Lease lost, entering init state.");
|
log_line("Lease lost, entering init state.");
|
||||||
run_script(NULL, SCRIPT_DECONFIG);
|
ifchange(NULL, IFCHANGE_DECONFIG);
|
||||||
cs->timeout = 0;
|
cs->timeout = 0;
|
||||||
cs->packetNum = 0;
|
cs->packetNum = 0;
|
||||||
change_listen_mode(cs, LM_RAW);
|
change_listen_mode(cs, LM_RAW);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user