diff options
| author | Pat Ruddy <pat@voltanet.io> | 2020-10-21 18:22:06 +0100 |
|---|---|---|
| committer | Pat Ruddy <pat@voltanet.io> | 2021-02-02 09:37:14 +0000 |
| commit | 4eb8c74f6cdddb310353b397edcda466b2a7e210 (patch) | |
| tree | 3d9e62d5b414e2abd1cb9fa96e9c145b27db82b6 /lib/agentx.c | |
| parent | 98a9144fb427ad234dae0a62f57be9e1da51729f (diff) | |
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/agentx.c')
| -rw-r--r-- | lib/agentx.c | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/lib/agentx.c b/lib/agentx.c index 603d8d6172..cf3814bc18 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); |
