Add --script-on-renewal option.

This commit is contained in:
Simon Kelley
2020-02-27 16:34:14 +00:00
parent 425e2405aa
commit ee64582a1f
5 changed files with 19 additions and 6 deletions

View File

@@ -267,7 +267,8 @@ struct event_desc {
#define OPT_UBUS 58
#define OPT_IGNORE_CLID 59
#define OPT_SINGLE_PORT 60
#define OPT_LAST 61
#define OPT_LEASE_RENEW 61
#define OPT_LAST 62
#define OPTION_BITS (sizeof(unsigned int)*8)
#define OPTION_SIZE ( (OPT_LAST/OPTION_BITS)+((OPT_LAST%OPTION_BITS)!=0) )
@@ -482,7 +483,7 @@ struct crec {
#define F_NO_RR (1u<<25)
#define F_IPSET (1u<<26)
#define F_NOEXTRA (1u<<27)
#define F_SERVFAIL (1u<<28)
#define F_SERVFAIL (1u<<28) /* currently unused. */
#define F_RCODE (1u<<29)
#define F_SRV (1u<<30)
@@ -703,6 +704,7 @@ struct frec {
#define LEASE_NA 32 /* IPv6 no-temporary lease */
#define LEASE_TA 64 /* IPv6 temporary lease */
#define LEASE_HAVE_HWADDR 128 /* Have set hwaddress */
#define LEASE_EXP_CHANGED 256 /* Lease expiry time changed */
struct dhcp_lease {
int clid_len; /* length of client identifier */

View File

@@ -836,7 +836,7 @@ void lease_set_expires(struct dhcp_lease *lease, unsigned int len, time_t now)
dns_dirty = 1;
lease->expires = exp;
#ifndef HAVE_BROKEN_RTC
lease->flags |= LEASE_AUX_CHANGED;
lease->flags |= LEASE_AUX_CHANGED | LEASE_EXP_CHANGED;
file_dirty = 1;
#endif
}
@@ -1136,7 +1136,8 @@ int do_script_run(time_t now)
for (lease = leases; lease; lease = lease->next)
if ((lease->flags & (LEASE_NEW | LEASE_CHANGED)) ||
((lease->flags & LEASE_AUX_CHANGED) && option_bool(OPT_LEASE_RO)))
((lease->flags & LEASE_AUX_CHANGED) && option_bool(OPT_LEASE_RO)) ||
((lease->flags & LEASE_EXP_CHANGED) && option_bool(OPT_LEASE_RENEW)))
{
#ifdef HAVE_SCRIPT
queue_script((lease->flags & LEASE_NEW) ? ACTION_ADD : ACTION_OLD, lease,
@@ -1146,7 +1147,7 @@ int do_script_run(time_t now)
emit_dbus_signal((lease->flags & LEASE_NEW) ? ACTION_ADD : ACTION_OLD, lease,
lease->fqdn ? lease->fqdn : lease->hostname);
#endif
lease->flags &= ~(LEASE_NEW | LEASE_CHANGED | LEASE_AUX_CHANGED);
lease->flags &= ~(LEASE_NEW | LEASE_CHANGED | LEASE_AUX_CHANGED | LEASE_EXP_CHANGED);
/* this is used for the "add" call, then junked, since they're not in the database */
free(lease->extradata);

View File

@@ -166,6 +166,7 @@ struct myoption {
#define LOPT_SHARED_NET 357
#define LOPT_IGNORE_CLID 358
#define LOPT_SINGLE_PORT 359
#define LOPT_SCRIPT_TIME 360
#ifdef HAVE_GETOPT_LONG
static const struct option opts[] =
@@ -245,6 +246,7 @@ static const struct myoption opts[] =
{ "conf-dir", 1, 0, '7' },
{ "log-facility", 1, 0 ,'8' },
{ "leasefile-ro", 0, 0, '9' },
{ "script-on-renewal", 0, 0, LOPT_SCRIPT_TIME},
{ "dns-forward-max", 1, 0, '0' },
{ "clear-on-reload", 0, 0, LOPT_RELOAD },
{ "dhcp-ignore-names", 2, 0, LOPT_NO_NAMES },
@@ -515,6 +517,7 @@ static struct {
{ LOPT_RAPID_COMMIT, OPT_RAPID_COMMIT, NULL, gettext_noop("Enables DHCPv4 Rapid Commit option."), NULL },
{ LOPT_DUMPFILE, ARG_ONE, "<path>", gettext_noop("Path to debug packet dump file"), NULL },
{ LOPT_DUMPMASK, ARG_ONE, "<hex>", gettext_noop("Mask which packets to dump"), NULL },
{ LOPT_SCRIPT_TIME, OPT_LEASE_RENEW, NULL, gettext_noop("Call dhcp-script when lease expiry changes."), NULL },
{ 0, 0, NULL, NULL, NULL }
};