iPXE discussion forum
IPXE LLDP and type casting - Printable Version

+- iPXE discussion forum (https://forum.ipxe.org)
+-- Forum: iPXE user forums (/forumdisplay.php?fid=1)
+--- Forum: General (/forumdisplay.php?fid=2)
+--- Thread: IPXE LLDP and type casting (/showthread.php?tid=18559)

IPXE LLDP and type casting - andreika - 2019-06-28 22:17

Hi Guys,
I have made sosme changes to support LLDP protocol in ipxe.

The code itself working as expected. But I can not make ipxe to set ip-address on interface. There is a mess with a type.

I have a string which is IP-address, and i want to set this ip on interface but for some reason can't.

Can you please help me with a type casting?



set intf netX
set timeout 60

set tab:int8 9
set src ${${intf}.lldp/lldpsource}
echo -- Waiting for an LLDP packet to arrive...
set count:int32 0
iseq ${${intf}.lldp/lldpsource} ${src} || goto mgmtaddr
sleep 1
inc count
iseq ${count} ${timeout} || goto retry_poll_lldp
clear count

# You may handle timeout here
echo -- Timed out waiting for an LLDP packet
exit 1


echo -- Got an LLDP packet from ${${intf}.lldp/lldpsource}
echo --

# Set the maximum length of portname like Gi1/0/34 = 8
set loop:int32 16
# Lets count the length on the string to find the right ofset number
  echo -- len of ${${intf}.lldp/2} now eq=${loop}
  inc loop -1
  isset ${${intf}.lldp/${loop}.1.0.2} || goto get_len_tlv2

  echo -- The length of porname ${${intf}.lldp/2} = ${loop}
  echo -- Let's get 1 or 2 digits right after the slash symbol
  # Let's identify how much symbols in portnumber
  # For exmple 34 = 2 symbols
  #             7 = 1 symbol
set num:int8 0
  inc loop -1
  inc num
  # Let's try to find the slash before the digits
  echo -- Is it slash with hex(2f): ${${intf}.lldp/${loop}.1.0.2:hex} = 2f on ${loop} position?
  iseq ${${intf}.lldp/${loop}.1.0.2:hex} 2f ||  goto right_position

  inc loop
  isset ${${intf}.lldp/${loop}.1.0.2} || goto exit_portnum
  set portnum ${portnum}${${intf}.lldp/${loop}.1.0.2}
  echo ${portnum}
  iseq num 0 || goto portnum

  echo -- Portnum : ${portnum}

set loop:int32 255
  echo -- len of ${${intf}.lldp/5} now eq=${loop}
  inc loop -1
  isset ${${intf}.lldp/${loop}.1.0.5} || goto get_len_tlv5

  echo -- The length of tlv5 ${${intf}.lldp/5} = ${loop}
  echo -- The l of tlv 5 ${${intf}.lldp/5:strlen}
  inc loop -19
  set ip_addr ${ip_addr}${${intf}.lldp/${loop}.3.0.5}
  inc loop 3
  set ip_addr ${ip_addr}.${${intf}.lldp/${loop}.3.0.5}
  inc loop 3
  set ip_addr ${ip_addr}.${${intf}.lldp/${loop}.3.0.5}
  set gw ${ip_addr}.1
  set ip_addr ${ip_addr}.0${portnum}
  echo ${loop}
  echo ${ip_addr}

  echo -- ip_addr = ${ip_addr}
  ifclose net0
  set net0/ip ${ip_addr}
  set net0/netmask
  set net0/gateway ${gw}
  ifopen net0

  ifstat net0

echo Starting Ubuntu x64 installer for ${hostname}
set base-url http://${gw}
kernel ${base-url}/linux
initrd ${base-url}/initrd.gz
boot ||

# If everything failed, give the user some options
echo Boot from ${base-url} failed
prompt --key 0x197e --timeout 2000 Press F12 to investigate || exit

RE: IPXE LLDP and type casting - cckp - 2019-07-03 00:59

count the length on the string to find the right ofset number?

so basically you invented two string manipulating methods: len(str) and substr(str)?

sounds good