head	1.8;
access;
symbols
	netbsd-11-0-RC4:1.8
	netbsd-11-0-RC3:1.8
	dhcpcd-10_3_1:1.1.1.9
	netbsd-11-0-RC2:1.8
	netbsd-11-0-RC1:1.8
	perseant-exfatfs-base-20250801:1.8
	netbsd-11:1.8.0.2
	netbsd-11-base:1.8
	dhcpcd-10_2_3:1.1.1.9
	dhcpcd-10_2_2:1.1.1.8
	dhcpcd-10_2_0a:1.1.1.8
	dhcpcd-10_2_0:1.1.1.8
	netbsd-10-1-RELEASE:1.6
	perseant-exfatfs-base-20240630:1.7
	perseant-exfatfs:1.7.0.2
	perseant-exfatfs-base:1.7
	dhcpcd-10_0_8:1.1.1.8
	dhcpcd-10_0_7:1.1.1.8
	netbsd-8-3-RELEASE:1.1.1.1.8.2
	netbsd-9-4-RELEASE:1.3
	netbsd-10-0-RELEASE:1.6
	netbsd-10-0-RC6:1.6
	netbsd-10-0-RC5:1.6
	netbsd-10-0-RC4:1.6
	netbsd-10-0-RC3:1.6
	netbsd-10-0-RC2:1.6
	dhcpcd-10_0_6a:1.1.1.8
	dhcpcd-10_0_6:1.1.1.8
	netbsd-10-0-RC1:1.6
	dhcpcd-10_0_4:1.1.1.8
	dhcpcd-10_0_3:1.1.1.8
	dhcpcd-10_0_2:1.1.1.8
	dhcpcd-10_0_1:1.1.1.8
	netbsd-10:1.6.0.6
	netbsd-10-base:1.6
	netbsd-9-3-RELEASE:1.3
	dhcpcd-9_4_1:1.1.1.7
	cjep_sun2x-base1:1.6
	cjep_sun2x:1.6.0.4
	cjep_sun2x-base:1.6
	cjep_staticlib_x-base1:1.6
	netbsd-9-2-RELEASE:1.3
	cjep_staticlib_x:1.6.0.2
	cjep_staticlib_x-base:1.6
	dhcpcd-9_4_0:1.1.1.7
	dhcpcd-9_3_4:1.1.1.6
	dhcpcd-9_3_3:1.1.1.6
	dhcpcd-9_3_2:1.1.1.5
	netbsd-9-1-RELEASE:1.3
	dhcpcd-9_3_1:1.1.1.5
	dhcpcd-9_3_0:1.1.1.5
	dhcpcd-9_2_0:1.1.1.5
	dhcpcd-9_1_4:1.1.1.5
	dhcpcd-9_1_3:1.1.1.5
	dhcpcd-9_1_2:1.1.1.5
	dhcpcd-9_1_1:1.1.1.5
	dhcpcd-9_1_0:1.1.1.5
	phil-wifi-20200421:1.4
	dhcpcd-9_0_2:1.1.1.5
	dhcpcd-9_0_1:1.1.1.5
	phil-wifi-20200411:1.4
	is-mlppp:1.3.0.4
	is-mlppp-base:1.3
	phil-wifi-20200406:1.4
	dhcpcd-9_0_0:1.1.1.5
	netbsd-8-2-RELEASE:1.1.1.1.8.2
	netbsd-9-0-RELEASE:1.3
	netbsd-9-0-RC2:1.3
	dhcpcd-8_1_6:1.1.1.4
	dhcpcd-8_1_5:1.1.1.4
	dhcpcd-8_1_4:1.1.1.4
	dhcpcd-8_1_3:1.1.1.4
	netbsd-9-0-RC1:1.3
	phil-wifi-20191119:1.3
	dhcpcd-8_1_2:1.1.1.4
	dhcpcd-8_1_1:1.1.1.4
	dhcpcd-8_1_0:1.1.1.4
	ROY:1.1.1
	dhcpcd-8-0-6:1.1.1.4
	dhcpcd-8-0-5:1.1.1.4
	dhcpcd-8-0-4:1.1.1.4
	dhcpcd-8-0-3:1.1.1.4
	netbsd-9:1.3.0.2
	netbsd-9-base:1.3
	dhcpcd-8-0-2:1.1.1.4
	dhcpcd-8-0-1:1.1.1.4
	dhcpcd-8-0-0:1.1.1.4
	dhcpcd-7-2-3a:1.1.1.3
	phil-wifi-20190609:1.2
	netbsd-8-1-RELEASE:1.1.1.1.8.2
	netbsd-8-1-RC1:1.1.1.1.8.2
	dhcpcd-7-2-2:1.1.1.3
	dhcpcd-7-2-1:1.1.1.3
	dhcpcd-7-2-0:1.1.1.3
	dhcpcd-7-1-1:1.1.1.3
	pgoyette-compat-merge-20190127:1.1.1.2.2.1
	pgoyette-compat-20190127:1.2
	dhcpcd-7-1-0:1.1.1.3
	pgoyette-compat-20190118:1.2
	pgoyette-compat-1226:1.2
	pgoyette-compat-1126:1.2
	pgoyette-compat-1020:1.2
	pgoyette-compat-0930:1.2
	pgoyette-compat-0906:1.1.1.2
	netbsd-7-2-RELEASE:1.1.1.2.6.2
	dhcpcd-7-0-8:1.1.1.2
	pgoyette-compat-0728:1.1.1.2
	netbsd-7:1.1.1.2.0.6
	dhcpcd-7-0-7:1.1.1.2
	netbsd-8-0-RELEASE:1.1.1.1.8.1
	phil-wifi:1.1.1.2.0.4
	phil-wifi-base:1.1.1.2
	pgoyette-compat-0625:1.1.1.2
	netbsd-8-0-RC2:1.1.1.1.8.1
	dhcpcd-7-0-6:1.1.1.2
	dhcpcd-7-0-5b:1.1.1.2
	dhcpcd-7-0-5a:1.1.1.2
	dhcpcd-7-0-5:1.1.1.2
	pgoyette-compat-0521:1.1.1.2
	dhcpcd-7-0-4:1.1.1.2
	pgoyette-compat-0502:1.1.1.2
	pgoyette-compat-0422:1.1.1.2
	netbsd-8-0-RC1:1.1.1.1.8.1
	pgoyette-compat-0415:1.1.1.2
	pgoyette-compat-0407:1.1.1.2
	dhcpcd-7-0-3:1.1.1.2
	pgoyette-compat-0330:1.1.1.2
	dhcpcd-7-0-2:1.1.1.2
	pgoyette-compat-0322:1.1.1.2
	pgoyette-compat-0315:1.1.1.2
	pgoyette-compat:1.1.1.2.0.2
	pgoyette-compat-base:1.1.1.2
	dhcpcd-7-0-1:1.1.1.2
	dhcpcd-7-0-0:1.1.1.1
	dhcpcd-7-0-0-rc4:1.1.1.1
	matt-nb8-mediatek:1.1.1.1.0.12
	matt-nb8-mediatek-base:1.1.1.1
	dhcpcd-7-0-0-rc3:1.1.1.1
	dhcpcd-7-0-0-rc2:1.1.1.1
	perseant-stdc-iso10646:1.1.1.1.0.10
	perseant-stdc-iso10646-base:1.1.1.1
	netbsd-8:1.1.1.1.0.8
	netbsd-8-base:1.1.1.1
	prg-localcount2-base3:1.1.1.1
	prg-localcount2-base2:1.1.1.1
	dhcpcd-7-0-0-rc1:1.1.1.1
	prg-localcount2-base1:1.1.1.1
	prg-localcount2:1.1.1.1.0.6
	prg-localcount2-base:1.1.1.1
	pgoyette-localcount:1.1.1.1.0.4
	pgoyette-localcount-20170426:1.1.1.1
	bouyer-socketcan:1.1.1.1.0.2
	bouyer-socketcan-base1:1.1.1.1
	dhcpcd-7-0-0-beta3:1.1.1.1
	dhcpcd-7-0-0-beta2:1.1.1.1
	dhcpcd-7-0-0-beta1:1.1.1.1
	roy:1.1.1;
locks; strict;
comment	@# @;


1.8
date	2025.05.16.13.17.43;	author roy;	state Exp;
branches;
next	1.7;
commitid	iDD76tBMISFfl8VF;

1.7
date	2023.04.21.16.54.26;	author roy;	state Exp;
branches
	1.7.2.1;
next	1.6;
commitid	RSjPPlaT2zc9QZlE;

1.6
date	2020.12.28.13.57.40;	author roy;	state Exp;
branches;
next	1.5;
commitid	glmA8thTcbkBZvBC;

1.5
date	2020.11.20.13.24.58;	author roy;	state Exp;
branches;
next	1.4;
commitid	zpZxK7weice72DwC;

1.4
date	2020.04.02.12.41.47;	author roy;	state Exp;
branches;
next	1.3;
commitid	f8Wc4BN4taQtfO2C;

1.3
date	2019.07.24.09.57.43;	author roy;	state Exp;
branches;
next	1.2;
commitid	4iib5MRwJY8xthwB;

1.2
date	2018.09.22.13.17.46;	author kre;	state Exp;
branches;
next	1.1;
commitid	DO5SBbZluRbhn6TA;

1.1
date	2017.03.31.20.51.16;	author roy;	state Exp;
branches
	1.1.1.1;
next	;
commitid	2iSri9mccyHffKLz;

1.7.2.1
date	2025.08.02.05.21.01;	author perseant;	state Exp;
branches;
next	;
commitid	23j6GFaDws3O875G;

1.1.1.1
date	2017.03.31.20.51.16;	author roy;	state Exp;
branches
	1.1.1.1.2.1
	1.1.1.1.4.1
	1.1.1.1.8.1;
next	1.1.1.2;
commitid	2iSri9mccyHffKLz;

1.1.1.2
date	2018.01.29.11.11.23;	author roy;	state Exp;
branches
	1.1.1.2.2.1
	1.1.1.2.4.1
	1.1.1.2.6.1;
next	1.1.1.3;
commitid	ANwLArYxQ3OXfLoA;

1.1.1.3
date	2019.01.22.15.16.25;	author roy;	state Exp;
branches;
next	1.1.1.4;
commitid	ObRHdPr38Oth7N8B;

1.1.1.4
date	2019.07.24.09.54.49;	author roy;	state Exp;
branches;
next	1.1.1.5;
commitid	Nokc5jYoPRhfshwB;

1.1.1.5
date	2020.04.02.12.38.55;	author roy;	state Exp;
branches;
next	1.1.1.6;
commitid	B3wgJaSBzotdeO2C;

1.1.1.6
date	2020.11.20.13.23.39;	author roy;	state Exp;
branches;
next	1.1.1.7;
commitid	wyvM0GHuvNB91DwC;

1.1.1.7
date	2020.12.28.13.56.26;	author roy;	state Exp;
branches;
next	1.1.1.8;
commitid	rE25gHSvbs4yYvBC;

1.1.1.8
date	2023.04.21.16.52.46;	author roy;	state Exp;
branches;
next	1.1.1.9;
commitid	SzhZ9f5ppzfOOZlE;

