Skip to content

Commit

Permalink
keepalived/ipvsadm support NAT64
Browse files Browse the repository at this point in the history
  • Loading branch information
mscbg committed Nov 22, 2018
1 parent 6498d3e commit 3639367
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 13 deletions.
3 changes: 2 additions & 1 deletion include/conf/laddr.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ struct dp_vs_laddr_entry {

struct dp_vs_laddr_conf {
/* identify service */
int af;
int af_s;
uint8_t proto;
union inet_addr vaddr;
uint16_t vport;
Expand All @@ -54,6 +54,7 @@ struct dp_vs_laddr_conf {
char oifname[IFNAMSIZ];

/* for set */
int af_l;
union inet_addr laddr;
char ifname[IFNAMSIZ];

Expand Down
2 changes: 1 addition & 1 deletion src/ipvs/ip_vs_dest.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ int dp_vs_new_dest(struct dp_vs_service *svc,
}
assert(dest->svc == NULL);

dest->af = svc->af;
dest->af = udest->af;
dest->proto = svc->proto;
dest->vaddr = svc->addr;
dest->vport = svc->port;
Expand Down
8 changes: 4 additions & 4 deletions src/ipvs/ip_vs_laddr.c
Original file line number Diff line number Diff line change
Expand Up @@ -463,19 +463,19 @@ static int laddr_sockopt_set(sockoptid_t opt, const void *conf, size_t size)
&match) != EDPVS_OK)
return EDPVS_INVAL;

svc = dp_vs_service_lookup(laddr_conf->af, laddr_conf->proto,
svc = dp_vs_service_lookup(laddr_conf->af_s, laddr_conf->proto,
&laddr_conf->vaddr, laddr_conf->vport,
laddr_conf->fwmark, NULL, &match);
if (!svc)
return EDPVS_NOSERV;

switch (opt) {
case SOCKOPT_SET_LADDR_ADD:
err = dp_vs_laddr_add(svc, laddr_conf->af, &laddr_conf->laddr,
err = dp_vs_laddr_add(svc, laddr_conf->af_l, &laddr_conf->laddr,
laddr_conf->ifname);
break;
case SOCKOPT_SET_LADDR_DEL:
err = dp_vs_laddr_del(svc, laddr_conf->af, &laddr_conf->laddr);
err = dp_vs_laddr_del(svc, laddr_conf->af_l, &laddr_conf->laddr);
break;
case SOCKOPT_SET_LADDR_FLUSH:
err = dp_vs_laddr_flush(svc);
Expand Down Expand Up @@ -509,7 +509,7 @@ static int laddr_sockopt_get(sockoptid_t opt, const void *conf, size_t size,
return EDPVS_INVAL;


svc = dp_vs_service_lookup(laddr_conf->af, laddr_conf->proto,
svc = dp_vs_service_lookup(laddr_conf->af_s, laddr_conf->proto,
&laddr_conf->vaddr, laddr_conf->vport,
laddr_conf->fwmark, NULL, &match);
if (!svc)
Expand Down
2 changes: 1 addition & 1 deletion tools/ipvsadm/ipvsadm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1883,7 +1883,7 @@ print_service_entry(ipvs_service_entry_t *se, unsigned int format)
char *dname;
ipvs_dest_entry_t *e = &d->entrytable[i];

if (!(dname = addrport_to_anyname(se->af, &(e->addr), ntohs(e->port),
if (!(dname = addrport_to_anyname(e->af, &(e->addr), ntohs(e->port),
se->protocol, format))) {
fprintf(stderr, "addrport_to_anyname fails\n");
exit(1);
Expand Down
13 changes: 7 additions & 6 deletions tools/keepalived/keepalived/libipvs-2.6/libipvs.c
Original file line number Diff line number Diff line change
Expand Up @@ -321,10 +321,11 @@ static void ipvs_fill_laddr_conf(ipvs_service_t *svc, ipvs_laddr_t *laddr,
struct dp_vs_laddr_conf *conf)
{
memset(conf, 0, sizeof(*conf));
conf->af = laddr->af;
conf->af_s = svc->af;
conf->proto = svc->protocol;
conf->vport = svc->port;
conf->fwmark = svc->fwmark;
conf->af_l = laddr->af;
if (strlen(laddr->ifname))
snprintf(conf->ifname, sizeof(conf->ifname), "%s", laddr->ifname);

Expand Down Expand Up @@ -615,7 +616,7 @@ struct ip_vs_get_laddrs *ipvs_get_laddrs(ipvs_service_entry_t *svc)
size_t res_size, i;

memset(&conf, 0, sizeof(struct dp_vs_laddr_conf));
conf.af = svc->af;
conf.af_s = svc->af;
conf.proto = svc->protocol;
if (svc->af == AF_INET)
conf.vaddr.in = svc->addr.in;
Expand Down Expand Up @@ -644,8 +645,8 @@ struct ip_vs_get_laddrs *ipvs_get_laddrs(ipvs_service_entry_t *svc)
laddrs->port = result->vport;
laddrs->fwmark = result->fwmark;
laddrs->num_laddrs = result->nladdrs;
laddrs->af = result->af;
if (result->af == AF_INET)
laddrs->af = result->af_s;
if (result->af_s == AF_INET)
laddrs->addr.in = result->vaddr.in;
else
laddrs->addr.in6 = result->vaddr.in6;
Expand All @@ -654,8 +655,8 @@ struct ip_vs_get_laddrs *ipvs_get_laddrs(ipvs_service_entry_t *svc)
laddrs->entrytable[i].__addr_v4 = result->laddrs[i].addr.in.s_addr;
laddrs->entrytable[i].port_conflict = result->laddrs[i].nport_conflict;
laddrs->entrytable[i].conn_counts = result->laddrs[i].nconns;
laddrs->entrytable[i].af = result->af;
if (result->af == AF_INET)
laddrs->entrytable[i].af = result->laddrs[i].af;
if (result->laddrs[i].af == AF_INET)
laddrs->entrytable[i].addr.in = result->laddrs[i].addr.in;
else
laddrs->entrytable[i].addr.in6 = result->laddrs[i].addr.in6;
Expand Down

0 comments on commit 3639367

Please sign in to comment.