From nobody Tue Dec 17 10:07:41 2024 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 4YCCDG3n48z5h0kc; Tue, 17 Dec 2024 10:07:42 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4YCCDG0Xd4z494Q; Tue, 17 Dec 2024 10:07:42 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1734430062; 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=nxecwl/n4gOxn4C9+Rw9Yn9ZGQWaDjK4y41vlAHFYW8=; b=Q86K29glqa7NZrMIuI00bB0fHeLfLr78690HauA/2dDn9AAVBSr0rfFYGOQMHtYQIIHLul YW9wIoyMIb6C7vnK4J0yWhadP9BTS0ag0s5OCs3HCtYjAnjkQXZNGdfihf4e+NBx0MtWKJ GkbyTsuoESrDB3vRGRmzrN3Y5L25hAmRwL7WA0FYwS4IuasVm79ywmIqgbt3x5ZCCIFgN8 IY2oTorvAKvLhss3wIYhWB9QTfaOWYy8MJKKNiXSiORqhfrZczJ49emqzT0RWzi/QNrDc2 5hy2XGtcBnSXs5ZUTQt0Bi3rIRgydpR9yr0g0f9QsfYoCUUh6efG+RgAFBKEWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1734430062; 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=nxecwl/n4gOxn4C9+Rw9Yn9ZGQWaDjK4y41vlAHFYW8=; b=psrO2M71VJ8sugej7A+ww5nqmlm+VUxyanzKp1B0hZPov7TR6toDNaPnutQsiHffoI/uJY KoMx2jtbal2gCgKNQDGwyDPJSo4lqho8aPilVg3YeEBJqVnD+D68LPeqOQF1HagfIR+wvF NWPu2VRCduRNJfmxJuLNc4IstaZVpjxF2PDwJmW3uJB6SNofnrO+8eXptU+XijoaJ7B10K diNnZIYZSZANdSr5PAsSX5ooDZLwV9RBi3vdM3+6XqJmnZSzEhMmxm78bNNRxp6/+qHJm8 edZrhm/l8B7R5qRr3vTzckhvqMkKUSx/p5ShSYxp/m/Ka9MvYY7Utl4eY1kaqQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1734430062; a=rsa-sha256; cv=none; b=MWhUoAd4KlOJp1uzi0sOCTD2bO1QUueyT6CMmqGMIkA9jXFC4R0ZC67CA0MnBjLvKwVp3R QS5YXAa/qovf38gnumILf9xnCMaeIpw1qYy8LYwD1VWAan+4uZq8+whkzdPuaAg1o/2QhW L3u3alPFpMFvCtQMI4nUIwdMyF8PZFApYVtLq/rvNCteCvU+CbDMUPAKwBrsS/How+dIRk 4XoQCT7rt7kc3yjB1115K/OxUS5qlzXphKSnVonjQb+g+vtZaWQV/i0HHvuVd+KM4Jq4s8 YNsLvfHUiIpPId82KAayHqrGt8Gb0Ktxcq22mwHeRfNiqGFj2JHt5QMLS4U4QQ== 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 4YCCDG06ZWzJtt; Tue, 17 Dec 2024 10:07:42 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 4BHA7fw2023338; Tue, 17 Dec 2024 10:07:41 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4BHA7fkH023335; Tue, 17 Dec 2024 10:07:41 GMT (envelope-from git) Date: Tue, 17 Dec 2024 10:07:41 GMT Message-Id: <202412171007.4BHA7fkH023335@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kristof Provost Subject: git: e4e0f497429c - main - in: add in_mask2len() 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: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: e4e0f497429c635a02897d86c4eb5ec649cc2df8 Auto-Submitted: auto-generated The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=e4e0f497429c635a02897d86c4eb5ec649cc2df8 commit e4e0f497429c635a02897d86c4eb5ec649cc2df8 Author: Kristof Provost AuthorDate: 2024-10-22 08:45:06 +0000 Commit: Kristof Provost CommitDate: 2024-12-17 10:07:12 +0000 in: add in_mask2len() Similar to the existing in6_mask2len() function, but for IPv4. This will be used by pf's nat64 code. Obtained from: OpenBSD Sponsored by: Rubicon Communications, LLC ("Netgate") Differential Revision: https://reviews.freebsd.org/D47785 --- sys/netinet/in.c | 21 +++++++++++++++++++++ sys/netinet/in_var.h | 1 + 2 files changed, 22 insertions(+) diff --git a/sys/netinet/in.c b/sys/netinet/in.c index c78f0f5758f7..a6f212e9d3ef 100644 --- a/sys/netinet/in.c +++ b/sys/netinet/in.c @@ -441,6 +441,27 @@ in_control_ioctl(u_long cmd, void *data, struct ifnet *ifp, return (error); } +int +in_mask2len(struct in_addr *mask) +{ + int x, y; + u_char *p; + + p = (u_char *)mask; + for (x = 0; x < sizeof(*mask); x++) { + if (p[x] != 0xff) + break; + } + y = 0; + if (x < sizeof(*mask)) { + for (y = 0; y < 8; y++) { + if ((p[x] & (0x80 >> y)) == 0) + break; + } + } + return (x * 8 + y); +} + int in_control(struct socket *so, u_long cmd, void *data, struct ifnet *ifp, struct thread *td) diff --git a/sys/netinet/in_var.h b/sys/netinet/in_var.h index b4bdb2a65fc8..1f6f6edb9219 100644 --- a/sys/netinet/in_var.h +++ b/sys/netinet/in_var.h @@ -459,6 +459,7 @@ int in_joingroup_locked(struct ifnet *, const struct in_addr *, int in_leavegroup(struct in_multi *, /*const*/ struct in_mfilter *); int in_leavegroup_locked(struct in_multi *, /*const*/ struct in_mfilter *); +int in_mask2len(struct in_addr *); int in_control(struct socket *, u_long, void *, struct ifnet *, struct thread *); int in_control_ioctl(u_long, void *, struct ifnet *,