From patchwork Fri Feb 6 18:00:25 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sven Eckelmann X-Patchwork-Id: 5354 Received: from mail.gmx.net (mail.gmx.net [213.165.64.20]) by open-mesh.net (8.14.3/8.13.4/Debian-3sarge3) with SMTP id n16I1mbo004874 for ; Fri, 6 Feb 2009 18:01:49 GMT Received: (qmail invoked by alias); 06 Feb 2009 18:00:29 -0000 Received: from unknown (EHLO localhost) [88.130.173.182] by mail.gmx.net (mp070) with SMTP; 06 Feb 2009 19:00:29 +0100 X-Authenticated: #15668376 X-Provags-ID: V01U2FsdGVkX1/Cq0cWgLvCP2L0cBeZgYiGArFWJ/rVpfUn+lksFO mzAogWOA6U7KWm From: Sven Eckelmann To: b.a.t.m.a.n@open-mesh.net Date: Fri, 6 Feb 2009 19:00:25 +0100 Message-Id: <1233943226-24592-1-git-send-email-sven.eckelmann@gmx.de> X-Mailer: git-send-email 1.6.0.6 In-Reply-To: <200901140236.58441.sven.eckelmann@gmx.de> References: <200901140236.58441.sven.eckelmann@gmx.de> X-Y-GMX-Trusted: 0 X-FuHaFi: 0.49 Subject: [B.A.T.M.A.N.] [PATCH] Introduce get_tunneled_(protocol|udpdest) for better portability X-BeenThere: b.a.t.m.a.n@open-mesh.net X-Mailman-Version: 2.1.11 Precedence: list Reply-To: The list for a Better Approach To Mobile Ad-hoc Networking List-Id: The list for a Better Approach To Mobile Ad-hoc Networking List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 06 Feb 2009 18:01:49 -0000 FreeBSD has different definition of udp and ip headers then systems with glibc. To support both a two new static functions were introduced. * get_tunneled_protocol - get protocol of inside the tunneled ip packet * get_tunneled_udpdest - get udp port of tunneled udp/ip packet New systems can easily introduced in that way without changing the real code. Signed-off-by: Sven Eckelmann --- batman/posix/tunnel.c | 31 +++++++++++++++++++++++++++---- 1 files changed, 27 insertions(+), 4 deletions(-) diff --git a/batman/posix/tunnel.c b/batman/posix/tunnel.c index a576bb9..44a4ff0 100644 --- a/batman/posix/tunnel.c +++ b/batman/posix/tunnel.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -70,6 +71,28 @@ void init_bh_ports(void) +static uint8_t get_tunneled_protocol(const unsigned char *buff) +{ +#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__Darwin__) + return ((struct ip *)(buff + 1))->ip_p; +#else + return ((struct iphdr *)(buff + 1))->protocol; +#endif +} + + + +static uint16_t get_tunneled_udpdest(const unsigned char *buff) +{ +#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__Darwin__) + return ((struct udphdr *)(buff + 1 + ((struct ip *)(buff + 1))->ip_hl*4))->uh_dport; +#else + return ((struct udphdr *)(buff + 1 + ((struct iphdr *)(buff + 1))->ihl*4))->dest; +#endif +} + + + static int8_t get_tun_ip(struct sockaddr_in *gw_addr, int32_t udp_sock, uint32_t *tun_addr) { struct sockaddr_in sender_addr; @@ -257,7 +280,7 @@ void *client_to_gw_tun(void *arg) if (write(tun_fd, buff + 1, buff_len - 1) < 0) debug_output(0, "Error - can't write packet: %s\n", strerror(errno)); - if (((struct iphdr *)(buff + 1))->protocol != IPPROTO_ICMP) { + if (get_tunneled_protocol(buff) != IPPROTO_ICMP) { gw_state = GW_STATE_VERIFIED; gw_state_time = current_time; } @@ -305,11 +328,11 @@ void *client_to_gw_tun(void *arg) ignore_packet = 0; - if (((struct iphdr *)(buff + 1))->protocol == IPPROTO_UDP) { + if (get_tunneled_protocol(buff) == IPPROTO_UDP) { for (i = 0; i < (int)(sizeof(bh_udp_ports)/sizeof(short)); i++) { - if (((struct udphdr *)(buff + 1 + ((struct iphdr *)(buff + 1))->ihl*4))->dest == bh_udp_ports[i]) { + if (get_tunneled_udpdest(buff) == bh_udp_ports[i]) { ignore_packet = 1; break; @@ -318,7 +341,7 @@ void *client_to_gw_tun(void *arg) } - } else if (((struct iphdr *)(buff + 1))->protocol == IPPROTO_ICMP) { + } else if (get_tunneled_protocol(buff) == IPPROTO_ICMP) { ignore_packet = 1;