]> git.pld-linux.org Git - packages/djbdns.git/commitdiff
- new version of patch by Tomasz Grobelny
authorjm <jm@pld-linux.org>
Thu, 30 Sep 2004 23:06:07 +0000 (23:06 +0000)
committercvs2git <feedback@pld-linux.org>
Sun, 24 Jun 2012 12:13:13 +0000 (12:13 +0000)
Changed files:
    dnscache-1.05-multiple-ip.patch -> 1.3

dnscache-1.05-multiple-ip.patch [new file with mode: 0644]

diff --git a/dnscache-1.05-multiple-ip.patch b/dnscache-1.05-multiple-ip.patch
new file mode 100644 (file)
index 0000000..2dc6ab1
--- /dev/null
@@ -0,0 +1,322 @@
+diff -urN djbdns-1.05.org/MULTIPLEIP djbdns-1.05/MULTIPLEIP
+--- djbdns-1.05.org/MULTIPLEIP  Thu Jan  1 01:00:00 1970
++++ djbdns-1.05/MULTIPLEIP  Sat Apr 28 22:15:42 2001
+@@ -0,0 +1,10 @@
++
++When applied, dnscache will accept a /-delimited list of IP address in $IP
++and bind to each in turn. This allows one to have dnscache listen on, say,
++external IP 1.2.3.4 which only client group A can reach, and, say,
++internal IP 4.3.2.1 which only client group B can reach. Assuming 1.2.3.4
++and 4.3.2.1 are on the same machine, instead of running two independent
++dnscache instances on 1.2.3.4 and 4.3.2.1, one instance can bind to both
++IP's and serve queries from the shared cache. Simply put 1.2.3.4/4.3.2.1 in env/IP.
++
++http://danp.net/djbdns/patches.html
+diff -r -u djbdns+ipv6/dnscache.c djbdns-1.05/dnscache.c
+--- djbdns+ipv6/dnscache.c     2004-09-29 21:17:03.000000000 +0200
++++ djbdns-1.05/dnscache.c     2004-09-29 22:02:38.018542064 +0200
+@@ -6,6 +6,7 @@
+ #include "error.h"
+ #include "ip4.h"
+ #include "ip6.h"
++#include "str.h"
+ #include "uint16.h"
+ #include "uint64.h"
+ #include "socket.h"
+@@ -52,12 +53,20 @@
+ static char myipoutgoing[16];
+-static char myipincoming[16];
+ static char buf[1024];
+ uint64 numqueries = 0;
++struct interf {
++  char ip[16];
++  int udp53;
++  int tcp53;
++  iopause_fd *udp53io;
++  iopause_fd *tcp53io;
++
++  struct interf *next;
++};
+-static int udp53;
++struct interf *interhead = 0;
+ #define MAXUDP 200
+ static struct udpclient {
+@@ -65,6 +74,7 @@
+   struct taia start;
+   uint64 active; /* query number, if active; otherwise 0 */
+   iopause_fd *io;
++  int fd;
+   char ip[16];
+   uint16 port;
+   char id[2];
+@@ -84,12 +94,12 @@
+   if (!u[j].active) return;
+   response_id(u[j].id);
+   if (response_len > 512) response_tc();
+-  socket_send6(udp53,response,response_len,u[j].ip,u[j].port,u[j].scope_id);
++  socket_send6(u[j].fd,response,response_len,u[j].ip,u[j].port,u[j].scope_id);
+   log_querydone(&u[j].active,response_len);
+   u[j].active = 0; --uactive;
+ }
+-void u_new(void)
++void u_new(int fd)
+ {
+   int j;
+   int i;
+@@ -114,8 +124,9 @@
+   x = u + j;
+   taia_now(&x->start);
++  x->fd=fd;
+-  len = socket_recv6(udp53,buf,sizeof buf,x->ip,&x->port,&x->scope_id);
++  len = socket_recv6(x->fd,buf,sizeof buf,x->ip,&x->port,&x->scope_id);
+   if (len == -1) return;
+   if (len >= sizeof buf) return;
+   if (x->port < 1024) if (x->port != 53) return;
+@@ -134,8 +145,6 @@
+   }
+ }
+-static int tcp53;
+-
+ #define MAXTCP 20
+ struct tcpclient {
+   struct query q;
+@@ -143,6 +152,7 @@
+   struct taia timeout;
+   uint64 active; /* query number or 1, if active; otherwise 0 */
+   iopause_fd *io;
++  int fd;
+   char ip[16]; /* send response to this address */
+   uint16 port; /* send response to this port */
+   char id[2];
+@@ -272,7 +282,7 @@
+   x->state = 0;
+ }
+-void t_new(void)
++void t_new(int fd)
+ {
+   int i;
+   int j;
+@@ -296,8 +306,9 @@
+   x = t + j;
+   taia_now(&x->start);
++  x->fd=fd;
+-  x->tcp = socket_accept6(tcp53,x->ip,&x->port,&x->scope_id);
++  x->tcp = socket_accept6(x->fd,x->ip,&x->port,&x->scope_id);
+   if (x->tcp == -1) return;
+   if (x->port < 1024) if (x->port != 53) { close(x->tcp); return; }
+   if (!okclient(x->ip)) { close(x->tcp); return; }
+@@ -310,19 +321,24 @@
+   log_tcpopen(x->ip,x->port);
+ }
++#define FATAL "dnscache: fatal: "
+-iopause_fd io[3 + MAXUDP + MAXTCP];
+-iopause_fd *udp53io;
+-iopause_fd *tcp53io;
++iopause_fd *io = 0;
++int numio;
+ static void doit(void)
+ {
+   int j;
+   struct taia deadline;
+   struct taia stamp;
++  struct interf *inter;
+   int iolen;
+   int r;
++  io = (iopause_fd *) alloc((numio + 1 + MAXUDP + MAXTCP) * sizeof(iopause_fd));
++  if (!io)
++    strerr_die2sys(111,FATAL,"unable to alloc io: ");
++
+   for (;;) {
+     taia_now(&stamp);
+     taia_uint(&deadline,120);
+@@ -330,13 +346,15 @@
+     iolen = 0;
+-    udp53io = io + iolen++;
+-    udp53io->fd = udp53;
+-    udp53io->events = IOPAUSE_READ;
+-
+-    tcp53io = io + iolen++;
+-    tcp53io->fd = tcp53;
+-    tcp53io->events = IOPAUSE_READ;
++    for (inter = interhead; inter != 0; inter = inter->next) {
++      inter->udp53io = io + iolen++;
++      inter->udp53io->fd = inter->udp53;
++      inter->udp53io->events = IOPAUSE_READ;
++
++      inter->tcp53io = io + iolen++;
++      inter->tcp53io->fd = inter->tcp53;
++      inter->tcp53io->events = IOPAUSE_READ;
++    }
+     for (j = 0;j < MAXUDP;++j)
+       if (u[j].active) {
+@@ -378,23 +396,30 @@
+           t_rw(j);
+       }
+-    if (udp53io)
+-      if (udp53io->revents)
+-      u_new();
+-
+-    if (tcp53io)
+-      if (tcp53io->revents)
+-      t_new();
+-  }
++    for (inter = interhead; inter != 0; inter = inter->next) {
++        if (inter->udp53io)
++          if (inter->udp53io->revents)
++            u_new(inter->udp53);
++      
++      if (inter->tcp53io)
++          if (inter->tcp53io->revents)
++            t_new(inter->tcp53);
++          }
++        }
+ }
+   
+-#define FATAL "dnscache: fatal: "
+-
+ char seed[128];
+ int main()
+ {
+   char *x;
++  int len;
++  int pos;
++  int oldpos;
++  char iptmp[4];
++  char iperr[IP4_FMT];
++  struct interf *inter;
++  struct interf *itmp;
+   unsigned int i, j, k;
+   unsigned long cachesize;
+   static stralloc sa = {0};
+@@ -405,31 +430,50 @@
+   x = env_get("IP");
+   if (!x)
+     strerr_die2x(111,FATAL,"$IP not set");
+-  if (!ip6_scan(x,myipincoming))
+-    strerr_die3x(111,FATAL,"unable to parse IP address ",x);
++  len = str_len(x);
++  numio = pos = oldpos = 0;
++  while (pos < len) {
++    if (pos) oldpos = pos + 1;
++    pos = oldpos + str_chr(x + oldpos,'/');
++    x[pos] = 0;
++    if (!str_len(x + oldpos)) continue;
++
++    if (!ip6_scan(x + oldpos,iptmp))
++      strerr_die3x(111,FATAL,"unable to parse IP address ",x + oldpos);
++
++    inter = (struct interf *) alloc(sizeof(struct interf));
++
++    if (interhead == 0) interhead = inter;
++    else if (interhead->next == 0) interhead->next = inter;
++    else {
++      for (itmp = interhead; itmp->next != 0; itmp = itmp->next);
++      itmp->next = inter;
++    }
+-#if 0
+-  /* if if IP is a mapped-IPv4 address, disable IPv6 functionality */
+-  /* this is actually a bad idea */
+-  if (ip6_isv4mapped(myipincoming))
+-    noipv6 = 1;
+-#endif
+-
+-  udp53 = socket_udp6();
+-  if (udp53 == -1)
+-    strerr_die2sys(111,FATAL,"unable to create UDP socket: ");
+-  if (socket_bind6_reuse(udp53,myipincoming,53,interface) == -1)
+-    strerr_die2sys(111,FATAL,"unable to bind UDP socket: ");
+-
+-  tcp53 = socket_tcp6();
+-  if (tcp53 == -1)
+-    strerr_die2sys(111,FATAL,"unable to create TCP socket: ");
+-  if (socket_bind6_reuse(tcp53,myipincoming,53,interface) == -1)
+-    strerr_die2sys(111,FATAL,"unable to bind TCP socket: ");
++    inter->next = 0;
++    inter->udp53 = socket_udp6();
++    if (inter->udp53 == -1)
++      strerr_die4sys(111,FATAL,"unable to create UDP socket for IP address ",x + oldpos,": ");
++    if (socket_bind6_reuse(inter->udp53,iptmp,53,interface) == -1)
++      strerr_die4sys(111,FATAL,"unable to bind UDP socket for IP address ",x + oldpos,": ");
++
++    inter->tcp53 = socket_tcp6();
++    if (inter->tcp53 == -1)
++      strerr_die4sys(111,FATAL,"unable to create TCP socket for IP address ",x + oldpos,": ");
++    if (socket_bind6_reuse(inter->tcp53,iptmp,53,interface) == -1)
++      strerr_die4sys(111,FATAL,"unable to bind TCP socket for IP address ",x + oldpos,": ");
++
++    numio++;
++    log_listen(iptmp);
++  }
++
++  if (interhead == 0)
++    strerr_die2x(111,FATAL,"no interfaces to listen on");
+   droproot(FATAL);
+-  socket_tryreservein(udp53,131072);
++  for (inter = interhead; inter != 0; inter = inter->next)
++    socket_tryreservein(inter->udp53,131072);
+   byte_zero(seed,sizeof seed);
+   read(0,seed,sizeof seed);
+@@ -471,8 +515,11 @@
+   if (!roots_init())
+     strerr_die2sys(111,FATAL,"unable to read servers: ");
+-  if (socket_listen(tcp53,20) == -1)
+-    strerr_die2sys(111,FATAL,"unable to listen on TCP socket: ");
++  for (inter = interhead; inter != 0; inter = inter->next)
++    if (socket_listen(inter->tcp53,20) == -1) {
++      iperr[ip4_fmt(iperr,inter->ip)] = 0;
++      strerr_die4sys(111,FATAL,"unable to listen on TCP socket for IP ",iperr,": ");
++    }
+   log_startup();
+   doit();
+diff -r -u djbdns+ipv6/log.c djbdns-1.05/log.c
+--- djbdns+ipv6/log.c  2004-09-29 21:17:03.000000000 +0200
++++ djbdns-1.05/log.c  2004-09-29 21:47:02.523655344 +0200
+@@ -285,3 +285,10 @@
+   number(tactive);
+   line();
+ }
++
++void log_listen(const char addr[16])
++{
++  string("listening on ");
++  ip(addr);
++  line();
++}
+diff -r -u djbdns+ipv6/log.h djbdns-1.05/log.h
+--- djbdns+ipv6/log.h  2001-02-11 22:11:45.000000000 +0100
++++ djbdns-1.05/log.h  2004-09-29 21:18:46.114548728 +0200
+@@ -4,6 +4,7 @@
+ #include "uint64.h"
+ extern void log_startup(void);
++extern void log_listen(const char *);
+ extern void log_query(uint64 *,const char *,unsigned int,const char *,const char *,const char *);
+ extern void log_querydrop(uint64 *);
This page took 0.08188 seconds and 4 git commands to generate.