1.1.1.9
date	2025.05.16.13.16.27;	author roy;	state Exp;
branches;
next	;
commitid	KslacjcDN1Q9k8VF;

1.1.1.1.2.1
date	2017.03.31.20.51.16;	author roy;	state dead;
branches;
next	1.1.1.1.2.2;

1.1.1.1.2.2
date	2017.03.31.20.51.17;	author roy;	state Exp;
branches;
next	;

1.1.1.1.4.1
date	2017.03.31.20.51.16;	author pgoyette;	state dead;
branches;
next	1.1.1.1.4.2;
commitid	ojV02aOSdzvBqZOz;

1.1.1.1.4.2
date	2017.04.26.02.52.23;	author pgoyette;	state Exp;
branches;
next	;
commitid	ojV02aOSdzvBqZOz;

1.1.1.1.8.1
date	2018.04.09.16.46.34;	author martin;	state Exp;
branches;
next	1.1.1.1.8.2;
commitid	EzvHIuotKE2mSMxA;

1.1.1.1.8.2
date	2019.04.26.19.18.22;	author martin;	state Exp;
branches;
next	;
commitid	ApYO1Wt23frIqTkB;

1.1.1.2.2.1
date	2018.09.30.01.45.11;	author pgoyette;	state Exp;
branches;
next	;
commitid	SQ44grEPCeKPh4UA;

1.1.1.2.4.1
date	2019.06.10.21.44.43;	author christos;	state Exp;
branches;
next	1.1.1.2.4.2;
commitid	jtc8rnCzWiEEHGqB;

1.1.1.2.4.2
date	2020.04.08.14.04.03;	author martin;	state Exp;
branches;
next	1.1.1.2.4.3;
commitid	Qli2aW9E74UFuA3C;

1.1.1.2.4.3
date	2020.04.13.07.45.58;	author martin;	state Exp;
branches;
next	;
commitid	X01YhRUPVUDaec4C;

1.1.1.2.6.1
date	2018.01.29.11.11.23;	author martin;	state dead;
branches;
next	1.1.1.2.6.2;
commitid	HmTKhyRj9OTCmLLA;

1.1.1.2.6.2
date	2018.07.27.10.43.20;	author martin;	state Exp;
branches;
next	;
commitid	HmTKhyRj9OTCmLLA;


desc
@@


1.8
log
@Sync with dhcpcd-10.2.3
@
text
@# Generate /etc/resolv.conf
# Support resolvconf(8) if available
# We can merge other dhcpcd resolv.conf files into one like resolvconf,
# but resolvconf is preferred as other applications like VPN clients
# can readily hook into it.
# Also, resolvconf can configure local nameservers such as bind
# or dnsmasq. This is important as the libc resolver isn't that powerful.

resolv_conf_dir="$state_dir/resolv.conf"
nocarrier_roaming_dir="$state_dir/roaming"
NL="
"
: ${resolvconf:=resolvconf}
if command -v "$resolvconf" >/dev/null 2>&1; then
	have_resolvconf=true
else
	have_resolvconf=false
fi

build_resolv_conf()
{
	cf="$state_dir/resolv.conf.$ifname"

	# Build a list of interfaces
	interfaces=$(list_interfaces "$resolv_conf_dir")

	# Build the resolv.conf
	header=
	if [ -n "$interfaces" ]; then
		# Build the header
		for x in ${interfaces}; do
			header="$header${header:+, }$x"
		done

		# Build the search list
		domain=$(cd "$resolv_conf_dir"; \
			key_get_value "domain " ${interfaces})
		search=$(cd "$resolv_conf_dir"; \
			key_get_value "search " ${interfaces})
		set -- ${domain}
		domain="$1"
		[ -n "$2" ] && search="$search $*"
		[ -n "$search" ] && search="$(uniqify $search)"
		[ "$domain" = "$search" ] && search=
		[ -n "$domain" ] && domain="domain $domain$NL"
		[ -n "$search" ] && search="search $search$NL"

		# Build the nameserver list
		srvs=$(cd "$resolv_conf_dir"; \
			key_get_value "nameserver " ${interfaces})
		for x in $(uniqify $srvs); do
			servers="${servers}nameserver $x$NL"
		done
	fi
	header="$signature_base${header:+ $from }$header"

	# Assemble resolv.conf using our head and tail files
	[ -f "$cf" ] && rm -f "$cf"
	[ -d "$resolv_conf_dir" ] || mkdir -p "$resolv_conf_dir"
	echo "$header" > "$cf"
	if [ -f /etc/resolv.conf.head ]; then
		cat /etc/resolv.conf.head >> "$cf"
	else
		echo "# /etc/resolv.conf.head can replace this line" >> "$cf"
	fi
	printf %s "$domain$search$servers" >> "$cf"
	if [ -f /etc/resolv.conf.tail ]; then
		cat /etc/resolv.conf.tail >> "$cf"
	else
		echo "# /etc/resolv.conf.tail can replace this line" >> "$cf"
	fi
	if change_file /etc/resolv.conf "$cf"; then
		chmod 644 /etc/resolv.conf
	fi
	rm -f "$cf"
}

# Extract any ND DNS options from the RA
# Obey the lifetimes
eval_nd_dns()
{

	eval rdnsstime=\$nd${i}_rdnss${j}_lifetime
	if [ -n "$rdnsstime" ]; then
		ltime=$(($rdnsstime - $offset))
		if [ "$ltime" -gt 0 ]; then
			eval rdnss=\$nd${i}_rdnss${j}_servers
			if [ -n "$rdnss" ]; then
				new_rdnss="$new_rdnss${new_rdnss:+ }$rdnss"
			fi
		fi
	fi

	eval dnssltime=\$nd${i}_dnssl${j}_lifetime
	if [ -n "$dnssltime" ]; then
		ltime=$(($dnssltime - $offset))
		if [ "$ltime" -gt 0 ]; then
			eval dnssl=\$nd${i}_dnssl${j}_search
			if [ -n "$dnssl" ]; then
				new_dnssl="$new_dnssl${new_dnssl:+ }$dnssl"
			fi
		fi
	fi

	# Break when we don't have either
	[ -z "$rdnsstime" ] && [ -z "$dnssltime" ] && return 1

	j=$(($j + 1))
	return 0
}

add_resolv_conf()
{
	conf="$signature$NL"
	warn=true

	# Loop to extract the ND DNS options using our indexed shell values
	i=1
	j=1
	while true; do
		eval acquired=\$nd${i}_acquired
		[ -z "$acquired" ] && break
		eval now=\$nd${i}_now
		[ -z "$now" ] && break
		offset=$(($now - $acquired))
		while true; do
			eval_nd_dns || break
		done
		i=$(($i + 1))
		j=1
	done
	[ -n "$new_rdnss" ] && \
	    new_domain_name_servers="$new_domain_name_servers${new_domain_name_servers:+ }$new_rdnss"
	[ -n "$new_dnssl" ] && \
	    new_domain_search="$new_domain_search${new_domain_search:+ }$new_dnssl"

	# Derive a new domain from our various hostname options
	if [ -z "$new_domain_name" ]; then
		if [ "$new_dhcp6_fqdn" != "${new_dhcp6_fqdn#*.}" ]; then
			new_domain_name="${new_dhcp6_fqdn#*.}"
		elif [ "$new_fqdn" != "${new_fqdn#*.}" ]; then
			new_domain_name="${new_fqdn#*.}"
		elif [ "$new_host_name" != "${new_host_name#*.}" ]; then
			new_domain_name="${new_host_name#*.}"
		fi
	fi

	# If we don't have any configuration, remove it
	if [ -z "$new_domain_name_servers" ] &&
	   [ -z "$new_domain_name" ] &&
	   [ -z "$new_domain_search" ]; then
		remove_resolv_conf
		return $?
	fi

	if [ -n "$new_domain_name" ]; then
		set -- $new_domain_name
		if valid_domainname "$1"; then
			conf="${conf}domain $1$NL"
		else
			syslog err "Invalid domain name: $1"
		fi
		# If there is no search this, make this one
		if [ -z "$new_domain_search" ]; then
			new_domain_search="$new_domain_name"
			[ "$new_domain_name" = "$1" ] && warn=true
		fi
	fi
	if [ -n "$new_domain_search" ]; then
		new_domain_search=$(uniqify $new_domain_search)
		if valid_domainname_list $new_domain_search; then
			conf="${conf}search $new_domain_search$NL"
		elif ! $warn; then
			syslog err "Invalid domain name in list:" \
			    "$new_domain_search"
		fi
	fi
	new_domain_name_servers=$(uniqify $new_domain_name_servers)
	for x in ${new_domain_name_servers}; do
		conf="${conf}nameserver $x$NL"
	done
	if $have_resolvconf; then
		[ -n "$ifmetric" ] && export IF_METRIC="$ifmetric"
		printf %s "$conf" | "$resolvconf" -a "$ifname"
		return $?
	fi

	if [ -e "$resolv_conf_dir/$ifname" ]; then
		rm -f "$resolv_conf_dir/$ifname"
	fi
	[ -d "$resolv_conf_dir" ] || mkdir -p "$resolv_conf_dir"
	printf %s "$conf" > "$resolv_conf_dir/$ifname"
	build_resolv_conf
}

remove_resolv_conf()
{
	if $have_resolvconf; then
		"$resolvconf" -d "$ifname" -f
	else
		if [ -e "$resolv_conf_dir/$ifname" ]; then
			rm -f "$resolv_conf_dir/$ifname"
		fi
		build_resolv_conf
	fi
}

# For ease of use, map DHCP6 names onto our DHCP4 names
case "$reason" in
BOUND6|RENEW6|REBIND6|REBOOT6|INFORM6)
	new_domain_name_servers="$new_dhcp6_name_servers"
	new_domain_search="$new_dhcp6_domain_search"
	;;
esac

if $if_configured; then
	if $have_resolvconf && [ "$reason" = NOCARRIER_ROAMING ]; then
		# avoid calling resolvconf -c on CARRIER unless we roam
		mkdir -p "$nocarrier_roaming_dir"
		echo " " >"$nocarrier_roaming_dir/$interface"
		"$resolvconf" -C "$interface.*"
	elif $have_resolvconf && [ "$reason" = CARRIER ]; then
		# Not all resolvconf implementations support -c
		if [ -e "$nocarrier_roaming_dir/$interface" ]; then
			rm -f "$nocarrier_roaming_dir/$interface"
			"$resolvconf" -c "$interface.*"
		fi
	elif $if_up || [ "$reason" = ROUTERADVERT ]; then
		add_resolv_conf
	elif $if_down; then
		remove_resolv_conf
	fi
fi
@


1.7
log
@Merge changes
@
text
@d84 8
a91 5
	[ -z "$rdnsstime" ] && return 1
	ltime=$(($rdnsstime - $offset))
	if [ "$ltime" -gt 0 ]; then
		eval rdnss=\$nd${i}_rdnss${j}_servers
		[ -n "$rdnss" ] && new_rdnss="$new_rdnss${new_rdnss:+ }$rdnss"
d95 8
a102 5
	[ -z "$dnssltime" ] && return 1
	ltime=$(($dnssltime - $offset))
	if [ "$ltime" -gt 0 ]; then
		eval dnssl=\$nd${i}_dnssl${j}_search
		[ -n "$dnssl" ] && new_dnssl="$new_dnssl${new_dnssl:+ }$dnssl"
