@@ -116,10 +116,13 @@ static void vsock_sk_destruct(struct sock *sk);
116
116
static int vsock_queue_rcv_skb (struct sock * sk , struct sk_buff * skb );
117
117
118
118
/* Protocol family. */
119
- static struct proto vsock_proto = {
119
+ struct proto vsock_proto = {
120
120
.name = "AF_VSOCK" ,
121
121
.owner = THIS_MODULE ,
122
122
.obj_size = sizeof (struct vsock_sock ),
123
+ #ifdef CONFIG_BPF_SYSCALL
124
+ .psock_update_sk_prot = vsock_bpf_update_proto ,
125
+ #endif
123
126
};
124
127
125
128
/* The default peer timeout indicates how long we will wait for a peer response
@@ -865,7 +868,7 @@ s64 vsock_stream_has_data(struct vsock_sock *vsk)
865
868
}
866
869
EXPORT_SYMBOL_GPL (vsock_stream_has_data );
867
870
868
- static s64 vsock_connectible_has_data (struct vsock_sock * vsk )
871
+ s64 vsock_connectible_has_data (struct vsock_sock * vsk )
869
872
{
870
873
struct sock * sk = sk_vsock (vsk );
871
874
@@ -874,6 +877,7 @@ static s64 vsock_connectible_has_data(struct vsock_sock *vsk)
874
877
else
875
878
return vsock_stream_has_data (vsk );
876
879
}
880
+ EXPORT_SYMBOL_GPL (vsock_connectible_has_data );
877
881
878
882
s64 vsock_stream_has_space (struct vsock_sock * vsk )
879
883
{
@@ -1131,6 +1135,13 @@ static __poll_t vsock_poll(struct file *file, struct socket *sock,
1131
1135
return mask ;
1132
1136
}
1133
1137
1138
+ static int vsock_read_skb (struct sock * sk , skb_read_actor_t read_actor )
1139
+ {
1140
+ struct vsock_sock * vsk = vsock_sk (sk );
1141
+
1142
+ return vsk -> transport -> read_skb (vsk , read_actor );
1143
+ }
1144
+
1134
1145
static int vsock_dgram_sendmsg (struct socket * sock , struct msghdr * msg ,
1135
1146
size_t len )
1136
1147
{
@@ -1242,18 +1253,42 @@ static int vsock_dgram_connect(struct socket *sock,
1242
1253
memcpy (& vsk -> remote_addr , remote_addr , sizeof (vsk -> remote_addr ));
1243
1254
sock -> state = SS_CONNECTED ;
1244
1255
1256
+ /* sock map disallows redirection of non-TCP sockets with sk_state !=
1257
+ * TCP_ESTABLISHED (see sock_map_redirect_allowed()), so we set
1258
+ * TCP_ESTABLISHED here to allow redirection of connected vsock dgrams.
1259
+ *
1260
+ * This doesn't seem to be abnormal state for datagram sockets, as the
1261
+ * same approach can be see in other datagram socket types as well
1262
+ * (such as unix sockets).
1263
+ */
1264
+ sk -> sk_state = TCP_ESTABLISHED ;
1265
+
1245
1266
out :
1246
1267
release_sock (sk );
1247
1268
return err ;
1248
1269
}
1249
1270
1250
- static int vsock_dgram_recvmsg (struct socket * sock , struct msghdr * msg ,
1251
- size_t len , int flags )
1271
+ int vsock_dgram_recvmsg (struct socket * sock , struct msghdr * msg ,
1272
+ size_t len , int flags )
1252
1273
{
1253
- struct vsock_sock * vsk = vsock_sk (sock -> sk );
1274
+ #ifdef CONFIG_BPF_SYSCALL
1275
+ const struct proto * prot ;
1276
+ #endif
1277
+ struct vsock_sock * vsk ;
1278
+ struct sock * sk ;
1279
+
1280
+ sk = sock -> sk ;
1281
+ vsk = vsock_sk (sk );
1282
+
1283
+ #ifdef CONFIG_BPF_SYSCALL
1284
+ prot = READ_ONCE (sk -> sk_prot );
1285
+ if (prot != & vsock_proto )
1286
+ return prot -> recvmsg (sk , msg , len , flags , NULL );
1287
+ #endif
1254
1288
1255
1289
return vsk -> transport -> dgram_dequeue (vsk , msg , len , flags );
1256
1290
}
1291
+ EXPORT_SYMBOL_GPL (vsock_dgram_recvmsg );
1257
1292
1258
1293
static const struct proto_ops vsock_dgram_ops = {
1259
1294
.family = PF_VSOCK ,
@@ -1272,6 +1307,7 @@ static const struct proto_ops vsock_dgram_ops = {
1272
1307
.recvmsg = vsock_dgram_recvmsg ,
1273
1308
.mmap = sock_no_mmap ,
1274
1309
.sendpage = sock_no_sendpage ,
1310
+ .read_skb = vsock_read_skb ,
1275
1311
};
1276
1312
1277
1313
static int vsock_transport_cancel_pkt (struct vsock_sock * vsk )
@@ -2086,13 +2122,16 @@ static int __vsock_seqpacket_recvmsg(struct sock *sk, struct msghdr *msg,
2086
2122
return err ;
2087
2123
}
2088
2124
2089
- static int
2125
+ int
2090
2126
vsock_connectible_recvmsg (struct socket * sock , struct msghdr * msg , size_t len ,
2091
2127
int flags )
2092
2128
{
2093
2129
struct sock * sk ;
2094
2130
struct vsock_sock * vsk ;
2095
2131
const struct vsock_transport * transport ;
2132
+ #ifdef CONFIG_BPF_SYSCALL
2133
+ const struct proto * prot ;
2134
+ #endif
2096
2135
int err ;
2097
2136
2098
2137
sk = sock -> sk ;
@@ -2139,6 +2178,14 @@ vsock_connectible_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
2139
2178
goto out ;
2140
2179
}
2141
2180
2181
+ #ifdef CONFIG_BPF_SYSCALL
2182
+ prot = READ_ONCE (sk -> sk_prot );
2183
+ if (prot != & vsock_proto ) {
2184
+ release_sock (sk );
2185
+ return prot -> recvmsg (sk , msg , len , flags , NULL );
2186
+ }
2187
+ #endif
2188
+
2142
2189
if (sk -> sk_type == SOCK_STREAM )
2143
2190
err = __vsock_stream_recvmsg (sk , msg , len , flags );
2144
2191
else
@@ -2148,6 +2195,7 @@ vsock_connectible_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
2148
2195
release_sock (sk );
2149
2196
return err ;
2150
2197
}
2198
+ EXPORT_SYMBOL_GPL (vsock_connectible_recvmsg );
2151
2199
2152
2200
static int vsock_set_rcvlowat (struct sock * sk , int val )
2153
2201
{
@@ -2188,6 +2236,7 @@ static const struct proto_ops vsock_stream_ops = {
2188
2236
.mmap = sock_no_mmap ,
2189
2237
.sendpage = sock_no_sendpage ,
2190
2238
.set_rcvlowat = vsock_set_rcvlowat ,
2239
+ .read_skb = vsock_read_skb ,
2191
2240
};
2192
2241
2193
2242
static const struct proto_ops vsock_seqpacket_ops = {
@@ -2209,6 +2258,7 @@ static const struct proto_ops vsock_seqpacket_ops = {
2209
2258
.recvmsg = vsock_connectible_recvmsg ,
2210
2259
.mmap = sock_no_mmap ,
2211
2260
.sendpage = sock_no_sendpage ,
2261
+ .read_skb = vsock_read_skb ,
2212
2262
};
2213
2263
2214
2264
static int vsock_create (struct net * net , struct socket * sock ,
@@ -2348,6 +2398,8 @@ static int __init vsock_init(void)
2348
2398
goto err_unregister_proto ;
2349
2399
}
2350
2400
2401
+ vsock_bpf_build_proto ();
2402
+
2351
2403
return 0 ;
2352
2404
2353
2405
err_unregister_proto :
0 commit comments