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.
6 * Generic socket support routines. Memory allocators, socket lock/release
7 * handler for protocols to use and generic option handler.
10 * Version: $Id: sock.c,v 1.117 2002/02/01 22:01:03 davem Exp $
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>
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
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
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
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.
94 #include <linux/capability.h>
95 #include <linux/config.h>
96 #include <linux/errno.h>
97 #include <linux/types.h>
98 #include <linux/socket.h>
100 #include <linux/kernel.h>
101 #include <linux/module.h>
102 #include <linux/proc_fs.h>
103 #include <linux/seq_file.h>
104 #include <linux/sched.h>
105 #include <linux/timer.h>
106 #include <linux/string.h>
107 #include <linux/sockios.h>
108 #include <linux/net.h>
109 #include <linux/mm.h>
110 #include <linux/slab.h>
111 #include <linux/interrupt.h>
112 #include <linux/poll.h>
113 #include <linux/tcp.h>
114 #include <linux/init.h>
116 #include <asm/uaccess.h>
117 #include <asm/system.h>
119 #include <linux/netdevice.h>
120 #include <net/protocol.h>
121 #include <linux/skbuff.h>
122 #include <net/request_sock.h>
123 #include <net/sock.h>
124 #include <net/xfrm.h>
125 #include <linux/ipsec.h>
127 #include <linux/filter.h>
128 #include <linux/vs_socket.h>
129 #include <linux/vs_limit.h>
130 #include <linux/vs_context.h>
136 /* Take into consideration the size of the struct sk_buff overhead in the
137 * determination of these values, since that is non-constant across
138 * platforms. This makes socket queueing behavior and performance
139 * not depend upon such differences.
141 #define _SK_MEM_PACKETS 256
142 #define _SK_MEM_OVERHEAD (sizeof(struct sk_buff) + 256)
143 #define SK_WMEM_MAX (_SK_MEM_OVERHEAD * _SK_MEM_PACKETS)
144 #define SK_RMEM_MAX (_SK_MEM_OVERHEAD * _SK_MEM_PACKETS)
146 /* Run time adjustable parameters. */
147 __u32 sysctl_wmem_max = SK_WMEM_MAX;
148 __u32 sysctl_rmem_max = SK_RMEM_MAX;
149 __u32 sysctl_wmem_default = SK_WMEM_MAX;
150 __u32 sysctl_rmem_default = SK_RMEM_MAX;
152 /* Maximal space eaten by iovec or ancilliary data plus some space */
153 int sysctl_optmem_max = sizeof(unsigned long)*(2*UIO_MAXIOV + 512);
155 static int sock_set_timeout(long *timeo_p, char __user *optval, int optlen)
159 if (optlen < sizeof(tv))
161 if (copy_from_user(&tv, optval, sizeof(tv)))
164 *timeo_p = MAX_SCHEDULE_TIMEOUT;
165 if (tv.tv_sec == 0 && tv.tv_usec == 0)
167 if (tv.tv_sec < (MAX_SCHEDULE_TIMEOUT/HZ - 1))
168 *timeo_p = tv.tv_sec*HZ + (tv.tv_usec+(1000000/HZ-1))/(1000000/HZ);
172 static void sock_warn_obsolete_bsdism(const char *name)
175 static char warncomm[TASK_COMM_LEN];
176 if (strcmp(warncomm, current->comm) && warned < 5) {
177 strcpy(warncomm, current->comm);
178 printk(KERN_WARNING "process `%s' is using obsolete "
179 "%s SO_BSDCOMPAT\n", warncomm, name);
184 static void sock_disable_timestamp(struct sock *sk)
186 if (sock_flag(sk, SOCK_TIMESTAMP)) {
187 sock_reset_flag(sk, SOCK_TIMESTAMP);
188 net_disable_timestamp();
193 int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
198 #if defined(CONFIG_VNET) || defined(CONFIG_VNET_MODULE)
199 /* Silently drop if VNET is active (if INET bind() has been
200 * overridden) and the context is not entitled to read the
204 (int) sk->sk_xid > 0 && sk->sk_xid != skb->xid) {
210 /* Cast skb->rcvbuf to unsigned... It's pointless, but reduces
211 number of warnings when compiling with -W --ANK
213 if (atomic_read(&sk->sk_rmem_alloc) + skb->truesize >=
214 (unsigned)sk->sk_rcvbuf) {
219 /* It would be deadlock, if sock_queue_rcv_skb is used
220 with socket lock! We assume that users of this
221 function are lock free.
223 err = sk_filter(sk, skb, 1);
228 skb_set_owner_r(skb, sk);
230 /* Cache the SKB length before we tack it onto the receive
231 * queue. Once it is added it no longer belongs to us and
232 * may be freed by other threads of control pulling packets
237 skb_queue_tail(&sk->sk_receive_queue, skb);
239 if (!sock_flag(sk, SOCK_DEAD))
240 sk->sk_data_ready(sk, skb_len);
244 EXPORT_SYMBOL(sock_queue_rcv_skb);
246 int sk_receive_skb(struct sock *sk, struct sk_buff *skb)
248 int rc = NET_RX_SUCCESS;
250 if (sk_filter(sk, skb, 0))
251 goto discard_and_relse;
256 if (!sock_owned_by_user(sk))
257 rc = sk->sk_backlog_rcv(sk, skb);
259 sk_add_backlog(sk, skb);
268 EXPORT_SYMBOL(sk_receive_skb);
270 struct dst_entry *__sk_dst_check(struct sock *sk, u32 cookie)
272 struct dst_entry *dst = sk->sk_dst_cache;
274 if (dst && dst->obsolete && dst->ops->check(dst, cookie) == NULL) {
275 sk->sk_dst_cache = NULL;
282 EXPORT_SYMBOL(__sk_dst_check);
284 struct dst_entry *sk_dst_check(struct sock *sk, u32 cookie)
286 struct dst_entry *dst = sk_dst_get(sk);
288 if (dst && dst->obsolete && dst->ops->check(dst, cookie) == NULL) {
296 EXPORT_SYMBOL(sk_dst_check);
299 * This is meant for all protocols to use and covers goings on
300 * at the socket level. Everything here is generic.
303 int sock_setsockopt(struct socket *sock, int level, int optname,
304 char __user *optval, int optlen)
306 struct sock *sk=sock->sk;
307 struct sk_filter *filter;
314 * Options without arguments
317 #ifdef SO_DONTLINGER /* Compatibility item... */
318 if (optname == SO_DONTLINGER) {
320 sock_reset_flag(sk, SOCK_LINGER);
326 if(optlen<sizeof(int))
329 if (get_user(val, (int __user *)optval))
339 if(val && !capable(CAP_NET_ADMIN))
344 sock_set_flag(sk, SOCK_DBG);
346 sock_reset_flag(sk, SOCK_DBG);
349 sk->sk_reuse = valbool;
357 sock_set_flag(sk, SOCK_LOCALROUTE);
359 sock_reset_flag(sk, SOCK_LOCALROUTE);
362 sock_valbool_flag(sk, SOCK_BROADCAST, valbool);
365 /* Don't error on this BSD doesn't and if you think
366 about it this is right. Otherwise apps have to
367 play 'guess the biggest size' games. RCVBUF/SNDBUF
368 are treated in BSD as hints */
370 if (val > sysctl_wmem_max)
371 val = sysctl_wmem_max;
373 sk->sk_userlocks |= SOCK_SNDBUF_LOCK;
374 if ((val * 2) < SOCK_MIN_SNDBUF)
375 sk->sk_sndbuf = SOCK_MIN_SNDBUF;
377 sk->sk_sndbuf = val * 2;
380 * Wake up sending tasks if we
383 sk->sk_write_space(sk);
387 if (!capable(CAP_NET_ADMIN)) {
394 /* Don't error on this BSD doesn't and if you think
395 about it this is right. Otherwise apps have to
396 play 'guess the biggest size' games. RCVBUF/SNDBUF
397 are treated in BSD as hints */
399 if (val > sysctl_rmem_max)
400 val = sysctl_rmem_max;
402 sk->sk_userlocks |= SOCK_RCVBUF_LOCK;
404 * We double it on the way in to account for
405 * "struct sk_buff" etc. overhead. Applications
406 * assume that the SO_RCVBUF setting they make will
407 * allow that much actual data to be received on that
410 * Applications are unaware that "struct sk_buff" and
411 * other overheads allocate from the receive buffer
412 * during socket buffer allocation.
414 * And after considering the possible alternatives,
415 * returning the value we actually used in getsockopt
416 * is the most desirable behavior.
418 if ((val * 2) < SOCK_MIN_RCVBUF)
419 sk->sk_rcvbuf = SOCK_MIN_RCVBUF;
421 sk->sk_rcvbuf = val * 2;
425 if (!capable(CAP_NET_ADMIN)) {
433 if (sk->sk_protocol == IPPROTO_TCP)
434 tcp_set_keepalive(sk, valbool);
436 sock_valbool_flag(sk, SOCK_KEEPOPEN, valbool);
440 sock_valbool_flag(sk, SOCK_URGINLINE, valbool);
444 sk->sk_no_check = valbool;
448 if ((val >= 0 && val <= 6) || capable(CAP_NET_ADMIN))
449 sk->sk_priority = val;
455 if(optlen<sizeof(ling)) {
456 ret = -EINVAL; /* 1003.1g */
459 if (copy_from_user(&ling,optval,sizeof(ling))) {
464 sock_reset_flag(sk, SOCK_LINGER);
466 #if (BITS_PER_LONG == 32)
467 if ((unsigned int)ling.l_linger >= MAX_SCHEDULE_TIMEOUT/HZ)
468 sk->sk_lingertime = MAX_SCHEDULE_TIMEOUT;
471 sk->sk_lingertime = (unsigned int)ling.l_linger * HZ;
472 sock_set_flag(sk, SOCK_LINGER);
477 sock_warn_obsolete_bsdism("setsockopt");
482 set_bit(SOCK_PASSCRED, &sock->flags);
484 clear_bit(SOCK_PASSCRED, &sock->flags);
487 #if defined(CONFIG_VNET) || defined(CONFIG_VNET_MODULE)
493 if (val < 0 || val > MAX_S_CONTEXT) {
503 sock_set_flag(sk, SOCK_RCVTSTAMP);
504 sock_enable_timestamp(sk);
506 sock_reset_flag(sk, SOCK_RCVTSTAMP);
512 sk->sk_rcvlowat = val ? : 1;
516 ret = sock_set_timeout(&sk->sk_rcvtimeo, optval, optlen);
520 ret = sock_set_timeout(&sk->sk_sndtimeo, optval, optlen);
523 #ifdef CONFIG_NETDEVICES
524 case SO_BINDTODEVICE:
526 char devname[IFNAMSIZ];
529 if (!capable(CAP_NET_RAW)) {
534 /* Bind this socket to a particular device like "eth0",
535 * as specified in the passed interface name. If the
536 * name is "" or the option length is zero the socket
541 sk->sk_bound_dev_if = 0;
543 if (optlen > IFNAMSIZ - 1)
544 optlen = IFNAMSIZ - 1;
545 memset(devname, 0, sizeof(devname));
546 if (copy_from_user(devname, optval, optlen)) {
551 /* Remove any cached route for this socket. */
554 if (devname[0] == '\0') {
555 sk->sk_bound_dev_if = 0;
557 struct net_device *dev = dev_get_by_name(devname);
562 sk->sk_bound_dev_if = dev->ifindex;
571 case SO_ATTACH_FILTER:
573 if (optlen == sizeof(struct sock_fprog)) {
574 struct sock_fprog fprog;
577 if (copy_from_user(&fprog, optval, sizeof(fprog)))
580 ret = sk_attach_filter(&fprog, sk);
584 case SO_DETACH_FILTER:
585 spin_lock_bh(&sk->sk_lock.slock);
586 filter = sk->sk_filter;
588 sk->sk_filter = NULL;
589 spin_unlock_bh(&sk->sk_lock.slock);
590 sk_filter_release(sk, filter);
593 spin_unlock_bh(&sk->sk_lock.slock);
597 /* We implement the SO_SNDLOWAT etc to
598 not be settable (1003.1g 5.3) */
608 int sock_getsockopt(struct socket *sock, int level, int optname,
609 char __user *optval, int __user *optlen)
611 struct sock *sk = sock->sk;
620 unsigned int lv = sizeof(int);
623 if(get_user(len,optlen))
631 v.val = sock_flag(sk, SOCK_DBG);
635 v.val = sock_flag(sk, SOCK_LOCALROUTE);
639 v.val = !!sock_flag(sk, SOCK_BROADCAST);
643 v.val = sk->sk_sndbuf;
647 v.val = sk->sk_rcvbuf;
651 v.val = sk->sk_reuse;
655 v.val = !!sock_flag(sk, SOCK_KEEPOPEN);
663 v.val = -sock_error(sk);
665 v.val = xchg(&sk->sk_err_soft, 0);
669 v.val = !!sock_flag(sk, SOCK_URGINLINE);
673 v.val = sk->sk_no_check;
677 v.val = sk->sk_priority;
682 v.ling.l_onoff = !!sock_flag(sk, SOCK_LINGER);
683 v.ling.l_linger = sk->sk_lingertime / HZ;
687 sock_warn_obsolete_bsdism("getsockopt");
691 v.val = sock_flag(sk, SOCK_RCVTSTAMP);
695 lv=sizeof(struct timeval);
696 if (sk->sk_rcvtimeo == MAX_SCHEDULE_TIMEOUT) {
700 v.tm.tv_sec = sk->sk_rcvtimeo / HZ;
701 v.tm.tv_usec = ((sk->sk_rcvtimeo % HZ) * 1000000) / HZ;
706 lv=sizeof(struct timeval);
707 if (sk->sk_sndtimeo == MAX_SCHEDULE_TIMEOUT) {
711 v.tm.tv_sec = sk->sk_sndtimeo / HZ;
712 v.tm.tv_usec = ((sk->sk_sndtimeo % HZ) * 1000000) / HZ;
717 v.val = sk->sk_rcvlowat;
725 v.val = test_bit(SOCK_PASSCRED, &sock->flags) ? 1 : 0;
729 if (len > sizeof(sk->sk_peercred))
730 len = sizeof(sk->sk_peercred);
731 if (copy_to_user(optval, &sk->sk_peercred, len))
739 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
743 if (copy_to_user(optval, address, len))
748 /* Dubious BSD thing... Probably nobody even uses it, but
749 * the UNIX standard wants it for whatever reason... -DaveM
752 v.val = sk->sk_state == TCP_LISTEN;
756 return security_socket_getpeersec_stream(sock, optval, optlen, len);
759 return(-ENOPROTOOPT);
763 if (copy_to_user(optval, &v, len))
766 if (put_user(len, optlen))
772 * sk_alloc - All socket objects are allocated here
773 * @family: protocol family
774 * @priority: for allocation (%GFP_KERNEL, %GFP_ATOMIC, etc)
775 * @prot: struct proto associated with this new sock instance
776 * @zero_it: if we should zero the newly allocated sock
778 struct sock *sk_alloc(int family, gfp_t priority,
779 struct proto *prot, int zero_it)
781 struct sock *sk = NULL;
782 kmem_cache_t *slab = prot->slab;
785 sk = kmem_cache_alloc(slab, priority);
787 sk = kmalloc(prot->obj_size, priority);
791 memset(sk, 0, prot->obj_size);
792 sk->sk_family = family;
794 * See comment in struct sock definition to understand
795 * why we need sk_prot_creator -acme
797 sk->sk_prot = sk->sk_prot_creator = prot;
803 if (security_sk_alloc(sk, family, priority))
806 if (!try_module_get(prot->owner))
813 kmem_cache_free(slab, sk);
819 void sk_free(struct sock *sk)
821 struct sk_filter *filter;
822 struct module *owner = sk->sk_prot_creator->owner;
827 filter = sk->sk_filter;
829 sk_filter_release(sk, filter);
830 sk->sk_filter = NULL;
833 sock_disable_timestamp(sk);
835 if (atomic_read(&sk->sk_omem_alloc))
836 printk(KERN_DEBUG "%s: optmem leakage (%d bytes) detected.\n",
837 __FUNCTION__, atomic_read(&sk->sk_omem_alloc));
839 security_sk_free(sk);
841 clr_vx_info(&sk->sk_vx_info);
843 clr_nx_info(&sk->sk_nx_info);
845 if (sk->sk_prot_creator->slab != NULL)
846 kmem_cache_free(sk->sk_prot_creator->slab, sk);
852 struct sock *sk_clone(struct sock *sk, const gfp_t priority)
854 struct sock *newsk = sk_alloc(sk->sk_family, priority, sk->sk_prot, 0);
857 struct sk_filter *filter;
859 memcpy(newsk, sk, sk->sk_prot->obj_size);
864 sk_node_init(&newsk->sk_node);
865 sock_lock_init(newsk);
868 atomic_set(&newsk->sk_rmem_alloc, 0);
869 atomic_set(&newsk->sk_wmem_alloc, 0);
870 atomic_set(&newsk->sk_omem_alloc, 0);
871 skb_queue_head_init(&newsk->sk_receive_queue);
872 skb_queue_head_init(&newsk->sk_write_queue);
874 rwlock_init(&newsk->sk_dst_lock);
875 rwlock_init(&newsk->sk_callback_lock);
877 newsk->sk_dst_cache = NULL;
878 newsk->sk_wmem_queued = 0;
879 newsk->sk_forward_alloc = 0;
880 newsk->sk_send_head = NULL;
881 newsk->sk_backlog.head = newsk->sk_backlog.tail = NULL;
882 newsk->sk_userlocks = sk->sk_userlocks & ~SOCK_BINDPORT_LOCK;
884 sock_reset_flag(newsk, SOCK_DONE);
885 skb_queue_head_init(&newsk->sk_error_queue);
887 filter = newsk->sk_filter;
889 sk_filter_charge(newsk, filter);
891 if (sk->sk_create_child)
892 sk->sk_create_child(sk, newsk);
894 if (unlikely(xfrm_sk_clone_policy(newsk))) {
895 /* It is still raw copy of parent, so invalidate
896 * destructor and make plain sk_free() */
897 newsk->sk_destruct = NULL;
904 newsk->sk_priority = 0;
905 atomic_set(&newsk->sk_refcnt, 2);
907 set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
908 newsk->sk_xid = sk->sk_xid;
910 set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
911 newsk->sk_nid = sk->sk_nid;
914 * Increment the counter in the same struct proto as the master
915 * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
916 * is the same as sk->sk_prot->socks, as this field was copied
919 * This _changes_ the previous behaviour, where
920 * tcp_create_openreq_child always was incrementing the
921 * equivalent to tcp_prot->socks (inet_sock_nr), so this have
922 * to be taken into account in all callers. -acme
924 sk_refcnt_debug_inc(newsk);
925 newsk->sk_socket = NULL;
926 newsk->sk_sleep = NULL;
928 if (newsk->sk_prot->sockets_allocated)
929 atomic_inc(newsk->sk_prot->sockets_allocated);
935 EXPORT_SYMBOL_GPL(sk_clone);
937 void __init sk_init(void)
939 if (num_physpages <= 4096) {
940 sysctl_wmem_max = 32767;
941 sysctl_rmem_max = 32767;
942 sysctl_wmem_default = 32767;
943 sysctl_rmem_default = 32767;
944 } else if (num_physpages >= 131072) {
945 sysctl_wmem_max = 131071;
946 sysctl_rmem_max = 131071;
951 * Simple resource managers for sockets.
956 * Write buffer destructor automatically called from kfree_skb.
958 void sock_wfree(struct sk_buff *skb)
960 struct sock *sk = skb->sk;
962 /* In case it might be waiting for more memory. */
963 atomic_sub(skb->truesize, &sk->sk_wmem_alloc);
964 if (!sock_flag(sk, SOCK_USE_WRITE_QUEUE))
965 sk->sk_write_space(sk);
970 * Read buffer destructor automatically called from kfree_skb.
972 void sock_rfree(struct sk_buff *skb)
974 struct sock *sk = skb->sk;
976 atomic_sub(skb->truesize, &sk->sk_rmem_alloc);
980 int sock_i_uid(struct sock *sk)
984 read_lock(&sk->sk_callback_lock);
985 uid = sk->sk_socket ? SOCK_INODE(sk->sk_socket)->i_uid : 0;
986 read_unlock(&sk->sk_callback_lock);
990 unsigned long sock_i_ino(struct sock *sk)
994 read_lock(&sk->sk_callback_lock);
995 ino = sk->sk_socket ? SOCK_INODE(sk->sk_socket)->i_ino : 0;
996 read_unlock(&sk->sk_callback_lock);
1001 * Allocate a skb from the socket's send buffer.
1003 struct sk_buff *sock_wmalloc(struct sock *sk, unsigned long size, int force,
1006 if (force || atomic_read(&sk->sk_wmem_alloc) < sk->sk_sndbuf) {
1007 struct sk_buff * skb = alloc_skb(size, priority);
1009 skb_set_owner_w(skb, sk);
1017 * Allocate a skb from the socket's receive buffer.
1019 struct sk_buff *sock_rmalloc(struct sock *sk, unsigned long size, int force,
1022 if (force || atomic_read(&sk->sk_rmem_alloc) < sk->sk_rcvbuf) {
1023 struct sk_buff *skb = alloc_skb(size, priority);
1025 skb_set_owner_r(skb, sk);
1033 * Allocate a memory block from the socket's option memory buffer.
1035 void *sock_kmalloc(struct sock *sk, int size, gfp_t priority)
1037 if ((unsigned)size <= sysctl_optmem_max &&
1038 atomic_read(&sk->sk_omem_alloc) + size < sysctl_optmem_max) {
1040 /* First do the add, to avoid the race if kmalloc
1043 atomic_add(size, &sk->sk_omem_alloc);
1044 mem = kmalloc(size, priority);
1047 atomic_sub(size, &sk->sk_omem_alloc);
1053 * Free an option memory block.
1055 void sock_kfree_s(struct sock *sk, void *mem, int size)
1058 atomic_sub(size, &sk->sk_omem_alloc);
1061 /* It is almost wait_for_tcp_memory minus release_sock/lock_sock.
1062 I think, these locks should be removed for datagram sockets.
1064 static long sock_wait_for_wmem(struct sock * sk, long timeo)
1068 clear_bit(SOCK_ASYNC_NOSPACE, &sk->sk_socket->flags);
1072 if (signal_pending(current))
1074 set_bit(SOCK_NOSPACE, &sk->sk_socket->flags);
1075 prepare_to_wait(sk->sk_sleep, &wait, TASK_INTERRUPTIBLE);
1076 if (atomic_read(&sk->sk_wmem_alloc) < sk->sk_sndbuf)
1078 if (sk->sk_shutdown & SEND_SHUTDOWN)
1082 timeo = schedule_timeout(timeo);
1084 finish_wait(sk->sk_sleep, &wait);
1090 * Generic send/receive buffer handlers
1093 static struct sk_buff *sock_alloc_send_pskb(struct sock *sk,
1094 unsigned long header_len,
1095 unsigned long data_len,
1096 int noblock, int *errcode)
1098 struct sk_buff *skb;
1103 gfp_mask = sk->sk_allocation;
1104 if (gfp_mask & __GFP_WAIT)
1105 gfp_mask |= __GFP_REPEAT;
1107 timeo = sock_sndtimeo(sk, noblock);
1109 err = sock_error(sk);
1114 if (sk->sk_shutdown & SEND_SHUTDOWN)
1117 if (atomic_read(&sk->sk_wmem_alloc) < sk->sk_sndbuf) {
1118 skb = alloc_skb(header_len, sk->sk_allocation);
1123 /* No pages, we're done... */
1127 npages = (data_len + (PAGE_SIZE - 1)) >> PAGE_SHIFT;
1128 skb->truesize += data_len;
1129 skb_shinfo(skb)->nr_frags = npages;
1130 for (i = 0; i < npages; i++) {
1134 page = alloc_pages(sk->sk_allocation, 0);
1137 skb_shinfo(skb)->nr_frags = i;
1142 frag = &skb_shinfo(skb)->frags[i];
1144 frag->page_offset = 0;
1145 frag->size = (data_len >= PAGE_SIZE ?
1148 data_len -= PAGE_SIZE;
1151 /* Full success... */
1157 set_bit(SOCK_ASYNC_NOSPACE, &sk->sk_socket->flags);
1158 set_bit(SOCK_NOSPACE, &sk->sk_socket->flags);
1162 if (signal_pending(current))
1164 timeo = sock_wait_for_wmem(sk, timeo);
1167 skb_set_owner_w(skb, sk);
1171 err = sock_intr_errno(timeo);
1177 struct sk_buff *sock_alloc_send_skb(struct sock *sk, unsigned long size,
1178 int noblock, int *errcode)
1180 return sock_alloc_send_pskb(sk, size, 0, noblock, errcode);
1183 static void __lock_sock(struct sock *sk)
1188 prepare_to_wait_exclusive(&sk->sk_lock.wq, &wait,
1189 TASK_UNINTERRUPTIBLE);
1190 spin_unlock_bh(&sk->sk_lock.slock);
1192 spin_lock_bh(&sk->sk_lock.slock);
1193 if(!sock_owned_by_user(sk))
1196 finish_wait(&sk->sk_lock.wq, &wait);
1199 static void __release_sock(struct sock *sk)
1201 struct sk_buff *skb = sk->sk_backlog.head;
1204 sk->sk_backlog.head = sk->sk_backlog.tail = NULL;
1208 struct sk_buff *next = skb->next;
1211 sk->sk_backlog_rcv(sk, skb);
1214 * We are in process context here with softirqs
1215 * disabled, use cond_resched_softirq() to preempt.
1216 * This is safe to do because we've taken the backlog
1219 cond_resched_softirq();
1222 } while (skb != NULL);
1225 } while((skb = sk->sk_backlog.head) != NULL);
1229 * sk_wait_data - wait for data to arrive at sk_receive_queue
1230 * @sk: sock to wait on
1231 * @timeo: for how long
1233 * Now socket state including sk->sk_err is changed only under lock,
1234 * hence we may omit checks after joining wait queue.
1235 * We check receive queue before schedule() only as optimization;
1236 * it is very likely that release_sock() added new data.
1238 int sk_wait_data(struct sock *sk, long *timeo)
1243 prepare_to_wait(sk->sk_sleep, &wait, TASK_INTERRUPTIBLE);
1244 set_bit(SOCK_ASYNC_WAITDATA, &sk->sk_socket->flags);
1245 rc = sk_wait_event(sk, timeo, !skb_queue_empty(&sk->sk_receive_queue));
1246 clear_bit(SOCK_ASYNC_WAITDATA, &sk->sk_socket->flags);
1247 finish_wait(sk->sk_sleep, &wait);
1251 EXPORT_SYMBOL(sk_wait_data);
1254 * Set of default routines for initialising struct proto_ops when
1255 * the protocol does not support a particular function. In certain
1256 * cases where it makes no sense for a protocol to have a "do nothing"
1257 * function, some default processing is provided.
1260 int sock_no_bind(struct socket *sock, struct sockaddr *saddr, int len)
1265 int sock_no_connect(struct socket *sock, struct sockaddr *saddr,
1271 int sock_no_socketpair(struct socket *sock1, struct socket *sock2)
1276 int sock_no_accept(struct socket *sock, struct socket *newsock, int flags)
1281 int sock_no_getname(struct socket *sock, struct sockaddr *saddr,
1287 unsigned int sock_no_poll(struct file * file, struct socket *sock, poll_table *pt)
1292 int sock_no_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1297 int sock_no_listen(struct socket *sock, int backlog)
1302 int sock_no_shutdown(struct socket *sock, int how)
1307 int sock_no_setsockopt(struct socket *sock, int level, int optname,
1308 char __user *optval, int optlen)
1313 int sock_no_getsockopt(struct socket *sock, int level, int optname,
1314 char __user *optval, int __user *optlen)
1319 int sock_no_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *m,
1325 int sock_no_recvmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *m,
1326 size_t len, int flags)
1331 int sock_no_mmap(struct file *file, struct socket *sock, struct vm_area_struct *vma)
1333 /* Mirror missing mmap method error code */
1337 ssize_t sock_no_sendpage(struct socket *sock, struct page *page, int offset, size_t size, int flags)
1340 struct msghdr msg = {.msg_flags = flags};
1342 char *kaddr = kmap(page);
1343 iov.iov_base = kaddr + offset;
1345 res = kernel_sendmsg(sock, &msg, &iov, 1, size);
1351 * Default Socket Callbacks
1354 static void sock_def_wakeup(struct sock *sk)
1356 read_lock(&sk->sk_callback_lock);
1357 if (sk->sk_sleep && waitqueue_active(sk->sk_sleep))
1358 wake_up_interruptible_all(sk->sk_sleep);
1359 read_unlock(&sk->sk_callback_lock);
1362 static void sock_def_error_report(struct sock *sk)
1364 read_lock(&sk->sk_callback_lock);
1365 if (sk->sk_sleep && waitqueue_active(sk->sk_sleep))
1366 wake_up_interruptible(sk->sk_sleep);
1367 sk_wake_async(sk,0,POLL_ERR);
1368 read_unlock(&sk->sk_callback_lock);
1371 static void sock_def_readable(struct sock *sk, int len)
1373 read_lock(&sk->sk_callback_lock);
1374 if (sk->sk_sleep && waitqueue_active(sk->sk_sleep))
1375 wake_up_interruptible(sk->sk_sleep);
1376 sk_wake_async(sk,1,POLL_IN);
1377 read_unlock(&sk->sk_callback_lock);
1380 static void sock_def_write_space(struct sock *sk)
1382 read_lock(&sk->sk_callback_lock);
1384 /* Do not wake up a writer until he can make "significant"
1387 if((atomic_read(&sk->sk_wmem_alloc) << 1) <= sk->sk_sndbuf) {
1388 if (sk->sk_sleep && waitqueue_active(sk->sk_sleep))
1389 wake_up_interruptible(sk->sk_sleep);
1391 /* Should agree with poll, otherwise some programs break */
1392 if (sock_writeable(sk))
1393 sk_wake_async(sk, 2, POLL_OUT);
1396 read_unlock(&sk->sk_callback_lock);
1399 static void sock_def_destruct(struct sock *sk)
1401 kfree(sk->sk_protinfo);
1404 void sk_send_sigurg(struct sock *sk)
1406 if (sk->sk_socket && sk->sk_socket->file)
1407 if (send_sigurg(&sk->sk_socket->file->f_owner))
1408 sk_wake_async(sk, 3, POLL_PRI);
1411 void sk_reset_timer(struct sock *sk, struct timer_list* timer,
1412 unsigned long expires)
1414 if (!mod_timer(timer, expires))
1418 EXPORT_SYMBOL(sk_reset_timer);
1420 void sk_stop_timer(struct sock *sk, struct timer_list* timer)
1422 if (timer_pending(timer) && del_timer(timer))
1426 EXPORT_SYMBOL(sk_stop_timer);
1428 void sock_init_data(struct socket *sock, struct sock *sk)
1430 skb_queue_head_init(&sk->sk_receive_queue);
1431 skb_queue_head_init(&sk->sk_write_queue);
1432 skb_queue_head_init(&sk->sk_error_queue);
1434 sk->sk_send_head = NULL;
1436 init_timer(&sk->sk_timer);
1438 sk->sk_allocation = GFP_KERNEL;
1439 sk->sk_rcvbuf = sysctl_rmem_default;
1440 sk->sk_sndbuf = sysctl_wmem_default;
1441 sk->sk_state = TCP_CLOSE;
1442 sk->sk_socket = sock;
1444 sock_set_flag(sk, SOCK_ZAPPED);
1448 sk->sk_type = sock->type;
1449 sk->sk_sleep = &sock->wait;
1452 sk->sk_sleep = NULL;
1454 rwlock_init(&sk->sk_dst_lock);
1455 rwlock_init(&sk->sk_callback_lock);
1457 sk->sk_state_change = sock_def_wakeup;
1458 sk->sk_data_ready = sock_def_readable;
1459 sk->sk_write_space = sock_def_write_space;
1460 sk->sk_error_report = sock_def_error_report;
1461 sk->sk_destruct = sock_def_destruct;
1463 sk->sk_sndmsg_page = NULL;
1464 sk->sk_sndmsg_off = 0;
1466 sk->sk_peercred.pid = 0;
1467 sk->sk_peercred.uid = -1;
1468 sk->sk_peercred.gid = -1;
1469 sk->sk_write_pending = 0;
1470 sk->sk_rcvlowat = 1;
1471 sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
1472 sk->sk_sndtimeo = MAX_SCHEDULE_TIMEOUT;
1474 sk->sk_stamp.tv_sec = -1L;
1475 sk->sk_stamp.tv_usec = -1L;
1477 set_vx_info(&sk->sk_vx_info, current->vx_info);
1478 sk->sk_xid = vx_current_xid();
1480 set_nx_info(&sk->sk_nx_info, current->nx_info);
1481 sk->sk_nid = nx_current_nid();
1482 atomic_set(&sk->sk_refcnt, 1);
1485 void fastcall lock_sock(struct sock *sk)
1488 spin_lock_bh(&(sk->sk_lock.slock));
1489 if (sk->sk_lock.owner)
1491 sk->sk_lock.owner = (void *)1;
1492 spin_unlock_bh(&(sk->sk_lock.slock));
1495 EXPORT_SYMBOL(lock_sock);
1497 void fastcall release_sock(struct sock *sk)
1499 spin_lock_bh(&(sk->sk_lock.slock));
1500 if (sk->sk_backlog.tail)
1502 sk->sk_lock.owner = NULL;
1503 if (waitqueue_active(&(sk->sk_lock.wq)))
1504 wake_up(&(sk->sk_lock.wq));
1505 spin_unlock_bh(&(sk->sk_lock.slock));
1507 EXPORT_SYMBOL(release_sock);
1509 int sock_get_timestamp(struct sock *sk, struct timeval __user *userstamp)
1511 if (!sock_flag(sk, SOCK_TIMESTAMP))
1512 sock_enable_timestamp(sk);
1513 if (sk->sk_stamp.tv_sec == -1)
1515 if (sk->sk_stamp.tv_sec == 0)
1516 do_gettimeofday(&sk->sk_stamp);
1517 return copy_to_user(userstamp, &sk->sk_stamp, sizeof(struct timeval)) ?
1520 EXPORT_SYMBOL(sock_get_timestamp);
1522 void sock_enable_timestamp(struct sock *sk)
1524 if (!sock_flag(sk, SOCK_TIMESTAMP)) {
1525 sock_set_flag(sk, SOCK_TIMESTAMP);
1526 net_enable_timestamp();
1529 EXPORT_SYMBOL(sock_enable_timestamp);
1532 * Get a socket option on an socket.
1534 * FIX: POSIX 1003.1g is very ambiguous here. It states that
1535 * asynchronous errors should be reported by getsockopt. We assume
1536 * this means if you specify SO_ERROR (otherwise whats the point of it).
1538 int sock_common_getsockopt(struct socket *sock, int level, int optname,
1539 char __user *optval, int __user *optlen)
1541 struct sock *sk = sock->sk;
1543 return sk->sk_prot->getsockopt(sk, level, optname, optval, optlen);
1546 EXPORT_SYMBOL(sock_common_getsockopt);
1548 #ifdef CONFIG_COMPAT
1549 int compat_sock_common_getsockopt(struct socket *sock, int level, int optname,
1550 char __user *optval, int __user *optlen)
1552 struct sock *sk = sock->sk;
1554 if (sk->sk_prot->compat_setsockopt != NULL)
1555 return sk->sk_prot->compat_getsockopt(sk, level, optname,
1557 return sk->sk_prot->getsockopt(sk, level, optname, optval, optlen);
1559 EXPORT_SYMBOL(compat_sock_common_getsockopt);
1562 int sock_common_recvmsg(struct kiocb *iocb, struct socket *sock,
1563 struct msghdr *msg, size_t size, int flags)
1565 struct sock *sk = sock->sk;
1569 err = sk->sk_prot->recvmsg(iocb, sk, msg, size, flags & MSG_DONTWAIT,
1570 flags & ~MSG_DONTWAIT, &addr_len);
1572 msg->msg_namelen = addr_len;
1576 EXPORT_SYMBOL(sock_common_recvmsg);
1579 * Set socket options on an inet socket.
1581 int sock_common_setsockopt(struct socket *sock, int level, int optname,
1582 char __user *optval, int optlen)
1584 struct sock *sk = sock->sk;
1586 return sk->sk_prot->setsockopt(sk, level, optname, optval, optlen);
1589 EXPORT_SYMBOL(sock_common_setsockopt);
1591 #ifdef CONFIG_COMPAT
1592 int compat_sock_common_setsockopt(struct socket *sock, int level, int optname,
1593 char __user *optval, int optlen)
1595 struct sock *sk = sock->sk;
1597 if (sk->sk_prot->compat_setsockopt != NULL)
1598 return sk->sk_prot->compat_setsockopt(sk, level, optname,
1600 return sk->sk_prot->setsockopt(sk, level, optname, optval, optlen);
1602 EXPORT_SYMBOL(compat_sock_common_setsockopt);
1605 void sk_common_release(struct sock *sk)
1607 if (sk->sk_prot->destroy)
1608 sk->sk_prot->destroy(sk);
1611 * Observation: when sock_common_release is called, processes have
1612 * no access to socket. But net still has.
1613 * Step one, detach it from networking:
1615 * A. Remove from hash tables.
1618 sk->sk_prot->unhash(sk);
1621 * In this point socket cannot receive new packets, but it is possible
1622 * that some packets are in flight because some CPU runs receiver and
1623 * did hash table lookup before we unhashed socket. They will achieve
1624 * receive queue and will be purged by socket destructor.
1626 * Also we still have packets pending on receive queue and probably,
1627 * our own packets waiting in device queues. sock_destroy will drain
1628 * receive queue, but transmitted packets will delay socket destruction
1629 * until the last reference will be released.
1634 xfrm_sk_free_policy(sk);
1636 sk_refcnt_debug_release(sk);
1640 EXPORT_SYMBOL(sk_common_release);
1642 static DEFINE_RWLOCK(proto_list_lock);
1643 static LIST_HEAD(proto_list);
1645 int proto_register(struct proto *prot, int alloc_slab)
1647 char *request_sock_slab_name = NULL;
1648 char *timewait_sock_slab_name;
1652 prot->slab = kmem_cache_create(prot->name, prot->obj_size, 0,
1653 SLAB_HWCACHE_ALIGN, NULL, NULL);
1655 if (prot->slab == NULL) {
1656 printk(KERN_CRIT "%s: Can't create sock SLAB cache!\n",
1661 if (prot->rsk_prot != NULL) {
1662 static const char mask[] = "request_sock_%s";
1664 request_sock_slab_name = kmalloc(strlen(prot->name) + sizeof(mask) - 1, GFP_KERNEL);
1665 if (request_sock_slab_name == NULL)
1666 goto out_free_sock_slab;
1668 sprintf(request_sock_slab_name, mask, prot->name);
1669 prot->rsk_prot->slab = kmem_cache_create(request_sock_slab_name,
1670 prot->rsk_prot->obj_size, 0,
1671 SLAB_HWCACHE_ALIGN, NULL, NULL);
1673 if (prot->rsk_prot->slab == NULL) {
1674 printk(KERN_CRIT "%s: Can't create request sock SLAB cache!\n",
1676 goto out_free_request_sock_slab_name;
1680 if (prot->twsk_prot != NULL) {
1681 static const char mask[] = "tw_sock_%s";
1683 timewait_sock_slab_name = kmalloc(strlen(prot->name) + sizeof(mask) - 1, GFP_KERNEL);
1685 if (timewait_sock_slab_name == NULL)
1686 goto out_free_request_sock_slab;
1688 sprintf(timewait_sock_slab_name, mask, prot->name);
1689 prot->twsk_prot->twsk_slab =
1690 kmem_cache_create(timewait_sock_slab_name,
1691 prot->twsk_prot->twsk_obj_size,
1692 0, SLAB_HWCACHE_ALIGN,
1694 if (prot->twsk_prot->twsk_slab == NULL)
1695 goto out_free_timewait_sock_slab_name;
1699 write_lock(&proto_list_lock);
1700 list_add(&prot->node, &proto_list);
1701 write_unlock(&proto_list_lock);
1705 out_free_timewait_sock_slab_name:
1706 kfree(timewait_sock_slab_name);
1707 out_free_request_sock_slab:
1708 if (prot->rsk_prot && prot->rsk_prot->slab) {
1709 kmem_cache_destroy(prot->rsk_prot->slab);
1710 prot->rsk_prot->slab = NULL;
1712 out_free_request_sock_slab_name:
1713 kfree(request_sock_slab_name);
1715 kmem_cache_destroy(prot->slab);
1720 EXPORT_SYMBOL(proto_register);
1722 void proto_unregister(struct proto *prot)
1724 write_lock(&proto_list_lock);
1725 list_del(&prot->node);
1726 write_unlock(&proto_list_lock);
1728 if (prot->slab != NULL) {
1729 kmem_cache_destroy(prot->slab);
1733 if (prot->rsk_prot != NULL && prot->rsk_prot->slab != NULL) {
1734 const char *name = kmem_cache_name(prot->rsk_prot->slab);
1736 kmem_cache_destroy(prot->rsk_prot->slab);
1738 prot->rsk_prot->slab = NULL;
1741 if (prot->twsk_prot != NULL && prot->twsk_prot->twsk_slab != NULL) {
1742 const char *name = kmem_cache_name(prot->twsk_prot->twsk_slab);
1744 kmem_cache_destroy(prot->twsk_prot->twsk_slab);
1746 prot->twsk_prot->twsk_slab = NULL;
1750 EXPORT_SYMBOL(proto_unregister);
1752 #ifdef CONFIG_PROC_FS
1753 static inline struct proto *__proto_head(void)
1755 return list_entry(proto_list.next, struct proto, node);
1758 static inline struct proto *proto_head(void)
1760 return list_empty(&proto_list) ? NULL : __proto_head();
1763 static inline struct proto *proto_next(struct proto *proto)
1765 return proto->node.next == &proto_list ? NULL :
1766 list_entry(proto->node.next, struct proto, node);
1769 static inline struct proto *proto_get_idx(loff_t pos)
1771 struct proto *proto;
1774 list_for_each_entry(proto, &proto_list, node)
1783 static void *proto_seq_start(struct seq_file *seq, loff_t *pos)
1785 read_lock(&proto_list_lock);
1786 return *pos ? proto_get_idx(*pos - 1) : SEQ_START_TOKEN;
1789 static void *proto_seq_next(struct seq_file *seq, void *v, loff_t *pos)
1792 return v == SEQ_START_TOKEN ? proto_head() : proto_next(v);
1795 static void proto_seq_stop(struct seq_file *seq, void *v)
1797 read_unlock(&proto_list_lock);
1800 static char proto_method_implemented(const void *method)
1802 return method == NULL ? 'n' : 'y';
1805 static void proto_seq_printf(struct seq_file *seq, struct proto *proto)
1807 seq_printf(seq, "%-9s %4u %6d %6d %-3s %6u %-3s %-10s "
1808 "%2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c\n",
1811 proto->sockets_allocated != NULL ? atomic_read(proto->sockets_allocated) : -1,
1812 proto->memory_allocated != NULL ? atomic_read(proto->memory_allocated) : -1,
1813 proto->memory_pressure != NULL ? *proto->memory_pressure ? "yes" : "no" : "NI",
1815 proto->slab == NULL ? "no" : "yes",
1816 module_name(proto->owner),
1817 proto_method_implemented(proto->close),
1818 proto_method_implemented(proto->connect),
1819 proto_method_implemented(proto->disconnect),
1820 proto_method_implemented(proto->accept),
1821 proto_method_implemented(proto->ioctl),
1822 proto_method_implemented(proto->init),
1823 proto_method_implemented(proto->destroy),
1824 proto_method_implemented(proto->shutdown),
1825 proto_method_implemented(proto->setsockopt),
1826 proto_method_implemented(proto->getsockopt),
1827 proto_method_implemented(proto->sendmsg),
1828 proto_method_implemented(proto->recvmsg),
1829 proto_method_implemented(proto->sendpage),
1830 proto_method_implemented(proto->bind),
1831 proto_method_implemented(proto->backlog_rcv),
1832 proto_method_implemented(proto->hash),
1833 proto_method_implemented(proto->unhash),
1834 proto_method_implemented(proto->get_port),
1835 proto_method_implemented(proto->enter_memory_pressure));
1838 static int proto_seq_show(struct seq_file *seq, void *v)
1840 if (v == SEQ_START_TOKEN)
1841 seq_printf(seq, "%-9s %-4s %-8s %-6s %-5s %-7s %-4s %-10s %s",
1850 "cl co di ac io in de sh ss gs se re sp bi br ha uh gp em\n");
1852 proto_seq_printf(seq, v);
1856 static struct seq_operations proto_seq_ops = {
1857 .start = proto_seq_start,
1858 .next = proto_seq_next,
1859 .stop = proto_seq_stop,
1860 .show = proto_seq_show,
1863 static int proto_seq_open(struct inode *inode, struct file *file)
1865 return seq_open(file, &proto_seq_ops);
1868 static struct file_operations proto_seq_fops = {
1869 .owner = THIS_MODULE,
1870 .open = proto_seq_open,
1872 .llseek = seq_lseek,
1873 .release = seq_release,
1876 static int __init proto_init(void)
1878 /* register /proc/net/protocols */
1879 return proc_net_fops_create("protocols", S_IRUGO, &proto_seq_fops) == NULL ? -ENOBUFS : 0;
1882 subsys_initcall(proto_init);
1884 #endif /* PROC_FS */
1886 EXPORT_SYMBOL(sk_alloc);
1887 EXPORT_SYMBOL(sk_free);
1888 EXPORT_SYMBOL(sk_send_sigurg);
1889 EXPORT_SYMBOL(sock_alloc_send_skb);
1890 EXPORT_SYMBOL(sock_init_data);
1891 EXPORT_SYMBOL(sock_kfree_s);
1892 EXPORT_SYMBOL(sock_kmalloc);
1893 EXPORT_SYMBOL(sock_no_accept);
1894 EXPORT_SYMBOL(sock_no_bind);
1895 EXPORT_SYMBOL(sock_no_connect);
1896 EXPORT_SYMBOL(sock_no_getname);
1897 EXPORT_SYMBOL(sock_no_getsockopt);
1898 EXPORT_SYMBOL(sock_no_ioctl);
1899 EXPORT_SYMBOL(sock_no_listen);
1900 EXPORT_SYMBOL(sock_no_mmap);
1901 EXPORT_SYMBOL(sock_no_poll);
1902 EXPORT_SYMBOL(sock_no_recvmsg);
1903 EXPORT_SYMBOL(sock_no_sendmsg);
1904 EXPORT_SYMBOL(sock_no_sendpage);
1905 EXPORT_SYMBOL(sock_no_setsockopt);
1906 EXPORT_SYMBOL(sock_no_shutdown);
1907 EXPORT_SYMBOL(sock_no_socketpair);
1908 EXPORT_SYMBOL(sock_rfree);
1909 EXPORT_SYMBOL(sock_setsockopt);
1910 EXPORT_SYMBOL(sock_wfree);
1911 EXPORT_SYMBOL(sock_wmalloc);
1912 EXPORT_SYMBOL(sock_i_uid);
1913 EXPORT_SYMBOL(sock_i_ino);
1914 EXPORT_SYMBOL(sysctl_optmem_max);
1915 #ifdef CONFIG_SYSCTL
1916 EXPORT_SYMBOL(sysctl_rmem_max);
1917 EXPORT_SYMBOL(sysctl_wmem_max);