Skip to content

Commit df377c0

Browse files
authored
Merge pull request #2580 from pqarmitage/updates
Handle updated vrrp_delayed_start and return (none) from inet_sockaddrtos() if address unspecified
2 parents 6049a4e + 447a7a6 commit df377c0

File tree

6 files changed

+75
-54
lines changed

6 files changed

+75
-54
lines changed

Makefile.am

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ dist-hook:
6565
if [ -n "`git status --porcelain $$f`" ]; then continue; fi; \
6666
if [ ! -f $(top_distdir)/$$f ]; then continue; fi; \
6767
touch --date=@`git log -n 1 --format=%ct -- $$f` $(top_distdir)/$$f; \
68-
done \
68+
done; \
69+
cd lib; \
70+
make git-commit.h; \
71+
cd ..; \
6972
fi \
7073
fi
7174
@rm -f $(distdir)/README

keepalived/core/keepalived_netlink.c

Lines changed: 36 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,14 @@ netlink_if_address_filter(__attribute__((unused)) struct sockaddr_nl *snl, struc
922922
if (tb[IFA_ADDRESS] == NULL)
923923
tb[IFA_ADDRESS] = tb[IFA_LOCAL];
924924

925+
/* Ignore tentative addresses - we can't do anything with them */
926+
#if HAVE_DECL_IFA_FLAGS
927+
if ((tb[IFA_FLAGS] ? *(uint32_t *)RTA_DATA(tb[IFA_FLAGS]) : ifa->ifa_flags) & IFA_F_TENTATIVE)
928+
#else
929+
if (ifa->ifa_flags & IFA_F_TENTATIVE)
930+
#endif
931+
return 0;
932+
925933
/* local interface address */
926934
addr.addr = (tb[IFA_LOCAL] ? RTA_DATA(tb[IFA_LOCAL]) : NULL);
927935

@@ -1005,52 +1013,39 @@ netlink_if_address_filter(__attribute__((unused)) struct sockaddr_nl *snl, struc
10051013
else
10061014
is_tracking_saddr = false;
10071015

1008-
if (ifp == (
1009-
#ifdef _HAVE_VRRP_VMAC_
1010-
vrrp->family == AF_INET ? VRRP_CONFIGURED_IFP(vrrp) :
1011-
#endif
1012-
vrrp->ifp) &&
1013-
vrrp->flags_if_fault &&
1014-
vrrp->family == ifa->ifa_family &&
1016+
if (vrrp->family == ifa->ifa_family &&
10151017
vrrp->saddr.ss_family == AF_UNSPEC &&
1016-
(!__test_bit(VRRP_FLAG_SADDR_FROM_CONFIG, &vrrp->flags) || is_tracking_saddr)) {
1017-
/* Copy the address */
1018-
if (ifa->ifa_family == AF_INET)
1019-
inet_ip4tosockaddr(addr.in, &vrrp->saddr);
1020-
else
1021-
inet_ip6tosockaddr(addr.in6, &vrrp->saddr);
1022-
try_up_instance(vrrp, false, VRRP_FAULT_FL_NO_SOURCE_IP);
1023-
}
1018+
__test_bit(VRRP_FAULT_FL_NO_SOURCE_IP, &vrrp->flags_if_fault) &&
1019+
vrrp->ifp) {
1020+
if (ifp == (
1021+
#ifdef _HAVE_VRRP_VMAC_
1022+
vrrp->family == AF_INET ? VRRP_CONFIGURED_IFP(vrrp) :
1023+
#endif
1024+
vrrp->ifp) &&
1025+
(!__test_bit(VRRP_FLAG_SADDR_FROM_CONFIG, &vrrp->flags) || is_tracking_saddr)) {
1026+
/* Copy the address */
1027+
if (ifa->ifa_family == AF_INET)
1028+
inet_ip4tosockaddr(addr.in, &vrrp->saddr);
1029+
else
1030+
inet_ip6tosockaddr(addr.in6, &vrrp->saddr);
1031+
try_up_instance(vrrp, false, VRRP_FAULT_FL_NO_SOURCE_IP);
1032+
}
10241033
#ifdef _HAVE_VRRP_VMAC_
1025-
/* If IPv6 link local and vmac doesn't have an address or we have
1026-
* created one ourselves, add/replace the new address on the vmac */
1027-
else if (vrrp->family == AF_INET6 &&
1028-
vrrp->ifp &&
1029-
ifp == vrrp->ifp->base_ifp &&
1030-
IS_MAC_IP_VLAN(vrrp->ifp) &&
1031-
!__test_bit(VRRP_VMAC_XMITBASE_BIT, &vrrp->flags) &&
1032-
ifa->ifa_family == AF_INET6 &&
1033-
vrrp->ifp->is_ours) {
1034-
if (vrrp->saddr.ss_family == AF_UNSPEC) {
1035-
inet_ip6tosockaddr(addr.in6, &vrrp->saddr);
1036-
#if 0
1037-
if (IN6_IS_ADDR_UNSPECIFIED(&vrrp->ifp->sin6_addr)) {
1038-
/* This should never happen with the current code since we always
1039-
* create a link local address on the VMAC interface.
1040-
* However, if in future it is decided not to automatically create
1041-
* a link local address on the VMAC interface if the parent interface
1042-
* does not have one, then we will need the following code
1043-
*/
1044-
if (add_link_local_address(vrrp->ifp, addr.in6) &&
1045-
vrrp->flags_if_fault &&
1046-
(!__test_bit(VRRP_FLAG_SADDR_FROM_CONFIG, &vrrp->flags) || is_tracking_saddr))
1034+
/* If IPv6 link local and vmac doesn't have an address or we have
1035+
* created one ourselves, add/replace the new address on the vmac */
1036+
else if (vrrp->family == AF_INET6 &&
1037+
IS_MAC_IP_VLAN(vrrp->ifp) &&
1038+
vrrp->ifp->is_ours &&
1039+
ifp == vrrp->ifp->base_ifp &&
1040+
!__test_bit(VRRP_VMAC_XMITBASE_BIT, &vrrp->flags)) {
1041+
inet_ip6tosockaddr(addr.in6, &vrrp->saddr);
1042+
if (!__test_bit(VRRP_FLAG_SADDR_FROM_CONFIG, &vrrp->flags) || is_tracking_saddr)
10471043
try_up_instance(vrrp, false, VRRP_FAULT_FL_NO_SOURCE_IP);
1048-
} else
1049-
#endif
1050-
reset_link_local_address(&vrrp->ifp->sin6_addr, vrrp);
1044+
else
1045+
reset_link_local_address(&vrrp->ifp->sin6_addr, vrrp);
10511046
}
1052-
}
10531047
#endif
1048+
}
10541049
}
10551050
}
10561051
}

keepalived/vrrp/vrrp.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2053,9 +2053,13 @@ vrrp_state_backup(vrrp_t *vrrp, const vrrphdr_t *hd, const char *buf, ssize_t bu
20532053
vrrp->rlflags = 0 ;
20542054

20552055
if (__test_bit(LOG_DETAIL_BIT, &debug)) {
2056-
char old_master[INET6_ADDRSTRLEN];
2057-
strcpy(old_master, inet_sockaddrtos(&vrrp->master_saddr));
2058-
log_message(LOG_INFO, "(%s) master changed from %s to %s", vrrp->iname, old_master, inet_sockaddrtos(&vrrp->pkt_saddr));
2056+
if (vrrp->master_saddr.ss_family == AF_UNSPEC)
2057+
log_message(LOG_INFO, "(%s) master set to %s", vrrp->iname, inet_sockaddrtos(&vrrp->pkt_saddr));
2058+
else {
2059+
char old_master[INET6_ADDRSTRLEN];
2060+
strcpy(old_master, inet_sockaddrtos(&vrrp->master_saddr));
2061+
log_message(LOG_INFO, "(%s) master changed from %s to %s", vrrp->iname, old_master, inet_sockaddrtos(&vrrp->pkt_saddr));
2062+
}
20592063
}
20602064
}
20612065

@@ -3867,7 +3871,8 @@ vrrp_complete_instance(vrrp_t * vrrp)
38673871
/* coverity[var_deref_model] - vrrp->configured_ifp is not NULL for VMAC */
38683872
netlink_link_add_vmac(vrrp, old_interface);
38693873
}
3870-
}
3874+
} else if (old_interface)
3875+
netlink_link_del_vmac(vrrp);
38713876

