Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 28 May 2014 06:55:44 -0700 (PDT)
From:      =?iso-8859-1?Q?Yves_Gu=E9rin?= <yvesguerin@yahoo.ca>
To:        "rc@freebsd.org" <rc@freebsd.org>, David Wolfskill <david@catwhisker.org>
Subject:   Re: An attempt to decrease time taken to bring up NICs
Message-ID:  <1401285344.56835.YahooMailNeo@web122405.mail.ne1.yahoo.com>
In-Reply-To: <20140527225721.GA64440@albert.catwhisker.org>
References:  <20140527225721.GA64440@albert.catwhisker.org>

next in thread | previous in thread | raw e-mail | index | archive | help
Dear,=0A=0AI have the same problem, but I resolved it by modifying the boot=
 screen (/boot/loader.4th) and (to include my network setup as a menu, repl=
acing the FreeBSD one) I transfert my choice via the kernel arguments and I=
 had an rc script to setup my rc.conf dynamically.=0A=0ARegards,=0A=0A=0A=
=A0=0AYves Guerin=0A=0A=0A=0A=0A=0ALe Mardi 27 mai 2014 18h57, David Wolfsk=
ill <david@catwhisker.org> a =E9crit :=0A =0A=0A=0AThis may well be somethi=
ng that is generally applicable only to a subset=0Aof machines, but here go=
es....=0A=0AMy laptop has both wired (em(4)) and wireless (iwn(4)) NICs.=A0=
 During=0Anormal operation, I would prefer to have one NIC used; which one =
depends=0Aon circumstances that are rather location-dependent -- but the ma=
chine=0Ais intended to have the role of "DHCP client" (again, in "normal=0A=
operation").=0A=0AAs a consequence, /etc/rc.conf includes:=0A=0Awlans_iwn0=
=3Dwlan0=0Aifconfig_wlan0=3D"WPA DHCP"=0Aifconfig_em0=3D"DHCP"=0A=0A=0AAnd =
as a consequence of *that*, FreeBSD (via rc.d/netif, if I understand=0Acorr=
ectly) attempts to bring up em0, then wlan0... serially, and on=0Aevery boo=
t (well, transition from single-user to multi-user mode).=0A=0ANow, I can c=
ontrol the behavior a bit:=0A* I can choose whether or not to plug a wire i=
nto em0.=A0 (In some cases,=0A=A0 I can even control whether or not the oth=
er end of the wire is connected=0A=A0 to anything useful. :-})=0A* I can di=
sable the iwn0 NIC (by sliding the hardware switch).=0A=A0 (Sometimes I can=
 even do that intentionally. :-})=0A=0ABut whether or not either (or both) =
of the above have been done, we=0Afirst try to bring up em0, then try to br=
ing up wlan0.=0A=0AOne plausible approach might be to fork off separate sub=
processes, and=0Atry to bring up the NICs in parallel.=A0 However, I'm not =
that ambitious. :-}=0A=0AI did think of a couple of things that might help =
somewhat, though, and=0Aeven tried coding one of them up:=0A* Create an rc.=
conf knob to control allow the specification of the=0A=A0 number of NICs I =
would like to have brought up.=A0 In my case, I might=0A=A0 set that at 1 -=
- so if I'm in an environment where I know I only want=0A=A0 to use thw wir=
ed NIC, I connect em0, it's brought up, and then=0A=A0 rc.d/netif stops try=
ing to bring up NICs (because I've reached the=0A=A0 target number).=0A* Cr=
eate an rc.conf knob to make the sequence in which the NICs are=0A=A0 broug=
ht up explicit.=0A=0AFor the first one (specifying a target number of activ=
e NICs), I cobbled=0Aup a bit of code (only changing rc.d/netif); the chang=
ed version even=0Aseems to do the right thing if I invoke:=0A=0A=A0=A0=A0 s=
ervice netif start=0A=0AHowever, in "real life" (i.e., during a real transi=
tion from single- to=0Amulti-user mode), the behavior seems to be unchanged=
.=0A=0AIs there something ... different ... about how rc.d/netif is invoked=
=0Aduring boot time, perhaps?=0A=0A=0AFor the second... it seems that the s=
equence is effectively dictated by=0Athe sequence in which "ifconfig -l" ou=
tputs the list of NICs (though=0Arc.d/netif has a bit of code to move lo0 t=
o the front of the list).=A0 I=0Asuppose one possible approach would be:=0A=
* If a certain rc variable has a non-empty value, treat it as a=0A=A0 space=
-separated list of NICs (same format as output of "ifconfig -l"),=0A=A0 and=
 use that value in place of the currently-used "ifconfig -l"=0A=A0 output.=
=A0 (This implies that the current behavior of ensuring that lo0=0A=A0 is f=
irst would remain.)=0A* If that rc variable is undefined or has an empty va=
lue, fall back to=0A=A0 the current use of the output of "ifconfog -l".=0A=
=0AMight want to set an emtpy value for the rc variable in=0A/etc/defaults/=
rc.conf.=0A=0A=0AThe reason the second one is an issue is that it seems to =
me that the=0Abehavior I'm seeing (where rc.d/netif tries the wired NIC fir=
st, then=0Athe wireless) is essentially an accident of the names chosen for=
 the=0ANICs, rather than something that an administrator can choose.=0A=0AF=
