Common issues gathering local interface information...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi there,

I've been writing applications that need local interface information
several times now (IP-address, MAC, subnet mask, ARP, routing info
etc.), for different versions of the Linux kernel.

Every time I have to implement such a routine I find myself wondering
what interface will be 'the best'. The /proc filesystem? The sysfs
filesystem? IOCTL's? NETLINK sockets?

Of course, they all work most of the time; but not for all Linux
versions. Let's take an issue I've had; get the interface name using a
given MAC-address.

I could use IOCTL's, this method probably produces the most readable
code, works with practically every Linux kernel and is relatively easy
to implement. First get interface information using SIOCGIFCONF, then
iterate through the list and call SIOCGIFHWADDR to get the
MAC-addresses.

However, SIOCGIFCONF does not return interface information of
interfaces that have no IP-address, so this method was rejected due to
the need for this capability.

The NETLINK implementation seemed rather hefty (in terms of codesize
and readability) so was not preferred.

Then I used the /proc filesystem interface; this was pretty doable,
but still I somehow always question the sensibility of the
dissecting-info-from-formatted-files-method to read the interface
names from /proc/net/dev. This seemed to work fine, and worked with
all kernel versions....

...until Linux-2.6.25 was released, where /proc/net is changed to be a
symlink to /proc/self/net and a symlink-check in the application made
the application somewhat disfunctional. The check was put there to
make sure the /proc/net directory was not rerouted by a symlink (with
possible malicious intentions).

A simple removal of the check was the solution, bringing along all
possible security compromises.

This example was given to indicate the issues I come across all the
time, not as a specific problem or something.

I've been reading a lot about kernel interfaces but there always seems
to be a dispute about which one is appropriate for a particular
situation. But no matter how much I learn about the different
interfaces, I still have trouble choosing the 'right' one. My question
is, is there some general rule-of-thumb you use that could help me on
this? Or any other type of advice? Any methods you use to decide? Any
help is appreciated!

Thanks in advance!

-Kris
--
To unsubscribe from this list: send the line "unsubscribe linux-net" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux 802.1Q VLAN]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Git]     [Bugtraq]     [Yosemite News and Information]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux PCI]     [Linux Admin]     [Samba]

  Powered by Linux