From owner-freebsd-questions@FreeBSD.ORG Thu Apr 24 17:14:15 2014 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 090588A3 for ; Thu, 24 Apr 2014 17:14:15 +0000 (UTC) Received: from land.berklix.org (land.berklix.org [144.76.10.75]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 703C2158C for ; Thu, 24 Apr 2014 17:14:13 +0000 (UTC) Received: from mart.js.berklix.net (pD9FBE129.dip0.t-ipconnect.de [217.251.225.41]) (authenticated bits=128) by land.berklix.org (8.14.5/8.14.5) with ESMTP id s3OHDlqh025328; Thu, 24 Apr 2014 17:13:47 GMT (envelope-from jhs@berklix.com) Received: from fire.js.berklix.net (fire.js.berklix.net [192.168.91.41]) by mart.js.berklix.net (8.14.3/8.14.3) with ESMTP id s3OHDvHb070001; Thu, 24 Apr 2014 19:13:57 +0200 (CEST) (envelope-from jhs@berklix.com) Received: from fire.js.berklix.net (localhost [127.0.0.1]) by fire.js.berklix.net (8.14.7/8.14.7) with ESMTP id s3OHDXkZ013843; Thu, 24 Apr 2014 19:13:45 +0200 (CEST) (envelope-from jhs@berklix.com) Message-Id: <201404241713.s3OHDXkZ013843@fire.js.berklix.net> to: Rolf Nielsen Subject: Re: Running a command when a specific interface is created or destroyed From: "Julian H. Stacey" Organization: http://berklix.com BSD Unix Linux Consultants, Munich Germany User-agent: EXMH on FreeBSD http://berklix.com/free/ X-URL: http://www.berklix.com In-reply-to: Your message "Thu, 24 Apr 2014 08:51:08 -0600." Date: Thu, 24 Apr 2014 19:13:33 +0200 Cc: User questions X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 24 Apr 2014 17:14:15 -0000 Warren Block wrote: > On Thu, 24 Apr 2014, Rolf Nielsen wrote: > > > Hi, > > > > I use my phone's 3G/4G connection to connect my computer to the > > internet. With the help of the urndis driver, it comes up as ue0. > > However, if I reboot the computer, the phone automatically disables USB > > tethering, and I can't re-enable it until the boot is complete. > > > > Being somewhat paranoid, I use an OpenVPN service, and I want the cilent > > to start automatically. I obviously can't set it to start from rc.conf, > > as I can't log in to the server before I have an internet connection. > > > > So, is there a way to start the OpenVPN client automatically upon > > creation of the ue0 interface? E.g. can dhclient be set up to run the > > openvpn start script after it has given ue0 an IP address? And is there > > a way to automatically stop the openvpn client if ue0 is destroyed, e.g. > > if I disconnect my phone from the computer? > > devd(8) can do that. Look at /etc/devd.conf for some examples, and > devd.conf(5) for more detail. Yes, devd & its conf are very useful. > > So, is there a way to start the OpenVPN client automatically upon > > creation of the ue0 interface? Yes, Example: I automatically fetch a password (if environment is secure) to gbde decrypt & mount a UFS when a USB stick is attached. http://www.berklix.com/~jhs/src/bsd/fixes/FreeBSD/src/jhs/etc/devd/berklix.conf See lines beginning: gbde attach On detach, closing processes or unmounting file systems Before a device disappears is more problematic, as devd only gets nudged after. I suppose if a VPN has a watchdog/ keepalive, no problem. (For my crypted UFS, I should config AMD to umount my /media/* on timeout, [& remount on demand]). Cheers, Julian -- Julian Stacey, BSD Unix Linux C Sys Eng Consultant, Munich http://berklix.com Interleave replies below like a play script. Indent old text with "> ". Google breach privacy http://berklix.com/jhs/adverts/