610794a416e8d2fe2312b791591de809ae24f274
[linux-3.10.git] / net / phonet / pep.c
1 /*
2  * File: pep.c
3  *
4  * Phonet pipe protocol end point socket
5  *
6  * Copyright (C) 2008 Nokia Corporation.
7  *
8  * Author: RĂ©mi Denis-Courmont <remi.denis-courmont@nokia.com>
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * version 2 as published by the Free Software Foundation.
13  *
14  * This program is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22  * 02110-1301 USA
23  */
24
25 #include <linux/kernel.h>
26 #include <linux/slab.h>
27 #include <linux/socket.h>
28 #include <net/sock.h>
29 #include <net/tcp_states.h>
30 #include <asm/ioctls.h>
31
32 #include <linux/phonet.h>
33 #include <net/phonet/phonet.h>
34 #include <net/phonet/pep.h>
35 #include <net/phonet/gprs.h>
36
37 /* sk_state values:
38  * TCP_CLOSE            sock not in use yet
39  * TCP_CLOSE_WAIT       disconnected pipe
40  * TCP_LISTEN           listening pipe endpoint
41  * TCP_SYN_RECV         connected pipe in disabled state
42  * TCP_ESTABLISHED      connected pipe in enabled state
43  *
44  * pep_sock locking:
45  *  - sk_state, ackq, hlist: sock lock needed
46  *  - listener: read only
47  *  - pipe_handle: read only
48  */
49
50 #define CREDITS_MAX     10
51 #define CREDITS_THR     7
52
53 #define pep_sb_size(s) (((s) + 5) & ~3) /* 2-bytes head, 32-bits aligned */
54
55 /* Get the next TLV sub-block. */
56 static unsigned char *pep_get_sb(struct sk_buff *skb, u8 *ptype, u8 *plen,
57                                         void *buf)
58 {
59         void *data = NULL;
60         struct {
61                 u8 sb_type;
62                 u8 sb_len;
63         } *ph, h;
64         int buflen = *plen;
65
66         ph = skb_header_pointer(skb, 0, 2, &h);
67         if (ph == NULL || ph->sb_len < 2 || !pskb_may_pull(skb, ph->sb_len))
68                 return NULL;
69         ph->sb_len -= 2;
70         *ptype = ph->sb_type;
71         *plen = ph->sb_len;
72
73         if (buflen > ph->sb_len)
74                 buflen = ph->sb_len;
75         data = skb_header_pointer(skb, 2, buflen, buf);
76         __skb_pull(skb, 2 + ph->sb_len);
77         return data;
78 }
79
80 static struct sk_buff *pep_alloc_skb(struct sock *sk, const void *payload,
81                                         int len, gfp_t priority)
82 {
83         struct sk_buff *skb = alloc_skb(MAX_PNPIPE_HEADER + len, priority);
84         if (!skb)
85                 return NULL;
86         skb_set_owner_w(skb, sk);
87
88         skb_reserve(skb, MAX_PNPIPE_HEADER);
89         __skb_put(skb, len);
90         skb_copy_to_linear_data(skb, payload, len);
91         __skb_push(skb, sizeof(struct pnpipehdr));
92         skb_reset_transport_header(skb);
93         return skb;
94 }
95
96 static int pep_reply(struct sock *sk, struct sk_buff *oskb, u8 code,
97                         const void *data, int len, gfp_t priority)
98 {
99         const struct pnpipehdr *oph = pnp_hdr(oskb);
100         struct pnpipehdr *ph;
101         struct sk_buff *skb;
102         struct sockaddr_pn peer;
103
104         skb = pep_alloc_skb(sk, data, len, priority);
105         if (!skb)
106                 return -ENOMEM;
107
108         ph = pnp_hdr(skb);
109         ph->utid = oph->utid;
110         ph->message_id = oph->message_id + 1; /* REQ -> RESP */
111         ph->pipe_handle = oph->pipe_handle;
112         ph->error_code = code;
113
114         pn_skb_get_src_sockaddr(oskb, &peer);
115         return pn_skb_send(sk, skb, &peer);
116 }
117
118 static int pep_indicate(struct sock *sk, u8 id, u8 code,
119                         const void *data, int len, gfp_t priority)
120 {
121         struct pep_sock *pn = pep_sk(sk);
122         struct pnpipehdr *ph;
123         struct sk_buff *skb;
124
125         skb = pep_alloc_skb(sk, data, len, priority);
126         if (!skb)
127                 return -ENOMEM;
128
129         ph = pnp_hdr(skb);
130         ph->utid = 0;
131         ph->message_id = id;
132         ph->pipe_handle = pn->pipe_handle;
133         ph->data[0] = code;
134         return pn_skb_send(sk, skb, NULL);
135 }
136
137 #define PAD 0x00
138
139 #ifdef CONFIG_PHONET_PIPECTRLR
140 static int pipe_handler_request(struct sock *sk, u8 id, u8 code,
141                                 const void *data, int len)
142 {
143         struct pep_sock *pn = pep_sk(sk);
144         struct pnpipehdr *ph;
145         struct sk_buff *skb;
146
147         skb = pep_alloc_skb(sk, data, len, GFP_KERNEL);
148         if (!skb)
149                 return -ENOMEM;
150
151         ph = pnp_hdr(skb);
152         ph->utid = id; /* whatever */
153         ph->message_id = id;
154         ph->pipe_handle = pn->pipe_handle;
155         ph->data[0] = code;
156         return pn_skb_send(sk, skb, NULL);
157 }
158
159 static int pipe_handler_send_created_ind(struct sock *sk)
160 {
161         struct pep_sock *pn = pep_sk(sk);
162         u8 data[4] = {
163                 PN_PIPE_SB_NEGOTIATED_FC, pep_sb_size(2),
164                 pn->tx_fc, pn->rx_fc,
165         };
166
167         return pep_indicate(sk, PNS_PIPE_CREATED_IND, 1 /* sub-blocks */,
168                                 data, 4, GFP_ATOMIC);
169 }
170
171 static int pipe_handler_send_ind(struct sock *sk, u8 id)
172 {
173         return pep_indicate(sk, id, PAD, NULL, 0, GFP_ATOMIC);
174 }
175
176 static int pipe_handler_enable_pipe(struct sock *sk, int enable)
177 {
178         u8 id = enable ? PNS_PEP_ENABLE_REQ : PNS_PEP_DISABLE_REQ;
179
180         return pipe_handler_request(sk, id, PAD, NULL, 0);
181 }
182 #endif
183
184 static int pep_accept_conn(struct sock *sk, struct sk_buff *skb)
185 {
186         static const u8 data[20] = {
187                 PAD, PAD, PAD, 2 /* sub-blocks */,
188                 PN_PIPE_SB_REQUIRED_FC_TX, pep_sb_size(5), 3, PAD,
189                         PN_MULTI_CREDIT_FLOW_CONTROL,
190                         PN_ONE_CREDIT_FLOW_CONTROL,
191                         PN_LEGACY_FLOW_CONTROL,
192                         PAD,
193                 PN_PIPE_SB_PREFERRED_FC_RX, pep_sb_size(5), 3, PAD,
194                         PN_MULTI_CREDIT_FLOW_CONTROL,
195                         PN_ONE_CREDIT_FLOW_CONTROL,
196                         PN_LEGACY_FLOW_CONTROL,
197                         PAD,
198         };
199
200         might_sleep();
201         return pep_reply(sk, skb, PN_PIPE_NO_ERROR, data, sizeof(data),
202                                 GFP_KERNEL);
203 }
204
205 static int pep_reject_conn(struct sock *sk, struct sk_buff *skb, u8 code)
206 {
207         static const u8 data[4] = { PAD, PAD, PAD, 0 /* sub-blocks */ };
208         WARN_ON(code == PN_PIPE_NO_ERROR);
209         return pep_reply(sk, skb, code, data, sizeof(data), GFP_ATOMIC);
210 }
211
212 /* Control requests are not sent by the pipe service and have a specific
213  * message format. */
214 static int pep_ctrlreq_error(struct sock *sk, struct sk_buff *oskb, u8 code,
215                                 gfp_t priority)
216 {
217         const struct pnpipehdr *oph = pnp_hdr(oskb);
218         struct sk_buff *skb;
219         struct pnpipehdr *ph;
220         struct sockaddr_pn dst;
221         u8 data[4] = {
222                 oph->data[0], /* PEP type */
223                 code, /* error code, at an unusual offset */
224                 PAD, PAD,
225         };
226
227         skb = pep_alloc_skb(sk, data, 4, priority);
228         if (!skb)
229                 return -ENOMEM;
230
231         ph = pnp_hdr(skb);
232         ph->utid = oph->utid;
233         ph->message_id = PNS_PEP_CTRL_RESP;
234         ph->pipe_handle = oph->pipe_handle;
235         ph->data[0] = oph->data[1]; /* CTRL id */
236
237         pn_skb_get_src_sockaddr(oskb, &dst);
238         return pn_skb_send(sk, skb, &dst);
239 }
240
241 static int pipe_snd_status(struct sock *sk, u8 type, u8 status, gfp_t priority)
242 {
243         u8 data[4] = { type, PAD, PAD, status };
244
245         return pep_indicate(sk, PNS_PEP_STATUS_IND, PN_PEP_TYPE_COMMON,
246                                 data, 4, priority);
247 }
248
249 /* Send our RX flow control information to the sender.
250  * Socket must be locked. */
251 static void pipe_grant_credits(struct sock *sk, gfp_t priority)
252 {
253         struct pep_sock *pn = pep_sk(sk);
254
255         BUG_ON(sk->sk_state != TCP_ESTABLISHED);
256
257         switch (pn->rx_fc) {
258         case PN_LEGACY_FLOW_CONTROL: /* TODO */
259                 break;
260         case PN_ONE_CREDIT_FLOW_CONTROL:
261                 if (pipe_snd_status(sk, PN_PEP_IND_FLOW_CONTROL,
262                                         PEP_IND_READY, priority) == 0)
263                         pn->rx_credits = 1;
264                 break;
265         case PN_MULTI_CREDIT_FLOW_CONTROL:
266                 if ((pn->rx_credits + CREDITS_THR) > CREDITS_MAX)
267                         break;
268                 if (pipe_snd_status(sk, PN_PEP_IND_ID_MCFC_GRANT_CREDITS,
269                                         CREDITS_MAX - pn->rx_credits,
270                                         priority) == 0)
271                         pn->rx_credits = CREDITS_MAX;
272                 break;
273         }
274 }
275
276 static int pipe_rcv_status(struct sock *sk, struct sk_buff *skb)
277 {
278         struct pep_sock *pn = pep_sk(sk);
279         struct pnpipehdr *hdr;
280         int wake = 0;
281
282         if (!pskb_may_pull(skb, sizeof(*hdr) + 4))
283                 return -EINVAL;
284
285         hdr = pnp_hdr(skb);
286         if (hdr->data[0] != PN_PEP_TYPE_COMMON) {
287                 LIMIT_NETDEBUG(KERN_DEBUG"Phonet unknown PEP type: %u\n",
288                                 (unsigned)hdr->data[0]);
289                 return -EOPNOTSUPP;
290         }
291
292         switch (hdr->data[1]) {
293         case PN_PEP_IND_FLOW_CONTROL:
294                 switch (pn->tx_fc) {
295                 case PN_LEGACY_FLOW_CONTROL:
296                         switch (hdr->data[4]) {
297                         case PEP_IND_BUSY:
298                                 atomic_set(&pn->tx_credits, 0);
299                                 break;
300                         case PEP_IND_READY:
301                                 atomic_set(&pn->tx_credits, wake = 1);
302                                 break;
303                         }
304                         break;
305                 case PN_ONE_CREDIT_FLOW_CONTROL:
306                         if (hdr->data[4] == PEP_IND_READY)
307                                 atomic_set(&pn->tx_credits, wake = 1);
308                         break;
309                 }
310                 break;
311
312         case PN_PEP_IND_ID_MCFC_GRANT_CREDITS:
313                 if (pn->tx_fc != PN_MULTI_CREDIT_FLOW_CONTROL)
314                         break;
315                 atomic_add(wake = hdr->data[4], &pn->tx_credits);
316                 break;
317
318         default:
319                 LIMIT_NETDEBUG(KERN_DEBUG"Phonet unknown PEP indication: %u\n",
320                                 (unsigned)hdr->data[1]);
321                 return -EOPNOTSUPP;
322         }
323         if (wake)
324                 sk->sk_write_space(sk);
325         return 0;
326 }
327
328 static int pipe_rcv_created(struct sock *sk, struct sk_buff *skb)
329 {
330         struct pep_sock *pn = pep_sk(sk);
331         struct pnpipehdr *hdr = pnp_hdr(skb);
332         u8 n_sb = hdr->data[0];
333
334         pn->rx_fc = pn->tx_fc = PN_LEGACY_FLOW_CONTROL;
335         __skb_pull(skb, sizeof(*hdr));
336         while (n_sb > 0) {
337                 u8 type, buf[2], len = sizeof(buf);
338                 u8 *data = pep_get_sb(skb, &type, &len, buf);
339
340                 if (data == NULL)
341                         return -EINVAL;
342                 switch (type) {
343                 case PN_PIPE_SB_NEGOTIATED_FC:
344                         if (len < 2 || (data[0] | data[1]) > 3)
345                                 break;
346                         pn->tx_fc = data[0] & 3;
347                         pn->rx_fc = data[1] & 3;
348                         break;
349                 }
350                 n_sb--;
351         }
352         return 0;
353 }
354
355 /* Queue an skb to a connected sock.
356  * Socket lock must be held. */
357 static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
358 {
359         struct pep_sock *pn = pep_sk(sk);
360         struct pnpipehdr *hdr = pnp_hdr(skb);
361         struct sk_buff_head *queue;
362         int err = 0;
363
364         BUG_ON(sk->sk_state == TCP_CLOSE_WAIT);
365
366         switch (hdr->message_id) {
367         case PNS_PEP_CONNECT_REQ:
368                 pep_reject_conn(sk, skb, PN_PIPE_ERR_PEP_IN_USE);
369                 break;
370
371         case PNS_PEP_DISCONNECT_REQ:
372                 pep_reply(sk, skb, PN_PIPE_NO_ERROR, NULL, 0, GFP_ATOMIC);
373                 sk->sk_state = TCP_CLOSE_WAIT;
374                 if (!sock_flag(sk, SOCK_DEAD))
375                         sk->sk_state_change(sk);
376                 break;
377
378 #ifdef CONFIG_PHONET_PIPECTRLR
379         case PNS_PEP_DISCONNECT_RESP:
380                 sk->sk_state = TCP_CLOSE;
381                 break;
382 #endif
383
384         case PNS_PEP_ENABLE_REQ:
385                 /* Wait for PNS_PIPE_(ENABLED|REDIRECTED)_IND */
386                 pep_reply(sk, skb, PN_PIPE_NO_ERROR, NULL, 0, GFP_ATOMIC);
387                 break;
388
389 #ifdef CONFIG_PHONET_PIPECTRLR
390         case PNS_PEP_ENABLE_RESP:
391                 pipe_handler_send_ind(sk, PNS_PIPE_ENABLED_IND);
392
393                 if (!pn_flow_safe(pn->tx_fc)) {
394                         atomic_set(&pn->tx_credits, 1);
395                         sk->sk_write_space(sk);
396                 }
397                 if (sk->sk_state == TCP_ESTABLISHED)
398                         break; /* Nothing to do */
399                 sk->sk_state = TCP_ESTABLISHED;
400                 pipe_grant_credits(sk, GFP_ATOMIC);
401                 break;
402 #endif
403
404         case PNS_PEP_RESET_REQ:
405                 switch (hdr->state_after_reset) {
406                 case PN_PIPE_DISABLE:
407                         pn->init_enable = 0;
408                         break;
409                 case PN_PIPE_ENABLE:
410                         pn->init_enable = 1;
411                         break;
412                 default: /* not allowed to send an error here!? */
413                         err = -EINVAL;
414                         goto out;
415                 }
416                 /* fall through */
417         case PNS_PEP_DISABLE_REQ:
418                 atomic_set(&pn->tx_credits, 0);
419                 pep_reply(sk, skb, PN_PIPE_NO_ERROR, NULL, 0, GFP_ATOMIC);
420                 break;
421
422 #ifdef CONFIG_PHONET_PIPECTRLR
423         case PNS_PEP_DISABLE_RESP:
424                 atomic_set(&pn->tx_credits, 0);
425                 pipe_handler_send_ind(sk, PNS_PIPE_DISABLED_IND);
426                 sk->sk_state = TCP_SYN_RECV;
427                 pn->rx_credits = 0;
428                 break;
429 #endif
430
431         case PNS_PEP_CTRL_REQ:
432                 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
433                         atomic_inc(&sk->sk_drops);
434                         break;
435                 }
436                 __skb_pull(skb, 4);
437                 queue = &pn->ctrlreq_queue;
438                 goto queue;
439
440         case PNS_PIPE_ALIGNED_DATA:
441                 __skb_pull(skb, 1);
442                 /* fall through */
443         case PNS_PIPE_DATA:
444                 __skb_pull(skb, 3); /* Pipe data header */
445                 if (!pn_flow_safe(pn->rx_fc)) {
446                         err = sock_queue_rcv_skb(sk, skb);
447                         if (!err)
448                                 return NET_RX_SUCCESS;
449                         err = -ENOBUFS;
450                         break;
451                 }
452
453                 if (pn->rx_credits == 0) {
454                         atomic_inc(&sk->sk_drops);
455                         err = -ENOBUFS;
456                         break;
457                 }
458                 pn->rx_credits--;
459                 queue = &sk->sk_receive_queue;
460                 goto queue;
461
462         case PNS_PEP_STATUS_IND:
463                 pipe_rcv_status(sk, skb);
464                 break;
465
466         case PNS_PIPE_REDIRECTED_IND:
467                 err = pipe_rcv_created(sk, skb);
468                 break;
469
470         case PNS_PIPE_CREATED_IND:
471                 err = pipe_rcv_created(sk, skb);
472                 if (err)
473                         break;
474                 /* fall through */
475         case PNS_PIPE_RESET_IND:
476                 if (!pn->init_enable)
477                         break;
478                 /* fall through */
479         case PNS_PIPE_ENABLED_IND:
480                 if (!pn_flow_safe(pn->tx_fc)) {
481                         atomic_set(&pn->tx_credits, 1);
482                         sk->sk_write_space(sk);
483                 }
484                 if (sk->sk_state == TCP_ESTABLISHED)
485                         break; /* Nothing to do */
486                 sk->sk_state = TCP_ESTABLISHED;
487                 pipe_grant_credits(sk, GFP_ATOMIC);
488                 break;
489
490         case PNS_PIPE_DISABLED_IND:
491                 sk->sk_state = TCP_SYN_RECV;
492                 pn->rx_credits = 0;
493                 break;
494
495         default:
496                 LIMIT_NETDEBUG(KERN_DEBUG"Phonet unknown PEP message: %u\n",
497                                 hdr->message_id);
498                 err = -EINVAL;
499         }
500 out:
501         kfree_skb(skb);
502         return (err == -ENOBUFS) ? NET_RX_DROP : NET_RX_SUCCESS;
503
504 queue:
505         skb->dev = NULL;
506         skb_set_owner_r(skb, sk);
507         err = skb->len;
508         skb_queue_tail(queue, skb);
509         if (!sock_flag(sk, SOCK_DEAD))
510                 sk->sk_data_ready(sk, err);
511         return NET_RX_SUCCESS;
512 }
513
514 /* Destroy connected sock. */
515 static void pipe_destruct(struct sock *sk)
516 {
517         struct pep_sock *pn = pep_sk(sk);
518
519         skb_queue_purge(&sk->sk_receive_queue);
520         skb_queue_purge(&pn->ctrlreq_queue);
521 }
522
523 #ifdef CONFIG_PHONET_PIPECTRLR
524 static u8 pipe_negotiate_fc(const u8 *fcs, unsigned n)
525 {
526         unsigned i;
527         u8 final_fc = PN_NO_FLOW_CONTROL;
528
529         for (i = 0; i < n; i++) {
530                 u8 fc = fcs[i];
531
532                 if (fc > final_fc && fc < PN_MAX_FLOW_CONTROL)
533                         final_fc = fc;
534         }
535         return final_fc;
536 }
537
538 static int pep_connresp_rcv(struct sock *sk, struct sk_buff *skb)
539 {
540         struct pep_sock *pn = pep_sk(sk);
541         struct pnpipehdr *hdr;
542         u8 n_sb;
543
544         if (!pskb_pull(skb, sizeof(*hdr) + 4))
545                 return -EINVAL;
546
547         hdr = pnp_hdr(skb);
548
549         /* Parse sub-blocks */
550         n_sb = hdr->data[4];
551         while (n_sb > 0) {
552                 u8 type, buf[6], len = sizeof(buf);
553                 const u8 *data = pep_get_sb(skb, &type, &len, buf);
554
555                 if (data == NULL)
556                         return -EINVAL;
557
558                 switch (type) {
559                 case PN_PIPE_SB_REQUIRED_FC_TX:
560                         if (len < 2 || len < data[0])
561                                 break;
562                         pn->tx_fc = pipe_negotiate_fc(data + 2, len - 2);
563                         break;
564
565                 case PN_PIPE_SB_PREFERRED_FC_RX:
566                         if (len < 2 || len < data[0])
567                                 break;
568                         pn->rx_fc = pipe_negotiate_fc(data + 2, len - 2);
569                         break;
570
571                 }
572                 n_sb--;
573         }
574
575         sk->sk_state = TCP_SYN_RECV;
576         sk->sk_backlog_rcv = pipe_do_rcv;
577         sk->sk_destruct = pipe_destruct;
578         pn->rx_credits = 0;
579         sk->sk_state_change(sk);
580
581         return pipe_handler_send_created_ind(sk);
582 }
583 #endif
584
585 static int pep_connreq_rcv(struct sock *sk, struct sk_buff *skb)
586 {
587         struct sock *newsk;
588         struct pep_sock *newpn, *pn = pep_sk(sk);
589         struct pnpipehdr *hdr;
590         struct sockaddr_pn dst, src;
591         u16 peer_type;
592         u8 pipe_handle, enabled, n_sb;
593         u8 aligned = 0;
594
595         if (!pskb_pull(skb, sizeof(*hdr) + 4))
596                 return -EINVAL;
597
598         hdr = pnp_hdr(skb);
599         pipe_handle = hdr->pipe_handle;
600         switch (hdr->state_after_connect) {
601         case PN_PIPE_DISABLE:
602                 enabled = 0;
603                 break;
604         case PN_PIPE_ENABLE:
605                 enabled = 1;
606                 break;
607         default:
608                 pep_reject_conn(sk, skb, PN_PIPE_ERR_INVALID_PARAM);
609                 return -EINVAL;
610         }
611         peer_type = hdr->other_pep_type << 8;
612
613         /* Parse sub-blocks (options) */
614         n_sb = hdr->data[4];
615         while (n_sb > 0) {
616                 u8 type, buf[1], len = sizeof(buf);
617                 const u8 *data = pep_get_sb(skb, &type, &len, buf);
618
619                 if (data == NULL)
620                         return -EINVAL;
621                 switch (type) {
622                 case PN_PIPE_SB_CONNECT_REQ_PEP_SUB_TYPE:
623                         if (len < 1)
624                                 return -EINVAL;
625                         peer_type = (peer_type & 0xff00) | data[0];
626                         break;
627                 case PN_PIPE_SB_ALIGNED_DATA:
628                         aligned = data[0] != 0;
629                         break;
630                 }
631                 n_sb--;
632         }
633
634         skb = skb_clone(skb, GFP_ATOMIC);
635         if (!skb)
636                 return -ENOMEM;
637
638         /* Create a new to-be-accepted sock */
639         newsk = sk_alloc(sock_net(sk), PF_PHONET, GFP_ATOMIC, sk->sk_prot);
640         if (!newsk) {
641                 kfree_skb(skb);
642                 return -ENOMEM;
643         }
644         sock_init_data(NULL, newsk);
645         newsk->sk_state = TCP_SYN_RECV;
646         newsk->sk_backlog_rcv = pipe_do_rcv;
647         newsk->sk_protocol = sk->sk_protocol;
648         newsk->sk_destruct = pipe_destruct;
649
650         newpn = pep_sk(newsk);
651         pn_skb_get_dst_sockaddr(skb, &dst);
652         pn_skb_get_src_sockaddr(skb, &src);
653         newpn->pn_sk.sobject = pn_sockaddr_get_object(&dst);
654         newpn->pn_sk.dobject = pn_sockaddr_get_object(&src);
655         newpn->pn_sk.resource = pn_sockaddr_get_resource(&dst);
656         skb_queue_head_init(&newpn->ctrlreq_queue);
657         newpn->pipe_handle = pipe_handle;
658         atomic_set(&newpn->tx_credits, 0);
659         newpn->peer_type = peer_type;
660         newpn->rx_credits = 0;
661         newpn->rx_fc = newpn->tx_fc = PN_LEGACY_FLOW_CONTROL;
662         newpn->init_enable = enabled;
663         newpn->aligned = aligned;
664
665         BUG_ON(!skb_queue_empty(&newsk->sk_receive_queue));
666         skb_queue_head(&newsk->sk_receive_queue, skb);
667         if (!sock_flag(sk, SOCK_DEAD))
668                 sk->sk_data_ready(sk, 0);
669
670         sk_acceptq_added(sk);
671         sk_add_node(newsk, &pn->ackq);
672         return 0;
673 }
674
675 /* Listening sock must be locked */
676 static struct sock *pep_find_pipe(const struct hlist_head *hlist,
677                                         const struct sockaddr_pn *dst,
678                                         u8 pipe_handle)
679 {
680         struct hlist_node *node;
681         struct sock *sknode;
682         u16 dobj = pn_sockaddr_get_object(dst);
683
684         sk_for_each(sknode, node, hlist) {
685                 struct pep_sock *pnnode = pep_sk(sknode);
686
687                 /* Ports match, but addresses might not: */
688                 if (pnnode->pn_sk.sobject != dobj)
689                         continue;
690                 if (pnnode->pipe_handle != pipe_handle)
691                         continue;
692                 if (sknode->sk_state == TCP_CLOSE_WAIT)
693                         continue;
694
695                 sock_hold(sknode);
696                 return sknode;
697         }
698         return NULL;
699 }
700
701 /*
702  * Deliver an skb to a listening sock.
703  * Socket lock must be held.
704  * We then queue the skb to the right connected sock (if any).
705  */
706 static int pep_do_rcv(struct sock *sk, struct sk_buff *skb)
707 {
708         struct pep_sock *pn = pep_sk(sk);
709         struct sock *sknode;
710         struct pnpipehdr *hdr;
711         struct sockaddr_pn dst;
712         u8 pipe_handle;
713
714         if (!pskb_may_pull(skb, sizeof(*hdr)))
715                 goto drop;
716
717         hdr = pnp_hdr(skb);
718         pipe_handle = hdr->pipe_handle;
719         if (pipe_handle == PN_PIPE_INVALID_HANDLE)
720                 goto drop;
721
722         pn_skb_get_dst_sockaddr(skb, &dst);
723
724         /* Look for an existing pipe handle */
725         sknode = pep_find_pipe(&pn->hlist, &dst, pipe_handle);
726         if (sknode)
727                 return sk_receive_skb(sknode, skb, 1);
728
729         /* Look for a pipe handle pending accept */
730         sknode = pep_find_pipe(&pn->ackq, &dst, pipe_handle);
731         if (sknode) {
732                 sock_put(sknode);
733                 if (net_ratelimit())
734                         printk(KERN_WARNING"Phonet unconnected PEP ignored");
735                 goto drop;
736         }
737
738         switch (hdr->message_id) {
739         case PNS_PEP_CONNECT_REQ:
740                 if (sk->sk_state == TCP_LISTEN && !sk_acceptq_is_full(sk))
741                         pep_connreq_rcv(sk, skb);
742                 else
743                         pep_reject_conn(sk, skb, PN_PIPE_ERR_PEP_IN_USE);
744                 break;
745
746 #ifdef CONFIG_PHONET_PIPECTRLR
747         case PNS_PEP_CONNECT_RESP:
748                 pep_connresp_rcv(sk, skb);
749                 break;
750 #endif
751
752         case PNS_PEP_DISCONNECT_REQ:
753                 pep_reply(sk, skb, PN_PIPE_NO_ERROR, NULL, 0, GFP_ATOMIC);
754                 break;
755
756         case PNS_PEP_CTRL_REQ:
757                 pep_ctrlreq_error(sk, skb, PN_PIPE_INVALID_HANDLE, GFP_ATOMIC);
758                 break;
759
760         case PNS_PEP_RESET_REQ:
761         case PNS_PEP_ENABLE_REQ:
762         case PNS_PEP_DISABLE_REQ:
763                 /* invalid handle is not even allowed here! */
764         default:
765                 break;
766         }
767 drop:
768         kfree_skb(skb);
769         return NET_RX_SUCCESS;
770 }
771
772 #ifndef CONFIG_PHONET_PIPECTRLR
773 static int pipe_do_remove(struct sock *sk)
774 {
775         struct pep_sock *pn = pep_sk(sk);
776         struct pnpipehdr *ph;
777         struct sk_buff *skb;
778
779         skb = pep_alloc_skb(sk, NULL, 0, GFP_KERNEL);
780         if (!skb)
781                 return -ENOMEM;
782
783         ph = pnp_hdr(skb);
784         ph->utid = 0;
785         ph->message_id = PNS_PIPE_REMOVE_REQ;
786         ph->pipe_handle = pn->pipe_handle;
787         ph->data[0] = PAD;
788         return pn_skb_send(sk, skb, NULL);
789 }
790 #endif
791
792 /* associated socket ceases to exist */
793 static void pep_sock_close(struct sock *sk, long timeout)
794 {
795         struct pep_sock *pn = pep_sk(sk);
796         int ifindex = 0;
797
798         sock_hold(sk); /* keep a reference after sk_common_release() */
799         sk_common_release(sk);
800
801         lock_sock(sk);
802         if (sk->sk_state == TCP_LISTEN) {
803                 /* Destroy the listen queue */
804                 struct sock *sknode;
805                 struct hlist_node *p, *n;
806
807                 sk_for_each_safe(sknode, p, n, &pn->ackq)
808                         sk_del_node_init(sknode);
809                 sk->sk_state = TCP_CLOSE;
810         } else if ((1 << sk->sk_state) & (TCPF_SYN_RECV|TCPF_ESTABLISHED)) {
811 #ifndef CONFIG_PHONET_PIPECTRLR
812                 /* Forcefully remove dangling Phonet pipe */
813                 pipe_do_remove(sk);
814 #else
815                 /* send pep disconnect request */
816                 pipe_handler_request(sk, PNS_PEP_DISCONNECT_REQ, PAD, NULL, 0);
817                 sk->sk_state = TCP_CLOSE;
818 #endif
819         }
820
821         ifindex = pn->ifindex;
822         pn->ifindex = 0;
823         release_sock(sk);
824
825         if (ifindex)
826                 gprs_detach(sk);
827         sock_put(sk);
828 }
829
830 static int pep_wait_connreq(struct sock *sk, int noblock)
831 {
832         struct task_struct *tsk = current;
833         struct pep_sock *pn = pep_sk(sk);
834         long timeo = sock_rcvtimeo(sk, noblock);
835
836         for (;;) {
837                 DEFINE_WAIT(wait);
838
839                 if (sk->sk_state != TCP_LISTEN)
840                         return -EINVAL;
841                 if (!hlist_empty(&pn->ackq))
842                         break;
843                 if (!timeo)
844                         return -EWOULDBLOCK;
845                 if (signal_pending(tsk))
846                         return sock_intr_errno(timeo);
847
848                 prepare_to_wait_exclusive(sk_sleep(sk), &wait,
849                                                 TASK_INTERRUPTIBLE);
850                 release_sock(sk);
851                 timeo = schedule_timeout(timeo);
852                 lock_sock(sk);
853                 finish_wait(sk_sleep(sk), &wait);
854         }
855
856         return 0;
857 }
858
859 static struct sock *pep_sock_accept(struct sock *sk, int flags, int *errp)
860 {
861         struct pep_sock *pn = pep_sk(sk);
862         struct sock *newsk = NULL;
863         struct sk_buff *oskb;
864         int err;
865
866         lock_sock(sk);
867         err = pep_wait_connreq(sk, flags & O_NONBLOCK);
868         if (err)
869                 goto out;
870
871         newsk = __sk_head(&pn->ackq);
872
873         oskb = skb_dequeue(&newsk->sk_receive_queue);
874         err = pep_accept_conn(newsk, oskb);
875         if (err) {
876                 skb_queue_head(&newsk->sk_receive_queue, oskb);
877                 newsk = NULL;
878                 goto out;
879         }
880         kfree_skb(oskb);
881
882         sock_hold(sk);
883         pep_sk(newsk)->listener = sk;
884
885         sock_hold(newsk);
886         sk_del_node_init(newsk);
887         sk_acceptq_removed(sk);
888         sk_add_node(newsk, &pn->hlist);
889         __sock_put(newsk);
890
891 out:
892         release_sock(sk);
893         *errp = err;
894         return newsk;
895 }
896
897 #ifdef CONFIG_PHONET_PIPECTRLR
898 static int pep_sock_connect(struct sock *sk, struct sockaddr *addr, int len)
899 {
900         struct pep_sock *pn = pep_sk(sk);
901         const struct sockaddr_pn *spn = (struct sockaddr_pn *)addr;
902         u8 data[4] = { 0 /* sub-blocks */, PAD, PAD, PAD };
903
904         pn->pn_sk.dobject = pn_sockaddr_get_object(spn);
905         pn->pn_sk.resource = pn_sockaddr_get_resource(spn);
906         return pipe_handler_request(sk, PNS_PEP_CONNECT_REQ,
907                                         PN_PIPE_DISABLE, data, 4);
908 }
909 #endif
910
911 static int pep_ioctl(struct sock *sk, int cmd, unsigned long arg)
912 {
913         struct pep_sock *pn = pep_sk(sk);
914         int answ;
915
916         switch (cmd) {
917         case SIOCINQ:
918                 if (sk->sk_state == TCP_LISTEN)
919                         return -EINVAL;
920
921                 lock_sock(sk);
922                 if (sock_flag(sk, SOCK_URGINLINE) &&
923                     !skb_queue_empty(&pn->ctrlreq_queue))
924                         answ = skb_peek(&pn->ctrlreq_queue)->len;
925                 else if (!skb_queue_empty(&sk->sk_receive_queue))
926                         answ = skb_peek(&sk->sk_receive_queue)->len;
927                 else
928                         answ = 0;
929                 release_sock(sk);
930                 return put_user(answ, (int __user *)arg);
931         }
932
933         return -ENOIOCTLCMD;
934 }
935
936 static int pep_init(struct sock *sk)
937 {
938         struct pep_sock *pn = pep_sk(sk);
939
940         INIT_HLIST_HEAD(&pn->ackq);
941         INIT_HLIST_HEAD(&pn->hlist);
942         skb_queue_head_init(&pn->ctrlreq_queue);
943         pn->pipe_handle = PN_PIPE_INVALID_HANDLE;
944         return 0;
945 }
946
947 static int pep_setsockopt(struct sock *sk, int level, int optname,
948                                 char __user *optval, unsigned int optlen)
949 {
950         struct pep_sock *pn = pep_sk(sk);
951         int val = 0, err = 0;
952
953         if (level != SOL_PNPIPE)
954                 return -ENOPROTOOPT;
955         if (optlen >= sizeof(int)) {
956                 if (get_user(val, (int __user *) optval))
957                         return -EFAULT;
958         }
959
960         lock_sock(sk);
961         switch (optname) {
962 #ifdef CONFIG_PHONET_PIPECTRLR
963         case PNPIPE_PIPE_HANDLE:
964                 if (val) {
965                         pn->pipe_handle = val;
966                         break;
967                 }
968 #endif
969
970         case PNPIPE_ENCAP:
971                 if (val && val != PNPIPE_ENCAP_IP) {
972                         err = -EINVAL;
973                         break;
974                 }
975                 if (!pn->ifindex == !val)
976                         break; /* Nothing to do! */
977                 if (!capable(CAP_NET_ADMIN)) {
978                         err = -EPERM;
979                         break;
980                 }
981                 if (val) {
982                         release_sock(sk);
983                         err = gprs_attach(sk);
984                         if (err > 0) {
985                                 pn->ifindex = err;
986                                 err = 0;
987                         }
988                 } else {
989                         pn->ifindex = 0;
990                         release_sock(sk);
991                         gprs_detach(sk);
992                         err = 0;
993                 }
994                 goto out_norel;
995
996 #ifdef CONFIG_PHONET_PIPECTRLR
997         case PNPIPE_ENABLE:
998                 if ((1 << sk->sk_state) & ~(TCPF_SYN_RECV|TCPF_ESTABLISHED)) {
999                         err = -ENOTCONN;
1000                         break;
1001                 }
1002                 err = pipe_handler_enable_pipe(sk, val);
1003                 break;
1004 #endif
1005
1006         default:
1007                 err = -ENOPROTOOPT;
1008         }
1009         release_sock(sk);
1010
1011 out_norel:
1012         return err;
1013 }
1014
1015 static int pep_getsockopt(struct sock *sk, int level, int optname,
1016                                 char __user *optval, int __user *optlen)
1017 {
1018         struct pep_sock *pn = pep_sk(sk);
1019         int len, val;
1020
1021         if (level != SOL_PNPIPE)
1022                 return -ENOPROTOOPT;
1023         if (get_user(len, optlen))
1024                 return -EFAULT;
1025
1026         switch (optname) {
1027         case PNPIPE_ENCAP:
1028                 val = pn->ifindex ? PNPIPE_ENCAP_IP : PNPIPE_ENCAP_NONE;
1029                 break;
1030
1031         case PNPIPE_IFINDEX:
1032                 val = pn->ifindex;
1033                 break;
1034
1035 #ifdef CONFIG_PHONET_PIPECTRLR
1036         case PNPIPE_ENABLE:
1037                 val = sk->sk_state == TCP_ESTABLISHED;
1038                 break;
1039 #endif
1040
1041         default:
1042                 return -ENOPROTOOPT;
1043         }
1044
1045         len = min_t(unsigned int, sizeof(int), len);
1046         if (put_user(len, optlen))
1047                 return -EFAULT;
1048         if (put_user(val, (int __user *) optval))
1049                 return -EFAULT;
1050         return 0;
1051 }
1052
1053 static int pipe_skb_send(struct sock *sk, struct sk_buff *skb)
1054 {
1055         struct pep_sock *pn = pep_sk(sk);
1056         struct pnpipehdr *ph;
1057         int err;
1058
1059         if (pn_flow_safe(pn->tx_fc) &&
1060             !atomic_add_unless(&pn->tx_credits, -1, 0)) {
1061                 kfree_skb(skb);
1062                 return -ENOBUFS;
1063         }
1064
1065         skb_push(skb, 3 + pn->aligned);
1066         skb_reset_transport_header(skb);
1067         ph = pnp_hdr(skb);
1068         ph->utid = 0;
1069         if (pn->aligned) {
1070                 ph->message_id = PNS_PIPE_ALIGNED_DATA;
1071                 ph->data[0] = 0; /* padding */
1072         } else
1073                 ph->message_id = PNS_PIPE_DATA;
1074         ph->pipe_handle = pn->pipe_handle;
1075         err = pn_skb_send(sk, skb, NULL);
1076
1077         if (err && pn_flow_safe(pn->tx_fc))
1078                 atomic_inc(&pn->tx_credits);
1079         return err;
1080
1081 }
1082
1083 static int pep_sendmsg(struct kiocb *iocb, struct sock *sk,
1084                         struct msghdr *msg, size_t len)
1085 {
1086         struct pep_sock *pn = pep_sk(sk);
1087         struct sk_buff *skb;
1088         long timeo;
1089         int flags = msg->msg_flags;
1090         int err, done;
1091
1092         if ((msg->msg_flags & ~(MSG_DONTWAIT|MSG_EOR|MSG_NOSIGNAL|
1093                                 MSG_CMSG_COMPAT)) ||
1094                         !(msg->msg_flags & MSG_EOR))
1095                 return -EOPNOTSUPP;
1096
1097         skb = sock_alloc_send_skb(sk, MAX_PNPIPE_HEADER + len,
1098                                         flags & MSG_DONTWAIT, &err);
1099         if (!skb)
1100                 return err;
1101
1102         skb_reserve(skb, MAX_PHONET_HEADER + 3);
1103         err = memcpy_fromiovec(skb_put(skb, len), msg->msg_iov, len);
1104         if (err < 0)
1105                 goto outfree;
1106
1107         lock_sock(sk);
1108         timeo = sock_sndtimeo(sk, flags & MSG_DONTWAIT);
1109         if ((1 << sk->sk_state) & (TCPF_LISTEN|TCPF_CLOSE)) {
1110                 err = -ENOTCONN;
1111                 goto out;
1112         }
1113         if (sk->sk_state != TCP_ESTABLISHED) {
1114                 /* Wait until the pipe gets to enabled state */
1115 disabled:
1116                 err = sk_stream_wait_connect(sk, &timeo);
1117                 if (err)
1118                         goto out;
1119
1120                 if (sk->sk_state == TCP_CLOSE_WAIT) {
1121                         err = -ECONNRESET;
1122                         goto out;
1123                 }
1124         }
1125         BUG_ON(sk->sk_state != TCP_ESTABLISHED);
1126
1127         /* Wait until flow control allows TX */
1128         done = atomic_read(&pn->tx_credits);
1129         while (!done) {
1130                 DEFINE_WAIT(wait);
1131
1132                 if (!timeo) {
1133                         err = -EAGAIN;
1134                         goto out;
1135                 }
1136                 if (signal_pending(current)) {
1137                         err = sock_intr_errno(timeo);
1138                         goto out;
1139                 }
1140
1141                 prepare_to_wait(sk_sleep(sk), &wait,
1142                                 TASK_INTERRUPTIBLE);
1143                 done = sk_wait_event(sk, &timeo, atomic_read(&pn->tx_credits));
1144                 finish_wait(sk_sleep(sk), &wait);
1145
1146                 if (sk->sk_state != TCP_ESTABLISHED)
1147                         goto disabled;
1148         }
1149
1150         err = pipe_skb_send(sk, skb);
1151         if (err >= 0)
1152                 err = len; /* success! */
1153         skb = NULL;
1154 out:
1155         release_sock(sk);
1156 outfree:
1157         kfree_skb(skb);
1158         return err;
1159 }
1160
1161 int pep_writeable(struct sock *sk)
1162 {
1163         struct pep_sock *pn = pep_sk(sk);
1164
1165         return atomic_read(&pn->tx_credits);
1166 }
1167
1168 int pep_write(struct sock *sk, struct sk_buff *skb)
1169 {
1170         struct sk_buff *rskb, *fs;
1171         int flen = 0;
1172
1173         if (pep_sk(sk)->aligned)
1174                 return pipe_skb_send(sk, skb);
1175
1176         rskb = alloc_skb(MAX_PNPIPE_HEADER, GFP_ATOMIC);
1177         if (!rskb) {
1178                 kfree_skb(skb);
1179                 return -ENOMEM;
1180         }
1181         skb_shinfo(rskb)->frag_list = skb;
1182         rskb->len += skb->len;
1183         rskb->data_len += rskb->len;
1184         rskb->truesize += rskb->len;
1185
1186         /* Avoid nested fragments */
1187         skb_walk_frags(skb, fs)
1188                 flen += fs->len;
1189         skb->next = skb_shinfo(skb)->frag_list;
1190         skb_frag_list_init(skb);
1191         skb->len -= flen;
1192         skb->data_len -= flen;
1193         skb->truesize -= flen;
1194
1195         skb_reserve(rskb, MAX_PHONET_HEADER + 3);
1196         return pipe_skb_send(sk, rskb);
1197 }
1198
1199 struct sk_buff *pep_read(struct sock *sk)
1200 {
1201         struct sk_buff *skb = skb_dequeue(&sk->sk_receive_queue);
1202
1203         if (sk->sk_state == TCP_ESTABLISHED)
1204                 pipe_grant_credits(sk, GFP_ATOMIC);
1205         return skb;
1206 }
1207
1208 static int pep_recvmsg(struct kiocb *iocb, struct sock *sk,
1209                         struct msghdr *msg, size_t len, int noblock,
1210                         int flags, int *addr_len)
1211 {
1212         struct sk_buff *skb;
1213         int err;
1214
1215         if (flags & ~(MSG_OOB|MSG_PEEK|MSG_TRUNC|MSG_DONTWAIT|MSG_WAITALL|
1216                         MSG_NOSIGNAL|MSG_CMSG_COMPAT))
1217                 return -EOPNOTSUPP;
1218
1219         if (unlikely(1 << sk->sk_state & (TCPF_LISTEN | TCPF_CLOSE)))
1220                 return -ENOTCONN;
1221
1222         if ((flags & MSG_OOB) || sock_flag(sk, SOCK_URGINLINE)) {
1223                 /* Dequeue and acknowledge control request */
1224                 struct pep_sock *pn = pep_sk(sk);
1225
1226                 if (flags & MSG_PEEK)
1227                         return -EOPNOTSUPP;
1228                 skb = skb_dequeue(&pn->ctrlreq_queue);
1229                 if (skb) {
1230                         pep_ctrlreq_error(sk, skb, PN_PIPE_NO_ERROR,
1231                                                 GFP_KERNEL);
1232                         msg->msg_flags |= MSG_OOB;
1233                         goto copy;
1234                 }
1235                 if (flags & MSG_OOB)
1236                         return -EINVAL;
1237         }
1238
1239         skb = skb_recv_datagram(sk, flags, noblock, &err);
1240         lock_sock(sk);
1241         if (skb == NULL) {
1242                 if (err == -ENOTCONN && sk->sk_state == TCP_CLOSE_WAIT)
1243                         err = -ECONNRESET;
1244                 release_sock(sk);
1245                 return err;
1246         }
1247
1248         if (sk->sk_state == TCP_ESTABLISHED)
1249                 pipe_grant_credits(sk, GFP_KERNEL);
1250         release_sock(sk);
1251 copy:
1252         msg->msg_flags |= MSG_EOR;
1253         if (skb->len > len)
1254                 msg->msg_flags |= MSG_TRUNC;
1255         else
1256                 len = skb->len;
1257
1258         err = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, len);
1259         if (!err)
1260                 err = (flags & MSG_TRUNC) ? skb->len : len;
1261
1262         skb_free_datagram(sk, skb);
1263         return err;
1264 }
1265
1266 static void pep_sock_unhash(struct sock *sk)
1267 {
1268         struct pep_sock *pn = pep_sk(sk);
1269         struct sock *skparent = NULL;
1270
1271         lock_sock(sk);
1272
1273 #ifndef CONFIG_PHONET_PIPECTRLR
1274         if ((1 << sk->sk_state) & ~(TCPF_CLOSE|TCPF_LISTEN)) {
1275                 skparent = pn->listener;
1276                 release_sock(sk);
1277
1278                 pn = pep_sk(skparent);
1279                 lock_sock(skparent);
1280                 sk_del_node_init(sk);
1281                 sk = skparent;
1282         }
1283 #endif
1284         /* Unhash a listening sock only when it is closed
1285          * and all of its active connected pipes are closed. */
1286         if (hlist_empty(&pn->hlist))
1287                 pn_sock_unhash(&pn->pn_sk.sk);
1288         release_sock(sk);
1289
1290         if (skparent)
1291                 sock_put(skparent);
1292 }
1293
1294 static struct proto pep_proto = {
1295         .close          = pep_sock_close,
1296         .accept         = pep_sock_accept,
1297 #ifdef CONFIG_PHONET_PIPECTRLR
1298         .connect        = pep_sock_connect,
1299 #endif
1300         .ioctl          = pep_ioctl,
1301         .init           = pep_init,
1302         .setsockopt     = pep_setsockopt,
1303         .getsockopt     = pep_getsockopt,
1304         .sendmsg        = pep_sendmsg,
1305         .recvmsg        = pep_recvmsg,
1306         .backlog_rcv    = pep_do_rcv,
1307         .hash           = pn_sock_hash,
1308         .unhash         = pep_sock_unhash,
1309         .get_port       = pn_sock_get_port,
1310         .obj_size       = sizeof(struct pep_sock),
1311         .owner          = THIS_MODULE,
1312         .name           = "PNPIPE",
1313 };
1314
1315 static struct phonet_protocol pep_pn_proto = {
1316         .ops            = &phonet_stream_ops,
1317         .prot           = &pep_proto,
1318         .sock_type      = SOCK_SEQPACKET,
1319 };
1320
1321 static int __init pep_register(void)
1322 {
1323         return phonet_proto_register(PN_PROTO_PIPE, &pep_pn_proto);
1324 }
1325
1326 static void __exit pep_unregister(void)
1327 {
1328         phonet_proto_unregister(PN_PROTO_PIPE, &pep_pn_proto);
1329 }
1330
1331 module_init(pep_register);
1332 module_exit(pep_unregister);
1333 MODULE_AUTHOR("Remi Denis-Courmont, Nokia");
1334 MODULE_DESCRIPTION("Phonet pipe protocol");
1335 MODULE_LICENSE("GPL");
1336 MODULE_ALIAS_NET_PF_PROTO(PF_PHONET, PN_PROTO_PIPE);