From owner-freebsd-bugs@freebsd.org Wed Aug 9 23:02:41 2017 Return-Path: Delivered-To: freebsd-bugs@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 2A1E0DD7D40 for ; Wed, 9 Aug 2017 23:02:41 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org (kenobi.freebsd.org [IPv6:2001:1900:2254:206a::16:76]) (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 152386400C for ; Wed, 9 Aug 2017 23:02:41 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from bugs.freebsd.org ([127.0.1.118]) by kenobi.freebsd.org (8.15.2/8.15.2) with ESMTP id v79N2eTM000702 for ; Wed, 9 Aug 2017 23:02:40 GMT (envelope-from bugzilla-noreply@freebsd.org) From: bugzilla-noreply@freebsd.org To: freebsd-bugs@FreeBSD.org Subject: [Bug 221379] bsdinstall(8): Installer doesn't support default router outside local subnet Date: Wed, 09 Aug 2017 23:02:41 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: bin X-Bugzilla-Version: CURRENT X-Bugzilla-Keywords: X-Bugzilla-Severity: Affects Some People X-Bugzilla-Who: nrg_freebsd-bugs@voidptr.de X-Bugzilla-Status: New X-Bugzilla-Resolution: X-Bugzilla-Priority: --- X-Bugzilla-Assigned-To: freebsd-bugs@FreeBSD.org X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version rep_platform op_sys bug_status bug_severity priority component assigned_to reporter Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: https://bugs.freebsd.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 09 Aug 2017 23:02:41 -0000 https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D221379 Bug ID: 221379 Summary: bsdinstall(8): Installer doesn't support default router outside local subnet Product: Base System Version: CURRENT Hardware: Any OS: Any Status: New Severity: Affects Some People Priority: --- Component: bin Assignee: freebsd-bugs@FreeBSD.org Reporter: nrg_freebsd-bugs@voidptr.de *Problem:* When the default gateway isn't contained in the subnet described by the loc= al system's IP address and Subnet mask, bsdinstall(8) fails when it tries to a= dd the default route, throwing the user back to the start of the install proce= ss. *Background:* IPv4 exhaustion has led some server providers to use rather questionable networking hacks to conserve IP space =E2=80=94 namely, using gateway addre= sses outside the local subnet so the first address on the local subnet (x.x.x.1) doesn't have to be a router and can be used for customer machines instead. I'm currently seeing this on a KVM virtual machine from OneProvider (an Online.net reseller), but apparently OVH, Hetzner, and a bunch of smaller players do the same thing. My (slightly anonymized) network config: vtnet0: inet 195.154.123.234 netmask 0xffffffff broadcast 195.154.123.234 Destination Gateway Flags Netif Expire default 62.210.112.1 UGS vtnet0 62.210.112.1 52:54:00:00:82:41 UHS vtnet0 On a "normal" FreeBSD system, this can be achieved using an rc.conf somethi= ng like this: ifconfig_vtnet0=3D"inet 195.154.123.234 netmask 255.255.255.255" gateway_if=3D"vtnet0" gateway_ip=3D"62.210.112.1" static_routes=3D"gateway default" route_gateway=3D"-host $gateway_ip -interface $gateway_if" route_default=3D"default $gateway_ip" Or temporarily using route(8): route add -host 62.210.112.1 -iface vtnet0 route add default 62.210.112.1 *Problem details:* The installer tries `route add default 62.210.112.1` directly, which of cou= rse fails because there is no route to 62.210.112.1 yet (see usr.sbin/bsdinstall/scripts/netconfig_ipv4:94 in base). Manually configuring the network from a shell doesn't work because `netconfig_ipv4` *always* re-configures (and thereby breaks) the network, e= ven when nothing was changed. Responding "No" to "Would you like to configure IPv4 for this interface?" a= lso doesn't help because something in bsdinstall(8) deletes the file behind the /etc/resolv.conf symlink every time the installer is launched. *Possible solutions (as far as I can see):* 1. As a workaround, we could at least stop bsdinstall from deleting/overwri= ting /etc/resolv.conf unless the user explicitly requests changes to the configuration. I've attached `always-write-resolvconf.patch` that gives the user an option= to configure resolv.conf even when they skipped the configuration of network addresses and gateways. 2. Preferably, `netconfig_ipv4` should detect the gateway-outside-subnet scenario and generate a working rc.conf for it. This is a bit more involved, mainly because we need to implement a portable method of detecting if a given IP (the gateway) is inside a given network (= the IP + subnet mask of the local machine). For this, I've built a truly awk-ful function =E2=80=94 I had to reimplemen= t bitwise operations from scratch because the awk version in FreeBSD base doesn't sup= port the `and()` function=E2=80=A6 >From there on it's just some additional shell code along the lines of `if ! router_inside_subnet; then route add -host $defaultrouter -iface $interface; fi; route add default $defaultrouter`. See `router-outside-subnet.patch` for that one. Probably needs some improvements in terms of readability. Testing should be less of an issue: the only finicky bit is the is-it-inside-subnet check, an= d if that crashes or gives a false-negative result, the script just adds a superfluous route that doesn't hurt anyone. --=20 You are receiving this mail because: You are the assignee for the bug.=