From ef9f9ae4282fc4fdd5f0dc7f2d42b1b234ea3150 Mon Sep 17 00:00:00 2001 From: bol-van Date: Wed, 13 Nov 2024 19:08:59 +0300 Subject: [PATCH] nfqws: move code --- nfq/darkmagic.c | 31 ++++++++++++++++++++++++++++++ nfq/darkmagic.h | 3 +++ nfq/desync.c | 4 ++-- nfq/helpers.c | 51 +------------------------------------------------ nfq/helpers.h | 4 ---- nfq/params.c | 15 +++++++++++++++ nfq/params.h | 1 + 7 files changed, 53 insertions(+), 56 deletions(-) diff --git a/nfq/darkmagic.c b/nfq/darkmagic.c index 8457c3c..5a583b0 100644 --- a/nfq/darkmagic.c +++ b/nfq/darkmagic.c @@ -1871,3 +1871,34 @@ void verdict_udp_csum_fix(uint8_t verdict, struct udphdr *udphdr, size_t transpo udp_fix_checksum(udphdr,transport_len,ip,ip6hdr); } } + +void dbgprint_socket_buffers(int fd) +{ + if (params.debug) + { + int v; + socklen_t sz; + sz = sizeof(int); + if (!getsockopt(fd, SOL_SOCKET, SO_RCVBUF, &v, &sz)) + DLOG("fd=%d SO_RCVBUF=%d\n", fd, v); + sz = sizeof(int); + if (!getsockopt(fd, SOL_SOCKET, SO_SNDBUF, &v, &sz)) + DLOG("fd=%d SO_SNDBUF=%d\n", fd, v); + } +} +bool set_socket_buffers(int fd, int rcvbuf, int sndbuf) +{ + DLOG("set_socket_buffers fd=%d rcvbuf=%d sndbuf=%d\n", fd, rcvbuf, sndbuf); + if (rcvbuf && setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &rcvbuf, sizeof(int)) < 0) + { + DLOG_PERROR("setsockopt (SO_RCVBUF)"); + return false; + } + if (sndbuf && setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &sndbuf, sizeof(int)) < 0) + { + DLOG_PERROR("setsockopt (SO_SNDBUF)"); + return false; + } + dbgprint_socket_buffers(fd); + return true; +} diff --git a/nfq/darkmagic.h b/nfq/darkmagic.h index 58f0718..0d00de7 100644 --- a/nfq/darkmagic.h +++ b/nfq/darkmagic.h @@ -247,3 +247,6 @@ void do_nat(bool bOutbound, struct ip *ip, struct ip6_hdr *ip6, struct tcphdr *t void verdict_tcp_csum_fix(uint8_t verdict, struct tcphdr *tcphdr, size_t transport_len, struct ip *ip, struct ip6_hdr *ip6hdr); void verdict_udp_csum_fix(uint8_t verdict, struct udphdr *udphdr, size_t transport_len, struct ip *ip, struct ip6_hdr *ip6hdr); + +void dbgprint_socket_buffers(int fd); +bool set_socket_buffers(int fd, int rcvbuf, int sndbuf); diff --git a/nfq/desync.c b/nfq/desync.c index 398a89d..efb9b22 100644 --- a/nfq/desync.c +++ b/nfq/desync.c @@ -2163,7 +2163,7 @@ static void packet_debug(bool replay, const struct dissect *dis) char s[80]; str_tcphdr(s,sizeof(s),dis->tcp); DLOG(" %s\n",s); - if (dis->len_payload) { DLOG("TCP: len=%zu : ",dis->len_payload); hexdump_limited_dlog(dis->data_payload, dis->len_payload, 32); DLOG("\n"); } + if (dis->len_payload) { DLOG("TCP: len=%zu : ",dis->len_payload); hexdump_limited_dlog(dis->data_payload, dis->len_payload, PKTDATA_MAXDUMP); DLOG("\n"); } } else if (dis->udp) @@ -2171,7 +2171,7 @@ static void packet_debug(bool replay, const struct dissect *dis) char s[30]; str_udphdr(s,sizeof(s),dis->udp); DLOG(" %s\n",s); - if (dis->len_payload) { DLOG("UDP: len=%zu : ",dis->len_payload); hexdump_limited_dlog(dis->data_payload, dis->len_payload, 32); DLOG("\n"); } + if (dis->len_payload) { DLOG("UDP: len=%zu : ",dis->len_payload); hexdump_limited_dlog(dis->data_payload, dis->len_payload, PKTDATA_MAXDUMP); DLOG("\n"); } } else DLOG("\n"); diff --git a/nfq/helpers.c b/nfq/helpers.c index 90c0452..274dfb3 100644 --- a/nfq/helpers.c +++ b/nfq/helpers.c @@ -5,12 +5,11 @@ #include #include #include +#include #include #include #include -#include "params.h" - int unique_size_t(size_t *pu, int ct) { int i, j, u; @@ -64,22 +63,6 @@ char *strncasestr(const char *s, const char *find, size_t slen) return (char *)s; } -void hexdump_limited_dlog(const uint8_t *data, size_t size, size_t limit) -{ - size_t k; - bool bcut = false; - if (size > limit) - { - size = limit; - bcut = true; - } - if (!size) return; - for (k = 0; k < size; k++) DLOG("%02X ", data[k]); - DLOG(bcut ? "... : " : ": "); - for (k = 0; k < size; k++) DLOG("%c", data[k] >= 0x20 && data[k] <= 0x7F ? (char)data[k] : '.'); - if (bcut) DLOG(" ..."); -} - bool load_file(const char *filename, void *buffer, size_t *buffer_size) { @@ -220,38 +203,6 @@ uint16_t saport(const struct sockaddr *sa) sa->sa_family==AF_INET6 ? ((struct sockaddr_in6*)sa)->sin6_port : 0); } -void dbgprint_socket_buffers(int fd) -{ - if (params.debug) - { - int v; - socklen_t sz; - sz = sizeof(int); - if (!getsockopt(fd, SOL_SOCKET, SO_RCVBUF, &v, &sz)) - DLOG("fd=%d SO_RCVBUF=%d\n", fd, v); - sz = sizeof(int); - if (!getsockopt(fd, SOL_SOCKET, SO_SNDBUF, &v, &sz)) - DLOG("fd=%d SO_SNDBUF=%d\n", fd, v); - } -} -bool set_socket_buffers(int fd, int rcvbuf, int sndbuf) -{ - DLOG("set_socket_buffers fd=%d rcvbuf=%d sndbuf=%d\n", fd, rcvbuf, sndbuf); - if (rcvbuf && setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &rcvbuf, sizeof(int)) < 0) - { - DLOG_PERROR("setsockopt (SO_RCVBUF)"); - close(fd); - return false; - } - if (sndbuf && setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &sndbuf, sizeof(int)) < 0) - { - DLOG_PERROR("setsockopt (SO_SNDBUF)"); - close(fd); - return false; - } - dbgprint_socket_buffers(fd); - return true; -} uint64_t pntoh64(const void *p) { diff --git a/nfq/helpers.h b/nfq/helpers.h index 58051a7..c011ad3 100644 --- a/nfq/helpers.h +++ b/nfq/helpers.h @@ -24,7 +24,6 @@ void rtrim(char *s); void replace_char(char *s, char from, char to); char *strncasestr(const char *s,const char *find, size_t slen); -void hexdump_limited_dlog(const uint8_t *data, size_t size, size_t limit); bool load_file(const char *filename,void *buffer,size_t *buffer_size); bool load_file_nonempty(const char *filename,void *buffer,size_t *buffer_size); bool save_file(const char *filename, const void *buffer, size_t buffer_size); @@ -40,9 +39,6 @@ uint16_t saport(const struct sockaddr *sa); bool seq_within(uint32_t s, uint32_t s1, uint32_t s2); -void dbgprint_socket_buffers(int fd); -bool set_socket_buffers(int fd, int rcvbuf, int sndbuf); - uint64_t pntoh64(const void *p); void phton64(uint8_t *p, uint64_t v); diff --git a/nfq/params.c b/nfq/params.c index 8a7702c..585d906 100644 --- a/nfq/params.c +++ b/nfq/params.c @@ -154,6 +154,21 @@ int HOSTLIST_DEBUGLOG_APPEND(const char *format, ...) return 0; } +void hexdump_limited_dlog(const uint8_t *data, size_t size, size_t limit) +{ + size_t k; + bool bcut = false; + if (size > limit) + { + size = limit; + bcut = true; + } + if (!size) return; + for (k = 0; k < size; k++) DLOG("%02X ", data[k]); + DLOG(bcut ? "... : " : ": "); + for (k = 0; k < size; k++) DLOG("%c", data[k] >= 0x20 && data[k] <= 0x7F ? (char)data[k] : '.'); + if (bcut) DLOG(" ..."); +} struct desync_profile_list *dp_list_add(struct desync_profile_list_head *head) { diff --git a/nfq/params.h b/nfq/params.h index ead35e1..b6b912b 100644 --- a/nfq/params.h +++ b/nfq/params.h @@ -148,3 +148,4 @@ int DLOG_ERR(const char *format, ...); int DLOG_PERROR(const char *s); int DLOG_CONDUP(const char *format, ...); int HOSTLIST_DEBUGLOG_APPEND(const char *format, ...); +void hexdump_limited_dlog(const uint8_t *data, size_t size, size_t limit);