Hello,

        This patch should work on Solaris 2.x. You can apply it to the
dhcp-2.0b1pl18 tree (I did not try pl17).

> Thanks Michael. To make sure myself, can these patches be installed for
> Sun Solaris Platforms or is it Linux specific ? I am running DHCP server
> on a Sun Sparc/Solaris 2.5.x 
> 
> For cases where DHCP and DNS servers are hosted on different machines,
> any other pointers (as in my case) ?
> 
        Be sure your name server is a primary for zones.

> Thanks
> 
> P
*** dhcp-2.0b1pl16/Makefile.conf.orig   Wed Feb 24 13:54:13 1999
--- dhcp-2.0b1pl16/Makefile.conf        Wed Feb 24 13:59:44 1999
***************
*** 85,95 ****
  #VARDB = /etc
  ##--sunos4--
  
! ## Solaris 2.5 (with gcc)
  ##--sunos5-gcc--
  #INSTALL=/usr/ucb/install
  #MANINSTALL=/usr/ucb/install
! #LIBS = -lresolv -lsocket -lnsl -lgen
  #CC=gcc
  #COPTS = -Wall -Wno-unused -Wno-implicit -Wno-comment \
  #      -Wno-uninitialized -Wno-char-subscripts -Werror
--- 85,96 ----
  #VARDB = /etc
  ##--sunos4--
  
! ## Solaris 2.5 (with gcc and BIND 8.1.2)
  ##--sunos5-gcc--
  #INSTALL=/usr/ucb/install
  #MANINSTALL=/usr/ucb/install
! #LFLAGS = -L/usr/local/bind/lib
! #LIBS = -lbind -lsocket -lnsl -lgen
  #CC=gcc
  #COPTS = -Wall -Wno-unused -Wno-implicit -Wno-comment \
  #      -Wno-uninitialized -Wno-char-subscripts -Werror
***************
*** 187,194 ****
  #SCRIPT=linux
  ##--linux-1--
  
! ## Linux 2.0
  ##--linux-2.0--
  #COPTS = -DLINUX_MAJOR=2 -DLINUX_MINOR=0
  #CF = cf/linux.h
  #ADMMANDIR = /usr/man/man8
--- 188,197 ----
  #SCRIPT=linux
  ##--linux-1--
  
! ## Linux 2.0 (with BIND 8.1.2)
  ##--linux-2.0--
+ #LFLAGS = -L/usr/local/bind/lib
+ #LIBS = -lbind
  #COPTS = -DLINUX_MAJOR=2 -DLINUX_MINOR=0
  #CF = cf/linux.h
  #ADMMANDIR = /usr/man/man8
*** dhcp-2.0b1pl16/client/Makefile.dist.orig    Wed Feb 24 16:04:29 1999
--- dhcp-2.0b1pl16/client/Makefile.dist Wed Feb 24 16:06:10 1999
***************
*** 38,44 ****
  MAN    = dhclient.8 dhclient.conf.5 dhclient-script.8 dhclient.leases.5
  
  DEBUG  = -g
! INCLUDES = -I.. -I../includes
  DHCPLIB = ../common/libdhcp.a
  CFLAGS = $(DEBUG) $(PREDEFINES) $(INCLUDES) $(COPTS)
  
--- 38,44 ----
  MAN    = dhclient.8 dhclient.conf.5 dhclient-script.8 dhclient.leases.5
  
  DEBUG  = -g
! INCLUDES = -I.. -I/usr/local/bind/include -I../includes
  DHCPLIB = ../common/libdhcp.a
  CFLAGS = $(DEBUG) $(PREDEFINES) $(INCLUDES) $(COPTS)
  
*** dhcp-2.0b1pl16/common/Makefile.dist.orig    Wed Feb 24 15:46:46 1999
--- dhcp-2.0b1pl16/common/Makefile.dist Wed Feb 24 15:47:20 1999
***************
*** 40,46 ****
  MAN    = dhcp-options.5
  
  DEBUG  = -g
! INCLUDES = -I.. -I../includes
  CFLAGS = $(DEBUG) $(PREDEFINES) $(INCLUDES) $(COPTS)
  
  all:  libdhcp.a $(CATMANPAGES)
--- 40,46 ----
  MAN    = dhcp-options.5
  
  DEBUG  = -g
! INCLUDES = -I.. -I/usr/local/bind/include -I../includes
  CFLAGS = $(DEBUG) $(PREDEFINES) $(INCLUDES) $(COPTS)
  
  all:  libdhcp.a $(CATMANPAGES)
*** dhcp-2.0b1pl16/relay/Makefile.dist.orig     Wed Feb 24 16:06:28 1999
--- dhcp-2.0b1pl16/relay/Makefile.dist  Wed Feb 24 16:06:49 1999
***************
*** 37,43 ****
  MAN    = dhcrelay.8
  
  DEBUG  = -g
! INCLUDES = -I.. -I../includes
  DHCPLIB = ../common/libdhcp.a
  CFLAGS = $(DEBUG) $(PREDEFINES) $(INCLUDES) $(COPTS)
  
