LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 07-15-2008, 04:07 PM   #1
blank87
LQ Newbie
 
Registered: Jun 2008
Posts: 4

Rep: Reputation: 0
Checking if a TCP/UDP connection is actually local


Hi everyone,

I want to be able to tell if the endpoint of a UDP or TCP connection is actually on the same machine. Using the Linux Security Module, I'm able to check the destination IP of all outgoing traffic, but I'm not sure how to get a machine's IP from inside the kernel (to compare with the destination IP) . Does anyone know how to do this?
 
Old 07-15-2008, 05:30 PM   #2
Cocoabean
LQ Newbie
 
Registered: Jan 2007
Distribution: Ubuntu
Posts: 17

Rep: Reputation: 0
I'm not sure exactly what you mean, but if the connection is to the destination computer, it is a 'loopback' (assuming the same interface on the same system) and the destination IP will show up as an IP starting with '127'. To get the IP addresses of the network interfaces on your machine, type 'ifconfig'. If you have more than one interface and only want to see the IP address of one of your interfaces type 'ifconfig eth0' where 'eth0' is the name of the card. Could also be 'eth1' or 'wlan0' and so on and so forth depending upon your distro and hardware. Hope that helps!
 
Old 07-15-2008, 07:32 PM   #3
blank87
LQ Newbie
 
Registered: Jun 2008
Posts: 4

Original Poster
Rep: Reputation: 0
Thanks for your input, but I think I was unclear with what I'm trying to do.

I'm trying to write a kernel module that blocks certain kinds of IPC's between processes. One of those IPC's I wish to block are TCP/UDP connections that are actually local (the source and destination addresses actually refer to the EXACT same machine). I could check for an IP starting with 127, but I also want to be able to catch the case where the client fills in my machine's ACTUAL IP address (ie: it sets the address field to 123.123.123.123 instead of 127.0.0.1). This is the reason I want to be able to find the IP address(es) of a machine. And I need to be able to do this from a kernel module . Any ideas?

Or, alternatively, does anyone know HOW ifconfig does its job? I tried using strace on it but I'm too much of a newbie to see what structures and key functions the system calls access to get the information.

Last edited by blank87; 07-15-2008 at 07:36 PM.
 
Old 07-15-2008, 11:14 PM   #4
Cocoabean
LQ Newbie
 
Registered: Jan 2007
Distribution: Ubuntu
Posts: 17

Rep: Reputation: 0
Does the machine have more than one NIC. You can disable loopback without writing a module IIRC. I'm not sure that it will block requests to the real IP from the same machine, you could always block incoming connections from 'localhost' on your firewall.
 
Old 07-16-2008, 02:21 AM   #5
resetreset
Senior Member
 
Registered: Mar 2008
Location: Cyberspace
Distribution: Dynebolic, Ubuntu 10.10
Posts: 1,340

Rep: Reputation: 62
the output of netstat should tell you this.
 
Old 07-16-2008, 02:44 AM   #6
pinniped
Senior Member
 
Registered: May 2008
Location: planet earth
Distribution: Debian
Posts: 1,732

Rep: Reputation: 50
This sounds like the sort of thing you'd use iptables for; I just don't know if iptables rules can be applied to loopback traffic as well.
 
Old 07-16-2008, 03:04 AM   #7
hasanatizaz
Member
 
Registered: Nov 2007
Location: Pakistan
Distribution: Redhat and Debian
Posts: 317
Blog Entries: 1

Rep: Reputation: 35
yeah it can be seen through netstat.
 
Old 07-17-2008, 02:21 AM   #8
blank87
LQ Newbie
 
Registered: Jun 2008
Posts: 4

Original Poster
Rep: Reputation: 0
The problem is I can't use netstat to get this information IN the kernel itself. I'm coding inside the linux kernel. I really don't want to call a fork and execve to get netstat running to get the information I want :S.

Netstat must have some way of asking the kernel for the information...I want to know how it's doing this :S. I've tried using strace and looking through the system calls it does but I can't pinpoint exactly where the local IP address(es) are found . I need to know where in the kernel code the lookup of a machine's IP address is done (and what data structures it uses). Does anyone know where INSIDE the linux kernel code this is done?

And yes, the machine does have more than one NIC . Actually, blocking requests to the real IP from the same machine is EXACTLY my problem. I need to know given this destination address, is it mine?

Last edited by blank87; 07-17-2008 at 02:23 AM.
 
Old 07-17-2008, 08:44 AM   #9
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
First of all I would suggest you report this thread for closure (see the "Report" button) and after it's closed open a thread in either the kernel or Programming forum for this topic (and link back to it). Not only are those more appropriate fora but creating a new thread "the right way" should rid you of any userland-related answers and focus on in-kernel work.

Asserting a packet came in from the wire first (socket buffer), and Linux being efficient, it'll cache info where it can. So I think you're looking for the (RIB/FIB) route caches (of which stuff is exported to /proc for userland reading). How SKBs work says that in sk_buff you have dst_entry (packet route). So searching LXR for "struct dst_entry" could be a start else maybe the "protocol independent destination cache definitions" from include/net/dst.h. Stuff related to route caches should probably have something like "rt_cache", "rt_dst" or alike anyway, or else terms like "cache lookup" or "routing table" (yielding anything in include/net/) could be interesting (to you that is ;-p).
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
About TCP / UDP shipon_97 Linux - Newbie 5 06-24-2012 06:22 PM
TCP and UDP aatwell Programming 4 11-07-2007 08:47 AM
tcp/udp and c++ Kroenecker Programming 1 05-10-2005 11:56 AM
UDP over TCP The_Nerd Programming 7 07-21-2004 09:45 PM
how to stop a connection to a specific UDP/TCP port? aromes Linux - Networking 2 03-04-2004 07:37 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 05:10 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration