]> granicus.if.org Git - libnl/commitdiff
idiag: workaround and add comment about idiagnl_send_simple() only handling 8 bit...
authorThomas Haller <thaller@redhat.com>
Mon, 26 Aug 2019 13:49:17 +0000 (15:49 +0200)
committerThomas Haller <thaller@redhat.com>
Mon, 26 Aug 2019 13:52:26 +0000 (15:52 +0200)
Related: https://github.com/thom311/libnl/pull/222#issuecomment-521956236

lib/idiag/idiag.c
lib/idiag/idiag_msg_obj.c

index cae8c1f680ab5e6ceae256993af2c7e0a09f0365..23a8413a6f6a0bad5128324d9745337a2e584c9b 100644 (file)
@@ -56,7 +56,8 @@ int idiagnl_connect(struct nl_sock *sk)
  * @arg flags  Message flags
  * @arg family Address family
  * @arg states Socket states to query
- * @arg ext    Inet Diag attribute extensions to query
+ * @arg ext    Inet Diag attribute extensions to query. Note that this only supports
+ *   8 bit arguments. Flags outside uint8_t range are silently ignored.
  *
  * @return 0 on success or a negative error code. Due to a bug, this function
  * returns the number of bytes sent. Treat any non-negative number as success.
index 9a154938253343fe601510b1be1706a889fd23fb..a1beb2c7ad98a9cc90ef03c7da9e11b3b0f1d984 100644 (file)
@@ -90,7 +90,17 @@ static int idiagnl_request_update(struct nl_cache *cache, struct nl_sock *sk)
        int family = cache->c_iarg1;
        int states = cache->c_iarg2;
 
-       return idiagnl_send_simple(sk, 0, family, states, _INET_DIAG_ALL);
+       /* idiagnl_send_simple()'s "ext" argument is u16, which is too small for _INET_DIAG_ALL,
+        * which is more than 16 bits on recent kernels.
+        *
+        * Actually, internally idiagnl_send_simple() sets "struct inet_diag_req"'s "idiag_ext"
+        * field, which is only 8 bits. So, it's even worse.
+        *
+        * FIXME: this probably should be fixed (by adding idiagnl_send_simple2() function), but for
+        *    the moment it means we cannot request more than 0xFF.
+        */
+
+       return idiagnl_send_simple(sk, 0, family, states, (uint16_t) _INET_DIAG_ALL);
 }
 
 static struct nl_cache_ops idiagnl_msg_ops = {