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

RFC: hostapd: extend module to allow multiple APs. #49171

Closed
wants to merge 2 commits into from

Conversation

qolii
Copy link
Contributor

@qolii qolii commented Oct 26, 2018

Motivation for this change

It is useful to be able to run multiple APs on a hostapd machine. The traditional ways to do this appear to be:

  1. Run multiple instances of the daemon.
  2. Run one instance of the daemon with multiple separate config files.

This change implements (1). I prefer this a bit over (2), because it gives each AP its own separate log in journald, and also means you can change configuration and restart just one AP at a time. I have found this to be more flexible in use.

I also have a version of this change implementing (2), if people feel strongly about that.

NOTE: This is a breaking change to the configuration format. My approach has been to take the existing single-AP configuration style, define a submodule around it, and modify the nixos module to take a list of this submodule called APs, as follows:

{
  enable = true;
  APs = [
    # 5GHz
    { interface = "wlp7s0";
      driver = "nl80211";
      ssid = "acbdef";
      hwMode = "a";
      wpa = true;
      wpaPassphrase = "12345";
      channel = 0;
      extraConfig = ''
        ...
      '';
    }
    # 2.4GHz
    { interface = "wlp5s0";
      driver = "nl80211";
      ssid = "abcdef";
      hwMode = "g";
      wpa = true;
      wpaPassphrase = "12345";
      channel = 0;
      extraConfig = ''
        ...
      '';
    }
  ];
}

This will result in two systemd service files, namely, hostapd-wlp7s0.service and hostapd-wlp5s0.service.

This works well, but will not accept any working existing configurations. I also could not figure out how to extend the hostapd entry in rename.nix. I expect these things are a big problem for the acceptance of this change, so if anyone has advice on how to achieve this more gently, please let me know.

systemd ordering

Upon making this change, I noticed failures at startup due to systemd ordering, because hostapd would try to start too early. I have thus reworked the ordering a little bit, and observe a completely reliable service on my machine. However, I am not an expert in all the different types of ways to do this, so any advice on this front is also very welcome.

In summary, this change has been very functional for me in testing.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Fits CONTRIBUTING.md.

@GrahamcOfBorg GrahamcOfBorg added 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux labels Oct 26, 2018
@qolii
Copy link
Contributor Author

qolii commented Oct 26, 2018

[Mentioning @wkennington and @Phreedom, as folks in the maintainers list for hostapd.]

@qolii
Copy link
Contributor Author

qolii commented Oct 27, 2018

A thought: given that we are faced with a breaking change anyway, would it be worthwhile to add a bridge field to the submodule, and then have hostapd service unit bindsTo and after the bridge's device unit? I don't know if there is currently an actual dependency on that, but I think there should be.

@qolii
Copy link
Contributor Author

qolii commented Oct 31, 2018

Well, I went for it. This actually lets me simplify the dependency list now that the bridge dependency is explicit. I rebooted my machine a bunch of times an observed stable bring-up of everything.

Since it's a separate commit, it will be easy to back out if there are issues.

@flokli
Copy link
Contributor

flokli commented Jun 22, 2019

@qolii Thanks for the PR! Sorry this went unnoticed for so long.

I gave this a try together with @NinjaTrappeur. We rebased your commits on the latest master, a more recent version of the branch can be found at https://github.com/flokli/nixpkgs/commits/hostapd-multiple-ifs.

I incorporated the systemd interface escaping that was done in master since your PR.

I do have more comments about it. Do you still want to merge this in? If yes, could you reset your PR to that version, so I can comment in here?

@qolii
Copy link
Contributor Author

qolii commented Jun 24, 2019

@flokli, thanks for getting back to me! This sounds great. Please give me another day or two, I'm a bit swamped at the moment.

@flokli
Copy link
Contributor

flokli commented Jun 24, 2019

sure :-)

@qolii
Copy link
Contributor Author

qolii commented Jul 3, 2019

Hi @flokli, so, what I did was remake the branch on my fork by cherry-picking the two commits from the branch on your fork. So I think those are now what you see here.

Is this what you had in mind?

If so, comment away! What are you thinking?

@ofborg ofborg bot added the 2.status: merge conflict This PR has merge conflicts with the target branch label Jul 3, 2019
@qolii
Copy link
Contributor Author

qolii commented Jul 3, 2019

(And just fixed merge conflicts)

@ofborg ofborg bot removed the 2.status: merge conflict This PR has merge conflicts with the target branch label Jul 3, 2019
@qolii
Copy link
Contributor Author

qolii commented Jul 8, 2019

(and just reinstated the noScan option that got stomped)

@qolii
Copy link
Contributor Author

qolii commented Aug 9, 2019

