summaryrefslogtreecommitdiffstats
path: root/utils
diff options
context:
space:
mode:
authorNeelesh Gupta <neelegup@linux.vnet.ibm.com>2013-10-28 12:45:21 +0530
committerJeremy Kerr <jk@ozlabs.org>2013-11-06 16:34:26 +0800
commitb8e53cb4b96eb17dc7fa0ffc505dfebae37e6cbf (patch)
tree2049ee274a9a7872366da8b95dbecaffc215df3a /utils
parentf385e8cacbc574e213b0805a8d383373f29a8058 (diff)
downloadpetitboot-b8e53cb4b96eb17dc7fa0ffc505dfebae37e6cbf.zip
petitboot-b8e53cb4b96eb17dc7fa0ffc505dfebae37e6cbf.tar.gz
discover: Change parsers to explicitly request configuration files
Add a new function parser_request_url() to read the data from configuration files present remotely. We deprecate iterate_parser_files() and download_config() functions along with the 'filenames' and 'method' members of the 'parser' structure so that individual parsers would now require to request the configuration files data from the parser code and doesn't necessarily export the list of configuration files. Add the support to handle incoming DHCP event, done by passing all the relevant environment variables of the udhcpc to the discover code. Also, update the pxe parser code to populate the list of configuration file names as per PXELINUX convention of fallback names using mac and ip addresses of the booting machine. Signed-off-by: Neelesh Gupta <neelegup@linux.vnet.ibm.com> Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Diffstat (limited to 'utils')
-rw-r--r--utils/pb-udhcpc103
1 files changed, 25 insertions, 78 deletions
diff --git a/utils/pb-udhcpc b/utils/pb-udhcpc
index dd291b9..3494985 100644
--- a/utils/pb-udhcpc
+++ b/utils/pb-udhcpc
@@ -9,97 +9,44 @@
PBOOT_USER_EVENT_SOCKET="/tmp/petitboot.ev"
log="/var/log/petitboot/pb-udhcpc.log"
-resolve_url() {
- file="$1"
-
- # URL? use as-is.
- tmp=${file%://*}
- if [ "$tmp" != "$file" ]
- then
- echo "$file"
- return
- fi
-
- # Otherwise, TFTP using an appropriate host. Start with the
- # DHCP 'tftp' option:
- host=${tftp}
-
- # next, try the DHCP next-server-address
- [ -z "$host" ] && host=${siaddr}
-
- # finally, use the DHCP server we got this lease from:
- [ -z "$host" ] && host=${serverid}
-
- echo "tftp://$host/$file"
-}
-
-do_pxe() {
- basedir=$1
-
- params="conf@${interface} method=dhcp"
+pb_add () {
+ # Looks like udhcpc will give us different names, depending if the
+ # parameter was in the header, or specified by options
+ [ -z "$bootfile" ] && bootfile=${boot_file}
- # first, try by MAC
- mac=$(tr ':' '-' < /sys/class/$interface/address)
- pb-event $params url=$basedir/01-$mac
+ mac=$(< /sys/class/net/$interface/address)
+ paramstr=''
- # try decreasing fragments of IP lease
- ip_hex=$(printf '%02X%02X%02X%02X' $(echo $ip | tr '.' ' '))
- for i in $(seq 8 -1 1)
+ # Collect relevant DHCP response parameters into $paramstr
+ for name in conffile bootfile mac ip siaddr serverid tftp
do
- frag=${ip_hex:0:$i}
- pb-event $params url=$basedir/$frag
- done
+ value=$(eval "echo \${$name}")
+ [ -n "$value" ] || continue;
- # last, use default
- pb-event $params url=$basedir/default
-}
+ paramstr="$paramstr $name=$value"
+ done
-pb_add () {
+ pb-event dhcp@{interface} $paramstr
- # Look for an explicit config file location in the DHCP config-file
- # parameter
+ # Check if an explicit config file present
if [ -n "${conffile}" ]
then
- url=$(resolve_url ${conffile})
- pb-event conf@${interface} url=$url method=dhcp
- return
- fi
-
- # Otherwise, we'll need the boot-file parameter. Looks like udhcpc
- # will give us different names, depending if the parameter was in
- # the header, or specified by options
- [ -z "$bootfile" ] && bootfile=${boot_file}
-
- if [ -z "$bootfile" ]
- then
- return
+ return;
fi
- # PXE behaviour is to download the config file based on a file
- # structure relative to the pxelinux binary
- file=${bootfile}
- [ -z "$file" ] && file=${boot_file}
- if [ -n "$file" ]
- then
- basedir=${file%%/*}
- do_pxe $basedir
- fi
+ # Finally, add an option for the boot_file parameter
+ paramstr='name=netboot'
- # Finally, add an option for the boot_file parameter
- k_server_ip=${rootpath%%:*}
- k_root_dir=${rootpath#*:}
+ # Collect relevant parameters to add an option to the boot_file parameter
+ for name in rootpath siaddr boot_file
+ do
+ value=$(eval "echo \${$name}")
+ [ -n "$value" ] || continue;
- args=
- if [ -n "$rootpath" ]
- then
- [ ${k_server_ip} != ${rootpath} ] || k_server_ip=${serverid}
- args="root=/dev/nfs ip=any nfsroot=${k_server_ip}:${k_root_dir}"
- fi
+ paramstr="$paramstr $name=$value"
+ done
- pb-event add@${interface} \
- name=netboot \
- image=tftp://${siaddr}/${boot_file} \
- args="$args"
+ pb-event add@{interface} $paramstr
}
pb_remove () {
OpenPOWER on IntegriCloud