fix Mac OS X compilation issues
clean up ESP output thread with duplicate add_outgoing_esp_header() and add_ipv4_header() functions git-svn-id: svn://svn.code.sf.net/p/openhip/code/hip/trunk@240 4c5cb64f-9889-4596-9799-84b02dc3effa
This commit is contained in:
parent
7b2783c98e
commit
e4036a2b07
|
@ -142,6 +142,7 @@ fi
|
|||
#
|
||||
# Mac OS X detection
|
||||
################################################################################
|
||||
AC_CANONICAL_HOST
|
||||
want_osx=false
|
||||
case "${host}" in
|
||||
*-apple-darwin*)
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
#ifndef _CHECKSUM_H
|
||||
#define _CHECKSUM_H
|
||||
|
||||
#ifndef __MACOSX__
|
||||
#ifndef __WIN32__
|
||||
#include <asm/types.h>
|
||||
#include <endian.h>
|
||||
|
@ -41,8 +42,12 @@
|
|||
#include <win32/types.h>
|
||||
#include <ws2tcpip.h>
|
||||
#endif /* __WIN32__ */
|
||||
#else /* __MACOSX__ */
|
||||
#include <mac/mac_types.h>
|
||||
#include <netinet/in.h>
|
||||
#endif /* __MACOSX__ */
|
||||
|
||||
#ifdef __WIN32__
|
||||
#if defined __WIN32__ || defined __MACOSX__
|
||||
/* Windows' ws2tcpip.h has struct in6_addr with __u8 and __u16 members,
|
||||
* but no __u32 as we need here for accumulation.
|
||||
*/
|
||||
|
@ -116,7 +121,7 @@ static __inline unsigned long csum_tcpudp_nofold(unsigned long saddr,
|
|||
* computes the checksum of the TCP/UDP pseudo-header
|
||||
* returns a 16-bit checksum, already complemented
|
||||
*/
|
||||
#ifdef __WIN32__
|
||||
#if defined __WIN32__ || defined __MACOSX__
|
||||
static __inline unsigned short int csum_tcpudp_magic(unsigned long saddr,
|
||||
unsigned long daddr,
|
||||
unsigned short len,
|
||||
|
@ -181,7 +186,7 @@ static __inline unsigned short csum_hip_revert(unsigned long saddr,
|
|||
/*
|
||||
* HIP checksum = tcp checksum + hitMagic - csum(saddr,daddr)
|
||||
*/
|
||||
#ifdef __WIN32__
|
||||
#if defined __WIN32__ || defined __MACOSX__
|
||||
static __inline unsigned short csum_tcpudp_hip_nofold6(struct in6_addr *saddr1,
|
||||
struct in6_addr *daddr1,
|
||||
unsigned short sum,
|
||||
|
@ -291,7 +296,7 @@ static inline unsigned short csum_tcpudp_hip_nofold6(struct in6_addr *saddr,
|
|||
|
||||
#endif
|
||||
|
||||
#ifdef __WIN32__
|
||||
#if defined __WIN32__ || defined __MACOSX__
|
||||
static __inline unsigned short csum_hip_revert6(struct in6_addr *saddr1,
|
||||
struct in6_addr *daddr1,
|
||||
unsigned short sum,
|
||||
|
|
|
@ -76,7 +76,6 @@
|
|||
/* Local functions */
|
||||
/* int read_netlink_response();*/
|
||||
|
||||
void readdress_association(int add, struct sockaddr *newaddr, int if_index);
|
||||
void association_add_address(hip_assoc *hip_a, struct sockaddr *newaddr,
|
||||
int if_index);
|
||||
void association_del_address(hip_assoc *hip_a, struct sockaddr *newaddr,
|
||||
|
|
|
@ -92,6 +92,10 @@ int s_esp, s_esp_udp, s_esp_udp_dg, s_esp6;
|
|||
|
||||
#ifdef __MACOSX__
|
||||
extern char *logaddr(struct sockaddr *addr);
|
||||
/* __MACOS__ uses raw IP output */
|
||||
#ifndef RAW_IP_OUT
|
||||
#define RAW_IP_OUT
|
||||
#endif
|
||||
#endif
|
||||
|
||||
__u32 g_tap_lsi;
|
||||
|
@ -161,10 +165,6 @@ extern __u32 get_preferred_lsi(struct sockaddr *lsi);
|
|||
extern int do_bcast();
|
||||
extern int maxof(int num_args, ...);
|
||||
|
||||
#ifdef __MACOSX__
|
||||
void add_outgoing_esp_header(__u8 *data, __u32 src, __u32 dst, __u16 len);
|
||||
#endif
|
||||
|
||||
void init_readsp()
|
||||
{
|
||||
if (readsp[0])
|
||||
|
@ -213,7 +213,9 @@ void *hip_esp_output(void *arg)
|
|||
static hip_sadb_entry *entry;
|
||||
struct sockaddr_storage ss_lsi;
|
||||
struct sockaddr *lsi = (struct sockaddr*)&ss_lsi;
|
||||
#ifndef RAW_IP_OUT
|
||||
sockaddr_list *l;
|
||||
#endif /* RAW_IP_OUT */
|
||||
#ifndef HIP_VPLS
|
||||
__u32 lsi_ip;
|
||||
#else
|
||||
|
@ -221,9 +223,6 @@ void *hip_esp_output(void *arg)
|
|||
time_t last_time, now_time;
|
||||
int packet_count = 0;
|
||||
#endif
|
||||
#ifdef __MACOSX__
|
||||
__u32 saddr, daddr;
|
||||
#endif
|
||||
#ifdef RAW_IP_OUT
|
||||
int s_raw = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);
|
||||
if (s_raw < 0)
|
||||
|
@ -381,7 +380,7 @@ void *hip_esp_output(void *arg)
|
|||
while (entry)
|
||||
{
|
||||
pthread_mutex_lock(&entry->rw_lock);
|
||||
#ifdef RAW_IP_OUT
|
||||
#if defined RAW_IP_OUT
|
||||
offset = sizeof(struct ip);
|
||||
#else
|
||||
offset = 0;
|
||||
|
@ -417,43 +416,19 @@ void *hip_esp_output(void *arg)
|
|||
* selection problems.
|
||||
*/
|
||||
add_ipv4_header(data,
|
||||
ntohl(LSI4(&entry->src_addrs->
|
||||
addr)),
|
||||
ntohl(LSI4(
|
||||
&entry->dst_addrs
|
||||
->
|
||||
addr)),
|
||||
(struct ip*)
|
||||
&raw_buff[sizeof(struct eth_hdr)
|
||||
],
|
||||
sizeof(struct ip) + len,
|
||||
IPPROTO_ESP);
|
||||
err = sendto(s_raw, data,
|
||||
sizeof(struct ip) + len, flags,
|
||||
ntohl(LSI4(&entry->src_addrs->addr)),
|
||||
ntohl(LSI4( &entry->dst_addrs->addr)),
|
||||
(struct ip*) &raw_buff[sizeof(struct eth_hdr)],
|
||||
sizeof(struct ip) + len, IPPROTO_ESP);
|
||||
#ifdef __MACOSX__
|
||||
err = sendto(s_esp, data, sizeof(struct ip) + len, flags, 0, 0);
|
||||
#else
|
||||
err = sendto(s_raw, data, sizeof(struct ip) + len, flags,
|
||||
SA(&entry->dst_addrs->addr),
|
||||
SALEN(&entry->dst_addrs->addr));
|
||||
#endif /* __MACOSX__ */
|
||||
|
||||
#else
|
||||
#ifdef __MACOSX__
|
||||
/*I need to build an IP header and write it to a different address!*/
|
||||
/* TODO: use offset above, and LSI4 macro
|
||||
* instead
|
||||
* of calls to inet_addr()
|
||||
*/
|
||||
memmove(&data[20],&data,len);
|
||||
saddr =
|
||||
inet_addr(logaddr(SA(&entry->src_addrs->addr)));
|
||||
daddr =
|
||||
inet_addr(logaddr(SA(&entry->dst_addrs->addr)));
|
||||
|
||||
add_outgoing_esp_header(data, saddr,daddr,len);
|
||||
|
||||
err = sendto(s_esp,data, len + sizeof(struct ip),
|
||||
flags, 0, 0);
|
||||
if (err < 0)
|
||||
{
|
||||
perror("sendto()");
|
||||
}
|
||||
#else /* __MACOSX__ */
|
||||
if (entry->mode == 3)
|
||||
{
|
||||
s = s_esp_udp;
|
||||
|
@ -470,7 +445,6 @@ void *hip_esp_output(void *arg)
|
|||
err = sendto(s, data, len, flags,
|
||||
SA(&entry->dst_addrs->addr),
|
||||
SALEN(&entry->dst_addrs->addr));
|
||||
#endif /* __MACOSX__ */
|
||||
#endif /* RAW_IP_OUT */
|
||||
if (err < 0)
|
||||
{
|
||||
|
@ -486,6 +460,7 @@ void *hip_esp_output(void *arg)
|
|||
&now,
|
||||
1);
|
||||
}
|
||||
#ifndef RAW_IP_OUT
|
||||
/* multihoming: duplicate packets to multiple
|
||||
* destination addresses */
|
||||
for (l = entry->dst_addrs->next; l;
|
||||
|
@ -502,6 +477,7 @@ void *hip_esp_output(void *arg)
|
|||
strerror(errno));
|
||||
}
|
||||
}
|
||||
#endif /* !RAW_IP_OUT */
|
||||
/* broadcasts are unicast to each association */
|
||||
if (!is_broadcast)
|
||||
{
|
||||
|
@ -509,10 +485,10 @@ void *hip_esp_output(void *arg)
|
|||
}
|
||||
entry = hip_sadb_get_next(entry);
|
||||
} /* end while */
|
||||
/*
|
||||
* IPv6
|
||||
*/
|
||||
}
|
||||
/*
|
||||
* IPv6
|
||||
*/
|
||||
else if ((raw_buff[12] == 0x86) && (raw_buff[13] == 0xdd))
|
||||
{
|
||||
ip6h = (struct ip6_hdr*) &raw_buff[14];
|
||||
|
@ -685,46 +661,19 @@ void *hip_esp_output(void *arg)
|
|||
* Use this to override OS source address
|
||||
* selection problems.
|
||||
*/
|
||||
add_ipv4_header(data,
|
||||
ntohl(LSI4(&entry->src_addrs->
|
||||
addr)),
|
||||
ntohl(LSI4(
|
||||
&entry->dst_addrs
|
||||
->
|
||||
addr)),
|
||||
(struct ip*)
|
||||
&raw_buff[sizeof(struct eth_hdr)
|
||||
],
|
||||
sizeof(struct ip) + len,
|
||||
IPPROTO_ESP);
|
||||
err = sendto(s_raw, data,
|
||||
sizeof(struct ip) + len, flags,
|
||||
add_ipv4_header(data, ntohl(LSI4(&entry->src_addrs->addr)),
|
||||
ntohl(LSI4(&entry->dst_addrs-> addr)),
|
||||
(struct ip*) &raw_buff[sizeof(struct eth_hdr)],
|
||||
sizeof(struct ip) + len, IPPROTO_ESP);
|
||||
#ifdef __MACOSX__
|
||||
err = sendto(s_esp, data, sizeof(struct ip) + len, flags, 0, 0);
|
||||
#else
|
||||
err = sendto(s_raw, data, sizeof(struct ip) + len, flags,
|
||||
SA(&entry->dst_addrs->addr),
|
||||
SALEN(&entry->dst_addrs->addr));
|
||||
#endif /* __MACOSX__ */
|
||||
|
||||
#else
|
||||
#ifdef __MACOSX__
|
||||
/*I need to build an IP header and write it to a different address!*/
|
||||
/* TODO: use offset above, and LSI4 macro
|
||||
* instead
|
||||
* of calls to inet_addr()
|
||||
*/
|
||||
memmove(&data[20],&data,len);
|
||||
saddr =
|
||||
inet_addr(logaddr(SA(&entry->src_addrs
|
||||
->addr)));
|
||||
daddr =
|
||||
inet_addr(logaddr(SA(&entry->dst_addrs
|
||||
->addr)));
|
||||
|
||||
add_outgoing_esp_header(data, saddr,daddr,len);
|
||||
|
||||
err = sendto(s_esp,data, len + sizeof(struct ip),
|
||||
flags, 0, 0);
|
||||
if (err < 0)
|
||||
{
|
||||
perror("sendto()");
|
||||
}
|
||||
#else /* __MACOSX__ */
|
||||
if (entry->mode == 3)
|
||||
{
|
||||
s = s_esp_udp;
|
||||
|
@ -741,7 +690,6 @@ void *hip_esp_output(void *arg)
|
|||
err = sendto(s, data, len, flags,
|
||||
SA(&entry->dst_addrs->addr),
|
||||
SALEN(&entry->dst_addrs->addr));
|
||||
#endif /* __MACOSX__ */
|
||||
#endif /* RAW_IP_OUT */
|
||||
if (err < 0)
|
||||
{
|
||||
|
@ -2208,11 +2156,7 @@ void add_ipv4_header(__u8 *data, __u32 src, __u32 dst, struct ip *old,
|
|||
iph->ip_dst.s_addr = htonl(dst);
|
||||
|
||||
/* add the header checksum */
|
||||
#if defined(__MACOSX__) && defined(__BIG_ENDIAN__)
|
||||
iph->ip_sum = ip_fast_csum((__u8*)iph, 20);
|
||||
#else
|
||||
iph->ip_sum = ip_fast_csum((__u8*)iph, iph->ip_hl);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -2283,31 +2227,6 @@ void add_ipv6_header(__u8 *data,
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef __MACOSX__
|
||||
|
||||
void add_outgoing_esp_header(__u8 *data, __u32 src, __u32 dst, __u16 len)
|
||||
{
|
||||
struct ip *iph = (struct ip*)data;
|
||||
|
||||
memset(iph, 0, sizeof(struct ip));
|
||||
iph->ip_v = 4;
|
||||
iph->ip_hl = 5;
|
||||
iph->ip_tos = 0;
|
||||
iph->ip_len = htons(len + sizeof(struct ip));
|
||||
iph->ip_id = 1337;
|
||||
iph->ip_off = htons(0x4000);
|
||||
iph->ip_ttl = 64;
|
||||
iph->ip_p = IPPROTO_ESP;
|
||||
iph->ip_sum = 0;
|
||||
iph->ip_src.s_addr = src;
|
||||
iph->ip_dst.s_addr = dst;
|
||||
|
||||
/* add the header checksum */
|
||||
iph->ip_sum = ip_fast_csum((__u8*)iph, iph->ip_hl);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* get_mac_addr()
|
||||
* Give a random 6-bit Ethernet address given an IPv4/IPv6 address.
|
||||
|
|
Loading…
Reference in New Issue