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 * PF_INET protocol family socket handler.
8 * Version: $Id: af_inet.c,v 1.82 1999/01/04 20:36:44 davem Exp $
10 * Authors: Ross Biro, <bir7@leland.Stanford.Edu>
11 * Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
12 * Florian La Roche, <flla@stud.uni-sb.de>
13 * Alan Cox, <A.Cox@swansea.ac.uk>
15 * Changes (see also sock.c)
17 * A.N.Kuznetsov : Socket death error in accept().
18 * John Richardson : Fix non blocking error in connect()
19 * so sockets that fail to connect
20 * don't return -EINPROGRESS.
21 * Alan Cox : Asynchronous I/O support
22 * Alan Cox : Keep correct socket pointer on sock structures
24 * Alan Cox : Semantics of SO_LINGER aren't state moved
25 * to close when you look carefully. With
26 * this fixed and the accept bug fixed
27 * some RPC stuff seems happier.
28 * Niibe Yutaka : 4.4BSD style write async I/O
30 * Tony Gale : Fixed reuse semantics.
31 * Alan Cox : bind() shouldn't abort existing but dead
32 * sockets. Stops FTP netin:.. I hope.
33 * Alan Cox : bind() works correctly for RAW sockets. Note
34 * that FreeBSD at least was broken in this respect
35 * so be careful with compatibility tests...
36 * Alan Cox : routing cache support
37 * Alan Cox : memzero the socket structure for compactness.
38 * Matt Day : nonblock connect error handler
39 * Alan Cox : Allow large numbers of pending sockets
40 * (eg for big web sites), but only if
41 * specifically application requested.
42 * Alan Cox : New buffering throughout IP. Used dumbly.
43 * Alan Cox : New buffering now used smartly.
44 * Alan Cox : BSD rather than common sense interpretation of
46 * Germano Caronni : Assorted small races.
47 * Alan Cox : sendmsg/recvmsg basic support.
48 * Alan Cox : Only sendmsg/recvmsg now supported.
49 * Alan Cox : Locked down bind (see security list).
50 * Alan Cox : Loosened bind a little.
51 * Mike McLagan : ADD/DEL DLCI Ioctls
52 * Willy Konynenberg : Transparent proxying support.
53 * David S. Miller : New socket lookup architecture.
54 * Some other random speedups.
55 * Cyrus Durgin : Cleaned up file for kmod hacks.
57 * This program is free software; you can redistribute it and/or
58 * modify it under the terms of the GNU General Public License
59 * as published by the Free Software Foundation; either version
60 * 2 of the License, or (at your option) any later version.
63 #include <linux/config.h>
64 #include <linux/errno.h>
65 #include <linux/types.h>
66 #include <linux/socket.h>
68 #include <linux/kernel.h>
69 #include <linux/major.h>
70 #include <linux/sched.h>
71 #include <linux/timer.h>
72 #include <linux/string.h>
73 #include <linux/sockios.h>
74 #include <linux/net.h>
75 #include <linux/fcntl.h>
77 #include <linux/interrupt.h>
78 #include <linux/proc_fs.h>
79 #include <linux/stat.h>
80 #include <linux/init.h>
81 #include <linux/poll.h>
83 #include <asm/uaccess.h>
84 #include <asm/system.h>
86 #include <linux/inet.h>
87 #include <linux/netdevice.h>
89 #include <net/protocol.h>
92 #include <net/route.h>
95 #include <linux/skbuff.h>
100 #include <net/inet_common.h>
101 #include <linux/ip_fw.h>
102 #ifdef CONFIG_IP_MROUTE
103 #include <linux/mroute.h>
105 #ifdef CONFIG_IP_MASQUERADE
106 #include <net/ip_masq.h>
112 #include <linux/kmod.h>
114 #ifdef CONFIG_NET_RADIO
115 #include <linux/wireless.h>
116 #endif /* CONFIG_NET_RADIO */
118 #define min(a,b) ((a)<(b)?(a):(b))
120 struct linux_mib net_statistics
;
122 extern int raw_get_info(char *, char **, off_t
, int, int);
123 extern int snmp_get_info(char *, char **, off_t
, int, int);
124 extern int netstat_get_info(char *, char **, off_t
, int, int);
125 extern int afinet_get_info(char *, char **, off_t
, int, int);
126 extern int tcp_get_info(char *, char **, off_t
, int, int);
127 extern int udp_get_info(char *, char **, off_t
, int, int);
128 extern void ip_mc_drop_socket(struct sock
*sk
);
131 extern int dlci_ioctl(unsigned int, void*);
134 #ifdef CONFIG_DLCI_MODULE
135 int (*dlci_ioctl_hook
)(unsigned int, void *) = NULL
;
138 int (*rarp_ioctl_hook
)(unsigned int,void*) = NULL
;
141 * Destroy an AF_INET socket
144 static __inline__
void kill_sk_queues(struct sock
*sk
)
148 /* First the read buffer. */
149 while((skb
= skb_dequeue(&sk
->receive_queue
)) != NULL
) {
150 /* This will take care of closing sockets that were
151 * listening and didn't accept everything.
153 if (skb
->sk
!= NULL
&& skb
->sk
!= sk
)
154 skb
->sk
->prot
->close(skb
->sk
, 0);
158 /* Next, the error queue. */
159 while((skb
= skb_dequeue(&sk
->error_queue
)) != NULL
)
162 /* Now the backlog. */
163 while((skb
=skb_dequeue(&sk
->back_log
)) != NULL
)
167 static __inline__
void kill_sk_now(struct sock
*sk
)
169 /* No longer exists. */
170 del_from_prot_sklist(sk
);
172 /* Remove from protocol hash chains. */
173 sk
->prot
->unhash(sk
);
177 dst_release(sk
->dst_cache
);
178 if (atomic_read(&sk
->omem_alloc
))
179 printk(KERN_DEBUG
"kill_sk_now: optmem leakage (%d bytes) detected.\n", atomic_read(&sk
->omem_alloc
));
183 static __inline__
void kill_sk_later(struct sock
*sk
)
185 /* this should never happen. */
186 /* actually it can if an ack has just been sent. */
188 * It's more normal than that...
189 * It can happen because a skb is still in the device queues
193 NETDEBUG(printk(KERN_DEBUG
"Socket destroy delayed (r=%d w=%d)\n",
194 atomic_read(&sk
->rmem_alloc
),
195 atomic_read(&sk
->wmem_alloc
)));
200 net_reset_timer(sk
, TIME_DESTROY
, SOCK_DESTROY_TIME
);
203 void destroy_sock(struct sock
*sk
)
205 lock_sock(sk
); /* just to be safe. */
207 /* Now we can no longer get new packets or once the
208 * timers are killed, send them.
210 net_delete_timer(sk
);
212 if (sk
->prot
->destroy
)
213 sk
->prot
->destroy(sk
);
217 /* Now if it has a half accepted/ closed socket. */
219 sk
->pair
->prot
->close(sk
->pair
, 0);
223 /* Now if everything is gone we can free the socket
224 * structure, otherwise we need to keep it around until
225 * everything is gone.
227 if (atomic_read(&sk
->rmem_alloc
) == 0 && atomic_read(&sk
->wmem_alloc
) == 0)
234 * The routines beyond this point handle the behaviour of an AF_INET
235 * socket object. Mostly it punts to the subprotocols of IP to do
241 * Set socket options on an inet socket.
244 int inet_setsockopt(struct socket
*sock
, int level
, int optname
,
245 char *optval
, int optlen
)
247 struct sock
*sk
=sock
->sk
;
248 if (sk
->prot
->setsockopt
==NULL
)
250 return sk
->prot
->setsockopt(sk
,level
,optname
,optval
,optlen
);
254 * Get a socket option on an AF_INET socket.
256 * FIX: POSIX 1003.1g is very ambiguous here. It states that
257 * asynchronous errors should be reported by getsockopt. We assume
258 * this means if you specify SO_ERROR (otherwise whats the point of it).
261 int inet_getsockopt(struct socket
*sock
, int level
, int optname
,
262 char *optval
, int *optlen
)
264 struct sock
*sk
=sock
->sk
;
265 if (sk
->prot
->getsockopt
==NULL
)
267 return sk
->prot
->getsockopt(sk
,level
,optname
,optval
,optlen
);
271 * Automatically bind an unbound socket.
274 static int inet_autobind(struct sock
*sk
)
276 /* We may need to bind the socket. */
278 sk
->num
= sk
->prot
->good_socknum();
281 sk
->sport
= htons(sk
->num
);
283 add_to_prot_sklist(sk
);
289 * Move a socket into listening state.
292 int inet_listen(struct socket
*sock
, int backlog
)
294 struct sock
*sk
= sock
->sk
;
296 if (sock
->state
!= SS_UNCONNECTED
|| sock
->type
!= SOCK_STREAM
)
299 if (inet_autobind(sk
) != 0)
302 /* We might as well re use these. */
303 if ((unsigned) backlog
== 0) /* BSDism */
305 if ((unsigned) backlog
> SOMAXCONN
)
307 sk
->max_ack_backlog
= backlog
;
308 if (sk
->state
!= TCP_LISTEN
) {
310 sk
->state
= TCP_LISTEN
;
311 dst_release(xchg(&sk
->dst_cache
, NULL
));
312 sk
->prot
->rehash(sk
);
313 add_to_prot_sklist(sk
);
315 sk
->socket
->flags
|= SO_ACCEPTCON
;
320 * Create an inet socket.
322 * FIXME: Gcc would generate much better code if we set the parameters
323 * up in in-memory structure order. Gcc68K even more so
326 static int inet_create(struct socket
*sock
, int protocol
)
332 if (sock
->type
== SOCK_PACKET
) {
334 if (net_families
[PF_PACKET
]==NULL
)
336 #if defined(CONFIG_KMOD) && defined(CONFIG_PACKET_MODULE)
337 char module_name
[30];
338 sprintf(module_name
,"net-pf-%d", PF_PACKET
);
339 request_module(module_name
);
340 if (net_families
[PF_PACKET
] == NULL
)
342 return -ESOCKTNOSUPPORT
;
345 printk(KERN_INFO
"%s uses obsolete (PF_INET,SOCK_PACKET)\n", current
->comm
);
346 return net_families
[PF_PACKET
]->create(sock
, protocol
);
349 sock
->state
= SS_UNCONNECTED
;
350 sk
= sk_alloc(PF_INET
, GFP_KERNEL
, 1);
354 switch (sock
->type
) {
356 if (protocol
&& protocol
!= IPPROTO_TCP
)
357 goto free_and_noproto
;
358 protocol
= IPPROTO_TCP
;
359 if (ipv4_config
.no_pmtu_disc
)
360 sk
->ip_pmtudisc
= IP_PMTUDISC_DONT
;
362 sk
->ip_pmtudisc
= IP_PMTUDISC_WANT
;
364 sock
->ops
= &inet_stream_ops
;
367 goto free_and_badtype
;
369 if (protocol
&& protocol
!= IPPROTO_UDP
)
370 goto free_and_noproto
;
371 protocol
= IPPROTO_UDP
;
372 sk
->no_check
= UDP_NO_CHECK
;
373 sk
->ip_pmtudisc
= IP_PMTUDISC_DONT
;
375 sock
->ops
= &inet_dgram_ops
;
378 if (!capable(CAP_NET_RAW
))
379 goto free_and_badperm
;
381 goto free_and_noproto
;
384 sk
->ip_pmtudisc
= IP_PMTUDISC_DONT
;
386 sock
->ops
= &inet_dgram_ops
;
387 if (protocol
== IPPROTO_RAW
)
391 goto free_and_badtype
;
394 sock_init_data(sock
,sk
);
399 #ifdef CONFIG_TCP_NAGLE_OFF
402 sk
->family
= PF_INET
;
403 sk
->protocol
= protocol
;
406 sk
->backlog_rcv
= prot
->backlog_rcv
;
408 sk
->timer
.data
= (unsigned long)sk
;
409 sk
->timer
.function
= &net_timer
;
411 sk
->ip_ttl
=ip_statistics
.IpDefaultTTL
;
419 /* It assumes that any protocol which allows
420 * the user to assign a number at socket
421 * creation time automatically
424 sk
->sport
= htons(sk
->num
);
426 /* Add to protocol hash chains. */
428 add_to_prot_sklist(sk
);
431 if (sk
->prot
->init
) {
432 int err
= sk
->prot
->init(sk
);
442 return -ESOCKTNOSUPPORT
;
450 return -EPROTONOSUPPORT
;
458 * The peer socket should always be NULL (or else). When we call this
459 * function we are destroying the object and from then on nobody
460 * should refer to it.
463 int inet_release(struct socket
*sock
, struct socket
*peersock
)
465 struct sock
*sk
= sock
->sk
;
470 /* Begin closedown and wake up sleepers. */
471 if (sock
->state
!= SS_UNCONNECTED
)
472 sock
->state
= SS_DISCONNECTING
;
473 sk
->state_change(sk
);
475 /* Applications forget to leave groups before exiting */
476 ip_mc_drop_socket(sk
);
478 /* If linger is set, we don't return until the close
479 * is complete. Otherwise we return immediately. The
480 * actually closing is done the same either way.
482 * If the close is due to the process exiting, we never
486 if (sk
->linger
&& !(current
->flags
& PF_EXITING
)) {
487 timeout
= MAX_SCHEDULE_TIMEOUT
;
489 /* XXX This makes no sense whatsoever... -DaveM */
491 timeout
= HZ
*sk
->lingertime
;
495 sk
->prot
->close(sk
, timeout
);
500 static int inet_bind(struct socket
*sock
, struct sockaddr
*uaddr
, int addr_len
)
502 struct sockaddr_in
*addr
=(struct sockaddr_in
*)uaddr
;
503 struct sock
*sk
=sock
->sk
;
507 /* If the socket has its own bind function then use it. (RAW) */
509 return sk
->prot
->bind(sk
, uaddr
, addr_len
);
511 /* Check these errors (active socket, bad address length, double bind). */
512 if ((sk
->state
!= TCP_CLOSE
) ||
513 (addr_len
< sizeof(struct sockaddr_in
)) ||
517 snum
= ntohs(addr
->sin_port
);
518 #ifdef CONFIG_IP_MASQUERADE
519 /* The kernel masquerader needs some ports. */
520 if((snum
>= PORT_MASQ_BEGIN
) && (snum
<= PORT_MASQ_END
))
524 snum
= sk
->prot
->good_socknum();
525 if (snum
< PROT_SOCK
&& !capable(CAP_NET_BIND_SERVICE
))
528 chk_addr_ret
= inet_addr_type(addr
->sin_addr
.s_addr
);
529 if (addr
->sin_addr
.s_addr
!= 0 && chk_addr_ret
!= RTN_LOCAL
&&
530 chk_addr_ret
!= RTN_MULTICAST
&& chk_addr_ret
!= RTN_BROADCAST
) {
531 #ifdef CONFIG_IP_TRANSPARENT_PROXY
532 /* Superuser may bind to any address to allow transparent proxying. */
533 if(chk_addr_ret
!= RTN_UNICAST
|| !capable(CAP_NET_ADMIN
))
535 return -EADDRNOTAVAIL
; /* Source address MUST be ours! */
538 /* We keep a pair of addresses. rcv_saddr is the one
539 * used by hash lookups, and saddr is used for transmit.
541 * In the BSD API these are the same except where it
542 * would be illegal to use them (multicast/broadcast) in
543 * which case the sending device address is used.
545 sk
->rcv_saddr
= sk
->saddr
= addr
->sin_addr
.s_addr
;
546 if(chk_addr_ret
== RTN_MULTICAST
|| chk_addr_ret
== RTN_BROADCAST
)
547 sk
->saddr
= 0; /* Use device */
549 /* Make sure we are allowed to bind here. */
550 if(sk
->prot
->verify_bind(sk
, snum
))
554 sk
->sport
= htons(snum
);
557 sk
->prot
->rehash(sk
);
558 add_to_prot_sklist(sk
);
559 dst_release(sk
->dst_cache
);
564 int inet_dgram_connect(struct socket
*sock
, struct sockaddr
* uaddr
,
565 int addr_len
, int flags
)
567 struct sock
*sk
=sock
->sk
;
570 if (inet_autobind(sk
) != 0)
572 if (sk
->prot
->connect
== NULL
)
574 err
= sk
->prot
->connect(sk
, (struct sockaddr
*)uaddr
, addr_len
);
580 static void inet_wait_for_connect(struct sock
*sk
)
582 struct wait_queue wait
= { current
, NULL
};
584 add_wait_queue(sk
->sleep
, &wait
);
585 current
->state
= TASK_INTERRUPTIBLE
;
586 while (sk
->state
== TCP_SYN_SENT
|| sk
->state
== TCP_SYN_RECV
) {
587 if (signal_pending(current
))
592 current
->state
= TASK_INTERRUPTIBLE
;
594 current
->state
= TASK_RUNNING
;
595 remove_wait_queue(sk
->sleep
, &wait
);
599 * Connect to a remote host. There is regrettably still a little
600 * TCP 'magic' in here.
603 int inet_stream_connect(struct socket
*sock
, struct sockaddr
* uaddr
,
604 int addr_len
, int flags
)
606 struct sock
*sk
=sock
->sk
;
609 if(sock
->state
!= SS_UNCONNECTED
&& sock
->state
!= SS_CONNECTING
) {
610 if(sock
->state
== SS_CONNECTED
)
615 if(sock
->state
== SS_CONNECTING
) {
616 if(tcp_connected(sk
->state
)) {
617 sock
->state
= SS_CONNECTED
;
620 if(sk
->protocol
== IPPROTO_TCP
&& (flags
& O_NONBLOCK
)) {
622 return sock_error(sk
);
626 /* We may need to bind the socket. */
627 if (inet_autobind(sk
) != 0)
629 if (sk
->prot
->connect
== NULL
)
631 err
= sk
->prot
->connect(sk
, uaddr
, addr_len
);
634 sock
->state
= SS_CONNECTING
;
637 if (sk
->state
> TCP_FIN_WAIT2
&& sock
->state
== SS_CONNECTING
) {
638 sock
->state
= SS_UNCONNECTED
;
639 return sock_error(sk
);
642 if (sk
->state
!= TCP_ESTABLISHED
&& (flags
& O_NONBLOCK
))
643 return (-EINPROGRESS
);
645 if (sk
->state
== TCP_SYN_SENT
|| sk
->state
== TCP_SYN_RECV
) {
646 inet_wait_for_connect(sk
);
647 if (signal_pending(current
))
651 sock
->state
= SS_CONNECTED
;
652 if ((sk
->state
!= TCP_ESTABLISHED
) && sk
->err
) {
653 /* This is ugly but needed to fix a race in the ICMP error handler */
654 if (sk
->protocol
== IPPROTO_TCP
&& sk
->zapped
) {
656 tcp_set_state(sk
, TCP_CLOSE
);
659 sock
->state
= SS_UNCONNECTED
;
660 return sock_error(sk
);
666 * Accept a pending connection. The TCP layer now gives BSD semantics.
669 int inet_accept(struct socket
*sock
, struct socket
*newsock
, int flags
)
671 struct sock
*sk1
= sock
->sk
, *sk2
;
672 struct sock
*newsk
= newsock
->sk
;
675 if (sock
->state
!= SS_UNCONNECTED
|| !(sock
->flags
& SO_ACCEPTCON
))
679 if (sk1
->prot
->accept
== NULL
)
682 /* Restore the state if we have been interrupted, and then returned. */
683 if (sk1
->pair
!= NULL
) {
687 if((sk2
= sk1
->prot
->accept(sk1
,flags
)) == NULL
)
692 * We've been passed an extra socket.
693 * We need to free it up because the tcp module creates
694 * its own when it accepts one.
696 sk2
->sleep
= newsk
->sleep
;
699 sk2
->socket
= newsock
;
700 newsk
->socket
= NULL
;
702 if (flags
& O_NONBLOCK
)
703 goto do_half_success
;
705 if(sk2
->state
== TCP_ESTABLISHED
)
706 goto do_full_success
;
710 if (sk2
->state
== TCP_CLOSE
)
711 goto do_bad_connection
;
714 newsock
->state
= SS_CONNECTED
;
722 err
= sock_error(sk2
);
728 newsk
->socket
= newsock
;
732 err
= sock_error(sk1
);
739 * This does both peername and sockname.
742 static int inet_getname(struct socket
*sock
, struct sockaddr
*uaddr
,
743 int *uaddr_len
, int peer
)
745 struct sock
*sk
= sock
->sk
;
746 struct sockaddr_in
*sin
= (struct sockaddr_in
*)uaddr
;
748 sin
->sin_family
= AF_INET
;
750 if (!tcp_connected(sk
->state
))
752 sin
->sin_port
= sk
->dport
;
753 sin
->sin_addr
.s_addr
= sk
->daddr
;
755 __u32 addr
= sk
->rcv_saddr
;
758 sin
->sin_port
= sk
->sport
;
759 sin
->sin_addr
.s_addr
= addr
;
761 *uaddr_len
= sizeof(*sin
);
767 int inet_recvmsg(struct socket
*sock
, struct msghdr
*msg
, int size
,
768 int flags
, struct scm_cookie
*scm
)
770 struct sock
*sk
= sock
->sk
;
774 if (sock
->flags
& SO_ACCEPTCON
)
776 if (sk
->prot
->recvmsg
== NULL
)
778 /* We may need to bind the socket. */
779 if (inet_autobind(sk
) != 0)
781 err
= sk
->prot
->recvmsg(sk
, msg
, size
, flags
&MSG_DONTWAIT
,
782 flags
&~MSG_DONTWAIT
, &addr_len
);
784 msg
->msg_namelen
= addr_len
;
789 int inet_sendmsg(struct socket
*sock
, struct msghdr
*msg
, int size
,
790 struct scm_cookie
*scm
)
792 struct sock
*sk
= sock
->sk
;
794 if (sk
->shutdown
& SEND_SHUTDOWN
) {
795 if (!(msg
->msg_flags
&MSG_NOSIGNAL
))
796 send_sig(SIGPIPE
, current
, 1);
799 if (sk
->prot
->sendmsg
== NULL
)
802 return sock_error(sk
);
804 /* We may need to bind the socket. */
805 if(inet_autobind(sk
) != 0)
808 return sk
->prot
->sendmsg(sk
, msg
, size
);
812 int inet_shutdown(struct socket
*sock
, int how
)
814 struct sock
*sk
= sock
->sk
;
816 /* This should really check to make sure
817 * the socket is a TCP socket. (WHY AC...)
819 how
++; /* maps 0->1 has the advantage of making bit 1 rcvs and
822 if ((how
& ~SHUTDOWN_MASK
) || how
==0) /* MAXINT->0 */
824 if (sock
->state
== SS_CONNECTING
&& sk
->state
== TCP_ESTABLISHED
)
825 sock
->state
= SS_CONNECTED
;
826 if (!sk
|| !tcp_connected(sk
->state
))
829 if (sk
->prot
->shutdown
)
830 sk
->prot
->shutdown(sk
, how
);
835 unsigned int inet_poll(struct file
* file
, struct socket
*sock
, poll_table
*wait
)
837 struct sock
*sk
= sock
->sk
;
839 if (sk
->prot
->poll
== NULL
)
841 return sk
->prot
->poll(file
, sock
, wait
);
845 * ioctl() calls you can issue on an INET socket. Most of these are
846 * device configuration and stuff and very rarely used. Some ioctls
847 * pass on to the socket itself.
849 * NOTE: I like the idea of a module for the config stuff. ie ifconfig
850 * loads the devconfigure module does its configuring and unloads it.
851 * There's a good 20K of config code hanging around the kernel.
854 static int inet_ioctl(struct socket
*sock
, unsigned int cmd
, unsigned long arg
)
856 struct sock
*sk
= sock
->sk
;
864 err
= get_user(pid
, (int *) arg
);
867 if (current
->pid
!= pid
&& current
->pgrp
!= -pid
&&
868 !capable(CAP_NET_ADMIN
))
874 return put_user(sk
->proc
, (int *)arg
);
876 if(sk
->stamp
.tv_sec
==0)
878 err
= copy_to_user((void *)arg
,&sk
->stamp
,sizeof(struct timeval
));
885 return(ip_rt_ioctl(cmd
,(void *) arg
));
889 return(arp_ioctl(cmd
,(void *) arg
));
894 if (rarp_ioctl_hook
== NULL
)
895 request_module("rarp");
897 if (rarp_ioctl_hook
!= NULL
)
898 return(rarp_ioctl_hook(cmd
,(void *) arg
));
910 return(devinet_ioctl(cmd
,(void *) arg
));
914 return(br_ioctl(cmd
,(void *) arg
));
922 return(dlci_ioctl(cmd
, (void *) arg
));
925 #ifdef CONFIG_DLCI_MODULE
928 if (dlci_ioctl_hook
== NULL
)
929 request_module("dlci");
933 return((*dlci_ioctl_hook
)(cmd
, (void *) arg
));
938 if ((cmd
>= SIOCDEVPRIVATE
) &&
939 (cmd
<= (SIOCDEVPRIVATE
+ 15)))
940 return(dev_ioctl(cmd
,(void *) arg
));
942 #ifdef CONFIG_NET_RADIO
943 if((cmd
>= SIOCIWFIRST
) && (cmd
<= SIOCIWLAST
))
944 return(dev_ioctl(cmd
,(void *) arg
));
947 if (sk
->prot
->ioctl
==NULL
|| (err
=sk
->prot
->ioctl(sk
, cmd
, arg
))==-ENOIOCTLCMD
)
948 return(dev_ioctl(cmd
,(void *) arg
));
955 struct proto_ops inet_stream_ops
= {
976 struct proto_ops inet_dgram_ops
= {
997 struct net_proto_family inet_family_ops
= {
1003 #ifdef CONFIG_PROC_FS
1004 #ifdef CONFIG_INET_RARP
1005 static struct proc_dir_entry proc_net_rarp
= {
1006 PROC_NET_RARP
, 4, "rarp",
1007 S_IFREG
| S_IRUGO
, 1, 0, 0,
1008 0, &proc_net_inode_operations
,
1012 static struct proc_dir_entry proc_net_raw
= {
1013 PROC_NET_RAW
, 3, "raw",
1014 S_IFREG
| S_IRUGO
, 1, 0, 0,
1015 0, &proc_net_inode_operations
,
1018 static struct proc_dir_entry proc_net_netstat
= {
1019 PROC_NET_NETSTAT
, 7, "netstat",
1020 S_IFREG
| S_IRUGO
, 1, 0, 0,
1021 0, &proc_net_inode_operations
,
1024 static struct proc_dir_entry proc_net_snmp
= {
1025 PROC_NET_SNMP
, 4, "snmp",
1026 S_IFREG
| S_IRUGO
, 1, 0, 0,
1027 0, &proc_net_inode_operations
,
1030 static struct proc_dir_entry proc_net_sockstat
= {
1031 PROC_NET_SOCKSTAT
, 8, "sockstat",
1032 S_IFREG
| S_IRUGO
, 1, 0, 0,
1033 0, &proc_net_inode_operations
,
1036 static struct proc_dir_entry proc_net_tcp
= {
1037 PROC_NET_TCP
, 3, "tcp",
1038 S_IFREG
| S_IRUGO
, 1, 0, 0,
1039 0, &proc_net_inode_operations
,
1042 static struct proc_dir_entry proc_net_udp
= {
1043 PROC_NET_UDP
, 3, "udp",
1044 S_IFREG
| S_IRUGO
, 1, 0, 0,
1045 0, &proc_net_inode_operations
,
1048 #endif /* CONFIG_PROC_FS */
1050 extern void tcp_init(void);
1051 extern void tcp_v4_init(struct net_proto_family
*);
1055 * Called by socket.c on kernel startup.
1058 __initfunc(void inet_proto_init(struct net_proto
*pro
))
1060 struct sk_buff
*dummy_skb
;
1061 struct inet_protocol
*p
;
1063 printk(KERN_INFO
"NET4: Linux TCP/IP 1.0 for NET4.0\n");
1065 if (sizeof(struct inet_skb_parm
) > sizeof(dummy_skb
->cb
))
1067 printk(KERN_CRIT
"inet_proto_init: panic\n");
1072 * Tell SOCKET that we are alive...
1075 (void) sock_register(&inet_family_ops
);
1078 * Add all the protocols.
1081 printk(KERN_INFO
"IP Protocols: ");
1082 for(p
= inet_protocol_base
; p
!= NULL
;)
1084 struct inet_protocol
*tmp
= (struct inet_protocol
*) p
->next
;
1085 inet_add_protocol(p
);
1086 printk("%s%s",p
->name
,tmp
?", ":"\n");
1091 * Set the ARP module up
1097 * Set the IP module up
1102 tcp_v4_init(&inet_family_ops
);
1104 /* Setup TCP slab cache for open requests. */
1109 * Set the ICMP layer up
1112 icmp_init(&inet_family_ops
);
1114 /* I wish inet_add_protocol had no constructor hook...
1115 I had to move IPIP from net/ipv4/protocol.c :-( --ANK
1117 #ifdef CONFIG_NET_IPIP
1120 #ifdef CONFIG_NET_IPGRE
1125 * Set the firewalling up
1127 #if defined(CONFIG_IP_FIREWALL)
1131 #ifdef CONFIG_IP_MASQUERADE
1136 * Initialise the multicast router
1138 #if defined(CONFIG_IP_MROUTE)
1142 #ifdef CONFIG_INET_RARP
1143 rarp_ioctl_hook
= rarp_ioctl
;
1146 * Create all the /proc entries.
1149 #ifdef CONFIG_PROC_FS
1150 #ifdef CONFIG_INET_RARP
1151 proc_net_register(&proc_net_rarp
);
1153 proc_net_register(&proc_net_raw
);
1154 proc_net_register(&proc_net_snmp
);
1155 proc_net_register(&proc_net_netstat
);
1156 proc_net_register(&proc_net_sockstat
);
1157 proc_net_register(&proc_net_tcp
);
1158 proc_net_register(&proc_net_udp
);
1159 #endif /* CONFIG_PROC_FS */