am af61fbf3: (-s ours) Merge "Revert "DO NOT MERGE: Remove two almost-unused include files."" into klp-dev
* commit 'af61fbf387c183caec7da2c59f474f515f7bb6af':
Revert "DO NOT MERGE: Remove two almost-unused include files."
diff --git a/Android.mk b/Android.mk
index b0d19d9..240b25b 100644
--- a/Android.mk
+++ b/Android.mk
@@ -3,6 +3,7 @@
LOCAL_SRC_FILES:=clatd.c dump.c checksum.c translate.c icmp.c ipv4.c ipv6.c config.c dns64.c logging.c getaddr.c getroute.c netlink_callbacks.c netlink_msg.c setif.c setroute.c mtu.c
+LOCAL_CFLAGS := -Wall -Werror
LOCAL_C_INCLUDES := external/libnl-headers
LOCAL_STATIC_LIBRARIES := libnl_2
LOCAL_SHARED_LIBRARIES := libcutils liblog
diff --git a/clatd.c b/clatd.c
index 26ecb57..a0ee07d 100644
--- a/clatd.c
+++ b/clatd.c
@@ -47,8 +47,6 @@
#include <private/android_filesystem_config.h>
-#include "ipv4.h"
-#include "ipv6.h"
#include "translate.h"
#include "clatd.h"
#include "config.h"
@@ -84,7 +82,7 @@
/* function: stop_loop
* signal handler: stop the event loop
*/
-void stop_loop(int signal) {
+void stop_loop() {
running = 0;
}
@@ -146,7 +144,6 @@
* tunnel - tun device data
*/
void configure_tun_ipv6(const struct tun_data *tunnel) {
- struct in6_addr local_nat64_prefix_6;
int status;
status = if_route(tunnel->device6, AF_INET6, &Global_Clatd_Config.ipv6_local_subnet,
@@ -379,7 +376,6 @@
logmsg(ANDROID_LOG_WARN,"read_packet/tun interface removed");
running = 0;
} else {
- struct tun_pi tun_header;
ssize_t header_size = sizeof(struct tun_pi);
if(readlen < header_size) {
diff --git a/clatd.conf b/clatd.conf
index 578da59..0d4b79e 100644
--- a/clatd.conf
+++ b/clatd.conf
@@ -11,7 +11,7 @@
# get the plat_subnet from dns lookups (requires DNS64)
plat_from_dns64 yes
# hostname to use to lookup plat subnet. must contain only A records
-plat_from_dns64_hostname ipv4.google.com
+plat_from_dns64_hostname ipv4only.arpa
# plat subnet to send ipv4 traffic to. This is a /96 subnet.
# This setting only makes sense with: plat_from_dns64 no
diff --git a/config.c b/config.c
index 61a4ebb..b82ac6c 100644
--- a/config.c
+++ b/config.c
@@ -154,7 +154,7 @@
* does dns lookups to set the plat subnet or exits on failure, waits forever for a dns response with a query backoff timer
*/
void dns64_detection() {
- int i, backoff_sleep, status;
+ int backoff_sleep, status;
struct in6_addr tmp_ptr;
backoff_sleep = 1;
diff --git a/icmp.c b/icmp.c
index af96b83..75a4a4d 100644
--- a/icmp.c
+++ b/icmp.c
@@ -139,7 +139,7 @@
}
// We don't understand this ICMP type. Return parameter problem so the caller will bail out.
- logmsg_dbg(ANDROID_LOG_DEBUG, "icmp6_to_icmp_type: unhandled ICMP type %d", type);
+ logmsg_dbg(ANDROID_LOG_DEBUG, "icmp6_to_icmp_type: unhandled ICMP type/code %d/%d", type, code);
return ICMP_PARAMETERPROB;
}
diff --git a/ipv4.c b/ipv4.c
index 89e47e4..b5cbf80 100644
--- a/ipv4.c
+++ b/ipv4.c
@@ -28,7 +28,6 @@
#include "translate.h"
#include "checksum.h"
-#include "ipv4.h"
#include "logging.h"
#include "debug.h"
#include "dump.h"
@@ -124,12 +123,14 @@
// Calculate the pseudo-header checksum.
checksum = ipv6_pseudo_header_checksum(0, ip6_targ, len_left);
- if(nxthdr == IPPROTO_ICMPV6) {
+ if (nxthdr == IPPROTO_ICMPV6) {
iov_len = icmp_packet(out, pos + 1, (const struct icmphdr *) next_header, checksum, len_left);
- } else if(nxthdr == IPPROTO_TCP) {
+ } else if (nxthdr == IPPROTO_TCP) {
iov_len = tcp_packet(out, pos + 1, (const struct tcphdr *) next_header, checksum, len_left);
- } else if(nxthdr == IPPROTO_UDP) {
+ } else if (nxthdr == IPPROTO_UDP) {
iov_len = udp_packet(out, pos + 1, (const struct udphdr *) next_header, checksum, len_left);
+ } else if (nxthdr == IPPROTO_GRE) {
+ iov_len = generic_packet(out, pos + 1, next_header, len_left);
} else {
#if CLAT_DEBUG
logmsg_dbg(ANDROID_LOG_ERROR, "ip_packet/unknown protocol: %x",header->protocol);
diff --git a/ipv4.h b/ipv4.h
deleted file mode 100644
index 00befd2..0000000
--- a/ipv4.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright 2011 Daniel Drown
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * ipv4.h - takes an ipv4 packet and hands it off to the proper translate function
- */
-#ifndef __IPV4_H__
-#define __IPV4_H__
-
-#include "translate.h"
-
-int ipv4_packet(clat_packet out, int pos, const char *packet, size_t len);
-
-#endif /* __IPV4_H__ */
diff --git a/ipv6.c b/ipv6.c
index ef1e62f..79303ec 100644
--- a/ipv6.c
+++ b/ipv6.c
@@ -29,7 +29,6 @@
#include "translate.h"
#include "checksum.h"
-#include "ipv6.h"
#include "logging.h"
#include "dump.h"
#include "config.h"
@@ -43,8 +42,7 @@
* len - size of ip payload
* returns: the highest position in the output clat_packet that's filled in
*/
-int icmp6_packet(clat_packet out, int pos, const struct icmp6_hdr *icmp6, uint32_t checksum,
- size_t len) {
+int icmp6_packet(clat_packet out, int pos, const struct icmp6_hdr *icmp6, size_t len) {
const char *payload;
size_t payload_size;
@@ -56,7 +54,7 @@
payload = (const char *) (icmp6 + 1);
payload_size = len - sizeof(struct icmp6_hdr);
- return icmp6_to_icmp(out, pos, icmp6, checksum, payload, payload_size);
+ return icmp6_to_icmp(out, pos, icmp6, payload, payload_size);
}
/* function: log_bad_address
@@ -64,16 +62,18 @@
* fmt - printf-style format, use %s to place the address
* badaddr - the bad address in question
*/
-void log_bad_address(const char *fmt, const struct in6_addr *src, const struct in6_addr *dst) {
#if CLAT_DEBUG
+void log_bad_address(const char *fmt, const struct in6_addr *src, const struct in6_addr *dst) {
char srcstr[INET6_ADDRSTRLEN];
char dststr[INET6_ADDRSTRLEN];
inet_ntop(AF_INET6, src, srcstr, sizeof(srcstr));
inet_ntop(AF_INET6, dst, dststr, sizeof(dststr));
logmsg_dbg(ANDROID_LOG_ERROR, fmt, srcstr, dststr);
-#endif
}
+#else
+#define log_bad_address(fmt, src, dst)
+#endif
/* function: ipv6_packet
* takes an ipv6 packet and hands it off to the layer 4 protocol function
@@ -90,7 +90,6 @@
size_t len_left;
uint32_t checksum;
int iov_len;
- int i;
if(len < sizeof(struct ip6_hdr)) {
logmsg_dbg(ANDROID_LOG_ERROR, "ipv6_packet/too short for an ip6 header: %d", len);
@@ -137,15 +136,16 @@
checksum = ipv4_pseudo_header_checksum(0, ip_targ, len_left);
// does not support IPv6 extension headers, this will drop any packet with them
- if(protocol == IPPROTO_ICMP) {
- iov_len = icmp6_packet(out, pos + 1, (const struct icmp6_hdr *) next_header, checksum,
- len_left);
- } else if(ip6->ip6_nxt == IPPROTO_TCP) {
+ if (protocol == IPPROTO_ICMP) {
+ iov_len = icmp6_packet(out, pos + 1, (const struct icmp6_hdr *) next_header, len_left);
+ } else if (ip6->ip6_nxt == IPPROTO_TCP) {
iov_len = tcp_packet(out, pos + 1, (const struct tcphdr *) next_header, checksum,
len_left);
- } else if(ip6->ip6_nxt == IPPROTO_UDP) {
+ } else if (ip6->ip6_nxt == IPPROTO_UDP) {
iov_len = udp_packet(out, pos + 1, (const struct udphdr *) next_header, checksum,
len_left);
+ } else if (ip6->ip6_nxt == IPPROTO_GRE) {
+ iov_len = generic_packet(out, pos + 1, next_header, len_left);
} else {
#if CLAT_DEBUG
logmsg(ANDROID_LOG_ERROR, "ipv6_packet/unknown next header type: %x", ip6->ip6_nxt);
diff --git a/ipv6.h b/ipv6.h
deleted file mode 100644
index 019de17..0000000
--- a/ipv6.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright 2011 Daniel Drown
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * ipv6.h - takes an ipv6 packet and hands it off to the proper translate function
- */
-#ifndef __IPV6_H__
-#define __IPV6_H__
-
-#include "translate.h"
-
-int ipv6_packet(clat_packet out, int pos, const char *packet, size_t len);
-
-#endif /* __IPV6_H__ */
diff --git a/translate.c b/translate.c
index fc70f3d..00ea0b9 100644
--- a/translate.c
+++ b/translate.c
@@ -149,7 +149,7 @@
// Third-party ICMPv6 message. This may have been originated by an native IPv6 address.
// In that case, the source IPv6 address can't be translated and we need to make up an IPv4
// source address. For now, use 255.0.0.<ttl>, which at least looks useful in traceroute.
- if (ip->saddr == (uint32_t) INADDR_NONE) {
+ if ((uint32_t) ip->saddr == INADDR_NONE) {
ttl_guess = icmp_guess_ttl(old_header->ip6_hlim);
ip->saddr = htonl((0xff << 24) + ttl_guess);
}
@@ -236,16 +236,14 @@
* translate ipv6 icmp to ipv4 icmp
* out - output packet
* icmp6 - source packet icmp6 header
- * checksum - pseudo-header checksum (unused)
* payload - icmp6 payload
* payload_size - size of payload
* returns: the highest position in the output clat_packet that's filled in
*/
-int icmp6_to_icmp(clat_packet out, int pos, const struct icmp6_hdr *icmp6, uint32_t checksum,
+int icmp6_to_icmp(clat_packet out, int pos, const struct icmp6_hdr *icmp6,
const char *payload, size_t payload_size) {
struct icmphdr *icmp_targ = out[pos].iov_base;
uint8_t icmp_type;
- int ttl;
int clat_packet_len;
memset(icmp_targ, 0, sizeof(struct icmphdr));
@@ -280,6 +278,22 @@
return clat_packet_len;
}
+/* function: generic_packet
+ * takes a generic IP packet and sets it up for translation
+ * out - output packet
+ * pos - position in the output packet of the transport header
+ * payload - pointer to IP payload
+ * len - size of ip payload
+ * returns: the highest position in the output clat_packet that's filled in
+ */
+int generic_packet(clat_packet out, int pos, const char *payload, size_t len) {
+ out[pos].iov_len = 0;
+ out[CLAT_POS_PAYLOAD].iov_base = (char *) payload;
+ out[CLAT_POS_PAYLOAD].iov_len = len;
+
+ return CLAT_POS_PAYLOAD + 1;
+}
+
/* function: udp_packet
* takes a udp packet and sets it up for translation
* out - output packet
diff --git a/translate.h b/translate.h
index fded251..9f1ac15 100644
--- a/translate.h
+++ b/translate.h
@@ -47,12 +47,19 @@
void fill_ip6_header(struct ip6_hdr *ip6, uint16_t payload_len, uint8_t protocol,
const struct iphdr *old_header);
+// Translate IPv4 and IPv6 packets.
+int ipv4_packet(clat_packet out, int pos, const char *packet, size_t len);
+int ipv6_packet(clat_packet out, int pos, const char *packet, size_t len);
+
// Translate ICMP packets.
int icmp_to_icmp6(clat_packet out, int pos, const struct icmphdr *icmp, uint32_t checksum,
const char *payload, size_t payload_size);
-int icmp6_to_icmp(clat_packet out, int pos, const struct icmp6_hdr *icmp6, uint32_t checksum,
+int icmp6_to_icmp(clat_packet out, int pos, const struct icmp6_hdr *icmp6,
const char *payload, size_t payload_size);
+// Translate generic IP packets.
+int generic_packet(clat_packet out, int pos, const char *payload, size_t len);
+
// Translate TCP and UDP packets.
int tcp_packet(clat_packet out, int pos, const struct tcphdr *tcp, uint32_t checksum, size_t len);
int udp_packet(clat_packet out, int pos, const struct udphdr *udp, uint32_t checksum, size_t len);