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)