Dave Shield wrote:
> On 10 February 2010 09:23, Josef Moellers <[email protected]>
> wrote:
>> I'd like to amend the etherlike-mib code for Linux....
>> Any comment/objection while I locally write/test?
>
> Go right ahead.
> We look forward to seeing whatever you come up with.
The patch (against 5.5) is appended.
Thanks in advance,
Josef
--
These are my personal views and not those of Fujitsu Technology Solutions!
Josef Möllers (Pinguinpfleger bei FTS)
If failure had no penalty success would not be a prize (T. Pratchett)
Company Details: http://de.ts.fujitsu.com/imprint.html
--- net-snmp-5.5/agent/mibgroup/etherlike-mib/data_access/dot3stats_linux.c.josef 2010-02-10 12:50:00.000000000 +0100
+++ net-snmp-5.5/agent/mibgroup/etherlike-mib/data_access/dot3stats_linux.c 2010-02-10 12:50:53.000000000 +0100
@@ -331,6 +331,80 @@
#endif
}
+/*
+ * NAME: getulongfromsysclassnetstatistics
+ * PURPOSE: To get a single statistics value from /sys/class/net/<ifname>/statistics/<ctrname>
+ * ARGUMENTS: ifname: interface name
+ * ctrname: counter name
+ * valuep: where to store value
+ * RETURNS: 0 if value not available
+ * non-0 if value available
+ */
+static int
+getulongfromsysclassnetstatistics(const char *ifname, char *ctrname, u_long *valuep)
+{
+ char path[256];
+ FILE *fp;
+ int rv;
+
+ if (ifname == NULL || ctrname == NULL || valuep == NULL)
+ return 0;
+
+ snprintf(path, sizeof(path), "/sys/class/net/%s/statistics/%s", ifname, ctrname);
+ fp = fopen(path, "rt");
+ if (fp == NULL)
+ return 0;
+
+ rv = 1;
+ if (fscanf(fp, "%lu", valuep) != 1)
+ rv = 0;
+
+ fclose(fp);
+
+ return rv;
+}
+
+/*
+ * NAME: interface_sysclassnet_dot3stats_get
+ * PURPOSE: To get ethernet statistics from /sys/class/net/...
+ * ARGUMENTS: rowreq_ctx: where to store the value(s)
+ * name: interface name
+ * RETURNS: nothing. fields not set if data not available
+ */
+void
+interface_sysclassnet_dot3stats_get (dot3StatsTable_rowreq_ctx *rowreq_ctx, const char *name)
+{
+ u_long value;
+ dot3StatsTable_data *data = &rowreq_ctx->data;
+
+ if (getulongfromsysclassnetstatistics(name, "rx_errors", &value)) {
+ data->dot3StatsFCSErrors = value;
+ rowreq_ctx->column_exists_flags |= COLUMN_DOT3STATSFCSERRORS_FLAG;
+ }
+ if (getulongfromsysclassnetstatistics(name, "tx_dropped", &value)) {
+ data->dot3StatsDeferredTransmissions = value;
+ rowreq_ctx->column_exists_flags |= COLUMN_DOT3STATSDEFERREDTRANSMISSIONS_FLAG;
+ }
+ if (getulongfromsysclassnetstatistics(name, "tx_fifo_errors", &value)) {
+ data->dot3StatsInternalMacTransmitErrors = value;
+ rowreq_ctx->column_exists_flags |= COLUMN_DOT3STATSINTERNALMACTRANSMITERRORS_FLAG;
+ }
+ if (getulongfromsysclassnetstatistics(name, "tx_carrier_errors", &value)) {
+ data->dot3StatsCarrierSenseErrors = value;
+ rowreq_ctx->column_exists_flags |= COLUMN_DOT3STATSCARRIERSENSEERRORS_FLAG;
+ }
+ if (getulongfromsysclassnetstatistics(name, "rx_frame_errors", &value)) {
+ data->dot3StatsFrameTooLongs = value;
+ rowreq_ctx->column_exists_flags |= COLUMN_DOT3STATSFRAMETOOLONGS_FLAG;
+ }
+ if (getulongfromsysclassnetstatistics(name, "rx_fifo_errors", &value)) {
+ data->dot3StatsInternalMacReceiveErrors = value;
+ rowreq_ctx->column_exists_flags |= COLUMN_DOT3STATSINTERNALMACRECEIVEERRORS_FLAG;
+ }
+
+ return;
+}
+
/* ioctl wrapper
--- net-snmp-5.5/agent/mibgroup/etherlike-mib/dot3StatsTable/dot3StatsTable_data_access.c.josef 2010-02-10 12:51:11.000000000 +0100
+++ net-snmp-5.5/agent/mibgroup/etherlike-mib/dot3StatsTable/dot3StatsTable_data_access.c 2010-02-10 12:52:12.000000000 +0100
@@ -326,6 +326,8 @@
continue;
}
+ interface_sysclassnet_dot3stats_get(rowreq_ctx, p->name);
+
/*
* insert into table container
*/
------------------------------------------------------------------------------
SOLARIS 10 is the OS for Data Centers - provides features such as DTrace,
Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW
http://p.sf.net/sfu/solaris-dev2dev
_______________________________________________
Net-snmp-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders