vxlan: refactor setting/getting vxlan flags

As these properties are FLAG types in the netlink
API, we should also expose them as such in the
libnl API.

It is less code and require less code to support a new
flag.

The point is really to keep the API smaller instead of
wasting a getter and setter for each flag.
This commit is contained in:
Thomas Haller
2016-11-05 17:12:03 +01:00
parent 755b8cc008
commit fb8cb3e917
3 changed files with 20 additions and 96 deletions
+2 -8
View File
@@ -106,11 +106,8 @@ extern int rtnl_link_vxlan_get_remcsum_tx(struct rtnl_link *);
extern int rtnl_link_vxlan_set_remcsum_rx(struct rtnl_link *, uint8_t);
extern int rtnl_link_vxlan_get_remcsum_rx(struct rtnl_link *);
extern int rtnl_link_vxlan_set_gbp(struct rtnl_link *, int);
extern int rtnl_link_vxlan_get_gbp(struct rtnl_link *);
extern int rtnl_link_vxlan_set_remcsum_nopartial(struct rtnl_link *, int);
extern int rtnl_link_vxlan_get_remcsum_nopartial(struct rtnl_link *);
extern int rtnl_link_vxlan_set_flags(struct rtnl_link *, uint32_t flags, int enable);
extern int rtnl_link_vxlan_get_flags(struct rtnl_link *, uint32_t *out_flags);
extern int rtnl_link_vxlan_set_collect_metadata(struct rtnl_link *, uint8_t);
extern int rtnl_link_vxlan_get_collect_metadata(struct rtnl_link *);
@@ -118,9 +115,6 @@ extern int rtnl_link_vxlan_get_collect_metadata(struct rtnl_link *);
extern int rtnl_link_vxlan_set_label(struct rtnl_link *, uint32_t);
extern int rtnl_link_vxlan_get_label(struct rtnl_link *, uint32_t *);
extern int rtnl_link_vxlan_set_gpe(struct rtnl_link *, int);
extern int rtnl_link_vxlan_get_gpe(struct rtnl_link *);
#ifdef __cplusplus
}
#endif
+16 -82
View File
@@ -1155,7 +1155,7 @@ int rtnl_link_vxlan_get_limit(struct rtnl_link *link, uint32_t *limit)
* @return 0 on success or a negative error code
*/
int rtnl_link_vxlan_set_port_range(struct rtnl_link *link,
struct ifla_vxlan_port_range *range)
struct ifla_vxlan_port_range *range)
{
struct vxlan_info *vxi = link->l_info;
@@ -1178,7 +1178,7 @@ int rtnl_link_vxlan_set_port_range(struct rtnl_link *link,
* @return 0 on success or a negative error code
*/
int rtnl_link_vxlan_get_port_range(struct rtnl_link *link,
struct ifla_vxlan_port_range *range)
struct ifla_vxlan_port_range *range)
{
struct vxlan_info *vxi = link->l_info;
@@ -1659,78 +1659,6 @@ int rtnl_link_vxlan_get_remcsum_rx(struct rtnl_link *link)
return vxi->vxi_remcsum_rx;
}
/**
* Set group-based policy extension flag to use for VXLAN
* @arg link Link object
* @arg enable Boolean enabling or disabling flag
*
* @return 0 on success or a negative error code
*/
int rtnl_link_vxlan_set_gbp(struct rtnl_link *link, int enable)
{
struct vxlan_info *vxi = link->l_info;
IS_VXLAN_LINK_ASSERT(link);
if (enable)
vxi->vxi_flags |= RTNL_LINK_VXLAN_F_GBP;
else
vxi->vxi_flags &= ~RTNL_LINK_VXLAN_F_GBP;
return 0;
}
/**
* Get group-based policy extension flag to use for VXLAN
* @arg link Link object
*
* @return Status value on success or a negative error code
*/
int rtnl_link_vxlan_get_gbp(struct rtnl_link *link)
{
struct vxlan_info *vxi = link->l_info;
IS_VXLAN_LINK_ASSERT(link);
return !!(vxi->vxi_flags & RTNL_LINK_VXLAN_F_GBP);
}
/**
* Set no-partial remote offload checksum flag to use for VXLAN
* @arg link Link object
* @arg enable Boolean enabling or disabling flag
*
* @return 0 on success or a negative error code
*/
int rtnl_link_vxlan_set_remcsum_nopartial(struct rtnl_link *link, int enable)
{
struct vxlan_info *vxi = link->l_info;
IS_VXLAN_LINK_ASSERT(link);
if (enable)
vxi->vxi_flags |= RTNL_LINK_VXLAN_F_REMCSUM_NOPARTIAL;
else
vxi->vxi_flags &= ~RTNL_LINK_VXLAN_F_REMCSUM_NOPARTIAL;
return 0;
}
/**
* Get no-partial remote offload checksum flag to use for VXLAN
* @arg link Link object
*
* @return Status value on success or a negative error code
*/
int rtnl_link_vxlan_get_remcsum_nopartial(struct rtnl_link *link)
{
struct vxlan_info *vxi = link->l_info;
IS_VXLAN_LINK_ASSERT(link);
return !!(vxi->vxi_flags & RTNL_LINK_VXLAN_F_REMCSUM_NOPARTIAL);
}
/**
* Set collect metadata status to use for VXLAN
* @arg link Link object
@@ -1812,39 +1740,45 @@ int rtnl_link_vxlan_get_label(struct rtnl_link *link, uint32_t *label)
}
/**
* Set generic protocol extension flag to use for VXLAN
* Set VXLAN flags RTNL_LINK_VXLAN_F_*
* @arg link Link object
* @flags Which flags to set
* @arg enable Boolean enabling or disabling flag
*
* @return 0 on success or a negative error code
*/
int rtnl_link_vxlan_set_gpe(struct rtnl_link *link, int enable)
int rtnl_link_vxlan_set_flags(struct rtnl_link *link, uint32_t flags, int enable)
{
struct vxlan_info *vxi = link->l_info;
IS_VXLAN_LINK_ASSERT(link);
if (flags & ~(RTNL_LINK_VXLAN_F_GBP | RTNL_LINK_VXLAN_F_GPE | RTNL_LINK_VXLAN_F_REMCSUM_NOPARTIAL))
return -NLE_INVAL;
if (enable)
vxi->vxi_flags |= RTNL_LINK_VXLAN_F_GPE;
vxi->vxi_flags |= flags;
else
vxi->vxi_flags &= ~RTNL_LINK_VXLAN_F_GPE;
vxi->vxi_flags &= ~flags;
return 0;
}
/**
* Get generic protocol extension flag to use for VXLAN
* Get VXLAN flags RTNL_LINK_VXLAN_F_*
* @arg link Link object
* @arg out_flags Output value for flags. Must be present.
*
* @return Status value on success or a negative error code
* @return Zero on success or a negative error code
*/
int rtnl_link_vxlan_get_gpe(struct rtnl_link *link)
int rtnl_link_vxlan_get_flags(struct rtnl_link *link, uint32_t *out_flags)
{
struct vxlan_info *vxi = link->l_info;
IS_VXLAN_LINK_ASSERT(link);
return !!(vxi->vxi_flags & RTNL_LINK_VXLAN_F_GPE);
*out_flags = vxi->vxi_flags;
return 0;
}
/** @} */
+2 -6
View File
@@ -965,22 +965,18 @@ global:
rtnl_link_macvlan_set_macmode;
rtnl_link_macvlan_str2macmode;
rtnl_link_vxlan_get_collect_metadata;
rtnl_link_vxlan_get_gbp;
rtnl_link_vxlan_get_gpe;
rtnl_link_vxlan_get_flags;
rtnl_link_vxlan_get_label;
rtnl_link_vxlan_get_port;
rtnl_link_vxlan_get_remcsum_nopartial;
rtnl_link_vxlan_get_remcsum_rx;
rtnl_link_vxlan_get_remcsum_tx;
rtnl_link_vxlan_get_udp_csum;
rtnl_link_vxlan_get_udp_zero_csum6_rx;
rtnl_link_vxlan_get_udp_zero_csum6_tx;
rtnl_link_vxlan_set_collect_metadata;
rtnl_link_vxlan_set_gbp;
rtnl_link_vxlan_set_gpe;
rtnl_link_vxlan_set_flags;
rtnl_link_vxlan_set_label;
rtnl_link_vxlan_set_port;
rtnl_link_vxlan_set_remcsum_nopartial;
rtnl_link_vxlan_set_remcsum_rx;
rtnl_link_vxlan_set_remcsum_tx;
rtnl_link_vxlan_set_udp_csum;