Skip to content

Commit

Permalink
vrrp: General default value if rt_addrprotos does not include keepalived
Browse files Browse the repository at this point in the history
Signed-off-by: Quentin Armitage <[email protected]>
  • Loading branch information
pqarmitage committed Oct 28, 2024
1 parent 59dc632 commit a2328fe
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
5 changes: 2 additions & 3 deletions keepalived/vrrp/vrrp_ipaddress.c
Original file line number Diff line number Diff line change
Expand Up @@ -851,8 +851,7 @@ void
set_addrproto(void)
{
#if HAVE_DECL_IFA_PROTO
find_rttables_addrproto("keepalived", &address_protocol);
if (!address_protocol)
address_protocol = RTPROT_KEEPALIVED;
if (!find_rttables_addrproto("keepalived", &address_protocol))
create_rttables_addrproto("keepalived", &address_protocol);
#endif
}
43 changes: 43 additions & 0 deletions lib/rttables.c
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,49 @@ get_rttables_scope(uint32_t id)
}

#if HAVE_DECL_IFA_PROTO
static const char *
get_rttables_addrproto(uint32_t id)
{
return get_entry(id, &rt_scopes, RT_ADDRPROTOS_FILE, rtscope_default, 255);
}

bool
create_rttables_addrproto(const char *name, uint8_t *id)
{
unsigned val;
rt_entry_t *rte;

/* We need to find a free value - try RTPROT_KEEPALIVED first */
val = RTPROT_KEEPALIVED;
if (!get_rttables_addrproto(val)) {
for (val = 0; val <= 255; val++) {
if (get_rttables_addrproto(val))
break;
}
}

if (val > 255)
return false;

*id = val & 0xff;

/* Add the entry so other configuration can use it */
PMALLOC(rte);
if (!rte)
return false;

rte->id = val;
rte->name = STRDUP(name);
if (!rte->name) {
FREE(rte);
return false;
}

list_add_tail(&rte->e_list, &rt_addrprotos);

return true;
}

bool
find_rttables_addrproto(const char *name, uint8_t *id)
{
Expand Down
1 change: 1 addition & 0 deletions lib/rttables.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ extern bool find_rttables_group(const char *, uint32_t *);
#endif
extern bool find_rttables_proto(const char *, uint8_t *);
#if HAVE_DECL_IFA_PROTO
extern bool create_rttables_addrproto(const char *, uint8_t *);
extern bool find_rttables_addrproto(const char *, uint8_t *);
#endif
extern bool find_rttables_rtntype(const char *, uint8_t *);
Expand Down

0 comments on commit a2328fe

Please sign in to comment.