/* Kernel routing table updates using netlink over GNU/Linux system.
 * Copyright (C) 1997, 98, 99 Kunihiro Ishiguro
 *
 * This file is part of GNU Zebra.
 *
 * GNU Zebra 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; either version 2, or (at your option) any
 * later version.
 *
 * GNU Zebra 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 GNU Zebra; see the file COPYING.  If not, write to the Free
 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 * 02111-1307, USA.  
 */

#include <zebra.h>

/* Hack for GNU libc version 2. */
#ifndef MSG_TRUNC
#define MSG_TRUNC      0x20
#endif /* MSG_TRUNC */

#include "linklist.h"
#include "if.h"
#include "log.h"
#include "prefix.h"
#include "connected.h"
#include "table.h"
#include "rib.h"
#include "thread.h"

#include "zebra/zserv.h"
#include "zebra/redistribute.h"
#include "zebra/interface.h"
#include "zebra/debug.h"

/* Socket interface to kernel */
struct nlsock
{
  int sock;
  int seq;
  struct sockaddr_nl snl;
  char *name;
} netlink =	{ -1, 0, {0}, "netlink-listen" },	/* kernel messages */
  netlink_cmd = { -1, 0, {0}, "netlink-cmd" },          /* command channel */
  netlink_addr = {-1, 0, {0}, "netlink-addr" };		/* address channel */

struct message nlmsg_str[] =
{
  {RTM_NEWROUTE, "RTM_NEWROUTE"},
  {RTM_DELROUTE, "RTM_DELROUTE"},
  {RTM_GETROUTE, "RTM_GETROUTE"},
  {RTM_NEWLINK,  "RTM_NEWLINK"},
  {RTM_DELLINK,  "RTM_DELLINK"},
  {RTM_GETLINK,  "RTM_GETLINK"},
  {RTM_NEWADDR,  "RTM_NEWADDR"},
  {RTM_DELADDR,  "RTM_DELADDR"},
  {RTM_GETADDR,  "RTM_GETADDR"},
  {0,            NULL}
};

extern int rtm_table_default;

