1100280Sgordon#!/bin/sh
225184Sjkh#
350472Speter# $FreeBSD$
466830Sobrien#
525184Sjkh
6117019Smtm# PROVIDE: netoptions
7169215Smtm# REQUIRE: FILESYSTEMS
8197143Shrs# BEFORE: netif
9136224Smtm# KEYWORD: nojail
1025184Sjkh
11100280Sgordon. /etc/rc.subr
12197646Sume. /etc/network.subr
1325184Sjkh
14197143Shrsname="netoptions"
15298514Slmedesc="Network options setup"
16197143Shrsstart_cmd="netoptions_start"
17197143Shrsstop_cmd=:
18197143Shrs
19179940Smtm_netoptions_initdone=
20179940Smtmnetoptions_init()
21179940Smtm{
22179940Smtm	if [ -z "${_netoptions_initdone}" ]; then
23179940Smtm		echo -n 'Additional TCP/IP options:'
24179940Smtm		_netoptions_initdone=yes
25179940Smtm	fi
26179940Smtm}
27179940Smtm
28197143Shrsnetoptions_start()
29197143Shrs{
30197698Shrs	local _af
31197698Shrs
32197698Shrs	for _af in inet inet6; do
33197698Shrs		afexists ${_af} && eval netoptions_${_af}
34197698Shrs	done
35197698Shrs	[ -n "${_netoptions_initdone}" ] && echo '.'
36197698Shrs}
37197698Shrs
38197698Shrsnetoptions_inet()
39197698Shrs{
40197702Shrs	case ${log_in_vain} in
41197702Shrs	[12])
42197143Shrs		netoptions_init
43197143Shrs		echo -n " log_in_vain=${log_in_vain}"
44220153Semaste		${SYSCTL} net.inet.tcp.log_in_vain=${log_in_vain} >/dev/null
45220153Semaste		${SYSCTL} net.inet.udp.log_in_vain=${log_in_vain} >/dev/null
46197702Shrs		;;
47197702Shrs	*)
48220153Semaste		${SYSCTL} net.inet.tcp.log_in_vain=0 >/dev/null
49220153Semaste		${SYSCTL} net.inet.udp.log_in_vain=0 >/dev/null
50197702Shrs		;;
51197702Shrs	esac
5285831Sdes
53197143Shrs	if checkyesno tcp_extensions; then
54220153Semaste		${SYSCTL} net.inet.tcp.rfc1323=1 >/dev/null
55197698Shrs	else
56197143Shrs		netoptions_init
57198383Shrs		echo -n " rfc1323 extensions=${tcp_extensions}"
58220153Semaste		${SYSCTL} net.inet.tcp.rfc1323=0 >/dev/null
59197143Shrs	fi
6065532Snectar
61197698Shrs	if checkyesno tcp_keepalive; then
62220153Semaste		${SYSCTL} net.inet.tcp.always_keepalive=1 >/dev/null
63197698Shrs	else
64197143Shrs		netoptions_init
65198383Shrs		echo -n " TCP keepalive=${tcp_keepalive}"
66220153Semaste		${SYSCTL} net.inet.tcp.always_keepalive=0 >/dev/null
67197143Shrs	fi
68169217Smtm
69197143Shrs	if checkyesno tcp_drop_synfin; then
70197143Shrs		netoptions_init
71198383Shrs		echo -n " drop SYN+FIN packets=${tcp_drop_synfin}"
72220153Semaste		${SYSCTL} net.inet.tcp.drop_synfin=1 >/dev/null
73197698Shrs	else
74220153Semaste		${SYSCTL} net.inet.tcp.drop_synfin=0 >/dev/null
75197143Shrs	fi
76169217Smtm
77197143Shrs	case ${ip_portrange_first} in
78197143Shrs	[0-9]*)
79197143Shrs		netoptions_init
80197143Shrs		echo -n " ip_portrange_first=$ip_portrange_first"
81220153Semaste		${SYSCTL} net.inet.ip.portrange.first=$ip_portrange_first >/dev/null
82197143Shrs		;;
83197143Shrs	esac
84169217Smtm
85197143Shrs	case ${ip_portrange_last} in
86197143Shrs	[0-9]*)
87197143Shrs		netoptions_init
88197143Shrs		echo -n " ip_portrange_last=$ip_portrange_last"
89220153Semaste		${SYSCTL} net.inet.ip.portrange.last=$ip_portrange_last >/dev/null
90197143Shrs		;;
91197143Shrs	esac
92197698Shrs}
93169217Smtm
94197698Shrsnetoptions_inet6()
95197698Shrs{
96197698Shrs	if checkyesno ipv6_ipv4mapping; then
97197698Shrs		netoptions_init
98197698Shrs		echo -n " ipv4-mapped-ipv6=${ipv6_ipv4mapping}"
99220153Semaste		${SYSCTL} net.inet6.ip6.v6only=0 >/dev/null
100197698Shrs	else
101220153Semaste		${SYSCTL} net.inet6.ip6.v6only=1 >/dev/null
102197143Shrs	fi
103212576Shrs
104212576Shrs	if checkyesno ipv6_privacy; then
105212576Shrs		netoptions_init
106212576Shrs		echo -n " IPv6 Privacy Addresses"
107220153Semaste		${SYSCTL} net.inet6.ip6.use_tempaddr=1 >/dev/null
108220153Semaste		${SYSCTL} net.inet6.ip6.prefer_tempaddr=1 >/dev/null
109212576Shrs	fi
110225521Shrs
111225521Shrs	case $ipv6_cpe_wanif in
112225521Shrs	""|[Nn][Oo]|[Nn][Oo][Nn][Ee]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0)
113225521Shrs		${SYSCTL} net.inet6.ip6.no_radr=0 >/dev/null
114225521Shrs		${SYSCTL} net.inet6.ip6.rfc6204w3=0 >/dev/null
115225521Shrs	;;
116225521Shrs	*)	
117225521Shrs		netoptions_init
118225521Shrs		echo -n " IPv6 CPE WANIF=${ipv6_cpe_wanif}"
119225521Shrs		${SYSCTL} net.inet6.ip6.no_radr=1 >/dev/null
120225521Shrs		${SYSCTL} net.inet6.ip6.rfc6204w3=1 >/dev/null
121225521Shrs	;;
122225521Shrs	esac
123197143Shrs}
124169217Smtm
125197143Shrsload_rc_config $name
126197143Shrsrun_rc_command $1
127