All of lore.kernel.org
 help / color / mirror / Atom feed
* How to get creatior PID information for the local tcp connection
@ 2016-04-07 17:43 ` Vishnu Pratap Singh
  0 siblings, 0 replies; 6+ messages in thread
From: Vishnu Pratap Singh @ 2016-04-07 17:31 UTC (permalink / raw)
  To: dccp, linux-kernel, netdev, vishnu.ps

Hi,


Issue -  How to get PID information for the local tcp connection



i want to get the creator PID for each socket in user space for local
tcp connection, i see in kernel there is support for returing PID with
"SO_PEERCRED" ioctl to work across namespaces. it uses struct pid and
struct cred to store the peer credentials on struct sock.
cred_to_ucred(sk->sk_peer_pid, sk->sk_peer_cred, &peercred); Above
function stores the PID information in ucred->pid = pid_vnr(pid); and
same is returned via "SO_PEERCRED" ioctl .

But for local tcp connection i get pid as 0, is there any way i can
get the PID information. Any help or suggestion will be highly
helpful.



BR,

Vishnu<div id="DDB4FAA8-2DD7-40BB-A1B8-4E2AA1F9FDF2"><br />
<table style="border-top: 1px solid #aaabb6;">
	<tr>
        <td style="width: 55px; padding-top: 13px;"><a
href="https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail"
target="_blank"><img
src="https://ipmcdn.avast.com/images/2016/icons/icon-envelope-open-tick-round-orange-v1.png"
/></a></td>
		<td style="width: 470px; padding-top: 15px; color: #41424e;
font-size: 13px; font-family: Arial, Helvetica, sans-serif;
line-height: 18px;">Virus-free. <a
href="https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail"
target="_blank" style="color: #4453ea;">www.avast.com</a>
		</td>
	</tr>
</table><a href="#DDB4FAA8-2DD7-40BB-A1B8-4E2AA1F9FDF2" width="1"
height="1"></a></div>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* How to get creatior PID information for the local tcp connection
@ 2016-04-07 17:43 ` Vishnu Pratap Singh
  0 siblings, 0 replies; 6+ messages in thread
From: Vishnu Pratap Singh @ 2016-04-07 17:43 UTC (permalink / raw)
  To: dccp

Hi,


Issue -  How to get PID information for the local tcp connection



i want to get the creator PID for each socket in user space for local
tcp connection, i see in kernel there is support for returing PID with
"SO_PEERCRED" ioctl to work across namespaces. it uses struct pid and
struct cred to store the peer credentials on struct sock.
cred_to_ucred(sk->sk_peer_pid, sk->sk_peer_cred, &peercred); Above
function stores the PID information in ucred->pid = pid_vnr(pid); and
same is returned via "SO_PEERCRED" ioctl .

But for local tcp connection i get pid as 0, is there any way i can
get the PID information. Any help or suggestion will be highly
helpful.



BR,

Vishnu<div id="DDB4FAA8-2DD7-40BB-A1B8-4E2AA1F9FDF2"><br />
<table style="border-top: 1px solid #aaabb6;">
	<tr>
        <td style="width: 55px; padding-top: 13px;"><a
href="https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail"
target="_blank"><img
src="https://ipmcdn.avast.com/images/2016/icons/icon-envelope-open-tick-round-orange-v1.png"
/></a></td>
		<td style="width: 470px; padding-top: 15px; color: #41424e;
font-size: 13px; font-family: Arial, Helvetica, sans-serif;
line-height: 18px;">Virus-free. <a
href="https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail"
target="_blank" style="color: #4453ea;">www.avast.com</a>
		</td>
	</tr>
</table><a href="#DDB4FAA8-2DD7-40BB-A1B8-4E2AA1F9FDF2" width="1"
height="1"></a></div>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: How to get creatior PID information for the local tcp connection
  2016-04-07 17:43 ` Vishnu Pratap Singh
@ 2016-04-07 18:26   ` Eric Dumazet
  -1 siblings, 0 replies; 6+ messages in thread
