aboutsummaryrefslogtreecommitdiffstats
path: root/net/xfrm/xfrm_state.c
diff options
context:
space:
mode:
authorPatrick McHardy <kaber@trash.net>2007-04-09 14:47:18 -0400
committerDavid S. Miller <davem@sunset.davemloft.net>2007-04-26 01:28:38 -0400
commitc5c2523893747f88a83376abad310c8ad13f7197 (patch)
tree58f1ab25ac9f7ca7460abbd24e9bab9c8683f6fd /net/xfrm/xfrm_state.c
parent557922584d9c5b6b990bcfb2fec3134f0e73a05d (diff)
[XFRM]: Optimize MTU calculation
Replace the probing based MTU estimation, which usually takes 2-3 iterations to find a fitting value and may underestimate the MTU, by an exact calculation. Also fix underestimation of the XFRM trailer_len, which causes unnecessary reallocations. Signed-off-by: Patrick McHardy <kaber@trash.net> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/xfrm/xfrm_state.c')
-rw-r--r--net/xfrm/xfrm_state.c36
1 files changed, 8 insertions, 28 deletions
diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
index 63a20e818164..69a3600afd9d 100644
--- a/net/xfrm/xfrm_state.c
+++ b/net/xfrm/xfrm_state.c
@@ -1667,37 +1667,17 @@ void xfrm_state_delete_tunnel(struct xfrm_state *x)
1667} 1667}
1668EXPORT_SYMBOL(xfrm_state_delete_tunnel); 1668EXPORT_SYMBOL(xfrm_state_delete_tunnel);
1669 1669
1670/*
1671 * This function is NOT optimal. For example, with ESP it will give an
1672 * MTU that's usually two bytes short of being optimal. However, it will
1673 * usually give an answer that's a multiple of 4 provided the input is
1674 * also a multiple of 4.
1675 */
1676int xfrm_state_mtu(struct xfrm_state *x, int mtu) 1670int xfrm_state_mtu(struct xfrm_state *x, int mtu)
1677{ 1671{
1678 int res = mtu; 1672 int res;
1679
1680 res -= x->props.header_len;
1681
1682 for (;;) {
1683 int m = res;
1684
1685 if (m < 68)
1686 return 68;
1687
1688 spin_lock_bh(&x->lock);
1689 if (x->km.state == XFRM_STATE_VALID &&
1690 x->type && x->type->get_max_size)
1691 m = x->type->get_max_size(x, m);
1692 else
1693 m += x->props.header_len;
1694 spin_unlock_bh(&x->lock);
1695
1696 if (m <= mtu)
1697 break;
1698 res -= (m - mtu);
1699 }
1700 1673
1674 spin_lock_bh(&x->lock);
1675 if (x->km.state == XFRM_STATE_VALID &&
1676 x->type && x->type->get_mtu)
1677 res = x->type->get_mtu(x, mtu);
1678 else
1679 res = mtu;
1680 spin_unlock_bh(&x->lock);
1701 return res; 1681 return res;
1702} 1682}
1703 1683