/* Make socket for Linux netlink interface. */
static int
netlink_socket (struct nlsock *nl, unsigned long groups)
{
  int ret;
  struct sockaddr_nl snl;
  int sock;
  int namelen;

  sock = socket (AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
  if (sock < 0)
    {
      zlog (NULL, LOG_ERR, "Can't open %s socket: %s", nl->name,
	    strerror (errno));
      return -1;
    }

  ret = fcntl (sock, F_SETFL, O_NONBLOCK);
  if (ret < 0)
    {
      zlog (NULL, LOG_ERR, "Can't set %s socket flags: %s", nl->name,
	    strerror (errno));
      close (sock);
      return -1;
    }
  
  memset (&snl, 0, sizeof snl);
  snl.nl_family = AF_NETLINK;
  snl.nl_groups = groups;

  /* Bind the socket to the netlink structure for anything. */
  ret = bind (sock, (struct sockaddr *) &snl, sizeof snl);
  if (ret < 0)
    {
      zlog (NULL, LOG_ERR, "Can't bind %s socket to group 0x%x: %s", 
	    nl->name, snl.nl_groups, strerror (errno));
      close (sock);
      return -1;
    }

  /* multiple netlink sockets will have different nl_pid */
  namelen = sizeof snl;
  ret = getsockname (sock, (struct sockaddr *) &snl, &namelen);
  if (ret < 0 || namelen != sizeof snl)
    {
      zlog (NULL, LOG_ERR, "Can't get %s socket name: %s", nl->name,
	    strerror (errno));
      close (sock);
      return -1;
    }

  nl->snl = snl;
  nl->sock = sock;
  return ret;
}

/* Get type specified information from netlink. */
static int
netlink_request (int family, int type, struct nlsock *nl)
{
  int ret;
  struct sockaddr_nl snl;

  struct
  {
    struct nlmsghdr nlh;
    struct rtgenmsg g;
  } req;


  /* Check netlink socket. */
  if (nl->sock < 0)
    {
      zlog (NULL, LOG_ERR, "%s socket isn't active.", nl->name);
      return -1;
    }

  memset (&snl, 0, sizeof snl);
  snl.nl_family = AF_NETLINK;

  req.nlh.nlmsg_len = sizeof req;
  req.nlh.nlmsg_type = type;
  req.nlh.nlmsg_flags = NLM_F_ROOT | NLM_F_MATCH | NLM_F_REQUEST;
  req.nlh.nlmsg_pid = 0;
  req.nlh.nlmsg_seq = ++nl->seq;
  req.g.rtgen_family = family;
 
  ret = sendto (nl->sock, (void*) &req, sizeof req, 0, 
		(struct sockaddr*) &snl, sizeof snl);
  if (ret < 0)
    {
      zlog (NULL, LOG_ERR, "%s sendto failed: %s", nl->name, strerror (errno));
      return -1;
    }
  return 0;
}

/* Receive message from netlink interface and pass those information
   to the given function. */
static int
netlink_parse_info (int (*filter) (struct sockaddr_nl *, struct nlmsghdr *),
		    struct nlsock *nl)
{
  int status;
  int ret = 0;
  int error;

  while (1)
    {
      char buf[4096];
      struct iovec iov = { buf, sizeof buf };
      struct sockaddr_nl snl;
      struct msghdr msg = { (void*)&snl, sizeof snl, &iov, 1, NULL, 0, 0};
      struct nlmsghdr *h;

      status = recvmsg (nl->sock, &msg, 0);

      if (status < 0)
	{
	  if (errno == EINTR)
	    continue;
	  if (errno == EWOULDBLOCK || errno == EAGAIN)
	    break;
	  zlog (NULL, LOG_ERR, "%s recvmsg overrun", nl->name);
	  continue;
	}

      if (status == 0)
	{
	  zlog (NULL, LOG_ERR, "%s EOF", nl->name);
	  return -1;
	}

      if (msg.msg_namelen != sizeof snl)
	{
	  zlog (NULL, LOG_ERR, "%s sender address length error: length %d",
	       nl->name, msg.msg_namelen);
	  return -1;
	}

      for (h = (struct nlmsghdr *) buf; NLMSG_OK (h, status); 
	   h = NLMSG_NEXT (h, status))
	{
	  /* Finish of reading. */
	  if (h->nlmsg_type == NLMSG_DONE)
	    return ret;

	  /* Error handling. */
	  if (h->nlmsg_type == NLMSG_ERROR)
	    {
	      struct nlmsgerr *err = (struct nlmsgerr *) NLMSG_DATA (h);
	      
              /* If the error field is zero, then this is an ACK */
              if (err->error == 0) 
                {
                  if (IS_ZEBRA_DEBUG_KERNEL) 
                    {  
                      zlog_info("%s: %s ACK: type=%s(%u), seq=%u, pid=%d", 
                        __FUNCTION__, nl->name,
                        lookup (nlmsg_str, err->msg.nlmsg_type),
                        err->msg.nlmsg_type, err->msg.nlmsg_seq,
		        err->msg.nlmsg_pid);
                    }
                
                  /* return if not a multipart message, otherwise continue */  
                  if(!(h->nlmsg_flags & NLM_F_MULTI)) 
                    { 
                      return 0;    
                    }
                  continue; 
                }
              
              if (h->nlmsg_len < NLMSG_LENGTH (sizeof (struct nlmsgerr)))
		{
		  zlog (NULL, LOG_ERR, "%s error: message truncated",
			nl->name);
		  return -1;
		}
	      
	      /* Deal with Error Noise  - MAG*/
	      {
		int loglvl = LOG_ERR;
		int errnum = err->error;
		int msg_type = err->msg.nlmsg_type;
		
		if (nl == &netlink_cmd 
		    && (-errnum == ENODEV || -errnum == ESRCH)
		    && (msg_type == RTM_NEWROUTE 
			|| msg_type == RTM_DELROUTE)) 
		    loglvl = LOG_DEBUG;

		zlog (NULL, loglvl, "%s error: %s, type=%s(%u), "
		      "seq=%u, pid=%d",
		      nl->name, strerror (-errnum),
		      lookup (nlmsg_str, msg_type),
		      msg_type, err->msg.nlmsg_seq,
		    err->msg.nlmsg_pid);
	      }
	      /*
	      ret = -1;
	      continue;
	      */
	      return -1;
	    }

	  /* OK we got netlink message. */
	  if (IS_ZEBRA_DEBUG_KERNEL)
	    zlog_info ("netlink_parse_info: %s type %s(%u), seq=%u, pid=%d",
		      nl->name,
		      lookup (nlmsg_str, h->nlmsg_type), h->nlmsg_type,
		      h->nlmsg_seq, h->nlmsg_pid);

	  /* skip unsolicited messages originating from command socket */
	  if (nl != &netlink_cmd && h->nlmsg_pid == netlink_cmd.snl.nl_pid)
	    {
	      if (IS_ZEBRA_DEBUG_KERNEL)
		zlog_info ("netlink_parse_info: %s packet comes from %s",
			  nl->name, netlink_cmd.name);
	      continue;
	    }

	  error = (*filter) (&snl, h);
	  if (error < 0)
	    {
	      zlog (NULL, LOG_ERR, "%s filter function error", nl->name);
	      ret = error;
	    }
	}

      /* After error care. */
      if (msg.msg_flags & MSG_TRUNC)
	{
	  zlog (NULL, LOG_ERR, "%s error: message truncated", nl->name);
	  continue;
	}
      if (status)
	{
	  zlog (NULL, LOG_ERR, "%s error: data remnant size %d", nl->name,
		status);
	  return -1;
	}
    }
  return ret;
}

/* Utility function for parse rtattr. */
static void
netlink_parse_rtattr (struct rtattr **tb, int max, struct rtattr *rta, int len)
{
  while (RTA_OK(rta, len)) 
    {
      if (rta->rta_type <= max)
	tb[rta->rta_type] = rta;
      rta = RTA_NEXT(rta,len);
    }
}

/* Called from interface_lookup_netlink().  This function is only used
   during bootstrap. */
int
netlink_interface (struct sockaddr_nl *snl, struct nlmsghdr *h)
{
  int len;
  struct ifinfomsg *ifi;
  struct rtattr *tb[IFLA_MAX + 1];
  struct interface *ifp;
  char *name;
  int i;

  ifi = NLMSG_DATA (h);

  if (h->nlmsg_type != RTM_NEWLINK)
    return 0;

  len = h->nlmsg_len - NLMSG_LENGTH (sizeof (struct ifinfomsg));
  if (len < 0)
    return -1;

  /* Looking up interface name. */
  memset (tb, 0, sizeof tb);
  netlink_parse_rtattr (tb, IFLA_MAX, IFLA_RTA (ifi), len);
  if (tb[IFLA_IFNAME] == NULL)
    return -1;
  name = (char *)RTA_DATA(tb[IFLA_IFNAME]);

  /* Add interface. */
  ifp = if_get_by_name (name);
  
  ifp->ifindex = ifi->ifi_index;
  ifp->flags = ifi->ifi_flags & 0x0000fffff;
  ifp->mtu = *(int *)RTA_DATA (tb[IFLA_MTU]);
  ifp->metric = 1;

  /* Hardware type and address. */
  ifp->hw_type = ifi->ifi_type;

  if (tb[IFLA_ADDRESS])
    {
      int hw_addr_len;

      hw_addr_len = RTA_PAYLOAD(tb[IFLA_ADDRESS]);

      if (hw_addr_len > INTERFACE_HWADDR_MAX)
	zlog_warn ("Hardware address is too large: %d", hw_addr_len);
      else
	{      
	  ifp->hw_addr_len = hw_addr_len;
	  memcpy (ifp->hw_addr, RTA_DATA(tb[IFLA_ADDRESS]), hw_addr_len);

	  for (i = 0; i < hw_addr_len; i++)
	    if (ifp->hw_addr[i] != 0)
	      break;

	  if (i == hw_addr_len)
	    ifp->hw_addr_len = 0;
	  else
	    ifp->hw_addr_len = hw_addr_len;
	}
    }

  if_add_update (ifp);

  return 0;
}

/* Lookup interface IPv4/IPv6 address. */
int
netlink_interface_addr (struct sockaddr_nl *snl, struct nlmsghdr *h)
{
  int len;
  struct ifaddrmsg *ifa;
  struct rtattr *tb [IFA_MAX + 1];
  struct interface *ifp;
  void *addr = NULL;
  void *broad = NULL;
  u_char flags = 0;
  char *label = NULL;
  int peeronly = 0;

  ifa = NLMSG_DATA (h);

  if (ifa->ifa_family != AF_INET 
#ifdef HAVE_IPV6
      && ifa->ifa_family != AF_INET6
#endif /* HAVE_IPV6 */
      )
    return 0;

  if (h->nlmsg_type != RTM_NEWADDR && h->nlmsg_type != RTM_DELADDR)
    return 0;

  len = h->nlmsg_len - NLMSG_LENGTH(sizeof (struct ifaddrmsg));
  if (len < 0)
    return -1;

  memset (tb, 0, sizeof tb);
  netlink_parse_rtattr (tb, IFA_MAX, IFA_RTA (ifa), len);

  ifp = if_lookup_by_index (ifa->ifa_index);
  if (ifp == NULL)
    {
      zlog_err ("netlink_interface_addr can't find interface by index %d",
		ifa->ifa_index);
      return -1;
    }

  if (IS_ZEBRA_DEBUG_KERNEL)	/* remove this line to see initial ifcfg */
    {
      char buf[BUFSIZ];
      zlog_info ("netlink_interface_addr %s %s/%d:",
		 lookup (nlmsg_str, h->nlmsg_type),
		 ifp->name, ifa->ifa_prefixlen);
      if (tb[IFA_LOCAL])
	zlog_info ("  IFA_LOCAL     %s", inet_ntop (ifa->ifa_family,
		  RTA_DATA (tb[IFA_LOCAL]), buf, BUFSIZ));
      if (tb[IFA_ADDRESS])
	zlog_info ("  IFA_ADDRESS   %s", inet_ntop (ifa->ifa_family,
		  RTA_DATA (tb[IFA_ADDRESS]), buf, BUFSIZ));
      if (tb[IFA_BROADCAST])
	zlog_info ("  IFA_BROADCAST %s", inet_ntop (ifa->ifa_family,
		  RTA_DATA (tb[IFA_BROADCAST]), buf, BUFSIZ));
      if (tb[IFA_LABEL] && strcmp (ifp->name, RTA_DATA (tb[IFA_LABEL])))
	zlog_info ("  IFA_LABEL     %s", RTA_DATA (tb[IFA_LABEL]));
    }

  /* peer or broadcast network? */
  if (ifa->ifa_family == AF_INET)
    peeronly = if_is_pointopoint (ifp) ||
	       ifa->ifa_prefixlen >= IPV4_MAX_PREFIXLEN - 1;
#ifdef HAVE_IPV6
  if (ifa->ifa_family == AF_INET6) {
    peeronly = if_is_pointopoint (ifp) ||
	       ifa->ifa_prefixlen >= IPV6_MAX_PREFIXLEN - 1;
  }
#endif /* HAVE_IPV6*/
  if (!(tb[IFA_LOCAL] && tb[IFA_ADDRESS])) {
  	/* FIXME: IPv6 Appears to have only IFA_ADDRESS */
  	peeronly=0;
  }

  /* network. prefixlen applies to IFA_ADDRESS rather than IFA_LOCAL */
  if (tb[IFA_ADDRESS] && !peeronly)
    addr = RTA_DATA (tb[IFA_ADDRESS]);
  else if (tb[IFA_LOCAL])
    addr = RTA_DATA (tb[IFA_LOCAL]);
  else
    addr = NULL;

  /* broadcast/peer */
  if (tb[IFA_BROADCAST])
    broad = RTA_DATA (tb[IFA_BROADCAST]);
  else if (tb[IFA_ADDRESS] && peeronly)
    broad = RTA_DATA (tb[IFA_ADDRESS]);		/* peer address specified */
  else
    broad = NULL;

  /* Flags. */
  if (ifa->ifa_flags & IFA_F_SECONDARY)
    SET_FLAG (flags, ZEBRA_IFA_SECONDARY);

  /* Label */
  if (tb[IFA_LABEL])
    label = (char *) RTA_DATA (tb[IFA_LABEL]);

  if (ifp && label && strcmp (ifp->name, label) == 0)
    label = NULL;

  /* Register interface address to the interface. */
  if (ifa->ifa_family == AF_INET)
    {
      if (h->nlmsg_type == RTM_NEWADDR) 
	connected_add_ipv4 (ifp, flags,
			    (struct in_addr *) addr, ifa->ifa_prefixlen, 
			    (struct in_addr *) broad, label);
      else 
	connected_delete_ipv4 (ifp, flags,
			       (struct in_addr *) addr, ifa->ifa_prefixlen, 
			       (struct in_addr *) broad, label);
    }
#ifdef HAVE_IPV6
  if (ifa->ifa_family == AF_INET6)
    {
      if (h->nlmsg_type == RTM_NEWADDR)
	connected_add_ipv6 (ifp, 
			    (struct in6_addr *) addr, ifa->ifa_prefixlen, 
			    (struct in6_addr *) broad);
      else
	connected_delete_ipv6 (ifp, 
			       (struct in6_addr *) addr, ifa->ifa_prefixlen, 
			       (struct in6_addr *) broad);
    }
#endif /* HAVE_IPV6*/

  return 0;
}

/* Looking up routing table by netlink interface. */
int
netlink_routing_table (struct sockaddr_nl *snl, struct nlmsghdr *h)
{
  int len;
  struct rtmsg *rtm;
  struct rtattr *tb [RTA_MAX + 1];
  u_char flags = 0;
  
  char anyaddr[16] = {0};

  int index;
  int table;
  void *dest;
  void *gate;

  rtm = NLMSG_DATA (h);

  if (h->nlmsg_type != RTM_NEWROUTE)
    return 0;
  if (rtm->rtm_type != RTN_UNICAST)
    return 0;

  table = rtm->rtm_table;
#if 0		/* we weed them out later in rib_weed_tables () */
  if (table != RT_TABLE_MAIN && table != rtm_table_default)
    return 0;
#endif

  len = h->nlmsg_len - NLMSG_LENGTH(sizeof (struct rtmsg));
  if (len < 0)
    return -1;

  memset (tb, 0, sizeof tb);
  netlink_parse_rtattr (tb, RTA_MAX, RTM_RTA (rtm), len);

  if (rtm->rtm_flags & RTM_F_CLONED)
    return 0;
  if (rtm->rtm_protocol == RTPROT_REDIRECT)
    return 0;
  if (rtm->rtm_protocol == RTPROT_KERNEL)
    return 0;

  if (rtm->rtm_src_len != 0)
    return 0;

  /* Route which inserted by Zebra. */
  if (rtm->rtm_protocol == RTPROT_ZEBRA)
    flags |= ZEBRA_FLAG_SELFROUTE;
  
  index = 0;
  dest = NULL;
  gate = NULL;

  if (tb[RTA_OIF])
    index = *(int *) RTA_DATA (tb[RTA_OIF]);

  if (tb[RTA_DST])
    dest = RTA_DATA (tb[RTA_DST]);
  else
    dest = anyaddr;

  /* Multipath treatment is needed. */
  if (tb[RTA_GATEWAY])
    gate = RTA_DATA (tb[RTA_GATEWAY]);

  if (rtm->rtm_family == AF_INET)
    {
      struct prefix_ipv4 p;
      p.family = AF_INET;
      memcpy (&p.prefix, dest, 4);
      p.prefixlen = rtm->rtm_dst_len;

      rib_add_ipv4 (ZEBRA_ROUTE_KERNEL, flags, &p, gate, index, table, 0, 0);
    }
#ifdef HAVE_IPV6
  if (rtm->rtm_family == AF_INET6)
    {
      struct prefix_ipv6 p;
      p.family = AF_INET6;
      memcpy (&p.prefix, dest, 16);
      p.prefixlen = rtm->rtm_dst_len;

      rib_add_ipv6 (ZEBRA_ROUTE_KERNEL, flags, &p, gate, index, table);
    }
#endif /* HAVE_IPV6 */

  return 0;
}

struct message rtproto_str [] = 
{
  {RTPROT_REDIRECT, "redirect"},
  {RTPROT_KERNEL,   "kernel"},
  {RTPROT_BOOT,     "boot"},
  {RTPROT_STATIC,   "static"},
  {RTPROT_GATED,    "GateD"},
  {RTPROT_RA,       "router advertisement"},
  {RTPROT_MRT,      "MRT"},
  {RTPROT_ZEBRA,    "Zebra"},
#ifdef RTPROT_BIRD
  {RTPROT_BIRD,     "BIRD"},
#endif /* RTPROT_BIRD */
  {0,               NULL}
};

/* Routing information change from the kernel. */
int
netlink_route_change (struct sockaddr_nl *snl, struct nlmsghdr *h)
{
  int len;
  struct rtmsg *rtm;
  struct rtattr *tb [RTA_MAX + 1];
  
  char anyaddr[16] = {0};

  int index;
  int table;
  void *dest;
  void *gate;

  rtm = NLMSG_DATA (h);

  if (! (h->nlmsg_type == RTM_NEWROUTE || h->nlmsg_type == RTM_DELROUTE))
    {
      /* If this is not route add/delete message print warning. */
      zlog_warn ("Kernel message: %d\n", h->nlmsg_type);
      return 0;
    }

  /* Connected route. */
  if (IS_ZEBRA_DEBUG_KERNEL)
    zlog_info ("%s %s %s proto %s",
	       h->nlmsg_type == RTM_NEWROUTE ? "RTM_NEWROUTE" : "RTM_DELROUTE",
	       rtm->rtm_family == AF_INET ? "ipv4" : "ipv6",
	       rtm->rtm_type == RTN_UNICAST ? "unicast" : "multicast",
	       lookup (rtproto_str, rtm->rtm_protocol));

  if (rtm->rtm_type != RTN_UNICAST)
    {
      return 0;
    }

  table = rtm->rtm_table;
  if (table != RT_TABLE_MAIN && table != rtm_table_default)
    {
      return 0;
    }

  len = h->nlmsg_len - NLMSG_LENGTH(sizeof (struct rtmsg));
  if (len < 0)
    return -1;

  memset (tb, 0, sizeof tb);
  netlink_parse_rtattr (tb, RTA_MAX, RTM_RTA (rtm), len);

  if (rtm->rtm_flags & RTM_F_CLONED)
    return 0;
  if (rtm->rtm_protocol == RTPROT_REDIRECT)
    return 0;
  if (rtm->rtm_protocol == RTPROT_KERNEL)
    return 0;

  if (rtm->rtm_protocol == RTPROT_ZEBRA && h->nlmsg_type == RTM_NEWROUTE)
    return 0;

  if (rtm->rtm_src_len != 0)
    {
      zlog_warn ("netlink_route_change(): no src len");
      return 0;
    }
  
  index = 0;
  dest = NULL;
  gate = NULL;

  if (tb[RTA_OIF])
    index = *(int *) RTA_DATA (tb[RTA_OIF]);

  if (tb[RTA_DST])
    dest = RTA_DATA (tb[RTA_DST]);
  else
    dest = anyaddr;

  if (tb[RTA_GATEWAY])
    gate = RTA_DATA (tb[RTA_GATEWAY]);

  if (rtm->rtm_family == AF_INET)
    {
      struct prefix_ipv4 p;
      p.family = AF_INET;
      memcpy (&p.prefix, dest, 4);
      p.prefixlen = rtm->rtm_dst_len;

      if (IS_ZEBRA_DEBUG_KERNEL)
	{
	  if (h->nlmsg_type == RTM_NEWROUTE)
	    zlog_info ("RTM_NEWROUTE %s/%d",
		       inet_ntoa (p.prefix), p.prefixlen);
	  else
	    zlog_info ("RTM_DELROUTE %s/%d",
		       inet_ntoa (p.prefix), p.prefixlen);
	}

      if (h->nlmsg_type == RTM_NEWROUTE)
	rib_add_ipv4 (ZEBRA_ROUTE_KERNEL, 0, &p, gate, index, table, 0, 0);
      else
	rib_delete_ipv4 (ZEBRA_ROUTE_KERNEL, 0, &p, gate, index, table);
    }

#ifdef HAVE_IPV6
  if (rtm->rtm_family == AF_INET6)
    {
      struct prefix_ipv6 p;
      char buf[BUFSIZ];

      p.family = AF_INET6;
      memcpy (&p.prefix, dest, 16);
      p.prefixlen = rtm->rtm_dst_len;

      if (IS_ZEBRA_DEBUG_KERNEL)
	{
	  if (h->nlmsg_type == RTM_NEWROUTE)
	    zlog_info ("RTM_NEWROUTE %s/%d",
		       inet_ntop (AF_INET6, &p.prefix, buf, BUFSIZ),
		       p.prefixlen);
	  else
	    zlog_info ("RTM_DELROUTE %s/%d",
		       inet_ntop (AF_INET6, &p.prefix, buf, BUFSIZ),
		       p.prefixlen);
	}

      if (h->nlmsg_type == RTM_NEWROUTE)
	rib_add_ipv6 (ZEBRA_ROUTE_KERNEL, 0, &p, gate, index, 0);
      else
	rib_delete_ipv6 (ZEBRA_ROUTE_KERNEL, 0, &p, gate, index, 0);
    }
#endif /* HAVE_IPV6 */

  return 0;
}

int
netlink_link_change (struct sockaddr_nl *snl, struct nlmsghdr *h)
{
  int len;
  struct ifinfomsg *ifi;
  struct rtattr *tb [IFLA_MAX + 1];
  struct interface *ifp;
  char *name;

  ifi = NLMSG_DATA (h);

  if (! (h->nlmsg_type == RTM_NEWLINK || h->nlmsg_type == RTM_DELLINK))
    {
      /* If this is not link add/delete message so print warning. */
      zlog_warn ("netlink_link_change: wrong kernel message %d\n",
		 h->nlmsg_type);
      return 0;
    }

  len = h->nlmsg_len - NLMSG_LENGTH (sizeof (struct ifinfomsg));
  if (len < 0)
    return -1;

  /* Looking up interface name. */
  memset (tb, 0, sizeof tb);
  netlink_parse_rtattr (tb, IFLA_MAX, IFLA_RTA (ifi), len);
  if (tb[IFLA_IFNAME] == NULL)
    return -1;
  name = (char *)RTA_DATA(tb[IFLA_IFNAME]);

  /* Add interface. */
  if (h->nlmsg_type == RTM_NEWLINK)
    {
      ifp = if_lookup_by_name (name);

      if (ifp == NULL || ! CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE))
	{
	  if (ifp == NULL)
	    ifp = if_get_by_name (name);

	  ifp->ifindex = ifi->ifi_index;
	  ifp->flags = ifi->ifi_flags & 0x0000fffff;
	  ifp->mtu = *(int *)RTA_DATA (tb[IFLA_MTU]);
	  ifp->metric = 1;

	  /* If new link is added. */
	  if_add_update(ifp);
	}      
      else
	{
	  /* Interface status change. */
	  ifp->ifindex = ifi->ifi_index;
	  ifp->mtu = *(int *)RTA_DATA (tb[IFLA_MTU]);
	  ifp->metric = 1;

	  if (if_is_operative (ifp))
	    {
	      ifp->flags = ifi->ifi_flags & 0x0000fffff;
	      if (! if_is_operative (ifp))
		if_down (ifp);
	    }
	  else
	    {
	      ifp->flags = ifi->ifi_flags & 0x0000fffff;
	      if (if_is_operative (ifp))
		if_up (ifp);
	    }
	}
    }
  else
    {
      /* RTM_DELLINK. */
      ifp = if_lookup_by_name (name);

      if (ifp == NULL)
	{
	  zlog (NULL, LOG_WARNING, "interface %s is deleted but can't find",
                name);
	  return 0;
	}
      
      if_delete_update (ifp);
    }

  return 0;
}

