From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-15.pe-b.jellyfish.systems (out-15.pe-b.jellyfish.systems [198.54.127.81]) by passt.top (Postfix) with ESMTPS id 6219D5A004C for ; Fri, 24 May 2024 14:49:21 +0200 (CEST) Received: from output-router-5c9bf9d745-l6sn7 (new-01.privateemail.com [198.54.118.220]) by pe-b.jellyfish.systems (Postfix) with ESMTPA id 4Vm4cH61KwzGpG6; Fri, 24 May 2024 12:49:19 +0000 (UTC) Received: from MTA-07.privateemail.com (unknown [10.50.14.17]) (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.privateemail.com (Postfix) with ESMTPS id C257E18000CF; Fri, 24 May 2024 08:49:19 -0400 (EDT) Received: from mta-07.privateemail.com (localhost [127.0.0.1]) by mta-07.privateemail.com (Postfix) with ESMTP id 959D4180004D; Fri, 24 May 2024 08:49:19 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=danishpraka.sh; s=default; t=1716554959; bh=spFF/tLPTftzgctMjlX8B8FWNEL9Y6ELfhIFsGl4fPY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lISr1VywOmqzqAVH8pbR90k3y4haQ39sDYpoxe4GcgxXMSJ7vjbugPcE9ePAUOjPT 2mwCvytwc9dujqRhIAb9L+f5VoTppDhXh6SZ8AEpG161KNjEBrPeDoa0pGBCwGFg11 e9jmPlr3b3pDaejbyKX66F5Ee4x5AxKfZ0TISKjvuZAh72cEhpD97I51hE4HN8GoSu Cho/oBqLsKJQQiiLHU/w262ol2aCVAYzKb80mMnZPlkJCXBeEQaHvdA2/b8pNnMrlc Y3bE98HReEM8P6YHlzEaKWFlxfuqShzJZVFGPFRy9MHrMqbi0S64JMTC092MEc91gI HfT4+wyxK3cVg== Received: from localhost.localdomain (unknown [122.171.22.79]) by mta-07.privateemail.com (Postfix) with ESMTPA; Fri, 24 May 2024 08:49:16 -0400 (EDT) From: Danish Prakash To: passt-dev@passt.top, sbrivio@redhat.com Subject: [PATCH] pasta.c: modify hostname when detaching new namespace Date: Fri, 24 May 2024 18:18:53 +0530 Message-ID: <20240524124903.2004-1-contact@danishpraka.sh> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240520083650.12032-1-contact@danishpraka.sh> References: <20240520083650.12032-1-contact@danishpraka.sh> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Virus-Scanned: ClamAV using ClamSMTP Message-ID-Hash: 2ZZ4OZYME5XKTRN2FMNT66JS72YZHTH3 X-Message-ID-Hash: 2ZZ4OZYME5XKTRN2FMNT66JS72YZHTH3 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 | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pasta.c b/pasta.c index 31e1e00..90afd74 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,12 @@ 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 ) { + 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.1