connman.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: matthias.gerstner@suse.de
To: connman@lists.linux.dev
Subject: [PATCH 5/7] dnsproxy: support programmatic configuration of the default listen port
Date: Thu, 17 Feb 2022 12:31:11 +0100	[thread overview]
Message-ID: <20220217113113.24088-6-matthias.gerstner@suse.de> (raw)
In-Reply-To: <20220217113113.24088-1-matthias.gerstner@suse.de>

From: Matthias Gerstner <matthias.gerstner@suse.de>

This way a test instance of dnsproxy can be setup that listens on an
unprivileged port for easier testing as non-root.
---
 src/connman.h  |  1 +
 src/dnsproxy.c | 10 ++++++++--
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/connman.h b/src/connman.h
index 68176086..909b53ae 100644
--- a/src/connman.h
+++ b/src/connman.h
@@ -983,6 +983,7 @@ void __connman_dnsproxy_remove_listener(int index);
 int __connman_dnsproxy_append(int index, const char *domain, const char *server);
 int __connman_dnsproxy_remove(int index, const char *domain, const char *server);
 int __connman_dnsproxy_set_mdns(int index, bool enabled);
+void __connman_dnsproxy_set_listen_port(unsigned int port);
 
 int __connman_6to4_probe(struct connman_service *service);
 void __connman_6to4_remove(struct connman_ipconfig *ipconfig);
diff --git a/src/dnsproxy.c b/src/dnsproxy.c
index d04057fa..f862c788 100644
--- a/src/dnsproxy.c
+++ b/src/dnsproxy.c
@@ -223,6 +223,7 @@ static GHashTable *listener_table = NULL;
 static time_t next_refresh;
 static GHashTable *partial_tcp_req_table;
 static guint cache_timer = 0;
+static in_port_t dns_listen_port = 53;
 
 static guint16 get_id(void)
 {
@@ -3704,7 +3705,7 @@ static GIOChannel *get_listener(int family, int protocol, int index)
 	if (family == AF_INET6) {
 		memset(&s.sin6, 0, sizeof(s.sin6));
 		s.sin6.sin6_family = AF_INET6;
-		s.sin6.sin6_port = htons(53);
+		s.sin6.sin6_port = htons(dns_listen_port);
 		slen = sizeof(s.sin6);
 
 		if (__connman_inet_get_interface_address(index,
@@ -3721,7 +3722,7 @@ static GIOChannel *get_listener(int family, int protocol, int index)
 	} else if (family == AF_INET) {
 		memset(&s.sin, 0, sizeof(s.sin));
 		s.sin.sin_family = AF_INET;
-		s.sin.sin_port = htons(53);
+		s.sin.sin_port = htons(dns_listen_port);
 		slen = sizeof(s.sin);
 
 		if (__connman_inet_get_interface_address(index,
@@ -4050,3 +4051,8 @@ void __connman_dnsproxy_cleanup(void)
 	if (ipv6_resolve)
 		g_resolv_unref(ipv6_resolve);
 }
+
+void __connman_dnsproxy_set_listen_port(unsigned int port)
+{
+	dns_listen_port = port;
+}
-- 
2.34.1


  parent reply	other threads:[~2022-02-17 11:31 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-17 11:31 dnsproxy: some initial refactoring and integration test matthias.gerstner
2022-02-17 11:31 ` [PATCH 1/7] dnsproxy: remove unused domain parameter from `remove_server()` matthias.gerstner
2022-02-17 11:31 ` [PATCH 2/7] dnsproxy: remove unnecessarily shadowed variable matthias.gerstner
2022-02-17 11:31 ` [PATCH 3/7] dnsproxy: protocol_offset: remove error return case and return size_t matthias.gerstner
2022-02-21  8:49   ` Daniel Wagner
2022-02-17 11:31 ` [PATCH 4/7] .gitignore: also ignore backup configure script matthias.gerstner
2022-02-21  8:49   ` Daniel Wagner
2022-02-17 11:31 ` matthias.gerstner [this message]
2022-02-17 11:31 ` [PATCH 6/7] dnsproxy-test: support command line specification of dnsproxy port matthias.gerstner
2022-02-17 11:31 ` [PATCH 7/7] dnsproxy: add standalone test version of dnsproxy and a test script for it matthias.gerstner
2022-02-21  8:48   ` Daniel Wagner
2022-02-28 13:19     ` dnsproxy: some initial refactoring and integration test matthias.gerstner
2022-02-28 13:19       ` [PATCH] dnsproxy: add standalone test version of dnsproxy and a test script for it matthias.gerstner
2022-03-04  8:50         ` Daniel Wagner
2022-02-21  8:51 ` dnsproxy: some initial refactoring and integration test Daniel Wagner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220217113113.24088-6-matthias.gerstner@suse.de \
    --to=matthias.gerstner@suse.de \
    --cc=connman@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).