Commit 6332840e authored by Adam Wujek's avatar Adam Wujek 💬

Merge branch 'adam-dhcp'

Support getting URL to dot-config via DHCP
parents 745f8d33 8723e45b
mainmenu "White Rabbit Switch configuration"
config DOTCONF_URL
choice DOTCONF_SOURCE
prompt "Source for a run-time replacement of dot-config"
default DOTCONF_SOURCE_TRY_DHCP
string "URL for a run-time replacement of dot-config"
config DOTCONF_SOURCE_LOCAL
bool "Use local dot-config"
help
The White Rabbit Switch is configured at run-time,
according to a dot-config .config file. The file
is the same .config you are defining now. If you
select an empty string, dot-config is not replaced
at run time. Otherwise, tftp://, ftp:// or http://
URLs are allowed. Names are allowed if you configured
a DNS server. The special strings IPADDR and MACADDR
are substituted before retrieving the file.
is the same .config you are defining now. If you
select this option, dot-config is not replaced
at run time.
config DOTCONF_SOURCE_REMOTE
bool "Use remote dot-config"
help
Use the URL to dot-config provided in DOTCONF_URL.
config DOTCONF_SOURCE_FORCE_DHCP
bool "Force to get the URL to a dot-config via DHCP"
help
Retrieve a URL to the dot-config via DHCP at boot.
The URL can be configured in the "filename" configuration field of
the DHCP server.
config DOTCONF_SOURCE_TRY_DHCP
bool "Try to get the URL to a dot-config via DHCP"
help
The same as DOTCONF_SOURCE_FORCE_DHCP, but this option does not
cause errors in SNMP's objects if the switch fails to retrieve
the URL to the dot-config via DHCP.
endchoice
config DOTCONF_URL
string "URL for a run-time replacement of dot-config"
depends on DOTCONF_SOURCE_REMOTE
help
tftp://, ftp:// or http:// URLs are allowed. Names are allowed if
you configured a DNS server. The special strings IPADDR and MACADDR
are substituted before retrieving the file.
Example: "tftp://morgana/wrs-config-IPADDR"
config BR2_CONFIGFILE
......
#
# Automatically generated make config: don't edit
#
CONFIG_DOTCONF_URL=""
# CONFIG_DOTCONF_SOURCE_LOCAL is not set
# CONFIG_DOTCONF_SOURCE_REMOTE is not set
# CONFIG_DOTCONF_SOURCE_FORCE_DHCP is not set
CONFIG_DOTCONF_SOURCE_TRY_DHCP=y
CONFIG_BR2_CONFIGFILE="wrs_release_br2_config"
CONFIG_PPSI=y
......
......@@ -336,7 +336,8 @@ configuration file each time it is booted, and applies the choices
before starting any service. The name of the configuration file can
include the @sc{mac} or @sc{ip} address of the device, to allow
running several switches with different configurations in the same
network.
network. The URL to the configuration file can also be retrieved from DHCP
server.
@c ==========================================================================
@node The Configuration File
......@@ -352,12 +353,39 @@ The configuration step creates @t{.config}, that you can copy to your
@sc{wrs} as @t{/wr/etc/dot-config}. After reboot, you'll see your
choices in effect.
The first configuration choice is @t{CONFIG_DOTCONF_URL}. If the
selected string is not empty, the Switch will download a new @t{dot-config}
file, and replace the copy in local storage if it is different. If
the string is empty, no network access is performed.
The first configuration choice is about source of the @t{dot-config} file
(items starting with @t{CONFIG_DOTCONF_SOURCE_}). The following @t{dot-config}
sources are implemented in current version:
@table @t
@item CONFIG_DOTCONF_SOURCE_LOCAL
Use local @t{dot-config} file stored in @t{/wr/etc/dot-config}.
In this case no network access is performed.
@item CONFIG_DOTCONF_SOURCE_REMOTE
Get a @t{dot-config} file from the URL provided in @t{CONFIG_DOTCONF_URL}.
@item CONFIG_DOTCONF_SOURCE_FORCE_DHCP
Get a URL to a @t{dot-config} file from a DHCP server.
The URL can be configured in the ``@t{filename}'' configuration field
of the DHCP server. The configured URL has to be in the same form as
@t{CONFIG_DOTCONF_URL}.
@item CONFIG_DOTCONF_SOURCE_TRY_DHCP
The same as @t{CONFIG_DOTCONF_SOURCE_FORCE_DHCP}, but this option does
not cause errors in SNMP's objects if the switch fails to retrieve the
URL to the @t{dot-config} via DHCP. Note that syntax and download
errors of @t{dot-config} are notified in the same way as for other
choices.
@end table
If the selected option triggers @sc{wrs} to download a new @t{dot-config}
file, it will replace the copy in the local storage if it is different.
@t{CONFIG_DOTCONF_URL} is of the form
The URL (stored in @t{CONFIG_DOTCONF_URL} or retrieved via DHCP) is of the form
``@i{protocol}@t{://}@i{host}@t{/}@i{pathname}''. The special upper-case
strings @t{IPADDR} and @t{MACADDR} are substituted with the current
addresses of the management port of the switch.
......@@ -388,6 +416,7 @@ The three parts of the URL are as follows:
For example this is a valid configuration for run-time update:
@smallexample
CONFIG_DOTCONF_SOURCE_REMOTE=y
CONFIG_DOTCONF_URL="tftp://morgana/wrs-config-IPADDR"
CONFIG_DNS_SERVER="192.168.16.1"
CONFIG_DNS_DOMAIN="i.gnudd.com"
......@@ -397,9 +426,10 @@ And it results, in my case, in @t{wrs-config-192.168.16.9} being
served to the @sc{wrs}.
Please remember that the new @t{dot-config} should include a valid
@t{DOTCONF_URL} setting, or you won't be able to update the configuration
at the next boot. In any case, you can always copy a configuration
file using @i{ssh}, or use the web interface to change the configuration.
@t{CONFIG_DOTCONF_SOURCE_*} setting, or you won't be able to update the
configuration at the next boot. In any case, you can always copy a
configuration file using @i{ssh}, or use the web interface to change the
configuration.
Changes performed using the web interface are immediately active, because
the web server takes proper action; the new file copied over with @i{ssh},
or any hand-edits, are only effective at next boot, unless overwritten by
......@@ -442,9 +472,13 @@ value is changed by the web interface, proper action is taken.
@table @code
@item CONFIG_DOTCONF_URL
@item CONFIG_DOTCONF_SOURCE_LOCAL
@itemx CONFIG_DOTCONF_SOURCE_REMOTE
@itemx CONFIG_DOTCONF_SOURCE_FORCE_DHCP
@itemx CONFIG_DOTCONF_SOURCE_TRY_DHCP
@itemx CONFIG_DOTCONF_URL
The location of a config file to be used at a replacement
The source and location of a config file to be used at a replacement
the next time the system boots. See @ref{Dynamic WRS Configuration}
and @ref{The Configuration File} for details.
......@@ -1477,9 +1511,8 @@ WR-SWITCH-MIB::wrsMainSystemStatus.0 = INTEGER: ok(1)
WR-SWITCH-MIB::wrsOSStatus.0 = INTEGER: ok(1)
WR-SWITCH-MIB::wrsTimingStatus.0 = INTEGER: ok(1)
[...]
WR-SWITCH-MIB::wrsConfigSource.0 = INTEGER: tftp(4)
WR-SWITCH-MIB::wrsConfigSourceHost.0 = STRING: 192.168.1.1
WR-SWITCH-MIB::wrsConfigSourceFilename.0 = STRING: config-192.168.1.10
WR-SWITCH-MIB::wrsConfigSource.0 = INTEGER: remote(4)
WR-SWITCH-MIB::wrsConfigSourceUrl.0 = STRING: tftp://192.168.1.1/config-192.168.1.10
WR-SWITCH-MIB::wrsBootConfigStatus.0 = INTEGER: ok(1)
WR-SWITCH-MIB::wrsBootHwinfoReadout.0 = INTEGER: ok(1)
WR-SWITCH-MIB::wrsBootLoadFPGA.0 = INTEGER: ok(1)
......
......@@ -510,8 +510,7 @@ between devices connected to the ports.\\
\texttt{WR-SWITCH-MIB::wrsRestartReason}\\
\texttt{WR-SWITCH-MIB::wrsRestartReasonMonit}\\
\texttt{WR-SWITCH-MIB::wrsConfigSource}\\
\texttt{WR-SWITCH-MIB::wrsConfigSourceHost}\\
\texttt{WR-SWITCH-MIB::wrsConfigSourceFilename}\\
\texttt{WR-SWITCH-MIB::wrsConfigSourceUrl}\\
\texttt{WR-SWITCH-MIB::wrsBootHwinfoReadout}\\
\texttt{WR-SWITCH-MIB::wrsBootLoadFPGA}\\
\texttt{WR-SWITCH-MIB::wrsBootLoadLM32}\\
......@@ -533,19 +532,21 @@ between devices connected to the ports.\\
\item [] \underline{Severity}: ERROR
\item [] \underline{Description}:\\
Dot-config file used to configure the switch can be stored locally or
retrieved from a central server. When it is fetch from the server it has
to be verified before being applied. If downloading or verification has
retrieved from a central server. Additionally URL to the remote dot-config
can be retrieved via DHCP request. When dot-config is fetch from the server
it has to be verified before being applied. If downloading or verification has
failed an alarm is raised.
\item [] \underline{SNMP objects}:\\
\texttt{WR-SWITCH-MIB::wrsBootSuccessful} - status word informing
whether switch booted correctly\\
\texttt{WR-SWITCH-MIB::wrsConfigSource} - source of a dot-config,
local or protocol which was used do fetch the dot-config\\
\texttt{WR-SWITCH-MIB::wrsConfigSourceHost} - address of a server
providing dot-config (if not local)\\
\texttt{WR-SWITCH-MIB::wrsConfigSourceFilename} - path to the dot-config
on a server (if not local)\\
\texttt{WR-SWITCH-MIB::wrsBootConfigStatus} - result of the dot-config verification
\texttt{WR-SWITCH-MIB::wrsBootSuccessful} -- status word informing
whether switch booted correctly\\
\texttt{WR-SWITCH-MIB::wrsConfigSource} -- source of a dot-config,
local, remote or get URL to the dot-config via DHCP. When
\texttt{wrsConfigSource} is set to the \texttt{tryDhcp}, then failure of
getting dot-config's URL via DHCP does not rise an error in
\texttt{wrsBootSuccessful}\\
\texttt{WR-SWITCH-MIB::wrsConfigSourceUrl} -- path to the dot-config
on a server (if not local)\\
\texttt{WR-SWITCH-MIB::wrsBootConfigStatus} -- result of the dot-config verification
\end{packed_enum}
\subsubsection{\bf Any userspace daemon has crashed/restarted}
......
......@@ -66,6 +66,7 @@ this section can have one of the following values:
\item \texttt{wrsBootSuccessful} -- Grouped status of
\texttt{wrsBootStatusGroup}, indicating whether boot was successful.
\texttt{Error} when dot-config source is wrong, unable to get the dot-config,
unable to get URL to the dot-config,
dot-config contains errors, unable to read the hwinfo, unable to load
the FPGA bitstream, unable to load the LM32 software, any kernel
modules or userspace daemons are missing (issue \ref{fail:other:boot},
......@@ -186,8 +187,9 @@ this section can have one of the following values:
\item \texttt{wrsFaultIP} -- Not implemented
\item \texttt{wrsFaultLR} -- Not implemented
\item \texttt{wrsConfigSource}
\item \texttt{wrsConfigSourceHost}
\item \texttt{wrsConfigSourceFilename}
\item \texttt{wrsConfigSourceUrl}
\item \texttt{wrsRestartReasonMonit} -- Process that caused \texttt{monit}
to trigger a restart.
\item \texttt{wrsBootConfigStatus}
%below boot status values
\item \texttt{wrsBootHwinfoReadout}
......@@ -200,8 +202,7 @@ this section can have one of the following values:
\item \texttt{wrsGwWatchdogTimeouts} -- Number of times the watchdog has
restarted the HDL module responsible for the Ethernet switching process
(issue \ref{fail:data:swcore_hang}).
\item \texttt{wrsRestartReasonMonit} -- Process that caused \texttt{monit}
to trigger a restart.
\end{itemize}
\item \texttt{wrsTemperatureGroup}
\begin{itemize}
......
......@@ -10,13 +10,14 @@ dotconfig=/wr/etc/dot-config
tmpconfig=/tmp/dot-config
tmpdir=/tmp
rm -f "$tmpdir"/dot-config_source
if [ -f $dotconfig ]; then
. $dotconfig
echo "local" > "$tmpdir"/dot-config_proto
#assume that local config is always ok
echo "config_ok" > "$tmpdir"/dot-config_status
else
echo "no_config" > "$tmpdir"/dot-config_proto
echo "no_config" > "$tmpdir"/dot-config_source
echo "config_error" > "$tmpdir"/dot-config_status
fi
......@@ -28,8 +29,42 @@ if [ ! -z "$CONFIG_DNS_SERVER" ]; then
fi
fi
# remove "$tmpdir"/dot-config_source_url" in case it is not first run
# of this script
rm -f "$tmpdir"/dot-config_source_url
# If we are expected to get a new dot-conf, do it
if [ -n "$CONFIG_DOTCONF_URL" ]; then
if [ -n "$CONFIG_DOTCONF_SOURCE_REMOTE" ] || [ -n "$CONFIG_DOTCONF_SOURCE_TRY_DHCP" ] \
|| [ -n "$CONFIG_DOTCONF_SOURCE_FORCE_DHCP" ]; then
echo "remote" > "$tmpdir"/dot-config_source
# get URL via DHCP
if [ -n "$CONFIG_DOTCONF_SOURCE_TRY_DHCP" ] \
|| [ -n "$CONFIG_DOTCONF_SOURCE_FORCE_DHCP" ]; then
if [ -n "$CONFIG_DOTCONF_SOURCE_TRY_DHCP" ]; then
echo "try_dhcp" > "$tmpdir"/dot-config_source
fi
if [ -n "$CONFIG_DOTCONF_SOURCE_FORCE_DHCP" ]; then
echo "force_dhcp" > "$tmpdir"/dot-config_source
fi
# let udhcpc run /wr/bin/dhcp_get_filename.sh script to get "filename"
# from DHCP (which contain url with dot-config).
/sbin/udhcpc -i eth0 -s /wr/bin/dhcp_get_filename.sh -O bootfile -o \
-n -q -f -t 5 &>/dev/null
if [ -f "$tmpdir"/dot-config_source_url ]; then
# replace CONFIG_DOTCONF_URL with one gotten from dhcp
CONFIG_DOTCONF_URL=`cat "$tmpdir"/dot-config_source_url`
echo "Got dot-config's URL ("$CONFIG_DOTCONF_URL") via DHCP"
else
echo "dhcp_error" > "$tmpdir"/dot-config_status
echo "Unable to get dot-config's URL via DHCP, using old dot-config"
# apply old dot-config
/wr/bin/apply_dot-config
exit
fi
fi
# replace IPADDR and MACADDR, to have a device-specific name
macaddr=$(cat /sys/class/net/eth0/address)
ipaddr=$(ifconfig eth0 | grep inet | cut -d: -f 2 | cut '-d ' -f 1)
......@@ -46,11 +81,8 @@ if [ -n "$CONFIG_DOTCONF_URL" ]; then
host=$(echo $URL | cut -d/ -f 3)
filename=$(echo $URL | cut -d/ -f 4-)
# save proto, host and filename of dot-config, to be used by SNMPd
echo "$proto" > "$tmpdir"/dot-config_proto
echo "$host" > "$tmpdir"/dot-config_host
echo "$filename" > "$tmpdir"/dot-config_filename
# save URL of dot-config, to be used by SNMPd
echo "$URL" > "$tmpdir"/dot-config_source_url
rm -f $tmpconfig
case $proto in
http|ftp)
......@@ -80,6 +112,11 @@ if [ -n "$CONFIG_DOTCONF_URL" ]; then
echo "download_error" > "$tmpdir"/dot-config_status
echo "Download error for dot-config \"$URL\", using old"
fi
elif [ -n "$DOTCONF_SOURCE_LOCAL" ]; then
echo "local" > "$tmpdir"/dot-config_source
echo "Using local dot-config"
else
echo "Unknown dot-config source. Using local dot-config"
fi
# Finally, apply what we have, be it old or new
......
......@@ -377,6 +377,21 @@ function wrs_interface_setup(){
else
return "dhcponly";
}
function wrs_dotconf_source_setup(){
if(!empty($_SESSION["KCONFIG"]["CONFIG_DOTCONF_SOURCE_LOCAL"]))
return "source_local";
else if (!empty($_SESSION["KCONFIG"]["CONFIG_DOTCONF_SOURCE_REMOTE"]))
return "source_remote";
else if (!empty($_SESSION["KCONFIG"]["CONFIG_DOTCONF_SOURCE_TRY_DHCP"]))
return "source_try_dhcp";
else if (!empty($_SESSION["KCONFIG"]["CONFIG_DOTCONF_SOURCE_FORCE_DHCP"]))
return "source_force_dhcp";
else
return "source_try_dhcp";
}
/*
* It checks whether the filesystem is writable or not.
*
......@@ -789,15 +804,7 @@ function wrs_management(){
sleep(2);
header('Location: management.php');
} else if (!strcmp($cmd, "kconfigURL")){
$_SESSION["KCONFIG"]["CONFIG_DOTCONF_URL"] = $_POST["dotconfigURL"];
save_kconfig();
apply_kconfig();
sleep(2);
wrs_reboot();
}
}
/**
......@@ -1003,9 +1010,16 @@ function wrs_display_help($help_id, $name){
$message = "<p>
Options: <br>
- <b>Reboot switch</b>: Reboots the switch.<br>
- <b>System Monitor</b>: Enable/Disable the monitor daemon.<br>
- <b>Load Configuration Files</b>: Load a backup dotconfig file to the WRS.<br>
- <b>Load Dotconfig from URL</b>: Set this field if you want to load dotconfig from an URL at boot stage.<br>
- <b>System Monitor</b>: Enable/Disable the monit daemon.<br>
- <b>Dot-config source during start</b>: Set the source of dot-config file at WRS startup. <br>
-- <b>Local</b>: The White Rabbit Switch is configured at run-time, according to a dot-config file stored locally.
If you select this option, dot-config is not replaced at run time.<br>
-- <b>Remote</b>: Use provided URL to the dot-config.<br>
-- <b>Force DHCP</b>: Retrieve a URL to the dot-config via DHCP at boot. The URL can be configured in the \"filename\"
configuration field of the DHCP server.<br>
-- <b>Try DHCP</b>: The same as Force DHCP, but this option does not cause errors in SNMP's objects if the switch
fails to retrieve the URL to the dot-config via DHCP.<br>
- <b>Load Configuration Files</b>: Upload a backup dotconfig file to the WRS and reboot.<br>
- <b>Backup Configuration Files</b>: Downloads a copy of dotconfig file, which contains all the setup of the WRS.<br>
</p>";
} else if (!strcmp($help_id, "ptp")){
......@@ -1113,12 +1127,19 @@ function wrs_display_help($help_id, $name){
$message = str_replace("\n", "<br>", $message);
} else if (!strcmp($help_id, "logs")){
$message = "<p>Log files for the following services: <br>
- <b>HAL daemon<br>
- <b>RTU daemon<br>
- <b>PPSi daemon<br>
- <b>WRS Watchdog status<br>
- <b>System Monitor<br>
- <b>SNMP service<br>
- <b>HAL daemon</b>, <b>RTU daemon</b>, <b>PPSi daemon</b>, <b>WRS Watchdog status</b> - The string can
be a pathname (e.g. /dev/kmsg) or a &lt;facility&gt;.&lt;level&gt; spefification like \"daemon.debug\".
An empty strings is used to represent no logging (like /dev/null). Please note that unknown facility
names will generate a runtime error on the switch.<br>
- <b>Monit</b> - The string can be a pathname (e.g. /dev/kmsg) or a \"syslog\" string. An empty strings
is used to represent no logging. If it is needed to select facility and level please leave here empty
string and change /etc/monitrc file directly. Please note that unknown facility names will generate a
runtime error on the switch.<br>
- <b>SNMP service</b> - The string can be a pathname (e.g. /dev/kmsg) or a valid snmpd log option (without -L).
\"sd\" or \"s daemon\" will forward messages to syslog with daemon as facility. To set level (i.e. 5) use
\"S 5 daemon\". For details please check \"man snmpcmd\". An empty strings is used to represent no
logging (like /dev/null). Please note that unknown facility names will generate a runtime error on the
switch.<br>
</p>";
}
......
......@@ -52,7 +52,56 @@
<hr>
<br><br>
<center><p><strong>Load configuration files</strong></p></center>
<center><p><strong>Dot-config source during start:</strong></p></center>
<?php
if((!empty($_POST["dotconfig_source"]))){
/* remove all possible sources from the file */
delete_from_kconfig("CONFIG_DOTCONF_SOURCE_LOCAL=");
delete_from_kconfig("CONFIG_DOTCONF_SOURCE_REMOTE=");
delete_from_kconfig("CONFIG_DOTCONF_SOURCE_TRY_DHCP=");
delete_from_kconfig("CONFIG_DOTCONF_SOURCE_FORCE_DHCP=");
delete_from_kconfig("CONFIG_DOTCONF_URL=");
/* remove all possible sources from the _SESSION */
$_SESSION["KCONFIG"]["CONFIG_DOTCONF_SOURCE_LOCAL"]="";
$_SESSION["KCONFIG"]["CONFIG_DOTCONF_SOURCE_REMOTE"]="";
$_SESSION["KCONFIG"]["CONFIG_DOTCONF_SOURCE_TRY_DHCP"]="";
$_SESSION["KCONFIG"]["CONFIG_DOTCONF_SOURCE_FORCE_DHCP"]="";
$_SESSION["KCONFIG"]["CONFIG_DOTCONF_URL"]="";
/* assembly new source name */
$new_dot_source = "CONFIG_DOTCONF_".$_POST["dotconfig_source"];
/* add new source to session and file */
$_SESSION["KCONFIG"][$new_dot_source]="y";
check_add_existing_kconfig($new_dot_source."=");
/* add URL for remote if source is remote */
if (!strcmp($_POST["dotconfig_source"], "SOURCE_REMOTE")) {
$_SESSION["KCONFIG"]["CONFIG_DOTCONF_URL"]=$_POST["dotconfig_URL"];
check_add_existing_kconfig("CONFIG_DOTCONF_URL=");
}
save_kconfig();
}
echo '<FORM method="POST">
<table id="daemon" border="0" align="center">
<tr>
<td>
<input type="radio" name="dotconfig_source" value="SOURCE_LOCAL"'; if(!strcmp(wrs_dotconf_source_setup(), "source_local")) echo "checked";
echo ' > Local <br>
<input type="radio" name="dotconfig_source" value="SOURCE_REMOTE"'; if(!strcmp(wrs_dotconf_source_setup(), "source_remote")) echo "checked";
echo ' > Remote
<INPUT type=text name="dotconfig_URL" size="25%" VALUE='; echo $_SESSION['KCONFIG']['CONFIG_DOTCONF_URL']; echo '><br>
<input type="radio" name="dotconfig_source" value="SOURCE_TRY_DHCP"'; if(!strcmp(wrs_dotconf_source_setup(), "source_try_dhcp")) echo "checked";
echo ' > Try DHCP <br>
<input type="radio" name="dotconfig_source" value="SOURCE_FORCE_DHCP"'; if(!strcmp(wrs_dotconf_source_setup(), "source_force_dhcp")) echo "checked";
echo ' > Force DHCP <br>
</td>
<td><INPUT type="submit" value="Change" class="btn"></td>
</tr>
</table>
</FORM>
<br>';
?>
<center><p><strong>Load dot-config from local computer</strong></p></center>
<table class='altrowstable' id='alternatecolor'>
<tr>
<FORM method="POST" ENCTYPE="multipart/form-data" onsubmit="return confirm('Are you sure you want to upload a dotconfig file? \nThis could result in the malfunction of the switch.');">
......@@ -60,14 +109,6 @@
<td><INPUT type=submit value="Load dot-config" class="btn" ><INPUT type=hidden name=MAX_FILE_SIZE VALUE= <?php wrs_php_filesize();?>000></td>
</form>
</tr>
<tr>
<FORM method="POST" onsubmit="return confirm('Are you sure you want to set an URL for dotconfig? \nThis could result in the malfunction of the switch.');">
<td align="center"><INPUT type=text name="dotconfigURL" size="35%" VALUE= <?php echo $_SESSION['KCONFIG']['CONFIG_DOTCONF_URL'];?>></td>
<input type="hidden" name="cmd" value="kconfigURL">
<td><INPUT type=submit value="Load from URL" class="btn" ></td>
</form>
</tr>
<tr>
</table>
</center>
......
......@@ -26,7 +26,7 @@ if [ "$1" == "local_config" ]; then
# remove source information in case previous config was received from
# network
rm /tmp/dot-config_*
echo "local" > /tmp/dot-config_proto
echo "local" > /tmp/dot-config_source
#assume that local config is always ok
echo "config_ok" > /tmp/dot-config_status
fi
......
#!/bin/sh
# Adam Wujek @ CERN
#
# This script is to be run by udhcpc
#
# udhcpc should save URL to the dot-config in boot_file.
# URL shall be stored in "filename" configuration field of DHCP server.
#
# We create a temporary file in /tmp, to avoid wearing flash if not
# needed. Then we replace the real file if different.
tmpdir="/tmp"
if [ -n "$boot_file" ]; then
echo $boot_file > "$tmpdir"/dot-config_source_url
fi
......@@ -579,32 +579,40 @@ wrsConfigSource OBJECT-TYPE
error(1),
errorMinor(2),
local(3),
tftp(4),
http(5),
ftp(6)
remote(4),
tryDhcp(5),
forceDhcp(6)
}
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"Source of used dotconfig, used protocol if config was received from
network
errorMinor - cannot read status file, problem is probably somewhere else"
"Source of used dotconfig
local - used dot-config was stored on the switch
remote - dot-config retrieved from the network check the
wrsConfigSourceUrl for the path
tryDhcp - try to get URL to the dot-config via DHCP, if DHCP retrieve
fail do not propagate error to the wrsBootSuccessful;
forceDhcp - get URL to the dot-config via DHCP, if failed propagate error
to the wrsBootSuccessful
errorMinor - cannot read the status file, problem is probably somewhere
else"
::= { wrsBootStatusGroup 6 }
wrsConfigSourceHost OBJECT-TYPE
wrsConfigSourceUrl OBJECT-TYPE
SYNTAX DisplayString (SIZE (0..64))
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"Server's address which provided dotconfig"
"Url to the dot-config"
::= { wrsBootStatusGroup 7 }
wrsConfigSourceFilename OBJECT-TYPE
SYNTAX DisplayString (SIZE (0..128))
MAX-ACCESS read-only
STATUS current
wrsRestartReasonMonit OBJECT-TYPE
SYNTAX DisplayString (SIZE (0..32))
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"Path and filename of dotconfig file on server"
"Program's name which caused the monit to restart the switch due to too
many crashes."
::= { wrsBootStatusGroup 8 }
wrsBootConfigStatus OBJECT-TYPE
......@@ -614,16 +622,18 @@ wrsBootConfigStatus OBJECT-TYPE
error(2),
downloadError(3),
checkError(4),
errorMinor(5)
errorMinor(5),
dhcpError(6)
}
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"Result of loading or downloading dot-config file
ok - dot-config downloaded or loaded correctly
downloadError - unable to download file from given source
downloadError - unable to download a file from a given source
checkError - config file is not valid or too short (less than 200 characters).
errorMinor - cannot read status file, problem is probably somewhere else"
errorMinor - cannot read the status file, problem is probably somewhere else
dhcpError - unable to get URL to dot-config via DHCP (only for forceDhcp)"
::= { wrsBootStatusGroup 9 }
wrsBootHwinfoReadout OBJECT-TYPE
......@@ -716,14 +726,6 @@ wrsGwWatchdogTimeouts OBJECT-TYPE
for the Ethernet switching process."
::= { wrsBootStatusGroup 15 }
wrsRestartReasonMonit OBJECT-TYPE
SYNTAX DisplayString (SIZE (0..32))
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"Program's name that monit failed to start several times"
::= { wrsBootStatusGroup 16 }
-- wrsTemperatureGroup (.7.1.3)
wrsTemperatureGroup OBJECT IDENTIFIER ::= { wrsOperationStatus 3 }
......
......@@ -6,9 +6,8 @@
#define MONIT_REASON_FILE "/tmp/monit_restart_reason"
#define DOTCONFIGDIR "/tmp"
#define DOTCONFIG_PROTO "dot-config_proto"
#define DOTCONFIG_HOST "dot-config_host"
#define DOTCONFIG_FILENAME "dot-config_filename"
#define DOTCONFIG_SOURCE "dot-config_source"
#define DOTCONFIG_SOURCE_URL "dot-config_source_url"
#define DOTCONFIG_STATUS "dot-config_status"
#define HWINFO_FILE "/tmp/hwinfo_read_status"
......@@ -38,8 +37,8 @@ static struct pickinfo wrsBootStatus_pickinfo[] = {
FIELD(wrsBootStatus_s, ASN_OCTET_STR, wrsFaultIP),
FIELD(wrsBootStatus_s, ASN_OCTET_STR, wrsFaultLR),
FIELD(wrsBootStatus_s, ASN_INTEGER, wrsConfigSource),
FIELD(wrsBootStatus_s, ASN_OCTET_STR, wrsConfigSourceHost),
FIELD(wrsBootStatus_s, ASN_OCTET_STR, wrsConfigSourceFilename),
FIELD(wrsBootStatus_s, ASN_OCTET_STR, wrsConfigSourceUrl),
FIELD(wrsBootStatus_s, ASN_OCTET_STR, wrsRestartReasonMonit),
FIELD(wrsBootStatus_s, ASN_INTEGER, wrsBootConfigStatus),
FIELD(wrsBootStatus_s, ASN_INTEGER, wrsBootHwinfoReadout),
FIELD(wrsBootStatus_s, ASN_INTEGER, wrsBootLoadFPGA),
......@@ -47,7 +46,6 @@ static struct pickinfo wrsBootStatus_pickinfo[] = {
FIELD(wrsBootStatus_s, ASN_INTEGER, wrsBootKernelModulesMissing),
FIELD(wrsBootStatus_s, ASN_INTEGER, wrsBootUserspaceDaemonsMissing),
FIELD(wrsBootStatus_s, ASN_COUNTER, wrsGwWatchdogTimeouts),
FIELD(wrsBootStatus_s, ASN_OCTET_STR, wrsRestartReasonMonit),
};
struct wrsBootStatus_s wrsBootStatus_s;
......@@ -174,7 +172,7 @@ static void get_boot_info(void){
* triggered by monit */
wrsBootStatus_s.wrsRestartReason = WRS_RESTART_REASON_MONIT;
/* try to get program that caused restart */
fscanf(f, LINE_READ_LEN(31),
fscanf(f, LINE_READ_LEN(WRS_RESTART_REASON_MONIT_LEN),
wrsBootStatus_s.wrsRestartReasonMonit);
fclose(f);
}
......@@ -188,63 +186,51 @@ static void get_dotconfig_source(void)
/* Check dotconfig source.
* dotconfig source can change in runtime, i.e. from remote to local by
* web-interface */
/* read protocol used to get dotconfig */
f = fopen(DOTCONFIGDIR "/" DOTCONFIG_PROTO, "r");
/* read source used to get dotconfig */
f = fopen(DOTCONFIGDIR "/" DOTCONFIG_SOURCE, "r");
if (f) {
/* readline without newline */
fscanf(f, LINE_READ_LEN(20), buff);
fclose(f);
if (!strncmp(buff, "tftp", 10))
if (!strncmp(buff, "remote", 10))
wrsBootStatus_s.wrsConfigSource =
WRS_CONFIG_SOURCE_PROTO_TFTP;
else if (!strncmp(buff, "http", 10))
WRS_CONFIG_SOURCE_REMOTE;
else if (!strncmp(buff, "try_dhcp", 10))
wrsBootStatus_s.wrsConfigSource =
WRS_CONFIG_SOURCE_PROTO_HTTP;
else if (!strncmp(buff, "ftp", 10))
WRS_CONFIG_SOURCE_TRY_DHCP;
else if (!strncmp(buff, "force_dhcp", 10))
wrsBootStatus_s.wrsConfigSource =
WRS_CONFIG_SOURCE_PROTO_FTP;
WRS_CONFIG_SOURCE_FORCE_DHCP;
else if (!strncmp(buff, "local", 10))
wrsBootStatus_s.wrsConfigSource =
WRS_CONFIG_SOURCE_PROTO_LOCAL;
else /* unknown proto */
WRS_CONFIG_SOURCE_LOCAL;
else /* unknown source */
wrsBootStatus_s.wrsConfigSource =
WRS_CONFIG_SOURCE_PROTO_ERROR;
WRS_CONFIG_SOURCE_ERROR;
} else {
/* proto file not found, probably something else caused
/* file with source not found, probably something else caused
* a problem */
wrsBootStatus_s.wrsConfigSource =
WRS_CONFIG_SOURCE_PROTO_ERROR_MINOR;
WRS_CONFIG_SOURCE_ERROR_MINOR;
}
/* read hostname and file name only when config is not local */
if (wrsBootStatus_s.wrsConfigSource != WRS_CONFIG_SOURCE_PROTO_LOCAL) {
/* read host used to get dotconfig */
f = fopen(DOTCONFIGDIR "/" DOTCONFIG_HOST, "r");
/* read dot-config's URL only when config source is not local */
if (wrsBootStatus_s.wrsConfigSource != WRS_CONFIG_SOURCE_LOCAL) {
/* read URL used to get dotconfig */
f = fopen(DOTCONFIGDIR "/" DOTCONFIG_SOURCE_URL, "r");
if (f) {
/* readline without newline */
fscanf(f, LINE_READ_LEN(WRS_CONFIG_SOURCE_HOST_LEN),
wrsBootStatus_s.wrsConfigSourceHost);
fscanf(f, LINE_READ_LEN(WRS_CONFIG_SOURCE_URL_LEN),
wrsBootStatus_s.wrsConfigSourceUrl);
fclose(f);
} else {
/* host file not found, put "error" into
* wrsConfigSourceHost */
strcpy(wrsBootStatus_s.wrsConfigSourceHost, "error");
}
/* read filename used to get dotconfig */
f = fopen(DOTCONFIGDIR "/" DOTCONFIG_FILENAME, "r");
if (f) {
/* readline without newline */
fscanf(f,
LINE_READ_LEN(WRS_CONFIG_SOURCE_FILENAME_LEN),
wrsBootStatus_s.wrsConfigSourceFilename);
fclose(f);
} else {
/* host file not found, put "error" into
* wrsConfigSourceFilename */
strcpy(wrsBootStatus_s.wrsConfigSourceFilename,
"error");
strcpy(wrsBootStatus_s.wrsConfigSourceUrl, "error");
}
} else {
memset(wrsBootStatus_s.wrsConfigSourceUrl, 0,
sizeof(wrsBootStatus_s.wrsConfigSourceUrl));
}
f = fopen(DOTCONFIGDIR "/" DOTCONFIG_STATUS, "r");
......@@ -261,6 +247,9 @@ static void get_dotconfig_source(void)
else if (!strncmp(buff, "download_error", 20))
wrsBootStatus_s.wrsBootConfigStatus =
WRS_CONFIG_STATUS_DL_ERROR;
else if (!strncmp(buff, "dhcp_error", 20))
wrsBootStatus_s.wrsBootConfigStatus =
WRS_CONFIG_STATUS_DHCP_ERROR;
else
wrsBootStatus_s.wrsBootConfigStatus =
WRS_CONFIG_STATUS_ERROR;
......
......@@ -4,24 +4,25 @@
#define WRSBOOTSTATUS_CACHE_TIMEOUT 5
#define WRSBOOTSTATUS_OID WRS_OID, 7, 1, 2
#define WRS_RESTART_REASON_MONIT_LEN 32
#define WRS_RESTART_REASON_ERROR 1 /* error */
#define WRS_RESTART_REASON_MONIT 7 /* ok */
#define WRS_CONFIG_SOURCE_HOST_LEN 64
#define WRS_CONFIG_SOURCE_FILENAME_LEN 128
#define WRS_CONFIG_SOURCE_PROTO_ERROR 1 /* error */
#define WRS_CONFIG_SOURCE_PROTO_ERROR_MINOR 2 /* warning */
#define WRS_CONFIG_SOURCE_PROTO_LOCAL 3 /* ok */
/* below proto are ok, if host and filename not empty */
#define WRS_CONFIG_SOURCE_PROTO_TFTP 4
#define WRS_CONFIG_SOURCE_PROTO_HTTP 5
#define WRS_CONFIG_SOURCE_PROTO_FTP 6
#define WRS_CONFIG_SOURCE_URL_LEN 128
#define WRS_CONFIG_SOURCE_ERROR 1 /* error */
#define WRS_CONFIG_SOURCE_ERROR_MINOR 2 /* warning */
#define WRS_CONFIG_SOURCE_LOCAL 3 /* ok */
#define WRS_CONFIG_SOURCE_REMOTE 4 /* ok */
#define WRS_CONFIG_SOURCE_TRY_DHCP 5 /* ok */
#define WRS_CONFIG_SOURCE_FORCE_DHCP 6 /* ok */
#define WRS_CONFIG_STATUS_OK 1 /* ok */
#define WRS_CONFIG_STATUS_ERROR 2 /* error */
#define WRS_CONFIG_STATUS_DL_ERROR 3 /* error */
#define WRS_CONFIG_STATUS_CHECK_ERROR 4 /* error */
#define WRS_CONFIG_STATUS_ERROR_MINOR 5 /* warning */
#define WRS_CONFIG_STATUS_DHCP_ERROR 6 /* ok, for try_dhcp,
* error for force_dhcp */
#define WRS_BOOT_HWINFO_OK 1 /* ok */
#define WRS_BOOT_HWINFO_ERROR 2 /* error */
......@@ -46,8 +47,8 @@ struct wrsBootStatus_s {
char wrsFaultIP[11]; /* faulty instruction pointer as string */
char wrsFaultLR[11]; /* link register at fault as string */
int32_t wrsConfigSource;
char wrsConfigSourceHost[WRS_CONFIG_SOURCE_HOST_LEN+1];
char wrsConfigSourceFilename[WRS_CONFIG_SOURCE_FILENAME_LEN+1];
char wrsConfigSourceUrl[WRS_CONFIG_SOURCE_URL_LEN+1];
char wrsRestartReasonMonit[WRS_RESTART_REASON_MONIT_LEN+1];
int32_t wrsBootConfigStatus;
int32_t wrsBootHwinfoReadout;
int32_t wrsBootLoadFPGA;
......@@ -55,7 +56,6 @@ struct wrsBootStatus_s {
int32_t wrsBootKernelModulesMissing;
int32_t wrsBootUserspaceDaemonsMissing;
int32_t wrsGwWatchdogTimeouts;
char wrsRestartReasonMonit[32];
};
extern struct wrsBootStatus_s wrsBootStatus_s;
......
......@@ -70,10 +70,13 @@ time_t wrsOSStatus_data_fill(void)
if ( /* check if error */
b->wrsBootCnt == 0
|| b->wrsRestartReason == WRS_RESTART_REASON_ERROR
|| b->wrsConfigSource == WRS_CONFIG_SOURCE_PROTO_ERROR
|| b->wrsConfigSource == WRS_CONFIG_SOURCE_ERROR
|| b->wrsBootConfigStatus == WRS_CONFIG_STATUS_ERROR
|| b->wrsBootConfigStatus == WRS_CONFIG_STATUS_DL_ERROR
|| b->wrsBootConfigStatus == WRS_CONFIG_STATUS_CHECK_ERROR
/* error only when dhcp failed for force_dhcp */
|| (b->wrsBootConfigStatus == WRS_CONFIG_STATUS_DHCP_ERROR
&& b->wrsConfigSource == WRS_CONFIG_SOURCE_FORCE_DHCP)
|| b->wrsBootHwinfoReadout == WRS_BOOT_HWINFO_ERROR
|| b->wrsBootLoadFPGA == WRS_BOOT_LOAD_FPGA_ERROR
|| b->wrsBootLoadFPGA == WRS_BOOT_LOAD_FPGA_FILE_NOT_FOUND
......@@ -85,7 +88,7 @@ time_t wrsOSStatus_data_fill(void)
wrsOSStatus_s.wrsBootSuccessful = WRS_BOOT_SUCCESSFUL_ERROR;
} else if ( /* check if warning */
b->wrsConfigSource == WRS_CONFIG_SOURCE_PROTO_ERROR_MINOR
b->wrsConfigSource == WRS_CONFIG_SOURCE_ERROR_MINOR
|| b->wrsBootConfigStatus == WRS_CONFIG_STATUS_ERROR_MINOR
|| b->wrsBootHwinfoReadout == WRS_BOOT_HWINFO_ERROR_MINOR
|| b->wrsBootHwinfoReadout == WRS_BOOT_HWINFO_WARNING
......@@ -107,9 +110,10 @@ time_t wrsOSStatus_data_fill(void)
} else if ( /* check if OK */
b->wrsBootCnt != 0
&& b->wrsRestartReason != WRS_RESTART_REASON_ERROR
&& b->wrsConfigSource != WRS_CONFIG_SOURCE_PROTO_ERROR
&& b->wrsConfigSource != WRS_CONFIG_SOURCE_PROTO_ERROR_MINOR /* warning */
&& b->wrsBootConfigStatus == WRS_CONFIG_STATUS_OK
&& b->wrsConfigSource != WRS_CONFIG_SOURCE_ERROR
&& b->wrsConfigSource != WRS_CONFIG_SOURCE_ERROR_MINOR /* warning */
&& (b->wrsBootConfigStatus == WRS_CONFIG_STATUS_OK
|| b->wrsConfigSource == WRS_CONFIG_SOURCE_TRY_DHCP)
&& b->wrsBootHwinfoReadout == WRS_BOOT_HWINFO_OK
&& b->wrsBootLoadFPGA == WRS_BOOT_LOAD_FPGA_OK
&& b->wrsBootLoadLM32 == WRS_BOOT_LOAD_LM32_OK
......@@ -118,20 +122,20 @@ time_t wrsOSStatus_data_fill(void)
) { /* OK, but check source */
/* additional check of source */
if (
b->wrsConfigSource == WRS_CONFIG_SOURCE_PROTO_LOCAL
b->wrsConfigSource == WRS_CONFIG_SOURCE_LOCAL
|| b->wrsConfigSource == WRS_CONFIG_SOURCE_TRY_DHCP
|| (
(
b->wrsConfigSource == WRS_CONFIG_SOURCE_PROTO_TFTP
|| b->wrsConfigSource == WRS_CONFIG_SOURCE_PROTO_HTTP
|| b->wrsConfigSource == WRS_CONFIG_SOURCE_PROTO_FTP
b->wrsConfigSource == WRS_CONFIG_SOURCE_REMOTE
|| b->wrsConfigSource == WRS_CONFIG_SOURCE_FORCE_DHCP
)
&& strnlen(b->wrsConfigSourceHost, WRS_CONFIG_SOURCE_HOST_LEN + 1)
&& strnlen(b->wrsConfigSourceFilename, WRS_CONFIG_SOURCE_FILENAME_LEN + 1)
&& strnlen(b->wrsConfigSourceUrl, WRS_CONFIG_SOURCE_URL_LEN + 1)
)
) { /* OK */
/* when dotconfig is local or (remote and host not empty and filename not empty) */
/* when dotconfig is local or try_dhcp or
* ((remote or force_dhcp) and url not empty) */
wrsOSStatus_s.wrsBootSuccessful = WRS_BOOT_SUCCESSFUL_OK;
} else { /* error because of source */
} else { /* error because of empty source url */
wrsOSStatus_s.wrsBootSuccessful = WRS_BOOT_SUCCESSFUL_ERROR;
}
} else { /* probably bug in previous conditions,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment