Skip to contentSkip to conversation

New: Established connections not displayed in /proc/tcp/netstat

Bugme-new New Andrew Morton 3 participants 3 messages Mar 8, 2007 – Mar 9, 2007

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

Begin forwarded message:

Date: Thu, 8 Mar 2007 07:53:57 -0800
From: [email protected]
To: [email protected]
Subject: [Bugme-new] [Bug 8151] New: Established connections not displayed in /proc/tcp/netstat

http://bugzilla.kernel.org/show_bug.cgi?id=8151

Summary: Established connections not displayed in
/proc/tcp/netstat
Kernel Version: 2.6.17-rt7-default #3 PREEMPT
Status: NEW
Severity: normal
Owner: [email protected]
Submitter: [email protected]
CC: [email protected]

Most recent kernel where this bug did *NOT* occur: Unknown

Distribution: SUSE 10 Pro

Hardware Environment: Intel(R) Pentium(R) 4 CPU 2.80GHz, 32 bit, 512 Megs of RAM

Software Environment: SUSE 10, 2.6.17-rt7-default with ingo molnar RT patch

Problem Description:

Established tcp network connections are not shown in /proc/net/tcp (not displayed in netstat).

I began to notice this when I would use netstat to display all established connections. There were a few connections not shown as ESTABLISHED by netstat, yet my application did not report a connection broken with the remote device. I logged into the remote device and observed the connection was ESTABLISHED on the remote side. In addition, I verified the transfer of data to the remote device. I searched through the proc file system to find out more info and it seems that my application still held the socket file descriptor as opened.

#### LOCAL MACHINE WITH BUG

# 10.1.2.71 is IP of remote device note connection not established

local:/ # netstat -a | grep 10.1.2.71

## NOTE IP of local device

local:/ # ifconfig eth1

eth1 Link encap:Ethernet HWaddr 00:03:2D:09:0E:6F

          inet addr:10.1.2.10  Bcast:10.1.2.255  Mask:255.255.255.0

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          RX packets:558434 errors:0 dropped:0 overruns:0 frame:0

          TX packets:264478 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:1000

          RX bytes:37082257 (35.3 Mb)  TX bytes:19489061 (18.5 Mb)

          Interrupt:18

# ##telnet into remote machine

local:/ # telnet 10.1.2.71

Trying 10.1.2.71...

Connected to 10.1.2.71.

Escape character is '^]'.

MontaVista(R) Linux(R) Professional Edition 3.1

Linux/ppc 2.4.20_mvl31-405gp_eval

(none) login: root

Password:

Linux (none) 2.4.20_mvl31-405gp_eval #474 Tue Dec 27 16:37:25 PST 2005 ppc unknown

MontaVista(R) Linux(R) Professional Edition 3.1

BusyBox v0.60.3 (2004.01.09-22:55+0000) Built-in shell (ash)

Enter 'help' for a list of built-in commands.

######## Remote machine. Note connection established on port 1400 with local machine

# netstat -a | grep 10.1.2.10

tcp 0 0 10.1.2.71:telnet 10.1.2.10:51555 ESTABLISHED

tcp 0 0 10.1.2.71:1400 10.1.2.10:60380 ESTABLISHED

###### Back on LOCAL machine with bug

### Note established connection to IP 10.1.2.71 on port 1400 not shown. However, other established connections shown to other devices running the same remote server software.

local:/proc/2774/fd # grep 0A02010A /proc/net/tcp | more

64: 0A02010A:EBDC 4702010A:0578 01 00000000:00000000 00:00000000 00000000
0 0 7477 1 d8ba1980 201 40 10 2 100

70: 0A02010A:A547 4802010A:0578 01 00000000:00000000 00:00000000 00000000
0 0 7478 1 d8ba1400 201 40 10 2 100

#### Display open inodes

### I grep for the inode of the established connections from above. My application will open the sockets to the remote devices sequentially.

