<commit_before>#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>

#include <netinet/in.h>
#include <netinet/ip6.h>
#include <netinet/tcp.h>

#include <rte_branch_prediction.h>
#include <rte_byteorder.h>
#include <rte_cycles.h>
#include <rte_hash.h>
#include <rte_hash_crc.h>
#include <rte_hexdump.h>
#include <rte_lcore.h>
#include <rte_log.h>
#include <rte_mbuf.h>
#include <rte_memcpy.h>
#include <rte_random.h>
#include <rte_rwlock.h>
#include <rte_spinlock.h>

#include <jemalloc/jemalloc.h>

#include "checksum.h"
#include "common.h"
#include "ethernet.h"
#include "extractor.h"
#include "ip_utils.h"
#include "je_utils.h"
#include "l4_utils.h"
#include "sdn_sensor.h"
#include "sensor_conf.h"
#include "tcp.h"

// XXX: how can I place a TCP hash on each socket?
static struct rte_hash_parameters tcp_hash_params = {
    .name               = "tcp_hash_socket_0",
    .entries            = L4_TCP_HASH_SIZE,
    .bucket_entries     = L4_TCP_BUCKET_SIZE,
    .key_len            = sizeof(ss_tcp_key_t),
    .hash_func          = rte_hash_crc,
    .hash_func_init_val = 0,
    .socket_id          = 0,
};

static rte_rwlock_t tcp_hash_lock;
static rte_hash_t* tcp_hash;
static ss_tcp_socket_t* tcp_sockets[L4_TCP_HASH_SIZE];

int ss_tcp_init() {
    rte_rwlock_init(&tcp_hash_lock);

    tcp_hash = rte_hash_create(&tcp_hash_params);
    if (tcp_hash == NULL) {
        RTE_LOG(ERR, L3L4, "could not initialize tcp socket hash\n");
        return -1;
    }
    
    memset(tcp_sockets, 0, sizeof(tcp_sockets));
    
    return 0;
}

int ss_tcp_timer_callback() {
    uint64_t expired_ticks = rte_rdtsc() - (rte_get_tsc_hz() * L4_TCP_EXPIRED_SECONDS);
    int expired_sockets = 0;
    ss_tcp_socket_t* socket;

    rte_rwlock_write_lock(&tcp_hash_lock);<commit_msg>tcp.c: minor adjustments for DPDK 2.2<commit_after>#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>

#include <netinet/in.h>
#include <netinet/ip6.h>
#include <netinet/tcp.h>

#include <rte_branch_prediction.h>
#include <rte_byteorder.h>
#include <rte_cycles.h>
#include <rte_hash.h>
#include <rte_hash_crc.h>
#include <rte_hexdump.h>
#include <rte_lcore.h>
#include <rte_log.h>
#include <rte_mbuf.h>
#include <rte_memcpy.h>
#include <rte_random.h>
#include <rte_rwlock.h>
#include <rte_spinlock.h>

#include <jemalloc/jemalloc.h>

#include "checksum.h"
#include "common.h"
#include "ethernet.h"
#include "extractor.h"
#include "ip_utils.h"
#include "je_utils.h"
#include "l4_utils.h"
#include "sdn_sensor.h"
#include "sensor_conf.h"
#include "tcp.h"

// XXX: how can I place a TCP hash on each socket?
static struct rte_hash_parameters tcp_hash_params = {
    .name               = "tcp_hash_socket_0",
    .entries            = L4_TCP_HASH_SIZE,
    //.bucket_entries     = L4_TCP_BUCKET_SIZE,
    .key_len            = sizeof(ss_tcp_key_t),
    .hash_func          = rte_hash_crc,
    .hash_func_init_val = 0,
    .socket_id          = 0,
};

static rte_rwlock_t tcp_hash_lock;
static rte_hash_t* tcp_hash;
static ss_tcp_socket_t* tcp_sockets[L4_TCP_HASH_SIZE];

int ss_tcp_init() {
    rte_rwlock_init(&tcp_hash_lock);

    tcp_hash = rte_hash_create(&tcp_hash_params);
    if (tcp_hash == NULL) {
        RTE_LOG(ERR, L3L4, "could not initialize tcp socket hash\n");
        return -1;
    }
    
    memset(tcp_sockets, 0, sizeof(tcp_sockets));
    
    return 0;
}

int ss_tcp_timer_callback() {
    uint64_t expired_ticks = rte_rdtsc() - (rte_get_tsc_hz() * L4_TCP_EXPIRED_SECONDS);
    int expired_sockets = 0;
    ss_tcp_socket_t* socket;

    rte_rwlock_write_lock(&tcp_hash_lock);
{'fraction_non_alphanumeric': 0.12909388646288208, 'fraction_numerical': 0.009825327510917031, 'mean_word_length': 3.8866666666666667, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 47, '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': '5055356', 'n_tokens_mistral': 1564, 'n_tokens_neox': 1535, 'n_words': 280}