From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: passt.top; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=ONrkdTXl; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTP id 070755A004C for ; Thu, 29 Aug 2024 05:00:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724900401; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LcDvfCyfgl6NxktiBkB/RbVWsrhVVXT3dfeailCooLk=; b=ONrkdTXlq1waJ78JDqVtlHuoX8ooQfMkUOKIHDBhP4CA8nvhfyHovN3pCDr1dLBSew6v4I JVyChGmhhkvuU3JkQ/LCBdjKIeAmAKFtJtKH42cBFlj0UHM883DLaTqIXuPV0WhgKEdg+A 1Ny3pQW+gAK6cS1bw/NWu1AHqsPewro= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-339-1oAK5KKEO9qd2a-kj8iXCg-1; Wed, 28 Aug 2024 23:00:00 -0400 X-MC-Unique: 1oAK5KKEO9qd2a-kj8iXCg-1 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-429c224d9edso1599305e9.1 for ; Wed, 28 Aug 2024 19:59:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724900399; x=1725505199; h=content-transfer-encoding:mime-version:organization:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=LcDvfCyfgl6NxktiBkB/RbVWsrhVVXT3dfeailCooLk=; b=Fd9PSHeaegqAOE2U/SajwgukUQ/L3Za8Ovj2ruDGy8FH+k43uRuv5r7520ujeRCrpD XUom+V1pYikSmq9z3ZuGMxzqDH25by43fOhE41W1EO5nD6opUIMZo9wJWnCJqD0jo6A8 iCwlBw9a8A9/Wr0jbzZE69+m6Fqq78RwKPbb81ULBz/FZJil286q9MGI3/KqxhbYlAgT 5P8b3wur4IpBFrqZ2Y4yymaqyny0lzinS+cl8MFe4EyEy83roTntk7Bv68u0vhzNZkEj NTaLazNGhkzzcjTgDqH1voexXRpgLzp1ZnA9HbWdfYEvUfyn+JLskrpwc89LrwPfo8IO LSLA== X-Forwarded-Encrypted: i=1; AJvYcCXGu4IX2XnbNNh5niX8zcLKJdZ4MwbCNg/4+g23FHKsUdX3YqZEqOHDpHKrKHKesNaW3W+GQX0tBkI=@passt.top X-Gm-Message-State: AOJu0Yyni1Q9Gy/9M1L5P+eKnH7atLnRGCXlwPRe9Cb15wuA5se8ndG6 tEquleCknbH8VVpinfPFmY7VdqPYZmI0Ojhkh/OIgMUmQ3x2upffgIlxUSjPQJ0a3PnL555vllc 5PWGZo4fzIHkAIq8x+dntJfYl9Oxg/Qsr3eGIH7b+/+g+HGEdRQ== X-Received: by 2002:a05:600c:4fd3:b0:428:1007:6068 with SMTP id 5b1f17b1804b1-42bb01fb0e4mr11073975e9.34.1724900398756; Wed, 28 Aug 2024 19:59:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHYP2ltc20ockODB4YX61iVr1ncax4mCRnPLnMNusEMwqNnH+JbE/i+URicpDXZ9JCbpqsIhQ== X-Received: by 2002:a05:600c:4fd3:b0:428:1007:6068 with SMTP id 5b1f17b1804b1-42bb01fb0e4mr11073865e9.34.1724900398270; Wed, 28 Aug 2024 19:59:58 -0700 (PDT) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [176.103.220.4]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42bb6e27467sm3428355e9.38.2024.08.28.19.59.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Aug 2024 19:59:57 -0700 (PDT) Date: Thu, 29 Aug 2024 04:59:55 +0200 From: Stefano Brivio To: David Gibson Subject: Re: [PATCH 3/3] fwd, conf: Probe host's ephemeral ports Message-ID: <20240829045955.7f83a9e5@elisabeth> In-Reply-To: References: <20240828055610.3241117-1-david@gibson.dropbear.id.au> <20240828055610.3241117-4-david@gibson.dropbear.id.au> <9ba5487a-17b7-4c7b-a3d4-7a1e2c7d88a5@redhat.com> Organization: Red Hat X-Mailer: Claws Mail 4.2.0 (GTK 3.24.41; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: YFOSJHRVD2FVLSFJO6E3DA76QBVSGONP X-Message-ID-Hash: YFOSJHRVD2FVLSFJO6E3DA76QBVSGONP X-MailFrom: sbrivio@redhat.com 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: Laurent Vivier , passt-dev@passt.top 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: On Thu, 29 Aug 2024 11:29:30 +1000 David Gibson wrote: > On Wed, Aug 28, 2024 at 12:22:18PM +0200, Laurent Vivier wrote: > > On 28/08/2024 07:56, David Gibson wrote: > > > > > > [...] > > > > > > + lineread_init(&lr, fd); > > > + len = lineread_get(&lr, &line); > > > + if (len < 0) > > > + goto parse_err; > > > + > > > + tab = strchr(line, '\t'); > > > + if (!tab) > > > + goto parse_err; > > > + *tab = '\0'; > > > + > > > + errno = 0; > > > + min = strtol(line, &end, 10); > > > + if (*end || errno) > > > + goto parse_err; > > > + > > > + errno = 0; > > > + max = strtol(tab + 1, &end, 10); > > > + if (*end || errno) > > > + goto parse_err; > > > > As /proc files are well formated, why don't you use fscanf()? > > Something like: > > > > FILE *f; > > > > f = fopen(PORT_RANGE_SYSCTL, "r"); > > if (f == NULL) { > > warn("Unable to parse %s", PORT_RANGE_SYSCTL); > > return; > > } > > ret = fscanf(f, "%d %d", &min, &max); > > fclose(f); > > if (ret != 2) > > goto parse_error; > > Hm, maybe. I never feel like I know exactly what the parse rules for > scanf() are, so I tend to avoid it. Stefano, any thoughts? The issue with fopen() and ffscanf() is that they need dynamic allocation, see also 32d07f5e59f2 ("passt, pasta: Completely avoid dynamic memory allocation"). Still, here, we could use lineread_get() and sscanf() as we do in fwd.c, procfs_scan_listen(), but I don't really have a preference. If you find that scanf() is confusing for you, perhaps it would be better to use something simpler as you did. On the other hand it would be 2 lines of code instead of (somewhat bug-prone) 14 lines. I'm not sure, I'd say whatever you feel most comfortable with... -- Stefano