inetdevice.h 5.5 KB

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