Coding around human perversity

David Wolfskill david at catwhisker.org
Thu Dec 18 11:45:15 PST 2008


Eh.  I started to write a very long narrative, but came to my senses.

Here's the RCS log of a script I wrote that handles NIC initialization
for my laptop (running FreeBSD).  (The revisions prior to 17 Dec were
lost in an unfortunate incident involving an unclean shutdown while
running a not-quite-as-stable-as-might-be-desired version of FreeBSD
CURRENT; while the script itself was OK, the ,v file was toast.  But
it's the 2 recent log entries that are of interest, anyway.)

g1-37(8.0-C)[1] rlog /usr/local/etc/rc.d/nic_init 

RCS file: /usr/local/etc/rc.d/RCS/nic_init,v
Working file: /usr/local/etc/rc.d/nic_init
head: 1.3
branch:
locks: strict
access list:
symbolic names:
keyword substitution: kv
total revisions: 3;     selected revisions: 3
description:
Script to find an appropriate NIC and establish a network connection.
----------------------------
revision 1.3
date: 2008/12/18 18:52:44;  author: root;  state: Exp;  lines: +47 -3
I'm getting tired of writing clever code to circumvent perverse
people.

After my last change, I figured I'd be good, as merely getting
"association" wouldn't necessarily get an IP address (which would
come from a DHCP server), and if wpa_supplicant managed to acquire
an association to some AP I didn't want to mess with anyway, the
code I committed would see that there may well be an association,
but there waas no IP address (other than 0.0.0.0) assigned, so it
wasn't worth losing sleep over -- just try my routine (which this
script starts up, since  obviously can't figure out how to use
wpa_supplicant in any way that makes a particle of sense or is of
any use.

Boy, was I in for a rude surprise!

It seems that some AT&T customer (based on the IP addresses returned
in /etc/resolv.conf as nameservers) has an AP configured to allow random
associations, and even DHCP "service" -- that is DESIGNED to be BROKEN!
Yes:  we get an IP address, netmask, and a default gateway that we CAN'T
EVEN PING!

This is STUPID.  And PERVERSE.

OK.  THIS version of the start-up script will check for all of that
perversity, and I *believe* it should manage to evade it.

I shudder to think what absurd mal-configuration I'll need to code
around next.
----------------------------
revision 1.2
date: 2008/12/17 14:10:46;  author: root;  state: Exp;  lines: +9 -4
wpa_supplicant was getting a NIC "active", but dhclient wasn't getting an
address, leaving the NIC's IP address as 0.0.0.0 -- which was NOT useful.

This code should evade that particular form of ... helpfulness.
Or something.
----------------------------
revision 1.1
date: 2008/12/15 23:18:04;  author: root;  state: Exp;
Initial revision
----------------------------
=============================================================================

And it worked:

Dec 18 10:56:16 localhost kernel: nic_init invoked with argument faststart; flag
s: -n 1 
Dec 18 10:56:16 localhost kernel: Found IP address 192.168.1.103 on NIC an0; che
cking for default gateway
Dec 18 10:56:16 localhost kernel: Found default gateway 192.168.1.1; checking us
ability
Dec 18 10:56:28 localhost kernel: Default gateway 192.168.1.1 not pingable; cont
inuing with nic_init
Dec 18 10:56:28 localhost kernel: Starting nic_init.
...
Dec 18 10:56:37 localhost kernel: dhclient: Exiting /etc/dhclient-exit-hooks (PREINIT) with exit_status 0
Dec 18 10:56:38 localhost kernel: DHCPREQUEST on an0 to 255.255.255.255 port 67
Dec 18 10:56:38 localhost kernel: 
Dec 18 10:56:38 localhost kernel: DHCPNAK from 172.17.0.1
Dec 18 10:56:38 localhost kernel: 
Dec 18 10:56:38 localhost kernel: DHCPDISCOVER on an0 to 255.255.255.255 port 67 interval 6
Dec 18 10:56:38 localhost kernel: 
Dec 18 10:56:40 localhost kernel: DHCPOFFER from 172.17.0.1
Dec 18 10:56:40 localhost kernel: 
Dec 18 10:56:42 localhost kernel: DHCPREQUEST on an0 to 255.255.255.255 port 67
Dec 18 10:56:42 localhost kernel: 
Dec 18 10:56:42 localhost kernel: DHCPACK from 172.17.0.1
Dec 18 10:56:42 localhost kernel: 
Dec 18 10:56:46 localhost kernel: bound to 172.17.1.37 -- renewal in 302400 seconds.


Yeah, if someone wants to see the /bin/sh script, I can share that;
fair warning: it's in the BSD "rc.d" form (intended to work with
rcorder(8), though the techniques used should be relatively portable).
Certainly more so than some bash(1) constructs I've encountered. :-}

Peace,
david
-- 
David H. Wolfskill				david at catwhisker.org
Depriving a girl or boy of an opportunity for education is evil.

See http://www.catwhisker.org/~david/publickey.gpg for my public key.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
URL: <http://www.baylisa.org/pipermail/baylisa/attachments/20081218/ed69041e/attachment.bin>


More information about the Baylisa mailing list