d105 3
@


1.7.2.1
log
@Sync with HEAD
@
text
@d84 5
a88 8
	if [ -n "$rdnsstime" ]; then
		ltime=$(($rdnsstime - $offset))
		if [ "$ltime" -gt 0 ]; then
			eval rdnss=\$nd${i}_rdnss${j}_servers
			if [ -n "$rdnss" ]; then
				new_rdnss="$new_rdnss${new_rdnss:+ }$rdnss"
			fi
		fi
d92 5
a96 8
	if [ -n "$dnssltime" ]; then
		ltime=$(($dnssltime - $offset))
		if [ "$ltime" -gt 0 ]; then
			eval dnssl=\$nd${i}_dnssl${j}_search
			if [ -n "$dnssl" ]; then
				new_dnssl="$new_dnssl${new_dnssl:+ }$dnssl"
			fi
		fi
a98 3
	# Break when we don't have either
	[ -z "$rdnsstime" ] && [ -z "$dnssltime" ] && return 1

@


1.6
log
@Sync with dhcpcd-9.4.0
@
text
@d14 1
a14 1
if type "$resolvconf" >/dev/null 2>&1; then
@


1.5
log
@Sync with dhcpcd-9.3.3
@
text
@d10 1
d14 5
d173 1
a173 1
	if type "$resolvconf" >/dev/null 2>&1; then
d189 1
a189 1
	if type "$resolvconf" >/dev/null 2>&1; then
d208 12
a219 1
	if $if_up || [ "$reason" = ROUTERADVERT ]; then
@


1.4
log
@Sync
@
text
@d201 6
a206 4
if $if_up || [ "$reason" = ROUTERADVERT ]; then
	add_resolv_conf
elif $if_down; then
	remove_resolv_conf
@


1.3
log
@Sync
@
text
@d45 1
a45 1
		for x in $(uniqify ${srvs}); do
d155 1
d163 1
@


1.2
log
@
PR install/53622  (probably)

