Skip to content

Commit ba41380

Browse files
idoschPaolo Abeni
authored andcommitted
ipv6: Add flow label to route get requests
The default IPv6 multipath hash policy takes the flow label into account when calculating a multipath hash and previous patches added a flow label selector to IPv6 FIB rules. Allow user space to specify a flow label in route get requests by adding a new netlink attribute and using its value to populate the "flowlabel" field in the IPv6 flow info structure prior to a route lookup. Deny the attribute in RTM_{NEW,DEL}ROUTE requests by checking for it in rtm_to_fib6_config() and returning an error if present. A subsequent patch will use this capability to test the new flow label selector in IPv6 FIB rules. Reviewed-by: Petr Machata <petrm@nvidia.com> Signed-off-by: Ido Schimmel <idosch@nvidia.com> Reviewed-by: Guillaume Nault <gnault@redhat.com> Signed-off-by: Paolo Abeni <pabeni@redhat.com>
1 parent c72004a commit ba41380

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

include/uapi/linux/rtnetlink.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ enum rtattr_type_t {
393393
RTA_SPORT,
394394
RTA_DPORT,
395395
RTA_NH_ID,
396+
RTA_FLOWLABEL,
396397
__RTA_MAX
397398
};
398399

net/ipv6/route.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5005,6 +5005,7 @@ static const struct nla_policy rtm_ipv6_policy[RTA_MAX+1] = {
50055005
[RTA_SPORT] = { .type = NLA_U16 },
50065006
[RTA_DPORT] = { .type = NLA_U16 },
50075007
[RTA_NH_ID] = { .type = NLA_U32 },
5008+
[RTA_FLOWLABEL] = { .type = NLA_BE32 },
50085009
};
50095010

50105011
static int rtm_to_fib6_config(struct sk_buff *skb, struct nlmsghdr *nlh,
@@ -5030,6 +5031,12 @@ static int rtm_to_fib6_config(struct sk_buff *skb, struct nlmsghdr *nlh,
50305031
goto errout;
50315032
}
50325033

5034+
if (tb[RTA_FLOWLABEL]) {
5035+
NL_SET_ERR_MSG_ATTR(extack, tb[RTA_FLOWLABEL],
5036+
"Flow label cannot be specified for this operation");
5037+
goto errout;
5038+
}
5039+
50335040
*cfg = (struct fib6_config){
50345041
.fc_table = rtm->rtm_table,
50355042
.fc_dst_len = rtm->rtm_dst_len,
@@ -6013,6 +6020,13 @@ static int inet6_rtm_valid_getroute_req(struct sk_buff *skb,
60136020
return -EINVAL;
60146021
}
60156022

6023+
if (tb[RTA_FLOWLABEL] &&
6024+
(nla_get_be32(tb[RTA_FLOWLABEL]) & ~IPV6_FLOWLABEL_MASK)) {
6025+
NL_SET_ERR_MSG_ATTR(extack, tb[RTA_FLOWLABEL],
6026+
"Invalid flow label");
6027+
return -EINVAL;
6028+
}
6029+
60166030
for (i = 0; i <= RTA_MAX; i++) {
60176031
if (!tb[i])
60186032
continue;
@@ -6027,6 +6041,7 @@ static int inet6_rtm_valid_getroute_req(struct sk_buff *skb,
60276041
case RTA_SPORT:
60286042
case RTA_DPORT:
60296043
case RTA_IP_PROTO:
6044+
case RTA_FLOWLABEL:
60306045
break;
60316046
default:
60326047
NL_SET_ERR_MSG_MOD(extack, "Unsupported attribute in get route request");
@@ -6049,6 +6064,7 @@ static int inet6_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh,
60496064
struct sk_buff *skb;
60506065
struct rtmsg *rtm;
60516066
struct flowi6 fl6 = {};
6067+
__be32 flowlabel;
60526068
bool fibmatch;
60536069

60546070
err = inet6_rtm_valid_getroute_req(in_skb, nlh, tb, extack);
@@ -6057,7 +6073,6 @@ static int inet6_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh,
60576073

60586074
err = -EINVAL;
60596075
rtm = nlmsg_data(nlh);
6060-
fl6.flowlabel = ip6_make_flowinfo(rtm->rtm_tos, 0);
60616076
fibmatch = !!(rtm->rtm_flags & RTM_F_FIB_MATCH);
60626077

60636078
if (tb[RTA_SRC]) {
@@ -6103,6 +6118,9 @@ static int inet6_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh,
61036118
goto errout;
61046119
}
61056120

6121+
flowlabel = nla_get_be32_default(tb[RTA_FLOWLABEL], 0);
6122+
fl6.flowlabel = ip6_make_flowinfo(rtm->rtm_tos, flowlabel);
6123+
61066124
if (iif) {
61076125
struct net_device *dev;
61086126
int flags = 0;

0 commit comments

Comments
 (0)