ml_alc10:/proc/2774/fd # ls -l | grep socket | grep 747[0-9]

lrwx------ 1 root root 64 Mar 7 10:37 154 -> socket:[7471]

lrwx------ 1 root root 64 Mar 7 10:37 155 -> socket:[7472]

lrwx------ 1 root root 64 Mar 7 10:37 158 -> socket:[7473]

lrwx------ 1 root root 64 Mar 7 10:37 159 -> socket:[7474]

lrwx------ 1 root root 64 Mar 7 10:37 160 -> socket:[7475]

lrwx------ 1 root root 64 Mar 7 10:37 161 -> socket:[7476]

lrwx------ 1 root root 64 Mar 7 10:37 162 -> socket:[7477]

lrwx------ 1 root root 64 Mar 7 10:37 163 -> socket:[7478]

lrwx------ 1 root root 64 Mar 7 10:37 164 -> socket:[7479]

## Check if socket inode 7479 exists in /proc/net/tcp

local:/proc/2774/fd # grep 7479 /proc/net/tcp | more

local:/proc/2774/fd # ls -l | grep 7479

lrwx------ 1 root root 64 Mar 7 10:37 164 -> socket:[7479]

local:/proc/2774/fd # grep 7479 /proc/net/tcp | more

local:/proc/2774/fd #

#### NOTE Very Strange behavior. The connection will intermittently be shown in /proc/net/tcp with the same local port number and inode. This leads me to believe that the connection persists throughout and that the kernel is failing to accurately display all established socket connections.

Please advise on how display all ESTABLISHED connections correctly.

Thanks.

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.

#1 lore raw

PATCH 1/1 procfs : reorder struct pid_dentry to save space on 64bit archs, and constify them

This patches changes the order of fields of struct pid_entry (file fs/proc/base.c) in order to avoid a hole on 64bit archs. (8 bytes saved per object)

It also changes all pid_entry arrays to be const qualified, to make clear they must not be modified.

Before (on x86_64) :

# size fs/proc/base.o
   text    data     bss     dec     hex filename
  15549    2192       0   17741    454d fs/proc/base.o

After :

# size fs/proc/base.o
   text    data     bss     dec     hex filename
  17229     176       0   17405    43fd fs/proc/base.o

Thats 336 bytes saved on kernel size on x86_64

 fs/proc/base.c |   53 +++++++++++++++++++++++------------------------
 1 file changed, 27 insertions(+), 26 deletions(-)
