]>
Commit | Line | Data |
---|---|---|
4a95091d FL |
1 | /* |
2 | * Copyright (c) 2014 Red Hat, Inc. | |
3 | * | |
4 | * Based on mac-learning implementation. | |
5 | * | |
6 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
7 | * you may not use this file except in compliance with the License. | |
8 | * You may obtain a copy of the License at: | |
9 | * | |
10 | * http://www.apache.org/licenses/LICENSE-2.0 | |
11 | * | |
12 | * Unless required by applicable law or agreed to in writing, software | |
13 | * distributed under the License is distributed on an "AS IS" BASIS, | |
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
15 | * See the License for the specific language governing permissions and | |
16 | * limitations under the License. | |
17 | */ | |
18 | ||
19 | #ifndef MCAST_SNOOPING_H | |
20 | #define MCAST_SNOOPING_H 1 | |
21 | ||
22 | #include <time.h> | |
23 | #include "hmap.h" | |
24 | #include "list.h" | |
25 | #include "ovs-atomic.h" | |
26 | #include "ovs-thread.h" | |
27 | #include "packets.h" | |
28 | #include "timeval.h" | |
29 | ||
30 | struct mcast_snooping; | |
31 | ||
32 | /* Default maximum size of a mcast snooping table, in entries. */ | |
33 | #define MCAST_DEFAULT_MAX_ENTRIES 2048 | |
34 | ||
35 | /* Time, in seconds, before expiring a mcast_group due to inactivity. */ | |
36 | #define MCAST_ENTRY_DEFAULT_IDLE_TIME 300 | |
37 | ||
38 | /* Time, in seconds, before expiring a mrouter_port due to inactivity. */ | |
39 | #define MCAST_MROUTER_PORT_IDLE_TIME 180 | |
40 | ||
41 | /* Multicast group entry. | |
42 | * Guarded by owning 'mcast_snooping''s rwlock. */ | |
43 | struct mcast_group { | |
44 | /* Node in parent struct mcast_snooping hmap. */ | |
45 | struct hmap_node hmap_node; | |
46 | ||
47 | /* Multicast group IPv4 address. */ | |
48 | ovs_be32 ip4; | |
49 | ||
50 | /* VLAN tag. */ | |
51 | uint16_t vlan; | |
52 | ||
53 | /* Node in parent struct mcast_snooping group_lru. */ | |
ca6ba700 | 54 | struct ovs_list group_node OVS_GUARDED; |
4a95091d FL |
55 | |
56 | /* Contains struct mcast_group_bundle (ports), least recently used | |
57 | * at the front, most recently used at the back. */ | |
ca6ba700 | 58 | struct ovs_list bundle_lru OVS_GUARDED; |
4a95091d FL |
59 | }; |
60 | ||
61 | /* The bundle associated to the multicast group. | |
62 | * Guarded by owning 'mcast_snooping''s rwlock. */ | |
63 | struct mcast_group_bundle { | |
64 | /* Node in parent struct mcast_group bundle_lru list. */ | |
ca6ba700 | 65 | struct ovs_list bundle_node OVS_GUARDED; |
4a95091d FL |
66 | |
67 | /* When this node expires. */ | |
68 | time_t expires; | |
69 | ||
70 | /* Learned port. */ | |
71 | void *port OVS_GUARDED; | |
72 | }; | |
73 | ||
74 | /* The bundle connected to a multicast router. | |
75 | * Guarded by owning 'mcast_snooping''s rwlock. */ | |
76 | struct mcast_mrouter_bundle { | |
77 | /* Node in parent struct mcast_group mrouter_lru list. */ | |
ca6ba700 | 78 | struct ovs_list mrouter_node OVS_GUARDED; |
4a95091d FL |
79 | |
80 | /* When this node expires. */ | |
81 | time_t expires; | |
82 | ||
83 | /* VLAN tag. */ | |
84 | uint16_t vlan; | |
85 | ||
86 | /* Learned port. */ | |
87 | void *port OVS_GUARDED; | |
88 | }; | |
89 | ||
8e04a33f | 90 | /* The bundle to send multicast traffic or Reports. |
4a95091d | 91 | * Guarded by owning 'mcast_snooping''s rwlock */ |
f4ae6e23 FL |
92 | struct mcast_port_bundle { |
93 | /* Node in parent struct mcast_snooping. */ | |
94 | struct ovs_list node; | |
4a95091d FL |
95 | |
96 | /* VLAN tag. */ | |
97 | uint16_t vlan; | |
98 | ||
99 | /* Learned port. */ | |
f4ae6e23 | 100 | void *port; |
4a95091d FL |
101 | }; |
102 | ||
103 | /* Multicast snooping table. */ | |
104 | struct mcast_snooping { | |
105 | /* Snooping/learning table. */ | |
106 | struct hmap table; | |
107 | ||
108 | /* Contains struct mcast_group, least recently used at the front, | |
109 | * most recently used at the back. */ | |
ca6ba700 | 110 | struct ovs_list group_lru OVS_GUARDED; |
4a95091d FL |
111 | |
112 | /* Contains struct mcast_mrouter_bundle, least recently used at the | |
113 | * front, most recently used at the back. */ | |
ca6ba700 | 114 | struct ovs_list mrouter_lru OVS_GUARDED; |
4a95091d | 115 | |
f4ae6e23 | 116 | /* Contains struct mcast_port_bundle to be flooded with multicast |
4a95091d | 117 | * packets in no special order. */ |
ca6ba700 | 118 | struct ovs_list fport_list OVS_GUARDED; |
4a95091d | 119 | |
8e04a33f FL |
120 | /* Contains struct mcast_port_bundle to forward Reports in |
121 | * no special order. */ | |
122 | struct ovs_list rport_list OVS_GUARDED; | |
123 | ||
4a95091d FL |
124 | /* Secret for randomizing hash table. */ |
125 | uint32_t secret; | |
126 | ||
127 | /* Maximum age before deleting an entry. */ | |
128 | unsigned int idle_time; | |
129 | ||
130 | /* Maximum number of multicast groups learned. */ | |
131 | size_t max_entries; | |
132 | ||
133 | /* True if flow revalidation is needed. */ | |
134 | bool need_revalidate; | |
135 | ||
136 | /* True if unregistered multicast packets should be flooded to all | |
137 | * ports, otherwise send them to ports connected to multicast routers. */ | |
138 | bool flood_unreg; | |
139 | ||
140 | struct ovs_refcount ref_cnt; | |
141 | struct ovs_rwlock rwlock; | |
142 | }; | |
143 | ||
144 | /* Basics. */ | |
145 | bool mcast_snooping_enabled(const struct mcast_snooping *ms); | |
146 | bool mcast_snooping_flood_unreg(const struct mcast_snooping *ms); | |
147 | int mcast_mrouter_age(const struct mcast_snooping *ms, | |
148 | const struct mcast_mrouter_bundle *m); | |
149 | int mcast_bundle_age(const struct mcast_snooping *ms, | |
150 | const struct mcast_group_bundle *b); | |
151 | struct mcast_snooping *mcast_snooping_create(void); | |
152 | struct mcast_snooping *mcast_snooping_ref(const struct mcast_snooping *); | |
153 | void mcast_snooping_unref(struct mcast_snooping *); | |
154 | bool mcast_snooping_run(struct mcast_snooping *ms); | |
155 | void mcast_snooping_wait(struct mcast_snooping *ms); | |
156 | ||
157 | /* Configuration. */ | |
158 | void mcast_snooping_set_idle_time(struct mcast_snooping *ms, | |
159 | unsigned int idle_time) | |
160 | OVS_REQ_WRLOCK(ms->rwlock); | |
161 | void mcast_snooping_set_max_entries(struct mcast_snooping *ms, | |
162 | size_t max_entries) | |
163 | OVS_REQ_WRLOCK(ms->rwlock); | |
164 | bool | |
165 | mcast_snooping_set_flood_unreg(struct mcast_snooping *ms, bool enable) | |
166 | OVS_REQ_WRLOCK(ms->rwlock); | |
f4ae6e23 FL |
167 | void mcast_snooping_set_port_flood(struct mcast_snooping *ms, void *port, |
168 | bool flood) | |
4a95091d | 169 | OVS_REQ_WRLOCK(ms->rwlock); |
8e04a33f FL |
170 | void mcast_snooping_set_port_flood_reports(struct mcast_snooping *ms, |
171 | void *port, bool flood) | |
172 | OVS_REQ_WRLOCK(ms->rwlock); | |
4a95091d FL |
173 | |
174 | /* Lookup. */ | |
175 | struct mcast_group * | |
176 | mcast_snooping_lookup(const struct mcast_snooping *ms, ovs_be32 dip, | |
177 | uint16_t vlan) | |
178 | OVS_REQ_RDLOCK(ms->rwlock); | |
179 | ||
180 | /* Learning. */ | |
181 | bool mcast_snooping_add_group(struct mcast_snooping *ms, ovs_be32 ip4, | |
182 | uint16_t vlan, void *port) | |
183 | OVS_REQ_WRLOCK(ms->rwlock); | |
184 | bool mcast_snooping_leave_group(struct mcast_snooping *ms, ovs_be32 ip4, | |
185 | uint16_t vlan, void *port) | |
186 | OVS_REQ_WRLOCK(ms->rwlock); | |
187 | bool mcast_snooping_add_mrouter(struct mcast_snooping *ms, uint16_t vlan, | |
188 | void *port) | |
189 | OVS_REQ_WRLOCK(ms->rwlock); | |
4a95091d FL |
190 | bool mcast_snooping_is_query(ovs_be16 igmp_type); |
191 | bool mcast_snooping_is_membership(ovs_be16 igmp_type); | |
192 | ||
193 | /* Flush. */ | |
194 | void mcast_snooping_mdb_flush(struct mcast_snooping *ms); | |
195 | void mcast_snooping_flush(struct mcast_snooping *ms); | |
196 | ||
197 | #endif /* mcast-snooping.h */ |