[IPV4]: Safer reassembly
[deliverable/linux.git] / include / net / ip.h
CommitLineData
1da177e4
LT
1/*
2 * INET An implementation of the TCP/IP protocol suite for the LINUX
3 * operating system. INET is implemented using the BSD Socket
4 * interface as the means of communication with the user level.
5 *
6 * Definitions for the IP module.
7 *
8 * Version: @(#)ip.h 1.0.2 05/07/93
9 *
02c30a84 10 * Authors: Ross Biro
1da177e4
LT
11 * Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
12 * Alan Cox, <gw4pts@gw4pts.ampr.org>
13 *
14 * Changes:
15 * Mike McLagan : Routing by source
16 *
17 * This program is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU General Public License
19 * as published by the Free Software Foundation; either version
20 * 2 of the License, or (at your option) any later version.
21 */
22#ifndef _IP_H
23#define _IP_H
24
25#include <linux/config.h>
26#include <linux/types.h>
27#include <linux/socket.h>
28#include <linux/ip.h>
29#include <linux/in.h>
30#include <linux/netdevice.h>
31#include <linux/inetdevice.h>
32#include <linux/in_route.h>
33#include <net/route.h>
34#include <net/arp.h>
35#include <net/snmp.h>
36
37struct sock;
38
39struct inet_skb_parm
40{
41 struct ip_options opt; /* Compiled IP options */
42 unsigned char flags;
43
44#define IPSKB_MASQUERADED 1
45#define IPSKB_TRANSLATED 2
46#define IPSKB_FORWARDED 4
47#define IPSKB_XFRM_TUNNEL_SIZE 8
89cee8b1 48#define IPSKB_FRAG_COMPLETE 16
1da177e4
LT
49};
50
51struct ipcm_cookie
52{
53 u32 addr;
54 int oif;
55 struct ip_options *opt;
56};
57
58#define IPCB(skb) ((struct inet_skb_parm*)((skb)->cb))
59
60struct ip_ra_chain
61{
62 struct ip_ra_chain *next;
63 struct sock *sk;
64 void (*destructor)(struct sock *);
65};
66
67extern struct ip_ra_chain *ip_ra_chain;
68extern rwlock_t ip_ra_lock;
69
70/* IP flags. */
71#define IP_CE 0x8000 /* Flag: "Congestion" */
72#define IP_DF 0x4000 /* Flag: "Don't Fragment" */
73#define IP_MF 0x2000 /* Flag: "More Fragments" */
74#define IP_OFFSET 0x1FFF /* "Fragment Offset" part */
75
76#define IP_FRAG_TIME (30 * HZ) /* fragment lifetime */
77
78extern void ip_mc_dropsocket(struct sock *);
79extern void ip_mc_dropdevice(struct net_device *dev);
80extern int igmp_mc_proc_init(void);
81
82/*
83 * Functions provided by ip.c
84 */
85
86extern int ip_build_and_send_pkt(struct sk_buff *skb, struct sock *sk,
87 u32 saddr, u32 daddr,
88 struct ip_options *opt);
89extern int ip_rcv(struct sk_buff *skb, struct net_device *dev,
f2ccd8fa 90 struct packet_type *pt, struct net_device *orig_dev);
1da177e4
LT
91extern int ip_local_deliver(struct sk_buff *skb);
92extern int ip_mr_input(struct sk_buff *skb);
93extern int ip_output(struct sk_buff *skb);
94extern int ip_mc_output(struct sk_buff *skb);
95extern int ip_fragment(struct sk_buff *skb, int (*out)(struct sk_buff*));
96extern int ip_do_nat(struct sk_buff *skb);
97extern void ip_send_check(struct iphdr *ip);
98extern int ip_queue_xmit(struct sk_buff *skb, int ipfragok);
99extern void ip_init(void);
100extern int ip_append_data(struct sock *sk,
101 int getfrag(void *from, char *to, int offset, int len,
102 int odd, struct sk_buff *skb),
103 void *from, int len, int protolen,
104 struct ipcm_cookie *ipc,
105 struct rtable *rt,
106 unsigned int flags);
107extern int ip_generic_getfrag(void *from, char *to, int offset, int len, int odd, struct sk_buff *skb);
108extern ssize_t ip_append_page(struct sock *sk, struct page *page,
109 int offset, size_t size, int flags);
110extern int ip_push_pending_frames(struct sock *sk);
111extern void ip_flush_pending_frames(struct sock *sk);
112
113/* datagram.c */
114extern int ip4_datagram_connect(struct sock *sk,
115 struct sockaddr *uaddr, int addr_len);
116
117/*
118 * Map a multicast IP onto multicast MAC for type Token Ring.
119 * This conforms to RFC1469 Option 2 Multicasting i.e.
120 * using a functional address to transmit / receive
121 * multicast packets.
122 */
123
124static inline void ip_tr_mc_map(u32 addr, char *buf)
125{
126 buf[0]=0xC0;
127 buf[1]=0x00;
128 buf[2]=0x00;
129 buf[3]=0x04;
130 buf[4]=0x00;
131 buf[5]=0x00;
132}
133
134struct ip_reply_arg {
135 struct kvec iov[1];
136 u32 csum;
137 int csumoffset; /* u16 offset of csum in iov[0].iov_base */
138 /* -1 if not needed */
139};
140
141void ip_send_reply(struct sock *sk, struct sk_buff *skb, struct ip_reply_arg *arg,
142 unsigned int len);
143
1da177e4
LT
144struct ipv4_config
145{
146 int log_martians;
147 int autoconfig;
148 int no_pmtu_disc;
149};
150
151extern struct ipv4_config ipv4_config;
152DECLARE_SNMP_STAT(struct ipstats_mib, ip_statistics);
153#define IP_INC_STATS(field) SNMP_INC_STATS(ip_statistics, field)
154#define IP_INC_STATS_BH(field) SNMP_INC_STATS_BH(ip_statistics, field)
155#define IP_INC_STATS_USER(field) SNMP_INC_STATS_USER(ip_statistics, field)
156DECLARE_SNMP_STAT(struct linux_mib, net_statistics);
157#define NET_INC_STATS(field) SNMP_INC_STATS(net_statistics, field)
158#define NET_INC_STATS_BH(field) SNMP_INC_STATS_BH(net_statistics, field)
159#define NET_INC_STATS_USER(field) SNMP_INC_STATS_USER(net_statistics, field)
160#define NET_ADD_STATS_BH(field, adnd) SNMP_ADD_STATS_BH(net_statistics, field, adnd)
161#define NET_ADD_STATS_USER(field, adnd) SNMP_ADD_STATS_USER(net_statistics, field, adnd)
162
163extern int sysctl_local_port_range[2];
164extern int sysctl_ip_default_ttl;
cdac4e07 165extern int sysctl_ip_nonlocal_bind;
1da177e4 166
20380731
ACM
167/* From ip_fragment.c */
168extern int sysctl_ipfrag_high_thresh;
169extern int sysctl_ipfrag_low_thresh;
170extern int sysctl_ipfrag_time;
171extern int sysctl_ipfrag_secret_interval;
89cee8b1 172extern int sysctl_ipfrag_max_dist;
20380731
ACM
173
174/* From inetpeer.c */
175extern int inet_peer_threshold;
176extern int inet_peer_minttl;
177extern int inet_peer_maxttl;
178extern int inet_peer_gc_mintime;
179extern int inet_peer_gc_maxtime;
180
181/* From ip_output.c */
182extern int sysctl_ip_dynaddr;
183
184extern void ipfrag_init(void);
185
1da177e4
LT
186#ifdef CONFIG_INET
187/* The function in 2.2 was invalid, producing wrong result for
188 * check=0xFEFF. It was noticed by Arthur Skawina _year_ ago. --ANK(000625) */
189static inline
190int ip_decrease_ttl(struct iphdr *iph)
191{
192 u32 check = iph->check;
193 check += htons(0x0100);
194 iph->check = check + (check>=0xFFFF);
195 return --iph->ttl;
196}
197
198static inline
199int ip_dont_fragment(struct sock *sk, struct dst_entry *dst)
200{
201 return (inet_sk(sk)->pmtudisc == IP_PMTUDISC_DO ||
202 (inet_sk(sk)->pmtudisc == IP_PMTUDISC_WANT &&
203 !(dst_metric(dst, RTAX_LOCK)&(1<<RTAX_MTU))));
204}
205
206extern void __ip_select_ident(struct iphdr *iph, struct dst_entry *dst, int more);
207
208static inline void ip_select_ident(struct iphdr *iph, struct dst_entry *dst, struct sock *sk)
209{
210 if (iph->frag_off & htons(IP_DF)) {
211 /* This is only to work around buggy Windows95/2000
212 * VJ compression implementations. If the ID field
213 * does not change, they drop every other packet in
214 * a TCP stream using header compression.
215 */
216 iph->id = (sk && inet_sk(sk)->daddr) ?
217 htons(inet_sk(sk)->id++) : 0;
218 } else
219 __ip_select_ident(iph, dst, 0);
220}
221
222static inline void ip_select_ident_more(struct iphdr *iph, struct dst_entry *dst, struct sock *sk, int more)
223{
224 if (iph->frag_off & htons(IP_DF)) {
225 if (sk && inet_sk(sk)->daddr) {
226 iph->id = htons(inet_sk(sk)->id);
227 inet_sk(sk)->id += 1 + more;
228 } else
229 iph->id = 0;
230 } else
231 __ip_select_ident(iph, dst, more);
232}
233
234/*
235 * Map a multicast IP onto multicast MAC for type ethernet.
236 */
237
238static inline void ip_eth_mc_map(u32 addr, char *buf)
239{
240 addr=ntohl(addr);
241 buf[0]=0x01;
242 buf[1]=0x00;
243 buf[2]=0x5e;
244 buf[5]=addr&0xFF;
245 addr>>=8;
246 buf[4]=addr&0xFF;
247 addr>>=8;
248 buf[3]=addr&0x7F;
249}
250
251/*
252 * Map a multicast IP onto multicast MAC for type IP-over-InfiniBand.
253 * Leave P_Key as 0 to be filled in by driver.
254 */
255
256static inline void ip_ib_mc_map(u32 addr, char *buf)
257{
258 buf[0] = 0; /* Reserved */
259 buf[1] = 0xff; /* Multicast QPN */
260 buf[2] = 0xff;
261 buf[3] = 0xff;
262 addr = ntohl(addr);
263 buf[4] = 0xff;
264 buf[5] = 0x12; /* link local scope */
265 buf[6] = 0x40; /* IPv4 signature */
266 buf[7] = 0x1b;
267 buf[8] = 0; /* P_Key */
268 buf[9] = 0;
269 buf[10] = 0;
270 buf[11] = 0;
271 buf[12] = 0;
272 buf[13] = 0;
273 buf[14] = 0;
274 buf[15] = 0;
275 buf[19] = addr & 0xff;
276 addr >>= 8;
277 buf[18] = addr & 0xff;
278 addr >>= 8;
279 buf[17] = addr & 0xff;
280 addr >>= 8;
281 buf[16] = addr & 0x0f;
282}
283
284#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
285#include <linux/ipv6.h>
286#endif
287
288static __inline__ void inet_reset_saddr(struct sock *sk)
289{
290 inet_sk(sk)->rcv_saddr = inet_sk(sk)->saddr = 0;
291#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
292 if (sk->sk_family == PF_INET6) {
293 struct ipv6_pinfo *np = inet6_sk(sk);
294
295 memset(&np->saddr, 0, sizeof(np->saddr));
296 memset(&np->rcv_saddr, 0, sizeof(np->rcv_saddr));
297 }
298#endif
299}
300
301#endif
302
303extern int ip_call_ra_chain(struct sk_buff *skb);
304
305/*
306 * Functions provided by ip_fragment.o
307 */
308
309enum ip_defrag_users
310{
311 IP_DEFRAG_LOCAL_DELIVER,
312 IP_DEFRAG_CALL_RA_CHAIN,
313 IP_DEFRAG_CONNTRACK_IN,
314 IP_DEFRAG_CONNTRACK_OUT,
315 IP_DEFRAG_NAT_OUT,
316 IP_DEFRAG_VS_IN,
317 IP_DEFRAG_VS_OUT,
318 IP_DEFRAG_VS_FWD
319};
320
321struct sk_buff *ip_defrag(struct sk_buff *skb, u32 user);
322extern int ip_frag_nqueues;
323extern atomic_t ip_frag_mem;
324
325/*
326 * Functions provided by ip_forward.c
327 */
328
329extern int ip_forward(struct sk_buff *skb);
330extern int ip_net_unreachable(struct sk_buff *skb);
331
332/*
333 * Functions provided by ip_options.c
334 */
335
336extern void ip_options_build(struct sk_buff *skb, struct ip_options *opt, u32 daddr, struct rtable *rt, int is_frag);
337extern int ip_options_echo(struct ip_options *dopt, struct sk_buff *skb);
338extern void ip_options_fragment(struct sk_buff *skb);
339extern int ip_options_compile(struct ip_options *opt, struct sk_buff *skb);
4c6ea29d
ACM
340extern int ip_options_get(struct ip_options **optp,
341 unsigned char *data, int optlen);
342extern int ip_options_get_from_user(struct ip_options **optp,
343 unsigned char __user *data, int optlen);
1da177e4
LT
344extern void ip_options_undo(struct ip_options * opt);
345extern void ip_forward_options(struct sk_buff *skb);
346extern int ip_options_rcv_srr(struct sk_buff *skb);
347
348/*
349 * Functions provided by ip_sockglue.c
350 */
351
352extern void ip_cmsg_recv(struct msghdr *msg, struct sk_buff *skb);
353extern int ip_cmsg_send(struct msghdr *msg, struct ipcm_cookie *ipc);
354extern int ip_setsockopt(struct sock *sk, int level, int optname, char __user *optval, int optlen);
355extern int ip_getsockopt(struct sock *sk, int level, int optname, char __user *optval, int __user *optlen);
356extern int ip_ra_control(struct sock *sk, unsigned char on, void (*destructor)(struct sock *));
357
358extern int ip_recv_error(struct sock *sk, struct msghdr *msg, int len);
359extern void ip_icmp_error(struct sock *sk, struct sk_buff *skb, int err,
360 u16 port, u32 info, u8 *payload);
361extern void ip_local_error(struct sock *sk, int err, u32 daddr, u16 dport,
362 u32 info);
363
364/* sysctl helpers - any sysctl which holds a value that ends up being
365 * fed into the routing cache should use these handlers.
366 */
367int ipv4_doint_and_flush(ctl_table *ctl, int write,
368 struct file* filp, void __user *buffer,
369 size_t *lenp, loff_t *ppos);
370int ipv4_doint_and_flush_strategy(ctl_table *table, int __user *name, int nlen,
371 void __user *oldval, size_t __user *oldlenp,
372 void __user *newval, size_t newlen,
373 void **context);
20380731
ACM
374#ifdef CONFIG_PROC_FS
375extern int ip_misc_proc_init(void);
376#endif
377
378extern struct ctl_table ipv4_table[];
1da177e4
LT
379
380#endif /* _IP_H */
This page took 0.10007 seconds and 5 git commands to generate.