Changeset cd775fa for router


Ignore:
Timestamp:
Nov 8, 2016 3:24:30 AM (4 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
b559b41
Parents:
ab064fd
Message:

Transport: Improve IPv6 selection logic
to skip temporary addresses on linux

File:
1 edited

Legend:

Unmodified
Added
Removed
  • router/java/src/net/i2p/router/transport/TransportManager.java

    rab064fd rcd775fa  
    1212import java.io.Writer;
    1313import java.net.InetAddress;
     14import java.net.Inet6Address;
    1415import java.net.UnknownHostException;
    1516import java.util.ArrayList;
     
    166167                int port = udp.getRequestedPort();
    167168                if (port > 0)
    168                     ntcp.externalAddressReceived(SOURCE_CONFIG, null, port);
     169                    ntcp.externalAddressReceived(SOURCE_CONFIG, (byte[]) null, port);
    169170            }
    170171        }
     
    183184    private void initializeAddress(Transport t) {
    184185        Set<String> ipset = Addresses.getAddresses(false, true);  // non-local, include IPv6
     186        //
     187        // Avoid IPv6 temporary addresses if we have a non-temporary one
     188        //
     189        boolean hasNonTempV6Address = false;
     190        List<InetAddress> addresses = new ArrayList<InetAddress>(4);
     191        List<Inet6Address> tempV6Addresses = new ArrayList<Inet6Address>(4);
    185192        for (String ips : ipset) {
    186193            try {
    187                 InetAddress ia = InetAddress.getByName(ips);
    188                 byte[] ip = ia.getAddress();
    189                 t.externalAddressReceived(SOURCE_INTERFACE, ip, 0);
     194                InetAddress addr = InetAddress.getByName(ips);
     195                if (ips.contains(":") && (addr instanceof Inet6Address)) {
     196                    Inet6Address v6addr = (Inet6Address) addr;
     197                    // getAddresses(false, true) will not return deprecated addresses
     198                    //if (Addresses.isDeprecated(v6addr)) {
     199                    //    if (_log.shouldWarn())
     200                    //        _log.warn("Not binding to deprecated temporary address " + bt);
     201                    //    continue;
     202                    //}
     203                    if (Addresses.isTemporary(v6addr)) {
     204                        // Save temporary addresses
     205                        // we only use these if we don't have a non-temporary adress
     206                        tempV6Addresses.add(v6addr);
     207                        continue;
     208                    }
     209                    hasNonTempV6Address = true;
     210                }
     211                addresses.add(addr);
    190212            } catch (UnknownHostException e) {
    191213                _log.error("UDP failed to bind to local address", e);
    192214            }
     215        }
     216        // we only use these if we don't have a non-temporary adress
     217        if (!tempV6Addresses.isEmpty()) {
     218            if (hasNonTempV6Address) {
     219                if (_log.shouldWarn()) {
     220                    for (Inet6Address addr : tempV6Addresses) {
     221                        _log.warn("Not binding to temporary address " + addr.getHostAddress());
     222                    }
     223                }
     224            } else {
     225                addresses.addAll(tempV6Addresses);
     226            }
     227        }
     228        for (InetAddress ia : addresses) {
     229            byte[] ip = ia.getAddress();
     230            t.externalAddressReceived(SOURCE_INTERFACE, ip, 0);
    193231        }
    194232    }
Note: See TracChangeset for help on using the changeset viewer.