diff --git a/server/routers/newt/error.ts b/server/routers/newt/error.ts new file mode 100644 index 000000000..d2ab8937c --- /dev/null +++ b/server/routers/newt/error.ts @@ -0,0 +1,24 @@ +import { sendToClient } from "#dynamic/routers/ws"; + +// Error codes for registration failures +export const NewtErrorCodes = { + NO_AVAILABLE_SUBNET: { + code: "NO_AVAILABLE_SUBNET", + message: + "No available subnet could be assigned to this site on its exit node. Please contact your administrator to increase the available address space for this exit node's subnet." + } +} as const; + +// Helper function to send registration error +export async function sendNewtError( + error: (typeof NewtErrorCodes)[keyof typeof NewtErrorCodes], + newtId: string +) { + sendToClient(newtId, { + type: "newt/error", + data: { + code: error.code, + message: error.message + } + }); +} diff --git a/server/routers/newt/handleNewtRegisterMessage.ts b/server/routers/newt/handleNewtRegisterMessage.ts index 7adc74a1b..43dee26f5 100644 --- a/server/routers/newt/handleNewtRegisterMessage.ts +++ b/server/routers/newt/handleNewtRegisterMessage.ts @@ -14,6 +14,7 @@ import { getUniqueSubnetForExitNode } from "@server/lib/exitNodes"; import { fetchContainers } from "./dockerSocket"; import { buildTargetConfigurationForNewtClient } from "./buildConfiguration"; import { canCompress } from "@server/lib/clientVersionChecks"; +import { NewtErrorCodes, sendNewtError } from "./error"; export const handleNewtRegisterMessage: MessageHandler = async (context) => { const { message, client, sendToClient } = context; @@ -116,6 +117,7 @@ export const handleNewtRegisterMessage: MessageHandler = async (context) => { logger.error( `No available subnets found for the new exit node id ${exitNodeId} and site id ${siteId}` ); + sendNewtError(NewtErrorCodes.NO_AVAILABLE_SUBNET, newt.newtId); return; } diff --git a/server/routers/olm/error.ts b/server/routers/olm/error.ts index d9058a3f6..b0fd90993 100644 --- a/server/routers/olm/error.ts +++ b/server/routers/olm/error.ts @@ -94,6 +94,11 @@ export const OlmErrorCodes = { HOLEPUNCH_MISSING: { code: "HOLEPUNCH_MISSING", message: `Unable to coordinate client P2P connection. Please ensure your client can reach the server on UDP port ${udpPort} and try registering again.` + }, + NO_AVAILABLE_SUBNET: { + code: "NO_AVAILABLE_SUBNET", + message: + "No available subnet could be assigned to this client on the selected exit node. Please contact your administrator to increase the available address space for this exit node's subnet." } } as const; diff --git a/server/routers/olm/handleOlmRegisterMessage.ts b/server/routers/olm/handleOlmRegisterMessage.ts index 693920950..988e68afd 100644 --- a/server/routers/olm/handleOlmRegisterMessage.ts +++ b/server/routers/olm/handleOlmRegisterMessage.ts @@ -347,6 +347,7 @@ export const handleOlmRegisterMessage: MessageHandler = async (context) => { `[handleOlmRegisterMessage] No available subnets found for exit node id ${exitNodeId} and client id ${client.clientId}`, { orgId: client.orgId, clientId: client.clientId } ); + sendOlmError(OlmErrorCodes.NO_AVAILABLE_SUBNET, olm.olmId); return; }