/*
 * IS-IS Rout(e)ing protocol - isis_zebra.c   
 *
 * Copyright (C) 2001,2002   Sampo Saaristo
 *                           Tampere University of Technology      
 *                           Institute of Communications Engineering
 *
 * This program is free software; you can redistribute it and/or modify it 
 * under the terms of the GNU General Public Licenseas published by the Free 
 * Software Foundation; either version 2 of the License, or (at your option) 
 * any later version.
 *
 * 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, write to the Free Software Foundation, Inc., 
 * 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

#include <zebra.h>
#include <net/ethernet.h>

#include "thread.h"
#include "command.h"
#include "memory.h"
#include "log.h"
#include "if.h"
#include "network.h"
#include "prefix.h"
#include "zclient.h"
#include "stream.h"
#include "linklist.h"

#include "isisd/isis_constants.h"
#include "isisd/isis_common.h"
#include "isisd/isis_circuit.h"
#include "isisd/isis_csm.h"
#include "isisd/isis_route.h"
#include "isisd/isis_zebra.h"

struct zclient *zclient = NULL;

extern struct thread_master *master;

int 
isis_zebra_if_add (int command, struct zclient *zclient, zebra_size_t length)
{
  struct interface *ifp;

  ifp = zebra_interface_add_read (zclient->ibuf);
  

  zlog_info ("Zebra I/F add: %s index %d flags %ld metric %d mtu %d",
	     ifp->name, ifp->ifindex, ifp->flags, ifp->metric, ifp->mtu);
  
  if (if_is_up (ifp))
    isis_csm_state_change (IF_UP_FROM_Z, circuit_scan_by_ifp (ifp), ifp);
  
  return 0;
}

int
isis_zebra_if_del (int command, struct zclient *zclient, zebra_size_t length)
{
  struct interface *ifp;
  struct stream *s;

  s = zclient->ibuf;
  ifp = zebra_interface_state_read (s);
  
  if (!ifp)
    return 0;

  if (if_is_up (ifp))
    zlog_warn ("Zebra: got delete of %s, but interface is still up",
               ifp->name);

  zlog_info ("Zebra I/F delete: %s index %d flags %ld metric %d mtu %d",
	     ifp->name, ifp->ifindex, ifp->flags, ifp->metric, ifp->mtu);

  if_delete (ifp);
  
  isis_csm_state_change (IF_DOWN_FROM_Z, circuit_scan_by_ifp (ifp), ifp);

  return 0;
}

struct interface *
zebra_interface_if_lookup (struct stream *s)
{
  struct interface *ifp;
  u_char ifname_tmp[INTERFACE_NAMSIZ];

  /* Read interface name. */
  stream_get (ifname_tmp, s, INTERFACE_NAMSIZ);

  /* Lookup this by interface index. */
  ifp = if_lookup_by_name (ifname_tmp);

  /* If such interface does not exist, indicate an error */
  if (!ifp)
    return NULL;

  return ifp;
}

void
zebra_interface_if_set_value (struct stream *s, struct interface *ifp)
{
  /* Read interface's index. */
  ifp->ifindex = stream_getl (s);

  /* Read interface's value. */
  ifp->flags = stream_getl (s);
  ifp->metric = stream_getl (s);
  ifp->mtu = stream_getl (s);
  ifp->bandwidth = stream_getl (s);
}

int
isis_zebra_if_state_up (int command, struct zclient *zclient, 
			zebra_size_t length)
{
  struct interface *ifp;
  
  ifp = zebra_interface_if_lookup (zclient->ibuf);
    
  if (!ifp)
    return 0;
  
  if (if_is_up (ifp)) {
    zebra_interface_if_set_value (zclient->ibuf, ifp);
    isis_circuit_update_params (circuit_scan_by_ifp (ifp), ifp);
    return 0;
  }
  
  zebra_interface_if_set_value (zclient->ibuf, ifp);
  isis_csm_state_change (IF_UP_FROM_Z, circuit_scan_by_ifp (ifp), ifp);
  
  return 0;
}


int
isis_zebra_if_state_down (int command, struct zclient *zclient, 
			  zebra_size_t length)
{
  struct interface *ifp;
  
  ifp = zebra_interface_if_lookup (zclient->ibuf);
  
  if (ifp == NULL)
    return 0;
  
  if (if_is_up (ifp)) {
    zebra_interface_if_set_value (zclient->ibuf, ifp);
    isis_csm_state_change (IF_DOWN_FROM_Z, circuit_scan_by_ifp (ifp), ifp);
  }
  
  return 0;
}