fs/proc/base.c +27 -26
index 01f7769..d71135b 100644
@@ -90,8 +90,8 @@ #include "internal.h"
 #define PROC_NUMBUF 13
 
 struct pid_entry {
-	int len;
 	char *name;
+	int len;
 	mode_t mode;
 	const struct inode_operations *iop;
 	const struct file_operations *fop;
@@ -99,8 +99,8 @@ struct pid_entry {
 };
 
 #define NOD(NAME, MODE, IOP, FOP, OP) {			\
-	.len  = sizeof(NAME) - 1,			\
 	.name = (NAME),					\
+	.len  = sizeof(NAME) - 1,			\
 	.mode = MODE,					\
 	.iop  = IOP,					\
 	.fop  = FOP,					\
@@ -1121,7 +1121,8 @@ static struct dentry_operations pid_dent
 
 /* Lookups */
 
-typedef struct dentry *instantiate_t(struct inode *, struct dentry *, struct task_struct *, void *);
+typedef struct dentry *instantiate_t(struct inode *, struct dentry *,
+				struct task_struct *, const void *);
 
 /*
  * Fill a directory entry.
@@ -1137,7 +1138,7 @@ typedef struct dentry *instantiate_t(str
  */
 static int proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
 	char *name, int len,
-	instantiate_t instantiate, struct task_struct *task, void *ptr)
+	instantiate_t instantiate, struct task_struct *task, const void *ptr)
 {
 	struct dentry *child, *dir = filp->f_path.dentry;
 	struct inode *inode;
@@ -1272,9 +1273,9 @@ static struct dentry_operations tid_fd_d
 };
 
 static struct dentry *proc_fd_instantiate(struct inode *dir,
-	struct dentry *dentry, struct task_struct *task, void *ptr)
+	struct dentry *dentry, struct task_struct *task, const void *ptr)
 {
-	unsigned fd = *(unsigned *)ptr;
+	unsigned fd = *(const unsigned *)ptr;
 	struct file *file;
 	struct files_struct *files;
  	struct inode *inode;
@@ -1422,9 +1423,9 @@ static const struct inode_operations pro
 };
 
 static struct dentry *proc_pident_instantiate(struct inode *dir,
-	struct dentry *dentry, struct task_struct *task, void *ptr)
+	struct dentry *dentry, struct task_struct *task, const void *ptr)
 {
-	struct pid_entry *p = ptr;
+	const struct pid_entry *p = ptr;
 	struct inode *inode;
 	struct proc_inode *ei;
 	struct dentry *error = ERR_PTR(-EINVAL);
@@ -1453,13 +1454,13 @@ out:
 
 static struct dentry *proc_pident_lookup(struct inode *dir, 
 					 struct dentry *dentry,
-					 struct pid_entry *ents,
+					 const struct pid_entry *ents,
 					 unsigned int nents)
 {
 	struct inode *inode;
 	struct dentry *error;
 	struct task_struct *task = get_proc_task(dir);
-	struct pid_entry *p, *last;
+	const struct pid_entry *p, *last;
 
 	error = ERR_PTR(-ENOENT);
 	inode = NULL;
@@ -1488,8 +1489,8 @@ out_no_task:
 	return error;
 }
 
-static int proc_pident_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
-	struct task_struct *task, struct pid_entry *p)
+static int proc_pident_fill_cache(struct file *filp, void *dirent,
+	filldir_t filldir, struct task_struct *task, const struct pid_entry *p)
 {
 	return proc_fill_cache(filp, dirent, filldir, p->name, p->len,
 				proc_pident_instantiate, task, p);
@@ -1497,14 +1498,14 @@ static int proc_pident_fill_cache(struct
 
 static int proc_pident_readdir(struct file *filp,
 		void *dirent, filldir_t filldir,
-		struct pid_entry *ents, unsigned int nents)
+		const struct pid_entry *ents, unsigned int nents)
 {
 	int i;
 	int pid;
 	struct dentry *dentry = filp->f_path.dentry;
 	struct inode *inode = dentry->d_inode;
 	struct task_struct *task = get_proc_task(inode);
-	struct pid_entry *p, *last;
+	const struct pid_entry *p, *last;
 	ino_t ino;
 	int ret;
 
@@ -1628,7 +1629,7 @@ static const struct file_operations proc
 	.write		= proc_pid_attr_write,
 };
 
-static struct pid_entry attr_dir_stuff[] = {
+static const struct pid_entry attr_dir_stuff[] = {
 	REG("current",    S_IRUGO|S_IWUGO, pid_attr),
 	REG("prev",       S_IRUGO,	   pid_attr),
 	REG("exec",       S_IRUGO|S_IWUGO, pid_attr),
@@ -1694,7 +1695,7 @@ static const struct inode_operations pro
  * that properly belong to the /proc filesystem, as they describe
  * describe something that is process related.
  */
-static struct pid_entry proc_base_stuff[] = {
+static const struct pid_entry proc_base_stuff[] = {
 	NOD("self", S_IFLNK|S_IRWXUGO,
 		&proc_self_inode_operations, NULL, {}),
 };
@@ -1723,9 +1724,9 @@ static struct dentry_operations proc_bas
 };
 
 static struct dentry *proc_base_instantiate(struct inode *dir,
-	struct dentry *dentry, struct task_struct *task, void *ptr)
+	struct dentry *dentry, struct task_struct *task, const void *ptr)
 {
-	struct pid_entry *p = ptr;
+	const struct pid_entry *p = ptr;
 	struct inode *inode;
 	struct proc_inode *ei;
 	struct dentry *error = ERR_PTR(-EINVAL);
@@ -1773,7 +1774,7 @@ static struct dentry *proc_base_lookup(s
 {
 	struct dentry *error;
 	struct task_struct *task = get_proc_task(dir);
-	struct pid_entry *p, *last;
+	const struct pid_entry *p, *last;
 
 	error = ERR_PTR(-ENOENT);
 
@@ -1799,8 +1800,8 @@ out_no_task:
 	return error;
 }
 
-static int proc_base_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
-	struct task_struct *task, struct pid_entry *p)
+static int proc_base_fill_cache(struct file *filp, void *dirent,
+	filldir_t filldir, struct task_struct *task, const struct pid_entry *p)
 {
 	return proc_fill_cache(filp, dirent, filldir, p->name, p->len,
 				proc_base_instantiate, task, p);
@@ -1837,7 +1838,7 @@ #endif
 static const struct file_operations proc_task_operations;
 static const struct inode_operations proc_task_inode_operations;
 
-static struct pid_entry tgid_base_stuff[] = {
+static const struct pid_entry tgid_base_stuff[] = {
 	DIR("task",       S_IRUGO|S_IXUGO, task),
 	DIR("fd",         S_IRUSR|S_IXUSR, fd),
 	INF("environ",    S_IRUSR, pid_environ),
@@ -1979,7 +1980,7 @@ out:
 
 static struct dentry *proc_pid_instantiate(struct inode *dir,
 					   struct dentry * dentry,
-					   struct task_struct *task, void *ptr)
+					   struct task_struct *task, const void *ptr)
 {
 	struct dentry *error = ERR_PTR(-ENOENT);
 	struct inode *inode;
@@ -2094,7 +2095,7 @@ int proc_pid_readdir(struct file * filp,
 		goto out_no_task;
 
 	for (; nr < ARRAY_SIZE(proc_base_stuff); filp->f_pos++, nr++) {
-		struct pid_entry *p = &proc_base_stuff[nr];
+		const struct pid_entry *p = &proc_base_stuff[nr];
 		if (proc_base_fill_cache(filp, dirent, filldir, reaper, p) < 0)
 			goto out;
 	}
@@ -2120,7 +2121,7 @@ out_no_task:
 /*
  * Tasks
  */
-static struct pid_entry tid_base_stuff[] = {
+static const struct pid_entry tid_base_stuff[] = {
 	DIR("fd",        S_IRUSR|S_IXUSR, fd),
 	INF("environ",   S_IRUSR, pid_environ),
 	INF("auxv",      S_IRUSR, pid_auxv),
@@ -2189,7 +2190,7 @@ static const struct inode_operations pro
 };
 
 static struct dentry *proc_task_instantiate(struct inode *dir,
-	struct dentry *dentry, struct task_struct *task, void *ptr)
+	struct dentry *dentry, struct task_struct *task, const void *ptr)
 {
 	struct dentry *error = ERR_PTR(-ENOENT);
 	struct inode *inode;
#2 lore raw
In reply to Andrew Morton
Quoted 5 lines · Andrew Morton

Date: Thu, 8 Mar 2007 07:53:57 -0800
From: [email protected]
To: [email protected]
Subject: [Bugme-new] [Bug 8151] New: Established connections not displayed in /proc/tcp/netstat

Please try running 'ss -nt' to see if it displays the missing connections. If it does then we can confirm a problem with /proc, otherwise the you might have a TCP problem instead.

Note that with a recent kernel you may have to build/load the tcp_diag module before 'ss -nt' will work.

Cheers,

Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt