History log of /openbsd-current/etc/netstart
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.234 18-Dec-2022 kn

Revert previous as it doesn't create additional lo(4) anymore

Reported by Andreas Bartelt on bugs@


# 1.233 18-Dec-2022 kn

Do not try to create physical interfaces

vifscreate() always creates all virtual interfaces up-front.

To check whether a given interface exists, ifstart() uses ifcreate()
which tries to create nonexistent ones.

Virtual ones are guaranteed to be present and physical ones cannot be
created, so replace the ifcreate() call with a simpler ifconfig test and
clarify the comment.

OK martijn afresh1


# 1.232 16-Dec-2022 kn

zap double space and needless line break


# 1.231 16-Dec-2022 afresh1

Prioritize lladdr over name/unit in hostname.if processing

When needed, lladdr is more precise and enduring.

Suggested by deraadt@
Many improvments and OK kn@


# 1.230 05-Dec-2022 afresh1

Add support configuring hostname.if(5) by lladdr

Original implementation by martijn@
Feedback and suggestions from kn@, sthen@, claudio@, florian@, and deraadt@.

ok deraadt


# 1.229 05-Nov-2022 kn

"need root privileges" is an error, print it on stderr"


# 1.228 05-Nov-2022 kn

Print full path in usage; OK jmc


# 1.227 01-Nov-2022 kn

Only load the SOII key if IPv6 is available

Possible now that IP6KERNERL is hoisted.
This also improves readability and zaps double negation logic.


# 1.226 01-Nov-2022 kn

Do not wait for DAD completion in dry-run mode

1. only do so when running without -n
2. move code to own wait_dad() helper like wait_autoconf_default() has it
3. use local _count as usual in both functions rather than the global count

Feedback OK claudio


# 1.225 31-Oct-2022 kn

Hoist only the feature check

Keep adding IPv6 routes after lo0 got an addres like before, meant to be
committed together with r1.223.


# 1.224 31-Oct-2022 kn

Fix comment: IPv6 link local addresses do not use SOII anymore

sys/netinet6/in6_ifattach.c r1.114 limited it to SLAAC addresses in 2019.


# 1.223 31-Oct-2022 kn

Improve shell style wrt. variable naming/boolean convention

The mixed use of upper and lower case variables is neither obvious nor
consistent.

PRINT_ONLY is local to netstart.
ip6kernel is local to netstart.
multicast gets sourced from rc.subr(8).

1. uppercase ip6kernel as is common for global variables in base scripts
2. use the simpler true/false idiom and default with the rest of
netstart-only variables, making it clearer that only `multicast=YES/NO'
comes from the rc environment
3. hoist kernel feature detection such that a later diff can load the SOII
key conditionally
4. zap obvious comment

OK aja


# 1.222 24-Oct-2022 kn

do not wait for autoconf in dry-run

If there is no default route but some interface has AUTOCONF, printing
what would be done still waits for... nothing to happen.

OK tb


# 1.221 24-Oct-2022 kn

Add required sh(1) to synopsis

Contrary to other scripts in base like rc.d(8) or MAKEDEV(8), netstart(8)
itself is not executable and must be passed as file to sh(1):
$ man -h netstart
/etc/netstart [-n] [interface ...]
$ /etc/netstart
ksh: /etc/netstart: cannot execute - Permission denied

Fix usage and synopsis to provide required usage:
$ man -h netsart
sh /etc/netstart [-n] [interface ...]

OK jmc


# 1.220 21-Oct-2022 kn

Fix synopsis, -n does not require an interface; OK jmc


Revision tags: OPENBSD_7_2_BASE
# 1.219 03-Jul-2022 kn

Create virtual interfaces upfront if specified on the command line

In cases like `sh /etc/netstart pair1 pair2', one of hostname.pair{1,2}
will contain a "patch pair{2,1}" command which expects the other interface
to exist.

If none exist, this would fail and netstart had to be run separately or
"patch"ed interface had to be manually created before.

There are other use cases where interfaces depend on each other, so before
(re)configuring an explicit list of interfaces, create all virtual ones
upfront so that a single netstart invocation will configure everything
correctly without having reflect dependencies in multiple ordered netstart
invocations.

Copy isin() from install.sub to help.

Feedback OK halex


# 1.218 26-Jun-2022 florian

Wait for autoconf interfaces to come up in netstart(8) instead of
rc(8). This makes tunnel interfaces work that depend on working
autoconf interfaces.
OK deraadt


Revision tags: OPENBSD_7_1_BASE
# 1.217 22-Feb-2022 dlg

add some more tunnels to the list of interfaces that rely on routing.


Revision tags: OPENBSD_7_0_BASE
# 1.216 02-Sep-2021 bluhm

Do not create loopback interfaces lo1, lo2, ... upfront. They are
automatically set up by the kernel when a routing domain is created.
An existing lo1 in rdomain 0 would prevent to add any interfaces
in rdomain 1.
OK kn@


# 1.215 30-Aug-2021 bluhm

Improve dubgging in /etc/netstart. Enable print only in ifcreate.
Add debugging output for ipv6 routes. Make localhost and multicast
code aware of the print only switch. Allow netstart -n to work
also if no interface is given.
OK kn@


# 1.214 06-Aug-2021 sthen

As tim@ spotted, a use of V4_AUTOCONF crept in when the variable name
was actually V4_DHCPCONF from previous use. Rename all of the V4_DHCPCONF
to V4_AUTOCONF so everything uses the new name. ok and reminder about
the installer from tb@


# 1.213 16-Jul-2021 florian

switch to dhcpleased/resolvd in base
OK deraadt


# 1.212 20-Jun-2021 florian

Don't try to install a default route with route(8) later on if we are
using inet autoconf, like we do with "dhcp" and "inet6 autoconf".
OK kn


Revision tags: OPENBSD_6_9_BASE
# 1.211 23-Dec-2020 krw

Allow the provision of dhclient(8) options on 'dhcp' lines in hostname.if(5)
files.

Usual man page help & ok jmc@


# 1.210 21-Dec-2020 krw

Avoid issuing pointless 'ifconfig <if> up' when processing 'dhcp' in
hostname.if files. dhclient(8) does that itself. Part of the
"further script optimizations" promised in r1.200 of netstart.

Tested & ok gnezdo@


# 1.209 29-Nov-2020 tb

Fix previous: use correct version of netstart and installer bits.


# 1.208 29-Nov-2020 deraadt

Add support for !command to mygate, so that netstart has a late opportunity
to perform network configuration (for example, "!route source -ifp em0")
Split mygate and myname manual pages (how did anyone ever believe these
are related), and perform hostname configuration much earlier in rc.
discussed with benno, claudio, jmc, etc etc, last version of !command
parser by tb


# 1.207 08-Nov-2020 jmc

no more mobileip;
ok claudio deraadt


Revision tags: OPENBSD_6_8_BASE
# 1.206 21-Jun-2020 dlg

start wg with the other interfaces that rely on routing being up.

from Matt Dunwoodie and Jason A. Donenfeld

ok deraadt@


# 1.205 22-May-2020 kn

Revert the following commit as it breaks hostname.if(5) lines with a
backslash at the end for line continuation

Breaking long lines into multiple ones must still be possible and does
require to treat the backslash as an escape character.

Breakage reported by Mark Patruck <mark at wrapped dot cx >, thanks!

---
distrib/miniroot/install.sub revision 1.1151
etc/netstart revision 1.203
date: 2020/05/21 11:54:41; author: kn; state: Exp; lines: +2 -2;
Do not treat backslashe as an escape character in hostname.if(5) lines

ifstart() should always pass such lines unaltered, especially if they
contain "nwid" or "description" lines with arbitrary strings.

<bsdlisten at gmail dot com> reported SSIDs such as "Mike's" during
installation end as broken; this was because the installer escaped
the single quote using backslashes which ended up being treated as
escape characters much later during hostname.if parsing in netstart(8).

Ok deraadt


# 1.204 21-May-2020 kn

Fix stripcom() description wrt. comments not on their own line

Neither netstart's nor install.sub's (subtly different) implementations
remove trailing comments on lines not starting as a comment, e.g.,
lines like "up #not down" go through unaltered and without "#not down"
being removed.

Only lines *beginning* with the comment sign ("#") are stripped.

No functional change, just updating function descriptions.


# 1.203 21-May-2020 kn

Do not treat backslashe as an escape character in hostname.if(5) lines

ifstart() should always pass such lines unaltered, especially if they
contain "nwid" or "description" lines with arbitrary strings.

<bsdlisten at gmail dot com> reported SSIDs such as "Mike's" during
installation end as broken; this was because the installer escaped
the single quote using backslashes which ended up being treated as
escape characters much later during hostname.if parsing in netstart(8).

Ok deraadt


Revision tags: OPENBSD_6_7_BASE
# 1.202 15-Jan-2020 kn

Do not redirect already quiet stdout for IPv6 reject routes

"route -q" already silences all standard output; if it still prints
something, that's a bug to fix in route.

OK bluhm


# 1.201 25-Oct-2019 dlg

handle aggr(4) in the same way as trunk(4)

from brad@
ok bluhm@ claudio@ deraadt@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.200 29-Aug-2018 krw

Historically /etc/netstart (and the equivalent code in the install
script) did 'ifconfig <if> down' before starting dhclient(8). This was
a way of ensuring old running copies of dhclient were killed before a
new one started. Current dhclient does not need this assist, so change
"ifconfig <if> down" to "ifconfig <if> up" pending further script
optimizations.

Similar to a 2014 attempt by halex@. Prompted by a misc@ report
from Kristjan Komlosi reporting hanging diskless setups.

ok halex@ kn@


# 1.199 08-Jul-2018 tb

netstart is used during system start, but also interactively.
Show proper error message if a regular user executes netstart.
Only do the privilege check if the id binary is available,
which might not be the case during diskless system startup.

ok deraadt, jasper, jca, krw, rpe (who wrote the same diff), sthen


# 1.198 28-Apr-2018 rpe

Add a proper usage() function.

Suggested by and OK jmc.
OK tb


Revision tags: OPENBSD_6_3_BASE
# 1.197 04-Mar-2018 jmc

when -n is used, no need to spit out "Missing parameters." before
displaying usage();

ok tb


# 1.196 03-Mar-2018 landry

Lowercase 'usage' and group -n with interface in it.
From jmc@, ok tb@


# 1.195 21-Feb-2018 rpe

Tweak comments.

OK tb


# 1.194 19-Feb-2018 rpe

Write warning/error messages to stderr and end them with a fullstop.

OK tb


# 1.193 19-Feb-2018 rpe

- use specific patterns when looping over /etc/hostname.if files
to skip backup or temp files.
- test if the patterns matched actual files
- warn if ifcreate() fails on an interface and continue with the
subsequent interfaces in the list instead of return'ing

OK dlg sthen tb


# 1.192 17-Feb-2018 rpe

- Add descriptions for the new functions ifcreate() and vifscreate()
- In ifcreate() use the exit code of the {} block directly
- In vifscreate(), use the ifconfig -C output directly in the for _vif loop
- Remove superfluous and somewhat confusing comment

OK dlg kn sthen


# 1.191 14-Feb-2018 dlg

create virtual interfaces before starting all interface config.

this resolves an ordering problem when adding pseudo interfaces to bridges

tweaks from kn@
ok mpi@ sthen@


# 1.190 10-Feb-2018 claudio

Remove some special IPv4 in IPv6 mapped prefixes that are already rejected
by the ::0.0.0.0/96 reject route added to deny all IPv4 mapped addresses.
Makes the inet6 routing table almost fit in one screen.
OK benno@


# 1.189 10-Feb-2018 florian

Load RFC 7217 key material and generate if it does not already exist.

Add soii.key to changelist (pointed out by semarie) and mtree/special
(suggest by Craig Skinner).

OK naddy, sthen, rpe, tb


# 1.188 06-Feb-2018 tb

If -n is given, the netstart script should not (try to) set the default
route(s). Simply print the command(s) to be issued instead.

tweak & ok rpe


# 1.187 12-Nov-2017 tb

Remove HN_DIR variable and expand it in the only place it was used. It
currently serves no purpose.

ok rpe, agreement from deraadt and halex


Revision tags: OPENBSD_6_2_BASE
# 1.186 25-Jul-2017 rpe

Finally remove backwards compat code to support the 'rtsol' keyword
in hostname.if(5)

OK mpi@ deraadt@ florian@
OK jmc@ from doc perspective


# 1.185 21-Jul-2017 rpe

Align ifstart() in netstart and install.sub.

- in netstart, rename _file to _hn referencing hostname.if files
- in install.sub switch ifstart() to be used with _if instead of
_hn as parameter

ok krw@ tb@


# 1.184 28-May-2017 awolk

etc/netstart: use colon separator instead of dot with chown

OK jung@, deraadt@, jmc@


# 1.183 07-May-2017 rpe

Change test from [] to [[]] and simplify pattern.

OK tb@, krw@ (for [[]])
Feedback and OK halex@


# 1.182 07-May-2017 rpe

Replace hardcoded script name with ${0##*/}

OK tb@ halex@


# 1.181 01-May-2017 rpe

Revert r1.170 and remove the id==0 check.
The id binary is not available in nfs diskless setups at this point.

reported by Andreas Kusalananda, thanks.
discussed with deraadt@


# 1.180 01-May-2017 rpe

Remove last remnants of rtsol. IPv6 autoconfiguration of interfaces is now
done in ifstart(). Remove ipv6autoconf() and replace rtsolif with a boolean
variable V6_AUTOCONF. Replace dhcpif with a boolean variable V4_DHCPCONF.
Both are later used in defaultroute() to decide whether or not to configre
defaultroutes from /etc/mygate.

OK krw@


# 1.179 30-Apr-2017 mpi

Do not try to delete a default route before adding it.

Now that route are automatically G/C with the address they are attached
to there's no reason to duplicate the kernel's job.

Fix a regression introduced with multipath default routes.

ok deraadt@


# 1.178 25-Apr-2017 rpe

Unbreak netstart for multiple inteface configurations like trunk
or carp. Ensure that the noglob option is disabled at the end of
parse_hn_line() and ifstart().

Reported by Christer Solskogen and Stefan Wollny, thanks!


# 1.177 24-Apr-2017 rpe

Introduce a new function parse_hn_line() that replaces the existing
hostname.if(5) parsing code in ifstart().
Add a -n option to netstart to only print the interface configuration
commands instead of executing them.
Add a HN_DIR variable, that points to the directory of the hostname.if
files (default /etc) that allows for future regression tests.

- add new parse_hn_line() function
- change ifstart()
- rename $if to $_if
- don't ifconfig or ifconfig create if -n option is used
- replace hostname.if(5) parsing code with new parse_hn_line()
- just print configuration commands if -n option is used
- autoconf now happens in ifstart(), remove ifv6autoconf()
- introduce HN_DIR variable for the hostname.if file location
- add handling of the -n option to only print config commands
- ensure -n is only used if interfaces are specified as parameters

Discussed with and positive feedback from many
'commit' deraadt@
OK sthen@


# 1.176 08-Apr-2017 rpe

- localize the if, file and stat variables which also ensures that
variables are not named like commands.
- change test from [] to [[]]

OK tb@ halex@


# 1.175 07-Apr-2017 rpe

Minimize differences in ifstart() function between netstart and
install.sub which makes it easier to spot changes in the future.

- comments and formatting
- quotes on assignments are not needed (netstart)
- remove stray space in test (netstart)
- use $file variable with while-loop (netstart)
- although valid, instead of i use $i in arithmetic test (install.sub)

OK krw@, tb@
Looks good deraadt@


# 1.174 07-Apr-2017 rpe

Align comments of ifstart() function in netstart and install.sub.


# 1.173 07-Apr-2017 rpe

Align comments of stripcom() function in netstart and install.sub.


Revision tags: OPENBSD_6_1_BASE
# 1.172 06-Dec-2016 mpi

Do not lose the default route when netstart(8) is run a second time on
the interface pointed to by the default route.

Since the kernel no longer keep routes with dangling address pointer,
netstart(8) has to re-add the default route when the corresponding ifa
has been deleted and re-created.

deraadt@ points out that even if the previous semantic was not necessarily
better, a script like netstart(8) cannot totally fix the default route
problem.

Regression reported by and fix tested by Hrvoje Popovski.

ksh foo checked by halex@


# 1.171 27-Sep-2016 rzalamena

Delay switch(4) interface start up so it can attach virtual interfaces
like vether(4).

nits from and ok benno@, phessler@


# 1.170 09-Sep-2016 jasper

print a clear error message when not ran as root instead of just falling
through and try whatever it can do with the invoking user's perms

feedback/ok aja@ rpe@


Revision tags: OPENBSD_6_0_BASE
# 1.169 19-Jul-2016 mpi

Do not consider tap(4) a special interface and start if before other
pseudo-interfaces.

This unbreak vlan(4) on top of tap(4) since the refactoring to turn it
MP-safe.

ok claudio@, deraadt@


# 1.168 27-Mar-2016 sthen

Don't delete the 224/4 route in netstart, unless it's being done to ensure that
a -reject route can be added. Restores the ability to set an interface route
before daemons are started, lost during the previous simplification.
ok millert mpi


Revision tags: OPENBSD_5_9_BASE
# 1.167 29-Dec-2015 rpe

Remove backslash, not necessary after '&&'

OK halex@


# 1.166 29-Dec-2015 rpe

Replace last remaining `` with $()

OK halex@


# 1.165 18-Dec-2015 ajacoutot

Drop the now useless multicast setup comment.

prodded by tim@, ok mpi@


# 1.164 17-Dec-2015 ajacoutot

Simplify multicast option handling (10 less lines) by matching /etc/rc behavior
towards other YES|NO options and drop the error warning.


with and ok tim@, ok rpe@ on an earlier diff


# 1.163 05-Dec-2015 mpi

It does not make sense to insert a specific route for 224/4 when the
default one is good enough.

So merge rc.conf(8)'s 'multicast_router' and 'multicast_host' into a
single 'multicast'. If set to YES the reject route for 224/4 is not
inserted by netstart(8).

Manual bits from jmc@

ok henning@, ajacoutot@


# 1.162 12-Nov-2015 rpe

Changes to ifautostart():
- Rename function to ifv6autoconf() to make IPv6 relation clearer
- Localize and rename variables

OK krw@


# 1.161 12-Nov-2015 rpe

Changes to ifmstart():
- Change comments to make it clearer that ifmstart() takes two lists
of interface driver names (of which the second is optional) and not
the actual interface instances.
- Use localized variables and use slightly more verbose names.
- Use continue 2 to skip to the next hostname.if file.
- Use shell pattern @() instead of testing _sif individually.

OK krw@


# 1.160 12-Nov-2015 rpe

Changes to stripcom():
- Align comments with /etc/rc version
- Use localized variables
- Use safer "print -r --" instead of plain echo

Changes to ifstart():
- Tweak comment
- Add usage

OK krw@


# 1.159 01-Nov-2015 rpe

Start the rework of the /etc/netstart shell script.

General changes:
- apply a similar 'style' as used in the installer scripts
- improve comments to be more to the point, remove where code is obvious
- document usage of functions if they have arguments
- rename variables where it improves readability
- replace really old-school shell code with more contemporary idioms

Other changes:
- No need to care about "autoboot" because netstart doesn't inherit the
positional parameters from /etc/rc anymore. /etc/rc executes netstart
instead of sourcing it since r1.439.
- Use simpler for-loop to process list of interfaces with ifstart.

OK halex@


# 1.158 26-Oct-2015 rpe

The hostname variable is not used since r1.99. Remove it and use
stripcom() output directly with the hostname command.

OK deraadt@ krw@


# 1.157 23-Oct-2015 claudio

netstart bits for tap(4)


# 1.156 27-Sep-2015 sthen

Don't print output when setting autoconf on interfaces. Suggested by deraadt,
ok florian@ rpe@


# 1.155 13-Sep-2015 sthen

only print the "IPv6 autoconf" line if there are interfaces to configure
feedback/ok rpe


# 1.154 11-Sep-2015 sthen

Set "inet6 autoconf" individually on interfaces that have rtsol set in
hostname.if, previously netstart tried to configure them all at once
("ifconfig if0 if1 if2 inet6 autoconf"). From Delan Azabani, ok phessler@


Revision tags: OPENBSD_5_8_BASE
# 1.153 20-Jul-2015 rpe

Disable Strict Bourne shell mode for /etc/rc and /etc/netstart to be
able to use ksh syntax within these scripts. This way init doesn't
need to be changed, which starts /etc/rc using /bin/sh and people
can still use "sh /etc/netstart ifname".

Idea from and OK halex@
OK deraadt@ krw@ guenther@


# 1.152 19-Jul-2015 florian

Bring up pflow last as it might send with a source address that is on
any of the other interfaces.
OK deraadt, phessler, benno


# 1.151 19-Jul-2015 rpe

Always source rc.subr to be able to use the rc.conf parsing routine
to get the network related vars from rc.conf. This is even necessary
if netstart is run from within /etc/rc. Remove test of $INRC which
unintentionally evaluated always to true.

problem with previous change found by nigel@
OK sthen@ aja@ halex@


# 1.150 19-Jul-2015 ajacoutot

Revert 1.148 for now until I can talk to rpe@
It introduced a regression reported by nigel@


# 1.149 19-Jul-2015 rpe

Replace test command with [].

OK halex@ krw@


# 1.148 19-Jul-2015 rpe

Ensure, that we source rc.subr and parse rc.conf ONLY if we are not
inside /etc/rc.

With help from and OK halex@, ajacoutot@


# 1.147 18-Jul-2015 rpe

- remove trailing blanks introduced in previous commit
- no space in redirections like </foo or >$bar
- few other minor whitespaces

OK krw@


# 1.146 18-Jul-2015 rpe

Improve comments
- Add comments for functions
- Start comments with capital letters
- End comments with a full stop
- Allow comments to extend up to column 80

OK krw@


# 1.145 06-Jun-2015 florian

Allow rtsol keyword in hostname.if(5) with net.inet6.ip6.forwarding=1.
"inet6 autoconf" was working before and rtsol should behave the same.
OK phessler


Revision tags: OPENBSD_5_7_BASE
# 1.144 03-Dec-2014 florian

The kernel handles rtsol(8) functionality since some time now.
Treat rtsol in hostname.if as a keyword like dhcp and call ifconfig
inet6 autoconf.
"reads good" todd@
OK krw@ (who is *not* an IPv6 person), but I recruited him in his
capacity as an installer person.


# 1.143 28-Sep-2014 claudio

Revert 1.142. Without the down netstart will just print the ifconfig
output because it may end up just calling 'ifconfig $if'. This needs
to be done better and properly tested.


# 1.142 26-Sep-2014 halex

remove explicit 'down' of an interface before starting a dhcp request, thereby
avoiding annoying delays for some switch configurations

ok claudio@ deraadt@

i would add ok phessler@, but it was not valid without an ok krw@


Revision tags: OPENBSD_5_6_BASE
# 1.141 12-Jul-2014 stsp

Fix netstart after autoconf6 change so 'rtsol' lines in hostname.if work again.
found by pelikan@; ok pelikan@ henning@


# 1.140 12-Jul-2014 robert

Make rc.conf a parsed configuration file and stop sourcing it as a shell
script.
From now on rc.conf has a fixed syntax (key=val) and it is not allowed
to add anything to it besides the supported syntax, it all going to be
ignored.

discussed with and help from deraadt@ and halex@


Revision tags: OPENBSD_5_5_BASE
# 1.139 22-Aug-2013 mpi

Like for dhclient, do no create a route to alias addresses via 127.0.0.1.
Our stack is able to tell if the address is local or not.

ok todd@, krw@


Revision tags: OPENBSD_5_4_BASE
# 1.138 20-Mar-2013 todd

fix lies in netstart; replacement wording from halex@
pointed out by Ryan Kavannagh rak at debian dot org


Revision tags: OPENBSD_5_3_BASE
# 1.137 05-Dec-2012 rpe

remove "Invalid interface name" message
requested by krw@

ok halex@


# 1.136 02-Dec-2012 rpe

use the more compact version of the check for ifconfig'able interfaces
from install.sub

with feedback from and ok halex


# 1.135 02-Dec-2012 rpe

- remove isalphanumeric() and replace it with a shell pattern, that
tries a bit harder to identify invalid interface names and in
this case emit an error message.
- use [[ $1 == autoboot ]] to avoid a shell error message due to
possible spaces in first argument
- no change in functionality

discussed with krw and halex
ok ("I like this") krw


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.134 07-Oct-2011 deraadt

The new ypbind changes requires that the domainname be set before
rc.conf is run. There's no real downside.
ok aja


Revision tags: OPENBSD_5_0_BASE
# 1.133 07-Jul-2011 guenther

Eliminate some $? tests by rolling the command into the condition

ok halex@


# 1.132 26-May-2011 mpf

Add svlan(4) startup bits.
From markus@. OK naddy, claudio, reyk.


Revision tags: OPENBSD_4_9_BASE
# 1.131 09-Feb-2011 sobrado

fix an unbalanced parenthesis in a comment; while here, split the comment
in a better place to make it more readable.

ok jmc@ and miod@


Revision tags: OPENBSD_4_8_BASE
# 1.130 16-Jun-2010 todd

permit e.g. -inet6 syntax by slurping all lines not just some
noticed by rhsv6 at hushmail dot com, ok sthen@


Revision tags: OPENBSD_4_7_BASE
# 1.129 12-Jan-2010 henning

when setting up lo0 use 127.0.0.1/8 instead of 127.0.0.1 for clarity and
correctness. it's not 1992 any more, kids. ok mcbride dlg krw


# 1.128 10-Dec-2009 todd

o stop reordering ifconfig arguments (e.g. after 'up ..')
o only stop processing if inet or inet6 lines are malformed
o everything not a specially handled bit is passed to ifconfig unmangled
noticed by several after the move from bridgename.bridge0 -> hostname.bridge0
prodded by deraadt@, tested by and feedback from several
man page bits 'look fine' jmc@


# 1.127 22-Nov-2009 deraadt

Stop supporting bridgename.bridge* files, and move to hostname.bridge*
files. To cope with this change, read about the mv command.
ok claudio todd


# 1.126 17-Sep-2009 simon

change variable i to $i in an expression of ifstart() for consistency
with the rest of the file. no functional change.

feedback from sthen@, ok krw@


# 1.125 10-Jul-2009 jdixon

Delay creation of tun(4) interfaces until the underlying interface and
routes are available. This fixes usage for some OpenVPN users that start
it from hostname.tun*.

Tested by Johan Huldtgren. ok sthen@, johan@.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.124 25-Nov-2008 markus

delay /etc/netstart until IPv6-DAD (dup-address-detection) is completed.
ok fries, hshoexer, claudio


# 1.123 14-Aug-2008 sthen

Tools from /usr may not be used in netstart since it may be NFS-mounted
and not available at that time. Rewrite the hostname.if permission check
to use only /bin/ls and the shell. Requested by deraadt.

ok todd, "Twisted." deraadt


Revision tags: OPENBSD_4_4_BASE
# 1.122 23-Jul-2008 sthen

Prevent warning about insecure hostnames where no /etc/hostname.*
exists. From wcmaier@.

Check target of symbolic links to avoid noise at boot and in
seucrity output where you have several interfaces symlinked to one
config file.

"If you think this is the right thing to do" deraadt@


# 1.121 09-Jun-2008 todd

warn once not 3 times in case of a non existent file, discussed with deraadt
originally pointed out by Johan Torin


# 1.120 09-Jun-2008 deraadt

Ensure that hostname.* files are also re-chowned to root.wheel at each
boot as discussed with claudio while eating tasty donairs. ok todd


# 1.119 17-Apr-2008 deraadt

before using them, force hostname.* files to be unreadable by world
first version from todd, ok millert


Revision tags: OPENBSD_4_3_BASE
# 1.118 17-Jan-2008 brad

Execute rtsol after turning up trunk(4) and vlan(4) interfaces so they're
taken into consideration for rtsol.

ok reyk@ dlg@


# 1.117 09-Jan-2008 mpf

Do not bring up pfsync(4) before the working ruleset
has been loaded. Otherwise, states that are received during the
initial bulk update mismatch the correct pf-checksum and
do not attach to the rules.
Problem identified by david@. Fix done in collaboration.
OK henning@


Revision tags: OPENBSD_4_2_BASE
# 1.116 02-Aug-2007 david

move the delay for IPv6 DAD to after all interfaces have started
fixes problems with daemons being unable to bind to all addreses at boot
ok itojun@ hshoexer@


Revision tags: OPENBSD_4_1_BASE
# 1.115 15-Nov-2006 itojun

reject multicast packet without scope identifier specified.


Revision tags: OPENBSD_4_0_BASE
# 1.114 29-Jun-2006 todd

do not add an extra space; nwid and description come out wrong
fix as proposed by maja@, thanks!


Revision tags: OPENBSD_3_9_BASE
# 1.113 28-Dec-2005 david

nuke extra whitespace


# 1.112 06-Dec-2005 reyk

multicast_host=YES only works if a valid default gateway is available.
validate this condition and reject multicast traffic on failure.

ok todd@ naddy@


# 1.111 02-Nov-2005 todd

fix inspired by pr#4590
ok krw@


# 1.110 25-Oct-2005 todd

better logic from krw@:
- do not process mygate for v4 if dhcp
- do not process mygate for v6 if rtsol
this also makes the mygate processing logic more readable
ok krw@


# 1.109 14-Oct-2005 todd

add v6 support for /etc/mygate
ok deraadt@ mickey@ krw@
same functionality tested/ok'ed by by mickey, brad, matthieu, and me
with this one may now put a v6 IP in /etc/mygate on a separate line from
the v4 default gateway and netstart will do the right thing


# 1.108 12-Oct-2005 todd

shrink stripcom(), sync with install.sub
ok krw@


# 1.107 04-Oct-2005 todd

trunk must be started after physical ethernet devices, but before vlan.
populate ifmstart lines accordingly.
prodded/tested by brad@
ok reyk@


# 1.106 28-Sep-2005 todd

use eval consistently, fixes description quotes on rtsol and dhcp
fix inspired by and closes pr 4495
ok krw@


Revision tags: OPENBSD_3_8_BASE
# 1.105 22-May-2005 todd

Introduce 'ifmstart' to deal with starting multiple interfaces minus a list
of interfaces.

This reduces the netstart script by 174 chars, 13 words, and 19 lines, but
more importantly, makes it more simple and less cluttered should more special
case/orderings be needed.

ok brad@ and pr 4197 submitter, inspired by and closes pr 4197


# 1.104 04-Apr-2005 djm

unbreak; ok pval@


# 1.103 03-Apr-2005 deraadt

if dhcp is used to get an address on any interface, ignore /etc/mygate
ok krw
(this lets us do something rather cool with the zaurus in particular)


Revision tags: OPENBSD_3_7_BASE
# 1.102 04-Jan-2005 mcbride

Bring up the carp(4) interface before default route.

ok pascoe@ mpf@


# 1.101 30-Dec-2004 millert

Add a copy of stripcom so /etc/netstart can be run standalone again.
OK deraadt@


# 1.100 19-Dec-2004 millert

Allow comments in /etc/{myname,mygate,defaultdomain}; OK deraadt@


# 1.99 04-Dec-2004 itojun

remove "route $hostname 127.0.0.1" line. deraadt ok
*** please update /etc/netstart and test if it works ok for you ***


# 1.98 20-Oct-2004 deraadt

make all route commands use -qn; ok mcbride henning


Revision tags: OPENBSD_3_6_BASE
# 1.97 29-May-2004 deraadt

one last route command lacking -qn


Revision tags: OPENBSD_3_5_BASE
# 1.96 22-Mar-2004 mcbride

Make sure pfsync is brought up before carp.

ok deraadt@


# 1.95 13-Mar-2004 mcbride

Delay pfsync(4) configuration, as the syncif has to be configured in
advance. From Thorsten Lockert.


# 1.94 14-Jan-2004 deraadt

ok, it took quite a bit of prodding but itojun finally explained why the
extra sleep 1 is in here, and we came to the conclusion it is safe to
delete it. whee.


# 1.93 13-Jan-2004 deraadt

repair v6 lo0 documentation


# 1.92 11-Jan-2004 deraadt

add loopback routes late


# 1.91 09-Jan-2004 deraadt

create all routes with -q; markus ok


# 1.90 04-Dec-2003 millert

Need to do "ifconfig create" for bridge interfaces too.


# 1.89 03-Dec-2003 markus

add support for ifconfig clone; from netbsd; ok deraadt, henning


# 1.88 20-Oct-2003 david

delay carp initialization until after physical interfaces are configured
ok mcbride@ henning@ deraadt@ todd@


Revision tags: OPENBSD_3_4_BASE
# 1.87 27-Aug-2003 henning

only try to set hostname to what /etc/myname says if that file actually exists,
otherwise preserve `hostname`
netbooted machines can live perfectly fine without it; they get their hostname
earlier.

ok krw@ cedric@


Revision tags: OPENBSD_3_3_BASE
# 1.86 16-Feb-2003 krw

Fix up some DNS verbiage to make it consistant.

Fix up default route selection by

a) Forcing user to explicitly chose 'dhcp' as a mechanism for
specifying a default route, rather than guessing based on one or more
interfaces being configured by dhcp.

b) If the user specified default route does not work, re-present the
existing default route rather than losing it.

c) Move default route selection to after nameserver activation so the
user can specify a hostname as the default route.

Change /etc/netstart so that /etc/mygate wins if a default route was
already specified (i.e. by dhcp).

ok deraadt@.


Revision tags: OPENBSD_3_2_BASE
# 1.85 16-May-2002 todd

ignore non-existent cases where '$if' evaluates to '*'.
From Andr� Lucas <andre@ae-35.com>, fixes pr # 2658.
'Looks good' from miod@, millert@, and krw@.


Revision tags: OPENBSD_3_1_BASE
# 1.84 23-Feb-2002 deraadt

re-add support for $if expansion; hamajima@nagoya.ydc.co.jp


# 1.83 21-Feb-2002 miod

Change the network components initialization order.
Change from:
o all interfaces
o all bridges
o routes
to:
o physical interfaces
o routes
o gif and gre interfaces
o bridges

Fixeski PR #2400.
Manual page updates coming soon.
Ok angelos@ chris@ deraadt@


Revision tags: OPENBSD_3_0_BASE
# 1.82 31-Jul-2001 hugh

a space before a redirect


# 1.81 06-Jul-2001 angelos

Also, source /etc/rc.conf so we can pull in the
multicast_host/multicast_router settings; this is useful if one
flushes the routing table and re-initializes.

We really need a netconfig tool of sorts.


# 1.80 06-Jul-2001 angelos

Use "route -n show -inet" to determine the default multicast iface.


# 1.79 03-Jul-2001 deraadt

pull in rc.conf early so that pf(1) startup is right; tested by jasoni, comments from millert


# 1.78 30-May-2001 deraadt

Remove ipf. Darren Reed has interpreted his (old, new, whichever)
licence in a way that makes ipf not free according to the rules we
established over 5 years ago, at www.openbsd.org/goals.html (and those
same basic rules govern the other *BSD projects too). Specifically,
Darren says that modified versions are not permitted. But software
which OpenBSD uses and redistributes must be free to all (be they
people or companies), for any purpose they wish to use it, including
modification, use, peeing on, or even integration into baby mulching
machines or atomic bombs to be dropped on Australia. Furthermore, we
know of a number of companies using ipf with modification like us, who
are now in the same situation, and we hope that some of them will work
with us to fill this gap that now exists in OpenBSD (temporarily, we
hope).


Revision tags: OPENBSD_2_9_BASE
# 1.77 13-Mar-2001 deraadt

spelling; maurice@maurice.wan.nl


# 1.76 06-Feb-2001 todd

ignore blank lines in addition to comments
fixes pr#1660 from wilfried@telia.com .. Thanks!


# 1.75 10-Jan-2001 jason

support !command in bridgename.if files, too


# 1.74 27-Nov-2000 millert

Use -n to test if a variable is non-zero. Otherwise, if the variable's
contents start with a '-' test becomes unhappy (since it interprets it
as another option).


# 1.73 08-Nov-2000 todd

This fixes pr 1481, we now handle args > 6 in /etc/hostname.if in the
cases where we did not previously handle them.
Thanks to Scott Atwood <atwood@cs.stanford.edu> for reminding us of this.


Revision tags: OPENBSD_2_8_BASE
# 1.72 02-Sep-2000 todd

subtle bug .. global variables in a while loop need reset 'just incase'
With:
hostname.fxp0 having a last line of:
inet6 alias 3ffe:...
and hostname.gif0 having a first two lines of:
giftunnel 1.2.3.4
dest 1.2.4.3
We end up with the command:
ifconfig gif0 giftunnel alias 1.2.3.4 1.2.4.3
.. which is clearly wrong and fixed by this change


# 1.71 18-Jun-2000 todd

rc.conf now parses ${local_rcconf} internally; closes pr 1259


Revision tags: OPENBSD_2_7_BASE
# 1.70 08-May-2000 todd

fix dhcp 'NONE' ness from install to allow media parsing to work
.. ok deraadt@, millert@


# 1.69 21-Apr-2000 deraadt

rc.conf.local support, inspired by chuck yerkes


# 1.68 04-Apr-2000 millert

Remove the -E flag from ipf as it is implicitly enabled and using
the -E flag here causes the kernel to printf 'IP Filter: already
initialized'.


# 1.67 18-Mar-2000 deraadt

silence all extra route addition printouts


# 1.66 17-Mar-2000 itojun

correct reject route installations for IPv6. improve comments.


# 1.65 12-Mar-2000 itojun

disallow packets to malicious 6to4 prefix, based on
http://playground.iijlab.net/i-d/draft-itojun-ipv6-transition-abuse-00.txt


# 1.64 10-Mar-2000 todd

fix non behavior
with this `!' lines in /etc/hostname.* run even without certain lines
(like a comment) preceeding it.


# 1.63 10-Jan-2000 todd

allow arbitrary commands in /etc/hostname.* files if the line starts with '!'


# 1.62 02-Jan-2000 deraadt

rtsol case can configure the interface up, since it would be nice to finish
DAD before the actual rtsol(8) run happens later. and since it will rtsol,
it is going to be up in any case.


# 1.61 02-Jan-2000 itojun

one more indentation fix.


# 1.60 02-Jan-2000 itojun

indentation fix (todd's part)


# 1.59 02-Jan-2000 todd

fix rtsold case, reset cmd for each iteration!


# 1.58 02-Jan-2000 itojun

allow options after "rtsol".
XXX both "dhcp" and "rtsol" has keyword *down* at the end. is it okay?


# 1.57 02-Jan-2000 itojun

echo "IPv6 autoconf: interfaces" before invoking rtsol.
sleep for net.inet6.ip6.dad_count seconds to ensure that IPv6 DAD is completed.
TODO: rtsold (rc.conf line), manpage


# 1.56 02-Jan-2000 itojun

ipv6 autoconf on hosts (non-routers).

to do this,
1. in sysctl.conf, add these lines:
net.inet6.ip6.forwarding=0
net.inet6.ip6.accept_rtadv=1
2. in hostname.foo, add
rtsol

specifying two or more interfaces with "rtsol" may result in strange
behavior - ipv6 spec does not permit multi-interface node to be autoconfig'ed.


# 1.55 02-Jan-2000 todd

add to hostname.* parsing:
- multiple entries support (read: aliases)
- inet6 support
- support for comments (#)
(look for hostname.if(5) commit for syntax details)


# 1.54 31-Dec-1999 itojun

install IPv6 reject routes only if kernel is capable of IPv6.


# 1.53 09-Dec-1999 itojun

avoid transmitting invalid IPv6 packets out to the wire.


# 1.52 09-Dec-1999 itojun

do not perform IPv6 initialization for loopback interface.
MUST make lo0 up before any IPv6 operations.
it will be considered a pilot error if you don't.
(I prefer to have lo0 initialized automatically)


Revision tags: OPENBSD_2_6_BASE
# 1.51 01-Sep-1999 deraadt

support # characters in bridgename.* files; millert


# 1.50 01-Sep-1999 deraadt

cleanup parsing of hostname.* files, and seperate bridge control into
bridgename.* files; all documented in new hostname.if(5) and
bridgename.if(5) man pages


# 1.49 09-Aug-1999 angelos

Only parse/setup the hostname.foo file if interface foo exists (this
is useful for laptops with different ethernet cards etc.)


Revision tags: OPENBSD_2_5_BASE
# 1.48 29-Mar-1999 niklas

New multicast route setup style


# 1.47 26-Mar-1999 niklas

Add bridge interface handling


# 1.46 01-Mar-1999 millert

Add support in /etc/hostname.xxx for files of the format:
up [options]
Any of the following may or may not be set:
$name $mask $bcaddr $extras


# 1.45 28-Oct-1998 millert

Kill the awful hack used to match and split /etc/hostname.* We now use
a function, isalphanumeric, to determine whether an interface name is
likely to be valid. This means that things like /etc/hostname.le0.bak,
/etc/hostname.le0#, /etc/hostname.le0~, etc. will be ignored as they
should. There is no longer an implicate assumption that /etc/hostname.*
only contains a single '.'.


Revision tags: OPENBSD_2_4_BASE
# 1.44 06-Oct-1998 deraadt

move ipnat to end of netstart, to support dhcp+ipnat


# 1.43 18-Sep-1998 deraadt

apply media directives on dhcp interfaces


# 1.42 10-Sep-1998 marc

better way of handling dhcp client; Jason Ish <jbi130@mail.usask.ca>


# 1.41 08-Sep-1998 marc

dhcp client stuff. "Angelos D. Keromytis" <angelos@dsl.cis.upenn.edu>


# 1.40 24-Aug-1998 downsj

You can't use -interface default when there's no default gateway
set (yet). Use -interface $hostname if mygate doesn't exist so that
this actually works on routers.


# 1.39 04-Jul-1998 deraadt

put 224 route on default, to avoid a hostname lookup


# 1.38 22-May-1998 deraadt

use route -n, what the heck


Revision tags: OPENBSD_2_3_BASE
# 1.37 28-Mar-1998 deraadt

s/^nat/ipnat/


# 1.36 23-Feb-1998 niklas

remove trailing blank line


# 1.35 07-Feb-1998 deraadt

ipforward is in sysctl.conf now


# 1.34 21-Dec-1997 deraadt

ugh


# 1.33 20-Dec-1997 deraadt

ipforwarding option in rc.conf


# 1.32 29-Nov-1997 kstailey

NAT requires IPF


# 1.31 04-Nov-1997 deraadt

kill spaces at ends of lines; m4


Revision tags: OPENBSD_2_2_BASE
# 1.30 14-Oct-1997 deraadt

set hostname/domainname before running rc.conf; m4@umn.edu


# 1.29 04-Sep-1997 deraadt

fork netstart; new child is rc.conf


# 1.28 25-Aug-1997 millert

Explicately pass -host flag to route(8) to avoid confusion with networks.


# 1.27 19-Aug-1997 niklas

Add hook for rpc.lockd, make nfsd flags settable in netstart


# 1.26 31-Jul-1997 downsj

Make quotas optional; wedged into netstart for the time being.
/etc/rc.conf, anyone?


# 1.25 30-Jul-1997 deraadt

do not run routed by default


# 1.24 28-Jul-1997 kstailey

Move configuration of loopback interface to before all other interfaces.
Allows the use of local caching-only nameserver with no "nameserver"
entry in /etc/resolv.conf to configure a route between the hostname
and loopback.


# 1.23 25-Jul-1997 provos

earlier start of keymanagement


# 1.22 24-Jul-1997 deraadt

make amd use /tmp_mnt by default


# 1.21 22-Jul-1997 provos

start the photuris daemon per default. hilfe.


# 1.20 17-Jun-1997 niklas

Put in hooks to start ypserv with flags


# 1.19 17-Jun-1997 niklas

Put in hooks to start rpc.yppasswdd with flags


Revision tags: OPENBSD_2_1_BASE
# 1.18 15-Apr-1997 deraadt

kill route flush until .. hmm kernel routing socket bug or something


# 1.17 09-Apr-1997 kstailey

add NAT startup


# 1.16 07-Apr-1997 rees

flush all old routes before adding new interfaces or routes.
ref: netbsd pr3228/misc, Matthias Scheler


# 1.15 03-Mar-1997 downsj

fix typo


# 1.14 11-Feb-1997 deraadt

add default route before fiddling with loopback route to avoid DNS problems; m4@umn.edu, #97


# 1.13 03-Feb-1997 deraadt

do ifaliases after /usr/bin exists in nfs diskless env; pr#77, matthieu@laas.fr


# 1.12 02-Nov-1996 deraadt

timed off by default


Revision tags: OPENBSD_2_0_BASE
# 1.11 23-Sep-1996 deraadt

rfc1323 variable


# 1.10 04-Sep-1996 deraadt

control portmap, inetd, and lpd from netstart; idea from tqbf@enteract.com


# 1.9 27-Aug-1996 deraadt

224.0.0.0 not 0.0.0.224; from peter@demon.net


# 1.8 18-Jun-1996 deraadt

move std stuff from rc.local to rc


# 1.7 16-Jun-1996 deraadt

install sample commented /etc/ifaliases file; which can now contain #
comments and blank lines. new format is "interface address netmask"
(yes, i changed the order of the entries). inspired by netbsd pr#2474;
gillhaa@ghost.whirlpool.com


# 1.6 02-Jun-1996 tholo

Install a multicast route by default


# 1.5 26-May-1996 deraadt

sync & label


# 1.4 09-Jan-1996 dm

added IP filter to netstat/rc and put examples in /usr/share/ipf


# 1.3 30-Dec-1995 deraadt

from netbsd: start mrouted like routed


# 1.2 18-Dec-1995 deraadt

/etc/ifaliases support by randy@zyzzyva.com


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.234 18-Dec-2022 kn

Revert previous as it doesn't create additional lo(4) anymore

Reported by Andreas Bartelt on bugs@


# 1.233 18-Dec-2022 kn

Do not try to create physical interfaces

vifscreate() always creates all virtual interfaces up-front.

To check whether a given interface exists, ifstart() uses ifcreate()
which tries to create nonexistent ones.

Virtual ones are guaranteed to be present and physical ones cannot be
created, so replace the ifcreate() call with a simpler ifconfig test and
clarify the comment.

OK martijn afresh1


# 1.232 16-Dec-2022 kn

zap double space and needless line break


# 1.231 16-Dec-2022 afresh1

Prioritize lladdr over name/unit in hostname.if processing

When needed, lladdr is more precise and enduring.

Suggested by deraadt@
Many improvments and OK kn@


# 1.230 05-Dec-2022 afresh1

Add support configuring hostname.if(5) by lladdr

Original implementation by martijn@
Feedback and suggestions from kn@, sthen@, claudio@, florian@, and deraadt@.

ok deraadt


# 1.229 05-Nov-2022 kn

"need root privileges" is an error, print it on stderr"


# 1.228 05-Nov-2022 kn

Print full path in usage; OK jmc


# 1.227 01-Nov-2022 kn

Only load the SOII key if IPv6 is available

Possible now that IP6KERNERL is hoisted.
This also improves readability and zaps double negation logic.


# 1.226 01-Nov-2022 kn

Do not wait for DAD completion in dry-run mode

1. only do so when running without -n
2. move code to own wait_dad() helper like wait_autoconf_default() has it
3. use local _count as usual in both functions rather than the global count

Feedback OK claudio


# 1.225 31-Oct-2022 kn

Hoist only the feature check

Keep adding IPv6 routes after lo0 got an addres like before, meant to be
committed together with r1.223.


# 1.224 31-Oct-2022 kn

Fix comment: IPv6 link local addresses do not use SOII anymore

sys/netinet6/in6_ifattach.c r1.114 limited it to SLAAC addresses in 2019.


# 1.223 31-Oct-2022 kn

Improve shell style wrt. variable naming/boolean convention

The mixed use of upper and lower case variables is neither obvious nor
consistent.

PRINT_ONLY is local to netstart.
ip6kernel is local to netstart.
multicast gets sourced from rc.subr(8).

1. uppercase ip6kernel as is common for global variables in base scripts
2. use the simpler true/false idiom and default with the rest of
netstart-only variables, making it clearer that only `multicast=YES/NO'
comes from the rc environment
3. hoist kernel feature detection such that a later diff can load the SOII
key conditionally
4. zap obvious comment

OK aja


# 1.222 24-Oct-2022 kn

do not wait for autoconf in dry-run

If there is no default route but some interface has AUTOCONF, printing
what would be done still waits for... nothing to happen.

OK tb


# 1.221 24-Oct-2022 kn

Add required sh(1) to synopsis

Contrary to other scripts in base like rc.d(8) or MAKEDEV(8), netstart(8)
itself is not executable and must be passed as file to sh(1):
$ man -h netstart
/etc/netstart [-n] [interface ...]
$ /etc/netstart
ksh: /etc/netstart: cannot execute - Permission denied

Fix usage and synopsis to provide required usage:
$ man -h netsart
sh /etc/netstart [-n] [interface ...]

OK jmc


# 1.220 21-Oct-2022 kn

Fix synopsis, -n does not require an interface; OK jmc


Revision tags: OPENBSD_7_2_BASE
# 1.219 03-Jul-2022 kn

Create virtual interfaces upfront if specified on the command line

In cases like `sh /etc/netstart pair1 pair2', one of hostname.pair{1,2}
will contain a "patch pair{2,1}" command which expects the other interface
to exist.

If none exist, this would fail and netstart had to be run separately or
"patch"ed interface had to be manually created before.

There are other use cases where interfaces depend on each other, so before
(re)configuring an explicit list of interfaces, create all virtual ones
upfront so that a single netstart invocation will configure everything
correctly without having reflect dependencies in multiple ordered netstart
invocations.

Copy isin() from install.sub to help.

Feedback OK halex


# 1.218 26-Jun-2022 florian

Wait for autoconf interfaces to come up in netstart(8) instead of
rc(8). This makes tunnel interfaces work that depend on working
autoconf interfaces.
OK deraadt


Revision tags: OPENBSD_7_1_BASE
# 1.217 22-Feb-2022 dlg

add some more tunnels to the list of interfaces that rely on routing.


Revision tags: OPENBSD_7_0_BASE
# 1.216 02-Sep-2021 bluhm

Do not create loopback interfaces lo1, lo2, ... upfront. They are
automatically set up by the kernel when a routing domain is created.
An existing lo1 in rdomain 0 would prevent to add any interfaces
in rdomain 1.
OK kn@


# 1.215 30-Aug-2021 bluhm

Improve dubgging in /etc/netstart. Enable print only in ifcreate.
Add debugging output for ipv6 routes. Make localhost and multicast
code aware of the print only switch. Allow netstart -n to work
also if no interface is given.
OK kn@


# 1.214 06-Aug-2021 sthen

As tim@ spotted, a use of V4_AUTOCONF crept in when the variable name
was actually V4_DHCPCONF from previous use. Rename all of the V4_DHCPCONF
to V4_AUTOCONF so everything uses the new name. ok and reminder about
the installer from tb@


# 1.213 16-Jul-2021 florian

switch to dhcpleased/resolvd in base
OK deraadt


# 1.212 20-Jun-2021 florian

Don't try to install a default route with route(8) later on if we are
using inet autoconf, like we do with "dhcp" and "inet6 autoconf".
OK kn


Revision tags: OPENBSD_6_9_BASE
# 1.211 23-Dec-2020 krw

Allow the provision of dhclient(8) options on 'dhcp' lines in hostname.if(5)
files.

Usual man page help & ok jmc@


# 1.210 21-Dec-2020 krw

Avoid issuing pointless 'ifconfig <if> up' when processing 'dhcp' in
hostname.if files. dhclient(8) does that itself. Part of the
"further script optimizations" promised in r1.200 of netstart.

Tested & ok gnezdo@


# 1.209 29-Nov-2020 tb

Fix previous: use correct version of netstart and installer bits.


# 1.208 29-Nov-2020 deraadt

Add support for !command to mygate, so that netstart has a late opportunity
to perform network configuration (for example, "!route source -ifp em0")
Split mygate and myname manual pages (how did anyone ever believe these
are related), and perform hostname configuration much earlier in rc.
discussed with benno, claudio, jmc, etc etc, last version of !command
parser by tb


# 1.207 08-Nov-2020 jmc

no more mobileip;
ok claudio deraadt


Revision tags: OPENBSD_6_8_BASE
# 1.206 21-Jun-2020 dlg

start wg with the other interfaces that rely on routing being up.

from Matt Dunwoodie and Jason A. Donenfeld

ok deraadt@


# 1.205 22-May-2020 kn

Revert the following commit as it breaks hostname.if(5) lines with a
backslash at the end for line continuation

Breaking long lines into multiple ones must still be possible and does
require to treat the backslash as an escape character.

Breakage reported by Mark Patruck <mark at wrapped dot cx >, thanks!

---
distrib/miniroot/install.sub revision 1.1151
etc/netstart revision 1.203
date: 2020/05/21 11:54:41; author: kn; state: Exp; lines: +2 -2;
Do not treat backslashe as an escape character in hostname.if(5) lines

ifstart() should always pass such lines unaltered, especially if they
contain "nwid" or "description" lines with arbitrary strings.

<bsdlisten at gmail dot com> reported SSIDs such as "Mike's" during
installation end as broken; this was because the installer escaped
the single quote using backslashes which ended up being treated as
escape characters much later during hostname.if parsing in netstart(8).

Ok deraadt


# 1.204 21-May-2020 kn

Fix stripcom() description wrt. comments not on their own line

Neither netstart's nor install.sub's (subtly different) implementations
remove trailing comments on lines not starting as a comment, e.g.,
lines like "up #not down" go through unaltered and without "#not down"
being removed.

Only lines *beginning* with the comment sign ("#") are stripped.

No functional change, just updating function descriptions.


# 1.203 21-May-2020 kn

Do not treat backslashe as an escape character in hostname.if(5) lines

ifstart() should always pass such lines unaltered, especially if they
contain "nwid" or "description" lines with arbitrary strings.

<bsdlisten at gmail dot com> reported SSIDs such as "Mike's" during
installation end as broken; this was because the installer escaped
the single quote using backslashes which ended up being treated as
escape characters much later during hostname.if parsing in netstart(8).

Ok deraadt


Revision tags: OPENBSD_6_7_BASE
# 1.202 15-Jan-2020 kn

Do not redirect already quiet stdout for IPv6 reject routes

"route -q" already silences all standard output; if it still prints
something, that's a bug to fix in route.

OK bluhm


# 1.201 25-Oct-2019 dlg

handle aggr(4) in the same way as trunk(4)

from brad@
ok bluhm@ claudio@ deraadt@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.200 29-Aug-2018 krw

Historically /etc/netstart (and the equivalent code in the install
script) did 'ifconfig <if> down' before starting dhclient(8). This was
a way of ensuring old running copies of dhclient were killed before a
new one started. Current dhclient does not need this assist, so change
"ifconfig <if> down" to "ifconfig <if> up" pending further script
optimizations.

Similar to a 2014 attempt by halex@. Prompted by a misc@ report
from Kristjan Komlosi reporting hanging diskless setups.

ok halex@ kn@


# 1.199 08-Jul-2018 tb

netstart is used during system start, but also interactively.
Show proper error message if a regular user executes netstart.
Only do the privilege check if the id binary is available,
which might not be the case during diskless system startup.

ok deraadt, jasper, jca, krw, rpe (who wrote the same diff), sthen


# 1.198 28-Apr-2018 rpe

Add a proper usage() function.

Suggested by and OK jmc.
OK tb


Revision tags: OPENBSD_6_3_BASE
# 1.197 04-Mar-2018 jmc

when -n is used, no need to spit out "Missing parameters." before
displaying usage();

ok tb


# 1.196 03-Mar-2018 landry

Lowercase 'usage' and group -n with interface in it.
From jmc@, ok tb@


# 1.195 21-Feb-2018 rpe

Tweak comments.

OK tb


# 1.194 19-Feb-2018 rpe

Write warning/error messages to stderr and end them with a fullstop.

OK tb


# 1.193 19-Feb-2018 rpe

- use specific patterns when looping over /etc/hostname.if files
to skip backup or temp files.
- test if the patterns matched actual files
- warn if ifcreate() fails on an interface and continue with the
subsequent interfaces in the list instead of return'ing

OK dlg sthen tb


# 1.192 17-Feb-2018 rpe

- Add descriptions for the new functions ifcreate() and vifscreate()
- In ifcreate() use the exit code of the {} block directly
- In vifscreate(), use the ifconfig -C output directly in the for _vif loop
- Remove superfluous and somewhat confusing comment

OK dlg kn sthen


# 1.191 14-Feb-2018 dlg

create virtual interfaces before starting all interface config.

this resolves an ordering problem when adding pseudo interfaces to bridges

tweaks from kn@
ok mpi@ sthen@


# 1.190 10-Feb-2018 claudio

Remove some special IPv4 in IPv6 mapped prefixes that are already rejected
by the ::0.0.0.0/96 reject route added to deny all IPv4 mapped addresses.
Makes the inet6 routing table almost fit in one screen.
OK benno@


# 1.189 10-Feb-2018 florian

Load RFC 7217 key material and generate if it does not already exist.

Add soii.key to changelist (pointed out by semarie) and mtree/special
(suggest by Craig Skinner).

OK naddy, sthen, rpe, tb


# 1.188 06-Feb-2018 tb

If -n is given, the netstart script should not (try to) set the default
route(s). Simply print the command(s) to be issued instead.

tweak & ok rpe


# 1.187 12-Nov-2017 tb

Remove HN_DIR variable and expand it in the only place it was used. It
currently serves no purpose.

ok rpe, agreement from deraadt and halex


Revision tags: OPENBSD_6_2_BASE
# 1.186 25-Jul-2017 rpe

Finally remove backwards compat code to support the 'rtsol' keyword
in hostname.if(5)

OK mpi@ deraadt@ florian@
OK jmc@ from doc perspective


# 1.185 21-Jul-2017 rpe

Align ifstart() in netstart and install.sub.

- in netstart, rename _file to _hn referencing hostname.if files
- in install.sub switch ifstart() to be used with _if instead of
_hn as parameter

ok krw@ tb@


# 1.184 28-May-2017 awolk

etc/netstart: use colon separator instead of dot with chown

OK jung@, deraadt@, jmc@


# 1.183 07-May-2017 rpe

Change test from [] to [[]] and simplify pattern.

OK tb@, krw@ (for [[]])
Feedback and OK halex@


# 1.182 07-May-2017 rpe

Replace hardcoded script name with ${0##*/}

OK tb@ halex@


# 1.181 01-May-2017 rpe

Revert r1.170 and remove the id==0 check.
The id binary is not available in nfs diskless setups at this point.

reported by Andreas Kusalananda, thanks.
discussed with deraadt@


# 1.180 01-May-2017 rpe

Remove last remnants of rtsol. IPv6 autoconfiguration of interfaces is now
done in ifstart(). Remove ipv6autoconf() and replace rtsolif with a boolean
variable V6_AUTOCONF. Replace dhcpif with a boolean variable V4_DHCPCONF.
Both are later used in defaultroute() to decide whether or not to configre
defaultroutes from /etc/mygate.

OK krw@


# 1.179 30-Apr-2017 mpi

Do not try to delete a default route before adding it.

Now that route are automatically G/C with the address they are attached
to there's no reason to duplicate the kernel's job.

Fix a regression introduced with multipath default routes.

ok deraadt@


# 1.178 25-Apr-2017 rpe

Unbreak netstart for multiple inteface configurations like trunk
or carp. Ensure that the noglob option is disabled at the end of
parse_hn_line() and ifstart().

Reported by Christer Solskogen and Stefan Wollny, thanks!


# 1.177 24-Apr-2017 rpe

Introduce a new function parse_hn_line() that replaces the existing
hostname.if(5) parsing code in ifstart().
Add a -n option to netstart to only print the interface configuration
commands instead of executing them.
Add a HN_DIR variable, that points to the directory of the hostname.if
files (default /etc) that allows for future regression tests.

- add new parse_hn_line() function
- change ifstart()
- rename $if to $_if
- don't ifconfig or ifconfig create if -n option is used
- replace hostname.if(5) parsing code with new parse_hn_line()
- just print configuration commands if -n option is used
- autoconf now happens in ifstart(), remove ifv6autoconf()
- introduce HN_DIR variable for the hostname.if file location
- add handling of the -n option to only print config commands
- ensure -n is only used if interfaces are specified as parameters

Discussed with and positive feedback from many
'commit' deraadt@
OK sthen@


# 1.176 08-Apr-2017 rpe

- localize the if, file and stat variables which also ensures that
variables are not named like commands.
- change test from [] to [[]]

OK tb@ halex@


# 1.175 07-Apr-2017 rpe

Minimize differences in ifstart() function between netstart and
install.sub which makes it easier to spot changes in the future.

- comments and formatting
- quotes on assignments are not needed (netstart)
- remove stray space in test (netstart)
- use $file variable with while-loop (netstart)
- although valid, instead of i use $i in arithmetic test (install.sub)

OK krw@, tb@
Looks good deraadt@


# 1.174 07-Apr-2017 rpe

Align comments of ifstart() function in netstart and install.sub.


# 1.173 07-Apr-2017 rpe

Align comments of stripcom() function in netstart and install.sub.


Revision tags: OPENBSD_6_1_BASE
# 1.172 06-Dec-2016 mpi

Do not lose the default route when netstart(8) is run a second time on
the interface pointed to by the default route.

Since the kernel no longer keep routes with dangling address pointer,
netstart(8) has to re-add the default route when the corresponding ifa
has been deleted and re-created.

deraadt@ points out that even if the previous semantic was not necessarily
better, a script like netstart(8) cannot totally fix the default route
problem.

Regression reported by and fix tested by Hrvoje Popovski.

ksh foo checked by halex@


# 1.171 27-Sep-2016 rzalamena

Delay switch(4) interface start up so it can attach virtual interfaces
like vether(4).

nits from and ok benno@, phessler@


# 1.170 09-Sep-2016 jasper

print a clear error message when not ran as root instead of just falling
through and try whatever it can do with the invoking user's perms

feedback/ok aja@ rpe@


Revision tags: OPENBSD_6_0_BASE
# 1.169 19-Jul-2016 mpi

Do not consider tap(4) a special interface and start if before other
pseudo-interfaces.

This unbreak vlan(4) on top of tap(4) since the refactoring to turn it
MP-safe.

ok claudio@, deraadt@


# 1.168 27-Mar-2016 sthen

Don't delete the 224/4 route in netstart, unless it's being done to ensure that
a -reject route can be added. Restores the ability to set an interface route
before daemons are started, lost during the previous simplification.
ok millert mpi


Revision tags: OPENBSD_5_9_BASE
# 1.167 29-Dec-2015 rpe

Remove backslash, not necessary after '&&'

OK halex@


# 1.166 29-Dec-2015 rpe

Replace last remaining `` with $()

OK halex@


# 1.165 18-Dec-2015 ajacoutot

Drop the now useless multicast setup comment.

prodded by tim@, ok mpi@


# 1.164 17-Dec-2015 ajacoutot

Simplify multicast option handling (10 less lines) by matching /etc/rc behavior
towards other YES|NO options and drop the error warning.


with and ok tim@, ok rpe@ on an earlier diff


# 1.163 05-Dec-2015 mpi

It does not make sense to insert a specific route for 224/4 when the
default one is good enough.

So merge rc.conf(8)'s 'multicast_router' and 'multicast_host' into a
single 'multicast'. If set to YES the reject route for 224/4 is not
inserted by netstart(8).

Manual bits from jmc@

ok henning@, ajacoutot@


# 1.162 12-Nov-2015 rpe

Changes to ifautostart():
- Rename function to ifv6autoconf() to make IPv6 relation clearer
- Localize and rename variables

OK krw@


# 1.161 12-Nov-2015 rpe

Changes to ifmstart():
- Change comments to make it clearer that ifmstart() takes two lists
of interface driver names (of which the second is optional) and not
the actual interface instances.
- Use localized variables and use slightly more verbose names.
- Use continue 2 to skip to the next hostname.if file.
- Use shell pattern @() instead of testing _sif individually.

OK krw@


# 1.160 12-Nov-2015 rpe

Changes to stripcom():
- Align comments with /etc/rc version
- Use localized variables
- Use safer "print -r --" instead of plain echo

Changes to ifstart():
- Tweak comment
- Add usage

OK krw@


# 1.159 01-Nov-2015 rpe

Start the rework of the /etc/netstart shell script.

General changes:
- apply a similar 'style' as used in the installer scripts
- improve comments to be more to the point, remove where code is obvious
- document usage of functions if they have arguments
- rename variables where it improves readability
- replace really old-school shell code with more contemporary idioms

Other changes:
- No need to care about "autoboot" because netstart doesn't inherit the
positional parameters from /etc/rc anymore. /etc/rc executes netstart
instead of sourcing it since r1.439.
- Use simpler for-loop to process list of interfaces with ifstart.

OK halex@


# 1.158 26-Oct-2015 rpe

The hostname variable is not used since r1.99. Remove it and use
stripcom() output directly with the hostname command.

OK deraadt@ krw@


# 1.157 23-Oct-2015 claudio

netstart bits for tap(4)


# 1.156 27-Sep-2015 sthen

Don't print output when setting autoconf on interfaces. Suggested by deraadt,
ok florian@ rpe@


# 1.155 13-Sep-2015 sthen

only print the "IPv6 autoconf" line if there are interfaces to configure
feedback/ok rpe


# 1.154 11-Sep-2015 sthen

Set "inet6 autoconf" individually on interfaces that have rtsol set in
hostname.if, previously netstart tried to configure them all at once
("ifconfig if0 if1 if2 inet6 autoconf"). From Delan Azabani, ok phessler@


Revision tags: OPENBSD_5_8_BASE
# 1.153 20-Jul-2015 rpe

Disable Strict Bourne shell mode for /etc/rc and /etc/netstart to be
able to use ksh syntax within these scripts. This way init doesn't
need to be changed, which starts /etc/rc using /bin/sh and people
can still use "sh /etc/netstart ifname".

Idea from and OK halex@
OK deraadt@ krw@ guenther@


# 1.152 19-Jul-2015 florian

Bring up pflow last as it might send with a source address that is on
any of the other interfaces.
OK deraadt, phessler, benno


# 1.151 19-Jul-2015 rpe

Always source rc.subr to be able to use the rc.conf parsing routine
to get the network related vars from rc.conf. This is even necessary
if netstart is run from within /etc/rc. Remove test of $INRC which
unintentionally evaluated always to true.

problem with previous change found by nigel@
OK sthen@ aja@ halex@


# 1.150 19-Jul-2015 ajacoutot

Revert 1.148 for now until I can talk to rpe@
It introduced a regression reported by nigel@


# 1.149 19-Jul-2015 rpe

Replace test command with [].

OK halex@ krw@


# 1.148 19-Jul-2015 rpe

Ensure, that we source rc.subr and parse rc.conf ONLY if we are not
inside /etc/rc.

With help from and OK halex@, ajacoutot@


# 1.147 18-Jul-2015 rpe

- remove trailing blanks introduced in previous commit
- no space in redirections like </foo or >$bar
- few other minor whitespaces

OK krw@


# 1.146 18-Jul-2015 rpe

Improve comments
- Add comments for functions
- Start comments with capital letters
- End comments with a full stop
- Allow comments to extend up to column 80

OK krw@


# 1.145 06-Jun-2015 florian

Allow rtsol keyword in hostname.if(5) with net.inet6.ip6.forwarding=1.
"inet6 autoconf" was working before and rtsol should behave the same.
OK phessler


Revision tags: OPENBSD_5_7_BASE
# 1.144 03-Dec-2014 florian

The kernel handles rtsol(8) functionality since some time now.
Treat rtsol in hostname.if as a keyword like dhcp and call ifconfig
inet6 autoconf.
"reads good" todd@
OK krw@ (who is *not* an IPv6 person), but I recruited him in his
capacity as an installer person.


# 1.143 28-Sep-2014 claudio

Revert 1.142. Without the down netstart will just print the ifconfig
output because it may end up just calling 'ifconfig $if'. This needs
to be done better and properly tested.


# 1.142 26-Sep-2014 halex

remove explicit 'down' of an interface before starting a dhcp request, thereby
avoiding annoying delays for some switch configurations

ok claudio@ deraadt@

i would add ok phessler@, but it was not valid without an ok krw@


Revision tags: OPENBSD_5_6_BASE
# 1.141 12-Jul-2014 stsp

Fix netstart after autoconf6 change so 'rtsol' lines in hostname.if work again.
found by pelikan@; ok pelikan@ henning@


# 1.140 12-Jul-2014 robert

Make rc.conf a parsed configuration file and stop sourcing it as a shell
script.
From now on rc.conf has a fixed syntax (key=val) and it is not allowed
to add anything to it besides the supported syntax, it all going to be
ignored.

discussed with and help from deraadt@ and halex@


Revision tags: OPENBSD_5_5_BASE
# 1.139 22-Aug-2013 mpi

Like for dhclient, do no create a route to alias addresses via 127.0.0.1.
Our stack is able to tell if the address is local or not.

ok todd@, krw@


Revision tags: OPENBSD_5_4_BASE
# 1.138 20-Mar-2013 todd

fix lies in netstart; replacement wording from halex@
pointed out by Ryan Kavannagh rak at debian dot org


Revision tags: OPENBSD_5_3_BASE
# 1.137 05-Dec-2012 rpe

remove "Invalid interface name" message
requested by krw@

ok halex@


# 1.136 02-Dec-2012 rpe

use the more compact version of the check for ifconfig'able interfaces
from install.sub

with feedback from and ok halex


# 1.135 02-Dec-2012 rpe

- remove isalphanumeric() and replace it with a shell pattern, that
tries a bit harder to identify invalid interface names and in
this case emit an error message.
- use [[ $1 == autoboot ]] to avoid a shell error message due to
possible spaces in first argument
- no change in functionality

discussed with krw and halex
ok ("I like this") krw


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.134 07-Oct-2011 deraadt

The new ypbind changes requires that the domainname be set before
rc.conf is run. There's no real downside.
ok aja


Revision tags: OPENBSD_5_0_BASE
# 1.133 07-Jul-2011 guenther

Eliminate some $? tests by rolling the command into the condition

ok halex@


# 1.132 26-May-2011 mpf

Add svlan(4) startup bits.
From markus@. OK naddy, claudio, reyk.


Revision tags: OPENBSD_4_9_BASE
# 1.131 09-Feb-2011 sobrado

fix an unbalanced parenthesis in a comment; while here, split the comment
in a better place to make it more readable.

ok jmc@ and miod@


Revision tags: OPENBSD_4_8_BASE
# 1.130 16-Jun-2010 todd

permit e.g. -inet6 syntax by slurping all lines not just some
noticed by rhsv6 at hushmail dot com, ok sthen@


Revision tags: OPENBSD_4_7_BASE
# 1.129 12-Jan-2010 henning

when setting up lo0 use 127.0.0.1/8 instead of 127.0.0.1 for clarity and
correctness. it's not 1992 any more, kids. ok mcbride dlg krw


# 1.128 10-Dec-2009 todd

o stop reordering ifconfig arguments (e.g. after 'up ..')
o only stop processing if inet or inet6 lines are malformed
o everything not a specially handled bit is passed to ifconfig unmangled
noticed by several after the move from bridgename.bridge0 -> hostname.bridge0
prodded by deraadt@, tested by and feedback from several
man page bits 'look fine' jmc@


# 1.127 22-Nov-2009 deraadt

Stop supporting bridgename.bridge* files, and move to hostname.bridge*
files. To cope with this change, read about the mv command.
ok claudio todd


# 1.126 17-Sep-2009 simon

change variable i to $i in an expression of ifstart() for consistency
with the rest of the file. no functional change.

feedback from sthen@, ok krw@


# 1.125 10-Jul-2009 jdixon

Delay creation of tun(4) interfaces until the underlying interface and
routes are available. This fixes usage for some OpenVPN users that start
it from hostname.tun*.

Tested by Johan Huldtgren. ok sthen@, johan@.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.124 25-Nov-2008 markus

delay /etc/netstart until IPv6-DAD (dup-address-detection) is completed.
ok fries, hshoexer, claudio


# 1.123 14-Aug-2008 sthen

Tools from /usr may not be used in netstart since it may be NFS-mounted
and not available at that time. Rewrite the hostname.if permission check
to use only /bin/ls and the shell. Requested by deraadt.

ok todd, "Twisted." deraadt


Revision tags: OPENBSD_4_4_BASE
# 1.122 23-Jul-2008 sthen

Prevent warning about insecure hostnames where no /etc/hostname.*
exists. From wcmaier@.

Check target of symbolic links to avoid noise at boot and in
seucrity output where you have several interfaces symlinked to one
config file.

"If you think this is the right thing to do" deraadt@


# 1.121 09-Jun-2008 todd

warn once not 3 times in case of a non existent file, discussed with deraadt
originally pointed out by Johan Torin


# 1.120 09-Jun-2008 deraadt

Ensure that hostname.* files are also re-chowned to root.wheel at each
boot as discussed with claudio while eating tasty donairs. ok todd


# 1.119 17-Apr-2008 deraadt

before using them, force hostname.* files to be unreadable by world
first version from todd, ok millert


Revision tags: OPENBSD_4_3_BASE
# 1.118 17-Jan-2008 brad

Execute rtsol after turning up trunk(4) and vlan(4) interfaces so they're
taken into consideration for rtsol.

ok reyk@ dlg@


# 1.117 09-Jan-2008 mpf

Do not bring up pfsync(4) before the working ruleset
has been loaded. Otherwise, states that are received during the
initial bulk update mismatch the correct pf-checksum and
do not attach to the rules.
Problem identified by david@. Fix done in collaboration.
OK henning@


Revision tags: OPENBSD_4_2_BASE
# 1.116 02-Aug-2007 david

move the delay for IPv6 DAD to after all interfaces have started
fixes problems with daemons being unable to bind to all addreses at boot
ok itojun@ hshoexer@


Revision tags: OPENBSD_4_1_BASE
# 1.115 15-Nov-2006 itojun

reject multicast packet without scope identifier specified.


Revision tags: OPENBSD_4_0_BASE
# 1.114 29-Jun-2006 todd

do not add an extra space; nwid and description come out wrong
fix as proposed by maja@, thanks!


Revision tags: OPENBSD_3_9_BASE
# 1.113 28-Dec-2005 david

nuke extra whitespace


# 1.112 06-Dec-2005 reyk

multicast_host=YES only works if a valid default gateway is available.
validate this condition and reject multicast traffic on failure.

ok todd@ naddy@


# 1.111 02-Nov-2005 todd

fix inspired by pr#4590
ok krw@


# 1.110 25-Oct-2005 todd

better logic from krw@:
- do not process mygate for v4 if dhcp
- do not process mygate for v6 if rtsol
this also makes the mygate processing logic more readable
ok krw@


# 1.109 14-Oct-2005 todd

add v6 support for /etc/mygate
ok deraadt@ mickey@ krw@
same functionality tested/ok'ed by by mickey, brad, matthieu, and me
with this one may now put a v6 IP in /etc/mygate on a separate line from
the v4 default gateway and netstart will do the right thing


# 1.108 12-Oct-2005 todd

shrink stripcom(), sync with install.sub
ok krw@


# 1.107 04-Oct-2005 todd

trunk must be started after physical ethernet devices, but before vlan.
populate ifmstart lines accordingly.
prodded/tested by brad@
ok reyk@


# 1.106 28-Sep-2005 todd

use eval consistently, fixes description quotes on rtsol and dhcp
fix inspired by and closes pr 4495
ok krw@


Revision tags: OPENBSD_3_8_BASE
# 1.105 22-May-2005 todd

Introduce 'ifmstart' to deal with starting multiple interfaces minus a list
of interfaces.

This reduces the netstart script by 174 chars, 13 words, and 19 lines, but
more importantly, makes it more simple and less cluttered should more special
case/orderings be needed.

ok brad@ and pr 4197 submitter, inspired by and closes pr 4197


# 1.104 04-Apr-2005 djm

unbreak; ok pval@


# 1.103 03-Apr-2005 deraadt

if dhcp is used to get an address on any interface, ignore /etc/mygate
ok krw
(this lets us do something rather cool with the zaurus in particular)


Revision tags: OPENBSD_3_7_BASE
# 1.102 04-Jan-2005 mcbride

Bring up the carp(4) interface before default route.

ok pascoe@ mpf@


# 1.101 30-Dec-2004 millert

Add a copy of stripcom so /etc/netstart can be run standalone again.
OK deraadt@


# 1.100 19-Dec-2004 millert

Allow comments in /etc/{myname,mygate,defaultdomain}; OK deraadt@


# 1.99 04-Dec-2004 itojun

remove "route $hostname 127.0.0.1" line. deraadt ok
*** please update /etc/netstart and test if it works ok for you ***


# 1.98 20-Oct-2004 deraadt

make all route commands use -qn; ok mcbride henning


Revision tags: OPENBSD_3_6_BASE
# 1.97 29-May-2004 deraadt

one last route command lacking -qn


Revision tags: OPENBSD_3_5_BASE
# 1.96 22-Mar-2004 mcbride

Make sure pfsync is brought up before carp.

ok deraadt@


# 1.95 13-Mar-2004 mcbride

Delay pfsync(4) configuration, as the syncif has to be configured in
advance. From Thorsten Lockert.


# 1.94 14-Jan-2004 deraadt

ok, it took quite a bit of prodding but itojun finally explained why the
extra sleep 1 is in here, and we came to the conclusion it is safe to
delete it. whee.


# 1.93 13-Jan-2004 deraadt

repair v6 lo0 documentation


# 1.92 11-Jan-2004 deraadt

add loopback routes late


# 1.91 09-Jan-2004 deraadt

create all routes with -q; markus ok


# 1.90 04-Dec-2003 millert

Need to do "ifconfig create" for bridge interfaces too.


# 1.89 03-Dec-2003 markus

add support for ifconfig clone; from netbsd; ok deraadt, henning


# 1.88 20-Oct-2003 david

delay carp initialization until after physical interfaces are configured
ok mcbride@ henning@ deraadt@ todd@


Revision tags: OPENBSD_3_4_BASE
# 1.87 27-Aug-2003 henning

only try to set hostname to what /etc/myname says if that file actually exists,
otherwise preserve `hostname`
netbooted machines can live perfectly fine without it; they get their hostname
earlier.

ok krw@ cedric@


Revision tags: OPENBSD_3_3_BASE
# 1.86 16-Feb-2003 krw

Fix up some DNS verbiage to make it consistant.

Fix up default route selection by

a) Forcing user to explicitly chose 'dhcp' as a mechanism for
specifying a default route, rather than guessing based on one or more
interfaces being configured by dhcp.

b) If the user specified default route does not work, re-present the
existing default route rather than losing it.

c) Move default route selection to after nameserver activation so the
user can specify a hostname as the default route.

Change /etc/netstart so that /etc/mygate wins if a default route was
already specified (i.e. by dhcp).

ok deraadt@.


Revision tags: OPENBSD_3_2_BASE
# 1.85 16-May-2002 todd

ignore non-existent cases where '$if' evaluates to '*'.
From Andr� Lucas <andre@ae-35.com>, fixes pr # 2658.
'Looks good' from miod@, millert@, and krw@.


Revision tags: OPENBSD_3_1_BASE
# 1.84 23-Feb-2002 deraadt

re-add support for $if expansion; hamajima@nagoya.ydc.co.jp


# 1.83 21-Feb-2002 miod

Change the network components initialization order.
Change from:
o all interfaces
o all bridges
o routes
to:
o physical interfaces
o routes
o gif and gre interfaces
o bridges

Fixeski PR #2400.
Manual page updates coming soon.
Ok angelos@ chris@ deraadt@


Revision tags: OPENBSD_3_0_BASE
# 1.82 31-Jul-2001 hugh

a space before a redirect


# 1.81 06-Jul-2001 angelos

Also, source /etc/rc.conf so we can pull in the
multicast_host/multicast_router settings; this is useful if one
flushes the routing table and re-initializes.

We really need a netconfig tool of sorts.


# 1.80 06-Jul-2001 angelos

Use "route -n show -inet" to determine the default multicast iface.


# 1.79 03-Jul-2001 deraadt

pull in rc.conf early so that pf(1) startup is right; tested by jasoni, comments from millert


# 1.78 30-May-2001 deraadt

Remove ipf. Darren Reed has interpreted his (old, new, whichever)
licence in a way that makes ipf not free according to the rules we
established over 5 years ago, at www.openbsd.org/goals.html (and those
same basic rules govern the other *BSD projects too). Specifically,
Darren says that modified versions are not permitted. But software
which OpenBSD uses and redistributes must be free to all (be they
people or companies), for any purpose they wish to use it, including
modification, use, peeing on, or even integration into baby mulching
machines or atomic bombs to be dropped on Australia. Furthermore, we
know of a number of companies using ipf with modification like us, who
are now in the same situation, and we hope that some of them will work
with us to fill this gap that now exists in OpenBSD (temporarily, we
hope).


Revision tags: OPENBSD_2_9_BASE
# 1.77 13-Mar-2001 deraadt

spelling; maurice@maurice.wan.nl


# 1.76 06-Feb-2001 todd

ignore blank lines in addition to comments
fixes pr#1660 from wilfried@telia.com .. Thanks!


# 1.75 10-Jan-2001 jason

support !command in bridgename.if files, too


# 1.74 27-Nov-2000 millert

Use -n to test if a variable is non-zero. Otherwise, if the variable's
contents start with a '-' test becomes unhappy (since it interprets it
as another option).


# 1.73 08-Nov-2000 todd

This fixes pr 1481, we now handle args > 6 in /etc/hostname.if in the
cases where we did not previously handle them.
Thanks to Scott Atwood <atwood@cs.stanford.edu> for reminding us of this.


Revision tags: OPENBSD_2_8_BASE
# 1.72 02-Sep-2000 todd

subtle bug .. global variables in a while loop need reset 'just incase'
With:
hostname.fxp0 having a last line of:
inet6 alias 3ffe:...
and hostname.gif0 having a first two lines of:
giftunnel 1.2.3.4
dest 1.2.4.3
We end up with the command:
ifconfig gif0 giftunnel alias 1.2.3.4 1.2.4.3
.. which is clearly wrong and fixed by this change


# 1.71 18-Jun-2000 todd

rc.conf now parses ${local_rcconf} internally; closes pr 1259


Revision tags: OPENBSD_2_7_BASE
# 1.70 08-May-2000 todd

fix dhcp 'NONE' ness from install to allow media parsing to work
.. ok deraadt@, millert@


# 1.69 21-Apr-2000 deraadt

rc.conf.local support, inspired by chuck yerkes


# 1.68 04-Apr-2000 millert

Remove the -E flag from ipf as it is implicitly enabled and using
the -E flag here causes the kernel to printf 'IP Filter: already
initialized'.


# 1.67 18-Mar-2000 deraadt

silence all extra route addition printouts


# 1.66 17-Mar-2000 itojun

correct reject route installations for IPv6. improve comments.


# 1.65 12-Mar-2000 itojun

disallow packets to malicious 6to4 prefix, based on
http://playground.iijlab.net/i-d/draft-itojun-ipv6-transition-abuse-00.txt


# 1.64 10-Mar-2000 todd

fix non behavior
with this `!' lines in /etc/hostname.* run even without certain lines
(like a comment) preceeding it.


# 1.63 10-Jan-2000 todd

allow arbitrary commands in /etc/hostname.* files if the line starts with '!'


# 1.62 02-Jan-2000 deraadt

rtsol case can configure the interface up, since it would be nice to finish
DAD before the actual rtsol(8) run happens later. and since it will rtsol,
it is going to be up in any case.


# 1.61 02-Jan-2000 itojun

one more indentation fix.


# 1.60 02-Jan-2000 itojun

indentation fix (todd's part)


# 1.59 02-Jan-2000 todd

fix rtsold case, reset cmd for each iteration!


# 1.58 02-Jan-2000 itojun

allow options after "rtsol".
XXX both "dhcp" and "rtsol" has keyword *down* at the end. is it okay?


# 1.57 02-Jan-2000 itojun

echo "IPv6 autoconf: interfaces" before invoking rtsol.
sleep for net.inet6.ip6.dad_count seconds to ensure that IPv6 DAD is completed.
TODO: rtsold (rc.conf line), manpage


# 1.56 02-Jan-2000 itojun

ipv6 autoconf on hosts (non-routers).

to do this,
1. in sysctl.conf, add these lines:
net.inet6.ip6.forwarding=0
net.inet6.ip6.accept_rtadv=1
2. in hostname.foo, add
rtsol

specifying two or more interfaces with "rtsol" may result in strange
behavior - ipv6 spec does not permit multi-interface node to be autoconfig'ed.


# 1.55 02-Jan-2000 todd

add to hostname.* parsing:
- multiple entries support (read: aliases)
- inet6 support
- support for comments (#)
(look for hostname.if(5) commit for syntax details)


# 1.54 31-Dec-1999 itojun

install IPv6 reject routes only if kernel is capable of IPv6.


# 1.53 09-Dec-1999 itojun

avoid transmitting invalid IPv6 packets out to the wire.


# 1.52 09-Dec-1999 itojun

do not perform IPv6 initialization for loopback interface.
MUST make lo0 up before any IPv6 operations.
it will be considered a pilot error if you don't.
(I prefer to have lo0 initialized automatically)


Revision tags: OPENBSD_2_6_BASE
# 1.51 01-Sep-1999 deraadt

support # characters in bridgename.* files; millert


# 1.50 01-Sep-1999 deraadt

cleanup parsing of hostname.* files, and seperate bridge control into
bridgename.* files; all documented in new hostname.if(5) and
bridgename.if(5) man pages


# 1.49 09-Aug-1999 angelos

Only parse/setup the hostname.foo file if interface foo exists (this
is useful for laptops with different ethernet cards etc.)


Revision tags: OPENBSD_2_5_BASE
# 1.48 29-Mar-1999 niklas

New multicast route setup style


# 1.47 26-Mar-1999 niklas

Add bridge interface handling


# 1.46 01-Mar-1999 millert

Add support in /etc/hostname.xxx for files of the format:
up [options]
Any of the following may or may not be set:
$name $mask $bcaddr $extras


# 1.45 28-Oct-1998 millert

Kill the awful hack used to match and split /etc/hostname.* We now use
a function, isalphanumeric, to determine whether an interface name is
likely to be valid. This means that things like /etc/hostname.le0.bak,
/etc/hostname.le0#, /etc/hostname.le0~, etc. will be ignored as they
should. There is no longer an implicate assumption that /etc/hostname.*
only contains a single '.'.


Revision tags: OPENBSD_2_4_BASE
# 1.44 06-Oct-1998 deraadt

move ipnat to end of netstart, to support dhcp+ipnat


# 1.43 18-Sep-1998 deraadt

apply media directives on dhcp interfaces


# 1.42 10-Sep-1998 marc

better way of handling dhcp client; Jason Ish <jbi130@mail.usask.ca>


# 1.41 08-Sep-1998 marc

dhcp client stuff. "Angelos D. Keromytis" <angelos@dsl.cis.upenn.edu>


# 1.40 24-Aug-1998 downsj

You can't use -interface default when there's no default gateway
set (yet). Use -interface $hostname if mygate doesn't exist so that
this actually works on routers.


# 1.39 04-Jul-1998 deraadt

put 224 route on default, to avoid a hostname lookup


# 1.38 22-May-1998 deraadt

use route -n, what the heck


Revision tags: OPENBSD_2_3_BASE
# 1.37 28-Mar-1998 deraadt

s/^nat/ipnat/


# 1.36 23-Feb-1998 niklas

remove trailing blank line


# 1.35 07-Feb-1998 deraadt

ipforward is in sysctl.conf now


# 1.34 21-Dec-1997 deraadt

ugh


# 1.33 20-Dec-1997 deraadt

ipforwarding option in rc.conf


# 1.32 29-Nov-1997 kstailey

NAT requires IPF


# 1.31 04-Nov-1997 deraadt

kill spaces at ends of lines; m4


Revision tags: OPENBSD_2_2_BASE
# 1.30 14-Oct-1997 deraadt

set hostname/domainname before running rc.conf; m4@umn.edu


# 1.29 04-Sep-1997 deraadt

fork netstart; new child is rc.conf


# 1.28 25-Aug-1997 millert

Explicately pass -host flag to route(8) to avoid confusion with networks.


# 1.27 19-Aug-1997 niklas

Add hook for rpc.lockd, make nfsd flags settable in netstart


# 1.26 31-Jul-1997 downsj

Make quotas optional; wedged into netstart for the time being.
/etc/rc.conf, anyone?


# 1.25 30-Jul-1997 deraadt

do not run routed by default


# 1.24 28-Jul-1997 kstailey

Move configuration of loopback interface to before all other interfaces.
Allows the use of local caching-only nameserver with no "nameserver"
entry in /etc/resolv.conf to configure a route between the hostname
and loopback.


# 1.23 25-Jul-1997 provos

earlier start of keymanagement


# 1.22 24-Jul-1997 deraadt

make amd use /tmp_mnt by default


# 1.21 22-Jul-1997 provos

start the photuris daemon per default. hilfe.


# 1.20 17-Jun-1997 niklas

Put in hooks to start ypserv with flags


# 1.19 17-Jun-1997 niklas

Put in hooks to start rpc.yppasswdd with flags


Revision tags: OPENBSD_2_1_BASE
# 1.18 15-Apr-1997 deraadt

kill route flush until .. hmm kernel routing socket bug or something


# 1.17 09-Apr-1997 kstailey

add NAT startup


# 1.16 07-Apr-1997 rees

flush all old routes before adding new interfaces or routes.
ref: netbsd pr3228/misc, Matthias Scheler


# 1.15 03-Mar-1997 downsj

fix typo


# 1.14 11-Feb-1997 deraadt

add default route before fiddling with loopback route to avoid DNS problems; m4@umn.edu, #97


# 1.13 03-Feb-1997 deraadt

do ifaliases after /usr/bin exists in nfs diskless env; pr#77, matthieu@laas.fr


# 1.12 02-Nov-1996 deraadt

timed off by default


Revision tags: OPENBSD_2_0_BASE
# 1.11 23-Sep-1996 deraadt

rfc1323 variable


# 1.10 04-Sep-1996 deraadt

control portmap, inetd, and lpd from netstart; idea from tqbf@enteract.com


# 1.9 27-Aug-1996 deraadt

224.0.0.0 not 0.0.0.224; from peter@demon.net


# 1.8 18-Jun-1996 deraadt

move std stuff from rc.local to rc


# 1.7 16-Jun-1996 deraadt

install sample commented /etc/ifaliases file; which can now contain #
comments and blank lines. new format is "interface address netmask"
(yes, i changed the order of the entries). inspired by netbsd pr#2474;
gillhaa@ghost.whirlpool.com


# 1.6 02-Jun-1996 tholo

Install a multicast route by default


# 1.5 26-May-1996 deraadt

sync & label


# 1.4 09-Jan-1996 dm

added IP filter to netstat/rc and put examples in /usr/share/ipf


# 1.3 30-Dec-1995 deraadt

from netbsd: start mrouted like routed


# 1.2 18-Dec-1995 deraadt

/etc/ifaliases support by randy@zyzzyva.com


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.232 16-Dec-2022 kn

zap double space and needless line break


# 1.231 16-Dec-2022 afresh1

Prioritize lladdr over name/unit in hostname.if processing

When needed, lladdr is more precise and enduring.

Suggested by deraadt@
Many improvments and OK kn@


# 1.230 05-Dec-2022 afresh1

Add support configuring hostname.if(5) by lladdr

Original implementation by martijn@
Feedback and suggestions from kn@, sthen@, claudio@, florian@, and deraadt@.

ok deraadt


# 1.229 05-Nov-2022 kn

"need root privileges" is an error, print it on stderr"


# 1.228 05-Nov-2022 kn

Print full path in usage; OK jmc


# 1.227 01-Nov-2022 kn

Only load the SOII key if IPv6 is available

Possible now that IP6KERNERL is hoisted.
This also improves readability and zaps double negation logic.


# 1.226 01-Nov-2022 kn

Do not wait for DAD completion in dry-run mode

1. only do so when running without -n
2. move code to own wait_dad() helper like wait_autoconf_default() has it
3. use local _count as usual in both functions rather than the global count

Feedback OK claudio


# 1.225 31-Oct-2022 kn

Hoist only the feature check

Keep adding IPv6 routes after lo0 got an addres like before, meant to be
committed together with r1.223.


# 1.224 31-Oct-2022 kn

Fix comment: IPv6 link local addresses do not use SOII anymore

sys/netinet6/in6_ifattach.c r1.114 limited it to SLAAC addresses in 2019.


# 1.223 31-Oct-2022 kn

Improve shell style wrt. variable naming/boolean convention

The mixed use of upper and lower case variables is neither obvious nor
consistent.

PRINT_ONLY is local to netstart.
ip6kernel is local to netstart.
multicast gets sourced from rc.subr(8).

1. uppercase ip6kernel as is common for global variables in base scripts
2. use the simpler true/false idiom and default with the rest of
netstart-only variables, making it clearer that only `multicast=YES/NO'
comes from the rc environment
3. hoist kernel feature detection such that a later diff can load the SOII
key conditionally
4. zap obvious comment

OK aja


# 1.222 24-Oct-2022 kn

do not wait for autoconf in dry-run

If there is no default route but some interface has AUTOCONF, printing
what would be done still waits for... nothing to happen.

OK tb


# 1.221 24-Oct-2022 kn

Add required sh(1) to synopsis

Contrary to other scripts in base like rc.d(8) or MAKEDEV(8), netstart(8)
itself is not executable and must be passed as file to sh(1):
$ man -h netstart
/etc/netstart [-n] [interface ...]
$ /etc/netstart
ksh: /etc/netstart: cannot execute - Permission denied

Fix usage and synopsis to provide required usage:
$ man -h netsart
sh /etc/netstart [-n] [interface ...]

OK jmc


# 1.220 21-Oct-2022 kn

Fix synopsis, -n does not require an interface; OK jmc


Revision tags: OPENBSD_7_2_BASE
# 1.219 03-Jul-2022 kn

Create virtual interfaces upfront if specified on the command line

In cases like `sh /etc/netstart pair1 pair2', one of hostname.pair{1,2}
will contain a "patch pair{2,1}" command which expects the other interface
to exist.

If none exist, this would fail and netstart had to be run separately or
"patch"ed interface had to be manually created before.

There are other use cases where interfaces depend on each other, so before
(re)configuring an explicit list of interfaces, create all virtual ones
upfront so that a single netstart invocation will configure everything
correctly without having reflect dependencies in multiple ordered netstart
invocations.

Copy isin() from install.sub to help.

Feedback OK halex


# 1.218 26-Jun-2022 florian

Wait for autoconf interfaces to come up in netstart(8) instead of
rc(8). This makes tunnel interfaces work that depend on working
autoconf interfaces.
OK deraadt


Revision tags: OPENBSD_7_1_BASE
# 1.217 22-Feb-2022 dlg

add some more tunnels to the list of interfaces that rely on routing.


Revision tags: OPENBSD_7_0_BASE
# 1.216 02-Sep-2021 bluhm

Do not create loopback interfaces lo1, lo2, ... upfront. They are
automatically set up by the kernel when a routing domain is created.
An existing lo1 in rdomain 0 would prevent to add any interfaces
in rdomain 1.
OK kn@


# 1.215 30-Aug-2021 bluhm

Improve dubgging in /etc/netstart. Enable print only in ifcreate.
Add debugging output for ipv6 routes. Make localhost and multicast
code aware of the print only switch. Allow netstart -n to work
also if no interface is given.
OK kn@


# 1.214 06-Aug-2021 sthen

As tim@ spotted, a use of V4_AUTOCONF crept in when the variable name
was actually V4_DHCPCONF from previous use. Rename all of the V4_DHCPCONF
to V4_AUTOCONF so everything uses the new name. ok and reminder about
the installer from tb@


# 1.213 16-Jul-2021 florian

switch to dhcpleased/resolvd in base
OK deraadt


# 1.212 20-Jun-2021 florian

Don't try to install a default route with route(8) later on if we are
using inet autoconf, like we do with "dhcp" and "inet6 autoconf".
OK kn


Revision tags: OPENBSD_6_9_BASE
# 1.211 23-Dec-2020 krw

Allow the provision of dhclient(8) options on 'dhcp' lines in hostname.if(5)
files.

Usual man page help & ok jmc@


# 1.210 21-Dec-2020 krw

Avoid issuing pointless 'ifconfig <if> up' when processing 'dhcp' in
hostname.if files. dhclient(8) does that itself. Part of the
"further script optimizations" promised in r1.200 of netstart.

Tested & ok gnezdo@


# 1.209 29-Nov-2020 tb

Fix previous: use correct version of netstart and installer bits.


# 1.208 29-Nov-2020 deraadt

Add support for !command to mygate, so that netstart has a late opportunity
to perform network configuration (for example, "!route source -ifp em0")
Split mygate and myname manual pages (how did anyone ever believe these
are related), and perform hostname configuration much earlier in rc.
discussed with benno, claudio, jmc, etc etc, last version of !command
parser by tb


# 1.207 08-Nov-2020 jmc

no more mobileip;
ok claudio deraadt


Revision tags: OPENBSD_6_8_BASE
# 1.206 21-Jun-2020 dlg

start wg with the other interfaces that rely on routing being up.

from Matt Dunwoodie and Jason A. Donenfeld

ok deraadt@


# 1.205 22-May-2020 kn

Revert the following commit as it breaks hostname.if(5) lines with a
backslash at the end for line continuation

Breaking long lines into multiple ones must still be possible and does
require to treat the backslash as an escape character.

Breakage reported by Mark Patruck <mark at wrapped dot cx >, thanks!

---
distrib/miniroot/install.sub revision 1.1151
etc/netstart revision 1.203
date: 2020/05/21 11:54:41; author: kn; state: Exp; lines: +2 -2;
Do not treat backslashe as an escape character in hostname.if(5) lines

ifstart() should always pass such lines unaltered, especially if they
contain "nwid" or "description" lines with arbitrary strings.

<bsdlisten at gmail dot com> reported SSIDs such as "Mike's" during
installation end as broken; this was because the installer escaped
the single quote using backslashes which ended up being treated as
escape characters much later during hostname.if parsing in netstart(8).

Ok deraadt


# 1.204 21-May-2020 kn

Fix stripcom() description wrt. comments not on their own line

Neither netstart's nor install.sub's (subtly different) implementations
remove trailing comments on lines not starting as a comment, e.g.,
lines like "up #not down" go through unaltered and without "#not down"
being removed.

Only lines *beginning* with the comment sign ("#") are stripped.

No functional change, just updating function descriptions.


# 1.203 21-May-2020 kn

Do not treat backslashe as an escape character in hostname.if(5) lines

ifstart() should always pass such lines unaltered, especially if they
contain "nwid" or "description" lines with arbitrary strings.

<bsdlisten at gmail dot com> reported SSIDs such as "Mike's" during
installation end as broken; this was because the installer escaped
the single quote using backslashes which ended up being treated as
escape characters much later during hostname.if parsing in netstart(8).

Ok deraadt


Revision tags: OPENBSD_6_7_BASE
# 1.202 15-Jan-2020 kn

Do not redirect already quiet stdout for IPv6 reject routes

"route -q" already silences all standard output; if it still prints
something, that's a bug to fix in route.

OK bluhm


# 1.201 25-Oct-2019 dlg

handle aggr(4) in the same way as trunk(4)

from brad@
ok bluhm@ claudio@ deraadt@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.200 29-Aug-2018 krw

Historically /etc/netstart (and the equivalent code in the install
script) did 'ifconfig <if> down' before starting dhclient(8). This was
a way of ensuring old running copies of dhclient were killed before a
new one started. Current dhclient does not need this assist, so change
"ifconfig <if> down" to "ifconfig <if> up" pending further script
optimizations.

Similar to a 2014 attempt by halex@. Prompted by a misc@ report
from Kristjan Komlosi reporting hanging diskless setups.

ok halex@ kn@


# 1.199 08-Jul-2018 tb

netstart is used during system start, but also interactively.
Show proper error message if a regular user executes netstart.
Only do the privilege check if the id binary is available,
which might not be the case during diskless system startup.

ok deraadt, jasper, jca, krw, rpe (who wrote the same diff), sthen


# 1.198 28-Apr-2018 rpe

Add a proper usage() function.

Suggested by and OK jmc.
OK tb


Revision tags: OPENBSD_6_3_BASE
# 1.197 04-Mar-2018 jmc

when -n is used, no need to spit out "Missing parameters." before
displaying usage();

ok tb


# 1.196 03-Mar-2018 landry

Lowercase 'usage' and group -n with interface in it.
From jmc@, ok tb@


# 1.195 21-Feb-2018 rpe

Tweak comments.

OK tb


# 1.194 19-Feb-2018 rpe

Write warning/error messages to stderr and end them with a fullstop.

OK tb


# 1.193 19-Feb-2018 rpe

- use specific patterns when looping over /etc/hostname.if files
to skip backup or temp files.
- test if the patterns matched actual files
- warn if ifcreate() fails on an interface and continue with the
subsequent interfaces in the list instead of return'ing

OK dlg sthen tb


# 1.192 17-Feb-2018 rpe

- Add descriptions for the new functions ifcreate() and vifscreate()
- In ifcreate() use the exit code of the {} block directly
- In vifscreate(), use the ifconfig -C output directly in the for _vif loop
- Remove superfluous and somewhat confusing comment

OK dlg kn sthen


# 1.191 14-Feb-2018 dlg

create virtual interfaces before starting all interface config.

this resolves an ordering problem when adding pseudo interfaces to bridges

tweaks from kn@
ok mpi@ sthen@


# 1.190 10-Feb-2018 claudio

Remove some special IPv4 in IPv6 mapped prefixes that are already rejected
by the ::0.0.0.0/96 reject route added to deny all IPv4 mapped addresses.
Makes the inet6 routing table almost fit in one screen.
OK benno@


# 1.189 10-Feb-2018 florian

Load RFC 7217 key material and generate if it does not already exist.

Add soii.key to changelist (pointed out by semarie) and mtree/special
(suggest by Craig Skinner).

OK naddy, sthen, rpe, tb


# 1.188 06-Feb-2018 tb

If -n is given, the netstart script should not (try to) set the default
route(s). Simply print the command(s) to be issued instead.

tweak & ok rpe


# 1.187 12-Nov-2017 tb

Remove HN_DIR variable and expand it in the only place it was used. It
currently serves no purpose.

ok rpe, agreement from deraadt and halex


Revision tags: OPENBSD_6_2_BASE
# 1.186 25-Jul-2017 rpe

Finally remove backwards compat code to support the 'rtsol' keyword
in hostname.if(5)

OK mpi@ deraadt@ florian@
OK jmc@ from doc perspective


# 1.185 21-Jul-2017 rpe

Align ifstart() in netstart and install.sub.

- in netstart, rename _file to _hn referencing hostname.if files
- in install.sub switch ifstart() to be used with _if instead of
_hn as parameter

ok krw@ tb@


# 1.184 28-May-2017 awolk

etc/netstart: use colon separator instead of dot with chown

OK jung@, deraadt@, jmc@


# 1.183 07-May-2017 rpe

Change test from [] to [[]] and simplify pattern.

OK tb@, krw@ (for [[]])
Feedback and OK halex@


# 1.182 07-May-2017 rpe

Replace hardcoded script name with ${0##*/}

OK tb@ halex@


# 1.181 01-May-2017 rpe

Revert r1.170 and remove the id==0 check.
The id binary is not available in nfs diskless setups at this point.

reported by Andreas Kusalananda, thanks.
discussed with deraadt@


# 1.180 01-May-2017 rpe

Remove last remnants of rtsol. IPv6 autoconfiguration of interfaces is now
done in ifstart(). Remove ipv6autoconf() and replace rtsolif with a boolean
variable V6_AUTOCONF. Replace dhcpif with a boolean variable V4_DHCPCONF.
Both are later used in defaultroute() to decide whether or not to configre
defaultroutes from /etc/mygate.

OK krw@


# 1.179 30-Apr-2017 mpi

Do not try to delete a default route before adding it.

Now that route are automatically G/C with the address they are attached
to there's no reason to duplicate the kernel's job.

Fix a regression introduced with multipath default routes.

ok deraadt@


# 1.178 25-Apr-2017 rpe

Unbreak netstart for multiple inteface configurations like trunk
or carp. Ensure that the noglob option is disabled at the end of
parse_hn_line() and ifstart().

Reported by Christer Solskogen and Stefan Wollny, thanks!


# 1.177 24-Apr-2017 rpe

Introduce a new function parse_hn_line() that replaces the existing
hostname.if(5) parsing code in ifstart().
Add a -n option to netstart to only print the interface configuration
commands instead of executing them.
Add a HN_DIR variable, that points to the directory of the hostname.if
files (default /etc) that allows for future regression tests.

- add new parse_hn_line() function
- change ifstart()
- rename $if to $_if
- don't ifconfig or ifconfig create if -n option is used
- replace hostname.if(5) parsing code with new parse_hn_line()
- just print configuration commands if -n option is used
- autoconf now happens in ifstart(), remove ifv6autoconf()
- introduce HN_DIR variable for the hostname.if file location
- add handling of the -n option to only print config commands
- ensure -n is only used if interfaces are specified as parameters

Discussed with and positive feedback from many
'commit' deraadt@
OK sthen@


# 1.176 08-Apr-2017 rpe

- localize the if, file and stat variables which also ensures that
variables are not named like commands.
- change test from [] to [[]]

OK tb@ halex@


# 1.175 07-Apr-2017 rpe

Minimize differences in ifstart() function between netstart and
install.sub which makes it easier to spot changes in the future.

- comments and formatting
- quotes on assignments are not needed (netstart)
- remove stray space in test (netstart)
- use $file variable with while-loop (netstart)
- although valid, instead of i use $i in arithmetic test (install.sub)

OK krw@, tb@
Looks good deraadt@


# 1.174 07-Apr-2017 rpe

Align comments of ifstart() function in netstart and install.sub.


# 1.173 07-Apr-2017 rpe

Align comments of stripcom() function in netstart and install.sub.


Revision tags: OPENBSD_6_1_BASE
# 1.172 06-Dec-2016 mpi

Do not lose the default route when netstart(8) is run a second time on
the interface pointed to by the default route.

Since the kernel no longer keep routes with dangling address pointer,
netstart(8) has to re-add the default route when the corresponding ifa
has been deleted and re-created.

deraadt@ points out that even if the previous semantic was not necessarily
better, a script like netstart(8) cannot totally fix the default route
problem.

Regression reported by and fix tested by Hrvoje Popovski.

ksh foo checked by halex@


# 1.171 27-Sep-2016 rzalamena

Delay switch(4) interface start up so it can attach virtual interfaces
like vether(4).

nits from and ok benno@, phessler@


# 1.170 09-Sep-2016 jasper

print a clear error message when not ran as root instead of just falling
through and try whatever it can do with the invoking user's perms

feedback/ok aja@ rpe@


Revision tags: OPENBSD_6_0_BASE
# 1.169 19-Jul-2016 mpi

Do not consider tap(4) a special interface and start if before other
pseudo-interfaces.

This unbreak vlan(4) on top of tap(4) since the refactoring to turn it
MP-safe.

ok claudio@, deraadt@


# 1.168 27-Mar-2016 sthen

Don't delete the 224/4 route in netstart, unless it's being done to ensure that
a -reject route can be added. Restores the ability to set an interface route
before daemons are started, lost during the previous simplification.
ok millert mpi


Revision tags: OPENBSD_5_9_BASE
# 1.167 29-Dec-2015 rpe

Remove backslash, not necessary after '&&'

OK halex@


# 1.166 29-Dec-2015 rpe

Replace last remaining `` with $()

OK halex@


# 1.165 18-Dec-2015 ajacoutot

Drop the now useless multicast setup comment.

prodded by tim@, ok mpi@


# 1.164 17-Dec-2015 ajacoutot

Simplify multicast option handling (10 less lines) by matching /etc/rc behavior
towards other YES|NO options and drop the error warning.


with and ok tim@, ok rpe@ on an earlier diff


# 1.163 05-Dec-2015 mpi

It does not make sense to insert a specific route for 224/4 when the
default one is good enough.

So merge rc.conf(8)'s 'multicast_router' and 'multicast_host' into a
single 'multicast'. If set to YES the reject route for 224/4 is not
inserted by netstart(8).

Manual bits from jmc@

ok henning@, ajacoutot@


# 1.162 12-Nov-2015 rpe

Changes to ifautostart():
- Rename function to ifv6autoconf() to make IPv6 relation clearer
- Localize and rename variables

OK krw@


# 1.161 12-Nov-2015 rpe

Changes to ifmstart():
- Change comments to make it clearer that ifmstart() takes two lists
of interface driver names (of which the second is optional) and not
the actual interface instances.
- Use localized variables and use slightly more verbose names.
- Use continue 2 to skip to the next hostname.if file.
- Use shell pattern @() instead of testing _sif individually.

OK krw@


# 1.160 12-Nov-2015 rpe

Changes to stripcom():
- Align comments with /etc/rc version
- Use localized variables
- Use safer "print -r --" instead of plain echo

Changes to ifstart():
- Tweak comment
- Add usage

OK krw@


# 1.159 01-Nov-2015 rpe

Start the rework of the /etc/netstart shell script.

General changes:
- apply a similar 'style' as used in the installer scripts
- improve comments to be more to the point, remove where code is obvious
- document usage of functions if they have arguments
- rename variables where it improves readability
- replace really old-school shell code with more contemporary idioms

Other changes:
- No need to care about "autoboot" because netstart doesn't inherit the
positional parameters from /etc/rc anymore. /etc/rc executes netstart
instead of sourcing it since r1.439.
- Use simpler for-loop to process list of interfaces with ifstart.

OK halex@


# 1.158 26-Oct-2015 rpe

The hostname variable is not used since r1.99. Remove it and use
stripcom() output directly with the hostname command.

OK deraadt@ krw@


# 1.157 23-Oct-2015 claudio

netstart bits for tap(4)


# 1.156 27-Sep-2015 sthen

Don't print output when setting autoconf on interfaces. Suggested by deraadt,
ok florian@ rpe@


# 1.155 13-Sep-2015 sthen

only print the "IPv6 autoconf" line if there are interfaces to configure
feedback/ok rpe


# 1.154 11-Sep-2015 sthen

Set "inet6 autoconf" individually on interfaces that have rtsol set in
hostname.if, previously netstart tried to configure them all at once
("ifconfig if0 if1 if2 inet6 autoconf"). From Delan Azabani, ok phessler@


Revision tags: OPENBSD_5_8_BASE
# 1.153 20-Jul-2015 rpe

Disable Strict Bourne shell mode for /etc/rc and /etc/netstart to be
able to use ksh syntax within these scripts. This way init doesn't
need to be changed, which starts /etc/rc using /bin/sh and people
can still use "sh /etc/netstart ifname".

Idea from and OK halex@
OK deraadt@ krw@ guenther@


# 1.152 19-Jul-2015 florian

Bring up pflow last as it might send with a source address that is on
any of the other interfaces.
OK deraadt, phessler, benno


# 1.151 19-Jul-2015 rpe

Always source rc.subr to be able to use the rc.conf parsing routine
to get the network related vars from rc.conf. This is even necessary
if netstart is run from within /etc/rc. Remove test of $INRC which
unintentionally evaluated always to true.

problem with previous change found by nigel@
OK sthen@ aja@ halex@


# 1.150 19-Jul-2015 ajacoutot

Revert 1.148 for now until I can talk to rpe@
It introduced a regression reported by nigel@


# 1.149 19-Jul-2015 rpe

Replace test command with [].

OK halex@ krw@


# 1.148 19-Jul-2015 rpe

Ensure, that we source rc.subr and parse rc.conf ONLY if we are not
inside /etc/rc.

With help from and OK halex@, ajacoutot@


# 1.147 18-Jul-2015 rpe

- remove trailing blanks introduced in previous commit
- no space in redirections like </foo or >$bar
- few other minor whitespaces

OK krw@


# 1.146 18-Jul-2015 rpe

Improve comments
- Add comments for functions
- Start comments with capital letters
- End comments with a full stop
- Allow comments to extend up to column 80

OK krw@


# 1.145 06-Jun-2015 florian

Allow rtsol keyword in hostname.if(5) with net.inet6.ip6.forwarding=1.
"inet6 autoconf" was working before and rtsol should behave the same.
OK phessler


Revision tags: OPENBSD_5_7_BASE
# 1.144 03-Dec-2014 florian

The kernel handles rtsol(8) functionality since some time now.
Treat rtsol in hostname.if as a keyword like dhcp and call ifconfig
inet6 autoconf.
"reads good" todd@
OK krw@ (who is *not* an IPv6 person), but I recruited him in his
capacity as an installer person.


# 1.143 28-Sep-2014 claudio

Revert 1.142. Without the down netstart will just print the ifconfig
output because it may end up just calling 'ifconfig $if'. This needs
to be done better and properly tested.


# 1.142 26-Sep-2014 halex

remove explicit 'down' of an interface before starting a dhcp request, thereby
avoiding annoying delays for some switch configurations

ok claudio@ deraadt@

i would add ok phessler@, but it was not valid without an ok krw@


Revision tags: OPENBSD_5_6_BASE
# 1.141 12-Jul-2014 stsp

Fix netstart after autoconf6 change so 'rtsol' lines in hostname.if work again.
found by pelikan@; ok pelikan@ henning@


# 1.140 12-Jul-2014 robert

Make rc.conf a parsed configuration file and stop sourcing it as a shell
script.
From now on rc.conf has a fixed syntax (key=val) and it is not allowed
to add anything to it besides the supported syntax, it all going to be
ignored.

discussed with and help from deraadt@ and halex@


Revision tags: OPENBSD_5_5_BASE
# 1.139 22-Aug-2013 mpi

Like for dhclient, do no create a route to alias addresses via 127.0.0.1.
Our stack is able to tell if the address is local or not.

ok todd@, krw@


Revision tags: OPENBSD_5_4_BASE
# 1.138 20-Mar-2013 todd

fix lies in netstart; replacement wording from halex@
pointed out by Ryan Kavannagh rak at debian dot org


Revision tags: OPENBSD_5_3_BASE
# 1.137 05-Dec-2012 rpe

remove "Invalid interface name" message
requested by krw@

ok halex@


# 1.136 02-Dec-2012 rpe

use the more compact version of the check for ifconfig'able interfaces
from install.sub

with feedback from and ok halex


# 1.135 02-Dec-2012 rpe

- remove isalphanumeric() and replace it with a shell pattern, that
tries a bit harder to identify invalid interface names and in
this case emit an error message.
- use [[ $1 == autoboot ]] to avoid a shell error message due to
possible spaces in first argument
- no change in functionality

discussed with krw and halex
ok ("I like this") krw


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.134 07-Oct-2011 deraadt

The new ypbind changes requires that the domainname be set before
rc.conf is run. There's no real downside.
ok aja


Revision tags: OPENBSD_5_0_BASE
# 1.133 07-Jul-2011 guenther

Eliminate some $? tests by rolling the command into the condition

ok halex@


# 1.132 26-May-2011 mpf

Add svlan(4) startup bits.
From markus@. OK naddy, claudio, reyk.


Revision tags: OPENBSD_4_9_BASE
# 1.131 09-Feb-2011 sobrado

fix an unbalanced parenthesis in a comment; while here, split the comment
in a better place to make it more readable.

ok jmc@ and miod@


Revision tags: OPENBSD_4_8_BASE
# 1.130 16-Jun-2010 todd

permit e.g. -inet6 syntax by slurping all lines not just some
noticed by rhsv6 at hushmail dot com, ok sthen@


Revision tags: OPENBSD_4_7_BASE
# 1.129 12-Jan-2010 henning

when setting up lo0 use 127.0.0.1/8 instead of 127.0.0.1 for clarity and
correctness. it's not 1992 any more, kids. ok mcbride dlg krw


# 1.128 10-Dec-2009 todd

o stop reordering ifconfig arguments (e.g. after 'up ..')
o only stop processing if inet or inet6 lines are malformed
o everything not a specially handled bit is passed to ifconfig unmangled
noticed by several after the move from bridgename.bridge0 -> hostname.bridge0
prodded by deraadt@, tested by and feedback from several
man page bits 'look fine' jmc@


# 1.127 22-Nov-2009 deraadt

Stop supporting bridgename.bridge* files, and move to hostname.bridge*
files. To cope with this change, read about the mv command.
ok claudio todd


# 1.126 17-Sep-2009 simon

change variable i to $i in an expression of ifstart() for consistency
with the rest of the file. no functional change.

feedback from sthen@, ok krw@


# 1.125 10-Jul-2009 jdixon

Delay creation of tun(4) interfaces until the underlying interface and
routes are available. This fixes usage for some OpenVPN users that start
it from hostname.tun*.

Tested by Johan Huldtgren. ok sthen@, johan@.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.124 25-Nov-2008 markus

delay /etc/netstart until IPv6-DAD (dup-address-detection) is completed.
ok fries, hshoexer, claudio


# 1.123 14-Aug-2008 sthen

Tools from /usr may not be used in netstart since it may be NFS-mounted
and not available at that time. Rewrite the hostname.if permission check
to use only /bin/ls and the shell. Requested by deraadt.

ok todd, "Twisted." deraadt


Revision tags: OPENBSD_4_4_BASE
# 1.122 23-Jul-2008 sthen

Prevent warning about insecure hostnames where no /etc/hostname.*
exists. From wcmaier@.

Check target of symbolic links to avoid noise at boot and in
seucrity output where you have several interfaces symlinked to one
config file.

"If you think this is the right thing to do" deraadt@


# 1.121 09-Jun-2008 todd

warn once not 3 times in case of a non existent file, discussed with deraadt
originally pointed out by Johan Torin


# 1.120 09-Jun-2008 deraadt

Ensure that hostname.* files are also re-chowned to root.wheel at each
boot as discussed with claudio while eating tasty donairs. ok todd


# 1.119 17-Apr-2008 deraadt

before using them, force hostname.* files to be unreadable by world
first version from todd, ok millert


Revision tags: OPENBSD_4_3_BASE
# 1.118 17-Jan-2008 brad

Execute rtsol after turning up trunk(4) and vlan(4) interfaces so they're
taken into consideration for rtsol.

ok reyk@ dlg@


# 1.117 09-Jan-2008 mpf

Do not bring up pfsync(4) before the working ruleset
has been loaded. Otherwise, states that are received during the
initial bulk update mismatch the correct pf-checksum and
do not attach to the rules.
Problem identified by david@. Fix done in collaboration.
OK henning@


Revision tags: OPENBSD_4_2_BASE
# 1.116 02-Aug-2007 david

move the delay for IPv6 DAD to after all interfaces have started
fixes problems with daemons being unable to bind to all addreses at boot
ok itojun@ hshoexer@


Revision tags: OPENBSD_4_1_BASE
# 1.115 15-Nov-2006 itojun

reject multicast packet without scope identifier specified.


Revision tags: OPENBSD_4_0_BASE
# 1.114 29-Jun-2006 todd

do not add an extra space; nwid and description come out wrong
fix as proposed by maja@, thanks!


Revision tags: OPENBSD_3_9_BASE
# 1.113 28-Dec-2005 david

nuke extra whitespace


# 1.112 06-Dec-2005 reyk

multicast_host=YES only works if a valid default gateway is available.
validate this condition and reject multicast traffic on failure.

ok todd@ naddy@


# 1.111 02-Nov-2005 todd

fix inspired by pr#4590
ok krw@


# 1.110 25-Oct-2005 todd

better logic from krw@:
- do not process mygate for v4 if dhcp
- do not process mygate for v6 if rtsol
this also makes the mygate processing logic more readable
ok krw@


# 1.109 14-Oct-2005 todd

add v6 support for /etc/mygate
ok deraadt@ mickey@ krw@
same functionality tested/ok'ed by by mickey, brad, matthieu, and me
with this one may now put a v6 IP in /etc/mygate on a separate line from
the v4 default gateway and netstart will do the right thing


# 1.108 12-Oct-2005 todd

shrink stripcom(), sync with install.sub
ok krw@


# 1.107 04-Oct-2005 todd

trunk must be started after physical ethernet devices, but before vlan.
populate ifmstart lines accordingly.
prodded/tested by brad@
ok reyk@


# 1.106 28-Sep-2005 todd

use eval consistently, fixes description quotes on rtsol and dhcp
fix inspired by and closes pr 4495
ok krw@


Revision tags: OPENBSD_3_8_BASE
# 1.105 22-May-2005 todd

Introduce 'ifmstart' to deal with starting multiple interfaces minus a list
of interfaces.

This reduces the netstart script by 174 chars, 13 words, and 19 lines, but
more importantly, makes it more simple and less cluttered should more special
case/orderings be needed.

ok brad@ and pr 4197 submitter, inspired by and closes pr 4197


# 1.104 04-Apr-2005 djm

unbreak; ok pval@


# 1.103 03-Apr-2005 deraadt

if dhcp is used to get an address on any interface, ignore /etc/mygate
ok krw
(this lets us do something rather cool with the zaurus in particular)


Revision tags: OPENBSD_3_7_BASE
# 1.102 04-Jan-2005 mcbride

Bring up the carp(4) interface before default route.

ok pascoe@ mpf@


# 1.101 30-Dec-2004 millert

Add a copy of stripcom so /etc/netstart can be run standalone again.
OK deraadt@


# 1.100 19-Dec-2004 millert

Allow comments in /etc/{myname,mygate,defaultdomain}; OK deraadt@


# 1.99 04-Dec-2004 itojun

remove "route $hostname 127.0.0.1" line. deraadt ok
*** please update /etc/netstart and test if it works ok for you ***


# 1.98 20-Oct-2004 deraadt

make all route commands use -qn; ok mcbride henning


Revision tags: OPENBSD_3_6_BASE
# 1.97 29-May-2004 deraadt

one last route command lacking -qn


Revision tags: OPENBSD_3_5_BASE
# 1.96 22-Mar-2004 mcbride

Make sure pfsync is brought up before carp.

ok deraadt@


# 1.95 13-Mar-2004 mcbride

Delay pfsync(4) configuration, as the syncif has to be configured in
advance. From Thorsten Lockert.


# 1.94 14-Jan-2004 deraadt

ok, it took quite a bit of prodding but itojun finally explained why the
extra sleep 1 is in here, and we came to the conclusion it is safe to
delete it. whee.


# 1.93 13-Jan-2004 deraadt

repair v6 lo0 documentation


# 1.92 11-Jan-2004 deraadt

add loopback routes late


# 1.91 09-Jan-2004 deraadt

create all routes with -q; markus ok


# 1.90 04-Dec-2003 millert

Need to do "ifconfig create" for bridge interfaces too.


# 1.89 03-Dec-2003 markus

add support for ifconfig clone; from netbsd; ok deraadt, henning


# 1.88 20-Oct-2003 david

delay carp initialization until after physical interfaces are configured
ok mcbride@ henning@ deraadt@ todd@


Revision tags: OPENBSD_3_4_BASE
# 1.87 27-Aug-2003 henning

only try to set hostname to what /etc/myname says if that file actually exists,
otherwise preserve `hostname`
netbooted machines can live perfectly fine without it; they get their hostname
earlier.

ok krw@ cedric@


Revision tags: OPENBSD_3_3_BASE
# 1.86 16-Feb-2003 krw

Fix up some DNS verbiage to make it consistant.

Fix up default route selection by

a) Forcing user to explicitly chose 'dhcp' as a mechanism for
specifying a default route, rather than guessing based on one or more
interfaces being configured by dhcp.

b) If the user specified default route does not work, re-present the
existing default route rather than losing it.

c) Move default route selection to after nameserver activation so the
user can specify a hostname as the default route.

Change /etc/netstart so that /etc/mygate wins if a default route was
already specified (i.e. by dhcp).

ok deraadt@.


Revision tags: OPENBSD_3_2_BASE
# 1.85 16-May-2002 todd

ignore non-existent cases where '$if' evaluates to '*'.
From Andr� Lucas <andre@ae-35.com>, fixes pr # 2658.
'Looks good' from miod@, millert@, and krw@.


Revision tags: OPENBSD_3_1_BASE
# 1.84 23-Feb-2002 deraadt

re-add support for $if expansion; hamajima@nagoya.ydc.co.jp


# 1.83 21-Feb-2002 miod

Change the network components initialization order.
Change from:
o all interfaces
o all bridges
o routes
to:
o physical interfaces
o routes
o gif and gre interfaces
o bridges

Fixeski PR #2400.
Manual page updates coming soon.
Ok angelos@ chris@ deraadt@


Revision tags: OPENBSD_3_0_BASE
# 1.82 31-Jul-2001 hugh

a space before a redirect


# 1.81 06-Jul-2001 angelos

Also, source /etc/rc.conf so we can pull in the
multicast_host/multicast_router settings; this is useful if one
flushes the routing table and re-initializes.

We really need a netconfig tool of sorts.


# 1.80 06-Jul-2001 angelos

Use "route -n show -inet" to determine the default multicast iface.


# 1.79 03-Jul-2001 deraadt

pull in rc.conf early so that pf(1) startup is right; tested by jasoni, comments from millert


# 1.78 30-May-2001 deraadt

Remove ipf. Darren Reed has interpreted his (old, new, whichever)
licence in a way that makes ipf not free according to the rules we
established over 5 years ago, at www.openbsd.org/goals.html (and those
same basic rules govern the other *BSD projects too). Specifically,
Darren says that modified versions are not permitted. But software
which OpenBSD uses and redistributes must be free to all (be they
people or companies), for any purpose they wish to use it, including
modification, use, peeing on, or even integration into baby mulching
machines or atomic bombs to be dropped on Australia. Furthermore, we
know of a number of companies using ipf with modification like us, who
are now in the same situation, and we hope that some of them will work
with us to fill this gap that now exists in OpenBSD (temporarily, we
hope).


Revision tags: OPENBSD_2_9_BASE
# 1.77 13-Mar-2001 deraadt

spelling; maurice@maurice.wan.nl


# 1.76 06-Feb-2001 todd

ignore blank lines in addition to comments
fixes pr#1660 from wilfried@telia.com .. Thanks!


# 1.75 10-Jan-2001 jason

support !command in bridgename.if files, too


# 1.74 27-Nov-2000 millert

Use -n to test if a variable is non-zero. Otherwise, if the variable's
contents start with a '-' test becomes unhappy (since it interprets it
as another option).


# 1.73 08-Nov-2000 todd

This fixes pr 1481, we now handle args > 6 in /etc/hostname.if in the
cases where we did not previously handle them.
Thanks to Scott Atwood <atwood@cs.stanford.edu> for reminding us of this.


Revision tags: OPENBSD_2_8_BASE
# 1.72 02-Sep-2000 todd

subtle bug .. global variables in a while loop need reset 'just incase'
With:
hostname.fxp0 having a last line of:
inet6 alias 3ffe:...
and hostname.gif0 having a first two lines of:
giftunnel 1.2.3.4
dest 1.2.4.3
We end up with the command:
ifconfig gif0 giftunnel alias 1.2.3.4 1.2.4.3
.. which is clearly wrong and fixed by this change


# 1.71 18-Jun-2000 todd

rc.conf now parses ${local_rcconf} internally; closes pr 1259


Revision tags: OPENBSD_2_7_BASE
# 1.70 08-May-2000 todd

fix dhcp 'NONE' ness from install to allow media parsing to work
.. ok deraadt@, millert@


# 1.69 21-Apr-2000 deraadt

rc.conf.local support, inspired by chuck yerkes


# 1.68 04-Apr-2000 millert

Remove the -E flag from ipf as it is implicitly enabled and using
the -E flag here causes the kernel to printf 'IP Filter: already
initialized'.


# 1.67 18-Mar-2000 deraadt

silence all extra route addition printouts


# 1.66 17-Mar-2000 itojun

correct reject route installations for IPv6. improve comments.


# 1.65 12-Mar-2000 itojun

disallow packets to malicious 6to4 prefix, based on
http://playground.iijlab.net/i-d/draft-itojun-ipv6-transition-abuse-00.txt


# 1.64 10-Mar-2000 todd

fix non behavior
with this `!' lines in /etc/hostname.* run even without certain lines
(like a comment) preceeding it.


# 1.63 10-Jan-2000 todd

allow arbitrary commands in /etc/hostname.* files if the line starts with '!'


# 1.62 02-Jan-2000 deraadt

rtsol case can configure the interface up, since it would be nice to finish
DAD before the actual rtsol(8) run happens later. and since it will rtsol,
it is going to be up in any case.


# 1.61 02-Jan-2000 itojun

one more indentation fix.


# 1.60 02-Jan-2000 itojun

indentation fix (todd's part)


# 1.59 02-Jan-2000 todd

fix rtsold case, reset cmd for each iteration!


# 1.58 02-Jan-2000 itojun

allow options after "rtsol".
XXX both "dhcp" and "rtsol" has keyword *down* at the end. is it okay?


# 1.57 02-Jan-2000 itojun

echo "IPv6 autoconf: interfaces" before invoking rtsol.
sleep for net.inet6.ip6.dad_count seconds to ensure that IPv6 DAD is completed.
TODO: rtsold (rc.conf line), manpage


# 1.56 02-Jan-2000 itojun

ipv6 autoconf on hosts (non-routers).

to do this,
1. in sysctl.conf, add these lines:
net.inet6.ip6.forwarding=0
net.inet6.ip6.accept_rtadv=1
2. in hostname.foo, add
rtsol

specifying two or more interfaces with "rtsol" may result in strange
behavior - ipv6 spec does not permit multi-interface node to be autoconfig'ed.


# 1.55 02-Jan-2000 todd

add to hostname.* parsing:
- multiple entries support (read: aliases)
- inet6 support
- support for comments (#)
(look for hostname.if(5) commit for syntax details)


# 1.54 31-Dec-1999 itojun

install IPv6 reject routes only if kernel is capable of IPv6.


# 1.53 09-Dec-1999 itojun

avoid transmitting invalid IPv6 packets out to the wire.


# 1.52 09-Dec-1999 itojun

do not perform IPv6 initialization for loopback interface.
MUST make lo0 up before any IPv6 operations.
it will be considered a pilot error if you don't.
(I prefer to have lo0 initialized automatically)


Revision tags: OPENBSD_2_6_BASE
# 1.51 01-Sep-1999 deraadt

support # characters in bridgename.* files; millert


# 1.50 01-Sep-1999 deraadt

cleanup parsing of hostname.* files, and seperate bridge control into
bridgename.* files; all documented in new hostname.if(5) and
bridgename.if(5) man pages


# 1.49 09-Aug-1999 angelos

Only parse/setup the hostname.foo file if interface foo exists (this
is useful for laptops with different ethernet cards etc.)


Revision tags: OPENBSD_2_5_BASE
# 1.48 29-Mar-1999 niklas

New multicast route setup style


# 1.47 26-Mar-1999 niklas

Add bridge interface handling


# 1.46 01-Mar-1999 millert

Add support in /etc/hostname.xxx for files of the format:
up [options]
Any of the following may or may not be set:
$name $mask $bcaddr $extras


# 1.45 28-Oct-1998 millert

Kill the awful hack used to match and split /etc/hostname.* We now use
a function, isalphanumeric, to determine whether an interface name is
likely to be valid. This means that things like /etc/hostname.le0.bak,
/etc/hostname.le0#, /etc/hostname.le0~, etc. will be ignored as they
should. There is no longer an implicate assumption that /etc/hostname.*
only contains a single '.'.


Revision tags: OPENBSD_2_4_BASE
# 1.44 06-Oct-1998 deraadt

move ipnat to end of netstart, to support dhcp+ipnat


# 1.43 18-Sep-1998 deraadt

apply media directives on dhcp interfaces


# 1.42 10-Sep-1998 marc

better way of handling dhcp client; Jason Ish <jbi130@mail.usask.ca>


# 1.41 08-Sep-1998 marc

dhcp client stuff. "Angelos D. Keromytis" <angelos@dsl.cis.upenn.edu>


# 1.40 24-Aug-1998 downsj

You can't use -interface default when there's no default gateway
set (yet). Use -interface $hostname if mygate doesn't exist so that
this actually works on routers.


# 1.39 04-Jul-1998 deraadt

put 224 route on default, to avoid a hostname lookup


# 1.38 22-May-1998 deraadt

use route -n, what the heck


Revision tags: OPENBSD_2_3_BASE
# 1.37 28-Mar-1998 deraadt

s/^nat/ipnat/


# 1.36 23-Feb-1998 niklas

remove trailing blank line


# 1.35 07-Feb-1998 deraadt

ipforward is in sysctl.conf now


# 1.34 21-Dec-1997 deraadt

ugh


# 1.33 20-Dec-1997 deraadt

ipforwarding option in rc.conf


# 1.32 29-Nov-1997 kstailey

NAT requires IPF


# 1.31 04-Nov-1997 deraadt

kill spaces at ends of lines; m4


Revision tags: OPENBSD_2_2_BASE
# 1.30 14-Oct-1997 deraadt

set hostname/domainname before running rc.conf; m4@umn.edu


# 1.29 04-Sep-1997 deraadt

fork netstart; new child is rc.conf


# 1.28 25-Aug-1997 millert

Explicately pass -host flag to route(8) to avoid confusion with networks.


# 1.27 19-Aug-1997 niklas

Add hook for rpc.lockd, make nfsd flags settable in netstart


# 1.26 31-Jul-1997 downsj

Make quotas optional; wedged into netstart for the time being.
/etc/rc.conf, anyone?


# 1.25 30-Jul-1997 deraadt

do not run routed by default


# 1.24 28-Jul-1997 kstailey

Move configuration of loopback interface to before all other interfaces.
Allows the use of local caching-only nameserver with no "nameserver"
entry in /etc/resolv.conf to configure a route between the hostname
and loopback.


# 1.23 25-Jul-1997 provos

earlier start of keymanagement


# 1.22 24-Jul-1997 deraadt

make amd use /tmp_mnt by default


# 1.21 22-Jul-1997 provos

start the photuris daemon per default. hilfe.


# 1.20 17-Jun-1997 niklas

Put in hooks to start ypserv with flags


# 1.19 17-Jun-1997 niklas

Put in hooks to start rpc.yppasswdd with flags


Revision tags: OPENBSD_2_1_BASE
# 1.18 15-Apr-1997 deraadt

kill route flush until .. hmm kernel routing socket bug or something


# 1.17 09-Apr-1997 kstailey

add NAT startup


# 1.16 07-Apr-1997 rees

flush all old routes before adding new interfaces or routes.
ref: netbsd pr3228/misc, Matthias Scheler


# 1.15 03-Mar-1997 downsj

fix typo


# 1.14 11-Feb-1997 deraadt

add default route before fiddling with loopback route to avoid DNS problems; m4@umn.edu, #97


# 1.13 03-Feb-1997 deraadt

do ifaliases after /usr/bin exists in nfs diskless env; pr#77, matthieu@laas.fr


# 1.12 02-Nov-1996 deraadt

timed off by default


Revision tags: OPENBSD_2_0_BASE
# 1.11 23-Sep-1996 deraadt

rfc1323 variable


# 1.10 04-Sep-1996 deraadt

control portmap, inetd, and lpd from netstart; idea from tqbf@enteract.com


# 1.9 27-Aug-1996 deraadt

224.0.0.0 not 0.0.0.224; from peter@demon.net


# 1.8 18-Jun-1996 deraadt

move std stuff from rc.local to rc


# 1.7 16-Jun-1996 deraadt

install sample commented /etc/ifaliases file; which can now contain #
comments and blank lines. new format is "interface address netmask"
(yes, i changed the order of the entries). inspired by netbsd pr#2474;
gillhaa@ghost.whirlpool.com


# 1.6 02-Jun-1996 tholo

Install a multicast route by default


# 1.5 26-May-1996 deraadt

sync & label


# 1.4 09-Jan-1996 dm

added IP filter to netstat/rc and put examples in /usr/share/ipf


# 1.3 30-Dec-1995 deraadt

from netbsd: start mrouted like routed


# 1.2 18-Dec-1995 deraadt

/etc/ifaliases support by randy@zyzzyva.com


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.230 05-Dec-2022 afresh1

Add support configuring hostname.if(5) by lladdr

Original implementation by martijn@
Feedback and suggestions from kn@, sthen@, claudio@, florian@, and deraadt@.

ok deraadt


# 1.229 05-Nov-2022 kn

"need root privileges" is an error, print it on stderr"


# 1.228 05-Nov-2022 kn

Print full path in usage; OK jmc


# 1.227 01-Nov-2022 kn

Only load the SOII key if IPv6 is available

Possible now that IP6KERNERL is hoisted.
This also improves readability and zaps double negation logic.


# 1.226 01-Nov-2022 kn

Do not wait for DAD completion in dry-run mode

1. only do so when running without -n
2. move code to own wait_dad() helper like wait_autoconf_default() has it
3. use local _count as usual in both functions rather than the global count

Feedback OK claudio


# 1.225 31-Oct-2022 kn

Hoist only the feature check

Keep adding IPv6 routes after lo0 got an addres like before, meant to be
committed together with r1.223.


# 1.224 31-Oct-2022 kn

Fix comment: IPv6 link local addresses do not use SOII anymore

sys/netinet6/in6_ifattach.c r1.114 limited it to SLAAC addresses in 2019.


# 1.223 31-Oct-2022 kn

Improve shell style wrt. variable naming/boolean convention

The mixed use of upper and lower case variables is neither obvious nor
consistent.

PRINT_ONLY is local to netstart.
ip6kernel is local to netstart.
multicast gets sourced from rc.subr(8).

1. uppercase ip6kernel as is common for global variables in base scripts
2. use the simpler true/false idiom and default with the rest of
netstart-only variables, making it clearer that only `multicast=YES/NO'
comes from the rc environment
3. hoist kernel feature detection such that a later diff can load the SOII
key conditionally
4. zap obvious comment

OK aja


# 1.222 24-Oct-2022 kn

do not wait for autoconf in dry-run

If there is no default route but some interface has AUTOCONF, printing
what would be done still waits for... nothing to happen.

OK tb


# 1.221 24-Oct-2022 kn

Add required sh(1) to synopsis

Contrary to other scripts in base like rc.d(8) or MAKEDEV(8), netstart(8)
itself is not executable and must be passed as file to sh(1):
$ man -h netstart
/etc/netstart [-n] [interface ...]
$ /etc/netstart
ksh: /etc/netstart: cannot execute - Permission denied

Fix usage and synopsis to provide required usage:
$ man -h netsart
sh /etc/netstart [-n] [interface ...]

OK jmc


# 1.220 21-Oct-2022 kn

Fix synopsis, -n does not require an interface; OK jmc


Revision tags: OPENBSD_7_2_BASE
# 1.219 03-Jul-2022 kn

Create virtual interfaces upfront if specified on the command line

In cases like `sh /etc/netstart pair1 pair2', one of hostname.pair{1,2}
will contain a "patch pair{2,1}" command which expects the other interface
to exist.

If none exist, this would fail and netstart had to be run separately or
"patch"ed interface had to be manually created before.

There are other use cases where interfaces depend on each other, so before
(re)configuring an explicit list of interfaces, create all virtual ones
upfront so that a single netstart invocation will configure everything
correctly without having reflect dependencies in multiple ordered netstart
invocations.

Copy isin() from install.sub to help.

Feedback OK halex


# 1.218 26-Jun-2022 florian

Wait for autoconf interfaces to come up in netstart(8) instead of
rc(8). This makes tunnel interfaces work that depend on working
autoconf interfaces.
OK deraadt


Revision tags: OPENBSD_7_1_BASE
# 1.217 22-Feb-2022 dlg

add some more tunnels to the list of interfaces that rely on routing.


Revision tags: OPENBSD_7_0_BASE
# 1.216 02-Sep-2021 bluhm

Do not create loopback interfaces lo1, lo2, ... upfront. They are
automatically set up by the kernel when a routing domain is created.
An existing lo1 in rdomain 0 would prevent to add any interfaces
in rdomain 1.
OK kn@


# 1.215 30-Aug-2021 bluhm

Improve dubgging in /etc/netstart. Enable print only in ifcreate.
Add debugging output for ipv6 routes. Make localhost and multicast
code aware of the print only switch. Allow netstart -n to work
also if no interface is given.
OK kn@


# 1.214 06-Aug-2021 sthen

As tim@ spotted, a use of V4_AUTOCONF crept in when the variable name
was actually V4_DHCPCONF from previous use. Rename all of the V4_DHCPCONF
to V4_AUTOCONF so everything uses the new name. ok and reminder about
the installer from tb@


# 1.213 16-Jul-2021 florian

switch to dhcpleased/resolvd in base
OK deraadt


# 1.212 20-Jun-2021 florian

Don't try to install a default route with route(8) later on if we are
using inet autoconf, like we do with "dhcp" and "inet6 autoconf".
OK kn


Revision tags: OPENBSD_6_9_BASE
# 1.211 23-Dec-2020 krw

Allow the provision of dhclient(8) options on 'dhcp' lines in hostname.if(5)
files.

Usual man page help & ok jmc@


# 1.210 21-Dec-2020 krw

Avoid issuing pointless 'ifconfig <if> up' when processing 'dhcp' in
hostname.if files. dhclient(8) does that itself. Part of the
"further script optimizations" promised in r1.200 of netstart.

Tested & ok gnezdo@


# 1.209 29-Nov-2020 tb

Fix previous: use correct version of netstart and installer bits.


# 1.208 29-Nov-2020 deraadt

Add support for !command to mygate, so that netstart has a late opportunity
to perform network configuration (for example, "!route source -ifp em0")
Split mygate and myname manual pages (how did anyone ever believe these
are related), and perform hostname configuration much earlier in rc.
discussed with benno, claudio, jmc, etc etc, last version of !command
parser by tb


# 1.207 08-Nov-2020 jmc

no more mobileip;
ok claudio deraadt


Revision tags: OPENBSD_6_8_BASE
# 1.206 21-Jun-2020 dlg

start wg with the other interfaces that rely on routing being up.

from Matt Dunwoodie and Jason A. Donenfeld

ok deraadt@


# 1.205 22-May-2020 kn

Revert the following commit as it breaks hostname.if(5) lines with a
backslash at the end for line continuation

Breaking long lines into multiple ones must still be possible and does
require to treat the backslash as an escape character.

Breakage reported by Mark Patruck <mark at wrapped dot cx >, thanks!

---
distrib/miniroot/install.sub revision 1.1151
etc/netstart revision 1.203
date: 2020/05/21 11:54:41; author: kn; state: Exp; lines: +2 -2;
Do not treat backslashe as an escape character in hostname.if(5) lines

ifstart() should always pass such lines unaltered, especially if they
contain "nwid" or "description" lines with arbitrary strings.

<bsdlisten at gmail dot com> reported SSIDs such as "Mike's" during
installation end as broken; this was because the installer escaped
the single quote using backslashes which ended up being treated as
escape characters much later during hostname.if parsing in netstart(8).

Ok deraadt


# 1.204 21-May-2020 kn

Fix stripcom() description wrt. comments not on their own line

Neither netstart's nor install.sub's (subtly different) implementations
remove trailing comments on lines not starting as a comment, e.g.,
lines like "up #not down" go through unaltered and without "#not down"
being removed.

Only lines *beginning* with the comment sign ("#") are stripped.

No functional change, just updating function descriptions.


# 1.203 21-May-2020 kn

Do not treat backslashe as an escape character in hostname.if(5) lines

ifstart() should always pass such lines unaltered, especially if they
contain "nwid" or "description" lines with arbitrary strings.

<bsdlisten at gmail dot com> reported SSIDs such as "Mike's" during
installation end as broken; this was because the installer escaped
the single quote using backslashes which ended up being treated as
escape characters much later during hostname.if parsing in netstart(8).

Ok deraadt


Revision tags: OPENBSD_6_7_BASE
# 1.202 15-Jan-2020 kn

Do not redirect already quiet stdout for IPv6 reject routes

"route -q" already silences all standard output; if it still prints
something, that's a bug to fix in route.

OK bluhm


# 1.201 25-Oct-2019 dlg

handle aggr(4) in the same way as trunk(4)

from brad@
ok bluhm@ claudio@ deraadt@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.200 29-Aug-2018 krw

Historically /etc/netstart (and the equivalent code in the install
script) did 'ifconfig <if> down' before starting dhclient(8). This was
a way of ensuring old running copies of dhclient were killed before a
new one started. Current dhclient does not need this assist, so change
"ifconfig <if> down" to "ifconfig <if> up" pending further script
optimizations.

Similar to a 2014 attempt by halex@. Prompted by a misc@ report
from Kristjan Komlosi reporting hanging diskless setups.

ok halex@ kn@


# 1.199 08-Jul-2018 tb

netstart is used during system start, but also interactively.
Show proper error message if a regular user executes netstart.
Only do the privilege check if the id binary is available,
which might not be the case during diskless system startup.

ok deraadt, jasper, jca, krw, rpe (who wrote the same diff), sthen


# 1.198 28-Apr-2018 rpe

Add a proper usage() function.

Suggested by and OK jmc.
OK tb


Revision tags: OPENBSD_6_3_BASE
# 1.197 04-Mar-2018 jmc

when -n is used, no need to spit out "Missing parameters." before
displaying usage();

ok tb


# 1.196 03-Mar-2018 landry

Lowercase 'usage' and group -n with interface in it.
From jmc@, ok tb@


# 1.195 21-Feb-2018 rpe

Tweak comments.

OK tb


# 1.194 19-Feb-2018 rpe

Write warning/error messages to stderr and end them with a fullstop.

OK tb


# 1.193 19-Feb-2018 rpe

- use specific patterns when looping over /etc/hostname.if files
to skip backup or temp files.
- test if the patterns matched actual files
- warn if ifcreate() fails on an interface and continue with the
subsequent interfaces in the list instead of return'ing

OK dlg sthen tb


# 1.192 17-Feb-2018 rpe

- Add descriptions for the new functions ifcreate() and vifscreate()
- In ifcreate() use the exit code of the {} block directly
- In vifscreate(), use the ifconfig -C output directly in the for _vif loop
- Remove superfluous and somewhat confusing comment

OK dlg kn sthen


# 1.191 14-Feb-2018 dlg

create virtual interfaces before starting all interface config.

this resolves an ordering problem when adding pseudo interfaces to bridges

tweaks from kn@
ok mpi@ sthen@


# 1.190 10-Feb-2018 claudio

Remove some special IPv4 in IPv6 mapped prefixes that are already rejected
by the ::0.0.0.0/96 reject route added to deny all IPv4 mapped addresses.
Makes the inet6 routing table almost fit in one screen.
OK benno@


# 1.189 10-Feb-2018 florian

Load RFC 7217 key material and generate if it does not already exist.

Add soii.key to changelist (pointed out by semarie) and mtree/special
(suggest by Craig Skinner).

OK naddy, sthen, rpe, tb


# 1.188 06-Feb-2018 tb

If -n is given, the netstart script should not (try to) set the default
route(s). Simply print the command(s) to be issued instead.

tweak & ok rpe


# 1.187 12-Nov-2017 tb

Remove HN_DIR variable and expand it in the only place it was used. It
currently serves no purpose.

ok rpe, agreement from deraadt and halex


Revision tags: OPENBSD_6_2_BASE
# 1.186 25-Jul-2017 rpe

Finally remove backwards compat code to support the 'rtsol' keyword
in hostname.if(5)

OK mpi@ deraadt@ florian@
OK jmc@ from doc perspective


# 1.185 21-Jul-2017 rpe

Align ifstart() in netstart and install.sub.

- in netstart, rename _file to _hn referencing hostname.if files
- in install.sub switch ifstart() to be used with _if instead of
_hn as parameter

ok krw@ tb@


# 1.184 28-May-2017 awolk

etc/netstart: use colon separator instead of dot with chown

OK jung@, deraadt@, jmc@


# 1.183 07-May-2017 rpe

Change test from [] to [[]] and simplify pattern.

OK tb@, krw@ (for [[]])
Feedback and OK halex@


# 1.182 07-May-2017 rpe

Replace hardcoded script name with ${0##*/}

OK tb@ halex@


# 1.181 01-May-2017 rpe

Revert r1.170 and remove the id==0 check.
The id binary is not available in nfs diskless setups at this point.

reported by Andreas Kusalananda, thanks.
discussed with deraadt@


# 1.180 01-May-2017 rpe

Remove last remnants of rtsol. IPv6 autoconfiguration of interfaces is now
done in ifstart(). Remove ipv6autoconf() and replace rtsolif with a boolean
variable V6_AUTOCONF. Replace dhcpif with a boolean variable V4_DHCPCONF.
Both are later used in defaultroute() to decide whether or not to configre
defaultroutes from /etc/mygate.

OK krw@


# 1.179 30-Apr-2017 mpi

Do not try to delete a default route before adding it.

Now that route are automatically G/C with the address they are attached
to there's no reason to duplicate the kernel's job.

Fix a regression introduced with multipath default routes.

ok deraadt@


# 1.178 25-Apr-2017 rpe

Unbreak netstart for multiple inteface configurations like trunk
or carp. Ensure that the noglob option is disabled at the end of
parse_hn_line() and ifstart().

Reported by Christer Solskogen and Stefan Wollny, thanks!


# 1.177 24-Apr-2017 rpe

Introduce a new function parse_hn_line() that replaces the existing
hostname.if(5) parsing code in ifstart().
Add a -n option to netstart to only print the interface configuration
commands instead of executing them.
Add a HN_DIR variable, that points to the directory of the hostname.if
files (default /etc) that allows for future regression tests.

- add new parse_hn_line() function
- change ifstart()
- rename $if to $_if
- don't ifconfig or ifconfig create if -n option is used
- replace hostname.if(5) parsing code with new parse_hn_line()
- just print configuration commands if -n option is used
- autoconf now happens in ifstart(), remove ifv6autoconf()
- introduce HN_DIR variable for the hostname.if file location
- add handling of the -n option to only print config commands
- ensure -n is only used if interfaces are specified as parameters

Discussed with and positive feedback from many
'commit' deraadt@
OK sthen@


# 1.176 08-Apr-2017 rpe

- localize the if, file and stat variables which also ensures that
variables are not named like commands.
- change test from [] to [[]]

OK tb@ halex@


# 1.175 07-Apr-2017 rpe

Minimize differences in ifstart() function between netstart and
install.sub which makes it easier to spot changes in the future.

- comments and formatting
- quotes on assignments are not needed (netstart)
- remove stray space in test (netstart)
- use $file variable with while-loop (netstart)
- although valid, instead of i use $i in arithmetic test (install.sub)

OK krw@, tb@
Looks good deraadt@


# 1.174 07-Apr-2017 rpe

Align comments of ifstart() function in netstart and install.sub.


# 1.173 07-Apr-2017 rpe

Align comments of stripcom() function in netstart and install.sub.


Revision tags: OPENBSD_6_1_BASE
# 1.172 06-Dec-2016 mpi

Do not lose the default route when netstart(8) is run a second time on
the interface pointed to by the default route.

Since the kernel no longer keep routes with dangling address pointer,
netstart(8) has to re-add the default route when the corresponding ifa
has been deleted and re-created.

deraadt@ points out that even if the previous semantic was not necessarily
better, a script like netstart(8) cannot totally fix the default route
problem.

Regression reported by and fix tested by Hrvoje Popovski.

ksh foo checked by halex@


# 1.171 27-Sep-2016 rzalamena

Delay switch(4) interface start up so it can attach virtual interfaces
like vether(4).

nits from and ok benno@, phessler@


# 1.170 09-Sep-2016 jasper

print a clear error message when not ran as root instead of just falling
through and try whatever it can do with the invoking user's perms

feedback/ok aja@ rpe@


Revision tags: OPENBSD_6_0_BASE
# 1.169 19-Jul-2016 mpi

Do not consider tap(4) a special interface and start if before other
pseudo-interfaces.

This unbreak vlan(4) on top of tap(4) since the refactoring to turn it
MP-safe.

ok claudio@, deraadt@


# 1.168 27-Mar-2016 sthen

Don't delete the 224/4 route in netstart, unless it's being done to ensure that
a -reject route can be added. Restores the ability to set an interface route
before daemons are started, lost during the previous simplification.
ok millert mpi


Revision tags: OPENBSD_5_9_BASE
# 1.167 29-Dec-2015 rpe

Remove backslash, not necessary after '&&'

OK halex@


# 1.166 29-Dec-2015 rpe

Replace last remaining `` with $()

OK halex@


# 1.165 18-Dec-2015 ajacoutot

Drop the now useless multicast setup comment.

prodded by tim@, ok mpi@


# 1.164 17-Dec-2015 ajacoutot

Simplify multicast option handling (10 less lines) by matching /etc/rc behavior
towards other YES|NO options and drop the error warning.


with and ok tim@, ok rpe@ on an earlier diff


# 1.163 05-Dec-2015 mpi

It does not make sense to insert a specific route for 224/4 when the
default one is good enough.

So merge rc.conf(8)'s 'multicast_router' and 'multicast_host' into a
single 'multicast'. If set to YES the reject route for 224/4 is not
inserted by netstart(8).

Manual bits from jmc@

ok henning@, ajacoutot@


# 1.162 12-Nov-2015 rpe

Changes to ifautostart():
- Rename function to ifv6autoconf() to make IPv6 relation clearer
- Localize and rename variables

OK krw@


# 1.161 12-Nov-2015 rpe

Changes to ifmstart():
- Change comments to make it clearer that ifmstart() takes two lists
of interface driver names (of which the second is optional) and not
the actual interface instances.
- Use localized variables and use slightly more verbose names.
- Use continue 2 to skip to the next hostname.if file.
- Use shell pattern @() instead of testing _sif individually.

OK krw@


# 1.160 12-Nov-2015 rpe

Changes to stripcom():
- Align comments with /etc/rc version
- Use localized variables
- Use safer "print -r --" instead of plain echo

Changes to ifstart():
- Tweak comment
- Add usage

OK krw@


# 1.159 01-Nov-2015 rpe

Start the rework of the /etc/netstart shell script.

General changes:
- apply a similar 'style' as used in the installer scripts
- improve comments to be more to the point, remove where code is obvious
- document usage of functions if they have arguments
- rename variables where it improves readability
- replace really old-school shell code with more contemporary idioms

Other changes:
- No need to care about "autoboot" because netstart doesn't inherit the
positional parameters from /etc/rc anymore. /etc/rc executes netstart
instead of sourcing it since r1.439.
- Use simpler for-loop to process list of interfaces with ifstart.

OK halex@


# 1.158 26-Oct-2015 rpe

The hostname variable is not used since r1.99. Remove it and use
stripcom() output directly with the hostname command.

OK deraadt@ krw@


# 1.157 23-Oct-2015 claudio

netstart bits for tap(4)


# 1.156 27-Sep-2015 sthen

Don't print output when setting autoconf on interfaces. Suggested by deraadt,
ok florian@ rpe@


# 1.155 13-Sep-2015 sthen

only print the "IPv6 autoconf" line if there are interfaces to configure
feedback/ok rpe


# 1.154 11-Sep-2015 sthen

Set "inet6 autoconf" individually on interfaces that have rtsol set in
hostname.if, previously netstart tried to configure them all at once
("ifconfig if0 if1 if2 inet6 autoconf"). From Delan Azabani, ok phessler@


Revision tags: OPENBSD_5_8_BASE
# 1.153 20-Jul-2015 rpe

Disable Strict Bourne shell mode for /etc/rc and /etc/netstart to be
able to use ksh syntax within these scripts. This way init doesn't
need to be changed, which starts /etc/rc using /bin/sh and people
can still use "sh /etc/netstart ifname".

Idea from and OK halex@
OK deraadt@ krw@ guenther@


# 1.152 19-Jul-2015 florian

Bring up pflow last as it might send with a source address that is on
any of the other interfaces.
OK deraadt, phessler, benno


# 1.151 19-Jul-2015 rpe

Always source rc.subr to be able to use the rc.conf parsing routine
to get the network related vars from rc.conf. This is even necessary
if netstart is run from within /etc/rc. Remove test of $INRC which
unintentionally evaluated always to true.

problem with previous change found by nigel@
OK sthen@ aja@ halex@


# 1.150 19-Jul-2015 ajacoutot

Revert 1.148 for now until I can talk to rpe@
It introduced a regression reported by nigel@


# 1.149 19-Jul-2015 rpe

Replace test command with [].

OK halex@ krw@


# 1.148 19-Jul-2015 rpe

Ensure, that we source rc.subr and parse rc.conf ONLY if we are not
inside /etc/rc.

With help from and OK halex@, ajacoutot@


# 1.147 18-Jul-2015 rpe

- remove trailing blanks introduced in previous commit
- no space in redirections like </foo or >$bar
- few other minor whitespaces

OK krw@


# 1.146 18-Jul-2015 rpe

Improve comments
- Add comments for functions
- Start comments with capital letters
- End comments with a full stop
- Allow comments to extend up to column 80

OK krw@


# 1.145 06-Jun-2015 florian

Allow rtsol keyword in hostname.if(5) with net.inet6.ip6.forwarding=1.
"inet6 autoconf" was working before and rtsol should behave the same.
OK phessler


Revision tags: OPENBSD_5_7_BASE
# 1.144 03-Dec-2014 florian

The kernel handles rtsol(8) functionality since some time now.
Treat rtsol in hostname.if as a keyword like dhcp and call ifconfig
inet6 autoconf.
"reads good" todd@
OK krw@ (who is *not* an IPv6 person), but I recruited him in his
capacity as an installer person.


# 1.143 28-Sep-2014 claudio

Revert 1.142. Without the down netstart will just print the ifconfig
output because it may end up just calling 'ifconfig $if'. This needs
to be done better and properly tested.


# 1.142 26-Sep-2014 halex

remove explicit 'down' of an interface before starting a dhcp request, thereby
avoiding annoying delays for some switch configurations

ok claudio@ deraadt@

i would add ok phessler@, but it was not valid without an ok krw@


Revision tags: OPENBSD_5_6_BASE
# 1.141 12-Jul-2014 stsp

Fix netstart after autoconf6 change so 'rtsol' lines in hostname.if work again.
found by pelikan@; ok pelikan@ henning@


# 1.140 12-Jul-2014 robert

Make rc.conf a parsed configuration file and stop sourcing it as a shell
script.
From now on rc.conf has a fixed syntax (key=val) and it is not allowed
to add anything to it besides the supported syntax, it all going to be
ignored.

discussed with and help from deraadt@ and halex@


Revision tags: OPENBSD_5_5_BASE
# 1.139 22-Aug-2013 mpi

Like for dhclient, do no create a route to alias addresses via 127.0.0.1.
Our stack is able to tell if the address is local or not.

ok todd@, krw@


Revision tags: OPENBSD_5_4_BASE
# 1.138 20-Mar-2013 todd

fix lies in netstart; replacement wording from halex@
pointed out by Ryan Kavannagh rak at debian dot org


Revision tags: OPENBSD_5_3_BASE
# 1.137 05-Dec-2012 rpe

remove "Invalid interface name" message
requested by krw@

ok halex@


# 1.136 02-Dec-2012 rpe

use the more compact version of the check for ifconfig'able interfaces
from install.sub

with feedback from and ok halex


# 1.135 02-Dec-2012 rpe

- remove isalphanumeric() and replace it with a shell pattern, that
tries a bit harder to identify invalid interface names and in
this case emit an error message.
- use [[ $1 == autoboot ]] to avoid a shell error message due to
possible spaces in first argument
- no change in functionality

discussed with krw and halex
ok ("I like this") krw


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.134 07-Oct-2011 deraadt

The new ypbind changes requires that the domainname be set before
rc.conf is run. There's no real downside.
ok aja


Revision tags: OPENBSD_5_0_BASE
# 1.133 07-Jul-2011 guenther

Eliminate some $? tests by rolling the command into the condition

ok halex@


# 1.132 26-May-2011 mpf

Add svlan(4) startup bits.
From markus@. OK naddy, claudio, reyk.


Revision tags: OPENBSD_4_9_BASE
# 1.131 09-Feb-2011 sobrado

fix an unbalanced parenthesis in a comment; while here, split the comment
in a better place to make it more readable.

ok jmc@ and miod@


Revision tags: OPENBSD_4_8_BASE
# 1.130 16-Jun-2010 todd

permit e.g. -inet6 syntax by slurping all lines not just some
noticed by rhsv6 at hushmail dot com, ok sthen@


Revision tags: OPENBSD_4_7_BASE
# 1.129 12-Jan-2010 henning

when setting up lo0 use 127.0.0.1/8 instead of 127.0.0.1 for clarity and
correctness. it's not 1992 any more, kids. ok mcbride dlg krw


# 1.128 10-Dec-2009 todd

o stop reordering ifconfig arguments (e.g. after 'up ..')
o only stop processing if inet or inet6 lines are malformed
o everything not a specially handled bit is passed to ifconfig unmangled
noticed by several after the move from bridgename.bridge0 -> hostname.bridge0
prodded by deraadt@, tested by and feedback from several
man page bits 'look fine' jmc@


# 1.127 22-Nov-2009 deraadt

Stop supporting bridgename.bridge* files, and move to hostname.bridge*
files. To cope with this change, read about the mv command.
ok claudio todd


# 1.126 17-Sep-2009 simon

change variable i to $i in an expression of ifstart() for consistency
with the rest of the file. no functional change.

feedback from sthen@, ok krw@


# 1.125 10-Jul-2009 jdixon

Delay creation of tun(4) interfaces until the underlying interface and
routes are available. This fixes usage for some OpenVPN users that start
it from hostname.tun*.

Tested by Johan Huldtgren. ok sthen@, johan@.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.124 25-Nov-2008 markus

delay /etc/netstart until IPv6-DAD (dup-address-detection) is completed.
ok fries, hshoexer, claudio


# 1.123 14-Aug-2008 sthen

Tools from /usr may not be used in netstart since it may be NFS-mounted
and not available at that time. Rewrite the hostname.if permission check
to use only /bin/ls and the shell. Requested by deraadt.

ok todd, "Twisted." deraadt


Revision tags: OPENBSD_4_4_BASE
# 1.122 23-Jul-2008 sthen

Prevent warning about insecure hostnames where no /etc/hostname.*
exists. From wcmaier@.

Check target of symbolic links to avoid noise at boot and in
seucrity output where you have several interfaces symlinked to one
config file.

"If you think this is the right thing to do" deraadt@


# 1.121 09-Jun-2008 todd

warn once not 3 times in case of a non existent file, discussed with deraadt
originally pointed out by Johan Torin


# 1.120 09-Jun-2008 deraadt

Ensure that hostname.* files are also re-chowned to root.wheel at each
boot as discussed with claudio while eating tasty donairs. ok todd


# 1.119 17-Apr-2008 deraadt

before using them, force hostname.* files to be unreadable by world
first version from todd, ok millert


Revision tags: OPENBSD_4_3_BASE
# 1.118 17-Jan-2008 brad

Execute rtsol after turning up trunk(4) and vlan(4) interfaces so they're
taken into consideration for rtsol.

ok reyk@ dlg@


# 1.117 09-Jan-2008 mpf

Do not bring up pfsync(4) before the working ruleset
has been loaded. Otherwise, states that are received during the
initial bulk update mismatch the correct pf-checksum and
do not attach to the rules.
Problem identified by david@. Fix done in collaboration.
OK henning@


Revision tags: OPENBSD_4_2_BASE
# 1.116 02-Aug-2007 david

move the delay for IPv6 DAD to after all interfaces have started
fixes problems with daemons being unable to bind to all addreses at boot
ok itojun@ hshoexer@


Revision tags: OPENBSD_4_1_BASE
# 1.115 15-Nov-2006 itojun

reject multicast packet without scope identifier specified.


Revision tags: OPENBSD_4_0_BASE
# 1.114 29-Jun-2006 todd

do not add an extra space; nwid and description come out wrong
fix as proposed by maja@, thanks!


Revision tags: OPENBSD_3_9_BASE
# 1.113 28-Dec-2005 david

nuke extra whitespace


# 1.112 06-Dec-2005 reyk

multicast_host=YES only works if a valid default gateway is available.
validate this condition and reject multicast traffic on failure.

ok todd@ naddy@


# 1.111 02-Nov-2005 todd

fix inspired by pr#4590
ok krw@


# 1.110 25-Oct-2005 todd

better logic from krw@:
- do not process mygate for v4 if dhcp
- do not process mygate for v6 if rtsol
this also makes the mygate processing logic more readable
ok krw@


# 1.109 14-Oct-2005 todd

add v6 support for /etc/mygate
ok deraadt@ mickey@ krw@
same functionality tested/ok'ed by by mickey, brad, matthieu, and me
with this one may now put a v6 IP in /etc/mygate on a separate line from
the v4 default gateway and netstart will do the right thing


# 1.108 12-Oct-2005 todd

shrink stripcom(), sync with install.sub
ok krw@


# 1.107 04-Oct-2005 todd

trunk must be started after physical ethernet devices, but before vlan.
populate ifmstart lines accordingly.
prodded/tested by brad@
ok reyk@


# 1.106 28-Sep-2005 todd

use eval consistently, fixes description quotes on rtsol and dhcp
fix inspired by and closes pr 4495
ok krw@


Revision tags: OPENBSD_3_8_BASE
# 1.105 22-May-2005 todd

Introduce 'ifmstart' to deal with starting multiple interfaces minus a list
of interfaces.

This reduces the netstart script by 174 chars, 13 words, and 19 lines, but
more importantly, makes it more simple and less cluttered should more special
case/orderings be needed.

ok brad@ and pr 4197 submitter, inspired by and closes pr 4197


# 1.104 04-Apr-2005 djm

unbreak; ok pval@


# 1.103 03-Apr-2005 deraadt

if dhcp is used to get an address on any interface, ignore /etc/mygate
ok krw
(this lets us do something rather cool with the zaurus in particular)


Revision tags: OPENBSD_3_7_BASE
# 1.102 04-Jan-2005 mcbride

Bring up the carp(4) interface before default route.

ok pascoe@ mpf@


# 1.101 30-Dec-2004 millert

Add a copy of stripcom so /etc/netstart can be run standalone again.
OK deraadt@


# 1.100 19-Dec-2004 millert

Allow comments in /etc/{myname,mygate,defaultdomain}; OK deraadt@


# 1.99 04-Dec-2004 itojun

remove "route $hostname 127.0.0.1" line. deraadt ok
*** please update /etc/netstart and test if it works ok for you ***


# 1.98 20-Oct-2004 deraadt

make all route commands use -qn; ok mcbride henning


Revision tags: OPENBSD_3_6_BASE
# 1.97 29-May-2004 deraadt

one last route command lacking -qn


Revision tags: OPENBSD_3_5_BASE
# 1.96 22-Mar-2004 mcbride

Make sure pfsync is brought up before carp.

ok deraadt@


# 1.95 13-Mar-2004 mcbride

Delay pfsync(4) configuration, as the syncif has to be configured in
advance. From Thorsten Lockert.


# 1.94 14-Jan-2004 deraadt

ok, it took quite a bit of prodding but itojun finally explained why the
extra sleep 1 is in here, and we came to the conclusion it is safe to
delete it. whee.


# 1.93 13-Jan-2004 deraadt

repair v6 lo0 documentation


# 1.92 11-Jan-2004 deraadt

add loopback routes late


# 1.91 09-Jan-2004 deraadt

create all routes with -q; markus ok


# 1.90 04-Dec-2003 millert

Need to do "ifconfig create" for bridge interfaces too.


# 1.89 03-Dec-2003 markus

add support for ifconfig clone; from netbsd; ok deraadt, henning


# 1.88 20-Oct-2003 david

delay carp initialization until after physical interfaces are configured
ok mcbride@ henning@ deraadt@ todd@


Revision tags: OPENBSD_3_4_BASE
# 1.87 27-Aug-2003 henning

only try to set hostname to what /etc/myname says if that file actually exists,
otherwise preserve `hostname`
netbooted machines can live perfectly fine without it; they get their hostname
earlier.

ok krw@ cedric@


Revision tags: OPENBSD_3_3_BASE
# 1.86 16-Feb-2003 krw

Fix up some DNS verbiage to make it consistant.

Fix up default route selection by

a) Forcing user to explicitly chose 'dhcp' as a mechanism for
specifying a default route, rather than guessing based on one or more
interfaces being configured by dhcp.

b) If the user specified default route does not work, re-present the
existing default route rather than losing it.

c) Move default route selection to after nameserver activation so the
user can specify a hostname as the default route.

Change /etc/netstart so that /etc/mygate wins if a default route was
already specified (i.e. by dhcp).

ok deraadt@.


Revision tags: OPENBSD_3_2_BASE
# 1.85 16-May-2002 todd

ignore non-existent cases where '$if' evaluates to '*'.
From Andr� Lucas <andre@ae-35.com>, fixes pr # 2658.
'Looks good' from miod@, millert@, and krw@.


Revision tags: OPENBSD_3_1_BASE
# 1.84 23-Feb-2002 deraadt

re-add support for $if expansion; hamajima@nagoya.ydc.co.jp


# 1.83 21-Feb-2002 miod

Change the network components initialization order.
Change from:
o all interfaces
o all bridges
o routes
to:
o physical interfaces
o routes
o gif and gre interfaces
o bridges

Fixeski PR #2400.
Manual page updates coming soon.
Ok angelos@ chris@ deraadt@


Revision tags: OPENBSD_3_0_BASE
# 1.82 31-Jul-2001 hugh

a space before a redirect


# 1.81 06-Jul-2001 angelos

Also, source /etc/rc.conf so we can pull in the
multicast_host/multicast_router settings; this is useful if one
flushes the routing table and re-initializes.

We really need a netconfig tool of sorts.


# 1.80 06-Jul-2001 angelos

Use "route -n show -inet" to determine the default multicast iface.


# 1.79 03-Jul-2001 deraadt

pull in rc.conf early so that pf(1) startup is right; tested by jasoni, comments from millert


# 1.78 30-May-2001 deraadt

Remove ipf. Darren Reed has interpreted his (old, new, whichever)
licence in a way that makes ipf not free according to the rules we
established over 5 years ago, at www.openbsd.org/goals.html (and those
same basic rules govern the other *BSD projects too). Specifically,
Darren says that modified versions are not permitted. But software
which OpenBSD uses and redistributes must be free to all (be they
people or companies), for any purpose they wish to use it, including
modification, use, peeing on, or even integration into baby mulching
machines or atomic bombs to be dropped on Australia. Furthermore, we
know of a number of companies using ipf with modification like us, who
are now in the same situation, and we hope that some of them will work
with us to fill this gap that now exists in OpenBSD (temporarily, we
hope).


Revision tags: OPENBSD_2_9_BASE
# 1.77 13-Mar-2001 deraadt

spelling; maurice@maurice.wan.nl


# 1.76 06-Feb-2001 todd

ignore blank lines in addition to comments
fixes pr#1660 from wilfried@telia.com .. Thanks!


# 1.75 10-Jan-2001 jason

support !command in bridgename.if files, too


# 1.74 27-Nov-2000 millert

Use -n to test if a variable is non-zero. Otherwise, if the variable's
contents start with a '-' test becomes unhappy (since it interprets it
as another option).


# 1.73 08-Nov-2000 todd

This fixes pr 1481, we now handle args > 6 in /etc/hostname.if in the
cases where we did not previously handle them.
Thanks to Scott Atwood <atwood@cs.stanford.edu> for reminding us of this.


Revision tags: OPENBSD_2_8_BASE
# 1.72 02-Sep-2000 todd

subtle bug .. global variables in a while loop need reset 'just incase'
With:
hostname.fxp0 having a last line of:
inet6 alias 3ffe:...
and hostname.gif0 having a first two lines of:
giftunnel 1.2.3.4
dest 1.2.4.3
We end up with the command:
ifconfig gif0 giftunnel alias 1.2.3.4 1.2.4.3
.. which is clearly wrong and fixed by this change


# 1.71 18-Jun-2000 todd

rc.conf now parses ${local_rcconf} internally; closes pr 1259


Revision tags: OPENBSD_2_7_BASE
# 1.70 08-May-2000 todd

fix dhcp 'NONE' ness from install to allow media parsing to work
.. ok deraadt@, millert@


# 1.69 21-Apr-2000 deraadt

rc.conf.local support, inspired by chuck yerkes


# 1.68 04-Apr-2000 millert

Remove the -E flag from ipf as it is implicitly enabled and using
the -E flag here causes the kernel to printf 'IP Filter: already
initialized'.


# 1.67 18-Mar-2000 deraadt

silence all extra route addition printouts


# 1.66 17-Mar-2000 itojun

correct reject route installations for IPv6. improve comments.


# 1.65 12-Mar-2000 itojun

disallow packets to malicious 6to4 prefix, based on
http://playground.iijlab.net/i-d/draft-itojun-ipv6-transition-abuse-00.txt


# 1.64 10-Mar-2000 todd

fix non behavior
with this `!' lines in /etc/hostname.* run even without certain lines
(like a comment) preceeding it.


# 1.63 10-Jan-2000 todd

allow arbitrary commands in /etc/hostname.* files if the line starts with '!'


# 1.62 02-Jan-2000 deraadt

rtsol case can configure the interface up, since it would be nice to finish
DAD before the actual rtsol(8) run happens later. and since it will rtsol,
it is going to be up in any case.


# 1.61 02-Jan-2000 itojun

one more indentation fix.


# 1.60 02-Jan-2000 itojun

indentation fix (todd's part)


# 1.59 02-Jan-2000 todd

fix rtsold case, reset cmd for each iteration!


# 1.58 02-Jan-2000 itojun

allow options after "rtsol".
XXX both "dhcp" and "rtsol" has keyword *down* at the end. is it okay?


# 1.57 02-Jan-2000 itojun

echo "IPv6 autoconf: interfaces" before invoking rtsol.
sleep for net.inet6.ip6.dad_count seconds to ensure that IPv6 DAD is completed.
TODO: rtsold (rc.conf line), manpage


# 1.56 02-Jan-2000 itojun

ipv6 autoconf on hosts (non-routers).

to do this,
1. in sysctl.conf, add these lines:
net.inet6.ip6.forwarding=0
net.inet6.ip6.accept_rtadv=1
2. in hostname.foo, add
rtsol

specifying two or more interfaces with "rtsol" may result in strange
behavior - ipv6 spec does not permit multi-interface node to be autoconfig'ed.


# 1.55 02-Jan-2000 todd

add to hostname.* parsing:
- multiple entries support (read: aliases)
- inet6 support
- support for comments (#)
(look for hostname.if(5) commit for syntax details)


# 1.54 31-Dec-1999 itojun

install IPv6 reject routes only if kernel is capable of IPv6.


# 1.53 09-Dec-1999 itojun

avoid transmitting invalid IPv6 packets out to the wire.


# 1.52 09-Dec-1999 itojun

do not perform IPv6 initialization for loopback interface.
MUST make lo0 up before any IPv6 operations.
it will be considered a pilot error if you don't.
(I prefer to have lo0 initialized automatically)


Revision tags: OPENBSD_2_6_BASE
# 1.51 01-Sep-1999 deraadt

support # characters in bridgename.* files; millert


# 1.50 01-Sep-1999 deraadt

cleanup parsing of hostname.* files, and seperate bridge control into
bridgename.* files; all documented in new hostname.if(5) and
bridgename.if(5) man pages


# 1.49 09-Aug-1999 angelos

Only parse/setup the hostname.foo file if interface foo exists (this
is useful for laptops with different ethernet cards etc.)


Revision tags: OPENBSD_2_5_BASE
# 1.48 29-Mar-1999 niklas

New multicast route setup style


# 1.47 26-Mar-1999 niklas

Add bridge interface handling


# 1.46 01-Mar-1999 millert

Add support in /etc/hostname.xxx for files of the format:
up [options]
Any of the following may or may not be set:
$name $mask $bcaddr $extras


# 1.45 28-Oct-1998 millert

Kill the awful hack used to match and split /etc/hostname.* We now use
a function, isalphanumeric, to determine whether an interface name is
likely to be valid. This means that things like /etc/hostname.le0.bak,
/etc/hostname.le0#, /etc/hostname.le0~, etc. will be ignored as they
should. There is no longer an implicate assumption that /etc/hostname.*
only contains a single '.'.


Revision tags: OPENBSD_2_4_BASE
# 1.44 06-Oct-1998 deraadt

move ipnat to end of netstart, to support dhcp+ipnat


# 1.43 18-Sep-1998 deraadt

apply media directives on dhcp interfaces


# 1.42 10-Sep-1998 marc

better way of handling dhcp client; Jason Ish <jbi130@mail.usask.ca>


# 1.41 08-Sep-1998 marc

dhcp client stuff. "Angelos D. Keromytis" <angelos@dsl.cis.upenn.edu>


# 1.40 24-Aug-1998 downsj

You can't use -interface default when there's no default gateway
set (yet). Use -interface $hostname if mygate doesn't exist so that
this actually works on routers.


# 1.39 04-Jul-1998 deraadt

put 224 route on default, to avoid a hostname lookup


# 1.38 22-May-1998 deraadt

use route -n, what the heck


Revision tags: OPENBSD_2_3_BASE
# 1.37 28-Mar-1998 deraadt

s/^nat/ipnat/


# 1.36 23-Feb-1998 niklas

remove trailing blank line


# 1.35 07-Feb-1998 deraadt

ipforward is in sysctl.conf now


# 1.34 21-Dec-1997 deraadt

ugh


# 1.33 20-Dec-1997 deraadt

ipforwarding option in rc.conf


# 1.32 29-Nov-1997 kstailey

NAT requires IPF


# 1.31 04-Nov-1997 deraadt

kill spaces at ends of lines; m4


Revision tags: OPENBSD_2_2_BASE
# 1.30 14-Oct-1997 deraadt

set hostname/domainname before running rc.conf; m4@umn.edu


# 1.29 04-Sep-1997 deraadt

fork netstart; new child is rc.conf


# 1.28 25-Aug-1997 millert

Explicately pass -host flag to route(8) to avoid confusion with networks.


# 1.27 19-Aug-1997 niklas

Add hook for rpc.lockd, make nfsd flags settable in netstart


# 1.26 31-Jul-1997 downsj

Make quotas optional; wedged into netstart for the time being.
/etc/rc.conf, anyone?


# 1.25 30-Jul-1997 deraadt

do not run routed by default


# 1.24 28-Jul-1997 kstailey

Move configuration of loopback interface to before all other interfaces.
Allows the use of local caching-only nameserver with no "nameserver"
entry in /etc/resolv.conf to configure a route between the hostname
and loopback.


# 1.23 25-Jul-1997 provos

earlier start of keymanagement


# 1.22 24-Jul-1997 deraadt

make amd use /tmp_mnt by default


# 1.21 22-Jul-1997 provos

start the photuris daemon per default. hilfe.


# 1.20 17-Jun-1997 niklas

Put in hooks to start ypserv with flags


# 1.19 17-Jun-1997 niklas

Put in hooks to start rpc.yppasswdd with flags


Revision tags: OPENBSD_2_1_BASE
# 1.18 15-Apr-1997 deraadt

kill route flush until .. hmm kernel routing socket bug or something


# 1.17 09-Apr-1997 kstailey

add NAT startup


# 1.16 07-Apr-1997 rees

flush all old routes before adding new interfaces or routes.
ref: netbsd pr3228/misc, Matthias Scheler


# 1.15 03-Mar-1997 downsj

fix typo


# 1.14 11-Feb-1997 deraadt

add default route before fiddling with loopback route to avoid DNS problems; m4@umn.edu, #97


# 1.13 03-Feb-1997 deraadt

do ifaliases after /usr/bin exists in nfs diskless env; pr#77, matthieu@laas.fr


# 1.12 02-Nov-1996 deraadt

timed off by default


Revision tags: OPENBSD_2_0_BASE
# 1.11 23-Sep-1996 deraadt

rfc1323 variable


# 1.10 04-Sep-1996 deraadt

control portmap, inetd, and lpd from netstart; idea from tqbf@enteract.com


# 1.9 27-Aug-1996 deraadt

224.0.0.0 not 0.0.0.224; from peter@demon.net


# 1.8 18-Jun-1996 deraadt

move std stuff from rc.local to rc


# 1.7 16-Jun-1996 deraadt

install sample commented /etc/ifaliases file; which can now contain #
comments and blank lines. new format is "interface address netmask"
(yes, i changed the order of the entries). inspired by netbsd pr#2474;
gillhaa@ghost.whirlpool.com


# 1.6 02-Jun-1996 tholo

Install a multicast route by default


# 1.5 26-May-1996 deraadt

sync & label


# 1.4 09-Jan-1996 dm

added IP filter to netstat/rc and put examples in /usr/share/ipf


# 1.3 30-Dec-1995 deraadt

from netbsd: start mrouted like routed


# 1.2 18-Dec-1995 deraadt

/etc/ifaliases support by randy@zyzzyva.com


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.229 05-Nov-2022 kn

"need root privileges" is an error, print it on stderr"


# 1.228 05-Nov-2022 kn

Print full path in usage; OK jmc


# 1.227 01-Nov-2022 kn

Only load the SOII key if IPv6 is available

Possible now that IP6KERNERL is hoisted.
This also improves readability and zaps double negation logic.


# 1.226 01-Nov-2022 kn

Do not wait for DAD completion in dry-run mode

1. only do so when running without -n
2. move code to own wait_dad() helper like wait_autoconf_default() has it
3. use local _count as usual in both functions rather than the global count

Feedback OK claudio


# 1.225 31-Oct-2022 kn

Hoist only the feature check

Keep adding IPv6 routes after lo0 got an addres like before, meant to be
committed together with r1.223.


# 1.224 31-Oct-2022 kn

Fix comment: IPv6 link local addresses do not use SOII anymore

sys/netinet6/in6_ifattach.c r1.114 limited it to SLAAC addresses in 2019.


# 1.223 31-Oct-2022 kn

Improve shell style wrt. variable naming/boolean convention

The mixed use of upper and lower case variables is neither obvious nor
consistent.

PRINT_ONLY is local to netstart.
ip6kernel is local to netstart.
multicast gets sourced from rc.subr(8).

1. uppercase ip6kernel as is common for global variables in base scripts
2. use the simpler true/false idiom and default with the rest of
netstart-only variables, making it clearer that only `multicast=YES/NO'
comes from the rc environment
3. hoist kernel feature detection such that a later diff can load the SOII
key conditionally
4. zap obvious comment

OK aja


# 1.222 24-Oct-2022 kn

do not wait for autoconf in dry-run

If there is no default route but some interface has AUTOCONF, printing
what would be done still waits for... nothing to happen.

OK tb


# 1.221 24-Oct-2022 kn

Add required sh(1) to synopsis

Contrary to other scripts in base like rc.d(8) or MAKEDEV(8), netstart(8)
itself is not executable and must be passed as file to sh(1):
$ man -h netstart
/etc/netstart [-n] [interface ...]
$ /etc/netstart
ksh: /etc/netstart: cannot execute - Permission denied

Fix usage and synopsis to provide required usage:
$ man -h netsart
sh /etc/netstart [-n] [interface ...]

OK jmc


# 1.220 21-Oct-2022 kn

Fix synopsis, -n does not require an interface; OK jmc


Revision tags: OPENBSD_7_2_BASE
# 1.219 03-Jul-2022 kn

Create virtual interfaces upfront if specified on the command line

In cases like `sh /etc/netstart pair1 pair2', one of hostname.pair{1,2}
will contain a "patch pair{2,1}" command which expects the other interface
to exist.

If none exist, this would fail and netstart had to be run separately or
"patch"ed interface had to be manually created before.

There are other use cases where interfaces depend on each other, so before
(re)configuring an explicit list of interfaces, create all virtual ones
upfront so that a single netstart invocation will configure everything
correctly without having reflect dependencies in multiple ordered netstart
invocations.

Copy isin() from install.sub to help.

Feedback OK halex


# 1.218 26-Jun-2022 florian

Wait for autoconf interfaces to come up in netstart(8) instead of
rc(8). This makes tunnel interfaces work that depend on working
autoconf interfaces.
OK deraadt


Revision tags: OPENBSD_7_1_BASE
# 1.217 22-Feb-2022 dlg

add some more tunnels to the list of interfaces that rely on routing.


Revision tags: OPENBSD_7_0_BASE
# 1.216 02-Sep-2021 bluhm

Do not create loopback interfaces lo1, lo2, ... upfront. They are
automatically set up by the kernel when a routing domain is created.
An existing lo1 in rdomain 0 would prevent to add any interfaces
in rdomain 1.
OK kn@


# 1.215 30-Aug-2021 bluhm

Improve dubgging in /etc/netstart. Enable print only in ifcreate.
Add debugging output for ipv6 routes. Make localhost and multicast
code aware of the print only switch. Allow netstart -n to work
also if no interface is given.
OK kn@


# 1.214 06-Aug-2021 sthen

As tim@ spotted, a use of V4_AUTOCONF crept in when the variable name
was actually V4_DHCPCONF from previous use. Rename all of the V4_DHCPCONF
to V4_AUTOCONF so everything uses the new name. ok and reminder about
the installer from tb@


# 1.213 16-Jul-2021 florian

switch to dhcpleased/resolvd in base
OK deraadt


# 1.212 20-Jun-2021 florian

Don't try to install a default route with route(8) later on if we are
using inet autoconf, like we do with "dhcp" and "inet6 autoconf".
OK kn


Revision tags: OPENBSD_6_9_BASE
# 1.211 23-Dec-2020 krw

Allow the provision of dhclient(8) options on 'dhcp' lines in hostname.if(5)
files.

Usual man page help & ok jmc@


# 1.210 21-Dec-2020 krw

Avoid issuing pointless 'ifconfig <if> up' when processing 'dhcp' in
hostname.if files. dhclient(8) does that itself. Part of the
"further script optimizations" promised in r1.200 of netstart.

Tested & ok gnezdo@


# 1.209 29-Nov-2020 tb

Fix previous: use correct version of netstart and installer bits.


# 1.208 29-Nov-2020 deraadt

Add support for !command to mygate, so that netstart has a late opportunity
to perform network configuration (for example, "!route source -ifp em0")
Split mygate and myname manual pages (how did anyone ever believe these
are related), and perform hostname configuration much earlier in rc.
discussed with benno, claudio, jmc, etc etc, last version of !command
parser by tb


# 1.207 08-Nov-2020 jmc

no more mobileip;
ok claudio deraadt


Revision tags: OPENBSD_6_8_BASE
# 1.206 21-Jun-2020 dlg

start wg with the other interfaces that rely on routing being up.

from Matt Dunwoodie and Jason A. Donenfeld

ok deraadt@


# 1.205 22-May-2020 kn

Revert the following commit as it breaks hostname.if(5) lines with a
backslash at the end for line continuation

Breaking long lines into multiple ones must still be possible and does
require to treat the backslash as an escape character.

Breakage reported by Mark Patruck <mark at wrapped dot cx >, thanks!

---
distrib/miniroot/install.sub revision 1.1151
etc/netstart revision 1.203
date: 2020/05/21 11:54:41; author: kn; state: Exp; lines: +2 -2;
Do not treat backslashe as an escape character in hostname.if(5) lines

ifstart() should always pass such lines unaltered, especially if they
contain "nwid" or "description" lines with arbitrary strings.

<bsdlisten at gmail dot com> reported SSIDs such as "Mike's" during
installation end as broken; this was because the installer escaped
the single quote using backslashes which ended up being treated as
escape characters much later during hostname.if parsing in netstart(8).

Ok deraadt


# 1.204 21-May-2020 kn

Fix stripcom() description wrt. comments not on their own line

Neither netstart's nor install.sub's (subtly different) implementations
remove trailing comments on lines not starting as a comment, e.g.,
lines like "up #not down" go through unaltered and without "#not down"
being removed.

Only lines *beginning* with the comment sign ("#") are stripped.

No functional change, just updating function descriptions.


# 1.203 21-May-2020 kn

Do not treat backslashe as an escape character in hostname.if(5) lines

ifstart() should always pass such lines unaltered, especially if they
contain "nwid" or "description" lines with arbitrary strings.

<bsdlisten at gmail dot com> reported SSIDs such as "Mike's" during
installation end as broken; this was because the installer escaped
the single quote using backslashes which ended up being treated as
escape characters much later during hostname.if parsing in netstart(8).

Ok deraadt


Revision tags: OPENBSD_6_7_BASE
# 1.202 15-Jan-2020 kn

Do not redirect already quiet stdout for IPv6 reject routes

"route -q" already silences all standard output; if it still prints
something, that's a bug to fix in route.

OK bluhm


# 1.201 25-Oct-2019 dlg

handle aggr(4) in the same way as trunk(4)

from brad@
ok bluhm@ claudio@ deraadt@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.200 29-Aug-2018 krw

Historically /etc/netstart (and the equivalent code in the install
script) did 'ifconfig <if> down' before starting dhclient(8). This was
a way of ensuring old running copies of dhclient were killed before a
new one started. Current dhclient does not need this assist, so change
"ifconfig <if> down" to "ifconfig <if> up" pending further script
optimizations.

Similar to a 2014 attempt by halex@. Prompted by a misc@ report
from Kristjan Komlosi reporting hanging diskless setups.

ok halex@ kn@


# 1.199 08-Jul-2018 tb

netstart is used during system start, but also interactively.
Show proper error message if a regular user executes netstart.
Only do the privilege check if the id binary is available,
which might not be the case during diskless system startup.

ok deraadt, jasper, jca, krw, rpe (who wrote the same diff), sthen


# 1.198 28-Apr-2018 rpe

Add a proper usage() function.

Suggested by and OK jmc.
OK tb


Revision tags: OPENBSD_6_3_BASE
# 1.197 04-Mar-2018 jmc

when -n is used, no need to spit out "Missing parameters." before
displaying usage();

ok tb


# 1.196 03-Mar-2018 landry

Lowercase 'usage' and group -n with interface in it.
From jmc@, ok tb@


# 1.195 21-Feb-2018 rpe

Tweak comments.

OK tb


# 1.194 19-Feb-2018 rpe

Write warning/error messages to stderr and end them with a fullstop.

OK tb


# 1.193 19-Feb-2018 rpe

- use specific patterns when looping over /etc/hostname.if files
to skip backup or temp files.
- test if the patterns matched actual files
- warn if ifcreate() fails on an interface and continue with the
subsequent interfaces in the list instead of return'ing

OK dlg sthen tb


# 1.192 17-Feb-2018 rpe

- Add descriptions for the new functions ifcreate() and vifscreate()
- In ifcreate() use the exit code of the {} block directly
- In vifscreate(), use the ifconfig -C output directly in the for _vif loop
- Remove superfluous and somewhat confusing comment

OK dlg kn sthen


# 1.191 14-Feb-2018 dlg

create virtual interfaces before starting all interface config.

this resolves an ordering problem when adding pseudo interfaces to bridges

tweaks from kn@
ok mpi@ sthen@


# 1.190 10-Feb-2018 claudio

Remove some special IPv4 in IPv6 mapped prefixes that are already rejected
by the ::0.0.0.0/96 reject route added to deny all IPv4 mapped addresses.
Makes the inet6 routing table almost fit in one screen.
OK benno@


# 1.189 10-Feb-2018 florian

Load RFC 7217 key material and generate if it does not already exist.

Add soii.key to changelist (pointed out by semarie) and mtree/special
(suggest by Craig Skinner).

OK naddy, sthen, rpe, tb


# 1.188 06-Feb-2018 tb

If -n is given, the netstart script should not (try to) set the default
route(s). Simply print the command(s) to be issued instead.

tweak & ok rpe


# 1.187 12-Nov-2017 tb

Remove HN_DIR variable and expand it in the only place it was used. It
currently serves no purpose.

ok rpe, agreement from deraadt and halex


Revision tags: OPENBSD_6_2_BASE
# 1.186 25-Jul-2017 rpe

Finally remove backwards compat code to support the 'rtsol' keyword
in hostname.if(5)

OK mpi@ deraadt@ florian@
OK jmc@ from doc perspective


# 1.185 21-Jul-2017 rpe

Align ifstart() in netstart and install.sub.

- in netstart, rename _file to _hn referencing hostname.if files
- in install.sub switch ifstart() to be used with _if instead of
_hn as parameter

ok krw@ tb@


# 1.184 28-May-2017 awolk

etc/netstart: use colon separator instead of dot with chown

OK jung@, deraadt@, jmc@


# 1.183 07-May-2017 rpe

Change test from [] to [[]] and simplify pattern.

OK tb@, krw@ (for [[]])
Feedback and OK halex@


# 1.182 07-May-2017 rpe

Replace hardcoded script name with ${0##*/}

OK tb@ halex@


# 1.181 01-May-2017 rpe

Revert r1.170 and remove the id==0 check.
The id binary is not available in nfs diskless setups at this point.

reported by Andreas Kusalananda, thanks.
discussed with deraadt@


# 1.180 01-May-2017 rpe

Remove last remnants of rtsol. IPv6 autoconfiguration of interfaces is now
done in ifstart(). Remove ipv6autoconf() and replace rtsolif with a boolean
variable V6_AUTOCONF. Replace dhcpif with a boolean variable V4_DHCPCONF.
Both are later used in defaultroute() to decide whether or not to configre
defaultroutes from /etc/mygate.

OK krw@


# 1.179 30-Apr-2017 mpi

Do not try to delete a default route before adding it.

Now that route are automatically G/C with the address they are attached
to there's no reason to duplicate the kernel's job.

Fix a regression introduced with multipath default routes.

ok deraadt@


# 1.178 25-Apr-2017 rpe

Unbreak netstart for multiple inteface configurations like trunk
or carp. Ensure that the noglob option is disabled at the end of
parse_hn_line() and ifstart().

Reported by Christer Solskogen and Stefan Wollny, thanks!


# 1.177 24-Apr-2017 rpe

Introduce a new function parse_hn_line() that replaces the existing
hostname.if(5) parsing code in ifstart().
Add a -n option to netstart to only print the interface configuration
commands instead of executing them.
Add a HN_DIR variable, that points to the directory of the hostname.if
files (default /etc) that allows for future regression tests.

- add new parse_hn_line() function
- change ifstart()
- rename $if to $_if
- don't ifconfig or ifconfig create if -n option is used
- replace hostname.if(5) parsing code with new parse_hn_line()
- just print configuration commands if -n option is used
- autoconf now happens in ifstart(), remove ifv6autoconf()
- introduce HN_DIR variable for the hostname.if file location
- add handling of the -n option to only print config commands
- ensure -n is only used if interfaces are specified as parameters

Discussed with and positive feedback from many
'commit' deraadt@
OK sthen@


# 1.176 08-Apr-2017 rpe

- localize the if, file and stat variables which also ensures that
variables are not named like commands.
- change test from [] to [[]]

OK tb@ halex@


# 1.175 07-Apr-2017 rpe

Minimize differences in ifstart() function between netstart and
install.sub which makes it easier to spot changes in the future.

- comments and formatting
- quotes on assignments are not needed (netstart)
- remove stray space in test (netstart)
- use $file variable with while-loop (netstart)
- although valid, instead of i use $i in arithmetic test (install.sub)

OK krw@, tb@
Looks good deraadt@


# 1.174 07-Apr-2017 rpe

Align comments of ifstart() function in netstart and install.sub.


# 1.173 07-Apr-2017 rpe

Align comments of stripcom() function in netstart and install.sub.


Revision tags: OPENBSD_6_1_BASE
# 1.172 06-Dec-2016 mpi

Do not lose the default route when netstart(8) is run a second time on
the interface pointed to by the default route.

Since the kernel no longer keep routes with dangling address pointer,
netstart(8) has to re-add the default route when the corresponding ifa
has been deleted and re-created.

deraadt@ points out that even if the previous semantic was not necessarily
better, a script like netstart(8) cannot totally fix the default route
problem.

Regression reported by and fix tested by Hrvoje Popovski.

ksh foo checked by halex@


# 1.171 27-Sep-2016 rzalamena

Delay switch(4) interface start up so it can attach virtual interfaces
like vether(4).

nits from and ok benno@, phessler@


# 1.170 09-Sep-2016 jasper

print a clear error message when not ran as root instead of just falling
through and try whatever it can do with the invoking user's perms

feedback/ok aja@ rpe@


Revision tags: OPENBSD_6_0_BASE
# 1.169 19-Jul-2016 mpi

Do not consider tap(4) a special interface and start if before other
pseudo-interfaces.

This unbreak vlan(4) on top of tap(4) since the refactoring to turn it
MP-safe.

ok claudio@, deraadt@


# 1.168 27-Mar-2016 sthen

Don't delete the 224/4 route in netstart, unless it's being done to ensure that
a -reject route can be added. Restores the ability to set an interface route
before daemons are started, lost during the previous simplification.
ok millert mpi


Revision tags: OPENBSD_5_9_BASE
# 1.167 29-Dec-2015 rpe

Remove backslash, not necessary after '&&'

OK halex@


# 1.166 29-Dec-2015 rpe

Replace last remaining `` with $()

OK halex@


# 1.165 18-Dec-2015 ajacoutot

Drop the now useless multicast setup comment.

prodded by tim@, ok mpi@


# 1.164 17-Dec-2015 ajacoutot

Simplify multicast option handling (10 less lines) by matching /etc/rc behavior
towards other YES|NO options and drop the error warning.


with and ok tim@, ok rpe@ on an earlier diff


# 1.163 05-Dec-2015 mpi

It does not make sense to insert a specific route for 224/4 when the
default one is good enough.

So merge rc.conf(8)'s 'multicast_router' and 'multicast_host' into a
single 'multicast'. If set to YES the reject route for 224/4 is not
inserted by netstart(8).

Manual bits from jmc@

ok henning@, ajacoutot@


# 1.162 12-Nov-2015 rpe

Changes to ifautostart():
- Rename function to ifv6autoconf() to make IPv6 relation clearer
- Localize and rename variables

OK krw@


# 1.161 12-Nov-2015 rpe

Changes to ifmstart():
- Change comments to make it clearer that ifmstart() takes two lists
of interface driver names (of which the second is optional) and not
the actual interface instances.
- Use localized variables and use slightly more verbose names.
- Use continue 2 to skip to the next hostname.if file.
- Use shell pattern @() instead of testing _sif individually.

OK krw@


# 1.160 12-Nov-2015 rpe

Changes to stripcom():
- Align comments with /etc/rc version
- Use localized variables
- Use safer "print -r --" instead of plain echo

Changes to ifstart():
- Tweak comment
- Add usage

OK krw@


# 1.159 01-Nov-2015 rpe

Start the rework of the /etc/netstart shell script.

General changes:
- apply a similar 'style' as used in the installer scripts
- improve comments to be more to the point, remove where code is obvious
- document usage of functions if they have arguments
- rename variables where it improves readability
- replace really old-school shell code with more contemporary idioms

Other changes:
- No need to care about "autoboot" because netstart doesn't inherit the
positional parameters from /etc/rc anymore. /etc/rc executes netstart
instead of sourcing it since r1.439.
- Use simpler for-loop to process list of interfaces with ifstart.

OK halex@


# 1.158 26-Oct-2015 rpe

The hostname variable is not used since r1.99. Remove it and use
stripcom() output directly with the hostname command.

OK deraadt@ krw@


# 1.157 23-Oct-2015 claudio

netstart bits for tap(4)


# 1.156 27-Sep-2015 sthen

Don't print output when setting autoconf on interfaces. Suggested by deraadt,
ok florian@ rpe@


# 1.155 13-Sep-2015 sthen

only print the "IPv6 autoconf" line if there are interfaces to configure
feedback/ok rpe


# 1.154 11-Sep-2015 sthen

Set "inet6 autoconf" individually on interfaces that have rtsol set in
hostname.if, previously netstart tried to configure them all at once
("ifconfig if0 if1 if2 inet6 autoconf"). From Delan Azabani, ok phessler@


Revision tags: OPENBSD_5_8_BASE
# 1.153 20-Jul-2015 rpe

Disable Strict Bourne shell mode for /etc/rc and /etc/netstart to be
able to use ksh syntax within these scripts. This way init doesn't
need to be changed, which starts /etc/rc using /bin/sh and people
can still use "sh /etc/netstart ifname".

Idea from and OK halex@
OK deraadt@ krw@ guenther@


# 1.152 19-Jul-2015 florian

Bring up pflow last as it might send with a source address that is on
any of the other interfaces.
OK deraadt, phessler, benno


# 1.151 19-Jul-2015 rpe

Always source rc.subr to be able to use the rc.conf parsing routine
to get the network related vars from rc.conf. This is even necessary
if netstart is run from within /etc/rc. Remove test of $INRC which
unintentionally evaluated always to true.

problem with previous change found by nigel@
OK sthen@ aja@ halex@


# 1.150 19-Jul-2015 ajacoutot

Revert 1.148 for now until I can talk to rpe@
It introduced a regression reported by nigel@


# 1.149 19-Jul-2015 rpe

Replace test command with [].

OK halex@ krw@


# 1.148 19-Jul-2015 rpe

Ensure, that we source rc.subr and parse rc.conf ONLY if we are not
inside /etc/rc.

With help from and OK halex@, ajacoutot@


# 1.147 18-Jul-2015 rpe

- remove trailing blanks introduced in previous commit
- no space in redirections like </foo or >$bar
- few other minor whitespaces

OK krw@


# 1.146 18-Jul-2015 rpe

Improve comments
- Add comments for functions
- Start comments with capital letters
- End comments with a full stop
- Allow comments to extend up to column 80

OK krw@


# 1.145 06-Jun-2015 florian

Allow rtsol keyword in hostname.if(5) with net.inet6.ip6.forwarding=1.
"inet6 autoconf" was working before and rtsol should behave the same.
OK phessler


Revision tags: OPENBSD_5_7_BASE
# 1.144 03-Dec-2014 florian

The kernel handles rtsol(8) functionality since some time now.
Treat rtsol in hostname.if as a keyword like dhcp and call ifconfig
inet6 autoconf.
"reads good" todd@
OK krw@ (who is *not* an IPv6 person), but I recruited him in his
capacity as an installer person.


# 1.143 28-Sep-2014 claudio

Revert 1.142. Without the down netstart will just print the ifconfig
output because it may end up just calling 'ifconfig $if'. This needs
to be done better and properly tested.


# 1.142 26-Sep-2014 halex

remove explicit 'down' of an interface before starting a dhcp request, thereby
avoiding annoying delays for some switch configurations

ok claudio@ deraadt@

i would add ok phessler@, but it was not valid without an ok krw@


Revision tags: OPENBSD_5_6_BASE
# 1.141 12-Jul-2014 stsp

Fix netstart after autoconf6 change so 'rtsol' lines in hostname.if work again.
found by pelikan@; ok pelikan@ henning@


# 1.140 12-Jul-2014 robert

Make rc.conf a parsed configuration file and stop sourcing it as a shell
script.
From now on rc.conf has a fixed syntax (key=val) and it is not allowed
to add anything to it besides the supported syntax, it all going to be
ignored.

discussed with and help from deraadt@ and halex@


Revision tags: OPENBSD_5_5_BASE
# 1.139 22-Aug-2013 mpi

Like for dhclient, do no create a route to alias addresses via 127.0.0.1.
Our stack is able to tell if the address is local or not.

ok todd@, krw@


Revision tags: OPENBSD_5_4_BASE
# 1.138 20-Mar-2013 todd

fix lies in netstart; replacement wording from halex@
pointed out by Ryan Kavannagh rak at debian dot org


Revision tags: OPENBSD_5_3_BASE
# 1.137 05-Dec-2012 rpe

remove "Invalid interface name" message
requested by krw@

ok halex@


# 1.136 02-Dec-2012 rpe

use the more compact version of the check for ifconfig'able interfaces
from install.sub

with feedback from and ok halex


# 1.135 02-Dec-2012 rpe

- remove isalphanumeric() and replace it with a shell pattern, that
tries a bit harder to identify invalid interface names and in
this case emit an error message.
- use [[ $1 == autoboot ]] to avoid a shell error message due to
possible spaces in first argument
- no change in functionality

discussed with krw and halex
ok ("I like this") krw


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.134 07-Oct-2011 deraadt

The new ypbind changes requires that the domainname be set before
rc.conf is run. There's no real downside.
ok aja


Revision tags: OPENBSD_5_0_BASE
# 1.133 07-Jul-2011 guenther

Eliminate some $? tests by rolling the command into the condition

ok halex@


# 1.132 26-May-2011 mpf

Add svlan(4) startup bits.
From markus@. OK naddy, claudio, reyk.


Revision tags: OPENBSD_4_9_BASE
# 1.131 09-Feb-2011 sobrado

fix an unbalanced parenthesis in a comment; while here, split the comment
in a better place to make it more readable.

ok jmc@ and miod@


Revision tags: OPENBSD_4_8_BASE
# 1.130 16-Jun-2010 todd

permit e.g. -inet6 syntax by slurping all lines not just some
noticed by rhsv6 at hushmail dot com, ok sthen@


Revision tags: OPENBSD_4_7_BASE
# 1.129 12-Jan-2010 henning

when setting up lo0 use 127.0.0.1/8 instead of 127.0.0.1 for clarity and
correctness. it's not 1992 any more, kids. ok mcbride dlg krw


# 1.128 10-Dec-2009 todd

o stop reordering ifconfig arguments (e.g. after 'up ..')
o only stop processing if inet or inet6 lines are malformed
o everything not a specially handled bit is passed to ifconfig unmangled
noticed by several after the move from bridgename.bridge0 -> hostname.bridge0
prodded by deraadt@, tested by and feedback from several
man page bits 'look fine' jmc@


# 1.127 22-Nov-2009 deraadt

Stop supporting bridgename.bridge* files, and move to hostname.bridge*
files. To cope with this change, read about the mv command.
ok claudio todd


# 1.126 17-Sep-2009 simon

change variable i to $i in an expression of ifstart() for consistency
with the rest of the file. no functional change.

feedback from sthen@, ok krw@


# 1.125 10-Jul-2009 jdixon

Delay creation of tun(4) interfaces until the underlying interface and
routes are available. This fixes usage for some OpenVPN users that start
it from hostname.tun*.

Tested by Johan Huldtgren. ok sthen@, johan@.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.124 25-Nov-2008 markus

delay /etc/netstart until IPv6-DAD (dup-address-detection) is completed.
ok fries, hshoexer, claudio


# 1.123 14-Aug-2008 sthen

Tools from /usr may not be used in netstart since it may be NFS-mounted
and not available at that time. Rewrite the hostname.if permission check
to use only /bin/ls and the shell. Requested by deraadt.

ok todd, "Twisted." deraadt


Revision tags: OPENBSD_4_4_BASE
# 1.122 23-Jul-2008 sthen

Prevent warning about insecure hostnames where no /etc/hostname.*
exists. From wcmaier@.

Check target of symbolic links to avoid noise at boot and in
seucrity output where you have several interfaces symlinked to one
config file.

"If you think this is the right thing to do" deraadt@


# 1.121 09-Jun-2008 todd

warn once not 3 times in case of a non existent file, discussed with deraadt
originally pointed out by Johan Torin


# 1.120 09-Jun-2008 deraadt

Ensure that hostname.* files are also re-chowned to root.wheel at each
boot as discussed with claudio while eating tasty donairs. ok todd


# 1.119 17-Apr-2008 deraadt

before using them, force hostname.* files to be unreadable by world
first version from todd, ok millert


Revision tags: OPENBSD_4_3_BASE
# 1.118 17-Jan-2008 brad

Execute rtsol after turning up trunk(4) and vlan(4) interfaces so they're
taken into consideration for rtsol.

ok reyk@ dlg@


# 1.117 09-Jan-2008 mpf

Do not bring up pfsync(4) before the working ruleset
has been loaded. Otherwise, states that are received during the
initial bulk update mismatch the correct pf-checksum and
do not attach to the rules.
Problem identified by david@. Fix done in collaboration.
OK henning@


Revision tags: OPENBSD_4_2_BASE
# 1.116 02-Aug-2007 david

move the delay for IPv6 DAD to after all interfaces have started
fixes problems with daemons being unable to bind to all addreses at boot
ok itojun@ hshoexer@


Revision tags: OPENBSD_4_1_BASE
# 1.115 15-Nov-2006 itojun

reject multicast packet without scope identifier specified.


Revision tags: OPENBSD_4_0_BASE
# 1.114 29-Jun-2006 todd

do not add an extra space; nwid and description come out wrong
fix as proposed by maja@, thanks!


Revision tags: OPENBSD_3_9_BASE
# 1.113 28-Dec-2005 david

nuke extra whitespace


# 1.112 06-Dec-2005 reyk

multicast_host=YES only works if a valid default gateway is available.
validate this condition and reject multicast traffic on failure.

ok todd@ naddy@


# 1.111 02-Nov-2005 todd

fix inspired by pr#4590
ok krw@


# 1.110 25-Oct-2005 todd

better logic from krw@:
- do not process mygate for v4 if dhcp
- do not process mygate for v6 if rtsol
this also makes the mygate processing logic more readable
ok krw@


# 1.109 14-Oct-2005 todd

add v6 support for /etc/mygate
ok deraadt@ mickey@ krw@
same functionality tested/ok'ed by by mickey, brad, matthieu, and me
with this one may now put a v6 IP in /etc/mygate on a separate line from
the v4 default gateway and netstart will do the right thing


# 1.108 12-Oct-2005 todd

shrink stripcom(), sync with install.sub
ok krw@


# 1.107 04-Oct-2005 todd

trunk must be started after physical ethernet devices, but before vlan.
populate ifmstart lines accordingly.
prodded/tested by brad@
ok reyk@


# 1.106 28-Sep-2005 todd

use eval consistently, fixes description quotes on rtsol and dhcp
fix inspired by and closes pr 4495
ok krw@


Revision tags: OPENBSD_3_8_BASE
# 1.105 22-May-2005 todd

Introduce 'ifmstart' to deal with starting multiple interfaces minus a list
of interfaces.

This reduces the netstart script by 174 chars, 13 words, and 19 lines, but
more importantly, makes it more simple and less cluttered should more special
case/orderings be needed.

ok brad@ and pr 4197 submitter, inspired by and closes pr 4197


# 1.104 04-Apr-2005 djm

unbreak; ok pval@


# 1.103 03-Apr-2005 deraadt

if dhcp is used to get an address on any interface, ignore /etc/mygate
ok krw
(this lets us do something rather cool with the zaurus in particular)


Revision tags: OPENBSD_3_7_BASE
# 1.102 04-Jan-2005 mcbride

Bring up the carp(4) interface before default route.

ok pascoe@ mpf@


# 1.101 30-Dec-2004 millert

Add a copy of stripcom so /etc/netstart can be run standalone again.
OK deraadt@


# 1.100 19-Dec-2004 millert

Allow comments in /etc/{myname,mygate,defaultdomain}; OK deraadt@


# 1.99 04-Dec-2004 itojun

remove "route $hostname 127.0.0.1" line. deraadt ok
*** please update /etc/netstart and test if it works ok for you ***


# 1.98 20-Oct-2004 deraadt

make all route commands use -qn; ok mcbride henning


Revision tags: OPENBSD_3_6_BASE
# 1.97 29-May-2004 deraadt

one last route command lacking -qn


Revision tags: OPENBSD_3_5_BASE
# 1.96 22-Mar-2004 mcbride

Make sure pfsync is brought up before carp.

ok deraadt@


# 1.95 13-Mar-2004 mcbride

Delay pfsync(4) configuration, as the syncif has to be configured in
advance. From Thorsten Lockert.


# 1.94 14-Jan-2004 deraadt

ok, it took quite a bit of prodding but itojun finally explained why the
extra sleep 1 is in here, and we came to the conclusion it is safe to
delete it. whee.


# 1.93 13-Jan-2004 deraadt

repair v6 lo0 documentation


# 1.92 11-Jan-2004 deraadt

add loopback routes late


# 1.91 09-Jan-2004 deraadt

create all routes with -q; markus ok


# 1.90 04-Dec-2003 millert

Need to do "ifconfig create" for bridge interfaces too.


# 1.89 03-Dec-2003 markus

add support for ifconfig clone; from netbsd; ok deraadt, henning


# 1.88 20-Oct-2003 david

delay carp initialization until after physical interfaces are configured
ok mcbride@ henning@ deraadt@ todd@


Revision tags: OPENBSD_3_4_BASE
# 1.87 27-Aug-2003 henning

only try to set hostname to what /etc/myname says if that file actually exists,
otherwise preserve `hostname`
netbooted machines can live perfectly fine without it; they get their hostname
earlier.

ok krw@ cedric@


Revision tags: OPENBSD_3_3_BASE
# 1.86 16-Feb-2003 krw

Fix up some DNS verbiage to make it consistant.

Fix up default route selection by

a) Forcing user to explicitly chose 'dhcp' as a mechanism for
specifying a default route, rather than guessing based on one or more
interfaces being configured by dhcp.

b) If the user specified default route does not work, re-present the
existing default route rather than losing it.

c) Move default route selection to after nameserver activation so the
user can specify a hostname as the default route.

Change /etc/netstart so that /etc/mygate wins if a default route was
already specified (i.e. by dhcp).

ok deraadt@.


Revision tags: OPENBSD_3_2_BASE
# 1.85 16-May-2002 todd

ignore non-existent cases where '$if' evaluates to '*'.
From Andr� Lucas <andre@ae-35.com>, fixes pr # 2658.
'Looks good' from miod@, millert@, and krw@.


Revision tags: OPENBSD_3_1_BASE
# 1.84 23-Feb-2002 deraadt

re-add support for $if expansion; hamajima@nagoya.ydc.co.jp


# 1.83 21-Feb-2002 miod

Change the network components initialization order.
Change from:
o all interfaces
o all bridges
o routes
to:
o physical interfaces
o routes
o gif and gre interfaces
o bridges

Fixeski PR #2400.
Manual page updates coming soon.
Ok angelos@ chris@ deraadt@


Revision tags: OPENBSD_3_0_BASE
# 1.82 31-Jul-2001 hugh

a space before a redirect


# 1.81 06-Jul-2001 angelos

Also, source /etc/rc.conf so we can pull in the
multicast_host/multicast_router settings; this is useful if one
flushes the routing table and re-initializes.

We really need a netconfig tool of sorts.


# 1.80 06-Jul-2001 angelos

Use "route -n show -inet" to determine the default multicast iface.


# 1.79 03-Jul-2001 deraadt

pull in rc.conf early so that pf(1) startup is right; tested by jasoni, comments from millert


# 1.78 30-May-2001 deraadt

Remove ipf. Darren Reed has interpreted his (old, new, whichever)
licence in a way that makes ipf not free according to the rules we
established over 5 years ago, at www.openbsd.org/goals.html (and those
same basic rules govern the other *BSD projects too). Specifically,
Darren says that modified versions are not permitted. But software
which OpenBSD uses and redistributes must be free to all (be they
people or companies), for any purpose they wish to use it, including
modification, use, peeing on, or even integration into baby mulching
machines or atomic bombs to be dropped on Australia. Furthermore, we
know of a number of companies using ipf with modification like us, who
are now in the same situation, and we hope that some of them will work
with us to fill this gap that now exists in OpenBSD (temporarily, we
hope).


Revision tags: OPENBSD_2_9_BASE
# 1.77 13-Mar-2001 deraadt

spelling; maurice@maurice.wan.nl


# 1.76 06-Feb-2001 todd

ignore blank lines in addition to comments
fixes pr#1660 from wilfried@telia.com .. Thanks!


# 1.75 10-Jan-2001 jason

support !command in bridgename.if files, too


# 1.74 27-Nov-2000 millert

Use -n to test if a variable is non-zero. Otherwise, if the variable's
contents start with a '-' test becomes unhappy (since it interprets it
as another option).


# 1.73 08-Nov-2000 todd

This fixes pr 1481, we now handle args > 6 in /etc/hostname.if in the
cases where we did not previously handle them.
Thanks to Scott Atwood <atwood@cs.stanford.edu> for reminding us of this.


Revision tags: OPENBSD_2_8_BASE
# 1.72 02-Sep-2000 todd

subtle bug .. global variables in a while loop need reset 'just incase'
With:
hostname.fxp0 having a last line of:
inet6 alias 3ffe:...
and hostname.gif0 having a first two lines of:
giftunnel 1.2.3.4
dest 1.2.4.3
We end up with the command:
ifconfig gif0 giftunnel alias 1.2.3.4 1.2.4.3
.. which is clearly wrong and fixed by this change


# 1.71 18-Jun-2000 todd

rc.conf now parses ${local_rcconf} internally; closes pr 1259


Revision tags: OPENBSD_2_7_BASE
# 1.70 08-May-2000 todd

fix dhcp 'NONE' ness from install to allow media parsing to work
.. ok deraadt@, millert@


# 1.69 21-Apr-2000 deraadt

rc.conf.local support, inspired by chuck yerkes


# 1.68 04-Apr-2000 millert

Remove the -E flag from ipf as it is implicitly enabled and using
the -E flag here causes the kernel to printf 'IP Filter: already
initialized'.


# 1.67 18-Mar-2000 deraadt

silence all extra route addition printouts


# 1.66 17-Mar-2000 itojun

correct reject route installations for IPv6. improve comments.


# 1.65 12-Mar-2000 itojun

disallow packets to malicious 6to4 prefix, based on
http://playground.iijlab.net/i-d/draft-itojun-ipv6-transition-abuse-00.txt


# 1.64 10-Mar-2000 todd

fix non behavior
with this `!' lines in /etc/hostname.* run even without certain lines
(like a comment) preceeding it.


# 1.63 10-Jan-2000 todd

allow arbitrary commands in /etc/hostname.* files if the line starts with '!'


# 1.62 02-Jan-2000 deraadt

rtsol case can configure the interface up, since it would be nice to finish
DAD before the actual rtsol(8) run happens later. and since it will rtsol,
it is going to be up in any case.


# 1.61 02-Jan-2000 itojun

one more indentation fix.


# 1.60 02-Jan-2000 itojun

indentation fix (todd's part)


# 1.59 02-Jan-2000 todd

fix rtsold case, reset cmd for each iteration!


# 1.58 02-Jan-2000 itojun

allow options after "rtsol".
XXX both "dhcp" and "rtsol" has keyword *down* at the end. is it okay?


# 1.57 02-Jan-2000 itojun

echo "IPv6 autoconf: interfaces" before invoking rtsol.
sleep for net.inet6.ip6.dad_count seconds to ensure that IPv6 DAD is completed.
TODO: rtsold (rc.conf line), manpage


# 1.56 02-Jan-2000 itojun

ipv6 autoconf on hosts (non-routers).

to do this,
1. in sysctl.conf, add these lines:
net.inet6.ip6.forwarding=0
net.inet6.ip6.accept_rtadv=1
2. in hostname.foo, add
rtsol

specifying two or more interfaces with "rtsol" may result in strange
behavior - ipv6 spec does not permit multi-interface node to be autoconfig'ed.


# 1.55 02-Jan-2000 todd

add to hostname.* parsing:
- multiple entries support (read: aliases)
- inet6 support
- support for comments (#)
(look for hostname.if(5) commit for syntax details)


# 1.54 31-Dec-1999 itojun

install IPv6 reject routes only if kernel is capable of IPv6.


# 1.53 09-Dec-1999 itojun

avoid transmitting invalid IPv6 packets out to the wire.


# 1.52 09-Dec-1999 itojun

do not perform IPv6 initialization for loopback interface.
MUST make lo0 up before any IPv6 operations.
it will be considered a pilot error if you don't.
(I prefer to have lo0 initialized automatically)


Revision tags: OPENBSD_2_6_BASE
# 1.51 01-Sep-1999 deraadt

support # characters in bridgename.* files; millert


# 1.50 01-Sep-1999 deraadt

cleanup parsing of hostname.* files, and seperate bridge control into
bridgename.* files; all documented in new hostname.if(5) and
bridgename.if(5) man pages


# 1.49 09-Aug-1999 angelos

Only parse/setup the hostname.foo file if interface foo exists (this
is useful for laptops with different ethernet cards etc.)


Revision tags: OPENBSD_2_5_BASE
# 1.48 29-Mar-1999 niklas

New multicast route setup style


# 1.47 26-Mar-1999 niklas

Add bridge interface handling


# 1.46 01-Mar-1999 millert

Add support in /etc/hostname.xxx for files of the format:
up [options]
Any of the following may or may not be set:
$name $mask $bcaddr $extras


# 1.45 28-Oct-1998 millert

Kill the awful hack used to match and split /etc/hostname.* We now use
a function, isalphanumeric, to determine whether an interface name is
likely to be valid. This means that things like /etc/hostname.le0.bak,
/etc/hostname.le0#, /etc/hostname.le0~, etc. will be ignored as they
should. There is no longer an implicate assumption that /etc/hostname.*
only contains a single '.'.


Revision tags: OPENBSD_2_4_BASE
# 1.44 06-Oct-1998 deraadt

move ipnat to end of netstart, to support dhcp+ipnat


# 1.43 18-Sep-1998 deraadt

apply media directives on dhcp interfaces


# 1.42 10-Sep-1998 marc

better way of handling dhcp client; Jason Ish <jbi130@mail.usask.ca>


# 1.41 08-Sep-1998 marc

dhcp client stuff. "Angelos D. Keromytis" <angelos@dsl.cis.upenn.edu>


# 1.40 24-Aug-1998 downsj

You can't use -interface default when there's no default gateway
set (yet). Use -interface $hostname if mygate doesn't exist so that
this actually works on routers.


# 1.39 04-Jul-1998 deraadt

put 224 route on default, to avoid a hostname lookup


# 1.38 22-May-1998 deraadt

use route -n, what the heck


Revision tags: OPENBSD_2_3_BASE
# 1.37 28-Mar-1998 deraadt

s/^nat/ipnat/


# 1.36 23-Feb-1998 niklas

remove trailing blank line


# 1.35 07-Feb-1998 deraadt

ipforward is in sysctl.conf now


# 1.34 21-Dec-1997 deraadt

ugh


# 1.33 20-Dec-1997 deraadt

ipforwarding option in rc.conf


# 1.32 29-Nov-1997 kstailey

NAT requires IPF


# 1.31 04-Nov-1997 deraadt

kill spaces at ends of lines; m4


Revision tags: OPENBSD_2_2_BASE
# 1.30 14-Oct-1997 deraadt

set hostname/domainname before running rc.conf; m4@umn.edu


# 1.29 04-Sep-1997 deraadt

fork netstart; new child is rc.conf


# 1.28 25-Aug-1997 millert

Explicately pass -host flag to route(8) to avoid confusion with networks.


# 1.27 19-Aug-1997 niklas

Add hook for rpc.lockd, make nfsd flags settable in netstart


# 1.26 31-Jul-1997 downsj

Make quotas optional; wedged into netstart for the time being.
/etc/rc.conf, anyone?


# 1.25 30-Jul-1997 deraadt

do not run routed by default


# 1.24 28-Jul-1997 kstailey

Move configuration of loopback interface to before all other interfaces.
Allows the use of local caching-only nameserver with no "nameserver"
entry in /etc/resolv.conf to configure a route between the hostname
and loopback.


# 1.23 25-Jul-1997 provos

earlier start of keymanagement


# 1.22 24-Jul-1997 deraadt

make amd use /tmp_mnt by default


# 1.21 22-Jul-1997 provos

start the photuris daemon per default. hilfe.


# 1.20 17-Jun-1997 niklas

Put in hooks to start ypserv with flags


# 1.19 17-Jun-1997 niklas

Put in hooks to start rpc.yppasswdd with flags


Revision tags: OPENBSD_2_1_BASE
# 1.18 15-Apr-1997 deraadt

kill route flush until .. hmm kernel routing socket bug or something


# 1.17 09-Apr-1997 kstailey

add NAT startup


# 1.16 07-Apr-1997 rees

flush all old routes before adding new interfaces or routes.
ref: netbsd pr3228/misc, Matthias Scheler


# 1.15 03-Mar-1997 downsj

fix typo


# 1.14 11-Feb-1997 deraadt

add default route before fiddling with loopback route to avoid DNS problems; m4@umn.edu, #97


# 1.13 03-Feb-1997 deraadt

do ifaliases after /usr/bin exists in nfs diskless env; pr#77, matthieu@laas.fr


# 1.12 02-Nov-1996 deraadt

timed off by default


Revision tags: OPENBSD_2_0_BASE
# 1.11 23-Sep-1996 deraadt

rfc1323 variable


# 1.10 04-Sep-1996 deraadt

control portmap, inetd, and lpd from netstart; idea from tqbf@enteract.com


# 1.9 27-Aug-1996 deraadt

224.0.0.0 not 0.0.0.224; from peter@demon.net


# 1.8 18-Jun-1996 deraadt

move std stuff from rc.local to rc


# 1.7 16-Jun-1996 deraadt

install sample commented /etc/ifaliases file; which can now contain #
comments and blank lines. new format is "interface address netmask"
(yes, i changed the order of the entries). inspired by netbsd pr#2474;
gillhaa@ghost.whirlpool.com


# 1.6 02-Jun-1996 tholo

Install a multicast route by default


# 1.5 26-May-1996 deraadt

sync & label


# 1.4 09-Jan-1996 dm

added IP filter to netstat/rc and put examples in /usr/share/ipf


# 1.3 30-Dec-1995 deraadt

from netbsd: start mrouted like routed


# 1.2 18-Dec-1995 deraadt

/etc/ifaliases support by randy@zyzzyva.com


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.227 01-Nov-2022 kn

Only load the SOII key if IPv6 is available

Possible now that IP6KERNERL is hoisted.
This also improves readability and zaps double negation logic.


# 1.226 01-Nov-2022 kn

Do not wait for DAD completion in dry-run mode

1. only do so when running without -n
2. move code to own wait_dad() helper like wait_autoconf_default() has it
3. use local _count as usual in both functions rather than the global count

Feedback OK claudio


# 1.225 31-Oct-2022 kn

Hoist only the feature check

Keep adding IPv6 routes after lo0 got an addres like before, meant to be
committed together with r1.223.


# 1.224 31-Oct-2022 kn

Fix comment: IPv6 link local addresses do not use SOII anymore

sys/netinet6/in6_ifattach.c r1.114 limited it to SLAAC addresses in 2019.


# 1.223 31-Oct-2022 kn

Improve shell style wrt. variable naming/boolean convention

The mixed use of upper and lower case variables is neither obvious nor
consistent.

PRINT_ONLY is local to netstart.
ip6kernel is local to netstart.
multicast gets sourced from rc.subr(8).

1. uppercase ip6kernel as is common for global variables in base scripts
2. use the simpler true/false idiom and default with the rest of
netstart-only variables, making it clearer that only `multicast=YES/NO'
comes from the rc environment
3. hoist kernel feature detection such that a later diff can load the SOII
key conditionally
4. zap obvious comment

OK aja


# 1.222 24-Oct-2022 kn

do not wait for autoconf in dry-run

If there is no default route but some interface has AUTOCONF, printing
what would be done still waits for... nothing to happen.

OK tb


# 1.221 24-Oct-2022 kn

Add required sh(1) to synopsis

Contrary to other scripts in base like rc.d(8) or MAKEDEV(8), netstart(8)
itself is not executable and must be passed as file to sh(1):
$ man -h netstart
/etc/netstart [-n] [interface ...]
$ /etc/netstart
ksh: /etc/netstart: cannot execute - Permission denied

Fix usage and synopsis to provide required usage:
$ man -h netsart
sh /etc/netstart [-n] [interface ...]

OK jmc


# 1.220 21-Oct-2022 kn

Fix synopsis, -n does not require an interface; OK jmc


Revision tags: OPENBSD_7_2_BASE
# 1.219 03-Jul-2022 kn

Create virtual interfaces upfront if specified on the command line

In cases like `sh /etc/netstart pair1 pair2', one of hostname.pair{1,2}
will contain a "patch pair{2,1}" command which expects the other interface
to exist.

If none exist, this would fail and netstart had to be run separately or
"patch"ed interface had to be manually created before.

There are other use cases where interfaces depend on each other, so before
(re)configuring an explicit list of interfaces, create all virtual ones
upfront so that a single netstart invocation will configure everything
correctly without having reflect dependencies in multiple ordered netstart
invocations.

Copy isin() from install.sub to help.

Feedback OK halex


# 1.218 26-Jun-2022 florian

Wait for autoconf interfaces to come up in netstart(8) instead of
rc(8). This makes tunnel interfaces work that depend on working
autoconf interfaces.
OK deraadt


Revision tags: OPENBSD_7_1_BASE
# 1.217 22-Feb-2022 dlg

add some more tunnels to the list of interfaces that rely on routing.


Revision tags: OPENBSD_7_0_BASE
# 1.216 02-Sep-2021 bluhm

Do not create loopback interfaces lo1, lo2, ... upfront. They are
automatically set up by the kernel when a routing domain is created.
An existing lo1 in rdomain 0 would prevent to add any interfaces
in rdomain 1.
OK kn@


# 1.215 30-Aug-2021 bluhm

Improve dubgging in /etc/netstart. Enable print only in ifcreate.
Add debugging output for ipv6 routes. Make localhost and multicast
code aware of the print only switch. Allow netstart -n to work
also if no interface is given.
OK kn@


# 1.214 06-Aug-2021 sthen

As tim@ spotted, a use of V4_AUTOCONF crept in when the variable name
was actually V4_DHCPCONF from previous use. Rename all of the V4_DHCPCONF
to V4_AUTOCONF so everything uses the new name. ok and reminder about
the installer from tb@


# 1.213 16-Jul-2021 florian

switch to dhcpleased/resolvd in base
OK deraadt


# 1.212 20-Jun-2021 florian

Don't try to install a default route with route(8) later on if we are
using inet autoconf, like we do with "dhcp" and "inet6 autoconf".
OK kn


Revision tags: OPENBSD_6_9_BASE
# 1.211 23-Dec-2020 krw

Allow the provision of dhclient(8) options on 'dhcp' lines in hostname.if(5)
files.

Usual man page help & ok jmc@


# 1.210 21-Dec-2020 krw

Avoid issuing pointless 'ifconfig <if> up' when processing 'dhcp' in
hostname.if files. dhclient(8) does that itself. Part of the
"further script optimizations" promised in r1.200 of netstart.

Tested & ok gnezdo@


# 1.209 29-Nov-2020 tb

Fix previous: use correct version of netstart and installer bits.


# 1.208 29-Nov-2020 deraadt

Add support for !command to mygate, so that netstart has a late opportunity
to perform network configuration (for example, "!route source -ifp em0")
Split mygate and myname manual pages (how did anyone ever believe these
are related), and perform hostname configuration much earlier in rc.
discussed with benno, claudio, jmc, etc etc, last version of !command
parser by tb


# 1.207 08-Nov-2020 jmc

no more mobileip;
ok claudio deraadt


Revision tags: OPENBSD_6_8_BASE
# 1.206 21-Jun-2020 dlg

start wg with the other interfaces that rely on routing being up.

from Matt Dunwoodie and Jason A. Donenfeld

ok deraadt@


# 1.205 22-May-2020 kn

Revert the following commit as it breaks hostname.if(5) lines with a
backslash at the end for line continuation

Breaking long lines into multiple ones must still be possible and does
require to treat the backslash as an escape character.

Breakage reported by Mark Patruck <mark at wrapped dot cx >, thanks!

---
distrib/miniroot/install.sub revision 1.1151
etc/netstart revision 1.203
date: 2020/05/21 11:54:41; author: kn; state: Exp; lines: +2 -2;
Do not treat backslashe as an escape character in hostname.if(5) lines

ifstart() should always pass such lines unaltered, especially if they
contain "nwid" or "description" lines with arbitrary strings.

<bsdlisten at gmail dot com> reported SSIDs such as "Mike's" during
installation end as broken; this was because the installer escaped
the single quote using backslashes which ended up being treated as
escape characters much later during hostname.if parsing in netstart(8).

Ok deraadt


# 1.204 21-May-2020 kn

Fix stripcom() description wrt. comments not on their own line

Neither netstart's nor install.sub's (subtly different) implementations
remove trailing comments on lines not starting as a comment, e.g.,
lines like "up #not down" go through unaltered and without "#not down"
being removed.

Only lines *beginning* with the comment sign ("#") are stripped.

No functional change, just updating function descriptions.


# 1.203 21-May-2020 kn

Do not treat backslashe as an escape character in hostname.if(5) lines

ifstart() should always pass such lines unaltered, especially if they
contain "nwid" or "description" lines with arbitrary strings.

<bsdlisten at gmail dot com> reported SSIDs such as "Mike's" during
installation end as broken; this was because the installer escaped
the single quote using backslashes which ended up being treated as
escape characters much later during hostname.if parsing in netstart(8).

Ok deraadt


Revision tags: OPENBSD_6_7_BASE
# 1.202 15-Jan-2020 kn

Do not redirect already quiet stdout for IPv6 reject routes

"route -q" already silences all standard output; if it still prints
something, that's a bug to fix in route.

OK bluhm


# 1.201 25-Oct-2019 dlg

handle aggr(4) in the same way as trunk(4)

from brad@
ok bluhm@ claudio@ deraadt@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.200 29-Aug-2018 krw

Historically /etc/netstart (and the equivalent code in the install
script) did 'ifconfig <if> down' before starting dhclient(8). This was
a way of ensuring old running copies of dhclient were killed before a
new one started. Current dhclient does not need this assist, so change
"ifconfig <if> down" to "ifconfig <if> up" pending further script
optimizations.

Similar to a 2014 attempt by halex@. Prompted by a misc@ report
from Kristjan Komlosi reporting hanging diskless setups.

ok halex@ kn@


# 1.199 08-Jul-2018 tb

netstart is used during system start, but also interactively.
Show proper error message if a regular user executes netstart.
Only do the privilege check if the id binary is available,
which might not be the case during diskless system startup.

ok deraadt, jasper, jca, krw, rpe (who wrote the same diff), sthen


# 1.198 28-Apr-2018 rpe

Add a proper usage() function.

Suggested by and OK jmc.
OK tb


Revision tags: OPENBSD_6_3_BASE
# 1.197 04-Mar-2018 jmc

when -n is used, no need to spit out "Missing parameters." before
displaying usage();

ok tb


# 1.196 03-Mar-2018 landry

Lowercase 'usage' and group -n with interface in it.
From jmc@, ok tb@


# 1.195 21-Feb-2018 rpe

Tweak comments.

OK tb


# 1.194 19-Feb-2018 rpe

Write warning/error messages to stderr and end them with a fullstop.

OK tb


# 1.193 19-Feb-2018 rpe

- use specific patterns when looping over /etc/hostname.if files
to skip backup or temp files.
- test if the patterns matched actual files
- warn if ifcreate() fails on an interface and continue with the
subsequent interfaces in the list instead of return'ing

OK dlg sthen tb


# 1.192 17-Feb-2018 rpe

- Add descriptions for the new functions ifcreate() and vifscreate()
- In ifcreate() use the exit code of the {} block directly
- In vifscreate(), use the ifconfig -C output directly in the for _vif loop
- Remove superfluous and somewhat confusing comment

OK dlg kn sthen


# 1.191 14-Feb-2018 dlg

create virtual interfaces before starting all interface config.

this resolves an ordering problem when adding pseudo interfaces to bridges

tweaks from kn@
ok mpi@ sthen@


# 1.190 10-Feb-2018 claudio

Remove some special IPv4 in IPv6 mapped prefixes that are already rejected
by the ::0.0.0.0/96 reject route added to deny all IPv4 mapped addresses.
Makes the inet6 routing table almost fit in one screen.
OK benno@


# 1.189 10-Feb-2018 florian

Load RFC 7217 key material and generate if it does not already exist.

Add soii.key to changelist (pointed out by semarie) and mtree/special
(suggest by Craig Skinner).

OK naddy, sthen, rpe, tb


# 1.188 06-Feb-2018 tb

If -n is given, the netstart script should not (try to) set the default
route(s). Simply print the command(s) to be issued instead.

tweak & ok rpe


# 1.187 12-Nov-2017 tb

Remove HN_DIR variable and expand it in the only place it was used. It
currently serves no purpose.

ok rpe, agreement from deraadt and halex


Revision tags: OPENBSD_6_2_BASE
# 1.186 25-Jul-2017 rpe

Finally remove backwards compat code to support the 'rtsol' keyword
in hostname.if(5)

OK mpi@ deraadt@ florian@
OK jmc@ from doc perspective


# 1.185 21-Jul-2017 rpe

Align ifstart() in netstart and install.sub.

- in netstart, rename _file to _hn referencing hostname.if files
- in install.sub switch ifstart() to be used with _if instead of
_hn as parameter

ok krw@ tb@


# 1.184 28-May-2017 awolk

etc/netstart: use colon separator instead of dot with chown

OK jung@, deraadt@, jmc@


# 1.183 07-May-2017 rpe

Change test from [] to [[]] and simplify pattern.

OK tb@, krw@ (for [[]])
Feedback and OK halex@


# 1.182 07-May-2017 rpe

Replace hardcoded script name with ${0##*/}

OK tb@ halex@


# 1.181 01-May-2017 rpe

Revert r1.170 and remove the id==0 check.
The id binary is not available in nfs diskless setups at this point.

reported by Andreas Kusalananda, thanks.
discussed with deraadt@


# 1.180 01-May-2017 rpe

Remove last remnants of rtsol. IPv6 autoconfiguration of interfaces is now
done in ifstart(). Remove ipv6autoconf() and replace rtsolif with a boolean
variable V6_AUTOCONF. Replace dhcpif with a boolean variable V4_DHCPCONF.
Both are later used in defaultroute() to decide whether or not to configre
defaultroutes from /etc/mygate.

OK krw@


# 1.179 30-Apr-2017 mpi

Do not try to delete a default route before adding it.

Now that route are automatically G/C with the address they are attached
to there's no reason to duplicate the kernel's job.

Fix a regression introduced with multipath default routes.

ok deraadt@


# 1.178 25-Apr-2017 rpe

Unbreak netstart for multiple inteface configurations like trunk
or carp. Ensure that the noglob option is disabled at the end of
parse_hn_line() and ifstart().

Reported by Christer Solskogen and Stefan Wollny, thanks!


# 1.177 24-Apr-2017 rpe

Introduce a new function parse_hn_line() that replaces the existing
hostname.if(5) parsing code in ifstart().
Add a -n option to netstart to only print the interface configuration
commands instead of executing them.
Add a HN_DIR variable, that points to the directory of the hostname.if
files (default /etc) that allows for future regression tests.

- add new parse_hn_line() function
- change ifstart()
- rename $if to $_if
- don't ifconfig or ifconfig create if -n option is used
- replace hostname.if(5) parsing code with new parse_hn_line()
- just print configuration commands if -n option is used
- autoconf now happens in ifstart(), remove ifv6autoconf()
- introduce HN_DIR variable for the hostname.if file location
- add handling of the -n option to only print config commands
- ensure -n is only used if interfaces are specified as parameters

Discussed with and positive feedback from many
'commit' deraadt@
OK sthen@


# 1.176 08-Apr-2017 rpe

- localize the if, file and stat variables which also ensures that
variables are not named like commands.
- change test from [] to [[]]

OK tb@ halex@


# 1.175 07-Apr-2017 rpe

Minimize differences in ifstart() function between netstart and
install.sub which makes it easier to spot changes in the future.

- comments and formatting
- quotes on assignments are not needed (netstart)
- remove stray space in test (netstart)
- use $file variable with while-loop (netstart)
- although valid, instead of i use $i in arithmetic test (install.sub)

OK krw@, tb@
Looks good deraadt@


# 1.174 07-Apr-2017 rpe

Align comments of ifstart() function in netstart and install.sub.


# 1.173 07-Apr-2017 rpe

Align comments of stripcom() function in netstart and install.sub.


Revision tags: OPENBSD_6_1_BASE
# 1.172 06-Dec-2016 mpi

Do not lose the default route when netstart(8) is run a second time on
the interface pointed to by the default route.

Since the kernel no longer keep routes with dangling address pointer,
netstart(8) has to re-add the default route when the corresponding ifa
has been deleted and re-created.

deraadt@ points out that even if the previous semantic was not necessarily
better, a script like netstart(8) cannot totally fix the default route
problem.

Regression reported by and fix tested by Hrvoje Popovski.

ksh foo checked by halex@


# 1.171 27-Sep-2016 rzalamena

Delay switch(4) interface start up so it can attach virtual interfaces
like vether(4).

nits from and ok benno@, phessler@


# 1.170 09-Sep-2016 jasper

print a clear error message when not ran as root instead of just falling
through and try whatever it can do with the invoking user's perms

feedback/ok aja@ rpe@


Revision tags: OPENBSD_6_0_BASE
# 1.169 19-Jul-2016 mpi

Do not consider tap(4) a special interface and start if before other
pseudo-interfaces.

This unbreak vlan(4) on top of tap(4) since the refactoring to turn it
MP-safe.

ok claudio@, deraadt@


# 1.168 27-Mar-2016 sthen

Don't delete the 224/4 route in netstart, unless it's being done to ensure that
a -reject route can be added. Restores the ability to set an interface route
before daemons are started, lost during the previous simplification.
ok millert mpi


Revision tags: OPENBSD_5_9_BASE
# 1.167 29-Dec-2015 rpe

Remove backslash, not necessary after '&&'

OK halex@


# 1.166 29-Dec-2015 rpe

Replace last remaining `` with $()

OK halex@


# 1.165 18-Dec-2015 ajacoutot

Drop the now useless multicast setup comment.

prodded by tim@, ok mpi@


# 1.164 17-Dec-2015 ajacoutot

Simplify multicast option handling (10 less lines) by matching /etc/rc behavior
towards other YES|NO options and drop the error warning.


with and ok tim@, ok rpe@ on an earlier diff


# 1.163 05-Dec-2015 mpi

It does not make sense to insert a specific route for 224/4 when the
default one is good enough.

So merge rc.conf(8)'s 'multicast_router' and 'multicast_host' into a
single 'multicast'. If set to YES the reject route for 224/4 is not
inserted by netstart(8).

Manual bits from jmc@

ok henning@, ajacoutot@


# 1.162 12-Nov-2015 rpe

Changes to ifautostart():
- Rename function to ifv6autoconf() to make IPv6 relation clearer
- Localize and rename variables

OK krw@


# 1.161 12-Nov-2015 rpe

Changes to ifmstart():
- Change comments to make it clearer that ifmstart() takes two lists
of interface driver names (of which the second is optional) and not
the actual interface instances.
- Use localized variables and use slightly more verbose names.
- Use continue 2 to skip to the next hostname.if file.
- Use shell pattern @() instead of testing _sif individually.

OK krw@


# 1.160 12-Nov-2015 rpe

Changes to stripcom():
- Align comments with /etc/rc version
- Use localized variables
- Use safer "print -r --" instead of plain echo

Changes to ifstart():
- Tweak comment
- Add usage

OK krw@


# 1.159 01-Nov-2015 rpe

Start the rework of the /etc/netstart shell script.

General changes:
- apply a similar 'style' as used in the installer scripts
- improve comments to be more to the point, remove where code is obvious
- document usage of functions if they have arguments
- rename variables where it improves readability
- replace really old-school shell code with more contemporary idioms

Other changes:
- No need to care about "autoboot" because netstart doesn't inherit the
positional parameters from /etc/rc anymore. /etc/rc executes netstart
instead of sourcing it since r1.439.
- Use simpler for-loop to process list of interfaces with ifstart.

OK halex@


# 1.158 26-Oct-2015 rpe

The hostname variable is not used since r1.99. Remove it and use
stripcom() output directly with the hostname command.

OK deraadt@ krw@


# 1.157 23-Oct-2015 claudio

netstart bits for tap(4)


# 1.156 27-Sep-2015 sthen

Don't print output when setting autoconf on interfaces. Suggested by deraadt,
ok florian@ rpe@


# 1.155 13-Sep-2015 sthen

only print the "IPv6 autoconf" line if there are interfaces to configure
feedback/ok rpe


# 1.154 11-Sep-2015 sthen

Set "inet6 autoconf" individually on interfaces that have rtsol set in
hostname.if, previously netstart tried to configure them all at once
("ifconfig if0 if1 if2 inet6 autoconf"). From Delan Azabani, ok phessler@


Revision tags: OPENBSD_5_8_BASE
# 1.153 20-Jul-2015 rpe

Disable Strict Bourne shell mode for /etc/rc and /etc/netstart to be
able to use ksh syntax within these scripts. This way init doesn't
need to be changed, which starts /etc/rc using /bin/sh and people
can still use "sh /etc/netstart ifname".

Idea from and OK halex@
OK deraadt@ krw@ guenther@


# 1.152 19-Jul-2015 florian

Bring up pflow last as it might send with a source address that is on
any of the other interfaces.
OK deraadt, phessler, benno


# 1.151 19-Jul-2015 rpe

Always source rc.subr to be able to use the rc.conf parsing routine
to get the network related vars from rc.conf. This is even necessary
if netstart is run from within /etc/rc. Remove test of $INRC which
unintentionally evaluated always to true.

problem with previous change found by nigel@
OK sthen@ aja@ halex@


# 1.150 19-Jul-2015 ajacoutot

Revert 1.148 for now until I can talk to rpe@
It introduced a regression reported by nigel@


# 1.149 19-Jul-2015 rpe

Replace test command with [].

OK halex@ krw@


# 1.148 19-Jul-2015 rpe

Ensure, that we source rc.subr and parse rc.conf ONLY if we are not
inside /etc/rc.

With help from and OK halex@, ajacoutot@


# 1.147 18-Jul-2015 rpe

- remove trailing blanks introduced in previous commit
- no space in redirections like </foo or >$bar
- few other minor whitespaces

OK krw@


# 1.146 18-Jul-2015 rpe

Improve comments
- Add comments for functions
- Start comments with capital letters
- End comments with a full stop
- Allow comments to extend up to column 80

OK krw@


# 1.145 06-Jun-2015 florian

Allow rtsol keyword in hostname.if(5) with net.inet6.ip6.forwarding=1.
"inet6 autoconf" was working before and rtsol should behave the same.
OK phessler


Revision tags: OPENBSD_5_7_BASE
# 1.144 03-Dec-2014 florian

The kernel handles rtsol(8) functionality since some time now.
Treat rtsol in hostname.if as a keyword like dhcp and call ifconfig
inet6 autoconf.
"reads good" todd@
OK krw@ (who is *not* an IPv6 person), but I recruited him in his
capacity as an installer person.


# 1.143 28-Sep-2014 claudio

Revert 1.142. Without the down netstart will just print the ifconfig
output because it may end up just calling 'ifconfig $if'. This needs
to be done better and properly tested.


# 1.142 26-Sep-2014 halex

remove explicit 'down' of an interface before starting a dhcp request, thereby
avoiding annoying delays for some switch configurations

ok claudio@ deraadt@

i would add ok phessler@, but it was not valid without an ok krw@


Revision tags: OPENBSD_5_6_BASE
# 1.141 12-Jul-2014 stsp

Fix netstart after autoconf6 change so 'rtsol' lines in hostname.if work again.
found by pelikan@; ok pelikan@ henning@


# 1.140 12-Jul-2014 robert

Make rc.conf a parsed configuration file and stop sourcing it as a shell
script.
From now on rc.conf has a fixed syntax (key=val) and it is not allowed
to add anything to it besides the supported syntax, it all going to be
ignored.

discussed with and help from deraadt@ and halex@


Revision tags: OPENBSD_5_5_BASE
# 1.139 22-Aug-2013 mpi

Like for dhclient, do no create a route to alias addresses via 127.0.0.1.
Our stack is able to tell if the address is local or not.

ok todd@, krw@


Revision tags: OPENBSD_5_4_BASE
# 1.138 20-Mar-2013 todd

fix lies in netstart; replacement wording from halex@
pointed out by Ryan Kavannagh rak at debian dot org


Revision tags: OPENBSD_5_3_BASE
# 1.137 05-Dec-2012 rpe

remove "Invalid interface name" message
requested by krw@

ok halex@


# 1.136 02-Dec-2012 rpe

use the more compact version of the check for ifconfig'able interfaces
from install.sub

with feedback from and ok halex


# 1.135 02-Dec-2012 rpe

- remove isalphanumeric() and replace it with a shell pattern, that
tries a bit harder to identify invalid interface names and in
this case emit an error message.
- use [[ $1 == autoboot ]] to avoid a shell error message due to
possible spaces in first argument
- no change in functionality

discussed with krw and halex
ok ("I like this") krw


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.134 07-Oct-2011 deraadt

The new ypbind changes requires that the domainname be set before
rc.conf is run. There's no real downside.
ok aja


Revision tags: OPENBSD_5_0_BASE
# 1.133 07-Jul-2011 guenther

Eliminate some $? tests by rolling the command into the condition

ok halex@


# 1.132 26-May-2011 mpf

Add svlan(4) startup bits.
From markus@. OK naddy, claudio, reyk.


Revision tags: OPENBSD_4_9_BASE
# 1.131 09-Feb-2011 sobrado

fix an unbalanced parenthesis in a comment; while here, split the comment
in a better place to make it more readable.

ok jmc@ and miod@


Revision tags: OPENBSD_4_8_BASE
# 1.130 16-Jun-2010 todd

permit e.g. -inet6 syntax by slurping all lines not just some
noticed by rhsv6 at hushmail dot com, ok sthen@


Revision tags: OPENBSD_4_7_BASE
# 1.129 12-Jan-2010 henning

when setting up lo0 use 127.0.0.1/8 instead of 127.0.0.1 for clarity and
correctness. it's not 1992 any more, kids. ok mcbride dlg krw


# 1.128 10-Dec-2009 todd

o stop reordering ifconfig arguments (e.g. after 'up ..')
o only stop processing if inet or inet6 lines are malformed
o everything not a specially handled bit is passed to ifconfig unmangled
noticed by several after the move from bridgename.bridge0 -> hostname.bridge0
prodded by deraadt@, tested by and feedback from several
man page bits 'look fine' jmc@


# 1.127 22-Nov-2009 deraadt

Stop supporting bridgename.bridge* files, and move to hostname.bridge*
files. To cope with this change, read about the mv command.
ok claudio todd


# 1.126 17-Sep-2009 simon

change variable i to $i in an expression of ifstart() for consistency
with the rest of the file. no functional change.

feedback from sthen@, ok krw@


# 1.125 10-Jul-2009 jdixon

Delay creation of tun(4) interfaces until the underlying interface and
routes are available. This fixes usage for some OpenVPN users that start
it from hostname.tun*.

Tested by Johan Huldtgren. ok sthen@, johan@.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.124 25-Nov-2008 markus

delay /etc/netstart until IPv6-DAD (dup-address-detection) is completed.
ok fries, hshoexer, claudio


# 1.123 14-Aug-2008 sthen

Tools from /usr may not be used in netstart since it may be NFS-mounted
and not available at that time. Rewrite the hostname.if permission check
to use only /bin/ls and the shell. Requested by deraadt.

ok todd, "Twisted." deraadt


Revision tags: OPENBSD_4_4_BASE
# 1.122 23-Jul-2008 sthen

Prevent warning about insecure hostnames where no /etc/hostname.*
exists. From wcmaier@.

Check target of symbolic links to avoid noise at boot and in
seucrity output where you have several interfaces symlinked to one
config file.

"If you think this is the right thing to do" deraadt@


# 1.121 09-Jun-2008 todd

warn once not 3 times in case of a non existent file, discussed with deraadt
originally pointed out by Johan Torin


# 1.120 09-Jun-2008 deraadt

Ensure that hostname.* files are also re-chowned to root.wheel at each
boot as discussed with claudio while eating tasty donairs. ok todd


# 1.119 17-Apr-2008 deraadt

before using them, force hostname.* files to be unreadable by world
first version from todd, ok millert


Revision tags: OPENBSD_4_3_BASE
# 1.118 17-Jan-2008 brad

Execute rtsol after turning up trunk(4) and vlan(4) interfaces so they're
taken into consideration for rtsol.

ok reyk@ dlg@


# 1.117 09-Jan-2008 mpf

Do not bring up pfsync(4) before the working ruleset
has been loaded. Otherwise, states that are received during the
initial bulk update mismatch the correct pf-checksum and
do not attach to the rules.
Problem identified by david@. Fix done in collaboration.
OK henning@


Revision tags: OPENBSD_4_2_BASE
# 1.116 02-Aug-2007 david

move the delay for IPv6 DAD to after all interfaces have started
fixes problems with daemons being unable to bind to all addreses at boot
ok itojun@ hshoexer@


Revision tags: OPENBSD_4_1_BASE
# 1.115 15-Nov-2006 itojun

reject multicast packet without scope identifier specified.


Revision tags: OPENBSD_4_0_BASE
# 1.114 29-Jun-2006 todd

do not add an extra space; nwid and description come out wrong
fix as proposed by maja@, thanks!


Revision tags: OPENBSD_3_9_BASE
# 1.113 28-Dec-2005 david

nuke extra whitespace


# 1.112 06-Dec-2005 reyk

multicast_host=YES only works if a valid default gateway is available.
validate this condition and reject multicast traffic on failure.

ok todd@ naddy@


# 1.111 02-Nov-2005 todd

fix inspired by pr#4590
ok krw@


# 1.110 25-Oct-2005 todd

better logic from krw@:
- do not process mygate for v4 if dhcp
- do not process mygate for v6 if rtsol
this also makes the mygate processing logic more readable
ok krw@


# 1.109 14-Oct-2005 todd

add v6 support for /etc/mygate
ok deraadt@ mickey@ krw@
same functionality tested/ok'ed by by mickey, brad, matthieu, and me
with this one may now put a v6 IP in /etc/mygate on a separate line from
the v4 default gateway and netstart will do the right thing


# 1.108 12-Oct-2005 todd

shrink stripcom(), sync with install.sub
ok krw@


# 1.107 04-Oct-2005 todd

trunk must be started after physical ethernet devices, but before vlan.
populate ifmstart lines accordingly.
prodded/tested by brad@
ok reyk@


# 1.106 28-Sep-2005 todd

use eval consistently, fixes description quotes on rtsol and dhcp
fix inspired by and closes pr 4495
ok krw@


Revision tags: OPENBSD_3_8_BASE
# 1.105 22-May-2005 todd

Introduce 'ifmstart' to deal with starting multiple interfaces minus a list
of interfaces.

This reduces the netstart script by 174 chars, 13 words, and 19 lines, but
more importantly, makes it more simple and less cluttered should more special
case/orderings be needed.

ok brad@ and pr 4197 submitter, inspired by and closes pr 4197


# 1.104 04-Apr-2005 djm

unbreak; ok pval@


# 1.103 03-Apr-2005 deraadt

if dhcp is used to get an address on any interface, ignore /etc/mygate
ok krw
(this lets us do something rather cool with the zaurus in particular)


Revision tags: OPENBSD_3_7_BASE
# 1.102 04-Jan-2005 mcbride

Bring up the carp(4) interface before default route.

ok pascoe@ mpf@


# 1.101 30-Dec-2004 millert

Add a copy of stripcom so /etc/netstart can be run standalone again.
OK deraadt@


# 1.100 19-Dec-2004 millert

Allow comments in /etc/{myname,mygate,defaultdomain}; OK deraadt@


# 1.99 04-Dec-2004 itojun

remove "route $hostname 127.0.0.1" line. deraadt ok
*** please update /etc/netstart and test if it works ok for you ***


# 1.98 20-Oct-2004 deraadt

make all route commands use -qn; ok mcbride henning


Revision tags: OPENBSD_3_6_BASE
# 1.97 29-May-2004 deraadt

one last route command lacking -qn


Revision tags: OPENBSD_3_5_BASE
# 1.96 22-Mar-2004 mcbride

Make sure pfsync is brought up before carp.

ok deraadt@


# 1.95 13-Mar-2004 mcbride

Delay pfsync(4) configuration, as the syncif has to be configured in
advance. From Thorsten Lockert.


# 1.94 14-Jan-2004 deraadt

ok, it took quite a bit of prodding but itojun finally explained why the
extra sleep 1 is in here, and we came to the conclusion it is safe to
delete it. whee.


# 1.93 13-Jan-2004 deraadt

repair v6 lo0 documentation


# 1.92 11-Jan-2004 deraadt

add loopback routes late


# 1.91 09-Jan-2004 deraadt

create all routes with -q; markus ok


# 1.90 04-Dec-2003 millert

Need to do "ifconfig create" for bridge interfaces too.


# 1.89 03-Dec-2003 markus

add support for ifconfig clone; from netbsd; ok deraadt, henning


# 1.88 20-Oct-2003 david

delay carp initialization until after physical interfaces are configured
ok mcbride@ henning@ deraadt@ todd@


Revision tags: OPENBSD_3_4_BASE
# 1.87 27-Aug-2003 henning

only try to set hostname to what /etc/myname says if that file actually exists,
otherwise preserve `hostname`
netbooted machines can live perfectly fine without it; they get their hostname
earlier.

ok krw@ cedric@


Revision tags: OPENBSD_3_3_BASE
# 1.86 16-Feb-2003 krw

Fix up some DNS verbiage to make it consistant.

Fix up default route selection by

a) Forcing user to explicitly chose 'dhcp' as a mechanism for
specifying a default route, rather than guessing based on one or more
interfaces being configured by dhcp.

b) If the user specified default route does not work, re-present the
existing default route rather than losing it.

c) Move default route selection to after nameserver activation so the
user can specify a hostname as the default route.

Change /etc/netstart so that /etc/mygate wins if a default route was
already specified (i.e. by dhcp).

ok deraadt@.


Revision tags: OPENBSD_3_2_BASE
# 1.85 16-May-2002 todd

ignore non-existent cases where '$if' evaluates to '*'.
From Andr� Lucas <andre@ae-35.com>, fixes pr # 2658.
'Looks good' from miod@, millert@, and krw@.


Revision tags: OPENBSD_3_1_BASE
# 1.84 23-Feb-2002 deraadt

re-add support for $if expansion; hamajima@nagoya.ydc.co.jp


# 1.83 21-Feb-2002 miod

Change the network components initialization order.
Change from:
o all interfaces
o all bridges
o routes
to:
o physical interfaces
o routes
o gif and gre interfaces
o bridges

Fixeski PR #2400.
Manual page updates coming soon.
Ok angelos@ chris@ deraadt@


Revision tags: OPENBSD_3_0_BASE
# 1.82 31-Jul-2001 hugh

a space before a redirect


# 1.81 06-Jul-2001 angelos

Also, source /etc/rc.conf so we can pull in the
multicast_host/multicast_router settings; this is useful if one
flushes the routing table and re-initializes.

We really need a netconfig tool of sorts.


# 1.80 06-Jul-2001 angelos

Use "route -n show -inet" to determine the default multicast iface.


# 1.79 03-Jul-2001 deraadt

pull in rc.conf early so that pf(1) startup is right; tested by jasoni, comments from millert


# 1.78 30-May-2001 deraadt

Remove ipf. Darren Reed has interpreted his (old, new, whichever)
licence in a way that makes ipf not free according to the rules we
established over 5 years ago, at www.openbsd.org/goals.html (and those
same basic rules govern the other *BSD projects too). Specifically,
Darren says that modified versions are not permitted. But software
which OpenBSD uses and redistributes must be free to all (be they
people or companies), for any purpose they wish to use it, including
modification, use, peeing on, or even integration into baby mulching
machines or atomic bombs to be dropped on Australia. Furthermore, we
know of a number of companies using ipf with modification like us, who
are now in the same situation, and we hope that some of them will work
with us to fill this gap that now exists in OpenBSD (temporarily, we
hope).


Revision tags: OPENBSD_2_9_BASE
# 1.77 13-Mar-2001 deraadt

spelling; maurice@maurice.wan.nl


# 1.76 06-Feb-2001 todd

ignore blank lines in addition to comments
fixes pr#1660 from wilfried@telia.com .. Thanks!


# 1.75 10-Jan-2001 jason

support !command in bridgename.if files, too


# 1.74 27-Nov-2000 millert

Use -n to test if a variable is non-zero. Otherwise, if the variable's
contents start with a '-' test becomes unhappy (since it interprets it
as another option).


# 1.73 08-Nov-2000 todd

This fixes pr 1481, we now handle args > 6 in /etc/hostname.if in the
cases where we did not previously handle them.
Thanks to Scott Atwood <atwood@cs.stanford.edu> for reminding us of this.


Revision tags: OPENBSD_2_8_BASE
# 1.72 02-Sep-2000 todd

subtle bug .. global variables in a while loop need reset 'just incase'
With:
hostname.fxp0 having a last line of:
inet6 alias 3ffe:...
and hostname.gif0 having a first two lines of:
giftunnel 1.2.3.4
dest 1.2.4.3
We end up with the command:
ifconfig gif0 giftunnel alias 1.2.3.4 1.2.4.3
.. which is clearly wrong and fixed by this change


# 1.71 18-Jun-2000 todd

rc.conf now parses ${local_rcconf} internally; closes pr 1259


Revision tags: OPENBSD_2_7_BASE
# 1.70 08-May-2000 todd

fix dhcp 'NONE' ness from install to allow media parsing to work
.. ok deraadt@, millert@


# 1.69 21-Apr-2000 deraadt

rc.conf.local support, inspired by chuck yerkes


# 1.68 04-Apr-2000 millert

Remove the -E flag from ipf as it is implicitly enabled and using
the -E flag here causes the kernel to printf 'IP Filter: already
initialized'.


# 1.67 18-Mar-2000 deraadt

silence all extra route addition printouts


# 1.66 17-Mar-2000 itojun

correct reject route installations for IPv6. improve comments.


# 1.65 12-Mar-2000 itojun

disallow packets to malicious 6to4 prefix, based on
http://playground.iijlab.net/i-d/draft-itojun-ipv6-transition-abuse-00.txt


# 1.64 10-Mar-2000 todd

fix non behavior
with this `!' lines in /etc/hostname.* run even without certain lines
(like a comment) preceeding it.


# 1.63 10-Jan-2000 todd

allow arbitrary commands in /etc/hostname.* files if the line starts with '!'


# 1.62 02-Jan-2000 deraadt

rtsol case can configure the interface up, since it would be nice to finish
DAD before the actual rtsol(8) run happens later. and since it will rtsol,
it is going to be up in any case.


# 1.61 02-Jan-2000 itojun

one more indentation fix.


# 1.60 02-Jan-2000 itojun

indentation fix (todd's part)


# 1.59 02-Jan-2000 todd

fix rtsold case, reset cmd for each iteration!


# 1.58 02-Jan-2000 itojun

allow options after "rtsol".
XXX both "dhcp" and "rtsol" has keyword *down* at the end. is it okay?


# 1.57 02-Jan-2000 itojun

echo "IPv6 autoconf: interfaces" before invoking rtsol.
sleep for net.inet6.ip6.dad_count seconds to ensure that IPv6 DAD is completed.
TODO: rtsold (rc.conf line), manpage


# 1.56 02-Jan-2000 itojun

ipv6 autoconf on hosts (non-routers).

to do this,
1. in sysctl.conf, add these lines:
net.inet6.ip6.forwarding=0
net.inet6.ip6.accept_rtadv=1
2. in hostname.foo, add
rtsol

specifying two or more interfaces with "rtsol" may result in strange
behavior - ipv6 spec does not permit multi-interface node to be autoconfig'ed.


# 1.55 02-Jan-2000 todd

add to hostname.* parsing:
- multiple entries support (read: aliases)
- inet6 support
- support for comments (#)
(look for hostname.if(5) commit for syntax details)


# 1.54 31-Dec-1999 itojun

install IPv6 reject routes only if kernel is capable of IPv6.


# 1.53 09-Dec-1999 itojun

avoid transmitting invalid IPv6 packets out to the wire.


# 1.52 09-Dec-1999 itojun

do not perform IPv6 initialization for loopback interface.
MUST make lo0 up before any IPv6 operations.
it will be considered a pilot error if you don't.
(I prefer to have lo0 initialized automatically)


Revision tags: OPENBSD_2_6_BASE
# 1.51 01-Sep-1999 deraadt

support # characters in bridgename.* files; millert


# 1.50 01-Sep-1999 deraadt

cleanup parsing of hostname.* files, and seperate bridge control into
bridgename.* files; all documented in new hostname.if(5) and
bridgename.if(5) man pages


# 1.49 09-Aug-1999 angelos

Only parse/setup the hostname.foo file if interface foo exists (this
is useful for laptops with different ethernet cards etc.)


Revision tags: OPENBSD_2_5_BASE
# 1.48 29-Mar-1999 niklas

New multicast route setup style


# 1.47 26-Mar-1999 niklas

Add bridge interface handling


# 1.46 01-Mar-1999 millert

Add support in /etc/hostname.xxx for files of the format:
up [options]
Any of the following may or may not be set:
$name $mask $bcaddr $extras


# 1.45 28-Oct-1998 millert

Kill the awful hack used to match and split /etc/hostname.* We now use
a function, isalphanumeric, to determine whether an interface name is
likely to be valid. This means that things like /etc/hostname.le0.bak,
/etc/hostname.le0#, /etc/hostname.le0~, etc. will be ignored as they
should. There is no longer an implicate assumption that /etc/hostname.*
only contains a single '.'.


Revision tags: OPENBSD_2_4_BASE
# 1.44 06-Oct-1998 deraadt

move ipnat to end of netstart, to support dhcp+ipnat


# 1.43 18-Sep-1998 deraadt

apply media directives on dhcp interfaces


# 1.42 10-Sep-1998 marc

better way of handling dhcp client; Jason Ish <jbi130@mail.usask.ca>


# 1.41 08-Sep-1998 marc

dhcp client stuff. "Angelos D. Keromytis" <angelos@dsl.cis.upenn.edu>


# 1.40 24-Aug-1998 downsj

You can't use -interface default when there's no default gateway
set (yet). Use -interface $hostname if mygate doesn't exist so that
this actually works on routers.


# 1.39 04-Jul-1998 deraadt

put 224 route on default, to avoid a hostname lookup


# 1.38 22-May-1998 deraadt

use route -n, what the heck


Revision tags: OPENBSD_2_3_BASE
# 1.37 28-Mar-1998 deraadt

s/^nat/ipnat/


# 1.36 23-Feb-1998 niklas

remove trailing blank line


# 1.35 07-Feb-1998 deraadt

ipforward is in sysctl.conf now


# 1.34 21-Dec-1997 deraadt

ugh


# 1.33 20-Dec-1997 deraadt

ipforwarding option in rc.conf


# 1.32 29-Nov-1997 kstailey

NAT requires IPF


# 1.31 04-Nov-1997 deraadt

kill spaces at ends of lines; m4


Revision tags: OPENBSD_2_2_BASE
# 1.30 14-Oct-1997 deraadt

set hostname/domainname before running rc.conf; m4@umn.edu


# 1.29 04-Sep-1997 deraadt

fork netstart; new child is rc.conf


# 1.28 25-Aug-1997 millert

Explicately pass -host flag to route(8) to avoid confusion with networks.


# 1.27 19-Aug-1997 niklas

Add hook for rpc.lockd, make nfsd flags settable in netstart


# 1.26 31-Jul-1997 downsj

Make quotas optional; wedged into netstart for the time being.
/etc/rc.conf, anyone?


# 1.25 30-Jul-1997 deraadt

do not run routed by default


# 1.24 28-Jul-1997 kstailey

Move configuration of loopback interface to before all other interfaces.
Allows the use of local caching-only nameserver with no "nameserver"
entry in /etc/resolv.conf to configure a route between the hostname
and loopback.


# 1.23 25-Jul-1997 provos

earlier start of keymanagement


# 1.22 24-Jul-1997 deraadt

make amd use /tmp_mnt by default


# 1.21 22-Jul-1997 provos

start the photuris daemon per default. hilfe.


# 1.20 17-Jun-1997 niklas

Put in hooks to start ypserv with flags


# 1.19 17-Jun-1997 niklas

Put in hooks to start rpc.yppasswdd with flags


Revision tags: OPENBSD_2_1_BASE
# 1.18 15-Apr-1997 deraadt

kill route flush until .. hmm kernel routing socket bug or something


# 1.17 09-Apr-1997 kstailey

add NAT startup


# 1.16 07-Apr-1997 rees

flush all old routes before adding new interfaces or routes.
ref: netbsd pr3228/misc, Matthias Scheler


# 1.15 03-Mar-1997 downsj

fix typo


# 1.14 11-Feb-1997 deraadt

add default route before fiddling with loopback route to avoid DNS problems; m4@umn.edu, #97


# 1.13 03-Feb-1997 deraadt

do ifaliases after /usr/bin exists in nfs diskless env; pr#77, matthieu@laas.fr


# 1.12 02-Nov-1996 deraadt

timed off by default


Revision tags: OPENBSD_2_0_BASE
# 1.11 23-Sep-1996 deraadt

rfc1323 variable


# 1.10 04-Sep-1996 deraadt

control portmap, inetd, and lpd from netstart; idea from tqbf@enteract.com


# 1.9 27-Aug-1996 deraadt

224.0.0.0 not 0.0.0.224; from peter@demon.net


# 1.8 18-Jun-1996 deraadt

move std stuff from rc.local to rc


# 1.7 16-Jun-1996 deraadt

install sample commented /etc/ifaliases file; which can now contain #
comments and blank lines. new format is "interface address netmask"
(yes, i changed the order of the entries). inspired by netbsd pr#2474;
gillhaa@ghost.whirlpool.com


# 1.6 02-Jun-1996 tholo

Install a multicast route by default


# 1.5 26-May-1996 deraadt

sync & label


# 1.4 09-Jan-1996 dm

added IP filter to netstat/rc and put examples in /usr/share/ipf


# 1.3 30-Dec-1995 deraadt

from netbsd: start mrouted like routed


# 1.2 18-Dec-1995 deraadt

/etc/ifaliases support by randy@zyzzyva.com


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.222 24-Oct-2022 kn

do not wait for autoconf in dry-run

If there is no default route but some interface has AUTOCONF, printing
what would be done still waits for... nothing to happen.

OK tb


# 1.221 24-Oct-2022 kn

Add required sh(1) to synopsis

Contrary to other scripts in base like rc.d(8) or MAKEDEV(8), netstart(8)
itself is not executable and must be passed as file to sh(1):
$ man -h netstart
/etc/netstart [-n] [interface ...]
$ /etc/netstart
ksh: /etc/netstart: cannot execute - Permission denied

Fix usage and synopsis to provide required usage:
$ man -h netsart
sh /etc/netstart [-n] [interface ...]

OK jmc


# 1.220 21-Oct-2022 kn

Fix synopsis, -n does not require an interface; OK jmc


Revision tags: OPENBSD_7_2_BASE
# 1.219 03-Jul-2022 kn

Create virtual interfaces upfront if specified on the command line

In cases like `sh /etc/netstart pair1 pair2', one of hostname.pair{1,2}
will contain a "patch pair{2,1}" command which expects the other interface
to exist.

If none exist, this would fail and netstart had to be run separately or
"patch"ed interface had to be manually created before.

There are other use cases where interfaces depend on each other, so before
(re)configuring an explicit list of interfaces, create all virtual ones
upfront so that a single netstart invocation will configure everything
correctly without having reflect dependencies in multiple ordered netstart
invocations.

Copy isin() from install.sub to help.

Feedback OK halex


# 1.218 26-Jun-2022 florian

Wait for autoconf interfaces to come up in netstart(8) instead of
rc(8). This makes tunnel interfaces work that depend on working
autoconf interfaces.
OK deraadt


Revision tags: OPENBSD_7_1_BASE
# 1.217 22-Feb-2022 dlg

add some more tunnels to the list of interfaces that rely on routing.


Revision tags: OPENBSD_7_0_BASE
# 1.216 02-Sep-2021 bluhm

Do not create loopback interfaces lo1, lo2, ... upfront. They are
automatically set up by the kernel when a routing domain is created.
An existing lo1 in rdomain 0 would prevent to add any interfaces
in rdomain 1.
OK kn@


# 1.215 30-Aug-2021 bluhm

Improve dubgging in /etc/netstart. Enable print only in ifcreate.
Add debugging output for ipv6 routes. Make localhost and multicast
code aware of the print only switch. Allow netstart -n to work
also if no interface is given.
OK kn@


# 1.214 06-Aug-2021 sthen

As tim@ spotted, a use of V4_AUTOCONF crept in when the variable name
was actually V4_DHCPCONF from previous use. Rename all of the V4_DHCPCONF
to V4_AUTOCONF so everything uses the new name. ok and reminder about
the installer from tb@


# 1.213 16-Jul-2021 florian

switch to dhcpleased/resolvd in base
OK deraadt


# 1.212 20-Jun-2021 florian

Don't try to install a default route with route(8) later on if we are
using inet autoconf, like we do with "dhcp" and "inet6 autoconf".
OK kn


Revision tags: OPENBSD_6_9_BASE
# 1.211 23-Dec-2020 krw

Allow the provision of dhclient(8) options on 'dhcp' lines in hostname.if(5)
files.

Usual man page help & ok jmc@


# 1.210 21-Dec-2020 krw

Avoid issuing pointless 'ifconfig <if> up' when processing 'dhcp' in
hostname.if files. dhclient(8) does that itself. Part of the
"further script optimizations" promised in r1.200 of netstart.

Tested & ok gnezdo@


# 1.209 29-Nov-2020 tb

Fix previous: use correct version of netstart and installer bits.


# 1.208 29-Nov-2020 deraadt

Add support for !command to mygate, so that netstart has a late opportunity
to perform network configuration (for example, "!route source -ifp em0")
Split mygate and myname manual pages (how did anyone ever believe these
are related), and perform hostname configuration much earlier in rc.
discussed with benno, claudio, jmc, etc etc, last version of !command
parser by tb


# 1.207 08-Nov-2020 jmc

no more mobileip;
ok claudio deraadt


Revision tags: OPENBSD_6_8_BASE
# 1.206 21-Jun-2020 dlg

start wg with the other interfaces that rely on routing being up.

from Matt Dunwoodie and Jason A. Donenfeld

ok deraadt@


# 1.205 22-May-2020 kn

Revert the following commit as it breaks hostname.if(5) lines with a
backslash at the end for line continuation

Breaking long lines into multiple ones must still be possible and does
require to treat the backslash as an escape character.

Breakage reported by Mark Patruck <mark at wrapped dot cx >, thanks!

---
distrib/miniroot/install.sub revision 1.1151
etc/netstart revision 1.203
date: 2020/05/21 11:54:41; author: kn; state: Exp; lines: +2 -2;
Do not treat backslashe as an escape character in hostname.if(5) lines

ifstart() should always pass such lines unaltered, especially if they
contain "nwid" or "description" lines with arbitrary strings.

<bsdlisten at gmail dot com> reported SSIDs such as "Mike's" during
installation end as broken; this was because the installer escaped
the single quote using backslashes which ended up being treated as
escape characters much later during hostname.if parsing in netstart(8).

Ok deraadt


# 1.204 21-May-2020 kn

Fix stripcom() description wrt. comments not on their own line

Neither netstart's nor install.sub's (subtly different) implementations
remove trailing comments on lines not starting as a comment, e.g.,
lines like "up #not down" go through unaltered and without "#not down"
being removed.

Only lines *beginning* with the comment sign ("#") are stripped.

No functional change, just updating function descriptions.


# 1.203 21-May-2020 kn

Do not treat backslashe as an escape character in hostname.if(5) lines

ifstart() should always pass such lines unaltered, especially if they
contain "nwid" or "description" lines with arbitrary strings.

<bsdlisten at gmail dot com> reported SSIDs such as "Mike's" during
installation end as broken; this was because the installer escaped
the single quote using backslashes which ended up being treated as
escape characters much later during hostname.if parsing in netstart(8).

Ok deraadt


Revision tags: OPENBSD_6_7_BASE
# 1.202 15-Jan-2020 kn

Do not redirect already quiet stdout for IPv6 reject routes

"route -q" already silences all standard output; if it still prints
something, that's a bug to fix in route.

OK bluhm


# 1.201 25-Oct-2019 dlg

handle aggr(4) in the same way as trunk(4)

from brad@
ok bluhm@ claudio@ deraadt@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.200 29-Aug-2018 krw

Historically /etc/netstart (and the equivalent code in the install
script) did 'ifconfig <if> down' before starting dhclient(8). This was
a way of ensuring old running copies of dhclient were killed before a
new one started. Current dhclient does not need this assist, so change
"ifconfig <if> down" to "ifconfig <if> up" pending further script
optimizations.

Similar to a 2014 attempt by halex@. Prompted by a misc@ report
from Kristjan Komlosi reporting hanging diskless setups.

ok halex@ kn@


# 1.199 08-Jul-2018 tb

netstart is used during system start, but also interactively.
Show proper error message if a regular user executes netstart.
Only do the privilege check if the id binary is available,
which might not be the case during diskless system startup.

ok deraadt, jasper, jca, krw, rpe (who wrote the same diff), sthen


# 1.198 28-Apr-2018 rpe

Add a proper usage() function.

Suggested by and OK jmc.
OK tb


Revision tags: OPENBSD_6_3_BASE
# 1.197 04-Mar-2018 jmc

when -n is used, no need to spit out "Missing parameters." before
displaying usage();

ok tb


# 1.196 03-Mar-2018 landry

Lowercase 'usage' and group -n with interface in it.
From jmc@, ok tb@


# 1.195 21-Feb-2018 rpe

Tweak comments.

OK tb


# 1.194 19-Feb-2018 rpe

Write warning/error messages to stderr and end them with a fullstop.

OK tb


# 1.193 19-Feb-2018 rpe

- use specific patterns when looping over /etc/hostname.if files
to skip backup or temp files.
- test if the patterns matched actual files
- warn if ifcreate() fails on an interface and continue with the
subsequent interfaces in the list instead of return'ing

OK dlg sthen tb


# 1.192 17-Feb-2018 rpe

- Add descriptions for the new functions ifcreate() and vifscreate()
- In ifcreate() use the exit code of the {} block directly
- In vifscreate(), use the ifconfig -C output directly in the for _vif loop
- Remove superfluous and somewhat confusing comment

OK dlg kn sthen


# 1.191 14-Feb-2018 dlg

create virtual interfaces before starting all interface config.

this resolves an ordering problem when adding pseudo interfaces to bridges

tweaks from kn@
ok mpi@ sthen@


# 1.190 10-Feb-2018 claudio

Remove some special IPv4 in IPv6 mapped prefixes that are already rejected
by the ::0.0.0.0/96 reject route added to deny all IPv4 mapped addresses.
Makes the inet6 routing table almost fit in one screen.
OK benno@


# 1.189 10-Feb-2018 florian

Load RFC 7217 key material and generate if it does not already exist.

Add soii.key to changelist (pointed out by semarie) and mtree/special
(suggest by Craig Skinner).

OK naddy, sthen, rpe, tb


# 1.188 06-Feb-2018 tb

If -n is given, the netstart script should not (try to) set the default
route(s). Simply print the command(s) to be issued instead.

tweak & ok rpe


# 1.187 12-Nov-2017 tb

Remove HN_DIR variable and expand it in the only place it was used. It
currently serves no purpose.

ok rpe, agreement from deraadt and halex


Revision tags: OPENBSD_6_2_BASE
# 1.186 25-Jul-2017 rpe

Finally remove backwards compat code to support the 'rtsol' keyword
in hostname.if(5)

OK mpi@ deraadt@ florian@
OK jmc@ from doc perspective


# 1.185 21-Jul-2017 rpe

Align ifstart() in netstart and install.sub.

- in netstart, rename _file to _hn referencing hostname.if files
- in install.sub switch ifstart() to be used with _if instead of
_hn as parameter

ok krw@ tb@


# 1.184 28-May-2017 awolk

etc/netstart: use colon separator instead of dot with chown

OK jung@, deraadt@, jmc@


# 1.183 07-May-2017 rpe

Change test from [] to [[]] and simplify pattern.

OK tb@, krw@ (for [[]])
Feedback and OK halex@


# 1.182 07-May-2017 rpe

Replace hardcoded script name with ${0##*/}

OK tb@ halex@


# 1.181 01-May-2017 rpe

Revert r1.170 and remove the id==0 check.
The id binary is not available in nfs diskless setups at this point.

reported by Andreas Kusalananda, thanks.
discussed with deraadt@


# 1.180 01-May-2017 rpe

Remove last remnants of rtsol. IPv6 autoconfiguration of interfaces is now
done in ifstart(). Remove ipv6autoconf() and replace rtsolif with a boolean
variable V6_AUTOCONF. Replace dhcpif with a boolean variable V4_DHCPCONF.
Both are later used in defaultroute() to decide whether or not to configre
defaultroutes from /etc/mygate.

OK krw@


# 1.179 30-Apr-2017 mpi

Do not try to delete a default route before adding it.

Now that route are automatically G/C with the address they are attached
to there's no reason to duplicate the kernel's job.

Fix a regression introduced with multipath default routes.

ok deraadt@


# 1.178 25-Apr-2017 rpe

Unbreak netstart for multiple inteface configurations like trunk
or carp. Ensure that the noglob option is disabled at the end of
parse_hn_line() and ifstart().

Reported by Christer Solskogen and Stefan Wollny, thanks!


# 1.177 24-Apr-2017 rpe

Introduce a new function parse_hn_line() that replaces the existing
hostname.if(5) parsing code in ifstart().
Add a -n option to netstart to only print the interface configuration
commands instead of executing them.
Add a HN_DIR variable, that points to the directory of the hostname.if
files (default /etc) that allows for future regression tests.

- add new parse_hn_line() function
- change ifstart()
- rename $if to $_if
- don't ifconfig or ifconfig create if -n option is used
- replace hostname.if(5) parsing code with new parse_hn_line()
- just print configuration commands if -n option is used
- autoconf now happens in ifstart(), remove ifv6autoconf()
- introduce HN_DIR variable for the hostname.if file location
- add handling of the -n option to only print config commands
- ensure -n is only used if interfaces are specified as parameters

Discussed with and positive feedback from many
'commit' deraadt@
OK sthen@


# 1.176 08-Apr-2017 rpe

- localize the if, file and stat variables which also ensures that
variables are not named like commands.
- change test from [] to [[]]

OK tb@ halex@


# 1.175 07-Apr-2017 rpe

Minimize differences in ifstart() function between netstart and
install.sub which makes it easier to spot changes in the future.

- comments and formatting
- quotes on assignments are not needed (netstart)
- remove stray space in test (netstart)
- use $file variable with while-loop (netstart)
- although valid, instead of i use $i in arithmetic test (install.sub)

OK krw@, tb@
Looks good deraadt@


# 1.174 07-Apr-2017 rpe

Align comments of ifstart() function in netstart and install.sub.


# 1.173 07-Apr-2017 rpe

Align comments of stripcom() function in netstart and install.sub.


Revision tags: OPENBSD_6_1_BASE
# 1.172 06-Dec-2016 mpi

Do not lose the default route when netstart(8) is run a second time on
the interface pointed to by the default route.

Since the kernel no longer keep routes with dangling address pointer,
netstart(8) has to re-add the default route when the corresponding ifa
has been deleted and re-created.

deraadt@ points out that even if the previous semantic was not necessarily
better, a script like netstart(8) cannot totally fix the default route
problem.

Regression reported by and fix tested by Hrvoje Popovski.

ksh foo checked by halex@


# 1.171 27-Sep-2016 rzalamena

Delay switch(4) interface start up so it can attach virtual interfaces
like vether(4).

nits from and ok benno@, phessler@


# 1.170 09-Sep-2016 jasper

print a clear error message when not ran as root instead of just falling
through and try whatever it can do with the invoking user's perms

feedback/ok aja@ rpe@


Revision tags: OPENBSD_6_0_BASE
# 1.169 19-Jul-2016 mpi

Do not consider tap(4) a special interface and start if before other
pseudo-interfaces.

This unbreak vlan(4) on top of tap(4) since the refactoring to turn it
MP-safe.

ok claudio@, deraadt@


# 1.168 27-Mar-2016 sthen

Don't delete the 224/4 route in netstart, unless it's being done to ensure that
a -reject route can be added. Restores the ability to set an interface route
before daemons are started, lost during the previous simplification.
ok millert mpi


Revision tags: OPENBSD_5_9_BASE
# 1.167 29-Dec-2015 rpe

Remove backslash, not necessary after '&&'

OK halex@


# 1.166 29-Dec-2015 rpe

Replace last remaining `` with $()

OK halex@


# 1.165 18-Dec-2015 ajacoutot

Drop the now useless multicast setup comment.

prodded by tim@, ok mpi@


# 1.164 17-Dec-2015 ajacoutot

Simplify multicast option handling (10 less lines) by matching /etc/rc behavior
towards other YES|NO options and drop the error warning.


with and ok tim@, ok rpe@ on an earlier diff


# 1.163 05-Dec-2015 mpi

It does not make sense to insert a specific route for 224/4 when the
default one is good enough.

So merge rc.conf(8)'s 'multicast_router' and 'multicast_host' into a
single 'multicast'. If set to YES the reject route for 224/4 is not
inserted by netstart(8).

Manual bits from jmc@

ok henning@, ajacoutot@


# 1.162 12-Nov-2015 rpe

Changes to ifautostart():
- Rename function to ifv6autoconf() to make IPv6 relation clearer
- Localize and rename variables

OK krw@


# 1.161 12-Nov-2015 rpe

Changes to ifmstart():
- Change comments to make it clearer that ifmstart() takes two lists
of interface driver names (of which the second is optional) and not
the actual interface instances.
- Use localized variables and use slightly more verbose names.
- Use continue 2 to skip to the next hostname.if file.
- Use shell pattern @() instead of testing _sif individually.

OK krw@


# 1.160 12-Nov-2015 rpe

Changes to stripcom():
- Align comments with /etc/rc version
- Use localized variables
- Use safer "print -r --" instead of plain echo

Changes to ifstart():
- Tweak comment
- Add usage

OK krw@


# 1.159 01-Nov-2015 rpe

Start the rework of the /etc/netstart shell script.

General changes:
- apply a similar 'style' as used in the installer scripts
- improve comments to be more to the point, remove where code is obvious
- document usage of functions if they have arguments
- rename variables where it improves readability
- replace really old-school shell code with more contemporary idioms

Other changes:
- No need to care about "autoboot" because netstart doesn't inherit the
positional parameters from /etc/rc anymore. /etc/rc executes netstart
instead of sourcing it since r1.439.
- Use simpler for-loop to process list of interfaces with ifstart.

OK halex@


# 1.158 26-Oct-2015 rpe

The hostname variable is not used since r1.99. Remove it and use
stripcom() output directly with the hostname command.

OK deraadt@ krw@


# 1.157 23-Oct-2015 claudio

netstart bits for tap(4)


# 1.156 27-Sep-2015 sthen

Don't print output when setting autoconf on interfaces. Suggested by deraadt,
ok florian@ rpe@


# 1.155 13-Sep-2015 sthen

only print the "IPv6 autoconf" line if there are interfaces to configure
feedback/ok rpe


# 1.154 11-Sep-2015 sthen

Set "inet6 autoconf" individually on interfaces that have rtsol set in
hostname.if, previously netstart tried to configure them all at once
("ifconfig if0 if1 if2 inet6 autoconf"). From Delan Azabani, ok phessler@


Revision tags: OPENBSD_5_8_BASE
# 1.153 20-Jul-2015 rpe

Disable Strict Bourne shell mode for /etc/rc and /etc/netstart to be
able to use ksh syntax within these scripts. This way init doesn't
need to be changed, which starts /etc/rc using /bin/sh and people
can still use "sh /etc/netstart ifname".

Idea from and OK halex@
OK deraadt@ krw@ guenther@


# 1.152 19-Jul-2015 florian

Bring up pflow last as it might send with a source address that is on
any of the other interfaces.
OK deraadt, phessler, benno


# 1.151 19-Jul-2015 rpe

Always source rc.subr to be able to use the rc.conf parsing routine
to get the network related vars from rc.conf. This is even necessary
if netstart is run from within /etc/rc. Remove test of $INRC which
unintentionally evaluated always to true.

problem with previous change found by nigel@
OK sthen@ aja@ halex@


# 1.150 19-Jul-2015 ajacoutot

Revert 1.148 for now until I can talk to rpe@
It introduced a regression reported by nigel@


# 1.149 19-Jul-2015 rpe

Replace test command with [].

OK halex@ krw@


# 1.148 19-Jul-2015 rpe

Ensure, that we source rc.subr and parse rc.conf ONLY if we are not
inside /etc/rc.

With help from and OK halex@, ajacoutot@


# 1.147 18-Jul-2015 rpe

- remove trailing blanks introduced in previous commit
- no space in redirections like </foo or >$bar
- few other minor whitespaces

OK krw@


# 1.146 18-Jul-2015 rpe

Improve comments
- Add comments for functions
- Start comments with capital letters
- End comments with a full stop
- Allow comments to extend up to column 80

OK krw@


# 1.145 06-Jun-2015 florian

Allow rtsol keyword in hostname.if(5) with net.inet6.ip6.forwarding=1.
"inet6 autoconf" was working before and rtsol should behave the same.
OK phessler


Revision tags: OPENBSD_5_7_BASE
# 1.144 03-Dec-2014 florian

The kernel handles rtsol(8) functionality since some time now.
Treat rtsol in hostname.if as a keyword like dhcp and call ifconfig
inet6 autoconf.
"reads good" todd@
OK krw@ (who is *not* an IPv6 person), but I recruited him in his
capacity as an installer person.


# 1.143 28-Sep-2014 claudio

Revert 1.142. Without the down netstart will just print the ifconfig
output because it may end up just calling 'ifconfig $if'. This needs
to be done better and properly tested.


# 1.142 26-Sep-2014 halex

remove explicit 'down' of an interface before starting a dhcp request, thereby
avoiding annoying delays for some switch configurations

ok claudio@ deraadt@

i would add ok phessler@, but it was not valid without an ok krw@


Revision tags: OPENBSD_5_6_BASE
# 1.141 12-Jul-2014 stsp

Fix netstart after autoconf6 change so 'rtsol' lines in hostname.if work again.
found by pelikan@; ok pelikan@ henning@


# 1.140 12-Jul-2014 robert

Make rc.conf a parsed configuration file and stop sourcing it as a shell
script.
From now on rc.conf has a fixed syntax (key=val) and it is not allowed
to add anything to it besides the supported syntax, it all going to be
ignored.

discussed with and help from deraadt@ and halex@


Revision tags: OPENBSD_5_5_BASE
# 1.139 22-Aug-2013 mpi

Like for dhclient, do no create a route to alias addresses via 127.0.0.1.
Our stack is able to tell if the address is local or not.

ok todd@, krw@


Revision tags: OPENBSD_5_4_BASE
# 1.138 20-Mar-2013 todd

fix lies in netstart; replacement wording from halex@
pointed out by Ryan Kavannagh rak at debian dot org


Revision tags: OPENBSD_5_3_BASE
# 1.137 05-Dec-2012 rpe

remove "Invalid interface name" message
requested by krw@

ok halex@


# 1.136 02-Dec-2012 rpe

use the more compact version of the check for ifconfig'able interfaces
from install.sub

with feedback from and ok halex


# 1.135 02-Dec-2012 rpe

- remove isalphanumeric() and replace it with a shell pattern, that
tries a bit harder to identify invalid interface names and in
this case emit an error message.
- use [[ $1 == autoboot ]] to avoid a shell error message due to
possible spaces in first argument
- no change in functionality

discussed with krw and halex
ok ("I like this") krw


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.134 07-Oct-2011 deraadt

The new ypbind changes requires that the domainname be set before
rc.conf is run. There's no real downside.
ok aja


Revision tags: OPENBSD_5_0_BASE
# 1.133 07-Jul-2011 guenther

Eliminate some $? tests by rolling the command into the condition

ok halex@


# 1.132 26-May-2011 mpf

Add svlan(4) startup bits.
From markus@. OK naddy, claudio, reyk.


Revision tags: OPENBSD_4_9_BASE
# 1.131 09-Feb-2011 sobrado

fix an unbalanced parenthesis in a comment; while here, split the comment
in a better place to make it more readable.

ok jmc@ and miod@


Revision tags: OPENBSD_4_8_BASE
# 1.130 16-Jun-2010 todd

permit e.g. -inet6 syntax by slurping all lines not just some
noticed by rhsv6 at hushmail dot com, ok sthen@


Revision tags: OPENBSD_4_7_BASE
# 1.129 12-Jan-2010 henning

when setting up lo0 use 127.0.0.1/8 instead of 127.0.0.1 for clarity and
correctness. it's not 1992 any more, kids. ok mcbride dlg krw


# 1.128 10-Dec-2009 todd

o stop reordering ifconfig arguments (e.g. after 'up ..')
o only stop processing if inet or inet6 lines are malformed
o everything not a specially handled bit is passed to ifconfig unmangled
noticed by several after the move from bridgename.bridge0 -> hostname.bridge0
prodded by deraadt@, tested by and feedback from several
man page bits 'look fine' jmc@


# 1.127 22-Nov-2009 deraadt

Stop supporting bridgename.bridge* files, and move to hostname.bridge*
files. To cope with this change, read about the mv command.
ok claudio todd


# 1.126 17-Sep-2009 simon

change variable i to $i in an expression of ifstart() for consistency
with the rest of the file. no functional change.

feedback from sthen@, ok krw@


# 1.125 10-Jul-2009 jdixon

Delay creation of tun(4) interfaces until the underlying interface and
routes are available. This fixes usage for some OpenVPN users that start
it from hostname.tun*.

Tested by Johan Huldtgren. ok sthen@, johan@.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.124 25-Nov-2008 markus

delay /etc/netstart until IPv6-DAD (dup-address-detection) is completed.
ok fries, hshoexer, claudio


# 1.123 14-Aug-2008 sthen

Tools from /usr may not be used in netstart since it may be NFS-mounted
and not available at that time. Rewrite the hostname.if permission check
to use only /bin/ls and the shell. Requested by deraadt.

ok todd, "Twisted." deraadt


Revision tags: OPENBSD_4_4_BASE
# 1.122 23-Jul-2008 sthen

Prevent warning about insecure hostnames where no /etc/hostname.*
exists. From wcmaier@.

Check target of symbolic links to avoid noise at boot and in
seucrity output where you have several interfaces symlinked to one
config file.

"If you think this is the right thing to do" deraadt@


# 1.121 09-Jun-2008 todd

warn once not 3 times in case of a non existent file, discussed with deraadt
originally pointed out by Johan Torin


# 1.120 09-Jun-2008 deraadt

Ensure that hostname.* files are also re-chowned to root.wheel at each
boot as discussed with claudio while eating tasty donairs. ok todd


# 1.119 17-Apr-2008 deraadt

before using them, force hostname.* files to be unreadable by world
first version from todd, ok millert


Revision tags: OPENBSD_4_3_BASE
# 1.118 17-Jan-2008 brad

Execute rtsol after turning up trunk(4) and vlan(4) interfaces so they're
taken into consideration for rtsol.

ok reyk@ dlg@


# 1.117 09-Jan-2008 mpf

Do not bring up pfsync(4) before the working ruleset
has been loaded. Otherwise, states that are received during the
initial bulk update mismatch the correct pf-checksum and
do not attach to the rules.
Problem identified by david@. Fix done in collaboration.
OK henning@


Revision tags: OPENBSD_4_2_BASE
# 1.116 02-Aug-2007 david

move the delay for IPv6 DAD to after all interfaces have started
fixes problems with daemons being unable to bind to all addreses at boot
ok itojun@ hshoexer@


Revision tags: OPENBSD_4_1_BASE
# 1.115 15-Nov-2006 itojun

reject multicast packet without scope identifier specified.


Revision tags: OPENBSD_4_0_BASE
# 1.114 29-Jun-2006 todd

do not add an extra space; nwid and description come out wrong
fix as proposed by maja@, thanks!


Revision tags: OPENBSD_3_9_BASE
# 1.113 28-Dec-2005 david

nuke extra whitespace


# 1.112 06-Dec-2005 reyk

multicast_host=YES only works if a valid default gateway is available.
validate this condition and reject multicast traffic on failure.

ok todd@ naddy@


# 1.111 02-Nov-2005 todd

fix inspired by pr#4590
ok krw@


# 1.110 25-Oct-2005 todd

better logic from krw@:
- do not process mygate for v4 if dhcp
- do not process mygate for v6 if rtsol
this also makes the mygate processing logic more readable
ok krw@


# 1.109 14-Oct-2005 todd

add v6 support for /etc/mygate
ok deraadt@ mickey@ krw@
same functionality tested/ok'ed by by mickey, brad, matthieu, and me
with this one may now put a v6 IP in /etc/mygate on a separate line from
the v4 default gateway and netstart will do the right thing


# 1.108 12-Oct-2005 todd

shrink stripcom(), sync with install.sub
ok krw@


# 1.107 04-Oct-2005 todd

trunk must be started after physical ethernet devices, but before vlan.
populate ifmstart lines accordingly.
prodded/tested by brad@
ok reyk@


# 1.106 28-Sep-2005 todd

use eval consistently, fixes description quotes on rtsol and dhcp
fix inspired by and closes pr 4495
ok krw@


Revision tags: OPENBSD_3_8_BASE
# 1.105 22-May-2005 todd

Introduce 'ifmstart' to deal with starting multiple interfaces minus a list
of interfaces.

This reduces the netstart script by 174 chars, 13 words, and 19 lines, but
more importantly, makes it more simple and less cluttered should more special
case/orderings be needed.

ok brad@ and pr 4197 submitter, inspired by and closes pr 4197


# 1.104 04-Apr-2005 djm

unbreak; ok pval@


# 1.103 03-Apr-2005 deraadt

if dhcp is used to get an address on any interface, ignore /etc/mygate
ok krw
(this lets us do something rather cool with the zaurus in particular)


Revision tags: OPENBSD_3_7_BASE
# 1.102 04-Jan-2005 mcbride

Bring up the carp(4) interface before default route.

ok pascoe@ mpf@


# 1.101 30-Dec-2004 millert

Add a copy of stripcom so /etc/netstart can be run standalone again.
OK deraadt@


# 1.100 19-Dec-2004 millert

Allow comments in /etc/{myname,mygate,defaultdomain}; OK deraadt@


# 1.99 04-Dec-2004 itojun

remove "route $hostname 127.0.0.1" line. deraadt ok
*** please update /etc/netstart and test if it works ok for you ***


# 1.98 20-Oct-2004 deraadt

make all route commands use -qn; ok mcbride henning


Revision tags: OPENBSD_3_6_BASE
# 1.97 29-May-2004 deraadt

one last route command lacking -qn


Revision tags: OPENBSD_3_5_BASE
# 1.96 22-Mar-2004 mcbride

Make sure pfsync is brought up before carp.

ok deraadt@


# 1.95 13-Mar-2004 mcbride

Delay pfsync(4) configuration, as the syncif has to be configured in
advance. From Thorsten Lockert.


# 1.94 14-Jan-2004 deraadt

ok, it took quite a bit of prodding but itojun finally explained why the
extra sleep 1 is in here, and we came to the conclusion it is safe to
delete it. whee.


# 1.93 13-Jan-2004 deraadt

repair v6 lo0 documentation


# 1.92 11-Jan-2004 deraadt

add loopback routes late


# 1.91 09-Jan-2004 deraadt

create all routes with -q; markus ok


# 1.90 04-Dec-2003 millert

Need to do "ifconfig create" for bridge interfaces too.


# 1.89 03-Dec-2003 markus

add support for ifconfig clone; from netbsd; ok deraadt, henning


# 1.88 20-Oct-2003 david

delay carp initialization until after physical interfaces are configured
ok mcbride@ henning@ deraadt@ todd@


Revision tags: OPENBSD_3_4_BASE
# 1.87 27-Aug-2003 henning

only try to set hostname to what /etc/myname says if that file actually exists,
otherwise preserve `hostname`
netbooted machines can live perfectly fine without it; they get their hostname
earlier.

ok krw@ cedric@


Revision tags: OPENBSD_3_3_BASE
# 1.86 16-Feb-2003 krw

Fix up some DNS verbiage to make it consistant.

Fix up default route selection by

a) Forcing user to explicitly chose 'dhcp' as a mechanism for
specifying a default route, rather than guessing based on one or more
interfaces being configured by dhcp.

b) If the user specified default route does not work, re-present the
existing default route rather than losing it.

c) Move default route selection to after nameserver activation so the
user can specify a hostname as the default route.

Change /etc/netstart so that /etc/mygate wins if a default route was
already specified (i.e. by dhcp).

ok deraadt@.


Revision tags: OPENBSD_3_2_BASE
# 1.85 16-May-2002 todd

ignore non-existent cases where '$if' evaluates to '*'.
From Andr� Lucas <andre@ae-35.com>, fixes pr # 2658.
'Looks good' from miod@, millert@, and krw@.


Revision tags: OPENBSD_3_1_BASE
# 1.84 23-Feb-2002 deraadt

re-add support for $if expansion; hamajima@nagoya.ydc.co.jp


# 1.83 21-Feb-2002 miod

Change the network components initialization order.
Change from:
o all interfaces
o all bridges
o routes
to:
o physical interfaces
o routes
o gif and gre interfaces
o bridges

Fixeski PR #2400.
Manual page updates coming soon.
Ok angelos@ chris@ deraadt@


Revision tags: OPENBSD_3_0_BASE
# 1.82 31-Jul-2001 hugh

a space before a redirect


# 1.81 06-Jul-2001 angelos

Also, source /etc/rc.conf so we can pull in the
multicast_host/multicast_router settings; this is useful if one
flushes the routing table and re-initializes.

We really need a netconfig tool of sorts.


# 1.80 06-Jul-2001 angelos

Use "route -n show -inet" to determine the default multicast iface.


# 1.79 03-Jul-2001 deraadt

pull in rc.conf early so that pf(1) startup is right; tested by jasoni, comments from millert


# 1.78 30-May-2001 deraadt

Remove ipf. Darren Reed has interpreted his (old, new, whichever)
licence in a way that makes ipf not free according to the rules we
established over 5 years ago, at www.openbsd.org/goals.html (and those
same basic rules govern the other *BSD projects too). Specifically,
Darren says that modified versions are not permitted. But software
which OpenBSD uses and redistributes must be free to all (be they
people or companies), for any purpose they wish to use it, including
modification, use, peeing on, or even integration into baby mulching
machines or atomic bombs to be dropped on Australia. Furthermore, we
know of a number of companies using ipf with modification like us, who
are now in the same situation, and we hope that some of them will work
with us to fill this gap that now exists in OpenBSD (temporarily, we
hope).


Revision tags: OPENBSD_2_9_BASE
# 1.77 13-Mar-2001 deraadt

spelling; maurice@maurice.wan.nl


# 1.76 06-Feb-2001 todd

ignore blank lines in addition to comments
fixes pr#1660 from wilfried@telia.com .. Thanks!


# 1.75 10-Jan-2001 jason

support !command in bridgename.if files, too


# 1.74 27-Nov-2000 millert

Use -n to test if a variable is non-zero. Otherwise, if the variable's
contents start with a '-' test becomes unhappy (since it interprets it
as another option).


# 1.73 08-Nov-2000 todd

This fixes pr 1481, we now handle args > 6 in /etc/hostname.if in the
cases where we did not previously handle them.
Thanks to Scott Atwood <atwood@cs.stanford.edu> for reminding us of this.


Revision tags: OPENBSD_2_8_BASE
# 1.72 02-Sep-2000 todd

subtle bug .. global variables in a while loop need reset 'just incase'
With:
hostname.fxp0 having a last line of:
inet6 alias 3ffe:...
and hostname.gif0 having a first two lines of:
giftunnel 1.2.3.4
dest 1.2.4.3
We end up with the command:
ifconfig gif0 giftunnel alias 1.2.3.4 1.2.4.3
.. which is clearly wrong and fixed by this change


# 1.71 18-Jun-2000 todd

rc.conf now parses ${local_rcconf} internally; closes pr 1259


Revision tags: OPENBSD_2_7_BASE
# 1.70 08-May-2000 todd

fix dhcp 'NONE' ness from install to allow media parsing to work
.. ok deraadt@, millert@


# 1.69 21-Apr-2000 deraadt

rc.conf.local support, inspired by chuck yerkes


# 1.68 04-Apr-2000 millert

Remove the -E flag from ipf as it is implicitly enabled and using
the -E flag here causes the kernel to printf 'IP Filter: already
initialized'.


# 1.67 18-Mar-2000 deraadt

silence all extra route addition printouts


# 1.66 17-Mar-2000 itojun

correct reject route installations for IPv6. improve comments.


# 1.65 12-Mar-2000 itojun

disallow packets to malicious 6to4 prefix, based on
http://playground.iijlab.net/i-d/draft-itojun-ipv6-transition-abuse-00.txt


# 1.64 10-Mar-2000 todd

fix non behavior
with this `!' lines in /etc/hostname.* run even without certain lines
(like a comment) preceeding it.


# 1.63 10-Jan-2000 todd

allow arbitrary commands in /etc/hostname.* files if the line starts with '!'


# 1.62 02-Jan-2000 deraadt

rtsol case can configure the interface up, since it would be nice to finish
DAD before the actual rtsol(8) run happens later. and since it will rtsol,
it is going to be up in any case.


# 1.61 02-Jan-2000 itojun

one more indentation fix.


# 1.60 02-Jan-2000 itojun

indentation fix (todd's part)


# 1.59 02-Jan-2000 todd

fix rtsold case, reset cmd for each iteration!


# 1.58 02-Jan-2000 itojun

allow options after "rtsol".
XXX both "dhcp" and "rtsol" has keyword *down* at the end. is it okay?


# 1.57 02-Jan-2000 itojun

echo "IPv6 autoconf: interfaces" before invoking rtsol.
sleep for net.inet6.ip6.dad_count seconds to ensure that IPv6 DAD is completed.
TODO: rtsold (rc.conf line), manpage


# 1.56 02-Jan-2000 itojun

ipv6 autoconf on hosts (non-routers).

to do this,
1. in sysctl.conf, add these lines:
net.inet6.ip6.forwarding=0
net.inet6.ip6.accept_rtadv=1
2. in hostname.foo, add
rtsol

specifying two or more interfaces with "rtsol" may result in strange
behavior - ipv6 spec does not permit multi-interface node to be autoconfig'ed.


# 1.55 02-Jan-2000 todd

add to hostname.* parsing:
- multiple entries support (read: aliases)
- inet6 support
- support for comments (#)
(look for hostname.if(5) commit for syntax details)


# 1.54 31-Dec-1999 itojun

install IPv6 reject routes only if kernel is capable of IPv6.


# 1.53 09-Dec-1999 itojun

avoid transmitting invalid IPv6 packets out to the wire.


# 1.52 09-Dec-1999 itojun

do not perform IPv6 initialization for loopback interface.
MUST make lo0 up before any IPv6 operations.
it will be considered a pilot error if you don't.
(I prefer to have lo0 initialized automatically)


Revision tags: OPENBSD_2_6_BASE
# 1.51 01-Sep-1999 deraadt

support # characters in bridgename.* files; millert


# 1.50 01-Sep-1999 deraadt

cleanup parsing of hostname.* files, and seperate bridge control into
bridgename.* files; all documented in new hostname.if(5) and
bridgename.if(5) man pages


# 1.49 09-Aug-1999 angelos

Only parse/setup the hostname.foo file if interface foo exists (this
is useful for laptops with different ethernet cards etc.)


Revision tags: OPENBSD_2_5_BASE
# 1.48 29-Mar-1999 niklas

New multicast route setup style


# 1.47 26-Mar-1999 niklas

Add bridge interface handling


# 1.46 01-Mar-1999 millert

Add support in /etc/hostname.xxx for files of the format:
up [options]
Any of the following may or may not be set:
$name $mask $bcaddr $extras


# 1.45 28-Oct-1998 millert

Kill the awful hack used to match and split /etc/hostname.* We now use
a function, isalphanumeric, to determine whether an interface name is
likely to be valid. This means that things like /etc/hostname.le0.bak,
/etc/hostname.le0#, /etc/hostname.le0~, etc. will be ignored as they
should. There is no longer an implicate assumption that /etc/hostname.*
only contains a single '.'.


Revision tags: OPENBSD_2_4_BASE
# 1.44 06-Oct-1998 deraadt

move ipnat to end of netstart, to support dhcp+ipnat


# 1.43 18-Sep-1998 deraadt

apply media directives on dhcp interfaces


# 1.42 10-Sep-1998 marc

better way of handling dhcp client; Jason Ish <jbi130@mail.usask.ca>


# 1.41 08-Sep-1998 marc

dhcp client stuff. "Angelos D. Keromytis" <angelos@dsl.cis.upenn.edu>


# 1.40 24-Aug-1998 downsj

You can't use -interface default when there's no default gateway
set (yet). Use -interface $hostname if mygate doesn't exist so that
this actually works on routers.


# 1.39 04-Jul-1998 deraadt

put 224 route on default, to avoid a hostname lookup


# 1.38 22-May-1998 deraadt

use route -n, what the heck


Revision tags: OPENBSD_2_3_BASE
# 1.37 28-Mar-1998 deraadt

s/^nat/ipnat/


# 1.36 23-Feb-1998 niklas

remove trailing blank line


# 1.35 07-Feb-1998 deraadt

ipforward is in sysctl.conf now


# 1.34 21-Dec-1997 deraadt

ugh


# 1.33 20-Dec-1997 deraadt

ipforwarding option in rc.conf


# 1.32 29-Nov-1997 kstailey

NAT requires IPF


# 1.31 04-Nov-1997 deraadt

kill spaces at ends of lines; m4


Revision tags: OPENBSD_2_2_BASE
# 1.30 14-Oct-1997 deraadt

set hostname/domainname before running rc.conf; m4@umn.edu


# 1.29 04-Sep-1997 deraadt

fork netstart; new child is rc.conf


# 1.28 25-Aug-1997 millert

Explicately pass -host flag to route(8) to avoid confusion with networks.


# 1.27 19-Aug-1997 niklas

Add hook for rpc.lockd, make nfsd flags settable in netstart


# 1.26 31-Jul-1997 downsj

Make quotas optional; wedged into netstart for the time being.
/etc/rc.conf, anyone?


# 1.25 30-Jul-1997 deraadt

do not run routed by default


# 1.24 28-Jul-1997 kstailey

Move configuration of loopback interface to before all other interfaces.
Allows the use of local caching-only nameserver with no "nameserver"
entry in /etc/resolv.conf to configure a route between the hostname
and loopback.


# 1.23 25-Jul-1997 provos

earlier start of keymanagement


# 1.22 24-Jul-1997 deraadt

make amd use /tmp_mnt by default


# 1.21 22-Jul-1997 provos

start the photuris daemon per default. hilfe.


# 1.20 17-Jun-1997 niklas

Put in hooks to start ypserv with flags


# 1.19 17-Jun-1997 niklas

Put in hooks to start rpc.yppasswdd with flags


Revision tags: OPENBSD_2_1_BASE
# 1.18 15-Apr-1997 deraadt

kill route flush until .. hmm kernel routing socket bug or something


# 1.17 09-Apr-1997 kstailey

add NAT startup


# 1.16 07-Apr-1997 rees

flush all old routes before adding new interfaces or routes.
ref: netbsd pr3228/misc, Matthias Scheler


# 1.15 03-Mar-1997 downsj

fix typo


# 1.14 11-Feb-1997 deraadt

add default route before fiddling with loopback route to avoid DNS problems; m4@umn.edu, #97


# 1.13 03-Feb-1997 deraadt

do ifaliases after /usr/bin exists in nfs diskless env; pr#77, matthieu@laas.fr


# 1.12 02-Nov-1996 deraadt

timed off by default


Revision tags: OPENBSD_2_0_BASE
# 1.11 23-Sep-1996 deraadt

rfc1323 variable


# 1.10 04-Sep-1996 deraadt

control portmap, inetd, and lpd from netstart; idea from tqbf@enteract.com


# 1.9 27-Aug-1996 deraadt

224.0.0.0 not 0.0.0.224; from peter@demon.net


# 1.8 18-Jun-1996 deraadt

move std stuff from rc.local to rc


# 1.7 16-Jun-1996 deraadt

install sample commented /etc/ifaliases file; which can now contain #
comments and blank lines. new format is "interface address netmask"
(yes, i changed the order of the entries). inspired by netbsd pr#2474;
gillhaa@ghost.whirlpool.com


# 1.6 02-Jun-1996 tholo

Install a multicast route by default


# 1.5 26-May-1996 deraadt

sync & label


# 1.4 09-Jan-1996 dm

added IP filter to netstat/rc and put examples in /usr/share/ipf


# 1.3 30-Dec-1995 deraadt

from netbsd: start mrouted like routed


# 1.2 18-Dec-1995 deraadt

/etc/ifaliases support by randy@zyzzyva.com


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.220 21-Oct-2022 kn

Fix synopsis, -n does not require an interface; OK jmc


Revision tags: OPENBSD_7_2_BASE
# 1.219 03-Jul-2022 kn

Create virtual interfaces upfront if specified on the command line

In cases like `sh /etc/netstart pair1 pair2', one of hostname.pair{1,2}
will contain a "patch pair{2,1}" command which expects the other interface
to exist.

If none exist, this would fail and netstart had to be run separately or
"patch"ed interface had to be manually created before.

There are other use cases where interfaces depend on each other, so before
(re)configuring an explicit list of interfaces, create all virtual ones
upfront so that a single netstart invocation will configure everything
correctly without having reflect dependencies in multiple ordered netstart
invocations.

Copy isin() from install.sub to help.

Feedback OK halex


# 1.218 26-Jun-2022 florian

Wait for autoconf interfaces to come up in netstart(8) instead of
rc(8). This makes tunnel interfaces work that depend on working
autoconf interfaces.
OK deraadt


Revision tags: OPENBSD_7_1_BASE
# 1.217 22-Feb-2022 dlg

add some more tunnels to the list of interfaces that rely on routing.


Revision tags: OPENBSD_7_0_BASE
# 1.216 02-Sep-2021 bluhm

Do not create loopback interfaces lo1, lo2, ... upfront. They are
automatically set up by the kernel when a routing domain is created.
An existing lo1 in rdomain 0 would prevent to add any interfaces
in rdomain 1.
OK kn@


# 1.215 30-Aug-2021 bluhm

Improve dubgging in /etc/netstart. Enable print only in ifcreate.
Add debugging output for ipv6 routes. Make localhost and multicast
code aware of the print only switch. Allow netstart -n to work
also if no interface is given.
OK kn@


# 1.214 06-Aug-2021 sthen

As tim@ spotted, a use of V4_AUTOCONF crept in when the variable name
was actually V4_DHCPCONF from previous use. Rename all of the V4_DHCPCONF
to V4_AUTOCONF so everything uses the new name. ok and reminder about
the installer from tb@


# 1.213 16-Jul-2021 florian

switch to dhcpleased/resolvd in base
OK deraadt


# 1.212 20-Jun-2021 florian

Don't try to install a default route with route(8) later on if we are
using inet autoconf, like we do with "dhcp" and "inet6 autoconf".
OK kn


Revision tags: OPENBSD_6_9_BASE
# 1.211 23-Dec-2020 krw

Allow the provision of dhclient(8) options on 'dhcp' lines in hostname.if(5)
files.

Usual man page help & ok jmc@


# 1.210 21-Dec-2020 krw

Avoid issuing pointless 'ifconfig <if> up' when processing 'dhcp' in
hostname.if files. dhclient(8) does that itself. Part of the
"further script optimizations" promised in r1.200 of netstart.

Tested & ok gnezdo@


# 1.209 29-Nov-2020 tb

Fix previous: use correct version of netstart and installer bits.


# 1.208 29-Nov-2020 deraadt

Add support for !command to mygate, so that netstart has a late opportunity
to perform network configuration (for example, "!route source -ifp em0")
Split mygate and myname manual pages (how did anyone ever believe these
are related), and perform hostname configuration much earlier in rc.
discussed with benno, claudio, jmc, etc etc, last version of !command
parser by tb


# 1.207 08-Nov-2020 jmc

no more mobileip;
ok claudio deraadt


Revision tags: OPENBSD_6_8_BASE
# 1.206 21-Jun-2020 dlg

start wg with the other interfaces that rely on routing being up.

from Matt Dunwoodie and Jason A. Donenfeld

ok deraadt@


# 1.205 22-May-2020 kn

Revert the following commit as it breaks hostname.if(5) lines with a
backslash at the end for line continuation

Breaking long lines into multiple ones must still be possible and does
require to treat the backslash as an escape character.

Breakage reported by Mark Patruck <mark at wrapped dot cx >, thanks!

---
distrib/miniroot/install.sub revision 1.1151
etc/netstart revision 1.203
date: 2020/05/21 11:54:41; author: kn; state: Exp; lines: +2 -2;
Do not treat backslashe as an escape character in hostname.if(5) lines

ifstart() should always pass such lines unaltered, especially if they
contain "nwid" or "description" lines with arbitrary strings.

<bsdlisten at gmail dot com> reported SSIDs such as "Mike's" during
installation end as broken; this was because the installer escaped
the single quote using backslashes which ended up being treated as
escape characters much later during hostname.if parsing in netstart(8).

Ok deraadt


# 1.204 21-May-2020 kn

Fix stripcom() description wrt. comments not on their own line

Neither netstart's nor install.sub's (subtly different) implementations
remove trailing comments on lines not starting as a comment, e.g.,
lines like "up #not down" go through unaltered and without "#not down"
being removed.

Only lines *beginning* with the comment sign ("#") are stripped.

No functional change, just updating function descriptions.


# 1.203 21-May-2020 kn

Do not treat backslashe as an escape character in hostname.if(5) lines

ifstart() should always pass such lines unaltered, especially if they
contain "nwid" or "description" lines with arbitrary strings.

<bsdlisten at gmail dot com> reported SSIDs such as "Mike's" during
installation end as broken; this was because the installer escaped
the single quote using backslashes which ended up being treated as
escape characters much later during hostname.if parsing in netstart(8).

Ok deraadt


Revision tags: OPENBSD_6_7_BASE
# 1.202 15-Jan-2020 kn

Do not redirect already quiet stdout for IPv6 reject routes

"route -q" already silences all standard output; if it still prints
something, that's a bug to fix in route.

OK bluhm


# 1.201 25-Oct-2019 dlg

handle aggr(4) in the same way as trunk(4)

from brad@
ok bluhm@ claudio@ deraadt@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.200 29-Aug-2018 krw

Historically /etc/netstart (and the equivalent code in the install
script) did 'ifconfig <if> down' before starting dhclient(8). This was
a way of ensuring old running copies of dhclient were killed before a
new one started. Current dhclient does not need this assist, so change
"ifconfig <if> down" to "ifconfig <if> up" pending further script
optimizations.

Similar to a 2014 attempt by halex@. Prompted by a misc@ report
from Kristjan Komlosi reporting hanging diskless setups.

ok halex@ kn@


# 1.199 08-Jul-2018 tb

netstart is used during system start, but also interactively.
Show proper error message if a regular user executes netstart.
Only do the privilege check if the id binary is available,
which might not be the case during diskless system startup.

ok deraadt, jasper, jca, krw, rpe (who wrote the same diff), sthen


# 1.198 28-Apr-2018 rpe

Add a proper usage() function.

Suggested by and OK jmc.
OK tb


Revision tags: OPENBSD_6_3_BASE
# 1.197 04-Mar-2018 jmc

when -n is used, no need to spit out "Missing parameters." before
displaying usage();

ok tb


# 1.196 03-Mar-2018 landry

Lowercase 'usage' and group -n with interface in it.
From jmc@, ok tb@


# 1.195 21-Feb-2018 rpe

Tweak comments.

OK tb


# 1.194 19-Feb-2018 rpe

Write warning/error messages to stderr and end them with a fullstop.

OK tb


# 1.193 19-Feb-2018 rpe

- use specific patterns when looping over /etc/hostname.if files
to skip backup or temp files.
- test if the patterns matched actual files
- warn if ifcreate() fails on an interface and continue with the
subsequent interfaces in the list instead of return'ing

OK dlg sthen tb


# 1.192 17-Feb-2018 rpe

- Add descriptions for the new functions ifcreate() and vifscreate()
- In ifcreate() use the exit code of the {} block directly
- In vifscreate(), use the ifconfig -C output directly in the for _vif loop
- Remove superfluous and somewhat confusing comment

OK dlg kn sthen


# 1.191 14-Feb-2018 dlg

create virtual interfaces before starting all interface config.

this resolves an ordering problem when adding pseudo interfaces to bridges

tweaks from kn@
ok mpi@ sthen@


# 1.190 10-Feb-2018 claudio

Remove some special IPv4 in IPv6 mapped prefixes that are already rejected
by the ::0.0.0.0/96 reject route added to deny all IPv4 mapped addresses.
Makes the inet6 routing table almost fit in one screen.
OK benno@


# 1.189 10-Feb-2018 florian

Load RFC 7217 key material and generate if it does not already exist.

Add soii.key to changelist (pointed out by semarie) and mtree/special
(suggest by Craig Skinner).

OK naddy, sthen, rpe, tb


# 1.188 06-Feb-2018 tb

If -n is given, the netstart script should not (try to) set the default
route(s). Simply print the command(s) to be issued instead.

tweak & ok rpe


# 1.187 12-Nov-2017 tb

Remove HN_DIR variable and expand it in the only place it was used. It
currently serves no purpose.

ok rpe, agreement from deraadt and halex


Revision tags: OPENBSD_6_2_BASE
# 1.186 25-Jul-2017 rpe

Finally remove backwards compat code to support the 'rtsol' keyword
in hostname.if(5)

OK mpi@ deraadt@ florian@
OK jmc@ from doc perspective


# 1.185 21-Jul-2017 rpe

Align ifstart() in netstart and install.sub.

- in netstart, rename _file to _hn referencing hostname.if files
- in install.sub switch ifstart() to be used with _if instead of
_hn as parameter

ok krw@ tb@


# 1.184 28-May-2017 awolk

etc/netstart: use colon separator instead of dot with chown

OK jung@, deraadt@, jmc@


# 1.183 07-May-2017 rpe

Change test from [] to [[]] and simplify pattern.

OK tb@, krw@ (for [[]])
Feedback and OK halex@


# 1.182 07-May-2017 rpe

Replace hardcoded script name with ${0##*/}

OK tb@ halex@


# 1.181 01-May-2017 rpe

Revert r1.170 and remove the id==0 check.
The id binary is not available in nfs diskless setups at this point.

reported by Andreas Kusalananda, thanks.
discussed with deraadt@


# 1.180 01-May-2017 rpe

Remove last remnants of rtsol. IPv6 autoconfiguration of interfaces is now
done in ifstart(). Remove ipv6autoconf() and replace rtsolif with a boolean
variable V6_AUTOCONF. Replace dhcpif with a boolean variable V4_DHCPCONF.
Both are later used in defaultroute() to decide whether or not to configre
defaultroutes from /etc/mygate.

OK krw@


# 1.179 30-Apr-2017 mpi

Do not try to delete a default route before adding it.

Now that route are automatically G/C with the address they are attached
to there's no reason to duplicate the kernel's job.

Fix a regression introduced with multipath default routes.

ok deraadt@


# 1.178 25-Apr-2017 rpe

Unbreak netstart for multiple inteface configurations like trunk
or carp. Ensure that the noglob option is disabled at the end of
parse_hn_line() and ifstart().

Reported by Christer Solskogen and Stefan Wollny, thanks!


# 1.177 24-Apr-2017 rpe

Introduce a new function parse_hn_line() that replaces the existing
hostname.if(5) parsing code in ifstart().
Add a -n option to netstart to only print the interface configuration
commands instead of executing them.
Add a HN_DIR variable, that points to the directory of the hostname.if
files (default /etc) that allows for future regression tests.

- add new parse_hn_line() function
- change ifstart()
- rename $if to $_if
- don't ifconfig or ifconfig create if -n option is used
- replace hostname.if(5) parsing code with new parse_hn_line()
- just print configuration commands if -n option is used
- autoconf now happens in ifstart(), remove ifv6autoconf()
- introduce HN_DIR variable for the hostname.if file location
- add handling of the -n option to only print config commands
- ensure -n is only used if interfaces are specified as parameters

Discussed with and positive feedback from many
'commit' deraadt@
OK sthen@


# 1.176 08-Apr-2017 rpe

- localize the if, file and stat variables which also ensures that
variables are not named like commands.
- change test from [] to [[]]

OK tb@ halex@


# 1.175 07-Apr-2017 rpe

Minimize differences in ifstart() function between netstart and
install.sub which makes it easier to spot changes in the future.

- comments and formatting
- quotes on assignments are not needed (netstart)
- remove stray space in test (netstart)
- use $file variable with while-loop (netstart)
- although valid, instead of i use $i in arithmetic test (install.sub)

OK krw@, tb@
Looks good deraadt@


# 1.174 07-Apr-2017 rpe

Align comments of ifstart() function in netstart and install.sub.


# 1.173 07-Apr-2017 rpe

Align comments of stripcom() function in netstart and install.sub.


Revision tags: OPENBSD_6_1_BASE
# 1.172 06-Dec-2016 mpi

Do not lose the default route when netstart(8) is run a second time on
the interface pointed to by the default route.

Since the kernel no longer keep routes with dangling address pointer,
netstart(8) has to re-add the default route when the corresponding ifa
has been deleted and re-created.

deraadt@ points out that even if the previous semantic was not necessarily
better, a script like netstart(8) cannot totally fix the default route
problem.

Regression reported by and fix tested by Hrvoje Popovski.

ksh foo checked by halex@


# 1.171 27-Sep-2016 rzalamena

Delay switch(4) interface start up so it can attach virtual interfaces
like vether(4).

nits from and ok benno@, phessler@


# 1.170 09-Sep-2016 jasper

print a clear error message when not ran as root instead of just falling
through and try whatever it can do with the invoking user's perms

feedback/ok aja@ rpe@


Revision tags: OPENBSD_6_0_BASE
# 1.169 19-Jul-2016 mpi

Do not consider tap(4) a special interface and start if before other
pseudo-interfaces.

This unbreak vlan(4) on top of tap(4) since the refactoring to turn it
MP-safe.

ok claudio@, deraadt@


# 1.168 27-Mar-2016 sthen

Don't delete the 224/4 route in netstart, unless it's being done to ensure that
a -reject route can be added. Restores the ability to set an interface route
before daemons are started, lost during the previous simplification.
ok millert mpi


Revision tags: OPENBSD_5_9_BASE
# 1.167 29-Dec-2015 rpe

Remove backslash, not necessary after '&&'

OK halex@


# 1.166 29-Dec-2015 rpe

Replace last remaining `` with $()

OK halex@


# 1.165 18-Dec-2015 ajacoutot

Drop the now useless multicast setup comment.

prodded by tim@, ok mpi@


# 1.164 17-Dec-2015 ajacoutot

Simplify multicast option handling (10 less lines) by matching /etc/rc behavior
towards other YES|NO options and drop the error warning.


with and ok tim@, ok rpe@ on an earlier diff


# 1.163 05-Dec-2015 mpi

It does not make sense to insert a specific route for 224/4 when the
default one is good enough.

So merge rc.conf(8)'s 'multicast_router' and 'multicast_host' into a
single 'multicast'. If set to YES the reject route for 224/4 is not
inserted by netstart(8).

Manual bits from jmc@

ok henning@, ajacoutot@


# 1.162 12-Nov-2015 rpe

Changes to ifautostart():
- Rename function to ifv6autoconf() to make IPv6 relation clearer
- Localize and rename variables

OK krw@


# 1.161 12-Nov-2015 rpe

Changes to ifmstart():
- Change comments to make it clearer that ifmstart() takes two lists
of interface driver names (of which the second is optional) and not
the actual interface instances.
- Use localized variables and use slightly more verbose names.
- Use continue 2 to skip to the next hostname.if file.
- Use shell pattern @() instead of testing _sif individually.

OK krw@


# 1.160 12-Nov-2015 rpe

Changes to stripcom():
- Align comments with /etc/rc version
- Use localized variables
- Use safer "print -r --" instead of plain echo

Changes to ifstart():
- Tweak comment
- Add usage

OK krw@


# 1.159 01-Nov-2015 rpe

Start the rework of the /etc/netstart shell script.

General changes:
- apply a similar 'style' as used in the installer scripts
- improve comments to be more to the point, remove where code is obvious
- document usage of functions if they have arguments
- rename variables where it improves readability
- replace really old-school shell code with more contemporary idioms

Other changes:
- No need to care about "autoboot" because netstart doesn't inherit the
positional parameters from /etc/rc anymore. /etc/rc executes netstart
instead of sourcing it since r1.439.
- Use simpler for-loop to process list of interfaces with ifstart.

OK halex@


# 1.158 26-Oct-2015 rpe

The hostname variable is not used since r1.99. Remove it and use
stripcom() output directly with the hostname command.

OK deraadt@ krw@


# 1.157 23-Oct-2015 claudio

netstart bits for tap(4)


# 1.156 27-Sep-2015 sthen

Don't print output when setting autoconf on interfaces. Suggested by deraadt,
ok florian@ rpe@


# 1.155 13-Sep-2015 sthen

only print the "IPv6 autoconf" line if there are interfaces to configure
feedback/ok rpe


# 1.154 11-Sep-2015 sthen

Set "inet6 autoconf" individually on interfaces that have rtsol set in
hostname.if, previously netstart tried to configure them all at once
("ifconfig if0 if1 if2 inet6 autoconf"). From Delan Azabani, ok phessler@


Revision tags: OPENBSD_5_8_BASE
# 1.153 20-Jul-2015 rpe

Disable Strict Bourne shell mode for /etc/rc and /etc/netstart to be
able to use ksh syntax within these scripts. This way init doesn't
need to be changed, which starts /etc/rc using /bin/sh and people
can still use "sh /etc/netstart ifname".

Idea from and OK halex@
OK deraadt@ krw@ guenther@


# 1.152 19-Jul-2015 florian

Bring up pflow last as it might send with a source address that is on
any of the other interfaces.
OK deraadt, phessler, benno


# 1.151 19-Jul-2015 rpe

Always source rc.subr to be able to use the rc.conf parsing routine
to get the network related vars from rc.conf. This is even necessary
if netstart is run from within /etc/rc. Remove test of $INRC which
unintentionally evaluated always to true.

problem with previous change found by nigel@
OK sthen@ aja@ halex@


# 1.150 19-Jul-2015 ajacoutot

Revert 1.148 for now until I can talk to rpe@
It introduced a regression reported by nigel@


# 1.149 19-Jul-2015 rpe

Replace test command with [].

OK halex@ krw@


# 1.148 19-Jul-2015 rpe

Ensure, that we source rc.subr and parse rc.conf ONLY if we are not
inside /etc/rc.

With help from and OK halex@, ajacoutot@


# 1.147 18-Jul-2015 rpe

- remove trailing blanks introduced in previous commit
- no space in redirections like </foo or >$bar
- few other minor whitespaces

OK krw@


# 1.146 18-Jul-2015 rpe

Improve comments
- Add comments for functions
- Start comments with capital letters
- End comments with a full stop
- Allow comments to extend up to column 80

OK krw@


# 1.145 06-Jun-2015 florian

Allow rtsol keyword in hostname.if(5) with net.inet6.ip6.forwarding=1.
"inet6 autoconf" was working before and rtsol should behave the same.
OK phessler


Revision tags: OPENBSD_5_7_BASE
# 1.144 03-Dec-2014 florian

The kernel handles rtsol(8) functionality since some time now.
Treat rtsol in hostname.if as a keyword like dhcp and call ifconfig
inet6 autoconf.
"reads good" todd@
OK krw@ (who is *not* an IPv6 person), but I recruited him in his
capacity as an installer person.


# 1.143 28-Sep-2014 claudio

Revert 1.142. Without the down netstart will just print the ifconfig
output because it may end up just calling 'ifconfig $if'. This needs
to be done better and properly tested.


# 1.142 26-Sep-2014 halex

remove explicit 'down' of an interface before starting a dhcp request, thereby
avoiding annoying delays for some switch configurations

ok claudio@ deraadt@

i would add ok phessler@, but it was not valid without an ok krw@


Revision tags: OPENBSD_5_6_BASE
# 1.141 12-Jul-2014 stsp

Fix netstart after autoconf6 change so 'rtsol' lines in hostname.if work again.
found by pelikan@; ok pelikan@ henning@


# 1.140 12-Jul-2014 robert

Make rc.conf a parsed configuration file and stop sourcing it as a shell
script.
From now on rc.conf has a fixed syntax (key=val) and it is not allowed
to add anything to it besides the supported syntax, it all going to be
ignored.

discussed with and help from deraadt@ and halex@


Revision tags: OPENBSD_5_5_BASE
# 1.139 22-Aug-2013 mpi

Like for dhclient, do no create a route to alias addresses via 127.0.0.1.
Our stack is able to tell if the address is local or not.

ok todd@, krw@


Revision tags: OPENBSD_5_4_BASE
# 1.138 20-Mar-2013 todd

fix lies in netstart; replacement wording from halex@
pointed out by Ryan Kavannagh rak at debian dot org


Revision tags: OPENBSD_5_3_BASE
# 1.137 05-Dec-2012 rpe

remove "Invalid interface name" message
requested by krw@

ok halex@


# 1.136 02-Dec-2012 rpe

use the more compact version of the check for ifconfig'able interfaces
from install.sub

with feedback from and ok halex


# 1.135 02-Dec-2012 rpe

- remove isalphanumeric() and replace it with a shell pattern, that
tries a bit harder to identify invalid interface names and in
this case emit an error message.
- use [[ $1 == autoboot ]] to avoid a shell error message due to
possible spaces in first argument
- no change in functionality

discussed with krw and halex
ok ("I like this") krw


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.134 07-Oct-2011 deraadt

The new ypbind changes requires that the domainname be set before
rc.conf is run. There's no real downside.
ok aja


Revision tags: OPENBSD_5_0_BASE
# 1.133 07-Jul-2011 guenther

Eliminate some $? tests by rolling the command into the condition

ok halex@


# 1.132 26-May-2011 mpf

Add svlan(4) startup bits.
From markus@. OK naddy, claudio, reyk.


Revision tags: OPENBSD_4_9_BASE
# 1.131 09-Feb-2011 sobrado

fix an unbalanced parenthesis in a comment; while here, split the comment
in a better place to make it more readable.

ok jmc@ and miod@


Revision tags: OPENBSD_4_8_BASE
# 1.130 16-Jun-2010 todd

permit e.g. -inet6 syntax by slurping all lines not just some
noticed by rhsv6 at hushmail dot com, ok sthen@


Revision tags: OPENBSD_4_7_BASE
# 1.129 12-Jan-2010 henning

when setting up lo0 use 127.0.0.1/8 instead of 127.0.0.1 for clarity and
correctness. it's not 1992 any more, kids. ok mcbride dlg krw


# 1.128 10-Dec-2009 todd

o stop reordering ifconfig arguments (e.g. after 'up ..')
o only stop processing if inet or inet6 lines are malformed
o everything not a specially handled bit is passed to ifconfig unmangled
noticed by several after the move from bridgename.bridge0 -> hostname.bridge0
prodded by deraadt@, tested by and feedback from several
man page bits 'look fine' jmc@


# 1.127 22-Nov-2009 deraadt

Stop supporting bridgename.bridge* files, and move to hostname.bridge*
files. To cope with this change, read about the mv command.
ok claudio todd


# 1.126 17-Sep-2009 simon

change variable i to $i in an expression of ifstart() for consistency
with the rest of the file. no functional change.

feedback from sthen@, ok krw@


# 1.125 10-Jul-2009 jdixon

Delay creation of tun(4) interfaces until the underlying interface and
routes are available. This fixes usage for some OpenVPN users that start
it from hostname.tun*.

Tested by Johan Huldtgren. ok sthen@, johan@.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.124 25-Nov-2008 markus

delay /etc/netstart until IPv6-DAD (dup-address-detection) is completed.
ok fries, hshoexer, claudio


# 1.123 14-Aug-2008 sthen

Tools from /usr may not be used in netstart since it may be NFS-mounted
and not available at that time. Rewrite the hostname.if permission check
to use only /bin/ls and the shell. Requested by deraadt.

ok todd, "Twisted." deraadt


Revision tags: OPENBSD_4_4_BASE
# 1.122 23-Jul-2008 sthen

Prevent warning about insecure hostnames where no /etc/hostname.*
exists. From wcmaier@.

Check target of symbolic links to avoid noise at boot and in
seucrity output where you have several interfaces symlinked to one
config file.

"If you think this is the right thing to do" deraadt@


# 1.121 09-Jun-2008 todd

warn once not 3 times in case of a non existent file, discussed with deraadt
originally pointed out by Johan Torin


# 1.120 09-Jun-2008 deraadt

Ensure that hostname.* files are also re-chowned to root.wheel at each
boot as discussed with claudio while eating tasty donairs. ok todd


# 1.119 17-Apr-2008 deraadt

before using them, force hostname.* files to be unreadable by world
first version from todd, ok millert


Revision tags: OPENBSD_4_3_BASE
# 1.118 17-Jan-2008 brad

Execute rtsol after turning up trunk(4) and vlan(4) interfaces so they're
taken into consideration for rtsol.

ok reyk@ dlg@


# 1.117 09-Jan-2008 mpf

Do not bring up pfsync(4) before the working ruleset
has been loaded. Otherwise, states that are received during the
initial bulk update mismatch the correct pf-checksum and
do not attach to the rules.
Problem identified by david@. Fix done in collaboration.
OK henning@


Revision tags: OPENBSD_4_2_BASE
# 1.116 02-Aug-2007 david

move the delay for IPv6 DAD to after all interfaces have started
fixes problems with daemons being unable to bind to all addreses at boot
ok itojun@ hshoexer@


Revision tags: OPENBSD_4_1_BASE
# 1.115 15-Nov-2006 itojun

reject multicast packet without scope identifier specified.


Revision tags: OPENBSD_4_0_BASE
# 1.114 29-Jun-2006 todd

do not add an extra space; nwid and description come out wrong
fix as proposed by maja@, thanks!


Revision tags: OPENBSD_3_9_BASE
# 1.113 28-Dec-2005 david

nuke extra whitespace


# 1.112 06-Dec-2005 reyk

multicast_host=YES only works if a valid default gateway is available.
validate this condition and reject multicast traffic on failure.

ok todd@ naddy@


# 1.111 02-Nov-2005 todd

fix inspired by pr#4590
ok krw@


# 1.110 25-Oct-2005 todd

better logic from krw@:
- do not process mygate for v4 if dhcp
- do not process mygate for v6 if rtsol
this also makes the mygate processing logic more readable
ok krw@


# 1.109 14-Oct-2005 todd

add v6 support for /etc/mygate
ok deraadt@ mickey@ krw@
same functionality tested/ok'ed by by mickey, brad, matthieu, and me
with this one may now put a v6 IP in /etc/mygate on a separate line from
the v4 default gateway and netstart will do the right thing


# 1.108 12-Oct-2005 todd

shrink stripcom(), sync with install.sub
ok krw@


# 1.107 04-Oct-2005 todd

trunk must be started after physical ethernet devices, but before vlan.
populate ifmstart lines accordingly.
prodded/tested by brad@
ok reyk@


# 1.106 28-Sep-2005 todd

use eval consistently, fixes description quotes on rtsol and dhcp
fix inspired by and closes pr 4495
ok krw@


Revision tags: OPENBSD_3_8_BASE
# 1.105 22-May-2005 todd

Introduce 'ifmstart' to deal with starting multiple interfaces minus a list
of interfaces.

This reduces the netstart script by 174 chars, 13 words, and 19 lines, but
more importantly, makes it more simple and less cluttered should more special
case/orderings be needed.

ok brad@ and pr 4197 submitter, inspired by and closes pr 4197


# 1.104 04-Apr-2005 djm

unbreak; ok pval@


# 1.103 03-Apr-2005 deraadt

if dhcp is used to get an address on any interface, ignore /etc/mygate
ok krw
(this lets us do something rather cool with the zaurus in particular)


Revision tags: OPENBSD_3_7_BASE
# 1.102 04-Jan-2005 mcbride

Bring up the carp(4) interface before default route.

ok pascoe@ mpf@


# 1.101 30-Dec-2004 millert

Add a copy of stripcom so /etc/netstart can be run standalone again.
OK deraadt@


# 1.100 19-Dec-2004 millert

Allow comments in /etc/{myname,mygate,defaultdomain}; OK deraadt@


# 1.99 04-Dec-2004 itojun

remove "route $hostname 127.0.0.1" line. deraadt ok
*** please update /etc/netstart and test if it works ok for you ***


# 1.98 20-Oct-2004 deraadt

make all route commands use -qn; ok mcbride henning


Revision tags: OPENBSD_3_6_BASE
# 1.97 29-May-2004 deraadt

one last route command lacking -qn


Revision tags: OPENBSD_3_5_BASE
# 1.96 22-Mar-2004 mcbride

Make sure pfsync is brought up before carp.

ok deraadt@


# 1.95 13-Mar-2004 mcbride

Delay pfsync(4) configuration, as the syncif has to be configured in
advance. From Thorsten Lockert.


# 1.94 14-Jan-2004 deraadt

ok, it took quite a bit of prodding but itojun finally explained why the
extra sleep 1 is in here, and we came to the conclusion it is safe to
delete it. whee.


# 1.93 13-Jan-2004 deraadt

repair v6 lo0 documentation


# 1.92 11-Jan-2004 deraadt

add loopback routes late


# 1.91 09-Jan-2004 deraadt

create all routes with -q; markus ok


# 1.90 04-Dec-2003 millert

Need to do "ifconfig create" for bridge interfaces too.


# 1.89 03-Dec-2003 markus

add support for ifconfig clone; from netbsd; ok deraadt, henning


# 1.88 20-Oct-2003 david

delay carp initialization until after physical interfaces are configured
ok mcbride@ henning@ deraadt@ todd@


Revision tags: OPENBSD_3_4_BASE
# 1.87 27-Aug-2003 henning

only try to set hostname to what /etc/myname says if that file actually exists,
otherwise preserve `hostname`
netbooted machines can live perfectly fine without it; they get their hostname
earlier.

ok krw@ cedric@


Revision tags: OPENBSD_3_3_BASE
# 1.86 16-Feb-2003 krw

Fix up some DNS verbiage to make it consistant.

Fix up default route selection by

a) Forcing user to explicitly chose 'dhcp' as a mechanism for
specifying a default route, rather than guessing based on one or more
interfaces being configured by dhcp.

b) If the user specified default route does not work, re-present the
existing default route rather than losing it.

c) Move default route selection to after nameserver activation so the
user can specify a hostname as the default route.

Change /etc/netstart so that /etc/mygate wins if a default route was
already specified (i.e. by dhcp).

ok deraadt@.


Revision tags: OPENBSD_3_2_BASE
# 1.85 16-May-2002 todd

ignore non-existent cases where '$if' evaluates to '*'.
From Andr� Lucas <andre@ae-35.com>, fixes pr # 2658.
'Looks good' from miod@, millert@, and krw@.


Revision tags: OPENBSD_3_1_BASE
# 1.84 23-Feb-2002 deraadt

re-add support for $if expansion; hamajima@nagoya.ydc.co.jp


# 1.83 21-Feb-2002 miod

Change the network components initialization order.
Change from:
o all interfaces
o all bridges
o routes
to:
o physical interfaces
o routes
o gif and gre interfaces
o bridges

Fixeski PR #2400.
Manual page updates coming soon.
Ok angelos@ chris@ deraadt@


Revision tags: OPENBSD_3_0_BASE
# 1.82 31-Jul-2001 hugh

a space before a redirect


# 1.81 06-Jul-2001 angelos

Also, source /etc/rc.conf so we can pull in the
multicast_host/multicast_router settings; this is useful if one
flushes the routing table and re-initializes.

We really need a netconfig tool of sorts.


# 1.80 06-Jul-2001 angelos

Use "route -n show -inet" to determine the default multicast iface.


# 1.79 03-Jul-2001 deraadt

pull in rc.conf early so that pf(1) startup is right; tested by jasoni, comments from millert


# 1.78 30-May-2001 deraadt

Remove ipf. Darren Reed has interpreted his (old, new, whichever)
licence in a way that makes ipf not free according to the rules we
established over 5 years ago, at www.openbsd.org/goals.html (and those
same basic rules govern the other *BSD projects too). Specifically,
Darren says that modified versions are not permitted. But software
which OpenBSD uses and redistributes must be free to all (be they
people or companies), for any purpose they wish to use it, including
modification, use, peeing on, or even integration into baby mulching
machines or atomic bombs to be dropped on Australia. Furthermore, we
know of a number of companies using ipf with modification like us, who
are now in the same situation, and we hope that some of them will work
with us to fill this gap that now exists in OpenBSD (temporarily, we
hope).


Revision tags: OPENBSD_2_9_BASE
# 1.77 13-Mar-2001 deraadt

spelling; maurice@maurice.wan.nl


# 1.76 06-Feb-2001 todd

ignore blank lines in addition to comments
fixes pr#1660 from wilfried@telia.com .. Thanks!


# 1.75 10-Jan-2001 jason

support !command in bridgename.if files, too


# 1.74 27-Nov-2000 millert

Use -n to test if a variable is non-zero. Otherwise, if the variable's
contents start with a '-' test becomes unhappy (since it interprets it
as another option).


# 1.73 08-Nov-2000 todd

This fixes pr 1481, we now handle args > 6 in /etc/hostname.if in the
cases where we did not previously handle them.
Thanks to Scott Atwood <atwood@cs.stanford.edu> for reminding us of this.


Revision tags: OPENBSD_2_8_BASE
# 1.72 02-Sep-2000 todd

subtle bug .. global variables in a while loop need reset 'just incase'
With:
hostname.fxp0 having a last line of:
inet6 alias 3ffe:...
and hostname.gif0 having a first two lines of:
giftunnel 1.2.3.4
dest 1.2.4.3
We end up with the command:
ifconfig gif0 giftunnel alias 1.2.3.4 1.2.4.3
.. which is clearly wrong and fixed by this change


# 1.71 18-Jun-2000 todd

rc.conf now parses ${local_rcconf} internally; closes pr 1259


Revision tags: OPENBSD_2_7_BASE
# 1.70 08-May-2000 todd

fix dhcp 'NONE' ness from install to allow media parsing to work
.. ok deraadt@, millert@


# 1.69 21-Apr-2000 deraadt

rc.conf.local support, inspired by chuck yerkes


# 1.68 04-Apr-2000 millert

Remove the -E flag from ipf as it is implicitly enabled and using
the -E flag here causes the kernel to printf 'IP Filter: already
initialized'.


# 1.67 18-Mar-2000 deraadt

silence all extra route addition printouts


# 1.66 17-Mar-2000 itojun

correct reject route installations for IPv6. improve comments.


# 1.65 12-Mar-2000 itojun

disallow packets to malicious 6to4 prefix, based on
http://playground.iijlab.net/i-d/draft-itojun-ipv6-transition-abuse-00.txt


# 1.64 10-Mar-2000 todd

fix non behavior
with this `!' lines in /etc/hostname.* run even without certain lines
(like a comment) preceeding it.


# 1.63 10-Jan-2000 todd

allow arbitrary commands in /etc/hostname.* files if the line starts with '!'


# 1.62 02-Jan-2000 deraadt

rtsol case can configure the interface up, since it would be nice to finish
DAD before the actual rtsol(8) run happens later. and since it will rtsol,
it is going to be up in any case.


# 1.61 02-Jan-2000 itojun

one more indentation fix.


# 1.60 02-Jan-2000 itojun

indentation fix (todd's part)


# 1.59 02-Jan-2000 todd

fix rtsold case, reset cmd for each iteration!


# 1.58 02-Jan-2000 itojun

allow options after "rtsol".
XXX both "dhcp" and "rtsol" has keyword *down* at the end. is it okay?


# 1.57 02-Jan-2000 itojun

echo "IPv6 autoconf: interfaces" before invoking rtsol.
sleep for net.inet6.ip6.dad_count seconds to ensure that IPv6 DAD is completed.
TODO: rtsold (rc.conf line), manpage


# 1.56 02-Jan-2000 itojun

ipv6 autoconf on hosts (non-routers).

to do this,
1. in sysctl.conf, add these lines:
net.inet6.ip6.forwarding=0
net.inet6.ip6.accept_rtadv=1
2. in hostname.foo, add
rtsol

specifying two or more interfaces with "rtsol" may result in strange
behavior - ipv6 spec does not permit multi-interface node to be autoconfig'ed.


# 1.55 02-Jan-2000 todd

add to hostname.* parsing:
- multiple entries support (read: aliases)
- inet6 support
- support for comments (#)
(look for hostname.if(5) commit for syntax details)


# 1.54 31-Dec-1999 itojun

install IPv6 reject routes only if kernel is capable of IPv6.


# 1.53 09-Dec-1999 itojun

avoid transmitting invalid IPv6 packets out to the wire.


# 1.52 09-Dec-1999 itojun

do not perform IPv6 initialization for loopback interface.
MUST make lo0 up before any IPv6 operations.
it will be considered a pilot error if you don't.
(I prefer to have lo0 initialized automatically)


Revision tags: OPENBSD_2_6_BASE
# 1.51 01-Sep-1999 deraadt

support # characters in bridgename.* files; millert


# 1.50 01-Sep-1999 deraadt

cleanup parsing of hostname.* files, and seperate bridge control into
bridgename.* files; all documented in new hostname.if(5) and
bridgename.if(5) man pages


# 1.49 09-Aug-1999 angelos

Only parse/setup the hostname.foo file if interface foo exists (this
is useful for laptops with different ethernet cards etc.)


Revision tags: OPENBSD_2_5_BASE
# 1.48 29-Mar-1999 niklas

New multicast route setup style


# 1.47 26-Mar-1999 niklas

Add bridge interface handling


# 1.46 01-Mar-1999 millert

Add support in /etc/hostname.xxx for files of the format:
up [options]
Any of the following may or may not be set:
$name $mask $bcaddr $extras


# 1.45 28-Oct-1998 millert

Kill the awful hack used to match and split /etc/hostname.* We now use
a function, isalphanumeric, to determine whether an interface name is
likely to be valid. This means that things like /etc/hostname.le0.bak,
/etc/hostname.le0#, /etc/hostname.le0~, etc. will be ignored as they
should. There is no longer an implicate assumption that /etc/hostname.*
only contains a single '.'.


Revision tags: OPENBSD_2_4_BASE
# 1.44 06-Oct-1998 deraadt

move ipnat to end of netstart, to support dhcp+ipnat


# 1.43 18-Sep-1998 deraadt

apply media directives on dhcp interfaces


# 1.42 10-Sep-1998 marc

better way of handling dhcp client; Jason Ish <jbi130@mail.usask.ca>


# 1.41 08-Sep-1998 marc

dhcp client stuff. "Angelos D. Keromytis" <angelos@dsl.cis.upenn.edu>


# 1.40 24-Aug-1998 downsj

You can't use -interface default when there's no default gateway
set (yet). Use -interface $hostname if mygate doesn't exist so that
this actually works on routers.


# 1.39 04-Jul-1998 deraadt

put 224 route on default, to avoid a hostname lookup


# 1.38 22-May-1998 deraadt

use route -n, what the heck


Revision tags: OPENBSD_2_3_BASE
# 1.37 28-Mar-1998 deraadt

s/^nat/ipnat/


# 1.36 23-Feb-1998 niklas

remove trailing blank line


# 1.35 07-Feb-1998 deraadt

ipforward is in sysctl.conf now


# 1.34 21-Dec-1997 deraadt

ugh


# 1.33 20-Dec-1997 deraadt

ipforwarding option in rc.conf


# 1.32 29-Nov-1997 kstailey

NAT requires IPF


# 1.31 04-Nov-1997 deraadt

kill spaces at ends of lines; m4


Revision tags: OPENBSD_2_2_BASE
# 1.30 14-Oct-1997 deraadt

set hostname/domainname before running rc.conf; m4@umn.edu


# 1.29 04-Sep-1997 deraadt

fork netstart; new child is rc.conf


# 1.28 25-Aug-1997 millert

Explicately pass -host flag to route(8) to avoid confusion with networks.


# 1.27 19-Aug-1997 niklas

Add hook for rpc.lockd, make nfsd flags settable in netstart


# 1.26 31-Jul-1997 downsj

Make quotas optional; wedged into netstart for the time being.
/etc/rc.conf, anyone?


# 1.25 30-Jul-1997 deraadt

do not run routed by default


# 1.24 28-Jul-1997 kstailey

Move configuration of loopback interface to before all other interfaces.
Allows the use of local caching-only nameserver with no "nameserver"
entry in /etc/resolv.conf to configure a route between the hostname
and loopback.


# 1.23 25-Jul-1997 provos

earlier start of keymanagement


# 1.22 24-Jul-1997 deraadt

make amd use /tmp_mnt by default


# 1.21 22-Jul-1997 provos

start the photuris daemon per default. hilfe.


# 1.20 17-Jun-1997 niklas

Put in hooks to start ypserv with flags


# 1.19 17-Jun-1997 niklas

Put in hooks to start rpc.yppasswdd with flags


Revision tags: OPENBSD_2_1_BASE
# 1.18 15-Apr-1997 deraadt

kill route flush until .. hmm kernel routing socket bug or something


# 1.17 09-Apr-1997 kstailey

add NAT startup


# 1.16 07-Apr-1997 rees

flush all old routes before adding new interfaces or routes.
ref: netbsd pr3228/misc, Matthias Scheler


# 1.15 03-Mar-1997 downsj

fix typo


# 1.14 11-Feb-1997 deraadt

add default route before fiddling with loopback route to avoid DNS problems; m4@umn.edu, #97


# 1.13 03-Feb-1997 deraadt

do ifaliases after /usr/bin exists in nfs diskless env; pr#77, matthieu@laas.fr


# 1.12 02-Nov-1996 deraadt

timed off by default


Revision tags: OPENBSD_2_0_BASE
# 1.11 23-Sep-1996 deraadt

rfc1323 variable


# 1.10 04-Sep-1996 deraadt

control portmap, inetd, and lpd from netstart; idea from tqbf@enteract.com


# 1.9 27-Aug-1996 deraadt

224.0.0.0 not 0.0.0.224; from peter@demon.net


# 1.8 18-Jun-1996 deraadt

move std stuff from rc.local to rc


# 1.7 16-Jun-1996 deraadt

install sample commented /etc/ifaliases file; which can now contain #
comments and blank lines. new format is "interface address netmask"
(yes, i changed the order of the entries). inspired by netbsd pr#2474;
gillhaa@ghost.whirlpool.com


# 1.6 02-Jun-1996 tholo

Install a multicast route by default


# 1.5 26-May-1996 deraadt

sync & label


# 1.4 09-Jan-1996 dm

added IP filter to netstat/rc and put examples in /usr/share/ipf


# 1.3 30-Dec-1995 deraadt

from netbsd: start mrouted like routed


# 1.2 18-Dec-1995 deraadt

/etc/ifaliases support by randy@zyzzyva.com


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.219 03-Jul-2022 kn

Create virtual interfaces upfront if specified on the command line

In cases like `sh /etc/netstart pair1 pair2', one of hostname.pair{1,2}
will contain a "patch pair{2,1}" command which expects the other interface
to exist.

If none exist, this would fail and netstart had to be run separately or
"patch"ed interface had to be manually created before.

There are other use cases where interfaces depend on each other, so before
(re)configuring an explicit list of interfaces, create all virtual ones
upfront so that a single netstart invocation will configure everything
correctly without having reflect dependencies in multiple ordered netstart
invocations.

Copy isin() from install.sub to help.

Feedback OK halex


# 1.218 26-Jun-2022 florian

Wait for autoconf interfaces to come up in netstart(8) instead of
rc(8). This makes tunnel interfaces work that depend on working
autoconf interfaces.
OK deraadt


Revision tags: OPENBSD_7_1_BASE
# 1.217 22-Feb-2022 dlg

add some more tunnels to the list of interfaces that rely on routing.


Revision tags: OPENBSD_7_0_BASE
# 1.216 02-Sep-2021 bluhm

Do not create loopback interfaces lo1, lo2, ... upfront. They are
automatically set up by the kernel when a routing domain is created.
An existing lo1 in rdomain 0 would prevent to add any interfaces
in rdomain 1.
OK kn@


# 1.215 30-Aug-2021 bluhm

Improve dubgging in /etc/netstart. Enable print only in ifcreate.
Add debugging output for ipv6 routes. Make localhost and multicast
code aware of the print only switch. Allow netstart -n to work
also if no interface is given.
OK kn@


# 1.214 06-Aug-2021 sthen

As tim@ spotted, a use of V4_AUTOCONF crept in when the variable name
was actually V4_DHCPCONF from previous use. Rename all of the V4_DHCPCONF
to V4_AUTOCONF so everything uses the new name. ok and reminder about
the installer from tb@


# 1.213 16-Jul-2021 florian

switch to dhcpleased/resolvd in base
OK deraadt


# 1.212 20-Jun-2021 florian

Don't try to install a default route with route(8) later on if we are
using inet autoconf, like we do with "dhcp" and "inet6 autoconf".
OK kn


Revision tags: OPENBSD_6_9_BASE
# 1.211 23-Dec-2020 krw

Allow the provision of dhclient(8) options on 'dhcp' lines in hostname.if(5)
files.

Usual man page help & ok jmc@


# 1.210 21-Dec-2020 krw

Avoid issuing pointless 'ifconfig <if> up' when processing 'dhcp' in
hostname.if files. dhclient(8) does that itself. Part of the
"further script optimizations" promised in r1.200 of netstart.

Tested & ok gnezdo@


# 1.209 29-Nov-2020 tb

Fix previous: use correct version of netstart and installer bits.


# 1.208 29-Nov-2020 deraadt

Add support for !command to mygate, so that netstart has a late opportunity
to perform network configuration (for example, "!route source -ifp em0")
Split mygate and myname manual pages (how did anyone ever believe these
are related), and perform hostname configuration much earlier in rc.
discussed with benno, claudio, jmc, etc etc, last version of !command
parser by tb


# 1.207 08-Nov-2020 jmc

no more mobileip;
ok claudio deraadt


Revision tags: OPENBSD_6_8_BASE
# 1.206 21-Jun-2020 dlg

start wg with the other interfaces that rely on routing being up.

from Matt Dunwoodie and Jason A. Donenfeld

ok deraadt@


# 1.205 22-May-2020 kn

Revert the following commit as it breaks hostname.if(5) lines with a
backslash at the end for line continuation

Breaking long lines into multiple ones must still be possible and does
require to treat the backslash as an escape character.

Breakage reported by Mark Patruck <mark at wrapped dot cx >, thanks!

---
distrib/miniroot/install.sub revision 1.1151
etc/netstart revision 1.203
date: 2020/05/21 11:54:41; author: kn; state: Exp; lines: +2 -2;
Do not treat backslashe as an escape character in hostname.if(5) lines

ifstart() should always pass such lines unaltered, especially if they
contain "nwid" or "description" lines with arbitrary strings.

<bsdlisten at gmail dot com> reported SSIDs such as "Mike's" during
installation end as broken; this was because the installer escaped
the single quote using backslashes which ended up being treated as
escape characters much later during hostname.if parsing in netstart(8).

Ok deraadt


# 1.204 21-May-2020 kn

Fix stripcom() description wrt. comments not on their own line

Neither netstart's nor install.sub's (subtly different) implementations
remove trailing comments on lines not starting as a comment, e.g.,
lines like "up #not down" go through unaltered and without "#not down"
being removed.

Only lines *beginning* with the comment sign ("#") are stripped.

No functional change, just updating function descriptions.


# 1.203 21-May-2020 kn

Do not treat backslashe as an escape character in hostname.if(5) lines

ifstart() should always pass such lines unaltered, especially if they
contain "nwid" or "description" lines with arbitrary strings.

<bsdlisten at gmail dot com> reported SSIDs such as "Mike's" during
installation end as broken; this was because the installer escaped
the single quote using backslashes which ended up being treated as
escape characters much later during hostname.if parsing in netstart(8).

Ok deraadt


Revision tags: OPENBSD_6_7_BASE
# 1.202 15-Jan-2020 kn

Do not redirect already quiet stdout for IPv6 reject routes

"route -q" already silences all standard output; if it still prints
something, that's a bug to fix in route.

OK bluhm


# 1.201 25-Oct-2019 dlg

handle aggr(4) in the same way as trunk(4)

from brad@
ok bluhm@ claudio@ deraadt@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.200 29-Aug-2018 krw

Historically /etc/netstart (and the equivalent code in the install
script) did 'ifconfig <if> down' before starting dhclient(8). This was
a way of ensuring old running copies of dhclient were killed before a
new one started. Current dhclient does not need this assist, so change
"ifconfig <if> down" to "ifconfig <if> up" pending further script
optimizations.

Similar to a 2014 attempt by halex@. Prompted by a misc@ report
from Kristjan Komlosi reporting hanging diskless setups.

ok halex@ kn@


# 1.199 08-Jul-2018 tb

netstart is used during system start, but also interactively.
Show proper error message if a regular user executes netstart.
Only do the privilege check if the id binary is available,
which might not be the case during diskless system startup.

ok deraadt, jasper, jca, krw, rpe (who wrote the same diff), sthen


# 1.198 28-Apr-2018 rpe

Add a proper usage() function.

Suggested by and OK jmc.
OK tb


Revision tags: OPENBSD_6_3_BASE
# 1.197 04-Mar-2018 jmc

when -n is used, no need to spit out "Missing parameters." before
displaying usage();

ok tb


# 1.196 03-Mar-2018 landry

Lowercase 'usage' and group -n with interface in it.
From jmc@, ok tb@


# 1.195 21-Feb-2018 rpe

Tweak comments.

OK tb


# 1.194 19-Feb-2018 rpe

Write warning/error messages to stderr and end them with a fullstop.

OK tb


# 1.193 19-Feb-2018 rpe

- use specific patterns when looping over /etc/hostname.if files
to skip backup or temp files.
- test if the patterns matched actual files
- warn if ifcreate() fails on an interface and continue with the
subsequent interfaces in the list instead of return'ing

OK dlg sthen tb


# 1.192 17-Feb-2018 rpe

- Add descriptions for the new functions ifcreate() and vifscreate()
- In ifcreate() use the exit code of the {} block directly
- In vifscreate(), use the ifconfig -C output directly in the for _vif loop
- Remove superfluous and somewhat confusing comment

OK dlg kn sthen


# 1.191 14-Feb-2018 dlg

create virtual interfaces before starting all interface config.

this resolves an ordering problem when adding pseudo interfaces to bridges

tweaks from kn@
ok mpi@ sthen@


# 1.190 10-Feb-2018 claudio

Remove some special IPv4 in IPv6 mapped prefixes that are already rejected
by the ::0.0.0.0/96 reject route added to deny all IPv4 mapped addresses.
Makes the inet6 routing table almost fit in one screen.
OK benno@


# 1.189 10-Feb-2018 florian

Load RFC 7217 key material and generate if it does not already exist.

Add soii.key to changelist (pointed out by semarie) and mtree/special
(suggest by Craig Skinner).

OK naddy, sthen, rpe, tb


# 1.188 06-Feb-2018 tb

If -n is given, the netstart script should not (try to) set the default
route(s). Simply print the command(s) to be issued instead.

tweak & ok rpe


# 1.187 12-Nov-2017 tb

Remove HN_DIR variable and expand it in the only place it was used. It
currently serves no purpose.

ok rpe, agreement from deraadt and halex


Revision tags: OPENBSD_6_2_BASE
# 1.186 25-Jul-2017 rpe

Finally remove backwards compat code to support the 'rtsol' keyword
in hostname.if(5)

OK mpi@ deraadt@ florian@
OK jmc@ from doc perspective


# 1.185 21-Jul-2017 rpe

Align ifstart() in netstart and install.sub.

- in netstart, rename _file to _hn referencing hostname.if files
- in install.sub switch ifstart() to be used with _if instead of
_hn as parameter

ok krw@ tb@


# 1.184 28-May-2017 awolk

etc/netstart: use colon separator instead of dot with chown

OK jung@, deraadt@, jmc@


# 1.183 07-May-2017 rpe

Change test from [] to [[]] and simplify pattern.

OK tb@, krw@ (for [[]])
Feedback and OK halex@


# 1.182 07-May-2017 rpe

Replace hardcoded script name with ${0##*/}

OK tb@ halex@


# 1.181 01-May-2017 rpe

Revert r1.170 and remove the id==0 check.
The id binary is not available in nfs diskless setups at this point.

reported by Andreas Kusalananda, thanks.
discussed with deraadt@


# 1.180 01-May-2017 rpe

Remove last remnants of rtsol. IPv6 autoconfiguration of interfaces is now
done in ifstart(). Remove ipv6autoconf() and replace rtsolif with a boolean
variable V6_AUTOCONF. Replace dhcpif with a boolean variable V4_DHCPCONF.
Both are later used in defaultroute() to decide whether or not to configre
defaultroutes from /etc/mygate.

OK krw@


# 1.179 30-Apr-2017 mpi

Do not try to delete a default route before adding it.

Now that route are automatically G/C with the address they are attached
to there's no reason to duplicate the kernel's job.

Fix a regression introduced with multipath default routes.

ok deraadt@


# 1.178 25-Apr-2017 rpe

Unbreak netstart for multiple inteface configurations like trunk
or carp. Ensure that the noglob option is disabled at the end of
parse_hn_line() and ifstart().

Reported by Christer Solskogen and Stefan Wollny, thanks!


# 1.177 24-Apr-2017 rpe

Introduce a new function parse_hn_line() that replaces the existing
hostname.if(5) parsing code in ifstart().
Add a -n option to netstart to only print the interface configuration
commands instead of executing them.
Add a HN_DIR variable, that points to the directory of the hostname.if
files (default /etc) that allows for future regression tests.

- add new parse_hn_line() function
- change ifstart()
- rename $if to $_if
- don't ifconfig or ifconfig create if -n option is used
- replace hostname.if(5) parsing code with new parse_hn_line()
- just print configuration commands if -n option is used
- autoconf now happens in ifstart(), remove ifv6autoconf()
- introduce HN_DIR variable for the hostname.if file location
- add handling of the -n option to only print config commands
- ensure -n is only used if interfaces are specified as parameters

Discussed with and positive feedback from many
'commit' deraadt@
OK sthen@


# 1.176 08-Apr-2017 rpe

- localize the if, file and stat variables which also ensures that
variables are not named like commands.
- change test from [] to [[]]

OK tb@ halex@


# 1.175 07-Apr-2017 rpe

Minimize differences in ifstart() function between netstart and
install.sub which makes it easier to spot changes in the future.

- comments and formatting
- quotes on assignments are not needed (netstart)
- remove stray space in test (netstart)
- use $file variable with while-loop (netstart)
- although valid, instead of i use $i in arithmetic test (install.sub)

OK krw@, tb@
Looks good deraadt@


# 1.174 07-Apr-2017 rpe

Align comments of ifstart() function in netstart and install.sub.


# 1.173 07-Apr-2017 rpe

Align comments of stripcom() function in netstart and install.sub.


Revision tags: OPENBSD_6_1_BASE
# 1.172 06-Dec-2016 mpi

Do not lose the default route when netstart(8) is run a second time on
the interface pointed to by the default route.

Since the kernel no longer keep routes with dangling address pointer,
netstart(8) has to re-add the default route when the corresponding ifa
has been deleted and re-created.

deraadt@ points out that even if the previous semantic was not necessarily
better, a script like netstart(8) cannot totally fix the default route
problem.

Regression reported by and fix tested by Hrvoje Popovski.

ksh foo checked by halex@


# 1.171 27-Sep-2016 rzalamena

Delay switch(4) interface start up so it can attach virtual interfaces
like vether(4).

nits from and ok benno@, phessler@


# 1.170 09-Sep-2016 jasper

print a clear error message when not ran as root instead of just falling
through and try whatever it can do with the invoking user's perms

feedback/ok aja@ rpe@


Revision tags: OPENBSD_6_0_BASE
# 1.169 19-Jul-2016 mpi

Do not consider tap(4) a special interface and start if before other
pseudo-interfaces.

This unbreak vlan(4) on top of tap(4) since the refactoring to turn it
MP-safe.

ok claudio@, deraadt@


# 1.168 27-Mar-2016 sthen

Don't delete the 224/4 route in netstart, unless it's being done to ensure that
a -reject route can be added. Restores the ability to set an interface route
before daemons are started, lost during the previous simplification.
ok millert mpi


Revision tags: OPENBSD_5_9_BASE
# 1.167 29-Dec-2015 rpe

Remove backslash, not necessary after '&&'

OK halex@


# 1.166 29-Dec-2015 rpe

Replace last remaining `` with $()

OK halex@


# 1.165 18-Dec-2015 ajacoutot

Drop the now useless multicast setup comment.

prodded by tim@, ok mpi@


# 1.164 17-Dec-2015 ajacoutot

Simplify multicast option handling (10 less lines) by matching /etc/rc behavior
towards other YES|NO options and drop the error warning.


with and ok tim@, ok rpe@ on an earlier diff


# 1.163 05-Dec-2015 mpi

It does not make sense to insert a specific route for 224/4 when the
default one is good enough.

So merge rc.conf(8)'s 'multicast_router' and 'multicast_host' into a
single 'multicast'. If set to YES the reject route for 224/4 is not
inserted by netstart(8).

Manual bits from jmc@

ok henning@, ajacoutot@


# 1.162 12-Nov-2015 rpe

Changes to ifautostart():
- Rename function to ifv6autoconf() to make IPv6 relation clearer
- Localize and rename variables

OK krw@


# 1.161 12-Nov-2015 rpe

Changes to ifmstart():
- Change comments to make it clearer that ifmstart() takes two lists
of interface driver names (of which the second is optional) and not
the actual interface instances.
- Use localized variables and use slightly more verbose names.
- Use continue 2 to skip to the next hostname.if file.
- Use shell pattern @() instead of testing _sif individually.

OK krw@


# 1.160 12-Nov-2015 rpe

Changes to stripcom():
- Align comments with /etc/rc version
- Use localized variables
- Use safer "print -r --" instead of plain echo

Changes to ifstart():
- Tweak comment
- Add usage

OK krw@


# 1.159 01-Nov-2015 rpe

Start the rework of the /etc/netstart shell script.

General changes:
- apply a similar 'style' as used in the installer scripts
- improve comments to be more to the point, remove where code is obvious
- document usage of functions if they have arguments
- rename variables where it improves readability
- replace really old-school shell code with more contemporary idioms

Other changes:
- No need to care about "autoboot" because netstart doesn't inherit the
positional parameters from /etc/rc anymore. /etc/rc executes netstart
instead of sourcing it since r1.439.
- Use simpler for-loop to process list of interfaces with ifstart.

OK halex@


# 1.158 26-Oct-2015 rpe

The hostname variable is not used since r1.99. Remove it and use
stripcom() output directly with the hostname command.

OK deraadt@ krw@


# 1.157 23-Oct-2015 claudio

netstart bits for tap(4)


# 1.156 27-Sep-2015 sthen

Don't print output when setting autoconf on interfaces. Suggested by deraadt,
ok florian@ rpe@


# 1.155 13-Sep-2015 sthen

only print the "IPv6 autoconf" line if there are interfaces to configure
feedback/ok rpe


# 1.154 11-Sep-2015 sthen

Set "inet6 autoconf" individually on interfaces that have rtsol set in
hostname.if, previously netstart tried to configure them all at once
("ifconfig if0 if1 if2 inet6 autoconf"). From Delan Azabani, ok phessler@


Revision tags: OPENBSD_5_8_BASE
# 1.153 20-Jul-2015 rpe

Disable Strict Bourne shell mode for /etc/rc and /etc/netstart to be
able to use ksh syntax within these scripts. This way init doesn't
need to be changed, which starts /etc/rc using /bin/sh and people
can still use "sh /etc/netstart ifname".

Idea from and OK halex@
OK deraadt@ krw@ guenther@


# 1.152 19-Jul-2015 florian

Bring up pflow last as it might send with a source address that is on
any of the other interfaces.
OK deraadt, phessler, benno


# 1.151 19-Jul-2015 rpe

Always source rc.subr to be able to use the rc.conf parsing routine
to get the network related vars from rc.conf. This is even necessary
if netstart is run from within /etc/rc. Remove test of $INRC which
unintentionally evaluated always to true.

problem with previous change found by nigel@
OK sthen@ aja@ halex@


# 1.150 19-Jul-2015 ajacoutot

Revert 1.148 for now until I can talk to rpe@
It introduced a regression reported by nigel@


# 1.149 19-Jul-2015 rpe

Replace test command with [].

OK halex@ krw@


# 1.148 19-Jul-2015 rpe

Ensure, that we source rc.subr and parse rc.conf ONLY if we are not
inside /etc/rc.

With help from and OK halex@, ajacoutot@


# 1.147 18-Jul-2015 rpe

- remove trailing blanks introduced in previous commit
- no space in redirections like </foo or >$bar
- few other minor whitespaces

OK krw@


# 1.146 18-Jul-2015 rpe

Improve comments
- Add comments for functions
- Start comments with capital letters
- End comments with a full stop
- Allow comments to extend up to column 80

OK krw@


# 1.145 06-Jun-2015 florian

Allow rtsol keyword in hostname.if(5) with net.inet6.ip6.forwarding=1.
"inet6 autoconf" was working before and rtsol should behave the same.
OK phessler


Revision tags: OPENBSD_5_7_BASE
# 1.144 03-Dec-2014 florian

The kernel handles rtsol(8) functionality since some time now.
Treat rtsol in hostname.if as a keyword like dhcp and call ifconfig
inet6 autoconf.
"reads good" todd@
OK krw@ (who is *not* an IPv6 person), but I recruited him in his
capacity as an installer person.


# 1.143 28-Sep-2014 claudio

Revert 1.142. Without the down netstart will just print the ifconfig
output because it may end up just calling 'ifconfig $if'. This needs
to be done better and properly tested.


# 1.142 26-Sep-2014 halex

remove explicit 'down' of an interface before starting a dhcp request, thereby
avoiding annoying delays for some switch configurations

ok claudio@ deraadt@

i would add ok phessler@, but it was not valid without an ok krw@


Revision tags: OPENBSD_5_6_BASE
# 1.141 12-Jul-2014 stsp

Fix netstart after autoconf6 change so 'rtsol' lines in hostname.if work again.
found by pelikan@; ok pelikan@ henning@


# 1.140 12-Jul-2014 robert

Make rc.conf a parsed configuration file and stop sourcing it as a shell
script.
From now on rc.conf has a fixed syntax (key=val) and it is not allowed
to add anything to it besides the supported syntax, it all going to be
ignored.

discussed with and help from deraadt@ and halex@


Revision tags: OPENBSD_5_5_BASE
# 1.139 22-Aug-2013 mpi

Like for dhclient, do no create a route to alias addresses via 127.0.0.1.
Our stack is able to tell if the address is local or not.

ok todd@, krw@


Revision tags: OPENBSD_5_4_BASE
# 1.138 20-Mar-2013 todd

fix lies in netstart; replacement wording from halex@
pointed out by Ryan Kavannagh rak at debian dot org


Revision tags: OPENBSD_5_3_BASE
# 1.137 05-Dec-2012 rpe

remove "Invalid interface name" message
requested by krw@

ok halex@


# 1.136 02-Dec-2012 rpe

use the more compact version of the check for ifconfig'able interfaces
from install.sub

with feedback from and ok halex


# 1.135 02-Dec-2012 rpe

- remove isalphanumeric() and replace it with a shell pattern, that
tries a bit harder to identify invalid interface names and in
this case emit an error message.
- use [[ $1 == autoboot ]] to avoid a shell error message due to
possible spaces in first argument
- no change in functionality

discussed with krw and halex
ok ("I like this") krw


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.134 07-Oct-2011 deraadt

The new ypbind changes requires that the domainname be set before
rc.conf is run. There's no real downside.
ok aja


Revision tags: OPENBSD_5_0_BASE
# 1.133 07-Jul-2011 guenther

Eliminate some $? tests by rolling the command into the condition

ok halex@


# 1.132 26-May-2011 mpf

Add svlan(4) startup bits.
From markus@. OK naddy, claudio, reyk.


Revision tags: OPENBSD_4_9_BASE
# 1.131 09-Feb-2011 sobrado

fix an unbalanced parenthesis in a comment; while here, split the comment
in a better place to make it more readable.

ok jmc@ and miod@


Revision tags: OPENBSD_4_8_BASE
# 1.130 16-Jun-2010 todd

permit e.g. -inet6 syntax by slurping all lines not just some
noticed by rhsv6 at hushmail dot com, ok sthen@


Revision tags: OPENBSD_4_7_BASE
# 1.129 12-Jan-2010 henning

when setting up lo0 use 127.0.0.1/8 instead of 127.0.0.1 for clarity and
correctness. it's not 1992 any more, kids. ok mcbride dlg krw


# 1.128 10-Dec-2009 todd

o stop reordering ifconfig arguments (e.g. after 'up ..')
o only stop processing if inet or inet6 lines are malformed
o everything not a specially handled bit is passed to ifconfig unmangled
noticed by several after the move from bridgename.bridge0 -> hostname.bridge0
prodded by deraadt@, tested by and feedback from several
man page bits 'look fine' jmc@


# 1.127 22-Nov-2009 deraadt

Stop supporting bridgename.bridge* files, and move to hostname.bridge*
files. To cope with this change, read about the mv command.
ok claudio todd


# 1.126 17-Sep-2009 simon

change variable i to $i in an expression of ifstart() for consistency
with the rest of the file. no functional change.

feedback from sthen@, ok krw@


# 1.125 10-Jul-2009 jdixon

Delay creation of tun(4) interfaces until the underlying interface and
routes are available. This fixes usage for some OpenVPN users that start
it from hostname.tun*.

Tested by Johan Huldtgren. ok sthen@, johan@.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.124 25-Nov-2008 markus

delay /etc/netstart until IPv6-DAD (dup-address-detection) is completed.
ok fries, hshoexer, claudio


# 1.123 14-Aug-2008 sthen

Tools from /usr may not be used in netstart since it may be NFS-mounted
and not available at that time. Rewrite the hostname.if permission check
to use only /bin/ls and the shell. Requested by deraadt.

ok todd, "Twisted." deraadt


Revision tags: OPENBSD_4_4_BASE
# 1.122 23-Jul-2008 sthen

Prevent warning about insecure hostnames where no /etc/hostname.*
exists. From wcmaier@.

Check target of symbolic links to avoid noise at boot and in
seucrity output where you have several interfaces symlinked to one
config file.

"If you think this is the right thing to do" deraadt@


# 1.121 09-Jun-2008 todd

warn once not 3 times in case of a non existent file, discussed with deraadt
originally pointed out by Johan Torin


# 1.120 09-Jun-2008 deraadt

Ensure that hostname.* files are also re-chowned to root.wheel at each
boot as discussed with claudio while eating tasty donairs. ok todd


# 1.119 17-Apr-2008 deraadt

before using them, force hostname.* files to be unreadable by world
first version from todd, ok millert


Revision tags: OPENBSD_4_3_BASE
# 1.118 17-Jan-2008 brad

Execute rtsol after turning up trunk(4) and vlan(4) interfaces so they're
taken into consideration for rtsol.

ok reyk@ dlg@


# 1.117 09-Jan-2008 mpf

Do not bring up pfsync(4) before the working ruleset
has been loaded. Otherwise, states that are received during the
initial bulk update mismatch the correct pf-checksum and
do not attach to the rules.
Problem identified by david@. Fix done in collaboration.
OK henning@


Revision tags: OPENBSD_4_2_BASE
# 1.116 02-Aug-2007 david

move the delay for IPv6 DAD to after all interfaces have started
fixes problems with daemons being unable to bind to all addreses at boot
ok itojun@ hshoexer@


Revision tags: OPENBSD_4_1_BASE
# 1.115 15-Nov-2006 itojun

reject multicast packet without scope identifier specified.


Revision tags: OPENBSD_4_0_BASE
# 1.114 29-Jun-2006 todd

do not add an extra space; nwid and description come out wrong
fix as proposed by maja@, thanks!


Revision tags: OPENBSD_3_9_BASE
# 1.113 28-Dec-2005 david

nuke extra whitespace


# 1.112 06-Dec-2005 reyk

multicast_host=YES only works if a valid default gateway is available.
validate this condition and reject multicast traffic on failure.

ok todd@ naddy@


# 1.111 02-Nov-2005 todd

fix inspired by pr#4590
ok krw@


# 1.110 25-Oct-2005 todd

better logic from krw@:
- do not process mygate for v4 if dhcp
- do not process mygate for v6 if rtsol
this also makes the mygate processing logic more readable
ok krw@


# 1.109 14-Oct-2005 todd

add v6 support for /etc/mygate
ok deraadt@ mickey@ krw@
same functionality tested/ok'ed by by mickey, brad, matthieu, and me
with this one may now put a v6 IP in /etc/mygate on a separate line from
the v4 default gateway and netstart will do the right thing


# 1.108 12-Oct-2005 todd

shrink stripcom(), sync with install.sub
ok krw@


# 1.107 04-Oct-2005 todd

trunk must be started after physical ethernet devices, but before vlan.
populate ifmstart lines accordingly.
prodded/tested by brad@
ok reyk@


# 1.106 28-Sep-2005 todd

use eval consistently, fixes description quotes on rtsol and dhcp
fix inspired by and closes pr 4495
ok krw@


Revision tags: OPENBSD_3_8_BASE
# 1.105 22-May-2005 todd

Introduce 'ifmstart' to deal with starting multiple interfaces minus a list
of interfaces.

This reduces the netstart script by 174 chars, 13 words, and 19 lines, but
more importantly, makes it more simple and less cluttered should more special
case/orderings be needed.

ok brad@ and pr 4197 submitter, inspired by and closes pr 4197


# 1.104 04-Apr-2005 djm

unbreak; ok pval@


# 1.103 03-Apr-2005 deraadt

if dhcp is used to get an address on any interface, ignore /etc/mygate
ok krw
(this lets us do something rather cool with the zaurus in particular)


Revision tags: OPENBSD_3_7_BASE
# 1.102 04-Jan-2005 mcbride

Bring up the carp(4) interface before default route.

ok pascoe@ mpf@


# 1.101 30-Dec-2004 millert

Add a copy of stripcom so /etc/netstart can be run standalone again.
OK deraadt@


# 1.100 19-Dec-2004 millert

Allow comments in /etc/{myname,mygate,defaultdomain}; OK deraadt@


# 1.99 04-Dec-2004 itojun

remove "route $hostname 127.0.0.1" line. deraadt ok
*** please update /etc/netstart and test if it works ok for you ***


# 1.98 20-Oct-2004 deraadt

make all route commands use -qn; ok mcbride henning


Revision tags: OPENBSD_3_6_BASE
# 1.97 29-May-2004 deraadt

one last route command lacking -qn


Revision tags: OPENBSD_3_5_BASE
# 1.96 22-Mar-2004 mcbride

Make sure pfsync is brought up before carp.

ok deraadt@


# 1.95 13-Mar-2004 mcbride

Delay pfsync(4) configuration, as the syncif has to be configured in
advance. From Thorsten Lockert.


# 1.94 14-Jan-2004 deraadt

ok, it took quite a bit of prodding but itojun finally explained why the
extra sleep 1 is in here, and we came to the conclusion it is safe to
delete it. whee.


# 1.93 13-Jan-2004 deraadt

repair v6 lo0 documentation


# 1.92 11-Jan-2004 deraadt

add loopback routes late


# 1.91 09-Jan-2004 deraadt

create all routes with -q; markus ok


# 1.90 04-Dec-2003 millert

Need to do "ifconfig create" for bridge interfaces too.


# 1.89 03-Dec-2003 markus

add support for ifconfig clone; from netbsd; ok deraadt, henning


# 1.88 20-Oct-2003 david

delay carp initialization until after physical interfaces are configured
ok mcbride@ henning@ deraadt@ todd@


Revision tags: OPENBSD_3_4_BASE
# 1.87 27-Aug-2003 henning

only try to set hostname to what /etc/myname says if that file actually exists,
otherwise preserve `hostname`
netbooted machines can live perfectly fine without it; they get their hostname
earlier.

ok krw@ cedric@


Revision tags: OPENBSD_3_3_BASE
# 1.86 16-Feb-2003 krw

Fix up some DNS verbiage to make it consistant.

Fix up default route selection by

a) Forcing user to explicitly chose 'dhcp' as a mechanism for
specifying a default route, rather than guessing based on one or more
interfaces being configured by dhcp.

b) If the user specified default route does not work, re-present the
existing default route rather than losing it.

c) Move default route selection to after nameserver activation so the
user can specify a hostname as the default route.

Change /etc/netstart so that /etc/mygate wins if a default route was
already specified (i.e. by dhcp).

ok deraadt@.


Revision tags: OPENBSD_3_2_BASE
# 1.85 16-May-2002 todd

ignore non-existent cases where '$if' evaluates to '*'.
From Andr� Lucas <andre@ae-35.com>, fixes pr # 2658.
'Looks good' from miod@, millert@, and krw@.


Revision tags: OPENBSD_3_1_BASE
# 1.84 23-Feb-2002 deraadt

re-add support for $if expansion; hamajima@nagoya.ydc.co.jp


# 1.83 21-Feb-2002 miod

Change the network components initialization order.
Change from:
o all interfaces
o all bridges
o routes
to:
o physical interfaces
o routes
o gif and gre interfaces
o bridges

Fixeski PR #2400.
Manual page updates coming soon.
Ok angelos@ chris@ deraadt@


Revision tags: OPENBSD_3_0_BASE
# 1.82 31-Jul-2001 hugh

a space before a redirect


# 1.81 06-Jul-2001 angelos

Also, source /etc/rc.conf so we can pull in the
multicast_host/multicast_router settings; this is useful if one
flushes the routing table and re-initializes.

We really need a netconfig tool of sorts.


# 1.80 06-Jul-2001 angelos

Use "route -n show -inet" to determine the default multicast iface.


# 1.79 03-Jul-2001 deraadt

pull in rc.conf early so that pf(1) startup is right; tested by jasoni, comments from millert


# 1.78 30-May-2001 deraadt

Remove ipf. Darren Reed has interpreted his (old, new, whichever)
licence in a way that makes ipf not free according to the rules we
established over 5 years ago, at www.openbsd.org/goals.html (and those
same basic rules govern the other *BSD projects too). Specifically,
Darren says that modified versions are not permitted. But software
which OpenBSD uses and redistributes must be free to all (be they
people or companies), for any purpose they wish to use it, including
modification, use, peeing on, or even integration into baby mulching
machines or atomic bombs to be dropped on Australia. Furthermore, we
know of a number of companies using ipf with modification like us, who
are now in the same situation, and we hope that some of them will work
with us to fill this gap that now exists in OpenBSD (temporarily, we
hope).


Revision tags: OPENBSD_2_9_BASE
# 1.77 13-Mar-2001 deraadt

spelling; maurice@maurice.wan.nl


# 1.76 06-Feb-2001 todd

ignore blank lines in addition to comments
fixes pr#1660 from wilfried@telia.com .. Thanks!


# 1.75 10-Jan-2001 jason

support !command in bridgename.if files, too


# 1.74 27-Nov-2000 millert

Use -n to test if a variable is non-zero. Otherwise, if the variable's
contents start with a '-' test becomes unhappy (since it interprets it
as another option).


# 1.73 08-Nov-2000 todd

This fixes pr 1481, we now handle args > 6 in /etc/hostname.if in the
cases where we did not previously handle them.
Thanks to Scott Atwood <atwood@cs.stanford.edu> for reminding us of this.


Revision tags: OPENBSD_2_8_BASE
# 1.72 02-Sep-2000 todd

subtle bug .. global variables in a while loop need reset 'just incase'
With:
hostname.fxp0 having a last line of:
inet6 alias 3ffe:...
and hostname.gif0 having a first two lines of:
giftunnel 1.2.3.4
dest 1.2.4.3
We end up with the command:
ifconfig gif0 giftunnel alias 1.2.3.4 1.2.4.3
.. which is clearly wrong and fixed by this change


# 1.71 18-Jun-2000 todd

rc.conf now parses ${local_rcconf} internally; closes pr 1259


Revision tags: OPENBSD_2_7_BASE
# 1.70 08-May-2000 todd

fix dhcp 'NONE' ness from install to allow media parsing to work
.. ok deraadt@, millert@


# 1.69 21-Apr-2000 deraadt

rc.conf.local support, inspired by chuck yerkes


# 1.68 04-Apr-2000 millert

Remove the -E flag from ipf as it is implicitly enabled and using
the -E flag here causes the kernel to printf 'IP Filter: already
initialized'.


# 1.67 18-Mar-2000 deraadt

silence all extra route addition printouts


# 1.66 17-Mar-2000 itojun

correct reject route installations for IPv6. improve comments.


# 1.65 12-Mar-2000 itojun

disallow packets to malicious 6to4 prefix, based on
http://playground.iijlab.net/i-d/draft-itojun-ipv6-transition-abuse-00.txt


# 1.64 10-Mar-2000 todd

fix non behavior
with this `!' lines in /etc/hostname.* run even without certain lines
(like a comment) preceeding it.


# 1.63 10-Jan-2000 todd

allow arbitrary commands in /etc/hostname.* files if the line starts with '!'


# 1.62 02-Jan-2000 deraadt

rtsol case can configure the interface up, since it would be nice to finish
DAD before the actual rtsol(8) run happens later. and since it will rtsol,
it is going to be up in any case.


# 1.61 02-Jan-2000 itojun

one more indentation fix.


# 1.60 02-Jan-2000 itojun

indentation fix (todd's part)


# 1.59 02-Jan-2000 todd

fix rtsold case, reset cmd for each iteration!


# 1.58 02-Jan-2000 itojun

allow options after "rtsol".
XXX both "dhcp" and "rtsol" has keyword *down* at the end. is it okay?


# 1.57 02-Jan-2000 itojun

echo "IPv6 autoconf: interfaces" before invoking rtsol.
sleep for net.inet6.ip6.dad_count seconds to ensure that IPv6 DAD is completed.
TODO: rtsold (rc.conf line), manpage


# 1.56 02-Jan-2000 itojun

ipv6 autoconf on hosts (non-routers).

to do this,
1. in sysctl.conf, add these lines:
net.inet6.ip6.forwarding=0
net.inet6.ip6.accept_rtadv=1
2. in hostname.foo, add
rtsol

specifying two or more interfaces with "rtsol" may result in strange
behavior - ipv6 spec does not permit multi-interface node to be autoconfig'ed.


# 1.55 02-Jan-2000 todd

add to hostname.* parsing:
- multiple entries support (read: aliases)
- inet6 support
- support for comments (#)
(look for hostname.if(5) commit for syntax details)


# 1.54 31-Dec-1999 itojun

install IPv6 reject routes only if kernel is capable of IPv6.


# 1.53 09-Dec-1999 itojun

avoid transmitting invalid IPv6 packets out to the wire.


# 1.52 09-Dec-1999 itojun

do not perform IPv6 initialization for loopback interface.
MUST make lo0 up before any IPv6 operations.
it will be considered a pilot error if you don't.
(I prefer to have lo0 initialized automatically)


Revision tags: OPENBSD_2_6_BASE
# 1.51 01-Sep-1999 deraadt

support # characters in bridgename.* files; millert


# 1.50 01-Sep-1999 deraadt

cleanup parsing of hostname.* files, and seperate bridge control into
bridgename.* files; all documented in new hostname.if(5) and
bridgename.if(5) man pages


# 1.49 09-Aug-1999 angelos

Only parse/setup the hostname.foo file if interface foo exists (this
is useful for laptops with different ethernet cards etc.)


Revision tags: OPENBSD_2_5_BASE
# 1.48 29-Mar-1999 niklas

New multicast route setup style


# 1.47 26-Mar-1999 niklas

Add bridge interface handling


# 1.46 01-Mar-1999 millert

Add support in /etc/hostname.xxx for files of the format:
up [options]
Any of the following may or may not be set:
$name $mask $bcaddr $extras


# 1.45 28-Oct-1998 millert

Kill the awful hack used to match and split /etc/hostname.* We now use
a function, isalphanumeric, to determine whether an interface name is
likely to be valid. This means that things like /etc/hostname.le0.bak,
/etc/hostname.le0#, /etc/hostname.le0~, etc. will be ignored as they
should. There is no longer an implicate assumption that /etc/hostname.*
only contains a single '.'.


Revision tags: OPENBSD_2_4_BASE
# 1.44 06-Oct-1998 deraadt

move ipnat to end of netstart, to support dhcp+ipnat


# 1.43 18-Sep-1998 deraadt

apply media directives on dhcp interfaces


# 1.42 10-Sep-1998 marc

better way of handling dhcp client; Jason Ish <jbi130@mail.usask.ca>


# 1.41 08-Sep-1998 marc

dhcp client stuff. "Angelos D. Keromytis" <angelos@dsl.cis.upenn.edu>


# 1.40 24-Aug-1998 downsj

You can't use -interface default when there's no default gateway
set (yet). Use -interface $hostname if mygate doesn't exist so that
this actually works on routers.


# 1.39 04-Jul-1998 deraadt

put 224 route on default, to avoid a hostname lookup


# 1.38 22-May-1998 deraadt

use route -n, what the heck


Revision tags: OPENBSD_2_3_BASE
# 1.37 28-Mar-1998 deraadt

s/^nat/ipnat/


# 1.36 23-Feb-1998 niklas

remove trailing blank line


# 1.35 07-Feb-1998 deraadt

ipforward is in sysctl.conf now


# 1.34 21-Dec-1997 deraadt

ugh


# 1.33 20-Dec-1997 deraadt

ipforwarding option in rc.conf


# 1.32 29-Nov-1997 kstailey

NAT requires IPF


# 1.31 04-Nov-1997 deraadt

kill spaces at ends of lines; m4


Revision tags: OPENBSD_2_2_BASE
# 1.30 14-Oct-1997 deraadt

set hostname/domainname before running rc.conf; m4@umn.edu


# 1.29 04-Sep-1997 deraadt

fork netstart; new child is rc.conf


# 1.28 25-Aug-1997 millert

Explicately pass -host flag to route(8) to avoid confusion with networks.


# 1.27 19-Aug-1997 niklas

Add hook for rpc.lockd, make nfsd flags settable in netstart


# 1.26 31-Jul-1997 downsj

Make quotas optional; wedged into netstart for the time being.
/etc/rc.conf, anyone?


# 1.25 30-Jul-1997 deraadt

do not run routed by default


# 1.24 28-Jul-1997 kstailey

Move configuration of loopback interface to before all other interfaces.
Allows the use of local caching-only nameserver with no "nameserver"
entry in /etc/resolv.conf to configure a route between the hostname
and loopback.


# 1.23 25-Jul-1997 provos

earlier start of keymanagement


# 1.22 24-Jul-1997 deraadt

make amd use /tmp_mnt by default


# 1.21 22-Jul-1997 provos

start the photuris daemon per default. hilfe.


# 1.20 17-Jun-1997 niklas

Put in hooks to start ypserv with flags


# 1.19 17-Jun-1997 niklas

Put in hooks to start rpc.yppasswdd with flags


Revision tags: OPENBSD_2_1_BASE
# 1.18 15-Apr-1997 deraadt

kill route flush until .. hmm kernel routing socket bug or something


# 1.17 09-Apr-1997 kstailey

add NAT startup


# 1.16 07-Apr-1997 rees

flush all old routes before adding new interfaces or routes.
ref: netbsd pr3228/misc, Matthias Scheler


# 1.15 03-Mar-1997 downsj

fix typo


# 1.14 11-Feb-1997 deraadt

add default route before fiddling with loopback route to avoid DNS problems; m4@umn.edu, #97


# 1.13 03-Feb-1997 deraadt

do ifaliases after /usr/bin exists in nfs diskless env; pr#77, matthieu@laas.fr


# 1.12 02-Nov-1996 deraadt

timed off by default


Revision tags: OPENBSD_2_0_BASE
# 1.11 23-Sep-1996 deraadt

rfc1323 variable


# 1.10 04-Sep-1996 deraadt

control portmap, inetd, and lpd from netstart; idea from tqbf@enteract.com


# 1.9 27-Aug-1996 deraadt

224.0.0.0 not 0.0.0.224; from peter@demon.net


# 1.8 18-Jun-1996 deraadt

move std stuff from rc.local to rc


# 1.7 16-Jun-1996 deraadt

install sample commented /etc/ifaliases file; which can now contain #
comments and blank lines. new format is "interface address netmask"
(yes, i changed the order of the entries). inspired by netbsd pr#2474;
gillhaa@ghost.whirlpool.com


# 1.6 02-Jun-1996 tholo

Install a multicast route by default


# 1.5 26-May-1996 deraadt

sync & label


# 1.4 09-Jan-1996 dm

added IP filter to netstat/rc and put examples in /usr/share/ipf


# 1.3 30-Dec-1995 deraadt

from netbsd: start mrouted like routed


# 1.2 18-Dec-1995 deraadt

/etc/ifaliases support by randy@zyzzyva.com


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.218 26-Jun-2022 florian

Wait for autoconf interfaces to come up in netstart(8) instead of
rc(8). This makes tunnel interfaces work that depend on working
autoconf interfaces.
OK deraadt


Revision tags: OPENBSD_7_1_BASE
# 1.217 22-Feb-2022 dlg

add some more tunnels to the list of interfaces that rely on routing.


Revision tags: OPENBSD_7_0_BASE
# 1.216 02-Sep-2021 bluhm

Do not create loopback interfaces lo1, lo2, ... upfront. They are
automatically set up by the kernel when a routing domain is created.
An existing lo1 in rdomain 0 would prevent to add any interfaces
in rdomain 1.
OK kn@


# 1.215 30-Aug-2021 bluhm

Improve dubgging in /etc/netstart. Enable print only in ifcreate.
Add debugging output for ipv6 routes. Make localhost and multicast
code aware of the print only switch. Allow netstart -n to work
also if no interface is given.
OK kn@


# 1.214 06-Aug-2021 sthen

As tim@ spotted, a use of V4_AUTOCONF crept in when the variable name
was actually V4_DHCPCONF from previous use. Rename all of the V4_DHCPCONF
to V4_AUTOCONF so everything uses the new name. ok and reminder about
the installer from tb@


# 1.213 16-Jul-2021 florian

switch to dhcpleased/resolvd in base
OK deraadt


# 1.212 20-Jun-2021 florian

Don't try to install a default route with route(8) later on if we are
using inet autoconf, like we do with "dhcp" and "inet6 autoconf".
OK kn


Revision tags: OPENBSD_6_9_BASE
# 1.211 23-Dec-2020 krw

Allow the provision of dhclient(8) options on 'dhcp' lines in hostname.if(5)
files.

Usual man page help & ok jmc@


# 1.210 21-Dec-2020 krw

Avoid issuing pointless 'ifconfig <if> up' when processing 'dhcp' in
hostname.if files. dhclient(8) does that itself. Part of the
"further script optimizations" promised in r1.200 of netstart.

Tested & ok gnezdo@


# 1.209 29-Nov-2020 tb

Fix previous: use correct version of netstart and installer bits.


# 1.208 29-Nov-2020 deraadt

Add support for !command to mygate, so that netstart has a late opportunity
to perform network configuration (for example, "!route source -ifp em0")
Split mygate and myname manual pages (how did anyone ever believe these
are related), and perform hostname configuration much earlier in rc.
discussed with benno, claudio, jmc, etc etc, last version of !command
parser by tb


# 1.207 08-Nov-2020 jmc

no more mobileip;
ok claudio deraadt


Revision tags: OPENBSD_6_8_BASE
# 1.206 21-Jun-2020 dlg

start wg with the other interfaces that rely on routing being up.

from Matt Dunwoodie and Jason A. Donenfeld

ok deraadt@


# 1.205 22-May-2020 kn

Revert the following commit as it breaks hostname.if(5) lines with a
backslash at the end for line continuation

Breaking long lines into multiple ones must still be possible and does
require to treat the backslash as an escape character.

Breakage reported by Mark Patruck <mark at wrapped dot cx >, thanks!

---
distrib/miniroot/install.sub revision 1.1151
etc/netstart revision 1.203
date: 2020/05/21 11:54:41; author: kn; state: Exp; lines: +2 -2;
Do not treat backslashe as an escape character in hostname.if(5) lines

ifstart() should always pass such lines unaltered, especially if they
contain "nwid" or "description" lines with arbitrary strings.

<bsdlisten at gmail dot com> reported SSIDs such as "Mike's" during
installation end as broken; this was because the installer escaped
the single quote using backslashes which ended up being treated as
escape characters much later during hostname.if parsing in netstart(8).

Ok deraadt


# 1.204 21-May-2020 kn

Fix stripcom() description wrt. comments not on their own line

Neither netstart's nor install.sub's (subtly different) implementations
remove trailing comments on lines not starting as a comment, e.g.,
lines like "up #not down" go through unaltered and without "#not down"
being removed.

Only lines *beginning* with the comment sign ("#") are stripped.

No functional change, just updating function descriptions.


# 1.203 21-May-2020 kn

Do not treat backslashe as an escape character in hostname.if(5) lines

ifstart() should always pass such lines unaltered, especially if they
contain "nwid" or "description" lines with arbitrary strings.

<bsdlisten at gmail dot com> reported SSIDs such as "Mike's" during
installation end as broken; this was because the installer escaped
the single quote using backslashes which ended up being treated as
escape characters much later during hostname.if parsing in netstart(8).

Ok deraadt


Revision tags: OPENBSD_6_7_BASE
# 1.202 15-Jan-2020 kn

Do not redirect already quiet stdout for IPv6 reject routes

"route -q" already silences all standard output; if it still prints
something, that's a bug to fix in route.

OK bluhm


# 1.201 25-Oct-2019 dlg

handle aggr(4) in the same way as trunk(4)

from brad@
ok bluhm@ claudio@ deraadt@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.200 29-Aug-2018 krw

Historically /etc/netstart (and the equivalent code in the install
script) did 'ifconfig <if> down' before starting dhclient(8). This was
a way of ensuring old running copies of dhclient were killed before a
new one started. Current dhclient does not need this assist, so change
"ifconfig <if> down" to "ifconfig <if> up" pending further script
optimizations.

Similar to a 2014 attempt by halex@. Prompted by a misc@ report
from Kristjan Komlosi reporting hanging diskless setups.

ok halex@ kn@


# 1.199 08-Jul-2018 tb

netstart is used during system start, but also interactively.
Show proper error message if a regular user executes netstart.
Only do the privilege check if the id binary is available,
which might not be the case during diskless system startup.

ok deraadt, jasper, jca, krw, rpe (who wrote the same diff), sthen


# 1.198 28-Apr-2018 rpe

Add a proper usage() function.

Suggested by and OK jmc.
OK tb


Revision tags: OPENBSD_6_3_BASE
# 1.197 04-Mar-2018 jmc

when -n is used, no need to spit out "Missing parameters." before
displaying usage();

ok tb


# 1.196 03-Mar-2018 landry

Lowercase 'usage' and group -n with interface in it.
From jmc@, ok tb@


# 1.195 21-Feb-2018 rpe

Tweak comments.

OK tb


# 1.194 19-Feb-2018 rpe

Write warning/error messages to stderr and end them with a fullstop.

OK tb


# 1.193 19-Feb-2018 rpe

- use specific patterns when looping over /etc/hostname.if files
to skip backup or temp files.
- test if the patterns matched actual files
- warn if ifcreate() fails on an interface and continue with the
subsequent interfaces in the list instead of return'ing

OK dlg sthen tb


# 1.192 17-Feb-2018 rpe

- Add descriptions for the new functions ifcreate() and vifscreate()
- In ifcreate() use the exit code of the {} block directly
- In vifscreate(), use the ifconfig -C output directly in the for _vif loop
- Remove superfluous and somewhat confusing comment

OK dlg kn sthen


# 1.191 14-Feb-2018 dlg

create virtual interfaces before starting all interface config.

this resolves an ordering problem when adding pseudo interfaces to bridges

tweaks from kn@
ok mpi@ sthen@


# 1.190 10-Feb-2018 claudio

Remove some special IPv4 in IPv6 mapped prefixes that are already rejected
by the ::0.0.0.0/96 reject route added to deny all IPv4 mapped addresses.
Makes the inet6 routing table almost fit in one screen.
OK benno@


# 1.189 10-Feb-2018 florian

Load RFC 7217 key material and generate if it does not already exist.

Add soii.key to changelist (pointed out by semarie) and mtree/special
(suggest by Craig Skinner).

OK naddy, sthen, rpe, tb


# 1.188 06-Feb-2018 tb

If -n is given, the netstart script should not (try to) set the default
route(s). Simply print the command(s) to be issued instead.

tweak & ok rpe


# 1.187 12-Nov-2017 tb

Remove HN_DIR variable and expand it in the only place it was used. It
currently serves no purpose.

ok rpe, agreement from deraadt and halex


Revision tags: OPENBSD_6_2_BASE
# 1.186 25-Jul-2017 rpe

Finally remove backwards compat code to support the 'rtsol' keyword
in hostname.if(5)

OK mpi@ deraadt@ florian@
OK jmc@ from doc perspective


# 1.185 21-Jul-2017 rpe

Align ifstart() in netstart and install.sub.

- in netstart, rename _file to _hn referencing hostname.if files
- in install.sub switch ifstart() to be used with _if instead of
_hn as parameter

ok krw@ tb@


# 1.184 28-May-2017 awolk

etc/netstart: use colon separator instead of dot with chown

OK jung@, deraadt@, jmc@


# 1.183 07-May-2017 rpe

Change test from [] to [[]] and simplify pattern.

OK tb@, krw@ (for [[]])
Feedback and OK halex@


# 1.182 07-May-2017 rpe

Replace hardcoded script name with ${0##*/}

OK tb@ halex@


# 1.181 01-May-2017 rpe

Revert r1.170 and remove the id==0 check.
The id binary is not available in nfs diskless setups at this point.

reported by Andreas Kusalananda, thanks.
discussed with deraadt@


# 1.180 01-May-2017 rpe

Remove last remnants of rtsol. IPv6 autoconfiguration of interfaces is now
done in ifstart(). Remove ipv6autoconf() and replace rtsolif with a boolean
variable V6_AUTOCONF. Replace dhcpif with a boolean variable V4_DHCPCONF.
Both are later used in defaultroute() to decide whether or not to configre
defaultroutes from /etc/mygate.

OK krw@


# 1.179 30-Apr-2017 mpi

Do not try to delete a default route before adding it.

Now that route are automatically G/C with the address they are attached
to there's no reason to duplicate the kernel's job.

Fix a regression introduced with multipath default routes.

ok deraadt@


# 1.178 25-Apr-2017 rpe

Unbreak netstart for multiple inteface configurations like trunk
or carp. Ensure that the noglob option is disabled at the end of
parse_hn_line() and ifstart().

Reported by Christer Solskogen and Stefan Wollny, thanks!


# 1.177 24-Apr-2017 rpe

Introduce a new function parse_hn_line() that replaces the existing
hostname.if(5) parsing code in ifstart().
Add a -n option to netstart to only print the interface configuration
commands instead of executing them.
Add a HN_DIR variable, that points to the directory of the hostname.if
files (default /etc) that allows for future regression tests.

- add new parse_hn_line() function
- change ifstart()
- rename $if to $_if
- don't ifconfig or ifconfig create if -n option is used
- replace hostname.if(5) parsing code with new parse_hn_line()
- just print configuration commands if -n option is used
- autoconf now happens in ifstart(), remove ifv6autoconf()
- introduce HN_DIR variable for the hostname.if file location
- add handling of the -n option to only print config commands
- ensure -n is only used if interfaces are specified as parameters

Discussed with and positive feedback from many
'commit' deraadt@
OK sthen@


# 1.176 08-Apr-2017 rpe

- localize the if, file and stat variables which also ensures that
variables are not named like commands.
- change test from [] to [[]]

OK tb@ halex@


# 1.175 07-Apr-2017 rpe

Minimize differences in ifstart() function between netstart and
install.sub which makes it easier to spot changes in the future.

- comments and formatting
- quotes on assignments are not needed (netstart)
- remove stray space in test (netstart)
- use $file variable with while-loop (netstart)
- although valid, instead of i use $i in arithmetic test (install.sub)

OK krw@, tb@
Looks good deraadt@


# 1.174 07-Apr-2017 rpe

Align comments of ifstart() function in netstart and install.sub.


# 1.173 07-Apr-2017 rpe

Align comments of stripcom() function in netstart and install.sub.


Revision tags: OPENBSD_6_1_BASE
# 1.172 06-Dec-2016 mpi

Do not lose the default route when netstart(8) is run a second time on
the interface pointed to by the default route.

Since the kernel no longer keep routes with dangling address pointer,
netstart(8) has to re-add the default route when the corresponding ifa
has been deleted and re-created.

deraadt@ points out that even if the previous semantic was not necessarily
better, a script like netstart(8) cannot totally fix the default route
problem.

Regression reported by and fix tested by Hrvoje Popovski.

ksh foo checked by halex@


# 1.171 27-Sep-2016 rzalamena

Delay switch(4) interface start up so it can attach virtual interfaces
like vether(4).

nits from and ok benno@, phessler@


# 1.170 09-Sep-2016 jasper

print a clear error message when not ran as root instead of just falling
through and try whatever it can do with the invoking user's perms

feedback/ok aja@ rpe@


Revision tags: OPENBSD_6_0_BASE
# 1.169 19-Jul-2016 mpi

Do not consider tap(4) a special interface and start if before other
pseudo-interfaces.

This unbreak vlan(4) on top of tap(4) since the refactoring to turn it
MP-safe.

ok claudio@, deraadt@


# 1.168 27-Mar-2016 sthen

Don't delete the 224/4 route in netstart, unless it's being done to ensure that
a -reject route can be added. Restores the ability to set an interface route
before daemons are started, lost during the previous simplification.
ok millert mpi


Revision tags: OPENBSD_5_9_BASE
# 1.167 29-Dec-2015 rpe

Remove backslash, not necessary after '&&'

OK halex@


# 1.166 29-Dec-2015 rpe

Replace last remaining `` with $()

OK halex@


# 1.165 18-Dec-2015 ajacoutot

Drop the now useless multicast setup comment.

prodded by tim@, ok mpi@


# 1.164 17-Dec-2015 ajacoutot

Simplify multicast option handling (10 less lines) by matching /etc/rc behavior
towards other YES|NO options and drop the error warning.


with and ok tim@, ok rpe@ on an earlier diff


# 1.163 05-Dec-2015 mpi

It does not make sense to insert a specific route for 224/4 when the
default one is good enough.

So merge rc.conf(8)'s 'multicast_router' and 'multicast_host' into a
single 'multicast'. If set to YES the reject route for 224/4 is not
inserted by netstart(8).

Manual bits from jmc@

ok henning@, ajacoutot@


# 1.162 12-Nov-2015 rpe

Changes to ifautostart():
- Rename function to ifv6autoconf() to make IPv6 relation clearer
- Localize and rename variables

OK krw@


# 1.161 12-Nov-2015 rpe

Changes to ifmstart():
- Change comments to make it clearer that ifmstart() takes two lists
of interface driver names (of which the second is optional) and not
the actual interface instances.
- Use localized variables and use slightly more verbose names.
- Use continue 2 to skip to the next hostname.if file.
- Use shell pattern @() instead of testing _sif individually.

OK krw@


# 1.160 12-Nov-2015 rpe

Changes to stripcom():
- Align comments with /etc/rc version
- Use localized variables
- Use safer "print -r --" instead of plain echo

Changes to ifstart():
- Tweak comment
- Add usage

OK krw@


# 1.159 01-Nov-2015 rpe

Start the rework of the /etc/netstart shell script.

General changes:
- apply a similar 'style' as used in the installer scripts
- improve comments to be more to the point, remove where code is obvious
- document usage of functions if they have arguments
- rename variables where it improves readability
- replace really old-school shell code with more contemporary idioms

Other changes:
- No need to care about "autoboot" because netstart doesn't inherit the
positional parameters from /etc/rc anymore. /etc/rc executes netstart
instead of sourcing it since r1.439.
- Use simpler for-loop to process list of interfaces with ifstart.

OK halex@


# 1.158 26-Oct-2015 rpe

The hostname variable is not used since r1.99. Remove it and use
stripcom() output directly with the hostname command.

OK deraadt@ krw@


# 1.157 23-Oct-2015 claudio

netstart bits for tap(4)


# 1.156 27-Sep-2015 sthen

Don't print output when setting autoconf on interfaces. Suggested by deraadt,
ok florian@ rpe@


# 1.155 13-Sep-2015 sthen

only print the "IPv6 autoconf" line if there are interfaces to configure
feedback/ok rpe


# 1.154 11-Sep-2015 sthen

Set "inet6 autoconf" individually on interfaces that have rtsol set in
hostname.if, previously netstart tried to configure them all at once
("ifconfig if0 if1 if2 inet6 autoconf"). From Delan Azabani, ok phessler@


Revision tags: OPENBSD_5_8_BASE
# 1.153 20-Jul-2015 rpe

Disable Strict Bourne shell mode for /etc/rc and /etc/netstart to be
able to use ksh syntax within these scripts. This way init doesn't
need to be changed, which starts /etc/rc using /bin/sh and people
can still use "sh /etc/netstart ifname".

Idea from and OK halex@
OK deraadt@ krw@ guenther@


# 1.152 19-Jul-2015 florian

Bring up pflow last as it might send with a source address that is on
any of the other interfaces.
OK deraadt, phessler, benno


# 1.151 19-Jul-2015 rpe

Always source rc.subr to be able to use the rc.conf parsing routine
to get the network related vars from rc.conf. This is even necessary
if netstart is run from within /etc/rc. Remove test of $INRC which
unintentionally evaluated always to true.

problem with previous change found by nigel@
OK sthen@ aja@ halex@


# 1.150 19-Jul-2015 ajacoutot

Revert 1.148 for now until I can talk to rpe@
It introduced a regression reported by nigel@


# 1.149 19-Jul-2015 rpe

Replace test command with [].

OK halex@ krw@


# 1.148 19-Jul-2015 rpe

Ensure, that we source rc.subr and parse rc.conf ONLY if we are not
inside /etc/rc.

With help from and OK halex@, ajacoutot@


# 1.147 18-Jul-2015 rpe

- remove trailing blanks introduced in previous commit
- no space in redirections like </foo or >$bar
- few other minor whitespaces

OK krw@


# 1.146 18-Jul-2015 rpe

Improve comments
- Add comments for functions
- Start comments with capital letters
- End comments with a full stop
- Allow comments to extend up to column 80

OK krw@


# 1.145 06-Jun-2015 florian

Allow rtsol keyword in hostname.if(5) with net.inet6.ip6.forwarding=1.
"inet6 autoconf" was working before and rtsol should behave the same.
OK phessler


Revision tags: OPENBSD_5_7_BASE
# 1.144 03-Dec-2014 florian

The kernel handles rtsol(8) functionality since some time now.
Treat rtsol in hostname.if as a keyword like dhcp and call ifconfig
inet6 autoconf.
"reads good" todd@
OK krw@ (who is *not* an IPv6 person), but I recruited him in his
capacity as an installer person.


# 1.143 28-Sep-2014 claudio

Revert 1.142. Without the down netstart will just print the ifconfig
output because it may end up just calling 'ifconfig $if'. This needs
to be done better and properly tested.


# 1.142 26-Sep-2014 halex

remove explicit 'down' of an interface before starting a dhcp request, thereby
avoiding annoying delays for some switch configurations

ok claudio@ deraadt@

i would add ok phessler@, but it was not valid without an ok krw@


Revision tags: OPENBSD_5_6_BASE
# 1.141 12-Jul-2014 stsp

Fix netstart after autoconf6 change so 'rtsol' lines in hostname.if work again.
found by pelikan@; ok pelikan@ henning@


# 1.140 12-Jul-2014 robert

Make rc.conf a parsed configuration file and stop sourcing it as a shell
script.
From now on rc.conf has a fixed syntax (key=val) and it is not allowed
to add anything to it besides the supported syntax, it all going to be
ignored.

discussed with and help from deraadt@ and halex@


Revision tags: OPENBSD_5_5_BASE
# 1.139 22-Aug-2013 mpi

Like for dhclient, do no create a route to alias addresses via 127.0.0.1.
Our stack is able to tell if the address is local or not.

ok todd@, krw@


Revision tags: OPENBSD_5_4_BASE
# 1.138 20-Mar-2013 todd

fix lies in netstart; replacement wording from halex@
pointed out by Ryan Kavannagh rak at debian dot org


Revision tags: OPENBSD_5_3_BASE
# 1.137 05-Dec-2012 rpe

remove "Invalid interface name" message
requested by krw@

ok halex@


# 1.136 02-Dec-2012 rpe

use the more compact version of the check for ifconfig'able interfaces
from install.sub

with feedback from and ok halex


# 1.135 02-Dec-2012 rpe

- remove isalphanumeric() and replace it with a shell pattern, that
tries a bit harder to identify invalid interface names and in
this case emit an error message.
- use [[ $1 == autoboot ]] to avoid a shell error message due to
possible spaces in first argument
- no change in functionality

discussed with krw and halex
ok ("I like this") krw


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.134 07-Oct-2011 deraadt

The new ypbind changes requires that the domainname be set before
rc.conf is run. There's no real downside.
ok aja


Revision tags: OPENBSD_5_0_BASE
# 1.133 07-Jul-2011 guenther

Eliminate some $? tests by rolling the command into the condition

ok halex@


# 1.132 26-May-2011 mpf

Add svlan(4) startup bits.
From markus@. OK naddy, claudio, reyk.


Revision tags: OPENBSD_4_9_BASE
# 1.131 09-Feb-2011 sobrado

fix an unbalanced parenthesis in a comment; while here, split the comment
in a better place to make it more readable.

ok jmc@ and miod@


Revision tags: OPENBSD_4_8_BASE
# 1.130 16-Jun-2010 todd

permit e.g. -inet6 syntax by slurping all lines not just some
noticed by rhsv6 at hushmail dot com, ok sthen@


Revision tags: OPENBSD_4_7_BASE
# 1.129 12-Jan-2010 henning

when setting up lo0 use 127.0.0.1/8 instead of 127.0.0.1 for clarity and
correctness. it's not 1992 any more, kids. ok mcbride dlg krw


# 1.128 10-Dec-2009 todd

o stop reordering ifconfig arguments (e.g. after 'up ..')
o only stop processing if inet or inet6 lines are malformed
o everything not a specially handled bit is passed to ifconfig unmangled
noticed by several after the move from bridgename.bridge0 -> hostname.bridge0
prodded by deraadt@, tested by and feedback from several
man page bits 'look fine' jmc@


# 1.127 22-Nov-2009 deraadt

Stop supporting bridgename.bridge* files, and move to hostname.bridge*
files. To cope with this change, read about the mv command.
ok claudio todd


# 1.126 17-Sep-2009 simon

change variable i to $i in an expression of ifstart() for consistency
with the rest of the file. no functional change.

feedback from sthen@, ok krw@


# 1.125 10-Jul-2009 jdixon

Delay creation of tun(4) interfaces until the underlying interface and
routes are available. This fixes usage for some OpenVPN users that start
it from hostname.tun*.

Tested by Johan Huldtgren. ok sthen@, johan@.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.124 25-Nov-2008 markus

delay /etc/netstart until IPv6-DAD (dup-address-detection) is completed.
ok fries, hshoexer, claudio


# 1.123 14-Aug-2008 sthen

Tools from /usr may not be used in netstart since it may be NFS-mounted
and not available at that time. Rewrite the hostname.if permission check
to use only /bin/ls and the shell. Requested by deraadt.

ok todd, "Twisted." deraadt


Revision tags: OPENBSD_4_4_BASE
# 1.122 23-Jul-2008 sthen

Prevent warning about insecure hostnames where no /etc/hostname.*
exists. From wcmaier@.

Check target of symbolic links to avoid noise at boot and in
seucrity output where you have several interfaces symlinked to one
config file.

"If you think this is the right thing to do" deraadt@


# 1.121 09-Jun-2008 todd

warn once not 3 times in case of a non existent file, discussed with deraadt
originally pointed out by Johan Torin


# 1.120 09-Jun-2008 deraadt

Ensure that hostname.* files are also re-chowned to root.wheel at each
boot as discussed with claudio while eating tasty donairs. ok todd


# 1.119 17-Apr-2008 deraadt

before using them, force hostname.* files to be unreadable by world
first version from todd, ok millert


Revision tags: OPENBSD_4_3_BASE
# 1.118 17-Jan-2008 brad

Execute rtsol after turning up trunk(4) and vlan(4) interfaces so they're
taken into consideration for rtsol.

ok reyk@ dlg@


# 1.117 09-Jan-2008 mpf

Do not bring up pfsync(4) before the working ruleset
has been loaded. Otherwise, states that are received during the
initial bulk update mismatch the correct pf-checksum and
do not attach to the rules.
Problem identified by david@. Fix done in collaboration.
OK henning@


Revision tags: OPENBSD_4_2_BASE
# 1.116 02-Aug-2007 david

move the delay for IPv6 DAD to after all interfaces have started
fixes problems with daemons being unable to bind to all addreses at boot
ok itojun@ hshoexer@


Revision tags: OPENBSD_4_1_BASE
# 1.115 15-Nov-2006 itojun

reject multicast packet without scope identifier specified.


Revision tags: OPENBSD_4_0_BASE
# 1.114 29-Jun-2006 todd

do not add an extra space; nwid and description come out wrong
fix as proposed by maja@, thanks!


Revision tags: OPENBSD_3_9_BASE
# 1.113 28-Dec-2005 david

nuke extra whitespace


# 1.112 06-Dec-2005 reyk

multicast_host=YES only works if a valid default gateway is available.
validate this condition and reject multicast traffic on failure.

ok todd@ naddy@


# 1.111 02-Nov-2005 todd

fix inspired by pr#4590
ok krw@


# 1.110 25-Oct-2005 todd

better logic from krw@:
- do not process mygate for v4 if dhcp
- do not process mygate for v6 if rtsol
this also makes the mygate processing logic more readable
ok krw@


# 1.109 14-Oct-2005 todd

add v6 support for /etc/mygate
ok deraadt@ mickey@ krw@
same functionality tested/ok'ed by by mickey, brad, matthieu, and me
with this one may now put a v6 IP in /etc/mygate on a separate line from
the v4 default gateway and netstart will do the right thing


# 1.108 12-Oct-2005 todd

shrink stripcom(), sync with install.sub
ok krw@


# 1.107 04-Oct-2005 todd

trunk must be started after physical ethernet devices, but before vlan.
populate ifmstart lines accordingly.
prodded/tested by brad@
ok reyk@


# 1.106 28-Sep-2005 todd

use eval consistently, fixes description quotes on rtsol and dhcp
fix inspired by and closes pr 4495
ok krw@


Revision tags: OPENBSD_3_8_BASE
# 1.105 22-May-2005 todd

Introduce 'ifmstart' to deal with starting multiple interfaces minus a list
of interfaces.

This reduces the netstart script by 174 chars, 13 words, and 19 lines, but
more importantly, makes it more simple and less cluttered should more special
case/orderings be needed.

ok brad@ and pr 4197 submitter, inspired by and closes pr 4197


# 1.104 04-Apr-2005 djm

unbreak; ok pval@


# 1.103 03-Apr-2005 deraadt

if dhcp is used to get an address on any interface, ignore /etc/mygate
ok krw
(this lets us do something rather cool with the zaurus in particular)


Revision tags: OPENBSD_3_7_BASE
# 1.102 04-Jan-2005 mcbride

Bring up the carp(4) interface before default route.

ok pascoe@ mpf@


# 1.101 30-Dec-2004 millert

Add a copy of stripcom so /etc/netstart can be run standalone again.
OK deraadt@


# 1.100 19-Dec-2004 millert

Allow comments in /etc/{myname,mygate,defaultdomain}; OK deraadt@


# 1.99 04-Dec-2004 itojun

remove "route $hostname 127.0.0.1" line. deraadt ok
*** please update /etc/netstart and test if it works ok for you ***


# 1.98 20-Oct-2004 deraadt

make all route commands use -qn; ok mcbride henning


Revision tags: OPENBSD_3_6_BASE
# 1.97 29-May-2004 deraadt

one last route command lacking -qn


Revision tags: OPENBSD_3_5_BASE
# 1.96 22-Mar-2004 mcbride

Make sure pfsync is brought up before carp.

ok deraadt@


# 1.95 13-Mar-2004 mcbride

Delay pfsync(4) configuration, as the syncif has to be configured in
advance. From Thorsten Lockert.


# 1.94 14-Jan-2004 deraadt

ok, it took quite a bit of prodding but itojun finally explained why the
extra sleep 1 is in here, and we came to the conclusion it is safe to
delete it. whee.


# 1.93 13-Jan-2004 deraadt

repair v6 lo0 documentation


# 1.92 11-Jan-2004 deraadt

add loopback routes late


# 1.91 09-Jan-2004 deraadt

create all routes with -q; markus ok


# 1.90 04-Dec-2003 millert

Need to do "ifconfig create" for bridge interfaces too.


# 1.89 03-Dec-2003 markus

add support for ifconfig clone; from netbsd; ok deraadt, henning


# 1.88 20-Oct-2003 david

delay carp initialization until after physical interfaces are configured
ok mcbride@ henning@ deraadt@ todd@


Revision tags: OPENBSD_3_4_BASE
# 1.87 27-Aug-2003 henning

only try to set hostname to what /etc/myname says if that file actually exists,
otherwise preserve `hostname`
netbooted machines can live perfectly fine without it; they get their hostname
earlier.

ok krw@ cedric@


Revision tags: OPENBSD_3_3_BASE
# 1.86 16-Feb-2003 krw

Fix up some DNS verbiage to make it consistant.

Fix up default route selection by

a) Forcing user to explicitly chose 'dhcp' as a mechanism for
specifying a default route, rather than guessing based on one or more
interfaces being configured by dhcp.

b) If the user specified default route does not work, re-present the
existing default route rather than losing it.

c) Move default route selection to after nameserver activation so the
user can specify a hostname as the default route.

Change /etc/netstart so that /etc/mygate wins if a default route was
already specified (i.e. by dhcp).

ok deraadt@.


Revision tags: OPENBSD_3_2_BASE
# 1.85 16-May-2002 todd

ignore non-existent cases where '$if' evaluates to '*'.
From Andr� Lucas <andre@ae-35.com>, fixes pr # 2658.
'Looks good' from miod@, millert@, and krw@.


Revision tags: OPENBSD_3_1_BASE
# 1.84 23-Feb-2002 deraadt

re-add support for $if expansion; hamajima@nagoya.ydc.co.jp


# 1.83 21-Feb-2002 miod

Change the network components initialization order.
Change from:
o all interfaces
o all bridges
o routes
to:
o physical interfaces
o routes
o gif and gre interfaces
o bridges

Fixeski PR #2400.
Manual page updates coming soon.
Ok angelos@ chris@ deraadt@


Revision tags: OPENBSD_3_0_BASE
# 1.82 31-Jul-2001 hugh

a space before a redirect


# 1.81 06-Jul-2001 angelos

Also, source /etc/rc.conf so we can pull in the
multicast_host/multicast_router settings; this is useful if one
flushes the routing table and re-initializes.

We really need a netconfig tool of sorts.


# 1.80 06-Jul-2001 angelos

Use "route -n show -inet" to determine the default multicast iface.


# 1.79 03-Jul-2001 deraadt

pull in rc.conf early so that pf(1) startup is right; tested by jasoni, comments from millert


# 1.78 30-May-2001 deraadt

Remove ipf. Darren Reed has interpreted his (old, new, whichever)
licence in a way that makes ipf not free according to the rules we
established over 5 years ago, at www.openbsd.org/goals.html (and those
same basic rules govern the other *BSD projects too). Specifically,
Darren says that modified versions are not permitted. But software
which OpenBSD uses and redistributes must be free to all (be they
people or companies), for any purpose they wish to use it, including
modification, use, peeing on, or even integration into baby mulching
machines or atomic bombs to be dropped on Australia. Furthermore, we
know of a number of companies using ipf with modification like us, who
are now in the same situation, and we hope that some of them will work
with us to fill this gap that now exists in OpenBSD (temporarily, we
hope).


Revision tags: OPENBSD_2_9_BASE
# 1.77 13-Mar-2001 deraadt

spelling; maurice@maurice.wan.nl


# 1.76 06-Feb-2001 todd

ignore blank lines in addition to comments
fixes pr#1660 from wilfried@telia.com .. Thanks!


# 1.75 10-Jan-2001 jason

support !command in bridgename.if files, too


# 1.74 27-Nov-2000 millert

Use -n to test if a variable is non-zero. Otherwise, if the variable's
contents start with a '-' test becomes unhappy (since it interprets it
as another option).


# 1.73 08-Nov-2000 todd

This fixes pr 1481, we now handle args > 6 in /etc/hostname.if in the
cases where we did not previously handle them.
Thanks to Scott Atwood <atwood@cs.stanford.edu> for reminding us of this.


Revision tags: OPENBSD_2_8_BASE
# 1.72 02-Sep-2000 todd

subtle bug .. global variables in a while loop need reset 'just incase'
With:
hostname.fxp0 having a last line of:
inet6 alias 3ffe:...
and hostname.gif0 having a first two lines of:
giftunnel 1.2.3.4
dest 1.2.4.3
We end up with the command:
ifconfig gif0 giftunnel alias 1.2.3.4 1.2.4.3
.. which is clearly wrong and fixed by this change


# 1.71 18-Jun-2000 todd

rc.conf now parses ${local_rcconf} internally; closes pr 1259


Revision tags: OPENBSD_2_7_BASE
# 1.70 08-May-2000 todd

fix dhcp 'NONE' ness from install to allow media parsing to work
.. ok deraadt@, millert@


# 1.69 21-Apr-2000 deraadt

rc.conf.local support, inspired by chuck yerkes


# 1.68 04-Apr-2000 millert

Remove the -E flag from ipf as it is implicitly enabled and using
the -E flag here causes the kernel to printf 'IP Filter: already
initialized'.


# 1.67 18-Mar-2000 deraadt

silence all extra route addition printouts


# 1.66 17-Mar-2000 itojun

correct reject route installations for IPv6. improve comments.


# 1.65 12-Mar-2000 itojun

disallow packets to malicious 6to4 prefix, based on
http://playground.iijlab.net/i-d/draft-itojun-ipv6-transition-abuse-00.txt


# 1.64 10-Mar-2000 todd

fix non behavior
with this `!' lines in /etc/hostname.* run even without certain lines
(like a comment) preceeding it.


# 1.63 10-Jan-2000 todd

allow arbitrary commands in /etc/hostname.* files if the line starts with '!'


# 1.62 02-Jan-2000 deraadt

rtsol case can configure the interface up, since it would be nice to finish
DAD before the actual rtsol(8) run happens later. and since it will rtsol,
it is going to be up in any case.


# 1.61 02-Jan-2000 itojun

one more indentation fix.


# 1.60 02-Jan-2000 itojun

indentation fix (todd's part)


# 1.59 02-Jan-2000 todd

fix rtsold case, reset cmd for each iteration!


# 1.58 02-Jan-2000 itojun

allow options after "rtsol".
XXX both "dhcp" and "rtsol" has keyword *down* at the end. is it okay?


# 1.57 02-Jan-2000 itojun

echo "IPv6 autoconf: interfaces" before invoking rtsol.
sleep for net.inet6.ip6.dad_count seconds to ensure that IPv6 DAD is completed.
TODO: rtsold (rc.conf line), manpage


# 1.56 02-Jan-2000 itojun

ipv6 autoconf on hosts (non-routers).

to do this,
1. in sysctl.conf, add these lines:
net.inet6.ip6.forwarding=0
net.inet6.ip6.accept_rtadv=1
2. in hostname.foo, add
rtsol

specifying two or more interfaces with "rtsol" may result in strange
behavior - ipv6 spec does not permit multi-interface node to be autoconfig'ed.


# 1.55 02-Jan-2000 todd

add to hostname.* parsing:
- multiple entries support (read: aliases)
- inet6 support
- support for comments (#)
(look for hostname.if(5) commit for syntax details)


# 1.54 31-Dec-1999 itojun

install IPv6 reject routes only if kernel is capable of IPv6.


# 1.53 09-Dec-1999 itojun

avoid transmitting invalid IPv6 packets out to the wire.


# 1.52 09-Dec-1999 itojun

do not perform IPv6 initialization for loopback interface.
MUST make lo0 up before any IPv6 operations.
it will be considered a pilot error if you don't.
(I prefer to have lo0 initialized automatically)


Revision tags: OPENBSD_2_6_BASE
# 1.51 01-Sep-1999 deraadt

support # characters in bridgename.* files; millert


# 1.50 01-Sep-1999 deraadt

cleanup parsing of hostname.* files, and seperate bridge control into
bridgename.* files; all documented in new hostname.if(5) and
bridgename.if(5) man pages


# 1.49 09-Aug-1999 angelos

Only parse/setup the hostname.foo file if interface foo exists (this
is useful for laptops with different ethernet cards etc.)


Revision tags: OPENBSD_2_5_BASE
# 1.48 29-Mar-1999 niklas

New multicast route setup style


# 1.47 26-Mar-1999 niklas

Add bridge interface handling


# 1.46 01-Mar-1999 millert

Add support in /etc/hostname.xxx for files of the format:
up [options]
Any of the following may or may not be set:
$name $mask $bcaddr $extras


# 1.45 28-Oct-1998 millert

Kill the awful hack used to match and split /etc/hostname.* We now use
a function, isalphanumeric, to determine whether an interface name is
likely to be valid. This means that things like /etc/hostname.le0.bak,
/etc/hostname.le0#, /etc/hostname.le0~, etc. will be ignored as they
should. There is no longer an implicate assumption that /etc/hostname.*
only contains a single '.'.


Revision tags: OPENBSD_2_4_BASE
# 1.44 06-Oct-1998 deraadt

move ipnat to end of netstart, to support dhcp+ipnat


# 1.43 18-Sep-1998 deraadt

apply media directives on dhcp interfaces


# 1.42 10-Sep-1998 marc

better way of handling dhcp client; Jason Ish <jbi130@mail.usask.ca>


# 1.41 08-Sep-1998 marc

dhcp client stuff. "Angelos D. Keromytis" <angelos@dsl.cis.upenn.edu>


# 1.40 24-Aug-1998 downsj

You can't use -interface default when there's no default gateway
set (yet). Use -interface $hostname if mygate doesn't exist so that
this actually works on routers.


# 1.39 04-Jul-1998 deraadt

put 224 route on default, to avoid a hostname lookup


# 1.38 22-May-1998 deraadt

use route -n, what the heck


Revision tags: OPENBSD_2_3_BASE
# 1.37 28-Mar-1998 deraadt

s/^nat/ipnat/


# 1.36 23-Feb-1998 niklas

remove trailing blank line


# 1.35 07-Feb-1998 deraadt

ipforward is in sysctl.conf now


# 1.34 21-Dec-1997 deraadt

ugh


# 1.33 20-Dec-1997 deraadt

ipforwarding option in rc.conf


# 1.32 29-Nov-1997 kstailey

NAT requires IPF


# 1.31 04-Nov-1997 deraadt

kill spaces at ends of lines; m4


Revision tags: OPENBSD_2_2_BASE
# 1.30 14-Oct-1997 deraadt

set hostname/domainname before running rc.conf; m4@umn.edu


# 1.29 04-Sep-1997 deraadt

fork netstart; new child is rc.conf


# 1.28 25-Aug-1997 millert

Explicately pass -host flag to route(8) to avoid confusion with networks.


# 1.27 19-Aug-1997 niklas

Add hook for rpc.lockd, make nfsd flags settable in netstart


# 1.26 31-Jul-1997 downsj

Make quotas optional; wedged into netstart for the time being.
/etc/rc.conf, anyone?


# 1.25 30-Jul-1997 deraadt

do not run routed by default


# 1.24 28-Jul-1997 kstailey

Move configuration of loopback interface to before all other interfaces.
Allows the use of local caching-only nameserver with no "nameserver"
entry in /etc/resolv.conf to configure a route between the hostname
and loopback.


# 1.23 25-Jul-1997 provos

earlier start of keymanagement


# 1.22 24-Jul-1997 deraadt

make amd use /tmp_mnt by default


# 1.21 22-Jul-1997 provos

start the photuris daemon per default. hilfe.


# 1.20 17-Jun-1997 niklas

Put in hooks to start ypserv with flags


# 1.19 17-Jun-1997 niklas

Put in hooks to start rpc.yppasswdd with flags


Revision tags: OPENBSD_2_1_BASE
# 1.18 15-Apr-1997 deraadt

kill route flush until .. hmm kernel routing socket bug or something


# 1.17 09-Apr-1997 kstailey

add NAT startup


# 1.16 07-Apr-1997 rees

flush all old routes before adding new interfaces or routes.
ref: netbsd pr3228/misc, Matthias Scheler


# 1.15 03-Mar-1997 downsj

fix typo


# 1.14 11-Feb-1997 deraadt

add default route before fiddling with loopback route to avoid DNS problems; m4@umn.edu, #97


# 1.13 03-Feb-1997 deraadt

do ifaliases after /usr/bin exists in nfs diskless env; pr#77, matthieu@laas.fr


# 1.12 02-Nov-1996 deraadt

timed off by default


Revision tags: OPENBSD_2_0_BASE
# 1.11 23-Sep-1996 deraadt

rfc1323 variable


# 1.10 04-Sep-1996 deraadt

control portmap, inetd, and lpd from netstart; idea from tqbf@enteract.com


# 1.9 27-Aug-1996 deraadt

224.0.0.0 not 0.0.0.224; from peter@demon.net


# 1.8 18-Jun-1996 deraadt

move std stuff from rc.local to rc


# 1.7 16-Jun-1996 deraadt

install sample commented /etc/ifaliases file; which can now contain #
comments and blank lines. new format is "interface address netmask"
(yes, i changed the order of the entries). inspired by netbsd pr#2474;
gillhaa@ghost.whirlpool.com


# 1.6 02-Jun-1996 tholo

Install a multicast route by default


# 1.5 26-May-1996 deraadt

sync & label


# 1.4 09-Jan-1996 dm

added IP filter to netstat/rc and put examples in /usr/share/ipf


# 1.3 30-Dec-1995 deraadt

from netbsd: start mrouted like routed


# 1.2 18-Dec-1995 deraadt

/etc/ifaliases support by randy@zyzzyva.com


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.217 22-Feb-2022 dlg

add some more tunnels to the list of interfaces that rely on routing.


Revision tags: OPENBSD_7_0_BASE
# 1.216 02-Sep-2021 bluhm

Do not create loopback interfaces lo1, lo2, ... upfront. They are
automatically set up by the kernel when a routing domain is created.
An existing lo1 in rdomain 0 would prevent to add any interfaces
in rdomain 1.
OK kn@


# 1.215 30-Aug-2021 bluhm

Improve dubgging in /etc/netstart. Enable print only in ifcreate.
Add debugging output for ipv6 routes. Make localhost and multicast
code aware of the print only switch. Allow netstart -n to work
also if no interface is given.
OK kn@


# 1.214 06-Aug-2021 sthen

As tim@ spotted, a use of V4_AUTOCONF crept in when the variable name
was actually V4_DHCPCONF from previous use. Rename all of the V4_DHCPCONF
to V4_AUTOCONF so everything uses the new name. ok and reminder about
the installer from tb@


# 1.213 16-Jul-2021 florian

switch to dhcpleased/resolvd in base
OK deraadt


# 1.212 20-Jun-2021 florian

Don't try to install a default route with route(8) later on if we are
using inet autoconf, like we do with "dhcp" and "inet6 autoconf".
OK kn


Revision tags: OPENBSD_6_9_BASE
# 1.211 23-Dec-2020 krw

Allow the provision of dhclient(8) options on 'dhcp' lines in hostname.if(5)
files.

Usual man page help & ok jmc@


# 1.210 21-Dec-2020 krw

Avoid issuing pointless 'ifconfig <if> up' when processing 'dhcp' in
hostname.if files. dhclient(8) does that itself. Part of the
"further script optimizations" promised in r1.200 of netstart.

Tested & ok gnezdo@


# 1.209 29-Nov-2020 tb

Fix previous: use correct version of netstart and installer bits.


# 1.208 29-Nov-2020 deraadt

Add support for !command to mygate, so that netstart has a late opportunity
to perform network configuration (for example, "!route source -ifp em0")
Split mygate and myname manual pages (how did anyone ever believe these
are related), and perform hostname configuration much earlier in rc.
discussed with benno, claudio, jmc, etc etc, last version of !command
parser by tb


# 1.207 08-Nov-2020 jmc

no more mobileip;
ok claudio deraadt


Revision tags: OPENBSD_6_8_BASE
# 1.206 21-Jun-2020 dlg

start wg with the other interfaces that rely on routing being up.

from Matt Dunwoodie and Jason A. Donenfeld

ok deraadt@


# 1.205 22-May-2020 kn

Revert the following commit as it breaks hostname.if(5) lines with a
backslash at the end for line continuation

Breaking long lines into multiple ones must still be possible and does
require to treat the backslash as an escape character.

Breakage reported by Mark Patruck <mark at wrapped dot cx >, thanks!

---
distrib/miniroot/install.sub revision 1.1151
etc/netstart revision 1.203
date: 2020/05/21 11:54:41; author: kn; state: Exp; lines: +2 -2;
Do not treat backslashe as an escape character in hostname.if(5) lines

ifstart() should always pass such lines unaltered, especially if they
contain "nwid" or "description" lines with arbitrary strings.

<bsdlisten at gmail dot com> reported SSIDs such as "Mike's" during
installation end as broken; this was because the installer escaped
the single quote using backslashes which ended up being treated as
escape characters much later during hostname.if parsing in netstart(8).

Ok deraadt


# 1.204 21-May-2020 kn

Fix stripcom() description wrt. comments not on their own line

Neither netstart's nor install.sub's (subtly different) implementations
remove trailing comments on lines not starting as a comment, e.g.,
lines like "up #not down" go through unaltered and without "#not down"
being removed.

Only lines *beginning* with the comment sign ("#") are stripped.

No functional change, just updating function descriptions.


# 1.203 21-May-2020 kn

Do not treat backslashe as an escape character in hostname.if(5) lines

ifstart() should always pass such lines unaltered, especially if they
contain "nwid" or "description" lines with arbitrary strings.

<bsdlisten at gmail dot com> reported SSIDs such as "Mike's" during
installation end as broken; this was because the installer escaped
the single quote using backslashes which ended up being treated as
escape characters much later during hostname.if parsing in netstart(8).

Ok deraadt


Revision tags: OPENBSD_6_7_BASE
# 1.202 15-Jan-2020 kn

Do not redirect already quiet stdout for IPv6 reject routes

"route -q" already silences all standard output; if it still prints
something, that's a bug to fix in route.

OK bluhm


# 1.201 25-Oct-2019 dlg

handle aggr(4) in the same way as trunk(4)

from brad@
ok bluhm@ claudio@ deraadt@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.200 29-Aug-2018 krw

Historically /etc/netstart (and the equivalent code in the install
script) did 'ifconfig <if> down' before starting dhclient(8). This was
a way of ensuring old running copies of dhclient were killed before a
new one started. Current dhclient does not need this assist, so change
"ifconfig <if> down" to "ifconfig <if> up" pending further script
optimizations.

Similar to a 2014 attempt by halex@. Prompted by a misc@ report
from Kristjan Komlosi reporting hanging diskless setups.

ok halex@ kn@


# 1.199 08-Jul-2018 tb

netstart is used during system start, but also interactively.
Show proper error message if a regular user executes netstart.
Only do the privilege check if the id binary is available,
which might not be the case during diskless system startup.

ok deraadt, jasper, jca, krw, rpe (who wrote the same diff), sthen


# 1.198 28-Apr-2018 rpe

Add a proper usage() function.

Suggested by and OK jmc.
OK tb


Revision tags: OPENBSD_6_3_BASE
# 1.197 04-Mar-2018 jmc

when -n is used, no need to spit out "Missing parameters." before
displaying usage();

ok tb


# 1.196 03-Mar-2018 landry

Lowercase 'usage' and group -n with interface in it.
From jmc@, ok tb@


# 1.195 21-Feb-2018 rpe

Tweak comments.

OK tb


# 1.194 19-Feb-2018 rpe

Write warning/error messages to stderr and end them with a fullstop.

OK tb


# 1.193 19-Feb-2018 rpe

- use specific patterns when looping over /etc/hostname.if files
to skip backup or temp files.
- test if the patterns matched actual files
- warn if ifcreate() fails on an interface and continue with the
subsequent interfaces in the list instead of return'ing

OK dlg sthen tb


# 1.192 17-Feb-2018 rpe

- Add descriptions for the new functions ifcreate() and vifscreate()
- In ifcreate() use the exit code of the {} block directly
- In vifscreate(), use the ifconfig -C output directly in the for _vif loop
- Remove superfluous and somewhat confusing comment

OK dlg kn sthen


# 1.191 14-Feb-2018 dlg

create virtual interfaces before starting all interface config.

this resolves an ordering problem when adding pseudo interfaces to bridges

tweaks from kn@
ok mpi@ sthen@


# 1.190 10-Feb-2018 claudio

Remove some special IPv4 in IPv6 mapped prefixes that are already rejected
by the ::0.0.0.0/96 reject route added to deny all IPv4 mapped addresses.
Makes the inet6 routing table almost fit in one screen.
OK benno@


# 1.189 10-Feb-2018 florian

Load RFC 7217 key material and generate if it does not already exist.

Add soii.key to changelist (pointed out by semarie) and mtree/special
(suggest by Craig Skinner).

OK naddy, sthen, rpe, tb


# 1.188 06-Feb-2018 tb

If -n is given, the netstart script should not (try to) set the default
route(s). Simply print the command(s) to be issued instead.

tweak & ok rpe


# 1.187 12-Nov-2017 tb

Remove HN_DIR variable and expand it in the only place it was used. It
currently serves no purpose.

ok rpe, agreement from deraadt and halex


Revision tags: OPENBSD_6_2_BASE
# 1.186 25-Jul-2017 rpe

Finally remove backwards compat code to support the 'rtsol' keyword
in hostname.if(5)

OK mpi@ deraadt@ florian@
OK jmc@ from doc perspective


# 1.185 21-Jul-2017 rpe

Align ifstart() in netstart and install.sub.

- in netstart, rename _file to _hn referencing hostname.if files
- in install.sub switch ifstart() to be used with _if instead of
_hn as parameter

ok krw@ tb@


# 1.184 28-May-2017 awolk

etc/netstart: use colon separator instead of dot with chown

OK jung@, deraadt@, jmc@


# 1.183 07-May-2017 rpe

Change test from [] to [[]] and simplify pattern.

OK tb@, krw@ (for [[]])
Feedback and OK halex@


# 1.182 07-May-2017 rpe

Replace hardcoded script name with ${0##*/}

OK tb@ halex@


# 1.181 01-May-2017 rpe

Revert r1.170 and remove the id==0 check.
The id binary is not available in nfs diskless setups at this point.

reported by Andreas Kusalananda, thanks.
discussed with deraadt@


# 1.180 01-May-2017 rpe

Remove last remnants of rtsol. IPv6 autoconfiguration of interfaces is now
done in ifstart(). Remove ipv6autoconf() and replace rtsolif with a boolean
variable V6_AUTOCONF. Replace dhcpif with a boolean variable V4_DHCPCONF.
Both are later used in defaultroute() to decide whether or not to configre
defaultroutes from /etc/mygate.

OK krw@


# 1.179 30-Apr-2017 mpi

Do not try to delete a default route before adding it.

Now that route are automatically G/C with the address they are attached
to there's no reason to duplicate the kernel's job.

Fix a regression introduced with multipath default routes.

ok deraadt@


# 1.178 25-Apr-2017 rpe

Unbreak netstart for multiple inteface configurations like trunk
or carp. Ensure that the noglob option is disabled at the end of
parse_hn_line() and ifstart().

Reported by Christer Solskogen and Stefan Wollny, thanks!


# 1.177 24-Apr-2017 rpe

Introduce a new function parse_hn_line() that replaces the existing
hostname.if(5) parsing code in ifstart().
Add a -n option to netstart to only print the interface configuration
commands instead of executing them.
Add a HN_DIR variable, that points to the directory of the hostname.if
files (default /etc) that allows for future regression tests.

- add new parse_hn_line() function
- change ifstart()
- rename $if to $_if
- don't ifconfig or ifconfig create if -n option is used
- replace hostname.if(5) parsing code with new parse_hn_line()
- just print configuration commands if -n option is used
- autoconf now happens in ifstart(), remove ifv6autoconf()
- introduce HN_DIR variable for the hostname.if file location
- add handling of the -n option to only print config commands
- ensure -n is only used if interfaces are specified as parameters

Discussed with and positive feedback from many
'commit' deraadt@
OK sthen@


# 1.176 08-Apr-2017 rpe

- localize the if, file and stat variables which also ensures that
variables are not named like commands.
- change test from [] to [[]]

OK tb@ halex@


# 1.175 07-Apr-2017 rpe

Minimize differences in ifstart() function between netstart and
install.sub which makes it easier to spot changes in the future.

- comments and formatting
- quotes on assignments are not needed (netstart)
- remove stray space in test (netstart)
- use $file variable with while-loop (netstart)
- although valid, instead of i use $i in arithmetic test (install.sub)

OK krw@, tb@
Looks good deraadt@


# 1.174 07-Apr-2017 rpe

Align comments of ifstart() function in netstart and install.sub.


# 1.173 07-Apr-2017 rpe

Align comments of stripcom() function in netstart and install.sub.


Revision tags: OPENBSD_6_1_BASE
# 1.172 06-Dec-2016 mpi

Do not lose the default route when netstart(8) is run a second time on
the interface pointed to by the default route.

Since the kernel no longer keep routes with dangling address pointer,
netstart(8) has to re-add the default route when the corresponding ifa
has been deleted and re-created.

deraadt@ points out that even if the previous semantic was not necessarily
better, a script like netstart(8) cannot totally fix the default route
problem.

Regression reported by and fix tested by Hrvoje Popovski.

ksh foo checked by halex@


# 1.171 27-Sep-2016 rzalamena

Delay switch(4) interface start up so it can attach virtual interfaces
like vether(4).

nits from and ok benno@, phessler@


# 1.170 09-Sep-2016 jasper

print a clear error message when not ran as root instead of just falling
through and try whatever it can do with the invoking user's perms

feedback/ok aja@ rpe@


Revision tags: OPENBSD_6_0_BASE
# 1.169 19-Jul-2016 mpi

Do not consider tap(4) a special interface and start if before other
pseudo-interfaces.

This unbreak vlan(4) on top of tap(4) since the refactoring to turn it
MP-safe.

ok claudio@, deraadt@


# 1.168 27-Mar-2016 sthen

Don't delete the 224/4 route in netstart, unless it's being done to ensure that
a -reject route can be added. Restores the ability to set an interface route
before daemons are started, lost during the previous simplification.
ok millert mpi


Revision tags: OPENBSD_5_9_BASE
# 1.167 29-Dec-2015 rpe

Remove backslash, not necessary after '&&'

OK halex@


# 1.166 29-Dec-2015 rpe

Replace last remaining `` with $()

OK halex@


# 1.165 18-Dec-2015 ajacoutot

Drop the now useless multicast setup comment.

prodded by tim@, ok mpi@


# 1.164 17-Dec-2015 ajacoutot

Simplify multicast option handling (10 less lines) by matching /etc/rc behavior
towards other YES|NO options and drop the error warning.


with and ok tim@, ok rpe@ on an earlier diff


# 1.163 05-Dec-2015 mpi

It does not make sense to insert a specific route for 224/4 when the
default one is good enough.

So merge rc.conf(8)'s 'multicast_router' and 'multicast_host' into a
single 'multicast'. If set to YES the reject route for 224/4 is not
inserted by netstart(8).

Manual bits from jmc@

ok henning@, ajacoutot@


# 1.162 12-Nov-2015 rpe

Changes to ifautostart():
- Rename function to ifv6autoconf() to make IPv6 relation clearer
- Localize and rename variables

OK krw@


# 1.161 12-Nov-2015 rpe

Changes to ifmstart():
- Change comments to make it clearer that ifmstart() takes two lists
of interface driver names (of which the second is optional) and not
the actual interface instances.
- Use localized variables and use slightly more verbose names.
- Use continue 2 to skip to the next hostname.if file.
- Use shell pattern @() instead of testing _sif individually.

OK krw@


# 1.160 12-Nov-2015 rpe

Changes to stripcom():
- Align comments with /etc/rc version
- Use localized variables
- Use safer "print -r --" instead of plain echo

Changes to ifstart():
- Tweak comment
- Add usage

OK krw@


# 1.159 01-Nov-2015 rpe

Start the rework of the /etc/netstart shell script.

General changes:
- apply a similar 'style' as used in the installer scripts
- improve comments to be more to the point, remove where code is obvious
- document usage of functions if they have arguments
- rename variables where it improves readability
- replace really old-school shell code with more contemporary idioms

Other changes:
- No need to care about "autoboot" because netstart doesn't inherit the
positional parameters from /etc/rc anymore. /etc/rc executes netstart
instead of sourcing it since r1.439.
- Use simpler for-loop to process list of interfaces with ifstart.

OK halex@


# 1.158 26-Oct-2015 rpe

The hostname variable is not used since r1.99. Remove it and use
stripcom() output directly with the hostname command.

OK deraadt@ krw@


# 1.157 23-Oct-2015 claudio

netstart bits for tap(4)


# 1.156 27-Sep-2015 sthen

Don't print output when setting autoconf on interfaces. Suggested by deraadt,
ok florian@ rpe@


# 1.155 13-Sep-2015 sthen

only print the "IPv6 autoconf" line if there are interfaces to configure
feedback/ok rpe


# 1.154 11-Sep-2015 sthen

Set "inet6 autoconf" individually on interfaces that have rtsol set in
hostname.if, previously netstart tried to configure them all at once
("ifconfig if0 if1 if2 inet6 autoconf"). From Delan Azabani, ok phessler@


Revision tags: OPENBSD_5_8_BASE
# 1.153 20-Jul-2015 rpe

Disable Strict Bourne shell mode for /etc/rc and /etc/netstart to be
able to use ksh syntax within these scripts. This way init doesn't
need to be changed, which starts /etc/rc using /bin/sh and people
can still use "sh /etc/netstart ifname".

Idea from and OK halex@
OK deraadt@ krw@ guenther@


# 1.152 19-Jul-2015 florian

Bring up pflow last as it might send with a source address that is on
any of the other interfaces.
OK deraadt, phessler, benno


# 1.151 19-Jul-2015 rpe

Always source rc.subr to be able to use the rc.conf parsing routine
to get the network related vars from rc.conf. This is even necessary
if netstart is run from within /etc/rc. Remove test of $INRC which
unintentionally evaluated always to true.

problem with previous change found by nigel@
OK sthen@ aja@ halex@


# 1.150 19-Jul-2015 ajacoutot

Revert 1.148 for now until I can talk to rpe@
It introduced a regression reported by nigel@


# 1.149 19-Jul-2015 rpe

Replace test command with [].

OK halex@ krw@


# 1.148 19-Jul-2015 rpe

Ensure, that we source rc.subr and parse rc.conf ONLY if we are not
inside /etc/rc.

With help from and OK halex@, ajacoutot@


# 1.147 18-Jul-2015 rpe

- remove trailing blanks introduced in previous commit
- no space in redirections like </foo or >$bar
- few other minor whitespaces

OK krw@


# 1.146 18-Jul-2015 rpe

Improve comments
- Add comments for functions
- Start comments with capital letters
- End comments with a full stop
- Allow comments to extend up to column 80

OK krw@


# 1.145 06-Jun-2015 florian

Allow rtsol keyword in hostname.if(5) with net.inet6.ip6.forwarding=1.
"inet6 autoconf" was working before and rtsol should behave the same.
OK phessler


Revision tags: OPENBSD_5_7_BASE
# 1.144 03-Dec-2014 florian

The kernel handles rtsol(8) functionality since some time now.
Treat rtsol in hostname.if as a keyword like dhcp and call ifconfig
inet6 autoconf.
"reads good" todd@
OK krw@ (who is *not* an IPv6 person), but I recruited him in his
capacity as an installer person.


# 1.143 28-Sep-2014 claudio

Revert 1.142. Without the down netstart will just print the ifconfig
output because it may end up just calling 'ifconfig $if'. This needs
to be done better and properly tested.


# 1.142 26-Sep-2014 halex

remove explicit 'down' of an interface before starting a dhcp request, thereby
avoiding annoying delays for some switch configurations

ok claudio@ deraadt@

i would add ok phessler@, but it was not valid without an ok krw@


Revision tags: OPENBSD_5_6_BASE
# 1.141 12-Jul-2014 stsp

Fix netstart after autoconf6 change so 'rtsol' lines in hostname.if work again.
found by pelikan@; ok pelikan@ henning@


# 1.140 12-Jul-2014 robert

Make rc.conf a parsed configuration file and stop sourcing it as a shell
script.
From now on rc.conf has a fixed syntax (key=val) and it is not allowed
to add anything to it besides the supported syntax, it all going to be
ignored.

discussed with and help from deraadt@ and halex@


Revision tags: OPENBSD_5_5_BASE
# 1.139 22-Aug-2013 mpi

Like for dhclient, do no create a route to alias addresses via 127.0.0.1.
Our stack is able to tell if the address is local or not.

ok todd@, krw@


Revision tags: OPENBSD_5_4_BASE
# 1.138 20-Mar-2013 todd

fix lies in netstart; replacement wording from halex@
pointed out by Ryan Kavannagh rak at debian dot org


Revision tags: OPENBSD_5_3_BASE
# 1.137 05-Dec-2012 rpe

remove "Invalid interface name" message
requested by krw@

ok halex@


# 1.136 02-Dec-2012 rpe

use the more compact version of the check for ifconfig'able interfaces
from install.sub

with feedback from and ok halex


# 1.135 02-Dec-2012 rpe

- remove isalphanumeric() and replace it with a shell pattern, that
tries a bit harder to identify invalid interface names and in
this case emit an error message.
- use [[ $1 == autoboot ]] to avoid a shell error message due to
possible spaces in first argument
- no change in functionality

discussed with krw and halex
ok ("I like this") krw


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.134 07-Oct-2011 deraadt

The new ypbind changes requires that the domainname be set before
rc.conf is run. There's no real downside.
ok aja


Revision tags: OPENBSD_5_0_BASE
# 1.133 07-Jul-2011 guenther

Eliminate some $? tests by rolling the command into the condition

ok halex@


# 1.132 26-May-2011 mpf

Add svlan(4) startup bits.
From markus@. OK naddy, claudio, reyk.


Revision tags: OPENBSD_4_9_BASE
# 1.131 09-Feb-2011 sobrado

fix an unbalanced parenthesis in a comment; while here, split the comment
in a better place to make it more readable.

ok jmc@ and miod@


Revision tags: OPENBSD_4_8_BASE
# 1.130 16-Jun-2010 todd

permit e.g. -inet6 syntax by slurping all lines not just some
noticed by rhsv6 at hushmail dot com, ok sthen@


Revision tags: OPENBSD_4_7_BASE
# 1.129 12-Jan-2010 henning

when setting up lo0 use 127.0.0.1/8 instead of 127.0.0.1 for clarity and
correctness. it's not 1992 any more, kids. ok mcbride dlg krw


# 1.128 10-Dec-2009 todd

o stop reordering ifconfig arguments (e.g. after 'up ..')
o only stop processing if inet or inet6 lines are malformed
o everything not a specially handled bit is passed to ifconfig unmangled
noticed by several after the move from bridgename.bridge0 -> hostname.bridge0
prodded by deraadt@, tested by and feedback from several
man page bits 'look fine' jmc@


# 1.127 22-Nov-2009 deraadt

Stop supporting bridgename.bridge* files, and move to hostname.bridge*
files. To cope with this change, read about the mv command.
ok claudio todd


# 1.126 17-Sep-2009 simon

change variable i to $i in an expression of ifstart() for consistency
with the rest of the file. no functional change.

feedback from sthen@, ok krw@


# 1.125 10-Jul-2009 jdixon

Delay creation of tun(4) interfaces until the underlying interface and
routes are available. This fixes usage for some OpenVPN users that start
it from hostname.tun*.

Tested by Johan Huldtgren. ok sthen@, johan@.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.124 25-Nov-2008 markus

delay /etc/netstart until IPv6-DAD (dup-address-detection) is completed.
ok fries, hshoexer, claudio


# 1.123 14-Aug-2008 sthen

Tools from /usr may not be used in netstart since it may be NFS-mounted
and not available at that time. Rewrite the hostname.if permission check
to use only /bin/ls and the shell. Requested by deraadt.

ok todd, "Twisted." deraadt


Revision tags: OPENBSD_4_4_BASE
# 1.122 23-Jul-2008 sthen

Prevent warning about insecure hostnames where no /etc/hostname.*
exists. From wcmaier@.

Check target of symbolic links to avoid noise at boot and in
seucrity output where you have several interfaces symlinked to one
config file.

"If you think this is the right thing to do" deraadt@


# 1.121 09-Jun-2008 todd

warn once not 3 times in case of a non existent file, discussed with deraadt
originally pointed out by Johan Torin


# 1.120 09-Jun-2008 deraadt

Ensure that hostname.* files are also re-chowned to root.wheel at each
boot as discussed with claudio while eating tasty donairs. ok todd


# 1.119 17-Apr-2008 deraadt

before using them, force hostname.* files to be unreadable by world
first version from todd, ok millert


Revision tags: OPENBSD_4_3_BASE
# 1.118 17-Jan-2008 brad

Execute rtsol after turning up trunk(4) and vlan(4) interfaces so they're
taken into consideration for rtsol.

ok reyk@ dlg@


# 1.117 09-Jan-2008 mpf

Do not bring up pfsync(4) before the working ruleset
has been loaded. Otherwise, states that are received during the
initial bulk update mismatch the correct pf-checksum and
do not attach to the rules.
Problem identified by david@. Fix done in collaboration.
OK henning@


Revision tags: OPENBSD_4_2_BASE
# 1.116 02-Aug-2007 david

move the delay for IPv6 DAD to after all interfaces have started
fixes problems with daemons being unable to bind to all addreses at boot
ok itojun@ hshoexer@


Revision tags: OPENBSD_4_1_BASE
# 1.115 15-Nov-2006 itojun

reject multicast packet without scope identifier specified.


Revision tags: OPENBSD_4_0_BASE
# 1.114 29-Jun-2006 todd

do not add an extra space; nwid and description come out wrong
fix as proposed by maja@, thanks!


Revision tags: OPENBSD_3_9_BASE
# 1.113 28-Dec-2005 david

nuke extra whitespace


# 1.112 06-Dec-2005 reyk

multicast_host=YES only works if a valid default gateway is available.
validate this condition and reject multicast traffic on failure.

ok todd@ naddy@


# 1.111 02-Nov-2005 todd

fix inspired by pr#4590
ok krw@


# 1.110 25-Oct-2005 todd

better logic from krw@:
- do not process mygate for v4 if dhcp
- do not process mygate for v6 if rtsol
this also makes the mygate processing logic more readable
ok krw@


# 1.109 14-Oct-2005 todd

add v6 support for /etc/mygate
ok deraadt@ mickey@ krw@
same functionality tested/ok'ed by by mickey, brad, matthieu, and me
with this one may now put a v6 IP in /etc/mygate on a separate line from
the v4 default gateway and netstart will do the right thing


# 1.108 12-Oct-2005 todd

shrink stripcom(), sync with install.sub
ok krw@


# 1.107 04-Oct-2005 todd

trunk must be started after physical ethernet devices, but before vlan.
populate ifmstart lines accordingly.
prodded/tested by brad@
ok reyk@


# 1.106 28-Sep-2005 todd

use eval consistently, fixes description quotes on rtsol and dhcp
fix inspired by and closes pr 4495
ok krw@


Revision tags: OPENBSD_3_8_BASE
# 1.105 22-May-2005 todd

Introduce 'ifmstart' to deal with starting multiple interfaces minus a list
of interfaces.

This reduces the netstart script by 174 chars, 13 words, and 19 lines, but
more importantly, makes it more simple and less cluttered should more special
case/orderings be needed.

ok brad@ and pr 4197 submitter, inspired by and closes pr 4197


# 1.104 04-Apr-2005 djm

unbreak; ok pval@


# 1.103 03-Apr-2005 deraadt

if dhcp is used to get an address on any interface, ignore /etc/mygate
ok krw
(this lets us do something rather cool with the zaurus in particular)


Revision tags: OPENBSD_3_7_BASE
# 1.102 04-Jan-2005 mcbride

Bring up the carp(4) interface before default route.

ok pascoe@ mpf@


# 1.101 30-Dec-2004 millert

Add a copy of stripcom so /etc/netstart can be run standalone again.
OK deraadt@


# 1.100 19-Dec-2004 millert

Allow comments in /etc/{myname,mygate,defaultdomain}; OK deraadt@


# 1.99 04-Dec-2004 itojun

remove "route $hostname 127.0.0.1" line. deraadt ok
*** please update /etc/netstart and test if it works ok for you ***


# 1.98 20-Oct-2004 deraadt

make all route commands use -qn; ok mcbride henning


Revision tags: OPENBSD_3_6_BASE
# 1.97 29-May-2004 deraadt

one last route command lacking -qn


Revision tags: OPENBSD_3_5_BASE
# 1.96 22-Mar-2004 mcbride

Make sure pfsync is brought up before carp.

ok deraadt@


# 1.95 13-Mar-2004 mcbride

Delay pfsync(4) configuration, as the syncif has to be configured in
advance. From Thorsten Lockert.


# 1.94 14-Jan-2004 deraadt

ok, it took quite a bit of prodding but itojun finally explained why the
extra sleep 1 is in here, and we came to the conclusion it is safe to
delete it. whee.


# 1.93 13-Jan-2004 deraadt

repair v6 lo0 documentation


# 1.92 11-Jan-2004 deraadt

add loopback routes late


# 1.91 09-Jan-2004 deraadt

create all routes with -q; markus ok


# 1.90 04-Dec-2003 millert

Need to do "ifconfig create" for bridge interfaces too.


# 1.89 03-Dec-2003 markus

add support for ifconfig clone; from netbsd; ok deraadt, henning


# 1.88 20-Oct-2003 david

delay carp initialization until after physical interfaces are configured
ok mcbride@ henning@ deraadt@ todd@


Revision tags: OPENBSD_3_4_BASE
# 1.87 27-Aug-2003 henning

only try to set hostname to what /etc/myname says if that file actually exists,
otherwise preserve `hostname`
netbooted machines can live perfectly fine without it; they get their hostname
earlier.

ok krw@ cedric@


Revision tags: OPENBSD_3_3_BASE
# 1.86 16-Feb-2003 krw

Fix up some DNS verbiage to make it consistant.

Fix up default route selection by

a) Forcing user to explicitly chose 'dhcp' as a mechanism for
specifying a default route, rather than guessing based on one or more
interfaces being configured by dhcp.

b) If the user specified default route does not work, re-present the
existing default route rather than losing it.

c) Move default route selection to after nameserver activation so the
user can specify a hostname as the default route.

Change /etc/netstart so that /etc/mygate wins if a default route was
already specified (i.e. by dhcp).

ok deraadt@.


Revision tags: OPENBSD_3_2_BASE
# 1.85 16-May-2002 todd

ignore non-existent cases where '$if' evaluates to '*'.
From Andr� Lucas <andre@ae-35.com>, fixes pr # 2658.
'Looks good' from miod@, millert@, and krw@.


Revision tags: OPENBSD_3_1_BASE
# 1.84 23-Feb-2002 deraadt

re-add support for $if expansion; hamajima@nagoya.ydc.co.jp


# 1.83 21-Feb-2002 miod

Change the network components initialization order.
Change from:
o all interfaces
o all bridges
o routes
to:
o physical interfaces
o routes
o gif and gre interfaces
o bridges

Fixeski PR #2400.
Manual page updates coming soon.
Ok angelos@ chris@ deraadt@


Revision tags: OPENBSD_3_0_BASE
# 1.82 31-Jul-2001 hugh

a space before a redirect


# 1.81 06-Jul-2001 angelos

Also, source /etc/rc.conf so we can pull in the
multicast_host/multicast_router settings; this is useful if one
flushes the routing table and re-initializes.

We really need a netconfig tool of sorts.


# 1.80 06-Jul-2001 angelos

Use "route -n show -inet" to determine the default multicast iface.


# 1.79 03-Jul-2001 deraadt

pull in rc.conf early so that pf(1) startup is right; tested by jasoni, comments from millert


# 1.78 30-May-2001 deraadt

Remove ipf. Darren Reed has interpreted his (old, new, whichever)
licence in a way that makes ipf not free according to the rules we
established over 5 years ago, at www.openbsd.org/goals.html (and those
same basic rules govern the other *BSD projects too). Specifically,
Darren says that modified versions are not permitted. But software
which OpenBSD uses and redistributes must be free to all (be they
people or companies), for any purpose they wish to use it, including
modification, use, peeing on, or even integration into baby mulching
machines or atomic bombs to be dropped on Australia. Furthermore, we
know of a number of companies using ipf with modification like us, who
are now in the same situation, and we hope that some of them will work
with us to fill this gap that now exists in OpenBSD (temporarily, we
hope).


Revision tags: OPENBSD_2_9_BASE
# 1.77 13-Mar-2001 deraadt

spelling; maurice@maurice.wan.nl


# 1.76 06-Feb-2001 todd

ignore blank lines in addition to comments
fixes pr#1660 from wilfried@telia.com .. Thanks!


# 1.75 10-Jan-2001 jason

support !command in bridgename.if files, too


# 1.74 27-Nov-2000 millert

Use -n to test if a variable is non-zero. Otherwise, if the variable's
contents start with a '-' test becomes unhappy (since it interprets it
as another option).


# 1.73 08-Nov-2000 todd

This fixes pr 1481, we now handle args > 6 in /etc/hostname.if in the
cases where we did not previously handle them.
Thanks to Scott Atwood <atwood@cs.stanford.edu> for reminding us of this.


Revision tags: OPENBSD_2_8_BASE
# 1.72 02-Sep-2000 todd

subtle bug .. global variables in a while loop need reset 'just incase'
With:
hostname.fxp0 having a last line of:
inet6 alias 3ffe:...
and hostname.gif0 having a first two lines of:
giftunnel 1.2.3.4
dest 1.2.4.3
We end up with the command:
ifconfig gif0 giftunnel alias 1.2.3.4 1.2.4.3
.. which is clearly wrong and fixed by this change


# 1.71 18-Jun-2000 todd

rc.conf now parses ${local_rcconf} internally; closes pr 1259


Revision tags: OPENBSD_2_7_BASE
# 1.70 08-May-2000 todd

fix dhcp 'NONE' ness from install to allow media parsing to work
.. ok deraadt@, millert@


# 1.69 21-Apr-2000 deraadt

rc.conf.local support, inspired by chuck yerkes


# 1.68 04-Apr-2000 millert

Remove the -E flag from ipf as it is implicitly enabled and using
the -E flag here causes the kernel to printf 'IP Filter: already
initialized'.


# 1.67 18-Mar-2000 deraadt

silence all extra route addition printouts


# 1.66 17-Mar-2000 itojun

correct reject route installations for IPv6. improve comments.


# 1.65 12-Mar-2000 itojun

disallow packets to malicious 6to4 prefix, based on
http://playground.iijlab.net/i-d/draft-itojun-ipv6-transition-abuse-00.txt


# 1.64 10-Mar-2000 todd

fix non behavior
with this `!' lines in /etc/hostname.* run even without certain lines
(like a comment) preceeding it.


# 1.63 10-Jan-2000 todd

allow arbitrary commands in /etc/hostname.* files if the line starts with '!'


# 1.62 02-Jan-2000 deraadt

rtsol case can configure the interface up, since it would be nice to finish
DAD before the actual rtsol(8) run happens later. and since it will rtsol,
it is going to be up in any case.


# 1.61 02-Jan-2000 itojun

one more indentation fix.


# 1.60 02-Jan-2000 itojun

indentation fix (todd's part)


# 1.59 02-Jan-2000 todd

fix rtsold case, reset cmd for each iteration!


# 1.58 02-Jan-2000 itojun

allow options after "rtsol".
XXX both "dhcp" and "rtsol" has keyword *down* at the end. is it okay?


# 1.57 02-Jan-2000 itojun

echo "IPv6 autoconf: interfaces" before invoking rtsol.
sleep for net.inet6.ip6.dad_count seconds to ensure that IPv6 DAD is completed.
TODO: rtsold (rc.conf line), manpage


# 1.56 02-Jan-2000 itojun

ipv6 autoconf on hosts (non-routers).

to do this,
1. in sysctl.conf, add these lines:
net.inet6.ip6.forwarding=0
net.inet6.ip6.accept_rtadv=1
2. in hostname.foo, add
rtsol

specifying two or more interfaces with "rtsol" may result in strange
behavior - ipv6 spec does not permit multi-interface node to be autoconfig'ed.


# 1.55 02-Jan-2000 todd

add to hostname.* parsing:
- multiple entries support (read: aliases)
- inet6 support
- support for comments (#)
(look for hostname.if(5) commit for syntax details)


# 1.54 31-Dec-1999 itojun

install IPv6 reject routes only if kernel is capable of IPv6.


# 1.53 09-Dec-1999 itojun

avoid transmitting invalid IPv6 packets out to the wire.


# 1.52 09-Dec-1999 itojun

do not perform IPv6 initialization for loopback interface.
MUST make lo0 up before any IPv6 operations.
it will be considered a pilot error if you don't.
(I prefer to have lo0 initialized automatically)


Revision tags: OPENBSD_2_6_BASE
# 1.51 01-Sep-1999 deraadt

support # characters in bridgename.* files; millert


# 1.50 01-Sep-1999 deraadt

cleanup parsing of hostname.* files, and seperate bridge control into
bridgename.* files; all documented in new hostname.if(5) and
bridgename.if(5) man pages


# 1.49 09-Aug-1999 angelos

Only parse/setup the hostname.foo file if interface foo exists (this
is useful for laptops with different ethernet cards etc.)


Revision tags: OPENBSD_2_5_BASE
# 1.48 29-Mar-1999 niklas

New multicast route setup style


# 1.47 26-Mar-1999 niklas

Add bridge interface handling


# 1.46 01-Mar-1999 millert

Add support in /etc/hostname.xxx for files of the format:
up [options]
Any of the following may or may not be set:
$name $mask $bcaddr $extras


# 1.45 28-Oct-1998 millert

Kill the awful hack used to match and split /etc/hostname.* We now use
a function, isalphanumeric, to determine whether an interface name is
likely to be valid. This means that things like /etc/hostname.le0.bak,
/etc/hostname.le0#, /etc/hostname.le0~, etc. will be ignored as they
should. There is no longer an implicate assumption that /etc/hostname.*
only contains a single '.'.


Revision tags: OPENBSD_2_4_BASE
# 1.44 06-Oct-1998 deraadt

move ipnat to end of netstart, to support dhcp+ipnat


# 1.43 18-Sep-1998 deraadt

apply media directives on dhcp interfaces


# 1.42 10-Sep-1998 marc

better way of handling dhcp client; Jason Ish <jbi130@mail.usask.ca>


# 1.41 08-Sep-1998 marc

dhcp client stuff. "Angelos D. Keromytis" <angelos@dsl.cis.upenn.edu>


# 1.40 24-Aug-1998 downsj

You can't use -interface default when there's no default gateway
set (yet). Use -interface $hostname if mygate doesn't exist so that
this actually works on routers.


# 1.39 04-Jul-1998 deraadt

put 224 route on default, to avoid a hostname lookup


# 1.38 22-May-1998 deraadt

use route -n, what the heck


Revision tags: OPENBSD_2_3_BASE
# 1.37 28-Mar-1998 deraadt

s/^nat/ipnat/


# 1.36 23-Feb-1998 niklas

remove trailing blank line


# 1.35 07-Feb-1998 deraadt

ipforward is in sysctl.conf now


# 1.34 21-Dec-1997 deraadt

ugh


# 1.33 20-Dec-1997 deraadt

ipforwarding option in rc.conf


# 1.32 29-Nov-1997 kstailey

NAT requires IPF


# 1.31 04-Nov-1997 deraadt

kill spaces at ends of lines; m4


Revision tags: OPENBSD_2_2_BASE
# 1.30 14-Oct-1997 deraadt

set hostname/domainname before running rc.conf; m4@umn.edu


# 1.29 04-Sep-1997 deraadt

fork netstart; new child is rc.conf


# 1.28 25-Aug-1997 millert

Explicately pass -host flag to route(8) to avoid confusion with networks.


# 1.27 19-Aug-1997 niklas

Add hook for rpc.lockd, make nfsd flags settable in netstart


# 1.26 31-Jul-1997 downsj

Make quotas optional; wedged into netstart for the time being.
/etc/rc.conf, anyone?


# 1.25 30-Jul-1997 deraadt

do not run routed by default


# 1.24 28-Jul-1997 kstailey

Move configuration of loopback interface to before all other interfaces.
Allows the use of local caching-only nameserver with no "nameserver"
entry in /etc/resolv.conf to configure a route between the hostname
and loopback.


# 1.23 25-Jul-1997 provos

earlier start of keymanagement


# 1.22 24-Jul-1997 deraadt

make amd use /tmp_mnt by default


# 1.21 22-Jul-1997 provos

start the photuris daemon per default. hilfe.


# 1.20 17-Jun-1997 niklas

Put in hooks to start ypserv with flags


# 1.19 17-Jun-1997 niklas

Put in hooks to start rpc.yppasswdd with flags


Revision tags: OPENBSD_2_1_BASE
# 1.18 15-Apr-1997 deraadt

kill route flush until .. hmm kernel routing socket bug or something


# 1.17 09-Apr-1997 kstailey

add NAT startup


# 1.16 07-Apr-1997 rees

flush all old routes before adding new interfaces or routes.
ref: netbsd pr3228/misc, Matthias Scheler


# 1.15 03-Mar-1997 downsj

fix typo


# 1.14 11-Feb-1997 deraadt

add default route before fiddling with loopback route to avoid DNS problems; m4@umn.edu, #97


# 1.13 03-Feb-1997 deraadt

do ifaliases after /usr/bin exists in nfs diskless env; pr#77, matthieu@laas.fr


# 1.12 02-Nov-1996 deraadt

timed off by default


Revision tags: OPENBSD_2_0_BASE
# 1.11 23-Sep-1996 deraadt

rfc1323 variable


# 1.10 04-Sep-1996 deraadt

control portmap, inetd, and lpd from netstart; idea from tqbf@enteract.com


# 1.9 27-Aug-1996 deraadt

224.0.0.0 not 0.0.0.224; from peter@demon.net


# 1.8 18-Jun-1996 deraadt

move std stuff from rc.local to rc


# 1.7 16-Jun-1996 deraadt

install sample commented /etc/ifaliases file; which can now contain #
comments and blank lines. new format is "interface address netmask"
(yes, i changed the order of the entries). inspired by netbsd pr#2474;
gillhaa@ghost.whirlpool.com


# 1.6 02-Jun-1996 tholo

Install a multicast route by default


# 1.5 26-May-1996 deraadt

sync & label


# 1.4 09-Jan-1996 dm

added IP filter to netstat/rc and put examples in /usr/share/ipf


# 1.3 30-Dec-1995 deraadt

from netbsd: start mrouted like routed


# 1.2 18-Dec-1995 deraadt

/etc/ifaliases support by randy@zyzzyva.com


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.216 02-Sep-2021 bluhm

Do not create loopback interfaces lo1, lo2, ... upfront. They are
automatically set up by the kernel when a routing domain is created.
An existing lo1 in rdomain 0 would prevent to add any interfaces
in rdomain 1.
OK kn@


# 1.215 30-Aug-2021 bluhm

Improve dubgging in /etc/netstart. Enable print only in ifcreate.
Add debugging output for ipv6 routes. Make localhost and multicast
code aware of the print only switch. Allow netstart -n to work
also if no interface is given.
OK kn@


# 1.214 06-Aug-2021 sthen

As tim@ spotted, a use of V4_AUTOCONF crept in when the variable name
was actually V4_DHCPCONF from previous use. Rename all of the V4_DHCPCONF
to V4_AUTOCONF so everything uses the new name. ok and reminder about
the installer from tb@


# 1.213 16-Jul-2021 florian

switch to dhcpleased/resolvd in base
OK deraadt


# 1.212 20-Jun-2021 florian

Don't try to install a default route with route(8) later on if we are
using inet autoconf, like we do with "dhcp" and "inet6 autoconf".
OK kn


Revision tags: OPENBSD_6_9_BASE
# 1.211 23-Dec-2020 krw

Allow the provision of dhclient(8) options on 'dhcp' lines in hostname.if(5)
files.

Usual man page help & ok jmc@


# 1.210 21-Dec-2020 krw

Avoid issuing pointless 'ifconfig <if> up' when processing 'dhcp' in
hostname.if files. dhclient(8) does that itself. Part of the
"further script optimizations" promised in r1.200 of netstart.

Tested & ok gnezdo@


# 1.209 29-Nov-2020 tb

Fix previous: use correct version of netstart and installer bits.


# 1.208 29-Nov-2020 deraadt

Add support for !command to mygate, so that netstart has a late opportunity
to perform network configuration (for example, "!route source -ifp em0")
Split mygate and myname manual pages (how did anyone ever believe these
are related), and perform hostname configuration much earlier in rc.
discussed with benno, claudio, jmc, etc etc, last version of !command
parser by tb


# 1.207 08-Nov-2020 jmc

no more mobileip;
ok claudio deraadt


Revision tags: OPENBSD_6_8_BASE
# 1.206 21-Jun-2020 dlg

start wg with the other interfaces that rely on routing being up.

from Matt Dunwoodie and Jason A. Donenfeld

ok deraadt@


# 1.205 22-May-2020 kn

Revert the following commit as it breaks hostname.if(5) lines with a
backslash at the end for line continuation

Breaking long lines into multiple ones must still be possible and does
require to treat the backslash as an escape character.

Breakage reported by Mark Patruck <mark at wrapped dot cx >, thanks!

---
distrib/miniroot/install.sub revision 1.1151
etc/netstart revision 1.203
date: 2020/05/21 11:54:41; author: kn; state: Exp; lines: +2 -2;
Do not treat backslashe as an escape character in hostname.if(5) lines

ifstart() should always pass such lines unaltered, especially if they
contain "nwid" or "description" lines with arbitrary strings.

<bsdlisten at gmail dot com> reported SSIDs such as "Mike's" during
installation end as broken; this was because the installer escaped
the single quote using backslashes which ended up being treated as
escape characters much later during hostname.if parsing in netstart(8).

Ok deraadt


# 1.204 21-May-2020 kn

Fix stripcom() description wrt. comments not on their own line

Neither netstart's nor install.sub's (subtly different) implementations
remove trailing comments on lines not starting as a comment, e.g.,
lines like "up #not down" go through unaltered and without "#not down"
being removed.

Only lines *beginning* with the comment sign ("#") are stripped.

No functional change, just updating function descriptions.


# 1.203 21-May-2020 kn

Do not treat backslashe as an escape character in hostname.if(5) lines

ifstart() should always pass such lines unaltered, especially if they
contain "nwid" or "description" lines with arbitrary strings.

<bsdlisten at gmail dot com> reported SSIDs such as "Mike's" during
installation end as broken; this was because the installer escaped
the single quote using backslashes which ended up being treated as
escape characters much later during hostname.if parsing in netstart(8).

Ok deraadt


Revision tags: OPENBSD_6_7_BASE
# 1.202 15-Jan-2020 kn

Do not redirect already quiet stdout for IPv6 reject routes

"route -q" already silences all standard output; if it still prints
something, that's a bug to fix in route.

OK bluhm


# 1.201 25-Oct-2019 dlg

handle aggr(4) in the same way as trunk(4)

from brad@
ok bluhm@ claudio@ deraadt@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.200 29-Aug-2018 krw

Historically /etc/netstart (and the equivalent code in the install
script) did 'ifconfig <if> down' before starting dhclient(8). This was
a way of ensuring old running copies of dhclient were killed before a
new one started. Current dhclient does not need this assist, so change
"ifconfig <if> down" to "ifconfig <if> up" pending further script
optimizations.

Similar to a 2014 attempt by halex@. Prompted by a misc@ report
from Kristjan Komlosi reporting hanging diskless setups.

ok halex@ kn@


# 1.199 08-Jul-2018 tb

netstart is used during system start, but also interactively.
Show proper error message if a regular user executes netstart.
Only do the privilege check if the id binary is available,
which might not be the case during diskless system startup.

ok deraadt, jasper, jca, krw, rpe (who wrote the same diff), sthen


# 1.198 28-Apr-2018 rpe

Add a proper usage() function.

Suggested by and OK jmc.
OK tb


Revision tags: OPENBSD_6_3_BASE
# 1.197 04-Mar-2018 jmc

when -n is used, no need to spit out "Missing parameters." before
displaying usage();

ok tb


# 1.196 03-Mar-2018 landry

Lowercase 'usage' and group -n with interface in it.
From jmc@, ok tb@


# 1.195 21-Feb-2018 rpe

Tweak comments.

OK tb


# 1.194 19-Feb-2018 rpe

Write warning/error messages to stderr and end them with a fullstop.

OK tb


# 1.193 19-Feb-2018 rpe

- use specific patterns when looping over /etc/hostname.if files
to skip backup or temp files.
- test if the patterns matched actual files
- warn if ifcreate() fails on an interface and continue with the
subsequent interfaces in the list instead of return'ing

OK dlg sthen tb


# 1.192 17-Feb-2018 rpe

- Add descriptions for the new functions ifcreate() and vifscreate()
- In ifcreate() use the exit code of the {} block directly
- In vifscreate(), use the ifconfig -C output directly in the for _vif loop
- Remove superfluous and somewhat confusing comment

OK dlg kn sthen


# 1.191 14-Feb-2018 dlg

create virtual interfaces before starting all interface config.

this resolves an ordering problem when adding pseudo interfaces to bridges

tweaks from kn@
ok mpi@ sthen@


# 1.190 10-Feb-2018 claudio

Remove some special IPv4 in IPv6 mapped prefixes that are already rejected
by the ::0.0.0.0/96 reject route added to deny all IPv4 mapped addresses.
Makes the inet6 routing table almost fit in one screen.
OK benno@


# 1.189 10-Feb-2018 florian

Load RFC 7217 key material and generate if it does not already exist.

Add soii.key to changelist (pointed out by semarie) and mtree/special
(suggest by Craig Skinner).

OK naddy, sthen, rpe, tb


# 1.188 06-Feb-2018 tb

If -n is given, the netstart script should not (try to) set the default
route(s). Simply print the command(s) to be issued instead.

tweak & ok rpe


# 1.187 12-Nov-2017 tb

Remove HN_DIR variable and expand it in the only place it was used. It
currently serves no purpose.

ok rpe, agreement from deraadt and halex


Revision tags: OPENBSD_6_2_BASE
# 1.186 25-Jul-2017 rpe

Finally remove backwards compat code to support the 'rtsol' keyword
in hostname.if(5)

OK mpi@ deraadt@ florian@
OK jmc@ from doc perspective


# 1.185 21-Jul-2017 rpe

Align ifstart() in netstart and install.sub.

- in netstart, rename _file to _hn referencing hostname.if files
- in install.sub switch ifstart() to be used with _if instead of
_hn as parameter

ok krw@ tb@


# 1.184 28-May-2017 awolk

etc/netstart: use colon separator instead of dot with chown

OK jung@, deraadt@, jmc@


# 1.183 07-May-2017 rpe

Change test from [] to [[]] and simplify pattern.

OK tb@, krw@ (for [[]])
Feedback and OK halex@


# 1.182 07-May-2017 rpe

Replace hardcoded script name with ${0##*/}

OK tb@ halex@


# 1.181 01-May-2017 rpe

Revert r1.170 and remove the id==0 check.
The id binary is not available in nfs diskless setups at this point.

reported by Andreas Kusalananda, thanks.
discussed with deraadt@


# 1.180 01-May-2017 rpe

Remove last remnants of rtsol. IPv6 autoconfiguration of interfaces is now
done in ifstart(). Remove ipv6autoconf() and replace rtsolif with a boolean
variable V6_AUTOCONF. Replace dhcpif with a boolean variable V4_DHCPCONF.
Both are later used in defaultroute() to decide whether or not to configre
defaultroutes from /etc/mygate.

OK krw@


# 1.179 30-Apr-2017 mpi

Do not try to delete a default route before adding it.

Now that route are automatically G/C with the address they are attached
to there's no reason to duplicate the kernel's job.

Fix a regression introduced with multipath default routes.

ok deraadt@


# 1.178 25-Apr-2017 rpe

Unbreak netstart for multiple inteface configurations like trunk
or carp. Ensure that the noglob option is disabled at the end of
parse_hn_line() and ifstart().

Reported by Christer Solskogen and Stefan Wollny, thanks!


# 1.177 24-Apr-2017 rpe

Introduce a new function parse_hn_line() that replaces the existing
hostname.if(5) parsing code in ifstart().
Add a -n option to netstart to only print the interface configuration
commands instead of executing them.
Add a HN_DIR variable, that points to the directory of the hostname.if
files (default /etc) that allows for future regression tests.

- add new parse_hn_line() function
- change ifstart()
- rename $if to $_if
- don't ifconfig or ifconfig create if -n option is used
- replace hostname.if(5) parsing code with new parse_hn_line()
- just print configuration commands if -n option is used
- autoconf now happens in ifstart(), remove ifv6autoconf()
- introduce HN_DIR variable for the hostname.if file location
- add handling of the -n option to only print config commands
- ensure -n is only used if interfaces are specified as parameters

Discussed with and positive feedback from many
'commit' deraadt@
OK sthen@


# 1.176 08-Apr-2017 rpe

- localize the if, file and stat variables which also ensures that
variables are not named like commands.
- change test from [] to [[]]

OK tb@ halex@


# 1.175 07-Apr-2017 rpe

Minimize differences in ifstart() function between netstart and
install.sub which makes it easier to spot changes in the future.

- comments and formatting
- quotes on assignments are not needed (netstart)
- remove stray space in test (netstart)
- use $file variable with while-loop (netstart)
- although valid, instead of i use $i in arithmetic test (install.sub)

OK krw@, tb@
Looks good deraadt@


# 1.174 07-Apr-2017 rpe

Align comments of ifstart() function in netstart and install.sub.


# 1.173 07-Apr-2017 rpe

Align comments of stripcom() function in netstart and install.sub.


Revision tags: OPENBSD_6_1_BASE
# 1.172 06-Dec-2016 mpi

Do not lose the default route when netstart(8) is run a second time on
the interface pointed to by the default route.

Since the kernel no longer keep routes with dangling address pointer,
netstart(8) has to re-add the default route when the corresponding ifa
has been deleted and re-created.

deraadt@ points out that even if the previous semantic was not necessarily
better, a script like netstart(8) cannot totally fix the default route
problem.

Regression reported by and fix tested by Hrvoje Popovski.

ksh foo checked by halex@


# 1.171 27-Sep-2016 rzalamena

Delay switch(4) interface start up so it can attach virtual interfaces
like vether(4).

nits from and ok benno@, phessler@


# 1.170 09-Sep-2016 jasper

print a clear error message when not ran as root instead of just falling
through and try whatever it can do with the invoking user's perms

feedback/ok aja@ rpe@


Revision tags: OPENBSD_6_0_BASE
# 1.169 19-Jul-2016 mpi

Do not consider tap(4) a special interface and start if before other
pseudo-interfaces.

This unbreak vlan(4) on top of tap(4) since the refactoring to turn it
MP-safe.

ok claudio@, deraadt@


# 1.168 27-Mar-2016 sthen

Don't delete the 224/4 route in netstart, unless it's being done to ensure that
a -reject route can be added. Restores the ability to set an interface route
before daemons are started, lost during the previous simplification.
ok millert mpi


Revision tags: OPENBSD_5_9_BASE
# 1.167 29-Dec-2015 rpe

Remove backslash, not necessary after '&&'

OK halex@


# 1.166 29-Dec-2015 rpe

Replace last remaining `` with $()

OK halex@


# 1.165 18-Dec-2015 ajacoutot

Drop the now useless multicast setup comment.

prodded by tim@, ok mpi@


# 1.164 17-Dec-2015 ajacoutot

Simplify multicast option handling (10 less lines) by matching /etc/rc behavior
towards other YES|NO options and drop the error warning.


with and ok tim@, ok rpe@ on an earlier diff


# 1.163 05-Dec-2015 mpi

It does not make sense to insert a specific route for 224/4 when the
default one is good enough.

So merge rc.conf(8)'s 'multicast_router' and 'multicast_host' into a
single 'multicast'. If set to YES the reject route for 224/4 is not
inserted by netstart(8).

Manual bits from jmc@

ok henning@, ajacoutot@


# 1.162 12-Nov-2015 rpe

Changes to ifautostart():
- Rename function to ifv6autoconf() to make IPv6 relation clearer
- Localize and rename variables

OK krw@


# 1.161 12-Nov-2015 rpe

Changes to ifmstart():
- Change comments to make it clearer that ifmstart() takes two lists
of interface driver names (of which the second is optional) and not
the actual interface instances.
- Use localized variables and use slightly more verbose names.
- Use continue 2 to skip to the next hostname.if file.
- Use shell pattern @() instead of testing _sif individually.

OK krw@


# 1.160 12-Nov-2015 rpe

Changes to stripcom():
- Align comments with /etc/rc version
- Use localized variables
- Use safer "print -r --" instead of plain echo

Changes to ifstart():
- Tweak comment
- Add usage

OK krw@


# 1.159 01-Nov-2015 rpe

Start the rework of the /etc/netstart shell script.

General changes:
- apply a similar 'style' as used in the installer scripts
- improve comments to be more to the point, remove where code is obvious
- document usage of functions if they have arguments
- rename variables where it improves readability
- replace really old-school shell code with more contemporary idioms

Other changes:
- No need to care about "autoboot" because netstart doesn't inherit the
positional parameters from /etc/rc anymore. /etc/rc executes netstart
instead of sourcing it since r1.439.
- Use simpler for-loop to process list of interfaces with ifstart.

OK halex@


# 1.158 26-Oct-2015 rpe

The hostname variable is not used since r1.99. Remove it and use
stripcom() output directly with the hostname command.

OK deraadt@ krw@


# 1.157 23-Oct-2015 claudio

netstart bits for tap(4)


# 1.156 27-Sep-2015 sthen

Don't print output when setting autoconf on interfaces. Suggested by deraadt,
ok florian@ rpe@


# 1.155 13-Sep-2015 sthen

only print the "IPv6 autoconf" line if there are interfaces to configure
feedback/ok rpe


# 1.154 11-Sep-2015 sthen

Set "inet6 autoconf" individually on interfaces that have rtsol set in
hostname.if, previously netstart tried to configure them all at once
("ifconfig if0 if1 if2 inet6 autoconf"). From Delan Azabani, ok phessler@


Revision tags: OPENBSD_5_8_BASE
# 1.153 20-Jul-2015 rpe

Disable Strict Bourne shell mode for /etc/rc and /etc/netstart to be
able to use ksh syntax within these scripts. This way init doesn't
need to be changed, which starts /etc/rc using /bin/sh and people
can still use "sh /etc/netstart ifname".

Idea from and OK halex@
OK deraadt@ krw@ guenther@


# 1.152 19-Jul-2015 florian

Bring up pflow last as it might send with a source address that is on
any of the other interfaces.
OK deraadt, phessler, benno


# 1.151 19-Jul-2015 rpe

Always source rc.subr to be able to use the rc.conf parsing routine
to get the network related vars from rc.conf. This is even necessary
if netstart is run from within /etc/rc. Remove test of $INRC which
unintentionally evaluated always to true.

problem with previous change found by nigel@
OK sthen@ aja@ halex@


# 1.150 19-Jul-2015 ajacoutot

Revert 1.148 for now until I can talk to rpe@
It introduced a regression reported by nigel@


# 1.149 19-Jul-2015 rpe

Replace test command with [].

OK halex@ krw@


# 1.148 19-Jul-2015 rpe

Ensure, that we source rc.subr and parse rc.conf ONLY if we are not
inside /etc/rc.

With help from and OK halex@, ajacoutot@


# 1.147 18-Jul-2015 rpe

- remove trailing blanks introduced in previous commit
- no space in redirections like </foo or >$bar
- few other minor whitespaces

OK krw@


# 1.146 18-Jul-2015 rpe

Improve comments
- Add comments for functions
- Start comments with capital letters
- End comments with a full stop
- Allow comments to extend up to column 80

OK krw@


# 1.145 06-Jun-2015 florian

Allow rtsol keyword in hostname.if(5) with net.inet6.ip6.forwarding=1.
"inet6 autoconf" was working before and rtsol should behave the same.
OK phessler


Revision tags: OPENBSD_5_7_BASE
# 1.144 03-Dec-2014 florian

The kernel handles rtsol(8) functionality since some time now.
Treat rtsol in hostname.if as a keyword like dhcp and call ifconfig
inet6 autoconf.
"reads good" todd@
OK krw@ (who is *not* an IPv6 person), but I recruited him in his
capacity as an installer person.


# 1.143 28-Sep-2014 claudio

Revert 1.142. Without the down netstart will just print the ifconfig
output because it may end up just calling 'ifconfig $if'. This needs
to be done better and properly tested.


# 1.142 26-Sep-2014 halex

remove explicit 'down' of an interface before starting a dhcp request, thereby
avoiding annoying delays for some switch configurations

ok claudio@ deraadt@

i would add ok phessler@, but it was not valid without an ok krw@


Revision tags: OPENBSD_5_6_BASE
# 1.141 12-Jul-2014 stsp

Fix netstart after autoconf6 change so 'rtsol' lines in hostname.if work again.
found by pelikan@; ok pelikan@ henning@


# 1.140 12-Jul-2014 robert

Make rc.conf a parsed configuration file and stop sourcing it as a shell
script.
From now on rc.conf has a fixed syntax (key=val) and it is not allowed
to add anything to it besides the supported syntax, it all going to be
ignored.

discussed with and help from deraadt@ and halex@


Revision tags: OPENBSD_5_5_BASE
# 1.139 22-Aug-2013 mpi

Like for dhclient, do no create a route to alias addresses via 127.0.0.1.
Our stack is able to tell if the address is local or not.

ok todd@, krw@


Revision tags: OPENBSD_5_4_BASE
# 1.138 20-Mar-2013 todd

fix lies in netstart; replacement wording from halex@
pointed out by Ryan Kavannagh rak at debian dot org


Revision tags: OPENBSD_5_3_BASE
# 1.137 05-Dec-2012 rpe

remove "Invalid interface name" message
requested by krw@

ok halex@


# 1.136 02-Dec-2012 rpe

use the more compact version of the check for ifconfig'able interfaces
from install.sub

with feedback from and ok halex


# 1.135 02-Dec-2012 rpe

- remove isalphanumeric() and replace it with a shell pattern, that
tries a bit harder to identify invalid interface names and in
this case emit an error message.
- use [[ $1 == autoboot ]] to avoid a shell error message due to
possible spaces in first argument
- no change in functionality

discussed with krw and halex
ok ("I like this") krw


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.134 07-Oct-2011 deraadt

The new ypbind changes requires that the domainname be set before
rc.conf is run. There's no real downside.
ok aja


Revision tags: OPENBSD_5_0_BASE
# 1.133 07-Jul-2011 guenther

Eliminate some $? tests by rolling the command into the condition

ok halex@


# 1.132 26-May-2011 mpf

Add svlan(4) startup bits.
From markus@. OK naddy, claudio, reyk.


Revision tags: OPENBSD_4_9_BASE
# 1.131 09-Feb-2011 sobrado

fix an unbalanced parenthesis in a comment; while here, split the comment
in a better place to make it more readable.

ok jmc@ and miod@


Revision tags: OPENBSD_4_8_BASE
# 1.130 16-Jun-2010 todd

permit e.g. -inet6 syntax by slurping all lines not just some
noticed by rhsv6 at hushmail dot com, ok sthen@


Revision tags: OPENBSD_4_7_BASE
# 1.129 12-Jan-2010 henning

when setting up lo0 use 127.0.0.1/8 instead of 127.0.0.1 for clarity and
correctness. it's not 1992 any more, kids. ok mcbride dlg krw


# 1.128 10-Dec-2009 todd

o stop reordering ifconfig arguments (e.g. after 'up ..')
o only stop processing if inet or inet6 lines are malformed
o everything not a specially handled bit is passed to ifconfig unmangled
noticed by several after the move from bridgename.bridge0 -> hostname.bridge0
prodded by deraadt@, tested by and feedback from several
man page bits 'look fine' jmc@


# 1.127 22-Nov-2009 deraadt

Stop supporting bridgename.bridge* files, and move to hostname.bridge*
files. To cope with this change, read about the mv command.
ok claudio todd


# 1.126 17-Sep-2009 simon

change variable i to $i in an expression of ifstart() for consistency
with the rest of the file. no functional change.

feedback from sthen@, ok krw@


# 1.125 10-Jul-2009 jdixon

Delay creation of tun(4) interfaces until the underlying interface and
routes are available. This fixes usage for some OpenVPN users that start
it from hostname.tun*.

Tested by Johan Huldtgren. ok sthen@, johan@.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.124 25-Nov-2008 markus

delay /etc/netstart until IPv6-DAD (dup-address-detection) is completed.
ok fries, hshoexer, claudio


# 1.123 14-Aug-2008 sthen

Tools from /usr may not be used in netstart since it may be NFS-mounted
and not available at that time. Rewrite the hostname.if permission check
to use only /bin/ls and the shell. Requested by deraadt.

ok todd, "Twisted." deraadt


Revision tags: OPENBSD_4_4_BASE
# 1.122 23-Jul-2008 sthen

Prevent warning about insecure hostnames where no /etc/hostname.*
exists. From wcmaier@.

Check target of symbolic links to avoid noise at boot and in
seucrity output where you have several interfaces symlinked to one
config file.

"If you think this is the right thing to do" deraadt@


# 1.121 09-Jun-2008 todd

warn once not 3 times in case of a non existent file, discussed with deraadt
originally pointed out by Johan Torin


# 1.120 09-Jun-2008 deraadt

Ensure that hostname.* files are also re-chowned to root.wheel at each
boot as discussed with claudio while eating tasty donairs. ok todd


# 1.119 17-Apr-2008 deraadt

before using them, force hostname.* files to be unreadable by world
first version from todd, ok millert


Revision tags: OPENBSD_4_3_BASE
# 1.118 17-Jan-2008 brad

Execute rtsol after turning up trunk(4) and vlan(4) interfaces so they're
taken into consideration for rtsol.

ok reyk@ dlg@


# 1.117 09-Jan-2008 mpf

Do not bring up pfsync(4) before the working ruleset
has been loaded. Otherwise, states that are received during the
initial bulk update mismatch the correct pf-checksum and
do not attach to the rules.
Problem identified by david@. Fix done in collaboration.
OK henning@


Revision tags: OPENBSD_4_2_BASE
# 1.116 02-Aug-2007 david

move the delay for IPv6 DAD to after all interfaces have started
fixes problems with daemons being unable to bind to all addreses at boot
ok itojun@ hshoexer@


Revision tags: OPENBSD_4_1_BASE
# 1.115 15-Nov-2006 itojun

reject multicast packet without scope identifier specified.


Revision tags: OPENBSD_4_0_BASE
# 1.114 29-Jun-2006 todd

do not add an extra space; nwid and description come out wrong
fix as proposed by maja@, thanks!


Revision tags: OPENBSD_3_9_BASE
# 1.113 28-Dec-2005 david

nuke extra whitespace


# 1.112 06-Dec-2005 reyk

multicast_host=YES only works if a valid default gateway is available.
validate this condition and reject multicast traffic on failure.

ok todd@ naddy@


# 1.111 02-Nov-2005 todd

fix inspired by pr#4590
ok krw@


# 1.110 25-Oct-2005 todd

better logic from krw@:
- do not process mygate for v4 if dhcp
- do not process mygate for v6 if rtsol
this also makes the mygate processing logic more readable
ok krw@


# 1.109 14-Oct-2005 todd

add v6 support for /etc/mygate
ok deraadt@ mickey@ krw@
same functionality tested/ok'ed by by mickey, brad, matthieu, and me
with this one may now put a v6 IP in /etc/mygate on a separate line from
the v4 default gateway and netstart will do the right thing


# 1.108 12-Oct-2005 todd

shrink stripcom(), sync with install.sub
ok krw@


# 1.107 04-Oct-2005 todd

trunk must be started after physical ethernet devices, but before vlan.
populate ifmstart lines accordingly.
prodded/tested by brad@
ok reyk@


# 1.106 28-Sep-2005 todd

use eval consistently, fixes description quotes on rtsol and dhcp
fix inspired by and closes pr 4495
ok krw@


Revision tags: OPENBSD_3_8_BASE
# 1.105 22-May-2005 todd

Introduce 'ifmstart' to deal with starting multiple interfaces minus a list
of interfaces.

This reduces the netstart script by 174 chars, 13 words, and 19 lines, but
more importantly, makes it more simple and less cluttered should more special
case/orderings be needed.

ok brad@ and pr 4197 submitter, inspired by and closes pr 4197


# 1.104 04-Apr-2005 djm

unbreak; ok pval@


# 1.103 03-Apr-2005 deraadt

if dhcp is used to get an address on any interface, ignore /etc/mygate
ok krw
(this lets us do something rather cool with the zaurus in particular)


Revision tags: OPENBSD_3_7_BASE
# 1.102 04-Jan-2005 mcbride

Bring up the carp(4) interface before default route.

ok pascoe@ mpf@


# 1.101 30-Dec-2004 millert

Add a copy of stripcom so /etc/netstart can be run standalone again.
OK deraadt@


# 1.100 19-Dec-2004 millert

Allow comments in /etc/{myname,mygate,defaultdomain}; OK deraadt@


# 1.99 04-Dec-2004 itojun

remove "route $hostname 127.0.0.1" line. deraadt ok
*** please update /etc/netstart and test if it works ok for you ***


# 1.98 20-Oct-2004 deraadt

make all route commands use -qn; ok mcbride henning


Revision tags: OPENBSD_3_6_BASE
# 1.97 29-May-2004 deraadt

one last route command lacking -qn


Revision tags: OPENBSD_3_5_BASE
# 1.96 22-Mar-2004 mcbride

Make sure pfsync is brought up before carp.

ok deraadt@


# 1.95 13-Mar-2004 mcbride

Delay pfsync(4) configuration, as the syncif has to be configured in
advance. From Thorsten Lockert.


# 1.94 14-Jan-2004 deraadt

ok, it took quite a bit of prodding but itojun finally explained why the
extra sleep 1 is in here, and we came to the conclusion it is safe to
delete it. whee.


# 1.93 13-Jan-2004 deraadt

repair v6 lo0 documentation


# 1.92 11-Jan-2004 deraadt

add loopback routes late


# 1.91 09-Jan-2004 deraadt

create all routes with -q; markus ok


# 1.90 04-Dec-2003 millert

Need to do "ifconfig create" for bridge interfaces too.


# 1.89 03-Dec-2003 markus

add support for ifconfig clone; from netbsd; ok deraadt, henning


# 1.88 20-Oct-2003 david

delay carp initialization until after physical interfaces are configured
ok mcbride@ henning@ deraadt@ todd@


Revision tags: OPENBSD_3_4_BASE
# 1.87 27-Aug-2003 henning

only try to set hostname to what /etc/myname says if that file actually exists,
otherwise preserve `hostname`
netbooted machines can live perfectly fine without it; they get their hostname
earlier.

ok krw@ cedric@


Revision tags: OPENBSD_3_3_BASE
# 1.86 16-Feb-2003 krw

Fix up some DNS verbiage to make it consistant.

Fix up default route selection by

a) Forcing user to explicitly chose 'dhcp' as a mechanism for
specifying a default route, rather than guessing based on one or more
interfaces being configured by dhcp.

b) If the user specified default route does not work, re-present the
existing default route rather than losing it.

c) Move default route selection to after nameserver activation so the
user can specify a hostname as the default route.

Change /etc/netstart so that /etc/mygate wins if a default route was
already specified (i.e. by dhcp).

ok deraadt@.


Revision tags: OPENBSD_3_2_BASE
# 1.85 16-May-2002 todd

ignore non-existent cases where '$if' evaluates to '*'.
From Andr� Lucas <andre@ae-35.com>, fixes pr # 2658.
'Looks good' from miod@, millert@, and krw@.


Revision tags: OPENBSD_3_1_BASE
# 1.84 23-Feb-2002 deraadt

re-add support for $if expansion; hamajima@nagoya.ydc.co.jp


# 1.83 21-Feb-2002 miod

Change the network components initialization order.
Change from:
o all interfaces
o all bridges
o routes
to:
o physical interfaces
o routes
o gif and gre interfaces
o bridges

Fixeski PR #2400.
Manual page updates coming soon.
Ok angelos@ chris@ deraadt@


Revision tags: OPENBSD_3_0_BASE
# 1.82 31-Jul-2001 hugh

a space before a redirect


# 1.81 06-Jul-2001 angelos

Also, source /etc/rc.conf so we can pull in the
multicast_host/multicast_router settings; this is useful if one
flushes the routing table and re-initializes.

We really need a netconfig tool of sorts.


# 1.80 06-Jul-2001 angelos

Use "route -n show -inet" to determine the default multicast iface.


# 1.79 03-Jul-2001 deraadt

pull in rc.conf early so that pf(1) startup is right; tested by jasoni, comments from millert


# 1.78 30-May-2001 deraadt

Remove ipf. Darren Reed has interpreted his (old, new, whichever)
licence in a way that makes ipf not free according to the rules we
established over 5 years ago, at www.openbsd.org/goals.html (and those
same basic rules govern the other *BSD projects too). Specifically,
Darren says that modified versions are not permitted. But software
which OpenBSD uses and redistributes must be free to all (be they
people or companies), for any purpose they wish to use it, including
modification, use, peeing on, or even integration into baby mulching
machines or atomic bombs to be dropped on Australia. Furthermore, we
know of a number of companies using ipf with modification like us, who
are now in the same situation, and we hope that some of them will work
with us to fill this gap that now exists in OpenBSD (temporarily, we
hope).


Revision tags: OPENBSD_2_9_BASE
# 1.77 13-Mar-2001 deraadt

spelling; maurice@maurice.wan.nl


# 1.76 06-Feb-2001 todd

ignore blank lines in addition to comments
fixes pr#1660 from wilfried@telia.com .. Thanks!


# 1.75 10-Jan-2001 jason

support !command in bridgename.if files, too


# 1.74 27-Nov-2000 millert

Use -n to test if a variable is non-zero. Otherwise, if the variable's
contents start with a '-' test becomes unhappy (since it interprets it
as another option).


# 1.73 08-Nov-2000 todd

This fixes pr 1481, we now handle args > 6 in /etc/hostname.if in the
cases where we did not previously handle them.
Thanks to Scott Atwood <atwood@cs.stanford.edu> for reminding us of this.


Revision tags: OPENBSD_2_8_BASE
# 1.72 02-Sep-2000 todd

subtle bug .. global variables in a while loop need reset 'just incase'
With:
hostname.fxp0 having a last line of:
inet6 alias 3ffe:...
and hostname.gif0 having a first two lines of:
giftunnel 1.2.3.4
dest 1.2.4.3
We end up with the command:
ifconfig gif0 giftunnel alias 1.2.3.4 1.2.4.3
.. which is clearly wrong and fixed by this change


# 1.71 18-Jun-2000 todd

rc.conf now parses ${local_rcconf} internally; closes pr 1259


Revision tags: OPENBSD_2_7_BASE
# 1.70 08-May-2000 todd

fix dhcp 'NONE' ness from install to allow media parsing to work
.. ok deraadt@, millert@


# 1.69 21-Apr-2000 deraadt

rc.conf.local support, inspired by chuck yerkes


# 1.68 04-Apr-2000 millert

Remove the -E flag from ipf as it is implicitly enabled and using
the -E flag here causes the kernel to printf 'IP Filter: already
initialized'.


# 1.67 18-Mar-2000 deraadt

silence all extra route addition printouts


# 1.66 17-Mar-2000 itojun

correct reject route installations for IPv6. improve comments.


# 1.65 12-Mar-2000 itojun

disallow packets to malicious 6to4 prefix, based on
http://playground.iijlab.net/i-d/draft-itojun-ipv6-transition-abuse-00.txt


# 1.64 10-Mar-2000 todd

fix non behavior
with this `!' lines in /etc/hostname.* run even without certain lines
(like a comment) preceeding it.


# 1.63 10-Jan-2000 todd

allow arbitrary commands in /etc/hostname.* files if the line starts with '!'


# 1.62 02-Jan-2000 deraadt

rtsol case can configure the interface up, since it would be nice to finish
DAD before the actual rtsol(8) run happens later. and since it will rtsol,
it is going to be up in any case.


# 1.61 02-Jan-2000 itojun

one more indentation fix.


# 1.60 02-Jan-2000 itojun

indentation fix (todd's part)


# 1.59 02-Jan-2000 todd

fix rtsold case, reset cmd for each iteration!


# 1.58 02-Jan-2000 itojun

allow options after "rtsol".
XXX both "dhcp" and "rtsol" has keyword *down* at the end. is it okay?


# 1.57 02-Jan-2000 itojun

echo "IPv6 autoconf: interfaces" before invoking rtsol.
sleep for net.inet6.ip6.dad_count seconds to ensure that IPv6 DAD is completed.
TODO: rtsold (rc.conf line), manpage


# 1.56 02-Jan-2000 itojun

ipv6 autoconf on hosts (non-routers).

to do this,
1. in sysctl.conf, add these lines:
net.inet6.ip6.forwarding=0
net.inet6.ip6.accept_rtadv=1
2. in hostname.foo, add
rtsol

specifying two or more interfaces with "rtsol" may result in strange
behavior - ipv6 spec does not permit multi-interface node to be autoconfig'ed.


# 1.55 02-Jan-2000 todd

add to hostname.* parsing:
- multiple entries support (read: aliases)
- inet6 support
- support for comments (#)
(look for hostname.if(5) commit for syntax details)


# 1.54 31-Dec-1999 itojun

install IPv6 reject routes only if kernel is capable of IPv6.


# 1.53 09-Dec-1999 itojun

avoid transmitting invalid IPv6 packets out to the wire.


# 1.52 09-Dec-1999 itojun

do not perform IPv6 initialization for loopback interface.
MUST make lo0 up before any IPv6 operations.
it will be considered a pilot error if you don't.
(I prefer to have lo0 initialized automatically)


Revision tags: OPENBSD_2_6_BASE
# 1.51 01-Sep-1999 deraadt

support # characters in bridgename.* files; millert


# 1.50 01-Sep-1999 deraadt

cleanup parsing of hostname.* files, and seperate bridge control into
bridgename.* files; all documented in new hostname.if(5) and
bridgename.if(5) man pages


# 1.49 09-Aug-1999 angelos

Only parse/setup the hostname.foo file if interface foo exists (this
is useful for laptops with different ethernet cards etc.)


Revision tags: OPENBSD_2_5_BASE
# 1.48 29-Mar-1999 niklas

New multicast route setup style


# 1.47 26-Mar-1999 niklas

Add bridge interface handling


# 1.46 01-Mar-1999 millert

Add support in /etc/hostname.xxx for files of the format:
up [options]
Any of the following may or may not be set:
$name $mask $bcaddr $extras


# 1.45 28-Oct-1998 millert

Kill the awful hack used to match and split /etc/hostname.* We now use
a function, isalphanumeric, to determine whether an interface name is
likely to be valid. This means that things like /etc/hostname.le0.bak,
/etc/hostname.le0#, /etc/hostname.le0~, etc. will be ignored as they
should. There is no longer an implicate assumption that /etc/hostname.*
only contains a single '.'.


Revision tags: OPENBSD_2_4_BASE
# 1.44 06-Oct-1998 deraadt

move ipnat to end of netstart, to support dhcp+ipnat


# 1.43 18-Sep-1998 deraadt

apply media directives on dhcp interfaces


# 1.42 10-Sep-1998 marc

better way of handling dhcp client; Jason Ish <jbi130@mail.usask.ca>


# 1.41 08-Sep-1998 marc

dhcp client stuff. "Angelos D. Keromytis" <angelos@dsl.cis.upenn.edu>


# 1.40 24-Aug-1998 downsj

You can't use -interface default when there's no default gateway
set (yet). Use -interface $hostname if mygate doesn't exist so that
this actually works on routers.


# 1.39 04-Jul-1998 deraadt

put 224 route on default, to avoid a hostname lookup


# 1.38 22-May-1998 deraadt

use route -n, what the heck


Revision tags: OPENBSD_2_3_BASE
# 1.37 28-Mar-1998 deraadt

s/^nat/ipnat/


# 1.36 23-Feb-1998 niklas

remove trailing blank line


# 1.35 07-Feb-1998 deraadt

ipforward is in sysctl.conf now


# 1.34 21-Dec-1997 deraadt

ugh


# 1.33 20-Dec-1997 deraadt

ipforwarding option in rc.conf


# 1.32 29-Nov-1997 kstailey

NAT requires IPF


# 1.31 04-Nov-1997 deraadt

kill spaces at ends of lines; m4


Revision tags: OPENBSD_2_2_BASE
# 1.30 14-Oct-1997 deraadt

set hostname/domainname before running rc.conf; m4@umn.edu


# 1.29 04-Sep-1997 deraadt

fork netstart; new child is rc.conf


# 1.28 25-Aug-1997 millert

Explicately pass -host flag to route(8) to avoid confusion with networks.


# 1.27 19-Aug-1997 niklas

Add hook for rpc.lockd, make nfsd flags settable in netstart


# 1.26 31-Jul-1997 downsj

Make quotas optional; wedged into netstart for the time being.
/etc/rc.conf, anyone?


# 1.25 30-Jul-1997 deraadt

do not run routed by default


# 1.24 28-Jul-1997 kstailey

Move configuration of loopback interface to before all other interfaces.
Allows the use of local caching-only nameserver with no "nameserver"
entry in /etc/resolv.conf to configure a route between the hostname
and loopback.


# 1.23 25-Jul-1997 provos

earlier start of keymanagement


# 1.22 24-Jul-1997 deraadt

make amd use /tmp_mnt by default


# 1.21 22-Jul-1997 provos

start the photuris daemon per default. hilfe.


# 1.20 17-Jun-1997 niklas

Put in hooks to start ypserv with flags


# 1.19 17-Jun-1997 niklas

Put in hooks to start rpc.yppasswdd with flags


Revision tags: OPENBSD_2_1_BASE
# 1.18 15-Apr-1997 deraadt

kill route flush until .. hmm kernel routing socket bug or something


# 1.17 09-Apr-1997 kstailey

add NAT startup


# 1.16 07-Apr-1997 rees

flush all old routes before adding new interfaces or routes.
ref: netbsd pr3228/misc, Matthias Scheler


# 1.15 03-Mar-1997 downsj

fix typo


# 1.14 11-Feb-1997 deraadt

add default route before fiddling with loopback route to avoid DNS problems; m4@umn.edu, #97


# 1.13 03-Feb-1997 deraadt

do ifaliases after /usr/bin exists in nfs diskless env; pr#77, matthieu@laas.fr


# 1.12 02-Nov-1996 deraadt

timed off by default


Revision tags: OPENBSD_2_0_BASE
# 1.11 23-Sep-1996 deraadt

rfc1323 variable


# 1.10 04-Sep-1996 deraadt

control portmap, inetd, and lpd from netstart; idea from tqbf@enteract.com


# 1.9 27-Aug-1996 deraadt

224.0.0.0 not 0.0.0.224; from peter@demon.net


# 1.8 18-Jun-1996 deraadt

move std stuff from rc.local to rc


# 1.7 16-Jun-1996 deraadt

install sample commented /etc/ifaliases file; which can now contain #
comments and blank lines. new format is "interface address netmask"
(yes, i changed the order of the entries). inspired by netbsd pr#2474;
gillhaa@ghost.whirlpool.com


# 1.6 02-Jun-1996 tholo

Install a multicast route by default


# 1.5 26-May-1996 deraadt

sync & label


# 1.4 09-Jan-1996 dm

added IP filter to netstat/rc and put examples in /usr/share/ipf


# 1.3 30-Dec-1995 deraadt

from netbsd: start mrouted like routed


# 1.2 18-Dec-1995 deraadt

/etc/ifaliases support by randy@zyzzyva.com


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.215 30-Aug-2021 bluhm

Improve dubgging in /etc/netstart. Enable print only in ifcreate.
Add debugging output for ipv6 routes. Make localhost and multicast
code aware of the print only switch. Allow netstart -n to work
also if no interface is given.
OK kn@


# 1.214 06-Aug-2021 sthen

As tim@ spotted, a use of V4_AUTOCONF crept in when the variable name
was actually V4_DHCPCONF from previous use. Rename all of the V4_DHCPCONF
to V4_AUTOCONF so everything uses the new name. ok and reminder about
the installer from tb@


# 1.213 16-Jul-2021 florian

switch to dhcpleased/resolvd in base
OK deraadt


# 1.212 20-Jun-2021 florian

Don't try to install a default route with route(8) later on if we are
using inet autoconf, like we do with "dhcp" and "inet6 autoconf".
OK kn


Revision tags: OPENBSD_6_9_BASE
# 1.211 23-Dec-2020 krw

Allow the provision of dhclient(8) options on 'dhcp' lines in hostname.if(5)
files.

Usual man page help & ok jmc@


# 1.210 21-Dec-2020 krw

Avoid issuing pointless 'ifconfig <if> up' when processing 'dhcp' in
hostname.if files. dhclient(8) does that itself. Part of the
"further script optimizations" promised in r1.200 of netstart.

Tested & ok gnezdo@


# 1.209 29-Nov-2020 tb

Fix previous: use correct version of netstart and installer bits.


# 1.208 29-Nov-2020 deraadt

Add support for !command to mygate, so that netstart has a late opportunity
to perform network configuration (for example, "!route source -ifp em0")
Split mygate and myname manual pages (how did anyone ever believe these
are related), and perform hostname configuration much earlier in rc.
discussed with benno, claudio, jmc, etc etc, last version of !command
parser by tb


# 1.207 08-Nov-2020 jmc

no more mobileip;
ok claudio deraadt


Revision tags: OPENBSD_6_8_BASE
# 1.206 21-Jun-2020 dlg

start wg with the other interfaces that rely on routing being up.

from Matt Dunwoodie and Jason A. Donenfeld

ok deraadt@


# 1.205 22-May-2020 kn

Revert the following commit as it breaks hostname.if(5) lines with a
backslash at the end for line continuation

Breaking long lines into multiple ones must still be possible and does
require to treat the backslash as an escape character.

Breakage reported by Mark Patruck <mark at wrapped dot cx >, thanks!

---
distrib/miniroot/install.sub revision 1.1151
etc/netstart revision 1.203
date: 2020/05/21 11:54:41; author: kn; state: Exp; lines: +2 -2;
Do not treat backslashe as an escape character in hostname.if(5) lines

ifstart() should always pass such lines unaltered, especially if they
contain "nwid" or "description" lines with arbitrary strings.

<bsdlisten at gmail dot com> reported SSIDs such as "Mike's" during
installation end as broken; this was because the installer escaped
the single quote using backslashes which ended up being treated as
escape characters much later during hostname.if parsing in netstart(8).

Ok deraadt


# 1.204 21-May-2020 kn

Fix stripcom() description wrt. comments not on their own line

Neither netstart's nor install.sub's (subtly different) implementations
remove trailing comments on lines not starting as a comment, e.g.,
lines like "up #not down" go through unaltered and without "#not down"
being removed.

Only lines *beginning* with the comment sign ("#") are stripped.

No functional change, just updating function descriptions.


# 1.203 21-May-2020 kn

Do not treat backslashe as an escape character in hostname.if(5) lines

ifstart() should always pass such lines unaltered, especially if they
contain "nwid" or "description" lines with arbitrary strings.

<bsdlisten at gmail dot com> reported SSIDs such as "Mike's" during
installation end as broken; this was because the installer escaped
the single quote using backslashes which ended up being treated as
escape characters much later during hostname.if parsing in netstart(8).

Ok deraadt


Revision tags: OPENBSD_6_7_BASE
# 1.202 15-Jan-2020 kn

Do not redirect already quiet stdout for IPv6 reject routes

"route -q" already silences all standard output; if it still prints
something, that's a bug to fix in route.

OK bluhm


# 1.201 25-Oct-2019 dlg

handle aggr(4) in the same way as trunk(4)

from brad@
ok bluhm@ claudio@ deraadt@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.200 29-Aug-2018 krw

Historically /etc/netstart (and the equivalent code in the install
script) did 'ifconfig <if> down' before starting dhclient(8). This was
a way of ensuring old running copies of dhclient were killed before a
new one started. Current dhclient does not need this assist, so change
"ifconfig <if> down" to "ifconfig <if> up" pending further script
optimizations.

Similar to a 2014 attempt by halex@. Prompted by a misc@ report
from Kristjan Komlosi reporting hanging diskless setups.

ok halex@ kn@


# 1.199 08-Jul-2018 tb

netstart is used during system start, but also interactively.
Show proper error message if a regular user executes netstart.
Only do the privilege check if the id binary is available,
which might not be the case during diskless system startup.

ok deraadt, jasper, jca, krw, rpe (who wrote the same diff), sthen


# 1.198 28-Apr-2018 rpe

Add a proper usage() function.

Suggested by and OK jmc.
OK tb


Revision tags: OPENBSD_6_3_BASE
# 1.197 04-Mar-2018 jmc

when -n is used, no need to spit out "Missing parameters." before
displaying usage();

ok tb


# 1.196 03-Mar-2018 landry

Lowercase 'usage' and group -n with interface in it.
From jmc@, ok tb@


# 1.195 21-Feb-2018 rpe

Tweak comments.

OK tb


# 1.194 19-Feb-2018 rpe

Write warning/error messages to stderr and end them with a fullstop.

OK tb


# 1.193 19-Feb-2018 rpe

- use specific patterns when looping over /etc/hostname.if files
to skip backup or temp files.
- test if the patterns matched actual files
- warn if ifcreate() fails on an interface and continue with the
subsequent interfaces in the list instead of return'ing

OK dlg sthen tb


# 1.192 17-Feb-2018 rpe

- Add descriptions for the new functions ifcreate() and vifscreate()
- In ifcreate() use the exit code of the {} block directly
- In vifscreate(), use the ifconfig -C output directly in the for _vif loop
- Remove superfluous and somewhat confusing comment

OK dlg kn sthen


# 1.191 14-Feb-2018 dlg

create virtual interfaces before starting all interface config.

this resolves an ordering problem when adding pseudo interfaces to bridges

tweaks from kn@
ok mpi@ sthen@


# 1.190 10-Feb-2018 claudio

Remove some special IPv4 in IPv6 mapped prefixes that are already rejected
by the ::0.0.0.0/96 reject route added to deny all IPv4 mapped addresses.
Makes the inet6 routing table almost fit in one screen.
OK benno@


# 1.189 10-Feb-2018 florian

Load RFC 7217 key material and generate if it does not already exist.

Add soii.key to changelist (pointed out by semarie) and mtree/special
(suggest by Craig Skinner).

OK naddy, sthen, rpe, tb


# 1.188 06-Feb-2018 tb

If -n is given, the netstart script should not (try to) set the default
route(s). Simply print the command(s) to be issued instead.

tweak & ok rpe


# 1.187 12-Nov-2017 tb

Remove HN_DIR variable and expand it in the only place it was used. It
currently serves no purpose.

ok rpe, agreement from deraadt and halex


Revision tags: OPENBSD_6_2_BASE
# 1.186 25-Jul-2017 rpe

Finally remove backwards compat code to support the 'rtsol' keyword
in hostname.if(5)

OK mpi@ deraadt@ florian@
OK jmc@ from doc perspective


# 1.185 21-Jul-2017 rpe

Align ifstart() in netstart and install.sub.

- in netstart, rename _file to _hn referencing hostname.if files
- in install.sub switch ifstart() to be used with _if instead of
_hn as parameter

ok krw@ tb@


# 1.184 28-May-2017 awolk

etc/netstart: use colon separator instead of dot with chown

OK jung@, deraadt@, jmc@


# 1.183 07-May-2017 rpe

Change test from [] to [[]] and simplify pattern.

OK tb@, krw@ (for [[]])
Feedback and OK halex@


# 1.182 07-May-2017 rpe

Replace hardcoded script name with ${0##*/}

OK tb@ halex@


# 1.181 01-May-2017 rpe

Revert r1.170 and remove the id==0 check.
The id binary is not available in nfs diskless setups at this point.

reported by Andreas Kusalananda, thanks.
discussed with deraadt@


# 1.180 01-May-2017 rpe

Remove last remnants of rtsol. IPv6 autoconfiguration of interfaces is now
done in ifstart(). Remove ipv6autoconf() and replace rtsolif with a boolean
variable V6_AUTOCONF. Replace dhcpif with a boolean variable V4_DHCPCONF.
Both are later used in defaultroute() to decide whether or not to configre
defaultroutes from /etc/mygate.

OK krw@


# 1.179 30-Apr-2017 mpi

Do not try to delete a default route before adding it.

Now that route are automatically G/C with the address they are attached
to there's no reason to duplicate the kernel's job.

Fix a regression introduced with multipath default routes.

ok deraadt@


# 1.178 25-Apr-2017 rpe

Unbreak netstart for multiple inteface configurations like trunk
or carp. Ensure that the noglob option is disabled at the end of
parse_hn_line() and ifstart().

Reported by Christer Solskogen and Stefan Wollny, thanks!


# 1.177 24-Apr-2017 rpe

Introduce a new function parse_hn_line() that replaces the existing
hostname.if(5) parsing code in ifstart().
Add a -n option to netstart to only print the interface configuration
commands instead of executing them.
Add a HN_DIR variable, that points to the directory of the hostname.if
files (default /etc) that allows for future regression tests.

- add new parse_hn_line() function
- change ifstart()
- rename $if to $_if
- don't ifconfig or ifconfig create if -n option is used
- replace hostname.if(5) parsing code with new parse_hn_line()
- just print configuration commands if -n option is used
- autoconf now happens in ifstart(), remove ifv6autoconf()
- introduce HN_DIR variable for the hostname.if file location
- add handling of the -n option to only print config commands
- ensure -n is only used if interfaces are specified as parameters

Discussed with and positive feedback from many
'commit' deraadt@
OK sthen@


# 1.176 08-Apr-2017 rpe

- localize the if, file and stat variables which also ensures that
variables are not named like commands.
- change test from [] to [[]]

OK tb@ halex@


# 1.175 07-Apr-2017 rpe

Minimize differences in ifstart() function between netstart and
install.sub which makes it easier to spot changes in the future.

- comments and formatting
- quotes on assignments are not needed (netstart)
- remove stray space in test (netstart)
- use $file variable with while-loop (netstart)
- although valid, instead of i use $i in arithmetic test (install.sub)

OK krw@, tb@
Looks good deraadt@


# 1.174 07-Apr-2017 rpe

Align comments of ifstart() function in netstart and install.sub.


# 1.173 07-Apr-2017 rpe

Align comments of stripcom() function in netstart and install.sub.


Revision tags: OPENBSD_6_1_BASE
# 1.172 06-Dec-2016 mpi

Do not lose the default route when netstart(8) is run a second time on
the interface pointed to by the default route.

Since the kernel no longer keep routes with dangling address pointer,
netstart(8) has to re-add the default route when the corresponding ifa
has been deleted and re-created.

deraadt@ points out that even if the previous semantic was not necessarily
better, a script like netstart(8) cannot totally fix the default route
problem.

Regression reported by and fix tested by Hrvoje Popovski.

ksh foo checked by halex@


# 1.171 27-Sep-2016 rzalamena

Delay switch(4) interface start up so it can attach virtual interfaces
like vether(4).

nits from and ok benno@, phessler@


# 1.170 09-Sep-2016 jasper

print a clear error message when not ran as root instead of just falling
through and try whatever it can do with the invoking user's perms

feedback/ok aja@ rpe@


Revision tags: OPENBSD_6_0_BASE
# 1.169 19-Jul-2016 mpi

Do not consider tap(4) a special interface and start if before other
pseudo-interfaces.

This unbreak vlan(4) on top of tap(4) since the refactoring to turn it
MP-safe.

ok claudio@, deraadt@


# 1.168 27-Mar-2016 sthen

Don't delete the 224/4 route in netstart, unless it's being done to ensure that
a -reject route can be added. Restores the ability to set an interface route
before daemons are started, lost during the previous simplification.
ok millert mpi


Revision tags: OPENBSD_5_9_BASE
# 1.167 29-Dec-2015 rpe

Remove backslash, not necessary after '&&'

OK halex@


# 1.166 29-Dec-2015 rpe

Replace last remaining `` with $()

OK halex@


# 1.165 18-Dec-2015 ajacoutot

Drop the now useless multicast setup comment.

prodded by tim@, ok mpi@


# 1.164 17-Dec-2015 ajacoutot

Simplify multicast option handling (10 less lines) by matching /etc/rc behavior
towards other YES|NO options and drop the error warning.


with and ok tim@, ok rpe@ on an earlier diff


# 1.163 05-Dec-2015 mpi

It does not make sense to insert a specific route for 224/4 when the
default one is good enough.

So merge rc.conf(8)'s 'multicast_router' and 'multicast_host' into a
single 'multicast'. If set to YES the reject route for 224/4 is not
inserted by netstart(8).

Manual bits from jmc@

ok henning@, ajacoutot@


# 1.162 12-Nov-2015 rpe

Changes to ifautostart():
- Rename function to ifv6autoconf() to make IPv6 relation clearer
- Localize and rename variables

OK krw@


# 1.161 12-Nov-2015 rpe

Changes to ifmstart():
- Change comments to make it clearer that ifmstart() takes two lists
of interface driver names (of which the second is optional) and not
the actual interface instances.
- Use localized variables and use slightly more verbose names.
- Use continue 2 to skip to the next hostname.if file.
- Use shell pattern @() instead of testing _sif individually.

OK krw@


# 1.160 12-Nov-2015 rpe

Changes to stripcom():
- Align comments with /etc/rc version
- Use localized variables
- Use safer "print -r --" instead of plain echo

Changes to ifstart():
- Tweak comment
- Add usage

OK krw@


# 1.159 01-Nov-2015 rpe

Start the rework of the /etc/netstart shell script.

General changes:
- apply a similar 'style' as used in the installer scripts
- improve comments to be more to the point, remove where code is obvious
- document usage of functions if they have arguments
- rename variables where it improves readability
- replace really old-school shell code with more contemporary idioms

Other changes:
- No need to care about "autoboot" because netstart doesn't inherit the
positional parameters from /etc/rc anymore. /etc/rc executes netstart
instead of sourcing it since r1.439.
- Use simpler for-loop to process list of interfaces with ifstart.

OK halex@


# 1.158 26-Oct-2015 rpe

The hostname variable is not used since r1.99. Remove it and use
stripcom() output directly with the hostname command.

OK deraadt@ krw@


# 1.157 23-Oct-2015 claudio

netstart bits for tap(4)


# 1.156 27-Sep-2015 sthen

Don't print output when setting autoconf on interfaces. Suggested by deraadt,
ok florian@ rpe@


# 1.155 13-Sep-2015 sthen

only print the "IPv6 autoconf" line if there are interfaces to configure
feedback/ok rpe


# 1.154 11-Sep-2015 sthen

Set "inet6 autoconf" individually on interfaces that have rtsol set in
hostname.if, previously netstart tried to configure them all at once
("ifconfig if0 if1 if2 inet6 autoconf"). From Delan Azabani, ok phessler@


Revision tags: OPENBSD_5_8_BASE
# 1.153 20-Jul-2015 rpe

Disable Strict Bourne shell mode for /etc/rc and /etc/netstart to be
able to use ksh syntax within these scripts. This way init doesn't
need to be changed, which starts /etc/rc using /bin/sh and people
can still use "sh /etc/netstart ifname".

Idea from and OK halex@
OK deraadt@ krw@ guenther@


# 1.152 19-Jul-2015 florian

Bring up pflow last as it might send with a source address that is on
any of the other interfaces.
OK deraadt, phessler, benno


# 1.151 19-Jul-2015 rpe

Always source rc.subr to be able to use the rc.conf parsing routine
to get the network related vars from rc.conf. This is even necessary
if netstart is run from within /etc/rc. Remove test of $INRC which
unintentionally evaluated always to true.

problem with previous change found by nigel@
OK sthen@ aja@ halex@


# 1.150 19-Jul-2015 ajacoutot

Revert 1.148 for now until I can talk to rpe@
It introduced a regression reported by nigel@


# 1.149 19-Jul-2015 rpe

Replace test command with [].

OK halex@ krw@


# 1.148 19-Jul-2015 rpe

Ensure, that we source rc.subr and parse rc.conf ONLY if we are not
inside /etc/rc.

With help from and OK halex@, ajacoutot@


# 1.147 18-Jul-2015 rpe

- remove trailing blanks introduced in previous commit
- no space in redirections like </foo or >$bar
- few other minor whitespaces

OK krw@


# 1.146 18-Jul-2015 rpe

Improve comments
- Add comments for functions
- Start comments with capital letters
- End comments with a full stop
- Allow comments to extend up to column 80

OK krw@


# 1.145 06-Jun-2015 florian

Allow rtsol keyword in hostname.if(5) with net.inet6.ip6.forwarding=1.
"inet6 autoconf" was working before and rtsol should behave the same.
OK phessler


Revision tags: OPENBSD_5_7_BASE
# 1.144 03-Dec-2014 florian

The kernel handles rtsol(8) functionality since some time now.
Treat rtsol in hostname.if as a keyword like dhcp and call ifconfig
inet6 autoconf.
"reads good" todd@
OK krw@ (who is *not* an IPv6 person), but I recruited him in his
capacity as an installer person.


# 1.143 28-Sep-2014 claudio

Revert 1.142. Without the down netstart will just print the ifconfig
output because it may end up just calling 'ifconfig $if'. This needs
to be done better and properly tested.


# 1.142 26-Sep-2014 halex

remove explicit 'down' of an interface before starting a dhcp request, thereby
avoiding annoying delays for some switch configurations

ok claudio@ deraadt@

i would add ok phessler@, but it was not valid without an ok krw@


Revision tags: OPENBSD_5_6_BASE
# 1.141 12-Jul-2014 stsp

Fix netstart after autoconf6 change so 'rtsol' lines in hostname.if work again.
found by pelikan@; ok pelikan@ henning@


# 1.140 12-Jul-2014 robert

Make rc.conf a parsed configuration file and stop sourcing it as a shell
script.
From now on rc.conf has a fixed syntax (key=val) and it is not allowed
to add anything to it besides the supported syntax, it all going to be
ignored.

discussed with and help from deraadt@ and halex@


Revision tags: OPENBSD_5_5_BASE
# 1.139 22-Aug-2013 mpi

Like for dhclient, do no create a route to alias addresses via 127.0.0.1.
Our stack is able to tell if the address is local or not.

ok todd@, krw@


Revision tags: OPENBSD_5_4_BASE
# 1.138 20-Mar-2013 todd

fix lies in netstart; replacement wording from halex@
pointed out by Ryan Kavannagh rak at debian dot org


Revision tags: OPENBSD_5_3_BASE
# 1.137 05-Dec-2012 rpe

remove "Invalid interface name" message
requested by krw@

ok halex@


# 1.136 02-Dec-2012 rpe

use the more compact version of the check for ifconfig'able interfaces
from install.sub

with feedback from and ok halex


# 1.135 02-Dec-2012 rpe

- remove isalphanumeric() and replace it with a shell pattern, that
tries a bit harder to identify invalid interface names and in
this case emit an error message.
- use [[ $1 == autoboot ]] to avoid a shell error message due to
possible spaces in first argument
- no change in functionality

discussed with krw and halex
ok ("I like this") krw


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.134 07-Oct-2011 deraadt

The new ypbind changes requires that the domainname be set before
rc.conf is run. There's no real downside.
ok aja


Revision tags: OPENBSD_5_0_BASE
# 1.133 07-Jul-2011 guenther

Eliminate some $? tests by rolling the command into the condition

ok halex@


# 1.132 26-May-2011 mpf

Add svlan(4) startup bits.
From markus@. OK naddy, claudio, reyk.


Revision tags: OPENBSD_4_9_BASE
# 1.131 09-Feb-2011 sobrado

fix an unbalanced parenthesis in a comment; while here, split the comment
in a better place to make it more readable.

ok jmc@ and miod@


Revision tags: OPENBSD_4_8_BASE
# 1.130 16-Jun-2010 todd

permit e.g. -inet6 syntax by slurping all lines not just some
noticed by rhsv6 at hushmail dot com, ok sthen@


Revision tags: OPENBSD_4_7_BASE
# 1.129 12-Jan-2010 henning

when setting up lo0 use 127.0.0.1/8 instead of 127.0.0.1 for clarity and
correctness. it's not 1992 any more, kids. ok mcbride dlg krw


# 1.128 10-Dec-2009 todd

o stop reordering ifconfig arguments (e.g. after 'up ..')
o only stop processing if inet or inet6 lines are malformed
o everything not a specially handled bit is passed to ifconfig unmangled
noticed by several after the move from bridgename.bridge0 -> hostname.bridge0
prodded by deraadt@, tested by and feedback from several
man page bits 'look fine' jmc@


# 1.127 22-Nov-2009 deraadt

Stop supporting bridgename.bridge* files, and move to hostname.bridge*
files. To cope with this change, read about the mv command.
ok claudio todd


# 1.126 17-Sep-2009 simon

change variable i to $i in an expression of ifstart() for consistency
with the rest of the file. no functional change.

feedback from sthen@, ok krw@


# 1.125 10-Jul-2009 jdixon

Delay creation of tun(4) interfaces until the underlying interface and
routes are available. This fixes usage for some OpenVPN users that start
it from hostname.tun*.

Tested by Johan Huldtgren. ok sthen@, johan@.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.124 25-Nov-2008 markus

delay /etc/netstart until IPv6-DAD (dup-address-detection) is completed.
ok fries, hshoexer, claudio


# 1.123 14-Aug-2008 sthen

Tools from /usr may not be used in netstart since it may be NFS-mounted
and not available at that time. Rewrite the hostname.if permission check
to use only /bin/ls and the shell. Requested by deraadt.

ok todd, "Twisted." deraadt


Revision tags: OPENBSD_4_4_BASE
# 1.122 23-Jul-2008 sthen

Prevent warning about insecure hostnames where no /etc/hostname.*
exists. From wcmaier@.

Check target of symbolic links to avoid noise at boot and in
seucrity output where you have several interfaces symlinked to one
config file.

"If you think this is the right thing to do" deraadt@


# 1.121 09-Jun-2008 todd

warn once not 3 times in case of a non existent file, discussed with deraadt
originally pointed out by Johan Torin


# 1.120 09-Jun-2008 deraadt

Ensure that hostname.* files are also re-chowned to root.wheel at each
boot as discussed with claudio while eating tasty donairs. ok todd


# 1.119 17-Apr-2008 deraadt

before using them, force hostname.* files to be unreadable by world
first version from todd, ok millert


Revision tags: OPENBSD_4_3_BASE
# 1.118 17-Jan-2008 brad

Execute rtsol after turning up trunk(4) and vlan(4) interfaces so they're
taken into consideration for rtsol.

ok reyk@ dlg@


# 1.117 09-Jan-2008 mpf

Do not bring up pfsync(4) before the working ruleset
has been loaded. Otherwise, states that are received during the
initial bulk update mismatch the correct pf-checksum and
do not attach to the rules.
Problem identified by david@. Fix done in collaboration.
OK henning@


Revision tags: OPENBSD_4_2_BASE
# 1.116 02-Aug-2007 david

move the delay for IPv6 DAD to after all interfaces have started
fixes problems with daemons being unable to bind to all addreses at boot
ok itojun@ hshoexer@


Revision tags: OPENBSD_4_1_BASE
# 1.115 15-Nov-2006 itojun

reject multicast packet without scope identifier specified.


Revision tags: OPENBSD_4_0_BASE
# 1.114 29-Jun-2006 todd

do not add an extra space; nwid and description come out wrong
fix as proposed by maja@, thanks!


Revision tags: OPENBSD_3_9_BASE
# 1.113 28-Dec-2005 david

nuke extra whitespace


# 1.112 06-Dec-2005 reyk

multicast_host=YES only works if a valid default gateway is available.
validate this condition and reject multicast traffic on failure.

ok todd@ naddy@


# 1.111 02-Nov-2005 todd

fix inspired by pr#4590
ok krw@


# 1.110 25-Oct-2005 todd

better logic from krw@:
- do not process mygate for v4 if dhcp
- do not process mygate for v6 if rtsol
this also makes the mygate processing logic more readable
ok krw@


# 1.109 14-Oct-2005 todd

add v6 support for /etc/mygate
ok deraadt@ mickey@ krw@
same functionality tested/ok'ed by by mickey, brad, matthieu, and me
with this one may now put a v6 IP in /etc/mygate on a separate line from
the v4 default gateway and netstart will do the right thing


# 1.108 12-Oct-2005 todd

shrink stripcom(), sync with install.sub
ok krw@


# 1.107 04-Oct-2005 todd

trunk must be started after physical ethernet devices, but before vlan.
populate ifmstart lines accordingly.
prodded/tested by brad@
ok reyk@


# 1.106 28-Sep-2005 todd

use eval consistently, fixes description quotes on rtsol and dhcp
fix inspired by and closes pr 4495
ok krw@


Revision tags: OPENBSD_3_8_BASE
# 1.105 22-May-2005 todd

Introduce 'ifmstart' to deal with starting multiple interfaces minus a list
of interfaces.

This reduces the netstart script by 174 chars, 13 words, and 19 lines, but
more importantly, makes it more simple and less cluttered should more special
case/orderings be needed.

ok brad@ and pr 4197 submitter, inspired by and closes pr 4197


# 1.104 04-Apr-2005 djm

unbreak; ok pval@


# 1.103 03-Apr-2005 deraadt

if dhcp is used to get an address on any interface, ignore /etc/mygate
ok krw
(this lets us do something rather cool with the zaurus in particular)


Revision tags: OPENBSD_3_7_BASE
# 1.102 04-Jan-2005 mcbride

Bring up the carp(4) interface before default route.

ok pascoe@ mpf@


# 1.101 30-Dec-2004 millert

Add a copy of stripcom so /etc/netstart can be run standalone again.
OK deraadt@


# 1.100 19-Dec-2004 millert

Allow comments in /etc/{myname,mygate,defaultdomain}; OK deraadt@


# 1.99 04-Dec-2004 itojun

remove "route $hostname 127.0.0.1" line. deraadt ok
*** please update /etc/netstart and test if it works ok for you ***


# 1.98 20-Oct-2004 deraadt

make all route commands use -qn; ok mcbride henning


Revision tags: OPENBSD_3_6_BASE
# 1.97 29-May-2004 deraadt

one last route command lacking -qn


Revision tags: OPENBSD_3_5_BASE
# 1.96 22-Mar-2004 mcbride

Make sure pfsync is brought up before carp.

ok deraadt@


# 1.95 13-Mar-2004 mcbride

Delay pfsync(4) configuration, as the syncif has to be configured in
advance. From Thorsten Lockert.


# 1.94 14-Jan-2004 deraadt

ok, it took quite a bit of prodding but itojun finally explained why the
extra sleep 1 is in here, and we came to the conclusion it is safe to
delete it. whee.


# 1.93 13-Jan-2004 deraadt

repair v6 lo0 documentation


# 1.92 11-Jan-2004 deraadt

add loopback routes late


# 1.91 09-Jan-2004 deraadt

create all routes with -q; markus ok


# 1.90 04-Dec-2003 millert

Need to do "ifconfig create" for bridge interfaces too.


# 1.89 03-Dec-2003 markus

add support for ifconfig clone; from netbsd; ok deraadt, henning


# 1.88 20-Oct-2003 david

delay carp initialization until after physical interfaces are configured
ok mcbride@ henning@ deraadt@ todd@


Revision tags: OPENBSD_3_4_BASE
# 1.87 27-Aug-2003 henning

only try to set hostname to what /etc/myname says if that file actually exists,
otherwise preserve `hostname`
netbooted machines can live perfectly fine without it; they get their hostname
earlier.

ok krw@ cedric@


Revision tags: OPENBSD_3_3_BASE
# 1.86 16-Feb-2003 krw

Fix up some DNS verbiage to make it consistant.

Fix up default route selection by

a) Forcing user to explicitly chose 'dhcp' as a mechanism for
specifying a default route, rather than guessing based on one or more
interfaces being configured by dhcp.

b) If the user specified default route does not work, re-present the
existing default route rather than losing it.

c) Move default route selection to after nameserver activation so the
user can specify a hostname as the default route.

Change /etc/netstart so that /etc/mygate wins if a default route was
already specified (i.e. by dhcp).

ok deraadt@.


Revision tags: OPENBSD_3_2_BASE
# 1.85 16-May-2002 todd

ignore non-existent cases where '$if' evaluates to '*'.
From Andr� Lucas <andre@ae-35.com>, fixes pr # 2658.
'Looks good' from miod@, millert@, and krw@.


Revision tags: OPENBSD_3_1_BASE
# 1.84 23-Feb-2002 deraadt

re-add support for $if expansion; hamajima@nagoya.ydc.co.jp


# 1.83 21-Feb-2002 miod

Change the network components initialization order.
Change from:
o all interfaces
o all bridges
o routes
to:
o physical interfaces
o routes
o gif and gre interfaces
o bridges

Fixeski PR #2400.
Manual page updates coming soon.
Ok angelos@ chris@ deraadt@


Revision tags: OPENBSD_3_0_BASE
# 1.82 31-Jul-2001 hugh

a space before a redirect


# 1.81 06-Jul-2001 angelos

Also, source /etc/rc.conf so we can pull in the
multicast_host/multicast_router settings; this is useful if one
flushes the routing table and re-initializes.

We really need a netconfig tool of sorts.


# 1.80 06-Jul-2001 angelos

Use "route -n show -inet" to determine the default multicast iface.


# 1.79 03-Jul-2001 deraadt

pull in rc.conf early so that pf(1) startup is right; tested by jasoni, comments from millert


# 1.78 30-May-2001 deraadt

Remove ipf. Darren Reed has interpreted his (old, new, whichever)
licence in a way that makes ipf not free according to the rules we
established over 5 years ago, at www.openbsd.org/goals.html (and those
same basic rules govern the other *BSD projects too). Specifically,
Darren says that modified versions are not permitted. But software
which OpenBSD uses and redistributes must be free to all (be they
people or companies), for any purpose they wish to use it, including
modification, use, peeing on, or even integration into baby mulching
machines or atomic bombs to be dropped on Australia. Furthermore, we
know of a number of companies using ipf with modification like us, who
are now in the same situation, and we hope that some of them will work
with us to fill this gap that now exists in OpenBSD (temporarily, we
hope).


Revision tags: OPENBSD_2_9_BASE
# 1.77 13-Mar-2001 deraadt

spelling; maurice@maurice.wan.nl


# 1.76 06-Feb-2001 todd

ignore blank lines in addition to comments
fixes pr#1660 from wilfried@telia.com .. Thanks!


# 1.75 10-Jan-2001 jason

support !command in bridgename.if files, too


# 1.74 27-Nov-2000 millert

Use -n to test if a variable is non-zero. Otherwise, if the variable's
contents start with a '-' test becomes unhappy (since it interprets it
as another option).


# 1.73 08-Nov-2000 todd

This fixes pr 1481, we now handle args > 6 in /etc/hostname.if in the
cases where we did not previously handle them.
Thanks to Scott Atwood <atwood@cs.stanford.edu> for reminding us of this.


Revision tags: OPENBSD_2_8_BASE
# 1.72 02-Sep-2000 todd

subtle bug .. global variables in a while loop need reset 'just incase'
With:
hostname.fxp0 having a last line of:
inet6 alias 3ffe:...
and hostname.gif0 having a first two lines of:
giftunnel 1.2.3.4
dest 1.2.4.3
We end up with the command:
ifconfig gif0 giftunnel alias 1.2.3.4 1.2.4.3
.. which is clearly wrong and fixed by this change


# 1.71 18-Jun-2000 todd

rc.conf now parses ${local_rcconf} internally; closes pr 1259


Revision tags: OPENBSD_2_7_BASE
# 1.70 08-May-2000 todd

fix dhcp 'NONE' ness from install to allow media parsing to work
.. ok deraadt@, millert@


# 1.69 21-Apr-2000 deraadt

rc.conf.local support, inspired by chuck yerkes


# 1.68 04-Apr-2000 millert

Remove the -E flag from ipf as it is implicitly enabled and using
the -E flag here causes the kernel to printf 'IP Filter: already
initialized'.


# 1.67 18-Mar-2000 deraadt

silence all extra route addition printouts


# 1.66 17-Mar-2000 itojun

correct reject route installations for IPv6. improve comments.


# 1.65 12-Mar-2000 itojun

disallow packets to malicious 6to4 prefix, based on
http://playground.iijlab.net/i-d/draft-itojun-ipv6-transition-abuse-00.txt


# 1.64 10-Mar-2000 todd

fix non behavior
with this `!' lines in /etc/hostname.* run even without certain lines
(like a comment) preceeding it.


# 1.63 10-Jan-2000 todd

allow arbitrary commands in /etc/hostname.* files if the line starts with '!'


# 1.62 02-Jan-2000 deraadt

rtsol case can configure the interface up, since it would be nice to finish
DAD before the actual rtsol(8) run happens later. and since it will rtsol,
it is going to be up in any case.


# 1.61 02-Jan-2000 itojun

one more indentation fix.


# 1.60 02-Jan-2000 itojun

indentation fix (todd's part)


# 1.59 02-Jan-2000 todd

fix rtsold case, reset cmd for each iteration!


# 1.58 02-Jan-2000 itojun

allow options after "rtsol".
XXX both "dhcp" and "rtsol" has keyword *down* at the end. is it okay?


# 1.57 02-Jan-2000 itojun

echo "IPv6 autoconf: interfaces" before invoking rtsol.
sleep for net.inet6.ip6.dad_count seconds to ensure that IPv6 DAD is completed.
TODO: rtsold (rc.conf line), manpage


# 1.56 02-Jan-2000 itojun

ipv6 autoconf on hosts (non-routers).

to do this,
1. in sysctl.conf, add these lines:
net.inet6.ip6.forwarding=0
net.inet6.ip6.accept_rtadv=1
2. in hostname.foo, add
rtsol

specifying two or more interfaces with "rtsol" may result in strange
behavior - ipv6 spec does not permit multi-interface node to be autoconfig'ed.


# 1.55 02-Jan-2000 todd

add to hostname.* parsing:
- multiple entries support (read: aliases)
- inet6 support
- support for comments (#)
(look for hostname.if(5) commit for syntax details)


# 1.54 31-Dec-1999 itojun

install IPv6 reject routes only if kernel is capable of IPv6.


# 1.53 09-Dec-1999 itojun

avoid transmitting invalid IPv6 packets out to the wire.


# 1.52 09-Dec-1999 itojun

do not perform IPv6 initialization for loopback interface.
MUST make lo0 up before any IPv6 operations.
it will be considered a pilot error if you don't.
(I prefer to have lo0 initialized automatically)


Revision tags: OPENBSD_2_6_BASE
# 1.51 01-Sep-1999 deraadt

support # characters in bridgename.* files; millert


# 1.50 01-Sep-1999 deraadt

cleanup parsing of hostname.* files, and seperate bridge control into
bridgename.* files; all documented in new hostname.if(5) and
bridgename.if(5) man pages


# 1.49 09-Aug-1999 angelos

Only parse/setup the hostname.foo file if interface foo exists (this
is useful for laptops with different ethernet cards etc.)


Revision tags: OPENBSD_2_5_BASE
# 1.48 29-Mar-1999 niklas

New multicast route setup style


# 1.47 26-Mar-1999 niklas

Add bridge interface handling


# 1.46 01-Mar-1999 millert

Add support in /etc/hostname.xxx for files of the format:
up [options]
Any of the following may or may not be set:
$name $mask $bcaddr $extras


# 1.45 28-Oct-1998 millert

Kill the awful hack used to match and split /etc/hostname.* We now use
a function, isalphanumeric, to determine whether an interface name is
likely to be valid. This means that things like /etc/hostname.le0.bak,
/etc/hostname.le0#, /etc/hostname.le0~, etc. will be ignored as they
should. There is no longer an implicate assumption that /etc/hostname.*
only contains a single '.'.


Revision tags: OPENBSD_2_4_BASE
# 1.44 06-Oct-1998 deraadt

move ipnat to end of netstart, to support dhcp+ipnat


# 1.43 18-Sep-1998 deraadt

apply media directives on dhcp interfaces


# 1.42 10-Sep-1998 marc

better way of handling dhcp client; Jason Ish <jbi130@mail.usask.ca>


# 1.41 08-Sep-1998 marc

dhcp client stuff. "Angelos D. Keromytis" <angelos@dsl.cis.upenn.edu>


# 1.40 24-Aug-1998 downsj

You can't use -interface default when there's no default gateway
set (yet). Use -interface $hostname if mygate doesn't exist so that
this actually works on routers.


# 1.39 04-Jul-1998 deraadt

put 224 route on default, to avoid a hostname lookup


# 1.38 22-May-1998 deraadt

use route -n, what the heck


Revision tags: OPENBSD_2_3_BASE
# 1.37 28-Mar-1998 deraadt

s/^nat/ipnat/


# 1.36 23-Feb-1998 niklas

remove trailing blank line


# 1.35 07-Feb-1998 deraadt

ipforward is in sysctl.conf now


# 1.34 21-Dec-1997 deraadt

ugh


# 1.33 20-Dec-1997 deraadt

ipforwarding option in rc.conf


# 1.32 29-Nov-1997 kstailey

NAT requires IPF


# 1.31 04-Nov-1997 deraadt

kill spaces at ends of lines; m4


Revision tags: OPENBSD_2_2_BASE
# 1.30 14-Oct-1997 deraadt

set hostname/domainname before running rc.conf; m4@umn.edu


# 1.29 04-Sep-1997 deraadt

fork netstart; new child is rc.conf


# 1.28 25-Aug-1997 millert

Explicately pass -host flag to route(8) to avoid confusion with networks.


# 1.27 19-Aug-1997 niklas

Add hook for rpc.lockd, make nfsd flags settable in netstart


# 1.26 31-Jul-1997 downsj

Make quotas optional; wedged into netstart for the time being.
/etc/rc.conf, anyone?


# 1.25 30-Jul-1997 deraadt

do not run routed by default


# 1.24 28-Jul-1997 kstailey

Move configuration of loopback interface to before all other interfaces.
Allows the use of local caching-only nameserver with no "nameserver"
entry in /etc/resolv.conf to configure a route between the hostname
and loopback.


# 1.23 25-Jul-1997 provos

earlier start of keymanagement


# 1.22 24-Jul-1997 deraadt

make amd use /tmp_mnt by default


# 1.21 22-Jul-1997 provos

start the photuris daemon per default. hilfe.


# 1.20 17-Jun-1997 niklas

Put in hooks to start ypserv with flags


# 1.19 17-Jun-1997 niklas

Put in hooks to start rpc.yppasswdd with flags


Revision tags: OPENBSD_2_1_BASE
# 1.18 15-Apr-1997 deraadt

kill route flush until .. hmm kernel routing socket bug or something


# 1.17 09-Apr-1997 kstailey

add NAT startup


# 1.16 07-Apr-1997 rees

flush all old routes before adding new interfaces or routes.
ref: netbsd pr3228/misc, Matthias Scheler


# 1.15 03-Mar-1997 downsj

fix typo


# 1.14 11-Feb-1997 deraadt

add default route before fiddling with loopback route to avoid DNS problems; m4@umn.edu, #97


# 1.13 03-Feb-1997 deraadt

do ifaliases after /usr/bin exists in nfs diskless env; pr#77, matthieu@laas.fr


# 1.12 02-Nov-1996 deraadt

timed off by default


Revision tags: OPENBSD_2_0_BASE
# 1.11 23-Sep-1996 deraadt

rfc1323 variable


# 1.10 04-Sep-1996 deraadt

control portmap, inetd, and lpd from netstart; idea from tqbf@enteract.com


# 1.9 27-Aug-1996 deraadt

224.0.0.0 not 0.0.0.224; from peter@demon.net


# 1.8 18-Jun-1996 deraadt

move std stuff from rc.local to rc


# 1.7 16-Jun-1996 deraadt

install sample commented /etc/ifaliases file; which can now contain #
comments and blank lines. new format is "interface address netmask"
(yes, i changed the order of the entries). inspired by netbsd pr#2474;
gillhaa@ghost.whirlpool.com


# 1.6 02-Jun-1996 tholo

Install a multicast route by default


# 1.5 26-May-1996 deraadt

sync & label


# 1.4 09-Jan-1996 dm

added IP filter to netstat/rc and put examples in /usr/share/ipf


# 1.3 30-Dec-1995 deraadt

from netbsd: start mrouted like routed


# 1.2 18-Dec-1995 deraadt

/etc/ifaliases support by randy@zyzzyva.com


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.214 06-Aug-2021 sthen

As tim@ spotted, a use of V4_AUTOCONF crept in when the variable name
was actually V4_DHCPCONF from previous use. Rename all of the V4_DHCPCONF
to V4_AUTOCONF so everything uses the new name. ok and reminder about
the installer from tb@


# 1.213 16-Jul-2021 florian

switch to dhcpleased/resolvd in base
OK deraadt


# 1.212 20-Jun-2021 florian

Don't try to install a default route with route(8) later on if we are
using inet autoconf, like we do with "dhcp" and "inet6 autoconf".
OK kn


Revision tags: OPENBSD_6_9_BASE
# 1.211 23-Dec-2020 krw

Allow the provision of dhclient(8) options on 'dhcp' lines in hostname.if(5)
files.

Usual man page help & ok jmc@


# 1.210 21-Dec-2020 krw

Avoid issuing pointless 'ifconfig <if> up' when processing 'dhcp' in
hostname.if files. dhclient(8) does that itself. Part of the
"further script optimizations" promised in r1.200 of netstart.

Tested & ok gnezdo@


# 1.209 29-Nov-2020 tb

Fix previous: use correct version of netstart and installer bits.


# 1.208 29-Nov-2020 deraadt

Add support for !command to mygate, so that netstart has a late opportunity
to perform network configuration (for example, "!route source -ifp em0")
Split mygate and myname manual pages (how did anyone ever believe these
are related), and perform hostname configuration much earlier in rc.
discussed with benno, claudio, jmc, etc etc, last version of !command
parser by tb


# 1.207 08-Nov-2020 jmc

no more mobileip;
ok claudio deraadt


Revision tags: OPENBSD_6_8_BASE
# 1.206 21-Jun-2020 dlg

start wg with the other interfaces that rely on routing being up.

from Matt Dunwoodie and Jason A. Donenfeld

ok deraadt@


# 1.205 22-May-2020 kn

Revert the following commit as it breaks hostname.if(5) lines with a
backslash at the end for line continuation

Breaking long lines into multiple ones must still be possible and does
require to treat the backslash as an escape character.

Breakage reported by Mark Patruck <mark at wrapped dot cx >, thanks!

---
distrib/miniroot/install.sub revision 1.1151
etc/netstart revision 1.203
date: 2020/05/21 11:54:41; author: kn; state: Exp; lines: +2 -2;
Do not treat backslashe as an escape character in hostname.if(5) lines

ifstart() should always pass such lines unaltered, especially if they
contain "nwid" or "description" lines with arbitrary strings.

<bsdlisten at gmail dot com> reported SSIDs such as "Mike's" during
installation end as broken; this was because the installer escaped
the single quote using backslashes which ended up being treated as
escape characters much later during hostname.if parsing in netstart(8).

Ok deraadt


# 1.204 21-May-2020 kn

Fix stripcom() description wrt. comments not on their own line

Neither netstart's nor install.sub's (subtly different) implementations
remove trailing comments on lines not starting as a comment, e.g.,
lines like "up #not down" go through unaltered and without "#not down"
being removed.

Only lines *beginning* with the comment sign ("#") are stripped.

No functional change, just updating function descriptions.


# 1.203 21-May-2020 kn

Do not treat backslashe as an escape character in hostname.if(5) lines

ifstart() should always pass such lines unaltered, especially if they
contain "nwid" or "description" lines with arbitrary strings.

<bsdlisten at gmail dot com> reported SSIDs such as "Mike's" during
installation end as broken; this was because the installer escaped
the single quote using backslashes which ended up being treated as
escape characters much later during hostname.if parsing in netstart(8).

Ok deraadt


Revision tags: OPENBSD_6_7_BASE
# 1.202 15-Jan-2020 kn

Do not redirect already quiet stdout for IPv6 reject routes

"route -q" already silences all standard output; if it still prints
something, that's a bug to fix in route.

OK bluhm


# 1.201 25-Oct-2019 dlg

handle aggr(4) in the same way as trunk(4)

from brad@
ok bluhm@ claudio@ deraadt@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.200 29-Aug-2018 krw

Historically /etc/netstart (and the equivalent code in the install
script) did 'ifconfig <if> down' before starting dhclient(8). This was
a way of ensuring old running copies of dhclient were killed before a
new one started. Current dhclient does not need this assist, so change
"ifconfig <if> down" to "ifconfig <if> up" pending further script
optimizations.

Similar to a 2014 attempt by halex@. Prompted by a misc@ report
from Kristjan Komlosi reporting hanging diskless setups.

ok halex@ kn@


# 1.199 08-Jul-2018 tb

netstart is used during system start, but also interactively.
Show proper error message if a regular user executes netstart.
Only do the privilege check if the id binary is available,
which might not be the case during diskless system startup.

ok deraadt, jasper, jca, krw, rpe (who wrote the same diff), sthen


# 1.198 28-Apr-2018 rpe

Add a proper usage() function.

Suggested by and OK jmc.
OK tb


Revision tags: OPENBSD_6_3_BASE
# 1.197 04-Mar-2018 jmc

when -n is used, no need to spit out "Missing parameters." before
displaying usage();

ok tb


# 1.196 03-Mar-2018 landry

Lowercase 'usage' and group -n with interface in it.
From jmc@, ok tb@


# 1.195 21-Feb-2018 rpe

Tweak comments.

OK tb


# 1.194 19-Feb-2018 rpe

Write warning/error messages to stderr and end them with a fullstop.

OK tb


# 1.193 19-Feb-2018 rpe

- use specific patterns when looping over /etc/hostname.if files
to skip backup or temp files.
- test if the patterns matched actual files
- warn if ifcreate() fails on an interface and continue with the
subsequent interfaces in the list instead of return'ing

OK dlg sthen tb


# 1.192 17-Feb-2018 rpe

- Add descriptions for the new functions ifcreate() and vifscreate()
- In ifcreate() use the exit code of the {} block directly
- In vifscreate(), use the ifconfig -C output directly in the for _vif loop
- Remove superfluous and somewhat confusing comment

OK dlg kn sthen


# 1.191 14-Feb-2018 dlg

create virtual interfaces before starting all interface config.

this resolves an ordering problem when adding pseudo interfaces to bridges

tweaks from kn@
ok mpi@ sthen@


# 1.190 10-Feb-2018 claudio

Remove some special IPv4 in IPv6 mapped prefixes that are already rejected
by the ::0.0.0.0/96 reject route added to deny all IPv4 mapped addresses.
Makes the inet6 routing table almost fit in one screen.
OK benno@


# 1.189 10-Feb-2018 florian

Load RFC 7217 key material and generate if it does not already exist.

Add soii.key to changelist (pointed out by semarie) and mtree/special
(suggest by Craig Skinner).

OK naddy, sthen, rpe, tb


# 1.188 06-Feb-2018 tb

If -n is given, the netstart script should not (try to) set the default
route(s). Simply print the command(s) to be issued instead.

tweak & ok rpe


# 1.187 12-Nov-2017 tb

Remove HN_DIR variable and expand it in the only place it was used. It
currently serves no purpose.

ok rpe, agreement from deraadt and halex


Revision tags: OPENBSD_6_2_BASE
# 1.186 25-Jul-2017 rpe

Finally remove backwards compat code to support the 'rtsol' keyword
in hostname.if(5)

OK mpi@ deraadt@ florian@
OK jmc@ from doc perspective


# 1.185 21-Jul-2017 rpe

Align ifstart() in netstart and install.sub.

- in netstart, rename _file to _hn referencing hostname.if files
- in install.sub switch ifstart() to be used with _if instead of
_hn as parameter

ok krw@ tb@


# 1.184 28-May-2017 awolk

etc/netstart: use colon separator instead of dot with chown

OK jung@, deraadt@, jmc@


# 1.183 07-May-2017 rpe

Change test from [] to [[]] and simplify pattern.

OK tb@, krw@ (for [[]])
Feedback and OK halex@


# 1.182 07-May-2017 rpe

Replace hardcoded script name with ${0##*/}

OK tb@ halex@


# 1.181 01-May-2017 rpe

Revert r1.170 and remove the id==0 check.
The id binary is not available in nfs diskless setups at this point.

reported by Andreas Kusalananda, thanks.
discussed with deraadt@


# 1.180 01-May-2017 rpe

Remove last remnants of rtsol. IPv6 autoconfiguration of interfaces is now
done in ifstart(). Remove ipv6autoconf() and replace rtsolif with a boolean
variable V6_AUTOCONF. Replace dhcpif with a boolean variable V4_DHCPCONF.
Both are later used in defaultroute() to decide whether or not to configre
defaultroutes from /etc/mygate.

OK krw@


# 1.179 30-Apr-2017 mpi

Do not try to delete a default route before adding it.

Now that route are automatically G/C with the address they are attached
to there's no reason to duplicate the kernel's job.

Fix a regression introduced with multipath default routes.

ok deraadt@


# 1.178 25-Apr-2017 rpe

Unbreak netstart for multiple inteface configurations like trunk
or carp. Ensure that the noglob option is disabled at the end of
parse_hn_line() and ifstart().

Reported by Christer Solskogen and Stefan Wollny, thanks!


# 1.177 24-Apr-2017 rpe

Introduce a new function parse_hn_line() that replaces the existing
hostname.if(5) parsing code in ifstart().
Add a -n option to netstart to only print the interface configuration
commands instead of executing them.
Add a HN_DIR variable, that points to the directory of the hostname.if
files (default /etc) that allows for future regression tests.

- add new parse_hn_line() function
- change ifstart()
- rename $if to $_if
- don't ifconfig or ifconfig create if -n option is used
- replace hostname.if(5) parsing code with new parse_hn_line()
- just print configuration commands if -n option is used
- autoconf now happens in ifstart(), remove ifv6autoconf()
- introduce HN_DIR variable for the hostname.if file location
- add handling of the -n option to only print config commands
- ensure -n is only used if interfaces are specified as parameters

Discussed with and positive feedback from many
'commit' deraadt@
OK sthen@


# 1.176 08-Apr-2017 rpe

- localize the if, file and stat variables which also ensures that
variables are not named like commands.
- change test from [] to [[]]

OK tb@ halex@


# 1.175 07-Apr-2017 rpe

Minimize differences in ifstart() function between netstart and
install.sub which makes it easier to spot changes in the future.

- comments and formatting
- quotes on assignments are not needed (netstart)
- remove stray space in test (netstart)
- use $file variable with while-loop (netstart)
- although valid, instead of i use $i in arithmetic test (install.sub)

OK krw@, tb@
Looks good deraadt@


# 1.174 07-Apr-2017 rpe

Align comments of ifstart() function in netstart and install.sub.


# 1.173 07-Apr-2017 rpe

Align comments of stripcom() function in netstart and install.sub.


Revision tags: OPENBSD_6_1_BASE
# 1.172 06-Dec-2016 mpi

Do not lose the default route when netstart(8) is run a second time on
the interface pointed to by the default route.

Since the kernel no longer keep routes with dangling address pointer,
netstart(8) has to re-add the default route when the corresponding ifa
has been deleted and re-created.

deraadt@ points out that even if the previous semantic was not necessarily
better, a script like netstart(8) cannot totally fix the default route
problem.

Regression reported by and fix tested by Hrvoje Popovski.

ksh foo checked by halex@


# 1.171 27-Sep-2016 rzalamena

Delay switch(4) interface start up so it can attach virtual interfaces
like vether(4).

nits from and ok benno@, phessler@


# 1.170 09-Sep-2016 jasper

print a clear error message when not ran as root instead of just falling
through and try whatever it can do with the invoking user's perms

feedback/ok aja@ rpe@


Revision tags: OPENBSD_6_0_BASE
# 1.169 19-Jul-2016 mpi

Do not consider tap(4) a special interface and start if before other
pseudo-interfaces.

This unbreak vlan(4) on top of tap(4) since the refactoring to turn it
MP-safe.

ok claudio@, deraadt@


# 1.168 27-Mar-2016 sthen

Don't delete the 224/4 route in netstart, unless it's being done to ensure that
a -reject route can be added. Restores the ability to set an interface route
before daemons are started, lost during the previous simplification.
ok millert mpi


Revision tags: OPENBSD_5_9_BASE
# 1.167 29-Dec-2015 rpe

Remove backslash, not necessary after '&&'

OK halex@


# 1.166 29-Dec-2015 rpe

Replace last remaining `` with $()

OK halex@


# 1.165 18-Dec-2015 ajacoutot

Drop the now useless multicast setup comment.

prodded by tim@, ok mpi@


# 1.164 17-Dec-2015 ajacoutot

Simplify multicast option handling (10 less lines) by matching /etc/rc behavior
towards other YES|NO options and drop the error warning.


with and ok tim@, ok rpe@ on an earlier diff


# 1.163 05-Dec-2015 mpi

It does not make sense to insert a specific route for 224/4 when the
default one is good enough.

So merge rc.conf(8)'s 'multicast_router' and 'multicast_host' into a
single 'multicast'. If set to YES the reject route for 224/4 is not
inserted by netstart(8).

Manual bits from jmc@

ok henning@, ajacoutot@


# 1.162 12-Nov-2015 rpe

Changes to ifautostart():
- Rename function to ifv6autoconf() to make IPv6 relation clearer
- Localize and rename variables

OK krw@


# 1.161 12-Nov-2015 rpe

Changes to ifmstart():
- Change comments to make it clearer that ifmstart() takes two lists
of interface driver names (of which the second is optional) and not
the actual interface instances.
- Use localized variables and use slightly more verbose names.
- Use continue 2 to skip to the next hostname.if file.
- Use shell pattern @() instead of testing _sif individually.

OK krw@


# 1.160 12-Nov-2015 rpe

Changes to stripcom():
- Align comments with /etc/rc version
- Use localized variables
- Use safer "print -r --" instead of plain echo

Changes to ifstart():
- Tweak comment
- Add usage

OK krw@


# 1.159 01-Nov-2015 rpe

Start the rework of the /etc/netstart shell script.

General changes:
- apply a similar 'style' as used in the installer scripts
- improve comments to be more to the point, remove where code is obvious
- document usage of functions if they have arguments
- rename variables where it improves readability
- replace really old-school shell code with more contemporary idioms

Other changes:
- No need to care about "autoboot" because netstart doesn't inherit the
positional parameters from /etc/rc anymore. /etc/rc executes netstart
instead of sourcing it since r1.439.
- Use simpler for-loop to process list of interfaces with ifstart.

OK halex@


# 1.158 26-Oct-2015 rpe

The hostname variable is not used since r1.99. Remove it and use
stripcom() output directly with the hostname command.

OK deraadt@ krw@


# 1.157 23-Oct-2015 claudio

netstart bits for tap(4)


# 1.156 27-Sep-2015 sthen

Don't print output when setting autoconf on interfaces. Suggested by deraadt,
ok florian@ rpe@


# 1.155 13-Sep-2015 sthen

only print the "IPv6 autoconf" line if there are interfaces to configure
feedback/ok rpe


# 1.154 11-Sep-2015 sthen

Set "inet6 autoconf" individually on interfaces that have rtsol set in
hostname.if, previously netstart tried to configure them all at once
("ifconfig if0 if1 if2 inet6 autoconf"). From Delan Azabani, ok phessler@


Revision tags: OPENBSD_5_8_BASE
# 1.153 20-Jul-2015 rpe

Disable Strict Bourne shell mode for /etc/rc and /etc/netstart to be
able to use ksh syntax within these scripts. This way init doesn't
need to be changed, which starts /etc/rc using /bin/sh and people
can still use "sh /etc/netstart ifname".

Idea from and OK halex@
OK deraadt@ krw@ guenther@


# 1.152 19-Jul-2015 florian

Bring up pflow last as it might send with a source address that is on
any of the other interfaces.
OK deraadt, phessler, benno


# 1.151 19-Jul-2015 rpe

Always source rc.subr to be able to use the rc.conf parsing routine
to get the network related vars from rc.conf. This is even necessary
if netstart is run from within /etc/rc. Remove test of $INRC which
unintentionally evaluated always to true.

problem with previous change found by nigel@
OK sthen@ aja@ halex@


# 1.150 19-Jul-2015 ajacoutot

Revert 1.148 for now until I can talk to rpe@
It introduced a regression reported by nigel@


# 1.149 19-Jul-2015 rpe

Replace test command with [].

OK halex@ krw@


# 1.148 19-Jul-2015 rpe

Ensure, that we source rc.subr and parse rc.conf ONLY if we are not
inside /etc/rc.

With help from and OK halex@, ajacoutot@


# 1.147 18-Jul-2015 rpe

- remove trailing blanks introduced in previous commit
- no space in redirections like </foo or >$bar
- few other minor whitespaces

OK krw@


# 1.146 18-Jul-2015 rpe

Improve comments
- Add comments for functions
- Start comments with capital letters
- End comments with a full stop
- Allow comments to extend up to column 80

OK krw@


# 1.145 06-Jun-2015 florian

Allow rtsol keyword in hostname.if(5) with net.inet6.ip6.forwarding=1.
"inet6 autoconf" was working before and rtsol should behave the same.
OK phessler


Revision tags: OPENBSD_5_7_BASE
# 1.144 03-Dec-2014 florian

The kernel handles rtsol(8) functionality since some time now.
Treat rtsol in hostname.if as a keyword like dhcp and call ifconfig
inet6 autoconf.
"reads good" todd@
OK krw@ (who is *not* an IPv6 person), but I recruited him in his
capacity as an installer person.


# 1.143 28-Sep-2014 claudio

Revert 1.142. Without the down netstart will just print the ifconfig
output because it may end up just calling 'ifconfig $if'. This needs
to be done better and properly tested.


# 1.142 26-Sep-2014 halex

remove explicit 'down' of an interface before starting a dhcp request, thereby
avoiding annoying delays for some switch configurations

ok claudio@ deraadt@

i would add ok phessler@, but it was not valid without an ok krw@


Revision tags: OPENBSD_5_6_BASE
# 1.141 12-Jul-2014 stsp

Fix netstart after autoconf6 change so 'rtsol' lines in hostname.if work again.
found by pelikan@; ok pelikan@ henning@


# 1.140 12-Jul-2014 robert

Make rc.conf a parsed configuration file and stop sourcing it as a shell
script.
From now on rc.conf has a fixed syntax (key=val) and it is not allowed
to add anything to it besides the supported syntax, it all going to be
ignored.

discussed with and help from deraadt@ and halex@


Revision tags: OPENBSD_5_5_BASE
# 1.139 22-Aug-2013 mpi

Like for dhclient, do no create a route to alias addresses via 127.0.0.1.
Our stack is able to tell if the address is local or not.

ok todd@, krw@


Revision tags: OPENBSD_5_4_BASE
# 1.138 20-Mar-2013 todd

fix lies in netstart; replacement wording from halex@
pointed out by Ryan Kavannagh rak at debian dot org


Revision tags: OPENBSD_5_3_BASE
# 1.137 05-Dec-2012 rpe

remove "Invalid interface name" message
requested by krw@

ok halex@


# 1.136 02-Dec-2012 rpe

use the more compact version of the check for ifconfig'able interfaces
from install.sub

with feedback from and ok halex


# 1.135 02-Dec-2012 rpe

- remove isalphanumeric() and replace it with a shell pattern, that
tries a bit harder to identify invalid interface names and in
this case emit an error message.
- use [[ $1 == autoboot ]] to avoid a shell error message due to
possible spaces in first argument
- no change in functionality

discussed with krw and halex
ok ("I like this") krw


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.134 07-Oct-2011 deraadt

The new ypbind changes requires that the domainname be set before
rc.conf is run. There's no real downside.
ok aja


Revision tags: OPENBSD_5_0_BASE
# 1.133 07-Jul-2011 guenther

Eliminate some $? tests by rolling the command into the condition

ok halex@


# 1.132 26-May-2011 mpf

Add svlan(4) startup bits.
From markus@. OK naddy, claudio, reyk.


Revision tags: OPENBSD_4_9_BASE
# 1.131 09-Feb-2011 sobrado

fix an unbalanced parenthesis in a comment; while here, split the comment
in a better place to make it more readable.

ok jmc@ and miod@


Revision tags: OPENBSD_4_8_BASE
# 1.130 16-Jun-2010 todd

permit e.g. -inet6 syntax by slurping all lines not just some
noticed by rhsv6 at hushmail dot com, ok sthen@


Revision tags: OPENBSD_4_7_BASE
# 1.129 12-Jan-2010 henning

when setting up lo0 use 127.0.0.1/8 instead of 127.0.0.1 for clarity and
correctness. it's not 1992 any more, kids. ok mcbride dlg krw


# 1.128 10-Dec-2009 todd

o stop reordering ifconfig arguments (e.g. after 'up ..')
o only stop processing if inet or inet6 lines are malformed
o everything not a specially handled bit is passed to ifconfig unmangled
noticed by several after the move from bridgename.bridge0 -> hostname.bridge0
prodded by deraadt@, tested by and feedback from several
man page bits 'look fine' jmc@


# 1.127 22-Nov-2009 deraadt

Stop supporting bridgename.bridge* files, and move to hostname.bridge*
files. To cope with this change, read about the mv command.
ok claudio todd


# 1.126 17-Sep-2009 simon

change variable i to $i in an expression of ifstart() for consistency
with the rest of the file. no functional change.

feedback from sthen@, ok krw@


# 1.125 10-Jul-2009 jdixon

Delay creation of tun(4) interfaces until the underlying interface and
routes are available. This fixes usage for some OpenVPN users that start
it from hostname.tun*.

Tested by Johan Huldtgren. ok sthen@, johan@.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.124 25-Nov-2008 markus

delay /etc/netstart until IPv6-DAD (dup-address-detection) is completed.
ok fries, hshoexer, claudio


# 1.123 14-Aug-2008 sthen

Tools from /usr may not be used in netstart since it may be NFS-mounted
and not available at that time. Rewrite the hostname.if permission check
to use only /bin/ls and the shell. Requested by deraadt.

ok todd, "Twisted." deraadt


Revision tags: OPENBSD_4_4_BASE
# 1.122 23-Jul-2008 sthen

Prevent warning about insecure hostnames where no /etc/hostname.*
exists. From wcmaier@.

Check target of symbolic links to avoid noise at boot and in
seucrity output where you have several interfaces symlinked to one
config file.

"If you think this is the right thing to do" deraadt@


# 1.121 09-Jun-2008 todd

warn once not 3 times in case of a non existent file, discussed with deraadt
originally pointed out by Johan Torin


# 1.120 09-Jun-2008 deraadt

Ensure that hostname.* files are also re-chowned to root.wheel at each
boot as discussed with claudio while eating tasty donairs. ok todd


# 1.119 17-Apr-2008 deraadt

before using them, force hostname.* files to be unreadable by world
first version from todd, ok millert


Revision tags: OPENBSD_4_3_BASE
# 1.118 17-Jan-2008 brad

Execute rtsol after turning up trunk(4) and vlan(4) interfaces so they're
taken into consideration for rtsol.

ok reyk@ dlg@


# 1.117 09-Jan-2008 mpf

Do not bring up pfsync(4) before the working ruleset
has been loaded. Otherwise, states that are received during the
initial bulk update mismatch the correct pf-checksum and
do not attach to the rules.
Problem identified by david@. Fix done in collaboration.
OK henning@


Revision tags: OPENBSD_4_2_BASE
# 1.116 02-Aug-2007 david

move the delay for IPv6 DAD to after all interfaces have started
fixes problems with daemons being unable to bind to all addreses at boot
ok itojun@ hshoexer@


Revision tags: OPENBSD_4_1_BASE
# 1.115 15-Nov-2006 itojun

reject multicast packet without scope identifier specified.


Revision tags: OPENBSD_4_0_BASE
# 1.114 29-Jun-2006 todd

do not add an extra space; nwid and description come out wrong
fix as proposed by maja@, thanks!


Revision tags: OPENBSD_3_9_BASE
# 1.113 28-Dec-2005 david

nuke extra whitespace


# 1.112 06-Dec-2005 reyk

multicast_host=YES only works if a valid default gateway is available.
validate this condition and reject multicast traffic on failure.

ok todd@ naddy@


# 1.111 02-Nov-2005 todd

fix inspired by pr#4590
ok krw@


# 1.110 25-Oct-2005 todd

better logic from krw@:
- do not process mygate for v4 if dhcp
- do not process mygate for v6 if rtsol
this also makes the mygate processing logic more readable
ok krw@


# 1.109 14-Oct-2005 todd

add v6 support for /etc/mygate
ok deraadt@ mickey@ krw@
same functionality tested/ok'ed by by mickey, brad, matthieu, and me
with this one may now put a v6 IP in /etc/mygate on a separate line from
the v4 default gateway and netstart will do the right thing


# 1.108 12-Oct-2005 todd

shrink stripcom(), sync with install.sub
ok krw@


# 1.107 04-Oct-2005 todd

trunk must be started after physical ethernet devices, but before vlan.
populate ifmstart lines accordingly.
prodded/tested by brad@
ok reyk@


# 1.106 28-Sep-2005 todd

use eval consistently, fixes description quotes on rtsol and dhcp
fix inspired by and closes pr 4495
ok krw@


Revision tags: OPENBSD_3_8_BASE
# 1.105 22-May-2005 todd

Introduce 'ifmstart' to deal with starting multiple interfaces minus a list
of interfaces.

This reduces the netstart script by 174 chars, 13 words, and 19 lines, but
more importantly, makes it more simple and less cluttered should more special
case/orderings be needed.

ok brad@ and pr 4197 submitter, inspired by and closes pr 4197


# 1.104 04-Apr-2005 djm

unbreak; ok pval@


# 1.103 03-Apr-2005 deraadt

if dhcp is used to get an address on any interface, ignore /etc/mygate
ok krw
(this lets us do something rather cool with the zaurus in particular)


Revision tags: OPENBSD_3_7_BASE
# 1.102 04-Jan-2005 mcbride

Bring up the carp(4) interface before default route.

ok pascoe@ mpf@


# 1.101 30-Dec-2004 millert

Add a copy of stripcom so /etc/netstart can be run standalone again.
OK deraadt@


# 1.100 19-Dec-2004 millert

Allow comments in /etc/{myname,mygate,defaultdomain}; OK deraadt@


# 1.99 04-Dec-2004 itojun

remove "route $hostname 127.0.0.1" line. deraadt ok
*** please update /etc/netstart and test if it works ok for you ***


# 1.98 20-Oct-2004 deraadt

make all route commands use -qn; ok mcbride henning


Revision tags: OPENBSD_3_6_BASE
# 1.97 29-May-2004 deraadt

one last route command lacking -qn


Revision tags: OPENBSD_3_5_BASE
# 1.96 22-Mar-2004 mcbride

Make sure pfsync is brought up before carp.

ok deraadt@


# 1.95 13-Mar-2004 mcbride

Delay pfsync(4) configuration, as the syncif has to be configured in
advance. From Thorsten Lockert.


# 1.94 14-Jan-2004 deraadt

ok, it took quite a bit of prodding but itojun finally explained why the
extra sleep 1 is in here, and we came to the conclusion it is safe to
delete it. whee.


# 1.93 13-Jan-2004 deraadt

repair v6 lo0 documentation


# 1.92 11-Jan-2004 deraadt

add loopback routes late


# 1.91 09-Jan-2004 deraadt

create all routes with -q; markus ok


# 1.90 04-Dec-2003 millert

Need to do "ifconfig create" for bridge interfaces too.


# 1.89 03-Dec-2003 markus

add support for ifconfig clone; from netbsd; ok deraadt, henning


# 1.88 20-Oct-2003 david

delay carp initialization until after physical interfaces are configured
ok mcbride@ henning@ deraadt@ todd@


Revision tags: OPENBSD_3_4_BASE
# 1.87 27-Aug-2003 henning

only try to set hostname to what /etc/myname says if that file actually exists,
otherwise preserve `hostname`
netbooted machines can live perfectly fine without it; they get their hostname
earlier.

ok krw@ cedric@


Revision tags: OPENBSD_3_3_BASE
# 1.86 16-Feb-2003 krw

Fix up some DNS verbiage to make it consistant.

Fix up default route selection by

a) Forcing user to explicitly chose 'dhcp' as a mechanism for
specifying a default route, rather than guessing based on one or more
interfaces being configured by dhcp.

b) If the user specified default route does not work, re-present the
existing default route rather than losing it.

c) Move default route selection to after nameserver activation so the
user can specify a hostname as the default route.

Change /etc/netstart so that /etc/mygate wins if a default route was
already specified (i.e. by dhcp).

ok deraadt@.


Revision tags: OPENBSD_3_2_BASE
# 1.85 16-May-2002 todd

ignore non-existent cases where '$if' evaluates to '*'.
From Andr� Lucas <andre@ae-35.com>, fixes pr # 2658.
'Looks good' from miod@, millert@, and krw@.


Revision tags: OPENBSD_3_1_BASE
# 1.84 23-Feb-2002 deraadt

re-add support for $if expansion; hamajima@nagoya.ydc.co.jp


# 1.83 21-Feb-2002 miod

Change the network components initialization order.
Change from:
o all interfaces
o all bridges
o routes
to:
o physical interfaces
o routes
o gif and gre interfaces
o bridges

Fixeski PR #2400.
Manual page updates coming soon.
Ok angelos@ chris@ deraadt@


Revision tags: OPENBSD_3_0_BASE
# 1.82 31-Jul-2001 hugh

a space before a redirect


# 1.81 06-Jul-2001 angelos

Also, source /etc/rc.conf so we can pull in the
multicast_host/multicast_router settings; this is useful if one
flushes the routing table and re-initializes.

We really need a netconfig tool of sorts.


# 1.80 06-Jul-2001 angelos

Use "route -n show -inet" to determine the default multicast iface.


# 1.79 03-Jul-2001 deraadt

pull in rc.conf early so that pf(1) startup is right; tested by jasoni, comments from millert


# 1.78 30-May-2001 deraadt

Remove ipf. Darren Reed has interpreted his (old, new, whichever)
licence in a way that makes ipf not free according to the rules we
established over 5 years ago, at www.openbsd.org/goals.html (and those
same basic rules govern the other *BSD projects too). Specifically,
Darren says that modified versions are not permitted. But software
which OpenBSD uses and redistributes must be free to all (be they
people or companies), for any purpose they wish to use it, including
modification, use, peeing on, or even integration into baby mulching
machines or atomic bombs to be dropped on Australia. Furthermore, we
know of a number of companies using ipf with modification like us, who
are now in the same situation, and we hope that some of them will work
with us to fill this gap that now exists in OpenBSD (temporarily, we
hope).


Revision tags: OPENBSD_2_9_BASE
# 1.77 13-Mar-2001 deraadt

spelling; maurice@maurice.wan.nl


# 1.76 06-Feb-2001 todd

ignore blank lines in addition to comments
fixes pr#1660 from wilfried@telia.com .. Thanks!


# 1.75 10-Jan-2001 jason

support !command in bridgename.if files, too


# 1.74 27-Nov-2000 millert

Use -n to test if a variable is non-zero. Otherwise, if the variable's
contents start with a '-' test becomes unhappy (since it interprets it
as another option).


# 1.73 08-Nov-2000 todd

This fixes pr 1481, we now handle args > 6 in /etc/hostname.if in the
cases where we did not previously handle them.
Thanks to Scott Atwood <atwood@cs.stanford.edu> for reminding us of this.


Revision tags: OPENBSD_2_8_BASE
# 1.72 02-Sep-2000 todd

subtle bug .. global variables in a while loop need reset 'just incase'
With:
hostname.fxp0 having a last line of:
inet6 alias 3ffe:...
and hostname.gif0 having a first two lines of:
giftunnel 1.2.3.4
dest 1.2.4.3
We end up with the command:
ifconfig gif0 giftunnel alias 1.2.3.4 1.2.4.3
.. which is clearly wrong and fixed by this change


# 1.71 18-Jun-2000 todd

rc.conf now parses ${local_rcconf} internally; closes pr 1259


Revision tags: OPENBSD_2_7_BASE
# 1.70 08-May-2000 todd

fix dhcp 'NONE' ness from install to allow media parsing to work
.. ok deraadt@, millert@


# 1.69 21-Apr-2000 deraadt

rc.conf.local support, inspired by chuck yerkes


# 1.68 04-Apr-2000 millert

Remove the -E flag from ipf as it is implicitly enabled and using
the -E flag here causes the kernel to printf 'IP Filter: already
initialized'.


# 1.67 18-Mar-2000 deraadt

silence all extra route addition printouts


# 1.66 17-Mar-2000 itojun

correct reject route installations for IPv6. improve comments.


# 1.65 12-Mar-2000 itojun

disallow packets to malicious 6to4 prefix, based on
http://playground.iijlab.net/i-d/draft-itojun-ipv6-transition-abuse-00.txt


# 1.64 10-Mar-2000 todd

fix non behavior
with this `!' lines in /etc/hostname.* run even without certain lines
(like a comment) preceeding it.


# 1.63 10-Jan-2000 todd

allow arbitrary commands in /etc/hostname.* files if the line starts with '!'


# 1.62 02-Jan-2000 deraadt

rtsol case can configure the interface up, since it would be nice to finish
DAD before the actual rtsol(8) run happens later. and since it will rtsol,
it is going to be up in any case.


# 1.61 02-Jan-2000 itojun

one more indentation fix.


# 1.60 02-Jan-2000 itojun

indentation fix (todd's part)


# 1.59 02-Jan-2000 todd

fix rtsold case, reset cmd for each iteration!


# 1.58 02-Jan-2000 itojun

allow options after "rtsol".
XXX both "dhcp" and "rtsol" has keyword *down* at the end. is it okay?


# 1.57 02-Jan-2000 itojun

echo "IPv6 autoconf: interfaces" before invoking rtsol.
sleep for net.inet6.ip6.dad_count seconds to ensure that IPv6 DAD is completed.
TODO: rtsold (rc.conf line), manpage


# 1.56 02-Jan-2000 itojun

ipv6 autoconf on hosts (non-routers).

to do this,
1. in sysctl.conf, add these lines:
net.inet6.ip6.forwarding=0
net.inet6.ip6.accept_rtadv=1
2. in hostname.foo, add
rtsol

specifying two or more interfaces with "rtsol" may result in strange
behavior - ipv6 spec does not permit multi-interface node to be autoconfig'ed.


# 1.55 02-Jan-2000 todd

add to hostname.* parsing:
- multiple entries support (read: aliases)
- inet6 support
- support for comments (#)
(look for hostname.if(5) commit for syntax details)


# 1.54 31-Dec-1999 itojun

install IPv6 reject routes only if kernel is capable of IPv6.


# 1.53 09-Dec-1999 itojun

avoid transmitting invalid IPv6 packets out to the wire.


# 1.52 09-Dec-1999 itojun

do not perform IPv6 initialization for loopback interface.
MUST make lo0 up before any IPv6 operations.
it will be considered a pilot error if you don't.
(I prefer to have lo0 initialized automatically)


Revision tags: OPENBSD_2_6_BASE
# 1.51 01-Sep-1999 deraadt

support # characters in bridgename.* files; millert


# 1.50 01-Sep-1999 deraadt

cleanup parsing of hostname.* files, and seperate bridge control into
bridgename.* files; all documented in new hostname.if(5) and
bridgename.if(5) man pages


# 1.49 09-Aug-1999 angelos

Only parse/setup the hostname.foo file if interface foo exists (this
is useful for laptops with different ethernet cards etc.)


Revision tags: OPENBSD_2_5_BASE
# 1.48 29-Mar-1999 niklas

New multicast route setup style


# 1.47 26-Mar-1999 niklas

Add bridge interface handling


# 1.46 01-Mar-1999 millert

Add support in /etc/hostname.xxx for files of the format:
up [options]
Any of the following may or may not be set:
$name $mask $bcaddr $extras


# 1.45 28-Oct-1998 millert

Kill the awful hack used to match and split /etc/hostname.* We now use
a function, isalphanumeric, to determine whether an interface name is
likely to be valid. This means that things like /etc/hostname.le0.bak,
/etc/hostname.le0#, /etc/hostname.le0~, etc. will be ignored as they
should. There is no longer an implicate assumption that /etc/hostname.*
only contains a single '.'.


Revision tags: OPENBSD_2_4_BASE
# 1.44 06-Oct-1998 deraadt

move ipnat to end of netstart, to support dhcp+ipnat


# 1.43 18-Sep-1998 deraadt

apply media directives on dhcp interfaces


# 1.42 10-Sep-1998 marc

better way of handling dhcp client; Jason Ish <jbi130@mail.usask.ca>


# 1.41 08-Sep-1998 marc

dhcp client stuff. "Angelos D. Keromytis" <angelos@dsl.cis.upenn.edu>


# 1.40 24-Aug-1998 downsj

You can't use -interface default when there's no default gateway
set (yet). Use -interface $hostname if mygate doesn't exist so that
this actually works on routers.


# 1.39 04-Jul-1998 deraadt

put 224 route on default, to avoid a hostname lookup


# 1.38 22-May-1998 deraadt

use route -n, what the heck


Revision tags: OPENBSD_2_3_BASE
# 1.37 28-Mar-1998 deraadt

s/^nat/ipnat/


# 1.36 23-Feb-1998 niklas

remove trailing blank line


# 1.35 07-Feb-1998 deraadt

ipforward is in sysctl.conf now


# 1.34 21-Dec-1997 deraadt

ugh


# 1.33 20-Dec-1997 deraadt

ipforwarding option in rc.conf


# 1.32 29-Nov-1997 kstailey

NAT requires IPF


# 1.31 04-Nov-1997 deraadt

kill spaces at ends of lines; m4


Revision tags: OPENBSD_2_2_BASE
# 1.30 14-Oct-1997 deraadt

set hostname/domainname before running rc.conf; m4@umn.edu


# 1.29 04-Sep-1997 deraadt

fork netstart; new child is rc.conf


# 1.28 25-Aug-1997 millert

Explicately pass -host flag to route(8) to avoid confusion with networks.


# 1.27 19-Aug-1997 niklas

Add hook for rpc.lockd, make nfsd flags settable in netstart


# 1.26 31-Jul-1997 downsj

Make quotas optional; wedged into netstart for the time being.
/etc/rc.conf, anyone?


# 1.25 30-Jul-1997 deraadt

do not run routed by default


# 1.24 28-Jul-1997 kstailey

Move configuration of loopback interface to before all other interfaces.
Allows the use of local caching-only nameserver with no "nameserver"
entry in /etc/resolv.conf to configure a route between the hostname
and loopback.


# 1.23 25-Jul-1997 provos

earlier start of keymanagement


# 1.22 24-Jul-1997 deraadt

make amd use /tmp_mnt by default


# 1.21 22-Jul-1997 provos

start the photuris daemon per default. hilfe.


# 1.20 17-Jun-1997 niklas

Put in hooks to start ypserv with flags


# 1.19 17-Jun-1997 niklas

Put in hooks to start rpc.yppasswdd with flags


Revision tags: OPENBSD_2_1_BASE
# 1.18 15-Apr-1997 deraadt

kill route flush until .. hmm kernel routing socket bug or something


# 1.17 09-Apr-1997 kstailey

add NAT startup


# 1.16 07-Apr-1997 rees

flush all old routes before adding new interfaces or routes.
ref: netbsd pr3228/misc, Matthias Scheler


# 1.15 03-Mar-1997 downsj

fix typo


# 1.14 11-Feb-1997 deraadt

add default route before fiddling with loopback route to avoid DNS problems; m4@umn.edu, #97


# 1.13 03-Feb-1997 deraadt

do ifaliases after /usr/bin exists in nfs diskless env; pr#77, matthieu@laas.fr


# 1.12 02-Nov-1996 deraadt

timed off by default


Revision tags: OPENBSD_2_0_BASE
# 1.11 23-Sep-1996 deraadt

rfc1323 variable


# 1.10 04-Sep-1996 deraadt

control portmap, inetd, and lpd from netstart; idea from tqbf@enteract.com


# 1.9 27-Aug-1996 deraadt

224.0.0.0 not 0.0.0.224; from peter@demon.net


# 1.8 18-Jun-1996 deraadt

move std stuff from rc.local to rc


# 1.7 16-Jun-1996 deraadt

install sample commented /etc/ifaliases file; which can now contain #
comments and blank lines. new format is "interface address netmask"
(yes, i changed the order of the entries). inspired by netbsd pr#2474;
gillhaa@ghost.whirlpool.com


# 1.6 02-Jun-1996 tholo

Install a multicast route by default


# 1.5 26-May-1996 deraadt

sync & label


# 1.4 09-Jan-1996 dm

added IP filter to netstat/rc and put examples in /usr/share/ipf


# 1.3 30-Dec-1995 deraadt

from netbsd: start mrouted like routed


# 1.2 18-Dec-1995 deraadt

/etc/ifaliases support by randy@zyzzyva.com


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.213 16-Jul-2021 florian

switch to dhcpleased/resolvd in base
OK deraadt


# 1.212 20-Jun-2021 florian

Don't try to install a default route with route(8) later on if we are
using inet autoconf, like we do with "dhcp" and "inet6 autoconf".
OK kn


Revision tags: OPENBSD_6_9_BASE
# 1.211 23-Dec-2020 krw

Allow the provision of dhclient(8) options on 'dhcp' lines in hostname.if(5)
files.

Usual man page help & ok jmc@


# 1.210 21-Dec-2020 krw

Avoid issuing pointless 'ifconfig <if> up' when processing 'dhcp' in
hostname.if files. dhclient(8) does that itself. Part of the
"further script optimizations" promised in r1.200 of netstart.

Tested & ok gnezdo@


# 1.209 29-Nov-2020 tb

Fix previous: use correct version of netstart and installer bits.


# 1.208 29-Nov-2020 deraadt

Add support for !command to mygate, so that netstart has a late opportunity
to perform network configuration (for example, "!route source -ifp em0")
Split mygate and myname manual pages (how did anyone ever believe these
are related), and perform hostname configuration much earlier in rc.
discussed with benno, claudio, jmc, etc etc, last version of !command
parser by tb


# 1.207 08-Nov-2020 jmc

no more mobileip;
ok claudio deraadt


Revision tags: OPENBSD_6_8_BASE
# 1.206 21-Jun-2020 dlg

start wg with the other interfaces that rely on routing being up.

from Matt Dunwoodie and Jason A. Donenfeld

ok deraadt@


# 1.205 22-May-2020 kn

Revert the following commit as it breaks hostname.if(5) lines with a
backslash at the end for line continuation

Breaking long lines into multiple ones must still be possible and does
require to treat the backslash as an escape character.

Breakage reported by Mark Patruck <mark at wrapped dot cx >, thanks!

---
distrib/miniroot/install.sub revision 1.1151
etc/netstart revision 1.203
date: 2020/05/21 11:54:41; author: kn; state: Exp; lines: +2 -2;
Do not treat backslashe as an escape character in hostname.if(5) lines

ifstart() should always pass such lines unaltered, especially if they
contain "nwid" or "description" lines with arbitrary strings.

<bsdlisten at gmail dot com> reported SSIDs such as "Mike's" during
installation end as broken; this was because the installer escaped
the single quote using backslashes which ended up being treated as
escape characters much later during hostname.if parsing in netstart(8).

Ok deraadt


# 1.204 21-May-2020 kn

Fix stripcom() description wrt. comments not on their own line

Neither netstart's nor install.sub's (subtly different) implementations
remove trailing comments on lines not starting as a comment, e.g.,
lines like "up #not down" go through unaltered and without "#not down"
being removed.

Only lines *beginning* with the comment sign ("#") are stripped.

No functional change, just updating function descriptions.


# 1.203 21-May-2020 kn

Do not treat backslashe as an escape character in hostname.if(5) lines

ifstart() should always pass such lines unaltered, especially if they
contain "nwid" or "description" lines with arbitrary strings.

<bsdlisten at gmail dot com> reported SSIDs such as "Mike's" during
installation end as broken; this was because the installer escaped
the single quote using backslashes which ended up being treated as
escape characters much later during hostname.if parsing in netstart(8).

Ok deraadt


Revision tags: OPENBSD_6_7_BASE
# 1.202 15-Jan-2020 kn

Do not redirect already quiet stdout for IPv6 reject routes

"route -q" already silences all standard output; if it still prints
something, that's a bug to fix in route.

OK bluhm


# 1.201 25-Oct-2019 dlg

handle aggr(4) in the same way as trunk(4)

from brad@
ok bluhm@ claudio@ deraadt@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.200 29-Aug-2018 krw

Historically /etc/netstart (and the equivalent code in the install
script) did 'ifconfig <if> down' before starting dhclient(8). This was
a way of ensuring old running copies of dhclient were killed before a
new one started. Current dhclient does not need this assist, so change
"ifconfig <if> down" to "ifconfig <if> up" pending further script
optimizations.

Similar to a 2014 attempt by halex@. Prompted by a misc@ report
from Kristjan Komlosi reporting hanging diskless setups.

ok halex@ kn@


# 1.199 08-Jul-2018 tb

netstart is used during system start, but also interactively.
Show proper error message if a regular user executes netstart.
Only do the privilege check if the id binary is available,
which might not be the case during diskless system startup.

ok deraadt, jasper, jca, krw, rpe (who wrote the same diff), sthen


# 1.198 28-Apr-2018 rpe

Add a proper usage() function.

Suggested by and OK jmc.
OK tb


Revision tags: OPENBSD_6_3_BASE
# 1.197 04-Mar-2018 jmc

when -n is used, no need to spit out "Missing parameters." before
displaying usage();

ok tb


# 1.196 03-Mar-2018 landry

Lowercase 'usage' and group -n with interface in it.
From jmc@, ok tb@


# 1.195 21-Feb-2018 rpe

Tweak comments.

OK tb


# 1.194 19-Feb-2018 rpe

Write warning/error messages to stderr and end them with a fullstop.

OK tb


# 1.193 19-Feb-2018 rpe

- use specific patterns when looping over /etc/hostname.if files
to skip backup or temp files.
- test if the patterns matched actual files
- warn if ifcreate() fails on an interface and continue with the
subsequent interfaces in the list instead of return'ing

OK dlg sthen tb


# 1.192 17-Feb-2018 rpe

- Add descriptions for the new functions ifcreate() and vifscreate()
- In ifcreate() use the exit code of the {} block directly
- In vifscreate(), use the ifconfig -C output directly in the for _vif loop
- Remove superfluous and somewhat confusing comment

OK dlg kn sthen


# 1.191 14-Feb-2018 dlg

create virtual interfaces before starting all interface config.

this resolves an ordering problem when adding pseudo interfaces to bridges

tweaks from kn@
ok mpi@ sthen@


# 1.190 10-Feb-2018 claudio

Remove some special IPv4 in IPv6 mapped prefixes that are already rejected
by the ::0.0.0.0/96 reject route added to deny all IPv4 mapped addresses.
Makes the inet6 routing table almost fit in one screen.
OK benno@


# 1.189 10-Feb-2018 florian

Load RFC 7217 key material and generate if it does not already exist.

Add soii.key to changelist (pointed out by semarie) and mtree/special
(suggest by Craig Skinner).

OK naddy, sthen, rpe, tb


# 1.188 06-Feb-2018 tb

If -n is given, the netstart script should not (try to) set the default
route(s). Simply print the command(s) to be issued instead.

tweak & ok rpe


# 1.187 12-Nov-2017 tb

Remove HN_DIR variable and expand it in the only place it was used. It
currently serves no purpose.

ok rpe, agreement from deraadt and halex


Revision tags: OPENBSD_6_2_BASE
# 1.186 25-Jul-2017 rpe

Finally remove backwards compat code to support the 'rtsol' keyword
in hostname.if(5)

OK mpi@ deraadt@ florian@
OK jmc@ from doc perspective


# 1.185 21-Jul-2017 rpe

Align ifstart() in netstart and install.sub.

- in netstart, rename _file to _hn referencing hostname.if files
- in install.sub switch ifstart() to be used with _if instead of
_hn as parameter

ok krw@ tb@


# 1.184 28-May-2017 awolk

etc/netstart: use colon separator instead of dot with chown

OK jung@, deraadt@, jmc@


# 1.183 07-May-2017 rpe

Change test from [] to [[]] and simplify pattern.

OK tb@, krw@ (for [[]])
Feedback and OK halex@


# 1.182 07-May-2017 rpe

Replace hardcoded script name with ${0##*/}

OK tb@ halex@


# 1.181 01-May-2017 rpe

Revert r1.170 and remove the id==0 check.
The id binary is not available in nfs diskless setups at this point.

reported by Andreas Kusalananda, thanks.
discussed with deraadt@


# 1.180 01-May-2017 rpe

Remove last remnants of rtsol. IPv6 autoconfiguration of interfaces is now
done in ifstart(). Remove ipv6autoconf() and replace rtsolif with a boolean
variable V6_AUTOCONF. Replace dhcpif with a boolean variable V4_DHCPCONF.
Both are later used in defaultroute() to decide whether or not to configre
defaultroutes from /etc/mygate.

OK krw@


# 1.179 30-Apr-2017 mpi

Do not try to delete a default route before adding it.

Now that route are automatically G/C with the address they are attached
to there's no reason to duplicate the kernel's job.

Fix a regression introduced with multipath default routes.

ok deraadt@


# 1.178 25-Apr-2017 rpe

Unbreak netstart for multiple inteface configurations like trunk
or carp. Ensure that the noglob option is disabled at the end of
parse_hn_line() and ifstart().

Reported by Christer Solskogen and Stefan Wollny, thanks!


# 1.177 24-Apr-2017 rpe

Introduce a new function parse_hn_line() that replaces the existing
hostname.if(5) parsing code in ifstart().
Add a -n option to netstart to only print the interface configuration
commands instead of executing them.
Add a HN_DIR variable, that points to the directory of the hostname.if
files (default /etc) that allows for future regression tests.

- add new parse_hn_line() function
- change ifstart()
- rename $if to $_if
- don't ifconfig or ifconfig create if -n option is used
- replace hostname.if(5) parsing code with new parse_hn_line()
- just print configuration commands if -n option is used
- autoconf now happens in ifstart(), remove ifv6autoconf()
- introduce HN_DIR variable for the hostname.if file location
- add handling of the -n option to only print config commands
- ensure -n is only used if interfaces are specified as parameters

Discussed with and positive feedback from many
'commit' deraadt@
OK sthen@


# 1.176 08-Apr-2017 rpe

- localize the if, file and stat variables which also ensures that
variables are not named like commands.
- change test from [] to [[]]

OK tb@ halex@


# 1.175 07-Apr-2017 rpe

Minimize differences in ifstart() function between netstart and
install.sub which makes it easier to spot changes in the future.

- comments and formatting
- quotes on assignments are not needed (netstart)
- remove stray space in test (netstart)
- use $file variable with while-loop (netstart)
- although valid, instead of i use $i in arithmetic test (install.sub)

OK krw@, tb@
Looks good deraadt@


# 1.174 07-Apr-2017 rpe

Align comments of ifstart() function in netstart and install.sub.


# 1.173 07-Apr-2017 rpe

Align comments of stripcom() function in netstart and install.sub.


Revision tags: OPENBSD_6_1_BASE
# 1.172 06-Dec-2016 mpi

Do not lose the default route when netstart(8) is run a second time on
the interface pointed to by the default route.

Since the kernel no longer keep routes with dangling address pointer,
netstart(8) has to re-add the default route when the corresponding ifa
has been deleted and re-created.

deraadt@ points out that even if the previous semantic was not necessarily
better, a script like netstart(8) cannot totally fix the default route
problem.

Regression reported by and fix tested by Hrvoje Popovski.

ksh foo checked by halex@


# 1.171 27-Sep-2016 rzalamena

Delay switch(4) interface start up so it can attach virtual interfaces
like vether(4).

nits from and ok benno@, phessler@


# 1.170 09-Sep-2016 jasper

print a clear error message when not ran as root instead of just falling
through and try whatever it can do with the invoking user's perms

feedback/ok aja@ rpe@


Revision tags: OPENBSD_6_0_BASE
# 1.169 19-Jul-2016 mpi

Do not consider tap(4) a special interface and start if before other
pseudo-interfaces.

This unbreak vlan(4) on top of tap(4) since the refactoring to turn it
MP-safe.

ok claudio@, deraadt@


# 1.168 27-Mar-2016 sthen

Don't delete the 224/4 route in netstart, unless it's being done to ensure that
a -reject route can be added. Restores the ability to set an interface route
before daemons are started, lost during the previous simplification.
ok millert mpi


Revision tags: OPENBSD_5_9_BASE
# 1.167 29-Dec-2015 rpe

Remove backslash, not necessary after '&&'

OK halex@


# 1.166 29-Dec-2015 rpe

Replace last remaining `` with $()

OK halex@


# 1.165 18-Dec-2015 ajacoutot

Drop the now useless multicast setup comment.

prodded by tim@, ok mpi@


# 1.164 17-Dec-2015 ajacoutot

Simplify multicast option handling (10 less lines) by matching /etc/rc behavior
towards other YES|NO options and drop the error warning.


with and ok tim@, ok rpe@ on an earlier diff


# 1.163 05-Dec-2015 mpi

It does not make sense to insert a specific route for 224/4 when the
default one is good enough.

So merge rc.conf(8)'s 'multicast_router' and 'multicast_host' into a
single 'multicast'. If set to YES the reject route for 224/4 is not
inserted by netstart(8).

Manual bits from jmc@

ok henning@, ajacoutot@


# 1.162 12-Nov-2015 rpe

Changes to ifautostart():
- Rename function to ifv6autoconf() to make IPv6 relation clearer
- Localize and rename variables

OK krw@


# 1.161 12-Nov-2015 rpe

Changes to ifmstart():
- Change comments to make it clearer that ifmstart() takes two lists
of interface driver names (of which the second is optional) and not
the actual interface instances.
- Use localized variables and use slightly more verbose names.
- Use continue 2 to skip to the next hostname.if file.
- Use shell pattern @() instead of testing _sif individually.

OK krw@


# 1.160 12-Nov-2015 rpe

Changes to stripcom():
- Align comments with /etc/rc version
- Use localized variables
- Use safer "print -r --" instead of plain echo

Changes to ifstart():
- Tweak comment
- Add usage

OK krw@


# 1.159 01-Nov-2015 rpe

Start the rework of the /etc/netstart shell script.

General changes:
- apply a similar 'style' as used in the installer scripts
- improve comments to be more to the point, remove where code is obvious
- document usage of functions if they have arguments
- rename variables where it improves readability
- replace really old-school shell code with more contemporary idioms

Other changes:
- No need to care about "autoboot" because netstart doesn't inherit the
positional parameters from /etc/rc anymore. /etc/rc executes netstart
instead of sourcing it since r1.439.
- Use simpler for-loop to process list of interfaces with ifstart.

OK halex@


# 1.158 26-Oct-2015 rpe

The hostname variable is not used since r1.99. Remove it and use
stripcom() output directly with the hostname command.

OK deraadt@ krw@


# 1.157 23-Oct-2015 claudio

netstart bits for tap(4)


# 1.156 27-Sep-2015 sthen

Don't print output when setting autoconf on interfaces. Suggested by deraadt,
ok florian@ rpe@


# 1.155 13-Sep-2015 sthen

only print the "IPv6 autoconf" line if there are interfaces to configure
feedback/ok rpe


# 1.154 11-Sep-2015 sthen

Set "inet6 autoconf" individually on interfaces that have rtsol set in
hostname.if, previously netstart tried to configure them all at once
("ifconfig if0 if1 if2 inet6 autoconf"). From Delan Azabani, ok phessler@


Revision tags: OPENBSD_5_8_BASE
# 1.153 20-Jul-2015 rpe

Disable Strict Bourne shell mode for /etc/rc and /etc/netstart to be
able to use ksh syntax within these scripts. This way init doesn't
need to be changed, which starts /etc/rc using /bin/sh and people
can still use "sh /etc/netstart ifname".

Idea from and OK halex@
OK deraadt@ krw@ guenther@


# 1.152 19-Jul-2015 florian

Bring up pflow last as it might send with a source address that is on
any of the other interfaces.
OK deraadt, phessler, benno


# 1.151 19-Jul-2015 rpe

Always source rc.subr to be able to use the rc.conf parsing routine
to get the network related vars from rc.conf. This is even necessary
if netstart is run from within /etc/rc. Remove test of $INRC which
unintentionally evaluated always to true.

problem with previous change found by nigel@
OK sthen@ aja@ halex@


# 1.150 19-Jul-2015 ajacoutot

Revert 1.148 for now until I can talk to rpe@
It introduced a regression reported by nigel@


# 1.149 19-Jul-2015 rpe

Replace test command with [].

OK halex@ krw@


# 1.148 19-Jul-2015 rpe

Ensure, that we source rc.subr and parse rc.conf ONLY if we are not
inside /etc/rc.

With help from and OK halex@, ajacoutot@


# 1.147 18-Jul-2015 rpe

- remove trailing blanks introduced in previous commit
- no space in redirections like </foo or >$bar
- few other minor whitespaces

OK krw@


# 1.146 18-Jul-2015 rpe

Improve comments
- Add comments for functions
- Start comments with capital letters
- End comments with a full stop
- Allow comments to extend up to column 80

OK krw@


# 1.145 06-Jun-2015 florian

Allow rtsol keyword in hostname.if(5) with net.inet6.ip6.forwarding=1.
"inet6 autoconf" was working before and rtsol should behave the same.
OK phessler


Revision tags: OPENBSD_5_7_BASE
# 1.144 03-Dec-2014 florian

The kernel handles rtsol(8) functionality since some time now.
Treat rtsol in hostname.if as a keyword like dhcp and call ifconfig
inet6 autoconf.
"reads good" todd@
OK krw@ (who is *not* an IPv6 person), but I recruited him in his
capacity as an installer person.


# 1.143 28-Sep-2014 claudio

Revert 1.142. Without the down netstart will just print the ifconfig
output because it may end up just calling 'ifconfig $if'. This needs
to be done better and properly tested.


# 1.142 26-Sep-2014 halex

remove explicit 'down' of an interface before starting a dhcp request, thereby
avoiding annoying delays for some switch configurations

ok claudio@ deraadt@

i would add ok phessler@, but it was not valid without an ok krw@


Revision tags: OPENBSD_5_6_BASE
# 1.141 12-Jul-2014 stsp

Fix netstart after autoconf6 change so 'rtsol' lines in hostname.if work again.
found by pelikan@; ok pelikan@ henning@


# 1.140 12-Jul-2014 robert

Make rc.conf a parsed configuration file and stop sourcing it as a shell
script.
From now on rc.conf has a fixed syntax (key=val) and it is not allowed
to add anything to it besides the supported syntax, it all going to be
ignored.

discussed with and help from deraadt@ and halex@


Revision tags: OPENBSD_5_5_BASE
# 1.139 22-Aug-2013 mpi

Like for dhclient, do no create a route to alias addresses via 127.0.0.1.
Our stack is able to tell if the address is local or not.

ok todd@, krw@


Revision tags: OPENBSD_5_4_BASE
# 1.138 20-Mar-2013 todd

fix lies in netstart; replacement wording from halex@
pointed out by Ryan Kavannagh rak at debian dot org


Revision tags: OPENBSD_5_3_BASE
# 1.137 05-Dec-2012 rpe

remove "Invalid interface name" message
requested by krw@

ok halex@


# 1.136 02-Dec-2012 rpe

use the more compact version of the check for ifconfig'able interfaces
from install.sub

with feedback from and ok halex


# 1.135 02-Dec-2012 rpe

- remove isalphanumeric() and replace it with a shell pattern, that
tries a bit harder to identify invalid interface names and in
this case emit an error message.
- use [[ $1 == autoboot ]] to avoid a shell error message due to
possible spaces in first argument
- no change in functionality

discussed with krw and halex
ok ("I like this") krw


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.134 07-Oct-2011 deraadt

The new ypbind changes requires that the domainname be set before
rc.conf is run. There's no real downside.
ok aja


Revision tags: OPENBSD_5_0_BASE
# 1.133 07-Jul-2011 guenther

Eliminate some $? tests by rolling the command into the condition

ok halex@


# 1.132 26-May-2011 mpf

Add svlan(4) startup bits.
From markus@. OK naddy, claudio, reyk.


Revision tags: OPENBSD_4_9_BASE
# 1.131 09-Feb-2011 sobrado

fix an unbalanced parenthesis in a comment; while here, split the comment
in a better place to make it more readable.

ok jmc@ and miod@


Revision tags: OPENBSD_4_8_BASE
# 1.130 16-Jun-2010 todd

permit e.g. -inet6 syntax by slurping all lines not just some
noticed by rhsv6 at hushmail dot com, ok sthen@


Revision tags: OPENBSD_4_7_BASE
# 1.129 12-Jan-2010 henning

when setting up lo0 use 127.0.0.1/8 instead of 127.0.0.1 for clarity and
correctness. it's not 1992 any more, kids. ok mcbride dlg krw


# 1.128 10-Dec-2009 todd

o stop reordering ifconfig arguments (e.g. after 'up ..')
o only stop processing if inet or inet6 lines are malformed
o everything not a specially handled bit is passed to ifconfig unmangled
noticed by several after the move from bridgename.bridge0 -> hostname.bridge0
prodded by deraadt@, tested by and feedback from several
man page bits 'look fine' jmc@


# 1.127 22-Nov-2009 deraadt

Stop supporting bridgename.bridge* files, and move to hostname.bridge*
files. To cope with this change, read about the mv command.
ok claudio todd


# 1.126 17-Sep-2009 simon

change variable i to $i in an expression of ifstart() for consistency
with the rest of the file. no functional change.

feedback from sthen@, ok krw@


# 1.125 10-Jul-2009 jdixon

Delay creation of tun(4) interfaces until the underlying interface and
routes are available. This fixes usage for some OpenVPN users that start
it from hostname.tun*.

Tested by Johan Huldtgren. ok sthen@, johan@.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.124 25-Nov-2008 markus

delay /etc/netstart until IPv6-DAD (dup-address-detection) is completed.
ok fries, hshoexer, claudio


# 1.123 14-Aug-2008 sthen

Tools from /usr may not be used in netstart since it may be NFS-mounted
and not available at that time. Rewrite the hostname.if permission check
to use only /bin/ls and the shell. Requested by deraadt.

ok todd, "Twisted." deraadt


Revision tags: OPENBSD_4_4_BASE
# 1.122 23-Jul-2008 sthen

Prevent warning about insecure hostnames where no /etc/hostname.*
exists. From wcmaier@.

Check target of symbolic links to avoid noise at boot and in
seucrity output where you have several interfaces symlinked to one
config file.

"If you think this is the right thing to do" deraadt@


# 1.121 09-Jun-2008 todd

warn once not 3 times in case of a non existent file, discussed with deraadt
originally pointed out by Johan Torin


# 1.120 09-Jun-2008 deraadt

Ensure that hostname.* files are also re-chowned to root.wheel at each
boot as discussed with claudio while eating tasty donairs. ok todd


# 1.119 17-Apr-2008 deraadt

before using them, force hostname.* files to be unreadable by world
first version from todd, ok millert


Revision tags: OPENBSD_4_3_BASE
# 1.118 17-Jan-2008 brad

Execute rtsol after turning up trunk(4) and vlan(4) interfaces so they're
taken into consideration for rtsol.

ok reyk@ dlg@


# 1.117 09-Jan-2008 mpf

Do not bring up pfsync(4) before the working ruleset
has been loaded. Otherwise, states that are received during the
initial bulk update mismatch the correct pf-checksum and
do not attach to the rules.
Problem identified by david@. Fix done in collaboration.
OK henning@


Revision tags: OPENBSD_4_2_BASE
# 1.116 02-Aug-2007 david

move the delay for IPv6 DAD to after all interfaces have started
fixes problems with daemons being unable to bind to all addreses at boot
ok itojun@ hshoexer@


Revision tags: OPENBSD_4_1_BASE
# 1.115 15-Nov-2006 itojun

reject multicast packet without scope identifier specified.


Revision tags: OPENBSD_4_0_BASE
# 1.114 29-Jun-2006 todd

do not add an extra space; nwid and description come out wrong
fix as proposed by maja@, thanks!


Revision tags: OPENBSD_3_9_BASE
# 1.113 28-Dec-2005 david

nuke extra whitespace


# 1.112 06-Dec-2005 reyk

multicast_host=YES only works if a valid default gateway is available.
validate this condition and reject multicast traffic on failure.

ok todd@ naddy@


# 1.111 02-Nov-2005 todd

fix inspired by pr#4590
ok krw@


# 1.110 25-Oct-2005 todd

better logic from krw@:
- do not process mygate for v4 if dhcp
- do not process mygate for v6 if rtsol
this also makes the mygate processing logic more readable
ok krw@


# 1.109 14-Oct-2005 todd

add v6 support for /etc/mygate
ok deraadt@ mickey@ krw@
same functionality tested/ok'ed by by mickey, brad, matthieu, and me
with this one may now put a v6 IP in /etc/mygate on a separate line from
the v4 default gateway and netstart will do the right thing


# 1.108 12-Oct-2005 todd

shrink stripcom(), sync with install.sub
ok krw@


# 1.107 04-Oct-2005 todd

trunk must be started after physical ethernet devices, but before vlan.
populate ifmstart lines accordingly.
prodded/tested by brad@
ok reyk@


# 1.106 28-Sep-2005 todd

use eval consistently, fixes description quotes on rtsol and dhcp
fix inspired by and closes pr 4495
ok krw@


Revision tags: OPENBSD_3_8_BASE
# 1.105 22-May-2005 todd

Introduce 'ifmstart' to deal with starting multiple interfaces minus a list
of interfaces.

This reduces the netstart script by 174 chars, 13 words, and 19 lines, but
more importantly, makes it more simple and less cluttered should more special
case/orderings be needed.

ok brad@ and pr 4197 submitter, inspired by and closes pr 4197


# 1.104 04-Apr-2005 djm

unbreak; ok pval@


# 1.103 03-Apr-2005 deraadt

if dhcp is used to get an address on any interface, ignore /etc/mygate
ok krw
(this lets us do something rather cool with the zaurus in particular)


Revision tags: OPENBSD_3_7_BASE
# 1.102 04-Jan-2005 mcbride

Bring up the carp(4) interface before default route.

ok pascoe@ mpf@


# 1.101 30-Dec-2004 millert

Add a copy of stripcom so /etc/netstart can be run standalone again.
OK deraadt@


# 1.100 19-Dec-2004 millert

Allow comments in /etc/{myname,mygate,defaultdomain}; OK deraadt@


# 1.99 04-Dec-2004 itojun

remove "route $hostname 127.0.0.1" line. deraadt ok
*** please update /etc/netstart and test if it works ok for you ***


# 1.98 20-Oct-2004 deraadt

make all route commands use -qn; ok mcbride henning


Revision tags: OPENBSD_3_6_BASE
# 1.97 29-May-2004 deraadt

one last route command lacking -qn


Revision tags: OPENBSD_3_5_BASE
# 1.96 22-Mar-2004 mcbride

Make sure pfsync is brought up before carp.

ok deraadt@


# 1.95 13-Mar-2004 mcbride

Delay pfsync(4) configuration, as the syncif has to be configured in
advance. From Thorsten Lockert.


# 1.94 14-Jan-2004 deraadt

ok, it took quite a bit of prodding but itojun finally explained why the
extra sleep 1 is in here, and we came to the conclusion it is safe to
delete it. whee.


# 1.93 13-Jan-2004 deraadt

repair v6 lo0 documentation


# 1.92 11-Jan-2004 deraadt

add loopback routes late


# 1.91 09-Jan-2004 deraadt

create all routes with -q; markus ok


# 1.90 04-Dec-2003 millert

Need to do "ifconfig create" for bridge interfaces too.


# 1.89 03-Dec-2003 markus

add support for ifconfig clone; from netbsd; ok deraadt, henning


# 1.88 20-Oct-2003 david

delay carp initialization until after physical interfaces are configured
ok mcbride@ henning@ deraadt@ todd@


Revision tags: OPENBSD_3_4_BASE
# 1.87 27-Aug-2003 henning

only try to set hostname to what /etc/myname says if that file actually exists,
otherwise preserve `hostname`
netbooted machines can live perfectly fine without it; they get their hostname
earlier.

ok krw@ cedric@


Revision tags: OPENBSD_3_3_BASE
# 1.86 16-Feb-2003 krw

Fix up some DNS verbiage to make it consistant.

Fix up default route selection by

a) Forcing user to explicitly chose 'dhcp' as a mechanism for
specifying a default route, rather than guessing based on one or more
interfaces being configured by dhcp.

b) If the user specified default route does not work, re-present the
existing default route rather than losing it.

c) Move default route selection to after nameserver activation so the
user can specify a hostname as the default route.

Change /etc/netstart so that /etc/mygate wins if a default route was
already specified (i.e. by dhcp).

ok deraadt@.


Revision tags: OPENBSD_3_2_BASE
# 1.85 16-May-2002 todd

ignore non-existent cases where '$if' evaluates to '*'.
From Andr� Lucas <andre@ae-35.com>, fixes pr # 2658.
'Looks good' from miod@, millert@, and krw@.


Revision tags: OPENBSD_3_1_BASE
# 1.84 23-Feb-2002 deraadt

re-add support for $if expansion; hamajima@nagoya.ydc.co.jp


# 1.83 21-Feb-2002 miod

Change the network components initialization order.
Change from:
o all interfaces
o all bridges
o routes
to:
o physical interfaces
o routes
o gif and gre interfaces
o bridges

Fixeski PR #2400.
Manual page updates coming soon.
Ok angelos@ chris@ deraadt@


Revision tags: OPENBSD_3_0_BASE
# 1.82 31-Jul-2001 hugh

a space before a redirect


# 1.81 06-Jul-2001 angelos

Also, source /etc/rc.conf so we can pull in the
multicast_host/multicast_router settings; this is useful if one
flushes the routing table and re-initializes.

We really need a netconfig tool of sorts.


# 1.80 06-Jul-2001 angelos

Use "route -n show -inet" to determine the default multicast iface.


# 1.79 03-Jul-2001 deraadt

pull in rc.conf early so that pf(1) startup is right; tested by jasoni, comments from millert


# 1.78 30-May-2001 deraadt

Remove ipf. Darren Reed has interpreted his (old, new, whichever)
licence in a way that makes ipf not free according to the rules we
established over 5 years ago, at www.openbsd.org/goals.html (and those
same basic rules govern the other *BSD projects too). Specifically,
Darren says that modified versions are not permitted. But software
which OpenBSD uses and redistributes must be free to all (be they
people or companies), for any purpose they wish to use it, including
modification, use, peeing on, or even integration into baby mulching
machines or atomic bombs to be dropped on Australia. Furthermore, we
know of a number of companies using ipf with modification like us, who
are now in the same situation, and we hope that some of them will work
with us to fill this gap that now exists in OpenBSD (temporarily, we
hope).


Revision tags: OPENBSD_2_9_BASE
# 1.77 13-Mar-2001 deraadt

spelling; maurice@maurice.wan.nl


# 1.76 06-Feb-2001 todd

ignore blank lines in addition to comments
fixes pr#1660 from wilfried@telia.com .. Thanks!


# 1.75 10-Jan-2001 jason

support !command in bridgename.if files, too


# 1.74 27-Nov-2000 millert

Use -n to test if a variable is non-zero. Otherwise, if the variable's
contents start with a '-' test becomes unhappy (since it interprets it
as another option).


# 1.73 08-Nov-2000 todd

This fixes pr 1481, we now handle args > 6 in /etc/hostname.if in the
cases where we did not previously handle them.
Thanks to Scott Atwood <atwood@cs.stanford.edu> for reminding us of this.


Revision tags: OPENBSD_2_8_BASE
# 1.72 02-Sep-2000 todd

subtle bug .. global variables in a while loop need reset 'just incase'
With:
hostname.fxp0 having a last line of:
inet6 alias 3ffe:...
and hostname.gif0 having a first two lines of:
giftunnel 1.2.3.4
dest 1.2.4.3
We end up with the command:
ifconfig gif0 giftunnel alias 1.2.3.4 1.2.4.3
.. which is clearly wrong and fixed by this change


# 1.71 18-Jun-2000 todd

rc.conf now parses ${local_rcconf} internally; closes pr 1259


Revision tags: OPENBSD_2_7_BASE
# 1.70 08-May-2000 todd

fix dhcp 'NONE' ness from install to allow media parsing to work
.. ok deraadt@, millert@


# 1.69 21-Apr-2000 deraadt

rc.conf.local support, inspired by chuck yerkes


# 1.68 04-Apr-2000 millert

Remove the -E flag from ipf as it is implicitly enabled and using
the -E flag here causes the kernel to printf 'IP Filter: already
initialized'.


# 1.67 18-Mar-2000 deraadt

silence all extra route addition printouts


# 1.66 17-Mar-2000 itojun

correct reject route installations for IPv6. improve comments.


# 1.65 12-Mar-2000 itojun

disallow packets to malicious 6to4 prefix, based on
http://playground.iijlab.net/i-d/draft-itojun-ipv6-transition-abuse-00.txt


# 1.64 10-Mar-2000 todd

fix non behavior
with this `!' lines in /etc/hostname.* run even without certain lines
(like a comment) preceeding it.


# 1.63 10-Jan-2000 todd

allow arbitrary commands in /etc/hostname.* files if the line starts with '!'


# 1.62 02-Jan-2000 deraadt

rtsol case can configure the interface up, since it would be nice to finish
DAD before the actual rtsol(8) run happens later. and since it will rtsol,
it is going to be up in any case.


# 1.61 02-Jan-2000 itojun

one more indentation fix.


# 1.60 02-Jan-2000 itojun

indentation fix (todd's part)


# 1.59 02-Jan-2000 todd

fix rtsold case, reset cmd for each iteration!


# 1.58 02-Jan-2000 itojun

allow options after "rtsol".
XXX both "dhcp" and "rtsol" has keyword *down* at the end. is it okay?


# 1.57 02-Jan-2000 itojun

echo "IPv6 autoconf: interfaces" before invoking rtsol.
sleep for net.inet6.ip6.dad_count seconds to ensure that IPv6 DAD is completed.
TODO: rtsold (rc.conf line), manpage


# 1.56 02-Jan-2000 itojun

ipv6 autoconf on hosts (non-routers).

to do this,
1. in sysctl.conf, add these lines:
net.inet6.ip6.forwarding=0
net.inet6.ip6.accept_rtadv=1
2. in hostname.foo, add
rtsol

specifying two or more interfaces with "rtsol" may result in strange
behavior - ipv6 spec does not permit multi-interface node to be autoconfig'ed.


# 1.55 02-Jan-2000 todd

add to hostname.* parsing:
- multiple entries support (read: aliases)
- inet6 support
- support for comments (#)
(look for hostname.if(5) commit for syntax details)


# 1.54 31-Dec-1999 itojun

install IPv6 reject routes only if kernel is capable of IPv6.


# 1.53 09-Dec-1999 itojun

avoid transmitting invalid IPv6 packets out to the wire.


# 1.52 09-Dec-1999 itojun

do not perform IPv6 initialization for loopback interface.
MUST make lo0 up before any IPv6 operations.
it will be considered a pilot error if you don't.
(I prefer to have lo0 initialized automatically)


Revision tags: OPENBSD_2_6_BASE
# 1.51 01-Sep-1999 deraadt

support # characters in bridgename.* files; millert


# 1.50 01-Sep-1999 deraadt

cleanup parsing of hostname.* files, and seperate bridge control into
bridgename.* files; all documented in new hostname.if(5) and
bridgename.if(5) man pages


# 1.49 09-Aug-1999 angelos

Only parse/setup the hostname.foo file if interface foo exists (this
is useful for laptops with different ethernet cards etc.)


Revision tags: OPENBSD_2_5_BASE
# 1.48 29-Mar-1999 niklas

New multicast route setup style


# 1.47 26-Mar-1999 niklas

Add bridge interface handling


# 1.46 01-Mar-1999 millert

Add support in /etc/hostname.xxx for files of the format:
up [options]
Any of the following may or may not be set:
$name $mask $bcaddr $extras


# 1.45 28-Oct-1998 millert

Kill the awful hack used to match and split /etc/hostname.* We now use
a function, isalphanumeric, to determine whether an interface name is
likely to be valid. This means that things like /etc/hostname.le0.bak,
/etc/hostname.le0#, /etc/hostname.le0~, etc. will be ignored as they
should. There is no longer an implicate assumption that /etc/hostname.*
only contains a single '.'.


Revision tags: OPENBSD_2_4_BASE
# 1.44 06-Oct-1998 deraadt

move ipnat to end of netstart, to support dhcp+ipnat


# 1.43 18-Sep-1998 deraadt

apply media directives on dhcp interfaces


# 1.42 10-Sep-1998 marc

better way of handling dhcp client; Jason Ish <jbi130@mail.usask.ca>


# 1.41 08-Sep-1998 marc

dhcp client stuff. "Angelos D. Keromytis" <angelos@dsl.cis.upenn.edu>


# 1.40 24-Aug-1998 downsj

You can't use -interface default when there's no default gateway
set (yet). Use -interface $hostname if mygate doesn't exist so that
this actually works on routers.


# 1.39 04-Jul-1998 deraadt

put 224 route on default, to avoid a hostname lookup


# 1.38 22-May-1998 deraadt

use route -n, what the heck


Revision tags: OPENBSD_2_3_BASE
# 1.37 28-Mar-1998 deraadt

s/^nat/ipnat/


# 1.36 23-Feb-1998 niklas

remove trailing blank line


# 1.35 07-Feb-1998 deraadt

ipforward is in sysctl.conf now


# 1.34 21-Dec-1997 deraadt

ugh


# 1.33 20-Dec-1997 deraadt

ipforwarding option in rc.conf


# 1.32 29-Nov-1997 kstailey

NAT requires IPF


# 1.31 04-Nov-1997 deraadt

kill spaces at ends of lines; m4


Revision tags: OPENBSD_2_2_BASE
# 1.30 14-Oct-1997 deraadt

set hostname/domainname before running rc.conf; m4@umn.edu


# 1.29 04-Sep-1997 deraadt

fork netstart; new child is rc.conf


# 1.28 25-Aug-1997 millert

Explicately pass -host flag to route(8) to avoid confusion with networks.


# 1.27 19-Aug-1997 niklas

Add hook for rpc.lockd, make nfsd flags settable in netstart


# 1.26 31-Jul-1997 downsj

Make quotas optional; wedged into netstart for the time being.
/etc/rc.conf, anyone?


# 1.25 30-Jul-1997 deraadt

do not run routed by default


# 1.24 28-Jul-1997 kstailey

Move configuration of loopback interface to before all other interfaces.
Allows the use of local caching-only nameserver with no "nameserver"
entry in /etc/resolv.conf to configure a route between the hostname
and loopback.


# 1.23 25-Jul-1997 provos

earlier start of keymanagement


# 1.22 24-Jul-1997 deraadt

make amd use /tmp_mnt by default


# 1.21 22-Jul-1997 provos

start the photuris daemon per default. hilfe.


# 1.20 17-Jun-1997 niklas

Put in hooks to start ypserv with flags


# 1.19 17-Jun-1997 niklas

Put in hooks to start rpc.yppasswdd with flags


Revision tags: OPENBSD_2_1_BASE
# 1.18 15-Apr-1997 deraadt

kill route flush until .. hmm kernel routing socket bug or something


# 1.17 09-Apr-1997 kstailey

add NAT startup


# 1.16 07-Apr-1997 rees

flush all old routes before adding new interfaces or routes.
ref: netbsd pr3228/misc, Matthias Scheler


# 1.15 03-Mar-1997 downsj

fix typo


# 1.14 11-Feb-1997 deraadt

add default route before fiddling with loopback route to avoid DNS problems; m4@umn.edu, #97


# 1.13 03-Feb-1997 deraadt

do ifaliases after /usr/bin exists in nfs diskless env; pr#77, matthieu@laas.fr


# 1.12 02-Nov-1996 deraadt

timed off by default


Revision tags: OPENBSD_2_0_BASE
# 1.11 23-Sep-1996 deraadt

rfc1323 variable


# 1.10 04-Sep-1996 deraadt

control portmap, inetd, and lpd from netstart; idea from tqbf@enteract.com


# 1.9 27-Aug-1996 deraadt

224.0.0.0 not 0.0.0.224; from peter@demon.net


# 1.8 18-Jun-1996 deraadt

move std stuff from rc.local to rc


# 1.7 16-Jun-1996 deraadt

install sample commented /etc/ifaliases file; which can now contain #
comments and blank lines. new format is "interface address netmask"
(yes, i changed the order of the entries). inspired by netbsd pr#2474;
gillhaa@ghost.whirlpool.com


# 1.6 02-Jun-1996 tholo

Install a multicast route by default


# 1.5 26-May-1996 deraadt

sync & label


# 1.4 09-Jan-1996 dm

added IP filter to netstat/rc and put examples in /usr/share/ipf


# 1.3 30-Dec-1995 deraadt

from netbsd: start mrouted like routed


# 1.2 18-Dec-1995 deraadt

/etc/ifaliases support by randy@zyzzyva.com


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.212 20-Jun-2021 florian

Don't try to install a default route with route(8) later on if we are
using inet autoconf, like we do with "dhcp" and "inet6 autoconf".
OK kn


Revision tags: OPENBSD_6_9_BASE
# 1.211 23-Dec-2020 krw

Allow the provision of dhclient(8) options on 'dhcp' lines in hostname.if(5)
files.

Usual man page help & ok jmc@


# 1.210 21-Dec-2020 krw

Avoid issuing pointless 'ifconfig <if> up' when processing 'dhcp' in
hostname.if files. dhclient(8) does that itself. Part of the
"further script optimizations" promised in r1.200 of netstart.

Tested & ok gnezdo@


# 1.209 29-Nov-2020 tb

Fix previous: use correct version of netstart and installer bits.


# 1.208 29-Nov-2020 deraadt

Add support for !command to mygate, so that netstart has a late opportunity
to perform network configuration (for example, "!route source -ifp em0")
Split mygate and myname manual pages (how did anyone ever believe these
are related), and perform hostname configuration much earlier in rc.
discussed with benno, claudio, jmc, etc etc, last version of !command
parser by tb


# 1.207 08-Nov-2020 jmc

no more mobileip;
ok claudio deraadt


Revision tags: OPENBSD_6_8_BASE
# 1.206 21-Jun-2020 dlg

start wg with the other interfaces that rely on routing being up.

from Matt Dunwoodie and Jason A. Donenfeld

ok deraadt@


# 1.205 22-May-2020 kn

Revert the following commit as it breaks hostname.if(5) lines with a
backslash at the end for line continuation

Breaking long lines into multiple ones must still be possible and does
require to treat the backslash as an escape character.

Breakage reported by Mark Patruck <mark at wrapped dot cx >, thanks!

---
distrib/miniroot/install.sub revision 1.1151
etc/netstart revision 1.203
date: 2020/05/21 11:54:41; author: kn; state: Exp; lines: +2 -2;
Do not treat backslashe as an escape character in hostname.if(5) lines

ifstart() should always pass such lines unaltered, especially if they
contain "nwid" or "description" lines with arbitrary strings.

<bsdlisten at gmail dot com> reported SSIDs such as "Mike's" during
installation end as broken; this was because the installer escaped
the single quote using backslashes which ended up being treated as
escape characters much later during hostname.if parsing in netstart(8).

Ok deraadt


# 1.204 21-May-2020 kn

Fix stripcom() description wrt. comments not on their own line

Neither netstart's nor install.sub's (subtly different) implementations
remove trailing comments on lines not starting as a comment, e.g.,
lines like "up #not down" go through unaltered and without "#not down"
being removed.

Only lines *beginning* with the comment sign ("#") are stripped.

No functional change, just updating function descriptions.


# 1.203 21-May-2020 kn

Do not treat backslashe as an escape character in hostname.if(5) lines

ifstart() should always pass such lines unaltered, especially if they
contain "nwid" or "description" lines with arbitrary strings.

<bsdlisten at gmail dot com> reported SSIDs such as "Mike's" during
installation end as broken; this was because the installer escaped
the single quote using backslashes which ended up being treated as
escape characters much later during hostname.if parsing in netstart(8).

Ok deraadt


Revision tags: OPENBSD_6_7_BASE
# 1.202 15-Jan-2020 kn

Do not redirect already quiet stdout for IPv6 reject routes

"route -q" already silences all standard output; if it still prints
something, that's a bug to fix in route.

OK bluhm


# 1.201 25-Oct-2019 dlg

handle aggr(4) in the same way as trunk(4)

from brad@
ok bluhm@ claudio@ deraadt@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.200 29-Aug-2018 krw

Historically /etc/netstart (and the equivalent code in the install
script) did 'ifconfig <if> down' before starting dhclient(8). This was
a way of ensuring old running copies of dhclient were killed before a
new one started. Current dhclient does not need this assist, so change
"ifconfig <if> down" to "ifconfig <if> up" pending further script
optimizations.

Similar to a 2014 attempt by halex@. Prompted by a misc@ report
from Kristjan Komlosi reporting hanging diskless setups.

ok halex@ kn@


# 1.199 08-Jul-2018 tb

netstart is used during system start, but also interactively.
Show proper error message if a regular user executes netstart.
Only do the privilege check if the id binary is available,
which might not be the case during diskless system startup.

ok deraadt, jasper, jca, krw, rpe (who wrote the same diff), sthen


# 1.198 28-Apr-2018 rpe

Add a proper usage() function.

Suggested by and OK jmc.
OK tb


Revision tags: OPENBSD_6_3_BASE
# 1.197 04-Mar-2018 jmc

when -n is used, no need to spit out "Missing parameters." before
displaying usage();

ok tb


# 1.196 03-Mar-2018 landry

Lowercase 'usage' and group -n with interface in it.
From jmc@, ok tb@


# 1.195 21-Feb-2018 rpe

Tweak comments.

OK tb


# 1.194 19-Feb-2018 rpe

Write warning/error messages to stderr and end them with a fullstop.

OK tb


# 1.193 19-Feb-2018 rpe

- use specific patterns when looping over /etc/hostname.if files
to skip backup or temp files.
- test if the patterns matched actual files
- warn if ifcreate() fails on an interface and continue with the
subsequent interfaces in the list instead of return'ing

OK dlg sthen tb


# 1.192 17-Feb-2018 rpe

- Add descriptions for the new functions ifcreate() and vifscreate()
- In ifcreate() use the exit code of the {} block directly
- In vifscreate(), use the ifconfig -C output directly in the for _vif loop
- Remove superfluous and somewhat confusing comment

OK dlg kn sthen


# 1.191 14-Feb-2018 dlg

create virtual interfaces before starting all interface config.

this resolves an ordering problem when adding pseudo interfaces to bridges

tweaks from kn@
ok mpi@ sthen@


# 1.190 10-Feb-2018 claudio

Remove some special IPv4 in IPv6 mapped prefixes that are already rejected
by the ::0.0.0.0/96 reject route added to deny all IPv4 mapped addresses.
Makes the inet6 routing table almost fit in one screen.
OK benno@


# 1.189 10-Feb-2018 florian

Load RFC 7217 key material and generate if it does not already exist.

Add soii.key to changelist (pointed out by semarie) and mtree/special
(suggest by Craig Skinner).

OK naddy, sthen, rpe, tb


# 1.188 06-Feb-2018 tb

If -n is given, the netstart script should not (try to) set the default
route(s). Simply print the command(s) to be issued instead.

tweak & ok rpe


# 1.187 12-Nov-2017 tb

Remove HN_DIR variable and expand it in the only place it was used. It
currently serves no purpose.

ok rpe, agreement from deraadt and halex


Revision tags: OPENBSD_6_2_BASE
# 1.186 25-Jul-2017 rpe

Finally remove backwards compat code to support the 'rtsol' keyword
in hostname.if(5)

OK mpi@ deraadt@ florian@
OK jmc@ from doc perspective


# 1.185 21-Jul-2017 rpe

Align ifstart() in netstart and install.sub.

- in netstart, rename _file to _hn referencing hostname.if files
- in install.sub switch ifstart() to be used with _if instead of
_hn as parameter

ok krw@ tb@


# 1.184 28-May-2017 awolk

etc/netstart: use colon separator instead of dot with chown

OK jung@, deraadt@, jmc@


# 1.183 07-May-2017 rpe

Change test from [] to [[]] and simplify pattern.

OK tb@, krw@ (for [[]])
Feedback and OK halex@


# 1.182 07-May-2017 rpe

Replace hardcoded script name with ${0##*/}

OK tb@ halex@


# 1.181 01-May-2017 rpe

Revert r1.170 and remove the id==0 check.
The id binary is not available in nfs diskless setups at this point.

reported by Andreas Kusalananda, thanks.
discussed with deraadt@


# 1.180 01-May-2017 rpe

Remove last remnants of rtsol. IPv6 autoconfiguration of interfaces is now
done in ifstart(). Remove ipv6autoconf() and replace rtsolif with a boolean
variable V6_AUTOCONF. Replace dhcpif with a boolean variable V4_DHCPCONF.
Both are later used in defaultroute() to decide whether or not to configre
defaultroutes from /etc/mygate.

OK krw@


# 1.179 30-Apr-2017 mpi

Do not try to delete a default route before adding it.

Now that route are automatically G/C with the address they are attached
to there's no reason to duplicate the kernel's job.

Fix a regression introduced with multipath default routes.

ok deraadt@


# 1.178 25-Apr-2017 rpe

Unbreak netstart for multiple inteface configurations like trunk
or carp. Ensure that the noglob option is disabled at the end of
parse_hn_line() and ifstart().

Reported by Christer Solskogen and Stefan Wollny, thanks!


# 1.177 24-Apr-2017 rpe

Introduce a new function parse_hn_line() that replaces the existing
hostname.if(5) parsing code in ifstart().
Add a -n option to netstart to only print the interface configuration
commands instead of executing them.
Add a HN_DIR variable, that points to the directory of the hostname.if
files (default /etc) that allows for future regression tests.

- add new parse_hn_line() function
- change ifstart()
- rename $if to $_if
- don't ifconfig or ifconfig create if -n option is used
- replace hostname.if(5) parsing code with new parse_hn_line()
- just print configuration commands if -n option is used
- autoconf now happens in ifstart(), remove ifv6autoconf()
- introduce HN_DIR variable for the hostname.if file location
- add handling of the -n option to only print config commands
- ensure -n is only used if interfaces are specified as parameters

Discussed with and positive feedback from many
'commit' deraadt@
OK sthen@


# 1.176 08-Apr-2017 rpe

- localize the if, file and stat variables which also ensures that
variables are not named like commands.
- change test from [] to [[]]

OK tb@ halex@


# 1.175 07-Apr-2017 rpe

Minimize differences in ifstart() function between netstart and
install.sub which makes it easier to spot changes in the future.

- comments and formatting
- quotes on assignments are not needed (netstart)
- remove stray space in test (netstart)
- use $file variable with while-loop (netstart)
- although valid, instead of i use $i in arithmetic test (install.sub)

OK krw@, tb@
Looks good deraadt@


# 1.174 07-Apr-2017 rpe

Align comments of ifstart() function in netstart and install.sub.


# 1.173 07-Apr-2017 rpe

Align comments of stripcom() function in netstart and install.sub.


Revision tags: OPENBSD_6_1_BASE
# 1.172 06-Dec-2016 mpi

Do not lose the default route when netstart(8) is run a second time on
the interface pointed to by the default route.

Since the kernel no longer keep routes with dangling address pointer,
netstart(8) has to re-add the default route when the corresponding ifa
has been deleted and re-created.

deraadt@ points out that even if the previous semantic was not necessarily
better, a script like netstart(8) cannot totally fix the default route
problem.

Regression reported by and fix tested by Hrvoje Popovski.

ksh foo checked by halex@


# 1.171 27-Sep-2016 rzalamena

Delay switch(4) interface start up so it can attach virtual interfaces
like vether(4).

nits from and ok benno@, phessler@


# 1.170 09-Sep-2016 jasper

print a clear error message when not ran as root instead of just falling
through and try whatever it can do with the invoking user's perms

feedback/ok aja@ rpe@


Revision tags: OPENBSD_6_0_BASE
# 1.169 19-Jul-2016 mpi

Do not consider tap(4) a special interface and start if before other
pseudo-interfaces.

This unbreak vlan(4) on top of tap(4) since the refactoring to turn it
MP-safe.

ok claudio@, deraadt@


# 1.168 27-Mar-2016 sthen

Don't delete the 224/4 route in netstart, unless it's being done to ensure that
a -reject route can be added. Restores the ability to set an interface route
before daemons are started, lost during the previous simplification.
ok millert mpi


Revision tags: OPENBSD_5_9_BASE
# 1.167 29-Dec-2015 rpe

Remove backslash, not necessary after '&&'

OK halex@


# 1.166 29-Dec-2015 rpe

Replace last remaining `` with $()

OK halex@


# 1.165 18-Dec-2015 ajacoutot

Drop the now useless multicast setup comment.

prodded by tim@, ok mpi@


# 1.164 17-Dec-2015 ajacoutot

Simplify multicast option handling (10 less lines) by matching /etc/rc behavior
towards other YES|NO options and drop the error warning.


with and ok tim@, ok rpe@ on an earlier diff


# 1.163 05-Dec-2015 mpi

It does not make sense to insert a specific route for 224/4 when the
default one is good enough.

So merge rc.conf(8)'s 'multicast_router' and 'multicast_host' into a
single 'multicast'. If set to YES the reject route for 224/4 is not
inserted by netstart(8).

Manual bits from jmc@

ok henning@, ajacoutot@


# 1.162 12-Nov-2015 rpe

Changes to ifautostart():
- Rename function to ifv6autoconf() to make IPv6 relation clearer
- Localize and rename variables

OK krw@


# 1.161 12-Nov-2015 rpe

Changes to ifmstart():
- Change comments to make it clearer that ifmstart() takes two lists
of interface driver names (of which the second is optional) and not
the actual interface instances.
- Use localized variables and use slightly more verbose names.
- Use continue 2 to skip to the next hostname.if file.
- Use shell pattern @() instead of testing _sif individually.

OK krw@


# 1.160 12-Nov-2015 rpe

Changes to stripcom():
- Align comments with /etc/rc version
- Use localized variables
- Use safer "print -r --" instead of plain echo

Changes to ifstart():
- Tweak comment
- Add usage

OK krw@


# 1.159 01-Nov-2015 rpe

Start the rework of the /etc/netstart shell script.

General changes:
- apply a similar 'style' as used in the installer scripts
- improve comments to be more to the point, remove where code is obvious
- document usage of functions if they have arguments
- rename variables where it improves readability
- replace really old-school shell code with more contemporary idioms

Other changes:
- No need to care about "autoboot" because netstart doesn't inherit the
positional parameters from /etc/rc anymore. /etc/rc executes netstart
instead of sourcing it since r1.439.
- Use simpler for-loop to process list of interfaces with ifstart.

OK halex@


# 1.158 26-Oct-2015 rpe

The hostname variable is not used since r1.99. Remove it and use
stripcom() output directly with the hostname command.

OK deraadt@ krw@


# 1.157 23-Oct-2015 claudio

netstart bits for tap(4)


# 1.156 27-Sep-2015 sthen

Don't print output when setting autoconf on interfaces. Suggested by deraadt,
ok florian@ rpe@


# 1.155 13-Sep-2015 sthen

only print the "IPv6 autoconf" line if there are interfaces to configure
feedback/ok rpe


# 1.154 11-Sep-2015 sthen

Set "inet6 autoconf" individually on interfaces that have rtsol set in
hostname.if, previously netstart tried to configure them all at once
("ifconfig if0 if1 if2 inet6 autoconf"). From Delan Azabani, ok phessler@


Revision tags: OPENBSD_5_8_BASE
# 1.153 20-Jul-2015 rpe

Disable Strict Bourne shell mode for /etc/rc and /etc/netstart to be
able to use ksh syntax within these scripts. This way init doesn't
need to be changed, which starts /etc/rc using /bin/sh and people
can still use "sh /etc/netstart ifname".

Idea from and OK halex@
OK deraadt@ krw@ guenther@


# 1.152 19-Jul-2015 florian

Bring up pflow last as it might send with a source address that is on
any of the other interfaces.
OK deraadt, phessler, benno


# 1.151 19-Jul-2015 rpe

Always source rc.subr to be able to use the rc.conf parsing routine
to get the network related vars from rc.conf. This is even necessary
if netstart is run from within /etc/rc. Remove test of $INRC which
unintentionally evaluated always to true.

problem with previous change found by nigel@
OK sthen@ aja@ halex@


# 1.150 19-Jul-2015 ajacoutot

Revert 1.148 for now until I can talk to rpe@
It introduced a regression reported by nigel@


# 1.149 19-Jul-2015 rpe

Replace test command with [].

OK halex@ krw@


# 1.148 19-Jul-2015 rpe

Ensure, that we source rc.subr and parse rc.conf ONLY if we are not
inside /etc/rc.

With help from and OK halex@, ajacoutot@


# 1.147 18-Jul-2015 rpe

- remove trailing blanks introduced in previous commit
- no space in redirections like </foo or >$bar
- few other minor whitespaces

OK krw@


# 1.146 18-Jul-2015 rpe

Improve comments
- Add comments for functions
- Start comments with capital letters
- End comments with a full stop
- Allow comments to extend up to column 80

OK krw@


# 1.145 06-Jun-2015 florian

Allow rtsol keyword in hostname.if(5) with net.inet6.ip6.forwarding=1.
"inet6 autoconf" was working before and rtsol should behave the same.
OK phessler


Revision tags: OPENBSD_5_7_BASE
# 1.144 03-Dec-2014 florian

The kernel handles rtsol(8) functionality since some time now.
Treat rtsol in hostname.if as a keyword like dhcp and call ifconfig
inet6 autoconf.
"reads good" todd@
OK krw@ (who is *not* an IPv6 person), but I recruited him in his
capacity as an installer person.


# 1.143 28-Sep-2014 claudio

Revert 1.142. Without the down netstart will just print the ifconfig
output because it may end up just calling 'ifconfig $if'. This needs
to be done better and properly tested.


# 1.142 26-Sep-2014 halex

remove explicit 'down' of an interface before starting a dhcp request, thereby
avoiding annoying delays for some switch configurations

ok claudio@ deraadt@

i would add ok phessler@, but it was not valid without an ok krw@


Revision tags: OPENBSD_5_6_BASE
# 1.141 12-Jul-2014 stsp

Fix netstart after autoconf6 change so 'rtsol' lines in hostname.if work again.
found by pelikan@; ok pelikan@ henning@


# 1.140 12-Jul-2014 robert

Make rc.conf a parsed configuration file and stop sourcing it as a shell
script.
From now on rc.conf has a fixed syntax (key=val) and it is not allowed
to add anything to it besides the supported syntax, it all going to be
ignored.

discussed with and help from deraadt@ and halex@


Revision tags: OPENBSD_5_5_BASE
# 1.139 22-Aug-2013 mpi

Like for dhclient, do no create a route to alias addresses via 127.0.0.1.
Our stack is able to tell if the address is local or not.

ok todd@, krw@


Revision tags: OPENBSD_5_4_BASE
# 1.138 20-Mar-2013 todd

fix lies in netstart; replacement wording from halex@
pointed out by Ryan Kavannagh rak at debian dot org


Revision tags: OPENBSD_5_3_BASE
# 1.137 05-Dec-2012 rpe

remove "Invalid interface name" message
requested by krw@

ok halex@


# 1.136 02-Dec-2012 rpe

use the more compact version of the check for ifconfig'able interfaces
from install.sub

with feedback from and ok halex


# 1.135 02-Dec-2012 rpe

- remove isalphanumeric() and replace it with a shell pattern, that
tries a bit harder to identify invalid interface names and in
this case emit an error message.
- use [[ $1 == autoboot ]] to avoid a shell error message due to
possible spaces in first argument
- no change in functionality

discussed with krw and halex
ok ("I like this") krw


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.134 07-Oct-2011 deraadt

The new ypbind changes requires that the domainname be set before
rc.conf is run. There's no real downside.
ok aja


Revision tags: OPENBSD_5_0_BASE
# 1.133 07-Jul-2011 guenther

Eliminate some $? tests by rolling the command into the condition

ok halex@


# 1.132 26-May-2011 mpf

Add svlan(4) startup bits.
From markus@. OK naddy, claudio, reyk.


Revision tags: OPENBSD_4_9_BASE
# 1.131 09-Feb-2011 sobrado

fix an unbalanced parenthesis in a comment; while here, split the comment
in a better place to make it more readable.

ok jmc@ and miod@


Revision tags: OPENBSD_4_8_BASE
# 1.130 16-Jun-2010 todd

permit e.g. -inet6 syntax by slurping all lines not just some
noticed by rhsv6 at hushmail dot com, ok sthen@


Revision tags: OPENBSD_4_7_BASE
# 1.129 12-Jan-2010 henning

when setting up lo0 use 127.0.0.1/8 instead of 127.0.0.1 for clarity and
correctness. it's not 1992 any more, kids. ok mcbride dlg krw


# 1.128 10-Dec-2009 todd

o stop reordering ifconfig arguments (e.g. after 'up ..')
o only stop processing if inet or inet6 lines are malformed
o everything not a specially handled bit is passed to ifconfig unmangled
noticed by several after the move from bridgename.bridge0 -> hostname.bridge0
prodded by deraadt@, tested by and feedback from several
man page bits 'look fine' jmc@


# 1.127 22-Nov-2009 deraadt

Stop supporting bridgename.bridge* files, and move to hostname.bridge*
files. To cope with this change, read about the mv command.
ok claudio todd


# 1.126 17-Sep-2009 simon

change variable i to $i in an expression of ifstart() for consistency
with the rest of the file. no functional change.

feedback from sthen@, ok krw@


# 1.125 10-Jul-2009 jdixon

Delay creation of tun(4) interfaces until the underlying interface and
routes are available. This fixes usage for some OpenVPN users that start
it from hostname.tun*.

Tested by Johan Huldtgren. ok sthen@, johan@.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.124 25-Nov-2008 markus

delay /etc/netstart until IPv6-DAD (dup-address-detection) is completed.
ok fries, hshoexer, claudio


# 1.123 14-Aug-2008 sthen

Tools from /usr may not be used in netstart since it may be NFS-mounted
and not available at that time. Rewrite the hostname.if permission check
to use only /bin/ls and the shell. Requested by deraadt.

ok todd, "Twisted." deraadt


Revision tags: OPENBSD_4_4_BASE
# 1.122 23-Jul-2008 sthen

Prevent warning about insecure hostnames where no /etc/hostname.*
exists. From wcmaier@.

Check target of symbolic links to avoid noise at boot and in
seucrity output where you have several interfaces symlinked to one
config file.

"If you think this is the right thing to do" deraadt@


# 1.121 09-Jun-2008 todd

warn once not 3 times in case of a non existent file, discussed with deraadt
originally pointed out by Johan Torin


# 1.120 09-Jun-2008 deraadt

Ensure that hostname.* files are also re-chowned to root.wheel at each
boot as discussed with claudio while eating tasty donairs. ok todd


# 1.119 17-Apr-2008 deraadt

before using them, force hostname.* files to be unreadable by world
first version from todd, ok millert


Revision tags: OPENBSD_4_3_BASE
# 1.118 17-Jan-2008 brad

Execute rtsol after turning up trunk(4) and vlan(4) interfaces so they're
taken into consideration for rtsol.

ok reyk@ dlg@


# 1.117 09-Jan-2008 mpf

Do not bring up pfsync(4) before the working ruleset
has been loaded. Otherwise, states that are received during the
initial bulk update mismatch the correct pf-checksum and
do not attach to the rules.
Problem identified by david@. Fix done in collaboration.
OK henning@


Revision tags: OPENBSD_4_2_BASE
# 1.116 02-Aug-2007 david

move the delay for IPv6 DAD to after all interfaces have started
fixes problems with daemons being unable to bind to all addreses at boot
ok itojun@ hshoexer@


Revision tags: OPENBSD_4_1_BASE
# 1.115 15-Nov-2006 itojun

reject multicast packet without scope identifier specified.


Revision tags: OPENBSD_4_0_BASE
# 1.114 29-Jun-2006 todd

do not add an extra space; nwid and description come out wrong
fix as proposed by maja@, thanks!


Revision tags: OPENBSD_3_9_BASE
# 1.113 28-Dec-2005 david

nuke extra whitespace


# 1.112 06-Dec-2005 reyk

multicast_host=YES only works if a valid default gateway is available.
validate this condition and reject multicast traffic on failure.

ok todd@ naddy@


# 1.111 02-Nov-2005 todd

fix inspired by pr#4590
ok krw@


# 1.110 25-Oct-2005 todd

better logic from krw@:
- do not process mygate for v4 if dhcp
- do not process mygate for v6 if rtsol
this also makes the mygate processing logic more readable
ok krw@


# 1.109 14-Oct-2005 todd

add v6 support for /etc/mygate
ok deraadt@ mickey@ krw@
same functionality tested/ok'ed by by mickey, brad, matthieu, and me
with this one may now put a v6 IP in /etc/mygate on a separate line from
the v4 default gateway and netstart will do the right thing


# 1.108 12-Oct-2005 todd

shrink stripcom(), sync with install.sub
ok krw@


# 1.107 04-Oct-2005 todd

trunk must be started after physical ethernet devices, but before vlan.
populate ifmstart lines accordingly.
prodded/tested by brad@
ok reyk@


# 1.106 28-Sep-2005 todd

use eval consistently, fixes description quotes on rtsol and dhcp
fix inspired by and closes pr 4495
ok krw@


Revision tags: OPENBSD_3_8_BASE
# 1.105 22-May-2005 todd

Introduce 'ifmstart' to deal with starting multiple interfaces minus a list
of interfaces.

This reduces the netstart script by 174 chars, 13 words, and 19 lines, but
more importantly, makes it more simple and less cluttered should more special
case/orderings be needed.

ok brad@ and pr 4197 submitter, inspired by and closes pr 4197


# 1.104 04-Apr-2005 djm

unbreak; ok pval@


# 1.103 03-Apr-2005 deraadt

if dhcp is used to get an address on any interface, ignore /etc/mygate
ok krw
(this lets us do something rather cool with the zaurus in particular)


Revision tags: OPENBSD_3_7_BASE
# 1.102 04-Jan-2005 mcbride

Bring up the carp(4) interface before default route.

ok pascoe@ mpf@


# 1.101 30-Dec-2004 millert

Add a copy of stripcom so /etc/netstart can be run standalone again.
OK deraadt@


# 1.100 19-Dec-2004 millert

Allow comments in /etc/{myname,mygate,defaultdomain}; OK deraadt@


# 1.99 04-Dec-2004 itojun

remove "route $hostname 127.0.0.1" line. deraadt ok
*** please update /etc/netstart and test if it works ok for you ***


# 1.98 20-Oct-2004 deraadt

make all route commands use -qn; ok mcbride henning


Revision tags: OPENBSD_3_6_BASE
# 1.97 29-May-2004 deraadt

one last route command lacking -qn


Revision tags: OPENBSD_3_5_BASE
# 1.96 22-Mar-2004 mcbride

Make sure pfsync is brought up before carp.

ok deraadt@


# 1.95 13-Mar-2004 mcbride

Delay pfsync(4) configuration, as the syncif has to be configured in
advance. From Thorsten Lockert.


# 1.94 14-Jan-2004 deraadt

ok, it took quite a bit of prodding but itojun finally explained why the
extra sleep 1 is in here, and we came to the conclusion it is safe to
delete it. whee.


# 1.93 13-Jan-2004 deraadt

repair v6 lo0 documentation


# 1.92 11-Jan-2004 deraadt

add loopback routes late


# 1.91 09-Jan-2004 deraadt

create all routes with -q; markus ok


# 1.90 04-Dec-2003 millert

Need to do "ifconfig create" for bridge interfaces too.


# 1.89 03-Dec-2003 markus

add support for ifconfig clone; from netbsd; ok deraadt, henning


# 1.88 20-Oct-2003 david

delay carp initialization until after physical interfaces are configured
ok mcbride@ henning@ deraadt@ todd@


Revision tags: OPENBSD_3_4_BASE
# 1.87 27-Aug-2003 henning

only try to set hostname to what /etc/myname says if that file actually exists,
otherwise preserve `hostname`
netbooted machines can live perfectly fine without it; they get their hostname
earlier.

ok krw@ cedric@


Revision tags: OPENBSD_3_3_BASE
# 1.86 16-Feb-2003 krw

Fix up some DNS verbiage to make it consistant.

Fix up default route selection by

a) Forcing user to explicitly chose 'dhcp' as a mechanism for
specifying a default route, rather than guessing based on one or more
interfaces being configured by dhcp.

b) If the user specified default route does not work, re-present the
existing default route rather than losing it.

c) Move default route selection to after nameserver activation so the
user can specify a hostname as the default route.

Change /etc/netstart so that /etc/mygate wins if a default route was
already specified (i.e. by dhcp).

ok deraadt@.


Revision tags: OPENBSD_3_2_BASE
# 1.85 16-May-2002 todd

ignore non-existent cases where '$if' evaluates to '*'.
From Andr� Lucas <andre@ae-35.com>, fixes pr # 2658.
'Looks good' from miod@, millert@, and krw@.


Revision tags: OPENBSD_3_1_BASE
# 1.84 23-Feb-2002 deraadt

re-add support for $if expansion; hamajima@nagoya.ydc.co.jp


# 1.83 21-Feb-2002 miod

Change the network components initialization order.
Change from:
o all interfaces
o all bridges
o routes
to:
o physical interfaces
o routes
o gif and gre interfaces
o bridges

Fixeski PR #2400.
Manual page updates coming soon.
Ok angelos@ chris@ deraadt@


Revision tags: OPENBSD_3_0_BASE
# 1.82 31-Jul-2001 hugh

a space before a redirect


# 1.81 06-Jul-2001 angelos

Also, source /etc/rc.conf so we can pull in the
multicast_host/multicast_router settings; this is useful if one
flushes the routing table and re-initializes.

We really need a netconfig tool of sorts.


# 1.80 06-Jul-2001 angelos

Use "route -n show -inet" to determine the default multicast iface.


# 1.79 03-Jul-2001 deraadt

pull in rc.conf early so that pf(1) startup is right; tested by jasoni, comments from millert


# 1.78 30-May-2001 deraadt

Remove ipf. Darren Reed has interpreted his (old, new, whichever)
licence in a way that makes ipf not free according to the rules we
established over 5 years ago, at www.openbsd.org/goals.html (and those
same basic rules govern the other *BSD projects too). Specifically,
Darren says that modified versions are not permitted. But software
which OpenBSD uses and redistributes must be free to all (be they
people or companies), for any purpose they wish to use it, including
modification, use, peeing on, or even integration into baby mulching
machines or atomic bombs to be dropped on Australia. Furthermore, we
know of a number of companies using ipf with modification like us, who
are now in the same situation, and we hope that some of them will work
with us to fill this gap that now exists in OpenBSD (temporarily, we
hope).


Revision tags: OPENBSD_2_9_BASE
# 1.77 13-Mar-2001 deraadt

spelling; maurice@maurice.wan.nl


# 1.76 06-Feb-2001 todd

ignore blank lines in addition to comments
fixes pr#1660 from wilfried@telia.com .. Thanks!


# 1.75 10-Jan-2001 jason

support !command in bridgename.if files, too


# 1.74 27-Nov-2000 millert

Use -n to test if a variable is non-zero. Otherwise, if the variable's
contents start with a '-' test becomes unhappy (since it interprets it
as another option).


# 1.73 08-Nov-2000 todd

This fixes pr 1481, we now handle args > 6 in /etc/hostname.if in the
cases where we did not previously handle them.
Thanks to Scott Atwood <atwood@cs.stanford.edu> for reminding us of this.


Revision tags: OPENBSD_2_8_BASE
# 1.72 02-Sep-2000 todd

subtle bug .. global variables in a while loop need reset 'just incase'
With:
hostname.fxp0 having a last line of:
inet6 alias 3ffe:...
and hostname.gif0 having a first two lines of:
giftunnel 1.2.3.4
dest 1.2.4.3
We end up with the command:
ifconfig gif0 giftunnel alias 1.2.3.4 1.2.4.3
.. which is clearly wrong and fixed by this change


# 1.71 18-Jun-2000 todd

rc.conf now parses ${local_rcconf} internally; closes pr 1259


Revision tags: OPENBSD_2_7_BASE
# 1.70 08-May-2000 todd

fix dhcp 'NONE' ness from install to allow media parsing to work
.. ok deraadt@, millert@


# 1.69 21-Apr-2000 deraadt

rc.conf.local support, inspired by chuck yerkes


# 1.68 04-Apr-2000 millert

Remove the -E flag from ipf as it is implicitly enabled and using
the -E flag here causes the kernel to printf 'IP Filter: already
initialized'.


# 1.67 18-Mar-2000 deraadt

silence all extra route addition printouts


# 1.66 17-Mar-2000 itojun

correct reject route installations for IPv6. improve comments.


# 1.65 12-Mar-2000 itojun

disallow packets to malicious 6to4 prefix, based on
http://playground.iijlab.net/i-d/draft-itojun-ipv6-transition-abuse-00.txt


# 1.64 10-Mar-2000 todd

fix non behavior
with this `!' lines in /etc/hostname.* run even without certain lines
(like a comment) preceeding it.


# 1.63 10-Jan-2000 todd

allow arbitrary commands in /etc/hostname.* files if the line starts with '!'


# 1.62 02-Jan-2000 deraadt

rtsol case can configure the interface up, since it would be nice to finish
DAD before the actual rtsol(8) run happens later. and since it will rtsol,
it is going to be up in any case.


# 1.61 02-Jan-2000 itojun

one more indentation fix.


# 1.60 02-Jan-2000 itojun

indentation fix (todd's part)


# 1.59 02-Jan-2000 todd

fix rtsold case, reset cmd for each iteration!


# 1.58 02-Jan-2000 itojun

allow options after "rtsol".
XXX both "dhcp" and "rtsol" has keyword *down* at the end. is it okay?


# 1.57 02-Jan-2000 itojun

echo "IPv6 autoconf: interfaces" before invoking rtsol.
sleep for net.inet6.ip6.dad_count seconds to ensure that IPv6 DAD is completed.
TODO: rtsold (rc.conf line), manpage


# 1.56 02-Jan-2000 itojun

ipv6 autoconf on hosts (non-routers).

to do this,
1. in sysctl.conf, add these lines:
net.inet6.ip6.forwarding=0
net.inet6.ip6.accept_rtadv=1
2. in hostname.foo, add
rtsol

specifying two or more interfaces with "rtsol" may result in strange
behavior - ipv6 spec does not permit multi-interface node to be autoconfig'ed.


# 1.55 02-Jan-2000 todd

add to hostname.* parsing:
- multiple entries support (read: aliases)
- inet6 support
- support for comments (#)
(look for hostname.if(5) commit for syntax details)


# 1.54 31-Dec-1999 itojun

install IPv6 reject routes only if kernel is capable of IPv6.


# 1.53 09-Dec-1999 itojun

avoid transmitting invalid IPv6 packets out to the wire.


# 1.52 09-Dec-1999 itojun

do not perform IPv6 initialization for loopback interface.
MUST make lo0 up before any IPv6 operations.
it will be considered a pilot error if you don't.
(I prefer to have lo0 initialized automatically)


Revision tags: OPENBSD_2_6_BASE
# 1.51 01-Sep-1999 deraadt

support # characters in bridgename.* files; millert


# 1.50 01-Sep-1999 deraadt

cleanup parsing of hostname.* files, and seperate bridge control into
bridgename.* files; all documented in new hostname.if(5) and
bridgename.if(5) man pages


# 1.49 09-Aug-1999 angelos

Only parse/setup the hostname.foo file if interface foo exists (this
is useful for laptops with different ethernet cards etc.)


Revision tags: OPENBSD_2_5_BASE
# 1.48 29-Mar-1999 niklas

New multicast route setup style


# 1.47 26-Mar-1999 niklas

Add bridge interface handling


# 1.46 01-Mar-1999 millert

Add support in /etc/hostname.xxx for files of the format:
up [options]
Any of the following may or may not be set:
$name $mask $bcaddr $extras


# 1.45 28-Oct-1998 millert

Kill the awful hack used to match and split /etc/hostname.* We now use
a function, isalphanumeric, to determine whether an interface name is
likely to be valid. This means that things like /etc/hostname.le0.bak,
/etc/hostname.le0#, /etc/hostname.le0~, etc. will be ignored as they
should. There is no longer an implicate assumption that /etc/hostname.*
only contains a single '.'.


Revision tags: OPENBSD_2_4_BASE
# 1.44 06-Oct-1998 deraadt

move ipnat to end of netstart, to support dhcp+ipnat


# 1.43 18-Sep-1998 deraadt

apply media directives on dhcp interfaces


# 1.42 10-Sep-1998 marc

better way of handling dhcp client; Jason Ish <jbi130@mail.usask.ca>


# 1.41 08-Sep-1998 marc

dhcp client stuff. "Angelos D. Keromytis" <angelos@dsl.cis.upenn.edu>


# 1.40 24-Aug-1998 downsj

You can't use -interface default when there's no default gateway
set (yet). Use -interface $hostname if mygate doesn't exist so that
this actually works on routers.


# 1.39 04-Jul-1998 deraadt

put 224 route on default, to avoid a hostname lookup


# 1.38 22-May-1998 deraadt

use route -n, what the heck


Revision tags: OPENBSD_2_3_BASE
# 1.37 28-Mar-1998 deraadt

s/^nat/ipnat/


# 1.36 23-Feb-1998 niklas

remove trailing blank line


# 1.35 07-Feb-1998 deraadt

ipforward is in sysctl.conf now


# 1.34 21-Dec-1997 deraadt

ugh


# 1.33 20-Dec-1997 deraadt

ipforwarding option in rc.conf


# 1.32 29-Nov-1997 kstailey

NAT requires IPF


# 1.31 04-Nov-1997 deraadt

kill spaces at ends of lines; m4


Revision tags: OPENBSD_2_2_BASE
# 1.30 14-Oct-1997 deraadt

set hostname/domainname before running rc.conf; m4@umn.edu


# 1.29 04-Sep-1997 deraadt

fork netstart; new child is rc.conf


# 1.28 25-Aug-1997 millert

Explicately pass -host flag to route(8) to avoid confusion with networks.


# 1.27 19-Aug-1997 niklas

Add hook for rpc.lockd, make nfsd flags settable in netstart


# 1.26 31-Jul-1997 downsj

Make quotas optional; wedged into netstart for the time being.
/etc/rc.conf, anyone?


# 1.25 30-Jul-1997 deraadt

do not run routed by default


# 1.24 28-Jul-1997 kstailey

Move configuration of loopback interface to before all other interfaces.
Allows the use of local caching-only nameserver with no "nameserver"
entry in /etc/resolv.conf to configure a route between the hostname
and loopback.


# 1.23 25-Jul-1997 provos

earlier start of keymanagement


# 1.22 24-Jul-1997 deraadt

make amd use /tmp_mnt by default


# 1.21 22-Jul-1997 provos

start the photuris daemon per default. hilfe.


# 1.20 17-Jun-1997 niklas

Put in hooks to start ypserv with flags


# 1.19 17-Jun-1997 niklas

Put in hooks to start rpc.yppasswdd with flags


Revision tags: OPENBSD_2_1_BASE
# 1.18 15-Apr-1997 deraadt

kill route flush until .. hmm kernel routing socket bug or something


# 1.17 09-Apr-1997 kstailey

add NAT startup


# 1.16 07-Apr-1997 rees

flush all old routes before adding new interfaces or routes.
ref: netbsd pr3228/misc, Matthias Scheler


# 1.15 03-Mar-1997 downsj

fix typo


# 1.14 11-Feb-1997 deraadt

add default route before fiddling with loopback route to avoid DNS problems; m4@umn.edu, #97


# 1.13 03-Feb-1997 deraadt

do ifaliases after /usr/bin exists in nfs diskless env; pr#77, matthieu@laas.fr


# 1.12 02-Nov-1996 deraadt

timed off by default


Revision tags: OPENBSD_2_0_BASE
# 1.11 23-Sep-1996 deraadt

rfc1323 variable


# 1.10 04-Sep-1996 deraadt

control portmap, inetd, and lpd from netstart; idea from tqbf@enteract.com


# 1.9 27-Aug-1996 deraadt

224.0.0.0 not 0.0.0.224; from peter@demon.net


# 1.8 18-Jun-1996 deraadt

move std stuff from rc.local to rc


# 1.7 16-Jun-1996 deraadt

install sample commented /etc/ifaliases file; which can now contain #
comments and blank lines. new format is "interface address netmask"
(yes, i changed the order of the entries). inspired by netbsd pr#2474;
gillhaa@ghost.whirlpool.com


# 1.6 02-Jun-1996 tholo

Install a multicast route by default


# 1.5 26-May-1996 deraadt

sync & label


# 1.4 09-Jan-1996 dm

added IP filter to netstat/rc and put examples in /usr/share/ipf


# 1.3 30-Dec-1995 deraadt

from netbsd: start mrouted like routed


# 1.2 18-Dec-1995 deraadt

/etc/ifaliases support by randy@zyzzyva.com


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.211 23-Dec-2020 krw

Allow the provision of dhclient(8) options on 'dhcp' lines in hostname.if(5)
files.

Usual man page help & ok jmc@


# 1.210 21-Dec-2020 krw

Avoid issuing pointless 'ifconfig <if> up' when processing 'dhcp' in
hostname.if files. dhclient(8) does that itself. Part of the
"further script optimizations" promised in r1.200 of netstart.

Tested & ok gnezdo@


# 1.209 29-Nov-2020 tb

Fix previous: use correct version of netstart and installer bits.


# 1.208 29-Nov-2020 deraadt

Add support for !command to mygate, so that netstart has a late opportunity
to perform network configuration (for example, "!route source -ifp em0")
Split mygate and myname manual pages (how did anyone ever believe these
are related), and perform hostname configuration much earlier in rc.
discussed with benno, claudio, jmc, etc etc, last version of !command
parser by tb


# 1.207 08-Nov-2020 jmc

no more mobileip;
ok claudio deraadt


Revision tags: OPENBSD_6_8_BASE
# 1.206 21-Jun-2020 dlg

start wg with the other interfaces that rely on routing being up.

from Matt Dunwoodie and Jason A. Donenfeld

ok deraadt@


# 1.205 22-May-2020 kn

Revert the following commit as it breaks hostname.if(5) lines with a
backslash at the end for line continuation

Breaking long lines into multiple ones must still be possible and does
require to treat the backslash as an escape character.

Breakage reported by Mark Patruck <mark at wrapped dot cx >, thanks!

---
distrib/miniroot/install.sub revision 1.1151
etc/netstart revision 1.203
date: 2020/05/21 11:54:41; author: kn; state: Exp; lines: +2 -2;
Do not treat backslashe as an escape character in hostname.if(5) lines

ifstart() should always pass such lines unaltered, especially if they
contain "nwid" or "description" lines with arbitrary strings.

<bsdlisten at gmail dot com> reported SSIDs such as "Mike's" during
installation end as broken; this was because the installer escaped
the single quote using backslashes which ended up being treated as
escape characters much later during hostname.if parsing in netstart(8).

Ok deraadt


# 1.204 21-May-2020 kn

Fix stripcom() description wrt. comments not on their own line

Neither netstart's nor install.sub's (subtly different) implementations
remove trailing comments on lines not starting as a comment, e.g.,
lines like "up #not down" go through unaltered and without "#not down"
being removed.

Only lines *beginning* with the comment sign ("#") are stripped.

No functional change, just updating function descriptions.


# 1.203 21-May-2020 kn

Do not treat backslashe as an escape character in hostname.if(5) lines

ifstart() should always pass such lines unaltered, especially if they
contain "nwid" or "description" lines with arbitrary strings.

<bsdlisten at gmail dot com> reported SSIDs such as "Mike's" during
installation end as broken; this was because the installer escaped
the single quote using backslashes which ended up being treated as
escape characters much later during hostname.if parsing in netstart(8).

Ok deraadt


Revision tags: OPENBSD_6_7_BASE
# 1.202 15-Jan-2020 kn

Do not redirect already quiet stdout for IPv6 reject routes

"route -q" already silences all standard output; if it still prints
something, that's a bug to fix in route.

OK bluhm


# 1.201 25-Oct-2019 dlg

handle aggr(4) in the same way as trunk(4)

from brad@
ok bluhm@ claudio@ deraadt@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.200 29-Aug-2018 krw

Historically /etc/netstart (and the equivalent code in the install
script) did 'ifconfig <if> down' before starting dhclient(8). This was
a way of ensuring old running copies of dhclient were killed before a
new one started. Current dhclient does not need this assist, so change
"ifconfig <if> down" to "ifconfig <if> up" pending further script
optimizations.

Similar to a 2014 attempt by halex@. Prompted by a misc@ report
from Kristjan Komlosi reporting hanging diskless setups.

ok halex@ kn@


# 1.199 08-Jul-2018 tb

netstart is used during system start, but also interactively.
Show proper error message if a regular user executes netstart.
Only do the privilege check if the id binary is available,
which might not be the case during diskless system startup.

ok deraadt, jasper, jca, krw, rpe (who wrote the same diff), sthen


# 1.198 28-Apr-2018 rpe

Add a proper usage() function.

Suggested by and OK jmc.
OK tb


Revision tags: OPENBSD_6_3_BASE
# 1.197 04-Mar-2018 jmc

when -n is used, no need to spit out "Missing parameters." before
displaying usage();

ok tb


# 1.196 03-Mar-2018 landry

Lowercase 'usage' and group -n with interface in it.
From jmc@, ok tb@


# 1.195 21-Feb-2018 rpe

Tweak comments.

OK tb


# 1.194 19-Feb-2018 rpe

Write warning/error messages to stderr and end them with a fullstop.

OK tb


# 1.193 19-Feb-2018 rpe

- use specific patterns when looping over /etc/hostname.if files
to skip backup or temp files.
- test if the patterns matched actual files
- warn if ifcreate() fails on an interface and continue with the
subsequent interfaces in the list instead of return'ing

OK dlg sthen tb


# 1.192 17-Feb-2018 rpe

- Add descriptions for the new functions ifcreate() and vifscreate()
- In ifcreate() use the exit code of the {} block directly
- In vifscreate(), use the ifconfig -C output directly in the for _vif loop
- Remove superfluous and somewhat confusing comment

OK dlg kn sthen


# 1.191 14-Feb-2018 dlg

create virtual interfaces before starting all interface config.

this resolves an ordering problem when adding pseudo interfaces to bridges

tweaks from kn@
ok mpi@ sthen@


# 1.190 10-Feb-2018 claudio

Remove some special IPv4 in IPv6 mapped prefixes that are already rejected
by the ::0.0.0.0/96 reject route added to deny all IPv4 mapped addresses.
Makes the inet6 routing table almost fit in one screen.
OK benno@


# 1.189 10-Feb-2018 florian

Load RFC 7217 key material and generate if it does not already exist.

Add soii.key to changelist (pointed out by semarie) and mtree/special
(suggest by Craig Skinner).

OK naddy, sthen, rpe, tb


# 1.188 06-Feb-2018 tb

If -n is given, the netstart script should not (try to) set the default
route(s). Simply print the command(s) to be issued instead.

tweak & ok rpe


# 1.187 12-Nov-2017 tb

Remove HN_DIR variable and expand it in the only place it was used. It
currently serves no purpose.

ok rpe, agreement from deraadt and halex


Revision tags: OPENBSD_6_2_BASE
# 1.186 25-Jul-2017 rpe

Finally remove backwards compat code to support the 'rtsol' keyword
in hostname.if(5)

OK mpi@ deraadt@ florian@
OK jmc@ from doc perspective


# 1.185 21-Jul-2017 rpe

Align ifstart() in netstart and install.sub.

- in netstart, rename _file to _hn referencing hostname.if files
- in install.sub switch ifstart() to be used with _if instead of
_hn as parameter

ok krw@ tb@


# 1.184 28-May-2017 awolk

etc/netstart: use colon separator instead of dot with chown

OK jung@, deraadt@, jmc@


# 1.183 07-May-2017 rpe

Change test from [] to [[]] and simplify pattern.

OK tb@, krw@ (for [[]])
Feedback and OK halex@


# 1.182 07-May-2017 rpe

Replace hardcoded script name with ${0##*/}

OK tb@ halex@


# 1.181 01-May-2017 rpe

Revert r1.170 and remove the id==0 check.
The id binary is not available in nfs diskless setups at this point.

reported by Andreas Kusalananda, thanks.
discussed with deraadt@


# 1.180 01-May-2017 rpe

Remove last remnants of rtsol. IPv6 autoconfiguration of interfaces is now
done in ifstart(). Remove ipv6autoconf() and replace rtsolif with a boolean
variable V6_AUTOCONF. Replace dhcpif with a boolean variable V4_DHCPCONF.
Both are later used in defaultroute() to decide whether or not to configre
defaultroutes from /etc/mygate.

OK krw@


# 1.179 30-Apr-2017 mpi

Do not try to delete a default route before adding it.

Now that route are automatically G/C with the address they are attached
to there's no reason to duplicate the kernel's job.

Fix a regression introduced with multipath default routes.

ok deraadt@


# 1.178 25-Apr-2017 rpe

Unbreak netstart for multiple inteface configurations like trunk
or carp. Ensure that the noglob option is disabled at the end of
parse_hn_line() and ifstart().

Reported by Christer Solskogen and Stefan Wollny, thanks!


# 1.177 24-Apr-2017 rpe

Introduce a new function parse_hn_line() that replaces the existing
hostname.if(5) parsing code in ifstart().
Add a -n option to netstart to only print the interface configuration
commands instead of executing them.
Add a HN_DIR variable, that points to the directory of the hostname.if
files (default /etc) that allows for future regression tests.

- add new parse_hn_line() function
- change ifstart()
- rename $if to $_if
- don't ifconfig or ifconfig create if -n option is used
- replace hostname.if(5) parsing code with new parse_hn_line()
- just print configuration commands if -n option is used
- autoconf now happens in ifstart(), remove ifv6autoconf()
- introduce HN_DIR variable for the hostname.if file location
- add handling of the -n option to only print config commands
- ensure -n is only used if interfaces are specified as parameters

Discussed with and positive feedback from many
'commit' deraadt@
OK sthen@


# 1.176 08-Apr-2017 rpe

- localize the if, file and stat variables which also ensures that
variables are not named like commands.
- change test from [] to [[]]

OK tb@ halex@


# 1.175 07-Apr-2017 rpe

Minimize differences in ifstart() function between netstart and
install.sub which makes it easier to spot changes in the future.

- comments and formatting
- quotes on assignments are not needed (netstart)
- remove stray space in test (netstart)
- use $file variable with while-loop (netstart)
- although valid, instead of i use $i in arithmetic test (install.sub)

OK krw@, tb@
Looks good deraadt@


# 1.174 07-Apr-2017 rpe

Align comments of ifstart() function in netstart and install.sub.


# 1.173 07-Apr-2017 rpe

Align comments of stripcom() function in netstart and install.sub.


Revision tags: OPENBSD_6_1_BASE
# 1.172 06-Dec-2016 mpi

Do not lose the default route when netstart(8) is run a second time on
the interface pointed to by the default route.

Since the kernel no longer keep routes with dangling address pointer,
netstart(8) has to re-add the default route when the corresponding ifa
has been deleted and re-created.

deraadt@ points out that even if the previous semantic was not necessarily
better, a script like netstart(8) cannot totally fix the default route
problem.

Regression reported by and fix tested by Hrvoje Popovski.

ksh foo checked by halex@


# 1.171 27-Sep-2016 rzalamena

Delay switch(4) interface start up so it can attach virtual interfaces
like vether(4).

nits from and ok benno@, phessler@


# 1.170 09-Sep-2016 jasper

print a clear error message when not ran as root instead of just falling
through and try whatever it can do with the invoking user's perms

feedback/ok aja@ rpe@


Revision tags: OPENBSD_6_0_BASE
# 1.169 19-Jul-2016 mpi

Do not consider tap(4) a special interface and start if before other
pseudo-interfaces.

This unbreak vlan(4) on top of tap(4) since the refactoring to turn it
MP-safe.

ok claudio@, deraadt@


# 1.168 27-Mar-2016 sthen

Don't delete the 224/4 route in netstart, unless it's being done to ensure that
a -reject route can be added. Restores the ability to set an interface route
before daemons are started, lost during the previous simplification.
ok millert mpi


Revision tags: OPENBSD_5_9_BASE
# 1.167 29-Dec-2015 rpe

Remove backslash, not necessary after '&&'

OK halex@


# 1.166 29-Dec-2015 rpe

Replace last remaining `` with $()

OK halex@


# 1.165 18-Dec-2015 ajacoutot

Drop the now useless multicast setup comment.

prodded by tim@, ok mpi@


# 1.164 17-Dec-2015 ajacoutot

Simplify multicast option handling (10 less lines) by matching /etc/rc behavior
towards other YES|NO options and drop the error warning.


with and ok tim@, ok rpe@ on an earlier diff


# 1.163 05-Dec-2015 mpi

It does not make sense to insert a specific route for 224/4 when the
default one is good enough.

So merge rc.conf(8)'s 'multicast_router' and 'multicast_host' into a
single 'multicast'. If set to YES the reject route for 224/4 is not
inserted by netstart(8).

Manual bits from jmc@

ok henning@, ajacoutot@


# 1.162 12-Nov-2015 rpe

Changes to ifautostart():
- Rename function to ifv6autoconf() to make IPv6 relation clearer
- Localize and rename variables

OK krw@


# 1.161 12-Nov-2015 rpe

Changes to ifmstart():
- Change comments to make it clearer that ifmstart() takes two lists
of interface driver names (of which the second is optional) and not
the actual interface instances.
- Use localized variables and use slightly more verbose names.
- Use continue 2 to skip to the next hostname.if file.
- Use shell pattern @() instead of testing _sif individually.

OK krw@


# 1.160 12-Nov-2015 rpe

Changes to stripcom():
- Align comments with /etc/rc version
- Use localized variables
- Use safer "print -r --" instead of plain echo

Changes to ifstart():
- Tweak comment
- Add usage

OK krw@


# 1.159 01-Nov-2015 rpe

Start the rework of the /etc/netstart shell script.

General changes:
- apply a similar 'style' as used in the installer scripts
- improve comments to be more to the point, remove where code is obvious
- document usage of functions if they have arguments
- rename variables where it improves readability
- replace really old-school shell code with more contemporary idioms

Other changes:
- No need to care about "autoboot" because netstart doesn't inherit the
positional parameters from /etc/rc anymore. /etc/rc executes netstart
instead of sourcing it since r1.439.
- Use simpler for-loop to process list of interfaces with ifstart.

OK halex@


# 1.158 26-Oct-2015 rpe

The hostname variable is not used since r1.99. Remove it and use
stripcom() output directly with the hostname command.

OK deraadt@ krw@


# 1.157 23-Oct-2015 claudio

netstart bits for tap(4)


# 1.156 27-Sep-2015 sthen

Don't print output when setting autoconf on interfaces. Suggested by deraadt,
ok florian@ rpe@


# 1.155 13-Sep-2015 sthen

only print the "IPv6 autoconf" line if there are interfaces to configure
feedback/ok rpe


# 1.154 11-Sep-2015 sthen

Set "inet6 autoconf" individually on interfaces that have rtsol set in
hostname.if, previously netstart tried to configure them all at once
("ifconfig if0 if1 if2 inet6 autoconf"). From Delan Azabani, ok phessler@


Revision tags: OPENBSD_5_8_BASE
# 1.153 20-Jul-2015 rpe

Disable Strict Bourne shell mode for /etc/rc and /etc/netstart to be
able to use ksh syntax within these scripts. This way init doesn't
need to be changed, which starts /etc/rc using /bin/sh and people
can still use "sh /etc/netstart ifname".

Idea from and OK halex@
OK deraadt@ krw@ guenther@


# 1.152 19-Jul-2015 florian

Bring up pflow last as it might send with a source address that is on
any of the other interfaces.
OK deraadt, phessler, benno


# 1.151 19-Jul-2015 rpe

Always source rc.subr to be able to use the rc.conf parsing routine
to get the network related vars from rc.conf. This is even necessary
if netstart is run from within /etc/rc. Remove test of $INRC which
unintentionally evaluated always to true.

problem with previous change found by nigel@
OK sthen@ aja@ halex@


# 1.150 19-Jul-2015 ajacoutot

Revert 1.148 for now until I can talk to rpe@
It introduced a regression reported by nigel@


# 1.149 19-Jul-2015 rpe

Replace test command with [].

OK halex@ krw@


# 1.148 19-Jul-2015 rpe

Ensure, that we source rc.subr and parse rc.conf ONLY if we are not
inside /etc/rc.

With help from and OK halex@, ajacoutot@


# 1.147 18-Jul-2015 rpe

- remove trailing blanks introduced in previous commit
- no space in redirections like </foo or >$bar
- few other minor whitespaces

OK krw@


# 1.146 18-Jul-2015 rpe

Improve comments
- Add comments for functions
- Start comments with capital letters
- End comments with a full stop
- Allow comments to extend up to column 80

OK krw@


# 1.145 06-Jun-2015 florian

Allow rtsol keyword in hostname.if(5) with net.inet6.ip6.forwarding=1.
"inet6 autoconf" was working before and rtsol should behave the same.
OK phessler


Revision tags: OPENBSD_5_7_BASE
# 1.144 03-Dec-2014 florian

The kernel handles rtsol(8) functionality since some time now.
Treat rtsol in hostname.if as a keyword like dhcp and call ifconfig
inet6 autoconf.
"reads good" todd@
OK krw@ (who is *not* an IPv6 person), but I recruited him in his
capacity as an installer person.


# 1.143 28-Sep-2014 claudio

Revert 1.142. Without the down netstart will just print the ifconfig
output because it may end up just calling 'ifconfig $if'. This needs
to be done better and properly tested.


# 1.142 26-Sep-2014 halex

remove explicit 'down' of an interface before starting a dhcp request, thereby
avoiding annoying delays for some switch configurations

ok claudio@ deraadt@

i would add ok phessler@, but it was not valid without an ok krw@


Revision tags: OPENBSD_5_6_BASE
# 1.141 12-Jul-2014 stsp

Fix netstart after autoconf6 change so 'rtsol' lines in hostname.if work again.
found by pelikan@; ok pelikan@ henning@


# 1.140 12-Jul-2014 robert

Make rc.conf a parsed configuration file and stop sourcing it as a shell
script.
From now on rc.conf has a fixed syntax (key=val) and it is not allowed
to add anything to it besides the supported syntax, it all going to be
ignored.

discussed with and help from deraadt@ and halex@


Revision tags: OPENBSD_5_5_BASE
# 1.139 22-Aug-2013 mpi

Like for dhclient, do no create a route to alias addresses via 127.0.0.1.
Our stack is able to tell if the address is local or not.

ok todd@, krw@


Revision tags: OPENBSD_5_4_BASE
# 1.138 20-Mar-2013 todd

fix lies in netstart; replacement wording from halex@
pointed out by Ryan Kavannagh rak at debian dot org


Revision tags: OPENBSD_5_3_BASE
# 1.137 05-Dec-2012 rpe

remove "Invalid interface name" message
requested by krw@

ok halex@


# 1.136 02-Dec-2012 rpe

use the more compact version of the check for ifconfig'able interfaces
from install.sub

with feedback from and ok halex


# 1.135 02-Dec-2012 rpe

- remove isalphanumeric() and replace it with a shell pattern, that
tries a bit harder to identify invalid interface names and in
this case emit an error message.
- use [[ $1 == autoboot ]] to avoid a shell error message due to
possible spaces in first argument
- no change in functionality

discussed with krw and halex
ok ("I like this") krw


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.134 07-Oct-2011 deraadt

The new ypbind changes requires that the domainname be set before
rc.conf is run. There's no real downside.
ok aja


Revision tags: OPENBSD_5_0_BASE
# 1.133 07-Jul-2011 guenther

Eliminate some $? tests by rolling the command into the condition

ok halex@


# 1.132 26-May-2011 mpf

Add svlan(4) startup bits.
From markus@. OK naddy, claudio, reyk.


Revision tags: OPENBSD_4_9_BASE
# 1.131 09-Feb-2011 sobrado

fix an unbalanced parenthesis in a comment; while here, split the comment
in a better place to make it more readable.

ok jmc@ and miod@


Revision tags: OPENBSD_4_8_BASE
# 1.130 16-Jun-2010 todd

permit e.g. -inet6 syntax by slurping all lines not just some
noticed by rhsv6 at hushmail dot com, ok sthen@


Revision tags: OPENBSD_4_7_BASE
# 1.129 12-Jan-2010 henning

when setting up lo0 use 127.0.0.1/8 instead of 127.0.0.1 for clarity and
correctness. it's not 1992 any more, kids. ok mcbride dlg krw


# 1.128 10-Dec-2009 todd

o stop reordering ifconfig arguments (e.g. after 'up ..')
o only stop processing if inet or inet6 lines are malformed
o everything not a specially handled bit is passed to ifconfig unmangled
noticed by several after the move from bridgename.bridge0 -> hostname.bridge0
prodded by deraadt@, tested by and feedback from several
man page bits 'look fine' jmc@


# 1.127 22-Nov-2009 deraadt

Stop supporting bridgename.bridge* files, and move to hostname.bridge*
files. To cope with this change, read about the mv command.
ok claudio todd


# 1.126 17-Sep-2009 simon

change variable i to $i in an expression of ifstart() for consistency
with the rest of the file. no functional change.

feedback from sthen@, ok krw@


# 1.125 10-Jul-2009 jdixon

Delay creation of tun(4) interfaces until the underlying interface and
routes are available. This fixes usage for some OpenVPN users that start
it from hostname.tun*.

Tested by Johan Huldtgren. ok sthen@, johan@.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.124 25-Nov-2008 markus

delay /etc/netstart until IPv6-DAD (dup-address-detection) is completed.
ok fries, hshoexer, claudio


# 1.123 14-Aug-2008 sthen

Tools from /usr may not be used in netstart since it may be NFS-mounted
and not available at that time. Rewrite the hostname.if permission check
to use only /bin/ls and the shell. Requested by deraadt.

ok todd, "Twisted." deraadt


Revision tags: OPENBSD_4_4_BASE
# 1.122 23-Jul-2008 sthen

Prevent warning about insecure hostnames where no /etc/hostname.*
exists. From wcmaier@.

Check target of symbolic links to avoid noise at boot and in
seucrity output where you have several interfaces symlinked to one
config file.

"If you think this is the right thing to do" deraadt@


# 1.121 09-Jun-2008 todd

warn once not 3 times in case of a non existent file, discussed with deraadt
originally pointed out by Johan Torin


# 1.120 09-Jun-2008 deraadt

Ensure that hostname.* files are also re-chowned to root.wheel at each
boot as discussed with claudio while eating tasty donairs. ok todd


# 1.119 17-Apr-2008 deraadt

before using them, force hostname.* files to be unreadable by world
first version from todd, ok millert


Revision tags: OPENBSD_4_3_BASE
# 1.118 17-Jan-2008 brad

Execute rtsol after turning up trunk(4) and vlan(4) interfaces so they're
taken into consideration for rtsol.

ok reyk@ dlg@


# 1.117 09-Jan-2008 mpf

Do not bring up pfsync(4) before the working ruleset
has been loaded. Otherwise, states that are received during the
initial bulk update mismatch the correct pf-checksum and
do not attach to the rules.
Problem identified by david@. Fix done in collaboration.
OK henning@


Revision tags: OPENBSD_4_2_BASE
# 1.116 02-Aug-2007 david

move the delay for IPv6 DAD to after all interfaces have started
fixes problems with daemons being unable to bind to all addreses at boot
ok itojun@ hshoexer@


Revision tags: OPENBSD_4_1_BASE
# 1.115 15-Nov-2006 itojun

reject multicast packet without scope identifier specified.


Revision tags: OPENBSD_4_0_BASE
# 1.114 29-Jun-2006 todd

do not add an extra space; nwid and description come out wrong
fix as proposed by maja@, thanks!


Revision tags: OPENBSD_3_9_BASE
# 1.113 28-Dec-2005 david

nuke extra whitespace


# 1.112 06-Dec-2005 reyk

multicast_host=YES only works if a valid default gateway is available.
validate this condition and reject multicast traffic on failure.

ok todd@ naddy@


# 1.111 02-Nov-2005 todd

fix inspired by pr#4590
ok krw@


# 1.110 25-Oct-2005 todd

better logic from krw@:
- do not process mygate for v4 if dhcp
- do not process mygate for v6 if rtsol
this also makes the mygate processing logic more readable
ok krw@


# 1.109 14-Oct-2005 todd

add v6 support for /etc/mygate
ok deraadt@ mickey@ krw@
same functionality tested/ok'ed by by mickey, brad, matthieu, and me
with this one may now put a v6 IP in /etc/mygate on a separate line from
the v4 default gateway and netstart will do the right thing


# 1.108 12-Oct-2005 todd

shrink stripcom(), sync with install.sub
ok krw@


# 1.107 04-Oct-2005 todd

trunk must be started after physical ethernet devices, but before vlan.
populate ifmstart lines accordingly.
prodded/tested by brad@
ok reyk@


# 1.106 28-Sep-2005 todd

use eval consistently, fixes description quotes on rtsol and dhcp
fix inspired by and closes pr 4495
ok krw@


Revision tags: OPENBSD_3_8_BASE
# 1.105 22-May-2005 todd

Introduce 'ifmstart' to deal with starting multiple interfaces minus a list
of interfaces.

This reduces the netstart script by 174 chars, 13 words, and 19 lines, but
more importantly, makes it more simple and less cluttered should more special
case/orderings be needed.

ok brad@ and pr 4197 submitter, inspired by and closes pr 4197


# 1.104 04-Apr-2005 djm

unbreak; ok pval@


# 1.103 03-Apr-2005 deraadt

if dhcp is used to get an address on any interface, ignore /etc/mygate
ok krw
(this lets us do something rather cool with the zaurus in particular)


Revision tags: OPENBSD_3_7_BASE
# 1.102 04-Jan-2005 mcbride

Bring up the carp(4) interface before default route.

ok pascoe@ mpf@


# 1.101 30-Dec-2004 millert

Add a copy of stripcom so /etc/netstart can be run standalone again.
OK deraadt@


# 1.100 19-Dec-2004 millert

Allow comments in /etc/{myname,mygate,defaultdomain}; OK deraadt@


# 1.99 04-Dec-2004 itojun

remove "route $hostname 127.0.0.1" line. deraadt ok
*** please update /etc/netstart and test if it works ok for you ***


# 1.98 20-Oct-2004 deraadt

make all route commands use -qn; ok mcbride henning


Revision tags: OPENBSD_3_6_BASE
# 1.97 29-May-2004 deraadt

one last route command lacking -qn


Revision tags: OPENBSD_3_5_BASE
# 1.96 22-Mar-2004 mcbride

Make sure pfsync is brought up before carp.

ok deraadt@


# 1.95 13-Mar-2004 mcbride

Delay pfsync(4) configuration, as the syncif has to be configured in
advance. From Thorsten Lockert.


# 1.94 14-Jan-2004 deraadt

ok, it took quite a bit of prodding but itojun finally explained why the
extra sleep 1 is in here, and we came to the conclusion it is safe to
delete it. whee.


# 1.93 13-Jan-2004 deraadt

repair v6 lo0 documentation


# 1.92 11-Jan-2004 deraadt

add loopback routes late


# 1.91 09-Jan-2004 deraadt

create all routes with -q; markus ok


# 1.90 04-Dec-2003 millert

Need to do "ifconfig create" for bridge interfaces too.


# 1.89 03-Dec-2003 markus

add support for ifconfig clone; from netbsd; ok deraadt, henning


# 1.88 20-Oct-2003 david

delay carp initialization until after physical interfaces are configured
ok mcbride@ henning@ deraadt@ todd@


Revision tags: OPENBSD_3_4_BASE
# 1.87 27-Aug-2003 henning

only try to set hostname to what /etc/myname says if that file actually exists,
otherwise preserve `hostname`
netbooted machines can live perfectly fine without it; they get their hostname
earlier.

ok krw@ cedric@


Revision tags: OPENBSD_3_3_BASE
# 1.86 16-Feb-2003 krw

Fix up some DNS verbiage to make it consistant.

Fix up default route selection by

a) Forcing user to explicitly chose 'dhcp' as a mechanism for
specifying a default route, rather than guessing based on one or more
interfaces being configured by dhcp.

b) If the user specified default route does not work, re-present the
existing default route rather than losing it.

c) Move default route selection to after nameserver activation so the
user can specify a hostname as the default route.

Change /etc/netstart so that /etc/mygate wins if a default route was
already specified (i.e. by dhcp).

ok deraadt@.


Revision tags: OPENBSD_3_2_BASE
# 1.85 16-May-2002 todd

ignore non-existent cases where '$if' evaluates to '*'.
From Andr� Lucas <andre@ae-35.com>, fixes pr # 2658.
'Looks good' from miod@, millert@, and krw@.


Revision tags: OPENBSD_3_1_BASE
# 1.84 23-Feb-2002 deraadt

re-add support for $if expansion; hamajima@nagoya.ydc.co.jp


# 1.83 21-Feb-2002 miod

Change the network components initialization order.
Change from:
o all interfaces
o all bridges
o routes
to:
o physical interfaces
o routes
o gif and gre interfaces
o bridges

Fixeski PR #2400.
Manual page updates coming soon.
Ok angelos@ chris@ deraadt@


Revision tags: OPENBSD_3_0_BASE
# 1.82 31-Jul-2001 hugh

a space before a redirect


# 1.81 06-Jul-2001 angelos

Also, source /etc/rc.conf so we can pull in the
multicast_host/multicast_router settings; this is useful if one
flushes the routing table and re-initializes.

We really need a netconfig tool of sorts.


# 1.80 06-Jul-2001 angelos

Use "route -n show -inet" to determine the default multicast iface.


# 1.79 03-Jul-2001 deraadt

pull in rc.conf early so that pf(1) startup is right; tested by jasoni, comments from millert


# 1.78 30-May-2001 deraadt

Remove ipf. Darren Reed has interpreted his (old, new, whichever)
licence in a way that makes ipf not free according to the rules we
established over 5 years ago, at www.openbsd.org/goals.html (and those
same basic rules govern the other *BSD projects too). Specifically,
Darren says that modified versions are not permitted. But software
which OpenBSD uses and redistributes must be free to all (be they
people or companies), for any purpose they wish to use it, including
modification, use, peeing on, or even integration into baby mulching
machines or atomic bombs to be dropped on Australia. Furthermore, we
know of a number of companies using ipf with modification like us, who
are now in the same situation, and we hope that some of them will work
with us to fill this gap that now exists in OpenBSD (temporarily, we
hope).


Revision tags: OPENBSD_2_9_BASE
# 1.77 13-Mar-2001 deraadt

spelling; maurice@maurice.wan.nl


# 1.76 06-Feb-2001 todd

ignore blank lines in addition to comments
fixes pr#1660 from wilfried@telia.com .. Thanks!


# 1.75 10-Jan-2001 jason

support !command in bridgename.if files, too


# 1.74 27-Nov-2000 millert

Use -n to test if a variable is non-zero. Otherwise, if the variable's
contents start with a '-' test becomes unhappy (since it interprets it
as another option).


# 1.73 08-Nov-2000 todd

This fixes pr 1481, we now handle args > 6 in /etc/hostname.if in the
cases where we did not previously handle them.
Thanks to Scott Atwood <atwood@cs.stanford.edu> for reminding us of this.


Revision tags: OPENBSD_2_8_BASE
# 1.72 02-Sep-2000 todd

subtle bug .. global variables in a while loop need reset 'just incase'
With:
hostname.fxp0 having a last line of:
inet6 alias 3ffe:...
and hostname.gif0 having a first two lines of:
giftunnel 1.2.3.4
dest 1.2.4.3
We end up with the command:
ifconfig gif0 giftunnel alias 1.2.3.4 1.2.4.3
.. which is clearly wrong and fixed by this change


# 1.71 18-Jun-2000 todd

rc.conf now parses ${local_rcconf} internally; closes pr 1259


Revision tags: OPENBSD_2_7_BASE
# 1.70 08-May-2000 todd

fix dhcp 'NONE' ness from install to allow media parsing to work
.. ok deraadt@, millert@


# 1.69 21-Apr-2000 deraadt

rc.conf.local support, inspired by chuck yerkes


# 1.68 04-Apr-2000 millert

Remove the -E flag from ipf as it is implicitly enabled and using
the -E flag here causes the kernel to printf 'IP Filter: already
initialized'.


# 1.67 18-Mar-2000 deraadt

silence all extra route addition printouts


# 1.66 17-Mar-2000 itojun

correct reject route installations for IPv6. improve comments.


# 1.65 12-Mar-2000 itojun

disallow packets to malicious 6to4 prefix, based on
http://playground.iijlab.net/i-d/draft-itojun-ipv6-transition-abuse-00.txt


# 1.64 10-Mar-2000 todd

fix non behavior
with this `!' lines in /etc/hostname.* run even without certain lines
(like a comment) preceeding it.


# 1.63 10-Jan-2000 todd

allow arbitrary commands in /etc/hostname.* files if the line starts with '!'


# 1.62 02-Jan-2000 deraadt

rtsol case can configure the interface up, since it would be nice to finish
DAD before the actual rtsol(8) run happens later. and since it will rtsol,
it is going to be up in any case.


# 1.61 02-Jan-2000 itojun

one more indentation fix.


# 1.60 02-Jan-2000 itojun

indentation fix (todd's part)


# 1.59 02-Jan-2000 todd

fix rtsold case, reset cmd for each iteration!


# 1.58 02-Jan-2000 itojun

allow options after "rtsol".
XXX both "dhcp" and "rtsol" has keyword *down* at the end. is it okay?


# 1.57 02-Jan-2000 itojun

echo "IPv6 autoconf: interfaces" before invoking rtsol.
sleep for net.inet6.ip6.dad_count seconds to ensure that IPv6 DAD is completed.
TODO: rtsold (rc.conf line), manpage


# 1.56 02-Jan-2000 itojun

ipv6 autoconf on hosts (non-routers).

to do this,
1. in sysctl.conf, add these lines:
net.inet6.ip6.forwarding=0
net.inet6.ip6.accept_rtadv=1
2. in hostname.foo, add
rtsol

specifying two or more interfaces with "rtsol" may result in strange
behavior - ipv6 spec does not permit multi-interface node to be autoconfig'ed.


# 1.55 02-Jan-2000 todd

add to hostname.* parsing:
- multiple entries support (read: aliases)
- inet6 support
- support for comments (#)
(look for hostname.if(5) commit for syntax details)


# 1.54 31-Dec-1999 itojun

install IPv6 reject routes only if kernel is capable of IPv6.


# 1.53 09-Dec-1999 itojun

avoid transmitting invalid IPv6 packets out to the wire.


# 1.52 09-Dec-1999 itojun

do not perform IPv6 initialization for loopback interface.
MUST make lo0 up before any IPv6 operations.
it will be considered a pilot error if you don't.
(I prefer to have lo0 initialized automatically)


Revision tags: OPENBSD_2_6_BASE
# 1.51 01-Sep-1999 deraadt

support # characters in bridgename.* files; millert


# 1.50 01-Sep-1999 deraadt

cleanup parsing of hostname.* files, and seperate bridge control into
bridgename.* files; all documented in new hostname.if(5) and
bridgename.if(5) man pages


# 1.49 09-Aug-1999 angelos

Only parse/setup the hostname.foo file if interface foo exists (this
is useful for laptops with different ethernet cards etc.)


Revision tags: OPENBSD_2_5_BASE
# 1.48 29-Mar-1999 niklas

New multicast route setup style


# 1.47 26-Mar-1999 niklas

Add bridge interface handling


# 1.46 01-Mar-1999 millert

Add support in /etc/hostname.xxx for files of the format:
up [options]
Any of the following may or may not be set:
$name $mask $bcaddr $extras


# 1.45 28-Oct-1998 millert

Kill the awful hack used to match and split /etc/hostname.* We now use
a function, isalphanumeric, to determine whether an interface name is
likely to be valid. This means that things like /etc/hostname.le0.bak,
/etc/hostname.le0#, /etc/hostname.le0~, etc. will be ignored as they
should. There is no longer an implicate assumption that /etc/hostname.*
only contains a single '.'.


Revision tags: OPENBSD_2_4_BASE
# 1.44 06-Oct-1998 deraadt

move ipnat to end of netstart, to support dhcp+ipnat


# 1.43 18-Sep-1998 deraadt

apply media directives on dhcp interfaces


# 1.42 10-Sep-1998 marc

better way of handling dhcp client; Jason Ish <jbi130@mail.usask.ca>


# 1.41 08-Sep-1998 marc

dhcp client stuff. "Angelos D. Keromytis" <angelos@dsl.cis.upenn.edu>


# 1.40 24-Aug-1998 downsj

You can't use -interface default when there's no default gateway
set (yet). Use -interface $hostname if mygate doesn't exist so that
this actually works on routers.


# 1.39 04-Jul-1998 deraadt

put 224 route on default, to avoid a hostname lookup


# 1.38 22-May-1998 deraadt

use route -n, what the heck


Revision tags: OPENBSD_2_3_BASE
# 1.37 28-Mar-1998 deraadt

s/^nat/ipnat/


# 1.36 23-Feb-1998 niklas

remove trailing blank line


# 1.35 07-Feb-1998 deraadt

ipforward is in sysctl.conf now


# 1.34 21-Dec-1997 deraadt

ugh


# 1.33 20-Dec-1997 deraadt

ipforwarding option in rc.conf


# 1.32 29-Nov-1997 kstailey

NAT requires IPF


# 1.31 04-Nov-1997 deraadt

kill spaces at ends of lines; m4


Revision tags: OPENBSD_2_2_BASE
# 1.30 14-Oct-1997 deraadt

set hostname/domainname before running rc.conf; m4@umn.edu


# 1.29 04-Sep-1997 deraadt

fork netstart; new child is rc.conf


# 1.28 25-Aug-1997 millert

Explicately pass -host flag to route(8) to avoid confusion with networks.


# 1.27 19-Aug-1997 niklas

Add hook for rpc.lockd, make nfsd flags settable in netstart


# 1.26 31-Jul-1997 downsj

Make quotas optional; wedged into netstart for the time being.
/etc/rc.conf, anyone?


# 1.25 30-Jul-1997 deraadt

do not run routed by default


# 1.24 28-Jul-1997 kstailey

Move configuration of loopback interface to before all other interfaces.
Allows the use of local caching-only nameserver with no "nameserver"
entry in /etc/resolv.conf to configure a route between the hostname
and loopback.


# 1.23 25-Jul-1997 provos

earlier start of keymanagement


# 1.22 24-Jul-1997 deraadt

make amd use /tmp_mnt by default


# 1.21 22-Jul-1997 provos

start the photuris daemon per default. hilfe.


# 1.20 17-Jun-1997 niklas

Put in hooks to start ypserv with flags


# 1.19 17-Jun-1997 niklas

Put in hooks to start rpc.yppasswdd with flags


Revision tags: OPENBSD_2_1_BASE
# 1.18 15-Apr-1997 deraadt

kill route flush until .. hmm kernel routing socket bug or something


# 1.17 09-Apr-1997 kstailey

add NAT startup


# 1.16 07-Apr-1997 rees

flush all old routes before adding new interfaces or routes.
ref: netbsd pr3228/misc, Matthias Scheler


# 1.15 03-Mar-1997 downsj

fix typo


# 1.14 11-Feb-1997 deraadt

add default route before fiddling with loopback route to avoid DNS problems; m4@umn.edu, #97


# 1.13 03-Feb-1997 deraadt

do ifaliases after /usr/bin exists in nfs diskless env; pr#77, matthieu@laas.fr


# 1.12 02-Nov-1996 deraadt

timed off by default


Revision tags: OPENBSD_2_0_BASE
# 1.11 23-Sep-1996 deraadt

rfc1323 variable


# 1.10 04-Sep-1996 deraadt

control portmap, inetd, and lpd from netstart; idea from tqbf@enteract.com


# 1.9 27-Aug-1996 deraadt

224.0.0.0 not 0.0.0.224; from peter@demon.net


# 1.8 18-Jun-1996 deraadt

move std stuff from rc.local to rc


# 1.7 16-Jun-1996 deraadt

install sample commented /etc/ifaliases file; which can now contain #
comments and blank lines. new format is "interface address netmask"
(yes, i changed the order of the entries). inspired by netbsd pr#2474;
gillhaa@ghost.whirlpool.com


# 1.6 02-Jun-1996 tholo

Install a multicast route by default


# 1.5 26-May-1996 deraadt

sync & label


# 1.4 09-Jan-1996 dm

added IP filter to netstat/rc and put examples in /usr/share/ipf


# 1.3 30-Dec-1995 deraadt

from netbsd: start mrouted like routed


# 1.2 18-Dec-1995 deraadt

/etc/ifaliases support by randy@zyzzyva.com


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.210 21-Dec-2020 krw

Avoid issuing pointless 'ifconfig <if> up' when processing 'dhcp' in
hostname.if files. dhclient(8) does that itself. Part of the
"further script optimizations" promised in r1.200 of netstart.

Tested & ok gnezdo@


# 1.209 29-Nov-2020 tb

Fix previous: use correct version of netstart and installer bits.


# 1.208 29-Nov-2020 deraadt

Add support for !command to mygate, so that netstart has a late opportunity
to perform network configuration (for example, "!route source -ifp em0")
Split mygate and myname manual pages (how did anyone ever believe these
are related), and perform hostname configuration much earlier in rc.
discussed with benno, claudio, jmc, etc etc, last version of !command
parser by tb


# 1.207 08-Nov-2020 jmc

no more mobileip;
ok claudio deraadt


Revision tags: OPENBSD_6_8_BASE
# 1.206 21-Jun-2020 dlg

start wg with the other interfaces that rely on routing being up.

from Matt Dunwoodie and Jason A. Donenfeld

ok deraadt@


# 1.205 22-May-2020 kn

Revert the following commit as it breaks hostname.if(5) lines with a
backslash at the end for line continuation

Breaking long lines into multiple ones must still be possible and does
require to treat the backslash as an escape character.

Breakage reported by Mark Patruck <mark at wrapped dot cx >, thanks!

---
distrib/miniroot/install.sub revision 1.1151
etc/netstart revision 1.203
date: 2020/05/21 11:54:41; author: kn; state: Exp; lines: +2 -2;
Do not treat backslashe as an escape character in hostname.if(5) lines

ifstart() should always pass such lines unaltered, especially if they
contain "nwid" or "description" lines with arbitrary strings.

<bsdlisten at gmail dot com> reported SSIDs such as "Mike's" during
installation end as broken; this was because the installer escaped
the single quote using backslashes which ended up being treated as
escape characters much later during hostname.if parsing in netstart(8).

Ok deraadt


# 1.204 21-May-2020 kn

Fix stripcom() description wrt. comments not on their own line

Neither netstart's nor install.sub's (subtly different) implementations
remove trailing comments on lines not starting as a comment, e.g.,
lines like "up #not down" go through unaltered and without "#not down"
being removed.

Only lines *beginning* with the comment sign ("#") are stripped.

No functional change, just updating function descriptions.


# 1.203 21-May-2020 kn

Do not treat backslashe as an escape character in hostname.if(5) lines

ifstart() should always pass such lines unaltered, especially if they
contain "nwid" or "description" lines with arbitrary strings.

<bsdlisten at gmail dot com> reported SSIDs such as "Mike's" during
installation end as broken; this was because the installer escaped
the single quote using backslashes which ended up being treated as
escape characters much later during hostname.if parsing in netstart(8).

Ok deraadt


Revision tags: OPENBSD_6_7_BASE
# 1.202 15-Jan-2020 kn

Do not redirect already quiet stdout for IPv6 reject routes

"route -q" already silences all standard output; if it still prints
something, that's a bug to fix in route.

OK bluhm


# 1.201 25-Oct-2019 dlg

handle aggr(4) in the same way as trunk(4)

from brad@
ok bluhm@ claudio@ deraadt@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.200 29-Aug-2018 krw

Historically /etc/netstart (and the equivalent code in the install
script) did 'ifconfig <if> down' before starting dhclient(8). This was
a way of ensuring old running copies of dhclient were killed before a
new one started. Current dhclient does not need this assist, so change
"ifconfig <if> down" to "ifconfig <if> up" pending further script
optimizations.

Similar to a 2014 attempt by halex@. Prompted by a misc@ report
from Kristjan Komlosi reporting hanging diskless setups.

ok halex@ kn@


# 1.199 08-Jul-2018 tb

netstart is used during system start, but also interactively.
Show proper error message if a regular user executes netstart.
Only do the privilege check if the id binary is available,
which might not be the case during diskless system startup.

ok deraadt, jasper, jca, krw, rpe (who wrote the same diff), sthen


# 1.198 28-Apr-2018 rpe

Add a proper usage() function.

Suggested by and OK jmc.
OK tb


Revision tags: OPENBSD_6_3_BASE
# 1.197 04-Mar-2018 jmc

when -n is used, no need to spit out "Missing parameters." before
displaying usage();

ok tb


# 1.196 03-Mar-2018 landry

Lowercase 'usage' and group -n with interface in it.
From jmc@, ok tb@


# 1.195 21-Feb-2018 rpe

Tweak comments.

OK tb


# 1.194 19-Feb-2018 rpe

Write warning/error messages to stderr and end them with a fullstop.

OK tb


# 1.193 19-Feb-2018 rpe

- use specific patterns when looping over /etc/hostname.if files
to skip backup or temp files.
- test if the patterns matched actual files
- warn if ifcreate() fails on an interface and continue with the
subsequent interfaces in the list instead of return'ing

OK dlg sthen tb


# 1.192 17-Feb-2018 rpe

- Add descriptions for the new functions ifcreate() and vifscreate()
- In ifcreate() use the exit code of the {} block directly
- In vifscreate(), use the ifconfig -C output directly in the for _vif loop
- Remove superfluous and somewhat confusing comment

OK dlg kn sthen


# 1.191 14-Feb-2018 dlg

create virtual interfaces before starting all interface config.

this resolves an ordering problem when adding pseudo interfaces to bridges

tweaks from kn@
ok mpi@ sthen@


# 1.190 10-Feb-2018 claudio

Remove some special IPv4 in IPv6 mapped prefixes that are already rejected
by the ::0.0.0.0/96 reject route added to deny all IPv4 mapped addresses.
Makes the inet6 routing table almost fit in one screen.
OK benno@


# 1.189 10-Feb-2018 florian

Load RFC 7217 key material and generate if it does not already exist.

Add soii.key to changelist (pointed out by semarie) and mtree/special
(suggest by Craig Skinner).

OK naddy, sthen, rpe, tb


# 1.188 06-Feb-2018 tb

If -n is given, the netstart script should not (try to) set the default
route(s). Simply print the command(s) to be issued instead.

tweak & ok rpe


# 1.187 12-Nov-2017 tb

Remove HN_DIR variable and expand it in the only place it was used. It
currently serves no purpose.

ok rpe, agreement from deraadt and halex


Revision tags: OPENBSD_6_2_BASE
# 1.186 25-Jul-2017 rpe

Finally remove backwards compat code to support the 'rtsol' keyword
in hostname.if(5)

OK mpi@ deraadt@ florian@
OK jmc@ from doc perspective


# 1.185 21-Jul-2017 rpe

Align ifstart() in netstart and install.sub.

- in netstart, rename _file to _hn referencing hostname.if files
- in install.sub switch ifstart() to be used with _if instead of
_hn as parameter

ok krw@ tb@


# 1.184 28-May-2017 awolk

etc/netstart: use colon separator instead of dot with chown

OK jung@, deraadt@, jmc@


# 1.183 07-May-2017 rpe

Change test from [] to [[]] and simplify pattern.

OK tb@, krw@ (for [[]])
Feedback and OK halex@


# 1.182 07-May-2017 rpe

Replace hardcoded script name with ${0##*/}

OK tb@ halex@


# 1.181 01-May-2017 rpe

Revert r1.170 and remove the id==0 check.
The id binary is not available in nfs diskless setups at this point.

reported by Andreas Kusalananda, thanks.
discussed with deraadt@


# 1.180 01-May-2017 rpe

Remove last remnants of rtsol. IPv6 autoconfiguration of interfaces is now
done in ifstart(). Remove ipv6autoconf() and replace rtsolif with a boolean
variable V6_AUTOCONF. Replace dhcpif with a boolean variable V4_DHCPCONF.
Both are later used in defaultroute() to decide whether or not to configre
defaultroutes from /etc/mygate.

OK krw@


# 1.179 30-Apr-2017 mpi

Do not try to delete a default route before adding it.

Now that route are automatically G/C with the address they are attached
to there's no reason to duplicate the kernel's job.

Fix a regression introduced with multipath default routes.

ok deraadt@


# 1.178 25-Apr-2017 rpe

Unbreak netstart for multiple inteface configurations like trunk
or carp. Ensure that the noglob option is disabled at the end of
parse_hn_line() and ifstart().

Reported by Christer Solskogen and Stefan Wollny, thanks!


# 1.177 24-Apr-2017 rpe

Introduce a new function parse_hn_line() that replaces the existing
hostname.if(5) parsing code in ifstart().
Add a -n option to netstart to only print the interface configuration
commands instead of executing them.
Add a HN_DIR variable, that points to the directory of the hostname.if
files (default /etc) that allows for future regression tests.

- add new parse_hn_line() function
- change ifstart()
- rename $if to $_if
- don't ifconfig or ifconfig create if -n option is used
- replace hostname.if(5) parsing code with new parse_hn_line()
- just print configuration commands if -n option is used
- autoconf now happens in ifstart(), remove ifv6autoconf()
- introduce HN_DIR variable for the hostname.if file location
- add handling of the -n option to only print config commands
- ensure -n is only used if interfaces are specified as parameters

Discussed with and positive feedback from many
'commit' deraadt@
OK sthen@


# 1.176 08-Apr-2017 rpe

- localize the if, file and stat variables which also ensures that
variables are not named like commands.
- change test from [] to [[]]

OK tb@ halex@


# 1.175 07-Apr-2017 rpe

Minimize differences in ifstart() function between netstart and
install.sub which makes it easier to spot changes in the future.

- comments and formatting
- quotes on assignments are not needed (netstart)
- remove stray space in test (netstart)
- use $file variable with while-loop (netstart)
- although valid, instead of i use $i in arithmetic test (install.sub)

OK krw@, tb@
Looks good deraadt@


# 1.174 07-Apr-2017 rpe

Align comments of ifstart() function in netstart and install.sub.


# 1.173 07-Apr-2017 rpe

Align comments of stripcom() function in netstart and install.sub.


Revision tags: OPENBSD_6_1_BASE
# 1.172 06-Dec-2016 mpi

Do not lose the default route when netstart(8) is run a second time on
the interface pointed to by the default route.

Since the kernel no longer keep routes with dangling address pointer,
netstart(8) has to re-add the default route when the corresponding ifa
has been deleted and re-created.

deraadt@ points out that even if the previous semantic was not necessarily
better, a script like netstart(8) cannot totally fix the default route
problem.

Regression reported by and fix tested by Hrvoje Popovski.

ksh foo checked by halex@


# 1.171 27-Sep-2016 rzalamena

Delay switch(4) interface start up so it can attach virtual interfaces
like vether(4).

nits from and ok benno@, phessler@


# 1.170 09-Sep-2016 jasper

print a clear error message when not ran as root instead of just falling
through and try whatever it can do with the invoking user's perms

feedback/ok aja@ rpe@


Revision tags: OPENBSD_6_0_BASE
# 1.169 19-Jul-2016 mpi

Do not consider tap(4) a special interface and start if before other
pseudo-interfaces.

This unbreak vlan(4) on top of tap(4) since the refactoring to turn it
MP-safe.

ok claudio@, deraadt@


# 1.168 27-Mar-2016 sthen

Don't delete the 224/4 route in netstart, unless it's being done to ensure that
a -reject route can be added. Restores the ability to set an interface route
before daemons are started, lost during the previous simplification.
ok millert mpi


Revision tags: OPENBSD_5_9_BASE
# 1.167 29-Dec-2015 rpe

Remove backslash, not necessary after '&&'

OK halex@


# 1.166 29-Dec-2015 rpe

Replace last remaining `` with $()

OK halex@


# 1.165 18-Dec-2015 ajacoutot

Drop the now useless multicast setup comment.

prodded by tim@, ok mpi@


# 1.164 17-Dec-2015 ajacoutot

Simplify multicast option handling (10 less lines) by matching /etc/rc behavior
towards other YES|NO options and drop the error warning.


with and ok tim@, ok rpe@ on an earlier diff


# 1.163 05-Dec-2015 mpi

It does not make sense to insert a specific route for 224/4 when the
default one is good enough.

So merge rc.conf(8)'s 'multicast_router' and 'multicast_host' into a
single 'multicast'. If set to YES the reject route for 224/4 is not
inserted by netstart(8).

Manual bits from jmc@

ok henning@, ajacoutot@


# 1.162 12-Nov-2015 rpe

Changes to ifautostart():
- Rename function to ifv6autoconf() to make IPv6 relation clearer
- Localize and rename variables

OK krw@


# 1.161 12-Nov-2015 rpe

Changes to ifmstart():
- Change comments to make it clearer that ifmstart() takes two lists
of interface driver names (of which the second is optional) and not
the actual interface instances.
- Use localized variables and use slightly more verbose names.
- Use continue 2 to skip to the next hostname.if file.
- Use shell pattern @() instead of testing _sif individually.

OK krw@


# 1.160 12-Nov-2015 rpe

Changes to stripcom():
- Align comments with /etc/rc version
- Use localized variables
- Use safer "print -r --" instead of plain echo

Changes to ifstart():
- Tweak comment
- Add usage

OK krw@


# 1.159 01-Nov-2015 rpe

Start the rework of the /etc/netstart shell script.

General changes:
- apply a similar 'style' as used in the installer scripts
- improve comments to be more to the point, remove where code is obvious
- document usage of functions if they have arguments
- rename variables where it improves readability
- replace really old-school shell code with more contemporary idioms

Other changes:
- No need to care about "autoboot" because netstart doesn't inherit the
positional parameters from /etc/rc anymore. /etc/rc executes netstart
instead of sourcing it since r1.439.
- Use simpler for-loop to process list of interfaces with ifstart.

OK halex@


# 1.158 26-Oct-2015 rpe

The hostname variable is not used since r1.99. Remove it and use
stripcom() output directly with the hostname command.

OK deraadt@ krw@


# 1.157 23-Oct-2015 claudio

netstart bits for tap(4)


# 1.156 27-Sep-2015 sthen

Don't print output when setting autoconf on interfaces. Suggested by deraadt,
ok florian@ rpe@


# 1.155 13-Sep-2015 sthen

only print the "IPv6 autoconf" line if there are interfaces to configure
feedback/ok rpe


# 1.154 11-Sep-2015 sthen

Set "inet6 autoconf" individually on interfaces that have rtsol set in
hostname.if, previously netstart tried to configure them all at once
("ifconfig if0 if1 if2 inet6 autoconf"). From Delan Azabani, ok phessler@


Revision tags: OPENBSD_5_8_BASE
# 1.153 20-Jul-2015 rpe

Disable Strict Bourne shell mode for /etc/rc and /etc/netstart to be
able to use ksh syntax within these scripts. This way init doesn't
need to be changed, which starts /etc/rc using /bin/sh and people
can still use "sh /etc/netstart ifname".

Idea from and OK halex@
OK deraadt@ krw@ guenther@


# 1.152 19-Jul-2015 florian

Bring up pflow last as it might send with a source address that is on
any of the other interfaces.
OK deraadt, phessler, benno


# 1.151 19-Jul-2015 rpe

Always source rc.subr to be able to use the rc.conf parsing routine
to get the network related vars from rc.conf. This is even necessary
if netstart is run from within /etc/rc. Remove test of $INRC which
unintentionally evaluated always to true.

problem with previous change found by nigel@
OK sthen@ aja@ halex@


# 1.150 19-Jul-2015 ajacoutot

Revert 1.148 for now until I can talk to rpe@
It introduced a regression reported by nigel@


# 1.149 19-Jul-2015 rpe

Replace test command with [].

OK halex@ krw@


# 1.148 19-Jul-2015 rpe

Ensure, that we source rc.subr and parse rc.conf ONLY if we are not
inside /etc/rc.

With help from and OK halex@, ajacoutot@


# 1.147 18-Jul-2015 rpe

- remove trailing blanks introduced in previous commit
- no space in redirections like </foo or >$bar
- few other minor whitespaces

OK krw@


# 1.146 18-Jul-2015 rpe

Improve comments
- Add comments for functions
- Start comments with capital letters
- End comments with a full stop
- Allow comments to extend up to column 80

OK krw@


# 1.145 06-Jun-2015 florian

Allow rtsol keyword in hostname.if(5) with net.inet6.ip6.forwarding=1.
"inet6 autoconf" was working before and rtsol should behave the same.
OK phessler


Revision tags: OPENBSD_5_7_BASE
# 1.144 03-Dec-2014 florian

The kernel handles rtsol(8) functionality since some time now.
Treat rtsol in hostname.if as a keyword like dhcp and call ifconfig
inet6 autoconf.
"reads good" todd@
OK krw@ (who is *not* an IPv6 person), but I recruited him in his
capacity as an installer person.


# 1.143 28-Sep-2014 claudio

Revert 1.142. Without the down netstart will just print the ifconfig
output because it may end up just calling 'ifconfig $if'. This needs
to be done better and properly tested.


# 1.142 26-Sep-2014 halex

remove explicit 'down' of an interface before starting a dhcp request, thereby
avoiding annoying delays for some switch configurations

ok claudio@ deraadt@

i would add ok phessler@, but it was not valid without an ok krw@


Revision tags: OPENBSD_5_6_BASE
# 1.141 12-Jul-2014 stsp

Fix netstart after autoconf6 change so 'rtsol' lines in hostname.if work again.
found by pelikan@; ok pelikan@ henning@


# 1.140 12-Jul-2014 robert

Make rc.conf a parsed configuration file and stop sourcing it as a shell
script.
From now on rc.conf has a fixed syntax (key=val) and it is not allowed
to add anything to it besides the supported syntax, it all going to be
ignored.

discussed with and help from deraadt@ and halex@


Revision tags: OPENBSD_5_5_BASE
# 1.139 22-Aug-2013 mpi

Like for dhclient, do no create a route to alias addresses via 127.0.0.1.
Our stack is able to tell if the address is local or not.

ok todd@, krw@


Revision tags: OPENBSD_5_4_BASE
# 1.138 20-Mar-2013 todd

fix lies in netstart; replacement wording from halex@
pointed out by Ryan Kavannagh rak at debian dot org


Revision tags: OPENBSD_5_3_BASE
# 1.137 05-Dec-2012 rpe

remove "Invalid interface name" message
requested by krw@

ok halex@


# 1.136 02-Dec-2012 rpe

use the more compact version of the check for ifconfig'able interfaces
from install.sub

with feedback from and ok halex


# 1.135 02-Dec-2012 rpe

- remove isalphanumeric() and replace it with a shell pattern, that
tries a bit harder to identify invalid interface names and in
this case emit an error message.
- use [[ $1 == autoboot ]] to avoid a shell error message due to
possible spaces in first argument
- no change in functionality

discussed with krw and halex
ok ("I like this") krw


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.134 07-Oct-2011 deraadt

The new ypbind changes requires that the domainname be set before
rc.conf is run. There's no real downside.
ok aja


Revision tags: OPENBSD_5_0_BASE
# 1.133 07-Jul-2011 guenther

Eliminate some $? tests by rolling the command into the condition

ok halex@


# 1.132 26-May-2011 mpf

Add svlan(4) startup bits.
From markus@. OK naddy, claudio, reyk.


Revision tags: OPENBSD_4_9_BASE
# 1.131 09-Feb-2011 sobrado

fix an unbalanced parenthesis in a comment; while here, split the comment
in a better place to make it more readable.

ok jmc@ and miod@


Revision tags: OPENBSD_4_8_BASE
# 1.130 16-Jun-2010 todd

permit e.g. -inet6 syntax by slurping all lines not just some
noticed by rhsv6 at hushmail dot com, ok sthen@


Revision tags: OPENBSD_4_7_BASE
# 1.129 12-Jan-2010 henning

when setting up lo0 use 127.0.0.1/8 instead of 127.0.0.1 for clarity and
correctness. it's not 1992 any more, kids. ok mcbride dlg krw


# 1.128 10-Dec-2009 todd

o stop reordering ifconfig arguments (e.g. after 'up ..')
o only stop processing if inet or inet6 lines are malformed
o everything not a specially handled bit is passed to ifconfig unmangled
noticed by several after the move from bridgename.bridge0 -> hostname.bridge0
prodded by deraadt@, tested by and feedback from several
man page bits 'look fine' jmc@


# 1.127 22-Nov-2009 deraadt

Stop supporting bridgename.bridge* files, and move to hostname.bridge*
files. To cope with this change, read about the mv command.
ok claudio todd


# 1.126 17-Sep-2009 simon

change variable i to $i in an expression of ifstart() for consistency
with the rest of the file. no functional change.

feedback from sthen@, ok krw@


# 1.125 10-Jul-2009 jdixon

Delay creation of tun(4) interfaces until the underlying interface and
routes are available. This fixes usage for some OpenVPN users that start
it from hostname.tun*.

Tested by Johan Huldtgren. ok sthen@, johan@.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.124 25-Nov-2008 markus

delay /etc/netstart until IPv6-DAD (dup-address-detection) is completed.
ok fries, hshoexer, claudio


# 1.123 14-Aug-2008 sthen

Tools from /usr may not be used in netstart since it may be NFS-mounted
and not available at that time. Rewrite the hostname.if permission check
to use only /bin/ls and the shell. Requested by deraadt.

ok todd, "Twisted." deraadt


Revision tags: OPENBSD_4_4_BASE
# 1.122 23-Jul-2008 sthen

Prevent warning about insecure hostnames where no /etc/hostname.*
exists. From wcmaier@.

Check target of symbolic links to avoid noise at boot and in
seucrity output where you have several interfaces symlinked to one
config file.

"If you think this is the right thing to do" deraadt@


# 1.121 09-Jun-2008 todd

warn once not 3 times in case of a non existent file, discussed with deraadt
originally pointed out by Johan Torin


# 1.120 09-Jun-2008 deraadt

Ensure that hostname.* files are also re-chowned to root.wheel at each
boot as discussed with claudio while eating tasty donairs. ok todd


# 1.119 17-Apr-2008 deraadt

before using them, force hostname.* files to be unreadable by world
first version from todd, ok millert


Revision tags: OPENBSD_4_3_BASE
# 1.118 17-Jan-2008 brad

Execute rtsol after turning up trunk(4) and vlan(4) interfaces so they're
taken into consideration for rtsol.

ok reyk@ dlg@


# 1.117 09-Jan-2008 mpf

Do not bring up pfsync(4) before the working ruleset
has been loaded. Otherwise, states that are received during the
initial bulk update mismatch the correct pf-checksum and
do not attach to the rules.
Problem identified by david@. Fix done in collaboration.
OK henning@


Revision tags: OPENBSD_4_2_BASE
# 1.116 02-Aug-2007 david

move the delay for IPv6 DAD to after all interfaces have started
fixes problems with daemons being unable to bind to all addreses at boot
ok itojun@ hshoexer@


Revision tags: OPENBSD_4_1_BASE
# 1.115 15-Nov-2006 itojun

reject multicast packet without scope identifier specified.


Revision tags: OPENBSD_4_0_BASE
# 1.114 29-Jun-2006 todd

do not add an extra space; nwid and description come out wrong
fix as proposed by maja@, thanks!


Revision tags: OPENBSD_3_9_BASE
# 1.113 28-Dec-2005 david

nuke extra whitespace


# 1.112 06-Dec-2005 reyk

multicast_host=YES only works if a valid default gateway is available.
validate this condition and reject multicast traffic on failure.

ok todd@ naddy@


# 1.111 02-Nov-2005 todd

fix inspired by pr#4590
ok krw@


# 1.110 25-Oct-2005 todd

better logic from krw@:
- do not process mygate for v4 if dhcp
- do not process mygate for v6 if rtsol
this also makes the mygate processing logic more readable
ok krw@


# 1.109 14-Oct-2005 todd

add v6 support for /etc/mygate
ok deraadt@ mickey@ krw@
same functionality tested/ok'ed by by mickey, brad, matthieu, and me
with this one may now put a v6 IP in /etc/mygate on a separate line from
the v4 default gateway and netstart will do the right thing


# 1.108 12-Oct-2005 todd

shrink stripcom(), sync with install.sub
ok krw@


# 1.107 04-Oct-2005 todd

trunk must be started after physical ethernet devices, but before vlan.
populate ifmstart lines accordingly.
prodded/tested by brad@
ok reyk@


# 1.106 28-Sep-2005 todd

use eval consistently, fixes description quotes on rtsol and dhcp
fix inspired by and closes pr 4495
ok krw@


Revision tags: OPENBSD_3_8_BASE
# 1.105 22-May-2005 todd

Introduce 'ifmstart' to deal with starting multiple interfaces minus a list
of interfaces.

This reduces the netstart script by 174 chars, 13 words, and 19 lines, but
more importantly, makes it more simple and less cluttered should more special
case/orderings be needed.

ok brad@ and pr 4197 submitter, inspired by and closes pr 4197


# 1.104 04-Apr-2005 djm

unbreak; ok pval@


# 1.103 03-Apr-2005 deraadt

if dhcp is used to get an address on any interface, ignore /etc/mygate
ok krw
(this lets us do something rather cool with the zaurus in particular)


Revision tags: OPENBSD_3_7_BASE
# 1.102 04-Jan-2005 mcbride

Bring up the carp(4) interface before default route.

ok pascoe@ mpf@


# 1.101 30-Dec-2004 millert

Add a copy of stripcom so /etc/netstart can be run standalone again.
OK deraadt@


# 1.100 19-Dec-2004 millert

Allow comments in /etc/{myname,mygate,defaultdomain}; OK deraadt@


# 1.99 04-Dec-2004 itojun

remove "route $hostname 127.0.0.1" line. deraadt ok
*** please update /etc/netstart and test if it works ok for you ***


# 1.98 20-Oct-2004 deraadt

make all route commands use -qn; ok mcbride henning


Revision tags: OPENBSD_3_6_BASE
# 1.97 29-May-2004 deraadt

one last route command lacking -qn


Revision tags: OPENBSD_3_5_BASE
# 1.96 22-Mar-2004 mcbride

Make sure pfsync is brought up before carp.

ok deraadt@


# 1.95 13-Mar-2004 mcbride

Delay pfsync(4) configuration, as the syncif has to be configured in
advance. From Thorsten Lockert.


# 1.94 14-Jan-2004 deraadt

ok, it took quite a bit of prodding but itojun finally explained why the
extra sleep 1 is in here, and we came to the conclusion it is safe to
delete it. whee.


# 1.93 13-Jan-2004 deraadt

repair v6 lo0 documentation


# 1.92 11-Jan-2004 deraadt

add loopback routes late


# 1.91 09-Jan-2004 deraadt

create all routes with -q; markus ok


# 1.90 04-Dec-2003 millert

Need to do "ifconfig create" for bridge interfaces too.


# 1.89 03-Dec-2003 markus

add support for ifconfig clone; from netbsd; ok deraadt, henning


# 1.88 20-Oct-2003 david

delay carp initialization until after physical interfaces are configured
ok mcbride@ henning@ deraadt@ todd@


Revision tags: OPENBSD_3_4_BASE
# 1.87 27-Aug-2003 henning

only try to set hostname to what /etc/myname says if that file actually exists,
otherwise preserve `hostname`
netbooted machines can live perfectly fine without it; they get their hostname
earlier.

ok krw@ cedric@


Revision tags: OPENBSD_3_3_BASE
# 1.86 16-Feb-2003 krw

Fix up some DNS verbiage to make it consistant.

Fix up default route selection by

a) Forcing user to explicitly chose 'dhcp' as a mechanism for
specifying a default route, rather than guessing based on one or more
interfaces being configured by dhcp.

b) If the user specified default route does not work, re-present the
existing default route rather than losing it.

c) Move default route selection to after nameserver activation so the
user can specify a hostname as the default route.

Change /etc/netstart so that /etc/mygate wins if a default route was
already specified (i.e. by dhcp).

ok deraadt@.


Revision tags: OPENBSD_3_2_BASE
# 1.85 16-May-2002 todd

ignore non-existent cases where '$if' evaluates to '*'.
From Andr� Lucas <andre@ae-35.com>, fixes pr # 2658.
'Looks good' from miod@, millert@, and krw@.


Revision tags: OPENBSD_3_1_BASE
# 1.84 23-Feb-2002 deraadt

re-add support for $if expansion; hamajima@nagoya.ydc.co.jp


# 1.83 21-Feb-2002 miod

Change the network components initialization order.
Change from:
o all interfaces
o all bridges
o routes
to:
o physical interfaces
o routes
o gif and gre interfaces
o bridges

Fixeski PR #2400.
Manual page updates coming soon.
Ok angelos@ chris@ deraadt@


Revision tags: OPENBSD_3_0_BASE
# 1.82 31-Jul-2001 hugh

a space before a redirect


# 1.81 06-Jul-2001 angelos

Also, source /etc/rc.conf so we can pull in the
multicast_host/multicast_router settings; this is useful if one
flushes the routing table and re-initializes.

We really need a netconfig tool of sorts.


# 1.80 06-Jul-2001 angelos

Use "route -n show -inet" to determine the default multicast iface.


# 1.79 03-Jul-2001 deraadt

pull in rc.conf early so that pf(1) startup is right; tested by jasoni, comments from millert


# 1.78 30-May-2001 deraadt

Remove ipf. Darren Reed has interpreted his (old, new, whichever)
licence in a way that makes ipf not free according to the rules we
established over 5 years ago, at www.openbsd.org/goals.html (and those
same basic rules govern the other *BSD projects too). Specifically,
Darren says that modified versions are not permitted. But software
which OpenBSD uses and redistributes must be free to all (be they
people or companies), for any purpose they wish to use it, including
modification, use, peeing on, or even integration into baby mulching
machines or atomic bombs to be dropped on Australia. Furthermore, we
know of a number of companies using ipf with modification like us, who
are now in the same situation, and we hope that some of them will work
with us to fill this gap that now exists in OpenBSD (temporarily, we
hope).


Revision tags: OPENBSD_2_9_BASE
# 1.77 13-Mar-2001 deraadt

spelling; maurice@maurice.wan.nl


# 1.76 06-Feb-2001 todd

ignore blank lines in addition to comments
fixes pr#1660 from wilfried@telia.com .. Thanks!


# 1.75 10-Jan-2001 jason

support !command in bridgename.if files, too


# 1.74 27-Nov-2000 millert

Use -n to test if a variable is non-zero. Otherwise, if the variable's
contents start with a '-' test becomes unhappy (since it interprets it
as another option).


# 1.73 08-Nov-2000 todd

This fixes pr 1481, we now handle args > 6 in /etc/hostname.if in the
cases where we did not previously handle them.
Thanks to Scott Atwood <atwood@cs.stanford.edu> for reminding us of this.


Revision tags: OPENBSD_2_8_BASE
# 1.72 02-Sep-2000 todd

subtle bug .. global variables in a while loop need reset 'just incase'
With:
hostname.fxp0 having a last line of:
inet6 alias 3ffe:...
and hostname.gif0 having a first two lines of:
giftunnel 1.2.3.4
dest 1.2.4.3
We end up with the command:
ifconfig gif0 giftunnel alias 1.2.3.4 1.2.4.3
.. which is clearly wrong and fixed by this change


# 1.71 18-Jun-2000 todd

rc.conf now parses ${local_rcconf} internally; closes pr 1259


Revision tags: OPENBSD_2_7_BASE
# 1.70 08-May-2000 todd

fix dhcp 'NONE' ness from install to allow media parsing to work
.. ok deraadt@, millert@


# 1.69 21-Apr-2000 deraadt

rc.conf.local support, inspired by chuck yerkes


# 1.68 04-Apr-2000 millert

Remove the -E flag from ipf as it is implicitly enabled and using
the -E flag here causes the kernel to printf 'IP Filter: already
initialized'.


# 1.67 18-Mar-2000 deraadt

silence all extra route addition printouts


# 1.66 17-Mar-2000 itojun

correct reject route installations for IPv6. improve comments.


# 1.65 12-Mar-2000 itojun

disallow packets to malicious 6to4 prefix, based on
http://playground.iijlab.net/i-d/draft-itojun-ipv6-transition-abuse-00.txt


# 1.64 10-Mar-2000 todd

fix non behavior
with this `!' lines in /etc/hostname.* run even without certain lines
(like a comment) preceeding it.


# 1.63 10-Jan-2000 todd

allow arbitrary commands in /etc/hostname.* files if the line starts with '!'


# 1.62 02-Jan-2000 deraadt

rtsol case can configure the interface up, since it would be nice to finish
DAD before the actual rtsol(8) run happens later. and since it will rtsol,
it is going to be up in any case.


# 1.61 02-Jan-2000 itojun

one more indentation fix.


# 1.60 02-Jan-2000 itojun

indentation fix (todd's part)


# 1.59 02-Jan-2000 todd

fix rtsold case, reset cmd for each iteration!


# 1.58 02-Jan-2000 itojun

allow options after "rtsol".
XXX both "dhcp" and "rtsol" has keyword *down* at the end. is it okay?


# 1.57 02-Jan-2000 itojun

echo "IPv6 autoconf: interfaces" before invoking rtsol.
sleep for net.inet6.ip6.dad_count seconds to ensure that IPv6 DAD is completed.
TODO: rtsold (rc.conf line), manpage


# 1.56 02-Jan-2000 itojun

ipv6 autoconf on hosts (non-routers).

to do this,
1. in sysctl.conf, add these lines:
net.inet6.ip6.forwarding=0
net.inet6.ip6.accept_rtadv=1
2. in hostname.foo, add
rtsol

specifying two or more interfaces with "rtsol" may result in strange
behavior - ipv6 spec does not permit multi-interface node to be autoconfig'ed.


# 1.55 02-Jan-2000 todd

add to hostname.* parsing:
- multiple entries support (read: aliases)
- inet6 support
- support for comments (#)
(look for hostname.if(5) commit for syntax details)


# 1.54 31-Dec-1999 itojun

install IPv6 reject routes only if kernel is capable of IPv6.


# 1.53 09-Dec-1999 itojun

avoid transmitting invalid IPv6 packets out to the wire.


# 1.52 09-Dec-1999 itojun

do not perform IPv6 initialization for loopback interface.
MUST make lo0 up before any IPv6 operations.
it will be considered a pilot error if you don't.
(I prefer to have lo0 initialized automatically)


Revision tags: OPENBSD_2_6_BASE
# 1.51 01-Sep-1999 deraadt

support # characters in bridgename.* files; millert


# 1.50 01-Sep-1999 deraadt

cleanup parsing of hostname.* files, and seperate bridge control into
bridgename.* files; all documented in new hostname.if(5) and
bridgename.if(5) man pages


# 1.49 09-Aug-1999 angelos

Only parse/setup the hostname.foo file if interface foo exists (this
is useful for laptops with different ethernet cards etc.)


Revision tags: OPENBSD_2_5_BASE
# 1.48 29-Mar-1999 niklas

New multicast route setup style


# 1.47 26-Mar-1999 niklas

Add bridge interface handling


# 1.46 01-Mar-1999 millert

Add support in /etc/hostname.xxx for files of the format:
up [options]
Any of the following may or may not be set:
$name $mask $bcaddr $extras


# 1.45 28-Oct-1998 millert

Kill the awful hack used to match and split /etc/hostname.* We now use
a function, isalphanumeric, to determine whether an interface name is
likely to be valid. This means that things like /etc/hostname.le0.bak,
/etc/hostname.le0#, /etc/hostname.le0~, etc. will be ignored as they
should. There is no longer an implicate assumption that /etc/hostname.*
only contains a single '.'.


Revision tags: OPENBSD_2_4_BASE
# 1.44 06-Oct-1998 deraadt

move ipnat to end of netstart, to support dhcp+ipnat


# 1.43 18-Sep-1998 deraadt

apply media directives on dhcp interfaces


# 1.42 10-Sep-1998 marc

better way of handling dhcp client; Jason Ish <jbi130@mail.usask.ca>


# 1.41 08-Sep-1998 marc

dhcp client stuff. "Angelos D. Keromytis" <angelos@dsl.cis.upenn.edu>


# 1.40 24-Aug-1998 downsj

You can't use -interface default when there's no default gateway
set (yet). Use -interface $hostname if mygate doesn't exist so that
this actually works on routers.


# 1.39 04-Jul-1998 deraadt

put 224 route on default, to avoid a hostname lookup


# 1.38 22-May-1998 deraadt

use route -n, what the heck


Revision tags: OPENBSD_2_3_BASE
# 1.37 28-Mar-1998 deraadt

s/^nat/ipnat/


# 1.36 23-Feb-1998 niklas

remove trailing blank line


# 1.35 07-Feb-1998 deraadt

ipforward is in sysctl.conf now


# 1.34 21-Dec-1997 deraadt

ugh


# 1.33 20-Dec-1997 deraadt

ipforwarding option in rc.conf


# 1.32 29-Nov-1997 kstailey

NAT requires IPF


# 1.31 04-Nov-1997 deraadt

kill spaces at ends of lines; m4


Revision tags: OPENBSD_2_2_BASE
# 1.30 14-Oct-1997 deraadt

set hostname/domainname before running rc.conf; m4@umn.edu


# 1.29 04-Sep-1997 deraadt

fork netstart; new child is rc.conf


# 1.28 25-Aug-1997 millert

Explicately pass -host flag to route(8) to avoid confusion with networks.


# 1.27 19-Aug-1997 niklas

Add hook for rpc.lockd, make nfsd flags settable in netstart


# 1.26 31-Jul-1997 downsj

Make quotas optional; wedged into netstart for the time being.
/etc/rc.conf, anyone?


# 1.25 30-Jul-1997 deraadt

do not run routed by default


# 1.24 28-Jul-1997 kstailey

Move configuration of loopback interface to before all other interfaces.
Allows the use of local caching-only nameserver with no "nameserver"
entry in /etc/resolv.conf to configure a route between the hostname
and loopback.


# 1.23 25-Jul-1997 provos

earlier start of keymanagement


# 1.22 24-Jul-1997 deraadt

make amd use /tmp_mnt by default


# 1.21 22-Jul-1997 provos

start the photuris daemon per default. hilfe.


# 1.20 17-Jun-1997 niklas

Put in hooks to start ypserv with flags


# 1.19 17-Jun-1997 niklas

Put in hooks to start rpc.yppasswdd with flags


Revision tags: OPENBSD_2_1_BASE
# 1.18 15-Apr-1997 deraadt

kill route flush until .. hmm kernel routing socket bug or something


# 1.17 09-Apr-1997 kstailey

add NAT startup


# 1.16 07-Apr-1997 rees

flush all old routes before adding new interfaces or routes.
ref: netbsd pr3228/misc, Matthias Scheler


# 1.15 03-Mar-1997 downsj

fix typo


# 1.14 11-Feb-1997 deraadt

add default route before fiddling with loopback route to avoid DNS problems; m4@umn.edu, #97


# 1.13 03-Feb-1997 deraadt

do ifaliases after /usr/bin exists in nfs diskless env; pr#77, matthieu@laas.fr


# 1.12 02-Nov-1996 deraadt

timed off by default


Revision tags: OPENBSD_2_0_BASE
# 1.11 23-Sep-1996 deraadt

rfc1323 variable


# 1.10 04-Sep-1996 deraadt

control portmap, inetd, and lpd from netstart; idea from tqbf@enteract.com


# 1.9 27-Aug-1996 deraadt

224.0.0.0 not 0.0.0.224; from peter@demon.net


# 1.8 18-Jun-1996 deraadt

move std stuff from rc.local to rc


# 1.7 16-Jun-1996 deraadt

install sample commented /etc/ifaliases file; which can now contain #
comments and blank lines. new format is "interface address netmask"
(yes, i changed the order of the entries). inspired by netbsd pr#2474;
gillhaa@ghost.whirlpool.com


# 1.6 02-Jun-1996 tholo

Install a multicast route by default


# 1.5 26-May-1996 deraadt

sync & label


# 1.4 09-Jan-1996 dm

added IP filter to netstat/rc and put examples in /usr/share/ipf


# 1.3 30-Dec-1995 deraadt

from netbsd: start mrouted like routed


# 1.2 18-Dec-1995 deraadt

/etc/ifaliases support by randy@zyzzyva.com


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.209 29-Nov-2020 tb

Fix previous: use correct version of netstart and installer bits.


# 1.208 29-Nov-2020 deraadt

Add support for !command to mygate, so that netstart has a late opportunity
to perform network configuration (for example, "!route source -ifp em0")
Split mygate and myname manual pages (how did anyone ever believe these
are related), and perform hostname configuration much earlier in rc.
discussed with benno, claudio, jmc, etc etc, last version of !command
parser by tb


# 1.207 08-Nov-2020 jmc

no more mobileip;
ok claudio deraadt


Revision tags: OPENBSD_6_8_BASE
# 1.206 21-Jun-2020 dlg

start wg with the other interfaces that rely on routing being up.

from Matt Dunwoodie and Jason A. Donenfeld

ok deraadt@


# 1.205 22-May-2020 kn

Revert the following commit as it breaks hostname.if(5) lines with a
backslash at the end for line continuation

Breaking long lines into multiple ones must still be possible and does
require to treat the backslash as an escape character.

Breakage reported by Mark Patruck <mark at wrapped dot cx >, thanks!

---
distrib/miniroot/install.sub revision 1.1151
etc/netstart revision 1.203
date: 2020/05/21 11:54:41; author: kn; state: Exp; lines: +2 -2;
Do not treat backslashe as an escape character in hostname.if(5) lines

ifstart() should always pass such lines unaltered, especially if they
contain "nwid" or "description" lines with arbitrary strings.

<bsdlisten at gmail dot com> reported SSIDs such as "Mike's" during
installation end as broken; this was because the installer escaped
the single quote using backslashes which ended up being treated as
escape characters much later during hostname.if parsing in netstart(8).

Ok deraadt


# 1.204 21-May-2020 kn

Fix stripcom() description wrt. comments not on their own line

Neither netstart's nor install.sub's (subtly different) implementations
remove trailing comments on lines not starting as a comment, e.g.,
lines like "up #not down" go through unaltered and without "#not down"
being removed.

Only lines *beginning* with the comment sign ("#") are stripped.

No functional change, just updating function descriptions.


# 1.203 21-May-2020 kn

Do not treat backslashe as an escape character in hostname.if(5) lines

ifstart() should always pass such lines unaltered, especially if they
contain "nwid" or "description" lines with arbitrary strings.

<bsdlisten at gmail dot com> reported SSIDs such as "Mike's" during
installation end as broken; this was because the installer escaped
the single quote using backslashes which ended up being treated as
escape characters much later during hostname.if parsing in netstart(8).

Ok deraadt


Revision tags: OPENBSD_6_7_BASE
# 1.202 15-Jan-2020 kn

Do not redirect already quiet stdout for IPv6 reject routes

"route -q" already silences all standard output; if it still prints
something, that's a bug to fix in route.

OK bluhm


# 1.201 25-Oct-2019 dlg

handle aggr(4) in the same way as trunk(4)

from brad@
ok bluhm@ claudio@ deraadt@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.200 29-Aug-2018 krw

Historically /etc/netstart (and the equivalent code in the install
script) did 'ifconfig <if> down' before starting dhclient(8). This was
a way of ensuring old running copies of dhclient were killed before a
new one started. Current dhclient does not need this assist, so change
"ifconfig <if> down" to "ifconfig <if> up" pending further script
optimizations.

Similar to a 2014 attempt by halex@. Prompted by a misc@ report
from Kristjan Komlosi reporting hanging diskless setups.

ok halex@ kn@


# 1.199 08-Jul-2018 tb

netstart is used during system start, but also interactively.
Show proper error message if a regular user executes netstart.
Only do the privilege check if the id binary is available,
which might not be the case during diskless system startup.

ok deraadt, jasper, jca, krw, rpe (who wrote the same diff), sthen


# 1.198 28-Apr-2018 rpe

Add a proper usage() function.

Suggested by and OK jmc.
OK tb


Revision tags: OPENBSD_6_3_BASE
# 1.197 04-Mar-2018 jmc

when -n is used, no need to spit out "Missing parameters." before
displaying usage();

ok tb


# 1.196 03-Mar-2018 landry

Lowercase 'usage' and group -n with interface in it.
From jmc@, ok tb@


# 1.195 21-Feb-2018 rpe

Tweak comments.

OK tb


# 1.194 19-Feb-2018 rpe

Write warning/error messages to stderr and end them with a fullstop.

OK tb


# 1.193 19-Feb-2018 rpe

- use specific patterns when looping over /etc/hostname.if files
to skip backup or temp files.
- test if the patterns matched actual files
- warn if ifcreate() fails on an interface and continue with the
subsequent interfaces in the list instead of return'ing

OK dlg sthen tb


# 1.192 17-Feb-2018 rpe

- Add descriptions for the new functions ifcreate() and vifscreate()
- In ifcreate() use the exit code of the {} block directly
- In vifscreate(), use the ifconfig -C output directly in the for _vif loop
- Remove superfluous and somewhat confusing comment

OK dlg kn sthen


# 1.191 14-Feb-2018 dlg

create virtual interfaces before starting all interface config.

this resolves an ordering problem when adding pseudo interfaces to bridges

tweaks from kn@
ok mpi@ sthen@


# 1.190 10-Feb-2018 claudio

Remove some special IPv4 in IPv6 mapped prefixes that are already rejected
by the ::0.0.0.0/96 reject route added to deny all IPv4 mapped addresses.
Makes the inet6 routing table almost fit in one screen.
OK benno@


# 1.189 10-Feb-2018 florian

Load RFC 7217 key material and generate if it does not already exist.

Add soii.key to changelist (pointed out by semarie) and mtree/special
(suggest by Craig Skinner).

OK naddy, sthen, rpe, tb


# 1.188 06-Feb-2018 tb

If -n is given, the netstart script should not (try to) set the default
route(s). Simply print the command(s) to be issued instead.

tweak & ok rpe


# 1.187 12-Nov-2017 tb

Remove HN_DIR variable and expand it in the only place it was used. It
currently serves no purpose.

ok rpe, agreement from deraadt and halex


Revision tags: OPENBSD_6_2_BASE
# 1.186 25-Jul-2017 rpe

Finally remove backwards compat code to support the 'rtsol' keyword
in hostname.if(5)

OK mpi@ deraadt@ florian@
OK jmc@ from doc perspective


# 1.185 21-Jul-2017 rpe

Align ifstart() in netstart and install.sub.

- in netstart, rename _file to _hn referencing hostname.if files
- in install.sub switch ifstart() to be used with _if instead of
_hn as parameter

ok krw@ tb@


# 1.184 28-May-2017 awolk

etc/netstart: use colon separator instead of dot with chown

OK jung@, deraadt@, jmc@


# 1.183 07-May-2017 rpe

Change test from [] to [[]] and simplify pattern.

OK tb@, krw@ (for [[]])
Feedback and OK halex@


# 1.182 07-May-2017 rpe

Replace hardcoded script name with ${0##*/}

OK tb@ halex@


# 1.181 01-May-2017 rpe

Revert r1.170 and remove the id==0 check.
The id binary is not available in nfs diskless setups at this point.

reported by Andreas Kusalananda, thanks.
discussed with deraadt@


# 1.180 01-May-2017 rpe

Remove last remnants of rtsol. IPv6 autoconfiguration of interfaces is now
done in ifstart(). Remove ipv6autoconf() and replace rtsolif with a boolean
variable V6_AUTOCONF. Replace dhcpif with a boolean variable V4_DHCPCONF.
Both are later used in defaultroute() to decide whether or not to configre
defaultroutes from /etc/mygate.

OK krw@


# 1.179 30-Apr-2017 mpi

Do not try to delete a default route before adding it.

Now that route are automatically G/C with the address they are attached
to there's no reason to duplicate the kernel's job.

Fix a regression introduced with multipath default routes.

ok deraadt@


# 1.178 25-Apr-2017 rpe

Unbreak netstart for multiple inteface configurations like trunk
or carp. Ensure that the noglob option is disabled at the end of
parse_hn_line() and ifstart().

Reported by Christer Solskogen and Stefan Wollny, thanks!


# 1.177 24-Apr-2017 rpe

Introduce a new function parse_hn_line() that replaces the existing
hostname.if(5) parsing code in ifstart().
Add a -n option to netstart to only print the interface configuration
commands instead of executing them.
Add a HN_DIR variable, that points to the directory of the hostname.if
files (default /etc) that allows for future regression tests.

- add new parse_hn_line() function
- change ifstart()
- rename $if to $_if
- don't ifconfig or ifconfig create if -n option is used
- replace hostname.if(5) parsing code with new parse_hn_line()
- just print configuration commands if -n option is used
- autoconf now happens in ifstart(), remove ifv6autoconf()
- introduce HN_DIR variable for the hostname.if file location
- add handling of the -n option to only print config commands
- ensure -n is only used if interfaces are specified as parameters

Discussed with and positive feedback from many
'commit' deraadt@
OK sthen@


# 1.176 08-Apr-2017 rpe

- localize the if, file and stat variables which also ensures that
variables are not named like commands.
- change test from [] to [[]]

OK tb@ halex@


# 1.175 07-Apr-2017 rpe

Minimize differences in ifstart() function between netstart and
install.sub which makes it easier to spot changes in the future.

- comments and formatting
- quotes on assignments are not needed (netstart)
- remove stray space in test (netstart)
- use $file variable with while-loop (netstart)
- although valid, instead of i use $i in arithmetic test (install.sub)

OK krw@, tb@
Looks good deraadt@


# 1.174 07-Apr-2017 rpe

Align comments of ifstart() function in netstart and install.sub.


# 1.173 07-Apr-2017 rpe

Align comments of stripcom() function in netstart and install.sub.


Revision tags: OPENBSD_6_1_BASE
# 1.172 06-Dec-2016 mpi

Do not lose the default route when netstart(8) is run a second time on
the interface pointed to by the default route.

Since the kernel no longer keep routes with dangling address pointer,
netstart(8) has to re-add the default route when the corresponding ifa
has been deleted and re-created.

deraadt@ points out that even if the previous semantic was not necessarily
better, a script like netstart(8) cannot totally fix the default route
problem.

Regression reported by and fix tested by Hrvoje Popovski.

ksh foo checked by halex@


# 1.171 27-Sep-2016 rzalamena

Delay switch(4) interface start up so it can attach virtual interfaces
like vether(4).

nits from and ok benno@, phessler@


# 1.170 09-Sep-2016 jasper

print a clear error message when not ran as root instead of just falling
through and try whatever it can do with the invoking user's perms

feedback/ok aja@ rpe@


Revision tags: OPENBSD_6_0_BASE
# 1.169 19-Jul-2016 mpi

Do not consider tap(4) a special interface and start if before other
pseudo-interfaces.

This unbreak vlan(4) on top of tap(4) since the refactoring to turn it
MP-safe.

ok claudio@, deraadt@


# 1.168 27-Mar-2016 sthen

Don't delete the 224/4 route in netstart, unless it's being done to ensure that
a -reject route can be added. Restores the ability to set an interface route
before daemons are started, lost during the previous simplification.
ok millert mpi


Revision tags: OPENBSD_5_9_BASE
# 1.167 29-Dec-2015 rpe

Remove backslash, not necessary after '&&'

OK halex@


# 1.166 29-Dec-2015 rpe

Replace last remaining `` with $()

OK halex@


# 1.165 18-Dec-2015 ajacoutot

Drop the now useless multicast setup comment.

prodded by tim@, ok mpi@


# 1.164 17-Dec-2015 ajacoutot

Simplify multicast option handling (10 less lines) by matching /etc/rc behavior
towards other YES|NO options and drop the error warning.


with and ok tim@, ok rpe@ on an earlier diff


# 1.163 05-Dec-2015 mpi

It does not make sense to insert a specific route for 224/4 when the
default one is good enough.

So merge rc.conf(8)'s 'multicast_router' and 'multicast_host' into a
single 'multicast'. If set to YES the reject route for 224/4 is not
inserted by netstart(8).

Manual bits from jmc@

ok henning@, ajacoutot@


# 1.162 12-Nov-2015 rpe

Changes to ifautostart():
- Rename function to ifv6autoconf() to make IPv6 relation clearer
- Localize and rename variables

OK krw@


# 1.161 12-Nov-2015 rpe

Changes to ifmstart():
- Change comments to make it clearer that ifmstart() takes two lists
of interface driver names (of which the second is optional) and not
the actual interface instances.
- Use localized variables and use slightly more verbose names.
- Use continue 2 to skip to the next hostname.if file.
- Use shell pattern @() instead of testing _sif individually.

OK krw@


# 1.160 12-Nov-2015 rpe

Changes to stripcom():
- Align comments with /etc/rc version
- Use localized variables
- Use safer "print -r --" instead of plain echo

Changes to ifstart():
- Tweak comment
- Add usage

OK krw@


# 1.159 01-Nov-2015 rpe

Start the rework of the /etc/netstart shell script.

General changes:
- apply a similar 'style' as used in the installer scripts
- improve comments to be more to the point, remove where code is obvious
- document usage of functions if they have arguments
- rename variables where it improves readability
- replace really old-school shell code with more contemporary idioms

Other changes:
- No need to care about "autoboot" because netstart doesn't inherit the
positional parameters from /etc/rc anymore. /etc/rc executes netstart
instead of sourcing it since r1.439.
- Use simpler for-loop to process list of interfaces with ifstart.

OK halex@


# 1.158 26-Oct-2015 rpe

The hostname variable is not used since r1.99. Remove it and use
stripcom() output directly with the hostname command.

OK deraadt@ krw@


# 1.157 23-Oct-2015 claudio

netstart bits for tap(4)


# 1.156 27-Sep-2015 sthen

Don't print output when setting autoconf on interfaces. Suggested by deraadt,
ok florian@ rpe@


# 1.155 13-Sep-2015 sthen

only print the "IPv6 autoconf" line if there are interfaces to configure
feedback/ok rpe


# 1.154 11-Sep-2015 sthen

Set "inet6 autoconf" individually on interfaces that have rtsol set in
hostname.if, previously netstart tried to configure them all at once
("ifconfig if0 if1 if2 inet6 autoconf"). From Delan Azabani, ok phessler@


Revision tags: OPENBSD_5_8_BASE
# 1.153 20-Jul-2015 rpe

Disable Strict Bourne shell mode for /etc/rc and /etc/netstart to be
able to use ksh syntax within these scripts. This way init doesn't
need to be changed, which starts /etc/rc using /bin/sh and people
can still use "sh /etc/netstart ifname".

Idea from and OK halex@
OK deraadt@ krw@ guenther@


# 1.152 19-Jul-2015 florian

Bring up pflow last as it might send with a source address that is on
any of the other interfaces.
OK deraadt, phessler, benno


# 1.151 19-Jul-2015 rpe

Always source rc.subr to be able to use the rc.conf parsing routine
to get the network related vars from rc.conf. This is even necessary
if netstart is run from within /etc/rc. Remove test of $INRC which
unintentionally evaluated always to true.

problem with previous change found by nigel@
OK sthen@ aja@ halex@


# 1.150 19-Jul-2015 ajacoutot

Revert 1.148 for now until I can talk to rpe@
It introduced a regression reported by nigel@


# 1.149 19-Jul-2015 rpe

Replace test command with [].

OK halex@ krw@


# 1.148 19-Jul-2015 rpe

Ensure, that we source rc.subr and parse rc.conf ONLY if we are not
inside /etc/rc.

With help from and OK halex@, ajacoutot@


# 1.147 18-Jul-2015 rpe

- remove trailing blanks introduced in previous commit
- no space in redirections like </foo or >$bar
- few other minor whitespaces

OK krw@


# 1.146 18-Jul-2015 rpe

Improve comments
- Add comments for functions
- Start comments with capital letters
- End comments with a full stop
- Allow comments to extend up to column 80

OK krw@


# 1.145 06-Jun-2015 florian

Allow rtsol keyword in hostname.if(5) with net.inet6.ip6.forwarding=1.
"inet6 autoconf" was working before and rtsol should behave the same.
OK phessler


Revision tags: OPENBSD_5_7_BASE
# 1.144 03-Dec-2014 florian

The kernel handles rtsol(8) functionality since some time now.
Treat rtsol in hostname.if as a keyword like dhcp and call ifconfig
inet6 autoconf.
"reads good" todd@
OK krw@ (who is *not* an IPv6 person), but I recruited him in his
capacity as an installer person.


# 1.143 28-Sep-2014 claudio

Revert 1.142. Without the down netstart will just print the ifconfig
output because it may end up just calling 'ifconfig $if'. This needs
to be done better and properly tested.


# 1.142 26-Sep-2014 halex

remove explicit 'down' of an interface before starting a dhcp request, thereby
avoiding annoying delays for some switch configurations

ok claudio@ deraadt@

i would add ok phessler@, but it was not valid without an ok krw@


Revision tags: OPENBSD_5_6_BASE
# 1.141 12-Jul-2014 stsp

Fix netstart after autoconf6 change so 'rtsol' lines in hostname.if work again.
found by pelikan@; ok pelikan@ henning@


# 1.140 12-Jul-2014 robert

Make rc.conf a parsed configuration file and stop sourcing it as a shell
script.
From now on rc.conf has a fixed syntax (key=val) and it is not allowed
to add anything to it besides the supported syntax, it all going to be
ignored.

discussed with and help from deraadt@ and halex@


Revision tags: OPENBSD_5_5_BASE
# 1.139 22-Aug-2013 mpi

Like for dhclient, do no create a route to alias addresses via 127.0.0.1.
Our stack is able to tell if the address is local or not.

ok todd@, krw@


Revision tags: OPENBSD_5_4_BASE
# 1.138 20-Mar-2013 todd

fix lies in netstart; replacement wording from halex@
pointed out by Ryan Kavannagh rak at debian dot org


Revision tags: OPENBSD_5_3_BASE
# 1.137 05-Dec-2012 rpe

remove "Invalid interface name" message
requested by krw@

ok halex@


# 1.136 02-Dec-2012 rpe

use the more compact version of the check for ifconfig'able interfaces
from install.sub

with feedback from and ok halex


# 1.135 02-Dec-2012 rpe

- remove isalphanumeric() and replace it with a shell pattern, that
tries a bit harder to identify invalid interface names and in
this case emit an error message.
- use [[ $1 == autoboot ]] to avoid a shell error message due to
possible spaces in first argument
- no change in functionality

discussed with krw and halex
ok ("I like this") krw


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.134 07-Oct-2011 deraadt

The new ypbind changes requires that the domainname be set before
rc.conf is run. There's no real downside.
ok aja


Revision tags: OPENBSD_5_0_BASE
# 1.133 07-Jul-2011 guenther

Eliminate some $? tests by rolling the command into the condition

ok halex@


# 1.132 26-May-2011 mpf

Add svlan(4) startup bits.
From markus@. OK naddy, claudio, reyk.


Revision tags: OPENBSD_4_9_BASE
# 1.131 09-Feb-2011 sobrado

fix an unbalanced parenthesis in a comment; while here, split the comment
in a better place to make it more readable.

ok jmc@ and miod@


Revision tags: OPENBSD_4_8_BASE
# 1.130 16-Jun-2010 todd

permit e.g. -inet6 syntax by slurping all lines not just some
noticed by rhsv6 at hushmail dot com, ok sthen@


Revision tags: OPENBSD_4_7_BASE
# 1.129 12-Jan-2010 henning

when setting up lo0 use 127.0.0.1/8 instead of 127.0.0.1 for clarity and
correctness. it's not 1992 any more, kids. ok mcbride dlg krw


# 1.128 10-Dec-2009 todd

o stop reordering ifconfig arguments (e.g. after 'up ..')
o only stop processing if inet or inet6 lines are malformed
o everything not a specially handled bit is passed to ifconfig unmangled
noticed by several after the move from bridgename.bridge0 -> hostname.bridge0
prodded by deraadt@, tested by and feedback from several
man page bits 'look fine' jmc@


# 1.127 22-Nov-2009 deraadt

Stop supporting bridgename.bridge* files, and move to hostname.bridge*
files. To cope with this change, read about the mv command.
ok claudio todd


# 1.126 17-Sep-2009 simon

change variable i to $i in an expression of ifstart() for consistency
with the rest of the file. no functional change.

feedback from sthen@, ok krw@


# 1.125 10-Jul-2009 jdixon

Delay creation of tun(4) interfaces until the underlying interface and
routes are available. This fixes usage for some OpenVPN users that start
it from hostname.tun*.

Tested by Johan Huldtgren. ok sthen@, johan@.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.124 25-Nov-2008 markus

delay /etc/netstart until IPv6-DAD (dup-address-detection) is completed.
ok fries, hshoexer, claudio


# 1.123 14-Aug-2008 sthen

Tools from /usr may not be used in netstart since it may be NFS-mounted
and not available at that time. Rewrite the hostname.if permission check
to use only /bin/ls and the shell. Requested by deraadt.

ok todd, "Twisted." deraadt


Revision tags: OPENBSD_4_4_BASE
# 1.122 23-Jul-2008 sthen

Prevent warning about insecure hostnames where no /etc/hostname.*
exists. From wcmaier@.

Check target of symbolic links to avoid noise at boot and in
seucrity output where you have several interfaces symlinked to one
config file.

"If you think this is the right thing to do" deraadt@


# 1.121 09-Jun-2008 todd

warn once not 3 times in case of a non existent file, discussed with deraadt
originally pointed out by Johan Torin


# 1.120 09-Jun-2008 deraadt

Ensure that hostname.* files are also re-chowned to root.wheel at each
boot as discussed with claudio while eating tasty donairs. ok todd


# 1.119 17-Apr-2008 deraadt

before using them, force hostname.* files to be unreadable by world
first version from todd, ok millert


Revision tags: OPENBSD_4_3_BASE
# 1.118 17-Jan-2008 brad

Execute rtsol after turning up trunk(4) and vlan(4) interfaces so they're
taken into consideration for rtsol.

ok reyk@ dlg@


# 1.117 09-Jan-2008 mpf

Do not bring up pfsync(4) before the working ruleset
has been loaded. Otherwise, states that are received during the
initial bulk update mismatch the correct pf-checksum and
do not attach to the rules.
Problem identified by david@. Fix done in collaboration.
OK henning@


Revision tags: OPENBSD_4_2_BASE
# 1.116 02-Aug-2007 david

move the delay for IPv6 DAD to after all interfaces have started
fixes problems with daemons being unable to bind to all addreses at boot
ok itojun@ hshoexer@


Revision tags: OPENBSD_4_1_BASE
# 1.115 15-Nov-2006 itojun

reject multicast packet without scope identifier specified.


Revision tags: OPENBSD_4_0_BASE
# 1.114 29-Jun-2006 todd

do not add an extra space; nwid and description come out wrong
fix as proposed by maja@, thanks!


Revision tags: OPENBSD_3_9_BASE
# 1.113 28-Dec-2005 david

nuke extra whitespace


# 1.112 06-Dec-2005 reyk

multicast_host=YES only works if a valid default gateway is available.
validate this condition and reject multicast traffic on failure.

ok todd@ naddy@


# 1.111 02-Nov-2005 todd

fix inspired by pr#4590
ok krw@


# 1.110 25-Oct-2005 todd

better logic from krw@:
- do not process mygate for v4 if dhcp
- do not process mygate for v6 if rtsol
this also makes the mygate processing logic more readable
ok krw@


# 1.109 14-Oct-2005 todd

add v6 support for /etc/mygate
ok deraadt@ mickey@ krw@
same functionality tested/ok'ed by by mickey, brad, matthieu, and me
with this one may now put a v6 IP in /etc/mygate on a separate line from
the v4 default gateway and netstart will do the right thing


# 1.108 12-Oct-2005 todd

shrink stripcom(), sync with install.sub
ok krw@


# 1.107 04-Oct-2005 todd

trunk must be started after physical ethernet devices, but before vlan.
populate ifmstart lines accordingly.
prodded/tested by brad@
ok reyk@


# 1.106 28-Sep-2005 todd

use eval consistently, fixes description quotes on rtsol and dhcp
fix inspired by and closes pr 4495
ok krw@


Revision tags: OPENBSD_3_8_BASE
# 1.105 22-May-2005 todd

Introduce 'ifmstart' to deal with starting multiple interfaces minus a list
of interfaces.

This reduces the netstart script by 174 chars, 13 words, and 19 lines, but
more importantly, makes it more simple and less cluttered should more special
case/orderings be needed.

ok brad@ and pr 4197 submitter, inspired by and closes pr 4197


# 1.104 04-Apr-2005 djm

unbreak; ok pval@


# 1.103 03-Apr-2005 deraadt

if dhcp is used to get an address on any interface, ignore /etc/mygate
ok krw
(this lets us do something rather cool with the zaurus in particular)


Revision tags: OPENBSD_3_7_BASE
# 1.102 04-Jan-2005 mcbride

Bring up the carp(4) interface before default route.

ok pascoe@ mpf@


# 1.101 30-Dec-2004 millert

Add a copy of stripcom so /etc/netstart can be run standalone again.
OK deraadt@


# 1.100 19-Dec-2004 millert

Allow comments in /etc/{myname,mygate,defaultdomain}; OK deraadt@


# 1.99 04-Dec-2004 itojun

remove "route $hostname 127.0.0.1" line. deraadt ok
*** please update /etc/netstart and test if it works ok for you ***


# 1.98 20-Oct-2004 deraadt

make all route commands use -qn; ok mcbride henning


Revision tags: OPENBSD_3_6_BASE
# 1.97 29-May-2004 deraadt

one last route command lacking -qn


Revision tags: OPENBSD_3_5_BASE
# 1.96 22-Mar-2004 mcbride

Make sure pfsync is brought up before carp.

ok deraadt@


# 1.95 13-Mar-2004 mcbride

Delay pfsync(4) configuration, as the syncif has to be configured in
advance. From Thorsten Lockert.


# 1.94 14-Jan-2004 deraadt

ok, it took quite a bit of prodding but itojun finally explained why the
extra sleep 1 is in here, and we came to the conclusion it is safe to
delete it. whee.


# 1.93 13-Jan-2004 deraadt

repair v6 lo0 documentation


# 1.92 11-Jan-2004 deraadt

add loopback routes late


# 1.91 09-Jan-2004 deraadt

create all routes with -q; markus ok


# 1.90 04-Dec-2003 millert

Need to do "ifconfig create" for bridge interfaces too.


# 1.89 03-Dec-2003 markus

add support for ifconfig clone; from netbsd; ok deraadt, henning


# 1.88 20-Oct-2003 david

delay carp initialization until after physical interfaces are configured
ok mcbride@ henning@ deraadt@ todd@


Revision tags: OPENBSD_3_4_BASE
# 1.87 27-Aug-2003 henning

only try to set hostname to what /etc/myname says if that file actually exists,
otherwise preserve `hostname`
netbooted machines can live perfectly fine without it; they get their hostname
earlier.

ok krw@ cedric@


Revision tags: OPENBSD_3_3_BASE
# 1.86 16-Feb-2003 krw

Fix up some DNS verbiage to make it consistant.

Fix up default route selection by

a) Forcing user to explicitly chose 'dhcp' as a mechanism for
specifying a default route, rather than guessing based on one or more
interfaces being configured by dhcp.

b) If the user specified default route does not work, re-present the
existing default route rather than losing it.

c) Move default route selection to after nameserver activation so the
user can specify a hostname as the default route.

Change /etc/netstart so that /etc/mygate wins if a default route was
already specified (i.e. by dhcp).

ok deraadt@.


Revision tags: OPENBSD_3_2_BASE
# 1.85 16-May-2002 todd

ignore non-existent cases where '$if' evaluates to '*'.
From Andr� Lucas <andre@ae-35.com>, fixes pr # 2658.
'Looks good' from miod@, millert@, and krw@.


Revision tags: OPENBSD_3_1_BASE
# 1.84 23-Feb-2002 deraadt

re-add support for $if expansion; hamajima@nagoya.ydc.co.jp


# 1.83 21-Feb-2002 miod

Change the network components initialization order.
Change from:
o all interfaces
o all bridges
o routes
to:
o physical interfaces
o routes
o gif and gre interfaces
o bridges

Fixeski PR #2400.
Manual page updates coming soon.
Ok angelos@ chris@ deraadt@


Revision tags: OPENBSD_3_0_BASE
# 1.82 31-Jul-2001 hugh

a space before a redirect


# 1.81 06-Jul-2001 angelos

Also, source /etc/rc.conf so we can pull in the
multicast_host/multicast_router settings; this is useful if one
flushes the routing table and re-initializes.

We really need a netconfig tool of sorts.


# 1.80 06-Jul-2001 angelos

Use "route -n show -inet" to determine the default multicast iface.


# 1.79 03-Jul-2001 deraadt

pull in rc.conf early so that pf(1) startup is right; tested by jasoni, comments from millert


# 1.78 30-May-2001 deraadt

Remove ipf. Darren Reed has interpreted his (old, new, whichever)
licence in a way that makes ipf not free according to the rules we
established over 5 years ago, at www.openbsd.org/goals.html (and those
same basic rules govern the other *BSD projects too). Specifically,
Darren says that modified versions are not permitted. But software
which OpenBSD uses and redistributes must be free to all (be they
people or companies), for any purpose they wish to use it, including
modification, use, peeing on, or even integration into baby mulching
machines or atomic bombs to be dropped on Australia. Furthermore, we
know of a number of companies using ipf with modification like us, who
are now in the same situation, and we hope that some of them will work
with us to fill this gap that now exists in OpenBSD (temporarily, we
hope).


Revision tags: OPENBSD_2_9_BASE
# 1.77 13-Mar-2001 deraadt

spelling; maurice@maurice.wan.nl


# 1.76 06-Feb-2001 todd

ignore blank lines in addition to comments
fixes pr#1660 from wilfried@telia.com .. Thanks!


# 1.75 10-Jan-2001 jason

support !command in bridgename.if files, too


# 1.74 27-Nov-2000 millert

Use -n to test if a variable is non-zero. Otherwise, if the variable's
contents start with a '-' test becomes unhappy (since it interprets it
as another option).


# 1.73 08-Nov-2000 todd

This fixes pr 1481, we now handle args > 6 in /etc/hostname.if in the
cases where we did not previously handle them.
Thanks to Scott Atwood <atwood@cs.stanford.edu> for reminding us of this.


Revision tags: OPENBSD_2_8_BASE
# 1.72 02-Sep-2000 todd

subtle bug .. global variables in a while loop need reset 'just incase'
With:
hostname.fxp0 having a last line of:
inet6 alias 3ffe:...
and hostname.gif0 having a first two lines of:
giftunnel 1.2.3.4
dest 1.2.4.3
We end up with the command:
ifconfig gif0 giftunnel alias 1.2.3.4 1.2.4.3
.. which is clearly wrong and fixed by this change


# 1.71 18-Jun-2000 todd

rc.conf now parses ${local_rcconf} internally; closes pr 1259


Revision tags: OPENBSD_2_7_BASE
# 1.70 08-May-2000 todd

fix dhcp 'NONE' ness from install to allow media parsing to work
.. ok deraadt@, millert@


# 1.69 21-Apr-2000 deraadt

rc.conf.local support, inspired by chuck yerkes


# 1.68 04-Apr-2000 millert

Remove the -E flag from ipf as it is implicitly enabled and using
the -E flag here causes the kernel to printf 'IP Filter: already
initialized'.


# 1.67 18-Mar-2000 deraadt

silence all extra route addition printouts


# 1.66 17-Mar-2000 itojun

correct reject route installations for IPv6. improve comments.


# 1.65 12-Mar-2000 itojun

disallow packets to malicious 6to4 prefix, based on
http://playground.iijlab.net/i-d/draft-itojun-ipv6-transition-abuse-00.txt


# 1.64 10-Mar-2000 todd

fix non behavior
with this `!' lines in /etc/hostname.* run even without certain lines
(like a comment) preceeding it.


# 1.63 10-Jan-2000 todd

allow arbitrary commands in /etc/hostname.* files if the line starts with '!'


# 1.62 02-Jan-2000 deraadt

rtsol case can configure the interface up, since it would be nice to finish
DAD before the actual rtsol(8) run happens later. and since it will rtsol,
it is going to be up in any case.


# 1.61 02-Jan-2000 itojun

one more indentation fix.


# 1.60 02-Jan-2000 itojun

indentation fix (todd's part)


# 1.59 02-Jan-2000 todd

fix rtsold case, reset cmd for each iteration!


# 1.58 02-Jan-2000 itojun

allow options after "rtsol".
XXX both "dhcp" and "rtsol" has keyword *down* at the end. is it okay?


# 1.57 02-Jan-2000 itojun

echo "IPv6 autoconf: interfaces" before invoking rtsol.
sleep for net.inet6.ip6.dad_count seconds to ensure that IPv6 DAD is completed.
TODO: rtsold (rc.conf line), manpage


# 1.56 02-Jan-2000 itojun

ipv6 autoconf on hosts (non-routers).

to do this,
1. in sysctl.conf, add these lines:
net.inet6.ip6.forwarding=0
net.inet6.ip6.accept_rtadv=1
2. in hostname.foo, add
rtsol

specifying two or more interfaces with "rtsol" may result in strange
behavior - ipv6 spec does not permit multi-interface node to be autoconfig'ed.


# 1.55 02-Jan-2000 todd

add to hostname.* parsing:
- multiple entries support (read: aliases)
- inet6 support
- support for comments (#)
(look for hostname.if(5) commit for syntax details)


# 1.54 31-Dec-1999 itojun

install IPv6 reject routes only if kernel is capable of IPv6.


# 1.53 09-Dec-1999 itojun

avoid transmitting invalid IPv6 packets out to the wire.


# 1.52 09-Dec-1999 itojun

do not perform IPv6 initialization for loopback interface.
MUST make lo0 up before any IPv6 operations.
it will be considered a pilot error if you don't.
(I prefer to have lo0 initialized automatically)


Revision tags: OPENBSD_2_6_BASE
# 1.51 01-Sep-1999 deraadt

support # characters in bridgename.* files; millert


# 1.50 01-Sep-1999 deraadt

cleanup parsing of hostname.* files, and seperate bridge control into
bridgename.* files; all documented in new hostname.if(5) and
bridgename.if(5) man pages


# 1.49 09-Aug-1999 angelos

Only parse/setup the hostname.foo file if interface foo exists (this
is useful for laptops with different ethernet cards etc.)


Revision tags: OPENBSD_2_5_BASE
# 1.48 29-Mar-1999 niklas

New multicast route setup style


# 1.47 26-Mar-1999 niklas

Add bridge interface handling


# 1.46 01-Mar-1999 millert

Add support in /etc/hostname.xxx for files of the format:
up [options]
Any of the following may or may not be set:
$name $mask $bcaddr $extras


# 1.45 28-Oct-1998 millert

Kill the awful hack used to match and split /etc/hostname.* We now use
a function, isalphanumeric, to determine whether an interface name is
likely to be valid. This means that things like /etc/hostname.le0.bak,
/etc/hostname.le0#, /etc/hostname.le0~, etc. will be ignored as they
should. There is no longer an implicate assumption that /etc/hostname.*
only contains a single '.'.


Revision tags: OPENBSD_2_4_BASE
# 1.44 06-Oct-1998 deraadt

move ipnat to end of netstart, to support dhcp+ipnat


# 1.43 18-Sep-1998 deraadt

apply media directives on dhcp interfaces


# 1.42 10-Sep-1998 marc

better way of handling dhcp client; Jason Ish <jbi130@mail.usask.ca>


# 1.41 08-Sep-1998 marc

dhcp client stuff. "Angelos D. Keromytis" <angelos@dsl.cis.upenn.edu>


# 1.40 24-Aug-1998 downsj

You can't use -interface default when there's no default gateway
set (yet). Use -interface $hostname if mygate doesn't exist so that
this actually works on routers.


# 1.39 04-Jul-1998 deraadt

put 224 route on default, to avoid a hostname lookup


# 1.38 22-May-1998 deraadt

use route -n, what the heck


Revision tags: OPENBSD_2_3_BASE
# 1.37 28-Mar-1998 deraadt

s/^nat/ipnat/


# 1.36 23-Feb-1998 niklas

remove trailing blank line


# 1.35 07-Feb-1998 deraadt

ipforward is in sysctl.conf now


# 1.34 21-Dec-1997 deraadt

ugh


# 1.33 20-Dec-1997 deraadt

ipforwarding option in rc.conf


# 1.32 29-Nov-1997 kstailey

NAT requires IPF


# 1.31 04-Nov-1997 deraadt

kill spaces at ends of lines; m4


Revision tags: OPENBSD_2_2_BASE
# 1.30 14-Oct-1997 deraadt

set hostname/domainname before running rc.conf; m4@umn.edu


# 1.29 04-Sep-1997 deraadt

fork netstart; new child is rc.conf


# 1.28 25-Aug-1997 millert

Explicately pass -host flag to route(8) to avoid confusion with networks.


# 1.27 19-Aug-1997 niklas

Add hook for rpc.lockd, make nfsd flags settable in netstart


# 1.26 31-Jul-1997 downsj

Make quotas optional; wedged into netstart for the time being.
/etc/rc.conf, anyone?


# 1.25 30-Jul-1997 deraadt

do not run routed by default


# 1.24 28-Jul-1997 kstailey

Move configuration of loopback interface to before all other interfaces.
Allows the use of local caching-only nameserver with no "nameserver"
entry in /etc/resolv.conf to configure a route between the hostname
and loopback.


# 1.23 25-Jul-1997 provos

earlier start of keymanagement


# 1.22 24-Jul-1997 deraadt

make amd use /tmp_mnt by default


# 1.21 22-Jul-1997 provos

start the photuris daemon per default. hilfe.


# 1.20 17-Jun-1997 niklas

Put in hooks to start ypserv with flags


# 1.19 17-Jun-1997 niklas

Put in hooks to start rpc.yppasswdd with flags


Revision tags: OPENBSD_2_1_BASE
# 1.18 15-Apr-1997 deraadt

kill route flush until .. hmm kernel routing socket bug or something


# 1.17 09-Apr-1997 kstailey

add NAT startup


# 1.16 07-Apr-1997 rees

flush all old routes before adding new interfaces or routes.
ref: netbsd pr3228/misc, Matthias Scheler


# 1.15 03-Mar-1997 downsj

fix typo


# 1.14 11-Feb-1997 deraadt

add default route before fiddling with loopback route to avoid DNS problems; m4@umn.edu, #97


# 1.13 03-Feb-1997 deraadt

do ifaliases after /usr/bin exists in nfs diskless env; pr#77, matthieu@laas.fr


# 1.12 02-Nov-1996 deraadt

timed off by default


Revision tags: OPENBSD_2_0_BASE
# 1.11 23-Sep-1996 deraadt

rfc1323 variable


# 1.10 04-Sep-1996 deraadt

control portmap, inetd, and lpd from netstart; idea from tqbf@enteract.com


# 1.9 27-Aug-1996 deraadt

224.0.0.0 not 0.0.0.224; from peter@demon.net


# 1.8 18-Jun-1996 deraadt

move std stuff from rc.local to rc


# 1.7 16-Jun-1996 deraadt

install sample commented /etc/ifaliases file; which can now contain #
comments and blank lines. new format is "interface address netmask"
(yes, i changed the order of the entries). inspired by netbsd pr#2474;
gillhaa@ghost.whirlpool.com


# 1.6 02-Jun-1996 tholo

Install a multicast route by default


# 1.5 26-May-1996 deraadt

sync & label


# 1.4 09-Jan-1996 dm

added IP filter to netstat/rc and put examples in /usr/share/ipf


# 1.3 30-Dec-1995 deraadt

from netbsd: start mrouted like routed


# 1.2 18-Dec-1995 deraadt

/etc/ifaliases support by randy@zyzzyva.com


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.207 08-Nov-2020 jmc

no more mobileip;
ok claudio deraadt


Revision tags: OPENBSD_6_8_BASE
# 1.206 21-Jun-2020 dlg

start wg with the other interfaces that rely on routing being up.

from Matt Dunwoodie and Jason A. Donenfeld

ok deraadt@


# 1.205 22-May-2020 kn

Revert the following commit as it breaks hostname.if(5) lines with a
backslash at the end for line continuation

Breaking long lines into multiple ones must still be possible and does
require to treat the backslash as an escape character.

Breakage reported by Mark Patruck <mark at wrapped dot cx >, thanks!

---
distrib/miniroot/install.sub revision 1.1151
etc/netstart revision 1.203
date: 2020/05/21 11:54:41; author: kn; state: Exp; lines: +2 -2;
Do not treat backslashe as an escape character in hostname.if(5) lines

ifstart() should always pass such lines unaltered, especially if they
contain "nwid" or "description" lines with arbitrary strings.

<bsdlisten at gmail dot com> reported SSIDs such as "Mike's" during
installation end as broken; this was because the installer escaped
the single quote using backslashes which ended up being treated as
escape characters much later during hostname.if parsing in netstart(8).

Ok deraadt


# 1.204 21-May-2020 kn

Fix stripcom() description wrt. comments not on their own line

Neither netstart's nor install.sub's (subtly different) implementations
remove trailing comments on lines not starting as a comment, e.g.,
lines like "up #not down" go through unaltered and without "#not down"
being removed.

Only lines *beginning* with the comment sign ("#") are stripped.

No functional change, just updating function descriptions.


# 1.203 21-May-2020 kn

Do not treat backslashe as an escape character in hostname.if(5) lines

ifstart() should always pass such lines unaltered, especially if they
contain "nwid" or "description" lines with arbitrary strings.

<bsdlisten at gmail dot com> reported SSIDs such as "Mike's" during
installation end as broken; this was because the installer escaped
the single quote using backslashes which ended up being treated as
escape characters much later during hostname.if parsing in netstart(8).

Ok deraadt


Revision tags: OPENBSD_6_7_BASE
# 1.202 15-Jan-2020 kn

Do not redirect already quiet stdout for IPv6 reject routes

"route -q" already silences all standard output; if it still prints
something, that's a bug to fix in route.

OK bluhm


# 1.201 25-Oct-2019 dlg

handle aggr(4) in the same way as trunk(4)

from brad@
ok bluhm@ claudio@ deraadt@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.200 29-Aug-2018 krw

Historically /etc/netstart (and the equivalent code in the install
script) did 'ifconfig <if> down' before starting dhclient(8). This was
a way of ensuring old running copies of dhclient were killed before a
new one started. Current dhclient does not need this assist, so change
"ifconfig <if> down" to "ifconfig <if> up" pending further script
optimizations.

Similar to a 2014 attempt by halex@. Prompted by a misc@ report
from Kristjan Komlosi reporting hanging diskless setups.

ok halex@ kn@


# 1.199 08-Jul-2018 tb

netstart is used during system start, but also interactively.
Show proper error message if a regular user executes netstart.
Only do the privilege check if the id binary is available,
which might not be the case during diskless system startup.

ok deraadt, jasper, jca, krw, rpe (who wrote the same diff), sthen


# 1.198 28-Apr-2018 rpe

Add a proper usage() function.

Suggested by and OK jmc.
OK tb


Revision tags: OPENBSD_6_3_BASE
# 1.197 04-Mar-2018 jmc

when -n is used, no need to spit out "Missing parameters." before
displaying usage();

ok tb


# 1.196 03-Mar-2018 landry

Lowercase 'usage' and group -n with interface in it.
From jmc@, ok tb@


# 1.195 21-Feb-2018 rpe

Tweak comments.

OK tb


# 1.194 19-Feb-2018 rpe

Write warning/error messages to stderr and end them with a fullstop.

OK tb


# 1.193 19-Feb-2018 rpe

- use specific patterns when looping over /etc/hostname.if files
to skip backup or temp files.
- test if the patterns matched actual files
- warn if ifcreate() fails on an interface and continue with the
subsequent interfaces in the list instead of return'ing

OK dlg sthen tb


# 1.192 17-Feb-2018 rpe

- Add descriptions for the new functions ifcreate() and vifscreate()
- In ifcreate() use the exit code of the {} block directly
- In vifscreate(), use the ifconfig -C output directly in the for _vif loop
- Remove superfluous and somewhat confusing comment

OK dlg kn sthen


# 1.191 14-Feb-2018 dlg

create virtual interfaces before starting all interface config.

this resolves an ordering problem when adding pseudo interfaces to bridges

tweaks from kn@
ok mpi@ sthen@


# 1.190 10-Feb-2018 claudio

Remove some special IPv4 in IPv6 mapped prefixes that are already rejected
by the ::0.0.0.0/96 reject route added to deny all IPv4 mapped addresses.
Makes the inet6 routing table almost fit in one screen.
OK benno@


# 1.189 10-Feb-2018 florian

Load RFC 7217 key material and generate if it does not already exist.

Add soii.key to changelist (pointed out by semarie) and mtree/special
(suggest by Craig Skinner).

OK naddy, sthen, rpe, tb


# 1.188 06-Feb-2018 tb

If -n is given, the netstart script should not (try to) set the default
route(s). Simply print the command(s) to be issued instead.

tweak & ok rpe


# 1.187 12-Nov-2017 tb

Remove HN_DIR variable and expand it in the only place it was used. It
currently serves no purpose.

ok rpe, agreement from deraadt and halex


Revision tags: OPENBSD_6_2_BASE
# 1.186 25-Jul-2017 rpe

Finally remove backwards compat code to support the 'rtsol' keyword
in hostname.if(5)

OK mpi@ deraadt@ florian@
OK jmc@ from doc perspective


# 1.185 21-Jul-2017 rpe

Align ifstart() in netstart and install.sub.

- in netstart, rename _file to _hn referencing hostname.if files
- in install.sub switch ifstart() to be used with _if instead of
_hn as parameter

ok krw@ tb@


# 1.184 28-May-2017 awolk

etc/netstart: use colon separator instead of dot with chown

OK jung@, deraadt@, jmc@


# 1.183 07-May-2017 rpe

Change test from [] to [[]] and simplify pattern.

OK tb@, krw@ (for [[]])
Feedback and OK halex@


# 1.182 07-May-2017 rpe

Replace hardcoded script name with ${0##*/}

OK tb@ halex@


# 1.181 01-May-2017 rpe

Revert r1.170 and remove the id==0 check.
The id binary is not available in nfs diskless setups at this point.

reported by Andreas Kusalananda, thanks.
discussed with deraadt@


# 1.180 01-May-2017 rpe

Remove last remnants of rtsol. IPv6 autoconfiguration of interfaces is now
done in ifstart(). Remove ipv6autoconf() and replace rtsolif with a boolean
variable V6_AUTOCONF. Replace dhcpif with a boolean variable V4_DHCPCONF.
Both are later used in defaultroute() to decide whether or not to configre
defaultroutes from /etc/mygate.

OK krw@


# 1.179 30-Apr-2017 mpi

Do not try to delete a default route before adding it.

Now that route are automatically G/C with the address they are attached
to there's no reason to duplicate the kernel's job.

Fix a regression introduced with multipath default routes.

ok deraadt@


# 1.178 25-Apr-2017 rpe

Unbreak netstart for multiple inteface configurations like trunk
or carp. Ensure that the noglob option is disabled at the end of
parse_hn_line() and ifstart().

Reported by Christer Solskogen and Stefan Wollny, thanks!


# 1.177 24-Apr-2017 rpe

Introduce a new function parse_hn_line() that replaces the existing
hostname.if(5) parsing code in ifstart().
Add a -n option to netstart to only print the interface configuration
commands instead of executing them.
Add a HN_DIR variable, that points to the directory of the hostname.if
files (default /etc) that allows for future regression tests.

- add new parse_hn_line() function
- change ifstart()
- rename $if to $_if
- don't ifconfig or ifconfig create if -n option is used
- replace hostname.if(5) parsing code with new parse_hn_line()
- just print configuration commands if -n option is used
- autoconf now happens in ifstart(), remove ifv6autoconf()
- introduce HN_DIR variable for the hostname.if file location
- add handling of the -n option to only print config commands
- ensure -n is only used if interfaces are specified as parameters

Discussed with and positive feedback from many
'commit' deraadt@
OK sthen@


# 1.176 08-Apr-2017 rpe

- localize the if, file and stat variables which also ensures that
variables are not named like commands.
- change test from [] to [[]]

OK tb@ halex@


# 1.175 07-Apr-2017 rpe

Minimize differences in ifstart() function between netstart and
install.sub which makes it easier to spot changes in the future.

- comments and formatting
- quotes on assignments are not needed (netstart)
- remove stray space in test (netstart)
- use $file variable with while-loop (netstart)
- although valid, instead of i use $i in arithmetic test (install.sub)

OK krw@, tb@
Looks good deraadt@


# 1.174 07-Apr-2017 rpe

Align comments of ifstart() function in netstart and install.sub.


# 1.173 07-Apr-2017 rpe

Align comments of stripcom() function in netstart and install.sub.


Revision tags: OPENBSD_6_1_BASE
# 1.172 06-Dec-2016 mpi

Do not lose the default route when netstart(8) is run a second time on
the interface pointed to by the default route.

Since the kernel no longer keep routes with dangling address pointer,
netstart(8) has to re-add the default route when the corresponding ifa
has been deleted and re-created.

deraadt@ points out that even if the previous semantic was not necessarily
better, a script like netstart(8) cannot totally fix the default route
problem.

Regression reported by and fix tested by Hrvoje Popovski.

ksh foo checked by halex@


# 1.171 27-Sep-2016 rzalamena

Delay switch(4) interface start up so it can attach virtual interfaces
like vether(4).

nits from and ok benno@, phessler@


# 1.170 09-Sep-2016 jasper

print a clear error message when not ran as root instead of just falling
through and try whatever it can do with the invoking user's perms

feedback/ok aja@ rpe@


Revision tags: OPENBSD_6_0_BASE
# 1.169 19-Jul-2016 mpi

Do not consider tap(4) a special interface and start if before other
pseudo-interfaces.

This unbreak vlan(4) on top of tap(4) since the refactoring to turn it
MP-safe.

ok claudio@, deraadt@


# 1.168 27-Mar-2016 sthen

Don't delete the 224/4 route in netstart, unless it's being done to ensure that
a -reject route can be added. Restores the ability to set an interface route
before daemons are started, lost during the previous simplification.
ok millert mpi


Revision tags: OPENBSD_5_9_BASE
# 1.167 29-Dec-2015 rpe

Remove backslash, not necessary after '&&'

OK halex@


# 1.166 29-Dec-2015 rpe

Replace last remaining `` with $()

OK halex@


# 1.165 18-Dec-2015 ajacoutot

Drop the now useless multicast setup comment.

prodded by tim@, ok mpi@


# 1.164 17-Dec-2015 ajacoutot

Simplify multicast option handling (10 less lines) by matching /etc/rc behavior
towards other YES|NO options and drop the error warning.


with and ok tim@, ok rpe@ on an earlier diff


# 1.163 05-Dec-2015 mpi

It does not make sense to insert a specific route for 224/4 when the
default one is good enough.

So merge rc.conf(8)'s 'multicast_router' and 'multicast_host' into a
single 'multicast'. If set to YES the reject route for 224/4 is not
inserted by netstart(8).

Manual bits from jmc@

ok henning@, ajacoutot@


# 1.162 12-Nov-2015 rpe

Changes to ifautostart():
- Rename function to ifv6autoconf() to make IPv6 relation clearer
- Localize and rename variables

OK krw@


# 1.161 12-Nov-2015 rpe

Changes to ifmstart():
- Change comments to make it clearer that ifmstart() takes two lists
of interface driver names (of which the second is optional) and not
the actual interface instances.
- Use localized variables and use slightly more verbose names.
- Use continue 2 to skip to the next hostname.if file.
- Use shell pattern @() instead of testing _sif individually.

OK krw@


# 1.160 12-Nov-2015 rpe

Changes to stripcom():
- Align comments with /etc/rc version
- Use localized variables
- Use safer "print -r --" instead of plain echo

Changes to ifstart():
- Tweak comment
- Add usage

OK krw@


# 1.159 01-Nov-2015 rpe

Start the rework of the /etc/netstart shell script.

General changes:
- apply a similar 'style' as used in the installer scripts
- improve comments to be more to the point, remove where code is obvious
- document usage of functions if they have arguments
- rename variables where it improves readability
- replace really old-school shell code with more contemporary idioms

Other changes:
- No need to care about "autoboot" because netstart doesn't inherit the
positional parameters from /etc/rc anymore. /etc/rc executes netstart
instead of sourcing it since r1.439.
- Use simpler for-loop to process list of interfaces with ifstart.

OK halex@


# 1.158 26-Oct-2015 rpe

The hostname variable is not used since r1.99. Remove it and use
stripcom() output directly with the hostname command.

OK deraadt@ krw@


# 1.157 23-Oct-2015 claudio

netstart bits for tap(4)


# 1.156 27-Sep-2015 sthen

Don't print output when setting autoconf on interfaces. Suggested by deraadt,
ok florian@ rpe@


# 1.155 13-Sep-2015 sthen

only print the "IPv6 autoconf" line if there are interfaces to configure
feedback/ok rpe


# 1.154 11-Sep-2015 sthen

Set "inet6 autoconf" individually on interfaces that have rtsol set in
hostname.if, previously netstart tried to configure them all at once
("ifconfig if0 if1 if2 inet6 autoconf"). From Delan Azabani, ok phessler@


Revision tags: OPENBSD_5_8_BASE
# 1.153 20-Jul-2015 rpe

Disable Strict Bourne shell mode for /etc/rc and /etc/netstart to be
able to use ksh syntax within these scripts. This way init doesn't
need to be changed, which starts /etc/rc using /bin/sh and people
can still use "sh /etc/netstart ifname".

Idea from and OK halex@
OK deraadt@ krw@ guenther@


# 1.152 19-Jul-2015 florian

Bring up pflow last as it might send with a source address that is on
any of the other interfaces.
OK deraadt, phessler, benno


# 1.151 19-Jul-2015 rpe

Always source rc.subr to be able to use the rc.conf parsing routine
to get the network related vars from rc.conf. This is even necessary
if netstart is run from within /etc/rc. Remove test of $INRC which
unintentionally evaluated always to true.

problem with previous change found by nigel@
OK sthen@ aja@ halex@


# 1.150 19-Jul-2015 ajacoutot

Revert 1.148 for now until I can talk to rpe@
It introduced a regression reported by nigel@


# 1.149 19-Jul-2015 rpe

Replace test command with [].

OK halex@ krw@


# 1.148 19-Jul-2015 rpe

Ensure, that we source rc.subr and parse rc.conf ONLY if we are not
inside /etc/rc.

With help from and OK halex@, ajacoutot@


# 1.147 18-Jul-2015 rpe

- remove trailing blanks introduced in previous commit
- no space in redirections like </foo or >$bar
- few other minor whitespaces

OK krw@


# 1.146 18-Jul-2015 rpe

Improve comments
- Add comments for functions
- Start comments with capital letters
- End comments with a full stop
- Allow comments to extend up to column 80

OK krw@


# 1.145 06-Jun-2015 florian

Allow rtsol keyword in hostname.if(5) with net.inet6.ip6.forwarding=1.
"inet6 autoconf" was working before and rtsol should behave the same.
OK phessler


Revision tags: OPENBSD_5_7_BASE
# 1.144 03-Dec-2014 florian

The kernel handles rtsol(8) functionality since some time now.
Treat rtsol in hostname.if as a keyword like dhcp and call ifconfig
inet6 autoconf.
"reads good" todd@
OK krw@ (who is *not* an IPv6 person), but I recruited him in his
capacity as an installer person.


# 1.143 28-Sep-2014 claudio

Revert 1.142. Without the down netstart will just print the ifconfig
output because it may end up just calling 'ifconfig $if'. This needs
to be done better and properly tested.


# 1.142 26-Sep-2014 halex

remove explicit 'down' of an interface before starting a dhcp request, thereby
avoiding annoying delays for some switch configurations

ok claudio@ deraadt@

i would add ok phessler@, but it was not valid without an ok krw@


Revision tags: OPENBSD_5_6_BASE
# 1.141 12-Jul-2014 stsp

Fix netstart after autoconf6 change so 'rtsol' lines in hostname.if work again.
found by pelikan@; ok pelikan@ henning@


# 1.140 12-Jul-2014 robert

Make rc.conf a parsed configuration file and stop sourcing it as a shell
script.
From now on rc.conf has a fixed syntax (key=val) and it is not allowed
to add anything to it besides the supported syntax, it all going to be
ignored.

discussed with and help from deraadt@ and halex@


Revision tags: OPENBSD_5_5_BASE
# 1.139 22-Aug-2013 mpi

Like for dhclient, do no create a route to alias addresses via 127.0.0.1.
Our stack is able to tell if the address is local or not.

ok todd@, krw@


Revision tags: OPENBSD_5_4_BASE
# 1.138 20-Mar-2013 todd

fix lies in netstart; replacement wording from halex@
pointed out by Ryan Kavannagh rak at debian dot org


Revision tags: OPENBSD_5_3_BASE
# 1.137 05-Dec-2012 rpe

remove "Invalid interface name" message
requested by krw@

ok halex@


# 1.136 02-Dec-2012 rpe

use the more compact version of the check for ifconfig'able interfaces
from install.sub

with feedback from and ok halex


# 1.135 02-Dec-2012 rpe

- remove isalphanumeric() and replace it with a shell pattern, that
tries a bit harder to identify invalid interface names and in
this case emit an error message.
- use [[ $1 == autoboot ]] to avoid a shell error message due to
possible spaces in first argument
- no change in functionality

discussed with krw and halex
ok ("I like this") krw


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.134 07-Oct-2011 deraadt

The new ypbind changes requires that the domainname be set before
rc.conf is run. There's no real downside.
ok aja


Revision tags: OPENBSD_5_0_BASE
# 1.133 07-Jul-2011 guenther

Eliminate some $? tests by rolling the command into the condition

ok halex@


# 1.132 26-May-2011 mpf

Add svlan(4) startup bits.
From markus@. OK naddy, claudio, reyk.


Revision tags: OPENBSD_4_9_BASE
# 1.131 09-Feb-2011 sobrado

fix an unbalanced parenthesis in a comment; while here, split the comment
in a better place to make it more readable.

ok jmc@ and miod@


Revision tags: OPENBSD_4_8_BASE
# 1.130 16-Jun-2010 todd

permit e.g. -inet6 syntax by slurping all lines not just some
noticed by rhsv6 at hushmail dot com, ok sthen@


Revision tags: OPENBSD_4_7_BASE
# 1.129 12-Jan-2010 henning

when setting up lo0 use 127.0.0.1/8 instead of 127.0.0.1 for clarity and
correctness. it's not 1992 any more, kids. ok mcbride dlg krw


# 1.128 10-Dec-2009 todd

o stop reordering ifconfig arguments (e.g. after 'up ..')
o only stop processing if inet or inet6 lines are malformed
o everything not a specially handled bit is passed to ifconfig unmangled
noticed by several after the move from bridgename.bridge0 -> hostname.bridge0
prodded by deraadt@, tested by and feedback from several
man page bits 'look fine' jmc@


# 1.127 22-Nov-2009 deraadt

Stop supporting bridgename.bridge* files, and move to hostname.bridge*
files. To cope with this change, read about the mv command.
ok claudio todd


# 1.126 17-Sep-2009 simon

change variable i to $i in an expression of ifstart() for consistency
with the rest of the file. no functional change.

feedback from sthen@, ok krw@


# 1.125 10-Jul-2009 jdixon

Delay creation of tun(4) interfaces until the underlying interface and
routes are available. This fixes usage for some OpenVPN users that start
it from hostname.tun*.

Tested by Johan Huldtgren. ok sthen@, johan@.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.124 25-Nov-2008 markus

delay /etc/netstart until IPv6-DAD (dup-address-detection) is completed.
ok fries, hshoexer, claudio


# 1.123 14-Aug-2008 sthen

Tools from /usr may not be used in netstart since it may be NFS-mounted
and not available at that time. Rewrite the hostname.if permission check
to use only /bin/ls and the shell. Requested by deraadt.

ok todd, "Twisted." deraadt


Revision tags: OPENBSD_4_4_BASE
# 1.122 23-Jul-2008 sthen

Prevent warning about insecure hostnames where no /etc/hostname.*
exists. From wcmaier@.

Check target of symbolic links to avoid noise at boot and in
seucrity output where you have several interfaces symlinked to one
config file.

"If you think this is the right thing to do" deraadt@


# 1.121 09-Jun-2008 todd

warn once not 3 times in case of a non existent file, discussed with deraadt
originally pointed out by Johan Torin


# 1.120 09-Jun-2008 deraadt

Ensure that hostname.* files are also re-chowned to root.wheel at each
boot as discussed with claudio while eating tasty donairs. ok todd


# 1.119 17-Apr-2008 deraadt

before using them, force hostname.* files to be unreadable by world
first version from todd, ok millert


Revision tags: OPENBSD_4_3_BASE
# 1.118 17-Jan-2008 brad

Execute rtsol after turning up trunk(4) and vlan(4) interfaces so they're
taken into consideration for rtsol.

ok reyk@ dlg@


# 1.117 09-Jan-2008 mpf

Do not bring up pfsync(4) before the working ruleset
has been loaded. Otherwise, states that are received during the
initial bulk update mismatch the correct pf-checksum and
do not attach to the rules.
Problem identified by david@. Fix done in collaboration.
OK henning@


Revision tags: OPENBSD_4_2_BASE
# 1.116 02-Aug-2007 david

move the delay for IPv6 DAD to after all interfaces have started
fixes problems with daemons being unable to bind to all addreses at boot
ok itojun@ hshoexer@


Revision tags: OPENBSD_4_1_BASE
# 1.115 15-Nov-2006 itojun

reject multicast packet without scope identifier specified.


Revision tags: OPENBSD_4_0_BASE
# 1.114 29-Jun-2006 todd

do not add an extra space; nwid and description come out wrong
fix as proposed by maja@, thanks!


Revision tags: OPENBSD_3_9_BASE
# 1.113 28-Dec-2005 david

nuke extra whitespace


# 1.112 06-Dec-2005 reyk

multicast_host=YES only works if a valid default gateway is available.
validate this condition and reject multicast traffic on failure.

ok todd@ naddy@


# 1.111 02-Nov-2005 todd

fix inspired by pr#4590
ok krw@


# 1.110 25-Oct-2005 todd

better logic from krw@:
- do not process mygate for v4 if dhcp
- do not process mygate for v6 if rtsol
this also makes the mygate processing logic more readable
ok krw@


# 1.109 14-Oct-2005 todd

add v6 support for /etc/mygate
ok deraadt@ mickey@ krw@
same functionality tested/ok'ed by by mickey, brad, matthieu, and me
with this one may now put a v6 IP in /etc/mygate on a separate line from
the v4 default gateway and netstart will do the right thing


# 1.108 12-Oct-2005 todd

shrink stripcom(), sync with install.sub
ok krw@


# 1.107 04-Oct-2005 todd

trunk must be started after physical ethernet devices, but before vlan.
populate ifmstart lines accordingly.
prodded/tested by brad@
ok reyk@


# 1.106 28-Sep-2005 todd

use eval consistently, fixes description quotes on rtsol and dhcp
fix inspired by and closes pr 4495
ok krw@


Revision tags: OPENBSD_3_8_BASE
# 1.105 22-May-2005 todd

Introduce 'ifmstart' to deal with starting multiple interfaces minus a list
of interfaces.

This reduces the netstart script by 174 chars, 13 words, and 19 lines, but
more importantly, makes it more simple and less cluttered should more special
case/orderings be needed.

ok brad@ and pr 4197 submitter, inspired by and closes pr 4197


# 1.104 04-Apr-2005 djm

unbreak; ok pval@


# 1.103 03-Apr-2005 deraadt

if dhcp is used to get an address on any interface, ignore /etc/mygate
ok krw
(this lets us do something rather cool with the zaurus in particular)


Revision tags: OPENBSD_3_7_BASE
# 1.102 04-Jan-2005 mcbride

Bring up the carp(4) interface before default route.

ok pascoe@ mpf@


# 1.101 30-Dec-2004 millert

Add a copy of stripcom so /etc/netstart can be run standalone again.
OK deraadt@


# 1.100 19-Dec-2004 millert

Allow comments in /etc/{myname,mygate,defaultdomain}; OK deraadt@


# 1.99 04-Dec-2004 itojun

remove "route $hostname 127.0.0.1" line. deraadt ok
*** please update /etc/netstart and test if it works ok for you ***


# 1.98 20-Oct-2004 deraadt

make all route commands use -qn; ok mcbride henning


Revision tags: OPENBSD_3_6_BASE
# 1.97 29-May-2004 deraadt

one last route command lacking -qn


Revision tags: OPENBSD_3_5_BASE
# 1.96 22-Mar-2004 mcbride

Make sure pfsync is brought up before carp.

ok deraadt@


# 1.95 13-Mar-2004 mcbride

Delay pfsync(4) configuration, as the syncif has to be configured in
advance. From Thorsten Lockert.


# 1.94 14-Jan-2004 deraadt

ok, it took quite a bit of prodding but itojun finally explained why the
extra sleep 1 is in here, and we came to the conclusion it is safe to
delete it. whee.


# 1.93 13-Jan-2004 deraadt

repair v6 lo0 documentation


# 1.92 11-Jan-2004 deraadt

add loopback routes late


# 1.91 09-Jan-2004 deraadt

create all routes with -q; markus ok


# 1.90 04-Dec-2003 millert

Need to do "ifconfig create" for bridge interfaces too.


# 1.89 03-Dec-2003 markus

add support for ifconfig clone; from netbsd; ok deraadt, henning


# 1.88 20-Oct-2003 david

delay carp initialization until after physical interfaces are configured
ok mcbride@ henning@ deraadt@ todd@


Revision tags: OPENBSD_3_4_BASE
# 1.87 27-Aug-2003 henning

only try to set hostname to what /etc/myname says if that file actually exists,
otherwise preserve `hostname`
netbooted machines can live perfectly fine without it; they get their hostname
earlier.

ok krw@ cedric@


Revision tags: OPENBSD_3_3_BASE
# 1.86 16-Feb-2003 krw

Fix up some DNS verbiage to make it consistant.

Fix up default route selection by

a) Forcing user to explicitly chose 'dhcp' as a mechanism for
specifying a default route, rather than guessing based on one or more
interfaces being configured by dhcp.

b) If the user specified default route does not work, re-present the
existing default route rather than losing it.

c) Move default route selection to after nameserver activation so the
user can specify a hostname as the default route.

Change /etc/netstart so that /etc/mygate wins if a default route was
already specified (i.e. by dhcp).

ok deraadt@.


Revision tags: OPENBSD_3_2_BASE
# 1.85 16-May-2002 todd

ignore non-existent cases where '$if' evaluates to '*'.
From Andr� Lucas <andre@ae-35.com>, fixes pr # 2658.
'Looks good' from miod@, millert@, and krw@.


Revision tags: OPENBSD_3_1_BASE
# 1.84 23-Feb-2002 deraadt

re-add support for $if expansion; hamajima@nagoya.ydc.co.jp


# 1.83 21-Feb-2002 miod

Change the network components initialization order.
Change from:
o all interfaces
o all bridges
o routes
to:
o physical interfaces
o routes
o gif and gre interfaces
o bridges

Fixeski PR #2400.
Manual page updates coming soon.
Ok angelos@ chris@ deraadt@


Revision tags: OPENBSD_3_0_BASE
# 1.82 31-Jul-2001 hugh

a space before a redirect


# 1.81 06-Jul-2001 angelos

Also, source /etc/rc.conf so we can pull in the
multicast_host/multicast_router settings; this is useful if one
flushes the routing table and re-initializes.

We really need a netconfig tool of sorts.


# 1.80 06-Jul-2001 angelos

Use "route -n show -inet" to determine the default multicast iface.


# 1.79 03-Jul-2001 deraadt

pull in rc.conf early so that pf(1) startup is right; tested by jasoni, comments from millert


# 1.78 30-May-2001 deraadt

Remove ipf. Darren Reed has interpreted his (old, new, whichever)
licence in a way that makes ipf not free according to the rules we
established over 5 years ago, at www.openbsd.org/goals.html (and those
same basic rules govern the other *BSD projects too). Specifically,
Darren says that modified versions are not permitted. But software
which OpenBSD uses and redistributes must be free to all (be they
people or companies), for any purpose they wish to use it, including
modification, use, peeing on, or even integration into baby mulching
machines or atomic bombs to be dropped on Australia. Furthermore, we
know of a number of companies using ipf with modification like us, who
are now in the same situation, and we hope that some of them will work
with us to fill this gap that now exists in OpenBSD (temporarily, we
hope).


Revision tags: OPENBSD_2_9_BASE
# 1.77 13-Mar-2001 deraadt

spelling; maurice@maurice.wan.nl


# 1.76 06-Feb-2001 todd

ignore blank lines in addition to comments
fixes pr#1660 from wilfried@telia.com .. Thanks!


# 1.75 10-Jan-2001 jason

support !command in bridgename.if files, too


# 1.74 27-Nov-2000 millert

Use -n to test if a variable is non-zero. Otherwise, if the variable's
contents start with a '-' test becomes unhappy (since it interprets it
as another option).


# 1.73 08-Nov-2000 todd

This fixes pr 1481, we now handle args > 6 in /etc/hostname.if in the
cases where we did not previously handle them.
Thanks to Scott Atwood <atwood@cs.stanford.edu> for reminding us of this.


Revision tags: OPENBSD_2_8_BASE
# 1.72 02-Sep-2000 todd

subtle bug .. global variables in a while loop need reset 'just incase'
With:
hostname.fxp0 having a last line of:
inet6 alias 3ffe:...
and hostname.gif0 having a first two lines of:
giftunnel 1.2.3.4
dest 1.2.4.3
We end up with the command:
ifconfig gif0 giftunnel alias 1.2.3.4 1.2.4.3
.. which is clearly wrong and fixed by this change


# 1.71 18-Jun-2000 todd

rc.conf now parses ${local_rcconf} internally; closes pr 1259


Revision tags: OPENBSD_2_7_BASE
# 1.70 08-May-2000 todd

fix dhcp 'NONE' ness from install to allow media parsing to work
.. ok deraadt@, millert@


# 1.69 21-Apr-2000 deraadt

rc.conf.local support, inspired by chuck yerkes


# 1.68 04-Apr-2000 millert

Remove the -E flag from ipf as it is implicitly enabled and using
the -E flag here causes the kernel to printf 'IP Filter: already
initialized'.


# 1.67 18-Mar-2000 deraadt

silence all extra route addition printouts


# 1.66 17-Mar-2000 itojun

correct reject route installations for IPv6. improve comments.


# 1.65 12-Mar-2000 itojun

disallow packets to malicious 6to4 prefix, based on
http://playground.iijlab.net/i-d/draft-itojun-ipv6-transition-abuse-00.txt


# 1.64 10-Mar-2000 todd

fix non behavior
with this `!' lines in /etc/hostname.* run even without certain lines
(like a comment) preceeding it.


# 1.63 10-Jan-2000 todd

allow arbitrary commands in /etc/hostname.* files if the line starts with '!'


# 1.62 02-Jan-2000 deraadt

rtsol case can configure the interface up, since it would be nice to finish
DAD before the actual rtsol(8) run happens later. and since it will rtsol,
it is going to be up in any case.


# 1.61 02-Jan-2000 itojun

one more indentation fix.


# 1.60 02-Jan-2000 itojun

indentation fix (todd's part)


# 1.59 02-Jan-2000 todd

fix rtsold case, reset cmd for each iteration!


# 1.58 02-Jan-2000 itojun

allow options after "rtsol".
XXX both "dhcp" and "rtsol" has keyword *down* at the end. is it okay?


# 1.57 02-Jan-2000 itojun

echo "IPv6 autoconf: interfaces" before invoking rtsol.
sleep for net.inet6.ip6.dad_count seconds to ensure that IPv6 DAD is completed.
TODO: rtsold (rc.conf line), manpage


# 1.56 02-Jan-2000 itojun

ipv6 autoconf on hosts (non-routers).

to do this,
1. in sysctl.conf, add these lines:
net.inet6.ip6.forwarding=0
net.inet6.ip6.accept_rtadv=1
2. in hostname.foo, add
rtsol

specifying two or more interfaces with "rtsol" may result in strange
behavior - ipv6 spec does not permit multi-interface node to be autoconfig'ed.


# 1.55 02-Jan-2000 todd

add to hostname.* parsing:
- multiple entries support (read: aliases)
- inet6 support
- support for comments (#)
(look for hostname.if(5) commit for syntax details)


# 1.54 31-Dec-1999 itojun

install IPv6 reject routes only if kernel is capable of IPv6.


# 1.53 09-Dec-1999 itojun

avoid transmitting invalid IPv6 packets out to the wire.


# 1.52 09-Dec-1999 itojun

do not perform IPv6 initialization for loopback interface.
MUST make lo0 up before any IPv6 operations.
it will be considered a pilot error if you don't.
(I prefer to have lo0 initialized automatically)


Revision tags: OPENBSD_2_6_BASE
# 1.51 01-Sep-1999 deraadt

support # characters in bridgename.* files; millert


# 1.50 01-Sep-1999 deraadt

cleanup parsing of hostname.* files, and seperate bridge control into
bridgename.* files; all documented in new hostname.if(5) and
bridgename.if(5) man pages


# 1.49 09-Aug-1999 angelos

Only parse/setup the hostname.foo file if interface foo exists (this
is useful for laptops with different ethernet cards etc.)


Revision tags: OPENBSD_2_5_BASE
# 1.48 29-Mar-1999 niklas

New multicast route setup style


# 1.47 26-Mar-1999 niklas

Add bridge interface handling


# 1.46 01-Mar-1999 millert

Add support in /etc/hostname.xxx for files of the format:
up [options]
Any of the following may or may not be set:
$name $mask $bcaddr $extras


# 1.45 28-Oct-1998 millert

Kill the awful hack used to match and split /etc/hostname.* We now use
a function, isalphanumeric, to determine whether an interface name is
likely to be valid. This means that things like /etc/hostname.le0.bak,
/etc/hostname.le0#, /etc/hostname.le0~, etc. will be ignored as they
should. There is no longer an implicate assumption that /etc/hostname.*
only contains a single '.'.


Revision tags: OPENBSD_2_4_BASE
# 1.44 06-Oct-1998 deraadt

move ipnat to end of netstart, to support dhcp+ipnat


# 1.43 18-Sep-1998 deraadt

apply media directives on dhcp interfaces


# 1.42 10-Sep-1998 marc

better way of handling dhcp client; Jason Ish <jbi130@mail.usask.ca>


# 1.41 08-Sep-1998 marc

dhcp client stuff. "Angelos D. Keromytis" <angelos@dsl.cis.upenn.edu>


# 1.40 24-Aug-1998 downsj

You can't use -interface default when there's no default gateway
set (yet). Use -interface $hostname if mygate doesn't exist so that
this actually works on routers.


# 1.39 04-Jul-1998 deraadt

put 224 route on default, to avoid a hostname lookup


# 1.38 22-May-1998 deraadt

use route -n, what the heck


Revision tags: OPENBSD_2_3_BASE
# 1.37 28-Mar-1998 deraadt

s/^nat/ipnat/


# 1.36 23-Feb-1998 niklas

remove trailing blank line


# 1.35 07-Feb-1998 deraadt

ipforward is in sysctl.conf now


# 1.34 21-Dec-1997 deraadt

ugh


# 1.33 20-Dec-1997 deraadt

ipforwarding option in rc.conf


# 1.32 29-Nov-1997 kstailey

NAT requires IPF


# 1.31 04-Nov-1997 deraadt

kill spaces at ends of lines; m4


Revision tags: OPENBSD_2_2_BASE
# 1.30 14-Oct-1997 deraadt

set hostname/domainname before running rc.conf; m4@umn.edu


# 1.29 04-Sep-1997 deraadt

fork netstart; new child is rc.conf


# 1.28 25-Aug-1997 millert

Explicately pass -host flag to route(8) to avoid confusion with networks.


# 1.27 19-Aug-1997 niklas

Add hook for rpc.lockd, make nfsd flags settable in netstart


# 1.26 31-Jul-1997 downsj

Make quotas optional; wedged into netstart for the time being.
/etc/rc.conf, anyone?


# 1.25 30-Jul-1997 deraadt

do not run routed by default


# 1.24 28-Jul-1997 kstailey

Move configuration of loopback interface to before all other interfaces.
Allows the use of local caching-only nameserver with no "nameserver"
entry in /etc/resolv.conf to configure a route between the hostname
and loopback.


# 1.23 25-Jul-1997 provos

earlier start of keymanagement


# 1.22 24-Jul-1997 deraadt

make amd use /tmp_mnt by default


# 1.21 22-Jul-1997 provos

start the photuris daemon per default. hilfe.


# 1.20 17-Jun-1997 niklas

Put in hooks to start ypserv with flags


# 1.19 17-Jun-1997 niklas

Put in hooks to start rpc.yppasswdd with flags


Revision tags: OPENBSD_2_1_BASE
# 1.18 15-Apr-1997 deraadt

kill route flush until .. hmm kernel routing socket bug or something


# 1.17 09-Apr-1997 kstailey

add NAT startup


# 1.16 07-Apr-1997 rees

flush all old routes before adding new interfaces or routes.
ref: netbsd pr3228/misc, Matthias Scheler


# 1.15 03-Mar-1997 downsj

fix typo


# 1.14 11-Feb-1997 deraadt

add default route before fiddling with loopback route to avoid DNS problems; m4@umn.edu, #97


# 1.13 03-Feb-1997 deraadt

do ifaliases after /usr/bin exists in nfs diskless env; pr#77, matthieu@laas.fr


# 1.12 02-Nov-1996 deraadt

timed off by default


Revision tags: OPENBSD_2_0_BASE
# 1.11 23-Sep-1996 deraadt

rfc1323 variable


# 1.10 04-Sep-1996 deraadt

control portmap, inetd, and lpd from netstart; idea from tqbf@enteract.com


# 1.9 27-Aug-1996 deraadt

224.0.0.0 not 0.0.0.224; from peter@demon.net


# 1.8 18-Jun-1996 deraadt

move std stuff from rc.local to rc


# 1.7 16-Jun-1996 deraadt

install sample commented /etc/ifaliases file; which can now contain #
comments and blank lines. new format is "interface address netmask"
(yes, i changed the order of the entries). inspired by netbsd pr#2474;
gillhaa@ghost.whirlpool.com


# 1.6 02-Jun-1996 tholo

Install a multicast route by default


# 1.5 26-May-1996 deraadt

sync & label


# 1.4 09-Jan-1996 dm

added IP filter to netstat/rc and put examples in /usr/share/ipf


# 1.3 30-Dec-1995 deraadt

from netbsd: start mrouted like routed


# 1.2 18-Dec-1995 deraadt

/etc/ifaliases support by randy@zyzzyva.com


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.206 21-Jun-2020 dlg

start wg with the other interfaces that rely on routing being up.

from Matt Dunwoodie and Jason A. Donenfeld

ok deraadt@


# 1.205 22-May-2020 kn

Revert the following commit as it breaks hostname.if(5) lines with a
backslash at the end for line continuation

Breaking long lines into multiple ones must still be possible and does
require to treat the backslash as an escape character.

Breakage reported by Mark Patruck <mark at wrapped dot cx >, thanks!

---
distrib/miniroot/install.sub revision 1.1151
etc/netstart revision 1.203
date: 2020/05/21 11:54:41; author: kn; state: Exp; lines: +2 -2;
Do not treat backslashe as an escape character in hostname.if(5) lines

ifstart() should always pass such lines unaltered, especially if they
contain "nwid" or "description" lines with arbitrary strings.

<bsdlisten at gmail dot com> reported SSIDs such as "Mike's" during
installation end as broken; this was because the installer escaped
the single quote using backslashes which ended up being treated as
escape characters much later during hostname.if parsing in netstart(8).

Ok deraadt


# 1.204 21-May-2020 kn

Fix stripcom() description wrt. comments not on their own line

Neither netstart's nor install.sub's (subtly different) implementations
remove trailing comments on lines not starting as a comment, e.g.,
lines like "up #not down" go through unaltered and without "#not down"
being removed.

Only lines *beginning* with the comment sign ("#") are stripped.

No functional change, just updating function descriptions.


# 1.203 21-May-2020 kn

Do not treat backslashe as an escape character in hostname.if(5) lines

ifstart() should always pass such lines unaltered, especially if they
contain "nwid" or "description" lines with arbitrary strings.

<bsdlisten at gmail dot com> reported SSIDs such as "Mike's" during
installation end as broken; this was because the installer escaped
the single quote using backslashes which ended up being treated as
escape characters much later during hostname.if parsing in netstart(8).

Ok deraadt


Revision tags: OPENBSD_6_7_BASE
# 1.202 15-Jan-2020 kn

Do not redirect already quiet stdout for IPv6 reject routes

"route -q" already silences all standard output; if it still prints
something, that's a bug to fix in route.

OK bluhm


# 1.201 25-Oct-2019 dlg

handle aggr(4) in the same way as trunk(4)

from brad@
ok bluhm@ claudio@ deraadt@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.200 29-Aug-2018 krw

Historically /etc/netstart (and the equivalent code in the install
script) did 'ifconfig <if> down' before starting dhclient(8). This was
a way of ensuring old running copies of dhclient were killed before a
new one started. Current dhclient does not need this assist, so change
"ifconfig <if> down" to "ifconfig <if> up" pending further script
optimizations.

Similar to a 2014 attempt by halex@. Prompted by a misc@ report
from Kristjan Komlosi reporting hanging diskless setups.

ok halex@ kn@


# 1.199 08-Jul-2018 tb

netstart is used during system start, but also interactively.
Show proper error message if a regular user executes netstart.
Only do the privilege check if the id binary is available,
which might not be the case during diskless system startup.

ok deraadt, jasper, jca, krw, rpe (who wrote the same diff), sthen


# 1.198 28-Apr-2018 rpe

Add a proper usage() function.

Suggested by and OK jmc.
OK tb


Revision tags: OPENBSD_6_3_BASE
# 1.197 04-Mar-2018 jmc

when -n is used, no need to spit out "Missing parameters." before
displaying usage();

ok tb


# 1.196 03-Mar-2018 landry

Lowercase 'usage' and group -n with interface in it.
From jmc@, ok tb@


# 1.195 21-Feb-2018 rpe

Tweak comments.

OK tb


# 1.194 19-Feb-2018 rpe

Write warning/error messages to stderr and end them with a fullstop.

OK tb


# 1.193 19-Feb-2018 rpe

- use specific patterns when looping over /etc/hostname.if files
to skip backup or temp files.
- test if the patterns matched actual files
- warn if ifcreate() fails on an interface and continue with the
subsequent interfaces in the list instead of return'ing

OK dlg sthen tb


# 1.192 17-Feb-2018 rpe

- Add descriptions for the new functions ifcreate() and vifscreate()
- In ifcreate() use the exit code of the {} block directly
- In vifscreate(), use the ifconfig -C output directly in the for _vif loop
- Remove superfluous and somewhat confusing comment

OK dlg kn sthen


# 1.191 14-Feb-2018 dlg

create virtual interfaces before starting all interface config.

this resolves an ordering problem when adding pseudo interfaces to bridges

tweaks from kn@
ok mpi@ sthen@


# 1.190 10-Feb-2018 claudio

Remove some special IPv4 in IPv6 mapped prefixes that are already rejected
by the ::0.0.0.0/96 reject route added to deny all IPv4 mapped addresses.
Makes the inet6 routing table almost fit in one screen.
OK benno@


# 1.189 10-Feb-2018 florian

Load RFC 7217 key material and generate if it does not already exist.

Add soii.key to changelist (pointed out by semarie) and mtree/special
(suggest by Craig Skinner).

OK naddy, sthen, rpe, tb


# 1.188 06-Feb-2018 tb

If -n is given, the netstart script should not (try to) set the default
route(s). Simply print the command(s) to be issued instead.

tweak & ok rpe


# 1.187 12-Nov-2017 tb

Remove HN_DIR variable and expand it in the only place it was used. It
currently serves no purpose.

ok rpe, agreement from deraadt and halex


Revision tags: OPENBSD_6_2_BASE
# 1.186 25-Jul-2017 rpe

Finally remove backwards compat code to support the 'rtsol' keyword
in hostname.if(5)

OK mpi@ deraadt@ florian@
OK jmc@ from doc perspective


# 1.185 21-Jul-2017 rpe

Align ifstart() in netstart and install.sub.

- in netstart, rename _file to _hn referencing hostname.if files
- in install.sub switch ifstart() to be used with _if instead of
_hn as parameter

ok krw@ tb@


# 1.184 28-May-2017 awolk

etc/netstart: use colon separator instead of dot with chown

OK jung@, deraadt@, jmc@


# 1.183 07-May-2017 rpe

Change test from [] to [[]] and simplify pattern.

OK tb@, krw@ (for [[]])
Feedback and OK halex@


# 1.182 07-May-2017 rpe

Replace hardcoded script name with ${0##*/}

OK tb@ halex@


# 1.181 01-May-2017 rpe

Revert r1.170 and remove the id==0 check.
The id binary is not available in nfs diskless setups at this point.

reported by Andreas Kusalananda, thanks.
discussed with deraadt@


# 1.180 01-May-2017 rpe

Remove last remnants of rtsol. IPv6 autoconfiguration of interfaces is now
done in ifstart(). Remove ipv6autoconf() and replace rtsolif with a boolean
variable V6_AUTOCONF. Replace dhcpif with a boolean variable V4_DHCPCONF.
Both are later used in defaultroute() to decide whether or not to configre
defaultroutes from /etc/mygate.

OK krw@


# 1.179 30-Apr-2017 mpi

Do not try to delete a default route before adding it.

Now that route are automatically G/C with the address they are attached
to there's no reason to duplicate the kernel's job.

Fix a regression introduced with multipath default routes.

ok deraadt@


# 1.178 25-Apr-2017 rpe

Unbreak netstart for multiple inteface configurations like trunk
or carp. Ensure that the noglob option is disabled at the end of
parse_hn_line() and ifstart().

Reported by Christer Solskogen and Stefan Wollny, thanks!


# 1.177 24-Apr-2017 rpe

Introduce a new function parse_hn_line() that replaces the existing
hostname.if(5) parsing code in ifstart().
Add a -n option to netstart to only print the interface configuration
commands instead of executing them.
Add a HN_DIR variable, that points to the directory of the hostname.if
files (default /etc) that allows for future regression tests.

- add new parse_hn_line() function
- change ifstart()
- rename $if to $_if
- don't ifconfig or ifconfig create if -n option is used
- replace hostname.if(5) parsing code with new parse_hn_line()
- just print configuration commands if -n option is used
- autoconf now happens in ifstart(), remove ifv6autoconf()
- introduce HN_DIR variable for the hostname.if file location
- add handling of the -n option to only print config commands
- ensure -n is only used if interfaces are specified as parameters

Discussed with and positive feedback from many
'commit' deraadt@
OK sthen@


# 1.176 08-Apr-2017 rpe

- localize the if, file and stat variables which also ensures that
variables are not named like commands.
- change test from [] to [[]]

OK tb@ halex@


# 1.175 07-Apr-2017 rpe

Minimize differences in ifstart() function between netstart and
install.sub which makes it easier to spot changes in the future.

- comments and formatting
- quotes on assignments are not needed (netstart)
- remove stray space in test (netstart)
- use $file variable with while-loop (netstart)
- although valid, instead of i use $i in arithmetic test (install.sub)

OK krw@, tb@
Looks good deraadt@


# 1.174 07-Apr-2017 rpe

Align comments of ifstart() function in netstart and install.sub.


# 1.173 07-Apr-2017 rpe

Align comments of stripcom() function in netstart and install.sub.


Revision tags: OPENBSD_6_1_BASE
# 1.172 06-Dec-2016 mpi

Do not lose the default route when netstart(8) is run a second time on
the interface pointed to by the default route.

Since the kernel no longer keep routes with dangling address pointer,
netstart(8) has to re-add the default route when the corresponding ifa
has been deleted and re-created.

deraadt@ points out that even if the previous semantic was not necessarily
better, a script like netstart(8) cannot totally fix the default route
problem.

Regression reported by and fix tested by Hrvoje Popovski.

ksh foo checked by halex@


# 1.171 27-Sep-2016 rzalamena

Delay switch(4) interface start up so it can attach virtual interfaces
like vether(4).

nits from and ok benno@, phessler@


# 1.170 09-Sep-2016 jasper

print a clear error message when not ran as root instead of just falling
through and try whatever it can do with the invoking user's perms

feedback/ok aja@ rpe@


Revision tags: OPENBSD_6_0_BASE
# 1.169 19-Jul-2016 mpi

Do not consider tap(4) a special interface and start if before other
pseudo-interfaces.

This unbreak vlan(4) on top of tap(4) since the refactoring to turn it
MP-safe.

ok claudio@, deraadt@


# 1.168 27-Mar-2016 sthen

Don't delete the 224/4 route in netstart, unless it's being done to ensure that
a -reject route can be added. Restores the ability to set an interface route
before daemons are started, lost during the previous simplification.
ok millert mpi


Revision tags: OPENBSD_5_9_BASE
# 1.167 29-Dec-2015 rpe

Remove backslash, not necessary after '&&'

OK halex@


# 1.166 29-Dec-2015 rpe

Replace last remaining `` with $()

OK halex@


# 1.165 18-Dec-2015 ajacoutot

Drop the now useless multicast setup comment.

prodded by tim@, ok mpi@


# 1.164 17-Dec-2015 ajacoutot

Simplify multicast option handling (10 less lines) by matching /etc/rc behavior
towards other YES|NO options and drop the error warning.


with and ok tim@, ok rpe@ on an earlier diff


# 1.163 05-Dec-2015 mpi

It does not make sense to insert a specific route for 224/4 when the
default one is good enough.

So merge rc.conf(8)'s 'multicast_router' and 'multicast_host' into a
single 'multicast'. If set to YES the reject route for 224/4 is not
inserted by netstart(8).

Manual bits from jmc@

ok henning@, ajacoutot@


# 1.162 12-Nov-2015 rpe

Changes to ifautostart():
- Rename function to ifv6autoconf() to make IPv6 relation clearer
- Localize and rename variables

OK krw@


# 1.161 12-Nov-2015 rpe

Changes to ifmstart():
- Change comments to make it clearer that ifmstart() takes two lists
of interface driver names (of which the second is optional) and not
the actual interface instances.
- Use localized variables and use slightly more verbose names.
- Use continue 2 to skip to the next hostname.if file.
- Use shell pattern @() instead of testing _sif individually.

OK krw@


# 1.160 12-Nov-2015 rpe

Changes to stripcom():
- Align comments with /etc/rc version
- Use localized variables
- Use safer "print -r --" instead of plain echo

Changes to ifstart():
- Tweak comment
- Add usage

OK krw@


# 1.159 01-Nov-2015 rpe

Start the rework of the /etc/netstart shell script.

General changes:
- apply a similar 'style' as used in the installer scripts
- improve comments to be more to the point, remove where code is obvious
- document usage of functions if they have arguments
- rename variables where it improves readability
- replace really old-school shell code with more contemporary idioms

Other changes:
- No need to care about "autoboot" because netstart doesn't inherit the
positional parameters from /etc/rc anymore. /etc/rc executes netstart
instead of sourcing it since r1.439.
- Use simpler for-loop to process list of interfaces with ifstart.

OK halex@


# 1.158 26-Oct-2015 rpe

The hostname variable is not used since r1.99. Remove it and use
stripcom() output directly with the hostname command.

OK deraadt@ krw@


# 1.157 23-Oct-2015 claudio

netstart bits for tap(4)


# 1.156 27-Sep-2015 sthen

Don't print output when setting autoconf on interfaces. Suggested by deraadt,
ok florian@ rpe@


# 1.155 13-Sep-2015 sthen

only print the "IPv6 autoconf" line if there are interfaces to configure
feedback/ok rpe


# 1.154 11-Sep-2015 sthen

Set "inet6 autoconf" individually on interfaces that have rtsol set in
hostname.if, previously netstart tried to configure them all at once
("ifconfig if0 if1 if2 inet6 autoconf"). From Delan Azabani, ok phessler@


Revision tags: OPENBSD_5_8_BASE
# 1.153 20-Jul-2015 rpe

Disable Strict Bourne shell mode for /etc/rc and /etc/netstart to be
able to use ksh syntax within these scripts. This way init doesn't
need to be changed, which starts /etc/rc using /bin/sh and people
can still use "sh /etc/netstart ifname".

Idea from and OK halex@
OK deraadt@ krw@ guenther@


# 1.152 19-Jul-2015 florian

Bring up pflow last as it might send with a source address that is on
any of the other interfaces.
OK deraadt, phessler, benno


# 1.151 19-Jul-2015 rpe

Always source rc.subr to be able to use the rc.conf parsing routine
to get the network related vars from rc.conf. This is even necessary
if netstart is run from within /etc/rc. Remove test of $INRC which
unintentionally evaluated always to true.

problem with previous change found by nigel@
OK sthen@ aja@ halex@


# 1.150 19-Jul-2015 ajacoutot

Revert 1.148 for now until I can talk to rpe@
It introduced a regression reported by nigel@


# 1.149 19-Jul-2015 rpe

Replace test command with [].

OK halex@ krw@


# 1.148 19-Jul-2015 rpe

Ensure, that we source rc.subr and parse rc.conf ONLY if we are not
inside /etc/rc.

With help from and OK halex@, ajacoutot@


# 1.147 18-Jul-2015 rpe

- remove trailing blanks introduced in previous commit
- no space in redirections like </foo or >$bar
- few other minor whitespaces

OK krw@


# 1.146 18-Jul-2015 rpe

Improve comments
- Add comments for functions
- Start comments with capital letters
- End comments with a full stop
- Allow comments to extend up to column 80

OK krw@


# 1.145 06-Jun-2015 florian

Allow rtsol keyword in hostname.if(5) with net.inet6.ip6.forwarding=1.
"inet6 autoconf" was working before and rtsol should behave the same.
OK phessler


Revision tags: OPENBSD_5_7_BASE
# 1.144 03-Dec-2014 florian

The kernel handles rtsol(8) functionality since some time now.
Treat rtsol in hostname.if as a keyword like dhcp and call ifconfig
inet6 autoconf.
"reads good" todd@
OK krw@ (who is *not* an IPv6 person), but I recruited him in his
capacity as an installer person.


# 1.143 28-Sep-2014 claudio

Revert 1.142. Without the down netstart will just print the ifconfig
output because it may end up just calling 'ifconfig $if'. This needs
to be done better and properly tested.


# 1.142 26-Sep-2014 halex

remove explicit 'down' of an interface before starting a dhcp request, thereby
avoiding annoying delays for some switch configurations

ok claudio@ deraadt@

i would add ok phessler@, but it was not valid without an ok krw@


Revision tags: OPENBSD_5_6_BASE
# 1.141 12-Jul-2014 stsp

Fix netstart after autoconf6 change so 'rtsol' lines in hostname.if work again.
found by pelikan@; ok pelikan@ henning@


# 1.140 12-Jul-2014 robert

Make rc.conf a parsed configuration file and stop sourcing it as a shell
script.
From now on rc.conf has a fixed syntax (key=val) and it is not allowed
to add anything to it besides the supported syntax, it all going to be
ignored.

discussed with and help from deraadt@ and halex@


Revision tags: OPENBSD_5_5_BASE
# 1.139 22-Aug-2013 mpi

Like for dhclient, do no create a route to alias addresses via 127.0.0.1.
Our stack is able to tell if the address is local or not.

ok todd@, krw@


Revision tags: OPENBSD_5_4_BASE
# 1.138 20-Mar-2013 todd

fix lies in netstart; replacement wording from halex@
pointed out by Ryan Kavannagh rak at debian dot org


Revision tags: OPENBSD_5_3_BASE
# 1.137 05-Dec-2012 rpe

remove "Invalid interface name" message
requested by krw@

ok halex@


# 1.136 02-Dec-2012 rpe

use the more compact version of the check for ifconfig'able interfaces
from install.sub

with feedback from and ok halex


# 1.135 02-Dec-2012 rpe

- remove isalphanumeric() and replace it with a shell pattern, that
tries a bit harder to identify invalid interface names and in
this case emit an error message.
- use [[ $1 == autoboot ]] to avoid a shell error message due to
possible spaces in first argument
- no change in functionality

discussed with krw and halex
ok ("I like this") krw


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.134 07-Oct-2011 deraadt

The new ypbind changes requires that the domainname be set before
rc.conf is run. There's no real downside.
ok aja


Revision tags: OPENBSD_5_0_BASE
# 1.133 07-Jul-2011 guenther

Eliminate some $? tests by rolling the command into the condition

ok halex@


# 1.132 26-May-2011 mpf

Add svlan(4) startup bits.
From markus@. OK naddy, claudio, reyk.


Revision tags: OPENBSD_4_9_BASE
# 1.131 09-Feb-2011 sobrado

fix an unbalanced parenthesis in a comment; while here, split the comment
in a better place to make it more readable.

ok jmc@ and miod@


Revision tags: OPENBSD_4_8_BASE
# 1.130 16-Jun-2010 todd

permit e.g. -inet6 syntax by slurping all lines not just some
noticed by rhsv6 at hushmail dot com, ok sthen@


Revision tags: OPENBSD_4_7_BASE
# 1.129 12-Jan-2010 henning

when setting up lo0 use 127.0.0.1/8 instead of 127.0.0.1 for clarity and
correctness. it's not 1992 any more, kids. ok mcbride dlg krw


# 1.128 10-Dec-2009 todd

o stop reordering ifconfig arguments (e.g. after 'up ..')
o only stop processing if inet or inet6 lines are malformed
o everything not a specially handled bit is passed to ifconfig unmangled
noticed by several after the move from bridgename.bridge0 -> hostname.bridge0
prodded by deraadt@, tested by and feedback from several
man page bits 'look fine' jmc@


# 1.127 22-Nov-2009 deraadt

Stop supporting bridgename.bridge* files, and move to hostname.bridge*
files. To cope with this change, read about the mv command.
ok claudio todd


# 1.126 17-Sep-2009 simon

change variable i to $i in an expression of ifstart() for consistency
with the rest of the file. no functional change.

feedback from sthen@, ok krw@


# 1.125 10-Jul-2009 jdixon

Delay creation of tun(4) interfaces until the underlying interface and
routes are available. This fixes usage for some OpenVPN users that start
it from hostname.tun*.

Tested by Johan Huldtgren. ok sthen@, johan@.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.124 25-Nov-2008 markus

delay /etc/netstart until IPv6-DAD (dup-address-detection) is completed.
ok fries, hshoexer, claudio


# 1.123 14-Aug-2008 sthen

Tools from /usr may not be used in netstart since it may be NFS-mounted
and not available at that time. Rewrite the hostname.if permission check
to use only /bin/ls and the shell. Requested by deraadt.

ok todd, "Twisted." deraadt


Revision tags: OPENBSD_4_4_BASE
# 1.122 23-Jul-2008 sthen

Prevent warning about insecure hostnames where no /etc/hostname.*
exists. From wcmaier@.

Check target of symbolic links to avoid noise at boot and in
seucrity output where you have several interfaces symlinked to one
config file.

"If you think this is the right thing to do" deraadt@


# 1.121 09-Jun-2008 todd

warn once not 3 times in case of a non existent file, discussed with deraadt
originally pointed out by Johan Torin


# 1.120 09-Jun-2008 deraadt

Ensure that hostname.* files are also re-chowned to root.wheel at each
boot as discussed with claudio while eating tasty donairs. ok todd


# 1.119 17-Apr-2008 deraadt

before using them, force hostname.* files to be unreadable by world
first version from todd, ok millert


Revision tags: OPENBSD_4_3_BASE
# 1.118 17-Jan-2008 brad

Execute rtsol after turning up trunk(4) and vlan(4) interfaces so they're
taken into consideration for rtsol.

ok reyk@ dlg@


# 1.117 09-Jan-2008 mpf

Do not bring up pfsync(4) before the working ruleset
has been loaded. Otherwise, states that are received during the
initial bulk update mismatch the correct pf-checksum and
do not attach to the rules.
Problem identified by david@. Fix done in collaboration.
OK henning@


Revision tags: OPENBSD_4_2_BASE
# 1.116 02-Aug-2007 david

move the delay for IPv6 DAD to after all interfaces have started
fixes problems with daemons being unable to bind to all addreses at boot
ok itojun@ hshoexer@


Revision tags: OPENBSD_4_1_BASE
# 1.115 15-Nov-2006 itojun

reject multicast packet without scope identifier specified.


Revision tags: OPENBSD_4_0_BASE
# 1.114 29-Jun-2006 todd

do not add an extra space; nwid and description come out wrong
fix as proposed by maja@, thanks!


Revision tags: OPENBSD_3_9_BASE
# 1.113 28-Dec-2005 david

nuke extra whitespace


# 1.112 06-Dec-2005 reyk

multicast_host=YES only works if a valid default gateway is available.
validate this condition and reject multicast traffic on failure.

ok todd@ naddy@


# 1.111 02-Nov-2005 todd

fix inspired by pr#4590
ok krw@


# 1.110 25-Oct-2005 todd

better logic from krw@:
- do not process mygate for v4 if dhcp
- do not process mygate for v6 if rtsol
this also makes the mygate processing logic more readable
ok krw@


# 1.109 14-Oct-2005 todd

add v6 support for /etc/mygate
ok deraadt@ mickey@ krw@
same functionality tested/ok'ed by by mickey, brad, matthieu, and me
with this one may now put a v6 IP in /etc/mygate on a separate line from
the v4 default gateway and netstart will do the right thing


# 1.108 12-Oct-2005 todd

shrink stripcom(), sync with install.sub
ok krw@


# 1.107 04-Oct-2005 todd

trunk must be started after physical ethernet devices, but before vlan.
populate ifmstart lines accordingly.
prodded/tested by brad@
ok reyk@


# 1.106 28-Sep-2005 todd

use eval consistently, fixes description quotes on rtsol and dhcp
fix inspired by and closes pr 4495
ok krw@


Revision tags: OPENBSD_3_8_BASE
# 1.105 22-May-2005 todd

Introduce 'ifmstart' to deal with starting multiple interfaces minus a list
of interfaces.

This reduces the netstart script by 174 chars, 13 words, and 19 lines, but
more importantly, makes it more simple and less cluttered should more special
case/orderings be needed.

ok brad@ and pr 4197 submitter, inspired by and closes pr 4197


# 1.104 04-Apr-2005 djm

unbreak; ok pval@


# 1.103 03-Apr-2005 deraadt

if dhcp is used to get an address on any interface, ignore /etc/mygate
ok krw
(this lets us do something rather cool with the zaurus in particular)


Revision tags: OPENBSD_3_7_BASE
# 1.102 04-Jan-2005 mcbride

Bring up the carp(4) interface before default route.

ok pascoe@ mpf@


# 1.101 30-Dec-2004 millert

Add a copy of stripcom so /etc/netstart can be run standalone again.
OK deraadt@


# 1.100 19-Dec-2004 millert

Allow comments in /etc/{myname,mygate,defaultdomain}; OK deraadt@


# 1.99 04-Dec-2004 itojun

remove "route $hostname 127.0.0.1" line. deraadt ok
*** please update /etc/netstart and test if it works ok for you ***


# 1.98 20-Oct-2004 deraadt

make all route commands use -qn; ok mcbride henning


Revision tags: OPENBSD_3_6_BASE
# 1.97 29-May-2004 deraadt

one last route command lacking -qn


Revision tags: OPENBSD_3_5_BASE
# 1.96 22-Mar-2004 mcbride

Make sure pfsync is brought up before carp.

ok deraadt@


# 1.95 13-Mar-2004 mcbride

Delay pfsync(4) configuration, as the syncif has to be configured in
advance. From Thorsten Lockert.


# 1.94 14-Jan-2004 deraadt

ok, it took quite a bit of prodding but itojun finally explained why the
extra sleep 1 is in here, and we came to the conclusion it is safe to
delete it. whee.


# 1.93 13-Jan-2004 deraadt

repair v6 lo0 documentation


# 1.92 11-Jan-2004 deraadt

add loopback routes late


# 1.91 09-Jan-2004 deraadt

create all routes with -q; markus ok


# 1.90 04-Dec-2003 millert

Need to do "ifconfig create" for bridge interfaces too.


# 1.89 03-Dec-2003 markus

add support for ifconfig clone; from netbsd; ok deraadt, henning


# 1.88 20-Oct-2003 david

delay carp initialization until after physical interfaces are configured
ok mcbride@ henning@ deraadt@ todd@


Revision tags: OPENBSD_3_4_BASE
# 1.87 27-Aug-2003 henning

only try to set hostname to what /etc/myname says if that file actually exists,
otherwise preserve `hostname`
netbooted machines can live perfectly fine without it; they get their hostname
earlier.

ok krw@ cedric@


Revision tags: OPENBSD_3_3_BASE
# 1.86 16-Feb-2003 krw

Fix up some DNS verbiage to make it consistant.

Fix up default route selection by

a) Forcing user to explicitly chose 'dhcp' as a mechanism for
specifying a default route, rather than guessing based on one or more
interfaces being configured by dhcp.

b) If the user specified default route does not work, re-present the
existing default route rather than losing it.

c) Move default route selection to after nameserver activation so the
user can specify a hostname as the default route.

Change /etc/netstart so that /etc/mygate wins if a default route was
already specified (i.e. by dhcp).

ok deraadt@.


Revision tags: OPENBSD_3_2_BASE
# 1.85 16-May-2002 todd

ignore non-existent cases where '$if' evaluates to '*'.
From Andr� Lucas <andre@ae-35.com>, fixes pr # 2658.
'Looks good' from miod@, millert@, and krw@.


Revision tags: OPENBSD_3_1_BASE
# 1.84 23-Feb-2002 deraadt

re-add support for $if expansion; hamajima@nagoya.ydc.co.jp


# 1.83 21-Feb-2002 miod

Change the network components initialization order.
Change from:
o all interfaces
o all bridges
o routes
to:
o physical interfaces
o routes
o gif and gre interfaces
o bridges

Fixeski PR #2400.
Manual page updates coming soon.
Ok angelos@ chris@ deraadt@


Revision tags: OPENBSD_3_0_BASE
# 1.82 31-Jul-2001 hugh

a space before a redirect


# 1.81 06-Jul-2001 angelos

Also, source /etc/rc.conf so we can pull in the
multicast_host/multicast_router settings; this is useful if one
flushes the routing table and re-initializes.

We really need a netconfig tool of sorts.


# 1.80 06-Jul-2001 angelos

Use "route -n show -inet" to determine the default multicast iface.


# 1.79 03-Jul-2001 deraadt

pull in rc.conf early so that pf(1) startup is right; tested by jasoni, comments from millert


# 1.78 30-May-2001 deraadt

Remove ipf. Darren Reed has interpreted his (old, new, whichever)
licence in a way that makes ipf not free according to the rules we
established over 5 years ago, at www.openbsd.org/goals.html (and those
same basic rules govern the other *BSD projects too). Specifically,
Darren says that modified versions are not permitted. But software
which OpenBSD uses and redistributes must be free to all (be they
people or companies), for any purpose they wish to use it, including
modification, use, peeing on, or even integration into baby mulching
machines or atomic bombs to be dropped on Australia. Furthermore, we
know of a number of companies using ipf with modification like us, who
are now in the same situation, and we hope that some of them will work
with us to fill this gap that now exists in OpenBSD (temporarily, we
hope).


Revision tags: OPENBSD_2_9_BASE
# 1.77 13-Mar-2001 deraadt

spelling; maurice@maurice.wan.nl


# 1.76 06-Feb-2001 todd

ignore blank lines in addition to comments
fixes pr#1660 from wilfried@telia.com .. Thanks!


# 1.75 10-Jan-2001 jason

support !command in bridgename.if files, too


# 1.74 27-Nov-2000 millert

Use -n to test if a variable is non-zero. Otherwise, if the variable's
contents start with a '-' test becomes unhappy (since it interprets it
as another option).


# 1.73 08-Nov-2000 todd

This fixes pr 1481, we now handle args > 6 in /etc/hostname.if in the
cases where we did not previously handle them.
Thanks to Scott Atwood <atwood@cs.stanford.edu> for reminding us of this.


Revision tags: OPENBSD_2_8_BASE
# 1.72 02-Sep-2000 todd

subtle bug .. global variables in a while loop need reset 'just incase'
With:
hostname.fxp0 having a last line of:
inet6 alias 3ffe:...
and hostname.gif0 having a first two lines of:
giftunnel 1.2.3.4
dest 1.2.4.3
We end up with the command:
ifconfig gif0 giftunnel alias 1.2.3.4 1.2.4.3
.. which is clearly wrong and fixed by this change


# 1.71 18-Jun-2000 todd

rc.conf now parses ${local_rcconf} internally; closes pr 1259


Revision tags: OPENBSD_2_7_BASE
# 1.70 08-May-2000 todd

fix dhcp 'NONE' ness from install to allow media parsing to work
.. ok deraadt@, millert@


# 1.69 21-Apr-2000 deraadt

rc.conf.local support, inspired by chuck yerkes


# 1.68 04-Apr-2000 millert

Remove the -E flag from ipf as it is implicitly enabled and using
the -E flag here causes the kernel to printf 'IP Filter: already
initialized'.


# 1.67 18-Mar-2000 deraadt

silence all extra route addition printouts


# 1.66 17-Mar-2000 itojun

correct reject route installations for IPv6. improve comments.


# 1.65 12-Mar-2000 itojun

disallow packets to malicious 6to4 prefix, based on
http://playground.iijlab.net/i-d/draft-itojun-ipv6-transition-abuse-00.txt


# 1.64 10-Mar-2000 todd

fix non behavior
with this `!' lines in /etc/hostname.* run even without certain lines
(like a comment) preceeding it.


# 1.63 10-Jan-2000 todd

allow arbitrary commands in /etc/hostname.* files if the line starts with '!'


# 1.62 02-Jan-2000 deraadt

rtsol case can configure the interface up, since it would be nice to finish
DAD before the actual rtsol(8) run happens later. and since it will rtsol,
it is going to be up in any case.


# 1.61 02-Jan-2000 itojun

one more indentation fix.


# 1.60 02-Jan-2000 itojun

indentation fix (todd's part)


# 1.59 02-Jan-2000 todd

fix rtsold case, reset cmd for each iteration!


# 1.58 02-Jan-2000 itojun

allow options after "rtsol".
XXX both "dhcp" and "rtsol" has keyword *down* at the end. is it okay?


# 1.57 02-Jan-2000 itojun

echo "IPv6 autoconf: interfaces" before invoking rtsol.
sleep for net.inet6.ip6.dad_count seconds to ensure that IPv6 DAD is completed.
TODO: rtsold (rc.conf line), manpage


# 1.56 02-Jan-2000 itojun

ipv6 autoconf on hosts (non-routers).

to do this,
1. in sysctl.conf, add these lines:
net.inet6.ip6.forwarding=0
net.inet6.ip6.accept_rtadv=1
2. in hostname.foo, add
rtsol

specifying two or more interfaces with "rtsol" may result in strange
behavior - ipv6 spec does not permit multi-interface node to be autoconfig'ed.


# 1.55 02-Jan-2000 todd

add to hostname.* parsing:
- multiple entries support (read: aliases)
- inet6 support
- support for comments (#)
(look for hostname.if(5) commit for syntax details)


# 1.54 31-Dec-1999 itojun

install IPv6 reject routes only if kernel is capable of IPv6.


# 1.53 09-Dec-1999 itojun

avoid transmitting invalid IPv6 packets out to the wire.


# 1.52 09-Dec-1999 itojun

do not perform IPv6 initialization for loopback interface.
MUST make lo0 up before any IPv6 operations.
it will be considered a pilot error if you don't.
(I prefer to have lo0 initialized automatically)


Revision tags: OPENBSD_2_6_BASE
# 1.51 01-Sep-1999 deraadt

support # characters in bridgename.* files; millert


# 1.50 01-Sep-1999 deraadt

cleanup parsing of hostname.* files, and seperate bridge control into
bridgename.* files; all documented in new hostname.if(5) and
bridgename.if(5) man pages


# 1.49 09-Aug-1999 angelos

Only parse/setup the hostname.foo file if interface foo exists (this
is useful for laptops with different ethernet cards etc.)


Revision tags: OPENBSD_2_5_BASE
# 1.48 29-Mar-1999 niklas

New multicast route setup style


# 1.47 26-Mar-1999 niklas

Add bridge interface handling


# 1.46 01-Mar-1999 millert

Add support in /etc/hostname.xxx for files of the format:
up [options]
Any of the following may or may not be set:
$name $mask $bcaddr $extras


# 1.45 28-Oct-1998 millert

Kill the awful hack used to match and split /etc/hostname.* We now use
a function, isalphanumeric, to determine whether an interface name is
likely to be valid. This means that things like /etc/hostname.le0.bak,
/etc/hostname.le0#, /etc/hostname.le0~, etc. will be ignored as they
should. There is no longer an implicate assumption that /etc/hostname.*
only contains a single '.'.


Revision tags: OPENBSD_2_4_BASE
# 1.44 06-Oct-1998 deraadt

move ipnat to end of netstart, to support dhcp+ipnat


# 1.43 18-Sep-1998 deraadt

apply media directives on dhcp interfaces


# 1.42 10-Sep-1998 marc

better way of handling dhcp client; Jason Ish <jbi130@mail.usask.ca>


# 1.41 08-Sep-1998 marc

dhcp client stuff. "Angelos D. Keromytis" <angelos@dsl.cis.upenn.edu>


# 1.40 24-Aug-1998 downsj

You can't use -interface default when there's no default gateway
set (yet). Use -interface $hostname if mygate doesn't exist so that
this actually works on routers.


# 1.39 04-Jul-1998 deraadt

put 224 route on default, to avoid a hostname lookup


# 1.38 22-May-1998 deraadt

use route -n, what the heck


Revision tags: OPENBSD_2_3_BASE
# 1.37 28-Mar-1998 deraadt

s/^nat/ipnat/


# 1.36 23-Feb-1998 niklas

remove trailing blank line


# 1.35 07-Feb-1998 deraadt

ipforward is in sysctl.conf now


# 1.34 21-Dec-1997 deraadt

ugh


# 1.33 20-Dec-1997 deraadt

ipforwarding option in rc.conf


# 1.32 29-Nov-1997 kstailey

NAT requires IPF


# 1.31 04-Nov-1997 deraadt

kill spaces at ends of lines; m4


Revision tags: OPENBSD_2_2_BASE
# 1.30 14-Oct-1997 deraadt

set hostname/domainname before running rc.conf; m4@umn.edu


# 1.29 04-Sep-1997 deraadt

fork netstart; new child is rc.conf


# 1.28 25-Aug-1997 millert

Explicately pass -host flag to route(8) to avoid confusion with networks.


# 1.27 19-Aug-1997 niklas

Add hook for rpc.lockd, make nfsd flags settable in netstart


# 1.26 31-Jul-1997 downsj

Make quotas optional; wedged into netstart for the time being.
/etc/rc.conf, anyone?


# 1.25 30-Jul-1997 deraadt

do not run routed by default


# 1.24 28-Jul-1997 kstailey

Move configuration of loopback interface to before all other interfaces.
Allows the use of local caching-only nameserver with no "nameserver"
entry in /etc/resolv.conf to configure a route between the hostname
and loopback.


# 1.23 25-Jul-1997 provos

earlier start of keymanagement


# 1.22 24-Jul-1997 deraadt

make amd use /tmp_mnt by default


# 1.21 22-Jul-1997 provos

start the photuris daemon per default. hilfe.


# 1.20 17-Jun-1997 niklas

Put in hooks to start ypserv with flags


# 1.19 17-Jun-1997 niklas

Put in hooks to start rpc.yppasswdd with flags


Revision tags: OPENBSD_2_1_BASE
# 1.18 15-Apr-1997 deraadt

kill route flush until .. hmm kernel routing socket bug or something


# 1.17 09-Apr-1997 kstailey

add NAT startup


# 1.16 07-Apr-1997 rees

flush all old routes before adding new interfaces or routes.
ref: netbsd pr3228/misc, Matthias Scheler


# 1.15 03-Mar-1997 downsj

fix typo


# 1.14 11-Feb-1997 deraadt

add default route before fiddling with loopback route to avoid DNS problems; m4@umn.edu, #97


# 1.13 03-Feb-1997 deraadt

do ifaliases after /usr/bin exists in nfs diskless env; pr#77, matthieu@laas.fr


# 1.12 02-Nov-1996 deraadt

timed off by default


Revision tags: OPENBSD_2_0_BASE
# 1.11 23-Sep-1996 deraadt

rfc1323 variable


# 1.10 04-Sep-1996 deraadt

control portmap, inetd, and lpd from netstart; idea from tqbf@enteract.com


# 1.9 27-Aug-1996 deraadt

224.0.0.0 not 0.0.0.224; from peter@demon.net


# 1.8 18-Jun-1996 deraadt

move std stuff from rc.local to rc


# 1.7 16-Jun-1996 deraadt

install sample commented /etc/ifaliases file; which can now contain #
comments and blank lines. new format is "interface address netmask"
(yes, i changed the order of the entries). inspired by netbsd pr#2474;
gillhaa@ghost.whirlpool.com


# 1.6 02-Jun-1996 tholo

Install a multicast route by default


# 1.5 26-May-1996 deraadt

sync & label


# 1.4 09-Jan-1996 dm

added IP filter to netstat/rc and put examples in /usr/share/ipf


# 1.3 30-Dec-1995 deraadt

from netbsd: start mrouted like routed


# 1.2 18-Dec-1995 deraadt

/etc/ifaliases support by randy@zyzzyva.com


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.205 22-May-2020 kn

Revert the following commit as it breaks hostname.if(5) lines with a
backslash at the end for line continuation

Breaking long lines into multiple ones must still be possible and does
require to treat the backslash as an escape character.

Breakage reported by Mark Patruck <mark at wrapped dot cx >, thanks!

---
distrib/miniroot/install.sub revision 1.1151
etc/netstart revision 1.203
date: 2020/05/21 11:54:41; author: kn; state: Exp; lines: +2 -2;
Do not treat backslashe as an escape character in hostname.if(5) lines

ifstart() should always pass such lines unaltered, especially if they
contain "nwid" or "description" lines with arbitrary strings.

<bsdlisten at gmail dot com> reported SSIDs such as "Mike's" during
installation end as broken; this was because the installer escaped
the single quote using backslashes which ended up being treated as
escape characters much later during hostname.if parsing in netstart(8).

Ok deraadt


# 1.204 21-May-2020 kn

Fix stripcom() description wrt. comments not on their own line

Neither netstart's nor install.sub's (subtly different) implementations
remove trailing comments on lines not starting as a comment, e.g.,
lines like "up #not down" go through unaltered and without "#not down"
being removed.

Only lines *beginning* with the comment sign ("#") are stripped.

No functional change, just updating function descriptions.


# 1.203 21-May-2020 kn

Do not treat backslashe as an escape character in hostname.if(5) lines

ifstart() should always pass such lines unaltered, especially if they
contain "nwid" or "description" lines with arbitrary strings.

<bsdlisten at gmail dot com> reported SSIDs such as "Mike's" during
installation end as broken; this was because the installer escaped
the single quote using backslashes which ended up being treated as
escape characters much later during hostname.if parsing in netstart(8).

Ok deraadt


Revision tags: OPENBSD_6_7_BASE
# 1.202 15-Jan-2020 kn

Do not redirect already quiet stdout for IPv6 reject routes

"route -q" already silences all standard output; if it still prints
something, that's a bug to fix in route.

OK bluhm


# 1.201 25-Oct-2019 dlg

handle aggr(4) in the same way as trunk(4)

from brad@
ok bluhm@ claudio@ deraadt@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.200 29-Aug-2018 krw

Historically /etc/netstart (and the equivalent code in the install
script) did 'ifconfig <if> down' before starting dhclient(8). This was
a way of ensuring old running copies of dhclient were killed before a
new one started. Current dhclient does not need this assist, so change
"ifconfig <if> down" to "ifconfig <if> up" pending further script
optimizations.

Similar to a 2014 attempt by halex@. Prompted by a misc@ report
from Kristjan Komlosi reporting hanging diskless setups.

ok halex@ kn@


# 1.199 08-Jul-2018 tb

netstart is used during system start, but also interactively.
Show proper error message if a regular user executes netstart.
Only do the privilege check if the id binary is available,
which might not be the case during diskless system startup.

ok deraadt, jasper, jca, krw, rpe (who wrote the same diff), sthen


# 1.198 28-Apr-2018 rpe

Add a proper usage() function.

Suggested by and OK jmc.
OK tb


Revision tags: OPENBSD_6_3_BASE
# 1.197 04-Mar-2018 jmc

when -n is used, no need to spit out "Missing parameters." before
displaying usage();

ok tb


# 1.196 03-Mar-2018 landry

Lowercase 'usage' and group -n with interface in it.
From jmc@, ok tb@


# 1.195 21-Feb-2018 rpe

Tweak comments.

OK tb


# 1.194 19-Feb-2018 rpe

Write warning/error messages to stderr and end them with a fullstop.

OK tb


# 1.193 19-Feb-2018 rpe

- use specific patterns when looping over /etc/hostname.if files
to skip backup or temp files.
- test if the patterns matched actual files
- warn if ifcreate() fails on an interface and continue with the
subsequent interfaces in the list instead of return'ing

OK dlg sthen tb


# 1.192 17-Feb-2018 rpe

- Add descriptions for the new functions ifcreate() and vifscreate()
- In ifcreate() use the exit code of the {} block directly
- In vifscreate(), use the ifconfig -C output directly in the for _vif loop
- Remove superfluous and somewhat confusing comment

OK dlg kn sthen


# 1.191 14-Feb-2018 dlg

create virtual interfaces before starting all interface config.

this resolves an ordering problem when adding pseudo interfaces to bridges

tweaks from kn@
ok mpi@ sthen@


# 1.190 10-Feb-2018 claudio

Remove some special IPv4 in IPv6 mapped prefixes that are already rejected
by the ::0.0.0.0/96 reject route added to deny all IPv4 mapped addresses.
Makes the inet6 routing table almost fit in one screen.
OK benno@


# 1.189 10-Feb-2018 florian

Load RFC 7217 key material and generate if it does not already exist.

Add soii.key to changelist (pointed out by semarie) and mtree/special
(suggest by Craig Skinner).

OK naddy, sthen, rpe, tb


# 1.188 06-Feb-2018 tb

If -n is given, the netstart script should not (try to) set the default
route(s). Simply print the command(s) to be issued instead.

tweak & ok rpe


# 1.187 12-Nov-2017 tb

Remove HN_DIR variable and expand it in the only place it was used. It
currently serves no purpose.

ok rpe, agreement from deraadt and halex


Revision tags: OPENBSD_6_2_BASE
# 1.186 25-Jul-2017 rpe

Finally remove backwards compat code to support the 'rtsol' keyword
in hostname.if(5)

OK mpi@ deraadt@ florian@
OK jmc@ from doc perspective


# 1.185 21-Jul-2017 rpe

Align ifstart() in netstart and install.sub.

- in netstart, rename _file to _hn referencing hostname.if files
- in install.sub switch ifstart() to be used with _if instead of
_hn as parameter

ok krw@ tb@


# 1.184 28-May-2017 awolk

etc/netstart: use colon separator instead of dot with chown

OK jung@, deraadt@, jmc@


# 1.183 07-May-2017 rpe

Change test from [] to [[]] and simplify pattern.

OK tb@, krw@ (for [[]])
Feedback and OK halex@


# 1.182 07-May-2017 rpe

Replace hardcoded script name with ${0##*/}

OK tb@ halex@


# 1.181 01-May-2017 rpe

Revert r1.170 and remove the id==0 check.
The id binary is not available in nfs diskless setups at this point.

reported by Andreas Kusalananda, thanks.
discussed with deraadt@


# 1.180 01-May-2017 rpe

Remove last remnants of rtsol. IPv6 autoconfiguration of interfaces is now
done in ifstart(). Remove ipv6autoconf() and replace rtsolif with a boolean
variable V6_AUTOCONF. Replace dhcpif with a boolean variable V4_DHCPCONF.
Both are later used in defaultroute() to decide whether or not to configre
defaultroutes from /etc/mygate.

OK krw@


# 1.179 30-Apr-2017 mpi

Do not try to delete a default route before adding it.

Now that route are automatically G/C with the address they are attached
to there's no reason to duplicate the kernel's job.

Fix a regression introduced with multipath default routes.

ok deraadt@


# 1.178 25-Apr-2017 rpe

Unbreak netstart for multiple inteface configurations like trunk
or carp. Ensure that the noglob option is disabled at the end of
parse_hn_line() and ifstart().

Reported by Christer Solskogen and Stefan Wollny, thanks!


# 1.177 24-Apr-2017 rpe

Introduce a new function parse_hn_line() that replaces the existing
hostname.if(5) parsing code in ifstart().
Add a -n option to netstart to only print the interface configuration
commands instead of executing them.
Add a HN_DIR variable, that points to the directory of the hostname.if
files (default /etc) that allows for future regression tests.

- add new parse_hn_line() function
- change ifstart()
- rename $if to $_if
- don't ifconfig or ifconfig create if -n option is used
- replace hostname.if(5) parsing code with new parse_hn_line()
- just print configuration commands if -n option is used
- autoconf now happens in ifstart(), remove ifv6autoconf()
- introduce HN_DIR variable for the hostname.if file location
- add handling of the -n option to only print config commands
- ensure -n is only used if interfaces are specified as parameters

Discussed with and positive feedback from many
'commit' deraadt@
OK sthen@


# 1.176 08-Apr-2017 rpe

- localize the if, file and stat variables which also ensures that
variables are not named like commands.
- change test from [] to [[]]

OK tb@ halex@


# 1.175 07-Apr-2017 rpe

Minimize differences in ifstart() function between netstart and
install.sub which makes it easier to spot changes in the future.

- comments and formatting
- quotes on assignments are not needed (netstart)
- remove stray space in test (netstart)
- use $file variable with while-loop (netstart)
- although valid, instead of i use $i in arithmetic test (install.sub)

OK krw@, tb@
Looks good deraadt@


# 1.174 07-Apr-2017 rpe

Align comments of ifstart() function in netstart and install.sub.


# 1.173 07-Apr-2017 rpe

Align comments of stripcom() function in netstart and install.sub.


Revision tags: OPENBSD_6_1_BASE
# 1.172 06-Dec-2016 mpi

Do not lose the default route when netstart(8) is run a second time on
the interface pointed to by the default route.

Since the kernel no longer keep routes with dangling address pointer,
netstart(8) has to re-add the default route when the corresponding ifa
has been deleted and re-created.

deraadt@ points out that even if the previous semantic was not necessarily
better, a script like netstart(8) cannot totally fix the default route
problem.

Regression reported by and fix tested by Hrvoje Popovski.

ksh foo checked by halex@


# 1.171 27-Sep-2016 rzalamena

Delay switch(4) interface start up so it can attach virtual interfaces
like vether(4).

nits from and ok benno@, phessler@


# 1.170 09-Sep-2016 jasper

print a clear error message when not ran as root instead of just falling
through and try whatever it can do with the invoking user's perms

feedback/ok aja@ rpe@


Revision tags: OPENBSD_6_0_BASE
# 1.169 19-Jul-2016 mpi

Do not consider tap(4) a special interface and start if before other
pseudo-interfaces.

This unbreak vlan(4) on top of tap(4) since the refactoring to turn it
MP-safe.

ok claudio@, deraadt@


# 1.168 27-Mar-2016 sthen

Don't delete the 224/4 route in netstart, unless it's being done to ensure that
a -reject route can be added. Restores the ability to set an interface route
before daemons are started, lost during the previous simplification.
ok millert mpi


Revision tags: OPENBSD_5_9_BASE
# 1.167 29-Dec-2015 rpe

Remove backslash, not necessary after '&&'

OK halex@


# 1.166 29-Dec-2015 rpe

Replace last remaining `` with $()

OK halex@


# 1.165 18-Dec-2015 ajacoutot

Drop the now useless multicast setup comment.

prodded by tim@, ok mpi@


# 1.164 17-Dec-2015 ajacoutot

Simplify multicast option handling (10 less lines) by matching /etc/rc behavior
towards other YES|NO options and drop the error warning.


with and ok tim@, ok rpe@ on an earlier diff


# 1.163 05-Dec-2015 mpi

It does not make sense to insert a specific route for 224/4 when the
default one is good enough.

So merge rc.conf(8)'s 'multicast_router' and 'multicast_host' into a
single 'multicast'. If set to YES the reject route for 224/4 is not
inserted by netstart(8).

Manual bits from jmc@

ok henning@, ajacoutot@


# 1.162 12-Nov-2015 rpe

Changes to ifautostart():
- Rename function to ifv6autoconf() to make IPv6 relation clearer
- Localize and rename variables

OK krw@


# 1.161 12-Nov-2015 rpe

Changes to ifmstart():
- Change comments to make it clearer that ifmstart() takes two lists
of interface driver names (of which the second is optional) and not
the actual interface instances.
- Use localized variables and use slightly more verbose names.
- Use continue 2 to skip to the next hostname.if file.
- Use shell pattern @() instead of testing _sif individually.

OK krw@


# 1.160 12-Nov-2015 rpe

Changes to stripcom():
- Align comments with /etc/rc version
- Use localized variables
- Use safer "print -r --" instead of plain echo

Changes to ifstart():
- Tweak comment
- Add usage

OK krw@


# 1.159 01-Nov-2015 rpe

Start the rework of the /etc/netstart shell script.

General changes:
- apply a similar 'style' as used in the installer scripts
- improve comments to be more to the point, remove where code is obvious
- document usage of functions if they have arguments
- rename variables where it improves readability
- replace really old-school shell code with more contemporary idioms

Other changes:
- No need to care about "autoboot" because netstart doesn't inherit the
positional parameters from /etc/rc anymore. /etc/rc executes netstart
instead of sourcing it since r1.439.
- Use simpler for-loop to process list of interfaces with ifstart.

OK halex@


# 1.158 26-Oct-2015 rpe

The hostname variable is not used since r1.99. Remove it and use
stripcom() output directly with the hostname command.

OK deraadt@ krw@


# 1.157 23-Oct-2015 claudio

netstart bits for tap(4)


# 1.156 27-Sep-2015 sthen

Don't print output when setting autoconf on interfaces. Suggested by deraadt,
ok florian@ rpe@


# 1.155 13-Sep-2015 sthen

only print the "IPv6 autoconf" line if there are interfaces to configure
feedback/ok rpe


# 1.154 11-Sep-2015 sthen

Set "inet6 autoconf" individually on interfaces that have rtsol set in
hostname.if, previously netstart tried to configure them all at once
("ifconfig if0 if1 if2 inet6 autoconf"). From Delan Azabani, ok phessler@


Revision tags: OPENBSD_5_8_BASE
# 1.153 20-Jul-2015 rpe

Disable Strict Bourne shell mode for /etc/rc and /etc/netstart to be
able to use ksh syntax within these scripts. This way init doesn't
need to be changed, which starts /etc/rc using /bin/sh and people
can still use "sh /etc/netstart ifname".

Idea from and OK halex@
OK deraadt@ krw@ guenther@


# 1.152 19-Jul-2015 florian

Bring up pflow last as it might send with a source address that is on
any of the other interfaces.
OK deraadt, phessler, benno


# 1.151 19-Jul-2015 rpe

Always source rc.subr to be able to use the rc.conf parsing routine
to get the network related vars from rc.conf. This is even necessary
if netstart is run from within /etc/rc. Remove test of $INRC which
unintentionally evaluated always to true.

problem with previous change found by nigel@
OK sthen@ aja@ halex@


# 1.150 19-Jul-2015 ajacoutot

Revert 1.148 for now until I can talk to rpe@
It introduced a regression reported by nigel@


# 1.149 19-Jul-2015 rpe

Replace test command with [].

OK halex@ krw@


# 1.148 19-Jul-2015 rpe

Ensure, that we source rc.subr and parse rc.conf ONLY if we are not
inside /etc/rc.

With help from and OK halex@, ajacoutot@


# 1.147 18-Jul-2015 rpe

- remove trailing blanks introduced in previous commit
- no space in redirections like </foo or >$bar
- few other minor whitespaces

OK krw@


# 1.146 18-Jul-2015 rpe

Improve comments
- Add comments for functions
- Start comments with capital letters
- End comments with a full stop
- Allow comments to extend up to column 80

OK krw@


# 1.145 06-Jun-2015 florian

Allow rtsol keyword in hostname.if(5) with net.inet6.ip6.forwarding=1.
"inet6 autoconf" was working before and rtsol should behave the same.
OK phessler


Revision tags: OPENBSD_5_7_BASE
# 1.144 03-Dec-2014 florian

The kernel handles rtsol(8) functionality since some time now.
Treat rtsol in hostname.if as a keyword like dhcp and call ifconfig
inet6 autoconf.
"reads good" todd@
OK krw@ (who is *not* an IPv6 person), but I recruited him in his
capacity as an installer person.


# 1.143 28-Sep-2014 claudio

Revert 1.142. Without the down netstart will just print the ifconfig
output because it may end up just calling 'ifconfig $if'. This needs
to be done better and properly tested.


# 1.142 26-Sep-2014 halex

remove explicit 'down' of an interface before starting a dhcp request, thereby
avoiding annoying delays for some switch configurations

ok claudio@ deraadt@

i would add ok phessler@, but it was not valid without an ok krw@


Revision tags: OPENBSD_5_6_BASE
# 1.141 12-Jul-2014 stsp

Fix netstart after autoconf6 change so 'rtsol' lines in hostname.if work again.
found by pelikan@; ok pelikan@ henning@


# 1.140 12-Jul-2014 robert

Make rc.conf a parsed configuration file and stop sourcing it as a shell
script.
From now on rc.conf has a fixed syntax (key=val) and it is not allowed
to add anything to it besides the supported syntax, it all going to be
ignored.

discussed with and help from deraadt@ and halex@


Revision tags: OPENBSD_5_5_BASE
# 1.139 22-Aug-2013 mpi

Like for dhclient, do no create a route to alias addresses via 127.0.0.1.
Our stack is able to tell if the address is local or not.

ok todd@, krw@


Revision tags: OPENBSD_5_4_BASE
# 1.138 20-Mar-2013 todd

fix lies in netstart; replacement wording from halex@
pointed out by Ryan Kavannagh rak at debian dot org


Revision tags: OPENBSD_5_3_BASE
# 1.137 05-Dec-2012 rpe

remove "Invalid interface name" message
requested by krw@

ok halex@


# 1.136 02-Dec-2012 rpe

use the more compact version of the check for ifconfig'able interfaces
from install.sub

with feedback from and ok halex


# 1.135 02-Dec-2012 rpe

- remove isalphanumeric() and replace it with a shell pattern, that
tries a bit harder to identify invalid interface names and in
this case emit an error message.
- use [[ $1 == autoboot ]] to avoid a shell error message due to
possible spaces in first argument
- no change in functionality

discussed with krw and halex
ok ("I like this") krw


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.134 07-Oct-2011 deraadt

The new ypbind changes requires that the domainname be set before
rc.conf is run. There's no real downside.
ok aja


Revision tags: OPENBSD_5_0_BASE
# 1.133 07-Jul-2011 guenther

Eliminate some $? tests by rolling the command into the condition

ok halex@


# 1.132 26-May-2011 mpf

Add svlan(4) startup bits.
From markus@. OK naddy, claudio, reyk.


Revision tags: OPENBSD_4_9_BASE
# 1.131 09-Feb-2011 sobrado

fix an unbalanced parenthesis in a comment; while here, split the comment
in a better place to make it more readable.

ok jmc@ and miod@


Revision tags: OPENBSD_4_8_BASE
# 1.130 16-Jun-2010 todd

permit e.g. -inet6 syntax by slurping all lines not just some
noticed by rhsv6 at hushmail dot com, ok sthen@


Revision tags: OPENBSD_4_7_BASE
# 1.129 12-Jan-2010 henning

when setting up lo0 use 127.0.0.1/8 instead of 127.0.0.1 for clarity and
correctness. it's not 1992 any more, kids. ok mcbride dlg krw


# 1.128 10-Dec-2009 todd

o stop reordering ifconfig arguments (e.g. after 'up ..')
o only stop processing if inet or inet6 lines are malformed
o everything not a specially handled bit is passed to ifconfig unmangled
noticed by several after the move from bridgename.bridge0 -> hostname.bridge0
prodded by deraadt@, tested by and feedback from several
man page bits 'look fine' jmc@


# 1.127 22-Nov-2009 deraadt

Stop supporting bridgename.bridge* files, and move to hostname.bridge*
files. To cope with this change, read about the mv command.
ok claudio todd


# 1.126 17-Sep-2009 simon

change variable i to $i in an expression of ifstart() for consistency
with the rest of the file. no functional change.

feedback from sthen@, ok krw@


# 1.125 10-Jul-2009 jdixon

Delay creation of tun(4) interfaces until the underlying interface and
routes are available. This fixes usage for some OpenVPN users that start
it from hostname.tun*.

Tested by Johan Huldtgren. ok sthen@, johan@.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.124 25-Nov-2008 markus

delay /etc/netstart until IPv6-DAD (dup-address-detection) is completed.
ok fries, hshoexer, claudio


# 1.123 14-Aug-2008 sthen

Tools from /usr may not be used in netstart since it may be NFS-mounted
and not available at that time. Rewrite the hostname.if permission check
to use only /bin/ls and the shell. Requested by deraadt.

ok todd, "Twisted." deraadt


Revision tags: OPENBSD_4_4_BASE
# 1.122 23-Jul-2008 sthen

Prevent warning about insecure hostnames where no /etc/hostname.*
exists. From wcmaier@.

Check target of symbolic links to avoid noise at boot and in
seucrity output where you have several interfaces symlinked to one
config file.

"If you think this is the right thing to do" deraadt@


# 1.121 09-Jun-2008 todd

warn once not 3 times in case of a non existent file, discussed with deraadt
originally pointed out by Johan Torin


# 1.120 09-Jun-2008 deraadt

Ensure that hostname.* files are also re-chowned to root.wheel at each
boot as discussed with claudio while eating tasty donairs. ok todd


# 1.119 17-Apr-2008 deraadt

before using them, force hostname.* files to be unreadable by world
first version from todd, ok millert


Revision tags: OPENBSD_4_3_BASE
# 1.118 17-Jan-2008 brad

Execute rtsol after turning up trunk(4) and vlan(4) interfaces so they're
taken into consideration for rtsol.

ok reyk@ dlg@


# 1.117 09-Jan-2008 mpf

Do not bring up pfsync(4) before the working ruleset
has been loaded. Otherwise, states that are received during the
initial bulk update mismatch the correct pf-checksum and
do not attach to the rules.
Problem identified by david@. Fix done in collaboration.
OK henning@


Revision tags: OPENBSD_4_2_BASE
# 1.116 02-Aug-2007 david

move the delay for IPv6 DAD to after all interfaces have started
fixes problems with daemons being unable to bind to all addreses at boot
ok itojun@ hshoexer@


Revision tags: OPENBSD_4_1_BASE
# 1.115 15-Nov-2006 itojun

reject multicast packet without scope identifier specified.


Revision tags: OPENBSD_4_0_BASE
# 1.114 29-Jun-2006 todd

do not add an extra space; nwid and description come out wrong
fix as proposed by maja@, thanks!


Revision tags: OPENBSD_3_9_BASE
# 1.113 28-Dec-2005 david

nuke extra whitespace


# 1.112 06-Dec-2005 reyk

multicast_host=YES only works if a valid default gateway is available.
validate this condition and reject multicast traffic on failure.

ok todd@ naddy@


# 1.111 02-Nov-2005 todd

fix inspired by pr#4590
ok krw@


# 1.110 25-Oct-2005 todd

better logic from krw@:
- do not process mygate for v4 if dhcp
- do not process mygate for v6 if rtsol
this also makes the mygate processing logic more readable
ok krw@


# 1.109 14-Oct-2005 todd

add v6 support for /etc/mygate
ok deraadt@ mickey@ krw@
same functionality tested/ok'ed by by mickey, brad, matthieu, and me
with this one may now put a v6 IP in /etc/mygate on a separate line from
the v4 default gateway and netstart will do the right thing


# 1.108 12-Oct-2005 todd

shrink stripcom(), sync with install.sub
ok krw@


# 1.107 04-Oct-2005 todd

trunk must be started after physical ethernet devices, but before vlan.
populate ifmstart lines accordingly.
prodded/tested by brad@
ok reyk@


# 1.106 28-Sep-2005 todd

use eval consistently, fixes description quotes on rtsol and dhcp
fix inspired by and closes pr 4495
ok krw@


Revision tags: OPENBSD_3_8_BASE
# 1.105 22-May-2005 todd

Introduce 'ifmstart' to deal with starting multiple interfaces minus a list
of interfaces.

This reduces the netstart script by 174 chars, 13 words, and 19 lines, but
more importantly, makes it more simple and less cluttered should more special
case/orderings be needed.

ok brad@ and pr 4197 submitter, inspired by and closes pr 4197


# 1.104 04-Apr-2005 djm

unbreak; ok pval@


# 1.103 03-Apr-2005 deraadt

if dhcp is used to get an address on any interface, ignore /etc/mygate
ok krw
(this lets us do something rather cool with the zaurus in particular)


Revision tags: OPENBSD_3_7_BASE
# 1.102 04-Jan-2005 mcbride

Bring up the carp(4) interface before default route.

ok pascoe@ mpf@


# 1.101 30-Dec-2004 millert

Add a copy of stripcom so /etc/netstart can be run standalone again.
OK deraadt@


# 1.100 19-Dec-2004 millert

Allow comments in /etc/{myname,mygate,defaultdomain}; OK deraadt@


# 1.99 04-Dec-2004 itojun

remove "route $hostname 127.0.0.1" line. deraadt ok
*** please update /etc/netstart and test if it works ok for you ***


# 1.98 20-Oct-2004 deraadt

make all route commands use -qn; ok mcbride henning


Revision tags: OPENBSD_3_6_BASE
# 1.97 29-May-2004 deraadt

one last route command lacking -qn


Revision tags: OPENBSD_3_5_BASE
# 1.96 22-Mar-2004 mcbride

Make sure pfsync is brought up before carp.

ok deraadt@


# 1.95 13-Mar-2004 mcbride

Delay pfsync(4) configuration, as the syncif has to be configured in
advance. From Thorsten Lockert.


# 1.94 14-Jan-2004 deraadt

ok, it took quite a bit of prodding but itojun finally explained why the
extra sleep 1 is in here, and we came to the conclusion it is safe to
delete it. whee.


# 1.93 13-Jan-2004 deraadt

repair v6 lo0 documentation


# 1.92 11-Jan-2004 deraadt

add loopback routes late


# 1.91 09-Jan-2004 deraadt

create all routes with -q; markus ok


# 1.90 04-Dec-2003 millert

Need to do "ifconfig create" for bridge interfaces too.


# 1.89 03-Dec-2003 markus

add support for ifconfig clone; from netbsd; ok deraadt, henning


# 1.88 20-Oct-2003 david

delay carp initialization until after physical interfaces are configured
ok mcbride@ henning@ deraadt@ todd@


Revision tags: OPENBSD_3_4_BASE
# 1.87 27-Aug-2003 henning

only try to set hostname to what /etc/myname says if that file actually exists,
otherwise preserve `hostname`
netbooted machines can live perfectly fine without it; they get their hostname
earlier.

ok krw@ cedric@


Revision tags: OPENBSD_3_3_BASE
# 1.86 16-Feb-2003 krw

Fix up some DNS verbiage to make it consistant.

Fix up default route selection by

a) Forcing user to explicitly chose 'dhcp' as a mechanism for
specifying a default route, rather than guessing based on one or more
interfaces being configured by dhcp.

b) If the user specified default route does not work, re-present the
existing default route rather than losing it.

c) Move default route selection to after nameserver activation so the
user can specify a hostname as the default route.

Change /etc/netstart so that /etc/mygate wins if a default route was
already specified (i.e. by dhcp).

ok deraadt@.


Revision tags: OPENBSD_3_2_BASE
# 1.85 16-May-2002 todd

ignore non-existent cases where '$if' evaluates to '*'.
From Andr� Lucas <andre@ae-35.com>, fixes pr # 2658.
'Looks good' from miod@, millert@, and krw@.


Revision tags: OPENBSD_3_1_BASE
# 1.84 23-Feb-2002 deraadt

re-add support for $if expansion; hamajima@nagoya.ydc.co.jp


# 1.83 21-Feb-2002 miod

Change the network components initialization order.
Change from:
o all interfaces
o all bridges
o routes
to:
o physical interfaces
o routes
o gif and gre interfaces
o bridges

Fixeski PR #2400.
Manual page updates coming soon.
Ok angelos@ chris@ deraadt@


Revision tags: OPENBSD_3_0_BASE
# 1.82 31-Jul-2001 hugh

a space before a redirect


# 1.81 06-Jul-2001 angelos

Also, source /etc/rc.conf so we can pull in the
multicast_host/multicast_router settings; this is useful if one
flushes the routing table and re-initializes.

We really need a netconfig tool of sorts.


# 1.80 06-Jul-2001 angelos

Use "route -n show -inet" to determine the default multicast iface.


# 1.79 03-Jul-2001 deraadt

pull in rc.conf early so that pf(1) startup is right; tested by jasoni, comments from millert


# 1.78 30-May-2001 deraadt

Remove ipf. Darren Reed has interpreted his (old, new, whichever)
licence in a way that makes ipf not free according to the rules we
established over 5 years ago, at www.openbsd.org/goals.html (and those
same basic rules govern the other *BSD projects too). Specifically,
Darren says that modified versions are not permitted. But software
which OpenBSD uses and redistributes must be free to all (be they
people or companies), for any purpose they wish to use it, including
modification, use, peeing on, or even integration into baby mulching
machines or atomic bombs to be dropped on Australia. Furthermore, we
know of a number of companies using ipf with modification like us, who
are now in the same situation, and we hope that some of them will work
with us to fill this gap that now exists in OpenBSD (temporarily, we
hope).


Revision tags: OPENBSD_2_9_BASE
# 1.77 13-Mar-2001 deraadt

spelling; maurice@maurice.wan.nl


# 1.76 06-Feb-2001 todd

ignore blank lines in addition to comments
fixes pr#1660 from wilfried@telia.com .. Thanks!


# 1.75 10-Jan-2001 jason

support !command in bridgename.if files, too


# 1.74 27-Nov-2000 millert

Use -n to test if a variable is non-zero. Otherwise, if the variable's
contents start with a '-' test becomes unhappy (since it interprets it
as another option).


# 1.73 08-Nov-2000 todd

This fixes pr 1481, we now handle args > 6 in /etc/hostname.if in the
cases where we did not previously handle them.
Thanks to Scott Atwood <atwood@cs.stanford.edu> for reminding us of this.


Revision tags: OPENBSD_2_8_BASE
# 1.72 02-Sep-2000 todd

subtle bug .. global variables in a while loop need reset 'just incase'
With:
hostname.fxp0 having a last line of:
inet6 alias 3ffe:...
and hostname.gif0 having a first two lines of:
giftunnel 1.2.3.4
dest 1.2.4.3
We end up with the command:
ifconfig gif0 giftunnel alias 1.2.3.4 1.2.4.3
.. which is clearly wrong and fixed by this change


# 1.71 18-Jun-2000 todd

rc.conf now parses ${local_rcconf} internally; closes pr 1259


Revision tags: OPENBSD_2_7_BASE
# 1.70 08-May-2000 todd

fix dhcp 'NONE' ness from install to allow media parsing to work
.. ok deraadt@, millert@


# 1.69 21-Apr-2000 deraadt

rc.conf.local support, inspired by chuck yerkes


# 1.68 04-Apr-2000 millert

Remove the -E flag from ipf as it is implicitly enabled and using
the -E flag here causes the kernel to printf 'IP Filter: already
initialized'.


# 1.67 18-Mar-2000 deraadt

silence all extra route addition printouts


# 1.66 17-Mar-2000 itojun

correct reject route installations for IPv6. improve comments.


# 1.65 12-Mar-2000 itojun

disallow packets to malicious 6to4 prefix, based on
http://playground.iijlab.net/i-d/draft-itojun-ipv6-transition-abuse-00.txt


# 1.64 10-Mar-2000 todd

fix non behavior
with this `!' lines in /etc/hostname.* run even without certain lines
(like a comment) preceeding it.


# 1.63 10-Jan-2000 todd

allow arbitrary commands in /etc/hostname.* files if the line starts with '!'


# 1.62 02-Jan-2000 deraadt

rtsol case can configure the interface up, since it would be nice to finish
DAD before the actual rtsol(8) run happens later. and since it will rtsol,
it is going to be up in any case.


# 1.61 02-Jan-2000 itojun

one more indentation fix.


# 1.60 02-Jan-2000 itojun

indentation fix (todd's part)


# 1.59 02-Jan-2000 todd

fix rtsold case, reset cmd for each iteration!


# 1.58 02-Jan-2000 itojun

allow options after "rtsol".
XXX both "dhcp" and "rtsol" has keyword *down* at the end. is it okay?


# 1.57 02-Jan-2000 itojun

echo "IPv6 autoconf: interfaces" before invoking rtsol.
sleep for net.inet6.ip6.dad_count seconds to ensure that IPv6 DAD is completed.
TODO: rtsold (rc.conf line), manpage


# 1.56 02-Jan-2000 itojun

ipv6 autoconf on hosts (non-routers).

to do this,
1. in sysctl.conf, add these lines:
net.inet6.ip6.forwarding=0
net.inet6.ip6.accept_rtadv=1
2. in hostname.foo, add
rtsol

specifying two or more interfaces with "rtsol" may result in strange
behavior - ipv6 spec does not permit multi-interface node to be autoconfig'ed.


# 1.55 02-Jan-2000 todd

add to hostname.* parsing:
- multiple entries support (read: aliases)
- inet6 support
- support for comments (#)
(look for hostname.if(5) commit for syntax details)


# 1.54 31-Dec-1999 itojun

install IPv6 reject routes only if kernel is capable of IPv6.


# 1.53 09-Dec-1999 itojun

avoid transmitting invalid IPv6 packets out to the wire.


# 1.52 09-Dec-1999 itojun

do not perform IPv6 initialization for loopback interface.
MUST make lo0 up before any IPv6 operations.
it will be considered a pilot error if you don't.
(I prefer to have lo0 initialized automatically)


Revision tags: OPENBSD_2_6_BASE
# 1.51 01-Sep-1999 deraadt

support # characters in bridgename.* files; millert


# 1.50 01-Sep-1999 deraadt

cleanup parsing of hostname.* files, and seperate bridge control into
bridgename.* files; all documented in new hostname.if(5) and
bridgename.if(5) man pages


# 1.49 09-Aug-1999 angelos

Only parse/setup the hostname.foo file if interface foo exists (this
is useful for laptops with different ethernet cards etc.)


Revision tags: OPENBSD_2_5_BASE
# 1.48 29-Mar-1999 niklas

New multicast route setup style


# 1.47 26-Mar-1999 niklas

Add bridge interface handling


# 1.46 01-Mar-1999 millert

Add support in /etc/hostname.xxx for files of the format:
up [options]
Any of the following may or may not be set:
$name $mask $bcaddr $extras


# 1.45 28-Oct-1998 millert

Kill the awful hack used to match and split /etc/hostname.* We now use
a function, isalphanumeric, to determine whether an interface name is
likely to be valid. This means that things like /etc/hostname.le0.bak,
/etc/hostname.le0#, /etc/hostname.le0~, etc. will be ignored as they
should. There is no longer an implicate assumption that /etc/hostname.*
only contains a single '.'.


Revision tags: OPENBSD_2_4_BASE
# 1.44 06-Oct-1998 deraadt

move ipnat to end of netstart, to support dhcp+ipnat


# 1.43 18-Sep-1998 deraadt

apply media directives on dhcp interfaces


# 1.42 10-Sep-1998 marc

better way of handling dhcp client; Jason Ish <jbi130@mail.usask.ca>


# 1.41 08-Sep-1998 marc

dhcp client stuff. "Angelos D. Keromytis" <angelos@dsl.cis.upenn.edu>


# 1.40 24-Aug-1998 downsj

You can't use -interface default when there's no default gateway
set (yet). Use -interface $hostname if mygate doesn't exist so that
this actually works on routers.


# 1.39 04-Jul-1998 deraadt

put 224 route on default, to avoid a hostname lookup


# 1.38 22-May-1998 deraadt

use route -n, what the heck


Revision tags: OPENBSD_2_3_BASE
# 1.37 28-Mar-1998 deraadt

s/^nat/ipnat/


# 1.36 23-Feb-1998 niklas

remove trailing blank line


# 1.35 07-Feb-1998 deraadt

ipforward is in sysctl.conf now


# 1.34 21-Dec-1997 deraadt

ugh


# 1.33 20-Dec-1997 deraadt

ipforwarding option in rc.conf


# 1.32 29-Nov-1997 kstailey

NAT requires IPF


# 1.31 04-Nov-1997 deraadt

kill spaces at ends of lines; m4


Revision tags: OPENBSD_2_2_BASE
# 1.30 14-Oct-1997 deraadt

set hostname/domainname before running rc.conf; m4@umn.edu


# 1.29 04-Sep-1997 deraadt

fork netstart; new child is rc.conf


# 1.28 25-Aug-1997 millert

Explicately pass -host flag to route(8) to avoid confusion with networks.


# 1.27 19-Aug-1997 niklas

Add hook for rpc.lockd, make nfsd flags settable in netstart


# 1.26 31-Jul-1997 downsj

Make quotas optional; wedged into netstart for the time being.
/etc/rc.conf, anyone?


# 1.25 30-Jul-1997 deraadt

do not run routed by default


# 1.24 28-Jul-1997 kstailey

Move configuration of loopback interface to before all other interfaces.
Allows the use of local caching-only nameserver with no "nameserver"
entry in /etc/resolv.conf to configure a route between the hostname
and loopback.


# 1.23 25-Jul-1997 provos

earlier start of keymanagement


# 1.22 24-Jul-1997 deraadt

make amd use /tmp_mnt by default


# 1.21 22-Jul-1997 provos

start the photuris daemon per default. hilfe.


# 1.20 17-Jun-1997 niklas

Put in hooks to start ypserv with flags


# 1.19 17-Jun-1997 niklas

Put in hooks to start rpc.yppasswdd with flags


Revision tags: OPENBSD_2_1_BASE
# 1.18 15-Apr-1997 deraadt

kill route flush until .. hmm kernel routing socket bug or something


# 1.17 09-Apr-1997 kstailey

add NAT startup


# 1.16 07-Apr-1997 rees

flush all old routes before adding new interfaces or routes.
ref: netbsd pr3228/misc, Matthias Scheler


# 1.15 03-Mar-1997 downsj

fix typo


# 1.14 11-Feb-1997 deraadt

add default route before fiddling with loopback route to avoid DNS problems; m4@umn.edu, #97


# 1.13 03-Feb-1997 deraadt

do ifaliases after /usr/bin exists in nfs diskless env; pr#77, matthieu@laas.fr


# 1.12 02-Nov-1996 deraadt

timed off by default


Revision tags: OPENBSD_2_0_BASE
# 1.11 23-Sep-1996 deraadt

rfc1323 variable


# 1.10 04-Sep-1996 deraadt

control portmap, inetd, and lpd from netstart; idea from tqbf@enteract.com


# 1.9 27-Aug-1996 deraadt

224.0.0.0 not 0.0.0.224; from peter@demon.net


# 1.8 18-Jun-1996 deraadt

move std stuff from rc.local to rc


# 1.7 16-Jun-1996 deraadt

install sample commented /etc/ifaliases file; which can now contain #
comments and blank lines. new format is "interface address netmask"
(yes, i changed the order of the entries). inspired by netbsd pr#2474;
gillhaa@ghost.whirlpool.com


# 1.6 02-Jun-1996 tholo

Install a multicast route by default


# 1.5 26-May-1996 deraadt

sync & label


# 1.4 09-Jan-1996 dm

added IP filter to netstat/rc and put examples in /usr/share/ipf


# 1.3 30-Dec-1995 deraadt

from netbsd: start mrouted like routed


# 1.2 18-Dec-1995 deraadt

/etc/ifaliases support by randy@zyzzyva.com


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.204 21-May-2020 kn

Fix stripcom() description wrt. comments not on their own line

Neither netstart's nor install.sub's (subtly different) implementations
remove trailing comments on lines not starting as a comment, e.g.,
lines like "up #not down" go through unaltered and without "#not down"
being removed.

Only lines *beginning* with the comment sign ("#") are stripped.

No functional change, just updating function descriptions.


# 1.203 21-May-2020 kn

Do not treat backslashe as an escape character in hostname.if(5) lines

ifstart() should always pass such lines unaltered, especially if they
contain "nwid" or "description" lines with arbitrary strings.

<bsdlisten at gmail dot com> reported SSIDs such as "Mike's" during
installation end as broken; this was because the installer escaped
the single quote using backslashes which ended up being treated as
escape characters much later during hostname.if parsing in netstart(8).

Ok deraadt


Revision tags: OPENBSD_6_7_BASE
# 1.202 15-Jan-2020 kn

Do not redirect already quiet stdout for IPv6 reject routes

"route -q" already silences all standard output; if it still prints
something, that's a bug to fix in route.

OK bluhm


# 1.201 25-Oct-2019 dlg

handle aggr(4) in the same way as trunk(4)

from brad@
ok bluhm@ claudio@ deraadt@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.200 29-Aug-2018 krw

Historically /etc/netstart (and the equivalent code in the install
script) did 'ifconfig <if> down' before starting dhclient(8). This was
a way of ensuring old running copies of dhclient were killed before a
new one started. Current dhclient does not need this assist, so change
"ifconfig <if> down" to "ifconfig <if> up" pending further script
optimizations.

Similar to a 2014 attempt by halex@. Prompted by a misc@ report
from Kristjan Komlosi reporting hanging diskless setups.

ok halex@ kn@


# 1.199 08-Jul-2018 tb

netstart is used during system start, but also interactively.
Show proper error message if a regular user executes netstart.
Only do the privilege check if the id binary is available,
which might not be the case during diskless system startup.

ok deraadt, jasper, jca, krw, rpe (who wrote the same diff), sthen


# 1.198 28-Apr-2018 rpe

Add a proper usage() function.

Suggested by and OK jmc.
OK tb


Revision tags: OPENBSD_6_3_BASE
# 1.197 04-Mar-2018 jmc

when -n is used, no need to spit out "Missing parameters." before
displaying usage();

ok tb


# 1.196 03-Mar-2018 landry

Lowercase 'usage' and group -n with interface in it.
From jmc@, ok tb@


# 1.195 21-Feb-2018 rpe

Tweak comments.

OK tb


# 1.194 19-Feb-2018 rpe

Write warning/error messages to stderr and end them with a fullstop.

OK tb


# 1.193 19-Feb-2018 rpe

- use specific patterns when looping over /etc/hostname.if files
to skip backup or temp files.
- test if the patterns matched actual files
- warn if ifcreate() fails on an interface and continue with the
subsequent interfaces in the list instead of return'ing

OK dlg sthen tb


# 1.192 17-Feb-2018 rpe

- Add descriptions for the new functions ifcreate() and vifscreate()
- In ifcreate() use the exit code of the {} block directly
- In vifscreate(), use the ifconfig -C output directly in the for _vif loop
- Remove superfluous and somewhat confusing comment

OK dlg kn sthen


# 1.191 14-Feb-2018 dlg

create virtual interfaces before starting all interface config.

this resolves an ordering problem when adding pseudo interfaces to bridges

tweaks from kn@
ok mpi@ sthen@


# 1.190 10-Feb-2018 claudio

Remove some special IPv4 in IPv6 mapped prefixes that are already rejected
by the ::0.0.0.0/96 reject route added to deny all IPv4 mapped addresses.
Makes the inet6 routing table almost fit in one screen.
OK benno@


# 1.189 10-Feb-2018 florian

Load RFC 7217 key material and generate if it does not already exist.

Add soii.key to changelist (pointed out by semarie) and mtree/special
(suggest by Craig Skinner).

OK naddy, sthen, rpe, tb


# 1.188 06-Feb-2018 tb

If -n is given, the netstart script should not (try to) set the default
route(s). Simply print the command(s) to be issued instead.

tweak & ok rpe


# 1.187 12-Nov-2017 tb

Remove HN_DIR variable and expand it in the only place it was used. It
currently serves no purpose.

ok rpe, agreement from deraadt and halex


Revision tags: OPENBSD_6_2_BASE
# 1.186 25-Jul-2017 rpe

Finally remove backwards compat code to support the 'rtsol' keyword
in hostname.if(5)

OK mpi@ deraadt@ florian@
OK jmc@ from doc perspective


# 1.185 21-Jul-2017 rpe

Align ifstart() in netstart and install.sub.

- in netstart, rename _file to _hn referencing hostname.if files
- in install.sub switch ifstart() to be used with _if instead of
_hn as parameter

ok krw@ tb@


# 1.184 28-May-2017 awolk

etc/netstart: use colon separator instead of dot with chown

OK jung@, deraadt@, jmc@


# 1.183 07-May-2017 rpe

Change test from [] to [[]] and simplify pattern.

OK tb@, krw@ (for [[]])
Feedback and OK halex@


# 1.182 07-May-2017 rpe

Replace hardcoded script name with ${0##*/}

OK tb@ halex@


# 1.181 01-May-2017 rpe

Revert r1.170 and remove the id==0 check.
The id binary is not available in nfs diskless setups at this point.

reported by Andreas Kusalananda, thanks.
discussed with deraadt@


# 1.180 01-May-2017 rpe

Remove last remnants of rtsol. IPv6 autoconfiguration of interfaces is now
done in ifstart(). Remove ipv6autoconf() and replace rtsolif with a boolean
variable V6_AUTOCONF. Replace dhcpif with a boolean variable V4_DHCPCONF.
Both are later used in defaultroute() to decide whether or not to configre
defaultroutes from /etc/mygate.

OK krw@


# 1.179 30-Apr-2017 mpi

Do not try to delete a default route before adding it.

Now that route are automatically G/C with the address they are attached
to there's no reason to duplicate the kernel's job.

Fix a regression introduced with multipath default routes.

ok deraadt@


# 1.178 25-Apr-2017 rpe

Unbreak netstart for multiple inteface configurations like trunk
or carp. Ensure that the noglob option is disabled at the end of
parse_hn_line() and ifstart().

Reported by Christer Solskogen and Stefan Wollny, thanks!


# 1.177 24-Apr-2017 rpe

Introduce a new function parse_hn_line() that replaces the existing
hostname.if(5) parsing code in ifstart().
Add a -n option to netstart to only print the interface configuration
commands instead of executing them.
Add a HN_DIR variable, that points to the directory of the hostname.if
files (default /etc) that allows for future regression tests.

- add new parse_hn_line() function
- change ifstart()
- rename $if to $_if
- don't ifconfig or ifconfig create if -n option is used
- replace hostname.if(5) parsing code with new parse_hn_line()
- just print configuration commands if -n option is used
- autoconf now happens in ifstart(), remove ifv6autoconf()
- introduce HN_DIR variable for the hostname.if file location
- add handling of the -n option to only print config commands
- ensure -n is only used if interfaces are specified as parameters

Discussed with and positive feedback from many
'commit' deraadt@
OK sthen@


# 1.176 08-Apr-2017 rpe

- localize the if, file and stat variables which also ensures that
variables are not named like commands.
- change test from [] to [[]]

OK tb@ halex@


# 1.175 07-Apr-2017 rpe

Minimize differences in ifstart() function between netstart and
install.sub which makes it easier to spot changes in the future.

- comments and formatting
- quotes on assignments are not needed (netstart)
- remove stray space in test (netstart)
- use $file variable with while-loop (netstart)
- although valid, instead of i use $i in arithmetic test (install.sub)

OK krw@, tb@
Looks good deraadt@


# 1.174 07-Apr-2017 rpe

Align comments of ifstart() function in netstart and install.sub.


# 1.173 07-Apr-2017 rpe

Align comments of stripcom() function in netstart and install.sub.


Revision tags: OPENBSD_6_1_BASE
# 1.172 06-Dec-2016 mpi

Do not lose the default route when netstart(8) is run a second time on
the interface pointed to by the default route.

Since the kernel no longer keep routes with dangling address pointer,
netstart(8) has to re-add the default route when the corresponding ifa
has been deleted and re-created.

deraadt@ points out that even if the previous semantic was not necessarily
better, a script like netstart(8) cannot totally fix the default route
problem.

Regression reported by and fix tested by Hrvoje Popovski.

ksh foo checked by halex@


# 1.171 27-Sep-2016 rzalamena

Delay switch(4) interface start up so it can attach virtual interfaces
like vether(4).

nits from and ok benno@, phessler@


# 1.170 09-Sep-2016 jasper

print a clear error message when not ran as root instead of just falling
through and try whatever it can do with the invoking user's perms

feedback/ok aja@ rpe@


Revision tags: OPENBSD_6_0_BASE
# 1.169 19-Jul-2016 mpi

Do not consider tap(4) a special interface and start if before other
pseudo-interfaces.

This unbreak vlan(4) on top of tap(4) since the refactoring to turn it
MP-safe.

ok claudio@, deraadt@


# 1.168 27-Mar-2016 sthen

Don't delete the 224/4 route in netstart, unless it's being done to ensure that
a -reject route can be added. Restores the ability to set an interface route
before daemons are started, lost during the previous simplification.
ok millert mpi


Revision tags: OPENBSD_5_9_BASE
# 1.167 29-Dec-2015 rpe

Remove backslash, not necessary after '&&'

OK halex@


# 1.166 29-Dec-2015 rpe

Replace last remaining `` with $()

OK halex@


# 1.165 18-Dec-2015 ajacoutot

Drop the now useless multicast setup comment.

prodded by tim@, ok mpi@


# 1.164 17-Dec-2015 ajacoutot

Simplify multicast option handling (10 less lines) by matching /etc/rc behavior
towards other YES|NO options and drop the error warning.


with and ok tim@, ok rpe@ on an earlier diff


# 1.163 05-Dec-2015 mpi

It does not make sense to insert a specific route for 224/4 when the
default one is good enough.

So merge rc.conf(8)'s 'multicast_router' and 'multicast_host' into a
single 'multicast'. If set to YES the reject route for 224/4 is not
inserted by netstart(8).

Manual bits from jmc@

ok henning@, ajacoutot@


# 1.162 12-Nov-2015 rpe

Changes to ifautostart():
- Rename function to ifv6autoconf() to make IPv6 relation clearer
- Localize and rename variables

OK krw@


# 1.161 12-Nov-2015 rpe

Changes to ifmstart():
- Change comments to make it clearer that ifmstart() takes two lists
of interface driver names (of which the second is optional) and not
the actual interface instances.
- Use localized variables and use slightly more verbose names.
- Use continue 2 to skip to the next hostname.if file.
- Use shell pattern @() instead of testing _sif individually.

OK krw@


# 1.160 12-Nov-2015 rpe

Changes to stripcom():
- Align comments with /etc/rc version
- Use localized variables
- Use safer "print -r --" instead of plain echo

Changes to ifstart():
- Tweak comment
- Add usage

OK krw@


# 1.159 01-Nov-2015 rpe

Start the rework of the /etc/netstart shell script.

General changes:
- apply a similar 'style' as used in the installer scripts
- improve comments to be more to the point, remove where code is obvious
- document usage of functions if they have arguments
- rename variables where it improves readability
- replace really old-school shell code with more contemporary idioms

Other changes:
- No need to care about "autoboot" because netstart doesn't inherit the
positional parameters from /etc/rc anymore. /etc/rc executes netstart
instead of sourcing it since r1.439.
- Use simpler for-loop to process list of interfaces with ifstart.

OK halex@


# 1.158 26-Oct-2015 rpe

The hostname variable is not used since r1.99. Remove it and use
stripcom() output directly with the hostname command.

OK deraadt@ krw@


# 1.157 23-Oct-2015 claudio

netstart bits for tap(4)


# 1.156 27-Sep-2015 sthen

Don't print output when setting autoconf on interfaces. Suggested by deraadt,
ok florian@ rpe@


# 1.155 13-Sep-2015 sthen

only print the "IPv6 autoconf" line if there are interfaces to configure
feedback/ok rpe


# 1.154 11-Sep-2015 sthen

Set "inet6 autoconf" individually on interfaces that have rtsol set in
hostname.if, previously netstart tried to configure them all at once
("ifconfig if0 if1 if2 inet6 autoconf"). From Delan Azabani, ok phessler@


Revision tags: OPENBSD_5_8_BASE
# 1.153 20-Jul-2015 rpe

Disable Strict Bourne shell mode for /etc/rc and /etc/netstart to be
able to use ksh syntax within these scripts. This way init doesn't
need to be changed, which starts /etc/rc using /bin/sh and people
can still use "sh /etc/netstart ifname".

Idea from and OK halex@
OK deraadt@ krw@ guenther@


# 1.152 19-Jul-2015 florian

Bring up pflow last as it might send with a source address that is on
any of the other interfaces.
OK deraadt, phessler, benno


# 1.151 19-Jul-2015 rpe

Always source rc.subr to be able to use the rc.conf parsing routine
to get the network related vars from rc.conf. This is even necessary
if netstart is run from within /etc/rc. Remove test of $INRC which
unintentionally evaluated always to true.

problem with previous change found by nigel@
OK sthen@ aja@ halex@


# 1.150 19-Jul-2015 ajacoutot

Revert 1.148 for now until I can talk to rpe@
It introduced a regression reported by nigel@


# 1.149 19-Jul-2015 rpe

Replace test command with [].

OK halex@ krw@


# 1.148 19-Jul-2015 rpe

Ensure, that we source rc.subr and parse rc.conf ONLY if we are not
inside /etc/rc.

With help from and OK halex@, ajacoutot@


# 1.147 18-Jul-2015 rpe

- remove trailing blanks introduced in previous commit
- no space in redirections like </foo or >$bar
- few other minor whitespaces

OK krw@


# 1.146 18-Jul-2015 rpe

Improve comments
- Add comments for functions
- Start comments with capital letters
- End comments with a full stop
- Allow comments to extend up to column 80

OK krw@


# 1.145 06-Jun-2015 florian

Allow rtsol keyword in hostname.if(5) with net.inet6.ip6.forwarding=1.
"inet6 autoconf" was working before and rtsol should behave the same.
OK phessler


Revision tags: OPENBSD_5_7_BASE
# 1.144 03-Dec-2014 florian

The kernel handles rtsol(8) functionality since some time now.
Treat rtsol in hostname.if as a keyword like dhcp and call ifconfig
inet6 autoconf.
"reads good" todd@
OK krw@ (who is *not* an IPv6 person), but I recruited him in his
capacity as an installer person.


# 1.143 28-Sep-2014 claudio

Revert 1.142. Without the down netstart will just print the ifconfig
output because it may end up just calling 'ifconfig $if'. This needs
to be done better and properly tested.


# 1.142 26-Sep-2014 halex

remove explicit 'down' of an interface before starting a dhcp request, thereby
avoiding annoying delays for some switch configurations

ok claudio@ deraadt@

i would add ok phessler@, but it was not valid without an ok krw@


Revision tags: OPENBSD_5_6_BASE
# 1.141 12-Jul-2014 stsp

Fix netstart after autoconf6 change so 'rtsol' lines in hostname.if work again.
found by pelikan@; ok pelikan@ henning@


# 1.140 12-Jul-2014 robert

Make rc.conf a parsed configuration file and stop sourcing it as a shell
script.
From now on rc.conf has a fixed syntax (key=val) and it is not allowed
to add anything to it besides the supported syntax, it all going to be
ignored.

discussed with and help from deraadt@ and halex@


Revision tags: OPENBSD_5_5_BASE
# 1.139 22-Aug-2013 mpi

Like for dhclient, do no create a route to alias addresses via 127.0.0.1.
Our stack is able to tell if the address is local or not.

ok todd@, krw@


Revision tags: OPENBSD_5_4_BASE
# 1.138 20-Mar-2013 todd

fix lies in netstart; replacement wording from halex@
pointed out by Ryan Kavannagh rak at debian dot org


Revision tags: OPENBSD_5_3_BASE
# 1.137 05-Dec-2012 rpe

remove "Invalid interface name" message
requested by krw@

ok halex@


# 1.136 02-Dec-2012 rpe

use the more compact version of the check for ifconfig'able interfaces
from install.sub

with feedback from and ok halex


# 1.135 02-Dec-2012 rpe

- remove isalphanumeric() and replace it with a shell pattern, that
tries a bit harder to identify invalid interface names and in
this case emit an error message.
- use [[ $1 == autoboot ]] to avoid a shell error message due to
possible spaces in first argument
- no change in functionality

discussed with krw and halex
ok ("I like this") krw


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.134 07-Oct-2011 deraadt

The new ypbind changes requires that the domainname be set before
rc.conf is run. There's no real downside.
ok aja


Revision tags: OPENBSD_5_0_BASE
# 1.133 07-Jul-2011 guenther

Eliminate some $? tests by rolling the command into the condition

ok halex@


# 1.132 26-May-2011 mpf

Add svlan(4) startup bits.
From markus@. OK naddy, claudio, reyk.


Revision tags: OPENBSD_4_9_BASE
# 1.131 09-Feb-2011 sobrado

fix an unbalanced parenthesis in a comment; while here, split the comment
in a better place to make it more readable.

ok jmc@ and miod@


Revision tags: OPENBSD_4_8_BASE
# 1.130 16-Jun-2010 todd

permit e.g. -inet6 syntax by slurping all lines not just some
noticed by rhsv6 at hushmail dot com, ok sthen@


Revision tags: OPENBSD_4_7_BASE
# 1.129 12-Jan-2010 henning

when setting up lo0 use 127.0.0.1/8 instead of 127.0.0.1 for clarity and
correctness. it's not 1992 any more, kids. ok mcbride dlg krw


# 1.128 10-Dec-2009 todd

o stop reordering ifconfig arguments (e.g. after 'up ..')
o only stop processing if inet or inet6 lines are malformed
o everything not a specially handled bit is passed to ifconfig unmangled
noticed by several after the move from bridgename.bridge0 -> hostname.bridge0
prodded by deraadt@, tested by and feedback from several
man page bits 'look fine' jmc@


# 1.127 22-Nov-2009 deraadt

Stop supporting bridgename.bridge* files, and move to hostname.bridge*
files. To cope with this change, read about the mv command.
ok claudio todd


# 1.126 17-Sep-2009 simon

change variable i to $i in an expression of ifstart() for consistency
with the rest of the file. no functional change.

feedback from sthen@, ok krw@


# 1.125 10-Jul-2009 jdixon

Delay creation of tun(4) interfaces until the underlying interface and
routes are available. This fixes usage for some OpenVPN users that start
it from hostname.tun*.

Tested by Johan Huldtgren. ok sthen@, johan@.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.124 25-Nov-2008 markus

delay /etc/netstart until IPv6-DAD (dup-address-detection) is completed.
ok fries, hshoexer, claudio


# 1.123 14-Aug-2008 sthen

Tools from /usr may not be used in netstart since it may be NFS-mounted
and not available at that time. Rewrite the hostname.if permission check
to use only /bin/ls and the shell. Requested by deraadt.

ok todd, "Twisted." deraadt


Revision tags: OPENBSD_4_4_BASE
# 1.122 23-Jul-2008 sthen

Prevent warning about insecure hostnames where no /etc/hostname.*
exists. From wcmaier@.

Check target of symbolic links to avoid noise at boot and in
seucrity output where you have several interfaces symlinked to one
config file.

"If you think this is the right thing to do" deraadt@


# 1.121 09-Jun-2008 todd

warn once not 3 times in case of a non existent file, discussed with deraadt
originally pointed out by Johan Torin


# 1.120 09-Jun-2008 deraadt

Ensure that hostname.* files are also re-chowned to root.wheel at each
boot as discussed with claudio while eating tasty donairs. ok todd


# 1.119 17-Apr-2008 deraadt

before using them, force hostname.* files to be unreadable by world
first version from todd, ok millert


Revision tags: OPENBSD_4_3_BASE
# 1.118 17-Jan-2008 brad

Execute rtsol after turning up trunk(4) and vlan(4) interfaces so they're
taken into consideration for rtsol.

ok reyk@ dlg@


# 1.117 09-Jan-2008 mpf

Do not bring up pfsync(4) before the working ruleset
has been loaded. Otherwise, states that are received during the
initial bulk update mismatch the correct pf-checksum and
do not attach to the rules.
Problem identified by david@. Fix done in collaboration.
OK henning@


Revision tags: OPENBSD_4_2_BASE
# 1.116 02-Aug-2007 david

move the delay for IPv6 DAD to after all interfaces have started
fixes problems with daemons being unable to bind to all addreses at boot
ok itojun@ hshoexer@


Revision tags: OPENBSD_4_1_BASE
# 1.115 15-Nov-2006 itojun

reject multicast packet without scope identifier specified.


Revision tags: OPENBSD_4_0_BASE
# 1.114 29-Jun-2006 todd

do not add an extra space; nwid and description come out wrong
fix as proposed by maja@, thanks!


Revision tags: OPENBSD_3_9_BASE
# 1.113 28-Dec-2005 david

nuke extra whitespace


# 1.112 06-Dec-2005 reyk

multicast_host=YES only works if a valid default gateway is available.
validate this condition and reject multicast traffic on failure.

ok todd@ naddy@


# 1.111 02-Nov-2005 todd

fix inspired by pr#4590
ok krw@


# 1.110 25-Oct-2005 todd

better logic from krw@:
- do not process mygate for v4 if dhcp
- do not process mygate for v6 if rtsol
this also makes the mygate processing logic more readable
ok krw@


# 1.109 14-Oct-2005 todd

add v6 support for /etc/mygate
ok deraadt@ mickey@ krw@
same functionality tested/ok'ed by by mickey, brad, matthieu, and me
with this one may now put a v6 IP in /etc/mygate on a separate line from
the v4 default gateway and netstart will do the right thing


# 1.108 12-Oct-2005 todd

shrink stripcom(), sync with install.sub
ok krw@


# 1.107 04-Oct-2005 todd

trunk must be started after physical ethernet devices, but before vlan.
populate ifmstart lines accordingly.
prodded/tested by brad@
ok reyk@


# 1.106 28-Sep-2005 todd

use eval consistently, fixes description quotes on rtsol and dhcp
fix inspired by and closes pr 4495
ok krw@


Revision tags: OPENBSD_3_8_BASE
# 1.105 22-May-2005 todd

Introduce 'ifmstart' to deal with starting multiple interfaces minus a list
of interfaces.

This reduces the netstart script by 174 chars, 13 words, and 19 lines, but
more importantly, makes it more simple and less cluttered should more special
case/orderings be needed.

ok brad@ and pr 4197 submitter, inspired by and closes pr 4197


# 1.104 04-Apr-2005 djm

unbreak; ok pval@


# 1.103 03-Apr-2005 deraadt

if dhcp is used to get an address on any interface, ignore /etc/mygate
ok krw
(this lets us do something rather cool with the zaurus in particular)


Revision tags: OPENBSD_3_7_BASE
# 1.102 04-Jan-2005 mcbride

Bring up the carp(4) interface before default route.

ok pascoe@ mpf@


# 1.101 30-Dec-2004 millert

Add a copy of stripcom so /etc/netstart can be run standalone again.
OK deraadt@


# 1.100 19-Dec-2004 millert

Allow comments in /etc/{myname,mygate,defaultdomain}; OK deraadt@


# 1.99 04-Dec-2004 itojun

remove "route $hostname 127.0.0.1" line. deraadt ok
*** please update /etc/netstart and test if it works ok for you ***


# 1.98 20-Oct-2004 deraadt

make all route commands use -qn; ok mcbride henning


Revision tags: OPENBSD_3_6_BASE
# 1.97 29-May-2004 deraadt

one last route command lacking -qn


Revision tags: OPENBSD_3_5_BASE
# 1.96 22-Mar-2004 mcbride

Make sure pfsync is brought up before carp.

ok deraadt@


# 1.95 13-Mar-2004 mcbride

Delay pfsync(4) configuration, as the syncif has to be configured in
advance. From Thorsten Lockert.


# 1.94 14-Jan-2004 deraadt

ok, it took quite a bit of prodding but itojun finally explained why the
extra sleep 1 is in here, and we came to the conclusion it is safe to
delete it. whee.


# 1.93 13-Jan-2004 deraadt

repair v6 lo0 documentation


# 1.92 11-Jan-2004 deraadt

add loopback routes late


# 1.91 09-Jan-2004 deraadt

create all routes with -q; markus ok


# 1.90 04-Dec-2003 millert

Need to do "ifconfig create" for bridge interfaces too.


# 1.89 03-Dec-2003 markus

add support for ifconfig clone; from netbsd; ok deraadt, henning


# 1.88 20-Oct-2003 david

delay carp initialization until after physical interfaces are configured
ok mcbride@ henning@ deraadt@ todd@


Revision tags: OPENBSD_3_4_BASE
# 1.87 27-Aug-2003 henning

only try to set hostname to what /etc/myname says if that file actually exists,
otherwise preserve `hostname`
netbooted machines can live perfectly fine without it; they get their hostname
earlier.

ok krw@ cedric@


Revision tags: OPENBSD_3_3_BASE
# 1.86 16-Feb-2003 krw

Fix up some DNS verbiage to make it consistant.

Fix up default route selection by

a) Forcing user to explicitly chose 'dhcp' as a mechanism for
specifying a default route, rather than guessing based on one or more
interfaces being configured by dhcp.

b) If the user specified default route does not work, re-present the
existing default route rather than losing it.

c) Move default route selection to after nameserver activation so the
user can specify a hostname as the default route.

Change /etc/netstart so that /etc/mygate wins if a default route was
already specified (i.e. by dhcp).

ok deraadt@.


Revision tags: OPENBSD_3_2_BASE
# 1.85 16-May-2002 todd

ignore non-existent cases where '$if' evaluates to '*'.
From Andr� Lucas <andre@ae-35.com>, fixes pr # 2658.
'Looks good' from miod@, millert@, and krw@.


Revision tags: OPENBSD_3_1_BASE
# 1.84 23-Feb-2002 deraadt

re-add support for $if expansion; hamajima@nagoya.ydc.co.jp


# 1.83 21-Feb-2002 miod

Change the network components initialization order.
Change from:
o all interfaces
o all bridges
o routes
to:
o physical interfaces
o routes
o gif and gre interfaces
o bridges

Fixeski PR #2400.
Manual page updates coming soon.
Ok angelos@ chris@ deraadt@


Revision tags: OPENBSD_3_0_BASE
# 1.82 31-Jul-2001 hugh

a space before a redirect


# 1.81 06-Jul-2001 angelos

Also, source /etc/rc.conf so we can pull in the
multicast_host/multicast_router settings; this is useful if one
flushes the routing table and re-initializes.

We really need a netconfig tool of sorts.


# 1.80 06-Jul-2001 angelos

Use "route -n show -inet" to determine the default multicast iface.


# 1.79 03-Jul-2001 deraadt

pull in rc.conf early so that pf(1) startup is right; tested by jasoni, comments from millert


# 1.78 30-May-2001 deraadt

Remove ipf. Darren Reed has interpreted his (old, new, whichever)
licence in a way that makes ipf not free according to the rules we
established over 5 years ago, at www.openbsd.org/goals.html (and those
same basic rules govern the other *BSD projects too). Specifically,
Darren says that modified versions are not permitted. But software
which OpenBSD uses and redistributes must be free to all (be they
people or companies), for any purpose they wish to use it, including
modification, use, peeing on, or even integration into baby mulching
machines or atomic bombs to be dropped on Australia. Furthermore, we
know of a number of companies using ipf with modification like us, who
are now in the same situation, and we hope that some of them will work
with us to fill this gap that now exists in OpenBSD (temporarily, we
hope).


Revision tags: OPENBSD_2_9_BASE
# 1.77 13-Mar-2001 deraadt

spelling; maurice@maurice.wan.nl


# 1.76 06-Feb-2001 todd

ignore blank lines in addition to comments
fixes pr#1660 from wilfried@telia.com .. Thanks!


# 1.75 10-Jan-2001 jason

support !command in bridgename.if files, too


# 1.74 27-Nov-2000 millert

Use -n to test if a variable is non-zero. Otherwise, if the variable's
contents start with a '-' test becomes unhappy (since it interprets it
as another option).


# 1.73 08-Nov-2000 todd

This fixes pr 1481, we now handle args > 6 in /etc/hostname.if in the
cases where we did not previously handle them.
Thanks to Scott Atwood <atwood@cs.stanford.edu> for reminding us of this.


Revision tags: OPENBSD_2_8_BASE
# 1.72 02-Sep-2000 todd

subtle bug .. global variables in a while loop need reset 'just incase'
With:
hostname.fxp0 having a last line of:
inet6 alias 3ffe:...
and hostname.gif0 having a first two lines of:
giftunnel 1.2.3.4
dest 1.2.4.3
We end up with the command:
ifconfig gif0 giftunnel alias 1.2.3.4 1.2.4.3
.. which is clearly wrong and fixed by this change


# 1.71 18-Jun-2000 todd

rc.conf now parses ${local_rcconf} internally; closes pr 1259


Revision tags: OPENBSD_2_7_BASE
# 1.70 08-May-2000 todd

fix dhcp 'NONE' ness from install to allow media parsing to work
.. ok deraadt@, millert@


# 1.69 21-Apr-2000 deraadt

rc.conf.local support, inspired by chuck yerkes


# 1.68 04-Apr-2000 millert

Remove the -E flag from ipf as it is implicitly enabled and using
the -E flag here causes the kernel to printf 'IP Filter: already
initialized'.


# 1.67 18-Mar-2000 deraadt

silence all extra route addition printouts


# 1.66 17-Mar-2000 itojun

correct reject route installations for IPv6. improve comments.


# 1.65 12-Mar-2000 itojun

disallow packets to malicious 6to4 prefix, based on
http://playground.iijlab.net/i-d/draft-itojun-ipv6-transition-abuse-00.txt


# 1.64 10-Mar-2000 todd

fix non behavior
with this `!' lines in /etc/hostname.* run even without certain lines
(like a comment) preceeding it.


# 1.63 10-Jan-2000 todd

allow arbitrary commands in /etc/hostname.* files if the line starts with '!'


# 1.62 02-Jan-2000 deraadt

rtsol case can configure the interface up, since it would be nice to finish
DAD before the actual rtsol(8) run happens later. and since it will rtsol,
it is going to be up in any case.


# 1.61 02-Jan-2000 itojun

one more indentation fix.


# 1.60 02-Jan-2000 itojun

indentation fix (todd's part)


# 1.59 02-Jan-2000 todd

fix rtsold case, reset cmd for each iteration!


# 1.58 02-Jan-2000 itojun

allow options after "rtsol".
XXX both "dhcp" and "rtsol" has keyword *down* at the end. is it okay?


# 1.57 02-Jan-2000 itojun

echo "IPv6 autoconf: interfaces" before invoking rtsol.
sleep for net.inet6.ip6.dad_count seconds to ensure that IPv6 DAD is completed.
TODO: rtsold (rc.conf line), manpage


# 1.56 02-Jan-2000 itojun

ipv6 autoconf on hosts (non-routers).

to do this,
1. in sysctl.conf, add these lines:
net.inet6.ip6.forwarding=0
net.inet6.ip6.accept_rtadv=1
2. in hostname.foo, add
rtsol

specifying two or more interfaces with "rtsol" may result in strange
behavior - ipv6 spec does not permit multi-interface node to be autoconfig'ed.


# 1.55 02-Jan-2000 todd

add to hostname.* parsing:
- multiple entries support (read: aliases)
- inet6 support
- support for comments (#)
(look for hostname.if(5) commit for syntax details)


# 1.54 31-Dec-1999 itojun

install IPv6 reject routes only if kernel is capable of IPv6.


# 1.53 09-Dec-1999 itojun

avoid transmitting invalid IPv6 packets out to the wire.


# 1.52 09-Dec-1999 itojun

do not perform IPv6 initialization for loopback interface.
MUST make lo0 up before any IPv6 operations.
it will be considered a pilot error if you don't.
(I prefer to have lo0 initialized automatically)


Revision tags: OPENBSD_2_6_BASE
# 1.51 01-Sep-1999 deraadt

support # characters in bridgename.* files; millert


# 1.50 01-Sep-1999 deraadt

cleanup parsing of hostname.* files, and seperate bridge control into
bridgename.* files; all documented in new hostname.if(5) and
bridgename.if(5) man pages


# 1.49 09-Aug-1999 angelos

Only parse/setup the hostname.foo file if interface foo exists (this
is useful for laptops with different ethernet cards etc.)


Revision tags: OPENBSD_2_5_BASE
# 1.48 29-Mar-1999 niklas

New multicast route setup style


# 1.47 26-Mar-1999 niklas

Add bridge interface handling


# 1.46 01-Mar-1999 millert

Add support in /etc/hostname.xxx for files of the format:
up [options]
Any of the following may or may not be set:
$name $mask $bcaddr $extras


# 1.45 28-Oct-1998 millert

Kill the awful hack used to match and split /etc/hostname.* We now use
a function, isalphanumeric, to determine whether an interface name is
likely to be valid. This means that things like /etc/hostname.le0.bak,
/etc/hostname.le0#, /etc/hostname.le0~, etc. will be ignored as they
should. There is no longer an implicate assumption that /etc/hostname.*
only contains a single '.'.


Revision tags: OPENBSD_2_4_BASE
# 1.44 06-Oct-1998 deraadt

move ipnat to end of netstart, to support dhcp+ipnat


# 1.43 18-Sep-1998 deraadt

apply media directives on dhcp interfaces


# 1.42 10-Sep-1998 marc

better way of handling dhcp client; Jason Ish <jbi130@mail.usask.ca>


# 1.41 08-Sep-1998 marc

dhcp client stuff. "Angelos D. Keromytis" <angelos@dsl.cis.upenn.edu>


# 1.40 24-Aug-1998 downsj

You can't use -interface default when there's no default gateway
set (yet). Use -interface $hostname if mygate doesn't exist so that
this actually works on routers.


# 1.39 04-Jul-1998 deraadt

put 224 route on default, to avoid a hostname lookup


# 1.38 22-May-1998 deraadt

use route -n, what the heck


Revision tags: OPENBSD_2_3_BASE
# 1.37 28-Mar-1998 deraadt

s/^nat/ipnat/


# 1.36 23-Feb-1998 niklas

remove trailing blank line


# 1.35 07-Feb-1998 deraadt

ipforward is in sysctl.conf now


# 1.34 21-Dec-1997 deraadt

ugh


# 1.33 20-Dec-1997 deraadt

ipforwarding option in rc.conf


# 1.32 29-Nov-1997 kstailey

NAT requires IPF


# 1.31 04-Nov-1997 deraadt

kill spaces at ends of lines; m4


Revision tags: OPENBSD_2_2_BASE
# 1.30 14-Oct-1997 deraadt

set hostname/domainname before running rc.conf; m4@umn.edu


# 1.29 04-Sep-1997 deraadt

fork netstart; new child is rc.conf


# 1.28 25-Aug-1997 millert

Explicately pass -host flag to route(8) to avoid confusion with networks.


# 1.27 19-Aug-1997 niklas

Add hook for rpc.lockd, make nfsd flags settable in netstart


# 1.26 31-Jul-1997 downsj

Make quotas optional; wedged into netstart for the time being.
/etc/rc.conf, anyone?


# 1.25 30-Jul-1997 deraadt

do not run routed by default


# 1.24 28-Jul-1997 kstailey

Move configuration of loopback interface to before all other interfaces.
Allows the use of local caching-only nameserver with no "nameserver"
entry in /etc/resolv.conf to configure a route between the hostname
and loopback.


# 1.23 25-Jul-1997 provos

earlier start of keymanagement


# 1.22 24-Jul-1997 deraadt

make amd use /tmp_mnt by default


# 1.21 22-Jul-1997 provos

start the photuris daemon per default. hilfe.


# 1.20 17-Jun-1997 niklas

Put in hooks to start ypserv with flags


# 1.19 17-Jun-1997 niklas

Put in hooks to start rpc.yppasswdd with flags


Revision tags: OPENBSD_2_1_BASE
# 1.18 15-Apr-1997 deraadt

kill route flush until .. hmm kernel routing socket bug or something


# 1.17 09-Apr-1997 kstailey

add NAT startup


# 1.16 07-Apr-1997 rees

flush all old routes before adding new interfaces or routes.
ref: netbsd pr3228/misc, Matthias Scheler


# 1.15 03-Mar-1997 downsj

fix typo


# 1.14 11-Feb-1997 deraadt

add default route before fiddling with loopback route to avoid DNS problems; m4@umn.edu, #97


# 1.13 03-Feb-1997 deraadt

do ifaliases after /usr/bin exists in nfs diskless env; pr#77, matthieu@laas.fr


# 1.12 02-Nov-1996 deraadt

timed off by default


Revision tags: OPENBSD_2_0_BASE
# 1.11 23-Sep-1996 deraadt

rfc1323 variable


# 1.10 04-Sep-1996 deraadt

control portmap, inetd, and lpd from netstart; idea from tqbf@enteract.com


# 1.9 27-Aug-1996 deraadt

224.0.0.0 not 0.0.0.224; from peter@demon.net


# 1.8 18-Jun-1996 deraadt

move std stuff from rc.local to rc


# 1.7 16-Jun-1996 deraadt

install sample commented /etc/ifaliases file; which can now contain #
comments and blank lines. new format is "interface address netmask"
(yes, i changed the order of the entries). inspired by netbsd pr#2474;
gillhaa@ghost.whirlpool.com


# 1.6 02-Jun-1996 tholo

Install a multicast route by default


# 1.5 26-May-1996 deraadt

sync & label


# 1.4 09-Jan-1996 dm

added IP filter to netstat/rc and put examples in /usr/share/ipf


# 1.3 30-Dec-1995 deraadt

from netbsd: start mrouted like routed


# 1.2 18-Dec-1995 deraadt

/etc/ifaliases support by randy@zyzzyva.com


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.202 15-Jan-2020 kn

Do not redirect already quiet stdout for IPv6 reject routes

"route -q" already silences all standard output; if it still prints
something, that's a bug to fix in route.

OK bluhm


# 1.201 25-Oct-2019 dlg

handle aggr(4) in the same way as trunk(4)

from brad@
ok bluhm@ claudio@ deraadt@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.200 29-Aug-2018 krw

Historically /etc/netstart (and the equivalent code in the install
script) did 'ifconfig <if> down' before starting dhclient(8). This was
a way of ensuring old running copies of dhclient were killed before a
new one started. Current dhclient does not need this assist, so change
"ifconfig <if> down" to "ifconfig <if> up" pending further script
optimizations.

Similar to a 2014 attempt by halex@. Prompted by a misc@ report
from Kristjan Komlosi reporting hanging diskless setups.

ok halex@ kn@


# 1.199 08-Jul-2018 tb

netstart is used during system start, but also interactively.
Show proper error message if a regular user executes netstart.
Only do the privilege check if the id binary is available,
which might not be the case during diskless system startup.

ok deraadt, jasper, jca, krw, rpe (who wrote the same diff), sthen


# 1.198 28-Apr-2018 rpe

Add a proper usage() function.

Suggested by and OK jmc.
OK tb


Revision tags: OPENBSD_6_3_BASE
# 1.197 04-Mar-2018 jmc

when -n is used, no need to spit out "Missing parameters." before
displaying usage();

ok tb


# 1.196 03-Mar-2018 landry

Lowercase 'usage' and group -n with interface in it.
From jmc@, ok tb@


# 1.195 21-Feb-2018 rpe

Tweak comments.

OK tb


# 1.194 19-Feb-2018 rpe

Write warning/error messages to stderr and end them with a fullstop.

OK tb


# 1.193 19-Feb-2018 rpe

- use specific patterns when looping over /etc/hostname.if files
to skip backup or temp files.
- test if the patterns matched actual files
- warn if ifcreate() fails on an interface and continue with the
subsequent interfaces in the list instead of return'ing

OK dlg sthen tb


# 1.192 17-Feb-2018 rpe

- Add descriptions for the new functions ifcreate() and vifscreate()
- In ifcreate() use the exit code of the {} block directly
- In vifscreate(), use the ifconfig -C output directly in the for _vif loop
- Remove superfluous and somewhat confusing comment

OK dlg kn sthen


# 1.191 14-Feb-2018 dlg

create virtual interfaces before starting all interface config.

this resolves an ordering problem when adding pseudo interfaces to bridges

tweaks from kn@
ok mpi@ sthen@


# 1.190 10-Feb-2018 claudio

Remove some special IPv4 in IPv6 mapped prefixes that are already rejected
by the ::0.0.0.0/96 reject route added to deny all IPv4 mapped addresses.
Makes the inet6 routing table almost fit in one screen.
OK benno@


# 1.189 10-Feb-2018 florian

Load RFC 7217 key material and generate if it does not already exist.

Add soii.key to changelist (pointed out by semarie) and mtree/special
(suggest by Craig Skinner).

OK naddy, sthen, rpe, tb


# 1.188 06-Feb-2018 tb

If -n is given, the netstart script should not (try to) set the default
route(s). Simply print the command(s) to be issued instead.

tweak & ok rpe


# 1.187 12-Nov-2017 tb

Remove HN_DIR variable and expand it in the only place it was used. It
currently serves no purpose.

ok rpe, agreement from deraadt and halex


Revision tags: OPENBSD_6_2_BASE
# 1.186 25-Jul-2017 rpe

Finally remove backwards compat code to support the 'rtsol' keyword
in hostname.if(5)

OK mpi@ deraadt@ florian@
OK jmc@ from doc perspective


# 1.185 21-Jul-2017 rpe

Align ifstart() in netstart and install.sub.

- in netstart, rename _file to _hn referencing hostname.if files
- in install.sub switch ifstart() to be used with _if instead of
_hn as parameter

ok krw@ tb@


# 1.184 28-May-2017 awolk

etc/netstart: use colon separator instead of dot with chown

OK jung@, deraadt@, jmc@


# 1.183 07-May-2017 rpe

Change test from [] to [[]] and simplify pattern.

OK tb@, krw@ (for [[]])
Feedback and OK halex@


# 1.182 07-May-2017 rpe

Replace hardcoded script name with ${0##*/}

OK tb@ halex@


# 1.181 01-May-2017 rpe

Revert r1.170 and remove the id==0 check.
The id binary is not available in nfs diskless setups at this point.

reported by Andreas Kusalananda, thanks.
discussed with deraadt@


# 1.180 01-May-2017 rpe

Remove last remnants of rtsol. IPv6 autoconfiguration of interfaces is now
done in ifstart(). Remove ipv6autoconf() and replace rtsolif with a boolean
variable V6_AUTOCONF. Replace dhcpif with a boolean variable V4_DHCPCONF.
Both are later used in defaultroute() to decide whether or not to configre
defaultroutes from /etc/mygate.

OK krw@


# 1.179 30-Apr-2017 mpi

Do not try to delete a default route before adding it.

Now that route are automatically G/C with the address they are attached
to there's no reason to duplicate the kernel's job.

Fix a regression introduced with multipath default routes.

ok deraadt@


# 1.178 25-Apr-2017 rpe

Unbreak netstart for multiple inteface configurations like trunk
or carp. Ensure that the noglob option is disabled at the end of
parse_hn_line() and ifstart().

Reported by Christer Solskogen and Stefan Wollny, thanks!


# 1.177 24-Apr-2017 rpe

Introduce a new function parse_hn_line() that replaces the existing
hostname.if(5) parsing code in ifstart().
Add a -n option to netstart to only print the interface configuration
commands instead of executing them.
Add a HN_DIR variable, that points to the directory of the hostname.if
files (default /etc) that allows for future regression tests.

- add new parse_hn_line() function
- change ifstart()
- rename $if to $_if
- don't ifconfig or ifconfig create if -n option is used
- replace hostname.if(5) parsing code with new parse_hn_line()
- just print configuration commands if -n option is used
- autoconf now happens in ifstart(), remove ifv6autoconf()
- introduce HN_DIR variable for the hostname.if file location
- add handling of the -n option to only print config commands
- ensure -n is only used if interfaces are specified as parameters

Discussed with and positive feedback from many
'commit' deraadt@
OK sthen@


# 1.176 08-Apr-2017 rpe

- localize the if, file and stat variables which also ensures that
variables are not named like commands.
- change test from [] to [[]]

OK tb@ halex@


# 1.175 07-Apr-2017 rpe

Minimize differences in ifstart() function between netstart and
install.sub which makes it easier to spot changes in the future.

- comments and formatting
- quotes on assignments are not needed (netstart)
- remove stray space in test (netstart)
- use $file variable with while-loop (netstart)
- although valid, instead of i use $i in arithmetic test (install.sub)

OK krw@, tb@
Looks good deraadt@


# 1.174 07-Apr-2017 rpe

Align comments of ifstart() function in netstart and install.sub.


# 1.173 07-Apr-2017 rpe

Align comments of stripcom() function in netstart and install.sub.


Revision tags: OPENBSD_6_1_BASE
# 1.172 06-Dec-2016 mpi

Do not lose the default route when netstart(8) is run a second time on
the interface pointed to by the default route.

Since the kernel no longer keep routes with dangling address pointer,
netstart(8) has to re-add the default route when the corresponding ifa
has been deleted and re-created.

deraadt@ points out that even if the previous semantic was not necessarily
better, a script like netstart(8) cannot totally fix the default route
problem.

Regression reported by and fix tested by Hrvoje Popovski.

ksh foo checked by halex@


# 1.171 27-Sep-2016 rzalamena

Delay switch(4) interface start up so it can attach virtual interfaces
like vether(4).

nits from and ok benno@, phessler@


# 1.170 09-Sep-2016 jasper

print a clear error message when not ran as root instead of just falling
through and try whatever it can do with the invoking user's perms

feedback/ok aja@ rpe@


Revision tags: OPENBSD_6_0_BASE
# 1.169 19-Jul-2016 mpi

Do not consider tap(4) a special interface and start if before other
pseudo-interfaces.

This unbreak vlan(4) on top of tap(4) since the refactoring to turn it
MP-safe.

ok claudio@, deraadt@


# 1.168 27-Mar-2016 sthen

Don't delete the 224/4 route in netstart, unless it's being done to ensure that
a -reject route can be added. Restores the ability to set an interface route
before daemons are started, lost during the previous simplification.
ok millert mpi


Revision tags: OPENBSD_5_9_BASE
# 1.167 29-Dec-2015 rpe

Remove backslash, not necessary after '&&'

OK halex@


# 1.166 29-Dec-2015 rpe

Replace last remaining `` with $()

OK halex@


# 1.165 18-Dec-2015 ajacoutot

Drop the now useless multicast setup comment.

prodded by tim@, ok mpi@


# 1.164 17-Dec-2015 ajacoutot

Simplify multicast option handling (10 less lines) by matching /etc/rc behavior
towards other YES|NO options and drop the error warning.


with and ok tim@, ok rpe@ on an earlier diff


# 1.163 05-Dec-2015 mpi

It does not make sense to insert a specific route for 224/4 when the
default one is good enough.

So merge rc.conf(8)'s 'multicast_router' and 'multicast_host' into a
single 'multicast'. If set to YES the reject route for 224/4 is not
inserted by netstart(8).

Manual bits from jmc@

ok henning@, ajacoutot@


# 1.162 12-Nov-2015 rpe

Changes to ifautostart():
- Rename function to ifv6autoconf() to make IPv6 relation clearer
- Localize and rename variables

OK krw@


# 1.161 12-Nov-2015 rpe

Changes to ifmstart():
- Change comments to make it clearer that ifmstart() takes two lists
of interface driver names (of which the second is optional) and not
the actual interface instances.
- Use localized variables and use slightly more verbose names.
- Use continue 2 to skip to the next hostname.if file.
- Use shell pattern @() instead of testing _sif individually.

OK krw@


# 1.160 12-Nov-2015 rpe

Changes to stripcom():
- Align comments with /etc/rc version
- Use localized variables
- Use safer "print -r --" instead of plain echo

Changes to ifstart():
- Tweak comment
- Add usage

OK krw@


# 1.159 01-Nov-2015 rpe

Start the rework of the /etc/netstart shell script.

General changes:
- apply a similar 'style' as used in the installer scripts
- improve comments to be more to the point, remove where code is obvious
- document usage of functions if they have arguments
- rename variables where it improves readability
- replace really old-school shell code with more contemporary idioms

Other changes:
- No need to care about "autoboot" because netstart doesn't inherit the
positional parameters from /etc/rc anymore. /etc/rc executes netstart
instead of sourcing it since r1.439.
- Use simpler for-loop to process list of interfaces with ifstart.

OK halex@


# 1.158 26-Oct-2015 rpe

The hostname variable is not used since r1.99. Remove it and use
stripcom() output directly with the hostname command.

OK deraadt@ krw@


# 1.157 23-Oct-2015 claudio

netstart bits for tap(4)


# 1.156 27-Sep-2015 sthen

Don't print output when setting autoconf on interfaces. Suggested by deraadt,
ok florian@ rpe@


# 1.155 13-Sep-2015 sthen

only print the "IPv6 autoconf" line if there are interfaces to configure
feedback/ok rpe


# 1.154 11-Sep-2015 sthen

Set "inet6 autoconf" individually on interfaces that have rtsol set in
hostname.if, previously netstart tried to configure them all at once
("ifconfig if0 if1 if2 inet6 autoconf"). From Delan Azabani, ok phessler@


Revision tags: OPENBSD_5_8_BASE
# 1.153 20-Jul-2015 rpe

Disable Strict Bourne shell mode for /etc/rc and /etc/netstart to be
able to use ksh syntax within these scripts. This way init doesn't
need to be changed, which starts /etc/rc using /bin/sh and people
can still use "sh /etc/netstart ifname".

Idea from and OK halex@
OK deraadt@ krw@ guenther@


# 1.152 19-Jul-2015 florian

Bring up pflow last as it might send with a source address that is on
any of the other interfaces.
OK deraadt, phessler, benno


# 1.151 19-Jul-2015 rpe

Always source rc.subr to be able to use the rc.conf parsing routine
to get the network related vars from rc.conf. This is even necessary
if netstart is run from within /etc/rc. Remove test of $INRC which
unintentionally evaluated always to true.

problem with previous change found by nigel@
OK sthen@ aja@ halex@


# 1.150 19-Jul-2015 ajacoutot

Revert 1.148 for now until I can talk to rpe@
It introduced a regression reported by nigel@


# 1.149 19-Jul-2015 rpe

Replace test command with [].

OK halex@ krw@


# 1.148 19-Jul-2015 rpe

Ensure, that we source rc.subr and parse rc.conf ONLY if we are not
inside /etc/rc.

With help from and OK halex@, ajacoutot@


# 1.147 18-Jul-2015 rpe

- remove trailing blanks introduced in previous commit
- no space in redirections like </foo or >$bar
- few other minor whitespaces

OK krw@


# 1.146 18-Jul-2015 rpe

Improve comments
- Add comments for functions
- Start comments with capital letters
- End comments with a full stop
- Allow comments to extend up to column 80

OK krw@


# 1.145 06-Jun-2015 florian

Allow rtsol keyword in hostname.if(5) with net.inet6.ip6.forwarding=1.
"inet6 autoconf" was working before and rtsol should behave the same.
OK phessler


Revision tags: OPENBSD_5_7_BASE
# 1.144 03-Dec-2014 florian

The kernel handles rtsol(8) functionality since some time now.
Treat rtsol in hostname.if as a keyword like dhcp and call ifconfig
inet6 autoconf.
"reads good" todd@
OK krw@ (who is *not* an IPv6 person), but I recruited him in his
capacity as an installer person.


# 1.143 28-Sep-2014 claudio

Revert 1.142. Without the down netstart will just print the ifconfig
output because it may end up just calling 'ifconfig $if'. This needs
to be done better and properly tested.


# 1.142 26-Sep-2014 halex

remove explicit 'down' of an interface before starting a dhcp request, thereby
avoiding annoying delays for some switch configurations

ok claudio@ deraadt@

i would add ok phessler@, but it was not valid without an ok krw@


Revision tags: OPENBSD_5_6_BASE
# 1.141 12-Jul-2014 stsp

Fix netstart after autoconf6 change so 'rtsol' lines in hostname.if work again.
found by pelikan@; ok pelikan@ henning@


# 1.140 12-Jul-2014 robert

Make rc.conf a parsed configuration file and stop sourcing it as a shell
script.
From now on rc.conf has a fixed syntax (key=val) and it is not allowed
to add anything to it besides the supported syntax, it all going to be
ignored.

discussed with and help from deraadt@ and halex@


Revision tags: OPENBSD_5_5_BASE
# 1.139 22-Aug-2013 mpi

Like for dhclient, do no create a route to alias addresses via 127.0.0.1.
Our stack is able to tell if the address is local or not.

ok todd@, krw@


Revision tags: OPENBSD_5_4_BASE
# 1.138 20-Mar-2013 todd

fix lies in netstart; replacement wording from halex@
pointed out by Ryan Kavannagh rak at debian dot org


Revision tags: OPENBSD_5_3_BASE
# 1.137 05-Dec-2012 rpe

remove "Invalid interface name" message
requested by krw@

ok halex@


# 1.136 02-Dec-2012 rpe

use the more compact version of the check for ifconfig'able interfaces
from install.sub

with feedback from and ok halex


# 1.135 02-Dec-2012 rpe

- remove isalphanumeric() and replace it with a shell pattern, that
tries a bit harder to identify invalid interface names and in
this case emit an error message.
- use [[ $1 == autoboot ]] to avoid a shell error message due to
possible spaces in first argument
- no change in functionality

discussed with krw and halex
ok ("I like this") krw


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.134 07-Oct-2011 deraadt

The new ypbind changes requires that the domainname be set before
rc.conf is run. There's no real downside.
ok aja


Revision tags: OPENBSD_5_0_BASE
# 1.133 07-Jul-2011 guenther

Eliminate some $? tests by rolling the command into the condition

ok halex@


# 1.132 26-May-2011 mpf

Add svlan(4) startup bits.
From markus@. OK naddy, claudio, reyk.


Revision tags: OPENBSD_4_9_BASE
# 1.131 09-Feb-2011 sobrado

fix an unbalanced parenthesis in a comment; while here, split the comment
in a better place to make it more readable.

ok jmc@ and miod@


Revision tags: OPENBSD_4_8_BASE
# 1.130 16-Jun-2010 todd

permit e.g. -inet6 syntax by slurping all lines not just some
noticed by rhsv6 at hushmail dot com, ok sthen@


Revision tags: OPENBSD_4_7_BASE
# 1.129 12-Jan-2010 henning

when setting up lo0 use 127.0.0.1/8 instead of 127.0.0.1 for clarity and
correctness. it's not 1992 any more, kids. ok mcbride dlg krw


# 1.128 10-Dec-2009 todd

o stop reordering ifconfig arguments (e.g. after 'up ..')
o only stop processing if inet or inet6 lines are malformed
o everything not a specially handled bit is passed to ifconfig unmangled
noticed by several after the move from bridgename.bridge0 -> hostname.bridge0
prodded by deraadt@, tested by and feedback from several
man page bits 'look fine' jmc@


# 1.127 22-Nov-2009 deraadt

Stop supporting bridgename.bridge* files, and move to hostname.bridge*
files. To cope with this change, read about the mv command.
ok claudio todd


# 1.126 17-Sep-2009 simon

change variable i to $i in an expression of ifstart() for consistency
with the rest of the file. no functional change.

feedback from sthen@, ok krw@


# 1.125 10-Jul-2009 jdixon

Delay creation of tun(4) interfaces until the underlying interface and
routes are available. This fixes usage for some OpenVPN users that start
it from hostname.tun*.

Tested by Johan Huldtgren. ok sthen@, johan@.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.124 25-Nov-2008 markus

delay /etc/netstart until IPv6-DAD (dup-address-detection) is completed.
ok fries, hshoexer, claudio


# 1.123 14-Aug-2008 sthen

Tools from /usr may not be used in netstart since it may be NFS-mounted
and not available at that time. Rewrite the hostname.if permission check
to use only /bin/ls and the shell. Requested by deraadt.

ok todd, "Twisted." deraadt


Revision tags: OPENBSD_4_4_BASE
# 1.122 23-Jul-2008 sthen

Prevent warning about insecure hostnames where no /etc/hostname.*
exists. From wcmaier@.

Check target of symbolic links to avoid noise at boot and in
seucrity output where you have several interfaces symlinked to one
config file.

"If you think this is the right thing to do" deraadt@


# 1.121 09-Jun-2008 todd

warn once not 3 times in case of a non existent file, discussed with deraadt
originally pointed out by Johan Torin


# 1.120 09-Jun-2008 deraadt

Ensure that hostname.* files are also re-chowned to root.wheel at each
boot as discussed with claudio while eating tasty donairs. ok todd


# 1.119 17-Apr-2008 deraadt

before using them, force hostname.* files to be unreadable by world
first version from todd, ok millert


Revision tags: OPENBSD_4_3_BASE
# 1.118 17-Jan-2008 brad

Execute rtsol after turning up trunk(4) and vlan(4) interfaces so they're
taken into consideration for rtsol.

ok reyk@ dlg@


# 1.117 09-Jan-2008 mpf

Do not bring up pfsync(4) before the working ruleset
has been loaded. Otherwise, states that are received during the
initial bulk update mismatch the correct pf-checksum and
do not attach to the rules.
Problem identified by david@. Fix done in collaboration.
OK henning@


Revision tags: OPENBSD_4_2_BASE
# 1.116 02-Aug-2007 david

move the delay for IPv6 DAD to after all interfaces have started
fixes problems with daemons being unable to bind to all addreses at boot
ok itojun@ hshoexer@


Revision tags: OPENBSD_4_1_BASE
# 1.115 15-Nov-2006 itojun

reject multicast packet without scope identifier specified.


Revision tags: OPENBSD_4_0_BASE
# 1.114 29-Jun-2006 todd

do not add an extra space; nwid and description come out wrong
fix as proposed by maja@, thanks!


Revision tags: OPENBSD_3_9_BASE
# 1.113 28-Dec-2005 david

nuke extra whitespace


# 1.112 06-Dec-2005 reyk

multicast_host=YES only works if a valid default gateway is available.
validate this condition and reject multicast traffic on failure.

ok todd@ naddy@


# 1.111 02-Nov-2005 todd

fix inspired by pr#4590
ok krw@


# 1.110 25-Oct-2005 todd

better logic from krw@:
- do not process mygate for v4 if dhcp
- do not process mygate for v6 if rtsol
this also makes the mygate processing logic more readable
ok krw@


# 1.109 14-Oct-2005 todd

add v6 support for /etc/mygate
ok deraadt@ mickey@ krw@
same functionality tested/ok'ed by by mickey, brad, matthieu, and me
with this one may now put a v6 IP in /etc/mygate on a separate line from
the v4 default gateway and netstart will do the right thing


# 1.108 12-Oct-2005 todd

shrink stripcom(), sync with install.sub
ok krw@


# 1.107 04-Oct-2005 todd

trunk must be started after physical ethernet devices, but before vlan.
populate ifmstart lines accordingly.
prodded/tested by brad@
ok reyk@


# 1.106 28-Sep-2005 todd

use eval consistently, fixes description quotes on rtsol and dhcp
fix inspired by and closes pr 4495
ok krw@


Revision tags: OPENBSD_3_8_BASE
# 1.105 22-May-2005 todd

Introduce 'ifmstart' to deal with starting multiple interfaces minus a list
of interfaces.

This reduces the netstart script by 174 chars, 13 words, and 19 lines, but
more importantly, makes it more simple and less cluttered should more special
case/orderings be needed.

ok brad@ and pr 4197 submitter, inspired by and closes pr 4197


# 1.104 04-Apr-2005 djm

unbreak; ok pval@


# 1.103 03-Apr-2005 deraadt

if dhcp is used to get an address on any interface, ignore /etc/mygate
ok krw
(this lets us do something rather cool with the zaurus in particular)


Revision tags: OPENBSD_3_7_BASE
# 1.102 04-Jan-2005 mcbride

Bring up the carp(4) interface before default route.

ok pascoe@ mpf@


# 1.101 30-Dec-2004 millert

Add a copy of stripcom so /etc/netstart can be run standalone again.
OK deraadt@


# 1.100 19-Dec-2004 millert

Allow comments in /etc/{myname,mygate,defaultdomain}; OK deraadt@


# 1.99 04-Dec-2004 itojun

remove "route $hostname 127.0.0.1" line. deraadt ok
*** please update /etc/netstart and test if it works ok for you ***


# 1.98 20-Oct-2004 deraadt

make all route commands use -qn; ok mcbride henning


Revision tags: OPENBSD_3_6_BASE
# 1.97 29-May-2004 deraadt

one last route command lacking -qn


Revision tags: OPENBSD_3_5_BASE
# 1.96 22-Mar-2004 mcbride

Make sure pfsync is brought up before carp.

ok deraadt@


# 1.95 13-Mar-2004 mcbride

Delay pfsync(4) configuration, as the syncif has to be configured in
advance. From Thorsten Lockert.


# 1.94 14-Jan-2004 deraadt

ok, it took quite a bit of prodding but itojun finally explained why the
extra sleep 1 is in here, and we came to the conclusion it is safe to
delete it. whee.


# 1.93 13-Jan-2004 deraadt

repair v6 lo0 documentation


# 1.92 11-Jan-2004 deraadt

add loopback routes late


# 1.91 09-Jan-2004 deraadt

create all routes with -q; markus ok


# 1.90 04-Dec-2003 millert

Need to do "ifconfig create" for bridge interfaces too.


# 1.89 03-Dec-2003 markus

add support for ifconfig clone; from netbsd; ok deraadt, henning


# 1.88 20-Oct-2003 david

delay carp initialization until after physical interfaces are configured
ok mcbride@ henning@ deraadt@ todd@


Revision tags: OPENBSD_3_4_BASE
# 1.87 27-Aug-2003 henning

only try to set hostname to what /etc/myname says if that file actually exists,
otherwise preserve `hostname`
netbooted machines can live perfectly fine without it; they get their hostname
earlier.

ok krw@ cedric@


Revision tags: OPENBSD_3_3_BASE
# 1.86 16-Feb-2003 krw

Fix up some DNS verbiage to make it consistant.

Fix up default route selection by

a) Forcing user to explicitly chose 'dhcp' as a mechanism for
specifying a default route, rather than guessing based on one or more
interfaces being configured by dhcp.

b) If the user specified default route does not work, re-present the
existing default route rather than losing it.

c) Move default route selection to after nameserver activation so the
user can specify a hostname as the default route.

Change /etc/netstart so that /etc/mygate wins if a default route was
already specified (i.e. by dhcp).

ok deraadt@.


Revision tags: OPENBSD_3_2_BASE
# 1.85 16-May-2002 todd

ignore non-existent cases where '$if' evaluates to '*'.
From Andr� Lucas <andre@ae-35.com>, fixes pr # 2658.
'Looks good' from miod@, millert@, and krw@.


Revision tags: OPENBSD_3_1_BASE
# 1.84 23-Feb-2002 deraadt

re-add support for $if expansion; hamajima@nagoya.ydc.co.jp


# 1.83 21-Feb-2002 miod

Change the network components initialization order.
Change from:
o all interfaces
o all bridges
o routes
to:
o physical interfaces
o routes
o gif and gre interfaces
o bridges

Fixeski PR #2400.
Manual page updates coming soon.
Ok angelos@ chris@ deraadt@


Revision tags: OPENBSD_3_0_BASE
# 1.82 31-Jul-2001 hugh

a space before a redirect


# 1.81 06-Jul-2001 angelos

Also, source /etc/rc.conf so we can pull in the
multicast_host/multicast_router settings; this is useful if one
flushes the routing table and re-initializes.

We really need a netconfig tool of sorts.


# 1.80 06-Jul-2001 angelos

Use "route -n show -inet" to determine the default multicast iface.


# 1.79 03-Jul-2001 deraadt

pull in rc.conf early so that pf(1) startup is right; tested by jasoni, comments from millert


# 1.78 30-May-2001 deraadt

Remove ipf. Darren Reed has interpreted his (old, new, whichever)
licence in a way that makes ipf not free according to the rules we
established over 5 years ago, at www.openbsd.org/goals.html (and those
same basic rules govern the other *BSD projects too). Specifically,
Darren says that modified versions are not permitted. But software
which OpenBSD uses and redistributes must be free to all (be they
people or companies), for any purpose they wish to use it, including
modification, use, peeing on, or even integration into baby mulching
machines or atomic bombs to be dropped on Australia. Furthermore, we
know of a number of companies using ipf with modification like us, who
are now in the same situation, and we hope that some of them will work
with us to fill this gap that now exists in OpenBSD (temporarily, we
hope).


Revision tags: OPENBSD_2_9_BASE
# 1.77 13-Mar-2001 deraadt

spelling; maurice@maurice.wan.nl


# 1.76 06-Feb-2001 todd

ignore blank lines in addition to comments
fixes pr#1660 from wilfried@telia.com .. Thanks!


# 1.75 10-Jan-2001 jason

support !command in bridgename.if files, too


# 1.74 27-Nov-2000 millert

Use -n to test if a variable is non-zero. Otherwise, if the variable's
contents start with a '-' test becomes unhappy (since it interprets it
as another option).


# 1.73 08-Nov-2000 todd

This fixes pr 1481, we now handle args > 6 in /etc/hostname.if in the
cases where we did not previously handle them.
Thanks to Scott Atwood <atwood@cs.stanford.edu> for reminding us of this.


Revision tags: OPENBSD_2_8_BASE
# 1.72 02-Sep-2000 todd

subtle bug .. global variables in a while loop need reset 'just incase'
With:
hostname.fxp0 having a last line of:
inet6 alias 3ffe:...
and hostname.gif0 having a first two lines of:
giftunnel 1.2.3.4
dest 1.2.4.3
We end up with the command:
ifconfig gif0 giftunnel alias 1.2.3.4 1.2.4.3
.. which is clearly wrong and fixed by this change


# 1.71 18-Jun-2000 todd

rc.conf now parses ${local_rcconf} internally; closes pr 1259


Revision tags: OPENBSD_2_7_BASE
# 1.70 08-May-2000 todd

fix dhcp 'NONE' ness from install to allow media parsing to work
.. ok deraadt@, millert@


# 1.69 21-Apr-2000 deraadt

rc.conf.local support, inspired by chuck yerkes


# 1.68 04-Apr-2000 millert

Remove the -E flag from ipf as it is implicitly enabled and using
the -E flag here causes the kernel to printf 'IP Filter: already
initialized'.


# 1.67 18-Mar-2000 deraadt

silence all extra route addition printouts


# 1.66 17-Mar-2000 itojun

correct reject route installations for IPv6. improve comments.


# 1.65 12-Mar-2000 itojun

disallow packets to malicious 6to4 prefix, based on
http://playground.iijlab.net/i-d/draft-itojun-ipv6-transition-abuse-00.txt


# 1.64 10-Mar-2000 todd

fix non behavior
with this `!' lines in /etc/hostname.* run even without certain lines
(like a comment) preceeding it.


# 1.63 10-Jan-2000 todd

allow arbitrary commands in /etc/hostname.* files if the line starts with '!'


# 1.62 02-Jan-2000 deraadt

rtsol case can configure the interface up, since it would be nice to finish
DAD before the actual rtsol(8) run happens later. and since it will rtsol,
it is going to be up in any case.


# 1.61 02-Jan-2000 itojun

one more indentation fix.


# 1.60 02-Jan-2000 itojun

indentation fix (todd's part)


# 1.59 02-Jan-2000 todd

fix rtsold case, reset cmd for each iteration!


# 1.58 02-Jan-2000 itojun

allow options after "rtsol".
XXX both "dhcp" and "rtsol" has keyword *down* at the end. is it okay?


# 1.57 02-Jan-2000 itojun

echo "IPv6 autoconf: interfaces" before invoking rtsol.
sleep for net.inet6.ip6.dad_count seconds to ensure that IPv6 DAD is completed.
TODO: rtsold (rc.conf line), manpage


# 1.56 02-Jan-2000 itojun

ipv6 autoconf on hosts (non-routers).

to do this,
1. in sysctl.conf, add these lines:
net.inet6.ip6.forwarding=0
net.inet6.ip6.accept_rtadv=1
2. in hostname.foo, add
rtsol

specifying two or more interfaces with "rtsol" may result in strange
behavior - ipv6 spec does not permit multi-interface node to be autoconfig'ed.


# 1.55 02-Jan-2000 todd

add to hostname.* parsing:
- multiple entries support (read: aliases)
- inet6 support
- support for comments (#)
(look for hostname.if(5) commit for syntax details)


# 1.54 31-Dec-1999 itojun

install IPv6 reject routes only if kernel is capable of IPv6.


# 1.53 09-Dec-1999 itojun

avoid transmitting invalid IPv6 packets out to the wire.


# 1.52 09-Dec-1999 itojun

do not perform IPv6 initialization for loopback interface.
MUST make lo0 up before any IPv6 operations.
it will be considered a pilot error if you don't.
(I prefer to have lo0 initialized automatically)


Revision tags: OPENBSD_2_6_BASE
# 1.51 01-Sep-1999 deraadt

support # characters in bridgename.* files; millert


# 1.50 01-Sep-1999 deraadt

cleanup parsing of hostname.* files, and seperate bridge control into
bridgename.* files; all documented in new hostname.if(5) and
bridgename.if(5) man pages


# 1.49 09-Aug-1999 angelos

Only parse/setup the hostname.foo file if interface foo exists (this
is useful for laptops with different ethernet cards etc.)


Revision tags: OPENBSD_2_5_BASE
# 1.48 29-Mar-1999 niklas

New multicast route setup style


# 1.47 26-Mar-1999 niklas

Add bridge interface handling


# 1.46 01-Mar-1999 millert

Add support in /etc/hostname.xxx for files of the format:
up [options]
Any of the following may or may not be set:
$name $mask $bcaddr $extras


# 1.45 28-Oct-1998 millert

Kill the awful hack used to match and split /etc/hostname.* We now use
a function, isalphanumeric, to determine whether an interface name is
likely to be valid. This means that things like /etc/hostname.le0.bak,
/etc/hostname.le0#, /etc/hostname.le0~, etc. will be ignored as they
should. There is no longer an implicate assumption that /etc/hostname.*
only contains a single '.'.


Revision tags: OPENBSD_2_4_BASE
# 1.44 06-Oct-1998 deraadt

move ipnat to end of netstart, to support dhcp+ipnat


# 1.43 18-Sep-1998 deraadt

apply media directives on dhcp interfaces


# 1.42 10-Sep-1998 marc

better way of handling dhcp client; Jason Ish <jbi130@mail.usask.ca>


# 1.41 08-Sep-1998 marc

dhcp client stuff. "Angelos D. Keromytis" <angelos@dsl.cis.upenn.edu>


# 1.40 24-Aug-1998 downsj

You can't use -interface default when there's no default gateway
set (yet). Use -interface $hostname if mygate doesn't exist so that
this actually works on routers.


# 1.39 04-Jul-1998 deraadt

put 224 route on default, to avoid a hostname lookup


# 1.38 22-May-1998 deraadt

use route -n, what the heck


Revision tags: OPENBSD_2_3_BASE
# 1.37 28-Mar-1998 deraadt

s/^nat/ipnat/


# 1.36 23-Feb-1998 niklas

remove trailing blank line


# 1.35 07-Feb-1998 deraadt

ipforward is in sysctl.conf now


# 1.34 21-Dec-1997 deraadt

ugh


# 1.33 20-Dec-1997 deraadt

ipforwarding option in rc.conf


# 1.32 29-Nov-1997 kstailey

NAT requires IPF


# 1.31 04-Nov-1997 deraadt

kill spaces at ends of lines; m4


Revision tags: OPENBSD_2_2_BASE
# 1.30 14-Oct-1997 deraadt

set hostname/domainname before running rc.conf; m4@umn.edu


# 1.29 04-Sep-1997 deraadt

fork netstart; new child is rc.conf


# 1.28 25-Aug-1997 millert

Explicately pass -host flag to route(8) to avoid confusion with networks.


# 1.27 19-Aug-1997 niklas

Add hook for rpc.lockd, make nfsd flags settable in netstart


# 1.26 31-Jul-1997 downsj

Make quotas optional; wedged into netstart for the time being.
/etc/rc.conf, anyone?


# 1.25 30-Jul-1997 deraadt

do not run routed by default


# 1.24 28-Jul-1997 kstailey

Move configuration of loopback interface to before all other interfaces.
Allows the use of local caching-only nameserver with no "nameserver"
entry in /etc/resolv.conf to configure a route between the hostname
and loopback.


# 1.23 25-Jul-1997 provos

earlier start of keymanagement


# 1.22 24-Jul-1997 deraadt

make amd use /tmp_mnt by default


# 1.21 22-Jul-1997 provos

start the photuris daemon per default. hilfe.


# 1.20 17-Jun-1997 niklas

Put in hooks to start ypserv with flags


# 1.19 17-Jun-1997 niklas

Put in hooks to start rpc.yppasswdd with flags


Revision tags: OPENBSD_2_1_BASE
# 1.18 15-Apr-1997 deraadt

kill route flush until .. hmm kernel routing socket bug or something


# 1.17 09-Apr-1997 kstailey

add NAT startup


# 1.16 07-Apr-1997 rees

flush all old routes before adding new interfaces or routes.
ref: netbsd pr3228/misc, Matthias Scheler


# 1.15 03-Mar-1997 downsj

fix typo


# 1.14 11-Feb-1997 deraadt

add default route before fiddling with loopback route to avoid DNS problems; m4@umn.edu, #97


# 1.13 03-Feb-1997 deraadt

do ifaliases after /usr/bin exists in nfs diskless env; pr#77, matthieu@laas.fr


# 1.12 02-Nov-1996 deraadt

timed off by default


Revision tags: OPENBSD_2_0_BASE
# 1.11 23-Sep-1996 deraadt

rfc1323 variable


# 1.10 04-Sep-1996 deraadt

control portmap, inetd, and lpd from netstart; idea from tqbf@enteract.com


# 1.9 27-Aug-1996 deraadt

224.0.0.0 not 0.0.0.224; from peter@demon.net


# 1.8 18-Jun-1996 deraadt

move std stuff from rc.local to rc


# 1.7 16-Jun-1996 deraadt

install sample commented /etc/ifaliases file; which can now contain #
comments and blank lines. new format is "interface address netmask"
(yes, i changed the order of the entries). inspired by netbsd pr#2474;
gillhaa@ghost.whirlpool.com


# 1.6 02-Jun-1996 tholo

Install a multicast route by default


# 1.5 26-May-1996 deraadt

sync & label


# 1.4 09-Jan-1996 dm

added IP filter to netstat/rc and put examples in /usr/share/ipf


# 1.3 30-Dec-1995 deraadt

from netbsd: start mrouted like routed


# 1.2 18-Dec-1995 deraadt

/etc/ifaliases support by randy@zyzzyva.com


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.201 25-Oct-2019 dlg

handle aggr(4) in the same way as trunk(4)

from brad@
ok bluhm@ claudio@ deraadt@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.200 29-Aug-2018 krw

Historically /etc/netstart (and the equivalent code in the install
script) did 'ifconfig <if> down' before starting dhclient(8). This was
a way of ensuring old running copies of dhclient were killed before a
new one started. Current dhclient does not need this assist, so change
"ifconfig <if> down" to "ifconfig <if> up" pending further script
optimizations.

Similar to a 2014 attempt by halex@. Prompted by a misc@ report
from Kristjan Komlosi reporting hanging diskless setups.

ok halex@ kn@


# 1.199 08-Jul-2018 tb

netstart is used during system start, but also interactively.
Show proper error message if a regular user executes netstart.
Only do the privilege check if the id binary is available,
which might not be the case during diskless system startup.

ok deraadt, jasper, jca, krw, rpe (who wrote the same diff), sthen


# 1.198 28-Apr-2018 rpe

Add a proper usage() function.

Suggested by and OK jmc.
OK tb


Revision tags: OPENBSD_6_3_BASE
# 1.197 04-Mar-2018 jmc

when -n is used, no need to spit out "Missing parameters." before
displaying usage();

ok tb


# 1.196 03-Mar-2018 landry

Lowercase 'usage' and group -n with interface in it.
From jmc@, ok tb@


# 1.195 21-Feb-2018 rpe

Tweak comments.

OK tb


# 1.194 19-Feb-2018 rpe

Write warning/error messages to stderr and end them with a fullstop.

OK tb


# 1.193 19-Feb-2018 rpe

- use specific patterns when looping over /etc/hostname.if files
to skip backup or temp files.
- test if the patterns matched actual files
- warn if ifcreate() fails on an interface and continue with the
subsequent interfaces in the list instead of return'ing

OK dlg sthen tb


# 1.192 17-Feb-2018 rpe

- Add descriptions for the new functions ifcreate() and vifscreate()
- In ifcreate() use the exit code of the {} block directly
- In vifscreate(), use the ifconfig -C output directly in the for _vif loop
- Remove superfluous and somewhat confusing comment

OK dlg kn sthen


# 1.191 14-Feb-2018 dlg

create virtual interfaces before starting all interface config.

this resolves an ordering problem when adding pseudo interfaces to bridges

tweaks from kn@
ok mpi@ sthen@


# 1.190 10-Feb-2018 claudio

Remove some special IPv4 in IPv6 mapped prefixes that are already rejected
by the ::0.0.0.0/96 reject route added to deny all IPv4 mapped addresses.
Makes the inet6 routing table almost fit in one screen.
OK benno@


# 1.189 10-Feb-2018 florian

Load RFC 7217 key material and generate if it does not already exist.

Add soii.key to changelist (pointed out by semarie) and mtree/special
(suggest by Craig Skinner).

OK naddy, sthen, rpe, tb


# 1.188 06-Feb-2018 tb

If -n is given, the netstart script should not (try to) set the default
route(s). Simply print the command(s) to be issued instead.

tweak & ok rpe


# 1.187 12-Nov-2017 tb

Remove HN_DIR variable and expand it in the only place it was used. It
currently serves no purpose.

ok rpe, agreement from deraadt and halex


Revision tags: OPENBSD_6_2_BASE
# 1.186 25-Jul-2017 rpe

Finally remove backwards compat code to support the 'rtsol' keyword
in hostname.if(5)

OK mpi@ deraadt@ florian@
OK jmc@ from doc perspective


# 1.185 21-Jul-2017 rpe

Align ifstart() in netstart and install.sub.

- in netstart, rename _file to _hn referencing hostname.if files
- in install.sub switch ifstart() to be used with _if instead of
_hn as parameter

ok krw@ tb@


# 1.184 28-May-2017 awolk

etc/netstart: use colon separator instead of dot with chown

OK jung@, deraadt@, jmc@


# 1.183 07-May-2017 rpe

Change test from [] to [[]] and simplify pattern.

OK tb@, krw@ (for [[]])
Feedback and OK halex@


# 1.182 07-May-2017 rpe

Replace hardcoded script name with ${0##*/}

OK tb@ halex@


# 1.181 01-May-2017 rpe

Revert r1.170 and remove the id==0 check.
The id binary is not available in nfs diskless setups at this point.

reported by Andreas Kusalananda, thanks.
discussed with deraadt@


# 1.180 01-May-2017 rpe

Remove last remnants of rtsol. IPv6 autoconfiguration of interfaces is now
done in ifstart(). Remove ipv6autoconf() and replace rtsolif with a boolean
variable V6_AUTOCONF. Replace dhcpif with a boolean variable V4_DHCPCONF.
Both are later used in defaultroute() to decide whether or not to configre
defaultroutes from /etc/mygate.

OK krw@


# 1.179 30-Apr-2017 mpi

Do not try to delete a default route before adding it.

Now that route are automatically G/C with the address they are attached
to there's no reason to duplicate the kernel's job.

Fix a regression introduced with multipath default routes.

ok deraadt@


# 1.178 25-Apr-2017 rpe

Unbreak netstart for multiple inteface configurations like trunk
or carp. Ensure that the noglob option is disabled at the end of
parse_hn_line() and ifstart().

Reported by Christer Solskogen and Stefan Wollny, thanks!


# 1.177 24-Apr-2017 rpe

Introduce a new function parse_hn_line() that replaces the existing
hostname.if(5) parsing code in ifstart().
Add a -n option to netstart to only print the interface configuration
commands instead of executing them.
Add a HN_DIR variable, that points to the directory of the hostname.if
files (default /etc) that allows for future regression tests.

- add new parse_hn_line() function
- change ifstart()
- rename $if to $_if
- don't ifconfig or ifconfig create if -n option is used
- replace hostname.if(5) parsing code with new parse_hn_line()
- just print configuration commands if -n option is used
- autoconf now happens in ifstart(), remove ifv6autoconf()
- introduce HN_DIR variable for the hostname.if file location
- add handling of the -n option to only print config commands
- ensure -n is only used if interfaces are specified as parameters

Discussed with and positive feedback from many
'commit' deraadt@
OK sthen@


# 1.176 08-Apr-2017 rpe

- localize the if, file and stat variables which also ensures that
variables are not named like commands.
- change test from [] to [[]]

OK tb@ halex@


# 1.175 07-Apr-2017 rpe

Minimize differences in ifstart() function between netstart and
install.sub which makes it easier to spot changes in the future.

- comments and formatting
- quotes on assignments are not needed (netstart)
- remove stray space in test (netstart)
- use $file variable with while-loop (netstart)
- although valid, instead of i use $i in arithmetic test (install.sub)

OK krw@, tb@
Looks good deraadt@


# 1.174 07-Apr-2017 rpe

Align comments of ifstart() function in netstart and install.sub.


# 1.173 07-Apr-2017 rpe

Align comments of stripcom() function in netstart and install.sub.


Revision tags: OPENBSD_6_1_BASE
# 1.172 06-Dec-2016 mpi

Do not lose the default route when netstart(8) is run a second time on
the interface pointed to by the default route.

Since the kernel no longer keep routes with dangling address pointer,
netstart(8) has to re-add the default route when the corresponding ifa
has been deleted and re-created.

deraadt@ points out that even if the previous semantic was not necessarily
better, a script like netstart(8) cannot totally fix the default route
problem.

Regression reported by and fix tested by Hrvoje Popovski.

ksh foo checked by halex@


# 1.171 27-Sep-2016 rzalamena

Delay switch(4) interface start up so it can attach virtual interfaces
like vether(4).

nits from and ok benno@, phessler@


# 1.170 09-Sep-2016 jasper

print a clear error message when not ran as root instead of just falling
through and try whatever it can do with the invoking user's perms

feedback/ok aja@ rpe@


Revision tags: OPENBSD_6_0_BASE
# 1.169 19-Jul-2016 mpi

Do not consider tap(4) a special interface and start if before other
pseudo-interfaces.

This unbreak vlan(4) on top of tap(4) since the refactoring to turn it
MP-safe.

ok claudio@, deraadt@


# 1.168 27-Mar-2016 sthen

Don't delete the 224/4 route in netstart, unless it's being done to ensure that
a -reject route can be added. Restores the ability to set an interface route
before daemons are started, lost during the previous simplification.
ok millert mpi


Revision tags: OPENBSD_5_9_BASE
# 1.167 29-Dec-2015 rpe

Remove backslash, not necessary after '&&'

OK halex@


# 1.166 29-Dec-2015 rpe

Replace last remaining `` with $()

OK halex@


# 1.165 18-Dec-2015 ajacoutot

Drop the now useless multicast setup comment.

prodded by tim@, ok mpi@


# 1.164 17-Dec-2015 ajacoutot

Simplify multicast option handling (10 less lines) by matching /etc/rc behavior
towards other YES|NO options and drop the error warning.


with and ok tim@, ok rpe@ on an earlier diff


# 1.163 05-Dec-2015 mpi

It does not make sense to insert a specific route for 224/4 when the
default one is good enough.

So merge rc.conf(8)'s 'multicast_router' and 'multicast_host' into a
single 'multicast'. If set to YES the reject route for 224/4 is not
inserted by netstart(8).

Manual bits from jmc@

ok henning@, ajacoutot@


# 1.162 12-Nov-2015 rpe

Changes to ifautostart():
- Rename function to ifv6autoconf() to make IPv6 relation clearer
- Localize and rename variables

OK krw@


# 1.161 12-Nov-2015 rpe

Changes to ifmstart():
- Change comments to make it clearer that ifmstart() takes two lists
of interface driver names (of which the second is optional) and not
the actual interface instances.
- Use localized variables and use slightly more verbose names.
- Use continue 2 to skip to the next hostname.if file.
- Use shell pattern @() instead of testing _sif individually.

OK krw@


# 1.160 12-Nov-2015 rpe

Changes to stripcom():
- Align comments with /etc/rc version
- Use localized variables
- Use safer "print -r --" instead of plain echo

Changes to ifstart():
- Tweak comment
- Add usage

OK krw@


# 1.159 01-Nov-2015 rpe

Start the rework of the /etc/netstart shell script.

General changes:
- apply a similar 'style' as used in the installer scripts
- improve comments to be more to the point, remove where code is obvious
- document usage of functions if they have arguments
- rename variables where it improves readability
- replace really old-school shell code with more contemporary idioms

Other changes:
- No need to care about "autoboot" because netstart doesn't inherit the
positional parameters from /etc/rc anymore. /etc/rc executes netstart
instead of sourcing it since r1.439.
- Use simpler for-loop to process list of interfaces with ifstart.

OK halex@


# 1.158 26-Oct-2015 rpe

The hostname variable is not used since r1.99. Remove it and use
stripcom() output directly with the hostname command.

OK deraadt@ krw@


# 1.157 23-Oct-2015 claudio

netstart bits for tap(4)


# 1.156 27-Sep-2015 sthen

Don't print output when setting autoconf on interfaces. Suggested by deraadt,
ok florian@ rpe@


# 1.155 13-Sep-2015 sthen

only print the "IPv6 autoconf" line if there are interfaces to configure
feedback/ok rpe


# 1.154 11-Sep-2015 sthen

Set "inet6 autoconf" individually on interfaces that have rtsol set in
hostname.if, previously netstart tried to configure them all at once
("ifconfig if0 if1 if2 inet6 autoconf"). From Delan Azabani, ok phessler@


Revision tags: OPENBSD_5_8_BASE
# 1.153 20-Jul-2015 rpe

Disable Strict Bourne shell mode for /etc/rc and /etc/netstart to be
able to use ksh syntax within these scripts. This way init doesn't
need to be changed, which starts /etc/rc using /bin/sh and people
can still use "sh /etc/netstart ifname".

Idea from and OK halex@
OK deraadt@ krw@ guenther@


# 1.152 19-Jul-2015 florian

Bring up pflow last as it might send with a source address that is on
any of the other interfaces.
OK deraadt, phessler, benno


# 1.151 19-Jul-2015 rpe

Always source rc.subr to be able to use the rc.conf parsing routine
to get the network related vars from rc.conf. This is even necessary
if netstart is run from within /etc/rc. Remove test of $INRC which
unintentionally evaluated always to true.

problem with previous change found by nigel@
OK sthen@ aja@ halex@


# 1.150 19-Jul-2015 ajacoutot

Revert 1.148 for now until I can talk to rpe@
It introduced a regression reported by nigel@


# 1.149 19-Jul-2015 rpe

Replace test command with [].

OK halex@ krw@


# 1.148 19-Jul-2015 rpe

Ensure, that we source rc.subr and parse rc.conf ONLY if we are not
inside /etc/rc.

With help from and OK halex@, ajacoutot@


# 1.147 18-Jul-2015 rpe

- remove trailing blanks introduced in previous commit
- no space in redirections like </foo or >$bar
- few other minor whitespaces

OK krw@


# 1.146 18-Jul-2015 rpe

Improve comments
- Add comments for functions
- Start comments with capital letters
- End comments with a full stop
- Allow comments to extend up to column 80

OK krw@


# 1.145 06-Jun-2015 florian

Allow rtsol keyword in hostname.if(5) with net.inet6.ip6.forwarding=1.
"inet6 autoconf" was working before and rtsol should behave the same.
OK phessler


Revision tags: OPENBSD_5_7_BASE
# 1.144 03-Dec-2014 florian

The kernel handles rtsol(8) functionality since some time now.
Treat rtsol in hostname.if as a keyword like dhcp and call ifconfig
inet6 autoconf.
"reads good" todd@
OK krw@ (who is *not* an IPv6 person), but I recruited him in his
capacity as an installer person.


# 1.143 28-Sep-2014 claudio

Revert 1.142. Without the down netstart will just print the ifconfig
output because it may end up just calling 'ifconfig $if'. This needs
to be done better and properly tested.


# 1.142 26-Sep-2014 halex

remove explicit 'down' of an interface before starting a dhcp request, thereby
avoiding annoying delays for some switch configurations

ok claudio@ deraadt@

i would add ok phessler@, but it was not valid without an ok krw@


Revision tags: OPENBSD_5_6_BASE
# 1.141 12-Jul-2014 stsp

Fix netstart after autoconf6 change so 'rtsol' lines in hostname.if work again.
found by pelikan@; ok pelikan@ henning@


# 1.140 12-Jul-2014 robert

Make rc.conf a parsed configuration file and stop sourcing it as a shell
script.
From now on rc.conf has a fixed syntax (key=val) and it is not allowed
to add anything to it besides the supported syntax, it all going to be
ignored.

discussed with and help from deraadt@ and halex@


Revision tags: OPENBSD_5_5_BASE
# 1.139 22-Aug-2013 mpi

Like for dhclient, do no create a route to alias addresses via 127.0.0.1.
Our stack is able to tell if the address is local or not.

ok todd@, krw@


Revision tags: OPENBSD_5_4_BASE
# 1.138 20-Mar-2013 todd

fix lies in netstart; replacement wording from halex@
pointed out by Ryan Kavannagh rak at debian dot org


Revision tags: OPENBSD_5_3_BASE
# 1.137 05-Dec-2012 rpe

remove "Invalid interface name" message
requested by krw@

ok halex@


# 1.136 02-Dec-2012 rpe

use the more compact version of the check for ifconfig'able interfaces
from install.sub

with feedback from and ok halex


# 1.135 02-Dec-2012 rpe

- remove isalphanumeric() and replace it with a shell pattern, that
tries a bit harder to identify invalid interface names and in
this case emit an error message.
- use [[ $1 == autoboot ]] to avoid a shell error message due to
possible spaces in first argument
- no change in functionality

discussed with krw and halex
ok ("I like this") krw


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.134 07-Oct-2011 deraadt

The new ypbind changes requires that the domainname be set before
rc.conf is run. There's no real downside.
ok aja


Revision tags: OPENBSD_5_0_BASE
# 1.133 07-Jul-2011 guenther

Eliminate some $? tests by rolling the command into the condition

ok halex@


# 1.132 26-May-2011 mpf

Add svlan(4) startup bits.
From markus@. OK naddy, claudio, reyk.


Revision tags: OPENBSD_4_9_BASE
# 1.131 09-Feb-2011 sobrado

fix an unbalanced parenthesis in a comment; while here, split the comment
in a better place to make it more readable.

ok jmc@ and miod@


Revision tags: OPENBSD_4_8_BASE
# 1.130 16-Jun-2010 todd

permit e.g. -inet6 syntax by slurping all lines not just some
noticed by rhsv6 at hushmail dot com, ok sthen@


Revision tags: OPENBSD_4_7_BASE
# 1.129 12-Jan-2010 henning

when setting up lo0 use 127.0.0.1/8 instead of 127.0.0.1 for clarity and
correctness. it's not 1992 any more, kids. ok mcbride dlg krw


# 1.128 10-Dec-2009 todd

o stop reordering ifconfig arguments (e.g. after 'up ..')
o only stop processing if inet or inet6 lines are malformed
o everything not a specially handled bit is passed to ifconfig unmangled
noticed by several after the move from bridgename.bridge0 -> hostname.bridge0
prodded by deraadt@, tested by and feedback from several
man page bits 'look fine' jmc@


# 1.127 22-Nov-2009 deraadt

Stop supporting bridgename.bridge* files, and move to hostname.bridge*
files. To cope with this change, read about the mv command.
ok claudio todd


# 1.126 17-Sep-2009 simon

change variable i to $i in an expression of ifstart() for consistency
with the rest of the file. no functional change.

feedback from sthen@, ok krw@


# 1.125 10-Jul-2009 jdixon

Delay creation of tun(4) interfaces until the underlying interface and
routes are available. This fixes usage for some OpenVPN users that start
it from hostname.tun*.

Tested by Johan Huldtgren. ok sthen@, johan@.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.124 25-Nov-2008 markus

delay /etc/netstart until IPv6-DAD (dup-address-detection) is completed.
ok fries, hshoexer, claudio


# 1.123 14-Aug-2008 sthen

Tools from /usr may not be used in netstart since it may be NFS-mounted
and not available at that time. Rewrite the hostname.if permission check
to use only /bin/ls and the shell. Requested by deraadt.

ok todd, "Twisted." deraadt


Revision tags: OPENBSD_4_4_BASE
# 1.122 23-Jul-2008 sthen

Prevent warning about insecure hostnames where no /etc/hostname.*
exists. From wcmaier@.

Check target of symbolic links to avoid noise at boot and in
seucrity output where you have several interfaces symlinked to one
config file.

"If you think this is the right thing to do" deraadt@


# 1.121 09-Jun-2008 todd

warn once not 3 times in case of a non existent file, discussed with deraadt
originally pointed out by Johan Torin


# 1.120 09-Jun-2008 deraadt

Ensure that hostname.* files are also re-chowned to root.wheel at each
boot as discussed with claudio while eating tasty donairs. ok todd


# 1.119 17-Apr-2008 deraadt

before using them, force hostname.* files to be unreadable by world
first version from todd, ok millert


Revision tags: OPENBSD_4_3_BASE
# 1.118 17-Jan-2008 brad

Execute rtsol after turning up trunk(4) and vlan(4) interfaces so they're
taken into consideration for rtsol.

ok reyk@ dlg@


# 1.117 09-Jan-2008 mpf

Do not bring up pfsync(4) before the working ruleset
has been loaded. Otherwise, states that are received during the
initial bulk update mismatch the correct pf-checksum and
do not attach to the rules.
Problem identified by david@. Fix done in collaboration.
OK henning@


Revision tags: OPENBSD_4_2_BASE
# 1.116 02-Aug-2007 david

move the delay for IPv6 DAD to after all interfaces have started
fixes problems with daemons being unable to bind to all addreses at boot
ok itojun@ hshoexer@


Revision tags: OPENBSD_4_1_BASE
# 1.115 15-Nov-2006 itojun

reject multicast packet without scope identifier specified.


Revision tags: OPENBSD_4_0_BASE
# 1.114 29-Jun-2006 todd

do not add an extra space; nwid and description come out wrong
fix as proposed by maja@, thanks!


Revision tags: OPENBSD_3_9_BASE
# 1.113 28-Dec-2005 david

nuke extra whitespace


# 1.112 06-Dec-2005 reyk

multicast_host=YES only works if a valid default gateway is available.
validate this condition and reject multicast traffic on failure.

ok todd@ naddy@


# 1.111 02-Nov-2005 todd

fix inspired by pr#4590
ok krw@


# 1.110 25-Oct-2005 todd

better logic from krw@:
- do not process mygate for v4 if dhcp
- do not process mygate for v6 if rtsol
this also makes the mygate processing logic more readable
ok krw@


# 1.109 14-Oct-2005 todd

add v6 support for /etc/mygate
ok deraadt@ mickey@ krw@
same functionality tested/ok'ed by by mickey, brad, matthieu, and me
with this one may now put a v6 IP in /etc/mygate on a separate line from
the v4 default gateway and netstart will do the right thing


# 1.108 12-Oct-2005 todd

shrink stripcom(), sync with install.sub
ok krw@


# 1.107 04-Oct-2005 todd

trunk must be started after physical ethernet devices, but before vlan.
populate ifmstart lines accordingly.
prodded/tested by brad@
ok reyk@


# 1.106 28-Sep-2005 todd

use eval consistently, fixes description quotes on rtsol and dhcp
fix inspired by and closes pr 4495
ok krw@


Revision tags: OPENBSD_3_8_BASE
# 1.105 22-May-2005 todd

Introduce 'ifmstart' to deal with starting multiple interfaces minus a list
of interfaces.

This reduces the netstart script by 174 chars, 13 words, and 19 lines, but
more importantly, makes it more simple and less cluttered should more special
case/orderings be needed.

ok brad@ and pr 4197 submitter, inspired by and closes pr 4197


# 1.104 04-Apr-2005 djm

unbreak; ok pval@


# 1.103 03-Apr-2005 deraadt

if dhcp is used to get an address on any interface, ignore /etc/mygate
ok krw
(this lets us do something rather cool with the zaurus in particular)


Revision tags: OPENBSD_3_7_BASE
# 1.102 04-Jan-2005 mcbride

Bring up the carp(4) interface before default route.

ok pascoe@ mpf@


# 1.101 30-Dec-2004 millert

Add a copy of stripcom so /etc/netstart can be run standalone again.
OK deraadt@


# 1.100 19-Dec-2004 millert

Allow comments in /etc/{myname,mygate,defaultdomain}; OK deraadt@


# 1.99 04-Dec-2004 itojun

remove "route $hostname 127.0.0.1" line. deraadt ok
*** please update /etc/netstart and test if it works ok for you ***


# 1.98 20-Oct-2004 deraadt

make all route commands use -qn; ok mcbride henning


Revision tags: OPENBSD_3_6_BASE
# 1.97 29-May-2004 deraadt

one last route command lacking -qn


Revision tags: OPENBSD_3_5_BASE
# 1.96 22-Mar-2004 mcbride

Make sure pfsync is brought up before carp.

ok deraadt@


# 1.95 13-Mar-2004 mcbride

Delay pfsync(4) configuration, as the syncif has to be configured in
advance. From Thorsten Lockert.


# 1.94 14-Jan-2004 deraadt

ok, it took quite a bit of prodding but itojun finally explained why the
extra sleep 1 is in here, and we came to the conclusion it is safe to
delete it. whee.


# 1.93 13-Jan-2004 deraadt

repair v6 lo0 documentation


# 1.92 11-Jan-2004 deraadt

add loopback routes late


# 1.91 09-Jan-2004 deraadt

create all routes with -q; markus ok


# 1.90 04-Dec-2003 millert

Need to do "ifconfig create" for bridge interfaces too.


# 1.89 03-Dec-2003 markus

add support for ifconfig clone; from netbsd; ok deraadt, henning


# 1.88 20-Oct-2003 david

delay carp initialization until after physical interfaces are configured
ok mcbride@ henning@ deraadt@ todd@


Revision tags: OPENBSD_3_4_BASE
# 1.87 27-Aug-2003 henning

only try to set hostname to what /etc/myname says if that file actually exists,
otherwise preserve `hostname`
netbooted machines can live perfectly fine without it; they get their hostname
earlier.

ok krw@ cedric@


Revision tags: OPENBSD_3_3_BASE
# 1.86 16-Feb-2003 krw

Fix up some DNS verbiage to make it consistant.

Fix up default route selection by

a) Forcing user to explicitly chose 'dhcp' as a mechanism for
specifying a default route, rather than guessing based on one or more
interfaces being configured by dhcp.

b) If the user specified default route does not work, re-present the
existing default route rather than losing it.

c) Move default route selection to after nameserver activation so the
user can specify a hostname as the default route.

Change /etc/netstart so that /etc/mygate wins if a default route was
already specified (i.e. by dhcp).

ok deraadt@.


Revision tags: OPENBSD_3_2_BASE
# 1.85 16-May-2002 todd

ignore non-existent cases where '$if' evaluates to '*'.
From Andr� Lucas <andre@ae-35.com>, fixes pr # 2658.
'Looks good' from miod@, millert@, and krw@.


Revision tags: OPENBSD_3_1_BASE
# 1.84 23-Feb-2002 deraadt

re-add support for $if expansion; hamajima@nagoya.ydc.co.jp


# 1.83 21-Feb-2002 miod

Change the network components initialization order.
Change from:
o all interfaces
o all bridges
o routes
to:
o physical interfaces
o routes
o gif and gre interfaces
o bridges

Fixeski PR #2400.
Manual page updates coming soon.
Ok angelos@ chris@ deraadt@


Revision tags: OPENBSD_3_0_BASE
# 1.82 31-Jul-2001 hugh

a space before a redirect


# 1.81 06-Jul-2001 angelos

Also, source /etc/rc.conf so we can pull in the
multicast_host/multicast_router settings; this is useful if one
flushes the routing table and re-initializes.

We really need a netconfig tool of sorts.


# 1.80 06-Jul-2001 angelos

Use "route -n show -inet" to determine the default multicast iface.


# 1.79 03-Jul-2001 deraadt

pull in rc.conf early so that pf(1) startup is right; tested by jasoni, comments from millert


# 1.78 30-May-2001 deraadt

Remove ipf. Darren Reed has interpreted his (old, new, whichever)
licence in a way that makes ipf not free according to the rules we
established over 5 years ago, at www.openbsd.org/goals.html (and those
same basic rules govern the other *BSD projects too). Specifically,
Darren says that modified versions are not permitted. But software
which OpenBSD uses and redistributes must be free to all (be they
people or companies), for any purpose they wish to use it, including
modification, use, peeing on, or even integration into baby mulching
machines or atomic bombs to be dropped on Australia. Furthermore, we
know of a number of companies using ipf with modification like us, who
are now in the same situation, and we hope that some of them will work
with us to fill this gap that now exists in OpenBSD (temporarily, we
hope).


Revision tags: OPENBSD_2_9_BASE
# 1.77 13-Mar-2001 deraadt

spelling; maurice@maurice.wan.nl


# 1.76 06-Feb-2001 todd

ignore blank lines in addition to comments
fixes pr#1660 from wilfried@telia.com .. Thanks!


# 1.75 10-Jan-2001 jason

support !command in bridgename.if files, too


# 1.74 27-Nov-2000 millert

Use -n to test if a variable is non-zero. Otherwise, if the variable's
contents start with a '-' test becomes unhappy (since it interprets it
as another option).


# 1.73 08-Nov-2000 todd

This fixes pr 1481, we now handle args > 6 in /etc/hostname.if in the
cases where we did not previously handle them.
Thanks to Scott Atwood <atwood@cs.stanford.edu> for reminding us of this.


Revision tags: OPENBSD_2_8_BASE
# 1.72 02-Sep-2000 todd

subtle bug .. global variables in a while loop need reset 'just incase'
With:
hostname.fxp0 having a last line of:
inet6 alias 3ffe:...
and hostname.gif0 having a first two lines of:
giftunnel 1.2.3.4
dest 1.2.4.3
We end up with the command:
ifconfig gif0 giftunnel alias 1.2.3.4 1.2.4.3
.. which is clearly wrong and fixed by this change


# 1.71 18-Jun-2000 todd

rc.conf now parses ${local_rcconf} internally; closes pr 1259


Revision tags: OPENBSD_2_7_BASE
# 1.70 08-May-2000 todd

fix dhcp 'NONE' ness from install to allow media parsing to work
.. ok deraadt@, millert@


# 1.69 21-Apr-2000 deraadt

rc.conf.local support, inspired by chuck yerkes


# 1.68 04-Apr-2000 millert

Remove the -E flag from ipf as it is implicitly enabled and using
the -E flag here causes the kernel to printf 'IP Filter: already
initialized'.


# 1.67 18-Mar-2000 deraadt

silence all extra route addition printouts


# 1.66 17-Mar-2000 itojun

correct reject route installations for IPv6. improve comments.


# 1.65 12-Mar-2000 itojun

disallow packets to malicious 6to4 prefix, based on
http://playground.iijlab.net/i-d/draft-itojun-ipv6-transition-abuse-00.txt


# 1.64 10-Mar-2000 todd

fix non behavior
with this `!' lines in /etc/hostname.* run even without certain lines
(like a comment) preceeding it.


# 1.63 10-Jan-2000 todd

allow arbitrary commands in /etc/hostname.* files if the line starts with '!'


# 1.62 02-Jan-2000 deraadt

rtsol case can configure the interface up, since it would be nice to finish
DAD before the actual rtsol(8) run happens later. and since it will rtsol,
it is going to be up in any case.


# 1.61 02-Jan-2000 itojun

one more indentation fix.


# 1.60 02-Jan-2000 itojun

indentation fix (todd's part)


# 1.59 02-Jan-2000 todd

fix rtsold case, reset cmd for each iteration!


# 1.58 02-Jan-2000 itojun

allow options after "rtsol".
XXX both "dhcp" and "rtsol" has keyword *down* at the end. is it okay?


# 1.57 02-Jan-2000 itojun

echo "IPv6 autoconf: interfaces" before invoking rtsol.
sleep for net.inet6.ip6.dad_count seconds to ensure that IPv6 DAD is completed.
TODO: rtsold (rc.conf line), manpage


# 1.56 02-Jan-2000 itojun

ipv6 autoconf on hosts (non-routers).

to do this,
1. in sysctl.conf, add these lines:
net.inet6.ip6.forwarding=0
net.inet6.ip6.accept_rtadv=1
2. in hostname.foo, add
rtsol

specifying two or more interfaces with "rtsol" may result in strange
behavior - ipv6 spec does not permit multi-interface node to be autoconfig'ed.


# 1.55 02-Jan-2000 todd

add to hostname.* parsing:
- multiple entries support (read: aliases)
- inet6 support
- support for comments (#)
(look for hostname.if(5) commit for syntax details)


# 1.54 31-Dec-1999 itojun

install IPv6 reject routes only if kernel is capable of IPv6.


# 1.53 09-Dec-1999 itojun

avoid transmitting invalid IPv6 packets out to the wire.


# 1.52 09-Dec-1999 itojun

do not perform IPv6 initialization for loopback interface.
MUST make lo0 up before any IPv6 operations.
it will be considered a pilot error if you don't.
(I prefer to have lo0 initialized automatically)


Revision tags: OPENBSD_2_6_BASE
# 1.51 01-Sep-1999 deraadt

support # characters in bridgename.* files; millert


# 1.50 01-Sep-1999 deraadt

cleanup parsing of hostname.* files, and seperate bridge control into
bridgename.* files; all documented in new hostname.if(5) and
bridgename.if(5) man pages


# 1.49 09-Aug-1999 angelos

Only parse/setup the hostname.foo file if interface foo exists (this
is useful for laptops with different ethernet cards etc.)


Revision tags: OPENBSD_2_5_BASE
# 1.48 29-Mar-1999 niklas

New multicast route setup style


# 1.47 26-Mar-1999 niklas

Add bridge interface handling


# 1.46 01-Mar-1999 millert

Add support in /etc/hostname.xxx for files of the format:
up [options]
Any of the following may or may not be set:
$name $mask $bcaddr $extras


# 1.45 28-Oct-1998 millert

Kill the awful hack used to match and split /etc/hostname.* We now use
a function, isalphanumeric, to determine whether an interface name is
likely to be valid. This means that things like /etc/hostname.le0.bak,
/etc/hostname.le0#, /etc/hostname.le0~, etc. will be ignored as they
should. There is no longer an implicate assumption that /etc/hostname.*
only contains a single '.'.


Revision tags: OPENBSD_2_4_BASE
# 1.44 06-Oct-1998 deraadt

move ipnat to end of netstart, to support dhcp+ipnat


# 1.43 18-Sep-1998 deraadt

apply media directives on dhcp interfaces


# 1.42 10-Sep-1998 marc

better way of handling dhcp client; Jason Ish <jbi130@mail.usask.ca>


# 1.41 08-Sep-1998 marc

dhcp client stuff. "Angelos D. Keromytis" <angelos@dsl.cis.upenn.edu>


# 1.40 24-Aug-1998 downsj

You can't use -interface default when there's no default gateway
set (yet). Use -interface $hostname if mygate doesn't exist so that
this actually works on routers.


# 1.39 04-Jul-1998 deraadt

put 224 route on default, to avoid a hostname lookup


# 1.38 22-May-1998 deraadt

use route -n, what the heck


Revision tags: OPENBSD_2_3_BASE
# 1.37 28-Mar-1998 deraadt

s/^nat/ipnat/


# 1.36 23-Feb-1998 niklas

remove trailing blank line


# 1.35 07-Feb-1998 deraadt

ipforward is in sysctl.conf now


# 1.34 21-Dec-1997 deraadt

ugh


# 1.33 20-Dec-1997 deraadt

ipforwarding option in rc.conf


# 1.32 29-Nov-1997 kstailey

NAT requires IPF


# 1.31 04-Nov-1997 deraadt

kill spaces at ends of lines; m4


Revision tags: OPENBSD_2_2_BASE
# 1.30 14-Oct-1997 deraadt

set hostname/domainname before running rc.conf; m4@umn.edu


# 1.29 04-Sep-1997 deraadt

fork netstart; new child is rc.conf


# 1.28 25-Aug-1997 millert

Explicately pass -host flag to route(8) to avoid confusion with networks.


# 1.27 19-Aug-1997 niklas

Add hook for rpc.lockd, make nfsd flags settable in netstart


# 1.26 31-Jul-1997 downsj

Make quotas optional; wedged into netstart for the time being.
/etc/rc.conf, anyone?


# 1.25 30-Jul-1997 deraadt

do not run routed by default


# 1.24 28-Jul-1997 kstailey

Move configuration of loopback interface to before all other interfaces.
Allows the use of local caching-only nameserver with no "nameserver"
entry in /etc/resolv.conf to configure a route between the hostname
and loopback.


# 1.23 25-Jul-1997 provos

earlier start of keymanagement


# 1.22 24-Jul-1997 deraadt

make amd use /tmp_mnt by default


# 1.21 22-Jul-1997 provos

start the photuris daemon per default. hilfe.


# 1.20 17-Jun-1997 niklas

Put in hooks to start ypserv with flags


# 1.19 17-Jun-1997 niklas

Put in hooks to start rpc.yppasswdd with flags


Revision tags: OPENBSD_2_1_BASE
# 1.18 15-Apr-1997 deraadt

kill route flush until .. hmm kernel routing socket bug or something


# 1.17 09-Apr-1997 kstailey

add NAT startup


# 1.16 07-Apr-1997 rees

flush all old routes before adding new interfaces or routes.
ref: netbsd pr3228/misc, Matthias Scheler


# 1.15 03-Mar-1997 downsj

fix typo


# 1.14 11-Feb-1997 deraadt

add default route before fiddling with loopback route to avoid DNS problems; m4@umn.edu, #97


# 1.13 03-Feb-1997 deraadt

do ifaliases after /usr/bin exists in nfs diskless env; pr#77, matthieu@laas.fr


# 1.12 02-Nov-1996 deraadt

timed off by default


Revision tags: OPENBSD_2_0_BASE
# 1.11 23-Sep-1996 deraadt

rfc1323 variable


# 1.10 04-Sep-1996 deraadt

control portmap, inetd, and lpd from netstart; idea from tqbf@enteract.com


# 1.9 27-Aug-1996 deraadt

224.0.0.0 not 0.0.0.224; from peter@demon.net


# 1.8 18-Jun-1996 deraadt

move std stuff from rc.local to rc


# 1.7 16-Jun-1996 deraadt

install sample commented /etc/ifaliases file; which can now contain #
comments and blank lines. new format is "interface address netmask"
(yes, i changed the order of the entries). inspired by netbsd pr#2474;
gillhaa@ghost.whirlpool.com


# 1.6 02-Jun-1996 tholo

Install a multicast route by default


# 1.5 26-May-1996 deraadt

sync & label


# 1.4 09-Jan-1996 dm

added IP filter to netstat/rc and put examples in /usr/share/ipf


# 1.3 30-Dec-1995 deraadt

from netbsd: start mrouted like routed


# 1.2 18-Dec-1995 deraadt

/etc/ifaliases support by randy@zyzzyva.com


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.200 29-Aug-2018 krw

Historically /etc/netstart (and the equivalent code in the install
script) did 'ifconfig <if> down' before starting dhclient(8). This was
a way of ensuring old running copies of dhclient were killed before a
new one started. Current dhclient does not need this assist, so change
"ifconfig <if> down" to "ifconfig <if> up" pending further script
optimizations.

Similar to a 2014 attempt by halex@. Prompted by a misc@ report
from Kristjan Komlosi reporting hanging diskless setups.

ok halex@ kn@


# 1.199 08-Jul-2018 tb

netstart is used during system start, but also interactively.
Show proper error message if a regular user executes netstart.
Only do the privilege check if the id binary is available,
which might not be the case during diskless system startup.

ok deraadt, jasper, jca, krw, rpe (who wrote the same diff), sthen


# 1.198 28-Apr-2018 rpe

Add a proper usage() function.

Suggested by and OK jmc.
OK tb


Revision tags: OPENBSD_6_3_BASE
# 1.197 04-Mar-2018 jmc

when -n is used, no need to spit out "Missing parameters." before
displaying usage();

ok tb


# 1.196 03-Mar-2018 landry

Lowercase 'usage' and group -n with interface in it.
From jmc@, ok tb@


# 1.195 21-Feb-2018 rpe

Tweak comments.

OK tb


# 1.194 19-Feb-2018 rpe

Write warning/error messages to stderr and end them with a fullstop.

OK tb


# 1.193 19-Feb-2018 rpe

- use specific patterns when looping over /etc/hostname.if files
to skip backup or temp files.
- test if the patterns matched actual files
- warn if ifcreate() fails on an interface and continue with the
subsequent interfaces in the list instead of return'ing

OK dlg sthen tb


# 1.192 17-Feb-2018 rpe

- Add descriptions for the new functions ifcreate() and vifscreate()
- In ifcreate() use the exit code of the {} block directly
- In vifscreate(), use the ifconfig -C output directly in the for _vif loop
- Remove superfluous and somewhat confusing comment

OK dlg kn sthen


# 1.191 14-Feb-2018 dlg

create virtual interfaces before starting all interface config.

this resolves an ordering problem when adding pseudo interfaces to bridges

tweaks from kn@
ok mpi@ sthen@


# 1.190 10-Feb-2018 claudio

Remove some special IPv4 in IPv6 mapped prefixes that are already rejected
by the ::0.0.0.0/96 reject route added to deny all IPv4 mapped addresses.
Makes the inet6 routing table almost fit in one screen.
OK benno@


# 1.189 10-Feb-2018 florian

Load RFC 7217 key material and generate if it does not already exist.

Add soii.key to changelist (pointed out by semarie) and mtree/special
(suggest by Craig Skinner).

OK naddy, sthen, rpe, tb


# 1.188 06-Feb-2018 tb

If -n is given, the netstart script should not (try to) set the default
route(s). Simply print the command(s) to be issued instead.

tweak & ok rpe


# 1.187 12-Nov-2017 tb

Remove HN_DIR variable and expand it in the only place it was used. It
currently serves no purpose.

ok rpe, agreement from deraadt and halex


Revision tags: OPENBSD_6_2_BASE
# 1.186 25-Jul-2017 rpe

Finally remove backwards compat code to support the 'rtsol' keyword
in hostname.if(5)

OK mpi@ deraadt@ florian@
OK jmc@ from doc perspective


# 1.185 21-Jul-2017 rpe

Align ifstart() in netstart and install.sub.

- in netstart, rename _file to _hn referencing hostname.if files
- in install.sub switch ifstart() to be used with _if instead of
_hn as parameter

ok krw@ tb@


# 1.184 28-May-2017 awolk

etc/netstart: use colon separator instead of dot with chown

OK jung@, deraadt@, jmc@


# 1.183 07-May-2017 rpe

Change test from [] to [[]] and simplify pattern.

OK tb@, krw@ (for [[]])
Feedback and OK halex@


# 1.182 07-May-2017 rpe

Replace hardcoded script name with ${0##*/}

OK tb@ halex@


# 1.181 01-May-2017 rpe

Revert r1.170 and remove the id==0 check.
The id binary is not available in nfs diskless setups at this point.

reported by Andreas Kusalananda, thanks.
discussed with deraadt@


# 1.180 01-May-2017 rpe

Remove last remnants of rtsol. IPv6 autoconfiguration of interfaces is now
done in ifstart(). Remove ipv6autoconf() and replace rtsolif with a boolean
variable V6_AUTOCONF. Replace dhcpif with a boolean variable V4_DHCPCONF.
Both are later used in defaultroute() to decide whether or not to configre
defaultroutes from /etc/mygate.

OK krw@


# 1.179 30-Apr-2017 mpi

Do not try to delete a default route before adding it.

Now that route are automatically G/C with the address they are attached
to there's no reason to duplicate the kernel's job.

Fix a regression introduced with multipath default routes.

ok deraadt@


# 1.178 25-Apr-2017 rpe

Unbreak netstart for multiple inteface configurations like trunk
or carp. Ensure that the noglob option is disabled at the end of
parse_hn_line() and ifstart().

Reported by Christer Solskogen and Stefan Wollny, thanks!


# 1.177 24-Apr-2017 rpe

Introduce a new function parse_hn_line() that replaces the existing
hostname.if(5) parsing code in ifstart().
Add a -n option to netstart to only print the interface configuration
commands instead of executing them.
Add a HN_DIR variable, that points to the directory of the hostname.if
files (default /etc) that allows for future regression tests.

- add new parse_hn_line() function
- change ifstart()
- rename $if to $_if
- don't ifconfig or ifconfig create if -n option is used
- replace hostname.if(5) parsing code with new parse_hn_line()
- just print configuration commands if -n option is used
- autoconf now happens in ifstart(), remove ifv6autoconf()
- introduce HN_DIR variable for the hostname.if file location
- add handling of the -n option to only print config commands
- ensure -n is only used if interfaces are specified as parameters

Discussed with and positive feedback from many
'commit' deraadt@
OK sthen@


# 1.176 08-Apr-2017 rpe

- localize the if, file and stat variables which also ensures that
variables are not named like commands.
- change test from [] to [[]]

OK tb@ halex@


# 1.175 07-Apr-2017 rpe

Minimize differences in ifstart() function between netstart and
install.sub which makes it easier to spot changes in the future.

- comments and formatting
- quotes on assignments are not needed (netstart)
- remove stray space in test (netstart)
- use $file variable with while-loop (netstart)
- although valid, instead of i use $i in arithmetic test (install.sub)

OK krw@, tb@
Looks good deraadt@


# 1.174 07-Apr-2017 rpe

Align comments of ifstart() function in netstart and install.sub.


# 1.173 07-Apr-2017 rpe

Align comments of stripcom() function in netstart and install.sub.


Revision tags: OPENBSD_6_1_BASE
# 1.172 06-Dec-2016 mpi

Do not lose the default route when netstart(8) is run a second time on
the interface pointed to by the default route.

Since the kernel no longer keep routes with dangling address pointer,
netstart(8) has to re-add the default route when the corresponding ifa
has been deleted and re-created.

deraadt@ points out that even if the previous semantic was not necessarily
better, a script like netstart(8) cannot totally fix the default route
problem.

Regression reported by and fix tested by Hrvoje Popovski.

ksh foo checked by halex@


# 1.171 27-Sep-2016 rzalamena

Delay switch(4) interface start up so it can attach virtual interfaces
like vether(4).

nits from and ok benno@, phessler@


# 1.170 09-Sep-2016 jasper

print a clear error message when not ran as root instead of just falling
through and try whatever it can do with the invoking user's perms

feedback/ok aja@ rpe@


Revision tags: OPENBSD_6_0_BASE
# 1.169 19-Jul-2016 mpi

Do not consider tap(4) a special interface and start if before other
pseudo-interfaces.

This unbreak vlan(4) on top of tap(4) since the refactoring to turn it
MP-safe.

ok claudio@, deraadt@


# 1.168 27-Mar-2016 sthen

Don't delete the 224/4 route in netstart, unless it's being done to ensure that
a -reject route can be added. Restores the ability to set an interface route
before daemons are started, lost during the previous simplification.
ok millert mpi


Revision tags: OPENBSD_5_9_BASE
# 1.167 29-Dec-2015 rpe

Remove backslash, not necessary after '&&'

OK halex@


# 1.166 29-Dec-2015 rpe

Replace last remaining `` with $()

OK halex@


# 1.165 18-Dec-2015 ajacoutot

Drop the now useless multicast setup comment.

prodded by tim@, ok mpi@


# 1.164 17-Dec-2015 ajacoutot

Simplify multicast option handling (10 less lines) by matching /etc/rc behavior
towards other YES|NO options and drop the error warning.


with and ok tim@, ok rpe@ on an earlier diff


# 1.163 05-Dec-2015 mpi

It does not make sense to insert a specific route for 224/4 when the
default one is good enough.

So merge rc.conf(8)'s 'multicast_router' and 'multicast_host' into a
single 'multicast'. If set to YES the reject route for 224/4 is not
inserted by netstart(8).

Manual bits from jmc@

ok henning@, ajacoutot@


# 1.162 12-Nov-2015 rpe

Changes to ifautostart():
- Rename function to ifv6autoconf() to make IPv6 relation clearer
- Localize and rename variables

OK krw@


# 1.161 12-Nov-2015 rpe

Changes to ifmstart():
- Change comments to make it clearer that ifmstart() takes two lists
of interface driver names (of which the second is optional) and not
the actual interface instances.
- Use localized variables and use slightly more verbose names.
- Use continue 2 to skip to the next hostname.if file.
- Use shell pattern @() instead of testing _sif individually.

OK krw@


# 1.160 12-Nov-2015 rpe

Changes to stripcom():
- Align comments with /etc/rc version
- Use localized variables
- Use safer "print -r --" instead of plain echo

Changes to ifstart():
- Tweak comment
- Add usage

OK krw@


# 1.159 01-Nov-2015 rpe

Start the rework of the /etc/netstart shell script.

General changes:
- apply a similar 'style' as used in the installer scripts
- improve comments to be more to the point, remove where code is obvious
- document usage of functions if they have arguments
- rename variables where it improves readability
- replace really old-school shell code with more contemporary idioms

Other changes:
- No need to care about "autoboot" because netstart doesn't inherit the
positional parameters from /etc/rc anymore. /etc/rc executes netstart
instead of sourcing it since r1.439.
- Use simpler for-loop to process list of interfaces with ifstart.

OK halex@


# 1.158 26-Oct-2015 rpe

The hostname variable is not used since r1.99. Remove it and use
stripcom() output directly with the hostname command.

OK deraadt@ krw@


# 1.157 23-Oct-2015 claudio

netstart bits for tap(4)


# 1.156 27-Sep-2015 sthen

Don't print output when setting autoconf on interfaces. Suggested by deraadt,
ok florian@ rpe@


# 1.155 13-Sep-2015 sthen

only print the "IPv6 autoconf" line if there are interfaces to configure
feedback/ok rpe


# 1.154 11-Sep-2015 sthen

Set "inet6 autoconf" individually on interfaces that have rtsol set in
hostname.if, previously netstart tried to configure them all at once
("ifconfig if0 if1 if2 inet6 autoconf"). From Delan Azabani, ok phessler@


Revision tags: OPENBSD_5_8_BASE
# 1.153 20-Jul-2015 rpe

Disable Strict Bourne shell mode for /etc/rc and /etc/netstart to be
able to use ksh syntax within these scripts. This way init doesn't
need to be changed, which starts /etc/rc using /bin/sh and people
can still use "sh /etc/netstart ifname".

Idea from and OK halex@
OK deraadt@ krw@ guenther@


# 1.152 19-Jul-2015 florian

Bring up pflow last as it might send with a source address that is on
any of the other interfaces.
OK deraadt, phessler, benno


# 1.151 19-Jul-2015 rpe

Always source rc.subr to be able to use the rc.conf parsing routine
to get the network related vars from rc.conf. This is even necessary
if netstart is run from within /etc/rc. Remove test of $INRC which
unintentionally evaluated always to true.

problem with previous change found by nigel@
OK sthen@ aja@ halex@


# 1.150 19-Jul-2015 ajacoutot

Revert 1.148 for now until I can talk to rpe@
It introduced a regression reported by nigel@


# 1.149 19-Jul-2015 rpe

Replace test command with [].

OK halex@ krw@


# 1.148 19-Jul-2015 rpe

Ensure, that we source rc.subr and parse rc.conf ONLY if we are not
inside /etc/rc.

With help from and OK halex@, ajacoutot@


# 1.147 18-Jul-2015 rpe

- remove trailing blanks introduced in previous commit
- no space in redirections like </foo or >$bar
- few other minor whitespaces

OK krw@


# 1.146 18-Jul-2015 rpe

Improve comments
- Add comments for functions
- Start comments with capital letters
- End comments with a full stop
- Allow comments to extend up to column 80

OK krw@


# 1.145 06-Jun-2015 florian

Allow rtsol keyword in hostname.if(5) with net.inet6.ip6.forwarding=1.
"inet6 autoconf" was working before and rtsol should behave the same.
OK phessler


Revision tags: OPENBSD_5_7_BASE
# 1.144 03-Dec-2014 florian

The kernel handles rtsol(8) functionality since some time now.
Treat rtsol in hostname.if as a keyword like dhcp and call ifconfig
inet6 autoconf.
"reads good" todd@
OK krw@ (who is *not* an IPv6 person), but I recruited him in his
capacity as an installer person.


# 1.143 28-Sep-2014 claudio

Revert 1.142. Without the down netstart will just print the ifconfig
output because it may end up just calling 'ifconfig $if'. This needs
to be done better and properly tested.


# 1.142 26-Sep-2014 halex

remove explicit 'down' of an interface before starting a dhcp request, thereby
avoiding annoying delays for some switch configurations

ok claudio@ deraadt@

i would add ok phessler@, but it was not valid without an ok krw@


Revision tags: OPENBSD_5_6_BASE
# 1.141 12-Jul-2014 stsp

Fix netstart after autoconf6 change so 'rtsol' lines in hostname.if work again.
found by pelikan@; ok pelikan@ henning@


# 1.140 12-Jul-2014 robert

Make rc.conf a parsed configuration file and stop sourcing it as a shell
script.
From now on rc.conf has a fixed syntax (key=val) and it is not allowed
to add anything to it besides the supported syntax, it all going to be
ignored.

discussed with and help from deraadt@ and halex@


Revision tags: OPENBSD_5_5_BASE
# 1.139 22-Aug-2013 mpi

Like for dhclient, do no create a route to alias addresses via 127.0.0.1.
Our stack is able to tell if the address is local or not.

ok todd@, krw@


Revision tags: OPENBSD_5_4_BASE
# 1.138 20-Mar-2013 todd

fix lies in netstart; replacement wording from halex@
pointed out by Ryan Kavannagh rak at debian dot org


Revision tags: OPENBSD_5_3_BASE
# 1.137 05-Dec-2012 rpe

remove "Invalid interface name" message
requested by krw@

ok halex@


# 1.136 02-Dec-2012 rpe

use the more compact version of the check for ifconfig'able interfaces
from install.sub

with feedback from and ok halex


# 1.135 02-Dec-2012 rpe

- remove isalphanumeric() and replace it with a shell pattern, that
tries a bit harder to identify invalid interface names and in
this case emit an error message.
- use [[ $1 == autoboot ]] to avoid a shell error message due to
possible spaces in first argument
- no change in functionality

discussed with krw and halex
ok ("I like this") krw


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.134 07-Oct-2011 deraadt

The new ypbind changes requires that the domainname be set before
rc.conf is run. There's no real downside.
ok aja


Revision tags: OPENBSD_5_0_BASE
# 1.133 07-Jul-2011 guenther

Eliminate some $? tests by rolling the command into the condition

ok halex@


# 1.132 26-May-2011 mpf

Add svlan(4) startup bits.
From markus@. OK naddy, claudio, reyk.


Revision tags: OPENBSD_4_9_BASE
# 1.131 09-Feb-2011 sobrado

fix an unbalanced parenthesis in a comment; while here, split the comment
in a better place to make it more readable.

ok jmc@ and miod@


Revision tags: OPENBSD_4_8_BASE
# 1.130 16-Jun-2010 todd

permit e.g. -inet6 syntax by slurping all lines not just some
noticed by rhsv6 at hushmail dot com, ok sthen@


Revision tags: OPENBSD_4_7_BASE
# 1.129 12-Jan-2010 henning

when setting up lo0 use 127.0.0.1/8 instead of 127.0.0.1 for clarity and
correctness. it's not 1992 any more, kids. ok mcbride dlg krw


# 1.128 10-Dec-2009 todd

o stop reordering ifconfig arguments (e.g. after 'up ..')
o only stop processing if inet or inet6 lines are malformed
o everything not a specially handled bit is passed to ifconfig unmangled
noticed by several after the move from bridgename.bridge0 -> hostname.bridge0
prodded by deraadt@, tested by and feedback from several
man page bits 'look fine' jmc@


# 1.127 22-Nov-2009 deraadt

Stop supporting bridgename.bridge* files, and move to hostname.bridge*
files. To cope with this change, read about the mv command.
ok claudio todd


# 1.126 17-Sep-2009 simon

change variable i to $i in an expression of ifstart() for consistency
with the rest of the file. no functional change.

feedback from sthen@, ok krw@


# 1.125 10-Jul-2009 jdixon

Delay creation of tun(4) interfaces until the underlying interface and
routes are available. This fixes usage for some OpenVPN users that start
it from hostname.tun*.

Tested by Johan Huldtgren. ok sthen@, johan@.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.124 25-Nov-2008 markus

delay /etc/netstart until IPv6-DAD (dup-address-detection) is completed.
ok fries, hshoexer, claudio


# 1.123 14-Aug-2008 sthen

Tools from /usr may not be used in netstart since it may be NFS-mounted
and not available at that time. Rewrite the hostname.if permission check
to use only /bin/ls and the shell. Requested by deraadt.

ok todd, "Twisted." deraadt


Revision tags: OPENBSD_4_4_BASE
# 1.122 23-Jul-2008 sthen

Prevent warning about insecure hostnames where no /etc/hostname.*
exists. From wcmaier@.

Check target of symbolic links to avoid noise at boot and in
seucrity output where you have several interfaces symlinked to one
config file.

"If you think this is the right thing to do" deraadt@


# 1.121 09-Jun-2008 todd

warn once not 3 times in case of a non existent file, discussed with deraadt
originally pointed out by Johan Torin


# 1.120 09-Jun-2008 deraadt

Ensure that hostname.* files are also re-chowned to root.wheel at each
boot as discussed with claudio while eating tasty donairs. ok todd


# 1.119 17-Apr-2008 deraadt

before using them, force hostname.* files to be unreadable by world
first version from todd, ok millert


Revision tags: OPENBSD_4_3_BASE
# 1.118 17-Jan-2008 brad

Execute rtsol after turning up trunk(4) and vlan(4) interfaces so they're
taken into consideration for rtsol.

ok reyk@ dlg@


# 1.117 09-Jan-2008 mpf

Do not bring up pfsync(4) before the working ruleset
has been loaded. Otherwise, states that are received during the
initial bulk update mismatch the correct pf-checksum and
do not attach to the rules.
Problem identified by david@. Fix done in collaboration.
OK henning@


Revision tags: OPENBSD_4_2_BASE
# 1.116 02-Aug-2007 david

move the delay for IPv6 DAD to after all interfaces have started
fixes problems with daemons being unable to bind to all addreses at boot
ok itojun@ hshoexer@


Revision tags: OPENBSD_4_1_BASE
# 1.115 15-Nov-2006 itojun

reject multicast packet without scope identifier specified.


Revision tags: OPENBSD_4_0_BASE
# 1.114 29-Jun-2006 todd

do not add an extra space; nwid and description come out wrong
fix as proposed by maja@, thanks!


Revision tags: OPENBSD_3_9_BASE
# 1.113 28-Dec-2005 david

nuke extra whitespace


# 1.112 06-Dec-2005 reyk

multicast_host=YES only works if a valid default gateway is available.
validate this condition and reject multicast traffic on failure.

ok todd@ naddy@


# 1.111 02-Nov-2005 todd

fix inspired by pr#4590
ok krw@


# 1.110 25-Oct-2005 todd

better logic from krw@:
- do not process mygate for v4 if dhcp
- do not process mygate for v6 if rtsol
this also makes the mygate processing logic more readable
ok krw@


# 1.109 14-Oct-2005 todd

add v6 support for /etc/mygate
ok deraadt@ mickey@ krw@
same functionality tested/ok'ed by by mickey, brad, matthieu, and me
with this one may now put a v6 IP in /etc/mygate on a separate line from
the v4 default gateway and netstart will do the right thing


# 1.108 12-Oct-2005 todd

shrink stripcom(), sync with install.sub
ok krw@


# 1.107 04-Oct-2005 todd

trunk must be started after physical ethernet devices, but before vlan.
populate ifmstart lines accordingly.
prodded/tested by brad@
ok reyk@


# 1.106 28-Sep-2005 todd

use eval consistently, fixes description quotes on rtsol and dhcp
fix inspired by and closes pr 4495
ok krw@


Revision tags: OPENBSD_3_8_BASE
# 1.105 22-May-2005 todd

Introduce 'ifmstart' to deal with starting multiple interfaces minus a list
of interfaces.

This reduces the netstart script by 174 chars, 13 words, and 19 lines, but
more importantly, makes it more simple and less cluttered should more special
case/orderings be needed.

ok brad@ and pr 4197 submitter, inspired by and closes pr 4197


# 1.104 04-Apr-2005 djm

unbreak; ok pval@


# 1.103 03-Apr-2005 deraadt

if dhcp is used to get an address on any interface, ignore /etc/mygate
ok krw
(this lets us do something rather cool with the zaurus in particular)


Revision tags: OPENBSD_3_7_BASE
# 1.102 04-Jan-2005 mcbride

Bring up the carp(4) interface before default route.

ok pascoe@ mpf@


# 1.101 30-Dec-2004 millert

Add a copy of stripcom so /etc/netstart can be run standalone again.
OK deraadt@


# 1.100 19-Dec-2004 millert

Allow comments in /etc/{myname,mygate,defaultdomain}; OK deraadt@


# 1.99 04-Dec-2004 itojun

remove "route $hostname 127.0.0.1" line. deraadt ok
*** please update /etc/netstart and test if it works ok for you ***


# 1.98 20-Oct-2004 deraadt

make all route commands use -qn; ok mcbride henning


Revision tags: OPENBSD_3_6_BASE
# 1.97 29-May-2004 deraadt

one last route command lacking -qn


Revision tags: OPENBSD_3_5_BASE
# 1.96 22-Mar-2004 mcbride

Make sure pfsync is brought up before carp.

ok deraadt@


# 1.95 13-Mar-2004 mcbride

Delay pfsync(4) configuration, as the syncif has to be configured in
advance. From Thorsten Lockert.


# 1.94 14-Jan-2004 deraadt

ok, it took quite a bit of prodding but itojun finally explained why the
extra sleep 1 is in here, and we came to the conclusion it is safe to
delete it. whee.


# 1.93 13-Jan-2004 deraadt

repair v6 lo0 documentation


# 1.92 11-Jan-2004 deraadt

add loopback routes late


# 1.91 09-Jan-2004 deraadt

create all routes with -q; markus ok


# 1.90 04-Dec-2003 millert

Need to do "ifconfig create" for bridge interfaces too.


# 1.89 03-Dec-2003 markus

add support for ifconfig clone; from netbsd; ok deraadt, henning


# 1.88 20-Oct-2003 david

delay carp initialization until after physical interfaces are configured
ok mcbride@ henning@ deraadt@ todd@


Revision tags: OPENBSD_3_4_BASE
# 1.87 27-Aug-2003 henning

only try to set hostname to what /etc/myname says if that file actually exists,
otherwise preserve `hostname`
netbooted machines can live perfectly fine without it; they get their hostname
earlier.

ok krw@ cedric@


Revision tags: OPENBSD_3_3_BASE
# 1.86 16-Feb-2003 krw

Fix up some DNS verbiage to make it consistant.

Fix up default route selection by

a) Forcing user to explicitly chose 'dhcp' as a mechanism for
specifying a default route, rather than guessing based on one or more
interfaces being configured by dhcp.

b) If the user specified default route does not work, re-present the
existing default route rather than losing it.

c) Move default route selection to after nameserver activation so the
user can specify a hostname as the default route.

Change /etc/netstart so that /etc/mygate wins if a default route was
already specified (i.e. by dhcp).

ok deraadt@.


Revision tags: OPENBSD_3_2_BASE
# 1.85 16-May-2002 todd

ignore non-existent cases where '$if' evaluates to '*'.
From Andr� Lucas <andre@ae-35.com>, fixes pr # 2658.
'Looks good' from miod@, millert@, and krw@.


Revision tags: OPENBSD_3_1_BASE
# 1.84 23-Feb-2002 deraadt

re-add support for $if expansion; hamajima@nagoya.ydc.co.jp


# 1.83 21-Feb-2002 miod

Change the network components initialization order.
Change from:
o all interfaces
o all bridges
o routes
to:
o physical interfaces
o routes
o gif and gre interfaces
o bridges

Fixeski PR #2400.
Manual page updates coming soon.
Ok angelos@ chris@ deraadt@


Revision tags: OPENBSD_3_0_BASE
# 1.82 31-Jul-2001 hugh

a space before a redirect


# 1.81 06-Jul-2001 angelos

Also, source /etc/rc.conf so we can pull in the
multicast_host/multicast_router settings; this is useful if one
flushes the routing table and re-initializes.

We really need a netconfig tool of sorts.


# 1.80 06-Jul-2001 angelos

Use "route -n show -inet" to determine the default multicast iface.


# 1.79 03-Jul-2001 deraadt

pull in rc.conf early so that pf(1) startup is right; tested by jasoni, comments from millert


# 1.78 30-May-2001 deraadt

Remove ipf. Darren Reed has interpreted his (old, new, whichever)
licence in a way that makes ipf not free according to the rules we
established over 5 years ago, at www.openbsd.org/goals.html (and those
same basic rules govern the other *BSD projects too). Specifically,
Darren says that modified versions are not permitted. But software
which OpenBSD uses and redistributes must be free to all (be they
people or companies), for any purpose they wish to use it, including
modification, use, peeing on, or even integration into baby mulching
machines or atomic bombs to be dropped on Australia. Furthermore, we
know of a number of companies using ipf with modification like us, who
are now in the same situation, and we hope that some of them will work
with us to fill this gap that now exists in OpenBSD (temporarily, we
hope).


Revision tags: OPENBSD_2_9_BASE
# 1.77 13-Mar-2001 deraadt

spelling; maurice@maurice.wan.nl


# 1.76 06-Feb-2001 todd

ignore blank lines in addition to comments
fixes pr#1660 from wilfried@telia.com .. Thanks!


# 1.75 10-Jan-2001 jason

support !command in bridgename.if files, too


# 1.74 27-Nov-2000 millert

Use -n to test if a variable is non-zero. Otherwise, if the variable's
contents start with a '-' test becomes unhappy (since it interprets it
as another option).


# 1.73 08-Nov-2000 todd

This fixes pr 1481, we now handle args > 6 in /etc/hostname.if in the
cases where we did not previously handle them.
Thanks to Scott Atwood <atwood@cs.stanford.edu> for reminding us of this.


Revision tags: OPENBSD_2_8_BASE
# 1.72 02-Sep-2000 todd

subtle bug .. global variables in a while loop need reset 'just incase'
With:
hostname.fxp0 having a last line of:
inet6 alias 3ffe:...
and hostname.gif0 having a first two lines of:
giftunnel 1.2.3.4
dest 1.2.4.3
We end up with the command:
ifconfig gif0 giftunnel alias 1.2.3.4 1.2.4.3
.. which is clearly wrong and fixed by this change


# 1.71 18-Jun-2000 todd

rc.conf now parses ${local_rcconf} internally; closes pr 1259


Revision tags: OPENBSD_2_7_BASE
# 1.70 08-May-2000 todd

fix dhcp 'NONE' ness from install to allow media parsing to work
.. ok deraadt@, millert@


# 1.69 21-Apr-2000 deraadt

rc.conf.local support, inspired by chuck yerkes


# 1.68 04-Apr-2000 millert

Remove the -E flag from ipf as it is implicitly enabled and using
the -E flag here causes the kernel to printf 'IP Filter: already
initialized'.


# 1.67 18-Mar-2000 deraadt

silence all extra route addition printouts


# 1.66 17-Mar-2000 itojun

correct reject route installations for IPv6. improve comments.


# 1.65 12-Mar-2000 itojun

disallow packets to malicious 6to4 prefix, based on
http://playground.iijlab.net/i-d/draft-itojun-ipv6-transition-abuse-00.txt


# 1.64 10-Mar-2000 todd

fix non behavior
with this `!' lines in /etc/hostname.* run even without certain lines
(like a comment) preceeding it.


# 1.63 10-Jan-2000 todd

allow arbitrary commands in /etc/hostname.* files if the line starts with '!'


# 1.62 02-Jan-2000 deraadt

rtsol case can configure the interface up, since it would be nice to finish
DAD before the actual rtsol(8) run happens later. and since it will rtsol,
it is going to be up in any case.


# 1.61 02-Jan-2000 itojun

one more indentation fix.


# 1.60 02-Jan-2000 itojun

indentation fix (todd's part)


# 1.59 02-Jan-2000 todd

fix rtsold case, reset cmd for each iteration!


# 1.58 02-Jan-2000 itojun

allow options after "rtsol".
XXX both "dhcp" and "rtsol" has keyword *down* at the end. is it okay?


# 1.57 02-Jan-2000 itojun

echo "IPv6 autoconf: interfaces" before invoking rtsol.
sleep for net.inet6.ip6.dad_count seconds to ensure that IPv6 DAD is completed.
TODO: rtsold (rc.conf line), manpage


# 1.56 02-Jan-2000 itojun

ipv6 autoconf on hosts (non-routers).

to do this,
1. in sysctl.conf, add these lines:
net.inet6.ip6.forwarding=0
net.inet6.ip6.accept_rtadv=1
2. in hostname.foo, add
rtsol

specifying two or more interfaces with "rtsol" may result in strange
behavior - ipv6 spec does not permit multi-interface node to be autoconfig'ed.


# 1.55 02-Jan-2000 todd

add to hostname.* parsing:
- multiple entries support (read: aliases)
- inet6 support
- support for comments (#)
(look for hostname.if(5) commit for syntax details)


# 1.54 31-Dec-1999 itojun

install IPv6 reject routes only if kernel is capable of IPv6.


# 1.53 09-Dec-1999 itojun

avoid transmitting invalid IPv6 packets out to the wire.


# 1.52 09-Dec-1999 itojun

do not perform IPv6 initialization for loopback interface.
MUST make lo0 up before any IPv6 operations.
it will be considered a pilot error if you don't.
(I prefer to have lo0 initialized automatically)


Revision tags: OPENBSD_2_6_BASE
# 1.51 01-Sep-1999 deraadt

support # characters in bridgename.* files; millert


# 1.50 01-Sep-1999 deraadt

cleanup parsing of hostname.* files, and seperate bridge control into
bridgename.* files; all documented in new hostname.if(5) and
bridgename.if(5) man pages


# 1.49 09-Aug-1999 angelos

Only parse/setup the hostname.foo file if interface foo exists (this
is useful for laptops with different ethernet cards etc.)


Revision tags: OPENBSD_2_5_BASE
# 1.48 29-Mar-1999 niklas

New multicast route setup style


# 1.47 26-Mar-1999 niklas

Add bridge interface handling


# 1.46 01-Mar-1999 millert

Add support in /etc/hostname.xxx for files of the format:
up [options]
Any of the following may or may not be set:
$name $mask $bcaddr $extras


# 1.45 28-Oct-1998 millert

Kill the awful hack used to match and split /etc/hostname.* We now use
a function, isalphanumeric, to determine whether an interface name is
likely to be valid. This means that things like /etc/hostname.le0.bak,
/etc/hostname.le0#, /etc/hostname.le0~, etc. will be ignored as they
should. There is no longer an implicate assumption that /etc/hostname.*
only contains a single '.'.


Revision tags: OPENBSD_2_4_BASE
# 1.44 06-Oct-1998 deraadt

move ipnat to end of netstart, to support dhcp+ipnat


# 1.43 18-Sep-1998 deraadt

apply media directives on dhcp interfaces


# 1.42 10-Sep-1998 marc

better way of handling dhcp client; Jason Ish <jbi130@mail.usask.ca>


# 1.41 08-Sep-1998 marc

dhcp client stuff. "Angelos D. Keromytis" <angelos@dsl.cis.upenn.edu>


# 1.40 24-Aug-1998 downsj

You can't use -interface default when there's no default gateway
set (yet). Use -interface $hostname if mygate doesn't exist so that
this actually works on routers.


# 1.39 04-Jul-1998 deraadt

put 224 route on default, to avoid a hostname lookup


# 1.38 22-May-1998 deraadt

use route -n, what the heck


Revision tags: OPENBSD_2_3_BASE
# 1.37 28-Mar-1998 deraadt

s/^nat/ipnat/


# 1.36 23-Feb-1998 niklas

remove trailing blank line


# 1.35 07-Feb-1998 deraadt

ipforward is in sysctl.conf now


# 1.34 21-Dec-1997 deraadt

ugh


# 1.33 20-Dec-1997 deraadt

ipforwarding option in rc.conf


# 1.32 29-Nov-1997 kstailey

NAT requires IPF


# 1.31 04-Nov-1997 deraadt

kill spaces at ends of lines; m4


Revision tags: OPENBSD_2_2_BASE
# 1.30 14-Oct-1997 deraadt

set hostname/domainname before running rc.conf; m4@umn.edu


# 1.29 04-Sep-1997 deraadt

fork netstart; new child is rc.conf


# 1.28 25-Aug-1997 millert

Explicately pass -host flag to route(8) to avoid confusion with networks.


# 1.27 19-Aug-1997 niklas

Add hook for rpc.lockd, make nfsd flags settable in netstart


# 1.26 31-Jul-1997 downsj

Make quotas optional; wedged into netstart for the time being.
/etc/rc.conf, anyone?


# 1.25 30-Jul-1997 deraadt

do not run routed by default


# 1.24 28-Jul-1997 kstailey

Move configuration of loopback interface to before all other interfaces.
Allows the use of local caching-only nameserver with no "nameserver"
entry in /etc/resolv.conf to configure a route between the hostname
and loopback.


# 1.23 25-Jul-1997 provos

earlier start of keymanagement


# 1.22 24-Jul-1997 deraadt

make amd use /tmp_mnt by default


# 1.21 22-Jul-1997 provos

start the photuris daemon per default. hilfe.


# 1.20 17-Jun-1997 niklas

Put in hooks to start ypserv with flags


# 1.19 17-Jun-1997 niklas

Put in hooks to start rpc.yppasswdd with flags


Revision tags: OPENBSD_2_1_BASE
# 1.18 15-Apr-1997 deraadt

kill route flush until .. hmm kernel routing socket bug or something


# 1.17 09-Apr-1997 kstailey

add NAT startup


# 1.16 07-Apr-1997 rees

flush all old routes before adding new interfaces or routes.
ref: netbsd pr3228/misc, Matthias Scheler


# 1.15 03-Mar-1997 downsj

fix typo


# 1.14 11-Feb-1997 deraadt

add default route before fiddling with loopback route to avoid DNS problems; m4@umn.edu, #97


# 1.13 03-Feb-1997 deraadt

do ifaliases after /usr/bin exists in nfs diskless env; pr#77, matthieu@laas.fr


# 1.12 02-Nov-1996 deraadt

timed off by default


Revision tags: OPENBSD_2_0_BASE
# 1.11 23-Sep-1996 deraadt

rfc1323 variable


# 1.10 04-Sep-1996 deraadt

control portmap, inetd, and lpd from netstart; idea from tqbf@enteract.com


# 1.9 27-Aug-1996 deraadt

224.0.0.0 not 0.0.0.224; from peter@demon.net


# 1.8 18-Jun-1996 deraadt

move std stuff from rc.local to rc


# 1.7 16-Jun-1996 deraadt

install sample commented /etc/ifaliases file; which can now contain #
comments and blank lines. new format is "interface address netmask"
(yes, i changed the order of the entries). inspired by netbsd pr#2474;
gillhaa@ghost.whirlpool.com


# 1.6 02-Jun-1996 tholo

Install a multicast route by default


# 1.5 26-May-1996 deraadt

sync & label


# 1.4 09-Jan-1996 dm

added IP filter to netstat/rc and put examples in /usr/share/ipf


# 1.3 30-Dec-1995 deraadt

from netbsd: start mrouted like routed


# 1.2 18-Dec-1995 deraadt

/etc/ifaliases support by randy@zyzzyva.com


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.199 08-Jul-2018 tb

netstart is used during system start, but also interactively.
Show proper error message if a regular user executes netstart.
Only do the privilege check if the id binary is available,
which might not be the case during diskless system startup.

ok deraadt, jasper, jca, krw, rpe (who wrote the same diff), sthen


# 1.198 28-Apr-2018 rpe

Add a proper usage() function.

Suggested by and OK jmc.
OK tb


Revision tags: OPENBSD_6_3_BASE
# 1.197 04-Mar-2018 jmc

when -n is used, no need to spit out "Missing parameters." before
displaying usage();

ok tb


# 1.196 03-Mar-2018 landry

Lowercase 'usage' and group -n with interface in it.
From jmc@, ok tb@


# 1.195 21-Feb-2018 rpe

Tweak comments.

OK tb


# 1.194 19-Feb-2018 rpe

Write warning/error messages to stderr and end them with a fullstop.

OK tb


# 1.193 19-Feb-2018 rpe

- use specific patterns when looping over /etc/hostname.if files
to skip backup or temp files.
- test if the patterns matched actual files
- warn if ifcreate() fails on an interface and continue with the
subsequent interfaces in the list instead of return'ing

OK dlg sthen tb


# 1.192 17-Feb-2018 rpe

- Add descriptions for the new functions ifcreate() and vifscreate()
- In ifcreate() use the exit code of the {} block directly
- In vifscreate(), use the ifconfig -C output directly in the for _vif loop
- Remove superfluous and somewhat confusing comment

OK dlg kn sthen


# 1.191 14-Feb-2018 dlg

create virtual interfaces before starting all interface config.

this resolves an ordering problem when adding pseudo interfaces to bridges

tweaks from kn@
ok mpi@ sthen@


# 1.190 10-Feb-2018 claudio

Remove some special IPv4 in IPv6 mapped prefixes that are already rejected
by the ::0.0.0.0/96 reject route added to deny all IPv4 mapped addresses.
Makes the inet6 routing table almost fit in one screen.
OK benno@


# 1.189 10-Feb-2018 florian

Load RFC 7217 key material and generate if it does not already exist.

Add soii.key to changelist (pointed out by semarie) and mtree/special
(suggest by Craig Skinner).

OK naddy, sthen, rpe, tb


# 1.188 06-Feb-2018 tb

If -n is given, the netstart script should not (try to) set the default
route(s). Simply print the command(s) to be issued instead.

tweak & ok rpe


# 1.187 12-Nov-2017 tb

Remove HN_DIR variable and expand it in the only place it was used. It
currently serves no purpose.

ok rpe, agreement from deraadt and halex


Revision tags: OPENBSD_6_2_BASE
# 1.186 25-Jul-2017 rpe

Finally remove backwards compat code to support the 'rtsol' keyword
in hostname.if(5)

OK mpi@ deraadt@ florian@
OK jmc@ from doc perspective


# 1.185 21-Jul-2017 rpe

Align ifstart() in netstart and install.sub.

- in netstart, rename _file to _hn referencing hostname.if files
- in install.sub switch ifstart() to be used with _if instead of
_hn as parameter

ok krw@ tb@


# 1.184 28-May-2017 awolk

etc/netstart: use colon separator instead of dot with chown

OK jung@, deraadt@, jmc@


# 1.183 07-May-2017 rpe

Change test from [] to [[]] and simplify pattern.

OK tb@, krw@ (for [[]])
Feedback and OK halex@


# 1.182 07-May-2017 rpe

Replace hardcoded script name with ${0##*/}

OK tb@ halex@


# 1.181 01-May-2017 rpe

Revert r1.170 and remove the id==0 check.
The id binary is not available in nfs diskless setups at this point.

reported by Andreas Kusalananda, thanks.
discussed with deraadt@


# 1.180 01-May-2017 rpe

Remove last remnants of rtsol. IPv6 autoconfiguration of interfaces is now
done in ifstart(). Remove ipv6autoconf() and replace rtsolif with a boolean
variable V6_AUTOCONF. Replace dhcpif with a boolean variable V4_DHCPCONF.
Both are later used in defaultroute() to decide whether or not to configre
defaultroutes from /etc/mygate.

OK krw@


# 1.179 30-Apr-2017 mpi

Do not try to delete a default route before adding it.

Now that route are automatically G/C with the address they are attached
to there's no reason to duplicate the kernel's job.

Fix a regression introduced with multipath default routes.

ok deraadt@


# 1.178 25-Apr-2017 rpe

Unbreak netstart for multiple inteface configurations like trunk
or carp. Ensure that the noglob option is disabled at the end of
parse_hn_line() and ifstart().

Reported by Christer Solskogen and Stefan Wollny, thanks!


# 1.177 24-Apr-2017 rpe

Introduce a new function parse_hn_line() that replaces the existing
hostname.if(5) parsing code in ifstart().
Add a -n option to netstart to only print the interface configuration
commands instead of executing them.
Add a HN_DIR variable, that points to the directory of the hostname.if
files (default /etc) that allows for future regression tests.

- add new parse_hn_line() function
- change ifstart()
- rename $if to $_if
- don't ifconfig or ifconfig create if -n option is used
- replace hostname.if(5) parsing code with new parse_hn_line()
- just print configuration commands if -n option is used
- autoconf now happens in ifstart(), remove ifv6autoconf()
- introduce HN_DIR variable for the hostname.if file location
- add handling of the -n option to only print config commands
- ensure -n is only used if interfaces are specified as parameters

Discussed with and positive feedback from many
'commit' deraadt@
OK sthen@


# 1.176 08-Apr-2017 rpe

- localize the if, file and stat variables which also ensures that
variables are not named like commands.
- change test from [] to [[]]

OK tb@ halex@


# 1.175 07-Apr-2017 rpe

Minimize differences in ifstart() function between netstart and
install.sub which makes it easier to spot changes in the future.

- comments and formatting
- quotes on assignments are not needed (netstart)
- remove stray space in test (netstart)
- use $file variable with while-loop (netstart)
- although valid, instead of i use $i in arithmetic test (install.sub)

OK krw@, tb@
Looks good deraadt@


# 1.174 07-Apr-2017 rpe

Align comments of ifstart() function in netstart and install.sub.


# 1.173 07-Apr-2017 rpe

Align comments of stripcom() function in netstart and install.sub.


Revision tags: OPENBSD_6_1_BASE
# 1.172 06-Dec-2016 mpi

Do not lose the default route when netstart(8) is run a second time on
the interface pointed to by the default route.

Since the kernel no longer keep routes with dangling address pointer,
netstart(8) has to re-add the default route when the corresponding ifa
has been deleted and re-created.

deraadt@ points out that even if the previous semantic was not necessarily
better, a script like netstart(8) cannot totally fix the default route
problem.

Regression reported by and fix tested by Hrvoje Popovski.

ksh foo checked by halex@


# 1.171 27-Sep-2016 rzalamena

Delay switch(4) interface start up so it can attach virtual interfaces
like vether(4).

nits from and ok benno@, phessler@


# 1.170 09-Sep-2016 jasper

print a clear error message when not ran as root instead of just falling
through and try whatever it can do with the invoking user's perms

feedback/ok aja@ rpe@


Revision tags: OPENBSD_6_0_BASE
# 1.169 19-Jul-2016 mpi

Do not consider tap(4) a special interface and start if before other
pseudo-interfaces.

This unbreak vlan(4) on top of tap(4) since the refactoring to turn it
MP-safe.

ok claudio@, deraadt@


# 1.168 27-Mar-2016 sthen

Don't delete the 224/4 route in netstart, unless it's being done to ensure that
a -reject route can be added. Restores the ability to set an interface route
before daemons are started, lost during the previous simplification.
ok millert mpi


Revision tags: OPENBSD_5_9_BASE
# 1.167 29-Dec-2015 rpe

Remove backslash, not necessary after '&&'

OK halex@


# 1.166 29-Dec-2015 rpe

Replace last remaining `` with $()

OK halex@


# 1.165 18-Dec-2015 ajacoutot

Drop the now useless multicast setup comment.

prodded by tim@, ok mpi@


# 1.164 17-Dec-2015 ajacoutot

Simplify multicast option handling (10 less lines) by matching /etc/rc behavior
towards other YES|NO options and drop the error warning.


with and ok tim@, ok rpe@ on an earlier diff


# 1.163 05-Dec-2015 mpi

It does not make sense to insert a specific route for 224/4 when the
default one is good enough.

So merge rc.conf(8)'s 'multicast_router' and 'multicast_host' into a
single 'multicast'. If set to YES the reject route for 224/4 is not
inserted by netstart(8).

Manual bits from jmc@

ok henning@, ajacoutot@


# 1.162 12-Nov-2015 rpe

Changes to ifautostart():
- Rename function to ifv6autoconf() to make IPv6 relation clearer
- Localize and rename variables

OK krw@


# 1.161 12-Nov-2015 rpe

Changes to ifmstart():
- Change comments to make it clearer that ifmstart() takes two lists
of interface driver names (of which the second is optional) and not
the actual interface instances.
- Use localized variables and use slightly more verbose names.
- Use continue 2 to skip to the next hostname.if file.
- Use shell pattern @() instead of testing _sif individually.

OK krw@


# 1.160 12-Nov-2015 rpe

Changes to stripcom():
- Align comments with /etc/rc version
- Use localized variables
- Use safer "print -r --" instead of plain echo

Changes to ifstart():
- Tweak comment
- Add usage

OK krw@


# 1.159 01-Nov-2015 rpe

Start the rework of the /etc/netstart shell script.

General changes:
- apply a similar 'style' as used in the installer scripts
- improve comments to be more to the point, remove where code is obvious
- document usage of functions if they have arguments
- rename variables where it improves readability
- replace really old-school shell code with more contemporary idioms

Other changes:
- No need to care about "autoboot" because netstart doesn't inherit the
positional parameters from /etc/rc anymore. /etc/rc executes netstart
instead of sourcing it since r1.439.
- Use simpler for-loop to process list of interfaces with ifstart.

OK halex@


# 1.158 26-Oct-2015 rpe

The hostname variable is not used since r1.99. Remove it and use
stripcom() output directly with the hostname command.

OK deraadt@ krw@


# 1.157 23-Oct-2015 claudio

netstart bits for tap(4)


# 1.156 27-Sep-2015 sthen

Don't print output when setting autoconf on interfaces. Suggested by deraadt,
ok florian@ rpe@


# 1.155 13-Sep-2015 sthen

only print the "IPv6 autoconf" line if there are interfaces to configure
feedback/ok rpe


# 1.154 11-Sep-2015 sthen

Set "inet6 autoconf" individually on interfaces that have rtsol set in
hostname.if, previously netstart tried to configure them all at once
("ifconfig if0 if1 if2 inet6 autoconf"). From Delan Azabani, ok phessler@


Revision tags: OPENBSD_5_8_BASE
# 1.153 20-Jul-2015 rpe

Disable Strict Bourne shell mode for /etc/rc and /etc/netstart to be
able to use ksh syntax within these scripts. This way init doesn't
need to be changed, which starts /etc/rc using /bin/sh and people
can still use "sh /etc/netstart ifname".

Idea from and OK halex@
OK deraadt@ krw@ guenther@


# 1.152 19-Jul-2015 florian

Bring up pflow last as it might send with a source address that is on
any of the other interfaces.
OK deraadt, phessler, benno


# 1.151 19-Jul-2015 rpe

Always source rc.subr to be able to use the rc.conf parsing routine
to get the network related vars from rc.conf. This is even necessary
if netstart is run from within /etc/rc. Remove test of $INRC which
unintentionally evaluated always to true.

problem with previous change found by nigel@
OK sthen@ aja@ halex@


# 1.150 19-Jul-2015 ajacoutot

Revert 1.148 for now until I can talk to rpe@
It introduced a regression reported by nigel@


# 1.149 19-Jul-2015 rpe

Replace test command with [].

OK halex@ krw@


# 1.148 19-Jul-2015 rpe

Ensure, that we source rc.subr and parse rc.conf ONLY if we are not
inside /etc/rc.

With help from and OK halex@, ajacoutot@


# 1.147 18-Jul-2015 rpe

- remove trailing blanks introduced in previous commit
- no space in redirections like </foo or >$bar
- few other minor whitespaces

OK krw@


# 1.146 18-Jul-2015 rpe

Improve comments
- Add comments for functions
- Start comments with capital letters
- End comments with a full stop
- Allow comments to extend up to column 80

OK krw@


# 1.145 06-Jun-2015 florian

Allow rtsol keyword in hostname.if(5) with net.inet6.ip6.forwarding=1.
"inet6 autoconf" was working before and rtsol should behave the same.
OK phessler


Revision tags: OPENBSD_5_7_BASE
# 1.144 03-Dec-2014 florian

The kernel handles rtsol(8) functionality since some time now.
Treat rtsol in hostname.if as a keyword like dhcp and call ifconfig
inet6 autoconf.
"reads good" todd@
OK krw@ (who is *not* an IPv6 person), but I recruited him in his
capacity as an installer person.


# 1.143 28-Sep-2014 claudio

Revert 1.142. Without the down netstart will just print the ifconfig
output because it may end up just calling 'ifconfig $if'. This needs
to be done better and properly tested.


# 1.142 26-Sep-2014 halex

remove explicit 'down' of an interface before starting a dhcp request, thereby
avoiding annoying delays for some switch configurations

ok claudio@ deraadt@

i would add ok phessler@, but it was not valid without an ok krw@


Revision tags: OPENBSD_5_6_BASE
# 1.141 12-Jul-2014 stsp

Fix netstart after autoconf6 change so 'rtsol' lines in hostname.if work again.
found by pelikan@; ok pelikan@ henning@


# 1.140 12-Jul-2014 robert

Make rc.conf a parsed configuration file and stop sourcing it as a shell
script.
From now on rc.conf has a fixed syntax (key=val) and it is not allowed
to add anything to it besides the supported syntax, it all going to be
ignored.

discussed with and help from deraadt@ and halex@


Revision tags: OPENBSD_5_5_BASE
# 1.139 22-Aug-2013 mpi

Like for dhclient, do no create a route to alias addresses via 127.0.0.1.
Our stack is able to tell if the address is local or not.

ok todd@, krw@


Revision tags: OPENBSD_5_4_BASE
# 1.138 20-Mar-2013 todd

fix lies in netstart; replacement wording from halex@
pointed out by Ryan Kavannagh rak at debian dot org


Revision tags: OPENBSD_5_3_BASE
# 1.137 05-Dec-2012 rpe

remove "Invalid interface name" message
requested by krw@

ok halex@


# 1.136 02-Dec-2012 rpe

use the more compact version of the check for ifconfig'able interfaces
from install.sub

with feedback from and ok halex


# 1.135 02-Dec-2012 rpe

- remove isalphanumeric() and replace it with a shell pattern, that
tries a bit harder to identify invalid interface names and in
this case emit an error message.
- use [[ $1 == autoboot ]] to avoid a shell error message due to
possible spaces in first argument
- no change in functionality

discussed with krw and halex
ok ("I like this") krw


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.134 07-Oct-2011 deraadt

The new ypbind changes requires that the domainname be set before
rc.conf is run. There's no real downside.
ok aja


Revision tags: OPENBSD_5_0_BASE
# 1.133 07-Jul-2011 guenther

Eliminate some $? tests by rolling the command into the condition

ok halex@


# 1.132 26-May-2011 mpf

Add svlan(4) startup bits.
From markus@. OK naddy, claudio, reyk.


Revision tags: OPENBSD_4_9_BASE
# 1.131 09-Feb-2011 sobrado

fix an unbalanced parenthesis in a comment; while here, split the comment
in a better place to make it more readable.

ok jmc@ and miod@


Revision tags: OPENBSD_4_8_BASE
# 1.130 16-Jun-2010 todd

permit e.g. -inet6 syntax by slurping all lines not just some
noticed by rhsv6 at hushmail dot com, ok sthen@


Revision tags: OPENBSD_4_7_BASE
# 1.129 12-Jan-2010 henning

when setting up lo0 use 127.0.0.1/8 instead of 127.0.0.1 for clarity and
correctness. it's not 1992 any more, kids. ok mcbride dlg krw


# 1.128 10-Dec-2009 todd

o stop reordering ifconfig arguments (e.g. after 'up ..')
o only stop processing if inet or inet6 lines are malformed
o everything not a specially handled bit is passed to ifconfig unmangled
noticed by several after the move from bridgename.bridge0 -> hostname.bridge0
prodded by deraadt@, tested by and feedback from several
man page bits 'look fine' jmc@


# 1.127 22-Nov-2009 deraadt

Stop supporting bridgename.bridge* files, and move to hostname.bridge*
files. To cope with this change, read about the mv command.
ok claudio todd


# 1.126 17-Sep-2009 simon

change variable i to $i in an expression of ifstart() for consistency
with the rest of the file. no functional change.

feedback from sthen@, ok krw@


# 1.125 10-Jul-2009 jdixon

Delay creation of tun(4) interfaces until the underlying interface and
routes are available. This fixes usage for some OpenVPN users that start
it from hostname.tun*.

Tested by Johan Huldtgren. ok sthen@, johan@.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.124 25-Nov-2008 markus

delay /etc/netstart until IPv6-DAD (dup-address-detection) is completed.
ok fries, hshoexer, claudio


# 1.123 14-Aug-2008 sthen

Tools from /usr may not be used in netstart since it may be NFS-mounted
and not available at that time. Rewrite the hostname.if permission check
to use only /bin/ls and the shell. Requested by deraadt.

ok todd, "Twisted." deraadt


Revision tags: OPENBSD_4_4_BASE
# 1.122 23-Jul-2008 sthen

Prevent warning about insecure hostnames where no /etc/hostname.*
exists. From wcmaier@.

Check target of symbolic links to avoid noise at boot and in
seucrity output where you have several interfaces symlinked to one
config file.

"If you think this is the right thing to do" deraadt@


# 1.121 09-Jun-2008 todd

warn once not 3 times in case of a non existent file, discussed with deraadt
originally pointed out by Johan Torin


# 1.120 09-Jun-2008 deraadt

Ensure that hostname.* files are also re-chowned to root.wheel at each
boot as discussed with claudio while eating tasty donairs. ok todd


# 1.119 17-Apr-2008 deraadt

before using them, force hostname.* files to be unreadable by world
first version from todd, ok millert


Revision tags: OPENBSD_4_3_BASE
# 1.118 17-Jan-2008 brad

Execute rtsol after turning up trunk(4) and vlan(4) interfaces so they're
taken into consideration for rtsol.

ok reyk@ dlg@


# 1.117 09-Jan-2008 mpf

Do not bring up pfsync(4) before the working ruleset
has been loaded. Otherwise, states that are received during the
initial bulk update mismatch the correct pf-checksum and
do not attach to the rules.
Problem identified by david@. Fix done in collaboration.
OK henning@


Revision tags: OPENBSD_4_2_BASE
# 1.116 02-Aug-2007 david

move the delay for IPv6 DAD to after all interfaces have started
fixes problems with daemons being unable to bind to all addreses at boot
ok itojun@ hshoexer@


Revision tags: OPENBSD_4_1_BASE
# 1.115 15-Nov-2006 itojun

reject multicast packet without scope identifier specified.


Revision tags: OPENBSD_4_0_BASE
# 1.114 29-Jun-2006 todd

do not add an extra space; nwid and description come out wrong
fix as proposed by maja@, thanks!


Revision tags: OPENBSD_3_9_BASE
# 1.113 28-Dec-2005 david

nuke extra whitespace


# 1.112 06-Dec-2005 reyk

multicast_host=YES only works if a valid default gateway is available.
validate this condition and reject multicast traffic on failure.

ok todd@ naddy@


# 1.111 02-Nov-2005 todd

fix inspired by pr#4590
ok krw@


# 1.110 25-Oct-2005 todd

better logic from krw@:
- do not process mygate for v4 if dhcp
- do not process mygate for v6 if rtsol
this also makes the mygate processing logic more readable
ok krw@


# 1.109 14-Oct-2005 todd

add v6 support for /etc/mygate
ok deraadt@ mickey@ krw@
same functionality tested/ok'ed by by mickey, brad, matthieu, and me
with this one may now put a v6 IP in /etc/mygate on a separate line from
the v4 default gateway and netstart will do the right thing


# 1.108 12-Oct-2005 todd

shrink stripcom(), sync with install.sub
ok krw@


# 1.107 04-Oct-2005 todd

trunk must be started after physical ethernet devices, but before vlan.
populate ifmstart lines accordingly.
prodded/tested by brad@
ok reyk@


# 1.106 28-Sep-2005 todd

use eval consistently, fixes description quotes on rtsol and dhcp
fix inspired by and closes pr 4495
ok krw@


Revision tags: OPENBSD_3_8_BASE
# 1.105 22-May-2005 todd

Introduce 'ifmstart' to deal with starting multiple interfaces minus a list
of interfaces.

This reduces the netstart script by 174 chars, 13 words, and 19 lines, but
more importantly, makes it more simple and less cluttered should more special
case/orderings be needed.

ok brad@ and pr 4197 submitter, inspired by and closes pr 4197


# 1.104 04-Apr-2005 djm

unbreak; ok pval@


# 1.103 03-Apr-2005 deraadt

if dhcp is used to get an address on any interface, ignore /etc/mygate
ok krw
(this lets us do something rather cool with the zaurus in particular)


Revision tags: OPENBSD_3_7_BASE
# 1.102 04-Jan-2005 mcbride

Bring up the carp(4) interface before default route.

ok pascoe@ mpf@


# 1.101 30-Dec-2004 millert

Add a copy of stripcom so /etc/netstart can be run standalone again.
OK deraadt@


# 1.100 19-Dec-2004 millert

Allow comments in /etc/{myname,mygate,defaultdomain}; OK deraadt@


# 1.99 04-Dec-2004 itojun

remove "route $hostname 127.0.0.1" line. deraadt ok
*** please update /etc/netstart and test if it works ok for you ***


# 1.98 20-Oct-2004 deraadt

make all route commands use -qn; ok mcbride henning


Revision tags: OPENBSD_3_6_BASE
# 1.97 29-May-2004 deraadt

one last route command lacking -qn


Revision tags: OPENBSD_3_5_BASE
# 1.96 22-Mar-2004 mcbride

Make sure pfsync is brought up before carp.

ok deraadt@


# 1.95 13-Mar-2004 mcbride

Delay pfsync(4) configuration, as the syncif has to be configured in
advance. From Thorsten Lockert.


# 1.94 14-Jan-2004 deraadt

ok, it took quite a bit of prodding but itojun finally explained why the
extra sleep 1 is in here, and we came to the conclusion it is safe to
delete it. whee.


# 1.93 13-Jan-2004 deraadt

repair v6 lo0 documentation


# 1.92 11-Jan-2004 deraadt

add loopback routes late


# 1.91 09-Jan-2004 deraadt

create all routes with -q; markus ok


# 1.90 04-Dec-2003 millert

Need to do "ifconfig create" for bridge interfaces too.


# 1.89 03-Dec-2003 markus

add support for ifconfig clone; from netbsd; ok deraadt, henning


# 1.88 20-Oct-2003 david

delay carp initialization until after physical interfaces are configured
ok mcbride@ henning@ deraadt@ todd@


Revision tags: OPENBSD_3_4_BASE
# 1.87 27-Aug-2003 henning

only try to set hostname to what /etc/myname says if that file actually exists,
otherwise preserve `hostname`
netbooted machines can live perfectly fine without it; they get their hostname
earlier.

ok krw@ cedric@


Revision tags: OPENBSD_3_3_BASE
# 1.86 16-Feb-2003 krw

Fix up some DNS verbiage to make it consistant.

Fix up default route selection by

a) Forcing user to explicitly chose 'dhcp' as a mechanism for
specifying a default route, rather than guessing based on one or more
interfaces being configured by dhcp.

b) If the user specified default route does not work, re-present the
existing default route rather than losing it.

c) Move default route selection to after nameserver activation so the
user can specify a hostname as the default route.

Change /etc/netstart so that /etc/mygate wins if a default route was
already specified (i.e. by dhcp).

ok deraadt@.


Revision tags: OPENBSD_3_2_BASE
# 1.85 16-May-2002 todd

ignore non-existent cases where '$if' evaluates to '*'.
From Andr� Lucas <andre@ae-35.com>, fixes pr # 2658.
'Looks good' from miod@, millert@, and krw@.


Revision tags: OPENBSD_3_1_BASE
# 1.84 23-Feb-2002 deraadt

re-add support for $if expansion; hamajima@nagoya.ydc.co.jp


# 1.83 21-Feb-2002 miod

Change the network components initialization order.
Change from:
o all interfaces
o all bridges
o routes
to:
o physical interfaces
o routes
o gif and gre interfaces
o bridges

Fixeski PR #2400.
Manual page updates coming soon.
Ok angelos@ chris@ deraadt@


Revision tags: OPENBSD_3_0_BASE
# 1.82 31-Jul-2001 hugh

a space before a redirect


# 1.81 06-Jul-2001 angelos

Also, source /etc/rc.conf so we can pull in the
multicast_host/multicast_router settings; this is useful if one
flushes the routing table and re-initializes.

We really need a netconfig tool of sorts.


# 1.80 06-Jul-2001 angelos

Use "route -n show -inet" to determine the default multicast iface.


# 1.79 03-Jul-2001 deraadt

pull in rc.conf early so that pf(1) startup is right; tested by jasoni, comments from millert


# 1.78 30-May-2001 deraadt

Remove ipf. Darren Reed has interpreted his (old, new, whichever)
licence in a way that makes ipf not free according to the rules we
established over 5 years ago, at www.openbsd.org/goals.html (and those
same basic rules govern the other *BSD projects too). Specifically,
Darren says that modified versions are not permitted. But software
which OpenBSD uses and redistributes must be free to all (be they
people or companies), for any purpose they wish to use it, including
modification, use, peeing on, or even integration into baby mulching
machines or atomic bombs to be dropped on Australia. Furthermore, we
know of a number of companies using ipf with modification like us, who
are now in the same situation, and we hope that some of them will work
with us to fill this gap that now exists in OpenBSD (temporarily, we
hope).


Revision tags: OPENBSD_2_9_BASE
# 1.77 13-Mar-2001 deraadt

spelling; maurice@maurice.wan.nl


# 1.76 06-Feb-2001 todd

ignore blank lines in addition to comments
fixes pr#1660 from wilfried@telia.com .. Thanks!


# 1.75 10-Jan-2001 jason

support !command in bridgename.if files, too


# 1.74 27-Nov-2000 millert

Use -n to test if a variable is non-zero. Otherwise, if the variable's
contents start with a '-' test becomes unhappy (since it interprets it
as another option).


# 1.73 08-Nov-2000 todd

This fixes pr 1481, we now handle args > 6 in /etc/hostname.if in the
cases where we did not previously handle them.
Thanks to Scott Atwood <atwood@cs.stanford.edu> for reminding us of this.


Revision tags: OPENBSD_2_8_BASE
# 1.72 02-Sep-2000 todd

subtle bug .. global variables in a while loop need reset 'just incase'
With:
hostname.fxp0 having a last line of:
inet6 alias 3ffe:...
and hostname.gif0 having a first two lines of:
giftunnel 1.2.3.4
dest 1.2.4.3
We end up with the command:
ifconfig gif0 giftunnel alias 1.2.3.4 1.2.4.3
.. which is clearly wrong and fixed by this change


# 1.71 18-Jun-2000 todd

rc.conf now parses ${local_rcconf} internally; closes pr 1259


Revision tags: OPENBSD_2_7_BASE
# 1.70 08-May-2000 todd

fix dhcp 'NONE' ness from install to allow media parsing to work
.. ok deraadt@, millert@


# 1.69 21-Apr-2000 deraadt

rc.conf.local support, inspired by chuck yerkes


# 1.68 04-Apr-2000 millert

Remove the -E flag from ipf as it is implicitly enabled and using
the -E flag here causes the kernel to printf 'IP Filter: already
initialized'.


# 1.67 18-Mar-2000 deraadt

silence all extra route addition printouts


# 1.66 17-Mar-2000 itojun

correct reject route installations for IPv6. improve comments.


# 1.65 12-Mar-2000 itojun

disallow packets to malicious 6to4 prefix, based on
http://playground.iijlab.net/i-d/draft-itojun-ipv6-transition-abuse-00.txt


# 1.64 10-Mar-2000 todd

fix non behavior
with this `!' lines in /etc/hostname.* run even without certain lines
(like a comment) preceeding it.


# 1.63 10-Jan-2000 todd

allow arbitrary commands in /etc/hostname.* files if the line starts with '!'


# 1.62 02-Jan-2000 deraadt

rtsol case can configure the interface up, since it would be nice to finish
DAD before the actual rtsol(8) run happens later. and since it will rtsol,
it is going to be up in any case.


# 1.61 02-Jan-2000 itojun

one more indentation fix.


# 1.60 02-Jan-2000 itojun

indentation fix (todd's part)


# 1.59 02-Jan-2000 todd

fix rtsold case, reset cmd for each iteration!


# 1.58 02-Jan-2000 itojun

allow options after "rtsol".
XXX both "dhcp" and "rtsol" has keyword *down* at the end. is it okay?


# 1.57 02-Jan-2000 itojun

echo "IPv6 autoconf: interfaces" before invoking rtsol.
sleep for net.inet6.ip6.dad_count seconds to ensure that IPv6 DAD is completed.
TODO: rtsold (rc.conf line), manpage


# 1.56 02-Jan-2000 itojun

ipv6 autoconf on hosts (non-routers).

to do this,
1. in sysctl.conf, add these lines:
net.inet6.ip6.forwarding=0
net.inet6.ip6.accept_rtadv=1
2. in hostname.foo, add
rtsol

specifying two or more interfaces with "rtsol" may result in strange
behavior - ipv6 spec does not permit multi-interface node to be autoconfig'ed.


# 1.55 02-Jan-2000 todd

add to hostname.* parsing:
- multiple entries support (read: aliases)
- inet6 support
- support for comments (#)
(look for hostname.if(5) commit for syntax details)


# 1.54 31-Dec-1999 itojun

install IPv6 reject routes only if kernel is capable of IPv6.


# 1.53 09-Dec-1999 itojun

avoid transmitting invalid IPv6 packets out to the wire.


# 1.52 09-Dec-1999 itojun

do not perform IPv6 initialization for loopback interface.
MUST make lo0 up before any IPv6 operations.
it will be considered a pilot error if you don't.
(I prefer to have lo0 initialized automatically)


Revision tags: OPENBSD_2_6_BASE
# 1.51 01-Sep-1999 deraadt

support # characters in bridgename.* files; millert


# 1.50 01-Sep-1999 deraadt

cleanup parsing of hostname.* files, and seperate bridge control into
bridgename.* files; all documented in new hostname.if(5) and
bridgename.if(5) man pages


# 1.49 09-Aug-1999 angelos

Only parse/setup the hostname.foo file if interface foo exists (this
is useful for laptops with different ethernet cards etc.)


Revision tags: OPENBSD_2_5_BASE
# 1.48 29-Mar-1999 niklas

New multicast route setup style


# 1.47 26-Mar-1999 niklas

Add bridge interface handling


# 1.46 01-Mar-1999 millert

Add support in /etc/hostname.xxx for files of the format:
up [options]
Any of the following may or may not be set:
$name $mask $bcaddr $extras


# 1.45 28-Oct-1998 millert

Kill the awful hack used to match and split /etc/hostname.* We now use
a function, isalphanumeric, to determine whether an interface name is
likely to be valid. This means that things like /etc/hostname.le0.bak,
/etc/hostname.le0#, /etc/hostname.le0~, etc. will be ignored as they
should. There is no longer an implicate assumption that /etc/hostname.*
only contains a single '.'.


Revision tags: OPENBSD_2_4_BASE
# 1.44 06-Oct-1998 deraadt

move ipnat to end of netstart, to support dhcp+ipnat


# 1.43 18-Sep-1998 deraadt

apply media directives on dhcp interfaces


# 1.42 10-Sep-1998 marc

better way of handling dhcp client; Jason Ish <jbi130@mail.usask.ca>


# 1.41 08-Sep-1998 marc

dhcp client stuff. "Angelos D. Keromytis" <angelos@dsl.cis.upenn.edu>


# 1.40 24-Aug-1998 downsj

You can't use -interface default when there's no default gateway
set (yet). Use -interface $hostname if mygate doesn't exist so that
this actually works on routers.


# 1.39 04-Jul-1998 deraadt

put 224 route on default, to avoid a hostname lookup


# 1.38 22-May-1998 deraadt

use route -n, what the heck


Revision tags: OPENBSD_2_3_BASE
# 1.37 28-Mar-1998 deraadt

s/^nat/ipnat/


# 1.36 23-Feb-1998 niklas

remove trailing blank line


# 1.35 07-Feb-1998 deraadt

ipforward is in sysctl.conf now


# 1.34 21-Dec-1997 deraadt

ugh


# 1.33 20-Dec-1997 deraadt

ipforwarding option in rc.conf


# 1.32 29-Nov-1997 kstailey

NAT requires IPF


# 1.31 04-Nov-1997 deraadt

kill spaces at ends of lines; m4


Revision tags: OPENBSD_2_2_BASE
# 1.30 14-Oct-1997 deraadt

set hostname/domainname before running rc.conf; m4@umn.edu


# 1.29 04-Sep-1997 deraadt

fork netstart; new child is rc.conf


# 1.28 25-Aug-1997 millert

Explicately pass -host flag to route(8) to avoid confusion with networks.


# 1.27 19-Aug-1997 niklas

Add hook for rpc.lockd, make nfsd flags settable in netstart


# 1.26 31-Jul-1997 downsj

Make quotas optional; wedged into netstart for the time being.
/etc/rc.conf, anyone?


# 1.25 30-Jul-1997 deraadt

do not run routed by default


# 1.24 28-Jul-1997 kstailey

Move configuration of loopback interface to before all other interfaces.
Allows the use of local caching-only nameserver with no "nameserver"
entry in /etc/resolv.conf to configure a route between the hostname
and loopback.


# 1.23 25-Jul-1997 provos

earlier start of keymanagement


# 1.22 24-Jul-1997 deraadt

make amd use /tmp_mnt by default


# 1.21 22-Jul-1997 provos

start the photuris daemon per default. hilfe.


# 1.20 17-Jun-1997 niklas

Put in hooks to start ypserv with flags


# 1.19 17-Jun-1997 niklas

Put in hooks to start rpc.yppasswdd with flags


Revision tags: OPENBSD_2_1_BASE
# 1.18 15-Apr-1997 deraadt

kill route flush until .. hmm kernel routing socket bug or something


# 1.17 09-Apr-1997 kstailey

add NAT startup


# 1.16 07-Apr-1997 rees

flush all old routes before adding new interfaces or routes.
ref: netbsd pr3228/misc, Matthias Scheler


# 1.15 03-Mar-1997 downsj

fix typo


# 1.14 11-Feb-1997 deraadt

add default route before fiddling with loopback route to avoid DNS problems; m4@umn.edu, #97


# 1.13 03-Feb-1997 deraadt

do ifaliases after /usr/bin exists in nfs diskless env; pr#77, matthieu@laas.fr


# 1.12 02-Nov-1996 deraadt

timed off by default


Revision tags: OPENBSD_2_0_BASE
# 1.11 23-Sep-1996 deraadt

rfc1323 variable


# 1.10 04-Sep-1996 deraadt

control portmap, inetd, and lpd from netstart; idea from tqbf@enteract.com


# 1.9 27-Aug-1996 deraadt

224.0.0.0 not 0.0.0.224; from peter@demon.net


# 1.8 18-Jun-1996 deraadt

move std stuff from rc.local to rc


# 1.7 16-Jun-1996 deraadt

install sample commented /etc/ifaliases file; which can now contain #
comments and blank lines. new format is "interface address netmask"
(yes, i changed the order of the entries). inspired by netbsd pr#2474;
gillhaa@ghost.whirlpool.com


# 1.6 02-Jun-1996 tholo

Install a multicast route by default


# 1.5 26-May-1996 deraadt

sync & label


# 1.4 09-Jan-1996 dm

added IP filter to netstat/rc and put examples in /usr/share/ipf


# 1.3 30-Dec-1995 deraadt

from netbsd: start mrouted like routed


# 1.2 18-Dec-1995 deraadt

/etc/ifaliases support by randy@zyzzyva.com


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.198 28-Apr-2018 rpe

Add a proper usage() function.

Suggested by and OK jmc.
OK tb


Revision tags: OPENBSD_6_3_BASE
# 1.197 04-Mar-2018 jmc

when -n is used, no need to spit out "Missing parameters." before
displaying usage();

ok tb


# 1.196 03-Mar-2018 landry

Lowercase 'usage' and group -n with interface in it.
From jmc@, ok tb@


# 1.195 21-Feb-2018 rpe

Tweak comments.

OK tb


# 1.194 19-Feb-2018 rpe

Write warning/error messages to stderr and end them with a fullstop.

OK tb


# 1.193 19-Feb-2018 rpe

- use specific patterns when looping over /etc/hostname.if files
to skip backup or temp files.
- test if the patterns matched actual files
- warn if ifcreate() fails on an interface and continue with the
subsequent interfaces in the list instead of return'ing

OK dlg sthen tb


# 1.192 17-Feb-2018 rpe

- Add descriptions for the new functions ifcreate() and vifscreate()
- In ifcreate() use the exit code of the {} block directly
- In vifscreate(), use the ifconfig -C output directly in the for _vif loop
- Remove superfluous and somewhat confusing comment

OK dlg kn sthen


# 1.191 14-Feb-2018 dlg

create virtual interfaces before starting all interface config.

this resolves an ordering problem when adding pseudo interfaces to bridges

tweaks from kn@
ok mpi@ sthen@


# 1.190 10-Feb-2018 claudio

Remove some special IPv4 in IPv6 mapped prefixes that are already rejected
by the ::0.0.0.0/96 reject route added to deny all IPv4 mapped addresses.
Makes the inet6 routing table almost fit in one screen.
OK benno@


# 1.189 10-Feb-2018 florian

Load RFC 7217 key material and generate if it does not already exist.

Add soii.key to changelist (pointed out by semarie) and mtree/special
(suggest by Craig Skinner).

OK naddy, sthen, rpe, tb


# 1.188 06-Feb-2018 tb

If -n is given, the netstart script should not (try to) set the default
route(s). Simply print the command(s) to be issued instead.

tweak & ok rpe


# 1.187 12-Nov-2017 tb

Remove HN_DIR variable and expand it in the only place it was used. It
currently serves no purpose.

ok rpe, agreement from deraadt and halex


Revision tags: OPENBSD_6_2_BASE
# 1.186 25-Jul-2017 rpe

Finally remove backwards compat code to support the 'rtsol' keyword
in hostname.if(5)

OK mpi@ deraadt@ florian@
OK jmc@ from doc perspective


# 1.185 21-Jul-2017 rpe

Align ifstart() in netstart and install.sub.

- in netstart, rename _file to _hn referencing hostname.if files
- in install.sub switch ifstart() to be used with _if instead of
_hn as parameter

ok krw@ tb@


# 1.184 28-May-2017 awolk

etc/netstart: use colon separator instead of dot with chown

OK jung@, deraadt@, jmc@


# 1.183 07-May-2017 rpe

Change test from [] to [[]] and simplify pattern.

OK tb@, krw@ (for [[]])
Feedback and OK halex@


# 1.182 07-May-2017 rpe

Replace hardcoded script name with ${0##*/}

OK tb@ halex@


# 1.181 01-May-2017 rpe

Revert r1.170 and remove the id==0 check.
The id binary is not available in nfs diskless setups at this point.

reported by Andreas Kusalananda, thanks.
discussed with deraadt@


# 1.180 01-May-2017 rpe

Remove last remnants of rtsol. IPv6 autoconfiguration of interfaces is now
done in ifstart(). Remove ipv6autoconf() and replace rtsolif with a boolean
variable V6_AUTOCONF. Replace dhcpif with a boolean variable V4_DHCPCONF.
Both are later used in defaultroute() to decide whether or not to configre
defaultroutes from /etc/mygate.

OK krw@


# 1.179 30-Apr-2017 mpi

Do not try to delete a default route before adding it.

Now that route are automatically G/C with the address they are attached
to there's no reason to duplicate the kernel's job.

Fix a regression introduced with multipath default routes.

ok deraadt@


# 1.178 25-Apr-2017 rpe

Unbreak netstart for multiple inteface configurations like trunk
or carp. Ensure that the noglob option is disabled at the end of
parse_hn_line() and ifstart().

Reported by Christer Solskogen and Stefan Wollny, thanks!


# 1.177 24-Apr-2017 rpe

Introduce a new function parse_hn_line() that replaces the existing
hostname.if(5) parsing code in ifstart().
Add a -n option to netstart to only print the interface configuration
commands instead of executing them.
Add a HN_DIR variable, that points to the directory of the hostname.if
files (default /etc) that allows for future regression tests.

- add new parse_hn_line() function
- change ifstart()
- rename $if to $_if
- don't ifconfig or ifconfig create if -n option is used
- replace hostname.if(5) parsing code with new parse_hn_line()
- just print configuration commands if -n option is used
- autoconf now happens in ifstart(), remove ifv6autoconf()
- introduce HN_DIR variable for the hostname.if file location
- add handling of the -n option to only print config commands
- ensure -n is only used if interfaces are specified as parameters

Discussed with and positive feedback from many
'commit' deraadt@
OK sthen@


# 1.176 08-Apr-2017 rpe

- localize the if, file and stat variables which also ensures that
variables are not named like commands.
- change test from [] to [[]]

OK tb@ halex@


# 1.175 07-Apr-2017 rpe

Minimize differences in ifstart() function between netstart and
install.sub which makes it easier to spot changes in the future.

- comments and formatting
- quotes on assignments are not needed (netstart)
- remove stray space in test (netstart)
- use $file variable with while-loop (netstart)
- although valid, instead of i use $i in arithmetic test (install.sub)

OK krw@, tb@
Looks good deraadt@


# 1.174 07-Apr-2017 rpe

Align comments of ifstart() function in netstart and install.sub.


# 1.173 07-Apr-2017 rpe

Align comments of stripcom() function in netstart and install.sub.


Revision tags: OPENBSD_6_1_BASE
# 1.172 06-Dec-2016 mpi

Do not lose the default route when netstart(8) is run a second time on
the interface pointed to by the default route.

Since the kernel no longer keep routes with dangling address pointer,
netstart(8) has to re-add the default route when the corresponding ifa
has been deleted and re-created.

deraadt@ points out that even if the previous semantic was not necessarily
better, a script like netstart(8) cannot totally fix the default route
problem.

Regression reported by and fix tested by Hrvoje Popovski.

ksh foo checked by halex@


# 1.171 27-Sep-2016 rzalamena

Delay switch(4) interface start up so it can attach virtual interfaces
like vether(4).

nits from and ok benno@, phessler@


# 1.170 09-Sep-2016 jasper

print a clear error message when not ran as root instead of just falling
through and try whatever it can do with the invoking user's perms

feedback/ok aja@ rpe@


Revision tags: OPENBSD_6_0_BASE
# 1.169 19-Jul-2016 mpi

Do not consider tap(4) a special interface and start if before other
pseudo-interfaces.

This unbreak vlan(4) on top of tap(4) since the refactoring to turn it
MP-safe.

ok claudio@, deraadt@


# 1.168 27-Mar-2016 sthen

Don't delete the 224/4 route in netstart, unless it's being done to ensure that
a -reject route can be added. Restores the ability to set an interface route
before daemons are started, lost during the previous simplification.
ok millert mpi


Revision tags: OPENBSD_5_9_BASE
# 1.167 29-Dec-2015 rpe

Remove backslash, not necessary after '&&'

OK halex@


# 1.166 29-Dec-2015 rpe

Replace last remaining `` with $()

OK halex@


# 1.165 18-Dec-2015 ajacoutot

Drop the now useless multicast setup comment.

prodded by tim@, ok mpi@


# 1.164 17-Dec-2015 ajacoutot

Simplify multicast option handling (10 less lines) by matching /etc/rc behavior
towards other YES|NO options and drop the error warning.


with and ok tim@, ok rpe@ on an earlier diff


# 1.163 05-Dec-2015 mpi

It does not make sense to insert a specific route for 224/4 when the
default one is good enough.

So merge rc.conf(8)'s 'multicast_router' and 'multicast_host' into a
single 'multicast'. If set to YES the reject route for 224/4 is not
inserted by netstart(8).

Manual bits from jmc@

ok henning@, ajacoutot@


# 1.162 12-Nov-2015 rpe

Changes to ifautostart():
- Rename function to ifv6autoconf() to make IPv6 relation clearer
- Localize and rename variables

OK krw@


# 1.161 12-Nov-2015 rpe

Changes to ifmstart():
- Change comments to make it clearer that ifmstart() takes two lists
of interface driver names (of which the second is optional) and not
the actual interface instances.
- Use localized variables and use slightly more verbose names.
- Use continue 2 to skip to the next hostname.if file.
- Use shell pattern @() instead of testing _sif individually.

OK krw@


# 1.160 12-Nov-2015 rpe

Changes to stripcom():
- Align comments with /etc/rc version
- Use localized variables
- Use safer "print -r --" instead of plain echo

Changes to ifstart():
- Tweak comment
- Add usage

OK krw@


# 1.159 01-Nov-2015 rpe

Start the rework of the /etc/netstart shell script.

General changes:
- apply a similar 'style' as used in the installer scripts
- improve comments to be more to the point, remove where code is obvious
- document usage of functions if they have arguments
- rename variables where it improves readability
- replace really old-school shell code with more contemporary idioms

Other changes:
- No need to care about "autoboot" because netstart doesn't inherit the
positional parameters from /etc/rc anymore. /etc/rc executes netstart
instead of sourcing it since r1.439.
- Use simpler for-loop to process list of interfaces with ifstart.

OK halex@


# 1.158 26-Oct-2015 rpe

The hostname variable is not used since r1.99. Remove it and use
stripcom() output directly with the hostname command.

OK deraadt@ krw@


# 1.157 23-Oct-2015 claudio

netstart bits for tap(4)


# 1.156 27-Sep-2015 sthen

Don't print output when setting autoconf on interfaces. Suggested by deraadt,
ok florian@ rpe@


# 1.155 13-Sep-2015 sthen

only print the "IPv6 autoconf" line if there are interfaces to configure
feedback/ok rpe


# 1.154 11-Sep-2015 sthen

Set "inet6 autoconf" individually on interfaces that have rtsol set in
hostname.if, previously netstart tried to configure them all at once
("ifconfig if0 if1 if2 inet6 autoconf"). From Delan Azabani, ok phessler@


Revision tags: OPENBSD_5_8_BASE
# 1.153 20-Jul-2015 rpe

Disable Strict Bourne shell mode for /etc/rc and /etc/netstart to be
able to use ksh syntax within these scripts. This way init doesn't
need to be changed, which starts /etc/rc using /bin/sh and people
can still use "sh /etc/netstart ifname".

Idea from and OK halex@
OK deraadt@ krw@ guenther@


# 1.152 19-Jul-2015 florian

Bring up pflow last as it might send with a source address that is on
any of the other interfaces.
OK deraadt, phessler, benno


# 1.151 19-Jul-2015 rpe

Always source rc.subr to be able to use the rc.conf parsing routine
to get the network related vars from rc.conf. This is even necessary
if netstart is run from within /etc/rc. Remove test of $INRC which
unintentionally evaluated always to true.

problem with previous change found by nigel@
OK sthen@ aja@ halex@


# 1.150 19-Jul-2015 ajacoutot

Revert 1.148 for now until I can talk to rpe@
It introduced a regression reported by nigel@


# 1.149 19-Jul-2015 rpe

Replace test command with [].

OK halex@ krw@


# 1.148 19-Jul-2015 rpe

Ensure, that we source rc.subr and parse rc.conf ONLY if we are not
inside /etc/rc.

With help from and OK halex@, ajacoutot@


# 1.147 18-Jul-2015 rpe

- remove trailing blanks introduced in previous commit
- no space in redirections like </foo or >$bar
- few other minor whitespaces

OK krw@


# 1.146 18-Jul-2015 rpe

Improve comments
- Add comments for functions
- Start comments with capital letters
- End comments with a full stop
- Allow comments to extend up to column 80

OK krw@


# 1.145 06-Jun-2015 florian

Allow rtsol keyword in hostname.if(5) with net.inet6.ip6.forwarding=1.
"inet6 autoconf" was working before and rtsol should behave the same.
OK phessler


Revision tags: OPENBSD_5_7_BASE
# 1.144 03-Dec-2014 florian

The kernel handles rtsol(8) functionality since some time now.
Treat rtsol in hostname.if as a keyword like dhcp and call ifconfig
inet6 autoconf.
"reads good" todd@
OK krw@ (who is *not* an IPv6 person), but I recruited him in his
capacity as an installer person.


# 1.143 28-Sep-2014 claudio

Revert 1.142. Without the down netstart will just print the ifconfig
output because it may end up just calling 'ifconfig $if'. This needs
to be done better and properly tested.


# 1.142 26-Sep-2014 halex

remove explicit 'down' of an interface before starting a dhcp request, thereby
avoiding annoying delays for some switch configurations

ok claudio@ deraadt@

i would add ok phessler@, but it was not valid without an ok krw@


Revision tags: OPENBSD_5_6_BASE
# 1.141 12-Jul-2014 stsp

Fix netstart after autoconf6 change so 'rtsol' lines in hostname.if work again.
found by pelikan@; ok pelikan@ henning@


# 1.140 12-Jul-2014 robert

Make rc.conf a parsed configuration file and stop sourcing it as a shell
script.
From now on rc.conf has a fixed syntax (key=val) and it is not allowed
to add anything to it besides the supported syntax, it all going to be
ignored.

discussed with and help from deraadt@ and halex@


Revision tags: OPENBSD_5_5_BASE
# 1.139 22-Aug-2013 mpi

Like for dhclient, do no create a route to alias addresses via 127.0.0.1.
Our stack is able to tell if the address is local or not.

ok todd@, krw@


Revision tags: OPENBSD_5_4_BASE
# 1.138 20-Mar-2013 todd

fix lies in netstart; replacement wording from halex@
pointed out by Ryan Kavannagh rak at debian dot org


Revision tags: OPENBSD_5_3_BASE
# 1.137 05-Dec-2012 rpe

remove "Invalid interface name" message
requested by krw@

ok halex@


# 1.136 02-Dec-2012 rpe

use the more compact version of the check for ifconfig'able interfaces
from install.sub

with feedback from and ok halex


# 1.135 02-Dec-2012 rpe

- remove isalphanumeric() and replace it with a shell pattern, that
tries a bit harder to identify invalid interface names and in
this case emit an error message.
- use [[ $1 == autoboot ]] to avoid a shell error message due to
possible spaces in first argument
- no change in functionality

discussed with krw and halex
ok ("I like this") krw


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.134 07-Oct-2011 deraadt

The new ypbind changes requires that the domainname be set before
rc.conf is run. There's no real downside.
ok aja


Revision tags: OPENBSD_5_0_BASE
# 1.133 07-Jul-2011 guenther

Eliminate some $? tests by rolling the command into the condition

ok halex@


# 1.132 26-May-2011 mpf

Add svlan(4) startup bits.
From markus@. OK naddy, claudio, reyk.


Revision tags: OPENBSD_4_9_BASE
# 1.131 09-Feb-2011 sobrado

fix an unbalanced parenthesis in a comment; while here, split the comment
in a better place to make it more readable.

ok jmc@ and miod@


Revision tags: OPENBSD_4_8_BASE
# 1.130 16-Jun-2010 todd

permit e.g. -inet6 syntax by slurping all lines not just some
noticed by rhsv6 at hushmail dot com, ok sthen@


Revision tags: OPENBSD_4_7_BASE
# 1.129 12-Jan-2010 henning

when setting up lo0 use 127.0.0.1/8 instead of 127.0.0.1 for clarity and
correctness. it's not 1992 any more, kids. ok mcbride dlg krw


# 1.128 10-Dec-2009 todd

o stop reordering ifconfig arguments (e.g. after 'up ..')
o only stop processing if inet or inet6 lines are malformed
o everything not a specially handled bit is passed to ifconfig unmangled
noticed by several after the move from bridgename.bridge0 -> hostname.bridge0
prodded by deraadt@, tested by and feedback from several
man page bits 'look fine' jmc@


# 1.127 22-Nov-2009 deraadt

Stop supporting bridgename.bridge* files, and move to hostname.bridge*
files. To cope with this change, read about the mv command.
ok claudio todd


# 1.126 17-Sep-2009 simon

change variable i to $i in an expression of ifstart() for consistency
with the rest of the file. no functional change.

feedback from sthen@, ok krw@


# 1.125 10-Jul-2009 jdixon

Delay creation of tun(4) interfaces until the underlying interface and
routes are available. This fixes usage for some OpenVPN users that start
it from hostname.tun*.

Tested by Johan Huldtgren. ok sthen@, johan@.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.124 25-Nov-2008 markus

delay /etc/netstart until IPv6-DAD (dup-address-detection) is completed.
ok fries, hshoexer, claudio


# 1.123 14-Aug-2008 sthen

Tools from /usr may not be used in netstart since it may be NFS-mounted
and not available at that time. Rewrite the hostname.if permission check
to use only /bin/ls and the shell. Requested by deraadt.

ok todd, "Twisted." deraadt


Revision tags: OPENBSD_4_4_BASE
# 1.122 23-Jul-2008 sthen

Prevent warning about insecure hostnames where no /etc/hostname.*
exists. From wcmaier@.

Check target of symbolic links to avoid noise at boot and in
seucrity output where you have several interfaces symlinked to one
config file.

"If you think this is the right thing to do" deraadt@


# 1.121 09-Jun-2008 todd

warn once not 3 times in case of a non existent file, discussed with deraadt
originally pointed out by Johan Torin


# 1.120 09-Jun-2008 deraadt

Ensure that hostname.* files are also re-chowned to root.wheel at each
boot as discussed with claudio while eating tasty donairs. ok todd


# 1.119 17-Apr-2008 deraadt

before using them, force hostname.* files to be unreadable by world
first version from todd, ok millert


Revision tags: OPENBSD_4_3_BASE
# 1.118 17-Jan-2008 brad

Execute rtsol after turning up trunk(4) and vlan(4) interfaces so they're
taken into consideration for rtsol.

ok reyk@ dlg@


# 1.117 09-Jan-2008 mpf

Do not bring up pfsync(4) before the working ruleset
has been loaded. Otherwise, states that are received during the
initial bulk update mismatch the correct pf-checksum and
do not attach to the rules.
Problem identified by david@. Fix done in collaboration.
OK henning@


Revision tags: OPENBSD_4_2_BASE
# 1.116 02-Aug-2007 david

move the delay for IPv6 DAD to after all interfaces have started
fixes problems with daemons being unable to bind to all addreses at boot
ok itojun@ hshoexer@


Revision tags: OPENBSD_4_1_BASE
# 1.115 15-Nov-2006 itojun

reject multicast packet without scope identifier specified.


Revision tags: OPENBSD_4_0_BASE
# 1.114 29-Jun-2006 todd

do not add an extra space; nwid and description come out wrong
fix as proposed by maja@, thanks!


Revision tags: OPENBSD_3_9_BASE
# 1.113 28-Dec-2005 david

nuke extra whitespace


# 1.112 06-Dec-2005 reyk

multicast_host=YES only works if a valid default gateway is available.
validate this condition and reject multicast traffic on failure.

ok todd@ naddy@


# 1.111 02-Nov-2005 todd

fix inspired by pr#4590
ok krw@


# 1.110 25-Oct-2005 todd

better logic from krw@:
- do not process mygate for v4 if dhcp
- do not process mygate for v6 if rtsol
this also makes the mygate processing logic more readable
ok krw@


# 1.109 14-Oct-2005 todd

add v6 support for /etc/mygate
ok deraadt@ mickey@ krw@
same functionality tested/ok'ed by by mickey, brad, matthieu, and me
with this one may now put a v6 IP in /etc/mygate on a separate line from
the v4 default gateway and netstart will do the right thing


# 1.108 12-Oct-2005 todd

shrink stripcom(), sync with install.sub
ok krw@


# 1.107 04-Oct-2005 todd

trunk must be started after physical ethernet devices, but before vlan.
populate ifmstart lines accordingly.
prodded/tested by brad@
ok reyk@


# 1.106 28-Sep-2005 todd

use eval consistently, fixes description quotes on rtsol and dhcp
fix inspired by and closes pr 4495
ok krw@


Revision tags: OPENBSD_3_8_BASE
# 1.105 22-May-2005 todd

Introduce 'ifmstart' to deal with starting multiple interfaces minus a list
of interfaces.

This reduces the netstart script by 174 chars, 13 words, and 19 lines, but
more importantly, makes it more simple and less cluttered should more special
case/orderings be needed.

ok brad@ and pr 4197 submitter, inspired by and closes pr 4197


# 1.104 04-Apr-2005 djm

unbreak; ok pval@


# 1.103 03-Apr-2005 deraadt

if dhcp is used to get an address on any interface, ignore /etc/mygate
ok krw
(this lets us do something rather cool with the zaurus in particular)


Revision tags: OPENBSD_3_7_BASE
# 1.102 04-Jan-2005 mcbride

Bring up the carp(4) interface before default route.

ok pascoe@ mpf@


# 1.101 30-Dec-2004 millert

Add a copy of stripcom so /etc/netstart can be run standalone again.
OK deraadt@


# 1.100 19-Dec-2004 millert

Allow comments in /etc/{myname,mygate,defaultdomain}; OK deraadt@


# 1.99 04-Dec-2004 itojun

remove "route $hostname 127.0.0.1" line. deraadt ok
*** please update /etc/netstart and test if it works ok for you ***


# 1.98 20-Oct-2004 deraadt

make all route commands use -qn; ok mcbride henning


Revision tags: OPENBSD_3_6_BASE
# 1.97 29-May-2004 deraadt

one last route command lacking -qn


Revision tags: OPENBSD_3_5_BASE
# 1.96 22-Mar-2004 mcbride

Make sure pfsync is brought up before carp.

ok deraadt@


# 1.95 13-Mar-2004 mcbride

Delay pfsync(4) configuration, as the syncif has to be configured in
advance. From Thorsten Lockert.


# 1.94 14-Jan-2004 deraadt

ok, it took quite a bit of prodding but itojun finally explained why the
extra sleep 1 is in here, and we came to the conclusion it is safe to
delete it. whee.


# 1.93 13-Jan-2004 deraadt

repair v6 lo0 documentation


# 1.92 11-Jan-2004 deraadt

add loopback routes late


# 1.91 09-Jan-2004 deraadt

create all routes with -q; markus ok


# 1.90 04-Dec-2003 millert

Need to do "ifconfig create" for bridge interfaces too.


# 1.89 03-Dec-2003 markus

add support for ifconfig clone; from netbsd; ok deraadt, henning


# 1.88 20-Oct-2003 david

delay carp initialization until after physical interfaces are configured
ok mcbride@ henning@ deraadt@ todd@


Revision tags: OPENBSD_3_4_BASE
# 1.87 27-Aug-2003 henning

only try to set hostname to what /etc/myname says if that file actually exists,
otherwise preserve `hostname`
netbooted machines can live perfectly fine without it; they get their hostname
earlier.

ok krw@ cedric@


Revision tags: OPENBSD_3_3_BASE
# 1.86 16-Feb-2003 krw

Fix up some DNS verbiage to make it consistant.

Fix up default route selection by

a) Forcing user to explicitly chose 'dhcp' as a mechanism for
specifying a default route, rather than guessing based on one or more
interfaces being configured by dhcp.

b) If the user specified default route does not work, re-present the
existing default route rather than losing it.

c) Move default route selection to after nameserver activation so the
user can specify a hostname as the default route.

Change /etc/netstart so that /etc/mygate wins if a default route was
already specified (i.e. by dhcp).

ok deraadt@.


Revision tags: OPENBSD_3_2_BASE
# 1.85 16-May-2002 todd

ignore non-existent cases where '$if' evaluates to '*'.
From Andr� Lucas <andre@ae-35.com>, fixes pr # 2658.
'Looks good' from miod@, millert@, and krw@.


Revision tags: OPENBSD_3_1_BASE
# 1.84 23-Feb-2002 deraadt

re-add support for $if expansion; hamajima@nagoya.ydc.co.jp


# 1.83 21-Feb-2002 miod

Change the network components initialization order.
Change from:
o all interfaces
o all bridges
o routes
to:
o physical interfaces
o routes
o gif and gre interfaces
o bridges

Fixeski PR #2400.
Manual page updates coming soon.
Ok angelos@ chris@ deraadt@


Revision tags: OPENBSD_3_0_BASE
# 1.82 31-Jul-2001 hugh

a space before a redirect


# 1.81 06-Jul-2001 angelos

Also, source /etc/rc.conf so we can pull in the
multicast_host/multicast_router settings; this is useful if one
flushes the routing table and re-initializes.

We really need a netconfig tool of sorts.


# 1.80 06-Jul-2001 angelos

Use "route -n show -inet" to determine the default multicast iface.


# 1.79 03-Jul-2001 deraadt

pull in rc.conf early so that pf(1) startup is right; tested by jasoni, comments from millert


# 1.78 30-May-2001 deraadt

Remove ipf. Darren Reed has interpreted his (old, new, whichever)
licence in a way that makes ipf not free according to the rules we
established over 5 years ago, at www.openbsd.org/goals.html (and those
same basic rules govern the other *BSD projects too). Specifically,
Darren says that modified versions are not permitted. But software
which OpenBSD uses and redistributes must be free to all (be they
people or companies), for any purpose they wish to use it, including
modification, use, peeing on, or even integration into baby mulching
machines or atomic bombs to be dropped on Australia. Furthermore, we
know of a number of companies using ipf with modification like us, who
are now in the same situation, and we hope that some of them will work
with us to fill this gap that now exists in OpenBSD (temporarily, we
hope).


Revision tags: OPENBSD_2_9_BASE
# 1.77 13-Mar-2001 deraadt

spelling; maurice@maurice.wan.nl


# 1.76 06-Feb-2001 todd

ignore blank lines in addition to comments
fixes pr#1660 from wilfried@telia.com .. Thanks!


# 1.75 10-Jan-2001 jason

support !command in bridgename.if files, too


# 1.74 27-Nov-2000 millert

Use -n to test if a variable is non-zero. Otherwise, if the variable's
contents start with a '-' test becomes unhappy (since it interprets it
as another option).


# 1.73 08-Nov-2000 todd

This fixes pr 1481, we now handle args > 6 in /etc/hostname.if in the
cases where we did not previously handle them.
Thanks to Scott Atwood <atwood@cs.stanford.edu> for reminding us of this.


Revision tags: OPENBSD_2_8_BASE
# 1.72 02-Sep-2000 todd

subtle bug .. global variables in a while loop need reset 'just incase'
With:
hostname.fxp0 having a last line of:
inet6 alias 3ffe:...
and hostname.gif0 having a first two lines of:
giftunnel 1.2.3.4
dest 1.2.4.3
We end up with the command:
ifconfig gif0 giftunnel alias 1.2.3.4 1.2.4.3
.. which is clearly wrong and fixed by this change


# 1.71 18-Jun-2000 todd

rc.conf now parses ${local_rcconf} internally; closes pr 1259


Revision tags: OPENBSD_2_7_BASE
# 1.70 08-May-2000 todd

fix dhcp 'NONE' ness from install to allow media parsing to work
.. ok deraadt@, millert@


# 1.69 21-Apr-2000 deraadt

rc.conf.local support, inspired by chuck yerkes


# 1.68 04-Apr-2000 millert

Remove the -E flag from ipf as it is implicitly enabled and using
the -E flag here causes the kernel to printf 'IP Filter: already
initialized'.


# 1.67 18-Mar-2000 deraadt

silence all extra route addition printouts


# 1.66 17-Mar-2000 itojun

correct reject route installations for IPv6. improve comments.


# 1.65 12-Mar-2000 itojun

disallow packets to malicious 6to4 prefix, based on
http://playground.iijlab.net/i-d/draft-itojun-ipv6-transition-abuse-00.txt


# 1.64 10-Mar-2000 todd

fix non behavior
with this `!' lines in /etc/hostname.* run even without certain lines
(like a comment) preceeding it.


# 1.63 10-Jan-2000 todd

allow arbitrary commands in /etc/hostname.* files if the line starts with '!'


# 1.62 02-Jan-2000 deraadt

rtsol case can configure the interface up, since it would be nice to finish
DAD before the actual rtsol(8) run happens later. and since it will rtsol,
it is going to be up in any case.


# 1.61 02-Jan-2000 itojun

one more indentation fix.


# 1.60 02-Jan-2000 itojun

indentation fix (todd's part)


# 1.59 02-Jan-2000 todd

fix rtsold case, reset cmd for each iteration!


# 1.58 02-Jan-2000 itojun

allow options after "rtsol".
XXX both "dhcp" and "rtsol" has keyword *down* at the end. is it okay?


# 1.57 02-Jan-2000 itojun

echo "IPv6 autoconf: interfaces" before invoking rtsol.
sleep for net.inet6.ip6.dad_count seconds to ensure that IPv6 DAD is completed.
TODO: rtsold (rc.conf line), manpage


# 1.56 02-Jan-2000 itojun

ipv6 autoconf on hosts (non-routers).

to do this,
1. in sysctl.conf, add these lines:
net.inet6.ip6.forwarding=0
net.inet6.ip6.accept_rtadv=1
2. in hostname.foo, add
rtsol

specifying two or more interfaces with "rtsol" may result in strange
behavior - ipv6 spec does not permit multi-interface node to be autoconfig'ed.


# 1.55 02-Jan-2000 todd

add to hostname.* parsing:
- multiple entries support (read: aliases)
- inet6 support
- support for comments (#)
(look for hostname.if(5) commit for syntax details)


# 1.54 31-Dec-1999 itojun

install IPv6 reject routes only if kernel is capable of IPv6.


# 1.53 09-Dec-1999 itojun

avoid transmitting invalid IPv6 packets out to the wire.


# 1.52 09-Dec-1999 itojun

do not perform IPv6 initialization for loopback interface.
MUST make lo0 up before any IPv6 operations.
it will be considered a pilot error if you don't.
(I prefer to have lo0 initialized automatically)


Revision tags: OPENBSD_2_6_BASE
# 1.51 01-Sep-1999 deraadt

support # characters in bridgename.* files; millert


# 1.50 01-Sep-1999 deraadt

cleanup parsing of hostname.* files, and seperate bridge control into
bridgename.* files; all documented in new hostname.if(5) and
bridgename.if(5) man pages


# 1.49 09-Aug-1999 angelos

Only parse/setup the hostname.foo file if interface foo exists (this
is useful for laptops with different ethernet cards etc.)


Revision tags: OPENBSD_2_5_BASE
# 1.48 29-Mar-1999 niklas

New multicast route setup style


# 1.47 26-Mar-1999 niklas

Add bridge interface handling


# 1.46 01-Mar-1999 millert

Add support in /etc/hostname.xxx for files of the format:
up [options]
Any of the following may or may not be set:
$name $mask $bcaddr $extras


# 1.45 28-Oct-1998 millert

Kill the awful hack used to match and split /etc/hostname.* We now use
a function, isalphanumeric, to determine whether an interface name is
likely to be valid. This means that things like /etc/hostname.le0.bak,
/etc/hostname.le0#, /etc/hostname.le0~, etc. will be ignored as they
should. There is no longer an implicate assumption that /etc/hostname.*
only contains a single '.'.


Revision tags: OPENBSD_2_4_BASE
# 1.44 06-Oct-1998 deraadt

move ipnat to end of netstart, to support dhcp+ipnat


# 1.43 18-Sep-1998 deraadt

apply media directives on dhcp interfaces


# 1.42 10-Sep-1998 marc

better way of handling dhcp client; Jason Ish <jbi130@mail.usask.ca>


# 1.41 08-Sep-1998 marc

dhcp client stuff. "Angelos D. Keromytis" <angelos@dsl.cis.upenn.edu>


# 1.40 24-Aug-1998 downsj

You can't use -interface default when there's no default gateway
set (yet). Use -interface $hostname if mygate doesn't exist so that
this actually works on routers.


# 1.39 04-Jul-1998 deraadt

put 224 route on default, to avoid a hostname lookup


# 1.38 22-May-1998 deraadt

use route -n, what the heck


Revision tags: OPENBSD_2_3_BASE
# 1.37 28-Mar-1998 deraadt

s/^nat/ipnat/


# 1.36 23-Feb-1998 niklas

remove trailing blank line


# 1.35 07-Feb-1998 deraadt

ipforward is in sysctl.conf now


# 1.34 21-Dec-1997 deraadt

ugh


# 1.33 20-Dec-1997 deraadt

ipforwarding option in rc.conf


# 1.32 29-Nov-1997 kstailey

NAT requires IPF


# 1.31 04-Nov-1997 deraadt

kill spaces at ends of lines; m4


Revision tags: OPENBSD_2_2_BASE
# 1.30 14-Oct-1997 deraadt

set hostname/domainname before running rc.conf; m4@umn.edu


# 1.29 04-Sep-1997 deraadt

fork netstart; new child is rc.conf


# 1.28 25-Aug-1997 millert

Explicately pass -host flag to route(8) to avoid confusion with networks.


# 1.27 19-Aug-1997 niklas

Add hook for rpc.lockd, make nfsd flags settable in netstart


# 1.26 31-Jul-1997 downsj

Make quotas optional; wedged into netstart for the time being.
/etc/rc.conf, anyone?


# 1.25 30-Jul-1997 deraadt

do not run routed by default


# 1.24 28-Jul-1997 kstailey

Move configuration of loopback interface to before all other interfaces.
Allows the use of local caching-only nameserver with no "nameserver"
entry in /etc/resolv.conf to configure a route between the hostname
and loopback.


# 1.23 25-Jul-1997 provos

earlier start of keymanagement


# 1.22 24-Jul-1997 deraadt

make amd use /tmp_mnt by default


# 1.21 22-Jul-1997 provos

start the photuris daemon per default. hilfe.


# 1.20 17-Jun-1997 niklas

Put in hooks to start ypserv with flags


# 1.19 17-Jun-1997 niklas

Put in hooks to start rpc.yppasswdd with flags


Revision tags: OPENBSD_2_1_BASE
# 1.18 15-Apr-1997 deraadt

kill route flush until .. hmm kernel routing socket bug or something


# 1.17 09-Apr-1997 kstailey

add NAT startup


# 1.16 07-Apr-1997 rees

flush all old routes before adding new interfaces or routes.
ref: netbsd pr3228/misc, Matthias Scheler


# 1.15 03-Mar-1997 downsj

fix typo


# 1.14 11-Feb-1997 deraadt

add default route before fiddling with loopback route to avoid DNS problems; m4@umn.edu, #97


# 1.13 03-Feb-1997 deraadt

do ifaliases after /usr/bin exists in nfs diskless env; pr#77, matthieu@laas.fr


# 1.12 02-Nov-1996 deraadt

timed off by default


Revision tags: OPENBSD_2_0_BASE
# 1.11 23-Sep-1996 deraadt

rfc1323 variable


# 1.10 04-Sep-1996 deraadt

control portmap, inetd, and lpd from netstart; idea from tqbf@enteract.com


# 1.9 27-Aug-1996 deraadt

224.0.0.0 not 0.0.0.224; from peter@demon.net


# 1.8 18-Jun-1996 deraadt

move std stuff from rc.local to rc


# 1.7 16-Jun-1996 deraadt

install sample commented /etc/ifaliases file; which can now contain #
comments and blank lines. new format is "interface address netmask"
(yes, i changed the order of the entries). inspired by netbsd pr#2474;
gillhaa@ghost.whirlpool.com


# 1.6 02-Jun-1996 tholo

Install a multicast route by default


# 1.5 26-May-1996 deraadt

sync & label


# 1.4 09-Jan-1996 dm

added IP filter to netstat/rc and put examples in /usr/share/ipf


# 1.3 30-Dec-1995 deraadt

from netbsd: start mrouted like routed


# 1.2 18-Dec-1995 deraadt

/etc/ifaliases support by randy@zyzzyva.com


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.197 04-Mar-2018 jmc

when -n is used, no need to spit out "Missing parameters." before
displaying usage();

ok tb


# 1.196 03-Mar-2018 landry

Lowercase 'usage' and group -n with interface in it.
From jmc@, ok tb@


# 1.195 21-Feb-2018 rpe

Tweak comments.

OK tb


# 1.194 19-Feb-2018 rpe

Write warning/error messages to stderr and end them with a fullstop.

OK tb


# 1.193 19-Feb-2018 rpe

- use specific patterns when looping over /etc/hostname.if files
to skip backup or temp files.
- test if the patterns matched actual files
- warn if ifcreate() fails on an interface and continue with the
subsequent interfaces in the list instead of return'ing

OK dlg sthen tb


# 1.192 17-Feb-2018 rpe

- Add descriptions for the new functions ifcreate() and vifscreate()
- In ifcreate() use the exit code of the {} block directly
- In vifscreate(), use the ifconfig -C output directly in the for _vif loop
- Remove superfluous and somewhat confusing comment

OK dlg kn sthen


# 1.191 14-Feb-2018 dlg

create virtual interfaces before starting all interface config.

this resolves an ordering problem when adding pseudo interfaces to bridges

tweaks from kn@
ok mpi@ sthen@


# 1.190 10-Feb-2018 claudio

Remove some special IPv4 in IPv6 mapped prefixes that are already rejected
by the ::0.0.0.0/96 reject route added to deny all IPv4 mapped addresses.
Makes the inet6 routing table almost fit in one screen.
OK benno@


# 1.189 10-Feb-2018 florian

Load RFC 7217 key material and generate if it does not already exist.

Add soii.key to changelist (pointed out by semarie) and mtree/special
(suggest by Craig Skinner).

OK naddy, sthen, rpe, tb


# 1.188 06-Feb-2018 tb

If -n is given, the netstart script should not (try to) set the default
route(s). Simply print the command(s) to be issued instead.

tweak & ok rpe


# 1.187 12-Nov-2017 tb

Remove HN_DIR variable and expand it in the only place it was used. It
currently serves no purpose.

ok rpe, agreement from deraadt and halex


Revision tags: OPENBSD_6_2_BASE
# 1.186 25-Jul-2017 rpe

Finally remove backwards compat code to support the 'rtsol' keyword
in hostname.if(5)

OK mpi@ deraadt@ florian@
OK jmc@ from doc perspective


# 1.185 21-Jul-2017 rpe

Align ifstart() in netstart and install.sub.

- in netstart, rename _file to _hn referencing hostname.if files
- in install.sub switch ifstart() to be used with _if instead of
_hn as parameter

ok krw@ tb@


# 1.184 28-May-2017 awolk

etc/netstart: use colon separator instead of dot with chown

OK jung@, deraadt@, jmc@


# 1.183 07-May-2017 rpe

Change test from [] to [[]] and simplify pattern.

OK tb@, krw@ (for [[]])
Feedback and OK halex@


# 1.182 07-May-2017 rpe

Replace hardcoded script name with ${0##*/}

OK tb@ halex@


# 1.181 01-May-2017 rpe

Revert r1.170 and remove the id==0 check.
The id binary is not available in nfs diskless setups at this point.

reported by Andreas Kusalananda, thanks.
discussed with deraadt@


# 1.180 01-May-2017 rpe

Remove last remnants of rtsol. IPv6 autoconfiguration of interfaces is now
done in ifstart(). Remove ipv6autoconf() and replace rtsolif with a boolean
variable V6_AUTOCONF. Replace dhcpif with a boolean variable V4_DHCPCONF.
Both are later used in defaultroute() to decide whether or not to configre
defaultroutes from /etc/mygate.

OK krw@


# 1.179 30-Apr-2017 mpi

Do not try to delete a default route before adding it.

Now that route are automatically G/C with the address they are attached
to there's no reason to duplicate the kernel's job.

Fix a regression introduced with multipath default routes.

ok deraadt@


# 1.178 25-Apr-2017 rpe

Unbreak netstart for multiple inteface configurations like trunk
or carp. Ensure that the noglob option is disabled at the end of
parse_hn_line() and ifstart().

Reported by Christer Solskogen and Stefan Wollny, thanks!


# 1.177 24-Apr-2017 rpe

Introduce a new function parse_hn_line() that replaces the existing
hostname.if(5) parsing code in ifstart().
Add a -n option to netstart to only print the interface configuration
commands instead of executing them.
Add a HN_DIR variable, that points to the directory of the hostname.if
files (default /etc) that allows for future regression tests.

- add new parse_hn_line() function
- change ifstart()
- rename $if to $_if
- don't ifconfig or ifconfig create if -n option is used
- replace hostname.if(5) parsing code with new parse_hn_line()
- just print configuration commands if -n option is used
- autoconf now happens in ifstart(), remove ifv6autoconf()
- introduce HN_DIR variable for the hostname.if file location
- add handling of the -n option to only print config commands
- ensure -n is only used if interfaces are specified as parameters

Discussed with and positive feedback from many
'commit' deraadt@
OK sthen@


# 1.176 08-Apr-2017 rpe

- localize the if, file and stat variables which also ensures that
variables are not named like commands.
- change test from [] to [[]]

OK tb@ halex@


# 1.175 07-Apr-2017 rpe

Minimize differences in ifstart() function between netstart and
install.sub which makes it easier to spot changes in the future.

- comments and formatting
- quotes on assignments are not needed (netstart)
- remove stray space in test (netstart)
- use $file variable with while-loop (netstart)
- although valid, instead of i use $i in arithmetic test (install.sub)

OK krw@, tb@
Looks good deraadt@


# 1.174 07-Apr-2017 rpe

Align comments of ifstart() function in netstart and install.sub.


# 1.173 07-Apr-2017 rpe

Align comments of stripcom() function in netstart and install.sub.


Revision tags: OPENBSD_6_1_BASE
# 1.172 06-Dec-2016 mpi

Do not lose the default route when netstart(8) is run a second time on
the interface pointed to by the default route.

Since the kernel no longer keep routes with dangling address pointer,
netstart(8) has to re-add the default route when the corresponding ifa
has been deleted and re-created.

deraadt@ points out that even if the previous semantic was not necessarily
better, a script like netstart(8) cannot totally fix the default route
problem.

Regression reported by and fix tested by Hrvoje Popovski.

ksh foo checked by halex@


# 1.171 27-Sep-2016 rzalamena

Delay switch(4) interface start up so it can attach virtual interfaces
like vether(4).

nits from and ok benno@, phessler@


# 1.170 09-Sep-2016 jasper

print a clear error message when not ran as root instead of just falling
through and try whatever it can do with the invoking user's perms

feedback/ok aja@ rpe@


Revision tags: OPENBSD_6_0_BASE
# 1.169 19-Jul-2016 mpi

Do not consider tap(4) a special interface and start if before other
pseudo-interfaces.

This unbreak vlan(4) on top of tap(4) since the refactoring to turn it
MP-safe.

ok claudio@, deraadt@


# 1.168 27-Mar-2016 sthen

Don't delete the 224/4 route in netstart, unless it's being done to ensure that
a -reject route can be added. Restores the ability to set an interface route
before daemons are started, lost during the previous simplification.
ok millert mpi


Revision tags: OPENBSD_5_9_BASE
# 1.167 29-Dec-2015 rpe

Remove backslash, not necessary after '&&'

OK halex@


# 1.166 29-Dec-2015 rpe

Replace last remaining `` with $()

OK halex@


# 1.165 18-Dec-2015 ajacoutot

Drop the now useless multicast setup comment.

prodded by tim@, ok mpi@


# 1.164 17-Dec-2015 ajacoutot

Simplify multicast option handling (10 less lines) by matching /etc/rc behavior
towards other YES|NO options and drop the error warning.


with and ok tim@, ok rpe@ on an earlier diff


# 1.163 05-Dec-2015 mpi

It does not make sense to insert a specific route for 224/4 when the
default one is good enough.

So merge rc.conf(8)'s 'multicast_router' and 'multicast_host' into a
single 'multicast'. If set to YES the reject route for 224/4 is not
inserted by netstart(8).

Manual bits from jmc@

ok henning@, ajacoutot@


# 1.162 12-Nov-2015 rpe

Changes to ifautostart():
- Rename function to ifv6autoconf() to make IPv6 relation clearer
- Localize and rename variables

OK krw@


# 1.161 12-Nov-2015 rpe

Changes to ifmstart():
- Change comments to make it clearer that ifmstart() takes two lists
of interface driver names (of which the second is optional) and not
the actual interface instances.
- Use localized variables and use slightly more verbose names.
- Use continue 2 to skip to the next hostname.if file.
- Use shell pattern @() instead of testing _sif individually.

OK krw@


# 1.160 12-Nov-2015 rpe

Changes to stripcom():
- Align comments with /etc/rc version
- Use localized variables
- Use safer "print -r --" instead of plain echo

Changes to ifstart():
- Tweak comment
- Add usage

OK krw@


# 1.159 01-Nov-2015 rpe

Start the rework of the /etc/netstart shell script.

General changes:
- apply a similar 'style' as used in the installer scripts
- improve comments to be more to the point, remove where code is obvious
- document usage of functions if they have arguments
- rename variables where it improves readability
- replace really old-school shell code with more contemporary idioms

Other changes:
- No need to care about "autoboot" because netstart doesn't inherit the
positional parameters from /etc/rc anymore. /etc/rc executes netstart
instead of sourcing it since r1.439.
- Use simpler for-loop to process list of interfaces with ifstart.

OK halex@


# 1.158 26-Oct-2015 rpe

The hostname variable is not used since r1.99. Remove it and use
stripcom() output directly with the hostname command.

OK deraadt@ krw@


# 1.157 23-Oct-2015 claudio

netstart bits for tap(4)


# 1.156 27-Sep-2015 sthen

Don't print output when setting autoconf on interfaces. Suggested by deraadt,
ok florian@ rpe@


# 1.155 13-Sep-2015 sthen

only print the "IPv6 autoconf" line if there are interfaces to configure
feedback/ok rpe


# 1.154 11-Sep-2015 sthen

Set "inet6 autoconf" individually on interfaces that have rtsol set in
hostname.if, previously netstart tried to configure them all at once
("ifconfig if0 if1 if2 inet6 autoconf"). From Delan Azabani, ok phessler@


Revision tags: OPENBSD_5_8_BASE
# 1.153 20-Jul-2015 rpe

Disable Strict Bourne shell mode for /etc/rc and /etc/netstart to be
able to use ksh syntax within these scripts. This way init doesn't
need to be changed, which starts /etc/rc using /bin/sh and people
can still use "sh /etc/netstart ifname".

Idea from and OK halex@
OK deraadt@ krw@ guenther@


# 1.152 19-Jul-2015 florian

Bring up pflow last as it might send with a source address that is on
any of the other interfaces.
OK deraadt, phessler, benno


# 1.151 19-Jul-2015 rpe

Always source rc.subr to be able to use the rc.conf parsing routine
to get the network related vars from rc.conf. This is even necessary
if netstart is run from within /etc/rc. Remove test of $INRC which
unintentionally evaluated always to true.

problem with previous change found by nigel@
OK sthen@ aja@ halex@


# 1.150 19-Jul-2015 ajacoutot

Revert 1.148 for now until I can talk to rpe@
It introduced a regression reported by nigel@


# 1.149 19-Jul-2015 rpe

Replace test command with [].

OK halex@ krw@


# 1.148 19-Jul-2015 rpe

Ensure, that we source rc.subr and parse rc.conf ONLY if we are not
inside /etc/rc.

With help from and OK halex@, ajacoutot@


# 1.147 18-Jul-2015 rpe

- remove trailing blanks introduced in previous commit
- no space in redirections like </foo or >$bar
- few other minor whitespaces

OK krw@


# 1.146 18-Jul-2015 rpe

Improve comments
- Add comments for functions
- Start comments with capital letters
- End comments with a full stop
- Allow comments to extend up to column 80

OK krw@


# 1.145 06-Jun-2015 florian

Allow rtsol keyword in hostname.if(5) with net.inet6.ip6.forwarding=1.
"inet6 autoconf" was working before and rtsol should behave the same.
OK phessler


Revision tags: OPENBSD_5_7_BASE
# 1.144 03-Dec-2014 florian

The kernel handles rtsol(8) functionality since some time now.
Treat rtsol in hostname.if as a keyword like dhcp and call ifconfig
inet6 autoconf.
"reads good" todd@
OK krw@ (who is *not* an IPv6 person), but I recruited him in his
capacity as an installer person.


# 1.143 28-Sep-2014 claudio

Revert 1.142. Without the down netstart will just print the ifconfig
output because it may end up just calling 'ifconfig $if'. This needs
to be done better and properly tested.


# 1.142 26-Sep-2014 halex

remove explicit 'down' of an interface before starting a dhcp request, thereby
avoiding annoying delays for some switch configurations

ok claudio@ deraadt@

i would add ok phessler@, but it was not valid without an ok krw@


Revision tags: OPENBSD_5_6_BASE
# 1.141 12-Jul-2014 stsp

Fix netstart after autoconf6 change so 'rtsol' lines in hostname.if work again.
found by pelikan@; ok pelikan@ henning@


# 1.140 12-Jul-2014 robert

Make rc.conf a parsed configuration file and stop sourcing it as a shell
script.
From now on rc.conf has a fixed syntax (key=val) and it is not allowed
to add anything to it besides the supported syntax, it all going to be
ignored.

discussed with and help from deraadt@ and halex@


Revision tags: OPENBSD_5_5_BASE
# 1.139 22-Aug-2013 mpi

Like for dhclient, do no create a route to alias addresses via 127.0.0.1.
Our stack is able to tell if the address is local or not.

ok todd@, krw@


Revision tags: OPENBSD_5_4_BASE
# 1.138 20-Mar-2013 todd

fix lies in netstart; replacement wording from halex@
pointed out by Ryan Kavannagh rak at debian dot org


Revision tags: OPENBSD_5_3_BASE
# 1.137 05-Dec-2012 rpe

remove "Invalid interface name" message
requested by krw@

ok halex@


# 1.136 02-Dec-2012 rpe

use the more compact version of the check for ifconfig'able interfaces
from install.sub

with feedback from and ok halex


# 1.135 02-Dec-2012 rpe

- remove isalphanumeric() and replace it with a shell pattern, that
tries a bit harder to identify invalid interface names and in
this case emit an error message.
- use [[ $1 == autoboot ]] to avoid a shell error message due to
possible spaces in first argument
- no change in functionality

discussed with krw and halex
ok ("I like this") krw


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.134 07-Oct-2011 deraadt

The new ypbind changes requires that the domainname be set before
rc.conf is run. There's no real downside.
ok aja


Revision tags: OPENBSD_5_0_BASE
# 1.133 07-Jul-2011 guenther

Eliminate some $? tests by rolling the command into the condition

ok halex@


# 1.132 26-May-2011 mpf

Add svlan(4) startup bits.
From markus@. OK naddy, claudio, reyk.


Revision tags: OPENBSD_4_9_BASE
# 1.131 09-Feb-2011 sobrado

fix an unbalanced parenthesis in a comment; while here, split the comment
in a better place to make it more readable.

ok jmc@ and miod@


Revision tags: OPENBSD_4_8_BASE
# 1.130 16-Jun-2010 todd

permit e.g. -inet6 syntax by slurping all lines not just some
noticed by rhsv6 at hushmail dot com, ok sthen@


Revision tags: OPENBSD_4_7_BASE
# 1.129 12-Jan-2010 henning

when setting up lo0 use 127.0.0.1/8 instead of 127.0.0.1 for clarity and
correctness. it's not 1992 any more, kids. ok mcbride dlg krw


# 1.128 10-Dec-2009 todd

o stop reordering ifconfig arguments (e.g. after 'up ..')
o only stop processing if inet or inet6 lines are malformed
o everything not a specially handled bit is passed to ifconfig unmangled
noticed by several after the move from bridgename.bridge0 -> hostname.bridge0
prodded by deraadt@, tested by and feedback from several
man page bits 'look fine' jmc@


# 1.127 22-Nov-2009 deraadt

Stop supporting bridgename.bridge* files, and move to hostname.bridge*
files. To cope with this change, read about the mv command.
ok claudio todd


# 1.126 17-Sep-2009 simon

change variable i to $i in an expression of ifstart() for consistency
with the rest of the file. no functional change.

feedback from sthen@, ok krw@


# 1.125 10-Jul-2009 jdixon

Delay creation of tun(4) interfaces until the underlying interface and
routes are available. This fixes usage for some OpenVPN users that start
it from hostname.tun*.

Tested by Johan Huldtgren. ok sthen@, johan@.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.124 25-Nov-2008 markus

delay /etc/netstart until IPv6-DAD (dup-address-detection) is completed.
ok fries, hshoexer, claudio


# 1.123 14-Aug-2008 sthen

Tools from /usr may not be used in netstart since it may be NFS-mounted
and not available at that time. Rewrite the hostname.if permission check
to use only /bin/ls and the shell. Requested by deraadt.

ok todd, "Twisted." deraadt


Revision tags: OPENBSD_4_4_BASE
# 1.122 23-Jul-2008 sthen

Prevent warning about insecure hostnames where no /etc/hostname.*
exists. From wcmaier@.

Check target of symbolic links to avoid noise at boot and in
seucrity output where you have several interfaces symlinked to one
config file.

"If you think this is the right thing to do" deraadt@


# 1.121 09-Jun-2008 todd

warn once not 3 times in case of a non existent file, discussed with deraadt
originally pointed out by Johan Torin


# 1.120 09-Jun-2008 deraadt

Ensure that hostname.* files are also re-chowned to root.wheel at each
boot as discussed with claudio while eating tasty donairs. ok todd


# 1.119 17-Apr-2008 deraadt

before using them, force hostname.* files to be unreadable by world
first version from todd, ok millert


Revision tags: OPENBSD_4_3_BASE
# 1.118 17-Jan-2008 brad

Execute rtsol after turning up trunk(4) and vlan(4) interfaces so they're
taken into consideration for rtsol.

ok reyk@ dlg@


# 1.117 09-Jan-2008 mpf

Do not bring up pfsync(4) before the working ruleset
has been loaded. Otherwise, states that are received during the
initial bulk update mismatch the correct pf-checksum and
do not attach to the rules.
Problem identified by david@. Fix done in collaboration.
OK henning@


Revision tags: OPENBSD_4_2_BASE
# 1.116 02-Aug-2007 david

move the delay for IPv6 DAD to after all interfaces have started
fixes problems with daemons being unable to bind to all addreses at boot
ok itojun@ hshoexer@


Revision tags: OPENBSD_4_1_BASE
# 1.115 15-Nov-2006 itojun

reject multicast packet without scope identifier specified.


Revision tags: OPENBSD_4_0_BASE
# 1.114 29-Jun-2006 todd

do not add an extra space; nwid and description come out wrong
fix as proposed by maja@, thanks!


Revision tags: OPENBSD_3_9_BASE
# 1.113 28-Dec-2005 david

nuke extra whitespace


# 1.112 06-Dec-2005 reyk

multicast_host=YES only works if a valid default gateway is available.
validate this condition and reject multicast traffic on failure.

ok todd@ naddy@


# 1.111 02-Nov-2005 todd

fix inspired by pr#4590
ok krw@


# 1.110 25-Oct-2005 todd

better logic from krw@:
- do not process mygate for v4 if dhcp
- do not process mygate for v6 if rtsol
this also makes the mygate processing logic more readable
ok krw@


# 1.109 14-Oct-2005 todd

add v6 support for /etc/mygate
ok deraadt@ mickey@ krw@
same functionality tested/ok'ed by by mickey, brad, matthieu, and me
with this one may now put a v6 IP in /etc/mygate on a separate line from
the v4 default gateway and netstart will do the right thing


# 1.108 12-Oct-2005 todd

shrink stripcom(), sync with install.sub
ok krw@


# 1.107 04-Oct-2005 todd

trunk must be started after physical ethernet devices, but before vlan.
populate ifmstart lines accordingly.
prodded/tested by brad@
ok reyk@


# 1.106 28-Sep-2005 todd

use eval consistently, fixes description quotes on rtsol and dhcp
fix inspired by and closes pr 4495
ok krw@


Revision tags: OPENBSD_3_8_BASE
# 1.105 22-May-2005 todd

Introduce 'ifmstart' to deal with starting multiple interfaces minus a list
of interfaces.

This reduces the netstart script by 174 chars, 13 words, and 19 lines, but
more importantly, makes it more simple and less cluttered should more special
case/orderings be needed.

ok brad@ and pr 4197 submitter, inspired by and closes pr 4197


# 1.104 04-Apr-2005 djm

unbreak; ok pval@


# 1.103 03-Apr-2005 deraadt

if dhcp is used to get an address on any interface, ignore /etc/mygate
ok krw
(this lets us do something rather cool with the zaurus in particular)


Revision tags: OPENBSD_3_7_BASE
# 1.102 04-Jan-2005 mcbride

Bring up the carp(4) interface before default route.

ok pascoe@ mpf@


# 1.101 30-Dec-2004 millert

Add a copy of stripcom so /etc/netstart can be run standalone again.
OK deraadt@


# 1.100 19-Dec-2004 millert

Allow comments in /etc/{myname,mygate,defaultdomain}; OK deraadt@


# 1.99 04-Dec-2004 itojun

remove "route $hostname 127.0.0.1" line. deraadt ok
*** please update /etc/netstart and test if it works ok for you ***


# 1.98 20-Oct-2004 deraadt

make all route commands use -qn; ok mcbride henning


Revision tags: OPENBSD_3_6_BASE
# 1.97 29-May-2004 deraadt

one last route command lacking -qn


Revision tags: OPENBSD_3_5_BASE
# 1.96 22-Mar-2004 mcbride

Make sure pfsync is brought up before carp.

ok deraadt@


# 1.95 13-Mar-2004 mcbride

Delay pfsync(4) configuration, as the syncif has to be configured in
advance. From Thorsten Lockert.


# 1.94 14-Jan-2004 deraadt

ok, it took quite a bit of prodding but itojun finally explained why the
extra sleep 1 is in here, and we came to the conclusion it is safe to
delete it. whee.


# 1.93 13-Jan-2004 deraadt

repair v6 lo0 documentation


# 1.92 11-Jan-2004 deraadt

add loopback routes late


# 1.91 09-Jan-2004 deraadt

create all routes with -q; markus ok


# 1.90 04-Dec-2003 millert

Need to do "ifconfig create" for bridge interfaces too.


# 1.89 03-Dec-2003 markus

add support for ifconfig clone; from netbsd; ok deraadt, henning


# 1.88 20-Oct-2003 david

delay carp initialization until after physical interfaces are configured
ok mcbride@ henning@ deraadt@ todd@


Revision tags: OPENBSD_3_4_BASE
# 1.87 27-Aug-2003 henning

only try to set hostname to what /etc/myname says if that file actually exists,
otherwise preserve `hostname`
netbooted machines can live perfectly fine without it; they get their hostname
earlier.

ok krw@ cedric@


Revision tags: OPENBSD_3_3_BASE
# 1.86 16-Feb-2003 krw

Fix up some DNS verbiage to make it consistant.

Fix up default route selection by

a) Forcing user to explicitly chose 'dhcp' as a mechanism for
specifying a default route, rather than guessing based on one or more
interfaces being configured by dhcp.

b) If the user specified default route does not work, re-present the
existing default route rather than losing it.

c) Move default route selection to after nameserver activation so the
user can specify a hostname as the default route.

Change /etc/netstart so that /etc/mygate wins if a default route was
already specified (i.e. by dhcp).

ok deraadt@.


Revision tags: OPENBSD_3_2_BASE
# 1.85 16-May-2002 todd

ignore non-existent cases where '$if' evaluates to '*'.
From Andr� Lucas <andre@ae-35.com>, fixes pr # 2658.
'Looks good' from miod@, millert@, and krw@.


Revision tags: OPENBSD_3_1_BASE
# 1.84 23-Feb-2002 deraadt

re-add support for $if expansion; hamajima@nagoya.ydc.co.jp


# 1.83 21-Feb-2002 miod

Change the network components initialization order.
Change from:
o all interfaces
o all bridges
o routes
to:
o physical interfaces
o routes
o gif and gre interfaces
o bridges

Fixeski PR #2400.
Manual page updates coming soon.
Ok angelos@ chris@ deraadt@


Revision tags: OPENBSD_3_0_BASE
# 1.82 31-Jul-2001 hugh

a space before a redirect


# 1.81 06-Jul-2001 angelos

Also, source /etc/rc.conf so we can pull in the
multicast_host/multicast_router settings; this is useful if one
flushes the routing table and re-initializes.

We really need a netconfig tool of sorts.


# 1.80 06-Jul-2001 angelos

Use "route -n show -inet" to determine the default multicast iface.


# 1.79 03-Jul-2001 deraadt

pull in rc.conf early so that pf(1) startup is right; tested by jasoni, comments from millert


# 1.78 30-May-2001 deraadt

Remove ipf. Darren Reed has interpreted his (old, new, whichever)
licence in a way that makes ipf not free according to the rules we
established over 5 years ago, at www.openbsd.org/goals.html (and those
same basic rules govern the other *BSD projects too). Specifically,
Darren says that modified versions are not permitted. But software
which OpenBSD uses and redistributes must be free to all (be they
people or companies), for any purpose they wish to use it, including
modification, use, peeing on, or even integration into baby mulching
machines or atomic bombs to be dropped on Australia. Furthermore, we
know of a number of companies using ipf with modification like us, who
are now in the same situation, and we hope that some of them will work
with us to fill this gap that now exists in OpenBSD (temporarily, we
hope).


Revision tags: OPENBSD_2_9_BASE
# 1.77 13-Mar-2001 deraadt

spelling; maurice@maurice.wan.nl


# 1.76 06-Feb-2001 todd

ignore blank lines in addition to comments
fixes pr#1660 from wilfried@telia.com .. Thanks!


# 1.75 10-Jan-2001 jason

support !command in bridgename.if files, too


# 1.74 27-Nov-2000 millert

Use -n to test if a variable is non-zero. Otherwise, if the variable's
contents start with a '-' test becomes unhappy (since it interprets it
as another option).


# 1.73 08-Nov-2000 todd

This fixes pr 1481, we now handle args > 6 in /etc/hostname.if in the
cases where we did not previously handle them.
Thanks to Scott Atwood <atwood@cs.stanford.edu> for reminding us of this.


Revision tags: OPENBSD_2_8_BASE
# 1.72 02-Sep-2000 todd

subtle bug .. global variables in a while loop need reset 'just incase'
With:
hostname.fxp0 having a last line of:
inet6 alias 3ffe:...
and hostname.gif0 having a first two lines of:
giftunnel 1.2.3.4
dest 1.2.4.3
We end up with the command:
ifconfig gif0 giftunnel alias 1.2.3.4 1.2.4.3
.. which is clearly wrong and fixed by this change


# 1.71 18-Jun-2000 todd

rc.conf now parses ${local_rcconf} internally; closes pr 1259


Revision tags: OPENBSD_2_7_BASE
# 1.70 08-May-2000 todd

fix dhcp 'NONE' ness from install to allow media parsing to work
.. ok deraadt@, millert@


# 1.69 21-Apr-2000 deraadt

rc.conf.local support, inspired by chuck yerkes


# 1.68 04-Apr-2000 millert

Remove the -E flag from ipf as it is implicitly enabled and using
the -E flag here causes the kernel to printf 'IP Filter: already
initialized'.


# 1.67 18-Mar-2000 deraadt

silence all extra route addition printouts


# 1.66 17-Mar-2000 itojun

correct reject route installations for IPv6. improve comments.


# 1.65 12-Mar-2000 itojun

disallow packets to malicious 6to4 prefix, based on
http://playground.iijlab.net/i-d/draft-itojun-ipv6-transition-abuse-00.txt


# 1.64 10-Mar-2000 todd

fix non behavior
with this `!' lines in /etc/hostname.* run even without certain lines
(like a comment) preceeding it.


# 1.63 10-Jan-2000 todd

allow arbitrary commands in /etc/hostname.* files if the line starts with '!'


# 1.62 02-Jan-2000 deraadt

rtsol case can configure the interface up, since it would be nice to finish
DAD before the actual rtsol(8) run happens later. and since it will rtsol,
it is going to be up in any case.


# 1.61 02-Jan-2000 itojun

one more indentation fix.


# 1.60 02-Jan-2000 itojun

indentation fix (todd's part)


# 1.59 02-Jan-2000 todd

fix rtsold case, reset cmd for each iteration!


# 1.58 02-Jan-2000 itojun

allow options after "rtsol".
XXX both "dhcp" and "rtsol" has keyword *down* at the end. is it okay?


# 1.57 02-Jan-2000 itojun

echo "IPv6 autoconf: interfaces" before invoking rtsol.
sleep for net.inet6.ip6.dad_count seconds to ensure that IPv6 DAD is completed.
TODO: rtsold (rc.conf line), manpage


# 1.56 02-Jan-2000 itojun

ipv6 autoconf on hosts (non-routers).

to do this,
1. in sysctl.conf, add these lines:
net.inet6.ip6.forwarding=0
net.inet6.ip6.accept_rtadv=1
2. in hostname.foo, add
rtsol

specifying two or more interfaces with "rtsol" may result in strange
behavior - ipv6 spec does not permit multi-interface node to be autoconfig'ed.


# 1.55 02-Jan-2000 todd

add to hostname.* parsing:
- multiple entries support (read: aliases)
- inet6 support
- support for comments (#)
(look for hostname.if(5) commit for syntax details)


# 1.54 31-Dec-1999 itojun

install IPv6 reject routes only if kernel is capable of IPv6.


# 1.53 09-Dec-1999 itojun

avoid transmitting invalid IPv6 packets out to the wire.


# 1.52 09-Dec-1999 itojun

do not perform IPv6 initialization for loopback interface.
MUST make lo0 up before any IPv6 operations.
it will be considered a pilot error if you don't.
(I prefer to have lo0 initialized automatically)


Revision tags: OPENBSD_2_6_BASE
# 1.51 01-Sep-1999 deraadt

support # characters in bridgename.* files; millert


# 1.50 01-Sep-1999 deraadt

cleanup parsing of hostname.* files, and seperate bridge control into
bridgename.* files; all documented in new hostname.if(5) and
bridgename.if(5) man pages


# 1.49 09-Aug-1999 angelos

Only parse/setup the hostname.foo file if interface foo exists (this
is useful for laptops with different ethernet cards etc.)


Revision tags: OPENBSD_2_5_BASE
# 1.48 29-Mar-1999 niklas

New multicast route setup style


# 1.47 26-Mar-1999 niklas

Add bridge interface handling


# 1.46 01-Mar-1999 millert

Add support in /etc/hostname.xxx for files of the format:
up [options]
Any of the following may or may not be set:
$name $mask $bcaddr $extras


# 1.45 28-Oct-1998 millert

Kill the awful hack used to match and split /etc/hostname.* We now use
a function, isalphanumeric, to determine whether an interface name is
likely to be valid. This means that things like /etc/hostname.le0.bak,
/etc/hostname.le0#, /etc/hostname.le0~, etc. will be ignored as they
should. There is no longer an implicate assumption that /etc/hostname.*
only contains a single '.'.


Revision tags: OPENBSD_2_4_BASE
# 1.44 06-Oct-1998 deraadt

move ipnat to end of netstart, to support dhcp+ipnat


# 1.43 18-Sep-1998 deraadt

apply media directives on dhcp interfaces


# 1.42 10-Sep-1998 marc

better way of handling dhcp client; Jason Ish <jbi130@mail.usask.ca>


# 1.41 08-Sep-1998 marc

dhcp client stuff. "Angelos D. Keromytis" <angelos@dsl.cis.upenn.edu>


# 1.40 24-Aug-1998 downsj

You can't use -interface default when there's no default gateway
set (yet). Use -interface $hostname if mygate doesn't exist so that
this actually works on routers.


# 1.39 04-Jul-1998 deraadt

put 224 route on default, to avoid a hostname lookup


# 1.38 22-May-1998 deraadt

use route -n, what the heck


Revision tags: OPENBSD_2_3_BASE
# 1.37 28-Mar-1998 deraadt

s/^nat/ipnat/


# 1.36 23-Feb-1998 niklas

remove trailing blank line


# 1.35 07-Feb-1998 deraadt

ipforward is in sysctl.conf now


# 1.34 21-Dec-1997 deraadt

ugh


# 1.33 20-Dec-1997 deraadt

ipforwarding option in rc.conf


# 1.32 29-Nov-1997 kstailey

NAT requires IPF


# 1.31 04-Nov-1997 deraadt

kill spaces at ends of lines; m4


Revision tags: OPENBSD_2_2_BASE
# 1.30 14-Oct-1997 deraadt

set hostname/domainname before running rc.conf; m4@umn.edu


# 1.29 04-Sep-1997 deraadt

fork netstart; new child is rc.conf


# 1.28 25-Aug-1997 millert

Explicately pass -host flag to route(8) to avoid confusion with networks.


# 1.27 19-Aug-1997 niklas

Add hook for rpc.lockd, make nfsd flags settable in netstart


# 1.26 31-Jul-1997 downsj

Make quotas optional; wedged into netstart for the time being.
/etc/rc.conf, anyone?


# 1.25 30-Jul-1997 deraadt

do not run routed by default


# 1.24 28-Jul-1997 kstailey

Move configuration of loopback interface to before all other interfaces.
Allows the use of local caching-only nameserver with no "nameserver"
entry in /etc/resolv.conf to configure a route between the hostname
and loopback.


# 1.23 25-Jul-1997 provos

earlier start of keymanagement


# 1.22 24-Jul-1997 deraadt

make amd use /tmp_mnt by default


# 1.21 22-Jul-1997 provos

start the photuris daemon per default. hilfe.


# 1.20 17-Jun-1997 niklas

Put in hooks to start ypserv with flags


# 1.19 17-Jun-1997 niklas

Put in hooks to start rpc.yppasswdd with flags


Revision tags: OPENBSD_2_1_BASE
# 1.18 15-Apr-1997 deraadt

kill route flush until .. hmm kernel routing socket bug or something


# 1.17 09-Apr-1997 kstailey

add NAT startup


# 1.16 07-Apr-1997 rees

flush all old routes before adding new interfaces or routes.
ref: netbsd pr3228/misc, Matthias Scheler


# 1.15 03-Mar-1997 downsj

fix typo


# 1.14 11-Feb-1997 deraadt

add default route before fiddling with loopback route to avoid DNS problems; m4@umn.edu, #97


# 1.13 03-Feb-1997 deraadt

do ifaliases after /usr/bin exists in nfs diskless env; pr#77, matthieu@laas.fr


# 1.12 02-Nov-1996 deraadt

timed off by default


Revision tags: OPENBSD_2_0_BASE
# 1.11 23-Sep-1996 deraadt

rfc1323 variable


# 1.10 04-Sep-1996 deraadt

control portmap, inetd, and lpd from netstart; idea from tqbf@enteract.com


# 1.9 27-Aug-1996 deraadt

224.0.0.0 not 0.0.0.224; from peter@demon.net


# 1.8 18-Jun-1996 deraadt

move std stuff from rc.local to rc


# 1.7 16-Jun-1996 deraadt

install sample commented /etc/ifaliases file; which can now contain #
comments and blank lines. new format is "interface address netmask"
(yes, i changed the order of the entries). inspired by netbsd pr#2474;
gillhaa@ghost.whirlpool.com


# 1.6 02-Jun-1996 tholo

Install a multicast route by default


# 1.5 26-May-1996 deraadt

sync & label


# 1.4 09-Jan-1996 dm

added IP filter to netstat/rc and put examples in /usr/share/ipf


# 1.3 30-Dec-1995 deraadt

from netbsd: start mrouted like routed


# 1.2 18-Dec-1995 deraadt

/etc/ifaliases support by randy@zyzzyva.com


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.196 03-Mar-2018 landry

Lowercase 'usage' and group -n with interface in it.
From jmc@, ok tb@


# 1.195 21-Feb-2018 rpe

Tweak comments.

OK tb


# 1.194 19-Feb-2018 rpe

Write warning/error messages to stderr and end them with a fullstop.

OK tb


# 1.193 19-Feb-2018 rpe

- use specific patterns when looping over /etc/hostname.if files
to skip backup or temp files.
- test if the patterns matched actual files
- warn if ifcreate() fails on an interface and continue with the
subsequent interfaces in the list instead of return'ing

OK dlg sthen tb


# 1.192 17-Feb-2018 rpe

- Add descriptions for the new functions ifcreate() and vifscreate()
- In ifcreate() use the exit code of the {} block directly
- In vifscreate(), use the ifconfig -C output directly in the for _vif loop
- Remove superfluous and somewhat confusing comment

OK dlg kn sthen


# 1.191 14-Feb-2018 dlg

create virtual interfaces before starting all interface config.

this resolves an ordering problem when adding pseudo interfaces to bridges

tweaks from kn@
ok mpi@ sthen@


# 1.190 10-Feb-2018 claudio

Remove some special IPv4 in IPv6 mapped prefixes that are already rejected
by the ::0.0.0.0/96 reject route added to deny all IPv4 mapped addresses.
Makes the inet6 routing table almost fit in one screen.
OK benno@


# 1.189 10-Feb-2018 florian

Load RFC 7217 key material and generate if it does not already exist.

Add soii.key to changelist (pointed out by semarie) and mtree/special
(suggest by Craig Skinner).

OK naddy, sthen, rpe, tb


# 1.188 06-Feb-2018 tb

If -n is given, the netstart script should not (try to) set the default
route(s). Simply print the command(s) to be issued instead.

tweak & ok rpe


# 1.187 12-Nov-2017 tb

Remove HN_DIR variable and expand it in the only place it was used. It
currently serves no purpose.

ok rpe, agreement from deraadt and halex


Revision tags: OPENBSD_6_2_BASE
# 1.186 25-Jul-2017 rpe

Finally remove backwards compat code to support the 'rtsol' keyword
in hostname.if(5)

OK mpi@ deraadt@ florian@
OK jmc@ from doc perspective


# 1.185 21-Jul-2017 rpe

Align ifstart() in netstart and install.sub.

- in netstart, rename _file to _hn referencing hostname.if files
- in install.sub switch ifstart() to be used with _if instead of
_hn as parameter

ok krw@ tb@


# 1.184 28-May-2017 awolk

etc/netstart: use colon separator instead of dot with chown

OK jung@, deraadt@, jmc@


# 1.183 07-May-2017 rpe

Change test from [] to [[]] and simplify pattern.

OK tb@, krw@ (for [[]])
Feedback and OK halex@


# 1.182 07-May-2017 rpe

Replace hardcoded script name with ${0##*/}

OK tb@ halex@


# 1.181 01-May-2017 rpe

Revert r1.170 and remove the id==0 check.
The id binary is not available in nfs diskless setups at this point.

reported by Andreas Kusalananda, thanks.
discussed with deraadt@


# 1.180 01-May-2017 rpe

Remove last remnants of rtsol. IPv6 autoconfiguration of interfaces is now
done in ifstart(). Remove ipv6autoconf() and replace rtsolif with a boolean
variable V6_AUTOCONF. Replace dhcpif with a boolean variable V4_DHCPCONF.
Both are later used in defaultroute() to decide whether or not to configre
defaultroutes from /etc/mygate.

OK krw@


# 1.179 30-Apr-2017 mpi

Do not try to delete a default route before adding it.

Now that route are automatically G/C with the address they are attached
to there's no reason to duplicate the kernel's job.

Fix a regression introduced with multipath default routes.

ok deraadt@


# 1.178 25-Apr-2017 rpe

Unbreak netstart for multiple inteface configurations like trunk
or carp. Ensure that the noglob option is disabled at the end of
parse_hn_line() and ifstart().

Reported by Christer Solskogen and Stefan Wollny, thanks!


# 1.177 24-Apr-2017 rpe

Introduce a new function parse_hn_line() that replaces the existing
hostname.if(5) parsing code in ifstart().
Add a -n option to netstart to only print the interface configuration
commands instead of executing them.
Add a HN_DIR variable, that points to the directory of the hostname.if
files (default /etc) that allows for future regression tests.

- add new parse_hn_line() function
- change ifstart()
- rename $if to $_if
- don't ifconfig or ifconfig create if -n option is used
- replace hostname.if(5) parsing code with new parse_hn_line()
- just print configuration commands if -n option is used
- autoconf now happens in ifstart(), remove ifv6autoconf()
- introduce HN_DIR variable for the hostname.if file location
- add handling of the -n option to only print config commands
- ensure -n is only used if interfaces are specified as parameters

Discussed with and positive feedback from many
'commit' deraadt@
OK sthen@


# 1.176 08-Apr-2017 rpe

- localize the if, file and stat variables which also ensures that
variables are not named like commands.
- change test from [] to [[]]

OK tb@ halex@


# 1.175 07-Apr-2017 rpe

Minimize differences in ifstart() function between netstart and
install.sub which makes it easier to spot changes in the future.

- comments and formatting
- quotes on assignments are not needed (netstart)
- remove stray space in test (netstart)
- use $file variable with while-loop (netstart)
- although valid, instead of i use $i in arithmetic test (install.sub)

OK krw@, tb@
Looks good deraadt@


# 1.174 07-Apr-2017 rpe

Align comments of ifstart() function in netstart and install.sub.


# 1.173 07-Apr-2017 rpe

Align comments of stripcom() function in netstart and install.sub.


Revision tags: OPENBSD_6_1_BASE
# 1.172 06-Dec-2016 mpi

Do not lose the default route when netstart(8) is run a second time on
the interface pointed to by the default route.

Since the kernel no longer keep routes with dangling address pointer,
netstart(8) has to re-add the default route when the corresponding ifa
has been deleted and re-created.

deraadt@ points out that even if the previous semantic was not necessarily
better, a script like netstart(8) cannot totally fix the default route
problem.

Regression reported by and fix tested by Hrvoje Popovski.

ksh foo checked by halex@


# 1.171 27-Sep-2016 rzalamena

Delay switch(4) interface start up so it can attach virtual interfaces
like vether(4).

nits from and ok benno@, phessler@


# 1.170 09-Sep-2016 jasper

print a clear error message when not ran as root instead of just falling
through and try whatever it can do with the invoking user's perms

feedback/ok aja@ rpe@


Revision tags: OPENBSD_6_0_BASE
# 1.169 19-Jul-2016 mpi

Do not consider tap(4) a special interface and start if before other
pseudo-interfaces.

This unbreak vlan(4) on top of tap(4) since the refactoring to turn it
MP-safe.

ok claudio@, deraadt@


# 1.168 27-Mar-2016 sthen

Don't delete the 224/4 route in netstart, unless it's being done to ensure that
a -reject route can be added. Restores the ability to set an interface route
before daemons are started, lost during the previous simplification.
ok millert mpi


Revision tags: OPENBSD_5_9_BASE
# 1.167 29-Dec-2015 rpe

Remove backslash, not necessary after '&&'

OK halex@


# 1.166 29-Dec-2015 rpe

Replace last remaining `` with $()

OK halex@


# 1.165 18-Dec-2015 ajacoutot

Drop the now useless multicast setup comment.

prodded by tim@, ok mpi@


# 1.164 17-Dec-2015 ajacoutot

Simplify multicast option handling (10 less lines) by matching /etc/rc behavior
towards other YES|NO options and drop the error warning.


with and ok tim@, ok rpe@ on an earlier diff


# 1.163 05-Dec-2015 mpi

It does not make sense to insert a specific route for 224/4 when the
default one is good enough.

So merge rc.conf(8)'s 'multicast_router' and 'multicast_host' into a
single 'multicast'. If set to YES the reject route for 224/4 is not
inserted by netstart(8).

Manual bits from jmc@

ok henning@, ajacoutot@


# 1.162 12-Nov-2015 rpe

Changes to ifautostart():
- Rename function to ifv6autoconf() to make IPv6 relation clearer
- Localize and rename variables

OK krw@


# 1.161 12-Nov-2015 rpe

Changes to ifmstart():
- Change comments to make it clearer that ifmstart() takes two lists
of interface driver names (of which the second is optional) and not
the actual interface instances.
- Use localized variables and use slightly more verbose names.
- Use continue 2 to skip to the next hostname.if file.
- Use shell pattern @() instead of testing _sif individually.

OK krw@


# 1.160 12-Nov-2015 rpe

Changes to stripcom():
- Align comments with /etc/rc version
- Use localized variables
- Use safer "print -r --" instead of plain echo

Changes to ifstart():
- Tweak comment
- Add usage

OK krw@


# 1.159 01-Nov-2015 rpe

Start the rework of the /etc/netstart shell script.

General changes:
- apply a similar 'style' as used in the installer scripts
- improve comments to be more to the point, remove where code is obvious
- document usage of functions if they have arguments
- rename variables where it improves readability
- replace really old-school shell code with more contemporary idioms

Other changes:
- No need to care about "autoboot" because netstart doesn't inherit the
positional parameters from /etc/rc anymore. /etc/rc executes netstart
instead of sourcing it since r1.439.
- Use simpler for-loop to process list of interfaces with ifstart.

OK halex@


# 1.158 26-Oct-2015 rpe

The hostname variable is not used since r1.99. Remove it and use
stripcom() output directly with the hostname command.

OK deraadt@ krw@


# 1.157 23-Oct-2015 claudio

netstart bits for tap(4)


# 1.156 27-Sep-2015 sthen

Don't print output when setting autoconf on interfaces. Suggested by deraadt,
ok florian@ rpe@


# 1.155 13-Sep-2015 sthen

only print the "IPv6 autoconf" line if there are interfaces to configure
feedback/ok rpe


# 1.154 11-Sep-2015 sthen

Set "inet6 autoconf" individually on interfaces that have rtsol set in
hostname.if, previously netstart tried to configure them all at once
("ifconfig if0 if1 if2 inet6 autoconf"). From Delan Azabani, ok phessler@


Revision tags: OPENBSD_5_8_BASE
# 1.153 20-Jul-2015 rpe

Disable Strict Bourne shell mode for /etc/rc and /etc/netstart to be
able to use ksh syntax within these scripts. This way init doesn't
need to be changed, which starts /etc/rc using /bin/sh and people
can still use "sh /etc/netstart ifname".

Idea from and OK halex@
OK deraadt@ krw@ guenther@


# 1.152 19-Jul-2015 florian

Bring up pflow last as it might send with a source address that is on
any of the other interfaces.
OK deraadt, phessler, benno


# 1.151 19-Jul-2015 rpe

Always source rc.subr to be able to use the rc.conf parsing routine
to get the network related vars from rc.conf. This is even necessary
if netstart is run from within /etc/rc. Remove test of $INRC which
unintentionally evaluated always to true.

problem with previous change found by nigel@
OK sthen@ aja@ halex@


# 1.150 19-Jul-2015 ajacoutot

Revert 1.148 for now until I can talk to rpe@
It introduced a regression reported by nigel@


# 1.149 19-Jul-2015 rpe

Replace test command with [].

OK halex@ krw@


# 1.148 19-Jul-2015 rpe

Ensure, that we source rc.subr and parse rc.conf ONLY if we are not
inside /etc/rc.

With help from and OK halex@, ajacoutot@


# 1.147 18-Jul-2015 rpe

- remove trailing blanks introduced in previous commit
- no space in redirections like </foo or >$bar
- few other minor whitespaces

OK krw@


# 1.146 18-Jul-2015 rpe

Improve comments
- Add comments for functions
- Start comments with capital letters
- End comments with a full stop
- Allow comments to extend up to column 80

OK krw@


# 1.145 06-Jun-2015 florian

Allow rtsol keyword in hostname.if(5) with net.inet6.ip6.forwarding=1.
"inet6 autoconf" was working before and rtsol should behave the same.
OK phessler


Revision tags: OPENBSD_5_7_BASE
# 1.144 03-Dec-2014 florian

The kernel handles rtsol(8) functionality since some time now.
Treat rtsol in hostname.if as a keyword like dhcp and call ifconfig
inet6 autoconf.
"reads good" todd@
OK krw@ (who is *not* an IPv6 person), but I recruited him in his
capacity as an installer person.


# 1.143 28-Sep-2014 claudio

Revert 1.142. Without the down netstart will just print the ifconfig
output because it may end up just calling 'ifconfig $if'. This needs
to be done better and properly tested.


# 1.142 26-Sep-2014 halex

remove explicit 'down' of an interface before starting a dhcp request, thereby
avoiding annoying delays for some switch configurations

ok claudio@ deraadt@

i would add ok phessler@, but it was not valid without an ok krw@


Revision tags: OPENBSD_5_6_BASE
# 1.141 12-Jul-2014 stsp

Fix netstart after autoconf6 change so 'rtsol' lines in hostname.if work again.
found by pelikan@; ok pelikan@ henning@


# 1.140 12-Jul-2014 robert

Make rc.conf a parsed configuration file and stop sourcing it as a shell
script.
From now on rc.conf has a fixed syntax (key=val) and it is not allowed
to add anything to it besides the supported syntax, it all going to be
ignored.

discussed with and help from deraadt@ and halex@


Revision tags: OPENBSD_5_5_BASE
# 1.139 22-Aug-2013 mpi

Like for dhclient, do no create a route to alias addresses via 127.0.0.1.
Our stack is able to tell if the address is local or not.

ok todd@, krw@


Revision tags: OPENBSD_5_4_BASE
# 1.138 20-Mar-2013 todd

fix lies in netstart; replacement wording from halex@
pointed out by Ryan Kavannagh rak at debian dot org


Revision tags: OPENBSD_5_3_BASE
# 1.137 05-Dec-2012 rpe

remove "Invalid interface name" message
requested by krw@

ok halex@


# 1.136 02-Dec-2012 rpe

use the more compact version of the check for ifconfig'able interfaces
from install.sub

with feedback from and ok halex


# 1.135 02-Dec-2012 rpe

- remove isalphanumeric() and replace it with a shell pattern, that
tries a bit harder to identify invalid interface names and in
this case emit an error message.
- use [[ $1 == autoboot ]] to avoid a shell error message due to
possible spaces in first argument
- no change in functionality

discussed with krw and halex
ok ("I like this") krw


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.134 07-Oct-2011 deraadt

The new ypbind changes requires that the domainname be set before
rc.conf is run. There's no real downside.
ok aja


Revision tags: OPENBSD_5_0_BASE
# 1.133 07-Jul-2011 guenther

Eliminate some $? tests by rolling the command into the condition

ok halex@


# 1.132 26-May-2011 mpf

Add svlan(4) startup bits.
From markus@. OK naddy, claudio, reyk.


Revision tags: OPENBSD_4_9_BASE
# 1.131 09-Feb-2011 sobrado

fix an unbalanced parenthesis in a comment; while here, split the comment
in a better place to make it more readable.

ok jmc@ and miod@


Revision tags: OPENBSD_4_8_BASE
# 1.130 16-Jun-2010 todd

permit e.g. -inet6 syntax by slurping all lines not just some
noticed by rhsv6 at hushmail dot com, ok sthen@


Revision tags: OPENBSD_4_7_BASE
# 1.129 12-Jan-2010 henning

when setting up lo0 use 127.0.0.1/8 instead of 127.0.0.1 for clarity and
correctness. it's not 1992 any more, kids. ok mcbride dlg krw


# 1.128 10-Dec-2009 todd

o stop reordering ifconfig arguments (e.g. after 'up ..')
o only stop processing if inet or inet6 lines are malformed
o everything not a specially handled bit is passed to ifconfig unmangled
noticed by several after the move from bridgename.bridge0 -> hostname.bridge0
prodded by deraadt@, tested by and feedback from several
man page bits 'look fine' jmc@


# 1.127 22-Nov-2009 deraadt

Stop supporting bridgename.bridge* files, and move to hostname.bridge*
files. To cope with this change, read about the mv command.
ok claudio todd


# 1.126 17-Sep-2009 simon

change variable i to $i in an expression of ifstart() for consistency
with the rest of the file. no functional change.

feedback from sthen@, ok krw@


# 1.125 10-Jul-2009 jdixon

Delay creation of tun(4) interfaces until the underlying interface and
routes are available. This fixes usage for some OpenVPN users that start
it from hostname.tun*.

Tested by Johan Huldtgren. ok sthen@, johan@.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.124 25-Nov-2008 markus

delay /etc/netstart until IPv6-DAD (dup-address-detection) is completed.
ok fries, hshoexer, claudio


# 1.123 14-Aug-2008 sthen

Tools from /usr may not be used in netstart since it may be NFS-mounted
and not available at that time. Rewrite the hostname.if permission check
to use only /bin/ls and the shell. Requested by deraadt.

ok todd, "Twisted." deraadt


Revision tags: OPENBSD_4_4_BASE
# 1.122 23-Jul-2008 sthen

Prevent warning about insecure hostnames where no /etc/hostname.*
exists. From wcmaier@.

Check target of symbolic links to avoid noise at boot and in
seucrity output where you have several interfaces symlinked to one
config file.

"If you think this is the right thing to do" deraadt@


# 1.121 09-Jun-2008 todd

warn once not 3 times in case of a non existent file, discussed with deraadt
originally pointed out by Johan Torin


# 1.120 09-Jun-2008 deraadt

Ensure that hostname.* files are also re-chowned to root.wheel at each
boot as discussed with claudio while eating tasty donairs. ok todd


# 1.119 17-Apr-2008 deraadt

before using them, force hostname.* files to be unreadable by world
first version from todd, ok millert


Revision tags: OPENBSD_4_3_BASE
# 1.118 17-Jan-2008 brad

Execute rtsol after turning up trunk(4) and vlan(4) interfaces so they're
taken into consideration for rtsol.

ok reyk@ dlg@


# 1.117 09-Jan-2008 mpf

Do not bring up pfsync(4) before the working ruleset
has been loaded. Otherwise, states that are received during the
initial bulk update mismatch the correct pf-checksum and
do not attach to the rules.
Problem identified by david@. Fix done in collaboration.
OK henning@


Revision tags: OPENBSD_4_2_BASE
# 1.116 02-Aug-2007 david

move the delay for IPv6 DAD to after all interfaces have started
fixes problems with daemons being unable to bind to all addreses at boot
ok itojun@ hshoexer@


Revision tags: OPENBSD_4_1_BASE
# 1.115 15-Nov-2006 itojun

reject multicast packet without scope identifier specified.


Revision tags: OPENBSD_4_0_BASE
# 1.114 29-Jun-2006 todd

do not add an extra space; nwid and description come out wrong
fix as proposed by maja@, thanks!


Revision tags: OPENBSD_3_9_BASE
# 1.113 28-Dec-2005 david

nuke extra whitespace


# 1.112 06-Dec-2005 reyk

multicast_host=YES only works if a valid default gateway is available.
validate this condition and reject multicast traffic on failure.

ok todd@ naddy@


# 1.111 02-Nov-2005 todd

fix inspired by pr#4590
ok krw@


# 1.110 25-Oct-2005 todd

better logic from krw@:
- do not process mygate for v4 if dhcp
- do not process mygate for v6 if rtsol
this also makes the mygate processing logic more readable
ok krw@


# 1.109 14-Oct-2005 todd

add v6 support for /etc/mygate
ok deraadt@ mickey@ krw@
same functionality tested/ok'ed by by mickey, brad, matthieu, and me
with this one may now put a v6 IP in /etc/mygate on a separate line from
the v4 default gateway and netstart will do the right thing


# 1.108 12-Oct-2005 todd

shrink stripcom(), sync with install.sub
ok krw@


# 1.107 04-Oct-2005 todd

trunk must be started after physical ethernet devices, but before vlan.
populate ifmstart lines accordingly.
prodded/tested by brad@
ok reyk@


# 1.106 28-Sep-2005 todd

use eval consistently, fixes description quotes on rtsol and dhcp
fix inspired by and closes pr 4495
ok krw@


Revision tags: OPENBSD_3_8_BASE
# 1.105 22-May-2005 todd

Introduce 'ifmstart' to deal with starting multiple interfaces minus a list
of interfaces.

This reduces the netstart script by 174 chars, 13 words, and 19 lines, but
more importantly, makes it more simple and less cluttered should more special
case/orderings be needed.

ok brad@ and pr 4197 submitter, inspired by and closes pr 4197


# 1.104 04-Apr-2005 djm

unbreak; ok pval@


# 1.103 03-Apr-2005 deraadt

if dhcp is used to get an address on any interface, ignore /etc/mygate
ok krw
(this lets us do something rather cool with the zaurus in particular)


Revision tags: OPENBSD_3_7_BASE
# 1.102 04-Jan-2005 mcbride

Bring up the carp(4) interface before default route.

ok pascoe@ mpf@


# 1.101 30-Dec-2004 millert

Add a copy of stripcom so /etc/netstart can be run standalone again.
OK deraadt@


# 1.100 19-Dec-2004 millert

Allow comments in /etc/{myname,mygate,defaultdomain}; OK deraadt@


# 1.99 04-Dec-2004 itojun

remove "route $hostname 127.0.0.1" line. deraadt ok
*** please update /etc/netstart and test if it works ok for you ***


# 1.98 20-Oct-2004 deraadt

make all route commands use -qn; ok mcbride henning


Revision tags: OPENBSD_3_6_BASE
# 1.97 29-May-2004 deraadt

one last route command lacking -qn


Revision tags: OPENBSD_3_5_BASE
# 1.96 22-Mar-2004 mcbride

Make sure pfsync is brought up before carp.

ok deraadt@


# 1.95 13-Mar-2004 mcbride

Delay pfsync(4) configuration, as the syncif has to be configured in
advance. From Thorsten Lockert.


# 1.94 14-Jan-2004 deraadt

ok, it took quite a bit of prodding but itojun finally explained why the
extra sleep 1 is in here, and we came to the conclusion it is safe to
delete it. whee.


# 1.93 13-Jan-2004 deraadt

repair v6 lo0 documentation


# 1.92 11-Jan-2004 deraadt

add loopback routes late


# 1.91 09-Jan-2004 deraadt

create all routes with -q; markus ok


# 1.90 04-Dec-2003 millert

Need to do "ifconfig create" for bridge interfaces too.


# 1.89 03-Dec-2003 markus

add support for ifconfig clone; from netbsd; ok deraadt, henning


# 1.88 20-Oct-2003 david

delay carp initialization until after physical interfaces are configured
ok mcbride@ henning@ deraadt@ todd@


Revision tags: OPENBSD_3_4_BASE
# 1.87 27-Aug-2003 henning

only try to set hostname to what /etc/myname says if that file actually exists,
otherwise preserve `hostname`
netbooted machines can live perfectly fine without it; they get their hostname
earlier.

ok krw@ cedric@


Revision tags: OPENBSD_3_3_BASE
# 1.86 16-Feb-2003 krw

Fix up some DNS verbiage to make it consistant.

Fix up default route selection by

a) Forcing user to explicitly chose 'dhcp' as a mechanism for
specifying a default route, rather than guessing based on one or more
interfaces being configured by dhcp.

b) If the user specified default route does not work, re-present the
existing default route rather than losing it.

c) Move default route selection to after nameserver activation so the
user can specify a hostname as the default route.

Change /etc/netstart so that /etc/mygate wins if a default route was
already specified (i.e. by dhcp).

ok deraadt@.


Revision tags: OPENBSD_3_2_BASE
# 1.85 16-May-2002 todd

ignore non-existent cases where '$if' evaluates to '*'.
From Andr� Lucas <andre@ae-35.com>, fixes pr # 2658.
'Looks good' from miod@, millert@, and krw@.


Revision tags: OPENBSD_3_1_BASE
# 1.84 23-Feb-2002 deraadt

re-add support for $if expansion; hamajima@nagoya.ydc.co.jp


# 1.83 21-Feb-2002 miod

Change the network components initialization order.
Change from:
o all interfaces
o all bridges
o routes
to:
o physical interfaces
o routes
o gif and gre interfaces
o bridges

Fixeski PR #2400.
Manual page updates coming soon.
Ok angelos@ chris@ deraadt@


Revision tags: OPENBSD_3_0_BASE
# 1.82 31-Jul-2001 hugh

a space before a redirect


# 1.81 06-Jul-2001 angelos

Also, source /etc/rc.conf so we can pull in the
multicast_host/multicast_router settings; this is useful if one
flushes the routing table and re-initializes.

We really need a netconfig tool of sorts.


# 1.80 06-Jul-2001 angelos

Use "route -n show -inet" to determine the default multicast iface.


# 1.79 03-Jul-2001 deraadt

pull in rc.conf early so that pf(1) startup is right; tested by jasoni, comments from millert


# 1.78 30-May-2001 deraadt

Remove ipf. Darren Reed has interpreted his (old, new, whichever)
licence in a way that makes ipf not free according to the rules we
established over 5 years ago, at www.openbsd.org/goals.html (and those
same basic rules govern the other *BSD projects too). Specifically,
Darren says that modified versions are not permitted. But software
which OpenBSD uses and redistributes must be free to all (be they
people or companies), for any purpose they wish to use it, including
modification, use, peeing on, or even integration into baby mulching
machines or atomic bombs to be dropped on Australia. Furthermore, we
know of a number of companies using ipf with modification like us, who
are now in the same situation, and we hope that some of them will work
with us to fill this gap that now exists in OpenBSD (temporarily, we
hope).


Revision tags: OPENBSD_2_9_BASE
# 1.77 13-Mar-2001 deraadt

spelling; maurice@maurice.wan.nl


# 1.76 06-Feb-2001 todd

ignore blank lines in addition to comments
fixes pr#1660 from wilfried@telia.com .. Thanks!


# 1.75 10-Jan-2001 jason

support !command in bridgename.if files, too


# 1.74 27-Nov-2000 millert

Use -n to test if a variable is non-zero. Otherwise, if the variable's
contents start with a '-' test becomes unhappy (since it interprets it
as another option).


# 1.73 08-Nov-2000 todd

This fixes pr 1481, we now handle args > 6 in /etc/hostname.if in the
cases where we did not previously handle them.
Thanks to Scott Atwood <atwood@cs.stanford.edu> for reminding us of this.


Revision tags: OPENBSD_2_8_BASE
# 1.72 02-Sep-2000 todd

subtle bug .. global variables in a while loop need reset 'just incase'
With:
hostname.fxp0 having a last line of:
inet6 alias 3ffe:...
and hostname.gif0 having a first two lines of:
giftunnel 1.2.3.4
dest 1.2.4.3
We end up with the command:
ifconfig gif0 giftunnel alias 1.2.3.4 1.2.4.3
.. which is clearly wrong and fixed by this change


# 1.71 18-Jun-2000 todd

rc.conf now parses ${local_rcconf} internally; closes pr 1259


Revision tags: OPENBSD_2_7_BASE
# 1.70 08-May-2000 todd

fix dhcp 'NONE' ness from install to allow media parsing to work
.. ok deraadt@, millert@


# 1.69 21-Apr-2000 deraadt

rc.conf.local support, inspired by chuck yerkes


# 1.68 04-Apr-2000 millert

Remove the -E flag from ipf as it is implicitly enabled and using
the -E flag here causes the kernel to printf 'IP Filter: already
initialized'.


# 1.67 18-Mar-2000 deraadt

silence all extra route addition printouts


# 1.66 17-Mar-2000 itojun

correct reject route installations for IPv6. improve comments.


# 1.65 12-Mar-2000 itojun

disallow packets to malicious 6to4 prefix, based on
http://playground.iijlab.net/i-d/draft-itojun-ipv6-transition-abuse-00.txt


# 1.64 10-Mar-2000 todd

fix non behavior
with this `!' lines in /etc/hostname.* run even without certain lines
(like a comment) preceeding it.


# 1.63 10-Jan-2000 todd

allow arbitrary commands in /etc/hostname.* files if the line starts with '!'


# 1.62 02-Jan-2000 deraadt

rtsol case can configure the interface up, since it would be nice to finish
DAD before the actual rtsol(8) run happens later. and since it will rtsol,
it is going to be up in any case.


# 1.61 02-Jan-2000 itojun

one more indentation fix.


# 1.60 02-Jan-2000 itojun

indentation fix (todd's part)


# 1.59 02-Jan-2000 todd

fix rtsold case, reset cmd for each iteration!


# 1.58 02-Jan-2000 itojun

allow options after "rtsol".
XXX both "dhcp" and "rtsol" has keyword *down* at the end. is it okay?


# 1.57 02-Jan-2000 itojun

echo "IPv6 autoconf: interfaces" before invoking rtsol.
sleep for net.inet6.ip6.dad_count seconds to ensure that IPv6 DAD is completed.
TODO: rtsold (rc.conf line), manpage


# 1.56 02-Jan-2000 itojun

ipv6 autoconf on hosts (non-routers).

to do this,
1. in sysctl.conf, add these lines:
net.inet6.ip6.forwarding=0
net.inet6.ip6.accept_rtadv=1
2. in hostname.foo, add
rtsol

specifying two or more interfaces with "rtsol" may result in strange
behavior - ipv6 spec does not permit multi-interface node to be autoconfig'ed.


# 1.55 02-Jan-2000 todd

add to hostname.* parsing:
- multiple entries support (read: aliases)
- inet6 support
- support for comments (#)
(look for hostname.if(5) commit for syntax details)


# 1.54 31-Dec-1999 itojun

install IPv6 reject routes only if kernel is capable of IPv6.


# 1.53 09-Dec-1999 itojun

avoid transmitting invalid IPv6 packets out to the wire.


# 1.52 09-Dec-1999 itojun

do not perform IPv6 initialization for loopback interface.
MUST make lo0 up before any IPv6 operations.
it will be considered a pilot error if you don't.
(I prefer to have lo0 initialized automatically)


Revision tags: OPENBSD_2_6_BASE
# 1.51 01-Sep-1999 deraadt

support # characters in bridgename.* files; millert


# 1.50 01-Sep-1999 deraadt

cleanup parsing of hostname.* files, and seperate bridge control into
bridgename.* files; all documented in new hostname.if(5) and
bridgename.if(5) man pages


# 1.49 09-Aug-1999 angelos

Only parse/setup the hostname.foo file if interface foo exists (this
is useful for laptops with different ethernet cards etc.)


Revision tags: OPENBSD_2_5_BASE
# 1.48 29-Mar-1999 niklas

New multicast route setup style


# 1.47 26-Mar-1999 niklas

Add bridge interface handling


# 1.46 01-Mar-1999 millert

Add support in /etc/hostname.xxx for files of the format:
up [options]
Any of the following may or may not be set:
$name $mask $bcaddr $extras


# 1.45 28-Oct-1998 millert

Kill the awful hack used to match and split /etc/hostname.* We now use
a function, isalphanumeric, to determine whether an interface name is
likely to be valid. This means that things like /etc/hostname.le0.bak,
/etc/hostname.le0#, /etc/hostname.le0~, etc. will be ignored as they
should. There is no longer an implicate assumption that /etc/hostname.*
only contains a single '.'.


Revision tags: OPENBSD_2_4_BASE
# 1.44 06-Oct-1998 deraadt

move ipnat to end of netstart, to support dhcp+ipnat


# 1.43 18-Sep-1998 deraadt

apply media directives on dhcp interfaces


# 1.42 10-Sep-1998 marc

better way of handling dhcp client; Jason Ish <jbi130@mail.usask.ca>


# 1.41 08-Sep-1998 marc

dhcp client stuff. "Angelos D. Keromytis" <angelos@dsl.cis.upenn.edu>


# 1.40 24-Aug-1998 downsj

You can't use -interface default when there's no default gateway
set (yet). Use -interface $hostname if mygate doesn't exist so that
this actually works on routers.


# 1.39 04-Jul-1998 deraadt

put 224 route on default, to avoid a hostname lookup


# 1.38 22-May-1998 deraadt

use route -n, what the heck


Revision tags: OPENBSD_2_3_BASE
# 1.37 28-Mar-1998 deraadt

s/^nat/ipnat/


# 1.36 23-Feb-1998 niklas

remove trailing blank line


# 1.35 07-Feb-1998 deraadt

ipforward is in sysctl.conf now


# 1.34 21-Dec-1997 deraadt

ugh


# 1.33 20-Dec-1997 deraadt

ipforwarding option in rc.conf


# 1.32 29-Nov-1997 kstailey

NAT requires IPF


# 1.31 04-Nov-1997 deraadt

kill spaces at ends of lines; m4


Revision tags: OPENBSD_2_2_BASE
# 1.30 14-Oct-1997 deraadt

set hostname/domainname before running rc.conf; m4@umn.edu


# 1.29 04-Sep-1997 deraadt

fork netstart; new child is rc.conf


# 1.28 25-Aug-1997 millert

Explicately pass -host flag to route(8) to avoid confusion with networks.


# 1.27 19-Aug-1997 niklas

Add hook for rpc.lockd, make nfsd flags settable in netstart


# 1.26 31-Jul-1997 downsj

Make quotas optional; wedged into netstart for the time being.
/etc/rc.conf, anyone?


# 1.25 30-Jul-1997 deraadt

do not run routed by default


# 1.24 28-Jul-1997 kstailey

Move configuration of loopback interface to before all other interfaces.
Allows the use of local caching-only nameserver with no "nameserver"
entry in /etc/resolv.conf to configure a route between the hostname
and loopback.


# 1.23 25-Jul-1997 provos

earlier start of keymanagement


# 1.22 24-Jul-1997 deraadt

make amd use /tmp_mnt by default


# 1.21 22-Jul-1997 provos

start the photuris daemon per default. hilfe.


# 1.20 17-Jun-1997 niklas

Put in hooks to start ypserv with flags


# 1.19 17-Jun-1997 niklas

Put in hooks to start rpc.yppasswdd with flags


Revision tags: OPENBSD_2_1_BASE
# 1.18 15-Apr-1997 deraadt

kill route flush until .. hmm kernel routing socket bug or something


# 1.17 09-Apr-1997 kstailey

add NAT startup


# 1.16 07-Apr-1997 rees

flush all old routes before adding new interfaces or routes.
ref: netbsd pr3228/misc, Matthias Scheler


# 1.15 03-Mar-1997 downsj

fix typo


# 1.14 11-Feb-1997 deraadt

add default route before fiddling with loopback route to avoid DNS problems; m4@umn.edu, #97


# 1.13 03-Feb-1997 deraadt

do ifaliases after /usr/bin exists in nfs diskless env; pr#77, matthieu@laas.fr


# 1.12 02-Nov-1996 deraadt

timed off by default


Revision tags: OPENBSD_2_0_BASE
# 1.11 23-Sep-1996 deraadt

rfc1323 variable


# 1.10 04-Sep-1996 deraadt

control portmap, inetd, and lpd from netstart; idea from tqbf@enteract.com


# 1.9 27-Aug-1996 deraadt

224.0.0.0 not 0.0.0.224; from peter@demon.net


# 1.8 18-Jun-1996 deraadt

move std stuff from rc.local to rc


# 1.7 16-Jun-1996 deraadt

install sample commented /etc/ifaliases file; which can now contain #
comments and blank lines. new format is "interface address netmask"
(yes, i changed the order of the entries). inspired by netbsd pr#2474;
gillhaa@ghost.whirlpool.com


# 1.6 02-Jun-1996 tholo

Install a multicast route by default


# 1.5 26-May-1996 deraadt

sync & label


# 1.4 09-Jan-1996 dm

added IP filter to netstat/rc and put examples in /usr/share/ipf


# 1.3 30-Dec-1995 deraadt

from netbsd: start mrouted like routed


# 1.2 18-Dec-1995 deraadt

/etc/ifaliases support by randy@zyzzyva.com


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.195 21-Feb-2018 rpe

Tweak comments.

OK tb


# 1.194 19-Feb-2018 rpe

Write warning/error messages to stderr and end them with a fullstop.

OK tb


# 1.193 19-Feb-2018 rpe

- use specific patterns when looping over /etc/hostname.if files
to skip backup or temp files.
- test if the patterns matched actual files
- warn if ifcreate() fails on an interface and continue with the
subsequent interfaces in the list instead of return'ing

OK dlg sthen tb


# 1.192 17-Feb-2018 rpe

- Add descriptions for the new functions ifcreate() and vifscreate()
- In ifcreate() use the exit code of the {} block directly
- In vifscreate(), use the ifconfig -C output directly in the for _vif loop
- Remove superfluous and somewhat confusing comment

OK dlg kn sthen


# 1.191 14-Feb-2018 dlg

create virtual interfaces before starting all interface config.

this resolves an ordering problem when adding pseudo interfaces to bridges

tweaks from kn@
ok mpi@ sthen@


# 1.190 10-Feb-2018 claudio

Remove some special IPv4 in IPv6 mapped prefixes that are already rejected
by the ::0.0.0.0/96 reject route added to deny all IPv4 mapped addresses.
Makes the inet6 routing table almost fit in one screen.
OK benno@


# 1.189 10-Feb-2018 florian

Load RFC 7217 key material and generate if it does not already exist.

Add soii.key to changelist (pointed out by semarie) and mtree/special
(suggest by Craig Skinner).

OK naddy, sthen, rpe, tb


# 1.188 06-Feb-2018 tb

If -n is given, the netstart script should not (try to) set the default
route(s). Simply print the command(s) to be issued instead.

tweak & ok rpe


# 1.187 12-Nov-2017 tb

Remove HN_DIR variable and expand it in the only place it was used. It
currently serves no purpose.

ok rpe, agreement from deraadt and halex


Revision tags: OPENBSD_6_2_BASE
# 1.186 25-Jul-2017 rpe

Finally remove backwards compat code to support the 'rtsol' keyword
in hostname.if(5)

OK mpi@ deraadt@ florian@
OK jmc@ from doc perspective


# 1.185 21-Jul-2017 rpe

Align ifstart() in netstart and install.sub.

- in netstart, rename _file to _hn referencing hostname.if files
- in install.sub switch ifstart() to be used with _if instead of
_hn as parameter

ok krw@ tb@


# 1.184 28-May-2017 awolk

etc/netstart: use colon separator instead of dot with chown

OK jung@, deraadt@, jmc@


# 1.183 07-May-2017 rpe

Change test from [] to [[]] and simplify pattern.

OK tb@, krw@ (for [[]])
Feedback and OK halex@


# 1.182 07-May-2017 rpe

Replace hardcoded script name with ${0##*/}

OK tb@ halex@


# 1.181 01-May-2017 rpe

Revert r1.170 and remove the id==0 check.
The id binary is not available in nfs diskless setups at this point.

reported by Andreas Kusalananda, thanks.
discussed with deraadt@


# 1.180 01-May-2017 rpe

Remove last remnants of rtsol. IPv6 autoconfiguration of interfaces is now
done in ifstart(). Remove ipv6autoconf() and replace rtsolif with a boolean
variable V6_AUTOCONF. Replace dhcpif with a boolean variable V4_DHCPCONF.
Both are later used in defaultroute() to decide whether or not to configre
defaultroutes from /etc/mygate.

OK krw@


# 1.179 30-Apr-2017 mpi

Do not try to delete a default route before adding it.

Now that route are automatically G/C with the address they are attached
to there's no reason to duplicate the kernel's job.

Fix a regression introduced with multipath default routes.

ok deraadt@


# 1.178 25-Apr-2017 rpe

Unbreak netstart for multiple inteface configurations like trunk
or carp. Ensure that the noglob option is disabled at the end of
parse_hn_line() and ifstart().

Reported by Christer Solskogen and Stefan Wollny, thanks!


# 1.177 24-Apr-2017 rpe

Introduce a new function parse_hn_line() that replaces the existing
hostname.if(5) parsing code in ifstart().
Add a -n option to netstart to only print the interface configuration
commands instead of executing them.
Add a HN_DIR variable, that points to the directory of the hostname.if
files (default /etc) that allows for future regression tests.

- add new parse_hn_line() function
- change ifstart()
- rename $if to $_if
- don't ifconfig or ifconfig create if -n option is used
- replace hostname.if(5) parsing code with new parse_hn_line()
- just print configuration commands if -n option is used
- autoconf now happens in ifstart(), remove ifv6autoconf()
- introduce HN_DIR variable for the hostname.if file location
- add handling of the -n option to only print config commands
- ensure -n is only used if interfaces are specified as parameters

Discussed with and positive feedback from many
'commit' deraadt@
OK sthen@


# 1.176 08-Apr-2017 rpe

- localize the if, file and stat variables which also ensures that
variables are not named like commands.
- change test from [] to [[]]

OK tb@ halex@


# 1.175 07-Apr-2017 rpe

Minimize differences in ifstart() function between netstart and
install.sub which makes it easier to spot changes in the future.

- comments and formatting
- quotes on assignments are not needed (netstart)
- remove stray space in test (netstart)
- use $file variable with while-loop (netstart)
- although valid, instead of i use $i in arithmetic test (install.sub)

OK krw@, tb@
Looks good deraadt@


# 1.174 07-Apr-2017 rpe

Align comments of ifstart() function in netstart and install.sub.


# 1.173 07-Apr-2017 rpe

Align comments of stripcom() function in netstart and install.sub.


Revision tags: OPENBSD_6_1_BASE
# 1.172 06-Dec-2016 mpi

Do not lose the default route when netstart(8) is run a second time on
the interface pointed to by the default route.

Since the kernel no longer keep routes with dangling address pointer,
netstart(8) has to re-add the default route when the corresponding ifa
has been deleted and re-created.

deraadt@ points out that even if the previous semantic was not necessarily
better, a script like netstart(8) cannot totally fix the default route
problem.

Regression reported by and fix tested by Hrvoje Popovski.

ksh foo checked by halex@


# 1.171 27-Sep-2016 rzalamena

Delay switch(4) interface start up so it can attach virtual interfaces
like vether(4).

nits from and ok benno@, phessler@


# 1.170 09-Sep-2016 jasper

print a clear error message when not ran as root instead of just falling
through and try whatever it can do with the invoking user's perms

feedback/ok aja@ rpe@


Revision tags: OPENBSD_6_0_BASE
# 1.169 19-Jul-2016 mpi

Do not consider tap(4) a special interface and start if before other
pseudo-interfaces.

This unbreak vlan(4) on top of tap(4) since the refactoring to turn it
MP-safe.

ok claudio@, deraadt@


# 1.168 27-Mar-2016 sthen

Don't delete the 224/4 route in netstart, unless it's being done to ensure that
a -reject route can be added. Restores the ability to set an interface route
before daemons are started, lost during the previous simplification.
ok millert mpi


Revision tags: OPENBSD_5_9_BASE
# 1.167 29-Dec-2015 rpe

Remove backslash, not necessary after '&&'

OK halex@


# 1.166 29-Dec-2015 rpe

Replace last remaining `` with $()

OK halex@


# 1.165 18-Dec-2015 ajacoutot

Drop the now useless multicast setup comment.

prodded by tim@, ok mpi@


# 1.164 17-Dec-2015 ajacoutot

Simplify multicast option handling (10 less lines) by matching /etc/rc behavior
towards other YES|NO options and drop the error warning.


with and ok tim@, ok rpe@ on an earlier diff


# 1.163 05-Dec-2015 mpi

It does not make sense to insert a specific route for 224/4 when the
default one is good enough.

So merge rc.conf(8)'s 'multicast_router' and 'multicast_host' into a
single 'multicast'. If set to YES the reject route for 224/4 is not
inserted by netstart(8).

Manual bits from jmc@

ok henning@, ajacoutot@


# 1.162 12-Nov-2015 rpe

Changes to ifautostart():
- Rename function to ifv6autoconf() to make IPv6 relation clearer
- Localize and rename variables

OK krw@


# 1.161 12-Nov-2015 rpe

Changes to ifmstart():
- Change comments to make it clearer that ifmstart() takes two lists
of interface driver names (of which the second is optional) and not
the actual interface instances.
- Use localized variables and use slightly more verbose names.
- Use continue 2 to skip to the next hostname.if file.
- Use shell pattern @() instead of testing _sif individually.

OK krw@


# 1.160 12-Nov-2015 rpe

Changes to stripcom():
- Align comments with /etc/rc version
- Use localized variables
- Use safer "print -r --" instead of plain echo

Changes to ifstart():
- Tweak comment
- Add usage

OK krw@


# 1.159 01-Nov-2015 rpe

Start the rework of the /etc/netstart shell script.

General changes:
- apply a similar 'style' as used in the installer scripts
- improve comments to be more to the point, remove where code is obvious
- document usage of functions if they have arguments
- rename variables where it improves readability
- replace really old-school shell code with more contemporary idioms

Other changes:
- No need to care about "autoboot" because netstart doesn't inherit the
positional parameters from /etc/rc anymore. /etc/rc executes netstart
instead of sourcing it since r1.439.
- Use simpler for-loop to process list of interfaces with ifstart.

OK halex@


# 1.158 26-Oct-2015 rpe

The hostname variable is not used since r1.99. Remove it and use
stripcom() output directly with the hostname command.

OK deraadt@ krw@


# 1.157 23-Oct-2015 claudio

netstart bits for tap(4)


# 1.156 27-Sep-2015 sthen

Don't print output when setting autoconf on interfaces. Suggested by deraadt,
ok florian@ rpe@


# 1.155 13-Sep-2015 sthen

only print the "IPv6 autoconf" line if there are interfaces to configure
feedback/ok rpe


# 1.154 11-Sep-2015 sthen

Set "inet6 autoconf" individually on interfaces that have rtsol set in
hostname.if, previously netstart tried to configure them all at once
("ifconfig if0 if1 if2 inet6 autoconf"). From Delan Azabani, ok phessler@


Revision tags: OPENBSD_5_8_BASE
# 1.153 20-Jul-2015 rpe

Disable Strict Bourne shell mode for /etc/rc and /etc/netstart to be
able to use ksh syntax within these scripts. This way init doesn't
need to be changed, which starts /etc/rc using /bin/sh and people
can still use "sh /etc/netstart ifname".

Idea from and OK halex@
OK deraadt@ krw@ guenther@


# 1.152 19-Jul-2015 florian

Bring up pflow last as it might send with a source address that is on
any of the other interfaces.
OK deraadt, phessler, benno


# 1.151 19-Jul-2015 rpe

Always source rc.subr to be able to use the rc.conf parsing routine
to get the network related vars from rc.conf. This is even necessary
if netstart is run from within /etc/rc. Remove test of $INRC which
unintentionally evaluated always to true.

problem with previous change found by nigel@
OK sthen@ aja@ halex@


# 1.150 19-Jul-2015 ajacoutot

Revert 1.148 for now until I can talk to rpe@
It introduced a regression reported by nigel@


# 1.149 19-Jul-2015 rpe

Replace test command with [].

OK halex@ krw@


# 1.148 19-Jul-2015 rpe

Ensure, that we source rc.subr and parse rc.conf ONLY if we are not
inside /etc/rc.

With help from and OK halex@, ajacoutot@


# 1.147 18-Jul-2015 rpe

- remove trailing blanks introduced in previous commit
- no space in redirections like </foo or >$bar
- few other minor whitespaces

OK krw@


# 1.146 18-Jul-2015 rpe

Improve comments
- Add comments for functions
- Start comments with capital letters
- End comments with a full stop
- Allow comments to extend up to column 80

OK krw@


# 1.145 06-Jun-2015 florian

Allow rtsol keyword in hostname.if(5) with net.inet6.ip6.forwarding=1.
"inet6 autoconf" was working before and rtsol should behave the same.
OK phessler


Revision tags: OPENBSD_5_7_BASE
# 1.144 03-Dec-2014 florian

The kernel handles rtsol(8) functionality since some time now.
Treat rtsol in hostname.if as a keyword like dhcp and call ifconfig
inet6 autoconf.
"reads good" todd@
OK krw@ (who is *not* an IPv6 person), but I recruited him in his
capacity as an installer person.


# 1.143 28-Sep-2014 claudio

Revert 1.142. Without the down netstart will just print the ifconfig
output because it may end up just calling 'ifconfig $if'. This needs
to be done better and properly tested.


# 1.142 26-Sep-2014 halex

remove explicit 'down' of an interface before starting a dhcp request, thereby
avoiding annoying delays for some switch configurations

ok claudio@ deraadt@

i would add ok phessler@, but it was not valid without an ok krw@


Revision tags: OPENBSD_5_6_BASE
# 1.141 12-Jul-2014 stsp

Fix netstart after autoconf6 change so 'rtsol' lines in hostname.if work again.
found by pelikan@; ok pelikan@ henning@


# 1.140 12-Jul-2014 robert

Make rc.conf a parsed configuration file and stop sourcing it as a shell
script.
From now on rc.conf has a fixed syntax (key=val) and it is not allowed
to add anything to it besides the supported syntax, it all going to be
ignored.

discussed with and help from deraadt@ and halex@


Revision tags: OPENBSD_5_5_BASE
# 1.139 22-Aug-2013 mpi

Like for dhclient, do no create a route to alias addresses via 127.0.0.1.
Our stack is able to tell if the address is local or not.

ok todd@, krw@


Revision tags: OPENBSD_5_4_BASE
# 1.138 20-Mar-2013 todd

fix lies in netstart; replacement wording from halex@
pointed out by Ryan Kavannagh rak at debian dot org


Revision tags: OPENBSD_5_3_BASE
# 1.137 05-Dec-2012 rpe

remove "Invalid interface name" message
requested by krw@

ok halex@


# 1.136 02-Dec-2012 rpe

use the more compact version of the check for ifconfig'able interfaces
from install.sub

with feedback from and ok halex


# 1.135 02-Dec-2012 rpe

- remove isalphanumeric() and replace it with a shell pattern, that
tries a bit harder to identify invalid interface names and in
this case emit an error message.
- use [[ $1 == autoboot ]] to avoid a shell error message due to
possible spaces in first argument
- no change in functionality

discussed with krw and halex
ok ("I like this") krw


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.134 07-Oct-2011 deraadt

The new ypbind changes requires that the domainname be set before
rc.conf is run. There's no real downside.
ok aja


Revision tags: OPENBSD_5_0_BASE
# 1.133 07-Jul-2011 guenther

Eliminate some $? tests by rolling the command into the condition

ok halex@


# 1.132 26-May-2011 mpf

Add svlan(4) startup bits.
From markus@. OK naddy, claudio, reyk.


Revision tags: OPENBSD_4_9_BASE
# 1.131 09-Feb-2011 sobrado

fix an unbalanced parenthesis in a comment; while here, split the comment
in a better place to make it more readable.

ok jmc@ and miod@


Revision tags: OPENBSD_4_8_BASE
# 1.130 16-Jun-2010 todd

permit e.g. -inet6 syntax by slurping all lines not just some
noticed by rhsv6 at hushmail dot com, ok sthen@


Revision tags: OPENBSD_4_7_BASE
# 1.129 12-Jan-2010 henning

when setting up lo0 use 127.0.0.1/8 instead of 127.0.0.1 for clarity and
correctness. it's not 1992 any more, kids. ok mcbride dlg krw


# 1.128 10-Dec-2009 todd

o stop reordering ifconfig arguments (e.g. after 'up ..')
o only stop processing if inet or inet6 lines are malformed
o everything not a specially handled bit is passed to ifconfig unmangled
noticed by several after the move from bridgename.bridge0 -> hostname.bridge0
prodded by deraadt@, tested by and feedback from several
man page bits 'look fine' jmc@


# 1.127 22-Nov-2009 deraadt

Stop supporting bridgename.bridge* files, and move to hostname.bridge*
files. To cope with this change, read about the mv command.
ok claudio todd


# 1.126 17-Sep-2009 simon

change variable i to $i in an expression of ifstart() for consistency
with the rest of the file. no functional change.

feedback from sthen@, ok krw@


# 1.125 10-Jul-2009 jdixon

Delay creation of tun(4) interfaces until the underlying interface and
routes are available. This fixes usage for some OpenVPN users that start
it from hostname.tun*.

Tested by Johan Huldtgren. ok sthen@, johan@.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.124 25-Nov-2008 markus

delay /etc/netstart until IPv6-DAD (dup-address-detection) is completed.
ok fries, hshoexer, claudio


# 1.123 14-Aug-2008 sthen

Tools from /usr may not be used in netstart since it may be NFS-mounted
and not available at that time. Rewrite the hostname.if permission check
to use only /bin/ls and the shell. Requested by deraadt.

ok todd, "Twisted." deraadt


Revision tags: OPENBSD_4_4_BASE
# 1.122 23-Jul-2008 sthen

Prevent warning about insecure hostnames where no /etc/hostname.*
exists. From wcmaier@.

Check target of symbolic links to avoid noise at boot and in
seucrity output where you have several interfaces symlinked to one
config file.

"If you think this is the right thing to do" deraadt@


# 1.121 09-Jun-2008 todd

warn once not 3 times in case of a non existent file, discussed with deraadt
originally pointed out by Johan Torin


# 1.120 09-Jun-2008 deraadt

Ensure that hostname.* files are also re-chowned to root.wheel at each
boot as discussed with claudio while eating tasty donairs. ok todd


# 1.119 17-Apr-2008 deraadt

before using them, force hostname.* files to be unreadable by world
first version from todd, ok millert


Revision tags: OPENBSD_4_3_BASE
# 1.118 17-Jan-2008 brad

Execute rtsol after turning up trunk(4) and vlan(4) interfaces so they're
taken into consideration for rtsol.

ok reyk@ dlg@


# 1.117 09-Jan-2008 mpf

Do not bring up pfsync(4) before the working ruleset
has been loaded. Otherwise, states that are received during the
initial bulk update mismatch the correct pf-checksum and
do not attach to the rules.
Problem identified by david@. Fix done in collaboration.
OK henning@


Revision tags: OPENBSD_4_2_BASE
# 1.116 02-Aug-2007 david

move the delay for IPv6 DAD to after all interfaces have started
fixes problems with daemons being unable to bind to all addreses at boot
ok itojun@ hshoexer@


Revision tags: OPENBSD_4_1_BASE
# 1.115 15-Nov-2006 itojun

reject multicast packet without scope identifier specified.


Revision tags: OPENBSD_4_0_BASE
# 1.114 29-Jun-2006 todd

do not add an extra space; nwid and description come out wrong
fix as proposed by maja@, thanks!


Revision tags: OPENBSD_3_9_BASE
# 1.113 28-Dec-2005 david

nuke extra whitespace


# 1.112 06-Dec-2005 reyk

multicast_host=YES only works if a valid default gateway is available.
validate this condition and reject multicast traffic on failure.

ok todd@ naddy@


# 1.111 02-Nov-2005 todd

fix inspired by pr#4590
ok krw@


# 1.110 25-Oct-2005 todd

better logic from krw@:
- do not process mygate for v4 if dhcp
- do not process mygate for v6 if rtsol
this also makes the mygate processing logic more readable
ok krw@


# 1.109 14-Oct-2005 todd

add v6 support for /etc/mygate
ok deraadt@ mickey@ krw@
same functionality tested/ok'ed by by mickey, brad, matthieu, and me
with this one may now put a v6 IP in /etc/mygate on a separate line from
the v4 default gateway and netstart will do the right thing


# 1.108 12-Oct-2005 todd

shrink stripcom(), sync with install.sub
ok krw@


# 1.107 04-Oct-2005 todd

trunk must be started after physical ethernet devices, but before vlan.
populate ifmstart lines accordingly.
prodded/tested by brad@
ok reyk@


# 1.106 28-Sep-2005 todd

use eval consistently, fixes description quotes on rtsol and dhcp
fix inspired by and closes pr 4495
ok krw@


Revision tags: OPENBSD_3_8_BASE
# 1.105 22-May-2005 todd

Introduce 'ifmstart' to deal with starting multiple interfaces minus a list
of interfaces.

This reduces the netstart script by 174 chars, 13 words, and 19 lines, but
more importantly, makes it more simple and less cluttered should more special
case/orderings be needed.

ok brad@ and pr 4197 submitter, inspired by and closes pr 4197


# 1.104 04-Apr-2005 djm

unbreak; ok pval@


# 1.103 03-Apr-2005 deraadt

if dhcp is used to get an address on any interface, ignore /etc/mygate
ok krw
(this lets us do something rather cool with the zaurus in particular)


Revision tags: OPENBSD_3_7_BASE
# 1.102 04-Jan-2005 mcbride

Bring up the carp(4) interface before default route.

ok pascoe@ mpf@


# 1.101 30-Dec-2004 millert

Add a copy of stripcom so /etc/netstart can be run standalone again.
OK deraadt@


# 1.100 19-Dec-2004 millert

Allow comments in /etc/{myname,mygate,defaultdomain}; OK deraadt@


# 1.99 04-Dec-2004 itojun

remove "route $hostname 127.0.0.1" line. deraadt ok
*** please update /etc/netstart and test if it works ok for you ***


# 1.98 20-Oct-2004 deraadt

make all route commands use -qn; ok mcbride henning


Revision tags: OPENBSD_3_6_BASE
# 1.97 29-May-2004 deraadt

one last route command lacking -qn


Revision tags: OPENBSD_3_5_BASE
# 1.96 22-Mar-2004 mcbride

Make sure pfsync is brought up before carp.

ok deraadt@


# 1.95 13-Mar-2004 mcbride

Delay pfsync(4) configuration, as the syncif has to be configured in
advance. From Thorsten Lockert.


# 1.94 14-Jan-2004 deraadt

ok, it took quite a bit of prodding but itojun finally explained why the
extra sleep 1 is in here, and we came to the conclusion it is safe to
delete it. whee.


# 1.93 13-Jan-2004 deraadt

repair v6 lo0 documentation


# 1.92 11-Jan-2004 deraadt

add loopback routes late


# 1.91 09-Jan-2004 deraadt

create all routes with -q; markus ok


# 1.90 04-Dec-2003 millert

Need to do "ifconfig create" for bridge interfaces too.


# 1.89 03-Dec-2003 markus

add support for ifconfig clone; from netbsd; ok deraadt, henning


# 1.88 20-Oct-2003 david

delay carp initialization until after physical interfaces are configured
ok mcbride@ henning@ deraadt@ todd@


Revision tags: OPENBSD_3_4_BASE
# 1.87 27-Aug-2003 henning

only try to set hostname to what /etc/myname says if that file actually exists,
otherwise preserve `hostname`
netbooted machines can live perfectly fine without it; they get their hostname
earlier.

ok krw@ cedric@


Revision tags: OPENBSD_3_3_BASE
# 1.86 16-Feb-2003 krw

Fix up some DNS verbiage to make it consistant.

Fix up default route selection by

a) Forcing user to explicitly chose 'dhcp' as a mechanism for
specifying a default route, rather than guessing based on one or more
interfaces being configured by dhcp.

b) If the user specified default route does not work, re-present the
existing default route rather than losing it.

c) Move default route selection to after nameserver activation so the
user can specify a hostname as the default route.

Change /etc/netstart so that /etc/mygate wins if a default route was
already specified (i.e. by dhcp).

ok deraadt@.


Revision tags: OPENBSD_3_2_BASE
# 1.85 16-May-2002 todd

ignore non-existent cases where '$if' evaluates to '*'.
From Andr� Lucas <andre@ae-35.com>, fixes pr # 2658.
'Looks good' from miod@, millert@, and krw@.


Revision tags: OPENBSD_3_1_BASE
# 1.84 23-Feb-2002 deraadt

re-add support for $if expansion; hamajima@nagoya.ydc.co.jp


# 1.83 21-Feb-2002 miod

Change the network components initialization order.
Change from:
o all interfaces
o all bridges
o routes
to:
o physical interfaces
o routes
o gif and gre interfaces
o bridges

Fixeski PR #2400.
Manual page updates coming soon.
Ok angelos@ chris@ deraadt@


Revision tags: OPENBSD_3_0_BASE
# 1.82 31-Jul-2001 hugh

a space before a redirect


# 1.81 06-Jul-2001 angelos

Also, source /etc/rc.conf so we can pull in the
multicast_host/multicast_router settings; this is useful if one
flushes the routing table and re-initializes.

We really need a netconfig tool of sorts.


# 1.80 06-Jul-2001 angelos

Use "route -n show -inet" to determine the default multicast iface.


# 1.79 03-Jul-2001 deraadt

pull in rc.conf early so that pf(1) startup is right; tested by jasoni, comments from millert


# 1.78 30-May-2001 deraadt

Remove ipf. Darren Reed has interpreted his (old, new, whichever)
licence in a way that makes ipf not free according to the rules we
established over 5 years ago, at www.openbsd.org/goals.html (and those
same basic rules govern the other *BSD projects too). Specifically,
Darren says that modified versions are not permitted. But software
which OpenBSD uses and redistributes must be free to all (be they
people or companies), for any purpose they wish to use it, including
modification, use, peeing on, or even integration into baby mulching
machines or atomic bombs to be dropped on Australia. Furthermore, we
know of a number of companies using ipf with modification like us, who
are now in the same situation, and we hope that some of them will work
with us to fill this gap that now exists in OpenBSD (temporarily, we
hope).


Revision tags: OPENBSD_2_9_BASE
# 1.77 13-Mar-2001 deraadt

spelling; maurice@maurice.wan.nl


# 1.76 06-Feb-2001 todd

ignore blank lines in addition to comments
fixes pr#1660 from wilfried@telia.com .. Thanks!


# 1.75 10-Jan-2001 jason

support !command in bridgename.if files, too


# 1.74 27-Nov-2000 millert

Use -n to test if a variable is non-zero. Otherwise, if the variable's
contents start with a '-' test becomes unhappy (since it interprets it
as another option).


# 1.73 08-Nov-2000 todd

This fixes pr 1481, we now handle args > 6 in /etc/hostname.if in the
cases where we did not previously handle them.
Thanks to Scott Atwood <atwood@cs.stanford.edu> for reminding us of this.


Revision tags: OPENBSD_2_8_BASE
# 1.72 02-Sep-2000 todd

subtle bug .. global variables in a while loop need reset 'just incase'
With:
hostname.fxp0 having a last line of:
inet6 alias 3ffe:...
and hostname.gif0 having a first two lines of:
giftunnel 1.2.3.4
dest 1.2.4.3
We end up with the command:
ifconfig gif0 giftunnel alias 1.2.3.4 1.2.4.3
.. which is clearly wrong and fixed by this change


# 1.71 18-Jun-2000 todd

rc.conf now parses ${local_rcconf} internally; closes pr 1259


Revision tags: OPENBSD_2_7_BASE
# 1.70 08-May-2000 todd

fix dhcp 'NONE' ness from install to allow media parsing to work
.. ok deraadt@, millert@


# 1.69 21-Apr-2000 deraadt

rc.conf.local support, inspired by chuck yerkes


# 1.68 04-Apr-2000 millert

Remove the -E flag from ipf as it is implicitly enabled and using
the -E flag here causes the kernel to printf 'IP Filter: already
initialized'.


# 1.67 18-Mar-2000 deraadt

silence all extra route addition printouts


# 1.66 17-Mar-2000 itojun

correct reject route installations for IPv6. improve comments.


# 1.65 12-Mar-2000 itojun

disallow packets to malicious 6to4 prefix, based on
http://playground.iijlab.net/i-d/draft-itojun-ipv6-transition-abuse-00.txt


# 1.64 10-Mar-2000 todd

fix non behavior
with this `!' lines in /etc/hostname.* run even without certain lines
(like a comment) preceeding it.


# 1.63 10-Jan-2000 todd

allow arbitrary commands in /etc/hostname.* files if the line starts with '!'


# 1.62 02-Jan-2000 deraadt

rtsol case can configure the interface up, since it would be nice to finish
DAD before the actual rtsol(8) run happens later. and since it will rtsol,
it is going to be up in any case.


# 1.61 02-Jan-2000 itojun

one more indentation fix.


# 1.60 02-Jan-2000 itojun

indentation fix (todd's part)


# 1.59 02-Jan-2000 todd

fix rtsold case, reset cmd for each iteration!


# 1.58 02-Jan-2000 itojun

allow options after "rtsol".
XXX both "dhcp" and "rtsol" has keyword *down* at the end. is it okay?


# 1.57 02-Jan-2000 itojun

echo "IPv6 autoconf: interfaces" before invoking rtsol.
sleep for net.inet6.ip6.dad_count seconds to ensure that IPv6 DAD is completed.
TODO: rtsold (rc.conf line), manpage


# 1.56 02-Jan-2000 itojun

ipv6 autoconf on hosts (non-routers).

to do this,
1. in sysctl.conf, add these lines:
net.inet6.ip6.forwarding=0
net.inet6.ip6.accept_rtadv=1
2. in hostname.foo, add
rtsol

specifying two or more interfaces with "rtsol" may result in strange
behavior - ipv6 spec does not permit multi-interface node to be autoconfig'ed.


# 1.55 02-Jan-2000 todd

add to hostname.* parsing:
- multiple entries support (read: aliases)
- inet6 support
- support for comments (#)
(look for hostname.if(5) commit for syntax details)


# 1.54 31-Dec-1999 itojun

install IPv6 reject routes only if kernel is capable of IPv6.


# 1.53 09-Dec-1999 itojun

avoid transmitting invalid IPv6 packets out to the wire.


# 1.52 09-Dec-1999 itojun

do not perform IPv6 initialization for loopback interface.
MUST make lo0 up before any IPv6 operations.
it will be considered a pilot error if you don't.
(I prefer to have lo0 initialized automatically)


Revision tags: OPENBSD_2_6_BASE
# 1.51 01-Sep-1999 deraadt

support # characters in bridgename.* files; millert


# 1.50 01-Sep-1999 deraadt

cleanup parsing of hostname.* files, and seperate bridge control into
bridgename.* files; all documented in new hostname.if(5) and
bridgename.if(5) man pages


# 1.49 09-Aug-1999 angelos

Only parse/setup the hostname.foo file if interface foo exists (this
is useful for laptops with different ethernet cards etc.)


Revision tags: OPENBSD_2_5_BASE
# 1.48 29-Mar-1999 niklas

New multicast route setup style


# 1.47 26-Mar-1999 niklas

Add bridge interface handling


# 1.46 01-Mar-1999 millert

Add support in /etc/hostname.xxx for files of the format:
up [options]
Any of the following may or may not be set:
$name $mask $bcaddr $extras


# 1.45 28-Oct-1998 millert

Kill the awful hack used to match and split /etc/hostname.* We now use
a function, isalphanumeric, to determine whether an interface name is
likely to be valid. This means that things like /etc/hostname.le0.bak,
/etc/hostname.le0#, /etc/hostname.le0~, etc. will be ignored as they
should. There is no longer an implicate assumption that /etc/hostname.*
only contains a single '.'.


Revision tags: OPENBSD_2_4_BASE
# 1.44 06-Oct-1998 deraadt

move ipnat to end of netstart, to support dhcp+ipnat


# 1.43 18-Sep-1998 deraadt

apply media directives on dhcp interfaces


# 1.42 10-Sep-1998 marc

better way of handling dhcp client; Jason Ish <jbi130@mail.usask.ca>


# 1.41 08-Sep-1998 marc

dhcp client stuff. "Angelos D. Keromytis" <angelos@dsl.cis.upenn.edu>


# 1.40 24-Aug-1998 downsj

You can't use -interface default when there's no default gateway
set (yet). Use -interface $hostname if mygate doesn't exist so that
this actually works on routers.


# 1.39 04-Jul-1998 deraadt

put 224 route on default, to avoid a hostname lookup


# 1.38 22-May-1998 deraadt

use route -n, what the heck


Revision tags: OPENBSD_2_3_BASE
# 1.37 28-Mar-1998 deraadt

s/^nat/ipnat/


# 1.36 23-Feb-1998 niklas

remove trailing blank line


# 1.35 07-Feb-1998 deraadt

ipforward is in sysctl.conf now


# 1.34 21-Dec-1997 deraadt

ugh


# 1.33 20-Dec-1997 deraadt

ipforwarding option in rc.conf


# 1.32 29-Nov-1997 kstailey

NAT requires IPF


# 1.31 04-Nov-1997 deraadt

kill spaces at ends of lines; m4


Revision tags: OPENBSD_2_2_BASE
# 1.30 14-Oct-1997 deraadt

set hostname/domainname before running rc.conf; m4@umn.edu


# 1.29 04-Sep-1997 deraadt

fork netstart; new child is rc.conf


# 1.28 25-Aug-1997 millert

Explicately pass -host flag to route(8) to avoid confusion with networks.


# 1.27 19-Aug-1997 niklas

Add hook for rpc.lockd, make nfsd flags settable in netstart


# 1.26 31-Jul-1997 downsj

Make quotas optional; wedged into netstart for the time being.
/etc/rc.conf, anyone?


# 1.25 30-Jul-1997 deraadt

do not run routed by default


# 1.24 28-Jul-1997 kstailey

Move configuration of loopback interface to before all other interfaces.
Allows the use of local caching-only nameserver with no "nameserver"
entry in /etc/resolv.conf to configure a route between the hostname
and loopback.


# 1.23 25-Jul-1997 provos

earlier start of keymanagement


# 1.22 24-Jul-1997 deraadt

make amd use /tmp_mnt by default


# 1.21 22-Jul-1997 provos

start the photuris daemon per default. hilfe.


# 1.20 17-Jun-1997 niklas

Put in hooks to start ypserv with flags


# 1.19 17-Jun-1997 niklas

Put in hooks to start rpc.yppasswdd with flags


Revision tags: OPENBSD_2_1_BASE
# 1.18 15-Apr-1997 deraadt

kill route flush until .. hmm kernel routing socket bug or something


# 1.17 09-Apr-1997 kstailey

add NAT startup


# 1.16 07-Apr-1997 rees

flush all old routes before adding new interfaces or routes.
ref: netbsd pr3228/misc, Matthias Scheler


# 1.15 03-Mar-1997 downsj

fix typo


# 1.14 11-Feb-1997 deraadt

add default route before fiddling with loopback route to avoid DNS problems; m4@umn.edu, #97


# 1.13 03-Feb-1997 deraadt

do ifaliases after /usr/bin exists in nfs diskless env; pr#77, matthieu@laas.fr


# 1.12 02-Nov-1996 deraadt

timed off by default


Revision tags: OPENBSD_2_0_BASE
# 1.11 23-Sep-1996 deraadt

rfc1323 variable


# 1.10 04-Sep-1996 deraadt

control portmap, inetd, and lpd from netstart; idea from tqbf@enteract.com


# 1.9 27-Aug-1996 deraadt

224.0.0.0 not 0.0.0.224; from peter@demon.net


# 1.8 18-Jun-1996 deraadt

move std stuff from rc.local to rc


# 1.7 16-Jun-1996 deraadt

install sample commented /etc/ifaliases file; which can now contain #
comments and blank lines. new format is "interface address netmask"
(yes, i changed the order of the entries). inspired by netbsd pr#2474;
gillhaa@ghost.whirlpool.com


# 1.6 02-Jun-1996 tholo

Install a multicast route by default


# 1.5 26-May-1996 deraadt

sync & label


# 1.4 09-Jan-1996 dm

added IP filter to netstat/rc and put examples in /usr/share/ipf


# 1.3 30-Dec-1995 deraadt

from netbsd: start mrouted like routed


# 1.2 18-Dec-1995 deraadt

/etc/ifaliases support by randy@zyzzyva.com


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.194 19-Feb-2018 rpe

Write warning/error messages to stderr and end them with a fullstop.

OK tb


# 1.193 19-Feb-2018 rpe

- use specific patterns when looping over /etc/hostname.if files
to skip backup or temp files.
- test if the patterns matched actual files
- warn if ifcreate() fails on an interface and continue with the
subsequent interfaces in the list instead of return'ing

OK dlg sthen tb


# 1.192 17-Feb-2018 rpe

- Add descriptions for the new functions ifcreate() and vifscreate()
- In ifcreate() use the exit code of the {} block directly
- In vifscreate(), use the ifconfig -C output directly in the for _vif loop
- Remove superfluous and somewhat confusing comment

OK dlg kn sthen


# 1.191 14-Feb-2018 dlg

create virtual interfaces before starting all interface config.

this resolves an ordering problem when adding pseudo interfaces to bridges

tweaks from kn@
ok mpi@ sthen@


# 1.190 10-Feb-2018 claudio

Remove some special IPv4 in IPv6 mapped prefixes that are already rejected
by the ::0.0.0.0/96 reject route added to deny all IPv4 mapped addresses.
Makes the inet6 routing table almost fit in one screen.
OK benno@


# 1.189 10-Feb-2018 florian

Load RFC 7217 key material and generate if it does not already exist.

Add soii.key to changelist (pointed out by semarie) and mtree/special
(suggest by Craig Skinner).

OK naddy, sthen, rpe, tb


# 1.188 06-Feb-2018 tb

If -n is given, the netstart script should not (try to) set the default
route(s). Simply print the command(s) to be issued instead.

tweak & ok rpe


# 1.187 12-Nov-2017 tb

Remove HN_DIR variable and expand it in the only place it was used. It
currently serves no purpose.

ok rpe, agreement from deraadt and halex


Revision tags: OPENBSD_6_2_BASE
# 1.186 25-Jul-2017 rpe

Finally remove backwards compat code to support the 'rtsol' keyword
in hostname.if(5)

OK mpi@ deraadt@ florian@
OK jmc@ from doc perspective


# 1.185 21-Jul-2017 rpe

Align ifstart() in netstart and install.sub.

- in netstart, rename _file to _hn referencing hostname.if files
- in install.sub switch ifstart() to be used with _if instead of
_hn as parameter

ok krw@ tb@


# 1.184 28-May-2017 awolk

etc/netstart: use colon separator instead of dot with chown

OK jung@, deraadt@, jmc@


# 1.183 07-May-2017 rpe

Change test from [] to [[]] and simplify pattern.

OK tb@, krw@ (for [[]])
Feedback and OK halex@


# 1.182 07-May-2017 rpe

Replace hardcoded script name with ${0##*/}

OK tb@ halex@


# 1.181 01-May-2017 rpe

Revert r1.170 and remove the id==0 check.
The id binary is not available in nfs diskless setups at this point.

reported by Andreas Kusalananda, thanks.
discussed with deraadt@


# 1.180 01-May-2017 rpe

Remove last remnants of rtsol. IPv6 autoconfiguration of interfaces is now
done in ifstart(). Remove ipv6autoconf() and replace rtsolif with a boolean
variable V6_AUTOCONF. Replace dhcpif with a boolean variable V4_DHCPCONF.
Both are later used in defaultroute() to decide whether or not to configre
defaultroutes from /etc/mygate.

OK krw@


# 1.179 30-Apr-2017 mpi

Do not try to delete a default route before adding it.

Now that route are automatically G/C with the address they are attached
to there's no reason to duplicate the kernel's job.

Fix a regression introduced with multipath default routes.

ok deraadt@


# 1.178 25-Apr-2017 rpe

Unbreak netstart for multiple inteface configurations like trunk
or carp. Ensure that the noglob option is disabled at the end of
parse_hn_line() and ifstart().

Reported by Christer Solskogen and Stefan Wollny, thanks!


# 1.177 24-Apr-2017 rpe

Introduce a new function parse_hn_line() that replaces the existing
hostname.if(5) parsing code in ifstart().
Add a -n option to netstart to only print the interface configuration
commands instead of executing them.
Add a HN_DIR variable, that points to the directory of the hostname.if
files (default /etc) that allows for future regression tests.

- add new parse_hn_line() function
- change ifstart()
- rename $if to $_if
- don't ifconfig or ifconfig create if -n option is used
- replace hostname.if(5) parsing code with new parse_hn_line()
- just print configuration commands if -n option is used
- autoconf now happens in ifstart(), remove ifv6autoconf()
- introduce HN_DIR variable for the hostname.if file location
- add handling of the -n option to only print config commands
- ensure -n is only used if interfaces are specified as parameters

Discussed with and positive feedback from many
'commit' deraadt@
OK sthen@


# 1.176 08-Apr-2017 rpe

- localize the if, file and stat variables which also ensures that
variables are not named like commands.
- change test from [] to [[]]

OK tb@ halex@


# 1.175 07-Apr-2017 rpe

Minimize differences in ifstart() function between netstart and
install.sub which makes it easier to spot changes in the future.

- comments and formatting
- quotes on assignments are not needed (netstart)
- remove stray space in test (netstart)
- use $file variable with while-loop (netstart)
- although valid, instead of i use $i in arithmetic test (install.sub)

OK krw@, tb@
Looks good deraadt@


# 1.174 07-Apr-2017 rpe

Align comments of ifstart() function in netstart and install.sub.


# 1.173 07-Apr-2017 rpe

Align comments of stripcom() function in netstart and install.sub.


Revision tags: OPENBSD_6_1_BASE
# 1.172 06-Dec-2016 mpi

Do not lose the default route when netstart(8) is run a second time on
the interface pointed to by the default route.

Since the kernel no longer keep routes with dangling address pointer,
netstart(8) has to re-add the default route when the corresponding ifa
has been deleted and re-created.

deraadt@ points out that even if the previous semantic was not necessarily
better, a script like netstart(8) cannot totally fix the default route
problem.

Regression reported by and fix tested by Hrvoje Popovski.

ksh foo checked by halex@


# 1.171 27-Sep-2016 rzalamena

Delay switch(4) interface start up so it can attach virtual interfaces
like vether(4).

nits from and ok benno@, phessler@


# 1.170 09-Sep-2016 jasper

print a clear error message when not ran as root instead of just falling
through and try whatever it can do with the invoking user's perms

feedback/ok aja@ rpe@


Revision tags: OPENBSD_6_0_BASE
# 1.169 19-Jul-2016 mpi

Do not consider tap(4) a special interface and start if before other
pseudo-interfaces.

This unbreak vlan(4) on top of tap(4) since the refactoring to turn it
MP-safe.

ok claudio@, deraadt@


# 1.168 27-Mar-2016 sthen

Don't delete the 224/4 route in netstart, unless it's being done to ensure that
a -reject route can be added. Restores the ability to set an interface route
before daemons are started, lost during the previous simplification.
ok millert mpi


Revision tags: OPENBSD_5_9_BASE
# 1.167 29-Dec-2015 rpe

Remove backslash, not necessary after '&&'

OK halex@


# 1.166 29-Dec-2015 rpe

Replace last remaining `` with $()

OK halex@


# 1.165 18-Dec-2015 ajacoutot

Drop the now useless multicast setup comment.

prodded by tim@, ok mpi@


# 1.164 17-Dec-2015 ajacoutot

Simplify multicast option handling (10 less lines) by matching /etc/rc behavior
towards other YES|NO options and drop the error warning.


with and ok tim@, ok rpe@ on an earlier diff


# 1.163 05-Dec-2015 mpi

It does not make sense to insert a specific route for 224/4 when the
default one is good enough.

So merge rc.conf(8)'s 'multicast_router' and 'multicast_host' into a
single 'multicast'. If set to YES the reject route for 224/4 is not
inserted by netstart(8).

Manual bits from jmc@

ok henning@, ajacoutot@


# 1.162 12-Nov-2015 rpe

Changes to ifautostart():
- Rename function to ifv6autoconf() to make IPv6 relation clearer
- Localize and rename variables

OK krw@


# 1.161 12-Nov-2015 rpe

Changes to ifmstart():
- Change comments to make it clearer that ifmstart() takes two lists
of interface driver names (of which the second is optional) and not
the actual interface instances.
- Use localized variables and use slightly more verbose names.
- Use continue 2 to skip to the next hostname.if file.
- Use shell pattern @() instead of testing _sif individually.

OK krw@


# 1.160 12-Nov-2015 rpe

Changes to stripcom():
- Align comments with /etc/rc version
- Use localized variables
- Use safer "print -r --" instead of plain echo

Changes to ifstart():
- Tweak comment
- Add usage

OK krw@


# 1.159 01-Nov-2015 rpe

Start the rework of the /etc/netstart shell script.

General changes:
- apply a similar 'style' as used in the installer scripts
- improve comments to be more to the point, remove where code is obvious
- document usage of functions if they have arguments
- rename variables where it improves readability
- replace really old-school shell code with more contemporary idioms

Other changes:
- No need to care about "autoboot" because netstart doesn't inherit the
positional parameters from /etc/rc anymore. /etc/rc executes netstart
instead of sourcing it since r1.439.
- Use simpler for-loop to process list of interfaces with ifstart.

OK halex@


# 1.158 26-Oct-2015 rpe

The hostname variable is not used since r1.99. Remove it and use
stripcom() output directly with the hostname command.

OK deraadt@ krw@


# 1.157 23-Oct-2015 claudio

netstart bits for tap(4)


# 1.156 27-Sep-2015 sthen

Don't print output when setting autoconf on interfaces. Suggested by deraadt,
ok florian@ rpe@


# 1.155 13-Sep-2015 sthen

only print the "IPv6 autoconf" line if there are interfaces to configure
feedback/ok rpe


# 1.154 11-Sep-2015 sthen

Set "inet6 autoconf" individually on interfaces that have rtsol set in
hostname.if, previously netstart tried to configure them all at once
("ifconfig if0 if1 if2 inet6 autoconf"). From Delan Azabani, ok phessler@


Revision tags: OPENBSD_5_8_BASE
# 1.153 20-Jul-2015 rpe

Disable Strict Bourne shell mode for /etc/rc and /etc/netstart to be
able to use ksh syntax within these scripts. This way init doesn't
need to be changed, which starts /etc/rc using /bin/sh and people
can still use "sh /etc/netstart ifname".

Idea from and OK halex@
OK deraadt@ krw@ guenther@


# 1.152 19-Jul-2015 florian

Bring up pflow last as it might send with a source address that is on
any of the other interfaces.
OK deraadt, phessler, benno


# 1.151 19-Jul-2015 rpe

Always source rc.subr to be able to use the rc.conf parsing routine
to get the network related vars from rc.conf. This is even necessary
if netstart is run from within /etc/rc. Remove test of $INRC which
unintentionally evaluated always to true.

problem with previous change found by nigel@
OK sthen@ aja@ halex@


# 1.150 19-Jul-2015 ajacoutot

Revert 1.148 for now until I can talk to rpe@
It introduced a regression reported by nigel@


# 1.149 19-Jul-2015 rpe

Replace test command with [].

OK halex@ krw@


# 1.148 19-Jul-2015 rpe

Ensure, that we source rc.subr and parse rc.conf ONLY if we are not
inside /etc/rc.

With help from and OK halex@, ajacoutot@


# 1.147 18-Jul-2015 rpe

- remove trailing blanks introduced in previous commit
- no space in redirections like </foo or >$bar
- few other minor whitespaces

OK krw@


# 1.146 18-Jul-2015 rpe

Improve comments
- Add comments for functions
- Start comments with capital letters
- End comments with a full stop
- Allow comments to extend up to column 80

OK krw@


# 1.145 06-Jun-2015 florian

Allow rtsol keyword in hostname.if(5) with net.inet6.ip6.forwarding=1.
"inet6 autoconf" was working before and rtsol should behave the same.
OK phessler


Revision tags: OPENBSD_5_7_BASE
# 1.144 03-Dec-2014 florian

The kernel handles rtsol(8) functionality since some time now.
Treat rtsol in hostname.if as a keyword like dhcp and call ifconfig
inet6 autoconf.
"reads good" todd@
OK krw@ (who is *not* an IPv6 person), but I recruited him in his
capacity as an installer person.


# 1.143 28-Sep-2014 claudio

Revert 1.142. Without the down netstart will just print the ifconfig
output because it may end up just calling 'ifconfig $if'. This needs
to be done better and properly tested.


# 1.142 26-Sep-2014 halex

remove explicit 'down' of an interface before starting a dhcp request, thereby
avoiding annoying delays for some switch configurations

ok claudio@ deraadt@

i would add ok phessler@, but it was not valid without an ok krw@


Revision tags: OPENBSD_5_6_BASE
# 1.141 12-Jul-2014 stsp

Fix netstart after autoconf6 change so 'rtsol' lines in hostname.if work again.
found by pelikan@; ok pelikan@ henning@


# 1.140 12-Jul-2014 robert

Make rc.conf a parsed configuration file and stop sourcing it as a shell
script.
From now on rc.conf has a fixed syntax (key=val) and it is not allowed
to add anything to it besides the supported syntax, it all going to be
ignored.

discussed with and help from deraadt@ and halex@


Revision tags: OPENBSD_5_5_BASE
# 1.139 22-Aug-2013 mpi

Like for dhclient, do no create a route to alias addresses via 127.0.0.1.
Our stack is able to tell if the address is local or not.

ok todd@, krw@


Revision tags: OPENBSD_5_4_BASE
# 1.138 20-Mar-2013 todd

fix lies in netstart; replacement wording from halex@
pointed out by Ryan Kavannagh rak at debian dot org


Revision tags: OPENBSD_5_3_BASE
# 1.137 05-Dec-2012 rpe

remove "Invalid interface name" message
requested by krw@

ok halex@


# 1.136 02-Dec-2012 rpe

use the more compact version of the check for ifconfig'able interfaces
from install.sub

with feedback from and ok halex


# 1.135 02-Dec-2012 rpe

- remove isalphanumeric() and replace it with a shell pattern, that
tries a bit harder to identify invalid interface names and in
this case emit an error message.
- use [[ $1 == autoboot ]] to avoid a shell error message due to
possible spaces in first argument
- no change in functionality

discussed with krw and halex
ok ("I like this") krw


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.134 07-Oct-2011 deraadt

The new ypbind changes requires that the domainname be set before
rc.conf is run. There's no real downside.
ok aja


Revision tags: OPENBSD_5_0_BASE
# 1.133 07-Jul-2011 guenther

Eliminate some $? tests by rolling the command into the condition

ok halex@


# 1.132 26-May-2011 mpf

Add svlan(4) startup bits.
From markus@. OK naddy, claudio, reyk.


Revision tags: OPENBSD_4_9_BASE
# 1.131 09-Feb-2011 sobrado

fix an unbalanced parenthesis in a comment; while here, split the comment
in a better place to make it more readable.

ok jmc@ and miod@


Revision tags: OPENBSD_4_8_BASE
# 1.130 16-Jun-2010 todd

permit e.g. -inet6 syntax by slurping all lines not just some
noticed by rhsv6 at hushmail dot com, ok sthen@


Revision tags: OPENBSD_4_7_BASE
# 1.129 12-Jan-2010 henning

when setting up lo0 use 127.0.0.1/8 instead of 127.0.0.1 for clarity and
correctness. it's not 1992 any more, kids. ok mcbride dlg krw


# 1.128 10-Dec-2009 todd

o stop reordering ifconfig arguments (e.g. after 'up ..')
o only stop processing if inet or inet6 lines are malformed
o everything not a specially handled bit is passed to ifconfig unmangled
noticed by several after the move from bridgename.bridge0 -> hostname.bridge0
prodded by deraadt@, tested by and feedback from several
man page bits 'look fine' jmc@


# 1.127 22-Nov-2009 deraadt

Stop supporting bridgename.bridge* files, and move to hostname.bridge*
files. To cope with this change, read about the mv command.
ok claudio todd


# 1.126 17-Sep-2009 simon

change variable i to $i in an expression of ifstart() for consistency
with the rest of the file. no functional change.

feedback from sthen@, ok krw@


# 1.125 10-Jul-2009 jdixon

Delay creation of tun(4) interfaces until the underlying interface and
routes are available. This fixes usage for some OpenVPN users that start
it from hostname.tun*.

Tested by Johan Huldtgren. ok sthen@, johan@.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.124 25-Nov-2008 markus

delay /etc/netstart until IPv6-DAD (dup-address-detection) is completed.
ok fries, hshoexer, claudio


# 1.123 14-Aug-2008 sthen

Tools from /usr may not be used in netstart since it may be NFS-mounted
and not available at that time. Rewrite the hostname.if permission check
to use only /bin/ls and the shell. Requested by deraadt.

ok todd, "Twisted." deraadt


Revision tags: OPENBSD_4_4_BASE
# 1.122 23-Jul-2008 sthen

Prevent warning about insecure hostnames where no /etc/hostname.*
exists. From wcmaier@.

Check target of symbolic links to avoid noise at boot and in
seucrity output where you have several interfaces symlinked to one
config file.

"If you think this is the right thing to do" deraadt@


# 1.121 09-Jun-2008 todd

warn once not 3 times in case of a non existent file, discussed with deraadt
originally pointed out by Johan Torin


# 1.120 09-Jun-2008 deraadt

Ensure that hostname.* files are also re-chowned to root.wheel at each
boot as discussed with claudio while eating tasty donairs. ok todd


# 1.119 17-Apr-2008 deraadt

before using them, force hostname.* files to be unreadable by world
first version from todd, ok millert


Revision tags: OPENBSD_4_3_BASE
# 1.118 17-Jan-2008 brad

Execute rtsol after turning up trunk(4) and vlan(4) interfaces so they're
taken into consideration for rtsol.

ok reyk@ dlg@


# 1.117 09-Jan-2008 mpf

Do not bring up pfsync(4) before the working ruleset
has been loaded. Otherwise, states that are received during the
initial bulk update mismatch the correct pf-checksum and
do not attach to the rules.
Problem identified by david@. Fix done in collaboration.
OK henning@


Revision tags: OPENBSD_4_2_BASE
# 1.116 02-Aug-2007 david

move the delay for IPv6 DAD to after all interfaces have started
fixes problems with daemons being unable to bind to all addreses at boot
ok itojun@ hshoexer@


Revision tags: OPENBSD_4_1_BASE
# 1.115 15-Nov-2006 itojun

reject multicast packet without scope identifier specified.


Revision tags: OPENBSD_4_0_BASE
# 1.114 29-Jun-2006 todd

do not add an extra space; nwid and description come out wrong
fix as proposed by maja@, thanks!


Revision tags: OPENBSD_3_9_BASE
# 1.113 28-Dec-2005 david

nuke extra whitespace


# 1.112 06-Dec-2005 reyk

multicast_host=YES only works if a valid default gateway is available.
validate this condition and reject multicast traffic on failure.

ok todd@ naddy@


# 1.111 02-Nov-2005 todd

fix inspired by pr#4590
ok krw@


# 1.110 25-Oct-2005 todd

better logic from krw@:
- do not process mygate for v4 if dhcp
- do not process mygate for v6 if rtsol
this also makes the mygate processing logic more readable
ok krw@


# 1.109 14-Oct-2005 todd

add v6 support for /etc/mygate
ok deraadt@ mickey@ krw@
same functionality tested/ok'ed by by mickey, brad, matthieu, and me
with this one may now put a v6 IP in /etc/mygate on a separate line from
the v4 default gateway and netstart will do the right thing


# 1.108 12-Oct-2005 todd

shrink stripcom(), sync with install.sub
ok krw@


# 1.107 04-Oct-2005 todd

trunk must be started after physical ethernet devices, but before vlan.
populate ifmstart lines accordingly.
prodded/tested by brad@
ok reyk@


# 1.106 28-Sep-2005 todd

use eval consistently, fixes description quotes on rtsol and dhcp
fix inspired by and closes pr 4495
ok krw@


Revision tags: OPENBSD_3_8_BASE
# 1.105 22-May-2005 todd

Introduce 'ifmstart' to deal with starting multiple interfaces minus a list
of interfaces.

This reduces the netstart script by 174 chars, 13 words, and 19 lines, but
more importantly, makes it more simple and less cluttered should more special
case/orderings be needed.

ok brad@ and pr 4197 submitter, inspired by and closes pr 4197


# 1.104 04-Apr-2005 djm

unbreak; ok pval@


# 1.103 03-Apr-2005 deraadt

if dhcp is used to get an address on any interface, ignore /etc/mygate
ok krw
(this lets us do something rather cool with the zaurus in particular)


Revision tags: OPENBSD_3_7_BASE
# 1.102 04-Jan-2005 mcbride

Bring up the carp(4) interface before default route.

ok pascoe@ mpf@


# 1.101 30-Dec-2004 millert

Add a copy of stripcom so /etc/netstart can be run standalone again.
OK deraadt@


# 1.100 19-Dec-2004 millert

Allow comments in /etc/{myname,mygate,defaultdomain}; OK deraadt@


# 1.99 04-Dec-2004 itojun

remove "route $hostname 127.0.0.1" line. deraadt ok
*** please update /etc/netstart and test if it works ok for you ***


# 1.98 20-Oct-2004 deraadt

make all route commands use -qn; ok mcbride henning


Revision tags: OPENBSD_3_6_BASE
# 1.97 29-May-2004 deraadt

one last route command lacking -qn


Revision tags: OPENBSD_3_5_BASE
# 1.96 22-Mar-2004 mcbride

Make sure pfsync is brought up before carp.

ok deraadt@


# 1.95 13-Mar-2004 mcbride

Delay pfsync(4) configuration, as the syncif has to be configured in
advance. From Thorsten Lockert.


# 1.94 14-Jan-2004 deraadt

ok, it took quite a bit of prodding but itojun finally explained why the
extra sleep 1 is in here, and we came to the conclusion it is safe to
delete it. whee.


# 1.93 13-Jan-2004 deraadt

repair v6 lo0 documentation


# 1.92 11-Jan-2004 deraadt

add loopback routes late


# 1.91 09-Jan-2004 deraadt

create all routes with -q; markus ok


# 1.90 04-Dec-2003 millert

Need to do "ifconfig create" for bridge interfaces too.


# 1.89 03-Dec-2003 markus

add support for ifconfig clone; from netbsd; ok deraadt, henning


# 1.88 20-Oct-2003 david

delay carp initialization until after physical interfaces are configured
ok mcbride@ henning@ deraadt@ todd@


Revision tags: OPENBSD_3_4_BASE
# 1.87 27-Aug-2003 henning

only try to set hostname to what /etc/myname says if that file actually exists,
otherwise preserve `hostname`
netbooted machines can live perfectly fine without it; they get their hostname
earlier.

ok krw@ cedric@


Revision tags: OPENBSD_3_3_BASE
# 1.86 16-Feb-2003 krw

Fix up some DNS verbiage to make it consistant.

Fix up default route selection by

a) Forcing user to explicitly chose 'dhcp' as a mechanism for
specifying a default route, rather than guessing based on one or more
interfaces being configured by dhcp.

b) If the user specified default route does not work, re-present the
existing default route rather than losing it.

c) Move default route selection to after nameserver activation so the
user can specify a hostname as the default route.

Change /etc/netstart so that /etc/mygate wins if a default route was
already specified (i.e. by dhcp).

ok deraadt@.


Revision tags: OPENBSD_3_2_BASE
# 1.85 16-May-2002 todd

ignore non-existent cases where '$if' evaluates to '*'.
From Andr� Lucas <andre@ae-35.com>, fixes pr # 2658.
'Looks good' from miod@, millert@, and krw@.


Revision tags: OPENBSD_3_1_BASE
# 1.84 23-Feb-2002 deraadt

re-add support for $if expansion; hamajima@nagoya.ydc.co.jp


# 1.83 21-Feb-2002 miod

Change the network components initialization order.
Change from:
o all interfaces
o all bridges
o routes
to:
o physical interfaces
o routes
o gif and gre interfaces
o bridges

Fixeski PR #2400.
Manual page updates coming soon.
Ok angelos@ chris@ deraadt@


Revision tags: OPENBSD_3_0_BASE
# 1.82 31-Jul-2001 hugh

a space before a redirect


# 1.81 06-Jul-2001 angelos

Also, source /etc/rc.conf so we can pull in the
multicast_host/multicast_router settings; this is useful if one
flushes the routing table and re-initializes.

We really need a netconfig tool of sorts.


# 1.80 06-Jul-2001 angelos

Use "route -n show -inet" to determine the default multicast iface.


# 1.79 03-Jul-2001 deraadt

pull in rc.conf early so that pf(1) startup is right; tested by jasoni, comments from millert


# 1.78 30-May-2001 deraadt

Remove ipf. Darren Reed has interpreted his (old, new, whichever)
licence in a way that makes ipf not free according to the rules we
established over 5 years ago, at www.openbsd.org/goals.html (and those
same basic rules govern the other *BSD projects too). Specifically,
Darren says that modified versions are not permitted. But software
which OpenBSD uses and redistributes must be free to all (be they
people or companies), for any purpose they wish to use it, including
modification, use, peeing on, or even integration into baby mulching
machines or atomic bombs to be dropped on Australia. Furthermore, we
know of a number of companies using ipf with modification like us, who
are now in the same situation, and we hope that some of them will work
with us to fill this gap that now exists in OpenBSD (temporarily, we
hope).


Revision tags: OPENBSD_2_9_BASE
# 1.77 13-Mar-2001 deraadt

spelling; maurice@maurice.wan.nl


# 1.76 06-Feb-2001 todd

ignore blank lines in addition to comments
fixes pr#1660 from wilfried@telia.com .. Thanks!


# 1.75 10-Jan-2001 jason

support !command in bridgename.if files, too


# 1.74 27-Nov-2000 millert

Use -n to test if a variable is non-zero. Otherwise, if the variable's
contents start with a '-' test becomes unhappy (since it interprets it
as another option).


# 1.73 08-Nov-2000 todd

This fixes pr 1481, we now handle args > 6 in /etc/hostname.if in the
cases where we did not previously handle them.
Thanks to Scott Atwood <atwood@cs.stanford.edu> for reminding us of this.


Revision tags: OPENBSD_2_8_BASE
# 1.72 02-Sep-2000 todd

subtle bug .. global variables in a while loop need reset 'just incase'
With:
hostname.fxp0 having a last line of:
inet6 alias 3ffe:...
and hostname.gif0 having a first two lines of:
giftunnel 1.2.3.4
dest 1.2.4.3
We end up with the command:
ifconfig gif0 giftunnel alias 1.2.3.4 1.2.4.3
.. which is clearly wrong and fixed by this change


# 1.71 18-Jun-2000 todd

rc.conf now parses ${local_rcconf} internally; closes pr 1259


Revision tags: OPENBSD_2_7_BASE
# 1.70 08-May-2000 todd

fix dhcp 'NONE' ness from install to allow media parsing to work
.. ok deraadt@, millert@


# 1.69 21-Apr-2000 deraadt

rc.conf.local support, inspired by chuck yerkes


# 1.68 04-Apr-2000 millert

Remove the -E flag from ipf as it is implicitly enabled and using
the -E flag here causes the kernel to printf 'IP Filter: already
initialized'.


# 1.67 18-Mar-2000 deraadt

silence all extra route addition printouts


# 1.66 17-Mar-2000 itojun

correct reject route installations for IPv6. improve comments.


# 1.65 12-Mar-2000 itojun

disallow packets to malicious 6to4 prefix, based on
http://playground.iijlab.net/i-d/draft-itojun-ipv6-transition-abuse-00.txt


# 1.64 10-Mar-2000 todd

fix non behavior
with this `!' lines in /etc/hostname.* run even without certain lines
(like a comment) preceeding it.


# 1.63 10-Jan-2000 todd

allow arbitrary commands in /etc/hostname.* files if the line starts with '!'


# 1.62 02-Jan-2000 deraadt

rtsol case can configure the interface up, since it would be nice to finish
DAD before the actual rtsol(8) run happens later. and since it will rtsol,
it is going to be up in any case.


# 1.61 02-Jan-2000 itojun

one more indentation fix.


# 1.60 02-Jan-2000 itojun

indentation fix (todd's part)


# 1.59 02-Jan-2000 todd

fix rtsold case, reset cmd for each iteration!


# 1.58 02-Jan-2000 itojun

allow options after "rtsol".
XXX both "dhcp" and "rtsol" has keyword *down* at the end. is it okay?


# 1.57 02-Jan-2000 itojun

echo "IPv6 autoconf: interfaces" before invoking rtsol.
sleep for net.inet6.ip6.dad_count seconds to ensure that IPv6 DAD is completed.
TODO: rtsold (rc.conf line), manpage


# 1.56 02-Jan-2000 itojun

ipv6 autoconf on hosts (non-routers).

to do this,
1. in sysctl.conf, add these lines:
net.inet6.ip6.forwarding=0
net.inet6.ip6.accept_rtadv=1
2. in hostname.foo, add
rtsol

specifying two or more interfaces with "rtsol" may result in strange
behavior - ipv6 spec does not permit multi-interface node to be autoconfig'ed.


# 1.55 02-Jan-2000 todd

add to hostname.* parsing:
- multiple entries support (read: aliases)
- inet6 support
- support for comments (#)
(look for hostname.if(5) commit for syntax details)


# 1.54 31-Dec-1999 itojun

install IPv6 reject routes only if kernel is capable of IPv6.


# 1.53 09-Dec-1999 itojun

avoid transmitting invalid IPv6 packets out to the wire.


# 1.52 09-Dec-1999 itojun

do not perform IPv6 initialization for loopback interface.
MUST make lo0 up before any IPv6 operations.
it will be considered a pilot error if you don't.
(I prefer to have lo0 initialized automatically)


Revision tags: OPENBSD_2_6_BASE
# 1.51 01-Sep-1999 deraadt

support # characters in bridgename.* files; millert


# 1.50 01-Sep-1999 deraadt

cleanup parsing of hostname.* files, and seperate bridge control into
bridgename.* files; all documented in new hostname.if(5) and
bridgename.if(5) man pages


# 1.49 09-Aug-1999 angelos

Only parse/setup the hostname.foo file if interface foo exists (this
is useful for laptops with different ethernet cards etc.)


Revision tags: OPENBSD_2_5_BASE
# 1.48 29-Mar-1999 niklas

New multicast route setup style


# 1.47 26-Mar-1999 niklas

Add bridge interface handling


# 1.46 01-Mar-1999 millert

Add support in /etc/hostname.xxx for files of the format:
up [options]
Any of the following may or may not be set:
$name $mask $bcaddr $extras


# 1.45 28-Oct-1998 millert

Kill the awful hack used to match and split /etc/hostname.* We now use
a function, isalphanumeric, to determine whether an interface name is
likely to be valid. This means that things like /etc/hostname.le0.bak,
/etc/hostname.le0#, /etc/hostname.le0~, etc. will be ignored as they
should. There is no longer an implicate assumption that /etc/hostname.*
only contains a single '.'.


Revision tags: OPENBSD_2_4_BASE
# 1.44 06-Oct-1998 deraadt

move ipnat to end of netstart, to support dhcp+ipnat


# 1.43 18-Sep-1998 deraadt

apply media directives on dhcp interfaces


# 1.42 10-Sep-1998 marc

better way of handling dhcp client; Jason Ish <jbi130@mail.usask.ca>


# 1.41 08-Sep-1998 marc

dhcp client stuff. "Angelos D. Keromytis" <angelos@dsl.cis.upenn.edu>


# 1.40 24-Aug-1998 downsj

You can't use -interface default when there's no default gateway
set (yet). Use -interface $hostname if mygate doesn't exist so that
this actually works on routers.


# 1.39 04-Jul-1998 deraadt

put 224 route on default, to avoid a hostname lookup


# 1.38 22-May-1998 deraadt

use route -n, what the heck


Revision tags: OPENBSD_2_3_BASE
# 1.37 28-Mar-1998 deraadt

s/^nat/ipnat/


# 1.36 23-Feb-1998 niklas

remove trailing blank line


# 1.35 07-Feb-1998 deraadt

ipforward is in sysctl.conf now


# 1.34 21-Dec-1997 deraadt

ugh


# 1.33 20-Dec-1997 deraadt

ipforwarding option in rc.conf


# 1.32 29-Nov-1997 kstailey

NAT requires IPF


# 1.31 04-Nov-1997 deraadt

kill spaces at ends of lines; m4


Revision tags: OPENBSD_2_2_BASE
# 1.30 14-Oct-1997 deraadt

set hostname/domainname before running rc.conf; m4@umn.edu


# 1.29 04-Sep-1997 deraadt

fork netstart; new child is rc.conf


# 1.28 25-Aug-1997 millert

Explicately pass -host flag to route(8) to avoid confusion with networks.


# 1.27 19-Aug-1997 niklas

Add hook for rpc.lockd, make nfsd flags settable in netstart


# 1.26 31-Jul-1997 downsj

Make quotas optional; wedged into netstart for the time being.
/etc/rc.conf, anyone?


# 1.25 30-Jul-1997 deraadt

do not run routed by default


# 1.24 28-Jul-1997 kstailey

Move configuration of loopback interface to before all other interfaces.
Allows the use of local caching-only nameserver with no "nameserver"
entry in /etc/resolv.conf to configure a route between the hostname
and loopback.


# 1.23 25-Jul-1997 provos

earlier start of keymanagement


# 1.22 24-Jul-1997 deraadt

make amd use /tmp_mnt by default


# 1.21 22-Jul-1997 provos

start the photuris daemon per default. hilfe.


# 1.20 17-Jun-1997 niklas

Put in hooks to start ypserv with flags


# 1.19 17-Jun-1997 niklas

Put in hooks to start rpc.yppasswdd with flags


Revision tags: OPENBSD_2_1_BASE
# 1.18 15-Apr-1997 deraadt

kill route flush until .. hmm kernel routing socket bug or something


# 1.17 09-Apr-1997 kstailey

add NAT startup


# 1.16 07-Apr-1997 rees

flush all old routes before adding new interfaces or routes.
ref: netbsd pr3228/misc, Matthias Scheler


# 1.15 03-Mar-1997 downsj

fix typo


# 1.14 11-Feb-1997 deraadt

add default route before fiddling with loopback route to avoid DNS problems; m4@umn.edu, #97


# 1.13 03-Feb-1997 deraadt

do ifaliases after /usr/bin exists in nfs diskless env; pr#77, matthieu@laas.fr


# 1.12 02-Nov-1996 deraadt

timed off by default


Revision tags: OPENBSD_2_0_BASE
# 1.11 23-Sep-1996 deraadt

rfc1323 variable


# 1.10 04-Sep-1996 deraadt

control portmap, inetd, and lpd from netstart; idea from tqbf@enteract.com


# 1.9 27-Aug-1996 deraadt

224.0.0.0 not 0.0.0.224; from peter@demon.net


# 1.8 18-Jun-1996 deraadt

move std stuff from rc.local to rc


# 1.7 16-Jun-1996 deraadt

install sample commented /etc/ifaliases file; which can now contain #
comments and blank lines. new format is "interface address netmask"
(yes, i changed the order of the entries). inspired by netbsd pr#2474;
gillhaa@ghost.whirlpool.com


# 1.6 02-Jun-1996 tholo

Install a multicast route by default


# 1.5 26-May-1996 deraadt

sync & label


# 1.4 09-Jan-1996 dm

added IP filter to netstat/rc and put examples in /usr/share/ipf


# 1.3 30-Dec-1995 deraadt

from netbsd: start mrouted like routed


# 1.2 18-Dec-1995 deraadt

/etc/ifaliases support by randy@zyzzyva.com


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.192 17-Feb-2018 rpe

- Add descriptions for the new functions ifcreate() and vifscreate()
- In ifcreate() use the exit code of the {} block directly
- In vifscreate(), use the ifconfig -C output directly in the for _vif loop
- Remove superfluous and somewhat confusing comment

OK dlg kn sthen


# 1.191 14-Feb-2018 dlg

create virtual interfaces before starting all interface config.

this resolves an ordering problem when adding pseudo interfaces to bridges

tweaks from kn@
ok mpi@ sthen@


# 1.190 10-Feb-2018 claudio

Remove some special IPv4 in IPv6 mapped prefixes that are already rejected
by the ::0.0.0.0/96 reject route added to deny all IPv4 mapped addresses.
Makes the inet6 routing table almost fit in one screen.
OK benno@


# 1.189 10-Feb-2018 florian

Load RFC 7217 key material and generate if it does not already exist.

Add soii.key to changelist (pointed out by semarie) and mtree/special
(suggest by Craig Skinner).

OK naddy, sthen, rpe, tb


# 1.188 06-Feb-2018 tb

If -n is given, the netstart script should not (try to) set the default
route(s). Simply print the command(s) to be issued instead.

tweak & ok rpe


# 1.187 12-Nov-2017 tb

Remove HN_DIR variable and expand it in the only place it was used. It
currently serves no purpose.

ok rpe, agreement from deraadt and halex


Revision tags: OPENBSD_6_2_BASE
# 1.186 25-Jul-2017 rpe

Finally remove backwards compat code to support the 'rtsol' keyword
in hostname.if(5)

OK mpi@ deraadt@ florian@
OK jmc@ from doc perspective


# 1.185 21-Jul-2017 rpe

Align ifstart() in netstart and install.sub.

- in netstart, rename _file to _hn referencing hostname.if files
- in install.sub switch ifstart() to be used with _if instead of
_hn as parameter

ok krw@ tb@


# 1.184 28-May-2017 awolk

etc/netstart: use colon separator instead of dot with chown

OK jung@, deraadt@, jmc@


# 1.183 07-May-2017 rpe

Change test from [] to [[]] and simplify pattern.

OK tb@, krw@ (for [[]])
Feedback and OK halex@


# 1.182 07-May-2017 rpe

Replace hardcoded script name with ${0##*/}

OK tb@ halex@


# 1.181 01-May-2017 rpe

Revert r1.170 and remove the id==0 check.
The id binary is not available in nfs diskless setups at this point.

reported by Andreas Kusalananda, thanks.
discussed with deraadt@


# 1.180 01-May-2017 rpe

Remove last remnants of rtsol. IPv6 autoconfiguration of interfaces is now
done in ifstart(). Remove ipv6autoconf() and replace rtsolif with a boolean
variable V6_AUTOCONF. Replace dhcpif with a boolean variable V4_DHCPCONF.
Both are later used in defaultroute() to decide whether or not to configre
defaultroutes from /etc/mygate.

OK krw@


# 1.179 30-Apr-2017 mpi

Do not try to delete a default route before adding it.

Now that route are automatically G/C with the address they are attached
to there's no reason to duplicate the kernel's job.

Fix a regression introduced with multipath default routes.

ok deraadt@


# 1.178 25-Apr-2017 rpe

Unbreak netstart for multiple inteface configurations like trunk
or carp. Ensure that the noglob option is disabled at the end of
parse_hn_line() and ifstart().

Reported by Christer Solskogen and Stefan Wollny, thanks!


# 1.177 24-Apr-2017 rpe

Introduce a new function parse_hn_line() that replaces the existing
hostname.if(5) parsing code in ifstart().
Add a -n option to netstart to only print the interface configuration
commands instead of executing them.
Add a HN_DIR variable, that points to the directory of the hostname.if
files (default /etc) that allows for future regression tests.

- add new parse_hn_line() function
- change ifstart()
- rename $if to $_if
- don't ifconfig or ifconfig create if -n option is used
- replace hostname.if(5) parsing code with new parse_hn_line()
- just print configuration commands if -n option is used
- autoconf now happens in ifstart(), remove ifv6autoconf()
- introduce HN_DIR variable for the hostname.if file location
- add handling of the -n option to only print config commands
- ensure -n is only used if interfaces are specified as parameters

Discussed with and positive feedback from many
'commit' deraadt@
OK sthen@


# 1.176 08-Apr-2017 rpe

- localize the if, file and stat variables which also ensures that
variables are not named like commands.
- change test from [] to [[]]

OK tb@ halex@


# 1.175 07-Apr-2017 rpe

Minimize differences in ifstart() function between netstart and
install.sub which makes it easier to spot changes in the future.

- comments and formatting
- quotes on assignments are not needed (netstart)
- remove stray space in test (netstart)
- use $file variable with while-loop (netstart)
- although valid, instead of i use $i in arithmetic test (install.sub)

OK krw@, tb@
Looks good deraadt@


# 1.174 07-Apr-2017 rpe

Align comments of ifstart() function in netstart and install.sub.


# 1.173 07-Apr-2017 rpe

Align comments of stripcom() function in netstart and install.sub.


Revision tags: OPENBSD_6_1_BASE
# 1.172 06-Dec-2016 mpi

Do not lose the default route when netstart(8) is run a second time on
the interface pointed to by the default route.

Since the kernel no longer keep routes with dangling address pointer,
netstart(8) has to re-add the default route when the corresponding ifa
has been deleted and re-created.

deraadt@ points out that even if the previous semantic was not necessarily
better, a script like netstart(8) cannot totally fix the default route
problem.

Regression reported by and fix tested by Hrvoje Popovski.

ksh foo checked by halex@


# 1.171 27-Sep-2016 rzalamena

Delay switch(4) interface start up so it can attach virtual interfaces
like vether(4).

nits from and ok benno@, phessler@


# 1.170 09-Sep-2016 jasper

print a clear error message when not ran as root instead of just falling
through and try whatever it can do with the invoking user's perms

feedback/ok aja@ rpe@


Revision tags: OPENBSD_6_0_BASE
# 1.169 19-Jul-2016 mpi

Do not consider tap(4) a special interface and start if before other
pseudo-interfaces.

This unbreak vlan(4) on top of tap(4) since the refactoring to turn it
MP-safe.

ok claudio@, deraadt@


# 1.168 27-Mar-2016 sthen

Don't delete the 224/4 route in netstart, unless it's being done to ensure that
a -reject route can be added. Restores the ability to set an interface route
before daemons are started, lost during the previous simplification.
ok millert mpi


Revision tags: OPENBSD_5_9_BASE
# 1.167 29-Dec-2015 rpe

Remove backslash, not necessary after '&&'

OK halex@


# 1.166 29-Dec-2015 rpe

Replace last remaining `` with $()

OK halex@


# 1.165 18-Dec-2015 ajacoutot

Drop the now useless multicast setup comment.

prodded by tim@, ok mpi@


# 1.164 17-Dec-2015 ajacoutot

Simplify multicast option handling (10 less lines) by matching /etc/rc behavior
towards other YES|NO options and drop the error warning.


with and ok tim@, ok rpe@ on an earlier diff


# 1.163 05-Dec-2015 mpi

It does not make sense to insert a specific route for 224/4 when the
default one is good enough.

So merge rc.conf(8)'s 'multicast_router' and 'multicast_host' into a
single 'multicast'. If set to YES the reject route for 224/4 is not
inserted by netstart(8).

Manual bits from jmc@

ok henning@, ajacoutot@


# 1.162 12-Nov-2015 rpe

Changes to ifautostart():
- Rename function to ifv6autoconf() to make IPv6 relation clearer
- Localize and rename variables

OK krw@


# 1.161 12-Nov-2015 rpe

Changes to ifmstart():
- Change comments to make it clearer that ifmstart() takes two lists
of interface driver names (of which the second is optional) and not
the actual interface instances.
- Use localized variables and use slightly more verbose names.
- Use continue 2 to skip to the next hostname.if file.
- Use shell pattern @() instead of testing _sif individually.

OK krw@


# 1.160 12-Nov-2015 rpe

Changes to stripcom():
- Align comments with /etc/rc version
- Use localized variables
- Use safer "print -r --" instead of plain echo

Changes to ifstart():
- Tweak comment
- Add usage

OK krw@


# 1.159 01-Nov-2015 rpe

Start the rework of the /etc/netstart shell script.

General changes:
- apply a similar 'style' as used in the installer scripts
- improve comments to be more to the point, remove where code is obvious
- document usage of functions if they have arguments
- rename variables where it improves readability
- replace really old-school shell code with more contemporary idioms

Other changes:
- No need to care about "autoboot" because netstart doesn't inherit the
positional parameters from /etc/rc anymore. /etc/rc executes netstart
instead of sourcing it since r1.439.
- Use simpler for-loop to process list of interfaces with ifstart.

OK halex@


# 1.158 26-Oct-2015 rpe

The hostname variable is not used since r1.99. Remove it and use
stripcom() output directly with the hostname command.

OK deraadt@ krw@


# 1.157 23-Oct-2015 claudio

netstart bits for tap(4)


# 1.156 27-Sep-2015 sthen

Don't print output when setting autoconf on interfaces. Suggested by deraadt,
ok florian@ rpe@


# 1.155 13-Sep-2015 sthen

only print the "IPv6 autoconf" line if there are interfaces to configure
feedback/ok rpe


# 1.154 11-Sep-2015 sthen

Set "inet6 autoconf" individually on interfaces that have rtsol set in
hostname.if, previously netstart tried to configure them all at once
("ifconfig if0 if1 if2 inet6 autoconf"). From Delan Azabani, ok phessler@


Revision tags: OPENBSD_5_8_BASE
# 1.153 20-Jul-2015 rpe

Disable Strict Bourne shell mode for /etc/rc and /etc/netstart to be
able to use ksh syntax within these scripts. This way init doesn't
need to be changed, which starts /etc/rc using /bin/sh and people
can still use "sh /etc/netstart ifname".

Idea from and OK halex@
OK deraadt@ krw@ guenther@


# 1.152 19-Jul-2015 florian

Bring up pflow last as it might send with a source address that is on
any of the other interfaces.
OK deraadt, phessler, benno


# 1.151 19-Jul-2015 rpe

Always source rc.subr to be able to use the rc.conf parsing routine
to get the network related vars from rc.conf. This is even necessary
if netstart is run from within /etc/rc. Remove test of $INRC which
unintentionally evaluated always to true.

problem with previous change found by nigel@
OK sthen@ aja@ halex@


# 1.150 19-Jul-2015 ajacoutot

Revert 1.148 for now until I can talk to rpe@
It introduced a regression reported by nigel@


# 1.149 19-Jul-2015 rpe

Replace test command with [].

OK halex@ krw@


# 1.148 19-Jul-2015 rpe

Ensure, that we source rc.subr and parse rc.conf ONLY if we are not
inside /etc/rc.

With help from and OK halex@, ajacoutot@


# 1.147 18-Jul-2015 rpe

- remove trailing blanks introduced in previous commit
- no space in redirections like </foo or >$bar
- few other minor whitespaces

OK krw@


# 1.146 18-Jul-2015 rpe

Improve comments
- Add comments for functions
- Start comments with capital letters
- End comments with a full stop
- Allow comments to extend up to column 80

OK krw@


# 1.145 06-Jun-2015 florian

Allow rtsol keyword in hostname.if(5) with net.inet6.ip6.forwarding=1.
"inet6 autoconf" was working before and rtsol should behave the same.
OK phessler


Revision tags: OPENBSD_5_7_BASE
# 1.144 03-Dec-2014 florian

The kernel handles rtsol(8) functionality since some time now.
Treat rtsol in hostname.if as a keyword like dhcp and call ifconfig
inet6 autoconf.
"reads good" todd@
OK krw@ (who is *not* an IPv6 person), but I recruited him in his
capacity as an installer person.


# 1.143 28-Sep-2014 claudio

Revert 1.142. Without the down netstart will just print the ifconfig
output because it may end up just calling 'ifconfig $if'. This needs
to be done better and properly tested.


# 1.142 26-Sep-2014 halex

remove explicit 'down' of an interface before starting a dhcp request, thereby
avoiding annoying delays for some switch configurations

ok claudio@ deraadt@

i would add ok phessler@, but it was not valid without an ok krw@


Revision tags: OPENBSD_5_6_BASE
# 1.141 12-Jul-2014 stsp

Fix netstart after autoconf6 change so 'rtsol' lines in hostname.if work again.
found by pelikan@; ok pelikan@ henning@


# 1.140 12-Jul-2014 robert

Make rc.conf a parsed configuration file and stop sourcing it as a shell
script.
From now on rc.conf has a fixed syntax (key=val) and it is not allowed
to add anything to it besides the supported syntax, it all going to be
ignored.

discussed with and help from deraadt@ and halex@


Revision tags: OPENBSD_5_5_BASE
# 1.139 22-Aug-2013 mpi

Like for dhclient, do no create a route to alias addresses via 127.0.0.1.
Our stack is able to tell if the address is local or not.

ok todd@, krw@


Revision tags: OPENBSD_5_4_BASE
# 1.138 20-Mar-2013 todd

fix lies in netstart; replacement wording from halex@
pointed out by Ryan Kavannagh rak at debian dot org


Revision tags: OPENBSD_5_3_BASE
# 1.137 05-Dec-2012 rpe

remove "Invalid interface name" message
requested by krw@

ok halex@


# 1.136 02-Dec-2012 rpe

use the more compact version of the check for ifconfig'able interfaces
from install.sub

with feedback from and ok halex


# 1.135 02-Dec-2012 rpe

- remove isalphanumeric() and replace it with a shell pattern, that
tries a bit harder to identify invalid interface names and in
this case emit an error message.
- use [[ $1 == autoboot ]] to avoid a shell error message due to
possible spaces in first argument
- no change in functionality

discussed with krw and halex
ok ("I like this") krw


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.134 07-Oct-2011 deraadt

The new ypbind changes requires that the domainname be set before
rc.conf is run. There's no real downside.
ok aja


Revision tags: OPENBSD_5_0_BASE
# 1.133 07-Jul-2011 guenther

Eliminate some $? tests by rolling the command into the condition

ok halex@


# 1.132 26-May-2011 mpf

Add svlan(4) startup bits.
From markus@. OK naddy, claudio, reyk.


Revision tags: OPENBSD_4_9_BASE
# 1.131 09-Feb-2011 sobrado

fix an unbalanced parenthesis in a comment; while here, split the comment
in a better place to make it more readable.

ok jmc@ and miod@


Revision tags: OPENBSD_4_8_BASE
# 1.130 16-Jun-2010 todd

permit e.g. -inet6 syntax by slurping all lines not just some
noticed by rhsv6 at hushmail dot com, ok sthen@


Revision tags: OPENBSD_4_7_BASE
# 1.129 12-Jan-2010 henning

when setting up lo0 use 127.0.0.1/8 instead of 127.0.0.1 for clarity and
correctness. it's not 1992 any more, kids. ok mcbride dlg krw


# 1.128 10-Dec-2009 todd

o stop reordering ifconfig arguments (e.g. after 'up ..')
o only stop processing if inet or inet6 lines are malformed
o everything not a specially handled bit is passed to ifconfig unmangled
noticed by several after the move from bridgename.bridge0 -> hostname.bridge0
prodded by deraadt@, tested by and feedback from several
man page bits 'look fine' jmc@


# 1.127 22-Nov-2009 deraadt

Stop supporting bridgename.bridge* files, and move to hostname.bridge*
files. To cope with this change, read about the mv command.
ok claudio todd


# 1.126 17-Sep-2009 simon

change variable i to $i in an expression of ifstart() for consistency
with the rest of the file. no functional change.

feedback from sthen@, ok krw@


# 1.125 10-Jul-2009 jdixon

Delay creation of tun(4) interfaces until the underlying interface and
routes are available. This fixes usage for some OpenVPN users that start
it from hostname.tun*.

Tested by Johan Huldtgren. ok sthen@, johan@.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.124 25-Nov-2008 markus

delay /etc/netstart until IPv6-DAD (dup-address-detection) is completed.
ok fries, hshoexer, claudio


# 1.123 14-Aug-2008 sthen

Tools from /usr may not be used in netstart since it may be NFS-mounted
and not available at that time. Rewrite the hostname.if permission check
to use only /bin/ls and the shell. Requested by deraadt.

ok todd, "Twisted." deraadt


Revision tags: OPENBSD_4_4_BASE
# 1.122 23-Jul-2008 sthen

Prevent warning about insecure hostnames where no /etc/hostname.*
exists. From wcmaier@.

Check target of symbolic links to avoid noise at boot and in
seucrity output where you have several interfaces symlinked to one
config file.

"If you think this is the right thing to do" deraadt@


# 1.121 09-Jun-2008 todd

warn once not 3 times in case of a non existent file, discussed with deraadt
originally pointed out by Johan Torin


# 1.120 09-Jun-2008 deraadt

Ensure that hostname.* files are also re-chowned to root.wheel at each
boot as discussed with claudio while eating tasty donairs. ok todd


# 1.119 17-Apr-2008 deraadt

before using them, force hostname.* files to be unreadable by world
first version from todd, ok millert


Revision tags: OPENBSD_4_3_BASE
# 1.118 17-Jan-2008 brad

Execute rtsol after turning up trunk(4) and vlan(4) interfaces so they're
taken into consideration for rtsol.

ok reyk@ dlg@


# 1.117 09-Jan-2008 mpf

Do not bring up pfsync(4) before the working ruleset
has been loaded. Otherwise, states that are received during the
initial bulk update mismatch the correct pf-checksum and
do not attach to the rules.
Problem identified by david@. Fix done in collaboration.
OK henning@


Revision tags: OPENBSD_4_2_BASE
# 1.116 02-Aug-2007 david

move the delay for IPv6 DAD to after all interfaces have started
fixes problems with daemons being unable to bind to all addreses at boot
ok itojun@ hshoexer@


Revision tags: OPENBSD_4_1_BASE
# 1.115 15-Nov-2006 itojun

reject multicast packet without scope identifier specified.


Revision tags: OPENBSD_4_0_BASE
# 1.114 29-Jun-2006 todd

do not add an extra space; nwid and description come out wrong
fix as proposed by maja@, thanks!


Revision tags: OPENBSD_3_9_BASE
# 1.113 28-Dec-2005 david

nuke extra whitespace


# 1.112 06-Dec-2005 reyk

multicast_host=YES only works if a valid default gateway is available.
validate this condition and reject multicast traffic on failure.

ok todd@ naddy@


# 1.111 02-Nov-2005 todd

fix inspired by pr#4590
ok krw@


# 1.110 25-Oct-2005 todd

better logic from krw@:
- do not process mygate for v4 if dhcp
- do not process mygate for v6 if rtsol
this also makes the mygate processing logic more readable
ok krw@


# 1.109 14-Oct-2005 todd

add v6 support for /etc/mygate
ok deraadt@ mickey@ krw@
same functionality tested/ok'ed by by mickey, brad, matthieu, and me
with this one may now put a v6 IP in /etc/mygate on a separate line from
the v4 default gateway and netstart will do the right thing


# 1.108 12-Oct-2005 todd

shrink stripcom(), sync with install.sub
ok krw@


# 1.107 04-Oct-2005 todd

trunk must be started after physical ethernet devices, but before vlan.
populate ifmstart lines accordingly.
prodded/tested by brad@
ok reyk@


# 1.106 28-Sep-2005 todd

use eval consistently, fixes description quotes on rtsol and dhcp
fix inspired by and closes pr 4495
ok krw@


Revision tags: OPENBSD_3_8_BASE
# 1.105 22-May-2005 todd

Introduce 'ifmstart' to deal with starting multiple interfaces minus a list
of interfaces.

This reduces the netstart script by 174 chars, 13 words, and 19 lines, but
more importantly, makes it more simple and less cluttered should more special
case/orderings be needed.

ok brad@ and pr 4197 submitter, inspired by and closes pr 4197


# 1.104 04-Apr-2005 djm

unbreak; ok pval@


# 1.103 03-Apr-2005 deraadt

if dhcp is used to get an address on any interface, ignore /etc/mygate
ok krw
(this lets us do something rather cool with the zaurus in particular)


Revision tags: OPENBSD_3_7_BASE
# 1.102 04-Jan-2005 mcbride

Bring up the carp(4) interface before default route.

ok pascoe@ mpf@


# 1.101 30-Dec-2004 millert

Add a copy of stripcom so /etc/netstart can be run standalone again.
OK deraadt@


# 1.100 19-Dec-2004 millert

Allow comments in /etc/{myname,mygate,defaultdomain}; OK deraadt@


# 1.99 04-Dec-2004 itojun

remove "route $hostname 127.0.0.1" line. deraadt ok
*** please update /etc/netstart and test if it works ok for you ***


# 1.98 20-Oct-2004 deraadt

make all route commands use -qn; ok mcbride henning


Revision tags: OPENBSD_3_6_BASE
# 1.97 29-May-2004 deraadt

one last route command lacking -qn


Revision tags: OPENBSD_3_5_BASE
# 1.96 22-Mar-2004 mcbride

Make sure pfsync is brought up before carp.

ok deraadt@


# 1.95 13-Mar-2004 mcbride

Delay pfsync(4) configuration, as the syncif has to be configured in
advance. From Thorsten Lockert.


# 1.94 14-Jan-2004 deraadt

ok, it took quite a bit of prodding but itojun finally explained why the
extra sleep 1 is in here, and we came to the conclusion it is safe to
delete it. whee.


# 1.93 13-Jan-2004 deraadt

repair v6 lo0 documentation


# 1.92 11-Jan-2004 deraadt

add loopback routes late


# 1.91 09-Jan-2004 deraadt

create all routes with -q; markus ok


# 1.90 04-Dec-2003 millert

Need to do "ifconfig create" for bridge interfaces too.


# 1.89 03-Dec-2003 markus

add support for ifconfig clone; from netbsd; ok deraadt, henning


# 1.88 20-Oct-2003 david

delay carp initialization until after physical interfaces are configured
ok mcbride@ henning@ deraadt@ todd@


Revision tags: OPENBSD_3_4_BASE
# 1.87 27-Aug-2003 henning

only try to set hostname to what /etc/myname says if that file actually exists,
otherwise preserve `hostname`
netbooted machines can live perfectly fine without it; they get their hostname
earlier.

ok krw@ cedric@


Revision tags: OPENBSD_3_3_BASE
# 1.86 16-Feb-2003 krw

Fix up some DNS verbiage to make it consistant.

Fix up default route selection by

a) Forcing user to explicitly chose 'dhcp' as a mechanism for
specifying a default route, rather than guessing based on one or more
interfaces being configured by dhcp.

b) If the user specified default route does not work, re-present the
existing default route rather than losing it.

c) Move default route selection to after nameserver activation so the
user can specify a hostname as the default route.

Change /etc/netstart so that /etc/mygate wins if a default route was
already specified (i.e. by dhcp).

ok deraadt@.


Revision tags: OPENBSD_3_2_BASE
# 1.85 16-May-2002 todd

ignore non-existent cases where '$if' evaluates to '*'.
From Andr� Lucas <andre@ae-35.com>, fixes pr # 2658.
'Looks good' from miod@, millert@, and krw@.


Revision tags: OPENBSD_3_1_BASE
# 1.84 23-Feb-2002 deraadt

re-add support for $if expansion; hamajima@nagoya.ydc.co.jp


# 1.83 21-Feb-2002 miod

Change the network components initialization order.
Change from:
o all interfaces
o all bridges
o routes
to:
o physical interfaces
o routes
o gif and gre interfaces
o bridges

Fixeski PR #2400.
Manual page updates coming soon.
Ok angelos@ chris@ deraadt@


Revision tags: OPENBSD_3_0_BASE
# 1.82 31-Jul-2001 hugh

a space before a redirect


# 1.81 06-Jul-2001 angelos

Also, source /etc/rc.conf so we can pull in the
multicast_host/multicast_router settings; this is useful if one
flushes the routing table and re-initializes.

We really need a netconfig tool of sorts.


# 1.80 06-Jul-2001 angelos

Use "route -n show -inet" to determine the default multicast iface.


# 1.79 03-Jul-2001 deraadt

pull in rc.conf early so that pf(1) startup is right; tested by jasoni, comments from millert


# 1.78 30-May-2001 deraadt

Remove ipf. Darren Reed has interpreted his (old, new, whichever)
licence in a way that makes ipf not free according to the rules we
established over 5 years ago, at www.openbsd.org/goals.html (and those
same basic rules govern the other *BSD projects too). Specifically,
Darren says that modified versions are not permitted. But software
which OpenBSD uses and redistributes must be free to all (be they
people or companies), for any purpose they wish to use it, including
modification, use, peeing on, or even integration into baby mulching
machines or atomic bombs to be dropped on Australia. Furthermore, we
know of a number of companies using ipf with modification like us, who
are now in the same situation, and we hope that some of them will work
with us to fill this gap that now exists in OpenBSD (temporarily, we
hope).


Revision tags: OPENBSD_2_9_BASE
# 1.77 13-Mar-2001 deraadt

spelling; maurice@maurice.wan.nl


# 1.76 06-Feb-2001 todd

ignore blank lines in addition to comments
fixes pr#1660 from wilfried@telia.com .. Thanks!


# 1.75 10-Jan-2001 jason

support !command in bridgename.if files, too


# 1.74 27-Nov-2000 millert

Use -n to test if a variable is non-zero. Otherwise, if the variable's
contents start with a '-' test becomes unhappy (since it interprets it
as another option).


# 1.73 08-Nov-2000 todd

This fixes pr 1481, we now handle args > 6 in /etc/hostname.if in the
cases where we did not previously handle them.
Thanks to Scott Atwood <atwood@cs.stanford.edu> for reminding us of this.


Revision tags: OPENBSD_2_8_BASE
# 1.72 02-Sep-2000 todd

subtle bug .. global variables in a while loop need reset 'just incase'
With:
hostname.fxp0 having a last line of:
inet6 alias 3ffe:...
and hostname.gif0 having a first two lines of:
giftunnel 1.2.3.4
dest 1.2.4.3
We end up with the command:
ifconfig gif0 giftunnel alias 1.2.3.4 1.2.4.3
.. which is clearly wrong and fixed by this change


# 1.71 18-Jun-2000 todd

rc.conf now parses ${local_rcconf} internally; closes pr 1259


Revision tags: OPENBSD_2_7_BASE
# 1.70 08-May-2000 todd

fix dhcp 'NONE' ness from install to allow media parsing to work
.. ok deraadt@, millert@


# 1.69 21-Apr-2000 deraadt

rc.conf.local support, inspired by chuck yerkes


# 1.68 04-Apr-2000 millert

Remove the -E flag from ipf as it is implicitly enabled and using
the -E flag here causes the kernel to printf 'IP Filter: already
initialized'.


# 1.67 18-Mar-2000 deraadt

silence all extra route addition printouts


# 1.66 17-Mar-2000 itojun

correct reject route installations for IPv6. improve comments.


# 1.65 12-Mar-2000 itojun

disallow packets to malicious 6to4 prefix, based on
http://playground.iijlab.net/i-d/draft-itojun-ipv6-transition-abuse-00.txt


# 1.64 10-Mar-2000 todd

fix non behavior
with this `!' lines in /etc/hostname.* run even without certain lines
(like a comment) preceeding it.


# 1.63 10-Jan-2000 todd

allow arbitrary commands in /etc/hostname.* files if the line starts with '!'


# 1.62 02-Jan-2000 deraadt

rtsol case can configure the interface up, since it would be nice to finish
DAD before the actual rtsol(8) run happens later. and since it will rtsol,
it is going to be up in any case.


# 1.61 02-Jan-2000 itojun

one more indentation fix.


# 1.60 02-Jan-2000 itojun

indentation fix (todd's part)


# 1.59 02-Jan-2000 todd

fix rtsold case, reset cmd for each iteration!


# 1.58 02-Jan-2000 itojun

allow options after "rtsol".
XXX both "dhcp" and "rtsol" has keyword *down* at the end. is it okay?


# 1.57 02-Jan-2000 itojun

echo "IPv6 autoconf: interfaces" before invoking rtsol.
sleep for net.inet6.ip6.dad_count seconds to ensure that IPv6 DAD is completed.
TODO: rtsold (rc.conf line), manpage


# 1.56 02-Jan-2000 itojun

ipv6 autoconf on hosts (non-routers).

to do this,
1. in sysctl.conf, add these lines:
net.inet6.ip6.forwarding=0
net.inet6.ip6.accept_rtadv=1
2. in hostname.foo, add
rtsol

specifying two or more interfaces with "rtsol" may result in strange
behavior - ipv6 spec does not permit multi-interface node to be autoconfig'ed.


# 1.55 02-Jan-2000 todd

add to hostname.* parsing:
- multiple entries support (read: aliases)
- inet6 support
- support for comments (#)
(look for hostname.if(5) commit for syntax details)


# 1.54 31-Dec-1999 itojun

install IPv6 reject routes only if kernel is capable of IPv6.


# 1.53 09-Dec-1999 itojun

avoid transmitting invalid IPv6 packets out to the wire.


# 1.52 09-Dec-1999 itojun

do not perform IPv6 initialization for loopback interface.
MUST make lo0 up before any IPv6 operations.
it will be considered a pilot error if you don't.
(I prefer to have lo0 initialized automatically)


Revision tags: OPENBSD_2_6_BASE
# 1.51 01-Sep-1999 deraadt

support # characters in bridgename.* files; millert


# 1.50 01-Sep-1999 deraadt

cleanup parsing of hostname.* files, and seperate bridge control into
bridgename.* files; all documented in new hostname.if(5) and
bridgename.if(5) man pages


# 1.49 09-Aug-1999 angelos

Only parse/setup the hostname.foo file if interface foo exists (this
is useful for laptops with different ethernet cards etc.)


Revision tags: OPENBSD_2_5_BASE
# 1.48 29-Mar-1999 niklas

New multicast route setup style


# 1.47 26-Mar-1999 niklas

Add bridge interface handling


# 1.46 01-Mar-1999 millert

Add support in /etc/hostname.xxx for files of the format:
up [options]
Any of the following may or may not be set:
$name $mask $bcaddr $extras


# 1.45 28-Oct-1998 millert

Kill the awful hack used to match and split /etc/hostname.* We now use
a function, isalphanumeric, to determine whether an interface name is
likely to be valid. This means that things like /etc/hostname.le0.bak,
/etc/hostname.le0#, /etc/hostname.le0~, etc. will be ignored as they
should. There is no longer an implicate assumption that /etc/hostname.*
only contains a single '.'.


Revision tags: OPENBSD_2_4_BASE
# 1.44 06-Oct-1998 deraadt

move ipnat to end of netstart, to support dhcp+ipnat


# 1.43 18-Sep-1998 deraadt

apply media directives on dhcp interfaces


# 1.42 10-Sep-1998 marc

better way of handling dhcp client; Jason Ish <jbi130@mail.usask.ca>


# 1.41 08-Sep-1998 marc

dhcp client stuff. "Angelos D. Keromytis" <angelos@dsl.cis.upenn.edu>


# 1.40 24-Aug-1998 downsj

You can't use -interface default when there's no default gateway
set (yet). Use -interface $hostname if mygate doesn't exist so that
this actually works on routers.


# 1.39 04-Jul-1998 deraadt

put 224 route on default, to avoid a hostname lookup


# 1.38 22-May-1998 deraadt

use route -n, what the heck


Revision tags: OPENBSD_2_3_BASE
# 1.37 28-Mar-1998 deraadt

s/^nat/ipnat/


# 1.36 23-Feb-1998 niklas

remove trailing blank line


# 1.35 07-Feb-1998 deraadt

ipforward is in sysctl.conf now


# 1.34 21-Dec-1997 deraadt

ugh


# 1.33 20-Dec-1997 deraadt

ipforwarding option in rc.conf


# 1.32 29-Nov-1997 kstailey

NAT requires IPF


# 1.31 04-Nov-1997 deraadt

kill spaces at ends of lines; m4


Revision tags: OPENBSD_2_2_BASE
# 1.30 14-Oct-1997 deraadt

set hostname/domainname before running rc.conf; m4@umn.edu


# 1.29 04-Sep-1997 deraadt

fork netstart; new child is rc.conf


# 1.28 25-Aug-1997 millert

Explicately pass -host flag to route(8) to avoid confusion with networks.


# 1.27 19-Aug-1997 niklas

Add hook for rpc.lockd, make nfsd flags settable in netstart


# 1.26 31-Jul-1997 downsj

Make quotas optional; wedged into netstart for the time being.
/etc/rc.conf, anyone?


# 1.25 30-Jul-1997 deraadt

do not run routed by default


# 1.24 28-Jul-1997 kstailey

Move configuration of loopback interface to before all other interfaces.
Allows the use of local caching-only nameserver with no "nameserver"
entry in /etc/resolv.conf to configure a route between the hostname
and loopback.


# 1.23 25-Jul-1997 provos

earlier start of keymanagement


# 1.22 24-Jul-1997 deraadt

make amd use /tmp_mnt by default


# 1.21 22-Jul-1997 provos

start the photuris daemon per default. hilfe.


# 1.20 17-Jun-1997 niklas

Put in hooks to start ypserv with flags


# 1.19 17-Jun-1997 niklas

Put in hooks to start rpc.yppasswdd with flags


Revision tags: OPENBSD_2_1_BASE
# 1.18 15-Apr-1997 deraadt

kill route flush until .. hmm kernel routing socket bug or something


# 1.17 09-Apr-1997 kstailey

add NAT startup


# 1.16 07-Apr-1997 rees

flush all old routes before adding new interfaces or routes.
ref: netbsd pr3228/misc, Matthias Scheler


# 1.15 03-Mar-1997 downsj

fix typo


# 1.14 11-Feb-1997 deraadt

add default route before fiddling with loopback route to avoid DNS problems; m4@umn.edu, #97


# 1.13 03-Feb-1997 deraadt

do ifaliases after /usr/bin exists in nfs diskless env; pr#77, matthieu@laas.fr


# 1.12 02-Nov-1996 deraadt

timed off by default


Revision tags: OPENBSD_2_0_BASE
# 1.11 23-Sep-1996 deraadt

rfc1323 variable


# 1.10 04-Sep-1996 deraadt

control portmap, inetd, and lpd from netstart; idea from tqbf@enteract.com


# 1.9 27-Aug-1996 deraadt

224.0.0.0 not 0.0.0.224; from peter@demon.net


# 1.8 18-Jun-1996 deraadt

move std stuff from rc.local to rc


# 1.7 16-Jun-1996 deraadt

install sample commented /etc/ifaliases file; which can now contain #
comments and blank lines. new format is "interface address netmask"
(yes, i changed the order of the entries). inspired by netbsd pr#2474;
gillhaa@ghost.whirlpool.com


# 1.6 02-Jun-1996 tholo

Install a multicast route by default


# 1.5 26-May-1996 deraadt

sync & label


# 1.4 09-Jan-1996 dm

added IP filter to netstat/rc and put examples in /usr/share/ipf


# 1.3 30-Dec-1995 deraadt

from netbsd: start mrouted like routed


# 1.2 18-Dec-1995 deraadt

/etc/ifaliases support by randy@zyzzyva.com


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.191 14-Feb-2018 dlg

create virtual interfaces before starting all interface config.

this resolves an ordering problem when adding pseudo interfaces to bridges

tweaks from kn@
ok mpi@ sthen@


# 1.190 10-Feb-2018 claudio

Remove some special IPv4 in IPv6 mapped prefixes that are already rejected
by the ::0.0.0.0/96 reject route added to deny all IPv4 mapped addresses.
Makes the inet6 routing table almost fit in one screen.
OK benno@


# 1.189 10-Feb-2018 florian

Load RFC 7217 key material and generate if it does not already exist.

Add soii.key to changelist (pointed out by semarie) and mtree/special
(suggest by Craig Skinner).

OK naddy, sthen, rpe, tb


# 1.188 06-Feb-2018 tb

If -n is given, the netstart script should not (try to) set the default
route(s). Simply print the command(s) to be issued instead.

tweak & ok rpe


# 1.187 12-Nov-2017 tb

Remove HN_DIR variable and expand it in the only place it was used. It
currently serves no purpose.

ok rpe, agreement from deraadt and halex


Revision tags: OPENBSD_6_2_BASE
# 1.186 25-Jul-2017 rpe

Finally remove backwards compat code to support the 'rtsol' keyword
in hostname.if(5)

OK mpi@ deraadt@ florian@
OK jmc@ from doc perspective


# 1.185 21-Jul-2017 rpe

Align ifstart() in netstart and install.sub.

- in netstart, rename _file to _hn referencing hostname.if files
- in install.sub switch ifstart() to be used with _if instead of
_hn as parameter

ok krw@ tb@


# 1.184 28-May-2017 awolk

etc/netstart: use colon separator instead of dot with chown

OK jung@, deraadt@, jmc@


# 1.183 07-May-2017 rpe

Change test from [] to [[]] and simplify pattern.

OK tb@, krw@ (for [[]])
Feedback and OK halex@


# 1.182 07-May-2017 rpe

Replace hardcoded script name with ${0##*/}

OK tb@ halex@


# 1.181 01-May-2017 rpe

Revert r1.170 and remove the id==0 check.
The id binary is not available in nfs diskless setups at this point.

reported by Andreas Kusalananda, thanks.
discussed with deraadt@


# 1.180 01-May-2017 rpe

Remove last remnants of rtsol. IPv6 autoconfiguration of interfaces is now
done in ifstart(). Remove ipv6autoconf() and replace rtsolif with a boolean
variable V6_AUTOCONF. Replace dhcpif with a boolean variable V4_DHCPCONF.
Both are later used in defaultroute() to decide whether or not to configre
defaultroutes from /etc/mygate.

OK krw@


# 1.179 30-Apr-2017 mpi

Do not try to delete a default route before adding it.

Now that route are automatically G/C with the address they are attached
to there's no reason to duplicate the kernel's job.

Fix a regression introduced with multipath default routes.

ok deraadt@


# 1.178 25-Apr-2017 rpe

Unbreak netstart for multiple inteface configurations like trunk
or carp. Ensure that the noglob option is disabled at the end of
parse_hn_line() and ifstart().

Reported by Christer Solskogen and Stefan Wollny, thanks!


# 1.177 24-Apr-2017 rpe

Introduce a new function parse_hn_line() that replaces the existing
hostname.if(5) parsing code in ifstart().
Add a -n option to netstart to only print the interface configuration
commands instead of executing them.
Add a HN_DIR variable, that points to the directory of the hostname.if
files (default /etc) that allows for future regression tests.

- add new parse_hn_line() function
- change ifstart()
- rename $if to $_if
- don't ifconfig or ifconfig create if -n option is used
- replace hostname.if(5) parsing code with new parse_hn_line()
- just print configuration commands if -n option is used
- autoconf now happens in ifstart(), remove ifv6autoconf()
- introduce HN_DIR variable for the hostname.if file location
- add handling of the -n option to only print config commands
- ensure -n is only used if interfaces are specified as parameters

Discussed with and positive feedback from many
'commit' deraadt@
OK sthen@


# 1.176 08-Apr-2017 rpe

- localize the if, file and stat variables which also ensures that
variables are not named like commands.
- change test from [] to [[]]

OK tb@ halex@


# 1.175 07-Apr-2017 rpe

Minimize differences in ifstart() function between netstart and
install.sub which makes it easier to spot changes in the future.

- comments and formatting
- quotes on assignments are not needed (netstart)
- remove stray space in test (netstart)
- use $file variable with while-loop (netstart)
- although valid, instead of i use $i in arithmetic test (install.sub)

OK krw@, tb@
Looks good deraadt@


# 1.174 07-Apr-2017 rpe

Align comments of ifstart() function in netstart and install.sub.


# 1.173 07-Apr-2017 rpe

Align comments of stripcom() function in netstart and install.sub.


Revision tags: OPENBSD_6_1_BASE
# 1.172 06-Dec-2016 mpi

Do not lose the default route when netstart(8) is run a second time on
the interface pointed to by the default route.

Since the kernel no longer keep routes with dangling address pointer,
netstart(8) has to re-add the default route when the corresponding ifa
has been deleted and re-created.

deraadt@ points out that even if the previous semantic was not necessarily
better, a script like netstart(8) cannot totally fix the default route
problem.

Regression reported by and fix tested by Hrvoje Popovski.

ksh foo checked by halex@


# 1.171 27-Sep-2016 rzalamena

Delay switch(4) interface start up so it can attach virtual interfaces
like vether(4).

nits from and ok benno@, phessler@


# 1.170 09-Sep-2016 jasper

print a clear error message when not ran as root instead of just falling
through and try whatever it can do with the invoking user's perms

feedback/ok aja@ rpe@


Revision tags: OPENBSD_6_0_BASE
# 1.169 19-Jul-2016 mpi

Do not consider tap(4) a special interface and start if before other
pseudo-interfaces.

This unbreak vlan(4) on top of tap(4) since the refactoring to turn it
MP-safe.

ok claudio@, deraadt@


# 1.168 27-Mar-2016 sthen

Don't delete the 224/4 route in netstart, unless it's being done to ensure that
a -reject route can be added. Restores the ability to set an interface route
before daemons are started, lost during the previous simplification.
ok millert mpi


Revision tags: OPENBSD_5_9_BASE
# 1.167 29-Dec-2015 rpe

Remove backslash, not necessary after '&&'

OK halex@


# 1.166 29-Dec-2015 rpe

Replace last remaining `` with $()

OK halex@


# 1.165 18-Dec-2015 ajacoutot

Drop the now useless multicast setup comment.

prodded by tim@, ok mpi@


# 1.164 17-Dec-2015 ajacoutot

Simplify multicast option handling (10 less lines) by matching /etc/rc behavior
towards other YES|NO options and drop the error warning.


with and ok tim@, ok rpe@ on an earlier diff


# 1.163 05-Dec-2015 mpi

It does not make sense to insert a specific route for 224/4 when the
default one is good enough.

So merge rc.conf(8)'s 'multicast_router' and 'multicast_host' into a
single 'multicast'. If set to YES the reject route for 224/4 is not
inserted by netstart(8).

Manual bits from jmc@

ok henning@, ajacoutot@


# 1.162 12-Nov-2015 rpe

Changes to ifautostart():
- Rename function to ifv6autoconf() to make IPv6 relation clearer
- Localize and rename variables

OK krw@


# 1.161 12-Nov-2015 rpe

Changes to ifmstart():
- Change comments to make it clearer that ifmstart() takes two lists
of interface driver names (of which the second is optional) and not
the actual interface instances.
- Use localized variables and use slightly more verbose names.
- Use continue 2 to skip to the next hostname.if file.
- Use shell pattern @() instead of testing _sif individually.

OK krw@


# 1.160 12-Nov-2015 rpe

Changes to stripcom():
- Align comments with /etc/rc version
- Use localized variables
- Use safer "print -r --" instead of plain echo

Changes to ifstart():
- Tweak comment
- Add usage

OK krw@


# 1.159 01-Nov-2015 rpe

Start the rework of the /etc/netstart shell script.

General changes:
- apply a similar 'style' as used in the installer scripts
- improve comments to be more to the point, remove where code is obvious
- document usage of functions if they have arguments
- rename variables where it improves readability
- replace really old-school shell code with more contemporary idioms

Other changes:
- No need to care about "autoboot" because netstart doesn't inherit the
positional parameters from /etc/rc anymore. /etc/rc executes netstart
instead of sourcing it since r1.439.
- Use simpler for-loop to process list of interfaces with ifstart.

OK halex@


# 1.158 26-Oct-2015 rpe

The hostname variable is not used since r1.99. Remove it and use
stripcom() output directly with the hostname command.

OK deraadt@ krw@


# 1.157 23-Oct-2015 claudio

netstart bits for tap(4)


# 1.156 27-Sep-2015 sthen

Don't print output when setting autoconf on interfaces. Suggested by deraadt,
ok florian@ rpe@


# 1.155 13-Sep-2015 sthen

only print the "IPv6 autoconf" line if there are interfaces to configure
feedback/ok rpe


# 1.154 11-Sep-2015 sthen

Set "inet6 autoconf" individually on interfaces that have rtsol set in
hostname.if, previously netstart tried to configure them all at once
("ifconfig if0 if1 if2 inet6 autoconf"). From Delan Azabani, ok phessler@


Revision tags: OPENBSD_5_8_BASE
# 1.153 20-Jul-2015 rpe

Disable Strict Bourne shell mode for /etc/rc and /etc/netstart to be
able to use ksh syntax within these scripts. This way init doesn't
need to be changed, which starts /etc/rc using /bin/sh and people
can still use "sh /etc/netstart ifname".

Idea from and OK halex@
OK deraadt@ krw@ guenther@


# 1.152 19-Jul-2015 florian

Bring up pflow last as it might send with a source address that is on
any of the other interfaces.
OK deraadt, phessler, benno


# 1.151 19-Jul-2015 rpe

Always source rc.subr to be able to use the rc.conf parsing routine
to get the network related vars from rc.conf. This is even necessary
if netstart is run from within /etc/rc. Remove test of $INRC which
unintentionally evaluated always to true.

problem with previous change found by nigel@
OK sthen@ aja@ halex@


# 1.150 19-Jul-2015 ajacoutot

Revert 1.148 for now until I can talk to rpe@
It introduced a regression reported by nigel@


# 1.149 19-Jul-2015 rpe

Replace test command with [].

OK halex@ krw@


# 1.148 19-Jul-2015 rpe

Ensure, that we source rc.subr and parse rc.conf ONLY if we are not
inside /etc/rc.

With help from and OK halex@, ajacoutot@


# 1.147 18-Jul-2015 rpe

- remove trailing blanks introduced in previous commit
- no space in redirections like </foo or >$bar
- few other minor whitespaces

OK krw@


# 1.146 18-Jul-2015 rpe

Improve comments
- Add comments for functions
- Start comments with capital letters
- End comments with a full stop
- Allow comments to extend up to column 80

OK krw@


# 1.145 06-Jun-2015 florian

Allow rtsol keyword in hostname.if(5) with net.inet6.ip6.forwarding=1.
"inet6 autoconf" was working before and rtsol should behave the same.
OK phessler


Revision tags: OPENBSD_5_7_BASE
# 1.144 03-Dec-2014 florian

The kernel handles rtsol(8) functionality since some time now.
Treat rtsol in hostname.if as a keyword like dhcp and call ifconfig
inet6 autoconf.
"reads good" todd@
OK krw@ (who is *not* an IPv6 person), but I recruited him in his
capacity as an installer person.


# 1.143 28-Sep-2014 claudio

Revert 1.142. Without the down netstart will just print the ifconfig
output because it may end up just calling 'ifconfig $if'. This needs
to be done better and properly tested.


# 1.142 26-Sep-2014 halex

remove explicit 'down' of an interface before starting a dhcp request, thereby
avoiding annoying delays for some switch configurations

ok claudio@ deraadt@

i would add ok phessler@, but it was not valid without an ok krw@


Revision tags: OPENBSD_5_6_BASE
# 1.141 12-Jul-2014 stsp

Fix netstart after autoconf6 change so 'rtsol' lines in hostname.if work again.
found by pelikan@; ok pelikan@ henning@


# 1.140 12-Jul-2014 robert

Make rc.conf a parsed configuration file and stop sourcing it as a shell
script.
From now on rc.conf has a fixed syntax (key=val) and it is not allowed
to add anything to it besides the supported syntax, it all going to be
ignored.

discussed with and help from deraadt@ and halex@


Revision tags: OPENBSD_5_5_BASE
# 1.139 22-Aug-2013 mpi

Like for dhclient, do no create a route to alias addresses via 127.0.0.1.
Our stack is able to tell if the address is local or not.

ok todd@, krw@


Revision tags: OPENBSD_5_4_BASE
# 1.138 20-Mar-2013 todd

fix lies in netstart; replacement wording from halex@
pointed out by Ryan Kavannagh rak at debian dot org


Revision tags: OPENBSD_5_3_BASE
# 1.137 05-Dec-2012 rpe

remove "Invalid interface name" message
requested by krw@

ok halex@


# 1.136 02-Dec-2012 rpe

use the more compact version of the check for ifconfig'able interfaces
from install.sub

with feedback from and ok halex


# 1.135 02-Dec-2012 rpe

- remove isalphanumeric() and replace it with a shell pattern, that
tries a bit harder to identify invalid interface names and in
this case emit an error message.
- use [[ $1 == autoboot ]] to avoid a shell error message due to
possible spaces in first argument
- no change in functionality

discussed with krw and halex
ok ("I like this") krw


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.134 07-Oct-2011 deraadt

The new ypbind changes requires that the domainname be set before
rc.conf is run. There's no real downside.
ok aja


Revision tags: OPENBSD_5_0_BASE
# 1.133 07-Jul-2011 guenther

Eliminate some $? tests by rolling the command into the condition

ok halex@


# 1.132 26-May-2011 mpf

Add svlan(4) startup bits.
From markus@. OK naddy, claudio, reyk.


Revision tags: OPENBSD_4_9_BASE
# 1.131 09-Feb-2011 sobrado

fix an unbalanced parenthesis in a comment; while here, split the comment
in a better place to make it more readable.

ok jmc@ and miod@


Revision tags: OPENBSD_4_8_BASE
# 1.130 16-Jun-2010 todd

permit e.g. -inet6 syntax by slurping all lines not just some
noticed by rhsv6 at hushmail dot com, ok sthen@


Revision tags: OPENBSD_4_7_BASE
# 1.129 12-Jan-2010 henning

when setting up lo0 use 127.0.0.1/8 instead of 127.0.0.1 for clarity and
correctness. it's not 1992 any more, kids. ok mcbride dlg krw


# 1.128 10-Dec-2009 todd

o stop reordering ifconfig arguments (e.g. after 'up ..')
o only stop processing if inet or inet6 lines are malformed
o everything not a specially handled bit is passed to ifconfig unmangled
noticed by several after the move from bridgename.bridge0 -> hostname.bridge0
prodded by deraadt@, tested by and feedback from several
man page bits 'look fine' jmc@


# 1.127 22-Nov-2009 deraadt

Stop supporting bridgename.bridge* files, and move to hostname.bridge*
files. To cope with this change, read about the mv command.
ok claudio todd


# 1.126 17-Sep-2009 simon

change variable i to $i in an expression of ifstart() for consistency
with the rest of the file. no functional change.

feedback from sthen@, ok krw@


# 1.125 10-Jul-2009 jdixon

Delay creation of tun(4) interfaces until the underlying interface and
routes are available. This fixes usage for some OpenVPN users that start
it from hostname.tun*.

Tested by Johan Huldtgren. ok sthen@, johan@.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.124 25-Nov-2008 markus

delay /etc/netstart until IPv6-DAD (dup-address-detection) is completed.
ok fries, hshoexer, claudio


# 1.123 14-Aug-2008 sthen

Tools from /usr may not be used in netstart since it may be NFS-mounted
and not available at that time. Rewrite the hostname.if permission check
to use only /bin/ls and the shell. Requested by deraadt.

ok todd, "Twisted." deraadt


Revision tags: OPENBSD_4_4_BASE
# 1.122 23-Jul-2008 sthen

Prevent warning about insecure hostnames where no /etc/hostname.*
exists. From wcmaier@.

Check target of symbolic links to avoid noise at boot and in
seucrity output where you have several interfaces symlinked to one
config file.

"If you think this is the right thing to do" deraadt@


# 1.121 09-Jun-2008 todd

warn once not 3 times in case of a non existent file, discussed with deraadt
originally pointed out by Johan Torin


# 1.120 09-Jun-2008 deraadt

Ensure that hostname.* files are also re-chowned to root.wheel at each
boot as discussed with claudio while eating tasty donairs. ok todd


# 1.119 17-Apr-2008 deraadt

before using them, force hostname.* files to be unreadable by world
first version from todd, ok millert


Revision tags: OPENBSD_4_3_BASE
# 1.118 17-Jan-2008 brad

Execute rtsol after turning up trunk(4) and vlan(4) interfaces so they're
taken into consideration for rtsol.

ok reyk@ dlg@


# 1.117 09-Jan-2008 mpf

Do not bring up pfsync(4) before the working ruleset
has been loaded. Otherwise, states that are received during the
initial bulk update mismatch the correct pf-checksum and
do not attach to the rules.
Problem identified by david@. Fix done in collaboration.
OK henning@


Revision tags: OPENBSD_4_2_BASE
# 1.116 02-Aug-2007 david

move the delay for IPv6 DAD to after all interfaces have started
fixes problems with daemons being unable to bind to all addreses at boot
ok itojun@ hshoexer@


Revision tags: OPENBSD_4_1_BASE
# 1.115 15-Nov-2006 itojun

reject multicast packet without scope identifier specified.


Revision tags: OPENBSD_4_0_BASE
# 1.114 29-Jun-2006 todd

do not add an extra space; nwid and description come out wrong
fix as proposed by maja@, thanks!


Revision tags: OPENBSD_3_9_BASE
# 1.113 28-Dec-2005 david

nuke extra whitespace


# 1.112 06-Dec-2005 reyk

multicast_host=YES only works if a valid default gateway is available.
validate this condition and reject multicast traffic on failure.

ok todd@ naddy@


# 1.111 02-Nov-2005 todd

fix inspired by pr#4590
ok krw@


# 1.110 25-Oct-2005 todd

better logic from krw@:
- do not process mygate for v4 if dhcp
- do not process mygate for v6 if rtsol
this also makes the mygate processing logic more readable
ok krw@


# 1.109 14-Oct-2005 todd

add v6 support for /etc/mygate
ok deraadt@ mickey@ krw@
same functionality tested/ok'ed by by mickey, brad, matthieu, and me
with this one may now put a v6 IP in /etc/mygate on a separate line from
the v4 default gateway and netstart will do the right thing


# 1.108 12-Oct-2005 todd

shrink stripcom(), sync with install.sub
ok krw@


# 1.107 04-Oct-2005 todd

trunk must be started after physical ethernet devices, but before vlan.
populate ifmstart lines accordingly.
prodded/tested by brad@
ok reyk@


# 1.106 28-Sep-2005 todd

use eval consistently, fixes description quotes on rtsol and dhcp
fix inspired by and closes pr 4495
ok krw@


Revision tags: OPENBSD_3_8_BASE
# 1.105 22-May-2005 todd

Introduce 'ifmstart' to deal with starting multiple interfaces minus a list
of interfaces.

This reduces the netstart script by 174 chars, 13 words, and 19 lines, but
more importantly, makes it more simple and less cluttered should more special
case/orderings be needed.

ok brad@ and pr 4197 submitter, inspired by and closes pr 4197


# 1.104 04-Apr-2005 djm

unbreak; ok pval@


# 1.103 03-Apr-2005 deraadt

if dhcp is used to get an address on any interface, ignore /etc/mygate
ok krw
(this lets us do something rather cool with the zaurus in particular)


Revision tags: OPENBSD_3_7_BASE
# 1.102 04-Jan-2005 mcbride

Bring up the carp(4) interface before default route.

ok pascoe@ mpf@


# 1.101 30-Dec-2004 millert

Add a copy of stripcom so /etc/netstart can be run standalone again.
OK deraadt@


# 1.100 19-Dec-2004 millert

Allow comments in /etc/{myname,mygate,defaultdomain}; OK deraadt@


# 1.99 04-Dec-2004 itojun

remove "route $hostname 127.0.0.1" line. deraadt ok
*** please update /etc/netstart and test if it works ok for you ***


# 1.98 20-Oct-2004 deraadt

make all route commands use -qn; ok mcbride henning


Revision tags: OPENBSD_3_6_BASE
# 1.97 29-May-2004 deraadt

one last route command lacking -qn


Revision tags: OPENBSD_3_5_BASE
# 1.96 22-Mar-2004 mcbride

Make sure pfsync is brought up before carp.

ok deraadt@


# 1.95 13-Mar-2004 mcbride

Delay pfsync(4) configuration, as the syncif has to be configured in
advance. From Thorsten Lockert.


# 1.94 14-Jan-2004 deraadt

ok, it took quite a bit of prodding but itojun finally explained why the
extra sleep 1 is in here, and we came to the conclusion it is safe to
delete it. whee.


# 1.93 13-Jan-2004 deraadt

repair v6 lo0 documentation


# 1.92 11-Jan-2004 deraadt

add loopback routes late


# 1.91 09-Jan-2004 deraadt

create all routes with -q; markus ok


# 1.90 04-Dec-2003 millert

Need to do "ifconfig create" for bridge interfaces too.


# 1.89 03-Dec-2003 markus

add support for ifconfig clone; from netbsd; ok deraadt, henning


# 1.88 20-Oct-2003 david

delay carp initialization until after physical interfaces are configured
ok mcbride@ henning@ deraadt@ todd@


Revision tags: OPENBSD_3_4_BASE
# 1.87 27-Aug-2003 henning

only try to set hostname to what /etc/myname says if that file actually exists,
otherwise preserve `hostname`
netbooted machines can live perfectly fine without it; they get their hostname
earlier.

ok krw@ cedric@


Revision tags: OPENBSD_3_3_BASE
# 1.86 16-Feb-2003 krw

Fix up some DNS verbiage to make it consistant.

Fix up default route selection by

a) Forcing user to explicitly chose 'dhcp' as a mechanism for
specifying a default route, rather than guessing based on one or more
interfaces being configured by dhcp.

b) If the user specified default route does not work, re-present the
existing default route rather than losing it.

c) Move default route selection to after nameserver activation so the
user can specify a hostname as the default route.

Change /etc/netstart so that /etc/mygate wins if a default route was
already specified (i.e. by dhcp).

ok deraadt@.


Revision tags: OPENBSD_3_2_BASE
# 1.85 16-May-2002 todd

ignore non-existent cases where '$if' evaluates to '*'.
From Andr� Lucas <andre@ae-35.com>, fixes pr # 2658.
'Looks good' from miod@, millert@, and krw@.


Revision tags: OPENBSD_3_1_BASE
# 1.84 23-Feb-2002 deraadt

re-add support for $if expansion; hamajima@nagoya.ydc.co.jp


# 1.83 21-Feb-2002 miod

Change the network components initialization order.
Change from:
o all interfaces
o all bridges
o routes
to:
o physical interfaces
o routes
o gif and gre interfaces
o bridges

Fixeski PR #2400.
Manual page updates coming soon.
Ok angelos@ chris@ deraadt@


Revision tags: OPENBSD_3_0_BASE
# 1.82 31-Jul-2001 hugh

a space before a redirect


# 1.81 06-Jul-2001 angelos

Also, source /etc/rc.conf so we can pull in the
multicast_host/multicast_router settings; this is useful if one
flushes the routing table and re-initializes.

We really need a netconfig tool of sorts.


# 1.80 06-Jul-2001 angelos

Use "route -n show -inet" to determine the default multicast iface.


# 1.79 03-Jul-2001 deraadt

pull in rc.conf early so that pf(1) startup is right; tested by jasoni, comments from millert


# 1.78 30-May-2001 deraadt

Remove ipf. Darren Reed has interpreted his (old, new, whichever)
licence in a way that makes ipf not free according to the rules we
established over 5 years ago, at www.openbsd.org/goals.html (and those
same basic rules govern the other *BSD projects too). Specifically,
Darren says that modified versions are not permitted. But software
which OpenBSD uses and redistributes must be free to all (be they
people or companies), for any purpose they wish to use it, including
modification, use, peeing on, or even integration into baby mulching
machines or atomic bombs to be dropped on Australia. Furthermore, we
know of a number of companies using ipf with modification like us, who
are now in the same situation, and we hope that some of them will work
with us to fill this gap that now exists in OpenBSD (temporarily, we
hope).


Revision tags: OPENBSD_2_9_BASE
# 1.77 13-Mar-2001 deraadt

spelling; maurice@maurice.wan.nl


# 1.76 06-Feb-2001 todd

ignore blank lines in addition to comments
fixes pr#1660 from wilfried@telia.com .. Thanks!


# 1.75 10-Jan-2001 jason

support !command in bridgename.if files, too


# 1.74 27-Nov-2000 millert

Use -n to test if a variable is non-zero. Otherwise, if the variable's
contents start with a '-' test becomes unhappy (since it interprets it
as another option).


# 1.73 08-Nov-2000 todd

This fixes pr 1481, we now handle args > 6 in /etc/hostname.if in the
cases where we did not previously handle them.
Thanks to Scott Atwood <atwood@cs.stanford.edu> for reminding us of this.


Revision tags: OPENBSD_2_8_BASE
# 1.72 02-Sep-2000 todd

subtle bug .. global variables in a while loop need reset 'just incase'
With:
hostname.fxp0 having a last line of:
inet6 alias 3ffe:...
and hostname.gif0 having a first two lines of:
giftunnel 1.2.3.4
dest 1.2.4.3
We end up with the command:
ifconfig gif0 giftunnel alias 1.2.3.4 1.2.4.3
.. which is clearly wrong and fixed by this change


# 1.71 18-Jun-2000 todd

rc.conf now parses ${local_rcconf} internally; closes pr 1259


Revision tags: OPENBSD_2_7_BASE
# 1.70 08-May-2000 todd

fix dhcp 'NONE' ness from install to allow media parsing to work
.. ok deraadt@, millert@


# 1.69 21-Apr-2000 deraadt

rc.conf.local support, inspired by chuck yerkes


# 1.68 04-Apr-2000 millert

Remove the -E flag from ipf as it is implicitly enabled and using
the -E flag here causes the kernel to printf 'IP Filter: already
initialized'.


# 1.67 18-Mar-2000 deraadt

silence all extra route addition printouts


# 1.66 17-Mar-2000 itojun

correct reject route installations for IPv6. improve comments.


# 1.65 12-Mar-2000 itojun

disallow packets to malicious 6to4 prefix, based on
http://playground.iijlab.net/i-d/draft-itojun-ipv6-transition-abuse-00.txt


# 1.64 10-Mar-2000 todd

fix non behavior
with this `!' lines in /etc/hostname.* run even without certain lines
(like a comment) preceeding it.


# 1.63 10-Jan-2000 todd

allow arbitrary commands in /etc/hostname.* files if the line starts with '!'


# 1.62 02-Jan-2000 deraadt

rtsol case can configure the interface up, since it would be nice to finish
DAD before the actual rtsol(8) run happens later. and since it will rtsol,
it is going to be up in any case.


# 1.61 02-Jan-2000 itojun

one more indentation fix.


# 1.60 02-Jan-2000 itojun

indentation fix (todd's part)


# 1.59 02-Jan-2000 todd

fix rtsold case, reset cmd for each iteration!


# 1.58 02-Jan-2000 itojun

allow options after "rtsol".
XXX both "dhcp" and "rtsol" has keyword *down* at the end. is it okay?


# 1.57 02-Jan-2000 itojun

echo "IPv6 autoconf: interfaces" before invoking rtsol.
sleep for net.inet6.ip6.dad_count seconds to ensure that IPv6 DAD is completed.
TODO: rtsold (rc.conf line), manpage


# 1.56 02-Jan-2000 itojun

ipv6 autoconf on hosts (non-routers).

to do this,
1. in sysctl.conf, add these lines:
net.inet6.ip6.forwarding=0
net.inet6.ip6.accept_rtadv=1
2. in hostname.foo, add
rtsol

specifying two or more interfaces with "rtsol" may result in strange
behavior - ipv6 spec does not permit multi-interface node to be autoconfig'ed.


# 1.55 02-Jan-2000 todd

add to hostname.* parsing:
- multiple entries support (read: aliases)
- inet6 support
- support for comments (#)
(look for hostname.if(5) commit for syntax details)


# 1.54 31-Dec-1999 itojun

install IPv6 reject routes only if kernel is capable of IPv6.


# 1.53 09-Dec-1999 itojun

avoid transmitting invalid IPv6 packets out to the wire.


# 1.52 09-Dec-1999 itojun

do not perform IPv6 initialization for loopback interface.
MUST make lo0 up before any IPv6 operations.
it will be considered a pilot error if you don't.
(I prefer to have lo0 initialized automatically)


Revision tags: OPENBSD_2_6_BASE
# 1.51 01-Sep-1999 deraadt

support # characters in bridgename.* files; millert


# 1.50 01-Sep-1999 deraadt

cleanup parsing of hostname.* files, and seperate bridge control into
bridgename.* files; all documented in new hostname.if(5) and
bridgename.if(5) man pages


# 1.49 09-Aug-1999 angelos

Only parse/setup the hostname.foo file if interface foo exists (this
is useful for laptops with different ethernet cards etc.)


Revision tags: OPENBSD_2_5_BASE
# 1.48 29-Mar-1999 niklas

New multicast route setup style


# 1.47 26-Mar-1999 niklas

Add bridge interface handling


# 1.46 01-Mar-1999 millert

Add support in /etc/hostname.xxx for files of the format:
up [options]
Any of the following may or may not be set:
$name $mask $bcaddr $extras


# 1.45 28-Oct-1998 millert

Kill the awful hack used to match and split /etc/hostname.* We now use
a function, isalphanumeric, to determine whether an interface name is
likely to be valid. This means that things like /etc/hostname.le0.bak,
/etc/hostname.le0#, /etc/hostname.le0~, etc. will be ignored as they
should. There is no longer an implicate assumption that /etc/hostname.*
only contains a single '.'.


Revision tags: OPENBSD_2_4_BASE
# 1.44 06-Oct-1998 deraadt

move ipnat to end of netstart, to support dhcp+ipnat


# 1.43 18-Sep-1998 deraadt

apply media directives on dhcp interfaces


# 1.42 10-Sep-1998 marc

better way of handling dhcp client; Jason Ish <jbi130@mail.usask.ca>


# 1.41 08-Sep-1998 marc

dhcp client stuff. "Angelos D. Keromytis" <angelos@dsl.cis.upenn.edu>


# 1.40 24-Aug-1998 downsj

You can't use -interface default when there's no default gateway
set (yet). Use -interface $hostname if mygate doesn't exist so that
this actually works on routers.


# 1.39 04-Jul-1998 deraadt

put 224 route on default, to avoid a hostname lookup


# 1.38 22-May-1998 deraadt

use route -n, what the heck


Revision tags: OPENBSD_2_3_BASE
# 1.37 28-Mar-1998 deraadt

s/^nat/ipnat/


# 1.36 23-Feb-1998 niklas

remove trailing blank line


# 1.35 07-Feb-1998 deraadt

ipforward is in sysctl.conf now


# 1.34 21-Dec-1997 deraadt

ugh


# 1.33 20-Dec-1997 deraadt

ipforwarding option in rc.conf


# 1.32 29-Nov-1997 kstailey

NAT requires IPF


# 1.31 04-Nov-1997 deraadt

kill spaces at ends of lines; m4


Revision tags: OPENBSD_2_2_BASE
# 1.30 14-Oct-1997 deraadt

set hostname/domainname before running rc.conf; m4@umn.edu


# 1.29 04-Sep-1997 deraadt

fork netstart; new child is rc.conf


# 1.28 25-Aug-1997 millert

Explicately pass -host flag to route(8) to avoid confusion with networks.


# 1.27 19-Aug-1997 niklas

Add hook for rpc.lockd, make nfsd flags settable in netstart


# 1.26 31-Jul-1997 downsj

Make quotas optional; wedged into netstart for the time being.
/etc/rc.conf, anyone?


# 1.25 30-Jul-1997 deraadt

do not run routed by default


# 1.24 28-Jul-1997 kstailey

Move configuration of loopback interface to before all other interfaces.
Allows the use of local caching-only nameserver with no "nameserver"
entry in /etc/resolv.conf to configure a route between the hostname
and loopback.


# 1.23 25-Jul-1997 provos

earlier start of keymanagement


# 1.22 24-Jul-1997 deraadt

make amd use /tmp_mnt by default


# 1.21 22-Jul-1997 provos

start the photuris daemon per default. hilfe.


# 1.20 17-Jun-1997 niklas

Put in hooks to start ypserv with flags


# 1.19 17-Jun-1997 niklas

Put in hooks to start rpc.yppasswdd with flags


Revision tags: OPENBSD_2_1_BASE
# 1.18 15-Apr-1997 deraadt

kill route flush until .. hmm kernel routing socket bug or something


# 1.17 09-Apr-1997 kstailey

add NAT startup


# 1.16 07-Apr-1997 rees

flush all old routes before adding new interfaces or routes.
ref: netbsd pr3228/misc, Matthias Scheler


# 1.15 03-Mar-1997 downsj

fix typo


# 1.14 11-Feb-1997 deraadt

add default route before fiddling with loopback route to avoid DNS problems; m4@umn.edu, #97


# 1.13 03-Feb-1997 deraadt

do ifaliases after /usr/bin exists in nfs diskless env; pr#77, matthieu@laas.fr


# 1.12 02-Nov-1996 deraadt

timed off by default


Revision tags: OPENBSD_2_0_BASE
# 1.11 23-Sep-1996 deraadt

rfc1323 variable


# 1.10 04-Sep-1996 deraadt

control portmap, inetd, and lpd from netstart; idea from tqbf@enteract.com


# 1.9 27-Aug-1996 deraadt

224.0.0.0 not 0.0.0.224; from peter@demon.net


# 1.8 18-Jun-1996 deraadt

move std stuff from rc.local to rc


# 1.7 16-Jun-1996 deraadt

install sample commented /etc/ifaliases file; which can now contain #
comments and blank lines. new format is "interface address netmask"
(yes, i changed the order of the entries). inspired by netbsd pr#2474;
gillhaa@ghost.whirlpool.com


# 1.6 02-Jun-1996 tholo

Install a multicast route by default


# 1.5 26-May-1996 deraadt

sync & label


# 1.4 09-Jan-1996 dm

added IP filter to netstat/rc and put examples in /usr/share/ipf


# 1.3 30-Dec-1995 deraadt

from netbsd: start mrouted like routed


# 1.2 18-Dec-1995 deraadt

/etc/ifaliases support by randy@zyzzyva.com


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.190 10-Feb-2018 claudio

Remove some special IPv4 in IPv6 mapped prefixes that are already rejected
by the ::0.0.0.0/96 reject route added to deny all IPv4 mapped addresses.
Makes the inet6 routing table almost fit in one screen.
OK benno@


# 1.189 10-Feb-2018 florian

Load RFC 7217 key material and generate if it does not already exist.

Add soii.key to changelist (pointed out by semarie) and mtree/special
(suggest by Craig Skinner).

OK naddy, sthen, rpe, tb


# 1.188 06-Feb-2018 tb

If -n is given, the netstart script should not (try to) set the default
route(s). Simply print the command(s) to be issued instead.

tweak & ok rpe


# 1.187 12-Nov-2017 tb

Remove HN_DIR variable and expand it in the only place it was used. It
currently serves no purpose.

ok rpe, agreement from deraadt and halex


Revision tags: OPENBSD_6_2_BASE
# 1.186 25-Jul-2017 rpe

Finally remove backwards compat code to support the 'rtsol' keyword
in hostname.if(5)

OK mpi@ deraadt@ florian@
OK jmc@ from doc perspective


# 1.185 21-Jul-2017 rpe

Align ifstart() in netstart and install.sub.

- in netstart, rename _file to _hn referencing hostname.if files
- in install.sub switch ifstart() to be used with _if instead of
_hn as parameter

ok krw@ tb@


# 1.184 28-May-2017 awolk

etc/netstart: use colon separator instead of dot with chown

OK jung@, deraadt@, jmc@


# 1.183 07-May-2017 rpe

Change test from [] to [[]] and simplify pattern.

OK tb@, krw@ (for [[]])
Feedback and OK halex@


# 1.182 07-May-2017 rpe

Replace hardcoded script name with ${0##*/}

OK tb@ halex@


# 1.181 01-May-2017 rpe

Revert r1.170 and remove the id==0 check.
The id binary is not available in nfs diskless setups at this point.

reported by Andreas Kusalananda, thanks.
discussed with deraadt@


# 1.180 01-May-2017 rpe

Remove last remnants of rtsol. IPv6 autoconfiguration of interfaces is now
done in ifstart(). Remove ipv6autoconf() and replace rtsolif with a boolean
variable V6_AUTOCONF. Replace dhcpif with a boolean variable V4_DHCPCONF.
Both are later used in defaultroute() to decide whether or not to configre
defaultroutes from /etc/mygate.

OK krw@


# 1.179 30-Apr-2017 mpi

Do not try to delete a default route before adding it.

Now that route are automatically G/C with the address they are attached
to there's no reason to duplicate the kernel's job.

Fix a regression introduced with multipath default routes.

ok deraadt@


# 1.178 25-Apr-2017 rpe

Unbreak netstart for multiple inteface configurations like trunk
or carp. Ensure that the noglob option is disabled at the end of
parse_hn_line() and ifstart().

Reported by Christer Solskogen and Stefan Wollny, thanks!


# 1.177 24-Apr-2017 rpe

Introduce a new function parse_hn_line() that replaces the existing
hostname.if(5) parsing code in ifstart().
Add a -n option to netstart to only print the interface configuration
commands instead of executing them.
Add a HN_DIR variable, that points to the directory of the hostname.if
files (default /etc) that allows for future regression tests.

- add new parse_hn_line() function
- change ifstart()
- rename $if to $_if
- don't ifconfig or ifconfig create if -n option is used
- replace hostname.if(5) parsing code with new parse_hn_line()
- just print configuration commands if -n option is used
- autoconf now happens in ifstart(), remove ifv6autoconf()
- introduce HN_DIR variable for the hostname.if file location
- add handling of the -n option to only print config commands
- ensure -n is only used if interfaces are specified as parameters

Discussed with and positive feedback from many
'commit' deraadt@
OK sthen@


# 1.176 08-Apr-2017 rpe

- localize the if, file and stat variables which also ensures that
variables are not named like commands.
- change test from [] to [[]]

OK tb@ halex@


# 1.175 07-Apr-2017 rpe

Minimize differences in ifstart() function between netstart and
install.sub which makes it easier to spot changes in the future.

- comments and formatting
- quotes on assignments are not needed (netstart)
- remove stray space in test (netstart)
- use $file variable with while-loop (netstart)
- although valid, instead of i use $i in arithmetic test (install.sub)

OK krw@, tb@
Looks good deraadt@


# 1.174 07-Apr-2017 rpe

Align comments of ifstart() function in netstart and install.sub.


# 1.173 07-Apr-2017 rpe

Align comments of stripcom() function in netstart and install.sub.


Revision tags: OPENBSD_6_1_BASE
# 1.172 06-Dec-2016 mpi

Do not lose the default route when netstart(8) is run a second time on
the interface pointed to by the default route.

Since the kernel no longer keep routes with dangling address pointer,
netstart(8) has to re-add the default route when the corresponding ifa
has been deleted and re-created.

deraadt@ points out that even if the previous semantic was not necessarily
better, a script like netstart(8) cannot totally fix the default route
problem.

Regression reported by and fix tested by Hrvoje Popovski.

ksh foo checked by halex@


# 1.171 27-Sep-2016 rzalamena

Delay switch(4) interface start up so it can attach virtual interfaces
like vether(4).

nits from and ok benno@, phessler@


# 1.170 09-Sep-2016 jasper

print a clear error message when not ran as root instead of just falling
through and try whatever it can do with the invoking user's perms

feedback/ok aja@ rpe@


Revision tags: OPENBSD_6_0_BASE
# 1.169 19-Jul-2016 mpi

Do not consider tap(4) a special interface and start if before other
pseudo-interfaces.

This unbreak vlan(4) on top of tap(4) since the refactoring to turn it
MP-safe.

ok claudio@, deraadt@


# 1.168 27-Mar-2016 sthen

Don't delete the 224/4 route in netstart, unless it's being done to ensure that
a -reject route can be added. Restores the ability to set an interface route
before daemons are started, lost during the previous simplification.
ok millert mpi


Revision tags: OPENBSD_5_9_BASE
# 1.167 29-Dec-2015 rpe

Remove backslash, not necessary after '&&'

OK halex@


# 1.166 29-Dec-2015 rpe

Replace last remaining `` with $()

OK halex@


# 1.165 18-Dec-2015 ajacoutot

Drop the now useless multicast setup comment.

prodded by tim@, ok mpi@


# 1.164 17-Dec-2015 ajacoutot

Simplify multicast option handling (10 less lines) by matching /etc/rc behavior
towards other YES|NO options and drop the error warning.


with and ok tim@, ok rpe@ on an earlier diff


# 1.163 05-Dec-2015 mpi

It does not make sense to insert a specific route for 224/4 when the
default one is good enough.

So merge rc.conf(8)'s 'multicast_router' and 'multicast_host' into a
single 'multicast'. If set to YES the reject route for 224/4 is not
inserted by netstart(8).

Manual bits from jmc@

ok henning@, ajacoutot@


# 1.162 12-Nov-2015 rpe

Changes to ifautostart():
- Rename function to ifv6autoconf() to make IPv6 relation clearer
- Localize and rename variables

OK krw@


# 1.161 12-Nov-2015 rpe

Changes to ifmstart():
- Change comments to make it clearer that ifmstart() takes two lists
of interface driver names (of which the second is optional) and not
the actual interface instances.
- Use localized variables and use slightly more verbose names.
- Use continue 2 to skip to the next hostname.if file.
- Use shell pattern @() instead of testing _sif individually.

OK krw@


# 1.160 12-Nov-2015 rpe

Changes to stripcom():
- Align comments with /etc/rc version
- Use localized variables
- Use safer "print -r --" instead of plain echo

Changes to ifstart():
- Tweak comment
- Add usage

OK krw@


# 1.159 01-Nov-2015 rpe

Start the rework of the /etc/netstart shell script.

General changes:
- apply a similar 'style' as used in the installer scripts
- improve comments to be more to the point, remove where code is obvious
- document usage of functions if they have arguments
- rename variables where it improves readability
- replace really old-school shell code with more contemporary idioms

Other changes:
- No need to care about "autoboot" because netstart doesn't inherit the
positional parameters from /etc/rc anymore. /etc/rc executes netstart
instead of sourcing it since r1.439.
- Use simpler for-loop to process list of interfaces with ifstart.

OK halex@


# 1.158 26-Oct-2015 rpe

The hostname variable is not used since r1.99. Remove it and use
stripcom() output directly with the hostname command.

OK deraadt@ krw@


# 1.157 23-Oct-2015 claudio

netstart bits for tap(4)


# 1.156 27-Sep-2015 sthen

Don't print output when setting autoconf on interfaces. Suggested by deraadt,
ok florian@ rpe@


# 1.155 13-Sep-2015 sthen

only print the "IPv6 autoconf" line if there are interfaces to configure
feedback/ok rpe


# 1.154 11-Sep-2015 sthen

Set "inet6 autoconf" individually on interfaces that have rtsol set in
hostname.if, previously netstart tried to configure them all at once
("ifconfig if0 if1 if2 inet6 autoconf"). From Delan Azabani, ok phessler@


Revision tags: OPENBSD_5_8_BASE
# 1.153 20-Jul-2015 rpe

Disable Strict Bourne shell mode for /etc/rc and /etc/netstart to be
able to use ksh syntax within these scripts. This way init doesn't
need to be changed, which starts /etc/rc using /bin/sh and people
can still use "sh /etc/netstart ifname".

Idea from and OK halex@
OK deraadt@ krw@ guenther@


# 1.152 19-Jul-2015 florian

Bring up pflow last as it might send with a source address that is on
any of the other interfaces.
OK deraadt, phessler, benno


# 1.151 19-Jul-2015 rpe

Always source rc.subr to be able to use the rc.conf parsing routine
to get the network related vars from rc.conf. This is even necessary
if netstart is run from within /etc/rc. Remove test of $INRC which
unintentionally evaluated always to true.

problem with previous change found by nigel@
OK sthen@ aja@ halex@


# 1.150 19-Jul-2015 ajacoutot

Revert 1.148 for now until I can talk to rpe@
It introduced a regression reported by nigel@


# 1.149 19-Jul-2015 rpe

Replace test command with [].

OK halex@ krw@


# 1.148 19-Jul-2015 rpe

Ensure, that we source rc.subr and parse rc.conf ONLY if we are not
inside /etc/rc.

With help from and OK halex@, ajacoutot@


# 1.147 18-Jul-2015 rpe

- remove trailing blanks introduced in previous commit
- no space in redirections like </foo or >$bar
- few other minor whitespaces

OK krw@


# 1.146 18-Jul-2015 rpe

Improve comments
- Add comments for functions
- Start comments with capital letters
- End comments with a full stop
- Allow comments to extend up to column 80

OK krw@


# 1.145 06-Jun-2015 florian

Allow rtsol keyword in hostname.if(5) with net.inet6.ip6.forwarding=1.
"inet6 autoconf" was working before and rtsol should behave the same.
OK phessler


Revision tags: OPENBSD_5_7_BASE
# 1.144 03-Dec-2014 florian

The kernel handles rtsol(8) functionality since some time now.
Treat rtsol in hostname.if as a keyword like dhcp and call ifconfig
inet6 autoconf.
"reads good" todd@
OK krw@ (who is *not* an IPv6 person), but I recruited him in his
capacity as an installer person.


# 1.143 28-Sep-2014 claudio

Revert 1.142. Without the down netstart will just print the ifconfig
output because it may end up just calling 'ifconfig $if'. This needs
to be done better and properly tested.


# 1.142 26-Sep-2014 halex

remove explicit 'down' of an interface before starting a dhcp request, thereby
avoiding annoying delays for some switch configurations

ok claudio@ deraadt@

i would add ok phessler@, but it was not valid without an ok krw@


Revision tags: OPENBSD_5_6_BASE
# 1.141 12-Jul-2014 stsp

Fix netstart after autoconf6 change so 'rtsol' lines in hostname.if work again.
found by pelikan@; ok pelikan@ henning@


# 1.140 12-Jul-2014 robert

Make rc.conf a parsed configuration file and stop sourcing it as a shell
script.
From now on rc.conf has a fixed syntax (key=val) and it is not allowed
to add anything to it besides the supported syntax, it all going to be
ignored.

discussed with and help from deraadt@ and halex@


Revision tags: OPENBSD_5_5_BASE
# 1.139 22-Aug-2013 mpi

Like for dhclient, do no create a route to alias addresses via 127.0.0.1.
Our stack is able to tell if the address is local or not.

ok todd@, krw@


Revision tags: OPENBSD_5_4_BASE
# 1.138 20-Mar-2013 todd

fix lies in netstart; replacement wording from halex@
pointed out by Ryan Kavannagh rak at debian dot org


Revision tags: OPENBSD_5_3_BASE
# 1.137 05-Dec-2012 rpe

remove "Invalid interface name" message
requested by krw@

ok halex@


# 1.136 02-Dec-2012 rpe

use the more compact version of the check for ifconfig'able interfaces
from install.sub

with feedback from and ok halex


# 1.135 02-Dec-2012 rpe

- remove isalphanumeric() and replace it with a shell pattern, that
tries a bit harder to identify invalid interface names and in
this case emit an error message.
- use [[ $1 == autoboot ]] to avoid a shell error message due to
possible spaces in first argument
- no change in functionality

discussed with krw and halex
ok ("I like this") krw


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.134 07-Oct-2011 deraadt

The new ypbind changes requires that the domainname be set before
rc.conf is run. There's no real downside.
ok aja


Revision tags: OPENBSD_5_0_BASE
# 1.133 07-Jul-2011 guenther

Eliminate some $? tests by rolling the command into the condition

ok halex@


# 1.132 26-May-2011 mpf

Add svlan(4) startup bits.
From markus@. OK naddy, claudio, reyk.


Revision tags: OPENBSD_4_9_BASE
# 1.131 09-Feb-2011 sobrado

fix an unbalanced parenthesis in a comment; while here, split the comment
in a better place to make it more readable.

ok jmc@ and miod@


Revision tags: OPENBSD_4_8_BASE
# 1.130 16-Jun-2010 todd

permit e.g. -inet6 syntax by slurping all lines not just some
noticed by rhsv6 at hushmail dot com, ok sthen@


Revision tags: OPENBSD_4_7_BASE
# 1.129 12-Jan-2010 henning

when setting up lo0 use 127.0.0.1/8 instead of 127.0.0.1 for clarity and
correctness. it's not 1992 any more, kids. ok mcbride dlg krw


# 1.128 10-Dec-2009 todd

o stop reordering ifconfig arguments (e.g. after 'up ..')
o only stop processing if inet or inet6 lines are malformed
o everything not a specially handled bit is passed to ifconfig unmangled
noticed by several after the move from bridgename.bridge0 -> hostname.bridge0
prodded by deraadt@, tested by and feedback from several
man page bits 'look fine' jmc@


# 1.127 22-Nov-2009 deraadt

Stop supporting bridgename.bridge* files, and move to hostname.bridge*
files. To cope with this change, read about the mv command.
ok claudio todd


# 1.126 17-Sep-2009 simon

change variable i to $i in an expression of ifstart() for consistency
with the rest of the file. no functional change.

feedback from sthen@, ok krw@


# 1.125 10-Jul-2009 jdixon

Delay creation of tun(4) interfaces until the underlying interface and
routes are available. This fixes usage for some OpenVPN users that start
it from hostname.tun*.

Tested by Johan Huldtgren. ok sthen@, johan@.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.124 25-Nov-2008 markus

delay /etc/netstart until IPv6-DAD (dup-address-detection) is completed.
ok fries, hshoexer, claudio


# 1.123 14-Aug-2008 sthen

Tools from /usr may not be used in netstart since it may be NFS-mounted
and not available at that time. Rewrite the hostname.if permission check
to use only /bin/ls and the shell. Requested by deraadt.

ok todd, "Twisted." deraadt


Revision tags: OPENBSD_4_4_BASE
# 1.122 23-Jul-2008 sthen

Prevent warning about insecure hostnames where no /etc/hostname.*
exists. From wcmaier@.

Check target of symbolic links to avoid noise at boot and in
seucrity output where you have several interfaces symlinked to one
config file.

"If you think this is the right thing to do" deraadt@


# 1.121 09-Jun-2008 todd

warn once not 3 times in case of a non existent file, discussed with deraadt
originally pointed out by Johan Torin


# 1.120 09-Jun-2008 deraadt

Ensure that hostname.* files are also re-chowned to root.wheel at each
boot as discussed with claudio while eating tasty donairs. ok todd


# 1.119 17-Apr-2008 deraadt

before using them, force hostname.* files to be unreadable by world
first version from todd, ok millert


Revision tags: OPENBSD_4_3_BASE
# 1.118 17-Jan-2008 brad

Execute rtsol after turning up trunk(4) and vlan(4) interfaces so they're
taken into consideration for rtsol.

ok reyk@ dlg@


# 1.117 09-Jan-2008 mpf

Do not bring up pfsync(4) before the working ruleset
has been loaded. Otherwise, states that are received during the
initial bulk update mismatch the correct pf-checksum and
do not attach to the rules.
Problem identified by david@. Fix done in collaboration.
OK henning@


Revision tags: OPENBSD_4_2_BASE
# 1.116 02-Aug-2007 david

move the delay for IPv6 DAD to after all interfaces have started
fixes problems with daemons being unable to bind to all addreses at boot
ok itojun@ hshoexer@


Revision tags: OPENBSD_4_1_BASE
# 1.115 15-Nov-2006 itojun

reject multicast packet without scope identifier specified.


Revision tags: OPENBSD_4_0_BASE
# 1.114 29-Jun-2006 todd

do not add an extra space; nwid and description come out wrong
fix as proposed by maja@, thanks!


Revision tags: OPENBSD_3_9_BASE
# 1.113 28-Dec-2005 david

nuke extra whitespace


# 1.112 06-Dec-2005 reyk

multicast_host=YES only works if a valid default gateway is available.
validate this condition and reject multicast traffic on failure.

ok todd@ naddy@


# 1.111 02-Nov-2005 todd

fix inspired by pr#4590
ok krw@


# 1.110 25-Oct-2005 todd

better logic from krw@:
- do not process mygate for v4 if dhcp
- do not process mygate for v6 if rtsol
this also makes the mygate processing logic more readable
ok krw@


# 1.109 14-Oct-2005 todd

add v6 support for /etc/mygate
ok deraadt@ mickey@ krw@
same functionality tested/ok'ed by by mickey, brad, matthieu, and me
with this one may now put a v6 IP in /etc/mygate on a separate line from
the v4 default gateway and netstart will do the right thing


# 1.108 12-Oct-2005 todd

shrink stripcom(), sync with install.sub
ok krw@


# 1.107 04-Oct-2005 todd

trunk must be started after physical ethernet devices, but before vlan.
populate ifmstart lines accordingly.
prodded/tested by brad@
ok reyk@


# 1.106 28-Sep-2005 todd

use eval consistently, fixes description quotes on rtsol and dhcp
fix inspired by and closes pr 4495
ok krw@


Revision tags: OPENBSD_3_8_BASE
# 1.105 22-May-2005 todd

Introduce 'ifmstart' to deal with starting multiple interfaces minus a list
of interfaces.

This reduces the netstart script by 174 chars, 13 words, and 19 lines, but
more importantly, makes it more simple and less cluttered should more special
case/orderings be needed.

ok brad@ and pr 4197 submitter, inspired by and closes pr 4197


# 1.104 04-Apr-2005 djm

unbreak; ok pval@


# 1.103 03-Apr-2005 deraadt

if dhcp is used to get an address on any interface, ignore /etc/mygate
ok krw
(this lets us do something rather cool with the zaurus in particular)


Revision tags: OPENBSD_3_7_BASE
# 1.102 04-Jan-2005 mcbride

Bring up the carp(4) interface before default route.

ok pascoe@ mpf@


# 1.101 30-Dec-2004 millert

Add a copy of stripcom so /etc/netstart can be run standalone again.
OK deraadt@


# 1.100 19-Dec-2004 millert

Allow comments in /etc/{myname,mygate,defaultdomain}; OK deraadt@


# 1.99 04-Dec-2004 itojun

remove "route $hostname 127.0.0.1" line. deraadt ok
*** please update /etc/netstart and test if it works ok for you ***


# 1.98 20-Oct-2004 deraadt

make all route commands use -qn; ok mcbride henning


Revision tags: OPENBSD_3_6_BASE
# 1.97 29-May-2004 deraadt

one last route command lacking -qn


Revision tags: OPENBSD_3_5_BASE
# 1.96 22-Mar-2004 mcbride

Make sure pfsync is brought up before carp.

ok deraadt@


# 1.95 13-Mar-2004 mcbride

Delay pfsync(4) configuration, as the syncif has to be configured in
advance. From Thorsten Lockert.


# 1.94 14-Jan-2004 deraadt

ok, it took quite a bit of prodding but itojun finally explained why the
extra sleep 1 is in here, and we came to the conclusion it is safe to
delete it. whee.


# 1.93 13-Jan-2004 deraadt

repair v6 lo0 documentation


# 1.92 11-Jan-2004 deraadt

add loopback routes late


# 1.91 09-Jan-2004 deraadt

create all routes with -q; markus ok


# 1.90 04-Dec-2003 millert

Need to do "ifconfig create" for bridge interfaces too.


# 1.89 03-Dec-2003 markus

add support for ifconfig clone; from netbsd; ok deraadt, henning


# 1.88 20-Oct-2003 david

delay carp initialization until after physical interfaces are configured
ok mcbride@ henning@ deraadt@ todd@


Revision tags: OPENBSD_3_4_BASE
# 1.87 27-Aug-2003 henning

only try to set hostname to what /etc/myname says if that file actually exists,
otherwise preserve `hostname`
netbooted machines can live perfectly fine without it; they get their hostname
earlier.

ok krw@ cedric@


Revision tags: OPENBSD_3_3_BASE
# 1.86 16-Feb-2003 krw

Fix up some DNS verbiage to make it consistant.

Fix up default route selection by

a) Forcing user to explicitly chose 'dhcp' as a mechanism for
specifying a default route, rather than guessing based on one or more
interfaces being configured by dhcp.

b) If the user specified default route does not work, re-present the
existing default route rather than losing it.

c) Move default route selection to after nameserver activation so the
user can specify a hostname as the default route.

Change /etc/netstart so that /etc/mygate wins if a default route was
already specified (i.e. by dhcp).

ok deraadt@.


Revision tags: OPENBSD_3_2_BASE
# 1.85 16-May-2002 todd

ignore non-existent cases where '$if' evaluates to '*'.
From Andr� Lucas <andre@ae-35.com>, fixes pr # 2658.
'Looks good' from miod@, millert@, and krw@.


Revision tags: OPENBSD_3_1_BASE
# 1.84 23-Feb-2002 deraadt

re-add support for $if expansion; hamajima@nagoya.ydc.co.jp


# 1.83 21-Feb-2002 miod

Change the network components initialization order.
Change from:
o all interfaces
o all bridges
o routes
to:
o physical interfaces
o routes
o gif and gre interfaces
o bridges

Fixeski PR #2400.
Manual page updates coming soon.
Ok angelos@ chris@ deraadt@


Revision tags: OPENBSD_3_0_BASE
# 1.82 31-Jul-2001 hugh

a space before a redirect


# 1.81 06-Jul-2001 angelos

Also, source /etc/rc.conf so we can pull in the
multicast_host/multicast_router settings; this is useful if one
flushes the routing table and re-initializes.

We really need a netconfig tool of sorts.


# 1.80 06-Jul-2001 angelos

Use "route -n show -inet" to determine the default multicast iface.


# 1.79 03-Jul-2001 deraadt

pull in rc.conf early so that pf(1) startup is right; tested by jasoni, comments from millert


# 1.78 30-May-2001 deraadt

Remove ipf. Darren Reed has interpreted his (old, new, whichever)
licence in a way that makes ipf not free according to the rules we
established over 5 years ago, at www.openbsd.org/goals.html (and those
same basic rules govern the other *BSD projects too). Specifically,
Darren says that modified versions are not permitted. But software
which OpenBSD uses and redistributes must be free to all (be they
people or companies), for any purpose they wish to use it, including
modification, use, peeing on, or even integration into baby mulching
machines or atomic bombs to be dropped on Australia. Furthermore, we
know of a number of companies using ipf with modification like us, who
are now in the same situation, and we hope that some of them will work
with us to fill this gap that now exists in OpenBSD (temporarily, we
hope).


Revision tags: OPENBSD_2_9_BASE
# 1.77 13-Mar-2001 deraadt

spelling; maurice@maurice.wan.nl


# 1.76 06-Feb-2001 todd

ignore blank lines in addition to comments
fixes pr#1660 from wilfried@telia.com .. Thanks!


# 1.75 10-Jan-2001 jason

support !command in bridgename.if files, too


# 1.74 27-Nov-2000 millert

Use -n to test if a variable is non-zero. Otherwise, if the variable's
contents start with a '-' test becomes unhappy (since it interprets it
as another option).


# 1.73 08-Nov-2000 todd

This fixes pr 1481, we now handle args > 6 in /etc/hostname.if in the
cases where we did not previously handle them.
Thanks to Scott Atwood <atwood@cs.stanford.edu> for reminding us of this.


Revision tags: OPENBSD_2_8_BASE
# 1.72 02-Sep-2000 todd

subtle bug .. global variables in a while loop need reset 'just incase'
With:
hostname.fxp0 having a last line of:
inet6 alias 3ffe:...
and hostname.gif0 having a first two lines of:
giftunnel 1.2.3.4
dest 1.2.4.3
We end up with the command:
ifconfig gif0 giftunnel alias 1.2.3.4 1.2.4.3
.. which is clearly wrong and fixed by this change


# 1.71 18-Jun-2000 todd

rc.conf now parses ${local_rcconf} internally; closes pr 1259


Revision tags: OPENBSD_2_7_BASE
# 1.70 08-May-2000 todd

fix dhcp 'NONE' ness from install to allow media parsing to work
.. ok deraadt@, millert@


# 1.69 21-Apr-2000 deraadt

rc.conf.local support, inspired by chuck yerkes


# 1.68 04-Apr-2000 millert

Remove the -E flag from ipf as it is implicitly enabled and using
the -E flag here causes the kernel to printf 'IP Filter: already
initialized'.


# 1.67 18-Mar-2000 deraadt

silence all extra route addition printouts


# 1.66 17-Mar-2000 itojun

correct reject route installations for IPv6. improve comments.


# 1.65 12-Mar-2000 itojun

disallow packets to malicious 6to4 prefix, based on
http://playground.iijlab.net/i-d/draft-itojun-ipv6-transition-abuse-00.txt


# 1.64 10-Mar-2000 todd

fix non behavior
with this `!' lines in /etc/hostname.* run even without certain lines
(like a comment) preceeding it.


# 1.63 10-Jan-2000 todd

allow arbitrary commands in /etc/hostname.* files if the line starts with '!'


# 1.62 02-Jan-2000 deraadt

rtsol case can configure the interface up, since it would be nice to finish
DAD before the actual rtsol(8) run happens later. and since it will rtsol,
it is going to be up in any case.


# 1.61 02-Jan-2000 itojun

one more indentation fix.


# 1.60 02-Jan-2000 itojun

indentation fix (todd's part)


# 1.59 02-Jan-2000 todd

fix rtsold case, reset cmd for each iteration!


# 1.58 02-Jan-2000 itojun

allow options after "rtsol".
XXX both "dhcp" and "rtsol" has keyword *down* at the end. is it okay?


# 1.57 02-Jan-2000 itojun

echo "IPv6 autoconf: interfaces" before invoking rtsol.
sleep for net.inet6.ip6.dad_count seconds to ensure that IPv6 DAD is completed.
TODO: rtsold (rc.conf line), manpage


# 1.56 02-Jan-2000 itojun

ipv6 autoconf on hosts (non-routers).

to do this,
1. in sysctl.conf, add these lines:
net.inet6.ip6.forwarding=0
net.inet6.ip6.accept_rtadv=1
2. in hostname.foo, add
rtsol

specifying two or more interfaces with "rtsol" may result in strange
behavior - ipv6 spec does not permit multi-interface node to be autoconfig'ed.


# 1.55 02-Jan-2000 todd

add to hostname.* parsing:
- multiple entries support (read: aliases)
- inet6 support
- support for comments (#)
(look for hostname.if(5) commit for syntax details)


# 1.54 31-Dec-1999 itojun

install IPv6 reject routes only if kernel is capable of IPv6.


# 1.53 09-Dec-1999 itojun

avoid transmitting invalid IPv6 packets out to the wire.


# 1.52 09-Dec-1999 itojun

do not perform IPv6 initialization for loopback interface.
MUST make lo0 up before any IPv6 operations.
it will be considered a pilot error if you don't.
(I prefer to have lo0 initialized automatically)


Revision tags: OPENBSD_2_6_BASE
# 1.51 01-Sep-1999 deraadt

support # characters in bridgename.* files; millert


# 1.50 01-Sep-1999 deraadt

cleanup parsing of hostname.* files, and seperate bridge control into
bridgename.* files; all documented in new hostname.if(5) and
bridgename.if(5) man pages


# 1.49 09-Aug-1999 angelos

Only parse/setup the hostname.foo file if interface foo exists (this
is useful for laptops with different ethernet cards etc.)


Revision tags: OPENBSD_2_5_BASE
# 1.48 29-Mar-1999 niklas

New multicast route setup style


# 1.47 26-Mar-1999 niklas

Add bridge interface handling


# 1.46 01-Mar-1999 millert

Add support in /etc/hostname.xxx for files of the format:
up [options]
Any of the following may or may not be set:
$name $mask $bcaddr $extras


# 1.45 28-Oct-1998 millert

Kill the awful hack used to match and split /etc/hostname.* We now use
a function, isalphanumeric, to determine whether an interface name is
likely to be valid. This means that things like /etc/hostname.le0.bak,
/etc/hostname.le0#, /etc/hostname.le0~, etc. will be ignored as they
should. There is no longer an implicate assumption that /etc/hostname.*
only contains a single '.'.


Revision tags: OPENBSD_2_4_BASE
# 1.44 06-Oct-1998 deraadt

move ipnat to end of netstart, to support dhcp+ipnat


# 1.43 18-Sep-1998 deraadt

apply media directives on dhcp interfaces


# 1.42 10-Sep-1998 marc

better way of handling dhcp client; Jason Ish <jbi130@mail.usask.ca>


# 1.41 08-Sep-1998 marc

dhcp client stuff. "Angelos D. Keromytis" <angelos@dsl.cis.upenn.edu>


# 1.40 24-Aug-1998 downsj

You can't use -interface default when there's no default gateway
set (yet). Use -interface $hostname if mygate doesn't exist so that
this actually works on routers.


# 1.39 04-Jul-1998 deraadt

put 224 route on default, to avoid a hostname lookup


# 1.38 22-May-1998 deraadt

use route -n, what the heck


Revision tags: OPENBSD_2_3_BASE
# 1.37 28-Mar-1998 deraadt

s/^nat/ipnat/


# 1.36 23-Feb-1998 niklas

remove trailing blank line


# 1.35 07-Feb-1998 deraadt

ipforward is in sysctl.conf now


# 1.34 21-Dec-1997 deraadt

ugh


# 1.33 20-Dec-1997 deraadt

ipforwarding option in rc.conf


# 1.32 29-Nov-1997 kstailey

NAT requires IPF


# 1.31 04-Nov-1997 deraadt

kill spaces at ends of lines; m4


Revision tags: OPENBSD_2_2_BASE
# 1.30 14-Oct-1997 deraadt

set hostname/domainname before running rc.conf; m4@umn.edu


# 1.29 04-Sep-1997 deraadt

fork netstart; new child is rc.conf


# 1.28 25-Aug-1997 millert

Explicately pass -host flag to route(8) to avoid confusion with networks.


# 1.27 19-Aug-1997 niklas

Add hook for rpc.lockd, make nfsd flags settable in netstart


# 1.26 31-Jul-1997 downsj

Make quotas optional; wedged into netstart for the time being.
/etc/rc.conf, anyone?


# 1.25 30-Jul-1997 deraadt

do not run routed by default


# 1.24 28-Jul-1997 kstailey

Move configuration of loopback interface to before all other interfaces.
Allows the use of local caching-only nameserver with no "nameserver"
entry in /etc/resolv.conf to configure a route between the hostname
and loopback.


# 1.23 25-Jul-1997 provos

earlier start of keymanagement


# 1.22 24-Jul-1997 deraadt

make amd use /tmp_mnt by default


# 1.21 22-Jul-1997 provos

start the photuris daemon per default. hilfe.


# 1.20 17-Jun-1997 niklas

Put in hooks to start ypserv with flags


# 1.19 17-Jun-1997 niklas

Put in hooks to start rpc.yppasswdd with flags


Revision tags: OPENBSD_2_1_BASE
# 1.18 15-Apr-1997 deraadt

kill route flush until .. hmm kernel routing socket bug or something


# 1.17 09-Apr-1997 kstailey

add NAT startup


# 1.16 07-Apr-1997 rees

flush all old routes before adding new interfaces or routes.
ref: netbsd pr3228/misc, Matthias Scheler


# 1.15 03-Mar-1997 downsj

fix typo


# 1.14 11-Feb-1997 deraadt

add default route before fiddling with loopback route to avoid DNS problems; m4@umn.edu, #97


# 1.13 03-Feb-1997 deraadt

do ifaliases after /usr/bin exists in nfs diskless env; pr#77, matthieu@laas.fr


# 1.12 02-Nov-1996 deraadt

timed off by default


Revision tags: OPENBSD_2_0_BASE
# 1.11 23-Sep-1996 deraadt

rfc1323 variable


# 1.10 04-Sep-1996 deraadt

control portmap, inetd, and lpd from netstart; idea from tqbf@enteract.com


# 1.9 27-Aug-1996 deraadt

224.0.0.0 not 0.0.0.224; from peter@demon.net


# 1.8 18-Jun-1996 deraadt

move std stuff from rc.local to rc


# 1.7 16-Jun-1996 deraadt

install sample commented /etc/ifaliases file; which can now contain #
comments and blank lines. new format is "interface address netmask"
(yes, i changed the order of the entries). inspired by netbsd pr#2474;
gillhaa@ghost.whirlpool.com


# 1.6 02-Jun-1996 tholo

Install a multicast route by default


# 1.5 26-May-1996 deraadt

sync & label


# 1.4 09-Jan-1996 dm

added IP filter to netstat/rc and put examples in /usr/share/ipf


# 1.3 30-Dec-1995 deraadt

from netbsd: start mrouted like routed


# 1.2 18-Dec-1995 deraadt

/etc/ifaliases support by randy@zyzzyva.com


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.188 06-Feb-2018 tb

If -n is given, the netstart script should not (try to) set the default
route(s). Simply print the command(s) to be issued instead.

tweak & ok rpe


# 1.187 12-Nov-2017 tb

Remove HN_DIR variable and expand it in the only place it was used. It
currently serves no purpose.

ok rpe, agreement from deraadt and halex


Revision tags: OPENBSD_6_2_BASE
# 1.186 25-Jul-2017 rpe

Finally remove backwards compat code to support the 'rtsol' keyword
in hostname.if(5)

OK mpi@ deraadt@ florian@
OK jmc@ from doc perspective


# 1.185 21-Jul-2017 rpe

Align ifstart() in netstart and install.sub.

- in netstart, rename _file to _hn referencing hostname.if files
- in install.sub switch ifstart() to be used with _if instead of
_hn as parameter

ok krw@ tb@


# 1.184 28-May-2017 awolk

etc/netstart: use colon separator instead of dot with chown

OK jung@, deraadt@, jmc@


# 1.183 07-May-2017 rpe

Change test from [] to [[]] and simplify pattern.

OK tb@, krw@ (for [[]])
Feedback and OK halex@


# 1.182 07-May-2017 rpe

Replace hardcoded script name with ${0##*/}

OK tb@ halex@


# 1.181 01-May-2017 rpe

Revert r1.170 and remove the id==0 check.
The id binary is not available in nfs diskless setups at this point.

reported by Andreas Kusalananda, thanks.
discussed with deraadt@


# 1.180 01-May-2017 rpe

Remove last remnants of rtsol. IPv6 autoconfiguration of interfaces is now
done in ifstart(). Remove ipv6autoconf() and replace rtsolif with a boolean
variable V6_AUTOCONF. Replace dhcpif with a boolean variable V4_DHCPCONF.
Both are later used in defaultroute() to decide whether or not to configre
defaultroutes from /etc/mygate.

OK krw@


# 1.179 30-Apr-2017 mpi

Do not try to delete a default route before adding it.

Now that route are automatically G/C with the address they are attached
to there's no reason to duplicate the kernel's job.

Fix a regression introduced with multipath default routes.

ok deraadt@


# 1.178 25-Apr-2017 rpe

Unbreak netstart for multiple inteface configurations like trunk
or carp. Ensure that the noglob option is disabled at the end of
parse_hn_line() and ifstart().

Reported by Christer Solskogen and Stefan Wollny, thanks!


# 1.177 24-Apr-2017 rpe

Introduce a new function parse_hn_line() that replaces the existing
hostname.if(5) parsing code in ifstart().
Add a -n option to netstart to only print the interface configuration
commands instead of executing them.
Add a HN_DIR variable, that points to the directory of the hostname.if
files (default /etc) that allows for future regression tests.

- add new parse_hn_line() function
- change ifstart()
- rename $if to $_if
- don't ifconfig or ifconfig create if -n option is used
- replace hostname.if(5) parsing code with new parse_hn_line()
- just print configuration commands if -n option is used
- autoconf now happens in ifstart(), remove ifv6autoconf()
- introduce HN_DIR variable for the hostname.if file location
- add handling of the -n option to only print config commands
- ensure -n is only used if interfaces are specified as parameters

Discussed with and positive feedback from many
'commit' deraadt@
OK sthen@


# 1.176 08-Apr-2017 rpe

- localize the if, file and stat variables which also ensures that
variables are not named like commands.
- change test from [] to [[]]

OK tb@ halex@


# 1.175 07-Apr-2017 rpe

Minimize differences in ifstart() function between netstart and
install.sub which makes it easier to spot changes in the future.

- comments and formatting
- quotes on assignments are not needed (netstart)
- remove stray space in test (netstart)
- use $file variable with while-loop (netstart)
- although valid, instead of i use $i in arithmetic test (install.sub)

OK krw@, tb@
Looks good deraadt@


# 1.174 07-Apr-2017 rpe

Align comments of ifstart() function in netstart and install.sub.


# 1.173 07-Apr-2017 rpe

Align comments of stripcom() function in netstart and install.sub.


Revision tags: OPENBSD_6_1_BASE
# 1.172 06-Dec-2016 mpi

Do not lose the default route when netstart(8) is run a second time on
the interface pointed to by the default route.

Since the kernel no longer keep routes with dangling address pointer,
netstart(8) has to re-add the default route when the corresponding ifa
has been deleted and re-created.

deraadt@ points out that even if the previous semantic was not necessarily
better, a script like netstart(8) cannot totally fix the default route
problem.

Regression reported by and fix tested by Hrvoje Popovski.

ksh foo checked by halex@


# 1.171 27-Sep-2016 rzalamena

Delay switch(4) interface start up so it can attach virtual interfaces
like vether(4).

nits from and ok benno@, phessler@


# 1.170 09-Sep-2016 jasper

print a clear error message when not ran as root instead of just falling
through and try whatever it can do with the invoking user's perms

feedback/ok aja@ rpe@


Revision tags: OPENBSD_6_0_BASE
# 1.169 19-Jul-2016 mpi

Do not consider tap(4) a special interface and start if before other
pseudo-interfaces.

This unbreak vlan(4) on top of tap(4) since the refactoring to turn it
MP-safe.

ok claudio@, deraadt@


# 1.168 27-Mar-2016 sthen

Don't delete the 224/4 route in netstart, unless it's being done to ensure that
a -reject route can be added. Restores the ability to set an interface route
before daemons are started, lost during the previous simplification.
ok millert mpi


Revision tags: OPENBSD_5_9_BASE
# 1.167 29-Dec-2015 rpe

Remove backslash, not necessary after '&&'

OK halex@


# 1.166 29-Dec-2015 rpe

Replace last remaining `` with $()

OK halex@


# 1.165 18-Dec-2015 ajacoutot

Drop the now useless multicast setup comment.

prodded by tim@, ok mpi@


# 1.164 17-Dec-2015 ajacoutot

Simplify multicast option handling (10 less lines) by matching /etc/rc behavior
towards other YES|NO options and drop the error warning.


with and ok tim@, ok rpe@ on an earlier diff


# 1.163 05-Dec-2015 mpi

It does not make sense to insert a specific route for 224/4 when the
default one is good enough.

So merge rc.conf(8)'s 'multicast_router' and 'multicast_host' into a
single 'multicast'. If set to YES the reject route for 224/4 is not
inserted by netstart(8).

Manual bits from jmc@

ok henning@, ajacoutot@


# 1.162 12-Nov-2015 rpe

Changes to ifautostart():
- Rename function to ifv6autoconf() to make IPv6 relation clearer
- Localize and rename variables

OK krw@


# 1.161 12-Nov-2015 rpe

Changes to ifmstart():
- Change comments to make it clearer that ifmstart() takes two lists
of interface driver names (of which the second is optional) and not
the actual interface instances.
- Use localized variables and use slightly more verbose names.
- Use continue 2 to skip to the next hostname.if file.
- Use shell pattern @() instead of testing _sif individually.

OK krw@


# 1.160 12-Nov-2015 rpe

Changes to stripcom():
- Align comments with /etc/rc version
- Use localized variables
- Use safer "print -r --" instead of plain echo

Changes to ifstart():
- Tweak comment
- Add usage

OK krw@


# 1.159 01-Nov-2015 rpe

Start the rework of the /etc/netstart shell script.

General changes:
- apply a similar 'style' as used in the installer scripts
- improve comments to be more to the point, remove where code is obvious
- document usage of functions if they have arguments
- rename variables where it improves readability
- replace really old-school shell code with more contemporary idioms

Other changes:
- No need to care about "autoboot" because netstart doesn't inherit the
positional parameters from /etc/rc anymore. /etc/rc executes netstart
instead of sourcing it since r1.439.
- Use simpler for-loop to process list of interfaces with ifstart.

OK halex@


# 1.158 26-Oct-2015 rpe

The hostname variable is not used since r1.99. Remove it and use
stripcom() output directly with the hostname command.

OK deraadt@ krw@


# 1.157 23-Oct-2015 claudio

netstart bits for tap(4)


# 1.156 27-Sep-2015 sthen

Don't print output when setting autoconf on interfaces. Suggested by deraadt,
ok florian@ rpe@


# 1.155 13-Sep-2015 sthen

only print the "IPv6 autoconf" line if there are interfaces to configure
feedback/ok rpe


# 1.154 11-Sep-2015 sthen

Set "inet6 autoconf" individually on interfaces that have rtsol set in
hostname.if, previously netstart tried to configure them all at once
("ifconfig if0 if1 if2 inet6 autoconf"). From Delan Azabani, ok phessler@


Revision tags: OPENBSD_5_8_BASE
# 1.153 20-Jul-2015 rpe

Disable Strict Bourne shell mode for /etc/rc and /etc/netstart to be
able to use ksh syntax within these scripts. This way init doesn't
need to be changed, which starts /etc/rc using /bin/sh and people
can still use "sh /etc/netstart ifname".

Idea from and OK halex@
OK deraadt@ krw@ guenther@


# 1.152 19-Jul-2015 florian

Bring up pflow last as it might send with a source address that is on
any of the other interfaces.
OK deraadt, phessler, benno


# 1.151 19-Jul-2015 rpe

Always source rc.subr to be able to use the rc.conf parsing routine
to get the network related vars from rc.conf. This is even necessary
if netstart is run from within /etc/rc. Remove test of $INRC which
unintentionally evaluated always to true.

problem with previous change found by nigel@
OK sthen@ aja@ halex@


# 1.150 19-Jul-2015 ajacoutot

Revert 1.148 for now until I can talk to rpe@
It introduced a regression reported by nigel@


# 1.149 19-Jul-2015 rpe

Replace test command with [].

OK halex@ krw@


# 1.148 19-Jul-2015 rpe

Ensure, that we source rc.subr and parse rc.conf ONLY if we are not
inside /etc/rc.

With help from and OK halex@, ajacoutot@


# 1.147 18-Jul-2015 rpe

- remove trailing blanks introduced in previous commit
- no space in redirections like </foo or >$bar
- few other minor whitespaces

OK krw@


# 1.146 18-Jul-2015 rpe

Improve comments
- Add comments for functions
- Start comments with capital letters
- End comments with a full stop
- Allow comments to extend up to column 80

OK krw@


# 1.145 06-Jun-2015 florian

Allow rtsol keyword in hostname.if(5) with net.inet6.ip6.forwarding=1.
"inet6 autoconf" was working before and rtsol should behave the same.
OK phessler


Revision tags: OPENBSD_5_7_BASE
# 1.144 03-Dec-2014 florian

The kernel handles rtsol(8) functionality since some time now.
Treat rtsol in hostname.if as a keyword like dhcp and call ifconfig
inet6 autoconf.
"reads good" todd@
OK krw@ (who is *not* an IPv6 person), but I recruited him in his
capacity as an installer person.


# 1.143 28-Sep-2014 claudio

Revert 1.142. Without the down netstart will just print the ifconfig
output because it may end up just calling 'ifconfig $if'. This needs
to be done better and properly tested.


# 1.142 26-Sep-2014 halex

remove explicit 'down' of an interface before starting a dhcp request, thereby
avoiding annoying delays for some switch configurations

ok claudio@ deraadt@

i would add ok phessler@, but it was not valid without an ok krw@


Revision tags: OPENBSD_5_6_BASE
# 1.141 12-Jul-2014 stsp

Fix netstart after autoconf6 change so 'rtsol' lines in hostname.if work again.
found by pelikan@; ok pelikan@ henning@


# 1.140 12-Jul-2014 robert

Make rc.conf a parsed configuration file and stop sourcing it as a shell
script.
From now on rc.conf has a fixed syntax (key=val) and it is not allowed
to add anything to it besides the supported syntax, it all going to be
ignored.

discussed with and help from deraadt@ and halex@


Revision tags: OPENBSD_5_5_BASE
# 1.139 22-Aug-2013 mpi

Like for dhclient, do no create a route to alias addresses via 127.0.0.1.
Our stack is able to tell if the address is local or not.

ok todd@, krw@


Revision tags: OPENBSD_5_4_BASE
# 1.138 20-Mar-2013 todd

fix lies in netstart; replacement wording from halex@
pointed out by Ryan Kavannagh rak at debian dot org


Revision tags: OPENBSD_5_3_BASE
# 1.137 05-Dec-2012 rpe

remove "Invalid interface name" message
requested by krw@

ok halex@


# 1.136 02-Dec-2012 rpe

use the more compact version of the check for ifconfig'able interfaces
from install.sub

with feedback from and ok halex


# 1.135 02-Dec-2012 rpe

- remove isalphanumeric() and replace it with a shell pattern, that
tries a bit harder to identify invalid interface names and in
this case emit an error message.
- use [[ $1 == autoboot ]] to avoid a shell error message due to
possible spaces in first argument
- no change in functionality

discussed with krw and halex
ok ("I like this") krw


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.134 07-Oct-2011 deraadt

The new ypbind changes requires that the domainname be set before
rc.conf is run. There's no real downside.
ok aja


Revision tags: OPENBSD_5_0_BASE
# 1.133 07-Jul-2011 guenther

Eliminate some $? tests by rolling the command into the condition

ok halex@


# 1.132 26-May-2011 mpf

Add svlan(4) startup bits.
From markus@. OK naddy, claudio, reyk.


Revision tags: OPENBSD_4_9_BASE
# 1.131 09-Feb-2011 sobrado

fix an unbalanced parenthesis in a comment; while here, split the comment
in a better place to make it more readable.

ok jmc@ and miod@


Revision tags: OPENBSD_4_8_BASE
# 1.130 16-Jun-2010 todd

permit e.g. -inet6 syntax by slurping all lines not just some
noticed by rhsv6 at hushmail dot com, ok sthen@


Revision tags: OPENBSD_4_7_BASE
# 1.129 12-Jan-2010 henning

when setting up lo0 use 127.0.0.1/8 instead of 127.0.0.1 for clarity and
correctness. it's not 1992 any more, kids. ok mcbride dlg krw


# 1.128 10-Dec-2009 todd

o stop reordering ifconfig arguments (e.g. after 'up ..')
o only stop processing if inet or inet6 lines are malformed
o everything not a specially handled bit is passed to ifconfig unmangled
noticed by several after the move from bridgename.bridge0 -> hostname.bridge0
prodded by deraadt@, tested by and feedback from several
man page bits 'look fine' jmc@


# 1.127 22-Nov-2009 deraadt

Stop supporting bridgename.bridge* files, and move to hostname.bridge*
files. To cope with this change, read about the mv command.
ok claudio todd


# 1.126 17-Sep-2009 simon

change variable i to $i in an expression of ifstart() for consistency
with the rest of the file. no functional change.

feedback from sthen@, ok krw@


# 1.125 10-Jul-2009 jdixon

Delay creation of tun(4) interfaces until the underlying interface and
routes are available. This fixes usage for some OpenVPN users that start
it from hostname.tun*.

Tested by Johan Huldtgren. ok sthen@, johan@.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.124 25-Nov-2008 markus

delay /etc/netstart until IPv6-DAD (dup-address-detection) is completed.
ok fries, hshoexer, claudio


# 1.123 14-Aug-2008 sthen

Tools from /usr may not be used in netstart since it may be NFS-mounted
and not available at that time. Rewrite the hostname.if permission check
to use only /bin/ls and the shell. Requested by deraadt.

ok todd, "Twisted." deraadt


Revision tags: OPENBSD_4_4_BASE
# 1.122 23-Jul-2008 sthen

Prevent warning about insecure hostnames where no /etc/hostname.*
exists. From wcmaier@.

Check target of symbolic links to avoid noise at boot and in
seucrity output where you have several interfaces symlinked to one
config file.

"If you think this is the right thing to do" deraadt@


# 1.121 09-Jun-2008 todd

warn once not 3 times in case of a non existent file, discussed with deraadt
originally pointed out by Johan Torin


# 1.120 09-Jun-2008 deraadt

Ensure that hostname.* files are also re-chowned to root.wheel at each
boot as discussed with claudio while eating tasty donairs. ok todd


# 1.119 17-Apr-2008 deraadt

before using them, force hostname.* files to be unreadable by world
first version from todd, ok millert


Revision tags: OPENBSD_4_3_BASE
# 1.118 17-Jan-2008 brad

Execute rtsol after turning up trunk(4) and vlan(4) interfaces so they're
taken into consideration for rtsol.

ok reyk@ dlg@


# 1.117 09-Jan-2008 mpf

Do not bring up pfsync(4) before the working ruleset
has been loaded. Otherwise, states that are received during the
initial bulk update mismatch the correct pf-checksum and
do not attach to the rules.
Problem identified by david@. Fix done in collaboration.
OK henning@


Revision tags: OPENBSD_4_2_BASE
# 1.116 02-Aug-2007 david

move the delay for IPv6 DAD to after all interfaces have started
fixes problems with daemons being unable to bind to all addreses at boot
ok itojun@ hshoexer@


Revision tags: OPENBSD_4_1_BASE
# 1.115 15-Nov-2006 itojun

reject multicast packet without scope identifier specified.


Revision tags: OPENBSD_4_0_BASE
# 1.114 29-Jun-2006 todd

do not add an extra space; nwid and description come out wrong
fix as proposed by maja@, thanks!


Revision tags: OPENBSD_3_9_BASE
# 1.113 28-Dec-2005 david

nuke extra whitespace


# 1.112 06-Dec-2005 reyk

multicast_host=YES only works if a valid default gateway is available.
validate this condition and reject multicast traffic on failure.

ok todd@ naddy@


# 1.111 02-Nov-2005 todd

fix inspired by pr#4590
ok krw@


# 1.110 25-Oct-2005 todd

better logic from krw@:
- do not process mygate for v4 if dhcp
- do not process mygate for v6 if rtsol
this also makes the mygate processing logic more readable
ok krw@


# 1.109 14-Oct-2005 todd

add v6 support for /etc/mygate
ok deraadt@ mickey@ krw@
same functionality tested/ok'ed by by mickey, brad, matthieu, and me
with this one may now put a v6 IP in /etc/mygate on a separate line from
the v4 default gateway and netstart will do the right thing


# 1.108 12-Oct-2005 todd

shrink stripcom(), sync with install.sub
ok krw@


# 1.107 04-Oct-2005 todd

trunk must be started after physical ethernet devices, but before vlan.
populate ifmstart lines accordingly.
prodded/tested by brad@
ok reyk@


# 1.106 28-Sep-2005 todd

use eval consistently, fixes description quotes on rtsol and dhcp
fix inspired by and closes pr 4495
ok krw@


Revision tags: OPENBSD_3_8_BASE
# 1.105 22-May-2005 todd

Introduce 'ifmstart' to deal with starting multiple interfaces minus a list
of interfaces.

This reduces the netstart script by 174 chars, 13 words, and 19 lines, but
more importantly, makes it more simple and less cluttered should more special
case/orderings be needed.

ok brad@ and pr 4197 submitter, inspired by and closes pr 4197


# 1.104 04-Apr-2005 djm

unbreak; ok pval@


# 1.103 03-Apr-2005 deraadt

if dhcp is used to get an address on any interface, ignore /etc/mygate
ok krw
(this lets us do something rather cool with the zaurus in particular)


Revision tags: OPENBSD_3_7_BASE
# 1.102 04-Jan-2005 mcbride

Bring up the carp(4) interface before default route.

ok pascoe@ mpf@


# 1.101 30-Dec-2004 millert

Add a copy of stripcom so /etc/netstart can be run standalone again.
OK deraadt@


# 1.100 19-Dec-2004 millert

Allow comments in /etc/{myname,mygate,defaultdomain}; OK deraadt@


# 1.99 04-Dec-2004 itojun

remove "route $hostname 127.0.0.1" line. deraadt ok
*** please update /etc/netstart and test if it works ok for you ***


# 1.98 20-Oct-2004 deraadt

make all route commands use -qn; ok mcbride henning


Revision tags: OPENBSD_3_6_BASE
# 1.97 29-May-2004 deraadt

one last route command lacking -qn


Revision tags: OPENBSD_3_5_BASE
# 1.96 22-Mar-2004 mcbride

Make sure pfsync is brought up before carp.

ok deraadt@


# 1.95 13-Mar-2004 mcbride

Delay pfsync(4) configuration, as the syncif has to be configured in
advance. From Thorsten Lockert.


# 1.94 14-Jan-2004 deraadt

ok, it took quite a bit of prodding but itojun finally explained why the
extra sleep 1 is in here, and we came to the conclusion it is safe to
delete it. whee.


# 1.93 13-Jan-2004 deraadt

repair v6 lo0 documentation


# 1.92 11-Jan-2004 deraadt

add loopback routes late


# 1.91 09-Jan-2004 deraadt

create all routes with -q; markus ok


# 1.90 04-Dec-2003 millert

Need to do "ifconfig create" for bridge interfaces too.


# 1.89 03-Dec-2003 markus

add support for ifconfig clone; from netbsd; ok deraadt, henning


# 1.88 20-Oct-2003 david

delay carp initialization until after physical interfaces are configured
ok mcbride@ henning@ deraadt@ todd@


Revision tags: OPENBSD_3_4_BASE
# 1.87 27-Aug-2003 henning

only try to set hostname to what /etc/myname says if that file actually exists,
otherwise preserve `hostname`
netbooted machines can live perfectly fine without it; they get their hostname
earlier.

ok krw@ cedric@


Revision tags: OPENBSD_3_3_BASE
# 1.86 16-Feb-2003 krw

Fix up some DNS verbiage to make it consistant.

Fix up default route selection by

a) Forcing user to explicitly chose 'dhcp' as a mechanism for
specifying a default route, rather than guessing based on one or more
interfaces being configured by dhcp.

b) If the user specified default route does not work, re-present the
existing default route rather than losing it.

c) Move default route selection to after nameserver activation so the
user can specify a hostname as the default route.

Change /etc/netstart so that /etc/mygate wins if a default route was
already specified (i.e. by dhcp).

ok deraadt@.


Revision tags: OPENBSD_3_2_BASE
# 1.85 16-May-2002 todd

ignore non-existent cases where '$if' evaluates to '*'.
From Andr� Lucas <andre@ae-35.com>, fixes pr # 2658.
'Looks good' from miod@, millert@, and krw@.


Revision tags: OPENBSD_3_1_BASE
# 1.84 23-Feb-2002 deraadt

re-add support for $if expansion; hamajima@nagoya.ydc.co.jp


# 1.83 21-Feb-2002 miod

Change the network components initialization order.
Change from:
o all interfaces
o all bridges
o routes
to:
o physical interfaces
o routes
o gif and gre interfaces
o bridges

Fixeski PR #2400.
Manual page updates coming soon.
Ok angelos@ chris@ deraadt@


Revision tags: OPENBSD_3_0_BASE
# 1.82 31-Jul-2001 hugh

a space before a redirect


# 1.81 06-Jul-2001 angelos

Also, source /etc/rc.conf so we can pull in the
multicast_host/multicast_router settings; this is useful if one
flushes the routing table and re-initializes.

We really need a netconfig tool of sorts.


# 1.80 06-Jul-2001 angelos

Use "route -n show -inet" to determine the default multicast iface.


# 1.79 03-Jul-2001 deraadt

pull in rc.conf early so that pf(1) startup is right; tested by jasoni, comments from millert


# 1.78 30-May-2001 deraadt

Remove ipf. Darren Reed has interpreted his (old, new, whichever)
licence in a way that makes ipf not free according to the rules we
established over 5 years ago, at www.openbsd.org/goals.html (and those
same basic rules govern the other *BSD projects too). Specifically,
Darren says that modified versions are not permitted. But software
which OpenBSD uses and redistributes must be free to all (be they
people or companies), for any purpose they wish to use it, including
modification, use, peeing on, or even integration into baby mulching
machines or atomic bombs to be dropped on Australia. Furthermore, we
know of a number of companies using ipf with modification like us, who
are now in the same situation, and we hope that some of them will work
with us to fill this gap that now exists in OpenBSD (temporarily, we
hope).


Revision tags: OPENBSD_2_9_BASE
# 1.77 13-Mar-2001 deraadt

spelling; maurice@maurice.wan.nl


# 1.76 06-Feb-2001 todd

ignore blank lines in addition to comments
fixes pr#1660 from wilfried@telia.com .. Thanks!


# 1.75 10-Jan-2001 jason

support !command in bridgename.if files, too


# 1.74 27-Nov-2000 millert

Use -n to test if a variable is non-zero. Otherwise, if the variable's
contents start with a '-' test becomes unhappy (since it interprets it
as another option).


# 1.73 08-Nov-2000 todd

This fixes pr 1481, we now handle args > 6 in /etc/hostname.if in the
cases where we did not previously handle them.
Thanks to Scott Atwood <atwood@cs.stanford.edu> for reminding us of this.


Revision tags: OPENBSD_2_8_BASE
# 1.72 02-Sep-2000 todd

subtle bug .. global variables in a while loop need reset 'just incase'
With:
hostname.fxp0 having a last line of:
inet6 alias 3ffe:...
and hostname.gif0 having a first two lines of:
giftunnel 1.2.3.4
dest 1.2.4.3
We end up with the command:
ifconfig gif0 giftunnel alias 1.2.3.4 1.2.4.3
.. which is clearly wrong and fixed by this change


# 1.71 18-Jun-2000 todd

rc.conf now parses ${local_rcconf} internally; closes pr 1259


Revision tags: OPENBSD_2_7_BASE
# 1.70 08-May-2000 todd

fix dhcp 'NONE' ness from install to allow media parsing to work
.. ok deraadt@, millert@


# 1.69 21-Apr-2000 deraadt

rc.conf.local support, inspired by chuck yerkes


# 1.68 04-Apr-2000 millert

Remove the -E flag from ipf as it is implicitly enabled and using
the -E flag here causes the kernel to printf 'IP Filter: already
initialized'.


# 1.67 18-Mar-2000 deraadt

silence all extra route addition printouts


# 1.66 17-Mar-2000 itojun

correct reject route installations for IPv6. improve comments.


# 1.65 12-Mar-2000 itojun

disallow packets to malicious 6to4 prefix, based on
http://playground.iijlab.net/i-d/draft-itojun-ipv6-transition-abuse-00.txt


# 1.64 10-Mar-2000 todd

fix non behavior
with this `!' lines in /etc/hostname.* run even without certain lines
(like a comment) preceeding it.


# 1.63 10-Jan-2000 todd

allow arbitrary commands in /etc/hostname.* files if the line starts with '!'


# 1.62 02-Jan-2000 deraadt

rtsol case can configure the interface up, since it would be nice to finish
DAD before the actual rtsol(8) run happens later. and since it will rtsol,
it is going to be up in any case.


# 1.61 02-Jan-2000 itojun

one more indentation fix.


# 1.60 02-Jan-2000 itojun

indentation fix (todd's part)


# 1.59 02-Jan-2000 todd

fix rtsold case, reset cmd for each iteration!


# 1.58 02-Jan-2000 itojun

allow options after "rtsol".
XXX both "dhcp" and "rtsol" has keyword *down* at the end. is it okay?


# 1.57 02-Jan-2000 itojun

echo "IPv6 autoconf: interfaces" before invoking rtsol.
sleep for net.inet6.ip6.dad_count seconds to ensure that IPv6 DAD is completed.
TODO: rtsold (rc.conf line), manpage


# 1.56 02-Jan-2000 itojun

ipv6 autoconf on hosts (non-routers).

to do this,
1. in sysctl.conf, add these lines:
net.inet6.ip6.forwarding=0
net.inet6.ip6.accept_rtadv=1
2. in hostname.foo, add
rtsol

specifying two or more interfaces with "rtsol" may result in strange
behavior - ipv6 spec does not permit multi-interface node to be autoconfig'ed.


# 1.55 02-Jan-2000 todd

add to hostname.* parsing:
- multiple entries support (read: aliases)
- inet6 support
- support for comments (#)
(look for hostname.if(5) commit for syntax details)


# 1.54 31-Dec-1999 itojun

install IPv6 reject routes only if kernel is capable of IPv6.


# 1.53 09-Dec-1999 itojun

avoid transmitting invalid IPv6 packets out to the wire.


# 1.52 09-Dec-1999 itojun

do not perform IPv6 initialization for loopback interface.
MUST make lo0 up before any IPv6 operations.
it will be considered a pilot error if you don't.
(I prefer to have lo0 initialized automatically)


Revision tags: OPENBSD_2_6_BASE
# 1.51 01-Sep-1999 deraadt

support # characters in bridgename.* files; millert


# 1.50 01-Sep-1999 deraadt

cleanup parsing of hostname.* files, and seperate bridge control into
bridgename.* files; all documented in new hostname.if(5) and
bridgename.if(5) man pages


# 1.49 09-Aug-1999 angelos

Only parse/setup the hostname.foo file if interface foo exists (this
is useful for laptops with different ethernet cards etc.)


Revision tags: OPENBSD_2_5_BASE
# 1.48 29-Mar-1999 niklas

New multicast route setup style


# 1.47 26-Mar-1999 niklas

Add bridge interface handling


# 1.46 01-Mar-1999 millert

Add support in /etc/hostname.xxx for files of the format:
up [options]
Any of the following may or may not be set:
$name $mask $bcaddr $extras


# 1.45 28-Oct-1998 millert

Kill the awful hack used to match and split /etc/hostname.* We now use
a function, isalphanumeric, to determine whether an interface name is
likely to be valid. This means that things like /etc/hostname.le0.bak,
/etc/hostname.le0#, /etc/hostname.le0~, etc. will be ignored as they
should. There is no longer an implicate assumption that /etc/hostname.*
only contains a single '.'.


Revision tags: OPENBSD_2_4_BASE
# 1.44 06-Oct-1998 deraadt

move ipnat to end of netstart, to support dhcp+ipnat


# 1.43 18-Sep-1998 deraadt

apply media directives on dhcp interfaces


# 1.42 10-Sep-1998 marc

better way of handling dhcp client; Jason Ish <jbi130@mail.usask.ca>


# 1.41 08-Sep-1998 marc

dhcp client stuff. "Angelos D. Keromytis" <angelos@dsl.cis.upenn.edu>


# 1.40 24-Aug-1998 downsj

You can't use -interface default when there's no default gateway
set (yet). Use -interface $hostname if mygate doesn't exist so that
this actually works on routers.


# 1.39 04-Jul-1998 deraadt

put 224 route on default, to avoid a hostname lookup


# 1.38 22-May-1998 deraadt

use route -n, what the heck


Revision tags: OPENBSD_2_3_BASE
# 1.37 28-Mar-1998 deraadt

s/^nat/ipnat/


# 1.36 23-Feb-1998 niklas

remove trailing blank line


# 1.35 07-Feb-1998 deraadt

ipforward is in sysctl.conf now


# 1.34 21-Dec-1997 deraadt

ugh


# 1.33 20-Dec-1997 deraadt

ipforwarding option in rc.conf


# 1.32 29-Nov-1997 kstailey

NAT requires IPF


# 1.31 04-Nov-1997 deraadt

kill spaces at ends of lines; m4


Revision tags: OPENBSD_2_2_BASE
# 1.30 14-Oct-1997 deraadt

set hostname/domainname before running rc.conf; m4@umn.edu


# 1.29 04-Sep-1997 deraadt

fork netstart; new child is rc.conf


# 1.28 25-Aug-1997 millert

Explicately pass -host flag to route(8) to avoid confusion with networks.


# 1.27 19-Aug-1997 niklas

Add hook for rpc.lockd, make nfsd flags settable in netstart


# 1.26 31-Jul-1997 downsj

Make quotas optional; wedged into netstart for the time being.
/etc/rc.conf, anyone?


# 1.25 30-Jul-1997 deraadt

do not run routed by default


# 1.24 28-Jul-1997 kstailey

Move configuration of loopback interface to before all other interfaces.
Allows the use of local caching-only nameserver with no "nameserver"
entry in /etc/resolv.conf to configure a route between the hostname
and loopback.


# 1.23 25-Jul-1997 provos

earlier start of keymanagement


# 1.22 24-Jul-1997 deraadt

make amd use /tmp_mnt by default


# 1.21 22-Jul-1997 provos

start the photuris daemon per default. hilfe.


# 1.20 17-Jun-1997 niklas

Put in hooks to start ypserv with flags


# 1.19 17-Jun-1997 niklas

Put in hooks to start rpc.yppasswdd with flags


Revision tags: OPENBSD_2_1_BASE
# 1.18 15-Apr-1997 deraadt

kill route flush until .. hmm kernel routing socket bug or something


# 1.17 09-Apr-1997 kstailey

add NAT startup


# 1.16 07-Apr-1997 rees

flush all old routes before adding new interfaces or routes.
ref: netbsd pr3228/misc, Matthias Scheler


# 1.15 03-Mar-1997 downsj

fix typo


# 1.14 11-Feb-1997 deraadt

add default route before fiddling with loopback route to avoid DNS problems; m4@umn.edu, #97


# 1.13 03-Feb-1997 deraadt

do ifaliases after /usr/bin exists in nfs diskless env; pr#77, matthieu@laas.fr


# 1.12 02-Nov-1996 deraadt

timed off by default


Revision tags: OPENBSD_2_0_BASE
# 1.11 23-Sep-1996 deraadt

rfc1323 variable


# 1.10 04-Sep-1996 deraadt

control portmap, inetd, and lpd from netstart; idea from tqbf@enteract.com


# 1.9 27-Aug-1996 deraadt

224.0.0.0 not 0.0.0.224; from peter@demon.net


# 1.8 18-Jun-1996 deraadt

move std stuff from rc.local to rc


# 1.7 16-Jun-1996 deraadt

install sample commented /etc/ifaliases file; which can now contain #
comments and blank lines. new format is "interface address netmask"
(yes, i changed the order of the entries). inspired by netbsd pr#2474;
gillhaa@ghost.whirlpool.com


# 1.6 02-Jun-1996 tholo

Install a multicast route by default


# 1.5 26-May-1996 deraadt

sync & label


# 1.4 09-Jan-1996 dm

added IP filter to netstat/rc and put examples in /usr/share/ipf


# 1.3 30-Dec-1995 deraadt

from netbsd: start mrouted like routed


# 1.2 18-Dec-1995 deraadt

/etc/ifaliases support by randy@zyzzyva.com


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.187 12-Nov-2017 tb

Remove HN_DIR variable and expand it in the only place it was used. It
currently serves no purpose.

ok rpe, agreement from deraadt and halex


Revision tags: OPENBSD_6_2_BASE
# 1.186 25-Jul-2017 rpe

Finally remove backwards compat code to support the 'rtsol' keyword
in hostname.if(5)

OK mpi@ deraadt@ florian@
OK jmc@ from doc perspective


# 1.185 21-Jul-2017 rpe

Align ifstart() in netstart and install.sub.

- in netstart, rename _file to _hn referencing hostname.if files
- in install.sub switch ifstart() to be used with _if instead of
_hn as parameter

ok krw@ tb@


# 1.184 28-May-2017 awolk

etc/netstart: use colon separator instead of dot with chown

OK jung@, deraadt@, jmc@


# 1.183 07-May-2017 rpe

Change test from [] to [[]] and simplify pattern.

OK tb@, krw@ (for [[]])
Feedback and OK halex@


# 1.182 07-May-2017 rpe

Replace hardcoded script name with ${0##*/}

OK tb@ halex@


# 1.181 01-May-2017 rpe

Revert r1.170 and remove the id==0 check.
The id binary is not available in nfs diskless setups at this point.

reported by Andreas Kusalananda, thanks.
discussed with deraadt@


# 1.180 01-May-2017 rpe

Remove last remnants of rtsol. IPv6 autoconfiguration of interfaces is now
done in ifstart(). Remove ipv6autoconf() and replace rtsolif with a boolean
variable V6_AUTOCONF. Replace dhcpif with a boolean variable V4_DHCPCONF.
Both are later used in defaultroute() to decide whether or not to configre
defaultroutes from /etc/mygate.

OK krw@


# 1.179 30-Apr-2017 mpi

Do not try to delete a default route before adding it.

Now that route are automatically G/C with the address they are attached
to there's no reason to duplicate the kernel's job.

Fix a regression introduced with multipath default routes.

ok deraadt@


# 1.178 25-Apr-2017 rpe

Unbreak netstart for multiple inteface configurations like trunk
or carp. Ensure that the noglob option is disabled at the end of
parse_hn_line() and ifstart().

Reported by Christer Solskogen and Stefan Wollny, thanks!


# 1.177 24-Apr-2017 rpe

Introduce a new function parse_hn_line() that replaces the existing
hostname.if(5) parsing code in ifstart().
Add a -n option to netstart to only print the interface configuration
commands instead of executing them.
Add a HN_DIR variable, that points to the directory of the hostname.if
files (default /etc) that allows for future regression tests.

- add new parse_hn_line() function
- change ifstart()
- rename $if to $_if
- don't ifconfig or ifconfig create if -n option is used
- replace hostname.if(5) parsing code with new parse_hn_line()
- just print configuration commands if -n option is used
- autoconf now happens in ifstart(), remove ifv6autoconf()
- introduce HN_DIR variable for the hostname.if file location
- add handling of the -n option to only print config commands
- ensure -n is only used if interfaces are specified as parameters

Discussed with and positive feedback from many
'commit' deraadt@
OK sthen@


# 1.176 08-Apr-2017 rpe

- localize the if, file and stat variables which also ensures that
variables are not named like commands.
- change test from [] to [[]]

OK tb@ halex@


# 1.175 07-Apr-2017 rpe

Minimize differences in ifstart() function between netstart and
install.sub which makes it easier to spot changes in the future.

- comments and formatting
- quotes on assignments are not needed (netstart)
- remove stray space in test (netstart)
- use $file variable with while-loop (netstart)
- although valid, instead of i use $i in arithmetic test (install.sub)

OK krw@, tb@
Looks good deraadt@


# 1.174 07-Apr-2017 rpe

Align comments of ifstart() function in netstart and install.sub.


# 1.173 07-Apr-2017 rpe

Align comments of stripcom() function in netstart and install.sub.


Revision tags: OPENBSD_6_1_BASE
# 1.172 06-Dec-2016 mpi

Do not lose the default route when netstart(8) is run a second time on
the interface pointed to by the default route.

Since the kernel no longer keep routes with dangling address pointer,
netstart(8) has to re-add the default route when the corresponding ifa
has been deleted and re-created.

deraadt@ points out that even if the previous semantic was not necessarily
better, a script like netstart(8) cannot totally fix the default route
problem.

Regression reported by and fix tested by Hrvoje Popovski.

ksh foo checked by halex@


# 1.171 27-Sep-2016 rzalamena

Delay switch(4) interface start up so it can attach virtual interfaces
like vether(4).

nits from and ok benno@, phessler@


# 1.170 09-Sep-2016 jasper

print a clear error message when not ran as root instead of just falling
through and try whatever it can do with the invoking user's perms

feedback/ok aja@ rpe@


Revision tags: OPENBSD_6_0_BASE
# 1.169 19-Jul-2016 mpi

Do not consider tap(4) a special interface and start if before other
pseudo-interfaces.

This unbreak vlan(4) on top of tap(4) since the refactoring to turn it
MP-safe.

ok claudio@, deraadt@


# 1.168 27-Mar-2016 sthen

Don't delete the 224/4 route in netstart, unless it's being done to ensure that
a -reject route can be added. Restores the ability to set an interface route
before daemons are started, lost during the previous simplification.
ok millert mpi


Revision tags: OPENBSD_5_9_BASE
# 1.167 29-Dec-2015 rpe

Remove backslash, not necessary after '&&'

OK halex@


# 1.166 29-Dec-2015 rpe

Replace last remaining `` with $()

OK halex@


# 1.165 18-Dec-2015 ajacoutot

Drop the now useless multicast setup comment.

prodded by tim@, ok mpi@


# 1.164 17-Dec-2015 ajacoutot

Simplify multicast option handling (10 less lines) by matching /etc/rc behavior
towards other YES|NO options and drop the error warning.


with and ok tim@, ok rpe@ on an earlier diff


# 1.163 05-Dec-2015 mpi

It does not make sense to insert a specific route for 224/4 when the
default one is good enough.

So merge rc.conf(8)'s 'multicast_router' and 'multicast_host' into a
single 'multicast'. If set to YES the reject route for 224/4 is not
inserted by netstart(8).

Manual bits from jmc@

ok henning@, ajacoutot@


# 1.162 12-Nov-2015 rpe

Changes to ifautostart():
- Rename function to ifv6autoconf() to make IPv6 relation clearer
- Localize and rename variables

OK krw@


# 1.161 12-Nov-2015 rpe

Changes to ifmstart():
- Change comments to make it clearer that ifmstart() takes two lists
of interface driver names (of which the second is optional) and not
the actual interface instances.
- Use localized variables and use slightly more verbose names.
- Use continue 2 to skip to the next hostname.if file.
- Use shell pattern @() instead of testing _sif individually.

OK krw@


# 1.160 12-Nov-2015 rpe

Changes to stripcom():
- Align comments with /etc/rc version
- Use localized variables
- Use safer "print -r --" instead of plain echo

Changes to ifstart():
- Tweak comment
- Add usage

OK krw@


# 1.159 01-Nov-2015 rpe

Start the rework of the /etc/netstart shell script.

General changes:
- apply a similar 'style' as used in the installer scripts
- improve comments to be more to the point, remove where code is obvious
- document usage of functions if they have arguments
- rename variables where it improves readability
- replace really old-school shell code with more contemporary idioms

Other changes:
- No need to care about "autoboot" because netstart doesn't inherit the
positional parameters from /etc/rc anymore. /etc/rc executes netstart
instead of sourcing it since r1.439.
- Use simpler for-loop to process list of interfaces with ifstart.

OK halex@


# 1.158 26-Oct-2015 rpe

The hostname variable is not used since r1.99. Remove it and use
stripcom() output directly with the hostname command.

OK deraadt@ krw@


# 1.157 23-Oct-2015 claudio

netstart bits for tap(4)


# 1.156 27-Sep-2015 sthen

Don't print output when setting autoconf on interfaces. Suggested by deraadt,
ok florian@ rpe@


# 1.155 13-Sep-2015 sthen

only print the "IPv6 autoconf" line if there are interfaces to configure
feedback/ok rpe


# 1.154 11-Sep-2015 sthen

Set "inet6 autoconf" individually on interfaces that have rtsol set in
hostname.if, previously netstart tried to configure them all at once
("ifconfig if0 if1 if2 inet6 autoconf"). From Delan Azabani, ok phessler@


Revision tags: OPENBSD_5_8_BASE
# 1.153 20-Jul-2015 rpe

Disable Strict Bourne shell mode for /etc/rc and /etc/netstart to be
able to use ksh syntax within these scripts. This way init doesn't
need to be changed, which starts /etc/rc using /bin/sh and people
can still use "sh /etc/netstart ifname".

Idea from and OK halex@
OK deraadt@ krw@ guenther@


# 1.152 19-Jul-2015 florian

Bring up pflow last as it might send with a source address that is on
any of the other interfaces.
OK deraadt, phessler, benno


# 1.151 19-Jul-2015 rpe

Always source rc.subr to be able to use the rc.conf parsing routine
to get the network related vars from rc.conf. This is even necessary
if netstart is run from within /etc/rc. Remove test of $INRC which
unintentionally evaluated always to true.

problem with previous change found by nigel@
OK sthen@ aja@ halex@


# 1.150 19-Jul-2015 ajacoutot

Revert 1.148 for now until I can talk to rpe@
It introduced a regression reported by nigel@


# 1.149 19-Jul-2015 rpe

Replace test command with [].

OK halex@ krw@


# 1.148 19-Jul-2015 rpe

Ensure, that we source rc.subr and parse rc.conf ONLY if we are not
inside /etc/rc.

With help from and OK halex@, ajacoutot@


# 1.147 18-Jul-2015 rpe

- remove trailing blanks introduced in previous commit
- no space in redirections like </foo or >$bar
- few other minor whitespaces

OK krw@


# 1.146 18-Jul-2015 rpe

Improve comments
- Add comments for functions
- Start comments with capital letters
- End comments with a full stop
- Allow comments to extend up to column 80

OK krw@


# 1.145 06-Jun-2015 florian

Allow rtsol keyword in hostname.if(5) with net.inet6.ip6.forwarding=1.
"inet6 autoconf" was working before and rtsol should behave the same.
OK phessler


Revision tags: OPENBSD_5_7_BASE
# 1.144 03-Dec-2014 florian

The kernel handles rtsol(8) functionality since some time now.
Treat rtsol in hostname.if as a keyword like dhcp and call ifconfig
inet6 autoconf.
"reads good" todd@
OK krw@ (who is *not* an IPv6 person), but I recruited him in his
capacity as an installer person.


# 1.143 28-Sep-2014 claudio

Revert 1.142. Without the down netstart will just print the ifconfig
output because it may end up just calling 'ifconfig $if'. This needs
to be done better and properly tested.


# 1.142 26-Sep-2014 halex

remove explicit 'down' of an interface before starting a dhcp request, thereby
avoiding annoying delays for some switch configurations

ok claudio@ deraadt@

i would add ok phessler@, but it was not valid without an ok krw@


Revision tags: OPENBSD_5_6_BASE
# 1.141 12-Jul-2014 stsp

Fix netstart after autoconf6 change so 'rtsol' lines in hostname.if work again.
found by pelikan@; ok pelikan@ henning@


# 1.140 12-Jul-2014 robert

Make rc.conf a parsed configuration file and stop sourcing it as a shell
script.
From now on rc.conf has a fixed syntax (key=val) and it is not allowed
to add anything to it besides the supported syntax, it all going to be
ignored.

discussed with and help from deraadt@ and halex@


Revision tags: OPENBSD_5_5_BASE
# 1.139 22-Aug-2013 mpi

Like for dhclient, do no create a route to alias addresses via 127.0.0.1.
Our stack is able to tell if the address is local or not.

ok todd@, krw@


Revision tags: OPENBSD_5_4_BASE
# 1.138 20-Mar-2013 todd

fix lies in netstart; replacement wording from halex@
pointed out by Ryan Kavannagh rak at debian dot org


Revision tags: OPENBSD_5_3_BASE
# 1.137 05-Dec-2012 rpe

remove "Invalid interface name" message
requested by krw@

ok halex@


# 1.136 02-Dec-2012 rpe

use the more compact version of the check for ifconfig'able interfaces
from install.sub

with feedback from and ok halex


# 1.135 02-Dec-2012 rpe

- remove isalphanumeric() and replace it with a shell pattern, that
tries a bit harder to identify invalid interface names and in
this case emit an error message.
- use [[ $1 == autoboot ]] to avoid a shell error message due to
possible spaces in first argument
- no change in functionality

discussed with krw and halex
ok ("I like this") krw


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.134 07-Oct-2011 deraadt

The new ypbind changes requires that the domainname be set before
rc.conf is run. There's no real downside.
ok aja


Revision tags: OPENBSD_5_0_BASE
# 1.133 07-Jul-2011 guenther

Eliminate some $? tests by rolling the command into the condition

ok halex@


# 1.132 26-May-2011 mpf

Add svlan(4) startup bits.
From markus@. OK naddy, claudio, reyk.


Revision tags: OPENBSD_4_9_BASE
# 1.131 09-Feb-2011 sobrado

fix an unbalanced parenthesis in a comment; while here, split the comment
in a better place to make it more readable.

ok jmc@ and miod@


Revision tags: OPENBSD_4_8_BASE
# 1.130 16-Jun-2010 todd

permit e.g. -inet6 syntax by slurping all lines not just some
noticed by rhsv6 at hushmail dot com, ok sthen@


Revision tags: OPENBSD_4_7_BASE
# 1.129 12-Jan-2010 henning

when setting up lo0 use 127.0.0.1/8 instead of 127.0.0.1 for clarity and
correctness. it's not 1992 any more, kids. ok mcbride dlg krw


# 1.128 10-Dec-2009 todd

o stop reordering ifconfig arguments (e.g. after 'up ..')
o only stop processing if inet or inet6 lines are malformed
o everything not a specially handled bit is passed to ifconfig unmangled
noticed by several after the move from bridgename.bridge0 -> hostname.bridge0
prodded by deraadt@, tested by and feedback from several
man page bits 'look fine' jmc@


# 1.127 22-Nov-2009 deraadt

Stop supporting bridgename.bridge* files, and move to hostname.bridge*
files. To cope with this change, read about the mv command.
ok claudio todd


# 1.126 17-Sep-2009 simon

change variable i to $i in an expression of ifstart() for consistency
with the rest of the file. no functional change.

feedback from sthen@, ok krw@


# 1.125 10-Jul-2009 jdixon

Delay creation of tun(4) interfaces until the underlying interface and
routes are available. This fixes usage for some OpenVPN users that start
it from hostname.tun*.

Tested by Johan Huldtgren. ok sthen@, johan@.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.124 25-Nov-2008 markus

delay /etc/netstart until IPv6-DAD (dup-address-detection) is completed.
ok fries, hshoexer, claudio


# 1.123 14-Aug-2008 sthen

Tools from /usr may not be used in netstart since it may be NFS-mounted
and not available at that time. Rewrite the hostname.if permission check
to use only /bin/ls and the shell. Requested by deraadt.

ok todd, "Twisted." deraadt


Revision tags: OPENBSD_4_4_BASE
# 1.122 23-Jul-2008 sthen

Prevent warning about insecure hostnames where no /etc/hostname.*
exists. From wcmaier@.

Check target of symbolic links to avoid noise at boot and in
seucrity output where you have several interfaces symlinked to one
config file.

"If you think this is the right thing to do" deraadt@


# 1.121 09-Jun-2008 todd

warn once not 3 times in case of a non existent file, discussed with deraadt
originally pointed out by Johan Torin


# 1.120 09-Jun-2008 deraadt

Ensure that hostname.* files are also re-chowned to root.wheel at each
boot as discussed with claudio while eating tasty donairs. ok todd


# 1.119 17-Apr-2008 deraadt

before using them, force hostname.* files to be unreadable by world
first version from todd, ok millert


Revision tags: OPENBSD_4_3_BASE
# 1.118 17-Jan-2008 brad

Execute rtsol after turning up trunk(4) and vlan(4) interfaces so they're
taken into consideration for rtsol.

ok reyk@ dlg@


# 1.117 09-Jan-2008 mpf

Do not bring up pfsync(4) before the working ruleset
has been loaded. Otherwise, states that are received during the
initial bulk update mismatch the correct pf-checksum and
do not attach to the rules.
Problem identified by david@. Fix done in collaboration.
OK henning@


Revision tags: OPENBSD_4_2_BASE
# 1.116 02-Aug-2007 david

move the delay for IPv6 DAD to after all interfaces have started
fixes problems with daemons being unable to bind to all addreses at boot
ok itojun@ hshoexer@


Revision tags: OPENBSD_4_1_BASE
# 1.115 15-Nov-2006 itojun

reject multicast packet without scope identifier specified.


Revision tags: OPENBSD_4_0_BASE
# 1.114 29-Jun-2006 todd

do not add an extra space; nwid and description come out wrong
fix as proposed by maja@, thanks!


Revision tags: OPENBSD_3_9_BASE
# 1.113 28-Dec-2005 david

nuke extra whitespace


# 1.112 06-Dec-2005 reyk

multicast_host=YES only works if a valid default gateway is available.
validate this condition and reject multicast traffic on failure.

ok todd@ naddy@


# 1.111 02-Nov-2005 todd

fix inspired by pr#4590
ok krw@


# 1.110 25-Oct-2005 todd

better logic from krw@:
- do not process mygate for v4 if dhcp
- do not process mygate for v6 if rtsol
this also makes the mygate processing logic more readable
ok krw@


# 1.109 14-Oct-2005 todd

add v6 support for /etc/mygate
ok deraadt@ mickey@ krw@
same functionality tested/ok'ed by by mickey, brad, matthieu, and me
with this one may now put a v6 IP in /etc/mygate on a separate line from
the v4 default gateway and netstart will do the right thing


# 1.108 12-Oct-2005 todd

shrink stripcom(), sync with install.sub
ok krw@


# 1.107 04-Oct-2005 todd

trunk must be started after physical ethernet devices, but before vlan.
populate ifmstart lines accordingly.
prodded/tested by brad@
ok reyk@


# 1.106 28-Sep-2005 todd

use eval consistently, fixes description quotes on rtsol and dhcp
fix inspired by and closes pr 4495
ok krw@


Revision tags: OPENBSD_3_8_BASE
# 1.105 22-May-2005 todd

Introduce 'ifmstart' to deal with starting multiple interfaces minus a list
of interfaces.

This reduces the netstart script by 174 chars, 13 words, and 19 lines, but
more importantly, makes it more simple and less cluttered should more special
case/orderings be needed.

ok brad@ and pr 4197 submitter, inspired by and closes pr 4197


# 1.104 04-Apr-2005 djm

unbreak; ok pval@


# 1.103 03-Apr-2005 deraadt

if dhcp is used to get an address on any interface, ignore /etc/mygate
ok krw
(this lets us do something rather cool with the zaurus in particular)


Revision tags: OPENBSD_3_7_BASE
# 1.102 04-Jan-2005 mcbride

Bring up the carp(4) interface before default route.

ok pascoe@ mpf@


# 1.101 30-Dec-2004 millert

Add a copy of stripcom so /etc/netstart can be run standalone again.
OK deraadt@


# 1.100 19-Dec-2004 millert

Allow comments in /etc/{myname,mygate,defaultdomain}; OK deraadt@


# 1.99 04-Dec-2004 itojun

remove "route $hostname 127.0.0.1" line. deraadt ok
*** please update /etc/netstart and test if it works ok for you ***


# 1.98 20-Oct-2004 deraadt

make all route commands use -qn; ok mcbride henning


Revision tags: OPENBSD_3_6_BASE
# 1.97 29-May-2004 deraadt

one last route command lacking -qn


Revision tags: OPENBSD_3_5_BASE
# 1.96 22-Mar-2004 mcbride

Make sure pfsync is brought up before carp.

ok deraadt@


# 1.95 13-Mar-2004 mcbride

Delay pfsync(4) configuration, as the syncif has to be configured in
advance. From Thorsten Lockert.


# 1.94 14-Jan-2004 deraadt

ok, it took quite a bit of prodding but itojun finally explained why the
extra sleep 1 is in here, and we came to the conclusion it is safe to
delete it. whee.


# 1.93 13-Jan-2004 deraadt

repair v6 lo0 documentation


# 1.92 11-Jan-2004 deraadt

add loopback routes late


# 1.91 09-Jan-2004 deraadt

create all routes with -q; markus ok


# 1.90 04-Dec-2003 millert

Need to do "ifconfig create" for bridge interfaces too.


# 1.89 03-Dec-2003 markus

add support for ifconfig clone; from netbsd; ok deraadt, henning


# 1.88 20-Oct-2003 david

delay carp initialization until after physical interfaces are configured
ok mcbride@ henning@ deraadt@ todd@


Revision tags: OPENBSD_3_4_BASE
# 1.87 27-Aug-2003 henning

only try to set hostname to what /etc/myname says if that file actually exists,
otherwise preserve `hostname`
netbooted machines can live perfectly fine without it; they get their hostname
earlier.

ok krw@ cedric@


Revision tags: OPENBSD_3_3_BASE
# 1.86 16-Feb-2003 krw

Fix up some DNS verbiage to make it consistant.

Fix up default route selection by

a) Forcing user to explicitly chose 'dhcp' as a mechanism for
specifying a default route, rather than guessing based on one or more
interfaces being configured by dhcp.

b) If the user specified default route does not work, re-present the
existing default route rather than losing it.

c) Move default route selection to after nameserver activation so the
user can specify a hostname as the default route.

Change /etc/netstart so that /etc/mygate wins if a default route was
already specified (i.e. by dhcp).

ok deraadt@.


Revision tags: OPENBSD_3_2_BASE
# 1.85 16-May-2002 todd

ignore non-existent cases where '$if' evaluates to '*'.
From Andr� Lucas <andre@ae-35.com>, fixes pr # 2658.
'Looks good' from miod@, millert@, and krw@.


Revision tags: OPENBSD_3_1_BASE
# 1.84 23-Feb-2002 deraadt

re-add support for $if expansion; hamajima@nagoya.ydc.co.jp


# 1.83 21-Feb-2002 miod

Change the network components initialization order.
Change from:
o all interfaces
o all bridges
o routes
to:
o physical interfaces
o routes
o gif and gre interfaces
o bridges

Fixeski PR #2400.
Manual page updates coming soon.
Ok angelos@ chris@ deraadt@


Revision tags: OPENBSD_3_0_BASE
# 1.82 31-Jul-2001 hugh

a space before a redirect


# 1.81 06-Jul-2001 angelos

Also, source /etc/rc.conf so we can pull in the
multicast_host/multicast_router settings; this is useful if one
flushes the routing table and re-initializes.

We really need a netconfig tool of sorts.


# 1.80 06-Jul-2001 angelos

Use "route -n show -inet" to determine the default multicast iface.


# 1.79 03-Jul-2001 deraadt

pull in rc.conf early so that pf(1) startup is right; tested by jasoni, comments from millert


# 1.78 30-May-2001 deraadt

Remove ipf. Darren Reed has interpreted his (old, new, whichever)
licence in a way that makes ipf not free according to the rules we
established over 5 years ago, at www.openbsd.org/goals.html (and those
same basic rules govern the other *BSD projects too). Specifically,
Darren says that modified versions are not permitted. But software
which OpenBSD uses and redistributes must be free to all (be they
people or companies), for any purpose they wish to use it, including
modification, use, peeing on, or even integration into baby mulching
machines or atomic bombs to be dropped on Australia. Furthermore, we
know of a number of companies using ipf with modification like us, who
are now in the same situation, and we hope that some of them will work
with us to fill this gap that now exists in OpenBSD (temporarily, we
hope).


Revision tags: OPENBSD_2_9_BASE
# 1.77 13-Mar-2001 deraadt

spelling; maurice@maurice.wan.nl


# 1.76 06-Feb-2001 todd

ignore blank lines in addition to comments
fixes pr#1660 from wilfried@telia.com .. Thanks!


# 1.75 10-Jan-2001 jason

support !command in bridgename.if files, too


# 1.74 27-Nov-2000 millert

Use -n to test if a variable is non-zero. Otherwise, if the variable's
contents start with a '-' test becomes unhappy (since it interprets it
as another option).


# 1.73 08-Nov-2000 todd

This fixes pr 1481, we now handle args > 6 in /etc/hostname.if in the
cases where we did not previously handle them.
Thanks to Scott Atwood <atwood@cs.stanford.edu> for reminding us of this.


Revision tags: OPENBSD_2_8_BASE
# 1.72 02-Sep-2000 todd

subtle bug .. global variables in a while loop need reset 'just incase'
With:
hostname.fxp0 having a last line of:
inet6 alias 3ffe:...
and hostname.gif0 having a first two lines of:
giftunnel 1.2.3.4
dest 1.2.4.3
We end up with the command:
ifconfig gif0 giftunnel alias 1.2.3.4 1.2.4.3
.. which is clearly wrong and fixed by this change


# 1.71 18-Jun-2000 todd

rc.conf now parses ${local_rcconf} internally; closes pr 1259


Revision tags: OPENBSD_2_7_BASE
# 1.70 08-May-2000 todd

fix dhcp 'NONE' ness from install to allow media parsing to work
.. ok deraadt@, millert@


# 1.69 21-Apr-2000 deraadt

rc.conf.local support, inspired by chuck yerkes


# 1.68 04-Apr-2000 millert

Remove the -E flag from ipf as it is implicitly enabled and using
the -E flag here causes the kernel to printf 'IP Filter: already
initialized'.


# 1.67 18-Mar-2000 deraadt

silence all extra route addition printouts


# 1.66 17-Mar-2000 itojun

correct reject route installations for IPv6. improve comments.


# 1.65 12-Mar-2000 itojun

disallow packets to malicious 6to4 prefix, based on
http://playground.iijlab.net/i-d/draft-itojun-ipv6-transition-abuse-00.txt


# 1.64 10-Mar-2000 todd

fix non behavior
with this `!' lines in /etc/hostname.* run even without certain lines
(like a comment) preceeding it.


# 1.63 10-Jan-2000 todd

allow arbitrary commands in /etc/hostname.* files if the line starts with '!'


# 1.62 02-Jan-2000 deraadt

rtsol case can configure the interface up, since it would be nice to finish
DAD before the actual rtsol(8) run happens later. and since it will rtsol,
it is going to be up in any case.


# 1.61 02-Jan-2000 itojun

one more indentation fix.


# 1.60 02-Jan-2000 itojun

indentation fix (todd's part)


# 1.59 02-Jan-2000 todd

fix rtsold case, reset cmd for each iteration!


# 1.58 02-Jan-2000 itojun

allow options after "rtsol".
XXX both "dhcp" and "rtsol" has keyword *down* at the end. is it okay?


# 1.57 02-Jan-2000 itojun

echo "IPv6 autoconf: interfaces" before invoking rtsol.
sleep for net.inet6.ip6.dad_count seconds to ensure that IPv6 DAD is completed.
TODO: rtsold (rc.conf line), manpage


# 1.56 02-Jan-2000 itojun

ipv6 autoconf on hosts (non-routers).

to do this,
1. in sysctl.conf, add these lines:
net.inet6.ip6.forwarding=0
net.inet6.ip6.accept_rtadv=1
2. in hostname.foo, add
rtsol

specifying two or more interfaces with "rtsol" may result in strange
behavior - ipv6 spec does not permit multi-interface node to be autoconfig'ed.


# 1.55 02-Jan-2000 todd

add to hostname.* parsing:
- multiple entries support (read: aliases)
- inet6 support
- support for comments (#)
(look for hostname.if(5) commit for syntax details)


# 1.54 31-Dec-1999 itojun

install IPv6 reject routes only if kernel is capable of IPv6.


# 1.53 09-Dec-1999 itojun

avoid transmitting invalid IPv6 packets out to the wire.


# 1.52 09-Dec-1999 itojun

do not perform IPv6 initialization for loopback interface.
MUST make lo0 up before any IPv6 operations.
it will be considered a pilot error if you don't.
(I prefer to have lo0 initialized automatically)


Revision tags: OPENBSD_2_6_BASE
# 1.51 01-Sep-1999 deraadt

support # characters in bridgename.* files; millert


# 1.50 01-Sep-1999 deraadt

cleanup parsing of hostname.* files, and seperate bridge control into
bridgename.* files; all documented in new hostname.if(5) and
bridgename.if(5) man pages


# 1.49 09-Aug-1999 angelos

Only parse/setup the hostname.foo file if interface foo exists (this
is useful for laptops with different ethernet cards etc.)


Revision tags: OPENBSD_2_5_BASE
# 1.48 29-Mar-1999 niklas

New multicast route setup style


# 1.47 26-Mar-1999 niklas

Add bridge interface handling


# 1.46 01-Mar-1999 millert

Add support in /etc/hostname.xxx for files of the format:
up [options]
Any of the following may or may not be set:
$name $mask $bcaddr $extras


# 1.45 28-Oct-1998 millert

Kill the awful hack used to match and split /etc/hostname.* We now use
a function, isalphanumeric, to determine whether an interface name is
likely to be valid. This means that things like /etc/hostname.le0.bak,
/etc/hostname.le0#, /etc/hostname.le0~, etc. will be ignored as they
should. There is no longer an implicate assumption that /etc/hostname.*
only contains a single '.'.


Revision tags: OPENBSD_2_4_BASE
# 1.44 06-Oct-1998 deraadt

move ipnat to end of netstart, to support dhcp+ipnat


# 1.43 18-Sep-1998 deraadt

apply media directives on dhcp interfaces


# 1.42 10-Sep-1998 marc

better way of handling dhcp client; Jason Ish <jbi130@mail.usask.ca>


# 1.41 08-Sep-1998 marc

dhcp client stuff. "Angelos D. Keromytis" <angelos@dsl.cis.upenn.edu>


# 1.40 24-Aug-1998 downsj

You can't use -interface default when there's no default gateway
set (yet). Use -interface $hostname if mygate doesn't exist so that
this actually works on routers.


# 1.39 04-Jul-1998 deraadt

put 224 route on default, to avoid a hostname lookup


# 1.38 22-May-1998 deraadt

use route -n, what the heck


Revision tags: OPENBSD_2_3_BASE
# 1.37 28-Mar-1998 deraadt

s/^nat/ipnat/


# 1.36 23-Feb-1998 niklas

remove trailing blank line


# 1.35 07-Feb-1998 deraadt

ipforward is in sysctl.conf now


# 1.34 21-Dec-1997 deraadt

ugh


# 1.33 20-Dec-1997 deraadt

ipforwarding option in rc.conf


# 1.32 29-Nov-1997 kstailey

NAT requires IPF


# 1.31 04-Nov-1997 deraadt

kill spaces at ends of lines; m4


Revision tags: OPENBSD_2_2_BASE
# 1.30 14-Oct-1997 deraadt

set hostname/domainname before running rc.conf; m4@umn.edu


# 1.29 04-Sep-1997 deraadt

fork netstart; new child is rc.conf


# 1.28 25-Aug-1997 millert

Explicately pass -host flag to route(8) to avoid confusion with networks.


# 1.27 19-Aug-1997 niklas

Add hook for rpc.lockd, make nfsd flags settable in netstart


# 1.26 31-Jul-1997 downsj

Make quotas optional; wedged into netstart for the time being.
/etc/rc.conf, anyone?


# 1.25 30-Jul-1997 deraadt

do not run routed by default


# 1.24 28-Jul-1997 kstailey

Move configuration of loopback interface to before all other interfaces.
Allows the use of local caching-only nameserver with no "nameserver"
entry in /etc/resolv.conf to configure a route between the hostname
and loopback.


# 1.23 25-Jul-1997 provos

earlier start of keymanagement


# 1.22 24-Jul-1997 deraadt

make amd use /tmp_mnt by default


# 1.21 22-Jul-1997 provos

start the photuris daemon per default. hilfe.


# 1.20 17-Jun-1997 niklas

Put in hooks to start ypserv with flags


# 1.19 17-Jun-1997 niklas

Put in hooks to start rpc.yppasswdd with flags


Revision tags: OPENBSD_2_1_BASE
# 1.18 15-Apr-1997 deraadt

kill route flush until .. hmm kernel routing socket bug or something


# 1.17 09-Apr-1997 kstailey

add NAT startup


# 1.16 07-Apr-1997 rees

flush all old routes before adding new interfaces or routes.
ref: netbsd pr3228/misc, Matthias Scheler


# 1.15 03-Mar-1997 downsj

fix typo


# 1.14 11-Feb-1997 deraadt

add default route before fiddling with loopback route to avoid DNS problems; m4@umn.edu, #97


# 1.13 03-Feb-1997 deraadt

do ifaliases after /usr/bin exists in nfs diskless env; pr#77, matthieu@laas.fr


# 1.12 02-Nov-1996 deraadt

timed off by default


Revision tags: OPENBSD_2_0_BASE
# 1.11 23-Sep-1996 deraadt

rfc1323 variable


# 1.10 04-Sep-1996 deraadt

control portmap, inetd, and lpd from netstart; idea from tqbf@enteract.com


# 1.9 27-Aug-1996 deraadt

224.0.0.0 not 0.0.0.224; from peter@demon.net


# 1.8 18-Jun-1996 deraadt

move std stuff from rc.local to rc


# 1.7 16-Jun-1996 deraadt

install sample commented /etc/ifaliases file; which can now contain #
comments and blank lines. new format is "interface address netmask"
(yes, i changed the order of the entries). inspired by netbsd pr#2474;
gillhaa@ghost.whirlpool.com


# 1.6 02-Jun-1996 tholo

Install a multicast route by default


# 1.5 26-May-1996 deraadt

sync & label


# 1.4 09-Jan-1996 dm

added IP filter to netstat/rc and put examples in /usr/share/ipf


# 1.3 30-Dec-1995 deraadt

from netbsd: start mrouted like routed


# 1.2 18-Dec-1995 deraadt

/etc/ifaliases support by randy@zyzzyva.com


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision