Skip to content

Commit

Permalink
ipvs: set var_len = 0 when returning an error to SNMP
Browse files Browse the repository at this point in the history
The net-snmp code does this in header_simple_table(), so we should
do so when using a non-simple table.

Signed-off-by: Quentin Armitage <quentin@armitage.org.uk>
  • Loading branch information
pqarmitage committed Apr 28, 2024
1 parent 35195dc commit 2e165df
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions keepalived/core/snmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,15 @@ snmp_header_list_head_table(struct variable *vp, oid *name, size_t *length,
if (header_simple_table(vp, name, length, exact, var_len, write_method, -1) != MATCH_SUCCEEDED)
return NULL;

if (list_empty(l))
/* header_simple_table sets *var_len = 0 on error. On success it sets
*var_len = sizeof(long), and *write_method = NULL.
If we reach here, the success values will have been written. */

if (list_empty(l)) {
if (var_len)
*var_len = 0;
return NULL;
}

target = name[*length - 1];

Expand All @@ -85,16 +92,22 @@ snmp_header_list_head_table(struct variable *vp, oid *name, size_t *length,
if (current == target)
/* Exact match */
return e;
if (exact)
if (exact) {
/* No exact match found */
if (var_len)
*var_len = 0;
return NULL;
}
/* current is the best match */
name[*length - 1] = current;
return e;
}

/* There are insufficent entries in the list or no match
* at the end then just return no match */
if (var_len)
*var_len = 0;

return NULL;
}

Expand Down

0 comments on commit 2e165df

Please sign in to comment.