[OpenWrt-Devel] [PATCH] odhcpd: allow specifying lease trigger mode

Hans Dedecker dedeckeh at gmail.com
Fri Jul 13 06:54:25 EDT 2018


On Tue, Jun 26, 2018 at 10:34 PM Michał Kępień via openwrt-devel
<openwrt-devel at lists.openwrt.org> wrote:
>
> The sender domain has a DMARC Reject/Quarantine policy which disallows
> sending mailing list messages using the original "From" header.
>
> To mitigate this problem, the original message has been wrapped
> automatically by the mailing list software.
>
>
> ---------- Forwarded message ----------
> From: "Michał Kępień" <lede at kempniu.pl>
> To: openwrt-devel at lists.openwrt.org
> Cc:
> Bcc:
> Date: Tue, 26 Jun 2018 22:33:40 +0200
> Subject: [PATCH] odhcpd: allow specifying lease trigger mode
> odhcpd only calls the lease trigger script when a lease with an
> associated hostname is changed.  Enabling the lease trigger script to
> also be called when a lease without an associated hostname is changed
> allows for greater flexibility.
>
> Add a new global odhcpd configuration parameter, "leasetrigger_mode",
> with a default value of 0 which retains current behavior.  Setting the
> parameter to 1 causes the lease trigger script to instead be called
> every time any lease is changed, no matter whether it is associated with
> a hostname or not.
Hi,

What usecase do you want to cover by calling the lease script every time ?

