Changeset 177e0ae6


Ignore:
Timestamp:
Sep 16, 2005 9:24:42 PM (15 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
d6c3ffd
Parents:
dab1b4d
git-author:
jrandom <jrandom> (09/16/05 21:24:42)
git-committer:
zzz <zzz@…> (09/16/05 21:24:42)
Message:

2005-09-16 jrandom

  • Reject unroutable IPs in SSU like we do for the TCP transport (unless you have i2np.udp.allowLocal=true defined - useful for private nets)
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • history.txt

    rdab1b4d r177e0ae6  
    1 $Id: history.txt,v 1.251 2005/09/15 23:12:27 jrandom Exp $
     1$Id: history.txt,v 1.252 2005/09/16 13:28:27 jrandom Exp $
     2
     32005-09-16  jrandom
     4    * Reject unroutable IPs in SSU like we do for the TCP transport (unless
     5      you have i2np.udp.allowLocal=true defined - useful for private nets)
    26
    372005-09-16  jrandom
  • router/java/src/net/i2p/router/RouterVersion.java

    rdab1b4d r177e0ae6  
    1616 */
    1717public class RouterVersion {
    18     public final static String ID = "$Revision: 1.237 $ $Date: 2005/09/15 23:12:26 $";
     18    public final static String ID = "$Revision: 1.238 $ $Date: 2005/09/16 13:28:26 $";
    1919    public final static String VERSION = "0.6.0.5";
    20     public final static long BUILD = 12;
     20    public final static long BUILD = 13;
    2121    public static void main(String args[]) {
    2222        System.out.println("I2P Router version: " + VERSION + "-" + BUILD);
  • router/java/src/net/i2p/router/transport/TransportImpl.java

    rdab1b4d r177e0ae6  
    356356    public void recheckReachability() {}
    357357
     358    public static boolean isPubliclyRoutable(byte addr[]) {
     359        if (addr[0] == (int)127) return false;
     360        if (addr[0] == (int)10) return false;
     361        if ( (addr[0] == (int)172) && (addr[1] >= (int)16) && (addr[1] <= (int)31) ) return false;
     362        if ( (addr[0] == (int)192) && (addr[1] == (int)168) ) return false;
     363        if (addr[0] >= (int)224) return false; // no multicast
     364        return true; // or at least possible to be true
     365    }
    358366}
  • router/java/src/net/i2p/router/transport/tcp/TCPAddress.java

    rdab1b4d r177e0ae6  
    1515import net.i2p.data.DataHelper;
    1616import net.i2p.data.RouterAddress;
     17import net.i2p.router.transport.TransportImpl;
    1718import net.i2p.util.Log;
    1819
     
    133134                return false;
    134135            }
    135             if (quad[0] == (int)127) return false;
    136             if (quad[0] == (int)10) return false;
    137             if ( (quad[0] == (int)172) && (quad[1] >= (int)16) && (quad[1] <= (int)31) ) return false;
    138             if ( (quad[0] == (int)192) && (quad[1] == (int)168) ) return false;
    139             if (quad[0] >= (int)224) return false; // no multicast
    140             return true; // or at least possible to be true
     136            return TransportImpl.isPubliclyRoutable(quad);
    141137        } catch (Throwable t) {
    142138            if (_log.shouldLog(Log.WARN))
  • router/java/src/net/i2p/router/transport/udp/EstablishmentManager.java

    rdab1b4d r177e0ae6  
    129129        RemoteHostId to = new RemoteHostId(remAddr.getAddress(), port);
    130130       
     131        if (!_transport.isValid(to.getIP())) {
     132            _transport.failed(msg);
     133            return;
     134        }
     135       
    131136        if (_log.shouldLog(Log.DEBUG))
    132137            _log.debug("Add outobund establish state to: " + to);
     
    166171     */
    167172    void receiveSessionRequest(RemoteHostId from, UDPPacketReader reader) {
     173        if (!_transport.isValid(from.getIP()))
     174            return;
     175       
    168176        boolean isNew = false;
    169177        InboundEstablishState state = null;
     
    446454        state.setIntroNonce(nonce);
    447455        _context.statManager().addRateData("udp.sendIntroRelayRequest", 1, 0);
    448         _transport.send(_builder.buildRelayRequest(state, _transport.getIntroKey()));
     456        _transport.send(_builder.buildRelayRequest(_transport, state, _transport.getIntroKey()));
    449457        if (_log.shouldLog(Log.DEBUG))
    450458            _log.debug("Send intro for " + state.getRemoteHostId().toString() + " with our intro key as " + _transport.getIntroKey().toBase64());
  • router/java/src/net/i2p/router/transport/udp/InboundEstablishState.java

    rdab1b4d r177e0ae6  
    121121    public synchronized int getSentPort() { return _alicePort; }
    122122   
     123    public synchronized byte[] getBobIP() { return _bobIP; }
     124   
    123125    public synchronized byte[] getSentY() {
    124126        if (_sentY == null)
  • router/java/src/net/i2p/router/transport/udp/PacketBuilder.java

    rdab1b4d r177e0ae6  
    640640    private int getOurExplicitPort() { return 0; }
    641641   
    642     public UDPPacket buildRelayRequest(OutboundEstablishState state, SessionKey ourIntroKey) {
     642    public UDPPacket buildRelayRequest(UDPTransport transport, OutboundEstablishState state, SessionKey ourIntroKey) {
    643643        UDPAddress addr = state.getRemoteAddress();
    644644        int count = addr.getIntroducerCount();
     
    646646            return null;
    647647        int index = _context.random().nextInt(count);
    648         InetAddress iaddr = addr.getIntroducerHost(index);
    649         int iport = addr.getIntroducerPort(index);
    650         byte ikey[] = addr.getIntroducerKey(index);
    651         long tag = addr.getIntroducerTag(index);
    652         if ( (ikey == null) || (iport <= 0) || (iaddr == null) || (tag <= 0) ) {
    653             if (_log.shouldLog(_log.ERROR))
    654                 _log.error("Cannot build a relay request to " + state.getRemoteIdentity().calculateHash().toBase64()
    655                            + ", as their UDP address is invalid: addr=" + addr + " index=" + index);
    656             return null;
    657         }
    658         return buildRelayRequest(iaddr, iport, ikey, tag, ourIntroKey, state.getIntroNonce(), true);
     648        for (int i = 0; i < count; i++) {
     649            int cur = (i + index) % count;
     650            InetAddress iaddr = addr.getIntroducerHost(cur);
     651            int iport = addr.getIntroducerPort(cur);
     652            byte ikey[] = addr.getIntroducerKey(cur);
     653            long tag = addr.getIntroducerTag(cur);
     654            if ( (ikey == null) || (iport <= 0) || (iaddr == null) || (tag <= 0) ) {
     655                if (_log.shouldLog(_log.WARN))
     656                    _log.warn("Cannot build a relay request to " + state.getRemoteIdentity().calculateHash().toBase64()
     657                               + ", as their UDP address is invalid: addr=" + addr + " index=" + cur);
     658                continue;
     659            }
     660            if (transport.isValid(iaddr.getAddress()))
     661                return buildRelayRequest(iaddr, iport, ikey, tag, ourIntroKey, state.getIntroNonce(), true);
     662        }
     663        return null;
    659664    }
    660665   
  • router/java/src/net/i2p/router/transport/udp/UDPTransport.java

    rdab1b4d r177e0ae6  
    289289            if ( (_externalListenHost == null) ||
    290290                 (!eq(_externalListenHost.getAddress(), _externalListenPort, ourIP, ourPort)) ) {
    291                 if ( (_reachabilityStatus == CommSystemFacade.STATUS_UNKNOWN) ||
     291                if (!isValid(ourIP)) {
     292                    // ignore them
     293                } else if ( (_reachabilityStatus == CommSystemFacade.STATUS_UNKNOWN) ||
    292294                     (_context.clock().now() - _reachabilityStatusLastUpdated > 2*TEST_FREQUENCY) ) {
    293295                    // they told us something different and our tests are either old or failing
     
    329331    private static final boolean eq(byte laddr[], int lport, byte raddr[], int rport) {
    330332        return (rport == lport) && DataHelper.eq(laddr, raddr);
     333    }
     334   
     335    public final boolean isValid(byte addr[]) {
     336        if (addr == null) return false;
     337        if (addr.length < 4) return false;
     338        if (isPubliclyRoutable(addr))
     339            return true;
     340        return Boolean.valueOf(_context.getProperty("i2np.udp.allowLocal", "false")).booleanValue();
    331341    }
    332342   
Note: See TracChangeset for help on using the changeset viewer.