Contribute  :  Advanced Search  :  Directory  :  Forum  :  FAQ's  :  My Downloads  :  Links  :  Polls  
AFP548 Changing the world one server at a time.
Welcome to AFP548
Thursday, July 29 2010 @ 09:35 am MDT
   

Networking on OS X - configd

ArticlesLearn more about how OS X configures it's routes and interfaces.

This is one of the things that OS X does like no other Unix/Linux OS. So, before you pull your hair out trying to use ifconfig read this.

OS X Networking

Part 1 - Why OS X isn't like other Unixes

Let's call this the first in an occasional series on the networking "peculiarities" of OS X.

The single most common pet peeve I've heard from Unix admins coming to OS X is how to manage basic network settings. These admins are used to using ifconfig to bend their networks to their will. They've been doing it for years, it works well on every flavor of Unix/Linux out there, so it's no surprise that they continue the trend on OS X.

Of course this begins the slippery slope to one cheesed off Unix admin.

Every other Unix variant sticks to a pretty traditional, very static, network infrastructure. Let me explain before too many former Unix admins take issue with that statement. Most other operating systems are given an IP to use, and they use it. No questions, no sass. The machine will hold on to that IP come broken network or missing route statements until told otherwise. That's what I mean by static configuration.

Apple, on the other hand, wanted to change things a bit. Go figure.

Enter configd.

Instead of just taking an IP and using it, OS X wants to dynamically react to a changing network landscape. Since Macs are for grandmas in addition to admins, Apple had to make the system as usable as possible for those who are clueless about networking. This is what configd does.

When you set an IP configuration using the System Preferences that information is stored in a configuration file /Library/Preferences/SystemConfiguration/preferences.plist. Configd watches this file and waits for changes to happen.

When a change does occur, configd re-reads the entire configuration specified by this file. It breaks the configuration up by different protocol, ie. IP, AppleTalk, PPP, and sends the configuration on to a collection of agents that it has. There is an AppleTalk Agent, an IP Agent and a PPP Agent among others. These then make the changes to the interfaces as appropriate using systems calls like "ifconfig."

Configd then tells the IP Monitor Agent (IPMA), another one of configd's minions, about the network settings. The IPMA figures out what interface is highest in the list, makes that interface's gateway the default route out, and then adds routing statements to cover any other networks that might be connected to other interfaces. This dynamically builds OS X's routing table.

Makes sense so far. Everybody has a job. OS X handles the routing automatically. Cool.

There is another agent, however, that drives Unix admins into fits. The Kernel Event Monitor (KEM) waits for kernel events that tell it that an interface has gone down. When this happens it informs configd which interface has gone down. Configd then re-reads its config from the preference.plist file and sends out the new settings to the configuration agents which make sure the interfaces are configured they way they should be. This then triggers the IPMA which redoes the routing table according to the new information.

And that is what trips up the admins. They use their traditional methods of configuring an interface and use ifconfig to make it so. This works great. Until, for whatever reason, the KEM tells Configd things have changed. Configd then reverts everything back to whatever is held in the preference.plist file. This cheeses Unix admins off.

Another potential source of frustration is the fact that if an interface goes down configd will automatically remove that interface's IP from the routing table.

For example, if the ethernet cable gets unplugged from the NIC, the KEM gets the message that that interface is no more. Configd adjusts accordingly. The IP address that the interface had is no long accessible from the local machine. It's gone from the interface and its gone from the route table. Bummer. This is why you can't always depend on the IP address being there. Especially on flaky networks.

Another interesting feature of this mechanism is the kicker bundle, which can be found at /System/Library/SystemConfiguration/Kicker.bundle. This app is called when configd changes the networking configuration. It's the kicker's job to go around and restart any services that need to be told that a network change has occurred. For example, after an IP change has occurred the kicker bundle relaunches the Apple File Server and changes the local host name.

While this is a bit of a hack, you can add your own actions that occur after a network change by editing the kicker's configuration file at /System/Library/SystemConfiguration/Kicker.bundle/Contents/Resources/Kicker.xml.

Story Options

Advertising

Networking on OS X - configd | 14 comments | Create New Account
The following comments are owned by whomever posted them. This site is not responsible for what they say.
Networking on OS X - configd
Authored by: jkp on Monday, October 18 2004 @ 04:33 am MDT
Great article - some really interesting stuff in there that is fantastic to know.
Thanks for the heads up.
Networking on OS X - configd
Authored by: mathed on Tuesday, October 19 2004 @ 02:35 am MDT
Interesting stuff! Good to know explains a few quirkey behaviors that I have seen...

Thanks!
Networking on OS X - configd
Authored by: Anonymous on Wednesday, October 20 2004 @ 08:27 am MDT
WOW!
Great! Now let's do part 2 to 10 until we covered each and everything that
there is to know about OS X networking. It'll be a great resource and - if you
continue your easy approach on things - fun to read and easy enough to
understand even for foreigners (topic and language, that is) like me.

Thanks!
Networking on OS X - configd
Authored by: dragonmac on Monday, November 15 2004 @ 05:06 pm MST
Now I better understand Why my "route delete default; route add default
192.168.0.254" commands only work till restart.

While where on the topic and untill parts 2-10 are done anyone know how to
tell a client to keep a second "default" route or route to this default if
incoming route is from 192.168.0.254? Or A route only to be used as a
default route for lets say ARD or VNC services?
Networking on OS X - configd
Authored by: Anonymous on Sunday, March 06 2005 @ 12:37 pm MST
static routes can be added after automatically after reboot using the startup
item Jeff Frey created see his site

http://deaddog.duch.udel.edu/~frey/darwin/index.php

ENJOY
Networking on OS X - configd
Authored by: Anonymous on Wednesday, June 29 2005 @ 03:28 am MDT
what is the safest and reliable way to map static routes in Tiger server where the
routes stays even after server reboots?
Networking on OS X - configd
Authored by: Anonymous on Wednesday, August 17 2005 @ 07:42 am MDT
What is needed is an in-depth book on Darwin that enumerates all these
little quirks and foibles. I take it this is what "Mac OS X Panther[Tiger] for
UNIX Geeks" by OREILLY is supposed to do, but anyone who owns or has
even leafed through this book will tell you its woefully inadequate. Its time
a proper Darwin resource took care of this blindspot, so that we all didn't
have to approximate FreeBSD and all the online hacks to get a
comprehensive feel for the idiosyncracies of this particular flavour of
Unix that I, and maybe you too, happen to love but are increasingly
spitting at for want of basic distro specific information.
Networking on OS X - configd
Authored by: sunshine on Monday, November 07 2005 @ 07:59 pm MST
probably explains why I'm unable to resolve dns, when I vpn into work. I'm able
to dig and resolve hostnames through the host command, but I'm unable to ping
and surf the internet via vpn. I give it a shot and see if it fixes my problem.
Networking on OS X - configd
Authored by: Anonymous on Sunday, January 20 2008 @ 05:45 pm MST
Very interesting, but I have a problem with Leopard: I cannot find the Kicker.bundle anymore!
Is there a secret new way of hooking up a script on an IP change?
Networking on OS X - configd
Authored by: Anonymous on Tuesday, December 15 2009 @ 05:13 am MST
Just want to thank you for this valuable article. Explains a lot that I ran into in the past!