This is a multi-part message in MIME format.
--------------090405070403040502040505
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

Hi,

Feel free to ignore or include this, or tell me it's been done better! I
thought I'd put it out for reference if nothing else.

I needed a way to report the RedHat style ethernet port alias names
(/etc/sysconfig/network-scripts/ifcfg-*) as ifDescr for a series of
products.

The, rather basic, patch tucks into the ifTable code and rewrites the
tmp_descr field if it can find an appropriate alias, else it leaves the
field well alone.
Any interface without such a name is therefore unaffected (I assume this
will apply to all other systems, although haven't tested outside of our
environment).

Cheers,

John.

Patch file attached.

--------------090405070403040502040505
Content-Type: text/x-patch;
name="net-snmpd-5.3.0.1-ifDescr_Alias.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="net-snmpd-5.3.0.1-ifDescr_Alias.patch"

--- net-snmp-5.3.0.1/agent/mibgroup/if-mib/ifTable/ifTable.c 2006-04-11 14:48:51.580782604 +0100
+++ net-snmp-5.3.0.1/agent/mibgroup/if-mib/ifTable/ifTable.c.ifDescr_alias 2006-04-11 14:57:13.748530262 +0100
@@ -36,6 +36,9 @@
# include "if-mib/ifXTable/ifXTable.h"
#endif

+// RedHat alias includes.
+#include
+
oid ifTable_oid[] = { IFTABLE_OID };
int ifTable_oid_size = OID_LENGTH(ifTable_oid);

@@ -425,10 +428,13 @@
} else
tmp_descr = rowreq_ctx->data.ifDescr;

- if (NULL != tmp_descr)
- tmp_len = strlen(tmp_descr);
- else
+ if (NULL != tmp_descr) {
+ //RedHat - Rename interfaces to their RedHat aliases.
+ eth2if(tmp_descr);
+ tmp_len = strlen(tmp_descr);
+ } else {
tmp_len = 0;
+ }

/*
* TODO:231: |-> Extract the current value of the ifDescr data.
@@ -2307,5 +2313,53 @@
return rc;
} /* ifTable_check_dependencies */

+/*
+ * eth2if takes an interface name and converts it to the RedHat alias
+ * for that port.
+ *
+ * If no alias is found the interface name is unchanged.
+ *
+*/
+void
+eth2if(char* ethname)
+{
+//sprintf(ethname, "%s-Hi There!", ethname); return;
+ DIR* dir;
+ struct dirent* entry;
+ dir = opendir ("/etc/sysconfig/network-scripts");
+ if (!dir) return;
+ while ((entry = readdir(dir))) {
+ char* filename = strstr(entry->d_name, "ifcfg-");
+ if (filename) {
+ char path[128];
+ sprintf(path, "/etc/sysconfig/network-scripts/%s", entry->d_name);
+ FILE* f = fopen(path, "r");
+ if (!f) {closedir(dir); return;}
+ while (1) {
+ char* lineptr = NULL;
+ size_t length = 0;
+ if (getline(&lineptr, &length, f) == -1)
+ break;
+
+ char* lf = strchr(lineptr, '\n');
+ if (lf) *lf = 0;
+
+ if (!strncmp(lineptr, "DEVICE=", 7)) {
+ if (!strcmp(lineptr + 7, ethname)) {
+ sprintf(ethname, "%s", filename + 6);
+ fclose(f);
+ closedir(dir);
+ return;
+ }
+ }
+ free(lineptr);
+ }
+ fclose(f);
+ }
+ }
+ closedir(dir);
+ return;
+}
+
/** @} */
/** @{ */
--- net-snmp-5.3.0.1/agent/mibgroup/if-mib/ifTable/ifTable.h 2006-04-11 14:48:55.927615165 +0100
+++ net-snmp-5.3.0.1/agent/mibgroup/if-mib/ifTable/ifTable.h.ifDescr_Alias 2006-04-11 14:49:12.173989540 +0100
@@ -700,6 +700,9 @@
int ifTable_check_dependencies(ifTable_rowreq_ctx * ctx);


+ // RH definition:
+ void eth2if(char *ethname);
+
/*
* DUMMY markers, ignore
*


--------------090405070403040502040505--



-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=...057&dat=121642
_______________________________________________
Net-snmp-coders mailing list
Net-snmp-coders@lists.sourceforge.net
https://lists.sourceforge.net/lists/...et-snmp-coders