/home/tomh/openhip/hip-0.5/src/include/hip/hip_sadb.h

Go to the documentation of this file.
00001 /*
00002  * Host Identity Protocol
00003  * Copyright (C) 2002-04 the Boeing Company
00004  * 
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  *  hip_sadb.h
00016  *
00017  *  Authors: Jeff Ahrenholz <jeffrey.m.ahrenholz@boeing.com>
00018  * 
00019  * the HIP Security Association database
00020  *
00021  */
00022 #ifdef __MACOSX__
00023 #include <sys/types.h>
00024 #include <mac/mac_types.h>
00025 #else
00026 #ifdef __WIN32__
00027 #include <win32/types.h>
00028 #else
00029 #include <asm/types.h>          /* __u16, __u32, etc */
00030 #endif /* __WIN32__ */
00031 #endif
00032 #include <sys/types.h>          /* for socket.h */
00033 #ifdef __WIN32__
00034 #include <winsock2.h>
00035 #include <ws2tcpip.h>
00036 #else
00037 #include <sys/socket.h>         /* struct sockaddr */
00038 #include <netinet/in.h>         /* struct sockaddr_in */
00039 #endif /* __WIN32__ */
00040 #include <openssl/des.h>        /* des_key_schedule */
00041 #include <openssl/aes.h>        /* aes_key */
00042 #include <openssl/blowfish.h>   /* bf_key */
00043 
00044 /*
00045  * definitions
00046  */
00047 #define SADB_SIZE 512 
00048 #define LSI4(a) (((struct sockaddr_in*)a)->sin_addr.s_addr)
00049 
00050 /* HIP Security Association entry */
00051 typedef struct _hip_sadb_entry 
00052 {
00053         struct _hip_sadb_entry *next;
00054         __u32 spi;                      /* primary index into SADB */
00055         int direction;                  /* in/out */
00056         __u16 hit_magic;                /* for quick checksum calculation */
00057         sockaddr_list *src_addrs;       /* source addresses             */
00058         sockaddr_list *dst_addrs;       /* destination addresses        */
00059         /* inner addresses for BEET SAs (the above addresses
00060          * are used as outer addresses) */
00061         sockaddr_list *inner_src_addrs;
00062         sockaddr_list *inner_dst_addrs;
00063         __u32 mode;     /* ESP mode :  0-default 1-transport 2-tunnel 3-beet */
00064         __u16 dst_port;                 /* UDP dest. port for encaps. ESP */
00065         struct timeval usetime_ka;  /* last used timestamp, incl keep-alives */
00066         struct sockaddr_storage lsi;    /* LSI                          */
00067         struct sockaddr_storage lsi6;   /* IPv6 LSI (peer HIT)          */
00068         __u32 a_type;                   /* crypto parameters            */
00069         __u32 e_type;
00070         __u32 a_keylen;
00071         __u32 e_keylen;
00072         __u8 *a_key;                    /* raw crypto keys */
00073         __u8 *e_key;
00074         __u64 lifetime;                 /* seconds until expiration */
00075         __u64 bytes;                    /* bytes transmitted */
00076         struct timeval usetime;         /* last used timestamp */
00077         __u32 sequence;                 /* sequence number counter */
00078         __u32 replay_win;               /* anti-replay window */
00079         __u32 replay_map;               /* anti-replay bitmap */
00080         char iv[8];
00081         des_key_schedule ks[3];         /* 3-DES keys */
00082         AES_KEY *aes_key;               /* AES key */
00083         BF_KEY *bf_key;                 /* BLOWFISH key */
00084 #ifdef __WIN32__
00085         HANDLE rw_lock;
00086 #else
00087         pthread_mutex_t rw_lock;
00088 #endif
00089 } hip_sadb_entry;
00090 
00091 /* HIP SADB desintation cache entry */
00092 typedef struct _hip_sadb_dst_entry
00093 {
00094         struct _hip_sadb_dst_entry *next;
00095         struct sockaddr_storage addr;
00096         hip_sadb_entry *sadb_entry;
00097         
00098 } hip_sadb_dst_entry;
00099 
00100 /* HIP LSI table entry */
00101 #define LSI_PKT_BUFFER_SIZE 2000
00102 #define LSI_ENTRY_LIFETIME 120
00103 typedef struct _hip_lsi_entry
00104 {
00105         struct _hip_lsi_entry *next;
00106         struct sockaddr_storage addr;
00107         struct sockaddr_storage lsi4;
00108         struct sockaddr_storage lsi6;
00109         __u8 packet_buffer[LSI_PKT_BUFFER_SIZE];
00110         int num_packets;
00111         int next_packet;
00112         int send_packets;
00113         struct timeval creation_time;
00114 } hip_lsi_entry;
00115 /* protocol selector entry */
00116 #define PROTO_SEL_SIZE 512
00117 #define PROTO_SEL_ENTRY_LIFETIME 900
00118 #define PROTO_SEL_DEFAULT_FAMILY AF_INET
00119 #define hip_proto_sel_hash(a) (a % PROTO_SEL_SIZE)
00120 typedef struct _hip_proto_sel_entry
00121 {
00122         struct _hip_proto_sel_entry *next;
00123         __u32 selector;         /* upper layer protocol-specific selector */
00124         int family;             /* guidance on which address family to use */
00125         struct timeval last_used;
00126 } hip_proto_sel_entry;
00127 
00128 
00129 /*
00130  * functions
00131  */
00132 void hip_sadb_init();
00133 int hip_sadb_add(__u32 type, __u32 mode, struct sockaddr *inner_src,
00134     struct sockaddr *inner_dst, struct sockaddr *src, struct sockaddr *dst, __u16 port,
00135     __u32 spi, __u8 *e_key, __u32 e_type, __u32 e_keylen, __u8 *a_key,
00136     __u32 a_type, __u32 a_keylen, __u32 lifetime, __u16 hitmagic);
00137 int hip_sadb_delete(__u32 type, struct sockaddr *src, struct sockaddr *dst,
00138     __u32 spi);
00139 void hip_remove_expired_lsi_entries();
00140 void hip_add_lsi(struct sockaddr *addr, struct sockaddr *lsi4, 
00141         struct sockaddr *lsi6);
00142 int buffer_packet(struct sockaddr *lsi, __u8 *data, int len);
00143 void unbuffer_packets(hip_lsi_entry *entry);
00144 hip_lsi_entry *hip_lookup_lsi(struct sockaddr *lsi);
00145 hip_sadb_entry *hip_sadb_lookup_spi(__u32 spi);
00146 hip_sadb_entry *hip_sadb_lookup_addr(struct sockaddr *addr);
00147 hip_sadb_entry *hip_sadb_get_next(hip_sadb_entry *placemark);
00148 
00149 int hip_select_family_by_proto(__u32 lsi, __u8 proto, __u8 *header,
00150         struct timeval *now);
00151 int hip_add_proto_sel_entry(__u32 lsi, __u8 proto, __u8 *header, int family,
00152         int dir, struct timeval *now);
00153 void hip_remove_expired_sel_entries();
00154 

Generated on Mon Oct 22 11:43:43 2007 for OpenHIP by  doxygen 1.5.1