perf: 将vxlan_set_opt/vxlan_get_opt定义为inline
This commit is contained in:
@@ -68,8 +68,38 @@ enum vni_opt
|
|||||||
#define VXLAN_DST_PORT 4789
|
#define VXLAN_DST_PORT 4789
|
||||||
#define VXLAN_FRAME_HDR_LEN (sizeof(struct ethhdr) + sizeof(struct ip) + sizeof(struct udphdr) + sizeof(struct vxlan_hdr))
|
#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);
|
static inline 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);
|
{
|
||||||
|
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 0 : success
|
||||||
// return -1 : error
|
// return -1 : error
|
||||||
|
|||||||
@@ -67,39 +67,6 @@ static inline void udp_header_encode(struct udphdr *udp_hdr, uint16_t udp_sport,
|
|||||||
udp_hdr->uh_sum = 0;
|
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 0 : success
|
||||||
// return -1 : error
|
// return -1 : error
|
||||||
int vxlan_frame_decode(struct vxlan_hdr **vxlan_hdr, const char *data, uint16_t len)
|
int vxlan_frame_decode(struct vxlan_hdr **vxlan_hdr, const char *data, uint16_t len)
|
||||||
|
|||||||
Reference in New Issue
Block a user