1. Maxfwd Module

Bogdan Iancu

FhG FOKUS

1.1. Overview
1.2. Functions
1.2.1. maxfwd_process(max_value)
1.2.2. maxfwd_at_least(min_value)

1.1. Overview

The module implements all the operations regarding MaX-Forward header field, like adding it (if not present) or decrementing and checking the value of the existent one.

1.2. Functions

1.2.1.  maxfwd_process(max_value)

If no Max-Forward header is present in the received request, a header will be added having the original value equal with "max_value". An OK code is returned by the function.

If a Max-Forward header is already present, its value will be decremented. If after this operation its value will be positive non-zero, an OK code will be returned. Otherwise (for a zero value) an error code will be returned. Note that an error code will be also returned if the SIP message couldn't be parsed or if the Max-Forward header's body invalid (non numerical string or negative numerical value).

Meaning of the parameters is as follows:

  • max_value - Value to be added if there is no Max-Forwards header field in the message.

Example 1. maxfwd_process usage

# initial sanity checks -- messages with
# max_forwards==0, or excessively long requests
if (!maxfwd_process(10)) {
    sl_send_reply(483, "Too many hops");
    drop;
};

1.2.2.  maxfwd_at_least(min_value)

Test is there is enough hops in Max-forward header, i.e. we know how many hops is required to reach target. Returns true if Max-Forward header is present in the received request and the value is greater than "min_value".

Meaning of the parameters is as follows:

  • min_value - Min. number of required hops

Example 2. maxfwd_at_least usage

if (!maxfwd_at_least(3)) {
    sl_send_reply(483, "Too many hops");
    drop;
};