/******************************************************/
/* Copyright (C) 2008 Arch Rock Corporation           */
/* License Agreement: refer to LICENSE.txt            */
/*                                                    */
/******************************************************/

#ifndef _ROUTE_H
#define _ROUTE_H    1

#include <sys/socket.h>

/*! Commands for routecntl().
 */
enum RouteCmdsEnum{
  ADDROUTE=30,
  DELETEROUTE,
  READROUTE,
};

typedef struct rtentry
{
  /*! For this destination. */
  in6_addr_t dst;
  /*! Next hop address for the above destination. 
   *  This has to be a IPv6 link local address.
  */
  in6_addr_t nxthop;
  uint8_t hops;
  uint16_t cost;
}rtentry_t;

/*! A system call to get and configure the 
 *  routing table. If successful, the routes in the route table can 
 *  be extracted or changed.
 *
 *  @param[in] cmd See commands #RouteCmdsEnum
 *             \li \em ADDROUTE to add a static route entry
 *             \li \em DELETEROUTE to delete a static route entry
 *             \li \em READROUTE read the route entry, indexed by \em rtindex,
 *                          into \em rtentry
 *  @param[in] rtindex index to the route table
 *  @param[in,out] rtentry contains the entry of the routing table to be
 *                         set to or extracted from the table
 *  \return 0 if succeed and -1 if fail and errno is set appropriately.
 *  
 *  \par Errors:
 *    EINVAL if invalid parameters are passed
 *  \par
 *    ESIZE  if index is larger than table size
 */
int16_t routecntl(uint16_t cmd, int16_t rtindex, rtentry_t *rtentry);

/*! \brief A system call to get the number of valid route entries
 *  in the routing table.
 *  
 *  \pre Do not call this inside the interrupt handler context.
 *  \post If successful, return the number of routes.
 *
 *  \return number of valid route entries in the routing table
 */
int16_t num_rtentries();

#endif
