]> git.ipfire.org Git - thirdparty/libnl.git/commitdiff
Add socket flag NL_NO_AUTO_ACK to allow disabling auto ACKS
authorThomas Graf <tgr@plip.localdomain>
Mon, 20 Oct 2008 11:02:38 +0000 (13:02 +0200)
committerThomas Graf <tgr@plip.localdomain>
Mon, 20 Oct 2008 11:02:38 +0000 (13:02 +0200)
include/netlink-types.h
include/netlink/socket.h
lib/nl.c
lib/socket.c

index cddace93385e5d30b62597a7a26a949bd2e6d8f8..263e5d713ca86a77541f81f60f76be9850f3bf1f 100644 (file)
@@ -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
 
index 68477e41f1e7b6fd9f443febfe68ce51aa2ee063..c10bc2a112731d8acaa2edc90a5eaa321fbe428b 100644 (file)
@@ -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 *);
index 80a920aa948e199d21062117bd7f4f2e290d1e31..b230a4d0556c16e14a25a4094bd1adb2a5b7ab3b 100644 (file)
--- a/lib/nl.c
+++ b/lib/nl.c
  * // 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);
index 3b0d9dc1eb13918003ff0ee2216e5dd0b9b5552f..1a11971c921cfbf45b99166d529c5fef043efbd7 100644 (file)
@@ -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;
+}
+
 /** @} */
 
 /**