Commit b3b753fb authored by Tollef Fog Heen's avatar Tollef Fog Heen

Merge r5119: Always report sockaddr's as IP# <space> PORT#

Explain why.



git-svn-id: http://www.varnish-cache.org/svn/branches/2.1@5329 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent e204a8c3
......@@ -215,7 +215,7 @@ pan_sess(const struct sess *sp)
vsb_printf(vsp, "sp = %p {\n", sp);
vsb_printf(vsp,
" fd = %d, id = %d, xid = %u,\n", sp->fd, sp->id, sp->xid);
vsb_printf(vsp, " client = %s:%s,\n",
vsb_printf(vsp, " client = %s %s,\n",
sp->addr ? sp->addr : "?.?.?.?",
sp->port ? sp->port : "?");
switch (sp->step) {
......
......@@ -789,6 +789,10 @@ VRT_r_server_hostname(struct sess *sp)
return (vrt_hostname);
}
/*--------------------------------------------------------------------
* XXX: This is pessimistically silly
*/
int
VRT_r_server_port(struct sess *sp)
{
......
......@@ -443,7 +443,7 @@ sock_id(const char *pfx, int fd)
AN(vsb);
TCP_myname(fd, abuf1, sizeof abuf1, pbuf1, sizeof pbuf1);
TCP_hisname(fd, abuf2, sizeof abuf2, pbuf2, sizeof pbuf2);
vsb_printf(vsb, "%s %s:%s %s:%s", pfx, abuf2, pbuf2, abuf1, pbuf1);
vsb_printf(vsb, "%s %s %s %s %s", pfx, abuf2, pbuf2, abuf1, pbuf1);
vsb_finish(vsb);
AZ(vsb_overflowed(vsb));
return (vsb);
......
......@@ -25,7 +25,7 @@ varnish v1 -storage "-smalloc,1m" -vcl+backend {
varnish v1 -cliok "param.set diag_bitmap 0x00001000"
# Force the (random) port selected to be used again after restart.
varnish v1 -cliok "param.set listen_address ${v1_sock}"
varnish v1 -cliok "param.set listen_address ${v1_addr}:${v1_port}"
# varnishtest defaults to auto_restart off, to avoid masking bugs.
varnish v1 -cliok "param.set auto_restart on"
......
......@@ -94,7 +94,7 @@ server_thread(void *priv)
vl = vtc_logopen(s->name);
vtc_log(vl, 2, "Started on %s:%s", s->aaddr, s->aport);
vtc_log(vl, 2, "Started on %s %s", s->aaddr, s->aport);
for (i = 0; i < s->repeat; i++) {
if (s->repeat > 1)
vtc_log(vl, 3, "Iteration %d", i);
......@@ -184,12 +184,12 @@ server_start(struct server *s)
s->aport, sizeof s->aport);
macro_def(s->vl, s->name, "addr", "%s", s->aaddr);
macro_def(s->vl, s->name, "port", "%s", s->aport);
macro_def(s->vl, s->name, "sock", "%s:%s", s->aaddr, s->aport);
macro_def(s->vl, s->name, "sock", "%s %s", s->aaddr, s->aport);
/* Record the actual port, and reuse it on subsequent starts */
if (!strcmp(s->port, "0"))
REPLACE(s->port, s->aport);
}
vtc_log(s->vl, 1, "Listen on %s:%s", s->addr, s->port);
vtc_log(s->vl, 1, "Listen on %s %s", s->addr, s->port);
s->run = 1;
AZ(pthread_create(&s->tp, NULL, server_thread, s));
}
......
......@@ -277,7 +277,7 @@ varnish_launch(struct varnish *v)
vsb_printf(vsb, " -p syslog_cli_traffic=off");
vsb_printf(vsb, " -a '%s'", "127.0.0.1:0");
vsb_printf(vsb, " -S %s/_S", v->workdir);
vsb_printf(vsb, " -M %s:%s", abuf, pbuf);
vsb_printf(vsb, " -M '%s %s'", abuf, pbuf);
vsb_printf(vsb, " -P %s/varnishd.pid", v->workdir);
vsb_printf(vsb, " %s", vsb_data(v->storage));
vsb_printf(vsb, " %s", vsb_data(v->args));
......@@ -408,7 +408,7 @@ varnish_start(struct varnish *v)
vtc_log(v->vl, 2, "Listen on %s %s", h, p);
macro_def(v->vl, v->name, "addr", "%s", h);
macro_def(v->vl, v->name, "port", "%s", p);
macro_def(v->vl, v->name, "sock", "%s:%s", h, p);
macro_def(v->vl, v->name, "sock", "%s %s", h, p);
}
/**********************************************************************
......
......@@ -8,6 +8,7 @@ You may or may not want to know what Poul-Henning think.
.. toctree::
ipv6suckage.rst
platforms.rst
barriers.rst
thoughts.rst
......
.. _phk_ipv6suckage:
============
IPv6 Suckage
============
In my drawer full of cassette tapes, is a 6 tape collection published
by Carl Malamuds "Internet Talk Radio", the first and by far the
geekiest radio station on the internet.
The tapes are from 1994 and the topic is "IPng", the IPv4 replacement
that eventually became IPv6. To say that I am a bit jaded about
IPv6 by now, is accusing the pope of being religious.
IPv4 addresses in numeric form, are written as 192.168.0.1 and to
not confuse IPv6 with IPv4, it was decided in RFC1884 that IPv6
would use colons and groups of 16 bits, and because 128 bits are a
lot of bits, the secret '::' trick was introduced, to supress all
the zero bits that we may not ever need anyway: 1080::8:800:200C:417A
Colon was chosen because it was already used in MAC/ethernet addresses
and did no damage there and it is not a troublesome metacharacter
in shells. No worries.
Most protocols have a Well Known Service number, TELNET is 23, SSH
is 22 and HTTP is 80 so usually people will only have to care about
the IP number.
Except when they don't, for instance when they run more than one
webserver on the same machine.
No worries, says the power that controls what URLs look like, we
will just stick the port number after the IP# with a colon:
http://192.168.0.1:8080/...
That obviously does not work with IPv6, so RFC3986 comes around and
says "darn, we didn't think of that" and puts the IPV6 address in
[...] giving us:
http://[1080::8:800:200C:417A]:8080/
Remember that "harmless in shells" detail ? Yeah, sorry about that.
Now, there are also a RFC sanctioned API for translating a socket
address into an ascii string, getnameinfo(), and if you tell it that
you want a numeric return, you get a numeric return, and you don't
even need to know if it is a IPv4 or IPv6 address in the first place.
But it returns the IP# in one buffer and the port number in another,
so if you want to format the sockaddr in the by RFC5952 recommended
way (the same as RFC3986), you need to inspect the version field
in the sockaddr to see if you should do
"%s:%s", host, port
or
"[%s]:%s", host, port
Careless standardization costs code, have I mentioned this before ?
Varnish reports socket addresses as two fields: IP space PORT,
now you know why.
Until next time,
Poul-Henning, 2010-08-24
......@@ -102,6 +102,8 @@ VSS_parse(const char *str, char **addr, char **port)
} else {
/* IPv4 address of the form 127.0.0.1:80, or non-numeric */
p = strchr(str, ':');
if (p == NULL)
p = strchr(str, ' ');
if (p == NULL) {
*addr = strdup(str);
XXXAN(*addr);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment