GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — af_unix: Introduce SO_INQ. · torvalds/linux@df30285

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • arch
    • alpha/include/uapi/asm
      • socket.h
    • mips/include/uapi/asm
      • socket.h
    • parisc/include/uapi/asm
      • socket.h
    • sparc/include/uapi/asm
      • socket.h
  • include
    • net
      • af_unix.h
    • uapi/asm-generic
      • socket.h
  • net/unix
    • af_unix.c
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎arch/alpha/include/uapi/asm/socket.h‎

Copy file name to clipboardExpand all lines: arch/alpha/include/uapi/asm/socket.h
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@
152152

153153
#define SO_PASSRIGHTS 83
154154

155+
#define SO_INQ 84
156+
#define SCM_INQ SO_INQ
157+
155158
#if !defined(__KERNEL__)
156159

157160
#if __BITS_PER_LONG == 64
Collapse file

‎arch/mips/include/uapi/asm/socket.h‎

Copy file name to clipboardExpand all lines: arch/mips/include/uapi/asm/socket.h
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,9 @@
163163

164164
#define SO_PASSRIGHTS 83
165165

166+
#define SO_INQ 84
167+
#define SCM_INQ SO_INQ
168+
166169
#if !defined(__KERNEL__)
167170

168171
#if __BITS_PER_LONG == 64
Collapse file

‎arch/parisc/include/uapi/asm/socket.h‎

Copy file name to clipboardExpand all lines: arch/parisc/include/uapi/asm/socket.h
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@
144144

145145
#define SO_PASSRIGHTS 0x4051
146146

147+
#define SO_INQ 0x4052
148+
#define SCM_INQ SO_INQ
149+
147150
#if !defined(__KERNEL__)
148151

149152
#if __BITS_PER_LONG == 64
Collapse file

‎arch/sparc/include/uapi/asm/socket.h‎

Copy file name to clipboardExpand all lines: arch/sparc/include/uapi/asm/socket.h
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@
145145

146146
#define SO_PASSRIGHTS 0x005c
147147

148+
#define SO_INQ 0x005d
149+
#define SCM_INQ SO_INQ
150+
148151
#if !defined(__KERNEL__)
149152

150153

Collapse file

‎include/net/af_unix.h‎

Copy file name to clipboardExpand all lines: include/net/af_unix.h
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ struct unix_sock {
4848
wait_queue_entry_t peer_wake;
4949
struct scm_stat scm_stat;
5050
int inq_len;
51+
bool recvmsg_inq;
5152
#if IS_ENABLED(CONFIG_AF_UNIX_OOB)
5253
struct sk_buff *oob_skb;
5354
#endif
Collapse file

‎include/uapi/asm-generic/socket.h‎

Copy file name to clipboardExpand all lines: include/uapi/asm-generic/socket.h
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@
147147

148148
#define SO_PASSRIGHTS 83
149149

150+
#define SO_INQ 84
151+
#define SCM_INQ SO_INQ
152+
150153
#if !defined(__KERNEL__)
151154

152155
#if __BITS_PER_LONG == 64 || (defined(__x86_64__) && defined(__ILP32__))
Collapse file

‎net/unix/af_unix.c‎

Copy file name to clipboardExpand all lines: net/unix/af_unix.c
+60-2Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -934,6 +934,52 @@ static void unix_show_fdinfo(struct seq_file *m, struct socket *sock)
934934
#define unix_show_fdinfo NULL
935935
#endif
936936

937+
static bool unix_custom_sockopt(int optname)
938+
{
939+
switch (optname) {
940+
case SO_INQ:
941+
return true;
942+
default:
943+
return false;
944+
}
945+
}
946+
947+
static int unix_setsockopt(struct socket *sock, int level, int optname,
948+
sockptr_t optval, unsigned int optlen)
949+
{
950+
struct unix_sock *u = unix_sk(sock->sk);
951+
struct sock *sk = sock->sk;
952+
int val;
953+
954+
if (level != SOL_SOCKET)
955+
return -EOPNOTSUPP;
956+
957+
if (!unix_custom_sockopt(optname))
958+
return sock_setsockopt(sock, level, optname, optval, optlen);
959+
960+
if (optlen != sizeof(int))
961+
return -EINVAL;
962+
963+
if (copy_from_sockptr(&val, optval, sizeof(val)))
964+
return -EFAULT;
965+
966+
switch (optname) {
967+
case SO_INQ:
968+
if (sk->sk_type != SOCK_STREAM)
969+
return -EINVAL;
970+
971+
if (val > 1 || val < 0)
972+
return -EINVAL;
973+
974+
WRITE_ONCE(u->recvmsg_inq, val);
975+
break;
976+
default:
977+
return -ENOPROTOOPT;
978+
}
979+
980+
return 0;
981+
}
982+
937983
static const struct proto_ops unix_stream_ops = {
938984
.family = PF_UNIX,
939985
.owner = THIS_MODULE,
@@ -950,6 +996,7 @@ static const struct proto_ops unix_stream_ops = {
950996
#endif
951997
.listen = unix_listen,
952998
.shutdown = unix_shutdown,
999+
.setsockopt = unix_setsockopt,
9531000
.sendmsg = unix_stream_sendmsg,
9541001
.recvmsg = unix_stream_recvmsg,
9551002
.read_skb = unix_stream_read_skb,
@@ -1116,6 +1163,7 @@ static int unix_create(struct net *net, struct socket *sock, int protocol,
11161163

11171164
switch (sock->type) {
11181165
case SOCK_STREAM:
1166+
set_bit(SOCK_CUSTOM_SOCKOPT, &sock->flags);
11191167
sock->ops = &unix_stream_ops;
11201168
break;
11211169
/*
@@ -1847,6 +1895,9 @@ static int unix_accept(struct socket *sock, struct socket *newsock,
18471895
skb_free_datagram(sk, skb);
18481896
wake_up_interruptible(&unix_sk(sk)->peer_wait);
18491897

1898+
if (tsk->sk_type == SOCK_STREAM)
1899+
set_bit(SOCK_CUSTOM_SOCKOPT, &newsock->flags);
1900+
18501901
/* attach accepted sock to socket */
18511902
unix_state_lock(tsk);
18521903
unix_update_edges(unix_sk(tsk));
@@ -3034,10 +3085,17 @@ static int unix_stream_read_generic(struct unix_stream_read_state *state,
30343085
} while (size);
30353086

30363087
mutex_unlock(&u->iolock);
3037-
if (msg)
3088+
if (msg) {
30383089
scm_recv_unix(sock, msg, &scm, flags);
3039-
else
3090+
3091+
if (READ_ONCE(u->recvmsg_inq) || msg->msg_get_inq) {
3092+
msg->msg_inq = READ_ONCE(u->inq_len);
3093+
put_cmsg(msg, SOL_SOCKET, SCM_INQ,
3094+
sizeof(msg->msg_inq), &msg->msg_inq);
3095+
}
3096+
} else {
30403097
scm_destroy(&scm);
3098+
}
30413099
out:
30423100
return copied ? : err;
30433101
}

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.