diff options
author | Thomas Graf <tgraf@suug.ch> | 2011-03-21 14:51:52 (GMT) |
---|---|---|
committer | Thomas Graf <tgraf@suug.ch> | 2011-03-21 14:51:52 (GMT) |
commit | 8eb5b5532eae985a5f0911dccf2db8cb4e0a5de4 (patch) | |
tree | 0fec48d114edbb535bd234f2684acccf81447d13 /lib/route/cls/fw.c | |
parent | 5dc897d5de9f54078221b241e0122713207f5e0c (diff) | |
download | libnl-8eb5b5532eae985a5f0911dccf2db8cb4e0a5de4.zip libnl-8eb5b5532eae985a5f0911dccf2db8cb4e0a5de4.tar.gz libnl-8eb5b5532eae985a5f0911dccf2db8cb4e0a5de4.tar.bz2 |
Unified TC API
Finally got rid of all the qdisc/class/cls code duplication in
the tc module API. The API takes care of allocation/freeing the
tc object specific data.
I hope I got it right this time.
Diffstat (limited to 'lib/route/cls/fw.c')
-rw-r--r-- | lib/route/cls/fw.c | 78 |
1 files changed, 44 insertions, 34 deletions
diff --git a/lib/route/cls/fw.c b/lib/route/cls/fw.c index b8055fe..11c9c67 100644 --- a/lib/route/cls/fw.c +++ b/lib/route/cls/fw.c @@ -6,14 +6,14 @@ * License as published by the Free Software Foundation version 2.1 * of the License. * - * Copyright (c) 2003-2009 Thomas Graf <tgraf@suug.ch> + * Copyright (c) 2003-2011 Thomas Graf <tgraf@suug.ch> * Copyright (c) 2006 Petr Gotthard <petr.gotthard@siemens.com> * Copyright (c) 2006 Siemens AG Oesterreich */ /** - * @ingroup cls_api - * @defgroup fw Firewall Classifier + * @ingroup cls + * @defgroup cls_fw Firewall Classifier * * @{ */ @@ -21,8 +21,8 @@ #include <netlink-local.h> #include <netlink-tc.h> #include <netlink/netlink.h> +#include <netlink/route/tc-api.h> #include <netlink/route/classifier.h> -#include <netlink/route/classifier-modules.h> #include <netlink/route/cls/fw.h> /** @cond SKIP */ @@ -38,13 +38,13 @@ static struct nla_policy fw_policy[TCA_FW_MAX+1] = { .maxlen = IFNAMSIZ }, }; -static int fw_msg_parser(struct rtnl_cls *cls) +static int fw_msg_parser(struct rtnl_tc *tc, void *data) { - struct rtnl_fw *f = rtnl_cls_data(cls); struct nlattr *tb[TCA_FW_MAX + 1]; + struct rtnl_fw *f = data; int err; - err = tca_parse(tb, TCA_FW_MAX, (struct rtnl_tc *) cls, fw_policy); + err = tca_parse(tb, TCA_FW_MAX, tc, fw_policy); if (err < 0) return err; @@ -75,18 +75,17 @@ static int fw_msg_parser(struct rtnl_cls *cls) return 0; } -static void fw_free_data(struct rtnl_cls *cls) +static void fw_free_data(struct rtnl_tc *tc, void *data) { - struct rtnl_fw *f = rtnl_cls_data(cls); + struct rtnl_fw *f = data; nl_data_free(f->cf_act); nl_data_free(f->cf_police); } -static int fw_clone(struct rtnl_cls *_dst, struct rtnl_cls *_src) +static int fw_clone(void *_dst, void *_src) { - struct rtnl_fw *dst = rtnl_cls_data(_dst); - struct rtnl_fw *src = rtnl_cls_data(_src); + struct rtnl_fw *dst = _dst, *src = _src; if (src->cf_act && !(dst->cf_act = nl_data_clone(src->cf_act))) return -NLE_NOMEM; @@ -97,28 +96,35 @@ static int fw_clone(struct rtnl_cls *_dst, struct rtnl_cls *_src) return 0; } -static void fw_dump_line(struct rtnl_cls *cls, struct nl_dump_params *p) +static void fw_dump_line(struct rtnl_tc *tc, void *data, + struct nl_dump_params *p) { - struct rtnl_fw *f = rtnl_cls_data(cls); - char buf[32]; + struct rtnl_fw *f = data; + + if (f && f->cf_mask & FW_ATTR_CLASSID) { + char buf[32]; - if (f->cf_mask & FW_ATTR_CLASSID) nl_dump(p, " target %s", rtnl_tc_handle2str(f->cf_classid, buf, sizeof(buf))); + } } -static void fw_dump_details(struct rtnl_cls *cls, struct nl_dump_params *p) +static void fw_dump_details(struct rtnl_tc *tc, void *data, + struct nl_dump_params *p) { - struct rtnl_fw *f = rtnl_cls_data(cls); + struct rtnl_fw *f = data; - if (f->cf_mask & FW_ATTR_INDEV) + if (f && f->cf_mask & FW_ATTR_INDEV) nl_dump(p, "indev %s ", f->cf_indev); } -static int fw_get_opts(struct rtnl_cls *cls, struct nl_msg *msg) +static int fw_msg_fill(struct rtnl_tc *tc, void *data, struct nl_msg *msg) { - struct rtnl_fw *f = rtnl_cls_data(cls); - + struct rtnl_fw *f = data; + + if (!f) + return 0; + if (f->cf_mask & FW_ATTR_CLASSID) NLA_PUT_U32(msg, TCA_FW_CLASSID, f->cf_classid); @@ -134,7 +140,7 @@ static int fw_get_opts(struct rtnl_cls *cls, struct nl_msg *msg) return 0; nla_put_failure: - return -NLE_NOMEM; + return -NLE_MSGSIZE; } /** @@ -144,7 +150,10 @@ nla_put_failure: int rtnl_fw_set_classid(struct rtnl_cls *cls, uint32_t classid) { - struct rtnl_fw *f = rtnl_cls_data(cls); + struct rtnl_fw *f; + + if (!(f = rtnl_tc_data(TC_CAST(cls)))) + return -NLE_NOMEM; f->cf_classid = classid; f->cf_mask |= FW_ATTR_CLASSID; @@ -154,14 +163,15 @@ int rtnl_fw_set_classid(struct rtnl_cls *cls, uint32_t classid) /** @} */ -static struct rtnl_cls_ops fw_ops = { - .co_kind = "fw", - .co_size = sizeof(struct rtnl_fw), - .co_msg_parser = fw_msg_parser, - .co_free_data = fw_free_data, - .co_clone = fw_clone, - .co_get_opts = fw_get_opts, - .co_dump = { +static struct rtnl_tc_ops fw_ops = { + .to_kind = "fw", + .to_type = RTNL_TC_TYPE_CLS, + .to_size = sizeof(struct rtnl_fw), + .to_msg_parser = fw_msg_parser, + .to_msg_fill = fw_msg_fill, + .to_free_data = fw_free_data, + .to_clone = fw_clone, + .to_dump = { [NL_DUMP_LINE] = fw_dump_line, [NL_DUMP_DETAILS] = fw_dump_details, }, @@ -169,12 +179,12 @@ static struct rtnl_cls_ops fw_ops = { static void __init fw_init(void) { - rtnl_cls_register(&fw_ops); + rtnl_tc_register(&fw_ops); } static void __exit fw_exit(void) { - rtnl_cls_unregister(&fw_ops); + rtnl_tc_unregister(&fw_ops); } /** @} */ |