Skip to content

IP version selection: v4, v6, both#448

Open
StLyn4 wants to merge 1 commit intocomplexorganizations:mainfrom
StLyn4:main
Open

IP version selection: v4, v6, both#448
StLyn4 wants to merge 1 commit intocomplexorganizations:mainfrom
StLyn4:main

Conversation

@StLyn4
Copy link
Copy Markdown

@StLyn4 StLyn4 commented Nov 23, 2024

I think the title speaks for itself. Basically, another option has been added to the initial setup process, which allows you to choose between using IPv4 only, IPv6, or both (as it was before).

Why?
There are still quite a few places where only IPv4 is available (for example, almost everywhere in my country).
I have also come across some cheap configurations where only IPv6 is available, and IPv4 is disabled.

I would be happy to get feedback and make corrections if necessary.
Have a nice day! :)

Signed-off-by: Vsevolod Volkov <st.lyn4@gmail.com>
@StLyn4
Copy link
Copy Markdown
Author

StLyn4 commented Dec 7, 2024

Please specify in more detail what exactly needs to be simplified. As soon as I have free time, I will try to do it. 😊 As for the current state, I tried to preserve the original logic of the script and at the moment all the changes can be described as follows:

I simply added 2 flags: IP_V4_ENABLED and IP_V6_ENABLED. After that, I wrapped the code specific to these versions in "if IP_Vx_ENABLED". I also preliminarily divided some code into 2 parts by IP versions, while maintaining the same logic.

As for deeper changes:

  1. Added validation of the subnet address using regex.
  2. The IP address version for connecting to the server cannot be selected if only one version is initially selected (since this makes no sense).
  3. In many places, a construction like $(IFS=,; echo "${SERVER_ADDRESS[*]}") is used. In fact, the logic here is very simple: an array for strings is made, to which 1-2 addresses are added depending on the enabled IP versions, after which they are connected using "," so we get the final string, which can be put into the configuration.
  4. I lowered the chmod of the wireguard folder from 700 to 600, since there is nothing executable there by default anyway, and wireguard itself prints a warning at 700.
  5. Support for a particular IP version when creating new clients is determined by the presence of a suitable IP in WIREGUARD_CONFIG. That is, if IPv6 is somewhere there, then we consider that IPv6 is supported. If IPv4 is also there, then IPv4 is supported.

@JuliusKB
Copy link
Copy Markdown

JuliusKB commented Feb 19, 2025

This was my need exactly, as I needed quick and dirty way to set up only for ipv4 on test environment i used code from this pr and have encountered a bug

Unfortunately I lack time and skill in bash but per my understanding this is what the code is trying to do 10.0.0.2 + 1 instead of 2 + 1

/usr/local/bin/wireguard-manager.sh: line 1500: [: 10.0.0.2: integer expression expected
/usr/local/bin/wireguard-manager.sh: line 1578: 10.0.0.2: syntax error: invalid arithmetic operator (error token is ".0.0.2")
1577       CLIENT_ADDRESS_V4=$(echo "${PRIVATE_SUBNET_V4}" | cut --delimiter="." --fields=1-3).$((LASTIPV4 + 1))
1578       CLIENT_ADDRESS_V6=$(echo "${PRIVATE_SUBNET_V6}" | cut --delimiter=":" --fields=1-4):$((LASTIPV6 + 1))

P.S your work is much appreciated 🤘🤘

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.

2 participants