source: rtems/cpukit/libnetworking/netinet/udp_usrreq.c @ 3274c876

4.104.114.84.95
Last change on this file since 3274c876 was 3274c876, checked in by Joel Sherrill <joel.sherrill@…>, on 04/28/05 at 21:49:50

2005-04-28 Joel Sherrill <joel@…>

  • libnetworking/kern/kern_sysctl.c, libnetworking/libc/inet_ntop.c, libnetworking/net/if_ppp.c, libnetworking/net/pppcompress.c, libnetworking/net/slcompress.c, libnetworking/netinet/ip_output.c, libnetworking/netinet/udp_usrreq.c, libnetworking/nfs/bootp_subr.c, libnetworking/rtems/rtems_select.c, libnetworking/rtems/rtems_showifstat.c, libnetworking/rtems/rtems_showroute.c, libnetworking/rtems/rtems_syscall.c: Fixed type mismatch and uninitialized variable warnings.
  • Property mode set to 100644
File size: 17.2 KB
Line 
1/*
2 * Copyright (c) 1982, 1986, 1988, 1990, 1993, 1995
3 *      The Regents of the University of California.  All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 * 4. Neither the name of the University nor the names of its contributors
14 *    may be used to endorse or promote products derived from this software
15 *    without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 *      @(#)udp_usrreq.c        8.6 (Berkeley) 5/23/95
30 * $FreeBSD: src/sys/netinet/udp_usrreq.c,v 1.170 2004/11/08 14:44:53 phk Exp $
31 */
32
33#include <sys/param.h>
34#include <sys/queue.h>
35#include <sys/systm.h>
36#include <sys/malloc.h>
37#include <sys/mbuf.h>
38#include <sys/protosw.h>
39#include <sys/socket.h>
40#include <sys/socketvar.h>
41#include <sys/errno.h>
42#include <sys/stat.h>
43#include <sys/kernel.h>
44#include <sys/sysctl.h>
45#include <sys/syslog.h>
46
47#include <net/if.h>
48#include <net/route.h>
49
50#include <netinet/in.h>
51#include <netinet/in_systm.h>
52#include <netinet/ip.h>
53#include <netinet/in_pcb.h>
54#include <netinet/in_var.h>
55#include <netinet/ip_var.h>
56#include <netinet/ip_icmp.h>
57#include <netinet/udp.h>
58#include <netinet/udp_var.h>
59
60/*
61 * UDP protocol implementation.
62 * Per RFC 768, August, 1980.
63 */
64#ifndef COMPAT_42
65static int      udpcksum = 1;
66#else
67static int      udpcksum = 0;           /* XXX */
68#endif
69SYSCTL_INT(_net_inet_udp, UDPCTL_CHECKSUM, checksum, CTLFLAG_RW,
70                &udpcksum, 0, "");
71
72static int log_in_vain = 0;
73SYSCTL_INT(_net_inet_udp, OID_AUTO, log_in_vain, CTLFLAG_RW,
74        &log_in_vain, 0, "");
75
76struct  inpcbhead udb;          /* from udp_var.h */
77struct  inpcbinfo udbinfo;
78
79#ifndef UDBHASHSIZE
80#define UDBHASHSIZE 64
81#endif
82
83       struct   udpstat udpstat;        /* from udp_var.h */
84SYSCTL_STRUCT(_net_inet_udp, UDPCTL_STATS, stats, CTLFLAG_RD,
85        &udpstat, udpstat, "");
86
87static struct   sockaddr_in udp_in = { sizeof(udp_in), AF_INET };
88
89static  void udp_detach __P((struct inpcb *));
90static  int udp_output __P((struct inpcb *, struct mbuf *, struct mbuf *,
91                            struct mbuf *));
92static  void udp_notify __P((struct inpcb *, int));
93
94void
95udp_init()
96{
97        LIST_INIT(&udb);
98        udbinfo.listhead = &udb;
99        udbinfo.hashbase = hashinit(UDBHASHSIZE, M_PCB, &udbinfo.hashmask);
100}
101
102void
103udp_input(m, iphlen)
104        register struct mbuf *m;
105        int iphlen;
106{
107        register struct ip *ip;
108        register struct udphdr *uh;
109        register struct inpcb *inp;
110        struct mbuf *opts = 0;
111        int len;
112        struct ip save_ip;
113
114        udpstat.udps_ipackets++;
115
116        /*
117         * Strip IP options, if any; should skip this,
118         * make available to user, and use on returned packets,
119         * but we don't yet have a way to check the checksum
120         * with options still present.
121         */
122        if (iphlen > sizeof (struct ip)) {
123                ip_stripoptions(m, (struct mbuf *)0);
124                iphlen = sizeof(struct ip);
125        }
126
127        /*
128         * Get IP and UDP header together in first mbuf.
129         */
130        ip = mtod(m, struct ip *);
131        if (m->m_len < iphlen + sizeof(struct udphdr)) {
132                if ((m = m_pullup(m, iphlen + sizeof(struct udphdr))) == 0) {
133                        udpstat.udps_hdrops++;
134                        return;
135                }
136                ip = mtod(m, struct ip *);
137        }
138        uh = (struct udphdr *)((caddr_t)ip + iphlen);
139
140        /*
141         * Make mbuf data length reflect UDP length.
142         * If not enough data to reflect UDP length, drop.
143         */
144        len = ntohs((u_short)uh->uh_ulen);
145        if (ip->ip_len != len) {
146                if (len > ip->ip_len || len < sizeof(struct udphdr)) {
147                        udpstat.udps_badlen++;
148                        goto bad;
149                }
150                m_adj(m, len - ip->ip_len);
151                /* ip->ip_len = len; */
152        }
153        /*
154         * Save a copy of the IP header in case we want restore it
155         * for sending an ICMP error message in response.
156         */
157        save_ip = *ip;
158
159        /*
160         * Checksum extended UDP header and data.
161         */
162        if (uh->uh_sum) {
163                ((struct ipovly *)ip)->ih_next = 0;
164                ((struct ipovly *)ip)->ih_prev = 0;
165                ((struct ipovly *)ip)->ih_x1 = 0;
166                ((struct ipovly *)ip)->ih_len = uh->uh_ulen;
167                uh->uh_sum = in_cksum(m, len + sizeof (struct ip));
168                if (uh->uh_sum) {
169                        udpstat.udps_badsum++;
170                        m_freem(m);
171                        return;
172                }
173        }
174
175        if (IN_MULTICAST(ntohl(ip->ip_dst.s_addr)) ||
176            in_broadcast(ip->ip_dst, m->m_pkthdr.rcvif)) {
177                struct inpcb *last;
178                /*
179                 * Deliver a multicast or broadcast datagram to *all* sockets
180                 * for which the local and remote addresses and ports match
181                 * those of the incoming datagram.  This allows more than
182                 * one process to receive multi/broadcasts on the same port.
183                 * (This really ought to be done for unicast datagrams as
184                 * well, but that would cause problems with existing
185                 * applications that open both address-specific sockets and
186                 * a wildcard socket listening to the same port -- they would
187                 * end up receiving duplicates of every unicast datagram.
188                 * Those applications open the multiple sockets to overcome an
189                 * inadequacy of the UDP socket interface, but for backwards
190                 * compatibility we avoid the problem here rather than
191                 * fixing the interface.  Maybe 4.5BSD will remedy this?)
192                 */
193
194                /*
195                 * Construct sockaddr format source address.
196                 */
197                udp_in.sin_port = uh->uh_sport;
198                udp_in.sin_addr = ip->ip_src;
199                m->m_len -= sizeof (struct udpiphdr);
200                m->m_data += sizeof (struct udpiphdr);
201                /*
202                 * Locate pcb(s) for datagram.
203                 * (Algorithm copied from raw_intr().)
204                 */
205                last = NULL;
206                for (inp = udb.lh_first; inp != NULL; inp = inp->inp_list.le_next) {
207                        if (inp->inp_lport != uh->uh_dport)
208                                continue;
209                        if (inp->inp_laddr.s_addr != INADDR_ANY) {
210                                if (inp->inp_laddr.s_addr !=
211                                    ip->ip_dst.s_addr)
212                                        continue;
213                        }
214                        if (inp->inp_faddr.s_addr != INADDR_ANY) {
215                                if (inp->inp_faddr.s_addr !=
216                                    ip->ip_src.s_addr ||
217                                    inp->inp_fport != uh->uh_sport)
218                                        continue;
219                        }
220
221                        if (last != NULL) {
222                                struct mbuf *n;
223
224                                if ((n = m_copy(m, 0, M_COPYALL)) != NULL) {
225                                        if (last->inp_flags & INP_CONTROLOPTS
226                                            || last->inp_socket->so_options & SO_TIMESTAMP)
227                                                ip_savecontrol(last, &opts, ip, n);
228                                        if (sbappendaddr(&last->inp_socket->so_rcv,
229                                                (struct sockaddr *)&udp_in,
230                                                n, opts) == 0) {
231                                                m_freem(n);
232                                                if (opts)
233                                                    m_freem(opts);
234                                                udpstat.udps_fullsock++;
235                                        } else
236                                                sorwakeup(last->inp_socket);
237                                        opts = 0;
238                                }
239                        }
240                        last = inp;
241                        /*
242                         * Don't look for additional matches if this one does
243                         * not have either the SO_REUSEPORT or SO_REUSEADDR
244                         * socket options set.  This heuristic avoids searching
245                         * through all pcbs in the common case of a non-shared
246                         * port.  It * assumes that an application will never
247                         * clear these options after setting them.
248                         */
249                        if (((last->inp_socket->so_options&(SO_REUSEPORT|SO_REUSEADDR)) == 0))
250                                break;
251                }
252
253                if (last == NULL) {
254                        /*
255                         * No matching pcb found; discard datagram.
256                         * (No need to send an ICMP Port Unreachable
257                         * for a broadcast or multicast datgram.)
258                         */
259                        udpstat.udps_noportbcast++;
260                        goto bad;
261                }
262                if (last->inp_flags & INP_CONTROLOPTS
263                    || last->inp_socket->so_options & SO_TIMESTAMP)
264                        ip_savecontrol(last, &opts, ip, m);
265                if (sbappendaddr(&last->inp_socket->so_rcv,
266                     (struct sockaddr *)&udp_in,
267                     m, opts) == 0) {
268                        udpstat.udps_fullsock++;
269                        goto bad;
270                }
271                sorwakeup(last->inp_socket);
272                return;
273        }
274        /*
275         * Locate pcb for datagram.
276         */
277        inp = in_pcblookuphash(&udbinfo, ip->ip_src, uh->uh_sport,
278            ip->ip_dst, uh->uh_dport, 1);
279        if (inp == NULL) {
280                if (log_in_vain) {
281                        char buf[4*sizeof "123"];
282
283                        strcpy(buf, inet_ntoa(ip->ip_dst));
284                        log(LOG_INFO, "Connection attempt to UDP %s:%d"
285                            " from %s:%d\n",
286                                buf, ntohs(uh->uh_dport),
287                                inet_ntoa(ip->ip_src), ntohs(uh->uh_sport));
288                }
289                udpstat.udps_noport++;
290                if (m->m_flags & (M_BCAST | M_MCAST)) {
291                        udpstat.udps_noportbcast++;
292                        goto bad;
293                }
294                *ip = save_ip;
295                icmp_error(m, ICMP_UNREACH, ICMP_UNREACH_PORT, 0, 0);
296                return;
297        }
298
299        /*
300         * Construct sockaddr format source address.
301         * Stuff source address and datagram in user buffer.
302         */
303        udp_in.sin_port = uh->uh_sport;
304        udp_in.sin_addr = ip->ip_src;
305        if (inp->inp_flags & INP_CONTROLOPTS
306            || inp->inp_socket->so_options & SO_TIMESTAMP)
307                ip_savecontrol(inp, &opts, ip, m);
308        iphlen += sizeof(struct udphdr);
309        m->m_len -= iphlen;
310        m->m_pkthdr.len -= iphlen;
311        m->m_data += iphlen;
312        if (sbappendaddr(&inp->inp_socket->so_rcv, (struct sockaddr *)&udp_in,
313            m, opts) == 0) {
314                udpstat.udps_fullsock++;
315                goto bad;
316        }
317        sorwakeup(inp->inp_socket);
318        return;
319bad:
320        m_freem(m);
321        if (opts)
322                m_freem(opts);
323}
324
325/*
326 * Notify a udp user of an asynchronous error;
327 * just wake up so that he can collect error status.
328 */
329static void
330udp_notify(inp, errnum)
331        register struct inpcb *inp;
332        int errnum;
333{
334        inp->inp_socket->so_error = errnum;
335        sorwakeup(inp->inp_socket);
336        sowwakeup(inp->inp_socket);
337}
338
339void
340udp_ctlinput(cmd, sa, vip)
341        int cmd;
342        struct sockaddr *sa;
343        void *vip;
344{
345        register struct ip *ip = vip;
346        register struct udphdr *uh;
347
348        if (!PRC_IS_REDIRECT(cmd) &&
349            ((unsigned)cmd >= PRC_NCMDS || inetctlerrmap[cmd] == 0))
350                return;
351        if (ip) {
352                uh = (struct udphdr *)((caddr_t)ip + (ip->ip_hl << 2));
353                in_pcbnotify(&udb, sa, uh->uh_dport, ip->ip_src, uh->uh_sport,
354                        cmd, udp_notify);
355        } else
356                in_pcbnotify(&udb, sa, 0, zeroin_addr, 0, cmd, udp_notify);
357}
358
359static int
360udp_output(inp, m, addr, control)
361        register struct inpcb *inp;
362        register struct mbuf *m;
363        struct mbuf *addr, *control;
364{
365        register struct udpiphdr *ui;
366        register int len = m->m_pkthdr.len;
367        struct in_addr laddr;
368        int s = 0, error = 0;
369
370        laddr.s_addr = 0;
371        if (control)
372                m_freem(control);               /* XXX */
373
374        if (len + sizeof(struct udpiphdr) > IP_MAXPACKET) {
375                error = EMSGSIZE;
376                goto release;
377        }
378
379        if (addr) {
380                laddr = inp->inp_laddr;
381                if (inp->inp_faddr.s_addr != INADDR_ANY) {
382                        error = EISCONN;
383                        goto release;
384                }
385                /*
386                 * Must block input while temporarily connected.
387                 */
388                s = splnet();
389                error = in_pcbconnect(inp, addr);
390                if (error) {
391                        splx(s);
392                        goto release;
393                }
394        } else {
395                if (inp->inp_faddr.s_addr == INADDR_ANY) {
396                        error = ENOTCONN;
397                        goto release;
398                }
399        }
400        /*
401         * Calculate data length and get a mbuf
402         * for UDP and IP headers.
403         */
404        M_PREPEND(m, sizeof(struct udpiphdr), M_DONTWAIT);
405        if (m == 0) {
406                error = ENOBUFS;
407                if (addr)
408                        splx(s);
409                goto release;
410        }
411
412        /*
413         * Fill in mbuf with extended UDP header
414         * and addresses and length put into network format.
415         */
416        ui = mtod(m, struct udpiphdr *);
417        ui->ui_next = ui->ui_prev = 0;
418        ui->ui_x1 = 0;
419        ui->ui_pr = IPPROTO_UDP;
420        ui->ui_len = htons((u_short)len + sizeof (struct udphdr));
421        ui->ui_src = inp->inp_laddr;
422        ui->ui_dst = inp->inp_faddr;
423        ui->ui_sport = inp->inp_lport;
424        ui->ui_dport = inp->inp_fport;
425        ui->ui_ulen = ui->ui_len;
426
427        /*
428         * Stuff checksum and output datagram.
429         */
430        ui->ui_sum = 0;
431        if (udpcksum) {
432            if ((ui->ui_sum = in_cksum(m, sizeof (struct udpiphdr) + len)) == 0)
433                ui->ui_sum = 0xffff;
434        }
435        ((struct ip *)ui)->ip_len = sizeof (struct udpiphdr) + len;
436        ((struct ip *)ui)->ip_ttl = inp->inp_ip_ttl;    /* XXX */
437        ((struct ip *)ui)->ip_tos = inp->inp_ip_tos;    /* XXX */
438        udpstat.udps_opackets++;
439        error = ip_output(m, inp->inp_options, &inp->inp_route,
440            inp->inp_socket->so_options & (SO_DONTROUTE | SO_BROADCAST),
441            inp->inp_moptions);
442
443        if (addr) {
444                in_pcbdisconnect(inp);
445                inp->inp_laddr = laddr;
446                splx(s);
447        }
448        return (error);
449
450release:
451        m_freem(m);
452        return (error);
453}
454
455#ifdef __rtems__
456#define INP_INFO_RLOCK(a)
457#define INP_INFO_RUNLOCK(a)
458#define INP_LOCK(a)
459#define INP_UNLOCK(a)
460#endif
461
462static int
463udp_pcblist(SYSCTL_HANDLER_ARGS)
464{
465        int error, i, n, s;
466        struct inpcb *inp, **inp_list;
467        inp_gen_t gencnt;
468        struct xinpgen xig;
469
470        /*
471         * The process of preparing the TCB list is too time-consuming and
472         * resource-intensive to repeat twice on every request.
473         */
474        if (req->oldptr == 0) {
475                n = udbinfo.ipi_count;
476                req->oldidx = 2 * (sizeof xig)
477                        + (n + n/8) * sizeof(struct xinpcb);
478                return 0;
479        }
480
481        if (req->newptr != 0)
482                return EPERM;
483
484        /*
485         * OK, now we're committed to doing something.
486         */
487        s = splnet();
488        gencnt = udbinfo.ipi_gencnt;
489        n = udbinfo.ipi_count;
490        splx(s);
491
492        sysctl_wire_old_buffer(req, 2 * (sizeof xig)
493                + n * sizeof(struct xinpcb));
494
495        xig.xig_len = sizeof xig;
496        xig.xig_count = n;
497        xig.xig_gen = gencnt;
498#if 0
499        xig.xig_sogen = so_gencnt;
500#endif
501        error = SYSCTL_OUT(req, &xig, sizeof xig);
502        if (error)
503                return error;
504
505  /* ccj add the exit if count is 0 */
506  if (!n)
507    return error;
508 
509        inp_list = malloc(n * sizeof *inp_list, M_TEMP, M_WAITOK);
510        if (inp_list == 0)
511                return ENOMEM;
512       
513        s = splnet();
514        INP_INFO_RLOCK(&udbinfo);
515        for (inp = LIST_FIRST(udbinfo.listhead), i = 0; inp && i < n;
516             inp = LIST_NEXT(inp, inp_list)) {
517                INP_LOCK(inp);
518                if (inp->inp_gencnt <= gencnt)
519#if 0
520      &&
521                    cr_canseesocket(req->td->td_ucred, inp->inp_socket) == 0)
522#endif
523                        inp_list[i++] = inp;
524                INP_UNLOCK(inp);
525        }
526        INP_INFO_RUNLOCK(&udbinfo);
527        splx(s);
528        n = i;
529
530        error = 0;
531        for (i = 0; i < n; i++) {
532                inp = inp_list[i];
533                INP_LOCK(inp);
534                if (inp->inp_gencnt <= gencnt) {
535                        struct xinpcb xi;
536                        xi.xi_len = sizeof xi;
537                        /* XXX should avoid extra copy */
538                        bcopy(inp, &xi.xi_inp, sizeof *inp);
539#if 0
540                        if (inp->inp_socket)
541                                sotoxsocket(inp->inp_socket, &xi.xi_socket);
542#endif
543                        error = SYSCTL_OUT(req, &xi, sizeof xi);
544                }
545                INP_UNLOCK(inp);
546        }
547        if (!error) {
548                /*
549                 * Give the user an updated idea of our state.
550                 * If the generation differs from what we told
551                 * her before, she knows that something happened
552                 * while we were processing this request, and it
553                 * might be necessary to retry.
554                 */
555                s = splnet();
556                INP_INFO_RLOCK(&udbinfo);
557                xig.xig_gen = udbinfo.ipi_gencnt;
558#if 0
559                xig.xig_sogen = so_gencnt;
560#endif
561                xig.xig_count = udbinfo.ipi_count;
562                INP_INFO_RUNLOCK(&udbinfo);
563                splx(s);
564                error = SYSCTL_OUT(req, &xig, sizeof xig);
565        }
566        free(inp_list, M_TEMP);
567        return error;
568}
569
570SYSCTL_PROC(_net_inet_udp, UDPCTL_PCBLIST, pcblist, CTLFLAG_RD, 0, 0,
571            udp_pcblist, "S,xinpcb", "List of active UDP sockets");
572
573static u_long   udp_sendspace = 9216;           /* really max datagram size */
574                                        /* 40 1K datagrams */
575SYSCTL_INT(_net_inet_udp, UDPCTL_MAXDGRAM, maxdgram, CTLFLAG_RW,
576        &udp_sendspace, 0, "");
577
578static u_long   udp_recvspace = 40 * (1024 + sizeof(struct sockaddr_in));
579SYSCTL_INT(_net_inet_udp, UDPCTL_RECVSPACE, recvspace, CTLFLAG_RW,
580        &udp_recvspace, 0, "");
581
582/*ARGSUSED*/
583int
584udp_usrreq(so, req, m, addr, control)
585        struct socket *so;
586        int req;
587        struct mbuf *m, *addr, *control;
588{
589        struct inpcb *inp = sotoinpcb(so);
590        int error = 0;
591        int s;
592
593        if (req == PRU_CONTROL)
594                return (in_control(so, (u_long)m, (caddr_t)addr,
595                        (struct ifnet *)control));
596        if (inp == NULL && req != PRU_ATTACH) {
597                error = EINVAL;
598                goto release;
599        }
600        /*
601         * Note: need to block udp_input while changing
602         * the udp pcb queue and/or pcb addresses.
603         */
604        switch (req) {
605
606        case PRU_ATTACH:
607                if (inp != NULL) {
608                        error = EINVAL;
609                        break;
610                }
611                s = splnet();
612                error = in_pcballoc(so, &udbinfo);
613                splx(s);
614                if (error)
615                        break;
616                error = soreserve(so, udp_sendspace, udp_recvspace);
617                if (error)
618                        break;
619                ((struct inpcb *) so->so_pcb)->inp_ip_ttl = ip_defttl;
620                break;
621
622        case PRU_DETACH:
623                udp_detach(inp);
624                break;
625
626        case PRU_BIND:
627                s = splnet();
628                error = in_pcbbind(inp, addr);
629                splx(s);
630                break;
631
632        case PRU_LISTEN:
633                error = EOPNOTSUPP;
634                break;
635
636        case PRU_CONNECT:
637                if (inp->inp_faddr.s_addr != INADDR_ANY) {
638                        error = EISCONN;
639                        break;
640                }
641                s = splnet();
642                error = in_pcbconnect(inp, addr);
643                splx(s);
644                if (error == 0)
645                        soisconnected(so);
646                break;
647
648        case PRU_CONNECT2:
649                error = EOPNOTSUPP;
650                break;
651
652        case PRU_ACCEPT:
653                error = EOPNOTSUPP;
654                break;
655
656        case PRU_DISCONNECT:
657                if (inp->inp_faddr.s_addr == INADDR_ANY) {
658                        error = ENOTCONN;
659                        break;
660                }
661                s = splnet();
662                in_pcbdisconnect(inp);
663                inp->inp_laddr.s_addr = INADDR_ANY;
664                splx(s);
665                so->so_state &= ~SS_ISCONNECTED;                /* XXX */
666                break;
667
668        case PRU_SHUTDOWN:
669                socantsendmore(so);
670                break;
671
672        case PRU_SEND:
673                return (udp_output(inp, m, addr, control));
674
675        case PRU_ABORT:
676                soisdisconnected(so);
677                udp_detach(inp);
678                break;
679
680        case PRU_SOCKADDR:
681                in_setsockaddr(inp, addr);
682                break;
683
684        case PRU_PEERADDR:
685                in_setpeeraddr(inp, addr);
686                break;
687
688        case PRU_SENSE:
689                /*
690                 * stat: don't bother with a blocksize.
691                 */
692                return (0);
693
694        case PRU_SENDOOB:
695        case PRU_FASTTIMO:
696        case PRU_SLOWTIMO:
697        case PRU_PROTORCV:
698        case PRU_PROTOSEND:
699                error =  EOPNOTSUPP;
700                break;
701
702        case PRU_RCVD:
703        case PRU_RCVOOB:
704                return (EOPNOTSUPP);    /* do not free mbuf's */
705
706        default:
707                panic("udp_usrreq");
708        }
709
710release:
711        if (control) {
712                printf("udp control data unexpectedly retained\n");
713                m_freem(control);
714        }
715        if (m)
716                m_freem(m);
717        return (error);
718}
719
720static void
721udp_detach(inp)
722        struct inpcb *inp;
723{
724        int s = splnet();
725
726        in_pcbdetach(inp);
727        splx(s);
728}
Note: See TracBrowser for help on using the repository browser.