From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f67.google.com (mail-wm0-f67.google.com [74.125.82.67]) by dpdk.org (Postfix) with ESMTP id 8CB807CB6 for ; Sat, 9 Dec 2017 22:39:24 +0100 (CET) Received: by mail-wm0-f67.google.com with SMTP id 64so8140998wme.3 for ; Sat, 09 Dec 2017 13:39:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=dz3ZZJDo6hvGwAlx0VK1YrPAC2O7+PSO/sLuBihupt4=; b=iVJjRKiqJFhjouvHwBV7JgpNORPzc0KcWGOHqk1rBxQ6BafRIjiBbzFu9PKLwjzALA 478WVPJ3LnhHejyti1dJhqQIwb2k3yGQgXXJ6pkvxcHKaf7wPbWvY7SI3e1ZQqprvd3A ylwC7YoSFvCi/YfyXfSkxYQIfD+/JIxpCdMhS5kClFiBhtJ+r8EiQJEu5isR/iE3MA4e hlOFNYo3uSRCm92v4+1vyEtUHxJxouMqTX8IND9NzyiBQNWgexq2FapFag4XFdP/bpLr e6DHZoApx2rx4vsCl7ntnCcHlAuVJlyg79D5WEL6R3jnHHA3Ymom6baG5o6hA24RJEt2 +H4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=dz3ZZJDo6hvGwAlx0VK1YrPAC2O7+PSO/sLuBihupt4=; b=EUwG6s2NgjE2v8o5oKKLLmAkhhggiDWiwU5sancYUbNgG2oCHwsOZWrfa9edfGRaVw bZZnwmilaLJL7QvH6msq9ZKfvpeqkmg86lDg9ZbKdvL2dkfRr0/at2V9g+lTR1FJesUg jQI9m12NnTyibOsh4aW7OkEp9mAELNk1hbYizqkmUx6LwUBGjWYonl+dMocv7gGQOysV 6Indh0/YJ6+trwDG2+44UowrZe+dD+BM48EqXg1xv9mbvhLb66sgouxb990KUiTJg/Zv Zwv4JGSTA1wzlcdNWGZrKo62/NSbe8ypUWYvTSNoPulPJ+s8mlLiY+buvtzCLCtFKStt 6m+A== X-Gm-Message-State: AJaThX5X/f7SWWGFqk8zO79+3h8+XPoCHf7i6t2Ctr6qB0MehZrNQiXD jMGX4rqrvqD14pHY3GqDhD/37vJK X-Google-Smtp-Source: AGs4zMYy2OBdRSU9t2xhHio/WFqOprYgekHmlH2Dt0VH/ivu+m8CEbs1B7ETykz8A70Qc4lqKC5QZw== X-Received: by 10.80.135.199 with SMTP id 7mr54783258edz.103.1512855564025; Sat, 09 Dec 2017 13:39:24 -0800 (PST) Received: from xone.net.sahm.ae ([94.205.75.192]) by smtp.gmail.com with ESMTPSA id y3sm4841357edb.37.2017.12.09.13.39.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 09 Dec 2017 13:39:23 -0800 (PST) From: "Ilya V. Matveychikov" To: dev@dpdk.org Cc: olivier.matz@6wind.com, "Ilya V. Matveychikov" Date: Sun, 10 Dec 2017 00:39:18 +0300 Message-Id: <20171209213918.6311-1-matvejchikov@gmail.com> X-Mailer: git-send-email 2.14.2 In-Reply-To: References: Subject: [dpdk-dev] [PATCH v2] mbuf: check sanity of data_len and pkt_len as well 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: , X-List-Received-Date: Sat, 09 Dec 2017 21:39:24 -0000 Update rte_mbuf_sanity_check() to check sanity of data_len and pkt_len fields. For segmented packets it is supposed that head's pkt_len field should be the sum of all segments data_len values. Signed-off-by: Ilya V. Matveychikov --- lib/librte_mbuf/rte_mbuf.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/librte_mbuf/rte_mbuf.c b/lib/librte_mbuf/rte_mbuf.c index 7543662f7..937fd70ea 100644 --- a/lib/librte_mbuf/rte_mbuf.c +++ b/lib/librte_mbuf/rte_mbuf.c @@ -202,8 +202,7 @@ rte_pktmbuf_pool_create(const char *name, unsigned n, void rte_mbuf_sanity_check(const struct rte_mbuf *m, int is_header) { - const struct rte_mbuf *m_seg; - unsigned int nb_segs; + unsigned int nb_segs, pkt_len; if (m == NULL) rte_panic("mbuf is NULL\n"); @@ -224,14 +223,22 @@ rte_mbuf_sanity_check(const struct rte_mbuf *m, int is_header) if (is_header == 0) return; + /* data_len is supposed to be not more than pkt_len */ + if (m->data_len > m->pkt_len) + rte_panic("bad data_len\n"); + nb_segs = m->nb_segs; - m_seg = m; - while (m_seg && nb_segs != 0) { - m_seg = m_seg->next; - nb_segs--; - } - if (nb_segs != 0) + pkt_len = m->pkt_len; + + do { + nb_segs -= 1; + pkt_len -= m->data_len; + } while ((m = m->next) != NULL); + + if (nb_segs) rte_panic("bad nb_segs\n"); + if (pkt_len) + rte_panic("bad pkt_len\n"); } /* dump a mbuf on console */ -- 2.14.2