Netdev Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Ido Schimmel <idosch@idosch.org>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, kuba@kernel.org, dsahern@gmail.com,
roopa@nvidia.com, mlxsw@nvidia.com,
Ido Schimmel <idosch@nvidia.com>
Subject: [RFC PATCH net-next 07/22] nexthop: Prepare new notification info
Date: Tue, 8 Sep 2020 12:10:22 +0300 [thread overview]
Message-ID: <20200908091037.2709823-8-idosch@idosch.org> (raw)
In-Reply-To: <20200908091037.2709823-1-idosch@idosch.org>
From: Ido Schimmel <idosch@nvidia.com>
Prepare the new notification information so that it could be passed to
listeners in the new patch.
Signed-off-by: Ido Schimmel <idosch@nvidia.com>
---
net/ipv4/nexthop.c | 108 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 108 insertions(+)
diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c
index dafcb9f17250..68fd25c6eec7 100644
--- a/net/ipv4/nexthop.c
+++ b/net/ipv4/nexthop.c
@@ -36,15 +36,123 @@ static const struct nla_policy rtm_nh_policy[NHA_MAX + 1] = {
[NHA_FDB] = { .type = NLA_FLAG },
};
+static bool nexthop_notifiers_is_empty(struct net *net)
+{
+ return !net->nexthop.notifier_chain.head;
+}
+
+static void
+__nh_notifier_single_info_init(struct nh_notifier_single_info *nh_info,
+ const struct nexthop *nh)
+{
+ struct nh_info *nhi = rtnl_dereference(nh->nh_info);
+
+ nh_info->dev = nhi->fib_nhc.nhc_dev;
+ nh_info->gw_family = nhi->fib_nhc.nhc_gw_family;
+ if (nh_info->gw_family == AF_INET)
+ nh_info->ipv4 = nhi->fib_nhc.nhc_gw.ipv4;
+ else if (nh_info->gw_family == AF_INET6)
+ nh_info->ipv6 = nhi->fib_nhc.nhc_gw.ipv6;
+ nh_info->is_reject = nhi->reject_nh;
+ nh_info->is_fdb = nhi->fdb_nh;
+ nh_info->is_encap = !!nhi->fib_nhc.nhc_lwtstate;
+}
+
+static int nh_notifier_single_info_init(struct nh_notifier_info *info,
+ const struct nexthop *nh)
+{
+ info->nh = kzalloc(sizeof(*info->nh), GFP_KERNEL);
+ if (!info->nh)
+ return -ENOMEM;
+
+ __nh_notifier_single_info_init(info->nh, nh);
+
+ return 0;
+}
+
+static void nh_notifier_single_info_fini(struct nh_notifier_info *info)
+{
+ kfree(info->nh);
+}
+
+static int nh_notifier_grp_info_init(struct nh_notifier_info *info,
+ const struct nexthop *nh)
+{
+ struct nh_group *nhg = rtnl_dereference(nh->nh_grp);
+ u16 num_nh = nhg->num_nh;
+ int i;
+
+ info->nh_grp = kzalloc(struct_size(info->nh_grp, nh_entries, num_nh),
+ GFP_KERNEL);
+ if (!info->nh_grp)
+ return -ENOMEM;
+
+ info->nh_grp->num_nh = num_nh;
+ info->nh_grp->is_fdb = nhg->fdb_nh;
+
+ for (i = 0; i < num_nh; i++) {
+ struct nh_grp_entry *nhge = &nhg->nh_entries[i];
+
+ info->nh_grp->nh_entries[i].id = nhge->nh->id;
+ info->nh_grp->nh_entries[i].weight = nhge->weight;
+ __nh_notifier_single_info_init(&info->nh_grp->nh_entries[i].nh,
+ nhge->nh);
+ }
+
+ return 0;
+}
+
+static void nh_notifier_grp_info_fini(struct nh_notifier_info *info)
+{
+ kfree(info->nh_grp);
+}
+
+static int nh_notifier_info_init(struct nh_notifier_info *info,
+ const struct nexthop *nh)
+{
+ info->id = nh->id;
+ info->is_grp = nh->is_group;
+
+ if (info->is_grp)
+ return nh_notifier_grp_info_init(info, nh);
+ else
+ return nh_notifier_single_info_init(info, nh);
+}
+
+static void nh_notifier_info_fini(struct nh_notifier_info *info)
+{
+ if (info->is_grp)
+ nh_notifier_grp_info_fini(info);
+ else
+ nh_notifier_single_info_fini(info);
+}
+
static int call_nexthop_notifiers(struct net *net,
enum nexthop_event_type event_type,
struct nexthop *nh,
struct netlink_ext_ack *extack)
{
+ struct nh_notifier_info info = {
+ .net = net,
+ .extack = extack,
+ };
int err;
+ ASSERT_RTNL();
+
+ if (nexthop_notifiers_is_empty(net))
+ return 0;
+
+ err = nh_notifier_info_init(&info, nh);
+ if (err) {
+ NL_SET_ERR_MSG(extack, "Failed to initialize nexthop notifier info");
+ return err;
+ }
+
err = blocking_notifier_call_chain(&net->nexthop.notifier_chain,
event_type, nh);
+ nh_notifier_info_fini(&info);
+
return notifier_to_errno(err);
}
--
2.26.2
next prev parent reply other threads:[~2020-09-08 9:13 UTC|newest]
Thread overview: 56+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-08 9:10 [RFC PATCH net-next 00/22] nexthop: Add support for nexthop objects offload Ido Schimmel
2020-09-08 9:10 ` [RFC PATCH net-next 01/22] nexthop: Remove unused function declaration from header file Ido Schimmel
2020-09-08 14:29 ` David Ahern
2020-09-08 9:10 ` [RFC PATCH net-next 02/22] nexthop: Convert to blocking notification chain Ido Schimmel
2020-09-08 14:34 ` David Ahern
2020-09-08 9:10 ` [RFC PATCH net-next 03/22] nexthop: Only emit a notification when nexthop is actually deleted Ido Schimmel
2020-09-08 14:34 ` David Ahern
2020-09-08 14:39 ` Jiri Pirko
2020-09-08 14:42 ` David Ahern
2020-09-11 14:40 ` Ido Schimmel
2020-09-08 9:10 ` [RFC PATCH net-next 04/22] selftests: fib_nexthops: Test cleanup of FDB entries following nexthop deletion Ido Schimmel
2020-09-08 14:35 ` David Ahern
2020-09-08 9:10 ` [RFC PATCH net-next 05/22] nexthop: Add nexthop notification data structures Ido Schimmel
2020-09-08 14:43 ` David Ahern
2020-09-11 14:50 ` Ido Schimmel
2020-09-08 9:10 ` [RFC PATCH net-next 06/22] nexthop: Pass extack to nexthop notifier Ido Schimmel
2020-09-08 14:44 ` David Ahern
2020-09-08 9:10 ` Ido Schimmel [this message]
2020-09-08 14:55 ` [RFC PATCH net-next 07/22] nexthop: Prepare new notification info David Ahern
2020-09-11 15:01 ` Ido Schimmel
2020-09-08 9:10 ` [RFC PATCH net-next 08/22] nexthop: vxlan: Convert to " Ido Schimmel
2020-09-08 14:58 ` David Ahern
2020-09-11 15:05 ` Ido Schimmel
2020-09-08 9:10 ` [RFC PATCH net-next 09/22] rtnetlink: Add RTNH_F_TRAP flag Ido Schimmel
2020-09-08 15:02 ` David Ahern
2020-09-11 15:26 ` Ido Schimmel
2020-09-11 15:54 ` David Ahern
2020-09-08 9:10 ` [RFC PATCH net-next 10/22] nexthop: Allow setting "offload" and "trap" indications on nexthops Ido Schimmel
2020-09-08 15:14 ` David Ahern
2020-09-11 15:29 ` Ido Schimmel
2020-09-08 9:10 ` [RFC PATCH net-next 11/22] nexthop: Emit a notification when a nexthop is added Ido Schimmel
2020-09-08 15:21 ` David Ahern
2020-09-11 16:20 ` Ido Schimmel
2020-09-08 9:10 ` [RFC PATCH net-next 12/22] nexthop: Emit a notification when a nexthop group is replaced Ido Schimmel
2020-09-08 15:22 ` David Ahern
2020-09-08 9:10 ` [RFC PATCH net-next 13/22] nexthop: Emit a notification when a single nexthop " Ido Schimmel
2020-09-08 15:25 ` David Ahern
2020-09-11 16:24 ` Ido Schimmel
2020-09-08 9:10 ` [RFC PATCH net-next 14/22] nexthop: Emit a notification when a nexthop group is modified Ido Schimmel
2020-09-08 15:29 ` David Ahern
2020-09-08 9:10 ` [RFC PATCH net-next 15/22] nexthop: Emit a notification when a nexthop group is reduced Ido Schimmel
2020-09-08 15:33 ` David Ahern
2020-09-11 16:29 ` Ido Schimmel
2020-09-08 9:10 ` [RFC PATCH net-next 16/22] nexthop: Pass extack to register_nexthop_notifier() Ido Schimmel
2020-09-08 15:34 ` David Ahern
2020-09-08 9:10 ` [RFC PATCH net-next 17/22] nexthop: Replay nexthops when registering a notifier Ido Schimmel
2020-09-08 15:37 ` David Ahern
2020-09-11 16:40 ` Ido Schimmel
2020-09-11 16:47 ` David Ahern
2020-09-08 9:10 ` [RFC PATCH net-next 18/22] nexthop: Remove in-kernel route notifications when nexthop changes Ido Schimmel
2020-09-08 15:38 ` David Ahern
2020-09-08 9:10 ` [RFC PATCH net-next 19/22] netdevsim: Add devlink resource for nexthops Ido Schimmel
2020-09-08 9:10 ` [RFC PATCH net-next 20/22] netdevsim: Add dummy implementation for nexthop offload Ido Schimmel
2020-09-08 9:10 ` [RFC PATCH net-next 21/22] netdevsim: Allow programming routes with nexthop objects Ido Schimmel
2020-09-08 15:40 ` David Ahern
2020-09-08 9:10 ` [RFC PATCH net-next 22/22] selftests: netdevsim: Add test for nexthop offload API Ido Schimmel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200908091037.2709823-8-idosch@idosch.org \
--to=idosch@idosch.org \
--cc=davem@davemloft.net \
--cc=dsahern@gmail.com \
--cc=idosch@nvidia.com \
--cc=kuba@kernel.org \
--cc=mlxsw@nvidia.com \
--cc=netdev@vger.kernel.org \
--cc=roopa@nvidia.com \
--subject='Re: [RFC PATCH net-next 07/22] nexthop: Prepare new notification info' \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).