cleanup
[linux-2.4.21-pre4.git] / include / net1 / ipv6.h
1 /*
2  *      Linux INET6 implementation
3  *
4  *      Authors:
5  *      Pedro Roque             <roque@di.fc.ul.pt>
6  *
7  *      $Id: ipv6.h,v 1.1.1.1 2005/04/11 02:51:08 jack Exp $
8  *
9  *      This program is free software; you can redistribute it and/or
10  *      modify it under the terms of the GNU General Public License
11  *      as published by the Free Software Foundation; either version
12  *      2 of the License, or (at your option) any later version.
13  */
14
15 #ifndef _NET_IPV6_H
16 #define _NET_IPV6_H
17
18 #include <linux/ipv6.h>
19 #include <asm/hardirq.h>
20 #include <net/ndisc.h>
21 #include <net/flow.h>
22
23 #define SIN6_LEN_RFC2133        24
24
25 /*
26  *      NextHeader field of IPv6 header
27  */
28
29 #define NEXTHDR_HOP             0       /* Hop-by-hop option header. */
30 #define NEXTHDR_TCP             6       /* TCP segment. */
31 #define NEXTHDR_UDP             17      /* UDP message. */
32 #define NEXTHDR_IPV6            41      /* IPv6 in IPv6 */
33 #define NEXTHDR_ROUTING         43      /* Routing header. */
34 #define NEXTHDR_FRAGMENT        44      /* Fragmentation/reassembly header. */
35 #define NEXTHDR_ESP             50      /* Encapsulating security payload. */
36 #define NEXTHDR_AUTH            51      /* Authentication header. */
37 #define NEXTHDR_ICMP            58      /* ICMP for IPv6. */
38 #define NEXTHDR_NONE            59      /* No next header */
39 #define NEXTHDR_DEST            60      /* Destination options header. */
40
41 #define NEXTHDR_MAX             255
42
43
44
45 #define IPV6_DEFAULT_HOPLIMIT   64
46 #define IPV6_DEFAULT_MCASTHOPS  1
47
48 /*
49  *      Addr type
50  *      
51  *      type    -       unicast | multicast | anycast
52  *      scope   -       local   | site      | global
53  *      v4      -       compat
54  *      v4mapped
55  *      any
56  *      loopback
57  */
58
59 #define IPV6_ADDR_ANY           0x0000U
60
61 #define IPV6_ADDR_UNICAST       0x0001U 
62 #define IPV6_ADDR_MULTICAST     0x0002U 
63 #define IPV6_ADDR_ANYCAST       0x0004U
64
65 #define IPV6_ADDR_LOOPBACK      0x0010U
66 #define IPV6_ADDR_LINKLOCAL     0x0020U
67 #define IPV6_ADDR_SITELOCAL     0x0040U
68
69 #define IPV6_ADDR_COMPATv4      0x0080U
70
71 #define IPV6_ADDR_SCOPE_MASK    0x00f0U
72
73 #define IPV6_ADDR_MAPPED        0x1000U
74 #define IPV6_ADDR_RESERVED      0x2000U /* reserved address space */
75
76 /*
77  *      Addr scopes
78  */
79 #ifdef __KERNEL__
80 #define IPV6_ADDR_MC_SCOPE(a)   \
81         ((a)->s6_addr[1] & 0x0f)        /* nonstandard */
82 #define __IPV6_ADDR_SCOPE_INVALID       -1
83 #endif
84 #define IPV6_ADDR_SCOPE_NODELOCAL       0x01
85 #define IPV6_ADDR_SCOPE_LINKLOCAL       0x02
86 #define IPV6_ADDR_SCOPE_SITELOCAL       0x05
87 #define IPV6_ADDR_SCOPE_ORGLOCAL        0x08
88 #define IPV6_ADDR_SCOPE_GLOBAL          0x0e
89
90 /*
91  *      fragmentation header
92  */
93
94 struct frag_hdr {
95         unsigned char   nexthdr;
96         unsigned char   reserved;       
97         unsigned short  frag_off;
98         __u32           identification;
99 };
100
101 #ifdef __KERNEL__
102
103 #include <net/sock.h>
104
105 /* sysctls */
106 extern int sysctl_ipv6_bindv6only;
107
108 extern struct ipv6_mib          ipv6_statistics[NR_CPUS*2];
109 #define IP6_INC_STATS(field)            SNMP_INC_STATS(ipv6_statistics, field)
110 #define IP6_INC_STATS_BH(field)         SNMP_INC_STATS_BH(ipv6_statistics, field)
111 #define IP6_INC_STATS_USER(field)       SNMP_INC_STATS_USER(ipv6_statistics, field)
112 extern struct icmpv6_mib        icmpv6_statistics[NR_CPUS*2];
113 #define ICMP6_INC_STATS(field)          SNMP_INC_STATS(icmpv6_statistics, field)
114 #define ICMP6_INC_STATS_BH(field)       SNMP_INC_STATS_BH(icmpv6_statistics, field)
115 #define ICMP6_INC_STATS_USER(field)     SNMP_INC_STATS_USER(icmpv6_statistics, field)
116 extern struct udp_mib           udp_stats_in6[NR_CPUS*2];
117 #define UDP6_INC_STATS(field)           SNMP_INC_STATS(udp_stats_in6, field)
118 #define UDP6_INC_STATS_BH(field)        SNMP_INC_STATS_BH(udp_stats_in6, field)
119 #define UDP6_INC_STATS_USER(field)      SNMP_INC_STATS_USER(udp_stats_in6, field)
120 extern atomic_t                 inet6_sock_nr;
121
122 struct ip6_ra_chain
123 {
124         struct ip6_ra_chain     *next;
125         struct sock             *sk;
126         int                     sel;
127         void                    (*destructor)(struct sock *);
128 };
129
130 extern struct ip6_ra_chain      *ip6_ra_chain;
131 extern rwlock_t ip6_ra_lock;
132
133 /*
134    This structure is prepared by protocol, when parsing
135    ancillary data and passed to IPv6.
136  */
137
138 struct ipv6_txoptions
139 {
140         /* Length of this structure */
141         int                     tot_len;
142
143         /* length of extension headers   */
144
145         __u16                   opt_flen;       /* after fragment hdr */
146         __u16                   opt_nflen;      /* before fragment hdr */
147
148         struct ipv6_opt_hdr     *hopopt;
149         struct ipv6_opt_hdr     *dst0opt;
150         struct ipv6_rt_hdr      *srcrt; /* Routing Header */
151         struct ipv6_opt_hdr     *auth;
152         struct ipv6_opt_hdr     *dst1opt;
153
154         /* Option buffer, as read by IPV6_PKTOPTIONS, starts here. */
155 };
156
157 struct ip6_flowlabel
158 {
159         struct ip6_flowlabel    *next;
160         u32                     label;
161         struct in6_addr         dst;
162         struct ipv6_txoptions   *opt;
163         atomic_t                users;
164         u32                     linger;
165         u8                      share;
166         u32                     owner;
167         unsigned long           lastuse;
168         unsigned long           expires;
169 };
170
171 #define IPV6_FLOWINFO_MASK      __constant_htonl(0x0FFFFFFF)
172 #define IPV6_FLOWLABEL_MASK     __constant_htonl(0x000FFFFF)
173
174 struct ipv6_fl_socklist
175 {
176         struct ipv6_fl_socklist *next;
177         struct ip6_flowlabel    *fl;
178 };
179
180 extern struct ip6_flowlabel     *fl6_sock_lookup(struct sock *sk, u32 label);
181 extern struct ipv6_txoptions    *fl6_merge_options(struct ipv6_txoptions * opt_space,
182                                                    struct ip6_flowlabel * fl,
183                                                    struct ipv6_txoptions * fopt);
184 extern void                     fl6_free_socklist(struct sock *sk);
185 extern int                      ipv6_flowlabel_opt(struct sock *sk, char *optval, int optlen);
186 extern void                     ip6_flowlabel_init(void);
187 extern void                     ip6_flowlabel_cleanup(void);
188
189 static inline void fl6_sock_release(struct ip6_flowlabel *fl)
190 {
191         if (fl)
192                 atomic_dec(&fl->users);
193 }
194
195 extern int                      ip6_ra_control(struct sock *sk, int sel,
196                                                void (*destructor)(struct sock *));
197
198
199 extern int                      ip6_call_ra_chain(struct sk_buff *skb, int sel);
200
201 extern int                      ipv6_reassembly(struct sk_buff **skb, int);
202
203 extern int                      ipv6_parse_hopopts(struct sk_buff *skb, int);
204
205 extern int                      ipv6_parse_exthdrs(struct sk_buff **skb, int);
206
207 extern struct ipv6_txoptions *  ipv6_dup_options(struct sock *sk, struct ipv6_txoptions *opt);
208
209 extern int ip6_frag_nqueues;
210 extern atomic_t ip6_frag_mem;
211
212 #define IPV6_FRAG_TIMEOUT       (60*HZ)         /* 60 seconds */
213
214 /*
215  *      Function prototype for build_xmit
216  */
217
218 typedef int             (*inet_getfrag_t) (const void *data,
219                                            struct in6_addr *addr,
220                                            char *,
221                                            unsigned int, unsigned int);
222
223
224 extern int              ipv6_addr_type(struct in6_addr *addr);
225
226 static inline int ipv6_addr_scope(struct in6_addr *addr)
227 {
228         return ipv6_addr_type(addr) & IPV6_ADDR_SCOPE_MASK;
229 }
230
231 static inline int ipv6_addr_cmp(struct in6_addr *a1, struct in6_addr *a2)
232 {
233         return memcmp((void *) a1, (void *) a2, sizeof(struct in6_addr));
234 }
235
236 static inline void ipv6_addr_copy(struct in6_addr *a1, struct in6_addr *a2)
237 {
238         memcpy((void *) a1, (void *) a2, sizeof(struct in6_addr));
239 }
240
241 #ifndef __HAVE_ARCH_ADDR_SET
242 static inline void ipv6_addr_set(struct in6_addr *addr, 
243                                      __u32 w1, __u32 w2,
244                                      __u32 w3, __u32 w4)
245 {
246         addr->s6_addr32[0] = w1;
247         addr->s6_addr32[1] = w2;
248         addr->s6_addr32[2] = w3;
249         addr->s6_addr32[3] = w4;
250 }
251 #endif
252
253 static inline int ipv6_addr_any(struct in6_addr *a)
254 {
255         return ((a->s6_addr32[0] | a->s6_addr32[1] | 
256                  a->s6_addr32[2] | a->s6_addr32[3] ) == 0); 
257 }
258
259 /*
260  *      Prototypes exported by ipv6
261  */
262
263 /*
264  *      rcv function (called from netdevice level)
265  */
266
267 extern int                      ipv6_rcv(struct sk_buff *skb, 
268                                          struct net_device *dev, 
269                                          struct packet_type *pt);
270
271 /*
272  *      upper-layer output functions
273  */
274 extern int                      ip6_xmit(struct sock *sk,
275                                          struct sk_buff *skb,
276                                          struct flowi *fl,
277                                          struct ipv6_txoptions *opt);
278
279 extern int                      ip6_nd_hdr(struct sock *sk,
280                                            struct sk_buff *skb,
281                                            struct net_device *dev,
282                                            struct in6_addr *saddr,
283                                            struct in6_addr *daddr,
284                                            int proto, int len);
285
286 extern int                      ip6_build_xmit(struct sock *sk,
287                                                inet_getfrag_t getfrag,
288                                                const void *data,
289                                                struct flowi *fl,
290                                                unsigned length,
291                                                struct ipv6_txoptions *opt,
292                                                int hlimit, int flags);
293
294 /*
295  *      skb processing functions
296  */
297
298 extern int                      ip6_output(struct sk_buff *skb);
299 extern int                      ip6_forward(struct sk_buff *skb);
300 extern int                      ip6_input(struct sk_buff *skb);
301 extern int                      ip6_mc_input(struct sk_buff *skb);
302
303 /*
304  *      Extension header (options) processing
305  */
306
307 extern u8 *                     ipv6_build_nfrag_opts(struct sk_buff *skb,
308                                                       u8 *prev_hdr,
309                                                       struct ipv6_txoptions *opt,
310                                                       struct in6_addr *daddr,
311                                                       u32 jumbolen);
312 extern u8 *                     ipv6_build_frag_opts(struct sk_buff *skb,
313                                                      u8 *prev_hdr,
314                                                      struct ipv6_txoptions *opt);
315 extern void                     ipv6_push_nfrag_opts(struct sk_buff *skb,
316                                                      struct ipv6_txoptions *opt,
317                                                      u8 *proto,
318                                                      struct in6_addr **daddr_p);
319 extern void                     ipv6_push_frag_opts(struct sk_buff *skb,
320                                                     struct ipv6_txoptions *opt,
321                                                     u8 *proto);
322
323 extern int                      ipv6_skip_exthdr(struct sk_buff *, int start,
324                                                  u8 *nexthdrp, int len);
325
326 extern int                      ipv6_ext_hdr(u8 nexthdr);
327
328 extern struct ipv6_txoptions *  ipv6_invert_rthdr(struct sock *sk,
329                                                   struct ipv6_rt_hdr *hdr);
330
331
332 /*
333  *      socket options (ipv6_sockglue.c)
334  */
335
336 extern int                      ipv6_setsockopt(struct sock *sk, int level, 
337                                                 int optname, char *optval, 
338                                                 int optlen);
339 extern int                      ipv6_getsockopt(struct sock *sk, int level, 
340                                                 int optname, char *optval, 
341                                                 int *optlen);
342
343 extern void                     ipv6_packet_init(void);
344
345 extern void                     ipv6_netdev_notif_init(void);
346
347 extern void                     ipv6_packet_cleanup(void);
348
349 extern void                     ipv6_netdev_notif_cleanup(void);
350
351 extern int                      ipv6_recv_error(struct sock *sk, struct msghdr *msg, int len);
352 extern void                     ipv6_icmp_error(struct sock *sk, struct sk_buff *skb, int err, u16 port,
353                                                 u32 info, u8 *payload);
354 extern void                     ipv6_local_error(struct sock *sk, int err, struct flowi *fl, u32 info);
355
356 #endif /* __KERNEL__ */
357 #endif /* _NET_IPV6_H */
358
359
360