diff options
author | Thomas Haller <thaller@redhat.com> | 2017-05-12 08:37:53 (GMT) |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2017-05-12 09:27:57 (GMT) |
commit | a25db574707575913e7a9aea49fd7b16c12f7e03 (patch) | |
tree | 54c4449bbd5032bf8226de065803dbd2920c6cb2 /lib/route | |
parent | ef4a2bdfe2d4059a0be910b5491ffddf2cde8952 (diff) | |
download | libnl-a25db574707575913e7a9aea49fd7b16c12f7e03.zip libnl-a25db574707575913e7a9aea49fd7b16c12f7e03.tar.gz libnl-a25db574707575913e7a9aea49fd7b16c12f7e03.tar.bz2 |
rule: change API for setting/getting l3mdev rule property
- for rtnl_rule_set_l3mdev(), also allow unsetting the l3mdev field.
In practice, kernel only allows for two options: either omit
tb[FRA_L3MDEV] or set it to 1. As such, rtnl_rule_set_l3mdev()
allows for both of these. In principle the setter could get
extended to set other values. Such values are reserved.
- for rtnl_rule_get_l3mdev() also return an error code. I think it
is appropriate to mix value and negative error code, as long as
the range of values cannot overlap with error codes.
Arguably, the outcome is a bit awkward, as the function now is
expected to return -NLE_MISSING_ATTR or 1. So, the best check
is probably
if (rtnl_rule_get_l3mdev(r) > 0) { ... }
The reason for this change is that libnl should expose the netlink
API without coercing uint8 to boolean. That way, future changes
in kernel don't require update to libnl3.
Signed-off-by: Thomas Haller <thaller@redhat.com>
Diffstat (limited to 'lib/route')
-rw-r--r-- | lib/route/rule.c | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/lib/route/rule.c b/lib/route/rule.c index 76d9fe8..e257349 100644 --- a/lib/route/rule.c +++ b/lib/route/rule.c @@ -706,14 +706,41 @@ uint8_t rtnl_rule_get_action(struct rtnl_rule *rule) return rule->r_action; } -void rtnl_rule_set_l3mdev(struct rtnl_rule *rule) +/** + * Set l3mdev value of the rule (FRA_L3MDEV) + * @arg rule rule + * @arg value value to set + * + * Set the l3mdev value to value. Currently supported values + * are only 1 (set it) and -1 (unset it). All other values + * are reserved. + */ +void rtnl_rule_set_l3mdev(struct rtnl_rule *rule, int value) { - rule->r_l3mdev = 1; - rule->ce_mask |= RULE_ATTR_L3MDEV; + if (value >= 0) { + rule->r_l3mdev = (uint8_t) value; + rule->ce_mask |= RULE_ATTR_L3MDEV; + } else { + rule->r_l3mdev = 0; + rule->ce_mask &= ~((uint32_t) RULE_ATTR_L3MDEV); + } } -uint8_t rtnl_rule_get_l3mdev(struct rtnl_rule *rule) +/** + * Get l3mdev value of the rule (FRA_L3MDEV) + * @arg rule rule + * + * @return a negative error code, including -NLE_MISSING_ATTR + * if the property is unset. Otherwise returns a non-negative + * value. As FRA_L3MDEV is a boolean, the only expected + * value at the moment is 1. + */ +int rtnl_rule_get_l3mdev(struct rtnl_rule *rule) { + if (!rule) + return -NLE_INVAL; + if (!(rule->ce_mask & RULE_ATTR_L3MDEV)) + return -NLE_MISSING_ATTR; return rule->r_l3mdev; } |