Пример #1
0
/**
 * Add qdisc
 * @arg sk		Netlink socket
 * @arg qdisc		Qdisc to add 
 * @arg flags		Additional netlink message flags
 *
 * Builds a \c RTM_NEWQDISC netlink message requesting the addition
 * of a new qdisc and sends the message to the kernel. The configuration
 * of the qdisc is derived from the attributes of the specified qdisc.
 *
 * The following flags may be specified:
 *  - \c NLM_F_CREATE:  Create qdisc if it does not exist, otherwise 
 *                      -NLE_OBJ_NOTFOUND is returned.
 *  - \c NLM_F_REPLACE: If another qdisc is already attached to the
 *                      parent, replace it even if the handles mismatch.
 *  - \c NLM_F_EXCL:    Return -NLE_EXISTS if a qdisc with matching
 *                      handle exists already.
 *
 * Existing qdiscs with matching handles will be updated, unless the
 * flag \c NLM_F_EXCL is specified. If their handles do not match, the
 * error -NLE_EXISTS is returned unless the flag \c NLM_F_REPLACE is
 * specified in which case the existing qdisc is replaced with the new
 * one.  If no matching qdisc exists, it will be created if the flag
 * \c NLM_F_CREATE is set, otherwise the error -NLE_OBJ_NOTFOUND is
 * returned. 
 *
 * After sending, the function will wait for the ACK or an eventual
 * error message to be received and will therefore block until the
 * operation has been completed.
 *
 * @note Disabling auto-ack (nl_socket_disable_auto_ack()) will cause
 *       this function to return immediately after sending. In this case,
 *       it is the responsibility of the caller to handle any error
 *       messages returned.
 *
 * @return 0 on success or a negative error code.
 */
int rtnl_qdisc_add(struct nl_sock *sk, struct rtnl_qdisc *qdisc, int flags)
{
	struct nl_msg *msg;
	int err;

	if ((err = rtnl_qdisc_build_add_request(qdisc, flags, &msg)) < 0)
		return err;

	return nl_send_sync(sk, msg);
}
Пример #2
0
/**
 * Add a new qdisc
 * @arg sk		Netlink socket.
 * @arg qdisc		qdisc to delete
 * @arg flags		additional netlink message flags
 *
 * Builds a netlink message by calling rtnl_qdisc_build_add_request(),
 * sends the request to the kernel and waits for the ACK to be
 * received and thus blocks until the request has been processed.
 *
 * Common message flags used:
 *  - NLM_F_REPLACE - replace a potential existing qdisc
 *
 * @return 0 on success or a negative error code
 */
int rtnl_qdisc_add(struct nl_sock *sk, struct rtnl_qdisc *qdisc,
		   int flags)
{
	struct nl_msg *msg;
	int err;

	if ((err = rtnl_qdisc_build_add_request(qdisc, flags, &msg)) < 0)
		return err;

	err = nl_send_auto_complete(sk, msg);
	nlmsg_free(msg);
	if (err < 0)
		return err;

	return wait_for_ack(sk);
}