source: rtems/cpukit/libnetworking/net/if_loop.c @ 5f88544

4.104.114.84.95
Last change on this file since 5f88544 was 5f88544, checked in by Joel Sherrill <joel.sherrill@…>, on Aug 15, 2006 at 11:08:14 AM

2006-08-15 Joel Sherrill <joel@…>

  • libnetworking/kern/kern_sysctl.c: Change int to int32_t.
  • libnetworking/net/if_loop.c: Add cast to long. These plus a patch to machine/param.h let the h8300 build multilib.
  • Property mode set to 100644
File size: 6.6 KB
Line 
1/*
2 * Copyright (c) 1982, 1986, 1993
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 *      @(#)if_loop.c   8.2 (Berkeley) 1/9/95
30 * $FreeBSD: src/sys/net/if_loop.c,v 1.104 2005/02/24 01:34:01 sam Exp $
31 */
32
33/*
34 * $Id$
35 */
36
37/*
38 * Loopback interface driver for protocol testing and timing.
39 */
40#include "loop.h"
41#if NLOOP > 0
42
43#include "opt_atalk.h"
44#include "opt_inet.h"
45#include "opt_inet6.h"
46#include "opt_ipx.h"
47
48#include <sys/param.h>
49#include <sys/systm.h>
50#include <sys/kernel.h>
51#include <sys/mbuf.h>
52#include <sys/socket.h>
53#include <sys/errno.h>
54#include <sys/ioctl.h>
55#include <sys/time.h>
56
57#include <net/if.h>
58#include <net/if_types.h>
59#include <net/netisr.h>
60#include <net/route.h>
61#include <net/bpf.h>
62
63#ifdef  INET
64#include <netinet/in.h>
65#include <netinet/in_systm.h>
66#include <netinet/in_var.h>
67#include <netinet/ip.h>
68#endif
69
70#ifdef IPX
71#include <netipx/ipx.h>
72#include <netipx/ipx_if.h>
73#endif
74
75#ifdef INET6
76#ifndef INET
77#include <netinet/in.h>
78#endif
79#include <netinet6/in6_var.h>
80#include <netinet/ip6.h>
81#endif
82
83#ifdef NETATALK
84#include <netatalk/at.h>
85#include <netatalk/at_var.h>
86#endif
87
88static int loioctl(struct ifnet *, u_long, caddr_t);
89static void lortrequest(int, struct rtentry *, struct sockaddr *);
90
91       void rtems_bsdnet_loopattach(void *);
92PSEUDO_SET(loopattach, if_loop);
93
94#ifdef TINY_LOMTU
95#define LOMTU   (1024+512)
96#elif defined(LARGE_LOMTU)
97#define LOMTU  131072
98#else
99#define LOMTU   16384
100#endif
101
102struct  ifnet loif[NLOOP];
103
104/* ARGSUSED */
105void
106rtems_bsdnet_loopattach(dummy)
107        void *dummy;
108{
109        register struct ifnet *ifp;
110        register int i = 0;
111
112        for (ifp = loif; i < NLOOP; ifp++) {
113            ifp->if_name = "lo";
114            ifp->if_next = NULL;
115            ifp->if_unit = i++;
116            ifp->if_mtu = LOMTU;
117            ifp->if_flags = IFF_LOOPBACK | IFF_MULTICAST;
118            ifp->if_ioctl = loioctl;
119            ifp->if_output = looutput;
120            ifp->if_type = IFT_LOOP;
121            ifp->if_hdrlen = 0;
122            ifp->if_addrlen = 0;
123            ifp->if_snd.ifq_maxlen = ifqmaxlen;
124            if_attach(ifp);
125#if NBPFILTER > 0
126            bpfattach(ifp, DLT_NULL, sizeof(u_int));
127#endif
128        }
129}
130
131int
132looutput(ifp, m, dst, rt)
133        struct ifnet *ifp;
134        register struct mbuf *m;
135        struct sockaddr *dst;
136        register struct rtentry *rt;
137{
138        int s, isr;
139        register struct ifqueue *ifq = 0;
140
141        if ((m->m_flags & M_PKTHDR) == 0)
142                panic("looutput no HDR");
143#if NBPFILTER > 0
144        /* BPF write needs to be handled specially */
145        if (dst->sa_family == AF_UNSPEC) {
146                dst->sa_family = *(mtod(m, int *));
147                m->m_len -= sizeof(int);
148                m->m_pkthdr.len -= sizeof(int);
149                m->m_data += sizeof(int);
150        }
151
152        /* Let BPF see incoming packet */
153        if (ifp->if_bpf) {
154                /*
155                 * We need to prepend the address family as
156                 * a four byte field.  Cons up a dummy header
157                 * to pacify bpf.  This is safe because bpf
158                 * will only read from the mbuf (i.e., it won't
159                 * try to free it or keep a pointer a to it).
160                 */
161                struct mbuf m0;
162                u_int af = dst->sa_family;
163
164                m0.m_next = m;
165                m0.m_len = 4;
166                m0.m_data = (char *)&af;
167
168                bpf_mtap(ifp, &m0);
169        }
170#endif
171        m->m_pkthdr.rcvif = ifp;
172
173        if (rt && rt->rt_flags & (RTF_REJECT|RTF_BLACKHOLE)) {
174                m_freem(m);
175                return (rt->rt_flags & RTF_BLACKHOLE ? 0 :
176                        rt->rt_flags & RTF_HOST ? EHOSTUNREACH : ENETUNREACH);
177        }
178        ifp->if_opackets++;
179        ifp->if_obytes += m->m_pkthdr.len;
180        switch (dst->sa_family) {
181
182#ifdef INET
183        case AF_INET:
184                ifq = &ipintrq;
185                isr = NETISR_IP;
186                break;
187#endif
188#ifdef IPX
189        case AF_IPX:
190                ifq = &ipxintrq;
191                isr = NETISR_IPX;
192                break;
193#endif
194#ifdef NETATALK
195        case AF_APPLETALK:
196                ifq = &atintrq2;
197                isr = NETISR_ATALK;
198                break;
199#endif /* NETATALK */
200        default:
201                printf("lo%d: can't handle af%d\n", ifp->if_unit,
202                        dst->sa_family);
203                m_freem(m);
204                return (EAFNOSUPPORT);
205        }
206        s = splimp();
207        if (IF_QFULL(ifq)) {
208                IF_DROP(ifq);
209                m_freem(m);
210                splx(s);
211                return (ENOBUFS);
212        }
213        IF_ENQUEUE(ifq, m);
214        schednetisr(isr);
215        ifp->if_ipackets++;
216        ifp->if_ibytes += m->m_pkthdr.len;
217        splx(s);
218        return (0);
219}
220
221/* ARGSUSED */
222static void
223lortrequest(cmd, rt, sa)
224        int cmd;
225        struct rtentry *rt;
226        struct sockaddr *sa;
227{
228        if (rt) {
229                rt->rt_rmx.rmx_mtu = rt->rt_ifp->if_mtu; /* for ISO */
230                /*
231                 * For optimal performance, the send and receive buffers
232                 * should be at least twice the MTU plus a little more for
233                 * overhead.
234                 */
235                rt->rt_rmx.rmx_recvpipe = 
236                        rt->rt_rmx.rmx_sendpipe = 3L * (long)LOMTU;
237        }
238}
239
240/*
241 * Process an ioctl request.
242 */
243/* ARGSUSED */
244static int
245loioctl(ifp, cmd, data)
246        register struct ifnet *ifp;
247        u_long cmd;
248        caddr_t data;
249{
250        register struct ifaddr *ifa;
251        register struct ifreq *ifr = (struct ifreq *)data;
252        register int error = 0;
253
254        switch (cmd) {
255
256        case SIOCSIFADDR:
257                ifp->if_flags |= IFF_UP | IFF_RUNNING;
258                ifa = (struct ifaddr *)data;
259                ifa->ifa_rtrequest = lortrequest;
260                /*
261                 * Everything else is done at a higher level.
262                 */
263                break;
264
265        case SIOCADDMULTI:
266        case SIOCDELMULTI:
267                if (ifr == 0) {
268                        error = EAFNOSUPPORT;           /* XXX */
269                        break;
270                }
271                switch (ifr->ifr_addr.sa_family) {
272
273#ifdef INET
274                case AF_INET:
275                        break;
276#endif
277#ifdef INET6
278                case AF_INET6:
279                        break;
280#endif
281
282                default:
283                        error = EAFNOSUPPORT;
284                        break;
285                }
286                break;
287
288        case SIOCSIFMTU:
289                ifp->if_mtu = ifr->ifr_mtu;
290                break;
291
292        case SIOCSIFFLAGS:
293                break;
294
295        default:
296                error = EINVAL;
297        }
298        return (error);
299}
300#endif /* NLOOP > 0 */
Note: See TracBrowser for help on using the repository browser.