2 # Update, add or delete a network interface
4 require './zones-lib.pl';
7 $zinfo = &get_zone($in{'zone'});
8 $zinfo || &error($text{'edit_egone'});
10 # Find the network object
11 ($net) = grep { $_->{'address'} eq $in{'old'} } @{$zinfo->{'net'}};
12 $net || &error($text{'net_egone'});
13 $active = &get_active_interface($zinfo, $net);
15 $net ||= { 'keytype' => 'net' };
18 # Just remove this network
19 &delete_zone_object($zinfo, $net);
20 &net::deactivate_interface($active) if ($active);
24 $form = &get_net_form(\%in, $zinfo, $net);
25 $form->validate_redirect("edit_net.cgi");
26 if ($form->get_value("netmask")) {
27 $cidr = &net::mask_to_prefix($form->get_value("netmask"));
28 $net->{'address'} = $form->get_value("address")."/".$cidr;
31 $net->{'address'} = $form->get_value("address");
33 $net->{'physical'} = $form->get_value("physical");
34 &find_clash($zinfo, $net) &&
35 $form->validate_redirect("edit_net.cgi",
36 [ [ "address", $text{'net_eclash'} ] ]);
38 # Create or update the real interface
40 local $vmax = int($net::min_virtual_number);
42 foreach $a (&net::active_interfaces()) {
43 $vmax = $a->{'virtual'}
44 if ($a->{'name'} eq $in{'physical'} &&
45 $a->{'virtual'} > $vmax);
47 $active = { 'name' => $in{'physical'},
49 'fullname' => $in{'physical'}.":".($vmax+1),
50 'zone' => $in{'zone'},
54 $active->{'address'} = $in{'address'};
55 if ($in{'netmask_def'}) {
56 $active->{'netmask'} =
57 &net::automatic_netmask($in{'address'});
60 $active->{'netmask'} = $in{'netmask'};
62 $active->{'broadcast'} = &net::compute_broadcast(
63 $active->{'address'}, $active->{'netmask'});
64 $active->{'zone'} = $in{'zone'};
67 # Save the zone settings
69 &create_zone_object($zinfo, $net);
70 if ($zinfo->{'status'} eq 'running') {
71 &net::activate_interface($active);
75 &modify_zone_object($zinfo, $net);
77 &net::activate_interface($active);
82 &webmin_log($in{'new'} ? "create" : $in{'delete'} ? "delete" : "modify",
83 "net", $in{'old'} || $net->{'address'}, $net);
84 &redirect("edit_zone.cgi?zone=$in{'zone'}");