From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-06.pe-a.jellyfish.systems (out-06.pe-a.jellyfish.systems [198.54.127.66]) by passt.top (Postfix) with ESMTPS id 54BBC5A004F for ; Tue, 30 Jul 2024 08:01:56 +0200 (CEST) Received: from output-router-d5c465c44-45n78 (new-01-3.privateemail.com [66.29.159.56]) by pe-a.jellyfish.systems (Postfix) with ESMTPA id 4WY4PG2c5Jz4wFM; Tue, 30 Jul 2024 06:01:54 +0000 (UTC) Received: from MTA-11-1.privateemail.com (unknown [10.50.14.23]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by NEW-01-3.privateemail.com (Postfix) with ESMTPS id 4C113100588C; Tue, 30 Jul 2024 02:01:54 -0400 (EDT) Received: from mta-11.privateemail.com (localhost [127.0.0.1]) by mta-11.privateemail.com (Postfix) with ESMTP id 1D68818000AB; Tue, 30 Jul 2024 02:01:54 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=danishpraka.sh; s=default; t=1722319314; bh=1khoZVFGhjyJOPE8CP6KUXpIu88zb6PLJ9DfhvMacUU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nrKBw/kE/8kRE6iMilASE7xusdlPiQ6ZCAcwr5g6o0ZWY8p0JRwlor3k5k/ur3JAw kQW86Xlvj/31wyduHmGjkiIyu/VUhdu0FQ7QvFnhh8Rtw5072SqJXdPyZccV+4cMRH /yH+EaY0+4tygdlnVSf5vkc4XU844S/TCnTPuAXXX8gSIpEraPAm9QWiHTdwHLkznI kPrlNbP42xcm/r3ARuGgsmNx4psGY+KdZFYlM2ut9Miub+cleJoaJGTzI3eTLRkKYP Fz7EXIYv4sls9ufNj/n6IUfJFW3j/0xAJL8u+fxw3e5SI00zrqXgGWg8g4/mCQFKzp p097Q5/9NTV5w== Received: from localhost.localdomain (unknown [122.171.20.208]) by mta-11.privateemail.com (Postfix) with ESMTPA; Tue, 30 Jul 2024 02:01:50 -0400 (EDT) From: Danish Prakash To: passt-dev@passt.top, sbrivio@redhat.com Subject: [PATCH v2] pasta.c: modify hostname when detaching new namespace Date: Tue, 30 Jul 2024 11:31:23 +0530 Message-ID: <20240730060132.5522-1-contact@danishpraka.sh> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240520083343.10973-1-contact@danishpraka.sh> References: <20240520083343.10973-1-contact@danishpraka.sh> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Virus-Scanned: ClamAV using ClamSMTP Message-ID-Hash: ZWZ4AF4FZ22TRYKPC6H6APNSX5YOTBG6 X-Message-ID-Hash: ZWZ4AF4FZ22TRYKPC6H6APNSX5YOTBG6 X-MailFrom: contact@danishpraka.sh X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Danish Prakash X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: When invoking pasta without any arguments, it's difficult to tell whether we are in the new namespace or not leaving users a bit confused. This change modifies the host namespace to add a prefix "pasta-" to make it a bit more obvious. Signed-off-by: Danish Prakash --- pasta.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pasta.c b/pasta.c index 31e1e000ee1b..7ce502d3f299 100644 --- a/pasta.c +++ b/pasta.c @@ -50,6 +50,8 @@ #include "netlink.h" #include "log.h" +#define HOSTNAME_PREFIX "pasta-" + /* PID of child, in case we created a namespace */ int pasta_child_pid; @@ -178,6 +180,7 @@ struct pasta_spawn_cmd_arg { */ static int pasta_spawn_cmd(void *arg) { + char hostname[HOST_NAME_MAX + 1] = HOSTNAME_PREFIX; const struct pasta_spawn_cmd_arg *a; sigset_t set; @@ -188,6 +191,13 @@ static int pasta_spawn_cmd(void *arg) if (write_file("/proc/sys/net/ipv4/ping_group_range", "0 0")) warn("Cannot set ping_group_range, ICMP requests might fail"); + if (!gethostname(hostname + sizeof(HOSTNAME_PREFIX) - 1, HOST_NAME_MAX + 1 - + sizeof(HOSTNAME_PREFIX)) || errno == ENAMETOOLONG) { + hostname[HOST_NAME_MAX] = '\0'; + if (sethostname(hostname, strlen(hostname))) + warn("Unable to set pasta-prefixed hostname"); + } + /* Wait for the parent to be ready: see main() */ sigemptyset(&set); sigaddset(&set, SIGUSR1); -- 2.45.2