|
|
1.1 ! root 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, <[email protected]> ! 11: * Fred N. van Kempen, <[email protected]> ! 12: * Corey Minyard <[email protected]> ! 13: * Florian La Roche <[email protected]> ! 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: * Alan Cox : Eliminate low level recv/recvfrom ! 25: * ! 26: * This program is free software; you can redistribute it and/or ! 27: * modify it under the terms of the GNU General Public License ! 28: * as published by the Free Software Foundation; either version ! 29: * 2 of the License, or (at your option) any later version. ! 30: */ ! 31: #ifndef _SOCK_H ! 32: #define _SOCK_H ! 33: ! 34: #include <linux/timer.h> ! 35: #include <linux/ip.h> /* struct options */ ! 36: #include <linux/in.h> /* struct sockaddr_in */ ! 37: #include <linux/tcp.h> /* struct tcphdr */ ! 38: #include <linux/config.h> ! 39: ! 40: #include <linux/netdevice.h> ! 41: #include <linux/skbuff.h> /* struct sk_buff */ ! 42: #include <net/protocol.h> /* struct inet_protocol */ ! 43: #ifdef CONFIG_AX25 ! 44: #include <net/ax25.h> ! 45: #ifdef CONFIG_NETROM ! 46: #include <net/netrom.h> ! 47: #endif ! 48: #endif ! 49: #ifdef CONFIG_IPX ! 50: #include <net/ipx.h> ! 51: #endif ! 52: #ifdef CONFIG_ATALK ! 53: #include <linux/atalk.h> ! 54: #endif ! 55: ! 56: #include <linux/igmp.h> ! 57: ! 58: /* Think big (also on some systems a byte is faster) */ ! 59: #define SOCK_ARRAY_SIZE 256 ! 60: ! 61: ! 62: /* ! 63: * The AF_UNIX specific socket options ! 64: */ ! 65: ! 66: struct unix_opt ! 67: { ! 68: int family; ! 69: char * name; ! 70: int locks; ! 71: struct inode * inode; ! 72: struct semaphore readsem; ! 73: struct sock * other; ! 74: }; ! 75: ! 76: /* ! 77: * IP packet socket options ! 78: */ ! 79: ! 80: struct inet_packet_opt ! 81: { ! 82: struct notifier_block notifier; /* Used when bound */ ! 83: struct device *bound_dev; ! 84: unsigned long dev_stamp; ! 85: struct packet_type *prot_hook; ! 86: char device_name[15]; ! 87: }; ! 88: ! 89: ! 90: /* ! 91: * This structure really needs to be cleaned up. ! 92: * Most of it is for TCP, and not used by any of ! 93: * the other protocols. ! 94: */ ! 95: struct sock ! 96: { ! 97: struct options *opt; ! 98: volatile unsigned long wmem_alloc; ! 99: volatile unsigned long rmem_alloc; ! 100: unsigned long allocation; /* Allocation mode */ ! 101: __u32 write_seq; ! 102: __u32 sent_seq; ! 103: __u32 acked_seq; ! 104: __u32 copied_seq; ! 105: __u32 rcv_ack_seq; ! 106: __u32 window_seq; ! 107: __u32 fin_seq; ! 108: __u32 urg_seq; ! 109: __u32 urg_data; ! 110: int users; /* user count */ ! 111: /* ! 112: * Not all are volatile, but some are, so we ! 113: * might as well say they all are. ! 114: */ ! 115: volatile char dead, ! 116: urginline, ! 117: intr, ! 118: blog, ! 119: done, ! 120: reuse, ! 121: keepopen, ! 122: linger, ! 123: delay_acks, ! 124: destroy, ! 125: ack_timed, ! 126: no_check, ! 127: zapped, /* In ax25 & ipx means not linked */ ! 128: broadcast, ! 129: nonagle, ! 130: bsdism; ! 131: unsigned long lingertime; ! 132: int proc; ! 133: struct sock *next; ! 134: struct sock *prev; /* Doubly linked chain.. */ ! 135: struct sock *pair; ! 136: struct sk_buff * volatile send_head; ! 137: struct sk_buff * volatile send_tail; ! 138: struct sk_buff_head back_log; ! 139: struct sk_buff *partial; ! 140: struct timer_list partial_timer; ! 141: long retransmits; ! 142: struct sk_buff_head write_queue, ! 143: receive_queue; ! 144: struct proto *prot; ! 145: struct wait_queue **sleep; ! 146: __u32 daddr; ! 147: __u32 saddr; /* Sending source */ ! 148: __u32 rcv_saddr; /* Bound address */ ! 149: unsigned short max_unacked; ! 150: unsigned short window; ! 151: __u32 lastwin_seq; /* sequence number when we last updated the window we offer */ ! 152: volatile unsigned long ato; /* ack timeout */ ! 153: volatile unsigned long lrcvtime; /* jiffies at last rcv */ ! 154: unsigned short bytes_rcv; ! 155: /* ! 156: * mss is min(mtu, max_window) ! 157: */ ! 158: unsigned short mtu; /* mss negotiated in the syn's */ ! 159: volatile unsigned short mss; /* current eff. mss - can change */ ! 160: volatile unsigned short user_mss; /* mss requested by user in ioctl */ ! 161: volatile unsigned short max_window; ! 162: unsigned long window_clamp; ! 163: unsigned short num; ! 164: volatile unsigned short cong_window; ! 165: volatile unsigned short cong_count; ! 166: volatile unsigned short ssthresh; ! 167: volatile unsigned short packets_out; ! 168: volatile unsigned short shutdown; ! 169: volatile unsigned long rtt; ! 170: volatile unsigned long mdev; ! 171: volatile unsigned long rto; ! 172: ! 173: /* ! 174: * currently backoff isn't used, but I'm maintaining it in case ! 175: * we want to go back to a backoff formula that needs it ! 176: */ ! 177: ! 178: volatile unsigned short backoff; ! 179: volatile int err, err_soft; /* Soft holds errors that don't ! 180: cause failure but are the cause ! 181: of a persistent failure not just ! 182: 'timed out' */ ! 183: unsigned char protocol; ! 184: volatile unsigned char state; ! 185: volatile unsigned char ack_backlog; ! 186: unsigned char max_ack_backlog; ! 187: unsigned char priority; ! 188: unsigned char debug; ! 189: unsigned short rcvbuf; ! 190: unsigned short sndbuf; ! 191: unsigned short type; ! 192: unsigned char localroute; /* Route locally only */ ! 193: #ifdef CONFIG_IPX ! 194: /* ! 195: * Once the IPX ncpd patches are in these are going into protinfo ! 196: */ ! 197: ipx_address ipx_dest_addr; ! 198: ipx_interface *ipx_intrfc; ! 199: unsigned short ipx_port; ! 200: ! 201: /* To handle asynchronous messages from the NetWare server, we have to ! 202: * know the connection this socket belongs to. Sorry to blow up this ! 203: * structure even more. */ ! 204: struct ncp_server *ipx_ncp_server; ! 205: ! 206: #ifdef CONFIG_IPX_INTERN ! 207: unsigned char ipx_node[IPX_NODE_LEN]; ! 208: #endif ! 209: unsigned short ipx_type; ! 210: #endif ! 211: #ifdef CONFIG_AX25 ! 212: ax25_cb *ax25; ! 213: #ifdef CONFIG_NETROM ! 214: nr_cb *nr; ! 215: #endif ! 216: #endif ! 217: ! 218: /* ! 219: * This is where all the private (optional) areas that don't ! 220: * overlap will eventually live. ! 221: */ ! 222: ! 223: union ! 224: { ! 225: struct unix_opt af_unix; ! 226: #ifdef CONFIG_ATALK ! 227: struct atalk_sock af_at; ! 228: #endif ! 229: #ifdef CONFIG_INET ! 230: struct inet_packet_opt af_packet; ! 231: #endif ! 232: } protinfo; ! 233: ! 234: /* ! 235: * IP 'private area' or will be eventually ! 236: */ ! 237: int ip_ttl; /* TTL setting */ ! 238: int ip_tos; /* TOS */ ! 239: struct tcphdr dummy_th; ! 240: struct timer_list keepalive_timer; /* TCP keepalive hack */ ! 241: struct timer_list retransmit_timer; /* TCP retransmit timer */ ! 242: struct timer_list ack_timer; /* TCP delayed ack timer */ ! 243: int ip_xmit_timeout; /* Why the timeout is running */ ! 244: struct rtable *ip_route_cache; /* Cached output route */ ! 245: unsigned char ip_hdrincl; /* Include headers ? */ ! 246: #ifdef CONFIG_IP_MULTICAST ! 247: int ip_mc_ttl; /* Multicasting TTL */ ! 248: int ip_mc_loop; /* Loopback */ ! 249: char ip_mc_name[MAX_ADDR_LEN];/* Multicast device name */ ! 250: struct ip_mc_socklist *ip_mc_list; /* Group array */ ! 251: #endif ! 252: ! 253: /* ! 254: * This part is used for the timeout functions (timer.c). ! 255: */ ! 256: ! 257: int timeout; /* What are we waiting for? */ ! 258: struct timer_list timer; /* This is the TIME_WAIT/receive timer ! 259: * when we are doing IP ! 260: */ ! 261: struct timeval stamp; ! 262: ! 263: /* ! 264: * Identd ! 265: */ ! 266: ! 267: struct socket *socket; ! 268: ! 269: /* ! 270: * Callbacks ! 271: */ ! 272: ! 273: void (*state_change)(struct sock *sk); ! 274: void (*data_ready)(struct sock *sk,int bytes); ! 275: void (*write_space)(struct sock *sk); ! 276: void (*error_report)(struct sock *sk); ! 277: ! 278: }; ! 279: ! 280: /* ! 281: * IP protocol blocks we attach to sockets. ! 282: */ ! 283: ! 284: struct proto ! 285: { ! 286: void (*close)(struct sock *sk, unsigned long timeout); ! 287: int (*build_header)(struct sk_buff *skb, ! 288: __u32 saddr, ! 289: __u32 daddr, ! 290: struct device **dev, int type, ! 291: struct options *opt, int len, ! 292: int tos, int ttl, struct rtable ** rp); ! 293: int (*connect)(struct sock *sk, ! 294: struct sockaddr_in *usin, int addr_len); ! 295: struct sock * (*accept) (struct sock *sk, int flags); ! 296: void (*queue_xmit)(struct sock *sk, ! 297: struct device *dev, struct sk_buff *skb, ! 298: int free); ! 299: void (*retransmit)(struct sock *sk, int all); ! 300: void (*write_wakeup)(struct sock *sk); ! 301: void (*read_wakeup)(struct sock *sk); ! 302: int (*rcv)(struct sk_buff *buff, struct device *dev, ! 303: struct options *opt, __u32 daddr, ! 304: unsigned short len, __u32 saddr, ! 305: int redo, struct inet_protocol *protocol); ! 306: int (*select)(struct sock *sk, int which, ! 307: select_table *wait); ! 308: int (*ioctl)(struct sock *sk, int cmd, ! 309: unsigned long arg); ! 310: int (*init)(struct sock *sk); ! 311: void (*shutdown)(struct sock *sk, int how); ! 312: int (*setsockopt)(struct sock *sk, int level, int optname, ! 313: char *optval, int optlen); ! 314: int (*getsockopt)(struct sock *sk, int level, int optname, ! 315: char *optval, int *option); ! 316: int (*sendmsg)(struct sock *sk, struct msghdr *msg, int len, ! 317: int noblock, int flags); ! 318: int (*recvmsg)(struct sock *sk, struct msghdr *msg, int len, ! 319: int noblock, int flags, int *addr_len); ! 320: int (*bind)(struct sock *sk, struct sockaddr *uaddr, int addr_len); ! 321: unsigned short max_header; ! 322: unsigned long retransmits; ! 323: char name[32]; ! 324: int inuse, highestinuse; ! 325: struct sock * sock_array[SOCK_ARRAY_SIZE]; ! 326: }; ! 327: ! 328: #define TIME_WRITE 1 ! 329: #define TIME_CLOSE 2 ! 330: #define TIME_KEEPOPEN 3 ! 331: #define TIME_DESTROY 4 ! 332: #define TIME_DONE 5 /* Used to absorb those last few packets */ ! 333: #define TIME_PROBE0 6 ! 334: /* ! 335: * About 10 seconds ! 336: */ ! 337: #define SOCK_DESTROY_TIME (10*HZ) ! 338: ! 339: ! 340: /* ! 341: * Sockets 0-1023 can't be bound too unless you are superuser ! 342: */ ! 343: ! 344: #define PROT_SOCK 1024 ! 345: ! 346: ! 347: #define SHUTDOWN_MASK 3 ! 348: #define RCV_SHUTDOWN 1 ! 349: #define SEND_SHUTDOWN 2 ! 350: ! 351: /* ! 352: * Used by processes to "lock" a socket state, so that ! 353: * interrupts and bottom half handlers won't change it ! 354: * from under us. It essentially blocks any incoming ! 355: * packets, so that we won't get any new data or any ! 356: * packets that change the state of the socket. ! 357: * ! 358: * Note the 'barrier()' calls: gcc may not move a lock ! 359: * "downwards" or a unlock "upwards" when optimizing. ! 360: */ ! 361: extern void __release_sock(struct sock *sk); ! 362: ! 363: static inline void lock_sock(struct sock *sk) ! 364: { ! 365: #if 1 ! 366: /* debugging code: the test isn't even 100% correct, but it can catch bugs */ ! 367: /* Note that a double lock is ok in theory - it's just _usually_ a bug */ ! 368: if (sk->users) { ! 369: __label__ here; ! 370: printk("double lock on socket at %p\n", &&here); ! 371: here: ! 372: } ! 373: #endif ! 374: sk->users++; ! 375: barrier(); ! 376: } ! 377: ! 378: static inline void release_sock(struct sock *sk) ! 379: { ! 380: barrier(); ! 381: #if 1 ! 382: /* debugging code: remove me when ok */ ! 383: if (sk->users == 0) { ! 384: __label__ here; ! 385: sk->users = 1; ! 386: printk("trying to unlock unlocked socket at %p\n", &&here); ! 387: here: ! 388: } ! 389: #endif ! 390: if (!--sk->users) ! 391: __release_sock(sk); ! 392: } ! 393: ! 394: ! 395: extern void destroy_sock(struct sock *sk); ! 396: extern unsigned short get_new_socknum(struct proto *, ! 397: unsigned short); ! 398: extern void put_sock(unsigned short, struct sock *); ! 399: extern struct sock *get_sock(struct proto *, unsigned short, ! 400: unsigned long, unsigned short, ! 401: unsigned long); ! 402: extern struct sock *get_sock_mcast(struct sock *, unsigned short, ! 403: unsigned long, unsigned short, ! 404: unsigned long); ! 405: extern struct sock *get_sock_raw(struct sock *, unsigned short, ! 406: unsigned long, unsigned long); ! 407: ! 408: extern struct sk_buff *sock_wmalloc(struct sock *sk, ! 409: unsigned long size, int force, ! 410: int priority); ! 411: extern struct sk_buff *sock_rmalloc(struct sock *sk, ! 412: unsigned long size, int force, ! 413: int priority); ! 414: extern void sock_wfree(struct sock *sk, ! 415: struct sk_buff *skb); ! 416: extern void sock_rfree(struct sock *sk, ! 417: struct sk_buff *skb); ! 418: extern unsigned long sock_rspace(struct sock *sk); ! 419: extern unsigned long sock_wspace(struct sock *sk); ! 420: ! 421: extern int sock_setsockopt(struct sock *sk, int level, ! 422: int op, char *optval, ! 423: int optlen); ! 424: ! 425: extern int sock_getsockopt(struct sock *sk, int level, ! 426: int op, char *optval, ! 427: int *optlen); ! 428: extern struct sk_buff *sock_alloc_send_skb(struct sock *skb, ! 429: unsigned long size, ! 430: unsigned long fallback, ! 431: int noblock, ! 432: int *errcode); ! 433: ! 434: /* ! 435: * Queue a received datagram if it will fit. Stream and sequenced ! 436: * protocols can't normally use this as they need to fit buffers in ! 437: * and play with them. ! 438: * ! 439: * Inlined as its very short and called for pretty much every ! 440: * packet ever received. ! 441: */ ! 442: ! 443: extern __inline__ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb) ! 444: { ! 445: unsigned long flags; ! 446: if(sk->rmem_alloc + skb->truesize >= sk->rcvbuf) ! 447: return -ENOMEM; ! 448: save_flags(flags); ! 449: cli(); ! 450: sk->rmem_alloc+=skb->truesize; ! 451: skb->sk=sk; ! 452: restore_flags(flags); ! 453: skb_queue_tail(&sk->receive_queue,skb); ! 454: if(!sk->dead) ! 455: sk->data_ready(sk,skb->len); ! 456: return 0; ! 457: } ! 458: ! 459: /* ! 460: * Recover an error report and clear atomically ! 461: */ ! 462: ! 463: extern __inline__ int sock_error(struct sock *sk) ! 464: { ! 465: int err=xchg(&sk->err,0); ! 466: return -err; ! 467: } ! 468: ! 469: /* ! 470: * Declarations from timer.c ! 471: */ ! 472: ! 473: extern struct sock *timer_base; ! 474: ! 475: extern void delete_timer (struct sock *); ! 476: extern void reset_timer (struct sock *, int, unsigned long); ! 477: extern void net_timer (unsigned long); ! 478: ! 479: ! 480: /* ! 481: * Enable debug/info messages ! 482: */ ! 483: ! 484: #define NETDEBUG(x) x ! 485: ! 486: #endif /* _SOCK_H */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.