MINOR: sample: Add ipv6 to ipv4 and sint to ipv6 casts

The RFC4291 says that when the IPv6 adress have the followin form:
0000::ffff:a.b.c.d, if can be converted to an IPv4 adress. This patch
enable this conversion in casts.

As the sint can be casted as ipv4, and ipv4 can be casted as ipv6, we
can directly cast sint as ipv6 using the RFC4291.
This commit is contained in:
Thierry FOURNIER 2015-07-24 09:04:56 +02:00 committed by Willy Tarreau
parent fd7edd3968
commit cc4d1716a2

View File

@ -526,6 +526,14 @@ static int c_ip2ipv6(struct sample *smp)
return 1;
}
static int c_ipv62ip(struct sample *smp)
{
if (!v6tov4(&smp->data.ipv4, &smp->data.ipv6))
return 0;
smp->type = SMP_T_IPV6;
return 1;
}
static int c_ipv62str(struct sample *smp)
{
struct chunk *trash = get_trash_chunk();
@ -554,6 +562,14 @@ static int c_int2ip(struct sample *smp)
return 1;
}
static int c_int2ipv6(struct sample *smp)
{
smp->data.ipv4.s_addr = htonl((unsigned int)smp->data.sint);
v4tov6(&smp->data.ipv6, &smp->data.ipv4);
smp->type = SMP_T_IPV6;
return 1;
}
static int c_str2addr(struct sample *smp)
{
if (!buf2ip(smp->data.str.str, smp->data.str.len, &smp->data.ipv4)) {
@ -768,10 +784,10 @@ sample_cast_fct sample_casts[SMP_TYPES][SMP_TYPES] = {
/* to: ANY BOOL SINT ADDR IPV4 IPV6 STR BIN METH */
/* from: ANY */ { c_none, c_none, c_none, c_none, c_none, c_none, c_none, c_none, c_none, },
/* BOOL */ { c_none, c_none, c_none, NULL, NULL, NULL, c_int2str, NULL, NULL, },
/* SINT */ { c_none, c_none, c_none, c_int2ip, c_int2ip, NULL, c_int2str, c_int2bin, NULL, },
/* SINT */ { c_none, c_none, c_none, c_int2ip, c_int2ip, c_int2ipv6, c_int2str, c_int2bin, NULL, },
/* ADDR */ { c_none, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, },
/* IPV4 */ { c_none, NULL, c_ip2int, c_none, c_none, c_ip2ipv6, c_ip2str, c_addr2bin, NULL, },
/* IPV6 */ { c_none, NULL, NULL, c_none, NULL, c_none, c_ipv62str, c_addr2bin, NULL, },
/* IPV6 */ { c_none, NULL, NULL, c_none, c_ipv62ip,c_none, c_ipv62str, c_addr2bin, NULL, },
/* STR */ { c_none, c_str2int, c_str2int, c_str2addr, c_str2ip, c_str2ipv6, c_none, c_none, c_str2meth, },
/* BIN */ { c_none, NULL, NULL, NULL, NULL, NULL, c_bin2str, c_none, c_str2meth, },
/* METH */ { c_none, NULL, NULL, NULL, NULL, NULL, c_meth2str, c_meth2str, c_none, }