Skip to content

Commit 0dbaee3

Browse files
committed
net: Abstract default ADVMSS behind an accessor.
Make all RTAX_ADVMSS metric accesses go through a new helper function, dst_metric_advmss(). Leave the actual default metric as "zero" in the real metric slot, and compute the actual default value dynamically via a new dst_ops AF specific callback. For stacked IPSEC routes, we use the advmss of the path which preserves existing behavior. Unlike ipv4/ipv6, DecNET ties the advmss to the mtu and thus updates advmss on pmtu updates. This inconsistency in advmss handling results in more raw metric accesses than I wish we ended up with. Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent cc6f02d commit 0dbaee3

File tree

11 files changed

+75
-33
lines changed

11 files changed

+75
-33
lines changed

drivers/scsi/cxgbi/libcxgbi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,7 @@ unsigned int cxgbi_sock_select_mss(struct cxgbi_sock *csk, unsigned int pmtu)
825825
unsigned int idx;
826826
struct dst_entry *dst = csk->dst;
827827

828-
csk->advmss = dst_metric(dst, RTAX_ADVMSS);
828+
csk->advmss = dst_metric_advmss(dst);
829829

830830
if (csk->advmss > pmtu - 40)
831831
csk->advmss = pmtu - 40;

include/net/dst.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,22 @@ dst_metric_raw(const struct dst_entry *dst, const int metric)
112112
static inline u32
113113
dst_metric(const struct dst_entry *dst, const int metric)
114114
{
115-
WARN_ON_ONCE(metric == RTAX_HOPLIMIT);
115+
WARN_ON_ONCE(metric == RTAX_HOPLIMIT ||
116+
metric == RTAX_ADVMSS);
116117
return dst_metric_raw(dst, metric);
117118
}
118119

120+
static inline u32
121+
dst_metric_advmss(const struct dst_entry *dst)
122+
{
123+
u32 advmss = dst_metric_raw(dst, RTAX_ADVMSS);
124+
125+
if (!advmss)
126+
advmss = dst->ops->default_advmss(dst);
127+
128+
return advmss;
129+
}
130+
119131
static inline void dst_metric_set(struct dst_entry *dst, int metric, u32 val)
120132
{
121133
dst->_metrics[metric-1] = val;

include/net/dst_ops.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ struct dst_ops {
1616

1717
int (*gc)(struct dst_ops *ops);
1818
struct dst_entry * (*check)(struct dst_entry *, __u32 cookie);
19+
unsigned int (*default_advmss)(const struct dst_entry *);
1920
void (*destroy)(struct dst_entry *);
2021
void (*ifdown)(struct dst_entry *,
2122
struct net_device *dev, int how);

net/decnet/af_decnet.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,7 @@ static int dn_confirm_accept(struct sock *sk, long *timeo, gfp_t allocation)
829829
return -EINVAL;
830830

831831
scp->state = DN_CC;
832-
scp->segsize_loc = dst_metric(__sk_dst_get(sk), RTAX_ADVMSS);
832+
scp->segsize_loc = dst_metric_advmss(__sk_dst_get(sk));
833833
dn_send_conn_conf(sk, allocation);
834834

835835
prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);
@@ -958,7 +958,7 @@ static int __dn_connect(struct sock *sk, struct sockaddr_dn *addr, int addrlen,
958958
sk->sk_route_caps = sk->sk_dst_cache->dev->features;
959959
sock->state = SS_CONNECTING;
960960
scp->state = DN_CI;
961-
scp->segsize_loc = dst_metric(sk->sk_dst_cache, RTAX_ADVMSS);
961+
scp->segsize_loc = dst_metric_advmss(sk->sk_dst_cache);
962962

963963
dn_nsp_send_conninit(sk, NSP_CI);
964964
err = -EINPROGRESS;

net/decnet/dn_route.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ static unsigned long dn_rt_deadline;
110110

111111
static int dn_dst_gc(struct dst_ops *ops);
112112
static struct dst_entry *dn_dst_check(struct dst_entry *, __u32);
113+
static unsigned int dn_dst_default_advmss(const struct dst_entry *dst);
113114
static struct dst_entry *dn_dst_negative_advice(struct dst_entry *);
114115
static void dn_dst_link_failure(struct sk_buff *);
115116
static void dn_dst_update_pmtu(struct dst_entry *dst, u32 mtu);
@@ -129,6 +130,7 @@ static struct dst_ops dn_dst_ops = {
129130
.gc_thresh = 128,
130131
.gc = dn_dst_gc,
131132
.check = dn_dst_check,
133+
.default_advmss = dn_dst_default_advmss,
132134
.negative_advice = dn_dst_negative_advice,
133135
.link_failure = dn_dst_link_failure,
134136
.update_pmtu = dn_dst_update_pmtu,
@@ -245,7 +247,8 @@ static void dn_dst_update_pmtu(struct dst_entry *dst, u32 mtu)
245247
}
246248
if (!(dst_metric_locked(dst, RTAX_ADVMSS))) {
247249
u32 mss = mtu - DN_MAX_NSP_DATA_HEADER;
248-
if (dst_metric(dst, RTAX_ADVMSS) > mss)
250+
u32 existing_mss = dst_metric_raw(dst, RTAX_ADVMSS);
251+
if (!existing_mss || existing_mss > mss)
249252
dst_metric_set(dst, RTAX_ADVMSS, mss);
250253
}
251254
}
@@ -795,12 +798,17 @@ static int dn_rt_bug(struct sk_buff *skb)
795798
return NET_RX_DROP;
796799
}
797800

