From patchwork Tue Sep 27 08:23:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wojciech Drewek X-Patchwork-Id: 12990141 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5A25AC07E9D for ; Tue, 27 Sep 2022 08:27:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230384AbiI0I1F (ORCPT ); Tue, 27 Sep 2022 04:27:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230369AbiI0I1D (ORCPT ); Tue, 27 Sep 2022 04:27:03 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5276DA5715 for ; Tue, 27 Sep 2022 01:27:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1664267223; x=1695803223; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=aOUryZg2RFJaTZAkeDZYJzOrC0nqhpkz7rzsMMD9XU4=; b=ddOMRwCefybW8NSUiH1hK/heN+NZX2qNvVT/Qdndbqjz2/+hY0jcx66o CTSzgqTy7Fmv5ctfVpDMHFs1uBTHpSJVZCJmfaSuTsK/wAa9dxvwJZxNa jmy4ufBV9JCbYFmZA6vZeLuN0EiqJnvtBigl6m1EqYekCuTRzxmcyFpr0 ddKEzUAXsUvd7hgTkCxOWNUP/C1YTO7fHBjM0IEj0y1nq56GTZEKnKoiD 8difAEgKaOeB0gu0TiEqT0RRalfvGmfQN1ToD1D1++5abVZet0D2JHF3C wUrlc/rc3StjuVKhuXotCU42+rcvwB+37f4BmbCs/4oFED72CQUJYPnms g==; X-IronPort-AV: E=McAfee;i="6500,9779,10482"; a="327612358" X-IronPort-AV: E=Sophos;i="5.93,348,1654585200"; d="scan'208";a="327612358" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Sep 2022 01:27:02 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10482"; a="652199935" X-IronPort-AV: E=Sophos;i="5.93,348,1654585200"; d="scan'208";a="652199935" Received: from irvmail001.ir.intel.com ([10.43.11.63]) by orsmga008.jf.intel.com with ESMTP; 27 Sep 2022 01:27:01 -0700 Received: from switcheroo.igk.intel.com (switcheroo.igk.intel.com [172.22.229.137]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id 28R8QxxK023862; Tue, 27 Sep 2022 09:27:00 +0100 From: Wojciech Drewek To: netdev@vger.kernel.org Cc: dsahern@gmail.com, stephen@networkplumber.org, gnault@redhat.com Subject: [PATCH iproute2-next 1/3] uapi: move IPPROTO_L2TP to in.h Date: Tue, 27 Sep 2022 10:23:16 +0200 Message-Id: <20220927082318.289252-2-wojciech.drewek@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220927082318.289252-1-wojciech.drewek@intel.com> References: <20220927082318.289252-1-wojciech.drewek@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: dsahern@gmail.com Reflect changes in the kernel [1]. [1] https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git/commit/?id=65b32f801bfbc54dc98144a6ec26082b59d131ee Signed-off-by: Wojciech Drewek --- include/uapi/linux/in.h | 2 ++ include/uapi/linux/l2tp.h | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/uapi/linux/in.h b/include/uapi/linux/in.h index 42cfea14401d..34b3516c9581 100644 --- a/include/uapi/linux/in.h +++ b/include/uapi/linux/in.h @@ -68,6 +68,8 @@ enum { #define IPPROTO_PIM IPPROTO_PIM IPPROTO_COMP = 108, /* Compression Header Protocol */ #define IPPROTO_COMP IPPROTO_COMP + IPPROTO_L2TP = 115, /* Layer 2 Tunnelling Protocol */ +#define IPPROTO_L2TP IPPROTO_L2TP IPPROTO_SCTP = 132, /* Stream Control Transport Protocol */ #define IPPROTO_SCTP IPPROTO_SCTP IPPROTO_UDPLITE = 136, /* UDP-Lite (RFC 3828) */ diff --git a/include/uapi/linux/l2tp.h b/include/uapi/linux/l2tp.h index 0480d2dbed1a..e7705e875200 100644 --- a/include/uapi/linux/l2tp.h +++ b/include/uapi/linux/l2tp.h @@ -13,8 +13,6 @@ #include #include -#define IPPROTO_L2TP 115 - /** * struct sockaddr_l2tpip - the sockaddr structure for L2TP-over-IP sockets * @l2tp_family: address family number AF_L2TPIP. From patchwork Tue Sep 27 08:23:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wojciech Drewek X-Patchwork-Id: 12990142 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C04A8C6FA83 for ; Tue, 27 Sep 2022 08:27:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231482AbiI0I1H (ORCPT ); Tue, 27 Sep 2022 04:27:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230404AbiI0I1E (ORCPT ); Tue, 27 Sep 2022 04:27:04 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD260A5995 for ; Tue, 27 Sep 2022 01:27:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1664267223; x=1695803223; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=04U2UlVAhDjuqMarWqmfVMDxlV+0hRbqC3fiFw8K8MI=; b=eMIwx+uoznyFWAyGPQ+9PnaBxe+RPFYNpPNJ1z1eonhMNq2+v8lI6PI3 n4jbVzGT+I9IVMdkydmlGctyeRIN/sLjBSpEHyM/29jqjI4TfqqxoUKWW nm0auUIrI3nQdutiCWRVei7w1zuivsmhcbpA52na3UorBC1XZPQpMN4/u A2RpiUB5IND1N8PBHoz8Ht11WJ7FI6MFVjZpKCtr5FyvFYpu0gzNJg5vu TfLUTE4s3cwxuf6OVcN2cpRxz2PIZTRUvBhc4r6hMEQgCcPEn9pw4631u hYuC77zF/NXpaoo4qFcSR213Crw/gXyG4H0WYp4OaEj0EvmaAxlDd0MiU w==; X-IronPort-AV: E=McAfee;i="6500,9779,10482"; a="327612359" X-IronPort-AV: E=Sophos;i="5.93,348,1654585200"; d="scan'208";a="327612359" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Sep 2022 01:27:02 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10482"; a="652199937" X-IronPort-AV: E=Sophos;i="5.93,348,1654585200"; d="scan'208";a="652199937" Received: from irvmail001.ir.intel.com ([10.43.11.63]) by orsmga008.jf.intel.com with ESMTP; 27 Sep 2022 01:27:01 -0700 Received: from switcheroo.igk.intel.com (switcheroo.igk.intel.com [172.22.229.137]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id 28R8QxxL023862; Tue, 27 Sep 2022 09:27:00 +0100 From: Wojciech Drewek To: netdev@vger.kernel.org Cc: dsahern@gmail.com, stephen@networkplumber.org, gnault@redhat.com Subject: [PATCH iproute2-next 2/3] uapi: Add TCA_FLOWER_KEY_L2TPV3_SID Date: Tue, 27 Sep 2022 10:23:17 +0200 Message-Id: <20220927082318.289252-3-wojciech.drewek@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220927082318.289252-1-wojciech.drewek@intel.com> References: <20220927082318.289252-1-wojciech.drewek@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: dsahern@gmail.com Reflect changes in the kernel [1]. [1] https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git/commit/?id=8b189ea08c334f25dbb3d076f8adb8b80491d01d Signed-off-by: Wojciech Drewek --- include/uapi/linux/pkt_cls.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/uapi/linux/pkt_cls.h b/include/uapi/linux/pkt_cls.h index c142c0f8ed8a..b4fb72ac680a 100644 --- a/include/uapi/linux/pkt_cls.h +++ b/include/uapi/linux/pkt_cls.h @@ -592,6 +592,8 @@ enum { TCA_FLOWER_KEY_PPPOE_SID, /* be16 */ TCA_FLOWER_KEY_PPP_PROTO, /* be16 */ + TCA_FLOWER_KEY_L2TPV3_SID, /* be32 */ + __TCA_FLOWER_MAX, }; From patchwork Tue Sep 27 08:23:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wojciech Drewek X-Patchwork-Id: 12990143 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 97394C07E9D for ; Tue, 27 Sep 2022 08:27:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231513AbiI0I1I (ORCPT ); Tue, 27 Sep 2022 04:27:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60360 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231453AbiI0I1E (ORCPT ); Tue, 27 Sep 2022 04:27:04 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1177A4B9C for ; Tue, 27 Sep 2022 01:27:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1664267223; x=1695803223; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=VXhbykHihPAUBFCrh0oJNgEZ3P3H6jJ85FST6uFnx4s=; b=YkZrMmzB749dJDIJX5WUblVCac/yXAJS6rGj6Kt/lywmnvoxjvv+0KQx CpfGbK57lz1bv/QhEya+aLn4xehvy6wwv/KSxYFCMrw7P/9XZpYfX8T1Q IrwwcsIaYlQVkOdn1KcZPQWIJhuXC6JTw+5Pkv8BQ3Idnj2g2XG5ffGOF iMz17lgS2BpYY1al65YTuCfwcHLlqXP9ljhEr+MY58sRscH2g/NjkKdik WxUDRRE3l0JA4mpXkVCnfsLC8LYTD6bLl8Frt72J4JRdpTF1UXl7hfWVz /LnEWl9J7DO9szobdjQKhdTQI02fNChu2j1V9pdn2BbGJPNZic/Tw90lb g==; X-IronPort-AV: E=McAfee;i="6500,9779,10482"; a="327612361" X-IronPort-AV: E=Sophos;i="5.93,348,1654585200"; d="scan'208";a="327612361" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Sep 2022 01:27:03 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10482"; a="652199940" X-IronPort-AV: E=Sophos;i="5.93,348,1654585200"; d="scan'208";a="652199940" Received: from irvmail001.ir.intel.com ([10.43.11.63]) by orsmga008.jf.intel.com with ESMTP; 27 Sep 2022 01:27:02 -0700 Received: from switcheroo.igk.intel.com (switcheroo.igk.intel.com [172.22.229.137]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id 28R8QxxM023862; Tue, 27 Sep 2022 09:27:01 +0100 From: Wojciech Drewek To: netdev@vger.kernel.org Cc: dsahern@gmail.com, stephen@networkplumber.org, gnault@redhat.com Subject: [PATCH iproute2-next 3/3] f_flower: Introduce L2TPv3 support Date: Tue, 27 Sep 2022 10:23:18 +0200 Message-Id: <20220927082318.289252-4-wojciech.drewek@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220927082318.289252-1-wojciech.drewek@intel.com> References: <20220927082318.289252-1-wojciech.drewek@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: dsahern@gmail.com Add support for matching on L2TPv3 session ID. Session ID can be specified only when ip proto was set to IPPROTO_L2TP. L2TPv3 might be transported over IP or over UDP, this implementation is only about L2TPv3 over IP. IPv6 is also supported, in this case next header is set to IPPROTO_L2TP. Example filter: # tc filter add dev eth0 ingress prio 1 protocol ip \ flower \ ip_proto l2tp \ l2tpv3_sid 1234 \ skip_sw \ action drop Signed-off-by: Wojciech Drewek --- man/man8/tc-flower.8 | 11 +++++++++-- tc/f_flower.c | 45 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/man/man8/tc-flower.8 b/man/man8/tc-flower.8 index 5e486ea31d37..4de823e4ef3e 100644 --- a/man/man8/tc-flower.8 +++ b/man/man8/tc-flower.8 @@ -54,7 +54,9 @@ flower \- flow based traffic control filter .IR BOS " | " .B mpls_ttl .IR TTL " | " -.BR ip_proto " { " tcp " | " udp " | " sctp " | " icmp " | " icmpv6 " | " +.B l2tpv3_sid +.IR LSID " | " +.BR ip_proto " { " tcp " | " udp " | " sctp " | " icmp " | " icmpv6 " | " l2tp " | " .IR IP_PROTO " } | " .B ip_tos .IR MASKED_IP_TOS " | " @@ -291,11 +293,16 @@ entry. .I TTL is an unsigned 8 bit value in decimal format. .TP +.BI l2tpv3_sid " LSID" +Match on L2TPv3 session id field transported over IP or IPv6. +.I LSID +is an unsigned 32 bit value in decimal format. +.TP .BI ip_proto " IP_PROTO" Match on layer four protocol. .I IP_PROTO may be -.BR tcp ", " udp ", " sctp ", " icmp ", " icmpv6 +.BR tcp ", " udp ", " sctp ", " icmp ", " icmpv6 ", " l2tp or an unsigned 8bit value in hexadecimal format. .TP .BI ip_tos " MASKED_IP_TOS" diff --git a/tc/f_flower.c b/tc/f_flower.c index 069896a48f33..cf19009c63e1 100644 --- a/tc/f_flower.c +++ b/tc/f_flower.c @@ -60,7 +60,7 @@ static void explain(void) " ppp_proto [ ipv4 | ipv6 | mpls_uc | mpls_mc | PPP_PROTO ]" " dst_mac MASKED-LLADDR |\n" " src_mac MASKED-LLADDR |\n" - " ip_proto [tcp | udp | sctp | icmp | icmpv6 | IP-PROTO ] |\n" + " ip_proto [tcp | udp | sctp | icmp | icmpv6 | l2tp | IP-PROTO ] |\n" " ip_tos MASKED-IP_TOS |\n" " ip_ttl MASKED-IP_TTL |\n" " mpls LSE-LIST |\n" @@ -68,6 +68,7 @@ static void explain(void) " mpls_tc TC |\n" " mpls_bos BOS |\n" " mpls_ttl TTL |\n" + " l2tpv3_sid LSID |\n" " dst_ip PREFIX |\n" " src_ip PREFIX |\n" " dst_port PORT-NUMBER |\n" @@ -428,6 +429,11 @@ static int flower_parse_ip_proto(char *str, __be16 eth_type, int type, if (eth_type != htons(ETH_P_IPV6)) goto err; ip_proto = IPPROTO_ICMPV6; + } else if (!strcmp(str, "l2tp")) { + if (eth_type != htons(ETH_P_IP) && + eth_type != htons(ETH_P_IPV6)) + goto err; + ip_proto = IPPROTO_L2TP; } else { ret = get_u8(&ip_proto, str, 16); if (ret) @@ -646,6 +652,28 @@ static int flower_parse_icmp(char *str, __u16 eth_type, __u8 ip_proto, return flower_parse_u8(str, value_type, mask_type, NULL, NULL, n); } +static int flower_parse_l2tpv3(char *str, __be16 eth_type, __u8 ip_proto, + struct nlmsghdr *n) +{ + __be32 sid; + int ret; + + if ((eth_type != htons(ETH_P_IP) && eth_type != htons(ETH_P_IPV6)) || + ip_proto != IPPROTO_L2TP) { + fprintf(stderr, + "Can't set \"l2tpv3_sid\" if ethertype isn't IP and IPv6 or ip_proto isn't l2tp\n"); + return -1; + } + ret = get_be32(&sid, str, 10); + if (ret < 0) { + fprintf(stderr, "Illegal \"l2tpv3 session id\"\n"); + return -1; + } + addattr32(n, MAX_MSG, TCA_FLOWER_KEY_L2TPV3_SID, sid); + + return 0; +} + static int flower_port_attr_type(__u8 ip_proto, enum flower_endpoint endpoint) { if (ip_proto == IPPROTO_TCP) @@ -1840,6 +1868,11 @@ static int flower_parse_opt(struct filter_util *qu, char *handle, fprintf(stderr, "Illegal \"icmp code\"\n"); return -1; } + } else if (!strcmp(*argv, "l2tpv3_sid")) { + NEXT_ARG(); + ret = flower_parse_l2tpv3(*argv, eth_type, ip_proto, n); + if (ret < 0) + return -1; } else if (matches(*argv, "arp_tip") == 0) { NEXT_ARG(); ret = flower_parse_arp_ip_addr(*argv, eth_type, @@ -2153,6 +2186,8 @@ static void flower_print_ip_proto(__u8 *p_ip_proto, sprintf(out, "icmp"); else if (ip_proto == IPPROTO_ICMPV6) sprintf(out, "icmpv6"); + else if (ip_proto == IPPROTO_L2TP) + sprintf(out, "l2tp"); else sprintf(out, "%02x", ip_proto); @@ -2880,6 +2915,14 @@ static int flower_print_opt(struct filter_util *qu, FILE *f, flower_print_masked_u8("icmp_code", tb[nl_type], tb[nl_mask_type], NULL); + if (tb[TCA_FLOWER_KEY_L2TPV3_SID]) { + struct rtattr *attr = tb[TCA_FLOWER_KEY_L2TPV3_SID]; + + print_nl(); + print_uint(PRINT_ANY, "l2tpv3_sid", " l2tpv3_sid %u", + rta_getattr_be32(attr)); + } + flower_print_ip4_addr("arp_sip", tb[TCA_FLOWER_KEY_ARP_SIP], tb[TCA_FLOWER_KEY_ARP_SIP_MASK]); flower_print_ip4_addr("arp_tip", tb[TCA_FLOWER_KEY_ARP_TIP],