Skip to content

Commit 7299efd

Browse files
committed
add support for new packet drop reason structures
1 parent 87cc422 commit 7299efd

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

src/sflow.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,32 @@ typedef struct {
634634
} SFLExtended_queue_depth;
635635
#define XDRSIZ_SFLEXTENDED_Q_DEPTH 4
636636

637+
// Devlink Trap Name
638+
// opaque = flow_data; enterprise = 0; format = 1041
639+
// https://www.kernel.org/doc/html/latest/networking/devlink/devlink-trap.html
640+
// XDR spec:
641+
// struct extended_hw_trap {
642+
// string group<>; /* NET_DM_ATTR_HW_TRAP_GROUP_NAME */
643+
// string trap<>; /* NET_DM_ATTR_HW_TRAP_NAME */
644+
// }
645+
typedef struct _SFLExtended_hw_trap {
646+
SFLString group;
647+
SFLString trap;
648+
} SFLExtended_hw_trap;
649+
#define SFL_MAX_HW_TRAP_LEN 64
650+
651+
// Linux drop_monitor reason
652+
// opaque = flow_data; enterprise = 0; format = 1042
653+
// https://github.com/torvalds/linux/blob/master/include/net/dropreason.h
654+
// XDR spec:
655+
// struct extended_linux_drop_reason {
656+
// string reason<>; /* NET_DM_ATTR_REASON */
657+
// }
658+
typedef struct _SFLExtended_linux_reason {
659+
SFLString reason;
660+
} SFLExtended_linux_reason;
661+
#define SFL_MAX_LINUX_REASON_LEN 64
662+
637663
enum SFLFlow_type_tag {
638664
/* enterprise = 0, format = ... */
639665
SFLFLOW_HEADER = 1, /* Packet headers are sampled */
@@ -671,6 +697,8 @@ enum SFLFlow_type_tag {
671697
SFLFLOW_EX_FUNCTION = 1038,
672698
SFLFLOW_EX_TRANSIT = 1039,
673699
SFLFLOW_EX_Q_DEPTH = 1040,
700+
SFLFLOW_EX_HW_TRAP = 1041,
701+
SFLFLOW_EX_LINUX_REASON = 1042,
674702
SFLFLOW_EX_SOCKET4 = 2100,
675703
SFLFLOW_EX_SOCKET6 = 2101,
676704
SFLFLOW_EX_PROXYSOCKET4 = 2102,

src/sflowtool.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3708,6 +3708,38 @@ static void readExtendedQueueDepth(SFSample *sample)
37083708
sf_log_next32(sample, "queue_depth_bytes");
37093709
}
37103710

3711+
/*_________________----------------------------__________________
3712+
_________________ readExtendedHardwareTrap __________________
3713+
-----------------____________________________------------------
3714+
*/
3715+
3716+
static void readExtendedHardwareTrap(SFSample *sample)
3717+
{
3718+
sf_logf(sample, "extendedType", "hw_trap");
3719+
char groupName[SFL_MAX_HW_TRAP_LEN+1];
3720+
char trapName[SFL_MAX_HW_TRAP_LEN+1];
3721+
if(getString(sample, groupName, SFL_MAX_HW_TRAP_LEN) > 0) {
3722+
sf_logf(sample, "hw_trap_group", groupName);
3723+
}
3724+
if(getString(sample, trapName, SFL_MAX_HW_TRAP_LEN) > 0) {
3725+
sf_logf(sample, "hw_trap_name", trapName);
3726+
}
3727+
}
3728+
3729+
/*_________________----------------------------__________________
3730+
_________________ readExtendedLinuxReason __________________
3731+
-----------------____________________________------------------
3732+
*/
3733+
3734+
static void readExtendedLinuxReason(SFSample *sample)
3735+
{
3736+
sf_logf(sample, "extendedType", "linux_reason");
3737+
char reason[SFL_MAX_LINUX_REASON_LEN+1];
3738+
if(getString(sample, reason, SFL_MAX_LINUX_REASON_LEN) > 0) {
3739+
sf_logf(sample, "linux_drop_reason", reason);
3740+
}
3741+
}
3742+
37113743
/*_________________---------------------------__________________
37123744
_________________ readFlowSample_v2v4 __________________
37133745
-----------------___________________________------------------
@@ -4089,6 +4121,8 @@ static void readDiscardSample(SFSample *sample)
40894121
case SFLFLOW_HEADER: readFlowSample_header(sample); break;
40904122
case SFLFLOW_EX_FUNCTION: readExtendedFunction(sample); break;
40914123
case SFLFLOW_EX_EGRESS_Q: readExtendedEgressQueue(sample); break;
4124+
case SFLFLOW_EX_HW_TRAP: readExtendedHardwareTrap(sample); break;
4125+
case SFLFLOW_EX_LINUX_REASON: readExtendedLinuxReason(sample); break;
40924126
default: skipTLVRecord(sample, tag, length, "discard_sample_element"); break;
40934127
}
40944128
lengthCheck(sample, "discard_sample_element", start, length);

0 commit comments

Comments
 (0)