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

[FEATURE] Adding suggested ApprovedIP when adding peer #145

Conversation

GenericStudent
Copy link
Contributor

@GenericStudent GenericStudent commented Sep 19, 2021

This PR should resolve RM ticket 11588.

It adds a new setting option Suggest Next Approved IP.

If the above setting is enabled, when a user creates a new peer (for an existing tunnel atm, need to look at breaking out to JS so we can pick it up when the user navigates to Add New Peer page without pre-selecting a tunnel) it will work out what the next available IP address is.

It does this by working out the subnet value, broadcast value, and any existing peers. Once we have these values we can iterate from the subnet + 1 up until broadcast - 1, the first available IP address is "taken".

So we have the following examples of expected behaviour:

  • Tunnel's assigned interface has static IPv4 address of 192.168.100.1 with cidr range of /24

    • Peers with the IP addresses: 192.168.100.2, 192.168.100.3, 192.168.100.4, 192.168.100.6, 192.168.100.7
    • With the above setting enabled, when click the "Add new peer for this tunnel" button, it will pre-fill the ApprovedIP list with the address 192.168.100.5/32 given it's available. Doing this a second time (if we create .100.5) will result in the IP address 192.168.100.8/32 being suggested
  • Tunnel's WG specified IP address of 192.168.150.254/24

    • Suggests IP address 192.168.150.1/32

In this PR I'm iterating from subnet to broadcast as we can't assume the interface address is always lowest (.1/24 for example) as it could also be highest (.254/24 for example).

This is currently a work in progress and should not be deployed.

@GenericStudent
Copy link
Contributor Author

@theonemcdonald, think this PR is ready to review.

Any suggestions on consolidated / centralised methods for all CIDR / subnet validating, enumerating (subnet IP, broadcast IP, etc)? I've written out some "hacky" methods to achieve it but feel there must be better methods built into pfSense (I've tried looking but couldn't see any).

@GenericStudent GenericStudent changed the title WIP: Adding suggested ApprovedIP for new peer Adding suggested ApprovedIP when adding peer Sep 19, 2021
@GenericStudent
Copy link
Contributor Author

GenericStudent commented Sep 21, 2021

@theonemcdonald Is the refactor ongoing regarding this repo? I'm failing to build main branch now due the function wg_gen_publickey being missing from wg_api.inc, change where it was removed:
79e1d13#diff-cf8e3c0525cfc887248a896b62291303fae4ca316274ef217303abbed13be65eL705

Couldn't find it anywhere in the main branch.

@rcmcdonald91
Copy link
Owner

@GenericStudent Sorry about that, yeah that was an oversight on my part. You should be able to build now.

@GenericStudent
Copy link
Contributor Author

@GenericStudent Sorry about that, yeah that was an oversight on my part. You should be able to build now.

No worries, thanks for the quick resolve.

@GenericStudent
Copy link
Contributor Author

Please note I've refactored this codebase to use one of the composer added libraries, it sits on the branch feature/peer-endpoint-suggestion-using-composer however I'm unsure how to get the vendor folder added into the pkg-plist file nicely (I'm deving it by simply SCPing the entire vendor folder into position.

@GenericStudent GenericStudent changed the title Adding suggested ApprovedIP when adding peer [FEATURE] Adding suggested ApprovedIP when adding peer Oct 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants