/*
 * Client side of OSPF API.
 * Copyright (C) 2001, 2002, 2003 Ralph Keller
 *
 * 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>

#include "version.h"
#include "getopt.h"
#include "thread.h"
#include "prefix.h"
#include "linklist.h"
#include "if.h"
#include "vector.h"
#include "vty.h"
#include "command.h"
#include "filter.h"
#include "stream.h"
#include "log.h"
#include "memory.h"

#include "ospfd/ospfd.h"
#include "ospfd/ospf_interface.h"
#include "ospfd/ospf_asbr.h"
#include "ospfd/ospf_lsa.h"
#include "ospfd/ospf_opaque.h"
#include "ospfd/ospf_lsdb.h"
#include "ospfd/ospf_neighbor.h"
#include "ospfd/ospf_dump.h"
#include "ospfd/ospf_zebra.h"
#include "ospfd/ospf_api.h"

#include "ospf_apiclient.h"

/* Backlog for listen */
#define BACKLOG 5

/* -----------------------------------------------------------
 * Forward declarations
 * -----------------------------------------------------------
 */

void ospf_apiclient_handle_reply (struct ospf_apiclient *oclient,
				  struct msg *msg);
void ospf_apiclient_handle_update_notify (struct ospf_apiclient *oclient,
					  struct msg *msg);
void ospf_apiclient_handle_delete_notify (struct ospf_apiclient *oclient,
					  struct msg *msg);

/* -----------------------------------------------------------
 * Initialization
 * -----------------------------------------------------------
 */

unsigned short
ospf_apiclient_getport (void)
{
  struct servent *sp = getservbyname ("ospfapi", "tcp");

  return sp ? ntohs (sp->s_port) : OSPF_API_SYNC_PORT;
}

/* -----------------------------------------------------------
 * Followings are functions for connection management
 * -----------------------------------------------------------
 */

