summaryrefslogtreecommitdiffstats
path: root/lib/route/sch/prio.c
diff options
context:
space:
mode:
authorThomas Graf <tgr@lsx.localdomain>2008-05-14 15:49:44 (GMT)
committerThomas Graf <tgr@lsx.localdomain>2008-05-14 15:49:44 (GMT)
commit8a3efffa5b3fde252675239914118664d36a2c24 (patch)
treef8efc71b2bd4736f2a56084efea05d7ee191a422 /lib/route/sch/prio.c
parent85f932552e61c5997c1e83fe386098c94d93c273 (diff)
downloadlibnl-8a3efffa5b3fde252675239914118664d36a2c24.zip
libnl-8a3efffa5b3fde252675239914118664d36a2c24.tar.gz
libnl-8a3efffa5b3fde252675239914118664d36a2c24.tar.bz2
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/sch/prio.c')
-rw-r--r--lib/route/sch/prio.c23
1 files changed, 10 insertions, 13 deletions
diff --git a/lib/route/sch/prio.c b/lib/route/sch/prio.c
index 4e3d624..cd5526c 100644
--- a/lib/route/sch/prio.c
+++ b/lib/route/sch/prio.c
@@ -6,7 +6,7 @@
* License as published by the Free Software Foundation version 2.1
* of the License.
*
- * Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch>
+ * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
*/
/**
@@ -58,11 +58,11 @@ static int prio_msg_parser(struct rtnl_qdisc *qdisc)
struct tc_prio_qopt *opt;
if (qdisc->q_opts->d_size < sizeof(*opt))
- return nl_error(EINVAL, "prio specific option size mismatch");
+ return -NLE_INVAL;
prio = prio_alloc(qdisc);
if (!prio)
- return nl_errno(ENOMEM);
+ return -NLE_NOMEM;
opt = (struct tc_prio_qopt *) qdisc->q_opts->d_data;
prio->qp_bands = opt->bands;
@@ -173,7 +173,7 @@ int rtnl_qdisc_prio_set_bands(struct rtnl_qdisc *qdisc, int bands)
prio = prio_alloc(qdisc);
if (!prio)
- return nl_errno(ENOMEM);
+ return -NLE_NOMEM;
prio->qp_bands = bands;
prio->qp_mask |= SCH_PRIO_ATTR_BANDS;
@@ -194,7 +194,7 @@ int rtnl_qdisc_prio_get_bands(struct rtnl_qdisc *qdisc)
if (prio && prio->qp_mask & SCH_PRIO_ATTR_BANDS)
return prio->qp_bands;
else
- return nl_errno(ENOMEM);
+ return -NLE_NOMEM;
}
/**
@@ -212,18 +212,17 @@ int rtnl_qdisc_prio_set_priomap(struct rtnl_qdisc *qdisc, uint8_t priomap[],
prio = prio_alloc(qdisc);
if (!prio)
- return nl_errno(ENOMEM);
+ return -NLE_NOMEM;
if (!(prio->qp_mask & SCH_PRIO_ATTR_BANDS))
- return nl_error(EINVAL, "Set number of bands first");
+ return -NLE_MISSING_ATTR;
if ((len / sizeof(uint8_t)) > (TC_PRIO_MAX+1))
- return nl_error(ERANGE, "priomap length out of bounds");
+ return -NLE_RANGE;
for (i = 0; i <= TC_PRIO_MAX; i++) {
if (priomap[i] > prio->qp_bands)
- return nl_error(ERANGE, "priomap element %d " \
- "out of bounds, increase bands number");
+ return -NLE_RANGE;
}
memcpy(prio->qp_priomap, priomap, len);
@@ -245,10 +244,8 @@ uint8_t *rtnl_qdisc_prio_get_priomap(struct rtnl_qdisc *qdisc)
prio = prio_qdisc(qdisc);
if (prio && prio->qp_mask & SCH_PRIO_ATTR_PRIOMAP)
return prio->qp_priomap;
- else {
- nl_errno(ENOENT);
+ else
return NULL;
- }
}
/** @} */