Skip to content

Commit

Permalink
Fixes #622. Add a new file status for signaling default gateway under…
Browse files Browse the repository at this point in the history
… /tmp. dhclient script will check for this file to define if the interface needs a default gateway or not from its given routes.
  • Loading branch information
Ermal committed May 31, 2010
1 parent 1fb0596 commit 924f202
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
16 changes: 15 additions & 1 deletion etc/inc/system.inc
Expand Up @@ -263,15 +263,29 @@ function system_routing_configure() {
$interfacegw = "";
/* tack on all the hard defined gateways as well */
if (is_array($config['gateways']['gateway_item'])) {
mwexec("/bin/rm {$g['tmp_path']}/*_defaultgw");
$foundgw = false;
foreach ($config['gateways']['gateway_item'] as $gateway) {
if (isset($gateway['defaultgw'])) {
if ($gateway['gateway'] == "dynamic")
$gateway['gateway'] = get_interface_gateway($gateway['interface']);
$gatewayip = $gateway['gateway'];
$interfacegw = $gateway['interface'];
if (!empty($interfacegw)) {
$defaultif = get_real_interface($gateway['interface']);
if ($defaultif)
@file_put_contents("{$g['tmp_path']}/{$defaultif}_defaultgw", $gatewayip);
}
$foundgw = true;
break;
}
}
if ($foundgw == false) {
$defaultif = get_real_interface("wan");
$interfacegw = "wan";
$gatewayip = get_interface_gateway("wan");
@touch("{$g['tmp_path']}/{$defaultif}_defaultgw");
}
}
$dont_add_route = false;
/* if OLSRD is enabled, allow WAN to house DHCP. */
Expand Down Expand Up @@ -1418,4 +1432,4 @@ function system_get_dmesg_boot() {
return file_get_contents("{$g['varlog_path']}/dmesg.boot");
}

?>
?>
26 changes: 9 additions & 17 deletions sbin/dhclient-script
Expand Up @@ -130,23 +130,22 @@ delete_old_routes() {
}

add_new_routes() {
$LOGGER "Adding new routes"
# $ROUTE add $new_ip_address $LOCALHOST >/dev/null 2>&1
$LOGGER "Adding new routes to interface: $interface"

# Only allow the default route to be overridden if it's on our own interface
DEFAULTROUTE_IFACE=`/sbin/route get default | grep interface | awk '{print $2};'`
if [ -z "${DEFAULTROUTE_IFACE}" -o "{$interface}" = "${DEFAULTROUTE_IFACE}" ]; then
if [ -f "/tmp/${interface}_defaultgw" ]; then
$ROUTE delete default
for router in $new_routers; do
if [ "$new_ip_address" = "$router" ]; then
$ROUTE add default -iface $router
#>/dev/null 2>&1
echo $ROUTE add default -iface $router | $LOGGER
echo $new_routers > /tmp/${interface}_router
$ROUTE add default -iface $interface
echo $ROUTE add default -iface $interface | $LOGGER
echo $router > /tmp/${interface}_router
echo $router > /tmp/${interface}_defaultgw
else
$ROUTE add default $router
echo $ROUTE add default $router | $LOGGER
#>/dev/null 2>&1
echo $new_routers > /tmp/${interface}_router
echo $router > /tmp/${interface}_router
echo $router > /tmp/${interface}_defaultgw
fi
# 2nd and subsequent default routers error out, so explicitly
# stop processing the list after the first one.
Expand All @@ -163,13 +162,6 @@ add_new_routes() {
echo $new_routers > /tmp/${interface}_router
done
fi

# last ditch effort if no route exists.
DEFAULTROUTE=`$NETSTAT -rn | $GREP default`
if [ -z "${DEFAULTROUTE}" ]; then
$ROUTE add default -iface $interface
fi

}

add_new_resolv_conf() {
Expand Down

1 comment on commit 924f202

@marjohn56
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have just tested the one patch f09eaf7 and that seemed to work.

So what patches and in what order shall I tell Ned ( my Sky UK tester ) to try?

Please sign in to comment.