struct ospf_apiclient *
ospf_apiclient_connect (char *host, int syncport)
{
  struct sockaddr_in myaddr_sync;
  struct sockaddr_in myaddr_async;
  struct sockaddr_in peeraddr;
  struct hostent *hp;
  struct ospf_apiclient *new;
  int size = 0;
  int peeraddrlen;
  int async_server_sock;
  int fd1, fd2;
  int ret;
  int on = 1;

  /* There are two connections between the client and the server.
     First the client opens a connection for synchronous requests/replies 
     to the server. The server will accept this connection and
     as a reaction open a reverse connection channel for 
     asynchronous messages. */

  async_server_sock = socket (AF_INET, SOCK_STREAM, 0);
  if (async_server_sock < 0)
    {
      fprintf (stderr,
	       "ospf_apiclient_connect: creating async socket failed\n");
      return NULL;
    }

  /* Prepare socket for asynchronous messages */
  /* Initialize async address structure */
  memset (&myaddr_async, 0, sizeof (struct sockaddr_in));
  myaddr_async.sin_family = AF_INET;
  myaddr_async.sin_addr.s_addr = htonl (INADDR_ANY);
  myaddr_async.sin_port = htons (syncport+1);
  size = sizeof (struct sockaddr_in);
#ifdef HAVE_SIN_LEN
  myaddr_async.sin_len = size;
#endif /* HAVE_SIN_LEN */

  /* This is a server socket, reuse addr and port */
  ret = setsockopt (async_server_sock, SOL_SOCKET,
		    SO_REUSEADDR, (void *) &on, sizeof (on));
  if (ret < 0)
    {
      fprintf (stderr, "ospf_apiclient_connect: SO_REUSEADDR failed\n");
      close (async_server_sock);
      return NULL;
    }

#ifdef SO_REUSEPORT
  ret = setsockopt (async_server_sock, SOL_SOCKET, SO_REUSEPORT,
		    (void *) &on, sizeof (on));
  if (ret < 0)
    {
      fprintf (stderr, "ospf_apiclient_connect: SO_REUSEPORT failed\n");
      close (async_server_sock);
      return NULL;
    }
#endif /* SO_REUSEPORT */

  /* Bind socket to address structure */
  ret = bind (async_server_sock, (struct sockaddr *) &myaddr_async, size);
  if (ret < 0)
    {
      fprintf (stderr, "ospf_apiclient_connect: bind async socket failed\n");
      close (async_server_sock);
      return NULL;
    }

  /* Wait for reverse channel connection establishment from server */
  ret = listen (async_server_sock, BACKLOG);
  if (ret < 0)
    {
      fprintf (stderr, "ospf_apiclient_connect: listen: %s\n", strerror (errno));
      close (async_server_sock);
      return NULL;
    }

  /* Make connection for synchronous requests and connect to server */
  /* Resolve address of server */
  hp = gethostbyname (host);
  if (!hp)
    {
      fprintf (stderr, "ospf_apiclient_connect: no such host %s\n", host);
      close (async_server_sock);
      return NULL;
    }

  fd1 = socket (AF_INET, SOCK_STREAM, 0);
  if (fd1 < 0)
    {
      fprintf (stderr,
	       "ospf_apiclient_connect: creating sync socket failed\n");
      return NULL;
    }


  /* Reuse addr and port */
  ret = setsockopt (fd1, SOL_SOCKET,
                    SO_REUSEADDR, (void *) &on, sizeof (on));
  if (ret < 0)
    {
      fprintf (stderr, "ospf_apiclient_connect: SO_REUSEADDR failed\n");
      close (fd1);
      return NULL;
    }

#ifdef SO_REUSEPORT
  ret = setsockopt (fd1, SOL_SOCKET, SO_REUSEPORT,
                    (void *) &on, sizeof (on));
  if (ret < 0)
    {
      fprintf (stderr, "ospf_apiclient_connect: SO_REUSEPORT failed\n");
      close (fd1);
      return NULL;
    }
#endif /* SO_REUSEPORT */


  /* Bind sync socket to address structure. This is needed since we
     want the sync port number on a fixed port number. The reverse
     async channel will be at this port+1 */

  memset (&myaddr_sync, 0, sizeof (struct sockaddr_in));
  myaddr_sync.sin_family = AF_INET;
  myaddr_sync.sin_port = htons (syncport);
#ifdef HAVE_SIN_LEN
  myaddr_sync.sin_len = sizeof (struct sockaddr_in);
#endif /* HAVE_SIN_LEN */

  ret = bind (fd1, (struct sockaddr *) &myaddr_sync, size);
  if (ret < 0)
    {
      fprintf (stderr, "ospf_apiclient_connect: bind sync socket failed\n");
      close (fd1);
      return NULL;
    }

  /* Prepare address structure for connect */
  memcpy (&myaddr_sync.sin_addr, hp->h_addr, hp->h_length);
  myaddr_sync.sin_family = AF_INET;
  myaddr_sync.sin_port = htons(ospf_apiclient_getport ());
#ifdef HAVE_SIN_LEN
  myaddr_sync.sin_len = sizeof (struct sockaddr_in);
#endif /* HAVE_SIN_LEN */

  /* Now establish synchronous channel with OSPF daemon */
  ret = connect (fd1, (struct sockaddr *) &myaddr_sync,
		 sizeof (struct sockaddr_in));
  if (ret < 0)
    {
      fprintf (stderr, "ospf_apiclient_connect: sync connect failed\n");
      close (async_server_sock);
      close (fd1);
      return NULL;
    }

  /* Accept reverse connection */
  peeraddrlen = sizeof (struct sockaddr_in);
  memset (&peeraddr, 0, peeraddrlen);

  fd2 =
    accept (async_server_sock, (struct sockaddr *) &peeraddr, &peeraddrlen);
  if (fd2 < 0)
    {
      fprintf (stderr, "ospf_apiclient_connect: accept async failed\n");
      close (async_server_sock);
      close (fd1);
      return NULL;
    }

  /* Server socket is not needed anymore since we are not accepting more 
     connections */
  close (async_server_sock);

  /* Create new client-side instance */
  new = XMALLOC (MTYPE_OSPF_APICLIENT, sizeof (struct ospf_apiclient));
  memset (new, 0, sizeof (struct ospf_apiclient));

  /* Initialize socket descriptors for sync and async channels */
  new->fd_sync = fd1;
  new->fd_async = fd2;

  return new;
}

int
ospf_apiclient_close (struct ospf_apiclient *oclient)
{

  if (oclient->fd_sync >= 0)
    {
      close (oclient->fd_sync);
    }

  if (oclient->fd_async >= 0)
    {
      close (oclient->fd_async);
    }

  /* Free client structure */
  XFREE (MTYPE_OSPF_APICLIENT, oclient);
  return 0;
}

/* -----------------------------------------------------------
 * Followings are functions to send a request to OSPFd
 * -----------------------------------------------------------
 */