int
netlink_information_fetch (struct sockaddr_nl *snl, struct nlmsghdr *h)
{
  switch (h->nlmsg_type)
    {
    case RTM_NEWROUTE:
      return netlink_route_change (snl, h);
      break;
    case RTM_DELROUTE:
      return netlink_route_change (snl, h);
      break;
    case RTM_NEWLINK:
      return netlink_link_change (snl, h);
      break;
    case RTM_DELLINK:
      return netlink_link_change (snl, h);
      break;
    case RTM_NEWADDR:
      return netlink_interface_addr (snl, h);
      break;
    case RTM_DELADDR:
      return netlink_interface_addr (snl, h);
      break;
    default:
      zlog_warn ("Unknown netlink nlmsg_type %d\n", h->nlmsg_type);
      break;
    }
  return 0;
}

/* Interface lookup by netlink socket. */
int
interface_lookup_netlink ()
{
  int ret;

  /* Get interface information. */
  ret = netlink_request (AF_PACKET, RTM_GETLINK, &netlink_cmd);
  if (ret < 0)
    return ret;
  ret = netlink_parse_info (netlink_interface, &netlink_cmd);
  if (ret < 0)
    return ret;

  /* Get IPv4 address of the interfaces. */
  ret = netlink_request (AF_INET, RTM_GETADDR, &netlink_cmd);
  if (ret < 0)
    return ret;
  ret = netlink_parse_info (netlink_interface_addr, &netlink_cmd);
  if (ret < 0)
    return ret;

#ifdef HAVE_IPV6
  /* Get IPv6 address of the interfaces. */
  ret = netlink_request (AF_INET6, RTM_GETADDR, &netlink_cmd);
  if (ret < 0)
    return ret;
  ret = netlink_parse_info (netlink_interface_addr, &netlink_cmd);
  if (ret < 0)
    return ret;
#endif /* HAVE_IPV6 */

  return 0;
}

/* Routing table read function using netlink interface.  Only called
   bootstrap time. */
int
netlink_route_read ()
{
  int ret;

  /* Get IPv4 routing table. */
  ret = netlink_request (AF_INET, RTM_GETROUTE, &netlink_cmd);
  if (ret < 0)
    return ret;
  ret = netlink_parse_info (netlink_routing_table, &netlink_cmd);
  if (ret < 0)
    return ret;

#ifdef HAVE_IPV6
  /* Get IPv6 routing table. */
  ret = netlink_request (AF_INET6, RTM_GETROUTE, &netlink_cmd);
  if (ret < 0)
    return ret;
  ret = netlink_parse_info (netlink_routing_table, &netlink_cmd);
  if (ret < 0)
    return ret;
#endif /* HAVE_IPV6 */

  return 0;
}

/* Utility function  comes from iproute2. 
   Authors:	Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru> */
int
addattr_l (struct nlmsghdr *n, int maxlen, int type, void *data, int alen)
{
  int len;
  struct rtattr *rta;

  len = RTA_LENGTH(alen);

  if (NLMSG_ALIGN(n->nlmsg_len) + len > maxlen)
    return -1;

  rta = (struct rtattr*) (((char*)n) + NLMSG_ALIGN (n->nlmsg_len));
  rta->rta_type = type;
  rta->rta_len = len;
  memcpy (RTA_DATA(rta), data, alen);
  n->nlmsg_len = NLMSG_ALIGN (n->nlmsg_len) + len;

  return 0;
}

