Skip to content

Commit 91e7ac1

Browse files
alvasMancodebot
authored andcommitted
cu_cp: fix incorrect sctp parameters
1 parent 7e1681a commit 91e7ac1

File tree

3 files changed

+49
-16
lines changed

3 files changed

+49
-16
lines changed

include/srsran/support/io/sctp_socket.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,34 @@ class sctp_socket
7575
};
7676

7777
} // namespace srsran
78+
79+
namespace fmt {
80+
template <>
81+
struct formatter<srsran::sctp_socket_params> {
82+
template <typename ParseContext>
83+
auto parse(ParseContext& ctx)
84+
{
85+
return ctx.begin();
86+
}
87+
88+
template <typename FormatContext>
89+
auto format(const srsran::sctp_socket_params& cfg, FormatContext& ctx)
90+
{
91+
return format_to(ctx.out(),
92+
"if_name={} ai_family={} ai_socktype={} reuse_addr={} non_blockin_mode={} rx_timeout={} "
93+
"rto_initial={} rto_min={} rto_max={} init_max_attempts={} max_init_timeo={} no_delay={}",
94+
cfg.if_name,
95+
cfg.ai_family,
96+
cfg.ai_socktype,
97+
cfg.reuse_addr,
98+
cfg.non_blocking_mode,
99+
cfg.rx_timeout.count(),
100+
cfg.rto_initial,
101+
cfg.rto_min,
102+
cfg.rto_max,
103+
cfg.init_max_attempts,
104+
cfg.max_init_timeo,
105+
cfg.nodelay);
106+
}
107+
};
108+
} // namespace fmt

lib/ngap/gateways/n2_connection_client_factory.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ class n2_sctp_gateway_client : public n2_connection_client
232232
sctp_cfg.connect_address,
233233
sctp_cfg.connect_port,
234234
std::make_unique<sctp_to_n2_pdu_notifier>(std::move(cu_cp_rx_pdu_notifier), pcap_writer, logger));
235+
235236
if (sctp_sender == nullptr) {
236237
logger.error(
237238
"Failed to establish N2 TNL connection to AMF on {}:{}.\n", sctp_cfg.connect_address, sctp_cfg.connect_port);
@@ -275,12 +276,17 @@ srsran::srs_cu_cp::create_n2_connection_client(const n2_connection_client_config
275276
// Connection to AMF through SCTP.
276277
const auto& nw_mode = std::get<n2_connection_client_config::network>(params.mode);
277278
srsran::sctp_network_connector_config sctp_cfg;
278-
sctp_cfg.dest_name = "AMF";
279-
sctp_cfg.if_name = "N2";
280-
sctp_cfg.connect_address = nw_mode.amf_address;
281-
sctp_cfg.connect_port = nw_mode.amf_port;
282-
sctp_cfg.bind_address = nw_mode.bind_address;
283-
sctp_cfg.bind_interface = nw_mode.bind_interface;
284-
sctp_cfg.ppid = NGAP_PPID;
279+
sctp_cfg.dest_name = "AMF";
280+
sctp_cfg.if_name = "N2";
281+
sctp_cfg.connect_address = nw_mode.amf_address;
282+
sctp_cfg.connect_port = nw_mode.amf_port;
283+
sctp_cfg.bind_address = nw_mode.bind_address;
284+
sctp_cfg.bind_interface = nw_mode.bind_interface;
285+
sctp_cfg.rto_initial = nw_mode.rto_initial;
286+
sctp_cfg.rto_min = nw_mode.rto_min;
287+
sctp_cfg.rto_max = nw_mode.rto_max;
288+
sctp_cfg.init_max_attempts = nw_mode.init_max_attempts;
289+
sctp_cfg.max_init_timeo = nw_mode.max_init_timeo;
290+
sctp_cfg.ppid = NGAP_PPID;
285291
return std::make_unique<n2_sctp_gateway_client>(nw_mode.broker, sctp_cfg, params.pcap);
286292
}

lib/support/network/sctp_socket.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99
*/
1010

1111
#include "srsran/support/io/sctp_socket.h"
12+
#include "srsran/adt/optional.h"
1213
#include "srsran/srslog/srslog.h"
1314
#include "srsran/support/error_handling.h"
14-
#include "srsran/support/format_utils.h"
1515
#include "srsran/support/io/sockets.h"
16+
#include "srsran/support/srsran_assert.h"
1617
#include <fcntl.h>
1718
#include <netinet/in.h>
1819
#include <netinet/sctp.h>
@@ -31,10 +32,7 @@ bool sctp_subscribe_to_events(const unique_fd& fd)
3132
events.sctp_shutdown_event = 1;
3233
events.sctp_association_event = 1;
3334

34-
if (::setsockopt(fd.value(), IPPROTO_SCTP, SCTP_EVENTS, &events, sizeof(events)) != 0) {
35-
return false;
36-
}
37-
return true;
35+
return ::setsockopt(fd.value(), IPPROTO_SCTP, SCTP_EVENTS, &events, sizeof(events)) == 0;
3836
}
3937

4038
/// \brief Modify SCTP default parameters for quicker detection of broken links.
@@ -143,10 +141,7 @@ bool sctp_set_nodelay(const unique_fd& fd, std::optional<bool> nodelay)
143141
}
144142

145143
int optval = nodelay.value() ? 1 : 0;
146-
if (::setsockopt(fd.value(), IPPROTO_SCTP, SCTP_NODELAY, &optval, sizeof(optval)) != 0) {
147-
return false;
148-
}
149-
return true;
144+
return ::setsockopt(fd.value(), IPPROTO_SCTP, SCTP_NODELAY, &optval, sizeof(optval)) == 0;
150145
}
151146

152147
} // namespace
@@ -299,6 +294,7 @@ bool sctp_socket::set_non_blocking()
299294

300295
bool sctp_socket::set_sockopts(const sctp_socket_params& params)
301296
{
297+
logger.debug("Setting socket options. params=[{}]", params);
302298
if (not sctp_subscribe_to_events(sock_fd)) {
303299
logger.error(
304300
"{}: SCTP failed to be created. Cause: Subscribing to SCTP events failed: {}", if_name, strerror(errno));

0 commit comments

Comments
 (0)