int
isis_zebra_if_address_add (int command, struct zclient *zclient, 
                           zebra_size_t length)
{
  struct connected *c;
  struct prefix *p;
  u_char buf[BUFSIZ];

  c = zebra_interface_address_add_read (zclient->ibuf);
  
  if (c == NULL)
    return 0;
  
  p = c->address;
  
  prefix2str (p, buf, BUFSIZ);
#ifdef EXTREME_DEBUG
  if (p->family == AF_INET) 
    zlog_info ("connected IP address %s", buf);
#ifdef HAVE_IPV6
  if (p->family == AF_INET6)
    zlog_info ("connected IPv6 address %s", buf);
#endif /* HAVE_IPV6 */
#endif /* EXTREME_DEBUG */
  isis_circuit_add_addr (circuit_scan_by_ifp (c->ifp),  c);

  return 0;
}

int
isis_zebra_if_address_del (int command, struct zclient *client, 
                           zebra_size_t length)
{
  struct connected *c;
  struct interface *ifp;

  c = zebra_interface_address_delete_read (zclient->ibuf);
  
  if (c == NULL)
    return 0;
  
  ifp = c->ifp;
  
  connected_free (c);
  
  isis_circuit_del_addr (circuit_scan_by_ifp (ifp), c);
  
  return 0;
}

void
isis_zebra_route_add_ipv4 (struct prefix *prefix, 
                           struct isis_route_info *route_info)
{
  u_char message, flags;
  int psize;
  struct stream *stream;
  struct isis_nexthop *nexthop;
  struct listnode *node;

  if (CHECK_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNC))
    return;

  if (zclient->redist[ZEBRA_ROUTE_ISIS]) {
    message = 0;
    flags = 0;
    
    SET_FLAG (message, ZAPI_MESSAGE_NEXTHOP);
    SET_FLAG (message, ZAPI_MESSAGE_METRIC);
#if 0
    SET_FLAG (message, ZAPI_MESSAGE_DISTANCE);
#endif
    
    stream = zclient->obuf;
    stream_reset (stream);
    /* Length place holder. */
    stream_putw (stream, 0);
    /* command */
    stream_putc (stream, ZEBRA_IPV4_ROUTE_ADD);
    /* type */
    stream_putc (stream, ZEBRA_ROUTE_ISIS);
    /* flags */
    stream_putc (stream, flags);
    /* message */
    stream_putc (stream, message);
    /* prefix information */
    psize = PSIZE (prefix->prefixlen);
    stream_putc (stream, prefix->prefixlen);
    stream_write (stream, (u_char *)&prefix->u.prefix4, psize);      

    stream_putc (stream, listcount (route_info->nexthops));
    
    /* Nexthop, ifindex, distance and metric information */
    for (node = listhead (route_info->nexthops); node; nextnode (node)) {
      nexthop = getdata (node);
      /* FIXME: can it be ? */
      if (nexthop->ip.s_addr != INADDR_ANY) {
        stream_putc (stream, ZEBRA_NEXTHOP_IPV4);
        stream_put_in_addr (stream, &nexthop->ip);
      } else {
        stream_putc (stream, ZEBRA_NEXTHOP_IFINDEX);
        stream_putl (stream, nexthop->ifindex);
      }
    }
#if 0
    if (CHECK_FLAG (message, ZAPI_MESSAGE_DISTANCE))
      stream_putc (stream, route_info->depth);
#endif
    if (CHECK_FLAG (message, ZAPI_MESSAGE_METRIC))
      stream_putl (stream, route_info->cost);
    
    stream_putw_at (stream, 0, stream_get_endp (stream));
    writen (zclient->sock, stream->data, stream_get_endp (stream));
  }
}

void
isis_zebra_route_del_ipv4 (struct prefix *prefix, 
                           struct isis_route_info *route_info)
{
  struct zapi_ipv4 api;
  struct prefix_ipv4 prefix4;
  
  if (zclient->redist[ZEBRA_ROUTE_ISIS]) {
    api.type = ZEBRA_ROUTE_ISIS;
    api.flags = 0;
    api.message = 0;
    prefix4.family = AF_INET;
    prefix4.prefixlen = prefix->prefixlen;
    prefix4.prefix = prefix->u.prefix4;
    zapi_ipv4_delete (zclient, &prefix4, &api);
  }
  
  return;
}

#ifdef HAVE_IPV6
void
isis_zebra_route_add_ipv6 (struct prefix *prefix,
                           struct isis_route_info *route_info)
{
  struct zapi_ipv6 api;
  struct in6_addr **nexthop_list;
  unsigned int *ifindex_list;
  struct isis_nexthop6 *nexthop6;
  int i, size;
  struct listnode *node;
  struct prefix_ipv6 prefix6;

