<commit_before>#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <sys/time.h>

#include <bsd/string.h>
#include <bsd/sys/queue.h>

#include <jemalloc/jemalloc.h>

#include <json-c/json.h>
#include <json-c/json_object_private.h>

#include <pcap/pcap.h>

#include <rte_byteorder.h>
#include <rte_config.h>
#include <rte_lcore.h>
#include <rte_log.h>
#include <rte_lpm.h>
#include <rte_lpm6.h>

#include <uthash.h>

#include "common.h"
#include "ioc.h"
#include "json.h"
#include "sdn_sensor.h"
#include "sensor_conf.h"

/* COMMON */

int ss_metadata_prepare(ss_frame_t* fbuf) {
    ss_metadata_t* m = &fbuf->data;
    
    m->port_id     = (uint8_t) ~0;
    m->direction   = (uint8_t) ~0;
    m->self        = 0;
    m->length      = 0;
    memset(m->smac, 0, sizeof(m->smac));
    memset(m->dmac, 0, sizeof(m->dmac));
    m->eth_type    = 0x0000;
    memset(m->sip, 0, sizeof(m->sip));
    memset(m->dip, 0, sizeof(m->dip));
    m->ip_protocol = (uint8_t) ~0;
    m->ttl         = 0;
    m->l4_length   = (uint16_t) ~0;
    m->icmp_type   = (uint8_t) ~0;
    m->icmp_code   = (uint8_t) ~0;
    m->tcp_flags   = 0;
    m->sport       = 0;
    m->dport       = 0;
    memset(m->dns_name, 0, sizeof(m->dns_name));
    memset(m->dns_answers, 0, sizeof(m->dns_answers));
    
    return 0;
}

ss_direction_t ss_direction_load(const char* direction) {
    if (!strcasecmp(direction, "rx")) return SS_FRAME_RX;
    if (!strcasecmp(direction, "tx")) return SS_FRAME_TX;
    return (ss_direction_t) -1;
}

const char* ss_direction_dump(ss_direction_t direction) {
    switch (direction) {
        case SS_FRAME_RX: return "RX";
        case SS_FRAME_TX: return "TX";
        default:          return "UNKNOWN";
    }
}

int ss_flow_key_dump(const char* message, ss_flow_key_t* key) {
    uint8_t family;
    const char* protocol;
    char sip[SS_ADDR_STR_MAX];
    char dip[SS_ADDR_STR_MAX];
    uint16_t sport = rte_bswap16(key->sport);
    uint16_t dport = rte_bswap16(key->dport);

    memset(sip, 0, sizeof(sip));
    memset(dip, 0, sizeof(dip));
<commit_msg>common.c: rename flow_key to tcp_key (to allow sflow_key)<commit_after>#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <sys/time.h>

#include <bsd/string.h>
#include <bsd/sys/queue.h>

#include <jemalloc/jemalloc.h>

#include <json-c/json.h>
#include <json-c/json_object_private.h>

#include <pcap/pcap.h>

#include <rte_byteorder.h>
#include <rte_config.h>
#include <rte_lcore.h>
#include <rte_log.h>
#include <rte_lpm.h>
#include <rte_lpm6.h>

#include <uthash.h>

#include "common.h"
#include "ioc.h"
#include "json.h"
#include "sdn_sensor.h"
#include "sensor_conf.h"

/* COMMON */

int ss_metadata_prepare(ss_frame_t* fbuf) {
    ss_metadata_t* m = &fbuf->data;
    
    m->port_id     = (uint8_t) ~0;
    m->direction   = (uint8_t) ~0;
    m->self        = 0;
    m->length      = 0;
    memset(m->smac, 0, sizeof(m->smac));
    memset(m->dmac, 0, sizeof(m->dmac));
    m->eth_type    = 0x0000;
    memset(m->sip, 0, sizeof(m->sip));
    memset(m->dip, 0, sizeof(m->dip));
    m->ip_protocol = (uint8_t) ~0;
    m->ttl         = 0;
    m->l4_length   = (uint16_t) ~0;
    m->icmp_type   = (uint8_t) ~0;
    m->icmp_code   = (uint8_t) ~0;
    m->tcp_flags   = 0;
    m->sport       = 0;
    m->dport       = 0;
    memset(m->dns_name, 0, sizeof(m->dns_name));
    memset(m->dns_answers, 0, sizeof(m->dns_answers));
    
    return 0;
}

ss_direction_t ss_direction_load(const char* direction) {
    if (!strcasecmp(direction, "rx")) return SS_FRAME_RX;
    if (!strcasecmp(direction, "tx")) return SS_FRAME_TX;
    return (ss_direction_t) -1;
}

const char* ss_direction_dump(ss_direction_t direction) {
    switch (direction) {
        case SS_FRAME_RX: return "RX";
        case SS_FRAME_TX: return "TX";
        default:          return "UNKNOWN";
    }
}

int ss_tcp_key_dump(const char* message, ss_tcp_key_t* key) {
    uint8_t family;
    const char* protocol;
    char sip[SS_ADDR_STR_MAX];
    char dip[SS_ADDR_STR_MAX];
    uint16_t sport = rte_bswap16(key->sport);
    uint16_t dport = rte_bswap16(key->dport);

    memset(sip, 0, sizeof(sip));
    memset(dip, 0, sizeof(dip));

{'fraction_non_alphanumeric': 0.16527390900649955, 'fraction_numerical': 0.020891364902506964, 'mean_word_length': 3.2369714847590956, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 99, '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': '4064607', 'n_tokens_mistral': 1903, 'n_tokens_neox': 1838, 'n_words': 347}