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