Commit e8bc5a4f authored by Alessandro Rubini's avatar Alessandro Rubini

configuration: allow ppsi.conf to be downloaded at boot

The new Kconfig option allows dowloading ppsi.conf at boot time, from
TFTP or otherwise.  The filename in the URL can include IPADDR and/or
MACADDR, so the same configuration string can be used to set up a
batch of switches with different configurations.
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 7a42391f
......@@ -434,16 +434,38 @@ config PTP_PORT_PARAMS
CONFIG_PTP_CUSTOM_FILENAME, that you should copy to your switch.
config PTP_CUSTOM
bool "Custom ppsi.conf"
bool "Custom ppsi.conf in the WRS filesystem"
help
Use custom file for ppsi defined by CONFIG_PTP_CUSTOM_FILENAME.
config PTP_REMOTE_CONF
bool "Download ppsi.conf from the network at each boot"
help
This choice allows to specify an URL so you can download a
custom file using the network. This allows running a bunch
of switches, all with the same configuration but different
configuations that can't just be derived from PORT_PARAMS above.
endchoice
config PTP_CUSTOM_FILENAME
string "Pathname for your custom ppsi.conf"
depends on PTP_CUSTOM
default "/wr/etc/ppsi-custom.conf"
help
This is the filename used as ppsi.conf. Please note that the
file is copied to /wr/etc/ppsi.conf when configuration is applied,
and the PTP daemon always picks /wr/etc/ppsi.conf, not this
filename.
config PTP_CONF_URL
depends on PTP_REMOTE_CONF
string "Download URL (http, ftp, tftp) for custom ppsi.conf"
help
Like CONFIG_DOTCONF_URL, this option allows passing IPADDR
and MACADDR in the filename, and if a DNS server is configured,
you can use host names.
For example: tftp://morgana/wrs-IPADDR-ppsi.conf
menu "Management configuration"
......
......@@ -590,6 +590,7 @@ value is changed by the web interface, proper action is taken.
@item CONFIG_PTP_PORT_PARAMS
@itemx CONFIG_PTP_CUSTOM
@itemx CONFIG_PTP_REMOTE_CONF
By default, PPSi configuration file is assembled based on role and
protocol parameters stored in @t{PORTxx_PARAMS}. @t{TIME_BC} selected
......@@ -603,8 +604,17 @@ value is changed by the web interface, proper action is taken.
Alternatively PPSi can use custom user file for configuration
(@t{CONFIG_PTP_CUSTOM}).
Finally, you can choose @t{PTP_REMOTE_CONF} and be able to
specify an URL (@t{http://}, @t{ftp://} or @t{tftp://}) whence
the switch will download the @t{ppsi.conf} at boot time.
The filename in the URL can include @t{IPADDR} and/or @t{MACADDR},
so the same configuration string can be used to set up a batch
of switches with different configurations.
Please see the help provided within @i{Kconfig} for more details about
the various options we support.
@item CONFIG_PTP_CUSTOM_FILENAME
......@@ -613,6 +623,11 @@ value is changed by the web interface, proper action is taken.
the chosen name is expected to be installed in the @sc{wrs}
filesystem.
@item CONFIG_PTP_CONF_URL
If you choose @t{CONFIG_PTP_REMOTE_CONF} this is the URL
used to download @t{ppsi.conf} at each system boot.
@item CONFIG_SNMP_TRAPSINK_ADDRESS
@itemx CONFIG_SNMP_TRAP2SINK_ADDRESS
@itemx CONFIG_SNMP_RO_COMMUNITY
......
......@@ -95,6 +95,50 @@ if [ "$CONFIG_PTP_PORT_PARAMS" = "y" ]; then
/wr/bin/assembly_ppsi_conf.sh
elif [ "$CONFIG_PTP_CUSTOM" = "y" ]; then
cp "$CONFIG_PTP_CUSTOM_FILENAME" /wr/etc/ppsi.conf
elif [ "$CONFIG_PTP_REMOTE_CONF" = "y" ]; then
# Warning: code below copied from /etc/init.d/dot-config.
tmpconfig=/tmp/ppsi-config
# 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)
if [ -z "$ipaddr" ]; then
# if no IP address available from barebox try to get IP from old dot-config
# /etc/init.d/network will run later again
/etc/init.d/network
ipaddr=$(ifconfig eth0 | grep inet | cut -d: -f 2 | cut '-d ' -f 1)
fi
URL=$(echo $CONFIG_PTP_CONF_URL | \
sed -e s/MACADDR/$macaddr/ -e s/IPADDR/$ipaddr/)
# split the parts, as we need to handle tftp by hand
proto=$(echo $URL | cut -d: -f 1)
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
rm -f $tmpconfig
case $proto in
http|ftp)
wget $URL -O $tmpconfig
;;
tftp)
tftp -g -r "$filename" -l $tmpconfig $host
;;
*)
echo "Invalid URL for ppsi.conf: \"$URL\"" >& 2
;;
esac
if [ -f $tmpconfig ]; then
# copy it in place to use the new file (unless it is identical)
cmp -s $tmpconfig /wr/etc/ppsi.conf || \
cp $tmpconfig /wr/etc/ppsi.conf
fi
else
# no valid PTP option keep ppsi.conf with old postfix
echo "No valid PTP option in dot-config!"
......
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