38723877
if (vrrp->ifp->base_ifp->ifindex &&
38733878
!__test_bit(VRRP_VMAC_UP_BIT, &vrrp->flags) &&
@@ -4825,7 +4830,7 @@ vrrp_complete_init(void)
48254830
#endif
48264831

48274832
#if defined _HAVE_LIBIPSET_
4828-
if (!global_data->vrrp_iptables_inchain && global_data->using_ipsets) {
4833+
if (!global_data->vrrp_iptables_inchain && global_data->using_ipsets == true) {
48294834
log_message(LOG_INFO, "vrrp_ipsets has been specified but not vrrp_iptables - vrrp_ipsets will be ignored");
48304835
disable_ipsets();
48314836
}

keepalived/vrrp/vrrp_daemon.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,8 @@ delayed_start_clear_thread(__attribute__((unused)) thread_ref_t thread)
506506
static void
507507
start_vrrp(data_t *prev_global_data)
508508
{
509+
unsigned delay_remaining;
510+
509511
/* Clear the flags used for optimising performance */
510512
clear_summary_flags();
511513

@@ -617,16 +619,18 @@ start_vrrp(data_t *prev_global_data)
617619
} else
618620
vrrp_delayed_start_time.tv_sec = 0;
619621
} else if (vrrp_delayed_start_time.tv_sec) {
622+
vrrp_delayed_start_time = timer_sub_long(vrrp_delayed_start_time, prev_global_data->vrrp_startup_delay);
623+
vrrp_delayed_start_time = timer_add_long(vrrp_delayed_start_time, global_data->vrrp_startup_delay);
620624
if (time_now.tv_sec > vrrp_delayed_start_time.tv_sec ||
621625
(time_now.tv_sec == vrrp_delayed_start_time.tv_sec &&
622-
time_now.tv_usec >= vrrp_delayed_start_time.tv_usec))
626+
time_now.tv_usec >= vrrp_delayed_start_time.tv_usec)) {
623627
vrrp_delayed_start_time.tv_sec = 0;
624-
else {
625-
unsigned delay_left;
626-
delay_left = (vrrp_delayed_start_time.tv_sec - time_now.tv_sec) * 1000000UL
628+
log_message(LOG_INFO, "Reduced delayed start passed");
629+
} else {
630+
delay_remaining = (vrrp_delayed_start_time.tv_sec - time_now.tv_sec) * 1000000UL
627631
+ vrrp_delayed_start_time.tv_usec - time_now.tv_usec;
628-
thread_add_timer(master, delayed_start_clear_thread, NULL, delay_left);
629-
log_message(LOG_INFO, "Delaying startup for a further %g seconds", delay_left / TIMER_HZ_DOUBLE);
632+
thread_add_timer(master, delayed_start_clear_thread, NULL, delay_remaining);
633+
log_message(LOG_INFO, "Delaying startup for a further %g seconds", delay_remaining / TIMER_HZ_DOUBLE);
630634
}
631635
}
632636

keepalived/vrrp/vrrp_if.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1598,7 +1598,16 @@ setup_interface(vrrp_t *vrrp)
15981598
}
15991599
}
16001600

1601-
return;
1601+
/* If we have created a VMAC for the vrrp instance, the VMAC has an address
1602+
* (IPv6 only) and the vrrp instance does not have an address, add the
1603+
* address to the vrrp instance and try to bring it up. */
1604+
if (vrrp->family == AF_INET6) {
1605+
if (IN6_IS_ADDR_UNSPECIFIED(&vrrp->saddr) &&
1606+
(__test_bit(VRRP_FAULT_FL_NO_SOURCE_IP, &vrrp->flags_if_fault))) {
1607+
inet_ip6tosockaddr(&vrrp->ifp->sin6_addr, &vrrp->saddr);
1608+
try_up_instance(vrrp, false, VRRP_FAULT_FL_NO_SOURCE_IP);
1609+
}
1610+
}
16021611
}
16031612

16041613
#ifdef _HAVE_VRRP_VMAC_

lib/utils.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,11 @@ inet_sockaddrtos2(const sockaddr_t *addr, char *addr_str)
696696
{
697697
const void *addr_ip;
698698

699+
if (addr->ss_family == AF_UNSPEC) {
700+
strcpy(addr_str, "(none)");
701+
return addr_str;
702+
}
703+
699704
if (addr->ss_family == AF_INET6) {
700705
const struct sockaddr_in6 *addr6 = PTR_CAST_CONST(struct sockaddr_in6, addr);
701706
addr_ip = &addr6->sin6_addr;

0 commit comments

Comments
 (0)