mirror of
http://thekelleys.org.uk/git/dnsmasq.git
synced 2026-11-22 20:11:55 +00:00
Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
57f460de2f | ||
|
|
6caacacf6d | ||
|
|
60ac5af682 | ||
|
|
caa94380ac |
No files matched your search
+37
-2
@@ -1082,7 +1082,7 @@ If the client provides vendor-class, DNSMASQ_VENDOR_CLASS_ID,
|
|||||||
containing the IANA enterprise id for the class, and
|
containing the IANA enterprise id for the class, and
|
||||||
DNSMASQ_VENDOR_CLASS0..DNSMASQ_VENDOR_CLASSn for the data.
|
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.
|
every call to the script.
|
||||||
|
|
||||||
DNSMASQ_IAID containing the IAID for the lease. If the lease is a
|
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
|
receives a HUP signal, the script will be invoked for existing leases
|
||||||
with an "old " event.
|
with an "old " event.
|
||||||
.TP
|
.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
|
.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
|
.TP
|
||||||
.B \-9, --leasefile-ro
|
.B \-9, --leasefile-ro
|
||||||
Completely suppress use of the lease database file. The file will not
|
Completely suppress use of the lease database file. The file will not
|
||||||
|
|||||||
+1
-1
@@ -102,7 +102,7 @@ struct dhcp_netid *option_filter(struct dhcp_netid *tags, struct dhcp_netid *con
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* now flag options which are valid, including the context tags,
|
/* now flag options which are valid, including the context tags,
|
||||||
otherwise valid options are inhibited if we found a higher priotity one above */
|
otherwise valid options are inhibited if we found a higher priority one above */
|
||||||
if (context_tags)
|
if (context_tags)
|
||||||
{
|
{
|
||||||
struct dhcp_netid *last_tag;
|
struct dhcp_netid *last_tag;
|
||||||
|
|||||||
+5
-51
@@ -408,43 +408,17 @@ struct dhcp_config *find_config6(struct dhcp_config *configs,
|
|||||||
unsigned char *duid, int duid_len,
|
unsigned char *duid, int duid_len,
|
||||||
char *hostname)
|
char *hostname)
|
||||||
{
|
{
|
||||||
int count, new;
|
|
||||||
struct dhcp_config *config;
|
struct dhcp_config *config;
|
||||||
struct hwaddr_config *conf_addr;
|
|
||||||
unsigned char *hwaddr = NULL;
|
|
||||||
int duid_type, hw_len = 0, hw_type = 0;
|
|
||||||
|
|
||||||
if (duid)
|
if (duid)
|
||||||
{
|
for (config = configs; config; config = config->next)
|
||||||
for (config = configs; config; config = config->next)
|
if (config->flags & CONFIG_CLID)
|
||||||
if (config->flags & CONFIG_CLID)
|
|
||||||
{
|
|
||||||
if (config->clid_len == duid_len &&
|
|
||||||
memcmp(config->clid, duid, duid_len) == 0 &&
|
|
||||||
is_addr_in_context6(context, config))
|
|
||||||
return config;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* DHCPv6 doesn't deal in MAC addresses per-se, but some DUIDs do include
|
|
||||||
MAC addresses, so we try and parse them out here. Not that there is only one
|
|
||||||
DUID per host and it's created using any one of the MACs, so this is no
|
|
||||||
good no good for multihomed hosts. */
|
|
||||||
hwaddr = duid;
|
|
||||||
GETSHORT(duid_type, hwaddr);
|
|
||||||
if (duid_type == 1 || duid_type == 3)
|
|
||||||
{
|
{
|
||||||
GETSHORT(hw_type, hwaddr);
|
if (config->clid_len == duid_len &&
|
||||||
if (duid_type == 1)
|
memcmp(config->clid, duid, duid_len) == 0 &&
|
||||||
hwaddr += 4; /* skip time */
|
|
||||||
hw_len = duid_len - 8;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hwaddr)
|
|
||||||
for (config = configs; config; config = config->next)
|
|
||||||
if (config_has_mac(config, hwaddr, hw_len, hw_type) &&
|
|
||||||
is_addr_in_context6(context, config))
|
is_addr_in_context6(context, config))
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hostname && context)
|
if (hostname && context)
|
||||||
for (config = configs; config; config = config->next)
|
for (config = configs; config; config = config->next)
|
||||||
@@ -453,26 +427,6 @@ struct dhcp_config *find_config6(struct dhcp_config *configs,
|
|||||||
is_addr_in_context6(context, config))
|
is_addr_in_context6(context, config))
|
||||||
return config;
|
return config;
|
||||||
|
|
||||||
/* use match with fewest wildcard octets */
|
|
||||||
if (hwaddr)
|
|
||||||
{
|
|
||||||
struct dhcp_config *candidate;
|
|
||||||
|
|
||||||
for (candidate = NULL, count = 0, config = configs; config; config = config->next)
|
|
||||||
if (is_addr_in_context6(context, config))
|
|
||||||
for (conf_addr = config->hwaddr; conf_addr; conf_addr = conf_addr->next)
|
|
||||||
if (conf_addr->wildcard_mask != 0 &&
|
|
||||||
conf_addr->hwaddr_len == hw_len &&
|
|
||||||
(conf_addr->hwaddr_type == hw_type || conf_addr->hwaddr_type == 0) &&
|
|
||||||
(new = memcmp_masked(conf_addr->hwaddr, hwaddr, hw_len, conf_addr->wildcard_mask)) > count)
|
|
||||||
{
|
|
||||||
count = new;
|
|
||||||
candidate = config;
|
|
||||||
}
|
|
||||||
|
|
||||||
return candidate;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+22
-23
@@ -217,18 +217,6 @@ int create_helper(int event_fd, int err_fd, uid_t uid, gid_t gid, long max_fd)
|
|||||||
p += sprintf(p, ":");
|
p += sprintf(p, ":");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifdef HAVE_DHCP6
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* duid not MAC for IPv6 */
|
|
||||||
for (p = daemon->dhcp_buff, i = 0; i < data.clid_len; i++)
|
|
||||||
{
|
|
||||||
p += sprintf(p, "%.2x", buf[i]);
|
|
||||||
if (i != data.clid_len - 1)
|
|
||||||
p += sprintf(p, ":");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* expiry or length into dhcp_buff2 */
|
/* expiry or length into dhcp_buff2 */
|
||||||
#ifdef HAVE_BROKEN_RTC
|
#ifdef HAVE_BROKEN_RTC
|
||||||
@@ -265,6 +253,14 @@ int create_helper(int event_fd, int err_fd, uid_t uid, gid_t gid, long max_fd)
|
|||||||
if (i != daemon->duid_len - 1)
|
if (i != daemon->duid_len - 1)
|
||||||
p += sprintf(p, ":");
|
p += sprintf(p, ":");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* duid not MAC for IPv6 */
|
||||||
|
for (p = daemon->dhcp_buff, i = 0; i < data.clid_len; i++)
|
||||||
|
{
|
||||||
|
p += sprintf(p, "%.2x", buf[i]);
|
||||||
|
if (i != data.clid_len - 1)
|
||||||
|
p += sprintf(p, ":");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -302,8 +298,10 @@ int create_helper(int event_fd, int err_fd, uid_t uid, gid_t gid, long max_fd)
|
|||||||
|
|
||||||
if (is6)
|
if (is6)
|
||||||
{
|
{
|
||||||
|
lua_pushstring(lua, daemon->dhcp_buff);
|
||||||
|
lua_setfield(lua, -2, "client_duid");
|
||||||
lua_pushstring(lua, daemon->packet);
|
lua_pushstring(lua, daemon->packet);
|
||||||
lua_setfield(lua, -2, "duid");
|
lua_setfield(lua, -2, "server_duid");
|
||||||
lua_pushstring(lua, daemon->dhcp_buff3);
|
lua_pushstring(lua, daemon->dhcp_buff3);
|
||||||
lua_setfield(lua, -2, "iaid");
|
lua_setfield(lua, -2, "iaid");
|
||||||
}
|
}
|
||||||
@@ -365,18 +363,20 @@ int create_helper(int event_fd, int err_fd, uid_t uid, gid_t gid, long max_fd)
|
|||||||
|
|
||||||
buf = grab_extradata_lua(buf, end, "tags");
|
buf = grab_extradata_lua(buf, end, "tags");
|
||||||
|
|
||||||
|
if (is6)
|
||||||
|
buf = grab_extradata_lua(buf, end, "relay_address");
|
||||||
|
else if (data.giaddr.s_addr != 0)
|
||||||
|
{
|
||||||
|
lua_pushstring(lua, inet_ntoa(data.giaddr));
|
||||||
|
lua_setfield(lua, -2, "relay_address");
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 0; buf; i++)
|
for (i = 0; buf; i++)
|
||||||
{
|
{
|
||||||
sprintf(daemon->dhcp_buff2, "user_class%i", i);
|
sprintf(daemon->dhcp_buff2, "user_class%i", i);
|
||||||
buf = grab_extradata_lua(buf, end, daemon->dhcp_buff2);
|
buf = grab_extradata_lua(buf, end, daemon->dhcp_buff2);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is6 && data.giaddr.s_addr != 0)
|
|
||||||
{
|
|
||||||
lua_pushstring(lua, inet_ntoa(data.giaddr));
|
|
||||||
lua_setfield(lua, -2, "relay_address");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (data.action != ACTION_DEL && data.remaining_time != 0)
|
if (data.action != ACTION_DEL && data.remaining_time != 0)
|
||||||
{
|
{
|
||||||
lua_pushnumber(lua, data.remaining_time);
|
lua_pushnumber(lua, data.remaining_time);
|
||||||
@@ -442,7 +442,7 @@ int create_helper(int event_fd, int err_fd, uid_t uid, gid_t gid, long max_fd)
|
|||||||
if (is6)
|
if (is6)
|
||||||
{
|
{
|
||||||
my_setenv("DNSMASQ_IAID", daemon->dhcp_buff3, &err);
|
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)
|
if (!is6 && data.clid_len != 0)
|
||||||
@@ -493,6 +493,8 @@ int create_helper(int event_fd, int err_fd, uid_t uid, gid_t gid, long max_fd)
|
|||||||
|
|
||||||
if (is6)
|
if (is6)
|
||||||
buf = grab_extradata(buf, end, "DNSMASQ_RELAY_ADDRESS", &err);
|
buf = grab_extradata(buf, end, "DNSMASQ_RELAY_ADDRESS", &err);
|
||||||
|
else if (data.giaddr.s_addr != 0)
|
||||||
|
my_setenv("DNSMASQ_RELAY_ADDRESS", inet_ntoa(data.giaddr), &err);
|
||||||
|
|
||||||
for (i = 0; buf; i++)
|
for (i = 0; buf; i++)
|
||||||
{
|
{
|
||||||
@@ -500,9 +502,6 @@ int create_helper(int event_fd, int err_fd, uid_t uid, gid_t gid, long max_fd)
|
|||||||
buf = grab_extradata(buf, end, daemon->dhcp_buff2, &err);
|
buf = grab_extradata(buf, end, daemon->dhcp_buff2, &err);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is6 && data.giaddr.s_addr != 0)
|
|
||||||
my_setenv("DNSMASQ_RELAY_ADDRESS", inet_ntoa(data.giaddr), &err);
|
|
||||||
|
|
||||||
if (data.action != ACTION_DEL && data.remaining_time != 0)
|
if (data.action != ACTION_DEL && data.remaining_time != 0)
|
||||||
{
|
{
|
||||||
sprintf(daemon->dhcp_buff2, "%u", data.remaining_time);
|
sprintf(daemon->dhcp_buff2, "%u", data.remaining_time);
|
||||||
|
|||||||
+1
-2
@@ -504,10 +504,9 @@ u64 lease_find_max_addr6(struct dhcp_context *context)
|
|||||||
if (!(context->flags & (CONTEXT_STATIC | CONTEXT_PROXY)))
|
if (!(context->flags & (CONTEXT_STATIC | CONTEXT_PROXY)))
|
||||||
for (lease = leases; lease; lease = lease->next)
|
for (lease = leases; lease; lease = lease->next)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_DHCP6
|
|
||||||
if (!(lease->flags & (LEASE_TA | LEASE_NA)))
|
if (!(lease->flags & (LEASE_TA | LEASE_NA)))
|
||||||
continue;
|
continue;
|
||||||
#endif
|
|
||||||
if (is_same_net6((struct in6_addr *)lease->hwaddr, &context->start6, 64) &&
|
if (is_same_net6((struct in6_addr *)lease->hwaddr, &context->start6, 64) &&
|
||||||
addr6part((struct in6_addr *)lease->hwaddr) > addr6part(&context->start6) &&
|
addr6part((struct in6_addr *)lease->hwaddr) > addr6part(&context->start6) &&
|
||||||
addr6part((struct in6_addr *)lease->hwaddr) <= addr6part(&context->end6) &&
|
addr6part((struct in6_addr *)lease->hwaddr) <= addr6part(&context->end6) &&
|
||||||
|
|||||||
+2
-1
@@ -2095,7 +2095,8 @@ static void do_options(struct dhcp_context *context,
|
|||||||
struct dhcp_netid_list *id_list;
|
struct dhcp_netid_list *id_list;
|
||||||
|
|
||||||
/* filter options based on tags, those we want get DHOPT_TAGOK bit set */
|
/* filter options based on tags, those we want get DHOPT_TAGOK bit set */
|
||||||
tagif = option_filter(netid, &context->netid, config_opts);
|
context->netid.next = NULL;
|
||||||
|
tagif = option_filter(netid, context && context->netid.net ? &context->netid : NULL, config_opts);
|
||||||
|
|
||||||
/* logging */
|
/* logging */
|
||||||
if (option_bool(OPT_LOG_OPTS) && req_options)
|
if (option_bool(OPT_LOG_OPTS) && req_options)
|
||||||
|
|||||||
Reference in new issue
Block a user