When used as part of a network based install kernel, the SMALL "test" (aka [)
does not support -a or -o, so rewrite these scripts to avoid using that.
@
text
@d22 1
d73 1
a73 5
# For now, we ignore the lifetime of the DNS options unless they
# are absent or zero.
# In this case they are removed from consideration.
# See draft-gont-6man-slaac-dns-config-issues-01 for issues
# regarding DNS option lifetime in ND messages.
d76 5
a80 4
	eval ltime=\$nd${i}_rdnss${j}_lifetime
	if [ -z "$ltime" ] || [ "$ltime" = 0 ]; then
		rdnss=
	else
d82 1
d84 5
a88 4
	eval ltime=\$nd${i}_dnssl${j}_lifetime
	if [ -z "$ltime" ] || [ "$ltime" = 0 ]; then
		dnssl=
	else
d90 1
a92 4
	[ -z "${rdnss}${dnssl}" ] && return 1

	[ -n "$rdnss" ] && new_rdnss="$new_rdnss${new_rdnss:+ }$rdnss"
	[ -n "$dnssl" ] && new_dnssl="$new_dnssl${new_dnssl:+ }$dnssl"
d106 5
a115 1
		eval_nd_dns || break
@


1.1
log
@Initial revision
@
text
@d16 1
a16 2
	local cf="$state_dir/resolv.conf.$ifname"
	local interfaces= header= search= srvs= servers= x=
a78 1

d80 1
a80 1
	if [ -z "$ltime" -o "$ltime" = 0 ]; then
d86 1
a86 1
	if [ -z "$ltime" -o "$ltime" = 0 ]; then
d92 1
a92 1
	[ -z "$rdnss" -a -z "$dnssl" ] && return 1
d102 2
a103 2
	local x= conf="$signature$NL" warn=true
	local i j ltime rdnss dnssl new_rdnss new_dnssl
d133 3
a135 3
	if [ -z "$new_domain_name_servers" -a \
		-z "$new_domain_name" -a \
		-z "$new_domain_search" ]; then
@


1.1.1.1
log
@Import dhcpcd-7.0.0-beta. Changes from prior version include:

  *  source file locations reworked:
       dhcpcd source is in src
       dhcpcd hooks are in hooks
       compat is in compat
  *  README split into README.md and BUILDING.md
  *  internal routing is now protocol agnostic
  *  avoid using __packed and use compile time asserts instead
  *  addresses some alignment issues
  *  disable some ARP code on kernels which support RFC5227
  *  BSD IPv6 kernel settings are now updated to reflect dhcpcd config
  *  custom logger has been removed, syslog handles everything
     as such, the --logfile option has been removed as well.
     If you need better/earlier logging, get a better syslogger!
  *  distinfo and signed distinfo files are now available alongside
     release taraballs from this point onwards
  *  default DBDIR has changed from /var/db to /var/db/dhcpcd
  *  /etc/dhcpcd.duid moves to DBDIR/duid
  *  /etc/dhcpcd.secret moves to DBDIR/secret
  *  lease file names have dhcpcd removed from them as they are now
     inside a directory of the same name
  *  fixed issues with reject routes not working on some platforms
  *  improved nl80211 support on Linux for working out the SSID
  *  no longer request NTP by default in dhcpcd.conf
  *  BPF filtering vastly improved so dhcpcd only wake up on
     ARP or DHCP packets destined for it
  *  support for MUD URL (draft-ietf-opsawg-mud-05)
  *  if the kernel isn't doing DAD, don't insist on waiting for it
     to actually do it
  *  fix a potential crash where the DHCP or ARP states could be
     freed before the packet processing loop naturally breaks
  *  removed gateway and nogateway options
     (these can be controlled by the nooption directive which
     works for more than just gateways)
  *  removed ipv6ra_own and ipv6ra_own_default options
     (these can be controled by the ipv6rs/noipv6rs directive)
  *  fix a crash receiving SIGUSR1
@
text
@@


1.1.1.1.8.1
log
@Catch up to current in external/bsd/dhcpcd/, requested by roy in ticket #707:

external/bsd/dhcpcd/dist/configure              up to 1.1.1.7
external/bsd/dhcpcd/dist/hooks/10-wpa_supplicant up to 1.1.1.2
external/bsd/dhcpcd/dist/hooks/15-timezone      up to 1.1.1.2
external/bsd/dhcpcd/dist/hooks/20-resolv.conf   up to 1.1.1.2
external/bsd/dhcpcd/dist/hooks/29-lookup-hostname up to 1.1.1.2
external/bsd/dhcpcd/dist/hooks/30-hostname      up to 1.1.1.2
external/bsd/dhcpcd/dist/hooks/50-ntp.conf      up to 1.1.1.2
external/bsd/dhcpcd/dist/hooks/50-yp.conf       up to 1.1.1.2
external/bsd/dhcpcd/dist/hooks/50-ypbind.in     up to 1.1.1.2
external/bsd/dhcpcd/dist/hooks/dhcpcd-run-hooks.8.in up to 1.1.1.4
external/bsd/dhcpcd/dist/hooks/dhcpcd-run-hooks.in up to 1.1.1.4
external/bsd/dhcpcd/dist/src/arp.c              up to 1.1.1.6
external/bsd/dhcpcd/dist/src/common.h           up to 1.1.1.4
external/bsd/dhcpcd/dist/src/defs.h             up to 1.1.1.11
external/bsd/dhcpcd/dist/src/dhcp.c             up to 1.9
external/bsd/dhcpcd/dist/src/dhcp.h             up to 1.1.1.5
external/bsd/dhcpcd/dist/src/dhcp6.c            up to 1.1.1.10
external/bsd/dhcpcd/dist/src/dhcp6.h            up to 1.1.1.4
external/bsd/dhcpcd/dist/src/dhcpcd.8.in        up to 1.1.1.8
external/bsd/dhcpcd/dist/src/dhcpcd.c           up to 1.10
external/bsd/dhcpcd/dist/src/dhcpcd.conf.5.in   up to 1.1.1.7
external/bsd/dhcpcd/dist/src/dhcpcd.h           up to 1.1.1.5
external/bsd/dhcpcd/dist/src/if-bsd.c           up to 1.1.1.7
external/bsd/dhcpcd/dist/src/if-linux.c         up to 1.1.1.8
external/bsd/dhcpcd/dist/src/if-options.c       up to 1.8
external/bsd/dhcpcd/dist/src/if-options.h       up to 1.1.1.7
external/bsd/dhcpcd/dist/src/if-sun.c           up to 1.1.1.4
external/bsd/dhcpcd/dist/src/if.c               up to 1.1.1.8
external/bsd/dhcpcd/dist/src/if.h               up to 1.1.1.5
external/bsd/dhcpcd/dist/src/ipv4.c             up to 1.1.1.9
external/bsd/dhcpcd/dist/src/ipv4.h             up to 1.1.1.4
external/bsd/dhcpcd/dist/src/ipv6.c             up to 1.1.1.8
external/bsd/dhcpcd/dist/src/ipv6.h             up to 1.1.1.6
external/bsd/dhcpcd/dist/src/ipv6nd.c           up to 1.1.1.7
external/bsd/dhcpcd/dist/src/ipv6nd.h           up to 1.1.1.5
external/bsd/dhcpcd/dist/src/logerr.h           up to 1.1.1.3
external/bsd/dhcpcd/dist/src/route.c            up to 1.1.1.6
external/bsd/dhcpcd/dist/src/route.h            up to 1.1.1.4
external/bsd/dhcpcd/dist/src/dev/udev.c         up to 1.1.1.2
external/bsd/dhcpcd/dist/tests/eloop-bench/eloop-bench.c up to 1.1.1.3
external/bsd/dhcpcd/include/config.h            up to 1.3
external/bsd/dhcpcd/sbin/dhcpcd/Makefile        up to 1.43

Import dhcpcd-7.0.1 with the following changes:

  *  hooks: remove use of local builtin for better portability
  *  dhcpcd: don't log errors working out carrier for departed interfaces
  *  ipv4: allow configuration of static broadcast address
  *  if: don't set MTU during interface discovery
  *  if: don't activate non matching interfaces to commandline ones
  *  eloop-bench: fix hangs when using a large number of cycles
  *  dhcp: don't bind when we've just probed an address to inform

Import dhcpcd-7.0.2 with the following changes:

  *  Added support for setproctitle(3)
  *  Kernel RA is no longer disabled when IPv6 is disabled in dhcpcd
  *  DHCPv6 PD is no longer stopped if no Routers are found
  *  If the DHCP leased address is deleted, enter the reboot state
  *  DHCPv6 unicast is no longer performed when not in master mode
  *  dhcpcd will now detect netlink/route socket overflows ad re-sync

Import dhcpcd-7.0.3 with the following changes:

  *  dhcp6: fix a null termination overflow on status messages
  *  options: static routes can be setup in global context again
  *  routes: dhcpcd added host routes are now reported correctly
@
text
@d16 2
a17 1
	cf="$state_dir/resolv.conf.$ifname"
d80 1
d104 2
a105 2
	conf="$signature$NL"
	warn=true
@


1.1.1.1.8.2
log
@Sync to head, requested by roy in ticket #1250:

	external/bsd/dhcpcd/dist/compat/consttime_memequal.h up to 1.1.1.1
	external/bsd/dhcpcd/dist/.arcconfig             delete
	external/bsd/dhcpcd/dist/BUILDING.md            up to 1.1.1.3
	external/bsd/dhcpcd/dist/LICENSE                up to 1.1.1.3
	external/bsd/dhcpcd/dist/Makefile               up to 1.1.1.6
	external/bsd/dhcpcd/dist/configure              up to 1.1.1.11
	external/bsd/dhcpcd/dist/iconfig.mk             up to 1.1.1.2
	external/bsd/dhcpcd/dist/hooks/20-resolv.conf   up to 1.2
	external/bsd/dhcpcd/dist/hooks/29-lookup-hostname up to 1.2
	external/bsd/dhcpcd/dist/hooks/30-hostname      up to 1.2
	external/bsd/dhcpcd/dist/hooks/50-ntp.conf      up to 1.2
	external/bsd/dhcpcd/dist/hooks/50-yp.conf       up to 1.2
	external/bsd/dhcpcd/dist/hooks/50-ypbind.in     up to 1.2
	external/bsd/dhcpcd/dist/hooks/dhcpcd-run-hooks.in up to 1.3
	external/bsd/dhcpcd/dist/src/Makefile           up to 1.1.1.5
	external/bsd/dhcpcd/dist/src/arp.c              up to 1.1.1.10
	external/bsd/dhcpcd/dist/src/arp.h              up to 1.1.1.7
	external/bsd/dhcpcd/dist/src/auth.c             up to 1.1.1.7
	external/bsd/dhcpcd/dist/src/auth.h             up to 1.1.1.4
	external/bsd/dhcpcd/dist/src/bpf.c              up to 1.8
	external/bsd/dhcpcd/dist/src/bpf.h              up to 1.1.1.5
	external/bsd/dhcpcd/dist/src/common.c           up to 1.1.1.7
	external/bsd/dhcpcd/dist/src/common.h           up to 1.1.1.7
	external/bsd/dhcpcd/dist/src/control.c          up to 1.1.1.5
	external/bsd/dhcpcd/dist/src/control.h          up to 1.1.1.3
	external/bsd/dhcpcd/dist/src/defs.h             up to 1.1.1.20
	external/bsd/dhcpcd/dist/src/dev.c              up to 1.1.1.4
	external/bsd/dhcpcd/dist/src/dev.h              up to 1.1.1.3
	external/bsd/dhcpcd/dist/src/dhcp-common.c      up to 1.1.1.5
	external/bsd/dhcpcd/dist/src/dhcp-common.h      up to 1.1.1.3
	external/bsd/dhcpcd/dist/src/dhcp.c             up to 1.18
	external/bsd/dhcpcd/dist/src/dhcp.h             up to 1.1.1.9
	external/bsd/dhcpcd/dist/src/dhcp6.c            up to 1.6
	external/bsd/dhcpcd/dist/src/dhcp6.h            up to 1.1.1.9
	external/bsd/dhcpcd/dist/src/dhcpcd-embedded.c.in up to 1.1.1.3
	external/bsd/dhcpcd/dist/src/dhcpcd-embedded.h.in up to 1.1.1.3
	external/bsd/dhcpcd/dist/src/dhcpcd.8.in        up to 1.1.1.12
	external/bsd/dhcpcd/dist/src/dhcpcd.c           up to 1.18
	external/bsd/dhcpcd/dist/src/dhcpcd.conf.5.in   up to 1.1.1.12
	external/bsd/dhcpcd/dist/src/dhcpcd.h           up to 1.1.1.9
	external/bsd/dhcpcd/dist/src/duid.c             up to 1.1.1.5
	external/bsd/dhcpcd/dist/src/eloop.c            up to 1.1.1.6
	external/bsd/dhcpcd/dist/src/eloop.h            up to 1.1.1.4
	external/bsd/dhcpcd/dist/src/if-bsd.c           up to 1.6
	external/bsd/dhcpcd/dist/src/if-linux-wext.c    up to 1.1.1.3
	external/bsd/dhcpcd/dist/src/if-linux.c         up to 1.1.1.12
	external/bsd/dhcpcd/dist/src/if-options.c       up to 1.13
	external/bsd/dhcpcd/dist/src/if-options.h       up to 1.1.1.8
	external/bsd/dhcpcd/dist/src/if-sun.c           up to 1.1.1.7
	external/bsd/dhcpcd/dist/src/if.c               up to 1.1.1.12
	external/bsd/dhcpcd/dist/src/if.h               up to 1.1.1.7
	external/bsd/dhcpcd/dist/src/ipv4.c             up to 1.1.1.13
	external/bsd/dhcpcd/dist/src/ipv4.h             up to 1.1.1.7
	external/bsd/dhcpcd/dist/src/ipv4ll.c           up to 1.1.1.7
	external/bsd/dhcpcd/dist/src/ipv4ll.h           up to 1.1.1.6
	external/bsd/dhcpcd/dist/src/ipv6.c             up to 1.1.1.16
	external/bsd/dhcpcd/dist/src/ipv6.h             up to 1.1.1.10
	external/bsd/dhcpcd/dist/src/ipv6nd.c           up to 1.6
	external/bsd/dhcpcd/dist/src/ipv6nd.h           up to 1.1.1.9
	external/bsd/dhcpcd/dist/src/logerr.c           up to 1.1.1.3
	external/bsd/dhcpcd/dist/src/logerr.h           up to 1.1.1.4
	external/bsd/dhcpcd/dist/src/route.c            up to 1.1.1.10
	external/bsd/dhcpcd/dist/src/route.h            up to 1.1.1.6
	external/bsd/dhcpcd/dist/src/sa.c               up to 1.1.1.4
	external/bsd/dhcpcd/dist/src/sa.h               up to 1.1.1.3
	external/bsd/dhcpcd/dist/src/script.c           up to 1.1.1.7
	external/bsd/dhcpcd/dist/src/script.h           up to 1.1.1.3
	external/bsd/dhcpcd/dist/src/dev/udev.c         up to 1.1.1.3
	external/bsd/dhcpcd/dist/tests/Makefile         up to 1.1.1.2
	external/bsd/dhcpcd/sbin/dhcpcd/Makefile        up to 1.45

Import dhcpcd-7.2.1 with the following changes:
*  auth: Use consttime_memequal to avoid latency attack
*  DHCP: Fix a potential 1 byte read overflow with DHO_OPTSOVERLOADED
*  DHCPv6: Fix a potential buffer overflow reading NA/TA addresses
@
text
@d80 1
a80 1
	if [ -z "$ltime" ] || [ "$ltime" = 0 ]; then
d86 1
a86 1
	if [ -z "$ltime" ] || [ "$ltime" = 0 ]; then
d92 1
a92 1
	[ -z "${rdnss}${dnssl}" ] && return 1
d133 3
a135 3
	if [ -z "$new_domain_name_servers" ] &&
	   [ -z "$new_domain_name" ] &&
	   [ -z "$new_domain_search" ]; then
@


1.1.1.2
log
@Import dhcpcd-7.0.1 with the following changes:
*  hooks: remove use of local builtin for better portability
*  dhcpcd: don't log errors working out carrier for departed interfaces
*  ipv4: allow configuration of static broadcast address
*  if: don't set MTU during interface discovery
*  if: don't activate non matching interfaces to commandline ones
*  eloop-bench: fix hangs when using a large number of cycles
*  dhcp: don't bind when we've just probed an address to inform
@
text
@d16 2
a17 1
	cf="$state_dir/resolv.conf.$ifname"
d80 1
d104 2
a105 2
	conf="$signature$NL"
	warn=true
@


1.1.1.2.4.1
log
@Sync with HEAD
@
text
@d80 1
a80 1
	if [ -z "$ltime" ] || [ "$ltime" = 0 ]; then
d86 1
a86 1
	if [ -z "$ltime" ] || [ "$ltime" = 0 ]; then
d92 1
a92 1
	[ -z "${rdnss}${dnssl}" ] && return 1
d133 3
a135 3
	if [ -z "$new_domain_name_servers" ] &&
	   [ -z "$new_domain_name" ] &&
	   [ -z "$new_domain_search" ]; then
@


1.1.1.2.4.2
log
@Merge changes from current as of 20200406
@
text
@d44 1
a44 1
		for x in $(uniqify $srvs); do
a153 1
		new_domain_search=$(uniqify $new_domain_search)
a160 1
	new_domain_name_servers=$(uniqify $new_domain_name_servers)
@


1.1.1.2.4.3
log
@Mostly merge changes from HEAD upto 20200411
@
text
@a21 1
	header=
d72 5
a76 1
# Obey the lifetimes
d79 4
a82 5

	eval rdnsstime=\$nd${i}_rdnss${j}_lifetime
	[ -z "$rdnsstime" ] && return 1
	ltime=$(($rdnsstime - $offset))
	if [ "$ltime" -gt 0 ]; then
a83 1
		[ -n "$rdnss" ] && new_rdnss="$new_rdnss${new_rdnss:+ }$rdnss"
d85 4
a88 5

	eval dnssltime=\$nd${i}_dnssl${j}_lifetime
	[ -z "$dnssltime" ] && return 1
	ltime=$(($dnssltime - $offset))
	if [ "$ltime" -gt 0 ]; then
a89 1
		[ -n "$dnssl" ] && new_dnssl="$new_dnssl${new_dnssl:+ }$dnssl"
d92 4
a108 5
		eval acquired=\$nd${i}_acquired
		[ -z "$acquired" ] && break
		eval now=\$nd${i}_now
		[ -z "$now" ] && break
		offset=$(($now - $acquired))
d114 1
@


1.1.1.3
log
@Import dhcpcd-7.1.0 with the following changes:

* NetBSD: sets SO_RERROR on to detect receive socket overflow
* BSD: route improvements to avoid listening for own changes
* IP6: implement IP6 address sharing
* BSD: catch UP/DOWN events when interfaces does support media changes
* IPv4LL: remember old address when carrier is lost
@
text
@d80 1
a80 1
	if [ -z "$ltime" ] || [ "$ltime" = 0 ]; then
d86 1
a86 1
	if [ -z "$ltime" ] || [ "$ltime" = 0 ]; then
d92 1
a92 1
	[ -z "${rdnss}${dnssl}" ] && return 1
d133 3
a135 3
	if [ -z "$new_domain_name_servers" ] &&
	   [ -z "$new_domain_name" ] &&
	   [ -z "$new_domain_search" ]; then
@


1.1.1.4
log
@Import dhcpcd-8.0.0 with the following changes:

  *  ARP now supports many requests
  *  Routing tables now use Red-Black Trees
  *  Script variables are no longer allocated manually
@
text
@a21 1
	header=
d72 5
a76 1
# Obey the lifetimes
d79 4
a82 5

	eval rdnsstime=\$nd${i}_rdnss${j}_lifetime
	[ -z "$rdnsstime" ] && return 1
	ltime=$(($rdnsstime - $offset))
	if [ "$ltime" -gt 0 ]; then
a83 1
		[ -n "$rdnss" ] && new_rdnss="$new_rdnss${new_rdnss:+ }$rdnss"
d85 4
a88 5

	eval dnssltime=\$nd${i}_dnssl${j}_lifetime
	[ -z "$dnssltime" ] && return 1
	ltime=$(($dnssltime - $offset))
	if [ "$ltime" -gt 0 ]; then
a89 1
		[ -n "$dnssl" ] && new_dnssl="$new_dnssl${new_dnssl:+ }$dnssl"
d92 4
a108 5
		eval acquired=\$nd${i}_acquired
		[ -z "$acquired" ] && break
		eval now=\$nd${i}_now
		[ -z "$now" ] && break
		offset=$(($now - $acquired))
d114 1
@


1.1.1.5
log
@Update to dhcpcd-9.0.0 with the following changes:

 * Decode interface complex interface names eth0.100:2 eth0i100:2.
   This allows us to ignore some virtual interfaces by default
 * ARP: Report L2 header address on conflict for more clarity
 * DHCP: Support jumbo frames (untested)
 * DHCP6: Clean up old lease on failure to confirm/rebind, etc
 * RA: Prefer older routers
 * INET6: Obscure prefixes are now calculated correctly

 * Privilege Separation
 * default hostname is now a blank string rather than localhost
 * Leases are now dumped over the control socket - you get RA's now as well.
 * Better support for many IPv6 routers
 * RTM_MISS filtering
 * RA: Deprecate stale addresses by setting pltime 0
 * DHCP6: Deprecate stale addresses by setting pltime 0
@
text
@d45 1
a45 1
		for x in $(uniqify $srvs); do
a154 1
		new_domain_search=$(uniqify $new_domain_search)
a161 1
	new_domain_name_servers=$(uniqify $new_domain_name_servers)
@


1.1.1.6
log
@Update to dhcpcd-9.3.3 with the following changes:

 * dhcpcd: Don't create a launcher process if keeping in foreground
 * dhcpcd: Add --noconfigure option
 * control: Create an unpriv socket for non master mode
 * options: Don't log unknown ones when printing pidfile location
@
text
@d201 4
a204 6
if $if_configured; then
	if $if_up || [ "$reason" = ROUTERADVERT ]; then
		add_resolv_conf
	elif $if_down; then
		remove_resolv_conf
	fi
@


1.1.1.7
log
@Update to dhcpcd-9.4.0 with the following changes:

 * DHCP: For anonymous, just use a generic ClientID
 * link: Split hardware address randomisation out of anonymous option
 * link: Only report hardware changes for active interfaces
 * link: Report errors obtaining recv buffer size on overflow
 * hooks: Add NOCARRIER_ROAMING reason
 * hooks: interface_order now reflects priorities again
@
text
@a9 1
nocarrier_roaming_dir="$state_dir/roaming"
a12 5
if type "$resolvconf" >/dev/null 2>&1; then
	have_resolvconf=true
else
	have_resolvconf=false
fi
d167 1
a167 1
	if $have_resolvconf; then
d183 1
a183 1
	if $have_resolvconf; then
d202 1
a202 12
	if $have_resolvconf && [ "$reason" = NOCARRIER_ROAMING ]; then
		# avoid calling resolvconf -c on CARRIER unless we roam
		mkdir -p "$nocarrier_roaming_dir"
		echo " " >"$nocarrier_roaming_dir/$interface"
		"$resolvconf" -C "$interface.*"
	elif $have_resolvconf && [ "$reason" = CARRIER ]; then
		# Not all resolvconf implementations support -c
		if [ -e "$nocarrier_roaming_dir/$interface" ]; then
			rm -f "$nocarrier_roaming_dir/$interface"
			"$resolvconf" -c "$interface.*"
		fi
	elif $if_up || [ "$reason" = ROUTERADVERT ]; then
@


1.1.1.8
log
@Update to dhcpcd-10.0.1 with the following changes:

 * privsep: keep resources open rather than open/close
 * dhcp6: OPTION_NTP_SERVER is now preferred over OPTION_SNTP_SERVER
 * Misc bug fixes mainly around privsep for many platforms.
 * Fix for reading the some BSD routing table entries.
 * Fix reading authtokens from config.

Big new release, mainly around better privsep process management
which allows us to detect when they exit unexpectedly.
@
text
@d14 1
a14 1
if command -v "$resolvconf" >/dev/null 2>&1; then
@


1.1.1.9
log
@Import dhcpcd-10.2.3 with the following changes:

* DHCP: Restore logic on when to open an address specific socket
* BSD: routes via P2P interfaces now find their out-going interface
* dhcpcd: -b --background fixed
* resolv: Fix processing more DNSSL options than RDNSS]
* dhcpcd: Remove option rapid_commit from dhcpcd.conf
@
text
@d84 5
a88 8
	if [ -n "$rdnsstime" ]; then
		ltime=$(($rdnsstime - $offset))
		if [ "$ltime" -gt 0 ]; then
			eval rdnss=\$nd${i}_rdnss${j}_servers
			if [ -n "$rdnss" ]; then
				new_rdnss="$new_rdnss${new_rdnss:+ }$rdnss"
			fi
		fi
