* SSU: "rectify" IPv4/v6 MTUs differently due to different header size (mod 16)

* Penalize addresses w/o IP in sort
This commit is contained in:
zzz
2013-05-21 21:10:23 +00:00
parent c0350702fd
commit 9a4cd11748
6 changed files with 31 additions and 12 deletions

View File

@ -614,9 +614,13 @@ public abstract class TransportImpl implements Transport {
int rc = r.getCost();
byte[] lip = l.getIP();
byte[] rip = r.getIP();
if (lip != null && lip.length == 16)
if (lip == null)
lc += 20;
else if (lip.length == 16)
lc += adj;
if (rip != null && rip.length == 16)
if (rip == null)
rc += 20;
else if (rip.length == 16)
rc += adj;
if (lc > rc)
return 1;

View File

@ -677,7 +677,8 @@ class EstablishmentManager {
String smtu = addr.getOption(UDPAddress.PROP_MTU);
if (smtu != null) {
try {
int mtu = MTU.rectify(Integer.parseInt(smtu));
boolean isIPv6 = state.getSentIP().length == 16;
int mtu = MTU.rectify(isIPv6, Integer.parseInt(smtu));
peer.setHisMTU(mtu);
} catch (NumberFormatException nfe) {}
}

View File

@ -1,6 +1,7 @@
package net.i2p.router.transport.udp;
import java.net.InetAddress;
import java.net.Inet6Address;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Enumeration;
@ -41,7 +42,8 @@ abstract class MTU {
try {
// testing
//return ifc.getMTU();
return rectify(ifc.getMTU());
boolean isIPv6 = addr instanceof Inet6Address;
return rectify(isIPv6, ifc.getMTU());
} catch (SocketException se) {
// ignore
} catch (Throwable t) {
@ -58,11 +60,16 @@ abstract class MTU {
/**
* @return min of PeerState.MIN_MTU, max of PeerState.LARGE_MTU,
* rectified so rv % 16 == 12
* rectified so rv % 16 == 12 (IPv4)
* or rv % 16 == 0 (IPv6)
*/
public static int rectify(int mtu) {
public static int rectify(boolean isIPv6, int mtu) {
int rv = mtu;
int mod = rv % 16;
if (isIPv6) {
rv -= mod;
return Math.max(PeerState.MIN_IPV6_MTU, Math.min(PeerState.MAX_IPV6_MTU, rv));
}
if (mod > 12)
rv -= mod - 12;
else if (mod < 12)

View File

@ -267,8 +267,12 @@ class PeerState {
* and so PacketBuilder.buildPacket() works correctly.
*/
public static final int MIN_MTU = 620;
/** 1276 */
public static final int MIN_IPV6_MTU = MTU.rectify(1280);
/**
* IPv6/UDP header is 48 bytes, so we want MTU % 16 == 0.
*/
public static final int MIN_IPV6_MTU = 1280;
public static final int MAX_IPV6_MTU = 1472; // TODO 1488
private static final int DEFAULT_MTU = MIN_MTU;
/*

View File

@ -67,8 +67,10 @@ class UDPAddress {
_port = addr.getPort();
try {
String mtu = addr.getOption(PROP_MTU);
if (mtu != null)
_mtu = MTU.rectify(Integer.parseInt(mtu));
if (mtu != null) {
boolean isIPv6 = _host != null && _host.contains(":");
_mtu = MTU.rectify(isIPv6, Integer.parseInt(mtu));
}
} catch (NumberFormatException nfe) {}
String key = addr.getOption(PROP_INTRO_KEY);
if (key != null) {

View File

@ -587,8 +587,9 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
String p = _context.getProperty(PROP_DEFAULT_MTU);
if (p != null) {
try {
_mtu = MTU.rectify(Integer.parseInt(p));
_mtu_ipv6 = Math.max(_mtu, PeerState.MIN_IPV6_MTU);
int pmtu = Integer.parseInt(p);
_mtu = MTU.rectify(false, pmtu);
_mtu_ipv6 = MTU.rectify(true, pmtu);
return _mtu;
} catch (NumberFormatException nfe) {}
}