Ipv6 address deprecation

Good idea! I took some time and made a version that requires a single script and no external file. It abuses the /ipv6 nd prefix table to remember the old prefixes (stored as disabled with the most significant bit flipped, which effectively puts the prefixes in the a000::/3 range).

Because the individual entries are stored separately, prefixes appearing/disappearing incrementially is supported.

The single script is called at the end of the DHCPv6 client script (so it will also be called at the right moment after boot), as well as by the scheduler.

:local FLIPMSB do={
    :local prefixLen [:pick $1 ([:find $1 "/" 0] + 1) [:len $1]];
    :local prefix [:toip6 [:pick $1 0 [:find $1 "/" 0]]];
    :return (($prefix ^ 8000::) . "/" . $prefixLen);
};

/ipv6 nd prefix;
:foreach entry in=[find comment="to-be-deprecated" prefix in a000::/3 !dynamic disabled] do={ 
    :local flipped [get number=$entry prefix];
    :local intf [get number=$entry interface];
    :local prfx [$FLIPMSB $flipped];

    :if ([:len [find prefix=$prfx interface=$intf]] <= 0) do={ 
        :log warning "Deprecating prefix $prfx on $intf...";
        set $entry comment="auto-deprecated" prefix=$prfx interface=$intf \
            preferred-lifetime=0s valid-lifetime=5m disabled=no;
    };
};

:foreach entry in=[find prefix in 2000::/3 dynamic] do={ 
    :local prfx [get number=$entry prefix];
    :local intf [get number=$entry interface];
    :local flipped [$FLIPMSB $prfx];

    :if ([:len [find prefix=$flipped interface=$intf]] <= 0) do={ 
        :log info "Remembering to be deprecated prefix $prfx on $intf...";
        add comment="to-be-deprecated" prefix=$flipped interface=$intf \
            preferred-lifetime=0s valid-lifetime=5m disabled=yes;
    };
};

:local toBeRemoved [find comment="auto-deprecated" \
    !dynamic !disabled prefix in 2000::/3 preferred-lifetime<00:00:01];

:if ([:len $toBeRemoved] > 0) do={
    :delay 15s;
    :log info "Removing deprecated prefixes...";
    remove $toBeRemoved;
};