From 6d1a69aea6a8e6876149411aa2a29ebd18381741 Mon Sep 17 00:00:00 2001 From: luwenpeng Date: Tue, 28 Nov 2023 17:23:13 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E5=B0=86vxlan=5Fset=5Fopt/vxlan=5Fget?= =?UTF-8?q?=5Fopt=E5=AE=9A=E4=B9=89=E4=B8=BAinline?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/include/vxlan.h | 34 ++++++++++++++++++++++++++++++++-- common/src/vxlan.cpp | 33 --------------------------------- 2 files changed, 32 insertions(+), 35 deletions(-) diff --git a/common/include/vxlan.h b/common/include/vxlan.h index 97b439a..942c2f3 100644 --- a/common/include/vxlan.h +++ b/common/include/vxlan.h @@ -68,8 +68,38 @@ enum vni_opt #define VXLAN_DST_PORT 4789 #define VXLAN_FRAME_HDR_LEN (sizeof(struct ethhdr) + sizeof(struct ip) + sizeof(struct udphdr) + sizeof(struct vxlan_hdr)) -void vxlan_set_opt(struct vxlan_hdr *hdr, enum vni_opt opt, uint8_t val); -uint8_t vxlan_get_opt(struct vxlan_hdr *hdr, enum vni_opt opt); +static inline void vxlan_set_opt(struct vxlan_hdr *hdr, enum vni_opt opt, uint8_t val) +{ + switch (opt) + { + case VNI_OPT_DIR: + hdr->dir = (!!val); + break; + case VNI_OPT_TRAFFIC: + hdr->traffic = (!!val); + break; + case VNI_OPT_SFINDEX: + hdr->sf_index = (0x1f & val); + break; + default: + break; + } +} + +static inline uint8_t vxlan_get_opt(struct vxlan_hdr *hdr, enum vni_opt opt) +{ + switch (opt) + { + case VNI_OPT_DIR: + return hdr->dir; + case VNI_OPT_TRAFFIC: + return hdr->traffic; + case VNI_OPT_SFINDEX: + return hdr->sf_index; + default: + return 0; + } +} // return 0 : success // return -1 : error diff --git a/common/src/vxlan.cpp b/common/src/vxlan.cpp index ad214b4..d5c86d7 100644 --- a/common/src/vxlan.cpp +++ b/common/src/vxlan.cpp @@ -67,39 +67,6 @@ static inline void udp_header_encode(struct udphdr *udp_hdr, uint16_t udp_sport, udp_hdr->uh_sum = 0; } -void vxlan_set_opt(struct vxlan_hdr *hdr, enum vni_opt opt, uint8_t val) -{ - switch (opt) - { - case VNI_OPT_DIR: - hdr->dir = (!!val); - break; - case VNI_OPT_TRAFFIC: - hdr->traffic = (!!val); - break; - case VNI_OPT_SFINDEX: - hdr->sf_index = (0x1f & val); - break; - default: - break; - } -} - -uint8_t vxlan_get_opt(struct vxlan_hdr *hdr, enum vni_opt opt) -{ - switch (opt) - { - case VNI_OPT_DIR: - return (!!hdr->dir); - case VNI_OPT_TRAFFIC: - return (!!hdr->traffic); - case VNI_OPT_SFINDEX: - return hdr->sf_index; - default: - return 0; - } -} - // return 0 : success // return -1 : error int vxlan_frame_decode(struct vxlan_hdr **vxlan_hdr, const char *data, uint16_t len)