diff options
author | Thomas Graf <tgraf@suug.ch> | 2013-03-14 17:52:17 (GMT) |
---|---|---|
committer | Thomas Graf <tgraf@suug.ch> | 2013-03-14 17:52:17 (GMT) |
commit | 549d26dc87a8430f99aa8e48236a25630b2b1d31 (patch) | |
tree | 0c0156264c448fc8832429bef40716e1dfece828 | |
parent | e09e7f1035fc2a8c918822cbfcfac61c77153497 (diff) | |
download | libnl-549d26dc87a8430f99aa8e48236a25630b2b1d31.zip libnl-549d26dc87a8430f99aa8e48236a25630b2b1d31.tar.gz libnl-549d26dc87a8430f99aa8e48236a25630b2b1d31.tar.bz2 |
rtnl-addr: Inherit prefix length to nl_addr objs in rtnl_addr_set_prefixlen()
Previously if using rtnl_addr_set_prefixlen() the new prefix length
was not forwarded to the corresponding 'struct nl_addr' objects
associated with address already and thus the comparison function
would fail.
This patch also clears the internal ADDR_ATTR_PREFIXLEN flag if
the prefix length has been reset.
Signed-off-by: Thomas Graf <tgraf@suug.ch>
-rw-r--r-- | lib/route/addr.c | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/lib/route/addr.c b/lib/route/addr.c index 95a9447..e62c964 100644 --- a/lib/route/addr.c +++ b/lib/route/addr.c @@ -814,10 +814,39 @@ int rtnl_addr_get_family(struct rtnl_addr *addr) return addr->a_family; } -void rtnl_addr_set_prefixlen(struct rtnl_addr *addr, int prefix) +/** + * Set the prefix length / netmask + * @arg addr Address + * @arg prefixlen Length of prefix (netmask) + * + * Modifies the length of the prefix. If the address object contains a peer + * address the prefix length will apply to it, otherwise the prefix length + * will apply to the local address of the address. + * + * If the address object contains a peer or local address the corresponding + * `struct nl_addr` will be updated with the new prefix length. + * + * @note Specifying a length of 0 will remove the prefix length alltogether. + * + * @see rtnl_addr_get_prefixlen() + */ +void rtnl_addr_set_prefixlen(struct rtnl_addr *addr, int prefixlen) { - addr->a_prefixlen = prefix; - addr->ce_mask |= ADDR_ATTR_PREFIXLEN; + addr->a_prefixlen = prefixlen; + + if (prefixlen) + addr->ce_mask |= ADDR_ATTR_PREFIXLEN; + else + addr->ce_mask &= ~ADDR_ATTR_PREFIXLEN; + + /* + * The prefix length always applies to the peer address if + * a peer address is present. + */ + if (addr->a_peer) + nl_addr_set_prefixlen(addr->a_peer, prefixlen); + else if (addr->a_local) + nl_addr_set_prefixlen(addr->a_local, prefixlen); } int rtnl_addr_get_prefixlen(struct rtnl_addr *addr) |