Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

return proper sender TEID when rejecting new sessions #326

Merged
merged 2 commits into from
Feb 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/gtp_context.erl
Original file line number Diff line number Diff line change
Expand Up @@ -291,13 +291,15 @@ port_message(#request{socket = Socket, info = Info} = Request,
case get_handler_if(Socket, Msg) of
{ok, Interface, InterfaceOpts} ->
case ergw:get_accept_new() of
true -> ok;
true ->
validate_teid(Msg),
Server = context_new(Socket, Info, Version, Interface, InterfaceOpts),
port_message(Server, Request, Msg, false);

_ ->
throw({error, no_resources_available})
end,
validate_teid(Msg),
Server = context_new(Socket, Info, Version, Interface, InterfaceOpts),
port_message(Server, Request, Msg, false);
gtp_context:generic_error(Request, Msg, no_resources_available),
ok
end;

{error, _} = Error ->
throw(Error)
Expand Down
4 changes: 4 additions & 0 deletions src/gtp_v1_c.erl
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,10 @@ load_class(#gtp{type = g_pdu}) ->
load_class(_) ->
other.

find_sender_teid(#gtp{
ie = #{{tunnel_endpoint_identifier_control_plane,0} :=
#tunnel_endpoint_identifier_control_plane{tei = TEID}}}) ->
TEID;
find_sender_teid(_) ->
undefined.

Expand Down
10 changes: 9 additions & 1 deletion test/ergw_ggsn_test_lib.erl
Original file line number Diff line number Diff line change
Expand Up @@ -469,14 +469,22 @@ validate_response(create_pdp_context_request, overload, Response, GtpC) ->
validate_seq_no(Response, GtpC),

%% this is debatable, but decoding the request would require even more resources.
%% validate_teid(Response, GtpC),
validate_teid(Response, 0),

?match(#gtp{type = create_pdp_context_response,
ie = #{{cause,0} := #cause{value = no_resources_available}}},
Response),
GtpC;

validate_response(create_pdp_context_request, reject_new, Response, GtpC) ->
validate_seq_no(Response, GtpC),
validate_teid(Response, GtpC),

?match(#gtp{type = create_pdp_context_response,
ie = #{{cause,0} := #cause{value = no_resources_available}}},
Response),
GtpC;

validate_response(create_pdp_context_request, no_resources_available, Response, GtpC) ->
validate_seq_no(Response, GtpC),
validate_teid(Response, GtpC),
Expand Down
31 changes: 28 additions & 3 deletions test/ergw_pgw_test_lib.erl
Original file line number Diff line number Diff line change
Expand Up @@ -382,12 +382,21 @@ make_request(echo_request, _SubType,
#gtp{version = v2, type = echo_request, tei = undefined,
seq_no = SeqNo, ie = IEs};

make_request(create_session_request, missing_ie,
make_request(create_session_request, missing_sender_teid,
#gtpc{restart_counter = RCnt, seq_no = SeqNo}) ->
IEs = [#v2_recovery{restart_counter = RCnt}],
#gtp{version = v2, type = create_session_request, tei = 0,
seq_no = SeqNo, ie = IEs};

make_request(create_session_request, missing_ie,
#gtpc{restart_counter = RCnt, seq_no = SeqNo,
local_ip = LocalIP,
local_control_tei = LocalCntlTEI}) ->
IEs = [#v2_recovery{restart_counter = RCnt},
fq_teid(0, ?'S5/S8-C SGW', LocalCntlTEI, LocalIP)],
#gtp{version = v2, type = create_session_request, tei = 0,
seq_no = SeqNo, ie = IEs};

make_request(create_session_request, SubType,
#gtpc{restart_counter = RCnt, seq_no = SeqNo,
local_ip = LocalIP,
Expand Down Expand Up @@ -814,14 +823,22 @@ validate_response(_Type, invalid_teid, Response, GtpC) ->
}, Response),
GtpC;

validate_response(create_session_request, missing_ie, Response, GtpC) ->
validate_response(create_session_request, missing_sender_teid, Response, GtpC) ->
validate_seq_no(Response, GtpC),
validate_teid(Response, 0),
?match(#gtp{type = create_session_response,
ie = #{{v2_cause,0} := #v2_cause{v2_cause = mandatory_ie_missing}}},
Response),
GtpC;

validate_response(create_session_request, missing_ie, Response, GtpC) ->
validate_seq_no(Response, GtpC),
validate_teid(Response, GtpC),
?match(#gtp{type = create_session_response,
ie = #{{v2_cause,0} := #v2_cause{v2_cause = mandatory_ie_missing}}},
Response),
GtpC;

validate_response(create_session_request, aaa_reject, Response, GtpC) ->
validate_seq_no(Response, GtpC),
validate_teid(Response, GtpC),
Expand All @@ -840,14 +857,22 @@ validate_response(create_session_request, overload, Response, GtpC) ->
validate_seq_no(Response, GtpC),

%% this is debatable, but decoding the request would require even more resources.
%% validate_teid(Response, GtpC),
validate_teid(Response, 0),

?match(#gtp{type = create_session_response,
ie = #{{v2_cause,0} := #v2_cause{v2_cause = no_resources_available}}},
Response),
GtpC;

validate_response(create_session_request, reject_new, Response, GtpC) ->
validate_seq_no(Response, GtpC),
validate_teid(Response, GtpC),

?match(#gtp{type = create_session_response,
ie = #{{v2_cause,0} := #v2_cause{v2_cause = no_resources_available}}},
Response),
GtpC;

validate_response(create_session_request, no_resources_available, Response, GtpC) ->
validate_seq_no(Response, GtpC),
validate_teid(Response, GtpC),
Expand Down
9 changes: 9 additions & 0 deletions test/ergw_saegw_test_lib.erl
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,15 @@ validate_response(create_session_request, overload, Response, GtpC) ->
Response),
GtpC;

validate_response(create_session_request, reject_new, Response, GtpC) ->
validate_seq_no(Response, GtpC),
validate_teid(Response, GtpC),

?match(#gtp{type = create_session_response,
ie = #{{v2_cause,0} := #v2_cause{v2_cause = no_resources_available}}},
Response),
GtpC;

validate_response(create_session_request, invalid_apn, Response, GtpC) ->
validate_seq_no(Response, GtpC),
validate_teid(Response, GtpC),
Expand Down
4 changes: 2 additions & 2 deletions test/ggsn_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,7 @@ create_pdp_context_request_accept_new() ->
[{doc, "Check the accept_new = false can block new contexts"}].
create_pdp_context_request_accept_new(Config) ->
?equal(ergw:system_info(accept_new, false), true),
create_pdp_context(overload, Config),
create_pdp_context(reject_new, Config),
?equal(ergw:system_info(accept_new, true), false),

?equal([], outstanding_requests()),
Expand Down Expand Up @@ -993,7 +993,7 @@ path_failure(Config) ->
CtxKey = #context_key{socket = 'irx', id = {imsi, ?'IMSI', 5}},
{GtpC, _, _} = create_pdp_context(Config),

{_Handler, CtxPid} = gtp_context_reg:lookup(CtxKey),
{_, CtxPid} = gtp_context_reg:lookup(CtxKey),
#{left_tunnel := #tunnel{socket = CSocket}} = gtp_context:info(CtxPid),

ClientIP = proplists:get_value(client_ip, Config),
Expand Down
18 changes: 9 additions & 9 deletions test/ggsn_proxy_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,7 @@ create_pdp_context_request_accept_new() ->
[{doc, "Check the accept_new = false can block new connections"}].
create_pdp_context_request_accept_new(Config) ->
?equal(ergw:system_info(accept_new, false), true),
create_pdp_context(overload, Config),
create_pdp_context(reject_new, Config),
?equal(ergw:system_info(accept_new, true), false),

?equal([], outstanding_requests()),
Expand Down Expand Up @@ -1016,7 +1016,7 @@ ggsn_broken_recovery(Config) ->
CtxKey = #context_key{socket = 'irx', id = {imsi, ?'IMSI', 5}},
{GtpC, _, _} = create_pdp_context(Config),

{_Handler, CtxPid} = gtp_context_reg:lookup(CtxKey),
{_, CtxPid} = gtp_context_reg:lookup(CtxKey),
#{right_tunnel := #tunnel{socket = CSocket}} = gtp_context:info(CtxPid),

FinalGSN = proplists:get_value(final_gsn, Config),
Expand Down Expand Up @@ -1055,7 +1055,7 @@ path_failure_to_ggsn(Config) ->

{GtpC, _, _} = create_pdp_context(Config),

{_Handler, CtxPid} = gtp_context_reg:lookup(CtxKey),
{_, CtxPid} = gtp_context_reg:lookup(CtxKey),
#{right_tunnel := #tunnel{socket = CSocket}} = gtp_context:info(CtxPid),

FinalGSN = proplists:get_value(final_gsn, Config),
Expand Down Expand Up @@ -1112,7 +1112,7 @@ path_failure_to_ggsn_and_restore(Config) ->

{GtpC, _, _} = create_pdp_context(Config),

{_Handler, CtxPid} = gtp_context_reg:lookup(CtxKey),
{_, CtxPid} = gtp_context_reg:lookup(CtxKey),
#{right_tunnel := #tunnel{socket = CSocket}} = gtp_context:info(CtxPid),

FinalGSN = proplists:get_value(final_gsn, Config),
Expand Down Expand Up @@ -1174,7 +1174,7 @@ path_failure_to_sgsn(Config) ->
CtxKey = #context_key{socket = 'irx', id = {imsi, ?'IMSI', 5}},
{GtpC, _, _} = create_pdp_context(Config),

{_Handler, CtxPid} = gtp_context_reg:lookup(CtxKey),
{_, CtxPid} = gtp_context_reg:lookup(CtxKey),
#{left_tunnel := #tunnel{socket = CSocket}} = gtp_context:info(CtxPid),

ClientIP = proplists:get_value(client_ip, Config),
Expand Down Expand Up @@ -1504,7 +1504,7 @@ error_indication_ggsn2sgsn(Config) ->

{GtpC, _, _} = create_pdp_context(Config),

{_Handler, CtxPid} = gtp_context_reg:lookup(CtxKey),
{_, CtxPid} = gtp_context_reg:lookup(CtxKey),
true = is_pid(CtxPid),
#{bearer := #{right := RightBearer}} = gtp_context:info(CtxPid),

Expand Down Expand Up @@ -1570,7 +1570,7 @@ update_pdp_context_request_ra_update(Config) ->
RemoteCtxKey = #context_key{socket = 'remote-irx', id = {imsi, ?'PROXY-IMSI', 5}},

{GtpC1, _, _} = create_pdp_context(Config),
{_Handler, CtxPid} = gtp_context_reg:lookup(RemoteCtxKey),
{_, CtxPid} = gtp_context_reg:lookup(RemoteCtxKey),
#{left_tunnel := LeftTunnel1, bearer := #{left := LeftBearer1}} = gtp_context:info(CtxPid),

{GtpC2, _, _} = update_pdp_context(ra_update, GtpC1),
Expand Down Expand Up @@ -1599,7 +1599,7 @@ update_pdp_context_request_tei_update(Config) ->
RemoteCtxKey = #context_key{socket = 'remote-irx', id = {imsi, ?'PROXY-IMSI', 5}},

{GtpC1, _, _} = create_pdp_context(Config),
{_Handler, CtxPid} = gtp_context_reg:lookup(RemoteCtxKey),
{_, CtxPid} = gtp_context_reg:lookup(RemoteCtxKey),
#{left_tunnel := LeftTunnel1, bearer := #{left := LeftBearer1}} = gtp_context:info(CtxPid),

{_Handler, ProxyCtxPid} = gtp_context_reg:lookup(CtxKey),
Expand Down Expand Up @@ -1667,7 +1667,7 @@ update_pdp_context_request_broken_recovery(Config) ->
meck:passthrough([ReqKey, Request, Response])
end),
{GtpC1, _, _} = create_pdp_context(Config),
{_Handler, CtxPid} = gtp_context_reg:lookup(RemoteCtxKey),
{_, CtxPid} = gtp_context_reg:lookup(RemoteCtxKey),
#{left_tunnel := LeftTunnel1, bearer := #{left := LeftBearer1}} = gtp_context:info(CtxPid),

