Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 04 Sep 1998 00:44:21 +0100
From:      Brian Somers <brian@Awfulhak.org>
To:        Dirk-Willem van Gulik <dirk.vangulik@jrc.it>
Cc:        Marc Slemko <marcs@znep.com>, "Sean O'Connell" <sean@stat.Duke.EDU>, FreeBSD mobile <freebsd-mobile@FreeBSD.ORG>
Subject:   Re: /etc/pccard_ether 
Message-ID:  <199809032344.AAA06884@woof.lan.awfulhak.org>
In-Reply-To: Your message of "Mon, 31 Aug 1998 09:37:05 %2B0200." <Pine.BSF.3.96.980831093556.1827V-100000@elpc36.jrc.it> 

next in thread | previous in thread | raw e-mail | index | archive | help
This is a multipart MIME message.

--==_Exmh_-16747307640
Content-Type: text/plain; charset=us-ascii

> On Sun, 30 Aug 1998, Marc Slemko wrote:
> 
> > On Sun, 30 Aug 1998, Sean O'Connell wrote:
> > 
> > > I realize this probably picking a nit, but I was unable to get
> > > /etc/pccard_ether (in -stable) to work with the pccard_ifconfig
> > > option.  I have put together a quickie patch that is pretty
> > > much a direct hack (stolen entirely from the PAO pccard_ether
> > > for 2.2.6-RELEASE by HOSOKAWA, Tatsumi <hosokawa@jp.FreeBSD.org>).
> > > This fixes the handling of properly inserting the ifconfig_$interface
> > > into the script.  Otherwise it falls flat on it's face.
> 
> > The current design of the pccard_ifconfig line is designed so you have the
> > ifconfig arguments (eg. "inet 207.178.54.41") on it.
> 
> Or have it set to DHCP.. But still there is no convenient way to have
> different DHCP domains, on some which you trust '-r -n' setting for
> host and resolv.conf; whereas on others you might have to specifiy a whole
> lot more.

I don't know how much interest there is in this side of things, but 
I've been using the enclosed script for some time.  It allows you to 
specify a list of config files (this should be done in rc.conf), and 
when the pccard is attached, the script re-links the config files, 
kills the necessary programs and starts others.

The idea is that you make configuration alternatives based either on 
the domain or IP number handed out by a dhcp server.  You can also 
make template files that are s/something/variable/'d at configuration 
time.

The script needs polishing - I would have done this before now, but 
I'm not sure if it just makes things even more obscure than they 
already are.....

dhclient-script.local is called at the end of dhclient-script and 
iface-info is a perl script that grabs bits out of the lease file.

> Dw.

-- 
Brian <brian@Awfulhak.org>, <brian@FreeBSD.org>, <brian@OpenBSD.org>
      <http://www.Awfulhak.org>;
Don't _EVER_ lose your sense of humour....


--==_Exmh_-16747307640
Content-Type: text/plain ; name="iface-info"; charset=us-ascii
Content-Description: iface-info
Content-Disposition: attachment; filename="iface-info"

#! /usr/local/bin/perl

