From nobody Mon Jul 22 14:59:54 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 4WSNjk2YF7z5R5R0; Mon, 22 Jul 2024 14:59:54 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4WSNjk21scz57c3; Mon, 22 Jul 2024 14:59:54 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1721660394; 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=zRBUH4xLe6jcgOsCsXrg6IpFaK+TBMGyGD3fdsZAHLQ=; b=u80iQ7IoRkSFnUlzNi1irNMXnkOkJGWzWsGarZ8kUcRK1sPkLdVM1BtCclqGbJ7e6yrPge 1I7GaB3CW5/KYJ+Ed2ppn+kzjNERTCrlwsQtD0xg6q/KH+Cq6dA6PTkk0lqNnAf95dYDfj dHb1HqQ1Y6N9EOwImr+sduek3D1fPadlwu7KwrUqNpw5iVaat3249p6eF/tZDR7w5dGsH5 cSs0wX7pkvuSTl1NX+OCEWRI8QhPxkBPJY1q5TbBrvRRBSprv6e+0osjGe3q5yBz1em9/5 jFVEi8IlweM6wnSCGf213hIWJWyTV/mcxcnq15JPeiHT0b4ero3VsJKps8scXQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1721660394; a=rsa-sha256; cv=none; b=bN2+6SQ+zyKGun1xJBehjwPkvz4m382WGBRdRRXdiyi4+VOReIcArTW2x4/WM2oAvcwfwp 0bfwuYTl2rAOtqgYTXYVM1Jl5CheOxjY7b1i9nsj6A8wTfPTk5V3cNbc8D8KaG5RMAfabV ae8mpo+zldwMxffaS9Nb21pAu5U/V44OmLa8XfGf2tc93PMGIbcKa+OeW0EPws7qPxne2f yUHOMu8OUBK/imEFPjYcRVi10gdfNlOGnytjPH2vkF29cF1v0nqBwIqM4OZERQkilep7Av 4d9GWDBlHM/54h2UpvDkWQtF6fvZnyyOb5YyoI2NS6o5yVPzsbeATz8QFCdoGQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1721660394; 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=zRBUH4xLe6jcgOsCsXrg6IpFaK+TBMGyGD3fdsZAHLQ=; b=yhTJtpo26qO66hAKgktOY1Z1ILfi5y00IxfzXtX54s1E4d0bxGCerbrUwi7VKGNCIJR1Wz o5VHJg9IEuRrOaC12xeIV1qpMCXJRqLcfT7rTHg+qNBVoC1pQw8gw3ECkTBkh6n7jGJP0f FXXZT3+a3DZf5ah9xbp70E+ysqO6DQDAjxH8UDrw0H/bHsTJfYgYalLBKOcLp/UGdM4L3T oyEeVsbQyPQJcNNBht2KYNYshN+9zBS4YltI2KkuN7Zjgi9g12vPTtz0vmHycP5sefzfYT dCz5s1xc8KcaqvhlG5q5JPQxdye8z43OKk9OXuOPQHeaM97wyojmwxlCGcRv0g== 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 4WSNjk1WXLzpTD; Mon, 22 Jul 2024 14:59:54 +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 46MExsig033061; Mon, 22 Jul 2024 14:59:54 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 46MExskr033058; Mon, 22 Jul 2024 14:59:54 GMT (envelope-from git) Date: Mon, 22 Jul 2024 14:59:54 GMT Message-Id: <202407221459.46MExskr033058@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konrad Witaszczyk Subject: git: c74a4cea0dc9 - main - usr.sbin/uhsoctl: correct SIOCDIFADDR calls to use ifreq 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: def X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: c74a4cea0dc9dddf996179b1586fb6e9fbf6b702 Auto-Submitted: auto-generated The branch main has been updated by def: URL: https://cgit.FreeBSD.org/src/commit/?id=c74a4cea0dc9dddf996179b1586fb6e9fbf6b702 commit c74a4cea0dc9dddf996179b1586fb6e9fbf6b702 Author: Konrad Witaszczyk AuthorDate: 2024-06-28 10:29:15 +0000 Commit: Konrad Witaszczyk CommitDate: 2024-07-22 14:58:19 +0000 usr.sbin/uhsoctl: correct SIOCDIFADDR calls to use ifreq The SIOCDIFADDR ioctl takes an ifreq structure object, not an ifaliasreq structure object, as its argument. The ifreq structure does not include a separate mask field and the SIOCDIFADDR ioctl handler does not require a network mask as opposed to the ifaliasreq structure and the SIOCAIFADDR ioctl. Given that SIOCAIFADDR and SIOCDIFADDR ioctls significantly differ and use different structures for ioctl arguments, remove ifaddr_add() and move its logic handling these ioctls to ifaddr_add()'s callers. Reviewed by: brooks, jhb, oshogbo Accepted by: oshogbo (mentor) Obtained from: CheriBSD Differential Revision: https://reviews.freebsd.org/D46019 --- usr.sbin/uhsoctl/uhsoctl.c | 68 ++++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 35 deletions(-) diff --git a/usr.sbin/uhsoctl/uhsoctl.c b/usr.sbin/uhsoctl/uhsoctl.c index 992858eb45ca..b7aa1a45c667 100644 --- a/usr.sbin/uhsoctl/uhsoctl.c +++ b/usr.sbin/uhsoctl/uhsoctl.c @@ -356,27 +356,6 @@ logger(int pri, const char *fmt, ...) va_end(ap); } -/* Add/remove IP address from an interface */ -static int -ifaddr_ad(unsigned long d, const char *ifnam, struct sockaddr *sa, struct sockaddr *mask) -{ - struct ifaliasreq req; - int fd, error; - - fd = socket(AF_INET, SOCK_DGRAM, 0); - if (fd < 0) - return (-1); - - memset(&req, 0, sizeof(struct ifaliasreq)); - strlcpy(req.ifra_name, ifnam, sizeof(req.ifra_name)); - memcpy(&req.ifra_addr, sa, sa->sa_len); - memcpy(&req.ifra_mask, mask, mask->sa_len); - - error = ioctl(fd, d, (char *)&req); - close(fd); - return (error); -} - #define if_ifup(ifnam) if_setflags(ifnam, IFF_UP) #define if_ifdown(ifnam) if_setflags(ifnam, -IFF_UP) @@ -418,22 +397,45 @@ if_setflags(const char *ifnam, int flags) static int ifaddr_add(const char *ifnam, struct sockaddr *sa, struct sockaddr *mask) { - int error; + struct ifaliasreq ifra; + int error, fd; + + memset(&ifra, 0, sizeof(ifra)); + strlcpy(ifra.ifra_name, ifnam, sizeof(ifra.ifra_name)); + memcpy(&ifra.ifra_addr, sa, sa->sa_len); + memcpy(&ifra.ifra_mask, mask, mask->sa_len); + + fd = socket(AF_INET, SOCK_DGRAM, 0); + if (fd < 0) + return (-1); - error = ifaddr_ad(SIOCAIFADDR, ifnam, sa, mask); + error = ioctl(fd, SIOCAIFADDR, (caddr_t)&ifra); if (error != 0) warn("ioctl SIOCAIFADDR"); + + close(fd); return (error); } static int -ifaddr_del(const char *ifnam, struct sockaddr *sa, struct sockaddr *mask) +ifaddr_del(const char *ifnam, struct sockaddr *sa) { - int error; + struct ifreq ifr; + int error, fd; + + memset(&ifr, 0, sizeof(ifr)); + strlcpy(ifr.ifr_name, ifnam, sizeof(ifr.ifr_name)); + memcpy(&ifr.ifr_addr, sa, sa->sa_len); - error = ifaddr_ad(SIOCDIFADDR, ifnam, sa, mask); + fd = socket(AF_INET, SOCK_DGRAM, 0); + if (fd < 0) + return (-1); + + error = ioctl(fd, SIOCDIFADDR, (caddr_t)&ifr); if (error != 0) warn("ioctl SIOCDIFADDR"); + + close(fd); return (error); } @@ -897,8 +899,7 @@ at_async_owandata(void *arg, const char *resp) if (ctx->flags & IPASSIGNED) { memcpy(&sin.sin_addr.s_addr, &ctx->ip.s_addr, sizeof(sin.sin_addr.s_addr)); - ifaddr_del(ctx->ifnam, (struct sockaddr *)&sin, - (struct sockaddr *)&mask); + ifaddr_del(ctx->ifnam, (struct sockaddr *)&sin); } inet_pton(AF_INET, ip, &ctx->ip.s_addr); memcpy(&sin.sin_addr.s_addr, &ctx->ip.s_addr, @@ -1258,7 +1259,7 @@ do_connect(struct ctx *ctx, const char *tty) static void do_disconnect(struct ctx *ctx) { - struct sockaddr_in sin, mask; + struct sockaddr_in sin; /* Disconnect */ at_cmd(ctx, NULL, NULL, NULL, "AT_OWANCALL=%d,0,0\r\n", @@ -1267,14 +1268,11 @@ do_disconnect(struct ctx *ctx) /* Remove ip-address from interface */ if (ctx->flags & IPASSIGNED) { - sin.sin_len = mask.sin_len = sizeof(struct sockaddr_in); - memset(&mask.sin_addr.s_addr, 0xff, - sizeof(mask.sin_addr.s_addr)); - sin.sin_family = mask.sin_family = AF_INET; + sin.sin_len = sizeof(struct sockaddr_in); + sin.sin_family = AF_INET; memcpy(&sin.sin_addr.s_addr, &ctx->ip.s_addr, sizeof(sin.sin_addr.s_addr)); - ifaddr_del(ctx->ifnam, (struct sockaddr *)&sin, - (struct sockaddr *)&mask); + ifaddr_del(ctx->ifnam, (struct sockaddr *)&sin); if_ifdown(ctx->ifnam); ctx->flags &= ~IPASSIGNED;