From: Eric Dumazet @ 2016-04-07 18:26 UTC (permalink / raw)
  To: Vishnu Pratap Singh; +Cc: dccp, linux-kernel, netdev, vishnu.ps

On Thu, 2016-04-07 at 23:01 +0530, Vishnu Pratap Singh wrote:
> Hi,
> 
> 
> Issue -  How to get PID information for the local tcp connection
> 
> 
> 
> i want to get the creator PID for each socket in user space for local
> tcp connection, i see in kernel there is support for returing PID with
> "SO_PEERCRED" ioctl to work across namespaces. it uses struct pid and
> struct cred to store the peer credentials on struct sock.
> cred_to_ucred(sk->sk_peer_pid, sk->sk_peer_cred, &peercred); Above
> function stores the PID information in ucred->pid = pid_vnr(pid); and
> same is returned via "SO_PEERCRED" ioctl .
> 
> But for local tcp connection i get pid as 0, is there any way i can
> get the PID information. Any help or suggestion will be highly
> helpful.
> 
> 

man 7 socket

       SO_PEERCRED
              Return the credentials of the foreign  process  connected  to  this  socket.
              This  is  possible  only  for  connected  AF_UNIX stream sockets and AF_UNIX
              stream and datagram socket pairs created using socketpair(2);  see  unix(7).
              The  returned  credentials  are those that were in effect at the time of the
              call to connect(2) or socketpair(2).  The argument  is  a  ucred  structure;
              define  the  GNU_SOURCE  feature test macro to obtain the definition of that
              structure from <sys/socket.h>.  This socket option is read-only.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: How to get creatior PID information for the local tcp connection
@ 2016-04-07 18:26   ` Eric Dumazet
  0 siblings, 0 replies; 6+ messages in thread
From: Eric Dumazet @ 2016-04-07 18:26 UTC (permalink / raw)
  To: dccp

On Thu, 2016-04-07 at 23:01 +0530, Vishnu Pratap Singh wrote:
> Hi,
> 
> 
> Issue -  How to get PID information for the local tcp connection
> 
> 
> 
> i want to get the creator PID for each socket in user space for local
> tcp connection, i see in kernel there is support for returing PID with
> "SO_PEERCRED" ioctl to work across namespaces. it uses struct pid and
> struct cred to store the peer credentials on struct sock.
> cred_to_ucred(sk->sk_peer_pid, sk->sk_peer_cred, &peercred); Above
> function stores the PID information in ucred->pid = pid_vnr(pid); and
> same is returned via "SO_PEERCRED" ioctl .
> 
> But for local tcp connection i get pid as 0, is there any way i can
> get the PID information. Any help or suggestion will be highly
> helpful.
> 
> 

man 7 socket

       SO_PEERCRED
              Return the credentials of the foreign  process  connected  to  this  socket.
              This  is  possible  only  for  connected  AF_UNIX stream sockets and AF_UNIX
              stream and datagram socket pairs created using socketpair(2);  see  unix(7).
              The  returned  credentials  are those that were in effect at the time of the
              call to connect(2) or socketpair(2).  The argument  is  a  ucred  structure;
              define  the  GNU_SOURCE  feature test macro to obtain the definition of that
              structure from <sys/socket.h>.  This socket option is read-only.



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: How to get creatior PID information for the local tcp connection
  2016-04-07 17:43 ` Vishnu Pratap Singh
