Skip to content

Commit

Permalink
Fix single IP protocol enabled IRRDB prefix generation - fixes #662
Browse files Browse the repository at this point in the history
  • Loading branch information
barryo committed Aug 11, 2020
1 parent 685c9cd commit ed45c9b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 32 deletions.
28 changes: 14 additions & 14 deletions app/Tasks/Irrdb/UpdateAsnDb.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ class UpdateAsnDb extends UpdateDb
*/
public function update(): array
{
if( $this->customer()->isRouteServerClient() && $this->customer()->isIrrdbFiltered() ) {
$this->bgpq3()->setSources( $this->customer()->getIRRDB()->getSource() );
foreach( $this->protocols() as $protocol ) {

if( $this->customer()->isRouteServerClient($protocol) && $this->customer()->isIrrdbFiltered() ) {
$this->bgpq3()->setSources( $this->customer()->getIRRDB()->getSource() );

foreach( $this->protocols() as $protocol ) {
$this->startTimer();
$asns = $this->bgpq3()->getAsnList( $this->customer()->resolveAsMacro( $protocol, 'as' ), $protocol );
$this->result[ 'netTime' ] += $this->timeElapsed();
Expand All @@ -59,18 +60,17 @@ public function update(): array
if( $this->updateDb( $asns, $protocol, 'asn' ) ) {
$this->result[ 'v' . $protocol ][ 'dbUpdated' ] = true;
}
} else {
// This customer is not appropriate for IRRDB filtering.
// Delete any pre-existing entries just in case this has changed recently:
$this->startTimer();
D2EM::getConnection()->executeUpdate(
"DELETE FROM `irrdb_asn` WHERE customer_id = ? AND protocol = ?", [ $this->customer()->getId(), $protocol ]
);
$this->result[ 'dbTime' ] += $this->timeElapsed();
$this->result[ 'v' . $protocol ][ 'dbUpdated' ] = true;
$this->result[ 'msg' ] = "Customer not a RS client or IRRDB filtered for IPv{$protocol}. IPv{$protocol} ASNs, if any, wiped from database.";
}
} else {
// This customer is not appropriate for IRRDB filtering.
// Delete any pre-existing entries just in case this has changed recently:
$this->startTimer();
D2EM::getConnection()->executeUpdate(
"DELETE FROM `irrdb_asn` WHERE customer_id = ?", [ $this->customer()->getId() ]
);
$this->result[ 'dbTime' ] += $this->timeElapsed();
$this->result[ 'v4' ][ 'dbUpdated' ] = true;
$this->result[ 'v6' ][ 'dbUpdated' ] = true;
$this->result[ 'msg' ] = "Customer not a RS client or IRRDB filtered. ASNs, if any, wiped from database.";
}

return $this->result;
Expand Down
36 changes: 18 additions & 18 deletions app/Tasks/Irrdb/UpdatePrefixDb.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,31 +47,31 @@ class UpdatePrefixDb extends UpdateDb
* @return array
*/
public function update(): array {
if( $this->customer()->isRouteServerClient() && $this->customer()->isIrrdbFiltered() ) {
$this->bgpq3()->setSources($this->customer()->getIRRDB()->getSource());

foreach( $this->protocols() as $protocol ) {
foreach( $this->protocols() as $protocol ) {
if( $this->customer()->isRouteServerClient( $protocol ) && $this->customer()->isIrrdbFiltered() ) {
$this->bgpq3()->setSources( $this->customer()->getIRRDB()->getSource() );

$this->startTimer();
$prefixes = $this->bgpq3()->getPrefixList($this->customer()->resolveAsMacro($protocol, 'as'), $protocol);
$this->result['netTime'] += $this->timeElapsed();
$prefixes = $this->bgpq3()->getPrefixList( $this->customer()->resolveAsMacro( $protocol, 'as' ), $protocol );
$this->result[ 'netTime' ] += $this->timeElapsed();

$this->result['v' . $protocol]['count'] = count($prefixes);
$this->result[ 'v' . $protocol ][ 'count' ] = count( $prefixes );

if( $this->updateDb( $prefixes, $protocol, 'prefix' ) ) {
$this->result['v' . $protocol]['dbUpdated'] = true;
$this->result[ 'v' . $protocol ][ 'dbUpdated' ] = true;
}
} else {
// This customer is not appropriate for IRRDB filtering.
// Delete any pre-existing entries just in case this has changed recently:
$this->startTimer();
D2EM::getConnection()->executeUpdate(
"DELETE FROM `irrdb_prefix` WHERE customer_id = ? AND protocol = ?", [ $this->customer()->getId(), $protocol ]
);
$this->result[ 'dbTime' ] += $this->timeElapsed();
$this->result[ 'v' . $protocol ][ 'dbUpdated' ] = true;
$this->result[ 'msg' ] = "Customer not a RS client or IRRDB filtered for IPv{$protocol}. IPv{$protocol} prefixes, if any, wiped from database.";
}
} else {
// This customer is not appropriate for IRRDB filtering.
// Delete any pre-existing entries just in case this has changed recently:
$this->startTimer();
D2EM::getConnection()->executeUpdate(
"DELETE FROM `irrdb_prefix` WHERE customer_id = ?", [ $this->customer()->getId() ]
);
$this->result['dbTime'] += $this->timeElapsed();
$this->result['v4']['dbUpdated'] = true;
$this->result['v6']['dbUpdated'] = true;
$this->result['msg'] = "Customer not a RS client or IRRDB filtered. Prefixes, if any, wiped from database.";
}

return $this->result;
Expand Down

0 comments on commit ed45c9b

Please sign in to comment.