Skip to content

Commit 5170ae8

Browse files
committed
net: Abstract RTAX_HOPLIMIT metric accesses behind helper.
Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent abbf46a commit 5170ae8

File tree

8 files changed

+22
-9
lines changed

8 files changed

+22
-9
lines changed

drivers/net/pptp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ static int pptp_xmit(struct ppp_channel *chan, struct sk_buff *skb)
277277
iph->tos = 0;
278278
iph->daddr = rt->rt_dst;
279279
iph->saddr = rt->rt_src;
280-
iph->ttl = dst_metric(&rt->dst, RTAX_HOPLIMIT);
280+
iph->ttl = dst_metric_hoplimit(&rt->dst);
281281
iph->tot_len = htons(skb->len);
282282

283283
skb_dst_drop(skb);

include/net/dst.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,24 @@ struct dst_entry {
104104
#ifdef __KERNEL__
105105

106106
static inline u32
107-
dst_metric(const struct dst_entry *dst, int metric)
107+
dst_metric_raw(const struct dst_entry *dst, const int metric)
108108
{
109109
return dst->_metrics[metric-1];
110110
}
111111

112+
static inline u32
113+
dst_metric(const struct dst_entry *dst, const int metric)
114+
{
115+
WARN_ON_ONCE(metric == RTAX_HOPLIMIT);
116+
return dst_metric_raw(dst, metric);
117+
}
118+
119+
static inline u32
120+
dst_metric_hoplimit(const struct dst_entry *dst)
121+
{
122+
return dst_metric_raw(dst, RTAX_HOPLIMIT);
123+
}
124+
112125
static inline void dst_metric_set(struct dst_entry *dst, int metric, u32 val)
113126
{
114127
dst->_metrics[metric-1] = val;

net/ipv4/ip_gre.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,7 @@ static netdev_tx_t ipgre_tunnel_xmit(struct sk_buff *skb, struct net_device *dev
890890
iph->ttl = ((struct ipv6hdr *)old_iph)->hop_limit;
891891
#endif
892892
else
893-
iph->ttl = dst_metric(&rt->dst, RTAX_HOPLIMIT);
893+
iph->ttl = dst_metric_hoplimit(&rt->dst);
894894
}
895895

896896
((__be16 *)(iph + 1))[0] = tunnel->parms.o_flags;

net/ipv4/ip_output.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ static inline int ip_select_ttl(struct inet_sock *inet, struct dst_entry *dst)
130130
int ttl = inet->uc_ttl;
131131

132132
if (ttl < 0)
133-
ttl = dst_metric(dst, RTAX_HOPLIMIT);
133+
ttl = dst_metric_hoplimit(dst);
134134
return ttl;
135135
}
136136

net/ipv4/netfilter/ipt_REJECT.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ static void send_reset(struct sk_buff *oldskb, int hook)
116116
if (ip_route_me_harder(nskb, addr_type))
117117
goto free_nskb;
118118

119-
niph->ttl = dst_metric(skb_dst(nskb), RTAX_HOPLIMIT);
119+
niph->ttl = dst_metric_hoplimit(skb_dst(nskb));
120120

121121
/* "Never happens" */
122122
if (nskb->len > dst_mtu(skb_dst(nskb)))

net/ipv4/route.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1821,7 +1821,7 @@ static void rt_set_nexthop(struct rtable *rt, struct fib_result *res, u32 itag)
18211821
} else
18221822
dst_metric_set(dst, RTAX_MTU, dst->dev->mtu);
18231823

1824-
if (dst_metric(dst, RTAX_HOPLIMIT) == 0)
1824+
if (dst_metric_raw(dst, RTAX_HOPLIMIT) == 0)
18251825
dst_metric_set(dst, RTAX_HOPLIMIT, sysctl_ip_default_ttl);
18261826
if (dst_mtu(dst) > IP_MAX_MTU)
18271827
dst_metric_set(dst, RTAX_MTU, IP_MAX_MTU);

net/ipv4/xfrm4_mode_tunnel.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ static int xfrm4_mode_tunnel_output(struct xfrm_state *x, struct sk_buff *skb)
5656
0 : (XFRM_MODE_SKB_CB(skb)->frag_off & htons(IP_DF));
5757
ip_select_ident(top_iph, dst->child, NULL);
5858

59-
top_iph->ttl = dst_metric(dst->child, RTAX_HOPLIMIT);
59+
top_iph->ttl = dst_metric_hoplimit(dst->child);
6060

6161
top_iph->saddr = x->props.saddr.a4;
6262
top_iph->daddr = x->id.daddr.a4;

net/ipv6/route.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,7 +1104,7 @@ static int ipv6_get_mtu(struct net_device *dev)
11041104

11051105
int ip6_dst_hoplimit(struct dst_entry *dst)
11061106
{
1107-
int hoplimit = dst_metric(dst, RTAX_HOPLIMIT);
1107+
int hoplimit = dst_metric_raw(dst, RTAX_HOPLIMIT);
11081108
if (hoplimit < 0) {
11091109
struct net_device *dev = dst->dev;
11101110
struct inet6_dev *idev;
@@ -1310,7 +1310,7 @@ int ip6_route_add(struct fib6_config *cfg)
13101310
}
13111311
}
13121312

1313-
if (dst_metric(&rt->dst, RTAX_HOPLIMIT) == 0)
1313+
if (dst_metric_raw(&rt->dst, RTAX_HOPLIMIT) == 0)
13141314
dst_metric_set(&rt->dst, RTAX_HOPLIMIT, -1);
13151315
if (!dst_mtu(&rt->dst))
13161316
dst_metric_set(&rt->dst, RTAX_MTU, ipv6_get_mtu(dev));

0 commit comments

Comments
 (0)