1 /* 2 * INET An implementation of the TCP/IP protocol suite for the LINUX 3 * operating system. INET is implemented using the BSD Socket 4 * interface as the means of communication with the user level. 5 * 6 * This file implements the various access functions for the 7 * PROC file system. It is mainly used for debugging and 8 * statistics. 9 * 10 * Version: @(#)proc.c 1.0.5 05/27/93 11 * 12 * Authors: Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG> 13 * Gerald J. Heim, <heim@peanuts.informatik.uni-tuebingen.de> 14 * Fred Baumgarten, <dc6iq@insu1.etec.uni-karlsruhe.de> 15 * 16 * Fixes: 17 * Alan Cox : UDP sockets show the rxqueue/txqueue 18 * using hint flag for the netinfo. 19 * Pauline Middelink : Pidentd support 20 * 21 * To Do: 22 * Put the creating userid in the proc/net/... files. This will 23 * allow us to write an RFC931 daemon for Linux 24 * 25 * This program is free software; you can redistribute it and/or 26 * modify it under the terms of the GNU General Public License 27 * as published by the Free Software Foundation; either version 28 * 2 of the License, or (at your option) any later version. 29 */ 30 #include <asm/system.h>
31 #include <linux/autoconf.h>
32 #include <linux/sched.h>
33 #include <linux/socket.h>
34 #include <linux/net.h>
35 #include <linux/un.h>
36 #include <linux/in.h>
37 #include <linux/param.h>
38 #include "inet.h"
39 #include "dev.h"
40 #include "ip.h"
41 #include "protocol.h"
42 #include "tcp.h"
43 #include "udp.h"
44 #include "skbuff.h"
45 #include "sock.h"
46 #include "raw.h"
47
48 /* 49 * Get__netinfo returns the length of that string. 50 * 51 * KNOWN BUGS 52 * As in get_unix_netinfo, the buffer might be too small. If this 53 * happens, get__netinfo returns only part of the available infos. 54 */ 55 staticint 56 get__netinfo(structproto *pro, char *buffer, intformat)
/* */ 57 { 58 structsock **s_array;
59 structsock *sp;
60 char *pos=buffer;
61 inti;
62 inttimer_active;
63 unsignedlongdest, src;
64 unsignedshortdestp, srcp;
65
66 s_array = pro->sock_array;
67 pos+=sprintf(pos, "sl local_address rem_address st tx_queue rx_queue tr tm->when uid\n");
68 for(i = 0; i < SOCK_ARRAY_SIZE; i++) { 69 sp = s_array[i];
70 while(sp != NULL) { 71 dest = sp->daddr;
72 src = sp->saddr;
73 destp = sp->dummy_th.dest;
74 srcp = sp->dummy_th.source;
75
76 /* Since we are Little Endian we need to swap the bytes :-( */ 77 destp = ntohs(destp);
78 srcp = ntohs(srcp);
79
80 timer_active = del_timer(&sp->timer);
81 if (!timer_active)
82 sp->timer.expires = 0;
83 pos+=sprintf(pos, "%2d: %08lX:%04X %08lX:%04X %02X %08lX:%08lX %02X:%08lX %08X %d\n",
84 i, src, srcp, dest, destp, sp->state,
85 format==0?sp->send_seq-sp->rcv_ack_seq:sp->rmem_alloc,
86 format==0?sp->acked_seq-sp->copied_seq:sp->wmem_alloc,
87 timer_active, sp->timer.expires, (unsigned) sp->retransmits,
88 SOCK_INODE(sp->socket)->i_uid);
89 if (timer_active)
90 add_timer(&sp->timer);
91
92 /* Is place in buffer too rare? then abort. */ 93 if (pos > buffer+PAGE_SIZE-80) { 94 printk("oops, too many %s sockets for netinfo.\n",
95 pro->name);
96 return(strlen(buffer));
97 } 98
99 /* 100 * All sockets with (port mod SOCK_ARRAY_SIZE) = i 101 * are kept in sock_array[i], so we must follow the 102 * 'next' link to get them all. 103 */ 104 sp = sp->next;
105 } 106 } 107 return(strlen(buffer));
108 } 109
110
111 inttcp_get_info(char *buffer)
/* */ 112 { 113 returnget__netinfo(&tcp_prot, buffer,0);
114 } 115
116
117 intudp_get_info(char *buffer)
/* */ 118 { 119 returnget__netinfo(&udp_prot, buffer,1);
120 } 121
122
123 intraw_get_info(char *buffer)
/* */ 124 { 125 returnget__netinfo(&raw_prot, buffer,1);
126 }