Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use null instead of default, to avoid stomping on netmask #23382

Merged
merged 1 commit into from
Dec 23, 2024

Conversation

marksteward
Copy link
Contributor

Proposed change

Refines #23348 to return null instead of a default netmask. This then allows the code to avoid stomping on a preexisting netmask that isn't /24 for IPv4 or /64 for IPv6.

To be clear, the issue was never that the default was wrong, but that the netmask is overwritten as soon as the IP address field blurs, and the previous PR doesn't change that. A user tweaking the last octet of their IP address and clicking Save will not have the opportunity to notice the changed netmask before it applies and they lose access. /24 is less likely to break things but people do use /25s and 10.x.x.x networks. And /64 is the smallest used subnet for IPv6, /48 is quite often given out by ISPs.

This PR also switches to checking ip for colons instead of the whole address field, but that's very minor as nothing's validated at this stage.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (thank you!)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Example configuration

N/A

Additional information

Checklist

  • The code change is tested and works locally.
  • There is no commented out code in this PR.
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

Copy link

@home-assistant home-assistant bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @marksteward

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

@home-assistant
Copy link

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@@ -656,8 +656,10 @@ export class HassioNetwork extends LitElement {
if (id === "address") {
const index = (ev.target as any).index as number;
const { mask } = parseAddress(value);
this._interface[version]!.address![index] = formatAddress(value, mask);
this.requestUpdate("_interface");
if (mask) {
Copy link
Member

@bramkragten bramkragten Dec 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means a change in IP address is never picked up as long as there is no mask? And will never be saved?

Also means that if there is a re-render before the mask is updated, the changes of the user are undone.

Copy link
Contributor Author

@marksteward marksteward Dec 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh yep, just realised this after playing some more. It looks like adding an empty IP address adds with a /24 or /64 netmask, so there's always one behind the scenes, which we can use as the default instead.

bramkragten
bramkragten previously approved these changes Dec 22, 2024
@marksteward
Copy link
Contributor Author

(I've run yarn run lint:types locally now)

@silamon
Copy link
Contributor

silamon commented Dec 22, 2024

(I've run yarn run lint:types locally now)

To get CI green, you may need to run prettier as well

yarn run format:prettier

@marksteward
Copy link
Contributor Author

Thanks, that looks better!

@bramkragten bramkragten merged commit 7d0a269 into home-assistant:dev Dec 23, 2024
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Netmask is overwritten with incorrect data
3 participants