da582267f3ef83f58710ccbcd6e10b1be72ecea4
[akaros.git] / kern / src / net / udp.c
1 /* Copyright © 1994-1999 Lucent Technologies Inc.  All rights reserved.
2  * Portions Copyright © 1997-1999 Vita Nuova Limited
3  * Portions Copyright © 2000-2007 Vita Nuova Holdings Limited
4  *                                (www.vitanuova.com)
5  * Revisions Copyright © 2000-2007 Lucent Technologies Inc. and others
6  *
7  * Modified for the Akaros operating system:
8  * Copyright (c) 2013-2014 The Regents of the University of California
9  * Copyright (c) 2013-2015 Google Inc.
10  *
11  * Permission is hereby granted, free of charge, to any person obtaining a copy
12  * of this software and associated documentation files (the "Software"), to deal
13  * in the Software without restriction, including without limitation the rights
14  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15  * copies of the Software, and to permit persons to whom the Software is
16  * furnished to do so, subject to the following conditions:
17  *
18  * The above copyright notice and this permission notice shall be included in
19  * all copies or substantial portions of the Software.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
24  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27  * SOFTWARE. */
28
29 #define DEBUG
30 #include <vfs.h>
31 #include <kfs.h>
32 #include <slab.h>
33 #include <kmalloc.h>
34 #include <kref.h>
35 #include <string.h>
36 #include <stdio.h>
37 #include <assert.h>
38 #include <error.h>
39 #include <cpio.h>
40 #include <pmap.h>
41 #include <smp.h>
42 #include <ip.h>
43
44 #include <vfs.h>
45 #include <kfs.h>
46 #include <slab.h>
47 #include <kmalloc.h>
48 #include <kref.h>
49 #include <string.h>
50 #include <stdio.h>
51 #include <assert.h>
52 #include <error.h>
53 #include <cpio.h>
54 #include <pmap.h>
55 #include <smp.h>
56 #include <ip.h>
57
58 #define DPRINT if(0)print
59
60 enum {
61         UDP_UDPHDR_SZ = 8,
62
63         UDP4_PHDR_OFF = 8,
64         UDP4_PHDR_SZ = 12,
65         UDP4_IPHDR_SZ = 20,
66         UDP6_IPHDR_SZ = 40,
67         UDP6_PHDR_SZ = 40,
68         UDP6_PHDR_OFF = 0,
69
70         IP_UDPPROTO = 17,
71         UDP_USEAD7 = 52,
72         UDP_USEAD6 = 36,
73
74         Udprxms = 200,
75         Udptickms = 100,
76         Udpmaxxmit = 10,
77 };
78
79 typedef struct Udp4hdr Udp4hdr;
80 struct Udp4hdr {
81         /* ip header */
82         uint8_t vihl;                           /* Version and header length */
83         uint8_t tos;                            /* Type of service */
84         uint8_t length[2];                      /* packet length */
85         uint8_t id[2];                          /* Identification */
86         uint8_t frag[2];                        /* Fragment information */
87         uint8_t Unused;
88         uint8_t udpproto;                       /* Protocol */
89         uint8_t udpplen[2];                     /* Header plus data length */
90         uint8_t udpsrc[IPv4addrlen];    /* Ip source */
91         uint8_t udpdst[IPv4addrlen];    /* Ip destination */
92
93         /* udp header */
94         uint8_t udpsport[2];            /* Source port */
95         uint8_t udpdport[2];            /* Destination port */
96         uint8_t udplen[2];                      /* data length */
97         uint8_t udpcksum[2];            /* Checksum */
98 };
99
100 typedef struct Udp6hdr Udp6hdr;
101 struct Udp6hdr {
102         uint8_t viclfl[4];
103         uint8_t len[2];
104         uint8_t nextheader;
105         uint8_t hoplimit;
106         uint8_t udpsrc[IPaddrlen];
107         uint8_t udpdst[IPaddrlen];
108
109         /* udp header */
110         uint8_t udpsport[2];            /* Source port */
111         uint8_t udpdport[2];            /* Destination port */
112         uint8_t udplen[2];                      /* data length */
113         uint8_t udpcksum[2];            /* Checksum */
114 };
115
116 /* MIB II counters */
117 typedef struct Udpstats Udpstats;
118 struct Udpstats {
119         uint32_t udpInDatagrams;
120         uint32_t udpNoPorts;
121         uint32_t udpInErrors;
122         uint32_t udpOutDatagrams;
123 };
124
125 typedef struct Udppriv Udppriv;
126 struct Udppriv {
127         struct Ipht ht;
128
129         /* MIB counters */
130         Udpstats ustats;
131
132         /* non-MIB stats */
133         uint32_t csumerr;                       /* checksum errors */
134         uint32_t lenerr;                        /* short packet */
135 };
136
137 void (*etherprofiler) (char *name, int qlen);
138 void udpkick(void *x, struct block *bp);
139
140 /*
141  *  protocol specific part of Conv
142  */
143 typedef struct Udpcb Udpcb;
144 struct Udpcb {
145         uint8_t headers;
146 };
147
148 static void udpconnect(struct conv *c, char **argv, int argc)
149 {
150         Udppriv *upriv;
151
152         upriv = c->p->priv;
153         Fsstdconnect(c, argv, argc);
154         Fsconnected(c, 0);
155
156         iphtadd(&upriv->ht, c);
157 }
158
159 static void udpbind(struct conv *c, char **argv, int argc)
160 {
161         Udppriv *upriv;
162
163         upriv = c->p->priv;
164         Fsstdbind(c, argv, argc);
165         iphtadd(&upriv->ht, c);
166 }
167
168 static int udpstate(struct conv *c, char *state, int n)
169 {
170         return snprintf(state, n, "%s qin %d qout %d\n",
171                                         c->inuse ? "Open" : "Closed",
172                                         c->rq ? qlen(c->rq) : 0, c->wq ? qlen(c->wq) : 0);
173 }
174
175 static void udpannounce(struct conv *c, char **argv, int argc)
176 {
177         Udppriv *upriv;
178
179         upriv = c->p->priv;
180         Fsstdannounce(c, argv, argc);
181         Fsconnected(c, NULL);
182         iphtadd(&upriv->ht, c);
183 }
184
185 static void udpbypass(struct conv *cv, char **argv, int argc)
186 {
187         Udppriv *upriv = cv->p->priv;
188
189         Fsstdbypass(cv, argv, argc);
190         iphtadd(&upriv->ht, cv);
191 }
192
193 static void udpcreate(struct conv *c)
194 {
195         c->rq = qopen(128 * 1024, Qmsg, 0, 0);
196         c->wq = qbypass(udpkick, c);
197 }
198
199 static void udpclose(struct conv *c)
200 {
201         Udpcb *ucb;
202         Udppriv *upriv;
203
204         upriv = c->p->priv;
205         iphtrem(&upriv->ht, c);
206
207         c->state = 0;
208         qclose(c->rq);
209         qclose(c->wq);
210         qclose(c->eq);
211         ipmove(c->laddr, IPnoaddr);
212         ipmove(c->raddr, IPnoaddr);
213         c->lport = 0;
214         c->rport = 0;
215
216         ucb = (Udpcb *) c->ptcl;
217         ucb->headers = 0;
218
219         qunlock(&c->qlock);
220 }
221
222 void udpkick(void *x, struct block *bp)
223 {
224         struct conv *c = x;
225         Udp4hdr *uh4;
226         Udp6hdr *uh6;
227         uint16_t rport;
228         uint8_t laddr[IPaddrlen], raddr[IPaddrlen];
229         Udpcb *ucb;
230         int dlen, ptcllen;
231         Udppriv *upriv;
232         struct Fs *f;
233         int version;
234         struct conv *rc;
235
236         upriv = c->p->priv;
237         assert(upriv);
238         f = c->p->f;
239
240         netlog(c->p->f, Logudp, "udp: kick\n");
241         if (bp == NULL)
242                 return;
243
244         ucb = (Udpcb *) c->ptcl;
245         switch (ucb->headers) {
246                 case 7:
247                         /* get user specified addresses */
248                         bp = pullupblock(bp, UDP_USEAD7);
249                         if (bp == NULL)
250                                 return;
251                         ipmove(raddr, bp->rp);
252                         bp->rp += IPaddrlen;
253                         ipmove(laddr, bp->rp);
254                         bp->rp += IPaddrlen;
255                         /* pick interface closest to dest */
256                         if (ipforme(f, laddr) != Runi)
257                                 findlocalip(f, laddr, raddr);
258                         bp->rp += IPaddrlen;    /* Ignore ifc address */
259                         rport = nhgets(bp->rp);
260                         bp->rp += 2 + 2;        /* Ignore local port */
261                         break;
262                 case 6:
263                         /* get user specified addresses */
264                         bp = pullupblock(bp, UDP_USEAD6);
265                         if (bp == NULL)
266                                 return;
267                         ipmove(raddr, bp->rp);
268                         bp->rp += IPaddrlen;
269                         ipmove(laddr, bp->rp);
270                         bp->rp += IPaddrlen;
271                         /* pick interface closest to dest */
272                         if (ipforme(f, laddr) != Runi)
273                                 findlocalip(f, laddr, raddr);
274                         rport = nhgets(bp->rp);
275                         bp->rp += 2 + 2;        /* Ignore local port */
276                         break;
277                 default:
278                         rport = 0;
279                         break;
280         }
281
282         if (ucb->headers) {
283                 if (memcmp(laddr, v4prefix, IPv4off) == 0 ||
284                         ipcmp(laddr, IPnoaddr) == 0)
285                         version = V4;
286                 else
287                         version = V6;
288         } else {
289                 if ((memcmp(c->raddr, v4prefix, IPv4off) == 0 &&
290                          memcmp(c->laddr, v4prefix, IPv4off) == 0)
291                         || ipcmp(c->raddr, IPnoaddr) == 0)
292                         version = V4;
293                 else
294                         version = V6;
295         }
296
297         dlen = blocklen(bp);
298
299         /* fill in pseudo header and compute checksum */
300         switch (version) {
301                 case V4:
302                         bp = padblock(bp, UDP4_IPHDR_SZ + UDP_UDPHDR_SZ);
303                         if (bp == NULL)
304                                 return;
305
306                         uh4 = (Udp4hdr *) (bp->rp);
307                         ptcllen = dlen + UDP_UDPHDR_SZ;
308                         uh4->Unused = 0;
309                         uh4->udpproto = IP_UDPPROTO;
310                         uh4->frag[0] = 0;
311                         uh4->frag[1] = 0;
312                         hnputs(uh4->udpplen, ptcllen);
313                         if (ucb->headers) {
314                                 v6tov4(uh4->udpdst, raddr);
315                                 hnputs(uh4->udpdport, rport);
316                                 v6tov4(uh4->udpsrc, laddr);
317                                 rc = NULL;
318                         } else {
319                                 v6tov4(uh4->udpdst, c->raddr);
320                                 hnputs(uh4->udpdport, c->rport);
321                                 if (ipcmp(c->laddr, IPnoaddr) == 0)
322                                         findlocalip(f, c->laddr, c->raddr);
323                                 v6tov4(uh4->udpsrc, c->laddr);
324                                 rc = c;
325                         }
326                         hnputs(uh4->udpsport, c->lport);
327                         hnputs(uh4->udplen, ptcllen);
328                         uh4->udpcksum[0] = 0;
329                         uh4->udpcksum[1] = 0;
330                         hnputs(uh4->udpcksum,
331                                    ~ptclcsum(bp, UDP4_PHDR_OFF, UDP4_PHDR_SZ));
332                         bp->checksum_start = UDP4_IPHDR_SZ;
333                         bp->checksum_offset = uh4->udpcksum - uh4->udpsport;
334                         bp->transport_header_end = UDP4_IPHDR_SZ;
335                         bp->flag |= Budpck;
336                         uh4->vihl = IP_VER4;
337                         ipoput4(f, bp, 0, c->ttl, c->tos, rc);
338                         break;
339
340                 case V6:
341                         bp = padblock(bp, UDP6_IPHDR_SZ + UDP_UDPHDR_SZ);
342                         if (bp == NULL)
343                                 return;
344
345                         // using the v6 ip header to create pseudo header
346                         // first then reset it to the normal ip header
347                         uh6 = (Udp6hdr *) (bp->rp);
348                         memset(uh6, 0, 8);
349                         ptcllen = dlen + UDP_UDPHDR_SZ;
350                         hnputl(uh6->viclfl, ptcllen);
351                         uh6->hoplimit = IP_UDPPROTO;
352                         if (ucb->headers) {
353                                 ipmove(uh6->udpdst, raddr);
354                                 hnputs(uh6->udpdport, rport);
355                                 ipmove(uh6->udpsrc, laddr);
356                                 rc = NULL;
357                         } else {
358                                 ipmove(uh6->udpdst, c->raddr);
359                                 hnputs(uh6->udpdport, c->rport);
360                                 if (ipcmp(c->laddr, IPnoaddr) == 0)
361                                         findlocalip(f, c->laddr, c->raddr);
362                                 ipmove(uh6->udpsrc, c->laddr);
363                                 rc = c;
364                         }
365                         hnputs(uh6->udpsport, c->lport);
366                         hnputs(uh6->udplen, ptcllen);
367                         uh6->udpcksum[0] = 0;
368                         uh6->udpcksum[1] = 0;
369                         hnputs(uh6->udpcksum,
370                                    ptclcsum(bp, UDP6_PHDR_OFF,
371                                                         dlen + UDP_UDPHDR_SZ + UDP6_PHDR_SZ));
372                         memset(uh6, 0, 8);
373                         bp->transport_header_end = UDP6_IPHDR_SZ;
374                         uh6->viclfl[0] = IP_VER6;
375                         hnputs(uh6->len, ptcllen);
376                         uh6->nextheader = IP_UDPPROTO;
377                         ipoput6(f, bp, 0, c->ttl, c->tos, rc);
378                         break;
379
380                 default:
381                         panic("udpkick: version %d", version);
382         }
383         upriv->ustats.udpOutDatagrams++;
384 }
385
386 void udpiput(struct Proto *udp, struct Ipifc *ifc, struct block *bp)
387 {
388         int len;
389         Udp4hdr *uh4;
390         Udp6hdr *uh6;
391         struct conv *c;
392         Udpcb *ucb;
393         uint8_t raddr[IPaddrlen], laddr[IPaddrlen];
394         uint16_t rport, lport;
395         Udppriv *upriv;
396         struct Fs *f;
397         int version;
398         int ottl, oviclfl, olen;
399         uint8_t *p;
400
401         upriv = udp->priv;
402         f = udp->f;
403         upriv->ustats.udpInDatagrams++;
404
405         uh4 = (Udp4hdr *) (bp->rp);
406         version = ((uh4->vihl & 0xF0) == IP_VER6) ? V6 : V4;
407
408         /*
409          * Put back pseudo header for checksum
410          * (remember old values for icmpnoconv())
411          */
412         switch (version) {
413                 case V4:
414                         ottl = uh4->Unused;
415                         uh4->Unused = 0;
416                         len = nhgets(uh4->udplen);
417                         olen = nhgets(uh4->udpplen);
418                         hnputs(uh4->udpplen, len);
419
420                         v4tov6(raddr, uh4->udpsrc);
421                         v4tov6(laddr, uh4->udpdst);
422                         lport = nhgets(uh4->udpdport);
423                         rport = nhgets(uh4->udpsport);
424
425                         if (!(bp->flag & Budpck) &&
426                             (uh4->udpcksum[0] || uh4->udpcksum[1]) &&
427                             ptclcsum(bp, UDP4_PHDR_OFF, len + UDP4_PHDR_SZ)) {
428                                 upriv->ustats.udpInErrors++;
429                                 netlog(f, Logudp, "udp: checksum error %I\n",
430                                        raddr);
431                                 printd("udp: checksum error %I\n", raddr);
432                                 freeblist(bp);
433                                 return;
434                         }
435                         uh4->Unused = ottl;
436                         hnputs(uh4->udpplen, olen);
437                         break;
438                 case V6:
439                         uh6 = (Udp6hdr *) (bp->rp);
440                         len = nhgets(uh6->udplen);
441                         oviclfl = nhgetl(uh6->viclfl);
442                         olen = nhgets(uh6->len);
443                         ottl = uh6->hoplimit;
444                         ipmove(raddr, uh6->udpsrc);
445                         ipmove(laddr, uh6->udpdst);
446                         lport = nhgets(uh6->udpdport);
447                         rport = nhgets(uh6->udpsport);
448                         memset(uh6, 0, 8);
449                         hnputl(uh6->viclfl, len);
450                         uh6->hoplimit = IP_UDPPROTO;
451                         if (ptclcsum(bp, UDP6_PHDR_OFF, len + UDP6_PHDR_SZ)) {
452                                 upriv->ustats.udpInErrors++;
453                                 netlog(f, Logudp, "udp: checksum error %I\n", raddr);
454                                 printd("udp: checksum error %I\n", raddr);
455                                 freeblist(bp);
456                                 return;
457                         }
458                         hnputl(uh6->viclfl, oviclfl);
459                         hnputs(uh6->len, olen);
460                         uh6->nextheader = IP_UDPPROTO;
461                         uh6->hoplimit = ottl;
462                         break;
463                 default:
464                         panic("udpiput: version %d", version);
465                         return; /* to avoid a warning */
466         }
467
468         c = iphtlook(&upriv->ht, raddr, rport, laddr, lport);
469         if (c == NULL) {
470                 /* no converstation found */
471                 upriv->ustats.udpNoPorts++;
472                 netlog(f, Logudp, "udp: no conv %I!%d -> %I!%d\n", raddr, rport,
473                            laddr, lport);
474
475                 switch (version) {
476                         case V4:
477                                 icmpnoconv(f, bp);
478                                 break;
479                         case V6:
480                                 icmphostunr(f, ifc, bp, icmp6_port_unreach, 0);
481                                 break;
482                         default:
483                                 panic("udpiput2: version %d", version);
484                 }
485
486                 freeblist(bp);
487                 return;
488         }
489
490         if (c->state == Bypass) {
491                 bypass_or_drop(c, bp);
492                 return;
493         }
494
495         ucb = (Udpcb *) c->ptcl;
496
497         if (c->state == Announced) {
498                 if (ucb->headers == 0) {
499                         /* create a new conversation */
500                         if (ipforme(f, laddr) != Runi) {
501                                 switch (version) {
502                                         case V4:
503                                                 v4tov6(laddr, ifc->lifc->local);
504                                                 break;
505                                         case V6:
506                                                 ipmove(laddr, ifc->lifc->local);
507                                                 break;
508                                         default:
509                                                 panic("udpiput3: version %d", version);
510                                 }
511                         }
512                         qlock(&udp->qlock);
513                         c = Fsnewcall(c, raddr, rport, laddr, lport, version);
514                         qunlock(&udp->qlock);
515                         if (c == NULL) {
516                                 freeblist(bp);
517                                 return;
518                         }
519                         iphtadd(&upriv->ht, c);
520                         ucb = (Udpcb *) c->ptcl;
521                 }
522         }
523
524         qlock(&c->qlock);
525
526         /*
527          * Trim the packet down to data size
528          */
529         len -= UDP_UDPHDR_SZ;
530         switch (version) {
531                 case V4:
532                         bp = trimblock(bp, UDP4_IPHDR_SZ + UDP_UDPHDR_SZ, len);
533                         break;
534                 case V6:
535                         bp = trimblock(bp, UDP6_IPHDR_SZ + UDP_UDPHDR_SZ, len);
536                         break;
537                 default:
538                         bp = NULL;
539                         panic("udpiput4: version %d", version);
540         }
541         if (bp == NULL) {
542                 qunlock(&c->qlock);
543                 netlog(f, Logudp, "udp: len err %I.%d -> %I.%d\n", raddr, rport,
544                            laddr, lport);
545                 upriv->lenerr++;
546                 return;
547         }
548
549         netlog(f, Logudpmsg, "udp: %I.%d -> %I.%d l %d\n", raddr, rport,
550                    laddr, lport, len);
551
552         switch (ucb->headers) {
553                 case 7:
554                         /* pass the src address */
555                         bp = padblock(bp, UDP_USEAD7);
556                         p = bp->rp;
557                         ipmove(p, raddr);
558                         p += IPaddrlen;
559                         ipmove(p, laddr);
560                         p += IPaddrlen;
561                         ipmove(p, ifc->lifc->local);
562                         p += IPaddrlen;
563                         hnputs(p, rport);
564                         p += 2;
565                         hnputs(p, lport);
566                         break;
567                 case 6:
568                         /* pass the src address */
569                         bp = padblock(bp, UDP_USEAD6);
570                         p = bp->rp;
571                         ipmove(p, raddr);
572                         p += IPaddrlen;
573                         ipmove(p, ipforme(f, laddr) == Runi ? laddr : ifc->lifc->local);
574                         p += IPaddrlen;
575                         hnputs(p, rport);
576                         p += 2;
577                         hnputs(p, lport);
578                         break;
579         }
580
581         if (bp->next)
582                 bp = concatblock(bp);
583
584         if (qfull(c->rq)) {
585                 qunlock(&c->qlock);
586                 netlog(f, Logudp, "udp: qfull %I.%d -> %I.%d\n", raddr, rport,
587                            laddr, lport);
588                 freeblist(bp);
589                 return;
590         }
591
592         qpass(c->rq, bp);
593         qunlock(&c->qlock);
594
595 }
596
597 static void udpctl(struct conv *c, char **f, int n)
598 {
599         Udpcb *ucb = (Udpcb*)c->ptcl;
600
601         if ((n == 1) && strcmp(f[0], "oldheaders") == 0)
602                 ucb->headers = 6;
603         else if ((n == 1) && strcmp(f[0], "headers") == 0)
604                 ucb->headers = 7;
605         else
606                 error(EINVAL, "unknown command to %s", __func__);
607 }
608
609 void udpadvise(struct Proto *udp, struct block *bp, char *msg)
610 {
611         Udp4hdr *h4;
612         Udp6hdr *h6;
613         uint8_t source[IPaddrlen], dest[IPaddrlen];
614         uint16_t psource, pdest;
615         struct conv *s, **p;
616         int version;
617
618         h4 = (Udp4hdr *) (bp->rp);
619         version = ((h4->vihl & 0xF0) == IP_VER6) ? V6 : V4;
620
621         switch (version) {
622                 case V4:
623                         v4tov6(dest, h4->udpdst);
624                         v4tov6(source, h4->udpsrc);
625                         psource = nhgets(h4->udpsport);
626                         pdest = nhgets(h4->udpdport);
627                         break;
628                 case V6:
629                         h6 = (Udp6hdr *) (bp->rp);
630                         ipmove(dest, h6->udpdst);
631                         ipmove(source, h6->udpsrc);
632                         psource = nhgets(h6->udpsport);
633                         pdest = nhgets(h6->udpdport);
634                         break;
635                 default:
636                         panic("udpadvise: version %d", version);
637                         return; /* to avoid a warning */
638         }
639
640         /* Look for a connection */
641         for (p = udp->conv; *p; p++) {
642                 s = *p;
643                 if (s->rport == pdest)
644                         if (s->lport == psource)
645                                 if (ipcmp(s->raddr, dest) == 0)
646                                         if (ipcmp(s->laddr, source) == 0) {
647                                                 if (s->ignoreadvice)
648                                                         break;
649                                                 qlock(&s->qlock);
650                                                 qhangup(s->rq, msg);
651                                                 qhangup(s->wq, msg);
652                                                 qunlock(&s->qlock);
653                                                 freeblist(bp);
654                                                 return;
655                                         }
656         }
657         freeblist(bp);
658 }
659
660 int udpstats(struct Proto *udp, char *buf, int len)
661 {
662         Udppriv *upriv;
663         char *p, *e;
664
665         upriv = udp->priv;
666         p = buf;
667         e = p + len;
668         p = seprintf(p, e, "InDatagrams: %u\n", upriv->ustats.udpInDatagrams);
669         p = seprintf(p, e, "NoPorts: %u\n", upriv->ustats.udpNoPorts);
670         p = seprintf(p, e, "InErrors: %u\n", upriv->ustats.udpInErrors);
671         p = seprintf(p, e, "OutDatagrams: %u\n", upriv->ustats.udpOutDatagrams);
672         return p - buf;
673 }
674
675 void udpinit(struct Fs *fs)
676 {
677         struct Proto *udp;
678
679         udp = kzmalloc(sizeof(struct Proto), 0);
680         udp->priv = kzmalloc(sizeof(Udppriv), 0);
681         udp->name = "udp";
682         udp->connect = udpconnect;
683         udp->bind = udpbind;
684         udp->announce = udpannounce;
685         udp->bypass = udpbypass;
686         udp->ctl = udpctl;
687         udp->state = udpstate;
688         udp->create = udpcreate;
689         udp->close = udpclose;
690         udp->rcv = udpiput;
691         udp->advise = udpadvise;
692         udp->stats = udpstats;
693         udp->ipproto = IP_UDPPROTO;
694         udp->nc = 4096;
695         udp->ptclsize = sizeof(Udpcb);
696
697         Fsproto(fs, udp);
698 }