]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
5d5c5d0d A |
2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. |
3 | * | |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
1c79356b | 5 | * |
2d21ac55 A |
6 | * This file contains Original Code and/or Modifications of Original Code |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. The rights granted to you under the License | |
10 | * may not be used to create, or enable the creation or redistribution of, | |
11 | * unlawful or unlicensed copies of an Apple operating system, or to | |
12 | * circumvent, violate, or enable the circumvention or violation of, any | |
13 | * terms of an Apple operating system software license agreement. | |
8f6c56a5 | 14 | * |
2d21ac55 A |
15 | * Please obtain a copy of the License at |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
17 | * | |
18 | * The Original Code and all software distributed under the License are | |
19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
8f6c56a5 A |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
2d21ac55 A |
22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
23 | * Please see the License for the specific language governing rights and | |
24 | * limitations under the License. | |
8f6c56a5 | 25 | * |
2d21ac55 | 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
1c79356b A |
27 | */ |
28 | /* | |
29 | * Copyright (c) 1998 Luigi Rizzo | |
30 | * | |
31 | * Redistribution and use in source and binary forms, with or without | |
32 | * modification, are permitted provided that the following conditions | |
33 | * are met: | |
34 | * 1. Redistributions of source code must retain the above copyright | |
35 | * notice, this list of conditions and the following disclaimer. | |
36 | * 2. Redistributions in binary form must reproduce the above copyright | |
37 | * notice, this list of conditions and the following disclaimer in the | |
38 | * documentation and/or other materials provided with the distribution. | |
39 | * | |
40 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
41 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
42 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
43 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
44 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
45 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
46 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
48 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
49 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
50 | * SUCH DAMAGE. | |
51 | * | |
52 | */ | |
53 | #ifndef _NET_BRIDGE_H_ | |
54 | #define _NET_BRIDGE_H_ | |
9bccf70c A |
55 | #include <sys/appleapiopts.h> |
56 | ||
57 | #warning This is not used by Darwin, do not include | |
1c79356b A |
58 | |
59 | extern int do_bridge; | |
60 | /* | |
61 | * the hash table for bridge | |
62 | */ | |
63 | typedef struct hash_table { | |
64 | struct ifnet *name ; | |
65 | unsigned char etheraddr[6] ; | |
66 | unsigned short used ; | |
67 | } bdg_hash_table ; | |
68 | ||
69 | extern bdg_hash_table *bdg_table ; | |
70 | ||
9bccf70c A |
71 | /* |
72 | * We need additional info for the bridge. The bdg_ifp2sc[] array | |
73 | * provides a pointer to this struct using the if_index. | |
74 | * bdg_softc has a backpointer to the struct ifnet, the bridge | |
75 | * flags, and a cluster (bridging occurs only between port of the | |
76 | * same cluster). | |
77 | */ | |
78 | struct bdg_softc { | |
79 | struct ifnet *ifp ; | |
80 | /* also ((struct arpcom *)ifp)->ac_enaddr is the eth. addr */ | |
81 | int flags ; | |
82 | #define IFF_BDG_PROMISC 0x0001 /* set promisc mode on this if. */ | |
83 | #define IFF_MUTE 0x0002 /* mute this if for bridging. */ | |
84 | #define IFF_USED 0x0004 /* use this if for bridging. */ | |
85 | short cluster_id ; /* in network format */ | |
86 | u_long magic; | |
87 | } ; | |
88 | ||
89 | extern struct bdg_softc *ifp2sc; | |
90 | ||
91 | #define BDG_USED(ifp) (ifp2sc[ifp->if_index].flags & IFF_USED) | |
92 | #define BDG_MUTED(ifp) (ifp2sc[ifp->if_index].flags & IFF_MUTE) | |
93 | #define BDG_MUTE(ifp) ifp2sc[ifp->if_index].flags |= IFF_MUTE | |
94 | #define BDG_UNMUTE(ifp) ifp2sc[ifp->if_index].flags &= ~IFF_MUTE | |
95 | #define BDG_CLUSTER(ifp) (ifp2sc[ifp->if_index].cluster_id) | |
9bccf70c A |
96 | |
97 | #define BDG_SAMECLUSTER(ifp,src) \ | |
98 | (src == NULL || BDG_CLUSTER(ifp) == BDG_CLUSTER(src) ) | |
99 | ||
100 | ||
1c79356b | 101 | #define BDG_MAX_PORTS 128 |
9bccf70c A |
102 | typedef struct _bdg_addr { |
103 | unsigned char etheraddr[6] ; | |
104 | short cluster_id ; | |
105 | } bdg_addr ; | |
106 | extern bdg_addr bdg_addresses[BDG_MAX_PORTS]; | |
1c79356b A |
107 | extern int bdg_ports ; |
108 | ||
109 | /* | |
110 | * out of the 6 bytes, the last ones are more "variable". Since | |
111 | * we are on a little endian machine, we have to do some gimmick... | |
112 | */ | |
113 | #define HASH_SIZE 8192 /* must be a power of 2 */ | |
114 | #define HASH_FN(addr) ( \ | |
115 | ntohs( ((short *)addr)[1] ^ ((short *)addr)[2] ) & (HASH_SIZE -1)) | |
116 | ||
117 | #define IFF_MUTE IFF_LINK2 /* will need a separate flag... */ | |
118 | ||
9bccf70c | 119 | struct ifnet *bridge_in(struct ifnet *ifp, struct ether_header *eh); |
1c79356b | 120 | /* bdg_forward frees the mbuf if necessary, returning null */ |
9bccf70c | 121 | struct mbuf *bdg_forward(struct mbuf *m0, struct ether_header *eh, struct ifnet *dst); |
1c79356b A |
122 | |
123 | #ifdef __i386__ | |
124 | #define BDG_MATCH(a,b) ( \ | |
125 | ((unsigned short *)(a))[2] == ((unsigned short *)(b))[2] && \ | |
126 | *((unsigned int *)(a)) == *((unsigned int *)(b)) ) | |
127 | #define IS_ETHER_BROADCAST(a) ( \ | |
128 | *((unsigned int *)(a)) == 0xffffffff && \ | |
129 | ((unsigned short *)(a))[2] == 0xffff ) | |
130 | #else | |
131 | #warning... must complete these for the alpha etc. | |
132 | #define BDG_MATCH(a,b) (!bcmp(a, b, ETHER_ADDR_LEN) ) | |
133 | #endif | |
134 | /* | |
135 | * The following constants are not legal ifnet pointers, and are used | |
136 | * as return values from the classifier, bridge_dst_lookup() | |
137 | * The same values are used as index in the statistics arrays, | |
138 | * with BDG_FORWARD replacing specifically forwarded packets. | |
139 | */ | |
140 | #define BDG_BCAST ( (struct ifnet *)1 ) | |
141 | #define BDG_MCAST ( (struct ifnet *)2 ) | |
142 | #define BDG_LOCAL ( (struct ifnet *)3 ) | |
143 | #define BDG_DROP ( (struct ifnet *)4 ) | |
144 | #define BDG_UNKNOWN ( (struct ifnet *)5 ) | |
145 | #define BDG_IN ( (struct ifnet *)7 ) | |
146 | #define BDG_OUT ( (struct ifnet *)8 ) | |
147 | #define BDG_FORWARD ( (struct ifnet *)9 ) | |
148 | ||
149 | #define PF_BDG 3 /* XXX superhack */ | |
150 | /* | |
151 | * statistics, passed up with sysctl interface and ns -p bdg | |
152 | */ | |
153 | ||
154 | #define STAT_MAX (int)BDG_FORWARD | |
155 | struct bdg_port_stat { | |
156 | char name[16]; | |
157 | u_long collisions; | |
158 | u_long p_in[STAT_MAX+1]; | |
159 | } ; | |
160 | ||
161 | struct bdg_stats { | |
162 | struct bdg_port_stat s[16]; | |
163 | } ; | |
164 | ||
165 | ||
166 | #define BDG_STAT(ifp, type) bdg_stats.s[ifp->if_index].p_in[(int)type]++ | |
167 | ||
9bccf70c | 168 | #ifdef KERNEL |
1c79356b A |
169 | /* |
170 | * Find the right pkt destination: | |
171 | * BDG_BCAST is a broadcast | |
172 | * BDG_MCAST is a multicast | |
173 | * BDG_LOCAL is for a local address | |
174 | * BDG_DROP must be dropped | |
175 | * other ifp of the dest. interface (incl.self) | |
9bccf70c A |
176 | * |
177 | * We assume this is only called for interfaces for which bridging | |
178 | * is enabled, i.e. BDG_USED(ifp) is true. | |
1c79356b A |
179 | */ |
180 | static __inline | |
181 | struct ifnet * | |
9bccf70c | 182 | bridge_dst_lookup(struct ether_header *eh) |
1c79356b | 183 | { |
1c79356b A |
184 | struct ifnet *dst ; |
185 | int index ; | |
9bccf70c | 186 | bdg_addr *p ; |
1c79356b A |
187 | |
188 | if (IS_ETHER_BROADCAST(eh->ether_dhost)) | |
189 | return BDG_BCAST ; | |
190 | if (eh->ether_dhost[0] & 1) | |
191 | return BDG_MCAST ; | |
192 | /* | |
193 | * Lookup local addresses in case one matches. | |
194 | */ | |
9bccf70c A |
195 | for (index = bdg_ports, p = bdg_addresses ; index ; index--, p++ ) |
196 | if (BDG_MATCH(p->etheraddr, eh->ether_dhost) ) | |
1c79356b A |
197 | return BDG_LOCAL ; |
198 | /* | |
199 | * Look for a possible destination in table | |
200 | */ | |
201 | index= HASH_FN( eh->ether_dhost ); | |
202 | dst = bdg_table[index].name; | |
203 | if ( dst && BDG_MATCH( bdg_table[index].etheraddr, eh->ether_dhost) ) | |
204 | return dst ; | |
205 | else | |
206 | return BDG_UNKNOWN ; | |
207 | } | |
208 | ||
209 | #endif /* KERNEL */ | |
210 | ||
9bccf70c | 211 | #endif /* _NET_BRIDGE_H_ */ |