From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 72D6CC4360F for ; Tue, 2 Apr 2019 03:02:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3BB6C2070B for ; Tue, 2 Apr 2019 03:02:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554174153; bh=gRAQAR3Hrs3MPHA44gftQSh0wHdPxH/BzfgvtfSX/8c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=BhPp8c+XQuZFUGEDtYeXn8IPqczu2qsgog2jFN6nvMc+b3dilackwlE0fCnzDa0ME mEe/7nsVgOE7K3szMrwWJ9ehVUtZYu5kQ9M04XFnsZl2o5EZP3OJdMuZD2c2pe+Aus JW+xidNS+v4ZMhUtxkXcn04jodHZWmRvjNHxXbd0= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728931AbfDBDCb (ORCPT ); Mon, 1 Apr 2019 23:02:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:33368 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726988AbfDBDCX (ORCPT ); Mon, 1 Apr 2019 23:02:23 -0400 Received: from kenny.it.cumulusnetworks.com. (fw.cumulusnetworks.com [216.129.126.126]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1B359208E4; Tue, 2 Apr 2019 03:02:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554174142; bh=gRAQAR3Hrs3MPHA44gftQSh0wHdPxH/BzfgvtfSX/8c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2sSrVFxON5pDIt82WvkUenwjFJeSoGOVMngA7CM/Fiop8mVVHQ8l0k2iyTiibSqMX KrdY5QNNBvKoBDjxjLAL2EBiIiGfSqYHXB5j5Cv8UptXSrm1lNO7KXUAIqTBHK3UHq GPcY4ZXgfNfPdoemWwcVrFSjdZuUqCw6Zc1i6lg8= From: David Ahern To: davem@davemloft.net, netdev@vger.kernel.org Cc: idosch@mellanox.com, David Ahern Subject: [PATCH v3 net-next 3/5] ipv4: Refactor nexthop attributes in fib_dump_info Date: Mon, 1 Apr 2019 20:02:32 -0700 Message-Id: <20190402030234.26802-4-dsahern@kernel.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190402030234.26802-1-dsahern@kernel.org> References: <20190402030234.26802-1-dsahern@kernel.org> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: David Ahern Similar to ipv6, move addition of nexthop attributes to dump message into helpers that are called for both single path and multipath routes. Align the new helpers to the IPv6 variant which most notably means computing the flags argument based on settings in nh_flags. The RTA_FLOW argument is unique to IPv4, so it is appended after the new fib_nexthop_info helper. The intent of a later patch is to make both fib_nexthop_info and fib_add_nexthop usable for both IPv4 and IPv6. This patch is stepping stone in that direction. Signed-off-by: David Ahern --- net/ipv4/fib_semantics.c | 166 ++++++++++++++++++++++++++++++----------------- 1 file changed, 107 insertions(+), 59 deletions(-) diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c index 42666a409da0..32fb0123d881 100644 --- a/net/ipv4/fib_semantics.c +++ b/net/ipv4/fib_semantics.c @@ -1317,6 +1317,103 @@ struct fib_info *fib_create_info(struct fib_config *cfg, return ERR_PTR(err); } +static int fib_nexthop_info(struct sk_buff *skb, const struct fib_nh *nh, + unsigned int *flags, bool skip_oif) +{ + if (nh->fib_nh_flags & RTNH_F_DEAD) + *flags |= RTNH_F_DEAD; + + if (nh->fib_nh_flags & RTNH_F_LINKDOWN) { + *flags |= RTNH_F_LINKDOWN; + + rcu_read_lock(); + if (ip_ignore_linkdown(nh->fib_nh_dev)) + *flags |= RTNH_F_DEAD; + rcu_read_unlock(); + } + + if (nh->fib_nh_gw4 && + nla_put_in_addr(skb, RTA_GATEWAY, nh->fib_nh_gw4)) + goto nla_put_failure; + + *flags |= (nh->fib_nh_flags & RTNH_F_ONLINK); + if (nh->fib_nh_flags & RTNH_F_OFFLOAD) + *flags |= RTNH_F_OFFLOAD; + + if (!skip_oif && nh->fib_nh_dev && + nla_put_u32(skb, RTA_OIF, nh->fib_nh_dev->ifindex)) + goto nla_put_failure; + + if (nh->fib_nh_lws && + lwtunnel_fill_encap(skb, nh->fib_nh_lws) < 0) + goto nla_put_failure; + + return 0; + +nla_put_failure: + return -EMSGSIZE; +} + +#ifdef CONFIG_IP_ROUTE_MULTIPATH +static int fib_add_nexthop(struct sk_buff *skb, const struct fib_nh *nh) +{ + const struct net_device *dev = nh->fib_nh_dev; + struct rtnexthop *rtnh; + unsigned int flags = 0; + + rtnh = nla_reserve_nohdr(skb, sizeof(*rtnh)); + if (!rtnh) + goto nla_put_failure; + + rtnh->rtnh_hops = nh->fib_nh_weight - 1; + rtnh->rtnh_ifindex = dev ? dev->ifindex : 0; + + if (fib_nexthop_info(skb, nh, &flags, true) < 0) + goto nla_put_failure; + + rtnh->rtnh_flags = flags; + + /* length of rtnetlink header + attributes */ + rtnh->rtnh_len = nlmsg_get_pos(skb) - (void *)rtnh; + + return 0; + +nla_put_failure: + return -EMSGSIZE; +} + +static int fib_add_multipath(struct sk_buff *skb, struct fib_info *fi) +{ + struct nlattr *mp; + + mp = nla_nest_start(skb, RTA_MULTIPATH); + if (!mp) + goto nla_put_failure; + + for_nexthops(fi) { + if (fib_add_nexthop(skb, nh) < 0) + goto nla_put_failure; +#ifdef CONFIG_IP_ROUTE_CLASSID + if (nh->nh_tclassid && + nla_put_u32(skb, RTA_FLOW, nh->nh_tclassid)) + goto nla_put_failure; +#endif + } endfor_nexthops(fi); + + nla_nest_end(skb, mp); + + return 0; + +nla_put_failure: + return -EMSGSIZE; +} +#else +static int fib_add_multipath(struct sk_buff *skb, struct fib_info *fi) +{ + return 0; +} +#endif + int fib_dump_info(struct sk_buff *skb, u32 portid, u32 seq, int event, u32 tb_id, u8 type, __be32 dst, int dst_len, u8 tos, struct fib_info *fi, unsigned int flags) @@ -1357,72 +1454,23 @@ int fib_dump_info(struct sk_buff *skb, u32 portid, u32 seq, int event, nla_put_in_addr(skb, RTA_PREFSRC, fi->fib_prefsrc)) goto nla_put_failure; if (fi->fib_nhs == 1) { - if (fi->fib_nh->fib_nh_gw4 && - nla_put_in_addr(skb, RTA_GATEWAY, fi->fib_nh->fib_nh_gw4)) - goto nla_put_failure; - if (fi->fib_nh->fib_nh_oif && - nla_put_u32(skb, RTA_OIF, fi->fib_nh->fib_nh_oif)) + struct fib_nh *nh = &fi->fib_nh[0]; + unsigned int flags = 0; + + if (fib_nexthop_info(skb, nh, &flags, false) < 0) goto nla_put_failure; - if (fi->fib_nh->fib_nh_flags & RTNH_F_LINKDOWN) { - rcu_read_lock(); - if (ip_ignore_linkdown(fi->fib_nh->fib_nh_dev)) - rtm->rtm_flags |= RTNH_F_DEAD; - rcu_read_unlock(); - } - if (fi->fib_nh->fib_nh_flags & RTNH_F_OFFLOAD) - rtm->rtm_flags |= RTNH_F_OFFLOAD; + + rtm->rtm_flags = flags; #ifdef CONFIG_IP_ROUTE_CLASSID - if (fi->fib_nh[0].nh_tclassid && - nla_put_u32(skb, RTA_FLOW, fi->fib_nh[0].nh_tclassid)) + if (nh->nh_tclassid && + nla_put_u32(skb, RTA_FLOW, nh->nh_tclassid)) goto nla_put_failure; #endif - if (fi->fib_nh->fib_nh_lws && - lwtunnel_fill_encap(skb, fi->fib_nh->fib_nh_lws) < 0) + } else { + if (fib_add_multipath(skb, fi) < 0) goto nla_put_failure; } -#ifdef CONFIG_IP_ROUTE_MULTIPATH - if (fi->fib_nhs > 1) { - struct rtnexthop *rtnh; - struct nlattr *mp; - - mp = nla_nest_start(skb, RTA_MULTIPATH); - if (!mp) - goto nla_put_failure; - for_nexthops(fi) { - rtnh = nla_reserve_nohdr(skb, sizeof(*rtnh)); - if (!rtnh) - goto nla_put_failure; - - rtnh->rtnh_flags = nh->fib_nh_flags & 0xFF; - if (nh->fib_nh_flags & RTNH_F_LINKDOWN) { - rcu_read_lock(); - if (ip_ignore_linkdown(nh->fib_nh_dev)) - rtnh->rtnh_flags |= RTNH_F_DEAD; - rcu_read_unlock(); - } - rtnh->rtnh_hops = nh->fib_nh_weight - 1; - rtnh->rtnh_ifindex = nh->fib_nh_oif; - - if (nh->fib_nh_gw4 && - nla_put_in_addr(skb, RTA_GATEWAY, nh->fib_nh_gw4)) - goto nla_put_failure; -#ifdef CONFIG_IP_ROUTE_CLASSID - if (nh->nh_tclassid && - nla_put_u32(skb, RTA_FLOW, nh->nh_tclassid)) - goto nla_put_failure; -#endif - if (nh->fib_nh_lws && - lwtunnel_fill_encap(skb, nh->fib_nh_lws) < 0) - goto nla_put_failure; - - /* length of rtnetlink header + attributes */ - rtnh->rtnh_len = nlmsg_get_pos(skb) - (void *) rtnh; - } endfor_nexthops(fi); - - nla_nest_end(skb, mp); - } -#endif nlmsg_end(skb, nlh); return 0; -- 2.11.0