Support more than one clatd at a time.
The only change necessary is to stop calling the clat interface
"clat4" and instead name it based on the upstream interface
(specifically, "v4-<interface>".
Bug: 12111730
Change-Id: I489ebb0e3b1408ace8b64ca09ec20366fefe8d83
diff --git a/clatd.c b/clatd.c
index 4b6b8cc..f5d625d 100644
--- a/clatd.c
+++ b/clatd.c
@@ -51,7 +51,7 @@
#include "getaddr.h"
#include "dump.h"
-#define DEVICENAME4 "clat4"
+#define DEVICEPREFIX "v4-"
/* 40 bytes IPv6 header - 20 bytes IPv4 header + 8 bytes fragment header */
#define MTU_DELTA 28
@@ -156,11 +156,11 @@
*/
void interface_poll(const struct tun_data *tunnel) {
union anyip *interface_ip;
+ char *interface = Global_Clatd_Config.default_pdp_interface;
- interface_ip = getinterface_ip(Global_Clatd_Config.default_pdp_interface, AF_INET6);
+ interface_ip = getinterface_ip(interface, AF_INET6);
if(!interface_ip) {
- logmsg(ANDROID_LOG_WARN,"unable to find an ipv6 ip on interface %s",
- Global_Clatd_Config.default_pdp_interface);
+ logmsg(ANDROID_LOG_WARN,"unable to find an ipv6 ip on interface %s", interface);
return;
}
@@ -441,8 +441,7 @@
char *uplink_interface = NULL, *plat_prefix = NULL, *net_id_str = NULL, *mark_str = NULL;
unsigned net_id = NETID_UNSET;
uint32_t mark = MARK_UNSET;
-
- strcpy(tunnel.device4, DEVICENAME4);
+ unsigned len;
while((opt = getopt(argc, argv, "i:p:n:m:h")) != -1) {
switch(opt) {
@@ -482,6 +481,12 @@
exit(1);
}
+ len = snprintf(tunnel.device4, sizeof(tunnel.device4), "%s%s", DEVICEPREFIX, uplink_interface);
+ if (len >= sizeof(tunnel.device4)) {
+ logmsg(ANDROID_LOG_FATAL, "interface name too long '%s'", tunnel.device4);
+ exit(1);
+ }
+
logmsg(ANDROID_LOG_INFO, "Starting clat version %s on %s netid=%s mark=%s",
CLATD_VERSION, uplink_interface,
net_id_str ? net_id_str : "(none)",