inetdevice.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. #ifndef _LINUX_INETDEVICE_H
  2. #define _LINUX_INETDEVICE_H
  3. #ifdef __KERNEL__
  4. #include <linux/if.h>
  5. #include <linux/netdevice.h>
  6. #include <linux/rcupdate.h>
  7. #include <linux/timer.h>
  8. struct ipv4_devconf
  9. {
  10. int accept_redirects;
  11. int send_redirects;
  12. int secure_redirects;
  13. int shared_media;
  14. int accept_source_route;
  15. int rp_filter;
  16. int proxy_arp;
  17. int bootp_relay;
  18. int log_martians;
  19. int forwarding;
  20. int mc_forwarding;
  21. int tag;
  22. int arp_filter;
  23. int arp_announce;
  24. int arp_ignore;
  25. int arp_accept;
  26. int medium_id;
  27. int no_xfrm;
  28. int no_policy;
  29. int force_igmp_version;
  30. int promote_secondaries;
  31. void *sysctl;
  32. };
  33. extern struct ipv4_devconf ipv4_devconf;
  34. struct in_device
  35. {
  36. struct net_device *dev;
  37. atomic_t refcnt;
  38. int dead;
  39. struct in_ifaddr *ifa_list; /* IP ifaddr chain */
  40. rwlock_t mc_list_lock;
  41. struct ip_mc_list *mc_list; /* IP multicast filter chain */
  42. spinlock_t mc_tomb_lock;
  43. struct ip_mc_list *mc_tomb;
  44. unsigned long mr_v1_seen;
  45. unsigned long mr_v2_seen;
  46. unsigned long mr_maxdelay;
  47. unsigned char mr_qrv;
  48. unsigned char mr_gq_running;
  49. unsigned char mr_ifc_count;
  50. struct timer_list mr_gq_timer; /* general query timer */
  51. struct timer_list mr_ifc_timer; /* interface change timer */
  52. struct neigh_parms *arp_parms;
  53. struct ipv4_devconf cnf;
  54. struct rcu_head rcu_head;
  55. };
  56. #define IN_DEV_FORWARD(in_dev) ((in_dev)->cnf.forwarding)
  57. #define IN_DEV_MFORWARD(in_dev) (ipv4_devconf.mc_forwarding && (in_dev)->cnf.mc_forwarding)
  58. #define IN_DEV_RPFILTER(in_dev) (ipv4_devconf.rp_filter && (in_dev)->cnf.rp_filter)
  59. #define IN_DEV_SOURCE_ROUTE(in_dev) (ipv4_devconf.accept_source_route && (in_dev)->cnf.accept_source_route)
  60. #define IN_DEV_BOOTP_RELAY(in_dev) (ipv4_devconf.bootp_relay && (in_dev)->cnf.bootp_relay)
  61. #define IN_DEV_LOG_MARTIANS(in_dev) (ipv4_devconf.log_martians || (in_dev)->cnf.log_martians)
  62. #define IN_DEV_PROXY_ARP(in_dev) (ipv4_devconf.proxy_arp || (in_dev)->cnf.proxy_arp)
  63. #define IN_DEV_SHARED_MEDIA(in_dev) (ipv4_devconf.shared_media || (in_dev)->cnf.shared_media)
  64. #define IN_DEV_TX_REDIRECTS(in_dev) (ipv4_devconf.send_redirects || (in_dev)->cnf.send_redirects)
  65. #define IN_DEV_SEC_REDIRECTS(in_dev) (ipv4_devconf.secure_redirects || (in_dev)->cnf.secure_redirects)
  66. #define IN_DEV_IDTAG(in_dev) ((in_dev)->cnf.tag)
  67. #define IN_DEV_MEDIUM_ID(in_dev) ((in_dev)->cnf.medium_id)
  68. #define IN_DEV_PROMOTE_SECONDARIES(in_dev) (ipv4_devconf.promote_secondaries || (in_dev)->cnf.promote_secondaries)
  69. #define IN_DEV_RX_REDIRECTS(in_dev) \
  70. ((IN_DEV_FORWARD(in_dev) && \
  71. (ipv4_devconf.accept_redirects && (in_dev)->cnf.accept_redirects)) \
  72. || (!IN_DEV_FORWARD(in_dev) && \
  73. (ipv4_devconf.accept_redirects || (in_dev)->cnf.accept_redirects)))
  74. #define IN_DEV_ARPFILTER(in_dev) (ipv4_devconf.arp_filter || (in_dev)->cnf.arp_filter)
  75. #define IN_DEV_ARP_ANNOUNCE(in_dev) (max(ipv4_devconf.arp_announce, (in_dev)->cnf.arp_announce))
  76. #define IN_DEV_ARP_IGNORE(in_dev) (max(ipv4_devconf.arp_ignore, (in_dev)->cnf.arp_ignore))
  77. struct in_ifaddr
  78. {
  79. struct in_ifaddr *ifa_next;
  80. struct in_device *ifa_dev;
  81. struct rcu_head rcu_head;
  82. __be32 ifa_local;
  83. __be32 ifa_address;
  84. __be32 ifa_mask;
  85. __be32 ifa_broadcast;
  86. __be32 ifa_anycast;
  87. unsigned char ifa_scope;
  88. unsigned char ifa_flags;
  89. unsigned char ifa_prefixlen;
  90. char ifa_label[IFNAMSIZ];
  91. };
  92. extern int register_inetaddr_notifier(struct notifier_block *nb);
  93. extern int unregister_inetaddr_notifier(struct notifier_block *nb);
  94. extern struct net_device *ip_dev_find(__be32 addr);
  95. extern int inet_addr_onlink(struct in_device *in_dev, __be32 a, __be32 b);
  96. extern int devinet_ioctl(unsigned int cmd, void __user *);
  97. extern void devinet_init(void);
  98. extern struct in_device *inetdev_init(struct net_device *dev);
  99. extern struct in_device *inetdev_by_index(int);
  100. extern __be32 inet_select_addr(const struct net_device *dev, __be32 dst, int scope);
  101. extern __be32 inet_confirm_addr(const struct net_device *dev, __be32 dst, __be32 local, int scope);
  102. extern struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix, __be32 mask);
  103. extern void inet_forward_change(void);
  104. static __inline__ int inet_ifa_match(__be32 addr, struct in_ifaddr *ifa)
  105. {
  106. return !((addr^ifa->ifa_address)&ifa->ifa_mask);
  107. }
  108. /*
  109. * Check if a mask is acceptable.
  110. */
  111. static __inline__ int bad_mask(__be32 mask, __be32 addr)
  112. {
  113. __u32 hmask;
  114. if (addr & (mask = ~mask))
  115. return 1;
  116. hmask = ntohl(mask);
  117. if (hmask & (hmask+1))
  118. return 1;
  119. return 0;
  120. }
  121. #define for_primary_ifa(in_dev) { struct in_ifaddr *ifa; \
  122. for (ifa = (in_dev)->ifa_list; ifa && !(ifa->ifa_flags&IFA_F_SECONDARY); ifa = ifa->ifa_next)
  123. #define for_ifa(in_dev) { struct in_ifaddr *ifa; \
  124. for (ifa = (in_dev)->ifa_list; ifa; ifa = ifa->ifa_next)
  125. #define endfor_ifa(in_dev) }
  126. static inline struct in_device *__in_dev_get_rcu(const struct net_device *dev)
  127. {
  128. struct in_device *in_dev = dev->ip_ptr;
  129. if (in_dev)
  130. in_dev = rcu_dereference(in_dev);
  131. return in_dev;
  132. }
  133. static __inline__ struct in_device *
  134. in_dev_get(const struct net_device *dev)
  135. {
  136. struct in_device *in_dev;
  137. rcu_read_lock();
  138. in_dev = __in_dev_get_rcu(dev);
  139. if (in_dev)
  140. atomic_inc(&in_dev->refcnt);
  141. rcu_read_unlock();
  142. return in_dev;
  143. }
  144. static __inline__ struct in_device *
  145. __in_dev_get_rtnl(const struct net_device *dev)
  146. {
  147. return (struct in_device*)dev->ip_ptr;
  148. }
  149. extern void in_dev_finish_destroy(struct in_device *idev);
  150. static inline void in_dev_put(struct in_device *idev)
  151. {
  152. if (atomic_dec_and_test(&idev->refcnt))
  153. in_dev_finish_destroy(idev);
  154. }
  155. #define __in_dev_put(idev) atomic_dec(&(idev)->refcnt)
  156. #define in_dev_hold(idev) atomic_inc(&(idev)->refcnt)
  157. #endif /* __KERNEL__ */
  158. static __inline__ __be32 inet_make_mask(int logmask)
  159. {
  160. if (logmask)
  161. return htonl(~((1<<(32-logmask))-1));
  162. return 0;
  163. }
  164. static __inline__ int inet_mask_len(__be32 mask)
  165. {
  166. __u32 hmask = ntohl(mask);
  167. if (!hmask)
  168. return 0;
  169. return 32 - ffz(~hmask);
  170. }
  171. #endif /* _LINUX_INETDEVICE_H */