svc.c 16 KB

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