From 027b7f983502483e0af5a22dd52f206c46a18698 Mon Sep 17 00:00:00 2001 From: Oliver Smith Date: Tue, 19 Nov 2019 15:25:42 +0100 Subject: osmo_mdns_sock_init: remove reuse_addr parameter There is no use case where it is useful to disallow binding on the same IP and port for mDNS with mslookup. Change-Id: I70500737f63531f748b94e11d5d6f7a7d6581f71 --- include/osmocom/mslookup/mdns_sock.h | 6 +++--- include/osmocom/mslookup/mslookup_client_mdns.h | 3 +-- src/mslookup/mdns_sock.c | 21 +++++++++++---------- src/mslookup/mslookup_client_mdns.c | 4 ++-- tests/mslookup/mslookup_client_mdns_test.c | 4 ++-- utils/osmo-mslookup-client.c | 2 +- 6 files changed, 20 insertions(+), 20 deletions(-) diff --git a/include/osmocom/mslookup/mdns_sock.h b/include/osmocom/mslookup/mdns_sock.h index cdda20a2..b4f30cc3 100644 --- a/include/osmocom/mslookup/mdns_sock.h +++ b/include/osmocom/mslookup/mdns_sock.h @@ -7,8 +7,8 @@ struct osmo_mdns_sock { struct addrinfo *ai; }; -struct osmo_mdns_sock *osmo_mdns_sock_init(void *ctx, const char *ip, unsigned int port, bool reuse_addr, - int (*cb)(struct osmo_fd *fd, unsigned int what), - void *data, unsigned int priv_nr); +struct osmo_mdns_sock *osmo_mdns_sock_init(void *ctx, const char *ip, unsigned int port, + int (*cb)(struct osmo_fd *fd, unsigned int what), + void *data, unsigned int priv_nr); int osmo_mdns_sock_send(const struct osmo_mdns_sock *mdns_sock, struct msgb *msg); void osmo_mdns_sock_cleanup(struct osmo_mdns_sock *mdns_sock); diff --git a/include/osmocom/mslookup/mslookup_client_mdns.h b/include/osmocom/mslookup/mslookup_client_mdns.h index 68ebd32f..d48642a1 100644 --- a/include/osmocom/mslookup/mslookup_client_mdns.h +++ b/include/osmocom/mslookup/mslookup_client_mdns.h @@ -12,7 +12,6 @@ struct osmo_mslookup_client_method; #define OSMO_MSLOOKUP_MDNS_PORT 4266 struct osmo_mslookup_client_method *osmo_mslookup_client_add_mdns(struct osmo_mslookup_client *client, const char *ip, - uint16_t port, bool reuse_addr, - int initial_packet_id); + uint16_t port, int initial_packet_id); const struct osmo_sockaddr_str *osmo_mslookup_client_method_mdns_get_bind_addr(struct osmo_mslookup_client_method *dns_method); diff --git a/src/mslookup/mdns_sock.c b/src/mslookup/mdns_sock.c index 902ead83..4a964dbd 100644 --- a/src/mslookup/mdns_sock.c +++ b/src/mslookup/mdns_sock.c @@ -16,9 +16,9 @@ #include /* returns 0 on success, -1 on error */ -struct osmo_mdns_sock *osmo_mdns_sock_init(void *ctx, const char *ip, unsigned int port, bool reuse_addr, - int (*cb)(struct osmo_fd *fd, unsigned int what), - void *data, unsigned int priv_nr) +struct osmo_mdns_sock *osmo_mdns_sock_init(void *ctx, const char *ip, unsigned int port, + int (*cb)(struct osmo_fd *fd, unsigned int what), + void *data, unsigned int priv_nr) { struct osmo_mdns_sock *ret; int sock, rc; @@ -65,13 +65,14 @@ struct osmo_mdns_sock *osmo_mdns_sock_init(void *ctx, const char *ip, unsigned i goto error; } - /* Tests: client and server listen on same IP and port */ - if (reuse_addr) { - rc = setsockopt(sock,SOL_SOCKET,SO_REUSEADDR, (char *)&y, sizeof(y)); - if (rc == -1) { - LOGP(DLMSLOOKUP, LOGL_ERROR, "osmo_mdns_sock_init: setsockopt: %s\n", strerror(errno)); - goto error; - } + /* Always allow binding the same IP and port twice. This is needed in OsmoHLR (where the code becomes cleaner by + * just using a different socket for server and client code) and in the mslookup_client_mdns_test. Also for + * osmo-mslookup-client if it is running multiple times in parallel (i.e. two incoming calls almost at the same + * time need to be resolved with the simple dialplan example that just starts new processes). */ + rc = setsockopt(sock,SOL_SOCKET,SO_REUSEADDR, (char *)&y, sizeof(y)); + if (rc == -1) { + LOGP(DLMSLOOKUP, LOGL_ERROR, "osmo_mdns_sock_init: setsockopt: %s\n", strerror(errno)); + goto error; } /* Bind and register osmo_fd callback */ diff --git a/src/mslookup/mslookup_client_mdns.c b/src/mslookup/mslookup_client_mdns.c index 45bbf3d9..d61fd14e 100644 --- a/src/mslookup/mslookup_client_mdns.c +++ b/src/mslookup/mslookup_client_mdns.c @@ -146,7 +146,7 @@ static void mdns_method_destruct(struct osmo_mslookup_client_method *method) * ID, but all query parameters (service type, ID, ID type), to determine if a reply is * relevant. */ struct osmo_mslookup_client_method *osmo_mslookup_client_add_mdns(struct osmo_mslookup_client *client, const char *ip, - uint16_t port, bool reuse_addr, int initial_packet_id) + uint16_t port, int initial_packet_id) { struct osmo_mdns_method_state *state; struct osmo_mslookup_client_method *m; @@ -173,7 +173,7 @@ struct osmo_mslookup_client_method *osmo_mslookup_client_add_mdns(struct osmo_ms state->client = client; - state->mc = osmo_mdns_sock_init(state, ip, port, reuse_addr, mdns_method_recv, state, 0); + state->mc = osmo_mdns_sock_init(state, ip, port, mdns_method_recv, state, 0); if (!state->mc) goto error_cleanup; diff --git a/tests/mslookup/mslookup_client_mdns_test.c b/tests/mslookup/mslookup_client_mdns_test.c index 3d9de05d..2a781ba0 100644 --- a/tests/mslookup/mslookup_client_mdns_test.c +++ b/tests/mslookup/mslookup_client_mdns_test.c @@ -64,7 +64,7 @@ static int server_recv(struct osmo_fd *osmo_fd, unsigned int what) static void server_init() { fprintf(stderr, "%s\n", __func__); - server_mc = osmo_mdns_sock_init(ctx, TEST_IP, TEST_PORT, true, server_recv, NULL, 0); + server_mc = osmo_mdns_sock_init(ctx, TEST_IP, TEST_PORT, server_recv, NULL, 0); OSMO_ASSERT(server_mc); } @@ -84,7 +84,7 @@ static void client_init() fprintf(stderr, "%s\n", __func__); client = osmo_mslookup_client_new(ctx); OSMO_ASSERT(client); - client_method = osmo_mslookup_client_add_mdns(client, TEST_IP, TEST_PORT, true, 1337); + client_method = osmo_mslookup_client_add_mdns(client, TEST_IP, TEST_PORT, 1337); OSMO_ASSERT(client_method); } diff --git a/utils/osmo-mslookup-client.c b/utils/osmo-mslookup-client.c index 50f2a0c0..3754a192 100644 --- a/utils/osmo-mslookup-client.c +++ b/utils/osmo-mslookup-client.c @@ -627,7 +627,7 @@ int main(int argc, char **argv) if (!globals.mslookup_client || !osmo_mslookup_client_add_mdns(globals.mslookup_client, cmdline_opts.mdns_addr.ip, cmdline_opts.mdns_addr.port, - true, -1)) { + -1)) { print_error("Failed to start mDNS client\n"); goto program_exit; } -- cgit v1.2.3