From nobody Mon May 29 22:10:08 2023 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4QVV811zNHz4XFkQ; Mon, 29 May 2023 22:10:09 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4QVV810Q3kz3Hjq; Mon, 29 May 2023 22:10:09 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1685398209; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=OobUlw1MRdte9M5vfiRVGxSUIwHKOI9RrxsBZRduKwo=; b=FbZAISZB0HDtD6dqO7k/wZRepi3xXjjv69V131qJ7kWDc9VnjHyO8rZ3nv5qH2wVqGLaxe ETO6Lw6hLlFWRYyT1uiR1JL6FEi98GGf+RP4WOTLJPItwAKaHav/k5QPlFHbgbF8rcjmli likUngkrOq54XoVS1Irji/PD75r0j/HMqpOl2Dx0c/dPSnNd8wGsKoXW0cDVRMo9gDoz+J 48UISpc8weiB05UiFW0nT04Z/pheB5+QL9hKIEvOKFt9MgLsqYfWK/Xv/cSq4oI2f6vvYR 5F8XJ9IlhuIs1QJHunymLqjIKfIaUOoByige5WgKOIjpiJhyw8IUQgdfLsUf5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1685398209; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=OobUlw1MRdte9M5vfiRVGxSUIwHKOI9RrxsBZRduKwo=; b=w0W3DB7tB5q7VGq3rxoeBFODsh+dWXvuOzBY/sl7OipQPTPf+4ITV2+aQ4zMv+aDNJGvWR TbM7B+MgS5/PiX6gBV8PxJtcKCyO/x+/htp1BmGkT9M7RKDA0vBb2oPpgo+mUcc3dA0GXx 2GU6y84CZnoRjXLuXAwwBocRj780eLwBou8JAzVVYvT+U7BR/WtH6bOw+10z8BF5+zZD0W 2kLWz2hEb0r3Diqvct1ZSyUyDaYi1Q57qdXtXdlL6gUk/z6j8bu8SFLvMMaTRcCTPWXE9H ZRG+RCE8ly+jNkdpyYyKuoTU2InNWmAL8Ou0eWPLlsb0Jlv3ujXgfw5ZR7/hHw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1685398209; a=rsa-sha256; cv=none; b=ASvkHpErbrQ5Bi21HNi7KiXFqlTX7hGacazbWTkR6erdEBOagCJPxUS61B4/BkTVk2SX1R XB02Qs94/gOAwL7f8gdEqpTay+se7uA9SHJdvDJp4jkVlMwOVAbImOZoV6ZeFu8xX23jDj RzKek6L7FFPzAGRgqNZ/BPshoQjOMlGojnLDQJ2g6zabGmtvBopRs16aB8fjWPps9+KLv5 TD9h3oKEtb/pWteO5s89t3AdDv0RmB9msnnR1bixXa7wtJXIQa5GBXCcP0Tk1cy6+mq5la pyNRN4m4t5gNccnIebswCzXjsX+GZyPQNLPXawzLJKCRKFXKTBvPhrkbNHcjrw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4QVV806JjdzT7m; Mon, 29 May 2023 22:10:08 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 34TMA87X036598; Mon, 29 May 2023 22:10:08 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 34TMA8lX036592; Mon, 29 May 2023 22:10:08 GMT (envelope-from git) Date: Mon, 29 May 2023 22:10:08 GMT Message-Id: <202305292210.34TMA8lX036592@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 2c1296a3c547 - main - setkey(8): extract prefixlen calculation info helper List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 2c1296a3c5473651aa87eefea25e7b7475e9e16c Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=2c1296a3c5473651aa87eefea25e7b7475e9e16c commit 2c1296a3c5473651aa87eefea25e7b7475e9e16c Author: Konstantin Belousov AuthorDate: 2023-05-25 12:20:00 +0000 Commit: Konstantin Belousov CommitDate: 2023-05-29 22:10:02 +0000 setkey(8): extract prefixlen calculation info helper While there, hide AF_INET case under #ifdef INET. Reviewed by: ae Discussed with: bz Sponsored by: NVidia networking MFC after: 1 week Differential revision: https://reviews.freebsd.org/D40300 --- sbin/setkey/parse.y | 56 ++++++++++++++++++++++------------------------------- 1 file changed, 23 insertions(+), 33 deletions(-) diff --git a/sbin/setkey/parse.y b/sbin/setkey/parse.y index 3d3ed123d4f0..d279546fada6 100644 --- a/sbin/setkey/parse.y +++ b/sbin/setkey/parse.y @@ -787,6 +787,23 @@ setkeymsg0(struct sadb_msg *msg, unsigned type, unsigned satype, size_t l) return 0; } +static int +setkeymsg_plen(struct addrinfo *s) +{ + switch (s->ai_addr->sa_family) { +#ifdef INET + case AF_INET: + return (sizeof(struct in_addr) << 3); +#endif +#ifdef INET6 + case AF_INET6: + return (sizeof(struct in6_addr) << 3); +#endif + default: + return (-1); + } +} + /* XXX NO BUFFER OVERRUN CHECK! BAD BAD! */ static int setkeymsg_spdaddr(unsigned type, unsigned upper, vchar_t *policy, @@ -825,18 +842,9 @@ setkeymsg_spdaddr(unsigned type, unsigned upper, vchar_t *policy, if (s->ai_addr->sa_family != d->ai_addr->sa_family) continue; - switch (s->ai_addr->sa_family) { - case AF_INET: - plen = sizeof(struct in_addr) << 3; - break; -#ifdef INET6 - case AF_INET6: - plen = sizeof(struct in6_addr) << 3; - break; -#endif - default: + plen = setkeymsg_plen(s); + if (plen == -1) continue; - } /* set src */ sa = s->ai_addr; @@ -954,18 +962,9 @@ setkeymsg_addr(unsigned type, unsigned satype, struct addrinfo *srcs, if (s->ai_addr->sa_family != d->ai_addr->sa_family) continue; - switch (s->ai_addr->sa_family) { - case AF_INET: - plen = sizeof(struct in_addr) << 3; - break; -#ifdef INET6 - case AF_INET6: - plen = sizeof(struct in6_addr) << 3; - break; -#endif - default: + plen = setkeymsg_plen(s); + if (plen == -1) continue; - } /* set src */ sa = s->ai_addr; @@ -1140,18 +1139,9 @@ setkeymsg_add(unsigned type, unsigned satype, struct addrinfo *srcs, if (s->ai_addr->sa_family != d->ai_addr->sa_family) continue; - switch (s->ai_addr->sa_family) { - case AF_INET: - plen = sizeof(struct in_addr) << 3; - break; -#ifdef INET6 - case AF_INET6: - plen = sizeof(struct in6_addr) << 3; - break; -#endif - default: + plen = setkeymsg_plen(s); + if (plen == -1) continue; - } /* set src */ sa = s->ai_addr;