--- 37,43 ----
  MAN    = dhcrelay.8
  
  DEBUG  = -g
! INCLUDES = -I.. -I/usr/local/bind/include -I../includes
  DHCPLIB = ../common/libdhcp.a
  CFLAGS = $(DEBUG) $(PREDEFINES) $(INCLUDES) $(COPTS)
  
*** dhcp-2.0b1pl16/server/Makefile.dist.orig    Wed Feb 24 14:00:08 1999
--- dhcp-2.0b1pl16/server/Makefile.dist Wed Feb 24 14:01:42 1999
***************
*** 31,43 ****
  #
  
  CATMANPAGES = dhcpd.cat8 dhcpd.conf.cat5 dhcpd.leases.cat5
! SRCS   = dhcpd.c dhcp.c bootp.c confpars.c db.c
! OBJS   = dhcpd.o dhcp.o bootp.o confpars.o db.o
  PROG   = dhcpd
  MAN    = dhcpd.8 dhcpd.conf.5 dhcpd.leases.5
  
  DEBUG  = -g
! INCLUDES = -I.. -I../includes
  DHCPLIB = ../common/libdhcp.a
  CFLAGS = $(DEBUG) $(PREDEFINES) $(INCLUDES) $(COPTS)
  
--- 31,43 ----
  #
  
  CATMANPAGES = dhcpd.cat8 dhcpd.conf.cat5 dhcpd.leases.cat5
! SRCS   = dhcpd.c dhcp.c bootp.c confpars.c db.c nsupdate.c
! OBJS   = dhcpd.o dhcp.o bootp.o confpars.o db.o nsupdate.o
  PROG   = dhcpd
  MAN    = dhcpd.8 dhcpd.conf.5 dhcpd.leases.5
  
  DEBUG  = -g
! INCLUDES = -I.. -I/usr/local/bind/include -I../includes
  DHCPLIB = ../common/libdhcp.a
  CFLAGS = $(DEBUG) $(PREDEFINES) $(INCLUDES) $(COPTS)
  
*** dhcp-2.0b1pl16/includes/dhcpd.h.orig        Wed Feb 24 14:02:44 1999
--- dhcp-2.0b1pl16/includes/dhcpd.h     Wed Feb 24 15:30:13 1999
***************
*** 46,51 ****
--- 46,53 ----
  #include <sys/socket.h>
  #include <sys/un.h>
  #include <arpa/inet.h>
+ #include <arpa/nameser.h>
+ #include <resolv.h>
  #include <netdb.h>
  #else
  #define fd_set cygwin_fd_set
*** dhcp-2.0b1pl16/includes/cf/sunos5-5.h.orig  Wed Feb 24 14:04:34 1999
--- dhcp-2.0b1pl16/includes/cf/sunos5-5.h       Wed Feb 24 15:32:33 1999
***************
*** 138,145 ****
--- 138,147 ----
  
  /* Solaris doesn't provide an endian.h, so we have to do it. */
  
+ #if !defined (BIG_ENDIAN) && !defined (LITTLE_ENDIAN)
  #define BIG_ENDIAN 1
  #define LITTLE_ENDIAN 2
+ #endif /* BIG_ENDIAN && LITTLE_ENDIAN */
  #if defined (__i386) || defined (i386)
  # define BYTE_ORDER LITTLE_ENDIAN
  #else
*** dhcp-2.0b1pl16/server/dhcp.c.orig   Wed Feb 24 14:08:59 1999
--- dhcp-2.0b1pl16/server/dhcp.c        Wed Feb 24 15:54:52 1999
***************
*** 377,382 ****
--- 377,383 ----
  
        /* If we found a lease, release it. */
        if (lease) {
+               nsupdate (lease, DELETE);
                release_lease (lease);
        }
  }
***************
*** 1055,1060 ****
--- 1056,1063 ----
                ++outstanding_pings;
        } else {
                lease -> timestamp = cur_time;
+               if (!(lease -> flags & STATIC_LEASE))
+                       nsupdate (lease, ADD);
                dhcp_reply (lease);
        }
  }