Hans
>
> Signed-off-by: Michał Kępień <lede at kempniu.pl>
> ---
> The configuration parameter added by this patch could obviously be a
> boolean, but it occurred to me that if the flexibility of the lease
> trigger script is further improved in the future [1], more lease trigger
> modes may be added (e.g. upon every single DHCP event, even if one does
> not cause any lease to be modified).
>
> [1] see e.g. https://bugs.openwrt.org/index.php?do=details&task_id=401
>
>  README          | 18 ++++++++++--------
>  src/config.c    | 10 ++++++++--
>  src/dhcpv6-ia.c |  6 ++++++
>  src/odhcpd.h    |  1 +
>  4 files changed, 25 insertions(+), 10 deletions(-)
>
> diff --git a/README b/README
> index 0c562e6..a43f2e7 100644
> --- a/README
> +++ b/README
> @@ -57,14 +57,16 @@ and may also receive information from ubus
>
>  Section of type odhcpd
>
> -Option         Type    Default                 Description
> -legacy         bool    0                       Enable DHCPv4 if start but
> -                                               no dhcpv4 option set
> -maindhcp       bool    0                       Use odhcpd as the main DHCPv4
> -                                               service
> -leasefile      string                          DHCP/v6 lease/hostfile
> -leasetrigger   string                          Lease trigger script
> -loglevel       integer 6                       Syslog level priority (0-7)
> +Option                 Type    Default                 Description
> +legacy                 bool    0                       Enable DHCPv4 if start but
> +                                                       no dhcpv4 option set
> +maindhcp               bool    0                       Use odhcpd as the main DHCPv4
> +                                                       service
> +leasefile              string                          DHCP/v6 lease/hostfile
> +leasetrigger           string                          Lease trigger script
> +leasetrigger_mode      integer 0                       Lease trigger mode
> +                       0: lease with hostname changed, 1: any lease changed
> +loglevel               integer 6                       Syslog level priority (0-7)
>
>
>  Sections of type dhcp (configure DHCP / DHCPv6 / RA / NDP service)
> diff --git a/src/config.c b/src/config.c
> index 118349a..78488b7 100644
> --- a/src/config.c
> +++ b/src/config.c
> @@ -20,8 +20,8 @@ static int reload_pipe[2];
>  struct list_head leases = LIST_HEAD_INIT(leases);
>  struct list_head interfaces = LIST_HEAD_INIT(interfaces);
>  struct config config = {.legacy = false, .main_dhcpv4 = false,
> -                       .dhcp_cb = NULL, .dhcp_statefile = NULL,
> -                       .log_level = LOG_INFO};
> +                       .dhcp_cb = NULL, .dhcp_cb_mode = 0,
> +                       .dhcp_statefile = NULL, .log_level = LOG_INFO};
>
>  enum {
>         IFACE_ATTR_INTERFACE,
> @@ -149,6 +149,7 @@ enum {
>         ODHCPD_ATTR_MAINDHCP,
>         ODHCPD_ATTR_LEASEFILE,
>         ODHCPD_ATTR_LEASETRIGGER,
> +       ODHCPD_ATTR_LEASETRIGGER_MODE,
>         ODHCPD_ATTR_LOGLEVEL,
>         ODHCPD_ATTR_MAX
>  };
> @@ -158,6 +159,7 @@ static const struct blobmsg_policy odhcpd_attrs[LEASE_ATTR_MAX] = {
>         [ODHCPD_ATTR_MAINDHCP] = { .name = "maindhcp", .type = BLOBMSG_TYPE_BOOL },
>         [ODHCPD_ATTR_LEASEFILE] = { .name = "leasefile", .type = BLOBMSG_TYPE_STRING },
>         [ODHCPD_ATTR_LEASETRIGGER] = { .name = "leasetrigger", .type = BLOBMSG_TYPE_STRING },
> +       [ODHCPD_ATTR_LEASETRIGGER_MODE] = { .name = "leasetrigger_mode", .type = BLOBMSG_TYPE_INT32 },
>         [ODHCPD_ATTR_LOGLEVEL] = { .name = "loglevel", .type = BLOBMSG_TYPE_INT32 },
>  };
>
> @@ -290,6 +292,10 @@ static void set_config(struct uci_section *s)
>                 config.dhcp_cb = strdup(blobmsg_get_string(c));
>         }
>
> +       if ((c = tb[ODHCPD_ATTR_LEASETRIGGER_MODE])) {
> +               config.dhcp_cb_mode = blobmsg_get_u32(c);
> +       }
> +
>         if ((c = tb[ODHCPD_ATTR_LOGLEVEL])) {
>                 int log_level = (blobmsg_get_u32(c) & LOG_PRIMASK);
>
> diff --git a/src/dhcpv6-ia.c b/src/dhcpv6-ia.c
> index 4ee6dd2..e51be79 100644
> --- a/src/dhcpv6-ia.c
> +++ b/src/dhcpv6-ia.c
> @@ -408,6 +408,9 @@ void dhcpv6_write_statefile(void)
>
>                                         ctxt.buf[ctxt.buf_idx - 1] = '\n';
>                                         fwrite(ctxt.buf, 1, ctxt.buf_idx, ctxt.fp);
> +                                       if (config.dhcp_cb_mode > 0) {
> +                                               md5_hash(ctxt.buf, ctxt.buf_idx, &ctxt.md5);
> +                                       }
>                                 }
>                         }
>
> @@ -453,6 +456,9 @@ void dhcpv6_write_statefile(void)
>                                                                         "%s/32 ", ipbuf);
>                                         ctxt.buf[ctxt.buf_idx - 1] = '\n';
>                                         fwrite(ctxt.buf, 1, ctxt.buf_idx, ctxt.fp);
> +                                       if (config.dhcp_cb_mode > 0) {
> +                                               md5_hash(ctxt.buf, ctxt.buf_idx, &ctxt.md5);
> +                                       }
>                                 }
>                         }
>                 }
> diff --git a/src/odhcpd.h b/src/odhcpd.h
> index 91fdcbf..0f23667 100644
> --- a/src/odhcpd.h
> +++ b/src/odhcpd.h
> @@ -138,6 +138,7 @@ struct config {
>         bool legacy;
>         bool main_dhcpv4;
>         char *dhcp_cb;
> +       int dhcp_cb_mode;
>         char *dhcp_statefile;
>         int log_level;
>  } config;
> --
> 2.18.0
>
>
> _______________________________________________
> openwrt-devel mailing list
> openwrt-devel at lists.openwrt.org
> https://lists.openwrt.org/listinfo/openwrt-devel

_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


More information about the openwrt-devel mailing list