/* Send synchronous request, wait for reply */
int
ospf_apiclient_send_request (struct ospf_apiclient *oclient, struct msg *msg)
{
  u_int32_t reqseq;
  struct msg_reply *msgreply;
  int rc;

  /* NB: Given "msg" is freed inside this function. */

  /* Remember the sequence number of the request */
  reqseq = ntohl (msg->hdr.msgseq);

  /* Write message to OSPFd */
  rc = msg_write (oclient->fd_sync, msg);
  msg_free (msg);

  if (rc < 0)
    {
      return -1;
    }

  /* Wait for reply *//* NB: New "msg" is allocated by "msg_read()". */
  msg = msg_read (oclient->fd_sync);
  if (!msg)
    return -1;

  assert (msg->hdr.msgtype == MSG_REPLY);
  assert (ntohl (msg->hdr.msgseq) == reqseq);

  msgreply = (struct msg_reply *) STREAM_DATA (msg->s);
  rc = msgreply->errcode;
  msg_free (msg);

  return rc;
}


/* -----------------------------------------------------------
 * Helper functions
 * -----------------------------------------------------------
 */

static u_int32_t
ospf_apiclient_get_seqnr (void)
{
  static u_int32_t seqnr = MIN_SEQ;
  u_int32_t tmp;

  tmp = seqnr;
  /* Increment sequence number */
  if (seqnr < MAX_SEQ)
    {
      seqnr++;
    }
  else
    {
      seqnr = MIN_SEQ;
    }
  return tmp;
}

/* -----------------------------------------------------------
 * API to access OSPF daemon by client applications.
 * -----------------------------------------------------------
 */

/*
 * Synchronous request to register opaque type.
 */
int
ospf_apiclient_register_opaque_type (struct ospf_apiclient *cl,
				     u_char ltype, u_char otype)
{
  struct msg *msg;
  int rc;

  /* just put 1 as a sequence number. */
  msg = new_msg_register_opaque_type (ospf_apiclient_get_seqnr (),
				      ltype, otype);
  if (!msg)
    {
      fprintf (stderr, "new_msg_register_opaque_type failed\n");
      return -1;
    }

  rc = ospf_apiclient_send_request (cl, msg);
  return rc;
}

/* 
 * Synchronous request to synchronize with OSPF's LSDB.
 * Two steps required: register_event in order to get
 * dynamic updates and LSDB_Sync.
 */
int
ospf_apiclient_sync_lsdb (struct ospf_apiclient *oclient)
{
  struct msg *msg;
  int rc;
  struct lsa_filter_type filter;

  filter.typemask = 0xFFFF;	/* all LSAs */
  filter.origin = ANY_ORIGIN;
  filter.num_areas = 0;		/* all Areas. */

  msg = new_msg_register_event (ospf_apiclient_get_seqnr (), &filter);
  if (!msg)
    {
      fprintf (stderr, "new_msg_register_event failed\n");
      return -1;
    }
  rc = ospf_apiclient_send_request (oclient, msg);

  if (rc != 0)
    goto out;

  msg = new_msg_sync_lsdb (ospf_apiclient_get_seqnr (), &filter);
  if (!msg)
    {
      fprintf (stderr, "new_msg_sync_lsdb failed\n");
      return -1;
    }
  rc = ospf_apiclient_send_request (oclient, msg);

out:
  return rc;
}

/* 
 * Synchronous request to originate or update an LSA.
 */

int
ospf_apiclient_lsa_originate (struct ospf_apiclient *oclient,
			      struct in_addr ifaddr,
			      struct in_addr area_id,
			      u_char lsa_type,
			      u_char opaque_type, u_int32_t opaque_id,
			      void *opaquedata, int opaquelen)
{
  struct msg *msg;
  int rc;
  u_char buf[OSPF_MAX_LSA_SIZE];
  struct lsa_header *lsah;
  u_int32_t tmp;


  /* We can only originate opaque LSAs */
  if (!IS_OPAQUE_LSA (lsa_type))
    {
      fprintf (stderr, "Cannot originate non-opaque LSA type %d\n", lsa_type);
      return OSPF_API_ILLEGALLSATYPE;
    }

  /* Make a new LSA from parameters */
  lsah = (struct lsa_header *) buf;
  lsah->ls_age = 0;
  lsah->options = 0;
  lsah->type = lsa_type;

  tmp = SET_OPAQUE_LSID (opaque_type, opaque_id);
  lsah->id.s_addr = htonl (tmp);
  lsah->adv_router.s_addr = 0;
  lsah->ls_seqnum = 0;
  lsah->checksum = 0;
  lsah->length = htons (sizeof (struct lsa_header) + opaquelen);

  memcpy (((u_char *) lsah) + sizeof (struct lsa_header), opaquedata,
	  opaquelen);

  msg = new_msg_originate_request (ospf_apiclient_get_seqnr (),
				   ifaddr, area_id, lsah);
  if (!msg)
    {
      fprintf (stderr, "new_msg_originate_request failed\n");
      return OSPF_API_NOMEMORY;
    }

  rc = ospf_apiclient_send_request (oclient, msg);
  return rc;
}

