svc.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690
  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. sigd_enq(vcc, as_close, NULL, NULL, NULL);
  44. for (;;) {
  45. prepare_to_wait(sk_sleep(sk), &wait, TASK_UNINTERRUPTIBLE);
  46. if (test_bit(ATM_VF_RELEASED, &vcc->flags) || !sigd)
  47. break;
  48. schedule();
  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. sigd_enq(vcc, as_bind, NULL, NULL, &vcc->local);
  116. for (;;) {
  117. prepare_to_wait(sk_sleep(sk), &wait, TASK_UNINTERRUPTIBLE);
  118. if (!test_bit(ATM_VF_WAITING, &vcc->flags) || !sigd)
  119. break;
  120. schedule();
  121. }
  122. finish_wait(sk_sleep(sk), &wait);
  123. clear_bit(ATM_VF_REGIS, &vcc->flags); /* doesn't count */
  124. if (!sigd) {
  125. error = -EUNATCH;
  126. goto out;
  127. }
  128. if (!sk->sk_err)
  129. set_bit(ATM_VF_BOUND, &vcc->flags);
  130. error = -sk->sk_err;
  131. out:
  132. release_sock(sk);
  133. return error;
  134. }
  135. static int svc_connect(struct socket *sock, struct sockaddr *sockaddr,
  136. int sockaddr_len, int flags)
  137. {
  138. DEFINE_WAIT(wait);
  139. struct sock *sk = sock->sk;
  140. struct sockaddr_atmsvc *addr;
  141. struct atm_vcc *vcc = ATM_SD(sock);
  142. int error;
  143. pr_debug("%p\n", vcc);
  144. lock_sock(sk);
  145. if (sockaddr_len != sizeof(struct sockaddr_atmsvc)) {
  146. error = -EINVAL;
  147. goto out;
  148. }
  149. switch (sock->state) {
  150. default:
  151. error = -EINVAL;
  152. goto out;
  153. case SS_CONNECTED:
  154. error = -EISCONN;
  155. goto out;
  156. case SS_CONNECTING:
  157. if (test_bit(ATM_VF_WAITING, &vcc->flags)) {
  158. error = -EALREADY;
  159. goto out;
  160. }
  161. sock->state = SS_UNCONNECTED;
  162. if (sk->sk_err) {
  163. error = -sk->sk_err;
  164. goto out;
  165. }
  166. break;
  167. case SS_UNCONNECTED:
  168. addr = (struct sockaddr_atmsvc *) sockaddr;
  169. if (addr->sas_family != AF_ATMSVC) {
  170. error = -EAFNOSUPPORT;
  171. goto out;
  172. }
  173. if (!test_bit(ATM_VF_HASQOS, &vcc->flags)) {
  174. error = -EBADFD;
  175. goto out;
  176. }
  177. if (vcc->qos.txtp.traffic_class == ATM_ANYCLASS ||
  178. vcc->qos.rxtp.traffic_class == ATM_ANYCLASS) {
  179. error = -EINVAL;
  180. goto out;
  181. }
  182. if (!vcc->qos.txtp.traffic_class &&
  183. !vcc->qos.rxtp.traffic_class) {
  184. error = -EINVAL;
  185. goto out;
  186. }
  187. vcc->remote = *addr;
  188. set_bit(ATM_VF_WAITING, &vcc->flags);
  189. sigd_enq(vcc, as_connect, NULL, NULL, &vcc->remote);
  190. if (flags & O_NONBLOCK) {
  191. sock->state = SS_CONNECTING;
  192. error = -EINPROGRESS;
  193. goto out;
  194. }
  195. error = 0;
  196. prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);
  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. vcc->qos.txtp.max_pcr = SELECT_TOP_PCR(vcc->qos.txtp);
  250. vcc->qos.txtp.pcr = 0;
  251. vcc->qos.txtp.min_pcr = 0;
  252. error = vcc_connect(sock, vcc->itf, vcc->vpi, vcc->vci);
  253. if (!error)
  254. sock->state = SS_CONNECTED;
  255. else
  256. (void)svc_disconnect(vcc);
  257. out:
  258. release_sock(sk);
  259. return error;
  260. }
  261. static int svc_listen(struct socket *sock, int backlog)
  262. {
  263. DEFINE_WAIT(wait);
  264. struct sock *sk = sock->sk;
  265. struct atm_vcc *vcc = ATM_SD(sock);
  266. int error;
  267. pr_debug("%p\n", vcc);
  268. lock_sock(sk);
  269. /* let server handle listen on unbound sockets */
  270. if (test_bit(ATM_VF_SESSION, &vcc->flags)) {
  271. error = -EINVAL;
  272. goto out;
  273. }
  274. if (test_bit(ATM_VF_LISTEN, &vcc->flags)) {
  275. error = -EADDRINUSE;
  276. goto out;
  277. }
  278. set_bit(ATM_VF_WAITING, &vcc->flags);
  279. sigd_enq(vcc, as_listen, NULL, NULL, &vcc->local);
  280. for (;;) {
  281. prepare_to_wait(sk_sleep(sk), &wait, TASK_UNINTERRUPTIBLE);
  282. if (!test_bit(ATM_VF_WAITING, &vcc->flags) || !sigd)
  283. break;
  284. schedule();
  285. }
  286. finish_wait(sk_sleep(sk), &wait);
  287. if (!sigd) {
  288. error = -EUNATCH;
  289. goto out;
  290. }
  291. set_bit(ATM_VF_LISTEN, &vcc->flags);
  292. vcc_insert_socket(sk);
  293. sk->sk_max_ack_backlog = backlog > 0 ? backlog : ATM_BACKLOG_DEFAULT;
  294. error = -sk->sk_err;
  295. out:
  296. release_sock(sk);
  297. return error;
  298. }
  299. static int svc_accept(struct socket *sock, struct socket *newsock, int flags)
  300. {
  301. struct sock *sk = sock->sk;
  302. struct sk_buff *skb;
  303. struct atmsvc_msg *msg;
  304. struct atm_vcc *old_vcc = ATM_SD(sock);
  305. struct atm_vcc *new_vcc;
  306. int error;
  307. lock_sock(sk);
  308. error = svc_create(sock_net(sk), newsock, 0, 0);
  309. if (error)
  310. goto out;
  311. new_vcc = ATM_SD(newsock);
  312. pr_debug("%p -> %p\n", old_vcc, new_vcc);
  313. while (1) {
  314. DEFINE_WAIT(wait);
  315. prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);
  316. while (!(skb = skb_dequeue(&sk->sk_receive_queue)) &&
  317. sigd) {
  318. if (test_bit(ATM_VF_RELEASED, &old_vcc->flags))
  319. break;
  320. if (test_bit(ATM_VF_CLOSE, &old_vcc->flags)) {
  321. error = -sk->sk_err;
  322. break;
  323. }
  324. if (flags & O_NONBLOCK) {
  325. error = -EAGAIN;
  326. break;
  327. }
  328. release_sock(sk);
  329. schedule();
  330. lock_sock(sk);
  331. if (signal_pending(current)) {
  332. error = -ERESTARTSYS;
  333. break;
  334. }
  335. prepare_to_wait(sk_sleep(sk), &wait,
  336. TASK_INTERRUPTIBLE);
  337. }
  338. finish_wait(sk_sleep(sk), &wait);
  339. if (error)
  340. goto out;
  341. if (!skb) {
  342. error = -EUNATCH;
  343. goto out;
  344. }
  345. msg = (struct atmsvc_msg *)skb->data;
  346. new_vcc->qos = msg->qos;
  347. set_bit(ATM_VF_HASQOS, &new_vcc->flags);
  348. new_vcc->remote = msg->svc;
  349. new_vcc->local = msg->local;
  350. new_vcc->sap = msg->sap;
  351. error = vcc_connect(newsock, msg->pvc.sap_addr.itf,
  352. msg->pvc.sap_addr.vpi,
  353. msg->pvc.sap_addr.vci);
  354. dev_kfree_skb(skb);
  355. sk->sk_ack_backlog--;
  356. if (error) {
  357. sigd_enq2(NULL, as_reject, old_vcc, NULL, NULL,
  358. &old_vcc->qos, error);
  359. error = error == -EAGAIN ? -EBUSY : error;
  360. goto out;
  361. }
  362. /* wait should be short, so we ignore the non-blocking flag */
  363. set_bit(ATM_VF_WAITING, &new_vcc->flags);
  364. sigd_enq(new_vcc, as_accept, old_vcc, NULL, NULL);
  365. for (;;) {
  366. prepare_to_wait(sk_sleep(sk_atm(new_vcc)), &wait,
  367. TASK_UNINTERRUPTIBLE);
  368. if (!test_bit(ATM_VF_WAITING, &new_vcc->flags) || !sigd)
  369. break;
  370. release_sock(sk);
  371. schedule();
  372. lock_sock(sk);
  373. }
  374. finish_wait(sk_sleep(sk_atm(new_vcc)), &wait);
  375. if (!sigd) {
  376. error = -EUNATCH;
  377. goto out;
  378. }
  379. if (!sk_atm(new_vcc)->sk_err)
  380. break;
  381. if (sk_atm(new_vcc)->sk_err != ERESTARTSYS) {
  382. error = -sk_atm(new_vcc)->sk_err;
  383. goto out;
  384. }
  385. }
  386. newsock->state = SS_CONNECTED;
  387. out:
  388. release_sock(sk);
  389. return error;
  390. }
  391. static int svc_getname(struct socket *sock, struct sockaddr *sockaddr,
  392. int *sockaddr_len, int peer)
  393. {
  394. struct sockaddr_atmsvc *addr;
  395. *sockaddr_len = sizeof(struct sockaddr_atmsvc);
  396. addr = (struct sockaddr_atmsvc *) sockaddr;
  397. memcpy(addr, peer ? &ATM_SD(sock)->remote : &ATM_SD(sock)->local,
  398. sizeof(struct sockaddr_atmsvc));
  399. return 0;
  400. }
  401. int svc_change_qos(struct atm_vcc *vcc, struct atm_qos *qos)
  402. {
  403. struct sock *sk = sk_atm(vcc);
  404. DEFINE_WAIT(wait);
  405. set_bit(ATM_VF_WAITING, &vcc->flags);
  406. sigd_enq2(vcc, as_modify, NULL, NULL, &vcc->local, qos, 0);
  407. for (;;) {
  408. prepare_to_wait(sk_sleep(sk), &wait, TASK_UNINTERRUPTIBLE);
  409. if (!test_bit(ATM_VF_WAITING, &vcc->flags) ||
  410. test_bit(ATM_VF_RELEASED, &vcc->flags) || !sigd) {
  411. break;
  412. }
  413. schedule();
  414. }
  415. finish_wait(sk_sleep(sk), &wait);
  416. if (!sigd)
  417. return -EUNATCH;
  418. return -sk->sk_err;
  419. }
  420. static int svc_setsockopt(struct socket *sock, int level, int optname,
  421. char __user *optval, unsigned int optlen)
  422. {
  423. struct sock *sk = sock->sk;
  424. struct atm_vcc *vcc = ATM_SD(sock);
  425. int value, error = 0;
  426. lock_sock(sk);
  427. switch (optname) {
  428. case SO_ATMSAP:
  429. if (level != SOL_ATM || optlen != sizeof(struct atm_sap)) {
  430. error = -EINVAL;
  431. goto out;
  432. }
  433. if (copy_from_user(&vcc->sap, optval, optlen)) {
  434. error = -EFAULT;
  435. goto out;
  436. }
  437. set_bit(ATM_VF_HASSAP, &vcc->flags);
  438. break;
  439. case SO_MULTIPOINT:
  440. if (level != SOL_ATM || optlen != sizeof(int)) {
  441. error = -EINVAL;
  442. goto out;
  443. }
  444. if (get_user(value, (int __user *)optval)) {
  445. error = -EFAULT;
  446. goto out;
  447. }
  448. if (value == 1)
  449. set_bit(ATM_VF_SESSION, &vcc->flags);
  450. else if (value == 0)
  451. clear_bit(ATM_VF_SESSION, &vcc->flags);
  452. else
  453. error = -EINVAL;
  454. break;
  455. default:
  456. error = vcc_setsockopt(sock, level, optname, optval, optlen);
  457. }
  458. out:
  459. release_sock(sk);
  460. return error;
  461. }
  462. static int svc_getsockopt(struct socket *sock, int level, int optname,
  463. char __user *optval, int __user *optlen)
  464. {
  465. struct sock *sk = sock->sk;
  466. int error = 0, len;
  467. lock_sock(sk);
  468. if (!__SO_LEVEL_MATCH(optname, level) || optname != SO_ATMSAP) {
  469. error = vcc_getsockopt(sock, level, optname, optval, optlen);
  470. goto out;
  471. }
  472. if (get_user(len, optlen)) {
  473. error = -EFAULT;
  474. goto out;
  475. }
  476. if (len != sizeof(struct atm_sap)) {
  477. error = -EINVAL;
  478. goto out;
  479. }
  480. if (copy_to_user(optval, &ATM_SD(sock)->sap, sizeof(struct atm_sap))) {
  481. error = -EFAULT;
  482. goto out;
  483. }
  484. out:
  485. release_sock(sk);
  486. return error;
  487. }
  488. static int svc_addparty(struct socket *sock, struct sockaddr *sockaddr,
  489. int sockaddr_len, int flags)
  490. {
  491. DEFINE_WAIT(wait);
  492. struct sock *sk = sock->sk;
  493. struct atm_vcc *vcc = ATM_SD(sock);
  494. int error;
  495. lock_sock(sk);
  496. set_bit(ATM_VF_WAITING, &vcc->flags);
  497. sigd_enq(vcc, as_addparty, NULL, NULL,
  498. (struct sockaddr_atmsvc *) sockaddr);
  499. if (flags & O_NONBLOCK) {
  500. error = -EINPROGRESS;
  501. goto out;
  502. }
  503. pr_debug("added wait queue\n");
  504. for (;;) {
  505. prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);
  506. if (!test_bit(ATM_VF_WAITING, &vcc->flags) || !sigd)
  507. break;
  508. schedule();
  509. }
  510. finish_wait(sk_sleep(sk), &wait);
  511. error = xchg(&sk->sk_err_soft, 0);
  512. out:
  513. release_sock(sk);
  514. return error;
  515. }
  516. static int svc_dropparty(struct socket *sock, int ep_ref)
  517. {
  518. DEFINE_WAIT(wait);
  519. struct sock *sk = sock->sk;
  520. struct atm_vcc *vcc = ATM_SD(sock);
  521. int error;
  522. lock_sock(sk);
  523. set_bit(ATM_VF_WAITING, &vcc->flags);
  524. sigd_enq2(vcc, as_dropparty, NULL, NULL, NULL, NULL, ep_ref);
  525. for (;;) {
  526. prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);
  527. if (!test_bit(ATM_VF_WAITING, &vcc->flags) || !sigd)
  528. break;
  529. schedule();
  530. }
  531. finish_wait(sk_sleep(sk), &wait);
  532. if (!sigd) {
  533. error = -EUNATCH;
  534. goto out;
  535. }
  536. error = xchg(&sk->sk_err_soft, 0);
  537. out:
  538. release_sock(sk);
  539. return error;
  540. }
  541. static int svc_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
  542. {
  543. int error, ep_ref;
  544. struct sockaddr_atmsvc sa;
  545. struct atm_vcc *vcc = ATM_SD(sock);
  546. switch (cmd) {
  547. case ATM_ADDPARTY:
  548. if (!test_bit(ATM_VF_SESSION, &vcc->flags))
  549. return -EINVAL;
  550. if (copy_from_user(&sa, (void __user *) arg, sizeof(sa)))
  551. return -EFAULT;
  552. error = svc_addparty(sock, (struct sockaddr *)&sa, sizeof(sa),
  553. 0);
  554. break;
  555. case ATM_DROPPARTY:
  556. if (!test_bit(ATM_VF_SESSION, &vcc->flags))
  557. return -EINVAL;
  558. if (copy_from_user(&ep_ref, (void __user *) arg, sizeof(int)))
  559. return -EFAULT;
  560. error = svc_dropparty(sock, ep_ref);
  561. break;
  562. default:
  563. error = vcc_ioctl(sock, cmd, arg);
  564. }
  565. return error;
  566. }
  567. #ifdef CONFIG_COMPAT
  568. static int svc_compat_ioctl(struct socket *sock, unsigned int cmd,
  569. unsigned long arg)
  570. {
  571. /* The definition of ATM_ADDPARTY uses the size of struct atm_iobuf.
  572. But actually it takes a struct sockaddr_atmsvc, which doesn't need
  573. compat handling. So all we have to do is fix up cmd... */
  574. if (cmd == COMPAT_ATM_ADDPARTY)
  575. cmd = ATM_ADDPARTY;
  576. if (cmd == ATM_ADDPARTY || cmd == ATM_DROPPARTY)
  577. return svc_ioctl(sock, cmd, arg);
  578. else
  579. return vcc_compat_ioctl(sock, cmd, arg);
  580. }
  581. #endif /* CONFIG_COMPAT */
  582. static const struct proto_ops svc_proto_ops = {
  583. .family = PF_ATMSVC,
  584. .owner = THIS_MODULE,
  585. .release = svc_release,
  586. .bind = svc_bind,
  587. .connect = svc_connect,
  588. .socketpair = sock_no_socketpair,
  589. .accept = svc_accept,
  590. .getname = svc_getname,
  591. .poll = vcc_poll,
  592. .ioctl = svc_ioctl,
  593. #ifdef CONFIG_COMPAT
  594. .compat_ioctl = svc_compat_ioctl,
  595. #endif
  596. .listen = svc_listen,
  597. .shutdown = svc_shutdown,
  598. .setsockopt = svc_setsockopt,
  599. .getsockopt = svc_getsockopt,
  600. .sendmsg = vcc_sendmsg,
  601. .recvmsg = vcc_recvmsg,
  602. .mmap = sock_no_mmap,
  603. .sendpage = sock_no_sendpage,
  604. };
  605. static int svc_create(struct net *net, struct socket *sock, int protocol,
  606. int kern)
  607. {
  608. int error;
  609. if (!net_eq(net, &init_net))
  610. return -EAFNOSUPPORT;
  611. sock->ops = &svc_proto_ops;
  612. error = vcc_create(net, sock, protocol, AF_ATMSVC, kern);
  613. if (error)
  614. return error;
  615. ATM_SD(sock)->local.sas_family = AF_ATMSVC;
  616. ATM_SD(sock)->remote.sas_family = AF_ATMSVC;
  617. return 0;
  618. }
  619. static const struct net_proto_family svc_family_ops = {
  620. .family = PF_ATMSVC,
  621. .create = svc_create,
  622. .owner = THIS_MODULE,
  623. };
  624. /*
  625. * Initialize the ATM SVC protocol family
  626. */
  627. int __init atmsvc_init(void)
  628. {
  629. return sock_register(&svc_family_ops);
  630. }
  631. void atmsvc_exit(void)
  632. {
  633. sock_unregister(PF_ATMSVC);
  634. }