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.90 1999/05/29 04:30:38 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
)
153 /* Next, the error queue. */
154 while((skb
= skb_dequeue(&sk
->error_queue
)) != NULL
)
157 /* It is _impossible_ for the backlog to contain anything
158 * when we get here. All user references to this socket
159 * have gone away, only the net layer knows can touch it.
163 static __inline__
void kill_sk_now(struct sock
*sk
)
165 /* No longer exists. */
166 del_from_prot_sklist(sk
);
168 /* Remove from protocol hash chains. */
169 sk
->prot
->unhash(sk
);
173 dst_release(sk
->dst_cache
);
177 static __inline__
void kill_sk_later(struct sock
*sk
)
179 /* this should never happen. */
180 /* actually it can if an ack has just been sent. */
182 * It's more normal than that...
183 * It can happen because a skb is still in the device queues
187 NETDEBUG(printk(KERN_DEBUG
"Socket destroy delayed (r=%d w=%d)\n",
188 atomic_read(&sk
->rmem_alloc
),
189 atomic_read(&sk
->wmem_alloc
)));
194 net_reset_timer(sk
, TIME_DESTROY
, SOCK_DESTROY_TIME
);
197 /* Callers must hold the BH spinlock.
199 * At this point, there should be no process reference to this
200 * socket, and thus no user references at all. Therefore we
201 * can assume the socket waitqueue is inactive and nobody will
202 * try to jump onto it.
204 void destroy_sock(struct sock
*sk
)
206 /* Now we can no longer get new packets or once the
207 * timers are killed, send them.
209 net_delete_timer(sk
);
211 if (sk
->prot
->destroy
)
212 sk
->prot
->destroy(sk
);
216 /* Now if everything is gone we can free the socket
217 * structure, otherwise we need to keep it around until
218 * everything is gone.
220 if (atomic_read(&sk
->rmem_alloc
) == 0 && atomic_read(&sk
->wmem_alloc
) == 0)
227 * The routines beyond this point handle the behaviour of an AF_INET
228 * socket object. Mostly it punts to the subprotocols of IP to do
234 * Set socket options on an inet socket.
237 int inet_setsockopt(struct socket
*sock
, int level
, int optname
,
238 char *optval
, int optlen
)
240 struct sock
*sk
=sock
->sk
;
241 if (sk
->prot
->setsockopt
==NULL
)
243 return sk
->prot
->setsockopt(sk
,level
,optname
,optval
,optlen
);
247 * Get a socket option on an AF_INET socket.
249 * FIX: POSIX 1003.1g is very ambiguous here. It states that
250 * asynchronous errors should be reported by getsockopt. We assume
251 * this means if you specify SO_ERROR (otherwise whats the point of it).
254 int inet_getsockopt(struct socket
*sock
, int level
, int optname
,
255 char *optval
, int *optlen
)
257 struct sock
*sk
=sock
->sk
;
258 if (sk
->prot
->getsockopt
==NULL
)
260 return sk
->prot
->getsockopt(sk
,level
,optname
,optval
,optlen
);
264 * Automatically bind an unbound socket.
267 static int inet_autobind(struct sock
*sk
)
269 /* We may need to bind the socket. */
271 sk
->num
= sk
->prot
->good_socknum();
274 sk
->sport
= htons(sk
->num
);
276 add_to_prot_sklist(sk
);
281 /* Listening INET sockets never sleep to wait for memory, so
282 * it is completely silly to wake them up on queue space
283 * available events. So we hook them up to this dummy callback.
285 static void inet_listen_write_space(struct sock
*sk
)
290 * Move a socket into listening state.
293 int inet_listen(struct socket
*sock
, int backlog
)
295 struct sock
*sk
= sock
->sk
;
297 if (sock
->state
!= SS_UNCONNECTED
|| sock
->type
!= SOCK_STREAM
)
300 if (inet_autobind(sk
) != 0)
303 /* We might as well re use these. */
304 if ((unsigned) backlog
== 0) /* BSDism */
306 if ((unsigned) backlog
> SOMAXCONN
)
308 sk
->max_ack_backlog
= backlog
;
309 if (sk
->state
!= TCP_LISTEN
) {
311 sk
->state
= TCP_LISTEN
;
312 dst_release(xchg(&sk
->dst_cache
, NULL
));
313 sk
->prot
->rehash(sk
);
314 add_to_prot_sklist(sk
);
315 sk
->write_space
= inet_listen_write_space
;
317 sk
->socket
->flags
|= SO_ACCEPTCON
;
322 * Create an inet socket.
324 * FIXME: Gcc would generate much better code if we set the parameters
325 * up in in-memory structure order. Gcc68K even more so
328 static int inet_create(struct socket
*sock
, int protocol
)
334 if (sock
->type
== SOCK_PACKET
) {
336 if (net_families
[PF_PACKET
]==NULL
)
338 #if defined(CONFIG_KMOD) && defined(CONFIG_PACKET_MODULE)
339 char module_name
[30];
340 sprintf(module_name
,"net-pf-%d", PF_PACKET
);
341 request_module(module_name
);
342 if (net_families
[PF_PACKET
] == NULL
)
344 return -ESOCKTNOSUPPORT
;
347 printk(KERN_INFO
"%s uses obsolete (PF_INET,SOCK_PACKET)\n", current
->comm
);
348 return net_families
[PF_PACKET
]->create(sock
, protocol
);
351 sock
->state
= SS_UNCONNECTED
;
352 sk
= sk_alloc(PF_INET
, GFP_KERNEL
, 1);
356 switch (sock
->type
) {
358 if (protocol
&& protocol
!= IPPROTO_TCP
)
359 goto free_and_noproto
;
360 protocol
= IPPROTO_TCP
;
361 if (ipv4_config
.no_pmtu_disc
)
362 sk
->ip_pmtudisc
= IP_PMTUDISC_DONT
;
364 sk
->ip_pmtudisc
= IP_PMTUDISC_WANT
;
366 sock
->ops
= &inet_stream_ops
;
369 goto free_and_badtype
;
371 if (protocol
&& protocol
!= IPPROTO_UDP
)
372 goto free_and_noproto
;
373 protocol
= IPPROTO_UDP
;
374 sk
->no_check
= UDP_CSUM_DEFAULT
;
375 sk
->ip_pmtudisc
= IP_PMTUDISC_DONT
;
377 sock
->ops
= &inet_dgram_ops
;
380 if (!capable(CAP_NET_RAW
))
381 goto free_and_badperm
;
383 goto free_and_noproto
;
386 sk
->ip_pmtudisc
= IP_PMTUDISC_DONT
;
388 sock
->ops
= &inet_dgram_ops
;
389 if (protocol
== IPPROTO_RAW
)
393 goto free_and_badtype
;
396 sock_init_data(sock
,sk
);
401 #ifdef CONFIG_TCP_NAGLE_OFF
404 sk
->family
= PF_INET
;
405 sk
->protocol
= protocol
;
408 sk
->backlog_rcv
= prot
->backlog_rcv
;
410 sk
->timer
.data
= (unsigned long)sk
;
411 sk
->timer
.function
= &net_timer
;
413 sk
->ip_ttl
=ip_statistics
.IpDefaultTTL
;
421 /* It assumes that any protocol which allows
422 * the user to assign a number at socket
423 * creation time automatically
426 sk
->sport
= htons(sk
->num
);
428 /* Add to protocol hash chains. */
430 add_to_prot_sklist(sk
);
433 if (sk
->prot
->init
) {
434 int err
= sk
->prot
->init(sk
);
444 return -ESOCKTNOSUPPORT
;
452 return -EPROTONOSUPPORT
;
460 * The peer socket should always be NULL (or else). When we call this
461 * function we are destroying the object and from then on nobody
462 * should refer to it.
465 int inet_release(struct socket
*sock
, struct socket
*peersock
)
467 struct sock
*sk
= sock
->sk
;
472 /* Begin closedown and wake up sleepers. */
473 if (sock
->state
!= SS_UNCONNECTED
)
474 sock
->state
= SS_DISCONNECTING
;
475 sk
->state_change(sk
);
477 /* Applications forget to leave groups before exiting */
478 ip_mc_drop_socket(sk
);
480 /* If linger is set, we don't return until the close
481 * is complete. Otherwise we return immediately. The
482 * actually closing is done the same either way.
484 * If the close is due to the process exiting, we never
488 if (sk
->linger
&& !(current
->flags
& PF_EXITING
)) {
489 timeout
= MAX_SCHEDULE_TIMEOUT
;
491 /* XXX This makes no sense whatsoever... -DaveM */
493 timeout
= HZ
*sk
->lingertime
;
497 sk
->prot
->close(sk
, timeout
);
502 static int inet_bind(struct socket
*sock
, struct sockaddr
*uaddr
, int addr_len
)
504 struct sockaddr_in
*addr
=(struct sockaddr_in
*)uaddr
;
505 struct sock
*sk
=sock
->sk
;
509 /* If the socket has its own bind function then use it. (RAW) */
511 return sk
->prot
->bind(sk
, uaddr
, addr_len
);
513 /* Check these errors (active socket, bad address length, double bind). */
514 if ((sk
->state
!= TCP_CLOSE
) ||
515 (addr_len
< sizeof(struct sockaddr_in
)) ||
519 chk_addr_ret
= inet_addr_type(addr
->sin_addr
.s_addr
);
520 if (addr
->sin_addr
.s_addr
!= 0 && chk_addr_ret
!= RTN_LOCAL
&&
521 chk_addr_ret
!= RTN_MULTICAST
&& chk_addr_ret
!= RTN_BROADCAST
) {
522 #ifdef CONFIG_IP_TRANSPARENT_PROXY
523 /* Superuser may bind to any address to allow transparent proxying. */
524 if(chk_addr_ret
!= RTN_UNICAST
|| !capable(CAP_NET_ADMIN
))
526 return -EADDRNOTAVAIL
; /* Source address MUST be ours! */
529 /* We keep a pair of addresses. rcv_saddr is the one
530 * used by hash lookups, and saddr is used for transmit.
532 * In the BSD API these are the same except where it
533 * would be illegal to use them (multicast/broadcast) in
534 * which case the sending device address is used.
536 sk
->rcv_saddr
= sk
->saddr
= addr
->sin_addr
.s_addr
;
537 if(chk_addr_ret
== RTN_MULTICAST
|| chk_addr_ret
== RTN_BROADCAST
)
538 sk
->saddr
= 0; /* Use device */
540 snum
= ntohs(addr
->sin_port
);
541 #ifdef CONFIG_IP_MASQUERADE
542 /* The kernel masquerader needs some ports. */
543 if((snum
>= PORT_MASQ_BEGIN
) && (snum
<= PORT_MASQ_END
))
547 snum
= sk
->prot
->good_socknum();
548 if (snum
< PROT_SOCK
&& !capable(CAP_NET_BIND_SERVICE
))
551 /* Make sure we are allowed to bind here. */
552 if(sk
->prot
->verify_bind(sk
, snum
))
556 sk
->sport
= htons(snum
);
559 sk
->prot
->rehash(sk
);
560 add_to_prot_sklist(sk
);
561 dst_release(sk
->dst_cache
);
566 int inet_dgram_connect(struct socket
*sock
, struct sockaddr
* uaddr
,
567 int addr_len
, int flags
)
569 struct sock
*sk
=sock
->sk
;
572 if (inet_autobind(sk
) != 0)
574 if (sk
->prot
->connect
== NULL
)
576 err
= sk
->prot
->connect(sk
, (struct sockaddr
*)uaddr
, addr_len
);
582 static void inet_wait_for_connect(struct sock
*sk
)
584 DECLARE_WAITQUEUE(wait
, current
);
586 add_wait_queue(sk
->sleep
, &wait
);
587 current
->state
= TASK_INTERRUPTIBLE
;
588 while (sk
->state
== TCP_SYN_SENT
|| sk
->state
== TCP_SYN_RECV
) {
589 if (signal_pending(current
))
594 current
->state
= TASK_INTERRUPTIBLE
;
596 current
->state
= TASK_RUNNING
;
597 remove_wait_queue(sk
->sleep
, &wait
);
601 * Connect to a remote host. There is regrettably still a little
602 * TCP 'magic' in here.
605 int inet_stream_connect(struct socket
*sock
, struct sockaddr
* uaddr
,
606 int addr_len
, int flags
)
608 struct sock
*sk
=sock
->sk
;
611 if(sock
->state
!= SS_UNCONNECTED
&& sock
->state
!= SS_CONNECTING
) {
612 if(sock
->state
== SS_CONNECTED
)
617 if(sock
->state
== SS_CONNECTING
) {
618 /* Note: tcp_connected contains SYN_RECV, which may cause
619 bogus results here. -AK */
620 if(tcp_connected(sk
->state
)) {
621 sock
->state
= SS_CONNECTED
;
624 if (sk
->zapped
|| sk
->err
)
626 if (flags
& O_NONBLOCK
)
629 /* We may need to bind the socket. */
630 if (inet_autobind(sk
) != 0)
632 if (sk
->prot
->connect
== NULL
)
634 err
= sk
->prot
->connect(sk
, uaddr
, addr_len
);
635 /* Note: there is a theoretical race here when an wake up
636 occurred before inet_wait_for_connect is entered. In 2.3
637 the wait queue setup should be moved before the low level
641 sock
->state
= SS_CONNECTING
;
644 if (sk
->state
> TCP_FIN_WAIT2
&& sock
->state
== SS_CONNECTING
)
647 if (sk
->state
!= TCP_ESTABLISHED
&& (flags
& O_NONBLOCK
))
648 return (-EINPROGRESS
);
650 if (sk
->state
== TCP_SYN_SENT
|| sk
->state
== TCP_SYN_RECV
) {
651 inet_wait_for_connect(sk
);
652 if (signal_pending(current
))
656 sock
->state
= SS_CONNECTED
;
657 if ((sk
->state
!= TCP_ESTABLISHED
) && sk
->err
)
662 /* This is ugly but needed to fix a race in the ICMP error handler */
663 if (sk
->zapped
&& sk
->state
!= TCP_CLOSE
) {
665 tcp_set_state(sk
, TCP_CLOSE
);
669 sock
->state
= SS_UNCONNECTED
;
670 return sock_error(sk
);
674 * Accept a pending connection. The TCP layer now gives BSD semantics.
677 int inet_accept(struct socket
*sock
, struct socket
*newsock
, int flags
)
679 struct sock
*sk1
= sock
->sk
, *sk2
;
680 struct sock
*newsk
= newsock
->sk
;
683 if (sock
->state
!= SS_UNCONNECTED
|| !(sock
->flags
& SO_ACCEPTCON
))
687 if (sk1
->prot
->accept
== NULL
)
690 if((sk2
= sk1
->prot
->accept(sk1
,flags
)) == NULL
)
694 * We've been passed an extra socket.
695 * We need to free it up because the tcp module creates
696 * its own when it accepts one.
698 sk2
->sleep
= newsk
->sleep
;
701 sk2
->socket
= newsock
;
702 newsk
->socket
= NULL
;
704 if (flags
& O_NONBLOCK
)
705 goto do_half_success
;
707 if(sk2
->state
== TCP_ESTABLISHED
)
708 goto do_full_success
;
712 if (sk2
->state
== TCP_CLOSE
)
713 goto do_bad_connection
;
716 newsock
->state
= SS_CONNECTED
;
724 err
= sock_error(sk2
);
730 newsk
->socket
= newsock
;
734 err
= sock_error(sk1
);
741 * This does both peername and sockname.
744 static int inet_getname(struct socket
*sock
, struct sockaddr
*uaddr
,
745 int *uaddr_len
, int peer
)
747 struct sock
*sk
= sock
->sk
;
748 struct sockaddr_in
*sin
= (struct sockaddr_in
*)uaddr
;
750 sin
->sin_family
= AF_INET
;
752 if (!tcp_connected(sk
->state
))
754 sin
->sin_port
= sk
->dport
;
755 sin
->sin_addr
.s_addr
= sk
->daddr
;
757 __u32 addr
= sk
->rcv_saddr
;
760 sin
->sin_port
= sk
->sport
;
761 sin
->sin_addr
.s_addr
= addr
;
763 *uaddr_len
= sizeof(*sin
);
769 int inet_recvmsg(struct socket
*sock
, struct msghdr
*msg
, int size
,
770 int flags
, struct scm_cookie
*scm
)
772 struct sock
*sk
= sock
->sk
;
776 if (sock
->flags
& SO_ACCEPTCON
)
778 if (sk
->prot
->recvmsg
== NULL
)
780 /* We may need to bind the socket. */
781 if (inet_autobind(sk
) != 0)
783 err
= sk
->prot
->recvmsg(sk
, msg
, size
, flags
&MSG_DONTWAIT
,
784 flags
&~MSG_DONTWAIT
, &addr_len
);
786 msg
->msg_namelen
= addr_len
;
791 int inet_sendmsg(struct socket
*sock
, struct msghdr
*msg
, int size
,
792 struct scm_cookie
*scm
)
794 struct sock
*sk
= sock
->sk
;
796 if (sk
->shutdown
& SEND_SHUTDOWN
) {
797 if (!(msg
->msg_flags
&MSG_NOSIGNAL
))
798 send_sig(SIGPIPE
, current
, 1);
801 if (sk
->prot
->sendmsg
== NULL
)
804 return sock_error(sk
);
806 /* We may need to bind the socket. */
807 if(inet_autobind(sk
) != 0)
810 return sk
->prot
->sendmsg(sk
, msg
, size
);
814 int inet_shutdown(struct socket
*sock
, int how
)
816 struct sock
*sk
= sock
->sk
;
818 /* This should really check to make sure
819 * the socket is a TCP socket. (WHY AC...)
821 how
++; /* maps 0->1 has the advantage of making bit 1 rcvs and
824 if ((how
& ~SHUTDOWN_MASK
) || how
==0) /* MAXINT->0 */
826 if (sock
->state
== SS_CONNECTING
&& sk
->state
== TCP_ESTABLISHED
)
827 sock
->state
= SS_CONNECTED
;
828 if (!sk
|| !tcp_connected(sk
->state
))
831 if (sk
->prot
->shutdown
)
832 sk
->prot
->shutdown(sk
, how
);
833 /* Wake up anyone sleeping in poll. */
834 sk
->state_change(sk
);
839 unsigned int inet_poll(struct file
* file
, struct socket
*sock
, poll_table
*wait
)
841 struct sock
*sk
= sock
->sk
;
843 if (sk
->prot
->poll
== NULL
)
845 return sk
->prot
->poll(file
, sock
, wait
);
849 * ioctl() calls you can issue on an INET socket. Most of these are
850 * device configuration and stuff and very rarely used. Some ioctls
851 * pass on to the socket itself.
853 * NOTE: I like the idea of a module for the config stuff. ie ifconfig
854 * loads the devconfigure module does its configuring and unloads it.
855 * There's a good 20K of config code hanging around the kernel.
858 static int inet_ioctl(struct socket
*sock
, unsigned int cmd
, unsigned long arg
)
860 struct sock
*sk
= sock
->sk
;
868 err
= get_user(pid
, (int *) arg
);
871 if (current
->pid
!= pid
&& current
->pgrp
!= -pid
&&
872 !capable(CAP_NET_ADMIN
))
878 return put_user(sk
->proc
, (int *)arg
);
880 if(sk
->stamp
.tv_sec
==0)
882 err
= copy_to_user((void *)arg
,&sk
->stamp
,sizeof(struct timeval
));
889 return(ip_rt_ioctl(cmd
,(void *) arg
));
893 return(arp_ioctl(cmd
,(void *) arg
));
898 if (rarp_ioctl_hook
== NULL
)
899 request_module("rarp");
901 if (rarp_ioctl_hook
!= NULL
)
902 return(rarp_ioctl_hook(cmd
,(void *) arg
));
914 return(devinet_ioctl(cmd
,(void *) arg
));
918 return(br_ioctl(cmd
,(void *) arg
));
926 return(dlci_ioctl(cmd
, (void *) arg
));
929 #ifdef CONFIG_DLCI_MODULE
932 if (dlci_ioctl_hook
== NULL
)
933 request_module("dlci");
937 return((*dlci_ioctl_hook
)(cmd
, (void *) arg
));
942 if ((cmd
>= SIOCDEVPRIVATE
) &&
943 (cmd
<= (SIOCDEVPRIVATE
+ 15)))
944 return(dev_ioctl(cmd
,(void *) arg
));
946 #ifdef CONFIG_NET_RADIO
947 if((cmd
>= SIOCIWFIRST
) && (cmd
<= SIOCIWLAST
))
948 return(dev_ioctl(cmd
,(void *) arg
));
951 if (sk
->prot
->ioctl
==NULL
|| (err
=sk
->prot
->ioctl(sk
, cmd
, arg
))==-ENOIOCTLCMD
)
952 return(dev_ioctl(cmd
,(void *) arg
));
959 struct proto_ops inet_stream_ops
= {
980 struct proto_ops inet_dgram_ops
= {
1001 struct net_proto_family inet_family_ops
= {
1007 #ifdef CONFIG_PROC_FS
1008 #ifdef CONFIG_INET_RARP
1009 static struct proc_dir_entry proc_net_rarp
= {
1010 PROC_NET_RARP
, 4, "rarp",
1011 S_IFREG
| S_IRUGO
, 1, 0, 0,
1012 0, &proc_net_inode_operations
,
1016 static struct proc_dir_entry proc_net_raw
= {
1017 PROC_NET_RAW
, 3, "raw",
1018 S_IFREG
| S_IRUGO
, 1, 0, 0,
1019 0, &proc_net_inode_operations
,
1022 static struct proc_dir_entry proc_net_netstat
= {
1023 PROC_NET_NETSTAT
, 7, "netstat",
1024 S_IFREG
| S_IRUGO
, 1, 0, 0,
1025 0, &proc_net_inode_operations
,
1028 static struct proc_dir_entry proc_net_snmp
= {
1029 PROC_NET_SNMP
, 4, "snmp",
1030 S_IFREG
| S_IRUGO
, 1, 0, 0,
1031 0, &proc_net_inode_operations
,
1034 static struct proc_dir_entry proc_net_sockstat
= {
1035 PROC_NET_SOCKSTAT
, 8, "sockstat",
1036 S_IFREG
| S_IRUGO
, 1, 0, 0,
1037 0, &proc_net_inode_operations
,
1040 static struct proc_dir_entry proc_net_tcp
= {
1041 PROC_NET_TCP
, 3, "tcp",
1042 S_IFREG
| S_IRUGO
, 1, 0, 0,
1043 0, &proc_net_inode_operations
,
1046 static struct proc_dir_entry proc_net_udp
= {
1047 PROC_NET_UDP
, 3, "udp",
1048 S_IFREG
| S_IRUGO
, 1, 0, 0,
1049 0, &proc_net_inode_operations
,
1052 #endif /* CONFIG_PROC_FS */
1054 extern void tcp_init(void);
1055 extern void tcp_v4_init(struct net_proto_family
*);
1059 * Called by socket.c on kernel startup.
1062 __initfunc(void inet_proto_init(struct net_proto
*pro
))
1064 struct sk_buff
*dummy_skb
;
1065 struct inet_protocol
*p
;
1067 printk(KERN_INFO
"NET4: Linux TCP/IP 1.0 for NET4.0\n");
1069 if (sizeof(struct inet_skb_parm
) > sizeof(dummy_skb
->cb
))
1071 printk(KERN_CRIT
"inet_proto_init: panic\n");
1076 * Tell SOCKET that we are alive...
1079 (void) sock_register(&inet_family_ops
);
1082 * Add all the protocols.
1085 printk(KERN_INFO
"IP Protocols: ");
1086 for(p
= inet_protocol_base
; p
!= NULL
;)
1088 struct inet_protocol
*tmp
= (struct inet_protocol
*) p
->next
;
1089 inet_add_protocol(p
);
1090 printk("%s%s",p
->name
,tmp
?", ":"\n");
1095 * Set the ARP module up
1101 * Set the IP module up
1106 tcp_v4_init(&inet_family_ops
);
1108 /* Setup TCP slab cache for open requests. */
1113 * Set the ICMP layer up
1116 icmp_init(&inet_family_ops
);
1118 /* I wish inet_add_protocol had no constructor hook...
1119 I had to move IPIP from net/ipv4/protocol.c :-( --ANK
1121 #ifdef CONFIG_NET_IPIP
1124 #ifdef CONFIG_NET_IPGRE
1129 * Set the firewalling up
1131 #if defined(CONFIG_IP_FIREWALL)
1135 #ifdef CONFIG_IP_MASQUERADE
1140 * Initialise the multicast router
1142 #if defined(CONFIG_IP_MROUTE)
1146 #ifdef CONFIG_INET_RARP
1147 rarp_ioctl_hook
= rarp_ioctl
;
1150 * Create all the /proc entries.
1153 #ifdef CONFIG_PROC_FS
1154 #ifdef CONFIG_INET_RARP
1155 proc_net_register(&proc_net_rarp
);
1157 proc_net_register(&proc_net_raw
);
1158 proc_net_register(&proc_net_snmp
);
1159 proc_net_register(&proc_net_netstat
);
1160 proc_net_register(&proc_net_sockstat
);
1161 proc_net_register(&proc_net_tcp
);
1162 proc_net_register(&proc_net_udp
);
1163 #endif /* CONFIG_PROC_FS */