int
ospf_apiclient_lsa_delete (struct ospf_apiclient *oclient,
			   struct in_addr area_id, u_char lsa_type,
			   u_char opaque_type, u_int32_t opaque_id)
{
  struct msg *msg;
  int rc;

  /* Only opaque LSA can be deleted */
  if (!IS_OPAQUE_LSA (lsa_type))
    {
      fprintf (stderr, "Cannot delete non-opaque LSA type %d\n", lsa_type);
      return OSPF_API_ILLEGALLSATYPE;
    }

  /* opaque_id is in host byte order and will be converted
   * to network byte order by new_msg_delete_request */
  msg = new_msg_delete_request (ospf_apiclient_get_seqnr (),
				area_id, lsa_type, opaque_type, opaque_id);

  rc = ospf_apiclient_send_request (oclient, msg);
  return rc;
}

/* -----------------------------------------------------------
 * Followings are handlers for messages from OSPF daemon
 * -----------------------------------------------------------
 */

void
ospf_apiclient_handle_ready (struct ospf_apiclient *oclient, struct msg *msg)
{
  struct msg_ready_notify *r;
  r = (struct msg_ready_notify *) STREAM_DATA (msg->s);

  /* Invoke registered callback function. */
  if (oclient->ready_notify)
    {
      (oclient->ready_notify) (r->lsa_type, r->opaque_type, r->addr);
    }
}

void
ospf_apiclient_handle_new_if (struct ospf_apiclient *oclient, struct msg *msg)
{
  struct msg_new_if *n;
  n = (struct msg_new_if *) STREAM_DATA (msg->s);

  /* Invoke registered callback function. */
  if (oclient->new_if)
    {
      (oclient->new_if) (n->ifaddr, n->area_id);
    }
}

void
ospf_apiclient_handle_del_if (struct ospf_apiclient *oclient, struct msg *msg)
{
  struct msg_del_if *d;
  d = (struct msg_del_if *) STREAM_DATA (msg->s);

  /* Invoke registered callback function. */
  if (oclient->del_if)
    {
      (oclient->del_if) (d->ifaddr);
    }
}

void
ospf_apiclient_handle_ism_change (struct ospf_apiclient *oclient,
				  struct msg *msg)
{
  struct msg_ism_change *m;
  m = (struct msg_ism_change *) STREAM_DATA (msg->s);

  /* Invoke registered callback function. */
  if (oclient->ism_change)
    {
      (oclient->ism_change) (m->ifaddr, m->area_id, m->status);
    }

}

void
ospf_apiclient_handle_nsm_change (struct ospf_apiclient *oclient,
				  struct msg *msg)
{
  struct msg_nsm_change *m;
  m = (struct msg_nsm_change *) STREAM_DATA (msg->s);

  /* Invoke registered callback function. */
  if (oclient->nsm_change)
    {
      (oclient->nsm_change) (m->ifaddr, m->nbraddr, m->router_id, m->status);
    }
}

void
ospf_apiclient_handle_lsa_update (struct ospf_apiclient *oclient,
				  struct msg *msg)
{
  struct msg_lsa_change_notify *cn;
  struct lsa_header *lsa;
  int lsalen;

  cn = (struct msg_lsa_change_notify *) STREAM_DATA (msg->s);

  /* Extract LSA from message */
  lsalen = ntohs (cn->data.length);
  lsa = XMALLOC (MTYPE_OSPF_APICLIENT, lsalen);
  if (!lsa)
    {
      fprintf (stderr, "LSA update: Cannot allocate memory for LSA\n");
      return;
    }
  memcpy (lsa, &(cn->data), lsalen);

