source: rtems/cpukit/libnetworking/netinet/udp_usrreq.c @ 45f9cd0

4.10
Last change on this file since 45f9cd0 was 45f9cd0, checked in by Sebastian Huber <sebastian.huber@…>, on 11/02/12 at 13:45:50

libnetworking: Disconnect after mbuf shortage

The missing disconnect left the socket in an unusable state. Each send
request resulted in an EISCONN error.

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