2018-12-14 15:28:01 +00:00
|
|
|
<?php
|
|
|
|
|
2018-12-18 12:53:15 +00:00
|
|
|
// Load lib files.
|
2019-01-05 22:55:25 +00:00
|
|
|
require ("lib/constants.php");
|
2018-12-19 12:22:24 +00:00
|
|
|
require ("lib/define.php");
|
|
|
|
require ("lib/functions.php");
|
2018-12-14 15:28:01 +00:00
|
|
|
|
2020-02-07 19:42:07 +00:00
|
|
|
$roas["slurmVersion"] = 1;
|
2020-02-07 14:25:33 +00:00
|
|
|
|
2018-12-14 15:53:49 +00:00
|
|
|
$roas["validationOutputFilters"]["prefixFilters"] = array();
|
2020-01-28 19:56:14 +00:00
|
|
|
$roas["validationOutputFilters"]["bgpsecFilters"] = array();
|
2018-12-14 15:53:49 +00:00
|
|
|
$roas["locallyAddedAssertions"]["bgpsecAssertions"] = array();
|
2018-12-14 15:28:01 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* IPv6
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
$i = 0; // Counter used with tmp $raw_array.
|
|
|
|
$raw_array = array(); // tmp array() used for storing data to be processed
|
|
|
|
foreach ($files6 as $file)
|
|
|
|
{
|
|
|
|
$j = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* route6 with maxLength value set:
|
|
|
|
* - fd42:5d71:219::/48
|
2020-01-28 19:56:14 +00:00
|
|
|
*
|
2018-12-14 15:28:01 +00:00
|
|
|
* $ cat ../registry/data/route6/fd42:5d71:219::_48
|
|
|
|
* route6: fd42:5d71:219::/48
|
|
|
|
* origin: AS4242420119
|
|
|
|
* max-length: 48
|
|
|
|
* mnt-by: JRB0001-MNT
|
|
|
|
* source: DN42
|
|
|
|
*/
|
2020-01-28 19:56:14 +00:00
|
|
|
|
2018-12-14 15:28:01 +00:00
|
|
|
$data = file("../registry/data/route6/$file");
|
2020-01-28 19:56:14 +00:00
|
|
|
|
2018-12-14 15:28:01 +00:00
|
|
|
foreach ($data as $str)
|
|
|
|
{
|
|
|
|
$str = trim_special_chars ($str);
|
2020-01-28 19:56:14 +00:00
|
|
|
|
2018-12-14 16:05:07 +00:00
|
|
|
if (startsWith ($str, "max", 3)) $raw_array[$i]["max"] = $str;
|
|
|
|
elseif (startsWith ($str, "source", 6)) $raw_array[$i]["source"] = $str;
|
2018-12-19 14:04:52 +00:00
|
|
|
elseif (startsWith ($str, "route6", 6)) $raw_array[$i]["route"] = $str;
|
2018-12-14 16:05:07 +00:00
|
|
|
elseif (startsWith ($str, "origin", 6)) $raw_array[$i]["asn"][$j++] = $str;
|
|
|
|
elseif (startsWith ($str, "mnt", 3)) $raw_array[$i]["mnt"] = $str;
|
2020-01-28 19:56:14 +00:00
|
|
|
|
2018-12-14 15:28:01 +00:00
|
|
|
// Catch max-length not set in route object.
|
|
|
|
if (empty ($raw_array[$i]["max"])) $raw_array[$i]["max"] = -1;
|
|
|
|
}
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
$k = 0;
|
|
|
|
|
|
|
|
foreach ($raw_array as $sub_array)
|
|
|
|
{
|
|
|
|
// Extract prefix and subnet size
|
|
|
|
// Match prefix sizes 29-64, 80.
|
|
|
|
$prefix = array();
|
2018-12-14 16:05:07 +00:00
|
|
|
preg_match ("/([a-f0-9\:]{0,128})\/(29|[3-5][0-9]|6[0-4]|80)/",
|
|
|
|
explode ("6: ", $sub_array["route"])[1],
|
2018-12-14 15:28:01 +00:00
|
|
|
$prefix);
|
2020-01-28 19:56:14 +00:00
|
|
|
|
2018-12-14 15:28:01 +00:00
|
|
|
// Extract ta information
|
|
|
|
$source = array();
|
|
|
|
preg_match ("/([A-Z0-4]+)/",
|
2018-12-14 16:05:07 +00:00
|
|
|
explode (":", $sub_array["source"])[1],
|
2018-12-14 15:28:01 +00:00
|
|
|
$source);
|
2020-01-28 19:56:14 +00:00
|
|
|
|
2018-12-14 15:28:01 +00:00
|
|
|
// Try to extract max-length information
|
|
|
|
$maxlength = array();
|
|
|
|
if (($sub_array["max"]) != -1)
|
|
|
|
preg_match ("/([0-9]+)/",
|
2018-12-14 16:05:07 +00:00
|
|
|
explode (":", $sub_array["max"])[1],
|
2018-12-14 15:28:01 +00:00
|
|
|
$maxlength);
|
|
|
|
|
2018-12-14 16:05:07 +00:00
|
|
|
// Extract mnt-by information
|
|
|
|
$mnt = array();
|
|
|
|
preg_match ("/([A-Z0-9\-]+)/",
|
|
|
|
explode (":", $sub_array["mnt"])[1],
|
|
|
|
$mnt);
|
|
|
|
|
2018-12-14 15:28:01 +00:00
|
|
|
// Store extracted values
|
2018-12-14 16:05:07 +00:00
|
|
|
$_prefix = $prefix[0];
|
|
|
|
$_ta = (isset ($source[0]) ? $source[0] : "");
|
|
|
|
|
2018-12-14 15:28:01 +00:00
|
|
|
// We need to do conditional setting of maxLength to avoid errornous output.
|
|
|
|
if (($sub_array["max"]) != -1)
|
|
|
|
$_maxlength = (isset ($maxlength[0]) ? $maxlength[0] : "");
|
|
|
|
else
|
|
|
|
// Do fallback to default prefix size if max-length was not set.
|
2018-12-26 21:46:34 +00:00
|
|
|
$_maxlength = ($prefix[2] < MAX_LEN_IPV6 ? MAX_LEN_IPV6 : $prefix[2]);
|
2020-01-28 19:56:14 +00:00
|
|
|
|
2018-12-14 16:05:07 +00:00
|
|
|
$_mnt = $mnt[0];
|
|
|
|
|
2018-12-14 15:28:01 +00:00
|
|
|
// Loop through each asn in single route6 object and assign
|
|
|
|
// other values accordingly.
|
|
|
|
foreach ($sub_array["asn"] as $asn)
|
|
|
|
{
|
|
|
|
// Extract ASxxxxx from string.
|
|
|
|
preg_match ("/AS[0-9]+/", explode (":", $asn)[1], $_asn);
|
2020-01-28 19:56:14 +00:00
|
|
|
|
2018-12-17 17:37:09 +00:00
|
|
|
$roas["locallyAddedAssertions"]["prefixAssertions"][$k]["asn"] = trim ($_asn[0], "AS");
|
2018-12-14 15:28:01 +00:00
|
|
|
$roas["locallyAddedAssertions"]["prefixAssertions"][$k]["prefix"] = $_prefix;
|
2019-01-05 22:55:25 +00:00
|
|
|
$roas["locallyAddedAssertions"]["prefixAssertions"][$k]["maxPrefixLength"] = ($_asn[0] != "AS0" ? $_maxlength : MAX_LEN_IPV6_AS0);
|
2018-12-27 23:45:42 +00:00
|
|
|
$roas["locallyAddedAssertions"]["prefixAssertions"][$k]["source"] = "$_ta";
|
|
|
|
$roas["locallyAddedAssertions"]["prefixAssertions"][$k]["mnt-by"] = "$_mnt";
|
2018-12-14 16:05:07 +00:00
|
|
|
|
2018-12-14 15:28:01 +00:00
|
|
|
$k++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* IPv4
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
$i = 0; // Counter used with tmp $raw_array.
|
2020-01-28 19:56:14 +00:00
|
|
|
$raw_array = array(); // tmp array() used for storing data to be processed
|
2018-12-14 15:28:01 +00:00
|
|
|
foreach ($files4 as $file)
|
|
|
|
{
|
|
|
|
$j = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* route with maxLength value set:
|
|
|
|
* - 172.20.1.0/24
|
2020-01-28 19:56:14 +00:00
|
|
|
*
|
2018-12-14 15:28:01 +00:00
|
|
|
* $ cat ../registry/data/route/172.20.1.0_24
|
|
|
|
* route: 172.20.1.0/24
|
|
|
|
* origin: AS4242420119
|
|
|
|
* max-length: 24
|
|
|
|
* mnt-by: JRB0001-MNT
|
|
|
|
* source: DN42
|
|
|
|
*/
|
2020-01-28 19:56:14 +00:00
|
|
|
|
2018-12-14 15:28:01 +00:00
|
|
|
$data = file("../registry/data/route/$file");
|
2020-01-28 19:56:14 +00:00
|
|
|
|
2018-12-14 15:28:01 +00:00
|
|
|
foreach ($data as $str)
|
|
|
|
{
|
|
|
|
$str = trim_special_chars ($str);
|
2020-01-28 19:56:14 +00:00
|
|
|
|
2018-12-14 16:05:07 +00:00
|
|
|
if (startsWith ($str, "max", 3)) $raw_array[$i]["max"] = $str;
|
|
|
|
elseif (startsWith ($str, "source", 6)) $raw_array[$i]["source"] = $str;
|
|
|
|
elseif (startsWith ($str, "route", 5)) $raw_array[$i]["route"] = $str;
|
|
|
|
elseif (startsWith ($str, "origin", 6)) $raw_array[$i]["asn"][$j++] = $str;
|
|
|
|
elseif (startsWith ($str, "mnt", 3)) $raw_array[$i]["mnt"] = $str;
|
|
|
|
|
2018-12-14 15:28:01 +00:00
|
|
|
// Catch max-length not set in route object.
|
|
|
|
if (empty ($raw_array[$i]["max"])) $raw_array[$i]["max"] = -1;
|
|
|
|
}
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($raw_array as $sub_array)
|
|
|
|
{
|
|
|
|
// Extract prefix and subnet size
|
|
|
|
// Match prefix sizes 8-32.
|
|
|
|
$prefix = array();
|
2018-12-14 16:05:07 +00:00
|
|
|
preg_match ("/([0-9\.]{7,15})\/([8-9]|[1-2][0-9]|3[0-2])/",
|
|
|
|
explode (":", $sub_array["route"])[1],
|
2018-12-14 15:28:01 +00:00
|
|
|
$prefix);
|
2020-01-28 19:56:14 +00:00
|
|
|
|
2018-12-14 15:28:01 +00:00
|
|
|
// Extract ta information
|
|
|
|
$source = array();
|
|
|
|
preg_match ("/([A-Z0-4]+)/",
|
2018-12-14 16:05:07 +00:00
|
|
|
explode (":", $sub_array["source"])[1],
|
2018-12-14 15:28:01 +00:00
|
|
|
$source);
|
2020-01-28 19:56:14 +00:00
|
|
|
|
2018-12-14 15:28:01 +00:00
|
|
|
// Try to extract max-length information
|
|
|
|
$maxlength = array();
|
|
|
|
if (($sub_array["max"]) != -1)
|
|
|
|
preg_match ("/([0-9]+)/",
|
2018-12-14 16:05:07 +00:00
|
|
|
explode (":", $sub_array["max"])[1],
|
2018-12-14 15:28:01 +00:00
|
|
|
$maxlength);
|
|
|
|
|
2018-12-14 16:05:07 +00:00
|
|
|
// Extract mnt-by information
|
|
|
|
$mnt = array();
|
|
|
|
preg_match ("/([A-Z0-9\-]+)/",
|
|
|
|
explode (":", $sub_array["mnt"])[1],
|
|
|
|
$mnt);
|
|
|
|
|
2018-12-14 15:28:01 +00:00
|
|
|
// Store extracted values
|
2018-12-14 16:05:07 +00:00
|
|
|
$_prefix = $prefix[0];
|
|
|
|
$_ta = (isset ($source[0]) ? $source[0] : "");
|
|
|
|
|
2018-12-14 15:28:01 +00:00
|
|
|
// We need to do conditional setting of maxLength to avoid errornous output.
|
|
|
|
if (($sub_array["max"]) != -1)
|
|
|
|
$_maxlength = (isset ($maxlength[0]) ? $maxlength[0] : "");
|
|
|
|
else
|
|
|
|
// Do fallback to default prefix size if max-length was not set.
|
2018-12-26 21:46:34 +00:00
|
|
|
$_maxlength = ($prefix[2] < MAX_LEN_IPV4 ? MAX_LEN_IPV4 : $prefix[2]);
|
2018-12-14 16:05:07 +00:00
|
|
|
|
|
|
|
$_mnt = $mnt[0];
|
2020-01-28 19:56:14 +00:00
|
|
|
|
2018-12-14 15:28:01 +00:00
|
|
|
// Loop through each asn in single route6 object and assign
|
|
|
|
// other values accordingly.
|
|
|
|
foreach ($sub_array["asn"] as $asn)
|
|
|
|
{
|
|
|
|
// Extract ASxxxxx from string.
|
|
|
|
preg_match ("/AS[0-9]+/", explode (":", $asn)[1], $_asn);
|
2020-01-28 19:56:14 +00:00
|
|
|
|
2018-12-17 17:37:09 +00:00
|
|
|
$roas["locallyAddedAssertions"]["prefixAssertions"][$k]["asn"] = trim ($_asn[0], "AS");
|
2018-12-14 15:28:01 +00:00
|
|
|
$roas["locallyAddedAssertions"]["prefixAssertions"][$k]["prefix"] = $_prefix;
|
2019-01-05 22:55:25 +00:00
|
|
|
$roas["locallyAddedAssertions"]["prefixAssertions"][$k]["maxPrefixLength"] = ($_asn[0] != "AS0" ? $_maxlength : MAX_LEN_IPV4_AS0);
|
2018-12-27 23:45:42 +00:00
|
|
|
$roas["locallyAddedAssertions"]["prefixAssertions"][$k]["source"] = "$_ta";
|
|
|
|
$roas["locallyAddedAssertions"]["prefixAssertions"][$k]["mnt-by"] = "$_mnt";
|
2018-12-14 16:05:07 +00:00
|
|
|
|
2018-12-14 15:28:01 +00:00
|
|
|
$k++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-07 19:42:07 +00:00
|
|
|
/*
|
|
|
|
* Function: Add metadata
|
|
|
|
*
|
|
|
|
* Add info
|
|
|
|
* 1. generation time (now),
|
|
|
|
* 2. expire time (now + 3 days),
|
|
|
|
* 3. number of routes
|
|
|
|
*
|
|
|
|
* Numbers must be unquoted integers, and timeformat must
|
|
|
|
* be epoch format. TImezone is set to Etc/UTC.
|
|
|
|
*/
|
2020-02-26 22:59:17 +00:00
|
|
|
//$roas["metadata"]["counts"] = (int)count($roas["locallyAddedAssertions"]["prefixAssertions"]);
|
|
|
|
//$roas["metadata"]["generated"] = (int)(date_format(new \DateTime("now",new \DateTimeZone("UTC")),"U"));
|
|
|
|
//$roas["metadata"]["valid"] = (int)(date_format(date_modify(new \DateTime("now",new \DateTimeZone("UTC")),"+3day"),"U"));
|
2020-02-07 19:42:07 +00:00
|
|
|
|
2018-12-18 13:21:26 +00:00
|
|
|
writeRoutinatorExceptionFile($roas);
|
2018-12-14 15:28:01 +00:00
|
|
|
|
|
|
|
?>
|