From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 2FD79A0542; Sat, 17 Dec 2022 19:00:07 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C313F40695; Sat, 17 Dec 2022 19:00:06 +0100 (CET) Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) by mails.dpdk.org (Postfix) with ESMTP id C3A1B4068E for ; Sat, 17 Dec 2022 19:00:05 +0100 (CET) Received: by mail-wm1-f44.google.com with SMTP id k22-20020a05600c1c9600b003d1ee3a6289so3811979wms.2 for ; Sat, 17 Dec 2022 10:00:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/3zSN9x8ijrajOyzj6r3Q7LqBgb2k7gwWOgFrBalS30=; b=RGMeIai08DwhGsGJUrcxnW10wlW/HyDMkzdZgqXVPm3bLWwe04xMjyUFYwZ/BpFqpD 3Ok08QPeKF1OX1qngCcTk/OLKvo+pmPvOhrACyZqxyaJ4NkVDdHxNfZc1R1Z6EAP8UCZ IaOrPaDYDDA4YUurB+zjQlDY+p2eZqd1rMgddQ6h6MzfhX3Peysa7YTiOejJtau+cwDV xLM4FTVgsMXSrU+i8SyOyepQa1wSpGoKmQFAF8WU4C/g+xS6YsE4rf44XVaxOx9maNws rV1TLsJucWA24DuoWStpR1+zNQNMOsLTAVIEYm475LFHDwQfFlSgQkgCVv2+5kEqDHEZ 05Dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/3zSN9x8ijrajOyzj6r3Q7LqBgb2k7gwWOgFrBalS30=; b=I7X/khS/UPLLgf1DcIj7rqy4z4Dsm3QiLVHJI6mxHPrlabSQcWkxmE8fiO1ki7ql37 JE9nbDw1gDqGBdvsWMpYNSrQBbenO6YnVZnklkTI5ycy3MXbddUEdZ2j7MnDLgn7egco qB+QXp7bJEot49XwaHAP7TUGwInfl+IfDbTrVY4C0cvdE9jciCKWjzDtuXqDKiMvXtLH 7MMGlpM43kAycPDCBdrU87ZhGZPaUAUQ/nmzCtce+VDEpXz6erQL1FeN8I2eoJeHVmns pTAEeotHAmvHbFaYOHwfJewlyB0YnJlfm5qoWGSwrMYDLVLKJNxARi5AtLaf5ZRXBhQJ 2SIQ== X-Gm-Message-State: ANoB5pn1m5MG9KUNC15NuAttSXoZvAJdMiM+tYVfC2aB3Z81pwo7nzX+ YCE5eAhFlwhuGxMu0gENvYA= X-Google-Smtp-Source: AA0mqf58qrEBkGUpqLFKQo6P/9cyH+Voqf/mNTKsyTp8vmmFWQWpf+JSVDxCway3Iu8FJ+R4B8b3eQ== X-Received: by 2002:a05:600c:795:b0:3d1:cee0:46d0 with SMTP id z21-20020a05600c079500b003d1cee046d0mr28509258wmo.25.1671300005368; Sat, 17 Dec 2022 10:00:05 -0800 (PST) Received: from deluminator.localdomain (115-186-134-228.nayatel.pk. [115.186.134.228]) by smtp.gmail.com with ESMTPSA id n15-20020a1c720f000000b003cf4ec90938sm6463863wmc.21.2022.12.17.10.00.03 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 17 Dec 2022 10:00:05 -0800 (PST) From: Tanzeel-inline To: olivier.matz@6wind.com Cc: dev@dpdk.org, Tanzeel-inline , Tanzeel Ahmed Subject: [PATCH] lib/net: added push MPLS header API Date: Sat, 17 Dec 2022 12:59:57 -0500 Message-Id: <1671299997-13001-1-git-send-email-tanxeel1.ahmed@gmail.com> X-Mailer: git-send-email 1.8.3.1 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Push MPLS header after ethernet header, updates ethernet type and MPLS bs bit if required. Signed-off-by: Tanzeel Ahmed --- .mailmap | 1 + lib/net/rte_mpls.h | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/.mailmap b/.mailmap index 75884b6..5e06669 100644 --- a/.mailmap +++ b/.mailmap @@ -1301,6 +1301,7 @@ Takeshi Yoshimura Takuya Asada Tal Avraham Tal Shnaiderman +Tanzeel Ahmed Tao Y Yang Tao Zhu Taripin Samuel diff --git a/lib/net/rte_mpls.h b/lib/net/rte_mpls.h index 3e8cb90..6ae72df 100644 --- a/lib/net/rte_mpls.h +++ b/lib/net/rte_mpls.h @@ -13,6 +13,8 @@ #include #include +#include +#include #ifdef __cplusplus extern "C" { @@ -36,6 +38,63 @@ struct rte_mpls_hdr { uint8_t ttl; /**< Time to live. */ } __rte_packed; +#define RTE_MPLS_HLEN 4 /**< Length of MPLS header. */ + +/** + * Insert MPLS header into the packet. + * + * If it's first MPLS header to be inserted in the packet, + * - Updates the ether type. + * - Sets the MPLS bottom-of-stack bit to 1. + * + * @param m + * The pointer to the mbuf. + * @param mp + * The pointer to the MPLS header. + * @return + * 0 on success, -1 on error (If no ethernet header exists) + */ +static inline int +rte_mpls_push_over_l2(struct rte_mbuf **m, struct rte_mpls_hdr *mp) +{ + struct rte_ether_hdr *oh, *nh; + + /* Can't insert header if mbuf is shared */ + if (!RTE_MBUF_DIRECT(*m) || rte_mbuf_refcnt_read(*m) > 1) + return -EINVAL; + + /*Can't insert header if ethernet frame doesn't exist*/ + if (rte_pktmbuf_data_len(*m) < RTE_ETHER_HDR_LEN) + return -EINVAL; + + oh = rte_pktmbuf_mtod(*m, struct rte_ether_hdr *); + nh = (struct rte_ether_hdr *)(void *) + rte_pktmbuf_prepend(*m, sizeof(struct rte_mpls_hdr)); + if (nh == NULL) + return -ENOSPC; + + memmove(nh, oh, RTE_ETHER_HDR_LEN); + + mp->tag_msb = rte_cpu_to_be_16(mp->tag_msb); + + /* If first MPLS header, update ether type and bottom-of-stack bit */ + if (nh->ether_type != rte_cpu_to_be_16(RTE_ETHER_TYPE_MPLS)) + { + nh->ether_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_MPLS); + mp->bs = 1; + } + else + { + mp->bs = 0; + } + + /* Copy the MPLS header after ethernet frame */ + rte_memcpy(rte_pktmbuf_mtod_offset(*m, char*, sizeof(struct rte_ether_hdr)), mp, RTE_MPLS_HLEN); + + (*m)->data_len += RTE_MPLS_HLEN; + return 0; +} + #ifdef __cplusplus } #endif -- 1.8.3.1