Stream Scripting configuration overview
You can use Stream scripts to perform actions that are not supported by the current built-in feature set for Layer 7 TCP and UDP virtual servers. Stream scripts enable you to use predefined script commands and variables to manipulate the TCP/UDP request and response.
Stream scripts are composed of several functional components that define the trigger events, commands, operators, and more. The following example demonstrates how Stream scripting is applied to return the client IP address of a connection for the frontend, it's source address for the backend, and it's destination address.
The Stream script:
when STREAM_RESPONSE_DATA {
local cip=IP:client_addr()
local lip=IP:local_addr()
local rip=IP:remote_addr()
local cp=IP:client_port()
local lp=IP:local_port()
local rp=IP:remote_port()
local cipv=IP:client_ip_ver()
local sip=IP:server_addr()
local sp=IP:server_port()
local sipv=IP:server_ip_ver()
debug("resp: remote %s:%s, client %s:%s, local %s:%s, cip version %s\n", rip, rp, cip, cp, lip, lp, cipv)
debug("resp: server %s:%s, sip version %s\n", sip, sp, sipv)
log("resp: remote %s:%s, client %s:%s, local %s:%s, cip version %s", rip, rp, cip, cp, lip, lp, cipv)
log("resp: server %s:%s, sip version %s", sip, sp, sipv)
}
Stream script component breakdown:
|
Parameter |
Example |
Description |
|---|---|---|
|
Events — for details, see Stream Scripting events. |
||
|
STREAM_RESPONSE_DATA |
When a response comes from a real server. |
|
|
Commands — for details, see Predefined Stream Scripting commands. |
||
| IP:client_addr() | Returns the client IP address of a connection for the frontend, it's source address for the backend, and it's destination address. | |
|
|
IP:local_addr() | For the frontend, this returns the IP address of the virtual server that the client is connected to. For the backend, this returns the incoming interface IP address of the return packet. |
|
|
IP:remote_addr() | Returns the IP address of the host on the far end of the connection. |
|
|
IP:client_port() | Returns the local port number. In the frontend, the local port is the virtual server port. In the backend, the local port is the port of the gateway used to connect. |
|
|
IP:local_port() | Returns the local port number. In the frontend, the local port is the virtual server port. In the backend, the local port is the port of the gateway used to connect. |
|
|
IP:remote_port() |
Returns the remote port number. In the frontend, the remote port is the client port. In the backend, the remote port is the real server port. |
|
|
IP:client_ip_ver() |
Returns the current client IP version number of the connection, either 4 or 6. |
|
|
IP:server_addr() |
Returns the IP address of the server in backend. |
|
|
IP:server_port() |
Returns the server port number, which is the real server port. |
|
|
IP:server_ip_ver() |
Returns the current server IP version number of the connection, either 4 or 6. |
|
Operators — for details, see Operators. (Not applicable in this example). |
||
| Strings — for details, see String library. (Not applicable in this example). | ||
| Control structures — for details, see Control structures. (Not applicable in this example). | ||
|
Functions — for details, see Functions. (Not applicable in this example). |
||
Configuring Stream Scripting
From the FortiADC GUI, you can type or paste the script content into the configuration page. Alternatively, you can clone a system predefined script to customize. For details, see . From the HTTP Script page, you also have the option to import, export, and delete scripts.
Before you begin:
- You must have Read-Write permission for Server Load Balance settings.
After you have created a script configuration object, you can specify it in the virtual server configuration.
To create a Stream script configuration object:
- Go to Server Load Balance > Scripting.
- Click the Stream tab.
- Click Create New to display the configuration editor.

- Enter a unique name for the Stream script configuration. Valid characters are
A-Z,a-z,0-9,_, and-. No spaces. After you initially save the configuration, you cannot edit the name. - In the text box, type or paste your Stream script.
If you want to include this script as part of a multi-script configurations that allows you to execute multiple scripts in a certain order, ensure to set its priority. For more information, see Multi-script support for Stream Scripting. - Click Save.
Once the Stream script configuration is saved, you can specify it in the virtual server.
To import a Stream script:
- Go to Server Load Balance > Scripting.
- Click the Stream tab.
-
Click Import to display the file import options.

-
Click Choose File and browse for the script file. Supported file types are .tar, .tar.gz, and .zip.
-
Click Save.
Once the file is successfully imported, it will be listed in the Scripting > Stream page.
To export a Stream script:
- Go to Server Load Balance > Scripting.
- Click the Stream tab.
-
From the Stream page, select a Stream script configuration.
In the example below, the IP_COMMANDS script is selected.
-
Click Export initiate the file download.
The selected script configuration will be exported as a .tar file.
To delete a Stream script:
- Go to Server Load Balance > Scripting.
- Click the Stream tab.
-
From the Stream page, select a user-defined Stream script configuration. System predefined scripts cannot be deleted.
In the example below, the test_stream script configuration is selected.
-
Click Delete from the top navigation, or click
(delete icon) of the configuration.
Multiple script configurations can be deleted using the Delete button on the top navigation.