Skip to content

Commit 927cca3

Browse files
author
bol-van
committed
AI fixes
1 parent 162e890 commit 927cca3

File tree

6 files changed

+49
-32
lines changed

6 files changed

+49
-32
lines changed

nfq2/darkmagic.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1227,7 +1227,7 @@ bool win_dark_init(const struct str_list_head *ssid_filter, const struct str_lis
12271227
if (!f_WlanOpenHandle || !f_WlanCloseHandle || !f_WlanEnumInterfaces || !f_WlanQueryInterface || !f_WlanFreeMemory)
12281228
{
12291229
w_win32_error = GetLastError();
1230-
DLOG_ERR("could not import required functions from wlanapi.dll\n");
1230+
DLOG_ERR("could not import all required functions from wlanapi.dll\n");
12311231
win_dark_deinit();
12321232
return false;
12331233
}

nfq2/desync.c

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -730,21 +730,16 @@ static bool ipcache_get_hostname(const struct in_addr *a4, const struct in6_addr
730730
if (!params.cache_hostname)
731731
{
732732
*hostname = 0;
733-
return true;
733+
return false;
734734
}
735735
if (params.debug)
736736
{
737737
char s[40];
738738
ntopa46(a4, a6, s, sizeof(s));
739739
DLOG("ipcache hostname search for %s\n", s);
740740
}
741-
ip_cache_item *ipc = ipcacheTouch(&params.ipcache, a4, a6, NULL);
742-
if (!ipc)
743-
{
744-
DLOG_ERR("ipcache_get_hostname: out of memory\n");
745-
return false;
746-
}
747-
if (ipc->hostname)
741+
ip_cache_item *ipc = ipcacheFind(&params.ipcache, a4, a6, NULL);
742+
if (ipc && ipc->hostname)
748743
{
749744
if (params.debug)
750745
{
@@ -757,31 +752,36 @@ static bool ipcache_get_hostname(const struct in_addr *a4, const struct in6_addr
757752
}
758753
else
759754
*hostname = 0;
760-
return true;
755+
return *hostname;
761756
}
762757
static void ipcache_update_ttl(t_ctrack *ctrack, const struct in_addr *a4, const struct in6_addr *a6, const char *iface)
763758
{
764759
// no need to cache ttl in server mode because first packet is incoming
765760
if (ctrack && !params.server)
766761
{
767-
ip_cache_item *ipc = ipcacheTouch(&params.ipcache, a4, a6, iface);
768-
if (!ipc)
769-
{
770-
DLOG_ERR("ipcache: out of memory\n");
771-
return;
772-
}
762+
ip_cache_item *ipc;
773763
if (ctrack->incoming_ttl)
774764
{
765+
ipc = ipcacheTouch(&params.ipcache, a4, a6, iface);
766+
if (!ipc)
767+
{
768+
DLOG_ERR("ipcache: out of memory\n");
769+
return;
770+
}
775771
if (ipc->ttl != ctrack->incoming_ttl)
776772
{
777773
DLOG("updated ttl cache\n");
778774
ipc->ttl = ctrack->incoming_ttl;
779775
}
780776
}
781-
else if (ipc->ttl)
777+
else
782778
{
783-
DLOG("got cached ttl %u\n", ipc->ttl);
784-
ctrack->incoming_ttl = ipc->ttl;
779+
ipc = ipcacheFind(&params.ipcache, a4, a6, iface);
780+
if (ipc && ipc->ttl)
781+
{
782+
DLOG("got cached ttl %u\n", ipc->ttl);
783+
ctrack->incoming_ttl = ipc->ttl;
784+
}
785785
}
786786
}
787787
}
@@ -790,10 +790,8 @@ static void ipcache_get_ttl(t_ctrack *ctrack, const struct in_addr *a4, const st
790790
// no need to cache ttl in server mode because first packet is incoming
791791
if (ctrack && !ctrack->incoming_ttl && !params.server)
792792
{
793-
ip_cache_item *ipc = ipcacheTouch(&params.ipcache, a4, a6, iface);
794-
if (!ipc)
795-
DLOG_ERR("ipcache: out of memory\n");
796-
else if (ipc->ttl)
793+
ip_cache_item *ipc = ipcacheFind(&params.ipcache, a4, a6, iface);
794+
if (ipc && ipc->ttl)
797795
{
798796
DLOG("got cached ttl %u\n", ipc->ttl);
799797
ctrack->incoming_ttl = ipc->ttl;
@@ -897,7 +895,7 @@ static uint8_t desync(
897895
if (LIST_FIRST(&dp->lua_desync))
898896
{
899897
lua_rawgeti(params.L, LUA_REGISTRYINDEX, params.ref_desync_ctx);
900-
t_lua_desync_context *ctx = (t_lua_desync_context *)luaL_checkudata(params.L, 1, "desync_ctx");
898+
t_lua_desync_context *ctx = (t_lua_desync_context *)luaL_checkudata(params.L, -1, "desync_ctx");
901899
// this is singleton stored in the registry. safe to pop
902900
lua_pop(params.L,1);
903901

@@ -1264,7 +1262,7 @@ static bool play_prolog(
12641262
hostname_is_ip = ps->ctrack->hostname_is_ip;
12651263
if (!hostname && !ps->bReverse)
12661264
{
1267-
if (ipcache_get_hostname(ps->sdip4, ps->sdip6, ps->host, sizeof(ps->host), &hostname_is_ip) && *ps->host)
1265+
if (ipcache_get_hostname(ps->sdip4, ps->sdip6, ps->host, sizeof(ps->host), &hostname_is_ip))
12681266
if (!(hostname = ps->ctrack->hostname = strdup(ps->host)))
12691267
DLOG_ERR("strdup(host): out of memory\n");
12701268
}
@@ -1985,8 +1983,8 @@ static uint8_t dpi_desync_icmp_packet(
19851983
hostname = ctrack->hostname;
19861984
hostname_is_ip = ctrack->hostname_is_ip;
19871985
}
1988-
else if (ipcache_get_hostname(dis->ip ? &dis->ip->ip_dst : NULL, dis->ip6 ? &dis->ip6->ip6_dst : NULL, host, sizeof(host), &hostname_is_ip) && *host ||
1989-
ipcache_get_hostname(dis->ip ? &dis->ip->ip_src : NULL, dis->ip6 ? &dis->ip6->ip6_src : NULL, host, sizeof(host), &hostname_is_ip) && *host)
1986+
else if (ipcache_get_hostname(dis->ip ? &dis->ip->ip_dst : NULL, dis->ip6 ? &dis->ip6->ip6_dst : NULL, host, sizeof(host), &hostname_is_ip) ||
1987+
ipcache_get_hostname(dis->ip ? &dis->ip->ip_src : NULL, dis->ip6 ? &dis->ip6->ip6_src : NULL, host, sizeof(host), &hostname_is_ip))
19901988
{
19911989
hostname = host;
19921990
}
@@ -2052,8 +2050,8 @@ static uint8_t dpi_desync_ip_packet(
20522050
bool hostname_is_ip = false;
20532051
const char *hostname = NULL;
20542052
char host[256];
2055-
if (ipcache_get_hostname(dis->ip ? &dis->ip->ip_dst : NULL, dis->ip6 ? &dis->ip6->ip6_dst : NULL, host, sizeof(host), &hostname_is_ip) && *host ||
2056-
ipcache_get_hostname(dis->ip ? &dis->ip->ip_src : NULL, dis->ip6 ? &dis->ip6->ip6_src : NULL, host, sizeof(host), &hostname_is_ip) && *host)
2053+
if (ipcache_get_hostname(dis->ip ? &dis->ip->ip_dst : NULL, dis->ip6 ? &dis->ip6->ip6_dst : NULL, host, sizeof(host), &hostname_is_ip) ||
2054+
ipcache_get_hostname(dis->ip ? &dis->ip->ip_src : NULL, dis->ip6 ? &dis->ip6->ip6_src : NULL, host, sizeof(host), &hostname_is_ip))
20572055
{
20582056
hostname = host;
20592057
}

nfq2/filter.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ bool pf_parse(const char *s, port_filter *pf)
1818
if (*s=='*' && s[1]==0)
1919
{
2020
pf->from=1; pf->to=0xFFFF;
21+
pf->neg=false;
2122
return true;
2223
}
2324
if (*s=='~')

nfq2/pools.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,6 +1115,22 @@ void ipcachePrint(ip_cache *ipcache)
11151115
ipcache6Print(ipcache->ipcache6);
11161116
}
11171117

1118+
ip_cache_item *ipcacheFind(ip_cache *ipcache, const struct in_addr *a4, const struct in6_addr *a6, const char *iface)
1119+
{
1120+
ip_cache4 *ipcache4;
1121+
ip_cache6 *ipcache6;
1122+
if (a4)
1123+
{
1124+
if ((ipcache4 = ipcache4Find(ipcache->ipcache4,a4,iface)))
1125+
return &ipcache4->data;
1126+
}
1127+
else if (a6)
1128+
{
1129+
if ((ipcache6 = ipcache6Find(ipcache->ipcache6,a6,iface)))
1130+
return &ipcache6->data;
1131+
}
1132+
return NULL;
1133+
}
11181134
ip_cache_item *ipcacheTouch(ip_cache *ipcache, const struct in_addr *a4, const struct in6_addr *a6, const char *iface)
11191135
{
11201136
ip_cache4 *ipcache4;

nfq2/pools.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ typedef struct ip_cache
265265
} ip_cache;
266266

267267
ip_cache_item *ipcacheTouch(ip_cache *ipcache, const struct in_addr *a4, const struct in6_addr *a6, const char *iface);
268+
ip_cache_item *ipcacheFind(ip_cache *ipcache, const struct in_addr *a4, const struct in6_addr *a6, const char *iface);
268269
void ipcachePurgeRateLimited(ip_cache *ipcache, time_t lifetime);
269270
void ipcacheDestroy(ip_cache *ipcache);
270271
void ipcachePrint(ip_cache *ipcache);

nfq2/protocol.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ t_l7proto l7proto_from_name(const char *name)
4444
}
4545
bool l7_proto_match(t_l7proto l7proto, uint64_t filter_l7)
4646
{
47-
return filter_l7==L7_ALL || (filter_l7 & (1<<l7proto)) || (filter_l7 & (1<<L7_KNOWN)) && l7proto>L7_KNOWN && l7proto<L7_LAST;
47+
return filter_l7==L7_ALL || (filter_l7 & (1ULL<<l7proto)) || (filter_l7 & (1ULL<<L7_KNOWN)) && l7proto>L7_KNOWN && l7proto<L7_LAST;
4848
}
4949

5050
static const char *l7payload_name[] = {
@@ -73,7 +73,7 @@ const char *l7payload_str(t_l7payload l7)
7373
}
7474
bool l7_payload_match(t_l7payload l7payload, uint64_t filter_l7p)
7575
{
76-
return filter_l7p==L7P_ALL || (filter_l7p & (1<<l7payload)) || (filter_l7p & (1<<L7P_KNOWN)) && l7payload>L7P_KNOWN && l7payload<L7P_LAST;
76+
return filter_l7p==L7P_ALL || (filter_l7p & (1ULL<<l7payload)) || (filter_l7p & (1ULL<<L7P_KNOWN)) && l7payload>L7P_KNOWN && l7payload<L7P_LAST;
7777
}
7878
bool l7_payload_str_list(uint64_t l7p, char *buf, size_t size)
7979
{
@@ -91,7 +91,7 @@ bool l7_payload_str_list(uint64_t l7p, char *buf, size_t size)
9191
}
9292
for(pl=0, p=buf, e=p+size, *buf=0 ; pl<L7P_LAST ; pl++)
9393
{
94-
if (l7p & (1<<pl))
94+
if (l7p & (1ULL<<pl))
9595
{
9696
pstr = l7payload_str(pl);
9797
lstr = strlen(pstr);
@@ -1351,6 +1351,7 @@ bool IsQUICInitial(const uint8_t *data, size_t len)
13511351
offset += 1 + data[offset];
13521352

13531353
// token length
1354+
if (offset>=len || (offset + tvb_get_size(data[offset])) > len) return false;
13541355
offset += tvb_get_varint(data + offset, &sz);
13551356
offset += sz;
13561357
if (offset >= len) return false;

0 commit comments

Comments
 (0)