> For the complete documentation index, see [llms.txt](https://docs.cennso.com/components/rpr/latest/llms.txt) (all documentation: [llms.txt](https://docs.cennso.com/llms.txt)). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cennso.com/components/rpr/latest/configuration/aaa-forwarding.md).

# Forwarding of the AAA RADIUS requests

The RADIUS Proxy (RPR) configuration consists of a list of RADIUS Proxy servers and associated relay servers where the incoming requests are forwarded. Each RADIUS Proxy server specifies a RADIUS listener where incoming RADIUS requests are received. Each relay server specifies a RADIUS server where RADIUS Proxy forwards the incoming RADIUS requests.

RADIUS Proxy supports both Authentication and Accounting RADIUS servers. All the Authentication and Accounting RADIUS servers must be configured in one of the following groups:

- **auth** - the list of RADIUS Authentication servers.
- **acct** - the list of RADIUS Accounting servers.

Each RADIUS Authentication proxy server must be configured as **auth.{SERVER_NAME}.*** and each RADIUS Accounting proxy server must be configured as **acct.{SERVER_NAME}.***. The proxy servers may have the following configuration options:

>**NOTE:** All the configuration options listed below are prefixed with **auth.**, but they are also applicable to the RADIUS Accounting servers configured with the **acct.** prefix.

- **auth.{SERVER_NAME}.listen** - the RADIUS server listener address.
- **auth.{SERVER_NAME}.ports** - the list of ports at which RADIUS servers listen for incoming messages. It is recommended to use port `1812` for the RADIUS Authentication server and port `1813` for the RADIUS Accounting server.
- **auth.{SERVER_NAME}.sources** - the list of sources from which the given RADIUS server is allowed to accept incoming RADIUS messages. Each source has mandatory and optional fields:
    - A mandatory source address or a range of addresses in `address/mask` format, defining from where RADIUS Proxy is allowed to accept incoming messages.
    - A mandatory RADIUS secret, which must match the secret used by the RADIUS client sending the requests to the RADIUS Proxy server.
    - An optional **nas_id** value that specifies the Network Access Server (NAS) identifier. For more information, see the [RADIUS server metrics](https://docs.cennso.com/components/rpr/latest/observability/metrics.md#radius-server-metrics).

    RADIUS server silently drops incoming messages with the source address and secret not matching any entry in the list.

    >**CAUTION:** Most RADIUS metrics have labels that specify the NAS name and source IP of the incoming request. Setting wide IP ranges in **auth.{SERVER_NAME}.sources**, **acct.{SERVER_NAME}.sources**, or **coa.sources** may lead to high resource consumption and performance degradation.

- **auth.{SERVER_NAME}.allow_attrs** - the list of RADIUS attributes to preserve in the forwarded request. If the list is empty, RADIUS Proxy preserves all attributes. Otherwise, only the RADIUS attributes from the list are preserved.
- **auth.{SERVER_NAME}.relays** - the list of RADIUS relays where RADIUS Proxy forwards the incoming RADIUS requests. Each relay has mandatory and optional parameters:
    - **auth.{SERVER_NAME}.relays.{RELAY}.address** - a mandatory address, which the RADIUS Proxy uses to forward incoming messages. This can be an IP address or an FQDN. If the FQDN name is provided in the relay, and it resolves to multiple IP addresses, RPR distributes requests to all of them in a random order.

    >**CAUTION:** If the FQDN name can not be resolved, RPR prints an error about it during start-up and exits.

    - **auth.{SERVER_NAME}.relays.{RELAY}.secret** - A mandatory RADIUS secret, which must match the RADIUS secret of the side where the incoming message is forwarded.
    - **auth.{SERVER_NAME}.relays.{RELAY}.realm** - An optional parameter that controls the routing for the given relay. RADIUS Proxy uses realms to determine where to forward the given RADIUS request. A realm is a part of the [User-Name](https://www.rfc-editor.org/rfc/rfc2865#section-5.1) RADIUS attribute provided in the [Network Access Identifier](https://www.rfc-editor.org/rfc/rfc2486#section-2.4) format. If a realm is not specified in the RADIUS relay configuration, such a relay is a `default` relay. RPR uses the default relay to forward all requests if no relay with a suitable realm is found.

    >**NOTE:** Each RADIUS server that is configured in RADIUS Proxy must have only one default relay.

    - **auth.{SERVER_NAME}.relays.{RELAY}.timeout** - the number of milliseconds RADIUS Proxy waits for the response. If not specified in the configuration, the default value of `5000` is used.
    - **auth.{SERVER_NAME}.relays.{RELAY}.retries** - the number of tries to re-send a RADIUS request failed by timeout to the given RADIUS relay. If not specified, the default value of `3` is used. If the number of retries for a primary RADIUS server is exhausted, the failover RADIUS servers are used. Only after that, the client returns a response or an error. For more information, see the [RADIUS servers for failover scenarios](https://docs.cennso.com/components/rpr/latest/configuration/failover-servers.md) document.
    - **auth.{SERVER_NAME}.relays.{RELAY}.failover_server_pool** - the name of a pool of secondary RADIUS servers used for failover scenarios. For more information, see the [RADIUS servers for failover scenarios](https://docs.cennso.com/components/rpr/latest/configuration/failover-servers.md) document.

In the next section, you can see a configuration example that may help you better understand these configuration options.

## Configuration example for AAA RADIUS requests forwarding

This section provides a RADIUS Proxy configuration example that accepts the incoming RADIUS messages from one side and forwards them to another.

Look at the RADIUS Proxy configuration example:

```yaml
auth:
  1:
    listen: 0.0.0.0
    ports:
      - 1812
    sources:
      - source: 172.16.2.1
        secret: "secret-pgw-1"
        nas_id: PGW1
      - source: 172.16.2.2
        secret: "secret-pgw-2"
        nas_id: PGW2
      - source: 172.16.2.3
        secret: "secret-pgw-3"
        nas_id: PGW3
    allow_attrs: []
    relays:
      - address: "radius-server-1-host:1812"
        secret: "radius-server-1-secret"
        timeout: 5000
        retries: 3
      - address: "radius-server-2-host:1812"
        secret: "radius-server-2-secret"
        realm: "pgw-nas-2"

acct:
  1:
    listen: 0.0.0.0
    ports:
      - 1813
    sources:
      - source: 172.16.2.1
        secret: "secret-pgw-1"
        nas_id: PGW1
    allow_attrs: []
    relays:
      - address: "radius-server-1-host:1813"
        secret: "radius-server-1-secret"
```

In the example above, you can see the definition of two RADIUS Proxy servers:

- `proxy_auth_1`
- `proxy_acct_1`

The names of RADIUS servers are built by combining the `proxy_` prefix with `auth` or `acct` and the server identifier. Instead of `1`, you can choose any suitable identifier for the RADIUS server. The server identifier only impacts [metrics](https://docs.cennso.com/components/rpr/latest/observability/metrics.md#radius-server-metrics).

The first proxy defines the RADIUS Authentication server, while the second defines the RADIUS Accounting server. Both proxy servers listen on the `0.0.0.0` address but use different ports: the RADIUS Authentication server listens on port `1812`, and the RADIUS Accounting server listens on port `1813`.

According to the **auth.1.sources** and **acct.1.sources** configuration options:

- The RADIUS Authentication server accepts the incoming RADIUS requests only from `172.16.2.1`, `172.16.2.2`, and `172.16.2.3` addresses. Each request must include one of the configured secrets, with the correct secret determined by the source address of the incoming request.
  - For all the requests coming from the `172.16.2.1` address, the secret must be `secret-pgw-1`.
  - For all the requests coming from the `172.16.2.2` address, the secret must be `secret-pgw-2`.
  - For all the requests coming from the `172.16.2.3` address, the secret must be `secret-pgw-3`.
- The RADIUS Accounting server accepts incoming RADIUS requests only from the `172.16.2.1` address. All requests from this source must have the secret `secret-pgw-1`.

After RADIUS Proxy receives the incoming RADIUS request and it is allowed according to the **auth.1.sources** or **acct.1.sources** configuration, the message is forwarded to one of the specified relays.

All the incoming RADIUS Authentication requests are forwarded to one of these relays:

- `radius-server-1-host:1812`
- `radius-server-2-host:1812`

All the incoming RADIUS Accounting requests are forwarded to the `radius-server-1-host:1813` relay.

>**NOTE:** All the hostnames in the example above must be valid and resolvable to the IP address(es).

The server where RADIUS Proxy forwards an incoming RADIUS request depends on the content of the request and the value specified in the **auth.1.relays[].realm** or **acct.1.relays[].realm**. The incoming request is forwarded to the relay whose `realm` is matched with the realm specified in the [User-Name](https://www.rfc-editor.org/rfc/rfc2865#section-5.1) attribute from the incoming request.

If the incoming RADIUS Authentication request contains the `pgw-nas` realm in the `User-Name` attribute, RADIUS Proxy forwards this request to the `radius-server-2-host:1812` RADIUS server, since this relay is configured to handle the `pgw-nas` realm.

If there is no relay with a realm matched with the realm from the value of the `User-Name` attribute,  the request is forwarded to the default relay. The default relay is a relay without any realm specified in its configuration. In the example above, the default relay is `radius-server-1-host:1812`. The secret used for the outgoing RADIUS message is taken from the relay’s configuration.

The RADIUS Accounting server does not specify any relays with a realm in the example above. As a result, all the incoming RADIUS requests are forwarded to the default relay - `radius-server-1-host:1813`.

The lists of allowed RADIUS attributes specified under **auth.1.allow_attrs** and **acct.1.allow_attrs** are empty, so no filters are applied to the incoming RADIUS requests.

This diagram shows the possible flow of RADIUS requests based on the configuration example described above:

```mermaid
sequenceDiagram
  participant RADIUS-client-1
  participant RADIUS-client-2
  participant RADIUS-client-3

  participant RPR
  participant RADIUS-server-1
  participant RADIUS-server-2

  par [RADIUS Client 1 TO RPR]
    RADIUS-client-1->>RPR: RADIUS Access-Request
    Note over RADIUS-client-1,RPR: Source address: 172.16.2.1 <br/> Secret: secret-pgw-1 <br/> Nas-Identifier: PGW-1 <br/> User-Name: user1@pgw-nas-1
    RPR->>RADIUS-server-1: RADIUS Access-Request
    Note over RPR,RADIUS-server-1: No realm matched. <br/> Send to default relay. <br/> Secret: radius-server-1-secret
    RADIUS-server-1->>RPR: RADIUS Access-Accept
    RPR->>RADIUS-client-1: RADIUS Access-Accept

    RADIUS-client-1->>RPR: RADIUS Accounting-Request
    Note over RADIUS-client-1,RPR: Source address: 172.16.2.1<br/>Secret: secret-pgw-1 <br/> Nas-Identifier: PGW-1 <br/> User-Name: user1@pgw-nas-1
    RPR->>RADIUS-server-1: RADIUS Accounting-Request
    Note over RPR,RADIUS-server-1: No realm matched. <br/> Send to default relay. <br/> Secret: radius-server-1-secret
    RADIUS-server-1->>RPR: RADIUS Accounting-Response
    RPR->>RADIUS-client-1: RADIUS Accounting-Response

  and RADIUS Client 2 TO RPR
    RADIUS-client-2->>RPR: RADIUS Access-Request
    Note over RADIUS-client-2,RPR: Source address: 172.16.2.2 <br/> Secret: secret-pgw-2 <br/> Nas-Identifier: PGW-2 <br/> User-Name: user1@pgw-nas-1
    RPR->>RADIUS-server-1: RADIUS Access-Request
    Note over RPR,RADIUS-server-1: No realm matched. <br/> Send to default relay. <br/> Secret: radius-server-1-secret
    RADIUS-server-1->>RPR: RADIUS Access-Accept
    RPR->>RADIUS-client-2: RADIUS Access-Accept

  and RADIUS Client 3 TO RPR
    RADIUS-client-3->>RPR: RADIUS Access-Request
    Note over RADIUS-client-3,RPR: Source address: 172.16.2.3 <br/> Secret: secret-pgw-3 <br/> Nas-Identifier: PGW-2 <br/> User-Name: user1@pgw-nas-2
    RPR->>RADIUS-server-2: RADIUS Access-Request
    Note over RPR,RADIUS-server-2: Realm matched. <br /> Send to the relay based on realm. <br/> Secret: radius-server-2-secret
    RADIUS-server-2->>RPR: RADIUS Access-Accept
    RPR->>RADIUS-client-3: RADIUS Access-Accept
    
 and RADIUS Client 3 TO RPR
   RADIUS-client-3->>RPR: RADIUS Access-Request
   Note over RADIUS-client-3,RPR: Source address: 100.100.100.1 <br/> Secret: secret-pgw-4
   RPR->>RPR: Unknown source and secret. <br/> Request is dropped.
end
```