  if (CHECK_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNC))
    return;
  
  api.type = ZEBRA_ROUTE_ISIS;
  api.flags = 0;
  api.message = 0;
  SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP);
  SET_FLAG (api.message, ZAPI_MESSAGE_IFINDEX);
  SET_FLAG (api.message, ZAPI_MESSAGE_METRIC);
  api.metric = route_info->cost;
#if 0
  SET_FLAG (api.message, ZAPI_MESSAGE_DISTANCE);
  api.distance = route_info->depth;
#endif
  api.nexthop_num = listcount (route_info->nexthops6);
  api.ifindex_num = listcount (route_info->nexthops6);
  
  /* allocate memory for nexthop_list */
  size = sizeof (struct isis_nexthop6 *) * listcount (route_info->nexthops6);
  nexthop_list = (struct in6_addr **) XMALLOC (MTYPE_ISIS_TMP, size);
  if (!nexthop_list) {
    zlog_err ("isis_zebra_add_route_ipv6: out of memory!");
    return;
  }
  
  /* allocate memory for ifindex_list */
  size = sizeof (unsigned int) * listcount (route_info->nexthops6);
  ifindex_list = (unsigned int *) XMALLOC (MTYPE_ISIS_TMP, size);
  if (!ifindex_list) {
    zlog_err ("isis_zebra_add_route_ipv6: out of memory!");
    XFREE (MTYPE_ISIS_TMP, nexthop_list);
    return;
  }
  
  /* for each nexthop */
  i = 0;
  for (node = listhead (route_info->nexthops6); node; nextnode (node)) {
    nexthop6 = getdata (node);
    
    if (!IN6_IS_ADDR_LINKLOCAL (&nexthop6->ip6) &&
        !IN6_IS_ADDR_UNSPECIFIED (&nexthop6->ip6)) {
      api.nexthop_num--;
      api.ifindex_num--;
      continue;
    }
    
    nexthop_list[i] = &nexthop6->ip6;
    ifindex_list[i] = nexthop6->ifindex;
    i++;
  }
  
  api.nexthop = nexthop_list;
  api.ifindex = ifindex_list;
  
  if (api.nexthop_num && api.ifindex_num) {
    prefix6.family = AF_INET6;
    prefix6.prefixlen = prefix->prefixlen;
    memcpy (&prefix6.prefix, &prefix->u.prefix6, sizeof (struct in6_addr));
    zapi_ipv6_add (zclient, &prefix6, &api);
    SET_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNC);
  }
  
  XFREE (MTYPE_ISIS_TMP, nexthop_list);
  XFREE (MTYPE_ISIS_TMP, ifindex_list);
  
  return;
}

void
isis_zebra_route_del_ipv6 (struct prefix *prefix, 
                           struct isis_route_info *route_info)
{
  struct zapi_ipv6 api;
  struct in6_addr **nexthop_list;
  unsigned int *ifindex_list;
  struct isis_nexthop6 *nexthop6;
  int i, size;
  struct listnode *node;
  struct prefix_ipv6 prefix6;

  if (CHECK_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNC))
    return;
  
  api.type = ZEBRA_ROUTE_ISIS;
  api.flags = 0;
  api.message = 0;
  SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP);
  SET_FLAG (api.message, ZAPI_MESSAGE_IFINDEX);
  api.nexthop_num = listcount (route_info->nexthops6);
  api.ifindex_num = listcount (route_info->nexthops6);
  
  /* allocate memory for nexthop_list */
  size = sizeof (struct isis_nexthop6 *) * listcount (route_info->nexthops6);
  nexthop_list = (struct in6_addr **) XMALLOC (MTYPE_ISIS_TMP, size);
  if (!nexthop_list) {
    zlog_err ("isis_zebra_route_del_ipv6: out of memory!");
    return;
  }
  
  /* allocate memory for ifindex_list */
  size = sizeof (unsigned int) * listcount (route_info->nexthops6);
  ifindex_list = (unsigned int *) XMALLOC (MTYPE_ISIS_TMP, size);
  if (!ifindex_list) {
    zlog_err ("isis_zebra_route_del_ipv6: out of memory!");
    XFREE (MTYPE_ISIS_TMP, nexthop_list);
    return;
  }
  
  /* for each nexthop */
  i = 0;
  for (node = listhead (route_info->nexthops6); node; nextnode (node)) {
    nexthop6 = getdata (node);
    
    if (!IN6_IS_ADDR_LINKLOCAL (&nexthop6->ip6) &&
        !IN6_IS_ADDR_UNSPECIFIED (&nexthop6->ip6)) {
      api.nexthop_num--;
      api.ifindex_num--;
      continue;
    }
    
    nexthop_list[i] = &nexthop6->ip6;
    ifindex_list[i] = nexthop6->ifindex;
    i++;
  }
  
  api.nexthop = nexthop_list;
  api.ifindex = ifindex_list;
  
  if (api.nexthop_num && api.ifindex_num) {
    prefix6.family = AF_INET6;
    prefix6.prefixlen = prefix->prefixlen;
    memcpy (&prefix6.prefix, &prefix->u.prefix6, sizeof (struct in6_addr));
    zapi_ipv6_delete (zclient, &prefix6, &api);
    UNSET_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNC);
  }
  
  XFREE (MTYPE_ISIS_TMP, nexthop_list);
  XFREE (MTYPE_ISIS_TMP, ifindex_list);  
}


