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
00f65afe
Commit
00f65afe
authored
3 years ago
by
Tatsuhiro Tsujikawa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
nghttpx: Fix incorrect quic frontend address matching
parent
fc402f58
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
109 additions
and
82 deletions
+109
-82
src/shrpx_worker.cc
src/shrpx_worker.cc
+36
-13
src/util.cc
src/util.cc
+9
-64
src/util.h
src/util.h
+58
-5
src/util_test.cc
src/util_test.cc
+6
-0
No files found.
src/shrpx_worker.cc
View file @
00f65afe
...
@@ -1021,7 +1021,10 @@ const UpstreamAddr *Worker::find_quic_upstream_addr(const Address &local_addr) {
...
@@ -1021,7 +1021,10 @@ const UpstreamAddr *Worker::find_quic_upstream_addr(const Address &local_addr) {
assert
(
0
);
assert
(
0
);
}
}
auto
hostport
=
util
::
make_hostport
(
StringRef
{
host
.
data
()},
port
);
std
::
array
<
char
,
util
::
max_hostport
>
hostport_buf
;
auto
hostport
=
util
::
make_http_hostport
(
std
::
begin
(
hostport_buf
),
StringRef
{
host
.
data
()},
port
);
const
UpstreamAddr
*
fallback_faddr
=
nullptr
;
const
UpstreamAddr
*
fallback_faddr
=
nullptr
;
for
(
auto
&
faddr
:
quic_upstream_addrs_
)
{
for
(
auto
&
faddr
:
quic_upstream_addrs_
)
{
...
@@ -1033,21 +1036,41 @@ const UpstreamAddr *Worker::find_quic_upstream_addr(const Address &local_addr) {
...
@@ -1033,21 +1036,41 @@ const UpstreamAddr *Worker::find_quic_upstream_addr(const Address &local_addr) {
continue
;
continue
;
}
}
switch
(
faddr
.
family
)
{
if
(
faddr
.
port
==
443
||
faddr
.
port
==
80
)
{
case
AF_INET
:
switch
(
faddr
.
family
)
{
if
(
util
::
starts_with
(
faddr
.
hostport
,
StringRef
::
from_lit
(
"0.0.0.0:"
)))
{
case
AF_INET
:
fallback_faddr
=
&
faddr
;
if
(
util
::
streq
(
faddr
.
hostport
,
StringRef
::
from_lit
(
"0.0.0.0"
)))
{
}
fallback_faddr
=
&
faddr
;
}
break
;
break
;
case
AF_INET6
:
case
AF_INET6
:
if
(
util
::
starts_with
(
faddr
.
hostport
,
StringRef
::
from_lit
(
"[::]:"
)))
{
if
(
util
::
streq
(
faddr
.
hostport
,
StringRef
::
from_lit
(
"[::]"
)))
{
fallback_faddr
=
&
faddr
;
fallback_faddr
=
&
faddr
;
}
break
;
default:
assert
(
0
);
}
}
}
else
{
switch
(
faddr
.
family
)
{
case
AF_INET
:
if
(
util
::
starts_with
(
faddr
.
hostport
,
StringRef
::
from_lit
(
"0.0.0.0:"
)))
{
fallback_faddr
=
&
faddr
;
}
break
;
break
;
default:
case
AF_INET6
:
assert
(
0
);
if
(
util
::
starts_with
(
faddr
.
hostport
,
StringRef
::
from_lit
(
"[::]:"
)))
{
fallback_faddr
=
&
faddr
;
}
break
;
default:
assert
(
0
);
}
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
src/util.cc
View file @
00f65afe
...
@@ -1325,81 +1325,26 @@ std::string dtos(double n) {
...
@@ -1325,81 +1325,26 @@ std::string dtos(double n) {
StringRef
make_http_hostport
(
BlockAllocator
&
balloc
,
const
StringRef
&
host
,
StringRef
make_http_hostport
(
BlockAllocator
&
balloc
,
const
StringRef
&
host
,
uint16_t
port
)
{
uint16_t
port
)
{
if
(
port
!=
80
&&
port
!=
443
)
{
auto
iov
=
make_byte_ref
(
balloc
,
host
.
size
()
+
2
+
1
+
5
+
1
);
return
make_hostport
(
balloc
,
host
,
port
);
return
make_http_hostport
(
iov
.
base
,
host
,
port
);
}
auto
ipv6
=
ipv6_numeric_addr
(
host
.
c_str
());
auto
iov
=
make_byte_ref
(
balloc
,
host
.
size
()
+
(
ipv6
?
2
:
0
)
+
1
);
auto
p
=
iov
.
base
;
if
(
ipv6
)
{
*
p
++
=
'['
;
}
p
=
std
::
copy
(
std
::
begin
(
host
),
std
::
end
(
host
),
p
);
if
(
ipv6
)
{
*
p
++
=
']'
;
}
*
p
=
'\0'
;
return
StringRef
{
iov
.
base
,
p
};
}
}
std
::
string
make_hostport
(
const
StringRef
&
host
,
uint16_t
port
)
{
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
;
std
::
string
hostport
;
hostport
.
resize
(
host
.
size
()
+
(
ipv6
?
2
:
0
)
+
1
+
serv
.
size
());
// I'm not sure we can write \0 at the position std::string::size(),
// so allocate an extra byte.
hostport
.
resize
(
host
.
size
()
+
2
+
1
+
5
+
1
);
auto
p
=
&
hostport
[
0
];
auto
s
=
make_hostport
(
std
::
begin
(
hostport
),
host
,
port
);
hostport
.
resize
(
s
.
size
());
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
;
return
hostport
;
}
}
StringRef
make_hostport
(
BlockAllocator
&
balloc
,
const
StringRef
&
host
,
StringRef
make_hostport
(
BlockAllocator
&
balloc
,
const
StringRef
&
host
,
uint16_t
port
)
{
uint16_t
port
)
{
auto
ipv6
=
ipv6_numeric_addr
(
host
.
c_str
());
auto
iov
=
make_byte_ref
(
balloc
,
host
.
size
()
+
2
+
1
+
5
+
1
);
auto
serv
=
utos
(
port
);
return
make_hostport
(
iov
.
base
,
host
,
port
);
auto
iov
=
make_byte_ref
(
balloc
,
host
.
size
()
+
(
ipv6
?
2
:
0
)
+
1
+
serv
.
size
());
auto
p
=
iov
.
base
;
if
(
ipv6
)
{
*
p
++
=
'['
;
}
p
=
std
::
copy
(
std
::
begin
(
host
),
std
::
end
(
host
),
p
);
if
(
ipv6
)
{
*
p
++
=
']'
;
}
*
p
++
=
':'
;
p
=
std
::
copy
(
std
::
begin
(
serv
),
std
::
end
(
serv
),
p
);
*
p
=
'\0'
;
return
StringRef
{
iov
.
base
,
p
};
}
}
namespace
{
namespace
{
...
...
This diff is collapsed.
Click to expand it.
src/util.h
View file @
00f65afe
...
@@ -762,18 +762,71 @@ std::string format_duration(const std::chrono::microseconds &u);
...
@@ -762,18 +762,71 @@ std::string format_duration(const std::chrono::microseconds &u);
// Just like above, but this takes |t| as seconds.
// Just like above, but this takes |t| as seconds.
std
::
string
format_duration
(
double
t
);
std
::
string
format_duration
(
double
t
);
// Just like make_http_hostport(), but doesn't treat 80 and 443
// specially.
std
::
string
make_hostport
(
const
StringRef
&
host
,
uint16_t
port
);
StringRef
make_hostport
(
BlockAllocator
&
balloc
,
const
StringRef
&
host
,
uint16_t
port
);
template
<
typename
OutputIt
>
StringRef
make_hostport
(
OutputIt
first
,
const
StringRef
&
host
,
uint16_t
port
)
{
auto
ipv6
=
ipv6_numeric_addr
(
host
.
c_str
());
auto
serv
=
utos
(
port
);
auto
p
=
first
;
if
(
ipv6
)
{
*
p
++
=
'['
;
}
p
=
std
::
copy
(
std
::
begin
(
host
),
std
::
end
(
host
),
p
);
if
(
ipv6
)
{
*
p
++
=
']'
;
}
*
p
++
=
':'
;
p
=
std
::
copy
(
std
::
begin
(
serv
),
std
::
end
(
serv
),
p
);
*
p
=
'\0'
;
return
StringRef
{
first
,
p
};
}
// Creates "host:port" string using given |host| and |port|. If
// Creates "host:port" string using given |host| and |port|. If
// |host| is numeric IPv6 address (e.g., ::1), it is enclosed by "["
// |host| is numeric IPv6 address (e.g., ::1), it is enclosed by "["
// and "]". If |port| is 80 or 443, port part is omitted.
// and "]". If |port| is 80 or 443, port part is omitted.
StringRef
make_http_hostport
(
BlockAllocator
&
balloc
,
const
StringRef
&
host
,
StringRef
make_http_hostport
(
BlockAllocator
&
balloc
,
const
StringRef
&
host
,
uint16_t
port
);
uint16_t
port
);
// Just like make_http_hostport(), but doesn't treat 80 and 443
constexpr
size_t
max_hostport
=
NI_MAXHOST
+
/* [] for IPv6 */
2
+
/* : */
1
+
// specially.
/* port */
5
+
/* terminal NUL */
1
;
std
::
string
make_hostport
(
const
StringRef
&
host
,
uint16_t
port
);
StringRef
make_hostport
(
BlockAllocator
&
balloc
,
const
StringRef
&
host
,
template
<
typename
OutputIt
>
uint16_t
port
);
StringRef
make_http_hostport
(
OutputIt
first
,
const
StringRef
&
host
,
uint16_t
port
)
{
if
(
port
!=
80
&&
port
!=
443
)
{
return
make_hostport
(
first
,
host
,
port
);
}
auto
ipv6
=
ipv6_numeric_addr
(
host
.
c_str
());
auto
p
=
first
;
if
(
ipv6
)
{
*
p
++
=
'['
;
}
p
=
std
::
copy
(
std
::
begin
(
host
),
std
::
end
(
host
),
p
);
if
(
ipv6
)
{
*
p
++
=
']'
;
}
*
p
=
'\0'
;
return
StringRef
{
first
,
p
};
}
// Dumps |src| of length |len| in the format similar to `hexdump -C`.
// Dumps |src| of length |len| in the format similar to `hexdump -C`.
void
hexdump
(
FILE
*
out
,
const
uint8_t
*
src
,
size_t
len
);
void
hexdump
(
FILE
*
out
,
const
uint8_t
*
src
,
size_t
len
);
...
...
This diff is collapsed.
Click to expand it.
src/util_test.cc
View file @
00f65afe
...
@@ -550,6 +550,12 @@ void test_util_make_hostport(void) {
...
@@ -550,6 +550,12 @@ void test_util_make_hostport(void) {
util
::
make_hostport
(
balloc
,
StringRef
::
from_lit
(
"localhost"
),
80
));
util
::
make_hostport
(
balloc
,
StringRef
::
from_lit
(
"localhost"
),
80
));
CU_ASSERT
(
"[::1]:443"
==
CU_ASSERT
(
"[::1]:443"
==
util
::
make_hostport
(
balloc
,
StringRef
::
from_lit
(
"::1"
),
443
));
util
::
make_hostport
(
balloc
,
StringRef
::
from_lit
(
"::1"
),
443
));
// Check std::string version
CU_ASSERT
(
"abcdefghijklmnopqrstuvwxyz0123456789:65535"
==
util
::
make_hostport
(
StringRef
::
from_lit
(
"abcdefghijklmnopqrstuvwxyz0123456789"
),
65535
));
}
}
void
test_util_strifind
(
void
)
{
void
test_util_strifind
(
void
)
{
...
...
This diff is collapsed.
Click to expand it.
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