From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 2DADAA04F1; Mon, 13 Jan 2020 19:05:50 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 162A21D16E; Mon, 13 Jan 2020 19:05:43 +0100 (CET) Received: from mail-qt1-f193.google.com (mail-qt1-f193.google.com [209.85.160.193]) by dpdk.org (Postfix) with ESMTP id 1AD6D1D14A for ; Mon, 13 Jan 2020 19:05:40 +0100 (CET) Received: by mail-qt1-f193.google.com with SMTP id v25so9893993qto.7 for ; Mon, 13 Jan 2020 10:05:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:in-reply-to :references; bh=ET6zrKhu+U31QqjmQOum07OXuRkwpmn6nW03suTpb+8=; b=vhSdL6wbuMBdVLGzhv9oDsaONo3DJOEOyeXZbgYmAQeicabI7//gQEgkmx0fq02xji U1cpdW1QrF0Z7mKpF+GxvVdolXutiiOfPGL7iE305ZwRgrEPBx00fLVQEtbhwt/4iRJM JG09iWWqaU2qlN3Igpywr3eanRpfwnQQhlDC75JfGd/wcLk+FmZekv45YVIZw9/X4RWw 5Y/3AuP+al+yYBNCqq/40OwyOHFQTbIw3SBZaMT6I6j+07uViwepqm10fx5cxUt0xh6i 6YT6zy9QndphXKgs6hVdr+IVF06ZYYBG378iIkPBuCHki/UnM4Ys4rDJWD1ohXdW1UtH Ayfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=ET6zrKhu+U31QqjmQOum07OXuRkwpmn6nW03suTpb+8=; b=bTjhPaaZb1bWKTPJVpsFfBIY7SCVAtpnSp9F+X0l+NITkSYDESzXdoavKtVNlk24Sc llvsCPXIWUHSfpjhn74eG5Rx0/svdXG4Kg+FoMCotivhmmhKA2E6vUkTGXA971PQLmtf li33o/O1k8WsTA0s6NMmGmX6wuh9gVixpcx7hevKdAKT/pmYdcURBwWAhXTaaOAVUlq+ 1JIGG1JwwmuR5lPDaPCipxl9uzr3PWE7g+Dd1rp/0N0j7Z5zFq8oGruaLUSirA5JcBMn MYy3RlmMpROzMI1F5XwA0AXZ30wTgT04sUFHgWG3s53p4f3j5iFWig3MfGvOak0eRVSJ Dbhw== X-Gm-Message-State: APjAAAVbWqU1CCcPt2LSGi9Gr8oEVBTozo0pX8gm0eBs7m49AAj1Z1Je 6DBJvQkbjvbb517vw4nZghw= X-Google-Smtp-Source: APXvYqzaIMjEXj7l3WNOMKHT2244j3s7DEn5iWwLynS9FeGdGE2wmpALaDZnIJuxtVfQZlaFYfylAA== X-Received: by 2002:aed:2d67:: with SMTP id h94mr15063376qtd.74.1578938739467; Mon, 13 Jan 2020 10:05:39 -0800 (PST) Received: from sovaradhvm.ojp4suxva1celnnpiyhedynfde.bx.internal.cloudapp.net ([104.211.12.148]) by smtp.gmail.com with ESMTPSA id a36sm6272483qtk.29.2020.01.13.10.05.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2020 10:05:39 -0800 (PST) From: Sowmini Varadhan To: sowmini05@gmail.com, dev@dpdk.org Date: Mon, 13 Jan 2020 18:05:29 +0000 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH RFC V2 1/2] Hooks to allow the setting of filters on tcp flags X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" The rte_eth_ntuple_filter allows tcp_flags which can check for things like #define RTE_TCP_CWR_FLAG 0x80 /**< Congestion Window Reduced */ #define RTE_TCP_ECE_FLAG 0x40 /**< ECN-Echo */ #define RTE_TCP_URG_FLAG 0x20 /**< Urgent Pointer field significant */ #define RTE_TCP_ACK_FLAG 0x10 /**< Acknowledgment field significant */ #define RTE_TCP_PSH_FLAG 0x08 /**< Push Function */ #define RTE_TCP_RST_FLAG 0x04 /**< Reset the connection */ #define RTE_TCP_SYN_FLAG 0x02 /**< Synchronize sequence numbers */ #define RTE_TCP_FIN_FLAG 0x01 /**< No more data from sender */ but there are no existing examples that demonstrate how to use this feature. This patch extends the exisiting classification support to allow an optional flags in the input file. The flags string can be any concatenation of characters from {C, E, U, A, P, R, S, F} and "*" indicates "dont care". These flags are set in the ntuple_filter and are used to construct the tcp_spec and tcp_mask sent to the driver The rte_acl_field_def is updated to use the (u8) tcp flag as lookup key. Note that, as per https://doc.dpdk.org/guides/prog_guide/packet_classif_access_ctrl.html this field MUST be allocated fo4 4 bytes, thus it has sizeof(uint32_t). However, also note the XXX in this commit: additional updates are needed to the rte_flow_classify_table_entry_add() so that it does not ignore any key fields other than the 5-tuple. Signed-off-by: Sowmini Varadhan --- V2 : checkpatch fixes; revert accidental spelling mistake introduced in V1. examples/flow_classify/flow_classify.c | 87 ++++++++++++++++++++-- examples/flow_classify/ipv4_rules_file.txt | 22 +++--- 2 files changed, 91 insertions(+), 18 deletions(-) diff --git a/examples/flow_classify/flow_classify.c b/examples/flow_classify/flow_classify.c index 1c12bbb2f..e8a41741f 100644 --- a/examples/flow_classify/flow_classify.c +++ b/examples/flow_classify/flow_classify.c @@ -51,6 +51,7 @@ enum { CB_FLD_DST_PORT_MASK, CB_FLD_PROTO, CB_FLD_PRIORITY, + CB_FLD_TCP_FLAGS, CB_FLD_NUM, }; @@ -81,6 +82,7 @@ enum { DST_FIELD_IPV4, SRCP_FIELD_IPV4, DSTP_FIELD_IPV4, + TCP_FLAGS_FIELD, NUM_FIELDS_IPV4 }; @@ -88,7 +90,8 @@ enum { PROTO_INPUT_IPV4, SRC_INPUT_IPV4, DST_INPUT_IPV4, - SRCP_DESTP_INPUT_IPV4 + SRCP_DESTP_INPUT_IPV4, + TCP_FLAGS_INDEX, }; static struct rte_acl_field_def ipv4_defs[NUM_FIELDS_IPV4] = { @@ -145,6 +148,17 @@ static struct rte_acl_field_def ipv4_defs[NUM_FIELDS_IPV4] = { sizeof(struct rte_ipv4_hdr) + offsetof(struct rte_tcp_hdr, dst_port), }, + /* next field must be 4 bytes, even though flags is only 1 byte */ + { + /* rte_flags */ + .type = RTE_ACL_FIELD_TYPE_BITMASK, + .size = sizeof(uint32_t), + .field_index = TCP_FLAGS_FIELD, + .input_index = TCP_FLAGS_INDEX, + .offset = sizeof(struct rte_ether_hdr) + + sizeof(struct rte_ipv4_hdr) + + offsetof(struct rte_tcp_hdr, tcp_flags), + }, }; /* flow classify data */ @@ -272,12 +286,14 @@ lcore_main(struct flow_classifier *cls_app) int ret; int i = 0; - ret = rte_flow_classify_table_entry_delete(cls_app->cls, - rules[7]); - if (ret) - printf("table_entry_delete failed [7] %d\n\n", ret); - else - printf("table_entry_delete succeeded [7]\n\n"); + if (rules[7]) { + ret = rte_flow_classify_table_entry_delete(cls_app->cls, + rules[7]); + if (ret) + printf("table_entry_delete failed [7] %d\n\n", ret); + else + printf("table_entry_delete succeeded [7]\n\n"); + } /* * Check that the port is on the same NUMA node as the polling thread @@ -395,6 +411,53 @@ parse_ipv4_net(char *in, uint32_t *addr, uint32_t *mask_len) return 0; } +static int +get_tcp_flags(char *in, struct rte_eth_ntuple_filter *ntuple_filter) +{ + int len = strlen(in); + int i; + uint8_t flags = 0; + + if (strcmp(in, "*") == 0) { + ntuple_filter->tcp_flags = 0; + return 0; + } + + for (i = 0; i < len; i++) { + switch (in[i]) { + case 'S': + flags |= RTE_TCP_SYN_FLAG; + break; + case 'F': + flags |= RTE_TCP_FIN_FLAG; + break; + case 'R': + flags |= RTE_TCP_RST_FLAG; + break; + case 'P': + flags |= RTE_TCP_PSH_FLAG; + break; + case 'A': + flags |= RTE_TCP_ACK_FLAG; + break; + case 'U': + flags |= RTE_TCP_URG_FLAG; + break; + case 'E': + flags |= RTE_TCP_ECE_FLAG; + break; + case 'C': + flags |= RTE_TCP_CWR_FLAG; + break; + default: + fprintf(stderr, "unknown flag %c\n", in[i]); + return -1; + } + } + ntuple_filter->tcp_flags = flags; + return 0; +} + static int parse_ipv4_5tuple_rule(char *str, struct rte_eth_ntuple_filter *ntuple_filter) { @@ -466,6 +529,8 @@ parse_ipv4_5tuple_rule(char *str, struct rte_eth_ntuple_filter *ntuple_filter) ntuple_filter->priority = (uint16_t)temp; if (ntuple_filter->priority > FLOW_CLASSIFY_MAX_PRIORITY) ret = -EINVAL; + if (get_tcp_flags(in[CB_FLD_TCP_FLAGS], ntuple_filter)) + return -EINVAL; return ret; } @@ -582,10 +647,13 @@ add_classify_rule(struct rte_eth_ntuple_filter *ntuple_filter, memset(&tcp_spec, 0, sizeof(tcp_spec)); tcp_spec.hdr.src_port = ntuple_filter->src_port; tcp_spec.hdr.dst_port = ntuple_filter->dst_port; + tcp_spec.hdr.tcp_flags = ntuple_filter->tcp_flags; memset(&tcp_mask, 0, sizeof(tcp_mask)); tcp_mask.hdr.src_port = ntuple_filter->src_port_mask; tcp_mask.hdr.dst_port = ntuple_filter->dst_port_mask; + if (tcp_spec.hdr.tcp_flags != 0) + tcp_mask.hdr.tcp_flags = 0xff; tcp_item.type = RTE_FLOW_ITEM_TYPE_TCP; tcp_item.spec = &tcp_spec; @@ -640,6 +708,11 @@ add_classify_rule(struct rte_eth_ntuple_filter *ntuple_filter, return ret; } + /* XXX but this only adds table_type of + * RTE_FLOW_CLASSIFY_TABLE_ACL_IP4_5TUPLE + * i.e., it only ever does allocate_acl_ipv4_5tuple_rule() + * so the tcp_flags is ignored! + */ rule = rte_flow_classify_table_entry_add( cls_app->cls, &attr, pattern_ipv4_5tuple, actions, &key_found, &error); diff --git a/examples/flow_classify/ipv4_rules_file.txt b/examples/flow_classify/ipv4_rules_file.txt index dfa0631fc..415573732 100644 --- a/examples/flow_classify/ipv4_rules_file.txt +++ b/examples/flow_classify/ipv4_rules_file.txt @@ -1,14 +1,14 @@ #file format: -#src_ip/masklen dst_ip/masklen src_port : mask dst_port : mask proto/mask priority +#src_ip/masklen dst_ip/masklen src_port : mask dst_port : mask proto/mask priority tcp_flags # -2.2.2.3/24 2.2.2.7/24 32 : 0xffff 33 : 0xffff 17/0xff 0 -9.9.9.3/24 9.9.9.7/24 32 : 0xffff 33 : 0xffff 17/0xff 1 -9.9.9.3/24 9.9.9.7/24 32 : 0xffff 33 : 0xffff 6/0xff 2 -9.9.8.3/24 9.9.8.7/24 32 : 0xffff 33 : 0xffff 6/0xff 3 -6.7.8.9/24 2.3.4.5/24 32 : 0x0000 33 : 0x0000 132/0xff 4 -6.7.8.9/32 192.168.0.36/32 10 : 0xffff 11 : 0xffff 6/0xfe 5 -6.7.8.9/24 192.168.0.36/24 10 : 0xffff 11 : 0xffff 6/0xfe 6 -6.7.8.9/16 192.168.0.36/16 10 : 0xffff 11 : 0xffff 6/0xfe 7 -6.7.8.9/8 192.168.0.36/8 10 : 0xffff 11 : 0xffff 6/0xfe 8 +2.2.2.3/24 2.2.2.7/24 32 : 0xffff 33 : 0xffff 17/0xff 0 * +9.9.9.3/24 9.9.9.7/24 32 : 0xffff 33 : 0xffff 17/0xff 1 * +9.9.9.3/24 9.9.9.7/24 32 : 0xffff 33 : 0xffff 6/0xff 2 * +9.9.8.3/24 9.9.8.7/24 32 : 0xffff 33 : 0xffff 6/0xff 3 * +6.7.8.9/24 2.3.4.5/24 32 : 0x0000 33 : 0x0000 132/0xff 4 * +6.7.8.9/32 192.168.0.36/32 10 : 0xffff 11 : 0xffff 6/0xfe 5 * +6.7.8.9/24 192.168.0.36/24 10 : 0xffff 11 : 0xffff 6/0xfe 6 * +6.7.8.9/16 192.168.0.36/16 10 : 0xffff 11 : 0xffff 6/0xfe 7 * +6.7.8.9/8 192.168.0.36/8 10 : 0xffff 11 : 0xffff 6/0xfe 8 * #error rules -#9.8.7.6/8 192.168.0.36/8 10 : 0xffff 11 : 0xffff 6/0xfe 9 \ No newline at end of file +#9.8.7.6/8 192.168.0.36/8 10 : 0xffff 11 : 0xffff 6/0xfe 9 * -- 2.20.1