Skip to content

Commit

Permalink
dropmon config options hw_unknown=on|off (match all) and hw_function=…
Browse files Browse the repository at this point in the history
…on|off (include raw string in sFlow feed)
  • Loading branch information
sflow committed Feb 15, 2023
1 parent b730e77 commit 6889a09
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 7 deletions.
2 changes: 1 addition & 1 deletion hsflowd.spec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Summary: host sFlow daemon
Name: hsflowd
Version: 2.0.42
Version: 2.0.43
Release: 1
License: http://sflow.net/license.html
Group: Applications/Internet
Expand Down
2 changes: 1 addition & 1 deletion src/Linux/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ clean:

######### dependencies #########

.c.o: $(HEADERS)
.c.o:
$(CC) $(CFLAGS) -c $*.c

util.o: util.c $(HEADERS)
Expand Down
15 changes: 14 additions & 1 deletion src/Linux/hsflowconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -1346,6 +1346,8 @@ extern "C" {
sp->dropmon.max = 100000;
sp->dropmon.sw = YES;
sp->dropmon.hw = YES;
sp->dropmon.hw_unknown = NO;
sp->dropmon.hw_function = NO;
level[++depth] = HSPOBJ_DROPMON;
break;
case HSPTOKEN_PCAP:
Expand Down Expand Up @@ -1693,7 +1695,12 @@ extern "C" {
{
switch(tok->stok) {
case HSPTOKEN_GROUP:
// deprecated, ignored
// deprecated, ignore as long as it is well-formed. Must still
// parse to consume the arg.
{
uint32_t ignore;
if((tok = expectInteger32(sp, tok, &ignore, 1, 0xFFFFFFFF)) == NULL) return NO;
}
break;
case HSPTOKEN_START:
if((tok = expectONOFF(sp, tok, &sp->dropmon.start)) == NULL) return NO;
Expand All @@ -1704,6 +1711,12 @@ extern "C" {
case HSPTOKEN_HW:
if((tok = expectONOFF(sp, tok, &sp->dropmon.hw)) == NULL) return NO;
break;
case HSPTOKEN_HW_UNKNOWN:
if((tok = expectONOFF(sp, tok, &sp->dropmon.hw_unknown)) == NULL) return NO;
break;
case HSPTOKEN_HW_FUNCTION:
if((tok = expectONOFF(sp, tok, &sp->dropmon.hw_function)) == NULL) return NO;
break;
case HSPTOKEN_LIMIT:
if((tok = expectInteger32(sp, tok, &sp->dropmon.limit, 1, HSP_MAX_NOTIFY_RATELIMIT)) == NULL) return NO;
break;
Expand Down
2 changes: 2 additions & 0 deletions src/Linux/hsflowd.h
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,8 @@ extern "C" {
bool hw;
uint32_t limit;
uint32_t max;
bool hw_unknown;
bool hw_function;
} dropmon;
struct {
bool pcap;
Expand Down
2 changes: 2 additions & 0 deletions src/Linux/hsflowtokens.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ HSPTOKEN_DATA( HSPTOKEN_START, "start", HSPTOKENTYPE_ATTRIB, NULL)
HSPTOKEN_DATA( HSPTOKEN_LIMIT, "limit", HSPTOKENTYPE_ATTRIB, NULL)
HSPTOKEN_DATA( HSPTOKEN_SW, "sw", HSPTOKENTYPE_ATTRIB, NULL)
HSPTOKEN_DATA( HSPTOKEN_HW, "hw", HSPTOKENTYPE_ATTRIB, NULL)
HSPTOKEN_DATA( HSPTOKEN_HW_UNKNOWN, "hw_unknown", HSPTOKENTYPE_ATTRIB, NULL)
HSPTOKEN_DATA( HSPTOKEN_HW_FUNCTION, "hw_function", HSPTOKENTYPE_ATTRIB, NULL)
HSPTOKEN_DATA( HSPTOKEN_TUNNEL, "tunnel", HSPTOKENTYPE_ATTRIB, NULL)
HSPTOKEN_DATA( HSPTOKEN_MAX, "max", HSPTOKENTYPE_ATTRIB, NULL)
HSPTOKEN_DATA( HSPTOKEN_UNIXSOCK, "unixsock", HSPTOKENTYPE_ATTRIB, NULL)
Expand Down
24 changes: 23 additions & 1 deletion src/Linux/mod_dropmon.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ extern "C" {
UTARRAY_WALK(mdata->dropPatterns_hw, dp) {
if(fnmatch(dp->dropPoint, dropPointStr, FNM_CASEFOLD) == 0) {
// yes - add the direct lookup to the hash table for next time
myDebug(1, "dropPoint pattern %s matched grp=%s str=%s", dp->dropPoint, group, dropPointStr);
dp = newDropPoint(dropPointStr, NO, dp->reason);
addDropPoint_hw(mod, dp);
return dp;
Expand Down Expand Up @@ -339,6 +340,15 @@ extern "C" {
if(dp)
addDropPoint_hw(mod, dp);
}
if(sp->dropmon.hw_unknown) {
// Option to match everything that falls through the classifier. This
// is the same as including "HSP_DROPPOINT(*=,*,unknown)" in dropPoints_hw.h
// except that we can turn it on/off in the config.
HSPDropPointLoader dplAll = { "*=", "*", "unknown" };
HSPDropPoint *dp = buildDropPoint(&dplAll);
if(dp)
addDropPoint_hw(mod, dp);
}
}
}

Expand Down Expand Up @@ -611,7 +621,9 @@ That would allow everything to stay on the stack as it does here, which has nice
char *hw_group=NULL;
char *hw_name=NULL;
char *sw_symbol=NULL;

// space to assemble hw_function if included
char hwFnBuf[SFL_MAX_FUNCTION_SYMBOL_LEN+1];

struct nlattr *attr = (struct nlattr *)(msg + GENL_HDRLEN);
int len = msglen - GENL_HDRLEN;
while(UTNLA_OK(attr, len)) {
Expand Down Expand Up @@ -792,6 +804,16 @@ That would allow everything to stay on the stack as it does here, which has nice
fnElem.flowType.function.symbol.len = my_strlen(dp->dropPoint);
SFLADD_ELEMENT(&discard, &fnElem);
}
else if(sp->dropmon.hw_function) {
// This option (off by default) is to help with discovering (not missing)
// new codes that do not map to defined drop reason codes.
// This formatting assumes there is no space in the hw_name but it's not serious
// if there is because the string, if used, will likely be taken as a whole.
snprintf(hwFnBuf, SFL_MAX_FUNCTION_SYMBOL_LEN, "%s %s", hw_name ?: "-", hw_group ?: "-");
fnElem.flowType.function.symbol.str = hwFnBuf;
fnElem.flowType.function.symbol.len = my_strlen(hwFnBuf);
SFLADD_ELEMENT(&discard, &fnElem);
}

SEMLOCK_DO(sp->sync_agent) {
sfl_notifier_writeEventSample(notifier, &discard);
Expand Down
2 changes: 1 addition & 1 deletion src/Linux/scripts/hsflowd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ sflow {
# PSAMPLE config via tc:
# dent { sw=on switchport=enp.* egress=on }
# packet drop monitoring:
# dropmon { group=1 start=on limit=50 }
# dropmon { start=on limit=50 }
# Nvidia NVML GPU monitoring:
# nvml { }
# Xen hypervisor and VM monitoring:
Expand Down
2 changes: 1 addition & 1 deletion src/Linux/scripts/hsflowd.conf.cumulus
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ sflow {
# psample { group=1 }
# systemd {}
# nflog { group=1 }
# dropmon { group=1 start=off limit=1000 }
# dropmon { start=off limit=1000 }

# ====== Sampling/Polling/Collectors ======
# EITHER: automatic (DNS SRV+TXT from _sflow._udp):
Expand Down
2 changes: 1 addition & 1 deletion src/Linux/scripts/hsflowd.conf.dent
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ sflow {
# systemd {}
#
# monitor dropped packets:
# dropmon { group=1 start=off limit=1000 }
# dropmon { start=off limit=1000 }
}

0 comments on commit 6889a09

Please sign in to comment.