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 AF_INET socket handler.
7 *
8 * Version: @(#)sock.h 1.0.4 05/13/93
9 *
10 * Authors: Ross Biro, <bir7@leland.Stanford.Edu>
11 * Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
12 * Corey Minyard <wf-rch!minyard@relay.EU.net>
13 * Florian La Roche <flla@stud.uni-sb.de>
14 *
15 * Fixes:
16 * Alan Cox : Volatiles in skbuff pointers. See
17 * skbuff comments. May be overdone,
18 * better to prove they can be removed
19 * than the reverse.
20 * Alan Cox : Added a zapped field for tcp to note
21 * a socket is reset and must stay shut up
22 * Alan Cox : New fields for options
23 * Pauline Middelink : identd support
24 *
25 * This program is free software; you can redistribute it and/or
26 * modify it under the terms of the GNU General Public License
27 * as published by the Free Software Foundation; either version
28 * 2 of the License, or (at your option) any later version.
29 */
30 #ifndef _SOCK_H
31 #define _SOCK_H
32
33 #include <linux/timer.h>
34 #include <linux/ip.h> /* struct options */
35 #include <linux/tcp.h> /* struct tcphdr */
36
37 #include "skbuff.h" /* struct sk_buff */
38 #include "protocol.h" /* struct inet_protocol */
39 #ifdef CONFIG_AX25
40 #include "ax25.h"
41 #endif
42 #ifdef CONFIG_IPX
43 #include "ipx.h"
44 #endif
45
46 #define SOCK_ARRAY_SIZE 64
47
48
49 /*
50 * This structure really needs to be cleaned up.
51 * Most of it is for TCP, and not used by any of
52 * the other protocols.
53 */
54 struct sock {
55 struct options *opt;
56 volatile unsigned long wmem_alloc;
57 volatile unsigned long rmem_alloc;
58 unsigned long send_seq;
59 unsigned long acked_seq;
60 unsigned long copied_seq;
61 unsigned long rcv_ack_seq;
62 unsigned long window_seq;
63 unsigned long fin_seq;
64
65 /*
66 * Not all are volatile, but some are, so we
67 * might as well say they all are.
68 */
69 volatile char inuse,
70 dead,
71 urginline,
72 intr,
73 blog,
74 done,
75 reuse,
76 keepopen,
77 linger,
78 delay_acks,
79 destroy,
80 ack_timed,
81 no_check,
82 exp_growth,
83 zapped, /* In ax25 & ipx means not linked */
84 broadcast;
85 unsigned long lingertime;
86 int proc;
87 struct sock *next;
88 struct sock *pair;
89 struct sk_buff *volatile send_tail;
90 struct sk_buff *volatile send_head;
91 struct sk_buff *volatile back_log;
92 struct sk_buff *send_tmp;
93 long retransmits;
94 struct sk_buff *volatile wback,
95 *volatile wfront,
96 *volatile rqueue;
97 struct proto *prot;
98 struct wait_queue **sleep;
99 unsigned long daddr;
100 unsigned long saddr;
101 unsigned short max_unacked;
102 unsigned short window;
103 unsigned short bytes_rcv;
104 unsigned short mtu;
105 unsigned short num;
106 volatile unsigned short cong_window;
107 volatile unsigned short packets_out;
108 volatile unsigned short urg;
109 volatile unsigned short shutdown;
110 unsigned short mss;
111 volatile unsigned long rtt;
112 volatile unsigned long mdev;
113 volatile unsigned short backoff;
114 volatile short err;
115 unsigned char protocol;
116 volatile unsigned char state;
117 volatile unsigned char ack_backlog;
118 unsigned char max_ack_backlog;
119 unsigned char priority;
120 unsigned char debug;
121 unsigned short rcvbuf;
122 unsigned short sndbuf;
123 unsigned short type;
124 #ifdef CONFIG_IPX
125 ipx_address ipx_source_addr,ipx_dest_addr;
126 unsigned short ipx_type;
127 #endif
128 #ifdef CONFIG_AX25
129 /* Really we want to add a per protocol private area */
130 ax25_address ax25_source_addr,ax25_dest_addr;
131 struct sk_buff *volatile ax25_retxq[8];
132 char ax25_state,ax25_vs,ax25_vr,ax25_lastrxnr,ax25_lasttxnr;
133 char ax25_condition;
134 char ax25_retxcnt;
135 char ax25_xx;
136 char ax25_retxqi;
137 char ax25_rrtimer;
138 char ax25_timer;
139 #endif
140 struct tcphdr dummy_th;
141
142 /* This part is used for the timeout functions (timer.c). */
143 int timeout; /* What are we waiting for? */
144 struct timer_list timer;
145
146 /* identd */
147 struct socket *socket;
148 };
149
150 struct proto {
151 void *(*wmalloc)(struct sock *sk,
152 unsigned long size, int force,
153 int priority);
154 void *(*rmalloc)(struct sock *sk,
155 unsigned long size, int force,
156 int priority);
157 void (*wfree)(struct sock *sk, void *mem,
158 unsigned long size);
159 void (*rfree)(struct sock *sk, void *mem,
160 unsigned long size);
161 unsigned long (*rspace)(struct sock *sk);
162 unsigned long (*wspace)(struct sock *sk);
163 void (*close)(struct sock *sk, int timeout);
164 int (*read)(struct sock *sk, unsigned char *to,
165 int len, int nonblock, unsigned flags);
166 int (*write)(struct sock *sk, unsigned char *to,
167 int len, int nonblock, unsigned flags);
168 int (*sendto)(struct sock *sk,
169 unsigned char *from, int len, int noblock,
170 unsigned flags, struct sockaddr_in *usin,
171 int addr_len);
172 int (*recvfrom)(struct sock *sk,
173 unsigned char *from, int len, int noblock,
174 unsigned flags, struct sockaddr_in *usin,
175 int *addr_len);
176 int (*build_header)(struct sk_buff *skb,
177 unsigned long saddr,
178 unsigned long daddr,
179 struct device **dev, int type,
180 struct options *opt, int len);
181 int (*connect)(struct sock *sk,
182 struct sockaddr_in *usin, int addr_len);
183 struct sock *(*accept) (struct sock *sk, int flags);
184 void (*queue_xmit)(struct sock *sk,
185 struct device *dev, struct sk_buff *skb,
186 int free);
187 void (*retransmit)(struct sock *sk, int all);
188 void (*write_wakeup)(struct sock *sk);
189 void (*read_wakeup)(struct sock *sk);
190 int (*rcv)(struct sk_buff *buff, struct device *dev,
191 struct options *opt, unsigned long daddr,
192 unsigned short len, unsigned long saddr,
193 int redo, struct inet_protocol *protocol);
194 int (*select)(struct sock *sk, int which,
195 select_table *wait);
196 int (*ioctl)(struct sock *sk, int cmd,
197 unsigned long arg);
198 int (*init)(struct sock *sk);
199 void (*shutdown)(struct sock *sk, int how);
200 unsigned short max_header;
201 unsigned long retransmits;
202 struct sock *sock_array[SOCK_ARRAY_SIZE];
203 char name[80];
204 };
205
206 #define TIME_WRITE 1
207 #define TIME_CLOSE 2
208 #define TIME_KEEPOPEN 3
209 #define TIME_DESTROY 4
210 #define TIME_DONE 5 /* used to absorb those last few packets */
211 #define SOCK_DESTROY_TIME 1000 /* about 10 seconds */
212
213 #define PROT_SOCK 1024 /* Sockets 0-1023 can't be bound too unless you are superuser */
214
215 #define SHUTDOWN_MASK 3
216 #define RCV_SHUTDOWN 1
217 #define SEND_SHUTDOWN 2
218
219
220 extern void destroy_sock(struct sock *sk);
221 extern unsigned short get_new_socknum(struct proto *, unsigned short);
222 extern void put_sock(unsigned short, struct sock *);
223 extern void release_sock(struct sock *sk);
224 extern struct sock *get_sock(struct proto *, unsigned short,
225 unsigned long, unsigned short,
226 unsigned long);
227 extern void print_sk(struct sock *);
228 extern void *sock_wmalloc(struct sock *sk,
229 unsigned long size, int force,
230 int priority);
231 extern void *sock_rmalloc(struct sock *sk,
232 unsigned long size, int force,
233 int priority);
234 extern void sock_wfree(struct sock *sk, void *mem,
235 unsigned long size);
236 extern void sock_rfree(struct sock *sk, void *mem,
237 unsigned long size);
238 extern unsigned long sock_rspace(struct sock *sk);
239 extern unsigned long sock_wspace(struct sock *sk);
240
241
242 /* declarations from timer.c */
243 extern struct sock *timer_base;
244
245 void delete_timer (struct sock *);
246 void reset_timer (struct sock *, int, unsigned long);
247 void net_timer (unsigned long);
248
249
250 #endif /* _SOCK_H */