diff options
author | Eric Dumazet <eric.dumazet@gmail.com> | 2010-09-21 02:57:39 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2010-09-21 21:04:47 -0400 |
commit | 48daa3bb84d547828871534caa51427a3fe90748 (patch) | |
tree | 14b51ebc846bc0edecbbde028480ece59da53958 /include/net/addrconf.h | |
parent | 756e64a0b106f1a2ca96889c39ea0d48131105c0 (diff) |
ipv6: addrconf.h cleanups
- Use rcu_dereference_rtnl() in __in6_dev_get
- kerneldoc for __in6_dev_get() and in6_dev_get()
- Use inline functions instead of macros
Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include/net/addrconf.h')
-rw-r--r-- | include/net/addrconf.h | 63 |
1 files changed, 43 insertions, 20 deletions
diff --git a/include/net/addrconf.h b/include/net/addrconf.h index 45375b41a2a0..7d178a758acf 100644 --- a/include/net/addrconf.h +++ b/include/net/addrconf.h | |||
@@ -174,20 +174,32 @@ extern int ipv6_chk_acast_addr(struct net *net, struct net_device *dev, | |||
174 | extern int register_inet6addr_notifier(struct notifier_block *nb); | 174 | extern int register_inet6addr_notifier(struct notifier_block *nb); |
175 | extern int unregister_inet6addr_notifier(struct notifier_block *nb); | 175 | extern int unregister_inet6addr_notifier(struct notifier_block *nb); |
176 | 176 | ||
177 | static inline struct inet6_dev * | 177 | /** |
178 | __in6_dev_get(struct net_device *dev) | 178 | * __in6_dev_get - get inet6_dev pointer from netdevice |
179 | * @dev: network device | ||
180 | * | ||
181 | * Caller must hold rcu_read_lock or RTNL, because this function | ||
182 | * does not take a reference on the inet6_dev. | ||
183 | */ | ||
184 | static inline struct inet6_dev *__in6_dev_get(const struct net_device *dev) | ||
179 | { | 185 | { |
180 | return rcu_dereference_check(dev->ip6_ptr, | 186 | return rcu_dereference_rtnl(dev->ip6_ptr); |
181 | rcu_read_lock_held() || | ||
182 | lockdep_rtnl_is_held()); | ||
183 | } | 187 | } |
184 | 188 | ||
185 | static inline struct inet6_dev * | 189 | /** |
186 | in6_dev_get(struct net_device *dev) | 190 | * in6_dev_get - get inet6_dev pointer from netdevice |
191 | * @dev: network device | ||
192 | * | ||
193 | * This version can be used in any context, and takes a reference | ||
194 | * on the inet6_dev. Callers must use in6_dev_put() later to | ||
195 | * release this reference. | ||
196 | */ | ||
197 | static inline struct inet6_dev *in6_dev_get(const struct net_device *dev) | ||
187 | { | 198 | { |
188 | struct inet6_dev *idev = NULL; | 199 | struct inet6_dev *idev; |
200 | |||
189 | rcu_read_lock(); | 201 | rcu_read_lock(); |
190 | idev = __in6_dev_get(dev); | 202 | idev = rcu_dereference(dev->ip6_ptr); |
191 | if (idev) | 203 | if (idev) |
192 | atomic_inc(&idev->refcnt); | 204 | atomic_inc(&idev->refcnt); |
193 | rcu_read_unlock(); | 205 | rcu_read_unlock(); |
@@ -196,16 +208,21 @@ in6_dev_get(struct net_device *dev) | |||
196 | 208 | ||
197 | extern void in6_dev_finish_destroy(struct inet6_dev *idev); | 209 | extern void in6_dev_finish_destroy(struct inet6_dev *idev); |
198 | 210 | ||
199 | static inline void | 211 | static inline void in6_dev_put(struct inet6_dev *idev) |
200 | in6_dev_put(struct inet6_dev *idev) | ||
201 | { | 212 | { |
202 | if (atomic_dec_and_test(&idev->refcnt)) | 213 | if (atomic_dec_and_test(&idev->refcnt)) |
203 | in6_dev_finish_destroy(idev); | 214 | in6_dev_finish_destroy(idev); |
204 | } | 215 | } |
205 | 216 | ||
206 | #define __in6_dev_put(idev) atomic_dec(&(idev)->refcnt) | 217 | static inline void __in6_dev_put(struct inet6_dev *idev) |
207 | #define in6_dev_hold(idev) atomic_inc(&(idev)->refcnt) | 218 | { |
219 | atomic_dec(&idev->refcnt); | ||
220 | } | ||
208 | 221 | ||
222 | static inline void in6_dev_hold(struct inet6_dev *idev) | ||
223 | { | ||
224 | atomic_inc(&idev->refcnt); | ||
225 | } | ||
209 | 226 | ||
210 | extern void inet6_ifa_finish_destroy(struct inet6_ifaddr *ifp); | 227 | extern void inet6_ifa_finish_destroy(struct inet6_ifaddr *ifp); |
211 | 228 | ||
@@ -215,9 +232,15 @@ static inline void in6_ifa_put(struct inet6_ifaddr *ifp) | |||
215 | inet6_ifa_finish_destroy(ifp); | 232 | inet6_ifa_finish_destroy(ifp); |
216 | } | 233 | } |
217 | 234 | ||
218 | #define __in6_ifa_put(ifp) atomic_dec(&(ifp)->refcnt) | 235 | static inline void __in6_ifa_put(struct inet6_ifaddr *ifp) |
219 | #define in6_ifa_hold(ifp) atomic_inc(&(ifp)->refcnt) | 236 | { |
237 | atomic_dec(&ifp->refcnt); | ||
238 | } | ||
220 | 239 | ||
240 | static inline void in6_ifa_hold(struct inet6_ifaddr *ifp) | ||
241 | { | ||
242 | atomic_inc(&ifp->refcnt); | ||
243 | } | ||
221 | 244 | ||
222 | 245 | ||
223 | /* | 246 | /* |
@@ -240,23 +263,23 @@ static inline int ipv6_addr_is_multicast(const struct in6_addr *addr) | |||
240 | 263 | ||
241 | static inline int ipv6_addr_is_ll_all_nodes(const struct in6_addr *addr) | 264 | static inline int ipv6_addr_is_ll_all_nodes(const struct in6_addr *addr) |
242 | { | 265 | { |
243 | return (((addr->s6_addr32[0] ^ htonl(0xff020000)) | | 266 | return ((addr->s6_addr32[0] ^ htonl(0xff020000)) | |
244 | addr->s6_addr32[1] | addr->s6_addr32[2] | | 267 | addr->s6_addr32[1] | addr->s6_addr32[2] | |
245 | (addr->s6_addr32[3] ^ htonl(0x00000001))) == 0); | 268 | (addr->s6_addr32[3] ^ htonl(0x00000001))) == 0; |
246 | } | 269 | } |
247 | 270 | ||
248 | static inline int ipv6_addr_is_ll_all_routers(const struct in6_addr *addr) | 271 | static inline int ipv6_addr_is_ll_all_routers(const struct in6_addr *addr) |
249 | { | 272 | { |
250 | return (((addr->s6_addr32[0] ^ htonl(0xff020000)) | | 273 | return ((addr->s6_addr32[0] ^ htonl(0xff020000)) | |
251 | addr->s6_addr32[1] | addr->s6_addr32[2] | | 274 | addr->s6_addr32[1] | addr->s6_addr32[2] | |
252 | (addr->s6_addr32[3] ^ htonl(0x00000002))) == 0); | 275 | (addr->s6_addr32[3] ^ htonl(0x00000002))) == 0; |
253 | } | 276 | } |
254 | 277 | ||
255 | extern int __ipv6_isatap_ifid(u8 *eui, __be32 addr); | 278 | extern int __ipv6_isatap_ifid(u8 *eui, __be32 addr); |
256 | 279 | ||
257 | static inline int ipv6_addr_is_isatap(const struct in6_addr *addr) | 280 | static inline int ipv6_addr_is_isatap(const struct in6_addr *addr) |
258 | { | 281 | { |
259 | return ((addr->s6_addr32[2] | htonl(0x02000000)) == htonl(0x02005EFE)); | 282 | return (addr->s6_addr32[2] | htonl(0x02000000)) == htonl(0x02005EFE); |
260 | } | 283 | } |
261 | 284 | ||
262 | #ifdef CONFIG_PROC_FS | 285 | #ifdef CONFIG_PROC_FS |