2 * Copyright (c) 2014 Red Hat, Inc.
4 * Based on mac-learning implementation.
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:
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #ifndef MCAST_SNOOPING_H
20 #define MCAST_SNOOPING_H 1
25 #include "ovs-atomic.h"
26 #include "ovs-thread.h"
30 struct mcast_snooping;
32 /* Default maximum size of a mcast snooping table, in entries. */
33 #define MCAST_DEFAULT_MAX_ENTRIES 2048
35 /* Time, in seconds, before expiring a mcast_group due to inactivity. */
36 #define MCAST_ENTRY_DEFAULT_IDLE_TIME 300
38 /* Time, in seconds, before expiring a mrouter_port due to inactivity. */
39 #define MCAST_MROUTER_PORT_IDLE_TIME 180
41 /* Multicast group entry.
42 * Guarded by owning 'mcast_snooping''s rwlock. */
44 /* Node in parent struct mcast_snooping hmap. */
45 struct hmap_node hmap_node;
47 /* Multicast group IPv4 address. */
53 /* Node in parent struct mcast_snooping group_lru. */
54 struct list group_node OVS_GUARDED;
56 /* Contains struct mcast_group_bundle (ports), least recently used
57 * at the front, most recently used at the back. */
58 struct list bundle_lru OVS_GUARDED;
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. */
65 struct list bundle_node OVS_GUARDED;
67 /* When this node expires. */
71 void *port OVS_GUARDED;
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. */
78 struct list mrouter_node OVS_GUARDED;
80 /* When this node expires. */
87 void *port OVS_GUARDED;
90 /* The bundle to be flooded with multicast traffic.
91 * Guarded by owning 'mcast_snooping''s rwlock */
92 struct mcast_fport_bundle {
93 /* Node in parent struct mcast_snooping fport_list. */
94 struct list fport_node;
100 void *port OVS_GUARDED;
103 /* Multicast snooping table. */
104 struct mcast_snooping {
105 /* Snooping/learning table. */
108 /* Contains struct mcast_group, least recently used at the front,
109 * most recently used at the back. */
110 struct list group_lru OVS_GUARDED;
112 /* Contains struct mcast_mrouter_bundle, least recently used at the
113 * front, most recently used at the back. */
114 struct list mrouter_lru OVS_GUARDED;
116 /* Contains struct mcast_fport_bundle to be flooded with multicast
117 * packets in no special order. */
118 struct list fport_list OVS_GUARDED;
120 /* Secret for randomizing hash table. */
123 /* Maximum age before deleting an entry. */
124 unsigned int idle_time;
126 /* Maximum number of multicast groups learned. */
129 /* True if flow revalidation is needed. */
130 bool need_revalidate;
132 /* True if unregistered multicast packets should be flooded to all
133 * ports, otherwise send them to ports connected to multicast routers. */
136 struct ovs_refcount ref_cnt;
137 struct ovs_rwlock rwlock;
141 bool mcast_snooping_enabled(const struct mcast_snooping *ms);
142 bool mcast_snooping_flood_unreg(const struct mcast_snooping *ms);
143 int mcast_mrouter_age(const struct mcast_snooping *ms,
144 const struct mcast_mrouter_bundle *m);
145 int mcast_bundle_age(const struct mcast_snooping *ms,
146 const struct mcast_group_bundle *b);
147 struct mcast_snooping *mcast_snooping_create(void);
148 struct mcast_snooping *mcast_snooping_ref(const struct mcast_snooping *);
149 void mcast_snooping_unref(struct mcast_snooping *);
150 bool mcast_snooping_run(struct mcast_snooping *ms);
151 void mcast_snooping_wait(struct mcast_snooping *ms);
154 void mcast_snooping_set_idle_time(struct mcast_snooping *ms,
155 unsigned int idle_time)
156 OVS_REQ_WRLOCK(ms->rwlock);
157 void mcast_snooping_set_max_entries(struct mcast_snooping *ms,
159 OVS_REQ_WRLOCK(ms->rwlock);
161 mcast_snooping_set_flood_unreg(struct mcast_snooping *ms, bool enable)
162 OVS_REQ_WRLOCK(ms->rwlock);
163 void mcast_snooping_set_port_flood(struct mcast_snooping *ms, uint16_t vlan,
164 void *port, bool flood)
165 OVS_REQ_WRLOCK(ms->rwlock);
169 mcast_snooping_lookup(const struct mcast_snooping *ms, ovs_be32 dip,
171 OVS_REQ_RDLOCK(ms->rwlock);
174 bool mcast_snooping_add_group(struct mcast_snooping *ms, ovs_be32 ip4,
175 uint16_t vlan, void *port)
176 OVS_REQ_WRLOCK(ms->rwlock);
177 bool mcast_snooping_leave_group(struct mcast_snooping *ms, ovs_be32 ip4,
178 uint16_t vlan, void *port)
179 OVS_REQ_WRLOCK(ms->rwlock);
180 bool mcast_snooping_add_mrouter(struct mcast_snooping *ms, uint16_t vlan,
182 OVS_REQ_WRLOCK(ms->rwlock);
183 struct mcast_fport_bundle *
184 mcast_snooping_fport_lookup(struct mcast_snooping *ms, uint16_t vlan,
186 OVS_REQ_RDLOCK(ms->rwlock);
187 bool mcast_snooping_is_query(ovs_be16 igmp_type);
188 bool mcast_snooping_is_membership(ovs_be16 igmp_type);
191 void mcast_snooping_mdb_flush(struct mcast_snooping *ms);
192 void mcast_snooping_flush(struct mcast_snooping *ms);
194 #endif /* mcast-snooping.h */