Skip to content

Commit

Permalink
Preserve netmask if one isn't supplied in address
Browse files Browse the repository at this point in the history
  • Loading branch information
marksteward committed Dec 22, 2024
1 parent 8fa36c8 commit 8504b72
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
9 changes: 4 additions & 5 deletions src/data/hassio/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,10 @@ export const accesspointScan = async (
};

export const parseAddress = (address: string) => {
const isIPv6 = address.includes(":");
const [ip, cidr] = address.includes("/")
? address.split("/")
: [address, isIPv6 ? "64" : "24"];
return { ip, mask: cidrToNetmask(cidr, isIPv6) };
const [ip, cidr] = address.split("/");
const isIPv6 = ip.includes(":");
const mask = cidr ? cidrToNetmask(cidr, isIPv6) : null;
return { ip, mask };
};

export const formatAddress = (ip: string, mask: string) =>
Expand Down
8 changes: 7 additions & 1 deletion src/panels/config/network/supervisor-network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -655,8 +655,14 @@ export class HassioNetwork extends LitElement {
this._dirty = true;
if (id === "address") {
const index = (ev.target as any).index as number;
const { mask: oldMask } = parseAddress(
this._interface![version]!.address![index]
);
const { mask } = parseAddress(value);
this._interface[version]!.address![index] = formatAddress(value, mask);
this._interface[version]!.address![index] = formatAddress(
value,
mask || oldMask || ""
);
this.requestUpdate("_interface");
} else if (id === "netmask") {
const index = (ev.target as any).index as number;
Expand Down

0 comments on commit 8504b72

Please sign in to comment.