From owner-freebsd-questions@FreeBSD.ORG Tue Jan 4 13:34:17 2005 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 5D54E16A4D0 for ; Tue, 4 Jan 2005 13:34:17 +0000 (GMT) Received: from catflap.slightlystrange.org (cpc2-cmbg1-3-0-cust94.cmbg.cable.ntl.com [213.107.104.94]) by mx1.FreeBSD.org (Postfix) with ESMTP id B5F9543D5A for ; Tue, 4 Jan 2005 13:34:16 +0000 (GMT) (envelope-from danielby@slightlystrange.org) Received: from danielby by catflap.slightlystrange.org with local (Exim 4.43 (FreeBSD)) id 1ClopD-000Gzu-ND for freebsd-questions@freebsd.org; Tue, 04 Jan 2005 13:34:15 +0000 Date: Tue, 4 Jan 2005 13:34:15 +0000 From: Daniel Bye To: FreeBSD-Questions Questions Message-ID: <20050104133415.GB57348@catflap.slightlystrange.org> Mail-Followup-To: FreeBSD-Questions Questions References: <15416223037.20050103193803@hexren.net> <6074EB8D-5DC6-11D9-89A5-000D93AD26C8@tntluoma.com> <41D9BA53.4060105@locolomo.org> <2DF07A46-5DD2-11D9-89A5-000D93AD26C8@tntluoma.com> <3E8DD18E8557227C2A3C8E5A@utd49554.utdallas.edu> <7C6BEBEDE2DB4AC7E55D6843@utd49554.utdallas.edu> <3D1AE682-5DDF-11D9-B56F-000D9333E43C@secure-computing.net> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="MfFXiAuoTsnnDAfZ" Content-Disposition: inline In-Reply-To: <3D1AE682-5DDF-11D9-B56F-000D9333E43C@secure-computing.net> User-Agent: Mutt/1.4.2.1i Subject: Re: my lame attempt at a shell script... X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: Daniel Bye List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Jan 2005 13:34:17 -0000 --MfFXiAuoTsnnDAfZ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Jan 03, 2005 at 05:28:56PM -0600, Eric F Crist wrote: > A couple more questions, then I'm done. Promise. >=20 > I need to verify whether or not there is an entry for grog_firewall_oif= =20 > and grog_firewall_iif in /etc/rc.conf. If not, I want to exit with an=20 > error. Read /etc/rc.conf into your script's namespace using the syntax already discussed in this thread (`. /etc/defaults/rc.conf'), and you can then test for the existence of any variable it defines (or doesn't define):=20 if [ -n "${grog_firewall_iif}" ] then # Do stuff if ${grog_firewall_iif} is set else # Do stuff if ${grog_firewall_iif} is NOT set fi Or, to reverse the logic, use [ -z "{grog_firewall_iif}" ] if [ -z "${grog_firewall_iif}" ] then # Do stuff if ${grog_firewall_iif} is NOT set else # Do stuff if ${grog_firewall_iif} is set fi > Also, a little more advanced, I need to pull information from an=20 > ifconfig output. I need to pull network numbers for both the internal=20 > interface, as well as external interface. For example, >=20 > vr0: flags=3D8843 mtu 1500 > inet 192.168.1.5 netmask 0xffffff00 broadcast 192.168.1.255 > inet6 fe80::20e:a6ff:feb9:2d3d%vr0 prefixlen 64 scopeid 0x3 > ether 00:0e:a6:b9:2d:3d > media: Ethernet autoselect (100baseTX ) > status: active >=20 > I don't actually need my own address, I need to be able to figure out=20 > that the system, based on the above output, is on the 192.168.1.0/24=20 > network. This will be input into my firewall rulesets. >=20 > I imagine that there's a util or command around that can do this, or I=20 > can code out the math, but there's got to be an easier way. ipfw(8) can understand the netmask in hex format, so you can simply say: ii_nw=3D$(ifconfig "${grog_firewall_iif}" | awk '/inet/ {print $2":"$4}') ${ii_nw} will now contain something like "192.168.37.23:0xffffff00", which you can safely pass to ipfw(8): (2)[root@ip73:~] ---># ipfw add 900 allow ip from any to 192.168.37.23:0xffffff00 00900 allow ip from any to 192.168.0.0/24 HTH Dan --=20 Daniel Bye PGP Key: ftp://ftp.slightlystrange.org/pgpkey/dan.asc PGP Key fingerprint: 3B9D 8BBB EB03 BA83 5DB4 3B88 86FC F03A 90A1 BE8F _ ASCII ribbon campaign ( ) - against HTML, vCards and X - proprietary attachments in e-mail / \ --MfFXiAuoTsnnDAfZ Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (FreeBSD) iD8DBQFB2ptXhvzwOpChvo8RAhtFAKCsrbyrowBN1g5v79TD98WupJTf2QCeOXb0 5OIs9LgQDQI6E4+E+Onq1HU= =q18/ -----END PGP SIGNATURE----- --MfFXiAuoTsnnDAfZ--