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 02A00C43381 for ; Sat, 30 Mar 2019 00:47:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B51132070B for ; Sat, 30 Mar 2019 00:47:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553906862; bh=LTQY41UD8xkxogfQ4hk6QTZnDof5cUNnL9i8lPbm5B0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=XROKTdpXvv/A6+tkxHiQO3oY18CIT+z6xCA7QQwx62GDGbl3G1jGo9JaXoFMIJABh F7uVqJn6OhJL5Qho8WPn50LHAd1AjUSHN9GXy8RS9t/Fd6cpZIYpFCOJho0Pf5lYHE V9NJRoI+XWdMohdrYd0/Cw2HNlbl4Zy32fw+cFnA= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730413AbfC3Are (ORCPT ); Fri, 29 Mar 2019 20:47:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:56436 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730405AbfC3Are (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 20E87218EA; Sat, 30 Mar 2019 00:47:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553906853; bh=LTQY41UD8xkxogfQ4hk6QTZnDof5cUNnL9i8lPbm5B0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=K6ccwCgsZ3Rgt6R5gD+WXJ2Sxk1eUc2JnLKgOXKZrQ2hL7fgBMbdYFK1vWBmpjvR+ hymL0yFOx3Qi4nNO+aWa8usY52aJrIIx2Y1uSuenJ9xhfBEKCPpPtoRk9ftPtUOXb2 XFloVw/HtwVAggiklRIX78NlBtkV7m3Uk624aY3s= From: David Ahern To: davem@davemloft.net, netdev@vger.kernel.org Cc: idosch@mellanox.com, David Ahern Subject: [PATCH net-next 8/8] ipv6: Flip to fib_nexthop_info Date: Fri, 29 Mar 2019 17:47:31 -0700 Message-Id: <20190330004731.23959-9-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 Export fib_nexthop_info and fib_add_nexthop for use by IPv6 code. Remove rt6_nexthop_info and rt6_add_nexthop in favor of the IPv4 versions. Update fib_nexthop_info for IPv6 linkdown check and RTA_GATEWAY for AF_INET6. Signed-off-by: David Ahern --- include/net/ip_fib.h | 5 ++++ net/ipv4/fib_semantics.c | 30 ++++++++++++++----- net/ipv6/route.c | 78 +++++------------------------------------------- 3 files changed, 34 insertions(+), 79 deletions(-) diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h index 9849c8901033..5b6f533eac92 100644 --- a/include/net/ip_fib.h +++ b/include/net/ip_fib.h @@ -495,4 +495,9 @@ u32 ip_mtu_from_fib_result(struct fib_result *res, __be32 daddr); int ip_valid_fib_dump_req(struct net *net, const struct nlmsghdr *nlh, struct fib_dump_filter *filter, struct netlink_callback *cb); + +int fib_nexthop_info(struct sk_buff *skb, const struct fib_nh_common *nh, + unsigned int *flags, bool skip_oif, bool for_ipv4); +int fib_add_nexthop(struct sk_buff *skb, const struct fib_nh_common *nh, + int nh_weight, bool for_ipv4); #endif /* _NET_FIB_H */ diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c index 1efd6a88ccb5..efc487727d06 100644 --- a/net/ipv4/fib_semantics.c +++ b/net/ipv4/fib_semantics.c @@ -45,6 +45,7 @@ #include #include #include +#include #include "fib_lookup.h" @@ -1323,8 +1324,8 @@ 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_common *nh, - unsigned int *flags, bool skip_oif) +int fib_nexthop_info(struct sk_buff *skb, const struct fib_nh_common *nh, + unsigned int *flags, bool skip_oif, bool for_ipv4) { if (nh->nhc_flags & RTNH_F_DEAD) *flags |= RTNH_F_DEAD; @@ -1338,6 +1339,10 @@ static int fib_nexthop_info(struct sk_buff *skb, const struct fib_nh_common *nh, if (ip_ignore_linkdown(nh->nhc_dev)) *flags |= RTNH_F_DEAD; break; + case AF_INET6: + if (ip6_ignore_linkdown(nh->nhc_dev)) + *flags |= RTNH_F_DEAD; + break; } rcu_read_unlock(); } @@ -1348,6 +1353,11 @@ static int fib_nexthop_info(struct sk_buff *skb, const struct fib_nh_common *nh, if (nla_put_in_addr(skb, RTA_GATEWAY, nh->nhc_gw.ipv4)) goto nla_put_failure; break; + case AF_INET6: + if (nla_put_in6_addr(skb, RTA_GATEWAY, + &nh->nhc_gw.ipv6) < 0) + goto nla_put_failure; + break; } } @@ -1368,10 +1378,11 @@ static int fib_nexthop_info(struct sk_buff *skb, const struct fib_nh_common *nh, nla_put_failure: return -EMSGSIZE; } +EXPORT_SYMBOL_GPL(fib_nexthop_info); -#ifdef CONFIG_IP_ROUTE_MULTIPATH -static int fib_add_nexthop(struct sk_buff *skb, const struct fib_nh_common *nh, - int nh_weight) +#if IS_ENABLED(CONFIG_IP_ROUTE_MULTIPATH) || IS_ENABLED(CONFIG_IPV6) +int fib_add_nexthop(struct sk_buff *skb, const struct fib_nh_common *nh, + int nh_weight, bool for_ipv4) { const struct net_device *dev = nh->nhc_dev; struct rtnexthop *rtnh; @@ -1384,7 +1395,7 @@ static int fib_add_nexthop(struct sk_buff *skb, const struct fib_nh_common *nh, rtnh->rtnh_hops = nh_weight - 1; rtnh->rtnh_ifindex = dev ? dev->ifindex : 0; - if (fib_nexthop_info(skb, nh, &flags, true) < 0) + if (fib_nexthop_info(skb, nh, &flags, true, for_ipv4) < 0) goto nla_put_failure; rtnh->rtnh_flags = flags; @@ -1397,6 +1408,7 @@ static int fib_add_nexthop(struct sk_buff *skb, const struct fib_nh_common *nh, nla_put_failure: return -EMSGSIZE; } +EXPORT_SYMBOL_GPL(fib_add_nexthop); #endif #ifdef CONFIG_IP_ROUTE_MULTIPATH @@ -1409,7 +1421,8 @@ 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->nh_common, nh->fib_nh_weight) < 0) + if (fib_add_nexthop(skb, &nh->nh_common, + nh->fib_nh_weight, true) < 0) goto nla_put_failure; #ifdef CONFIG_IP_ROUTE_CLASSID if (nh->nh_tclassid && @@ -1475,7 +1488,8 @@ 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->nh_common, &flags, false) < 0) + if (fib_nexthop_info(skb, &nh->nh_common, &flags, + false, true) < 0) goto nla_put_failure; rtm->rtm_flags = flags; diff --git a/net/ipv6/route.c b/net/ipv6/route.c index c66b9ac37036..26e058485fd2 100644 --- a/net/ipv6/route.c +++ b/net/ipv6/route.c @@ -4624,73 +4624,6 @@ static size_t rt6_nlmsg_size(struct fib6_info *rt) + nexthop_len; } -static int rt6_nexthop_info(struct sk_buff *skb, const struct fib6_nh *fib6_nh, - unsigned int *flags, bool skip_oif) -{ - if (fib6_nh->fib_nh_flags & RTNH_F_DEAD) - *flags |= RTNH_F_DEAD; - - if (fib6_nh->fib_nh_flags & RTNH_F_LINKDOWN) { - *flags |= RTNH_F_LINKDOWN; - - rcu_read_lock(); - if (ip6_ignore_linkdown(fib6_nh->fib_nh_dev)) - *flags |= RTNH_F_DEAD; - rcu_read_unlock(); - } - - if (fib6_nh->fib_nh_has_gw) { - if (nla_put_in6_addr(skb, RTA_GATEWAY, &fib6_nh->fib_nh_gw6) < 0) - goto nla_put_failure; - } - - *flags |= (fib6_nh->fib_nh_flags & RTNH_F_ONLINK); - if (fib6_nh->fib_nh_flags & RTNH_F_OFFLOAD) - *flags |= RTNH_F_OFFLOAD; - - /* not needed for multipath encoding b/c it has a rtnexthop struct */ - if (!skip_oif && fib6_nh->fib_nh_dev && - nla_put_u32(skb, RTA_OIF, fib6_nh->fib_nh_dev->ifindex)) - goto nla_put_failure; - - if (fib6_nh->fib_nh_lws && - lwtunnel_fill_encap(skb, fib6_nh->fib_nh_lws) < 0) - goto nla_put_failure; - - return 0; - -nla_put_failure: - return -EMSGSIZE; -} - -/* add multipath next hop */ -static int rt6_add_nexthop(struct sk_buff *skb, const struct fib6_nh *fib6_nh) -{ - const struct net_device *dev = fib6_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 = fib6_nh->fib_nh_weight - 1; - rtnh->rtnh_ifindex = dev ? dev->ifindex : 0; - - if (rt6_nexthop_info(skb, fib6_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 rt6_fill_node(struct net *net, struct sk_buff *skb, struct fib6_info *rt, struct dst_entry *dst, struct in6_addr *dest, struct in6_addr *src, @@ -4807,19 +4740,22 @@ static int rt6_fill_node(struct net *net, struct sk_buff *skb, if (!mp) goto nla_put_failure; - if (rt6_add_nexthop(skb, &rt->fib6_nh) < 0) + if (fib_add_nexthop(skb, &rt->fib6_nh.nh_common, + rt->fib6_nh.fib_nh_weight, false) < 0) goto nla_put_failure; list_for_each_entry_safe(sibling, next_sibling, &rt->fib6_siblings, fib6_siblings) { - if (rt6_add_nexthop(skb, &sibling->fib6_nh) < 0) + if (fib_add_nexthop(skb, &sibling->fib6_nh.nh_common, + sibling->fib6_nh.fib_nh_weight, + false) < 0) goto nla_put_failure; } nla_nest_end(skb, mp); } else { - if (rt6_nexthop_info(skb, &rt->fib6_nh, &rtm->rtm_flags, - false) < 0) + if (fib_nexthop_info(skb, &rt->fib6_nh.nh_common, + &rtm->rtm_flags, false, false) < 0) goto nla_put_failure; } -- 2.11.0