net: Abstract away all dst_entry metrics accesses.
Subsystems (7)
David Miller
maintainerPATCH 1/1 net: Abstract away all dst_entry metrics accesses.
Use helper functions to hide all direct accesses, especially writes, to dst_entry metrics values.
This will allow us to:
1) More easily change how the metrics are stored.
2) Implement COW for metrics.
In particular this will help us put metrics into the inetpeer cache if that is what we end up doing. We can make the _metrics member a pointer instead of an array, initially have it point at the read-only metrics in the FIB, and then on the first set grab an inetpeer entry and point the _metrics member there.
--- include/net/dst.h | 26 +++++++++++++++-- net/bridge/br_device.c | 2 +- net/bridge/br_netfilter.c | 2 +- net/decnet/dn_route.c | 13 ++++----- net/ipv4/ip_gre.c | 2 +- net/ipv4/route.c | 55 ++++++++++++++++++++----------------- net/ipv4/tcp_input.c | 22 +++++++++------ net/ipv6/ndisc.c | 5 ++- net/ipv6/route.c | 66 +++++++++++++++++++++++++------------------- net/xfrm/xfrm_policy.c | 6 ++-- 10 files changed, 118 insertions(+), 81 deletions(-)
include/net/dst.h +23 -3
@@ -70,7 +70,7 @@ struct dst_entry {struct dst_ops *ops; -u32 metrics[RTAX_MAX ]; +u32 _metrics[RTAX_MAX ];#ifdef CONFIG_NET_CLS_ROUTE __u32 tclassid;
@@ -106,7 +106,27 @@ struct dst_entry {static inline u32 dst_metric (const struct dst_entry *dst,int metric) { -return dst->metrics[metric-1 ]; +return dst->_metrics[metric-1 ]; +} + +static inline void dst_metric_set (struct dst_entry *dst,int metric,u32 val) +{ + dst->_metrics[metric-1 ] = val; +} + +static inline void dst_import_metrics (struct dst_entry *dst,const u32 *src_metrics) +{ +memcpy (dst->_metrics, src_metrics,RTAX_MAX *sizeof (u32)); +} + +static inline void dst_copy_metrics (struct dst_entry *dest,const struct dst_entry *src) +{ +dst_import_metrics (dest, src->_metrics); +} + +static inline u32 *dst_metrics_ptr (struct dst_entry *dst) +{ +return dst->_metrics; } static inline u32
@@ -134,7 +154,7 @@ static inline unsigned long dst_metric_rtt(const struct dst_entry *dst, int metrstatic inline void set_dst_metric_rtt (struct dst_entry *dst,int metric,unsigned long rtt) { - dst->metrics[metric-1 ] =jiffies_to_msecs (rtt); +dst_metric_set (dst, metric,jiffies_to_msecs (rtt)); } static inline u32
net/bridge/br_device.c +1 -1
@@ -141,7 +141,7 @@ static int br_change_mtu(struct net_device *dev, int new_mtu)#ifdef CONFIG_BRIDGE_NETFILTER /* remember the MTU in the rtable for PMTU */ - br->fake_rtable.dst.metrics[RTAX_MTU -1 ] = new_mtu; +dst_metric_set (&br->fake_rtable.dst,RTAX_MTU , new_mtu);#endif return 0 ;
net/bridge/br_netfilter.c +1 -1
@@ -124,7 +124,7 @@ void br_netfilter_rtable_init(struct net_bridge *br)atomic_set (&rt->dst.__refcnt,1 ); rt->dst.dev = br->dev; rt->dst.path = &rt->dst; - rt->dst.metrics[RTAX_MTU -1 ] =1500 ; +dst_metric_set (&rt->dst,RTAX_MTU ,1500 ); rt->dst.flags =DST_NOXFRM ; rt->dst.ops = &fake_dst_ops; }
net/decnet/dn_route.c +6 -7
@@ -240,13 +240,13 @@ static void dn_dst_update_pmtu(struct dst_entry *dst, u32 mtu)if (dst_metric (dst,RTAX_MTU ) > mtu && mtu >= min_mtu) {if (!(dst_metric_locked (dst,RTAX_MTU ))) { - dst->metrics[RTAX_MTU -1 ] = mtu; +dst_metric_set (dst,RTAX_MTU , mtu);dst_set_expires (dst, dn_rt_mtu_expires); }if (!(dst_metric_locked (dst,RTAX_ADVMSS ))) {u32 mss = mtu -DN_MAX_NSP_DATA_HEADER ;if (dst_metric (dst,RTAX_ADVMSS ) > mss) - dst->metrics[RTAX_ADVMSS -1 ] = mss; +dst_metric_set (dst,RTAX_ADVMSS , mss); } } }
@@ -806,8 +806,7 @@ static int dn_rt_set_next_hop(struct dn_route *rt, struct dn_fib_res *res)if (DN_FIB_RES_GW (*res) &&DN_FIB_RES_NH (*res).nh_scope ==RT_SCOPE_LINK ) rt->rt_gateway =DN_FIB_RES_GW (*res); -memcpy (rt->dst.metrics, fi->fib_metrics, -sizeof (rt->dst.metrics)); +dst_import_metrics (&rt->dst, fi->fib_metrics); } rt->rt_type = res->type;
@@ -820,11 +819,11 @@ static int dn_rt_set_next_hop(struct dn_route *rt, struct dn_fib_res *res)if (dst_metric (&rt->dst,RTAX_MTU ) ==0 ||dst_metric (&rt->dst,RTAX_MTU ) > rt->dst.dev->mtu) - rt->dst.metrics[RTAX_MTU -1 ] = rt->dst.dev->mtu; +dst_metric_set (&rt->dst,RTAX_MTU , rt->dst.dev->mtu); mss =dn_mss_from_pmtu (dev,dst_mtu (&rt->dst));if (dst_metric (&rt->dst,RTAX_ADVMSS ) ==0 ||dst_metric (&rt->dst,RTAX_ADVMSS ) > mss) - rt->dst.metrics[RTAX_ADVMSS -1 ] = mss; +dst_metric_set (&rt->dst,RTAX_ADVMSS , mss);return 0 ; }
@@ -1502,7 +1501,7 @@ static int dn_rt_fill_info(struct sk_buff *skb, u32 pid, u32 seq,RTA_PUT (skb,RTA_PREFSRC ,2 , &rt->rt_local_src);if (rt->rt_daddr != rt->rt_gateway)RTA_PUT (skb,RTA_GATEWAY ,2 , &rt->rt_gateway); -if (rtnetlink_put_metrics (skb, rt->dst.metrics) <0 ) +if (rtnetlink_put_metrics (skb,dst_metrics_ptr (&rt->dst)) <0 ) goto rtattr_failure; expires = rt->dst.expires ? rt->dst.expires - jiffies :0 ; if (rtnl_put_cacheinfo(skb, &rt->dst, 0, 0, 0, expires,
net/ipv4/ip_gre.c +1 -1
@@ -818,7 +818,7 @@ static netdev_tx_t ipgre_tunnel_xmit(struct sk_buff *skb, struct net_device *dev !ipv4_is_multicast(tunnel->parms.iph.daddr)) || rt6->rt6i_dst.plen == 128) { rt6->rt6i_flags |=RTF_MODIFIED ; -skb_dst (skb)->metrics[RTAX_MTU -1 ] = mtu; +dst_metric_set (skb_dst (skb),RTAX_MTU , mtu); } }
net/ipv4/route.c +30 -25
101 lines not on this page · raw message
net/ipv4/tcp_input.c +13 -9
@@ -734,7 +734,7 @@ void tcp_update_metrics(struct sock *sk)* Reset our results. */ if (!(dst_metric_locked (dst,RTAX_RTT ))) - dst->metrics[RTAX_RTT -1 ] =0 ; +dst_metric_set (dst,RTAX_RTT ,0 );return ; }
@@ -776,34 +776,38 @@ void tcp_update_metrics(struct sock *sk)if (dst_metric (dst,RTAX_SSTHRESH ) && !dst_metric_locked (dst,RTAX_SSTHRESH ) && (tp->snd_cwnd >>1 ) >dst_metric (dst,RTAX_SSTHRESH )) - dst->metrics[RTAX_SSTHRESH -1 ] = tp->snd_cwnd >>1 ; +dst_metric_set (dst,RTAX_SSTHRESH , tp->snd_cwnd >>1 );if (!dst_metric_locked (dst,RTAX_CWND ) && tp->snd_cwnd >dst_metric (dst,RTAX_CWND )) - dst->metrics[RTAX_CWND -1 ] = tp->snd_cwnd; +dst_metric_set (dst,RTAX_CWND , tp->snd_cwnd); }else if (tp->snd_cwnd > tp->snd_ssthresh && icsk->icsk_ca_state == TCP_CA_Open) {/* Cong. avoidance phase, cwnd is reliable. */ if (!dst_metric_locked (dst,RTAX_SSTHRESH )) - dst->metrics[RTAX_SSTHRESH -1 ] = -max (tp->snd_cwnd >>1 , tp->snd_ssthresh); +dst_metric_set (dst,RTAX_SSTHRESH , +max (tp->snd_cwnd >>1 , tp->snd_ssthresh));if (!dst_metric_locked (dst,RTAX_CWND )) - dst->metrics[RTAX_CWND -1 ] = (dst_metric (dst,RTAX_CWND ) + tp->snd_cwnd) >>1 ; +dst_metric_set (dst,RTAX_CWND , + (dst_metric (dst,RTAX_CWND ) + + tp->snd_cwnd) >>1 ); }else {/* Else slow start did not finish, cwnd is non-sense, ssthresh may be also invalid. */ if (!dst_metric_locked (dst,RTAX_CWND )) - dst->metrics[RTAX_CWND -1 ] = (dst_metric (dst,RTAX_CWND ) + tp->snd_ssthresh) >>1 ; +dst_metric_set (dst,RTAX_CWND , + (dst_metric (dst,RTAX_CWND ) + + tp->snd_ssthresh) >>1 );if (dst_metric (dst,RTAX_SSTHRESH ) && !dst_metric_locked (dst,RTAX_SSTHRESH ) && tp->snd_ssthresh >dst_metric (dst,RTAX_SSTHRESH )) - dst->metrics[RTAX_SSTHRESH -1 ] = tp->snd_ssthresh; +dst_metric_set (dst,RTAX_SSTHRESH , tp->snd_ssthresh); }if (!dst_metric_locked (dst,RTAX_REORDERING )) {if (dst_metric (dst,RTAX_REORDERING ) < tp->reordering && tp->reordering != sysctl_tcp_reordering) - dst->metrics[RTAX_REORDERING -1 ] = tp->reordering; +dst_metric_set (dst,RTAX_REORDERING , tp->reordering); } } }
net/ipv6/ndisc.c +3 -2
@@ -1259,7 +1259,8 @@ static void ndisc_router_discovery(struct sk_buff *skb)if (ra_msg->icmph.icmp6_hop_limit) { in6_dev->cnf.hop_limit = ra_msg->icmph.icmp6_hop_limit;if (rt) - rt->dst.metrics[RTAX_HOPLIMIT -1 ] = ra_msg->icmph.icmp6_hop_limit; +dst_metric_set (&rt->dst,RTAX_HOPLIMIT , + ra_msg->icmph.icmp6_hop_limit); } skip_defrtr:
@@ -1377,7 +1378,7 @@ skip_linkparms: in6_dev->cnf.mtu6 = mtu;if (rt) - rt->dst.metrics[RTAX_MTU -1 ] = mtu; +dst_metric_set (&rt->dst,RTAX_MTU , mtu);rt6_mtu_change (skb->dev, mtu); }
net/ipv6/route.c +37 -29
177 lines not on this page · raw message
net/xfrm/xfrm_policy.c +3 -3
@@ -1433,7 +1433,7 @@ static struct dst_entry *xfrm_bundle_create(struct xfrm_policy *policy, } xdst->route = dst; -memcpy (&dst1->metrics, &dst->metrics,sizeof (dst->metrics)); +dst_copy_metrics (dst1, dst);if (xfrm[i]->props.mode !=XFRM_MODE_TRANSPORT ) { family = xfrm[i]->props.family;
@@ -2271,7 +2271,7 @@ static void xfrm_init_pmtu(struct dst_entry *dst)if (pmtu > route_mtu_cached) pmtu = route_mtu_cached; - dst->metrics[RTAX_MTU -1 ] = pmtu; +dst_metric_set (dst,RTAX_MTU , pmtu); }while ((dst = dst->next)); }
@@ -2349,7 +2349,7 @@ static int xfrm_bundle_ok(struct xfrm_policy *pol, struct xfrm_dst *first, mtu =xfrm_state_mtu (dst->xfrm, mtu);if (mtu > last->route_mtu_cached) mtu = last->route_mtu_cached; - dst->metrics[RTAX_MTU -1 ] = mtu; +dst_metric_set (dst,RTAX_MTU , mtu);if (last == first)break ;
Signature · 1 line
1.7.3.2
Quoted 9 lines · David Miller
Use helper functions to hide all direct accesses, especially writes, to
dst_entrymetrics values.This will allow us to:
1) More easily change how the metrics are stored.
2) Implement COW for metrics.
Quoted 7 lines
In particular this will help us put metrics into the inetpeer cache if that is what we end up doing. We can make the
_metricsmember a pointer instead of an array, initially have it point at the read-only metrics in the FIB, and then on the first set grab an inetpeer entry and point the_metricsmember there.Signed-off-by David S. Miller <[email protected]>
Very exciting, thanks David !