> 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/disconnect-forwarding.md).

# Forwarding of the Disconnect RADIUS requests

Besides forwarding the [RADIUS Authorization and Accounting](https://docs.cennso.com/components/rpr/latest/configuration/aaa-forwarding.md) requests, RADIUS Proxy (RPR) also supports forwarding of the [RADIUS CoA and Disconnect](https://www.ietf.org/rfc/rfc3576.txt) requests.

You can configure RADIUS CoA and Disconnect servers and relays using these configuration options:

- **coa.listen** - the RADIUS server listener address.
- **coa.port** - the RADIUS server listener port. Only a single value is supported. It is recommended to use port `3799` for RADIUS CoA and Disconnect requests.
- **coa.sources** - the list of sources from which the given RADIUS server is allowed to accept incoming RADIUS CoA and Disconnect messages. Each source must provide a RADIUS secret, the source address or range of addresses in the `address/mask` format, and the optional **nas_id**. The logic of handling the CoA sources configuration is the same as in [Forwarding of the AAA RADIUS requests](https://docs.cennso.com/components/rpr/latest/configuration/aaa-forwarding.md).
- **coa.allow_attrs** - the list of RADIUS attributes to preserve in the forwarded request. If the list is empty, RADIUS Proxy preserves all attributes. If the list is not empty, only the given RADIUS attributes are preserved in the forwarded request.
- **coa.remove_attrs** - the list of RADIUS attributes removed from all incoming RADIUS CoA and Disconnect requests.
- **coa.route_attr** - the name of the RADIUS attribute used by RADIUS Proxy to determine where to forward incoming CoA and Disconnect requests.
- **coa.relays** - the list of RADIUS relays where RADIUS Proxy forwards the incoming RADIUS requests. Each relay must have an address and a RADIUS secret specified. The address is used by RADIUS Proxy to forward incoming messages. The secret must match the secret of the side where the message is forwarded. If instead of an IP address, the FQDN name is provided in the relay configuration 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.

    To determine where to forward the given RADIUS request, RADIUS Proxy uses the value of the **coa.route_attr** configuration option. When a RADIUS request arrives at RADIUS Proxy, it fetches the value of the RADIUS attribute specified in the **coa.route_attr** configuration option. If the attribute value matches the value given in one of **coa.relays.{RELAY}.route_attr**, the message is forwarded to that relay. If there is no suitable relay found, the default relay is used. The default relay is the relay that does not contain the optional **coa.relays.{RELAY}.route_attr** configuration option. If the default relay is not specified in the configuration, and no suitable relays to forward the RADIUS CoA or Disconnect request, RPR answers with the `CoA-NAK` or `Disconnect-NAK` respectively.
- **coa.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.
- **coa.relays.{RELAY}.retries** - the number of re-tries to 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.
- **coa.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 understand these configuration options.

## Configuration example for forwarding of the RADIUS Disconnect requests

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

Look at the example of the RADIUS Proxy configuration:

```yaml
coa:
  listen: 0.0.0.0
  port: 3799
  sources:
    - secret: "ocs-1-secret"
      source: 172.2.1.1
      nas_id: OCS-1
  allow_attrs: ["NAS-IP-Address", "Acct-Session-Id", "Framed-IP-Address"]
  route_attr: "NAS-IP-Address"
  relays:
      # Relay to forward requests with NAS-IP-Address = 200.201.202.204  
    - address: "radius-server-1:3799"
      secret: "radius-server-1-secret"
      retries: 1
      route_attr: "200.201.202.204"
      timeout: 3000
      # Default relay without route_attr
    - address: "radius-server-2:3799"
      secret: "radius-server-2-secret"
      timeout: 5000
      retries: 1
```

In the example above, there is a definition of a single RADIUS server which listens for incoming RADIUS requests at the `0.0.0.0` address and `3799` port.

According to the **coa.sources[].source** configuration, the RADIUS server may accept the incoming RADIUS requests only from the `172.2.1.1` address. All such requests must have a secret value `ocs-1-secret`. If the incoming request arrives at this RADIUS server with a different source address or its secret does not match, such a request is silently dropped.

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

All of the incoming RADIUS requests are forwarded to one of two possible relays:

- `radius-server-1:3799`
- `radius-server-2:3799`

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

The server where RADIUS Proxy forwards the given incoming RADIUS request depends on the attributes located in the request. In the example above, **coa.route_attr** is configured with `NAS-IP-Address`. RADIUS Proxy checks the value of this attribute for each incoming RADIUS request. If the value of `NAS-IP-Address` is `200.201.202.204` like in the first relay, the request is forwarded to `radius-server-1:3799`. Otherwise, the default relay `radius-server-2:3799` is used. To communicate with the remote RADIUS server, RADIUS Proxy uses a secret defined in the relay where the message is sent.

The list of allowed RADIUS attributes (**allow_attrs**) is not empty, so only these attributes are preserved in the outgoing RADIUS messages:

- `NAS-IP-Address`
- `Acct-Session-Id`
- `Framed-IP-Address`

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 Disconnect-Request
    Note over RADIUS-client-1,RPR: Source address: 172.2.1.1 <br/> Secret: ocs-1-secret <br/> NAS-IP-Address: 200.201.202.204
    RPR->>RADIUS-server-1: RADIUS Disconnect-Request
    Note over RPR,RADIUS-server-1: NAS-IP-Address matched. <br/> Send to the given relay based on configuration. <br/> Secret: radius-server-1-secret
    RADIUS-server-1->>RPR: RADIUS Disconnect-Ack
    RPR->>RADIUS-client-1: RADIUS Disconnect-Ack

  and RADIUS Client 1 TO RPR
    RADIUS-client-1->>RPR: RADIUS Disconnect-Request
    Note over RADIUS-client-1,RPR: Source address: 172.2.1.1 <br/> Secret: ocs-1-secret <br/> NAS-IP-Address: 200.201.202.205
    RPR->>RADIUS-server-2: RADIUS Disconnect-Request
    Note over RPR,RADIUS-server-1: NAS-IP-Address is not matched. <br/> Send to the default relay. <br/> Secret: radius-server-2-secret
    RADIUS-server-2->>RPR: RADIUS Disconnect-Ack
    RPR->>RADIUS-client-1: RADIUS Disconnect-Ack

  and RADIUS Client 2 TO RPR
    RADIUS-client-2->>RPR: RADIUS Disconnect-Request
    Note over RADIUS-client-2,RPR: Source address: 172.16.2.3 <br/> Secret: secret-pgw-3
    RPR->>RPR: Unknown source and secret. <br/> Request is dropped.
end
```
