X-Git-Url: http://git.ozlabs.org/?p=petitboot;a=blobdiff_plain;f=utils%2Fpb-udhcpc;h=4495266e4614ee31bd6cf3068acf15e591300b06;hp=bac16dad5dc322b8c20cd0008b9dd6fdcb7c1ebe;hb=1abc62990a5817de56a55470fb2c62e966134722;hpb=25e4608e9e4572b3a835f7c43a8ec9c77125f492 diff --git a/utils/pb-udhcpc b/utils/pb-udhcpc index bac16da..4495266 100644 --- a/utils/pb-udhcpc +++ b/utils/pb-udhcpc @@ -9,105 +9,56 @@ 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=$(cat /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 pxeconffile pxepathprefix 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 - if [ -n "${conffile}" ] + # Check if an explicit boot file present. If there is, add it as + # an option directly. + if [ -z "${bootfile}" ] then - url=$(resolve_url ${conffile}) - pb-event conf@${interface} url=$url method=dhcp - return + 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 - fi + paramstr="" - # 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 - k_server_ip=${rootpath%%:*} - k_root_dir=${rootpath#*:} + # Collect relevant parameters to add an option to the bootfile + # parameter + for name in rootpath siaddr bootfile mac + 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} name="netboot $interface ($bootfile)" \ + $paramstr } pb_remove () { - pb-event remove@${interface} name=netboot + mac=$(cat /sys/class/net/$interface/address) + pb-event remove@${interface} mac=$mac } case "$1" in -bound | renew) +bound) pb_add ;; deconfig)