int
rta_addattr_l (struct rtattr *rta, int maxlen, int type, void *data, int alen)
{
  int len;
  struct rtattr *subrta;

  len = RTA_LENGTH(alen);

  if (RTA_ALIGN(rta->rta_len) + len > maxlen)
    return -1;

  subrta = (struct rtattr*) (((char*)rta) + RTA_ALIGN (rta->rta_len));
  subrta->rta_type = type;
  subrta->rta_len = len;
  memcpy (RTA_DATA(subrta), data, alen);
  rta->rta_len = NLMSG_ALIGN (rta->rta_len) + len;

  return 0;
}

/* Utility function comes from iproute2. 
   Authors:	Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru> */
int
addattr32 (struct nlmsghdr *n, int maxlen, int type, int data)
{
  int len;
  struct rtattr *rta;
  
  len = RTA_LENGTH(4);
  
  if (NLMSG_ALIGN (n->nlmsg_len) + len > maxlen)
    return -1;

  rta = (struct rtattr*) (((char*)n) + NLMSG_ALIGN (n->nlmsg_len));
  rta->rta_type = type;
  rta->rta_len = len;
  memcpy (RTA_DATA(rta), &data, 4);
  n->nlmsg_len = NLMSG_ALIGN (n->nlmsg_len) + len;

  return 0;
}

