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

Move work to compiler #6

Merged
merged 4 commits into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
elixir-radius
=============

[![CI](https://github.com/bearice/elixir-radius/actions/workflows/elixir.yml/badge.svg)](https://github.com/bearice/elixir-radius/actions/workflows/elixir.yml)

[![Hex.pm version](https://img.shields.io/hexpm/v/elixir_radius.svg?style=flat)](https://hex.pm/packages/elixir_radius)
[![CI](https://github.com/bearice/elixir-radius/actions/workflows/elixir.yml/badge.svg)](https://github.com/bearice/elixir-radius/actions/workflows/elixir.yml) [![Hex.pm version](https://img.shields.io/hexpm/v/elixir_radius.svg?style=flat)](https://hex.pm/packages/elixir_radius)

RADIUS protocol encoding and decoding

example
Example
-------
```Elixir
#wrapper of gen_udp
Expand All @@ -27,3 +25,27 @@ loop = fn(loop)->
end
loop.(loop)
```

Dictionary configuration
--------------------

Vendor specific dictionaries are compiled into a specific vendor module. Generic attributes and values
are compiled into `Radius.Dict`. If you add the "cisco" dictionary you will get the module `Radius.Dict.VendorCisco`.

```Elixir
config :elixir_radius,
included_dictionaries: ["rfc2865", "rfc2868", "rfc2869", "cisco"]
```

You can also add your own dictionaries by providing the paths to `:elixir_radius` in `:extra_dictionaries`

```Elixir
config :elixir_radius,
extra_dictionaries: ["path_to_your_dictionary"]
```

Macros
------

`Radius.Dict` exposes a set of macro's so you can construct AVPs and let the compiler confirm the
attributes and save time during runtime.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
35 changes: 17 additions & 18 deletions example.exs
Original file line number Diff line number Diff line change
@@ -1,39 +1,38 @@
require Logger
# RadiusApp.start :normal,[]
use Radius.Dict

# IO.puts inspect RadiusDict.Vendor.by_name("Cisco")
# IO.puts inspect RadiusDict.Attribute.by_name("Service-Type")
# IO.puts inspect RadiusDict.Value.by_name("Service-Type","Login-User")
# IO.puts inspect RadiusDict.Value.by_value(6,11)
# IO.puts inspect RadiusDict.Value.by_name("Cisco","Cisco-Disconnect-Cause","Unknown")
# IO.puts inspect RadiusDict.Value.by_value(9,195,11)
# IO.puts inspect RadiusDict.Value.by_value(9,1950,11)
# IO.puts inspect Radius.Dict.vendor_by_name("Cisco")
# IO.puts inspect Radius.Dict.attribute_by_name("Service-Type")
# IO.puts inspect Radius.Dict.value_by_name("Service-Type","Login-User")
# IO.puts inspect Radius.Dict.value_by_value("Service-Type",11)
# IO.puts inspect Radius.Dict.VendorCisco.value_by_name("Cisco-Disconnect-Cause","Unknown")
# IO.puts inspect Radius.Dict.VendorCisco.value_by_value("Cisco-Disconnect-Cause",11)

secret = "112233"

attrs = [
{"User-Password", "1234"},
attr_User_Password("1234"),
# tagged attribute (rfc2868)
{"Tunnel-Type", "PPTP"},
attr_Tunnel_Type(val_Tunnel_Type_PPTP()),
# equals
{"Tunnel-Type", {0, "PPTP"}},
{"Tunnel-Type", {10, "PPTP"}},
{"Service-Type", "Login-User"},
{attr_Tunnel_Type(), {0, "PPTP"}},
tverlaan marked this conversation as resolved.
Show resolved Hide resolved
attr_Tunnel_Type({10, "PPTP"}),
{attr_Service_Type(), "Login-User"},
# tag & value can be integer
{6, 1},
# ipaddr
{"NAS-IP-Address", {1, 2, 3, 4}},
{"NAS-IP-Address", 0x12345678},
{attr_NAS_IP_Address(), {1, 2, 3, 4}},
{attr_NAS_IP_Address(), 0x12345678},
# ipv6addr
{"Login-IPv6-Host", {2003, 0xEFFF, 0, 0, 0, 0, 0, 4}},
{attr_Login_IPv6_Host(), {2003, 0xEFFF, 0, 0, 0, 0, 0, 4}},
# VSA
{{"Vendor-Specific", 9},
{{attr_Vendor_Specific(), 9},
[
{"Cisco-Disconnect-Cause", 10},
{195, "Unknown"}
]},
# empty VSA?
{{"Vendor-Specific", "Microsoft"}, []},
{{attr_Vendor_Specific(), "Microsoft"}, []},
# some unknown attribute
{255, "123456"}
]
Expand Down
7 changes: 0 additions & 7 deletions lib/radius/application.ex

This file was deleted.

Loading