OpenHIP 0.9svn1
|
00001 /* -*- Mode:cc-mode; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 00002 /* vim: set ai sw=2 ts=2 et cindent cino={1s: */ 00003 /* 00004 * Host Identity Protocol 00005 * Copyright (c) 2002-2012 the Boeing Company 00006 * 00007 * Permission is hereby granted, free of charge, to any person obtaining a copy 00008 * of this software and associated documentation files (the "Software"), to deal 00009 * in the Software without restriction, including without limitation the rights 00010 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00011 * copies of the Software, and to permit persons to whom the Software is 00012 * furnished to do so, subject to the following conditions: 00013 * 00014 * The above copyright notice and this permission notice shall be included in 00015 * all copies or substantial portions of the Software. 00016 * 00017 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00018 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00019 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00020 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00021 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00022 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00023 * THE SOFTWARE. 00024 * 00025 * \file hip_usermode.h 00026 * 00027 * \authors Jeff Ahrenholz <jeffrey.m.ahrenholz@boeing.com> 00028 * 00029 * \brief Definition of usermode thread functions. 00030 * 00031 */ 00032 00033 #ifndef _HIP_USERMODE_H_ 00034 #define _HIP_USERMODE_H_ 00035 00036 #ifdef __WIN32__ 00037 #include <winsock2.h> 00038 #include <ws2tcpip.h> 00039 #else 00040 #include <sys/socket.h> /* struct sockaddr */ 00041 #endif 00042 00043 /* 00044 * Globally-accessible functions 00045 */ 00046 /* Windows _beghinthread() uses different type than pthread_create() */ 00047 #ifdef __WIN32__ 00048 void hip_esp_output(void *arg); 00049 void hip_esp_input(void *arg); 00050 void tunreader(void *arg); 00051 void hip_dns(void *arg); 00052 void hipd_main(void *arg); 00053 void hip_netlink(void *arg); 00054 void hip_status(void *arg); 00055 void hip_mobile_router(void *arg); 00056 extern int socketpair(int, int, int, int sv[2]); 00057 #define RETNULL ; 00058 #else 00059 void *hip_esp_output(void *arg); 00060 void *hip_esp_input(void *arg); 00061 void *tunreader(void *arg); 00062 void *hip_dns(void *arg); 00063 void *hipd_main(void *arg); 00064 void *hip_netlink(void *arg); 00065 void *hip_status(void *arg); 00066 void *hip_mobile_router(void *arg); 00067 #define RETNULL NULL; 00068 #endif 00069 00070 int init_esp_input(int family, int type, int proto, int port, char *msg); 00071 int main_loop(int argc, char **argv); 00072 int str_to_addr(unsigned char *data, struct sockaddr *addr); 00073 00074 /* 00075 * Global definitions 00076 */ 00077 #ifndef CONFIG_HIP 00078 #define CONFIG_HIP 00079 #endif 00080 00081 #ifdef HIP_VPLS 00082 #define HIP_TAP_INTERFACE_MTU 1500 00083 #else 00084 #define HIP_TAP_INTERFACE_MTU 1400 00085 #endif 00086 00087 #define DNS_PORT 53 00088 #define HIP_DNS_SUFFIX ".hip" 00089 extern __u64 g_tap_mac; 00090 extern int g_state; 00091 00092 /* 00093 * Macros from hip.h and elsewhere 00094 */ 00095 #if 0 00096 /* get pointer to IP from a sockaddr 00097 * useful for inet_ntop calls */ 00098 #define SA2IP(x) (((struct sockaddr*)x)->sa_family == AF_INET) ? \ 00099 (void*)&((struct sockaddr_in*)x)->sin_addr : \ 00100 (void*)&((struct sockaddr_in6*)x)->sin6_addr 00101 /* get socket address length in bytes */ 00102 #define SALEN(x) (((struct sockaddr*)x)->sa_family == AF_INET) ? \ 00103 sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6) 00104 /* get IP address length in bytes */ 00105 #define SAIPLEN(x) (((struct sockaddr*)x)->sa_family == AF_INET) ? 4 : 16 00106 #endif 00107 #define IS_LSI32(a) ((a & htonl(0xFF000000)) == htonl(0x01000000)) 00108 00109 00110 /* from linux/include/linux/kernel.h */ 00111 #define NIPQUAD(addr) \ 00112 ((unsigned char *)&addr)[0], \ 00113 ((unsigned char *)&addr)[1], \ 00114 ((unsigned char *)&addr)[2], \ 00115 ((unsigned char *)&addr)[3] 00116 00117 #define NIP6(addr) \ 00118 ntohs((addr).s6_addr16[0]), \ 00119 ntohs((addr).s6_addr16[1]), \ 00120 ntohs((addr).s6_addr16[2]), \ 00121 ntohs((addr).s6_addr16[3]), \ 00122 ntohs((addr).s6_addr16[4]), \ 00123 ntohs((addr).s6_addr16[5]), \ 00124 ntohs((addr).s6_addr16[6]), \ 00125 ntohs((addr).s6_addr16[7]) 00126 00127 #define TRUE 1 00128 #define FALSE 0 00129 00130 /* 00131 * Local data types 00132 */ 00133 struct ip_esp_hdr { 00134 __u32 spi; 00135 __u32 seq_no; 00136 __u8 enc_data[0]; 00137 }; 00138 00139 struct ip_esp_padinfo { 00140 __u8 pad_length; 00141 __u8 next_hdr; 00142 }; 00143 00144 struct eth_hdr { 00145 __u8 dst[6]; 00146 __u8 src[6]; 00147 __u16 type; 00148 } __attribute__((packed)); 00149 00150 /* ARP header - RFC 826, STD 37 */ 00151 /* 00152 * Make our own ARP header struct, so we can add the 00153 * 'packed' attribute 00154 */ 00155 struct arp_hdr { 00156 __u16 ar_hrd; 00157 __u16 ar_pro; 00158 __u8 ar_hln; 00159 __u8 ar_pln; 00160 __u16 ar_op; 00161 } __attribute__((packed)); 00162 00163 /* 00164 * Make our own ARP data struct, so we can add the 00165 * 'packed' attribute 00166 */ 00167 00168 struct arp_req_data { 00169 __u8 src_mac[6]; 00170 __u32 src_ip; 00171 __u8 dst_mac[6]; 00172 __u32 dst_ip; 00173 } __attribute__((packed)); 00174 00175 #define ARPOP_REQUEST 1 00176 #define ARPOP_REPLY 2 00177 00178 #endif