From 88ca8a6cd68201e0b3ee0dc7ce4f8a98d9be0d19 Mon Sep 17 00:00:00 2001 From: Vignesh Saravanaperumal Date: Thu, 8 Jul 2021 12:00:53 -0700 Subject: [PATCH] ANDROID: GKI: net: add vendor hooks for 'struct nf_conn' lifecycle Some vendors want to add a field when a 'sruct nf_conn' is added so give a hook to handle this. Any memory allocated when trace_android_rvh_nf_conn_alloc() is called needs to be freed when trace_android_rvh_nf_conn_free() is called. Note, if trace_android_rvh_nf_conn_alloc() fails, be sure to be able to handle this in trace_android_rvh_nf_conn_free(), but that should not be an issue as that needs to be addressed in vendor code that runs for 'struct nf_conn' objects that have been created before the vendor code is loaded no matter what. Bug: 171013716 Signed-off-by: Vignesh Saravanaperumal Change-Id: I4d2b025196a3df7ba4adec313c90483811cac728 --- drivers/android/vendor_hooks.c | 2 ++ include/trace/hooks/net.h | 6 ++++++ net/netfilter/nf_conntrack_core.c | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/drivers/android/vendor_hooks.c b/drivers/android/vendor_hooks.c index 45623e0d1e8b..55f2f4ab98ec 100644 --- a/drivers/android/vendor_hooks.c +++ b/drivers/android/vendor_hooks.c @@ -86,6 +86,8 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_prepare_prio_fork); EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_finish_prio_fork); EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_set_user_nice); EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_setscheduler); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_nf_conn_alloc); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_nf_conn_free); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_arch_set_freq_scale); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_is_fpsimd_save); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_binder_transaction_init); diff --git a/include/trace/hooks/net.h b/include/trace/hooks/net.h index acbb456d184b..687474a1dcb1 100644 --- a/include/trace/hooks/net.h +++ b/include/trace/hooks/net.h @@ -17,6 +17,12 @@ DECLARE_HOOK(android_vh_ptype_head, DECLARE_HOOK(android_vh_kfree_skb, TP_PROTO(struct sk_buff *skb), TP_ARGS(skb)); +struct nf_conn; +DECLARE_RESTRICTED_HOOK(android_rvh_nf_conn_alloc, + TP_PROTO(struct nf_conn *nf_conn), TP_ARGS(nf_conn), 1); +DECLARE_RESTRICTED_HOOK(android_rvh_nf_conn_free, + TP_PROTO(struct nf_conn *nf_conn), TP_ARGS(nf_conn), 1); + /* macro versions of hooks are no longer required */ #endif /* _TRACE_HOOK_NET_VH_H */ diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c index 31399c53dfb1..dd9bf6e25a94 100644 --- a/net/netfilter/nf_conntrack_core.c +++ b/net/netfilter/nf_conntrack_core.c @@ -32,6 +32,7 @@ #include #include #include +#include #include #include @@ -1619,6 +1620,8 @@ __nf_conntrack_alloc(struct net *net, nf_ct_zone_add(ct, zone); + trace_android_rvh_nf_conn_alloc(ct); + /* Because we use RCU lookups, we set ct_general.use to zero before * this is inserted in any list. */ @@ -1654,6 +1657,7 @@ void nf_conntrack_free(struct nf_conn *ct) cnet = nf_ct_pernet(net); smp_mb__before_atomic(); + trace_android_rvh_nf_conn_free(ct); atomic_dec(&cnet->count); } EXPORT_SYMBOL_GPL(nf_conntrack_free);