3 # Edit or create a bootup interface
5 require './net-lib.pl';
7 !$in{'new'} || &can_create_iface() || &error($text{'ifcs_ecannot'});
8 @boot = &boot_interfaces();
10 # Show page title and get interface
11 if ($in{'new'} && $in{'bond'}) {
12 # New bonding interface
13 &ui_print_header(undef, $text{'bonding_create'}, "");
15 elsif ($in{'new'} && $in{'vlan'}) {
17 &ui_print_header(undef, $text{'vlan_create'}, "");
19 elsif ($in{'new'} && $in{'bridge'}) {
21 &ui_print_header(undef, $text{'bridge_create'}, "");
24 if ($b->{'fullname'} =~ /^br(\d+)$/) {
30 # New real or virtual interface
31 &ui_print_header(undef, $text{'bifc_create'}, "");
33 # Pick a virtual number
34 $vmax = int($net::min_virtual_number);
35 foreach my $e (@boot) {
36 $vmax = $e->{'virtual'}
37 if ($e->{'name'} eq $in{'virtual'} &&
38 $e->{'virtual'} > $vmax);
44 $b = $boot[$in{'idx'}];
45 &can_iface($b) || &error($text{'ifcs_ecannot_this'});
46 &ui_print_header(undef, $text{'bifc_edit'}, "");
47 if (!$b->{'dhcp'} && !$b->{'bootp'} && !$b->{'broadcast'}) {
48 # Fill in broadcast if missing
49 $b->{'broadcast'} = &compute_broadcast(
50 $b->{'address'}, $b->{'netmask'});
55 print &ui_form_start("save_bifc.cgi");
56 print &ui_hidden("new", $in{'new'});
57 print &ui_hidden("idx", $in{'idx'});
58 print &ui_hidden("vlan", $in{'vlan'});
59 print &ui_hidden("bond", $in{'bond'});
60 print &ui_hidden("bridge", $in{'bridge'});
61 print &ui_table_start($in{'virtual'} || $b && $b->{'virtual'} ne "" ?
62 $text{'bifc_desc2'} : $text{'bifc_desc1'}, undef, 2);
65 if (defined(&can_iface_desc) && &can_iface_desc($b)) {
66 print &ui_table_row($text{'ifcs_desc'},
67 &ui_textbox("desc", $b ? $b->{'desc'} : undef, 60), 3);
71 if ($in{'new'} && $in{'virtual'}) {
72 # New virtual interface
73 $namefield = $in{'virtual'}.":".
74 &ui_textbox("virtual", $vmax+1, 3).
75 &ui_hidden("name", $in{'virtual'});
79 if ($in{'vlan'} == 1) {
80 $namefield = "auto".&ui_hidden("name", "auto");
82 elsif ($in{'bridge'}) {
83 $namefield = "br ".&ui_textbox("name", ($bmax+1), 3);
86 $namefield = &ui_textbox("name", undef, 6);
91 $namefield = "<tt>$b->{'fullname'}</tt>";
93 print &ui_table_row($text{'ifcs_name'}, $namefield);
96 if (&can_edit("up", $b) && $access{'up'}) {
97 $upfield = &ui_yesno_radio("up", !$b || $b->{'up'});
100 $upfield = !$b ? $text{'yes'} :
101 $b->{'up'} ? $text{'yes'} : $text{'no'};
103 print &ui_table_row($text{'bifc_act'}, $upfield);
105 # IP address source. This can either be DHCP, BootP or a fixed IP,
106 # netmask and broadcast
107 $virtual = (!$b && $in{'virtual'}) || ($b && $b->{'virtual'} ne "");
108 $dhcp = &can_edit("dhcp") && !$virtual;
109 $bootp = &can_edit("bootp") && !$virtual;
110 if (defined(&supports_no_address) && &supports_no_address()) {
111 # Having no address is allowed
114 elsif ($b && !$b->{'address'} && !$b->{'dhcp'} && !$b->{'bootp'}) {
120 push(@opts, [ "none", $text{'ifcs_noaddress'} ]);
123 push(@opts, [ "dhcp", $text{'ifcs_dhcp'} ]);
126 push(@opts, [ "bootp", $text{'ifcs_bootp'} ]);
130 @grid = ( $text{'ifcs_ip'},
131 &ui_textbox("address", $b ? $b->{'address'} : "", 15) );
132 if ($in{'virtual'} && $in{'new'} && $virtual_netmask) {
134 push(@grid, $text{'ifcs_mask'}, "<tt>$virtual_netmask</tt>");
136 elsif (&can_edit("netmask", $b) && $access{'netmask'}) {
138 push(@grid, $text{'ifcs_mask'},
139 &ui_textbox("netmask", $b ? $b->{'netmask'}
140 : $config{'def_netmask'}, 15));
142 elsif ($b && $b->{'netmask'}) {
144 push(@grid, $text{'ifcs_mask'}, "<tt>$b->{'netmask'}</tt>");
146 if (&can_edit("broadcast", $b) && $access{'broadcast'}) {
147 # Can edit broadcast address
148 push(@grid, $text{'ifcs_broad'},
149 &ui_opt_textbox("broadcast",
150 $b ? $b->{'broadcast'} : $config{'def_broadcast'},
151 15, $text{'ifcs_auto'}));
153 elsif ($b && $b->{'broadcast'}) {
155 push(@grid, $text{'ifcs_broad'}, "<tt>$b->{'broadcast'}</tt>");
157 push(@opts, [ "address", $text{'ifcs_static2'}, &ui_grid_table(\@grid, 2) ]);
161 print &ui_table_row($text{'ifcs_mode'},
162 &ui_radio_table("mode", $b && $b->{'dhcp'} ? "dhcp" :
163 $b && $b->{'bootp'} ? "bootp" :
164 $b && !$b->{'address'} ? "none" :
169 print &ui_table_row($opts[0]->[1], $opts[0]->[2]);
172 # Show the IPv6 field
173 if (&supports_address6($b)) {
174 # Multiple IPs allowed
175 $table6 = &ui_columns_start([ $text{'ifcs_address6'},
176 $text{'ifcs_netmask6'} ], 50);
177 for($i=0; $i<=($b ? scalar(@{$b->{'address6'}}) : 0); $i++) {
178 $table6 .= &ui_columns_row([
179 &ui_textbox("address6_$i",
180 $b->{'address6'}->[$i], 40),
181 &ui_textbox("netmask6_$i",
182 $b->{'netmask6'}->[$i] || 64, 10) ]);
184 $table6 .= &ui_columns_end();
185 print &ui_table_row($text{'ifcs_mode6'},
186 &ui_radio_table("mode6",
188 $b->{'auto6'} ? "auto" :
189 @{$b->{'address6'}} ? "address" : "none",
190 [ [ "none", $text{'ifcs_none6'} ],
191 [ "auto", $text{'ifcs_auto6'} ],
192 [ "address", $text{'ifcs_static2'}, $table6 ] ]), 2);
196 if (&can_edit("mtu", $b) && $access{'mtu'}) {
197 $mtufield = &ui_opt_textbox(
198 "mtu", $b ? $b->{'mtu'} : $config{'def_mtu'}, 8,
202 $mtufield = $b && $b->{'mtu'} ? $b->{'mtu'} : undef;
205 print &ui_table_row($text{'ifcs_mtu'}, $mtufield);
208 # Virtual sub-interfaces
209 if ($b && $b->{'virtual'} eq "") {
211 foreach $vb (@boot) {
212 if ($vb->{'virtual'} ne "" && $vb->{'name'} eq $b->{'name'}) {
217 if ($access{'virt'} && !$noos_support_add_virtifcs) {
218 $vlink = "(<a href='edit_bifc.cgi?new=1&virtual=$b->{'name'}'>".
219 "$text{'ifcs_addvirt'}</a>)\n";
221 print &ui_table_row($text{'ifcs_virts'}, $vcount." ".$vlink);
224 # Special parameters for teaming
225 if ($in{'bond'} || &iface_type($b->{'name'}) eq 'Bonded') {
226 # Select bonding teampartner
227 print &ui_table_row($text{'bonding_teamparts'},
228 &ui_textbox("partner", $b->{'partner'}, 10));
230 # Select teaming mode
231 @mode = ("balance-rr", "activebackup", "balance-xor", "broadcast", "802.3ad", "balance-tlb", "balance-alb");
232 print &ui_table_row($text{'bonding_teammode'},
233 &ui_select("bondmode", int($b->{'mode'}),
234 [ map { [ $_, $mode[$_] ] } (0 .. $#mode) ]));
236 # Select mii Monitoring Interval
237 print &ui_table_row($text{'bonding_miimon'},
238 &ui_textbox("miimon", $b->{'miimon'}, 5)." ms");
241 print &ui_table_row($text{'bonding_updelay'},
242 &ui_textbox("updelay", $b->{'updelay'}, 5)." ms");
245 print &ui_table_row($text{'bonding_downdelay'},
246 &ui_textbox("downdelay", $b->{'downdelay'}, 5)." ms");
249 # Special Parameter for vlan tagging
250 if(($in{'vlan'}) or (&iface_type($b->{'name'}) =~ /^(.*) (VLAN)$/)) {
251 $b->{'name'} =~ /(\S+)\.(\d+)/;
256 @phys = grep { $_->{'virtual'} eq '' } &active_interfaces();
257 print &ui_table_row($text{'vlan_physical'},
258 $in{'new'} ? &ui_select("physical", $physical,
259 [ map { $_->{'fullname'} } @phys ])
260 : $physical.&ui_hidden("physical", $physical));
263 print &ui_table_row($text{'vlan_id'},
264 $in{'new'} ? &ui_textbox("vlanid", $vlanid, 10)
265 : $vlanid.&ui_hidden("vlanid", $vlanid));
268 # Hardware address, if non-virtual
269 if (($in{'new'} && $in{'virtual'} eq "" && !$in{'bridge'}) ||
270 (!$in{'new'} && $b->{'virtual'} eq "" &&
271 defined(&boot_iface_hardware) &&
272 &boot_iface_hardware($b->{'name'}))) {
273 $hardfield = &ui_opt_textbox("ether", $b->{'ether'}, 30,
274 $text{'aifc_default'});
275 print &ui_table_row($text{'aifc_hard'}, $hardfield);
278 # Real interface for bridge
279 if ($in{'bridge'} || $b && $b->{'bridge'}) {
280 @ethboot = sort { $a cmp $b }
281 map { $_->{'fullname'} }
282 grep { $_->{'fullname'} =~ /^eth(\d+)$/ } @boot;
283 print &ui_table_row($text{'bifc_bridgeto'},
284 &ui_select("bridgeto", $b->{'bridgeto'}, \@ethboot, 1, 0,
285 $in{'new'} ? 0 : 1));
288 print &ui_table_end();
290 # Generate and show buttons at end of the form
292 if ($access{'bootonly'}) {
293 # Can only save both boot-time and active
295 push(@buts, [ "activate", $text{'bifc_capply'} ]);
298 push(@buts, [ "activate", $text{'bifc_apply'} ]);
299 if ($access{'delete'}) {
300 push(@buts, [ "unapply", $text{'bifc_dapply'} ]);
305 # Show buttons to save both boot-time and/or active
307 push(@buts, [ undef, $text{'create'} ]);
308 push(@buts, [ "activate", $text{'bifc_capply'} ]);
311 push(@buts, [ undef, $text{'save'} ])
312 unless $always_apply_ifcs;
313 if (!($b->{'bootp'} || $b->{'dhcp'}) ||
314 defined(&apply_interface)) {
315 push(@buts, [ "activate", $text{'bifc_apply'} ]);
317 if ($access{'delete'}) {
318 push(@buts, [ "unapply", $text{'bifc_dapply'} ]);
319 push(@buts, [ "delete", $text{'delete'} ])
320 unless $noos_support_delete_ifcs;
324 print &ui_form_end(\@buts);
326 &ui_print_footer("list_ifcs.cgi?mode=boot", $text{'ifcs_return'});