Page 1 of 1

Are special parameters parsed when script ran by DHCP server?

Posted: Mon Mar 23, 2020 5:12 am
by millenium7
At the moment I have a 30 line script to ensure only 1 DHCP lease can be active per Remote-ID at a time, the newest lease clears all other entries that have the same Remote-ID (potential issue if a client plugged a switch into their WAN connection instead of a router) but there's currently a bug in the script. Rather than running through it again and trying to debug, the script could be very simple if certain parameters are parsed to it from the DHCP server

At the moment it iterates through every single lease, finds the newest, then purges all others
If parsed parameters can be used then instead I could do it all on 1 line with something like
/ip dhcp-server lease remove [find where remote-id=%8 active-mac-address!=%1]

Where %1 would be the MAC address of the lease that triggered the script, %8 would be the remote-id
Is this supported in the MikroTik world?

Re: Are special parameters parsed when script ran by DHCP server?

Posted: Wed Mar 25, 2020 12:16 am
by eworm
At the moment I have a 30 line script to ensure only 1 DHCP lease can be active per Remote-ID at a time, the newest lease clears all other entries that have the same Remote-ID (potential issue if a client plugged a switch into their WAN connection instead of a router) but there's currently a bug in the script. Rather than running through it again and trying to debug, the script could be very simple if certain parameters are parsed to it from the DHCP server

At the moment it iterates through every single lease, finds the newest, then purges all others
If parsed parameters can be used then instead I could do it all on 1 line with something like
/ip dhcp-server lease remove [find where remote-id=%8 active-mac-address!=%1]

Where %1 would be the MAC address of the lease that triggered the script, %8 would be the remote-id
Is this supported in the MikroTik world?
There is no property "remote-id". Does client's hostname do the job?
/ ip dhcp-server lease remove [ find where host-name=$"lease-hostname" active-mac-address!=$leaseActMAC ]
See Manual:IP/DHCP Server and search for "lease-script".

Re: Are special parameters parsed when script ran by DHCP server?

Posted: Wed Mar 25, 2020 1:14 am
by millenium7
err yes there is
agent-remote-id and agent-circuit-id are parameters that are injected into DHCP request packets by another inline device, also knows as DHCP Option 82
Both are supported in MikroTik's DHCP server as read-only parameters

Re: Are special parameters parsed when script ran by DHCP server?

Posted: Wed Mar 25, 2020 8:30 am
by eworm
Well, ok... Did not try to guess the correct name. Just "remote-id" is not available.

You can get that info from $"lease-options". With ($"lease-options"->"82") you get both infos from option 82, surrounded by some binary bits. Looks like you have to parse that yourself.