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 09377C4360F for ; Sat, 30 Mar 2019 00:47:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CE8F2218CD for ; Sat, 30 Mar 2019 00:47:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553906856; bh=W34XwWDhD8HUakRAjr4ABT9Hmnrh2wVsv14hy8W0Zlc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=CXi0315RkPWpE8Rvw5w0zBB0qA1yUsqBo38lYPJTSbor3RQXKgYsBKRtHu58KVH1L crRKDPJkbtfB1z7nZoPiecO9tR4b+z+Tu7Kox6+26I31Ld4Juxc/+SDgS9K8IZuUhs G9WaMjzzk2Og2/3ji/cdRbXM5ZyNjZ91sRbuH7zI= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730419AbfC3Arf (ORCPT ); Fri, 29 Mar 2019 20:47:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:56424 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730404AbfC3Are (ORCPT ); Fri, 29 Mar 2019 20:47:34 -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 DCC7D218E2; Sat, 30 Mar 2019 00:47:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553906853; bh=W34XwWDhD8HUakRAjr4ABT9Hmnrh2wVsv14hy8W0Zlc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=scv9O8PBNsVENKgtk1FDWvNtIsRiKtdeUtRHxh0f1JL3z/+kiQo+ahGx1qjcFRXbv i0dWgLDsTgnUyANj/F6uTiK+D+i7vT/Bb5PB82t7XhYiMqohx23ofcCrt2aUFBp//F m3pVfd/g6p9w1xGBHWkaFHps/E4WeU2YLPiKoFuY= From: David Ahern To: davem@davemloft.net, netdev@vger.kernel.org Cc: idosch@mellanox.com, David Ahern Subject: [PATCH net-next 7/8] ipv4: Change fib_nexthop_info and fib_add_nexthop to take fib_nh_common Date: Fri, 29 Mar 2019 17:47:30 -0700 Message-Id: <20190330004731.23959-8-dsahern@kernel.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190330004731.23959-1-dsahern@kernel.org> References: <20190330004731.23959-1-dsahern@kernel.org> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: David Ahern With the exception of the nexthop weight, the nexthop attributes used by fib_nexthop_info and fib_add_nexthop come from the fib_nh_common struct. Update both to use it and change fib_nexthop_info to check the family as needed. nexthop weight comes from the common struct for existing use cases, but for nexthop groups the weight is outside of the fib_nh_common to allow the same nexthop definition to be used in multiple groups with different weights. Signed-off-by: David Ahern --- net/ipv4/fib_semantics.c | 50 ++++++++++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c index f5443b3102a5..1efd6a88ccb5 100644 --- a/net/ipv4/fib_semantics.c +++ b/net/ipv4/fib_semantics.c @@ -1323,35 +1323,44 @@ 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, +static int fib_nexthop_info(struct sk_buff *skb, const struct fib_nh_common *nh, unsigned int *flags, bool skip_oif) { - if (nh->fib_nh_flags & RTNH_F_DEAD) + if (nh->nhc_flags & RTNH_F_DEAD) *flags |= RTNH_F_DEAD; - if (nh->fib_nh_flags & RTNH_F_LINKDOWN) { + if (nh->nhc_flags & RTNH_F_LINKDOWN) { *flags |= RTNH_F_LINKDOWN; rcu_read_lock(); - if (ip_ignore_linkdown(nh->fib_nh_dev)) - *flags |= RTNH_F_DEAD; + switch (nh->nhc_family) { + case AF_INET: + if (ip_ignore_linkdown(nh->nhc_dev)) + *flags |= RTNH_F_DEAD; + break; + } rcu_read_unlock(); } - if (nh->fib_nh_gw4 && - nla_put_in_addr(skb, RTA_GATEWAY, nh->fib_nh_gw4)) - goto nla_put_failure; + if (nh->nhc_has_gw) { + switch (nh->nhc_family) { + case AF_INET: + if (nla_put_in_addr(skb, RTA_GATEWAY, nh->nhc_gw.ipv4)) + goto nla_put_failure; + break; + } + } - *flags |= (nh->fib_nh_flags & RTNH_F_ONLINK); - if (nh->fib_nh_flags & RTNH_F_OFFLOAD) + *flags |= (nh->nhc_flags & RTNH_F_ONLINK); + if (nh->nhc_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)) + if (!skip_oif && nh->nhc_dev && + nla_put_u32(skb, RTA_OIF, nh->nhc_dev->ifindex)) goto nla_put_failure; - if (nh->fib_nh_lws && - lwtunnel_fill_encap(skb, nh->fib_nh_lws) < 0) + if (nh->nhc_lwtstate && + lwtunnel_fill_encap(skb, nh->nhc_lwtstate) < 0) goto nla_put_failure; return 0; @@ -1361,9 +1370,10 @@ static int fib_nexthop_info(struct sk_buff *skb, const struct fib_nh *nh, } #ifdef CONFIG_IP_ROUTE_MULTIPATH -static int fib_add_nexthop(struct sk_buff *skb, const struct fib_nh *nh) +static int fib_add_nexthop(struct sk_buff *skb, const struct fib_nh_common *nh, + int nh_weight) { - const struct net_device *dev = nh->fib_nh_dev; + const struct net_device *dev = nh->nhc_dev; struct rtnexthop *rtnh; unsigned int flags = 0; @@ -1371,7 +1381,7 @@ static int fib_add_nexthop(struct sk_buff *skb, const struct fib_nh *nh) if (!rtnh) goto nla_put_failure; - rtnh->rtnh_hops = nh->fib_nh_weight - 1; + rtnh->rtnh_hops = nh_weight - 1; rtnh->rtnh_ifindex = dev ? dev->ifindex : 0; if (fib_nexthop_info(skb, nh, &flags, true) < 0) @@ -1387,7 +1397,9 @@ static int fib_add_nexthop(struct sk_buff *skb, const struct fib_nh *nh) nla_put_failure: return -EMSGSIZE; } +#endif +#ifdef CONFIG_IP_ROUTE_MULTIPATH static int fib_add_multipath(struct sk_buff *skb, struct fib_info *fi) { struct nlattr *mp; @@ -1397,7 +1409,7 @@ static int fib_add_multipath(struct sk_buff *skb, struct fib_info *fi) goto nla_put_failure; for_nexthops(fi) { - if (fib_add_nexthop(skb, nh) < 0) + if (fib_add_nexthop(skb, &nh->nh_common, nh->fib_nh_weight) < 0) goto nla_put_failure; #ifdef CONFIG_IP_ROUTE_CLASSID if (nh->nh_tclassid && @@ -1463,7 +1475,7 @@ int fib_dump_info(struct sk_buff *skb, u32 portid, u32 seq, int event, struct fib_nh *nh = &fi->fib_nh[0]; unsigned int flags = 0; - if (fib_nexthop_info(skb, nh, &flags, false) < 0) + if (fib_nexthop_info(skb, &nh->nh_common, &flags, false) < 0) goto nla_put_failure; rtm->rtm_flags = flags; -- 2.11.0