18 #include <netlink-local.h>
19 #include <netlink-tc.h>
20 #include <netlink/netlink.h>
21 #include <netlink/utils.h>
22 #include <netlink/route/tc.h>
23 #include <netlink/route/classifier.h>
24 #include <netlink/route/classifier-modules.h>
25 #include <netlink/route/link.h>
28 #define CLS_ATTR_PRIO (TCA_ATTR_MAX << 1)
29 #define CLS_ATTR_PROTOCOL (TCA_ATTR_MAX << 2)
32 static void cls_free_data(
struct nl_object *obj)
34 struct rtnl_cls *cls = (
struct rtnl_cls *) obj;
37 tca_free_data((
struct rtnl_tca *) cls);
44 static int cls_clone(
struct nl_object *_dst,
struct nl_object *_src)
46 struct rtnl_cls *dst = nl_object_priv(_dst);
47 struct rtnl_cls *src = nl_object_priv(_src);
51 err = tca_clone((
struct rtnl_tca *) dst, (
struct rtnl_tca *) src);
62 static int cls_dump_brief(
struct nl_object *obj,
struct nl_dump_params *p)
65 struct rtnl_cls *cls = (
struct rtnl_cls *) obj;
69 line = tca_dump_brief((
struct rtnl_tca *) cls,
"cls", p, 0);
71 dp_dump(p,
" prio %u protocol %s", cls->c_prio,
72 nl_ether_proto2str(cls->c_protocol, buf,
sizeof(buf)));
82 static int cls_dump_full(
struct nl_object *obj,
struct nl_dump_params *p)
84 struct rtnl_cls *cls = (
struct rtnl_cls *) obj;
88 line = cls_dump_brief(obj, p);
89 line = tca_dump_full((
struct rtnl_tca *) cls, p, line);
95 dp_dump(p,
"no options\n");
100 static int cls_dump_stats(
struct nl_object *obj,
struct nl_dump_params *p)
102 struct rtnl_cls *cls = (
struct rtnl_cls *) obj;
106 line = cls_dump_full(obj, p);
107 line = tca_dump_stats((
struct rtnl_tca *) cls, p, line);
122 struct rtnl_cls *rtnl_cls_alloc(
void)
127 void rtnl_cls_put(
struct rtnl_cls *cls)
140 void rtnl_cls_set_ifindex(
struct rtnl_cls *f,
int ifindex)
142 tca_set_ifindex((
struct rtnl_tca *) f, ifindex);
145 void rtnl_cls_set_handle(
struct rtnl_cls *f, uint32_t handle)
147 tca_set_handle((
struct rtnl_tca *) f, handle);
150 void rtnl_cls_set_parent(
struct rtnl_cls *f, uint32_t parent)
152 tca_set_parent((
struct rtnl_tca *) f, parent);
155 void rtnl_cls_set_kind(
struct rtnl_cls *f,
const char *kind)
157 tca_set_kind((
struct rtnl_tca *) f, kind);
158 f->c_ops = __rtnl_cls_lookup_ops(kind);
161 void rtnl_cls_set_prio(
struct rtnl_cls *cls,
int prio)
164 cls->ce_mask |= CLS_ATTR_PRIO;
167 int rtnl_cls_get_prio(
struct rtnl_cls *cls)
169 if (cls->ce_mask & CLS_ATTR_PRIO)
175 void rtnl_cls_set_protocol(
struct rtnl_cls *cls,
int protocol)
177 cls->c_protocol = protocol;
178 cls->ce_mask |= CLS_ATTR_PROTOCOL;
181 int rtnl_cls_get_protocol(
struct rtnl_cls *cls)
183 if (cls->ce_mask & CLS_ATTR_PROTOCOL)
184 return cls->c_protocol;
193 .oo_size =
sizeof(
struct rtnl_cls),
194 .oo_free_data = cls_free_data,
195 .oo_clone = cls_clone,
199 .oo_compare = tca_compare,
200 .oo_id_attrs = (TCA_ATTR_IFINDEX | TCA_ATTR_HANDLE),
Dump object in a brief one-liner.
int(* co_clone)(struct rtnl_cls *, struct rtnl_cls *)
Called whenever a classifier object needs to be cloned.
struct nl_object * nl_object_alloc(struct nl_object_ops *ops)
Allocate a new object of kind specified by the operations handle.
struct rtnl_cls_ops * rtnl_cls_lookup_ops(struct rtnl_cls *cls)
Lookup classifier operations for a classifier object.
int(* co_dump[NL_DUMP_MAX+1])(struct rtnl_cls *, struct nl_dump_params *, int)
Dump callbacks.
void nl_object_put(struct nl_object *obj)
Release a reference from an object.
void(* co_free_data)(struct rtnl_cls *)
Called before a class object gets destroyed.
char * oo_name
Unique name of object type.
Dump all attributes but no statistics.
Dump all attributes including statistics.