I tried to write a script in which, I needed to get a local address of a dynamic interface like PPPoE but failed to do so.
Any help would be appreciated.
Something like this but I couldn’t find a way to make it work.
# get local-address of the dynamic interface.
:local locoIP [get [find where comment=$commentN] local-address]
Are we talking about a dynamic IP address or a dynamic interface (as in /interface pppoe server print)? I mean, if you don’t know the address but you do know the name of the interface, it is simply :local locoIP [/ip address get [find interface=the-interface-name] address], but if you don’t know the interface name and only have the user name from the /ppp secret, it is :local locoIP ([/interface sstp-server monitor [find user=kotel] once as-value]->“local-address”) because the interface name may be allocated statically so the may not always be true.
Hi,
Thank you, I tried to replicate it. It seems okay till the last section of the script
It looks like the problem starts from there or perhaps shows itself when I added the line.
;log info "IPIP Tunnel address start"
:local interfaceN PPPOE
:local commentN Name
:local locoIP [/ip address get [find interface=$interfaceN] address]
:local tunnelIP [/interface ipip get [find where comment=$commentN] local-address]
# It looks like the problem starts from here.
:if ($locoIP != $tunnelIP) do={
/interface ipip set $tunnelIP local-address=$locoIP
;log info "IP Tunnel address updated"
}
$tunnelIP is an IP address, so I’d assume you had in mind /interface ipip set [find where comment=$commentN] local-address=$locoIP ?
But normally this should not be necessary - if you do not specify local-address for an IPIP tunnel, it will choose the address of the output interface chosen by routing as the source one for the outgoing transport packets, and it will accept transport packets coming from the remote-address to any of its own addresses. A src-nat rule may break this, but a masquerade one should not as the connections are removed when the address they’ve got as reply-dst-address changes.
I.e. from my point of view, the challenge is not to track the WAN IP locally but to inform the remote party about its change if the remote party has multiple IPIP tunnels.
Getting the IP from /ip address will be in CIDR format (x.x.x.x/32 or x.x.x.x/24 or x.x.x.x/whatever) which I doubt it will match with whatever is in local-address of an IPIP tunnel which is just x.x.x.x.
Use the local-address from the pppoe-client as @sindy suggested above.
Any of these two lines should work in your script replacing your line.
:local locoIP ([/interface pppoe-client monitor [find name=$interfaceN] once as-value]->"local-address")
:local locoIP ([/interface pppoe-client monitor $interfaceN once as-value]->"local-address")
@Znevna
I settle down with Sindy’s suggestion that I don’t need it. Although I tried to work it out, I failed. I have to grasp a better understanding of syntax first.