Skip to content

Commit c65a6a9

Browse files
committed
Merge branch 'net-Geneve-options-support-for-TC-act_tunnel_key'
Jakub Kicinski says: ==================== net: Geneve options support for TC act_tunnel_key Simon & Pieter say: This set adds Geneve Options support to the TC tunnel key action. It provides the plumbing required to configure Geneve variable length options. The options can be configured in the form CLASS:TYPE:DATA, where CLASS is represented as a 16bit hexadecimal value, TYPE as an 8bit hexadecimal value and DATA as a variable length hexadecimal value. Additionally multiple options may be listed using a comma delimiter. v2: - fix sparse warnings in patches 3 and 4 (first one reported by build bot). ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents c90d160 + 0ed5269 commit c65a6a9

File tree

9 files changed

+284
-18
lines changed

9 files changed

+284
-18
lines changed

drivers/net/geneve.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,8 @@ static void geneve_rx(struct geneve_dev *geneve, struct geneve_sock *gs,
236236
}
237237
/* Update tunnel dst according to Geneve options. */
238238
ip_tunnel_info_opts_set(&tun_dst->u.tun_info,
239-
gnvh->options, gnvh->opt_len * 4);
239+
gnvh->options, gnvh->opt_len * 4,
240+
TUNNEL_GENEVE_OPT);
240241
} else {
241242
/* Drop packets w/ critical options,
242243
* since we don't support any...
@@ -675,7 +676,8 @@ static void geneve_build_header(struct genevehdr *geneveh,
675676
geneveh->proto_type = htons(ETH_P_TEB);
676677
geneveh->rsvd2 = 0;
677678

678-
ip_tunnel_info_opts_get(geneveh->options, info);
679+
if (info->key.tun_flags & TUNNEL_GENEVE_OPT)
680+
ip_tunnel_info_opts_get(geneveh->options, info);
679681
}
680682

681683
static int geneve_build_skb(struct dst_entry *dst, struct sk_buff *skb,

drivers/net/vxlan.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2122,7 +2122,8 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
21222122
vni = tunnel_id_to_key32(info->key.tun_id);
21232123
ifindex = 0;
21242124
dst_cache = &info->dst_cache;
2125-
if (info->options_len)
2125+
if (info->options_len &&
2126+
info->key.tun_flags & TUNNEL_VXLAN_OPT)
21262127
md = ip_tunnel_info_opts(info);
21272128
ttl = info->key.ttl;
21282129
tos = info->key.tos;

include/net/ip_tunnels.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,10 +466,12 @@ static inline void ip_tunnel_info_opts_get(void *to,
466466
}
467467

468468
static inline void ip_tunnel_info_opts_set(struct ip_tunnel_info *info,
469-
const void *from, int len)
469+
const void *from, int len,
470+
__be16 flags)
470471
{
471472
memcpy(ip_tunnel_info_opts(info), from, len);
472473
info->options_len = len;
474+
info->key.tun_flags |= flags;
473475
}
474476

475477
static inline struct ip_tunnel_info *lwt_tun_info(struct lwtunnel_state *lwtstate)
@@ -511,9 +513,11 @@ static inline void ip_tunnel_info_opts_get(void *to,
511513
}
512514

513515
static inline void ip_tunnel_info_opts_set(struct ip_tunnel_info *info,
514-
const void *from, int len)
516+
const void *from, int len,
517+
__be16 flags)
515518
{
516519
info->options_len = 0;
520+
info->key.tun_flags |= flags;
517521
}
518522

519523
#endif /* CONFIG_INET */

include/uapi/linux/tc_act/tc_tunnel_key.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,35 @@ enum {
3636
TCA_TUNNEL_KEY_PAD,
3737
TCA_TUNNEL_KEY_ENC_DST_PORT, /* be16 */
3838
TCA_TUNNEL_KEY_NO_CSUM, /* u8 */
39+
TCA_TUNNEL_KEY_ENC_OPTS, /* Nested TCA_TUNNEL_KEY_ENC_OPTS_
40+
* attributes
41+
*/
3942
__TCA_TUNNEL_KEY_MAX,
4043
};
4144

4245
#define TCA_TUNNEL_KEY_MAX (__TCA_TUNNEL_KEY_MAX - 1)
4346

47+
enum {
48+
TCA_TUNNEL_KEY_ENC_OPTS_UNSPEC,
49+
TCA_TUNNEL_KEY_ENC_OPTS_GENEVE, /* Nested
50+
* TCA_TUNNEL_KEY_ENC_OPTS_
51+
* attributes
52+
*/
53+
__TCA_TUNNEL_KEY_ENC_OPTS_MAX,
54+
};
55+
56+
#define TCA_TUNNEL_KEY_ENC_OPTS_MAX (__TCA_TUNNEL_KEY_ENC_OPTS_MAX - 1)
57+
58+
enum {
59+
TCA_TUNNEL_KEY_ENC_OPT_GENEVE_UNSPEC,
60+
TCA_TUNNEL_KEY_ENC_OPT_GENEVE_CLASS, /* be16 */
61+
TCA_TUNNEL_KEY_ENC_OPT_GENEVE_TYPE, /* u8 */
62+
TCA_TUNNEL_KEY_ENC_OPT_GENEVE_DATA, /* 4 to 128 bytes */
63+
64+
__TCA_TUNNEL_KEY_ENC_OPT_GENEVE_MAX,
65+
};
66+
67+
#define TCA_TUNNEL_KEY_ENC_OPT_GENEVE_MAX \
68+
(__TCA_TUNNEL_KEY_ENC_OPT_GENEVE_MAX - 1)
69+
4470
#endif

net/core/filter.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3582,7 +3582,7 @@ BPF_CALL_3(bpf_skb_set_tunnel_opt, struct sk_buff *, skb,
35823582
if (unlikely(size > IP_TUNNEL_OPTS_MAX))
35833583
return -ENOMEM;
35843584

3585-
ip_tunnel_info_opts_set(info, from, size);
3585+
ip_tunnel_info_opts_set(info, from, size, TUNNEL_OPTIONS_PRESENT);
35863586

35873587
return 0;
35883588
}

net/ipv4/ip_gre.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,8 @@ static void erspan_fb_xmit(struct sk_buff *skb, struct net_device *dev,
587587
goto err_free_skb;
588588

589589
key = &tun_info->key;
590+
if (!(tun_info->key.tun_flags & TUNNEL_ERSPAN_OPT))
591+
goto err_free_rt;
590592
md = ip_tunnel_info_opts(tun_info);
591593
if (!md)
592594
goto err_free_rt;

net/ipv6/ip6_gre.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -990,6 +990,8 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb,
990990
fl6.flowi6_uid = sock_net_uid(dev_net(dev), NULL);
991991

992992
dsfield = key->tos;
993+
if (!(tun_info->key.tun_flags & TUNNEL_ERSPAN_OPT))
994+
goto tx_err;
993995
md = ip_tunnel_info_opts(tun_info);
994996
if (!md)
995997
goto tx_err;

net/openvswitch/flow_netlink.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2516,7 +2516,9 @@ static int validate_and_copy_set_tun(const struct nlattr *attr,
25162516
struct ovs_tunnel_info *ovs_tun;
25172517
struct nlattr *a;
25182518
int err = 0, start, opts_type;
2519+
__be16 dst_opt_type;
25192520

2521+
dst_opt_type = 0;
25202522
ovs_match_init(&match, &key, true, NULL);
25212523
opts_type = ip_tun_from_nlattr(nla_data(attr), &match, false, log);
25222524
if (opts_type < 0)
@@ -2528,10 +2530,13 @@ static int validate_and_copy_set_tun(const struct nlattr *attr,
25282530
err = validate_geneve_opts(&key);
25292531
if (err < 0)
25302532
return err;
2533+
dst_opt_type = TUNNEL_GENEVE_OPT;
25312534
break;
25322535
case OVS_TUNNEL_KEY_ATTR_VXLAN_OPTS:
2536+
dst_opt_type = TUNNEL_VXLAN_OPT;
25332537
break;
25342538
case OVS_TUNNEL_KEY_ATTR_ERSPAN_OPTS:
2539+
dst_opt_type = TUNNEL_ERSPAN_OPT;
25352540
break;
25362541
}
25372542
}
@@ -2574,7 +2579,7 @@ static int validate_and_copy_set_tun(const struct nlattr *attr,
25742579
*/
25752580
ip_tunnel_info_opts_set(tun_info,
25762581
TUN_METADATA_OPTS(&key, key.tun_opts_len),
2577-
key.tun_opts_len);
2582+
key.tun_opts_len, dst_opt_type);
25782583
add_nested_action_end(*sfa, start);
25792584

25802585
return err;

0 commit comments

Comments
 (0)