<commit_before>#include <iostream>
#include <string>
#include <vector>
#include <thread>
#include <fstream>
#include <memory>

#include <botan/tls_client.h>
#include <botan/tls_server.h>
#include <botan/x509cert.h>
#include <botan/pkcs8.h>
#include <botan/auto_rng.h>
#include <botan/hex.h>
#include <botan/pkcs8.h>
#include <botan/credentials_manager.h>
#include <botan/x509self.h>
#include <botan/data_src.h>

#include <arpa/inet.h>
#include <net/ethernet.h>
#include <netinet/ip.h>
#include <netinet/in.h>


#include "dtls.h"

#include "uvxbridge.h"
#include "uvxlan.h"


struct dtls_rx_args {
	int rc;
	int pad;
	char *txbuf;
	path_state_t *ps;
	struct vxlan_state_dp *dp_state;
};


class dtls_callbacks : public Botan::TLS::Callbacks
{
public:
	void
	tls_record_received(uint64_t rec_no __unused, const uint8_t buf[], size_t buf_len) override {
		struct dtls_rx_args *args = (struct dtls_rx_args *)this->dc_rx_cookie;
		/* pass up to vxlan_decap */
		args->ps->ps_rx_len = buf_len;
		args->rc = vxlan_decap_v4((char *)(uintptr_t)(buf), args->txbuf, args->ps, args->dp_state);
	}
	
	void
	tls_emit_data(const uint8_t buf[], size_t buf_len) override {
		int offset = 10; /* setup udp and copy to offset */ 
		/* copy data in the buffer to a UDP packet in the descriptors txring */
		memcpy(*dc_tx_cookie + offset, buf, buf_len);
	}
	bool
	tls_session_established(const Botan::TLS::Session& session __unused) override {
		return false;
	}
	<commit_msg>handle tx correctly<commit_after>#include <iostream>
#include <string>
#include <vector>
#include <thread>
#include <fstream>
#include <memory>

#include <botan/tls_client.h>
#include <botan/tls_server.h>
#include <botan/x509cert.h>
#include <botan/pkcs8.h>
#include <botan/auto_rng.h>
#include <botan/hex.h>
#include <botan/pkcs8.h>
#include <botan/credentials_manager.h>
#include <botan/x509self.h>
#include <botan/data_src.h>

#include <arpa/inet.h>
#include <net/ethernet.h>
#include <netinet/ip.h>
#include <netinet/in.h>


#include "dtls.h"

#include "uvxbridge.h"
#include "uvxlan.h"
#include <nmutil.h>

struct dtls_rx_args {
	int rc;
	int pad;
	char *txbuf;
	path_state_t *ps;
	struct vxlan_state_dp *dp_state;
};

static void
dtls_udp_fill(char *txbuf, void *payload, int len)
{
	struct ether_header *eh = (struct ether_header *)txbuf;
	struct ip *ip = (struct ip *)(uintptr_t)(eh + 1);
	struct udphdr *uh = (struct udphdr *)(ip + 1);
	void *data = (void *)(uintptr_t)(uh + 1);

	/* we can reuse the ether header and ip with the len adjusted */
	ip->ip_len = ntohs(sizeof(*ip) + sizeof(*uh) + len);
	udp_fill(uh, 443, 443, len);
	memcpy(data, payload, len);
}


class dtls_callbacks : public Botan::TLS::Callbacks
{
public:
	void
	tls_record_received(uint64_t rec_no __unused, const uint8_t buf[], size_t buf_len) override {
		struct dtls_rx_args *args = (struct dtls_rx_args *)this->dc_rx_cookie;
		/* pass up to vxlan_decap */
		args->ps->ps_rx_len = buf_len;
		args->rc = vxlan_decap_v4((char *)(uintptr_t)(buf), args->txbuf, args->ps, args->dp_state);
	}
	
	void
	tls_emit_data(const uint8_t buf[], size_t buf_len) override {
		dtls_udp_fill(*dc_tx_cookie, (char *)(uintptr_t)buf, buf_len);
	}
	bool
	tls_session_established(const Botan::TLS::Session& session __unused) override {
		return false;
	}
	
{'fraction_non_alphanumeric': 0.14617737003058104, 'fraction_numerical': 0.011314984709480122, 'mean_word_length': 5.136960600375234, 'pattern_counts': {'":': 0, '<': 44, '<?xml version=': 0, '>': 59, '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': '7077051', 'n_tokens_mistral': 1389, 'n_tokens_neox': 1337, 'n_words': 304}