static int
netlink_talk_filter (struct sockaddr_nl *snl, struct nlmsghdr *h)
{
  zlog_warn ("netlink_talk: ignoring message type 0x%04x", h->nlmsg_type);
  return 0;
}

/* sendmsg() to netlink socket then recvmsg(). */
int
netlink_talk (struct nlmsghdr *n, struct nlsock *nl)
{
  int status;
  struct sockaddr_nl snl;
  struct iovec iov = { (void*) n, n->nlmsg_len };
  struct msghdr msg = {(void*) &snl, sizeof snl, &iov, 1, NULL, 0, 0};
  int flags = 0;
  
  memset (&snl, 0, sizeof snl);
  snl.nl_family = AF_NETLINK;
  
  n->nlmsg_seq = ++netlink_cmd.seq;

  /* Request an acknowledgement by setting NLM_F_ACK */
  n->nlmsg_flags |= NLM_F_ACK;
  
  if (IS_ZEBRA_DEBUG_KERNEL) 
    zlog_info ("netlink_talk: %s type %s(%u), seq=%u", netlink_cmd.name,
	      lookup (nlmsg_str, n->nlmsg_type), n->nlmsg_type,
	      n->nlmsg_seq);

  /* Send message to netlink interface. */
  status = sendmsg (nl->sock, &msg, 0);
  if (status < 0)
    {
      zlog (NULL, LOG_ERR, "netlink_talk sendmsg() error: %s",
	    strerror (errno));
      return -1;
    }
  
  /* 
   * Change socket flags for blocking I/O. 
   * This ensures we wait for a reply in netlink_parse_info().
   */
  if((flags = fcntl(nl->sock, F_GETFL, 0)) < 0) 
    {
      zlog (NULL, LOG_ERR, "%s:%i F_GETFL error: %s", 
              __FUNCTION__, __LINE__, strerror (errno));
    }
  flags &= ~O_NONBLOCK;
  if(fcntl(nl->sock, F_SETFL, flags) < 0) 
    {
      zlog (NULL, LOG_ERR, "%s:%i F_SETFL error: %s", 
              __FUNCTION__, __LINE__, strerror (errno));
    }

  /* 
   * Get reply from netlink socket. 
   * The reply should either be an acknowlegement or an error.
   */
  status = netlink_parse_info (netlink_talk_filter, nl);
  
  /* Restore socket flags for nonblocking I/O */
  flags |= O_NONBLOCK;
  if(fcntl(nl->sock, F_SETFL, flags) < 0) 
    {
      zlog (NULL, LOG_ERR, "%s:%i F_SETFL error: %s", 
              __FUNCTION__, __LINE__, strerror (errno));
    }
  
  return status;
}

/* Routing table change via netlink interface. */
int
netlink_route (int cmd, int family, void *dest, int length, void *gate,
	       int index, int zebra_flags, int table)
{
  int ret;
  int bytelen;
  struct sockaddr_nl snl;
  int discard;

  struct 
  {
    struct nlmsghdr n;
    struct rtmsg r;
    char buf[1024];
  } req;

  memset (&req, 0, sizeof req);

  bytelen = (family == AF_INET ? 4 : 16);

  req.n.nlmsg_len = NLMSG_LENGTH (sizeof (struct rtmsg));
  req.n.nlmsg_flags = NLM_F_CREATE | NLM_F_REQUEST;
  req.n.nlmsg_type = cmd;
  req.r.rtm_family = family;
  req.r.rtm_table = table;
  req.r.rtm_dst_len = length;

  if (zebra_flags & ZEBRA_FLAG_BLACKHOLE)
    discard = 1;
  else
    discard = 0;

  if (cmd == RTM_NEWROUTE) 
    {
      req.r.rtm_protocol = RTPROT_ZEBRA;
      req.r.rtm_scope = RT_SCOPE_UNIVERSE;

      if (discard)
	req.r.rtm_type = RTN_BLACKHOLE;
      else
	req.r.rtm_type = RTN_UNICAST;
    }

  if (dest)
    addattr_l (&req.n, sizeof req, RTA_DST, dest, bytelen);

  if (! discard)
    {
      if (gate)
	addattr_l (&req.n, sizeof req, RTA_GATEWAY, gate, bytelen);
      if (index > 0)
	addattr32 (&req.n, sizeof req, RTA_OIF, index);
    }

  /* Destination netlink address. */
  memset (&snl, 0, sizeof snl);
  snl.nl_family = AF_NETLINK;

  /* Talk to netlink socket. */
  ret = netlink_talk (&req.n, &netlink);
  if (ret < 0)
    return -1;

  return 0;
}

