From nobody Fri Apr 26 02:52:30 2024 Delivered-To: wpasupplicant.patchew@gmail.com Received: by 2002:a02:b119:0:0:0:0:0 with SMTP id r25csp1107865jah; Wed, 12 Jan 2022 14:16:25 -0800 (PST) X-Google-Smtp-Source: ABdhPJxUUDGpnKMhnMQd3BzFr/77TWNBs8u//FRxk8ATwSkw0x3WzpAWPH45FCH0ESQKYyaMIEsW X-Received: by 2002:a05:620a:4108:: with SMTP id j8mr1447863qko.410.1642025785444; Wed, 12 Jan 2022 14:16:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642025785; cv=none; d=google.com; s=arc-20160816; b=owL+bGf32pBg4AeAtt74to0tHxviuVonROJF75GH/IMYuWjrRjkLo5KnakG4QBTtqx LnS6PmFS1U7AHPqJNssgCNR1g9eQ+WHLjl+cOB/DqPS8XLi5hY+6vCIyYqCVz9ZQEeuB bXwc9M3CWJmwU/C/8W3ZCWBJqyOBw4lCrkjNHKdn5IPnoEPbEbosFMHGY6M2VI9XFjTR /Ow5ylKMymJz/zUINi3cHKKyeHl5cUsNQwAxbosKL0tnP4nhLzmB+Jrt9LQ1BCprVzlO xJvkcDxbNHOOB1slNVamC8wwRs0PzXsTm+TiwYox/5Qecw1oeeMmIEELMpfUSzyp3Gbz AYpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:to:from:dkim-signature; bh=EpQxrWc4jiLOzQJTXldVlA43SbhNhX7c88Y76Ma74d4=; b=mbkiS6QDuVcT9IhWDtsm5aB/vCgb9BOcD07K6bLnQGI1WsXKgfoXaPu1jSo6C+m5WF KwPFMenHRgH3HqMzf9oiePyTWMaRLq4BGp10dhEtkb401rM7MvFnVuvMApXmYVhRmpfc 4hi4EgNZ3lY16OukRy62L9NqIIJgvzdkhA/e/Rgj0lcQIFtXkRtHDYdX8EOQlq9Ovlsl gQtlPLqLppFz5v82iKrHXYxgfNka+MFy4OCVl3qGOr2jBCC5UJ5/2Ws9xLHw6I6Zk46D 8CFJ4Ns8HxM2E9ugSwpBAKYUH3mq7QQrJzZkDPA9hCc9j90kb6yBKN7qUPijmSApvg81 T1Xg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=IqZrlJUa; spf=pass (google.com: domain of mptcp+bounces-3085-wpasupplicant.patchew=gmail.com@lists.linux.dev designates 2604:1380:1:3600::1 as permitted sender) smtp.mailfrom="mptcp+bounces-3085-wpasupplicant.patchew=gmail.com@lists.linux.dev"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ewr.edge.kernel.org (ewr.edge.kernel.org. [2604:1380:1:3600::1]) by mx.google.com with ESMTPS id u36si572424qtc.32.2022.01.12.14.16.25 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Jan 2022 14:16:25 -0800 (PST) Received-SPF: pass (google.com: domain of mptcp+bounces-3085-wpasupplicant.patchew=gmail.com@lists.linux.dev designates 2604:1380:1:3600::1 as permitted sender) client-ip=2604:1380:1:3600::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=IqZrlJUa; spf=pass (google.com: domain of mptcp+bounces-3085-wpasupplicant.patchew=gmail.com@lists.linux.dev designates 2604:1380:1:3600::1 as permitted sender) smtp.mailfrom="mptcp+bounces-3085-wpasupplicant.patchew=gmail.com@lists.linux.dev"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ewr.edge.kernel.org (Postfix) with ESMTPS id 442CA1C0C62 for ; Wed, 12 Jan 2022 22:16:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 41F172CAC; Wed, 12 Jan 2022 22:16:16 +0000 (UTC) X-Original-To: mptcp@lists.linux.dev Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 369AA2CAB for ; Wed, 12 Jan 2022 22:16:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1642025775; x=1673561775; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=0PKIoAWBG01b+R+jq+AHrVNak7XFUEjF6B66uXs43o8=; b=IqZrlJUaw47+dNjrI+fVxML9CjOy9FKX2963AJLEmeFFs1TyETqpvA8p AkHbHWZvjo9WKlWcRVzcKgQ+LQxPdVNNT95/IVKBIcBJmOAdb5oEzAkjI iNI95H2cqub6uF/4QZ2doMY51NLuTCs+P8r80S+Ollu2H22qSety2Rukc pPpbFmBL0ncmRsfmyr6MgrPqg2l4yLR52Zsfalqm/KRWGjOH1+lrWuRtD 8Q+zHN2yrlKR/rtqWDoEBZRKhCS6z72YbO/xWtmKZP+KRAy3LaLToe9jx 0c7RWfNgrcuxh7kh5+rFjLY0PEw6PHB7cRz7fRIsdnaebFxIWUh6Q3SDE Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10225"; a="307213944" X-IronPort-AV: E=Sophos;i="5.88,284,1635231600"; d="scan'208";a="307213944" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jan 2022 14:16:07 -0800 X-IronPort-AV: E=Sophos;i="5.88,284,1635231600"; d="scan'208";a="490907370" Received: from otc-tsn-4.jf.intel.com ([10.23.153.135]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jan 2022 14:16:07 -0800 From: Kishen Maloor To: kishen.maloor@intel.com, mptcp@lists.linux.dev Subject: [PATCH mptcp-next v2 14/21] mptcp: selftests: support MPTCP_PM_CMD_ANNOUNCE Date: Wed, 12 Jan 2022 17:15:16 -0500 Message-Id: <20220112221523.1829397-15-kishen.maloor@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220112221523.1829397-1-kishen.maloor@intel.com> References: <20220112221523.1829397-1-kishen.maloor@intel.com> Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This change updates the "pm_nl_ctl" testing sample with an "ann" (announce) option to support the newly added netlink interface command MPTCP_PM_CMD_ANNOUNCE to issue ADD_ADDR advertisements over the chosen MPTCP connection. E.g. ./pm_nl_ctl ann 192.168.122.75 token 823274047 id 25 dev enp1s0 Signed-off-by: Kishen Maloor --- tools/testing/selftests/net/mptcp/pm_nl_ctl.c | 130 ++++++++++++++++++ 1 file changed, 130 insertions(+) diff --git a/tools/testing/selftests/net/mptcp/pm_nl_ctl.c b/tools/testing/= selftests/net/mptcp/pm_nl_ctl.c index 354784512748..76dfb5a8984a 100644 --- a/tools/testing/selftests/net/mptcp/pm_nl_ctl.c +++ b/tools/testing/selftests/net/mptcp/pm_nl_ctl.c @@ -6,6 +6,7 @@ #include #include #include +#include =20 #include #include @@ -26,6 +27,7 @@ static void syntax(char *argv[]) { fprintf(stderr, "%s add|get|set|del|flush|dump|accept []\n", argv[0= ]); fprintf(stderr, "\tadd [flags signal|subflow|backup|fullmesh] [id ] [= dev ] \n"); + fprintf(stderr, "\tann id token [port ] [dev ]\n"); fprintf(stderr, "\tdel []\n"); fprintf(stderr, "\tget \n"); fprintf(stderr, "\tset [flags backup|nobackup]\n"); @@ -170,6 +172,132 @@ static int resolve_mptcp_pm_netlink(int fd) return genl_parse_getfamily((void *)data); } =20 +int announce_addr(int fd, int pm_family, int argc, char *argv[]) +{ + char data[NLMSG_ALIGN(sizeof(struct nlmsghdr)) + + NLMSG_ALIGN(sizeof(struct genlmsghdr)) + + 1024]; + u_int32_t flags =3D MPTCP_PM_ADDR_FLAG_SIGNAL; + u_int32_t token =3D UINT_MAX; + struct rtattr *rta, *addr; + u_int32_t id =3D UINT_MAX; + struct nlmsghdr *nh; + u_int16_t family; + int addr_start; + int off =3D 0; + int arg; + + memset(data, 0, sizeof(data)); + nh =3D (void *)data; + off =3D init_genl_req(data, pm_family, MPTCP_PM_CMD_ANNOUNCE, + MPTCP_PM_VER); + + if (argc < 7) + syntax(argv); + + /* local-ip header */ + addr_start =3D off; + addr =3D (void *)(data + off); + addr->rta_type =3D NLA_F_NESTED | MPTCP_PM_ATTR_ADDR; + addr->rta_len =3D RTA_LENGTH(0); + off +=3D NLMSG_ALIGN(addr->rta_len); + + /* local-ip data */ + /* record addr type */ + rta =3D (void *)(data + off); + if (inet_pton(AF_INET, argv[2], RTA_DATA(rta))) { + family =3D AF_INET; + rta->rta_type =3D MPTCP_PM_ADDR_ATTR_ADDR4; + rta->rta_len =3D RTA_LENGTH(4); + } else if (inet_pton(AF_INET6, argv[2], RTA_DATA(rta))) { + family =3D AF_INET6; + rta->rta_type =3D MPTCP_PM_ADDR_ATTR_ADDR6; + rta->rta_len =3D RTA_LENGTH(16); + } else + error(1, errno, "can't parse ip %s", argv[2]); + off +=3D NLMSG_ALIGN(rta->rta_len); + + /* addr family */ + rta =3D (void *)(data + off); + rta->rta_type =3D MPTCP_PM_ADDR_ATTR_FAMILY; + rta->rta_len =3D RTA_LENGTH(2); + memcpy(RTA_DATA(rta), &family, 2); + off +=3D NLMSG_ALIGN(rta->rta_len); + + /* addr flags (..SIGNAL) */ + rta =3D (void *)(data + off); + rta->rta_type =3D MPTCP_PM_ADDR_ATTR_FLAGS; + rta->rta_len =3D RTA_LENGTH(4); + memcpy(RTA_DATA(rta), &flags, 4); + off +=3D NLMSG_ALIGN(rta->rta_len); + + for (arg =3D 3; arg < argc; arg++) { + if (!strcmp(argv[arg], "id")) { + /* local-id */ + if (++arg >=3D argc) + error(1, 0, " missing id value"); + + id =3D atoi(argv[arg]); + rta =3D (void *)(data + off); + rta->rta_type =3D MPTCP_PM_ADDR_ATTR_ID; + rta->rta_len =3D RTA_LENGTH(1); + memcpy(RTA_DATA(rta), &id, 1); + off +=3D NLMSG_ALIGN(rta->rta_len); + } else if (!strcmp(argv[arg], "dev")) { + /* for the if_index */ + int32_t ifindex; + + if (++arg >=3D argc) + error(1, 0, " missing dev name"); + + ifindex =3D if_nametoindex(argv[arg]); + if (!ifindex) + error(1, errno, "unknown device %s", argv[arg]); + + rta =3D (void *)(data + off); + rta->rta_type =3D MPTCP_PM_ADDR_ATTR_IF_IDX; + rta->rta_len =3D RTA_LENGTH(4); + memcpy(RTA_DATA(rta), &ifindex, 4); + off +=3D NLMSG_ALIGN(rta->rta_len); + } else if (!strcmp(argv[arg], "port")) { + /* local-port (optional) */ + u_int16_t port; + + if (++arg >=3D argc) + error(1, 0, " missing port value"); + + port =3D atoi(argv[arg]); + rta =3D (void *)(data + off); + rta->rta_type =3D MPTCP_PM_ADDR_ATTR_PORT; + rta->rta_len =3D RTA_LENGTH(2); + memcpy(RTA_DATA(rta), &port, 2); + off +=3D NLMSG_ALIGN(rta->rta_len); + } else if (!strcmp(argv[arg], "token")) { + /* MPTCP connection token */ + if (++arg >=3D argc) + error(1, 0, " missing token value"); + + token =3D atoi(argv[arg]); + } else + error(1, 0, "unknown keyword %s", argv[arg]); + } + addr->rta_len =3D off - addr_start; + + if (id =3D=3D UINT_MAX || token =3D=3D UINT_MAX) + error(1, 0, " missing mandatory inputs"); + + /* token */ + rta =3D (void *)(data + off); + rta->rta_type =3D MPTCP_PM_ATTR_TOKEN; + rta->rta_len =3D RTA_LENGTH(4); + memcpy(RTA_DATA(rta), &token, 4); + off +=3D NLMSG_ALIGN(rta->rta_len); + + do_nl_req(fd, nh, off, 0); + + return 0; +} + int add_addr(int fd, int pm_family, int argc, char *argv[]) { char data[NLMSG_ALIGN(sizeof(struct nlmsghdr)) + @@ -744,6 +872,8 @@ int main(int argc, char *argv[]) =20 if (!strcmp(argv[1], "add")) return add_addr(fd, pm_family, argc, argv); + else if (!strcmp(argv[1], "ann")) + return announce_addr(fd, pm_family, argc, argv); else if (!strcmp(argv[1], "del")) return del_addr(fd, pm_family, argc, argv); else if (!strcmp(argv[1], "flush")) --=20 2.31.1