Skip to content

Commit

Permalink
keepalived: Generate the proper route for the interface IP configured…
Browse files Browse the repository at this point in the history
… 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>/32 via 0.0.0.0 src <dpvs-wan-ip> dev eth1 mtu 1500 tos 0 scope link metric 0 proto auto
...
  • Loading branch information
zhuangyan committed Jul 17, 2020
1 parent 2e64fd2 commit fa53421
Showing 1 changed file with 36 additions and 15 deletions.
51 changes: 36 additions & 15 deletions tools/keepalived/keepalived/vrrp/vrrp_ipaddress.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,41 +72,59 @@ ipaddresstos(char *buf, const ip_address_t *ipaddress)
}

/* Add/Delete IP address to a specific interface_t */
static void
static bool
dpvs_fill_addrconf(int is_add, uint32_t flags, ip_address_t *ipaddress,
char *dpdk_port, struct inet_addr_param *param)
{
if (ipaddress->ifp) {
strncpy(param->ifa_entry.ifname, ipaddress->ifp->ifname, IFNAMSIZ);
} else if (dpdk_port) {
strncpy(param->ifa_entry.ifname, dpdk_port, IFNAMSIZ);
} else {
return false;
}

if (is_add)
param->ifa_ops = INET_ADDR_ADD;
else
param->ifa_ops = INET_ADDR_DEL;

param->ifa_ops_flags = 0;
param->ifa_entry.af = ipaddress->ifa.ifa_family;
if (dpdk_port) {
strcpy(param->ifa_entry.ifname, dpdk_port);
} else {
strcpy(param->ifa_entry.ifname, IF_NAME(if_get_by_ifindex(ipaddress->ifa.ifa_index)));
}

if (param->ifa_entry.af == AF_INET)
param->ifa_entry.addr.in = ipaddress->u.sin.sin_addr;
else
param->ifa_entry.addr.in6 = ipaddress->u.sin6_addr;

param->ifa_entry.plen = ipaddress->ifa.ifa_prefixlen;
param->ifa_entry.flags &= ~IFA_F_SAPOOL;

return true;
}

int
netlink_ipaddress(ip_address_t* ipaddress, char *dpdk_port, int cmd)
{
int err;
struct inet_addr_param param;

if (dpdk_port == NULL)
return 1;

memset(&param, 0, sizeof(param));
dpvs_fill_addrconf(cmd == IPADDRESS_DEL ? 0 : 1, 0,
ipaddress, dpdk_port, &param);
ipvs_set_ipaddr(&param, cmd);

if (dpvs_fill_addrconf((cmd == IPADDRESS_ADD) ? 1 : 0,
0, ipaddress, dpdk_port, &param) == false) {
return -1;
}

err = ipvs_set_ipaddr(&param, cmd);
if (err) {
log_message(LOG_INFO, "%s: failed to \"%s %s dev %s\"",
__func__,
(cmd == IPADDRESS_ADD) ? "add" : "del",
ipaddresstos(NULL, ipaddress),
param.ifa_entry.ifname);
return -1;
}

return 1;
}
Expand Down Expand Up @@ -548,9 +566,10 @@ address_exist(vrrp_t *vrrp, ip_address_t *ipaddress, char *old_dpdk_port, char *
if (!ipaddress)
return true;


LIST_FOREACH(vrrp->vip, ipaddr, e) {
if (IP_ISEQ(ipaddr, ipaddress) && !strcmp(old_dpdk_port, new_dpdk_port)) {
if (IP_ISEQ(ipaddr, ipaddress) &&
old_dpdk_port && new_dpdk_port &&
!strcmp(old_dpdk_port, new_dpdk_port)) {
ipaddr->set = ipaddress->set;
#ifdef _WITH_IPTABLES_
ipaddr->iptable_rule_set = ipaddress->iptable_rule_set;
Expand All @@ -564,7 +583,9 @@ address_exist(vrrp_t *vrrp, ip_address_t *ipaddress, char *old_dpdk_port, char *
}

LIST_FOREACH(vrrp->evip, ipaddr, e) {
if (IP_ISEQ(ipaddr, ipaddress) && !strcmp(old_dpdk_port, new_dpdk_port)) {
if (IP_ISEQ(ipaddr, ipaddress) &&
old_dpdk_port && new_dpdk_port &&
!strcmp(old_dpdk_port, new_dpdk_port)) {
ipaddr->set = ipaddress->set;
#ifdef _WITH_IPTABLES_
ipaddr->iptable_rule_set = ipaddress->iptable_rule_set;
Expand Down

0 comments on commit fa53421

Please sign in to comment.