diff options
author | Pat Ruddy <pat@voltanet.io> | 2020-10-21 19:22:06 +0200 |
---|---|---|
committer | Pat Ruddy <pat@voltanet.io> | 2021-02-02 10:37:14 +0100 |
commit | 4eb8c74f6cdddb310353b397edcda466b2a7e210 (patch) | |
tree | 3d9e62d5b414e2abd1cb9fa96e9c145b27db82b6 /lib | |
parent | bgpd: implement mplsL3VpnVrfRtTable (diff) | |
download | frr-4eb8c74f6cdddb310353b397edcda466b2a7e210.tar.xz frr-4eb8c74f6cdddb310353b397edcda466b2a7e210.zip |
lib: allow traps with differently indexed objects
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>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/agentx.c | 31 | ||||
-rw-r--r-- | lib/smux.h | 10 |
2 files changed, 39 insertions, 2 deletions
diff --git a/lib/agentx.c b/lib/agentx.c index 603d8d617..cf3814bc1 100644 --- a/lib/agentx.c +++ b/lib/agentx.c @@ -268,6 +268,23 @@ int smux_trap(struct variable *vp, size_t vp_len, const oid *ename, 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); oid notification_oid[MAX_OID_LEN]; @@ -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); diff --git a/lib/smux.h b/lib/smux.h index 78267ddb4..ff97c8ab5 100644 --- a/lib/smux.h +++ b/lib/smux.h @@ -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); |