Fortinet white logo
Fortinet white logo

Script Reference Guide

TCP:lookup_tbl(t)

TCP:lookup_tbl(t)

This command is used to search the persistence table for an existing entry based on a specific hash key. If a matching real server (RS) is found and it is currently healthy, the command automatically sets that RS as the destination peer for the current session. If no match is found, the system falls back to the standard load-balancing persistence or method.

Syntax

TCP:lookup_tbl(t)

Arguments

Name Description

t

A Lua table containing the following field:

  • hash_value: (String, Required) The unique identifier to look up in the persistence table. Supports a maximum length of 63 characters (longer strings are truncated) and requires all characters to be printable.

Events

Applicable in the following events:

  • STREAM_REQUEST_DATA

  • STREAM_ PERSISTENCE

Example

In this example, the script performs a lookup using the client’s IP address. If the lookup is successful, the session is pinned to the previously stored real server.

when STREAM_PERSISTENCE {
    cip = IP:client_addr()  
    t={}
    t["operation"] = "save_tbl"
    t["hash_value"] = 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
 
    t={}
    t["hash_value"] = cip
    ret = TCP:lookup_tbl(t)
    if ret then 
        debug("hash LOOKUP success\n")
    else
        debug("hash lookup failed\n")
    end
} 

Supported Version

FortiADC version 7.6.7 and later.

TCP:lookup_tbl(t)

TCP:lookup_tbl(t)

This command is used to search the persistence table for an existing entry based on a specific hash key. If a matching real server (RS) is found and it is currently healthy, the command automatically sets that RS as the destination peer for the current session. If no match is found, the system falls back to the standard load-balancing persistence or method.

Syntax

TCP:lookup_tbl(t)

Arguments

Name Description

t

A Lua table containing the following field:

  • hash_value: (String, Required) The unique identifier to look up in the persistence table. Supports a maximum length of 63 characters (longer strings are truncated) and requires all characters to be printable.

Events

Applicable in the following events:

  • STREAM_REQUEST_DATA

  • STREAM_ PERSISTENCE

Example

In this example, the script performs a lookup using the client’s IP address. If the lookup is successful, the session is pinned to the previously stored real server.

when STREAM_PERSISTENCE {
    cip = IP:client_addr()  
    t={}
    t["operation"] = "save_tbl"
    t["hash_value"] = 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
 
    t={}
    t["hash_value"] = cip
    ret = TCP:lookup_tbl(t)
    if ret then 
        debug("hash LOOKUP success\n")
    else
        debug("hash lookup failed\n")
    end
} 

Supported Version

FortiADC version 7.6.7 and later.