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.88 1999/05/12 11:24:27 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.
56 * Andi Kleen : Fix inet_stream_connect TCP race.
58 * This program is free software; you can redistribute it and/or
59 * modify it under the terms of the GNU General Public License
60 * as published by the Free Software Foundation; either version
61 * 2 of the License, or (at your option) any later version.
64 #include <linux/config.h>
65 #include <linux/errno.h>
66 #include <linux/types.h>
67 #include <linux/socket.h>
69 #include <linux/kernel.h>
70 #include <linux/major.h>
71 #include <linux/sched.h>
72 #include <linux/timer.h>
73 #include <linux/string.h>
74 #include <linux/sockios.h>
75 #include <linux/net.h>
76 #include <linux/fcntl.h>
78 #include <linux/interrupt.h>
79 #include <linux/proc_fs.h>
80 #include <linux/stat.h>
81 #include <linux/init.h>
82 #include <linux/poll.h>
84 #include <asm/uaccess.h>
85 #include <asm/system.h>
87 #include <linux/inet.h>
88 #include <linux/netdevice.h>
90 #include <net/protocol.h>
93 #include <net/route.h>
96 #include <linux/skbuff.h>
100 #include <net/ipip.h>
101 #include <net/inet_common.h>
102 #include <linux/ip_fw.h>
103 #ifdef CONFIG_IP_MROUTE
104 #include <linux/mroute.h>
106 #ifdef CONFIG_IP_MASQUERADE
107 #include <net/ip_masq.h>
113 #include <linux/kmod.h>
115 #ifdef CONFIG_NET_RADIO
116 #include <linux/wireless.h>
117 #endif /* CONFIG_NET_RADIO */
119 #define min(a,b) ((a)<(b)?(a):(b))
121 struct linux_mib net_statistics
;
123 extern int raw_get_info(char *, char **, off_t
, int, int);
124 extern int snmp_get_info(char *, char **, off_t
, int, int);
125 extern int netstat_get_info(char *, char **, off_t
, int, int);
126 extern int afinet_get_info(char *, char **, off_t
, int, int);
127 extern int tcp_get_info(char *, char **, off_t
, int, int);
128 extern int udp_get_info(char *, char **, off_t
, int, int);
129 extern void ip_mc_drop_socket(struct sock
*sk
);
132 extern int dlci_ioctl(unsigned int, void*);
135 #ifdef CONFIG_DLCI_MODULE
136 int (*dlci_ioctl_hook
)(unsigned int, void *) = NULL
;
139 int (*rarp_ioctl_hook
)(unsigned int,void*) = NULL
;
142 * Destroy an AF_INET socket
145 static __inline__
void kill_sk_queues(struct sock
*sk
)
149 /* First the read buffer. */
150 while((skb
= skb_dequeue(&sk
->receive_queue
)) != NULL
) {
151 /* This will take care of closing sockets that were
152 * listening and didn't accept everything.
154 if (skb
->sk
!= NULL
&& skb
->sk
!= sk
)
155 skb
->sk
->prot
->close(skb
->sk
, 0);
159 /* Next, the error queue. */
160 while((skb
= skb_dequeue(&sk
->error_queue
)) != NULL
)
163 /* It is _impossible_ for the backlog to contain anything
164 * when we get here. All user references to this socket
165 * have gone away, only the net layer knows can touch it.
169 static __inline__
void kill_sk_now(struct sock
*sk
)
171 /* No longer exists. */
172 del_from_prot_sklist(sk
);
174 /* Remove from protocol hash chains. */
175 sk
->prot
->unhash(sk
);
179 dst_release(sk
->dst_cache
);
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 /* Callers must hold the BH spinlock.
205 * At this point, there should be no process reference to this
206 * socket, and thus no user references at all. Therefore we
207 * can assume the socket waitqueue is inactive and nobody will
208 * try to jump onto it.
210 void destroy_sock(struct sock
*sk
)
212 /* Now we can no longer get new packets or once the
213 * timers are killed, send them.
215 net_delete_timer(sk
);
217 if (sk
->prot
->destroy
)
218 sk
->prot
->destroy(sk
);
222 /* Now if it has a half accepted/ closed socket. */
224 sk
->pair
->prot
->close(sk
->pair
, 0);
228 /* Now if everything is gone we can free the socket
229 * structure, otherwise we need to keep it around until
230 * everything is gone.
232 if (atomic_read(&sk
->rmem_alloc
) == 0 && atomic_read(&sk
->wmem_alloc
) == 0)
239 * The routines beyond this point handle the behaviour of an AF_INET
240 * socket object. Mostly it punts to the subprotocols of IP to do
246 * Set socket options on an inet socket.
249 int inet_setsockopt(struct socket
*sock
, int level
, int optname
,
250 char *optval
, int optlen
)
252 struct sock
*sk
=sock
->sk
;
253 if (sk
->prot
->setsockopt
==NULL
)
255 return sk
->prot
->setsockopt(sk
,level
,optname
,optval
,optlen
);
259 * Get a socket option on an AF_INET socket.
261 * FIX: POSIX 1003.1g is very ambiguous here. It states that
262 * asynchronous errors should be reported by getsockopt. We assume
263 * this means if you specify SO_ERROR (otherwise whats the point of it).
266 int inet_getsockopt(struct socket
*sock
, int level
, int optname
,
267 char *optval
, int *optlen
)
269 struct sock
*sk
=sock
->sk
;
270 if (sk
->prot
->getsockopt
==NULL
)
272 return sk
->prot
->getsockopt(sk
,level
,optname
,optval
,optlen
);
276 * Automatically bind an unbound socket.
279 static int inet_autobind(struct sock
*sk
)
281 /* We may need to bind the socket. */
283 sk
->num
= sk
->prot
->good_socknum();
286 sk
->sport
= htons(sk
->num
);
288 add_to_prot_sklist(sk
);
294 * Move a socket into listening state.
297 int inet_listen(struct socket
*sock
, int backlog
)
299 struct sock
*sk
= sock
->sk
;
301 if (sock
->state
!= SS_UNCONNECTED
|| sock
->type
!= SOCK_STREAM
)
304 if (inet_autobind(sk
) != 0)
307 /* We might as well re use these. */
308 if ((unsigned) backlog
== 0) /* BSDism */
310 if ((unsigned) backlog
> SOMAXCONN
)
312 sk
->max_ack_backlog
= backlog
;
313 if (sk
->state
!= TCP_LISTEN
) {
315 sk
->state
= TCP_LISTEN
;
316 dst_release(xchg(&sk
->dst_cache
, NULL
));
317 sk
->prot
->rehash(sk
);
318 add_to_prot_sklist(sk
);
320 sk
->socket
->flags
|= SO_ACCEPTCON
;
325 * Create an inet socket.
327 * FIXME: Gcc would generate much better code if we set the parameters
328 * up in in-memory structure order. Gcc68K even more so
331 static int inet_create(struct socket
*sock
, int protocol
)
337 if (sock
->type
== SOCK_PACKET
) {
339 if (net_families
[PF_PACKET
]==NULL
)
341 #if defined(CONFIG_KMOD) && defined(CONFIG_PACKET_MODULE)
342 char module_name
[30];
343 sprintf(module_name
,"net-pf-%d", PF_PACKET
);
344 request_module(module_name
);
345 if (net_families
[PF_PACKET
] == NULL
)
347 return -ESOCKTNOSUPPORT
;
350 printk(KERN_INFO
"%s uses obsolete (PF_INET,SOCK_PACKET)\n", current
->comm
);
351 return net_families
[PF_PACKET
]->create(sock
, protocol
);
354 sock
->state
= SS_UNCONNECTED
;
355 sk
= sk_alloc(PF_INET
, GFP_KERNEL
, 1);
359 switch (sock
->type
) {
361 if (protocol
&& protocol
!= IPPROTO_TCP
)
362 goto free_and_noproto
;
363 protocol
= IPPROTO_TCP
;
364 if (ipv4_config
.no_pmtu_disc
)
365 sk
->ip_pmtudisc
= IP_PMTUDISC_DONT
;
367 sk
->ip_pmtudisc
= IP_PMTUDISC_WANT
;
369 sock
->ops
= &inet_stream_ops
;
372 goto free_and_badtype
;
374 if (protocol
&& protocol
!= IPPROTO_UDP
)
375 goto free_and_noproto
;
376 protocol
= IPPROTO_UDP
;
377 sk
->no_check
= UDP_NO_CHECK
;
378 sk
->ip_pmtudisc
= IP_PMTUDISC_DONT
;
380 sock
->ops
= &inet_dgram_ops
;
383 if (!capable(CAP_NET_RAW
))
384 goto free_and_badperm
;
386 goto free_and_noproto
;
389 sk
->ip_pmtudisc
= IP_PMTUDISC_DONT
;
391 sock
->ops
= &inet_dgram_ops
;
392 if (protocol
== IPPROTO_RAW
)
396 goto free_and_badtype
;
399 sock_init_data(sock
,sk
);
404 #ifdef CONFIG_TCP_NAGLE_OFF
407 sk
->family
= PF_INET
;
408 sk
->protocol
= protocol
;
411 sk
->backlog_rcv
= prot
->backlog_rcv
;
413 sk
->timer
.data
= (unsigned long)sk
;
414 sk
->timer
.function
= &net_timer
;
416 sk
->ip_ttl
=ip_statistics
.IpDefaultTTL
;
424 /* It assumes that any protocol which allows
425 * the user to assign a number at socket
426 * creation time automatically
429 sk
->sport
= htons(sk
->num
);
431 /* Add to protocol hash chains. */
433 add_to_prot_sklist(sk
);
436 if (sk
->prot
->init
) {
437 int err
= sk
->prot
->init(sk
);
447 return -ESOCKTNOSUPPORT
;
455 return -EPROTONOSUPPORT
;
463 * The peer socket should always be NULL (or else). When we call this
464 * function we are destroying the object and from then on nobody
465 * should refer to it.
468 int inet_release(struct socket
*sock
, struct socket
*peersock
)
470 struct sock
*sk
= sock
->sk
;
475 /* Begin closedown and wake up sleepers. */
476 if (sock
->state
!= SS_UNCONNECTED
)
477 sock
->state
= SS_DISCONNECTING
;
478 sk
->state_change(sk
);
480 /* Applications forget to leave groups before exiting */
481 ip_mc_drop_socket(sk
);
483 /* If linger is set, we don't return until the close
484 * is complete. Otherwise we return immediately. The
485 * actually closing is done the same either way.
487 * If the close is due to the process exiting, we never
491 if (sk
->linger
&& !(current
->flags
& PF_EXITING
)) {
492 timeout
= MAX_SCHEDULE_TIMEOUT
;
494 /* XXX This makes no sense whatsoever... -DaveM */
496 timeout
= HZ
*sk
->lingertime
;
500 sk
->prot
->close(sk
, timeout
);
505 static int inet_bind(struct socket
*sock
, struct sockaddr
*uaddr
, int addr_len
)
507 struct sockaddr_in
*addr
=(struct sockaddr_in
*)uaddr
;
508 struct sock
*sk
=sock
->sk
;
512 /* If the socket has its own bind function then use it. (RAW) */
514 return sk
->prot
->bind(sk
, uaddr
, addr_len
);
516 /* Check these errors (active socket, bad address length, double bind). */
517 if ((sk
->state
!= TCP_CLOSE
) ||
518 (addr_len
< sizeof(struct sockaddr_in
)) ||
522 chk_addr_ret
= inet_addr_type(addr
->sin_addr
.s_addr
);
523 if (addr
->sin_addr
.s_addr
!= 0 && chk_addr_ret
!= RTN_LOCAL
&&
524 chk_addr_ret
!= RTN_MULTICAST
&& chk_addr_ret
!= RTN_BROADCAST
) {
525 #ifdef CONFIG_IP_TRANSPARENT_PROXY
526 /* Superuser may bind to any address to allow transparent proxying. */
527 if(chk_addr_ret
!= RTN_UNICAST
|| !capable(CAP_NET_ADMIN
))
529 return -EADDRNOTAVAIL
; /* Source address MUST be ours! */
532 /* We keep a pair of addresses. rcv_saddr is the one
533 * used by hash lookups, and saddr is used for transmit.
535 * In the BSD API these are the same except where it
536 * would be illegal to use them (multicast/broadcast) in
537 * which case the sending device address is used.
539 sk
->rcv_saddr
= sk
->saddr
= addr
->sin_addr
.s_addr
;
540 if(chk_addr_ret
== RTN_MULTICAST
|| chk_addr_ret
== RTN_BROADCAST
)
541 sk
->saddr
= 0; /* Use device */
543 snum
= ntohs(addr
->sin_port
);
544 #ifdef CONFIG_IP_MASQUERADE
545 /* The kernel masquerader needs some ports. */
546 if((snum
>= PORT_MASQ_BEGIN
) && (snum
<= PORT_MASQ_END
))
550 snum
= sk
->prot
->good_socknum();
551 if (snum
< PROT_SOCK
&& !capable(CAP_NET_BIND_SERVICE
))
554 /* Make sure we are allowed to bind here. */
555 if(sk
->prot
->verify_bind(sk
, snum
))
559 sk
->sport
= htons(snum
);
562 sk
->prot
->rehash(sk
);
563 add_to_prot_sklist(sk
);
564 dst_release(sk
->dst_cache
);
569 int inet_dgram_connect(struct socket
*sock
, struct sockaddr
* uaddr
,
570 int addr_len
, int flags
)
572 struct sock
*sk
=sock
->sk
;
575 if (inet_autobind(sk
) != 0)
577 if (sk
->prot
->connect
== NULL
)
579 err
= sk
->prot
->connect(sk
, (struct sockaddr
*)uaddr
, addr_len
);
585 static void inet_wait_for_connect(struct sock
*sk
)
587 DECLARE_WAITQUEUE(wait
, current
);
589 add_wait_queue(sk
->sleep
, &wait
);
590 current
->state
= TASK_INTERRUPTIBLE
;
591 while (sk
->state
== TCP_SYN_SENT
|| sk
->state
== TCP_SYN_RECV
) {
592 if (signal_pending(current
))
597 current
->state
= TASK_INTERRUPTIBLE
;
599 current
->state
= TASK_RUNNING
;
600 remove_wait_queue(sk
->sleep
, &wait
);
604 * Connect to a remote host. There is regrettably still a little
605 * TCP 'magic' in here.
608 int inet_stream_connect(struct socket
*sock
, struct sockaddr
* uaddr
,
609 int addr_len
, int flags
)
611 struct sock
*sk
=sock
->sk
;
614 if(sock
->state
!= SS_UNCONNECTED
&& sock
->state
!= SS_CONNECTING
) {
615 if(sock
->state
== SS_CONNECTED
)
620 if(sock
->state
== SS_CONNECTING
) {
621 /* Note: tcp_connected contains SYN_RECV, which may cause
622 bogus results here. -AK */
623 if(tcp_connected(sk
->state
)) {
624 sock
->state
= SS_CONNECTED
;
627 if (sk
->zapped
|| sk
->err
)
629 if (flags
& O_NONBLOCK
)
632 /* We may need to bind the socket. */
633 if (inet_autobind(sk
) != 0)
635 if (sk
->prot
->connect
== NULL
)
637 err
= sk
->prot
->connect(sk
, uaddr
, addr_len
);
638 /* Note: there is a theoretical race here when an wake up
639 occurred before inet_wait_for_connect is entered. In 2.3
640 the wait queue setup should be moved before the low level
644 sock
->state
= SS_CONNECTING
;
647 if (sk
->state
> TCP_FIN_WAIT2
&& sock
->state
== SS_CONNECTING
)
650 if (sk
->state
!= TCP_ESTABLISHED
&& (flags
& O_NONBLOCK
))
651 return (-EINPROGRESS
);
653 if (sk
->state
== TCP_SYN_SENT
|| sk
->state
== TCP_SYN_RECV
) {
654 inet_wait_for_connect(sk
);
655 if (signal_pending(current
))
659 sock
->state
= SS_CONNECTED
;
660 if ((sk
->state
!= TCP_ESTABLISHED
) && sk
->err
)
665 /* This is ugly but needed to fix a race in the ICMP error handler */
666 if (sk
->zapped
&& sk
->state
!= TCP_CLOSE
) {
668 tcp_set_state(sk
, TCP_CLOSE
);
672 sock
->state
= SS_UNCONNECTED
;
673 return sock_error(sk
);
677 * Accept a pending connection. The TCP layer now gives BSD semantics.
680 int inet_accept(struct socket
*sock
, struct socket
*newsock
, int flags
)
682 struct sock
*sk1
= sock
->sk
, *sk2
;
683 struct sock
*newsk
= newsock
->sk
;
686 if (sock
->state
!= SS_UNCONNECTED
|| !(sock
->flags
& SO_ACCEPTCON
))
690 if (sk1
->prot
->accept
== NULL
)
693 /* Restore the state if we have been interrupted, and then returned. */
694 if (sk1
->pair
!= NULL
) {
698 if((sk2
= sk1
->prot
->accept(sk1
,flags
)) == NULL
)
703 * We've been passed an extra socket.
704 * We need to free it up because the tcp module creates
705 * its own when it accepts one.
707 sk2
->sleep
= newsk
->sleep
;
710 sk2
->socket
= newsock
;
711 newsk
->socket
= NULL
;
713 if (flags
& O_NONBLOCK
)
714 goto do_half_success
;
716 if(sk2
->state
== TCP_ESTABLISHED
)
717 goto do_full_success
;
721 if (sk2
->state
== TCP_CLOSE
)
722 goto do_bad_connection
;
725 newsock
->state
= SS_CONNECTED
;
733 err
= sock_error(sk2
);
739 newsk
->socket
= newsock
;
743 err
= sock_error(sk1
);
750 * This does both peername and sockname.
753 static int inet_getname(struct socket
*sock
, struct sockaddr
*uaddr
,
754 int *uaddr_len
, int peer
)
756 struct sock
*sk
= sock
->sk
;
757 struct sockaddr_in
*sin
= (struct sockaddr_in
*)uaddr
;
759 sin
->sin_family
= AF_INET
;
761 if (!tcp_connected(sk
->state
))
763 sin
->sin_port
= sk
->dport
;
764 sin
->sin_addr
.s_addr
= sk
->daddr
;
766 __u32 addr
= sk
->rcv_saddr
;
769 sin
->sin_port
= sk
->sport
;
770 sin
->sin_addr
.s_addr
= addr
;
772 *uaddr_len
= sizeof(*sin
);
778 int inet_recvmsg(struct socket
*sock
, struct msghdr
*msg
, int size
,
779 int flags
, struct scm_cookie
*scm
)
781 struct sock
*sk
= sock
->sk
;
785 if (sock
->flags
& SO_ACCEPTCON
)
787 if (sk
->prot
->recvmsg
== NULL
)
789 /* We may need to bind the socket. */
790 if (inet_autobind(sk
) != 0)
792 err
= sk
->prot
->recvmsg(sk
, msg
, size
, flags
&MSG_DONTWAIT
,
793 flags
&~MSG_DONTWAIT
, &addr_len
);
795 msg
->msg_namelen
= addr_len
;
800 int inet_sendmsg(struct socket
*sock
, struct msghdr
*msg
, int size
,
801 struct scm_cookie
*scm
)
803 struct sock
*sk
= sock
->sk
;
805 if (sk
->shutdown
& SEND_SHUTDOWN
) {
806 if (!(msg
->msg_flags
&MSG_NOSIGNAL
))
807 send_sig(SIGPIPE
, current
, 1);
810 if (sk
->prot
->sendmsg
== NULL
)
813 return sock_error(sk
);
815 /* We may need to bind the socket. */
816 if(inet_autobind(sk
) != 0)
819 return sk
->prot
->sendmsg(sk
, msg
, size
);
823 int inet_shutdown(struct socket
*sock
, int how
)
825 struct sock
*sk
= sock
->sk
;
827 /* This should really check to make sure
828 * the socket is a TCP socket. (WHY AC...)
830 how
++; /* maps 0->1 has the advantage of making bit 1 rcvs and
833 if ((how
& ~SHUTDOWN_MASK
) || how
==0) /* MAXINT->0 */
835 if (sock
->state
== SS_CONNECTING
&& sk
->state
== TCP_ESTABLISHED
)
836 sock
->state
= SS_CONNECTED
;
837 if (!sk
|| !tcp_connected(sk
->state
))
840 if (sk
->prot
->shutdown
)
841 sk
->prot
->shutdown(sk
, how
);
842 /* Wake up anyone sleeping in poll. */
843 sk
->state_change(sk
);
848 unsigned int inet_poll(struct file
* file
, struct socket
*sock
, poll_table
*wait
)
850 struct sock
*sk
= sock
->sk
;
852 if (sk
->prot
->poll
== NULL
)
854 return sk
->prot
->poll(file
, sock
, wait
);
858 * ioctl() calls you can issue on an INET socket. Most of these are
859 * device configuration and stuff and very rarely used. Some ioctls
860 * pass on to the socket itself.
862 * NOTE: I like the idea of a module for the config stuff. ie ifconfig
863 * loads the devconfigure module does its configuring and unloads it.
864 * There's a good 20K of config code hanging around the kernel.
867 static int inet_ioctl(struct socket
*sock
, unsigned int cmd
, unsigned long arg
)
869 struct sock
*sk
= sock
->sk
;
877 err
= get_user(pid
, (int *) arg
);
880 if (current
->pid
!= pid
&& current
->pgrp
!= -pid
&&
881 !capable(CAP_NET_ADMIN
))
887 return put_user(sk
->proc
, (int *)arg
);
889 if(sk
->stamp
.tv_sec
==0)
891 err
= copy_to_user((void *)arg
,&sk
->stamp
,sizeof(struct timeval
));
898 return(ip_rt_ioctl(cmd
,(void *) arg
));
902 return(arp_ioctl(cmd
,(void *) arg
));
907 if (rarp_ioctl_hook
== NULL
)
908 request_module("rarp");
910 if (rarp_ioctl_hook
!= NULL
)
911 return(rarp_ioctl_hook(cmd
,(void *) arg
));
923 return(devinet_ioctl(cmd
,(void *) arg
));
927 return(br_ioctl(cmd
,(void *) arg
));
935 return(dlci_ioctl(cmd
, (void *) arg
));
938 #ifdef CONFIG_DLCI_MODULE
941 if (dlci_ioctl_hook
== NULL
)
942 request_module("dlci");
946 return((*dlci_ioctl_hook
)(cmd
, (void *) arg
));
951 if ((cmd
>= SIOCDEVPRIVATE
) &&
952 (cmd
<= (SIOCDEVPRIVATE
+ 15)))
953 return(dev_ioctl(cmd
,(void *) arg
));
955 #ifdef CONFIG_NET_RADIO
956 if((cmd
>= SIOCIWFIRST
) && (cmd
<= SIOCIWLAST
))
957 return(dev_ioctl(cmd
,(void *) arg
));
960 if (sk
->prot
->ioctl
==NULL
|| (err
=sk
->prot
->ioctl(sk
, cmd
, arg
))==-ENOIOCTLCMD
)
961 return(dev_ioctl(cmd
,(void *) arg
));
968 struct proto_ops inet_stream_ops
= {
989 struct proto_ops inet_dgram_ops
= {
1010 struct net_proto_family inet_family_ops
= {
1016 #ifdef CONFIG_PROC_FS
1017 #ifdef CONFIG_INET_RARP
1018 static struct proc_dir_entry proc_net_rarp
= {
1019 PROC_NET_RARP
, 4, "rarp",
1020 S_IFREG
| S_IRUGO
, 1, 0, 0,
1021 0, &proc_net_inode_operations
,
1025 static struct proc_dir_entry proc_net_raw
= {
1026 PROC_NET_RAW
, 3, "raw",
1027 S_IFREG
| S_IRUGO
, 1, 0, 0,
1028 0, &proc_net_inode_operations
,
1031 static struct proc_dir_entry proc_net_netstat
= {
1032 PROC_NET_NETSTAT
, 7, "netstat",
1033 S_IFREG
| S_IRUGO
, 1, 0, 0,
1034 0, &proc_net_inode_operations
,
1037 static struct proc_dir_entry proc_net_snmp
= {
1038 PROC_NET_SNMP
, 4, "snmp",
1039 S_IFREG
| S_IRUGO
, 1, 0, 0,
1040 0, &proc_net_inode_operations
,
1043 static struct proc_dir_entry proc_net_sockstat
= {
1044 PROC_NET_SOCKSTAT
, 8, "sockstat",
1045 S_IFREG
| S_IRUGO
, 1, 0, 0,
1046 0, &proc_net_inode_operations
,
1049 static struct proc_dir_entry proc_net_tcp
= {
1050 PROC_NET_TCP
, 3, "tcp",
1051 S_IFREG
| S_IRUGO
, 1, 0, 0,
1052 0, &proc_net_inode_operations
,
1055 static struct proc_dir_entry proc_net_udp
= {
1056 PROC_NET_UDP
, 3, "udp",
1057 S_IFREG
| S_IRUGO
, 1, 0, 0,
1058 0, &proc_net_inode_operations
,
1061 #endif /* CONFIG_PROC_FS */
1063 extern void tcp_init(void);
1064 extern void tcp_v4_init(struct net_proto_family
*);
1068 * Called by socket.c on kernel startup.
1071 __initfunc(void inet_proto_init(struct net_proto
*pro
))
1073 struct sk_buff
*dummy_skb
;
1074 struct inet_protocol
*p
;
1076 printk(KERN_INFO
"NET4: Linux TCP/IP 1.0 for NET4.0\n");
1078 if (sizeof(struct inet_skb_parm
) > sizeof(dummy_skb
->cb
))
1080 printk(KERN_CRIT
"inet_proto_init: panic\n");
1085 * Tell SOCKET that we are alive...
1088 (void) sock_register(&inet_family_ops
);
1091 * Add all the protocols.
1094 printk(KERN_INFO
"IP Protocols: ");
1095 for(p
= inet_protocol_base
; p
!= NULL
;)
1097 struct inet_protocol
*tmp
= (struct inet_protocol
*) p
->next
;
1098 inet_add_protocol(p
);
1099 printk("%s%s",p
->name
,tmp
?", ":"\n");
1104 * Set the ARP module up
1110 * Set the IP module up
1115 tcp_v4_init(&inet_family_ops
);
1117 /* Setup TCP slab cache for open requests. */
1122 * Set the ICMP layer up
1125 icmp_init(&inet_family_ops
);
1127 /* I wish inet_add_protocol had no constructor hook...
1128 I had to move IPIP from net/ipv4/protocol.c :-( --ANK
1130 #ifdef CONFIG_NET_IPIP
1133 #ifdef CONFIG_NET_IPGRE
1138 * Set the firewalling up
1140 #if defined(CONFIG_IP_FIREWALL)
1144 #ifdef CONFIG_IP_MASQUERADE
1149 * Initialise the multicast router
1151 #if defined(CONFIG_IP_MROUTE)
1155 #ifdef CONFIG_INET_RARP
1156 rarp_ioctl_hook
= rarp_ioctl
;
1159 * Create all the /proc entries.
1162 #ifdef CONFIG_PROC_FS
1163 #ifdef CONFIG_INET_RARP
1164 proc_net_register(&proc_net_rarp
);
1166 proc_net_register(&proc_net_raw
);
1167 proc_net_register(&proc_net_snmp
);
1168 proc_net_register(&proc_net_netstat
);
1169 proc_net_register(&proc_net_sockstat
);
1170 proc_net_register(&proc_net_tcp
);
1171 proc_net_register(&proc_net_udp
);
1172 #endif /* CONFIG_PROC_FS */