@flokli / @NinjaTrappeur, any thoughts?

@flokli
Copy link
Contributor

flokli commented Aug 9, 2019

@qolii this doesn't look too bad to me, but for the next two weeks, I won't have access to the hardware available to test it.

I remember @NinjaTrappeur mentioning a lot of hostapd options were still missing. Instead of adding all these, do you think it might make sense to refactor this to something like https://github.com/Infinisil/rfcs/blob/config-option/rfcs/0042-config-option.md describes?

@qolii
Copy link
Contributor Author

qolii commented Aug 13, 2019

@floli, I like the idea of doing a refactor. However, would you be amenable to merging this first (as I think this provides genuinely useful functionality), and doing that in a separate PR?

I'm happy to give the refactor a shot myself.

Copy link
Contributor

@flokli flokli left a comment

Choose a reason for hiding this comment

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

After reading through the hostapd.conf manpage once more, some comments.

The changed options also require a changelog entry.

@@ -3,6 +3,7 @@
# TODO:
#
# asserts
# ensure interface name is set
Copy link
Contributor

Choose a reason for hiding this comment

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

It's probably not too complicated to add code for this inside this PR.

@@ -3,6 +3,7 @@
# TODO:
#
# asserts
# ensure interface name is set
# ensure that the nl80211 module is loaded/compiled in the kernel
Copy link
Contributor

Choose a reason for hiding this comment

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

This could be moved into the generic services.hostapd description.

@@ -3,6 +3,7 @@
# TODO:
#
# asserts
# ensure interface name is set
# ensure that the nl80211 module is loaded/compiled in the kernel
# wpa_supplicant and hostapd on the same wireless interface doesn't make any sense
Copy link
Contributor

Choose a reason for hiding this comment

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

probably the same applies for this one as well - In networking.supplicant.<name>, <name> can be separated by spaces, so matching automatically would be a bit more complicated.

default = "";
example = "wlp2s0";
description = ''
The interfaces <command>hostapd</command> will use.
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be singular.

interface = mkOption {
default = "";
example = "wlp2s0";
APs = mkOption {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure if I'm so happy with the APs = [] part - it's quite unintuitive compared to how the rest of the module system looks like, and hostapd too only knows about bssids and interfaces, not APs.

Can we make this similar to networking.supplicant? Having the description in services.hostapd, and a services.hostapd.<(interface_)name>.*, like networking.supplicant.<name>.*?

From my understanding, there can only be one hostapd process per physical interface, and configuring multiple bssids would be part of the per-interface config file, which would need to duplicated for dual/multi-band setups.

@ivan
Copy link
Member

ivan commented Sep 6, 2019

For the author, reviewers, and committers: this PR was scanned and appears to add a use of the deprecated types.string, which emits a warning as of #66346. Before merging, please change this to another type, possibly:

  • types.str for a single string where merging does not make sense, or cannot work
  • types.lines for multi-line configuration or scripts where merging is possible
  • types.listOf types.str for a mergeable list of strings

@flokli
Copy link
Contributor

flokli commented Oct 12, 2019

@qolii the usage of types.string was fixed in master in 478e718.

I'd be more in favor of doing the refactoring inside this PR - we introduce a bunch of new options / changes, which we'd have to worry about deprecating later again.

@stale
Copy link

stale bot commented Jun 1, 2020

Thank you for your contributions.
This has been automatically marked as stale because it has had no activity for 180 days.
If this is still important to you, we ask that you leave a comment below. Your comment can be as simple as "still important to me". This lets people see that at least one person still cares about this. Someone will have to do this at most twice a year if there is no other activity.
Here are suggestions that might help resolve this more quickly:

  1. Search for maintainers and people that previously touched the
    related code and @ mention them in a comment.
  2. Ask on the NixOS Discourse. 3. Ask on the #nixos channel on
    irc.freenode.net.

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jun 1, 2020
@qolii
Copy link
Contributor Author

qolii commented Jun 1, 2020

Still important to me! I'll try to rework this based on the comments so far. I know has changed in Nix-land since I first proposed this anyway.

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jun 1, 2020
@ryantm ryantm added 2.status: merge conflict This PR has merge conflicts with the target branch and removed 2.status: merge conflict This PR has merge conflicts with the target branch labels Oct 3, 2020
@stale
Copy link

stale bot commented Jun 7, 2021

I marked this as stale due to inactivity. → More info

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jun 7, 2021
@RaitoBezarius
Copy link
Member

Can I help you to get this PR merged?

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Dec 1, 2022
@AndersonTorres
Copy link
Member

Last activity from @qolii is from 2020:

NixOS/nix#3166

Closing as dead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.status: merge conflict This PR has merge conflicts with the target branch 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants