Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove requirement to specify interface for virtual route in order to track it #2429

Merged
merged 2 commits into from
Jun 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions keepalived/core/keepalived_netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,10 @@ compare_route(struct rtattr *tb[RTA_MAX + 1], ip_route_t *route, uint32_t table,
if (route->oif) {
if (!tb[RTA_OIF] || route->oif->ifindex != *PTR_CAST(uint32_t, RTA_DATA(tb[RTA_OIF])))
return false;
} else {
if (route->set && route->configured_ifindex &&
(!tb[RTA_OIF] || route->configured_ifindex != *PTR_CAST(uint32_t, RTA_DATA(tb[RTA_OIF]))))
} else if (route->set) {
if (!tb[RTA_OIF] != !route->configured_ifindex)
return false;
if (tb[RTA_OIF] && route->configured_ifindex != *PTR_CAST(uint32_t, RTA_DATA(tb[RTA_OIF])))
return false;
}

Expand Down Expand Up @@ -2360,9 +2361,8 @@ netlink_route_filter(__attribute__((unused)) struct sockaddr_nl *snl, struct nlm
route->configured_ifindex = *PTR_CAST(uint32_t, RTA_DATA(tb[RTA_OIF]));
if (route->oif && route->oif->ifindex != route->configured_ifindex)
log_message(LOG_INFO, "route added index %" PRIu32 " != config index %u", route->configured_ifindex, route->oif->ifindex);
}
else
log_message(LOG_INFO, "New route doesn't have i/f index");
} else
route->configured_ifindex = 0;

return 0;
}
Expand Down
8 changes: 4 additions & 4 deletions keepalived/include/vrrp_iproute.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ enum ip_route {
IPROUTE_PREF,
IPROUTE_FASTOPEN_NO_COOKIE,
IPROUTE_TTL_PROPAGATE,
IPROUTE_ADD,
IPROUTE_APPEND
IPROUTE_ADD_ROUTE,
IPROUTE_APPEND_ROUTE
};

#define IPROUTE_BIT_DSFIELD (1<<IPROUTE_DSFIELD)
Expand All @@ -181,8 +181,8 @@ enum ip_route {
#define IPROUTE_BIT_PREF (1<<IPROUTE_PREF)
#define IPROUTE_BIT_FASTOPEN_NO_COOKIE (1<<IPROUTE_FASTOPEN_NO_COOKIE)
#define IPROUTE_BIT_TTL_PROPAGATE (1<<IPROUTE_TTL_PROPAGATE)
#define IPROUTE_BIT_ADD (1<<IPROUTE_ADD)
#define IPROUTE_BIT_APPEND (1<<IPROUTE_APPEND)
#define IPROUTE_BIT_ADD (1<<IPROUTE_ADD_ROUTE)
#define IPROUTE_BIT_APPEND (1<<IPROUTE_APPEND_ROUTE)

typedef struct _ip_route {
ip_address_t *dst;
Expand Down
2 changes: 1 addition & 1 deletion keepalived/vrrp/vrrp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1764,7 +1764,7 @@ vrrp_restore_interface(vrrp_t * vrrp, bool advF, bool force)

/* remove virtual routes */
if (!list_empty(&vrrp->vroutes))
vrrp_handle_iproutes(vrrp, IPROUTE_DEL, false);
vrrp_handle_iproutes(vrrp, IPROUTE_DEL, force);

/* empty the delayed arp list */
vrrp_remove_delayed_arp(vrrp);
Expand Down
22 changes: 4 additions & 18 deletions keepalived/vrrp/vrrp_iproute.c
Original file line number Diff line number Diff line change
Expand Up @@ -531,9 +531,10 @@ netlink_rtlist(list_head_t *rt_list, int cmd, bool force)

list_for_each_entry(ip_route, rt_list, e_list) {
if ((cmd == IPROUTE_DEL) == ip_route->set || force) {
if (!netlink_route(ip_route, cmd))
ip_route->set = (cmd == IPROUTE_ADD);
else if (cmd != IPROUTE_ADD)
if (!netlink_route(ip_route, cmd)) {
if (cmd == IPROUTE_DEL)
ip_route->set = false;
} else if (cmd != IPROUTE_ADD)
ip_route->set = false;
}
}
Expand Down Expand Up @@ -1871,21 +1872,6 @@ alloc_route(list_head_t *rt_list, const vector_t *strvec, bool allow_track_group
report_config_error(CONFIG_GENERAL_ERROR, "Route cannot be tracked if protocol is not RTPROT_KEEPALIVED(%d), resetting protocol", RTPROT_KEEPALIVED);
new->protocol = RTPROT_KEEPALIVED;
new->mask |= IPROUTE_BIT_PROTOCOL;

if (!new->oif) {
/* Alternative is to track oif from when route last added.
* The interface will need to be added temporarily. tracking_obj_t will need
* a flag to specify permanent track, and a counter for number of temporary
* trackers. If the termporary tracker count becomes 0 and there is no permanent
* track, then the tracking_obj_t will need to be removed.
*
* We also have a problem if using nexthop, since the route will only be deleted
* when the interfaces for all of the hops have gone down. We would need to track
* all of the interfaces being used, and only mark the route as down if all the
* interfaces are down. */
report_config_error(CONFIG_GENERAL_ERROR, "Warning - cannot track route %s with no interface specified, not tracking", dest);
new->dont_track = true;
}
}

if (new->track_group && !new->oif) {
Expand Down
6 changes: 5 additions & 1 deletion keepalived/vrrp/vrrp_scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@
#ifdef _WITH_LVS_
#include "ipvswrapper.h"
#endif
#include "keepalived_netlink.h"


/* For load testing recvmsg() */
/* #define DEBUG_RECVMSG */
Expand Down Expand Up @@ -266,7 +268,9 @@ vrrp_init_state(list_head_t *l)
#endif

/* Set interface state */
vrrp_restore_interface(vrrp, false, false);
netlink_error_ignore = ESRCH; // returned if route does not exist
vrrp_restore_interface(vrrp, false, true);
netlink_error_ignore = 0;
if (is_up &&
new_state != VRRP_STATE_FAULT &&
!vrrp->num_script_init &&
Expand Down
Loading