![]() |
|
|||
0001 /* SPDX-License-Identifier: GPL-2.0 */ 0002 /* 0003 * generic net pointers 0004 */ 0005 0006 #ifndef __NET_GENERIC_H__ 0007 #define __NET_GENERIC_H__ 0008 0009 #include <linux/bug.h> 0010 #include <linux/rcupdate.h> 0011 #include <net/net_namespace.h> 0012 0013 /* 0014 * Generic net pointers are to be used by modules to put some private 0015 * stuff on the struct net without explicit struct net modification 0016 * 0017 * The rules are simple: 0018 * 1. set pernet_operations->id. After register_pernet_device you 0019 * will have the id of your private pointer. 0020 * 2. set pernet_operations->size to have the code allocate and free 0021 * a private structure pointed to from struct net. 0022 * 3. do not change this pointer while the net is alive; 0023 * 4. do not try to have any private reference on the net_generic object. 0024 * 0025 * After accomplishing all of the above, the private pointer can be 0026 * accessed with the net_generic() call. 0027 */ 0028 0029 struct net_generic { 0030 union { 0031 struct { 0032 unsigned int len; 0033 struct rcu_head rcu; 0034 } s; 0035 0036 void *ptr[0]; 0037 }; 0038 }; 0039 0040 static inline void *net_generic(const struct net *net, unsigned int id) 0041 { 0042 struct net_generic *ng; 0043 void *ptr; 0044 0045 rcu_read_lock(); 0046 ng = rcu_dereference(net->gen); 0047 ptr = ng->ptr[id]; 0048 rcu_read_unlock(); 0049 0050 return ptr; 0051 } 0052 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |