import of dnsmasq-2.44.tar.gz

This commit is contained in:
Simon Kelley
2008-07-20 15:10:39 +01:00
parent 1a6bca81f6
commit 3927da46aa
19 changed files with 339 additions and 281 deletions

View File

@@ -14,7 +14,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define VERSION "2.43"
#define VERSION "2.44"
#define FTABSIZ 150 /* max number of outstanding requests (default) */
#define MAX_PROCS 20 /* max no children for TCP requests */
@@ -245,8 +245,6 @@ typedef unsigned long in_addr_t;
#define HAVE_SOCKADDR_SA_LEN
/* Define before sys/socket.h is included so we get socklen_t */
#define _BSD_SOCKLEN_T_
/* This is not defined in Mac OS X arpa/nameserv.h */
#define IN6ADDRSZ 16
#elif defined(__NetBSD__)
#define HAVE_BSD_NETWORK

View File

@@ -248,9 +248,9 @@ int main (int argc, char **argv)
call safe_malloc */
if (ent_pw && ent_pw->pw_uid != 0)
{
hdr = safe_malloc(sizeof(*hdr));
int capsize = 1; /* for header version 1 */
hdr = safe_malloc(sizeof(*hdr));
/* find version supported by kernel */
memset(hdr, 0, sizeof(*hdr));
capget(hdr, NULL);

View File

@@ -33,10 +33,11 @@
#include <netinet/in.h>
#ifdef __APPLE__
/* need this before arpa/nameser.h */
# define BIND_8_COMPAT
# include <nameser.h>
# include <arpa/nameser_compat.h>
#else
# include <arpa/nameser.h>
#endif
#include <arpa/nameser.h>
/* and this. */
#include <getopt.h>
@@ -614,7 +615,8 @@ extern struct daemon {
struct server *last_server;
struct server *srv_save; /* Used for resend on DoD */
size_t packet_len; /* " " */
pid_t tcp_pids[MAX_PROCS];
struct randfd *rfd_save; /* " " */
pid_t tcp_pids[MAX_PROCS];
struct randfd randomsocks[RANDOM_SOCKS];
/* DHCP state */

View File

@@ -302,6 +302,7 @@ static int forward_query(int udpfd, union mysockaddr *udpaddr,
if (!forward->rfd6 &&
!(forward->rfd6 = allocate_rfd(AF_INET6)))
break;
daemon->rfd_save = forward->rfd6;
fd = forward->rfd6->fd;
}
else
@@ -310,6 +311,7 @@ static int forward_query(int udpfd, union mysockaddr *udpaddr,
if (!forward->rfd4 &&
!(forward->rfd4 = allocate_rfd(AF_INET)))
break;
daemon->rfd_save = forward->rfd4;
fd = forward->rfd4->fd;
}
}

View File

@@ -240,10 +240,20 @@ static void nl_routechange(struct nlmsghdr *h)
if (h->nlmsg_type == RTM_NEWROUTE && daemon->srv_save)
{
struct rtmsg *rtm = NLMSG_DATA(h);
if (rtm->rtm_type == RTN_UNICAST &&
rtm->rtm_scope == RT_SCOPE_LINK)
while(sendto(daemon->srv_save->sfd->fd, daemon->packet, daemon->packet_len, 0,
&daemon->srv_save->addr.sa, sa_len(&daemon->srv_save->addr)) == -1 && retry_send());
int fd;
if (rtm->rtm_type != RTN_UNICAST || rtm->rtm_scope != RT_SCOPE_LINK)
return;
if (daemon->srv_save->sfd)
fd = daemon->srv_save->sfd->fd;
else if (daemon->rfd_save && daemon->rfd_save->refcount != 0)
fd = daemon->rfd_save->fd;
else
return;
while(sendto(fd, daemon->packet, daemon->packet_len, 0,
&daemon->srv_save->addr.sa, sa_len(&daemon->srv_save->addr)) == -1 && retry_send());
}
}
#endif

View File

@@ -450,23 +450,25 @@ int random_sock(int family)
if ((fd = socket(family, SOCK_DGRAM, 0)) != -1)
{
union mysockaddr addr;
union mysockaddr addr;
unsigned short ports_avail = 65536u - (unsigned short)daemon->min_port;
int i;
memset(&addr, 0, sizeof(addr));
addr.in.sin_family = family;
addr.sa.sa_family = family;
if (fix_fd(fd))
while (1)
for (i = ports_avail; i != 0; i--)
{
unsigned short port = rand16();
if (port <= (unsigned short) daemon->min_port)
continue;
if (daemon->min_port != 0)
port = htons(daemon->min_port + (port % ports_avail));
if (family == AF_INET)
{
addr.in.sin_addr.s_addr = INADDR_ANY;
addr.in.sin_port = htons(port);
addr.in.sin_port = port;
#ifdef HAVE_SOCKADDR_SA_LEN
addr.in.sin_len = sizeof(struct sockaddr_in);
#endif
@@ -475,7 +477,7 @@ int random_sock(int family)
else
{
addr.in6.sin6_addr = in6addr_any;
addr.in6.sin6_port = htons(port);
addr.in6.sin6_port = port;
#ifdef HAVE_SOCKADDR_SA_LEN
addr.in6.sin6_len = sizeof(struct sockaddr_in6);
#endif

View File

@@ -1040,12 +1040,15 @@ size_t dhcp_reply(struct dhcp_context *context, char *iface_name, int int_index,
context->netid.next = netid;
netid = &context->netid;
}
if (lease && override.s_addr != 0)
lease->override = override;
else
override = lease->override;
if (lease)
{
if (override.s_addr != 0)
lease->override = override;
else
override = lease->override;
}
clear_packet(mess, end, agent_id);
option_put(mess, end, OPTION_MESSAGE_TYPE, 1, DHCPACK);
option_put(mess, end, OPTION_SERVER_IDENTIFIER, INADDRSZ, ntohl(server_id(context, override).s_addr));
@@ -1123,9 +1126,9 @@ static unsigned int calc_time(struct dhcp_context *context, struct dhcp_config *
static struct in_addr server_id(struct dhcp_context *context, struct in_addr override)
{
if (override.s_addr != 0)
if (override.s_addr != 0 || !context)
return override;
else
else
return context->local;
}