more debug output
[linux-2.4.git] / include / net / addrconf.h
1 #ifndef _ADDRCONF_H
2 #define _ADDRCONF_H
3
4 #define RETRANS_TIMER   HZ
5
6 #define MAX_RTR_SOLICITATIONS           3
7 #define RTR_SOLICITATION_INTERVAL       (4*HZ)
8
9 #define ADDR_CHECK_FREQUENCY            (120*HZ)
10
11 struct prefix_info {
12         __u8                    type;
13         __u8                    length;
14         __u8                    prefix_len;
15
16 #if defined(__BIG_ENDIAN_BITFIELD)
17         __u8                    onlink : 1,
18                                 autoconf : 1,
19                                 reserved : 6;
20 #elif defined(__LITTLE_ENDIAN_BITFIELD)
21         __u8                    reserved : 6,
22                                 autoconf : 1,
23                                 onlink : 1;
24 #else
25 #error "Please fix <asm/byteorder.h>"
26 #endif
27         __u32                   valid;
28         __u32                   prefered;
29         __u32                   reserved2;
30
31         struct in6_addr         prefix;
32 };
33
34
35 #ifdef __KERNEL__
36
37 #include <linux/in6.h>
38 #include <linux/netdevice.h>
39 #include <net/if_inet6.h>
40
41 #define IN6_ADDR_HSIZE          16
42
43 extern void                     addrconf_init(void);
44 extern void                     addrconf_cleanup(void);
45
46 extern int                      addrconf_notify(struct notifier_block *this, 
47                                                 unsigned long event, 
48                                                 void * data);
49
50 extern int                      addrconf_add_ifaddr(void *arg);
51 extern int                      addrconf_del_ifaddr(void *arg);
52 extern int                      addrconf_set_dstaddr(void *arg);
53
54 extern int                      ipv6_chk_addr(struct in6_addr *addr,
55                                               struct net_device *dev);
56 extern struct inet6_ifaddr *    ipv6_get_ifaddr(struct in6_addr *addr,
57                                                 struct net_device *dev);
58 extern int                      ipv6_get_saddr(struct dst_entry *dst, 
59                                                struct in6_addr *daddr,
60                                                struct in6_addr *saddr);
61 extern int                      ipv6_dev_get_saddr(struct net_device *dev, 
62                                                struct in6_addr *daddr,
63                                                struct in6_addr *saddr,
64                                                int onlink);
65 extern int                      ipv6_get_lladdr(struct net_device *dev, struct in6_addr *);
66 extern void                     addrconf_join_solict(struct net_device *dev,
67                                         struct in6_addr *addr);
68 extern void                     addrconf_leave_solict(struct net_device *dev,
69                                         struct in6_addr *addr);
70
71 /*
72  *      multicast prototypes (mcast.c)
73  */
74 extern int ipv6_sock_mc_join(struct sock *sk, int ifindex, 
75                   struct in6_addr *addr);
76 extern int ipv6_sock_mc_drop(struct sock *sk, int ifindex, 
77                   struct in6_addr *addr);
78 extern void ipv6_sock_mc_close(struct sock *sk);
79 extern int inet6_mc_check(struct sock *sk, struct in6_addr *mc_addr,
80                 struct in6_addr *src_addr);
81
82 extern int ipv6_dev_mc_inc(struct net_device *dev, struct in6_addr *addr);
83 extern int ipv6_dev_mc_dec(struct net_device *dev, struct in6_addr *addr);
84 extern void ipv6_mc_up(struct inet6_dev *idev);
85 extern void ipv6_mc_down(struct inet6_dev *idev);
86 extern void ipv6_mc_init_dev(struct inet6_dev *idev);
87 extern void ipv6_mc_destroy_dev(struct inet6_dev *idev);
88 extern void addrconf_dad_failure(struct inet6_ifaddr *ifp);
89
90 extern int ipv6_chk_mcast_addr(struct net_device *dev, struct in6_addr *group,
91                 struct in6_addr *src_addr);
92
93 extern void addrconf_prefix_rcv(struct net_device *dev, u8 *opt, int len);
94
95 /*
96  *      anycast prototypes (anycast.c)
97  */
98 extern int                      ipv6_sock_ac_join(struct sock *sk, 
99                                                   int ifindex, 
100                                                   struct in6_addr *addr);
101 extern int                      ipv6_sock_ac_drop(struct sock *sk,
102                                                   int ifindex, 
103                                                   struct in6_addr *addr);
104 extern void                     ipv6_sock_ac_close(struct sock *sk);
105 extern int                      inet6_ac_check(struct sock *sk, struct in6_addr *addr, int ifindex);
106
107 extern int                      ipv6_dev_ac_inc(struct net_device *dev,
108                                                 struct in6_addr *addr);
109 extern int                      ipv6_dev_ac_dec(struct net_device *dev,
110                                                 struct in6_addr *addr);
111 extern int                      ipv6_chk_acast_addr(struct net_device *dev,
112                                                 struct in6_addr *addr);
113
114
115 /* Device notifier */
116 extern int register_inet6addr_notifier(struct notifier_block *nb);
117 extern int unregister_inet6addr_notifier(struct notifier_block *nb);
118
119 static inline struct inet6_dev *
120 __in6_dev_get(struct net_device *dev)
121 {
122         return (struct inet6_dev *)dev->ip6_ptr;
123 }
124
125 extern rwlock_t addrconf_lock;
126
127 static inline struct inet6_dev *
128 in6_dev_get(struct net_device *dev)
129 {
130         struct inet6_dev *idev = NULL;
131         read_lock(&addrconf_lock);
132         idev = dev->ip6_ptr;
133         if (idev)
134                 atomic_inc(&idev->refcnt);
135         read_unlock(&addrconf_lock);
136         return idev;
137 }
138
139 extern void in6_dev_finish_destroy(struct inet6_dev *idev);
140
141 static inline void
142 in6_dev_put(struct inet6_dev *idev)
143 {
144         if (atomic_dec_and_test(&idev->refcnt))
145                 in6_dev_finish_destroy(idev);
146 }
147
148 #define __in6_dev_put(idev)  atomic_dec(&(idev)->refcnt)
149 #define in6_dev_hold(idev)   atomic_inc(&(idev)->refcnt)
150
151
152 extern void inet6_ifa_finish_destroy(struct inet6_ifaddr *ifp);
153
154 static inline void in6_ifa_put(struct inet6_ifaddr *ifp)
155 {
156         if (atomic_dec_and_test(&ifp->refcnt))
157                 inet6_ifa_finish_destroy(ifp);
158 }
159
160 #define __in6_ifa_put(idev)  atomic_dec(&(idev)->refcnt)
161 #define in6_ifa_hold(idev)   atomic_inc(&(idev)->refcnt)
162
163
164 extern void                     addrconf_forwarding_on(void);
165 /*
166  *      Hash function taken from net_alias.c
167  */
168
169 static __inline__ u8 ipv6_addr_hash(const struct in6_addr *addr)
170 {       
171         __u32 word;
172
173         /* 
174          * We perform the hash function over the last 64 bits of the address
175          * This will include the IEEE address token on links that support it.
176          */
177
178         word = addr->s6_addr[2] ^ addr->s6_addr32[3];
179         word  ^= (word>>16);
180         word ^= (word >> 8);
181
182         return ((word ^ (word >> 4)) & 0x0f);
183 }
184
185 /*
186  *      compute link-local solicited-node multicast address
187  */
188
189 static inline void addrconf_addr_solict_mult(const struct in6_addr *addr,
190                                              struct in6_addr *solicited)
191 {
192         ipv6_addr_set(solicited,
193                       __constant_htonl(0xFF020000), 0,
194                       __constant_htonl(0x1),
195                       __constant_htonl(0xFF000000) | addr->s6_addr32[3]);
196 }
197
198
199 static inline void ipv6_addr_all_nodes(struct in6_addr *addr)
200 {
201         ipv6_addr_set(addr,
202                       __constant_htonl(0xFF020000), 0, 0,
203                       __constant_htonl(0x1));
204 }
205
206 static inline void ipv6_addr_all_routers(struct in6_addr *addr)
207 {
208         ipv6_addr_set(addr,
209                       __constant_htonl(0xFF020000), 0, 0,
210                       __constant_htonl(0x2));
211 }
212
213 static inline int ipv6_addr_is_multicast(const struct in6_addr *addr)
214 {
215         return (addr->s6_addr32[0] & __constant_htonl(0xFF000000)) == __constant_htonl(0xFF000000);
216 }
217
218 static inline int ipv6_addr_is_ll_all_nodes(const struct in6_addr *addr)
219 {
220         return (addr->s6_addr32[0] == htonl(0xff020000) &&
221                 addr->s6_addr32[1] == 0 &&
222                 addr->s6_addr32[2] == 0 &&
223                 addr->s6_addr32[3] == htonl(0x00000001));
224 }
225
226 static inline int ipv6_addr_is_ll_all_routers(const struct in6_addr *addr)
227 {
228         return (addr->s6_addr32[0] == htonl(0xff020000) &&
229                 addr->s6_addr32[1] == 0 &&
230                 addr->s6_addr32[2] == 0 &&
231                 addr->s6_addr32[3] == htonl(0x00000002));
232 }
233
234 #endif
235 #endif