foreach my $key (keys %conns) {
my $name = $conns{$key}[1];
my $type = $conns{$key}[3];
- my $gateway = "";
# Skip anything that isn't a host connection
next unless ($type eq "host");
# The gateway is always the first address in the network
# (this is needed to push any routes below)
- $gateway = &Network::find_next_ip_address($netaddr, 1);
+ my $gateway = &Network::find_next_ip_address($netaddr, 1);
if (defined $address && defined $network && defined $netmask) {
print CONF "# Allocated IP address from $pool\n";
- print CONF "ifconfig-push ${address} ${netmask}\n\n";
+ print CONF "ifconfig-push ${address} ${netmask}\n";
}
+
+ # Push the first address of the static pool as the gateway.
+ # Withtout this pushed, the client will receive the first IP address
+ # of the dynamic pool which will cause problems later on:
+ # Any additional routes won't be able to reach the dynamic gateway
+ # but pushing a host route is not possible, because the OpenVPN client
+ # does not seem to understand how a layer 3 VPN works.
+ if (defined $gateway) {
+ print CONF "push \"route-gateway ${gateway}\"\n";
+ }
+
+ # End the block
+ print CONF "\n";
}
# Redirect Gateway?
next;
}
- print CONF "push \"route $netaddress $netmask $gateway\"\n";
+ print CONF "push \"route $netaddress $netmask\"\n";
}
# Newline