Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
nghttp2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
nghttp2
Commits
eb0c82d9
Commit
eb0c82d9
authored
Feb 13, 2016
by
Tatsuhiro Tsujikawa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
nghttpx: More log output when resolving addresses for better debugging
parent
7adfa5de
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
91 additions
and
18 deletions
+91
-18
src/shrpx-unittest.cc
src/shrpx-unittest.cc
+4
-0
src/shrpx.cc
src/shrpx.cc
+31
-8
src/util.cc
src/util.cc
+36
-9
src/util.h
src/util.h
+7
-1
src/util_test.cc
src/util_test.cc
+11
-0
src/util_test.h
src/util_test.h
+2
-0
No files found.
src/shrpx-unittest.cc
View file @
eb0c82d9
...
...
@@ -167,6 +167,10 @@ int main(int argc, char *argv[]) {
!
CU_add_test
(
pSuite
,
"util_get_uint64"
,
shrpx
::
test_util_get_uint64
)
||
!
CU_add_test
(
pSuite
,
"util_parse_config_str_list"
,
shrpx
::
test_util_parse_config_str_list
)
||
!
CU_add_test
(
pSuite
,
"util_make_http_hostport"
,
shrpx
::
test_util_make_http_hostport
)
||
!
CU_add_test
(
pSuite
,
"util_make_hostport"
,
shrpx
::
test_util_make_hostport
)
||
!
CU_add_test
(
pSuite
,
"gzip_inflate"
,
test_nghttp2_gzip_inflate
)
||
!
CU_add_test
(
pSuite
,
"buffer_write"
,
nghttp2
::
test_buffer_write
)
||
!
CU_add_test
(
pSuite
,
"pool_recycle"
,
nghttp2
::
test_pool_recycle
)
||
...
...
src/shrpx.cc
View file @
eb0c82d9
...
...
@@ -656,7 +656,7 @@ int create_tcp_server_socket(UpstreamAddr &faddr,
}
faddr
.
fd
=
fd
;
faddr
.
hostport
=
util
::
make_hostport
(
host
.
data
(),
faddr
.
port
);
faddr
.
hostport
=
util
::
make_h
ttp_h
ostport
(
host
.
data
(),
faddr
.
port
);
LOG
(
NOTICE
)
<<
"Listening on "
<<
faddr
.
hostport
;
...
...
@@ -2178,8 +2178,10 @@ void process_options(
exit
(
EXIT_FAILURE
);
}
LOG
(
INFO
)
<<
"Use UNIX domain socket path "
<<
path
<<
" for backend connection"
;
if
(
LOG_ENABLED
(
INFO
))
{
LOG
(
INFO
)
<<
"Use UNIX domain socket path "
<<
path
<<
" for backend connection"
;
}
addr
.
addr
.
su
.
un
.
sun_family
=
AF_UNIX
;
// copy path including terminal NULL
...
...
@@ -2189,44 +2191,65 @@ void process_options(
continue
;
}
addr
.
hostport
=
ImmutableString
(
util
::
make_hostport
(
addr
.
host
.
c_str
(),
addr
.
port
));
addr
.
hostport
=
ImmutableString
(
util
::
make_http_hostport
(
StringRef
(
addr
.
host
),
addr
.
port
));
auto
hostport
=
util
::
make_hostport
(
addr
.
host
.
c_str
(),
addr
.
port
);
if
(
resolve_hostname
(
&
addr
.
addr
,
addr
.
host
.
c_str
(),
addr
.
port
,
downstreamconf
.
family
)
==
-
1
)
{
LOG
(
FATAL
)
<<
"Resolving backend address failed: "
<<
hostport
;
exit
(
EXIT_FAILURE
);
}
LOG
(
NOTICE
)
<<
"Resolved backend address: "
<<
hostport
<<
" -> "
<<
util
::
numeric_hostport
(
&
addr
.
addr
.
su
.
sa
,
addr
.
addr
.
len
);
}
}
auto
&
proxy
=
mod_config
()
->
downstream_http_proxy
;
if
(
!
proxy
.
host
.
empty
())
{
if
(
LOG_ENABLED
(
INFO
))
{
LOG
(
INFO
)
<<
"Resolving backend http proxy address"
;
}
auto
hostport
=
util
::
make_hostport
(
proxy
.
host
.
c_str
(),
proxy
.
port
);
if
(
resolve_hostname
(
&
proxy
.
addr
,
proxy
.
host
.
c_str
(),
proxy
.
port
,
AF_UNSPEC
)
==
-
1
)
{
LOG
(
FATAL
)
<<
"Resolving backend HTTP proxy address failed: "
<<
hostport
;
exit
(
EXIT_FAILURE
);
}
LOG
(
NOTICE
)
<<
"Backend HTTP proxy address: "
<<
hostport
<<
" -> "
<<
util
::
numeric_hostport
(
&
proxy
.
addr
.
su
.
sa
,
proxy
.
addr
.
len
);
}
{
auto
&
memcachedconf
=
tlsconf
.
session_cache
.
memcached
;
if
(
memcachedconf
.
host
)
{
auto
hostport
=
util
::
make_hostport
(
memcachedconf
.
host
.
get
(),
memcachedconf
.
port
);
if
(
resolve_hostname
(
&
memcachedconf
.
addr
,
memcachedconf
.
host
.
get
(),
memcachedconf
.
port
,
memcachedconf
.
family
)
==
-
1
)
{
LOG
(
FATAL
)
<<
"Resolving memcached address for TLS session cache failed: "
<<
hostport
;
exit
(
EXIT_FAILURE
);
}
LOG
(
NOTICE
)
<<
"Memcached address for TLS session cache: "
<<
hostport
<<
" -> "
<<
util
::
numeric_hostport
(
&
memcachedconf
.
addr
.
su
.
sa
,
memcachedconf
.
addr
.
len
);
}
}
{
auto
&
memcachedconf
=
tlsconf
.
ticket
.
memcached
;
if
(
memcachedconf
.
host
)
{
auto
hostport
=
util
::
make_hostport
(
memcachedconf
.
host
.
get
(),
memcachedconf
.
port
);
if
(
resolve_hostname
(
&
memcachedconf
.
addr
,
memcachedconf
.
host
.
get
(),
memcachedconf
.
port
,
memcachedconf
.
family
)
==
-
1
)
{
LOG
(
FATAL
)
<<
"Resolving memcached address for TLS ticket key failed: "
<<
hostport
;
exit
(
EXIT_FAILURE
);
}
LOG
(
NOTICE
)
<<
"Memcached address for TLS ticket key: "
<<
hostport
<<
" -> "
<<
util
::
numeric_hostport
(
&
memcachedconf
.
addr
.
su
.
sa
,
memcachedconf
.
addr
.
len
);
}
}
...
...
src/util.cc
View file @
eb0c82d9
...
...
@@ -57,7 +57,6 @@
#include <nghttp2/nghttp2.h>
#include "timegm.h"
#include "template.h"
namespace
nghttp2
{
...
...
@@ -1149,25 +1148,53 @@ std::string dtos(double n) {
return
utos
(
static_cast
<
int64_t
>
(
n
))
+
"."
+
(
f
.
size
()
==
1
?
"0"
:
""
)
+
f
;
}
std
::
string
make_hostport
(
const
char
*
host
,
uint16_t
port
)
{
auto
ipv6
=
ipv6_numeric_addr
(
host
);
std
::
string
make_http_hostport
(
const
StringRef
&
host
,
uint16_t
port
)
{
if
(
port
!=
80
&&
port
!=
443
)
{
return
make_hostport
(
host
,
port
);
}
auto
ipv6
=
ipv6_numeric_addr
(
host
.
c_str
());
std
::
string
hostport
;
hostport
.
resize
(
host
.
size
()
+
(
ipv6
?
2
:
0
));
auto
p
=
&
hostport
[
0
];
if
(
ipv6
)
{
hostport
+
=
'['
;
*
p
++
=
'['
;
}
hostport
+=
host
;
p
=
std
::
copy_n
(
host
.
c_str
(),
host
.
size
(),
p
)
;
if
(
ipv6
)
{
hostport
+
=
']'
;
*
p
++
=
']'
;
}
if
(
port
!=
80
&&
port
!=
443
)
{
hostport
+=
':'
;
hostport
+=
utos
(
port
);
return
hostport
;
}
std
::
string
make_hostport
(
const
StringRef
&
host
,
uint16_t
port
)
{
auto
ipv6
=
ipv6_numeric_addr
(
host
.
c_str
());
auto
serv
=
utos
(
port
);
std
::
string
hostport
;
hostport
.
resize
(
host
.
size
()
+
(
ipv6
?
2
:
0
)
+
1
+
serv
.
size
());
auto
p
=
&
hostport
[
0
];
if
(
ipv6
)
{
*
p
++
=
'['
;
}
p
=
std
::
copy_n
(
host
.
c_str
(),
host
.
size
(),
p
);
if
(
ipv6
)
{
*
p
++
=
']'
;
}
*
p
++
=
':'
;
std
::
copy_n
(
serv
.
c_str
(),
serv
.
size
(),
p
);
return
hostport
;
}
...
...
src/util.h
View file @
eb0c82d9
...
...
@@ -49,6 +49,8 @@
#include "http-parser/http_parser.h"
#include "template.h"
namespace
nghttp2
{
// The additional HTTP/2 protocol ALPN protocol identifier we also
...
...
@@ -623,7 +625,11 @@ std::string format_duration(double t);
// Creates "host:port" string using given |host| and |port|. If
// |host| is numeric IPv6 address (e.g., ::1), it is enclosed by "["
// and "]". If |port| is 80 or 443, port part is omitted.
std
::
string
make_hostport
(
const
char
*
host
,
uint16_t
port
);
std
::
string
make_http_hostport
(
const
StringRef
&
host
,
uint16_t
port
);
// Just like make_http_hostport(), but doesn't treat 80 and 443
// specially.
std
::
string
make_hostport
(
const
StringRef
&
host
,
uint16_t
port
);
// Dumps |src| of length |len| in the format similar to `hexdump -C`.
void
hexdump
(
FILE
*
out
,
const
uint8_t
*
src
,
size_t
len
);
...
...
src/util_test.cc
View file @
eb0c82d9
...
...
@@ -455,4 +455,15 @@ void test_util_parse_config_str_list(void) {
CU_ASSERT
(
"charlie"
==
res
[
2
]);
}
void
test_util_make_http_hostport
(
void
)
{
CU_ASSERT
(
"localhost"
==
util
::
make_http_hostport
(
"localhost"
,
80
));
CU_ASSERT
(
"[::1]"
==
util
::
make_http_hostport
(
"::1"
,
443
));
CU_ASSERT
(
"localhost:3000"
==
util
::
make_http_hostport
(
"localhost"
,
3000
));
}
void
test_util_make_hostport
(
void
)
{
CU_ASSERT
(
"localhost:80"
==
util
::
make_hostport
(
"localhost"
,
80
));
CU_ASSERT
(
"[::1]:443"
==
util
::
make_hostport
(
"::1"
,
443
));
}
}
// namespace shrpx
src/util_test.h
View file @
eb0c82d9
...
...
@@ -57,6 +57,8 @@ void test_util_parse_http_date(void);
void
test_util_localtime_date
(
void
);
void
test_util_get_uint64
(
void
);
void
test_util_parse_config_str_list
(
void
);
void
test_util_make_http_hostport
(
void
);
void
test_util_make_hostport
(
void
);
}
// namespace shrpx
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment