diff --git a/src/sflow.h b/src/sflow.h index 1ed19ed..7949515 100644 --- a/src/sflow.h +++ b/src/sflow.h @@ -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 */ @@ -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, diff --git a/src/sflowtool.c b/src/sflowtool.c index b26e763..5f7b1bf 100644 --- a/src/sflowtool.c +++ b/src/sflowtool.c @@ -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 __________________ -----------------___________________________------------------ @@ -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);