pespin has submitted this change. (
https://gerrit.osmocom.org/c/erlang/osmo-epdg/+/35904?usp=email )
Change subject: Keep gtp2c specificities in its module file
......................................................................
Keep gtp2c specificities in its module file
Change-Id: I03cfe86723e881013a3a745eb81f6d0d8b9cfe94
---
A include/conv.hrl
M src/conv.erl
M src/epdg_gtpc_s2b.erl
M src/epdg_ue_fsm.erl
M src/gsup_server.erl
5 files changed, 83 insertions(+), 15 deletions(-)
Approvals:
pespin: Looks good to me, approved
Jenkins Builder: Verified
diff --git a/include/conv.hrl b/include/conv.hrl
new file mode 100644
index 0000000..1284d3b
--- /dev/null
+++ b/include/conv.hrl
@@ -0,0 +1,39 @@
+% (C) 2023 by sysmocom
+%
+% All Rights Reserved
+%
+% This program is free software; you can redistribute it and/or modify
+% it under the terms of the GNU Affero General Public License as
+% published by the Free Software Foundation; either version 3 of the
+% License, or (at your option) any later version.
+%
+% This program is distributed in the hope that it will be useful,
+% but WITHOUT ANY WARRANTY; without even the implied warranty of
+% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+% GNU General Public License for more details.
+%
+% You should have received a copy of the GNU Affero General Public License
+% along with this program. If not, see <http://www.gnu.org/licenses/>.
+%
+% Additional Permission under GNU AGPL version 3 section 7:
+%
+% If you modify this Program, or any covered work, by linking or
+% combining it with runtime libraries of Erlang/OTP as released by
+% Ericsson on
http://www.erlang.org (or a modified version of these
+% libraries), containing parts covered by the terms of the Erlang Public
+% License (
http://www.erlang.org/EPLICENSE), the licensors of this
+% Program grant you additional permission to convey the resulting work
+% without the need to license the runtime libraries of Erlang/OTP under
+% the GNU Affero General Public License. Corresponding Source for a
+% non-source form of such a combination shall include the source code
+% for the parts of the runtime libraries of Erlang/OTP used as well as
+% that of the covered work.
+%
+-hrl_name('conv.hrl').
+
+-record(epdg_eua, {
+ type_nr :: non_neg_integer(),
+ ipv4 :: binary(),
+ ipv6 :: binary()
+}).
+
diff --git a/src/conv.erl b/src/conv.erl
index 30365cc..a041847 100644
--- a/src/conv.erl
+++ b/src/conv.erl
@@ -34,9 +34,11 @@
-author('Pau Espin Pedrol <pespin(a)sysmocom.de>')>').
-include_lib("osmo_gsup/include/gsup_protocol.hrl").
+-include_lib("gtplib/include/gtp_packet.hrl").
-include_lib("gtp_utils.hrl").
+-include_lib("conv.hrl").
--export([cause_gtp2gsup/1]).
+-export([cause_gtp2gsup/1, gtp2_paa_to_epdg_eua/1, epdg_eua_to_gsup_pdp_address/1]).
-spec cause_gtp2gsup(integer()) -> integer().
@@ -51,3 +53,23 @@
cause_gtp2gsup(?GTP2_CAUSE_MANDATORY_IE_INCORRECT) -> ?GSUP_CAUSE_INV_MAND_INFO;
cause_gtp2gsup(?GTP2_CAUSE_MANDATORY_IE_MISSING) -> ?GSUP_CAUSE_INV_MAND_INFO;
cause_gtp2gsup(_) -> ?GSUP_CAUSE_PROTO_ERR_UNSPEC.
+
+
+gtp2_paa_to_epdg_eua(#v2_pdn_address_allocation{type = ipv4, address = Addr}) ->
+ #epdg_eua{type_nr = ?GTP_PDP_ADDR_TYPE_NR_IPv4,
+ ipv4 = Addr};
+gtp2_paa_to_epdg_eua(#v2_pdn_address_allocation{type = ipv6, address = Addr}) ->
+ #epdg_eua{type_nr = ?GTP_PDP_ADDR_TYPE_NR_IPv6,
+ ipv6 = Addr}.
+%TODO: IPv4v6
+
+epdg_eua_to_gsup_pdp_address(#epdg_eua{type_nr = ?GTP_PDP_ADDR_TYPE_NR_IPv4, ipv4 =
Addr}) ->
+ #{pdp_type_org => 1,
+ pdp_type_nr => ?GTP_PDP_ADDR_TYPE_NR_IPv4,
+ address => #{ ipv4 => Addr}};
+
+epdg_eua_to_gsup_pdp_address(#epdg_eua{type_nr = ?GTP_PDP_ADDR_TYPE_NR_IPv6, ipv6 =
Addr}) ->
+#{pdp_type_org => 1,
+ pdp_type_nr => ?GTP_PDP_ADDR_TYPE_NR_IPv6,
+ address => #{ ipv6 => Addr}}.
+%TODO: IPv4v6
diff --git a/src/epdg_gtpc_s2b.erl b/src/epdg_gtpc_s2b.erl
index 0b76b6f..9acbefa 100644
--- a/src/epdg_gtpc_s2b.erl
+++ b/src/epdg_gtpc_s2b.erl
@@ -316,7 +316,12 @@
Sess1 = update_gtp_session_from_create_session_response(Resp, Sess0),
lager:info("s2b: Updated Session after create_session_response:
~p~n", [Sess1]),
State1 = update_gtp_session(Sess0, Sess1, State0),
- epdg_ue_fsm:received_gtpc_create_session_response(Sess0#gtp_session.pid, {ok,
Resp}),
+ % Do GTP specific msg parsing here, pass only relevant fields:
+ #{{v2_pdn_address_allocation,0} := Paa} = Resp#gtp.ie,
+ ResInfo = #{
+ eua => conv:gtp2_paa_to_epdg_eua(Paa)
+ },
+ epdg_ue_fsm:received_gtpc_create_session_response(Sess0#gtp_session.pid, {ok,
ResInfo}),
{noreply, State1}
end;
diff --git a/src/epdg_ue_fsm.erl b/src/epdg_ue_fsm.erl
index 9221c79..fa780e8 100644
--- a/src/epdg_ue_fsm.erl
+++ b/src/epdg_ue_fsm.erl
@@ -132,10 +132,10 @@
{error, Err}
end.
-received_gtpc_create_session_response(Pid, Msg) ->
- lager:info("ue_fsm received_gtpc_create_session_response ~p~n",
[Msg]),
+received_gtpc_create_session_response(Pid, Result) ->
+ lager:info("ue_fsm received_gtpc_create_session_response ~p~n",
[Result]),
try
- gen_statem:call(Pid, {received_gtpc_create_session_response, Msg})
+ gen_statem:call(Pid, {received_gtpc_create_session_response, Result})
catch
exit:Err ->
{error, Err}
diff --git a/src/gsup_server.erl b/src/gsup_server.erl
index 229f5db..065abb4 100644
--- a/src/gsup_server.erl
+++ b/src/gsup_server.erl
@@ -39,8 +39,8 @@
-include_lib("diameter_3gpp_ts29_273_swx.hrl").
-include_lib("osmo_ss7/include/ipa.hrl").
-include_lib("osmo_gsup/include/gsup_protocol.hrl").
--include_lib("gtplib/include/gtp_packet.hrl").
-include("gtp_utils.hrl").
+-include("conv.hrl").
-define(SERVER, ?MODULE).
@@ -156,16 +156,9 @@
lager:info("tunnel_response for ~p: ~p~n", [Imsi, Result]),
Socket = State#gsups_state.socket,
case Result of
- {ok, #gtp{version = v2, type = create_session_response}} ->
- {ok, CreateSessResp} = Result,
- IEs = CreateSessResp#gtp.ie,
- %%#{{v2_bearer_context,0} := BearerMap} = IEs,
- #{{v2_pdn_address_allocation,0} := Paa} = IEs,
- PdpAddress = #{pdp_type_org => 1,
- pdp_type_nr => ?GTP_PDP_ADDR_TYPE_NR_IPv4,
- address => #{ ipv4 => Paa#v2_pdn_address_allocation.address}},
+ {ok, #{eua := Eua}} ->
PdpInfo = #{pdp_context_id => 0,
- pdp_address => PdpAddress,
+ pdp_address => conv:epdg_eua_to_gsup_pdp_address(Eua),
access_point_name => "foobar.apn",
quality_of_service => <<0, 0, 0>>,
pdp_charging => 0},
--
To view, visit
https://gerrit.osmocom.org/c/erlang/osmo-epdg/+/35904?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings
Gerrit-Project: erlang/osmo-epdg
Gerrit-Branch: master
Gerrit-Change-Id: I03cfe86723e881013a3a745eb81f6d0d8b9cfe94
Gerrit-Change-Number: 35904
Gerrit-PatchSet: 2
Gerrit-Owner: pespin <pespin(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
Gerrit-MessageType: merged