diff options
author | Thomas Haller <thaller@redhat.com> | 2016-03-31 14:19:10 (GMT) |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2016-04-15 14:24:15 (GMT) |
commit | 656bf6b16f9d015195bf9fb2fe58b0964f2dfc94 (patch) | |
tree | a172de6e4fe87328e756cd7551766233792a1b8f /lib/route/link/sit.c | |
parent | 00034104fc9fdc70440ba8f1cf4718d4139c2893 (diff) | |
download | libnl-656bf6b16f9d015195bf9fb2fe58b0964f2dfc94.zip libnl-656bf6b16f9d015195bf9fb2fe58b0964f2dfc94.tar.gz libnl-656bf6b16f9d015195bf9fb2fe58b0964f2dfc94.tar.bz2 |
sit: refactor IS_SIT_LINK_ASSERT()
Also check for NULL link and dereference link before
basic error checking.
Also move the declaration of the @sit member inside
the macro. Obviously, the macro must now always come at
first, after declaring local auto variables.
Signed-off-by: Thomas Haller <thaller@redhat.com>
Diffstat (limited to 'lib/route/link/sit.c')
-rw-r--r-- | lib/route/link/sit.c | 79 |
1 files changed, 26 insertions, 53 deletions
diff --git a/lib/route/link/sit.c b/lib/route/link/sit.c index fc0fd75..3306f53 100644 --- a/lib/route/link/sit.c +++ b/lib/route/link/sit.c @@ -362,11 +362,16 @@ static struct rtnl_link_info_ops sit_info_ops = { .io_free = sit_free, }; -#define IS_SIT_LINK_ASSERT(link) \ - if ((link)->l_info_ops != &sit_info_ops) { \ - APPBUG("Link is not a sit link. set type \"sit\" first."); \ - return -NLE_OPNOTSUPP; \ - } +#define IS_SIT_LINK_ASSERT(link, sit) \ + struct sit_info *sit; \ + do { \ + const struct rtnl_link *_link = (link); \ + if (!_link || _link->l_info_ops != &sit_info_ops) { \ + APPBUG("Link is not a sit link. set type \"sit\" first."); \ + return -NLE_OPNOTSUPP; \ + } \ + (sit) = _link->l_info; \ + } while (0) struct rtnl_link *rtnl_link_sit_alloc(void) { @@ -432,9 +437,7 @@ int rtnl_link_sit_add(struct nl_sock *sk, const char *name) */ int rtnl_link_sit_set_link(struct rtnl_link *link, uint32_t index) { - struct sit_info *sit = link->l_info; - - IS_SIT_LINK_ASSERT(link); + IS_SIT_LINK_ASSERT(link, sit); sit->link = index; sit->sit_mask |= SIT_ATTR_LINK; @@ -450,9 +453,7 @@ int rtnl_link_sit_set_link(struct rtnl_link *link, uint32_t index) */ uint32_t rtnl_link_sit_get_link(struct rtnl_link *link) { - struct sit_info *sit = link->l_info; - - IS_SIT_LINK_ASSERT(link); + IS_SIT_LINK_ASSERT(link, sit); return sit->link; } @@ -466,9 +467,7 @@ uint32_t rtnl_link_sit_get_link(struct rtnl_link *link) */ int rtnl_link_sit_set_local(struct rtnl_link *link, uint32_t addr) { - struct sit_info *sit = link->l_info; - - IS_SIT_LINK_ASSERT(link); + IS_SIT_LINK_ASSERT(link, sit); sit->local = addr; sit->sit_mask |= SIT_ATTR_LOCAL; @@ -484,9 +483,7 @@ int rtnl_link_sit_set_local(struct rtnl_link *link, uint32_t addr) */ uint32_t rtnl_link_sit_get_local(struct rtnl_link *link) { - struct sit_info *sit = link->l_info; - - IS_SIT_LINK_ASSERT(link); + IS_SIT_LINK_ASSERT(link, sit); return sit->local; } @@ -500,9 +497,7 @@ uint32_t rtnl_link_sit_get_local(struct rtnl_link *link) */ int rtnl_link_sit_set_remote(struct rtnl_link *link, uint32_t addr) { - struct sit_info *sit = link->l_info; - - IS_SIT_LINK_ASSERT(link); + IS_SIT_LINK_ASSERT(link, sit); sit->remote = addr; sit->sit_mask |= SIT_ATTR_REMOTE; @@ -518,9 +513,7 @@ int rtnl_link_sit_set_remote(struct rtnl_link *link, uint32_t addr) */ uint32_t rtnl_link_sit_get_remote(struct rtnl_link *link) { - struct sit_info *sit = link->l_info; - - IS_SIT_LINK_ASSERT(link); + IS_SIT_LINK_ASSERT(link, sit); return sit->remote; } @@ -534,9 +527,7 @@ uint32_t rtnl_link_sit_get_remote(struct rtnl_link *link) */ int rtnl_link_sit_set_ttl(struct rtnl_link *link, uint8_t ttl) { - struct sit_info *sit = link->l_info; - - IS_SIT_LINK_ASSERT(link); + IS_SIT_LINK_ASSERT(link, sit); sit->ttl = ttl; sit->sit_mask |= SIT_ATTR_TTL; @@ -552,9 +543,7 @@ int rtnl_link_sit_set_ttl(struct rtnl_link *link, uint8_t ttl) */ uint8_t rtnl_link_sit_get_ttl(struct rtnl_link *link) { - struct sit_info *sit = link->l_info; - - IS_SIT_LINK_ASSERT(link); + IS_SIT_LINK_ASSERT(link, sit); return sit->ttl; } @@ -568,9 +557,7 @@ uint8_t rtnl_link_sit_get_ttl(struct rtnl_link *link) */ int rtnl_link_sit_set_tos(struct rtnl_link *link, uint8_t tos) { - struct sit_info *sit = link->l_info; - - IS_SIT_LINK_ASSERT(link); + IS_SIT_LINK_ASSERT(link, sit); sit->tos = tos; sit->sit_mask |= SIT_ATTR_TOS; @@ -586,9 +573,7 @@ int rtnl_link_sit_set_tos(struct rtnl_link *link, uint8_t tos) */ uint8_t rtnl_link_sit_get_tos(struct rtnl_link *link) { - struct sit_info *sit = link->l_info; - - IS_SIT_LINK_ASSERT(link); + IS_SIT_LINK_ASSERT(link, sit); return sit->tos; } @@ -602,9 +587,7 @@ uint8_t rtnl_link_sit_get_tos(struct rtnl_link *link) */ int rtnl_link_sit_set_pmtudisc(struct rtnl_link *link, uint8_t pmtudisc) { - struct sit_info *sit = link->l_info; - - IS_SIT_LINK_ASSERT(link); + IS_SIT_LINK_ASSERT(link, sit); sit->pmtudisc = pmtudisc; sit->sit_mask |= SIT_ATTR_PMTUDISC; @@ -620,9 +603,7 @@ int rtnl_link_sit_set_pmtudisc(struct rtnl_link *link, uint8_t pmtudisc) */ uint8_t rtnl_link_sit_get_pmtudisc(struct rtnl_link *link) { - struct sit_info *sit = link->l_info; - - IS_SIT_LINK_ASSERT(link); + IS_SIT_LINK_ASSERT(link, sit); return sit->pmtudisc; } @@ -636,9 +617,7 @@ uint8_t rtnl_link_sit_get_pmtudisc(struct rtnl_link *link) */ int rtnl_link_sit_set_flags(struct rtnl_link *link, uint16_t flags) { - struct sit_info *sit = link->l_info; - - IS_SIT_LINK_ASSERT(link); + IS_SIT_LINK_ASSERT(link, sit); sit->flags = flags; sit->sit_mask |= SIT_ATTR_FLAGS; @@ -654,9 +633,7 @@ int rtnl_link_sit_set_flags(struct rtnl_link *link, uint16_t flags) */ uint16_t rtnl_link_sit_get_flags(struct rtnl_link *link) { - struct sit_info *sit = link->l_info; - - IS_SIT_LINK_ASSERT(link); + IS_SIT_LINK_ASSERT(link, sit); return sit->flags; } @@ -670,9 +647,7 @@ uint16_t rtnl_link_sit_get_flags(struct rtnl_link *link) */ int rtnl_link_sit_set_proto(struct rtnl_link *link, uint8_t proto) { - struct sit_info *sit = link->l_info; - - IS_SIT_LINK_ASSERT(link); + IS_SIT_LINK_ASSERT(link, sit); sit->proto = proto; sit->sit_mask |= SIT_ATTR_PROTO; @@ -688,9 +663,7 @@ int rtnl_link_sit_set_proto(struct rtnl_link *link, uint8_t proto) */ uint8_t rtnl_link_sit_get_proto(struct rtnl_link *link) { - struct sit_info *sit = link->l_info; - - IS_SIT_LINK_ASSERT(link); + IS_SIT_LINK_ASSERT(link, sit); return sit->proto; } |