[NETLINK]: Limit NLMSG_GOODSIZE to 8K.
authorDavid S. Miller <davem@davemloft.net>
Mon, 26 Mar 2007 03:27:59 +0000 (20:27 -0700)
committerDavid S. Miller <davem@sunset.davemloft.net>
Thu, 26 Apr 2007 05:23:45 +0000 (22:23 -0700)
Signed-off-by: David S. Miller <davem@davemloft.net>
include/linux/netlink.h
include/linux/skbuff.h

index 2a20f48..a9d3ad5 100644 (file)
@@ -171,9 +171,16 @@ int netlink_sendskb(struct sock *sk, struct sk_buff *skb, int protocol);
 
 /*
  *     skb should fit one page. This choice is good for headerless malloc.
+ *     But we should limit to 8K so that userspace does not have to
+ *     use enormous buffer sizes on recvmsg() calls just to avoid
+ *     MSG_TRUNC when PAGE_SIZE is very large.
  */
-#define NLMSG_GOODORDER 0
-#define NLMSG_GOODSIZE (SKB_MAX_ORDER(0, NLMSG_GOODORDER))
+#if PAGE_SIZE < 8192UL
+#define NLMSG_GOODSIZE SKB_WITH_OVERHEAD(PAGE_SIZE)
+#else
+#define NLMSG_GOODSIZE SKB_WITH_OVERHEAD(8192UL)
+#endif
+
 #define NLMSG_DEFAULT_SIZE (NLMSG_GOODSIZE - NLMSG_HDRLEN)
 
 
index f9441b5..30089ad 100644 (file)
 
 #define SKB_DATA_ALIGN(X)      (((X) + (SMP_CACHE_BYTES - 1)) & \
                                 ~(SMP_CACHE_BYTES - 1))
-#define SKB_MAX_ORDER(X, ORDER)        (((PAGE_SIZE << (ORDER)) - (X) - \
-                                 sizeof(struct skb_shared_info)) & \
-                                 ~(SMP_CACHE_BYTES - 1))
+#define SKB_WITH_OVERHEAD(X)   \
+       (((X) - sizeof(struct skb_shared_info)) & \
+        ~(SMP_CACHE_BYTES - 1))
+#define SKB_MAX_ORDER(X, ORDER) \
+       SKB_WITH_OVERHEAD((PAGE_SIZE << (ORDER)) - (X))
 #define SKB_MAX_HEAD(X)                (SKB_MAX_ORDER((X), 0))
 #define SKB_MAX_ALLOC          (SKB_MAX_ORDER(0, 2))