inally, I note that even in cases where I've disabled the wireless NIC,=0AI=
 see (e.g.):=0A=0A...=0AMay 27 14:08:45 d130 wpa_supplicant[374]: Failed to=
 initiate AP scan.=0AMay 27 14:09:16 d130 last message repeated 31 times=0A=
May 27 14:11:17 d130 last message repeated 121 times=0AMay 27 14:21:18 d130=
 last message repeated 600 times=0AMay 27 14:31:19 d130 last message repeat=
ed 600 times=0AMay 27 14:41:20 d130 last message repeated 600 times=0AMay 2=
7 14:51:21 d130 last message repeated 600 times=0AMay 27 15:01:22 d130 last=
 message repeated 600 times=0AMay 27 15:11:23 d130 last message repeated 60=
0 times=0AMay 27 15:21:24 d130 last message repeated 601 times=0AMay 27 15:=
31:25 d130 last message repeated 600 times=0AMay 27 15:41:26 d130 last mess=
age repeated 600 times=0A....=0A=0Awhich seems... well, not very clever.=A0=
 If I've disabled the wireless=0ANIC, I'd rather not have wpa_supplicant tr=
ying to do anything (at least,=0Awith the wireless NIC).=0A=0ASo -- am I ex=
hibiting my tendency toward "tunnel vision" again, or do=0Aparts of the abo=
ve seem to make some sense?=A0 Suggestions?=0A=0AThanks!=0A=0APeace,=0Adavi=
d=0A-- =0ADavid H. Wolfskill=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 david@c=
atwhisker.org=0ATaliban: Evil cowards with guns afraid of truth from a 14-y=
ear old girl.=0A=0ASee http://www.catwhisker.org/~david/publickey.gpg for m=
y public key.
From owner-freebsd-rc@FreeBSD.ORG  Thu May 29 16:16:17 2014
Return-Path: <owner-freebsd-rc@FreeBSD.ORG>
Delivered-To: freebsd-rc@freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org
 [IPv6:2001:1900:2254:206a::19:1])
 (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))
 (No client certificate requested)
 by hub.freebsd.org (Postfix) with ESMTPS id 3B6C3FD
 for <freebsd-rc@freebsd.org>; Thu, 29 May 2014 16:16:17 +0000 (UTC)
Received: from mail-qg0-x243.google.com (mail-qg0-x243.google.com
 [IPv6:2607:f8b0:400d:c04::243])
 (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits))
 (Client CN "smtp.gmail.com",
 Issuer "Google Internet Authority G2" (verified OK))
 by mx1.freebsd.org (Postfix) with ESMTPS id 0019A2A64
 for <freebsd-rc@freebsd.org>; Thu, 29 May 2014 16:16:16 +0000 (UTC)
