From patchwork Tue Dec 16 12:30:36 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taras Kondratiuk X-Patchwork-Id: 42326 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ee0-f69.google.com (mail-ee0-f69.google.com [74.125.83.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 3A8B12456A for ; Tue, 16 Dec 2014 12:31:33 +0000 (UTC) Received: by mail-ee0-f69.google.com with SMTP id d49sf8875381eek.4 for ; Tue, 16 Dec 2014 04:31:32 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:subject:precedence:list-id:list-unsubscribe:list-archive :list-post:list-help:list-subscribe:mime-version:content-type :content-transfer-encoding:errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=k6GBwdL0LjhZS1LV2q+A4u+Jw4Kk3FHwC4ZmO/gm2Ok=; b=m+xQmaChABDvlg6dtsv2T2wjp4dz9RgFqwqPcTvhCJLmM3opiZIyRzwtJTmCSWH/xc q7q8a6GHqL1Eqtleef2+D6rr+YnUeGD3PAfzrO/uDjU+T7PcBlUSbvY6NzTzAzLtlIJo Uo62A1SlwBDKEFJoL4KUmxkjKQnIMjkbslq71m5Y4GJBYQ0HV+NhMdinIk460NjVJpZ3 D+86VQZHVvpUmqcJMaVtsPdk/2zCeNS9ygw5RtkVbBObYuwc7fVxG+0f9MD6/8KyEKmK gQzCiHqSdPpjwACYrd704IEto5SMXdYU7g3sHpriC0mc9+hYMEPsmMdnaNbQiACeaNOD B7/g== X-Gm-Message-State: ALoCoQm59c0Uh8JiSE9oeWMsXIj1FjmSQne8pmfa58kEWgjDAEZqRBs8+1PrlCBrw57hj5wXTvYi X-Received: by 10.112.138.234 with SMTP id qt10mr5592986lbb.4.1418733092369; Tue, 16 Dec 2014 04:31:32 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.204.104 with SMTP id kx8ls873589lac.82.gmail; Tue, 16 Dec 2014 04:31:32 -0800 (PST) X-Received: by 10.112.91.43 with SMTP id cb11mr35065488lbb.63.1418733091934; Tue, 16 Dec 2014 04:31:31 -0800 (PST) Received: from mail-la0-f50.google.com (mail-la0-f50.google.com. [209.85.215.50]) by mx.google.com with ESMTPS id nv4si702145lbb.16.2014.12.16.04.31.31 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 16 Dec 2014 04:31:31 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.50 as permitted sender) client-ip=209.85.215.50; Received: by mail-la0-f50.google.com with SMTP id pn19so11353636lab.9 for ; Tue, 16 Dec 2014 04:31:31 -0800 (PST) X-Received: by 10.112.135.197 with SMTP id pu5mr35146140lbb.22.1418733091813; Tue, 16 Dec 2014 04:31:31 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.142.69 with SMTP id ru5csp1019922lbb; Tue, 16 Dec 2014 04:31:30 -0800 (PST) X-Received: by 10.229.118.1 with SMTP id t1mr65168062qcq.17.1418733090264; Tue, 16 Dec 2014 04:31:30 -0800 (PST) Received: from ip-10-35-177-41.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id k3si689069qcn.14.2014.12.16.04.31.29 (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 16 Dec 2014 04:31:30 -0800 (PST) Received-SPF: none (google.com: lng-odp-bounces@lists.linaro.org does not designate permitted sender hosts) client-ip=54.225.227.206; Received: from localhost ([127.0.0.1] helo=ip-10-35-177-41.ec2.internal) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1Y0rHj-0006YL-8Q; Tue, 16 Dec 2014 12:31:27 +0000 Received: from mail-la0-f47.google.com ([209.85.215.47]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1Y0rHL-0006UQ-7u for lng-odp@lists.linaro.org; Tue, 16 Dec 2014 12:31:03 +0000 Received: by mail-la0-f47.google.com with SMTP id hz20so10852003lab.20 for ; Tue, 16 Dec 2014 04:30:57 -0800 (PST) X-Received: by 10.112.135.197 with SMTP id pu5mr35143480lbb.22.1418733057268; Tue, 16 Dec 2014 04:30:57 -0800 (PST) Received: from uglx0153363.synapse.com ([195.238.92.128]) by mx.google.com with ESMTPSA id eg2sm169516lbb.29.2014.12.16.04.30.56 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 16 Dec 2014 04:30:56 -0800 (PST) From: Taras Kondratiuk To: lng-odp@lists.linaro.org Date: Tue, 16 Dec 2014 14:30:36 +0200 Message-Id: <1418733042-18047-4-git-send-email-taras.kondratiuk@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1418733042-18047-1-git-send-email-taras.kondratiuk@linaro.org> References: <1418733042-18047-1-git-send-email-taras.kondratiuk@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCHv5 3/9] api: packet: change layer offset/pointer API X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: lng-odp-bounces@lists.linaro.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: taras.kondratiuk@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.50 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 From: Bill Fischofer Signed-off-by: Bill Fischofer Signed-off-by: Taras Kondratiuk --- example/generator/odp_generator.c | 10 +- example/ipsec/odp_ipsec.c | 13 ++- example/ipsec/odp_ipsec_stream.c | 8 +- example/packet/odp_pktio.c | 5 +- helper/include/odph_ip.h | 4 +- helper/include/odph_udp.h | 4 +- platform/linux-generic/include/api/odp_packet.h | 130 ++++++++++++++------- .../linux-generic/include/odp_packet_internal.h | 11 ++ platform/linux-generic/odp_packet.c | 80 +++++++------ platform/linux-generic/odp_packet_socket.c | 17 ++- 10 files changed, 175 insertions(+), 107 deletions(-) diff --git a/example/generator/odp_generator.c b/example/generator/odp_generator.c index 5ded85c..aec2275 100644 --- a/example/generator/odp_generator.c +++ b/example/generator/odp_generator.c @@ -189,13 +189,13 @@ static void pack_udp_pkt(odp_buffer_t obuf) pkt = odp_packet_from_buffer(obuf); /* ether */ - odp_packet_set_l2_offset(pkt, 0); + odp_packet_l2_offset_set(pkt, 0); eth = (odph_ethhdr_t *)buf; memcpy((char *)eth->src.addr, args->appl.srcmac.addr, ODPH_ETHADDR_LEN); memcpy((char *)eth->dst.addr, args->appl.dstmac.addr, ODPH_ETHADDR_LEN); eth->type = odp_cpu_to_be_16(ODPH_ETHTYPE_IPV4); /* ip */ - odp_packet_set_l3_offset(pkt, ODPH_ETHHDR_LEN); + odp_packet_l3_offset_set(pkt, ODPH_ETHHDR_LEN); ip = (odph_ipv4hdr_t *)(buf + ODPH_ETHHDR_LEN); ip->dst_addr = odp_cpu_to_be_32(args->appl.dstip); ip->src_addr = odp_cpu_to_be_32(args->appl.srcip); @@ -208,7 +208,7 @@ static void pack_udp_pkt(odp_buffer_t obuf) ip->chksum = 0; odph_ipv4_csum_update(pkt); /* udp */ - odp_packet_set_l4_offset(pkt, ODPH_ETHHDR_LEN + ODPH_IPV4HDR_LEN); + odp_packet_l4_offset_set(pkt, ODPH_ETHHDR_LEN + ODPH_IPV4HDR_LEN); udp = (odph_udphdr_t *)(buf + ODPH_ETHHDR_LEN + ODPH_IPV4HDR_LEN); udp->src_port = 0; udp->dst_port = 0; @@ -246,13 +246,13 @@ static void pack_icmp_pkt(odp_buffer_t obuf) args->appl.payload = 56; pkt = odp_packet_from_buffer(obuf); /* ether */ - odp_packet_set_l2_offset(pkt, 0); + odp_packet_l2_offset_set(pkt, 0); eth = (odph_ethhdr_t *)buf; memcpy((char *)eth->src.addr, args->appl.srcmac.addr, ODPH_ETHADDR_LEN); memcpy((char *)eth->dst.addr, args->appl.dstmac.addr, ODPH_ETHADDR_LEN); eth->type = odp_cpu_to_be_16(ODPH_ETHTYPE_IPV4); /* ip */ - odp_packet_set_l3_offset(pkt, ODPH_ETHHDR_LEN); + odp_packet_l3_offset_set(pkt, ODPH_ETHHDR_LEN); ip = (odph_ipv4hdr_t *)(buf + ODPH_ETHHDR_LEN); ip->dst_addr = odp_cpu_to_be_32(args->appl.dstip); ip->src_addr = odp_cpu_to_be_32(args->appl.srcip); diff --git a/example/ipsec/odp_ipsec.c b/example/ipsec/odp_ipsec.c index cd73682..c6f7471 100644 --- a/example/ipsec/odp_ipsec.c +++ b/example/ipsec/odp_ipsec.c @@ -639,13 +639,14 @@ pkt_disposition_e do_input_verify(odp_packet_t pkt, static pkt_disposition_e do_route_fwd_db(odp_packet_t pkt, pkt_ctx_t *ctx) { - odph_ipv4hdr_t *ip = (odph_ipv4hdr_t *)odp_packet_l3(pkt); + odph_ipv4hdr_t *ip = (odph_ipv4hdr_t *)odp_packet_l3_ptr(pkt, NULL); fwd_db_entry_t *entry; entry = find_fwd_db_entry(odp_be_to_cpu_32(ip->dst_addr)); if (entry) { - odph_ethhdr_t *eth = (odph_ethhdr_t *)odp_packet_l2(pkt); + odph_ethhdr_t *eth = + (odph_ethhdr_t *)odp_packet_l2_ptr(pkt, NULL); memcpy(ð->dst, entry->dst_mac, ODPH_ETHADDR_LEN); memcpy(ð->src, entry->src_mac, ODPH_ETHADDR_LEN); @@ -676,7 +677,7 @@ pkt_disposition_e do_ipsec_in_classify(odp_packet_t pkt, bool *skip) { uint8_t *buf = odp_packet_addr(pkt); - odph_ipv4hdr_t *ip = (odph_ipv4hdr_t *)odp_packet_l3(pkt); + odph_ipv4hdr_t *ip = (odph_ipv4hdr_t *)odp_packet_l3_ptr(pkt, NULL); int hdr_len; odph_ahhdr_t *ah = NULL; odph_esphdr_t *esp = NULL; @@ -771,7 +772,7 @@ pkt_disposition_e do_ipsec_in_finish(odp_packet_t pkt, return PKT_DROP; if (!is_crypto_compl_status_ok(&auth_rc)) return PKT_DROP; - ip = (odph_ipv4hdr_t *)odp_packet_l3(pkt); + ip = (odph_ipv4hdr_t *)odp_packet_l3_ptr(pkt, NULL); /* * Finish auth @@ -836,7 +837,7 @@ pkt_disposition_e do_ipsec_out_classify(odp_packet_t pkt, bool *skip) { uint8_t *buf = odp_packet_addr(pkt); - odph_ipv4hdr_t *ip = (odph_ipv4hdr_t *)odp_packet_l3(pkt); + odph_ipv4hdr_t *ip = (odph_ipv4hdr_t *)odp_packet_l3_ptr(pkt, NULL); uint16_t ip_data_len = ipv4_data_len(ip); uint8_t *ip_data = ipv4_data_p(ip); ipsec_cache_entry_t *entry; @@ -1003,7 +1004,7 @@ pkt_disposition_e do_ipsec_out_finish(odp_packet_t pkt, return PKT_DROP; if (!is_crypto_compl_status_ok(&auth_rc)) return PKT_DROP; - ip = (odph_ipv4hdr_t *)odp_packet_l3(pkt); + ip = (odph_ipv4hdr_t *)odp_packet_l3_ptr(pkt, NULL); /* Finalize the IPv4 header */ ip->ttl = ctx->ipsec.ip_ttl; diff --git a/example/ipsec/odp_ipsec_stream.c b/example/ipsec/odp_ipsec_stream.c index 15cdb3d..93de198 100644 --- a/example/ipsec/odp_ipsec_stream.c +++ b/example/ipsec/odp_ipsec_stream.c @@ -195,7 +195,7 @@ odp_packet_t create_ipv4_packet(stream_db_entry_t *stream, /* Ethernet */ odp_packet_has_eth_set(pkt, 1); - odp_packet_set_l2_offset(pkt, data - base); + odp_packet_l2_offset_set(pkt, data - base); eth = (odph_ethhdr_t *)data; data += sizeof(*eth); @@ -205,10 +205,10 @@ odp_packet_t create_ipv4_packet(stream_db_entry_t *stream, /* IPv4 */ odp_packet_has_ipv4_set(pkt, 1); - odp_packet_set_l3_offset(pkt, data - base); + odp_packet_l3_offset_set(pkt, data - base); ip = (odph_ipv4hdr_t *)data; data += sizeof(*ip); - odp_packet_set_l4_offset(pkt, data - base); + odp_packet_l4_offset_set(pkt, data - base); /* Wait until almost finished to fill in mutable fields */ memset((char *)ip, 0, sizeof(*ip)); @@ -345,7 +345,7 @@ bool verify_ipv4_packet(stream_db_entry_t *stream, stream_pkt_hdr_t *test; /* Basic IPv4 verify (add checksum verification) */ - data = odp_packet_l3(pkt); + data = odp_packet_l3_ptr(pkt, NULL); ip = (odph_ipv4hdr_t *)data; data += sizeof(*ip); if (0x45 != ip->ver_ihl) diff --git a/example/packet/odp_pktio.c b/example/packet/odp_pktio.c index 10b79d7..463042c 100644 --- a/example/packet/odp_pktio.c +++ b/example/packet/odp_pktio.c @@ -483,7 +483,7 @@ static void swap_pkt_addrs(odp_packet_t pkt_tbl[], unsigned len) for (i = 0; i < len; ++i) { pkt = pkt_tbl[i]; if (odp_packet_has_eth(pkt)) { - eth = (odph_ethhdr_t *)odp_packet_l2(pkt); + eth = (odph_ethhdr_t *)odp_packet_l2_ptr(pkt, NULL); tmp_addr = eth->dst; eth->dst = eth->src; @@ -491,7 +491,8 @@ static void swap_pkt_addrs(odp_packet_t pkt_tbl[], unsigned len) if (odp_packet_has_ipv4(pkt)) { /* IPv4 */ - ip = (odph_ipv4hdr_t *)odp_packet_l3(pkt); + ip = (odph_ipv4hdr_t *) + odp_packet_l3_ptr(pkt, NULL); ip_tmp_addr = ip->src_addr; ip->src_addr = ip->dst_addr; diff --git a/helper/include/odph_ip.h b/helper/include/odph_ip.h index f78724e..16c8266 100644 --- a/helper/include/odph_ip.h +++ b/helper/include/odph_ip.h @@ -88,7 +88,7 @@ static inline int odph_ipv4_csum_valid(odp_packet_t pkt) if (!odp_packet_l3_offset(pkt)) return 0; - memcpy(&ip, odp_packet_l3(pkt), sizeof(odph_ipv4hdr_t)); + memcpy(&ip, odp_packet_l3_ptr(pkt, NULL), sizeof(odph_ipv4hdr_t)); w = (uint16_t *)(void *)&ip; chksum = ip.chksum; ip.chksum = 0x0; @@ -116,7 +116,7 @@ static inline uint16sum_t odph_ipv4_csum_update(odp_packet_t pkt) if (!odp_packet_l3_offset(pkt)) return 0; - ip = (odph_ipv4hdr_t *)odp_packet_l3(pkt); + ip = (odph_ipv4hdr_t *)odp_packet_l3_ptr(pkt, NULL); w = (uint16_t *)(void *)ip; ip->chksum = odp_chksum(w, nleft); return ip->chksum; diff --git a/helper/include/odph_udp.h b/helper/include/odph_udp.h index b2eaf03..ef0cd4c 100644 --- a/helper/include/odph_udp.h +++ b/helper/include/odph_udp.h @@ -64,8 +64,8 @@ static inline uint16_t odph_ipv4_udp_chksum(odp_packet_t pkt) if (!odp_packet_l4_offset(pkt)) return 0; - iph = (odph_ipv4hdr_t *)odp_packet_l3(pkt); - udph = (odph_udphdr_t *)odp_packet_l4(pkt); + iph = (odph_ipv4hdr_t *)odp_packet_l3_ptr(pkt, NULL); + udph = (odph_udphdr_t *)odp_packet_l4_ptr(pkt, NULL); udplen = odp_be_to_cpu_16(udph->length); /* the source ip */ diff --git a/platform/linux-generic/include/api/odp_packet.h b/platform/linux-generic/include/api/odp_packet.h index 9a15114..96e1474 100644 --- a/platform/linux-generic/include/api/odp_packet.h +++ b/platform/linux-generic/include/api/odp_packet.h @@ -180,10 +180,11 @@ uint8_t *odp_packet_addr(odp_packet_t pkt); size_t odp_packet_buf_size(odp_packet_t pkt); /** - * Packet data address + * Packet data pointer * - * Returns the current packet data address. When a packet is received from - * packet input, the data address points to the first byte of the packet. + * Returns the current packet data pointer. When a packet is received + * from packet input, this points to the first byte of the received + * packet. Packet level offsets are calculated relative to this position. * * @param pkt Packet handle * @@ -191,94 +192,145 @@ size_t odp_packet_buf_size(odp_packet_t pkt); * * @see odp_packet_l2(), odp_packet_addr() */ -uint8_t *odp_packet_data(odp_packet_t pkt); +void *odp_packet_data(odp_packet_t pkt); /** - * Get pointer to the start of the L2 frame + * Layer 2 start pointer * - * The L2 frame header address is not necessarily the same as the address of the - * packet buffer, see odp_packet_addr() + * Returns pointer to the start of the layer 2 header. Optionally, outputs + * number of data bytes in the segment following the pointer. * - * @param pkt Packet handle + * @param pkt Packet handle + * @param[out] len Number of data bytes remaining in the segment (output). + * Ignored when NULL. * - * @return Pointer to L2 header or NULL if not found + * @return Layer 2 start pointer, or offset 0 by default * - * @see odp_packet_addr(), odp_packet_data() + * @see odp_packet_l2_offset(), odp_packet_l2_offset_set() */ -uint8_t *odp_packet_l2(odp_packet_t pkt); +void *odp_packet_l2_ptr(odp_packet_t pkt, uint32_t *len); /** - * Return the byte offset from the packet buffer to the L2 frame + * Layer 2 start offset + * + * Returns offset to the start of the layer 2 header. The offset is calculated + * from the current odp_packet_data() position in bytes. + * + * User is responsible to update the offset when modifying the packet data + * pointer position. * * @param pkt Packet handle * - * @return L2 byte offset or ODP_PACKET_OFFSET_INVALID if not found + * @return Layer 2 start offset */ -size_t odp_packet_l2_offset(odp_packet_t pkt); +uint32_t odp_packet_l2_offset(odp_packet_t pkt); /** - * Set the byte offset to the L2 frame + * Set layer 2 start offset + * + * Set offset to the start of the layer 2 header. The offset is calculated from + * the current odp_packet_data() position in bytes. Offset must not exceed + * packet data length. Packet is not modified on an error. * * @param pkt Packet handle - * @param offset L2 byte offset + * @param offset Layer 2 start offset (0 ... odp_packet_len()-1) + * + * @retval 0 Success + * @retval Non-zero Failure */ -void odp_packet_set_l2_offset(odp_packet_t pkt, size_t offset); - +int odp_packet_l2_offset_set(odp_packet_t pkt, uint32_t offset); /** - * Get pointer to the start of the L3 packet + * Layer 3 start pointer * - * @param pkt Packet handle + * Returns pointer to the start of the layer 3 header. Optionally, outputs + * number of data bytes in the segment following the pointer. + * + * @param pkt Packet handle + * @param[out] len Number of data bytes remaining in the segment (output). + * Ignored when NULL. * - * @return Pointer to L3 packet or NULL if not found + * @return Layer 3 start pointer, or NULL * + * @see odp_packet_l3_offset(), odp_packet_l3_offset_set() */ -uint8_t *odp_packet_l3(odp_packet_t pkt); +void *odp_packet_l3_ptr(odp_packet_t pkt, uint32_t *len); /** - * Return the byte offset from the packet buffer to the L3 packet + * Layer 3 start offset + * + * Returns offset to the start of the layer 3 header. The offset is calculated + * from the current odp_packet_data() position in bytes. + * + * User is responsible to update the offset when modifying the packet data + * pointer position. * * @param pkt Packet handle * - * @return L3 byte offset or ODP_PACKET_OFFSET_INVALID if not found + * @return Layer 3 start offset or ODP_PACKET_OFFSET_INVALID if not found */ -size_t odp_packet_l3_offset(odp_packet_t pkt); +uint32_t odp_packet_l3_offset(odp_packet_t pkt); /** - * Set the byte offset to the L3 packet + * Set layer 3 start offset + * + * Set offset to the start of the layer 3 header. The offset is calculated from + * the current odp_packet_data() position in bytes. Offset must not exceed + * packet data length. Packet is not modified on an error. * * @param pkt Packet handle - * @param offset L3 byte offset + * @param offset Layer 3 start offset (0 ... odp_packet_len()-1) + * + * @retval 0 Success + * @retval Non-zero Failure */ -void odp_packet_set_l3_offset(odp_packet_t pkt, size_t offset); - +int odp_packet_l3_offset_set(odp_packet_t pkt, uint32_t offset); /** - * Get pointer to the start of the L4 packet + * Layer 4 start pointer * - * @param pkt Packet handle + * Returns pointer to the start of the layer 4 header. Optionally, outputs + * number of data bytes in the segment following the pointer. + * + * @param pkt Packet handle + * @param[out] len Number of data bytes remaining in the segment (output). + * Ignored when NULL. * - * @return Pointer to L4 packet or NULL if not found + * @return Layer 4 start pointer, or NULL * + * @see odp_packet_l4_offset(), odp_packet_l4_offset_set() */ -uint8_t *odp_packet_l4(odp_packet_t pkt); +void *odp_packet_l4_ptr(odp_packet_t pkt, uint32_t *len); /** - * Return the byte offset from the packet buffer to the L4 packet + * Layer 4 start offset + * + * Returns offset to the start of the layer 4 header. The offset is calculated + * from the current odp_packet_data() position in bytes. + * + * User is responsible to update the offset when modifying the packet data + * pointer position. * * @param pkt Packet handle * - * @return L4 byte offset or ODP_PACKET_OFFSET_INVALID if not found + * @return Layer 4 start offset or ODP_PACKET_OFFSET_INVALID if not found */ -size_t odp_packet_l4_offset(odp_packet_t pkt); +uint32_t odp_packet_l4_offset(odp_packet_t pkt); /** - * Set the byte offset to the L4 packet + * Set layer 4 start offset + * + * Set offset to the start of the layer 4 header. The offset is calculated from + * the current odp_packet_data() position in bytes. Offset must not exceed + * packet data length. Packet is not modified on an error. * * @param pkt Packet handle - * @param offset L4 byte offset + * @param offset Layer 4 start offset (0 ... odp_packet_len()-1) + * + * @retval 0 Success + * @retval Non-zero Failure */ -void odp_packet_set_l4_offset(odp_packet_t pkt, size_t offset); +int odp_packet_l4_offset_set(odp_packet_t pkt, uint32_t offset); /** * Print (debug) information about the packet diff --git a/platform/linux-generic/include/odp_packet_internal.h b/platform/linux-generic/include/odp_packet_internal.h index 9553f13..fbaaa5f 100644 --- a/platform/linux-generic/include/odp_packet_internal.h +++ b/platform/linux-generic/include/odp_packet_internal.h @@ -169,6 +169,17 @@ static inline void packet_init(pool_entry_t *pool, (pool->s.headroom + size); } +static inline void *packet_map(odp_packet_hdr_t *pkt_hdr, + uint32_t offset, uint32_t *seglen) +{ + if (offset > pkt_hdr->frame_len) + return NULL; + + return buffer_map(&pkt_hdr->buf_hdr, + pkt_hdr->headroom + offset, seglen, + pkt_hdr->headroom + pkt_hdr->frame_len); +} + odp_packet_t _odp_packet_alloc(odp_buffer_pool_t pool_hdl); #ifdef __cplusplus diff --git a/platform/linux-generic/odp_packet.c b/platform/linux-generic/odp_packet.c index a4ad3e8..783714b 100644 --- a/platform/linux-generic/odp_packet.c +++ b/platform/linux-generic/odp_packet.c @@ -93,75 +93,81 @@ size_t odp_packet_get_len(odp_packet_t pkt) uint8_t *odp_packet_addr(odp_packet_t pkt) { - return odp_buffer_addr(odp_packet_to_buffer(pkt)); + odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); + return buffer_map(&pkt_hdr->buf_hdr, 0, NULL, 0); } -uint8_t *odp_packet_data(odp_packet_t pkt) +void *odp_packet_data(odp_packet_t pkt) { - return odp_packet_addr(pkt) + odp_packet_hdr(pkt)->headroom; + odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); + return packet_map(pkt_hdr, 0, NULL); } - -uint8_t *odp_packet_l2(odp_packet_t pkt) +void *odp_packet_l2_ptr(odp_packet_t pkt, uint32_t *len) { - const size_t offset = odp_packet_l2_offset(pkt); - - if (odp_unlikely(offset == ODP_PACKET_OFFSET_INVALID)) - return NULL; - - return odp_packet_addr(pkt) + offset; + odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); + return packet_map(pkt_hdr, pkt_hdr->l2_offset, len); } -size_t odp_packet_l2_offset(odp_packet_t pkt) +uint32_t odp_packet_l2_offset(odp_packet_t pkt) { return odp_packet_hdr(pkt)->l2_offset; } -void odp_packet_set_l2_offset(odp_packet_t pkt, size_t offset) -{ - odp_packet_hdr(pkt)->l2_offset = offset; -} - -uint8_t *odp_packet_l3(odp_packet_t pkt) +int odp_packet_l2_offset_set(odp_packet_t pkt, uint32_t offset) { - const size_t offset = odp_packet_l3_offset(pkt); + odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); - if (odp_unlikely(offset == ODP_PACKET_OFFSET_INVALID)) - return NULL; + if (offset >= pkt_hdr->frame_len) + return -1; - return odp_packet_addr(pkt) + offset; + pkt_hdr->l2_offset = offset; + return 0; } -size_t odp_packet_l3_offset(odp_packet_t pkt) +void *odp_packet_l3_ptr(odp_packet_t pkt, uint32_t *len) { - return odp_packet_hdr(pkt)->l3_offset; + odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); + return packet_map(pkt_hdr, pkt_hdr->l3_offset, len); } -void odp_packet_set_l3_offset(odp_packet_t pkt, size_t offset) +uint32_t odp_packet_l3_offset(odp_packet_t pkt) { - odp_packet_hdr(pkt)->l3_offset = offset; + return odp_packet_hdr(pkt)->l3_offset; } -uint8_t *odp_packet_l4(odp_packet_t pkt) +int odp_packet_l3_offset_set(odp_packet_t pkt, uint32_t offset) { - const size_t offset = odp_packet_l4_offset(pkt); + odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); - if (odp_unlikely(offset == ODP_PACKET_OFFSET_INVALID)) - return NULL; + if (offset >= pkt_hdr->frame_len) + return -1; - return odp_packet_addr(pkt) + offset; + pkt_hdr->l3_offset = offset; + return 0; } -size_t odp_packet_l4_offset(odp_packet_t pkt) +void *odp_packet_l4_ptr(odp_packet_t pkt, uint32_t *len) { - return odp_packet_hdr(pkt)->l4_offset; + odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); + return packet_map(pkt_hdr, pkt_hdr->l4_offset, len); } -void odp_packet_set_l4_offset(odp_packet_t pkt, size_t offset) +uint32_t odp_packet_l4_offset(odp_packet_t pkt) { - odp_packet_hdr(pkt)->l4_offset = offset; + return odp_packet_hdr(pkt)->l4_offset; } +int odp_packet_l4_offset_set(odp_packet_t pkt, uint32_t offset) +{ + odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); + + if (offset >= pkt_hdr->frame_len) + return -1; + + pkt_hdr->l4_offset = offset; + return 0; +} int odp_packet_is_segmented(odp_packet_t pkt) { @@ -230,14 +236,14 @@ void odp_packet_parse(odp_packet_t pkt, size_t len, size_t frame_offset) pkt_hdr->input_flags.ipv4 = 1; pkt_hdr->input_flags.l3 = 1; pkt_hdr->l3_offset = frame_offset + ODPH_ETHHDR_LEN + offset; - ipv4 = (odph_ipv4hdr_t *)odp_packet_l3(pkt); + ipv4 = (odph_ipv4hdr_t *)odp_packet_l3_ptr(pkt, NULL); ip_proto = parse_ipv4(pkt_hdr, ipv4, &offset); break; case ODPH_ETHTYPE_IPV6: pkt_hdr->input_flags.ipv6 = 1; pkt_hdr->input_flags.l3 = 1; pkt_hdr->l3_offset = frame_offset + ODPH_ETHHDR_LEN + offset; - ipv6 = (odph_ipv6hdr_t *)odp_packet_l3(pkt); + ipv6 = (odph_ipv6hdr_t *)odp_packet_l3_ptr(pkt, NULL); ip_proto = parse_ipv6(pkt_hdr, ipv6, &offset); break; case ODPH_ETHTYPE_ARP: diff --git a/platform/linux-generic/odp_packet_socket.c b/platform/linux-generic/odp_packet_socket.c index 76e437a..ead5d2f 100644 --- a/platform/linux-generic/odp_packet_socket.c +++ b/platform/linux-generic/odp_packet_socket.c @@ -372,7 +372,7 @@ int send_pkt_sock_basic(pkt_sock_t *const pkt_sock, { odp_packet_t pkt; uint8_t *frame; - size_t frame_len; + uint32_t frame_len; unsigned i; unsigned flags; int sockfd; @@ -385,8 +385,7 @@ int send_pkt_sock_basic(pkt_sock_t *const pkt_sock, while (i < len) { pkt = pkt_table[i]; - frame = odp_packet_l2(pkt); - frame_len = odp_packet_get_len(pkt); + frame = odp_packet_l2_ptr(pkt, &frame_len); ret = send(sockfd, frame, frame_len, flags); if (odp_unlikely(ret == -1)) { @@ -492,10 +491,9 @@ int send_pkt_sock_mmsg(pkt_sock_t *const pkt_sock, memset(msgvec, 0, sizeof(msgvec)); for (i = 0; i < len; i++) { - uint8_t *const frame = odp_packet_l2(pkt_table[i]); - const size_t frame_len = odp_packet_get_len(pkt_table[i]); - iovecs[i].iov_base = frame; - iovecs[i].iov_len = frame_len; + uint32_t seglen; + iovecs[i].iov_base = odp_packet_l2_ptr(pkt_table[i], &seglen); + iovecs[i].iov_len = seglen; msgvec[i].msg_hdr.msg_iov = &iovecs[i]; msgvec[i].msg_hdr.msg_iovlen = 1; } @@ -635,7 +633,7 @@ static inline unsigned pkt_mmap_v2_tx(int sock, struct ring *ring, { union frame_map ppd; uint8_t *pkt_buf; - size_t pkt_len; + uint32_t pkt_len; unsigned frame_num, next_frame_num; int ret; unsigned i = 0; @@ -648,8 +646,7 @@ static inline unsigned pkt_mmap_v2_tx(int sock, struct ring *ring, next_frame_num = (frame_num + 1) % ring->rd_num; - pkt_buf = odp_packet_l2(pkt_table[i]); - pkt_len = odp_packet_get_len(pkt_table[i]); + pkt_buf = odp_packet_l2_ptr(pkt_table[i], &pkt_len); ppd.v2->tp_h.tp_snaplen = pkt_len; ppd.v2->tp_h.tp_len = pkt_len;