d92 5
a96 8
	if [ -n "$dnssltime" ]; then
		ltime=$(($dnssltime - $offset))
		if [ "$ltime" -gt 0 ]; then
			eval dnssl=\$nd${i}_dnssl${j}_search
			if [ -n "$dnssl" ]; then
				new_dnssl="$new_dnssl${new_dnssl:+ }$dnssl"
			fi
		fi
a98 3
	# Break when we don't have either
	[ -z "$rdnsstime" ] && [ -z "$dnssltime" ] && return 1

@


1.1.1.2.2.1
log
@Ssync with HEAD
@
text
@d80 1
a80 1
	if [ -z "$ltime" ] || [ "$ltime" = 0 ]; then
d86 1
a86 1
	if [ -z "$ltime" ] || [ "$ltime" = 0 ]; then
d92 1
a92 1
	[ -z "${rdnss}${dnssl}" ] && return 1
d133 3
a135 3
	if [ -z "$new_domain_name_servers" ] &&
	   [ -z "$new_domain_name" ] &&
	   [ -z "$new_domain_search" ]; then
@


1.1.1.2.6.1
log
@file 20-resolv.conf was added on branch netbsd-7 on 2018-07-27 10:43:20 +0000
@
text
@d1 202
@


1.1.1.2.6.2
log
@Pull up following revision(s) (requested by roy in ticket #1621):

	external/bsd/dhcpcd/dist/compat/crypt/sha256.c  up to 1.1.1.1
	external/bsd/dhcpcd/dist/compat/crypt/md5.c     up to 1.1.1.1
	external/bsd/dhcpcd/dist/compat/crypt/md5.h     up to 1.1.1.2
	external/bsd/dhcpcd/dist/compat/crypt/sha256.h  up to 1.1.1.1
	external/bsd/dhcpcd/dist/compat/crypt/hmac.c    up to 1.1.1.1
	external/bsd/dhcpcd/dist/compat/crypt/hmac.h    up to 1.1.1.1
	external/bsd/dhcpcd/dist/compat/_strtoi.h       up to 1.1.1.1
	external/bsd/dhcpcd/dist/compat/arc4random.c    up to 1.1.1.1
	external/bsd/dhcpcd/dist/compat/arc4random.h    up to 1.1.1.1
	external/bsd/dhcpcd/dist/compat/arc4random_uniform.c up to 1.1.1.1
	external/bsd/dhcpcd/dist/compat/arc4random_uniform.h up to 1.1.1.1
	external/bsd/dhcpcd/dist/compat/bitops.h        up to 1.1.1.1
	external/bsd/dhcpcd/dist/compat/dprintf.c       up to 1.1.1.2
	external/bsd/dhcpcd/dist/compat/dprintf.h       up to 1.1.1.2
	external/bsd/dhcpcd/dist/compat/endian.h        up to 1.1.1.1
	external/bsd/dhcpcd/dist/compat/pidfile.c       up to 1.1.1.1
	external/bsd/dhcpcd/dist/compat/pidfile.h       up to 1.1.1.1
	external/bsd/dhcpcd/dist/compat/queue.h         up to 1.1.1.1
	external/bsd/dhcpcd/dist/compat/reallocarray.c  up to 1.1.1.1
	external/bsd/dhcpcd/dist/compat/reallocarray.h  up to 1.1.1.1
	external/bsd/dhcpcd/dist/compat/strtoi.c        up to 1.1.1.1
	external/bsd/dhcpcd/dist/compat/strtoi.h        up to 1.1.1.1
	external/bsd/dhcpcd/dist/compat/strtou.c        up to 1.1.1.1
	external/bsd/dhcpcd/dist/compat/strlcpy.c       up to 1.1.1.1
	external/bsd/dhcpcd/dist/compat/strlcpy.h       up to 1.1.1.1
	external/bsd/dhcpcd/dist/config-null.mk         up to 1.1.1.1
	external/bsd/dhcpcd/dist/configure              up to 1.1.1.8
	external/bsd/dhcpcd/dist/iconfig.mk             up to 1.1.1.1
	external/bsd/dhcpcd/dist/hooks/01-test          up to 1.1.1.2
	external/bsd/dhcpcd/dist/hooks/02-dump          up to 1.1.1.1
	external/bsd/dhcpcd/dist/hooks/10-wpa_supplicant up to 1.1.1.2
	external/bsd/dhcpcd/dist/hooks/15-timezone      up to 1.1.1.2
	external/bsd/dhcpcd/dist/hooks/20-resolv.conf   up to 1.1.1.2
	external/bsd/dhcpcd/dist/hooks/29-lookup-hostname up to 1.1.1.2
	external/bsd/dhcpcd/dist/hooks/30-hostname      up to 1.1.1.2
	external/bsd/dhcpcd/dist/hooks/50-dhcpcd-compat up to 1.1.1.1
	external/bsd/dhcpcd/dist/hooks/50-ntp.conf      up to 1.1.1.2
	external/bsd/dhcpcd/dist/hooks/50-yp.conf       up to 1.1.1.2
	external/bsd/dhcpcd/dist/hooks/50-ypbind.in     up to 1.1.1.2
	external/bsd/dhcpcd/dist/hooks/Makefile         up to 1.1.1.1
	external/bsd/dhcpcd/dist/hooks/dhcpcd-run-hooks.8.in up to 1.1.1.4
	external/bsd/dhcpcd/dist/hooks/dhcpcd-run-hooks.in up to 1.1.1.4
	external/bsd/dhcpcd/dist/src/GNUmakefile        up to 1.1.1.1
	external/bsd/dhcpcd/dist/src/Makefile           up to 1.1.1.4
	external/bsd/dhcpcd/dist/src/arp.c              up to 1.1.1.7
	external/bsd/dhcpcd/dist/src/arp.h              up to 1.1.1.4
	external/bsd/dhcpcd/dist/src/auth.c             up to 1.1.1.5
	external/bsd/dhcpcd/dist/src/auth.h             up to 1.1.1.3
	external/bsd/dhcpcd/dist/src/bpf.c              up to 1.7
	external/bsd/dhcpcd/dist/src/bpf.h              up to 1.1.1.4
	external/bsd/dhcpcd/dist/src/common.c           up to 1.1.1.5
	external/bsd/dhcpcd/dist/src/common.h           up to 1.1.1.4
	external/bsd/dhcpcd/dist/src/control.c          up to 1.1.1.3
	external/bsd/dhcpcd/dist/src/control.h          up to 1.1.1.2
	external/bsd/dhcpcd/dist/src/defs.h             up to 1.1.1.15
	external/bsd/dhcpcd/dist/src/dev.c              up to 1.1.1.3
	external/bsd/dhcpcd/dist/src/dev.h              up to 1.1.1.2
	external/bsd/dhcpcd/dist/src/dhcp-common.c      up to 1.1.1.4
	external/bsd/dhcpcd/dist/src/dhcp-common.h      up to 1.1.1.2
	external/bsd/dhcpcd/dist/src/dhcp.c             up to 1.11
	external/bsd/dhcpcd/dist/src/dhcp.h             up to 1.1.1.6
	external/bsd/dhcpcd/dist/src/dhcp6.c            up to 1.1.1.12
	external/bsd/dhcpcd/dist/src/dhcp6.h            up to 1.1.1.6
	external/bsd/dhcpcd/dist/src/dhcpcd-definitions-small.conf up to 1.1.1.2
	external/bsd/dhcpcd/dist/src/dhcpcd-definitions.conf up to 1.1.1.2
	external/bsd/dhcpcd/dist/src/dhcpcd-embedded.c.in up to 1.1.1.2
	external/bsd/dhcpcd/dist/src/dhcpcd-embedded.h.in up to 1.1.1.2
	external/bsd/dhcpcd/dist/src/dhcpcd.8.in        up to 1.1.1.10
	external/bsd/dhcpcd/dist/src/dhcpcd.c           up to 1.13
	external/bsd/dhcpcd/dist/src/dhcpcd.conf        up to 1.1.1.2
	external/bsd/dhcpcd/dist/src/dhcpcd.conf.5.in   up to 1.1.1.10
	external/bsd/dhcpcd/dist/src/dhcpcd.h           up to 1.1.1.5
	external/bsd/dhcpcd/dist/src/duid.c             up to 1.1.1.3
	external/bsd/dhcpcd/dist/src/duid.h             up to 1.1.1.1
	external/bsd/dhcpcd/dist/src/eloop.c            up to 1.1.1.5
	external/bsd/dhcpcd/dist/src/eloop.h            up to 1.1.1.3
	external/bsd/dhcpcd/dist/src/genembedc          up to 1.1.1.1
	external/bsd/dhcpcd/dist/src/genembedh          up to 1.1.1.1
	external/bsd/dhcpcd/dist/src/if-bsd.c           up to 1.1.1.8
	external/bsd/dhcpcd/dist/src/if-linux-wext.c    up to 1.1.1.2
	external/bsd/dhcpcd/dist/src/if-linux.c         up to 1.1.1.10
	external/bsd/dhcpcd/dist/src/if-options.c       up to 1.10
	external/bsd/dhcpcd/dist/src/if-options.h       up to 1.1.1.7
	external/bsd/dhcpcd/dist/src/if-sun.c           up to 1.1.1.4
	external/bsd/dhcpcd/dist/src/if.c               up to 1.1.1.8
	external/bsd/dhcpcd/dist/src/if.h               up to 1.1.1.5
	external/bsd/dhcpcd/dist/src/ipv4.c             up to 1.1.1.9
	external/bsd/dhcpcd/dist/src/ipv4.h             up to 1.1.1.4
	external/bsd/dhcpcd/dist/src/ipv4ll.c           up to 1.1.1.4
	external/bsd/dhcpcd/dist/src/ipv4ll.h           up to 1.1.1.4
	external/bsd/dhcpcd/dist/src/ipv6.c             up to 1.1.1.11
	external/bsd/dhcpcd/dist/src/ipv6.h             up to 1.1.1.7
	external/bsd/dhcpcd/dist/src/ipv6nd.c           up to 1.1.1.8
	external/bsd/dhcpcd/dist/src/ipv6nd.h           up to 1.1.1.6
	external/bsd/dhcpcd/dist/src/logerr.c           up to 1.1.1.2
	external/bsd/dhcpcd/dist/src/logerr.h           up to 1.1.1.3
	external/bsd/dhcpcd/dist/src/route.c            up to 1.1.1.8
	external/bsd/dhcpcd/dist/src/route.h            up to 1.1.1.4
	external/bsd/dhcpcd/dist/src/sa.c               up to 1.1.1.3
	external/bsd/dhcpcd/dist/src/sa.h               up to 1.1.1.2
	external/bsd/dhcpcd/dist/src/script.c           up to 1.1.1.4
	external/bsd/dhcpcd/dist/src/script.h           up to 1.1.1.2
	external/bsd/dhcpcd/dist/src/dev/Makefile       up to 1.1.1.1
	external/bsd/dhcpcd/dist/src/dev/udev.c         up to 1.1.1.2
	external/bsd/dhcpcd/dist/tests/crypt/.gitignore up to 1.1.1.1
	external/bsd/dhcpcd/dist/tests/crypt/GNUmakefile up to 1.1.1.1
	external/bsd/dhcpcd/dist/tests/crypt/Makefile   up to 1.1.1.2
	external/bsd/dhcpcd/dist/tests/crypt/README.md  up to 1.1.1.1
	external/bsd/dhcpcd/dist/tests/crypt/run-test.c up to 1.1.1.2
	external/bsd/dhcpcd/dist/tests/crypt/test.h     up to 1.1.1.2
	external/bsd/dhcpcd/dist/tests/crypt/test_hmac_md5.c up to 1.1.1.3
	external/bsd/dhcpcd/dist/tests/Makefile         up to 1.1.1.1
	external/bsd/dhcpcd/dist/tests/eloop-bench/.gitignore up to 1.1.1.1
	external/bsd/dhcpcd/dist/tests/eloop-bench/Makefile up to 1.1.1.2
	external/bsd/dhcpcd/dist/tests/eloop-bench/README.md up to 1.1.1.1
	external/bsd/dhcpcd/dist/tests/eloop-bench/eloop-bench.c up to 1.1.1.3
	external/bsd/dhcpcd/dist/.arcconfig             up to 1.1.1.1
	external/bsd/dhcpcd/dist/.gitignore             up to 1.4
	external/bsd/dhcpcd/dist/BUILDING.md            up to 1.1.1.2
	external/bsd/dhcpcd/dist/LICENSE                up to 1.1.1.2
	external/bsd/dhcpcd/dist/Makefile               up to 1.1.1.5
	external/bsd/dhcpcd/dist/Makefile.inc           up to 1.1.1.2
	external/bsd/dhcpcd/dist/README.md              up to 1.1.1.3
	external/bsd/dhcpcd/dist/bpf-filter.h           delete
	external/bsd/dhcpcd/dist/common.c               delete
	external/bsd/dhcpcd/dist/arp.c                  delete
	external/bsd/dhcpcd/dist/arp.h                  delete
	external/bsd/dhcpcd/dist/auth.c                 delete
	external/bsd/dhcpcd/dist/auth.h                 delete
	external/bsd/dhcpcd/dist/dhcpcd.c               delete
	external/bsd/dhcpcd/dist/control.c              delete
	external/bsd/dhcpcd/dist/common.h               delete
	external/bsd/dhcpcd/dist/config.h               delete
	external/bsd/dhcpcd/dist/dhcp-common.c          delete
	external/bsd/dhcpcd/dist/control.h              delete
	external/bsd/dhcpcd/dist/defs.h                 delete
	external/bsd/dhcpcd/dist/dev.h                  delete
	external/bsd/dhcpcd/dist/dhcpcd-definitions.conf delete
	external/bsd/dhcpcd/dist/dhcp-common.h          delete
	external/bsd/dhcpcd/dist/dhcp.c                 delete
	external/bsd/dhcpcd/dist/dhcp.h                 delete
	external/bsd/dhcpcd/dist/dhcp6.c                delete
	external/bsd/dhcpcd/dist/dhcp6.h                delete
	external/bsd/dhcpcd/dist/dhcpcd-run-hooks.8.in  delete
	external/bsd/dhcpcd/dist/dhcpcd-embedded.c      delete
	external/bsd/dhcpcd/dist/dhcpcd.8.in            delete
	external/bsd/dhcpcd/dist/dhcpcd-embedded.c.in   delete
	external/bsd/dhcpcd/dist/dhcpcd-embedded.h      delete
	external/bsd/dhcpcd/dist/dhcpcd-embedded.h.in   delete
	external/bsd/dhcpcd/dist/ipv4.c                 delete
	external/bsd/dhcpcd/dist/if.c                   delete
	external/bsd/dhcpcd/dist/dhcpcd-run-hooks.in    delete
	external/bsd/dhcpcd/dist/dhcpcd.h               delete
	external/bsd/dhcpcd/dist/dhcpcd.conf            delete
	external/bsd/dhcpcd/dist/dhcpcd.conf.5.in       delete
	external/bsd/dhcpcd/dist/duid.c                 delete
	external/bsd/dhcpcd/dist/duid.h                 delete
	external/bsd/dhcpcd/dist/eloop.c                delete
	external/bsd/dhcpcd/dist/eloop.h                delete
	external/bsd/dhcpcd/dist/if-bsd.c               delete
	external/bsd/dhcpcd/dist/if-options.c           delete
	external/bsd/dhcpcd/dist/if-options.h           delete
	external/bsd/dhcpcd/dist/if.h                   delete
	external/bsd/dhcpcd/dist/crypt/hmac_md5.c       delete
	external/bsd/dhcpcd/dist/crypt/crypt.h          delete
	external/bsd/dhcpcd/dist/ipv4.h                 delete
	external/bsd/dhcpcd/dist/ipv4ll.c               delete
	external/bsd/dhcpcd/dist/ipv6.c                 delete
	external/bsd/dhcpcd/dist/ipv4ll.h               delete
	external/bsd/dhcpcd/dist/ipv6.h                 delete
	external/bsd/dhcpcd/dist/ipv6nd.c               delete
	external/bsd/dhcpcd/dist/ipv6nd.h               delete
	external/bsd/dhcpcd/dist/script.c               delete
	external/bsd/dhcpcd/dist/script.h               delete
	external/bsd/dhcpcd/dist/dhcpcd-hooks/15-timezone delete
	external/bsd/dhcpcd/dist/dhcpcd-hooks/01-test   delete
	external/bsd/dhcpcd/dist/dhcpcd-hooks/02-dump   delete
	external/bsd/dhcpcd/dist/dhcpcd-hooks/10-mtu    delete
	external/bsd/dhcpcd/dist/dhcpcd-hooks/10-wpa_supplicant delete
	external/bsd/dhcpcd/dist/dhcpcd-hooks/20-resolv.conf delete
	external/bsd/dhcpcd/dist/dhcpcd-hooks/29-lookup-hostname delete
	external/bsd/dhcpcd/dist/dhcpcd-hooks/30-hostname delete
	external/bsd/dhcpcd/dist/dhcpcd-hooks/50-ntp.conf delete
	external/bsd/dhcpcd/dist/dhcpcd-hooks/50-ypbind delete
	usr.sbin/postinstall/postinstall: revision 1.211-1.213
	etc/rc.d/dhcpcd					upto 1.5
	doc/3RDPARTY					manual edit

Import dhcpcd-7.0.7.
Adjust postinstal and rc file.
@
text
@a0 202
# Generate /etc/resolv.conf
# Support resolvconf(8) if available
# We can merge other dhcpcd resolv.conf files into one like resolvconf,
# but resolvconf is preferred as other applications like VPN clients
# can readily hook into it.
# Also, resolvconf can configure local nameservers such as bind
# or dnsmasq. This is important as the libc resolver isn't that powerful.

resolv_conf_dir="$state_dir/resolv.conf"
NL="
"
: ${resolvconf:=resolvconf}

build_resolv_conf()
{
	cf="$state_dir/resolv.conf.$ifname"

	# Build a list of interfaces
	interfaces=$(list_interfaces "$resolv_conf_dir")

	# Build the resolv.conf
	if [ -n "$interfaces" ]; then
		# Build the header
		for x in ${interfaces}; do
			header="$header${header:+, }$x"
		done

		# Build the search list
		domain=$(cd "$resolv_conf_dir"; \
			key_get_value "domain " ${interfaces})
		search=$(cd "$resolv_conf_dir"; \
			key_get_value "search " ${interfaces})
		set -- ${domain}
		domain="$1"
		[ -n "$2" ] && search="$search $*"
		[ -n "$search" ] && search="$(uniqify $search)"
		[ "$domain" = "$search" ] && search=
		[ -n "$domain" ] && domain="domain $domain$NL"
		[ -n "$search" ] && search="search $search$NL"

		# Build the nameserver list
		srvs=$(cd "$resolv_conf_dir"; \
			key_get_value "nameserver " ${interfaces})
		for x in $(uniqify ${srvs}); do
			servers="${servers}nameserver $x$NL"
		done
	fi
	header="$signature_base${header:+ $from }$header"

	# Assemble resolv.conf using our head and tail files
	[ -f "$cf" ] && rm -f "$cf"
	[ -d "$resolv_conf_dir" ] || mkdir -p "$resolv_conf_dir"
	echo "$header" > "$cf"
	if [ -f /etc/resolv.conf.head ]; then
		cat /etc/resolv.conf.head >> "$cf"
	else
		echo "# /etc/resolv.conf.head can replace this line" >> "$cf"
	fi
	printf %s "$domain$search$servers" >> "$cf"
	if [ -f /etc/resolv.conf.tail ]; then
		cat /etc/resolv.conf.tail >> "$cf"
	else
		echo "# /etc/resolv.conf.tail can replace this line" >> "$cf"
	fi
	if change_file /etc/resolv.conf "$cf"; then
		chmod 644 /etc/resolv.conf
	fi
	rm -f "$cf"
}

# Extract any ND DNS options from the RA
# For now, we ignore the lifetime of the DNS options unless they
# are absent or zero.
# In this case they are removed from consideration.
# See draft-gont-6man-slaac-dns-config-issues-01 for issues
# regarding DNS option lifetime in ND messages.
eval_nd_dns()
{
	eval ltime=\$nd${i}_rdnss${j}_lifetime
	if [ -z "$ltime" -o "$ltime" = 0 ]; then
		rdnss=
	else
		eval rdnss=\$nd${i}_rdnss${j}_servers
	fi
	eval ltime=\$nd${i}_dnssl${j}_lifetime
	if [ -z "$ltime" -o "$ltime" = 0 ]; then
		dnssl=
	else
		eval dnssl=\$nd${i}_dnssl${j}_search
	fi

	[ -z "$rdnss" -a -z "$dnssl" ] && return 1

	[ -n "$rdnss" ] && new_rdnss="$new_rdnss${new_rdnss:+ }$rdnss"
	[ -n "$dnssl" ] && new_dnssl="$new_dnssl${new_dnssl:+ }$dnssl"
	j=$(($j + 1))
	return 0
}

add_resolv_conf()
{
	conf="$signature$NL"
	warn=true

	# Loop to extract the ND DNS options using our indexed shell values
	i=1
	j=1
	while true; do
		while true; do
			eval_nd_dns || break
		done
		i=$(($i + 1))
		j=1
		eval_nd_dns || break
	done
	[ -n "$new_rdnss" ] && \
	    new_domain_name_servers="$new_domain_name_servers${new_domain_name_servers:+ }$new_rdnss"
	[ -n "$new_dnssl" ] && \
	    new_domain_search="$new_domain_search${new_domain_search:+ }$new_dnssl"

	# Derive a new domain from our various hostname options
	if [ -z "$new_domain_name" ]; then
		if [ "$new_dhcp6_fqdn" != "${new_dhcp6_fqdn#*.}" ]; then
			new_domain_name="${new_dhcp6_fqdn#*.}"
		elif [ "$new_fqdn" != "${new_fqdn#*.}" ]; then
			new_domain_name="${new_fqdn#*.}"
		elif [ "$new_host_name" != "${new_host_name#*.}" ]; then
			new_domain_name="${new_host_name#*.}"
		fi
	fi

	# If we don't have any configuration, remove it
	if [ -z "$new_domain_name_servers" -a \
		-z "$new_domain_name" -a \
		-z "$new_domain_search" ]; then
		remove_resolv_conf
		return $?
	fi

	if [ -n "$new_domain_name" ]; then
		set -- $new_domain_name
		if valid_domainname "$1"; then
			conf="${conf}domain $1$NL"
		else
			syslog err "Invalid domain name: $1"
		fi
		# If there is no search this, make this one
		if [ -z "$new_domain_search" ]; then
			new_domain_search="$new_domain_name"
			[ "$new_domain_name" = "$1" ] && warn=true
		fi
	fi
	if [ -n "$new_domain_search" ]; then
		if valid_domainname_list $new_domain_search; then
			conf="${conf}search $new_domain_search$NL"
		elif ! $warn; then
			syslog err "Invalid domain name in list:" \
			    "$new_domain_search"
		fi
	fi
	for x in ${new_domain_name_servers}; do
		conf="${conf}nameserver $x$NL"
	done
	if type "$resolvconf" >/dev/null 2>&1; then
		[ -n "$ifmetric" ] && export IF_METRIC="$ifmetric"
		printf %s "$conf" | "$resolvconf" -a "$ifname"
		return $?
	fi

	if [ -e "$resolv_conf_dir/$ifname" ]; then
		rm -f "$resolv_conf_dir/$ifname"
	fi
	[ -d "$resolv_conf_dir" ] || mkdir -p "$resolv_conf_dir"
	printf %s "$conf" > "$resolv_conf_dir/$ifname"
	build_resolv_conf
}

remove_resolv_conf()
{
	if type "$resolvconf" >/dev/null 2>&1; then
		"$resolvconf" -d "$ifname" -f
	else
		if [ -e "$resolv_conf_dir/$ifname" ]; then
			rm -f "$resolv_conf_dir/$ifname"
		fi
		build_resolv_conf
	fi
}

# For ease of use, map DHCP6 names onto our DHCP4 names
case "$reason" in
BOUND6|RENEW6|REBIND6|REBOOT6|INFORM6)
	new_domain_name_servers="$new_dhcp6_name_servers"
	new_domain_search="$new_dhcp6_domain_search"
	;;