*** dhcp-2.0b1pl16/server/nsupdate.c.orig       Wed Feb 24 14:18:16 1999
--- dhcp-2.0b1pl16/server/nsupdate.c    Wed Feb 24 14:13:38 1999
***************
*** 0 ****
--- 1,108 ----
+ #include "dhcpd.h"
+ 
+ void nsupdate(lease, opcode)
+ struct lease *lease;
+ int   opcode;
+ {
+       char    hostname[MAXDNAME];
+       char    domain[MAXDNAME];
+       char    revname[MAXDNAME];
+       char    *h;
+       int     len, z;
+       u_int32_t       ttl;
+       ns_updrec       *u, *n;
+ 
+       if (!(opcode == ADD || opcode == DELETE))
+               return;
+ 
+       h = lease->client_hostname ? lease->client_hostname : lease->hostname;
+       if (h == NULL) {
+               warn("%s: no hostname", piaddr(lease->ip_addr));
+               return;
+       }
+ 
+       if ( !res_hnok(h) ) {
+               warn("Bad hostname: <%s>", h);
+               return;
+       }
+ 
+       len = MAXDNAME - strlen(h) - 2;
+       memset(domain, 0, sizeof(domain));
+       if (lease->host && lease->host->group->options[DHO_DOMAIN_NAME]->value &&
+               lease->host->group->options[DHO_DOMAIN_NAME]->len < len)
+               memcpy(domain, lease->host->group->options[DHO_DOMAIN_NAME]->value,
+                       lease->host->group->options[DHO_DOMAIN_NAME]->len);
+       else if (lease->subnet && 
+lease->subnet->group->options[DHO_DOMAIN_NAME]->value &&
+               lease->subnet->group->options[DHO_DOMAIN_NAME]->len < len)
+               memcpy(domain, lease->subnet->group->options[DHO_DOMAIN_NAME]->value,
+               lease->subnet->group->options[DHO_DOMAIN_NAME]->len);
+       else 
+               return;
+       if (snprintf(hostname, MAXDNAME, "%s.%s.", h, domain) < 0)
+               return;
+       if ( lease->ip_addr.len == 4 ) { /* IPv4 */
+               snprintf(revname, MAXDNAME, "%d.%d.%d.%d.in-addr.arpa.",
+                       lease->ip_addr.iabuf[3], lease->ip_addr.iabuf[2],
+                       lease->ip_addr.iabuf[1], lease->ip_addr.iabuf[0]);
+       } else {
+               warn("unsupported IP address length: %d", lease->ip_addr.len);
+               return;
+       }
+       switch (opcode) {
+       case ADD:
+               ttl = lease->ends - lease->timestamp;
+               if (!(u = res_mkupdrec(S_PREREQ, hostname, C_IN, T_A, 0))) 
+                       return;
+               u->r_opcode = NXRRSET; u->r_data = NULL; u->r_size = 0;
+               if (!(n = res_mkupdrec(S_UPDATE, hostname, C_IN, T_A, ttl))) {
+                       res_freeupdrec(u);
+                       return;
+               }
+               n->r_opcode = opcode; n->r_data = piaddr(lease->ip_addr); n->r_size = 
+strlen(n->r_data);
+               u->r_next = n;
+               z = res_update(u);
+               note("add %s: %s IN A %s",
+                       z == 1 ? "succeeded" : "failed", hostname, n->r_data);
+               res_freeupdrec(u); 
+               res_freeupdrec(n);
+               if (z != 1) 
+                       return;
+               /* delete all PTR RRs with the same ip address. Wow! */
+               if (!(u = res_mkupdrec(S_PREREQ, revname, C_IN, T_PTR, 0)))
+                       return;
+               u->r_opcode = YXRRSET; u->r_data = NULL; u->r_size = 0;
+               if (!(n = res_mkupdrec(S_UPDATE, revname, C_IN, T_PTR, 0))) {
+                       res_freeupdrec(u);
+                       return;
+               }
+               n->r_opcode = DELETE; n->r_data = NULL; n->r_size = 0;
+               note("cleaning all PTR RRs for %s", revname);
+               res_update(u);
+               res_freeupdrec(u);
+               res_freeupdrec(n);
+               break;
+       case    DELETE:
+               ttl = 0;
+               if (!(u = res_mkupdrec(S_UPDATE, hostname, C_IN, T_A, ttl)))
+                       break;
+               u->r_opcode = opcode; u->r_data = piaddr(lease->ip_addr); u->r_size = 
+strlen(u->r_data);
+               z = res_update(u);
+               note("delete %s: %s IN A %s",
+                       z == 1 ? "succeeded" : "failed", hostname, u->r_data);
+               res_freeupdrec(u);
+               break;
+       default:
+               return; 
+       }
+ 
+       /* add/delete a PTR RR */
+       if (!(u = res_mkupdrec(S_UPDATE, revname, C_IN, T_PTR, ttl)))
+               return;
+       u->r_opcode = opcode; u->r_data = hostname; u->r_size = strlen(u->r_data);
+       z = res_update(u);
+       note("%s %s: %s IN PTR %s", 
+               opcode == ADD ? "add" : "delete", z == 1 ? "succeeded" : "failed",
+               revname, hostname);
+       res_freeupdrec(u);
+       return;
+ }
*** bind/src/lib/resolv/res_update.c.orig       Fri Dec 11 15:12:40 1998
--- bind/src/lib/resolv/res_update.c    Fri Dec 11 15:14:42 1998
***************
*** 502,508 ****
                if (n < 0) {
                        fprintf(stderr, "res_send: send error, n=%d\n", n);
                        break;
!               } else
                        numzones++;
        }
  
--- 502,508 ----
                if (n < 0) {
                        fprintf(stderr, "res_send: send error, n=%d\n", n);
                        break;
!               } else if (hp->rcode == NOERROR)
                        numzones++;
        }
  

Reply via email to