Sunday, April 13, 2008

Finding Physical Network Devices And Their Paths On Solaris

Hey There,

This week's lazy Sunday post deals with something a lot of Unix sys admins may not have to do. At least not in this particular way. It's not uncommon to be asked where a network interface physically "is" on a server, or where a cable is connected, but that task can sometimes be made difficult if you don't have physical access to the machine. Seeing it, and adding that to the knowledge you've collected on the command line, is almost guaranteed to succeed.

For the most part it's relatively simple, on Solaris Unix, to figure out the device paths to your network cards if you're using Sun hardware. Basically, just the output of "ifconfig -a" will get you started:

host # ifconfig -a
lo0: flags=1000849 mtu 8232 index 1
inet netmask ff000000
qfe0: flags=9040843 mtu 1500 index 2
inet netmask ffffff00 broadcast
groupname GRP
ether 8:0:20:**:**:**
qfe0:1: flags=1000843 mtu 1500 index 2
inet netmask ffffff00 broadcast

And you can tell that you only have the loopback device (which doesn't "really" count, although it's really bad "not" to have ;) and the qfe0 device.

Note that, if you have to find all the devices, even if they don't have cables attached, sometimes (if you have the latitude), running:

host # ifconfig -a plumb

Will make them show up in your "ifconfig" output. But you can most definitely find them by grepping the "qfe" network driver instance out of the /etc/path_to_inst file:

host # grep qfe /etc/path_to_inst
"/pci@8,700000/pci@3/SUNW,qfe@0,1" 0 "qfe"
"/pci@8,700000/pci@3/SUNW,qfe@1,1" 1 "qfe"
"/pci@8,700000/pci@3/SUNW,qfe@2,1" 2 "qfe"
"/pci@8,700000/pci@3/SUNW,qfe@3,1" 3 "qfe"

This shows you that there are actually 4 ports available, but, looking at "ifconfig," you can see that only port 0 is in use. Port 0 is supporting two separate IP's, but the qfe0:1 instance is "virtual" and doesn't indicate another physical port even though it does indicate another network address that's up on your machine.

Attached to the end of this post is a tiny script that will go through your "ifconfig -a" output and pick out the "real" devices that are up (no "virtuals" ;) and get the corresponding entry out of /etc/path_to_inst. It's not much, as far as script's go, but it's something you don't want to have to type too often ;)

Now comes the "iffy" part. Worst case, you'll have to go to the online manuals, or hard copy if you have it, to find this stuff out. For instance, on Sun v880's, the output from "prtdiag" does not show the device path for any of the pci devices. This makes it somewhat more difficult to figure out what PCI slot and/or port your network device is on, but it's still possible. Sometimes, it's just a matter of going through each line of output and determining what devices "couldn't" be the one you're looking for (Somewhat like the strategy you might use to pass an unnecessarily covoluted certification test.)

If you're fortunate enough, however, your machine may be able to help you make a direct correlation through the use of "prtdiag" (for instance, SunFire machines, up to at least the v440's, include this information. Some of Sun's newer machines have issues with spewing incorrect error messages when you use prtdiag. This shouldn't be an issue here, but just giving you a heads up in case you see any of those and think something else is wrong with your machine when it's perfectly fine).

For this example, we'll walk step by step through figuring out what PCI slot and port a network device resides on using a V440. First, we'll get the basic info using "ifconfig -a" (All output here will be summarized somewhat to save trees ;)

host # ifconfig -a
lo0: flags=2001000849 mtu 8232 index 1
inet netmask ff000000
ce3: flags=1000843 mtu 1500 index 3
inet netmask ffffff00 broadcast

Now, we know that the device we'll be looking for is "ce3." If there had been another listing up for, say, "ce3:1," we would ignore that, since it's a "virtual" interface.

Now we'll find that NIC's "physical" device path in /etc/path_to_inst:

host # grep ce /etc/path_to_inst|grep -w 3
"/pci@1f,700000/network@1" 3 "ce"

It's good to understand the basic format of /etc/path_to_inst if you need to search it for any information. It's very basic and each line consists of 3 elements, in order. The "physical device path" (the same as you would see if you ran an "ls" on /devices), the "instance number" and the "device driver name." It would probably be more easy to read if the device driver name came before the instance number, but it is what it is ;)

Now we'll check prtdiag to find out what slot this network card is plugged in on (or if it's a built-in port) and what port on the device the cable is (or should be) connected to:

host# prtdiag
System Configuration: Sun Microsystems sun4u Sun Fire V440
================================= IO Devices =================================
Bus Freq Slot + Name +
Type MHz Status Path Model
------ ---- ---------- ---------------------------- --------------------
pci 66 MB pci108e,abba (network) SUNW,pci-ce
okay /pci@1f,700000/network@1

And we find that it's, indeed, a built-in card. In this instance, since "prtdiag" doesn't give us much information about the port, we can derive this from the physical name. As a general rule of thumb, if you look at the end of the "Name + Path" column (or the same thing in /etc/path_to_inst) and see "network@0" it's on port 0, and it's on port 1 if you see "network@1" (Remember that the numbering system begins at 0, so instance 0 is always the first port. Note, also, that the "Path" name had no secondary "pci" designation. Generally, if you see a short path from pci to network, you're dealing with a Built-In port, since the first pci addressin the device name is the board)

Here's a quick excerpt (unrelated) from a machine that provides more information on the port and slot numbers (but not the exact matching path!!!! Can you feel the self-doubt eating away at you? Blow it off ;)

========================= IO Cards =========================
IO Port Bus Freq Bus Dev,
Brd Type ID Side Slot MHz Freq Func State Name Model
---- ---- ---- ---- ---- ---- ---- ---- ----- -------------------------------- ----------------------
I/O PCI 8 B 2 33 33 0,1 ok SUNW,qfe-pci108e,1001 SUNW,pci-qfe/pci-bridg+

In this situation, you'd have to use some deductive reasoning, as well, to be sure.

As a last resort (or a first one if you prefer), check out Sun's Online Documentation Center where you can read all the technical manuals and copy off each model's device-path-to-PCI-slot/port number mappings.

Yay :)

Best wishes,

Creative Commons License

This work is licensed under a
Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License


# - find our nic's and their physical device paths in /etc/path_to_inst
# 2008 - Mike Golvach -
# Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License

ifconfig -a|sed 's/^\([^0-9]*\)\([^:]*\):.*/\1 \2/'|egrep -v 'lo|in|gr'|sort -u|while read one two
awk '{ if ( $3 ~ /'"$one"'/ && $2 ~ /'"$two"'/ ) print $0 }' /etc/path_to_inst|sed 's/\"//g'

, Mike