/* dnsmasq is Copyright (c) 2000-2012 Simon Kelley

   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
   the Free Software Foundation; version 2 dated June, 1991, or
   (at your option) version 3 dated 29 June, 2007.
 
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
     
   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/


#include "dnsmasq.h"

#ifdef HAVE_DHCP6

static int dhcp6_maybe_relay(struct in6_addr *link_address, struct dhcp_netid **relay_tagsp, struct dhcp_context *context, 
			     int interface, char *iface_name, struct in6_addr *fallback, void *inbuff, size_t sz, int is_unicast, time_t now);
static int dhcp6_no_relay(int msg_type,  struct in6_addr *link_address, struct dhcp_netid *tags, struct dhcp_context *context, 
			  int interface, char *iface_name, struct in6_addr *fallback, void *inbuff, size_t sz, int is_unicast, time_t now);
static void log6_packet(char *type, unsigned char *clid, int clid_len, struct in6_addr *addr, int xid, char *iface, char *string);

static void *opt6_find (void *opts, void *end, unsigned int search, unsigned int minsize);
static void *opt6_next(void *opts, void *end);
static unsigned int opt6_uint(unsigned char *opt, int offset, int size);

#define opt6_len(opt) ((int)(opt6_uint(opt, -2, 2)))
#define opt6_type(opt) (opt6_uint(opt, -4, 2))
#define opt6_ptr(opt, i) ((void *)&(((unsigned char *)(opt))[4+(i)]))


size_t dhcp6_reply(struct dhcp_context *context, int interface, char *iface_name,
		   struct in6_addr *fallback, size_t sz, int is_unicast, time_t now)
{
  struct dhcp_netid *relay_tags = NULL;
  struct dhcp_vendor *vendor;

  /* Mark these so we only match each at most once, to avoid tangled linked lists */
  for (vendor = daemon->dhcp_vendors; vendor; vendor = vendor->next)
    vendor->netid.next = &vendor->netid;
  
  save_counter(0);
  
  if (dhcp6_maybe_relay(NULL, &relay_tags, context, interface, iface_name, fallback, daemon->dhcp_packet.iov_base, sz, is_unicast, now))
    return save_counter(0);

  return 0;
}

/* This cost me blood to write, it will probably cost you blood to understand - srk. */
static int dhcp6_maybe_relay(struct in6_addr *link_address, struct dhcp_netid **relay_tagsp, struct dhcp_context *context,
			     int interface, char *iface_name, struct in6_addr *fallback, void *inbuff, size_t sz, int is_unicast, time_t now)
{
  void *end = inbuff + sz;
  void *opts = inbuff + 34;
  int msg_type = *((unsigned char *)inbuff);
  unsigned char *outmsgtypep;
  void *opt;
  struct dhcp_vendor *vendor;

  /* if not an encaplsulated relayed message, just do the stuff */
  if (msg_type != DHCP6RELAYFORW)
    {
      /* if link_address != NULL if points to the link address field of the 
	 innermost nested RELAYFORW message, which is where we find the
	 address of the network on which we can allocate an address.
	 Recalculate the available contexts using that information. */
      
      if (link_address)
	{
	  struct dhcp_context *c;
	  context = NULL;
	  
	  for (c = daemon->dhcp6; c; c = c->next)
	    if (!IN6_IS_ADDR_LOOPBACK(link_address) &&
		!IN6_IS_ADDR_LINKLOCAL(link_address) &&
		!IN6_IS_ADDR_MULTICAST(link_address) &&
		is_same_net6(link_address, &c->start6, c->prefix) &&
		is_same_net6(link_address, &c->end6, c->prefix))
	      {
		c->current = context;
		context = c;
	      }

	  if (!context)
	    {
	      inet_ntop(AF_INET6, link_address, daemon->addrbuff, ADDRSTRLEN); 
	      my_syslog(MS_DHCP | LOG_WARNING, 
			_("no address range available for DHCPv6 request from relay at %s"),
			daemon->addrbuff);
	      return 0;
	    }
	}

      if (!context)
	{
	  my_syslog(MS_DHCP | LOG_WARNING, 
		    _("no address range available for DHCPv6 request via %s"), iface_name);
	  return 0;
	}

      return dhcp6_no_relay(msg_type, link_address, *relay_tagsp, context, interface, iface_name, fallback, inbuff, sz, is_unicast, now);
    }

  /* must have at least msg_type+hopcount+link_address+peer_address+minimal size option
     which is               1   +    1   +    16      +     16     + 2 + 2 = 38 */
  if (sz < 38)
    return 0;
  
  /* copy header stuff into reply message and set type to reply */
  outmsgtypep = put_opt6(inbuff, 34);
  *outmsgtypep = DHCP6RELAYREPL;

  /* look for relay options and set tags if found. */
  for (vendor = daemon->dhcp_vendors; vendor; vendor = vendor->next)
    {
      int mopt;
      
      if (vendor->match_type == MATCH_SUBSCRIBER)
	mopt = OPTION6_SUBSCRIBER_ID;
      else if (vendor->match_type == MATCH_REMOTE)
	mopt = OPTION6_REMOTE_ID; 
      else
	continue;

      if ((opt = opt6_find(opts, end, mopt, 1)) &&
	  vendor->len == opt6_len(opt) &&
	  memcmp(vendor->data, opt6_ptr(opt, 0), vendor->len) == 0 &&
	  vendor->netid.next != &vendor->netid)
	{
	  vendor->netid.next = *relay_tagsp;
	  *relay_tagsp = &vendor->netid;
	  break;
	}
    }
  
  for (opt = opts; opt; opt = opt6_next(opt, end))
    {
      int o = new_opt6(opt6_type(opt));
      if (opt6_type(opt) == OPTION6_RELAY_MSG)
	{
	  struct in6_addr link_address;
	  /* the packet data is unaligned, copy to aligned storage */
	  memcpy(&link_address, inbuff + 2, IN6ADDRSZ); 
	  /* Not, zero is_unicast since that is now known to refer to the 
	     relayed packet, not the original sent by the client */
	  if (!dhcp6_maybe_relay(&link_address, relay_tagsp, context, interface, iface_name, fallback, opt6_ptr(opt, 0), opt6_len(opt), 0, now))
	    return 0;
	}
      else
	put_opt6(opt6_ptr(opt, 0), opt6_len(opt));
      end_opt6(o);	    
    }
  
  return 1;
}

