mirror of
https://github.com/fosrl/pangolin.git
synced 2026-01-28 22:00:51 +00:00
Fix removing remote subnet on remove site resource
This commit is contained in:
@@ -701,11 +701,45 @@ async function handleSubnetProxyTargetUpdates(
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (const client of removedClients) {
|
for (const client of removedClients) {
|
||||||
|
// Check if this client still has access to another resource on this site with the same destination
|
||||||
|
const destinationStillInUse = await trx
|
||||||
|
.select()
|
||||||
|
.from(siteResources)
|
||||||
|
.innerJoin(
|
||||||
|
clientSiteResourcesAssociationsCache,
|
||||||
|
eq(
|
||||||
|
clientSiteResourcesAssociationsCache.siteResourceId,
|
||||||
|
siteResources.siteResourceId
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.where(
|
||||||
|
and(
|
||||||
|
eq(
|
||||||
|
clientSiteResourcesAssociationsCache.clientId,
|
||||||
|
client.clientId
|
||||||
|
),
|
||||||
|
eq(siteResources.siteId, siteResource.siteId),
|
||||||
|
eq(
|
||||||
|
siteResources.destination,
|
||||||
|
siteResource.destination
|
||||||
|
),
|
||||||
|
ne(
|
||||||
|
siteResources.siteResourceId,
|
||||||
|
siteResource.siteResourceId
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Only remove remote subnet if no other resource uses the same destination
|
||||||
|
const remoteSubnetsToRemove = destinationStillInUse.length > 0
|
||||||
|
? []
|
||||||
|
: generateRemoteSubnets([siteResource]);
|
||||||
|
|
||||||
olmJobs.push(
|
olmJobs.push(
|
||||||
removePeerData(
|
removePeerData(
|
||||||
client.clientId,
|
client.clientId,
|
||||||
siteResource.siteId,
|
siteResource.siteId,
|
||||||
generateRemoteSubnets([siteResource]),
|
remoteSubnetsToRemove,
|
||||||
generateAliasConfig([siteResource])
|
generateAliasConfig([siteResource])
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@@ -1213,12 +1247,46 @@ async function handleMessagesForClientResources(
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// Check if this client still has access to another resource on this site with the same destination
|
||||||
|
const destinationStillInUse = await trx
|
||||||
|
.select()
|
||||||
|
.from(siteResources)
|
||||||
|
.innerJoin(
|
||||||
|
clientSiteResourcesAssociationsCache,
|
||||||
|
eq(
|
||||||
|
clientSiteResourcesAssociationsCache.siteResourceId,
|
||||||
|
siteResources.siteResourceId
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.where(
|
||||||
|
and(
|
||||||
|
eq(
|
||||||
|
clientSiteResourcesAssociationsCache.clientId,
|
||||||
|
client.clientId
|
||||||
|
),
|
||||||
|
eq(siteResources.siteId, resource.siteId),
|
||||||
|
eq(
|
||||||
|
siteResources.destination,
|
||||||
|
resource.destination
|
||||||
|
),
|
||||||
|
ne(
|
||||||
|
siteResources.siteResourceId,
|
||||||
|
resource.siteResourceId
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Only remove remote subnet if no other resource uses the same destination
|
||||||
|
const remoteSubnetsToRemove = destinationStillInUse.length > 0
|
||||||
|
? []
|
||||||
|
: generateRemoteSubnets([resource]);
|
||||||
|
|
||||||
// Remove peer data from olm
|
// Remove peer data from olm
|
||||||
olmJobs.push(
|
olmJobs.push(
|
||||||
removePeerData(
|
removePeerData(
|
||||||
client.clientId,
|
client.clientId,
|
||||||
resource.siteId,
|
resource.siteId,
|
||||||
generateRemoteSubnets([resource]),
|
remoteSubnetsToRemove,
|
||||||
generateAliasConfig([resource])
|
generateAliasConfig([resource])
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { sendToClient } from "#dynamic/routers/ws";
|
import { sendToClient } from "#dynamic/routers/ws";
|
||||||
import { db, olms } from "@server/db";
|
import { db, olms, Transaction } from "@server/db";
|
||||||
import { Alias, SubnetProxyTarget } from "@server/lib/ip";
|
import { Alias, SubnetProxyTarget } from "@server/lib/ip";
|
||||||
import logger from "@server/logger";
|
import logger from "@server/logger";
|
||||||
import { eq } from "drizzle-orm";
|
import { eq } from "drizzle-orm";
|
||||||
|
|||||||
Reference in New Issue
Block a user