Merge pull request #109 from shaba/devel

add DNS and Domain support in systemd network unit
pull/114/head
Vlastimil Holer 7 years ago committed by GitHub
commit 71abaa89ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -111,6 +111,18 @@ get_gateway6() {
fi fi
} }
get_dns() {
dns=$(get_iface_var "DNS")
echo $dns
}
get_search_domain() {
search_domain=$(get_iface_var "SEARCH_DOMAIN")
echo $search_domain
}
get_ip() { get_ip() {
ip=$(get_iface_var "IP") ip=$(get_iface_var "IP")
@ -124,7 +136,9 @@ get_iface_var() {
echo $var echo $var
} }
gen_iface_conf() { gen_iface_conf() {
cat <<EOT cat <<EOT
[Network] [Network]
Address=$IP/$CIDR Address=$IP/$CIDR
@ -134,12 +148,16 @@ EOT
echo "Gateway=$GATEWAY" echo "Gateway=$GATEWAY"
fi fi
if [ -n "$MTU" ]; then if [ -n "$DNS" ]; then
cat <<EOT for dns_server in $DNS; do
echo "DNS=$dns_server"
done
fi
[Link] if [ -n "$DNS" ]; then
MTUBytes=$MTU" for domain in $SEARCH_DOMAIN; do
EOT echo "Domains=$domain"
done
fi fi
echo "" echo ""
@ -148,18 +166,30 @@ EOT
gen_iface6_conf() { gen_iface6_conf() {
cat <<EOT cat <<EOT
[Network] [Network]
Address=$IPV6/64 Address=$IP6/${IP6_PREFIX_LENGTH:-64}
IPv6AcceptRA=false
EOT EOT
if [ -n "$GATEWAY6" ]; then if [ -n "$GATEWAY6" ]; then
echo "Gateway=$GATEWAY6" echo "Gateway=$GATEWAY6"
fi fi
if [ -n "$MTU" ]; then if [ -n "$DNS" ]; then
cat <<EOT for dns_server in $DNS; do
echo "DNS=$dns_server"
done
fi
[Link] if [ -n "$DNS" ]; then
MTUBytes=$MTU for domain in $SEARCH_DOMAIN; do
echo "Domains=$domain"
done
fi
if [ -n "$IP6_ULA" ]; then
cat <<EOT
[Network]
Address=$IP6_ULA/64
EOT EOT
fi fi
@ -202,30 +232,41 @@ gen_network_configuration()
CIDR=$(mask2cidr "$MASK") CIDR=$(mask2cidr "$MASK")
MTU=$(get_mtu) MTU=$(get_mtu)
GATEWAY=$(get_gateway) GATEWAY=$(get_gateway)
DNS=$(get_dns)
SEARCH_DOMAIN=$(get_search_domain)
IPV6=$(get_iface_var "IPV6") IP6=$(get_iface_var "IP6")
[[ -z $IPV6 ]] && IPV6=$(get_iface_var "IP6") IP6_PREFIX_LENGTH=$(get_iface_var "IP6_PREFIX_LENGTH")
IP6_ULA=$(get_iface_var "IP6_ULA")
GATEWAY6=$(get_gateway6) GATEWAY6=$(get_gateway6)
CONTEXT_FORCE_IPV4=$(get_iface_var "CONTEXT_FORCE_IPV4") CONTEXT_FORCE_IPV4=$(get_iface_var "CONTEXT_FORCE_IPV4")
[ -z "${IP}${IPV6}" ] && continue [ -z "${IP}${IP6}" ] && continue
[ -z "${DEV}" ] && continue [ -z "${DEV}" ] && continue
( (
cat <<EOT cat <<EOT
[Match] [Match]
Name=$DEV Name=$DEV
EOT
if [ -n "$MTU" ]; then
cat <<EOT
[Link]
MTUBytes=$MTU
EOT EOT
[[ -z $IPV6 || -n $CONTEXT_FORCE_IPV4 ]] && gen_iface_conf fi
[[ -n $IPV6 ]] && gen_iface6_conf
[[ -n $IP || -n $CONTEXT_FORCE_IPV4 ]] && gen_iface_conf
[[ -n $IP6 ]] && gen_iface6_conf
) > /etc/systemd/network/${DEV}.network ) > /etc/systemd/network/${DEV}.network
done done
} }
[ -z "$(env | cut -d= -f1 | grep -E '^ETH[0-9]+_IPV*6*')" ] && exit 0 [ -z "$(env | cut -d= -f1 | grep -E '^ETH[0-9]+_IP6*')" ] && exit 0
gen_network_configuration gen_network_configuration

Loading…
Cancel
Save