41 lines
1.4 KiB
Plaintext
41 lines
1.4 KiB
Plaintext
/system/script remove [find name="bgp_lokal_export"]
|
|
|
|
/system/script add name=bgp_lokal_export dont-require-permissions=yes source={ \
|
|
:local startTime [/system clock get time];
|
|
:local startDate [/system clock get date];
|
|
:log info "BGP Export [$startDate $startTime]: mulai...";
|
|
|
|
# Clear existing address list
|
|
/ip firewall address-list remove [find list="bgp-export"];
|
|
|
|
:local cnt 0;
|
|
:local batchSize 100; # Process in batches to avoid memory issues
|
|
:local batchArray [:toarray ""];
|
|
|
|
# Single query for all relevant routes (distance=15 OR distance=200)
|
|
:foreach r in=[/routing/route find where (distance=15 or distance=200)] do={
|
|
:local dst [/routing/route get $r dst-address];
|
|
|
|
# Filter out default routes
|
|
:if ($dst != "0.0.0.0/0" && $dst != "::/0") do={
|
|
:set batchArray ($batchArray + $dst);
|
|
:set cnt ($cnt + 1);
|
|
|
|
# Process batch when size reached
|
|
:if ([:len $batchArray] >= $batchSize) do={
|
|
/ip firewall address-list add list="bgp-export" address=[:pick $batchArray 0 [:len $batchArray]];
|
|
:set batchArray [:toarray ""];
|
|
};
|
|
};
|
|
};
|
|
|
|
# Process remaining routes in final batch
|
|
:if ([:len $batchArray] > 0) do={
|
|
/ip firewall address-list add list="bgp-export" address=[:pick $batchArray 0 [:len $batchArray]];
|
|
};
|
|
|
|
:local endTime [/system clock get time];
|
|
:local endDate [/system clock get date];
|
|
:log info "BGP Export [$endDate $endTime]: selesai total $cnt rute"; \
|
|
}
|