From: Tom Herbert <tom@herbertland•com>
To: <davem@davemloft•net>, <netdev@vger•kernel.org>,
<roopa@cumulusnetworks•com>
Cc: <kernel-team@fb•com>
Subject: [PATCH net-next 1/2] lwtunnel: Add destroy state operation
Date: Thu, 13 Oct 2016 17:57:42 -0700 [thread overview]
Message-ID: <20161014005743.288956-2-tom@herbertland.com> (raw)
In-Reply-To: <20161014005743.288956-1-tom@herbertland.com>
Users of lwt tunnels may set up some secondary state in build_state
function. Add a corresponding destroy_state function to allow users to
clean up state. This destroy state function is called from lwstate_free.
Also, we now free lwstate using kfree_rcu so user can assume structure
is not freed before rcu.
Signed-off-by: Tom Herbert <tom@herbertland•com>
---
include/net/lwtunnel.h | 7 +++----
net/core/lwtunnel.c | 13 +++++++++++++
2 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/include/net/lwtunnel.h b/include/net/lwtunnel.h
index ea3f80f..119b11b 100644
--- a/include/net/lwtunnel.h
+++ b/include/net/lwtunnel.h
@@ -29,6 +29,7 @@ struct lwtunnel_state {
int (*orig_input)(struct sk_buff *);
int len;
__u16 headroom;
+ struct rcu_head rcu;
__u8 data[0];
};
@@ -43,13 +44,11 @@ struct lwtunnel_encap_ops {
int (*get_encap_size)(struct lwtunnel_state *lwtstate);
int (*cmp_encap)(struct lwtunnel_state *a, struct lwtunnel_state *b);
int (*xmit)(struct sk_buff *skb);
+ void (*destroy_state)(struct lwtunnel_state *lws);
};
#ifdef CONFIG_LWTUNNEL
-static inline void lwtstate_free(struct lwtunnel_state *lws)
-{
- kfree(lws);
-}
+void lwtstate_free(struct lwtunnel_state *lws);
static inline struct lwtunnel_state *
lwtstate_get(struct lwtunnel_state *lws)
diff --git a/net/core/lwtunnel.c b/net/core/lwtunnel.c
index e5f84c2..7401474 100644
--- a/net/core/lwtunnel.c
+++ b/net/core/lwtunnel.c
@@ -130,6 +130,19 @@ int lwtunnel_build_state(struct net_device *dev, u16 encap_type,
}
EXPORT_SYMBOL(lwtunnel_build_state);
+void lwtstate_free(struct lwtunnel_state *lws)
+{
+ const struct lwtunnel_encap_ops *ops = lwtun_encaps[lws->type];
+
+ if (ops->destroy_state) {
+ ops->destroy_state(lws);
+ kfree_rcu(lws, rcu);
+ } else {
+ kfree(lws);
+ }
+}
+EXPORT_SYMBOL(lwtstate_free);
+
int lwtunnel_fill_encap(struct sk_buff *skb, struct lwtunnel_state *lwtstate)
{
const struct lwtunnel_encap_ops *ops;
--
2.9.3
next prev parent reply other threads:[~2016-10-14 1:00 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-14 0:57 [PATCH net-next 0/2] ila: Cache a route in ILA lwt structure Tom Herbert
2016-10-14 0:57 ` Tom Herbert [this message]
2016-10-14 5:58 ` [PATCH net-next 1/2] lwtunnel: Add destroy state operation Roopa Prabhu
2016-10-14 8:59 ` Jiri Benc
2016-10-14 15:15 ` David Miller
2016-10-14 0:57 ` [PATCH net-next 2/2] ila: Cache a route to translated address Tom Herbert
2016-10-14 6:22 ` Roopa Prabhu
2016-10-14 9:04 ` Jiri Benc
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=20161014005743.288956-2-tom@herbertland.com \
--to=tom@herbertland$(echo .)com \
--cc=davem@davemloft$(echo .)net \
--cc=kernel-team@fb$(echo .)com \
--cc=netdev@vger$(echo .)kernel.org \
--cc=roopa@cumulusnetworks$(echo .)com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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