Skip to content

Commit 158f376

Browse files
author
zhuangyan
committed
keepalived: Generate the proper route for the interface IP configured within
static_ipaddress{}. - With this patch, we can get the below two expected result with the below configuration example. static_ipaddress { dpvs-wan-ip/30 dev eth1 } a) "dpvs-wan-ip" related route is generated. inet dpvs-wan-ip/30 scope global eth1 valid_lft forever preferred_lft forever ... b) "dpvs-wan-ip" is configured on the related interface for arp request. inet dpvs-wan-network-ip/30 via 0.0.0.0 src dpvs-wan-ip dev eth1 mtu 1500 tos 0 scope link metric 0 proto auto ...
1 parent 2e64fd2 commit 158f376

File tree

1 file changed

+36
-15
lines changed

1 file changed

+36
-15
lines changed

tools/keepalived/keepalived/vrrp/vrrp_ipaddress.c

+36-15
Original file line numberDiff line numberDiff line change
@@ -72,41 +72,59 @@ ipaddresstos(char *buf, const ip_address_t *ipaddress)
7272
}
7373

7474
/* Add/Delete IP address to a specific interface_t */
75-
static void
75+
static bool
7676
dpvs_fill_addrconf(int is_add, uint32_t flags, ip_address_t *ipaddress,
7777
char *dpdk_port, struct inet_addr_param *param)
7878
{
79+
if (ipaddress->ifp) {
80+
strncpy(param->ifa_entry.ifname, ipaddress->ifp->ifname, IFNAMSIZ);
81+
} else if (dpdk_port) {
82+
strncpy(param->ifa_entry.ifname, dpdk_port, IFNAMSIZ);
83+
} else {
84+
return false;
85+
}
86+
7987
if (is_add)
8088
param->ifa_ops = INET_ADDR_ADD;
8189
else
8290
param->ifa_ops = INET_ADDR_DEL;
91+
8392
param->ifa_ops_flags = 0;
8493
param->ifa_entry.af = ipaddress->ifa.ifa_family;
85-
if (dpdk_port) {
86-
strcpy(param->ifa_entry.ifname, dpdk_port);
87-
} else {
88-
strcpy(param->ifa_entry.ifname, IF_NAME(if_get_by_ifindex(ipaddress->ifa.ifa_index)));
89-
}
94+
9095
if (param->ifa_entry.af == AF_INET)
9196
param->ifa_entry.addr.in = ipaddress->u.sin.sin_addr;
9297
else
9398
param->ifa_entry.addr.in6 = ipaddress->u.sin6_addr;
99+
94100
param->ifa_entry.plen = ipaddress->ifa.ifa_prefixlen;
95101
param->ifa_entry.flags &= ~IFA_F_SAPOOL;
102+
103+
return true;
96104
}
97105

98106
int
99107
netlink_ipaddress(ip_address_t* ipaddress, char *dpdk_port, int cmd)
100108
{
109+
int err;
101110
struct inet_addr_param param;
102111

103-
if (dpdk_port == NULL)
104-
return 1;
105-
106112
memset(&param, 0, sizeof(param));
107-
dpvs_fill_addrconf(cmd == IPADDRESS_DEL ? 0 : 1, 0,
108-
ipaddress, dpdk_port, &param);
109-
ipvs_set_ipaddr(&param, cmd);
113+
114+
if (dpvs_fill_addrconf((cmd == IPADDRESS_ADD) ? 1 : 0,
115+
0, ipaddress, dpdk_port, &param) == false) {
116+
return -1;
117+
}
118+
119+
err = ipvs_set_ipaddr(&param, cmd);
120+
if (err) {
121+
log_message(LOG_INFO, "%s: failed to \"%s %s dev %s\"",
122+
__func__,
123+
(cmd == IPADDRESS_ADD) ? "add" : "del",
124+
ipaddresstos(NULL, ipaddress),
125+
param.ifa_entry.ifname);
126+
return -1;
127+
}
110128

111129
return 1;
112130
}
@@ -548,9 +566,10 @@ address_exist(vrrp_t *vrrp, ip_address_t *ipaddress, char *old_dpdk_port, char *
548566
if (!ipaddress)
549567
return true;
550568

551-
552569
LIST_FOREACH(vrrp->vip, ipaddr, e) {
553-
if (IP_ISEQ(ipaddr, ipaddress) && !strcmp(old_dpdk_port, new_dpdk_port)) {
570+
if (IP_ISEQ(ipaddr, ipaddress) &&
571+
old_dpdk_port && new_dpdk_port &&
572+
!strcmp(old_dpdk_port, new_dpdk_port)) {
554573
ipaddr->set = ipaddress->set;
555574
#ifdef _WITH_IPTABLES_
556575
ipaddr->iptable_rule_set = ipaddress->iptable_rule_set;
@@ -564,7 +583,9 @@ address_exist(vrrp_t *vrrp, ip_address_t *ipaddress, char *old_dpdk_port, char *
564583
}
565584

566585
LIST_FOREACH(vrrp->evip, ipaddr, e) {
567-
if (IP_ISEQ(ipaddr, ipaddress) && !strcmp(old_dpdk_port, new_dpdk_port)) {
586+
if (IP_ISEQ(ipaddr, ipaddress) &&
587+
old_dpdk_port && new_dpdk_port &&
588+
!strcmp(old_dpdk_port, new_dpdk_port)) {
568589
ipaddr->set = ipaddress->set;
569590
#ifdef _WITH_IPTABLES_
570591
ipaddr->iptable_rule_set = ipaddress->iptable_rule_set;

0 commit comments

Comments
 (0)