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

Support optional socket options #215

Merged
merged 7 commits into from
Oct 7, 2021
Merged

Support optional socket options #215

merged 7 commits into from
Oct 7, 2021

Conversation

meox
Copy link
Contributor

@meox meox commented Oct 3, 2021

Add the possibility to create a server passing extra options like netns and vrf.

Example:

%% vim: ft=erlang
[{eradius, [
  {tables, [dictionary]},
  {session_nodes, local},
  {radius_callback, fake_radius},
  {root, [
      {{"root", []}, [{"10.11.11.1", "testing123"}]}
  ]},
  {servers, [
      {root, {"10.11.11.2", [1812, 1813], [{netns, "/var/run/netns/myns"}]}}
  ]}
]}].

@meox meox requested a review from a team as a code owner October 3, 2021 10:30
Copy link
Contributor

@vkatsuba vkatsuba left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution! Please add test cases and provide example with description in README.

src/eradius_server.erl Outdated Show resolved Hide resolved
src/eradius_server.erl Outdated Show resolved Hide resolved
@vkatsuba
Copy link
Contributor

vkatsuba commented Oct 3, 2021

Please also run GitHub Actions manually in your fork and provide here the link to success CI.
How to:

Co-authored-by: Viacheslav Katsuba <[email protected]>
Copy link
Contributor

@vkatsuba vkatsuba left a comment

Choose a reason for hiding this comment

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

Please squash all commits into single commit.

README.md Outdated Show resolved Hide resolved
@meox
Copy link
Contributor Author

meox commented Oct 3, 2021

If I put my test: config_extra_options after config_1 and config_2 doesn't works:

{timeout,{gen_server,call,[eradius_server_mon,reconfigure]}}

but if I put before works.

@meox
Copy link
Contributor Author

meox commented Oct 3, 2021

@RoadRunnr
Copy link
Member

RoadRunnr commented Oct 4, 2021

Please squash all commits into single commit.

please don't do that. Structure you commits in a way that there is a single commit for each logical change. That means, one commit for the spelling (and only those), one for the code formatting changes and one commit for adding the socket options.

Comment on lines 132 to 133
validate_options(Opts) when is_list(Opts) ->
Opts;
Copy link
Member

Choose a reason for hiding this comment

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

this could use a check to restrict the options to the once we want to allow. For example there is no point to allow the binary (or list), the active, ip and recbuf options.

Don't do a negative filtering, explicitly check only for allowed options.

A full validation of the content of the options is not needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done: I have introduced validate_socket_options that checks if a specific options is in a banned list

@0xAX
Copy link
Member

0xAX commented Oct 4, 2021

Hello @meox and thanks for PR.

For now eradius UDP server uses options in a kind of mixed way. Some of them are predefined and could not be changed. Besides predefined there is recbuf that eradius takes from eradius application. In this case of intoducing per-server options - eradius server will collect options from different places.

I would suggest to introduce a generic place (and format maybe property list or map) for all socket related options in addition to predefined options.

Something like:

[{eradius, [
  {tables, [dictionary]},
  {session_nodes, local},
  {radius_callback, fake_radius},
  {root, [
      {{"root", []}, [{"10.11.11.1", "testing123"}]}
  ]},
  {servers, [
    {root, {"10.11.11.2", [1812, 1813], [{socket_opts, [{recbuf, 8192000},
                                                        {netns, "/var/run/netns/myns"}]}]}}
  ]}
]}].

So eradius server will start:

-define(DEFAULT_RADIUS_SERVER_OPTS(IP), [{{active, once}, {ip, IP}, binary]).


init({ServerName, IP, Port, Opts}) ->
  ...
  ...
  ...
  ExtraServerOptions = proplists:get_value(socket_opts, Opts, []),
  case gen_udp:open(Port, ?DEFAULT_RADIU_SERVER_OPTS(IP) ++ ExtraServerOptions) of
  ...
  ...

or something like this. This will allow to have recbuf per-server and also should simplify validation of options like @RoadRunnr suggested

@meox
Copy link
Contributor Author

meox commented Oct 4, 2021

Copy link
Contributor

@vkatsuba vkatsuba left a comment

Choose a reason for hiding this comment

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

LGTM.

@vkatsuba
Copy link
Contributor

vkatsuba commented Oct 4, 2021

@RoadRunnr, @0xAX, please take a look again.

README.md Outdated Show resolved Hide resolved
src/eradius_config.erl Outdated Show resolved Hide resolved
@0xAX
Copy link
Member

0xAX commented Oct 4, 2021

@meox Thanks for the update. I've put some comments, but in general the changes look pretty good and I think it could be merged after clarification the situation with recbuf in eradius_server

@meox
Copy link
Contributor Author

meox commented Oct 4, 2021

@meox meox requested a review from 0xAX October 4, 2021 15:48
Copy link
Member

@0xAX 0xAX left a comment

Choose a reason for hiding this comment

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

LGTM after fixing the things related to the last comments.

@meox
Copy link
Contributor Author

meox commented Oct 4, 2021

LGTM after fixing the things related to the last comments.

perfect: ping me if I have to change other stuff! and thanks for the support/suggestions.

@meox
Copy link
Contributor Author

meox commented Oct 4, 2021

Added a new test to check some cases for the eradius_config:validate_server function

@meox meox requested a review from 0xAX October 6, 2021 10:46
@meox
Copy link
Contributor Author

meox commented Oct 7, 2021

any chance to merge this branch soon?

@vkatsuba vkatsuba merged commit 70b2623 into travelping:master Oct 7, 2021
@vkatsuba
Copy link
Contributor

vkatsuba commented Oct 7, 2021

any chance to merge this branch soon?

Yep. Merged 😄. Thanks again for your contribution!

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.

4 participants