bird: add ta and mnt info to roa files and sha256 checksums

This commit is contained in:
netravnen 2020-01-08 19:30:17 +00:00 committed by Chriztoffer
parent 4865a85302
commit d67cd19794
3 changed files with 60 additions and 7 deletions

View file

@ -75,17 +75,22 @@ function writeBirdConfig ($roas)
foreach ($roas["roas"] as $roa)
{
$prfx = $roa["prefix"];
$mxLngth = $roa["maxLength"];
$sn = $roa["asn"];
$prefix = $roa["prefix"];
$maxLength = $roa["maxLength"];
$asn = $roa["asn"];
$source = $roa["ta"];
$mntby = $roa["mnt-by"];
$bird1_strng = "roa $prfx max $mxLngth as $sn;\n";
$bird2_strng = "route $prfx max $mxLngth as $sn;\n";
$bird_strng = "$prefix max $maxLength as $asn;";
$bird_strng .= " # $source/$mntby";
$bird1_strng = "roa $bird_strng\n";
$bird2_strng = "route $bird_strng\n";
fwrite ($bird1_fq, $bird1_strng);
fwrite ($bird2_fq, $bird2_strng);
if (strpos ($prfx, ":") !== false)
if (strpos ($prefix, ":") !== false)
{
fwrite ($bird1_fq6, $bird1_strng);
fwrite ($bird2_fq6, $bird2_strng);

View file

@ -48,6 +48,7 @@ foreach ($files6 as $file)
elseif (startsWith ($str, "source", 6)) $raw_array[$i]["source"] = $str;
elseif (startsWith ($str, "route6", 6)) $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;
// Catch max-length not set in route object.
if (empty ($raw_array[$i]["max"])) $raw_array[$i]["max"] = -1;
@ -79,6 +80,12 @@ foreach ($raw_array as $sub_array)
explode (":", $sub_array["max"])[1],
$maxlength);
// Extract mnt-by information
$mnt = array();
preg_match ("/([A-Z0-9\-]+)/",
explode (":", $sub_array["mnt"])[1],
$mnt);
// Store extracted values
$_prefix = $prefix[0];
$_ta = (isset ($source[0]) ? $source[0] : "");
@ -90,6 +97,8 @@ foreach ($raw_array as $sub_array)
// Do fallback to default prefix size if max-length was not set.
$_maxlength = ($prefix[2] < MAX_LEN_IPV6 ? MAX_LEN_IPV6 : $prefix[2]);
$_mnt = $mnt[0];
// Loop through each asn in single route6 object and assign
// other values accordingly.
foreach ($sub_array["asn"] as $asn)
@ -101,6 +110,7 @@ foreach ($raw_array as $sub_array)
$roas["roas"][$k]["prefix"] = $_prefix;
$roas["roas"][$k]["maxLength"] = ($_asn[0] != "AS0" ? $_maxlength : MAX_LEN_IPV6_AS0);
$roas["roas"][$k]["ta"] = $_ta;
$roas["roas"][$k]["mnt-by"] = $_mnt;
$k++;
}
@ -140,6 +150,7 @@ foreach ($files4 as $file)
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;
// Catch max-length not set in route object.
if (empty ($raw_array[$i]["max"])) $raw_array[$i]["max"] = -1;
@ -169,6 +180,12 @@ foreach ($raw_array as $sub_array)
explode (":", $sub_array["max"])[1],
$maxlength);
// Extract mnt-by information
$mnt = array();
preg_match ("/([A-Z0-9\-]+)/",
explode (":", $sub_array["mnt"])[1],
$mnt);
// Store extracted values
$_prefix = $prefix[0];
$_ta = (isset ($source[0]) ? $source[0] : "");
@ -180,6 +197,8 @@ foreach ($raw_array as $sub_array)
// Do fallback to default prefix size if max-length was not set.
$_maxlength = ($prefix[2] < MAX_LEN_IPV4 ? MAX_LEN_IPV4 : $prefix[2]);
$_mnt = $mnt[0];
// Loop through each asn in single route6 object and assign
// other values accordingly.
foreach ($sub_array["asn"] as $asn)
@ -191,11 +210,32 @@ foreach ($raw_array as $sub_array)
$roas["roas"][$k]["prefix"] = $_prefix;
$roas["roas"][$k]["maxLength"] = ($_asn[0] != "AS0" ? $_maxlength : MAX_LEN_IPV4_AS0);
$roas["roas"][$k]["ta"] = $_ta;
$roas["roas"][$k]["mnt-by"] = $_mnt;
$k++;
}
}
/*
* Function: Add metadata
*
* Add info
* 1. generation time (now),
* 2. expire time (now+7d),
* 3. number of routes
*/
$roaFileCreated = (int)( date_format( new \DateTime( "now", new \DateTimeZone( "UTC" ) ), "U" ) );
$roaFileExpire = (int)( date_format( date_modify( new \DateTime( "now", new \DateTimeZone( "UTC" ) ), "+3 day" ), "U" ) );
$roas["metadata"]["counts"] = (int)count($roas["roas"]);
$roas["metadata"]["generated"] = $roaFileCreated;
$roas["metadata"]["valid"] = $roaFileExpire;
/*
$roas["metadata"]["signature"] = "";
$roas["metadata"]["signatureData"] = "";
*/
writeExportJSON($roas);
writeBirdConfig($roas);

View file

@ -78,8 +78,16 @@ updates has been made to the [DN42 registry][1].
[5]: doc/crontab.md
" > roa/README.md
# computer checksums
for FILE in $(ls -1 roa/{bird*.conf,export*.json,README.md} | sed -e 's_roa/__g' | xargs) ; do
#md5sum roa/${FILE} > roa/${FILE}.md5
#sha1sum roa/${FILE} > roa/${FILE}.sha1
sha256sum roa/${FILE} > roa/${FILE}.sha256
#sha512sum roa/${FILE} > roa/${FILE}.sha512
done
# Commit latest version of ROA files
git -C roa/ add README.md *.conf *.json
git -C roa/ add README.md *.conf *.json *.sha256
git -C roa/ commit -m "Updated ROA files - $ISO_DATE" --quiet
# Push ROA repository to every remote configured