Skip to content

Commit

Permalink
Merge branch 'net-Geneve-options-support-for-TC-act_tunnel_key'
Browse files Browse the repository at this point in the history
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 <davem@davemloft.net>
  • Loading branch information
David S. Miller committed Jun 29, 2018
2 parents c90d160 + 0ed5269 commit c65a6a9
Show file tree
Hide file tree
Showing 9 changed files with 284 additions and 18 deletions.
6 changes: 4 additions & 2 deletions drivers/net/geneve.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,8 @@ static void geneve_rx(struct geneve_dev *geneve, struct geneve_sock *gs,
}
/* Update tunnel dst according to Geneve options. */
ip_tunnel_info_opts_set(&tun_dst->u.tun_info,
gnvh->options, gnvh->opt_len * 4);
gnvh->options, gnvh->opt_len * 4,
TUNNEL_GENEVE_OPT);
} else {
/* Drop packets w/ critical options,
* since we don't support any...
Expand Down Expand Up @@ -675,7 +676,8 @@ static void geneve_build_header(struct genevehdr *geneveh,
geneveh->proto_type = htons(ETH_P_TEB);
geneveh->rsvd2 = 0;

ip_tunnel_info_opts_get(geneveh->options, info);
if (info->key.tun_flags & TUNNEL_GENEVE_OPT)
ip_tunnel_info_opts_get(geneveh->options, info);
}

static int geneve_build_skb(struct dst_entry *dst, struct sk_buff *skb,
Expand Down
3 changes: 2 additions & 1 deletion drivers/net/vxlan.c
Original file line number Diff line number Diff line change
Expand Up @@ -2122,7 +2122,8 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
vni = tunnel_id_to_key32(info->key.tun_id);
ifindex = 0;
dst_cache = &info->dst_cache;
if (info->options_len)
if (info->options_len &&
info->key.tun_flags & TUNNEL_VXLAN_OPT)
md = ip_tunnel_info_opts(info);
ttl = info->key.ttl;
tos = info->key.tos;
Expand Down
8 changes: 6 additions & 2 deletions include/net/ip_tunnels.h
Original file line number Diff line number Diff line change
Expand Up @@ -466,10 +466,12 @@ static inline void ip_tunnel_info_opts_get(void *to,
}

static inline void ip_tunnel_info_opts_set(struct ip_tunnel_info *info,
const void *from, int len)
const void *from, int len,
__be16 flags)
{
memcpy(ip_tunnel_info_opts(info), from, len);
info->options_len = len;
info->key.tun_flags |= flags;
}

static inline struct ip_tunnel_info *lwt_tun_info(struct lwtunnel_state *lwtstate)
Expand Down Expand Up @@ -511,9 +513,11 @@ static inline void ip_tunnel_info_opts_get(void *to,
}

static inline void ip_tunnel_info_opts_set(struct ip_tunnel_info *info,
const void *from, int len)
const void *from, int len,
__be16 flags)
{
info->options_len = 0;
info->key.tun_flags |= flags;
}

#endif /* CONFIG_INET */
Expand Down
26 changes: 26 additions & 0 deletions include/uapi/linux/tc_act/tc_tunnel_key.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,35 @@ enum {
TCA_TUNNEL_KEY_PAD,
TCA_TUNNEL_KEY_ENC_DST_PORT, /* be16 */
TCA_TUNNEL_KEY_NO_CSUM, /* u8 */
TCA_TUNNEL_KEY_ENC_OPTS, /* Nested TCA_TUNNEL_KEY_ENC_OPTS_
* attributes
*/
__TCA_TUNNEL_KEY_MAX,
};

#define TCA_TUNNEL_KEY_MAX (__TCA_TUNNEL_KEY_MAX - 1)

enum {
TCA_TUNNEL_KEY_ENC_OPTS_UNSPEC,
TCA_TUNNEL_KEY_ENC_OPTS_GENEVE, /* Nested
* TCA_TUNNEL_KEY_ENC_OPTS_
* attributes
*/
__TCA_TUNNEL_KEY_ENC_OPTS_MAX,
};

#define TCA_TUNNEL_KEY_ENC_OPTS_MAX (__TCA_TUNNEL_KEY_ENC_OPTS_MAX - 1)

enum {
TCA_TUNNEL_KEY_ENC_OPT_GENEVE_UNSPEC,
TCA_TUNNEL_KEY_ENC_OPT_GENEVE_CLASS, /* be16 */
TCA_TUNNEL_KEY_ENC_OPT_GENEVE_TYPE, /* u8 */
TCA_TUNNEL_KEY_ENC_OPT_GENEVE_DATA, /* 4 to 128 bytes */

__TCA_TUNNEL_KEY_ENC_OPT_GENEVE_MAX,
};

#define TCA_TUNNEL_KEY_ENC_OPT_GENEVE_MAX \
(__TCA_TUNNEL_KEY_ENC_OPT_GENEVE_MAX - 1)

#endif
2 changes: 1 addition & 1 deletion net/core/filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -3582,7 +3582,7 @@ BPF_CALL_3(bpf_skb_set_tunnel_opt, struct sk_buff *, skb,
if (unlikely(size > IP_TUNNEL_OPTS_MAX))
return -ENOMEM;

ip_tunnel_info_opts_set(info, from, size);
ip_tunnel_info_opts_set(info, from, size, TUNNEL_OPTIONS_PRESENT);

return 0;
}
Expand Down
2 changes: 2 additions & 0 deletions net/ipv4/ip_gre.c
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,8 @@ static void erspan_fb_xmit(struct sk_buff *skb, struct net_device *dev,
goto err_free_skb;

key = &tun_info->key;
if (!(tun_info->key.tun_flags & TUNNEL_ERSPAN_OPT))
goto err_free_rt;
md = ip_tunnel_info_opts(tun_info);
if (!md)
goto err_free_rt;
Expand Down
2 changes: 2 additions & 0 deletions net/ipv6/ip6_gre.c
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,8 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb,
fl6.flowi6_uid = sock_net_uid(dev_net(dev), NULL);

dsfield = key->tos;
if (!(tun_info->key.tun_flags & TUNNEL_ERSPAN_OPT))
goto tx_err;
md = ip_tunnel_info_opts(tun_info);
if (!md)
goto tx_err;
Expand Down
7 changes: 6 additions & 1 deletion net/openvswitch/flow_netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -2516,7 +2516,9 @@ static int validate_and_copy_set_tun(const struct nlattr *attr,
struct ovs_tunnel_info *ovs_tun;
struct nlattr *a;
int err = 0, start, opts_type;
__be16 dst_opt_type;

dst_opt_type = 0;
ovs_match_init(&match, &key, true, NULL);
opts_type = ip_tun_from_nlattr(nla_data(attr), &match, false, log);
if (opts_type < 0)
Expand All @@ -2528,10 +2530,13 @@ static int validate_and_copy_set_tun(const struct nlattr *attr,
err = validate_geneve_opts(&key);
if (err < 0)
return err;
dst_opt_type = TUNNEL_GENEVE_OPT;
break;
case OVS_TUNNEL_KEY_ATTR_VXLAN_OPTS:
dst_opt_type = TUNNEL_VXLAN_OPT;
break;
case OVS_TUNNEL_KEY_ATTR_ERSPAN_OPTS:
dst_opt_type = TUNNEL_ERSPAN_OPT;
break;
}
}
Expand Down Expand Up @@ -2574,7 +2579,7 @@ static int validate_and_copy_set_tun(const struct nlattr *attr,
*/
ip_tunnel_info_opts_set(tun_info,
TUN_METADATA_OPTS(&key, key.tun_opts_len),
key.tun_opts_len);
key.tun_opts_len, dst_opt_type);
add_nested_action_end(*sfa, start);

return err;
Expand Down
Loading

0 comments on commit c65a6a9

Please sign in to comment.