/* Routing table change via netlink interface. */
int
netlink_route_multipath (int cmd, struct prefix *p, struct rib *rib,
			 int family)
{
  int bytelen;
  struct sockaddr_nl snl;
  struct nexthop *nexthop = NULL;
  int nexthop_num = 0;
  struct nlsock *nl;
  int discard;

  struct 
  {
    struct nlmsghdr n;
    struct rtmsg r;
    char buf[1024];
  } req;

  memset (&req, 0, sizeof req);

  bytelen = (family == AF_INET ? 4 : 16);

  req.n.nlmsg_len = NLMSG_LENGTH (sizeof (struct rtmsg));
  req.n.nlmsg_flags = NLM_F_CREATE | NLM_F_REQUEST;
  req.n.nlmsg_type = cmd;
  req.r.rtm_family = family;
  req.r.rtm_table = rib->table;
  req.r.rtm_dst_len = p->prefixlen;

  if (rib->flags & ZEBRA_FLAG_BLACKHOLE)
    discard = 1;
  else
    discard = 0;

  if (cmd == RTM_NEWROUTE) 
    {
      req.r.rtm_protocol = RTPROT_ZEBRA;
      req.r.rtm_scope = RT_SCOPE_UNIVERSE;

      if (discard)
	req.r.rtm_type = RTN_BLACKHOLE;
      else
	req.r.rtm_type = RTN_UNICAST;
    }

  addattr_l (&req.n, sizeof req, RTA_DST, &p->u.prefix, bytelen);

  /* Metric. */
  addattr32 (&req.n, sizeof req, RTA_PRIORITY, rib->metric);

  if (discard)
    {
      if (cmd == RTM_NEWROUTE)
	for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next)
	  SET_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB);
      goto skip;
    }

  /* Multipath case. */
  if (rib->nexthop_active_num == 1 || MULTIPATH_NUM == 1)
    {
      for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next)
	{
	  if ((cmd == RTM_NEWROUTE 
	       && CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE))
	      || (cmd == RTM_DELROUTE
		  && CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)))
	    {
	      if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE))
		{
		  if (nexthop->rtype == NEXTHOP_TYPE_IPV4 
		      || nexthop->rtype == NEXTHOP_TYPE_IPV4_IFINDEX)
		    addattr_l (&req.n, sizeof req, RTA_GATEWAY,
			       &nexthop->rgate.ipv4, bytelen);
#ifdef HAVE_IPV6
		  if (nexthop->rtype == NEXTHOP_TYPE_IPV6 
		      || nexthop->rtype == NEXTHOP_TYPE_IPV6_IFINDEX 
		      || nexthop->rtype == NEXTHOP_TYPE_IPV6_IFNAME)
		    addattr_l (&req.n, sizeof req, RTA_GATEWAY,
			       &nexthop->rgate.ipv6, bytelen);
#endif /* HAVE_IPV6 */
		  if (nexthop->rtype == NEXTHOP_TYPE_IFINDEX
		      || nexthop->rtype == NEXTHOP_TYPE_IFNAME
		      || nexthop->rtype == NEXTHOP_TYPE_IPV4_IFINDEX
		      || nexthop->rtype == NEXTHOP_TYPE_IPV6_IFINDEX
		      || nexthop->rtype == NEXTHOP_TYPE_IPV6_IFNAME)
		    addattr32 (&req.n, sizeof req, RTA_OIF,
			       nexthop->rifindex);
		}
	      else
		{
		  if (nexthop->type == NEXTHOP_TYPE_IPV4 
		      || nexthop->type == NEXTHOP_TYPE_IPV4_IFINDEX)
		    addattr_l (&req.n, sizeof req, RTA_GATEWAY,
			       &nexthop->gate.ipv4, bytelen);
#ifdef HAVE_IPV6
		  if (nexthop->type == NEXTHOP_TYPE_IPV6 
		      || nexthop->type == NEXTHOP_TYPE_IPV6_IFNAME
		      || nexthop->type == NEXTHOP_TYPE_IPV6_IFINDEX)
		    addattr_l (&req.n, sizeof req, RTA_GATEWAY,
			       &nexthop->gate.ipv6, bytelen);
#endif /* HAVE_IPV6 */
		  if (nexthop->type == NEXTHOP_TYPE_IFINDEX
		      || nexthop->type == NEXTHOP_TYPE_IFNAME
		      || nexthop->type == NEXTHOP_TYPE_IPV4_IFINDEX
		      || nexthop->type == NEXTHOP_TYPE_IPV6_IFINDEX
		      || nexthop->type == NEXTHOP_TYPE_IPV6_IFNAME)
		    addattr32 (&req.n, sizeof req, RTA_OIF, nexthop->ifindex);
		}

	      if (cmd == RTM_NEWROUTE)
		SET_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB);

	      nexthop_num++;
	      break;
	    }
	}
    }
  else
    {
      char buf[1024];
      struct rtattr *rta = (void *) buf;
      struct rtnexthop *rtnh;

      rta->rta_type = RTA_MULTIPATH;
      rta->rta_len = RTA_LENGTH(0);
      rtnh = RTA_DATA(rta);

      nexthop_num = 0;
      for (nexthop = rib->nexthop;
	   nexthop && (MULTIPATH_NUM == 0 || nexthop_num < MULTIPATH_NUM);
	   nexthop = nexthop->next)
	{
	  if ((cmd == RTM_NEWROUTE 
	       && CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE))
	      || (cmd == RTM_DELROUTE
		  && CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)))
	    {
	      nexthop_num++;

	      rtnh->rtnh_len = sizeof (*rtnh);
	      rtnh->rtnh_flags = 0;
	      rtnh->rtnh_hops = 0;
	      rta->rta_len += rtnh->rtnh_len;

	      if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE))
		{
		  if (nexthop->rtype == NEXTHOP_TYPE_IPV4
		      || nexthop->rtype == NEXTHOP_TYPE_IPV4_IFINDEX)
		    {
		      rta_addattr_l (rta, 4096, RTA_GATEWAY,
				     &nexthop->rgate.ipv4, bytelen);
		      rtnh->rtnh_len += sizeof (struct rtattr) + 4;
		    }
#ifdef HAVE_IPV6
		  if (nexthop->rtype == NEXTHOP_TYPE_IPV6
		      || nexthop->rtype == NEXTHOP_TYPE_IPV6_IFNAME
		      || nexthop->rtype == NEXTHOP_TYPE_IPV6_IFINDEX)
		    rta_addattr_l (rta, 4096, RTA_GATEWAY,
				   &nexthop->rgate.ipv6, bytelen);
#endif /* HAVE_IPV6 */
		  /* ifindex */
		  if (nexthop->rtype == NEXTHOP_TYPE_IFINDEX
		      || nexthop->rtype == NEXTHOP_TYPE_IFNAME
		      || nexthop->rtype == NEXTHOP_TYPE_IPV4_IFINDEX
		      || nexthop->rtype == NEXTHOP_TYPE_IPV6_IFINDEX
		      || nexthop->rtype == NEXTHOP_TYPE_IPV6_IFNAME)
		    rtnh->rtnh_ifindex = nexthop->rifindex;
		  else
		    rtnh->rtnh_ifindex = 0;
		}
	      else
		{
		  if (nexthop->type == NEXTHOP_TYPE_IPV4
		      || nexthop->type == NEXTHOP_TYPE_IPV4_IFINDEX)
		    {
		      rta_addattr_l (rta, 4096, RTA_GATEWAY,
				     &nexthop->gate.ipv4, bytelen);
		      rtnh->rtnh_len += sizeof (struct rtattr) + 4;
		    }
#ifdef HAVE_IPV6
		  if (nexthop->type == NEXTHOP_TYPE_IPV6
		      || nexthop->type == NEXTHOP_TYPE_IPV6_IFNAME
		      || nexthop->type == NEXTHOP_TYPE_IPV6_IFINDEX)
		    rta_addattr_l (rta, 4096, RTA_GATEWAY,
				   &nexthop->gate.ipv6, bytelen);
#endif /* HAVE_IPV6 */
		  /* ifindex */
		  if (nexthop->type == NEXTHOP_TYPE_IFINDEX
		      || nexthop->type == NEXTHOP_TYPE_IFNAME
		      || nexthop->type == NEXTHOP_TYPE_IPV4_IFINDEX
		      || nexthop->type == NEXTHOP_TYPE_IPV6_IFNAME
		      || nexthop->type == NEXTHOP_TYPE_IPV6_IFINDEX)
		    rtnh->rtnh_ifindex = nexthop->ifindex;
		  else
		    rtnh->rtnh_ifindex = 0;
		}
	      rtnh = RTNH_NEXT(rtnh);

	      if (cmd == RTM_NEWROUTE)
		SET_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB);
	    }
	}

      if (rta->rta_len > RTA_LENGTH (0))
	addattr_l (&req.n, 1024, RTA_MULTIPATH, RTA_DATA(rta),
		   RTA_PAYLOAD(rta));
    }

  /* If there is no useful nexthop then return. */
  if (nexthop_num == 0)
    {
      if (IS_ZEBRA_DEBUG_KERNEL)
	zlog_info ("netlink_route_multipath(): No useful nexthop.");
      return 0;
    }

 skip:

  /* Destination netlink address. */
  memset (&snl, 0, sizeof snl);
  snl.nl_family = AF_NETLINK;

  if (family == AF_INET)
    nl = &netlink_cmd;
  else
    nl = &netlink;

  /* Talk to netlink socket. */
  return netlink_talk (&req.n, nl);
}

