4.26.2.1. Configuring policies for TFTP commands

Changing the default behaviour of requests is possible using the request attribute. This hash is indexed by the request method ("read" or "write"), and the requested filename. If the hash contains no entry for a given combination, the "*" entry is used. If there is no matching entry in the hash, the command is rejected. The possible actions are described in the following table. See also Section 2.1, Policies for requests and responses.

ActionDescription
TFTP_REQ_ACCEPT Allow the request to pass.
TFTP_REQ_REJECT Reject the request and send an error message. Message code and text can be specified as second and third elements of the tuple.
TFTP_REQ_DROP Drop the packet.
TFTP_REQ_POLICY Call the function specified to make a decision about the event. The function receives four parameters: self, the method ("read"/"write"), the file name and the encoding used in the request. See Section 2.1, Policies for requests and responses for details.
TFTP_REQ_REWRITE Rewrite filename and/or encoding and accept the packet. See Section Rewriting the request for details.

Table 4.78.  Action codes on TFTP requests

Rewriting the request

To rewrite and accept a request, the hash value must be a tuple containing TFTP_REQ_REWRITE as the first value, and the filename and encoding to be sent to the server as the second and third values.

Responding with a custom error

To respond with a user-defined error code and message, the hash value must be a tuple containing TFTP_REQ_ERROR as the first value, the error code (an integer as defined by the TFTP RFC) as the second one, and the error message as the third. The session is (obviously) terminated; the TFTP server is not notified.