1 | /* |
---|
2 | * Copyright (c) 1998-2002 Luigi Rizzo |
---|
3 | * |
---|
4 | * Work partly supported by: Cisco Systems, Inc. - NSITE lab, RTP, NC |
---|
5 | * |
---|
6 | * Redistribution and use in source and binary forms, with or without |
---|
7 | * modification, are permitted provided that the following conditions |
---|
8 | * are met: |
---|
9 | * 1. Redistributions of source code must retain the above copyright |
---|
10 | * notice, this list of conditions and the following disclaimer. |
---|
11 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
12 | * notice, this list of conditions and the following disclaimer in the |
---|
13 | * documentation and/or other materials provided with the distribution. |
---|
14 | * |
---|
15 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
---|
16 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
---|
19 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
---|
20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
---|
21 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
---|
22 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
---|
23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
---|
24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
---|
25 | * SUCH DAMAGE. |
---|
26 | * |
---|
27 | * $FreeBSD: src/sys/net/bridge.h,v 1.11 2002/02/15 05:11:11 luigi Exp $ |
---|
28 | */ |
---|
29 | |
---|
30 | extern int do_bridge; |
---|
31 | |
---|
32 | /* |
---|
33 | * We need additional per-interface info for the bridge, which is |
---|
34 | * stored in a struct bdg_softc. The ifp2sc[] array provides a pointer |
---|
35 | * to this struct using the if_index as a mapping key. |
---|
36 | * bdg_softc has a backpointer to the struct ifnet, the bridge |
---|
37 | * flags, and a cluster (bridging occurs only between port of the |
---|
38 | * same cluster). |
---|
39 | */ |
---|
40 | |
---|
41 | struct cluster_softc; /* opaque here, defined in bridge.c */ |
---|
42 | |
---|
43 | struct bdg_softc { |
---|
44 | struct ifnet *ifp ; |
---|
45 | /* also ((struct arpcom *)ifp)->ac_enaddr is the eth. addr */ |
---|
46 | int flags ; |
---|
47 | #define IFF_BDG_PROMISC 0x0001 /* set promisc mode on this if. */ |
---|
48 | #define IFF_MUTE 0x0002 /* mute this if for bridging. */ |
---|
49 | #define IFF_USED 0x0004 /* use this if for bridging. */ |
---|
50 | struct cluster_softc *cluster; |
---|
51 | } ; |
---|
52 | |
---|
53 | extern struct bdg_softc *ifp2sc; |
---|
54 | |
---|
55 | #define BDG_USED(ifp) (ifp2sc[ifp->if_index].flags & IFF_USED) |
---|
56 | /* |
---|
57 | * BDG_ACTIVE(ifp) does all checks to see if bridging is enabled, loaded, |
---|
58 | * and used on a given interface. |
---|
59 | */ |
---|
60 | #define BDG_ACTIVE(ifp) (do_bridge && BDG_LOADED && BDG_USED(ifp)) |
---|
61 | |
---|
62 | /* |
---|
63 | * The following constants are not legal ifnet pointers, and are used |
---|
64 | * as return values from the classifier, bridge_dst_lookup(). |
---|
65 | * The same values are used as index in the statistics arrays, |
---|
66 | * with BDG_FORWARD replacing specifically forwarded packets. |
---|
67 | * |
---|
68 | * These constants are here because they are used in 'netstat' |
---|
69 | * to show bridge statistics. |
---|
70 | */ |
---|
71 | #define BDG_BCAST ( (struct ifnet *)1 ) |
---|
72 | #define BDG_MCAST ( (struct ifnet *)2 ) |
---|
73 | #define BDG_LOCAL ( (struct ifnet *)3 ) |
---|
74 | #define BDG_DROP ( (struct ifnet *)4 ) |
---|
75 | #define BDG_UNKNOWN ( (struct ifnet *)5 ) |
---|
76 | #define BDG_IN ( (struct ifnet *)7 ) |
---|
77 | #define BDG_OUT ( (struct ifnet *)8 ) |
---|
78 | #define BDG_FORWARD ( (struct ifnet *)9 ) |
---|
79 | |
---|
80 | /* |
---|
81 | * Statistics are passed up with the sysctl interface, "netstat -p bdg" |
---|
82 | * reads them. PF_BDG defines the 'bridge' protocol family. |
---|
83 | */ |
---|
84 | |
---|
85 | #define PF_BDG 3 /* XXX superhack */ |
---|
86 | |
---|
87 | #define STAT_MAX (int)BDG_FORWARD |
---|
88 | struct bdg_port_stat { |
---|
89 | char name[16]; |
---|
90 | u_long collisions; |
---|
91 | u_long p_in[STAT_MAX+1]; |
---|
92 | } ; |
---|
93 | |
---|
94 | /* XXX this should be made dynamic */ |
---|
95 | #define BDG_MAX_PORTS 128 |
---|
96 | struct bdg_stats { |
---|
97 | struct bdg_port_stat s[BDG_MAX_PORTS]; |
---|
98 | } ; |
---|
99 | |
---|
100 | |
---|
101 | #define BDG_STAT(ifp, type) bdg_stats.s[ifp->if_index].p_in[(uintptr_t)type]++ |
---|
102 | |
---|
103 | #ifdef _KERNEL |
---|
104 | typedef struct ifnet *bridge_in_t(struct ifnet *, struct ether_header *); |
---|
105 | /* bdg_forward frees the mbuf if necessary, returning null */ |
---|
106 | typedef struct mbuf *bdg_forward_t(struct mbuf *, struct ether_header *const, |
---|
107 | struct ifnet *); |
---|
108 | typedef void bdgtakeifaces_t(void); |
---|
109 | extern bridge_in_t *bridge_in_ptr; |
---|
110 | extern bdg_forward_t *bdg_forward_ptr; |
---|
111 | extern bdgtakeifaces_t *bdgtakeifaces_ptr; |
---|
112 | |
---|
113 | #define BDG_LOADED (bdgtakeifaces_ptr != NULL) |
---|
114 | #endif /* KERNEL */ |
---|