<commit_before>// Copyright (c) 2014-2017, NetApp, Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
//    this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice,
//    this list of conditions and the following disclaimer in the documentation
//    and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.

#pragma once

#include <stdint.h>
#include <sys/queue.h>
#include <sys/time.h>

// IWYU pragma: begin_exports
#include <plat.h>
#include <util.h>
// IWYU pragma: end_exports

struct warpcore;


SLIST_HEAD(w_sock_chain, w_sock);

struct w_iov_chain {
    STAILQ_HEAD(, w_iov);
    uint32_t tx_pending;
};


/// Do not compute a UDP checksum for outgoing packets. Has no effect for the
/// shim backend.
///
#define W_ZERO_CHKSUM 1


/// A warpcore socket.
///
struct w_sock {
    /// Pointer back to the warpcore instance associated with this w_sock.
    ///
    struct warpcore * w;
    struct w_iov_chain * iv;  ///< w_iov chain containing incoming unread data.
    SLIST_ENTRY(w_sock) next; ///< Next socket associated with this engine.
    /// The template header to be used for outbound packets on this
    /// w_sock.
    struct w_hdr * hdr;
    SLIST_ENTRY(w_sock) next_rx; ///< Next socket with unread data.
    uint8_t flags;
    /// @cond
    uint8_t _unused[3]; ///< @internal Padding.
/// @endcond
#ifndef WITH_NETMAP
    int fd; ///< Socket descriptor underlying the engine, if the shim is in use.
#else
    /// @cond
    uint8_t _unused2[4]; ///< @internal Padding.
                         /// @endcond
#endif
};


/// The I/O vector structure that warpcore uses at the center of its API. It is
/// mostly a pointer to the first UDP payload byte contained in a netmap packet
/// buffer, together with some associated meta data.
///
/// The meta data consists of the length of the payload data, the sender IPv4
/// address and port number, the DSCP and ECN bits associated with the IPv4
/// packet in which the payload arrived, and the netmap arrival timestamp.
///
/// The w_iov structure also contains a pointer to the next I/O vector, which
/// can be used to chain together longer data items for use with w_rx() and
/// w_tx().
///
struct w_iov {
    void * buf;               ///< Start of payload data.
    STAILQ_ENTRY(w_iov) next; ///< Next w_iov in a w_iov_chain.
    uint32_t idx;             ///< Index of netmap buffer. (Internal use.)
    uint16_t len;             ///< Length of payload data.

    /// Sender port on RX. Destination port on TX on a disconnected
    /// w_sock. Ignored on TX on a connected w_sock.
    uint16_t port;

    /// Sender IPv4 address on RX. Destination IPv4 address on TX on a
    /// disconnected w_sock. Ignored on TX on a connected w_sock.
    uint32_t ip;<commit_msg>Document and pad new struct w_iov_chain<commit_after>// Copyright (c) 2014-2017, NetApp, Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
//    this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice,
//    this list of conditions and the following disclaimer in the documentation
//    and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.

#pragma once

#include <stdint.h>
#include <sys/queue.h>
#include <sys/time.h>

// IWYU pragma: begin_exports
#include <plat.h>
#include <util.h>
// IWYU pragma: end_exports

struct warpcore;

/// A chain of w_sock socket.
///
SLIST_HEAD(w_sock_chain, w_sock);


/// A chain of w_iov I/O vectors. Also contains a counter that (on TX) tracks
/// how many w_iovs have not yet been transmitted by the NIC.
///
struct w_iov_chain {
    STAILQ_HEAD(, w_iov); ///< Head of the w_iov chain.
    uint32_t tx_pending; ///< Counter of untransmitted w_iovs. Only valid on TX.
    /// @cond
    uint8_t _unused2[4]; ///< @internal Padding.
    /// @endcond
};


/// Do not compute a UDP checksum for outgoing packets. Has no effect for the
/// shim backend.
///
#define W_ZERO_CHKSUM 1


/// A warpcore socket.
///
struct w_sock {
    /// Pointer back to the warpcore instance associated with this w_sock.
    ///
    struct warpcore * w;
    struct w_iov_chain * iv;  ///< w_iov chain containing incoming unread data.
    SLIST_ENTRY(w_sock) next; ///< Next socket associated with this engine.
    /// The template header to be used for outbound packets on this
    /// w_sock.
    struct w_hdr * hdr;
    SLIST_ENTRY(w_sock) next_rx; ///< Next socket with unread data.
    uint8_t flags;
    /// @cond
    uint8_t _unused[3]; ///< @internal Padding.
/// @endcond
#ifndef WITH_NETMAP
    int fd; ///< Socket descriptor underlying the engine, if the shim is in use.
#else
    /// @cond
    uint8_t _unused2[4]; ///< @internal Padding.
    /// @endcond
#endif
};


/// The I/O vector structure that warpcore uses at the center of its API. It is
/// mostly a pointer to the first UDP payload byte contained in a netmap packet
/// buffer, together with some associated meta data.
///
/// The meta data consists of the length of the payload data, the sender IPv4
/// address and port number, the DSCP and ECN bits associated with the IPv4
/// packet in which the payload arrived, and the netmap arrival timestamp.
///
/// The w_iov structure also contains a pointer to the next I/O vector, which
/// can be used to chain together longer data items for use with w_rx() and
/// w_tx().
///
struct w_iov {
    void * buf;               ///< Start of payload data.
    STAILQ_ENTRY(w_iov) next; ///< Next w_iov in a w_iov_chain.
    uint32_t idx;             ///< Index of netmap buffer. (Internal use.)
    uint16_t len;             ///< Length of payload data.

    /// Sender port on RX. Destination port on TX on a disconnected
    /// w_sock. Ignored on TX on a connected w_sock.
    uint16_t port;

    /// Sender IPv4 address on RX. Destination IPv4 address on TX on a
    /// disconnected w_sock. Ignored on TX on a connected w_sock.
    uint32_t ip;
{'fraction_non_alphanumeric': 0.09284550808169402, 'fraction_numerical': 0.008144342814183686, 'mean_word_length': 2.8635043562439497, 'pattern_counts': {'":': 0, '<': 36, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '711756', 'n_tokens_mistral': 2421, 'n_tokens_neox': 2271, 'n_words': 1061}