af_wanpipe.c 66 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611
  1. /*****************************************************************************
  2. * af_wanpipe.c WANPIPE(tm) Secure Socket Layer.
  3. *
  4. * Author: Nenad Corbic <ncorbic@sangoma.com>
  5. *
  6. * Copyright: (c) 2000 Sangoma Technologies Inc.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version
  11. * 2 of the License, or (at your option) any later version.
  12. * ============================================================================
  13. * Due Credit:
  14. * Wanpipe socket layer is based on Packet and
  15. * the X25 socket layers. The above sockets were
  16. * used for the specific use of Sangoma Technoloiges
  17. * API programs.
  18. * Packet socket Authors: Ross Biro, Fred N. van Kempen and
  19. * Alan Cox.
  20. * X25 socket Author: Jonathan Naylor.
  21. * ============================================================================
  22. * Mar 15, 2002 Arnaldo C. Melo o Use wp_sk()->num, as it isnt anymore in sock
  23. * Apr 25, 2000 Nenad Corbic o Added the ability to send zero length packets.
  24. * Mar 13, 2000 Nenad Corbic o Added a tx buffer check via ioctl call.
  25. * Mar 06, 2000 Nenad Corbic o Fixed the corrupt sock lcn problem.
  26. * Server and client applicaton can run
  27. * simultaneously without conflicts.
  28. * Feb 29, 2000 Nenad Corbic o Added support for PVC protocols, such as
  29. * CHDLC, Frame Relay and HDLC API.
  30. * Jan 17, 2000 Nenad Corbic o Initial version, based on AF_PACKET socket.
  31. * X25API support only.
  32. *
  33. ******************************************************************************/
  34. #include <linux/config.h>
  35. #include <linux/types.h>
  36. #include <linux/sched.h>
  37. #include <linux/mm.h>
  38. #include <linux/fcntl.h>
  39. #include <linux/socket.h>
  40. #include <linux/in.h>
  41. #include <linux/inet.h>
  42. #include <linux/netdevice.h>
  43. #include <linux/poll.h>
  44. #include <linux/wireless.h>
  45. #include <linux/kmod.h>
  46. #include <net/ip.h>
  47. #include <net/protocol.h>
  48. #include <linux/skbuff.h>
  49. #include <net/sock.h>
  50. #include <linux/errno.h>
  51. #include <linux/timer.h>
  52. #include <asm/system.h>
  53. #include <asm/uaccess.h>
  54. #include <linux/module.h>
  55. #include <linux/init.h>
  56. #include <linux/wanpipe.h>
  57. #include <linux/if_wanpipe.h>
  58. #include <linux/pkt_sched.h>
  59. #include <linux/tcp.h>
  60. #include <linux/if_wanpipe_common.h>
  61. #include <linux/sdla_x25.h>
  62. #ifdef CONFIG_INET
  63. #include <net/inet_common.h>
  64. #endif
  65. #define SLOW_BACKOFF 0.1*HZ
  66. #define FAST_BACKOFF 0.01*HZ
  67. //#define PRINT_DEBUG
  68. #ifdef PRINT_DEBUG
  69. #define DBG_PRINTK(format, a...) printk(format, ## a)
  70. #else
  71. #define DBG_PRINTK(format, a...)
  72. #endif
  73. /* SECURE SOCKET IMPLEMENTATION
  74. *
  75. * TRANSMIT:
  76. *
  77. * When the user sends a packet via send() system call
  78. * the wanpipe_sendmsg() function is executed.
  79. *
  80. * Each packet is enqueud into sk->sk_write_queue transmit
  81. * queue. When the packet is enqueued, a delayed transmit
  82. * timer is triggerd which acts as a Bottom Half hander.
  83. *
  84. * wanpipe_delay_transmit() function (BH), dequeues packets
  85. * from the sk->sk_write_queue transmit queue and sends it
  86. * to the deriver via dev->hard_start_xmit(skb, dev) function.
  87. * Note, this function is actual a function pointer of if_send()
  88. * routine in the wanpipe driver.
  89. *
  90. * X25API GUARANTEED DELIVERY:
  91. *
  92. * In order to provide 100% guaranteed packet delivery,
  93. * an atomic 'packet_sent' counter is implemented. Counter
  94. * is incremented for each packet enqueued
  95. * into sk->sk_write_queue. Counter is decremented each
  96. * time wanpipe_delayed_transmit() function successfuly
  97. * passes the packet to the driver. Before each send(), a poll
  98. * routine checks the sock resources The maximum value of
  99. * packet sent counter is 1, thus if one packet is queued, the
  100. * application will block until that packet is passed to the
  101. * driver.
  102. *
  103. * RECEIVE:
  104. *
  105. * Wanpipe device drivers call the socket bottom half
  106. * function, wanpipe_rcv() to queue the incoming packets
  107. * into an AF_WANPIPE socket queue. Based on wanpipe_rcv()
  108. * return code, the driver knows whether the packet was
  109. * successfully queued. If the socket queue is full,
  110. * protocol flow control is used by the driver, if any,
  111. * to slow down the traffic until the sock queue is free.
  112. *
  113. * Every time a packet arrives into a socket queue the
  114. * socket wakes up processes which are waiting to receive
  115. * data.
  116. *
  117. * If the socket queue is full, the driver sets a block
  118. * bit which signals the socket to kick the wanpipe driver
  119. * bottom half hander when the socket queue is partialy
  120. * empty. wanpipe_recvmsg() function performs this action.
  121. *
  122. * In case of x25api, packets will never be dropped, since
  123. * flow control is available.
  124. *
  125. * In case of streaming protocols like CHDLC, packets will
  126. * be dropped but the statistics will be generated.
  127. */
  128. /* The code below is used to test memory leaks. It prints out
  129. * a message every time kmalloc and kfree system calls get executed.
  130. * If the calls match there is no leak :)
  131. */
  132. /***********FOR DEBUGGING PURPOSES*********************************************
  133. #define KMEM_SAFETYZONE 8
  134. static void * dbg_kmalloc(unsigned int size, int prio, int line) {
  135. void * v = kmalloc(size,prio);
  136. printk(KERN_INFO "line %d kmalloc(%d,%d) = %p\n",line,size,prio,v);
  137. return v;
  138. }
  139. static void dbg_kfree(void * v, int line) {
  140. printk(KERN_INFO "line %d kfree(%p)\n",line,v);
  141. kfree(v);
  142. }
  143. #define kmalloc(x,y) dbg_kmalloc(x,y,__LINE__)
  144. #define kfree(x) dbg_kfree(x,__LINE__)
  145. ******************************************************************************/
  146. /* List of all wanpipe sockets. */
  147. HLIST_HEAD(wanpipe_sklist);
  148. static DEFINE_RWLOCK(wanpipe_sklist_lock);
  149. atomic_t wanpipe_socks_nr;
  150. static unsigned long wanpipe_tx_critical;
  151. #if 0
  152. /* Private wanpipe socket structures. */
  153. struct wanpipe_opt
  154. {
  155. void *mbox; /* Mail box */
  156. void *card; /* Card bouded to */
  157. struct net_device *dev; /* Bounded device */
  158. unsigned short lcn; /* Binded LCN */
  159. unsigned char svc; /* 0=pvc, 1=svc */
  160. unsigned char timer; /* flag for delayed transmit*/
  161. struct timer_list tx_timer;
  162. unsigned poll_cnt;
  163. unsigned char force; /* Used to force sock release */
  164. atomic_t packet_sent;
  165. };
  166. #endif
  167. static int sk_count;
  168. extern struct proto_ops wanpipe_ops;
  169. static unsigned long find_free_critical;
  170. static void wanpipe_unlink_driver(struct sock *sk);
  171. static void wanpipe_link_driver(struct net_device *dev, struct sock *sk);
  172. static void wanpipe_wakeup_driver(struct sock *sk);
  173. static int execute_command(struct sock *, unsigned char, unsigned int);
  174. static int check_dev(struct net_device *dev, sdla_t *card);
  175. struct net_device *wanpipe_find_free_dev(sdla_t *card);
  176. static void wanpipe_unlink_card (struct sock *);
  177. static int wanpipe_link_card (struct sock *);
  178. static struct sock *wanpipe_make_new(struct sock *);
  179. static struct sock *wanpipe_alloc_socket(void);
  180. static inline int get_atomic_device(struct net_device *dev);
  181. static int wanpipe_exec_cmd(struct sock *, int, unsigned int);
  182. static int get_ioctl_cmd (struct sock *, void *);
  183. static int set_ioctl_cmd (struct sock *, void *);
  184. static void release_device(struct net_device *dev);
  185. static void wanpipe_kill_sock_timer (unsigned long data);
  186. static void wanpipe_kill_sock_irq (struct sock *);
  187. static void wanpipe_kill_sock_accept (struct sock *);
  188. static int wanpipe_do_bind(struct sock *sk, struct net_device *dev,
  189. int protocol);
  190. struct sock * get_newsk_from_skb (struct sk_buff *);
  191. static int wanpipe_debug (struct sock *, void *);
  192. static void wanpipe_delayed_transmit (unsigned long data);
  193. static void release_driver(struct sock *);
  194. static void start_cleanup_timer (struct sock *);
  195. static void check_write_queue(struct sock *);
  196. static int check_driver_busy (struct sock *);
  197. /*============================================================
  198. * wanpipe_rcv
  199. *
  200. * Wanpipe socket bottom half handler. This function
  201. * is called by the WANPIPE device drivers to queue a
  202. * incoming packet into the socket receive queue.
  203. * Once the packet is queued, all processes waiting to
  204. * read are woken up.
  205. *
  206. * During socket bind, this function is bounded into
  207. * WANPIPE driver private.
  208. *===========================================================*/
  209. static int wanpipe_rcv(struct sk_buff *skb, struct net_device *dev,
  210. struct sock *sk)
  211. {
  212. struct wan_sockaddr_ll *sll = (struct wan_sockaddr_ll*)skb->cb;
  213. wanpipe_common_t *chan = dev->priv;
  214. /*
  215. * When we registered the protocol we saved the socket in the data
  216. * field for just this event.
  217. */
  218. skb->dev = dev;
  219. sll->sll_family = AF_WANPIPE;
  220. sll->sll_hatype = dev->type;
  221. sll->sll_protocol = skb->protocol;
  222. sll->sll_pkttype = skb->pkt_type;
  223. sll->sll_ifindex = dev->ifindex;
  224. sll->sll_halen = 0;
  225. if (dev->hard_header_parse)
  226. sll->sll_halen = dev->hard_header_parse(skb, sll->sll_addr);
  227. /*
  228. * WAN_PACKET_DATA : Data which should be passed up the receive queue.
  229. * WAN_PACKET_ASYC : Asynchronous data like place call, which should
  230. * be passed up the listening sock.
  231. * WAN_PACKET_ERR : Asynchronous data like clear call or restart
  232. * which should go into an error queue.
  233. */
  234. switch (skb->pkt_type){
  235. case WAN_PACKET_DATA:
  236. if (sock_queue_rcv_skb(sk,skb)<0){
  237. return -ENOMEM;
  238. }
  239. break;
  240. case WAN_PACKET_CMD:
  241. sk->sk_state = chan->state;
  242. /* Bug fix: update Mar6.
  243. * Do not set the sock lcn number here, since
  244. * cmd is not guaranteed to be executed on the
  245. * board, thus Lcn could be wrong */
  246. sk->sk_data_ready(sk, skb->len);
  247. kfree_skb(skb);
  248. break;
  249. case WAN_PACKET_ERR:
  250. sk->sk_state = chan->state;
  251. if (sock_queue_err_skb(sk,skb)<0){
  252. return -ENOMEM;
  253. }
  254. break;
  255. default:
  256. printk(KERN_INFO "wansock: BH Illegal Packet Type Dropping\n");
  257. kfree_skb(skb);
  258. break;
  259. }
  260. //??????????????????????
  261. // if (sk->sk_state == WANSOCK_DISCONNECTED){
  262. // if (sk->sk_zapped) {
  263. // //printk(KERN_INFO "wansock: Disconnected, killing early\n");
  264. // wanpipe_unlink_driver(sk);
  265. // sk->sk_bound_dev_if = 0;
  266. // }
  267. // }
  268. return 0;
  269. }
  270. /*============================================================
  271. * wanpipe_listen_rcv
  272. *
  273. * Wanpipe LISTEN socket bottom half handler. This function
  274. * is called by the WANPIPE device drivers to queue an
  275. * incoming call into the socket listening queue.
  276. * Once the packet is queued, the waiting accept() process
  277. * is woken up.
  278. *
  279. * During socket bind, this function is bounded into
  280. * WANPIPE driver private.
  281. *
  282. * IMPORTANT NOTE:
  283. * The accept call() is waiting for an skb packet
  284. * which contains a pointer to a device structure.
  285. *
  286. * When we do a bind to a device structre, we
  287. * bind a newly created socket into "chan->sk". Thus,
  288. * when accept receives the skb packet, it will know
  289. * from which dev it came form, and in turn it will know
  290. * the address of the new sock.
  291. *
  292. * NOTE: This function gets called from driver ISR.
  293. *===========================================================*/
  294. static int wanpipe_listen_rcv (struct sk_buff *skb, struct sock *sk)
  295. {
  296. wanpipe_opt *wp = wp_sk(sk), *newwp;
  297. struct wan_sockaddr_ll *sll = (struct wan_sockaddr_ll*)skb->cb;
  298. struct sock *newsk;
  299. struct net_device *dev;
  300. sdla_t *card;
  301. mbox_cmd_t *mbox_ptr;
  302. wanpipe_common_t *chan;
  303. /* Find a free device, if none found, all svc's are busy
  304. */
  305. card = (sdla_t*)wp->card;
  306. if (!card){
  307. printk(KERN_INFO "wansock: LISTEN ERROR, No Card\n");
  308. return -ENODEV;
  309. }
  310. dev = wanpipe_find_free_dev(card);
  311. if (!dev){
  312. printk(KERN_INFO "wansock: LISTEN ERROR, No Free Device\n");
  313. return -ENODEV;
  314. }
  315. chan=dev->priv;
  316. chan->state = WANSOCK_CONNECTING;
  317. /* Allocate a new sock, which accept will bind
  318. * and pass up to the user
  319. */
  320. if ((newsk = wanpipe_make_new(sk)) == NULL){
  321. release_device(dev);
  322. return -ENOMEM;
  323. }
  324. /* Initialize the new sock structure
  325. */
  326. newsk->sk_bound_dev_if = dev->ifindex;
  327. newwp = wp_sk(newsk);
  328. newwp->card = wp->card;
  329. /* Insert the sock into the main wanpipe
  330. * sock list.
  331. */
  332. atomic_inc(&wanpipe_socks_nr);
  333. /* Allocate and fill in the new Mail Box. Then
  334. * bind the mail box to the sock. It will be
  335. * used by the ioctl call to read call information
  336. * and to execute commands.
  337. */
  338. if ((mbox_ptr = kmalloc(sizeof(mbox_cmd_t), GFP_ATOMIC)) == NULL) {
  339. wanpipe_kill_sock_irq (newsk);
  340. release_device(dev);
  341. return -ENOMEM;
  342. }
  343. memset(mbox_ptr, 0, sizeof(mbox_cmd_t));
  344. memcpy(mbox_ptr,skb->data,skb->len);
  345. /* Register the lcn on which incoming call came
  346. * from. Thus, if we have to clear it, we know
  347. * which lcn to clear
  348. */
  349. newwp->lcn = mbox_ptr->cmd.lcn;
  350. newwp->mbox = (void *)mbox_ptr;
  351. DBG_PRINTK(KERN_INFO "NEWSOCK : Device %s, bind to lcn %i\n",
  352. dev->name,mbox_ptr->cmd.lcn);
  353. chan->lcn = mbox_ptr->cmd.lcn;
  354. card->u.x.svc_to_dev_map[(chan->lcn%MAX_X25_LCN)] = dev;
  355. sock_reset_flag(newsk, SOCK_ZAPPED);
  356. newwp->num = htons(X25_PROT);
  357. if (wanpipe_do_bind(newsk, dev, newwp->num)) {
  358. wanpipe_kill_sock_irq (newsk);
  359. release_device(dev);
  360. return -EINVAL;
  361. }
  362. newsk->sk_state = WANSOCK_CONNECTING;
  363. /* Fill in the standard sock address info */
  364. sll->sll_family = AF_WANPIPE;
  365. sll->sll_hatype = dev->type;
  366. sll->sll_protocol = skb->protocol;
  367. sll->sll_pkttype = skb->pkt_type;
  368. sll->sll_ifindex = dev->ifindex;
  369. sll->sll_halen = 0;
  370. skb->dev = dev;
  371. sk->sk_ack_backlog++;
  372. /* We must do this manually, since the sock_queue_rcv_skb()
  373. * function sets the skb->dev to NULL. However, we use
  374. * the dev field in the accept function.*/
  375. if (atomic_read(&sk->sk_rmem_alloc) + skb->truesize >=
  376. (unsigned)sk->sk_rcvbuf) {
  377. wanpipe_unlink_driver(newsk);
  378. wanpipe_kill_sock_irq (newsk);
  379. --sk->sk_ack_backlog;
  380. return -ENOMEM;
  381. }
  382. skb_set_owner_r(skb, sk);
  383. skb_queue_tail(&sk->sk_receive_queue, skb);
  384. sk->sk_data_ready(sk, skb->len);
  385. return 0;
  386. }
  387. /*============================================================
  388. * wanpipe_make_new
  389. *
  390. * Create a new sock, and allocate a wanpipe private
  391. * structure to it. Also, copy the important data
  392. * from the original sock to the new sock.
  393. *
  394. * This function is used by wanpipe_listen_rcv() listen
  395. * bottom half handler. A copy of the listening sock
  396. * is created using this function.
  397. *
  398. *===========================================================*/
  399. static struct sock *wanpipe_make_new(struct sock *osk)
  400. {
  401. struct sock *sk;
  402. if (osk->sk_type != SOCK_RAW)
  403. return NULL;
  404. if ((sk = wanpipe_alloc_socket()) == NULL)
  405. return NULL;
  406. sk->sk_type = osk->sk_type;
  407. sk->sk_socket = osk->sk_socket;
  408. sk->sk_priority = osk->sk_priority;
  409. sk->sk_protocol = osk->sk_protocol;
  410. wp_sk(sk)->num = wp_sk(osk)->num;
  411. sk->sk_rcvbuf = osk->sk_rcvbuf;
  412. sk->sk_sndbuf = osk->sk_sndbuf;
  413. sk->sk_state = WANSOCK_CONNECTING;
  414. sk->sk_sleep = osk->sk_sleep;
  415. if (sock_flag(osk, SOCK_DBG))
  416. sock_set_flag(sk, SOCK_DBG);
  417. return sk;
  418. }
  419. /*
  420. * FIXME: wanpipe_opt has to include a sock in its definition and stop using
  421. * sk_protinfo, but this code is not even compilable now, so lets leave it for
  422. * later.
  423. */
  424. static struct proto wanpipe_proto = {
  425. .name = "WANPIPE",
  426. .owner = THIS_MODULE,
  427. .obj_size = sizeof(struct sock),
  428. };
  429. /*============================================================
  430. * wanpipe_make_new
  431. *
  432. * Allocate memory for the a new sock, and sock
  433. * private data.
  434. *
  435. * Increment the module use count.
  436. *
  437. * This function is used by wanpipe_create() and
  438. * wanpipe_make_new() functions.
  439. *
  440. *===========================================================*/
  441. static struct sock *wanpipe_alloc_socket(void)
  442. {
  443. struct sock *sk;
  444. struct wanpipe_opt *wan_opt;
  445. if ((sk = sk_alloc(PF_WANPIPE, GFP_ATOMIC, &wanpipe_proto, 1)) == NULL)
  446. return NULL;
  447. if ((wan_opt = kmalloc(sizeof(struct wanpipe_opt), GFP_ATOMIC)) == NULL) {
  448. sk_free(sk);
  449. return NULL;
  450. }
  451. memset(wan_opt, 0x00, sizeof(struct wanpipe_opt));
  452. wp_sk(sk) = wan_opt;
  453. /* Use timer to send data to the driver. This will act
  454. * as a BH handler for sendmsg functions */
  455. init_timer(&wan_opt->tx_timer);
  456. wan_opt->tx_timer.data = (unsigned long)sk;
  457. wan_opt->tx_timer.function = wanpipe_delayed_transmit;
  458. sock_init_data(NULL, sk);
  459. return sk;
  460. }
  461. /*============================================================
  462. * wanpipe_sendmsg
  463. *
  464. * This function implements a sendto() system call,
  465. * for AF_WANPIPE socket family.
  466. * During socket bind() sk->sk_bound_dev_if is initialized
  467. * to a correct network device. This number is used
  468. * to find a network device to which the packet should
  469. * be passed to.
  470. *
  471. * Each packet is queued into sk->sk_write_queue and
  472. * delayed transmit bottom half handler is marked for
  473. * execution.
  474. *
  475. * A socket must be in WANSOCK_CONNECTED state before
  476. * a packet is queued into sk->sk_write_queue.
  477. *===========================================================*/
  478. static int wanpipe_sendmsg(struct kiocb *iocb, struct socket *sock,
  479. struct msghdr *msg, int len)
  480. {
  481. wanpipe_opt *wp;
  482. struct sock *sk = sock->sk;
  483. struct wan_sockaddr_ll *saddr=(struct wan_sockaddr_ll *)msg->msg_name;
  484. struct sk_buff *skb;
  485. struct net_device *dev;
  486. unsigned short proto;
  487. unsigned char *addr;
  488. int ifindex, err, reserve = 0;
  489. if (!sock_flag(sk, SOCK_ZAPPED))
  490. return -ENETDOWN;
  491. if (sk->sk_state != WANSOCK_CONNECTED)
  492. return -ENOTCONN;
  493. if (msg->msg_flags & ~(MSG_DONTWAIT|MSG_CMSG_COMPAT))
  494. return(-EINVAL);
  495. /* it was <=, now one can send
  496. * zero length packets */
  497. if (len < sizeof(x25api_hdr_t))
  498. return -EINVAL;
  499. wp = wp_sk(sk);
  500. if (saddr == NULL) {
  501. ifindex = sk->sk_bound_dev_if;
  502. proto = wp->num;
  503. addr = NULL;
  504. }else{
  505. if (msg->msg_namelen < sizeof(struct wan_sockaddr_ll)){
  506. return -EINVAL;
  507. }
  508. ifindex = sk->sk_bound_dev_if;
  509. proto = saddr->sll_protocol;
  510. addr = saddr->sll_addr;
  511. }
  512. dev = dev_get_by_index(ifindex);
  513. if (dev == NULL){
  514. printk(KERN_INFO "wansock: Send failed, dev index: %i\n",ifindex);
  515. return -ENXIO;
  516. }
  517. dev_put(dev);
  518. if (sock->type == SOCK_RAW)
  519. reserve = dev->hard_header_len;
  520. if (len > dev->mtu+reserve){
  521. return -EMSGSIZE;
  522. }
  523. skb = sock_alloc_send_skb(sk, len + LL_RESERVED_SPACE(dev),
  524. msg->msg_flags & MSG_DONTWAIT, &err);
  525. if (skb==NULL){
  526. goto out_unlock;
  527. }
  528. skb_reserve(skb, LL_RESERVED_SPACE(dev));
  529. skb->nh.raw = skb->data;
  530. /* Returns -EFAULT on error */
  531. err = memcpy_fromiovec(skb_put(skb,len), msg->msg_iov, len);
  532. if (err){
  533. goto out_free;
  534. }
  535. if (dev->hard_header) {
  536. int res;
  537. err = -EINVAL;
  538. res = dev->hard_header(skb, dev, ntohs(proto), addr, NULL, len);
  539. if (res<0){
  540. goto out_free;
  541. }
  542. }
  543. skb->protocol = proto;
  544. skb->dev = dev;
  545. skb->priority = sk->sk_priority;
  546. skb->pkt_type = WAN_PACKET_DATA;
  547. err = -ENETDOWN;
  548. if (!(dev->flags & IFF_UP))
  549. goto out_free;
  550. if (atomic_read(&sk->sk_wmem_alloc) + skb->truesize >
  551. (unsigned int)sk->sk_sndbuf){
  552. kfree_skb(skb);
  553. return -ENOBUFS;
  554. }
  555. skb_queue_tail(&sk->sk_write_queue,skb);
  556. atomic_inc(&wp->packet_sent);
  557. if (!(test_and_set_bit(0, &wp->timer)))
  558. mod_timer(&wp->tx_timer, jiffies + 1);
  559. return(len);
  560. out_free:
  561. kfree_skb(skb);
  562. out_unlock:
  563. return err;
  564. }
  565. /*============================================================
  566. * wanpipe_delayed_tarnsmit
  567. *
  568. * Transmit bottom half handler. It dequeues packets
  569. * from sk->sk_write_queue and passes them to the
  570. * driver. If the driver is busy, the packet is
  571. * re-enqueued.
  572. *
  573. * Packet Sent counter is decremented on successful
  574. * transmission.
  575. *===========================================================*/
  576. static void wanpipe_delayed_transmit (unsigned long data)
  577. {
  578. struct sock *sk=(struct sock *)data;
  579. struct sk_buff *skb;
  580. wanpipe_opt *wp = wp_sk(sk);
  581. struct net_device *dev = wp->dev;
  582. sdla_t *card = (sdla_t*)wp->card;
  583. if (!card || !dev){
  584. clear_bit(0, &wp->timer);
  585. DBG_PRINTK(KERN_INFO "wansock: Transmit delay, no dev or card\n");
  586. return;
  587. }
  588. if (sk->sk_state != WANSOCK_CONNECTED || !sock_flag(sk, SOCK_ZAPPED)) {
  589. clear_bit(0, &wp->timer);
  590. DBG_PRINTK(KERN_INFO "wansock: Tx Timer, State not CONNECTED\n");
  591. return;
  592. }
  593. /* If driver is executing command, we must offload
  594. * the board by not sending data. Otherwise a
  595. * pending command will never get a free buffer
  596. * to execute */
  597. if (atomic_read(&card->u.x.command_busy)){
  598. wp->tx_timer.expires = jiffies + SLOW_BACKOFF;
  599. add_timer(&wp->tx_timer);
  600. DBG_PRINTK(KERN_INFO "wansock: Tx Timer, command bys BACKOFF\n");
  601. return;
  602. }
  603. if (test_and_set_bit(0,&wanpipe_tx_critical)){
  604. printk(KERN_INFO "WanSock: Tx timer critical %s\n",dev->name);
  605. wp->tx_timer.expires = jiffies + SLOW_BACKOFF;
  606. add_timer(&wp->tx_timer);
  607. return;
  608. }
  609. /* Check for a packet in the fifo and send */
  610. if ((skb = skb_dequeue(&sk->sk_write_queue)) != NULL){
  611. if (dev->hard_start_xmit(skb, dev) != 0){
  612. /* Driver failed to transmit, re-enqueue
  613. * the packet and retry again later */
  614. skb_queue_head(&sk->sk_write_queue,skb);
  615. clear_bit(0,&wanpipe_tx_critical);
  616. return;
  617. }else{
  618. /* Packet Sent successful. Check for more packets
  619. * if more packets, re-trigger the transmit routine
  620. * other wise exit
  621. */
  622. atomic_dec(&wp->packet_sent);
  623. if (skb_peek(&sk->sk_write_queue) == NULL) {
  624. /* If there is nothing to send, kick
  625. * the poll routine, which will trigger
  626. * the application to send more data */
  627. sk->sk_data_ready(sk, 0);
  628. clear_bit(0, &wp->timer);
  629. }else{
  630. /* Reschedule as fast as possible */
  631. wp->tx_timer.expires = jiffies + 1;
  632. add_timer(&wp->tx_timer);
  633. }
  634. }
  635. }
  636. clear_bit(0,&wanpipe_tx_critical);
  637. }
  638. /*============================================================
  639. * execute_command
  640. *
  641. * Execute x25api commands. The atomic variable
  642. * chan->command is used to indicate to the driver that
  643. * command is pending for execution. The acutal command
  644. * structure is placed into a sock mbox structure
  645. * (wp_sk(sk)->mbox).
  646. *
  647. * The sock private structure, mbox is
  648. * used as shared memory between sock and the driver.
  649. * Driver uses the sock mbox to execute the command
  650. * and return the result.
  651. *
  652. * For all command except PLACE CALL, the function
  653. * waits for the result. PLACE CALL can be ether
  654. * blocking or nonblocking. The user sets this option
  655. * via ioctl call.
  656. *===========================================================*/
  657. static int execute_command(struct sock *sk, unsigned char cmd, unsigned int flags)
  658. {
  659. wanpipe_opt *wp = wp_sk(sk);
  660. struct net_device *dev;
  661. wanpipe_common_t *chan=NULL;
  662. int err=0;
  663. DECLARE_WAITQUEUE(wait, current);
  664. dev = dev_get_by_index(sk->sk_bound_dev_if);
  665. if (dev == NULL){
  666. printk(KERN_INFO "wansock: Exec failed no dev %i\n",
  667. sk->sk_bound_dev_if);
  668. return -ENODEV;
  669. }
  670. dev_put(dev);
  671. if ((chan=dev->priv) == NULL){
  672. printk(KERN_INFO "wansock: Exec cmd failed no priv area\n");
  673. return -ENODEV;
  674. }
  675. if (atomic_read(&chan->command)){
  676. printk(KERN_INFO "wansock: ERROR: Command already running %x, %s\n",
  677. atomic_read(&chan->command),dev->name);
  678. return -EINVAL;
  679. }
  680. if (!wp->mbox) {
  681. printk(KERN_INFO "wansock: In execute without MBOX\n");
  682. return -EINVAL;
  683. }
  684. ((mbox_cmd_t*)wp->mbox)->cmd.command = cmd;
  685. ((mbox_cmd_t*)wp->mbox)->cmd.lcn = wp->lcn;
  686. ((mbox_cmd_t*)wp->mbox)->cmd.result = 0x7F;
  687. if (flags & O_NONBLOCK){
  688. cmd |= 0x80;
  689. atomic_set(&chan->command, cmd);
  690. }else{
  691. atomic_set(&chan->command, cmd);
  692. }
  693. add_wait_queue(sk->sk_sleep,&wait);
  694. current->state = TASK_INTERRUPTIBLE;
  695. for (;;){
  696. if (((mbox_cmd_t*)wp->mbox)->cmd.result != 0x7F) {
  697. err = 0;
  698. break;
  699. }
  700. if (signal_pending(current)) {
  701. err = -ERESTARTSYS;
  702. break;
  703. }
  704. schedule();
  705. }
  706. current->state = TASK_RUNNING;
  707. remove_wait_queue(sk->sk_sleep,&wait);
  708. return err;
  709. }
  710. /*============================================================
  711. * wanpipe_destroy_timer
  712. *
  713. * Used by wanpipe_release, to delay release of
  714. * the socket.
  715. *===========================================================*/
  716. static void wanpipe_destroy_timer(unsigned long data)
  717. {
  718. struct sock *sk=(struct sock *)data;
  719. wanpipe_opt *wp = wp_sk(sk);
  720. if ((!atomic_read(&sk->sk_wmem_alloc) &&
  721. !atomic_read(&sk->sk_rmem_alloc)) ||
  722. (++wp->force == 5)) {
  723. if (atomic_read(&sk->sk_wmem_alloc) ||
  724. atomic_read(&sk->sk_rmem_alloc))
  725. printk(KERN_INFO "wansock: Warning, Packet Discarded due to sock shutdown!\n");
  726. kfree(wp);
  727. wp_sk(sk) = NULL;
  728. if (atomic_read(&sk->sk_refcnt) != 1) {
  729. atomic_set(&sk->sk_refcnt, 1);
  730. DBG_PRINTK(KERN_INFO "wansock: Error, wrong reference count: %i ! :delay.\n",
  731. atomic_read(&sk->sk_refcnt));
  732. }
  733. sock_put(sk);
  734. atomic_dec(&wanpipe_socks_nr);
  735. return;
  736. }
  737. sk->sk_timer.expires = jiffies + 5 * HZ;
  738. add_timer(&sk->sk_timer);
  739. printk(KERN_INFO "wansock: packet sk destroy delayed\n");
  740. }
  741. /*============================================================
  742. * wanpipe_unlink_driver
  743. *
  744. * When the socket is released, this function is
  745. * used to remove links that bind the sock and the
  746. * driver together.
  747. *===========================================================*/
  748. static void wanpipe_unlink_driver (struct sock *sk)
  749. {
  750. struct net_device *dev;
  751. wanpipe_common_t *chan=NULL;
  752. sock_reset_flag(sk, SOCK_ZAPPED);
  753. sk->sk_state = WANSOCK_DISCONNECTED;
  754. wp_sk(sk)->dev = NULL;
  755. dev = dev_get_by_index(sk->sk_bound_dev_if);
  756. if (!dev){
  757. printk(KERN_INFO "wansock: No dev on release\n");
  758. return;
  759. }
  760. dev_put(dev);
  761. if ((chan = dev->priv) == NULL){
  762. printk(KERN_INFO "wansock: No Priv Area on release\n");
  763. return;
  764. }
  765. set_bit(0,&chan->common_critical);
  766. chan->sk=NULL;
  767. chan->func=NULL;
  768. chan->mbox=NULL;
  769. chan->tx_timer=NULL;
  770. clear_bit(0,&chan->common_critical);
  771. release_device(dev);
  772. return;
  773. }
  774. /*============================================================
  775. * wanpipe_link_driver
  776. *
  777. * Upon successful bind(), sock is linked to a driver
  778. * by binding in the wanpipe_rcv() bottom half handler
  779. * to the driver function pointer, as well as sock and
  780. * sock mailbox addresses. This way driver can pass
  781. * data up the socket.
  782. *===========================================================*/
  783. static void wanpipe_link_driver(struct net_device *dev, struct sock *sk)
  784. {
  785. wanpipe_opt *wp = wp_sk(sk);
  786. wanpipe_common_t *chan = dev->priv;
  787. if (!chan)
  788. return;
  789. set_bit(0,&chan->common_critical);
  790. chan->sk=sk;
  791. chan->func=wanpipe_rcv;
  792. chan->mbox = wp->mbox;
  793. chan->tx_timer = &wp->tx_timer;
  794. wp->dev = dev;
  795. sock_set_flag(sk, SOCK_ZAPPED);
  796. clear_bit(0,&chan->common_critical);
  797. }
  798. /*============================================================
  799. * release_device
  800. *
  801. * During sock release, clear a critical bit, which
  802. * marks the device a being taken.
  803. *===========================================================*/
  804. static void release_device(struct net_device *dev)
  805. {
  806. wanpipe_common_t *chan=dev->priv;
  807. clear_bit(0,(void*)&chan->rw_bind);
  808. }
  809. /*============================================================
  810. * wanpipe_release
  811. *
  812. * Close a PACKET socket. This is fairly simple. We
  813. * immediately go to 'closed' state and remove our
  814. * protocol entry in the device list.
  815. *===========================================================*/
  816. static int wanpipe_release(struct socket *sock)
  817. {
  818. wanpipe_opt *wp;
  819. struct sock *sk = sock->sk;
  820. if (!sk)
  821. return 0;
  822. wp = wp_sk(sk);
  823. check_write_queue(sk);
  824. /* Kill the tx timer, if we don't kill it now, the timer
  825. * will run after we kill the sock. Timer code will
  826. * try to access the sock which has been killed and cause
  827. * kernel panic */
  828. del_timer(&wp->tx_timer);
  829. /*
  830. * Unhook packet receive handler.
  831. */
  832. if (wp->num == htons(X25_PROT) &&
  833. sk->sk_state != WANSOCK_DISCONNECTED && sock_flag(sk, SOCK_ZAPPED)) {
  834. struct net_device *dev = dev_get_by_index(sk->sk_bound_dev_if);
  835. wanpipe_common_t *chan;
  836. if (dev){
  837. chan=dev->priv;
  838. atomic_set(&chan->disconnect,1);
  839. DBG_PRINTK(KERN_INFO "wansock: Sending Clear Indication %i\n",
  840. sk->sk_state);
  841. dev_put(dev);
  842. }
  843. }
  844. set_bit(1,&wanpipe_tx_critical);
  845. write_lock(&wanpipe_sklist_lock);
  846. sk_del_node_init(sk);
  847. write_unlock(&wanpipe_sklist_lock);
  848. clear_bit(1,&wanpipe_tx_critical);
  849. release_driver(sk);
  850. /*
  851. * Now the socket is dead. No more input will appear.
  852. */
  853. sk->sk_state_change(sk); /* It is useless. Just for sanity. */
  854. sock->sk = NULL;
  855. sk->sk_socket = NULL;
  856. sock_set_flag(sk, SOCK_DEAD);
  857. /* Purge queues */
  858. skb_queue_purge(&sk->sk_receive_queue);
  859. skb_queue_purge(&sk->sk_write_queue);
  860. skb_queue_purge(&sk->sk_error_queue);
  861. if (atomic_read(&sk->sk_rmem_alloc) ||
  862. atomic_read(&sk->sk_wmem_alloc)) {
  863. del_timer(&sk->sk_timer);
  864. printk(KERN_INFO "wansock: Killing in Timer R %i , W %i\n",
  865. atomic_read(&sk->sk_rmem_alloc),
  866. atomic_read(&sk->sk_wmem_alloc));
  867. sk->sk_timer.data = (unsigned long)sk;
  868. sk->sk_timer.expires = jiffies + HZ;
  869. sk->sk_timer.function = wanpipe_destroy_timer;
  870. add_timer(&sk->sk_timer);
  871. return 0;
  872. }
  873. kfree(wp);
  874. wp_sk(sk) = NULL;
  875. if (atomic_read(&sk->sk_refcnt) != 1) {
  876. DBG_PRINTK(KERN_INFO "wansock: Error, wrong reference count: %i !:release.\n",
  877. atomic_read(&sk->sk_refcnt));
  878. atomic_set(&sk->sk_refcnt, 1);
  879. }
  880. sock_put(sk);
  881. atomic_dec(&wanpipe_socks_nr);
  882. return 0;
  883. }
  884. /*============================================================
  885. * check_write_queue
  886. *
  887. * During sock shutdown, if the sock state is
  888. * WANSOCK_CONNECTED and there is transmit data
  889. * pending. Wait until data is released
  890. * before proceeding.
  891. *===========================================================*/
  892. static void check_write_queue(struct sock *sk)
  893. {
  894. if (sk->sk_state != WANSOCK_CONNECTED)
  895. return;
  896. if (!atomic_read(&sk->sk_wmem_alloc))
  897. return;
  898. printk(KERN_INFO "wansock: MAJOR ERROR, Data lost on sock release !!!\n");
  899. }
  900. /*============================================================
  901. * release_driver
  902. *
  903. * This function is called during sock shutdown, to
  904. * release any resources and links that bind the sock
  905. * to the driver. It also changes the state of the
  906. * sock to WANSOCK_DISCONNECTED
  907. *===========================================================*/
  908. static void release_driver(struct sock *sk)
  909. {
  910. wanpipe_opt *wp;
  911. struct sk_buff *skb=NULL;
  912. struct sock *deadsk=NULL;
  913. if (sk->sk_state == WANSOCK_LISTEN ||
  914. sk->sk_state == WANSOCK_BIND_LISTEN) {
  915. while ((skb = skb_dequeue(&sk->sk_receive_queue)) != NULL) {
  916. if ((deadsk = get_newsk_from_skb(skb))){
  917. DBG_PRINTK (KERN_INFO "wansock: RELEASE: FOUND DEAD SOCK\n");
  918. sock_set_flag(deadsk, SOCK_DEAD);
  919. start_cleanup_timer(deadsk);
  920. }
  921. kfree_skb(skb);
  922. }
  923. if (sock_flag(sk, SOCK_ZAPPED))
  924. wanpipe_unlink_card(sk);
  925. }else{
  926. if (sock_flag(sk, SOCK_ZAPPED))
  927. wanpipe_unlink_driver(sk);
  928. }
  929. sk->sk_state = WANSOCK_DISCONNECTED;
  930. sk->sk_bound_dev_if = 0;
  931. sock_reset_flag(sk, SOCK_ZAPPED);
  932. wp = wp_sk(sk);
  933. if (wp && wp->mbox) {
  934. kfree(wp->mbox);
  935. wp->mbox = NULL;
  936. }
  937. }
  938. /*============================================================
  939. * start_cleanup_timer
  940. *
  941. * If new incoming call's are pending but the socket
  942. * is being released, start the timer which will
  943. * envoke the kill routines for pending socks.
  944. *===========================================================*/
  945. static void start_cleanup_timer (struct sock *sk)
  946. {
  947. del_timer(&sk->sk_timer);
  948. sk->sk_timer.data = (unsigned long)sk;
  949. sk->sk_timer.expires = jiffies + HZ;
  950. sk->sk_timer.function = wanpipe_kill_sock_timer;
  951. add_timer(&sk->sk_timer);
  952. }
  953. /*============================================================
  954. * wanpipe_kill_sock
  955. *
  956. * This is a function which performs actual killing
  957. * of the sock. It releases socket resources,
  958. * and unlinks the sock from the driver.
  959. *===========================================================*/
  960. static void wanpipe_kill_sock_timer (unsigned long data)
  961. {
  962. struct sock *sk = (struct sock *)data;
  963. struct sock **skp;
  964. if (!sk)
  965. return;
  966. /* This function can be called from interrupt. We must use
  967. * appropriate locks */
  968. if (test_bit(1,&wanpipe_tx_critical)){
  969. sk->sk_timer.expires = jiffies + 10;
  970. add_timer(&sk->sk_timer);
  971. return;
  972. }
  973. write_lock(&wanpipe_sklist_lock);
  974. sk_del_node_init(sk);
  975. write_unlock(&wanpipe_sklist_lock);
  976. if (wp_sk(sk)->num == htons(X25_PROT) &&
  977. sk->sk_state != WANSOCK_DISCONNECTED) {
  978. struct net_device *dev = dev_get_by_index(sk->sk_bound_dev_if);
  979. wanpipe_common_t *chan;
  980. if (dev){
  981. chan=dev->priv;
  982. atomic_set(&chan->disconnect,1);
  983. dev_put(dev);
  984. }
  985. }
  986. release_driver(sk);
  987. sk->sk_socket = NULL;
  988. /* Purge queues */
  989. skb_queue_purge(&sk->sk_receive_queue);
  990. skb_queue_purge(&sk->sk_write_queue);
  991. skb_queue_purge(&sk->sk_error_queue);
  992. if (atomic_read(&sk->sk_rmem_alloc) ||
  993. atomic_read(&sk->sk_wmem_alloc)) {
  994. del_timer(&sk->sk_timer);
  995. printk(KERN_INFO "wansock: Killing SOCK in Timer\n");
  996. sk->sk_timer.data = (unsigned long)sk;
  997. sk->sk_timer.expires = jiffies + HZ;
  998. sk->sk_timer.function = wanpipe_destroy_timer;
  999. add_timer(&sk->sk_timer);
  1000. return;
  1001. }
  1002. if (wp_sk(sk)) {
  1003. kfree(wp_sk(sk));
  1004. wp_sk(sk) = NULL;
  1005. }
  1006. if (atomic_read(&sk->sk_refcnt) != 1) {
  1007. atomic_set(&sk->sk_refcnt, 1);
  1008. DBG_PRINTK(KERN_INFO "wansock: Error, wrong reference count: %i ! :timer.\n",
  1009. atomic_read(&sk->sk_refcnt));
  1010. }
  1011. sock_put(sk);
  1012. atomic_dec(&wanpipe_socks_nr);
  1013. return;
  1014. }
  1015. static void wanpipe_kill_sock_accept (struct sock *sk)
  1016. {
  1017. struct sock **skp;
  1018. if (!sk)
  1019. return;
  1020. /* This function can be called from interrupt. We must use
  1021. * appropriate locks */
  1022. write_lock(&wanpipe_sklist_lock);
  1023. sk_del_node_init(sk);
  1024. write_unlock(&wanpipe_sklist_lock);
  1025. sk->sk_socket = NULL;
  1026. if (wp_sk(sk)) {
  1027. kfree(wp_sk(sk));
  1028. wp_sk(sk) = NULL;
  1029. }
  1030. if (atomic_read(&sk->sk_refcnt) != 1) {
  1031. atomic_set(&sk->sk_refcnt, 1);
  1032. DBG_PRINTK(KERN_INFO "wansock: Error, wrong reference count: %i ! :timer.\n",
  1033. atomic_read(&sk->sk_refcnt));
  1034. }
  1035. sock_put(sk);
  1036. atomic_dec(&wanpipe_socks_nr);
  1037. return;
  1038. }
  1039. static void wanpipe_kill_sock_irq (struct sock *sk)
  1040. {
  1041. if (!sk)
  1042. return;
  1043. sk->sk_socket = NULL;
  1044. if (wp_sk(sk)) {
  1045. kfree(wp_sk(sk));
  1046. wp_sk(sk) = NULL;
  1047. }
  1048. if (atomic_read(&sk->sk_refcnt) != 1) {
  1049. atomic_set(&sk->sk_refcnt, 1);
  1050. DBG_PRINTK(KERN_INFO "wansock: Error, wrong reference count: %i !:listen.\n",
  1051. atomic_read(&sk->sk_refcnt));
  1052. }
  1053. sock_put(sk);
  1054. atomic_dec(&wanpipe_socks_nr);
  1055. }
  1056. /*============================================================
  1057. * wanpipe_do_bind
  1058. *
  1059. * Bottom half of the binding system call.
  1060. * Once the wanpipe_bind() function checks the
  1061. * legality of the call, this function binds the
  1062. * sock to the driver.
  1063. *===========================================================*/
  1064. static int wanpipe_do_bind(struct sock *sk, struct net_device *dev,
  1065. int protocol)
  1066. {
  1067. wanpipe_opt *wp = wp_sk(sk);
  1068. wanpipe_common_t *chan=NULL;
  1069. int err=0;
  1070. if (sock_flag(sk, SOCK_ZAPPED)) {
  1071. err = -EALREADY;
  1072. goto bind_unlock_exit;
  1073. }
  1074. wp->num = protocol;
  1075. if (protocol == 0){
  1076. release_device(dev);
  1077. err = -EINVAL;
  1078. goto bind_unlock_exit;
  1079. }
  1080. if (dev) {
  1081. if (dev->flags&IFF_UP) {
  1082. chan=dev->priv;
  1083. sk->sk_state = chan->state;
  1084. if (wp->num == htons(X25_PROT) &&
  1085. sk->sk_state != WANSOCK_DISCONNECTED &&
  1086. sk->sk_state != WANSOCK_CONNECTING) {
  1087. DBG_PRINTK(KERN_INFO
  1088. "wansock: Binding to Device not DISCONNECTED %i\n",
  1089. sk->sk_state);
  1090. release_device(dev);
  1091. err = -EAGAIN;
  1092. goto bind_unlock_exit;
  1093. }
  1094. wanpipe_link_driver(dev,sk);
  1095. sk->sk_bound_dev_if = dev->ifindex;
  1096. /* X25 Specific option */
  1097. if (wp->num == htons(X25_PROT))
  1098. wp_sk(sk)->svc = chan->svc;
  1099. } else {
  1100. sk->sk_err = ENETDOWN;
  1101. sk->sk_error_report(sk);
  1102. release_device(dev);
  1103. err = -EINVAL;
  1104. }
  1105. } else {
  1106. err = -ENODEV;
  1107. }
  1108. bind_unlock_exit:
  1109. /* FIXME where is this lock */
  1110. return err;
  1111. }
  1112. /*============================================================
  1113. * wanpipe_bind
  1114. *
  1115. * BIND() System call, which is bound to the AF_WANPIPE
  1116. * operations structure. It checks for correct wanpipe
  1117. * card name, and cross references interface names with
  1118. * the card names. Thus, interface name must belong to
  1119. * the actual card.
  1120. *===========================================================*/
  1121. static int wanpipe_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
  1122. {
  1123. struct wan_sockaddr_ll *sll = (struct wan_sockaddr_ll*)uaddr;
  1124. struct sock *sk=sock->sk;
  1125. wanpipe_opt *wp = wp_sk(sk);
  1126. struct net_device *dev = NULL;
  1127. sdla_t *card=NULL;
  1128. char name[15];
  1129. /*
  1130. * Check legality
  1131. */
  1132. if (addr_len < sizeof(struct wan_sockaddr_ll)){
  1133. printk(KERN_INFO "wansock: Address length error\n");
  1134. return -EINVAL;
  1135. }
  1136. if (sll->sll_family != AF_WANPIPE){
  1137. printk(KERN_INFO "wansock: Illegal family name specified.\n");
  1138. return -EINVAL;
  1139. }
  1140. card = wanpipe_find_card (sll->sll_card);
  1141. if (!card){
  1142. printk(KERN_INFO "wansock: Wanpipe card not found: %s\n",sll->sll_card);
  1143. return -ENODEV;
  1144. }else{
  1145. wp_sk(sk)->card = (void *)card;
  1146. }
  1147. if (!strcmp(sll->sll_device,"svc_listen")){
  1148. /* Bind a sock to a card structure for listening
  1149. */
  1150. int err=0;
  1151. /* This is x25 specific area if protocol doesn't
  1152. * match, return error */
  1153. if (sll->sll_protocol != htons(X25_PROT))
  1154. return -EINVAL;
  1155. err= wanpipe_link_card (sk);
  1156. if (err < 0)
  1157. return err;
  1158. if (sll->sll_protocol)
  1159. wp->num = sll->sll_protocol;
  1160. sk->sk_state = WANSOCK_BIND_LISTEN;
  1161. return 0;
  1162. }else if (!strcmp(sll->sll_device,"svc_connect")){
  1163. /* This is x25 specific area if protocol doesn't
  1164. * match, return error */
  1165. if (sll->sll_protocol != htons(X25_PROT))
  1166. return -EINVAL;
  1167. /* Find a free device
  1168. */
  1169. dev = wanpipe_find_free_dev(card);
  1170. if (dev == NULL){
  1171. DBG_PRINTK(KERN_INFO "wansock: No free network devices for card %s\n",
  1172. card->devname);
  1173. return -EINVAL;
  1174. }
  1175. }else{
  1176. /* Bind a socket to a interface name
  1177. * This is used by PVC mostly
  1178. */
  1179. strlcpy(name,sll->sll_device,sizeof(name));
  1180. dev = dev_get_by_name(name);
  1181. if (dev == NULL){
  1182. printk(KERN_INFO "wansock: Failed to get Dev from name: %s,\n",
  1183. name);
  1184. return -ENODEV;
  1185. }
  1186. dev_put(dev);
  1187. if (check_dev(dev, card)){
  1188. printk(KERN_INFO "wansock: Device %s, doesn't belong to card %s\n",
  1189. dev->name, card->devname);
  1190. return -EINVAL;
  1191. }
  1192. if (get_atomic_device (dev))
  1193. return -EINVAL;
  1194. }
  1195. return wanpipe_do_bind(sk, dev, sll->sll_protocol ? : wp->num);
  1196. }
  1197. /*============================================================
  1198. * get_atomic_device
  1199. *
  1200. * Sets a bit atomically which indicates that
  1201. * the interface is taken. This avoids race conditions.
  1202. *===========================================================*/
  1203. static inline int get_atomic_device(struct net_device *dev)
  1204. {
  1205. wanpipe_common_t *chan = dev->priv;
  1206. if (!test_and_set_bit(0,(void *)&chan->rw_bind)){
  1207. return 0;
  1208. }
  1209. return 1;
  1210. }
  1211. /*============================================================
  1212. * check_dev
  1213. *
  1214. * Check that device name belongs to a particular card.
  1215. *===========================================================*/
  1216. static int check_dev(struct net_device *dev, sdla_t *card)
  1217. {
  1218. struct net_device* tmp_dev;
  1219. for (tmp_dev = card->wandev.dev; tmp_dev;
  1220. tmp_dev = *((struct net_device **)tmp_dev->priv)) {
  1221. if (tmp_dev->ifindex == dev->ifindex){
  1222. return 0;
  1223. }
  1224. }
  1225. return 1;
  1226. }
  1227. /*============================================================
  1228. * wanpipe_find_free_dev
  1229. *
  1230. * Find a free network interface. If found set atomic
  1231. * bit indicating that the interface is taken.
  1232. * X25API Specific.
  1233. *===========================================================*/
  1234. struct net_device *wanpipe_find_free_dev(sdla_t *card)
  1235. {
  1236. struct net_device* dev;
  1237. volatile wanpipe_common_t *chan;
  1238. if (test_and_set_bit(0,&find_free_critical)){
  1239. printk(KERN_INFO "CRITICAL in Find Free\n");
  1240. }
  1241. for (dev = card->wandev.dev; dev;
  1242. dev = *((struct net_device **)dev->priv)) {
  1243. chan = dev->priv;
  1244. if (!chan)
  1245. continue;
  1246. if (chan->usedby == API && chan->svc){
  1247. if (!get_atomic_device (dev)){
  1248. if (chan->state != WANSOCK_DISCONNECTED){
  1249. release_device(dev);
  1250. }else{
  1251. clear_bit(0,&find_free_critical);
  1252. return dev;
  1253. }
  1254. }
  1255. }
  1256. }
  1257. clear_bit(0,&find_free_critical);
  1258. return NULL;
  1259. }
  1260. /*============================================================
  1261. * wanpipe_create
  1262. *
  1263. * SOCKET() System call. It allocates a sock structure
  1264. * and adds the socket to the wanpipe_sk_list.
  1265. * Crates AF_WANPIPE socket.
  1266. *===========================================================*/
  1267. static int wanpipe_create(struct socket *sock, int protocol)
  1268. {
  1269. struct sock *sk;
  1270. //FIXME: This checks for root user, SECURITY ?
  1271. //if (!capable(CAP_NET_RAW))
  1272. // return -EPERM;
  1273. if (sock->type != SOCK_DGRAM && sock->type != SOCK_RAW)
  1274. return -ESOCKTNOSUPPORT;
  1275. sock->state = SS_UNCONNECTED;
  1276. if ((sk = wanpipe_alloc_socket()) == NULL)
  1277. return -ENOBUFS;
  1278. sk->sk_reuse = 1;
  1279. sock->ops = &wanpipe_ops;
  1280. sock_init_data(sock,sk);
  1281. sock_reset_flag(sk, SOCK_ZAPPED);
  1282. sk->sk_family = PF_WANPIPE;
  1283. wp_sk(sk)->num = protocol;
  1284. sk->sk_state = WANSOCK_DISCONNECTED;
  1285. sk->sk_ack_backlog = 0;
  1286. sk->sk_bound_dev_if = 0;
  1287. atomic_inc(&wanpipe_socks_nr);
  1288. /* We must disable interrupts because the ISR
  1289. * can also change the list */
  1290. set_bit(1,&wanpipe_tx_critical);
  1291. write_lock(&wanpipe_sklist_lock);
  1292. sk_add_node(sk, &wanpipe_sklist);
  1293. write_unlock(&wanpipe_sklist_lock);
  1294. clear_bit(1,&wanpipe_tx_critical);
  1295. return(0);
  1296. }
  1297. /*============================================================
  1298. * wanpipe_recvmsg
  1299. *
  1300. * Pull a packet from our receive queue and hand it
  1301. * to the user. If necessary we block.
  1302. *===========================================================*/
  1303. static int wanpipe_recvmsg(struct kiocb *iocb, struct socket *sock,
  1304. struct msghdr *msg, int len, int flags)
  1305. {
  1306. struct sock *sk = sock->sk;
  1307. struct sk_buff *skb;
  1308. int copied, err=-ENOBUFS;
  1309. /*
  1310. * If the address length field is there to be filled in, we fill
  1311. * it in now.
  1312. */
  1313. msg->msg_namelen = sizeof(struct wan_sockaddr_ll);
  1314. /*
  1315. * Call the generic datagram receiver. This handles all sorts
  1316. * of horrible races and re-entrancy so we can forget about it
  1317. * in the protocol layers.
  1318. *
  1319. * Now it will return ENETDOWN, if device have just gone down,
  1320. * but then it will block.
  1321. */
  1322. if (flags & MSG_OOB){
  1323. skb = skb_dequeue(&sk->sk_error_queue);
  1324. }else{
  1325. skb=skb_recv_datagram(sk,flags,1,&err);
  1326. }
  1327. /*
  1328. * An error occurred so return it. Because skb_recv_datagram()
  1329. * handles the blocking we don't see and worry about blocking
  1330. * retries.
  1331. */
  1332. if(skb==NULL)
  1333. goto out;
  1334. /*
  1335. * You lose any data beyond the buffer you gave. If it worries a
  1336. * user program they can ask the device for its MTU anyway.
  1337. */
  1338. copied = skb->len;
  1339. if (copied > len)
  1340. {
  1341. copied=len;
  1342. msg->msg_flags|=MSG_TRUNC;
  1343. }
  1344. wanpipe_wakeup_driver(sk);
  1345. /* We can't use skb_copy_datagram here */
  1346. err = memcpy_toiovec(msg->msg_iov, skb->data, copied);
  1347. if (err)
  1348. goto out_free;
  1349. sock_recv_timestamp(msg, sk, skb);
  1350. if (msg->msg_name)
  1351. memcpy(msg->msg_name, skb->cb, msg->msg_namelen);
  1352. /*
  1353. * Free or return the buffer as appropriate. Again this
  1354. * hides all the races and re-entrancy issues from us.
  1355. */
  1356. err = (flags&MSG_TRUNC) ? skb->len : copied;
  1357. out_free:
  1358. skb_free_datagram(sk, skb);
  1359. out:
  1360. return err;
  1361. }
  1362. /*============================================================
  1363. * wanpipe_wakeup_driver
  1364. *
  1365. * If socket receive buffer is full and driver cannot
  1366. * pass data up the sock, it sets a packet_block flag.
  1367. * This function check that flag and if sock receive
  1368. * queue has room it kicks the driver BH handler.
  1369. *
  1370. * This way, driver doesn't have to poll the sock
  1371. * receive queue.
  1372. *===========================================================*/
  1373. static void wanpipe_wakeup_driver(struct sock *sk)
  1374. {
  1375. struct net_device *dev = NULL;
  1376. wanpipe_common_t *chan=NULL;
  1377. dev = dev_get_by_index(sk->sk_bound_dev_if);
  1378. if (!dev)
  1379. return;
  1380. dev_put(dev);
  1381. if ((chan = dev->priv) == NULL)
  1382. return;
  1383. if (atomic_read(&chan->receive_block)){
  1384. if (atomic_read(&sk->sk_rmem_alloc) <
  1385. ((unsigned)sk->sk_rcvbuf * 0.9)) {
  1386. printk(KERN_INFO "wansock: Queuing task for wanpipe\n");
  1387. atomic_set(&chan->receive_block,0);
  1388. wanpipe_queue_tq(&chan->wanpipe_task);
  1389. wanpipe_mark_bh();
  1390. }
  1391. }
  1392. }
  1393. /*============================================================
  1394. * wanpipe_getname
  1395. *
  1396. * I don't know what to do with this yet.
  1397. * User can use this function to get sock address
  1398. * information. Not very useful for Sangoma's purposes.
  1399. *===========================================================*/
  1400. static int wanpipe_getname(struct socket *sock, struct sockaddr *uaddr,
  1401. int *uaddr_len, int peer)
  1402. {
  1403. struct net_device *dev;
  1404. struct sock *sk = sock->sk;
  1405. struct wan_sockaddr_ll *sll = (struct wan_sockaddr_ll*)uaddr;
  1406. sll->sll_family = AF_WANPIPE;
  1407. sll->sll_ifindex = sk->sk_bound_dev_if;
  1408. sll->sll_protocol = wp_sk(sk)->num;
  1409. dev = dev_get_by_index(sk->sk_bound_dev_if);
  1410. if (dev) {
  1411. sll->sll_hatype = dev->type;
  1412. sll->sll_halen = dev->addr_len;
  1413. memcpy(sll->sll_addr, dev->dev_addr, dev->addr_len);
  1414. } else {
  1415. sll->sll_hatype = 0; /* Bad: we have no ARPHRD_UNSPEC */
  1416. sll->sll_halen = 0;
  1417. }
  1418. *uaddr_len = sizeof(*sll);
  1419. dev_put(dev);
  1420. return 0;
  1421. }
  1422. /*============================================================
  1423. * wanpipe_notifier
  1424. *
  1425. * If driver turns off network interface, this function
  1426. * will be envoked. Currently I treate it as a
  1427. * call disconnect. More thought should go into this
  1428. * function.
  1429. *
  1430. * FIXME: More thought should go into this function.
  1431. *
  1432. *===========================================================*/
  1433. static int wanpipe_notifier(struct notifier_block *this, unsigned long msg, void *data)
  1434. {
  1435. struct sock *sk;
  1436. hlist_node *node;
  1437. struct net_device *dev = (struct net_device *)data;
  1438. sk_for_each(sk, node, &wanpipe_sklist) {
  1439. struct wanpipe_opt *po = wp_sk(sk);
  1440. if (!po)
  1441. continue;
  1442. if (dev == NULL)
  1443. continue;
  1444. switch (msg) {
  1445. case NETDEV_DOWN:
  1446. case NETDEV_UNREGISTER:
  1447. if (dev->ifindex == sk->sk_bound_dev_if) {
  1448. printk(KERN_INFO "wansock: Device down %s\n",dev->name);
  1449. if (sock_flag(sk, SOCK_ZAPPED)) {
  1450. wanpipe_unlink_driver(sk);
  1451. sk->sk_err = ENETDOWN;
  1452. sk->sk_error_report(sk);
  1453. }
  1454. if (msg == NETDEV_UNREGISTER) {
  1455. printk(KERN_INFO "wansock: Unregistering Device: %s\n",
  1456. dev->name);
  1457. wanpipe_unlink_driver(sk);
  1458. sk->sk_bound_dev_if = 0;
  1459. }
  1460. }
  1461. break;
  1462. case NETDEV_UP:
  1463. if (dev->ifindex == sk->sk_bound_dev_if &&
  1464. po->num && !sock_flag(sk, SOCK_ZAPPED)) {
  1465. printk(KERN_INFO "wansock: Registering Device: %s\n",
  1466. dev->name);
  1467. wanpipe_link_driver(dev,sk);
  1468. }
  1469. break;
  1470. }
  1471. }
  1472. return NOTIFY_DONE;
  1473. }
  1474. /*============================================================
  1475. * wanpipe_ioctl
  1476. *
  1477. * Execute a user commands, and set socket options.
  1478. *
  1479. * FIXME: More thought should go into this function.
  1480. *
  1481. *===========================================================*/
  1482. static int wanpipe_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
  1483. {
  1484. struct sock *sk = sock->sk;
  1485. int err;
  1486. switch(cmd)
  1487. {
  1488. case SIOCGSTAMP:
  1489. return sock_get_timestamp(sk, (struct timeval __user *)arg);
  1490. case SIOC_WANPIPE_CHECK_TX:
  1491. return atomic_read(&sk->sk_wmem_alloc);
  1492. case SIOC_WANPIPE_SOCK_STATE:
  1493. if (sk->sk_state == WANSOCK_CONNECTED)
  1494. return 0;
  1495. return 1;
  1496. case SIOC_WANPIPE_GET_CALL_DATA:
  1497. return get_ioctl_cmd (sk,(void*)arg);
  1498. case SIOC_WANPIPE_SET_CALL_DATA:
  1499. return set_ioctl_cmd (sk,(void*)arg);
  1500. case SIOC_WANPIPE_ACCEPT_CALL:
  1501. case SIOC_WANPIPE_CLEAR_CALL:
  1502. case SIOC_WANPIPE_RESET_CALL:
  1503. if ((err=set_ioctl_cmd(sk,(void*)arg)) < 0)
  1504. return err;
  1505. err=wanpipe_exec_cmd(sk,cmd,0);
  1506. get_ioctl_cmd(sk,(void*)arg);
  1507. return err;
  1508. case SIOC_WANPIPE_DEBUG:
  1509. return wanpipe_debug(sk,(void*)arg);
  1510. case SIOC_WANPIPE_SET_NONBLOCK:
  1511. if (sk->sk_state != WANSOCK_DISCONNECTED)
  1512. return -EINVAL;
  1513. sock->file->f_flags |= O_NONBLOCK;
  1514. return 0;
  1515. #ifdef CONFIG_INET
  1516. case SIOCADDRT:
  1517. case SIOCDELRT:
  1518. case SIOCDARP:
  1519. case SIOCGARP:
  1520. case SIOCSARP:
  1521. case SIOCDRARP:
  1522. case SIOCGRARP:
  1523. case SIOCSRARP:
  1524. case SIOCGIFADDR:
  1525. case SIOCSIFADDR:
  1526. case SIOCGIFBRDADDR:
  1527. case SIOCSIFBRDADDR:
  1528. case SIOCGIFNETMASK:
  1529. case SIOCSIFNETMASK:
  1530. case SIOCGIFDSTADDR:
  1531. case SIOCSIFDSTADDR:
  1532. case SIOCSIFFLAGS:
  1533. return inet_dgram_ops.ioctl(sock, cmd, arg);
  1534. #endif
  1535. default:
  1536. return dev_ioctl(cmd,(void __user *) arg);
  1537. }
  1538. /*NOTREACHED*/
  1539. }
  1540. /*============================================================
  1541. * wanpipe_debug
  1542. *
  1543. * This function will pass up information about all
  1544. * active sockets.
  1545. *
  1546. * FIXME: More thought should go into this function.
  1547. *
  1548. *===========================================================*/
  1549. static int wanpipe_debug (struct sock *origsk, void *arg)
  1550. {
  1551. struct sock *sk;
  1552. struct hlist_node *node;
  1553. struct net_device *dev = NULL;
  1554. wanpipe_common_t *chan=NULL;
  1555. int cnt=0, err=0;
  1556. wan_debug_t *dbg_data = (wan_debug_t *)arg;
  1557. sk_for_each(sk, node, &wanpipe_sklist) {
  1558. wanpipe_opt *wp = wp_sk(sk);
  1559. if (sk == origsk){
  1560. continue;
  1561. }
  1562. if ((err=put_user(1, &dbg_data->debug[cnt].free)))
  1563. return err;
  1564. if ((err = put_user(sk->sk_state,
  1565. &dbg_data->debug[cnt].state_sk)))
  1566. return err;
  1567. if ((err = put_user(sk->sk_rcvbuf,
  1568. &dbg_data->debug[cnt].rcvbuf)))
  1569. return err;
  1570. if ((err = put_user(atomic_read(&sk->sk_rmem_alloc),
  1571. &dbg_data->debug[cnt].rmem)))
  1572. return err;
  1573. if ((err = put_user(atomic_read(&sk->sk_wmem_alloc),
  1574. &dbg_data->debug[cnt].wmem)))
  1575. return err;
  1576. if ((err = put_user(sk->sk_sndbuf,
  1577. &dbg_data->debug[cnt].sndbuf)))
  1578. return err;
  1579. if ((err=put_user(sk_count, &dbg_data->debug[cnt].sk_count)))
  1580. return err;
  1581. if ((err=put_user(wp->poll_cnt, &dbg_data->debug[cnt].poll_cnt)))
  1582. return err;
  1583. if ((err = put_user(sk->sk_bound_dev_if,
  1584. &dbg_data->debug[cnt].bound)))
  1585. return err;
  1586. if (sk->sk_bound_dev_if) {
  1587. dev = dev_get_by_index(sk->sk_bound_dev_if);
  1588. if (!dev)
  1589. continue;
  1590. chan=dev->priv;
  1591. dev_put(dev);
  1592. if ((err=put_user(chan->state, &dbg_data->debug[cnt].d_state)))
  1593. return err;
  1594. if ((err=put_user(chan->svc, &dbg_data->debug[cnt].svc)))
  1595. return err;
  1596. if ((err=put_user(atomic_read(&chan->command),
  1597. &dbg_data->debug[cnt].command)))
  1598. return err;
  1599. if (wp){
  1600. sdla_t *card = (sdla_t*)wp->card;
  1601. if (card){
  1602. if ((err=put_user(atomic_read(&card->u.x.command_busy),
  1603. &dbg_data->debug[cnt].cmd_busy)))
  1604. return err;
  1605. }
  1606. if ((err=put_user(wp->lcn,
  1607. &dbg_data->debug[cnt].lcn)))
  1608. return err;
  1609. if (wp->mbox) {
  1610. if ((err=put_user(1, &dbg_data->debug[cnt].mbox)))
  1611. return err;
  1612. }
  1613. }
  1614. if ((err=put_user(atomic_read(&chan->receive_block),
  1615. &dbg_data->debug[cnt].rblock)))
  1616. return err;
  1617. if (copy_to_user(dbg_data->debug[cnt].name, dev->name, strlen(dev->name)))
  1618. return -EFAULT;
  1619. }
  1620. if (++cnt == MAX_NUM_DEBUG)
  1621. break;
  1622. }
  1623. return 0;
  1624. }
  1625. /*============================================================
  1626. * get_ioctl_cmd
  1627. *
  1628. * Pass up the contents of socket MBOX to the user.
  1629. *===========================================================*/
  1630. static int get_ioctl_cmd (struct sock *sk, void *arg)
  1631. {
  1632. x25api_t *usr_data = (x25api_t *)arg;
  1633. mbox_cmd_t *mbox_ptr;
  1634. int err;
  1635. if (usr_data == NULL)
  1636. return -EINVAL;
  1637. if (!wp_sk(sk)->mbox) {
  1638. return -EINVAL;
  1639. }
  1640. mbox_ptr = (mbox_cmd_t *)wp_sk(sk)->mbox;
  1641. if ((err=put_user(mbox_ptr->cmd.qdm, &usr_data->hdr.qdm)))
  1642. return err;
  1643. if ((err=put_user(mbox_ptr->cmd.cause, &usr_data->hdr.cause)))
  1644. return err;
  1645. if ((err=put_user(mbox_ptr->cmd.diagn, &usr_data->hdr.diagn)))
  1646. return err;
  1647. if ((err=put_user(mbox_ptr->cmd.length, &usr_data->hdr.length)))
  1648. return err;
  1649. if ((err=put_user(mbox_ptr->cmd.result, &usr_data->hdr.result)))
  1650. return err;
  1651. if ((err=put_user(mbox_ptr->cmd.lcn, &usr_data->hdr.lcn)))
  1652. return err;
  1653. if (mbox_ptr->cmd.length > 0){
  1654. if (mbox_ptr->cmd.length > X25_MAX_DATA)
  1655. return -EINVAL;
  1656. if (copy_to_user(usr_data->data, mbox_ptr->data, mbox_ptr->cmd.length)){
  1657. printk(KERN_INFO "wansock: Copy failed !!!\n");
  1658. return -EFAULT;
  1659. }
  1660. }
  1661. return 0;
  1662. }
  1663. /*============================================================
  1664. * set_ioctl_cmd
  1665. *
  1666. * Before command can be execute, socket MBOX must
  1667. * be created, and initialized with user data.
  1668. *===========================================================*/
  1669. static int set_ioctl_cmd (struct sock *sk, void *arg)
  1670. {
  1671. x25api_t *usr_data = (x25api_t *)arg;
  1672. mbox_cmd_t *mbox_ptr;
  1673. int err;
  1674. if (!wp_sk(sk)->mbox) {
  1675. void *mbox_ptr;
  1676. struct net_device *dev = dev_get_by_index(sk->sk_bound_dev_if);
  1677. if (!dev)
  1678. return -ENODEV;
  1679. dev_put(dev);
  1680. if ((mbox_ptr = kmalloc(sizeof(mbox_cmd_t), GFP_ATOMIC)) == NULL)
  1681. return -ENOMEM;
  1682. memset(mbox_ptr, 0, sizeof(mbox_cmd_t));
  1683. wp_sk(sk)->mbox = mbox_ptr;
  1684. wanpipe_link_driver(dev,sk);
  1685. }
  1686. mbox_ptr = (mbox_cmd_t*)wp_sk(sk)->mbox;
  1687. memset(mbox_ptr, 0, sizeof(mbox_cmd_t));
  1688. if (usr_data == NULL){
  1689. return 0;
  1690. }
  1691. if ((err=get_user(mbox_ptr->cmd.qdm, &usr_data->hdr.qdm)))
  1692. return err;
  1693. if ((err=get_user(mbox_ptr->cmd.cause, &usr_data->hdr.cause)))
  1694. return err;
  1695. if ((err=get_user(mbox_ptr->cmd.diagn, &usr_data->hdr.diagn)))
  1696. return err;
  1697. if ((err=get_user(mbox_ptr->cmd.length, &usr_data->hdr.length)))
  1698. return err;
  1699. if ((err=get_user(mbox_ptr->cmd.result, &usr_data->hdr.result)))
  1700. return err;
  1701. if (mbox_ptr->cmd.length > 0){
  1702. if (mbox_ptr->cmd.length > X25_MAX_DATA)
  1703. return -EINVAL;
  1704. if (copy_from_user(mbox_ptr->data, usr_data->data, mbox_ptr->cmd.length)){
  1705. printk(KERN_INFO "Copy failed\n");
  1706. return -EFAULT;
  1707. }
  1708. }
  1709. return 0;
  1710. }
  1711. /*======================================================================
  1712. * wanpipe_poll
  1713. *
  1714. * Datagram poll: Again totally generic. This also handles
  1715. * sequenced packet sockets providing the socket receive queue
  1716. * is only ever holding data ready to receive.
  1717. *
  1718. * Note: when you _don't_ use this routine for this protocol,
  1719. * and you use a different write policy from sock_writeable()
  1720. * then please supply your own write_space callback.
  1721. *=====================================================================*/
  1722. unsigned int wanpipe_poll(struct file * file, struct socket *sock, poll_table *wait)
  1723. {
  1724. struct sock *sk = sock->sk;
  1725. unsigned int mask;
  1726. ++wp_sk(sk)->poll_cnt;
  1727. poll_wait(file, sk->sk_sleep, wait);
  1728. mask = 0;
  1729. /* exceptional events? */
  1730. if (sk->sk_err || !skb_queue_empty(&sk->sk_error_queue)) {
  1731. mask |= POLLPRI;
  1732. return mask;
  1733. }
  1734. if (sk->sk_shutdown & RCV_SHUTDOWN)
  1735. mask |= POLLHUP;
  1736. /* readable? */
  1737. if (!skb_queue_empty(&sk->sk_receive_queue)) {
  1738. mask |= POLLIN | POLLRDNORM;
  1739. }
  1740. /* connection hasn't started yet */
  1741. if (sk->sk_state == WANSOCK_CONNECTING) {
  1742. return mask;
  1743. }
  1744. if (sk->sk_state == WANSOCK_DISCONNECTED) {
  1745. mask = POLLPRI;
  1746. return mask;
  1747. }
  1748. /* This check blocks the user process if there is
  1749. * a packet already queued in the socket write queue.
  1750. * This option is only for X25API protocol, for other
  1751. * protocol like chdlc enable streaming mode,
  1752. * where multiple packets can be pending in the socket
  1753. * transmit queue */
  1754. if (wp_sk(sk)->num == htons(X25_PROT)) {
  1755. if (atomic_read(&wp_sk(sk)->packet_sent))
  1756. return mask;
  1757. }
  1758. /* writable? */
  1759. if (sock_writeable(sk)){
  1760. mask |= POLLOUT | POLLWRNORM | POLLWRBAND;
  1761. }else{
  1762. set_bit(SOCK_ASYNC_NOSPACE, &sk->sk_socket->flags);
  1763. }
  1764. return mask;
  1765. }
  1766. /*======================================================================
  1767. * wanpipe_listen
  1768. *
  1769. * X25API Specific function. Set a socket into LISTENING MODE.
  1770. *=====================================================================*/
  1771. static int wanpipe_listen(struct socket *sock, int backlog)
  1772. {
  1773. struct sock *sk = sock->sk;
  1774. /* This is x25 specific area if protocol doesn't
  1775. * match, return error */
  1776. if (wp_sk(sk)->num != htons(X25_PROT))
  1777. return -EINVAL;
  1778. if (sk->sk_state == WANSOCK_BIND_LISTEN) {
  1779. sk->sk_max_ack_backlog = backlog;
  1780. sk->sk_state = WANSOCK_LISTEN;
  1781. return 0;
  1782. }else{
  1783. printk(KERN_INFO "wansock: Listening sock was not binded\n");
  1784. }
  1785. return -EINVAL;
  1786. }
  1787. /*======================================================================
  1788. * wanpipe_link_card
  1789. *
  1790. * Connects the listening socket to the driver
  1791. *=====================================================================*/
  1792. static int wanpipe_link_card (struct sock *sk)
  1793. {
  1794. sdla_t *card = (sdla_t*)wp_sk(sk)->card;
  1795. if (!card)
  1796. return -ENOMEM;
  1797. if ((card->sk != NULL) || (card->func != NULL)){
  1798. printk(KERN_INFO "wansock: Listening queue is already established\n");
  1799. return -EINVAL;
  1800. }
  1801. card->sk=sk;
  1802. card->func=wanpipe_listen_rcv;
  1803. sock_set_flag(sk, SOCK_ZAPPED);
  1804. return 0;
  1805. }
  1806. /*======================================================================
  1807. * wanpipe_listen
  1808. *
  1809. * X25API Specific function. Disconnect listening socket from
  1810. * the driver.
  1811. *=====================================================================*/
  1812. static void wanpipe_unlink_card (struct sock *sk)
  1813. {
  1814. sdla_t *card = (sdla_t*)wp_sk(sk)->card;
  1815. if (card){
  1816. card->sk=NULL;
  1817. card->func=NULL;
  1818. }
  1819. }
  1820. /*======================================================================
  1821. * wanpipe_exec_cmd
  1822. *
  1823. * Ioctl function calls this function to execute user command.
  1824. * Connect() sytem call also calls this function to execute
  1825. * place call. This function blocks until command is executed.
  1826. *=====================================================================*/
  1827. static int wanpipe_exec_cmd(struct sock *sk, int cmd, unsigned int flags)
  1828. {
  1829. int err = -EINVAL;
  1830. wanpipe_opt *wp = wp_sk(sk);
  1831. mbox_cmd_t *mbox_ptr = (mbox_cmd_t*)wp->mbox;
  1832. if (!mbox_ptr){
  1833. printk(KERN_INFO "NO MBOX PTR !!!!!\n");
  1834. return -EINVAL;
  1835. }
  1836. /* This is x25 specific area if protocol doesn't
  1837. * match, return error */
  1838. if (wp->num != htons(X25_PROT))
  1839. return -EINVAL;
  1840. switch (cmd){
  1841. case SIOC_WANPIPE_ACCEPT_CALL:
  1842. if (sk->sk_state != WANSOCK_CONNECTING) {
  1843. err = -EHOSTDOWN;
  1844. break;
  1845. }
  1846. err = execute_command(sk,X25_ACCEPT_CALL,0);
  1847. if (err < 0)
  1848. break;
  1849. /* Update. Mar6 2000.
  1850. * Do not set the sock lcn number here, since
  1851. * it is done in wanpipe_listen_rcv().
  1852. */
  1853. if (sk->sk_state == WANSOCK_CONNECTED) {
  1854. wp->lcn = ((mbox_cmd_t*)wp->mbox)->cmd.lcn;
  1855. DBG_PRINTK(KERN_INFO "\nwansock: Accept OK %i\n",
  1856. wp->lcn);
  1857. err = 0;
  1858. }else{
  1859. DBG_PRINTK (KERN_INFO "\nwansock: Accept Failed %i\n",
  1860. wp->lcn);
  1861. wp->lcn = 0;
  1862. err = -ECONNREFUSED;
  1863. }
  1864. break;
  1865. case SIOC_WANPIPE_CLEAR_CALL:
  1866. if (sk->sk_state == WANSOCK_DISCONNECTED) {
  1867. err = -EINVAL;
  1868. break;
  1869. }
  1870. /* Check if data buffers are pending for transmission,
  1871. * if so, check whether user wants to wait until data
  1872. * is transmitted, or clear a call and drop packets */
  1873. if (atomic_read(&sk->sk_wmem_alloc) ||
  1874. check_driver_busy(sk)) {
  1875. mbox_cmd_t *mbox = wp->mbox;
  1876. if (mbox->cmd.qdm & 0x80){
  1877. mbox->cmd.result = 0x35;
  1878. err = -EAGAIN;
  1879. break;
  1880. }
  1881. }
  1882. sk->sk_state = WANSOCK_DISCONNECTING;
  1883. err = execute_command(sk,X25_CLEAR_CALL,0);
  1884. if (err < 0)
  1885. break;
  1886. err = -ECONNREFUSED;
  1887. if (sk->sk_state == WANSOCK_DISCONNECTED) {
  1888. DBG_PRINTK(KERN_INFO "\nwansock: CLEAR OK %i\n",
  1889. wp->lcn);
  1890. wp->lcn = 0;
  1891. err = 0;
  1892. }
  1893. break;
  1894. case SIOC_WANPIPE_RESET_CALL:
  1895. if (sk->sk_state != WANSOCK_CONNECTED) {
  1896. err = -EINVAL;
  1897. break;
  1898. }
  1899. /* Check if data buffers are pending for transmission,
  1900. * if so, check whether user wants to wait until data
  1901. * is transmitted, or reset a call and drop packets */
  1902. if (atomic_read(&sk->sk_wmem_alloc) ||
  1903. check_driver_busy(sk)) {
  1904. mbox_cmd_t *mbox = wp->mbox;
  1905. if (mbox->cmd.qdm & 0x80){
  1906. mbox->cmd.result = 0x35;
  1907. err = -EAGAIN;
  1908. break;
  1909. }
  1910. }
  1911. err = execute_command(sk, X25_RESET,0);
  1912. if (err < 0)
  1913. break;
  1914. err = mbox_ptr->cmd.result;
  1915. break;
  1916. case X25_PLACE_CALL:
  1917. err=execute_command(sk,X25_PLACE_CALL,flags);
  1918. if (err < 0)
  1919. break;
  1920. if (sk->sk_state == WANSOCK_CONNECTED) {
  1921. wp->lcn = ((mbox_cmd_t*)wp->mbox)->cmd.lcn;
  1922. DBG_PRINTK(KERN_INFO "\nwansock: PLACE CALL OK %i\n",
  1923. wp->lcn);
  1924. err = 0;
  1925. } else if (sk->sk_state == WANSOCK_CONNECTING &&
  1926. (flags & O_NONBLOCK)) {
  1927. wp->lcn = ((mbox_cmd_t*)wp->mbox)->cmd.lcn;
  1928. DBG_PRINTK(KERN_INFO "\nwansock: Place Call OK: Waiting %i\n",
  1929. wp->lcn);
  1930. err = 0;
  1931. }else{
  1932. DBG_PRINTK(KERN_INFO "\nwansock: Place call Failed\n");
  1933. err = -ECONNREFUSED;
  1934. }
  1935. break;
  1936. default:
  1937. return -EINVAL;
  1938. }
  1939. return err;
  1940. }
  1941. static int check_driver_busy (struct sock *sk)
  1942. {
  1943. struct net_device *dev = dev_get_by_index(sk->sk_bound_dev_if);
  1944. wanpipe_common_t *chan;
  1945. if (!dev)
  1946. return 0;
  1947. dev_put(dev);
  1948. if ((chan=dev->priv) == NULL)
  1949. return 0;
  1950. return atomic_read(&chan->driver_busy);
  1951. }
  1952. /*======================================================================
  1953. * wanpipe_accept
  1954. *
  1955. * ACCEPT() System call. X25API Specific function.
  1956. * For each incoming call, create a new socket and
  1957. * return it to the user.
  1958. *=====================================================================*/
  1959. static int wanpipe_accept(struct socket *sock, struct socket *newsock, int flags)
  1960. {
  1961. struct sock *sk;
  1962. struct sock *newsk;
  1963. struct sk_buff *skb;
  1964. DECLARE_WAITQUEUE(wait, current);
  1965. int err=0;
  1966. if (newsock->sk != NULL){
  1967. wanpipe_kill_sock_accept(newsock->sk);
  1968. newsock->sk=NULL;
  1969. }
  1970. if ((sk = sock->sk) == NULL)
  1971. return -EINVAL;
  1972. if (sk->sk_type != SOCK_RAW)
  1973. return -EOPNOTSUPP;
  1974. if (sk->sk_state != WANSOCK_LISTEN)
  1975. return -EINVAL;
  1976. if (wp_sk(sk)->num != htons(X25_PROT))
  1977. return -EINVAL;
  1978. add_wait_queue(sk->sk_sleep,&wait);
  1979. current->state = TASK_INTERRUPTIBLE;
  1980. for (;;){
  1981. skb = skb_dequeue(&sk->sk_receive_queue);
  1982. if (skb){
  1983. err=0;
  1984. break;
  1985. }
  1986. if (signal_pending(current)) {
  1987. err = -ERESTARTSYS;
  1988. break;
  1989. }
  1990. schedule();
  1991. }
  1992. current->state = TASK_RUNNING;
  1993. remove_wait_queue(sk->sk_sleep,&wait);
  1994. if (err != 0)
  1995. return err;
  1996. newsk = get_newsk_from_skb(skb);
  1997. if (!newsk){
  1998. return -EINVAL;
  1999. }
  2000. set_bit(1,&wanpipe_tx_critical);
  2001. write_lock(&wanpipe_sklist_lock);
  2002. sk_add_node(newsk, &wanpipe_sklist);
  2003. write_unlock(&wanpipe_sklist_lock);
  2004. clear_bit(1,&wanpipe_tx_critical);
  2005. newsk->sk_socket = newsock;
  2006. newsk->sk_sleep = &newsock->wait;
  2007. /* Now attach up the new socket */
  2008. sk->sk_ack_backlog--;
  2009. newsock->sk = newsk;
  2010. kfree_skb(skb);
  2011. DBG_PRINTK(KERN_INFO "\nwansock: ACCEPT Got LCN %i\n",
  2012. wp_sk(newsk)->lcn);
  2013. return 0;
  2014. }
  2015. /*======================================================================
  2016. * get_newsk_from_skb
  2017. *
  2018. * Accept() uses this function to get the address of the new
  2019. * socket structure.
  2020. *=====================================================================*/
  2021. struct sock * get_newsk_from_skb (struct sk_buff *skb)
  2022. {
  2023. struct net_device *dev = skb->dev;
  2024. wanpipe_common_t *chan;
  2025. if (!dev){
  2026. return NULL;
  2027. }
  2028. if ((chan = dev->priv) == NULL){
  2029. return NULL;
  2030. }
  2031. if (!chan->sk){
  2032. return NULL;
  2033. }
  2034. return (struct sock *)chan->sk;
  2035. }
  2036. /*======================================================================
  2037. * wanpipe_connect
  2038. *
  2039. * CONNECT() System Call. X25API specific function
  2040. * Check the state of the sock, and execute PLACE_CALL command.
  2041. * Connect can ether block or return without waiting for connection,
  2042. * if specified by user.
  2043. *=====================================================================*/
  2044. static int wanpipe_connect(struct socket *sock, struct sockaddr *uaddr, int addr_len, int flags)
  2045. {
  2046. struct sock *sk = sock->sk;
  2047. struct wan_sockaddr_ll *addr = (struct wan_sockaddr_ll*)uaddr;
  2048. struct net_device *dev;
  2049. int err;
  2050. if (wp_sk(sk)->num != htons(X25_PROT))
  2051. return -EINVAL;
  2052. if (sk->sk_state == WANSOCK_CONNECTED)
  2053. return -EISCONN; /* No reconnect on a seqpacket socket */
  2054. if (sk->sk_state != WAN_DISCONNECTED) {
  2055. printk(KERN_INFO "wansock: Trying to connect on channel NON DISCONNECT\n");
  2056. return -ECONNREFUSED;
  2057. }
  2058. sk->sk_state = WANSOCK_DISCONNECTED;
  2059. sock->state = SS_UNCONNECTED;
  2060. if (addr_len != sizeof(struct wan_sockaddr_ll))
  2061. return -EINVAL;
  2062. if (addr->sll_family != AF_WANPIPE)
  2063. return -EINVAL;
  2064. if ((dev = dev_get_by_index(sk->sk_bound_dev_if)) == NULL)
  2065. return -ENETUNREACH;
  2066. dev_put(dev);
  2067. if (!sock_flag(sk, SOCK_ZAPPED)) /* Must bind first - autobinding does not work */
  2068. return -EINVAL;
  2069. sock->state = SS_CONNECTING;
  2070. sk->sk_state = WANSOCK_CONNECTING;
  2071. if (!wp_sk(sk)->mbox) {
  2072. if (wp_sk (sk)->svc)
  2073. return -EINVAL;
  2074. else {
  2075. int err;
  2076. if ((err=set_ioctl_cmd(sk,NULL)) < 0)
  2077. return err;
  2078. }
  2079. }
  2080. if ((err=wanpipe_exec_cmd(sk, X25_PLACE_CALL,flags)) != 0){
  2081. sock->state = SS_UNCONNECTED;
  2082. sk->sk_state = WANSOCK_CONNECTED;
  2083. return err;
  2084. }
  2085. if (sk->sk_state != WANSOCK_CONNECTED && (flags & O_NONBLOCK)) {
  2086. return 0;
  2087. }
  2088. if (sk->sk_state != WANSOCK_CONNECTED) {
  2089. sock->state = SS_UNCONNECTED;
  2090. return -ECONNREFUSED;
  2091. }
  2092. sock->state = SS_CONNECTED;
  2093. return 0;
  2094. }
  2095. struct proto_ops wanpipe_ops = {
  2096. .family = PF_WANPIPE,
  2097. .owner = THIS_MODULE,
  2098. .release = wanpipe_release,
  2099. .bind = wanpipe_bind,
  2100. .connect = wanpipe_connect,
  2101. .socketpair = sock_no_socketpair,
  2102. .accept = wanpipe_accept,
  2103. .getname = wanpipe_getname,
  2104. .poll = wanpipe_poll,
  2105. .ioctl = wanpipe_ioctl,
  2106. .listen = wanpipe_listen,
  2107. .shutdown = sock_no_shutdown,
  2108. .setsockopt = sock_no_setsockopt,
  2109. .getsockopt = sock_no_getsockopt,
  2110. .sendmsg = wanpipe_sendmsg,
  2111. .recvmsg = wanpipe_recvmsg
  2112. };
  2113. static struct net_proto_family wanpipe_family_ops = {
  2114. .family = PF_WANPIPE,
  2115. .create = wanpipe_create,
  2116. .owner = THIS_MODULE,
  2117. };
  2118. struct notifier_block wanpipe_netdev_notifier = {
  2119. .notifier_call = wanpipe_notifier,
  2120. };
  2121. #ifdef MODULE
  2122. void cleanup_module(void)
  2123. {
  2124. printk(KERN_INFO "wansock: Cleaning up \n");
  2125. unregister_netdevice_notifier(&wanpipe_netdev_notifier);
  2126. sock_unregister(PF_WANPIPE);
  2127. proto_unregister(&wanpipe_proto);
  2128. }
  2129. int init_module(void)
  2130. {
  2131. int rc;
  2132. printk(KERN_INFO "wansock: Registering Socket \n");
  2133. rc = proto_register(&wanpipe_proto, 0);
  2134. if (rc != 0)
  2135. goto out;
  2136. sock_register(&wanpipe_family_ops);
  2137. register_netdevice_notifier(&wanpipe_netdev_notifier);
  2138. out:
  2139. return rc;
  2140. }
  2141. #endif
  2142. MODULE_LICENSE("GPL");
  2143. MODULE_ALIAS_NETPROTO(PF_WANPIPE);