85 #include <netlink-local.h> 86 #include <netlink-tc.h> 87 #include <netlink/netlink.h> 88 #include <netlink/utils.h> 89 #include <netlink/route/link.h> 90 #include <netlink/route/tc.h> 91 #include <netlink/route/qdisc.h> 92 #include <netlink/route/class.h> 93 #include <netlink/route/classifier.h> 94 #include <netlink/route/qdisc-modules.h> 102 struct rtnl_qdisc *qdisc;
105 qdisc = rtnl_qdisc_alloc();
107 err = nl_errno(ENOMEM);
113 err = tca_msg_parser(n, (
struct rtnl_tca *) qdisc);
117 qops = rtnl_qdisc_lookup_ops(qdisc);
124 err = pp->pp_cb((
struct nl_object *) qdisc, pp);
131 rtnl_qdisc_put(qdisc);
136 static int qdisc_request_update(
struct nl_cache *c,
struct nl_handle *h)
138 struct tcmsg tchdr = {
139 .tcm_family = AF_UNSPEC,
140 .tcm_ifindex = c->c_iarg1,
152 static struct nl_msg *qdisc_build(
struct rtnl_qdisc *qdisc,
int type,
int flags)
158 msg = tca_build_msg((
struct rtnl_tca *) qdisc, type, flags);
162 qops = rtnl_qdisc_lookup_ops(qdisc);
202 msg = qdisc_build(qdisc, RTM_NEWQDISC,
NLM_F_CREATE | flags);
232 return nl_errno(ENOMEM);
262 struct rtnl_qdisc *
new)
280 struct rtnl_qdisc *
new)
287 return nl_errno(ENOMEM);
319 int required = TCA_ATTR_IFINDEX | TCA_ATTR_PARENT;
321 if ((qdisc->ce_mask & required) != required)
328 tchdr.tcm_family = AF_UNSPEC,
329 tchdr.tcm_handle = qdisc->q_handle,
330 tchdr.tcm_parent = qdisc->q_parent,
331 tchdr.tcm_ifindex = qdisc->q_ifindex,
332 nlmsg_append(msg, &tchdr,
sizeof(tchdr), NLMSG_ALIGNTO);
355 return nl_errno(ENOMEM);
386 struct nl_cache * cache;
408 int ifindex, uint32_t parent)
410 struct rtnl_qdisc *q;
415 nl_list_for_each_entry(q, &cache->c_items, ce_list) {
416 if (q->q_parent == parent && q->q_ifindex == ifindex) {
433 int ifindex, uint32_t handle)
435 struct rtnl_qdisc *q;
440 nl_list_for_each_entry(q, &cache->c_items, ce_list) {
441 if (q->q_handle == handle && q->q_ifindex == ifindex) {
453 .co_name =
"route/qdisc",
454 .co_hdrsize =
sizeof(
struct tcmsg),
456 { RTM_NEWQDISC, NL_ACT_NEW,
"new" },
457 { RTM_DELQDISC, NL_ACT_DEL,
"del" },
458 { RTM_GETQDISC, NL_ACT_GET,
"get" },
459 END_OF_MSGTYPES_LIST,
461 .co_protocol = NETLINK_ROUTE,
462 .co_request_update = qdisc_request_update,
463 .co_msg_parser = qdisc_msg_parser,
464 .co_obj_ops = &qdisc_obj_ops,
467 static void __init qdisc_init(
void)
472 static void __exit qdisc_exit(
void)
#define NLM_F_REPLACE
Replace existing matching config object with this request.
struct rtnl_qdisc * rtnl_qdisc_get_by_parent(struct nl_cache *cache, int ifindex, uint32_t parent)
Look up qdisc by its parent in the provided cache.
uint16_t nlmsg_type
Message type (content type)
int nl_cache_mngt_unregister(struct nl_cache_ops *ops)
Unregister a set of cache operations.
int nl_wait_for_ack(struct nl_handle *handle)
Wait for ACK.
void nl_object_get(struct nl_object *obj)
Acquire a reference on a object.
void nlmsg_free(struct nl_msg *n)
Free a netlink message.
struct nl_cache * rtnl_qdisc_alloc_cache(struct nl_handle *handle)
Build a qdisc cache including all qdiscs currently configured in the kernel.
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.
struct nl_msg * rtnl_qdisc_build_add_request(struct rtnl_qdisc *qdisc, int flags)
Build a netlink message to add a new qdisc.
int nl_cache_mngt_register(struct nl_cache_ops *ops)
Register a set of cache operations.
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.
int rtnl_qdisc_change(struct nl_handle *handle, struct rtnl_qdisc *qdisc, struct rtnl_qdisc *new)
Change attributes of a qdisc.
struct rtnl_qdisc * rtnl_qdisc_get(struct nl_cache *cache, int ifindex, uint32_t handle)
Look up qdisc by its handle in the provided cache.
int(* qo_msg_parser)(struct rtnl_qdisc *)
TCA_OPTIONS message parser.
int nlmsg_append(struct nl_msg *n, void *data, size_t len, int pad)
Append data to tail of a netlink message.
int rtnl_qdisc_delete(struct nl_handle *handle, struct rtnl_qdisc *qdisc)
Delete a qdisc.
struct nl_msg * nlmsg_alloc_simple(int nlmsgtype, int flags)
Allocate a new 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.
struct nl_msg * rtnl_qdisc_build_change_request(struct rtnl_qdisc *qdisc, struct rtnl_qdisc *new)
Build a netlink message to change attributes of a existing qdisc.
struct nl_msg *(* qo_get_opts)(struct rtnl_qdisc *)
Must return the contents supposed to be in TCA_OPTIONS.
struct nl_msg * rtnl_qdisc_build_delete_request(struct rtnl_qdisc *qdisc)
Build a netlink request message to delete a qdisc.
int rtnl_qdisc_add(struct nl_handle *handle, struct rtnl_qdisc *qdisc, int flags)
Add a new qdisc.
struct nl_cache * nl_cache_alloc(struct nl_cache_ops *ops)
Allocate an empty cache.