From: David Ahern <dsahern@kernel.org>
To: davem@davemloft.net, netdev@vger.kernel.org
Cc: idosch@mellanox.com, David Ahern <dsahern@gmail.com>
Subject: [PATCH net-next 3/8] ipv4: Move cached routes to fib_nh_common
Date: Fri, 29 Mar 2019 17:47:26 -0700 [thread overview]
Message-ID: <20190330004731.23959-4-dsahern@kernel.org> (raw)
In-Reply-To: <20190330004731.23959-1-dsahern@kernel.org>
From: David Ahern <dsahern@gmail.com>
While the cached routes, nh_pcpu_rth_output and nh_rth_input, are IPv4
specific, a later patch wants to make them accessible for IPv6
gateways with IPv4 routes but also allow IPv6 routes to have their own
cached entries. Move the IPv4 cached routes from fib_nh to fib_nh_common
and update references.
Signed-off-by: David Ahern <dsahern@gmail.com>
---
include/net/ip_fib.h | 6 ++++--
net/ipv4/fib_semantics.c | 33 +++++++++++++++++----------------
net/ipv4/route.c | 18 +++++++++---------
3 files changed, 30 insertions(+), 27 deletions(-)
diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
index 5070bc531ca4..cce437a1b2ff 100644
--- a/include/net/ip_fib.h
+++ b/include/net/ip_fib.h
@@ -92,6 +92,10 @@ struct fib_nh_common {
int nhc_weight;
atomic_t nhc_upper_bound;
+
+ /* v4 specific, but allows v6 gw with v4 routes */
+ struct rtable __rcu * __percpu *nhc_pcpu_rth_output;
+ struct rtable __rcu *nhc_rth_input;
};
struct fib_nh {
@@ -103,8 +107,6 @@ struct fib_nh {
#endif
__be32 nh_saddr;
int nh_saddr_genid;
- struct rtable __rcu * __percpu *nh_pcpu_rth_output;
- struct rtable __rcu *nh_rth_input;
struct fnhe_hash_bucket __rcu *nh_exceptions;
#define fib_nh_family nh_common.nhc_family
#define fib_nh_dev nh_common.nhc_dev
diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
index f81c7dc7ff59..e8c9208d35d2 100644
--- a/net/ipv4/fib_semantics.c
+++ b/net/ipv4/fib_semantics.c
@@ -210,6 +210,8 @@ void fib_nh_common_release(struct fib_nh_common *nhc)
dev_put(nhc->nhc_dev);
lwtstate_put(nhc->nhc_lwtstate);
+ rt_fibinfo_free_cpus(nhc->nhc_pcpu_rth_output);
+ rt_fibinfo_free(&nhc->nhc_rth_input);
}
EXPORT_SYMBOL_GPL(fib_nh_common_release);
@@ -221,8 +223,6 @@ void fib_nh_release(struct net *net, struct fib_nh *fib_nh)
#endif
fib_nh_common_release(&fib_nh->nh_common);
free_nh_exceptions(fib_nh);
- rt_fibinfo_free_cpus(fib_nh->nh_pcpu_rth_output);
- rt_fibinfo_free(&fib_nh->nh_rth_input);
}
/* Release a nexthop info record */
@@ -472,9 +472,15 @@ int fib_nh_common_init(struct fib_nh_common *nhc, struct nlattr *encap,
u16 encap_type, void *cfg, gfp_t gfp_flags,
struct netlink_ext_ack *extack)
{
+ int err;
+
+ nhc->nhc_pcpu_rth_output = alloc_percpu_gfp(struct rtable __rcu *,
+ gfp_flags);
+ if (!nhc->nhc_pcpu_rth_output)
+ return -ENOMEM;
+
if (encap) {
struct lwtunnel_state *lwtstate;
- int err;
if (encap_type == LWTUNNEL_ENCAP_NONE) {
NL_SET_ERR_MSG(extack, "LWT encap type not specified");
@@ -483,12 +489,17 @@ int fib_nh_common_init(struct fib_nh_common *nhc, struct nlattr *encap,
err = lwtunnel_build_state(encap_type, encap, nhc->nhc_family,
cfg, &lwtstate, extack);
if (err)
- return err;
+ goto lwt_failure;
nhc->nhc_lwtstate = lwtstate_get(lwtstate);
}
return 0;
+
+lwt_failure:
+ rt_fibinfo_free_cpus(nhc->nhc_pcpu_rth_output);
+ nhc->nhc_pcpu_rth_output = NULL;
+ return err;
}
EXPORT_SYMBOL_GPL(fib_nh_common_init);
@@ -496,18 +507,14 @@ int fib_nh_init(struct net *net, struct fib_nh *nh,
struct fib_config *cfg, int nh_weight,
struct netlink_ext_ack *extack)
{
- int err = -ENOMEM;
+ int err;
nh->fib_nh_family = AF_INET;
- nh->nh_pcpu_rth_output = alloc_percpu(struct rtable __rcu *);
- if (!nh->nh_pcpu_rth_output)
- goto err_out;
-
err = fib_nh_common_init(&nh->nh_common, cfg->fc_encap,
cfg->fc_encap_type, cfg, GFP_KERNEL, extack);
if (err)
- goto init_failure;
+ return err;
nh->fib_nh_oif = cfg->fc_oif;
if (cfg->fc_gw) {
@@ -525,12 +532,6 @@ int fib_nh_init(struct net *net, struct fib_nh *nh,
nh->fib_nh_weight = nh_weight;
#endif
return 0;
-
-init_failure:
- rt_fibinfo_free_cpus(nh->nh_pcpu_rth_output);
- nh->nh_pcpu_rth_output = NULL;
-err_out:
- return err;
}
#ifdef CONFIG_IP_ROUTE_MULTIPATH
diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index 3556d87558e6..60d525391908 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -637,6 +637,7 @@ static void fill_route_from_fnhe(struct rtable *rt, struct fib_nh_exception *fnh
static void update_or_create_fnhe(struct fib_nh *nh, __be32 daddr, __be32 gw,
u32 pmtu, bool lock, unsigned long expires)
{
+ struct fib_nh_common *nhc = &nh->nh_common;
struct fnhe_hash_bucket *hash;
struct fib_nh_exception *fnhe;
struct rtable *rt;
@@ -706,13 +707,13 @@ static void update_or_create_fnhe(struct fib_nh *nh, __be32 daddr, __be32 gw,
* stale, so anyone caching it rechecks if this exception
* applies to them.
*/
- rt = rcu_dereference(nh->nh_rth_input);
+ rt = rcu_dereference(nhc->nhc_rth_input);
if (rt)
rt->dst.obsolete = DST_OBSOLETE_KILL;
for_each_possible_cpu(i) {
struct rtable __rcu **prt;
- prt = per_cpu_ptr(nh->nh_pcpu_rth_output, i);
+ prt = per_cpu_ptr(nhc->nhc_pcpu_rth_output, i);
rt = rcu_dereference(*prt);
if (rt)
rt->dst.obsolete = DST_OBSOLETE_KILL;
@@ -1432,13 +1433,14 @@ static bool rt_bind_exception(struct rtable *rt, struct fib_nh_exception *fnhe,
static bool rt_cache_route(struct fib_nh *nh, struct rtable *rt)
{
+ struct fib_nh_common *nhc = &nh->nh_common;
struct rtable *orig, *prev, **p;
bool ret = true;
if (rt_is_input_route(rt)) {
- p = (struct rtable **)&nh->nh_rth_input;
+ p = (struct rtable **)&nhc->nhc_rth_input;
} else {
- p = (struct rtable **)raw_cpu_ptr(nh->nh_pcpu_rth_output);
+ p = (struct rtable **)raw_cpu_ptr(nhc->nhc_pcpu_rth_output);
}
orig = *p;
@@ -1762,7 +1764,7 @@ static int __mkroute_input(struct sk_buff *skb,
if (fnhe)
rth = rcu_dereference(fnhe->fnhe_rth_input);
else
- rth = rcu_dereference(nh->nh_rth_input);
+ rth = rcu_dereference(nhc->nhc_rth_input);
if (rt_cache_valid(rth)) {
skb_dst_set_noref(skb, &rth->dst);
goto out;
@@ -2057,10 +2059,8 @@ out: return err;
if (res->fi) {
if (!itag) {
struct fib_nh_common *nhc = FIB_RES_NH(*res);
- struct fib_nh *nh;
- nh = container_of(nhc, struct fib_nh, nh_common);
- rth = rcu_dereference(nh->nh_rth_input);
+ rth = rcu_dereference(nhc->nhc_rth_input);
if (rt_cache_valid(rth)) {
skb_dst_set_noref(skb, &rth->dst);
err = 0;
@@ -2289,7 +2289,7 @@ static struct rtable *__mkroute_output(const struct fib_result *res,
do_cache = false;
goto add;
}
- prth = raw_cpu_ptr(nh->nh_pcpu_rth_output);
+ prth = raw_cpu_ptr(nhc->nhc_pcpu_rth_output);
}
rth = rcu_dereference(*prth);
if (rt_cache_valid(rth) && dst_hold_safe(&rth->dst))
--
2.11.0
next prev parent reply other threads:[~2019-03-30 0:47 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-30 0:47 [PATCH net-next 0/8] net: More movement to fib_nh_common David Ahern
2019-03-30 0:47 ` [PATCH net-next 1/8] ipv4: Update fib_table_lookup tracepoint to take common nexthop David Ahern
2019-03-30 0:47 ` [PATCH net-next 2/8] ipv4: Add fib_nh_common to fib_result David Ahern
2019-03-30 0:47 ` David Ahern [this message]
2019-03-31 0:11 ` [PATCH net-next 3/8] ipv4: Move cached routes to fib_nh_common David Ahern
2019-03-31 1:41 ` David Miller
2019-03-30 0:47 ` [PATCH net-next 4/8] ipv6: Move exceptions " David Ahern
2019-03-30 0:47 ` [PATCH net-next 5/8] ipv4: Switch to nhc_exceptions for exception bucket David Ahern
2019-03-30 0:47 ` [PATCH net-next 6/8] ipv4: Refactor nexthop attributes in fib_dump_info David Ahern
2019-03-30 0:47 ` [PATCH net-next 7/8] ipv4: Change fib_nexthop_info and fib_add_nexthop to take fib_nh_common David Ahern
2019-03-30 0:47 ` [PATCH net-next 8/8] ipv6: Flip to fib_nexthop_info David Ahern
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=20190330004731.23959-4-dsahern@kernel.org \
--to=dsahern@kernel.org \
--cc=davem@davemloft.net \
--cc=dsahern@gmail.com \
--cc=idosch@mellanox.com \
--cc=netdev@vger.kernel.org \
/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
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).