getting PID and task name from sk_buff
Hello,
I am trying to get the PID and Task Name from the sk_buff and am having a hard time doing this.
I have tried the following:sk_buff->sk->sk_socket->file->fowner.pid
but that always seems to return 0.
I was then planning on using the pid to get the specific task and get the task->comm to get the name...but I am only getting PID(0): swapper.
Any suggestions on a better way to do this?
I am trying to track network traffic based on the process name and the process ID.
Thanks!
Alan Stead
Quoted 3 lines · Alan Stead
Any suggestions on a better way to do this?
I am trying to track network traffic based on the process name and the process ID.
Check out how the ipt_owner match module does it. However, I think that this is not perfect, either. Maybe someone else has a better idea?
Signature · 2 lines
[ Tobias DiPasquale ] 0x636f6465736c696e67657240676d61696c2e636f6d
Quoted 3 lines
Check out how the
ipt_ownermatch module does it. However, I think that this is not perfect, either. Maybe someone else has a better idea?
When you do things at the wrong layer, there is never a perfect solution.
When you need per-process accounting of network traffic, the correct layer would be in the socket I/O syscalls themselves. I think the LSM framework could provide the right hooks to do that.
best regards
Patrick
Quoted 3 lines
When you need per-process accounting of network traffic, the correct layer would be in the socket I/O syscalls themselves. I think the LSM framework could provide the right hooks to do that.
If the accounting of network traffic is done in the socket I/O syscalls, would this "count" traffic that might get filtered out by ip_tables?
I am new to all this, but am finding it very exciting to learn so much! Thanks for the responses!
Alan
Quoted 6 lines · Alan Stead
Quoted 3 lines
When you need per-process accounting of network traffic, the correct layer would be in the socket I/O syscalls themselves. I think the LSM framework could provide the right hooks to do that.
If the accounting of network traffic is done in the socket I/O syscalls, would this "count" traffic that might get filtered out by
ip_tables?
For incoming traffic, it would not count. For outgoing traffic, it would.
Another interesting topic is whether retransmits would count, or not. And whether header overhead would count, or not.
With a socket layer based approach, neither retransmits, nor header overhead, would count. For a netfilter based approach, it would be very hard to not account retransmits.
Decisions, decisions...
best regards
Patrick
Getting PID from sk_buff
I think I will try the system call approach, but I would also like to add a process-name match.
I have looked at the pid-owner match, however I dont have a pid to go by, and it seems ridiculous to go through all the tasks, find a matching name, and then go through that task's files to find a match. Instead I was trying to get the process pid from the sk_buff through:sk_buff->sk->sk_socket->file->f_owner.pid
but it always returns 0...?
Alan Stead