source: rtems/cpukit/libnetworking/netinet/udp_usrreq.c @ e744c36

5
Last change on this file since e744c36 was e744c36, checked in by Sebastian Huber <sebastian.huber@…>, on 06/07/17 at 05:36:59

network: Use inet_ntoa_r()

Update #2833.

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