Skip to content

Commit 2a43747

Browse files
jahurleydavem330
authored andcommitted
nfp: flower: set ip tunnel ttl from encap action
The TTL for encapsulating headers in IPv4 UDP tunnels is taken from a route lookup. Modify this to first check if a user has specified a TTL to be used in the TC action. Signed-off-by: John Hurley <[email protected]> Reviewed-by: Jakub Kicinski <[email protected]> Signed-off-by: Simon Horman <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 50ee42b commit 2a43747

File tree

1 file changed

+21
-18
lines changed
  • drivers/net/ethernet/netronome/nfp/flower

1 file changed

+21
-18
lines changed

drivers/net/ethernet/netronome/nfp/flower/action.c

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -238,18 +238,12 @@ nfp_fl_set_ipv4_udp_tun(struct nfp_fl_set_ipv4_udp_tun *set_tun,
238238
size_t act_size = sizeof(struct nfp_fl_set_ipv4_udp_tun);
239239
struct ip_tunnel_info *ip_tun = tcf_tunnel_info(action);
240240
u32 tmp_set_ip_tun_type_index = 0;
241-
struct flowi4 flow = {};
242241
/* Currently support one pre-tunnel so index is always 0. */
243242
int pretun_idx = 0;
244-
struct rtable *rt;
245-
struct net *net;
246-
int err;
247243

248244
if (ip_tun->options_len)
249245
return -EOPNOTSUPP;
250246

251-
net = dev_net(netdev);
252-
253247
set_tun->head.jump_id = NFP_FL_ACTION_OPCODE_SET_IPV4_TUNNEL;
254248
set_tun->head.len_lw = act_size >> NFP_FL_LW_SIZ;
255249

@@ -261,19 +255,28 @@ nfp_fl_set_ipv4_udp_tun(struct nfp_fl_set_ipv4_udp_tun *set_tun,
261255
set_tun->tun_type_index = cpu_to_be32(tmp_set_ip_tun_type_index);
262256
set_tun->tun_id = ip_tun->key.tun_id;
263257

264-
/* Do a route lookup to determine ttl - if fails then use default.
265-
* Note that CONFIG_INET is a requirement of CONFIG_NET_SWITCHDEV so
266-
* must be defined here.
267-
*/
268-
flow.daddr = ip_tun->key.u.ipv4.dst;
269-
flow.flowi4_proto = IPPROTO_UDP;
270-
rt = ip_route_output_key(net, &flow);
271-
err = PTR_ERR_OR_ZERO(rt);
272-
if (!err) {
273-
set_tun->ttl = ip4_dst_hoplimit(&rt->dst);
274-
ip_rt_put(rt);
258+
if (ip_tun->key.ttl) {
259+
set_tun->ttl = ip_tun->key.ttl;
275260
} else {
276-
set_tun->ttl = net->ipv4.sysctl_ip_default_ttl;
261+
struct net *net = dev_net(netdev);
262+
struct flowi4 flow = {};
263+
struct rtable *rt;
264+
int err;
265+
266+
/* Do a route lookup to determine ttl - if fails then use
267+
* default. Note that CONFIG_INET is a requirement of
268+
* CONFIG_NET_SWITCHDEV so must be defined here.
269+
*/
270+
flow.daddr = ip_tun->key.u.ipv4.dst;
271+
flow.flowi4_proto = IPPROTO_UDP;
272+
rt = ip_route_output_key(net, &flow);
273+
err = PTR_ERR_OR_ZERO(rt);
274+
if (!err) {
275+
set_tun->ttl = ip4_dst_hoplimit(&rt->dst);
276+
ip_rt_put(rt);
277+
} else {
278+
set_tun->ttl = net->ipv4.sysctl_ip_default_ttl;
279+
}
277280
}
278281

279282
set_tun->tos = ip_tun->key.tos;

0 commit comments

Comments
 (0)