Skip to content

Commit 80ef0f2

Browse files
nissimadidavem330
authored andcommitted
net/sched: act_tunnel_key: Allow key-less tunnels
Allow setting a tunnel without a tunnel key. This is required for tunneling protocols, such as GRE, that define the key as an optional field. Signed-off-by: Adi Nissim <adin@mellanox.com> Acked-by: Or Gerlitz <ogerlitz@mellanox.com> Reviewed-by: Oz Shlomo <ozsh@mellanox.com> Acked-by: Jiri Pirko <jiri@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent d1ecf8a commit 80ef0f2

1 file changed

Lines changed: 11 additions & 10 deletions

File tree

‎net/sched/act_tunnel_key.c‎

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,9 @@ static int tunnel_key_init(struct net *net, struct nlattr *nla,
210210
struct tcf_tunnel_key *t;
211211
bool exists = false;
212212
__be16 dst_port = 0;
213+
__be64 key_id = 0;
213214
int opts_len = 0;
214-
__be64 key_id;
215-
__be16 flags;
215+
__be16 flags = 0;
216216
u8 tos, ttl;
217217
int ret = 0;
218218
int err;
@@ -246,15 +246,15 @@ static int tunnel_key_init(struct net *net, struct nlattr *nla,
246246
case TCA_TUNNEL_KEY_ACT_RELEASE:
247247
break;
248248
case TCA_TUNNEL_KEY_ACT_SET:
249-
if (!tb[TCA_TUNNEL_KEY_ENC_KEY_ID]) {
250-
NL_SET_ERR_MSG(extack, "Missing tunnel key id");
251-
ret = -EINVAL;
252-
goto err_out;
253-
}
249+
if (tb[TCA_TUNNEL_KEY_ENC_KEY_ID]) {
250+
__be32 key32;
254251

255-
key_id = key32_to_tunnel_id(nla_get_be32(tb[TCA_TUNNEL_KEY_ENC_KEY_ID]));
252+
key32 = nla_get_be32(tb[TCA_TUNNEL_KEY_ENC_KEY_ID]);
253+
key_id = key32_to_tunnel_id(key32);
254+
flags = TUNNEL_KEY;
255+
}
256256

257-
flags = TUNNEL_KEY | TUNNEL_CSUM;
257+
flags |= TUNNEL_CSUM;
258258
if (tb[TCA_TUNNEL_KEY_NO_CSUM] &&
259259
nla_get_u8(tb[TCA_TUNNEL_KEY_NO_CSUM]))
260260
flags &= ~TUNNEL_CSUM;
@@ -508,7 +508,8 @@ static int tunnel_key_dump(struct sk_buff *skb, struct tc_action *a,
508508
struct ip_tunnel_key *key = &info->key;
509509
__be32 key_id = tunnel_id_to_key32(key->tun_id);
510510

511-
if (nla_put_be32(skb, TCA_TUNNEL_KEY_ENC_KEY_ID, key_id) ||
511+
if (((key->tun_flags & TUNNEL_KEY) &&
512+
nla_put_be32(skb, TCA_TUNNEL_KEY_ENC_KEY_ID, key_id)) ||
512513
tunnel_key_dump_addresses(skb,
513514
&params->tcft_enc_metadata->u.tun_info) ||
514515
nla_put_be16(skb, TCA_TUNNEL_KEY_ENC_DST_PORT, key->tp_dst) ||

0 commit comments

Comments
 (0)