static int dhcp6_no_relay(int msg_type, struct in6_addr *link_address, struct dhcp_netid *tags, struct dhcp_context *context, 
			  int interface, char *iface_name, struct in6_addr *fallback, void *inbuff, size_t sz, int is_unicast, time_t now)
{
  void *packet_options = inbuff + 4;
  void *end = inbuff + sz;
  void *opt, *oro;
  int i, o, o1;
  unsigned char *clid = NULL;
  int clid_len = 0, start_opts;
  struct dhcp_netid *tagif, *context_tags = NULL;
  char *client_hostname= NULL, *hostname = NULL;
  char *domain = NULL, *send_domain = NULL;
  struct dhcp_config *config = NULL;
  struct dhcp_netid known_id, iface_id;
  int done_dns = 0, hostname_auth = 0, do_encap = 0;
  unsigned char *outmsgtypep;
  struct dhcp_opt *opt_cfg;
  struct dhcp_vendor *vendor;
  struct dhcp_context *context_tmp;
  unsigned int xid, ignore = 0;
  unsigned int fqdn_flags = 0x01; /* default to send if we recieve no FQDN option */

  /* set tag with name == interface */
  iface_id.net = iface_name;
  iface_id.next = tags;
  tags = &iface_id; 

  /* copy over transaction-id, and save pointer to message type */
  outmsgtypep = put_opt6(inbuff, 4);
  start_opts = save_counter(-1);
  xid = outmsgtypep[3] | outmsgtypep[2] << 8 | outmsgtypep[1] << 16;
   
  /* We're going to be linking tags from all context we use. 
     mark them as unused so we don't link one twice and break the list */
  for (context_tmp = context; context_tmp; context_tmp = context_tmp->current)
    {
      context->netid.next = &context->netid;

      if (option_bool(OPT_LOG_OPTS))
	{
	   inet_ntop(AF_INET6, &context_tmp->start6, daemon->dhcp_buff, ADDRSTRLEN); 
	   inet_ntop(AF_INET6, &context_tmp->end6, daemon->dhcp_buff2, ADDRSTRLEN); 
	   if (context_tmp->flags & (CONTEXT_STATIC))
	     my_syslog(MS_DHCP | LOG_INFO, _("%u available DHCPv6 subnet: %s/%d"),
		       xid, daemon->dhcp_buff, context_tmp->prefix);
	   else
	     my_syslog(MS_DHCP | LOG_INFO, _("%u available DHCP range: %s -- %s"), 
		       xid, daemon->dhcp_buff, daemon->dhcp_buff2);
	}
    }

  if ((opt = opt6_find(packet_options, end, OPTION6_CLIENT_ID, 1)))
    {
      clid = opt6_ptr(opt, 0);
      clid_len = opt6_len(opt);
      o = new_opt6(OPTION6_CLIENT_ID);
      put_opt6(clid, clid_len);
      end_opt6(o);
    }
  else if (msg_type != DHCP6IREQ)
    return 0;

  /* server-id must match except for SOLICIT and CONFIRM messages */
  if (msg_type != DHCP6SOLICIT && msg_type != DHCP6CONFIRM && msg_type != DHCP6IREQ &&
      (!(opt = opt6_find(packet_options, end, OPTION6_SERVER_ID, 1)) ||
       opt6_len(opt) != daemon->duid_len ||
       memcmp(opt6_ptr(opt, 0), daemon->duid, daemon->duid_len) != 0))
    return 0;
  
  o = new_opt6(OPTION6_SERVER_ID);
  put_opt6(daemon->duid, daemon->duid_len);
  end_opt6(o);

  if (is_unicast &&
      (msg_type == DHCP6REQUEST || msg_type == DHCP6RENEW || msg_type == DHCP6RELEASE || msg_type == DHCP6DECLINE))
    
    {  
      o1 = new_opt6(OPTION6_STATUS_CODE);
      put_opt6_short(DHCP6USEMULTI);
      put_opt6_string("Use multicast");
      end_opt6(o1);
      return 1;
    }

  /* match vendor and user class options */
  for (vendor = daemon->dhcp_vendors; vendor; vendor = vendor->next)
    {
      int mopt;
      
      if (vendor->match_type == MATCH_VENDOR)
	mopt = OPTION6_VENDOR_CLASS;
      else if (vendor->match_type == MATCH_USER)
	mopt = OPTION6_USER_CLASS; 
      else
	continue;

      if ((opt = opt6_find(packet_options, end, mopt, 2)))
	{
	  void *enc_opt, *enc_end = opt6_ptr(opt, opt6_len(opt));
	  int offset = 0;
	  
	  if (mopt == OPTION6_VENDOR_CLASS)
	    {
	      if (opt6_len(opt) < 4)
		continue;
	      
	      if (vendor->enterprise != opt6_uint(opt, 0, 4))
		continue;
	    
	      offset = 4;
	    }
 
	  for (enc_opt = opt6_ptr(opt, offset); enc_opt; enc_opt = opt6_next(enc_opt, enc_end))
	    for (i = 0; i <= (opt6_len(enc_opt) - vendor->len); i++)
	      if (memcmp(vendor->data, opt6_ptr(enc_opt, i), vendor->len) == 0)
		{
		  vendor->netid.next = tags;
		  tags = &vendor->netid;
		  break;
		}
	}
    }

  /* dhcp-match. If we have hex-and-wildcards, look for a left-anchored match.
     Otherwise assume the option is an array, and look for a matching element. 
     If no data given, existance of the option is enough. This code handles 
     V-I opts too. */
  for (opt_cfg = daemon->dhcp_match6; opt_cfg; opt_cfg = opt_cfg->next)
    {
      int match = 0;
      
      if (opt_cfg->flags & DHOPT_RFC3925)
	{
	  for (opt = opt6_find(packet_options, end, OPTION6_VENDOR_OPTS, 4);
	       opt;
	       opt = opt6_find(opt6_next(opt, end), end, OPTION6_VENDOR_OPTS, 4))
	    {
	      void *vopt;
	      void *vend = opt6_ptr(opt, opt6_len(opt));
	      
	      for (vopt = opt6_find(opt6_ptr(opt, 4), vend, opt_cfg->opt, 0);
		   vopt;
		   vopt = opt6_find(opt6_next(vopt, vend), vend, opt_cfg->opt, 0))
		if ((match = match_bytes(opt_cfg, opt6_ptr(vopt, 0), opt6_len(vopt))))
		  break;
	    }
	  if (match)
	    break;
	}
      else
	{
	  if (!(opt = opt6_find(packet_options, end, opt_cfg->opt, 1)))
	    continue;
	  
	  match = match_bytes(opt_cfg, opt6_ptr(opt, 0), opt6_len(opt));
	} 
  
      if (match)
	{
	  opt_cfg->netid->next = tags;
	  tags = opt_cfg->netid;
	}
    }
  
  if ((opt = opt6_find(packet_options, end, OPTION6_FQDN, 1)))
    {
      /* RFC4704 refers */
       int len = opt6_len(opt) - 1;
       
       fqdn_flags = opt6_uint(opt, 0, 1);
       
       /* Always force update, since the client has no way to do it itself. */
       if (!option_bool(OPT_FQDN_UPDATE) && !(fqdn_flags & 0x01))
	 fqdn_flags |= 0x03;
 
       fqdn_flags &= ~0x04;

       if (len != 0 && len < 255)
	 {
	  unsigned char *pp, *op = opt6_ptr(opt, 1);
	  char *pq = daemon->dhcp_buff;
	  
	  pp = op;
	  while (*op != 0 && ((op + (*op) + 1) - pp) < len)
	    {
            memcpy(pq, op+1, *op);
            pq += *op;
            op += (*op)+1;
            *(pq++) = '.';
	    }
	  
	  if (pq != daemon->dhcp_buff)
	    pq--;
	  *pq = 0;

	  if (legal_hostname(daemon->dhcp_buff))
	    {
	      client_hostname = daemon->dhcp_buff;
	      if (option_bool(OPT_LOG_OPTS))
		my_syslog(MS_DHCP | LOG_INFO, _("%u client provides name: %s"), xid, client_hostname); 
	    }
	 }
    }	 
  
  if (clid)
    {
      config = find_config6(daemon->dhcp_conf, context, clid, clid_len, NULL);
      
      if (have_config(config, CONFIG_NAME))
	{
	  hostname = config->hostname;
	  domain = config->domain;
	  hostname_auth = 1;
	}
      else if (client_hostname)
	{
	  domain = strip_hostname(client_hostname);
	  
	  if (strlen(client_hostname) != 0)
	    {
	      hostname = client_hostname;
	      if (!config)
		{
		  /* Search again now we have a hostname. 
		     Only accept configs without CLID here, (it won't match)
		     to avoid impersonation by name. */
		  struct dhcp_config *new = find_config6(daemon->dhcp_conf, context, NULL, 0, hostname);
		  if (new && !have_config(new, CONFIG_CLID) && !new->hwaddr)
		    config = new;
		}
	    }
	}
    }

  if (config)
    {
      struct dhcp_netid_list *list;
      
      for (list = config->netid; list; list = list->next)
        {
          list->list->next = tags;
          tags = list->list;
        }

      /* set "known" tag for known hosts */
      known_id.net = "known";
      known_id.next = tags;
      tags = &known_id;

      if (have_config(config, CONFIG_DISABLE))
	ignore = 1;
    }
   
  tagif = run_tag_if(tags);
  
  /* if all the netids in the ignore list are present, ignore this client */
  if (daemon->dhcp_ignore)
    {
      struct dhcp_netid_list *id_list;
     
      for (id_list = daemon->dhcp_ignore; id_list; id_list = id_list->next)
	if (match_netid(id_list->list, tagif, 0))
	  ignore = 1;
    }
  
  /* if all the netids in the ignore_name list are present, ignore client-supplied name */
  if (!hostname_auth)
    {
       struct dhcp_netid_list *id_list;
       
       for (id_list = daemon->dhcp_ignore_names; id_list; id_list = id_list->next)
	 if ((!id_list->list) || match_netid(id_list->list, tagif, 0))
	   break;
       if (id_list)
	 hostname = NULL;
    }
  

  switch (msg_type)
    {
    default:
      return 0;

    case DHCP6SOLICIT:
    case DHCP6REQUEST:
      {
	void *rapid_commit = opt6_find(packet_options, end, OPTION6_RAPID_COMMIT, 0);
	int make_lease = (msg_type == DHCP6REQUEST || rapid_commit); 
	int serial = 0, used_config = 0;

	if (rapid_commit)
	  {
	    o = new_opt6(OPTION6_RAPID_COMMIT);
	    end_opt6(o);
	  }

	/* set reply message type */
	*outmsgtypep = make_lease ? DHCP6REPLY : DHCP6ADVERTISE;
	
	log6_packet(msg_type == DHCP6SOLICIT ? "DHCPSOLICIT" : "DHCPREQUEST",
		    clid, clid_len, NULL, xid, iface_name, ignore ? "ignored" : NULL);
	
	if (ignore)
	  return 0;
	
	for (opt = packet_options; opt; opt = opt6_next(opt, end))
	  {   
	    int iaid, ia_type = opt6_type(opt);
	    void *ia_option, *ia_end;
	    unsigned int min_time = 0xffffffff;
	    int t1cntr = 0;
	    int address_assigned = 0;
	    
	    if (ia_type != OPTION6_IA_NA && ia_type != OPTION6_IA_TA)
	      continue;
	    
	    if (ia_type == OPTION6_IA_NA && opt6_len(opt) < 12)
	      continue;
	    
	    if (ia_type == OPTION6_IA_TA && opt6_len(opt) < 4)
	      continue;
	    
	    iaid = opt6_uint(opt, 0, 4);
	    ia_end = opt6_ptr(opt, opt6_len(opt));
	    ia_option =  opt6_find(opt6_ptr(opt, ia_type == OPTION6_IA_NA ? 12 : 4), ia_end, OPTION6_IAADDR, 24);
	    
	    /* reset "USED" flags on leases */
	    lease6_find(NULL, 0, ia_type == OPTION6_IA_NA ? LEASE_NA : LEASE_TA, iaid, NULL);
	    
	    o = new_opt6(ia_type);
	    put_opt6_long(iaid);
	    if (ia_type == OPTION6_IA_NA)
	      {
		/* save pointer */
		t1cntr = save_counter(-1);
		/* so we can fill these in later */
		put_opt6_long(0);
		put_opt6_long(0); 
	      }
	    
	    while (1)
	      {
		struct in6_addr alloced_addr, *addrp = NULL;
		u32 preferred_time = 0;
		struct dhcp_lease *lease = NULL;
		
		if (ia_option)
		  {
		    struct in6_addr *req_addr = opt6_ptr(ia_option, 0);
		    preferred_time = opt6_uint(ia_option, 16, 4);
		    
		    if (!address6_available(context, req_addr, tags) &&
			(!have_config(config, CONFIG_ADDR6) || memcmp(&config->addr6, req_addr, IN6ADDRSZ) != 0))
		      {
			if (msg_type == DHCP6REQUEST)
			  {
			    /* host has a lease, but it's not on the correct link */
			    o1 = new_opt6(OPTION6_STATUS_CODE);
			    put_opt6_short(DHCP6NOTONLINK);
			    put_opt6_string("Not on link");
			    end_opt6(o1);
			  }
		      }
		    else if ((lease = lease6_find(NULL, 0, ia_type == OPTION6_IA_NA ? LEASE_NA : LEASE_TA, 
						  iaid, req_addr)) &&
			     (clid_len != lease->clid_len ||
			      memcmp(clid, lease->clid, clid_len) != 0))
		      {
			/* Address leased to another DUID */
			o1 = new_opt6(OPTION6_STATUS_CODE);
			put_opt6_short(DHCP6UNSPEC);
			put_opt6_string("Address in use");
			end_opt6(o1);
		      } 
		    else
		      addrp = req_addr;
		  }
		else
		  {
		    /* must have an address to CONFIRM */
		    if (msg_type == DHCP6REQUEST && ia_type == OPTION6_IA_NA)
		      return 0;
		    
		    /* Don't used configured addresses for temporary leases. */
		    if (have_config(config, CONFIG_ADDR6) && !used_config && ia_type == OPTION6_IA_NA)
		      {
			struct dhcp_lease *ltmp = lease6_find_by_addr(&config->addr6, 128, 0);
			 
			used_config = 1;
			inet_ntop(AF_INET6, &config->addr6, daemon->addrbuff, ADDRSTRLEN);
			
			if (ltmp && ltmp->clid && 
			    (ltmp->clid_len != clid_len || memcmp(ltmp->clid, clid, clid_len) != 0))
			  my_syslog(MS_DHCP | LOG_WARNING, _("not using configured address %s because it is leased to %s"),
				    daemon->addrbuff, print_mac(daemon->namebuff, ltmp->clid, ltmp->clid_len));
			else if (have_config(config, CONFIG_DECLINED) &&
				 difftime(now, config->decline_time) < (float)DECLINE_BACKOFF)
			  my_syslog(MS_DHCP | LOG_WARNING, _("not using configured address %s because it was previously declined"), 
				    daemon->addrbuff);
			else
			  addrp = &config->addr6;			 
		      }
		    
		    /* existing lease */
		    if (!addrp &&
			(lease = lease6_find(clid, clid_len, 
					     ia_type == OPTION6_IA_NA ? LEASE_NA : LEASE_TA, iaid, NULL)) &&
			address6_available(context, (struct in6_addr *)&lease->hwaddr, tags) &&
			!config_find_by_address6(daemon->dhcp_conf, (struct in6_addr *)&lease->hwaddr, 128, 0))
		      addrp = (struct in6_addr *)&lease->hwaddr;
		    
		    if (!addrp && address6_allocate(context, clid, clid_len, serial++, tags, &alloced_addr))
		      addrp = &alloced_addr;		    
		  }
		
		if (addrp)
		  {
		    unsigned int lease_time;
		    struct dhcp_context *this_context;
		    struct dhcp_config *valid_config = config;

		    /* don't use a config to set lease time if it specifies an address which isn't this. */
		    if (have_config(config, CONFIG_ADDR6) && memcmp(&config->addr6, addrp, IN6ADDRSZ) != 0)
		      valid_config = NULL;

		    address_assigned = 1;
		    
		    /* shouldn't ever fail */
		    if ((this_context = narrow_context6(context, addrp, tagif)))
		      {
			/* get tags from context if we've not used it before */
			if (this_context->netid.next == &this_context->netid && this_context->netid.net)
			  {
			    this_context->netid.next = context_tags;
			    context_tags = &this_context->netid;
			    if (!hostname_auth)
			      {
				struct dhcp_netid_list *id_list;
				
				for (id_list = daemon->dhcp_ignore_names; id_list; id_list = id_list->next)
				  if ((!id_list->list) || match_netid(id_list->list, &this_context->netid, 0))
				    break;
				if (id_list)
				  hostname = NULL;
			      }
			  }
			
			lease_time = have_config(valid_config, CONFIG_TIME) ? valid_config->lease_time : this_context->lease_time;
			
			if (ia_option)
			  {
			    if (preferred_time < 120u )
			      preferred_time = 120u; /* sanity */
			    if (lease_time == 0xffffffff || (preferred_time != 0xffffffff && preferred_time < lease_time))
			      lease_time = preferred_time;
			  }
			  
			if (lease_time < min_time)
			  min_time = lease_time;
			
			/* May fail to create lease */
			if (!lease && make_lease)
			  lease = lease6_allocate(addrp, ia_type == OPTION6_IA_NA ? LEASE_NA : LEASE_TA);
			
			if (lease)
			  {
			    lease_set_expires(lease, lease_time, now);
			    lease_set_hwaddr(lease, NULL, clid, 0, iaid, clid_len);
			    lease_set_interface(lease, interface);
			    if (hostname && ia_type == OPTION6_IA_NA)
			      {
				char *addr_domain = get_domain6(addrp);
				if (!send_domain)
				  send_domain = addr_domain;
				lease_set_hostname(lease, hostname, hostname_auth, addr_domain, domain);
			      }

#ifdef HAVE_SCRIPT
			    if (daemon->lease_change_command)
			      {
				void *class_opt;
				lease->flags |= LEASE_CHANGED;
				free(lease->extradata);
				lease->extradata = NULL;
				lease->extradata_size = lease->extradata_len = 0;
				lease->hwaddr_len = 0; /* surrogate for no of vendor classes */

				if ((class_opt = opt6_find(packet_options, end, OPTION6_VENDOR_CLASS, 4)))
				  {
				    void *enc_opt, *enc_end = opt6_ptr(class_opt, opt6_len(class_opt));
				    lease->hwaddr_len++;
				    /* send enterprise number first  */
				    sprintf(daemon->dhcp_buff2, "%u", opt6_uint(class_opt, 0, 4));
				    lease_add_extradata(lease, (unsigned char *)daemon->dhcp_buff2, strlen(daemon->dhcp_buff2), 0);
				    
				    if (opt6_len(class_opt) >= 6) 
				      for (enc_opt = opt6_ptr(class_opt, 4); enc_opt; enc_opt = opt6_next(enc_opt, enc_end))
					{
					  lease->hwaddr_len++;
					  lease_add_extradata(lease, opt6_ptr(enc_opt, 0), opt6_len(enc_opt), 0);
					}
				  }
				
				lease_add_extradata(lease, (unsigned char *)client_hostname, 
						    client_hostname ? strlen(client_hostname) : 0, 0);				
				
				/* space-concat tag set */
				if (!tagif && !context_tags)
				  lease_add_extradata(lease, NULL, 0, 0);
				else
				  {
				    struct dhcp_netid *n, *l, *tmp = tags;
				    
				    /* link temporarily */
				    for (n = context_tags; n && n->next; n = n->next);
				    if ((l = n))
				      {
					l->next = tags;
					tmp = context_tags;
				      }
				    
				    for (n = run_tag_if(tmp); n; n = n->next)
				      {
					struct dhcp_netid *n1;
					/* kill dupes */
					for (n1 = n->next; n1; n1 = n1->next)
					  if (strcmp(n->net, n1->net) == 0)
					    break;
					if (!n1)
					  lease_add_extradata(lease, (unsigned char *)n->net, strlen(n->net), n->next ? ' ' : 0); 
				      }

				    /* unlink again */
				    if (l)
				      l->next = NULL;
				  }

				if (link_address)
				  inet_ntop(AF_INET6, link_address, daemon->addrbuff, ADDRSTRLEN);
				
				lease_add_extradata(lease, (unsigned char *)daemon->addrbuff, link_address ? strlen(daemon->addrbuff) : 0, 0);
				  
				if ((class_opt = opt6_find(packet_options, end, OPTION6_USER_CLASS, 2)))
				  {
				    void *enc_opt, *enc_end = opt6_ptr(class_opt, opt6_len(class_opt));
				    for (enc_opt = opt6_ptr(class_opt, 0); enc_opt; enc_opt = opt6_next(enc_opt, enc_end))
				      lease_add_extradata(lease, opt6_ptr(enc_opt, 0), opt6_len(enc_opt), 0);
				  }
			      }
#endif	
			    
			  }
			else if (!send_domain)
			  send_domain = get_domain6(addrp);
			  
			
			if (lease || !make_lease)
			  {
			    o1 =  new_opt6(OPTION6_IAADDR);
			    put_opt6(addrp, sizeof(*addrp));
			    put_opt6_long(lease_time);
			    put_opt6_long(lease_time);
			    end_opt6(o1);

			    log6_packet( make_lease ? "DHCPREPLY" : "DHCPADVERTISE", 
					 clid, clid_len, addrp, xid, iface_name, hostname);
			  }
			
		      }
		  }
		
		
		if (!ia_option || 
		    !(ia_option = opt6_find(opt6_next(ia_option, ia_end), ia_end, OPTION6_IAADDR, 24)))
		  {
		    if (address_assigned) 
		      {
			if (ia_type == OPTION6_IA_NA)
			  {
			    /* go back an fill in fields in IA_NA option */
			    unsigned int t1 = min_time == 0xffffffff ? 0xffffffff : min_time/2;
			    unsigned int t2 = min_time == 0xffffffff ? 0xffffffff : (min_time/8) * 7;
			    int sav = save_counter(t1cntr);
			    put_opt6_long(t1);
			    put_opt6_long(t2);
			    save_counter(sav);
			  }
		      }
		    else
		      { 
			/* no address, return erro */
			o1 = new_opt6(OPTION6_STATUS_CODE);
			put_opt6_short(DHCP6NOADDRS);
			put_opt6_string("No addresses available");
			end_opt6(o1);
		      }
		    
		    end_opt6(o);
		    
		    break;
		  }
	      } 
	  }
  
	break;
      }   
   
    case DHCP6RENEW:
      {
	/* set reply message type */
	*outmsgtypep = DHCP6REPLY;
	
	log6_packet("DHCPRENEW", clid, clid_len, NULL, xid, iface_name, NULL);

	for (opt = packet_options; opt; opt = opt6_next(opt, end))
	  {
	    int ia_type = opt6_type(opt);
	    void *ia_option, *ia_end;
	    unsigned int min_time = 0xffffffff;
	    int t1cntr = 0, iacntr;
	    unsigned int iaid;
	    
	    if (ia_type != OPTION6_IA_NA && ia_type != OPTION6_IA_TA)
	      continue;
	    
	    if (ia_type == OPTION6_IA_NA && opt6_len(opt) < 12)
	      continue;
   
	    if (ia_type == OPTION6_IA_TA && opt6_len(opt) < 4)
	      continue;
	    
	    iaid = opt6_uint(opt, 0, 4);
	    	      	      
	    o = new_opt6(ia_type);
	    put_opt6_long(iaid);
	    if (ia_type == OPTION6_IA_NA)
	      {
		/* save pointer */
		t1cntr = save_counter(-1);
		/* so we can fill these in later */
		put_opt6_long(0);
		put_opt6_long(0); 
	      }
	    
	    iacntr = save_counter(-1); 
	    
	    /* reset "USED" flags on leases */
	    lease6_find(NULL, 0, ia_type == OPTION6_IA_NA ? LEASE_NA : LEASE_TA, iaid, NULL);
	    
	    ia_option = opt6_ptr(opt, ia_type == OPTION6_IA_NA ? 12 : 4);
	    ia_end = opt6_ptr(opt, opt6_len(opt));

	    for (ia_option = opt6_find(ia_option, ia_end, OPTION6_IAADDR, 24);
		 ia_option;
		 ia_option = opt6_find(opt6_next(ia_option, ia_end), ia_end, OPTION6_IAADDR, 24))
	      {
		struct dhcp_lease *lease = NULL;
		struct in6_addr *req_addr = opt6_ptr(ia_option, 0);
		u32 preferred_time = opt6_uint(ia_option, 16, 4);
		unsigned int lease_time;
		struct dhcp_context *this_context;
		struct dhcp_config *valid_config = config;
		
		/* don't use a config to set lease time if it specifies an address which isn't this. */
		if (have_config(config, CONFIG_ADDR6) && memcmp(&config->addr6, req_addr, IN6ADDRSZ) != 0)
		  valid_config = NULL;

		if (!(lease = lease6_find(clid, clid_len,
					  ia_type == OPTION6_IA_NA ? LEASE_NA : LEASE_TA, 
					  iaid, req_addr)))
		  {
		    /* If the server cannot find a client entry for the IA the server
		       returns the IA containing no addresses with a Status Code option set
		       to NoBinding in the Reply message. */
		    save_counter(iacntr);
		    t1cntr = 0;
		    
		    log6_packet("DHCPREPLY", clid, clid_len, req_addr, xid, iface_name, "lease not found");
		    
		    o1 = new_opt6(OPTION6_STATUS_CODE);
		    put_opt6_short(DHCP6NOBINDING);
		    put_opt6_string("No binding found");
		    end_opt6(o1);
		    break;
		  }
		
		
		if (!address6_available(context, req_addr, tagif) || 
		    !(this_context = narrow_context6(context, req_addr, tagif)))
		  lease_time = 0;
		else
		  {
		    /* get tags from context if we've not used it before */
		    if (this_context->netid.next == &this_context->netid && this_context->netid.net)
		      {
			this_context->netid.next = context_tags;
			context_tags = &this_context->netid;
			if (!hostname_auth)
			  {
			    struct dhcp_netid_list *id_list;
			    
			    for (id_list = daemon->dhcp_ignore_names; id_list; id_list = id_list->next)
			      if ((!id_list->list) || match_netid(id_list->list, &this_context->netid, 0))
				break;
			    if (id_list)
			      hostname = NULL;
			  }
		      }
		    
		    lease_time = have_config(valid_config, CONFIG_TIME) ? valid_config->lease_time : this_context->lease_time;
		    
		    if (preferred_time < 120u )
		      preferred_time = 120u; /* sanity */
		    if (lease_time == 0xffffffff || (preferred_time != 0xffffffff && preferred_time < lease_time))
		      lease_time = preferred_time;
		    
		    lease_set_expires(lease, lease_time, now);
		    if (ia_type == OPTION6_IA_NA && hostname)
		      {
			char *addr_domain = get_domain6(req_addr);
			if (!send_domain)
			  send_domain = addr_domain;
			lease_set_hostname(lease, hostname, hostname_auth, addr_domain, domain);
		      }
		    
		    if (lease_time < min_time)
		      min_time = lease_time;
		  }
		
		log6_packet("DHCPREPLY", clid, clid_len, req_addr, xid, iface_name, hostname);	
		
		o1 =  new_opt6(OPTION6_IAADDR);
		put_opt6(req_addr, sizeof(*req_addr));
		put_opt6_long(lease_time);
		put_opt6_long(lease_time);
		end_opt6(o1);
	      }
	    
	    if (t1cntr != 0)
	      {
		/* go back an fill in fields in IA_NA option */
		unsigned int t1 = min_time == 0xffffffff ? 0xffffffff : min_time/2;
		unsigned int t2 = min_time == 0xffffffff ? 0xffffffff : (min_time/8) * 7;
		int sav = save_counter(t1cntr);
		put_opt6_long(t1);
		put_opt6_long(t2);
		save_counter(sav);
	      }
	    
	    end_opt6(o);
	  }
	break;
	
      }
      
    case DHCP6CONFIRM:
      {
	/* set reply message type */
	*outmsgtypep = DHCP6REPLY;
	
	log6_packet("DHCPCONFIRM", clid, clid_len, NULL, xid, iface_name, NULL);
	
	for (opt = packet_options; opt; opt = opt6_next(opt, end))
	  {
	    int ia_type = opt6_type(opt);
	    void *ia_option, *ia_end;
	    
	    if (ia_type != OPTION6_IA_NA && ia_type != OPTION6_IA_TA)
	      continue;
	    
	    if (ia_type == OPTION6_IA_NA && opt6_len(opt) < 12)
	      continue;
	     
	    if (ia_type == OPTION6_IA_TA && opt6_len(opt) < 4)
	      continue;
	    
	    ia_option = opt6_ptr(opt, ia_type == OPTION6_IA_NA ? 12 : 4);
	    ia_end = opt6_ptr(opt, opt6_len(opt));
	    
	    for (ia_option = opt6_find(ia_option, ia_end, OPTION6_IAADDR, 24);
		 ia_option;
		 ia_option = opt6_find(opt6_next(ia_option, ia_end), ia_end, OPTION6_IAADDR, 24))
	      {
		struct in6_addr *req_addr = opt6_ptr(ia_option, 0);
		
		if (!address6_available(context, req_addr, run_tag_if(tags)))
		  {
		    o1 = new_opt6(OPTION6_STATUS_CODE);
		    put_opt6_short(DHCP6NOTONLINK);
		    put_opt6_string("Confirm failed");
		    end_opt6(o1);
		    return 1;
		  }

		log6_packet("DHCPREPLY", clid, clid_len, req_addr, xid, iface_name, hostname);
	      }
	  }	 

	o1 = new_opt6(OPTION6_STATUS_CODE);
	put_opt6_short(DHCP6SUCCESS );
	put_opt6_string("All addresses still on link");
	end_opt6(o1);
	return 1;
    }
      
    case DHCP6IREQ:
      {
	if (ignore)
	  return 0;
	*outmsgtypep = DHCP6REPLY;
	log6_packet("DHCPINFORMATION-REQUEST", clid, clid_len, NULL, xid, iface_name, hostname);
	break;
      }
      
      
    case DHCP6RELEASE:
      {
	/* set reply message type */
	*outmsgtypep = DHCP6REPLY;

	log6_packet("DHCPRELEASE", clid, clid_len, NULL, xid, iface_name, NULL);

	for (opt = packet_options; opt; opt = opt6_next(opt, end))
	  {
	    int iaid, ia_type = opt6_type(opt);
	    void *ia_option, *ia_end;
	    int made_ia = 0;
	    	    
	    if (ia_type != OPTION6_IA_NA && ia_type != OPTION6_IA_TA)
	      continue;

	    if (ia_type == OPTION6_IA_NA && opt6_len(opt) < 12)
	      continue;
	    
	    if (ia_type == OPTION6_IA_TA && opt6_len(opt) < 4)
	      continue;
	    
	    iaid = opt6_uint(opt, 0, 4);
	    ia_end = opt6_ptr(opt, opt6_len(opt));
	    ia_option = opt6_ptr(opt, ia_type == OPTION6_IA_NA ? 12 : 4);
	    
	    /* reset "USED" flags on leases */
	    lease6_find(NULL, 0, ia_type == OPTION6_IA_NA ? LEASE_NA : LEASE_TA, iaid, NULL);
		
	    for (ia_option = opt6_find(ia_option, ia_end, OPTION6_IAADDR, 24);
		 ia_option;
		 ia_option = opt6_find(opt6_next(ia_option, ia_end), ia_end, OPTION6_IAADDR, 24))
	      {
		struct dhcp_lease *lease;
		
		if ((lease = lease6_find(clid, clid_len, ia_type == OPTION6_IA_NA ? LEASE_NA : LEASE_TA,
					 iaid, opt6_ptr(ia_option, 0))))
		  lease_prune(lease, now);
		else
		  {
		    if (!made_ia)
		      {
			o = new_opt6(ia_type);
			put_opt6_long(iaid);
			if (ia_type == OPTION6_IA_NA)
			  {
			    put_opt6_long(0);
			    put_opt6_long(0); 
			  }
			made_ia = 1;
		      }
		    
		    o1 = new_opt6(OPTION6_IAADDR);
		    put_opt6(opt6_ptr(ia_option, 0), IN6ADDRSZ);
		    put_opt6_long(0);
		    put_opt6_long(0);
		    end_opt6(o1);
		  }
	      }
	    
	    if (made_ia)
	      {
		o1 = new_opt6(OPTION6_STATUS_CODE);
		put_opt6_short(DHCP6NOBINDING);
		put_opt6_string("No binding found");
		end_opt6(o1);
		
		end_opt6(o);
	      }
	  }
	
	o1 = new_opt6(OPTION6_STATUS_CODE);
	put_opt6_short(DHCP6SUCCESS);
	put_opt6_string("Release received");
	end_opt6(o1);
	
	return 1;
      }

    case DHCP6DECLINE:
      {
	/* set reply message type */
	*outmsgtypep = DHCP6REPLY;
	
	log6_packet("DHCPDECLINE", clid, clid_len, NULL, xid, iface_name, NULL);

	for (opt = packet_options; opt; opt = opt6_next(opt, end))
	  {
	    int iaid, ia_type = opt6_type(opt);
	    void *ia_option, *ia_end;
	    int made_ia = 0;
	    	    
	    if (ia_type != OPTION6_IA_NA && ia_type != OPTION6_IA_TA)
	      continue;

	    if (ia_type == OPTION6_IA_NA && opt6_len(opt) < 12)
	      continue;
	    
	    if (ia_type == OPTION6_IA_TA && opt6_len(opt) < 4)
	      continue;
	    
	    iaid = opt6_uint(opt, 0, 4);
	    ia_end = opt6_ptr(opt, opt6_len(opt));
	    ia_option = opt6_ptr(opt, ia_type == OPTION6_IA_NA ? 12 : 4);
	    
	    /* reset "USED" flags on leases */
	    lease6_find(NULL, 0, ia_type == OPTION6_IA_NA ? LEASE_NA : LEASE_TA, iaid, NULL);
		
	    for (ia_option = opt6_find(ia_option, ia_end, OPTION6_IAADDR, 24);
		 ia_option;
		 ia_option = opt6_find(opt6_next(ia_option, ia_end), ia_end, OPTION6_IAADDR, 24))
	      {
		struct dhcp_lease *lease;
		struct in6_addr *addrp = opt6_ptr(ia_option, 0);

		if (have_config(config, CONFIG_ADDR6) && 
		    memcmp(&config->addr6, addrp, IN6ADDRSZ) == 0)
		  {
		    prettyprint_time(daemon->dhcp_buff3, DECLINE_BACKOFF);
		    inet_ntop(AF_INET6, addrp, daemon->addrbuff, ADDRSTRLEN);
		    my_syslog(MS_DHCP | LOG_WARNING, _("disabling DHCP static address %s for %s"), 
			      daemon->addrbuff, daemon->dhcp_buff3);
		    config->flags |= CONFIG_DECLINED;
		    config->decline_time = now;
		  }
		else
		  /* make sure this host gets a different address next time. */
		  for (; context; context = context->current)
		    context->addr_epoch++;
		
		if ((lease = lease6_find(clid, clid_len, ia_type == OPTION6_IA_NA ? LEASE_NA : LEASE_TA,
					 iaid, opt6_ptr(ia_option, 0))))
		  lease_prune(lease, now);
		else
		  {
		    if (!made_ia)
		      {
			o = new_opt6(ia_type);
			put_opt6_long(iaid);
			if (ia_type == OPTION6_IA_NA)
			  {
			    put_opt6_long(0);
			    put_opt6_long(0); 
			  }
			made_ia = 1;
		      }
		    
		    o1 = new_opt6(OPTION6_IAADDR);
		    put_opt6(opt6_ptr(ia_option, 0), IN6ADDRSZ);
		    put_opt6_long(0);
		    put_opt6_long(0);
		    end_opt6(o1);
		  }
	      }
	    
	    if (made_ia)
	      {
		o1 = new_opt6(OPTION6_STATUS_CODE);
		put_opt6_short(DHCP6NOBINDING);
		put_opt6_string("No binding found");
		end_opt6(o1);
		
		end_opt6(o);
	      }
	    
	  }
	return 1;
      }

    }
  
  
  /* filter options based on tags, those we want get DHOPT_TAGOK bit set */
  tagif = option_filter(tags, context_tags, daemon->dhcp_opts6);
  
  oro = opt6_find(packet_options, end, OPTION6_ORO, 0);
  
  for (opt_cfg = daemon->dhcp_opts6; opt_cfg; opt_cfg = opt_cfg->next)
    {
      /* netids match and not encapsulated? */
      if (!(opt_cfg->flags & DHOPT_TAGOK))
	continue;
      
      if (!(opt_cfg->flags & DHOPT_FORCE) && oro)
	{
	  for (i = 0; i <  opt6_len(oro) - 1; i += 2)
	    if (opt6_uint(oro, i, 2) == (unsigned)opt_cfg->opt)
	      break;
	  
	  /* option not requested */
	  if (i >=  opt6_len(oro) - 1)
	    continue;
	}
      
      if (opt_cfg->opt == OPTION6_DNS_SERVER)
	{
	  done_dns = 1;
	  if (opt_cfg->len == 0)
	    continue;
	}
      
      o = new_opt6(opt_cfg->opt);
      /* Maye be empty */
      if (opt_cfg->val)
	put_opt6(opt_cfg->val, opt_cfg->len);
      end_opt6(o);
      
    }
  
  if (!done_dns && 
      (!IN6_IS_ADDR_UNSPECIFIED(&context->local6) ||
       !IN6_IS_ADDR_UNSPECIFIED(fallback)))
    {
      o = new_opt6(OPTION6_DNS_SERVER);
      if (IN6_IS_ADDR_UNSPECIFIED(&context->local6))
	put_opt6(fallback, IN6ADDRSZ);
      else
	put_opt6(&context->local6, IN6ADDRSZ);
      end_opt6(o); 
    }
   
    /* handle vendor-identifying vendor-encapsulated options,
       dhcp-option = vi-encap:13,17,....... */
  for (opt_cfg = daemon->dhcp_opts6; opt_cfg; opt_cfg = opt_cfg->next)
    opt_cfg->flags &= ~DHOPT_ENCAP_DONE;
  
  
  if (oro)
    for (i = 0; i <  opt6_len(oro) - 1; i += 2)
      if (opt6_uint(oro, i, 2) == OPTION6_VENDOR_OPTS)
	do_encap = 1;
  
  for (opt_cfg = daemon->dhcp_opts6; opt_cfg; opt_cfg = opt_cfg->next)
    { 
      if (opt_cfg->flags & DHOPT_RFC3925)
	{
	  int found = 0;
	  struct dhcp_opt *oc;
	  
	  if (opt_cfg->flags & DHOPT_ENCAP_DONE)
	    continue;
	  
	  for (oc = daemon->dhcp_opts6; oc; oc = oc->next)
	    {
	      oc->flags &= ~DHOPT_ENCAP_MATCH;
	      
	      if (!(oc->flags & DHOPT_RFC3925) || opt_cfg->u.encap != oc->u.encap)
		continue;
	      
	      oc->flags |= DHOPT_ENCAP_DONE;
	      if (match_netid(oc->netid, tagif, 1))
		{
		  /* option requested/forced? */
		  if (!oro || do_encap || (oc->flags & DHOPT_FORCE))
		    {
		      oc->flags |= DHOPT_ENCAP_MATCH;
		      found = 1;
		    }
		} 
	    }
	  
	  if (found)
	    { 
	      o = new_opt6(OPTION6_VENDOR_OPTS);	      
	      put_opt6_long(opt_cfg->u.encap);	
	     
	      for (oc = daemon->dhcp_opts6; oc; oc = oc->next)
		if (oc->flags & DHOPT_ENCAP_MATCH)
		  {
		    o1 = new_opt6(oc->opt);
		    put_opt6(oc->val, oc->len);
		    end_opt6(o1);
		  }
	      end_opt6(o);
	    }
	}
    }      


  if (hostname)
    {
      unsigned char *p;
      size_t len = strlen(hostname);
      
      if (send_domain)
	len += strlen(send_domain) + 1;

      o = new_opt6(OPTION6_FQDN);
      if ((p = expand(len + 3)))
	{
	  *(p++) = fqdn_flags;
	  p = do_rfc1035_name(p, hostname);
	  if (send_domain)
	    p = do_rfc1035_name(p, send_domain);
	  *p = 0;
	}
      end_opt6(o);
    }


  /* logging */
  if (option_bool(OPT_LOG_OPTS) && oro)
    {
      char *q = daemon->namebuff;
      for (i = 0; i <  opt6_len(oro) - 1; i += 2)
	{
	  char *s = option_string(AF_INET6, opt6_uint(oro, i, 2), NULL, 0, NULL, 0);
	  q += snprintf(q, MAXDNAME - (q - daemon->namebuff),
			"%d%s%s%s", 
			opt6_uint(oro, i, 2),
			strlen(s) != 0 ? ":" : "",
			s, 
			(i > opt6_len(oro) - 3) ? "" : ", ");
	  if ( i >  opt6_len(oro) - 3 || (q - daemon->namebuff) > 40)
	    {
	      q = daemon->namebuff;
	      my_syslog(MS_DHCP | LOG_INFO, _("%u requested options: %s"), xid, daemon->namebuff);
	    }
	}
    }
 
  log_tags(tagif, xid);

  if (option_bool(OPT_LOG_OPTS))
    {
      int end_opts = save_counter(-1);
      
      /* must have created at least one option */
      if (start_opts != end_opts)
	for (opt = daemon->outpacket.iov_base + start_opts; opt; opt = opt6_next(opt, daemon->outpacket.iov_base + end_opts))
	  {
	    int offset = 0;
	    char *optname;

	    /* account for flag byte on FQDN */
	    if (opt6_type(opt) == OPTION6_FQDN)
	      offset = 1;
	    
	    optname = option_string(AF_INET6, opt6_type(opt), opt6_ptr(opt, offset), opt6_len(opt) - offset, daemon->namebuff, MAXDNAME);
	    
	    my_syslog(MS_DHCP | LOG_INFO, "%u sent size:%3d option:%3d %s  %s", 
		      xid, opt6_len(opt), opt6_type(opt), optname, daemon->namebuff);
	  }
    }		 
  
  return 1;
  
}

