diff --git a/include/netlink-types.h b/include/netlink-types.h index cddace9..263e5d7 100644 --- a/include/netlink-types.h +++ b/include/netlink-types.h @@ -22,6 +22,7 @@ #define NL_SOCK_PASSCRED (1<<1) #define NL_OWN_PORT (1<<2) #define NL_MSG_PEEK (1<<3) +#define NL_NO_AUTO_ACK (1<<4) #define NL_MSG_CRED_PRESENT 1 diff --git a/include/netlink/socket.h b/include/netlink/socket.h index 68477e4..c10bc2a 100644 --- a/include/netlink/socket.h +++ b/include/netlink/socket.h @@ -56,6 +56,8 @@ extern int nl_socket_recv_pktinfo(struct nl_sock *, int); extern void nl_disable_sequence_check(struct nl_sock *); extern unsigned int nl_socket_use_seq(struct nl_sock *); +extern void nl_socket_disable_auto_ack(struct nl_sock *); +extern void nl_socket_enable_auto_ack(struct nl_sock *); extern int nl_socket_get_fd(struct nl_sock *); extern int nl_socket_set_nonblocking(struct nl_sock *); diff --git a/lib/nl.c b/lib/nl.c index 80a920a..b230a4d 100644 --- a/lib/nl.c +++ b/lib/nl.c @@ -126,7 +126,7 @@ * // and message flags all the time. nl_send_auto_complete() automatically * // extends your message header as needed with an appropriate sequence * // number, the netlink pid stored in the netlink socket and the message - * // flags NLM_F_REQUEST and NLM_F_ACK + * // flags NLM_F_REQUEST and NLM_F_ACK (if not disabled in the socket) * nl_send_auto_complete(sk, nlmsg_hdr(msg)); * * // Simple protocols don't require the complex message construction interface @@ -385,7 +385,10 @@ int nl_send_auto_complete(struct nl_sock *sk, struct nl_msg *msg) if (msg->nm_protocol == -1) msg->nm_protocol = sk->s_proto; - nlh->nlmsg_flags |= (NLM_F_REQUEST | NLM_F_ACK); + nlh->nlmsg_flags |= NLM_F_REQUEST; + + if (!(sk->s_flags & NL_NO_AUTO_ACK)) + nlh->nlmsg_flags |= NLM_F_ACK; if (cb->cb_send_ow) return cb->cb_send_ow(sk, msg); diff --git a/lib/socket.c b/lib/socket.c index 3b0d9dc..1a11971 100644 --- a/lib/socket.c +++ b/lib/socket.c @@ -276,6 +276,33 @@ unsigned int nl_socket_use_seq(struct nl_sock *sk) return sk->s_seq_next++; } +/** + * Disable automatic request for ACK + * @arg sk Netlink socket. + * + * The default behaviour of a socket is to request an ACK for + * each message sent to allow for the caller to synchronize to + * the completion of the netlink operation. This function + * disables this behaviour and will result in requests being + * sent which will not have the NLM_F_ACK flag set automatically. + * However, it is still possible for the caller to set the + * NLM_F_ACK flag explicitely. + */ +void nl_socket_disable_auto_ack(struct nl_sock *sk) +{ + sk->s_flags |= NL_NO_AUTO_ACK; +} + +/** + * Enable automatic request for ACK (default) + * @arg sk Netlink socket. + * @see nl_socket_disable_auto_ack + */ +void nl_socket_enable_auto_ack(struct nl_sock *sk) +{ + sk->s_flags &= ~NL_NO_AUTO_ACK; +} + /** @} */ /**