From nobody Mon Apr 04 19:16:30 2022 X-Original-To: dev-commits-src-all@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 A7A3D1A82D15; Mon, 4 Apr 2022 19:16:30 +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 4KXL9V2wqFz3vdG; Mon, 4 Apr 2022 19:16:30 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1649099790; 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=nb75WD8Jq26wcWpj94JnYOz/kktdlbLjU6ealG9xJoI=; b=Hy9qWqRxa4xyP7+ohKaOVTkt3S5/y68P1EMrS+UtLQGj9D4UxBA15ul0+3Dczeh3r/sd/e FkPYoyJZgeW7gNH1LQ2glI88P4VJS2rdpcatp3kF9Az18q/Sec1/MFuBfm2jsaLey24MxF xJ1tRnRs+a9tjwN7tGnkd0SofGjPgzvRNnJRGTeNW3uz0oN2exzC1wSHGB2P4Jo0DVouDZ vMu3h4ji6pIApeKZXQ9JLx7EsGcaNnYYca0vXTlZk88gOPgZ8KtK1Fs1QN+Es9Yc4vXLF0 ruFiM0ic8Kl8lkNWlFC8pMQBggKV5YJqt1LzfjCjXjkY3OJtDf1upk0itVyzhg== 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 40E1418094; Mon, 4 Apr 2022 19:16:30 +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 234JGUoN052831; Mon, 4 Apr 2022 19:16:30 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 234JGU1s052830; Mon, 4 Apr 2022 19:16:30 GMT (envelope-from git) Date: Mon, 4 Apr 2022 19:16:30 GMT Message-Id: <202204041916.234JGU1s052830@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: 4823489ab61d - main - libpfctl: relocate implementations of pfr_add/get/set_addrs List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@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: 4823489ab61dbaef4405cf03d2a48e77e593ce9c Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1649099790; 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=nb75WD8Jq26wcWpj94JnYOz/kktdlbLjU6ealG9xJoI=; b=NOQPZVAq9bDMUTUlPHvBjT1bZSDifPQhMRjFAicFc3UghyiXf2xhmcR37AYHy7isiVcooa ANtjx5YnMFr8RBpt8rBeVdtVKcWEeiw4BnyvWKn24zeKblshmQGHP7HhhLLniZSdXwEwLR xyfFhnvYzTw8R5dC1w2DzILx9x9egAt8I5UMIbyus+7O6NHSLGN7eVTyuoEr952S8YkaAE MnxvGssiKuNhabKgRRseDGbmVf7LKRp4fY0ryhJBxxDwcntdyR9OVnHBOdcrKuNqKwGUVJ OsVJDoYvmZ3cWAHIGzfsgHPP9QkrIMcUiG9oI5s7y2qDdSinGf5qGhLCFYy/Pw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1649099790; a=rsa-sha256; cv=none; b=hxqJkRbKdkbcKqN0ectyscU0bE5iI28EdvU+Lxtf/4becQ04NQ9NTOlE77EjaQQC0F2XMz nwF8ghiUCk7rH6qVcW8AmXbTsZYVFO+L9RXi1bmNlu0neZPqyfGU0eMkpt3QYAxctfJYXY Uq3gcgy64q1/OcTomfcyiBLv8p4BtNSLYI4r3QjqdRRVAoiX/STzEPMqMftS6CArLYhlRv LgeWyVe8CW8YAt3PSSAnUwsuWXOIOWj5JIV2Vi894u1gWwxXf1i9cLMDO2yJz8LxxMMdSR ACq9skVaN1BhrK5sbCqPLXMCL1kMyF+iBZsFhYOIuBDDoCLlFT2bInuLk6cnCw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=4823489ab61dbaef4405cf03d2a48e77e593ce9c commit 4823489ab61dbaef4405cf03d2a48e77e593ce9c Author: Reid Linnemann AuthorDate: 2022-04-04 14:43:38 +0000 Commit: Kristof Provost CommitDate: 2022-04-04 17:14:23 +0000 libpfctl: relocate implementations of pfr_add/get/set_addrs Reviewed by: kp MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D34740 --- lib/libpfctl/libpfctl.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++++ lib/libpfctl/libpfctl.h | 10 ++++- sbin/pfctl/pfctl_radix.c | 84 +++++++++--------------------------------- 3 files changed, 122 insertions(+), 68 deletions(-) diff --git a/lib/libpfctl/libpfctl.c b/lib/libpfctl/libpfctl.c index 991d3fce9780..f3a22106d51b 100644 --- a/lib/libpfctl/libpfctl.c +++ b/lib/libpfctl/libpfctl.c @@ -1460,3 +1460,99 @@ pfctl_get_syncookies(int dev, struct pfctl_syncookies *s) return (0); } + +int +pfctl_table_add_addrs(int dev, struct pfr_table *tbl, struct pfr_addr + *addr, int size, int *nadd, int flags) +{ + struct pfioc_table io; + + if (tbl == NULL || size < 0 || (size && addr == NULL)) { + return (EINVAL); + } + bzero(&io, sizeof io); + io.pfrio_flags = flags; + io.pfrio_table = *tbl; + io.pfrio_buffer = addr; + io.pfrio_esize = sizeof(*addr); + io.pfrio_size = size; + + if (ioctl(dev, DIOCRADDADDRS, &io)) + return (errno); + if (nadd != NULL) + *nadd = io.pfrio_nadd; + return (0); +} + +int +pfctl_table_del_addrs(int dev, struct pfr_table *tbl, struct pfr_addr + *addr, int size, int *ndel, int flags) +{ + struct pfioc_table io; + + if (tbl == NULL || size < 0 || (size && addr == NULL)) { + return (EINVAL); + } + bzero(&io, sizeof io); + io.pfrio_flags = flags; + io.pfrio_table = *tbl; + io.pfrio_buffer = addr; + io.pfrio_esize = sizeof(*addr); + io.pfrio_size = size; + + if (ioctl(dev, DIOCRDELADDRS, &io)) + return (errno); + if (ndel != NULL) + *ndel = io.pfrio_ndel; + return (0); +} + +int +pfctl_table_set_addrs(int dev, struct pfr_table *tbl, struct pfr_addr + *addr, int size, int *size2, int *nadd, int *ndel, int *nchange, int flags) +{ + struct pfioc_table io; + + if (tbl == NULL || size < 0 || (size && addr == NULL)) { + return (EINVAL); + } + bzero(&io, sizeof io); + io.pfrio_flags = flags; + io.pfrio_table = *tbl; + io.pfrio_buffer = addr; + io.pfrio_esize = sizeof(*addr); + io.pfrio_size = size; + io.pfrio_size2 = (size2 != NULL) ? *size2 : 0; + if (ioctl(dev, DIOCRSETADDRS, &io)) + return (-1); + if (nadd != NULL) + *nadd = io.pfrio_nadd; + if (ndel != NULL) + *ndel = io.pfrio_ndel; + if (nchange != NULL) + *nchange = io.pfrio_nchange; + if (size2 != NULL) + *size2 = io.pfrio_size2; + return (0); +} + +int pfctl_table_get_addrs(int dev, struct pfr_table *tbl, struct pfr_addr *addr, + int *size, int flags) +{ + struct pfioc_table io; + + if (tbl == NULL || size == NULL || *size < 0 || + (*size && addr == NULL)) { + return (EINVAL); + } + bzero(&io, sizeof io); + io.pfrio_flags = flags; + io.pfrio_table = *tbl; + io.pfrio_buffer = addr; + io.pfrio_esize = sizeof(*addr); + io.pfrio_size = *size; + if (ioctl(dev, DIOCRGETADDRS, &io)) + return (-1); + *size = io.pfrio_size; + return (0); +} diff --git a/lib/libpfctl/libpfctl.h b/lib/libpfctl/libpfctl.h index 92a1ea9b7cef..440ca2fe0d10 100644 --- a/lib/libpfctl/libpfctl.h +++ b/lib/libpfctl/libpfctl.h @@ -400,5 +400,13 @@ int pfctl_clear_nat(int dev, const char *anchorname); int pfctl_clear_eth_rules(int dev, const char *anchorname); int pfctl_set_syncookies(int dev, const struct pfctl_syncookies *s); int pfctl_get_syncookies(int dev, struct pfctl_syncookies *s); - +int pfctl_table_add_addrs(int dev, struct pfr_table *tbl, struct pfr_addr + *addr, int size, int *nadd, int flags); +int pfctl_table_del_addrs(int dev, struct pfr_table *tbl, struct pfr_addr + *addr, int size, int *ndel, int flags); +int pfctl_table_set_addrs(int dev, struct pfr_table *tbl, struct pfr_addr + *addr, int size, int *size2, int *nadd, int *ndel, int *nchange, + int flags); +int pfctl_table_get_addrs(int dev, struct pfr_table *tbl, struct pfr_addr + *addr, int *size, int flags); #endif diff --git a/sbin/pfctl/pfctl_radix.c b/sbin/pfctl/pfctl_radix.c index 218d0045a418..5d71a4e6ac89 100644 --- a/sbin/pfctl/pfctl_radix.c +++ b/sbin/pfctl/pfctl_radix.c @@ -211,24 +211,13 @@ int pfr_add_addrs(struct pfr_table *tbl, struct pfr_addr *addr, int size, int *nadd, int flags) { - struct pfioc_table io; + int ret; - if (tbl == NULL || size < 0 || (size && addr == NULL)) { - errno = EINVAL; - return (-1); - } - bzero(&io, sizeof io); - io.pfrio_flags = flags; - io.pfrio_table = *tbl; - io.pfrio_buffer = addr; - io.pfrio_esize = sizeof(*addr); - io.pfrio_size = size; - if (ioctl(dev, DIOCRADDADDRS, &io)) { - pfr_report_error(tbl, &io, "add addresses in"); + ret = pfctl_table_add_addrs(dev, tbl, addr, size, nadd, flags); + if (ret) { + errno = ret; return (-1); } - if (nadd != NULL) - *nadd = io.pfrio_nadd; return (0); } @@ -236,24 +225,13 @@ int pfr_del_addrs(struct pfr_table *tbl, struct pfr_addr *addr, int size, int *ndel, int flags) { - struct pfioc_table io; + int ret; - if (tbl == NULL || size < 0 || (size && addr == NULL)) { - errno = EINVAL; + ret = pfctl_table_del_addrs(dev, tbl, addr, size, ndel, flags); + if (ret) { + errno = ret; return (-1); } - bzero(&io, sizeof io); - io.pfrio_flags = flags; - io.pfrio_table = *tbl; - io.pfrio_buffer = addr; - io.pfrio_esize = sizeof(*addr); - io.pfrio_size = size; - if (ioctl(dev, DIOCRDELADDRS, &io)) { - pfr_report_error(tbl, &io, "delete addresses in"); - return (-1); - } - if (ndel != NULL) - *ndel = io.pfrio_ndel; return (0); } @@ -261,31 +239,14 @@ int pfr_set_addrs(struct pfr_table *tbl, struct pfr_addr *addr, int size, int *size2, int *nadd, int *ndel, int *nchange, int flags) { - struct pfioc_table io; + int ret; - if (tbl == NULL || size < 0 || (size && addr == NULL)) { - errno = EINVAL; - return (-1); - } - bzero(&io, sizeof io); - io.pfrio_flags = flags; - io.pfrio_table = *tbl; - io.pfrio_buffer = addr; - io.pfrio_esize = sizeof(*addr); - io.pfrio_size = size; - io.pfrio_size2 = (size2 != NULL) ? *size2 : 0; - if (ioctl(dev, DIOCRSETADDRS, &io)) { - pfr_report_error(tbl, &io, "set addresses in"); + ret = pfctl_table_set_addrs(dev, tbl, addr, size, size2, nadd, ndel, + nchange, flags); + if (ret) { + errno = ret; return (-1); } - if (nadd != NULL) - *nadd = io.pfrio_nadd; - if (ndel != NULL) - *ndel = io.pfrio_ndel; - if (nchange != NULL) - *nchange = io.pfrio_nchange; - if (size2 != NULL) - *size2 = io.pfrio_size2; return (0); } @@ -293,24 +254,13 @@ int pfr_get_addrs(struct pfr_table *tbl, struct pfr_addr *addr, int *size, int flags) { - struct pfioc_table io; + int ret; - if (tbl == NULL || size == NULL || *size < 0 || - (*size && addr == NULL)) { - errno = EINVAL; + ret = pfctl_table_get_addrs(dev, tbl, addr, size, flags); + if (ret) { + errno = ret; return (-1); } - bzero(&io, sizeof io); - io.pfrio_flags = flags; - io.pfrio_table = *tbl; - io.pfrio_buffer = addr; - io.pfrio_esize = sizeof(*addr); - io.pfrio_size = *size; - if (ioctl(dev, DIOCRGETADDRS, &io)) { - pfr_report_error(tbl, &io, "get addresses from"); - return (-1); - } - *size = io.pfrio_size; return (0); }