import of upstream 2.4.34.4 from kernel.org
[linux-2.4.git] / include / net / ipv6.h
1 /*
2  *      Linux INET6 implementation
3  *
4  *      Authors:
5  *      Pedro Roque             <pedro_m@yahoo.com>
6  *
7  *      $Id: ipv6.h,v 1.23 2000/12/13 18:31:48 davem 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 #include <net/snmp.h>
105
106 /* sysctls */
107 extern int sysctl_ipv6_bindv6only;
108 extern int sysctl_mld_max_msf;
109
110 extern struct ipv6_mib          ipv6_statistics[NR_CPUS*2];
111 #define IP6_INC_STATS(field)            SNMP_INC_STATS(ipv6_statistics, field)
112 #define IP6_INC_STATS_BH(field)         SNMP_INC_STATS_BH(ipv6_statistics, field)
113 #define IP6_INC_STATS_USER(field)       SNMP_INC_STATS_USER(ipv6_statistics, field)
114 extern struct icmpv6_mib        icmpv6_statistics[NR_CPUS*2];
115 #define ICMP6_INC_STATS(field)          SNMP_INC_STATS(icmpv6_statistics, field)
116 #define ICMP6_INC_STATS_BH(field)       SNMP_INC_STATS_BH(icmpv6_statistics, field)
117 #define ICMP6_INC_STATS_USER(field)     SNMP_INC_STATS_USER(icmpv6_statistics, field)
118 extern struct udp_mib           udp_stats_in6[NR_CPUS*2];
119 #define UDP6_INC_STATS(field)           SNMP_INC_STATS(udp_stats_in6, field)
120 #define UDP6_INC_STATS_BH(field)        SNMP_INC_STATS_BH(udp_stats_in6, field)
121 #define UDP6_INC_STATS_USER(field)      SNMP_INC_STATS_USER(udp_stats_in6, field)
122 extern atomic_t                 inet6_sock_nr;
123
124 struct ip6_ra_chain
125 {
126         struct ip6_ra_chain     *next;
127         struct sock             *sk;
128         int                     sel;
129         void                    (*destructor)(struct sock *);
130 };
131
132 extern struct ip6_ra_chain      *ip6_ra_chain;
133 extern rwlock_t ip6_ra_lock;
134
135 /*
136    This structure is prepared by protocol, when parsing
137    ancillary data and passed to IPv6.
138  */
139
140 struct ipv6_txoptions
141 {
142         /* Length of this structure */
143         int                     tot_len;
144
145         /* length of extension headers   */
146
147         __u16                   opt_flen;       /* after fragment hdr */
148         __u16                   opt_nflen;      /* before fragment hdr */
149
150         struct ipv6_opt_hdr     *hopopt;
151         struct ipv6_opt_hdr     *dst0opt;
152         struct ipv6_rt_hdr      *srcrt; /* Routing Header */
153         struct ipv6_opt_hdr     *auth;
154         struct ipv6_opt_hdr     *dst1opt;
155
156         /* Option buffer, as read by IPV6_PKTOPTIONS, starts here. */
157 };
158
159 struct ip6_flowlabel
160 {
161         struct ip6_flowlabel    *next;
162         u32                     label;
163         struct in6_addr         dst;
164         struct ipv6_txoptions   *opt;
165         atomic_t                users;
166         u32                     linger;
167         u8                      share;
168         u32                     owner;
169         unsigned long           lastuse;
170         unsigned long           expires;
171 };
172
173 #define IPV6_FLOWINFO_MASK      __constant_htonl(0x0FFFFFFF)
174 #define IPV6_FLOWLABEL_MASK     __constant_htonl(0x000FFFFF)
175
176 struct ipv6_fl_socklist
177 {
178         struct ipv6_fl_socklist *next;
179         struct ip6_flowlabel    *fl;
180 };
181
182 extern struct ip6_flowlabel     *fl6_sock_lookup(struct sock *sk, u32 label);
183 extern struct ipv6_txoptions    *fl6_merge_options(struct ipv6_txoptions * opt_space,
184                                                    struct ip6_flowlabel * fl,
185                                                    struct ipv6_txoptions * fopt);
186 extern void                     fl6_free_socklist(struct sock *sk);
187 extern int                      ipv6_flowlabel_opt(struct sock *sk, char *optval, int optlen);
188 extern void                     ip6_flowlabel_init(void);
189 extern void                     ip6_flowlabel_cleanup(void);
190
191 static inline void fl6_sock_release(struct ip6_flowlabel *fl)
192 {
193         if (fl)
194                 atomic_dec(&fl->users);
195 }
196
197 extern int                      ip6_ra_control(struct sock *sk, int sel,
198                                                void (*destructor)(struct sock *));
199
200
201 extern int                      ip6_call_ra_chain(struct sk_buff *skb, int sel);
202
203 extern int                      ipv6_reassembly(struct sk_buff **skb, int);
204
205 extern int                      ipv6_parse_hopopts(struct sk_buff *skb, int);
206
207 extern int                      ipv6_parse_exthdrs(struct sk_buff **skb, int);
208
209 extern struct ipv6_txoptions *  ipv6_dup_options(struct sock *sk, struct ipv6_txoptions *opt);
210
211 extern int ip6_frag_nqueues;
212 extern atomic_t ip6_frag_mem;
213
214 #define IPV6_FRAG_TIMEOUT       (60*HZ)         /* 60 seconds */
215
216 /*
217  *      Function prototype for build_xmit
218  */
219
220 typedef int             (*inet_getfrag_t) (const void *data,
221                                            struct in6_addr *addr,
222                                            char *,
223                                            unsigned int, unsigned int);
224
225
226 extern int              ipv6_addr_type(const struct in6_addr *addr);
227
228 static inline int ipv6_addr_scope(const struct in6_addr *addr)
229 {
230         return ipv6_addr_type(addr) & IPV6_ADDR_SCOPE_MASK;
231 }
232
233 static inline int ipv6_addr_cmp(const struct in6_addr *a1, const struct in6_addr *a2)
234 {
235         return memcmp((const void *) a1, (const void *) a2, sizeof(struct in6_addr));
236 }
237
238 static inline void ipv6_addr_copy(struct in6_addr *a1, const struct in6_addr *a2)
239 {
240         memcpy((void *) a1, (const void *) a2, sizeof(struct in6_addr));
241 }
242
243 #ifndef __HAVE_ARCH_ADDR_SET
244 static inline void ipv6_addr_set(struct in6_addr *addr, 
245                                      __u32 w1, __u32 w2,
246                                      __u32 w3, __u32 w4)
247 {
248         addr->s6_addr32[0] = w1;
249         addr->s6_addr32[1] = w2;
250         addr->s6_addr32[2] = w3;
251         addr->s6_addr32[3] = w4;
252 }
253 #endif
254
255 static inline int ipv6_addr_any(const struct in6_addr *a)
256 {
257         return ((a->s6_addr32[0] | a->s6_addr32[1] | 
258                  a->s6_addr32[2] | a->s6_addr32[3] ) == 0); 
259 }
260
261 /*
262  *      Prototypes exported by ipv6
263  */
264
265 /*
266  *      rcv function (called from netdevice level)
267  */
268
269 extern int                      ipv6_rcv(struct sk_buff *skb, 
270                                          struct net_device *dev, 
271                                          struct packet_type *pt);
272
273 /*
274  *      upper-layer output functions
275  */
276 extern int                      ip6_xmit(struct sock *sk,
277                                          struct sk_buff *skb,
278                                          struct flowi *fl,
279                                          struct ipv6_txoptions *opt);
280
281 extern int                      ip6_nd_hdr(struct sock *sk,
282                                            struct sk_buff *skb,
283                                            struct net_device *dev,
284                                            struct in6_addr *saddr,
285                                            struct in6_addr *daddr,
286                                            int proto, int len);
287
288 extern int                      ip6_build_xmit(struct sock *sk,
289                                                inet_getfrag_t getfrag,
290                                                const void *data,
291                                                struct flowi *fl,
292                                                unsigned length,
293                                                struct ipv6_txoptions *opt,
294                                                int hlimit, int flags);
295
296 /*
297  *      skb processing functions
298  */
299
300 extern int                      ip6_output(struct sk_buff *skb);
301 extern int                      ip6_forward(struct sk_buff *skb);
302 extern int                      ip6_input(struct sk_buff *skb);
303 extern int                      ip6_mc_input(struct sk_buff *skb);
304
305 /*
306  *      Extension header (options) processing
307  */
308
309 extern u8 *                     ipv6_build_nfrag_opts(struct sk_buff *skb,
310                                                       u8 *prev_hdr,
311                                                       struct ipv6_txoptions *opt,
312                                                       struct in6_addr *daddr,
313                                                       u32 jumbolen);
314 extern u8 *                     ipv6_build_frag_opts(struct sk_buff *skb,
315                                                      u8 *prev_hdr,
316                                                      struct ipv6_txoptions *opt);
317 extern void                     ipv6_push_nfrag_opts(struct sk_buff *skb,
318                                                      struct ipv6_txoptions *opt,
319                                                      u8 *proto,
320                                                      struct in6_addr **daddr_p);
321 extern void                     ipv6_push_frag_opts(struct sk_buff *skb,
322                                                     struct ipv6_txoptions *opt,
323                                                     u8 *proto);
324
325 extern int                      ipv6_skip_exthdr(const struct sk_buff *, int start,
326                                                  u8 *nexthdrp, int len);
327
328 extern int                      ipv6_ext_hdr(u8 nexthdr);
329
330 extern struct ipv6_txoptions *  ipv6_invert_rthdr(struct sock *sk,
331                                                   struct ipv6_rt_hdr *hdr);
332
333
334 /*
335  *      socket options (ipv6_sockglue.c)
336  */
337
338 extern int                      ipv6_setsockopt(struct sock *sk, int level, 
339                                                 int optname, char *optval, 
340                                                 int optlen);
341 extern int                      ipv6_getsockopt(struct sock *sk, int level, 
342                                                 int optname, char *optval, 
343                                                 int *optlen);
344
345 extern void                     ipv6_packet_init(void);
346
347 extern void                     ipv6_netdev_notif_init(void);
348
349 extern void                     ipv6_packet_cleanup(void);
350
351 extern void                     ipv6_netdev_notif_cleanup(void);
352
353 extern int                      ipv6_recv_error(struct sock *sk, struct msghdr *msg, int len);
354 extern void                     ipv6_icmp_error(struct sock *sk, struct sk_buff *skb, int err, u16 port,
355                                                 u32 info, u8 *payload);
356 extern void                     ipv6_local_error(struct sock *sk, int err, struct flowi *fl, u32 info);
357
358 extern int inet6_release(struct socket *sock);
359 extern int inet6_bind(struct socket *sock, struct sockaddr *uaddr, 
360                       int addr_len);
361 extern int inet6_getname(struct socket *sock, struct sockaddr *uaddr,
362                          int *uaddr_len, int peer);
363 extern int inet6_ioctl(struct socket *sock, unsigned int cmd, 
364                        unsigned long arg);
365
366 #endif /* __KERNEL__ */
367 #endif /* _NET_IPV6_H */
368
369
370