From nobody Sat May 20 09:49:40 2023 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 4QNf7n0QVLz4Bs2H; Sat, 20 May 2023 09:49:41 +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 4QNf7m5b2nz3rm6; Sat, 20 May 2023 09:49:40 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1684576180; 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=ENNXphpGIHd+axb8wKaFyDfowUSuMVO1PUbGZIcHOQ0=; b=nZuPFh/X39Gmjwu3RlTFc4mxOH0TxRPe/yOAwLrNWXyI/Plm+UuBUqRl8ND9rflqkEcfTY jH2r/pKWs0tvC2Z1LePM37kmtB7iY+bWg74VS4ING3vrfSPQXrk2PLFxLWTQtSMBOQr044 kh2Nc79b8GsrYd2rinuN2GfmJkIdpLVuJW9Fwx+dGpmJOlfK4++CePUQ2SS3Bw6vboMEeF qEjMH6sNp5ywMlpqqTDOuJWrsE/LxbNv1GclA+TZO09WZtAZfTKYGVZteVL5caLRVPw6jC 5ERJCqLqwndnfDsvI064lEKPWIYqXIgvBSqPx7TiIjAtlHmClXMVM+G5GL1hAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1684576180; 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=ENNXphpGIHd+axb8wKaFyDfowUSuMVO1PUbGZIcHOQ0=; b=Dhkw5s6/riycOX9kqX/Q067ftVMRMNy9G55K7O2M6dHtLZVsFnbCyr1teD96o4wXfnBaTq W1IQHuyf1n1qkvXdRlh7M1fOQl9izxgdH4jq9QCe780lVvzr0dy6EHww0+0y1ECPpSq0zw Cs3TfRdlDcV4l3jUFZlApzIOyeFqdh5gyilKYft+Qqvo32Cjk3+IzGi0O3QXSiao9nRBWJ YR1oqR/nKKbnBN8gDSoBrlAdTvMIiblQZm5q0E+ka8lmD4wTUvBvd+wFRqyOntYsNDgZZW +IAPqdXZmq7NRnIAqByQmcFdC124A/535RDQyqLPGZVKFJGAUcaAEHXMcIYBgA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1684576180; a=rsa-sha256; cv=none; b=Eip3fEnEIZs8F/FjZ2pvQfIi1Hdnhscn46OZ8sYVzM7KcbLXSvF2ZVQHbowP+RyJxfZpup A/5FYJPrEHfSdVSqxzPwgW7qs/1wbiA+7cI1X+bTCyj5Sx5Fh/sWWPiiJwYEbKrOPVkZWN occQZmpm99ueBOG1Kwhi9Y8FWBkHifJ+0Bxd2xVDFpj/HaadkR6njang38scV7AhApPxJb ygetPqbaAHONSupwWAq+tXZ2v2A0tk2xRE/5VoknmVPjC2CKq6AIAcS+29N9gjmrEIy4B7 NXeziiMhSfYt43FwTEHITWb9NoZ4PK+C3X5zNL0eJlwaX0zttpaLUFUlgzl2qw== 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 4QNf7m4f7Fz14SX; Sat, 20 May 2023 09:49:40 +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 34K9neS2035668; Sat, 20 May 2023 09:49:40 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 34K9necm035667; Sat, 20 May 2023 09:49:40 GMT (envelope-from git) Date: Sat, 20 May 2023 09:49:40 GMT Message-Id: <202305200949.34K9necm035667@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: "Alexander V. Chernikov" Subject: git: a72b78905a3d - main - ifconfig: simplify carp vhid setup. 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: melifaro X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: a72b78905a3df924875a2b18e4199f64f1ab432f Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by melifaro: URL: https://cgit.FreeBSD.org/src/commit/?id=a72b78905a3df924875a2b18e4199f64f1ab432f commit a72b78905a3df924875a2b18e4199f64f1ab432f Author: Alexander V. Chernikov AuthorDate: 2023-05-19 10:18:43 +0000 Commit: Alexander V. Chernikov CommitDate: 2023-05-20 09:49:15 +0000 ifconfig: simplify carp vhid setup. Currently carp implementation peeks into the opaque 'afp->af_addreq' buffer, assumes it knows the af-specific layout and assigns vhid directly. Simplify the code and remove abstraction leak by introducing per-afp callback for setting vhid. This change is a pre-requisite to set addresses via Netlink, as Netlink implementiation uses different structure layout. Reviewed by: kp Differential Revision: https://reviews.freebsd.org/D40160 MFC after: 2 weeks --- sbin/ifconfig/af_inet.c | 8 ++++++++ sbin/ifconfig/af_inet6.c | 7 +++++++ sbin/ifconfig/carp.c | 26 ++------------------------ sbin/ifconfig/ifconfig.h | 2 ++ 4 files changed, 19 insertions(+), 24 deletions(-) diff --git a/sbin/ifconfig/af_inet.c b/sbin/ifconfig/af_inet.c index 4569c9c362e9..cb030dbc711b 100644 --- a/sbin/ifconfig/af_inet.c +++ b/sbin/ifconfig/af_inet.c @@ -285,6 +285,13 @@ in_set_tunnel(int s, struct addrinfo *srcres, struct addrinfo *dstres) warn("SIOCSIFPHYADDR"); } +static void +in_set_vhid(int vhid) +{ + in_addreq.ifra_vhid = vhid; +} + + static struct afswtch af_inet = { .af_name = "inet", .af_af = AF_INET, @@ -297,6 +304,7 @@ static struct afswtch af_inet = { .af_postproc = in_postproc, .af_status_tunnel = in_status_tunnel, .af_settunnel = in_set_tunnel, + .af_setvhid = in_set_vhid, .af_difaddr = SIOCDIFADDR, .af_aifaddr = SIOCAIFADDR, .af_ridreq = &in_ridreq, diff --git a/sbin/ifconfig/af_inet6.c b/sbin/ifconfig/af_inet6.c index 0f4e0e75e44a..1bb08c8a6a5a 100644 --- a/sbin/ifconfig/af_inet6.c +++ b/sbin/ifconfig/af_inet6.c @@ -555,6 +555,12 @@ in6_set_tunnel(int s, struct addrinfo *srcres, struct addrinfo *dstres) warn("SIOCSIFPHYADDR_IN6"); } +static void +in6_set_vhid(int vhid) +{ + in6_addreq.ifra_vhid = vhid; +} + static struct cmd inet6_cmds[] = { DEF_CMD_ARG("prefixlen", setifprefixlen), DEF_CMD("anycast", IN6_IFF_ANYCAST, setip6flags), @@ -605,6 +611,7 @@ static struct afswtch af_inet6 = { .af_postproc = in6_postproc, .af_status_tunnel = in6_status_tunnel, .af_settunnel = in6_set_tunnel, + .af_setvhid = in6_set_vhid, .af_difaddr = SIOCDIFADDR_IN6, .af_aifaddr = SIOCAIFADDR_IN6, .af_ridreq = &in6_addreq, diff --git a/sbin/ifconfig/carp.c b/sbin/ifconfig/carp.c index 2a2d8ce407ab..cc38eed4cb4b 100644 --- a/sbin/ifconfig/carp.c +++ b/sbin/ifconfig/carp.c @@ -111,31 +111,9 @@ setcarp_vhid(const char *val, int d, int s, const struct afswtch *afp) errx(1, "vhid must be greater than 0 and less than %u", CARP_MAXVHID); - switch (afp->af_af) { -#ifdef INET - case AF_INET: - { - struct in_aliasreq *ifra; - - ifra = (struct in_aliasreq *)afp->af_addreq; - ifra->ifra_vhid = carpr_vhid; - break; - } -#endif -#ifdef INET6 - case AF_INET6: - { - struct in6_aliasreq *ifra; - - ifra = (struct in6_aliasreq *)afp->af_addreq; - ifra->ifra_vhid = carpr_vhid; - break; - } -#endif - default: + if (afp->af_setvhid == NULL) errx(1, "%s doesn't support carp(4)", afp->af_name); - } - + afp->af_setvhid(carpr_vhid); callback_register(setcarp_callback, NULL); } diff --git a/sbin/ifconfig/ifconfig.h b/sbin/ifconfig/ifconfig.h index 70a2c92199b6..7b2b88a4dfac 100644 --- a/sbin/ifconfig/ifconfig.h +++ b/sbin/ifconfig/ifconfig.h @@ -161,6 +161,7 @@ struct io_handler { struct snl_state *ss; /* NETLINK_ROUTE snl(3) socket */ }; +typedef void af_setvhid_f(int vhid); typedef void af_status_nl_f(struct ifconfig_args *args, struct io_handler *h, if_link_t *link, if_addr_t *ifa); @@ -188,6 +189,7 @@ struct afswtch { void (*af_getprefix)(const char *, int); void (*af_postproc)(int s, const struct afswtch *, int newaddr, int ifflags); + af_setvhid_f *af_setvhid; /* Set CARP vhid for an address */ u_long af_difaddr; /* set dst if address ioctl */ u_long af_aifaddr; /* set if address ioctl */ void *af_ridreq; /* */