]>
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> | |
e3102e42 | 23 | #include "dp-packet.h" |
ee89ea7b | 24 | #include "openvswitch/hmap.h" |
b19bab5b | 25 | #include "openvswitch/list.h" |
4a95091d FL |
26 | #include "ovs-atomic.h" |
27 | #include "ovs-thread.h" | |
28 | #include "packets.h" | |
29 | #include "timeval.h" | |
30 | ||
31 | struct mcast_snooping; | |
32 | ||
33 | /* Default maximum size of a mcast snooping table, in entries. */ | |
34 | #define MCAST_DEFAULT_MAX_ENTRIES 2048 | |
35 | ||
36 | /* Time, in seconds, before expiring a mcast_group due to inactivity. */ | |
37 | #define MCAST_ENTRY_DEFAULT_IDLE_TIME 300 | |
38 | ||
39 | /* Time, in seconds, before expiring a mrouter_port due to inactivity. */ | |
40 | #define MCAST_MROUTER_PORT_IDLE_TIME 180 | |
41 | ||
42 | /* Multicast group entry. | |
43 | * Guarded by owning 'mcast_snooping''s rwlock. */ | |
44 | struct mcast_group { | |
45 | /* Node in parent struct mcast_snooping hmap. */ | |
46 | struct hmap_node hmap_node; | |
47 | ||
964a4d5f TLSC |
48 | /* Multicast group IPv6/IPv4 address. */ |
49 | struct in6_addr addr; | |
4a95091d FL |
50 | |
51 | /* VLAN tag. */ | |
52 | uint16_t vlan; | |
53 | ||
54 | /* Node in parent struct mcast_snooping group_lru. */ | |
ca6ba700 | 55 | struct ovs_list group_node OVS_GUARDED; |
4a95091d FL |
56 | |
57 | /* Contains struct mcast_group_bundle (ports), least recently used | |
58 | * at the front, most recently used at the back. */ | |
ca6ba700 | 59 | struct ovs_list bundle_lru OVS_GUARDED; |
4a95091d FL |
60 | }; |
61 | ||
62 | /* The bundle associated to the multicast group. | |
63 | * Guarded by owning 'mcast_snooping''s rwlock. */ | |
64 | struct mcast_group_bundle { | |
65 | /* Node in parent struct mcast_group bundle_lru list. */ | |
ca6ba700 | 66 | struct ovs_list bundle_node OVS_GUARDED; |
4a95091d FL |
67 | |
68 | /* When this node expires. */ | |
69 | time_t expires; | |
70 | ||
71 | /* Learned port. */ | |
72 | void *port OVS_GUARDED; | |
73 | }; | |
74 | ||
75 | /* The bundle connected to a multicast router. | |
76 | * Guarded by owning 'mcast_snooping''s rwlock. */ | |
77 | struct mcast_mrouter_bundle { | |
78 | /* Node in parent struct mcast_group mrouter_lru list. */ | |
ca6ba700 | 79 | struct ovs_list mrouter_node OVS_GUARDED; |
4a95091d FL |
80 | |
81 | /* When this node expires. */ | |
82 | time_t expires; | |
83 | ||
84 | /* VLAN tag. */ | |
85 | uint16_t vlan; | |
86 | ||
87 | /* Learned port. */ | |
88 | void *port OVS_GUARDED; | |
89 | }; | |
90 | ||
8e04a33f | 91 | /* The bundle to send multicast traffic or Reports. |
4a95091d | 92 | * Guarded by owning 'mcast_snooping''s rwlock */ |
f4ae6e23 FL |
93 | struct mcast_port_bundle { |
94 | /* Node in parent struct mcast_snooping. */ | |
95 | struct ovs_list node; | |
4a95091d FL |
96 | |
97 | /* VLAN tag. */ | |
98 | uint16_t vlan; | |
99 | ||
100 | /* Learned port. */ | |
f4ae6e23 | 101 | void *port; |
4a95091d FL |
102 | }; |
103 | ||
104 | /* Multicast snooping table. */ | |
105 | struct mcast_snooping { | |
106 | /* Snooping/learning table. */ | |
107 | struct hmap table; | |
108 | ||
109 | /* Contains struct mcast_group, least recently used at the front, | |
110 | * most recently used at the back. */ | |
ca6ba700 | 111 | struct ovs_list group_lru OVS_GUARDED; |
4a95091d FL |
112 | |
113 | /* Contains struct mcast_mrouter_bundle, least recently used at the | |
114 | * front, most recently used at the back. */ | |
ca6ba700 | 115 | struct ovs_list mrouter_lru OVS_GUARDED; |
4a95091d | 116 | |
f4ae6e23 | 117 | /* Contains struct mcast_port_bundle to be flooded with multicast |
4a95091d | 118 | * packets in no special order. */ |
ca6ba700 | 119 | struct ovs_list fport_list OVS_GUARDED; |
4a95091d | 120 | |
8e04a33f FL |
121 | /* Contains struct mcast_port_bundle to forward Reports in |
122 | * no special order. */ | |
123 | struct ovs_list rport_list OVS_GUARDED; | |
124 | ||
4a95091d FL |
125 | /* Secret for randomizing hash table. */ |
126 | uint32_t secret; | |
127 | ||
128 | /* Maximum age before deleting an entry. */ | |
129 | unsigned int idle_time; | |
130 | ||
131 | /* Maximum number of multicast groups learned. */ | |
132 | size_t max_entries; | |
133 | ||
134 | /* True if flow revalidation is needed. */ | |
135 | bool need_revalidate; | |
136 | ||
137 | /* True if unregistered multicast packets should be flooded to all | |
138 | * ports, otherwise send them to ports connected to multicast routers. */ | |
139 | bool flood_unreg; | |
140 | ||
141 | struct ovs_refcount ref_cnt; | |
142 | struct ovs_rwlock rwlock; | |
143 | }; | |
144 | ||
145 | /* Basics. */ | |
146 | bool mcast_snooping_enabled(const struct mcast_snooping *ms); | |
147 | bool mcast_snooping_flood_unreg(const struct mcast_snooping *ms); | |
148 | int mcast_mrouter_age(const struct mcast_snooping *ms, | |
149 | const struct mcast_mrouter_bundle *m); | |
150 | int mcast_bundle_age(const struct mcast_snooping *ms, | |
151 | const struct mcast_group_bundle *b); | |
152 | struct mcast_snooping *mcast_snooping_create(void); | |
153 | struct mcast_snooping *mcast_snooping_ref(const struct mcast_snooping *); | |
154 | void mcast_snooping_unref(struct mcast_snooping *); | |
155 | bool mcast_snooping_run(struct mcast_snooping *ms); | |
156 | void mcast_snooping_wait(struct mcast_snooping *ms); | |
157 | ||
158 | /* Configuration. */ | |
159 | void mcast_snooping_set_idle_time(struct mcast_snooping *ms, | |
160 | unsigned int idle_time) | |
161 | OVS_REQ_WRLOCK(ms->rwlock); | |
162 | void mcast_snooping_set_max_entries(struct mcast_snooping *ms, | |
163 | size_t max_entries) | |
164 | OVS_REQ_WRLOCK(ms->rwlock); | |
165 | bool | |
166 | mcast_snooping_set_flood_unreg(struct mcast_snooping *ms, bool enable) | |
167 | OVS_REQ_WRLOCK(ms->rwlock); | |
f4ae6e23 FL |
168 | void mcast_snooping_set_port_flood(struct mcast_snooping *ms, void *port, |
169 | bool flood) | |
4a95091d | 170 | OVS_REQ_WRLOCK(ms->rwlock); |
8e04a33f FL |
171 | void mcast_snooping_set_port_flood_reports(struct mcast_snooping *ms, |
172 | void *port, bool flood) | |
173 | OVS_REQ_WRLOCK(ms->rwlock); | |
4a95091d FL |
174 | |
175 | /* Lookup. */ | |
176 | struct mcast_group * | |
964a4d5f TLSC |
177 | mcast_snooping_lookup(const struct mcast_snooping *ms, |
178 | const struct in6_addr *dip, uint16_t vlan) | |
179 | OVS_REQ_RDLOCK(ms->rwlock); | |
180 | struct mcast_group * | |
181 | mcast_snooping_lookup4(const struct mcast_snooping *ms, ovs_be32 ip4, | |
182 | uint16_t vlan) | |
4a95091d FL |
183 | OVS_REQ_RDLOCK(ms->rwlock); |
184 | ||
185 | /* Learning. */ | |
964a4d5f TLSC |
186 | bool mcast_snooping_add_group(struct mcast_snooping *ms, |
187 | const struct in6_addr *addr, | |
4a95091d FL |
188 | uint16_t vlan, void *port) |
189 | OVS_REQ_WRLOCK(ms->rwlock); | |
964a4d5f TLSC |
190 | bool mcast_snooping_add_group4(struct mcast_snooping *ms, ovs_be32 ip4, |
191 | uint16_t vlan, void *port) | |
192 | OVS_REQ_WRLOCK(ms->rwlock); | |
e3102e42 TLSC |
193 | int mcast_snooping_add_report(struct mcast_snooping *ms, |
194 | const struct dp_packet *p, | |
195 | uint16_t vlan, void *port) | |
196 | OVS_REQ_WRLOCK(ms->rwlock); | |
06994f87 TLSC |
197 | int mcast_snooping_add_mld(struct mcast_snooping *ms, |
198 | const struct dp_packet *p, | |
199 | uint16_t vlan, void *port) | |
200 | OVS_REQ_WRLOCK(ms->rwlock); | |
964a4d5f TLSC |
201 | bool mcast_snooping_leave_group(struct mcast_snooping *ms, |
202 | const struct in6_addr *addr, | |
4a95091d FL |
203 | uint16_t vlan, void *port) |
204 | OVS_REQ_WRLOCK(ms->rwlock); | |
964a4d5f TLSC |
205 | bool mcast_snooping_leave_group4(struct mcast_snooping *ms, ovs_be32 ip4, |
206 | uint16_t vlan, void *port) | |
207 | OVS_REQ_WRLOCK(ms->rwlock); | |
4a95091d FL |
208 | bool mcast_snooping_add_mrouter(struct mcast_snooping *ms, uint16_t vlan, |
209 | void *port) | |
210 | OVS_REQ_WRLOCK(ms->rwlock); | |
4a95091d FL |
211 | bool mcast_snooping_is_query(ovs_be16 igmp_type); |
212 | bool mcast_snooping_is_membership(ovs_be16 igmp_type); | |
213 | ||
214 | /* Flush. */ | |
215 | void mcast_snooping_mdb_flush(struct mcast_snooping *ms); | |
216 | void mcast_snooping_flush(struct mcast_snooping *ms); | |
4fbbf862 | 217 | void mcast_snooping_flush_bundle(struct mcast_snooping *ms, void *port); |
4a95091d FL |
218 | |
219 | #endif /* mcast-snooping.h */ |