]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib: allow traps with differently indexed objects
authorPat Ruddy <pat@voltanet.io>
Wed, 21 Oct 2020 17:22:06 +0000 (18:22 +0100)
committerPat Ruddy <pat@voltanet.io>
Tue, 2 Feb 2021 09:37:14 +0000 (09:37 +0000)
The function smux_trap only allows the paaasin of one index which is
applied to all indexed objects. However there is a requirement for
differently indexed objects within a singe trap. This commit
introduces a new function smux_trap_multi_index which can be called
with an array of indices. If this array is onf length 1 the original
smux_trap behaviour is maintained. smux_trap now calls the new
function with and index array length of 1 to avoid changes to
existing callers.

Signed-off-by: Pat Ruddy <pat@voltanet.io>
lib/agentx.c
lib/smux.h

index 603d8d6172d7926f7e842d9682cc67331a60914b..cf3814bc181e2cf4a00002fea5e2c7973b6ef674 100644 (file)
@@ -267,6 +267,23 @@ int smux_trap(struct variable *vp, size_t vp_len, const oid *ename,
              const oid *iname, size_t inamelen,
              const struct trap_object *trapobj, size_t trapobjlen,
              uint8_t sptrap)
+{
+       struct index_oid trap_index[1];
+
+       /* copy the single index into the multi-index format */
+       oid_copy(trap_index[0].indexname, iname, inamelen);
+       trap_index[0].indexlen = inamelen;
+
+       return (smux_trap_multi_index(
+               vp, vp_len, ename, enamelen, name, namelen, trap_index,
+               array_size(trap_index), trapobj, trapobjlen, sptrap));
+}
+
+int smux_trap_multi_index(struct variable *vp, size_t vp_len, const oid *ename,
+                         size_t enamelen, const oid *name, size_t namelen,
+                         struct index_oid *iname, size_t index_len,
+                         const struct trap_object *trapobj, size_t trapobjlen,
+                         uint8_t sptrap)
 {
        oid objid_snmptrap[] = {1, 3, 6, 1, 6, 3, 1, 1, 4, 1, 0};
        size_t objid_snmptrap_len = sizeof(objid_snmptrap) / sizeof(oid);
@@ -296,6 +313,13 @@ int smux_trap(struct variable *vp, size_t vp_len, const oid *ename,
                size_t val_len;
                WriteMethod *wm = NULL;
                struct variable cvp;
+               unsigned int iindex;
+               /*
+                * this allows the behaviour of smux_trap with a singe index
+                * for all objects to be maintained whilst allowing traps which
+                * have different indices per object to be supported
+                */
+               iindex = (index_len == 1) ? 0 : i;
 
                /* Make OID. */
                if (trapobj[i].namelen > 0) {
@@ -303,8 +327,10 @@ int smux_trap(struct variable *vp, size_t vp_len, const oid *ename,
                        onamelen = trapobj[i].namelen;
                        oid_copy(oid, name, namelen);
                        oid_copy(oid + namelen, trapobj[i].name, onamelen);
-                       oid_copy(oid + namelen + onamelen, iname, inamelen);
-                       oid_len = namelen + onamelen + inamelen;
+                       oid_copy(oid + namelen + onamelen,
+                                iname[iindex].indexname,
+                                iname[iindex].indexlen);
+                       oid_len = namelen + onamelen + iname[iindex].indexlen;
                } else {
                        /* Scalar object */
                        onamelen = trapobj[i].namelen * (-1);
@@ -330,6 +356,7 @@ int smux_trap(struct variable *vp, size_t vp_len, const oid *ename,
                        cvp.magic = vp[j].magic;
                        cvp.acl = vp[j].acl;
                        cvp.findVar = vp[j].findVar;
+
                        /* Grab the result. */
                        val = cvp.findVar(&cvp, oid, &oid_len, 1, &val_len,
                                          &wm);
index 78267ddb4a064ef55aedbd5471ea819472adbc60..ff97c8ab51329efe8e8ea31bb054e8f31e633da8 100644 (file)
@@ -79,6 +79,10 @@ struct trap_object {
        oid name[MAX_OID_LEN];
 };
 
+struct index_oid {
+       int indexlen;
+       oid indexname[MAX_OID_LEN];
+};
 /* Declare SMUX return value. */
 #define SNMP_LOCAL_VARIABLES                                                   \
        static long snmp_int_val __attribute__((unused));                      \
@@ -131,6 +135,12 @@ extern int smux_trap(struct variable *, size_t, const oid *, size_t,
                     const oid *, size_t, const oid *, size_t,
                     const struct trap_object *, size_t, uint8_t);
 
+extern int smux_trap_multi_index(struct variable *vp, size_t vp_len,
+                                const oid *ename, size_t enamelen,
+                                const oid *name, size_t namelen,
+                                struct index_oid *iname, size_t index_len,
+                                const struct trap_object *trapobj,
+                                size_t trapobjlen, uint8_t sptrap);
 extern int oid_compare(const oid *, int, const oid *, int);
 extern void oid2in_addr(oid[], int, struct in_addr *);
 extern void oid2int(oid oid[], int *dest);