#endif /* HAVE_IPV6 */



void
isis_zebra_route_update (struct prefix *prefix,
                         struct isis_route_info *route_info)
{
  if (zclient->sock < 0)
    return;

  if (!zclient->redist[ZEBRA_ROUTE_ISIS])
    return;

  if (CHECK_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ACTIVE)) {
    if (prefix->family == AF_INET)
      isis_zebra_route_add_ipv4 (prefix, route_info);
#ifdef HAVE_IPV6
    else if (prefix->family == AF_INET6)
      isis_zebra_route_add_ipv6 (prefix, route_info);
#endif /* HAVE_IPV6 */
  } else { 
    if (prefix->family == AF_INET)
      isis_zebra_route_del_ipv4 (prefix, route_info);
#ifdef HAVE_IPV6
    else if (prefix->family == AF_INET6)
      isis_zebra_route_del_ipv6 (prefix, route_info);
#endif /* HAVE_IPV6 */
  }
  return;
}


int
isis_zebra_read_ipv4 (int command, struct zclient *zclient, 
		      zebra_size_t length)
{
  struct stream *stream;
  struct zapi_ipv4 api;
  struct prefix_ipv4 p;
  unsigned long ifindex;
  struct in_addr nexthop;

  stream = zclient->ibuf;
  memset (&p, 0, sizeof (struct prefix_ipv4));
  ifindex = 0;

  api.type    = stream_getc (stream);
  api.flags   = stream_getc (stream);
  api.message = stream_getc (stream);

  p.family = AF_INET;
  p.prefixlen = stream_getc (stream);
  stream_get (&p.prefix, stream, PSIZE (p.prefixlen));
  
  if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP)) {
      api.nexthop_num = stream_getc (stream);
      nexthop.s_addr = stream_get_ipv4 (stream);
  }
  if (CHECK_FLAG (api.message, ZAPI_MESSAGE_IFINDEX)) {
    api.ifindex_num = stream_getc (stream);
    ifindex = stream_getl (stream);
  }
  if (CHECK_FLAG (api.message, ZAPI_MESSAGE_DISTANCE))
    api.distance = stream_getc (stream);
  if (CHECK_FLAG (api.message, ZAPI_MESSAGE_METRIC))
    api.metric = stream_getl (stream);
  else
    api.metric = 0;
  
  if (command == ZEBRA_IPV4_ROUTE_ADD) {
    zlog_info ("IPv4 Route add from Z");
  }

  return 0;
}


int 
isis_zebra_read_ipv6 (int command, struct zclient *zclient, 
		      zebra_size_t length)
{

  return 0;
}

#define ISIS_TYPE_IS_REDISTRIBUTED(T) \
T == ZEBRA_ROUTE_MAX ? zclient->default_information : zclient->redist[type]

int
isis_distribute_list_update (int routetype)
{
  return 0;
}

int
isis_redistribute_default_set(int routetype, int metric_type, int metric_value)
{
  return 0;
}


void
isis_zebra_init ()
{
  
  zclient = zclient_new ();
  zclient_init (zclient, ZEBRA_ROUTE_ISIS);
  zclient->interface_add = isis_zebra_if_add;
  zclient->interface_delete = isis_zebra_if_del;
  zclient->interface_up = isis_zebra_if_state_up;
  zclient->interface_down = isis_zebra_if_state_down;
  zclient->interface_address_add = isis_zebra_if_address_add;
  zclient->interface_address_delete = isis_zebra_if_address_del;
  zclient->ipv4_route_add = isis_zebra_read_ipv4;
  zclient->ipv4_route_delete = isis_zebra_read_ipv4;
#ifdef HAVE_IPV6
  zclient->ipv6_route_add = isis_zebra_read_ipv6;
  zclient->ipv6_route_delete = isis_zebra_read_ipv6;
#endif /* HAVE_IPV6 */

  return;
}

void
isis_zebra_finish ()
{

  zclient_stop (zclient);
  zclient_free (zclient);
  zclient = (struct zclient *) NULL;

  return;
}







