Skip to content

Commit

Permalink
Cleanup fixes, and fix gcc complains
Browse files Browse the repository at this point in the history
  • Loading branch information
phaag committed Jul 7, 2024
1 parent bc3c2c9 commit 53f9fa0
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
16 changes: 8 additions & 8 deletions src/libnfdump/filter/grammar.y
Original file line number Diff line number Diff line change
Expand Up @@ -231,21 +231,21 @@ term: ANY { /* this is an unconditionally true expression, as a filter applies i
$$.self = AddEngineNum($2, $3.comp, $4); if ( $$.self < 0 ) YYABORT;
}

| EXPORTER STRING comp NUMBER {
$$.self = AddExporterNum($2, $3.comp, $4); if ( $$.self < 0 ) YYABORT;
| EXPORTER STRING comp NUMBER {
$$.self = AddExporterNum($2, $3.comp, $4); if ( $$.self < 0 ) YYABORT;
}

| dqual PROTO NUMBER {
$$.self = AddProto($1.direction, NULL, $3); if ( $$.self < 0 ) YYABORT;
}
$$.self = AddProto($1.direction, NULL, $3); if ( $$.self < 0 ) YYABORT;
}

| dqual PROTO STRING {
$$.self = AddProto($1.direction, $3, 0); if ( $$.self < 0 ) YYABORT;
}
$$.self = AddProto($1.direction, $3, 0); if ( $$.self < 0 ) YYABORT;
}

| dqual PROTO ICMP {
$$.self = AddProto($1.direction, "icmp", 0); if ( $$.self < 0 ) YYABORT;
}
$$.self = AddProto($1.direction, "icmp", 0); if ( $$.self < 0 ) YYABORT;
}

| dqual PORT comp NUMBER {
$$.self = AddPortNumber($1.direction, $3.comp, $4); if ( $$.self < 0 ) YYABORT;
Expand Down
11 changes: 8 additions & 3 deletions src/nfdump/nflowcache.c
Original file line number Diff line number Diff line change
Expand Up @@ -799,8 +799,8 @@ static inline int New_HashKey(void *keymem, recordHandle_t *recordHandle, int sw
keyLen = sizeof(FlowKeyV4_t);
} else if (ipv6Flow) {
FlowKeyV6_t *keyptr = (FlowKeyV6_t *)keymem;
memcpy((void *)keyptr->srcAddr, (void *)ipv6Flow->srcAddr, 16);
memcpy((void *)keyptr->dstAddr, (void *)ipv6Flow->dstAddr, 16);
memcpy((void *)keyptr->srcAddr, (void *)ipv6Flow->dstAddr, 16);
memcpy((void *)keyptr->dstAddr, (void *)ipv6Flow->srcAddr, 16);
keyptr->srcPort = genericFlow->dstPort;
keyptr->dstPort = genericFlow->srcPort;
keyptr->proto = genericFlow->proto;
Expand All @@ -820,7 +820,8 @@ static inline int New_HashKey(void *keymem, recordHandle_t *recordHandle, int sw
keyptr->af = AF_INET;
keymem += sizeof(FlowKeyV4_t);
keyLen = sizeof(FlowKeyV4_t);
} else if (ipv6Flow) {
} else if (ipv6Flow && maxKeyLen > 16) {
// maxKeyLen > 16 is actually not needed but gcc complains otherwise
FlowKeyV6_t *keyptr = (FlowKeyV6_t *)keymem;
memcpy((void *)keyptr->srcAddr, (void *)ipv6Flow->srcAddr, 16);
memcpy((void *)keyptr->dstAddr, (void *)ipv6Flow->dstAddr, 16);
Expand All @@ -830,6 +831,10 @@ static inline int New_HashKey(void *keymem, recordHandle_t *recordHandle, int sw
keyptr->af = AF_INET6;
keymem += sizeof(FlowKeyV6_t);
keyLen = sizeof(FlowKeyV6_t);
} else {
// catch all cases, actually not needed.
LogError("ipv4Flow: %d, ipv6Flow: %d, maxKeyLen: %u", ipv4Flow != NULL, ipv6Flow != NULL, maxKeyLen);
memset(keymem, 0, maxKeyLen);
}
}
dbg_printf("New_HashKey() size: %u\n", keyLen);
Expand Down
2 changes: 0 additions & 2 deletions src/nfdump/nfstat.c
Original file line number Diff line number Diff line change
Expand Up @@ -1099,7 +1099,6 @@ static void PrintJsonStatLine(char *statName, stat_record_t *stat, outputParams_

StatRecord_t *statRecord = (StatRecord_t *)element->record;
hashkey_t *hashKey = statRecord->hashkey;
char tag_string[2] = {'\0', '\0'};
switch (type) {
case IS_NULL:
break;
Expand All @@ -1110,7 +1109,6 @@ static void PrintJsonStatLine(char *statName, stat_record_t *stat, outputParams_
snprintf(valstr, 64, "0x%llx", (unsigned long long)hashKey->v1);
break;
case IS_IPADDR:
tag_string[0] = outputParams->doTag ? TAG_CHAR : '\0';
if (hashKey->v0 == 0) { // IPv4
uint32_t ipv4 = htonl(hashKey->v1);
inet_ntop(AF_INET, &ipv4, valstr, sizeof(valstr));
Expand Down
4 changes: 2 additions & 2 deletions src/tor/torlookup.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <fts.h>
#include <stdint.h>
#include <stdio.h>
#include <sys/stat.h>
#include <unistd.h>

#include "conf/nfconf.h"
Expand Down Expand Up @@ -234,8 +235,7 @@ static char *string_trim(char *s) {
if (*s) {
char *p = s;
while (*p) p++;
while (isspace((unsigned char)*(--p)))
;
while (isspace((unsigned char)*(--p)));
p[1] = '\0';
}

Expand Down

0 comments on commit 53f9fa0

Please sign in to comment.