:sphinx.addnodesdocument)}( rawsourcechildren]( translations LanguagesNode)}(hhh](h pending_xref)}(hhh]docutils.nodesTextChinese (Simplified)}parenthsba attributes}(ids]classes]names]dupnames]backrefs] refdomainstdreftypedoc reftarget(/translations/zh_CN/networking/strparsermodnameN classnameN refexplicitutagnamehhh ubh)}(hhh]hChinese (Traditional)}hh2sbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget(/translations/zh_TW/networking/strparsermodnameN classnameN refexplicituh1hhh ubh)}(hhh]hItalian}hhFsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget(/translations/it_IT/networking/strparsermodnameN classnameN refexplicituh1hhh ubh)}(hhh]hJapanese}hhZsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget(/translations/ja_JP/networking/strparsermodnameN classnameN refexplicituh1hhh ubh)}(hhh]hKorean}hhnsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget(/translations/ko_KR/networking/strparsermodnameN classnameN refexplicituh1hhh ubh)}(hhh]hSpanish}hhsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget(/translations/sp_SP/networking/strparsermodnameN classnameN refexplicituh1hhh ubeh}(h]h ]h"]h$]h&]current_languageEnglishuh1h hh _documenthsourceNlineNubhcomment)}(h SPDX-License-Identifier: GPL-2.0h]h SPDX-License-Identifier: GPL-2.0}hhsbah}(h]h ]h"]h$]h&] xml:spacepreserveuh1hhhhhhB/var/lib/git/docbuild/linux/Documentation/networking/strparser.rsthKubhsection)}(hhh](htitle)}(hStream Parser (strparser)h]hStream Parser (strparser)}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(h Introductionh]h Introduction}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhhhhhKubh paragraph)}(hXoThe stream parser (strparser) is a utility that parses messages of an application layer protocol running over a data stream. The stream parser works in conjunction with an upper layer in the kernel to provide kernel support for application layer messages. For instance, Kernel Connection Multiplexor (KCM) uses the Stream Parser to parse messages using a BPF program.h]hXoThe stream parser (strparser) is a utility that parses messages of an application layer protocol running over a data stream. The stream parser works in conjunction with an upper layer in the kernel to provide kernel support for application layer messages. For instance, Kernel Connection Multiplexor (KCM) uses the Stream Parser to parse messages using a BPF program.}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK hhhhubh)}(hJThe strparser works in one of two modes: receive callback or general mode.h]hJThe strparser works in one of two modes: receive callback or general mode.}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh)}(hIn receive callback mode, the strparser is called from the data_ready callback of a TCP socket. Messages are parsed and delivered as they are received on the socket.h]hIn receive callback mode, the strparser is called from the data_ready callback of a TCP socket. Messages are parsed and delivered as they are received on the socket.}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh)}(hIn general mode, a sequence of skbs are fed to strparser from an outside source. Message are parsed and delivered as the sequence is processed. This modes allows strparser to be applied to arbitrary streams of data.h]hIn general mode, a sequence of skbs are fed to strparser from an outside source. Message are parsed and delivered as the sequence is processed. This modes allows strparser to be applied to arbitrary streams of data.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhhhhubeh}(h] introductionah ]h"] introductionah$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(h Interfaceh]h Interface}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhKubh)}(hX@The API includes a context structure, a set of callbacks, utility functions, and a data_ready function for receive callback mode. The callbacks include a parse_msg function that is called to perform parsing (e.g. BPF parsing in case of KCM), and a rcv_msg function that is called when a full message has been completed.h]hX@The API includes a context structure, a set of callbacks, utility functions, and a data_ready function for receive callback mode. The callbacks include a parse_msg function that is called to perform parsing (e.g. BPF parsing in case of KCM), and a rcv_msg function that is called when a full message has been completed.}(hj-hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK hjhhubeh}(h] interfaceah ]h"] interfaceah$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(h Functionsh]h Functions}(hjFhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjChhhhhK'ubh block_quote)}(hX :: strp_init(struct strparser *strp, struct sock *sk, const struct strp_callbacks *cb) Called to initialize a stream parser. strp is a struct of type strparser that is allocated by the upper layer. sk is the TCP socket associated with the stream parser for use with receive callback mode; in general mode this is set to NULL. Callbacks are called by the stream parser (the callbacks are listed below). :: void strp_pause(struct strparser *strp) Temporarily pause a stream parser. Message parsing is suspended and no new messages are delivered to the upper layer. :: void strp_unpause(struct strparser *strp) Unpause a paused stream parser. :: void strp_stop(struct strparser *strp); strp_stop is called to completely stop stream parser operations. This is called internally when the stream parser encounters an error, and it is called from the upper layer to stop parsing operations. :: void strp_done(struct strparser *strp); strp_done is called to release any resources held by the stream parser instance. This must be called after the stream processor has been stopped. :: int strp_process(struct strparser *strp, struct sk_buff *orig_skb, unsigned int orig_offset, size_t orig_len, size_t max_msg_size, long timeo) strp_process is called in general mode for a stream parser to parse an sk_buff. The number of bytes processed or a negative error number is returned. Note that strp_process does not consume the sk_buff. max_msg_size is maximum size the stream parser will parse. timeo is timeout for completing a message. :: void strp_data_ready(struct strparser *strp); The upper layer calls strp_tcp_data_ready when data is ready on the lower socket for strparser to process. This should be called from a data_ready callback that is set on the socket. Note that maximum messages size is the limit of the receive socket buffer and message timeout is the receive timeout for the socket. :: void strp_check_rcv(struct strparser *strp); strp_check_rcv is called to check for new messages on the socket. This is normally called at initialization of a stream parser instance or after strp_unpause. h](jU)}(hX:: strp_init(struct strparser *strp, struct sock *sk, const struct strp_callbacks *cb) Called to initialize a stream parser. strp is a struct of type strparser that is allocated by the upper layer. sk is the TCP socket associated with the stream parser for use with receive callback mode; in general mode this is set to NULL. Callbacks are called by the stream parser (the callbacks are listed below). :: void strp_pause(struct strparser *strp) Temporarily pause a stream parser. Message parsing is suspended and no new messages are delivered to the upper layer. :: void strp_unpause(struct strparser *strp) Unpause a paused stream parser. :: void strp_stop(struct strparser *strp); strp_stop is called to completely stop stream parser operations. This is called internally when the stream parser encounters an error, and it is called from the upper layer to stop parsing operations. :: void strp_done(struct strparser *strp); strp_done is called to release any resources held by the stream parser instance. This must be called after the stream processor has been stopped. :: int strp_process(struct strparser *strp, struct sk_buff *orig_skb, unsigned int orig_offset, size_t orig_len, size_t max_msg_size, long timeo) h](h literal_block)}(h[strp_init(struct strparser *strp, struct sock *sk, const struct strp_callbacks *cb)h]h[strp_init(struct strparser *strp, struct sock *sk, const struct strp_callbacks *cb)}hj`sbah}(h]h ]h"]h$]h&]hhuh1j^hhhK+hjZubh)}(hX:Called to initialize a stream parser. strp is a struct of type strparser that is allocated by the upper layer. sk is the TCP socket associated with the stream parser for use with receive callback mode; in general mode this is set to NULL. Callbacks are called by the stream parser (the callbacks are listed below).h]hX:Called to initialize a stream parser. strp is a struct of type strparser that is allocated by the upper layer. sk is the TCP socket associated with the stream parser for use with receive callback mode; in general mode this is set to NULL. Callbacks are called by the stream parser (the callbacks are listed below).}(hjnhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK.hjZubj_)}(h'void strp_pause(struct strparser *strp)h]h'void strp_pause(struct strparser *strp)}hj|sbah}(h]h ]h"]h$]h&]hhuh1j^hhhK6hjZubh)}(huTemporarily pause a stream parser. Message parsing is suspended and no new messages are delivered to the upper layer.h]huTemporarily pause a stream parser. Message parsing is suspended and no new messages are delivered to the upper layer.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK8hjZubj_)}(h)void strp_unpause(struct strparser *strp)h]h)void strp_unpause(struct strparser *strp)}hjsbah}(h]h ]h"]h$]h&]hhuh1j^hhhK=hjZubh)}(hUnpause a paused stream parser.h]hUnpause a paused stream parser.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK?hjZubj_)}(h'void strp_stop(struct strparser *strp);h]h'void strp_stop(struct strparser *strp);}hjsbah}(h]h ]h"]h$]h&]hhuh1j^hhhKChjZubh)}(hstrp_stop is called to completely stop stream parser operations. This is called internally when the stream parser encounters an error, and it is called from the upper layer to stop parsing operations.h]hstrp_stop is called to completely stop stream parser operations. This is called internally when the stream parser encounters an error, and it is called from the upper layer to stop parsing operations.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKEhjZubj_)}(h'void strp_done(struct strparser *strp);h]h'void strp_done(struct strparser *strp);}hjsbah}(h]h ]h"]h$]h&]hhuh1j^hhhKLhjZubh)}(hstrp_done is called to release any resources held by the stream parser instance. This must be called after the stream processor has been stopped.h]hstrp_done is called to release any resources held by the stream parser instance. This must be called after the stream processor has been stopped.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKNhjZubj_)}(hint strp_process(struct strparser *strp, struct sk_buff *orig_skb, unsigned int orig_offset, size_t orig_len, size_t max_msg_size, long timeo)h]hint strp_process(struct strparser *strp, struct sk_buff *orig_skb, unsigned int orig_offset, size_t orig_len, size_t max_msg_size, long timeo)}hjsbah}(h]h ]h"]h$]h&]hhuh1j^hhhKThjZubeh}(h]h ]h"]h$]h&]uh1jThhhK)hjVubh)}(hX0strp_process is called in general mode for a stream parser to parse an sk_buff. The number of bytes processed or a negative error number is returned. Note that strp_process does not consume the sk_buff. max_msg_size is maximum size the stream parser will parse. timeo is timeout for completing a message.h]hX0strp_process is called in general mode for a stream parser to parse an sk_buff. The number of bytes processed or a negative error number is returned. Note that strp_process does not consume the sk_buff. max_msg_size is maximum size the stream parser will parse. timeo is timeout for completing a message.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKXhjVubj_)}(h-void strp_data_ready(struct strparser *strp);h]h-void strp_data_ready(struct strparser *strp);}hjsbah}(h]h ]h"]h$]h&]hhuh1j^hhhK`hjVubh)}(hX;The upper layer calls strp_tcp_data_ready when data is ready on the lower socket for strparser to process. This should be called from a data_ready callback that is set on the socket. Note that maximum messages size is the limit of the receive socket buffer and message timeout is the receive timeout for the socket.h]hX;The upper layer calls strp_tcp_data_ready when data is ready on the lower socket for strparser to process. This should be called from a data_ready callback that is set on the socket. Note that maximum messages size is the limit of the receive socket buffer and message timeout is the receive timeout for the socket.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKbhjVubj_)}(h,void strp_check_rcv(struct strparser *strp);h]h,void strp_check_rcv(struct strparser *strp);}hj*sbah}(h]h ]h"]h$]h&]hhuh1j^hhhKjhjVubh)}(hstrp_check_rcv is called to check for new messages on the socket. This is normally called at initialization of a stream parser instance or after strp_unpause.h]hstrp_check_rcv is called to check for new messages on the socket. This is normally called at initialization of a stream parser instance or after strp_unpause.}(hj8hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKlhjVubeh}(h]h ]h"]h$]h&]uh1jThhhK)hjChhubeh}(h] functionsah ]h"] functionsah$]h&]uh1hhhhhhhhK'ubh)}(hhh](h)}(h Callbacksh]h Callbacks}(hjWhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjThhhhhKqubh)}(hThere are seven callbacks:h]hThere are seven callbacks:}(hjehhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKshjThhubjU)}(hXt:: int (*parse_msg)(struct strparser *strp, struct sk_buff *skb); parse_msg is called to determine the length of the next message in the stream. The upper layer must implement this function. It should parse the sk_buff as containing the headers for the next application layer message in the stream. The skb->cb in the input skb is a struct strp_msg. Only the offset field is relevant in parse_msg and gives the offset where the message starts in the skb. The return values of this function are: ========= =========================================================== >0 indicates length of successfully parsed message 0 indicates more data must be received to parse the message -ESTRPIPE current message should not be processed by the kernel, return control of the socket to userspace which can proceed to read the messages itself other < 0 Error in parsing, give control back to userspace assuming that synchronization is lost and the stream is unrecoverable (application expected to close TCP socket) ========= =========================================================== In the case that an error is returned (return value is less than zero) and the parser is in receive callback mode, then it will set the error on TCP socket and wake it up. If parse_msg returned -ESTRPIPE and the stream parser had previously read some bytes for the current message, then the error set on the attached socket is ENODATA since the stream is unrecoverable in that case. :: void (*lock)(struct strparser *strp) The lock callback is called to lock the strp structure when the strparser is performing an asynchronous operation (such as processing a timeout). In receive callback mode the default function is to lock_sock for the associated socket. In general mode the callback must be set appropriately. :: void (*unlock)(struct strparser *strp) The unlock callback is called to release the lock obtained by the lock callback. In receive callback mode the default function is release_sock for the associated socket. In general mode the callback must be set appropriately. :: void (*rcv_msg)(struct strparser *strp, struct sk_buff *skb); rcv_msg is called when a full message has been received and is queued. The callee must consume the sk_buff; it can call strp_pause to prevent any further messages from being received in rcv_msg (see strp_pause above). This callback must be set. The skb->cb in the input skb is a struct strp_msg. This struct contains two fields: offset and full_len. Offset is where the message starts in the skb, and full_len is the the length of the message. skb->len - offset may be greater than full_len since strparser does not trim the skb. :: int (*read_sock)(struct strparser *strp, read_descriptor_t *desc, sk_read_actor_t recv_actor); The read_sock callback is used by strparser instead of sock->ops->read_sock, if provided. :: int (*read_sock_done)(struct strparser *strp, int err); read_sock_done is called when the stream parser is done reading the TCP socket in receive callback mode. The stream parser may read multiple messages in a loop and this function allows cleanup to occur when exiting the loop. If the callback is not set (NULL in strp_init) a default function is used. :: void (*abort_parser)(struct strparser *strp, int err); This function is called when stream parser encounters an error in parsing. The default function stops the stream parser and sets the error in the socket if the parser is in receive callback mode. The default function can be changed by setting the callback to non-NULL in strp_init. h](j_)}(h>int (*parse_msg)(struct strparser *strp, struct sk_buff *skb);h]h>int (*parse_msg)(struct strparser *strp, struct sk_buff *skb);}hjwsbah}(h]h ]h"]h$]h&]hhuh1j^hhhKwhjsubh)}(hparse_msg is called to determine the length of the next message in the stream. The upper layer must implement this function. It should parse the sk_buff as containing the headers for the next application layer message in the stream.h]hparse_msg is called to determine the length of the next message in the stream. The upper layer must implement this function. It should parse the sk_buff as containing the headers for the next application layer message in the stream.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKyhjsubh)}(hThe skb->cb in the input skb is a struct strp_msg. Only the offset field is relevant in parse_msg and gives the offset where the message starts in the skb.h]hThe skb->cb in the input skb is a struct strp_msg. Only the offset field is relevant in parse_msg and gives the offset where the message starts in the skb.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK~hjsubh)}(h'The return values of this function are:h]h'The return values of this function are:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjsubhtable)}(hhh]htgroup)}(hhh](hcolspec)}(hhh]h}(h]h ]h"]h$]h&]colwidthK uh1jhjubj)}(hhh]h}(h]h ]h"]h$]h&]colwidthK;uh1jhjubhtbody)}(hhh](hrow)}(hhh](hentry)}(hhh]h)}(h>0h]h>0}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hhh]h)}(h/indicates length of successfully parsed messageh]h/indicates length of successfully parsed message}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]uh1jhjubj)}(hhh](j)}(hhh]h)}(h0h]h0}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hhh]h)}(h9indicates more data must be received to parse the messageh]h9indicates more data must be received to parse the message}(hj,hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj)ubah}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]uh1jhjubj)}(hhh](j)}(hhh]h)}(h -ESTRPIPEh]h -ESTRPIPE}(hjLhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjIubah}(h]h ]h"]h$]h&]uh1jhjFubj)}(hhh]h)}(hcurrent message should not be processed by the kernel, return control of the socket to userspace which can proceed to read the messages itselfh]hcurrent message should not be processed by the kernel, return control of the socket to userspace which can proceed to read the messages itself}(hjchhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj`ubah}(h]h ]h"]h$]h&]uh1jhjFubeh}(h]h ]h"]h$]h&]uh1jhjubj)}(hhh](j)}(hhh]h)}(h other < 0h]h other < 0}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jhj}ubj)}(hhh]h)}(hError in parsing, give control back to userspace assuming that synchronization is lost and the stream is unrecoverable (application expected to close TCP socket)h]hError in parsing, give control back to userspace assuming that synchronization is lost and the stream is unrecoverable (application expected to close TCP socket)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jhj}ubeh}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]colsKuh1jhjubah}(h]h ]h"]h$]h&]uh1jhjsubh)}(hX~In the case that an error is returned (return value is less than zero) and the parser is in receive callback mode, then it will set the error on TCP socket and wake it up. If parse_msg returned -ESTRPIPE and the stream parser had previously read some bytes for the current message, then the error set on the attached socket is ENODATA since the stream is unrecoverable in that case.h]hX~In the case that an error is returned (return value is less than zero) and the parser is in receive callback mode, then it will set the error on TCP socket and wake it up. If parse_msg returned -ESTRPIPE and the stream parser had previously read some bytes for the current message, then the error set on the attached socket is ENODATA since the stream is unrecoverable in that case.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjsubj_)}(h$void (*lock)(struct strparser *strp)h]h$void (*lock)(struct strparser *strp)}hjsbah}(h]h ]h"]h$]h&]hhuh1j^hhhKhjsubh)}(hX"The lock callback is called to lock the strp structure when the strparser is performing an asynchronous operation (such as processing a timeout). In receive callback mode the default function is to lock_sock for the associated socket. In general mode the callback must be set appropriately.h]hX"The lock callback is called to lock the strp structure when the strparser is performing an asynchronous operation (such as processing a timeout). In receive callback mode the default function is to lock_sock for the associated socket. In general mode the callback must be set appropriately.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjsubj_)}(h&void (*unlock)(struct strparser *strp)h]h&void (*unlock)(struct strparser *strp)}hjsbah}(h]h ]h"]h$]h&]hhuh1j^hhhKhjsubh)}(hThe unlock callback is called to release the lock obtained by the lock callback. In receive callback mode the default function is release_sock for the associated socket. In general mode the callback must be set appropriately.h]hThe unlock callback is called to release the lock obtained by the lock callback. In receive callback mode the default function is release_sock for the associated socket. In general mode the callback must be set appropriately.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjsubj_)}(h=void (*rcv_msg)(struct strparser *strp, struct sk_buff *skb);h]h=void (*rcv_msg)(struct strparser *strp, struct sk_buff *skb);}hj sbah}(h]h ]h"]h$]h&]hhuh1j^hhhKhjsubh)}(hrcv_msg is called when a full message has been received and is queued. The callee must consume the sk_buff; it can call strp_pause to prevent any further messages from being received in rcv_msg (see strp_pause above). This callback must be set.h]hrcv_msg is called when a full message has been received and is queued. The callee must consume the sk_buff; it can call strp_pause to prevent any further messages from being received in rcv_msg (see strp_pause above). This callback must be set.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjsubh)}(hXThe skb->cb in the input skb is a struct strp_msg. This struct contains two fields: offset and full_len. Offset is where the message starts in the skb, and full_len is the the length of the message. skb->len - offset may be greater than full_len since strparser does not trim the skb.h]hXThe skb->cb in the input skb is a struct strp_msg. This struct contains two fields: offset and full_len. Offset is where the message starts in the skb, and full_len is the the length of the message. skb->len - offset may be greater than full_len since strparser does not trim the skb.}(hj)hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjsubj_)}(hkint (*read_sock)(struct strparser *strp, read_descriptor_t *desc, sk_read_actor_t recv_actor);h]hkint (*read_sock)(struct strparser *strp, read_descriptor_t *desc, sk_read_actor_t recv_actor);}hj7sbah}(h]h ]h"]h$]h&]hhuh1j^hhhKhjsubh)}(h\The read_sock callback is used by strparser instead of sock->ops->read_sock, if provided. ::h]hYThe read_sock callback is used by strparser instead of sock->ops->read_sock, if provided.}(hjEhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjsubj_)}(hX int (*read_sock_done)(struct strparser *strp, int err); read_sock_done is called when the stream parser is done reading the TCP socket in receive callback mode. The stream parser may read multiple messages in a loop and this function allows cleanup to occur when exiting the loop. If the callback is not set (NULL in strp_init) a default function is used. :: void (*abort_parser)(struct strparser *strp, int err); This function is called when stream parser encounters an error in parsing. The default function stops the stream parser and sets the error in the socket if the parser is in receive callback mode. The default function can be changed by setting the callback to non-NULL in strp_init.h]hX int (*read_sock_done)(struct strparser *strp, int err); read_sock_done is called when the stream parser is done reading the TCP socket in receive callback mode. The stream parser may read multiple messages in a loop and this function allows cleanup to occur when exiting the loop. If the callback is not set (NULL in strp_init) a default function is used. :: void (*abort_parser)(struct strparser *strp, int err); This function is called when stream parser encounters an error in parsing. The default function stops the stream parser and sets the error in the socket if the parser is in receive callback mode. The default function can be changed by setting the callback to non-NULL in strp_init.}hjSsbah}(h]h ]h"]h$]h&]hhuh1j^hhhKhjsubeh}(h]h ]h"]h$]h&]uh1jThhhKuhjThhubeh}(h] callbacksah ]h"] callbacksah$]h&]uh1hhhhhhhhKqubh)}(hhh](h)}(h Statisticsh]h Statistics}(hjrhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjohhhhhKubh)}(hX.Various counters are kept for each stream parser instance. These are in the strp_stats structure. strp_aggr_stats is a convenience structure for accumulating statistics for multiple stream parser instances. save_strp_stats and aggregate_strp_stats are helper functions to save and aggregate statistics.h]hX.Various counters are kept for each stream parser instance. These are in the strp_stats structure. strp_aggr_stats is a convenience structure for accumulating statistics for multiple stream parser instances. save_strp_stats and aggregate_strp_stats are helper functions to save and aggregate statistics.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjohhubeh}(h] statisticsah ]h"] statisticsah$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(hMessage assembly limitsh]hMessage assembly limits}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhKubh)}(hYThe stream parser provide mechanisms to limit the resources consumed by message assembly.h]hYThe stream parser provide mechanisms to limit the resources consumed by message assembly.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hXwA timer is set when assembly starts for a new message. In receive callback mode the message timeout is taken from rcvtime for the associated TCP socket. In general mode, the timeout is passed as an argument in strp_process. If the timer fires before assembly completes the stream parser is aborted and the ETIMEDOUT error is set on the TCP socket if in receive callback mode.h]hXwA timer is set when assembly starts for a new message. In receive callback mode the message timeout is taken from rcvtime for the associated TCP socket. In general mode, the timeout is passed as an argument in strp_process. If the timer fires before assembly completes the stream parser is aborted and the ETIMEDOUT error is set on the TCP socket if in receive callback mode.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hXIn receive callback mode, message length is limited to the receive buffer size of the associated TCP socket. If the length returned by parse_msg is greater than the socket buffer size then the stream parser is aborted with EMSGSIZE error set on the TCP socket. Note that this makes the maximum size of receive skbuffs for a socket with a stream parser to be 2*sk_rcvbuf of the TCP socket.h]hXIn receive callback mode, message length is limited to the receive buffer size of the associated TCP socket. If the length returned by parse_msg is greater than the socket buffer size then the stream parser is aborted with EMSGSIZE error set on the TCP socket. Note that this makes the maximum size of receive skbuffs for a socket with a stream parser to be 2*sk_rcvbuf of the TCP socket.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hUIn general mode the message length limit is passed in as an argument to strp_process.h]hUIn general mode the message length limit is passed in as an argument to strp_process.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubeh}(h]message-assembly-limitsah ]h"]message assembly limitsah$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(hAuthorh]hAuthor}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhKubh)}(h Tom Herbert (tom@quantonium.net)h](h Tom Herbert (}(hjhhhNhNubh reference)}(htom@quantonium.neth]htom@quantonium.net}(hjhhhNhNubah}(h]h ]h"]h$]h&]refurimailto:tom@quantonium.netuh1jhjubh)}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjhhubeh}(h]authorah ]h"]authorah$]h&]uh1hhhhhhhhKubeh}(h]stream-parser-strparserah ]h"]stream parser (strparser)ah$]h&]uh1hhhhhhhhKubeh}(h]h ]h"]h$]h&]sourcehuh1hcurrent_sourceN current_lineNsettingsdocutils.frontendValues)}(hN generatorN datestampN source_linkN source_urlN toc_backlinksjfootnote_backlinksK sectnum_xformKstrip_commentsNstrip_elements_with_classesN strip_classesN report_levelK halt_levelKexit_status_levelKdebugNwarning_streamN tracebackinput_encoding utf-8-siginput_encoding_error_handlerstrictoutput_encodingutf-8output_encoding_error_handlerjNerror_encodingutf-8error_encoding_error_handlerbackslashreplace language_codeenrecord_dependenciesNconfigN id_prefixhauto_id_prefixid dump_settingsNdump_internalsNdump_transformsNdump_pseudo_xmlNexpose_internalsNstrict_visitorN_disable_configN_sourceh _destinationN _config_files]7/var/lib/git/docbuild/linux/Documentation/docutils.confafile_insertion_enabled raw_enabledKline_length_limitM'pep_referencesN pep_base_urlhttps://peps.python.org/pep_file_url_templatepep-%04drfc_referencesN rfc_base_url&https://datatracker.ietf.org/doc/html/ tab_widthKtrim_footnote_reference_spacesyntax_highlightlong smart_quotessmartquotes_locales]character_level_inline_markupdoctitle_xform docinfo_xformKsectsubtitle_xform image_loadinglinkembed_stylesheetcloak_email_addressessection_self_linkenvNubreporterNindirect_targets]substitution_defs}substitution_names}refnames}refids}nameids}(j)j&jjj@j=jQjNjljijjjjj!ju nametypes}(j)jj@jQjljjj!uh}(j&hjhj=jjNjCjijTjjojjjju footnote_refs} citation_refs} autofootnotes]autofootnote_refs]symbol_footnotes]symbol_footnote_refs] footnotes] citations]autofootnote_startKsymbol_footnote_startK id_counter collectionsCounter}Rparse_messages]transform_messages] transformerN include_log] decorationNhhub.