1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * Based on include/net/addrconf.h 4 * No Authors, no Copyright 5 */ 6 #ifndef _NIP_ADDRCONF_H 7 #define _NIP_ADDRCONF_H 8 9 #include <net/if_ninet.h> 10 #include <net/nip.h> 11 12 #include <linux/in.h> 13 #include <linux/in6.h> 14 #include <linux/netdevice.h> 15 16 #define ADDRCONF_NOTIFY_PRIORITY 0 17 #define NIN_ADDR_HSIZE_SHIFT (4) 18 #define NIN_ADDR_HSIZE (1 << NIN_ADDR_HSIZE_SHIFT) 19 20 #define DST_HOST 0x0001 /* NIP */ 21 22 int nip_addrconf_add_ifaddr(struct net *net, void __user *arg); 23 int nip_addrconf_del_ifaddr(struct net *net, void __user *arg); 24 25 int nip_dev_get_saddr(struct net *net, const struct net_device *dev, 26 const struct nip_addr *daddr, struct nip_addr *saddr); 27 28 int nip_addrconf_init(void); 29 void nip_addrconf_cleanup(void); 30 void nip_addr_to_str(const struct nip_addr *addr, unsigned char *buf, int buf_len); 31 32 /** 33 * __nin_dev_get - get ninet_dev pointer from netdevice 34 * @dev: network device 35 * 36 * Caller must hold rcu_read_lock or RTNL, because this function 37 * does not take a reference on the ninet_dev. 38 */ __nin_dev_get(const struct net_device * dev)39static inline struct ninet_dev *__nin_dev_get(const struct net_device *dev) 40 { 41 return rcu_dereference_rtnl(dev->nip_ptr); 42 } 43 44 /** 45 * nin_dev_get - get ninet_dev pointer from netdevice 46 * @dev: network device 47 */ nin_dev_get(const struct net_device * dev)48static inline struct ninet_dev *nin_dev_get(const struct net_device *dev) 49 { 50 struct ninet_dev *idev; 51 52 rcu_read_lock(); 53 idev = rcu_dereference(dev->nip_ptr); 54 if (idev) 55 refcount_inc(&idev->refcnt); 56 rcu_read_unlock(); 57 return idev; 58 } 59 __nin_dev_nd_parms_get_rcu(const struct net_device * dev)60static inline struct neigh_parms *__nin_dev_nd_parms_get_rcu( 61 const struct net_device *dev) 62 { 63 struct ninet_dev *idev = __nin_dev_get(dev); 64 65 return idev ? idev->nd_parms : NULL; 66 } 67 68 void nin_dev_finish_destroy(struct ninet_dev *idev); 69 nin_dev_put(struct ninet_dev * idev)70static inline void nin_dev_put(struct ninet_dev *idev) 71 { 72 if (refcount_dec_and_test(&idev->refcnt)) 73 nin_dev_finish_destroy(idev); 74 } 75 nin_dev_put_clear(struct ninet_dev ** pidev)76static inline void nin_dev_put_clear(struct ninet_dev **pidev) 77 { 78 struct ninet_dev *idev = *pidev; 79 80 if (idev) { 81 nin_dev_put(idev); 82 *pidev = NULL; 83 } 84 } 85 __nin_dev_put(struct ninet_dev * idev)86static inline void __nin_dev_put(struct ninet_dev *idev) 87 { 88 refcount_dec(&idev->refcnt); 89 } 90 nin_dev_hold(struct ninet_dev * idev)91static inline void nin_dev_hold(struct ninet_dev *idev) 92 { 93 refcount_inc(&idev->refcnt); 94 } 95 96 void ninet_ifa_finish_destroy(struct ninet_ifaddr *ifp); 97 nin_ifa_put(struct ninet_ifaddr * ifp)98static inline void nin_ifa_put(struct ninet_ifaddr *ifp) 99 { 100 if (refcount_dec_and_test(&ifp->refcnt)) 101 ninet_ifa_finish_destroy(ifp); 102 } 103 __nin_ifa_put(struct ninet_ifaddr * ifp)104static inline void __nin_ifa_put(struct ninet_ifaddr *ifp) 105 { 106 refcount_dec(&ifp->refcnt); 107 } 108 nin_ifa_hold(struct ninet_ifaddr * ifp)109static inline void nin_ifa_hold(struct ninet_ifaddr *ifp) 110 { 111 refcount_inc(&ifp->refcnt); 112 } 113 114 #endif 115