die "Usage: iface-info iface\n" if ($#ARGV != 0);

open (IFCONFIG, "ifconfig $ARGV[0] |") || die "Cannot execute ifconfig\n";
while (<IFCONFIG>) {
  $input = $_;
  foreach $var ("mtu", "inet", "netmask", "broadcast", "ether") {
    $_ = $input;
    chop;
    if (s/.*[ 	]($var) ([^ ]*).*/$2/) {
      $assign = $var;
      $n = 0;
      while (${$assign} ne "") {
        $n++;
        $assign = "$var$n";
      }
      ${$assign} = $_;
      print "$assign=$_\n";
      if ($var eq "netmask") {
        $bit = 0x80000000;
        $mask = eval $_;
        $bits = 0;
        while ($bit & $mask) {
          $bits++;
          $bit >>= 1;
        }
        while ($bit && !($bit & $mask)) {
          $bit >>= 1;
        }
        $assign = $n ? "$n" : "";
        print "netmask_bits$assign=$bits\n" unless $bit;
      }
    }
  }
}
close IFCONFIG;

exit 0 unless $inet;
open (LEASES, "/var/db/dhclient.leases") || exit 0;
while (<LEASES>) {
  $look = 1 if /\{/;
  if (/\}/) {
    last if $done;
    $look = $found = 0;
  }
  next unless $look;
  $found = 1 if /fixed-address $inet/;
  next unless $found;
  if (s/.*[ 	]routers[ 	]*(.*);.*/defaultroute=$1/) {
    print;
    $done = 1;
  }
  if (s/.*[ 	]domain-name-servers[ 	]*(.*);.*/$1/) {
    ($nameserver1, $nameserver2) = split(/,/);
    print "nameserver1=$nameserver1\n";
    print "nameserver2=$nameserver2";
    $done = 1;
  }
  if (s/.*[ 	]domain-name[ 	]*\"(.*)\".*/domain=$1/) {
    print;
    $done = 1;
  }
}
close LEASES;

--==_Exmh_-16747307640
Content-Type: text/plain ; name="dhclient-script.local"; charset=us-ascii
Content-Description: dhclient-script.local
Content-Disposition: attachment; filename="dhclient-script.local"

#! /bin/sh
#
# Do some post-configuration setup stuff
#

PATH=/usr/local/bin:$PATH
# link these files
pccard_files="/etc/profile /etc/printcap /usr/local/etc/smb.conf
              /etc/namedb/named.conf /home/brian/.netscape/preferences.js"
# Kill these progs
pccard_kill="smbd nmbd arpwatch rwhod"
pccard_restart="named"
# startup script dirs.
pccard_startup="/usr/local/etc/rc.d /usr/X11R6/etc/rc.d"

ip=$check_ip_address
domain=$check_domain_name
test -z "$ip" -a ."$new_ip_address" != ."$old_ip_address" &&
  ip=$new_ip_address domain=$new_domain_name

eval $(iface-info $interface)	# What's currently configured ?
[ "$inet" != "$ip" ] && exit 0	# We'll be called again...

generate() {
  # Generate from a template (.tmpl) file
  sed -e 's/dhclient-inet/'$inet/ \
      -e 's/dhclient-netmask-bits/'$netmask_bits/ \
      -e 's/dhclient-netmask/'$netmask/ \
      -e 's/dhclient-broadcast/'$broadcast/ \
      -e 's/dhclient-mtu/'$mtu/ \
      -e 's/dhclient-ether/'$ether/ \
      -e 's/dhclient-defaultroute/'$defaultroute/ \
      -e 's/dhclient-nameserver1/'$nameserver1/ \
      -e 's/dhclient-nameserver2/'$nameserver2/ \
      -e 's/dhclient-domain/'$domain/ \
    $1 >$2
}

case "$ip" in
  "") ;;

  *)  if [ -n "$pccard_files" ]; then
        if [ -z "$domain" ]; then
          logger -p local0.notice "dhcp: $interface: $ip: No leased domain !"
          exit 0
        fi
        keepgoing=TRUE
        for f in $pccard_files; do
          keepgoing=FALSE
          for file in $f.$domain.tmpl $f.$domain $f.$ip $f.tmpl
          do
            if [ -f $file ]; then
              keepgoing=TRUE
              break
            fi
          done
          if [ $keepgoing = FALSE ]; then
            echo "$f: Missing template file" >&2
            break
          fi
        done
        if [ $keepgoing = TRUE ]; then
          logger -p local0.notice "dhcp: Config $interface for $ip ($domain)"
          killall $(echo $pccard_kill)
          for f in $pccard_files; do
            rm -f $f
            if [ -f $f.$domain.tmpl ]; then
              generate $f.$domain.tmpl $f
            elif [ -f $f.$domain ]; then
              ln -s ${f##*/}.$domain $f
            elif [ -f $f.$ip ]; then
              ln -s ${f##*/}.$ip $f
            else
              generate $f.tmpl $f
            fi
          done
          killall -HUP $(echo $pccard_restart)
          sleep 1
          for dir in $pccard_startup; do
            if [ -d $dir ]; then
              for f in $dir/*.dhclient; do
                [ -x $f ] && $f $ip $domain
              done
            fi
          done
        else
          logger -p local0.notice "dhcp: $interface: $ip: Unknown config ($f) !"
        fi
      fi
      ;;
esac
exit 0

--==_Exmh_-16747307640--



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-mobile" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199809032344.AAA06884>