Skip to content

Commit

Permalink
Move work to compiler (#6)
Browse files Browse the repository at this point in the history
* Move work to compiler

Previously dicts were parsed and stored in ETS on application startup.
This commit introduces modules to get vendors, attributes and values.
This saves time during startup of the application. Secondly this opens
the possibility to offer a set of macros that will replace the macro
with the correct value at compile time instead of the encoding phase at
runtime. This should also decrease the amount of times you run into
EntryNotFoundError.

nimble_parsec is compiled into a module so that users of the library
don't have to add nimble_parsec as a dep themselves.

* Add option to specify extra dictionaries outside of this repo

* Only filter included dictionaries when the library is configured

* Fixes `example.exs`
  • Loading branch information
tverlaan committed Jun 7, 2023
1 parent c256e9f commit 057d46f
Show file tree
Hide file tree
Showing 164 changed files with 4,277 additions and 509 deletions.
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.
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"}},
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.

0 comments on commit 057d46f

Please sign in to comment.