From d67cd197941729e37b7b9dc238b2e3a8316ed00d Mon Sep 17 00:00:00 2001 From: Chriztoffer Date: Wed, 8 Jan 2020 19:30:17 +0000 Subject: [PATCH] bird: add ta and mnt info to roa files and sha256 checksums --- lib/functions.php | 17 +++++++++++------ roagen.php | 40 ++++++++++++++++++++++++++++++++++++++++ update.sh | 10 +++++++++- 3 files changed, 60 insertions(+), 7 deletions(-) diff --git a/lib/functions.php b/lib/functions.php index 4493e27..4b14d90 100755 --- a/lib/functions.php +++ b/lib/functions.php @@ -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); diff --git a/roagen.php b/roagen.php index e680c2b..be72ec7 100755 --- a/roagen.php +++ b/roagen.php @@ -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); diff --git a/update.sh b/update.sh index 6fb591e..58e6e09 100755 --- a/update.sh +++ b/update.sh @@ -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