af_iucv.c 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426
  1. /*
  2. * IUCV protocol stack for Linux on zSeries
  3. *
  4. * Copyright IBM Corp. 2006, 2009
  5. *
  6. * Author(s): Jennifer Hunt <jenhunt@us.ibm.com>
  7. * Hendrik Brueckner <brueckner@linux.vnet.ibm.com>
  8. * PM functions:
  9. * Ursula Braun <ursula.braun@de.ibm.com>
  10. */
  11. #define KMSG_COMPONENT "af_iucv"
  12. #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  13. #include <linux/module.h>
  14. #include <linux/types.h>
  15. #include <linux/list.h>
  16. #include <linux/errno.h>
  17. #include <linux/kernel.h>
  18. #include <linux/sched.h>
  19. #include <linux/slab.h>
  20. #include <linux/skbuff.h>
  21. #include <linux/init.h>
  22. #include <linux/poll.h>
  23. #include <net/sock.h>
  24. #include <asm/ebcdic.h>
  25. #include <asm/cpcmd.h>
  26. #include <linux/kmod.h>
  27. #include <net/iucv/af_iucv.h>
  28. #define VERSION "1.2"
  29. static char iucv_userid[80];
  30. static const struct proto_ops iucv_sock_ops;
  31. static struct proto iucv_proto = {
  32. .name = "AF_IUCV",
  33. .owner = THIS_MODULE,
  34. .obj_size = sizeof(struct iucv_sock),
  35. };
  36. static struct iucv_interface *pr_iucv;
  37. /* special AF_IUCV IPRM messages */
  38. static const u8 iprm_shutdown[8] =
  39. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01};
  40. #define TRGCLS_SIZE (sizeof(((struct iucv_message *)0)->class))
  41. /* macros to set/get socket control buffer at correct offset */
  42. #define CB_TAG(skb) ((skb)->cb) /* iucv message tag */
  43. #define CB_TAG_LEN (sizeof(((struct iucv_message *) 0)->tag))
  44. #define CB_TRGCLS(skb) ((skb)->cb + CB_TAG_LEN) /* iucv msg target class */
  45. #define CB_TRGCLS_LEN (TRGCLS_SIZE)
  46. #define __iucv_sock_wait(sk, condition, timeo, ret) \
  47. do { \
  48. DEFINE_WAIT(__wait); \
  49. long __timeo = timeo; \
  50. ret = 0; \
  51. prepare_to_wait(sk_sleep(sk), &__wait, TASK_INTERRUPTIBLE); \
  52. while (!(condition)) { \
  53. if (!__timeo) { \
  54. ret = -EAGAIN; \
  55. break; \
  56. } \
  57. if (signal_pending(current)) { \
  58. ret = sock_intr_errno(__timeo); \
  59. break; \
  60. } \
  61. release_sock(sk); \
  62. __timeo = schedule_timeout(__timeo); \
  63. lock_sock(sk); \
  64. ret = sock_error(sk); \
  65. if (ret) \
  66. break; \
  67. } \
  68. finish_wait(sk_sleep(sk), &__wait); \
  69. } while (0)
  70. #define iucv_sock_wait(sk, condition, timeo) \
  71. ({ \
  72. int __ret = 0; \
  73. if (!(condition)) \
  74. __iucv_sock_wait(sk, condition, timeo, __ret); \
  75. __ret; \
  76. })
  77. static void iucv_sock_kill(struct sock *sk);
  78. static void iucv_sock_close(struct sock *sk);
  79. static void iucv_sever_path(struct sock *, int);
  80. static int afiucv_hs_rcv(struct sk_buff *skb, struct net_device *dev,
  81. struct packet_type *pt, struct net_device *orig_dev);
  82. static int afiucv_hs_send(struct iucv_message *imsg, struct sock *sock,
  83. struct sk_buff *skb, u8 flags);
  84. static void afiucv_hs_callback_txnotify(struct sk_buff *, enum iucv_tx_notify);
  85. /* Call Back functions */
  86. static void iucv_callback_rx(struct iucv_path *, struct iucv_message *);
  87. static void iucv_callback_txdone(struct iucv_path *, struct iucv_message *);
  88. static void iucv_callback_connack(struct iucv_path *, u8 ipuser[16]);
  89. static int iucv_callback_connreq(struct iucv_path *, u8 ipvmid[8],
  90. u8 ipuser[16]);
  91. static void iucv_callback_connrej(struct iucv_path *, u8 ipuser[16]);
  92. static void iucv_callback_shutdown(struct iucv_path *, u8 ipuser[16]);
  93. static struct iucv_sock_list iucv_sk_list = {
  94. .lock = __RW_LOCK_UNLOCKED(iucv_sk_list.lock),
  95. .autobind_name = ATOMIC_INIT(0)
  96. };
  97. static struct iucv_handler af_iucv_handler = {
  98. .path_pending = iucv_callback_connreq,
  99. .path_complete = iucv_callback_connack,
  100. .path_severed = iucv_callback_connrej,
  101. .message_pending = iucv_callback_rx,
  102. .message_complete = iucv_callback_txdone,
  103. .path_quiesced = iucv_callback_shutdown,
  104. };
  105. static inline void high_nmcpy(unsigned char *dst, char *src)
  106. {
  107. memcpy(dst, src, 8);
  108. }
  109. static inline void low_nmcpy(unsigned char *dst, char *src)
  110. {
  111. memcpy(&dst[8], src, 8);
  112. }
  113. static int afiucv_pm_prepare(struct device *dev)
  114. {
  115. #ifdef CONFIG_PM_DEBUG
  116. printk(KERN_WARNING "afiucv_pm_prepare\n");
  117. #endif
  118. return 0;
  119. }
  120. static void afiucv_pm_complete(struct device *dev)
  121. {
  122. #ifdef CONFIG_PM_DEBUG
  123. printk(KERN_WARNING "afiucv_pm_complete\n");
  124. #endif
  125. }
  126. /**
  127. * afiucv_pm_freeze() - Freeze PM callback
  128. * @dev: AFIUCV dummy device
  129. *
  130. * Sever all established IUCV communication pathes
  131. */
  132. static int afiucv_pm_freeze(struct device *dev)
  133. {
  134. struct iucv_sock *iucv;
  135. struct sock *sk;
  136. struct hlist_node *node;
  137. int err = 0;
  138. #ifdef CONFIG_PM_DEBUG
  139. printk(KERN_WARNING "afiucv_pm_freeze\n");
  140. #endif
  141. read_lock(&iucv_sk_list.lock);
  142. sk_for_each(sk, node, &iucv_sk_list.head) {
  143. iucv = iucv_sk(sk);
  144. skb_queue_purge(&iucv->send_skb_q);
  145. skb_queue_purge(&iucv->backlog_skb_q);
  146. switch (sk->sk_state) {
  147. case IUCV_DISCONN:
  148. case IUCV_CLOSING:
  149. case IUCV_CONNECTED:
  150. iucv_sever_path(sk, 0);
  151. break;
  152. case IUCV_OPEN:
  153. case IUCV_BOUND:
  154. case IUCV_LISTEN:
  155. case IUCV_CLOSED:
  156. default:
  157. break;
  158. }
  159. skb_queue_purge(&iucv->send_skb_q);
  160. skb_queue_purge(&iucv->backlog_skb_q);
  161. }
  162. read_unlock(&iucv_sk_list.lock);
  163. return err;
  164. }
  165. /**
  166. * afiucv_pm_restore_thaw() - Thaw and restore PM callback
  167. * @dev: AFIUCV dummy device
  168. *
  169. * socket clean up after freeze
  170. */
  171. static int afiucv_pm_restore_thaw(struct device *dev)
  172. {
  173. struct sock *sk;
  174. struct hlist_node *node;
  175. #ifdef CONFIG_PM_DEBUG
  176. printk(KERN_WARNING "afiucv_pm_restore_thaw\n");
  177. #endif
  178. read_lock(&iucv_sk_list.lock);
  179. sk_for_each(sk, node, &iucv_sk_list.head) {
  180. switch (sk->sk_state) {
  181. case IUCV_CONNECTED:
  182. sk->sk_err = EPIPE;
  183. sk->sk_state = IUCV_DISCONN;
  184. sk->sk_state_change(sk);
  185. break;
  186. case IUCV_DISCONN:
  187. case IUCV_CLOSING:
  188. case IUCV_LISTEN:
  189. case IUCV_BOUND:
  190. case IUCV_OPEN:
  191. default:
  192. break;
  193. }
  194. }
  195. read_unlock(&iucv_sk_list.lock);
  196. return 0;
  197. }
  198. static const struct dev_pm_ops afiucv_pm_ops = {
  199. .prepare = afiucv_pm_prepare,
  200. .complete = afiucv_pm_complete,
  201. .freeze = afiucv_pm_freeze,
  202. .thaw = afiucv_pm_restore_thaw,
  203. .restore = afiucv_pm_restore_thaw,
  204. };
  205. static struct device_driver af_iucv_driver = {
  206. .owner = THIS_MODULE,
  207. .name = "afiucv",
  208. .bus = NULL,
  209. .pm = &afiucv_pm_ops,
  210. };
  211. /* dummy device used as trigger for PM functions */
  212. static struct device *af_iucv_dev;
  213. /**
  214. * iucv_msg_length() - Returns the length of an iucv message.
  215. * @msg: Pointer to struct iucv_message, MUST NOT be NULL
  216. *
  217. * The function returns the length of the specified iucv message @msg of data
  218. * stored in a buffer and of data stored in the parameter list (PRMDATA).
  219. *
  220. * For IUCV_IPRMDATA, AF_IUCV uses the following convention to transport socket
  221. * data:
  222. * PRMDATA[0..6] socket data (max 7 bytes);
  223. * PRMDATA[7] socket data length value (len is 0xff - PRMDATA[7])
  224. *
  225. * The socket data length is computed by subtracting the socket data length
  226. * value from 0xFF.
  227. * If the socket data len is greater 7, then PRMDATA can be used for special
  228. * notifications (see iucv_sock_shutdown); and further,
  229. * if the socket data len is > 7, the function returns 8.
  230. *
  231. * Use this function to allocate socket buffers to store iucv message data.
  232. */
  233. static inline size_t iucv_msg_length(struct iucv_message *msg)
  234. {
  235. size_t datalen;
  236. if (msg->flags & IUCV_IPRMDATA) {
  237. datalen = 0xff - msg->rmmsg[7];
  238. return (datalen < 8) ? datalen : 8;
  239. }
  240. return msg->length;
  241. }
  242. /**
  243. * iucv_sock_in_state() - check for specific states
  244. * @sk: sock structure
  245. * @state: first iucv sk state
  246. * @state: second iucv sk state
  247. *
  248. * Returns true if the socket in either in the first or second state.
  249. */
  250. static int iucv_sock_in_state(struct sock *sk, int state, int state2)
  251. {
  252. return (sk->sk_state == state || sk->sk_state == state2);
  253. }
  254. /**
  255. * iucv_below_msglim() - function to check if messages can be sent
  256. * @sk: sock structure
  257. *
  258. * Returns true if the send queue length is lower than the message limit.
  259. * Always returns true if the socket is not connected (no iucv path for
  260. * checking the message limit).
  261. */
  262. static inline int iucv_below_msglim(struct sock *sk)
  263. {
  264. struct iucv_sock *iucv = iucv_sk(sk);
  265. if (sk->sk_state != IUCV_CONNECTED)
  266. return 1;
  267. if (iucv->transport == AF_IUCV_TRANS_IUCV)
  268. return (skb_queue_len(&iucv->send_skb_q) < iucv->path->msglim);
  269. else
  270. return ((atomic_read(&iucv->msg_sent) < iucv->msglimit_peer) &&
  271. (atomic_read(&iucv->pendings) <= 0));
  272. }
  273. /**
  274. * iucv_sock_wake_msglim() - Wake up thread waiting on msg limit
  275. */
  276. static void iucv_sock_wake_msglim(struct sock *sk)
  277. {
  278. struct socket_wq *wq;
  279. rcu_read_lock();
  280. wq = rcu_dereference(sk->sk_wq);
  281. if (wq_has_sleeper(wq))
  282. wake_up_interruptible_all(&wq->wait);
  283. sk_wake_async(sk, SOCK_WAKE_SPACE, POLL_OUT);
  284. rcu_read_unlock();
  285. }
  286. /**
  287. * afiucv_hs_send() - send a message through HiperSockets transport
  288. */
  289. static int afiucv_hs_send(struct iucv_message *imsg, struct sock *sock,
  290. struct sk_buff *skb, u8 flags)
  291. {
  292. struct iucv_sock *iucv = iucv_sk(sock);
  293. struct af_iucv_trans_hdr *phs_hdr;
  294. struct sk_buff *nskb;
  295. int err, confirm_recv = 0;
  296. memset(skb->head, 0, ETH_HLEN);
  297. phs_hdr = (struct af_iucv_trans_hdr *)skb_push(skb,
  298. sizeof(struct af_iucv_trans_hdr));
  299. skb_reset_mac_header(skb);
  300. skb_reset_network_header(skb);
  301. skb_push(skb, ETH_HLEN);
  302. skb_reset_mac_header(skb);
  303. memset(phs_hdr, 0, sizeof(struct af_iucv_trans_hdr));
  304. phs_hdr->magic = ETH_P_AF_IUCV;
  305. phs_hdr->version = 1;
  306. phs_hdr->flags = flags;
  307. if (flags == AF_IUCV_FLAG_SYN)
  308. phs_hdr->window = iucv->msglimit;
  309. else if ((flags == AF_IUCV_FLAG_WIN) || !flags) {
  310. confirm_recv = atomic_read(&iucv->msg_recv);
  311. phs_hdr->window = confirm_recv;
  312. if (confirm_recv)
  313. phs_hdr->flags = phs_hdr->flags | AF_IUCV_FLAG_WIN;
  314. }
  315. memcpy(phs_hdr->destUserID, iucv->dst_user_id, 8);
  316. memcpy(phs_hdr->destAppName, iucv->dst_name, 8);
  317. memcpy(phs_hdr->srcUserID, iucv->src_user_id, 8);
  318. memcpy(phs_hdr->srcAppName, iucv->src_name, 8);
  319. ASCEBC(phs_hdr->destUserID, sizeof(phs_hdr->destUserID));
  320. ASCEBC(phs_hdr->destAppName, sizeof(phs_hdr->destAppName));
  321. ASCEBC(phs_hdr->srcUserID, sizeof(phs_hdr->srcUserID));
  322. ASCEBC(phs_hdr->srcAppName, sizeof(phs_hdr->srcAppName));
  323. if (imsg)
  324. memcpy(&phs_hdr->iucv_hdr, imsg, sizeof(struct iucv_message));
  325. skb->dev = iucv->hs_dev;
  326. if (!skb->dev)
  327. return -ENODEV;
  328. if (!(skb->dev->flags & IFF_UP) || !netif_carrier_ok(skb->dev))
  329. return -ENETDOWN;
  330. if (skb->len > skb->dev->mtu) {
  331. if (sock->sk_type == SOCK_SEQPACKET)
  332. return -EMSGSIZE;
  333. else
  334. skb_trim(skb, skb->dev->mtu);
  335. }
  336. skb->protocol = ETH_P_AF_IUCV;
  337. skb_shinfo(skb)->tx_flags |= SKBTX_DRV_NEEDS_SK_REF;
  338. nskb = skb_clone(skb, GFP_ATOMIC);
  339. if (!nskb)
  340. return -ENOMEM;
  341. skb_queue_tail(&iucv->send_skb_q, nskb);
  342. err = dev_queue_xmit(skb);
  343. if (net_xmit_eval(err)) {
  344. skb_unlink(nskb, &iucv->send_skb_q);
  345. kfree_skb(nskb);
  346. } else {
  347. atomic_sub(confirm_recv, &iucv->msg_recv);
  348. WARN_ON(atomic_read(&iucv->msg_recv) < 0);
  349. }
  350. return net_xmit_eval(err);
  351. }
  352. static struct sock *__iucv_get_sock_by_name(char *nm)
  353. {
  354. struct sock *sk;
  355. struct hlist_node *node;
  356. sk_for_each(sk, node, &iucv_sk_list.head)
  357. if (!memcmp(&iucv_sk(sk)->src_name, nm, 8))
  358. return sk;
  359. return NULL;
  360. }
  361. static void iucv_sock_destruct(struct sock *sk)
  362. {
  363. skb_queue_purge(&sk->sk_receive_queue);
  364. skb_queue_purge(&sk->sk_write_queue);
  365. }
  366. /* Cleanup Listen */
  367. static void iucv_sock_cleanup_listen(struct sock *parent)
  368. {
  369. struct sock *sk;
  370. /* Close non-accepted connections */
  371. while ((sk = iucv_accept_dequeue(parent, NULL))) {
  372. iucv_sock_close(sk);
  373. iucv_sock_kill(sk);
  374. }
  375. parent->sk_state = IUCV_CLOSED;
  376. }
  377. /* Kill socket (only if zapped and orphaned) */
  378. static void iucv_sock_kill(struct sock *sk)
  379. {
  380. if (!sock_flag(sk, SOCK_ZAPPED) || sk->sk_socket)
  381. return;
  382. iucv_sock_unlink(&iucv_sk_list, sk);
  383. sock_set_flag(sk, SOCK_DEAD);
  384. sock_put(sk);
  385. }
  386. /* Terminate an IUCV path */
  387. static void iucv_sever_path(struct sock *sk, int with_user_data)
  388. {
  389. unsigned char user_data[16];
  390. struct iucv_sock *iucv = iucv_sk(sk);
  391. struct iucv_path *path = iucv->path;
  392. if (iucv->path) {
  393. iucv->path = NULL;
  394. if (with_user_data) {
  395. low_nmcpy(user_data, iucv->src_name);
  396. high_nmcpy(user_data, iucv->dst_name);
  397. ASCEBC(user_data, sizeof(user_data));
  398. pr_iucv->path_sever(path, user_data);
  399. } else
  400. pr_iucv->path_sever(path, NULL);
  401. iucv_path_free(path);
  402. }
  403. }
  404. /* Close an IUCV socket */
  405. static void iucv_sock_close(struct sock *sk)
  406. {
  407. struct iucv_sock *iucv = iucv_sk(sk);
  408. unsigned long timeo;
  409. int err = 0;
  410. int blen;
  411. struct sk_buff *skb;
  412. lock_sock(sk);
  413. switch (sk->sk_state) {
  414. case IUCV_LISTEN:
  415. iucv_sock_cleanup_listen(sk);
  416. break;
  417. case IUCV_CONNECTED:
  418. if (iucv->transport == AF_IUCV_TRANS_HIPER) {
  419. /* send fin */
  420. blen = sizeof(struct af_iucv_trans_hdr) + ETH_HLEN;
  421. skb = sock_alloc_send_skb(sk, blen, 1, &err);
  422. if (skb) {
  423. skb_reserve(skb, blen);
  424. err = afiucv_hs_send(NULL, sk, skb,
  425. AF_IUCV_FLAG_FIN);
  426. }
  427. sk->sk_state = IUCV_DISCONN;
  428. sk->sk_state_change(sk);
  429. }
  430. case IUCV_DISCONN: /* fall through */
  431. sk->sk_state = IUCV_CLOSING;
  432. sk->sk_state_change(sk);
  433. if (!err && !skb_queue_empty(&iucv->send_skb_q)) {
  434. if (sock_flag(sk, SOCK_LINGER) && sk->sk_lingertime)
  435. timeo = sk->sk_lingertime;
  436. else
  437. timeo = IUCV_DISCONN_TIMEOUT;
  438. iucv_sock_wait(sk,
  439. iucv_sock_in_state(sk, IUCV_CLOSED, 0),
  440. timeo);
  441. }
  442. case IUCV_CLOSING: /* fall through */
  443. sk->sk_state = IUCV_CLOSED;
  444. sk->sk_state_change(sk);
  445. sk->sk_err = ECONNRESET;
  446. sk->sk_state_change(sk);
  447. skb_queue_purge(&iucv->send_skb_q);
  448. skb_queue_purge(&iucv->backlog_skb_q);
  449. default: /* fall through */
  450. iucv_sever_path(sk, 1);
  451. }
  452. if (iucv->hs_dev) {
  453. dev_put(iucv->hs_dev);
  454. iucv->hs_dev = NULL;
  455. sk->sk_bound_dev_if = 0;
  456. }
  457. /* mark socket for deletion by iucv_sock_kill() */
  458. sock_set_flag(sk, SOCK_ZAPPED);
  459. release_sock(sk);
  460. }
  461. static void iucv_sock_init(struct sock *sk, struct sock *parent)
  462. {
  463. if (parent)
  464. sk->sk_type = parent->sk_type;
  465. }
  466. static struct sock *iucv_sock_alloc(struct socket *sock, int proto, gfp_t prio)
  467. {
  468. struct sock *sk;
  469. struct iucv_sock *iucv;
  470. sk = sk_alloc(&init_net, PF_IUCV, prio, &iucv_proto);
  471. if (!sk)
  472. return NULL;
  473. iucv = iucv_sk(sk);
  474. sock_init_data(sock, sk);
  475. INIT_LIST_HEAD(&iucv->accept_q);
  476. spin_lock_init(&iucv->accept_q_lock);
  477. skb_queue_head_init(&iucv->send_skb_q);
  478. INIT_LIST_HEAD(&iucv->message_q.list);
  479. spin_lock_init(&iucv->message_q.lock);
  480. skb_queue_head_init(&iucv->backlog_skb_q);
  481. iucv->send_tag = 0;
  482. atomic_set(&iucv->pendings, 0);
  483. iucv->flags = 0;
  484. iucv->msglimit = 0;
  485. atomic_set(&iucv->msg_sent, 0);
  486. atomic_set(&iucv->msg_recv, 0);
  487. iucv->path = NULL;
  488. iucv->sk_txnotify = afiucv_hs_callback_txnotify;
  489. memset(&iucv->src_user_id , 0, 32);
  490. if (pr_iucv)
  491. iucv->transport = AF_IUCV_TRANS_IUCV;
  492. else
  493. iucv->transport = AF_IUCV_TRANS_HIPER;
  494. sk->sk_destruct = iucv_sock_destruct;
  495. sk->sk_sndtimeo = IUCV_CONN_TIMEOUT;
  496. sk->sk_allocation = GFP_DMA;
  497. sock_reset_flag(sk, SOCK_ZAPPED);
  498. sk->sk_protocol = proto;
  499. sk->sk_state = IUCV_OPEN;
  500. iucv_sock_link(&iucv_sk_list, sk);
  501. return sk;
  502. }
  503. /* Create an IUCV socket */
  504. static int iucv_sock_create(struct net *net, struct socket *sock, int protocol,
  505. int kern)
  506. {
  507. struct sock *sk;
  508. if (protocol && protocol != PF_IUCV)
  509. return -EPROTONOSUPPORT;
  510. sock->state = SS_UNCONNECTED;
  511. switch (sock->type) {
  512. case SOCK_STREAM:
  513. sock->ops = &iucv_sock_ops;
  514. break;
  515. case SOCK_SEQPACKET:
  516. /* currently, proto ops can handle both sk types */
  517. sock->ops = &iucv_sock_ops;
  518. break;
  519. default:
  520. return -ESOCKTNOSUPPORT;
  521. }
  522. sk = iucv_sock_alloc(sock, protocol, GFP_KERNEL);
  523. if (!sk)
  524. return -ENOMEM;
  525. iucv_sock_init(sk, NULL);
  526. return 0;
  527. }
  528. void iucv_sock_link(struct iucv_sock_list *l, struct sock *sk)
  529. {
  530. write_lock_bh(&l->lock);
  531. sk_add_node(sk, &l->head);
  532. write_unlock_bh(&l->lock);
  533. }
  534. void iucv_sock_unlink(struct iucv_sock_list *l, struct sock *sk)
  535. {
  536. write_lock_bh(&l->lock);
  537. sk_del_node_init(sk);
  538. write_unlock_bh(&l->lock);
  539. }
  540. void iucv_accept_enqueue(struct sock *parent, struct sock *sk)
  541. {
  542. unsigned long flags;
  543. struct iucv_sock *par = iucv_sk(parent);
  544. sock_hold(sk);
  545. spin_lock_irqsave(&par->accept_q_lock, flags);
  546. list_add_tail(&iucv_sk(sk)->accept_q, &par->accept_q);
  547. spin_unlock_irqrestore(&par->accept_q_lock, flags);
  548. iucv_sk(sk)->parent = parent;
  549. sk_acceptq_added(parent);
  550. }
  551. void iucv_accept_unlink(struct sock *sk)
  552. {
  553. unsigned long flags;
  554. struct iucv_sock *par = iucv_sk(iucv_sk(sk)->parent);
  555. spin_lock_irqsave(&par->accept_q_lock, flags);
  556. list_del_init(&iucv_sk(sk)->accept_q);
  557. spin_unlock_irqrestore(&par->accept_q_lock, flags);
  558. sk_acceptq_removed(iucv_sk(sk)->parent);
  559. iucv_sk(sk)->parent = NULL;
  560. sock_put(sk);
  561. }
  562. struct sock *iucv_accept_dequeue(struct sock *parent, struct socket *newsock)
  563. {
  564. struct iucv_sock *isk, *n;
  565. struct sock *sk;
  566. list_for_each_entry_safe(isk, n, &iucv_sk(parent)->accept_q, accept_q) {
  567. sk = (struct sock *) isk;
  568. lock_sock(sk);
  569. if (sk->sk_state == IUCV_CLOSED) {
  570. iucv_accept_unlink(sk);
  571. release_sock(sk);
  572. continue;
  573. }
  574. if (sk->sk_state == IUCV_CONNECTED ||
  575. sk->sk_state == IUCV_DISCONN ||
  576. !newsock) {
  577. iucv_accept_unlink(sk);
  578. if (newsock)
  579. sock_graft(sk, newsock);
  580. release_sock(sk);
  581. return sk;
  582. }
  583. release_sock(sk);
  584. }
  585. return NULL;
  586. }
  587. /* Bind an unbound socket */
  588. static int iucv_sock_bind(struct socket *sock, struct sockaddr *addr,
  589. int addr_len)
  590. {
  591. struct sockaddr_iucv *sa = (struct sockaddr_iucv *) addr;
  592. struct sock *sk = sock->sk;
  593. struct iucv_sock *iucv;
  594. int err = 0;
  595. struct net_device *dev;
  596. char uid[9];
  597. /* Verify the input sockaddr */
  598. if (!addr || addr->sa_family != AF_IUCV)
  599. return -EINVAL;
  600. lock_sock(sk);
  601. if (sk->sk_state != IUCV_OPEN) {
  602. err = -EBADFD;
  603. goto done;
  604. }
  605. write_lock_bh(&iucv_sk_list.lock);
  606. iucv = iucv_sk(sk);
  607. if (__iucv_get_sock_by_name(sa->siucv_name)) {
  608. err = -EADDRINUSE;
  609. goto done_unlock;
  610. }
  611. if (iucv->path)
  612. goto done_unlock;
  613. /* Bind the socket */
  614. if (pr_iucv)
  615. if (!memcmp(sa->siucv_user_id, iucv_userid, 8))
  616. goto vm_bind; /* VM IUCV transport */
  617. /* try hiper transport */
  618. memcpy(uid, sa->siucv_user_id, sizeof(uid));
  619. ASCEBC(uid, 8);
  620. rcu_read_lock();
  621. for_each_netdev_rcu(&init_net, dev) {
  622. if (!memcmp(dev->perm_addr, uid, 8)) {
  623. memcpy(iucv->src_name, sa->siucv_name, 8);
  624. memcpy(iucv->src_user_id, sa->siucv_user_id, 8);
  625. sk->sk_bound_dev_if = dev->ifindex;
  626. iucv->hs_dev = dev;
  627. dev_hold(dev);
  628. sk->sk_state = IUCV_BOUND;
  629. iucv->transport = AF_IUCV_TRANS_HIPER;
  630. if (!iucv->msglimit)
  631. iucv->msglimit = IUCV_HIPER_MSGLIM_DEFAULT;
  632. rcu_read_unlock();
  633. goto done_unlock;
  634. }
  635. }
  636. rcu_read_unlock();
  637. vm_bind:
  638. if (pr_iucv) {
  639. /* use local userid for backward compat */
  640. memcpy(iucv->src_name, sa->siucv_name, 8);
  641. memcpy(iucv->src_user_id, iucv_userid, 8);
  642. sk->sk_state = IUCV_BOUND;
  643. iucv->transport = AF_IUCV_TRANS_IUCV;
  644. if (!iucv->msglimit)
  645. iucv->msglimit = IUCV_QUEUELEN_DEFAULT;
  646. goto done_unlock;
  647. }
  648. /* found no dev to bind */
  649. err = -ENODEV;
  650. done_unlock:
  651. /* Release the socket list lock */
  652. write_unlock_bh(&iucv_sk_list.lock);
  653. done:
  654. release_sock(sk);
  655. return err;
  656. }
  657. /* Automatically bind an unbound socket */
  658. static int iucv_sock_autobind(struct sock *sk)
  659. {
  660. struct iucv_sock *iucv = iucv_sk(sk);
  661. char name[12];
  662. int err = 0;
  663. if (unlikely(!pr_iucv))
  664. return -EPROTO;
  665. memcpy(iucv->src_user_id, iucv_userid, 8);
  666. write_lock_bh(&iucv_sk_list.lock);
  667. sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
  668. while (__iucv_get_sock_by_name(name)) {
  669. sprintf(name, "%08x",
  670. atomic_inc_return(&iucv_sk_list.autobind_name));
  671. }
  672. write_unlock_bh(&iucv_sk_list.lock);
  673. memcpy(&iucv->src_name, name, 8);
  674. if (!iucv->msglimit)
  675. iucv->msglimit = IUCV_QUEUELEN_DEFAULT;
  676. return err;
  677. }
  678. static int afiucv_hs_connect(struct socket *sock)
  679. {
  680. struct sock *sk = sock->sk;
  681. struct sk_buff *skb;
  682. int blen = sizeof(struct af_iucv_trans_hdr) + ETH_HLEN;
  683. int err = 0;
  684. /* send syn */
  685. skb = sock_alloc_send_skb(sk, blen, 1, &err);
  686. if (!skb) {
  687. err = -ENOMEM;
  688. goto done;
  689. }
  690. skb->dev = NULL;
  691. skb_reserve(skb, blen);
  692. err = afiucv_hs_send(NULL, sk, skb, AF_IUCV_FLAG_SYN);
  693. done:
  694. return err;
  695. }
  696. static int afiucv_path_connect(struct socket *sock, struct sockaddr *addr)
  697. {
  698. struct sockaddr_iucv *sa = (struct sockaddr_iucv *) addr;
  699. struct sock *sk = sock->sk;
  700. struct iucv_sock *iucv = iucv_sk(sk);
  701. unsigned char user_data[16];
  702. int err;
  703. high_nmcpy(user_data, sa->siucv_name);
  704. low_nmcpy(user_data, iucv->src_name);
  705. ASCEBC(user_data, sizeof(user_data));
  706. /* Create path. */
  707. iucv->path = iucv_path_alloc(iucv->msglimit,
  708. IUCV_IPRMDATA, GFP_KERNEL);
  709. if (!iucv->path) {
  710. err = -ENOMEM;
  711. goto done;
  712. }
  713. err = pr_iucv->path_connect(iucv->path, &af_iucv_handler,
  714. sa->siucv_user_id, NULL, user_data,
  715. sk);
  716. if (err) {
  717. iucv_path_free(iucv->path);
  718. iucv->path = NULL;
  719. switch (err) {
  720. case 0x0b: /* Target communicator is not logged on */
  721. err = -ENETUNREACH;
  722. break;
  723. case 0x0d: /* Max connections for this guest exceeded */
  724. case 0x0e: /* Max connections for target guest exceeded */
  725. err = -EAGAIN;
  726. break;
  727. case 0x0f: /* Missing IUCV authorization */
  728. err = -EACCES;
  729. break;
  730. default:
  731. err = -ECONNREFUSED;
  732. break;
  733. }
  734. }
  735. done:
  736. return err;
  737. }
  738. /* Connect an unconnected socket */
  739. static int iucv_sock_connect(struct socket *sock, struct sockaddr *addr,
  740. int alen, int flags)
  741. {
  742. struct sockaddr_iucv *sa = (struct sockaddr_iucv *) addr;
  743. struct sock *sk = sock->sk;
  744. struct iucv_sock *iucv = iucv_sk(sk);
  745. int err;
  746. if (addr->sa_family != AF_IUCV || alen < sizeof(struct sockaddr_iucv))
  747. return -EINVAL;
  748. if (sk->sk_state != IUCV_OPEN && sk->sk_state != IUCV_BOUND)
  749. return -EBADFD;
  750. if (sk->sk_state == IUCV_OPEN &&
  751. iucv->transport == AF_IUCV_TRANS_HIPER)
  752. return -EBADFD; /* explicit bind required */
  753. if (sk->sk_type != SOCK_STREAM && sk->sk_type != SOCK_SEQPACKET)
  754. return -EINVAL;
  755. if (sk->sk_state == IUCV_OPEN) {
  756. err = iucv_sock_autobind(sk);
  757. if (unlikely(err))
  758. return err;
  759. }
  760. lock_sock(sk);
  761. /* Set the destination information */
  762. memcpy(iucv->dst_user_id, sa->siucv_user_id, 8);
  763. memcpy(iucv->dst_name, sa->siucv_name, 8);
  764. if (iucv->transport == AF_IUCV_TRANS_HIPER)
  765. err = afiucv_hs_connect(sock);
  766. else
  767. err = afiucv_path_connect(sock, addr);
  768. if (err)
  769. goto done;
  770. if (sk->sk_state != IUCV_CONNECTED)
  771. err = iucv_sock_wait(sk, iucv_sock_in_state(sk, IUCV_CONNECTED,
  772. IUCV_DISCONN),
  773. sock_sndtimeo(sk, flags & O_NONBLOCK));
  774. if (sk->sk_state == IUCV_DISCONN || sk->sk_state == IUCV_CLOSED)
  775. err = -ECONNREFUSED;
  776. if (err && iucv->transport == AF_IUCV_TRANS_IUCV)
  777. iucv_sever_path(sk, 0);
  778. done:
  779. release_sock(sk);
  780. return err;
  781. }
  782. /* Move a socket into listening state. */
  783. static int iucv_sock_listen(struct socket *sock, int backlog)
  784. {
  785. struct sock *sk = sock->sk;
  786. int err;
  787. lock_sock(sk);
  788. err = -EINVAL;
  789. if (sk->sk_state != IUCV_BOUND)
  790. goto done;
  791. if (sock->type != SOCK_STREAM && sock->type != SOCK_SEQPACKET)
  792. goto done;
  793. sk->sk_max_ack_backlog = backlog;
  794. sk->sk_ack_backlog = 0;
  795. sk->sk_state = IUCV_LISTEN;
  796. err = 0;
  797. done:
  798. release_sock(sk);
  799. return err;
  800. }
  801. /* Accept a pending connection */
  802. static int iucv_sock_accept(struct socket *sock, struct socket *newsock,
  803. int flags)
  804. {
  805. DECLARE_WAITQUEUE(wait, current);
  806. struct sock *sk = sock->sk, *nsk;
  807. long timeo;
  808. int err = 0;
  809. lock_sock_nested(sk, SINGLE_DEPTH_NESTING);
  810. if (sk->sk_state != IUCV_LISTEN) {
  811. err = -EBADFD;
  812. goto done;
  813. }
  814. timeo = sock_rcvtimeo(sk, flags & O_NONBLOCK);
  815. /* Wait for an incoming connection */
  816. add_wait_queue_exclusive(sk_sleep(sk), &wait);
  817. while (!(nsk = iucv_accept_dequeue(sk, newsock))) {
  818. set_current_state(TASK_INTERRUPTIBLE);
  819. if (!timeo) {
  820. err = -EAGAIN;
  821. break;
  822. }
  823. release_sock(sk);
  824. timeo = schedule_timeout(timeo);
  825. lock_sock_nested(sk, SINGLE_DEPTH_NESTING);
  826. if (sk->sk_state != IUCV_LISTEN) {
  827. err = -EBADFD;
  828. break;
  829. }
  830. if (signal_pending(current)) {
  831. err = sock_intr_errno(timeo);
  832. break;
  833. }
  834. }
  835. set_current_state(TASK_RUNNING);
  836. remove_wait_queue(sk_sleep(sk), &wait);
  837. if (err)
  838. goto done;
  839. newsock->state = SS_CONNECTED;
  840. done:
  841. release_sock(sk);
  842. return err;
  843. }
  844. static int iucv_sock_getname(struct socket *sock, struct sockaddr *addr,
  845. int *len, int peer)
  846. {
  847. struct sockaddr_iucv *siucv = (struct sockaddr_iucv *) addr;
  848. struct sock *sk = sock->sk;
  849. struct iucv_sock *iucv = iucv_sk(sk);
  850. addr->sa_family = AF_IUCV;
  851. *len = sizeof(struct sockaddr_iucv);
  852. if (peer) {
  853. memcpy(siucv->siucv_user_id, iucv->dst_user_id, 8);
  854. memcpy(siucv->siucv_name, iucv->dst_name, 8);
  855. } else {
  856. memcpy(siucv->siucv_user_id, iucv->src_user_id, 8);
  857. memcpy(siucv->siucv_name, iucv->src_name, 8);
  858. }
  859. memset(&siucv->siucv_port, 0, sizeof(siucv->siucv_port));
  860. memset(&siucv->siucv_addr, 0, sizeof(siucv->siucv_addr));
  861. memset(&siucv->siucv_nodeid, 0, sizeof(siucv->siucv_nodeid));
  862. return 0;
  863. }
  864. /**
  865. * iucv_send_iprm() - Send socket data in parameter list of an iucv message.
  866. * @path: IUCV path
  867. * @msg: Pointer to a struct iucv_message
  868. * @skb: The socket data to send, skb->len MUST BE <= 7
  869. *
  870. * Send the socket data in the parameter list in the iucv message
  871. * (IUCV_IPRMDATA). The socket data is stored at index 0 to 6 in the parameter
  872. * list and the socket data len at index 7 (last byte).
  873. * See also iucv_msg_length().
  874. *
  875. * Returns the error code from the iucv_message_send() call.
  876. */
  877. static int iucv_send_iprm(struct iucv_path *path, struct iucv_message *msg,
  878. struct sk_buff *skb)
  879. {
  880. u8 prmdata[8];
  881. memcpy(prmdata, (void *) skb->data, skb->len);
  882. prmdata[7] = 0xff - (u8) skb->len;
  883. return pr_iucv->message_send(path, msg, IUCV_IPRMDATA, 0,
  884. (void *) prmdata, 8);
  885. }
  886. static int iucv_sock_sendmsg(struct kiocb *iocb, struct socket *sock,
  887. struct msghdr *msg, size_t len)
  888. {
  889. struct sock *sk = sock->sk;
  890. struct iucv_sock *iucv = iucv_sk(sk);
  891. struct sk_buff *skb;
  892. struct iucv_message txmsg;
  893. struct cmsghdr *cmsg;
  894. int cmsg_done;
  895. long timeo;
  896. char user_id[9];
  897. char appl_id[9];
  898. int err;
  899. int noblock = msg->msg_flags & MSG_DONTWAIT;
  900. err = sock_error(sk);
  901. if (err)
  902. return err;
  903. if (msg->msg_flags & MSG_OOB)
  904. return -EOPNOTSUPP;
  905. /* SOCK_SEQPACKET: we do not support segmented records */
  906. if (sk->sk_type == SOCK_SEQPACKET && !(msg->msg_flags & MSG_EOR))
  907. return -EOPNOTSUPP;
  908. lock_sock(sk);
  909. if (sk->sk_shutdown & SEND_SHUTDOWN) {
  910. err = -EPIPE;
  911. goto out;
  912. }
  913. /* Return if the socket is not in connected state */
  914. if (sk->sk_state != IUCV_CONNECTED) {
  915. err = -ENOTCONN;
  916. goto out;
  917. }
  918. /* initialize defaults */
  919. cmsg_done = 0; /* check for duplicate headers */
  920. txmsg.class = 0;
  921. /* iterate over control messages */
  922. for (cmsg = CMSG_FIRSTHDR(msg); cmsg;
  923. cmsg = CMSG_NXTHDR(msg, cmsg)) {
  924. if (!CMSG_OK(msg, cmsg)) {
  925. err = -EINVAL;
  926. goto out;
  927. }
  928. if (cmsg->cmsg_level != SOL_IUCV)
  929. continue;
  930. if (cmsg->cmsg_type & cmsg_done) {
  931. err = -EINVAL;
  932. goto out;
  933. }
  934. cmsg_done |= cmsg->cmsg_type;
  935. switch (cmsg->cmsg_type) {
  936. case SCM_IUCV_TRGCLS:
  937. if (cmsg->cmsg_len != CMSG_LEN(TRGCLS_SIZE)) {
  938. err = -EINVAL;
  939. goto out;
  940. }
  941. /* set iucv message target class */
  942. memcpy(&txmsg.class,
  943. (void *) CMSG_DATA(cmsg), TRGCLS_SIZE);
  944. break;
  945. default:
  946. err = -EINVAL;
  947. goto out;
  948. break;
  949. }
  950. }
  951. /* allocate one skb for each iucv message:
  952. * this is fine for SOCK_SEQPACKET (unless we want to support
  953. * segmented records using the MSG_EOR flag), but
  954. * for SOCK_STREAM we might want to improve it in future */
  955. if (iucv->transport == AF_IUCV_TRANS_HIPER)
  956. skb = sock_alloc_send_skb(sk,
  957. len + sizeof(struct af_iucv_trans_hdr) + ETH_HLEN,
  958. noblock, &err);
  959. else
  960. skb = sock_alloc_send_skb(sk, len, noblock, &err);
  961. if (!skb) {
  962. err = -ENOMEM;
  963. goto out;
  964. }
  965. if (iucv->transport == AF_IUCV_TRANS_HIPER)
  966. skb_reserve(skb, sizeof(struct af_iucv_trans_hdr) + ETH_HLEN);
  967. if (memcpy_fromiovec(skb_put(skb, len), msg->msg_iov, len)) {
  968. err = -EFAULT;
  969. goto fail;
  970. }
  971. /* wait if outstanding messages for iucv path has reached */
  972. timeo = sock_sndtimeo(sk, noblock);
  973. err = iucv_sock_wait(sk, iucv_below_msglim(sk), timeo);
  974. if (err)
  975. goto fail;
  976. /* return -ECONNRESET if the socket is no longer connected */
  977. if (sk->sk_state != IUCV_CONNECTED) {
  978. err = -ECONNRESET;
  979. goto fail;
  980. }
  981. /* increment and save iucv message tag for msg_completion cbk */
  982. txmsg.tag = iucv->send_tag++;
  983. memcpy(CB_TAG(skb), &txmsg.tag, CB_TAG_LEN);
  984. if (iucv->transport == AF_IUCV_TRANS_HIPER) {
  985. atomic_inc(&iucv->msg_sent);
  986. err = afiucv_hs_send(&txmsg, sk, skb, 0);
  987. if (err) {
  988. atomic_dec(&iucv->msg_sent);
  989. goto fail;
  990. }
  991. goto release;
  992. }
  993. skb_queue_tail(&iucv->send_skb_q, skb);
  994. if (((iucv->path->flags & IUCV_IPRMDATA) & iucv->flags)
  995. && skb->len <= 7) {
  996. err = iucv_send_iprm(iucv->path, &txmsg, skb);
  997. /* on success: there is no message_complete callback
  998. * for an IPRMDATA msg; remove skb from send queue */
  999. if (err == 0) {
  1000. skb_unlink(skb, &iucv->send_skb_q);
  1001. kfree_skb(skb);
  1002. }
  1003. /* this error should never happen since the
  1004. * IUCV_IPRMDATA path flag is set... sever path */
  1005. if (err == 0x15) {
  1006. pr_iucv->path_sever(iucv->path, NULL);
  1007. skb_unlink(skb, &iucv->send_skb_q);
  1008. err = -EPIPE;
  1009. goto fail;
  1010. }
  1011. } else
  1012. err = pr_iucv->message_send(iucv->path, &txmsg, 0, 0,
  1013. (void *) skb->data, skb->len);
  1014. if (err) {
  1015. if (err == 3) {
  1016. user_id[8] = 0;
  1017. memcpy(user_id, iucv->dst_user_id, 8);
  1018. appl_id[8] = 0;
  1019. memcpy(appl_id, iucv->dst_name, 8);
  1020. pr_err("Application %s on z/VM guest %s"
  1021. " exceeds message limit\n",
  1022. appl_id, user_id);
  1023. err = -EAGAIN;
  1024. } else
  1025. err = -EPIPE;
  1026. skb_unlink(skb, &iucv->send_skb_q);
  1027. goto fail;
  1028. }
  1029. release:
  1030. release_sock(sk);
  1031. return len;
  1032. fail:
  1033. kfree_skb(skb);
  1034. out:
  1035. release_sock(sk);
  1036. return err;
  1037. }
  1038. /* iucv_fragment_skb() - Fragment a single IUCV message into multiple skb's
  1039. *
  1040. * Locking: must be called with message_q.lock held
  1041. */
  1042. static int iucv_fragment_skb(struct sock *sk, struct sk_buff *skb, int len)
  1043. {
  1044. int dataleft, size, copied = 0;
  1045. struct sk_buff *nskb;
  1046. dataleft = len;
  1047. while (dataleft) {
  1048. if (dataleft >= sk->sk_rcvbuf / 4)
  1049. size = sk->sk_rcvbuf / 4;
  1050. else
  1051. size = dataleft;
  1052. nskb = alloc_skb(size, GFP_ATOMIC | GFP_DMA);
  1053. if (!nskb)
  1054. return -ENOMEM;
  1055. /* copy target class to control buffer of new skb */
  1056. memcpy(CB_TRGCLS(nskb), CB_TRGCLS(skb), CB_TRGCLS_LEN);
  1057. /* copy data fragment */
  1058. memcpy(nskb->data, skb->data + copied, size);
  1059. copied += size;
  1060. dataleft -= size;
  1061. skb_reset_transport_header(nskb);
  1062. skb_reset_network_header(nskb);
  1063. nskb->len = size;
  1064. skb_queue_tail(&iucv_sk(sk)->backlog_skb_q, nskb);
  1065. }
  1066. return 0;
  1067. }
  1068. /* iucv_process_message() - Receive a single outstanding IUCV message
  1069. *
  1070. * Locking: must be called with message_q.lock held
  1071. */
  1072. static void iucv_process_message(struct sock *sk, struct sk_buff *skb,
  1073. struct iucv_path *path,
  1074. struct iucv_message *msg)
  1075. {
  1076. int rc;
  1077. unsigned int len;
  1078. len = iucv_msg_length(msg);
  1079. /* store msg target class in the second 4 bytes of skb ctrl buffer */
  1080. /* Note: the first 4 bytes are reserved for msg tag */
  1081. memcpy(CB_TRGCLS(skb), &msg->class, CB_TRGCLS_LEN);
  1082. /* check for special IPRM messages (e.g. iucv_sock_shutdown) */
  1083. if ((msg->flags & IUCV_IPRMDATA) && len > 7) {
  1084. if (memcmp(msg->rmmsg, iprm_shutdown, 8) == 0) {
  1085. skb->data = NULL;
  1086. skb->len = 0;
  1087. }
  1088. } else {
  1089. rc = pr_iucv->message_receive(path, msg,
  1090. msg->flags & IUCV_IPRMDATA,
  1091. skb->data, len, NULL);
  1092. if (rc) {
  1093. kfree_skb(skb);
  1094. return;
  1095. }
  1096. /* we need to fragment iucv messages for SOCK_STREAM only;
  1097. * for SOCK_SEQPACKET, it is only relevant if we support
  1098. * record segmentation using MSG_EOR (see also recvmsg()) */
  1099. if (sk->sk_type == SOCK_STREAM &&
  1100. skb->truesize >= sk->sk_rcvbuf / 4) {
  1101. rc = iucv_fragment_skb(sk, skb, len);
  1102. kfree_skb(skb);
  1103. skb = NULL;
  1104. if (rc) {
  1105. pr_iucv->path_sever(path, NULL);
  1106. return;
  1107. }
  1108. skb = skb_dequeue(&iucv_sk(sk)->backlog_skb_q);
  1109. } else {
  1110. skb_reset_transport_header(skb);
  1111. skb_reset_network_header(skb);
  1112. skb->len = len;
  1113. }
  1114. }
  1115. if (sock_queue_rcv_skb(sk, skb))
  1116. skb_queue_head(&iucv_sk(sk)->backlog_skb_q, skb);
  1117. }
  1118. /* iucv_process_message_q() - Process outstanding IUCV messages
  1119. *
  1120. * Locking: must be called with message_q.lock held
  1121. */
  1122. static void iucv_process_message_q(struct sock *sk)
  1123. {
  1124. struct iucv_sock *iucv = iucv_sk(sk);
  1125. struct sk_buff *skb;
  1126. struct sock_msg_q *p, *n;
  1127. list_for_each_entry_safe(p, n, &iucv->message_q.list, list) {
  1128. skb = alloc_skb(iucv_msg_length(&p->msg), GFP_ATOMIC | GFP_DMA);
  1129. if (!skb)
  1130. break;
  1131. iucv_process_message(sk, skb, p->path, &p->msg);
  1132. list_del(&p->list);
  1133. kfree(p);
  1134. if (!skb_queue_empty(&iucv->backlog_skb_q))
  1135. break;
  1136. }
  1137. }
  1138. static int iucv_sock_recvmsg(struct kiocb *iocb, struct socket *sock,
  1139. struct msghdr *msg, size_t len, int flags)
  1140. {
  1141. int noblock = flags & MSG_DONTWAIT;
  1142. struct sock *sk = sock->sk;
  1143. struct iucv_sock *iucv = iucv_sk(sk);
  1144. unsigned int copied, rlen;
  1145. struct sk_buff *skb, *rskb, *cskb, *sskb;
  1146. int blen;
  1147. int err = 0;
  1148. if ((sk->sk_state == IUCV_DISCONN) &&
  1149. skb_queue_empty(&iucv->backlog_skb_q) &&
  1150. skb_queue_empty(&sk->sk_receive_queue) &&
  1151. list_empty(&iucv->message_q.list))
  1152. return 0;
  1153. if (flags & (MSG_OOB))
  1154. return -EOPNOTSUPP;
  1155. /* receive/dequeue next skb:
  1156. * the function understands MSG_PEEK and, thus, does not dequeue skb */
  1157. skb = skb_recv_datagram(sk, flags, noblock, &err);
  1158. if (!skb) {
  1159. if (sk->sk_shutdown & RCV_SHUTDOWN)
  1160. return 0;
  1161. return err;
  1162. }
  1163. rlen = skb->len; /* real length of skb */
  1164. copied = min_t(unsigned int, rlen, len);
  1165. cskb = skb;
  1166. if (skb_copy_datagram_iovec(cskb, 0, msg->msg_iov, copied)) {
  1167. if (!(flags & MSG_PEEK))
  1168. skb_queue_head(&sk->sk_receive_queue, skb);
  1169. return -EFAULT;
  1170. }
  1171. /* SOCK_SEQPACKET: set MSG_TRUNC if recv buf size is too small */
  1172. if (sk->sk_type == SOCK_SEQPACKET) {
  1173. if (copied < rlen)
  1174. msg->msg_flags |= MSG_TRUNC;
  1175. /* each iucv message contains a complete record */
  1176. msg->msg_flags |= MSG_EOR;
  1177. }
  1178. /* create control message to store iucv msg target class:
  1179. * get the trgcls from the control buffer of the skb due to
  1180. * fragmentation of original iucv message. */
  1181. err = put_cmsg(msg, SOL_IUCV, SCM_IUCV_TRGCLS,
  1182. CB_TRGCLS_LEN, CB_TRGCLS(skb));
  1183. if (err) {
  1184. if (!(flags & MSG_PEEK))
  1185. skb_queue_head(&sk->sk_receive_queue, skb);
  1186. return err;
  1187. }
  1188. /* Mark read part of skb as used */
  1189. if (!(flags & MSG_PEEK)) {
  1190. /* SOCK_STREAM: re-queue skb if it contains unreceived data */
  1191. if (sk->sk_type == SOCK_STREAM) {
  1192. skb_pull(skb, copied);
  1193. if (skb->len) {
  1194. skb_queue_head(&sk->sk_receive_queue, skb);
  1195. goto done;
  1196. }
  1197. }
  1198. kfree_skb(skb);
  1199. if (iucv->transport == AF_IUCV_TRANS_HIPER) {
  1200. atomic_inc(&iucv->msg_recv);
  1201. if (atomic_read(&iucv->msg_recv) > iucv->msglimit) {
  1202. WARN_ON(1);
  1203. iucv_sock_close(sk);
  1204. return -EFAULT;
  1205. }
  1206. }
  1207. /* Queue backlog skbs */
  1208. spin_lock_bh(&iucv->message_q.lock);
  1209. rskb = skb_dequeue(&iucv->backlog_skb_q);
  1210. while (rskb) {
  1211. if (sock_queue_rcv_skb(sk, rskb)) {
  1212. skb_queue_head(&iucv->backlog_skb_q,
  1213. rskb);
  1214. break;
  1215. } else {
  1216. rskb = skb_dequeue(&iucv->backlog_skb_q);
  1217. }
  1218. }
  1219. if (skb_queue_empty(&iucv->backlog_skb_q)) {
  1220. if (!list_empty(&iucv->message_q.list))
  1221. iucv_process_message_q(sk);
  1222. if (atomic_read(&iucv->msg_recv) >=
  1223. iucv->msglimit / 2) {
  1224. /* send WIN to peer */
  1225. blen = sizeof(struct af_iucv_trans_hdr) +
  1226. ETH_HLEN;
  1227. sskb = sock_alloc_send_skb(sk, blen, 1, &err);
  1228. if (sskb) {
  1229. skb_reserve(sskb, blen);
  1230. err = afiucv_hs_send(NULL, sk, sskb,
  1231. AF_IUCV_FLAG_WIN);
  1232. }
  1233. if (err) {
  1234. sk->sk_state = IUCV_DISCONN;
  1235. sk->sk_state_change(sk);
  1236. }
  1237. }
  1238. }
  1239. spin_unlock_bh(&iucv->message_q.lock);
  1240. }
  1241. done:
  1242. /* SOCK_SEQPACKET: return real length if MSG_TRUNC is set */
  1243. if (sk->sk_type == SOCK_SEQPACKET && (flags & MSG_TRUNC))
  1244. copied = rlen;
  1245. return copied;
  1246. }
  1247. static inline unsigned int iucv_accept_poll(struct sock *parent)
  1248. {
  1249. struct iucv_sock *isk, *n;
  1250. struct sock *sk;
  1251. list_for_each_entry_safe(isk, n, &iucv_sk(parent)->accept_q, accept_q) {
  1252. sk = (struct sock *) isk;
  1253. if (sk->sk_state == IUCV_CONNECTED)
  1254. return POLLIN | POLLRDNORM;
  1255. }
  1256. return 0;
  1257. }
  1258. unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
  1259. poll_table *wait)
  1260. {
  1261. struct sock *sk = sock->sk;
  1262. unsigned int mask = 0;
  1263. sock_poll_wait(file, sk_sleep(sk), wait);
  1264. if (sk->sk_state == IUCV_LISTEN)
  1265. return iucv_accept_poll(sk);
  1266. if (sk->sk_err || !skb_queue_empty(&sk->sk_error_queue))
  1267. mask |= POLLERR;
  1268. if (sk->sk_shutdown & RCV_SHUTDOWN)
  1269. mask |= POLLRDHUP;
  1270. if (sk->sk_shutdown == SHUTDOWN_MASK)
  1271. mask |= POLLHUP;
  1272. if (!skb_queue_empty(&sk->sk_receive_queue) ||
  1273. (sk->sk_shutdown & RCV_SHUTDOWN))
  1274. mask |= POLLIN | POLLRDNORM;
  1275. if (sk->sk_state == IUCV_CLOSED)
  1276. mask |= POLLHUP;
  1277. if (sk->sk_state == IUCV_DISCONN)
  1278. mask |= POLLIN;
  1279. if (sock_writeable(sk) && iucv_below_msglim(sk))
  1280. mask |= POLLOUT | POLLWRNORM | POLLWRBAND;
  1281. else
  1282. set_bit(SOCK_ASYNC_NOSPACE, &sk->sk_socket->flags);
  1283. return mask;
  1284. }
  1285. static int iucv_sock_shutdown(struct socket *sock, int how)
  1286. {
  1287. struct sock *sk = sock->sk;
  1288. struct iucv_sock *iucv = iucv_sk(sk);
  1289. struct iucv_message txmsg;
  1290. int err = 0;
  1291. how++;
  1292. if ((how & ~SHUTDOWN_MASK) || !how)
  1293. return -EINVAL;
  1294. lock_sock(sk);
  1295. switch (sk->sk_state) {
  1296. case IUCV_DISCONN:
  1297. case IUCV_CLOSING:
  1298. case IUCV_CLOSED:
  1299. err = -ENOTCONN;
  1300. goto fail;
  1301. default:
  1302. sk->sk_shutdown |= how;
  1303. break;
  1304. }
  1305. if (how == SEND_SHUTDOWN || how == SHUTDOWN_MASK) {
  1306. txmsg.class = 0;
  1307. txmsg.tag = 0;
  1308. err = pr_iucv->message_send(iucv->path, &txmsg, IUCV_IPRMDATA,
  1309. 0, (void *) iprm_shutdown, 8);
  1310. if (err) {
  1311. switch (err) {
  1312. case 1:
  1313. err = -ENOTCONN;
  1314. break;
  1315. case 2:
  1316. err = -ECONNRESET;
  1317. break;
  1318. default:
  1319. err = -ENOTCONN;
  1320. break;
  1321. }
  1322. }
  1323. }
  1324. if (how == RCV_SHUTDOWN || how == SHUTDOWN_MASK) {
  1325. err = pr_iucv->path_quiesce(iucv->path, NULL);
  1326. if (err)
  1327. err = -ENOTCONN;
  1328. skb_queue_purge(&sk->sk_receive_queue);
  1329. }
  1330. /* Wake up anyone sleeping in poll */
  1331. sk->sk_state_change(sk);
  1332. fail:
  1333. release_sock(sk);
  1334. return err;
  1335. }
  1336. static int iucv_sock_release(struct socket *sock)
  1337. {
  1338. struct sock *sk = sock->sk;
  1339. int err = 0;
  1340. if (!sk)
  1341. return 0;
  1342. iucv_sock_close(sk);
  1343. sock_orphan(sk);
  1344. iucv_sock_kill(sk);
  1345. return err;
  1346. }
  1347. /* getsockopt and setsockopt */
  1348. static int iucv_sock_setsockopt(struct socket *sock, int level, int optname,
  1349. char __user *optval, unsigned int optlen)
  1350. {
  1351. struct sock *sk = sock->sk;
  1352. struct iucv_sock *iucv = iucv_sk(sk);
  1353. int val;
  1354. int rc;
  1355. if (level != SOL_IUCV)
  1356. return -ENOPROTOOPT;
  1357. if (optlen < sizeof(int))
  1358. return -EINVAL;
  1359. if (get_user(val, (int __user *) optval))
  1360. return -EFAULT;
  1361. rc = 0;
  1362. lock_sock(sk);
  1363. switch (optname) {
  1364. case SO_IPRMDATA_MSG:
  1365. if (val)
  1366. iucv->flags |= IUCV_IPRMDATA;
  1367. else
  1368. iucv->flags &= ~IUCV_IPRMDATA;
  1369. break;
  1370. case SO_MSGLIMIT:
  1371. switch (sk->sk_state) {
  1372. case IUCV_OPEN:
  1373. case IUCV_BOUND:
  1374. if (val < 1 || val > (u16)(~0))
  1375. rc = -EINVAL;
  1376. else
  1377. iucv->msglimit = val;
  1378. break;
  1379. default:
  1380. rc = -EINVAL;
  1381. break;
  1382. }
  1383. break;
  1384. default:
  1385. rc = -ENOPROTOOPT;
  1386. break;
  1387. }
  1388. release_sock(sk);
  1389. return rc;
  1390. }
  1391. static int iucv_sock_getsockopt(struct socket *sock, int level, int optname,
  1392. char __user *optval, int __user *optlen)
  1393. {
  1394. struct sock *sk = sock->sk;
  1395. struct iucv_sock *iucv = iucv_sk(sk);
  1396. unsigned int val;
  1397. int len;
  1398. if (level != SOL_IUCV)
  1399. return -ENOPROTOOPT;
  1400. if (get_user(len, optlen))
  1401. return -EFAULT;
  1402. if (len < 0)
  1403. return -EINVAL;
  1404. len = min_t(unsigned int, len, sizeof(int));
  1405. switch (optname) {
  1406. case SO_IPRMDATA_MSG:
  1407. val = (iucv->flags & IUCV_IPRMDATA) ? 1 : 0;
  1408. break;
  1409. case SO_MSGLIMIT:
  1410. lock_sock(sk);
  1411. val = (iucv->path != NULL) ? iucv->path->msglim /* connected */
  1412. : iucv->msglimit; /* default */
  1413. release_sock(sk);
  1414. break;
  1415. case SO_MSGSIZE:
  1416. if (sk->sk_state == IUCV_OPEN)
  1417. return -EBADFD;
  1418. val = (iucv->hs_dev) ? iucv->hs_dev->mtu -
  1419. sizeof(struct af_iucv_trans_hdr) - ETH_HLEN :
  1420. 0x7fffffff;
  1421. break;
  1422. default:
  1423. return -ENOPROTOOPT;
  1424. }
  1425. if (put_user(len, optlen))
  1426. return -EFAULT;
  1427. if (copy_to_user(optval, &val, len))
  1428. return -EFAULT;
  1429. return 0;
  1430. }
  1431. /* Callback wrappers - called from iucv base support */
  1432. static int iucv_callback_connreq(struct iucv_path *path,
  1433. u8 ipvmid[8], u8 ipuser[16])
  1434. {
  1435. unsigned char user_data[16];
  1436. unsigned char nuser_data[16];
  1437. unsigned char src_name[8];
  1438. struct hlist_node *node;
  1439. struct sock *sk, *nsk;
  1440. struct iucv_sock *iucv, *niucv;
  1441. int err;
  1442. memcpy(src_name, ipuser, 8);
  1443. EBCASC(src_name, 8);
  1444. /* Find out if this path belongs to af_iucv. */
  1445. read_lock(&iucv_sk_list.lock);
  1446. iucv = NULL;
  1447. sk = NULL;
  1448. sk_for_each(sk, node, &iucv_sk_list.head)
  1449. if (sk->sk_state == IUCV_LISTEN &&
  1450. !memcmp(&iucv_sk(sk)->src_name, src_name, 8)) {
  1451. /*
  1452. * Found a listening socket with
  1453. * src_name == ipuser[0-7].
  1454. */
  1455. iucv = iucv_sk(sk);
  1456. break;
  1457. }
  1458. read_unlock(&iucv_sk_list.lock);
  1459. if (!iucv)
  1460. /* No socket found, not one of our paths. */
  1461. return -EINVAL;
  1462. bh_lock_sock(sk);
  1463. /* Check if parent socket is listening */
  1464. low_nmcpy(user_data, iucv->src_name);
  1465. high_nmcpy(user_data, iucv->dst_name);
  1466. ASCEBC(user_data, sizeof(user_data));
  1467. if (sk->sk_state != IUCV_LISTEN) {
  1468. err = pr_iucv->path_sever(path, user_data);
  1469. iucv_path_free(path);
  1470. goto fail;
  1471. }
  1472. /* Check for backlog size */
  1473. if (sk_acceptq_is_full(sk)) {
  1474. err = pr_iucv->path_sever(path, user_data);
  1475. iucv_path_free(path);
  1476. goto fail;
  1477. }
  1478. /* Create the new socket */
  1479. nsk = iucv_sock_alloc(NULL, sk->sk_type, GFP_ATOMIC);
  1480. if (!nsk) {
  1481. err = pr_iucv->path_sever(path, user_data);
  1482. iucv_path_free(path);
  1483. goto fail;
  1484. }
  1485. niucv = iucv_sk(nsk);
  1486. iucv_sock_init(nsk, sk);
  1487. /* Set the new iucv_sock */
  1488. memcpy(niucv->dst_name, ipuser + 8, 8);
  1489. EBCASC(niucv->dst_name, 8);
  1490. memcpy(niucv->dst_user_id, ipvmid, 8);
  1491. memcpy(niucv->src_name, iucv->src_name, 8);
  1492. memcpy(niucv->src_user_id, iucv->src_user_id, 8);
  1493. niucv->path = path;
  1494. /* Call iucv_accept */
  1495. high_nmcpy(nuser_data, ipuser + 8);
  1496. memcpy(nuser_data + 8, niucv->src_name, 8);
  1497. ASCEBC(nuser_data + 8, 8);
  1498. /* set message limit for path based on msglimit of accepting socket */
  1499. niucv->msglimit = iucv->msglimit;
  1500. path->msglim = iucv->msglimit;
  1501. err = pr_iucv->path_accept(path, &af_iucv_handler, nuser_data, nsk);
  1502. if (err) {
  1503. iucv_sever_path(nsk, 1);
  1504. iucv_sock_kill(nsk);
  1505. goto fail;
  1506. }
  1507. iucv_accept_enqueue(sk, nsk);
  1508. /* Wake up accept */
  1509. nsk->sk_state = IUCV_CONNECTED;
  1510. sk->sk_data_ready(sk, 1);
  1511. err = 0;
  1512. fail:
  1513. bh_unlock_sock(sk);
  1514. return 0;
  1515. }
  1516. static void iucv_callback_connack(struct iucv_path *path, u8 ipuser[16])
  1517. {
  1518. struct sock *sk = path->private;
  1519. sk->sk_state = IUCV_CONNECTED;
  1520. sk->sk_state_change(sk);
  1521. }
  1522. static void iucv_callback_rx(struct iucv_path *path, struct iucv_message *msg)
  1523. {
  1524. struct sock *sk = path->private;
  1525. struct iucv_sock *iucv = iucv_sk(sk);
  1526. struct sk_buff *skb;
  1527. struct sock_msg_q *save_msg;
  1528. int len;
  1529. if (sk->sk_shutdown & RCV_SHUTDOWN) {
  1530. pr_iucv->message_reject(path, msg);
  1531. return;
  1532. }
  1533. spin_lock(&iucv->message_q.lock);
  1534. if (!list_empty(&iucv->message_q.list) ||
  1535. !skb_queue_empty(&iucv->backlog_skb_q))
  1536. goto save_message;
  1537. len = atomic_read(&sk->sk_rmem_alloc);
  1538. len += SKB_TRUESIZE(iucv_msg_length(msg));
  1539. if (len > sk->sk_rcvbuf)
  1540. goto save_message;
  1541. skb = alloc_skb(iucv_msg_length(msg), GFP_ATOMIC | GFP_DMA);
  1542. if (!skb)
  1543. goto save_message;
  1544. iucv_process_message(sk, skb, path, msg);
  1545. goto out_unlock;
  1546. save_message:
  1547. save_msg = kzalloc(sizeof(struct sock_msg_q), GFP_ATOMIC | GFP_DMA);
  1548. if (!save_msg)
  1549. goto out_unlock;
  1550. save_msg->path = path;
  1551. save_msg->msg = *msg;
  1552. list_add_tail(&save_msg->list, &iucv->message_q.list);
  1553. out_unlock:
  1554. spin_unlock(&iucv->message_q.lock);
  1555. }
  1556. static void iucv_callback_txdone(struct iucv_path *path,
  1557. struct iucv_message *msg)
  1558. {
  1559. struct sock *sk = path->private;
  1560. struct sk_buff *this = NULL;
  1561. struct sk_buff_head *list = &iucv_sk(sk)->send_skb_q;
  1562. struct sk_buff *list_skb = list->next;
  1563. unsigned long flags;
  1564. bh_lock_sock(sk);
  1565. if (!skb_queue_empty(list)) {
  1566. spin_lock_irqsave(&list->lock, flags);
  1567. while (list_skb != (struct sk_buff *)list) {
  1568. if (!memcmp(&msg->tag, CB_TAG(list_skb), CB_TAG_LEN)) {
  1569. this = list_skb;
  1570. break;
  1571. }
  1572. list_skb = list_skb->next;
  1573. }
  1574. if (this)
  1575. __skb_unlink(this, list);
  1576. spin_unlock_irqrestore(&list->lock, flags);
  1577. if (this) {
  1578. kfree_skb(this);
  1579. /* wake up any process waiting for sending */
  1580. iucv_sock_wake_msglim(sk);
  1581. }
  1582. }
  1583. if (sk->sk_state == IUCV_CLOSING) {
  1584. if (skb_queue_empty(&iucv_sk(sk)->send_skb_q)) {
  1585. sk->sk_state = IUCV_CLOSED;
  1586. sk->sk_state_change(sk);
  1587. }
  1588. }
  1589. bh_unlock_sock(sk);
  1590. }
  1591. static void iucv_callback_connrej(struct iucv_path *path, u8 ipuser[16])
  1592. {
  1593. struct sock *sk = path->private;
  1594. if (sk->sk_state == IUCV_CLOSED)
  1595. return;
  1596. bh_lock_sock(sk);
  1597. iucv_sever_path(sk, 1);
  1598. sk->sk_state = IUCV_DISCONN;
  1599. sk->sk_state_change(sk);
  1600. bh_unlock_sock(sk);
  1601. }
  1602. /* called if the other communication side shuts down its RECV direction;
  1603. * in turn, the callback sets SEND_SHUTDOWN to disable sending of data.
  1604. */
  1605. static void iucv_callback_shutdown(struct iucv_path *path, u8 ipuser[16])
  1606. {
  1607. struct sock *sk = path->private;
  1608. bh_lock_sock(sk);
  1609. if (sk->sk_state != IUCV_CLOSED) {
  1610. sk->sk_shutdown |= SEND_SHUTDOWN;
  1611. sk->sk_state_change(sk);
  1612. }
  1613. bh_unlock_sock(sk);
  1614. }
  1615. /***************** HiperSockets transport callbacks ********************/
  1616. static void afiucv_swap_src_dest(struct sk_buff *skb)
  1617. {
  1618. struct af_iucv_trans_hdr *trans_hdr =
  1619. (struct af_iucv_trans_hdr *)skb->data;
  1620. char tmpID[8];
  1621. char tmpName[8];
  1622. ASCEBC(trans_hdr->destUserID, sizeof(trans_hdr->destUserID));
  1623. ASCEBC(trans_hdr->destAppName, sizeof(trans_hdr->destAppName));
  1624. ASCEBC(trans_hdr->srcUserID, sizeof(trans_hdr->srcUserID));
  1625. ASCEBC(trans_hdr->srcAppName, sizeof(trans_hdr->srcAppName));
  1626. memcpy(tmpID, trans_hdr->srcUserID, 8);
  1627. memcpy(tmpName, trans_hdr->srcAppName, 8);
  1628. memcpy(trans_hdr->srcUserID, trans_hdr->destUserID, 8);
  1629. memcpy(trans_hdr->srcAppName, trans_hdr->destAppName, 8);
  1630. memcpy(trans_hdr->destUserID, tmpID, 8);
  1631. memcpy(trans_hdr->destAppName, tmpName, 8);
  1632. skb_push(skb, ETH_HLEN);
  1633. memset(skb->data, 0, ETH_HLEN);
  1634. }
  1635. /**
  1636. * afiucv_hs_callback_syn - react on received SYN
  1637. **/
  1638. static int afiucv_hs_callback_syn(struct sock *sk, struct sk_buff *skb)
  1639. {
  1640. struct sock *nsk;
  1641. struct iucv_sock *iucv, *niucv;
  1642. struct af_iucv_trans_hdr *trans_hdr;
  1643. int err;
  1644. iucv = iucv_sk(sk);
  1645. trans_hdr = (struct af_iucv_trans_hdr *)skb->data;
  1646. if (!iucv) {
  1647. /* no sock - connection refused */
  1648. afiucv_swap_src_dest(skb);
  1649. trans_hdr->flags = AF_IUCV_FLAG_SYN | AF_IUCV_FLAG_FIN;
  1650. err = dev_queue_xmit(skb);
  1651. goto out;
  1652. }
  1653. nsk = iucv_sock_alloc(NULL, sk->sk_type, GFP_ATOMIC);
  1654. bh_lock_sock(sk);
  1655. if ((sk->sk_state != IUCV_LISTEN) ||
  1656. sk_acceptq_is_full(sk) ||
  1657. !nsk) {
  1658. /* error on server socket - connection refused */
  1659. if (nsk)
  1660. sk_free(nsk);
  1661. afiucv_swap_src_dest(skb);
  1662. trans_hdr->flags = AF_IUCV_FLAG_SYN | AF_IUCV_FLAG_FIN;
  1663. err = dev_queue_xmit(skb);
  1664. bh_unlock_sock(sk);
  1665. goto out;
  1666. }
  1667. niucv = iucv_sk(nsk);
  1668. iucv_sock_init(nsk, sk);
  1669. niucv->transport = AF_IUCV_TRANS_HIPER;
  1670. niucv->msglimit = iucv->msglimit;
  1671. if (!trans_hdr->window)
  1672. niucv->msglimit_peer = IUCV_HIPER_MSGLIM_DEFAULT;
  1673. else
  1674. niucv->msglimit_peer = trans_hdr->window;
  1675. memcpy(niucv->dst_name, trans_hdr->srcAppName, 8);
  1676. memcpy(niucv->dst_user_id, trans_hdr->srcUserID, 8);
  1677. memcpy(niucv->src_name, iucv->src_name, 8);
  1678. memcpy(niucv->src_user_id, iucv->src_user_id, 8);
  1679. nsk->sk_bound_dev_if = sk->sk_bound_dev_if;
  1680. niucv->hs_dev = iucv->hs_dev;
  1681. dev_hold(niucv->hs_dev);
  1682. afiucv_swap_src_dest(skb);
  1683. trans_hdr->flags = AF_IUCV_FLAG_SYN | AF_IUCV_FLAG_ACK;
  1684. trans_hdr->window = niucv->msglimit;
  1685. /* if receiver acks the xmit connection is established */
  1686. err = dev_queue_xmit(skb);
  1687. if (!err) {
  1688. iucv_accept_enqueue(sk, nsk);
  1689. nsk->sk_state = IUCV_CONNECTED;
  1690. sk->sk_data_ready(sk, 1);
  1691. } else
  1692. iucv_sock_kill(nsk);
  1693. bh_unlock_sock(sk);
  1694. out:
  1695. return NET_RX_SUCCESS;
  1696. }
  1697. /**
  1698. * afiucv_hs_callback_synack() - react on received SYN-ACK
  1699. **/
  1700. static int afiucv_hs_callback_synack(struct sock *sk, struct sk_buff *skb)
  1701. {
  1702. struct iucv_sock *iucv = iucv_sk(sk);
  1703. struct af_iucv_trans_hdr *trans_hdr =
  1704. (struct af_iucv_trans_hdr *)skb->data;
  1705. if (!iucv)
  1706. goto out;
  1707. if (sk->sk_state != IUCV_BOUND)
  1708. goto out;
  1709. bh_lock_sock(sk);
  1710. iucv->msglimit_peer = trans_hdr->window;
  1711. sk->sk_state = IUCV_CONNECTED;
  1712. sk->sk_state_change(sk);
  1713. bh_unlock_sock(sk);
  1714. out:
  1715. kfree_skb(skb);
  1716. return NET_RX_SUCCESS;
  1717. }
  1718. /**
  1719. * afiucv_hs_callback_synfin() - react on received SYN_FIN
  1720. **/
  1721. static int afiucv_hs_callback_synfin(struct sock *sk, struct sk_buff *skb)
  1722. {
  1723. struct iucv_sock *iucv = iucv_sk(sk);
  1724. if (!iucv)
  1725. goto out;
  1726. if (sk->sk_state != IUCV_BOUND)
  1727. goto out;
  1728. bh_lock_sock(sk);
  1729. sk->sk_state = IUCV_DISCONN;
  1730. sk->sk_state_change(sk);
  1731. bh_unlock_sock(sk);
  1732. out:
  1733. kfree_skb(skb);
  1734. return NET_RX_SUCCESS;
  1735. }
  1736. /**
  1737. * afiucv_hs_callback_fin() - react on received FIN
  1738. **/
  1739. static int afiucv_hs_callback_fin(struct sock *sk, struct sk_buff *skb)
  1740. {
  1741. struct iucv_sock *iucv = iucv_sk(sk);
  1742. /* other end of connection closed */
  1743. if (!iucv)
  1744. goto out;
  1745. bh_lock_sock(sk);
  1746. if (sk->sk_state == IUCV_CONNECTED) {
  1747. sk->sk_state = IUCV_DISCONN;
  1748. sk->sk_state_change(sk);
  1749. }
  1750. bh_unlock_sock(sk);
  1751. out:
  1752. kfree_skb(skb);
  1753. return NET_RX_SUCCESS;
  1754. }
  1755. /**
  1756. * afiucv_hs_callback_win() - react on received WIN
  1757. **/
  1758. static int afiucv_hs_callback_win(struct sock *sk, struct sk_buff *skb)
  1759. {
  1760. struct iucv_sock *iucv = iucv_sk(sk);
  1761. struct af_iucv_trans_hdr *trans_hdr =
  1762. (struct af_iucv_trans_hdr *)skb->data;
  1763. if (!iucv)
  1764. return NET_RX_SUCCESS;
  1765. if (sk->sk_state != IUCV_CONNECTED)
  1766. return NET_RX_SUCCESS;
  1767. atomic_sub(trans_hdr->window, &iucv->msg_sent);
  1768. iucv_sock_wake_msglim(sk);
  1769. return NET_RX_SUCCESS;
  1770. }
  1771. /**
  1772. * afiucv_hs_callback_rx() - react on received data
  1773. **/
  1774. static int afiucv_hs_callback_rx(struct sock *sk, struct sk_buff *skb)
  1775. {
  1776. struct iucv_sock *iucv = iucv_sk(sk);
  1777. if (!iucv) {
  1778. kfree_skb(skb);
  1779. return NET_RX_SUCCESS;
  1780. }
  1781. if (sk->sk_state != IUCV_CONNECTED) {
  1782. kfree_skb(skb);
  1783. return NET_RX_SUCCESS;
  1784. }
  1785. /* write stuff from iucv_msg to skb cb */
  1786. if (skb->len <= sizeof(struct af_iucv_trans_hdr)) {
  1787. kfree_skb(skb);
  1788. return NET_RX_SUCCESS;
  1789. }
  1790. skb_pull(skb, sizeof(struct af_iucv_trans_hdr));
  1791. skb_reset_transport_header(skb);
  1792. skb_reset_network_header(skb);
  1793. spin_lock(&iucv->message_q.lock);
  1794. if (skb_queue_empty(&iucv->backlog_skb_q)) {
  1795. if (sock_queue_rcv_skb(sk, skb)) {
  1796. /* handle rcv queue full */
  1797. skb_queue_tail(&iucv->backlog_skb_q, skb);
  1798. }
  1799. } else
  1800. skb_queue_tail(&iucv_sk(sk)->backlog_skb_q, skb);
  1801. spin_unlock(&iucv->message_q.lock);
  1802. return NET_RX_SUCCESS;
  1803. }
  1804. /**
  1805. * afiucv_hs_rcv() - base function for arriving data through HiperSockets
  1806. * transport
  1807. * called from netif RX softirq
  1808. **/
  1809. static int afiucv_hs_rcv(struct sk_buff *skb, struct net_device *dev,
  1810. struct packet_type *pt, struct net_device *orig_dev)
  1811. {
  1812. struct hlist_node *node;
  1813. struct sock *sk;
  1814. struct iucv_sock *iucv;
  1815. struct af_iucv_trans_hdr *trans_hdr;
  1816. char nullstring[8];
  1817. int err = 0;
  1818. skb_pull(skb, ETH_HLEN);
  1819. trans_hdr = (struct af_iucv_trans_hdr *)skb->data;
  1820. EBCASC(trans_hdr->destAppName, sizeof(trans_hdr->destAppName));
  1821. EBCASC(trans_hdr->destUserID, sizeof(trans_hdr->destUserID));
  1822. EBCASC(trans_hdr->srcAppName, sizeof(trans_hdr->srcAppName));
  1823. EBCASC(trans_hdr->srcUserID, sizeof(trans_hdr->srcUserID));
  1824. memset(nullstring, 0, sizeof(nullstring));
  1825. iucv = NULL;
  1826. sk = NULL;
  1827. read_lock(&iucv_sk_list.lock);
  1828. sk_for_each(sk, node, &iucv_sk_list.head) {
  1829. if (trans_hdr->flags == AF_IUCV_FLAG_SYN) {
  1830. if ((!memcmp(&iucv_sk(sk)->src_name,
  1831. trans_hdr->destAppName, 8)) &&
  1832. (!memcmp(&iucv_sk(sk)->src_user_id,
  1833. trans_hdr->destUserID, 8)) &&
  1834. (!memcmp(&iucv_sk(sk)->dst_name, nullstring, 8)) &&
  1835. (!memcmp(&iucv_sk(sk)->dst_user_id,
  1836. nullstring, 8))) {
  1837. iucv = iucv_sk(sk);
  1838. break;
  1839. }
  1840. } else {
  1841. if ((!memcmp(&iucv_sk(sk)->src_name,
  1842. trans_hdr->destAppName, 8)) &&
  1843. (!memcmp(&iucv_sk(sk)->src_user_id,
  1844. trans_hdr->destUserID, 8)) &&
  1845. (!memcmp(&iucv_sk(sk)->dst_name,
  1846. trans_hdr->srcAppName, 8)) &&
  1847. (!memcmp(&iucv_sk(sk)->dst_user_id,
  1848. trans_hdr->srcUserID, 8))) {
  1849. iucv = iucv_sk(sk);
  1850. break;
  1851. }
  1852. }
  1853. }
  1854. read_unlock(&iucv_sk_list.lock);
  1855. if (!iucv)
  1856. sk = NULL;
  1857. /* no sock
  1858. how should we send with no sock
  1859. 1) send without sock no send rc checking?
  1860. 2) introduce default sock to handle this cases
  1861. SYN -> send SYN|ACK in good case, send SYN|FIN in bad case
  1862. data -> send FIN
  1863. SYN|ACK, SYN|FIN, FIN -> no action? */
  1864. switch (trans_hdr->flags) {
  1865. case AF_IUCV_FLAG_SYN:
  1866. /* connect request */
  1867. err = afiucv_hs_callback_syn(sk, skb);
  1868. break;
  1869. case (AF_IUCV_FLAG_SYN | AF_IUCV_FLAG_ACK):
  1870. /* connect request confirmed */
  1871. err = afiucv_hs_callback_synack(sk, skb);
  1872. break;
  1873. case (AF_IUCV_FLAG_SYN | AF_IUCV_FLAG_FIN):
  1874. /* connect request refused */
  1875. err = afiucv_hs_callback_synfin(sk, skb);
  1876. break;
  1877. case (AF_IUCV_FLAG_FIN):
  1878. /* close request */
  1879. err = afiucv_hs_callback_fin(sk, skb);
  1880. break;
  1881. case (AF_IUCV_FLAG_WIN):
  1882. err = afiucv_hs_callback_win(sk, skb);
  1883. if (skb->len == sizeof(struct af_iucv_trans_hdr)) {
  1884. kfree_skb(skb);
  1885. break;
  1886. }
  1887. /* fall through */
  1888. case 0:
  1889. /* plain data frame */
  1890. memcpy(CB_TRGCLS(skb), &trans_hdr->iucv_hdr.class,
  1891. CB_TRGCLS_LEN);
  1892. err = afiucv_hs_callback_rx(sk, skb);
  1893. break;
  1894. default:
  1895. ;
  1896. }
  1897. return err;
  1898. }
  1899. /**
  1900. * afiucv_hs_callback_txnotify() - handle send notifcations from HiperSockets
  1901. * transport
  1902. **/
  1903. static void afiucv_hs_callback_txnotify(struct sk_buff *skb,
  1904. enum iucv_tx_notify n)
  1905. {
  1906. struct sock *isk = skb->sk;
  1907. struct sock *sk = NULL;
  1908. struct iucv_sock *iucv = NULL;
  1909. struct sk_buff_head *list;
  1910. struct sk_buff *list_skb;
  1911. struct sk_buff *nskb;
  1912. unsigned long flags;
  1913. struct hlist_node *node;
  1914. read_lock_irqsave(&iucv_sk_list.lock, flags);
  1915. sk_for_each(sk, node, &iucv_sk_list.head)
  1916. if (sk == isk) {
  1917. iucv = iucv_sk(sk);
  1918. break;
  1919. }
  1920. read_unlock_irqrestore(&iucv_sk_list.lock, flags);
  1921. if (!iucv || sock_flag(sk, SOCK_ZAPPED))
  1922. return;
  1923. list = &iucv->send_skb_q;
  1924. spin_lock_irqsave(&list->lock, flags);
  1925. if (skb_queue_empty(list))
  1926. goto out_unlock;
  1927. list_skb = list->next;
  1928. nskb = list_skb->next;
  1929. while (list_skb != (struct sk_buff *)list) {
  1930. if (skb_shinfo(list_skb) == skb_shinfo(skb)) {
  1931. switch (n) {
  1932. case TX_NOTIFY_OK:
  1933. __skb_unlink(list_skb, list);
  1934. kfree_skb(list_skb);
  1935. iucv_sock_wake_msglim(sk);
  1936. break;
  1937. case TX_NOTIFY_PENDING:
  1938. atomic_inc(&iucv->pendings);
  1939. break;
  1940. case TX_NOTIFY_DELAYED_OK:
  1941. __skb_unlink(list_skb, list);
  1942. atomic_dec(&iucv->pendings);
  1943. if (atomic_read(&iucv->pendings) <= 0)
  1944. iucv_sock_wake_msglim(sk);
  1945. kfree_skb(list_skb);
  1946. break;
  1947. case TX_NOTIFY_UNREACHABLE:
  1948. case TX_NOTIFY_DELAYED_UNREACHABLE:
  1949. case TX_NOTIFY_TPQFULL: /* not yet used */
  1950. case TX_NOTIFY_GENERALERROR:
  1951. case TX_NOTIFY_DELAYED_GENERALERROR:
  1952. __skb_unlink(list_skb, list);
  1953. kfree_skb(list_skb);
  1954. if (sk->sk_state == IUCV_CONNECTED) {
  1955. sk->sk_state = IUCV_DISCONN;
  1956. sk->sk_state_change(sk);
  1957. }
  1958. break;
  1959. }
  1960. break;
  1961. }
  1962. list_skb = nskb;
  1963. nskb = nskb->next;
  1964. }
  1965. out_unlock:
  1966. spin_unlock_irqrestore(&list->lock, flags);
  1967. if (sk->sk_state == IUCV_CLOSING) {
  1968. if (skb_queue_empty(&iucv_sk(sk)->send_skb_q)) {
  1969. sk->sk_state = IUCV_CLOSED;
  1970. sk->sk_state_change(sk);
  1971. }
  1972. }
  1973. }
  1974. static const struct proto_ops iucv_sock_ops = {
  1975. .family = PF_IUCV,
  1976. .owner = THIS_MODULE,
  1977. .release = iucv_sock_release,
  1978. .bind = iucv_sock_bind,
  1979. .connect = iucv_sock_connect,
  1980. .listen = iucv_sock_listen,
  1981. .accept = iucv_sock_accept,
  1982. .getname = iucv_sock_getname,
  1983. .sendmsg = iucv_sock_sendmsg,
  1984. .recvmsg = iucv_sock_recvmsg,
  1985. .poll = iucv_sock_poll,
  1986. .ioctl = sock_no_ioctl,
  1987. .mmap = sock_no_mmap,
  1988. .socketpair = sock_no_socketpair,
  1989. .shutdown = iucv_sock_shutdown,
  1990. .setsockopt = iucv_sock_setsockopt,
  1991. .getsockopt = iucv_sock_getsockopt,
  1992. };
  1993. static const struct net_proto_family iucv_sock_family_ops = {
  1994. .family = AF_IUCV,
  1995. .owner = THIS_MODULE,
  1996. .create = iucv_sock_create,
  1997. };
  1998. static struct packet_type iucv_packet_type = {
  1999. .type = cpu_to_be16(ETH_P_AF_IUCV),
  2000. .func = afiucv_hs_rcv,
  2001. };
  2002. static int afiucv_iucv_init(void)
  2003. {
  2004. int err;
  2005. err = pr_iucv->iucv_register(&af_iucv_handler, 0);
  2006. if (err)
  2007. goto out;
  2008. /* establish dummy device */
  2009. af_iucv_driver.bus = pr_iucv->bus;
  2010. err = driver_register(&af_iucv_driver);
  2011. if (err)
  2012. goto out_iucv;
  2013. af_iucv_dev = kzalloc(sizeof(struct device), GFP_KERNEL);
  2014. if (!af_iucv_dev) {
  2015. err = -ENOMEM;
  2016. goto out_driver;
  2017. }
  2018. dev_set_name(af_iucv_dev, "af_iucv");
  2019. af_iucv_dev->bus = pr_iucv->bus;
  2020. af_iucv_dev->parent = pr_iucv->root;
  2021. af_iucv_dev->release = (void (*)(struct device *))kfree;
  2022. af_iucv_dev->driver = &af_iucv_driver;
  2023. err = device_register(af_iucv_dev);
  2024. if (err)
  2025. goto out_driver;
  2026. return 0;
  2027. out_driver:
  2028. driver_unregister(&af_iucv_driver);
  2029. out_iucv:
  2030. pr_iucv->iucv_unregister(&af_iucv_handler, 0);
  2031. out:
  2032. return err;
  2033. }
  2034. static int __init afiucv_init(void)
  2035. {
  2036. int err;
  2037. if (MACHINE_IS_VM) {
  2038. cpcmd("QUERY USERID", iucv_userid, sizeof(iucv_userid), &err);
  2039. if (unlikely(err)) {
  2040. WARN_ON(err);
  2041. err = -EPROTONOSUPPORT;
  2042. goto out;
  2043. }
  2044. pr_iucv = try_then_request_module(symbol_get(iucv_if), "iucv");
  2045. if (!pr_iucv) {
  2046. printk(KERN_WARNING "iucv_if lookup failed\n");
  2047. memset(&iucv_userid, 0, sizeof(iucv_userid));
  2048. }
  2049. } else {
  2050. memset(&iucv_userid, 0, sizeof(iucv_userid));
  2051. pr_iucv = NULL;
  2052. }
  2053. err = proto_register(&iucv_proto, 0);
  2054. if (err)
  2055. goto out;
  2056. err = sock_register(&iucv_sock_family_ops);
  2057. if (err)
  2058. goto out_proto;
  2059. if (pr_iucv) {
  2060. err = afiucv_iucv_init();
  2061. if (err)
  2062. goto out_sock;
  2063. }
  2064. dev_add_pack(&iucv_packet_type);
  2065. return 0;
  2066. out_sock:
  2067. sock_unregister(PF_IUCV);
  2068. out_proto:
  2069. proto_unregister(&iucv_proto);
  2070. out:
  2071. if (pr_iucv)
  2072. symbol_put(iucv_if);
  2073. return err;
  2074. }
  2075. static void __exit afiucv_exit(void)
  2076. {
  2077. if (pr_iucv) {
  2078. device_unregister(af_iucv_dev);
  2079. driver_unregister(&af_iucv_driver);
  2080. pr_iucv->iucv_unregister(&af_iucv_handler, 0);
  2081. symbol_put(iucv_if);
  2082. }
  2083. dev_remove_pack(&iucv_packet_type);
  2084. sock_unregister(PF_IUCV);
  2085. proto_unregister(&iucv_proto);
  2086. }
  2087. module_init(afiucv_init);
  2088. module_exit(afiucv_exit);
  2089. MODULE_AUTHOR("Jennifer Hunt <jenhunt@us.ibm.com>");
  2090. MODULE_DESCRIPTION("IUCV Sockets ver " VERSION);
  2091. MODULE_VERSION(VERSION);
  2092. MODULE_LICENSE("GPL");
  2093. MODULE_ALIAS_NETPROTO(PF_IUCV);