summaryrefslogtreecommitdiffstats
path: root/etc/rc.initial.setlanip
diff options
context:
space:
mode:
authorDarren Embry <dse@webonastick.com>2012-06-07 20:38:55 -0400
committerDarren Embry <dse@webonastick.com>2012-06-07 20:39:22 -0400
commitd23b53eb51a070d21b308484ca1aaba321e3be20 (patch)
treede2b0b0df207108622a668e1d6156907c3e1a770 /etc/rc.initial.setlanip
parent3176c0433422316db58f09ac51f357e89a0bdf90 (diff)
downloadpfsense-d23b53eb51a070d21b308484ca1aaba321e3be20.zip
pfsense-d23b53eb51a070d21b308484ca1aaba321e3be20.tar.gz
add gateways to config from cmdline
Diffstat (limited to 'etc/rc.initial.setlanip')
-rwxr-xr-xetc/rc.initial.setlanip61
1 files changed, 60 insertions, 1 deletions
diff --git a/etc/rc.initial.setlanip b/etc/rc.initial.setlanip
index 87743b2..e062e6e 100755
--- a/etc/rc.initial.setlanip
+++ b/etc/rc.initial.setlanip
@@ -166,6 +166,61 @@ if(!$interface) {
$ifaceassigned = "";
+function next_unused_gateway_name($interface) {
+ global $g, $config;
+ $new_name = "GW_" . strtoupper($interface);
+
+ if (!is_array($config['gateways']['gateway_item'])) { return $new_name; }
+ $count = 1;
+ do {
+ $existing = false;
+ foreach ($config['gateways']['gateway_item'] as $item) {
+ if ($item['name'] === $new_name) {
+ $existing = true;
+ break;
+ }
+ }
+ if ($existing) {
+ $count += 1;
+ $new_name = "GW_" . strtoupper($interface) . "_" . $count;
+ }
+ } while ($existing);
+ return $new_name;
+}
+
+function add_gateway_to_config($interface, $gatewayip, $inet_type) {
+ global $g, $config, $dry_run;
+ if (!is_array($config['gateways']['gateway_item'])) {
+ $config['gateways']['gateway_item'] = array();
+ }
+ $a_gateways = &$config['gateways']['gateway_item'];
+ if ($dry_run) {
+ print_r($a_gateways);
+ }
+ $new_name = next_unused_gateway_name($interface);
+ $is_default = true;
+ foreach ($a_gateways as $item) {
+ if ($item['ipprotocol'] === $inet_type) {
+ $is_default = false;
+ break;
+ }
+ }
+ $item = array(
+ "interface" => $interface,
+ "gateway" => $gatewayip,
+ "name" => $new_name,
+ "weight" => 1,
+ "ipprotocol" => $inet_type,
+ "interval" => true,
+ "descr" => "Interface $interface Gateway",
+ "defaultgw" => $is_default
+ );
+ if ($dry_run) {
+ print_r($item);
+ }
+ $a_gateways[] = $item;
+}
+
function console_configure_ip_address($version) {
global $g, $config, $interface, $restart_dhcpd, $ifaceassigned, $fp;
@@ -224,7 +279,6 @@ function console_configure_ip_address($version) {
} else {
$subnet = gen_subnet($intip, $intbits);
}
- echo "subnet: {$subnet}/{$intbits}\n";
do {
echo "\n" . sprintf(gettext("Enter the new %s %s gateway address. Press <ENTER> for none:"),
$upperifname, $label_IPvX) . "\n> ";
@@ -239,6 +293,11 @@ function console_configure_ip_address($version) {
}
}
} while (!($gwip == '' || ($is_ipaddr && $is_in_subnet)));
+
+ if ($gwip != '') {
+ $inet_type = ($version === 6) ? "inet6" : "inet";
+ add_gateway_to_config($interface, $gwip, $inet_type);
+ }
}
$ifppp = console_get_interface_from_ppp(get_real_interface("wan"));
if (!empty($ifppp))
OpenPOWER on IntegriCloud