Skip to content

Commit

Permalink
Merge pull request #419 from sinamics/iprange
Browse files Browse the repository at this point in the history
Fix "Controller Not Reachable" Error when invalid IP range exists in a network.
  • Loading branch information
sinamics authored May 22, 2024
2 parents 8d26add + 6d36b3c commit f7fb9ca
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 19 deletions.
3 changes: 1 addition & 2 deletions src/pages/admin/controller/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ const Controller = () => {
controllerStatus?.config?.settings || {};

const { online, tcpFallbackActive, version } = controllerStatus || {};

return (
<main className="flex w-full flex-col justify-center space-y-5 bg-base-100 p-3 sm:w-6/12 pb-80">
{controllerError ? (
Expand All @@ -41,7 +40,7 @@ const Controller = () => {
d="M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z"
/>
</svg>
<span>Error! Controller unreachable</span>
<span>{controllerError?.message}</span>
</div>
) : (
<>
Expand Down
8 changes: 1 addition & 7 deletions src/utils/IPv4gen.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
// function randomOctet() {
// return Math.floor(Math.random() * 255);

import { throwError } from "~/server/helpers/errorHandler";

// }
const cidrOptions = [
"10.121.15.0/24",
"10.121.16.0/24",
Expand Down Expand Up @@ -128,7 +122,7 @@ export const getNetworkClassCIDR = (

for (const range of ipRanges) {
if (ipToNumber(range.ipRangeStart) >= ipToNumber(range.ipRangeEnd)) {
return throwError("Invalid IP range provided");
continue;
}

const binaryStart = ipToBinary(range.ipRangeStart);
Expand Down
20 changes: 10 additions & 10 deletions src/utils/ztApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ export const get_controller_networks = async (
return await getData<ZTControllerListNetworks>(addr, headers);
} catch (error) {
const prefix = isCentral ? "[CENTRAL] " : "";
const message = `${prefix}An error occurred while getting get_controller_networks`;
const message = `${prefix} ${error} (get_controller_networks)`;
throw new APIError(message, axios.isAxiosError(error) ? error : undefined);
}
};
Expand Down Expand Up @@ -276,7 +276,7 @@ export const get_controller_status = async (
return await getData<ZTControllerNodeStatus>(addr, headers);
} catch (error) {
const prefix = isCentral ? "[CENTRAL] " : "";
const message = `${prefix}An error occurred while getting get_controller_status`;
const message = `${prefix} ${error} (get_controller_status)`;
throw new APIError(message, error as AxiosError);
}
};
Expand Down Expand Up @@ -324,7 +324,7 @@ export const network_create = async (
);
} catch (error) {
const prefix = isCentral ? "[CENTRAL] " : "";
const message = `${prefix}An error occurred while getting network_create`;
const message = `${prefix} ${error} (network_create)`;
throw new APIError(message, error as AxiosError);
}
};
Expand Down Expand Up @@ -352,7 +352,7 @@ export async function network_delete(
return { status: response.status, data: undefined };
} catch (error) {
const prefix = isCentral ? "[CENTRAL] " : "";
const message = `${prefix}An error occurred while getting network_delete`;
const message = `${prefix} ${error} (network_delete)`;
throw new APIError(message, error as AxiosError);
}
}
Expand Down Expand Up @@ -507,7 +507,7 @@ export const central_network_detail = async (
};
} catch (error) {
const source = isCentral ? "[ZT CENTRAL]" : "";
const message = `${source} An error occurred while getting data from network_details function`;
const message = `${source} ${error} (central_network_detail)`;
throw new APIError(message, error as AxiosError);
}
};
Expand Down Expand Up @@ -537,7 +537,7 @@ export const network_update = async ({
return await postData<NetworkEntity>(addr, headers, payload);
} catch (error) {
const prefix = central ? "[CENTRAL] " : "";
const message = `${prefix}An error occurred while getting network_update`;
const message = `${prefix} ${error} (network_update)`;
throw new APIError(message, error as AxiosError);
}
};
Expand All @@ -562,7 +562,7 @@ export const member_delete = async ({
return response.status as MemberDeleteResponse;
} catch (error) {
const prefix = central ? "[CENTRAL] " : "";
const message = `${prefix}An error occurred while getting member_delete`;
const message = `${prefix} ${error} (member_delete)`;
throw new APIError(message, error as AxiosError);
}
};
Expand Down Expand Up @@ -594,7 +594,7 @@ export const member_update = async ({
return await postData<MemberEntity>(addr, headers, payload);
} catch (error) {
const prefix = central ? "[CENTRAL] " : "";
const message = `${prefix}An error occurred while getting member_update`;
const message = `${prefix} ${error} (member_update)`;
throw new APIError(message, error as AxiosError);
}
};
Expand All @@ -618,7 +618,7 @@ export const member_details = async (

return await getData<MemberEntity>(addr, headers);
} catch (error) {
const message = "An error occurred while getting member_detail";
const message = `${error} (member_details)`;
throw new APIError(message, error as AxiosError);
}
};
Expand All @@ -637,7 +637,7 @@ export const peers = async (ctx: UserContext): Promise<ZTControllerGetPeer> => {
const response: AxiosResponse = await axios.get(addr, { headers });
return response.data as ZTControllerGetPeer;
} catch (error) {
const message = "An error occurred while getting peers";
const message = `${error} (peers)`;
throw new APIError(message, error as AxiosError);
}
};
Expand Down

0 comments on commit f7fb9ca

Please sign in to comment.