|
|
1.1 root 1: /*
2: * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3: *
4: * @APPLE_LICENSE_HEADER_START@
5: *
6: * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7: * Reserved. This file contains Original Code and/or Modifications of
8: * Original Code as defined in and that are subject to the Apple Public
9: * Source License Version 1.1 (the "License"). You may not use this file
10: * except in compliance with the License. Please obtain a copy of the
11: * License at http://www.apple.com/publicsource and read it before using
12: * this file.
13: *
14: * The Original Code and all software distributed under the License are
15: * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18: * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the
19: * License for the specific language governing rights and limitations
20: * under the License.
21: *
22: * @APPLE_LICENSE_HEADER_END@
23: */
24: /* Copyright (c) 1991 NeXT Computer, Inc. All rights reserved.
25: *
26: * netif.m - netif stub for testing NetDriver objects.
27: *
28: * HISTORY
29: * 24-Jul-91 Doug Mitchell at NeXT
30: * Created.
31: */
32:
33: /*
34: * Hmmm...we need KERNEL defined to get netif.h...
35: */
36: #import <bsd/sys/socket.h>
37: #define KERNEL 1
38: #import <net/netif.h>
39: #undef KERNEL
40: #import <driverkit/IONetDevice.h>
41: #import <net/if.h>
42: #import <bsd/sys/errno.h>
43: #import <bsd/sys/ioctl.h>
44: #import <driverkit/generalFuncs.h>
45: #import <libc.h>
46:
47: /*
48: * Horrible hack; these are kenel globals.
49: */
50: const char IFCONTROL_SETFLAGS[] = "setflags";
51: const char IFCONTROL_SETADDR[] = "setaddr";
52: const char IFCONTROL_GETADDR[] = "getaddr";
53: const char IFCONTROL_AUTOADDR[] = "autoaddr";
54: const char IFCONTROL_UNIXIOCTL[] = "unix-ioctl";
55:
56: /*
57: * This emulates all the calls to netif.c which a typical driver will make
58: * except for if_handle_input(); the client test program must implement
59: * that function to provide dispatch of incoming buffers.
60: *
61: * The client test program can define any arbitrary 'netbuf' struct desired.
62: * This module does not manipulate netbufs.
63: * We happen to use ifnet for internal representation for convenience - a lot
64: * of this code is just cloned from the kernel's netif.c.
65: */
66:
67: int if_output(netif_t netif, netbuf_t packet, void *addr)
68: {
69: struct ifnet *ifp = (struct ifnet *)netif;
70:
71: if (ifp->if_output == NULL) {
72: return (ENXIO);
73: } else {
74: return (ifp->if_output(netif, packet, addr));
75: }
76: }
77:
78: int if_init(netif_t netif)
79: {
80: struct ifnet *ifp = (struct ifnet *)netif;
81:
82: if (ifp->if_init == NULL) {
83: return (ENXIO);
84: } else {
85: return (ifp->if_init(netif));
86: }
87: }
88:
89: int if_control(netif_t netif, const char *command, void *data)
90: {
91: struct ifnet *ifp = (struct ifnet *)netif;
92:
93: if (ifp->if_control == NULL) {
94: return (ENXIO);
95: } else {
96: return (ifp->if_control(netif, command, data));
97: }
98: }
99:
100: int if_ioctl(netif_t netif, unsigned command, void *data)
101: {
102: struct ifnet *ifp = (struct ifnet *)netif;
103: struct ifreq *ifr = (struct ifreq *)data;
104: if_ioctl_t ioctl_stuff;
105:
106: if (ifp->if_control == NULL) {
107: return (ENXIO);
108: }
109: switch (command) {
110: case SIOCAUTOADDR:
111: return (ifp->if_control(netif, IFCONTROL_AUTOADDR,
112: (void *)&ifr->ifr_ifru));
113:
114:
115: case SIOCSIFADDR:
116: /*
117: * XXX: IP calls this incorrectly with an ifaddr
118: * struct instead of an ifreq struct
119: */
120: return (ifp->if_control(netif, IFCONTROL_SETADDR,
121: (void *)data));
122:
123: case SIOCGIFADDR:
124: return (ifp->if_control(netif, IFCONTROL_GETADDR,
125: (void *)&ifr->ifr_ifru));
126:
127: case SIOCSIFFLAGS:
128: return (ifp->if_control(netif, IFCONTROL_SETFLAGS,
129: (void *)&ifr->ifr_ifru));
130:
131: default:
132: ioctl_stuff.ioctl_command = command;
133: ioctl_stuff.ioctl_data = data;
134: return (ifp->if_control(netif, IFCONTROL_UNIXIOCTL,
135: (void *)&ioctl_stuff));
136: }
137: }
138:
139: netbuf_t if_getbuf(netif_t netif)
140: {
141: struct ifnet *ifp = (struct ifnet *)netif;
142:
143: if (ifp->if_getbuf == NULL) {
144: return (NULL); /* should never happen */
145: } else {
146: return (ifp->if_getbuf(netif));
147: }
148: }
149:
150: netif_t if_attach(if_init_func_t init_func,
151: if_input_func_t input_func,
152: if_output_func_t output_func,
153: if_getbuf_func_t getbuf_func,
154: if_control_func_t control_func,
155: const char *name,
156: unsigned unit,
157: const char *type,
158: unsigned mtu,
159: unsigned flags,
160: netif_class_t class,
161: void *private)
162: {
163: struct ifnet *ifp;
164:
165: ifp = (struct ifnet *)IOMalloc(sizeof(struct ifnet));
166: bzero((void *)ifp, sizeof(struct ifnet));
167: ifp->if_name = (char *)name;
168: ifp->if_type = (char *)type;
169: ifp->if_unit = unit;
170: ifp->if_mtu = mtu;
171: ifp->if_flags = flags;
172: ifp->if_snd.ifq_maxlen = /* ifqmaxlen */ IFQ_MAXLEN;
173: ifp->if_init = init_func;
174: ifp->if_output = output_func;
175: ifp->if_control = control_func;
176: ifp->if_input = input_func;
177: ifp->if_getbuf = getbuf_func;
178: ifp->if_private = private;
179: ifp->if_class = class;
180:
181: #ifdef notdef
182: /* we don't need this. */
183: for (ifpp = &ifnet;
184: *ifpp != NULL && (*ifpp)->if_class >= class;
185: ifpp = &(*ifpp)->if_next) {
186: }
187: ifp->if_next = *ifpp;
188: *ifpp = ifp;
189: if (ifp->if_class == NETIFCLASS_REAL) {
190: pingvirtuals((netif_t)ifp);
191: }
192: #endif notdef
193: return ((netif_t)ifp);
194: }
195:
196: void if_registervirtual(if_attach_func_t attach_func, void *private)
197: {
198: return; // ??
199: }
200:
201: void *
202: if_private(
203: netif_t netif
204: )
205: {
206: return (((struct ifnet *)netif)->if_private);
207: }
208:
209: unsigned
210: if_unit(
211: netif_t netif
212: )
213: {
214: return (((struct ifnet *)netif)->if_unit);
215: }
216:
217: const char *
218: if_name(
219: netif_t netif
220: )
221: {
222: return (((struct ifnet *)netif)->if_name);
223: }
224:
225: const char *
226: if_type(
227: netif_t netif
228: )
229: {
230: return (((struct ifnet *)netif)->if_type);
231: }
232:
233: unsigned
234: if_mtu(
235: netif_t netif
236: )
237: {
238: return (((struct ifnet *)netif)->if_mtu);
239: }
240:
241: unsigned
242: if_flags(
243: netif_t netif
244: )
245: {
246: return (((struct ifnet *)netif)->if_flags);
247: }
248:
249: unsigned
250: if_opackets(
251: netif_t netif
252: )
253: {
254: return (((struct ifnet *)netif)->if_opackets);
255: }
256:
257: unsigned
258: if_ipackets(
259: netif_t netif
260: )
261: {
262: return (((struct ifnet *)netif)->if_ipackets);
263: }
264:
265: unsigned
266: if_oerrors(
267: netif_t netif
268: )
269: {
270: return (((struct ifnet *)netif)->if_oerrors);
271: }
272:
273: unsigned
274: if_ierrors(
275: netif_t netif
276: )
277: {
278: return (((struct ifnet *)netif)->if_ierrors);
279: }
280:
281: unsigned
282: if_collisions(
283: netif_t netif
284: )
285: {
286: return (((struct ifnet *)netif)->if_collisions);
287: }
288:
289: void
290: if_flags_set(
291: netif_t netif,
292: unsigned flags
293: )
294: {
295: ((struct ifnet *)netif)->if_flags = flags;
296: }
297:
298: void
299: if_opackets_set(
300: netif_t netif,
301: unsigned opackets
302: )
303: {
304: ((struct ifnet *)netif)->if_opackets = opackets;
305: }
306:
307: void
308: if_ipackets_set(
309: netif_t netif,
310: unsigned ipackets
311: )
312: {
313: ((struct ifnet *)netif)->if_ipackets = ipackets;
314: }
315:
316: void
317: if_oerrors_set(
318: netif_t netif,
319: unsigned oerrors
320: )
321: {
322: ((struct ifnet *)netif)->if_oerrors = oerrors;
323: }
324:
325: void
326: if_ierrors_set(
327: netif_t netif,
328: unsigned ierrors
329: )
330: {
331: ((struct ifnet *)netif)->if_oerrors = ierrors;
332: }
333:
334: void
335: if_collisions_set(
336: netif_t netif,
337: unsigned collisions
338: )
339: {
340: ((struct ifnet *)netif)->if_collisions = collisions;
341: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.