summaryrefslogtreecommitdiffhomepage
path: root/system-linux.c
diff options
context:
space:
mode:
authorJohannes Kimmel <fff@bareminimum.eu>2020-09-04 04:59:41 +0200
committerHans Dedecker <dedeckeh@gmail.com>2020-09-12 21:12:48 +0200
commit226566b967dc4ef4d83ed7844b8ad746f4306f8d (patch)
treed02f90b9f2548a6ae5262ebceb1f8ce7ee55936b /system-linux.c
parenta3c033e2afc289672e0ed4b8d8a835d509715af8 (diff)
netifd: vxlan: refactor mapping of boolean attrs
Add a small function to handle boolean options and make use of it to handle: - rxcsum - txcsum Signed-off-by: Johannes Kimmel <fff@bareminimum.eu>
Diffstat (limited to 'system-linux.c')
-rw-r--r--system-linux.c24
1 files changed, 14 insertions, 10 deletions
diff --git a/system-linux.c b/system-linux.c
index 42f0de3..d87a9ee 100644
--- a/system-linux.c
+++ b/system-linux.c
@@ -3073,6 +3073,17 @@ failure:
#endif
#ifdef IFLA_VXLAN_MAX
+static void system_vxlan_map_bool_attr(struct nl_msg *msg, struct blob_attr **tb_data, int attrtype, int vxlandatatype, bool invert) {
+ struct blob_attr *cur;
+ if ((cur = tb_data[vxlandatatype])) {
+ bool val = blobmsg_get_bool(cur);
+ if (invert) {
+ val = !val;
+ }
+ nla_put_u8(msg, attrtype, val);
+ }
+}
+
static int system_add_vxlan(const char *name, const unsigned int link, struct blob_attr **tb, bool v6)
{
struct blob_attr *tb_data[__VXLAN_DATA_ATTR_MAX];
@@ -3210,16 +3221,9 @@ static int system_add_vxlan(const char *name, const unsigned int link, struct bl
nla_put(msg, IFLA_VXLAN_PORT_RANGE, sizeof(srcports), &srcports);
}
- if ((cur = tb_data[VXLAN_DATA_ATTR_RXCSUM])) {
- bool rxcsum = blobmsg_get_bool(cur);
- nla_put_u8(msg, IFLA_VXLAN_UDP_ZERO_CSUM6_RX, !rxcsum);
- }
-
- if ((cur = tb_data[VXLAN_DATA_ATTR_TXCSUM])) {
- bool txcsum = blobmsg_get_bool(cur);
- nla_put_u8(msg, IFLA_VXLAN_UDP_CSUM, txcsum);
- nla_put_u8(msg, IFLA_VXLAN_UDP_ZERO_CSUM6_TX, !txcsum);
- }
+ system_vxlan_map_bool_attr(msg, tb_data, IFLA_VXLAN_UDP_CSUM, VXLAN_DATA_ATTR_TXCSUM, false);
+ system_vxlan_map_bool_attr(msg, tb_data, IFLA_VXLAN_UDP_ZERO_CSUM6_RX, VXLAN_DATA_ATTR_RXCSUM, true);
+ system_vxlan_map_bool_attr(msg, tb_data, IFLA_VXLAN_UDP_ZERO_CSUM6_TX, VXLAN_DATA_ATTR_TXCSUM, true);
if ((cur = tb[TUNNEL_ATTR_TOS])) {
char *str = blobmsg_get_string(cur);