From 9e137aff1d8b0891219b6766c935f710ceab9676 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Fri, 11 Sep 2020 15:18:13 +0200 Subject: [PATCH] make sure a given timeslot can only be opened once (by default) Align the behavior of osmo-e1d with that of DAHDI: If a timeslot is opened once, it cannot be opened again by anyone until it is closed by the current owner. This way we'd have the same failure semantics in DAHDI vs. osmo-e1d, which is very useful in case of misconfiguration when osmo-bsc + osmo-mgw would "fight" over a timeslot. Add a osmo_e1dp_client_ts_open_force() function that allows to override and get back the original behavior. Closes: OS#4654 Change-Id: Ib25adf827ec41e74de15e0e4fdcfc9bcc9a32e58 --- TODO-RELEASE | 1 + include/osmocom/e1d/proto.h | 3 +++ include/osmocom/e1d/proto_clnt.h | 3 +++ src/ctl.c | 12 ++++++++++-- src/proto_clnt.c | 23 ++++++++++++++++++++--- 5 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 TODO-RELEASE diff --git a/TODO-RELEASE b/TODO-RELEASE new file mode 100644 index 0000000..27e2d93 --- /dev/null +++ b/TODO-RELEASE @@ -0,0 +1 @@ +* bump protocol version as 'flags' member was added to osmo_d1dp_ts_config diff --git a/include/osmocom/e1d/proto.h b/include/osmocom/e1d/proto.h index 5628e31..6457f14 100644 --- a/include/osmocom/e1d/proto.h +++ b/include/osmocom/e1d/proto.h @@ -81,6 +81,8 @@ enum osmo_e1dp_ts_mode { E1DP_TSMODE_HDLCFCS = 0x11, }; +/* osmo_e1dp_ts_config.flags */ +#define E1DP_TS_OPEN_F_FORCE 0x80 /* the idea here is to use the first byte as a version number, to prevent incompatible * clients from connecting to e1d */ @@ -118,6 +120,7 @@ struct osmo_e1dp_line_info { struct osmo_e1dp_ts_config { uint8_t mode; + uint8_t flags; uint16_t read_bufsize; } __attribute__((packed)); diff --git a/include/osmocom/e1d/proto_clnt.h b/include/osmocom/e1d/proto_clnt.h index 5a4f965..1473716 100644 --- a/include/osmocom/e1d/proto_clnt.h +++ b/include/osmocom/e1d/proto_clnt.h @@ -46,3 +46,6 @@ int osmo_e1dp_client_line_config(struct osmo_e1dp_client *clnt, int osmo_e1dp_client_ts_open(struct osmo_e1dp_client *clnt, uint8_t intf, uint8_t line, uint8_t ts, enum osmo_e1dp_ts_mode mode, uint16_t read_bufsize); +int osmo_e1dp_client_ts_open_force(struct osmo_e1dp_client *clnt, + uint8_t intf, uint8_t line, uint8_t ts, + enum osmo_e1dp_ts_mode mode, uint16_t read_bufsize); diff --git a/src/ctl.c b/src/ctl.c index 8da21fd..8a0e339 100644 --- a/src/ctl.c +++ b/src/ctl.c @@ -395,8 +395,16 @@ _e1d_ctl_ts_open(void *data, struct msgb *msgb, struct msgb *rmsgb, int *rfd) return 0; } - /* If already open, close previous */ - e1_ts_stop(ts); + if (ts->fd >= 0) { + /* we only force-reopen a busy timeslot if the flag is set */ + if (cfg->flags & E1DP_TS_OPEN_F_FORCE) { + e1_ts_stop(ts); + } else { + LOGPTS(ts, DE1D, LOGL_ERROR, + "Timeslot already open, rejecting re-open without F_FORCE\n"); + return 0; + } + } /* Init */ ret = _e1d_ts_start(ts, mode, cfg->read_bufsize); diff --git a/src/proto_clnt.c b/src/proto_clnt.c index 69c7234..0f6e367 100644 --- a/src/proto_clnt.c +++ b/src/proto_clnt.c @@ -315,10 +315,10 @@ osmo_e1dp_client_line_config(struct osmo_e1dp_client *clnt, return 0; } -int -osmo_e1dp_client_ts_open(struct osmo_e1dp_client *clnt, +static int +_client_ts_open(struct osmo_e1dp_client *clnt, uint8_t intf, uint8_t line, uint8_t ts, - enum osmo_e1dp_ts_mode mode, uint16_t read_bufsize) + enum osmo_e1dp_ts_mode mode, uint16_t read_bufsize, uint8_t flags) { struct msgb *msgb; struct osmo_e1dp_msg_hdr hdr; @@ -333,6 +333,7 @@ osmo_e1dp_client_ts_open(struct osmo_e1dp_client *clnt, memset(&cfg, 0x00, sizeof(struct osmo_e1dp_ts_config)); cfg.mode = mode; + cfg.flags = flags; cfg.read_bufsize = read_bufsize; tsfd = -1; @@ -348,3 +349,19 @@ osmo_e1dp_client_ts_open(struct osmo_e1dp_client *clnt, return tsfd; } + +int +osmo_e1dp_client_ts_open(struct osmo_e1dp_client *clnt, + uint8_t intf, uint8_t line, uint8_t ts, + enum osmo_e1dp_ts_mode mode, uint16_t read_bufsize) +{ + return _client_ts_open(clnt, intf, line, ts, mode, read_bufsize, 0); +} + +int +osmo_e1dp_client_ts_open_force(struct osmo_e1dp_client *clnt, + uint8_t intf, uint8_t line, uint8_t ts, + enum osmo_e1dp_ts_mode mode, uint16_t read_bufsize) +{ + return _client_ts_open(clnt, intf, line, ts, mode, read_bufsize, E1DP_TS_OPEN_F_FORCE); +}