801+
static unsigned int dn_dst_default_advmss(const struct dst_entry *dst)
802+
{
803+
return dn_mss_from_pmtu(dst->dev, dst_mtu(dst));
804+
}
805+
798806
static int dn_rt_set_next_hop(struct dn_route *rt, struct dn_fib_res *res)
799807
{
800808
struct dn_fib_info *fi = res->fi;
801809
struct net_device *dev = rt->dst.dev;
802810
struct neighbour *n;
803-
unsigned mss;
811+
unsigned int metric;
804812

805813
if (fi) {
806814
if (DN_FIB_RES_GW(*res) &&
@@ -820,10 +828,12 @@ static int dn_rt_set_next_hop(struct dn_route *rt, struct dn_fib_res *res)
820828
if (dst_metric(&rt->dst, RTAX_MTU) == 0 ||
821829
dst_metric(&rt->dst, RTAX_MTU) > rt->dst.dev->mtu)
822830
dst_metric_set(&rt->dst, RTAX_MTU, rt->dst.dev->mtu);
823-
mss = dn_mss_from_pmtu(dev, dst_mtu(&rt->dst));
824-
if (dst_metric(&rt->dst, RTAX_ADVMSS) == 0 ||
825-
dst_metric(&rt->dst, RTAX_ADVMSS) > mss)
826-
dst_metric_set(&rt->dst, RTAX_ADVMSS, mss);
831+
metric = dst_metric_raw(&rt->dst, RTAX_ADVMSS);
832+
if (metric) {
833+
unsigned int mss = dn_mss_from_pmtu(dev, dst_mtu(&rt->dst));
834+
if (metric > mss)
835+
dst_metric_set(&rt->dst, RTAX_ADVMSS, mss);
836+
}
827837
return 0;
828838
}
829839

net/ipv4/route.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ static unsigned long expires_ljiffies;
139139
*/
140140

141141
static struct dst_entry *ipv4_dst_check(struct dst_entry *dst, u32 cookie);
142+
static unsigned int ipv4_default_advmss(const struct dst_entry *dst);
142143
static void ipv4_dst_destroy(struct dst_entry *dst);
143144
static struct dst_entry *ipv4_negative_advice(struct dst_entry *dst);
144145
static void ipv4_link_failure(struct sk_buff *skb);
@@ -155,6 +156,7 @@ static struct dst_ops ipv4_dst_ops = {
155156
.protocol = cpu_to_be16(ETH_P_IP),
156157
.gc = rt_garbage_collect,
157158
.check = ipv4_dst_check,
159+
.default_advmss = ipv4_default_advmss,
158160
.destroy = ipv4_dst_destroy,
159161
.ifdown = ipv4_dst_ifdown,
160162
.negative_advice = ipv4_negative_advice,
@@ -383,8 +385,7 @@ static int rt_cache_seq_show(struct seq_file *seq, void *v)
383385
(__force u32)r->rt_gateway,
384386
r->rt_flags, atomic_read(&r->dst.__refcnt),
385387
r->dst.__use, 0, (__force u32)r->rt_src,
386-
(dst_metric(&r->dst, RTAX_ADVMSS) ?
387-
(int)dst_metric(&r->dst, RTAX_ADVMSS) + 40 : 0),
388+
dst_metric_advmss(&r->dst) + 40,
388389
dst_metric(&r->dst, RTAX_WINDOW),
389390
(int)((dst_metric(&r->dst, RTAX_RTT) >> 3) +
390391
dst_metric(&r->dst, RTAX_RTTVAR)),
@@ -1798,6 +1799,19 @@ static void set_class_tag(struct rtable *rt, u32 tag)
17981799
}
17991800
#endif
18001801

1802+
static unsigned int ipv4_default_advmss(const struct dst_entry *dst)
1803+
{
1804+
unsigned int advmss = dst_metric_raw(dst, RTAX_ADVMSS);
1805+
1806+
if (advmss == 0) {
1807+
advmss = max_t(unsigned int, dst->dev->mtu - 40,
1808+
ip_rt_min_advmss);
1809+
if (advmss > 65535 - 40)
1810+
advmss = 65535 - 40;
1811+
}
1812+
return advmss;
1813+
}
1814+
18011815
static void rt_set_nexthop(struct rtable *rt, struct fib_result *res, u32 itag)
18021816
{
18031817
struct dst_entry *dst = &rt->dst;
@@ -1823,11 +1837,7 @@ static void rt_set_nexthop(struct rtable *rt, struct fib_result *res, u32 itag)
18231837

18241838
if (dst_mtu(dst) > IP_MAX_MTU)
18251839
dst_metric_set(dst, RTAX_MTU, IP_MAX_MTU);
1826-
if (dst_metric(dst, RTAX_ADVMSS) == 0)
1827-
dst_metric_set(dst, RTAX_ADVMSS,
1828-
max_t(unsigned int, dst->dev->mtu - 40,
1829-
ip_rt_min_advmss));
1830-
if (dst_metric(dst, RTAX_ADVMSS) > 65535 - 40)
1840+
if (dst_metric_raw(dst, RTAX_ADVMSS) > 65535 - 40)
18311841
dst_metric_set(dst, RTAX_ADVMSS, 65535 - 40);
18321842

18331843
#ifdef CONFIG_NET_CLS_ROUTE

net/ipv4/tcp_ipv4.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1436,7 +1436,7 @@ struct sock *tcp_v4_syn_recv_sock(struct sock *sk, struct sk_buff *skb,
14361436

14371437
tcp_mtup_init(newsk);
14381438
tcp_sync_mss(newsk, dst_mtu(dst));
1439-
newtp->advmss = dst_metric(dst, RTAX_ADVMSS);
1439+
newtp->advmss = dst_metric_advmss(dst);
14401440
if (tcp_sk(sk)->rx_opt.user_mss &&
14411441
tcp_sk(sk)->rx_opt.user_mss < newtp->advmss)
14421442
newtp->advmss = tcp_sk(sk)->rx_opt.user_mss;

net/ipv4/tcp_output.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,13 @@ static __u16 tcp_advertise_mss(struct sock *sk)
119119
struct dst_entry *dst = __sk_dst_get(sk);
120120
int mss = tp->advmss;
121121

122-
if (dst && dst_metric(dst, RTAX_ADVMSS) < mss) {
123-
mss = dst_metric(dst, RTAX_ADVMSS);
124-
tp->advmss = mss;
122+
if (dst) {
123+
unsigned int metric = dst_metric_advmss(dst);
124+
125+
if (metric < mss) {
126+
mss = metric;
127+
tp->advmss = mss;
128+
}
125129
}
126130

127131
return (__u16)mss;
@@ -2422,7 +2426,7 @@ struct sk_buff *tcp_make_synack(struct sock *sk, struct dst_entry *dst,
24222426

24232427
skb_dst_set(skb, dst_clone(dst));
24242428

2425-
mss = dst_metric(dst, RTAX_ADVMSS);
2429+
mss = dst_metric_advmss(dst);
24262430
if (tp->rx_opt.user_mss && tp->rx_opt.user_mss < mss)
24272431
mss = tp->rx_opt.user_mss;
24282432

@@ -2556,7 +2560,7 @@ static void tcp_connect_init(struct sock *sk)
25562560

25572561
if (!tp->window_clamp)
25582562
tp->window_clamp = dst_metric(dst, RTAX_WINDOW);
2559-
tp->advmss = dst_metric(dst, RTAX_ADVMSS);
2563+
tp->advmss = dst_metric_advmss(dst);
25602564
if (tp->rx_opt.user_mss && tp->rx_opt.user_mss < tp->advmss)
25612565
tp->advmss = tp->rx_opt.user_mss;
25622566

net/ipv6/route.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676

7777
static struct rt6_info * ip6_rt_copy(struct rt6_info *ort);
7878
static struct dst_entry *ip6_dst_check(struct dst_entry *dst, u32 cookie);
79+
static unsigned int ip6_default_advmss(const struct dst_entry *dst);
7980
static struct dst_entry *ip6_negative_advice(struct dst_entry *);
8081
static void ip6_dst_destroy(struct dst_entry *);
8182
static void ip6_dst_ifdown(struct dst_entry *,
@@ -103,6 +104,7 @@ static struct dst_ops ip6_dst_ops_template = {
103104
.gc = ip6_dst_gc,
104105
.gc_thresh = 1024,
105106
.check = ip6_dst_check,
107+
.default_advmss = ip6_default_advmss,
106108
.destroy = ip6_dst_destroy,
107109
.ifdown = ip6_dst_ifdown,
108110
.negative_advice = ip6_negative_advice,
@@ -937,8 +939,12 @@ static void ip6_rt_update_pmtu(struct dst_entry *dst, u32 mtu)
937939

938940
static int ipv6_get_mtu(struct net_device *dev);
939941

940-
static inline unsigned int ipv6_advmss(struct net *net, unsigned int mtu)
942+
static unsigned int ip6_default_advmss(const struct dst_entry *dst)
941943
{
944+
struct net_device *dev = dst->dev;
945+
unsigned int mtu = dst_mtu(dst);
946+
struct net *net = dev_net(dev);
947+
942948
mtu -= sizeof(struct ipv6hdr) + sizeof(struct tcphdr);
943949

944950
if (mtu < net->ipv6.sysctl.ip6_rt_min_advmss)
@@ -990,7 +996,6 @@ struct dst_entry *icmp6_dst_alloc(struct net_device *dev,
990996
atomic_set(&rt->dst.__refcnt, 1);
991997
dst_metric_set(&rt->dst, RTAX_HOPLIMIT, 255);
992998
dst_metric_set(&rt->dst, RTAX_MTU, ipv6_get_mtu(rt->rt6i_dev));
993-
dst_metric_set(&rt->dst, RTAX_ADVMSS, ipv6_advmss(net, dst_mtu(&rt->dst)));
994999
rt->dst.output = ip6_output;
9951000

9961001
#if 0 /* there's no chance to use these for ndisc */
@@ -1312,8 +1317,6 @@ int ip6_route_add(struct fib6_config *cfg)
13121317

13131318
if (!dst_mtu(&rt->dst))
13141319
dst_metric_set(&rt->dst, RTAX_MTU, ipv6_get_mtu(dev));
1315-
if (!dst_metric(&rt->dst, RTAX_ADVMSS))
1316-
dst_metric_set(&rt->dst, RTAX_ADVMSS, ipv6_advmss(net, dst_mtu(&rt->dst)));
13171320
rt->dst.dev = dev;
13181321
rt->rt6i_idev = idev;
13191322
rt->rt6i_table = table;
@@ -1540,8 +1543,6 @@ void rt6_redirect(struct in6_addr *dest, struct in6_addr *src,
15401543
nrt->rt6i_nexthop = neigh_clone(neigh);
15411544
/* Reset pmtu, it may be better */
15421545
dst_metric_set(&nrt->dst, RTAX_MTU, ipv6_get_mtu(neigh->dev));
1543-
dst_metric_set(&nrt->dst, RTAX_ADVMSS, ipv6_advmss(dev_net(neigh->dev),
1544-
dst_mtu(&nrt->dst)));
15451546

15461547
if (ip6_ins_rt(nrt))
15471548
goto out;
@@ -1971,7 +1972,6 @@ struct rt6_info *addrconf_dst_alloc(struct inet6_dev *idev,
19711972
rt->rt6i_dev = net->loopback_dev;
19721973
rt->rt6i_idev = idev;
19731974
dst_metric_set(&rt->dst, RTAX_MTU, ipv6_get_mtu(rt->rt6i_dev));
1974-
dst_metric_set(&rt->dst, RTAX_ADVMSS, ipv6_advmss(net, dst_mtu(&rt->dst)));
19751975
dst_metric_set(&rt->dst, RTAX_HOPLIMIT, -1);
19761976
rt->dst.obsolete = -1;
19771977

@@ -2041,7 +2041,6 @@ static int rt6_mtu_change_route(struct rt6_info *rt, void *p_arg)
20412041
{
20422042
struct rt6_mtu_change_arg *arg = (struct rt6_mtu_change_arg *) p_arg;
20432043
struct inet6_dev *idev;
2044-
struct net *net = dev_net(arg->dev);
20452044

20462045
/* In IPv6 pmtu discovery is not optional,
20472046
so that RTAX_MTU lock cannot disable it.
@@ -2073,7 +2072,6 @@ static int rt6_mtu_change_route(struct rt6_info *rt, void *p_arg)
20732072
(dst_mtu(&rt->dst) < arg->mtu &&
20742073
dst_mtu(&rt->dst) == idev->cnf.mtu6))) {
20752074
dst_metric_set(&rt->dst, RTAX_MTU, arg->mtu);
2076-
dst_metric_set(&rt->dst, RTAX_ADVMSS, ipv6_advmss(net, arg->mtu));
20772075
}
20782076
return 0;
20792077
}

net/ipv6/tcp_ipv6.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1521,7 +1521,7 @@ static struct sock * tcp_v6_syn_recv_sock(struct sock *sk, struct sk_buff *skb,
15211521

15221522
tcp_mtup_init(newsk);
15231523
tcp_sync_mss(newsk, dst_mtu(dst));
1524-
newtp->advmss = dst_metric(dst, RTAX_ADVMSS);
1524+
newtp->advmss = dst_metric_advmss(dst);
15251525
tcp_initialize_rcv_mss(newsk);
15261526

15271527
newinet->inet_daddr = newinet->inet_saddr = LOOPBACK4_IPV6;

net/xfrm/xfrm_policy.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2361,6 +2361,11 @@ static int xfrm_bundle_ok(struct xfrm_policy *pol, struct xfrm_dst *first,
23612361
return 1;
23622362
}
23632363

2364+
static unsigned int xfrm_default_advmss(const struct dst_entry *dst)
2365+
{
2366+
return dst_metric_advmss(dst->path);
2367+
}
2368+
23642369
int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo)
23652370
{
23662371
struct net *net;
@@ -2378,6 +2383,8 @@ int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo)
23782383
dst_ops->kmem_cachep = xfrm_dst_cache;
23792384
if (likely(dst_ops->check == NULL))
23802385
dst_ops->check = xfrm_dst_check;
2386+
if (likely(dst_ops->default_advmss == NULL))
2387+
dst_ops->default_advmss = xfrm_default_advmss;
23812388
if (likely(dst_ops->negative_advice == NULL))
23822389
dst_ops->negative_advice = xfrm_negative_advice;
23832390
if (likely(dst_ops->link_failure == NULL))

0 commit comments

Comments
 (0)