Fortinet white logo
Fortinet white logo

Script Reference Guide

TCP:persist(t)

TCP:persist(t)

This command is used to manually add or update entries in the persistence table. It allows you to programmatically define custom session affinity by mapping a specific hash key to a real server. This ensures that subsequent traffic with the same identifier is consistently routed to the same backend resource.

Syntax

TCP:persist(t)

Arguments

Name Description

t

A Lua table containing the following fields:

  • operation: (String, Required) Must be set to "save_tbl" .

  • hash_value: (String, Required) The unique identifier to store. It supports a maximum length of 63 characters (longer strings are truncated) and requires all characters to be printable .

  • srv_name: (String, Required) The name of the real server to associate with the hash key.

  • timeout: (Integer, Optional) The duration in seconds that the entry remains in the table. The default value is 300 seconds.

Events

Applicable in the following events:

  • STREAM_REQUEST_DATA

  • STREAM_RESPONSE_DATA

  • STREAM_ PERSISTENCE

Example

In this example, the script captures the client's address, generates a SHA-512 hash, and uses it as a persistence key to pin the session to a specific server pool.

when STREAM_RESPONSE_DATA {
    cip = IP:client_addr()
    hash_str_cip = sha512_hex(cip)
    debug("-----save_tbl-----\n")
    t={}
t["operation"] = "save_tbl"
    t["hash_value"] = hash_str_cip
    t["srv_name"] = "pool1-2"
    ret = TCP:persist(t)
    if ret then
	debug("hash save table success\n");
    else
	debug("save table failed\n");
    end
}

Supported Version

FortiADC version 7.6.7 and later.

TCP:persist(t)

TCP:persist(t)

This command is used to manually add or update entries in the persistence table. It allows you to programmatically define custom session affinity by mapping a specific hash key to a real server. This ensures that subsequent traffic with the same identifier is consistently routed to the same backend resource.

Syntax

TCP:persist(t)

Arguments

Name Description

t

A Lua table containing the following fields:

  • operation: (String, Required) Must be set to "save_tbl" .

  • hash_value: (String, Required) The unique identifier to store. It supports a maximum length of 63 characters (longer strings are truncated) and requires all characters to be printable .

  • srv_name: (String, Required) The name of the real server to associate with the hash key.

  • timeout: (Integer, Optional) The duration in seconds that the entry remains in the table. The default value is 300 seconds.

Events

Applicable in the following events:

  • STREAM_REQUEST_DATA

  • STREAM_RESPONSE_DATA

  • STREAM_ PERSISTENCE

Example

In this example, the script captures the client's address, generates a SHA-512 hash, and uses it as a persistence key to pin the session to a specific server pool.

when STREAM_RESPONSE_DATA {
    cip = IP:client_addr()
    hash_str_cip = sha512_hex(cip)
    debug("-----save_tbl-----\n")
    t={}
t["operation"] = "save_tbl"
    t["hash_value"] = hash_str_cip
    t["srv_name"] = "pool1-2"
    ret = TCP:persist(t)
    if ret then
	debug("hash save table success\n");
    else
	debug("save table failed\n");
    end
}

Supported Version

FortiADC version 7.6.7 and later.