abis/close: Deliver S_L_INP_TEI_DN when closing the socket

* HSL/IPA had different socket closing code for the same thing,
  create one method for it.
* Both methods tried to send an event but as we are on the close
  path the sign_link was already removed from the list and the
  input event sending method couldn't find the sign_link using the
  sapi/tei provided.
diff --git a/src/e1_input.c b/src/e1_input.c
index 1bd4744..957b74c 100644
--- a/src/e1_input.c
+++ b/src/e1_input.c
@@ -645,27 +645,46 @@
 	return msg;
 }
 
-/* called by driver in case some kind of link state event */
-int e1inp_event(struct e1inp_ts *ts, int evt, uint8_t tei, uint8_t sapi)
+static int e1inp_int_snd_event(struct e1inp_ts *ts,
+			       struct e1inp_sign_link *link, int evt)
 {
-	struct e1inp_sign_link *link;
 	struct input_signal_data isd;
-
-	link = e1inp_lookup_sign_link(ts, tei, sapi);
-	if (!link)
-		return -EINVAL;
-
 	isd.line = ts->line;
 	isd.link_type = link->type;
 	isd.trx = link->trx;
-	isd.tei = tei;
-	isd.sapi = sapi;
+	isd.tei = link->tei;
+	isd.sapi = link->sapi;
 
 	/* report further upwards */
 	osmo_signal_dispatch(SS_L_INPUT, evt, &isd);
 	return 0;
 }
 
+
+/* called by driver in case some kind of link state event */
+int e1inp_event(struct e1inp_ts *ts, int evt, uint8_t tei, uint8_t sapi)
+{
+	struct e1inp_sign_link *link;
+
+	link = e1inp_lookup_sign_link(ts, tei, sapi);
+	if (!link)
+		return -EINVAL;
+	return e1inp_int_snd_event(ts, link, evt);
+}
+
+void e1inp_close_socket(struct e1inp_ts *ts,
+			struct e1inp_sign_link *sign_link,
+			struct osmo_fd *bfd)
+{
+	e1inp_int_snd_event(ts, sign_link, S_L_INP_TEI_DN);
+	/* the first e1inp_sign_link_destroy call closes the socket. */
+	if (bfd->fd != -1) {
+		osmo_fd_unregister(bfd);
+		close(bfd->fd);
+		bfd->fd = -1;
+	}
+}
+
 /* register a driver with the E1 core */
 int e1inp_driver_register(struct e1inp_driver *drv)
 {
diff --git a/src/input/hsl.c b/src/input/hsl.c
index 408228e..3dcba1d 100644
--- a/src/input/hsl.c
+++ b/src/input/hsl.c
@@ -307,15 +307,9 @@
 
 static void hsl_close(struct e1inp_sign_link *sign_link)
 {
-	struct e1inp_ts *ts = sign_link->ts;
-	struct osmo_fd *bfd = &ts->driver.ipaccess.fd;
-	e1inp_event(ts, S_L_INP_TEI_DN, sign_link->tei, sign_link->sapi);
-	/* the first e1inp_sign_link_destroy call closes the socket. */
-	if (bfd->fd != -1) {
-		osmo_fd_unregister(bfd);
-		close(bfd->fd);
-		bfd->fd = -1;
-	}
+	struct e1inp_ts *e1i_ts = sign_link->ts;
+	struct osmo_fd *bfd = &e1i_ts->driver.ipaccess.fd;
+	return e1inp_close_socket(e1i_ts, sign_link, bfd);
 }
 
 static int hsl_line_update(struct e1inp_line *line);
diff --git a/src/input/ipaccess.c b/src/input/ipaccess.c
index 2621290..6ae9ab3 100644
--- a/src/input/ipaccess.c
+++ b/src/input/ipaccess.c
@@ -464,10 +464,7 @@
 {
 	struct e1inp_ts *e1i_ts = sign_link->ts;
 	struct osmo_fd *bfd = &e1i_ts->driver.ipaccess.fd;
-	e1inp_event(e1i_ts, S_L_INP_TEI_DN, sign_link->tei, sign_link->sapi);
-	osmo_fd_unregister(bfd);
-	close(bfd->fd);
-	bfd->fd = -1;
+	return e1inp_close_socket(e1i_ts, sign_link, bfd);
 }
 
 static void timeout_ts1_write(void *data)