27 #include <netlink-local.h>
28 #include <netlink-tc.h>
29 #include <netlink/netlink.h>
30 #include <netlink/utils.h>
31 #include <netlink/route/tc.h>
32 #include <netlink/route/classifier.h>
33 #include <netlink/route/classifier-modules.h>
34 #include <netlink/route/link.h>
45 cls = rtnl_cls_alloc();
47 err = nl_errno(ENOMEM);
52 err = tca_msg_parser(nlh, (
struct rtnl_tca *) cls);
56 cls->c_prio = TC_H_MAJ(cls->c_info) >> 16;
57 cls->c_protocol = ntohs(TC_H_MIN(cls->c_info));
66 err = pp->pp_cb((
struct nl_object *) cls, pp);
78 static int cls_request_update(
struct nl_cache *cache,
struct nl_handle *handle)
80 struct tcmsg tchdr = {
81 .tcm_family = AF_UNSPEC,
82 .tcm_ifindex = cache->c_iarg1,
83 .tcm_parent = cache->c_iarg2,
91 static struct nl_msg *cls_build(
struct rtnl_cls *cls,
int type,
int flags)
98 msg = tca_build_msg((
struct rtnl_tca *) cls, type, flags);
103 prio = rtnl_cls_get_prio(cls);
104 proto = rtnl_cls_get_protocol(cls);
105 tchdr->tcm_info = TC_H_MAKE(prio << 16, htons(proto)),
147 return cls_build(cls, RTM_NEWTFILTER,
NLM_F_CREATE | flags);
162 int rtnl_cls_add(
struct nl_handle *handle,
struct rtnl_cls *cls,
int flags)
169 return nl_errno(ENOMEM);
193 return cls_build(cls, RTM_NEWTFILTER,
NLM_F_REPLACE | flags);
216 return nl_errno(ENOMEM);
240 return cls_build(cls, RTM_DELTFILTER, flags);
263 return nl_errno(ENOMEM);
296 int ifindex, uint32_t parent)
298 struct nl_cache * cache;
304 cache->c_iarg1 = ifindex;
305 cache->c_iarg2 = parent;
318 .co_name =
"route/cls",
319 .co_hdrsize =
sizeof(
struct tcmsg),
321 { RTM_NEWTFILTER, NL_ACT_NEW,
"new" },
322 { RTM_DELTFILTER, NL_ACT_DEL,
"del" },
323 { RTM_GETTFILTER, NL_ACT_GET,
"get" },
324 END_OF_MSGTYPES_LIST,
326 .co_protocol = NETLINK_ROUTE,
327 .co_request_update = cls_request_update,
328 .co_msg_parser = cls_msg_parser,
329 .co_obj_ops = &cls_obj_ops,
332 static void __init cls_init(
void)
337 static void __exit cls_exit(
void)
#define NLM_F_REPLACE
Replace existing matching config object with this request.
void * nlmsg_data(const struct nlmsghdr *nlh)
head of message payload
uint16_t nlmsg_type
Message type (content type)
struct rtnl_cls_ops * rtnl_cls_lookup_ops(struct rtnl_cls *cls)
Lookup classifier operations for a classifier object.
int nl_cache_mngt_unregister(struct nl_cache_ops *ops)
Unregister a set of cache operations.
struct nl_msg *(* co_get_opts)(struct rtnl_cls *)
Must return the contents supposed to be in TCA_OPTIONS.
int nl_wait_for_ack(struct nl_handle *handle)
Wait for ACK.
void nlmsg_free(struct nl_msg *n)
Free a netlink message.
struct nl_msg * rtnl_cls_build_change_request(struct rtnl_cls *cls, int flags)
Build a netlink message to change classifier attributes.
struct nl_msg * rtnl_cls_build_add_request(struct rtnl_cls *cls, int flags)
Build a netlink message to add a new classifier.
int nl_send_auto_complete(struct nl_handle *handle, struct nl_msg *msg)
Send netlink message and check & extend header values as needed.
void nl_cache_free(struct nl_cache *cache)
Free a cache.
int nl_cache_mngt_register(struct nl_cache_ops *ops)
Register a set of cache operations.
int(* co_msg_parser)(struct rtnl_cls *)
TCA_OPTIONS message parser.
int nl_cache_refill(struct nl_handle *handle, struct nl_cache *cache)
(Re)fill a cache with the contents in the kernel.
int nl_send_simple(struct nl_handle *handle, int type, int flags, void *buf, size_t size)
Send simple netlink message using nl_send_auto_complete()
#define NLM_F_CREATE
Create config object if it doesn't already exist.
#define NLM_F_DUMP
Dump all entries.
struct nlmsghdr * nlmsg_hdr(struct nl_msg *n)
Return actual netlink message.
int nla_put_nested(struct nl_msg *n, int attrtype, struct nl_msg *nested)
Add a nested netlink attribute to a netlink message.
int rtnl_cls_delete(struct nl_handle *handle, struct rtnl_cls *cls, int flags)
Delete a classifier.
struct nl_cache * rtnl_cls_alloc_cache(struct nl_handle *handle, int ifindex, uint32_t parent)
Build a classifier cache including all classifiers attached to the specified class/qdisc on eht speci...
struct nl_msg * rtnl_cls_build_delete_request(struct rtnl_cls *cls, int flags)
Build a netlink request message to delete a classifier.
int rtnl_cls_add(struct nl_handle *handle, struct rtnl_cls *cls, int flags)
Add a new classifier.
struct nl_cache * nl_cache_alloc(struct nl_cache_ops *ops)
Allocate an empty cache.
int rtnl_cls_change(struct nl_handle *handle, struct rtnl_cls *cls, int flags)
Change a classifier.