int
kernel_add_ipv4 (struct prefix *p, struct rib *rib)
{
  return netlink_route_multipath (RTM_NEWROUTE, p, rib, AF_INET);
}

int
kernel_delete_ipv4 (struct prefix *p, struct rib *rib)
{
  return netlink_route_multipath (RTM_DELROUTE, p, rib, AF_INET);
}

#ifdef HAVE_IPV6
int
kernel_add_ipv6 (struct prefix *p, struct rib *rib)
{
  return netlink_route_multipath (RTM_NEWROUTE, p, rib, AF_INET6);
}

int
kernel_delete_ipv6 (struct prefix *p, struct rib *rib)
{
  return netlink_route_multipath (RTM_DELROUTE, p, rib, AF_INET6);
}

/* Delete IPv6 route from the kernel. */
int
kernel_delete_ipv6_old (struct prefix_ipv6 *dest, struct in6_addr *gate,
			int index, int flags, int table)
{
  return netlink_route (RTM_DELROUTE, AF_INET6, &dest->prefix, dest->prefixlen,
			gate, index, flags, table);
}
#endif /* HAVE_IPV6 */

/* Interface address modification. */
int
netlink_address (int cmd, int family, struct interface *ifp,
		 struct connected *ifc)
{
  int bytelen;
  struct prefix *p;

  struct 
  {
    struct nlmsghdr n;
    struct ifaddrmsg ifa;
    char buf[1024];
  } req;

  p = ifc->address;
  memset (&req, 0, sizeof req);

  bytelen = (family == AF_INET ? 4 : 16);

  req.n.nlmsg_len = NLMSG_LENGTH (sizeof(struct ifaddrmsg));
  req.n.nlmsg_flags = NLM_F_REQUEST;
  req.n.nlmsg_type = cmd;
  req.ifa.ifa_family = family;

  req.ifa.ifa_index = ifp->ifindex;
  req.ifa.ifa_prefixlen = p->prefixlen;

  addattr_l (&req.n, sizeof req, IFA_LOCAL, &p->u.prefix, bytelen);

  if (family == AF_INET && cmd == RTM_NEWADDR)
    {
      if (if_is_broadcast (ifp) && ifc->destination)
	{
	  p = ifc->destination;
	  addattr_l(&req.n, sizeof req, IFA_BROADCAST, &p->u.prefix, bytelen);
	}
    }

  if (CHECK_FLAG (ifc->flags, ZEBRA_IFA_SECONDARY))
    SET_FLAG (req.ifa.ifa_flags, IFA_F_SECONDARY);
    
  if (ifc->label)
    addattr_l (&req.n, sizeof req, IFA_LABEL, ifc->label,
	       strlen (ifc->label) + 1);

  return netlink_talk (&req.n, &netlink_cmd);
}

int
kernel_address_add_ipv4 (struct interface *ifp, struct connected *ifc)
{
  return netlink_address (RTM_NEWADDR, AF_INET, ifp, ifc);
}

int
kernel_address_delete_ipv4 (struct interface *ifp, struct connected *ifc)
{
  return netlink_address (RTM_DELADDR, AF_INET, ifp, ifc);
}


extern struct thread_master *master;

/* Kernel route reflection. */
int
kernel_read (struct thread *thread)
{
  int ret;
  int sock;

  sock = THREAD_FD (thread);
  ret = netlink_parse_info (netlink_information_fetch, &netlink);
  thread_add_read (master, kernel_read, NULL, netlink.sock);

  return 0;
}

/* Exported interface function.  This function simply calls
   netlink_socket (). */
void
kernel_init ()
{
  unsigned long groups;

  groups = RTMGRP_LINK|RTMGRP_IPV4_ROUTE|RTMGRP_IPV4_IFADDR;
#ifdef HAVE_IPV6
  groups |= RTMGRP_IPV6_ROUTE|RTMGRP_IPV6_IFADDR;
#endif /* HAVE_IPV6 */
  netlink_socket (&netlink, groups);
  netlink_socket (&netlink_cmd, 0);

  /* Register kernel socket. */
  if (netlink.sock > 0)
    thread_add_read (master, kernel_read, NULL, netlink.sock);
}
