svc.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693
  1. // SPDX-License-Identifier: GPL-2.0
  2. /* net/atm/svc.c - ATM SVC sockets */
  3. /* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */
  4. #define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__
  5. #include <linux/string.h>
  6. #include <linux/net.h> /* struct socket, struct proto_ops */
  7. #include <linux/errno.h> /* error codes */
  8. #include <linux/kernel.h> /* printk */
  9. #include <linux/skbuff.h>
  10. #include <linux/wait.h>
  11. #include <linux/sched/signal.h>
  12. #include <linux/fcntl.h> /* O_NONBLOCK */
  13. #include <linux/init.h>
  14. #include <linux/atm.h> /* ATM stuff */
  15. #include <linux/atmsap.h>
  16. #include <linux/atmsvc.h>
  17. #include <linux/atmdev.h>
  18. #include <linux/bitops.h>
  19. #include <net/sock.h> /* for sock_no_* */
  20. #include <linux/uaccess.h>
  21. #include <linux/export.h>
  22. #include "resources.h"
  23. #include "common.h" /* common for PVCs and SVCs */
  24. #include "signaling.h"
  25. #include "addr.h"
  26. static int svc_create(struct net *net, struct socket *sock, int protocol,
  27. int kern);
  28. /*
  29. * Note: since all this is still nicely synchronized with the signaling demon,
  30. * there's no need to protect sleep loops with clis. If signaling is
  31. * moved into the kernel, that would change.
  32. */
  33. static int svc_shutdown(struct socket *sock, int how)
  34. {
  35. return 0;
  36. }
  37. static void svc_disconnect(struct atm_vcc *vcc)
  38. {
  39. DEFINE_WAIT(wait);
  40. struct sk_buff *skb;
  41. struct sock *sk = sk_atm(vcc);
  42. pr_debug("%p\n", vcc);
  43. if (test_bit(ATM_VF_REGIS, &vcc->flags)) {
  44. sigd_enq(vcc, as_close, NULL, NULL, NULL);
  45. for (;;) {
  46. prepare_to_wait(sk_sleep(sk), &wait, TASK_UNINTERRUPTIBLE);
  47. if (test_bit(ATM_VF_RELEASED, &vcc->flags) || !sigd)
  48. break;
  49. schedule();
  50. }
  51. finish_wait(sk_sleep(sk), &wait);
  52. }
  53. /* beware - socket is still in use by atmsigd until the last
  54. as_indicate has been answered */
  55. while ((skb = skb_dequeue(&sk->sk_receive_queue)) != NULL) {
  56. atm_return(vcc, skb->truesize);
  57. pr_debug("LISTEN REL\n");
  58. sigd_enq2(NULL, as_reject, vcc, NULL, NULL, &vcc->qos, 0);
  59. dev_kfree_skb(skb);
  60. }
  61. clear_bit(ATM_VF_REGIS, &vcc->flags);
  62. /* ... may retry later */
  63. }
  64. static int svc_release(struct socket *sock)
  65. {
  66. struct sock *sk = sock->sk;
  67. struct atm_vcc *vcc;
  68. if (sk) {
  69. vcc = ATM_SD(sock);
  70. pr_debug("%p\n", vcc);
  71. clear_bit(ATM_VF_READY, &vcc->flags);
  72. /*
  73. * VCC pointer is used as a reference,
  74. * so we must not free it (thereby subjecting it to re-use)
  75. * before all pending connections are closed
  76. */
  77. svc_disconnect(vcc);
  78. vcc_release(sock);
  79. }
  80. return 0;
  81. }
  82. static int svc_bind(struct socket *sock, struct sockaddr *sockaddr,
  83. int sockaddr_len)
  84. {
  85. DEFINE_WAIT(wait);
  86. struct sock *sk = sock->sk;
  87. struct sockaddr_atmsvc *addr;
  88. struct atm_vcc *vcc;
  89. int error;
  90. if (sockaddr_len != sizeof(struct sockaddr_atmsvc))
  91. return -EINVAL;
  92. lock_sock(sk);
  93. if (sock->state == SS_CONNECTED) {
  94. error = -EISCONN;
  95. goto out;
  96. }
  97. if (sock->state != SS_UNCONNECTED) {
  98. error = -EINVAL;
  99. goto out;
  100. }
  101. vcc = ATM_SD(sock);
  102. addr = (struct sockaddr_atmsvc *) sockaddr;
  103. if (addr->sas_family != AF_ATMSVC) {
  104. error = -EAFNOSUPPORT;
  105. goto out;
  106. }
  107. clear_bit(ATM_VF_BOUND, &vcc->flags);
  108. /* failing rebind will kill old binding */
  109. /* @@@ check memory (de)allocation on rebind */
  110. if (!test_bit(ATM_VF_HASQOS, &vcc->flags)) {
  111. error = -EBADFD;
  112. goto out;
  113. }
  114. vcc->local = *addr;
  115. set_bit(ATM_VF_WAITING, &vcc->flags);
  116. sigd_enq(vcc, as_bind, NULL, NULL, &vcc->local);
  117. for (;;) {
  118. prepare_to_wait(sk_sleep(sk), &wait, TASK_UNINTERRUPTIBLE);
  119. if (!test_bit(ATM_VF_WAITING, &vcc->flags) || !sigd)
  120. break;
  121. schedule();
  122. }
  123. finish_wait(sk_sleep(sk), &wait);
  124. clear_bit(ATM_VF_REGIS, &vcc->flags); /* doesn't count */
  125. if (!sigd) {
  126. error = -EUNATCH;
  127. goto out;
  128. }
  129. if (!sk->sk_err)
  130. set_bit(ATM_VF_BOUND, &vcc->flags);
  131. error = -sk->sk_err;
  132. out:
  133. release_sock(sk);
  134. return error;
  135. }
  136. static int svc_connect(struct socket *sock, struct sockaddr *sockaddr,
  137. int sockaddr_len, int flags)
  138. {
  139. DEFINE_WAIT(wait);
  140. struct sock *sk = sock->sk;
  141. struct sockaddr_atmsvc *addr;
  142. struct atm_vcc *vcc = ATM_SD(sock);
  143. int error;
  144. pr_debug("%p\n", vcc);
  145. lock_sock(sk);
  146. if (sockaddr_len != sizeof(struct sockaddr_atmsvc)) {
  147. error = -EINVAL;
  148. goto out;
  149. }
  150. switch (sock->state) {
  151. default:
  152. error = -EINVAL;
  153. goto out;
  154. case SS_CONNECTED:
  155. error = -EISCONN;
  156. goto out;
  157. case SS_CONNECTING:
  158. if (test_bit(ATM_VF_WAITING, &vcc->flags)) {
  159. error = -EALREADY;
  160. goto out;
  161. }
  162. sock->state = SS_UNCONNECTED;
  163. if (sk->sk_err) {
  164. error = -sk->sk_err;
  165. goto out;
  166. }
  167. break;
  168. case SS_UNCONNECTED:
  169. addr = (struct sockaddr_atmsvc *) sockaddr;
  170. if (addr->sas_family != AF_ATMSVC) {
  171. error = -EAFNOSUPPORT;
  172. goto out;
  173. }
  174. if (!test_bit(ATM_VF_HASQOS, &vcc->flags)) {
  175. error = -EBADFD;
  176. goto out;
  177. }
  178. if (vcc->qos.txtp.traffic_class == ATM_ANYCLASS ||
  179. vcc->qos.rxtp.traffic_class == ATM_ANYCLASS) {
  180. error = -EINVAL;
  181. goto out;
  182. }
  183. if (!vcc->qos.txtp.traffic_class &&
  184. !vcc->qos.rxtp.traffic_class) {
  185. error = -EINVAL;
  186. goto out;
  187. }
  188. vcc->remote = *addr;
  189. set_bit(ATM_VF_WAITING, &vcc->flags);
  190. sigd_enq(vcc, as_connect, NULL, NULL, &vcc->remote);
  191. if (flags & O_NONBLOCK) {
  192. sock->state = SS_CONNECTING;
  193. error = -EINPROGRESS;
  194. goto out;
  195. }
  196. error = 0;
  197. prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);
  198. while (test_bit(ATM_VF_WAITING, &vcc->flags) && sigd) {
  199. schedule();
  200. if (!signal_pending(current)) {
  201. prepare_to_wait(sk_sleep(sk), &wait,
  202. TASK_INTERRUPTIBLE);
  203. continue;
  204. }
  205. pr_debug("*ABORT*\n");
  206. /*
  207. * This is tricky:
  208. * Kernel ---close--> Demon
  209. * Kernel <--close--- Demon
  210. * or
  211. * Kernel ---close--> Demon
  212. * Kernel <--error--- Demon
  213. * or
  214. * Kernel ---close--> Demon
  215. * Kernel <--okay---- Demon
  216. * Kernel <--close--- Demon
  217. */
  218. sigd_enq(vcc, as_close, NULL, NULL, NULL);
  219. while (test_bit(ATM_VF_WAITING, &vcc->flags) && sigd) {
  220. prepare_to_wait(sk_sleep(sk), &wait,
  221. TASK_INTERRUPTIBLE);
  222. schedule();
  223. }
  224. if (!sk->sk_err)
  225. while (!test_bit(ATM_VF_RELEASED, &vcc->flags) &&
  226. sigd) {
  227. prepare_to_wait(sk_sleep(sk), &wait,
  228. TASK_INTERRUPTIBLE);
  229. schedule();
  230. }
  231. clear_bit(ATM_VF_REGIS, &vcc->flags);
  232. clear_bit(ATM_VF_RELEASED, &vcc->flags);
  233. clear_bit(ATM_VF_CLOSE, &vcc->flags);
  234. /* we're gone now but may connect later */
  235. error = -EINTR;
  236. break;
  237. }
  238. finish_wait(sk_sleep(sk), &wait);
  239. if (error)
  240. goto out;
  241. if (!sigd) {
  242. error = -EUNATCH;
  243. goto out;
  244. }
  245. if (sk->sk_err) {
  246. error = -sk->sk_err;
  247. goto out;
  248. }
  249. }
  250. vcc->qos.txtp.max_pcr = SELECT_TOP_PCR(vcc->qos.txtp);
  251. vcc->qos.txtp.pcr = 0;
  252. vcc->qos.txtp.min_pcr = 0;
  253. error = vcc_connect(sock, vcc->itf, vcc->vpi, vcc->vci);
  254. if (!error)
  255. sock->state = SS_CONNECTED;
  256. else
  257. (void)svc_disconnect(vcc);
  258. out:
  259. release_sock(sk);
  260. return error;
  261. }
  262. static int svc_listen(struct socket *sock, int backlog)
  263. {
  264. DEFINE_WAIT(wait);
  265. struct sock *sk = sock->sk;
  266. struct atm_vcc *vcc = ATM_SD(sock);
  267. int error;
  268. pr_debug("%p\n", vcc);
  269. lock_sock(sk);
  270. /* let server handle listen on unbound sockets */
  271. if (test_bit(ATM_VF_SESSION, &vcc->flags)) {
  272. error = -EINVAL;
  273. goto out;
  274. }
  275. if (test_bit(ATM_VF_LISTEN, &vcc->flags)) {
  276. error = -EADDRINUSE;
  277. goto out;
  278. }
  279. set_bit(ATM_VF_WAITING, &vcc->flags);
  280. sigd_enq(vcc, as_listen, NULL, NULL, &vcc->local);
  281. for (;;) {
  282. prepare_to_wait(sk_sleep(sk), &wait, TASK_UNINTERRUPTIBLE);
  283. if (!test_bit(ATM_VF_WAITING, &vcc->flags) || !sigd)
  284. break;
  285. schedule();
  286. }
  287. finish_wait(sk_sleep(sk), &wait);
  288. if (!sigd) {
  289. error = -EUNATCH;
  290. goto out;
  291. }
  292. set_bit(ATM_VF_LISTEN, &vcc->flags);
  293. vcc_insert_socket(sk);
  294. sk->sk_max_ack_backlog = backlog > 0 ? backlog : ATM_BACKLOG_DEFAULT;
  295. error = -sk->sk_err;
  296. out:
  297. release_sock(sk);
  298. return error;
  299. }
  300. static int svc_accept(struct socket *sock, struct socket *newsock, int flags,
  301. bool kern)
  302. {
  303. struct sock *sk = sock->sk;
  304. struct sk_buff *skb;
  305. struct atmsvc_msg *msg;
  306. struct atm_vcc *old_vcc = ATM_SD(sock);
  307. struct atm_vcc *new_vcc;
  308. int error;
  309. lock_sock(sk);
  310. error = svc_create(sock_net(sk), newsock, 0, kern);
  311. if (error)
  312. goto out;
  313. new_vcc = ATM_SD(newsock);
  314. pr_debug("%p -> %p\n", old_vcc, new_vcc);
  315. while (1) {
  316. DEFINE_WAIT(wait);
  317. prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);
  318. while (!(skb = skb_dequeue(&sk->sk_receive_queue)) &&
  319. sigd) {
  320. if (test_bit(ATM_VF_RELEASED, &old_vcc->flags))
  321. break;
  322. if (test_bit(ATM_VF_CLOSE, &old_vcc->flags)) {
  323. error = -sk->sk_err;
  324. break;
  325. }
  326. if (flags & O_NONBLOCK) {
  327. error = -EAGAIN;
  328. break;
  329. }
  330. release_sock(sk);
  331. schedule();
  332. lock_sock(sk);
  333. if (signal_pending(current)) {
  334. error = -ERESTARTSYS;
  335. break;
  336. }
  337. prepare_to_wait(sk_sleep(sk), &wait,
  338. TASK_INTERRUPTIBLE);
  339. }
  340. finish_wait(sk_sleep(sk), &wait);
  341. if (error)
  342. goto out;
  343. if (!skb) {
  344. error = -EUNATCH;
  345. goto out;
  346. }
  347. msg = (struct atmsvc_msg *)skb->data;
  348. new_vcc->qos = msg->qos;
  349. set_bit(ATM_VF_HASQOS, &new_vcc->flags);
  350. new_vcc->remote = msg->svc;
  351. new_vcc->local = msg->local;
  352. new_vcc->sap = msg->sap;
  353. error = vcc_connect(newsock, msg->pvc.sap_addr.itf,
  354. msg->pvc.sap_addr.vpi,
  355. msg->pvc.sap_addr.vci);
  356. dev_kfree_skb(skb);
  357. sk->sk_ack_backlog--;
  358. if (error) {
  359. sigd_enq2(NULL, as_reject, old_vcc, NULL, NULL,
  360. &old_vcc->qos, error);
  361. error = error == -EAGAIN ? -EBUSY : error;
  362. goto out;
  363. }
  364. /* wait should be short, so we ignore the non-blocking flag */
  365. set_bit(ATM_VF_WAITING, &new_vcc->flags);
  366. sigd_enq(new_vcc, as_accept, old_vcc, NULL, NULL);
  367. for (;;) {
  368. prepare_to_wait(sk_sleep(sk_atm(new_vcc)), &wait,
  369. TASK_UNINTERRUPTIBLE);
  370. if (!test_bit(ATM_VF_WAITING, &new_vcc->flags) || !sigd)
  371. break;
  372. release_sock(sk);
  373. schedule();
  374. lock_sock(sk);
  375. }
  376. finish_wait(sk_sleep(sk_atm(new_vcc)), &wait);
  377. if (!sigd) {
  378. error = -EUNATCH;
  379. goto out;
  380. }
  381. if (!sk_atm(new_vcc)->sk_err)
  382. break;
  383. if (sk_atm(new_vcc)->sk_err != ERESTARTSYS) {
  384. error = -sk_atm(new_vcc)->sk_err;
  385. goto out;
  386. }
  387. }
  388. newsock->state = SS_CONNECTED;
  389. out:
  390. release_sock(sk);
  391. return error;
  392. }
  393. static int svc_getname(struct socket *sock, struct sockaddr *sockaddr,
  394. int *sockaddr_len, int peer)
  395. {
  396. struct sockaddr_atmsvc *addr;
  397. *sockaddr_len = sizeof(struct sockaddr_atmsvc);
  398. addr = (struct sockaddr_atmsvc *) sockaddr;
  399. memcpy(addr, peer ? &ATM_SD(sock)->remote : &ATM_SD(sock)->local,
  400. sizeof(struct sockaddr_atmsvc));
  401. return 0;
  402. }
  403. int svc_change_qos(struct atm_vcc *vcc, struct atm_qos *qos)
  404. {
  405. struct sock *sk = sk_atm(vcc);
  406. DEFINE_WAIT(wait);
  407. set_bit(ATM_VF_WAITING, &vcc->flags);
  408. sigd_enq2(vcc, as_modify, NULL, NULL, &vcc->local, qos, 0);
  409. for (;;) {
  410. prepare_to_wait(sk_sleep(sk), &wait, TASK_UNINTERRUPTIBLE);
  411. if (!test_bit(ATM_VF_WAITING, &vcc->flags) ||
  412. test_bit(ATM_VF_RELEASED, &vcc->flags) || !sigd) {
  413. break;
  414. }
  415. schedule();
  416. }
  417. finish_wait(sk_sleep(sk), &wait);
  418. if (!sigd)
  419. return -EUNATCH;
  420. return -sk->sk_err;
  421. }
  422. static int svc_setsockopt(struct socket *sock, int level, int optname,
  423. char __user *optval, unsigned int optlen)
  424. {
  425. struct sock *sk = sock->sk;
  426. struct atm_vcc *vcc = ATM_SD(sock);
  427. int value, error = 0;
  428. lock_sock(sk);
  429. switch (optname) {
  430. case SO_ATMSAP:
  431. if (level != SOL_ATM || optlen != sizeof(struct atm_sap)) {
  432. error = -EINVAL;
  433. goto out;
  434. }
  435. if (copy_from_user(&vcc->sap, optval, optlen)) {
  436. error = -EFAULT;
  437. goto out;
  438. }
  439. set_bit(ATM_VF_HASSAP, &vcc->flags);
  440. break;
  441. case SO_MULTIPOINT:
  442. if (level != SOL_ATM || optlen != sizeof(int)) {
  443. error = -EINVAL;
  444. goto out;
  445. }
  446. if (get_user(value, (int __user *)optval)) {
  447. error = -EFAULT;
  448. goto out;
  449. }
  450. if (value == 1)
  451. set_bit(ATM_VF_SESSION, &vcc->flags);
  452. else if (value == 0)
  453. clear_bit(ATM_VF_SESSION, &vcc->flags);
  454. else
  455. error = -EINVAL;
  456. break;
  457. default:
  458. error = vcc_setsockopt(sock, level, optname, optval, optlen);
  459. }
  460. out:
  461. release_sock(sk);
  462. return error;
  463. }
  464. static int svc_getsockopt(struct socket *sock, int level, int optname,
  465. char __user *optval, int __user *optlen)
  466. {
  467. struct sock *sk = sock->sk;
  468. int error = 0, len;
  469. lock_sock(sk);
  470. if (!__SO_LEVEL_MATCH(optname, level) || optname != SO_ATMSAP) {
  471. error = vcc_getsockopt(sock, level, optname, optval, optlen);
  472. goto out;
  473. }
  474. if (get_user(len, optlen)) {
  475. error = -EFAULT;
  476. goto out;
  477. }
  478. if (len != sizeof(struct atm_sap)) {
  479. error = -EINVAL;
  480. goto out;
  481. }
  482. if (copy_to_user(optval, &ATM_SD(sock)->sap, sizeof(struct atm_sap))) {
  483. error = -EFAULT;
  484. goto out;
  485. }
  486. out:
  487. release_sock(sk);
  488. return error;
  489. }
  490. static int svc_addparty(struct socket *sock, struct sockaddr *sockaddr,
  491. int sockaddr_len, int flags)
  492. {
  493. DEFINE_WAIT(wait);
  494. struct sock *sk = sock->sk;
  495. struct atm_vcc *vcc = ATM_SD(sock);
  496. int error;
  497. lock_sock(sk);
  498. set_bit(ATM_VF_WAITING, &vcc->flags);
  499. sigd_enq(vcc, as_addparty, NULL, NULL,
  500. (struct sockaddr_atmsvc *) sockaddr);
  501. if (flags & O_NONBLOCK) {
  502. error = -EINPROGRESS;
  503. goto out;
  504. }
  505. pr_debug("added wait queue\n");
  506. for (;;) {
  507. prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);
  508. if (!test_bit(ATM_VF_WAITING, &vcc->flags) || !sigd)
  509. break;
  510. schedule();
  511. }
  512. finish_wait(sk_sleep(sk), &wait);
  513. error = -xchg(&sk->sk_err_soft, 0);
  514. out:
  515. release_sock(sk);
  516. return error;
  517. }
  518. static int svc_dropparty(struct socket *sock, int ep_ref)
  519. {
  520. DEFINE_WAIT(wait);
  521. struct sock *sk = sock->sk;
  522. struct atm_vcc *vcc = ATM_SD(sock);
  523. int error;
  524. lock_sock(sk);
  525. set_bit(ATM_VF_WAITING, &vcc->flags);
  526. sigd_enq2(vcc, as_dropparty, NULL, NULL, NULL, NULL, ep_ref);
  527. for (;;) {
  528. prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);
  529. if (!test_bit(ATM_VF_WAITING, &vcc->flags) || !sigd)
  530. break;
  531. schedule();
  532. }
  533. finish_wait(sk_sleep(sk), &wait);
  534. if (!sigd) {
  535. error = -EUNATCH;
  536. goto out;
  537. }
  538. error = -xchg(&sk->sk_err_soft, 0);
  539. out:
  540. release_sock(sk);
  541. return error;
  542. }
  543. static int svc_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
  544. {
  545. int error, ep_ref;
  546. struct sockaddr_atmsvc sa;
  547. struct atm_vcc *vcc = ATM_SD(sock);
  548. switch (cmd) {
  549. case ATM_ADDPARTY:
  550. if (!test_bit(ATM_VF_SESSION, &vcc->flags))
  551. return -EINVAL;
  552. if (copy_from_user(&sa, (void __user *) arg, sizeof(sa)))
  553. return -EFAULT;
  554. error = svc_addparty(sock, (struct sockaddr *)&sa, sizeof(sa),
  555. 0);
  556. break;
  557. case ATM_DROPPARTY:
  558. if (!test_bit(ATM_VF_SESSION, &vcc->flags))
  559. return -EINVAL;
  560. if (copy_from_user(&ep_ref, (void __user *) arg, sizeof(int)))
  561. return -EFAULT;
  562. error = svc_dropparty(sock, ep_ref);
  563. break;
  564. default:
  565. error = vcc_ioctl(sock, cmd, arg);
  566. }
  567. return error;
  568. }
  569. #ifdef CONFIG_COMPAT
  570. static int svc_compat_ioctl(struct socket *sock, unsigned int cmd,
  571. unsigned long arg)
  572. {
  573. /* The definition of ATM_ADDPARTY uses the size of struct atm_iobuf.
  574. But actually it takes a struct sockaddr_atmsvc, which doesn't need
  575. compat handling. So all we have to do is fix up cmd... */
  576. if (cmd == COMPAT_ATM_ADDPARTY)
  577. cmd = ATM_ADDPARTY;
  578. if (cmd == ATM_ADDPARTY || cmd == ATM_DROPPARTY)
  579. return svc_ioctl(sock, cmd, arg);
  580. else
  581. return vcc_compat_ioctl(sock, cmd, arg);
  582. }
  583. #endif /* CONFIG_COMPAT */
  584. static const struct proto_ops svc_proto_ops = {
  585. .family = PF_ATMSVC,
  586. .owner = THIS_MODULE,
  587. .release = svc_release,
  588. .bind = svc_bind,
  589. .connect = svc_connect,
  590. .socketpair = sock_no_socketpair,
  591. .accept = svc_accept,
  592. .getname = svc_getname,
  593. .poll = vcc_poll,
  594. .ioctl = svc_ioctl,
  595. #ifdef CONFIG_COMPAT
  596. .compat_ioctl = svc_compat_ioctl,
  597. #endif
  598. .listen = svc_listen,
  599. .shutdown = svc_shutdown,
  600. .setsockopt = svc_setsockopt,
  601. .getsockopt = svc_getsockopt,
  602. .sendmsg = vcc_sendmsg,
  603. .recvmsg = vcc_recvmsg,
  604. .mmap = sock_no_mmap,
  605. .sendpage = sock_no_sendpage,
  606. };
  607. static int svc_create(struct net *net, struct socket *sock, int protocol,
  608. int kern)
  609. {
  610. int error;
  611. if (!net_eq(net, &init_net))
  612. return -EAFNOSUPPORT;
  613. sock->ops = &svc_proto_ops;
  614. error = vcc_create(net, sock, protocol, AF_ATMSVC, kern);
  615. if (error)
  616. return error;
  617. ATM_SD(sock)->local.sas_family = AF_ATMSVC;
  618. ATM_SD(sock)->remote.sas_family = AF_ATMSVC;
  619. return 0;
  620. }
  621. static const struct net_proto_family svc_family_ops = {
  622. .family = PF_ATMSVC,
  623. .create = svc_create,
  624. .owner = THIS_MODULE,
  625. };
  626. /*
  627. * Initialize the ATM SVC protocol family
  628. */
  629. int __init atmsvc_init(void)
  630. {
  631. return sock_register(&svc_family_ops);
  632. }
  633. void atmsvc_exit(void)
  634. {
  635. sock_unregister(PF_ATMSVC);
  636. }