@ 2016-04-07 18:31     ` Eric Dumazet
  -1 siblings, 0 replies; 6+ messages in thread
From: Eric Dumazet @ 2016-04-07 18:31 UTC (permalink / raw)
  To: Vishnu Pratap Singh; +Cc: dccp, linux-kernel, netdev, vishnu.ps

On Thu, 2016-04-07 at 11:26 -0700, Eric Dumazet wrote:
> On Thu, 2016-04-07 at 23:01 +0530, Vishnu Pratap Singh wrote:
> > Hi,
> > 
> > 
> > Issue -  How to get PID information for the local tcp connection
> > 
> > 
> > 
> > i want to get the creator PID for each socket in user space for local
> > tcp connection, i see in kernel there is support for returing PID with
> > "SO_PEERCRED" ioctl to work across namespaces. it uses struct pid and
> > struct cred to store the peer credentials on struct sock.
> > cred_to_ucred(sk->sk_peer_pid, sk->sk_peer_cred, &peercred); Above
> > function stores the PID information in ucred->pid = pid_vnr(pid); and
> > same is returned via "SO_PEERCRED" ioctl .
> > 
> > But for local tcp connection i get pid as 0, is there any way i can
> > get the PID information. Any help or suggestion will be highly
> > helpful.
> > 
> > 
> 
> man 7 socket
> 
>        SO_PEERCRED
>               Return the credentials of the foreign  process  connected  to  this  socket.
>               This  is  possible  only  for  connected  AF_UNIX stream sockets and AF_UNIX
>               stream and datagram socket pairs created using socketpair(2);  see  unix(7).
>               The  returned  credentials  are those that were in effect at the time of the
>               call to connect(2) or socketpair(2).  The argument  is  a  ucred  structure;
>               define  the  GNU_SOURCE  feature test macro to obtain the definition of that
>               structure from <sys/socket.h>.  This socket option is read-only.
> 

Sorry, I hit "Send" too fast.

This is not implemented for TCP yet.

You'll have to take a look at iproute2 package, since "ss -tp" is able
to find this information, by looking at all /proc/{pid}/fd/*  files and
the socket inode number the kernel gives through inet_diag

Not scalable if you have millions of sockets...

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: How to get creatior PID information for the local tcp connection
@ 2016-04-07 18:31     ` Eric Dumazet
  0 siblings, 0 replies; 6+ messages in thread
From: Eric Dumazet @ 2016-04-07 18:31 UTC (permalink / raw)
  To: dccp

On Thu, 2016-04-07 at 11:26 -0700, Eric Dumazet wrote:
> On Thu, 2016-04-07 at 23:01 +0530, Vishnu Pratap Singh wrote:
> > Hi,
> > 
> > 
> > Issue -  How to get PID information for the local tcp connection
> > 
> > 
> > 
> > i want to get the creator PID for each socket in user space for local
> > tcp connection, i see in kernel there is support for returing PID with
> > "SO_PEERCRED" ioctl to work across namespaces. it uses struct pid and
> > struct cred to store the peer credentials on struct sock.
> > cred_to_ucred(sk->sk_peer_pid, sk->sk_peer_cred, &peercred); Above
> > function stores the PID information in ucred->pid = pid_vnr(pid); and
> > same is returned via "SO_PEERCRED" ioctl .
> > 
> > But for local tcp connection i get pid as 0, is there any way i can
> > get the PID information. Any help or suggestion will be highly
> > helpful.
> > 
> > 
> 
> man 7 socket
> 
>        SO_PEERCRED
>               Return the credentials of the foreign  process  connected  to  this  socket.
>               This  is  possible  only  for  connected  AF_UNIX stream sockets and AF_UNIX
>               stream and datagram socket pairs created using socketpair(2);  see  unix(7).
>               The  returned  credentials  are those that were in effect at the time of the
>               call to connect(2) or socketpair(2).  The argument  is  a  ucred  structure;
>               define  the  GNU_SOURCE  feature test macro to obtain the definition of that
>               structure from <sys/socket.h>.  This socket option is read-only.
> 

Sorry, I hit "Send" too fast.

This is not implemented for TCP yet.

You'll have to take a look at iproute2 package, since "ss -tp" is able
to find this information, by looking at all /proc/{pid}/fd/*  files and
the socket inode number the kernel gives through inet_diag

Not scalable if you have millions of sockets...



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2016-04-07 18:31 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-04-07 17:31 How to get creatior PID information for the local tcp connection Vishnu Pratap Singh
2016-04-07 17:43 ` Vishnu Pratap Singh
2016-04-07 18:26 ` Eric Dumazet
2016-04-07 18:26   ` Eric Dumazet
2016-04-07 18:31   ` Eric Dumazet
2016-04-07 18:31     ` Eric Dumazet

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.