Skip to content

Commit

Permalink
net, ipv4, lwtunnel: add and use LWTUNNEL_IP_FLAGS_BITMAP attribute
Browse files Browse the repository at this point in the history
Add the ability to pass 64-bit IP tunnel flags in IP tunnel core
code between the userspace and the kernel. On receiving, the new
attribute is preferred, the old 16-bit one is being read only if
the new one is not present.
On sending, there's no other options other than sending both of
them, so that both old and new userspace programs could work
properly.

Signed-off-by: Alexander Lobakin <alexandr.lobakin@intel.com>
  • Loading branch information
alobakin committed Jul 19, 2022
1 parent b666eda commit 722f0c7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
1 change: 1 addition & 0 deletions include/uapi/linux/lwtunnel.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ enum lwtunnel_ip_t {
LWTUNNEL_IP_FLAGS,
LWTUNNEL_IP_PAD,
LWTUNNEL_IP_OPTS,
LWTUNNEL_IP_FLAGS_BITMAP,
__LWTUNNEL_IP_MAX,
};

Expand Down
27 changes: 21 additions & 6 deletions net/ipv4/ip_tunnel_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,8 @@ static const struct nla_policy ip_tun_policy[LWTUNNEL_IP_MAX + 1] = {
[LWTUNNEL_IP_TOS] = { .type = NLA_U8 },
[LWTUNNEL_IP_FLAGS] = { .type = NLA_U16 },
[LWTUNNEL_IP_OPTS] = { .type = NLA_NESTED },
[LWTUNNEL_IP_FLAGS_BITMAP] =
NLA_POLICY_BITMAP(__IP_TUNNEL_FLAG_NUM),
};

static const struct nla_policy ip_opts_policy[LWTUNNEL_IP_OPTS_MAX + 1] = {
Expand Down Expand Up @@ -658,6 +660,8 @@ static int ip_tun_build_state(struct net *net, struct nlattr *attr,
struct nlattr *tb[LWTUNNEL_IP_MAX + 1];
struct lwtunnel_state *new_state;
struct ip_tunnel_info *tun_info;
IP_TUNNEL_DECLARE_FLAGS(flags);
bool set_flags = false;
int err, opt_len;

err = nla_parse_nested_deprecated(tb, LWTUNNEL_IP_MAX, attr,
Expand Down Expand Up @@ -706,13 +710,18 @@ static int ip_tun_build_state(struct net *net, struct nlattr *attr,
if (tb[LWTUNNEL_IP_TOS])
tun_info->key.tos = nla_get_u8(tb[LWTUNNEL_IP_TOS]);

if (tb[LWTUNNEL_IP_FLAGS]) {
IP_TUNNEL_DECLARE_FLAGS(flags);

if (tb[LWTUNNEL_IP_FLAGS_BITMAP]) {
nla_get_bitmap(tb[LWTUNNEL_IP_FLAGS_BITMAP], flags,
__IP_TUNNEL_FLAG_NUM);
set_flags = true;
} else if (tb[LWTUNNEL_IP_FLAGS]) {
ip_tunnel_flags_from_be16(flags,
nla_get_be16(tb[LWTUNNEL_IP_FLAGS]));
ip_tunnel_clear_options_present(flags);
set_flags = true;
}

if (set_flags) {
ip_tunnel_clear_options_present(flags);
bitmap_or(tun_info->key.tun_flags, tun_info->key.tun_flags,
flags, __IP_TUNNEL_FLAG_NUM);
}
Expand Down Expand Up @@ -855,7 +864,10 @@ static int ip_tun_fill_encap_info(struct sk_buff *skb,
nla_put_u8(skb, LWTUNNEL_IP_TTL, tun_info->key.ttl) ||
nla_put_be16(skb, LWTUNNEL_IP_FLAGS,
ip_tunnel_flags_to_be16(tun_info->key.tun_flags)) ||
ip_tun_fill_encap_opts(skb, LWTUNNEL_IP_OPTS, tun_info))
ip_tun_fill_encap_opts(skb, LWTUNNEL_IP_OPTS, tun_info) ||
nla_put_bitmap(skb, LWTUNNEL_IP_FLAGS_BITMAP,
tun_info->key.tun_flags, __IP_TUNNEL_FLAG_NUM,
LWTUNNEL_IP_PAD))
return -ENOMEM;

return 0;
Expand Down Expand Up @@ -908,8 +920,11 @@ static int ip_tun_encap_nlsize(struct lwtunnel_state *lwtstate)
+ nla_total_size(1) /* LWTUNNEL_IP_TOS */
+ nla_total_size(1) /* LWTUNNEL_IP_TTL */
+ nla_total_size(2) /* LWTUNNEL_IP_FLAGS */
+ ip_tun_opts_nlsize(lwt_tun_info(lwtstate));
+ ip_tun_opts_nlsize(lwt_tun_info(lwtstate))
/* LWTUNNEL_IP_OPTS */
+ nla_total_size_bitmap(__IP_TUNNEL_FLAG_NUM)
/* LWTUNNEL_IP_FLAGS_BITMAP */
;
}

static int ip_tun_cmp_encap(struct lwtunnel_state *a, struct lwtunnel_state *b)
Expand Down

0 comments on commit 722f0c7

Please sign in to comment.