From a18cd32422122adb6bb229580cbdc14cee03d7a9 Mon Sep 17 00:00:00 2001
From: Michal Wasiak <michal.wasiak@gmail.com>
Date: Thu, 8 Oct 2020 20:38:27 +0200
Subject: [PATCH] snmp/bridge_mib: fix length of dot1qTpFdbTable as an index

In the generated code MacAddress is mapped into ASN_OCTET_STR, which uses
a length as a first byte, then the content of MAC/string.
With this behaviour of ASN_OCTET_STR, the index was 1 byte longer than suppose
to be. Anyway, it is not needed to carry the length of MacAddress since it is
defined as fixed in the MIB.

Signed-off-by: Michal Wasiak <michal.wasiak@gmail.com>
---
 .../dot1qTpFdbTable/dot1qTpFdbTable.h         |  2 +-
 .../dot1qTpFdbTable_interface.c               | 31 ++++++++++++++-----
 2 files changed, 24 insertions(+), 9 deletions(-)

diff --git a/userspace/snmpd/bridge_mib/dot1qTpFdbTable/dot1qTpFdbTable.h b/userspace/snmpd/bridge_mib/dot1qTpFdbTable/dot1qTpFdbTable.h
index ee79ebd3c..97e6d7413 100644
--- a/userspace/snmpd/bridge_mib/dot1qTpFdbTable/dot1qTpFdbTable.h
+++ b/userspace/snmpd/bridge_mib/dot1qTpFdbTable/dot1qTpFdbTable.h
@@ -119,7 +119,7 @@ typedef struct dot1qTpFdbTable_mib_index_s {
      * POSSIBLE LENGHT FOR EVERY VARIABLE LENGTH INDEX!
      * Guessing 128 - col/entry(2)  - oid len(11)
 */
-#define MAX_dot1qTpFdbTable_IDX_LEN     8
+#define MAX_dot1qTpFdbTable_IDX_LEN     7
 
 
 /* *********************************************************************
diff --git a/userspace/snmpd/bridge_mib/dot1qTpFdbTable/dot1qTpFdbTable_interface.c b/userspace/snmpd/bridge_mib/dot1qTpFdbTable/dot1qTpFdbTable_interface.c
index c90cddf28..b8b702b95 100644
--- a/userspace/snmpd/bridge_mib/dot1qTpFdbTable/dot1qTpFdbTable_interface.c
+++ b/userspace/snmpd/bridge_mib/dot1qTpFdbTable/dot1qTpFdbTable_interface.c
@@ -135,13 +135,28 @@ _dot1qTpFdbTable_initialize_interface(dot1qTpFdbTable_registration * reg_ptr,  u
      *
      * save interface context for dot1qTpFdbTable
      */
-    /*
-     * Setting up the table's definition
-     */
-    netsnmp_table_helper_add_indexes(tbl_info,
-                                  ASN_UNSIGNED, /** index: dot1qFdbId */
-                                  ASN_OCTET_STR, /** index: dot1qTpFdbAddress */
-                             0);
+        /* Don't use netsnmp_table_helper_add_indexes as in the generated code because MacAddress is
+     * mapped into ASN_OCTET_STR, which has a length as a first byte, then the content of MAC/string.
+     * With this behaviour of ASN_OCTET_STR, the index was 1 byte longer. It is not needed to carry
+     * the length of MacAddress since it is defined with a fixed length in the MIB.
+     */
+    /* netsnmp_table_helper_add_indexes(tbl_info,
+     *                            ASN_UNSIGNED,    // index: dot1qFdbId
+     *                            ASN_OCTET_STR,   // index: dot1qTpFdbAddress
+     *                           0);
+     */
+    snmp_varlist_add_variable(&tbl_info->indexes,
+                                  NULL,
+                                  0,
+                                  ASN_INTEGER,
+                                  NULL,
+                                  0);
+    snmp_varlist_add_variable(&tbl_info->indexes,
+                                  NULL,
+                                  0,
+                                  ASN_PRIV_IMPLIED_OCTET_STR,
+                                  "XXXXXX",
+                                  6);
 
     /*  Define the minimum and maximum accessible columns.  This
         optimizes retrieval. */
@@ -324,7 +339,7 @@ dot1qTpFdbTable_index_to_oid(netsnmp_index *oid_idx,
     memset( &var_dot1qFdbId, 0x00, sizeof(var_dot1qFdbId) );
     var_dot1qFdbId.type = ASN_UNSIGNED;
     memset( &var_dot1qTpFdbAddress, 0x00, sizeof(var_dot1qTpFdbAddress) );
-    var_dot1qTpFdbAddress.type = ASN_OCTET_STR;
+    var_dot1qTpFdbAddress.type = ASN_PRIV_IMPLIED_OCTET_STR;
 
     /*
      * chain temp index varbinds together
-- 
GitLab