From patchwork Thu Mar 17 16:27:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wojciech Drewek X-Patchwork-Id: 12784301 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 13D0FC433EF for ; Thu, 17 Mar 2022 16:31:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236590AbiCQQdN (ORCPT ); Thu, 17 Mar 2022 12:33:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58186 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236582AbiCQQdM (ORCPT ); Thu, 17 Mar 2022 12:33:12 -0400 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CCDC6214FA1 for ; Thu, 17 Mar 2022 09:31:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1647534715; x=1679070715; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ZHK+wUPvq6Acyr/S+7tSIsMSY62v3Tcb1fxz5N5+QHM=; b=MYVXvbgAGzLYBZ/u/T4h8DILs4FyqvX7vWjlOPw5oHhPvU2sHUhTxNF6 lf6yMV/PVx4YRTEibpLJBt2K886pscHHWjMyV5D8MG/dzD3bCNoNHBnY6 zPtxX6uKifUaSZxmdZSx5vnjhHiTU2d7uk5ebyWJS6cq0MQFyf1Q2sXQR zcMYKmc/FZU2UEOGGO/euv5AtJj6UHgihEPmW/qX0fLiW4okHecMK4DHS G6ieQUtl6MU1N/mYSpgNDqvM7GZbRxmEO5pqkMLPLizdp/k6tnvjzDMIg pM4Vtth6XFvnoCaa5P5OI5EWccMThO/IoU750Gh+K8/aaXXD/KW9dEsr2 g==; X-IronPort-AV: E=McAfee;i="6200,9189,10289"; a="239070826" X-IronPort-AV: E=Sophos;i="5.90,188,1643702400"; d="scan'208";a="239070826" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Mar 2022 09:31:53 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,188,1643702400"; d="scan'208";a="581349991" Received: from irvmail001.ir.intel.com ([10.43.11.63]) by orsmga001.jf.intel.com with ESMTP; 17 Mar 2022 09:31:52 -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 22HGVoCn012391; Thu, 17 Mar 2022 16:31:51 GMT From: Wojciech Drewek To: netdev@vger.kernel.org Cc: dsahern@gmail.com, stephen@networkplumber.org, jiri@mellanox.com Subject: [PATCH iproute2-next v7 1/2] ip: GTP support in ip link Date: Thu, 17 Mar 2022 17:27:54 +0100 Message-Id: <20220317162755.4359-2-wojciech.drewek@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220317162755.4359-1-wojciech.drewek@intel.com> References: <20220317162755.4359-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 Support for creating GTP devices through ip link. Two arguments can be specified by the user when adding device of the GTP type. - role (sgsn or ggsn) - indicates whether we are on the GGSN or SGSN - hsize - indicates the size of the hash table where PDP sessions are stored IFLA_GTP_FD0 and IFLA_GTP_FD1 arguments would not be provided. Those are file descriptores to the sockets created in the userspace. Since we are not going to create sockets in ip link, we don't have to provide them. Signed-off-by: Wojciech Drewek Reviewed-by: Harald Welte --- v2: use SPDX tag, use strcmp() instead of matches(), parse IFLA_GTP_RESTART_COUNT arg v3: IFLA_GTP_CREATE_SOCKETS attribute introduced, fix options alpha order v4: resolve merge conflict in ip/Makefile v7: introduce gtp_role_to_string --- include/uapi/linux/if_link.h | 2 + ip/Makefile | 2 +- ip/iplink.c | 2 +- ip/iplink_gtp.c | 140 +++++++++++++++++++++++++++++++++++ man/man8/ip-link.8.in | 29 +++++++- 5 files changed, 172 insertions(+), 3 deletions(-) create mode 100644 ip/iplink_gtp.c diff --git a/include/uapi/linux/if_link.h b/include/uapi/linux/if_link.h index 5f36ff8e8c26..3edc5547f8dd 100644 --- a/include/uapi/linux/if_link.h +++ b/include/uapi/linux/if_link.h @@ -885,6 +885,8 @@ enum { IFLA_GTP_FD1, IFLA_GTP_PDP_HASHSIZE, IFLA_GTP_ROLE, + IFLA_GTP_CREATE_SOCKETS, + IFLA_GTP_RESTART_COUNT, __IFLA_GTP_MAX, }; #define IFLA_GTP_MAX (__IFLA_GTP_MAX - 1) diff --git a/ip/Makefile b/ip/Makefile index 11a361cef5de..0f14c609a4f0 100644 --- a/ip/Makefile +++ b/ip/Makefile @@ -12,7 +12,7 @@ IPOBJ=ip.o ipaddress.o ipaddrlabel.o iproute.o iprule.o ipnetns.o \ iplink_geneve.o iplink_vrf.o iproute_lwtunnel.o ipmacsec.o ipila.o \ ipvrf.o iplink_xstats.o ipseg6.o iplink_netdevsim.o iplink_rmnet.o \ ipnexthop.o ipmptcp.o iplink_bareudp.o iplink_wwan.o ipioam6.o \ - iplink_amt.o iplink_batadv.o + iplink_amt.o iplink_batadv.o iplink_gtp.o RTMONOBJ=rtmon.o diff --git a/ip/iplink.c b/ip/iplink.c index c0a3a9ad3e62..1fe163794d35 100644 --- a/ip/iplink.c +++ b/ip/iplink.c @@ -51,7 +51,7 @@ void iplink_types_usage(void) /* Remember to add new entry here if new type is added. */ fprintf(stderr, "TYPE := { amt | bareudp | bond | bond_slave | bridge | bridge_slave |\n" - " dummy | erspan | geneve | gre | gretap | ifb |\n" + " dummy | erspan | geneve | gre | gretap | gtp | ifb |\n" " ip6erspan | ip6gre | ip6gretap | ip6tnl |\n" " ipip | ipoib | ipvlan | ipvtap |\n" " macsec | macvlan | macvtap |\n" diff --git a/ip/iplink_gtp.c b/ip/iplink_gtp.c new file mode 100644 index 000000000000..086946b62ede --- /dev/null +++ b/ip/iplink_gtp.c @@ -0,0 +1,140 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#include + +#include "rt_names.h" +#include "utils.h" +#include "ip_common.h" + +#define GTP_ATTRSET(attrs, type) (((attrs) & (1L << (type))) != 0) + +static void print_explain(FILE *f) +{ + fprintf(f, + "Usage: ... gtp role ROLE\n" + " [ hsize HSIZE ]\n" + " [ restart_count RESTART_COUNT ]\n" + "\n" + "Where: ROLE := { sgsn | ggsn }\n" + " HSIZE := 1-131071\n" + " RESTART_COUNT := 0-255\n" + ); +} + +static void check_duparg(__u32 *attrs, int type, const char *key, + const char *argv) +{ + if (!GTP_ATTRSET(*attrs, type)) { + *attrs |= (1L << type); + return; + } + duparg2(key, argv); +} + +static int gtp_parse_opt(struct link_util *lu, int argc, char **argv, + struct nlmsghdr *n) +{ + __u32 attrs = 0; + + /* When creating GTP device through ip link, + * this flag has to be set. + */ + addattr8(n, 1024, IFLA_GTP_CREATE_SOCKETS, true); + + while (argc > 0) { + if (!strcmp(*argv, "role")) { + NEXT_ARG(); + check_duparg(&attrs, IFLA_GTP_ROLE, "role", *argv); + if (!strcmp(*argv, "sgsn")) + addattr32(n, 1024, IFLA_GTP_ROLE, GTP_ROLE_SGSN); + else if (!strcmp(*argv, "ggsn")) + addattr32(n, 1024, IFLA_GTP_ROLE, GTP_ROLE_GGSN); + else + invarg("invalid role, use sgsn or ggsn", *argv); + } else if (!strcmp(*argv, "hsize")) { + __u32 hsize; + + NEXT_ARG(); + check_duparg(&attrs, IFLA_GTP_PDP_HASHSIZE, "hsize", *argv); + + if (get_u32(&hsize, *argv, 0)) + invarg("invalid PDP hash size", *argv); + if (hsize >= 1u << 17) + invarg("PDP hash size too big", *argv); + addattr32(n, 1024, IFLA_GTP_PDP_HASHSIZE, hsize); + } else if (!strcmp(*argv, "restart_count")) { + __u8 restart_count; + + NEXT_ARG(); + check_duparg(&attrs, IFLA_GTP_RESTART_COUNT, "restart_count", *argv); + + if (get_u8(&restart_count, *argv, 10)) + invarg("invalid restart_count", *argv); + addattr8(n, 1024, IFLA_GTP_RESTART_COUNT, restart_count); + } else if (!strcmp(*argv, "help")) { + print_explain(stderr); + return -1; + } + argc--, argv++; + } + + if (!GTP_ATTRSET(attrs, IFLA_GTP_ROLE)) { + fprintf(stderr, "gtp: role of the gtp device was not specified\n"); + return -1; + } + + if (!GTP_ATTRSET(attrs, IFLA_GTP_PDP_HASHSIZE)) + addattr32(n, 1024, IFLA_GTP_PDP_HASHSIZE, 1024); + + return 0; +} + +static const char *gtp_role_to_string(__u32 role) +{ + switch (role) { + case GTP_ROLE_GGSN: + return "ggsn"; + case GTP_ROLE_SGSN: + return "sgsn"; + default: + return "unknown"; + } +} + +static void gtp_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) +{ + + if (tb[IFLA_GTP_ROLE]) { + __u32 role = rta_getattr_u32(tb[IFLA_GTP_ROLE]); + + print_string(PRINT_ANY, "role", "role %s ", + gtp_role_to_string(role)); + } + + if (tb[IFLA_GTP_PDP_HASHSIZE]) { + __u32 hsize = rta_getattr_u32(tb[IFLA_GTP_PDP_HASHSIZE]); + + print_uint(PRINT_ANY, "hsize", "hsize %u ", hsize); + } + + if (tb[IFLA_GTP_RESTART_COUNT]) { + __u8 restart_count = rta_getattr_u8(tb[IFLA_GTP_RESTART_COUNT]); + + print_uint(PRINT_ANY, "restart_count", + "restart_count %u ", restart_count); + } +} + +static void gtp_print_help(struct link_util *lu, int argc, char **argv, + FILE *f) +{ + print_explain(f); +} + +struct link_util gtp_link_util = { + .id = "gtp", + .maxattr = IFLA_GTP_MAX, + .parse_opt = gtp_parse_opt, + .print_opt = gtp_print_opt, + .print_help = gtp_print_help, +}; diff --git a/man/man8/ip-link.8.in b/man/man8/ip-link.8.in index 93106d7f79ce..7a6753747468 100644 --- a/man/man8/ip-link.8.in +++ b/man/man8/ip-link.8.in @@ -243,7 +243,8 @@ ip-link \- network device configuration .BR macsec " |" .BR netdevsim " |" .BR rmnet " |" -.BR xfrm " ]" +.BR xfrm " |" +.BR gtp " ]" .ti -8 .IR ETYPE " := [ " TYPE " |" @@ -392,6 +393,9 @@ Link types: .sp .BR xfrm - Virtual xfrm interface +.sp +.BR gtp +- GPRS Tunneling Protocol .in -8 .TP @@ -1941,6 +1945,29 @@ policies. Policies must be configured with the same key. If not set, the key def .in -8 +.TP +GTP Type Support +For a link of type +.I GTP +the following additional arguments are supported: + +.BI "ip link add " DEVICE " type gtp role " ROLE " hsize " HSIZE + +.in +8 +.sp +.BI role " ROLE " +- specifies the role of the GTP device, either sgsn or ggsn + +.sp +.BI hsize " HSIZE " +- specifies size of the hashtable which stores PDP contexts + +.sp +.BI restart_count " RESTART_COUNT " +- GTP instance restart counter + +.in -8 + .SS ip link delete - delete virtual link .TP From patchwork Thu Mar 17 16:27:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wojciech Drewek X-Patchwork-Id: 12784302 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 A3D20C433F5 for ; Thu, 17 Mar 2022 16:32:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236586AbiCQQdO (ORCPT ); Thu, 17 Mar 2022 12:33:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236583AbiCQQdN (ORCPT ); Thu, 17 Mar 2022 12:33:13 -0400 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8197321590E for ; Thu, 17 Mar 2022 09:31:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1647534716; x=1679070716; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=2fo2ZK3Yeu0gglCvRx2G2ahUzEvUiWXp7qo4wedaBmw=; b=kZHcLREmij65Ynwd5uBqTvq5ywYQL9irn2ad0EB/qkJsQX2VTe5yaNEt Llz0PpCXK3RdMR+p+YzvNvR8V2lbZkj6imd0Xh/o2cWBKpeAwL8HiYvcx EdQa5SGknbwDIWCfj4iVM8822GI7PPL9/M5wB9R5csvQIqbSe2NubX4Ne xPYVLOIbM7rovp7tLsgrR1QzhjlipZJvG+eGb6zGbU0Oy3b8cVNuxJTv5 LgZt98SNs/bOp09MDgAhnqQK/LZqrW7TLz2En0eBgXeiHSmVPnrJKDOWC C7jpRRMfvRIYKmdMRWbrb4pn4XpjHdg0+UF+YwrjvTv8LNHOlFK6dpozx w==; X-IronPort-AV: E=McAfee;i="6200,9189,10289"; a="239070831" X-IronPort-AV: E=Sophos;i="5.90,188,1643702400"; d="scan'208";a="239070831" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Mar 2022 09:31:53 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,188,1643702400"; d="scan'208";a="635417226" Received: from irvmail001.ir.intel.com ([10.43.11.63]) by FMSMGA003.fm.intel.com with ESMTP; 17 Mar 2022 09:31:52 -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 22HGVoCo012391; Thu, 17 Mar 2022 16:31:51 GMT From: Wojciech Drewek To: netdev@vger.kernel.org Cc: dsahern@gmail.com, stephen@networkplumber.org, jiri@mellanox.com Subject: [PATCH iproute2-next v7 2/2] f_flower: Implement gtp options support Date: Thu, 17 Mar 2022 17:27:55 +0100 Message-Id: <20220317162755.4359-3-wojciech.drewek@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220317162755.4359-1-wojciech.drewek@intel.com> References: <20220317162755.4359-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 parsing TCA_FLOWER_KEY_ENC_OPTS_GTP. Options are as follows: PDU_TYPE:QFI where each option is represented as 8-bit hexadecimal value. e.g. # ip link add gtp_dev type gtp role sgsn # tc qdisc add dev gtp_dev ingress # tc filter add dev gtp_dev protocol ip parent ffff: \ flower \ enc_key_id 11 \ gtp_opts 1:8/ff:ff \ action mirred egress redirect dev eth0 Signed-off-by: Wojciech Drewek --- v2: use SPDX tag, use strcmp() instead of matches(), parse IFLA_GTP_RESTART_COUNT arg v3: IFLA_GTP_CREATE_SOCKETS attribute introduced, fix options alpha order v5: add gtp_opts to explain function v6: use strcmp instead of matches --- include/uapi/linux/pkt_cls.h | 16 +++++ man/man8/tc-flower.8 | 10 +++ tc/f_flower.c | 123 ++++++++++++++++++++++++++++++++++- 3 files changed, 147 insertions(+), 2 deletions(-) diff --git a/include/uapi/linux/pkt_cls.h b/include/uapi/linux/pkt_cls.h index ee38b35c3f57..30ff8da0631b 100644 --- a/include/uapi/linux/pkt_cls.h +++ b/include/uapi/linux/pkt_cls.h @@ -616,6 +616,10 @@ enum { * TCA_FLOWER_KEY_ENC_OPT_ERSPAN_ * attributes */ + TCA_FLOWER_KEY_ENC_OPTS_GTP, /* Nested + * TCA_FLOWER_KEY_ENC_OPT_GTP_ + * attributes + */ __TCA_FLOWER_KEY_ENC_OPTS_MAX, }; @@ -654,6 +658,18 @@ enum { #define TCA_FLOWER_KEY_ENC_OPT_ERSPAN_MAX \ (__TCA_FLOWER_KEY_ENC_OPT_ERSPAN_MAX - 1) +enum { + TCA_FLOWER_KEY_ENC_OPT_GTP_UNSPEC, + TCA_FLOWER_KEY_ENC_OPT_GTP_PDU_TYPE, /* u8 */ + TCA_FLOWER_KEY_ENC_OPT_GTP_QFI, /* u8 */ + + __TCA_FLOWER_KEY_ENC_OPT_GTP_MAX, +}; + +#define TCA_FLOWER_KEY_ENC_OPT_GTP_MAX \ + (__TCA_FLOWER_KEY_ENC_OPT_GTP_MAX - 1) + + enum { TCA_FLOWER_KEY_MPLS_OPTS_UNSPEC, TCA_FLOWER_KEY_MPLS_OPTS_LSE, diff --git a/man/man8/tc-flower.8 b/man/man8/tc-flower.8 index 4541d9372684..f918a06d2927 100644 --- a/man/man8/tc-flower.8 +++ b/man/man8/tc-flower.8 @@ -89,6 +89,8 @@ flower \- flow based traffic control filter .B vxlan_opts | .B erspan_opts +| +.B gtp_opts } .IR OPTIONS " | " .BR ip_flags @@ -411,6 +413,8 @@ Match the connection zone, and can be masked. .BI vxlan_opts " OPTIONS" .TQ .BI erspan_opts " OPTIONS" +.TQ +.BI gtp_opts " OPTIONS" Match on IP tunnel metadata. Key id .I NUMBER is a 32 bit tunnel key id (e.g. VNI for VXLAN tunnel). @@ -446,6 +450,12 @@ VERSION:INDEX:DIR:HWID/VERSION:INDEX_MASK:DIR_MASK:HWID_MASK, where VERSION is represented as a 8bit number, INDEX as an 32bit number, DIR and HWID as a 8bit number. Multiple options is not supported. Note INDEX/INDEX_MASK is used when VERSION is 1, and DIR/DIR_MASK and HWID/HWID_MASK are used when VERSION is 2. +gtp_opts +.I OPTIONS +doesn't support multiple options, and it consists of a key followed by a slash +and corresponding mask. If the mask is missing, \fBtc\fR assumes a full-length +match. The option can be described in the form PDU_TYPE:QFI/PDU_TYPE_MASK:QFI_MASK +where both PDU_TYPE and QFI are represented as a 8bit hexadecimal values. .TP .BI ip_flags " IP_FLAGS" .I IP_FLAGS diff --git a/tc/f_flower.c b/tc/f_flower.c index ad159719c05f..686cf12140a7 100644 --- a/tc/f_flower.c +++ b/tc/f_flower.c @@ -84,6 +84,7 @@ static void explain(void) " geneve_opts MASKED-OPTIONS |\n" " vxlan_opts MASKED-OPTIONS |\n" " erspan_opts MASKED-OPTIONS |\n" + " gtp_opts MASKED-OPTIONS |\n" " ip_flags IP-FLAGS |\n" " enc_dst_port [ port_number ] |\n" " ct_state MASKED_CT_STATE |\n" @@ -1034,6 +1035,52 @@ static int flower_parse_erspan_opt(char *str, struct nlmsghdr *n) return 0; } +static int flower_parse_gtp_opt(char *str, struct nlmsghdr *n) +{ + struct rtattr *nest; + char *token; + int arg, err; + + nest = addattr_nest(n, MAX_MSG, TCA_FLOWER_KEY_ENC_OPTS_GTP | NLA_F_NESTED); + + token = strsep(&str, ":"); + for (arg = 1; arg <= TCA_FLOWER_KEY_ENC_OPT_GTP_MAX; arg++) { + switch (arg) { + case TCA_FLOWER_KEY_ENC_OPT_GTP_PDU_TYPE: + { + __u8 pdu_type; + + if (!strlen(token)) + break; + err = get_u8(&pdu_type, token, 16); + if (err) + return err; + addattr8(n, MAX_MSG, arg, pdu_type); + break; + } + case TCA_FLOWER_KEY_ENC_OPT_GTP_QFI: + { + __u8 qfi; + + if (!strlen(token)) + break; + err = get_u8(&qfi, token, 16); + if (err) + return err; + addattr8(n, MAX_MSG, arg, qfi); + break; + } + default: + fprintf(stderr, "Unknown \"gtp_opts\" type\n"); + return -1; + } + token = strsep(&str, ":"); + } + addattr_nest_end(n, nest); + + return 0; +} + static int flower_parse_geneve_opts(char *str, struct nlmsghdr *n) { char *token; @@ -1217,6 +1264,41 @@ static int flower_parse_enc_opts_erspan(char *str, struct nlmsghdr *n) return 0; } +static int flower_parse_enc_opts_gtp(char *str, struct nlmsghdr *n) +{ + char key[XATTR_SIZE_MAX], mask[XATTR_SIZE_MAX]; + struct rtattr *nest; + char *slash; + int err; + + slash = strchr(str, '/'); + if (slash) { + *slash++ = '\0'; + if (strlen(slash) > XATTR_SIZE_MAX) + return -1; + strcpy(mask, slash); + } else + strcpy(mask, "ff:ff"); + + if (strlen(str) > XATTR_SIZE_MAX) + return -1; + strcpy(key, str); + + nest = addattr_nest(n, MAX_MSG, TCA_FLOWER_KEY_ENC_OPTS | NLA_F_NESTED); + err = flower_parse_gtp_opt(key, n); + if (err) + return err; + addattr_nest_end(n, nest); + + nest = addattr_nest(n, MAX_MSG, TCA_FLOWER_KEY_ENC_OPTS_MASK | NLA_F_NESTED); + err = flower_parse_gtp_opt(mask, n); + if (err) + return err; + addattr_nest_end(n, nest); + + return 0; +} + static int flower_parse_mpls_lse(int *argc_p, char ***argv_p, struct nlmsghdr *nlh) { @@ -1869,6 +1951,13 @@ static int flower_parse_opt(struct filter_util *qu, char *handle, fprintf(stderr, "Illegal \"erspan_opts\"\n"); return -1; } + } else if (!strcmp(*argv, "gtp_opts")) { + NEXT_ARG(); + ret = flower_parse_enc_opts_gtp(*argv, n); + if (ret < 0) { + fprintf(stderr, "Illegal \"gtp_opts\"\n"); + return -1; + } } else if (matches(*argv, "action") == 0) { NEXT_ARG(); ret = parse_action(&argc, &argv, TCA_FLOWER_ACT, n); @@ -2338,6 +2427,21 @@ static void flower_print_erspan_opts(const char *name, struct rtattr *attr, sprintf(strbuf, "%u:%u:%u:%u", ver, idx, dir, hwid); } +static void flower_print_gtp_opts(const char *name, struct rtattr *attr, + char *strbuf, int len) +{ + struct rtattr *tb[TCA_FLOWER_KEY_ENC_OPT_GTP_MAX + 1]; + __u8 pdu_type, qfi; + + parse_rtattr(tb, TCA_FLOWER_KEY_ENC_OPT_GTP_MAX, RTA_DATA(attr), + RTA_PAYLOAD(attr)); + + pdu_type = rta_getattr_u8(tb[TCA_FLOWER_KEY_ENC_OPT_GTP_PDU_TYPE]); + qfi = rta_getattr_u8(tb[TCA_FLOWER_KEY_ENC_OPT_GTP_QFI]); + + snprintf(strbuf, len, "%02x:%02x", pdu_type, qfi); +} + static void __attribute__((format(printf, 2, 0))) flower_print_enc_parts(const char *name, const char *namefrm, struct rtattr *attr, char *key, char *mask) @@ -2370,15 +2474,18 @@ static void flower_print_enc_opts(const char *name, struct rtattr *attr, struct rtattr *key_tb[TCA_FLOWER_KEY_ENC_OPTS_MAX + 1]; struct rtattr *msk_tb[TCA_FLOWER_KEY_ENC_OPTS_MAX + 1]; char *key, *msk; + int len; if (!attr) return; - key = malloc(RTA_PAYLOAD(attr) * 2 + 1); + len = RTA_PAYLOAD(attr) * 2 + 1; + + key = malloc(len); if (!key) return; - msk = malloc(RTA_PAYLOAD(attr) * 2 + 1); + msk = malloc(len); if (!msk) goto err_key_free; @@ -2415,6 +2522,18 @@ static void flower_print_enc_opts(const char *name, struct rtattr *attr, flower_print_enc_parts(name, " erspan_opts %s", attr, key, msk); + } else if (key_tb[TCA_FLOWER_KEY_ENC_OPTS_GTP]) { + flower_print_gtp_opts("gtp_opt_key", + key_tb[TCA_FLOWER_KEY_ENC_OPTS_GTP], + key, len); + + if (msk_tb[TCA_FLOWER_KEY_ENC_OPTS_GTP]) + flower_print_gtp_opts("gtp_opt_mask", + msk_tb[TCA_FLOWER_KEY_ENC_OPTS_GTP], + msk, len); + + flower_print_enc_parts(name, " gtp_opts %s", attr, key, + msk); } free(msk);