  /* Invoke registered update callback function */
  if (oclient->update_notify)
    {
      (oclient->update_notify) (cn->ifaddr, cn->area_id, 
				cn->is_self_originated, lsa);
    }

  /* free memory allocated by ospf apiclient library */
  XFREE (MTYPE_OSPF_APICLIENT, lsa);
}

void
ospf_apiclient_handle_lsa_delete (struct ospf_apiclient *oclient,
				  struct msg *msg)
{
  struct msg_lsa_change_notify *cn;
  struct lsa_header *lsa;
  int lsalen;

  cn = (struct msg_lsa_change_notify *) STREAM_DATA (msg->s);

  /* Extract LSA from message */
  lsalen = ntohs (cn->data.length);
  lsa = XMALLOC (MTYPE_OSPF_APICLIENT, lsalen);
  if (!lsa)
    {
      fprintf (stderr, "LSA delete: Cannot allocate memory for LSA\n");
      return;
    }
  memcpy (lsa, &(cn->data), lsalen);

  /* Invoke registered update callback function */
  if (oclient->delete_notify)
    {
      (oclient->delete_notify) (cn->ifaddr, cn->area_id, 
				cn->is_self_originated, lsa);
    }

  /* free memory allocated by ospf apiclient library */
  XFREE (MTYPE_OSPF_APICLIENT, lsa);
}

void
ospf_apiclient_msghandle (struct ospf_apiclient *oclient, struct msg *msg)
{
  /* Call message handler function. */
  switch (msg->hdr.msgtype)
    {
    case MSG_READY_NOTIFY:
      ospf_apiclient_handle_ready (oclient, msg);
      break;
    case MSG_NEW_IF:
      ospf_apiclient_handle_new_if (oclient, msg);
      break;
    case MSG_DEL_IF:
      ospf_apiclient_handle_del_if (oclient, msg);
      break;
    case MSG_ISM_CHANGE:
      ospf_apiclient_handle_ism_change (oclient, msg);
      break;
    case MSG_NSM_CHANGE:
      ospf_apiclient_handle_nsm_change (oclient, msg);
      break;
    case MSG_LSA_UPDATE_NOTIFY:
      ospf_apiclient_handle_lsa_update (oclient, msg);
      break;
    case MSG_LSA_DELETE_NOTIFY:
      ospf_apiclient_handle_lsa_delete (oclient, msg);
      break;
    default:
      fprintf (stderr, "ospf_apiclient_read: Unknown message type: %d\n",
	       msg->hdr.msgtype);
      break;
    }
}

/* -----------------------------------------------------------
 * Callback handler registration
 * -----------------------------------------------------------
 */

void
ospf_apiclient_register_callback (struct ospf_apiclient *oclient,
				  void (*ready_notify) (u_char lsa_type,
							u_char opaque_type,
							struct in_addr addr),
				  void (*new_if) (struct in_addr ifaddr,
						  struct in_addr area_id),
				  void (*del_if) (struct in_addr ifaddr),
				  void (*ism_change) (struct in_addr ifaddr,
						      struct in_addr area_id,
						      u_char status),
				  void (*nsm_change) (struct in_addr ifaddr,
						      struct in_addr nbraddr,
						      struct in_addr
						      router_id,
						      u_char status),
				  void (*update_notify) (struct in_addr
							 ifaddr,
							 struct in_addr
							 area_id,
							 u_char self_origin,
							 struct lsa_header *
							 lsa),
				  void (*delete_notify) (struct in_addr
							 ifaddr,
							 struct in_addr
							 area_id,
							 u_char self_origin,
							 struct lsa_header *
							 lsa))
{
  assert (oclient);
  assert (update_notify);

  /* Register callback function */
  oclient->ready_notify = ready_notify;
  oclient->new_if = new_if;
  oclient->del_if = del_if;
  oclient->ism_change = ism_change;
  oclient->nsm_change = nsm_change;
  oclient->update_notify = update_notify;
  oclient->delete_notify = delete_notify;
}

/* -----------------------------------------------------------
 * Asynchronous message handling
 * -----------------------------------------------------------
 */

int
ospf_apiclient_handle_async (struct ospf_apiclient *oclient)
{
  struct msg *msg;

  /* Get a message */
  msg = msg_read (oclient->fd_async);

  if (!msg)
    {
      /* Connection broke down */
      return -1;
    }

  /* Handle message */
  ospf_apiclient_msghandle (oclient, msg);

  /* Don't forget to free this message */
  msg_free (msg);

  return 0;
}
