| Daniel Drown | a45056e | 2012-03-23 10:42:54 -0500 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright 2012 Daniel Drown | 
|  | 3 | * | 
|  | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 5 | * you may not use this file except in compliance with the License. | 
|  | 6 | * You may obtain a copy of the License at | 
|  | 7 | * | 
|  | 8 | * http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 9 | * | 
|  | 10 | * Unless required by applicable law or agreed to in writing, software | 
|  | 11 | * distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 13 | * See the License for the specific language governing permissions and | 
|  | 14 | * limitations under the License. | 
|  | 15 | * | 
|  | 16 | * clatd.c - tun interface setup and main event loop | 
|  | 17 | */ | 
| junyulai | c4e591a | 2018-11-26 22:36:10 +0900 | [diff] [blame] | 18 | #include <arpa/inet.h> | 
|  | 19 | #include <errno.h> | 
|  | 20 | #include <fcntl.h> | 
| Daniel Drown | a45056e | 2012-03-23 10:42:54 -0500 | [diff] [blame] | 21 | #include <poll.h> | 
|  | 22 | #include <signal.h> | 
| Daniel Drown | a45056e | 2012-03-23 10:42:54 -0500 | [diff] [blame] | 23 | #include <stdio.h> | 
| junyulai | c4e591a | 2018-11-26 22:36:10 +0900 | [diff] [blame] | 24 | #include <stdlib.h> | 
|  | 25 | #include <string.h> | 
| Daniel Drown | a45056e | 2012-03-23 10:42:54 -0500 | [diff] [blame] | 26 | #include <sys/ioctl.h> | 
| Elliott Hughes | 3afe9ae | 2014-07-18 17:25:26 -0700 | [diff] [blame] | 27 | #include <sys/prctl.h> | 
| Daniel Drown | a45056e | 2012-03-23 10:42:54 -0500 | [diff] [blame] | 28 | #include <sys/stat.h> | 
| junyulai | c4e591a | 2018-11-26 22:36:10 +0900 | [diff] [blame] | 29 | #include <sys/types.h> | 
|  | 30 | #include <time.h> | 
| Daniel Drown | a45056e | 2012-03-23 10:42:54 -0500 | [diff] [blame] | 31 | #include <unistd.h> | 
| Daniel Drown | a45056e | 2012-03-23 10:42:54 -0500 | [diff] [blame] | 32 |  | 
| Lorenzo Colitti | f08c5aa | 2014-06-03 12:56:38 +0900 | [diff] [blame] | 33 | #include <linux/filter.h> | 
| Daniel Drown | a45056e | 2012-03-23 10:42:54 -0500 | [diff] [blame] | 34 | #include <linux/if.h> | 
| Daniel Drown | a45056e | 2012-03-23 10:42:54 -0500 | [diff] [blame] | 35 | #include <linux/if_ether.h> | 
| Lorenzo Colitti | f08c5aa | 2014-06-03 12:56:38 +0900 | [diff] [blame] | 36 | #include <linux/if_packet.h> | 
| junyulai | c4e591a | 2018-11-26 22:36:10 +0900 | [diff] [blame] | 37 | #include <linux/if_tun.h> | 
| Lorenzo Colitti | f08c5aa | 2014-06-03 12:56:38 +0900 | [diff] [blame] | 38 | #include <net/if.h> | 
| junyulai | c4e591a | 2018-11-26 22:36:10 +0900 | [diff] [blame] | 39 | #include <sys/uio.h> | 
| Daniel Drown | a45056e | 2012-03-23 10:42:54 -0500 | [diff] [blame] | 40 |  | 
| Daniel Drown | a45056e | 2012-03-23 10:42:54 -0500 | [diff] [blame] | 41 | #include "clatd.h" | 
| Maciej Żenczykowski | f6ec94e | 2022-07-12 16:17:33 -0700 | [diff] [blame] | 42 | #include "checksum.h" | 
| Daniel Drown | a45056e | 2012-03-23 10:42:54 -0500 | [diff] [blame] | 43 | #include "config.h" | 
| Daniel Drown | a45056e | 2012-03-23 10:42:54 -0500 | [diff] [blame] | 44 | #include "dump.h" | 
| junyulai | c4e591a | 2018-11-26 22:36:10 +0900 | [diff] [blame] | 45 | #include "getaddr.h" | 
|  | 46 | #include "logging.h" | 
| junyulai | c4e591a | 2018-11-26 22:36:10 +0900 | [diff] [blame] | 47 | #include "translate.h" | 
| Daniel Drown | a45056e | 2012-03-23 10:42:54 -0500 | [diff] [blame] | 48 |  | 
| Maciej Żenczykowski | 5ce6cda | 2020-06-02 14:39:33 -0700 | [diff] [blame] | 49 | struct clat_config Global_Clatd_Config; | 
|  | 50 |  | 
| Lorenzo Colitti | 57d480d | 2014-02-09 10:35:38 +0900 | [diff] [blame] | 51 | /* 40 bytes IPv6 header - 20 bytes IPv4 header + 8 bytes fragment header */ | 
|  | 52 | #define MTU_DELTA 28 | 
|  | 53 |  | 
| Daniel Drown | a45056e | 2012-03-23 10:42:54 -0500 | [diff] [blame] | 54 | volatile sig_atomic_t running = 1; | 
|  | 55 |  | 
| Lorenzo Colitti | 66deecd | 2019-01-04 12:27:27 +0900 | [diff] [blame] | 56 | int ipv6_address_changed(const char *interface) { | 
|  | 57 | union anyip *interface_ip; | 
|  | 58 |  | 
|  | 59 | interface_ip = getinterface_ip(interface, AF_INET6); | 
|  | 60 | if (!interface_ip) { | 
|  | 61 | logmsg(ANDROID_LOG_ERROR, "Unable to find an IPv6 address on interface %s", interface); | 
|  | 62 | return 1; | 
|  | 63 | } | 
|  | 64 |  | 
|  | 65 | if (!ipv6_prefix_equal(&interface_ip->ip6, &Global_Clatd_Config.ipv6_local_subnet)) { | 
|  | 66 | char oldstr[INET6_ADDRSTRLEN]; | 
|  | 67 | char newstr[INET6_ADDRSTRLEN]; | 
|  | 68 | inet_ntop(AF_INET6, &Global_Clatd_Config.ipv6_local_subnet, oldstr, sizeof(oldstr)); | 
|  | 69 | inet_ntop(AF_INET6, &interface_ip->ip6, newstr, sizeof(newstr)); | 
|  | 70 | logmsg(ANDROID_LOG_INFO, "IPv6 prefix on %s changed: %s -> %s", interface, oldstr, newstr); | 
|  | 71 | free(interface_ip); | 
|  | 72 | return 1; | 
|  | 73 | } else { | 
|  | 74 | free(interface_ip); | 
|  | 75 | return 0; | 
|  | 76 | } | 
|  | 77 | } | 
|  | 78 |  | 
| Maciej Żenczykowski | e6e0c00 | 2023-01-18 23:57:35 +0000 | [diff] [blame] | 79 | // reads L3 IPv6 packet from AF_PACKET socket, translates to IPv4, writes to tun | 
|  | 80 | void process_packet_6_to_4(struct tun_data *tunnel) { | 
|  | 81 | uint8_t buf[MAXMTU]; | 
|  | 82 | ssize_t readlen = read(tunnel->read_fd6, buf, MAXMTU); | 
| Daniel Drown | a45056e | 2012-03-23 10:42:54 -0500 | [diff] [blame] | 83 |  | 
| junyulai | c4e591a | 2018-11-26 22:36:10 +0900 | [diff] [blame] | 84 | if (readlen < 0) { | 
| Lorenzo Colitti | 4945481 | 2015-01-31 19:18:47 +0900 | [diff] [blame] | 85 | if (errno != EAGAIN) { | 
| Maciej Żenczykowski | e6e0c00 | 2023-01-18 23:57:35 +0000 | [diff] [blame] | 86 | logmsg(ANDROID_LOG_WARN, "%s: read error: %s", __func__, strerror(errno)); | 
| Lorenzo Colitti | 4945481 | 2015-01-31 19:18:47 +0900 | [diff] [blame] | 87 | } | 
| Daniel Drown | a45056e | 2012-03-23 10:42:54 -0500 | [diff] [blame] | 88 | return; | 
| junyulai | c4e591a | 2018-11-26 22:36:10 +0900 | [diff] [blame] | 89 | } else if (readlen == 0) { | 
| Maciej Żenczykowski | e6e0c00 | 2023-01-18 23:57:35 +0000 | [diff] [blame] | 90 | logmsg(ANDROID_LOG_WARN, "%s: packet socket removed?", __func__); | 
| Daniel Drown | a45056e | 2012-03-23 10:42:54 -0500 | [diff] [blame] | 91 | running = 0; | 
| Lorenzo Colitti | f08c5aa | 2014-06-03 12:56:38 +0900 | [diff] [blame] | 92 | return; | 
| Maciej Żenczykowski | e6e0c00 | 2023-01-18 23:57:35 +0000 | [diff] [blame] | 93 | } else if (readlen >= MAXMTU) { | 
|  | 94 | logmsg(ANDROID_LOG_WARN, "%s: read truncation - ignoring pkt", __func__); | 
|  | 95 | return; | 
| Lorenzo Colitti | f08c5aa | 2014-06-03 12:56:38 +0900 | [diff] [blame] | 96 | } | 
|  | 97 |  | 
| Maciej Żenczykowski | e6e0c00 | 2023-01-18 23:57:35 +0000 | [diff] [blame] | 98 | translate_packet(tunnel->fd4, 0 /* to_ipv6 */, buf, readlen); | 
|  | 99 | } | 
|  | 100 |  | 
|  | 101 | // reads TUN_PI + L3 IPv4 packet from tun, translates to IPv6, writes to AF_INET6/RAW socket | 
|  | 102 | void process_packet_4_to_6(struct tun_data *tunnel) { | 
|  | 103 | uint8_t buf[PACKETLEN]; | 
|  | 104 | ssize_t readlen = read(tunnel->fd4, buf, PACKETLEN); | 
|  | 105 |  | 
|  | 106 | if (readlen < 0) { | 
|  | 107 | if (errno != EAGAIN) { | 
|  | 108 | logmsg(ANDROID_LOG_WARN, "%s: read error: %s", __func__, strerror(errno)); | 
|  | 109 | } | 
|  | 110 | return; | 
|  | 111 | } else if (readlen == 0) { | 
|  | 112 | logmsg(ANDROID_LOG_WARN, "%s: tun interface removed", __func__); | 
|  | 113 | running = 0; | 
|  | 114 | return; | 
|  | 115 | } else if (readlen >= PACKETLEN) { | 
|  | 116 | logmsg(ANDROID_LOG_WARN, "%s: read truncation - ignoring pkt", __func__); | 
| Maciej Żenczykowski | 5030353 | 2020-06-02 14:46:45 -0700 | [diff] [blame] | 117 | return; | 
|  | 118 | } | 
|  | 119 |  | 
| junyulai | c4e591a | 2018-11-26 22:36:10 +0900 | [diff] [blame] | 120 | struct tun_pi *tun_header = (struct tun_pi *)buf; | 
|  | 121 | if (readlen < (ssize_t)sizeof(*tun_header)) { | 
| Maciej Żenczykowski | e6e0c00 | 2023-01-18 23:57:35 +0000 | [diff] [blame] | 122 | logmsg(ANDROID_LOG_WARN, "%s: short read: got %ld bytes", __func__, readlen); | 
| Lorenzo Colitti | 9353be2 | 2014-12-03 15:18:29 +0900 | [diff] [blame] | 123 | return; | 
| Daniel Drown | a45056e | 2012-03-23 10:42:54 -0500 | [diff] [blame] | 124 | } | 
| Lorenzo Colitti | f08c5aa | 2014-06-03 12:56:38 +0900 | [diff] [blame] | 125 |  | 
| Lorenzo Colitti | 9353be2 | 2014-12-03 15:18:29 +0900 | [diff] [blame] | 126 | uint16_t proto = ntohs(tun_header->proto); | 
|  | 127 | if (proto != ETH_P_IP) { | 
|  | 128 | logmsg(ANDROID_LOG_WARN, "%s: unknown packet type = 0x%x", __func__, proto); | 
|  | 129 | return; | 
|  | 130 | } | 
|  | 131 |  | 
| junyulai | c4e591a | 2018-11-26 22:36:10 +0900 | [diff] [blame] | 132 | if (tun_header->flags != 0) { | 
| Lorenzo Colitti | 9353be2 | 2014-12-03 15:18:29 +0900 | [diff] [blame] | 133 | logmsg(ANDROID_LOG_WARN, "%s: unexpected flags = %d", __func__, tun_header->flags); | 
|  | 134 | } | 
|  | 135 |  | 
| Maciej Żenczykowski | 5030353 | 2020-06-02 14:46:45 -0700 | [diff] [blame] | 136 | uint8_t *packet = (uint8_t *)(tun_header + 1); | 
| Lorenzo Colitti | 9353be2 | 2014-12-03 15:18:29 +0900 | [diff] [blame] | 137 | readlen -= sizeof(*tun_header); | 
| Maciej Żenczykowski | e6e0c00 | 2023-01-18 23:57:35 +0000 | [diff] [blame] | 138 | translate_packet(tunnel->write_fd6, 1 /* to_ipv6 */, packet, readlen); | 
| Daniel Drown | a45056e | 2012-03-23 10:42:54 -0500 | [diff] [blame] | 139 | } | 
|  | 140 |  | 
| Maciej Żenczykowski | f6ec94e | 2022-07-12 16:17:33 -0700 | [diff] [blame] | 141 | // IPv6 DAD packet format: | 
|  | 142 | //   Ethernet header (if needed) will be added by the kernel: | 
|  | 143 | //     u8[6] src_mac; u8[6] dst_mac '33:33:ff:XX:XX:XX'; be16 ethertype '0x86DD' | 
|  | 144 | //   IPv6 header: | 
|  | 145 | //     be32 0x60000000 - ipv6, tclass 0, flowlabel 0 | 
|  | 146 | //     be16 payload_length '32'; u8 nxt_hdr ICMPv6 '58'; u8 hop limit '255' | 
|  | 147 | //     u128 src_ip6 '::' | 
|  | 148 | //     u128 dst_ip6 'ff02::1:ffXX:XXXX' | 
|  | 149 | //   ICMPv6 header: | 
|  | 150 | //     u8 type '135'; u8 code '0'; u16 icmp6 checksum; u32 reserved '0' | 
|  | 151 | //   ICMPv6 neighbour solicitation payload: | 
|  | 152 | //     u128 tgt_ip6 | 
|  | 153 | //   ICMPv6 ND options: | 
|  | 154 | //     u8 opt nr '14'; u8 length '1'; u8[6] nonce '6 random bytes' | 
| Maciej Żenczykowski | a1cb0f3 | 2022-07-19 09:22:58 -0700 | [diff] [blame] | 155 | void send_dad(int fd, const struct in6_addr* tgt) { | 
| Maciej Żenczykowski | f6ec94e | 2022-07-12 16:17:33 -0700 | [diff] [blame] | 156 | struct { | 
|  | 157 | struct ip6_hdr ip6h; | 
|  | 158 | struct nd_neighbor_solicit ns; | 
|  | 159 | uint8_t ns_opt_nr; | 
|  | 160 | uint8_t ns_opt_len; | 
|  | 161 | uint8_t ns_opt_nonce[6]; | 
|  | 162 | } dad_pkt = { | 
|  | 163 | .ip6h = { | 
|  | 164 | .ip6_flow = htonl(6 << 28),  // v6, 0 tclass, 0 flowlabel | 
|  | 165 | .ip6_plen = htons(sizeof(dad_pkt) - sizeof(struct ip6_hdr)),  // payload length, ie. 32 | 
|  | 166 | .ip6_nxt = IPPROTO_ICMPV6,  // 58 | 
|  | 167 | .ip6_hlim = 255, | 
|  | 168 | .ip6_src = {},  // :: | 
|  | 169 | .ip6_dst.s6_addr = { | 
|  | 170 | 0xFF, 0x02, 0, 0, | 
|  | 171 | 0, 0, 0, 0, | 
|  | 172 | 0, 0, 0, 1, | 
|  | 173 | 0xFF, tgt->s6_addr[13], tgt->s6_addr[14], tgt->s6_addr[15], | 
|  | 174 | },  // ff02::1:ffXX:XXXX - multicast group address derived from bottom 24-bits of tgt | 
|  | 175 | }, | 
|  | 176 | .ns = { | 
|  | 177 | .nd_ns_type = ND_NEIGHBOR_SOLICIT,  // 135 | 
|  | 178 | .nd_ns_code = 0, | 
|  | 179 | .nd_ns_cksum = 0,  // will be calculated later | 
|  | 180 | .nd_ns_reserved = 0, | 
|  | 181 | .nd_ns_target = *tgt, | 
|  | 182 | }, | 
|  | 183 | .ns_opt_nr = 14,  // icmp6 option 'nonce' from RFC3971 | 
|  | 184 | .ns_opt_len = 1,  // in units of 8 bytes, including option nr and len | 
| Maciej Żenczykowski | a1cb0f3 | 2022-07-19 09:22:58 -0700 | [diff] [blame] | 185 | .ns_opt_nonce = {},  // opt_len *8 - sizeof u8(opt_nr) - sizeof u8(opt_len) = 6 ranodmized bytes | 
| Maciej Żenczykowski | f6ec94e | 2022-07-12 16:17:33 -0700 | [diff] [blame] | 186 | }; | 
| Maciej Żenczykowski | a1cb0f3 | 2022-07-19 09:22:58 -0700 | [diff] [blame] | 187 | arc4random_buf(&dad_pkt.ns_opt_nonce, sizeof(dad_pkt.ns_opt_nonce)); | 
| Maciej Żenczykowski | f6ec94e | 2022-07-12 16:17:33 -0700 | [diff] [blame] | 188 |  | 
|  | 189 | // 40 byte IPv6 header + 8 byte ICMPv6 header + 16 byte ipv6 target address + 8 byte nonce option | 
|  | 190 | _Static_assert(sizeof(dad_pkt) == 40 + 8 + 16 + 8, "sizeof dad packet != 72"); | 
|  | 191 |  | 
|  | 192 | // IPv6 header checksum is standard negated 16-bit one's complement sum over the icmpv6 pseudo | 
|  | 193 | // header (which includes payload length, nextheader, and src/dst ip) and the icmpv6 payload. | 
|  | 194 | // | 
|  | 195 | // Src/dst ip immediately prefix the icmpv6 header itself, so can be handled along | 
|  | 196 | // with the payload.  We thus only need to manually account for payload len & next header. | 
|  | 197 | // | 
|  | 198 | // The magic '8' is simply the offset of the ip6_src field in the ipv6 header, | 
|  | 199 | // ie. we're skipping over the ipv6 version, tclass, flowlabel, payload length, next header | 
|  | 200 | // and hop limit fields, because they're not quite where we want them to be. | 
|  | 201 | // | 
|  | 202 | // ip6_plen is already in network order, while ip6_nxt is a single byte and thus needs htons(). | 
|  | 203 | uint32_t csum = dad_pkt.ip6h.ip6_plen + htons(dad_pkt.ip6h.ip6_nxt); | 
|  | 204 | csum = ip_checksum_add(csum, &dad_pkt.ip6h.ip6_src, sizeof(dad_pkt) - 8); | 
|  | 205 | dad_pkt.ns.nd_ns_cksum = ip_checksum_finish(csum); | 
|  | 206 |  | 
|  | 207 | const struct sockaddr_in6 dst = { | 
|  | 208 | .sin6_family = AF_INET6, | 
|  | 209 | .sin6_addr = dad_pkt.ip6h.ip6_dst, | 
|  | 210 | .sin6_scope_id = if_nametoindex(Global_Clatd_Config.native_ipv6_interface), | 
|  | 211 | }; | 
|  | 212 |  | 
| Maciej Żenczykowski | a1cb0f3 | 2022-07-19 09:22:58 -0700 | [diff] [blame] | 213 | sendto(fd, &dad_pkt, sizeof(dad_pkt), 0 /*flags*/, (const struct sockaddr *)&dst, sizeof(dst)); | 
| Maciej Żenczykowski | f6ec94e | 2022-07-12 16:17:33 -0700 | [diff] [blame] | 214 | } | 
|  | 215 |  | 
| Daniel Drown | a45056e | 2012-03-23 10:42:54 -0500 | [diff] [blame] | 216 | /* function: event_loop | 
|  | 217 | * reads packets from the tun network interface and passes them down the stack | 
| junyulai | c4e591a | 2018-11-26 22:36:10 +0900 | [diff] [blame] | 218 | *   tunnel - tun device data | 
| Daniel Drown | a45056e | 2012-03-23 10:42:54 -0500 | [diff] [blame] | 219 | */ | 
| Lorenzo Colitti | 9353be2 | 2014-12-03 15:18:29 +0900 | [diff] [blame] | 220 | void event_loop(struct tun_data *tunnel) { | 
| Maciej Żenczykowski | f6ec94e | 2022-07-12 16:17:33 -0700 | [diff] [blame] | 221 | // Apparently some network gear will refuse to perform NS for IPs that aren't DAD'ed, | 
|  | 222 | // this would then result in an ipv6-only network with working native ipv6, working | 
|  | 223 | // IPv4 via DNS64, but non-functioning IPv4 via CLAT (ie. IPv4 literals + IPv4 only apps). | 
|  | 224 | // The kernel itself doesn't do DAD for anycast ips (but does handle IPV6 MLD and handle ND). | 
|  | 225 | // So we'll spoof dad here, and yeah, we really should check for a response and in | 
|  | 226 | // case of failure pick a different IP.  Seeing as 48-bits of the IP are utterly random | 
|  | 227 | // (with the other 16 chosen to guarantee checksum neutrality) this seems like a remote | 
|  | 228 | // concern... | 
|  | 229 | // TODO: actually perform true DAD | 
| Maciej Żenczykowski | a1cb0f3 | 2022-07-19 09:22:58 -0700 | [diff] [blame] | 230 | send_dad(tunnel->write_fd6, &Global_Clatd_Config.ipv6_local_subnet); | 
| Maciej Żenczykowski | f6ec94e | 2022-07-12 16:17:33 -0700 | [diff] [blame] | 231 |  | 
| Daniel Drown | a45056e | 2012-03-23 10:42:54 -0500 | [diff] [blame] | 232 | time_t last_interface_poll; | 
| Lorenzo Colitti | dce3ddf | 2014-08-25 16:07:12 -0700 | [diff] [blame] | 233 | struct pollfd wait_fd[] = { | 
|  | 234 | { tunnel->read_fd6, POLLIN, 0 }, | 
|  | 235 | { tunnel->fd4, POLLIN, 0 }, | 
|  | 236 | }; | 
| Daniel Drown | a45056e | 2012-03-23 10:42:54 -0500 | [diff] [blame] | 237 |  | 
|  | 238 | // start the poll timer | 
|  | 239 | last_interface_poll = time(NULL); | 
|  | 240 |  | 
| junyulai | c4e591a | 2018-11-26 22:36:10 +0900 | [diff] [blame] | 241 | while (running) { | 
|  | 242 | if (poll(wait_fd, ARRAY_SIZE(wait_fd), NO_TRAFFIC_INTERFACE_POLL_FREQUENCY * 1000) == -1) { | 
| Bernie Innocenti | 69dc60d | 2018-05-14 20:40:49 +0900 | [diff] [blame] | 243 | if (errno != EINTR) { | 
| junyulai | c4e591a | 2018-11-26 22:36:10 +0900 | [diff] [blame] | 244 | logmsg(ANDROID_LOG_WARN, "event_loop/poll returned an error: %s", strerror(errno)); | 
| Daniel Drown | a45056e | 2012-03-23 10:42:54 -0500 | [diff] [blame] | 245 | } | 
|  | 246 | } else { | 
| Maciej Żenczykowski | e6e0c00 | 2023-01-18 23:57:35 +0000 | [diff] [blame] | 247 | // Call process_packet if the socket has data to be read, but also if an | 
| Lorenzo Colitti | 9353be2 | 2014-12-03 15:18:29 +0900 | [diff] [blame] | 248 | // error is waiting. If we don't call read() after getting POLLERR, a | 
|  | 249 | // subsequent poll() will return immediately with POLLERR again, | 
|  | 250 | // causing this code to spin in a loop. Calling read() will clear the | 
|  | 251 | // socket error flag instead. | 
| Maciej Żenczykowski | e6e0c00 | 2023-01-18 23:57:35 +0000 | [diff] [blame] | 252 | if (wait_fd[0].revents) process_packet_6_to_4(tunnel); | 
|  | 253 | if (wait_fd[1].revents) process_packet_4_to_6(tunnel); | 
| Daniel Drown | a45056e | 2012-03-23 10:42:54 -0500 | [diff] [blame] | 254 | } | 
|  | 255 |  | 
|  | 256 | time_t now = time(NULL); | 
| Rocco Yue | e4b7da6 | 2020-09-02 15:21:41 +0800 | [diff] [blame] | 257 | if (now >= (last_interface_poll + INTERFACE_POLL_FREQUENCY)) { | 
|  | 258 | last_interface_poll = now; | 
| Maciej Żenczykowski | ba667df | 2020-06-02 01:41:54 -0700 | [diff] [blame] | 259 | if (ipv6_address_changed(Global_Clatd_Config.native_ipv6_interface)) { | 
| Lorenzo Colitti | 66deecd | 2019-01-04 12:27:27 +0900 | [diff] [blame] | 260 | break; | 
|  | 261 | } | 
| Daniel Drown | a45056e | 2012-03-23 10:42:54 -0500 | [diff] [blame] | 262 | } | 
|  | 263 | } | 
|  | 264 | } |