From mboxrd@z Thu Jan 1 00:00:00 1970 From: Roopa Prabhu Subject: [PATCH net-next v2 2/3] ipv6: support sport and dport in RTM_GETROUTE Date: Sun, 6 May 2018 17:59:46 -0700 Message-ID: <1525654787-21990-3-git-send-email-roopa@cumulusnetworks.com> References: <1525654787-21990-1-git-send-email-roopa@cumulusnetworks.com> Cc: netdev@vger.kernel.org, dsa@cumulusnetworks.com, nikolay@cumulusnetworks.com, idosch@mellanox.com To: davem@davemloft.net Return-path: Received: from mail-pg0-f66.google.com ([74.125.83.66]:40914 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751889AbeEGA7y (ORCPT ); Sun, 6 May 2018 20:59:54 -0400 Received: by mail-pg0-f66.google.com with SMTP id l2-v6so19016280pgc.7 for ; Sun, 06 May 2018 17:59:54 -0700 (PDT) In-Reply-To: <1525654787-21990-1-git-send-email-roopa@cumulusnetworks.com> Sender: netdev-owner@vger.kernel.org List-ID: From: Roopa Prabhu This is a followup to fib6 rules sport and dport match support. Having them supported in getroute makes it easier to test fib6 rule lookups. Used by fib6 rule self tests. Signed-off-by: Roopa Prabhu --- net/ipv6/route.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/net/ipv6/route.c b/net/ipv6/route.c index 8ed1b51..bcdc056 100644 --- a/net/ipv6/route.c +++ b/net/ipv6/route.c @@ -4071,6 +4071,8 @@ static const struct nla_policy rtm_ipv6_policy[RTA_MAX+1] = { [RTA_UID] = { .type = NLA_U32 }, [RTA_MARK] = { .type = NLA_U32 }, [RTA_TABLE] = { .type = NLA_U32 }, + [RTA_SPORT] = { .type = NLA_U16 }, + [RTA_DPORT] = { .type = NLA_U16 }, }; static int rtm_to_fib6_config(struct sk_buff *skb, struct nlmsghdr *nlh, @@ -4728,6 +4730,17 @@ int rt6_dump_route(struct fib6_info *rt, void *p_arg) arg->cb->nlh->nlmsg_seq, NLM_F_MULTI); } +static int nla_get_port(struct nlattr *attr, __be16 *port) +{ + int p = nla_get_be16(attr); + + if (p <= 0 || p >= 0xffff) + return -EINVAL; + + *port = p; + return 0; +} + static int inet6_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh, struct netlink_ext_ack *extack) { @@ -4782,6 +4795,18 @@ static int inet6_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh, else fl6.flowi6_uid = iif ? INVALID_UID : current_uid(); + if (tb[RTA_SPORT]) { + err = nla_get_port(tb[RTA_SPORT], &fl6.fl6_sport); + if (err) + goto errout; + } + + if (tb[RTA_DPORT]) { + err = nla_get_port(tb[RTA_DPORT], &fl6.fl6_dport); + if (err) + goto errout; + } + if (iif) { struct net_device *dev; int flags = 0; -- 2.1.4