From 431ee37415f5962ed242004dd88cd0f0027d1f6c Mon Sep 17 00:00:00 2001 From: jakub-tldr <78603704+jakub-tldr@users.noreply.github.com> Date: Mon, 9 Mar 2026 15:58:12 +0100 Subject: [PATCH 1/2] add device id to ip check --- crates/defguard_core/src/handlers/network_devices.rs | 6 +++++- .../EditNetworkDeviceModal/EditNetworkDeviceModal.tsx | 1 + web/src/shared/api/api.ts | 1 + web/src/shared/api/types.ts | 1 + 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/crates/defguard_core/src/handlers/network_devices.rs b/crates/defguard_core/src/handlers/network_devices.rs index d3f250fd4a..0c03d194b8 100644 --- a/crates/defguard_core/src/handlers/network_devices.rs +++ b/crates/defguard_core/src/handlers/network_devices.rs @@ -216,6 +216,7 @@ pub struct AddNetworkDeviceResult { #[derive(Deserialize)] pub struct IpAvailabilityCheck { ips: Vec, + device_id: Option, } #[derive(Serialize)] @@ -258,7 +259,10 @@ pub(crate) async fn check_ip_availability( debug!( "Checking if IP address {ip} can be assigned to a device in location {location}", ); - let result = match location.can_assign_ips(&mut transaction, &[ip], None).await { + let result = match location + .can_assign_ips(&mut transaction, &[ip], check.device_id) + .await + { Ok(()) => IpAvailabilityCheckResult::new(true, true), Err(NetworkAddressError::NoContainingNetwork(name, ip, networks)) => { warn!( diff --git a/web/src/pages/NetworkDevicesPage/modals/EditNetworkDeviceModal/EditNetworkDeviceModal.tsx b/web/src/pages/NetworkDevicesPage/modals/EditNetworkDeviceModal/EditNetworkDeviceModal.tsx index a2385e1da5..2ac210d610 100644 --- a/web/src/pages/NetworkDevicesPage/modals/EditNetworkDeviceModal/EditNetworkDeviceModal.tsx +++ b/web/src/pages/NetworkDevicesPage/modals/EditNetworkDeviceModal/EditNetworkDeviceModal.tsx @@ -115,6 +115,7 @@ const ModalContent = ({ device, reservedNames }: ModalData) => { const { data: validationResponse } = await api.network_device.validateIps({ ips: formValues, locationId: device.location.id, + deviceId: device.id, }); validationResponse.forEach(({ valid, available }, index) => { if (!valid) { diff --git a/web/src/shared/api/api.ts b/web/src/shared/api/api.ts index eb7f013508..365c42cadb 100644 --- a/web/src/shared/api/api.ts +++ b/web/src/shared/api/api.ts @@ -321,6 +321,7 @@ const api = { validateIps: (data: ValidateDeviceIpsRequest) => client.post(`/device/network/ip/${data.locationId}`, { ips: data.ips, + device_id: data.deviceId, }), }, location: { diff --git a/web/src/shared/api/types.ts b/web/src/shared/api/types.ts index d5e44fadd8..30d3dfa638 100644 --- a/web/src/shared/api/types.ts +++ b/web/src/shared/api/types.ts @@ -86,6 +86,7 @@ export interface SetAutoAdoptionMfaSettingsRequest { export interface ValidateDeviceIpsRequest { ips: string[]; locationId: number; + deviceId?: number; } export interface IpValidation { From 5d697f1ed62d5b0e1221e35a0e1a123cb29b177e Mon Sep 17 00:00:00 2001 From: jakub-tldr <78603704+jakub-tldr@users.noreply.github.com> Date: Mon, 9 Mar 2026 16:02:30 +0100 Subject: [PATCH 2/2] fix network devices sorting --- .../pages/NetworkDevicesPage/NetworkDevicesTable.tsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/web/src/pages/NetworkDevicesPage/NetworkDevicesTable.tsx b/web/src/pages/NetworkDevicesPage/NetworkDevicesTable.tsx index 0efb21007f..70a7d676bf 100644 --- a/web/src/pages/NetworkDevicesPage/NetworkDevicesTable.tsx +++ b/web/src/pages/NetworkDevicesPage/NetworkDevicesTable.tsx @@ -53,8 +53,12 @@ export const NetworkDevicesTable = ({ networkDevices }: Props) => { const { mutate: openAdd, isPending: addPending } = useMutation({ mutationFn: async () => { const { data: locations } = await api.location.getLocations(); - const availableLocations = locations.filter( - (location) => location.location_mfa_mode === LocationMfaMode.Disabled, + const availableLocations = orderBy( + locations.filter( + (location) => location.location_mfa_mode === LocationMfaMode.Disabled, + ), + ['name'], + ['asc'], ); if (!availableLocations.length) return; const { data: availableIps } = await api.network_device.getAvailableIp( @@ -62,7 +66,7 @@ export const NetworkDevicesTable = ({ networkDevices }: Props) => { ); openModal(ModalName.AddNetworkDevice, { availableIps, - locations: orderBy(availableLocations, ['name'], ['asc']), + locations: availableLocations, reservedNames, }); },