Skip to content

Commit

Permalink
add support for new packet drop reason structures
Browse files Browse the repository at this point in the history
  • Loading branch information
sflow committed Mar 23, 2023
1 parent 87cc422 commit 7299efd
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/sflow.h
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,32 @@ typedef struct {
} SFLExtended_queue_depth;
#define XDRSIZ_SFLEXTENDED_Q_DEPTH 4

// Devlink Trap Name
// opaque = flow_data; enterprise = 0; format = 1041
// https://www.kernel.org/doc/html/latest/networking/devlink/devlink-trap.html
// XDR spec:
// struct extended_hw_trap {
// string group<>; /* NET_DM_ATTR_HW_TRAP_GROUP_NAME */
// string trap<>; /* NET_DM_ATTR_HW_TRAP_NAME */
// }
typedef struct _SFLExtended_hw_trap {
SFLString group;
SFLString trap;
} SFLExtended_hw_trap;
#define SFL_MAX_HW_TRAP_LEN 64

// Linux drop_monitor reason
// opaque = flow_data; enterprise = 0; format = 1042
// https://github.com/torvalds/linux/blob/master/include/net/dropreason.h
// XDR spec:
// struct extended_linux_drop_reason {
// string reason<>; /* NET_DM_ATTR_REASON */
// }
typedef struct _SFLExtended_linux_reason {
SFLString reason;
} SFLExtended_linux_reason;
#define SFL_MAX_LINUX_REASON_LEN 64

enum SFLFlow_type_tag {
/* enterprise = 0, format = ... */
SFLFLOW_HEADER = 1, /* Packet headers are sampled */
Expand Down Expand Up @@ -671,6 +697,8 @@ enum SFLFlow_type_tag {
SFLFLOW_EX_FUNCTION = 1038,
SFLFLOW_EX_TRANSIT = 1039,
SFLFLOW_EX_Q_DEPTH = 1040,
SFLFLOW_EX_HW_TRAP = 1041,
SFLFLOW_EX_LINUX_REASON = 1042,
SFLFLOW_EX_SOCKET4 = 2100,
SFLFLOW_EX_SOCKET6 = 2101,
SFLFLOW_EX_PROXYSOCKET4 = 2102,
Expand Down
34 changes: 34 additions & 0 deletions src/sflowtool.c
Original file line number Diff line number Diff line change
Expand Up @@ -3708,6 +3708,38 @@ static void readExtendedQueueDepth(SFSample *sample)
sf_log_next32(sample, "queue_depth_bytes");
}

/*_________________----------------------------__________________
_________________ readExtendedHardwareTrap __________________
-----------------____________________________------------------
*/

static void readExtendedHardwareTrap(SFSample *sample)
{
sf_logf(sample, "extendedType", "hw_trap");
char groupName[SFL_MAX_HW_TRAP_LEN+1];
char trapName[SFL_MAX_HW_TRAP_LEN+1];
if(getString(sample, groupName, SFL_MAX_HW_TRAP_LEN) > 0) {
sf_logf(sample, "hw_trap_group", groupName);
}
if(getString(sample, trapName, SFL_MAX_HW_TRAP_LEN) > 0) {
sf_logf(sample, "hw_trap_name", trapName);
}
}

/*_________________----------------------------__________________
_________________ readExtendedLinuxReason __________________
-----------------____________________________------------------
*/

static void readExtendedLinuxReason(SFSample *sample)
{
sf_logf(sample, "extendedType", "linux_reason");
char reason[SFL_MAX_LINUX_REASON_LEN+1];
if(getString(sample, reason, SFL_MAX_LINUX_REASON_LEN) > 0) {
sf_logf(sample, "linux_drop_reason", reason);
}
}

/*_________________---------------------------__________________
_________________ readFlowSample_v2v4 __________________
-----------------___________________________------------------
Expand Down Expand Up @@ -4089,6 +4121,8 @@ static void readDiscardSample(SFSample *sample)
case SFLFLOW_HEADER: readFlowSample_header(sample); break;
case SFLFLOW_EX_FUNCTION: readExtendedFunction(sample); break;
case SFLFLOW_EX_EGRESS_Q: readExtendedEgressQueue(sample); break;
case SFLFLOW_EX_HW_TRAP: readExtendedHardwareTrap(sample); break;
case SFLFLOW_EX_LINUX_REASON: readExtendedLinuxReason(sample); break;
default: skipTLVRecord(sample, tag, length, "discard_sample_element"); break;
}
lengthCheck(sample, "discard_sample_element", start, length);
Expand Down

0 comments on commit 7299efd

Please sign in to comment.