Received: by mail-qg0-f67.google.com with SMTP id a108so509686qge.2
 for <freebsd-rc@freebsd.org>; Thu, 29 May 2014 09:16:16 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;
 h=mime-version:date:message-id:subject:from:to:content-type;
 bh=lYyZIoRfrGnfdSDXSuj/UKOZhACn9ctjQr+2qZl3+eY=;
 b=xYPXrcp7TRTcuFiWdeqhGvDonDvNzEr5EYt89Hnx/3vvY/hKhSsk0NRXf1TFJgLUVR
 ZrSBFbL7pyVWBzCJUTA7ZNsFB+PjypWMSTw/aSz/1u27kKLfuAauhXXdN/FUf+mt9cVa
 eFApG4JxtCFimuFJDH6lB+4Dqlbc5R+UETYl0vAutTQjffckJWMAe2enoVQZVNcn+Xk4
 IW1L3bm8ztYR4IhJ2flsrPZPjGKMoAN+ZeTxuXI44AjEXmwGOdmmr5Np+xb8xxjFyVCa
 QZkfxCh3+K/GtOGtaM9R7vKlnu1UoeaUoPWIuVawp1KxGvXWMRRDeU3NCHZolRYOyqsu
 gTvQ==
MIME-Version: 1.0
X-Received: by 10.224.16.199 with SMTP id p7mr11931385qaa.76.1401380175960;
 Thu, 29 May 2014 09:16:15 -0700 (PDT)
Received: by 10.229.14.196 with HTTP; Thu, 29 May 2014 09:16:15 -0700 (PDT)
Date: Thu, 29 May 2014 11:16:15 -0500
Message-ID: <CA+7eH3XGh5yfr8eFL3oDMM4cZRVvNJF48K89p-ek5co22VF0ig@mail.gmail.com>
Subject: Help needed to add scheduling to a small rc.d script
From: Pietro Sammarco <pietro.bsdml@gmail.com>
To: freebsd-rc@freebsd.org
Content-Type: text/plain; charset=UTF-8
X-Content-Filtered-By: Mailman/MimeDel 2.1.18
X-BeenThere: freebsd-rc@freebsd.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: "Discussion related to /etc/rc.d design and implementation."
 <freebsd-rc.freebsd.org>
List-Unsubscribe: <http://lists.freebsd.org/mailman/options/freebsd-rc>,
 <mailto:freebsd-rc-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/freebsd-rc/>;
List-Post: <mailto:freebsd-rc@freebsd.org>
List-Help: <mailto:freebsd-rc-request@freebsd.org?subject=help>
List-Subscribe: <http://lists.freebsd.org/mailman/listinfo/freebsd-rc>,
 <mailto:freebsd-rc-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Thu, 29 May 2014 16:16:17 -0000

Hello everyone,

let me begin saying I know very little about sh scripting and shell
scripting in general, so by reading here and there I have managed to create
a small sh scrip that ping google.com and if the ping timed out it will
take wlan0 down, take it back up and run dhclient on it.

Essentially what I need to do is to add a 30 seconds scheduling time to
this script, so that each and every 30 seconds it will check if
google.comis pingable, and if not it will do what the script it
supposed to do, and
at the same time I want to keep the start and stop feature.


Lastly, the main reason why I need to make this script is because when my
laptop resumes from suspending ( hw.acpi.lid_switch_state ) the wireless
goes numb, and those steps are required for the OS to associate with the AP
again, and becase this laptop is not always connected through wireless and
sometimes it act as gateway sharing the connection from the ethernet card
to the wireless card, I would rather avoid to make this script a cronjob.

Here's the mini script itself

Thanks

#!/bin/sh

. /etc/rc.subr

name="resumewlan"
start_cmd="resumewlan_start"
stop_cmd="resumewlan_stop"

if ! [ "`ping -c 1 google.com`" ]; then
    ifconfig wlan0 down & ifconfig wlan0 up & dhclient wlan0
#if ping timed out, takes down the wireless, takes it back up and executes
dhlient on it
   fi



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