OSDN Git Service

New getsockopt option to get socket cookie
authorChenbo Feng <fengc@google.com>
Thu, 6 Apr 2017 02:00:55 +0000 (19:00 -0700)
committerDavid S. Miller <davem@davemloft.net>
Sat, 8 Apr 2017 15:07:01 +0000 (08:07 -0700)
Introduce a new getsockopt operation to retrieve the socket cookie
for a specific socket based on the socket fd.  It returns a unique
non-decreasing cookie for each socket.
Tested: https://android-review.googlesource.com/#/c/358163/

Acked-by: Willem de Bruijn <willemb@google.com>
Signed-off-by: Chenbo Feng <fengc@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
14 files changed:
arch/alpha/include/uapi/asm/socket.h
arch/avr32/include/uapi/asm/socket.h
arch/frv/include/uapi/asm/socket.h
arch/ia64/include/uapi/asm/socket.h
arch/m32r/include/uapi/asm/socket.h
arch/mips/include/uapi/asm/socket.h
arch/mn10300/include/uapi/asm/socket.h
arch/parisc/include/uapi/asm/socket.h
arch/powerpc/include/uapi/asm/socket.h
arch/s390/include/uapi/asm/socket.h
arch/sparc/include/uapi/asm/socket.h
arch/xtensa/include/uapi/asm/socket.h
include/uapi/asm-generic/socket.h
net/core/sock.c

index 1bb8cac..148d7a3 100644 (file)
 
 #define SO_INCOMING_NAPI_ID    56
 
+#define SO_COOKIE              57
+
 #endif /* _UAPI_ASM_SOCKET_H */
index f824eeb..2434d08 100644 (file)
@@ -96,4 +96,6 @@
 
 #define SO_INCOMING_NAPI_ID    56
 
+#define SO_COOKIE              57
+
 #endif /* _UAPI__ASM_AVR32_SOCKET_H */
index a8ad9be..1ccf456 100644 (file)
@@ -96,5 +96,7 @@
 
 #define SO_INCOMING_NAPI_ID    56
 
+#define SO_COOKIE              57
+
 #endif /* _ASM_SOCKET_H */
 
index 6af3253..2c3f4b4 100644 (file)
 
 #define SO_INCOMING_NAPI_ID    56
 
+#define SO_COOKIE              57
+
 #endif /* _ASM_IA64_SOCKET_H */
index e98b6bb..ae6548d 100644 (file)
@@ -96,4 +96,6 @@
 
 #define SO_INCOMING_NAPI_ID    56
 
+#define SO_COOKIE              57
+
 #endif /* _ASM_M32R_SOCKET_H */
index ae2b62e..3418ec9 100644 (file)
 
 #define SO_INCOMING_NAPI_ID    56
 
+#define SO_COOKIE              57
+
 #endif /* _UAPI_ASM_SOCKET_H */
index e4ac184..4526e92 100644 (file)
@@ -96,4 +96,6 @@
 
 #define SO_INCOMING_NAPI_ID    56
 
+#define SO_COOKIE              57
+
 #endif /* _ASM_SOCKET_H */
index f754c79..5147018 100644 (file)
@@ -95,4 +95,6 @@
 
 #define SO_INCOMING_NAPI_ID    0x4031
 
+#define SO_COOKIE              0x4032
+
 #endif /* _UAPI_ASM_SOCKET_H */
index 5f84af7..58e2ec0 100644 (file)
 
 #define SO_INCOMING_NAPI_ID    56
 
+#define SO_COOKIE              57
+
 #endif /* _ASM_POWERPC_SOCKET_H */
index 25ac496..e8e5ecf 100644 (file)
 
 #define SO_INCOMING_NAPI_ID    56
 
+#define SO_COOKIE              57
+
 #endif /* _ASM_SOCKET_H */
index b05513a..3f4ad19 100644 (file)
@@ -92,6 +92,8 @@
 
 #define SO_INCOMING_NAPI_ID    0x003a
 
+#define SO_COOKIE              0x003b
+
 /* Security levels - as per NRL IPv6 - don't actually do anything */
 #define SO_SECURITY_AUTHENTICATION             0x5001
 #define SO_SECURITY_ENCRYPTION_TRANSPORT       0x5002
index 786606c..1eb6d2f 100644 (file)
 
 #define SO_INCOMING_NAPI_ID    56
 
+#define SO_COOKIE              57
+
 #endif /* _XTENSA_SOCKET_H */
index c98a52f..2b48856 100644 (file)
@@ -98,4 +98,6 @@
 
 #define SO_INCOMING_NAPI_ID    56
 
+#define SO_COOKIE              57
+
 #endif /* __ASM_GENERIC_SOCKET_H */
index 392f9b6..a06bb7a 100644 (file)
@@ -1083,6 +1083,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
 
        union {
                int val;
+               u64 val64;
                struct linger ling;
                struct timeval tm;
        } v;
@@ -1340,6 +1341,13 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
                break;
 #endif
 
+       case SO_COOKIE:
+               lv = sizeof(u64);
+               if (len < lv)
+                       return -EINVAL;
+               v.val64 = sock_gen_cookie(sk);
+               break;
+
        default:
                /* We implement the SO_SNDLOWAT etc to not be settable
                 * (1003.1g 7).