214 lines
5.5 KiB
C
214 lines
5.5 KiB
C
/* wrnad.h - Wind River network acceleration daemon (NAD) */
|
|
|
|
/*
|
|
* Copyright (c) 2010 Wind River Systems, Inc.
|
|
*
|
|
* The right to copy, distribute or otherwise make use of this software
|
|
* may be licensed only pursuant to the terms of an applicable Wind River
|
|
* license agreement.
|
|
*/
|
|
|
|
/* includes */
|
|
|
|
/*
|
|
* Warning: some of these headers have various different contents
|
|
* under VxWorks and Linux. Presently the include path under VxWorks
|
|
* is such that the headers used are those under ipxinc/include/,
|
|
* which should be more consistent with the Linux headers.
|
|
* Needs attention.
|
|
*/
|
|
#include <sys/socket.h>
|
|
#include <sys/syslog.h>
|
|
#include <netinet/in.h>
|
|
#include <arpa/inet.h>
|
|
|
|
/* Note, for IPWRNAD builds, these headers are under ipxinc/include/. */
|
|
#include <linux/if.h>
|
|
#include <linux/if_arp.h>
|
|
#include <linux/netlink.h>
|
|
#include <linux/rtnetlink.h>
|
|
|
|
#ifndef IPWRNAD
|
|
#include <linux/ipsec.h>
|
|
#else
|
|
#ifdef IPIPSEC2
|
|
#define IPIPSEC_HAVE_UINT_TYPE
|
|
#define IPIPSEC_HAVE_UINT64_TYPE
|
|
#include <ipipsec_pfkeyv2.h>
|
|
#endif
|
|
#endif
|
|
|
|
/* defines */
|
|
|
|
#define WRNAD_MAX_IF 32
|
|
|
|
#define WRNAD_PROXY_IFNAME "proxy"
|
|
|
|
#define WRNAD_MIPC_NAE_BUS 0
|
|
#define WRNAD_MIPC_NAE_NODE 1
|
|
#define WRNAD_MIPC_NAE_PORT 3
|
|
|
|
#define WRNAD_RECVBUF_SIZE 8192
|
|
|
|
#define WRNAD_PROC_FILE "/proc/mipc_pow"
|
|
|
|
/* Define these for NAP 1.1 */
|
|
#undef WRNAD_IDENTIFY_ROUTERS
|
|
#undef WRNAD_SELF_GATEWAY_SKIP
|
|
|
|
/* typedefs */
|
|
|
|
typedef int (*wrnad_rtnl_handler) (struct nlmsghdr *);
|
|
#if !defined(IPWRNAD) || defined(IPIPSEC2)
|
|
typedef int (*wrnad_pfkey_handler) (struct sadb_msg *);
|
|
#endif /* !IPWRNAD || IPIPSEC2 */
|
|
|
|
#ifdef WRNAD_IDENTIFY_ROUTERS
|
|
|
|
typedef struct hash_list_struct hash_list_t;
|
|
|
|
struct hash_list_struct
|
|
{
|
|
hash_list_t *next; /* head, when used in table array */
|
|
hash_list_t *prev; /* tail, when used in table array */
|
|
};
|
|
|
|
typedef struct hash_item_pool
|
|
{
|
|
hash_list_t *items;
|
|
hash_list_t *blocks;
|
|
size_t item_size;
|
|
} hash_item_pool_t;
|
|
|
|
typedef struct ipv4_item_struct
|
|
{
|
|
hash_list_t list;
|
|
uint32_t addr; /* kept in network byte order */
|
|
} ip4_item_t;
|
|
|
|
typedef struct ipv6_item_struct
|
|
{
|
|
hash_list_t list;
|
|
uint32_t addr[4]; /* kept in network byte order */
|
|
} ip6_item_t;
|
|
|
|
static __inline__ void
|
|
hl_insert_between(hash_list_t *prev, hash_list_t *next, hash_list_t *item)
|
|
{
|
|
item->prev = prev;
|
|
item->next = next;
|
|
prev->next = item;
|
|
next->prev = item;
|
|
}
|
|
|
|
static __inline__ void
|
|
hl_insert_after(hash_list_t *old_item, hash_list_t *new_item)
|
|
{
|
|
hl_insert_between(old_item, old_item->next, new_item);
|
|
}
|
|
|
|
static __inline__ void
|
|
hl_insert_before(hash_list_t *old_item, hash_list_t *new_item)
|
|
{
|
|
hl_insert_between(old_item->prev, old_item, new_item);
|
|
}
|
|
|
|
static __inline__ void
|
|
hl_delete_item(hash_list_t *item)
|
|
{
|
|
hash_list_t *prev = item->prev;
|
|
hash_list_t *next = item->next;
|
|
next->prev = prev;
|
|
prev->next = next;
|
|
}
|
|
|
|
static __inline__ void
|
|
hl_init_list(hash_list_t *list)
|
|
{
|
|
list->prev = list;
|
|
list->next = list;
|
|
}
|
|
|
|
|
|
typedef unsigned int (*hash_func) (uint32_t *data);
|
|
|
|
typedef struct hash_table_struct
|
|
{
|
|
hash_list_t *table;
|
|
unsigned int mask; /* number of slots in table minus 1 */
|
|
hash_func hasher;
|
|
unsigned int n_slots; /* number of slots in the table; a power of two */
|
|
hash_item_pool_t *item_pool;
|
|
} hash_table_t;
|
|
|
|
#endif /* WRNAD_IDENTIFY_ROUTERS */
|
|
|
|
typedef struct
|
|
{
|
|
int ifindex;
|
|
char ifname[IFNAMSIZ];
|
|
#ifdef WRNAD_IDENTIFY_ROUTERS
|
|
hash_table_t v4_routers;
|
|
hash_table_t v6_routers;
|
|
#endif
|
|
}
|
|
Wrnad_proxy_interface;
|
|
|
|
/* globals */
|
|
extern Wrnad_proxy_interface wrnad_proxy_ifs[];
|
|
|
|
int wrnad_rtnl_monitor(int bus, int node, int port);
|
|
Wrnad_proxy_interface *wrnad_rtnl_check_proxy_interface(int ifindex);
|
|
int wrnad_rtnl_add_proxy_interface(int ifindex, char *ifname);
|
|
int wrnad_rtnl_del_proxy_interface(int ifindex, char *ifname);
|
|
const char *wrnad_rtnl_familystr(int family);
|
|
const char *wrnad_rtnl_typestr(int type);
|
|
void wrnad_rtnl_eth_ntop(unsigned char *mac, char *buf);
|
|
void wrnad_log(int priority, const char *format, /* args*/ ...);
|
|
int wrnad_rtnl_neigh_handler(struct nlmsghdr *nlh);
|
|
int wrnad_rtnl_link_handler(struct nlmsghdr *nlh);
|
|
int wrnad_rtnl_addr_handler(struct nlmsghdr *nlh);
|
|
int wrnad_rtnl_route_handler(struct nlmsghdr *nlh);
|
|
int wrnad_mipc_open(int bus, int node, int port);
|
|
void wrnad_mipc_close(int fd);
|
|
int wrnad_mipc_send_netlink(int fd, struct nlmsghdr *nlh);
|
|
void wrnad_terminate(int code);
|
|
void wrnad_cleanup(void);
|
|
int wrnad_pfkey_open(void);
|
|
void wrnad_pfkey_close(int fd);
|
|
int wrnad_pfkey_recv(int pfkeyfd, int mipcfd);
|
|
const char *wrnad_pfkey_typestr(int type);
|
|
#if !defined(IPWRNAD) || defined(IPIPSEC2)
|
|
int wrnad_mipc_send_pfkey(int fd, struct sadb_msg *msg);
|
|
#endif /* !IPWRNAD || IPIPSEC2 */
|
|
|
|
#ifndef IPWRNAD
|
|
int wrnad_neigh_ndp_open(void);
|
|
void wrnad_neigh_ndp_read(int fd, int nlfd, char *recvbuf, int size);
|
|
#endif
|
|
|
|
#ifdef IPWRNAD
|
|
static __inline__ unsigned char
|
|
wrnad_af_xlat(unsigned int af)
|
|
{
|
|
return (unsigned char)af;
|
|
}
|
|
#else
|
|
unsigned char wrnad_af_xlat(unsigned int af);
|
|
#endif
|
|
|
|
#ifdef WRNAD_IDENTIFY_ROUTERS
|
|
int hash_v4_init(hash_table_t *table);
|
|
int hash_v6_init(hash_table_t *table);
|
|
ip4_item_t * hash_lookup_ip4addr(hash_table_t *table,
|
|
uint32_t *paddr, unsigned int *pix);
|
|
ip6_item_t * hash_lookup_ip6addr(hash_table_t *table,
|
|
uint32_t *paddr, unsigned int *pix);
|
|
|
|
void hash_insert_ip4addr(hash_table_t *table, uint32_t *paddr);
|
|
void hash_insert_ip6addr(hash_table_t *table, uint32_t *paddr);
|
|
void hash_table_destroy(hash_table_t *table);
|
|
void hash_item_pools_destroy(void);
|
|
#endif /* WRNAD_IDENTIFY_ROUTERS */
|
|
|