perf: 将vxlan_set_opt/vxlan_get_opt定义为inline

This commit is contained in:
luwenpeng
2023-11-28 17:23:13 +08:00
parent 95abad41b5
commit 6d1a69aea6
2 changed files with 32 additions and 35 deletions

View File

@@ -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

View File

@@ -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)