esac

if $if_up || [ "$reason" = ROUTERADVERT ]; then
	add_resolv_conf
elif $if_down; then
	remove_resolv_conf
fi
@


1.1.1.1.2.1
log
@file 20-resolv.conf was added on branch bouyer-socketcan on 2017-03-31 20:51:17 +0000
@
text
@d1 204
@


1.1.1.1.2.2
log
@2552809
@
text
@a0 204
# Generate /etc/resolv.conf
# Support resolvconf(8) if available
# We can merge other dhcpcd resolv.conf files into one like resolvconf,
# but resolvconf is preferred as other applications like VPN clients
# can readily hook into it.
# Also, resolvconf can configure local nameservers such as bind
# or dnsmasq. This is important as the libc resolver isn't that powerful.

resolv_conf_dir="$state_dir/resolv.conf"
NL="
"
: ${resolvconf:=resolvconf}

build_resolv_conf()
{
	local cf="$state_dir/resolv.conf.$ifname"
	local interfaces= header= search= srvs= servers= x=

	# Build a list of interfaces
	interfaces=$(list_interfaces "$resolv_conf_dir")

	# Build the resolv.conf
	if [ -n "$interfaces" ]; then
		# Build the header
		for x in ${interfaces}; do
			header="$header${header:+, }$x"
		done

		# Build the search list
		domain=$(cd "$resolv_conf_dir"; \
			key_get_value "domain " ${interfaces})
		search=$(cd "$resolv_conf_dir"; \
			key_get_value "search " ${interfaces})
		set -- ${domain}
		domain="$1"
		[ -n "$2" ] && search="$search $*"
		[ -n "$search" ] && search="$(uniqify $search)"
		[ "$domain" = "$search" ] && search=
		[ -n "$domain" ] && domain="domain $domain$NL"
		[ -n "$search" ] && search="search $search$NL"

		# Build the nameserver list
		srvs=$(cd "$resolv_conf_dir"; \
			key_get_value "nameserver " ${interfaces})
		for x in $(uniqify ${srvs}); do
			servers="${servers}nameserver $x$NL"
		done
	fi
	header="$signature_base${header:+ $from }$header"

	# Assemble resolv.conf using our head and tail files
	[ -f "$cf" ] && rm -f "$cf"
	[ -d "$resolv_conf_dir" ] || mkdir -p "$resolv_conf_dir"
	echo "$header" > "$cf"
	if [ -f /etc/resolv.conf.head ]; then
		cat /etc/resolv.conf.head >> "$cf"
	else
		echo "# /etc/resolv.conf.head can replace this line" >> "$cf"
	fi
	printf %s "$domain$search$servers" >> "$cf"
	if [ -f /etc/resolv.conf.tail ]; then
		cat /etc/resolv.conf.tail >> "$cf"
	else
		echo "# /etc/resolv.conf.tail can replace this line" >> "$cf"
	fi
	if change_file /etc/resolv.conf "$cf"; then
		chmod 644 /etc/resolv.conf
	fi
	rm -f "$cf"
}

