version 1.1.1.4, 2021/03/17 00:56:46
|
version 1.1.1.5, 2023/09/27 11:02:07
|
Line 1
|
Line 1
|
/* dnsmasq is Copyright (c) 2000-2021 Simon Kelley | /* dnsmasq is Copyright (c) 2000-2022 Simon Kelley |
|
|
This program is free software; you can redistribute it and/or modify |
This program is free software; you can redistribute it and/or modify |
it under the terms of the GNU General Public License as published by |
it under the terms of the GNU General Public License as published by |
Line 233 int create_helper(int event_fd, int err_fd, uid_t uid,
|
Line 233 int create_helper(int event_fd, int err_fd, uid_t uid,
|
is6 = (data.flags != AF_INET); |
is6 = (data.flags != AF_INET); |
data.action = ACTION_ARP; |
data.action = ACTION_ARP; |
} |
} |
else | else if (data.action == ACTION_RELAY_SNOOP) |
continue; | { |
| is6 = 1; |
| action_str = "relay-snoop"; |
| } |
| else |
| continue; |
|
|
/* stringify MAC into dhcp_buff */ |
/* stringify MAC into dhcp_buff */ |
p = daemon->dhcp_buff; |
p = daemon->dhcp_buff; |
Line 287 int create_helper(int event_fd, int err_fd, uid_t uid,
|
Line 291 int create_helper(int event_fd, int err_fd, uid_t uid,
|
char *dot; |
char *dot; |
hostname = (char *)buf; |
hostname = (char *)buf; |
hostname[data.hostname_len - 1] = 0; |
hostname[data.hostname_len - 1] = 0; |
if (data.action != ACTION_TFTP) | if (data.action != ACTION_TFTP && data.action != ACTION_RELAY_SNOOP) |
{ |
{ |
if (!legal_hostname(hostname)) |
if (!legal_hostname(hostname)) |
hostname = NULL; |
hostname = NULL; |
Line 333 int create_helper(int event_fd, int err_fd, uid_t uid,
|
Line 337 int create_helper(int event_fd, int err_fd, uid_t uid,
|
lua_call(lua, 2, 0); /* pass 2 values, expect 0 */ |
lua_call(lua, 2, 0); /* pass 2 values, expect 0 */ |
} |
} |
} |
} |
|
else if (data.action == ACTION_RELAY_SNOOP) |
|
{ |
|
lua_getglobal(lua, "snoop"); |
|
if (lua_type(lua, -1) != LUA_TFUNCTION) |
|
lua_pop(lua, 1); /* tftp function optional */ |
|
else |
|
{ |
|
lua_pushstring(lua, action_str); /* arg1 - action */ |
|
lua_newtable(lua); /* arg2 - data table */ |
|
lua_pushstring(lua, daemon->addrbuff); |
|
lua_setfield(lua, -2, "client_address"); |
|
lua_pushstring(lua, hostname); |
|
lua_setfield(lua, -2, "prefix"); |
|
lua_pushstring(lua, data.interface); |
|
lua_setfield(lua, -2, "client_interface"); |
|
lua_call(lua, 2, 0); /* pass 2 values, expect 0 */ |
|
} |
|
} |
else if (data.action == ACTION_ARP) |
else if (data.action == ACTION_ARP) |
{ |
{ |
lua_getglobal(lua, "arp"); |
lua_getglobal(lua, "arp"); |
Line 399 int create_helper(int event_fd, int err_fd, uid_t uid,
|
Line 421 int create_helper(int event_fd, int err_fd, uid_t uid,
|
|
|
end = extradata + data.ed_len; |
end = extradata + data.ed_len; |
buf = extradata; |
buf = extradata; |
|
|
|
lua_pushnumber(lua, data.ed_len == 0 ? 1 : 0); |
|
lua_setfield(lua, -2, "data_missing"); |
|
|
if (!is6) |
if (!is6) |
buf = grab_extradata_lua(buf, end, "vendor_class"); |
buf = grab_extradata_lua(buf, end, "vendor_class"); |
Line 426 int create_helper(int event_fd, int err_fd, uid_t uid,
|
Line 451 int create_helper(int event_fd, int err_fd, uid_t uid,
|
buf = grab_extradata_lua(buf, end, "subscriber_id"); |
buf = grab_extradata_lua(buf, end, "subscriber_id"); |
buf = grab_extradata_lua(buf, end, "remote_id"); |
buf = grab_extradata_lua(buf, end, "remote_id"); |
} |
} |
| |
| buf = grab_extradata_lua(buf, end, "requested_options"); |
| buf = grab_extradata_lua(buf, end, "mud_url"); |
buf = grab_extradata_lua(buf, end, "tags"); |
buf = grab_extradata_lua(buf, end, "tags"); |
|
|
if (is6) |
if (is6) |
buf = grab_extradata_lua(buf, end, "relay_address"); |
buf = grab_extradata_lua(buf, end, "relay_address"); |
else if (data.giaddr.s_addr != 0) |
else if (data.giaddr.s_addr != 0) |
{ |
{ |
lua_pushstring(lua, inet_ntoa(data.giaddr)); | inet_ntop(AF_INET, &data.giaddr, daemon->dhcp_buff2, ADDRSTRLEN); |
| lua_pushstring(lua, daemon->dhcp_buff2); |
lua_setfield(lua, -2, "relay_address"); |
lua_setfield(lua, -2, "relay_address"); |
} |
} |
|
|
Line 553 int create_helper(int event_fd, int err_fd, uid_t uid,
|
Line 581 int create_helper(int event_fd, int err_fd, uid_t uid,
|
close(pipeout[1]); |
close(pipeout[1]); |
} |
} |
|
|
if (data.action != ACTION_TFTP && data.action != ACTION_ARP) | if (data.action != ACTION_TFTP && data.action != ACTION_ARP && data.action != ACTION_RELAY_SNOOP) |
{ |
{ |
#ifdef HAVE_DHCP6 |
#ifdef HAVE_DHCP6 |
my_setenv("DNSMASQ_IAID", is6 ? daemon->dhcp_buff3 : NULL, &err); |
my_setenv("DNSMASQ_IAID", is6 ? daemon->dhcp_buff3 : NULL, &err); |
Line 576 int create_helper(int event_fd, int err_fd, uid_t uid,
|
Line 604 int create_helper(int event_fd, int err_fd, uid_t uid,
|
|
|
end = extradata + data.ed_len; |
end = extradata + data.ed_len; |
buf = extradata; |
buf = extradata; |
|
|
|
if (data.ed_len == 0) |
|
my_setenv("DNSMASQ_DATA_MISSING", "1", &err); |
|
|
if (!is6) |
if (!is6) |
buf = grab_extradata(buf, end, "DNSMASQ_VENDOR_CLASS", &err); |
buf = grab_extradata(buf, end, "DNSMASQ_VENDOR_CLASS", &err); |
Line 604 int create_helper(int event_fd, int err_fd, uid_t uid,
|
Line 635 int create_helper(int event_fd, int err_fd, uid_t uid,
|
buf = grab_extradata(buf, end, "DNSMASQ_CIRCUIT_ID", &err); |
buf = grab_extradata(buf, end, "DNSMASQ_CIRCUIT_ID", &err); |
buf = grab_extradata(buf, end, "DNSMASQ_SUBSCRIBER_ID", &err); |
buf = grab_extradata(buf, end, "DNSMASQ_SUBSCRIBER_ID", &err); |
buf = grab_extradata(buf, end, "DNSMASQ_REMOTE_ID", &err); |
buf = grab_extradata(buf, end, "DNSMASQ_REMOTE_ID", &err); |
buf = grab_extradata(buf, end, "DNSMASQ_REQUESTED_OPTIONS", &err); |
|
} |
} |
|
|
|
buf = grab_extradata(buf, end, "DNSMASQ_REQUESTED_OPTIONS", &err); |
|
buf = grab_extradata(buf, end, "DNSMASQ_MUD_URL", &err); |
buf = grab_extradata(buf, end, "DNSMASQ_TAGS", &err); |
buf = grab_extradata(buf, end, "DNSMASQ_TAGS", &err); |
| |
if (is6) |
if (is6) |
buf = grab_extradata(buf, end, "DNSMASQ_RELAY_ADDRESS", &err); |
buf = grab_extradata(buf, end, "DNSMASQ_RELAY_ADDRESS", &err); |
else | else |
my_setenv("DNSMASQ_RELAY_ADDRESS", data.giaddr.s_addr != 0 ? inet_ntoa(data.giaddr) : NULL, &err); | { |
| const char *giaddr = NULL; |
| if (data.giaddr.s_addr != 0) |
| giaddr = inet_ntop(AF_INET, &data.giaddr, daemon->dhcp_buff2, ADDRSTRLEN); |
| my_setenv("DNSMASQ_RELAY_ADDRESS", giaddr, &err); |
| } |
|
|
for (i = 0; buf; i++) |
for (i = 0; buf; i++) |
{ |
{ |
Line 635 int create_helper(int event_fd, int err_fd, uid_t uid,
|
Line 672 int create_helper(int event_fd, int err_fd, uid_t uid,
|
fcntl(event_fd, F_SETFD, i | FD_CLOEXEC); |
fcntl(event_fd, F_SETFD, i | FD_CLOEXEC); |
close(pipefd[0]); |
close(pipefd[0]); |
|
|
|
if (data.action == ACTION_RELAY_SNOOP) |
|
strcpy(daemon->packet, data.interface); |
|
|
p = strrchr(daemon->lease_change_command, '/'); |
p = strrchr(daemon->lease_change_command, '/'); |
if (err == 0) |
if (err == 0) |
{ |
{ |
Line 805 void queue_script(int action, struct dhcp_lease *lease
|
Line 845 void queue_script(int action, struct dhcp_lease *lease
|
bytes_in_buf = p - (unsigned char *)buf; |
bytes_in_buf = p - (unsigned char *)buf; |
} |
} |
|
|
|
#ifdef HAVE_DHCP6 |
|
void queue_relay_snoop(struct in6_addr *client, int if_index, struct in6_addr *prefix, int prefix_len) |
|
{ |
|
/* no script */ |
|
if (daemon->helperfd == -1) |
|
return; |
|
|
|
inet_ntop(AF_INET6, prefix, daemon->addrbuff, ADDRSTRLEN); |
|
|
|
/* 5 for /nnn and zero on the end of the prefix. */ |
|
buff_alloc(sizeof(struct script_data) + ADDRSTRLEN + 5); |
|
memset(buf, 0, sizeof(struct script_data)); |
|
|
|
buf->action = ACTION_RELAY_SNOOP; |
|
buf->addr6 = *client; |
|
buf->hostname_len = sprintf((char *)(buf+1), "%s/%u", daemon->addrbuff, prefix_len) + 1; |
|
|
|
indextoname(daemon->dhcp6fd, if_index, buf->interface); |
|
|
|
bytes_in_buf = sizeof(struct script_data) + buf->hostname_len; |
|
} |
|
#endif |
|
|
#ifdef HAVE_TFTP |
#ifdef HAVE_TFTP |
/* This nastily re-uses DHCP-fields for TFTP stuff */ |
/* This nastily re-uses DHCP-fields for TFTP stuff */ |
void queue_tftp(off_t file_len, char *filename, union mysockaddr *peer) |
void queue_tftp(off_t file_len, char *filename, union mysockaddr *peer) |
Line 882 void helper_write(void)
|
Line 945 void helper_write(void)
|
} |
} |
} |
} |
|
|
#endif | #endif /* HAVE_SCRIPT */ |
| |
| |
| |