af_vsock.c 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014
  1. /*
  2. * VMware vSockets Driver
  3. *
  4. * Copyright (C) 2007-2013 VMware, Inc. All rights reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the Free
  8. * Software Foundation version 2 and no later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. */
  15. /* Implementation notes:
  16. *
  17. * - There are two kinds of sockets: those created by user action (such as
  18. * calling socket(2)) and those created by incoming connection request packets.
  19. *
  20. * - There are two "global" tables, one for bound sockets (sockets that have
  21. * specified an address that they are responsible for) and one for connected
  22. * sockets (sockets that have established a connection with another socket).
  23. * These tables are "global" in that all sockets on the system are placed
  24. * within them. - Note, though, that the bound table contains an extra entry
  25. * for a list of unbound sockets and SOCK_DGRAM sockets will always remain in
  26. * that list. The bound table is used solely for lookup of sockets when packets
  27. * are received and that's not necessary for SOCK_DGRAM sockets since we create
  28. * a datagram handle for each and need not perform a lookup. Keeping SOCK_DGRAM
  29. * sockets out of the bound hash buckets will reduce the chance of collisions
  30. * when looking for SOCK_STREAM sockets and prevents us from having to check the
  31. * socket type in the hash table lookups.
  32. *
  33. * - Sockets created by user action will either be "client" sockets that
  34. * initiate a connection or "server" sockets that listen for connections; we do
  35. * not support simultaneous connects (two "client" sockets connecting).
  36. *
  37. * - "Server" sockets are referred to as listener sockets throughout this
  38. * implementation because they are in the VSOCK_SS_LISTEN state. When a
  39. * connection request is received (the second kind of socket mentioned above),
  40. * we create a new socket and refer to it as a pending socket. These pending
  41. * sockets are placed on the pending connection list of the listener socket.
  42. * When future packets are received for the address the listener socket is
  43. * bound to, we check if the source of the packet is from one that has an
  44. * existing pending connection. If it does, we process the packet for the
  45. * pending socket. When that socket reaches the connected state, it is removed
  46. * from the listener socket's pending list and enqueued in the listener
  47. * socket's accept queue. Callers of accept(2) will accept connected sockets
  48. * from the listener socket's accept queue. If the socket cannot be accepted
  49. * for some reason then it is marked rejected. Once the connection is
  50. * accepted, it is owned by the user process and the responsibility for cleanup
  51. * falls with that user process.
  52. *
  53. * - It is possible that these pending sockets will never reach the connected
  54. * state; in fact, we may never receive another packet after the connection
  55. * request. Because of this, we must schedule a cleanup function to run in the
  56. * future, after some amount of time passes where a connection should have been
  57. * established. This function ensures that the socket is off all lists so it
  58. * cannot be retrieved, then drops all references to the socket so it is cleaned
  59. * up (sock_put() -> sk_free() -> our sk_destruct implementation). Note this
  60. * function will also cleanup rejected sockets, those that reach the connected
  61. * state but leave it before they have been accepted.
  62. *
  63. * - Lock ordering for pending or accept queue sockets is:
  64. *
  65. * lock_sock(listener);
  66. * lock_sock_nested(pending, SINGLE_DEPTH_NESTING);
  67. *
  68. * Using explicit nested locking keeps lockdep happy since normally only one
  69. * lock of a given class may be taken at a time.
  70. *
  71. * - Sockets created by user action will be cleaned up when the user process
  72. * calls close(2), causing our release implementation to be called. Our release
  73. * implementation will perform some cleanup then drop the last reference so our
  74. * sk_destruct implementation is invoked. Our sk_destruct implementation will
  75. * perform additional cleanup that's common for both types of sockets.
  76. *
  77. * - A socket's reference count is what ensures that the structure won't be
  78. * freed. Each entry in a list (such as the "global" bound and connected tables
  79. * and the listener socket's pending list and connected queue) ensures a
  80. * reference. When we defer work until process context and pass a socket as our
  81. * argument, we must ensure the reference count is increased to ensure the
  82. * socket isn't freed before the function is run; the deferred function will
  83. * then drop the reference.
  84. */
  85. #include <linux/types.h>
  86. #include <linux/bitops.h>
  87. #include <linux/cred.h>
  88. #include <linux/init.h>
  89. #include <linux/io.h>
  90. #include <linux/kernel.h>
  91. #include <linux/kmod.h>
  92. #include <linux/list.h>
  93. #include <linux/miscdevice.h>
  94. #include <linux/module.h>
  95. #include <linux/mutex.h>
  96. #include <linux/net.h>
  97. #include <linux/poll.h>
  98. #include <linux/skbuff.h>
  99. #include <linux/smp.h>
  100. #include <linux/socket.h>
  101. #include <linux/stddef.h>
  102. #include <linux/unistd.h>
  103. #include <linux/wait.h>
  104. #include <linux/workqueue.h>
  105. #include <net/sock.h>
  106. #include <net/af_vsock.h>
  107. static int __vsock_bind(struct sock *sk, struct sockaddr_vm *addr);
  108. static void vsock_sk_destruct(struct sock *sk);
  109. static int vsock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb);
  110. /* Protocol family. */
  111. static struct proto vsock_proto = {
  112. .name = "AF_VSOCK",
  113. .owner = THIS_MODULE,
  114. .obj_size = sizeof(struct vsock_sock),
  115. };
  116. /* The default peer timeout indicates how long we will wait for a peer response
  117. * to a control message.
  118. */
  119. #define VSOCK_DEFAULT_CONNECT_TIMEOUT (2 * HZ)
  120. static const struct vsock_transport *transport;
  121. static DEFINE_MUTEX(vsock_register_mutex);
  122. /**** EXPORTS ****/
  123. /* Get the ID of the local context. This is transport dependent. */
  124. int vm_sockets_get_local_cid(void)
  125. {
  126. return transport->get_local_cid();
  127. }
  128. EXPORT_SYMBOL_GPL(vm_sockets_get_local_cid);
  129. /**** UTILS ****/
  130. /* Each bound VSocket is stored in the bind hash table and each connected
  131. * VSocket is stored in the connected hash table.
  132. *
  133. * Unbound sockets are all put on the same list attached to the end of the hash
  134. * table (vsock_unbound_sockets). Bound sockets are added to the hash table in
  135. * the bucket that their local address hashes to (vsock_bound_sockets(addr)
  136. * represents the list that addr hashes to).
  137. *
  138. * Specifically, we initialize the vsock_bind_table array to a size of
  139. * VSOCK_HASH_SIZE + 1 so that vsock_bind_table[0] through
  140. * vsock_bind_table[VSOCK_HASH_SIZE - 1] are for bound sockets and
  141. * vsock_bind_table[VSOCK_HASH_SIZE] is for unbound sockets. The hash function
  142. * mods with VSOCK_HASH_SIZE to ensure this.
  143. */
  144. #define VSOCK_HASH_SIZE 251
  145. #define MAX_PORT_RETRIES 24
  146. #define VSOCK_HASH(addr) ((addr)->svm_port % VSOCK_HASH_SIZE)
  147. #define vsock_bound_sockets(addr) (&vsock_bind_table[VSOCK_HASH(addr)])
  148. #define vsock_unbound_sockets (&vsock_bind_table[VSOCK_HASH_SIZE])
  149. /* XXX This can probably be implemented in a better way. */
  150. #define VSOCK_CONN_HASH(src, dst) \
  151. (((src)->svm_cid ^ (dst)->svm_port) % VSOCK_HASH_SIZE)
  152. #define vsock_connected_sockets(src, dst) \
  153. (&vsock_connected_table[VSOCK_CONN_HASH(src, dst)])
  154. #define vsock_connected_sockets_vsk(vsk) \
  155. vsock_connected_sockets(&(vsk)->remote_addr, &(vsk)->local_addr)
  156. static struct list_head vsock_bind_table[VSOCK_HASH_SIZE + 1];
  157. static struct list_head vsock_connected_table[VSOCK_HASH_SIZE];
  158. static DEFINE_SPINLOCK(vsock_table_lock);
  159. /* Autobind this socket to the local address if necessary. */
  160. static int vsock_auto_bind(struct vsock_sock *vsk)
  161. {
  162. struct sock *sk = sk_vsock(vsk);
  163. struct sockaddr_vm local_addr;
  164. if (vsock_addr_bound(&vsk->local_addr))
  165. return 0;
  166. vsock_addr_init(&local_addr, VMADDR_CID_ANY, VMADDR_PORT_ANY);
  167. return __vsock_bind(sk, &local_addr);
  168. }
  169. static void vsock_init_tables(void)
  170. {
  171. int i;
  172. for (i = 0; i < ARRAY_SIZE(vsock_bind_table); i++)
  173. INIT_LIST_HEAD(&vsock_bind_table[i]);
  174. for (i = 0; i < ARRAY_SIZE(vsock_connected_table); i++)
  175. INIT_LIST_HEAD(&vsock_connected_table[i]);
  176. }
  177. static void __vsock_insert_bound(struct list_head *list,
  178. struct vsock_sock *vsk)
  179. {
  180. sock_hold(&vsk->sk);
  181. list_add(&vsk->bound_table, list);
  182. }
  183. static void __vsock_insert_connected(struct list_head *list,
  184. struct vsock_sock *vsk)
  185. {
  186. sock_hold(&vsk->sk);
  187. list_add(&vsk->connected_table, list);
  188. }
  189. static void __vsock_remove_bound(struct vsock_sock *vsk)
  190. {
  191. list_del_init(&vsk->bound_table);
  192. sock_put(&vsk->sk);
  193. }
  194. static void __vsock_remove_connected(struct vsock_sock *vsk)
  195. {
  196. list_del_init(&vsk->connected_table);
  197. sock_put(&vsk->sk);
  198. }
  199. static struct sock *__vsock_find_bound_socket(struct sockaddr_vm *addr)
  200. {
  201. struct vsock_sock *vsk;
  202. list_for_each_entry(vsk, vsock_bound_sockets(addr), bound_table)
  203. if (addr->svm_port == vsk->local_addr.svm_port)
  204. return sk_vsock(vsk);
  205. return NULL;
  206. }
  207. static struct sock *__vsock_find_connected_socket(struct sockaddr_vm *src,
  208. struct sockaddr_vm *dst)
  209. {
  210. struct vsock_sock *vsk;
  211. list_for_each_entry(vsk, vsock_connected_sockets(src, dst),
  212. connected_table) {
  213. if (vsock_addr_equals_addr(src, &vsk->remote_addr) &&
  214. dst->svm_port == vsk->local_addr.svm_port) {
  215. return sk_vsock(vsk);
  216. }
  217. }
  218. return NULL;
  219. }
  220. static bool __vsock_in_bound_table(struct vsock_sock *vsk)
  221. {
  222. return !list_empty(&vsk->bound_table);
  223. }
  224. static bool __vsock_in_connected_table(struct vsock_sock *vsk)
  225. {
  226. return !list_empty(&vsk->connected_table);
  227. }
  228. static void vsock_insert_unbound(struct vsock_sock *vsk)
  229. {
  230. spin_lock_bh(&vsock_table_lock);
  231. __vsock_insert_bound(vsock_unbound_sockets, vsk);
  232. spin_unlock_bh(&vsock_table_lock);
  233. }
  234. void vsock_insert_connected(struct vsock_sock *vsk)
  235. {
  236. struct list_head *list = vsock_connected_sockets(
  237. &vsk->remote_addr, &vsk->local_addr);
  238. spin_lock_bh(&vsock_table_lock);
  239. __vsock_insert_connected(list, vsk);
  240. spin_unlock_bh(&vsock_table_lock);
  241. }
  242. EXPORT_SYMBOL_GPL(vsock_insert_connected);
  243. void vsock_remove_bound(struct vsock_sock *vsk)
  244. {
  245. spin_lock_bh(&vsock_table_lock);
  246. __vsock_remove_bound(vsk);
  247. spin_unlock_bh(&vsock_table_lock);
  248. }
  249. EXPORT_SYMBOL_GPL(vsock_remove_bound);
  250. void vsock_remove_connected(struct vsock_sock *vsk)
  251. {
  252. spin_lock_bh(&vsock_table_lock);
  253. __vsock_remove_connected(vsk);
  254. spin_unlock_bh(&vsock_table_lock);
  255. }
  256. EXPORT_SYMBOL_GPL(vsock_remove_connected);
  257. struct sock *vsock_find_bound_socket(struct sockaddr_vm *addr)
  258. {
  259. struct sock *sk;
  260. spin_lock_bh(&vsock_table_lock);
  261. sk = __vsock_find_bound_socket(addr);
  262. if (sk)
  263. sock_hold(sk);
  264. spin_unlock_bh(&vsock_table_lock);
  265. return sk;
  266. }
  267. EXPORT_SYMBOL_GPL(vsock_find_bound_socket);
  268. struct sock *vsock_find_connected_socket(struct sockaddr_vm *src,
  269. struct sockaddr_vm *dst)
  270. {
  271. struct sock *sk;
  272. spin_lock_bh(&vsock_table_lock);
  273. sk = __vsock_find_connected_socket(src, dst);
  274. if (sk)
  275. sock_hold(sk);
  276. spin_unlock_bh(&vsock_table_lock);
  277. return sk;
  278. }
  279. EXPORT_SYMBOL_GPL(vsock_find_connected_socket);
  280. static bool vsock_in_bound_table(struct vsock_sock *vsk)
  281. {
  282. bool ret;
  283. spin_lock_bh(&vsock_table_lock);
  284. ret = __vsock_in_bound_table(vsk);
  285. spin_unlock_bh(&vsock_table_lock);
  286. return ret;
  287. }
  288. static bool vsock_in_connected_table(struct vsock_sock *vsk)
  289. {
  290. bool ret;
  291. spin_lock_bh(&vsock_table_lock);
  292. ret = __vsock_in_connected_table(vsk);
  293. spin_unlock_bh(&vsock_table_lock);
  294. return ret;
  295. }
  296. void vsock_remove_sock(struct vsock_sock *vsk)
  297. {
  298. if (vsock_in_bound_table(vsk))
  299. vsock_remove_bound(vsk);
  300. if (vsock_in_connected_table(vsk))
  301. vsock_remove_connected(vsk);
  302. }
  303. EXPORT_SYMBOL_GPL(vsock_remove_sock);
  304. void vsock_for_each_connected_socket(void (*fn)(struct sock *sk))
  305. {
  306. int i;
  307. spin_lock_bh(&vsock_table_lock);
  308. for (i = 0; i < ARRAY_SIZE(vsock_connected_table); i++) {
  309. struct vsock_sock *vsk;
  310. list_for_each_entry(vsk, &vsock_connected_table[i],
  311. connected_table)
  312. fn(sk_vsock(vsk));
  313. }
  314. spin_unlock_bh(&vsock_table_lock);
  315. }
  316. EXPORT_SYMBOL_GPL(vsock_for_each_connected_socket);
  317. void vsock_add_pending(struct sock *listener, struct sock *pending)
  318. {
  319. struct vsock_sock *vlistener;
  320. struct vsock_sock *vpending;
  321. vlistener = vsock_sk(listener);
  322. vpending = vsock_sk(pending);
  323. sock_hold(pending);
  324. sock_hold(listener);
  325. list_add_tail(&vpending->pending_links, &vlistener->pending_links);
  326. }
  327. EXPORT_SYMBOL_GPL(vsock_add_pending);
  328. void vsock_remove_pending(struct sock *listener, struct sock *pending)
  329. {
  330. struct vsock_sock *vpending = vsock_sk(pending);
  331. list_del_init(&vpending->pending_links);
  332. sock_put(listener);
  333. sock_put(pending);
  334. }
  335. EXPORT_SYMBOL_GPL(vsock_remove_pending);
  336. void vsock_enqueue_accept(struct sock *listener, struct sock *connected)
  337. {
  338. struct vsock_sock *vlistener;
  339. struct vsock_sock *vconnected;
  340. vlistener = vsock_sk(listener);
  341. vconnected = vsock_sk(connected);
  342. sock_hold(connected);
  343. sock_hold(listener);
  344. list_add_tail(&vconnected->accept_queue, &vlistener->accept_queue);
  345. }
  346. EXPORT_SYMBOL_GPL(vsock_enqueue_accept);
  347. static struct sock *vsock_dequeue_accept(struct sock *listener)
  348. {
  349. struct vsock_sock *vlistener;
  350. struct vsock_sock *vconnected;
  351. vlistener = vsock_sk(listener);
  352. if (list_empty(&vlistener->accept_queue))
  353. return NULL;
  354. vconnected = list_entry(vlistener->accept_queue.next,
  355. struct vsock_sock, accept_queue);
  356. list_del_init(&vconnected->accept_queue);
  357. sock_put(listener);
  358. /* The caller will need a reference on the connected socket so we let
  359. * it call sock_put().
  360. */
  361. return sk_vsock(vconnected);
  362. }
  363. static bool vsock_is_accept_queue_empty(struct sock *sk)
  364. {
  365. struct vsock_sock *vsk = vsock_sk(sk);
  366. return list_empty(&vsk->accept_queue);
  367. }
  368. static bool vsock_is_pending(struct sock *sk)
  369. {
  370. struct vsock_sock *vsk = vsock_sk(sk);
  371. return !list_empty(&vsk->pending_links);
  372. }
  373. static int vsock_send_shutdown(struct sock *sk, int mode)
  374. {
  375. return transport->shutdown(vsock_sk(sk), mode);
  376. }
  377. void vsock_pending_work(struct work_struct *work)
  378. {
  379. struct sock *sk;
  380. struct sock *listener;
  381. struct vsock_sock *vsk;
  382. bool cleanup;
  383. vsk = container_of(work, struct vsock_sock, dwork.work);
  384. sk = sk_vsock(vsk);
  385. listener = vsk->listener;
  386. cleanup = true;
  387. lock_sock(listener);
  388. lock_sock_nested(sk, SINGLE_DEPTH_NESTING);
  389. if (vsock_is_pending(sk)) {
  390. vsock_remove_pending(listener, sk);
  391. listener->sk_ack_backlog--;
  392. } else if (!vsk->rejected) {
  393. /* We are not on the pending list and accept() did not reject
  394. * us, so we must have been accepted by our user process. We
  395. * just need to drop our references to the sockets and be on
  396. * our way.
  397. */
  398. cleanup = false;
  399. goto out;
  400. }
  401. /* We need to remove ourself from the global connected sockets list so
  402. * incoming packets can't find this socket, and to reduce the reference
  403. * count.
  404. */
  405. if (vsock_in_connected_table(vsk))
  406. vsock_remove_connected(vsk);
  407. sk->sk_state = SS_FREE;
  408. out:
  409. release_sock(sk);
  410. release_sock(listener);
  411. if (cleanup)
  412. sock_put(sk);
  413. sock_put(sk);
  414. sock_put(listener);
  415. }
  416. EXPORT_SYMBOL_GPL(vsock_pending_work);
  417. /**** SOCKET OPERATIONS ****/
  418. static int __vsock_bind_stream(struct vsock_sock *vsk,
  419. struct sockaddr_vm *addr)
  420. {
  421. static u32 port = LAST_RESERVED_PORT + 1;
  422. struct sockaddr_vm new_addr;
  423. vsock_addr_init(&new_addr, addr->svm_cid, addr->svm_port);
  424. if (addr->svm_port == VMADDR_PORT_ANY) {
  425. bool found = false;
  426. unsigned int i;
  427. for (i = 0; i < MAX_PORT_RETRIES; i++) {
  428. if (port <= LAST_RESERVED_PORT)
  429. port = LAST_RESERVED_PORT + 1;
  430. new_addr.svm_port = port++;
  431. if (!__vsock_find_bound_socket(&new_addr)) {
  432. found = true;
  433. break;
  434. }
  435. }
  436. if (!found)
  437. return -EADDRNOTAVAIL;
  438. } else {
  439. /* If port is in reserved range, ensure caller
  440. * has necessary privileges.
  441. */
  442. if (addr->svm_port <= LAST_RESERVED_PORT &&
  443. !capable(CAP_NET_BIND_SERVICE)) {
  444. return -EACCES;
  445. }
  446. if (__vsock_find_bound_socket(&new_addr))
  447. return -EADDRINUSE;
  448. }
  449. vsock_addr_init(&vsk->local_addr, new_addr.svm_cid, new_addr.svm_port);
  450. /* Remove stream sockets from the unbound list and add them to the hash
  451. * table for easy lookup by its address. The unbound list is simply an
  452. * extra entry at the end of the hash table, a trick used by AF_UNIX.
  453. */
  454. __vsock_remove_bound(vsk);
  455. __vsock_insert_bound(vsock_bound_sockets(&vsk->local_addr), vsk);
  456. return 0;
  457. }
  458. static int __vsock_bind_dgram(struct vsock_sock *vsk,
  459. struct sockaddr_vm *addr)
  460. {
  461. return transport->dgram_bind(vsk, addr);
  462. }
  463. static int __vsock_bind(struct sock *sk, struct sockaddr_vm *addr)
  464. {
  465. struct vsock_sock *vsk = vsock_sk(sk);
  466. u32 cid;
  467. int retval;
  468. /* First ensure this socket isn't already bound. */
  469. if (vsock_addr_bound(&vsk->local_addr))
  470. return -EINVAL;
  471. /* Now bind to the provided address or select appropriate values if
  472. * none are provided (VMADDR_CID_ANY and VMADDR_PORT_ANY). Note that
  473. * like AF_INET prevents binding to a non-local IP address (in most
  474. * cases), we only allow binding to the local CID.
  475. */
  476. cid = transport->get_local_cid();
  477. if (addr->svm_cid != cid && addr->svm_cid != VMADDR_CID_ANY)
  478. return -EADDRNOTAVAIL;
  479. switch (sk->sk_socket->type) {
  480. case SOCK_STREAM:
  481. spin_lock_bh(&vsock_table_lock);
  482. retval = __vsock_bind_stream(vsk, addr);
  483. spin_unlock_bh(&vsock_table_lock);
  484. break;
  485. case SOCK_DGRAM:
  486. retval = __vsock_bind_dgram(vsk, addr);
  487. break;
  488. default:
  489. retval = -EINVAL;
  490. break;
  491. }
  492. return retval;
  493. }
  494. struct sock *__vsock_create(struct net *net,
  495. struct socket *sock,
  496. struct sock *parent,
  497. gfp_t priority,
  498. unsigned short type,
  499. int kern)
  500. {
  501. struct sock *sk;
  502. struct vsock_sock *psk;
  503. struct vsock_sock *vsk;
  504. sk = sk_alloc(net, AF_VSOCK, priority, &vsock_proto, kern);
  505. if (!sk)
  506. return NULL;
  507. sock_init_data(sock, sk);
  508. /* sk->sk_type is normally set in sock_init_data, but only if sock is
  509. * non-NULL. We make sure that our sockets always have a type by
  510. * setting it here if needed.
  511. */
  512. if (!sock)
  513. sk->sk_type = type;
  514. vsk = vsock_sk(sk);
  515. vsock_addr_init(&vsk->local_addr, VMADDR_CID_ANY, VMADDR_PORT_ANY);
  516. vsock_addr_init(&vsk->remote_addr, VMADDR_CID_ANY, VMADDR_PORT_ANY);
  517. sk->sk_destruct = vsock_sk_destruct;
  518. sk->sk_backlog_rcv = vsock_queue_rcv_skb;
  519. sk->sk_state = 0;
  520. sock_reset_flag(sk, SOCK_DONE);
  521. INIT_LIST_HEAD(&vsk->bound_table);
  522. INIT_LIST_HEAD(&vsk->connected_table);
  523. vsk->listener = NULL;
  524. INIT_LIST_HEAD(&vsk->pending_links);
  525. INIT_LIST_HEAD(&vsk->accept_queue);
  526. vsk->rejected = false;
  527. vsk->sent_request = false;
  528. vsk->ignore_connecting_rst = false;
  529. vsk->peer_shutdown = 0;
  530. psk = parent ? vsock_sk(parent) : NULL;
  531. if (parent) {
  532. vsk->trusted = psk->trusted;
  533. vsk->owner = get_cred(psk->owner);
  534. vsk->connect_timeout = psk->connect_timeout;
  535. } else {
  536. vsk->trusted = capable(CAP_NET_ADMIN);
  537. vsk->owner = get_current_cred();
  538. vsk->connect_timeout = VSOCK_DEFAULT_CONNECT_TIMEOUT;
  539. }
  540. if (transport->init(vsk, psk) < 0) {
  541. sk_free(sk);
  542. return NULL;
  543. }
  544. if (sock)
  545. vsock_insert_unbound(vsk);
  546. return sk;
  547. }
  548. EXPORT_SYMBOL_GPL(__vsock_create);
  549. static void __vsock_release(struct sock *sk)
  550. {
  551. if (sk) {
  552. struct sk_buff *skb;
  553. struct sock *pending;
  554. struct vsock_sock *vsk;
  555. vsk = vsock_sk(sk);
  556. pending = NULL; /* Compiler warning. */
  557. transport->release(vsk);
  558. lock_sock(sk);
  559. sock_orphan(sk);
  560. sk->sk_shutdown = SHUTDOWN_MASK;
  561. while ((skb = skb_dequeue(&sk->sk_receive_queue)))
  562. kfree_skb(skb);
  563. /* Clean up any sockets that never were accepted. */
  564. while ((pending = vsock_dequeue_accept(sk)) != NULL) {
  565. __vsock_release(pending);
  566. sock_put(pending);
  567. }
  568. release_sock(sk);
  569. sock_put(sk);
  570. }
  571. }
  572. static void vsock_sk_destruct(struct sock *sk)
  573. {
  574. struct vsock_sock *vsk = vsock_sk(sk);
  575. transport->destruct(vsk);
  576. /* When clearing these addresses, there's no need to set the family and
  577. * possibly register the address family with the kernel.
  578. */
  579. vsock_addr_init(&vsk->local_addr, VMADDR_CID_ANY, VMADDR_PORT_ANY);
  580. vsock_addr_init(&vsk->remote_addr, VMADDR_CID_ANY, VMADDR_PORT_ANY);
  581. put_cred(vsk->owner);
  582. }
  583. static int vsock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
  584. {
  585. int err;
  586. err = sock_queue_rcv_skb(sk, skb);
  587. if (err)
  588. kfree_skb(skb);
  589. return err;
  590. }
  591. s64 vsock_stream_has_data(struct vsock_sock *vsk)
  592. {
  593. return transport->stream_has_data(vsk);
  594. }
  595. EXPORT_SYMBOL_GPL(vsock_stream_has_data);
  596. s64 vsock_stream_has_space(struct vsock_sock *vsk)
  597. {
  598. return transport->stream_has_space(vsk);
  599. }
  600. EXPORT_SYMBOL_GPL(vsock_stream_has_space);
  601. static int vsock_release(struct socket *sock)
  602. {
  603. __vsock_release(sock->sk);
  604. sock->sk = NULL;
  605. sock->state = SS_FREE;
  606. return 0;
  607. }
  608. static int
  609. vsock_bind(struct socket *sock, struct sockaddr *addr, int addr_len)
  610. {
  611. int err;
  612. struct sock *sk;
  613. struct sockaddr_vm *vm_addr;
  614. sk = sock->sk;
  615. if (vsock_addr_cast(addr, addr_len, &vm_addr) != 0)
  616. return -EINVAL;
  617. lock_sock(sk);
  618. err = __vsock_bind(sk, vm_addr);
  619. release_sock(sk);
  620. return err;
  621. }
  622. static int vsock_getname(struct socket *sock,
  623. struct sockaddr *addr, int *addr_len, int peer)
  624. {
  625. int err;
  626. struct sock *sk;
  627. struct vsock_sock *vsk;
  628. struct sockaddr_vm *vm_addr;
  629. sk = sock->sk;
  630. vsk = vsock_sk(sk);
  631. err = 0;
  632. lock_sock(sk);
  633. if (peer) {
  634. if (sock->state != SS_CONNECTED) {
  635. err = -ENOTCONN;
  636. goto out;
  637. }
  638. vm_addr = &vsk->remote_addr;
  639. } else {
  640. vm_addr = &vsk->local_addr;
  641. }
  642. if (!vm_addr) {
  643. err = -EINVAL;
  644. goto out;
  645. }
  646. /* sys_getsockname() and sys_getpeername() pass us a
  647. * MAX_SOCK_ADDR-sized buffer and don't set addr_len. Unfortunately
  648. * that macro is defined in socket.c instead of .h, so we hardcode its
  649. * value here.
  650. */
  651. BUILD_BUG_ON(sizeof(*vm_addr) > 128);
  652. memcpy(addr, vm_addr, sizeof(*vm_addr));
  653. *addr_len = sizeof(*vm_addr);
  654. out:
  655. release_sock(sk);
  656. return err;
  657. }
  658. static int vsock_shutdown(struct socket *sock, int mode)
  659. {
  660. int err;
  661. struct sock *sk;
  662. /* User level uses SHUT_RD (0) and SHUT_WR (1), but the kernel uses
  663. * RCV_SHUTDOWN (1) and SEND_SHUTDOWN (2), so we must increment mode
  664. * here like the other address families do. Note also that the
  665. * increment makes SHUT_RDWR (2) into RCV_SHUTDOWN | SEND_SHUTDOWN (3),
  666. * which is what we want.
  667. */
  668. mode++;
  669. if ((mode & ~SHUTDOWN_MASK) || !mode)
  670. return -EINVAL;
  671. /* If this is a STREAM socket and it is not connected then bail out
  672. * immediately. If it is a DGRAM socket then we must first kick the
  673. * socket so that it wakes up from any sleeping calls, for example
  674. * recv(), and then afterwards return the error.
  675. */
  676. sk = sock->sk;
  677. if (sock->state == SS_UNCONNECTED) {
  678. err = -ENOTCONN;
  679. if (sk->sk_type == SOCK_STREAM)
  680. return err;
  681. } else {
  682. sock->state = SS_DISCONNECTING;
  683. err = 0;
  684. }
  685. /* Receive and send shutdowns are treated alike. */
  686. mode = mode & (RCV_SHUTDOWN | SEND_SHUTDOWN);
  687. if (mode) {
  688. lock_sock(sk);
  689. sk->sk_shutdown |= mode;
  690. sk->sk_state_change(sk);
  691. release_sock(sk);
  692. if (sk->sk_type == SOCK_STREAM) {
  693. sock_reset_flag(sk, SOCK_DONE);
  694. vsock_send_shutdown(sk, mode);
  695. }
  696. }
  697. return err;
  698. }
  699. static unsigned int vsock_poll(struct file *file, struct socket *sock,
  700. poll_table *wait)
  701. {
  702. struct sock *sk;
  703. unsigned int mask;
  704. struct vsock_sock *vsk;
  705. sk = sock->sk;
  706. vsk = vsock_sk(sk);
  707. poll_wait(file, sk_sleep(sk), wait);
  708. mask = 0;
  709. if (sk->sk_err)
  710. /* Signify that there has been an error on this socket. */
  711. mask |= POLLERR;
  712. /* INET sockets treat local write shutdown and peer write shutdown as a
  713. * case of POLLHUP set.
  714. */
  715. if ((sk->sk_shutdown == SHUTDOWN_MASK) ||
  716. ((sk->sk_shutdown & SEND_SHUTDOWN) &&
  717. (vsk->peer_shutdown & SEND_SHUTDOWN))) {
  718. mask |= POLLHUP;
  719. }
  720. if (sk->sk_shutdown & RCV_SHUTDOWN ||
  721. vsk->peer_shutdown & SEND_SHUTDOWN) {
  722. mask |= POLLRDHUP;
  723. }
  724. if (sock->type == SOCK_DGRAM) {
  725. /* For datagram sockets we can read if there is something in
  726. * the queue and write as long as the socket isn't shutdown for
  727. * sending.
  728. */
  729. if (!skb_queue_empty(&sk->sk_receive_queue) ||
  730. (sk->sk_shutdown & RCV_SHUTDOWN)) {
  731. mask |= POLLIN | POLLRDNORM;
  732. }
  733. if (!(sk->sk_shutdown & SEND_SHUTDOWN))
  734. mask |= POLLOUT | POLLWRNORM | POLLWRBAND;
  735. } else if (sock->type == SOCK_STREAM) {
  736. lock_sock(sk);
  737. /* Listening sockets that have connections in their accept
  738. * queue can be read.
  739. */
  740. if (sk->sk_state == VSOCK_SS_LISTEN
  741. && !vsock_is_accept_queue_empty(sk))
  742. mask |= POLLIN | POLLRDNORM;
  743. /* If there is something in the queue then we can read. */
  744. if (transport->stream_is_active(vsk) &&
  745. !(sk->sk_shutdown & RCV_SHUTDOWN)) {
  746. bool data_ready_now = false;
  747. int ret = transport->notify_poll_in(
  748. vsk, 1, &data_ready_now);
  749. if (ret < 0) {
  750. mask |= POLLERR;
  751. } else {
  752. if (data_ready_now)
  753. mask |= POLLIN | POLLRDNORM;
  754. }
  755. }
  756. /* Sockets whose connections have been closed, reset, or
  757. * terminated should also be considered read, and we check the
  758. * shutdown flag for that.
  759. */
  760. if (sk->sk_shutdown & RCV_SHUTDOWN ||
  761. vsk->peer_shutdown & SEND_SHUTDOWN) {
  762. mask |= POLLIN | POLLRDNORM;
  763. }
  764. /* Connected sockets that can produce data can be written. */
  765. if (sk->sk_state == SS_CONNECTED) {
  766. if (!(sk->sk_shutdown & SEND_SHUTDOWN)) {
  767. bool space_avail_now = false;
  768. int ret = transport->notify_poll_out(
  769. vsk, 1, &space_avail_now);
  770. if (ret < 0) {
  771. mask |= POLLERR;
  772. } else {
  773. if (space_avail_now)
  774. /* Remove POLLWRBAND since INET
  775. * sockets are not setting it.
  776. */
  777. mask |= POLLOUT | POLLWRNORM;
  778. }
  779. }
  780. }
  781. /* Simulate INET socket poll behaviors, which sets
  782. * POLLOUT|POLLWRNORM when peer is closed and nothing to read,
  783. * but local send is not shutdown.
  784. */
  785. if (sk->sk_state == SS_UNCONNECTED) {
  786. if (!(sk->sk_shutdown & SEND_SHUTDOWN))
  787. mask |= POLLOUT | POLLWRNORM;
  788. }
  789. release_sock(sk);
  790. }
  791. return mask;
  792. }
  793. static int vsock_dgram_sendmsg(struct socket *sock, struct msghdr *msg,
  794. size_t len)
  795. {
  796. int err;
  797. struct sock *sk;
  798. struct vsock_sock *vsk;
  799. struct sockaddr_vm *remote_addr;
  800. if (msg->msg_flags & MSG_OOB)
  801. return -EOPNOTSUPP;
  802. /* For now, MSG_DONTWAIT is always assumed... */
  803. err = 0;
  804. sk = sock->sk;
  805. vsk = vsock_sk(sk);
  806. lock_sock(sk);
  807. err = vsock_auto_bind(vsk);
  808. if (err)
  809. goto out;
  810. /* If the provided message contains an address, use that. Otherwise
  811. * fall back on the socket's remote handle (if it has been connected).
  812. */
  813. if (msg->msg_name &&
  814. vsock_addr_cast(msg->msg_name, msg->msg_namelen,
  815. &remote_addr) == 0) {
  816. /* Ensure this address is of the right type and is a valid
  817. * destination.
  818. */
  819. if (remote_addr->svm_cid == VMADDR_CID_ANY)
  820. remote_addr->svm_cid = transport->get_local_cid();
  821. if (!vsock_addr_bound(remote_addr)) {
  822. err = -EINVAL;
  823. goto out;
  824. }
  825. } else if (sock->state == SS_CONNECTED) {
  826. remote_addr = &vsk->remote_addr;
  827. if (remote_addr->svm_cid == VMADDR_CID_ANY)
  828. remote_addr->svm_cid = transport->get_local_cid();
  829. /* XXX Should connect() or this function ensure remote_addr is
  830. * bound?
  831. */
  832. if (!vsock_addr_bound(&vsk->remote_addr)) {
  833. err = -EINVAL;
  834. goto out;
  835. }
  836. } else {
  837. err = -EINVAL;
  838. goto out;
  839. }
  840. if (!transport->dgram_allow(remote_addr->svm_cid,
  841. remote_addr->svm_port)) {
  842. err = -EINVAL;
  843. goto out;
  844. }
  845. err = transport->dgram_enqueue(vsk, remote_addr, msg, len);
  846. out:
  847. release_sock(sk);
  848. return err;
  849. }
  850. static int vsock_dgram_connect(struct socket *sock,
  851. struct sockaddr *addr, int addr_len, int flags)
  852. {
  853. int err;
  854. struct sock *sk;
  855. struct vsock_sock *vsk;
  856. struct sockaddr_vm *remote_addr;
  857. sk = sock->sk;
  858. vsk = vsock_sk(sk);
  859. err = vsock_addr_cast(addr, addr_len, &remote_addr);
  860. if (err == -EAFNOSUPPORT && remote_addr->svm_family == AF_UNSPEC) {
  861. lock_sock(sk);
  862. vsock_addr_init(&vsk->remote_addr, VMADDR_CID_ANY,
  863. VMADDR_PORT_ANY);
  864. sock->state = SS_UNCONNECTED;
  865. release_sock(sk);
  866. return 0;
  867. } else if (err != 0)
  868. return -EINVAL;
  869. lock_sock(sk);
  870. err = vsock_auto_bind(vsk);
  871. if (err)
  872. goto out;
  873. if (!transport->dgram_allow(remote_addr->svm_cid,
  874. remote_addr->svm_port)) {
  875. err = -EINVAL;
  876. goto out;
  877. }
  878. memcpy(&vsk->remote_addr, remote_addr, sizeof(vsk->remote_addr));
  879. sock->state = SS_CONNECTED;
  880. out:
  881. release_sock(sk);
  882. return err;
  883. }
  884. static int vsock_dgram_recvmsg(struct socket *sock, struct msghdr *msg,
  885. size_t len, int flags)
  886. {
  887. return transport->dgram_dequeue(vsock_sk(sock->sk), msg, len, flags);
  888. }
  889. static const struct proto_ops vsock_dgram_ops = {
  890. .family = PF_VSOCK,
  891. .owner = THIS_MODULE,
  892. .release = vsock_release,
  893. .bind = vsock_bind,
  894. .connect = vsock_dgram_connect,
  895. .socketpair = sock_no_socketpair,
  896. .accept = sock_no_accept,
  897. .getname = vsock_getname,
  898. .poll = vsock_poll,
  899. .ioctl = sock_no_ioctl,
  900. .listen = sock_no_listen,
  901. .shutdown = vsock_shutdown,
  902. .setsockopt = sock_no_setsockopt,
  903. .getsockopt = sock_no_getsockopt,
  904. .sendmsg = vsock_dgram_sendmsg,
  905. .recvmsg = vsock_dgram_recvmsg,
  906. .mmap = sock_no_mmap,
  907. .sendpage = sock_no_sendpage,
  908. };
  909. static void vsock_connect_timeout(struct work_struct *work)
  910. {
  911. struct sock *sk;
  912. struct vsock_sock *vsk;
  913. vsk = container_of(work, struct vsock_sock, dwork.work);
  914. sk = sk_vsock(vsk);
  915. lock_sock(sk);
  916. if (sk->sk_state == SS_CONNECTING &&
  917. (sk->sk_shutdown != SHUTDOWN_MASK)) {
  918. sk->sk_state = SS_UNCONNECTED;
  919. sk->sk_err = ETIMEDOUT;
  920. sk->sk_error_report(sk);
  921. }
  922. release_sock(sk);
  923. sock_put(sk);
  924. }
  925. static int vsock_stream_connect(struct socket *sock, struct sockaddr *addr,
  926. int addr_len, int flags)
  927. {
  928. int err;
  929. struct sock *sk;
  930. struct vsock_sock *vsk;
  931. struct sockaddr_vm *remote_addr;
  932. long timeout;
  933. DEFINE_WAIT(wait);
  934. err = 0;
  935. sk = sock->sk;
  936. vsk = vsock_sk(sk);
  937. lock_sock(sk);
  938. /* XXX AF_UNSPEC should make us disconnect like AF_INET. */
  939. switch (sock->state) {
  940. case SS_CONNECTED:
  941. err = -EISCONN;
  942. goto out;
  943. case SS_DISCONNECTING:
  944. err = -EINVAL;
  945. goto out;
  946. case SS_CONNECTING:
  947. /* This continues on so we can move sock into the SS_CONNECTED
  948. * state once the connection has completed (at which point err
  949. * will be set to zero also). Otherwise, we will either wait
  950. * for the connection or return -EALREADY should this be a
  951. * non-blocking call.
  952. */
  953. err = -EALREADY;
  954. break;
  955. default:
  956. if ((sk->sk_state == VSOCK_SS_LISTEN) ||
  957. vsock_addr_cast(addr, addr_len, &remote_addr) != 0) {
  958. err = -EINVAL;
  959. goto out;
  960. }
  961. /* The hypervisor and well-known contexts do not have socket
  962. * endpoints.
  963. */
  964. if (!transport->stream_allow(remote_addr->svm_cid,
  965. remote_addr->svm_port)) {
  966. err = -ENETUNREACH;
  967. goto out;
  968. }
  969. /* Set the remote address that we are connecting to. */
  970. memcpy(&vsk->remote_addr, remote_addr,
  971. sizeof(vsk->remote_addr));
  972. err = vsock_auto_bind(vsk);
  973. if (err)
  974. goto out;
  975. sk->sk_state = SS_CONNECTING;
  976. err = transport->connect(vsk);
  977. if (err < 0)
  978. goto out;
  979. /* Mark sock as connecting and set the error code to in
  980. * progress in case this is a non-blocking connect.
  981. */
  982. sock->state = SS_CONNECTING;
  983. err = -EINPROGRESS;
  984. }
  985. /* The receive path will handle all communication until we are able to
  986. * enter the connected state. Here we wait for the connection to be
  987. * completed or a notification of an error.
  988. */
  989. timeout = vsk->connect_timeout;
  990. prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);
  991. while (sk->sk_state != SS_CONNECTED && sk->sk_err == 0) {
  992. if (flags & O_NONBLOCK) {
  993. /* If we're not going to block, we schedule a timeout
  994. * function to generate a timeout on the connection
  995. * attempt, in case the peer doesn't respond in a
  996. * timely manner. We hold on to the socket until the
  997. * timeout fires.
  998. */
  999. sock_hold(sk);
  1000. INIT_DELAYED_WORK(&vsk->dwork,
  1001. vsock_connect_timeout);
  1002. schedule_delayed_work(&vsk->dwork, timeout);
  1003. /* Skip ahead to preserve error code set above. */
  1004. goto out_wait;
  1005. }
  1006. release_sock(sk);
  1007. timeout = schedule_timeout(timeout);
  1008. lock_sock(sk);
  1009. if (signal_pending(current)) {
  1010. err = sock_intr_errno(timeout);
  1011. sk->sk_state = SS_UNCONNECTED;
  1012. sock->state = SS_UNCONNECTED;
  1013. goto out_wait;
  1014. } else if (timeout == 0) {
  1015. err = -ETIMEDOUT;
  1016. sk->sk_state = SS_UNCONNECTED;
  1017. sock->state = SS_UNCONNECTED;
  1018. goto out_wait;
  1019. }
  1020. prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);
  1021. }
  1022. if (sk->sk_err) {
  1023. err = -sk->sk_err;
  1024. sk->sk_state = SS_UNCONNECTED;
  1025. sock->state = SS_UNCONNECTED;
  1026. } else {
  1027. err = 0;
  1028. }
  1029. out_wait:
  1030. finish_wait(sk_sleep(sk), &wait);
  1031. out:
  1032. release_sock(sk);
  1033. return err;
  1034. }
  1035. static int vsock_accept(struct socket *sock, struct socket *newsock, int flags)
  1036. {
  1037. struct sock *listener;
  1038. int err;
  1039. struct sock *connected;
  1040. struct vsock_sock *vconnected;
  1041. long timeout;
  1042. DEFINE_WAIT(wait);
  1043. err = 0;
  1044. listener = sock->sk;
  1045. lock_sock(listener);
  1046. if (sock->type != SOCK_STREAM) {
  1047. err = -EOPNOTSUPP;
  1048. goto out;
  1049. }
  1050. if (listener->sk_state != VSOCK_SS_LISTEN) {
  1051. err = -EINVAL;
  1052. goto out;
  1053. }
  1054. /* Wait for children sockets to appear; these are the new sockets
  1055. * created upon connection establishment.
  1056. */
  1057. timeout = sock_sndtimeo(listener, flags & O_NONBLOCK);
  1058. prepare_to_wait(sk_sleep(listener), &wait, TASK_INTERRUPTIBLE);
  1059. while ((connected = vsock_dequeue_accept(listener)) == NULL &&
  1060. listener->sk_err == 0) {
  1061. release_sock(listener);
  1062. timeout = schedule_timeout(timeout);
  1063. finish_wait(sk_sleep(listener), &wait);
  1064. lock_sock(listener);
  1065. if (signal_pending(current)) {
  1066. err = sock_intr_errno(timeout);
  1067. goto out;
  1068. } else if (timeout == 0) {
  1069. err = -EAGAIN;
  1070. goto out;
  1071. }
  1072. prepare_to_wait(sk_sleep(listener), &wait, TASK_INTERRUPTIBLE);
  1073. }
  1074. finish_wait(sk_sleep(listener), &wait);
  1075. if (listener->sk_err)
  1076. err = -listener->sk_err;
  1077. if (connected) {
  1078. listener->sk_ack_backlog--;
  1079. lock_sock_nested(connected, SINGLE_DEPTH_NESTING);
  1080. vconnected = vsock_sk(connected);
  1081. /* If the listener socket has received an error, then we should
  1082. * reject this socket and return. Note that we simply mark the
  1083. * socket rejected, drop our reference, and let the cleanup
  1084. * function handle the cleanup; the fact that we found it in
  1085. * the listener's accept queue guarantees that the cleanup
  1086. * function hasn't run yet.
  1087. */
  1088. if (err) {
  1089. vconnected->rejected = true;
  1090. } else {
  1091. newsock->state = SS_CONNECTED;
  1092. sock_graft(connected, newsock);
  1093. }
  1094. release_sock(connected);
  1095. sock_put(connected);
  1096. }
  1097. out:
  1098. release_sock(listener);
  1099. return err;
  1100. }
  1101. static int vsock_listen(struct socket *sock, int backlog)
  1102. {
  1103. int err;
  1104. struct sock *sk;
  1105. struct vsock_sock *vsk;
  1106. sk = sock->sk;
  1107. lock_sock(sk);
  1108. if (sock->type != SOCK_STREAM) {
  1109. err = -EOPNOTSUPP;
  1110. goto out;
  1111. }
  1112. if (sock->state != SS_UNCONNECTED) {
  1113. err = -EINVAL;
  1114. goto out;
  1115. }
  1116. vsk = vsock_sk(sk);
  1117. if (!vsock_addr_bound(&vsk->local_addr)) {
  1118. err = -EINVAL;
  1119. goto out;
  1120. }
  1121. sk->sk_max_ack_backlog = backlog;
  1122. sk->sk_state = VSOCK_SS_LISTEN;
  1123. err = 0;
  1124. out:
  1125. release_sock(sk);
  1126. return err;
  1127. }
  1128. static int vsock_stream_setsockopt(struct socket *sock,
  1129. int level,
  1130. int optname,
  1131. char __user *optval,
  1132. unsigned int optlen)
  1133. {
  1134. int err;
  1135. struct sock *sk;
  1136. struct vsock_sock *vsk;
  1137. u64 val;
  1138. if (level != AF_VSOCK)
  1139. return -ENOPROTOOPT;
  1140. #define COPY_IN(_v) \
  1141. do { \
  1142. if (optlen < sizeof(_v)) { \
  1143. err = -EINVAL; \
  1144. goto exit; \
  1145. } \
  1146. if (copy_from_user(&_v, optval, sizeof(_v)) != 0) { \
  1147. err = -EFAULT; \
  1148. goto exit; \
  1149. } \
  1150. } while (0)
  1151. err = 0;
  1152. sk = sock->sk;
  1153. vsk = vsock_sk(sk);
  1154. lock_sock(sk);
  1155. switch (optname) {
  1156. case SO_VM_SOCKETS_BUFFER_SIZE:
  1157. COPY_IN(val);
  1158. transport->set_buffer_size(vsk, val);
  1159. break;
  1160. case SO_VM_SOCKETS_BUFFER_MAX_SIZE:
  1161. COPY_IN(val);
  1162. transport->set_max_buffer_size(vsk, val);
  1163. break;
  1164. case SO_VM_SOCKETS_BUFFER_MIN_SIZE:
  1165. COPY_IN(val);
  1166. transport->set_min_buffer_size(vsk, val);
  1167. break;
  1168. case SO_VM_SOCKETS_CONNECT_TIMEOUT: {
  1169. struct timeval tv;
  1170. COPY_IN(tv);
  1171. if (tv.tv_sec >= 0 && tv.tv_usec < USEC_PER_SEC &&
  1172. tv.tv_sec < (MAX_SCHEDULE_TIMEOUT / HZ - 1)) {
  1173. vsk->connect_timeout = tv.tv_sec * HZ +
  1174. DIV_ROUND_UP(tv.tv_usec, (1000000 / HZ));
  1175. if (vsk->connect_timeout == 0)
  1176. vsk->connect_timeout =
  1177. VSOCK_DEFAULT_CONNECT_TIMEOUT;
  1178. } else {
  1179. err = -ERANGE;
  1180. }
  1181. break;
  1182. }
  1183. default:
  1184. err = -ENOPROTOOPT;
  1185. break;
  1186. }
  1187. #undef COPY_IN
  1188. exit:
  1189. release_sock(sk);
  1190. return err;
  1191. }
  1192. static int vsock_stream_getsockopt(struct socket *sock,
  1193. int level, int optname,
  1194. char __user *optval,
  1195. int __user *optlen)
  1196. {
  1197. int err;
  1198. int len;
  1199. struct sock *sk;
  1200. struct vsock_sock *vsk;
  1201. u64 val;
  1202. if (level != AF_VSOCK)
  1203. return -ENOPROTOOPT;
  1204. err = get_user(len, optlen);
  1205. if (err != 0)
  1206. return err;
  1207. #define COPY_OUT(_v) \
  1208. do { \
  1209. if (len < sizeof(_v)) \
  1210. return -EINVAL; \
  1211. \
  1212. len = sizeof(_v); \
  1213. if (copy_to_user(optval, &_v, len) != 0) \
  1214. return -EFAULT; \
  1215. \
  1216. } while (0)
  1217. err = 0;
  1218. sk = sock->sk;
  1219. vsk = vsock_sk(sk);
  1220. switch (optname) {
  1221. case SO_VM_SOCKETS_BUFFER_SIZE:
  1222. val = transport->get_buffer_size(vsk);
  1223. COPY_OUT(val);
  1224. break;
  1225. case SO_VM_SOCKETS_BUFFER_MAX_SIZE:
  1226. val = transport->get_max_buffer_size(vsk);
  1227. COPY_OUT(val);
  1228. break;
  1229. case SO_VM_SOCKETS_BUFFER_MIN_SIZE:
  1230. val = transport->get_min_buffer_size(vsk);
  1231. COPY_OUT(val);
  1232. break;
  1233. case SO_VM_SOCKETS_CONNECT_TIMEOUT: {
  1234. struct timeval tv;
  1235. tv.tv_sec = vsk->connect_timeout / HZ;
  1236. tv.tv_usec =
  1237. (vsk->connect_timeout -
  1238. tv.tv_sec * HZ) * (1000000 / HZ);
  1239. COPY_OUT(tv);
  1240. break;
  1241. }
  1242. default:
  1243. return -ENOPROTOOPT;
  1244. }
  1245. err = put_user(len, optlen);
  1246. if (err != 0)
  1247. return -EFAULT;
  1248. #undef COPY_OUT
  1249. return 0;
  1250. }
  1251. static int vsock_stream_sendmsg(struct socket *sock, struct msghdr *msg,
  1252. size_t len)
  1253. {
  1254. struct sock *sk;
  1255. struct vsock_sock *vsk;
  1256. ssize_t total_written;
  1257. long timeout;
  1258. int err;
  1259. struct vsock_transport_send_notify_data send_data;
  1260. DEFINE_WAIT(wait);
  1261. sk = sock->sk;
  1262. vsk = vsock_sk(sk);
  1263. total_written = 0;
  1264. err = 0;
  1265. if (msg->msg_flags & MSG_OOB)
  1266. return -EOPNOTSUPP;
  1267. lock_sock(sk);
  1268. /* Callers should not provide a destination with stream sockets. */
  1269. if (msg->msg_namelen) {
  1270. err = sk->sk_state == SS_CONNECTED ? -EISCONN : -EOPNOTSUPP;
  1271. goto out;
  1272. }
  1273. /* Send data only if both sides are not shutdown in the direction. */
  1274. if (sk->sk_shutdown & SEND_SHUTDOWN ||
  1275. vsk->peer_shutdown & RCV_SHUTDOWN) {
  1276. err = -EPIPE;
  1277. goto out;
  1278. }
  1279. if (sk->sk_state != SS_CONNECTED ||
  1280. !vsock_addr_bound(&vsk->local_addr)) {
  1281. err = -ENOTCONN;
  1282. goto out;
  1283. }
  1284. if (!vsock_addr_bound(&vsk->remote_addr)) {
  1285. err = -EDESTADDRREQ;
  1286. goto out;
  1287. }
  1288. /* Wait for room in the produce queue to enqueue our user's data. */
  1289. timeout = sock_sndtimeo(sk, msg->msg_flags & MSG_DONTWAIT);
  1290. err = transport->notify_send_init(vsk, &send_data);
  1291. if (err < 0)
  1292. goto out;
  1293. while (total_written < len) {
  1294. ssize_t written;
  1295. prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);
  1296. while (vsock_stream_has_space(vsk) == 0 &&
  1297. sk->sk_err == 0 &&
  1298. !(sk->sk_shutdown & SEND_SHUTDOWN) &&
  1299. !(vsk->peer_shutdown & RCV_SHUTDOWN)) {
  1300. /* Don't wait for non-blocking sockets. */
  1301. if (timeout == 0) {
  1302. err = -EAGAIN;
  1303. finish_wait(sk_sleep(sk), &wait);
  1304. goto out_err;
  1305. }
  1306. err = transport->notify_send_pre_block(vsk, &send_data);
  1307. if (err < 0) {
  1308. finish_wait(sk_sleep(sk), &wait);
  1309. goto out_err;
  1310. }
  1311. release_sock(sk);
  1312. timeout = schedule_timeout(timeout);
  1313. lock_sock(sk);
  1314. if (signal_pending(current)) {
  1315. err = sock_intr_errno(timeout);
  1316. finish_wait(sk_sleep(sk), &wait);
  1317. goto out_err;
  1318. } else if (timeout == 0) {
  1319. err = -EAGAIN;
  1320. finish_wait(sk_sleep(sk), &wait);
  1321. goto out_err;
  1322. }
  1323. prepare_to_wait(sk_sleep(sk), &wait,
  1324. TASK_INTERRUPTIBLE);
  1325. }
  1326. finish_wait(sk_sleep(sk), &wait);
  1327. /* These checks occur both as part of and after the loop
  1328. * conditional since we need to check before and after
  1329. * sleeping.
  1330. */
  1331. if (sk->sk_err) {
  1332. err = -sk->sk_err;
  1333. goto out_err;
  1334. } else if ((sk->sk_shutdown & SEND_SHUTDOWN) ||
  1335. (vsk->peer_shutdown & RCV_SHUTDOWN)) {
  1336. err = -EPIPE;
  1337. goto out_err;
  1338. }
  1339. err = transport->notify_send_pre_enqueue(vsk, &send_data);
  1340. if (err < 0)
  1341. goto out_err;
  1342. /* Note that enqueue will only write as many bytes as are free
  1343. * in the produce queue, so we don't need to ensure len is
  1344. * smaller than the queue size. It is the caller's
  1345. * responsibility to check how many bytes we were able to send.
  1346. */
  1347. written = transport->stream_enqueue(
  1348. vsk, msg,
  1349. len - total_written);
  1350. if (written < 0) {
  1351. err = -ENOMEM;
  1352. goto out_err;
  1353. }
  1354. total_written += written;
  1355. err = transport->notify_send_post_enqueue(
  1356. vsk, written, &send_data);
  1357. if (err < 0)
  1358. goto out_err;
  1359. }
  1360. out_err:
  1361. if (total_written > 0)
  1362. err = total_written;
  1363. out:
  1364. release_sock(sk);
  1365. return err;
  1366. }
  1367. static int
  1368. vsock_stream_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
  1369. int flags)
  1370. {
  1371. struct sock *sk;
  1372. struct vsock_sock *vsk;
  1373. int err;
  1374. size_t target;
  1375. ssize_t copied;
  1376. long timeout;
  1377. struct vsock_transport_recv_notify_data recv_data;
  1378. DEFINE_WAIT(wait);
  1379. sk = sock->sk;
  1380. vsk = vsock_sk(sk);
  1381. err = 0;
  1382. lock_sock(sk);
  1383. if (sk->sk_state != SS_CONNECTED) {
  1384. /* Recvmsg is supposed to return 0 if a peer performs an
  1385. * orderly shutdown. Differentiate between that case and when a
  1386. * peer has not connected or a local shutdown occured with the
  1387. * SOCK_DONE flag.
  1388. */
  1389. if (sock_flag(sk, SOCK_DONE))
  1390. err = 0;
  1391. else
  1392. err = -ENOTCONN;
  1393. goto out;
  1394. }
  1395. if (flags & MSG_OOB) {
  1396. err = -EOPNOTSUPP;
  1397. goto out;
  1398. }
  1399. /* We don't check peer_shutdown flag here since peer may actually shut
  1400. * down, but there can be data in the queue that a local socket can
  1401. * receive.
  1402. */
  1403. if (sk->sk_shutdown & RCV_SHUTDOWN) {
  1404. err = 0;
  1405. goto out;
  1406. }
  1407. /* It is valid on Linux to pass in a zero-length receive buffer. This
  1408. * is not an error. We may as well bail out now.
  1409. */
  1410. if (!len) {
  1411. err = 0;
  1412. goto out;
  1413. }
  1414. /* We must not copy less than target bytes into the user's buffer
  1415. * before returning successfully, so we wait for the consume queue to
  1416. * have that much data to consume before dequeueing. Note that this
  1417. * makes it impossible to handle cases where target is greater than the
  1418. * queue size.
  1419. */
  1420. target = sock_rcvlowat(sk, flags & MSG_WAITALL, len);
  1421. if (target >= transport->stream_rcvhiwat(vsk)) {
  1422. err = -ENOMEM;
  1423. goto out;
  1424. }
  1425. timeout = sock_rcvtimeo(sk, flags & MSG_DONTWAIT);
  1426. copied = 0;
  1427. err = transport->notify_recv_init(vsk, target, &recv_data);
  1428. if (err < 0)
  1429. goto out;
  1430. while (1) {
  1431. s64 ready;
  1432. prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);
  1433. ready = vsock_stream_has_data(vsk);
  1434. if (ready == 0) {
  1435. if (sk->sk_err != 0 ||
  1436. (sk->sk_shutdown & RCV_SHUTDOWN) ||
  1437. (vsk->peer_shutdown & SEND_SHUTDOWN)) {
  1438. finish_wait(sk_sleep(sk), &wait);
  1439. break;
  1440. }
  1441. /* Don't wait for non-blocking sockets. */
  1442. if (timeout == 0) {
  1443. err = -EAGAIN;
  1444. finish_wait(sk_sleep(sk), &wait);
  1445. break;
  1446. }
  1447. err = transport->notify_recv_pre_block(
  1448. vsk, target, &recv_data);
  1449. if (err < 0) {
  1450. finish_wait(sk_sleep(sk), &wait);
  1451. break;
  1452. }
  1453. release_sock(sk);
  1454. timeout = schedule_timeout(timeout);
  1455. lock_sock(sk);
  1456. if (signal_pending(current)) {
  1457. err = sock_intr_errno(timeout);
  1458. finish_wait(sk_sleep(sk), &wait);
  1459. break;
  1460. } else if (timeout == 0) {
  1461. err = -EAGAIN;
  1462. finish_wait(sk_sleep(sk), &wait);
  1463. break;
  1464. }
  1465. } else {
  1466. ssize_t read;
  1467. finish_wait(sk_sleep(sk), &wait);
  1468. if (ready < 0) {
  1469. /* Invalid queue pair content. XXX This should
  1470. * be changed to a connection reset in a later
  1471. * change.
  1472. */
  1473. err = -ENOMEM;
  1474. goto out;
  1475. }
  1476. err = transport->notify_recv_pre_dequeue(
  1477. vsk, target, &recv_data);
  1478. if (err < 0)
  1479. break;
  1480. read = transport->stream_dequeue(
  1481. vsk, msg,
  1482. len - copied, flags);
  1483. if (read < 0) {
  1484. err = -ENOMEM;
  1485. break;
  1486. }
  1487. copied += read;
  1488. err = transport->notify_recv_post_dequeue(
  1489. vsk, target, read,
  1490. !(flags & MSG_PEEK), &recv_data);
  1491. if (err < 0)
  1492. goto out;
  1493. if (read >= target || flags & MSG_PEEK)
  1494. break;
  1495. target -= read;
  1496. }
  1497. }
  1498. if (sk->sk_err)
  1499. err = -sk->sk_err;
  1500. else if (sk->sk_shutdown & RCV_SHUTDOWN)
  1501. err = 0;
  1502. if (copied > 0)
  1503. err = copied;
  1504. out:
  1505. release_sock(sk);
  1506. return err;
  1507. }
  1508. static const struct proto_ops vsock_stream_ops = {
  1509. .family = PF_VSOCK,
  1510. .owner = THIS_MODULE,
  1511. .release = vsock_release,
  1512. .bind = vsock_bind,
  1513. .connect = vsock_stream_connect,
  1514. .socketpair = sock_no_socketpair,
  1515. .accept = vsock_accept,
  1516. .getname = vsock_getname,
  1517. .poll = vsock_poll,
  1518. .ioctl = sock_no_ioctl,
  1519. .listen = vsock_listen,
  1520. .shutdown = vsock_shutdown,
  1521. .setsockopt = vsock_stream_setsockopt,
  1522. .getsockopt = vsock_stream_getsockopt,
  1523. .sendmsg = vsock_stream_sendmsg,
  1524. .recvmsg = vsock_stream_recvmsg,
  1525. .mmap = sock_no_mmap,
  1526. .sendpage = sock_no_sendpage,
  1527. };
  1528. static int vsock_create(struct net *net, struct socket *sock,
  1529. int protocol, int kern)
  1530. {
  1531. if (!sock)
  1532. return -EINVAL;
  1533. if (protocol && protocol != PF_VSOCK)
  1534. return -EPROTONOSUPPORT;
  1535. switch (sock->type) {
  1536. case SOCK_DGRAM:
  1537. sock->ops = &vsock_dgram_ops;
  1538. break;
  1539. case SOCK_STREAM:
  1540. sock->ops = &vsock_stream_ops;
  1541. break;
  1542. default:
  1543. return -ESOCKTNOSUPPORT;
  1544. }
  1545. sock->state = SS_UNCONNECTED;
  1546. return __vsock_create(net, sock, NULL, GFP_KERNEL, 0, kern) ? 0 : -ENOMEM;
  1547. }
  1548. static const struct net_proto_family vsock_family_ops = {
  1549. .family = AF_VSOCK,
  1550. .create = vsock_create,
  1551. .owner = THIS_MODULE,
  1552. };
  1553. static long vsock_dev_do_ioctl(struct file *filp,
  1554. unsigned int cmd, void __user *ptr)
  1555. {
  1556. u32 __user *p = ptr;
  1557. int retval = 0;
  1558. switch (cmd) {
  1559. case IOCTL_VM_SOCKETS_GET_LOCAL_CID:
  1560. if (put_user(transport->get_local_cid(), p) != 0)
  1561. retval = -EFAULT;
  1562. break;
  1563. default:
  1564. pr_err("Unknown ioctl %d\n", cmd);
  1565. retval = -EINVAL;
  1566. }
  1567. return retval;
  1568. }
  1569. static long vsock_dev_ioctl(struct file *filp,
  1570. unsigned int cmd, unsigned long arg)
  1571. {
  1572. return vsock_dev_do_ioctl(filp, cmd, (void __user *)arg);
  1573. }
  1574. #ifdef CONFIG_COMPAT
  1575. static long vsock_dev_compat_ioctl(struct file *filp,
  1576. unsigned int cmd, unsigned long arg)
  1577. {
  1578. return vsock_dev_do_ioctl(filp, cmd, compat_ptr(arg));
  1579. }
  1580. #endif
  1581. static const struct file_operations vsock_device_ops = {
  1582. .owner = THIS_MODULE,
  1583. .unlocked_ioctl = vsock_dev_ioctl,
  1584. #ifdef CONFIG_COMPAT
  1585. .compat_ioctl = vsock_dev_compat_ioctl,
  1586. #endif
  1587. .open = nonseekable_open,
  1588. };
  1589. static struct miscdevice vsock_device = {
  1590. .name = "vsock",
  1591. .fops = &vsock_device_ops,
  1592. };
  1593. int __vsock_core_init(const struct vsock_transport *t, struct module *owner)
  1594. {
  1595. int err = mutex_lock_interruptible(&vsock_register_mutex);
  1596. if (err)
  1597. return err;
  1598. if (transport) {
  1599. err = -EBUSY;
  1600. goto err_busy;
  1601. }
  1602. /* Transport must be the owner of the protocol so that it can't
  1603. * unload while there are open sockets.
  1604. */
  1605. vsock_proto.owner = owner;
  1606. transport = t;
  1607. vsock_init_tables();
  1608. vsock_device.minor = MISC_DYNAMIC_MINOR;
  1609. err = misc_register(&vsock_device);
  1610. if (err) {
  1611. pr_err("Failed to register misc device\n");
  1612. goto err_reset_transport;
  1613. }
  1614. err = proto_register(&vsock_proto, 1); /* we want our slab */
  1615. if (err) {
  1616. pr_err("Cannot register vsock protocol\n");
  1617. goto err_deregister_misc;
  1618. }
  1619. err = sock_register(&vsock_family_ops);
  1620. if (err) {
  1621. pr_err("could not register af_vsock (%d) address family: %d\n",
  1622. AF_VSOCK, err);
  1623. goto err_unregister_proto;
  1624. }
  1625. mutex_unlock(&vsock_register_mutex);
  1626. return 0;
  1627. err_unregister_proto:
  1628. proto_unregister(&vsock_proto);
  1629. err_deregister_misc:
  1630. misc_deregister(&vsock_device);
  1631. err_reset_transport:
  1632. transport = NULL;
  1633. err_busy:
  1634. mutex_unlock(&vsock_register_mutex);
  1635. return err;
  1636. }
  1637. EXPORT_SYMBOL_GPL(__vsock_core_init);
  1638. void vsock_core_exit(void)
  1639. {
  1640. mutex_lock(&vsock_register_mutex);
  1641. misc_deregister(&vsock_device);
  1642. sock_unregister(AF_VSOCK);
  1643. proto_unregister(&vsock_proto);
  1644. /* We do not want the assignment below re-ordered. */
  1645. mb();
  1646. transport = NULL;
  1647. mutex_unlock(&vsock_register_mutex);
  1648. }
  1649. EXPORT_SYMBOL_GPL(vsock_core_exit);
  1650. const struct vsock_transport *vsock_core_get_transport(void)
  1651. {
  1652. /* vsock_register_mutex not taken since only the transport uses this
  1653. * function and only while registered.
  1654. */
  1655. return transport;
  1656. }
  1657. EXPORT_SYMBOL_GPL(vsock_core_get_transport);
  1658. MODULE_AUTHOR("VMware, Inc.");
  1659. MODULE_DESCRIPTION("VMware Virtual Socket Family");
  1660. MODULE_VERSION("1.0.2.0-k");
  1661. MODULE_LICENSE("GPL v2");