# Extract any ND DNS options from the RA
# For now, we ignore the lifetime of the DNS options unless they
# are absent or zero.
# In this case they are removed from consideration.
# See draft-gont-6man-slaac-dns-config-issues-01 for issues
# regarding DNS option lifetime in ND messages.
eval_nd_dns()
{

	eval ltime=\$nd${i}_rdnss${j}_lifetime
	if [ -z "$ltime" -o "$ltime" = 0 ]; then
		rdnss=
	else
		eval rdnss=\$nd${i}_rdnss${j}_servers
	fi
	eval ltime=\$nd${i}_dnssl${j}_lifetime
	if [ -z "$ltime" -o "$ltime" = 0 ]; then
		dnssl=
	else
		eval dnssl=\$nd${i}_dnssl${j}_search
	fi

	[ -z "$rdnss" -a -z "$dnssl" ] && return 1

	[ -n "$rdnss" ] && new_rdnss="$new_rdnss${new_rdnss:+ }$rdnss"
	[ -n "$dnssl" ] && new_dnssl="$new_dnssl${new_dnssl:+ }$dnssl"
	j=$(($j + 1))
	return 0
}

add_resolv_conf()
{
	local x= conf="$signature$NL" warn=true
	local i j ltime rdnss dnssl new_rdnss new_dnssl

	# Loop to extract the ND DNS options using our indexed shell values
	i=1
	j=1
	while true; do
		while true; do
			eval_nd_dns || break
		done
		i=$(($i + 1))
		j=1
		eval_nd_dns || break
	done
	[ -n "$new_rdnss" ] && \
	    new_domain_name_servers="$new_domain_name_servers${new_domain_name_servers:+ }$new_rdnss"
	[ -n "$new_dnssl" ] && \
	    new_domain_search="$new_domain_search${new_domain_search:+ }$new_dnssl"

	# Derive a new domain from our various hostname options
	if [ -z "$new_domain_name" ]; then
		if [ "$new_dhcp6_fqdn" != "${new_dhcp6_fqdn#*.}" ]; then
			new_domain_name="${new_dhcp6_fqdn#*.}"
		elif [ "$new_fqdn" != "${new_fqdn#*.}" ]; then
			new_domain_name="${new_fqdn#*.}"
		elif [ "$new_host_name" != "${new_host_name#*.}" ]; then
			new_domain_name="${new_host_name#*.}"
		fi
	fi

	# If we don't have any configuration, remove it
	if [ -z "$new_domain_name_servers" -a \
		-z "$new_domain_name" -a \
		-z "$new_domain_search" ]; then
		remove_resolv_conf
		return $?
	fi

	if [ -n "$new_domain_name" ]; then
		set -- $new_domain_name
		if valid_domainname "$1"; then
			conf="${conf}domain $1$NL"
		else
			syslog err "Invalid domain name: $1"
		fi
		# If there is no search this, make this one
		if [ -z "$new_domain_search" ]; then
			new_domain_search="$new_domain_name"
			[ "$new_domain_name" = "$1" ] && warn=true
		fi
	fi
	if [ -n "$new_domain_search" ]; then
		if valid_domainname_list $new_domain_search; then
			conf="${conf}search $new_domain_search$NL"
		elif ! $warn; then
			syslog err "Invalid domain name in list:" \
			    "$new_domain_search"
		fi
	fi
	for x in ${new_domain_name_servers}; do
		conf="${conf}nameserver $x$NL"
	done
	if type "$resolvconf" >/dev/null 2>&1; then
		[ -n "$ifmetric" ] && export IF_METRIC="$ifmetric"
		printf %s "$conf" | "$resolvconf" -a "$ifname"
		return $?
	fi

	if [ -e "$resolv_conf_dir/$ifname" ]; then
		rm -f "$resolv_conf_dir/$ifname"
	fi
	[ -d "$resolv_conf_dir" ] || mkdir -p "$resolv_conf_dir"
	printf %s "$conf" > "$resolv_conf_dir/$ifname"
	build_resolv_conf
}

