Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OpnSense
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
OpnSense
Commits
c85a9b0b
Commit
c85a9b0b
authored
Aug 12, 2015
by
Franco Fichtner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
interfaces: merge assignment rework and function rewrite from master
parent
0b6c6af8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
112 additions
and
132 deletions
+112
-132
config.console.inc
src/etc/inc/config.console.inc
+35
-29
util.inc
src/etc/inc/util.inc
+76
-102
rc.bootup
src/etc/rc.bootup
+1
-1
No files found.
src/etc/inc/config.console.inc
View file @
c85a9b0b
...
@@ -28,14 +28,6 @@
...
@@ -28,14 +28,6 @@
POSSIBILITY OF SUCH DAMAGE.
POSSIBILITY OF SUCH DAMAGE.
*/
*/
/****f* util/timeout
* NAME
* timeout - console input with timeout countdown. Note: erases 2 char of screen for timer. Leave space.
* INPUTS
* optional, seconds to wait before timeout. Default 9 seconds.
* RESULT
* returns 1 char of user input or null if no input.
******/
function
timeout
(
$timer
=
9
)
function
timeout
(
$timer
=
9
)
{
{
while
(
!
isset
(
$key
))
{
while
(
!
isset
(
$key
))
{
...
@@ -55,9 +47,7 @@ function timeout($timer = 9)
...
@@ -55,9 +47,7 @@ function timeout($timer = 9)
return
$key
;
return
$key
;
}
}
function
set_networking_interfaces_ports
(
$probe
=
false
)
function
set_networking_interfaces_ports
()
{
{
global
$config
;
global
$config
;
...
@@ -66,17 +56,22 @@ function set_networking_interfaces_ports()
...
@@ -66,17 +56,22 @@ function set_networking_interfaces_ports()
$interactive
=
true
;
$interactive
=
true
;
$key
=
null
;
$key
=
null
;
/* kernel messages clobber stty probing on ifconfig up */
mute_kernel_msgs
();
$iflist
=
get_interface_list
();
$iflist
=
get_interface_list
();
echo
PHP_EOL
.
gettext
(
'Press any key to start the manual interface assignment: '
);
if
(
$probe
)
{
echo
PHP_EOL
.
gettext
(
'Press any key to start the manual interface assignment: '
);
$key
=
timeout
(
7
);
$key
=
timeout
(
7
);
if
(
!
isset
(
$key
))
{
if
(
!
isset
(
$key
))
{
$interactive
=
false
;
$interactive
=
false
;
}
}
if
(
$key
!=
"
\n
"
)
{
if
(
$key
!=
"
\n
"
)
{
echo
PHP_EOL
;
echo
PHP_EOL
;
}
}
}
echo
<<<EOD
echo
<<<EOD
...
@@ -90,8 +85,8 @@ EOD;
...
@@ -90,8 +85,8 @@ EOD;
$iflist
=
array
();
$iflist
=
array
();
}
else
{
}
else
{
foreach
(
$iflist
as
$iface
=>
$ifa
)
{
foreach
(
$iflist
as
$iface
=>
$ifa
)
{
echo
sprintf
(
"% -7s%s %s %s
\n
"
,
$iface
,
$ifa
[
'mac'
],
interfaces_bring_up
(
$iface
);
$ifa
[
'up'
]
?
" (up)"
:
"(down)"
,
$ifa
[
'dmesg'
]);
echo
sprintf
(
"%-16s %s %s
\n
"
,
$iface
,
$ifa
[
'mac'
]
,
$ifa
[
'dmesg'
]);
}
}
}
}
...
@@ -149,6 +144,9 @@ EOD;
...
@@ -149,6 +144,9 @@ EOD;
if
(
$wanif
==
'a'
)
{
if
(
$wanif
==
'a'
)
{
$wanif
=
autodetect_interface
(
'WAN'
,
$fp
);
$wanif
=
autodetect_interface
(
'WAN'
,
$fp
);
if
(
!
$wanif
)
{
continue
;
}
}
}
if
(
!
array_key_exists
(
$wanif
,
$iflist
))
{
if
(
!
array_key_exists
(
$wanif
,
$iflist
))
{
...
@@ -176,6 +174,9 @@ EOD;
...
@@ -176,6 +174,9 @@ EOD;
if
(
$lanif
==
'a'
)
{
if
(
$lanif
==
'a'
)
{
$lanif
=
autodetect_interface
(
'LAN'
,
$fp
);
$lanif
=
autodetect_interface
(
'LAN'
,
$fp
);
if
(
!
$lanif
)
{
continue
;
}
}
}
if
(
!
array_key_exists
(
$lanif
,
$iflist
))
{
if
(
!
array_key_exists
(
$lanif
,
$iflist
))
{
...
@@ -227,7 +228,7 @@ EOD;
...
@@ -227,7 +228,7 @@ EOD;
}
}
if
(
$optif
[
$i
]
==
'a'
)
{
if
(
$optif
[
$i
]
==
'a'
)
{
$ad
=
autodetect_interface
(
gettext
(
"Optional"
)
.
" "
.
$io
,
$fp
);
$ad
=
autodetect_interface
(
'OPT'
.
$io
,
$fp
);
if
(
!
$ad
)
{
if
(
!
$ad
)
{
unset
(
$optif
[
$i
]);
unset
(
$optif
[
$i
]);
continue
;
continue
;
...
@@ -288,6 +289,8 @@ EOD;
...
@@ -288,6 +289,8 @@ EOD;
}
}
if
(
!
in_array
(
$key
,
array
(
'y'
,
'Y'
)))
{
if
(
!
in_array
(
$key
,
array
(
'y'
,
'Y'
)))
{
unmute_kernel_msgs
();
fclose
(
$fp
);
return
false
;
return
false
;
}
}
...
@@ -416,33 +419,36 @@ EOD;
...
@@ -416,33 +419,36 @@ EOD;
write_config
(
"Console assignment of interfaces"
);
write_config
(
"Console assignment of interfaces"
);
printf
(
gettext
(
"done.%s"
),
"
\n
"
);
printf
(
gettext
(
"done.%s"
),
"
\n
"
);
unmute_kernel_msgs
();
fclose
(
$fp
);
fclose
(
$fp
);
return
true
;
return
true
;
}
}
function
autodetect_interface
(
$
if
name
,
$fp
)
function
autodetect_interface
(
$name
,
$fp
)
{
{
$iflist_prev
=
get_interface_list
(
'media'
);
$iflist_prev
=
get_interface_list
(
true
);
echo
<<<EOD
echo
<<<EOD
Connect the {$
if
name} interface now and make sure that the link is up.
Connect the {$name} interface now and make sure that the link is up.
Then press ENTER to continue.
Then press ENTER to continue.
EOD;
EOD;
fgets
(
$fp
);
fgets
(
$fp
);
$iflist
=
get_interface_list
(
"media"
);
foreach
(
$iflist_prev
as
$ifn
=>
$ifa
)
{
$iflist
=
get_interface_list
(
true
);
if
(
!
$ifa
[
'up'
]
&&
$iflist
[
$ifn
][
'up'
])
{
printf
(
gettext
(
"Detected link-up on interface %s.%s"
),
$ifn
,
"
\n
"
);
foreach
(
$iflist
as
$ifn
=>
$ifa
)
{
if
(
!
isset
(
$iflist_prev
[
$ifn
]))
{
printf
(
gettext
(
"Detected link-up: %s%s"
),
$ifn
,
"
\n
"
);
return
$ifn
;
return
$ifn
;
}
}
}
}
printf
(
gettext
(
"No link-up detected.%s"
),
"
\n
"
);
printf
(
gettext
(
"No link-up detected.%s"
),
"
\n
"
);
return
null
;
return
false
;
}
}
function
vlan_setup
(
$iflist
,
$fp
)
function
vlan_setup
(
$iflist
,
$fp
)
...
...
src/etc/inc/util.inc
View file @
c85a9b0b
...
@@ -813,119 +813,93 @@ function get_configured_ipv6_addresses()
...
@@ -813,119 +813,93 @@ function get_configured_ipv6_addresses()
/*
/*
* get_interface_list() - Return a list of all physical interfaces
* get_interface_list() - Return a list of all physical interfaces
* along with MAC and status.
* along with MAC
, IPv4
and status.
*
*
* $mode = "active" - use ifconfig -lu
* $only_active = false -- interfaces that are available in the system
* "media" - use ifconfig to check physical connection
* true -- interfaces that are physically connected
* status (much slower)
*/
*/
function
get_interface_list
(
$mode
=
"active"
,
$keyby
=
"physical"
,
$vfaces
=
""
)
{
function
get_interface_list
(
$only_active
=
false
)
{
global
$config
;
global
$config
;
$upints
=
array
();
/* get a list of virtual interface types */
/* list of virtual interface types */
if
(
!
$vfaces
)
{
$vfaces
=
array
(
$vfaces
=
array
(
'_vlan'
,
'bridge'
,
'_wlan'
,
'ppp'
,
'bridge'
,
'pppoe'
,
'carp'
,
'pptp'
,
'enc'
,
'l2tp'
,
'faith'
,
'sl'
,
'gif'
,
'gif'
,
'gre'
,
'gre'
,
'ipfw'
,
'faith'
,
'l2tp'
,
'lo'
,
'lagg'
,
'ng'
,
'lo'
,
'_vlan'
,
'ng'
,
'_wlan'
,
'pflog'
,
'pflog'
,
'plip'
,
'plip'
,
'ppp'
,
'pfsync'
,
'pppoe'
,
'enc'
,
'pptp'
,
'tun'
,
'pfsync'
,
'carp'
,
'sl'
,
'lagg'
,
'tun'
,
'vip'
,
'vip'
'ipfw'
);
);
}
$ifnames_up
=
legacy_interface_listget
(
'up'
);
switch
(
$mode
)
{
$ifnames
=
legacy_interface_listget
();
case
'active'
:
$upints
=
legacy_interface_listget
(
'up'
);
if
(
$only_active
)
{
break
;
$_ifnames
=
array
();
case
'media'
:
$intlist
=
legacy_interface_listget
();
foreach
(
$ifnames
as
$ifname
)
{
$ifconfig
=
""
;
$ifinfo
=
legacy_interface_stats
(
$ifname
);
exec
(
"/sbin/ifconfig -a"
,
$ifconfig
);
if
(
isset
(
$ifinfo
[
'link state'
]))
{
$regexp
=
'/('
.
implode
(
'|'
,
$intlist
)
.
'):\s/'
;
if
(
$ifinfo
[
'link state'
]
==
'2'
)
{
$ifstatus
=
preg_grep
(
'/status:/'
,
$ifconfig
);
$_ifnames
[]
=
$ifname
;
foreach
(
$ifstatus
as
$status
)
{
}
$int
=
array_shift
(
$intlist
);
if
(
stristr
(
$status
,
'active'
))
{
$upints
[]
=
$int
;
}
}
}
}
break
;
default
:
$ifnames
=
$_ifnames
;
$upints
=
legacy_interface_listget
();
break
;
}
}
/* build interface list with netstat */
$linkinfo
=
""
;
exec
(
"/usr/bin/netstat -inW -f link | awk '{ print $1, $4 }'"
,
$linkinfo
);
array_shift
(
$linkinfo
);
/* build ip address list with netstat */
$ipinfo
=
""
;
exec
(
"/usr/bin/netstat -inW -f inet | awk '{ print $1, $4 }'"
,
$ipinfo
);
array_shift
(
$ipinfo
);
foreach
(
$linkinfo
as
$link
)
{
$friendly
=
""
;
$alink
=
explode
(
" "
,
$link
);
$ifname
=
rtrim
(
trim
(
$alink
[
0
]),
'*'
);
/* trim out all numbers before checking for vfaces */
if
(
!
in_array
(
array_shift
(
preg_split
(
'/\d/'
,
$ifname
)),
$vfaces
)
&&
!
stristr
(
$ifname
,
"_vlan"
)
&&
!
stristr
(
$ifname
,
"_wlan"
))
{
$toput
=
array
(
"mac"
=>
trim
(
$alink
[
1
]),
"up"
=>
in_array
(
$ifname
,
$upints
)
);
foreach
(
$ipinfo
as
$ip
)
{
$aip
=
explode
(
" "
,
$ip
);
if
(
$aip
[
0
]
==
$ifname
)
{
$toput
[
'ipaddr'
]
=
$aip
[
1
];
}
}
if
(
isset
(
$config
[
'interfaces'
]))
{
foreach
(
$config
[
'interfaces'
]
as
$name
=>
$int
)
{
if
(
$int
[
'if'
]
==
$ifname
)
$friendly
=
$name
;
}
}
switch
(
$keyby
)
{
case
"physical"
:
if
(
$friendly
!=
""
)
{
$toput
[
'friendly'
]
=
$friendly
;
}
$dmesg_arr
=
array
();
exec
(
"/sbin/dmesg |grep
$ifname
| head -n1"
,
$dmesg_arr
);
preg_match_all
(
"/<(.*?)>/i"
,
$dmesg_arr
[
0
],
$dmesg
);
if
(
isset
(
$dmesg
[
1
][
0
]))
{
$toput
[
'dmesg'
]
=
$dmesg
[
1
][
0
];
}
else
{
$toput
[
'dmesg'
]
=
null
;
}
$iflist
[
$ifname
]
=
$toput
;
break
;
case
"ppp"
:
case
"friendly"
:
foreach
(
$ifnames
as
$ifname
)
{
if
(
$friendly
!=
""
)
{
if
(
in_array
(
array_shift
(
preg_split
(
'/\d/'
,
$ifname
)),
$vfaces
))
{
$toput
[
'if'
]
=
$ifname
;
continue
;
$iflist
[
$friendly
]
=
$toput
;
}
$ifdata
=
pfSense_get_interface_addresses
(
$ifname
);
$toput
=
array
(
'up'
=>
in_array
(
$ifname
,
$ifnames_up
),
'ipaddr'
=>
$ifdata
[
'ipaddr'
],
'mac'
=>
$ifdata
[
'macaddr'
]
);
if
(
isset
(
$config
[
'interfaces'
]))
{
foreach
(
$config
[
'interfaces'
]
as
$name
=>
$int
)
{
if
(
$int
[
'if'
]
==
$ifname
)
{
$toput
[
'friendly'
]
=
$name
;
break
;
}
}
break
;
}
}
}
}
$dmesg_arr
=
array
();
exec
(
"/sbin/dmesg |grep
$ifname
| head -n1"
,
$dmesg_arr
);
preg_match_all
(
"/<(.*?)>/i"
,
$dmesg_arr
[
0
],
$dmesg
);
if
(
isset
(
$dmesg
[
1
][
0
]))
{
$toput
[
'dmesg'
]
=
$dmesg
[
1
][
0
];
}
else
{
$toput
[
'dmesg'
]
=
null
;
}
$iflist
[
$ifname
]
=
$toput
;
}
}
return
$iflist
;
return
$iflist
;
}
}
...
...
src/etc/rc.bootup
View file @
c85a9b0b
...
@@ -173,7 +173,7 @@ if (is_interface_mismatch()) {
...
@@ -173,7 +173,7 @@ if (is_interface_mismatch()) {
echo
PHP_EOL
.
gettext
(
'Default interfaces not found -- Running interface assignment option.'
)
.
PHP_EOL
;
echo
PHP_EOL
.
gettext
(
'Default interfaces not found -- Running interface assignment option.'
)
.
PHP_EOL
;
led_assigninterfaces
();
led_assigninterfaces
();
while
(
!
set_networking_interfaces_ports
());
while
(
!
set_networking_interfaces_ports
(
true
));
led_kitt
();
led_kitt
();
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment