Skip to content

Fix wireguard integrations for 4.8.x - #21

Merged
HarvsG merged 21 commits into
HarvsG:masterfrom
Hertzole:4.8-wireguard-fix
Oct 7, 2025
Merged

Fix wireguard integrations for 4.8.x#21
HarvsG merged 21 commits into
HarvsG:masterfrom
Hertzole:4.8-wireguard-fix

Conversation

@Hertzole

Copy link
Copy Markdown
Contributor

This fixes the WireGuard calls to the correct endpoints as of version 4.8.1. This is a breaking change and will no longer support anything below 4.8. While it's possible to support older versions, it would add more code to maintain to route each call to the correct version.

This can be used to fix HarvsG/ha-glinet4-integration#57, which I also have a fix for once this package gets a new updated published.

@Hertzole

Hertzole commented Sep 24, 2025

Copy link
Copy Markdown
Contributor Author

@HarvsG I have added versioning by passing a version string, usually gathered from the get_info call.
I do not have a pre 4.8 device to test with, but I assume that it will work since I just took the old code and put it back.

I've also added tests that use the new API and tests for starting and stopping. Anyone with an old device could run these tests to make sure everything works. I can confirm that it works on 4.8.1.

Comment thread gli4py/version.py Outdated
Comment thread gli4py/glinet.py Outdated
Comment thread gli4py/glinet.py Outdated
@Hertzole
Hertzole requested a review from HarvsG September 25, 2025 00:40

@HarvsG HarvsG left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Just a code review. I hope to test it tomorrow.
Lots of linting errors

Comment thread gli4py/glinet.py Outdated
Comment thread gli4py/glinet.py Outdated
Comment thread gli4py/glinet.py Outdated

if self._firmware_version < NEW_VPN_CLIENT_VERSION:
# If the version is less than 4.8 we need to adjust the response to match the new format
# The old format does not return an array, but just a single object.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Ill need to confirm this

@Hertzole

Copy link
Copy Markdown
Contributor Author

I'm not sure what to do about most of the linting errors about mixed line endings. I fixed some whitespace issues and unnecessary else statements though.

@HarvsG

HarvsG commented Sep 26, 2025

Copy link
Copy Markdown
Owner

I'm not sure what to do about most of the linting errors about mixed line endings. I fixed some whitespace issues and unnecessary else statements though.

I'll fix them when I review tomorrow

Comment thread gli4py/glinet.py
async def wireguard_client_state(self) -> dict:
async def wireguard_client_state(self) -> list:
"""
{"rx_bytes":0,"ipv6":"","tx_bytes":0,"domain":"vpn.example.com","group_id":7707,"port":51820,"name":"TheOracle","peer_id":1341,"status":0,"proxy":True,"log":"","ipv4":""}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Can you check if this is true for modern firmware - as it seems you are using tunnel_id and ned peer_id

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

What exactly do you want me to verify? Just so I understand.
But in-case you're referring to the comment being outdated, you'd be right.
Here's the full output of calling that endpoint on 4.8.1 (with some redactions)

{
	"id": 7,
	"jsonrpc": "2.0",
	"result": {
		"status_list": [
			{
				"enabled": true,
				"type": "wireguard",
				"tx_bytes": 24953488020,
				"peer_name": "PEER NAME HERE",
				"domain": [
					"XXX.XXX.XXX.XXX"
				],
				"group_id": 1234,
				"via": "wgclient1",
				"port": 51820,
				"tunnel_id": 10,
				"rx_bytes": 49725356924,
				"peer_id": 5678,
				"status": 1,
				"name": "Primary Tunnel",
				"ipv4": "XXX.XXX.XXX.XXX"
			}
		],
		"mode": 0
	}
}

Should I update the comment with the new response?

@HarvsG

HarvsG commented Sep 26, 2025

Copy link
Copy Markdown
Owner

does 4.8 support more that one connection at once?

@Hertzole

Copy link
Copy Markdown
Contributor Author

does 4.8 support more that one connection at once?

According to their releases, yes: "Added VPN multi-instance, allowing support for enabling multiple VPN clients at the same time."
I just personally can't verify it because I don't have another wireguard server to connect to.

@HarvsG

HarvsG commented Sep 26, 2025

Copy link
Copy Markdown
Owner

Ok so HarvsG/ha-glinet4-integration#66 now works with these API changes and hopefully adds support for multiple wg clients simultaneously.

I've done quite an ugly change to the WG api calls and to use peer_id and tunnel_id interchangeably

Can you test your system with this PR and the above PR and confirm it works

@Hertzole

Copy link
Copy Markdown
Contributor Author

I am getting a seemingly unrelated issue with an index out of bounds error on this line which stops me from testing. Printing the output of dev_info I only get 3 items, so no wonder 5 is out of range. Why 5 specifically?

@HarvsG

HarvsG commented Sep 26, 2025

Copy link
Copy Markdown
Owner

I am getting a seemingly unrelated issue with an index out of bounds error on this line which stops me from testing. Printing the output of dev_info I only get 3 items, so no wonder 5 is out of range. Why 5 specifically?

list(DeviceInterfaceType) turns the strenum defined at the top into a list with 7 items.

Which means it's not the 5 that is out of bounds but dev_info.get("type") (aka dev_info['type']) that is too large. Debug dev_info and see.

It may be that your device has a new interface type that has been added to the API
https://github.com/HarvsG/ha-glinet4-integration/blob/fc9327adf7a89f3c5e40487c725bafd398e3eb43/custom_components/glinet/router.py#L51

@Hertzole

Hertzole commented Sep 26, 2025

Copy link
Copy Markdown
Contributor Author

Ah, I see now. This router has a 6Ghz network, which is not listed. It returns as type 11. There's also WiFi 7, which I have disabled (and believe was disabled by default?)

I guess my phone just didn't use the 6Ghz network before when I set this up? Because now it does and that causes the issue.

Update: I enabled WiFi 7 / MLO WiFi (which I honestly don't know how it works), and that returns type 9. I do not know what type 8 and 10 are.

Update 2: I went ahead and tested and other networks. I can not find network type 8, but found 9 (MLO), 10 (MLO Guest), 11 (6Ghz), and 12 (6Ghz Guest). I can make a separate pull request for that later. I can now test these actual changes and will post on the PR you linked.

@Hertzole

Hertzole commented Sep 26, 2025

Copy link
Copy Markdown
Contributor Author

Can you upload the diff or create your own pr on this repo

The diff for what exactly? I'm sorry, but I'm not quite following what you mean.

If you're talking about the network interfaces, I made a pull request to the other repo. HarvsG/ha-glinet4-integration#67

@HarvsG
HarvsG merged commit 0763a59 into HarvsG:master Oct 7, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WireGuard VPN toggle not working since FW upgrade 4.8.2

2 participants