af_wanpipe.c 66 KB

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