Commit 45282d84 authored by Adam Wujek's avatar Adam Wujek 💬

Merge branch 'adam-dhcp'

Add possibility to configure IP address of management port in dot-config.
Signed-off-by: Adam Wujek's avatarAdam Wujek <adam.wujek@cern.ch>
parents 1f2a404f e49a0c19
......@@ -35,6 +35,69 @@ config PPSI
menu "Local Network Configuration"
choice
prompt "Management port configuration (eth0)"
default ETH0_DHCP
config ETH0_DHCP
bool "DHCP forever"
help
Try DHCP on management port (eth0) forever.
config ETH0_DHCP_ONCE
bool "Try DHCP, if fail use static address"
help
Try DHCP on management port (eth0) for a while, then configure
static IP. Useful, when you move switch between various development
enviroments.
config ETH0_STATIC
bool "Static address"
help
Use static address on management port (eth0). Don't try to DHCP.
endchoice
menu "Management port (eth0) Address"
depends on ETH0_DHCP_ONCE || ETH0_STATIC
config ETH0_IP
string "Static IP address of management port (eth0)"
default "192.168.1.254"
help
Static IP address of management port (eth0). Please note that
wrong IP address will generate a runtime error on the switch.
config ETH0_MASK
string "Mask of management port (eth0)"
default "255.255.255.0"
help
Mask of management port (eth0). Please note that wrong mask will
generate a runtime error on the switch.
config ETH0_NETWORK
string "Network of management port (eth0)"
default "192.168.1.0"
help
Network of management port (eth0). Please note that wrong network
will generate a runtime error on the switch.
config ETH0_BROADCAST
string "Broadcast of management port (eth0)"
default "192.168.1.255"
help
Broadcast of management port (eth0). Please note that wrong broadcast
will generate a runtime error on the switch.
config ETH0_GATEWAY
string "Default gateway of management port (eth0)"
default "192.168.1.1"
help
Default gateway of management port (eth0). Please note that
wrong gateway address will generate a runtime error on the switch.
endmenu
config NTP_SERVER
string "IP address of local NTP server (empty for none)"
help
......
......@@ -431,6 +431,25 @@ value is changed by the web interface, proper action is taken.
the next time the system boots. See @ref{Dynamic WRS Configuration}
and @ref{The Configuration File} for details.
@item CONFIG_ETH0_DHCP
@itemx CONFIG_ETH0_DHCP_ONCE
@itemx CONFIG_ETH0_STATIC
Configuration of management port's (@t{eth0}) IP. When
@t{CONFIG_ETH0_DHCP} is used, then switch tries to obtain IP via DHCP
forever. For option @t{CONFIG_ETH0_DHCP_ONCE} switch tries to get IP
via DHCP once, if this try is unsuccessful then switch uses static IP.
@t{CONFIG_ETH0_STATIC} forces switch to use provided static IP address.
@item CONFIG_ETH0_IP
@itemx CONFIG_ETH0_MASK
@itemx CONFIG_ETH0_NETWORK
@itemx CONFIG_ETH0_BROADCAST
@itemx CONFIG_ETH0_GATEWAY
Management port's (@t{eth0}) static IP configuration when
@t{CONFIG_ETH0_DHCP_ONCE} or @t{CONFIG_ETH0_STATIC} parameter is used.
@item CONFIG_NTP_SERVER
The NTP server used to prime White Rabbit time, at system boot.
......
......@@ -33,6 +33,12 @@ if [ -n "$CONFIG_DOTCONF_URL" ]; then
# 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_DOTCONF_URL | \
sed -e s/MACADDR/$macaddr/ -e s/IPADDR/$ipaddr/)
# split the parts, as we need to handle tftp by hand
......
......@@ -3,15 +3,74 @@
# Start the network....
#
dotconfig=/wr/etc/dot-config
int_file=/etc/network/interfaces
# no matter what we do keep lo up
ifup lo &> /dev/null
if grep -q '/ nfs' /proc/mounts; then
echo "Running via NFS: leaving eth0 config alone"
exit 0
fi
if grep -v '#' /etc/network/interfaces | grep -q 'eth0.*dhcp'; then
# run dhcp client in background, as ifup would run in one-shot mode
udhcpc -b -i eth0
else
# read dot-config
if [ -f $dotconfig ]; then
. $dotconfig
fi
# kill all previous instances of udhcpc
killall udhcpc &> /dev/null
# put eth0 down in case it was up before
ifdown eth0 &> /dev/null
if [ "$CONFIG_ETH0_STATIC" ] || [ "$CONFIG_ETH0_DHCP_ONCE" ]; then
echo "Write IP address"
echo "# File generated from dot-config, do not edit!" > $int_file
echo "# Configure Loopback" >> $int_file
echo "auto lo" >> $int_file
echo "iface lo inet loopback" >> $int_file
echo "" >> $int_file
echo "iface eth0 inet static" >> $int_file
if [ "$CONFIG_ETH0_IP" ]; then
echo " address $CONFIG_ETH0_IP" >> $int_file
fi
if [ "$CONFIG_ETH0_MASK" ]; then
echo " netmask $CONFIG_ETH0_MASK" >> $int_file
fi
if [ "$CONFIG_ETH0_NETWORK" ]; then
echo " network $CONFIG_ETH0_NETWORK" >> $int_file
fi
if [ "$CONFIG_ETH0_BROADCAST" ]; then
echo " broadcast $CONFIG_ETH0_BROADCAST" >> $int_file
fi
if [ "$CONFIG_ETH0_GATEWAY" ]; then
echo " gateway $CONFIG_ETH0_GATEWAY" >> $int_file
fi
fi
if [ "$CONFIG_ETH0_DHCP_ONCE" ]; then
echo "Try DHCP to get IP"
# try dhcp, if fail use static IP
udhcpc -i eth0 -n
if [ $? -ne 0 ]; then
echo "Failed to obtain IP address via DHCP, set static IP"
CONFIG_ETH0_STATIC="y"
else
exit
fi
fi
if [ "$CONFIG_ETH0_STATIC" ]; then
# ifup to use static parameters from /etc/netwrok/interfaces
echo "Using static IP"
ifup eth0
exit
fi
# Try to get IP via dhcp if failed run dhcp client forever in background.
# If no information how to get IP address is available use this option.
echo "Using DHCP to get IP"
udhcpc -b -i eth0
# This file will be overwritten in run time by /etc/init.c/network
#
# Configure Loopback
auto lo
iface lo inet loopback
#Force eth0 to be configured by DHCP
auto eth0
iface eth0 inet dhcp
# Uncomment this example for static configuration
# iface eth0 inet static
# address 192.168.1.10
# netmask 255.255.255.0
# network 192.168.1.0
# broadcast 192.168.1.255
# gateway 192.168.1.1
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