Re: netsnmp_register_table_iterator() failing

bps tech <[email protected]> Sat, 9 Nov 2024 00:56:17 +0530
Newsgroups gmane.network.net-snmp.user
Message-ID <CADsii7f2XJdU5Q7xiO2FGPskArfUZ=BJe3mVCG4Yf76mZQH+hA@mail.gmail.com>
--===============6859375516658191205==
Content-Type: multipart/alternative; boundary="0000000000003c002206266bba9e"

--0000000000003c002206266bba9e
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Hi Brian,

Thanks for the quick reply. I understand your point, however it will take
it's own time if I am going with private enterprise  number, controlled by
IANA.

But for now, could you help me what mistake I might be doing.

I hope it is possible to extend MIB-2 standard interface, I found this
example to extend standard MIB-2 interface over internet.

Thanks & Regards,
Bhashkar

On Sat, Nov 9, 2024 at 12:43=E2=80=AFAM Atkins, Brian <Brian.Atkins@netapp.=
com>
wrote:

> First, you shouldn=E2=80=99t be adding things to MIB-2, it is standards
> controlled. If you want to add a MIB branch, you should do it under the
> enterprise branch (1.3.6.1.4.1).  You=E2=80=99ll need a private enterpris=
e number,
> which are controlled by the IANA:
> https://www.iana.org/assignments/enterprise-numbers/
>
>
>
> You might be able to use the experimental branch (
> http://oid-info.com/get/1.3.6.1.3).  I=E2=80=99m not sure what=E2=80=99s =
involved in
> avoiding collisions on that branch.
>
>
>
> There might be other branches or subbranches that are appropriate that I=
=E2=80=99m
> not aware of.
>
>
>
> Regards,
>
> Brian
>
>
>
> *From:* bps tech <[email protected]>
> *Sent:* Friday, November 8, 2024 11:50 AM
> *To:* [email protected]
> *Subject:* netsnmp_register_table_iterator() failing
>
>
>
> You don't often get email from [email protected]. Learn why this is
> important <https://aka.ms/LearnAboutSenderIdentification>
>
>
>
> *EXTERNAL EMAIL - USE CAUTION when clicking links or attachments *
>
>
>
> Hi,
>
>
>
> I am writing my first code for SNMP. I am trying to extend the MIB-2
> standard interface table. During this process table iterator registration
> function    netsnmp_register_table_iterator(reg, iinfo)   is failing.
>
>
>
> Here is my code:
>
>
>
> void init_myCustomIfTable(void) {
>
>     static oid ifTable_oid[] =3D {1, 3, 6, 1, 2, 1, 2, 99};  // Base OID =
for
> custom table extension
>
>     size_t ifTable_oid_len =3D OID_LENGTH(ifTable_oid);
>
>
>
>     netsnmp_handler_registration *reg;
>
>     netsnmp_table_registration_info *table_info;
>
>     netsnmp_iterator_info *iinfo;
>
>
>
>     AIM_LOG_INFO("init_myCustomIfTable \n");
>
>     // Register the table with the SNMP agent
>
>     reg =3D netsnmp_create_handler_registration("myCustomIfTable",
>
>                                               get_custom_metric_data,
> ifTable_oid,
>
>                                               ifTable_oid_len,
>
>                                               HANDLER_CAN_RONLY);
>
>
>
>     // Error checking for handler registration
>
>     if (!reg) {
>
>
>
>         AIM_LOG_INFO("Failed to create handler registration for
> myCustomIfTable \n");
>
>         return;
>
>     }
>
>
>
>     // Define table structure and columns (e.g., index for ifIndex and
> custom metrics)
>
>     table_info =3D SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info);
>
>     if (!table_info) {
>
>         AIM_LOG_INFO("Failed to allocate memory for table registration
> info \n");
>
>         return;
>
>     }
>
>
>
>     netsnmp_table_helper_add_index(table_info, ASN_INTEGER, 0);  // Index
> for ifIndex
>
>     table_info->min_column =3D COLUMN_CUSTOM_METRIC1;           // Starti=
ng
> column for custom data
>
>     table_info->max_column =3D COLUMN_CUSTOM_METRIC2;           // Ending
> column for custom data
>
>
>
>     // Define iterator information for table walking
>
>     iinfo =3D SNMP_MALLOC_TYPEDEF(netsnmp_iterator_info);
>
>     if (!iinfo) {
>
>         AIM_LOG_INFO("Failed to allocate memory for iterator info \n");
>
>         free(table_info);  // Free memory before returning
>
>         return;
>
>     }
>
> iinfo->get_first_data_point =3D get_first_data_point;
>
>     iinfo->get_next_data_point =3D get_next_data_point;
>
>     iinfo->table_reginfo =3D table_info;
>
>
>
>     // Register the table iterator handler
>
>     if (!netsnmp_register_table_iterator(reg, iinfo)) {
>
>         AIM_LOG_INFO("Failed to register table iterator handler for
> myCustomIfTable \n");
>
>         free(iinfo);  // Clean up allocated memory
>
>         free(table_info);  // Clean up allocated memory
>
>         return;
>
>     }
>
> I am attaching my MIB file also.
>
>
>
> Any help in this regard would be highly appreciated.
>
>
>
> Thanks & Regards,
>
> Bhashkar
>

--0000000000003c002206266bba9e
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div dir=3D"ltr">Hi Brian,<div><br></div><div>Thanks for t=
he quick reply. I understand your point, however it will take it&#39;s own =
time if I am going with private=C2=A0enterprise=C2=A0 number, controlled by=
 IANA.</div><div><br></div><div>But for now, could you help me what mistake=
 I might be doing.=C2=A0</div><div><br></div><div>I hope it is possible to =
extend MIB-2 standard interface, I found this example to extend standard MI=
B-2 interface over internet.</div><div><br></div><div>Thanks &amp;=C2=A0Reg=
ards,</div><div>Bhashkar</div></div><br><div class=3D"gmail_quote"><div dir=
=3D"ltr" class=3D"gmail_attr">On Sat, Nov 9, 2024 at 12:43=E2=80=AFAM Atkin=
s, Brian &lt;<a href=3D"mailto:[email protected]">Brian.Atkins@netapp=
.com</a>&gt; wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"mar=
gin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1=
ex"><div class=3D"msg-4015593467883810255">





<div lang=3D"EN-US" style=3D"overflow-wrap: break-word;">
<div class=3D"m_-4015593467883810255WordSection1">
<p class=3D"MsoNormal"><span style=3D"font-size:11pt">First, you shouldn=E2=
=80=99t be adding things to MIB-2, it is standards controlled. If you want =
to add a MIB branch, you should do it under the enterprise branch (1.3.6.1.=
4.1).=C2=A0 You=E2=80=99ll need a private enterprise number,
 which are controlled by the IANA: <a href=3D"https://www.iana.org/assignme=
nts/enterprise-numbers/" target=3D"_blank">
https://www.iana.org/assignments/enterprise-numbers/</a><u></u><u></u></spa=
n></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11pt"><u></u>=C2=A0<u></u><=
/span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11pt">You might be able to =
use the experimental branch (<a href=3D"http://oid-info.com/get/1.3.6.1.3" =
target=3D"_blank">http://oid-info.com/get/1.3.6.1.3</a>).=C2=A0 I=E2=80=99m=
 not sure what=E2=80=99s involved in avoiding collisions on that branch.<u>=
</u><u></u></span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11pt"><u></u>=C2=A0<u></u><=
/span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11pt">There might be other =
branches or subbranches that are appropriate that I=E2=80=99m not aware of.=
<u></u><u></u></span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11pt"><u></u>=C2=A0<u></u><=
/span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11pt">Regards,<u></u><u></u=
></span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11pt">Brian<u></u><u></u></=
span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11pt"><u></u>=C2=A0<u></u><=
/span></p>
<div>
<div style=3D"border-right:none;border-bottom:none;border-left:none;border-=
top:1pt solid rgb(225,225,225);padding:3pt 0in 0in">
<p class=3D"MsoNormal"><b><span style=3D"font-size:11pt;font-family:Calibri=
,sans-serif">From:</span></b><span style=3D"font-size:11pt;font-family:Cali=
bri,sans-serif"> bps tech &lt;<a href=3D"mailto:[email protected]" target=
=3D"_blank">[email protected]</a>&gt;
<br>
<b>Sent:</b> Friday, November 8, 2024 11:50 AM<br>
<b>To:</b> <a href=3D"mailto:[email protected]" target=
=3D"_blank">[email protected]</a><br>
<b>Subject:</b> netsnmp_register_table_iterator() failing<u></u><u></u></sp=
an></p>
</div>
</div>
<p class=3D"MsoNormal"><u></u>=C2=A0<u></u></p>
<table border=3D"0" cellspacing=3D"0" cellpadding=3D"0" align=3D"left" widt=
h=3D"100%" style=3D"width:100%">
<tbody>
<tr>
<td width=3D"0" style=3D"width:0.3pt;background:rgb(166,166,166);padding:5.=
25pt 1.5pt">
</td>
<td width=3D"100%" style=3D"background:revert;border:revert;color:revert;di=
rection:revert;display:revert;font-size:revert;height:revert;letter-spacing=
:revert;line-height:revert;margin:revert;opacity:revert;outline:revert;over=
flow:revert;padding:revert;table-layout:revert;text-align:revert;text-inden=
t:revert;text-orientation:revert;text-overflow:revert;text-transform:revert=
;vertical-align:revert;white-space:revert;width:revert;word-break:revert;wo=
rd-spacing:revert;writing-mode:revert;zoom:revert">
<div>
<p class=3D"MsoNormal">
<span style=3D"font-size:9pt;font-family:&quot;Segoe UI&quot;,sans-serif;co=
lor:rgb(33,33,33)">You don&#39;t often get email from
<a href=3D"mailto:[email protected]" target=3D"_blank">[email protected]=
m</a>. <a href=3D"https://aka.ms/LearnAboutSenderIdentification" target=3D"=
_blank">
Learn why this is important</a> <u></u><u></u></span></p>
</div>
</td>
<td width=3D"75" style=3D"background:revert;border:revert;color:revert;dire=
ction:revert;display:revert;font-size:revert;height:revert;letter-spacing:r=
evert;line-height:revert;margin:revert;opacity:revert;outline:revert;overfl=
ow:revert;padding:revert;table-layout:revert;text-align:revert;text-indent:=
revert;text-orientation:revert;text-overflow:revert;text-transform:revert;v=
ertical-align:revert;white-space:revert;width:revert;word-break:revert;word=
-spacing:revert;writing-mode:revert;zoom:revert">
</td>
</tr>
</tbody>
</table>
<div>
<p class=3D"MsoNormal"><span style=3D"display:none"><u></u>=C2=A0<u></u></s=
pan></p>
<table border=3D"1" cellspacing=3D"0" cellpadding=3D"0" align=3D"left" styl=
e=3D"background:rgb(243,109,109)">
<tbody>
<tr>
<td style=3D"padding:7.5pt">
<p class=3D"MsoNormal">
<b><span style=3D"font-family:Arial,sans-serif;color:black">EXTERNAL EMAIL =
- USE CAUTION when clicking links or attachments
</span></b><u></u><u></u></p>
</td>
</tr>
</tbody>
</table>
<p class=3D"MsoNormal" style=3D"margin-bottom:12pt"><br>
<br>
<u></u><u></u></p>
<div>
<div>
<p class=3D"MsoNormal">Hi, <u></u><u></u></p>
<div>
<p class=3D"MsoNormal"><u></u>=C2=A0<u></u></p>
</div>
<div>
<p class=3D"MsoNormal">I am writing my first code for SNMP. I am trying to =
extend the MIB-2 standard interface table. During this process table iterat=
or registration function=C2=A0 =C2=A0 netsnmp_register_table_iterator(reg, =
iinfo)=C2=A0=C2=A0=C2=A0is failing.=C2=A0<u></u><u></u></p>
</div>
<div>
<p class=3D"MsoNormal"><u></u>=C2=A0<u></u></p>
</div>
<div>
<p class=3D"MsoNormal">Here is my code:<u></u><u></u></p>
</div>
<div>
<p class=3D"MsoNormal"><u></u>=C2=A0<u></u></p>
</div>
<div>
<p class=3D"MsoNormal">void init_myCustomIfTable(void) {<br>
<br>
=C2=A0 =C2=A0 static oid ifTable_oid[] =3D {1, 3, 6, 1, 2, 1, 2, 99}; =C2=
=A0// Base OID for custom table extension<br>
<br>
=C2=A0 =C2=A0 size_t ifTable_oid_len =3D OID_LENGTH(ifTable_oid);<br>
<br>
<br>
<br>
=C2=A0 =C2=A0 netsnmp_handler_registration *reg;<br>
<br>
=C2=A0 =C2=A0 netsnmp_table_registration_info *table_info;<br>
<br>
=C2=A0 =C2=A0 netsnmp_iterator_info *iinfo;<br>
<br>
<br>
<br>
=C2=A0 =C2=A0 AIM_LOG_INFO(&quot;init_myCustomIfTable \n&quot;);<br>
<br>
=C2=A0 =C2=A0 // Register the table with the SNMP agent<br>
<br>
=C2=A0 =C2=A0 reg =3D netsnmp_create_handler_registration(&quot;myCustomIfT=
able&quot;,<br>
<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 get_custom_metric_data, ifTable_oid,<br>
<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 ifTable_oid_len,<br>
<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 HANDLER_CAN_RONLY);<br>
<br>
<br>
<br>
=C2=A0 =C2=A0 // Error checking for handler registration<br>
<br>
=C2=A0 =C2=A0 if (!reg) {<br>
<br>
<br>
<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 AIM_LOG_INFO(&quot;Failed to create handler reg=
istration for myCustomIfTable \n&quot;);<br>
<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 return;<br>
<br>
=C2=A0 =C2=A0 }<br>
<br>
<br>
<br>
=C2=A0 =C2=A0 // Define table structure and columns (e.g., index for ifInde=
x and custom metrics)<br>
<br>
=C2=A0 =C2=A0 table_info =3D SNMP_MALLOC_TYPEDEF(netsnmp_table_registration=
_info);<br>
<br>
=C2=A0 =C2=A0 if (!table_info) {<br>
<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 AIM_LOG_INFO(&quot;Failed to allocate memory fo=
r table registration info \n&quot;);<br>
<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 return;<br>
<br>
=C2=A0 =C2=A0 }<br>
<br>
<br>
<br>
=C2=A0 =C2=A0 netsnmp_table_helper_add_index(table_info, ASN_INTEGER, 0); =
=C2=A0// Index for ifIndex<br>
<br>
=C2=A0 =C2=A0 table_info-&gt;min_column =3D COLUMN_CUSTOM_METRIC1; =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 // Starting column for custom data<br>
<br>
=C2=A0 =C2=A0 table_info-&gt;max_column =3D COLUMN_CUSTOM_METRIC2; =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 // Ending column for custom data<br>
<br>
<br>
<br>
=C2=A0 =C2=A0 // Define iterator information for table walking<br>
<br>
=C2=A0 =C2=A0 iinfo =3D SNMP_MALLOC_TYPEDEF(netsnmp_iterator_info);<br>
<br>
=C2=A0 =C2=A0 if (!iinfo) {<br>
<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 AIM_LOG_INFO(&quot;Failed to allocate memory fo=
r iterator info \n&quot;);<br>
<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 free(table_info); =C2=A0// Free memory before r=
eturning<br>
<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 return;<br>
<br>
=C2=A0 =C2=A0 }<br>
<br>
iinfo-&gt;get_first_data_point =3D get_first_data_point;<br>
<br>
=C2=A0 =C2=A0 iinfo-&gt;get_next_data_point =3D get_next_data_point;<br>
<br>
=C2=A0 =C2=A0 iinfo-&gt;table_reginfo =3D table_info;<br>
<br>
<br>
<br>
=C2=A0 =C2=A0 // Register the table iterator handler<br>
<br>
=C2=A0 =C2=A0 if (!netsnmp_register_table_iterator(reg, iinfo)) {<br>
<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 AIM_LOG_INFO(&quot;Failed to register table ite=
rator handler for myCustomIfTable \n&quot;);<br>
<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 free(iinfo); =C2=A0// Clean up allocated memory=
<br>
<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 free(table_info); =C2=A0// Clean up allocated m=
emory<br>
<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 return;<br>
<br>
=C2=A0 =C2=A0 }<br>
<br>
I am attaching my MIB file also.<u></u><u></u></p>
</div>
<div>
<p class=3D"MsoNormal"><u></u>=C2=A0<u></u></p>
</div>
<div>
<p class=3D"MsoNormal">Any help in this regard would be highly appreciated.=
<u></u><u></u></p>
</div>
<div>
<p class=3D"MsoNormal"><u></u>=C2=A0<u></u></p>
</div>
<div>
<p class=3D"MsoNormal">Thanks &amp; Regards,<u></u><u></u></p>
</div>
<div>
<p class=3D"MsoNormal">Bhashkar<u></u><u></u></p>
</div>
</div>
</div>
</div>
</div>
</div>

</div></blockquote></div></div>

--0000000000003c002206266bba9e--


--===============6859375516658191205==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline


--===============6859375516658191205==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Net-snmp-users mailing list
[email protected]
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/listinfo/net-snmp-users

--===============6859375516658191205==--