Re: How to avoid having ".0" at the end of the oids coming from a module
dga via Net-snmp-coders <[email protected]>
| Newsgroups | gmane.network.net-snmp.devel |
|---|---|
| Message-ID | <[email protected]> |
Thanks a lot Magnus for your answer !
I ever saw this kind of answers on the forum, so you probably right ...
However I not sure to understand it clearly in fact (may be there is
another way to do it ?)
Anyway I had to find a solution, and I manage to remove the ".0" at the
end of the oid, doing a fix on the function (header_generic):
int header_generic_fix(struct variable *vp,
oid * name,
size_t * length,
int exact, size_t * var_len, WriteMethod **
write_method,
int offset, int index)
{
oid newname[MAX_OID_LEN];
int result;
memcpy((char *) newname, (char *) vp->name, (int) vp->namelen *
sizeof(oid));
result = snmp_oid_compare(name, *length, newname, vp->namelen);
/* In case some OID of the "fake" interface are requested, we
remove them */
if (newname[index] == offset-1) {
newname[index]=offset;
result=1;
}
if ((exact && (result != 0)) || (!exact && (result >= 0))) return
(MATCH_FAILED);
memcpy((char *) name, (char *) newname, ((int) vp->namelen) *
sizeof(oid));
*length = vp->namelen;
*write_method = (WriteMethod*)0;
*var_len = sizeof(long); /* default to 'long' results */
return (MATCH_SUCCEEDED);
}
And I use it like that:
if (header_generic_fix(vp, name, length, exact, var_len,
write_method, OFFSET_TO_GPON, sizeof(gpon_fields_alias_oid)/sizeof(int)
+ 1) == MATCH_FAILED) {
snmp_log(LOG_ERR, "Error header_generic_fix: return
MATCH_FAILED !\n");
return NULL;
}
/!\ I do not advise to do this. There is probably another solution to do
it correctly ...
Best Regards,
Damien GARCIA
Le 16/04/2021 à 23:31, Magnus Fromreide a écrit :
> On Fri, Apr 16, 2021 at 04:41:43PM +0200, dga via Net-snmp-coders wrote:
>> Hello,
>>
>> I have written a module allowing to add "specifics" interfaces at a fixed
>> oid (50000) following the "linux" interfaces provided by default by the
>> package (version 5.7.3).
>>
>> However, it's not good for the customer has there is ".0" at the end of the
>> oids inserted for the "specifics" interfaces (the same oids for the "linux"
>> interfaces do not have this ".0" at the end).
>>
>> Example: request on the "alias field" of the mib2 (in ifXEntry)
>>
>> $ snmpwalk -v2c -c neufnet 192.168.247.123 1.3.6.1.2.1.31.1.1.1.18
>> iso.3.6.1.2.1.31.1.1.1.18.1 = ""
>> iso.3.6.1.2.1.31.1.1.1.18.2 = ""
>> iso.3.6.1.2.1.31.1.1.1.18.3 = ""
>> iso.3.6.1.2.1.31.1.1.1.18.4 = ""
>> iso.3.6.1.2.1.31.1.1.1.18.5 = ""
>> iso.3.6.1.2.1.31.1.1.1.18.6 = ""
>> iso.3.6.1.2.1.31.1.1.1.18.7 = ""
>> iso.3.6.1.2.1.31.1.1.1.18.8 = ""
>> iso.3.6.1.2.1.31.1.1.1.18.9 = ""
>> iso.3.6.1.2.1.31.1.1.1.18.10 = ""
>> iso.3.6.1.2.1.31.1.1.1.18.11 = ""
>> iso.3.6.1.2.1.31.1.1.1.18.50000.0 = STRING: "description of the specific
>> interface" <= Here is the oid inserted by the module with the ".0" at
>> the end
>>
>> Instead of having:
>>
>> iso.3.6.1.2.1.31.1.1.1.18.50000.0 = STRING: "description of the specific
>> interface"
>>
>> I would like having:
>>
>> iso.3.6.1.2.1.31.1.1.1.18.50000 = STRING: "description of the specific
>> interface"
>>
>>
>> May be someone has ever faced the same issue ?
> ifXEntry is a table and so ifAlias has an index value last.
>
> ifAlias has the oid .1.3.6.1.2.1.31.1.1.1.18 and you want 50000 to be
> the table index. It sounds as if you are registering ifXEntry.*.50000 as
> singular values and those should have a trailing 0, like e.g.
> sysContact and the helpers are adding those for you.
>
> You want to add a table row, not a number of values.
>
> /MF
>
>> Best Regards,
>>
>> Damien GARCIA
>>
>>
>> Bellow the some parts of the code I use to create the module:
>>
>>
>> #define OFFSET_TO_GPON 50000
>>
>> #define ALIAS 18
>>
>> static struct variable2 gpon_fields_alias[] = { ALIAS, ASN_OCTET_STR, RONLY,
>> var_update_field, 2, { 18, 0 } };
>>
>> static oid gpon_fields_alias_oid[] = { 1, 3, 6, 1, 2, 1, 31, 1, 1, 1 }; /*
>> .1.3.6.1.2.1.31.1.1.1 (ifXEntry) */
>>
>> static void register_mib_interface_tree()
>> {
>> /* Register OID for gpon0 alias in ifXEntry*/
>> gpon_fields_alias[0].name[1] = OFFSET_TO_GPON;
>> REGISTER_MIB("gpon_fields_alias", gpon_fields_alias, variable2,
>> gpon_fields_alias_oid);
>> }
>>
>> static u_char* var_update_field(struct variable *vp, oid * name, size_t *
>> length, int exact, size_t * var_len, WriteMethod ** write_method)
>> {
>> DEBUGMSGTL(("gpon0", "var_update_field entered\n"));
>> if (header_generic(vp, name, length, exact, var_len, write_method) ==
>> MATCH_FAILED) {
>> snmp_log(LOG_ERR, "Error header_generic_fix: return MATCH_FAILED
>> !\n");
>> return NULL;
>> }
>>
>> switch (vp->magic) {
>> case ALIAS: /* This object is an 'alias' name for the interface as
>> specified by a network manager, and provides a non-volatile 'handle' for the
>> interface */
>> *var_len = strlen(descriptionGpon_g);
>> return (u_char *) descriptionGpon_g;
>>
>> default:
>> DEBUGMSGTL(("snmpd", "unknown sub-id %d in
>> mib_gpon/var_update_field\n", vp->magic));
>>
>> }
>> return NULL;
>> }
>>
>>
>>
>> _______________________________________________
>> Net-snmp-coders mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/net-snmp-coders
_______________________________________________
Net-snmp-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders