diff options
author | Thomas Graf <tgr@lsx.localdomain> | 2008-05-14 17:49:44 +0200 |
---|---|---|
committer | Thomas Graf <tgr@lsx.localdomain> | 2008-05-14 17:49:44 +0200 |
commit | 8a3efffa5b3fde252675239914118664d36a2c24 (patch) | |
tree | f8efc71b2bd4736f2a56084efea05d7ee191a422 /lib/route/link | |
parent | 85f932552e61c5997c1e83fe386098c94d93c273 (diff) | |
download | libnl-8a3efffa5b3fde252675239914118664d36a2c24.tar.gz |
Thread-safe error handling
In order for the interface to become more thread safe, the error
handling was revised to no longer depend on a static errno and
error string buffer.
This patch converts all error paths to return a libnl specific
error code which can be translated to a error message using
nl_geterror(int error). The functions nl_error() and
nl_get_errno() are therefore obsolete.
This change required various sets of function prototypes to be
changed in order to return an error code, the most prominent
are:
struct nl_cache *foo_alloc_cache(...);
changed to:
int foo_alloc_cache(..., struct nl_cache **);
struct nl_msg *foo_build_request(...);
changed to:
int foo_build_request(..., struct nl_msg **);
struct foo *foo_parse(...);
changed to:
int foo_parse(..., struct foo **);
This pretty much only leaves trivial allocation functions to
still return a pointer object which can still return NULL to
signal out of memory.
This change is a serious API and ABI breaker, sorry!
Diffstat (limited to 'lib/route/link')
-rw-r--r-- | lib/route/link/api.c | 8 | ||||
-rw-r--r-- | lib/route/link/vlan.c | 51 |
2 files changed, 25 insertions, 34 deletions
diff --git a/lib/route/link/api.c b/lib/route/link/api.c index afe00b1..a0e7679 100644 --- a/lib/route/link/api.c +++ b/lib/route/link/api.c @@ -61,10 +61,10 @@ struct rtnl_link_info_ops *rtnl_link_info_ops_lookup(const char *name) int rtnl_link_register_info(struct rtnl_link_info_ops *ops) { if (ops->io_name == NULL) - return nl_error(EINVAL, "No name specified"); + return -NLE_INVAL; if (rtnl_link_info_ops_lookup(ops->io_name)) - return nl_error(EEXIST, "Link info operations already exist"); + return -NLE_EXIST; NL_DBG(1, "Registered link info operations %s\n", ops->io_name); @@ -83,10 +83,10 @@ int rtnl_link_unregister_info(struct rtnl_link_info_ops *ops) break; if (!t) - return nl_error(ENOENT, "No such link info operations"); + return -NLE_OPNOTSUPP; if (t->io_refcnt > 0) - return nl_error(EBUSY, "Info operations in use"); + return -NLE_BUSY; NL_DBG(1, "Unregistered link info perations %s\n", ops->io_name); diff --git a/lib/route/link/vlan.c b/lib/route/link/vlan.c index c148dca..ea5699f 100644 --- a/lib/route/link/vlan.c +++ b/lib/route/link/vlan.c @@ -6,7 +6,7 @@ * License as published by the Free Software Foundation version 2.1 * of the License. * - * Copyright (c) 2003-2007 Thomas Graf <tgraf@suug.ch> + * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch> */ /** @@ -73,7 +73,7 @@ static int vlan_alloc(struct rtnl_link *link) struct vlan_info *vi; if ((vi = calloc(1, sizeof(*vi))) == NULL) - return nl_errno(ENOMEM); + return -NLE_NOMEM; link->l_info = vi; @@ -119,12 +119,11 @@ static int vlan_parse(struct rtnl_link *link, struct nlattr *data, nla_for_each_nested(nla, tb[IFLA_VLAN_INGRESS_QOS], remaining) { if (nla_len(nla) < sizeof(*map)) - return nl_error(EINVAL, "Malformed mapping"); + return -NLE_INVAL; map = nla_data(nla); if (map->from < 0 || map->from > VLAN_PRIO_MAX) { - return nl_error(EINVAL, "VLAN prio %d out of " - "range", map->from); + return -NLE_INVAL; } vi->vi_ingress_qos[map->from] = map->to; @@ -140,7 +139,7 @@ static int vlan_parse(struct rtnl_link *link, struct nlattr *data, nla_for_each_nested(nla, tb[IFLA_VLAN_EGRESS_QOS], remaining) { if (nla_len(nla) < sizeof(*map)) - return nl_error(EINVAL, "Malformed mapping"); + return -NLE_INVAL; i++; } @@ -148,7 +147,7 @@ static int vlan_parse(struct rtnl_link *link, struct nlattr *data, vi->vi_egress_size = (i + 32) & ~31; vi->vi_egress_qos = calloc(vi->vi_egress_size, sizeof(*map)); if (vi->vi_egress_qos == NULL) - return nl_errno(ENOMEM); + return -NLE_NOMEM; i = 0; nla_for_each_nested(nla, tb[IFLA_VLAN_EGRESS_QOS], remaining) { @@ -260,7 +259,7 @@ static int vlan_clone(struct rtnl_link *dst, struct rtnl_link *src) vdst->vi_egress_qos = calloc(vsrc->vi_egress_size, sizeof(struct vlan_map)); if (!vdst->vi_egress_qos) - return nl_errno(ENOMEM); + return -NLE_NOMEM; memcpy(vdst->vi_egress_qos, vsrc->vi_egress_qos, vsrc->vi_egress_size * sizeof(struct vlan_map)); @@ -274,7 +273,7 @@ static int vlan_put_attrs(struct nl_msg *msg, struct rtnl_link *link) struct nlattr *data; if (!(data = nla_nest_start(msg, IFLA_INFO_DATA))) - return nl_errno(ENOBUFS); + return -NLE_MSGSIZE; if (vi->vi_mask & VLAN_HAS_ID) NLA_PUT_U16(msg, IFLA_VLAN_ID, vi->vi_vlan_id); @@ -349,7 +348,7 @@ int rtnl_link_vlan_set_id(struct rtnl_link *link, int id) struct vlan_info *vi = link->l_info; if (link->l_info_ops != &vlan_info_ops || !link->l_info_ops) - return nl_error(EOPNOTSUPP, "Not a VLAN link"); + return -NLE_OPNOTSUPP; vi->vi_vlan_id = id; vi->vi_mask |= VLAN_HAS_ID; @@ -362,7 +361,7 @@ int rtnl_link_vlan_get_id(struct rtnl_link *link) struct vlan_info *vi = link->l_info; if (link->l_info_ops != &vlan_info_ops || !link->l_info_ops) - return nl_error(EOPNOTSUPP, "Not a VLAN link"); + return -NLE_OPNOTSUPP; if (vi->vi_mask & VLAN_HAS_ID) return vi->vi_vlan_id; @@ -375,7 +374,7 @@ int rtnl_link_vlan_set_flags(struct rtnl_link *link, unsigned int flags) struct vlan_info *vi = link->l_info; if (link->l_info_ops != &vlan_info_ops || !link->l_info_ops) - return nl_error(EOPNOTSUPP, "Not a VLAN link"); + return -NLE_OPNOTSUPP; vi->vi_flags_mask |= flags; vi->vi_flags |= flags; @@ -389,7 +388,7 @@ int rtnl_link_vlan_unset_flags(struct rtnl_link *link, unsigned int flags) struct vlan_info *vi = link->l_info; if (link->l_info_ops != &vlan_info_ops || !link->l_info_ops) - return nl_error(EOPNOTSUPP, "Not a VLAN link"); + return -NLE_OPNOTSUPP; vi->vi_flags_mask |= flags; vi->vi_flags &= ~flags; @@ -403,7 +402,7 @@ unsigned int rtnl_link_vlan_get_flags(struct rtnl_link *link) struct vlan_info *vi = link->l_info; if (link->l_info_ops != &vlan_info_ops || !link->l_info_ops) - return nl_error(EOPNOTSUPP, "Not a VLAN link"); + return -NLE_OPNOTSUPP; return vi->vi_flags; } @@ -414,11 +413,10 @@ int rtnl_link_vlan_set_ingress_map(struct rtnl_link *link, int from, struct vlan_info *vi = link->l_info; if (link->l_info_ops != &vlan_info_ops || !link->l_info_ops) - return nl_error(EOPNOTSUPP, "Not a VLAN link"); + return -NLE_OPNOTSUPP; if (from < 0 || from > VLAN_PRIO_MAX) - return nl_error(EINVAL, "Invalid vlan prio 0..%d", - VLAN_PRIO_MAX); + return -NLE_INVAL; vi->vi_ingress_qos[from] = to; vi->vi_mask |= VLAN_HAS_INGRESS_QOS; @@ -430,10 +428,8 @@ uint32_t *rtnl_link_vlan_get_ingress_map(struct rtnl_link *link) { struct vlan_info *vi = link->l_info; - if (link->l_info_ops != &vlan_info_ops || !link->l_info_ops) { - nl_error(EOPNOTSUPP, "Not a VLAN link"); + if (link->l_info_ops != &vlan_info_ops || !link->l_info_ops) return NULL; - } if (vi->vi_mask & VLAN_HAS_INGRESS_QOS) return vi->vi_ingress_qos; @@ -446,11 +442,10 @@ int rtnl_link_vlan_set_egress_map(struct rtnl_link *link, uint32_t from, int to) struct vlan_info *vi = link->l_info; if (link->l_info_ops != &vlan_info_ops || !link->l_info_ops) - return nl_error(EOPNOTSUPP, "Not a VLAN link"); + return -NLE_OPNOTSUPP; if (to < 0 || to > VLAN_PRIO_MAX) - return nl_error(EINVAL, "Invalid vlan prio 0..%d", - VLAN_PRIO_MAX); + return -NLE_INVAL; if (vi->vi_negress >= vi->vi_egress_size) { int new_size = vi->vi_egress_size + 32; @@ -458,7 +453,7 @@ int rtnl_link_vlan_set_egress_map(struct rtnl_link *link, uint32_t from, int to) ptr = realloc(vi->vi_egress_qos, new_size); if (!ptr) - return nl_errno(ENOMEM); + return -NLE_NOMEM; vi->vi_egress_qos = ptr; vi->vi_egress_size = new_size; @@ -477,15 +472,11 @@ struct vlan_map *rtnl_link_vlan_get_egress_map(struct rtnl_link *link, { struct vlan_info *vi = link->l_info; - if (link->l_info_ops != &vlan_info_ops || !link->l_info_ops) { - nl_error(EOPNOTSUPP, "Not a VLAN link"); + if (link->l_info_ops != &vlan_info_ops || !link->l_info_ops) return NULL; - } - if (negress == NULL) { - nl_error(EINVAL, "Require pointer to store negress"); + if (negress == NULL) return NULL; - } if (vi->vi_mask & VLAN_HAS_EGRESS_QOS) { *negress = vi->vi_negress; |