get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/patches/105137/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 105137,
    "url": "http://patches.dpdk.org/api/patches/105137/?format=api",
    "web_url": "http://patches.dpdk.org/project/dpdk/patch/20211214141242.3383831-8-ronan.randles@intel.com/",
    "project": {
        "id": 1,
        "url": "http://patches.dpdk.org/api/projects/1/?format=api",
        "name": "DPDK",
        "link_name": "dpdk",
        "list_id": "dev.dpdk.org",
        "list_email": "dev@dpdk.org",
        "web_url": "http://core.dpdk.org",
        "scm_url": "git://dpdk.org/dpdk",
        "webscm_url": "http://git.dpdk.org/dpdk",
        "list_archive_url": "https://inbox.dpdk.org/dev",
        "list_archive_url_format": "https://inbox.dpdk.org/dev/{}",
        "commit_url_format": ""
    },
    "msgid": "<20211214141242.3383831-8-ronan.randles@intel.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/20211214141242.3383831-8-ronan.randles@intel.com",
    "date": "2021-12-14T14:12:37",
    "name": "[07/12] gen: add gen IP parsing",
    "commit_ref": null,
    "pull_url": null,
    "state": "not-applicable",
    "archived": true,
    "hash": "37fbecbe868d19fcce356dda8b790c1390fdf0e5",
    "submitter": {
        "id": 2439,
        "url": "http://patches.dpdk.org/api/people/2439/?format=api",
        "name": "Ronan Randles",
        "email": "ronan.randles@intel.com"
    },
    "delegate": {
        "id": 1,
        "url": "http://patches.dpdk.org/api/users/1/?format=api",
        "username": "tmonjalo",
        "first_name": "Thomas",
        "last_name": "Monjalon",
        "email": "thomas@monjalon.net"
    },
    "mbox": "http://patches.dpdk.org/project/dpdk/patch/20211214141242.3383831-8-ronan.randles@intel.com/mbox/",
    "series": [
        {
            "id": 20944,
            "url": "http://patches.dpdk.org/api/series/20944/?format=api",
            "web_url": "http://patches.dpdk.org/project/dpdk/list/?series=20944",
            "date": "2021-12-14T14:12:30",
            "name": "add packet generator library and example app",
            "version": 1,
            "mbox": "http://patches.dpdk.org/series/20944/mbox/"
        }
    ],
    "comments": "http://patches.dpdk.org/api/patches/105137/comments/",
    "check": "success",
    "checks": "http://patches.dpdk.org/api/patches/105137/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<dev-bounces@dpdk.org>",
        "X-Original-To": "patchwork@inbox.dpdk.org",
        "Delivered-To": "patchwork@inbox.dpdk.org",
        "Received": [
            "from mails.dpdk.org (mails.dpdk.org [217.70.189.124])\n\tby inbox.dpdk.org (Postfix) with ESMTP id 742EAA00C3;\n\tTue, 14 Dec 2021 15:13:38 +0100 (CET)",
            "from [217.70.189.124] (localhost [127.0.0.1])\n\tby mails.dpdk.org (Postfix) with ESMTP id 01E0F4117D;\n\tTue, 14 Dec 2021 15:13:00 +0100 (CET)",
            "from mga07.intel.com (mga07.intel.com [134.134.136.100])\n by mails.dpdk.org (Postfix) with ESMTP id 5EF7641165\n for <dev@dpdk.org>; Tue, 14 Dec 2021 15:12:58 +0100 (CET)",
            "from orsmga006.jf.intel.com ([10.7.209.51])\n by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;\n 14 Dec 2021 06:12:57 -0800",
            "from silpixa00401120.ir.intel.com ([10.55.129.95])\n by orsmga006.jf.intel.com with ESMTP; 14 Dec 2021 06:12:56 -0800"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=simple/simple;\n d=intel.com; i=@intel.com; q=dns/txt; s=Intel;\n t=1639491178; x=1671027178;\n h=from:to:cc:subject:date:message-id:in-reply-to:\n references:mime-version:content-transfer-encoding;\n bh=ZVGj9WVyV3dmDaAfl8IZeyPRexyBoc/wXqkUbabpWxs=;\n b=OeYc4fEiz1K3VJrc1x9oPuqGtpQa89DYMdlDhibHP1ev0BzjdPvKTnbK\n j0/yYkVzofWZdQvNLzjRuwSnkbjuEzqoufQdCSzRZx1KIoIlLMzcuhH7h\n 2iJvrIVVAsI2DnKFpOj2FKTgDJcreRIOGS6WB5nb7mB4GgLcxLSSr+UIq\n +xC1t548MWQbiAn77NAF0N3zJcZFJOBDp2ERitBfqYBhZLiSBoBWBFMuF\n wGCf0eTqWIpSmA4PPuTekp4stEZfawWPqH/EsCbcgVmqbcj0dbIXlSnzH\n 1iGw4sbySj8RzQ2kQO/Lrhcd6egCP0Qx7PFDc6dwMGpZ0FGWXyDnd1kQb w==;",
        "X-IronPort-AV": [
            "E=McAfee;i=\"6200,9189,10197\"; a=\"302362333\"",
            "E=Sophos;i=\"5.88,205,1635231600\"; d=\"scan'208\";a=\"302362333\"",
            "E=Sophos;i=\"5.88,205,1635231600\"; d=\"scan'208\";a=\"465104146\""
        ],
        "X-ExtLoop1": "1",
        "From": "Ronan Randles <ronan.randles@intel.com>",
        "To": "dev@dpdk.org",
        "Cc": "harry.van.haaren@intel.com,\n\tRonan Randles <ronan.randles@intel.com>",
        "Subject": "[PATCH 07/12] gen: add gen IP parsing",
        "Date": "Tue, 14 Dec 2021 14:12:37 +0000",
        "Message-Id": "<20211214141242.3383831-8-ronan.randles@intel.com>",
        "X-Mailer": "git-send-email 2.25.1",
        "In-Reply-To": "<20211214141242.3383831-1-ronan.randles@intel.com>",
        "References": "<20211214141242.3383831-1-ronan.randles@intel.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "X-BeenThere": "dev@dpdk.org",
        "X-Mailman-Version": "2.1.29",
        "Precedence": "list",
        "List-Id": "DPDK patches and discussions <dev.dpdk.org>",
        "List-Unsubscribe": "<https://mails.dpdk.org/options/dev>,\n <mailto:dev-request@dpdk.org?subject=unsubscribe>",
        "List-Archive": "<http://mails.dpdk.org/archives/dev/>",
        "List-Post": "<mailto:dev@dpdk.org>",
        "List-Help": "<mailto:dev-request@dpdk.org?subject=help>",
        "List-Subscribe": "<https://mails.dpdk.org/listinfo/dev>,\n <mailto:dev-request@dpdk.org?subject=subscribe>",
        "Errors-To": "dev-bounces@dpdk.org"
    },
    "content": "From: Harry van Haaren <harry.van.haaren@intel.com>\n\nThis commit adds support for the parsing of \"IP(src=...,dst=...)\"\nstrings. Parse string API improvement for app RCU.\nAppropriate unit tests also added.\n\nSigned-off-by: Harry van Haaren <harry.van.haaren@intel.com>\nSigned-off-by: Ronan Randles <ronan.randles@intel.com>\n---\n app/test/test_gen.c |  29 +++++++--\n lib/gen/rte_gen.c   | 146 +++++++++++++++++++++++++++++++++++++++++++-\n 2 files changed, 170 insertions(+), 5 deletions(-)",
    "diff": "diff --git a/app/test/test_gen.c b/app/test/test_gen.c\nindex 324582d0a5..7b67835c80 100644\n--- a/app/test/test_gen.c\n+++ b/app/test/test_gen.c\n@@ -117,26 +117,47 @@ test_gen_packet_parse_string(void)\n {\n \tstruct rte_gen *gen = rte_gen_create(mp);\n \tTEST_ASSERT_FAIL(gen, \"Expected valid pointer after create()\");\n-\n \tstruct str_parse_t {\n \t\tconst char *str;\n+\t\tuint32_t expected_to_fail;\n \t} pkt_strings[] = {\n \t\t{ .str = \"Ether()\"},\n \t\t{ .str = \"Ether()/\"},\n \t\t{ .str = \"/Ether()\"},\n-\t\t{ .str = \"/Ether()/\"}\n+\t\t{ .str = \"/Ether()/\"},\n+\t\t{ .str = \"Ether()/IP()\"},\n+\t\t{ .str = \"Ether()/IP(src=1.2.3.4,dst=5.6.7.8)\"},\n+\t\t{ .str = \"Ether()/IP(src=1.2.3.4,dst=192.168.255.255)\"},\n+\t\t{ .str = \"Ether()/IP(dst=172.16.0.9,src=1.2.3.4)\"},\n+\t\t{ .str = \"Ether()/IP(src=1.2.3.4)\"},\n+\t\t{ .str = \"Ether()/IP(srdst=5.6.7.8)\", .expected_to_fail = 1},\n+\t\t{ .str = \"Ether()/IP(src=1.2.3.4,ds=)\", .expected_to_fail = 1},\n+\t\t{ .str = \"Ether()/IP(src=1.2.3.4,dst=)\", .expected_to_fail = 1},\n+\t\t{ .str = \"Ether()/IP(src=,dst=5.6.7.8)\", .expected_to_fail = 1},\n+\t\t{ .str = \"Ether()/IP(sr=,dst=5.6.7.8)\", .expected_to_fail = 1},\n+\t\t{ .str = \"Ether()/IP(src=1.2.3.fail,dst=5.6.7.8)\",\n+\t\t\t\t\t.expected_to_fail = 1},\n \t};\n \n \tuint32_t i;\n \tfor (i = 0; i < RTE_DIM(pkt_strings); i++) {\n \t\tconst char *pkt_str = pkt_strings[i].str;\n \t\tint32_t err = rte_gen_packet_parse_string(gen, pkt_str, NULL);\n-\t\tTEST_ASSERT_EQUAL(err, 0, \"Expected string %s to parse.\",\n-\t\t\t\tpkt_str);\n+\n+\t\tif (err && pkt_strings[i].expected_to_fail != 1) {\n+\t\t\tprintf(\"Expected string %s to parse.\", pkt_str);\n+\t\t\treturn -1;\n+\t\t}\n+\t\t/* False pass if reached with no err when e_t_f = 1 */\n+\t\tif (!err && pkt_strings[i].expected_to_fail) {\n+\t\t\tprintf(\"False Pass on string: %s\\n\", pkt_str);\n+\t\t\treturn -1;\n+\t\t}\n \t}\n \n \trte_gen_destroy(gen);\n \treturn 0;\n+\n }\n \n \ndiff --git a/lib/gen/rte_gen.c b/lib/gen/rte_gen.c\nindex ab73120791..3dac436cff 100644\n--- a/lib/gen/rte_gen.c\n+++ b/lib/gen/rte_gen.c\n@@ -10,6 +10,7 @@\n #include <rte_log.h>\n \n #include <rte_ether.h>\n+#include <rte_ip.h>\n \n RTE_LOG_REGISTER(gen_logtype, lib.gen, NOTICE);\n \n@@ -136,6 +137,7 @@ rte_gen_tx_burst(struct rte_gen *gen,\n enum GEN_PROTO {\n \tGEN_PROTO_INVALID,\n \tGEN_PROTO_ETHER,\n+\tGEN_PROTO_IPV4,\n \n \t/* Must be last. */\n \tGEN_PROTO_COUNT,\n@@ -219,6 +221,140 @@ gen_parser_init(struct gen_parser *parser, struct rte_gen *gen,\n \treturn -ENOMEM;\n }\n \n+static void\n+gen_log_ipv4(void *data, const char *indent)\n+{\n+\tstruct rte_ipv4_hdr *ip = data;\n+\n+\tconst char *proto_str;\n+\tswitch (ip->next_proto_id) {\n+\tcase 0:\n+\t\tproto_str = \"hopopt\";\n+\t\tbreak;\n+\tdefault:\n+\t\tproto_str = \"unknown next proto\";\n+\t\tbreak;\n+\t}\n+\n+\tTGEN_LOG_PROTOCOL(DEBUG,\n+\t\t\"###[ IP ]###\\n%sversion = %d\\n%sihl = %d\\n%stos = %d\\n\"\n+\t\t\"%slen = %d\\n%sid = %d\\n%sflags = 0x%x\\n%sfrag = %d\\n\"\n+\t\t\"%sttl = %d\\n%sproto = %s (%d)\\n%schksum 0x%x\\n%ssrc = 0x%x\\n\"\n+\t\t\"%sdst = 0x%x\\n%soptions = %s\\n\",\n+\t\tindent, ip->version_ihl >> 4,\n+\t\tindent, ip->version_ihl & RTE_IPV4_HDR_IHL_MASK,\n+\t\tindent, ip->type_of_service,\n+\t\tindent, rte_be_to_cpu_16(ip->total_length),\n+\t\tindent, rte_be_to_cpu_16(ip->packet_id), /* TODO: Scapy ID? */\n+\t\tindent, rte_be_to_cpu_16(ip->packet_id), /*TODO: Scapy Flags?*/\n+\t\tindent, rte_be_to_cpu_16(ip->fragment_offset),\n+\t\tindent, ip->time_to_live,\n+\t\tindent, proto_str, ip->next_proto_id,\n+\t\tindent, rte_be_to_cpu_16(ip->hdr_checksum),\n+\t\tindent, rte_be_to_cpu_32(ip->src_addr),\n+\t\tindent, rte_be_to_cpu_32(ip->dst_addr),\n+\t\tindent, \"notImplemented\");\n+}\n+\n+static int32_t\n+gen_parse_ipv4_params(char *protocol_str, struct rte_ipv4_hdr *ip)\n+{\n+\t/* Strings to look for. */\n+\tstatic const char * const items[] = {\n+\t\t\"src=\",\n+\t\t\"dst=\",\n+\t};\n+\tconst uint32_t num_items = RTE_DIM(items);\n+\n+\tchar *tok_ptr;\n+\tuint32_t err = 0;\n+\tuint32_t i;\n+\tfor (i = 0; i < num_items; i++) {\n+\t\t/* Print input string into local buffer for processing. */\n+\t\tchar buffer[1024];\n+\t\tint chars_printed = snprintf(buffer, 1024, \"%s\", protocol_str);\n+\t\tif (chars_printed >= 1024)\n+\t\t\treturn -1;\n+\n+\t\t/* Find substring (e.g. src=) if not found skip to next one. */\n+\t\tchar *start = strstr(buffer, items[i]);\n+\t\tchar check_previous[32];\n+\t\tif (start != NULL) {\n+\t\t\tsnprintf(check_previous, 32, \"%.1s\", start - 1);\n+\t\t\tif (strcmp(&check_previous[0], \"(\") &&\n+\t\t\t\t\t\tstrcmp(&check_previous[0], \",\"))\n+\t\t\t\treturn -EINVAL;\n+\t\t}\n+\n+\t\tif (!start) {\n+\t\t\tif (!strstr(buffer, \",\"))\n+\t\t\t\tcontinue;\n+\t\t\telse\n+\t\t\t\treturn -EINVAL;\n+\t\t}\n+\t\t/* get from start of string till first , character. */\n+\t\tchar *item = strtok_r(start, \",\", &tok_ptr);\n+\n+\t\tif (strcmp(item, items[i]) == 0)\n+\t\t\treturn -EINVAL;\n+\t\t/* skip past the src= prefix. We know string is long enough as\n+\t\t * otherwise strstr() wouldn't have matched it.\n+\t\t */\n+\t\titem = &item[4];\n+\n+\t\tif (strcmp(items[i], \"src=\") == 0) {\n+\t\t\terr = rte_ip_parse_addr(item, &ip->src_addr);\n+\t\t\tip->src_addr = rte_cpu_to_be_32(ip->src_addr);\n+\t\t} else {\n+\t\t\terr = rte_ip_parse_addr(item, &ip->dst_addr);\n+\t\t\tip->dst_addr = rte_cpu_to_be_32(ip->dst_addr);\n+\t\t}\n+\t\tif (err) {\n+\t\t\tTGEN_LOG(ERR, \"parser ip_parse_addr error %d\\n\", err);\n+\t\t\treturn err;\n+\t\t}\n+\t}\n+\treturn 0;\n+}\n+\n+static int32_t\n+gen_parse_ipv4(struct gen_parser *parser, char *protocol_str)\n+{\n+\tstruct rte_ipv4_hdr *ip = gen_parser_get_data_ptr(parser);\n+\tmemset(ip, 0, sizeof(*ip));\n+\tip->version_ihl = RTE_IPV4_VHL_DEF;\n+\n+\t/* default addrs */\n+\tip->src_addr = RTE_IPV4(127, 0, 0, 1);\n+\tip->dst_addr = RTE_IPV4(127, 0, 0, 1);\n+\n+\tuint32_t err = 0;\n+\tif (strcmp(\"IP()\", protocol_str))\n+\t\terr = gen_parse_ipv4_params(protocol_str, ip);\n+\n+\tif (err) {\n+\t\tTGEN_LOG(ERR, \"parser parse ipv4 params error %d\\n\", err);\n+\t\treturn err;\n+\t}\n+\n+\t/* Move up write pointer in packet, recurse to next. */\n+\tenum GEN_PROTO inner;\n+\tparser->buf_write_offset += rte_ipv4_hdr_len(ip);\n+\t\terr = gen_parser_parse_next(parser, &inner);\n+\tif (err) {\n+\t\tTGEN_LOG(ERR, \"parser parse next() error %d\\n\", err);\n+\t\treturn err;\n+\t}\n+\n+\tswitch (inner) {\n+\tdefault:\n+\t\t/* Default protocol is hopopt (0). */\n+\t\tbreak;\n+\t};\n+\n+\treturn 0;\n+}\n+\n static void\n gen_log_ether(void *data, const char *indent)\n {\n@@ -304,7 +440,14 @@ static struct gen_parse_func_t gen_protocols[] = {\n \t\t.proto = GEN_PROTO_ETHER,\n \t\t.parse_func = gen_parse_ether,\n \t\t.log_func = gen_log_ether,\n-\t}\n+\t},\n+\t{\n+\t\t.name = \"IP(\",\n+\t\t.proto = GEN_PROTO_IPV4,\n+\t\t.parse_func = gen_parse_ipv4,\n+\t\t.log_func = gen_log_ipv4,\n+\t},\n+\n };\n \n /* Function to tokenize and parse each segment of a string.\n@@ -380,6 +523,7 @@ rte_gen_packet_parse_string(struct rte_gen *gen,\n \tif (err) {\n \t\tTGEN_LOG(ERR, \"Error in parsing packet string. \"\n \t\t\t\"Set \\\"gen\\\" log level to debug for more info.\\n\");\n+\t\trte_pktmbuf_free(parser.mbuf);\n \t\treturn -1;\n \t}\n \n",
    "prefixes": [
        "07/12"
    ]
}