{GtpC2, _, _} = update_pdp_context(simple, GtpC1),
Expand Down
14 changes: 12 additions & 2 deletions test/pgw_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,7 @@ common() ->
[invalid_gtp_pdu,
invalid_gtp_version,
apn_lookup,
create_session_request_missing_sender_teid,
create_session_request_missing_ie,
create_session_request_aaa_reject,
create_session_request_gx_fail,
Expand Down Expand Up @@ -1032,6 +1033,15 @@ invalid_gtp_version(Config) ->
meck_validate(Config),
ok.

%%--------------------------------------------------------------------
create_session_request_missing_sender_teid() ->
[{doc, "Check that Create Session Request IE validation works"}].
create_session_request_missing_sender_teid(Config) ->
create_session(missing_sender_teid, Config),

meck_validate(Config),
ok.

%%--------------------------------------------------------------------
create_session_request_missing_ie() ->
[{doc, "Check that Create Session Request IE validation works"}].
Expand Down Expand Up @@ -1170,7 +1180,7 @@ create_session_request_accept_new() ->
[{doc, "Check the accept_new = false can block new session"}].
create_session_request_accept_new(Config) ->
?equal(ergw:system_info(accept_new, false), true),
create_session(overload, Config),
create_session(reject_new, Config),
?equal(ergw:system_info(accept_new, true), false),

meck_validate(Config),
Expand Down Expand Up @@ -1266,7 +1276,7 @@ path_failure(Config) ->

{GtpC, _, _} = create_session(Config),

{_Handler, CtxPid} = gtp_context_reg:lookup(CtxKey),
{_, CtxPid} = gtp_context_reg:lookup(CtxKey),
#{left_tunnel := #tunnel{socket = CSocket}} = gtp_context:info(CtxPid),

ClientIP = proplists:get_value(client_ip, Config),
Expand Down
18 changes: 9 additions & 9 deletions test/pgw_proxy_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,7 @@ create_session_request_accept_new() ->
[{doc, "Check the accept_new = false can block new session"}].
create_session_request_accept_new(Config) ->
?equal(ergw:system_info(accept_new, false), true),
create_session(overload, Config),
create_session(reject_new, Config),
?equal(ergw:system_info(accept_new, true), false),

?equal([], outstanding_requests()),
Expand Down Expand Up @@ -1118,7 +1118,7 @@ path_failure_to_pgw(Config) ->

{GtpC, _, _} = create_session(Config),

{_Handler, CtxPid} = gtp_context_reg:lookup(CtxKey),
{_, CtxPid} = gtp_context_reg:lookup(CtxKey),
#{right_tunnel := #tunnel{socket = CSocket}} = gtp_context:info(CtxPid),

FinalGSN = proplists:get_value(final_gsn, Config),
Expand Down Expand Up @@ -1173,7 +1173,7 @@ path_failure_to_pgw_and_restore(Config) ->

{GtpC, _, _} = create_session(Config),

{_Handler, CtxPid} = gtp_context_reg:lookup(CtxKey),
{_, CtxPid} = gtp_context_reg:lookup(CtxKey),
#{right_tunnel := #tunnel{socket = CSocket}} = gtp_context:info(CtxPid),

FinalGSN = proplists:get_value(final_gsn, Config),
Expand Down Expand Up @@ -1237,7 +1237,7 @@ path_failure_to_sgw(Config) ->

{GtpC, _, _} = create_session(Config),

{_Handler, CtxPid} = gtp_context_reg:lookup(CtxKey),
{_, CtxPid} = gtp_context_reg:lookup(CtxKey),
#{left_tunnel := #tunnel{socket = CSocket}} = gtp_context:info(CtxPid),

ClientIP = proplists:get_value(client_ip, Config),
Expand Down Expand Up @@ -1827,7 +1827,7 @@ error_indication_pgw2sgw(Config) ->

{GtpC, _, _} = create_session(Config),

{_Handler, CtxPid} = gtp_context_reg:lookup(CtxKey),
{_, CtxPid} = gtp_context_reg:lookup(CtxKey),
true = is_pid(CtxPid),
#{bearer := #{right := RightBearer}} = gtp_context:info(CtxPid),

Expand Down Expand Up @@ -1894,7 +1894,7 @@ modify_bearer_request_ra_update(Config) ->

{GtpC1, _, _} = create_session(Config),

{_Handler, CtxPid} = gtp_context_reg:lookup(RemoteCtxKey),
{_, CtxPid} = gtp_context_reg:lookup(RemoteCtxKey),
#{left_tunnel := LeftTunnel1, bearer := #{left := LeftBearer1}} = gtp_context:info(CtxPid),

{GtpC2, _, _} = modify_bearer(ra_update, GtpC1),
Expand Down Expand Up @@ -1924,7 +1924,7 @@ modify_bearer_request_tei_update(Config) ->

{GtpC1, _, _} = create_session(Config),

{_Handler, CtxPid} = gtp_context_reg:lookup(RemoteCtxKey),
{_, CtxPid} = gtp_context_reg:lookup(RemoteCtxKey),
#{left_tunnel := LeftTunnel1, bearer := #{left := LeftBearer1}} = gtp_context:info(CtxPid),

{_Handler, ProxyCtxPid} = gtp_context_reg:lookup(CtxKey),
Expand Down Expand Up @@ -2416,7 +2416,7 @@ interop_sgsn_to_sgw(Config) ->

{GtpC1, _, _} = ergw_ggsn_test_lib:create_pdp_context(Config),

{_Handler, CtxPid} = gtp_context_reg:lookup(RemoteCtxKey),
{_, CtxPid} = gtp_context_reg:lookup(RemoteCtxKey),
#{left_tunnel := LeftTunnel1, bearer := #{left := LeftBearer1}} = gtp_context:info(CtxPid),

check_contexts_metric(v1, 3, 1),
Expand Down Expand Up @@ -2468,7 +2468,7 @@ interop_sgw_to_sgsn(Config) ->

{GtpC1, _, _} = create_session(Config),

{_Handler, CtxPid} = gtp_context_reg:lookup(RemoteCtxKey),
{_, CtxPid} = gtp_context_reg:lookup(RemoteCtxKey),
#{left_tunnel := LeftTunnel1, bearer := #{left := LeftBearer1}} = gtp_context:info(CtxPid),

check_contexts_metric(v1, 0, 0),
Expand Down
2 changes: 1 addition & 1 deletion test/saegw_s11_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@ create_session_request_accept_new() ->
[{doc, "Check the accept_new = false can block new session"}].
create_session_request_accept_new(Config) ->
?equal(ergw:system_info(accept_new, false), true),
create_session(overload, Config),
create_session(reject_new, Config),
?equal(ergw:system_info(accept_new, true), false),

meck_validate(Config),
Expand Down