remove_resolv_conf()
{
	if type "$resolvconf" >/dev/null 2>&1; then
		"$resolvconf" -d "$ifname" -f
	else
		if [ -e "$resolv_conf_dir/$ifname" ]; then
			rm -f "$resolv_conf_dir/$ifname"
		fi
		build_resolv_conf
	fi
}

# For ease of use, map DHCP6 names onto our DHCP4 names
case "$reason" in
BOUND6|RENEW6|REBIND6|REBOOT6|INFORM6)
	new_domain_name_servers="$new_dhcp6_name_servers"
	new_domain_search="$new_dhcp6_domain_search"
	;;
esac

if $if_up || [ "$reason" = ROUTERADVERT ]; then
	add_resolv_conf
elif $if_down; then
	remove_resolv_conf
fi
@


1.1.1.1.4.1
log
@file 20-resolv.conf was added on branch pgoyette-localcount on 2017-04-26 02:52:23 +0000
@
text
@d1 204
@


1.1.1.1.4.2
log
@Sync with HEAD
@
text
@a0 204
# Generate /etc/resolv.conf
# Support resolvconf(8) if available
# We can merge other dhcpcd resolv.conf files into one like resolvconf,
# but resolvconf is preferred as other applications like VPN clients
# can readily hook into it.
# Also, resolvconf can configure local nameservers such as bind
# or dnsmasq. This is important as the libc resolver isn't that powerful.

resolv_conf_dir="$state_dir/resolv.conf"
NL="
"
: ${resolvconf:=resolvconf}

build_resolv_conf()
{
	local cf="$state_dir/resolv.conf.$ifname"
	local interfaces= header= search= srvs= servers= x=

	# Build a list of interfaces
	interfaces=$(list_interfaces "$resolv_conf_dir")

	# Build the resolv.conf
	if [ -n "$interfaces" ]; then
		# Build the header
		for x in ${interfaces}; do
			header="$header${header:+, }$x"
		done

		# Build the search list
		domain=$(cd "$resolv_conf_dir"; \
			key_get_value "domain " ${interfaces})
		search=$(cd "$resolv_conf_dir"; \
			key_get_value "search " ${interfaces})
		set -- ${domain}
		domain="$1"
		[ -n "$2" ] && search="$search $*"
		[ -n "$search" ] && search="$(uniqify $search)"
		[ "$domain" = "$search" ] && search=
		[ -n "$domain" ] && domain="domain $domain$NL"
		[ -n "$search" ] && search="search $search$NL"

		# Build the nameserver list
		srvs=$(cd "$resolv_conf_dir"; \
			key_get_value "nameserver " ${interfaces})
		for x in $(uniqify ${srvs}); do
			servers="${servers}nameserver $x$NL"
		done
	fi
	header="$signature_base${header:+ $from }$header"

	# Assemble resolv.conf using our head and tail files
	[ -f "$cf" ] && rm -f "$cf"
	[ -d "$resolv_conf_dir" ] || mkdir -p "$resolv_conf_dir"
	echo "$header" > "$cf"
	if [ -f /etc/resolv.conf.head ]; then
		cat /etc/resolv.conf.head >> "$cf"
	else
		echo "# /etc/resolv.conf.head can replace this line" >> "$cf"
	fi
	printf %s "$domain$search$servers" >> "$cf"
	if [ -f /etc/resolv.conf.tail ]; then
		cat /etc/resolv.conf.tail >> "$cf"
	else
		echo "# /etc/resolv.conf.tail can replace this line" >> "$cf"
	fi
	if change_file /etc/resolv.conf "$cf"; then
		chmod 644 /etc/resolv.conf
	fi
	rm -f "$cf"
}

# Extract any ND DNS options from the RA
# For now, we ignore the lifetime of the DNS options unless they
# are absent or zero.
# In this case they are removed from consideration.
# See draft-gont-6man-slaac-dns-config-issues-01 for issues
# regarding DNS option lifetime in ND messages.
eval_nd_dns()
{

	eval ltime=\$nd${i}_rdnss${j}_lifetime
	if [ -z "$ltime" -o "$ltime" = 0 ]; then
		rdnss=
	else
		eval rdnss=\$nd${i}_rdnss${j}_servers
	fi
	eval ltime=\$nd${i}_dnssl${j}_lifetime
	if [ -z "$ltime" -o "$ltime" = 0 ]; then
		dnssl=
	else
		eval dnssl=\$nd${i}_dnssl${j}_search
	fi

	[ -z "$rdnss" -a -z "$dnssl" ] && return 1

	[ -n "$rdnss" ] && new_rdnss="$new_rdnss${new_rdnss:+ }$rdnss"
	[ -n "$dnssl" ] && new_dnssl="$new_dnssl${new_dnssl:+ }$dnssl"
	j=$(($j + 1))
	return 0
}

add_resolv_conf()
{
	local x= conf="$signature$NL" warn=true
	local i j ltime rdnss dnssl new_rdnss new_dnssl

	# Loop to extract the ND DNS options using our indexed shell values
	i=1
	j=1
	while true; do
		while true; do
			eval_nd_dns || break
		done
		i=$(($i + 1))
		j=1
		eval_nd_dns || break
	done
	[ -n "$new_rdnss" ] && \
	    new_domain_name_servers="$new_domain_name_servers${new_domain_name_servers:+ }$new_rdnss"
	[ -n "$new_dnssl" ] && \
	    new_domain_search="$new_domain_search${new_domain_search:+ }$new_dnssl"

	# Derive a new domain from our various hostname options
	if [ -z "$new_domain_name" ]; then
		if [ "$new_dhcp6_fqdn" != "${new_dhcp6_fqdn#*.}" ]; then
			new_domain_name="${new_dhcp6_fqdn#*.}"
		elif [ "$new_fqdn" != "${new_fqdn#*.}" ]; then
			new_domain_name="${new_fqdn#*.}"
		elif [ "$new_host_name" != "${new_host_name#*.}" ]; then
			new_domain_name="${new_host_name#*.}"
		fi
	fi

	# If we don't have any configuration, remove it
	if [ -z "$new_domain_name_servers" -a \
		-z "$new_domain_name" -a \
		-z "$new_domain_search" ]; then
		remove_resolv_conf
		return $?
	fi

	if [ -n "$new_domain_name" ]; then
		set -- $new_domain_name
		if valid_domainname "$1"; then
			conf="${conf}domain $1$NL"
		else
			syslog err "Invalid domain name: $1"
		fi
		# If there is no search this, make this one
		if [ -z "$new_domain_search" ]; then
			new_domain_search="$new_domain_name"
			[ "$new_domain_name" = "$1" ] && warn=true
		fi
	fi
	if [ -n "$new_domain_search" ]; then
		if valid_domainname_list $new_domain_search; then
			conf="${conf}search $new_domain_search$NL"
		elif ! $warn; then
			syslog err "Invalid domain name in list:" \
			    "$new_domain_search"
		fi
	fi
	for x in ${new_domain_name_servers}; do
		conf="${conf}nameserver $x$NL"
	done
	if type "$resolvconf" >/dev/null 2>&1; then
		[ -n "$ifmetric" ] && export IF_METRIC="$ifmetric"
		printf %s "$conf" | "$resolvconf" -a "$ifname"
		return $?
	fi

	if [ -e "$resolv_conf_dir/$ifname" ]; then
		rm -f "$resolv_conf_dir/$ifname"
	fi
	[ -d "$resolv_conf_dir" ] || mkdir -p "$resolv_conf_dir"
	printf %s "$conf" > "$resolv_conf_dir/$ifname"
	build_resolv_conf
}

remove_resolv_conf()
{
	if type "$resolvconf" >/dev/null 2>&1; then
		"$resolvconf" -d "$ifname" -f
	else
		if [ -e "$resolv_conf_dir/$ifname" ]; then
			rm -f "$resolv_conf_dir/$ifname"
		fi
		build_resolv_conf
	fi
}

# For ease of use, map DHCP6 names onto our DHCP4 names
case "$reason" in
BOUND6|RENEW6|REBIND6|REBOOT6|INFORM6)
	new_domain_name_servers="$new_dhcp6_name_servers"
	new_domain_search="$new_dhcp6_domain_search"
	;;
esac

if $if_up || [ "$reason" = ROUTERADVERT ]; then
	add_resolv_conf
elif $if_down; then
	remove_resolv_conf
fi
@


