TC_H_ROOT:
root qdisc (directly attached to the device)TC_H_INGRESS:
ingress qdisc (directly attached to the device)TC_H_UNSPEC:
unspecified qdisc (no reference)// Allocate a new empty qdisc to be filled out struct rtnl_qdisc *qdisc = rtnl_qdisc_alloc(); // ... specify the kind of the Qdisc rtnl_qdisc_set_kind(qdisc, "pfifo"); // Specify the device the qdisc should be attached to rtnl_qdisc_set_ifindex(qdisc, ifindex); // ... specify the parent qdisc rtnl_qdisc_set_parent(qdisc, TC_H_ROOT); // Specifying the handle is not required but makes reidentifying easier // and may help to avoid adding a qdisc twice. rtnl_qdisc_set_handle(qdisc, 0x000A0000); // Now on to specify the qdisc specific options, see the relevant qdisc // modules for documentation, in this example we set the upper limit of // the packet fifo qdisc to 64 rtnl_qdisc_fifo_set_limit(qdisc, 64); rtnl_qdisc_add(handle, qdisc, NLM_R_REPLACE); // Free up the memory rtnl_qdisc_put(qdisc);
// Allocate a new empty qdisc to be filled out with the parameters // specifying the qdisc to be deleted. Alternatively a fully equiped // Qdisc object from a cache can be used. struct rtnl_qdisc *qdisc = rtnl_qdisc_alloc(); // The interface index of the device the qdisc is on and the parent handle // are the least required fields to be filled out. // Note: Specify TC_H_ROOT or TC_H_INGRESS as parent handle to delete the // root respectively root ingress qdisc. rtnl_qdisc_set_ifindex(qdisc, ifindex); rtnl_qdisc_set_parent(qdisc, parent_handle); // If required for identification, the handle can be specified as well. rtnl_qdisc_set_handle(qdisc, qdisc_handle); // Not required but maybe helpful as sanity check, the kind of the qdisc // can be specified to avoid mistakes. rtnl_qdisc_set_kind(qdisc, "pfifo"); // Finally delete the qdisc with rtnl_qdisc_delete(), alternatively // rtnl_qdisc_build_delete_request() can be invoked to generate an // appropritate netlink message to send out. rtnl_qdisc_delete(handle, qdisc); // Free up the memory rtnl_qdisc_put(qdisc);
Modules | |
Queueing Discipline Modules | |
Queueing Discipline Object | |
Data Structures | |
struct | rtnl_qdisc_ops |
Qdisc Operations. More... | |
QDisc Addition | |
nl_msg * | rtnl_qdisc_build_add_request (struct rtnl_qdisc *qdisc, int flags) |
Build a netlink message to add a new qdisc. | |
int | rtnl_qdisc_add (struct nl_handle *handle, struct rtnl_qdisc *qdisc, int flags) |
Add a new qdisc. | |
QDisc Modification | |
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. | |
int | rtnl_qdisc_change (struct nl_handle *handle, struct rtnl_qdisc *qdisc, struct rtnl_qdisc *new) |
Change attributes of a qdisc. | |
QDisc Deletion | |
nl_msg * | rtnl_qdisc_build_delete_request (struct rtnl_qdisc *qdisc) |
Build a netlink request message to delete a qdisc. | |
int | rtnl_qdisc_delete (struct nl_handle *handle, struct rtnl_qdisc *qdisc) |
Delete a qdisc. | |
Qdisc Cache Management | |
nl_cache * | rtnl_qdisc_alloc_cache (struct nl_handle *handle) |
Build a qdisc cache including all qdiscs currently configured in the kernel. | |
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. | |
rtnl_qdisc * | rtnl_qdisc_get (struct nl_cache *cache, int ifindex, uint32_t handle) |
Look up qdisc by its handle in the provided cache. |
struct nl_msg* rtnl_qdisc_build_add_request | ( | struct rtnl_qdisc * | qdisc, | |
int | flags | |||
) |
qdisc | qdisc to add | |
flags | additional netlink message flags |
Common message flags used:
Definition at line 197 of file qdisc.c.
References NLM_F_CREATE.
Referenced by rtnl_qdisc_add().
00199 { 00200 struct nl_msg *msg; 00201 00202 msg = qdisc_build(qdisc, RTM_NEWQDISC, NLM_F_CREATE | flags); 00203 if (!msg) 00204 nl_errno(ENOMEM); 00205 00206 return msg; 00207 }
int rtnl_qdisc_add | ( | struct nl_handle * | handle, | |
struct rtnl_qdisc * | qdisc, | |||
int | flags | |||
) |
handle | netlink handle | |
qdisc | qdisc to delete | |
flags | additional netlink message flags |
Common message flags used:
Definition at line 224 of file qdisc.c.
References nl_send_auto_complete(), nl_wait_for_ack(), nlmsg_free(), and rtnl_qdisc_build_add_request().
00226 { 00227 struct nl_msg *msg; 00228 int err; 00229 00230 msg = rtnl_qdisc_build_add_request(qdisc, flags); 00231 if (!msg) 00232 return nl_errno(ENOMEM); 00233 00234 err = nl_send_auto_complete(handle, msg); 00235 nlmsg_free(msg); 00236 if (err < 0) 00237 return err; 00238 00239 return nl_wait_for_ack(handle); 00240 }
struct nl_msg* rtnl_qdisc_build_change_request | ( | struct rtnl_qdisc * | qdisc, | |
struct rtnl_qdisc * | new | |||
) |
qdisc | qdisc to change | |
new | new qdisc attributes |
Definition at line 261 of file qdisc.c.
References NLM_F_REPLACE.
Referenced by rtnl_qdisc_change().
00263 { 00264 return qdisc_build(qdisc, RTM_NEWQDISC, NLM_F_REPLACE); 00265 }
int rtnl_qdisc_change | ( | struct nl_handle * | handle, | |
struct rtnl_qdisc * | qdisc, | |||
struct rtnl_qdisc * | new | |||
) |
handle | netlink handle | |
qdisc | qdisc to change | |
new | new qdisc attributes |
Definition at line 279 of file qdisc.c.
References nl_send_auto_complete(), nl_wait_for_ack(), nlmsg_free(), and rtnl_qdisc_build_change_request().
00281 { 00282 struct nl_msg *msg; 00283 int err; 00284 00285 msg = rtnl_qdisc_build_change_request(qdisc, new); 00286 if (!msg) 00287 return nl_errno(ENOMEM); 00288 00289 err = nl_send_auto_complete(handle, msg); 00290 nlmsg_free(msg); 00291 if (err < 0) 00292 return err; 00293 00294 return nl_wait_for_ack(handle); 00295 }
struct nl_msg* rtnl_qdisc_build_delete_request | ( | struct rtnl_qdisc * | qdisc | ) |
qdisc | qdisc to delete |
Definition at line 315 of file qdisc.c.
References nlmsg_alloc_simple(), and nlmsg_append().
Referenced by rtnl_qdisc_delete().
00316 { 00317 struct nl_msg *msg; 00318 struct tcmsg tchdr; 00319 int required = TCA_ATTR_IFINDEX | TCA_ATTR_PARENT; 00320 00321 if ((qdisc->ce_mask & required) != required) 00322 BUG(); 00323 00324 msg = nlmsg_alloc_simple(RTM_DELQDISC, 0); 00325 if (!msg) 00326 return NULL; 00327 00328 tchdr.tcm_family = AF_UNSPEC, 00329 tchdr.tcm_handle = qdisc->q_handle, 00330 tchdr.tcm_parent = qdisc->q_parent, 00331 tchdr.tcm_ifindex = qdisc->q_ifindex, 00332 nlmsg_append(msg, &tchdr, sizeof(tchdr), NLMSG_ALIGNTO); 00333 00334 return msg; 00335 }
int rtnl_qdisc_delete | ( | struct nl_handle * | handle, | |
struct rtnl_qdisc * | qdisc | |||
) |
handle | netlink handle | |
qdisc | qdisc to delete |
Definition at line 348 of file qdisc.c.
References nl_send_auto_complete(), nl_wait_for_ack(), nlmsg_free(), and rtnl_qdisc_build_delete_request().
00349 { 00350 struct nl_msg *msg; 00351 int err; 00352 00353 msg = rtnl_qdisc_build_delete_request(qdisc); 00354 if (!msg) 00355 return nl_errno(ENOMEM); 00356 00357 err = nl_send_auto_complete(handle, msg); 00358 nlmsg_free(msg); 00359 if (err < 0) 00360 return err; 00361 00362 return nl_wait_for_ack(handle); 00363 }
struct nl_cache* rtnl_qdisc_alloc_cache | ( | struct nl_handle * | handle | ) |
handle | netlink handle |
Definition at line 384 of file qdisc.c.
References nl_cache_alloc(), nl_cache_free(), and nl_cache_refill().
00385 { 00386 struct nl_cache * cache; 00387 00388 cache = nl_cache_alloc(&rtnl_qdisc_ops); 00389 if (cache == NULL) 00390 return NULL; 00391 00392 if (handle && nl_cache_refill(handle, cache) < 0) { 00393 nl_cache_free(cache); 00394 return NULL; 00395 } 00396 00397 return cache; 00398 }
struct rtnl_qdisc* rtnl_qdisc_get_by_parent | ( | struct nl_cache * | cache, | |
int | ifindex, | |||
uint32_t | parent | |||
) |
cache | qdisc cache | |
ifindex | interface the qdisc is attached to | |
parent | parent handle |
Definition at line 407 of file qdisc.c.
References nl_object_get().
Referenced by rtnl_class_leaf_qdisc().
00409 { 00410 struct rtnl_qdisc *q; 00411 00412 if (cache->c_ops != &rtnl_qdisc_ops) 00413 return NULL; 00414 00415 nl_list_for_each_entry(q, &cache->c_items, ce_list) { 00416 if (q->q_parent == parent && q->q_ifindex == ifindex) { 00417 nl_object_get((struct nl_object *) q); 00418 return q; 00419 } 00420 } 00421 00422 return NULL; 00423 }
struct rtnl_qdisc* rtnl_qdisc_get | ( | struct nl_cache * | cache, | |
int | ifindex, | |||
uint32_t | handle | |||
) |
cache | qdisc cache | |
ifindex | interface the qdisc is attached to | |
handle | qdisc handle |
Definition at line 432 of file qdisc.c.
References nl_object_get().
00434 { 00435 struct rtnl_qdisc *q; 00436 00437 if (cache->c_ops != &rtnl_qdisc_ops) 00438 return NULL; 00439 00440 nl_list_for_each_entry(q, &cache->c_items, ce_list) { 00441 if (q->q_handle == handle && q->q_ifindex == ifindex) { 00442 nl_object_get((struct nl_object *) q); 00443 return q; 00444 } 00445 } 00446 00447 return NULL; 00448 }