static void log6_packet(char *type, unsigned char *clid, int clid_len, struct in6_addr *addr, int xid, char *iface, char *string)
{
  /* avoid buffer overflow */
  if (clid_len > 100)
    clid_len = 100;
  
  print_mac(daemon->namebuff, clid, clid_len);

  if (addr)
    {
      inet_ntop(AF_INET6, addr, daemon->dhcp_buff2, 255);
      strcat(daemon->dhcp_buff2, " ");
    }
  else
    daemon->dhcp_buff2[0] = 0;

  if(option_bool(OPT_LOG_OPTS))
    my_syslog(MS_DHCP | LOG_INFO, "%u %s(%s) %s %s%s",
	      xid, 
	      type,
	      iface, 
	      daemon->namebuff,
	      daemon->dhcp_buff2,
	      string ? string : "");
  else
    my_syslog(MS_DHCP | LOG_INFO, "%s(%s) %s %s%s",
	      type,
	      iface, 
	      daemon->namebuff,
	      daemon->dhcp_buff2,
	      string ? string : "");
}

static void *opt6_find (void *opts, void *end, unsigned int search, unsigned int minsize)
{
  u16 opt, opt_len;
  void *start;
  
  if (!opts)
    return NULL;
    
  while (1)
    {
      if (end - opts < 4) 
	return NULL;
      
      start = opts;
      GETSHORT(opt, opts);
      GETSHORT(opt_len, opts);
      
      if (opt_len > (end - opts))
	return NULL;
      
      if (opt == search && (opt_len >= minsize))
	return start;
      
      opts += opt_len;
    }
}

static void *opt6_next(void *opts, void *end)
{
  u16 opt_len;
  
  if (end - opts < 4) 
    return NULL;
  
  opts += 2;
  GETSHORT(opt_len, opts);
  
  if (opt_len >= (end - opts))
    return NULL;
  
  return opts + opt_len;
}

static unsigned int opt6_uint(unsigned char *opt, int offset, int size)
{
  /* this worries about unaligned data and byte order */
  unsigned int ret = 0;
  int i;
  unsigned char *p = opt6_ptr(opt, offset);
  
  for (i = 0; i < size; i++)
    ret = (ret << 8) | *p++;
  
  return ret;
} 

#endif
