From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: passt.top; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=MvhnsRMl; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTPS id DBDF75A061E for ; Tue, 28 Jan 2025 00:31:42 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1738020701; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=tSitKdG8UnQqQg8azh6zD2Lv/1jSuQ7D8JmaA5gGKqg=; b=MvhnsRMlBKJ+CoTo31S/V06BK88A/d/YTWF8uJmsc16EWTCNSU3staVvTi63NDi6I/QisI Lyh+Rtu+23RORtbu24lHkCHGq168cxhXBV/poMn9MC/5mRvclMMSiP+ux6gNIxCVJ3eFen Z9eq5yVSQ+uz7cwMCcH6YmVyYD7xT/s= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-407-HgU-MDjFMMa4AkW6AtlUxA-1; Mon, 27 Jan 2025 18:31:38 -0500 X-MC-Unique: HgU-MDjFMMa4AkW6AtlUxA-1 X-Mimecast-MFC-AGG-ID: HgU-MDjFMMa4AkW6AtlUxA Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4361d4e8359so36647765e9.3 for ; Mon, 27 Jan 2025 15:31:38 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738020697; x=1738625497; h=mime-version:organization:references:in-reply-to:message-id:subject :cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=tSitKdG8UnQqQg8azh6zD2Lv/1jSuQ7D8JmaA5gGKqg=; b=A0EssZNAevFAmkjBevnIVGqonjGRPOc7kgoM+fK9gSkyrk5c1J6ozOGMRz3ME+3nUW 7LENpZtGp/aYNvQz6tTUw/fZKjXQDo3agPHaPhfCTys2Co4sjA1GMU3FV/deUiOaOt2a I9S3vQ+FbMOuj2+QvooEPj/ziJX7GVqZQl2YUGJjTAOP5iUkondceAlX7Wdp0iD4A52J oPFty0JA5ptFdSSoMEsHMTtFDxthG3P4ibgdoYvbtBgwgpwoh6TZIsciGOFdHMO+ehTX O24euhSXsPHe0UhZqzstTPenPmrbj/AmgUqJpfr8uIetcA+btO84tQitcsYGiFst+fuh NcHQ== X-Gm-Message-State: AOJu0YxErHpZw3L7zBzCnJmg7BvRWREiILDt2seeeNG2CHPaswxOFtDU nFYJ0YInRtYxWSw41ndcrIXiCqdcR51PTI2WDkC2o+kLB58GwBm2406NQUx4c8fSChYbmktMCFH TSHqo/A2yG2Te/vg7458oo1Quufc+KrfqnyJljG7PM/dC3YYMEA== X-Gm-Gg: ASbGncsZWctJMQTo4LiYl9/ING/1hBg/6av+HeZRoF5X+ZjQ2zOW/9ZwQNKa1usQ1dc aEmaObupSKZ5JI2ho/mRz9K6N99LkK/1DPlPKGWIna+dJxHtRkDlpdjC67XZ2m4RO/FcwAeowLr UQGaTGrOnSP3W9dpPu/GbOqo5LI0Xstrc70SamFrrDHVOd9V6mWa6zbGOpcOKF0UrvC0+5BvJzf mW/cb/e1ZxpYlbOeWSQGYIqS/soyHFxPEMTqOppN5+8MeU0rxM7CmHBAur7TKbLwycjxQ0XLS5v 2WC1PNpFIoEUzx+u X-Received: by 2002:a05:600c:1c16:b0:435:32e:8270 with SMTP id 5b1f17b1804b1-438913de562mr398182055e9.14.1738020697112; Mon, 27 Jan 2025 15:31:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IFPhHbGyyn2BXE/71PCtPQBzNBoIYvZpMWdjDBB/YfOQp9fU0prjvFOE/9h1Dz6x9YMmRa2mA== X-Received: by 2002:a05:600c:1c16:b0:435:32e:8270 with SMTP id 5b1f17b1804b1-438913de562mr398181955e9.14.1738020696711; Mon, 27 Jan 2025 15:31:36 -0800 (PST) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [2a10:fc81:a806:d6a9::1]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-438bd48a94asm148235305e9.23.2025.01.27.15.31.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jan 2025 15:31:35 -0800 (PST) Date: Tue, 28 Jan 2025 00:31:33 +0100 From: Stefano Brivio To: passt-dev@passt.top Subject: Re: [PATCH 7/7] Introduce passt-repair Message-ID: <20250128003133.19011f58@elisabeth> In-Reply-To: <20250127231532.672363-8-sbrivio@redhat.com> References: <20250127231532.672363-1-sbrivio@redhat.com> <20250127231532.672363-8-sbrivio@redhat.com> Organization: Red Hat X-Mailer: Claws Mail 4.2.0 (GTK 3.24.41; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: axRxH3VKNgevEOpR-KjItDDXNk3wfq0vS5fHn5LRXgU_1738020697 X-Mimecast-Originator: redhat.com Content-Type: multipart/mixed; boundary="MP_/0CUBio=ru.G3PdFExuv8DpB" Message-ID-Hash: EF2TNSUQWZMYSH2TL2KEB254DXZL6CON X-Message-ID-Hash: EF2TNSUQWZMYSH2TL2KEB254DXZL6CON X-MailFrom: sbrivio@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Laurent Vivier , David Gibson X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: --MP_/0CUBio=ru.G3PdFExuv8DpB Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Content-Disposition: inline On Tue, 28 Jan 2025 00:15:32 +0100 Stefano Brivio wrote: > A privileged helper to set/clear TCP_REPAIR on sockets on behalf of > passt. Not used yet. ...but tested against source.c / target.c, attached. --- $ nc -l 9996 --- $ ./source 127.0.0.1 9996 9898 /tmp/repair.sock sending sequence: 3244673313 receiving sequence: 2250449386 --- # ./passt-repair /tmp/repair.sock --- $ strace ./target 127.0.0.1 9996 9898 /tmp/repair.sock 3244673313 2250449386 --- # ./passt-repair /tmp/repair.sock --- -- Stefano --MP_/0CUBio=ru.G3PdFExuv8DpB Content-Type: text/x-c++src Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=source.c #include #include #include #include #include #include #include #include #include #include #include int main(int argc, char **argv) { struct sockaddr_in a = { AF_INET, htons(atoi(argv[3])), { 0 }, { 0 } }; struct addrinfo hints = { 0, AF_UNSPEC, SOCK_STREAM, 0, 0, NULL, NULL, NULL }; struct sockaddr_un a_helper = { AF_UNIX, { 0 } }; int cmd, seq, s, s_helper; struct iovec iov = { &cmd, sizeof(cmd) }; char buf[CMSG_SPACE(sizeof(int))]; struct msghdr msg = { NULL, 0, &iov, 1, buf, sizeof(buf), 0 }; struct cmsghdr *cmsg = CMSG_FIRSTHDR(&msg); socklen_t seqlen = sizeof(int); struct addrinfo *r; (void)argc; if (argc != 5) { fprintf(stderr, "%s DST_ADDR DST_PORT SRC_PORT HELPER_PATH\n", argv[0]); return -1; } strcpy(a_helper.sun_path, argv[4]); getaddrinfo(argv[1], argv[2], &hints, &r); /* Connect socket to server and send some data */ s = socket(r->ai_family, SOCK_STREAM, IPPROTO_TCP); setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &((int){ 1 }), sizeof(int)); bind(s, (struct sockaddr *)&a, sizeof(a)); connect(s, r->ai_addr, r->ai_addrlen); send(s, "before migration\n", sizeof("before migration\n"), 0); /* Wait for helper */ s_helper = socket(AF_UNIX, SOCK_STREAM, 0); unlink(a_helper.sun_path); bind(s_helper, (struct sockaddr *)&a_helper, sizeof(a_helper)); listen(s_helper, 1); s_helper = accept(s_helper, NULL, NULL); /* Set up message for helper, with socket */ cmsg->cmsg_level = SOL_SOCKET; cmsg->cmsg_type = SCM_RIGHTS; cmsg->cmsg_len = CMSG_LEN(sizeof(int)); memcpy(CMSG_DATA(cmsg), &s, sizeof(s)); /* Send command to helper: turn repair mode on, wait for reply */ cmd = TCP_REPAIR_ON; sendmsg(s_helper, &msg, 0); recv(s_helper, &((int){ 0 }), 1, 0); /* Terminate helper */ cmd = INT_MAX; sendmsg(s_helper, &msg, 0); /* Get sending sequence */ seq = TCP_SEND_QUEUE; setsockopt(s, SOL_TCP, TCP_REPAIR_QUEUE, &seq, sizeof(seq)); getsockopt(s, SOL_TCP, TCP_QUEUE_SEQ, &seq, &seqlen); fprintf(stdout, "sending sequence: %u\n", seq); /* Get receiving sequence */ seq = TCP_RECV_QUEUE; setsockopt(s, SOL_TCP, TCP_REPAIR_QUEUE, &seq, sizeof(seq)); getsockopt(s, SOL_TCP, TCP_QUEUE_SEQ, &seq, &seqlen); fprintf(stdout, "receiving sequence: %u\n", seq); } --MP_/0CUBio=ru.G3PdFExuv8DpB Content-Type: text/x-c++src Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=target.c #include #include #include #include #include #include #include #include #include #include #include int main(int argc, char **argv) { struct sockaddr_in a = { AF_INET, htons(atoi(argv[3])), { 0 }, { 0 } }; struct addrinfo hints = { 0, AF_UNSPEC, SOCK_STREAM, 0, 0, NULL, NULL, NULL }; struct sockaddr_un a_helper = { AF_UNIX, { 0 } }; int cmd, s, s_helper, seq; struct iovec iov = { &cmd, sizeof(cmd) }; char buf[CMSG_SPACE(sizeof(int))]; struct msghdr msg = { NULL, 0, &iov, 1, buf, sizeof(buf), 0 }; struct cmsghdr *cmsg = CMSG_FIRSTHDR(&msg); struct addrinfo *r; (void)argc; strcpy(a_helper.sun_path, argv[4]); getaddrinfo(argv[1], argv[2], &hints, &r); if (argc != 7) { fprintf(stderr, "%s DST_ADDR DST_PORT SRC_PORT HELPER_PATH SSEQ RSEQ\n", argv[0]); return -1; } /* Prepare socket, bind to source port */ s = socket(r->ai_family, SOCK_STREAM, IPPROTO_TCP); setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &((int){ 1 }), sizeof(int)); bind(s, (struct sockaddr *)&a, sizeof(a)); /* Wait for helper */ s_helper = socket(AF_UNIX, SOCK_STREAM, 0); unlink(a_helper.sun_path); bind(s_helper, (struct sockaddr *)&a_helper, sizeof(a_helper)); listen(s_helper, 1); s_helper = accept(s_helper, NULL, NULL); /* Set up message for helper, with socket */ cmsg->cmsg_level = SOL_SOCKET; cmsg->cmsg_type = SCM_RIGHTS; cmsg->cmsg_len = CMSG_LEN(sizeof(int)); memcpy(CMSG_DATA(cmsg), &s, sizeof(s)); /* Send command to helper: turn repair mode on, wait for reply */ cmd = TCP_REPAIR_ON; sendmsg(s_helper, &msg, 0); recv(s_helper, &((int){ 0 }), 1, 0); /* Set sending sequence */ seq = TCP_SEND_QUEUE; setsockopt(s, SOL_TCP, TCP_REPAIR_QUEUE, &seq, sizeof(seq)); seq = atoi(argv[5]); setsockopt(s, SOL_TCP, TCP_QUEUE_SEQ, &seq, sizeof(seq)); /* Set receiving sequence */ seq = TCP_RECV_QUEUE; setsockopt(s, SOL_TCP, TCP_REPAIR_QUEUE, &seq, sizeof(seq)); seq = atoi(argv[6]); setsockopt(s, SOL_TCP, TCP_QUEUE_SEQ, &seq, sizeof(seq)); /* Connect setting kernel state only, without actual SYN / handshake */ connect(s, r->ai_addr, r->ai_addrlen); /* Send command to helper: turn repair mode on, wait for reply */ cmd = TCP_REPAIR_OFF; sendmsg(s_helper, &msg, 0); recv(s_helper, &((int){ 0 }), 1, 0); /* Terminate helper */ cmd = INT_MAX; sendmsg(s_helper, &msg, 0); /* Send some more data */ send(s, "after migration\n", sizeof("after migration\n"), 0); } --MP_/0CUBio=ru.G3PdFExuv8DpB--