2 * Linux INET6 implementation
5 * Pedro Roque <roque@di.fc.ul.pt>
7 * $Id: ipv6.h,v 1.1.1.1 2005/04/11 02:51:08 jack Exp $
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.
18 #include <linux/ipv6.h>
19 #include <asm/hardirq.h>
20 #include <net/ndisc.h>
23 #define SIN6_LEN_RFC2133 24
26 * NextHeader field of IPv6 header
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. */
41 #define NEXTHDR_MAX 255
45 #define IPV6_DEFAULT_HOPLIMIT 64
46 #define IPV6_DEFAULT_MCASTHOPS 1
51 * type - unicast | multicast | anycast
52 * scope - local | site | global
59 #define IPV6_ADDR_ANY 0x0000U
61 #define IPV6_ADDR_UNICAST 0x0001U
62 #define IPV6_ADDR_MULTICAST 0x0002U
63 #define IPV6_ADDR_ANYCAST 0x0004U
65 #define IPV6_ADDR_LOOPBACK 0x0010U
66 #define IPV6_ADDR_LINKLOCAL 0x0020U
67 #define IPV6_ADDR_SITELOCAL 0x0040U
69 #define IPV6_ADDR_COMPATv4 0x0080U
71 #define IPV6_ADDR_SCOPE_MASK 0x00f0U
73 #define IPV6_ADDR_MAPPED 0x1000U
74 #define IPV6_ADDR_RESERVED 0x2000U /* reserved address space */
80 #define IPV6_ADDR_MC_SCOPE(a) \
81 ((a)->s6_addr[1] & 0x0f) /* nonstandard */
82 #define __IPV6_ADDR_SCOPE_INVALID -1
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
91 * fragmentation header
95 unsigned char nexthdr;
96 unsigned char reserved;
97 unsigned short frag_off;
103 #include <net/sock.h>
106 extern int sysctl_ipv6_bindv6only;
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;
124 struct ip6_ra_chain *next;
127 void (*destructor)(struct sock *);
130 extern struct ip6_ra_chain *ip6_ra_chain;
131 extern rwlock_t ip6_ra_lock;
134 This structure is prepared by protocol, when parsing
135 ancillary data and passed to IPv6.
138 struct ipv6_txoptions
140 /* Length of this structure */
143 /* length of extension headers */
145 __u16 opt_flen; /* after fragment hdr */
146 __u16 opt_nflen; /* before fragment hdr */
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;
154 /* Option buffer, as read by IPV6_PKTOPTIONS, starts here. */
159 struct ip6_flowlabel *next;
162 struct ipv6_txoptions *opt;
167 unsigned long lastuse;
168 unsigned long expires;
171 #define IPV6_FLOWINFO_MASK __constant_htonl(0x0FFFFFFF)
172 #define IPV6_FLOWLABEL_MASK __constant_htonl(0x000FFFFF)
174 struct ipv6_fl_socklist
176 struct ipv6_fl_socklist *next;
177 struct ip6_flowlabel *fl;
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);
189 static inline void fl6_sock_release(struct ip6_flowlabel *fl)
192 atomic_dec(&fl->users);
195 extern int ip6_ra_control(struct sock *sk, int sel,
196 void (*destructor)(struct sock *));
199 extern int ip6_call_ra_chain(struct sk_buff *skb, int sel);
201 extern int ipv6_reassembly(struct sk_buff **skb, int);
203 extern int ipv6_parse_hopopts(struct sk_buff *skb, int);
205 extern int ipv6_parse_exthdrs(struct sk_buff **skb, int);
207 extern struct ipv6_txoptions * ipv6_dup_options(struct sock *sk, struct ipv6_txoptions *opt);
209 extern int ip6_frag_nqueues;
210 extern atomic_t ip6_frag_mem;
212 #define IPV6_FRAG_TIMEOUT (60*HZ) /* 60 seconds */
215 * Function prototype for build_xmit
218 typedef int (*inet_getfrag_t) (const void *data,
219 struct in6_addr *addr,
221 unsigned int, unsigned int);
224 extern int ipv6_addr_type(struct in6_addr *addr);
226 static inline int ipv6_addr_scope(struct in6_addr *addr)
228 return ipv6_addr_type(addr) & IPV6_ADDR_SCOPE_MASK;
231 static inline int ipv6_addr_cmp(struct in6_addr *a1, struct in6_addr *a2)
233 return memcmp((void *) a1, (void *) a2, sizeof(struct in6_addr));
236 static inline void ipv6_addr_copy(struct in6_addr *a1, struct in6_addr *a2)
238 memcpy((void *) a1, (void *) a2, sizeof(struct in6_addr));
241 #ifndef __HAVE_ARCH_ADDR_SET
242 static inline void ipv6_addr_set(struct in6_addr *addr,
246 addr->s6_addr32[0] = w1;
247 addr->s6_addr32[1] = w2;
248 addr->s6_addr32[2] = w3;
249 addr->s6_addr32[3] = w4;
253 static inline int ipv6_addr_any(struct in6_addr *a)
255 return ((a->s6_addr32[0] | a->s6_addr32[1] |
256 a->s6_addr32[2] | a->s6_addr32[3] ) == 0);
260 * Prototypes exported by ipv6
264 * rcv function (called from netdevice level)
267 extern int ipv6_rcv(struct sk_buff *skb,
268 struct net_device *dev,
269 struct packet_type *pt);
272 * upper-layer output functions
274 extern int ip6_xmit(struct sock *sk,
277 struct ipv6_txoptions *opt);
279 extern int ip6_nd_hdr(struct sock *sk,
281 struct net_device *dev,
282 struct in6_addr *saddr,
283 struct in6_addr *daddr,
286 extern int ip6_build_xmit(struct sock *sk,
287 inet_getfrag_t getfrag,
291 struct ipv6_txoptions *opt,
292 int hlimit, int flags);
295 * skb processing functions
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);
304 * Extension header (options) processing
307 extern u8 * ipv6_build_nfrag_opts(struct sk_buff *skb,
309 struct ipv6_txoptions *opt,
310 struct in6_addr *daddr,
312 extern u8 * ipv6_build_frag_opts(struct sk_buff *skb,
314 struct ipv6_txoptions *opt);
315 extern void ipv6_push_nfrag_opts(struct sk_buff *skb,
316 struct ipv6_txoptions *opt,
318 struct in6_addr **daddr_p);
319 extern void ipv6_push_frag_opts(struct sk_buff *skb,
320 struct ipv6_txoptions *opt,
323 extern int ipv6_skip_exthdr(struct sk_buff *, int start,
324 u8 *nexthdrp, int len);
326 extern int ipv6_ext_hdr(u8 nexthdr);
328 extern struct ipv6_txoptions * ipv6_invert_rthdr(struct sock *sk,
329 struct ipv6_rt_hdr *hdr);
333 * socket options (ipv6_sockglue.c)
336 extern int ipv6_setsockopt(struct sock *sk, int level,
337 int optname, char *optval,
339 extern int ipv6_getsockopt(struct sock *sk, int level,
340 int optname, char *optval,
343 extern void ipv6_packet_init(void);
345 extern void ipv6_netdev_notif_init(void);
347 extern void ipv6_packet_cleanup(void);
349 extern void ipv6_netdev_notif_cleanup(void);
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);
356 #endif /* __KERNEL__ */
357 #endif /* _NET_IPV6_H */