Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mtproto_proxy
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
mtproto_proxy
Commits
7677fe11
Unverified
Commit
7677fe11
authored
Aug 12, 2019
by
Sergey Prokhorov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add 'listener' to `protocol_error` metric
parent
e28e21a7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
11 deletions
+12
-11
mtp_handler.erl
src/mtp_handler.erl
+6
-5
mtp_metric.erl
src/mtp_metric.erl
+1
-1
single_dc_SUITE.erl
test/single_dc_SUITE.erl
+5
-5
No files found.
src/mtp_handler.erl
View file @
7677fe11
...
...
@@ -135,14 +135,15 @@ handle_cast({proxy_ans, Down, Data}, #state{down = Down, srv_error_filter = off}
{
ok
,
S1
}
=
up_send
(
Data
,
S
),
ok
=
mtp_down_conn
:
ack
(
Down
,
1
,
iolist_size
(
Data
)),
maybe_check_health
(
bump_timer
(
S1
));
handle_cast
({
proxy_ans
,
Down
,
?
SRV_ERROR
=
Data
},
#state
{
down
=
Down
,
srv_error_filter
=
Filter
,
addr
=
{
Ip
,
_}}
=
S
)
when
Filter
=/=
off
->
handle_cast
({
proxy_ans
,
Down
,
?
SRV_ERROR
=
Data
},
#state
{
down
=
Down
,
srv_error_filter
=
Filter
,
listener
=
Listener
,
addr
=
{
Ip
,
_}}
=
S
)
when
Filter
=/=
off
->
%% telegram server -> proxy
%% Server replied with server error; it might be another kind of replay attack;
%% Don't send this packet to client so proxy won't be fingerprinted
ok
=
mtp_down_conn
:
ack
(
Down
,
1
,
iolist_size
(
Data
)),
?
log
(
warning
,
"
~s
: protocol_error srv_error_filtered"
,
[
inet
:
ntoa
(
Ip
)]),
mtp_metric
:
count_inc
([
?
APP
,
protocol_error
,
total
],
1
,
#
{
labels
=>
[
srv_error_filtered
]}),
mtp_metric
:
count_inc
([
?
APP
,
protocol_error
,
total
],
1
,
#
{
labels
=>
[
Listener
,
srv_error_filtered
]}),
{
noreply
,
case
Filter
of
first
->
S
#state
{
srv_error_filter
=
off
};
...
...
@@ -182,7 +183,7 @@ handle_info({tcp, Sock, Data}, #state{sock = Sock, transport = Transport,
%% Consider checking health here as well
{
noreply
,
bump_timer
(
S1
)}
catch
error
:{
protocol_error
,
Type
,
Extra
}
->
mtp_metric
:
count_inc
([
?
APP
,
protocol_error
,
total
],
1
,
#
{
labels
=>
[
Type
]}),
mtp_metric
:
count_inc
([
?
APP
,
protocol_error
,
total
],
1
,
#
{
labels
=>
[
Listener
,
Type
]}),
?
log
(
warning
,
"
~s
: protocol_error
~p
~p
"
,
[
inet
:
ntoa
(
Ip
),
Type
,
Extra
]),
{
stop
,
normal
,
maybe_close_down
(
S
)}
end
;
...
...
@@ -333,7 +334,7 @@ parse_upstream_data(<<Header:64/binary, Rest/binary>>,
stage
=
tunnel
},
hibernate
));
{
error
,
Reason
}
when
is_atom
(
Reason
)
->
mtp_metric
:
count_inc
([
?
APP
,
protocol_error
,
total
],
1
,
#
{
labels
=>
[
Reason
]}),
mtp_metric
:
count_inc
([
?
APP
,
protocol_error
,
total
],
1
,
#
{
labels
=>
[
Listener
,
Reason
]}),
error
({
protocol_error
,
Reason
,
Header
})
end
;
parse_upstream_data
(
Bin
,
#state
{
stage
=
Stage
,
codec
=
Codec0
}
=
S
)
when
Stage
=/=
tunnel
->
...
...
src/mtp_metric.erl
View file @
7677fe11
...
...
@@ -158,7 +158,7 @@ active_metrics() ->
{
count
,
[
?
APP
,
protocol_error
,
total
],
"Proxy protocol errors"
,
#
{
labels
=>
[
reason
]}},
#
{
labels
=>
[
listener
,
reason
]}},
{
count
,
[
?
APP
,
protocol_ok
,
total
],
"Proxy upstream protocol type"
,
#
{
labels
=>
[
listener
,
protocol
]}},
...
...
test/single_dc_SUITE.erl
View file @
7677fe11
...
...
@@ -128,7 +128,7 @@ packet_too_large_case(Cfg) when is_list(Cfg) ->
Port
=
?
config
(
mtp_port
,
Cfg
),
Secret
=
?
config
(
mtp_secret
,
Cfg
),
ErrCount
=
fun
(
Tag
)
->
mtp_test_metric
:
get_tags
(
count
,
[
?
APP
,
protocol_error
,
total
],
[
Tag
])
mtp_test_metric
:
get_tags
(
count
,
[
?
APP
,
protocol_error
,
total
],
[
?
FUNCTION_NAME
,
Tag
])
end
,
OkPacket
=
binary
:
copy
(
<<
0
>>
,
64
),
BigPacket
=
binary
:
copy
(
<<
0
>>
,
1024
*
1024
+
1024
),
...
...
@@ -333,7 +333,7 @@ replay_attack_case(Cfg) when is_list(Cfg) ->
Seed
=
crypto
:
strong_rand_bytes
(
58
),
ErrCount
=
fun
()
->
mtp_test_metric
:
get_tags
(
count
,
[
?
APP
,
protocol_error
,
total
],
[
replay_session_detected
])
count
,
[
?
APP
,
protocol_error
,
total
],
[
?
FUNCTION_NAME
,
replay_session_detected
])
end
,
?
assertEqual
(
not_found
,
ErrCount
()),
Cli1
=
mtp_test_client
:
connect
(
Host
,
Port
,
Seed
,
Secret
,
DcId
,
mtp_secure
),
...
...
@@ -342,7 +342,7 @@ replay_attack_case(Cfg) when is_list(Cfg) ->
Cli2
=
mtp_test_client
:
connect
(
Host
,
Port
,
Seed
,
Secret
,
DcId
,
mtp_secure
),
?
assertEqual
(
ok
,
mtp_test_metric
:
wait_for_value
(
count
,
[
?
APP
,
protocol_error
,
total
],
[
replay_session_detected
],
1
,
5000
),
count
,
[
?
APP
,
protocol_error
,
total
],
[
?
FUNCTION_NAME
,
replay_session_detected
],
1
,
5000
),
{
mtp_session_storage
:
status
(),
sys
:
get_state
(
mtp_test_metric
)}),
?
assertEqual
(
1
,
ErrCount
()),
...
...
@@ -361,7 +361,7 @@ replay_attack_server_error_case(Cfg) when is_list(Cfg) ->
Secret
=
?
config
(
mtp_secret
,
Cfg
),
ErrCount
=
fun
()
->
mtp_test_metric
:
get_tags
(
count
,
[
?
APP
,
protocol_error
,
total
],
[
srv_error_filtered
])
count
,
[
?
APP
,
protocol_error
,
total
],
[
?
FUNCTION_NAME
,
srv_error_filtered
])
end
,
?
assertEqual
(
not_found
,
ErrCount
()),
Cli1
=
mtp_test_client
:
connect
(
Host
,
Port
,
Secret
,
DcId
,
mtp_secure
),
...
...
@@ -369,7 +369,7 @@ replay_attack_server_error_case(Cfg) when is_list(Cfg) ->
_
Cli2
=
mtp_test_client
:
send
(
<<
108
,
254
,
255
,
255
>>
,
Cli1
),
?
assertEqual
(
ok
,
mtp_test_metric
:
wait_for_value
(
count
,
[
?
APP
,
protocol_error
,
total
],
[
srv_error_filtered
],
1
,
5000
),
count
,
[
?
APP
,
protocol_error
,
total
],
[
?
FUNCTION_NAME
,
srv_error_filtered
],
1
,
5000
),
{
mtp_session_storage
:
status
(),
sys
:
get_state
(
mtp_test_metric
)}),
?
assertEqual
(
1
,
ErrCount
()).
...
...
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