Introduce the ability to bind a QIPCRTR family socket to a specific...
endpoint. When a socket is bound, only messages from the bound
endpoint can be received, and any messages sent from the socket are
by default directed to the bound endpoint. Clients can bind a socket
by using the setsockopt system call with the QRTR_BIND_ENDPOINT option
set to the desired endpoint binding.
A previously set binding can be reset by setting QRTR_BIND_ENDPOINT
option to zero. This behavior matches that of SO_BINDTOIFINDEX.
This functionality is useful for clients that need to communicate
with a specific device (i.e. endpoint), such as a PCIe-based 5G modem,
and are not interested in messages from other endpoints / nodes.
Signed-off-by: Denis Kenzior <denkenz@xxxxxxxxx>
Reviewed-by: Marcel Holtmann <marcel@xxxxxxxxxxxx>
Reviewed-by: Andy Gross <agross@xxxxxxxxxx>
---
include/uapi/linux/qrtr.h | 1 +
net/qrtr/af_qrtr.c | 54 ++++++++++++++++++++++++++++-----------
2 files changed, 40 insertions(+), 15 deletions(-)
@@ -1313,6 +1331,9 @@ static int qrtr_setsockopt(struct socket *sock, int level, int optname,
case QRTR_REPORT_ENDPOINT:
assign_bit(QRTR_F_REPORT_ENDPOINT, &ipc->flags, val);
break;
+ case QRTR_BIND_ENDPOINT:
+ ipc->bound_endpoint = val;
+ break;
default:
rc = -ENOPROTOOPT;
}
@@ -1346,6 +1367,9 @@ static int qrtr_getsockopt(struct socket *sock, int level, int optname,
case QRTR_REPORT_ENDPOINT:
val = test_bit(QRTR_F_REPORT_ENDPOINT, &ipc->flags);
break;
+ case QRTR_BIND_ENDPOINT:
+ val = ipc->bound_endpoint;
+ break;
default:
rc = -ENOPROTOOPT;
}