diff options
-rw-r--r-- | man/dnsmasq.8 | 39 | ||||
-rw-r--r-- | src/helper.c | 6 | ||||
-rw-r--r-- | src/rfc2131.c | 2 |
3 files changed, 42 insertions, 5 deletions
diff --git a/man/dnsmasq.8 b/man/dnsmasq.8 index 39b2251..3c761df 100644 --- a/man/dnsmasq.8 +++ b/man/dnsmasq.8 @@ -1082,7 +1082,7 @@ If the client provides vendor-class, DNSMASQ_VENDOR_CLASS_ID, containing the IANA enterprise id for the class, and DNSMASQ_VENDOR_CLASS0..DNSMASQ_VENDOR_CLASSn for the data. -DNSMASQ_DUID containing the DUID of the server: this is the same for +DNSMASQ_SERVER_DUID containing the DUID of the server: this is the same for every call to the script. DNSMASQ_IAID containing the IAID for the lease. If the lease is a @@ -1115,8 +1115,43 @@ leases will be called with "del" and others with "old". When dnsmasq receives a HUP signal, the script will be invoked for existing leases with an "old " event. .TP +.B --dhcp-luascript=<path> +Specify a script written in Lua, to be run when leases are created, +destroyed or changed. To use this option, dnsmasq must be compiled +with the correct support. The Lua interpreter is intialised once, when +dnsmasq starts, so that global variables persist between lease +events. The Lua code must define a +.B lease +function, and may provide +.B init +and +.B shutdown +functions, which are called, without arguments when dnsmasq starts up +and terminates. + +The +.B lease +method receives the information detailed in +.B --dhcp-script. +It gets two arguments, firstly the action, which is a string +containing, "add", "old" or "del", and secondly a table of tag value +pairs. The tags mostly correspond to the environment variables +detailed above, for instance the tag "domain" holds the same data as +the environment variable DNSMASQ_DOMAIN. There are a few extra tags +which hold the data supplied as arguments to +.B --dhcp-script. +These are +.B mac_address, ip_address +and +.B hostname +for IPv4, and +.B client_duid, ip_address +and +.B hostname +for IPv6. +.TP .B --dhcp-scriptuser -Specify the user as which to run the lease-change script. This defaults to root, but can be changed to another user using this flag. +Specify the user as which to run the lease-change script or Lua script. This defaults to root, but can be changed to another user using this flag. .TP .B \-9, --leasefile-ro Completely suppress use of the lease database file. The file will not diff --git a/src/helper.c b/src/helper.c index a465bcf..135111d 100644 --- a/src/helper.c +++ b/src/helper.c @@ -298,8 +298,10 @@ int create_helper(int event_fd, int err_fd, uid_t uid, gid_t gid, long max_fd) if (is6) { + lua_pushstring(lua, daemon->dhcp_buff); + lua_setfield(lua, -2, "client_duid"); lua_pushstring(lua, daemon->packet); - lua_setfield(lua, -2, "duid"); + lua_setfield(lua, -2, "server_duid"); lua_pushstring(lua, daemon->dhcp_buff3); lua_setfield(lua, -2, "iaid"); } @@ -440,7 +442,7 @@ int create_helper(int event_fd, int err_fd, uid_t uid, gid_t gid, long max_fd) if (is6) { my_setenv("DNSMASQ_IAID", daemon->dhcp_buff3, &err); - my_setenv("DNSMASQ_DUID", daemon->packet, &err); + my_setenv("DNSMASQ_SERVER_DUID", daemon->packet, &err); } if (!is6 && data.clid_len != 0) diff --git a/src/rfc2131.c b/src/rfc2131.c index 0dc06ab..39edf78 100644 --- a/src/rfc2131.c +++ b/src/rfc2131.c @@ -2096,7 +2096,7 @@ static void do_options(struct dhcp_context *context, /* filter options based on tags, those we want get DHOPT_TAGOK bit set */ context->netid.next = NULL; - tagif = option_filter(netid, context->netid.net ? &context->netid : NULL, config_opts); + tagif = option_filter(netid, context && context->netid.net ? &context->netid : NULL, config_opts); /* logging */ if (option_bool(OPT_LOG_OPTS) && req_options) |