kernel.org linux-2.6.9
[linux-2.6.git] / net / core / sock.c
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  *              Generic socket support routines. Memory allocators, socket lock/release
7  *              handler for protocols to use and generic option handler.
8  *
9  *
10  * Version:     $Id: sock.c,v 1.117 2002/02/01 22:01:03 davem Exp $
11  *
12  * Authors:     Ross Biro, <bir7@leland.Stanford.Edu>
13  *              Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
14  *              Florian La Roche, <flla@stud.uni-sb.de>
15  *              Alan Cox, <A.Cox@swansea.ac.uk>
16  *
17  * Fixes:
18  *              Alan Cox        :       Numerous verify_area() problems
19  *              Alan Cox        :       Connecting on a connecting socket
20  *                                      now returns an error for tcp.
21  *              Alan Cox        :       sock->protocol is set correctly.
22  *                                      and is not sometimes left as 0.
23  *              Alan Cox        :       connect handles icmp errors on a
24  *                                      connect properly. Unfortunately there
25  *                                      is a restart syscall nasty there. I
26  *                                      can't match BSD without hacking the C
27  *                                      library. Ideas urgently sought!
28  *              Alan Cox        :       Disallow bind() to addresses that are
29  *                                      not ours - especially broadcast ones!!
30  *              Alan Cox        :       Socket 1024 _IS_ ok for users. (fencepost)
31  *              Alan Cox        :       sock_wfree/sock_rfree don't destroy sockets,
32  *                                      instead they leave that for the DESTROY timer.
33  *              Alan Cox        :       Clean up error flag in accept
34  *              Alan Cox        :       TCP ack handling is buggy, the DESTROY timer
35  *                                      was buggy. Put a remove_sock() in the handler
36  *                                      for memory when we hit 0. Also altered the timer
37  *                                      code. The ACK stuff can wait and needs major 
38  *                                      TCP layer surgery.
39  *              Alan Cox        :       Fixed TCP ack bug, removed remove sock
40  *                                      and fixed timer/inet_bh race.
41  *              Alan Cox        :       Added zapped flag for TCP
42  *              Alan Cox        :       Move kfree_skb into skbuff.c and tidied up surplus code
43  *              Alan Cox        :       for new sk_buff allocations wmalloc/rmalloc now call alloc_skb
44  *              Alan Cox        :       kfree_s calls now are kfree_skbmem so we can track skb resources
45  *              Alan Cox        :       Supports socket option broadcast now as does udp. Packet and raw need fixing.
46  *              Alan Cox        :       Added RCVBUF,SNDBUF size setting. It suddenly occurred to me how easy it was so...
47  *              Rick Sladkey    :       Relaxed UDP rules for matching packets.
48  *              C.E.Hawkins     :       IFF_PROMISC/SIOCGHWADDR support
49  *      Pauline Middelink       :       identd support
50  *              Alan Cox        :       Fixed connect() taking signals I think.
51  *              Alan Cox        :       SO_LINGER supported
52  *              Alan Cox        :       Error reporting fixes
53  *              Anonymous       :       inet_create tidied up (sk->reuse setting)
54  *              Alan Cox        :       inet sockets don't set sk->type!
55  *              Alan Cox        :       Split socket option code
56  *              Alan Cox        :       Callbacks
57  *              Alan Cox        :       Nagle flag for Charles & Johannes stuff
58  *              Alex            :       Removed restriction on inet fioctl
59  *              Alan Cox        :       Splitting INET from NET core
60  *              Alan Cox        :       Fixed bogus SO_TYPE handling in getsockopt()
61  *              Adam Caldwell   :       Missing return in SO_DONTROUTE/SO_DEBUG code
62  *              Alan Cox        :       Split IP from generic code
63  *              Alan Cox        :       New kfree_skbmem()
64  *              Alan Cox        :       Make SO_DEBUG superuser only.
65  *              Alan Cox        :       Allow anyone to clear SO_DEBUG
66  *                                      (compatibility fix)
67  *              Alan Cox        :       Added optimistic memory grabbing for AF_UNIX throughput.
68  *              Alan Cox        :       Allocator for a socket is settable.
69  *              Alan Cox        :       SO_ERROR includes soft errors.
70  *              Alan Cox        :       Allow NULL arguments on some SO_ opts
71  *              Alan Cox        :       Generic socket allocation to make hooks
72  *                                      easier (suggested by Craig Metz).
73  *              Michael Pall    :       SO_ERROR returns positive errno again
74  *              Steve Whitehouse:       Added default destructor to free
75  *                                      protocol private data.
76  *              Steve Whitehouse:       Added various other default routines
77  *                                      common to several socket families.
78  *              Chris Evans     :       Call suser() check last on F_SETOWN
79  *              Jay Schulist    :       Added SO_ATTACH_FILTER and SO_DETACH_FILTER.
80  *              Andi Kleen      :       Add sock_kmalloc()/sock_kfree_s()
81  *              Andi Kleen      :       Fix write_space callback
82  *              Chris Evans     :       Security fixes - signedness again
83  *              Arnaldo C. Melo :       cleanups, use skb_queue_purge
84  *
85  * To Fix:
86  *
87  *
88  *              This program is free software; you can redistribute it and/or
89  *              modify it under the terms of the GNU General Public License
90  *              as published by the Free Software Foundation; either version
91  *              2 of the License, or (at your option) any later version.
92  */
93
94 #include <linux/config.h>
95 #include <linux/errno.h>
96 #include <linux/types.h>
97 #include <linux/socket.h>
98 #include <linux/in.h>
99 #include <linux/kernel.h>
100 #include <linux/major.h>
101 #include <linux/module.h>
102 #include <linux/sched.h>
103 #include <linux/timer.h>
104 #include <linux/string.h>
105 #include <linux/sockios.h>
106 #include <linux/net.h>
107 #include <linux/mm.h>
108 #include <linux/slab.h>
109 #include <linux/interrupt.h>
110 #include <linux/poll.h>
111 #include <linux/tcp.h>
112 #include <linux/init.h>
113
114 #include <asm/uaccess.h>
115 #include <asm/system.h>
116
117 #include <linux/netdevice.h>
118 #include <net/protocol.h>
119 #include <linux/skbuff.h>
120 #include <net/sock.h>
121 #include <net/xfrm.h>
122 #include <linux/ipsec.h>
123
124 #include <linux/filter.h>
125
126 #ifdef CONFIG_INET
127 #include <net/tcp.h>
128 #endif
129
130 /* Take into consideration the size of the struct sk_buff overhead in the
131  * determination of these values, since that is non-constant across
132  * platforms.  This makes socket queueing behavior and performance
133  * not depend upon such differences.
134  */
135 #define _SK_MEM_PACKETS         256
136 #define _SK_MEM_OVERHEAD        (sizeof(struct sk_buff) + 256)
137 #define SK_WMEM_MAX             (_SK_MEM_OVERHEAD * _SK_MEM_PACKETS)
138 #define SK_RMEM_MAX             (_SK_MEM_OVERHEAD * _SK_MEM_PACKETS)
139
140 /* Run time adjustable parameters. */
141 __u32 sysctl_wmem_max = SK_WMEM_MAX;
142 __u32 sysctl_rmem_max = SK_RMEM_MAX;
143 __u32 sysctl_wmem_default = SK_WMEM_MAX;
144 __u32 sysctl_rmem_default = SK_RMEM_MAX;
145
146 /* Maximal space eaten by iovec or ancilliary data plus some space */
147 int sysctl_optmem_max = sizeof(unsigned long)*(2*UIO_MAXIOV + 512);
148
149 static int sock_set_timeout(long *timeo_p, char __user *optval, int optlen)
150 {
151         struct timeval tv;
152
153         if (optlen < sizeof(tv))
154                 return -EINVAL;
155         if (copy_from_user(&tv, optval, sizeof(tv)))
156                 return -EFAULT;
157
158         *timeo_p = MAX_SCHEDULE_TIMEOUT;
159         if (tv.tv_sec == 0 && tv.tv_usec == 0)
160                 return 0;
161         if (tv.tv_sec < (MAX_SCHEDULE_TIMEOUT/HZ - 1))
162                 *timeo_p = tv.tv_sec*HZ + (tv.tv_usec+(1000000/HZ-1))/(1000000/HZ);
163         return 0;
164 }
165
166 static void sock_warn_obsolete_bsdism(const char *name)
167 {
168         static int warned;
169         static char warncomm[16];
170         if (strcmp(warncomm, current->comm) && warned < 5) { 
171                 strcpy(warncomm,  current->comm); 
172                 printk(KERN_WARNING "process `%s' is using obsolete "
173                        "%s SO_BSDCOMPAT\n", warncomm, name);
174                 warned++;
175         }
176 }
177
178 /*
179  *      This is meant for all protocols to use and covers goings on
180  *      at the socket level. Everything here is generic.
181  */
182
183 int sock_setsockopt(struct socket *sock, int level, int optname,
184                     char __user *optval, int optlen)
185 {
186         struct sock *sk=sock->sk;
187         struct sk_filter *filter;
188         int val;
189         int valbool;
190         struct linger ling;
191         int ret = 0;
192         
193         /*
194          *      Options without arguments
195          */
196
197 #ifdef SO_DONTLINGER            /* Compatibility item... */
198         switch (optname) {
199                 case SO_DONTLINGER:
200                         sock_reset_flag(sk, SOCK_LINGER);
201                         return 0;
202         }
203 #endif  
204                 
205         if(optlen<sizeof(int))
206                 return(-EINVAL);
207         
208         if (get_user(val, (int __user *)optval))
209                 return -EFAULT;
210         
211         valbool = val?1:0;
212
213         lock_sock(sk);
214
215         switch(optname) 
216         {
217                 case SO_DEBUG:  
218                         if(val && !capable(CAP_NET_ADMIN))
219                         {
220                                 ret = -EACCES;
221                         }
222                         else
223                                 sk->sk_debug = valbool;
224                         break;
225                 case SO_REUSEADDR:
226                         sk->sk_reuse = valbool;
227                         break;
228                 case SO_TYPE:
229                 case SO_ERROR:
230                         ret = -ENOPROTOOPT;
231                         break;
232                 case SO_DONTROUTE:
233                         sk->sk_localroute = valbool;
234                         break;
235                 case SO_BROADCAST:
236                         sock_valbool_flag(sk, SOCK_BROADCAST, valbool);
237                         break;
238                 case SO_SNDBUF:
239                         /* Don't error on this BSD doesn't and if you think
240                            about it this is right. Otherwise apps have to
241                            play 'guess the biggest size' games. RCVBUF/SNDBUF
242                            are treated in BSD as hints */
243                            
244                         if (val > sysctl_wmem_max)
245                                 val = sysctl_wmem_max;
246
247                         sk->sk_userlocks |= SOCK_SNDBUF_LOCK;
248                         if ((val * 2) < SOCK_MIN_SNDBUF)
249                                 sk->sk_sndbuf = SOCK_MIN_SNDBUF;
250                         else
251                                 sk->sk_sndbuf = val * 2;
252
253                         /*
254                          *      Wake up sending tasks if we
255                          *      upped the value.
256                          */
257                         sk->sk_write_space(sk);
258                         break;
259
260                 case SO_RCVBUF:
261                         /* Don't error on this BSD doesn't and if you think
262                            about it this is right. Otherwise apps have to
263                            play 'guess the biggest size' games. RCVBUF/SNDBUF
264                            are treated in BSD as hints */
265                           
266                         if (val > sysctl_rmem_max)
267                                 val = sysctl_rmem_max;
268
269                         sk->sk_userlocks |= SOCK_RCVBUF_LOCK;
270                         /* FIXME: is this lower bound the right one? */
271                         if ((val * 2) < SOCK_MIN_RCVBUF)
272                                 sk->sk_rcvbuf = SOCK_MIN_RCVBUF;
273                         else
274                                 sk->sk_rcvbuf = val * 2;
275                         break;
276
277                 case SO_KEEPALIVE:
278 #ifdef CONFIG_INET
279                         if (sk->sk_protocol == IPPROTO_TCP)
280                                 tcp_set_keepalive(sk, valbool);
281 #endif
282                         sock_valbool_flag(sk, SOCK_KEEPOPEN, valbool);
283                         break;
284
285                 case SO_OOBINLINE:
286                         sock_valbool_flag(sk, SOCK_URGINLINE, valbool);
287                         break;
288
289                 case SO_NO_CHECK:
290                         sk->sk_no_check = valbool;
291                         break;
292
293                 case SO_PRIORITY:
294                         if ((val >= 0 && val <= 6) || capable(CAP_NET_ADMIN)) 
295                                 sk->sk_priority = val;
296                         else
297                                 ret = -EPERM;
298                         break;
299
300                 case SO_LINGER:
301                         if(optlen<sizeof(ling)) {
302                                 ret = -EINVAL;  /* 1003.1g */
303                                 break;
304                         }
305                         if (copy_from_user(&ling,optval,sizeof(ling))) {
306                                 ret = -EFAULT;
307                                 break;
308                         }
309                         if (!ling.l_onoff)
310                                 sock_reset_flag(sk, SOCK_LINGER);
311                         else {
312 #if (BITS_PER_LONG == 32)
313                                 if (ling.l_linger >= MAX_SCHEDULE_TIMEOUT/HZ)
314                                         sk->sk_lingertime = MAX_SCHEDULE_TIMEOUT;
315                                 else
316 #endif
317                                         sk->sk_lingertime = ling.l_linger * HZ;
318                                 sock_set_flag(sk, SOCK_LINGER);
319                         }
320                         break;
321
322                 case SO_BSDCOMPAT:
323                         sock_warn_obsolete_bsdism("setsockopt");
324                         break;
325
326                 case SO_PASSCRED:
327                         sock->passcred = valbool;
328                         break;
329
330                 case SO_TIMESTAMP:
331                         sk->sk_rcvtstamp = valbool;
332                         if (valbool) 
333                                 sock_enable_timestamp(sk);
334                         break;
335
336                 case SO_RCVLOWAT:
337                         if (val < 0)
338                                 val = INT_MAX;
339                         sk->sk_rcvlowat = val ? : 1;
340                         break;
341
342                 case SO_RCVTIMEO:
343                         ret = sock_set_timeout(&sk->sk_rcvtimeo, optval, optlen);
344                         break;
345
346                 case SO_SNDTIMEO:
347                         ret = sock_set_timeout(&sk->sk_sndtimeo, optval, optlen);
348                         break;
349
350 #ifdef CONFIG_NETDEVICES
351                 case SO_BINDTODEVICE:
352                 {
353                         char devname[IFNAMSIZ]; 
354
355                         /* Sorry... */ 
356                         if (!capable(CAP_NET_RAW)) {
357                                 ret = -EPERM;
358                                 break;
359                         }
360
361                         /* Bind this socket to a particular device like "eth0",
362                          * as specified in the passed interface name. If the
363                          * name is "" or the option length is zero the socket 
364                          * is not bound. 
365                          */ 
366
367                         if (!valbool) {
368                                 sk->sk_bound_dev_if = 0;
369                         } else {
370                                 if (optlen > IFNAMSIZ) 
371                                         optlen = IFNAMSIZ; 
372                                 if (copy_from_user(devname, optval, optlen)) {
373                                         ret = -EFAULT;
374                                         break;
375                                 }
376
377                                 /* Remove any cached route for this socket. */
378                                 sk_dst_reset(sk);
379
380                                 if (devname[0] == '\0') {
381                                         sk->sk_bound_dev_if = 0;
382                                 } else {
383                                         struct net_device *dev = dev_get_by_name(devname);
384                                         if (!dev) {
385                                                 ret = -ENODEV;
386                                                 break;
387                                         }
388                                         sk->sk_bound_dev_if = dev->ifindex;
389                                         dev_put(dev);
390                                 }
391                         }
392                         break;
393                 }
394 #endif
395
396
397                 case SO_ATTACH_FILTER:
398                         ret = -EINVAL;
399                         if (optlen == sizeof(struct sock_fprog)) {
400                                 struct sock_fprog fprog;
401
402                                 ret = -EFAULT;
403                                 if (copy_from_user(&fprog, optval, sizeof(fprog)))
404                                         break;
405
406                                 ret = sk_attach_filter(&fprog, sk);
407                         }
408                         break;
409
410                 case SO_DETACH_FILTER:
411                         spin_lock_bh(&sk->sk_lock.slock);
412                         filter = sk->sk_filter;
413                         if (filter) {
414                                 sk->sk_filter = NULL;
415                                 spin_unlock_bh(&sk->sk_lock.slock);
416                                 sk_filter_release(sk, filter);
417                                 break;
418                         }
419                         spin_unlock_bh(&sk->sk_lock.slock);
420                         ret = -ENONET;
421                         break;
422
423                 /* We implement the SO_SNDLOWAT etc to
424                    not be settable (1003.1g 5.3) */
425                 default:
426                         ret = -ENOPROTOOPT;
427                         break;
428         }
429         release_sock(sk);
430         return ret;
431 }
432
433
434 int sock_getsockopt(struct socket *sock, int level, int optname,
435                     char __user *optval, int __user *optlen)
436 {
437         struct sock *sk = sock->sk;
438         
439         union
440         {
441                 int val;
442                 struct linger ling;
443                 struct timeval tm;
444         } v;
445         
446         unsigned int lv = sizeof(int);
447         int len;
448         
449         if(get_user(len,optlen))
450                 return -EFAULT;
451         if(len < 0)
452                 return -EINVAL;
453                 
454         switch(optname) 
455         {
456                 case SO_DEBUG:          
457                         v.val = sk->sk_debug;
458                         break;
459                 
460                 case SO_DONTROUTE:
461                         v.val = sk->sk_localroute;
462                         break;
463                 
464                 case SO_BROADCAST:
465                         v.val = !!sock_flag(sk, SOCK_BROADCAST);
466                         break;
467
468                 case SO_SNDBUF:
469                         v.val = sk->sk_sndbuf;
470                         break;
471                 
472                 case SO_RCVBUF:
473                         v.val = sk->sk_rcvbuf;
474                         break;
475
476                 case SO_REUSEADDR:
477                         v.val = sk->sk_reuse;
478                         break;
479
480                 case SO_KEEPALIVE:
481                         v.val = !!sock_flag(sk, SOCK_KEEPOPEN);
482                         break;
483
484                 case SO_TYPE:
485                         v.val = sk->sk_type;                            
486                         break;
487
488                 case SO_ERROR:
489                         v.val = -sock_error(sk);
490                         if(v.val==0)
491                                 v.val = xchg(&sk->sk_err_soft, 0);
492                         break;
493
494                 case SO_OOBINLINE:
495                         v.val = !!sock_flag(sk, SOCK_URGINLINE);
496                         break;
497         
498                 case SO_NO_CHECK:
499                         v.val = sk->sk_no_check;
500                         break;
501
502                 case SO_PRIORITY:
503                         v.val = sk->sk_priority;
504                         break;
505                 
506                 case SO_LINGER: 
507                         lv              = sizeof(v.ling);
508                         v.ling.l_onoff  = !!sock_flag(sk, SOCK_LINGER);
509                         v.ling.l_linger = sk->sk_lingertime / HZ;
510                         break;
511                                         
512                 case SO_BSDCOMPAT:
513                         sock_warn_obsolete_bsdism("getsockopt");
514                         break;
515
516                 case SO_TIMESTAMP:
517                         v.val = sk->sk_rcvtstamp;
518                         break;
519
520                 case SO_RCVTIMEO:
521                         lv=sizeof(struct timeval);
522                         if (sk->sk_rcvtimeo == MAX_SCHEDULE_TIMEOUT) {
523                                 v.tm.tv_sec = 0;
524                                 v.tm.tv_usec = 0;
525                         } else {
526                                 v.tm.tv_sec = sk->sk_rcvtimeo / HZ;
527                                 v.tm.tv_usec = ((sk->sk_rcvtimeo % HZ) * 1000000) / HZ;
528                         }
529                         break;
530
531                 case SO_SNDTIMEO:
532                         lv=sizeof(struct timeval);
533                         if (sk->sk_sndtimeo == MAX_SCHEDULE_TIMEOUT) {
534                                 v.tm.tv_sec = 0;
535                                 v.tm.tv_usec = 0;
536                         } else {
537                                 v.tm.tv_sec = sk->sk_sndtimeo / HZ;
538                                 v.tm.tv_usec = ((sk->sk_sndtimeo % HZ) * 1000000) / HZ;
539                         }
540                         break;
541
542                 case SO_RCVLOWAT:
543                         v.val = sk->sk_rcvlowat;
544                         break;
545
546                 case SO_SNDLOWAT:
547                         v.val=1;
548                         break; 
549
550                 case SO_PASSCRED:
551                         v.val = sock->passcred;
552                         break;
553
554                 case SO_PEERCRED:
555                         if (len > sizeof(sk->sk_peercred))
556                                 len = sizeof(sk->sk_peercred);
557                         if (copy_to_user(optval, &sk->sk_peercred, len))
558                                 return -EFAULT;
559                         goto lenout;
560
561                 case SO_PEERNAME:
562                 {
563                         char address[128];
564
565                         if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
566                                 return -ENOTCONN;
567                         if (lv < len)
568                                 return -EINVAL;
569                         if (copy_to_user(optval, address, len))
570                                 return -EFAULT;
571                         goto lenout;
572                 }
573
574                 /* Dubious BSD thing... Probably nobody even uses it, but
575                  * the UNIX standard wants it for whatever reason... -DaveM
576                  */
577                 case SO_ACCEPTCONN:
578                         v.val = sk->sk_state == TCP_LISTEN;
579                         break;
580
581                 case SO_PEERSEC:
582                         return security_socket_getpeersec(sock, optval, optlen, len);
583
584                 default:
585                         return(-ENOPROTOOPT);
586         }
587         if (len > lv)
588                 len = lv;
589         if (copy_to_user(optval, &v, len))
590                 return -EFAULT;
591 lenout:
592         if (put_user(len, optlen))
593                 return -EFAULT;
594         return 0;
595 }
596
597 static kmem_cache_t *sk_cachep;
598
599 /**
600  *      sk_alloc - All socket objects are allocated here
601  *      @family - protocol family
602  *      @priority - for allocation (%GFP_KERNEL, %GFP_ATOMIC, etc)
603  *      @zero_it - zeroes the allocated sock
604  *      @slab - alternate slab
605  *
606  *      All socket objects are allocated here. If @zero_it is non-zero
607  *      it should have the size of the are to be zeroed, because the
608  *      private slabcaches have different sizes of the generic struct sock.
609  *      1 has been kept as a way to say sizeof(struct sock).
610  */
611 struct sock *sk_alloc(int family, int priority, int zero_it, kmem_cache_t *slab)
612 {
613         struct sock *sk = NULL;
614
615         if (!slab)
616                 slab = sk_cachep;
617         sk = kmem_cache_alloc(slab, priority);
618         if (sk) {
619                 if (zero_it) {
620                         memset(sk, 0,
621                                zero_it == 1 ? sizeof(struct sock) : zero_it);
622                         sk->sk_family = family;
623                         sock_lock_init(sk);
624                 }
625                 sk->sk_slab = slab;
626                 
627                 if (security_sk_alloc(sk, family, priority)) {
628                         kmem_cache_free(slab, sk);
629                         sk = NULL;
630                 }
631         }
632         return sk;
633 }
634
635 void sk_free(struct sock *sk)
636 {
637         struct sk_filter *filter;
638         struct module *owner = sk->sk_owner;
639
640         if (sk->sk_destruct)
641                 sk->sk_destruct(sk);
642
643         filter = sk->sk_filter;
644         if (filter) {
645                 sk_filter_release(sk, filter);
646                 sk->sk_filter = NULL;
647         }
648
649         sock_disable_timestamp(sk);
650
651         if (atomic_read(&sk->sk_omem_alloc))
652                 printk(KERN_DEBUG "%s: optmem leakage (%d bytes) detected.\n",
653                        __FUNCTION__, atomic_read(&sk->sk_omem_alloc));
654
655         security_sk_free(sk);
656         kmem_cache_free(sk->sk_slab, sk);
657         module_put(owner);
658 }
659
660 void __init sk_init(void)
661 {
662         sk_cachep = kmem_cache_create("sock", sizeof(struct sock), 0,
663                                       SLAB_HWCACHE_ALIGN, NULL, NULL);
664         if (!sk_cachep)
665                 printk(KERN_CRIT "sk_init: Cannot create sock SLAB cache!");
666
667         if (num_physpages <= 4096) {
668                 sysctl_wmem_max = 32767;
669                 sysctl_rmem_max = 32767;
670                 sysctl_wmem_default = 32767;
671                 sysctl_rmem_default = 32767;
672         } else if (num_physpages >= 131072) {
673                 sysctl_wmem_max = 131071;
674                 sysctl_rmem_max = 131071;
675         }
676 }
677
678 /*
679  *      Simple resource managers for sockets.
680  */
681
682
683 /* 
684  * Write buffer destructor automatically called from kfree_skb. 
685  */
686 void sock_wfree(struct sk_buff *skb)
687 {
688         struct sock *sk = skb->sk;
689
690         /* In case it might be waiting for more memory. */
691         atomic_sub(skb->truesize, &sk->sk_wmem_alloc);
692         if (!sk->sk_use_write_queue)
693                 sk->sk_write_space(sk);
694         sock_put(sk);
695 }
696
697 /* 
698  * Read buffer destructor automatically called from kfree_skb. 
699  */
700 void sock_rfree(struct sk_buff *skb)
701 {
702         struct sock *sk = skb->sk;
703
704         atomic_sub(skb->truesize, &sk->sk_rmem_alloc);
705 }
706
707
708 int sock_i_uid(struct sock *sk)
709 {
710         int uid;
711
712         read_lock(&sk->sk_callback_lock);
713         uid = sk->sk_socket ? SOCK_INODE(sk->sk_socket)->i_uid : 0;
714         read_unlock(&sk->sk_callback_lock);
715         return uid;
716 }
717
718 unsigned long sock_i_ino(struct sock *sk)
719 {
720         unsigned long ino;
721
722         read_lock(&sk->sk_callback_lock);
723         ino = sk->sk_socket ? SOCK_INODE(sk->sk_socket)->i_ino : 0;
724         read_unlock(&sk->sk_callback_lock);
725         return ino;
726 }
727
728 /*
729  * Allocate a skb from the socket's send buffer.
730  */
731 struct sk_buff *sock_wmalloc(struct sock *sk, unsigned long size, int force, int priority)
732 {
733         if (force || atomic_read(&sk->sk_wmem_alloc) < sk->sk_sndbuf) {
734                 struct sk_buff * skb = alloc_skb(size, priority);
735                 if (skb) {
736                         skb_set_owner_w(skb, sk);
737                         return skb;
738                 }
739         }
740         return NULL;
741 }
742
743 /*
744  * Allocate a skb from the socket's receive buffer.
745  */ 
746 struct sk_buff *sock_rmalloc(struct sock *sk, unsigned long size, int force, int priority)
747 {
748         if (force || atomic_read(&sk->sk_rmem_alloc) < sk->sk_rcvbuf) {
749                 struct sk_buff *skb = alloc_skb(size, priority);
750                 if (skb) {
751                         skb_set_owner_r(skb, sk);
752                         return skb;
753                 }
754         }
755         return NULL;
756 }
757
758 /* 
759  * Allocate a memory block from the socket's option memory buffer.
760  */ 
761 void *sock_kmalloc(struct sock *sk, int size, int priority)
762 {
763         if ((unsigned)size <= sysctl_optmem_max &&
764             atomic_read(&sk->sk_omem_alloc) + size < sysctl_optmem_max) {
765                 void *mem;
766                 /* First do the add, to avoid the race if kmalloc
767                  * might sleep.
768                  */
769                 atomic_add(size, &sk->sk_omem_alloc);
770                 mem = kmalloc(size, priority);
771                 if (mem)
772                         return mem;
773                 atomic_sub(size, &sk->sk_omem_alloc);
774         }
775         return NULL;
776 }
777
778 /*
779  * Free an option memory block.
780  */
781 void sock_kfree_s(struct sock *sk, void *mem, int size)
782 {
783         kfree(mem);
784         atomic_sub(size, &sk->sk_omem_alloc);
785 }
786
787 /* It is almost wait_for_tcp_memory minus release_sock/lock_sock.
788    I think, these locks should be removed for datagram sockets.
789  */
790 static long sock_wait_for_wmem(struct sock * sk, long timeo)
791 {
792         DEFINE_WAIT(wait);
793
794         clear_bit(SOCK_ASYNC_NOSPACE, &sk->sk_socket->flags);
795         for (;;) {
796                 if (!timeo)
797                         break;
798                 if (signal_pending(current))
799                         break;
800                 set_bit(SOCK_NOSPACE, &sk->sk_socket->flags);
801                 prepare_to_wait(sk->sk_sleep, &wait, TASK_INTERRUPTIBLE);
802                 if (atomic_read(&sk->sk_wmem_alloc) < sk->sk_sndbuf)
803                         break;
804                 if (sk->sk_shutdown & SEND_SHUTDOWN)
805                         break;
806                 if (sk->sk_err)
807                         break;
808                 timeo = schedule_timeout(timeo);
809         }
810         finish_wait(sk->sk_sleep, &wait);
811         return timeo;
812 }
813
814
815 /*
816  *      Generic send/receive buffer handlers
817  */
818
819 struct sk_buff *sock_alloc_send_pskb(struct sock *sk, unsigned long header_len,
820                                      unsigned long data_len, int noblock, int *errcode)
821 {
822         struct sk_buff *skb;
823         unsigned int gfp_mask;
824         long timeo;
825         int err;
826
827         gfp_mask = sk->sk_allocation;
828         if (gfp_mask & __GFP_WAIT)
829                 gfp_mask |= __GFP_REPEAT;
830
831         timeo = sock_sndtimeo(sk, noblock);
832         while (1) {
833                 err = sock_error(sk);
834                 if (err != 0)
835                         goto failure;
836
837                 err = -EPIPE;
838                 if (sk->sk_shutdown & SEND_SHUTDOWN)
839                         goto failure;
840
841                 if (atomic_read(&sk->sk_wmem_alloc) < sk->sk_sndbuf) {
842                         skb = alloc_skb(header_len, sk->sk_allocation);
843                         if (skb) {
844                                 int npages;
845                                 int i;
846
847                                 /* No pages, we're done... */
848                                 if (!data_len)
849                                         break;
850
851                                 npages = (data_len + (PAGE_SIZE - 1)) >> PAGE_SHIFT;
852                                 skb->truesize += data_len;
853                                 skb_shinfo(skb)->nr_frags = npages;
854                                 for (i = 0; i < npages; i++) {
855                                         struct page *page;
856                                         skb_frag_t *frag;
857
858                                         page = alloc_pages(sk->sk_allocation, 0);
859                                         if (!page) {
860                                                 err = -ENOBUFS;
861                                                 skb_shinfo(skb)->nr_frags = i;
862                                                 kfree_skb(skb);
863                                                 goto failure;
864                                         }
865
866                                         frag = &skb_shinfo(skb)->frags[i];
867                                         frag->page = page;
868                                         frag->page_offset = 0;
869                                         frag->size = (data_len >= PAGE_SIZE ?
870                                                       PAGE_SIZE :
871                                                       data_len);
872                                         data_len -= PAGE_SIZE;
873                                 }
874
875                                 /* Full success... */
876                                 break;
877                         }
878                         err = -ENOBUFS;
879                         goto failure;
880                 }
881                 set_bit(SOCK_ASYNC_NOSPACE, &sk->sk_socket->flags);
882                 set_bit(SOCK_NOSPACE, &sk->sk_socket->flags);
883                 err = -EAGAIN;
884                 if (!timeo)
885                         goto failure;
886                 if (signal_pending(current))
887                         goto interrupted;
888                 timeo = sock_wait_for_wmem(sk, timeo);
889         }
890
891         skb_set_owner_w(skb, sk);
892         return skb;
893
894 interrupted:
895         err = sock_intr_errno(timeo);
896 failure:
897         *errcode = err;
898         return NULL;
899 }
900
901 struct sk_buff *sock_alloc_send_skb(struct sock *sk, unsigned long size, 
902                                     int noblock, int *errcode)
903 {
904         return sock_alloc_send_pskb(sk, size, 0, noblock, errcode);
905 }
906
907 void __lock_sock(struct sock *sk)
908 {
909         DEFINE_WAIT(wait);
910
911         for(;;) {
912                 prepare_to_wait_exclusive(&sk->sk_lock.wq, &wait,
913                                         TASK_UNINTERRUPTIBLE);
914                 spin_unlock_bh(&sk->sk_lock.slock);
915                 schedule();
916                 spin_lock_bh(&sk->sk_lock.slock);
917                 if(!sock_owned_by_user(sk))
918                         break;
919         }
920         finish_wait(&sk->sk_lock.wq, &wait);
921 }
922
923 void __release_sock(struct sock *sk)
924 {
925         struct sk_buff *skb = sk->sk_backlog.head;
926
927         do {
928                 sk->sk_backlog.head = sk->sk_backlog.tail = NULL;
929                 bh_unlock_sock(sk);
930
931                 do {
932                         struct sk_buff *next = skb->next;
933
934                         skb->next = NULL;
935                         sk->sk_backlog_rcv(sk, skb);
936                         skb = next;
937                 } while (skb != NULL);
938
939                 bh_lock_sock(sk);
940         } while((skb = sk->sk_backlog.head) != NULL);
941 }
942
943 /**
944  * sk_wait_data - wait for data to arrive at sk_receive_queue
945  * sk - sock to wait on
946  * timeo - for how long
947  *
948  * Now socket state including sk->sk_err is changed only under lock,
949  * hence we may omit checks after joining wait queue.
950  * We check receive queue before schedule() only as optimization;
951  * it is very likely that release_sock() added new data.
952  */
953 int sk_wait_data(struct sock *sk, long *timeo)
954 {
955         int rc;
956         DEFINE_WAIT(wait);
957
958         prepare_to_wait(sk->sk_sleep, &wait, TASK_INTERRUPTIBLE);
959         set_bit(SOCK_ASYNC_WAITDATA, &sk->sk_socket->flags);
960         rc = sk_wait_event(sk, timeo, !skb_queue_empty(&sk->sk_receive_queue));
961         clear_bit(SOCK_ASYNC_WAITDATA, &sk->sk_socket->flags);
962         finish_wait(sk->sk_sleep, &wait);
963         return rc;
964 }
965
966 EXPORT_SYMBOL(sk_wait_data);
967
968 /*
969  * Set of default routines for initialising struct proto_ops when
970  * the protocol does not support a particular function. In certain
971  * cases where it makes no sense for a protocol to have a "do nothing"
972  * function, some default processing is provided.
973  */
974
975 int sock_no_release(struct socket *sock)
976 {
977         return 0;
978 }
979
980 int sock_no_bind(struct socket *sock, struct sockaddr *saddr, int len)
981 {
982         return -EOPNOTSUPP;
983 }
984
985 int sock_no_connect(struct socket *sock, struct sockaddr *saddr, 
986                     int len, int flags)
987 {
988         return -EOPNOTSUPP;
989 }
990
991 int sock_no_socketpair(struct socket *sock1, struct socket *sock2)
992 {
993         return -EOPNOTSUPP;
994 }
995
996 int sock_no_accept(struct socket *sock, struct socket *newsock, int flags)
997 {
998         return -EOPNOTSUPP;
999 }
1000
1001 int sock_no_getname(struct socket *sock, struct sockaddr *saddr, 
1002                     int *len, int peer)
1003 {
1004         return -EOPNOTSUPP;
1005 }
1006
1007 unsigned int sock_no_poll(struct file * file, struct socket *sock, poll_table *pt)
1008 {
1009         return 0;
1010 }
1011
1012 int sock_no_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1013 {
1014         return -EOPNOTSUPP;
1015 }
1016
1017 int sock_no_listen(struct socket *sock, int backlog)
1018 {
1019         return -EOPNOTSUPP;
1020 }
1021
1022 int sock_no_shutdown(struct socket *sock, int how)
1023 {
1024         return -EOPNOTSUPP;
1025 }
1026
1027 int sock_no_setsockopt(struct socket *sock, int level, int optname,
1028                     char __user *optval, int optlen)
1029 {
1030         return -EOPNOTSUPP;
1031 }
1032
1033 int sock_no_getsockopt(struct socket *sock, int level, int optname,
1034                     char __user *optval, int __user *optlen)
1035 {
1036         return -EOPNOTSUPP;
1037 }
1038
1039 int sock_no_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *m,
1040                     size_t len)
1041 {
1042         return -EOPNOTSUPP;
1043 }
1044
1045 int sock_no_recvmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *m,
1046                     size_t len, int flags)
1047 {
1048         return -EOPNOTSUPP;
1049 }
1050
1051 int sock_no_mmap(struct file *file, struct socket *sock, struct vm_area_struct *vma)
1052 {
1053         /* Mirror missing mmap method error code */
1054         return -ENODEV;
1055 }
1056
1057 ssize_t sock_no_sendpage(struct socket *sock, struct page *page, int offset, size_t size, int flags)
1058 {
1059         ssize_t res;
1060         struct msghdr msg = {.msg_flags = flags};
1061         struct kvec iov;
1062         char *kaddr = kmap(page);
1063         iov.iov_base = kaddr + offset;
1064         iov.iov_len = size;
1065         res = kernel_sendmsg(sock, &msg, &iov, 1, size);
1066         kunmap(page);
1067         return res;
1068 }
1069
1070 /*
1071  *      Default Socket Callbacks
1072  */
1073
1074 void sock_def_wakeup(struct sock *sk)
1075 {
1076         read_lock(&sk->sk_callback_lock);
1077         if (sk->sk_sleep && waitqueue_active(sk->sk_sleep))
1078                 wake_up_interruptible_all(sk->sk_sleep);
1079         read_unlock(&sk->sk_callback_lock);
1080 }
1081
1082 void sock_def_error_report(struct sock *sk)
1083 {
1084         read_lock(&sk->sk_callback_lock);
1085         if (sk->sk_sleep && waitqueue_active(sk->sk_sleep))
1086                 wake_up_interruptible(sk->sk_sleep);
1087         sk_wake_async(sk,0,POLL_ERR); 
1088         read_unlock(&sk->sk_callback_lock);
1089 }
1090
1091 void sock_def_readable(struct sock *sk, int len)
1092 {
1093         read_lock(&sk->sk_callback_lock);
1094         if (sk->sk_sleep && waitqueue_active(sk->sk_sleep))
1095                 wake_up_interruptible(sk->sk_sleep);
1096         sk_wake_async(sk,1,POLL_IN);
1097         read_unlock(&sk->sk_callback_lock);
1098 }
1099
1100 void sock_def_write_space(struct sock *sk)
1101 {
1102         read_lock(&sk->sk_callback_lock);
1103
1104         /* Do not wake up a writer until he can make "significant"
1105          * progress.  --DaveM
1106          */
1107         if((atomic_read(&sk->sk_wmem_alloc) << 1) <= sk->sk_sndbuf) {
1108                 if (sk->sk_sleep && waitqueue_active(sk->sk_sleep))
1109                         wake_up_interruptible(sk->sk_sleep);
1110
1111                 /* Should agree with poll, otherwise some programs break */
1112                 if (sock_writeable(sk))
1113                         sk_wake_async(sk, 2, POLL_OUT);
1114         }
1115
1116         read_unlock(&sk->sk_callback_lock);
1117 }
1118
1119 void sock_def_destruct(struct sock *sk)
1120 {
1121         if (sk->sk_protinfo)
1122                 kfree(sk->sk_protinfo);
1123 }
1124
1125 void sk_send_sigurg(struct sock *sk)
1126 {
1127         if (sk->sk_socket && sk->sk_socket->file)
1128                 if (send_sigurg(&sk->sk_socket->file->f_owner))
1129                         sk_wake_async(sk, 3, POLL_PRI);
1130 }
1131
1132 void sk_reset_timer(struct sock *sk, struct timer_list* timer,
1133                     unsigned long expires)
1134 {
1135         if (!mod_timer(timer, expires))
1136                 sock_hold(sk);
1137 }
1138
1139 EXPORT_SYMBOL(sk_reset_timer);
1140
1141 void sk_stop_timer(struct sock *sk, struct timer_list* timer)
1142 {
1143         if (timer_pending(timer) && del_timer(timer))
1144                 __sock_put(sk);
1145 }
1146
1147 EXPORT_SYMBOL(sk_stop_timer);
1148
1149 void sock_init_data(struct socket *sock, struct sock *sk)
1150 {
1151         skb_queue_head_init(&sk->sk_receive_queue);
1152         skb_queue_head_init(&sk->sk_write_queue);
1153         skb_queue_head_init(&sk->sk_error_queue);
1154
1155         sk->sk_send_head        =       NULL;
1156
1157         init_timer(&sk->sk_timer);
1158         
1159         sk->sk_allocation       =       GFP_KERNEL;
1160         sk->sk_rcvbuf           =       sysctl_rmem_default;
1161         sk->sk_sndbuf           =       sysctl_wmem_default;
1162         sk->sk_state            =       TCP_CLOSE;
1163         sk->sk_zapped           =       1;
1164         sk->sk_socket           =       sock;
1165
1166         if(sock)
1167         {
1168                 sk->sk_type     =       sock->type;
1169                 sk->sk_sleep    =       &sock->wait;
1170                 sock->sk        =       sk;
1171         } else
1172                 sk->sk_sleep    =       NULL;
1173
1174         sk->sk_dst_lock         =       RW_LOCK_UNLOCKED;
1175         sk->sk_callback_lock    =       RW_LOCK_UNLOCKED;
1176
1177         sk->sk_state_change     =       sock_def_wakeup;
1178         sk->sk_data_ready       =       sock_def_readable;
1179         sk->sk_write_space      =       sock_def_write_space;
1180         sk->sk_error_report     =       sock_def_error_report;
1181         sk->sk_destruct         =       sock_def_destruct;
1182
1183         sk->sk_sndmsg_page      =       NULL;
1184         sk->sk_sndmsg_off       =       0;
1185
1186         sk->sk_peercred.pid     =       0;
1187         sk->sk_peercred.uid     =       -1;
1188         sk->sk_peercred.gid     =       -1;
1189         sk->sk_write_pending    =       0;
1190         sk->sk_rcvlowat         =       1;
1191         sk->sk_rcvtimeo         =       MAX_SCHEDULE_TIMEOUT;
1192         sk->sk_sndtimeo         =       MAX_SCHEDULE_TIMEOUT;
1193         sk->sk_owner            =       NULL;
1194
1195         sk->sk_stamp.tv_sec     = -1L;
1196         sk->sk_stamp.tv_usec    = -1L;
1197
1198         atomic_set(&sk->sk_refcnt, 1);
1199 }
1200
1201 void fastcall lock_sock(struct sock *sk)
1202 {
1203         might_sleep();
1204         spin_lock_bh(&(sk->sk_lock.slock));
1205         if (sk->sk_lock.owner)
1206                 __lock_sock(sk);
1207         sk->sk_lock.owner = (void *)1;
1208         spin_unlock_bh(&(sk->sk_lock.slock));
1209 }
1210
1211 EXPORT_SYMBOL(lock_sock);
1212
1213 void fastcall release_sock(struct sock *sk)
1214 {
1215         spin_lock_bh(&(sk->sk_lock.slock));
1216         if (sk->sk_backlog.tail)
1217                 __release_sock(sk);
1218         sk->sk_lock.owner = NULL;
1219         if (waitqueue_active(&(sk->sk_lock.wq)))
1220                 wake_up(&(sk->sk_lock.wq));
1221         spin_unlock_bh(&(sk->sk_lock.slock));
1222 }
1223 EXPORT_SYMBOL(release_sock);
1224
1225 /* When > 0 there are consumers of rx skb time stamps */
1226 atomic_t netstamp_needed = ATOMIC_INIT(0); 
1227
1228 int sock_get_timestamp(struct sock *sk, struct timeval __user *userstamp)
1229
1230         if (!sock_flag(sk, SOCK_TIMESTAMP))
1231                 sock_enable_timestamp(sk);
1232         if (sk->sk_stamp.tv_sec == -1) 
1233                 return -ENOENT;
1234         if (sk->sk_stamp.tv_sec == 0)
1235                 do_gettimeofday(&sk->sk_stamp);
1236         return copy_to_user(userstamp, &sk->sk_stamp, sizeof(struct timeval)) ?
1237                 -EFAULT : 0; 
1238
1239 EXPORT_SYMBOL(sock_get_timestamp);
1240
1241 void sock_enable_timestamp(struct sock *sk)
1242 {       
1243         if (!sock_flag(sk, SOCK_TIMESTAMP)) { 
1244                 sock_set_flag(sk, SOCK_TIMESTAMP);
1245                 atomic_inc(&netstamp_needed);
1246         }
1247 }
1248 EXPORT_SYMBOL(sock_enable_timestamp); 
1249
1250 void sock_disable_timestamp(struct sock *sk)
1251 {       
1252         if (sock_flag(sk, SOCK_TIMESTAMP)) { 
1253                 sock_reset_flag(sk, SOCK_TIMESTAMP);
1254                 atomic_dec(&netstamp_needed);
1255         }
1256 }
1257 EXPORT_SYMBOL(sock_disable_timestamp);
1258
1259 /*
1260  *      Get a socket option on an socket.
1261  *
1262  *      FIX: POSIX 1003.1g is very ambiguous here. It states that
1263  *      asynchronous errors should be reported by getsockopt. We assume
1264  *      this means if you specify SO_ERROR (otherwise whats the point of it).
1265  */
1266 int sock_common_getsockopt(struct socket *sock, int level, int optname,
1267                            char __user *optval, int __user *optlen)
1268 {
1269         struct sock *sk = sock->sk;
1270
1271         return sk->sk_prot->getsockopt(sk, level, optname, optval, optlen);
1272 }
1273
1274 EXPORT_SYMBOL(sock_common_getsockopt);
1275
1276 int sock_common_recvmsg(struct kiocb *iocb, struct socket *sock,
1277                         struct msghdr *msg, size_t size, int flags)
1278 {
1279         struct sock *sk = sock->sk;
1280         int addr_len = 0;
1281         int err;
1282
1283         err = sk->sk_prot->recvmsg(iocb, sk, msg, size, flags & MSG_DONTWAIT,
1284                                    flags & ~MSG_DONTWAIT, &addr_len);
1285         if (err >= 0)
1286                 msg->msg_namelen = addr_len;
1287         return err;
1288 }
1289
1290 EXPORT_SYMBOL(sock_common_recvmsg);
1291
1292 /*
1293  *      Set socket options on an inet socket.
1294  */
1295 int sock_common_setsockopt(struct socket *sock, int level, int optname,
1296                            char __user *optval, int optlen)
1297 {
1298         struct sock *sk = sock->sk;
1299
1300         return sk->sk_prot->setsockopt(sk, level, optname, optval, optlen);
1301 }
1302
1303 EXPORT_SYMBOL(sock_common_setsockopt);
1304
1305 void sk_common_release(struct sock *sk)
1306 {
1307         if (sk->sk_prot->destroy)
1308                 sk->sk_prot->destroy(sk);
1309
1310         /*
1311          * Observation: when sock_common_release is called, processes have
1312          * no access to socket. But net still has.
1313          * Step one, detach it from networking:
1314          *
1315          * A. Remove from hash tables.
1316          */
1317
1318         sk->sk_prot->unhash(sk);
1319
1320         /*
1321          * In this point socket cannot receive new packets, but it is possible
1322          * that some packets are in flight because some CPU runs receiver and
1323          * did hash table lookup before we unhashed socket. They will achieve
1324          * receive queue and will be purged by socket destructor.
1325          *
1326          * Also we still have packets pending on receive queue and probably,
1327          * our own packets waiting in device queues. sock_destroy will drain
1328          * receive queue, but transmitted packets will delay socket destruction
1329          * until the last reference will be released.
1330          */
1331
1332         sock_orphan(sk);
1333
1334         xfrm_sk_free_policy(sk);
1335
1336 #ifdef INET_REFCNT_DEBUG
1337         if (atomic_read(&sk->sk_refcnt) != 1)
1338                 printk(KERN_DEBUG "Destruction of the socket %p delayed, c=%d\n",
1339                        sk, atomic_read(&sk->sk_refcnt));
1340 #endif
1341         sock_put(sk);
1342 }
1343
1344 EXPORT_SYMBOL(sk_common_release);
1345
1346 int sk_alloc_slab(struct proto *prot, char *name)
1347 {
1348         prot->slab = kmem_cache_create(name,
1349                                        prot->slab_obj_size, 0,
1350                                        SLAB_HWCACHE_ALIGN, NULL, NULL);
1351
1352         return prot->slab != NULL ? 0 : -ENOBUFS;
1353 }
1354
1355 EXPORT_SYMBOL(sk_alloc_slab);
1356
1357 void sk_free_slab(struct proto *prot)
1358 {
1359         if (prot->slab != NULL) {
1360                 kmem_cache_destroy(prot->slab);
1361                 prot->slab = NULL;
1362         }
1363 }
1364
1365 EXPORT_SYMBOL(sk_free_slab);
1366
1367 EXPORT_SYMBOL(__lock_sock);
1368 EXPORT_SYMBOL(__release_sock);
1369 EXPORT_SYMBOL(sk_alloc);
1370 EXPORT_SYMBOL(sk_free);
1371 EXPORT_SYMBOL(sk_send_sigurg);
1372 EXPORT_SYMBOL(sock_alloc_send_pskb);
1373 EXPORT_SYMBOL(sock_alloc_send_skb);
1374 EXPORT_SYMBOL(sock_getsockopt);
1375 EXPORT_SYMBOL(sock_init_data);
1376 EXPORT_SYMBOL(sock_kfree_s);
1377 EXPORT_SYMBOL(sock_kmalloc);
1378 EXPORT_SYMBOL(sock_no_accept);
1379 EXPORT_SYMBOL(sock_no_bind);
1380 EXPORT_SYMBOL(sock_no_connect);
1381 EXPORT_SYMBOL(sock_no_getname);
1382 EXPORT_SYMBOL(sock_no_getsockopt);
1383 EXPORT_SYMBOL(sock_no_ioctl);
1384 EXPORT_SYMBOL(sock_no_listen);
1385 EXPORT_SYMBOL(sock_no_mmap);
1386 EXPORT_SYMBOL(sock_no_poll);
1387 EXPORT_SYMBOL(sock_no_recvmsg);
1388 EXPORT_SYMBOL(sock_no_release);
1389 EXPORT_SYMBOL(sock_no_sendmsg);
1390 EXPORT_SYMBOL(sock_no_sendpage);
1391 EXPORT_SYMBOL(sock_no_setsockopt);
1392 EXPORT_SYMBOL(sock_no_shutdown);
1393 EXPORT_SYMBOL(sock_no_socketpair);
1394 EXPORT_SYMBOL(sock_rfree);
1395 EXPORT_SYMBOL(sock_rmalloc);
1396 EXPORT_SYMBOL(sock_setsockopt);
1397 EXPORT_SYMBOL(sock_wfree);
1398 EXPORT_SYMBOL(sock_wmalloc);
1399 EXPORT_SYMBOL(sock_i_uid);
1400 EXPORT_SYMBOL(sock_i_ino);
1401 #ifdef CONFIG_SYSCTL
1402 EXPORT_SYMBOL(sysctl_optmem_max);
1403 EXPORT_SYMBOL(sysctl_rmem_max);
1404 EXPORT_SYMBOL(sysctl_wmem_max);
1405 #endif