diff options
Diffstat (limited to 'lib/route/tc.c')
-rw-r--r-- | lib/route/tc.c | 78 |
1 files changed, 35 insertions, 43 deletions
diff --git a/lib/route/tc.c b/lib/route/tc.c index 1351fa2..97faef4 100644 --- a/lib/route/tc.c +++ b/lib/route/tc.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> */ /** @@ -66,7 +66,7 @@ int tca_msg_parser(struct nlmsghdr *n, struct rtnl_tca *g) return err; if (tb[TCA_KIND] == NULL) - return nl_error(EINVAL, "Missing tca kind TLV"); + return -NLE_MISSING_ATTR; nla_strlcpy(g->tc_kind, tb[TCA_KIND], TCKINDSIZ); @@ -81,9 +81,9 @@ int tca_msg_parser(struct nlmsghdr *n, struct rtnl_tca *g) TCA_ATTR_PARENT | TCA_ATTR_INFO | TCA_ATTR_KIND); if (tb[TCA_OPTIONS]) { - g->tc_opts = nla_get_data(tb[TCA_OPTIONS]); + g->tc_opts = nl_data_alloc_attr(tb[TCA_OPTIONS]); if (!g->tc_opts) - return nl_errno(ENOMEM); + return -NLE_NOMEM; g->ce_mask |= TCA_ATTR_OPTS; } @@ -126,9 +126,9 @@ int tca_msg_parser(struct nlmsghdr *n, struct rtnl_tca *g) g->ce_mask |= TCA_ATTR_STATS; if (tbs[TCA_STATS_APP]) { - g->tc_xstats = nla_get_data(tbs[TCA_STATS_APP]); + g->tc_xstats = nl_data_alloc_attr(tbs[TCA_STATS_APP]); if (g->tc_xstats == NULL) - return -ENOMEM; + return -NLE_NOMEM; } else goto compat_xstats; } else { @@ -149,9 +149,9 @@ int tca_msg_parser(struct nlmsghdr *n, struct rtnl_tca *g) compat_xstats: if (tb[TCA_XSTATS]) { - g->tc_xstats = nla_get_data(tb[TCA_XSTATS]); + g->tc_xstats = nl_data_alloc_attr(tb[TCA_XSTATS]); if (g->tc_xstats == NULL) - return -ENOMEM; + return -NLE_NOMEM; g->ce_mask |= TCA_ATTR_XSTATS; } } @@ -171,58 +171,53 @@ int tca_clone(struct rtnl_tca *dst, struct rtnl_tca *src) if (src->tc_opts) { dst->tc_opts = nl_data_clone(src->tc_opts); if (!dst->tc_opts) - goto errout; + return -NLE_NOMEM; } if (src->tc_xstats) { dst->tc_xstats = nl_data_clone(src->tc_xstats); if (!dst->tc_xstats) - goto errout; + return -NLE_NOMEM; } return 0; -errout: - return nl_get_errno(); } -int tca_dump_brief(struct rtnl_tca *g, const char *type, - struct nl_dump_params *p, int line) +void tca_dump_line(struct rtnl_tca *g, const char *type, + struct nl_dump_params *p) { char handle[32], parent[32]; struct nl_cache *link_cache; link_cache = nl_cache_mngt_require("route/link"); - dp_dump(p, "%s %s ", g->tc_kind, type); + nl_dump_line(p, "%s %s ", g->tc_kind, type); if (link_cache) { char buf[32]; - dp_dump(p, "dev %s ", + nl_dump(p, "dev %s ", rtnl_link_i2name(link_cache, g->tc_ifindex, buf, sizeof(buf))); } else - dp_dump(p, "dev %u ", g->tc_ifindex); + nl_dump(p, "dev %u ", g->tc_ifindex); - dp_dump(p, "handle %s parent %s", + nl_dump(p, "handle %s parent %s", rtnl_tc_handle2str(g->tc_handle, handle, sizeof(handle)), rtnl_tc_handle2str(g->tc_parent, parent, sizeof(parent))); - - return 1; } -int tca_dump_full(struct rtnl_tca *g, struct nl_dump_params *p, int line) +void tca_dump_details(struct rtnl_tca *g, struct nl_dump_params *p) { - dp_dump_line(p, line++, " "); - return line; + nl_dump_line(p, " "); } -int tca_dump_stats(struct rtnl_tca *g, struct nl_dump_params *p, int line) +void tca_dump_stats(struct rtnl_tca *g, struct nl_dump_params *p) { char *unit, fmt[64]; float res; strcpy(fmt, " %7.2f %s %10u %10u %10u %10u %10u\n"); - dp_dump_line(p, line++, + nl_dump_line(p, " Stats: bytes packets drops overlimits" \ " qlen backlog\n"); @@ -230,7 +225,7 @@ int tca_dump_stats(struct rtnl_tca *g, struct nl_dump_params *p, int line) if (*unit == 'B') fmt[11] = '9'; - dp_dump_line(p, line++, fmt, res, unit, + nl_dump_line(p, fmt, res, unit, g->tc_stats[RTNL_TC_PACKETS], g->tc_stats[RTNL_TC_DROPS], g->tc_stats[RTNL_TC_OVERLIMITS], @@ -244,9 +239,7 @@ int tca_dump_stats(struct rtnl_tca *g, struct nl_dump_params *p, int line) if (*unit == 'B') fmt[11] = '9'; - dp_dump_line(p, line++, fmt, res, unit, g->tc_stats[RTNL_TC_RATE_PPS]); - - return line; + nl_dump_line(p, fmt, res, unit, g->tc_stats[RTNL_TC_RATE_PPS]); } int tca_compare(struct nl_object *_a, struct nl_object *_b, @@ -276,10 +269,7 @@ void tca_set_ifindex(struct rtnl_tca *t, int ifindex) int tca_get_ifindex(struct rtnl_tca *t) { - if (t->ce_mask & TCA_ATTR_IFINDEX) - return t->tc_ifindex; - else - return RTNL_LINK_NOT_FOUND; + return t->tc_ifindex; } void tca_set_handle(struct rtnl_tca *t, uint32_t handle) @@ -332,7 +322,8 @@ uint64_t tca_get_stat(struct rtnl_tca *t, int id) return t->tc_stats[id]; } -struct nl_msg *tca_build_msg(struct rtnl_tca *tca, int type, int flags) +int tca_build_msg(struct rtnl_tca *tca, int type, int flags, + struct nl_msg **result) { struct nl_msg *msg; struct tcmsg tchdr = { @@ -344,7 +335,7 @@ struct nl_msg *tca_build_msg(struct rtnl_tca *tca, int type, int flags) msg = nlmsg_alloc_simple(type, flags); if (!msg) - goto nla_put_failure; + return -NLE_NOMEM; if (nlmsg_append(msg, &tchdr, sizeof(tchdr), NLMSG_ALIGNTO) < 0) goto nla_put_failure; @@ -352,11 +343,12 @@ struct nl_msg *tca_build_msg(struct rtnl_tca *tca, int type, int flags) if (tca->ce_mask & TCA_ATTR_KIND) NLA_PUT_STRING(msg, TCA_KIND, tca->tc_kind); - return msg; + *result = msg; + return 0; nla_put_failure: nlmsg_free(msg); - return NULL; + return -NLE_MSGSIZE; } /** @endcond */ @@ -425,7 +417,7 @@ int rtnl_tc_calc_cell_log(int cell_size) if ((1 << i) == cell_size) return i; - return nl_errno(EINVAL); + return -NLE_INVAL; } @@ -546,13 +538,13 @@ int rtnl_tc_str2handle(const char *name, uint32_t *res) /* :YYYY */ h = 0; if (':' != *colon) - return -EINVAL; + return -NLE_INVAL; } if (':' == *colon) { /* check if we would lose bits */ if (TC_H_MAJ(h)) - return -ERANGE; + return -NLE_RANGE; h <<= 16; if ('\0' == colon[1]) { @@ -564,10 +556,10 @@ int rtnl_tc_str2handle(const char *name, uint32_t *res) /* check if we overlap with major part */ if (TC_H_MAJ(l)) - return -ERANGE; + return -NLE_RANGE; if ('\0' != *end) - return -EINVAL; + return -NLE_INVAL; *res = (h | l); } @@ -575,7 +567,7 @@ int rtnl_tc_str2handle(const char *name, uint32_t *res) /* XXXXYYYY */ *res = h; } else - return -EINVAL; + return -NLE_INVAL; return 0; } |